Annotation of loncom/interface/domainprefs.pm, revision 1.315
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.315 ! raeburn 4: # $Id: domainprefs.pm,v 1.314 2017/10/07 00:50:47 raeburn Exp $
1.2 albertel 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.286 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: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 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.183 bisitz 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.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 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.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
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.271 raeburn 107: (official, unofficial, community, textbook, and placement).
108: In each case the radio buttons 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.232 raeburn 168: use Apache::lonuserutils();
1.235 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.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.1 raeburn 179:
1.155 raeburn 180: my $registered_cleanup;
181: my $modified_urls;
182:
1.1 raeburn 183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
1.91 raeburn 191: my $context = 'domain';
1.1 raeburn 192: my $dom = $env{'request.role.domain'};
1.5 albertel 193: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
1.155 raeburn 202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
1.1 raeburn 206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 208: ['phase','actions']);
1.30 raeburn 209: my $phase = 'pickactions';
1.3 raeburn 210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
1.150 raeburn 213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 214: my %domconfig =
1.6 raeburn 215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 220: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 221: 'requestauthor','selfenrollment','inststatus',
1.279 raeburn 222: 'ltitools','ssl','trust'],$dom);
1.297 raeburn 223: if (ref($domconfig{'ltitools'}) eq 'HASH') {
224: my %encconfig =
225: &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom);
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
228: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
229: foreach my $item ('key','secret') {
230: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
231: }
232: }
233: }
234: }
235: }
1.43 raeburn 236: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 237: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 238: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 239: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 240: 'serverstatuses','helpsettings','coursedefaults',
1.279 raeburn 241: 'ltitools','selfenrollment','usersessions','ssl','trust');
1.171 raeburn 242: my %existing;
243: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
244: %existing = %{$domconfig{'loadbalancing'}};
245: }
246: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 247: push(@prefs_order,'loadbalancing');
248: }
1.30 raeburn 249: my %prefs = (
250: 'rolecolors' =>
251: { text => 'Default color schemes',
1.67 raeburn 252: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 253: header => [{col1 => 'Student Settings',
254: col2 => '',},
255: {col1 => 'Coordinator Settings',
256: col2 => '',},
257: {col1 => 'Author Settings',
258: col2 => '',},
259: {col1 => 'Administrator Settings',
260: col2 => '',}],
1.230 raeburn 261: print => \&print_rolecolors,
262: modify => \&modify_rolecolors,
1.30 raeburn 263: },
1.110 raeburn 264: 'login' =>
1.30 raeburn 265: { text => 'Log-in page options',
1.67 raeburn 266: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 267: header => [{col1 => 'Log-in Page Items',
268: col2 => '',},
269: {col1 => 'Log-in Help',
1.256 raeburn 270: col2 => 'Value'},
271: {col1 => 'Custom HTML in document head',
1.168 raeburn 272: col2 => 'Value'}],
1.230 raeburn 273: print => \&print_login,
274: modify => \&modify_login,
1.30 raeburn 275: },
1.43 raeburn 276: 'defaults' =>
1.236 raeburn 277: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 278: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 279: header => [{col1 => 'Setting',
1.236 raeburn 280: col2 => 'Value'},
1.294 raeburn 281: {col1 => 'Internal Authentication',
282: col2 => 'Value'},
1.236 raeburn 283: {col1 => 'Institutional user types',
1.305 raeburn 284: col2 => 'Name displayed'}],
1.230 raeburn 285: print => \&print_defaults,
286: modify => \&modify_defaults,
1.43 raeburn 287: },
1.30 raeburn 288: 'quotas' =>
1.197 raeburn 289: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 290: help => 'Domain_Configuration_Quotas',
1.77 raeburn 291: header => [{col1 => 'User affiliation',
1.72 raeburn 292: col2 => 'Available tools',
1.213 raeburn 293: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 294: print => \&print_quotas,
295: modify => \&modify_quotas,
1.30 raeburn 296: },
297: 'autoenroll' =>
298: { text => 'Auto-enrollment settings',
1.67 raeburn 299: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 300: header => [{col1 => 'Configuration setting',
301: col2 => 'Value(s)'}],
1.230 raeburn 302: print => \&print_autoenroll,
303: modify => \&modify_autoenroll,
1.30 raeburn 304: },
305: 'autoupdate' =>
306: { text => 'Auto-update settings',
1.67 raeburn 307: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 308: header => [{col1 => 'Setting',
309: col2 => 'Value',},
1.131 raeburn 310: {col1 => 'Setting',
311: col2 => 'Affiliation'},
1.43 raeburn 312: {col1 => 'User population',
1.227 bisitz 313: col2 => 'Updatable user data'}],
1.230 raeburn 314: print => \&print_autoupdate,
315: modify => \&modify_autoupdate,
1.30 raeburn 316: },
1.125 raeburn 317: 'autocreate' =>
318: { text => 'Auto-course creation settings',
319: help => 'Domain_Configuration_Auto_Creation',
320: header => [{col1 => 'Configuration Setting',
321: col2 => 'Value',}],
1.230 raeburn 322: print => \&print_autocreate,
323: modify => \&modify_autocreate,
1.125 raeburn 324: },
1.30 raeburn 325: 'directorysrch' =>
1.277 raeburn 326: { text => 'Directory searches',
1.67 raeburn 327: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 328: header => [{col1 => 'Institutional Directory Setting',
329: col2 => 'Value',},
330: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 331: col2 => 'Value',}],
1.230 raeburn 332: print => \&print_directorysrch,
333: modify => \&modify_directorysrch,
1.30 raeburn 334: },
335: 'contacts' =>
1.286 raeburn 336: { text => 'E-mail addresses and helpform',
1.67 raeburn 337: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 338: header => [{col1 => 'Default e-mail addresses',
339: col2 => 'Value',},
340: {col1 => 'Recipient(s) for notifications',
341: col2 => 'Value',},
342: {col1 => 'Ask helpdesk form settings',
343: col2 => 'Value',},],
1.230 raeburn 344: print => \&print_contacts,
345: modify => \&modify_contacts,
1.30 raeburn 346: },
347: 'usercreation' =>
348: { text => 'User creation',
1.67 raeburn 349: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 350: header => [{col1 => 'Format rule type',
351: col2 => 'Format rules in force'},
1.34 raeburn 352: {col1 => 'User account creation',
353: col2 => 'Usernames which may be created',},
1.30 raeburn 354: {col1 => 'Context',
1.43 raeburn 355: col2 => 'Assignable authentication types'}],
1.230 raeburn 356: print => \&print_usercreation,
357: modify => \&modify_usercreation,
1.30 raeburn 358: },
1.224 raeburn 359: 'selfcreation' =>
360: { text => 'Users self-creating accounts',
361: help => 'Domain_Configuration_Self_Creation',
362: header => [{col1 => 'Self-creation with institutional username',
363: col2 => 'Enabled?'},
364: {col1 => 'Institutional user type (login/SSO self-creation)',
365: col2 => 'Information user can enter'},
1.303 raeburn 366: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 367: col2 => 'Settings'}],
1.230 raeburn 368: print => \&print_selfcreation,
369: modify => \&modify_selfcreation,
1.224 raeburn 370: },
1.69 raeburn 371: 'usermodification' =>
1.33 raeburn 372: { text => 'User modification',
1.67 raeburn 373: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 374: header => [{col1 => 'Target user has role',
1.227 bisitz 375: col2 => 'User information updatable in author context'},
1.33 raeburn 376: {col1 => 'Target user has role',
1.227 bisitz 377: col2 => 'User information updatable in course context'}],
1.230 raeburn 378: print => \&print_usermodification,
379: modify => \&modify_usermodification,
1.33 raeburn 380: },
1.69 raeburn 381: 'scantron' =>
1.95 www 382: { text => 'Bubblesheet format file',
1.67 raeburn 383: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 384: header => [ {col1 => 'Item',
385: col2 => '',
386: }],
1.230 raeburn 387: print => \&print_scantron,
388: modify => \&modify_scantron,
1.46 raeburn 389: },
1.86 raeburn 390: 'requestcourses' =>
391: {text => 'Request creation of courses',
392: help => 'Domain_Configuration_Request_Courses',
393: header => [{col1 => 'User affiliation',
1.102 raeburn 394: col2 => 'Availability/Processing of requests',},
395: {col1 => 'Setting',
1.216 raeburn 396: col2 => 'Value'},
397: {col1 => 'Available textbooks',
1.235 raeburn 398: col2 => ''},
1.242 raeburn 399: {col1 => 'Available templates',
400: col2 => ''},
1.235 raeburn 401: {col1 => 'Validation (not official courses)',
402: col2 => 'Value'},],
1.230 raeburn 403: print => \&print_quotas,
404: modify => \&modify_quotas,
1.86 raeburn 405: },
1.163 raeburn 406: 'requestauthor' =>
1.223 bisitz 407: {text => 'Request Authoring Space',
1.163 raeburn 408: help => 'Domain_Configuration_Request_Author',
409: header => [{col1 => 'User affiliation',
410: col2 => 'Availability/Processing of requests',},
411: {col1 => 'Setting',
412: col2 => 'Value'}],
1.230 raeburn 413: print => \&print_quotas,
414: modify => \&modify_quotas,
1.163 raeburn 415: },
1.69 raeburn 416: 'coursecategories' =>
1.120 raeburn 417: { text => 'Cataloging of courses/communities',
1.67 raeburn 418: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 419: header => [{col1 => 'Catalog type/availability',
420: col2 => '',},
421: {col1 => 'Category settings for standard catalog',
1.57 raeburn 422: col2 => '',},
423: {col1 => 'Categories',
424: col2 => '',
425: }],
1.230 raeburn 426: print => \&print_coursecategories,
427: modify => \&modify_coursecategories,
1.69 raeburn 428: },
429: 'serverstatuses' =>
1.77 raeburn 430: {text => 'Access to server status pages',
1.69 raeburn 431: help => 'Domain_Configuration_Server_Status',
432: header => [{col1 => 'Status Page',
433: col2 => 'Other named users',
434: col3 => 'Specific IPs',
435: }],
1.230 raeburn 436: print => \&print_serverstatuses,
437: modify => \&modify_serverstatuses,
1.69 raeburn 438: },
1.118 jms 439: 'helpsettings' =>
1.282 raeburn 440: {text => 'Support settings',
1.118 jms 441: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 442: header => [{col1 => 'Help Page Settings (logged-in users)',
443: col2 => 'Value'},
444: {col1 => 'Helpdesk Roles',
445: col2 => 'Settings'},],
1.230 raeburn 446: print => \&print_helpsettings,
447: modify => \&modify_helpsettings,
1.118 jms 448: },
1.121 raeburn 449: 'coursedefaults' =>
450: {text => 'Course/Community defaults',
451: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 452: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
453: col2 => 'Value',},
454: {col1 => 'Defaults which can be overridden for each course by a DC',
455: col2 => 'Value',},],
1.230 raeburn 456: print => \&print_coursedefaults,
457: modify => \&modify_coursedefaults,
1.121 raeburn 458: },
1.231 raeburn 459: 'selfenrollment' =>
460: {text => 'Self-enrollment in Course/Community',
461: help => 'Domain_Configuration_Selfenrollment',
462: header => [{col1 => 'Configuration Rights',
463: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
464: {col1 => 'Defaults',
465: col2 => 'Value'},
466: {col1 => 'Self-enrollment validation (optional)',
467: col2 => 'Value'},],
468: print => \&print_selfenrollment,
469: modify => \&modify_selfenrollment,
470: },
1.120 raeburn 471: 'privacy' =>
472: {text => 'User Privacy',
473: help => 'Domain_Configuration_User_Privacy',
474: header => [{col1 => 'Setting',
475: col2 => 'Value',}],
1.230 raeburn 476: print => \&print_privacy,
477: modify => \&modify_privacy,
1.120 raeburn 478: },
1.141 raeburn 479: 'usersessions' =>
1.145 raeburn 480: {text => 'User session hosting/offloading',
1.137 raeburn 481: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 482: header => [{col1 => 'Domain server',
483: col2 => 'Servers to offload sessions to when busy'},
484: {col1 => 'Hosting of users from other domains',
1.137 raeburn 485: col2 => 'Rules'},
486: {col1 => "Hosting domain's own users elsewhere",
487: col2 => 'Rules'}],
1.230 raeburn 488: print => \&print_usersessions,
489: modify => \&modify_usersessions,
1.137 raeburn 490: },
1.279 raeburn 491: 'loadbalancing' =>
1.185 raeburn 492: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 493: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 494: header => [{col1 => 'Balancers',
1.150 raeburn 495: col2 => 'Default destinations',
1.183 bisitz 496: col3 => 'User affiliation',
1.150 raeburn 497: col4 => 'Overrides'},
498: ],
1.230 raeburn 499: print => \&print_loadbalancing,
500: modify => \&modify_loadbalancing,
1.150 raeburn 501: },
1.279 raeburn 502: 'ltitools' =>
1.267 raeburn 503: {text => 'External Tools (LTI)',
1.296 raeburn 504: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 505: header => [{col1 => 'Setting',
506: col2 => 'Value',}],
507: print => \&print_ltitools,
508: modify => \&modify_ltitools,
509: },
1.279 raeburn 510: 'ssl' =>
1.275 raeburn 511: {text => 'LON-CAPA Network (SSL)',
512: help => 'Domain_Configuration_Network_SSL',
513: header => [{col1 => 'Server',
514: col2 => 'Certificate Status'},
515: {col1 => 'Connections to other servers',
516: col2 => 'Rules'},
1.293 raeburn 517: {col1 => 'Connections from other servers',
518: col2 => 'Rules'},
1.275 raeburn 519: {col1 => "Replicating domain's published content",
520: col2 => 'Rules'}],
521: print => \&print_ssl,
522: modify => \&modify_ssl,
523: },
1.279 raeburn 524: 'trust' =>
525: {text => 'Trust Settings',
526: help => 'Domain_Configuration_Trust',
527: header => [{col1 => "Access to this domain's content by others",
528: col2 => 'Rules'},
529: {col1 => "Access to other domain's content by this domain",
530: col2 => 'Rules'},
531: {col1 => "Enrollment in this domain's courses by others",
532: col2 => 'Rules',},
533: {col1 => "Co-author roles in this domain for others",
534: col2 => 'Rules',},
535: {col1 => "Co-author roles for this domain's users elsewhere",
536: col2 => 'Rules',},
537: {col1 => "Domain roles in this domain assignable to others",
538: col2 => 'Rules'},
539: {col1 => "Course catalog for this domain displayed elsewhere",
540: col2 => 'Rules'},
541: {col1 => "Requests for creation of courses in this domain by others",
542: col2 => 'Rules'},
543: {col1 => "Users in other domains can send messages to this domain",
544: col2 => 'Rules'},],
545: print => \&print_trust,
546: modify => \&modify_trust,
547: },
1.3 raeburn 548: );
1.110 raeburn 549: if (keys(%servers) > 1) {
550: $prefs{'login'} = { text => 'Log-in page options',
551: help => 'Domain_Configuration_Login_Page',
552: header => [{col1 => 'Log-in Service',
553: col2 => 'Server Setting',},
554: {col1 => 'Log-in Page Items',
1.168 raeburn 555: col2 => ''},
556: {col1 => 'Log-in Help',
1.256 raeburn 557: col2 => 'Value'},
558: {col1 => 'Custom HTML in document head',
1.168 raeburn 559: col2 => 'Value'}],
1.230 raeburn 560: print => \&print_login,
561: modify => \&modify_login,
1.110 raeburn 562: };
563: }
1.174 foxr 564:
1.6 raeburn 565: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 566: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 567: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 568: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 569: text=>"Settings to display/modify"});
1.9 raeburn 570: my $confname = $dom.'-domainconfig';
1.174 foxr 571:
1.3 raeburn 572: if ($phase eq 'process') {
1.212 raeburn 573: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
574: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 575: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 576: $r->rflush();
1.212 raeburn 577: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 578: }
1.30 raeburn 579: } elsif ($phase eq 'display') {
1.192 raeburn 580: my $js = &recaptcha_js().
1.236 raeburn 581: &toggle_display_js();
1.171 raeburn 582: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 583: my ($othertitle,$usertypes,$types) =
584: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 585: $js .= &lonbalance_targets_js($dom,$types,\%servers,
586: $domconfig{'loadbalancing'}).
1.170 raeburn 587: &new_spares_js().
588: &common_domprefs_js().
589: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 590: }
1.216 raeburn 591: if (grep(/^requestcourses$/,@actions)) {
592: my $javascript_validations;
593: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
594: $js .= <<END;
595: <script type="text/javascript">
596: $javascript_validations
597: </script>
598: $coursebrowserjs
599: END
600: }
1.305 raeburn 601: if (grep(/^selfcreation$/,@actions)) {
602: $js .= &selfcreate_javascript();
603: }
1.286 raeburn 604: if (grep(/^contacts$/,@actions)) {
605: $js .= &contacts_javascript();
606: }
1.150 raeburn 607: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 608: } else {
1.180 raeburn 609: # check if domconfig user exists for the domain.
610: my $servadm = $r->dir_config('lonAdmEMail');
611: my ($configuserok,$author_ok,$switchserver) =
612: &config_check($dom,$confname,$servadm);
613: unless ($configuserok eq 'ok') {
1.181 raeburn 614: &Apache::lonconfigsettings::print_header($r,$phase,$context);
615: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 616: $confname).
1.181 raeburn 617: '<br />'
618: );
1.180 raeburn 619: if ($switchserver) {
1.181 raeburn 620: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
621: '<br />'.
622: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
623: '<br />'.
624: &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).
625: '<br />'.
626: &mt('To do that now, use the following link: [_1]',$switchserver)
627: );
628: } else {
629: $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.').
630: '<br />'.
631: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
632: );
1.180 raeburn 633: }
634: $r->print(&Apache::loncommon::end_page());
635: return OK;
636: }
1.21 raeburn 637: if (keys(%domconfig) == 0) {
638: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 639: my @ids=&Apache::lonnet::current_machine_ids();
640: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 641: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 642: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 643: my $custom_img_count = 0;
644: foreach my $img (@loginimages) {
645: if ($designhash{$dom.'.login.'.$img} ne '') {
646: $custom_img_count ++;
647: }
648: }
649: foreach my $role (@roles) {
650: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
651: $custom_img_count ++;
652: }
653: }
654: if ($custom_img_count > 0) {
1.94 raeburn 655: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 656: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 657: $r->print(
658: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
659: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
660: &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 />'.
661: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
662: if ($switch_server) {
1.30 raeburn 663: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 664: }
1.91 raeburn 665: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 666: return OK;
667: }
668: }
669: }
1.91 raeburn 670: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 671: }
672: return OK;
673: }
674:
675: sub process_changes {
1.205 raeburn 676: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 677: my %domconfig;
678: if (ref($values) eq 'HASH') {
679: %domconfig = %{$values};
680: }
1.3 raeburn 681: my $output;
682: if ($action eq 'login') {
1.205 raeburn 683: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 684: } elsif ($action eq 'rolecolors') {
1.9 raeburn 685: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 686: $lastactref,%domconfig);
1.3 raeburn 687: } elsif ($action eq 'quotas') {
1.216 raeburn 688: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 689: } elsif ($action eq 'autoenroll') {
1.205 raeburn 690: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 691: } elsif ($action eq 'autoupdate') {
692: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 693: } elsif ($action eq 'autocreate') {
694: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 695: } elsif ($action eq 'directorysrch') {
1.295 raeburn 696: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 697: } elsif ($action eq 'usercreation') {
1.28 raeburn 698: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 699: } elsif ($action eq 'selfcreation') {
1.305 raeburn 700: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 701: } elsif ($action eq 'usermodification') {
702: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 703: } elsif ($action eq 'contacts') {
1.205 raeburn 704: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 705: } elsif ($action eq 'defaults') {
1.212 raeburn 706: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 707: } elsif ($action eq 'scantron') {
1.205 raeburn 708: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 709: } elsif ($action eq 'coursecategories') {
1.239 raeburn 710: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 711: } elsif ($action eq 'serverstatuses') {
712: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 713: } elsif ($action eq 'requestcourses') {
1.216 raeburn 714: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 715: } elsif ($action eq 'requestauthor') {
1.216 raeburn 716: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 717: } elsif ($action eq 'helpsettings') {
1.285 raeburn 718: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 719: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 720: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 721: } elsif ($action eq 'selfenrollment') {
722: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 723: } elsif ($action eq 'usersessions') {
1.212 raeburn 724: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 725: } elsif ($action eq 'loadbalancing') {
726: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 727: } elsif ($action eq 'ltitools') {
728: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 729: } elsif ($action eq 'ssl') {
730: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 731: } elsif ($action eq 'trust') {
732: $output = &modify_trust($dom,$lastactref,%domconfig);
1.3 raeburn 733: }
734: return $output;
735: }
736:
737: sub print_config_box {
1.9 raeburn 738: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 739: my $rowtotal = 0;
1.49 raeburn 740: my $output;
741: if ($action eq 'coursecategories') {
742: $output = &coursecategories_javascript($settings);
1.236 raeburn 743: } elsif ($action eq 'defaults') {
744: $output = &defaults_javascript($settings);
1.282 raeburn 745: } elsif ($action eq 'helpsettings') {
746: my (%privs,%levelscurrent);
747: my %full=();
748: my %levels=(
749: course => {},
750: domain => {},
751: system => {},
752: );
753: my $context = 'domain';
754: my $crstype = 'Course';
755: my $formname = 'display';
756: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
757: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
758: $output =
759: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
760: \@templateroles);
1.91 raeburn 761: }
1.236 raeburn 762: $output .=
1.30 raeburn 763: '<table class="LC_nested_outer">
1.3 raeburn 764: <tr>
1.306 raeburn 765: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 766: &mt($item->{text}).' '.
767: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
768: '</tr>';
1.30 raeburn 769: $rowtotal ++;
1.110 raeburn 770: my $numheaders = 1;
771: if (ref($item->{'header'}) eq 'ARRAY') {
772: $numheaders = scalar(@{$item->{'header'}});
773: }
774: if ($numheaders > 1) {
1.64 raeburn 775: my $colspan = '';
1.145 raeburn 776: my $rightcolspan = '';
1.238 raeburn 777: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 778: ($action eq 'directorysrch') ||
1.256 raeburn 779: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 780: $colspan = ' colspan="2"';
781: }
1.145 raeburn 782: if ($action eq 'usersessions') {
783: $rightcolspan = ' colspan="3"';
784: }
1.30 raeburn 785: $output .= '
1.3 raeburn 786: <tr>
787: <td>
788: <table class="LC_nested">
789: <tr class="LC_info_row">
1.59 bisitz 790: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 791: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 792: </tr>';
1.69 raeburn 793: $rowtotal ++;
1.230 raeburn 794: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 795: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 796: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 797: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
798: ($action eq 'contacts')) {
1.230 raeburn 799: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 800: } elsif ($action eq 'coursecategories') {
1.230 raeburn 801: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 802: } elsif ($action eq 'login') {
1.256 raeburn 803: if ($numheaders == 4) {
1.168 raeburn 804: $colspan = ' colspan="2"';
805: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
806: } else {
807: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
808: }
1.230 raeburn 809: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 810: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 811: } elsif ($action eq 'rolecolors') {
1.30 raeburn 812: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 813: }
1.30 raeburn 814: $output .= '
1.6 raeburn 815: </table>
816: </td>
817: </tr>
818: <tr>
819: <td>
820: <table class="LC_nested">
821: <tr class="LC_info_row">
1.230 raeburn 822: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 823: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 824: </tr>';
825: $rowtotal ++;
1.230 raeburn 826: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
827: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 828: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.294 raeburn 829: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238 raeburn 830: if ($action eq 'coursecategories') {
831: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
832: $colspan = ' colspan="2"';
1.279 raeburn 833: } elsif ($action eq 'trust') {
834: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 835: } else {
836: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
837: }
1.279 raeburn 838: if ($action eq 'trust') {
839: $output .= '
840: </table>
841: </td>
842: </tr>';
843: my @trusthdrs = qw(2 3 4 5 6 7);
844: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
845: for (my $i=0; $i<@trusthdrs; $i++) {
846: $output .= '
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'}->[$trusthdrs[$i]]->{'col1'}).'</td>
852: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
853: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
854: </table>
855: </td>
856: </tr>';
857: }
858: $output .= '
859: <tr>
860: <td>
861: <table class="LC_nested">
862: <tr class="LC_info_row">
863: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
864: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
865: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
866: } else {
867: $output .= '
1.63 raeburn 868: </table>
869: </td>
870: </tr>
871: <tr>
872: <td>
873: <table class="LC_nested">
874: <tr class="LC_info_row">
875: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 876: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 877: </tr>'."\n";
1.279 raeburn 878: if ($action eq 'coursecategories') {
879: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
880: } else {
881: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
882: }
1.238 raeburn 883: }
1.63 raeburn 884: $rowtotal ++;
1.236 raeburn 885: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 886: ($action eq 'defaults') || ($action eq 'directorysrch') ||
887: ($action eq 'helpsettings')) {
1.230 raeburn 888: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.293 raeburn 889: } elsif ($action eq 'ssl') {
890: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
891: </table>
892: </td>
893: </tr>
894: <tr>
895: <td>
896: <table class="LC_nested">
897: <tr class="LC_info_row">
898: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
899: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
900: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
901: </table>
902: </td>
903: </tr>
904: <tr>
905: <td>
906: <table class="LC_nested">
907: <tr class="LC_info_row">
908: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
909: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
910: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 911: } elsif ($action eq 'login') {
1.256 raeburn 912: if ($numheaders == 4) {
1.168 raeburn 913: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
914: </table>
915: </td>
916: </tr>
917: <tr>
918: <td>
919: <table class="LC_nested">
920: <tr class="LC_info_row">
921: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 922: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 923: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
924: $rowtotal ++;
925: } else {
926: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
927: }
1.256 raeburn 928: $output .= '
929: </table>
930: </td>
931: </tr>
932: <tr>
933: <td>
934: <table class="LC_nested">
935: <tr class="LC_info_row">';
936: if ($numheaders == 4) {
937: $output .= '
938: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
939: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
940: </tr>';
941: } else {
942: $output .= '
943: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
944: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
945: </tr>';
946: }
947: $rowtotal ++;
948: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 949: } elsif ($action eq 'requestcourses') {
1.247 raeburn 950: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
951: $rowtotal ++;
952: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 953: </table>
954: </td>
955: </tr>
956: <tr>
957: <td>
958: <table class="LC_nested">
959: <tr class="LC_info_row">
960: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
961: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 962: &textbookcourses_javascript($settings).
963: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
964: </table>
965: </td>
966: </tr>
967: <tr>
968: <td>
969: <table class="LC_nested">
970: <tr class="LC_info_row">
971: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
972: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
973: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 974: </table>
975: </td>
976: </tr>
977: <tr>
978: <td>
979: <table class="LC_nested">
980: <tr class="LC_info_row">
1.306 raeburn 981: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
982: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 983: </tr>'.
984: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 985: } elsif ($action eq 'requestauthor') {
986: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 987: $rowtotal ++;
1.122 jms 988: } elsif ($action eq 'rolecolors') {
1.30 raeburn 989: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 990: </table>
991: </td>
992: </tr>
993: <tr>
994: <td>
995: <table class="LC_nested">
996: <tr class="LC_info_row">
1.306 raeburn 997: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 998: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 999: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1000: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1001: </tr>'.
1.30 raeburn 1002: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1003: </table>
1004: </td>
1005: </tr>
1006: <tr>
1007: <td>
1008: <table class="LC_nested">
1009: <tr class="LC_info_row">
1.59 bisitz 1010: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1011: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1012: </tr>'.
1.30 raeburn 1013: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1014: $rowtotal += 2;
1.6 raeburn 1015: }
1.3 raeburn 1016: } else {
1.30 raeburn 1017: $output .= '
1.3 raeburn 1018: <tr>
1019: <td>
1020: <table class="LC_nested">
1.30 raeburn 1021: <tr class="LC_info_row">';
1.277 raeburn 1022: if ($action eq 'login') {
1.30 raeburn 1023: $output .= '
1.59 bisitz 1024: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1025: } elsif ($action eq 'serverstatuses') {
1026: $output .= '
1.306 raeburn 1027: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1028: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1029:
1.6 raeburn 1030: } else {
1.30 raeburn 1031: $output .= '
1.306 raeburn 1032: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1033: }
1.72 raeburn 1034: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1035: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1036: &mt($item->{'header'}->[0]->{'col2'});
1037: if ($action eq 'serverstatuses') {
1038: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1039: }
1.69 raeburn 1040: } else {
1.306 raeburn 1041: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1042: &mt($item->{'header'}->[0]->{'col2'});
1043: }
1044: $output .= '</td>';
1045: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1046: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1047: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1048: &mt($item->{'header'}->[0]->{'col3'});
1049: } else {
1.306 raeburn 1050: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1051: &mt($item->{'header'}->[0]->{'col3'});
1052: }
1.69 raeburn 1053: if ($action eq 'serverstatuses') {
1054: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1055: }
1056: $output .= '</td>';
1.6 raeburn 1057: }
1.150 raeburn 1058: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1059: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1060: &mt($item->{'header'}->[0]->{'col4'});
1061: }
1.69 raeburn 1062: $output .= '</tr>';
1.48 raeburn 1063: $rowtotal ++;
1.168 raeburn 1064: if ($action eq 'quotas') {
1.86 raeburn 1065: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1066: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1067: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1068: ($action eq 'ltitools')) {
1.230 raeburn 1069: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1070: } elsif ($action eq 'scantron') {
1071: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1072: }
1.3 raeburn 1073: }
1.30 raeburn 1074: $output .= '
1.3 raeburn 1075: </table>
1076: </td>
1077: </tr>
1.30 raeburn 1078: </table><br />';
1079: return ($output,$rowtotal);
1.1 raeburn 1080: }
1081:
1.3 raeburn 1082: sub print_login {
1.168 raeburn 1083: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1084: my ($css_class,$datatable);
1.6 raeburn 1085: my %choices = &login_choices();
1.110 raeburn 1086:
1.168 raeburn 1087: if ($caller eq 'service') {
1.149 raeburn 1088: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1089: my $choice = $choices{'disallowlogin'};
1090: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1091: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1092: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1093: '<th>'.$choices{'server'}.'</th>'.
1094: '<th>'.$choices{'serverpath'}.'</th>'.
1095: '<th>'.$choices{'custompath'}.'</th>'.
1096: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1097: my %disallowed;
1098: if (ref($settings) eq 'HASH') {
1099: if (ref($settings->{'loginvia'}) eq 'HASH') {
1100: %disallowed = %{$settings->{'loginvia'}};
1101: }
1102: }
1103: foreach my $lonhost (sort(keys(%servers))) {
1104: my $direct = 'selected="selected"';
1.128 raeburn 1105: if (ref($disallowed{$lonhost}) eq 'HASH') {
1106: if ($disallowed{$lonhost}{'server'} ne '') {
1107: $direct = '';
1108: }
1.110 raeburn 1109: }
1.115 raeburn 1110: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1111: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1112: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1113: '</option>';
1.184 raeburn 1114: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1115: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1116: my $selected = '';
1.128 raeburn 1117: if (ref($disallowed{$lonhost}) eq 'HASH') {
1118: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1119: $selected = 'selected="selected"';
1120: }
1.110 raeburn 1121: }
1122: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1123: $servers{$hostid}.'</option>';
1124: }
1.128 raeburn 1125: $datatable .= '</select></td>'.
1126: '<td><select name="'.$lonhost.'_serverpath">';
1127: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1128: my $pathname = $path;
1129: if ($path eq 'custom') {
1130: $pathname = &mt('Custom Path').' ->';
1131: }
1132: my $selected = '';
1133: if (ref($disallowed{$lonhost}) eq 'HASH') {
1134: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1135: $selected = 'selected="selected"';
1136: }
1137: } elsif ($path eq '') {
1138: $selected = 'selected="selected"';
1139: }
1140: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1141: }
1142: $datatable .= '</select></td>';
1143: my ($custom,$exempt);
1144: if (ref($disallowed{$lonhost}) eq 'HASH') {
1145: $custom = $disallowed{$lonhost}{'custompath'};
1146: $exempt = $disallowed{$lonhost}{'exempt'};
1147: }
1148: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1149: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1150: '</tr>';
1.110 raeburn 1151: }
1152: $datatable .= '</table></td></tr>';
1153: return $datatable;
1.168 raeburn 1154: } elsif ($caller eq 'page') {
1155: my %defaultchecked = (
1156: 'coursecatalog' => 'on',
1.188 raeburn 1157: 'helpdesk' => 'on',
1.168 raeburn 1158: 'adminmail' => 'off',
1159: 'newuser' => 'off',
1160: );
1.188 raeburn 1161: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1162: my (%checkedon,%checkedoff);
1.42 raeburn 1163: foreach my $item (@toggles) {
1.168 raeburn 1164: if ($defaultchecked{$item} eq 'on') {
1165: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1166: $checkedoff{$item} = ' ';
1.168 raeburn 1167: } elsif ($defaultchecked{$item} eq 'off') {
1168: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1169: $checkedon{$item} = ' ';
1170: }
1.1 raeburn 1171: }
1.168 raeburn 1172: my @images = ('img','logo','domlogo','login');
1173: my @logintext = ('textcol','bgcol');
1174: my @bgs = ('pgbg','mainbg','sidebg');
1175: my @links = ('link','alink','vlink');
1176: my %designhash = &Apache::loncommon::get_domainconf($dom);
1177: my %defaultdesign = %Apache::loncommon::defaultdesign;
1178: my (%is_custom,%designs);
1179: my %defaults = (
1180: font => $defaultdesign{'login.font'},
1181: );
1.6 raeburn 1182: foreach my $item (@images) {
1.168 raeburn 1183: $defaults{$item} = $defaultdesign{'login.'.$item};
1184: $defaults{'showlogo'}{$item} = 1;
1185: }
1186: foreach my $item (@bgs) {
1187: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1188: }
1.41 raeburn 1189: foreach my $item (@logintext) {
1.168 raeburn 1190: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1191: }
1.168 raeburn 1192: foreach my $item (@links) {
1193: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1194: }
1.168 raeburn 1195: if (ref($settings) eq 'HASH') {
1196: foreach my $item (@toggles) {
1197: if ($settings->{$item} eq '1') {
1198: $checkedon{$item} = ' checked="checked" ';
1199: $checkedoff{$item} = ' ';
1200: } elsif ($settings->{$item} eq '0') {
1201: $checkedoff{$item} = ' checked="checked" ';
1202: $checkedon{$item} = ' ';
1203: }
1204: }
1205: foreach my $item (@images) {
1206: if (defined($settings->{$item})) {
1207: $designs{$item} = $settings->{$item};
1208: $is_custom{$item} = 1;
1209: }
1210: if (defined($settings->{'showlogo'}{$item})) {
1211: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1212: }
1213: }
1214: foreach my $item (@logintext) {
1215: if ($settings->{$item} ne '') {
1216: $designs{'logintext'}{$item} = $settings->{$item};
1217: $is_custom{$item} = 1;
1218: }
1219: }
1220: if ($settings->{'font'} ne '') {
1221: $designs{'font'} = $settings->{'font'};
1222: $is_custom{'font'} = 1;
1223: }
1224: foreach my $item (@bgs) {
1225: if ($settings->{$item} ne '') {
1226: $designs{'bgs'}{$item} = $settings->{$item};
1227: $is_custom{$item} = 1;
1228: }
1229: }
1230: foreach my $item (@links) {
1231: if ($settings->{$item} ne '') {
1232: $designs{'links'}{$item} = $settings->{$item};
1233: $is_custom{$item} = 1;
1234: }
1235: }
1236: } else {
1237: if ($designhash{$dom.'.login.font'} ne '') {
1238: $designs{'font'} = $designhash{$dom.'.login.font'};
1239: $is_custom{'font'} = 1;
1240: }
1241: foreach my $item (@images) {
1242: if ($designhash{$dom.'.login.'.$item} ne '') {
1243: $designs{$item} = $designhash{$dom.'.login.'.$item};
1244: $is_custom{$item} = 1;
1245: }
1246: }
1247: foreach my $item (@bgs) {
1248: if ($designhash{$dom.'.login.'.$item} ne '') {
1249: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1250: $is_custom{$item} = 1;
1251: }
1.6 raeburn 1252: }
1.168 raeburn 1253: foreach my $item (@links) {
1254: if ($designhash{$dom.'.login.'.$item} ne '') {
1255: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1256: $is_custom{$item} = 1;
1257: }
1.6 raeburn 1258: }
1259: }
1.168 raeburn 1260: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1261: logo => 'Institution Logo',
1262: domlogo => 'Domain Logo',
1263: login => 'Login box');
1264: my $itemcount = 1;
1265: foreach my $item (@toggles) {
1266: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1267: $datatable .=
1268: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1269: '</td><td>'.
1270: '<span class="LC_nobreak"><label><input type="radio" name="'.
1271: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1272: '</label> <label><input type="radio" name="'.$item.'"'.
1273: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1274: '</tr>';
1275: $itemcount ++;
1.6 raeburn 1276: }
1.168 raeburn 1277: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1278: $datatable .= '</tr></table></td></tr>';
1279: } elsif ($caller eq 'help') {
1280: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1281: my $switchserver = &check_switchserver($dom,$confname);
1282: my $itemcount = 1;
1283: $defaulturl = '/adm/loginproblems.html';
1284: $defaulttype = 'default';
1285: %lt = &Apache::lonlocal::texthash (
1286: del => 'Delete?',
1287: rep => 'Replace:',
1288: upl => 'Upload:',
1289: default => 'Default',
1290: custom => 'Custom',
1291: );
1292: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1293: my @currlangs;
1294: if (ref($settings) eq 'HASH') {
1295: if (ref($settings->{'helpurl'}) eq 'HASH') {
1296: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1297: next if ($settings->{'helpurl'}{$key} eq '');
1298: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1299: $type{$key} = 'custom';
1300: unless ($key eq 'nolang') {
1301: push(@currlangs,$key);
1302: }
1303: }
1304: } elsif ($settings->{'helpurl'} ne '') {
1305: $type{'nolang'} = 'custom';
1306: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1307: }
1308: }
1.168 raeburn 1309: foreach my $lang ('nolang',sort(@currlangs)) {
1310: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1311: $datatable .= '<tr'.$css_class.'>';
1312: if ($url{$lang} eq '') {
1313: $url{$lang} = $defaulturl;
1314: }
1315: if ($type{$lang} eq '') {
1316: $type{$lang} = $defaulttype;
1317: }
1318: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1319: if ($lang eq 'nolang') {
1320: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1321: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1322: } else {
1323: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1324: $langchoices{$lang},
1325: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1326: }
1327: $datatable .= '</span></td>'."\n".
1328: '<td class="LC_left_item">';
1329: if ($type{$lang} eq 'custom') {
1330: $datatable .= '<span class="LC_nobreak"><label>'.
1331: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1332: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1333: } else {
1334: $datatable .= $lt{'upl'};
1335: }
1336: $datatable .='<br />';
1337: if ($switchserver) {
1338: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1339: } else {
1340: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1341: }
1.168 raeburn 1342: $datatable .= '</td></tr>';
1343: $itemcount ++;
1.6 raeburn 1344: }
1.168 raeburn 1345: my @addlangs;
1346: foreach my $lang (sort(keys(%langchoices))) {
1347: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1348: push(@addlangs,$lang);
1349: }
1350: if (@addlangs > 0) {
1351: my %toadd;
1352: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1353: $toadd{''} = &mt('Select');
1354: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1355: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1356: &mt('Add log-in help page for a specific language:').' '.
1357: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1358: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1359: if ($switchserver) {
1360: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1361: } else {
1362: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1363: }
1.168 raeburn 1364: $datatable .= '</td></tr>';
1.169 raeburn 1365: $itemcount ++;
1.6 raeburn 1366: }
1.169 raeburn 1367: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1368: } elsif ($caller eq 'headtag') {
1369: my %domservers = &Apache::lonnet::get_servers($dom);
1370: my $choice = $choices{'headtag'};
1371: $css_class = ' class="LC_odd_row"';
1372: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1373: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1374: '<th>'.$choices{'current'}.'</th>'.
1375: '<th>'.$choices{'action'}.'</th>'.
1376: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1377: my (%currurls,%currexempt);
1378: if (ref($settings) eq 'HASH') {
1379: if (ref($settings->{'headtag'}) eq 'HASH') {
1380: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1381: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1382: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1383: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1384: }
1385: }
1386: }
1387: }
1388: my %lt = &Apache::lonlocal::texthash(
1389: del => 'Delete?',
1390: rep => 'Replace:',
1391: upl => 'Upload:',
1392: curr => 'View contents',
1393: none => 'None',
1394: );
1395: my $switchserver = &check_switchserver($dom,$confname);
1396: foreach my $lonhost (sort(keys(%domservers))) {
1397: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1398: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1399: if ($currurls{$lonhost}) {
1400: $datatable .= '<td class="LC_right_item"><a href="'.
1401: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1402: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1403: '">'.$lt{'curr'}.'</a></td>'.
1404: '<td><span class="LC_nobreak"><label>'.
1405: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1406: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1407: } else {
1408: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1409: }
1410: $datatable .='<br />';
1411: if ($switchserver) {
1412: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1413: } else {
1414: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1415: }
1416: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1417: }
1418: $datatable .= '</table></td></tr>';
1.1 raeburn 1419: }
1.6 raeburn 1420: return $datatable;
1421: }
1422:
1423: sub login_choices {
1424: my %choices =
1425: &Apache::lonlocal::texthash (
1.116 bisitz 1426: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1427: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1428: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1429: disallowlogin => "Login page requests redirected",
1430: hostid => "Server",
1.128 raeburn 1431: server => "Redirect to:",
1432: serverpath => "Path",
1433: custompath => "Custom",
1434: exempt => "Exempt IP(s)",
1.110 raeburn 1435: directlogin => "No redirect",
1436: newuser => "Link to create a user account",
1437: img => "Header",
1438: logo => "Main Logo",
1439: domlogo => "Domain Logo",
1440: login => "Log-in Header",
1441: textcol => "Text color",
1442: bgcol => "Box color",
1443: bgs => "Background colors",
1444: links => "Link colors",
1445: font => "Font color",
1446: pgbg => "Header",
1447: mainbg => "Page",
1448: sidebg => "Login box",
1449: link => "Link",
1450: alink => "Active link",
1451: vlink => "Visited link",
1.256 raeburn 1452: headtag => "Custom markup",
1453: action => "Action",
1454: current => "Current",
1.6 raeburn 1455: );
1456: return %choices;
1457: }
1458:
1459: sub print_rolecolors {
1.30 raeburn 1460: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1461: my %choices = &color_font_choices();
1462: my @bgs = ('pgbg','tabbg','sidebg');
1463: my @links = ('link','alink','vlink');
1464: my @images = ('img');
1465: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1466: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1467: my %defaultdesign = %Apache::loncommon::defaultdesign;
1468: my (%is_custom,%designs);
1.200 raeburn 1469: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1470: if (ref($settings) eq 'HASH') {
1471: if (ref($settings->{$role}) eq 'HASH') {
1472: if ($settings->{$role}->{'img'} ne '') {
1473: $designs{'img'} = $settings->{$role}->{'img'};
1474: $is_custom{'img'} = 1;
1475: }
1476: if ($settings->{$role}->{'font'} ne '') {
1477: $designs{'font'} = $settings->{$role}->{'font'};
1478: $is_custom{'font'} = 1;
1479: }
1.97 tempelho 1480: if ($settings->{$role}->{'fontmenu'} ne '') {
1481: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1482: $is_custom{'fontmenu'} = 1;
1483: }
1.6 raeburn 1484: foreach my $item (@bgs) {
1485: if ($settings->{$role}->{$item} ne '') {
1486: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1487: $is_custom{$item} = 1;
1488: }
1489: }
1490: foreach my $item (@links) {
1491: if ($settings->{$role}->{$item} ne '') {
1492: $designs{'links'}{$item} = $settings->{$role}->{$item};
1493: $is_custom{$item} = 1;
1494: }
1495: }
1496: }
1497: } else {
1498: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1499: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1500: $is_custom{'img'} = 1;
1501: }
1.97 tempelho 1502: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1503: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1504: $is_custom{'fontmenu'} = 1;
1505: }
1.6 raeburn 1506: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1507: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1508: $is_custom{'font'} = 1;
1509: }
1510: foreach my $item (@bgs) {
1511: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1512: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1513: $is_custom{$item} = 1;
1514:
1515: }
1516: }
1517: foreach my $item (@links) {
1518: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1519: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1520: $is_custom{$item} = 1;
1521: }
1522: }
1523: }
1524: my $itemcount = 1;
1.30 raeburn 1525: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1526: $datatable .= '</tr></table></td></tr>';
1527: return $datatable;
1528: }
1529:
1.200 raeburn 1530: sub role_defaults {
1531: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1532: my %defaults;
1533: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1534: return %defaults;
1535: }
1536: my %defaultdesign = %Apache::loncommon::defaultdesign;
1537: if ($role eq 'login') {
1538: %defaults = (
1539: font => $defaultdesign{$role.'.font'},
1540: );
1541: if (ref($logintext) eq 'ARRAY') {
1542: foreach my $item (@{$logintext}) {
1543: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1544: }
1545: }
1546: foreach my $item (@{$images}) {
1547: $defaults{'showlogo'}{$item} = 1;
1548: }
1549: } else {
1550: %defaults = (
1551: img => $defaultdesign{$role.'.img'},
1552: font => $defaultdesign{$role.'.font'},
1553: fontmenu => $defaultdesign{$role.'.fontmenu'},
1554: );
1555: }
1556: foreach my $item (@{$bgs}) {
1557: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1558: }
1559: foreach my $item (@{$links}) {
1560: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1561: }
1562: foreach my $item (@{$images}) {
1563: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1564: }
1565: return %defaults;
1566: }
1567:
1.6 raeburn 1568: sub display_color_options {
1.9 raeburn 1569: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1570: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1571: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1572: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1573: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1574: '<td>'.$choices->{'font'}.'</td>';
1575: if (!$is_custom->{'font'}) {
1.30 raeburn 1576: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1577: } else {
1578: $datatable .= '<td> </td>';
1579: }
1.174 foxr 1580: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1581:
1.8 raeburn 1582: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1583: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1584: ' value="'.$current_color.'" /> '.
1.174 foxr 1585: ' </td></tr>';
1.107 raeburn 1586: unless ($role eq 'login') {
1587: $datatable .= '<tr'.$css_class.'>'.
1588: '<td>'.$choices->{'fontmenu'}.'</td>';
1589: if (!$is_custom->{'fontmenu'}) {
1590: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1591: } else {
1592: $datatable .= '<td> </td>';
1593: }
1.202 raeburn 1594: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1595: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1596: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1597: '<input class="colorchooser" type="text" size="10" name="'
1598: .$role.'_fontmenu"'.
1599: ' value="'.$current_color.'" /> '.
1600: ' </td></tr>';
1.97 tempelho 1601: }
1.9 raeburn 1602: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1603: foreach my $img (@{$images}) {
1.18 albertel 1604: $itemcount ++;
1.6 raeburn 1605: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1606: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1607: '<td>'.$choices->{$img};
1.41 raeburn 1608: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1609: if ($role eq 'login') {
1610: if ($img eq 'login') {
1611: $login_hdr_pick =
1.135 bisitz 1612: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1613: $logincolors =
1614: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1615: $designs,$defaults);
1.70 raeburn 1616: } elsif ($img ne 'domlogo') {
1617: $datatable.= &logo_display_options($img,$defaults,$designs);
1618: }
1619: }
1620: $datatable .= '</td>';
1.6 raeburn 1621: if ($designs->{$img} ne '') {
1622: $imgfile = $designs->{$img};
1.18 albertel 1623: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1624: } else {
1625: $imgfile = $defaults->{$img};
1626: }
1627: if ($imgfile) {
1.9 raeburn 1628: my ($showfile,$fullsize);
1629: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1630: my $urldir = $1;
1631: my $filename = $2;
1632: my @info = &Apache::lonnet::stat_file($designs->{$img});
1633: if (@info) {
1634: my $thumbfile = 'tn-'.$filename;
1635: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1636: if (@thumb) {
1637: $showfile = $urldir.'/'.$thumbfile;
1638: } else {
1639: $showfile = $imgfile;
1640: }
1641: } else {
1642: $showfile = '';
1643: }
1644: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1645: $showfile = $imgfile;
1.6 raeburn 1646: my $imgdir = $1;
1647: my $filename = $2;
1.159 raeburn 1648: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1649: $showfile = "/$imgdir/tn-".$filename;
1650: } else {
1.159 raeburn 1651: my $input = $londocroot.$imgfile;
1652: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1653: if (!-e $output) {
1.9 raeburn 1654: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1655: my ($fullwidth,$fullheight) = &check_dimensions($input);
1656: if ($fullwidth ne '' && $fullheight ne '') {
1657: if ($fullwidth > $width && $fullheight > $height) {
1658: my $size = $width.'x'.$height;
1659: system("convert -sample $size $input $output");
1.159 raeburn 1660: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1661: }
1662: }
1.6 raeburn 1663: }
1664: }
1.16 raeburn 1665: }
1.6 raeburn 1666: if ($showfile) {
1.40 raeburn 1667: if ($showfile =~ m{^/(adm|res)/}) {
1668: if ($showfile =~ m{^/res/}) {
1669: my $local_showfile =
1670: &Apache::lonnet::filelocation('',$showfile);
1671: &Apache::lonnet::repcopy($local_showfile);
1672: }
1673: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1674: }
1675: if ($imgfile) {
1676: if ($imgfile =~ m{^/(adm|res)/}) {
1677: if ($imgfile =~ m{^/res/}) {
1678: my $local_imgfile =
1679: &Apache::lonnet::filelocation('',$imgfile);
1680: &Apache::lonnet::repcopy($local_imgfile);
1681: }
1682: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1683: } else {
1684: $fullsize = $imgfile;
1685: }
1686: }
1.41 raeburn 1687: $datatable .= '<td>';
1688: if ($img eq 'login') {
1.135 bisitz 1689: $datatable .= $login_hdr_pick;
1690: }
1.41 raeburn 1691: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1692: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1693: } else {
1.201 raeburn 1694: $datatable .= '<td> </td><td class="LC_left_item">'.
1695: &mt('Upload:').'<br />';
1.6 raeburn 1696: }
1697: } else {
1.201 raeburn 1698: $datatable .= '<td> </td><td class="LC_left_item">'.
1699: &mt('Upload:').'<br />';
1.6 raeburn 1700: }
1.9 raeburn 1701: if ($switchserver) {
1702: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1703: } else {
1.135 bisitz 1704: if ($img ne 'login') { # suppress file selection for Log-in header
1705: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1706: }
1.9 raeburn 1707: }
1708: $datatable .= '</td></tr>';
1.6 raeburn 1709: }
1710: $itemcount ++;
1711: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1712: $datatable .= '<tr'.$css_class.'>'.
1713: '<td>'.$choices->{'bgs'}.'</td>';
1714: my $bgs_def;
1715: foreach my $item (@{$bgs}) {
1716: if (!$is_custom->{$item}) {
1.70 raeburn 1717: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1718: }
1719: }
1720: if ($bgs_def) {
1.8 raeburn 1721: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1722: } else {
1723: $datatable .= '<td> </td>';
1724: }
1725: $datatable .= '<td class="LC_right_item">'.
1726: '<table border="0"><tr>';
1.174 foxr 1727:
1.6 raeburn 1728: foreach my $item (@{$bgs}) {
1.306 raeburn 1729: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 1730: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1731: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1732: $datatable .= ' ';
1.6 raeburn 1733: }
1.174 foxr 1734: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1735: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1736: }
1737: $datatable .= '</tr></table></td></tr>';
1738: $itemcount ++;
1739: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1740: $datatable .= '<tr'.$css_class.'>'.
1741: '<td>'.$choices->{'links'}.'</td>';
1742: my $links_def;
1743: foreach my $item (@{$links}) {
1744: if (!$is_custom->{$item}) {
1.30 raeburn 1745: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1746: }
1747: }
1748: if ($links_def) {
1.8 raeburn 1749: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1750: } else {
1751: $datatable .= '<td> </td>';
1752: }
1753: $datatable .= '<td class="LC_right_item">'.
1754: '<table border="0"><tr>';
1755: foreach my $item (@{$links}) {
1.234 raeburn 1756: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 1757: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 1758: if ($designs->{'links'}{$item}) {
1.174 foxr 1759: $datatable.=' ';
1.6 raeburn 1760: }
1.174 foxr 1761: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1762: '" /></td>';
1763: }
1.30 raeburn 1764: $$rowtotal += $itemcount;
1.3 raeburn 1765: return $datatable;
1766: }
1767:
1.70 raeburn 1768: sub logo_display_options {
1769: my ($img,$defaults,$designs) = @_;
1770: my $checkedon;
1771: if (ref($defaults) eq 'HASH') {
1772: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1773: if ($defaults->{'showlogo'}{$img}) {
1774: $checkedon = 'checked="checked" ';
1775: }
1776: }
1777: }
1778: if (ref($designs) eq 'HASH') {
1779: if (ref($designs->{'showlogo'}) eq 'HASH') {
1780: if (defined($designs->{'showlogo'}{$img})) {
1781: if ($designs->{'showlogo'}{$img} == 0) {
1782: $checkedon = '';
1783: } elsif ($designs->{'showlogo'}{$img} == 1) {
1784: $checkedon = 'checked="checked" ';
1785: }
1786: }
1787: }
1788: }
1789: return '<br /><label> <input type="checkbox" name="'.
1790: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1791: &mt('show').'</label>'."\n";
1792: }
1793:
1.41 raeburn 1794: sub login_header_options {
1.135 bisitz 1795: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1796: my $output = '';
1.41 raeburn 1797: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1798: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1799: if (!$is_custom->{'textcol'}) {
1800: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1801: ' ';
1802: }
1803: if (!$is_custom->{'bgcol'}) {
1804: $output .= $choices->{'bgcol'}.': '.
1805: '<span id="css_'.$role.'_font" style="background-color: '.
1806: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1807: }
1808: $output .= '<br />';
1809: }
1810: $output .='<br />';
1811: return $output;
1812: }
1813:
1814: sub login_text_colors {
1.201 raeburn 1815: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1816: my $color_menu = '<table border="0"><tr>';
1817: foreach my $item (@{$logintext}) {
1.306 raeburn 1818: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 1819: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1820: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1821: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1822: }
1823: $color_menu .= '</tr></table><br />';
1824: return $color_menu;
1825: }
1826:
1827: sub image_changes {
1828: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1829: my $output;
1.135 bisitz 1830: if ($img eq 'login') {
1831: # suppress image for Log-in header
1832: } elsif (!$is_custom) {
1.70 raeburn 1833: if ($img ne 'domlogo') {
1.41 raeburn 1834: $output .= &mt('Default image:').'<br />';
1835: } else {
1836: $output .= &mt('Default in use:').'<br />';
1837: }
1838: }
1.135 bisitz 1839: if ($img eq 'login') { # suppress image for Log-in header
1840: $output .= '<td>'.$logincolors;
1.41 raeburn 1841: } else {
1.135 bisitz 1842: if ($img_import) {
1843: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1844: }
1845: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1846: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1847: if ($is_custom) {
1848: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1849: '<input type="checkbox" name="'.
1850: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1851: '</label> '.&mt('Replace:').'</span><br />';
1852: } else {
1.306 raeburn 1853: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1854: }
1.41 raeburn 1855: }
1856: return $output;
1857: }
1858:
1.3 raeburn 1859: sub print_quotas {
1.86 raeburn 1860: my ($dom,$settings,$rowtotal,$action) = @_;
1861: my $context;
1862: if ($action eq 'quotas') {
1863: $context = 'tools';
1864: } else {
1865: $context = $action;
1866: }
1.197 raeburn 1867: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1868: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1869: my $typecount = 0;
1.101 raeburn 1870: my ($css_class,%titles);
1.86 raeburn 1871: if ($context eq 'requestcourses') {
1.271 raeburn 1872: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1873: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1874: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1875: %titles = &courserequest_titles();
1.163 raeburn 1876: } elsif ($context eq 'requestauthor') {
1877: @usertools = ('author');
1878: @options = ('norequest','approval','automatic');
1.210 raeburn 1879: %titles = &authorrequest_titles();
1.86 raeburn 1880: } else {
1.162 raeburn 1881: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1882: %titles = &tool_titles();
1.86 raeburn 1883: }
1.26 raeburn 1884: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1885: foreach my $type (@{$types}) {
1.197 raeburn 1886: my ($currdefquota,$currauthorquota);
1.163 raeburn 1887: unless (($context eq 'requestcourses') ||
1888: ($context eq 'requestauthor')) {
1.86 raeburn 1889: if (ref($settings) eq 'HASH') {
1890: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1891: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1892: } else {
1893: $currdefquota = $settings->{$type};
1894: }
1.197 raeburn 1895: if (ref($settings->{authorquota}) eq 'HASH') {
1896: $currauthorquota = $settings->{authorquota}->{$type};
1897: }
1.78 raeburn 1898: }
1.72 raeburn 1899: }
1.3 raeburn 1900: if (defined($usertypes->{$type})) {
1901: $typecount ++;
1902: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1903: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1904: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1905: '<td class="LC_left_item">';
1.101 raeburn 1906: if ($context eq 'requestcourses') {
1907: $datatable .= '<table><tr>';
1908: }
1909: my %cell;
1.72 raeburn 1910: foreach my $item (@usertools) {
1.101 raeburn 1911: if ($context eq 'requestcourses') {
1912: my ($curroption,$currlimit);
1913: if (ref($settings) eq 'HASH') {
1914: if (ref($settings->{$item}) eq 'HASH') {
1915: $curroption = $settings->{$item}->{$type};
1916: if ($curroption =~ /^autolimit=(\d*)$/) {
1917: $currlimit = $1;
1918: }
1919: }
1920: }
1921: if (!$curroption) {
1922: $curroption = 'norequest';
1923: }
1924: $datatable .= '<th>'.$titles{$item}.'</th>';
1925: foreach my $option (@options) {
1926: my $val = $option;
1927: if ($option eq 'norequest') {
1928: $val = 0;
1929: }
1930: if ($option eq 'validate') {
1931: my $canvalidate = 0;
1932: if (ref($validations{$item}) eq 'HASH') {
1933: if ($validations{$item}{$type}) {
1934: $canvalidate = 1;
1935: }
1936: }
1937: next if (!$canvalidate);
1938: }
1939: my $checked = '';
1940: if ($option eq $curroption) {
1941: $checked = ' checked="checked"';
1942: } elsif ($option eq 'autolimit') {
1943: if ($curroption =~ /^autolimit/) {
1944: $checked = ' checked="checked"';
1945: }
1946: }
1947: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1948: '<input type="radio" name="crsreq_'.$item.
1949: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1950: $titles{$option}.'</label>';
1.101 raeburn 1951: if ($option eq 'autolimit') {
1.127 raeburn 1952: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1953: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1954: 'value="'.$currlimit.'" />';
1.101 raeburn 1955: }
1.127 raeburn 1956: $cell{$item} .= '</span> ';
1.103 raeburn 1957: if ($option eq 'autolimit') {
1.127 raeburn 1958: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1959: }
1.101 raeburn 1960: }
1.163 raeburn 1961: } elsif ($context eq 'requestauthor') {
1962: my $curroption;
1963: if (ref($settings) eq 'HASH') {
1964: $curroption = $settings->{$type};
1965: }
1966: if (!$curroption) {
1967: $curroption = 'norequest';
1968: }
1969: foreach my $option (@options) {
1970: my $val = $option;
1971: if ($option eq 'norequest') {
1972: $val = 0;
1973: }
1974: my $checked = '';
1975: if ($option eq $curroption) {
1976: $checked = ' checked="checked"';
1977: }
1978: $datatable .= '<span class="LC_nobreak"><label>'.
1979: '<input type="radio" name="authorreq_'.$type.
1980: '" value="'.$val.'"'.$checked.' />'.
1981: $titles{$option}.'</label></span> ';
1982: }
1.101 raeburn 1983: } else {
1984: my $checked = 'checked="checked" ';
1985: if (ref($settings) eq 'HASH') {
1986: if (ref($settings->{$item}) eq 'HASH') {
1987: if ($settings->{$item}->{$type} == 0) {
1988: $checked = '';
1989: } elsif ($settings->{$item}->{$type} == 1) {
1990: $checked = 'checked="checked" ';
1991: }
1.78 raeburn 1992: }
1.72 raeburn 1993: }
1.101 raeburn 1994: $datatable .= '<span class="LC_nobreak"><label>'.
1995: '<input type="checkbox" name="'.$context.'_'.$item.
1996: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1997: '</label></span> ';
1.72 raeburn 1998: }
1.101 raeburn 1999: }
2000: if ($context eq 'requestcourses') {
2001: $datatable .= '</tr><tr>';
2002: foreach my $item (@usertools) {
1.106 raeburn 2003: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2004: }
2005: $datatable .= '</tr></table>';
1.72 raeburn 2006: }
1.86 raeburn 2007: $datatable .= '</td>';
1.163 raeburn 2008: unless (($context eq 'requestcourses') ||
2009: ($context eq 'requestauthor')) {
1.86 raeburn 2010: $datatable .=
1.197 raeburn 2011: '<td class="LC_right_item">'.
2012: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2013: '<input type="text" name="quota_'.$type.
1.72 raeburn 2014: '" value="'.$currdefquota.
1.197 raeburn 2015: '" size="5" /></span>'.(' ' x 2).
2016: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2017: '<input type="text" name="authorquota_'.$type.
2018: '" value="'.$currauthorquota.
2019: '" size="5" /></span></td>';
1.86 raeburn 2020: }
2021: $datatable .= '</tr>';
1.3 raeburn 2022: }
2023: }
2024: }
1.163 raeburn 2025: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2026: $defaultquota = '20';
1.197 raeburn 2027: $authorquota = '500';
1.86 raeburn 2028: if (ref($settings) eq 'HASH') {
2029: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2030: $defaultquota = $settings->{'defaultquota'}->{'default'};
2031: } elsif (defined($settings->{'default'})) {
2032: $defaultquota = $settings->{'default'};
2033: }
1.197 raeburn 2034: if (ref($settings->{'authorquota'}) eq 'HASH') {
2035: $authorquota = $settings->{'authorquota'}->{'default'};
2036: }
1.3 raeburn 2037: }
2038: }
2039: $typecount ++;
2040: $css_class = $typecount%2?' class="LC_odd_row"':'';
2041: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2042: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2043: '<td class="LC_left_item">';
1.101 raeburn 2044: if ($context eq 'requestcourses') {
2045: $datatable .= '<table><tr>';
2046: }
2047: my %defcell;
1.72 raeburn 2048: foreach my $item (@usertools) {
1.101 raeburn 2049: if ($context eq 'requestcourses') {
2050: my ($curroption,$currlimit);
2051: if (ref($settings) eq 'HASH') {
2052: if (ref($settings->{$item}) eq 'HASH') {
2053: $curroption = $settings->{$item}->{'default'};
2054: if ($curroption =~ /^autolimit=(\d*)$/) {
2055: $currlimit = $1;
2056: }
2057: }
2058: }
2059: if (!$curroption) {
2060: $curroption = 'norequest';
2061: }
2062: $datatable .= '<th>'.$titles{$item}.'</th>';
2063: foreach my $option (@options) {
2064: my $val = $option;
2065: if ($option eq 'norequest') {
2066: $val = 0;
2067: }
2068: if ($option eq 'validate') {
2069: my $canvalidate = 0;
2070: if (ref($validations{$item}) eq 'HASH') {
2071: if ($validations{$item}{'default'}) {
2072: $canvalidate = 1;
2073: }
2074: }
2075: next if (!$canvalidate);
2076: }
2077: my $checked = '';
2078: if ($option eq $curroption) {
2079: $checked = ' checked="checked"';
2080: } elsif ($option eq 'autolimit') {
2081: if ($curroption =~ /^autolimit/) {
2082: $checked = ' checked="checked"';
2083: }
2084: }
2085: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2086: '<input type="radio" name="crsreq_'.$item.
2087: '_default" value="'.$val.'"'.$checked.' />'.
2088: $titles{$option}.'</label>';
2089: if ($option eq 'autolimit') {
1.127 raeburn 2090: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2091: $item.'_limit_default" size="1" '.
2092: 'value="'.$currlimit.'" />';
2093: }
1.127 raeburn 2094: $defcell{$item} .= '</span> ';
1.104 raeburn 2095: if ($option eq 'autolimit') {
1.127 raeburn 2096: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2097: }
1.101 raeburn 2098: }
1.163 raeburn 2099: } elsif ($context eq 'requestauthor') {
2100: my $curroption;
2101: if (ref($settings) eq 'HASH') {
1.172 raeburn 2102: $curroption = $settings->{'default'};
1.163 raeburn 2103: }
2104: if (!$curroption) {
2105: $curroption = 'norequest';
2106: }
2107: foreach my $option (@options) {
2108: my $val = $option;
2109: if ($option eq 'norequest') {
2110: $val = 0;
2111: }
2112: my $checked = '';
2113: if ($option eq $curroption) {
2114: $checked = ' checked="checked"';
2115: }
2116: $datatable .= '<span class="LC_nobreak"><label>'.
2117: '<input type="radio" name="authorreq_default"'.
2118: ' value="'.$val.'"'.$checked.' />'.
2119: $titles{$option}.'</label></span> ';
2120: }
1.101 raeburn 2121: } else {
2122: my $checked = 'checked="checked" ';
2123: if (ref($settings) eq 'HASH') {
2124: if (ref($settings->{$item}) eq 'HASH') {
2125: if ($settings->{$item}->{'default'} == 0) {
2126: $checked = '';
2127: } elsif ($settings->{$item}->{'default'} == 1) {
2128: $checked = 'checked="checked" ';
2129: }
1.78 raeburn 2130: }
1.72 raeburn 2131: }
1.101 raeburn 2132: $datatable .= '<span class="LC_nobreak"><label>'.
2133: '<input type="checkbox" name="'.$context.'_'.$item.
2134: '" value="default" '.$checked.'/>'.$titles{$item}.
2135: '</label></span> ';
2136: }
2137: }
2138: if ($context eq 'requestcourses') {
2139: $datatable .= '</tr><tr>';
2140: foreach my $item (@usertools) {
1.106 raeburn 2141: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2142: }
1.101 raeburn 2143: $datatable .= '</tr></table>';
1.72 raeburn 2144: }
1.86 raeburn 2145: $datatable .= '</td>';
1.163 raeburn 2146: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2147: $datatable .= '<td class="LC_right_item">'.
2148: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2149: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2150: $defaultquota.'" size="5" /></span>'.(' ' x2).
2151: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2152: '<input type="text" name="authorquota" value="'.
2153: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2154: }
2155: $datatable .= '</tr>';
1.72 raeburn 2156: $typecount ++;
2157: $css_class = $typecount%2?' class="LC_odd_row"':'';
2158: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2159: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2160: if ($context eq 'requestcourses') {
1.109 raeburn 2161: $datatable .= &mt('(overrides affiliation, if set)').
2162: '</td>'.
2163: '<td class="LC_left_item">'.
2164: '<table><tr>';
1.101 raeburn 2165: } else {
1.109 raeburn 2166: $datatable .= &mt('(overrides affiliation, if checked)').
2167: '</td>'.
2168: '<td class="LC_left_item" colspan="2">'.
2169: '<br />';
1.101 raeburn 2170: }
2171: my %advcell;
1.72 raeburn 2172: foreach my $item (@usertools) {
1.101 raeburn 2173: if ($context eq 'requestcourses') {
2174: my ($curroption,$currlimit);
2175: if (ref($settings) eq 'HASH') {
2176: if (ref($settings->{$item}) eq 'HASH') {
2177: $curroption = $settings->{$item}->{'_LC_adv'};
2178: if ($curroption =~ /^autolimit=(\d*)$/) {
2179: $currlimit = $1;
2180: }
2181: }
2182: }
2183: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2184: my $checked = '';
2185: if ($curroption eq '') {
2186: $checked = ' checked="checked"';
2187: }
2188: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2189: '<input type="radio" name="crsreq_'.$item.
2190: '__LC_adv" value=""'.$checked.' />'.
2191: &mt('No override set').'</label></span> ';
1.101 raeburn 2192: foreach my $option (@options) {
2193: my $val = $option;
2194: if ($option eq 'norequest') {
2195: $val = 0;
2196: }
2197: if ($option eq 'validate') {
2198: my $canvalidate = 0;
2199: if (ref($validations{$item}) eq 'HASH') {
2200: if ($validations{$item}{'_LC_adv'}) {
2201: $canvalidate = 1;
2202: }
2203: }
2204: next if (!$canvalidate);
2205: }
2206: my $checked = '';
1.104 raeburn 2207: if ($val eq $curroption) {
1.101 raeburn 2208: $checked = ' checked="checked"';
2209: } elsif ($option eq 'autolimit') {
2210: if ($curroption =~ /^autolimit/) {
2211: $checked = ' checked="checked"';
2212: }
2213: }
2214: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2215: '<input type="radio" name="crsreq_'.$item.
2216: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2217: $titles{$option}.'</label>';
2218: if ($option eq 'autolimit') {
1.127 raeburn 2219: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2220: $item.'_limit__LC_adv" size="1" '.
2221: 'value="'.$currlimit.'" />';
2222: }
1.127 raeburn 2223: $advcell{$item} .= '</span> ';
1.104 raeburn 2224: if ($option eq 'autolimit') {
1.127 raeburn 2225: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2226: }
1.101 raeburn 2227: }
1.163 raeburn 2228: } elsif ($context eq 'requestauthor') {
2229: my $curroption;
2230: if (ref($settings) eq 'HASH') {
2231: $curroption = $settings->{'_LC_adv'};
2232: }
2233: my $checked = '';
2234: if ($curroption eq '') {
2235: $checked = ' checked="checked"';
2236: }
2237: $datatable .= '<span class="LC_nobreak"><label>'.
2238: '<input type="radio" name="authorreq__LC_adv"'.
2239: ' value=""'.$checked.' />'.
2240: &mt('No override set').'</label></span> ';
2241: foreach my $option (@options) {
2242: my $val = $option;
2243: if ($option eq 'norequest') {
2244: $val = 0;
2245: }
2246: my $checked = '';
2247: if ($val eq $curroption) {
2248: $checked = ' checked="checked"';
2249: }
2250: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2251: '<input type="radio" name="authorreq__LC_adv"'.
2252: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2253: $titles{$option}.'</label></span> ';
2254: }
1.101 raeburn 2255: } else {
2256: my $checked = 'checked="checked" ';
2257: if (ref($settings) eq 'HASH') {
2258: if (ref($settings->{$item}) eq 'HASH') {
2259: if ($settings->{$item}->{'_LC_adv'} == 0) {
2260: $checked = '';
2261: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2262: $checked = 'checked="checked" ';
2263: }
1.79 raeburn 2264: }
1.72 raeburn 2265: }
1.101 raeburn 2266: $datatable .= '<span class="LC_nobreak"><label>'.
2267: '<input type="checkbox" name="'.$context.'_'.$item.
2268: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2269: '</label></span> ';
2270: }
2271: }
2272: if ($context eq 'requestcourses') {
2273: $datatable .= '</tr><tr>';
2274: foreach my $item (@usertools) {
1.106 raeburn 2275: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2276: }
1.101 raeburn 2277: $datatable .= '</tr></table>';
1.72 raeburn 2278: }
1.98 raeburn 2279: $datatable .= '</td></tr>';
1.30 raeburn 2280: $$rowtotal += $typecount;
1.3 raeburn 2281: return $datatable;
2282: }
2283:
1.163 raeburn 2284: sub print_requestmail {
1.305 raeburn 2285: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2286: my ($now,$datatable,%currapp);
1.102 raeburn 2287: $now = time;
2288: if (ref($settings) eq 'HASH') {
2289: if (ref($settings->{'notify'}) eq 'HASH') {
2290: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2291: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2292: }
2293: }
2294: }
1.191 raeburn 2295: my $numinrow = 2;
1.224 raeburn 2296: my $css_class;
1.305 raeburn 2297: if ($$rowtotal%2) {
2298: $css_class = 'LC_odd_row';
2299: }
2300: if ($customcss) {
2301: $css_class .= " $customcss";
2302: }
2303: $css_class =~ s/^\s+//;
2304: if ($css_class) {
2305: $css_class = ' class="'.$css_class.'"';
2306: }
2307: if ($rowstyle) {
2308: $css_class .= ' style="'.$rowstyle.'"';
2309: }
1.163 raeburn 2310: my $text;
2311: if ($action eq 'requestcourses') {
2312: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2313: } elsif ($action eq 'requestauthor') {
2314: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2315: } else {
1.224 raeburn 2316: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2317: }
1.224 raeburn 2318: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2319: ' <td>'.$text.'</td>'.
1.102 raeburn 2320: ' <td class="LC_left_item">';
1.191 raeburn 2321: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2322: $action.'notifyapproval',%currapp);
1.191 raeburn 2323: if ($numdc > 0) {
2324: $datatable .= $table;
1.102 raeburn 2325: } else {
2326: $datatable .= &mt('There are no active Domain Coordinators');
2327: }
2328: $datatable .='</td></tr>';
2329: return $datatable;
2330: }
2331:
1.216 raeburn 2332: sub print_studentcode {
2333: my ($settings,$rowtotal) = @_;
2334: my $rownum = 0;
1.218 raeburn 2335: my ($output,%current);
1.271 raeburn 2336: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2337: if (ref($settings) eq 'HASH') {
2338: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2339: foreach my $type (@crstypes) {
2340: $current{$type} = $settings->{'uniquecode'}{$type};
2341: }
1.218 raeburn 2342: }
2343: }
2344: $output .= '<tr>'.
2345: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2346: '<td class="LC_left_item">';
2347: foreach my $type (@crstypes) {
2348: my $check = ' ';
2349: if ($current{$type}) {
2350: $check = ' checked="checked" ';
2351: }
2352: $output .= '<span class="LC_nobreak"><label>'.
2353: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2354: &mt($type).'</label></span>'.(' 'x2).' ';
2355: }
2356: $output .= '</td></tr>';
2357: $$rowtotal ++;
2358: return $output;
1.216 raeburn 2359: }
2360:
2361: sub print_textbookcourses {
1.242 raeburn 2362: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2363: my $rownum = 0;
2364: my $css_class;
2365: my $itemcount = 1;
2366: my $maxnum = 0;
2367: my $bookshash;
2368: if (ref($settings) eq 'HASH') {
1.242 raeburn 2369: $bookshash = $settings->{$type};
1.216 raeburn 2370: }
2371: my %ordered;
2372: if (ref($bookshash) eq 'HASH') {
2373: foreach my $item (keys(%{$bookshash})) {
2374: if (ref($bookshash->{$item}) eq 'HASH') {
2375: my $num = $bookshash->{$item}{'order'};
2376: $ordered{$num} = $item;
2377: }
2378: }
2379: }
2380: my $confname = $dom.'-domainconfig';
2381: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2382: my $maxnum = scalar(keys(%ordered));
2383: my $datatable;
1.216 raeburn 2384: if (keys(%ordered)) {
2385: my @items = sort { $a <=> $b } keys(%ordered);
2386: for (my $i=0; $i<@items; $i++) {
2387: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2388: my $key = $ordered{$items[$i]};
2389: my %coursehash=&Apache::lonnet::coursedescription($key);
2390: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2391: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2392: if (ref($bookshash->{$key}) eq 'HASH') {
2393: $subject = $bookshash->{$key}->{'subject'};
2394: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2395: if ($type eq 'textbooks') {
1.243 raeburn 2396: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2397: $author = $bookshash->{$key}->{'author'};
2398: $image = $bookshash->{$key}->{'image'};
2399: if ($image ne '') {
2400: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2401: my $imagethumb = "$path/tn-".$imagefile;
2402: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2403: }
1.216 raeburn 2404: }
2405: }
1.242 raeburn 2406: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2407: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2408: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2409: for (my $k=0; $k<=$maxnum; $k++) {
2410: my $vpos = $k+1;
2411: my $selstr;
2412: if ($k == $i) {
2413: $selstr = ' selected="selected" ';
2414: }
2415: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2416: }
2417: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2418: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2419: &mt('Delete?').'</label></span></td>'.
2420: '<td colspan="2">'.
1.242 raeburn 2421: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2422: (' 'x2).
1.242 raeburn 2423: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2424: if ($type eq 'textbooks') {
2425: $datatable .= (' 'x2).
1.243 raeburn 2426: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2427: (' 'x2).
1.242 raeburn 2428: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2429: (' 'x2).
2430: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2431: if ($image) {
1.267 raeburn 2432: $datatable .= $imgsrc.
1.242 raeburn 2433: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2434: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2435: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2436: }
2437: if ($switchserver) {
2438: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2439: } else {
2440: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2441: }
1.216 raeburn 2442: }
1.242 raeburn 2443: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2444: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2445: $coursetitle.'</span></td></tr>'."\n";
2446: $itemcount ++;
2447: }
2448: }
2449: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2450: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2451: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2452: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2453: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2454: for (my $k=0; $k<$maxnum+1; $k++) {
2455: my $vpos = $k+1;
2456: my $selstr;
2457: if ($k == $maxnum) {
2458: $selstr = ' selected="selected" ';
2459: }
2460: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2461: }
2462: $datatable .= '</select> '."\n".
1.242 raeburn 2463: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2464: '<td colspan="2">'.
1.242 raeburn 2465: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2466: (' 'x2).
1.242 raeburn 2467: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2468: (' 'x2);
2469: if ($type eq 'textbooks') {
1.243 raeburn 2470: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2471: (' 'x2).
2472: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2473: (' 'x2).
2474: '<span class="LC_nobreak">'.&mt('Image:').' ';
2475: if ($switchserver) {
2476: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2477: } else {
2478: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2479: }
1.216 raeburn 2480: }
2481: $datatable .= '</span>'."\n".
2482: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2483: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2484: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2485: &Apache::loncommon::selectcourse_link
1.242 raeburn 2486: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2487: '</span></td>'."\n".
2488: '</tr>'."\n";
2489: $itemcount ++;
2490: return $datatable;
2491: }
2492:
1.217 raeburn 2493: sub textbookcourses_javascript {
1.242 raeburn 2494: my ($settings) = @_;
2495: return unless(ref($settings) eq 'HASH');
2496: my (%ordered,%total,%jstext);
2497: foreach my $type ('textbooks','templates') {
2498: $total{$type} = 0;
2499: if (ref($settings->{$type}) eq 'HASH') {
2500: foreach my $item (keys(%{$settings->{$type}})) {
2501: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2502: my $num = $settings->{$type}->{$item}{'order'};
2503: $ordered{$type}{$num} = $item;
2504: }
2505: }
2506: $total{$type} = scalar(keys(%{$settings->{$type}}));
2507: }
2508: my @jsarray = ();
2509: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2510: push(@jsarray,$ordered{$type}{$item});
2511: }
2512: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2513: }
2514: return <<"ENDSCRIPT";
2515: <script type="text/javascript">
2516: // <![CDATA[
1.242 raeburn 2517: function reorderBooks(form,item,caller) {
1.217 raeburn 2518: var changedVal;
1.242 raeburn 2519: $jstext{'textbooks'};
2520: $jstext{'templates'};
2521: var newpos;
2522: var maxh;
2523: if (caller == 'textbooks') {
2524: newpos = 'textbooks_addbook_pos';
2525: maxh = 1 + $total{'textbooks'};
2526: } else {
2527: newpos = 'templates_addbook_pos';
2528: maxh = 1 + $total{'templates'};
2529: }
1.217 raeburn 2530: var current = new Array;
2531: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2532: if (item == newpos) {
2533: changedVal = newitemVal;
2534: } else {
2535: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2536: current[newitemVal] = newpos;
2537: }
1.242 raeburn 2538: if (caller == 'textbooks') {
2539: for (var i=0; i<textbooks.length; i++) {
2540: var elementName = 'textbooks_'+textbooks[i];
2541: if (elementName != item) {
2542: if (form.elements[elementName]) {
2543: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2544: current[currVal] = elementName;
2545: }
2546: }
2547: }
2548: }
2549: if (caller == 'templates') {
2550: for (var i=0; i<templates.length; i++) {
2551: var elementName = 'templates_'+templates[i];
2552: if (elementName != item) {
2553: if (form.elements[elementName]) {
2554: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2555: current[currVal] = elementName;
2556: }
1.217 raeburn 2557: }
2558: }
2559: }
2560: var oldVal;
2561: for (var j=0; j<maxh; j++) {
2562: if (current[j] == undefined) {
2563: oldVal = j;
2564: }
2565: }
2566: if (oldVal < changedVal) {
2567: for (var k=oldVal+1; k<=changedVal ; k++) {
2568: var elementName = current[k];
2569: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2570: }
2571: } else {
2572: for (var k=changedVal; k<oldVal; k++) {
2573: var elementName = current[k];
2574: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2575: }
2576: }
2577: return;
2578: }
2579:
2580: // ]]>
2581: </script>
2582:
2583: ENDSCRIPT
2584: }
2585:
1.267 raeburn 2586: sub ltitools_javascript {
2587: my ($settings) = @_;
2588: return unless(ref($settings) eq 'HASH');
2589: my (%ordered,$total,%jstext);
2590: $total = 0;
2591: foreach my $item (keys(%{$settings})) {
2592: if (ref($settings->{$item}) eq 'HASH') {
2593: my $num = $settings->{$item}{'order'};
2594: $ordered{$num} = $item;
2595: }
2596: }
2597: $total = scalar(keys(%{$settings}));
2598: my @jsarray = ();
2599: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2600: push(@jsarray,$ordered{$item});
2601: }
2602: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2603: return <<"ENDSCRIPT";
2604: <script type="text/javascript">
2605: // <![CDATA[
2606: function reorderLTI(form,item) {
2607: var changedVal;
2608: $jstext
2609: var newpos = 'ltitools_add_pos';
2610: var maxh = 1 + $total;
2611: var current = new Array;
2612: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2613: if (item == newpos) {
2614: changedVal = newitemVal;
2615: } else {
2616: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2617: current[newitemVal] = newpos;
2618: }
2619: for (var i=0; i<ltitools.length; i++) {
2620: var elementName = 'ltitools_'+ltitools[i];
2621: if (elementName != item) {
2622: if (form.elements[elementName]) {
2623: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2624: current[currVal] = elementName;
2625: }
2626: }
2627: }
2628: var oldVal;
2629: for (var j=0; j<maxh; j++) {
2630: if (current[j] == undefined) {
2631: oldVal = j;
2632: }
2633: }
2634: if (oldVal < changedVal) {
2635: for (var k=oldVal+1; k<=changedVal ; k++) {
2636: var elementName = current[k];
2637: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2638: }
2639: } else {
2640: for (var k=changedVal; k<oldVal; k++) {
2641: var elementName = current[k];
2642: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2643: }
2644: }
2645: return;
2646: }
2647:
2648: // ]]>
2649: </script>
2650:
2651: ENDSCRIPT
2652: }
2653:
1.3 raeburn 2654: sub print_autoenroll {
1.30 raeburn 2655: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2656: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2657: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2658: if (ref($settings) eq 'HASH') {
2659: if (exists($settings->{'run'})) {
2660: if ($settings->{'run'} eq '0') {
2661: $runoff = ' checked="checked" ';
2662: $runon = ' ';
2663: } else {
2664: $runon = ' checked="checked" ';
2665: $runoff = ' ';
2666: }
2667: } else {
2668: if ($autorun) {
2669: $runon = ' checked="checked" ';
2670: $runoff = ' ';
2671: } else {
2672: $runoff = ' checked="checked" ';
2673: $runon = ' ';
2674: }
2675: }
1.129 raeburn 2676: if (exists($settings->{'co-owners'})) {
2677: if ($settings->{'co-owners'} eq '0') {
2678: $coownersoff = ' checked="checked" ';
2679: $coownerson = ' ';
2680: } else {
2681: $coownerson = ' checked="checked" ';
2682: $coownersoff = ' ';
2683: }
2684: } else {
2685: $coownersoff = ' checked="checked" ';
2686: $coownerson = ' ';
2687: }
1.3 raeburn 2688: if (exists($settings->{'sender_domain'})) {
2689: $defdom = $settings->{'sender_domain'};
2690: }
1.274 raeburn 2691: if (exists($settings->{'autofailsafe'})) {
2692: $failsafe = $settings->{'autofailsafe'};
2693: }
1.14 raeburn 2694: } else {
2695: if ($autorun) {
2696: $runon = ' checked="checked" ';
2697: $runoff = ' ';
2698: } else {
2699: $runoff = ' checked="checked" ';
2700: $runon = ' ';
2701: }
1.3 raeburn 2702: }
2703: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2704: my $notif_sender;
2705: if (ref($settings) eq 'HASH') {
2706: $notif_sender = $settings->{'sender_uname'};
2707: }
1.3 raeburn 2708: my $datatable='<tr class="LC_odd_row">'.
2709: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2710: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2711: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2712: $runon.' value="1" />'.&mt('Yes').'</label> '.
2713: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2714: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2715: '</tr><tr>'.
2716: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2717: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2718: &mt('username').': '.
2719: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2720: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2721: ': '.$domform.'</span></td></tr>'.
2722: '<tr class="LC_odd_row">'.
2723: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2724: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2725: '<input type="radio" name="autoassign_coowners"'.
2726: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2727: '<label><input type="radio" name="autoassign_coowners"'.
2728: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2729: '</tr><tr>'.
2730: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2731: '<td class="LC_right_item"><span class="LC_nobreak">'.
2732: '<input type="text" name="autoenroll_failsafe"'.
2733: ' value="'.$failsafe.'" size="4" /></td></tr>';
2734: $$rowtotal += 4;
1.3 raeburn 2735: return $datatable;
2736: }
2737:
2738: sub print_autoupdate {
1.30 raeburn 2739: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2740: my $datatable;
2741: if ($position eq 'top') {
2742: my $updateon = ' ';
2743: my $updateoff = ' checked="checked" ';
2744: my $classlistson = ' ';
2745: my $classlistsoff = ' checked="checked" ';
2746: if (ref($settings) eq 'HASH') {
2747: if ($settings->{'run'} eq '1') {
2748: $updateon = $updateoff;
2749: $updateoff = ' ';
2750: }
2751: if ($settings->{'classlists'} eq '1') {
2752: $classlistson = $classlistsoff;
2753: $classlistsoff = ' ';
2754: }
2755: }
2756: my %title = (
2757: run => 'Auto-update active?',
2758: classlists => 'Update information in classlists?',
2759: );
2760: $datatable = '<tr class="LC_odd_row">'.
2761: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2762: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2763: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2764: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2765: '<label><input type="radio" name="autoupdate_run"'.
2766: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2767: '</tr><tr>'.
2768: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2769: '<td class="LC_right_item"><span class="LC_nobreak">'.
2770: '<label><input type="radio" name="classlists"'.
2771: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2772: '<label><input type="radio" name="classlists"'.
2773: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2774: '</tr>';
1.30 raeburn 2775: $$rowtotal += 2;
1.131 raeburn 2776: } elsif ($position eq 'middle') {
2777: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2778: my $numinrow = 3;
2779: my $locknamesettings;
2780: $datatable .= &insttypes_row($settings,$types,$usertypes,
2781: $dom,$numinrow,$othertitle,
1.305 raeburn 2782: 'lockablenames',$rowtotal);
1.131 raeburn 2783: $$rowtotal ++;
1.3 raeburn 2784: } else {
1.44 raeburn 2785: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2786: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2787: 'permanentemail','id');
1.33 raeburn 2788: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2789: my $numrows = 0;
1.26 raeburn 2790: if (ref($types) eq 'ARRAY') {
2791: if (@{$types} > 0) {
2792: $datatable =
2793: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2794: \@fields,$types,\$numrows);
1.30 raeburn 2795: $$rowtotal += @{$types};
1.26 raeburn 2796: }
1.3 raeburn 2797: }
2798: $datatable .=
2799: &usertype_update_row($settings,{'default' => $othertitle},
2800: \%fieldtitles,\@fields,['default'],
2801: \$numrows);
1.30 raeburn 2802: $$rowtotal ++;
1.3 raeburn 2803: }
2804: return $datatable;
2805: }
2806:
1.125 raeburn 2807: sub print_autocreate {
2808: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2809: my (%createon,%createoff,%currhash);
1.125 raeburn 2810: my @types = ('xml','req');
2811: if (ref($settings) eq 'HASH') {
2812: foreach my $item (@types) {
2813: $createoff{$item} = ' checked="checked" ';
2814: $createon{$item} = ' ';
2815: if (exists($settings->{$item})) {
2816: if ($settings->{$item}) {
2817: $createon{$item} = ' checked="checked" ';
2818: $createoff{$item} = ' ';
2819: }
2820: }
2821: }
1.210 raeburn 2822: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2823: $currhash{$settings->{'xmldc'}} = 1;
2824: }
1.125 raeburn 2825: } else {
2826: foreach my $item (@types) {
2827: $createoff{$item} = ' checked="checked" ';
2828: $createon{$item} = ' ';
2829: }
2830: }
2831: $$rowtotal += 2;
1.191 raeburn 2832: my $numinrow = 2;
1.125 raeburn 2833: my $datatable='<tr class="LC_odd_row">'.
2834: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2835: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2836: '<input type="radio" name="autocreate_xml"'.
2837: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2838: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2839: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2840: '</td></tr><tr>'.
2841: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2842: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2843: '<input type="radio" name="autocreate_req"'.
2844: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2845: '<label><input type="radio" name="autocreate_req"'.
2846: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2847: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2848: 'autocreate_xmldc',%currhash);
1.247 raeburn 2849: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2850: if ($numdc > 1) {
1.247 raeburn 2851: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2852: '</td><td class="LC_left_item">';
1.125 raeburn 2853: } else {
1.247 raeburn 2854: $datatable .= &mt('Course creation processed as:').
2855: '</td><td class="LC_right_item">';
1.125 raeburn 2856: }
1.247 raeburn 2857: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2858: $$rowtotal += $rows;
1.125 raeburn 2859: return $datatable;
2860: }
2861:
1.23 raeburn 2862: sub print_directorysrch {
1.277 raeburn 2863: my ($position,$dom,$settings,$rowtotal) = @_;
2864: my $datatable;
2865: if ($position eq 'top') {
2866: my $instsrchon = ' ';
2867: my $instsrchoff = ' checked="checked" ';
2868: my ($exacton,$containson,$beginson);
2869: my $instlocalon = ' ';
2870: my $instlocaloff = ' checked="checked" ';
2871: if (ref($settings) eq 'HASH') {
2872: if ($settings->{'available'} eq '1') {
2873: $instsrchon = $instsrchoff;
2874: $instsrchoff = ' ';
2875: }
2876: if ($settings->{'localonly'} eq '1') {
2877: $instlocalon = $instlocaloff;
2878: $instlocaloff = ' ';
2879: }
2880: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2881: foreach my $type (@{$settings->{'searchtypes'}}) {
2882: if ($type eq 'exact') {
2883: $exacton = ' checked="checked" ';
2884: } elsif ($type eq 'contains') {
2885: $containson = ' checked="checked" ';
2886: } elsif ($type eq 'begins') {
2887: $beginson = ' checked="checked" ';
2888: }
2889: }
2890: } else {
2891: if ($settings->{'searchtypes'} eq 'exact') {
2892: $exacton = ' checked="checked" ';
2893: } elsif ($settings->{'searchtypes'} eq 'contains') {
2894: $containson = ' checked="checked" ';
2895: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2896: $exacton = ' checked="checked" ';
2897: $containson = ' checked="checked" ';
2898: }
2899: }
1.277 raeburn 2900: }
2901: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2902: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2903:
2904: my $numinrow = 4;
2905: my $cansrchrow = 0;
2906: $datatable='<tr class="LC_odd_row">'.
2907: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2908: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2909: '<input type="radio" name="dirsrch_available"'.
2910: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2911: '<label><input type="radio" name="dirsrch_available"'.
2912: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2913: '</tr><tr>'.
2914: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2915: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2916: '<input type="radio" name="dirsrch_instlocalonly"'.
2917: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2918: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2919: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2920: '</tr>';
2921: $$rowtotal += 2;
2922: if (ref($usertypes) eq 'HASH') {
2923: if (keys(%{$usertypes}) > 0) {
2924: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 2925: $numinrow,$othertitle,'cansearch',
2926: $rowtotal);
1.277 raeburn 2927: $cansrchrow = 1;
1.25 raeburn 2928: }
1.23 raeburn 2929: }
1.277 raeburn 2930: if ($cansrchrow) {
2931: $$rowtotal ++;
2932: $datatable .= '<tr>';
2933: } else {
2934: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 2935: }
1.277 raeburn 2936: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2937: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2938: foreach my $title (@{$titleorder}) {
2939: if (defined($searchtitles->{$title})) {
2940: my $check = ' ';
2941: if (ref($settings) eq 'HASH') {
2942: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2943: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2944: $check = ' checked="checked" ';
2945: }
1.39 raeburn 2946: }
1.25 raeburn 2947: }
1.277 raeburn 2948: $datatable .= '<td class="LC_left_item">'.
2949: '<span class="LC_nobreak"><label>'.
2950: '<input type="checkbox" name="searchby" '.
2951: 'value="'.$title.'"'.$check.'/>'.
2952: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2953: }
2954: }
1.277 raeburn 2955: $datatable .= '</tr></table></td></tr>';
2956: $$rowtotal ++;
2957: if ($cansrchrow) {
2958: $datatable .= '<tr class="LC_odd_row">';
2959: } else {
2960: $datatable .= '<tr>';
2961: }
2962: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2963: '<td class="LC_left_item" colspan="2">'.
2964: '<span class="LC_nobreak"><label>'.
2965: '<input type="checkbox" name="searchtypes" '.
2966: $exacton.' value="exact" />'.&mt('Exact match').
2967: '</label> '.
2968: '<label><input type="checkbox" name="searchtypes" '.
2969: $beginson.' value="begins" />'.&mt('Begins with').
2970: '</label> '.
2971: '<label><input type="checkbox" name="searchtypes" '.
2972: $containson.' value="contains" />'.&mt('Contains').
2973: '</label></span></td></tr>';
2974: $$rowtotal ++;
1.26 raeburn 2975: } else {
1.277 raeburn 2976: my $domsrchon = ' checked="checked" ';
2977: my $domsrchoff = ' ';
2978: my $domlocalon = ' ';
2979: my $domlocaloff = ' checked="checked" ';
2980: if (ref($settings) eq 'HASH') {
2981: if ($settings->{'lclocalonly'} eq '1') {
2982: $domlocalon = $domlocaloff;
2983: $domlocaloff = ' ';
2984: }
2985: if ($settings->{'lcavailable'} eq '0') {
2986: $domsrchoff = $domsrchon;
2987: $domsrchon = ' ';
2988: }
2989: }
2990: $datatable='<tr class="LC_odd_row">'.
2991: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2992: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2993: '<input type="radio" name="dirsrch_domavailable"'.
2994: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2995: '<label><input type="radio" name="dirsrch_domavailable"'.
2996: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2997: '</tr><tr>'.
2998: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2999: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3000: '<input type="radio" name="dirsrch_domlocalonly"'.
3001: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3002: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3003: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3004: '</tr>';
3005: $$rowtotal += 2;
1.26 raeburn 3006: }
1.25 raeburn 3007: return $datatable;
3008: }
3009:
1.28 raeburn 3010: sub print_contacts {
1.286 raeburn 3011: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3012: my $datatable;
3013: my @contacts = ('adminemail','supportemail');
1.286 raeburn 3014: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
3015: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
3016: if ($position eq 'top') {
3017: if (ref($settings) eq 'HASH') {
3018: foreach my $item (@contacts) {
3019: if (exists($settings->{$item})) {
3020: $to{$item} = $settings->{$item};
3021: }
3022: }
3023: }
3024: } elsif ($position eq 'middle') {
3025: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3026: 'updatesmail','idconflictsmail');
1.288 raeburn 3027: foreach my $type (@mailings) {
3028: $otheremails{$type} = '';
3029: }
1.286 raeburn 3030: } else {
3031: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3032: foreach my $type (@mailings) {
3033: $otheremails{$type} = '';
3034: }
1.286 raeburn 3035: $bccemails{'helpdeskmail'} = '';
3036: $bccemails{'otherdomsmail'} = '';
3037: $includestr{'helpdeskmail'} = '';
3038: $includestr{'otherdomsmail'} = '';
3039: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3040: }
1.28 raeburn 3041: if (ref($settings) eq 'HASH') {
1.286 raeburn 3042: unless ($position eq 'top') {
3043: foreach my $type (@mailings) {
3044: if (exists($settings->{$type})) {
3045: if (ref($settings->{$type}) eq 'HASH') {
3046: foreach my $item (@contacts) {
3047: if ($settings->{$type}{$item}) {
3048: $checked{$type}{$item} = ' checked="checked" ';
3049: }
3050: }
3051: $otheremails{$type} = $settings->{$type}{'others'};
3052: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3053: $bccemails{$type} = $settings->{$type}{'bcc'};
3054: if ($settings->{$type}{'include'} ne '') {
3055: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3056: $includestr{$type} = &unescape($includestr{$type});
3057: }
3058: }
3059: }
3060: } elsif ($type eq 'lonstatusmail') {
3061: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3062: }
1.28 raeburn 3063: }
3064: }
1.286 raeburn 3065: if ($position eq 'bottom') {
3066: foreach my $type (@mailings) {
3067: $bccemails{$type} = $settings->{$type}{'bcc'};
3068: if ($settings->{$type}{'include'} ne '') {
3069: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3070: $includestr{$type} = &unescape($includestr{$type});
3071: }
3072: }
3073: if (ref($settings->{'helpform'}) eq 'HASH') {
3074: if (ref($fields) eq 'ARRAY') {
3075: foreach my $field (@{$fields}) {
3076: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3077: }
1.286 raeburn 3078: }
3079: if (exists($settings->{'helpform'}{'maxsize'})) {
3080: $maxsize = $settings->{'helpform'}{'maxsize'};
3081: } else {
1.289 raeburn 3082: $maxsize = '1.0';
1.286 raeburn 3083: }
3084: } else {
3085: if (ref($fields) eq 'ARRAY') {
3086: foreach my $field (@{$fields}) {
3087: $currfield{$field} = 'yes';
1.134 raeburn 3088: }
1.28 raeburn 3089: }
1.286 raeburn 3090: $maxsize = '1.0';
1.28 raeburn 3091: }
3092: }
3093: } else {
1.286 raeburn 3094: if ($position eq 'top') {
3095: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3096: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3097: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3098: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3099: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3100: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3101: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3102: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3103: } elsif ($position eq 'bottom') {
3104: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3105: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3106: if (ref($fields) eq 'ARRAY') {
3107: foreach my $field (@{$fields}) {
3108: $currfield{$field} = 'yes';
3109: }
3110: }
3111: $maxsize = '1.0';
3112: }
1.28 raeburn 3113: }
3114: my ($titles,$short_titles) = &contact_titles();
3115: my $rownum = 0;
3116: my $css_class;
1.286 raeburn 3117: if ($position eq 'top') {
3118: foreach my $item (@contacts) {
3119: $css_class = $rownum%2?' class="LC_odd_row"':'';
3120: $datatable .= '<tr'.$css_class.'>'.
3121: '<td><span class="LC_nobreak">'.$titles->{$item}.
3122: '</span></td><td class="LC_right_item">'.
3123: '<input type="text" name="'.$item.'" value="'.
3124: $to{$item}.'" /></td></tr>';
3125: $rownum ++;
3126: }
1.315 ! raeburn 3127: } elsif ($position eq 'bottom') {
! 3128: $css_class = $rownum%2?' class="LC_odd_row"':'';
! 3129: $datatable .= '<tr'.$css_class.'>'.
! 3130: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
! 3131: &mt('(e-mail, subject, and description always shown)').
! 3132: '</td><td class="LC_left_item">';
! 3133: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
! 3134: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
! 3135: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
! 3136: foreach my $field (@{$fields}) {
! 3137: $datatable .= '<tr><td>'.$fieldtitles->{$field};
! 3138: if (($field eq 'screenshot') || ($field eq 'cc')) {
! 3139: $datatable .= ' '.&mt('(logged-in users)');
! 3140: }
! 3141: $datatable .='</td><td>';
! 3142: my $clickaction;
! 3143: if ($field eq 'screenshot') {
! 3144: $clickaction = ' onclick="screenshotSize(this);"';
! 3145: }
! 3146: if (ref($possoptions->{$field}) eq 'ARRAY') {
! 3147: foreach my $option (@{$possoptions->{$field}}) {
! 3148: my $checked;
! 3149: if ($currfield{$field} eq $option) {
! 3150: $checked = ' checked="checked"';
! 3151: }
! 3152: $datatable .= '<span class="LC_nobreak"><label>'.
! 3153: '<input type="radio" name="helpform_'.$field.'" '.
! 3154: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
! 3155: '</label></span>'.(' 'x2);
! 3156: }
! 3157: }
! 3158: if ($field eq 'screenshot') {
! 3159: my $display;
! 3160: if ($currfield{$field} eq 'no') {
! 3161: $display = ' style="display:none"';
! 3162: }
! 3163: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
! 3164: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
! 3165: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
! 3166: }
! 3167: $datatable .= '</td></tr>';
! 3168: }
! 3169: $datatable .= '</table>';
! 3170: }
! 3171: $datatable .= '</td></tr>'."\n";
! 3172: $rownum ++;
! 3173: }
! 3174: unless ($position eq 'top') {
1.286 raeburn 3175: foreach my $type (@mailings) {
3176: $css_class = $rownum%2?' class="LC_odd_row"':'';
3177: $datatable .= '<tr'.$css_class.'>'.
3178: '<td><span class="LC_nobreak">'.
3179: $titles->{$type}.': </span></td>'.
3180: '<td class="LC_left_item">';
3181: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3182: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3183: }
3184: $datatable .= '<span class="LC_nobreak">';
3185: foreach my $item (@contacts) {
3186: $datatable .= '<label>'.
3187: '<input type="checkbox" name="'.$type.'"'.
3188: $checked{$type}{$item}.
3189: ' value="'.$item.'" />'.$short_titles->{$item}.
3190: '</label> ';
3191: }
3192: $datatable .= '</span><br />'.&mt('Others').': '.
3193: '<input type="text" name="'.$type.'_others" '.
3194: 'value="'.$otheremails{$type}.'" />';
3195: my %locchecked;
3196: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3197: foreach my $loc ('s','b') {
3198: if ($includeloc{$type} eq $loc) {
3199: $locchecked{$loc} = ' checked="checked"';
3200: last;
3201: }
3202: }
3203: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3204: '<input type="text" name="'.$type.'_bcc" '.
3205: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3206: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3207: &mt('Text automatically added to e-mail:').' '.
3208: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3209: '<span class="LC_nobreak">'.&mt('Location:').' '.
3210: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3211: (' 'x2).
3212: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3213: '</span></fieldset>';
3214: }
3215: $datatable .= '</td></tr>'."\n";
3216: $rownum ++;
3217: }
1.28 raeburn 3218: }
1.286 raeburn 3219: if ($position eq 'middle') {
3220: my %choices;
3221: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289 raeburn 3222: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3223: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 3224: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3225: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3226: &mt('LON-CAPA core group - MSU'),600,500));
3227: my @toggles = ('reporterrors','reportupdates');
3228: my %defaultchecked = ('reporterrors' => 'on',
3229: 'reportupdates' => 'on');
3230: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3231: \%choices,$rownum);
3232: $datatable .= $reports;
3233: } elsif ($position eq 'bottom') {
1.315 ! raeburn 3234: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 3235: my (@posstypes,%usertypeshash);
! 3236: if (ref($types) eq 'ARRAY') {
! 3237: @posstypes = @{$types};
! 3238: }
! 3239: if (@posstypes) {
! 3240: if (ref($usertypes) eq 'HASH') {
! 3241: %usertypeshash = %{$usertypes};
! 3242: }
! 3243: my @overridden;
! 3244: my $numinrow = 4;
! 3245: if (ref($settings) eq 'HASH') {
! 3246: if (ref($settings->{'overrides'}) eq 'HASH') {
! 3247: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
! 3248: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
! 3249: push(@overridden,$key);
! 3250: foreach my $item (@contacts) {
! 3251: if ($settings->{'overrides'}{$key}{$item}) {
! 3252: $checked{'override_'.$key}{$item} = ' checked="checked" ';
! 3253: }
! 3254: }
! 3255: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
! 3256: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
! 3257: $includeloc{'override_'.$key} = '';
! 3258: $includestr{'override_'.$key} = '';
! 3259: if ($settings->{'overrides'}{$key}{'include'} ne '') {
! 3260: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
! 3261: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
! 3262: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
! 3263: }
1.286 raeburn 3264: }
3265: }
3266: }
1.315 ! raeburn 3267: }
! 3268: my $customclass = 'LC_helpdesk_override';
! 3269: my $optionsprefix = 'LC_options_helpdesk_';
! 3270:
! 3271: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
! 3272:
! 3273: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
! 3274: $numinrow,$othertitle,'overrides',
! 3275: \$rownum,$onclicktypes,$customclass);
! 3276: $rownum ++;
! 3277: $usertypeshash{'default'} = $othertitle;
! 3278: foreach my $status (@posstypes) {
! 3279: my $css_class;
! 3280: if ($rownum%2) {
! 3281: $css_class = 'LC_odd_row ';
! 3282: }
! 3283: $css_class .= $customclass;
! 3284: my $rowid = $optionsprefix.$status;
! 3285: my $hidden = 1;
! 3286: my $currstyle = 'display:none';
! 3287: if (grep(/^\Q$status\E$/,@overridden)) {
! 3288: $currstyle = 'display:table-row';
! 3289: $hidden = 0;
! 3290: }
! 3291: my $key = 'override_'.$status;
! 3292: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
! 3293: $includeloc{$key},$includestr{$key},$status,$rowid,
! 3294: $usertypeshash{$status},$css_class,$currstyle,
! 3295: \@contacts,$short_titles);
! 3296: unless ($hidden) {
! 3297: $rownum ++;
1.286 raeburn 3298: }
3299: }
1.134 raeburn 3300: }
1.28 raeburn 3301: }
1.30 raeburn 3302: $$rowtotal += $rownum;
1.28 raeburn 3303: return $datatable;
3304: }
3305:
1.315 ! raeburn 3306: sub overridden_helpdesk {
! 3307: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
! 3308: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
! 3309: my $class = 'LC_left_item';
! 3310: if ($css_class) {
! 3311: $css_class = ' class="'.$css_class.'"';
! 3312: }
! 3313: if ($rowid) {
! 3314: $rowid = ' id="'.$rowid.'"';
! 3315: }
! 3316: if ($rowstyle) {
! 3317: $rowstyle = ' style="'.$rowstyle.'"';
! 3318: }
! 3319: my ($output,$description);
! 3320: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
! 3321: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
! 3322: "<td>$description</td>\n".
! 3323: '<td class="'.$class.'" colspan="2">'.
! 3324: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
! 3325: '<span class="LC_nobreak">';
! 3326: if (ref($contacts) eq 'ARRAY') {
! 3327: foreach my $item (@{$contacts}) {
! 3328: my $check;
! 3329: if (ref($checked) eq 'HASH') {
! 3330: $check = $checked->{$item};
! 3331: }
! 3332: my $title;
! 3333: if (ref($short_titles) eq 'HASH') {
! 3334: $title = $short_titles->{$item};
! 3335: }
! 3336: $output .= '<label>'.
! 3337: '<input type="checkbox" name="override_'.$type.'"'.$check.
! 3338: ' value="'.$item.'" />'.$title.'</label> ';
! 3339: }
! 3340: }
! 3341: $output .= '</span><br />'.&mt('Others').': '.
! 3342: '<input type="text" name="override_'.$type.'_others" '.
! 3343: 'value="'.$otheremails.'" />';
! 3344: my %locchecked;
! 3345: foreach my $loc ('s','b') {
! 3346: if ($includeloc eq $loc) {
! 3347: $locchecked{$loc} = ' checked="checked"';
! 3348: last;
! 3349: }
! 3350: }
! 3351: $output .= '<br />'.&mt('Bcc:').(' 'x6).
! 3352: '<input type="text" name="override_'.$type.'_bcc" '.
! 3353: 'value="'.$bccemails.'" /></fieldset>'.
! 3354: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
! 3355: &mt('Text automatically added to e-mail:').' '.
! 3356: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br >'.
! 3357: '<span class="LC_nobreak">'.&mt('Location:').' '.
! 3358: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
! 3359: (' 'x2).
! 3360: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
! 3361: '</span></fieldset>'.
! 3362: '</td></tr>'."\n";
! 3363: return $output;
! 3364: }
! 3365:
1.286 raeburn 3366: sub contacts_javascript {
3367: return <<"ENDSCRIPT";
3368:
3369: <script type="text/javascript">
3370: // <![CDATA[
3371:
3372: function screenshotSize(field) {
3373: if (document.getElementById('help_screenshotsize')) {
3374: if (field.value == 'no') {
1.289 raeburn 3375: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3376: } else {
3377: document.getElementById('help_screenshotsize').style.display="";
3378: }
3379: }
3380: return;
3381: }
3382:
1.315 ! raeburn 3383: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
! 3384: if (form.elements[checkbox].length != undefined) {
! 3385: var count = 0;
! 3386: if (docount) {
! 3387: for (var i=0; i<form.elements[checkbox].length; i++) {
! 3388: if (form.elements[checkbox][i].checked) {
! 3389: count ++;
! 3390: }
! 3391: }
! 3392: }
! 3393: for (var i=0; i<form.elements[checkbox].length; i++) {
! 3394: var type = form.elements[checkbox][i].value;
! 3395: if (document.getElementById(prefix+type)) {
! 3396: if (form.elements[checkbox][i].checked) {
! 3397: document.getElementById(prefix+type).style.display = 'table-row';
! 3398: if (count % 2 == 1) {
! 3399: document.getElementById(prefix+type).className = target+' LC_odd_row';
! 3400: } else {
! 3401: document.getElementById(prefix+type).className = target;
! 3402: }
! 3403: count ++;
! 3404: } else {
! 3405: document.getElementById(prefix+type).style.display = 'none';
! 3406: }
! 3407: }
! 3408: }
! 3409: }
! 3410: return;
! 3411: }
! 3412:
! 3413:
1.286 raeburn 3414: // ]]>
3415: </script>
3416:
3417: ENDSCRIPT
3418: }
3419:
1.118 jms 3420: sub print_helpsettings {
1.282 raeburn 3421: my ($position,$dom,$settings,$rowtotal) = @_;
3422: my $confname = $dom.'-domainconfig';
1.285 raeburn 3423: my $formname = 'display';
1.168 raeburn 3424: my ($datatable,$itemcount);
1.282 raeburn 3425: if ($position eq 'top') {
3426: $itemcount = 1;
3427: my (%choices,%defaultchecked,@toggles);
3428: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3429: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3430: &mt('LON-CAPA bug tracker'),600,500));
3431: %defaultchecked = ('submitbugs' => 'on');
3432: @toggles = ('submitbugs');
3433: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3434: \%choices,$itemcount);
3435: $$rowtotal ++;
3436: } else {
3437: my $css_class;
3438: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3439: my (%customroles,%ordered,%current);
1.301 raeburn 3440: if (ref($settings) eq 'HASH') {
3441: if (ref($settings->{'adhoc'}) eq 'HASH') {
3442: %current = %{$settings->{'adhoc'}};
3443: }
1.285 raeburn 3444: }
3445: my $count = 0;
3446: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3447: if ($key=~/^rolesdef\_(\w+)$/) {
3448: my $rolename = $1;
1.285 raeburn 3449: my (%privs,$order);
1.282 raeburn 3450: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3451: $customroles{$rolename} = \%privs;
1.285 raeburn 3452: if (ref($current{$rolename}) eq 'HASH') {
3453: $order = $current{$rolename}{'order'};
3454: }
3455: if ($order eq '') {
3456: $order = $count;
3457: }
3458: $ordered{$order} = $rolename;
3459: $count++;
3460: }
3461: }
3462: my $maxnum = scalar(keys(%ordered));
3463: my @roles_by_num = ();
3464: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3465: push(@roles_by_num,$item);
3466: }
3467: my $context = 'domprefs';
3468: my $crstype = 'Course';
3469: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3470: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3471: my ($numstatustypes,@jsarray);
3472: if (ref($types) eq 'ARRAY') {
3473: if (@{$types} > 0) {
3474: $numstatustypes = scalar(@{$types});
3475: push(@accesstypes,'status');
3476: @jsarray = ('bystatus');
1.282 raeburn 3477: }
3478: }
1.290 raeburn 3479: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3480: if (keys(%domhelpdesk)) {
3481: push(@accesstypes,('inc','exc'));
3482: push(@jsarray,('notinc','notexc'));
3483: }
3484: my $hiddenstr = join("','",@jsarray);
3485: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3486: my $context = 'domprefs';
3487: my $crstype = 'Course';
1.285 raeburn 3488: my $prefix = 'helproles_';
3489: my $add_class = 'LC_hidden';
3490: foreach my $num (@roles_by_num) {
3491: my $role = $ordered{$num};
3492: my ($desc,$access,@statuses);
3493: if (ref($current{$role}) eq 'HASH') {
3494: $desc = $current{$role}{'desc'};
3495: $access = $current{$role}{'access'};
3496: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3497: @statuses = @{$current{$role}{'insttypes'}};
3498: }
3499: }
3500: if ($desc eq '') {
3501: $desc = $role;
3502: }
3503: my $identifier = 'custhelp'.$num;
1.282 raeburn 3504: my %full=();
3505: my %levels= (
3506: course => {},
3507: domain => {},
3508: system => {},
3509: );
3510: my %levelscurrent=(
3511: course => {},
3512: domain => {},
3513: system => {},
3514: );
3515: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3516: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3517: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3518: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 3519: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 3520: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3521: for (my $k=0; $k<=$maxnum; $k++) {
3522: my $vpos = $k+1;
3523: my $selstr;
3524: if ($k == $num) {
3525: $selstr = ' selected="selected" ';
3526: }
3527: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3528: }
3529: $datatable .= '</select>'.(' 'x2).
3530: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3531: '</td>'.
3532: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3533: &mt('Name shown to users:').
3534: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3535: '</fieldset>'.
3536: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3537: $othertitle,$usertypes,$types,\%domhelpdesk).
3538: '<fieldset>'.
3539: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3540: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3541: \%levelscurrent,$identifier,
3542: 'LC_hidden',$prefix.$num.'_privs').
3543: '</fieldset></td>';
1.282 raeburn 3544: $itemcount ++;
3545: }
3546: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3547: my $newcust = 'custhelp'.$count;
3548: my (%privs,%levelscurrent);
3549: my %full=();
3550: my %levels= (
3551: course => {},
3552: domain => {},
3553: system => {},
3554: );
3555: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3556: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3557: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 3558: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 3559: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3560: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3561: for (my $k=0; $k<$maxnum+1; $k++) {
3562: my $vpos = $k+1;
3563: my $selstr;
3564: if ($k == $maxnum) {
3565: $selstr = ' selected="selected" ';
3566: }
3567: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3568: }
3569: $datatable .= '</select> '."\n".
1.282 raeburn 3570: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3571: '</label></span></td>'.
1.285 raeburn 3572: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3573: '<span class="LC_nobreak">'.
3574: &mt('Internal name:').
3575: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3576: '</span>'.(' 'x4).
3577: '<span class="LC_nobreak">'.
3578: &mt('Name shown to users:').
3579: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3580: '</span></fieldset>'.
3581: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3582: $usertypes,$types,\%domhelpdesk).
3583: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3584: &Apache::lonuserutils::custom_role_header($context,$crstype,
3585: \@templateroles,$newcust).
3586: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3587: \%levelscurrent,$newcust).
1.285 raeburn 3588: '</fieldset></td></tr>';
1.282 raeburn 3589: $count ++;
3590: $$rowtotal += $count;
3591: }
1.166 raeburn 3592: return $datatable;
1.121 raeburn 3593: }
3594:
1.285 raeburn 3595: sub adhocbutton {
3596: my ($prefix,$num,$field,$visibility) = @_;
3597: my %lt = &Apache::lonlocal::texthash(
3598: show => 'Show details',
3599: hide => 'Hide details',
3600: );
3601: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3602: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3603: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3604: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3605: }
3606:
3607: sub helpsettings_javascript {
3608: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3609: return unless(ref($roles_by_num) eq 'ARRAY');
3610: my %html_js_lt = &Apache::lonlocal::texthash(
3611: show => 'Show details',
3612: hide => 'Hide details',
3613: );
3614: &html_escape(\%html_js_lt);
3615: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3616: return <<"ENDSCRIPT";
3617: <script type="text/javascript">
3618: // <![CDATA[
3619:
3620: function reorderHelpRoles(form,item) {
3621: var changedVal;
3622: $jstext
3623: var newpos = 'helproles_${total}_pos';
3624: var maxh = 1 + $total;
3625: var current = new Array();
3626: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3627: if (item == newpos) {
3628: changedVal = newitemVal;
3629: } else {
3630: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3631: current[newitemVal] = newpos;
3632: }
3633: for (var i=0; i<helproles.length; i++) {
3634: var elementName = 'helproles_'+helproles[i]+'_pos';
3635: if (elementName != item) {
3636: if (form.elements[elementName]) {
3637: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3638: current[currVal] = elementName;
3639: }
3640: }
3641: }
3642: var oldVal;
3643: for (var j=0; j<maxh; j++) {
3644: if (current[j] == undefined) {
3645: oldVal = j;
3646: }
3647: }
3648: if (oldVal < changedVal) {
3649: for (var k=oldVal+1; k<=changedVal ; k++) {
3650: var elementName = current[k];
3651: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3652: }
3653: } else {
3654: for (var k=changedVal; k<oldVal; k++) {
3655: var elementName = current[k];
3656: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3657: }
3658: }
3659: return;
3660: }
3661:
3662: function helpdeskAccess(num) {
3663: var curraccess = null;
3664: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3665: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3666: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3667: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3668: }
3669: }
3670: }
3671: var shown = Array();
3672: var hidden = Array();
3673: if (curraccess == 'none') {
3674: hidden = Array('$hiddenstr');
3675: } else {
3676: if (curraccess == 'status') {
3677: shown = Array('bystatus');
3678: hidden = Array('notinc','notexc');
3679: } else {
3680: if (curraccess == 'exc') {
3681: shown = Array('notexc');
3682: hidden = Array('notinc','bystatus');
3683: }
3684: if (curraccess == 'inc') {
3685: shown = Array('notinc');
3686: hidden = Array('notexc','bystatus');
3687: }
1.293 raeburn 3688: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3689: hidden = Array('notinc','notexc','bystatus');
3690: }
3691: }
3692: }
3693: if (hidden.length > 0) {
3694: for (var i=0; i<hidden.length; i++) {
3695: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3696: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3697: }
3698: }
3699: }
3700: if (shown.length > 0) {
3701: for (var i=0; i<shown.length; i++) {
3702: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3703: if (shown[i] == 'privs') {
3704: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3705: } else {
3706: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3707: }
3708: }
3709: }
3710: }
3711: return;
3712: }
3713:
3714: function toggleHelpdeskItem(num,field) {
3715: if (document.getElementById('helproles_'+num+'_'+field)) {
3716: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 3717: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 3718: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3719: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3720: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3721: }
3722: } else {
3723: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3724: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3725: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3726: }
3727: }
3728: }
3729: return;
3730: }
3731:
3732: // ]]>
3733: </script>
3734:
3735: ENDSCRIPT
3736: }
3737:
3738: sub helpdeskroles_access {
3739: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3740: $usertypes,$types,$domhelpdesk) = @_;
3741: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3742: my %lt = &Apache::lonlocal::texthash(
3743: 'rou' => 'Role usage',
3744: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 3745: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3746: 'dh' => 'All with domain helpdesk role',
3747: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 3748: 'none' => 'None',
3749: 'status' => 'Determined based on institutional status',
3750: 'inc' => 'Include all, but exclude specific personnel',
3751: 'exc' => 'Exclude all, but include specific personnel',
3752: );
3753: my %usecheck = (
3754: all => ' checked="checked"',
3755: );
3756: my %displaydiv = (
3757: status => 'none',
3758: inc => 'none',
3759: exc => 'none',
3760: priv => 'block',
3761: );
3762: my $output;
3763: if (ref($current) eq 'HASH') {
3764: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3765: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3766: $usecheck{$current->{access}} = $usecheck{'all'};
3767: delete($usecheck{'all'});
3768: if ($current->{access} =~ /^(status|inc|exc)$/) {
3769: my $access = $1;
3770: $displaydiv{$access} = 'inline';
3771: } elsif ($current->{access} eq 'none') {
3772: $displaydiv{'priv'} = 'none';
3773: }
3774: }
3775: }
3776: }
3777: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3778: '<p>'.$lt{'whi'}.'</p>';
3779: foreach my $access (@{$accesstypes}) {
3780: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3781: ' onclick="helpdeskAccess('."'$num'".');" />'.
3782: $lt{$access}.'</label>';
3783: if ($access eq 'status') {
3784: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3785: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3786: $othertitle,$usertypes,$types).
3787: '</div>';
3788: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3789: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3790: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3791: '</div>';
3792: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3793: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3794: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3795: '</div>';
3796: }
3797: $output .= '</p>';
3798: }
3799: $output .= '</fieldset>';
3800: return $output;
3801: }
3802:
1.121 raeburn 3803: sub radiobutton_prefs {
1.192 raeburn 3804: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 3805: $additional,$align) = @_;
1.121 raeburn 3806: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3807: (ref($choices) eq 'HASH'));
3808:
1.170 raeburn 3809: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 3810:
3811: foreach my $item (@{$toggles}) {
3812: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3813: $checkedon{$item} = ' checked="checked" ';
3814: $checkedoff{$item} = ' ';
1.121 raeburn 3815: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3816: $checkedoff{$item} = ' checked="checked" ';
3817: $checkedon{$item} = ' ';
3818: }
3819: }
3820: if (ref($settings) eq 'HASH') {
1.121 raeburn 3821: foreach my $item (@{$toggles}) {
1.118 jms 3822: if ($settings->{$item} eq '1') {
3823: $checkedon{$item} = ' checked="checked" ';
3824: $checkedoff{$item} = ' ';
3825: } elsif ($settings->{$item} eq '0') {
3826: $checkedoff{$item} = ' checked="checked" ';
3827: $checkedon{$item} = ' ';
3828: }
3829: }
1.121 raeburn 3830: }
1.192 raeburn 3831: if ($onclick) {
3832: $onclick = ' onclick="'.$onclick.'"';
3833: }
1.121 raeburn 3834: foreach my $item (@{$toggles}) {
1.118 jms 3835: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3836: $datatable .=
1.306 raeburn 3837: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 3838: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3839: '</span></td>';
3840: if ($align eq 'left') {
3841: $datatable .= '<td class="LC_left_item">';
3842: } else {
3843: $datatable .= '<td class="LC_right_item">';
3844: }
1.289 raeburn 3845: $datatable .=
1.257 raeburn 3846: '<span class="LC_nobreak">'.
1.118 jms 3847: '<label><input type="radio" name="'.
1.192 raeburn 3848: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3849: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3850: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3851: '</span>'.$additional.
3852: '</td>'.
1.118 jms 3853: '</tr>';
3854: $itemcount ++;
1.121 raeburn 3855: }
3856: return ($datatable,$itemcount);
3857: }
3858:
1.267 raeburn 3859: sub print_ltitools {
3860: my ($dom,$settings,$rowtotal) = @_;
3861: my $rownum = 0;
3862: my $css_class;
3863: my $itemcount = 1;
3864: my $maxnum = 0;
3865: my %ordered;
3866: if (ref($settings) eq 'HASH') {
3867: foreach my $item (keys(%{$settings})) {
3868: if (ref($settings->{$item}) eq 'HASH') {
3869: my $num = $settings->{$item}{'order'};
3870: $ordered{$num} = $item;
3871: }
3872: }
3873: }
3874: my $confname = $dom.'-domainconfig';
3875: my $switchserver = &check_switchserver($dom,$confname);
3876: my $maxnum = scalar(keys(%ordered));
3877: my $datatable = <itools_javascript($settings);
3878: my %lt = <itools_names();
3879: my @courseroles = ('cc','in','ta','ep','st');
3880: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3881: my @fields = ('fullname','firstname','lastname','email','user','roles');
3882: if (keys(%ordered)) {
3883: my @items = sort { $a <=> $b } keys(%ordered);
3884: for (my $i=0; $i<@items; $i++) {
3885: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3886: my $item = $ordered{$items[$i]};
3887: my ($title,$key,$secret,$url,$imgsrc,$version);
3888: if (ref($settings->{$item}) eq 'HASH') {
3889: $title = $settings->{$item}->{'title'};
3890: $url = $settings->{$item}->{'url'};
3891: $key = $settings->{$item}->{'key'};
3892: $secret = $settings->{$item}->{'secret'};
3893: my $image = $settings->{$item}->{'image'};
3894: if ($image ne '') {
3895: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3896: }
3897: }
3898: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3899: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3900: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3901: for (my $k=0; $k<=$maxnum; $k++) {
3902: my $vpos = $k+1;
3903: my $selstr;
3904: if ($k == $i) {
3905: $selstr = ' selected="selected" ';
3906: }
3907: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3908: }
3909: $datatable .= '</select>'.(' 'x2).
3910: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3911: &mt('Delete?').'</label></span></td>'.
3912: '<td colspan="2">'.
3913: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3914: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3915: (' 'x2).
3916: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3917: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3918: (' 'x2).
3919: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3920: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3921: '<br /><br />'.
3922: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3923: ' value="'.$url.'" /></span>'.
3924: (' 'x2).
3925: '<span class="LC_nobreak">'.$lt{'key'}.
3926: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3927: (' 'x2).
3928: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3929: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3930: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
3931: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3932: '</fieldset>'.
3933: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3934: '<span class="LC_nobreak">'.&mt('Display target:');
3935: my %currdisp;
3936: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3937: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3938: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 3939: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
3940: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 3941: } else {
3942: $currdisp{'iframe'} = ' checked="checked"';
3943: }
3944: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3945: $currdisp{'width'} = $1;
3946: }
3947: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3948: $currdisp{'height'} = $1;
3949: }
1.296 raeburn 3950: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
3951: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 3952: } else {
3953: $currdisp{'iframe'} = ' checked="checked"';
3954: }
1.298 raeburn 3955: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 3956: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3957: $lt{$disp}.'</label>'.(' 'x2);
3958: }
3959: $datatable .= (' 'x4);
3960: foreach my $dimen ('width','height') {
3961: $datatable .= '<label>'.$lt{$dimen}.' '.
3962: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3963: (' 'x2);
3964: }
1.296 raeburn 3965: $datatable .= '<br />'.
3966: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3967: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
3968: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3969: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
3970: '</textarea></div><div style=""></div><br />';
1.267 raeburn 3971: $datatable .= '<br />';
3972: foreach my $extra ('passback','roster') {
3973: my $checkedon = '';
3974: my $checkedoff = ' checked="checked"';
3975: if ($settings->{$item}->{$extra}) {
3976: $checkedon = $checkedoff;
3977: $checkedoff = '';
3978: }
3979: $datatable .= $lt{$extra}.' '.
3980: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3981: &mt('Yes').'</label>'.(' 'x2).
3982: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3983: &mt('No').'</label>'.(' 'x4);
3984: }
3985: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3986: if ($imgsrc) {
3987: $datatable .= $imgsrc.
3988: '<label><input type="checkbox" name="ltitools_image_del"'.
3989: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3990: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3991: } else {
3992: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3993: }
3994: if ($switchserver) {
3995: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3996: } else {
3997: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3998: }
3999: $datatable .= '</span></fieldset>';
4000: my (%checkedfields,%rolemaps);
4001: if (ref($settings->{$item}) eq 'HASH') {
4002: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4003: %checkedfields = %{$settings->{$item}->{'fields'}};
4004: }
4005: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4006: %rolemaps = %{$settings->{$item}->{'roles'}};
4007: $checkedfields{'roles'} = 1;
4008: }
4009: }
4010: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4011: '<span class="LC_nobreak">';
4012: foreach my $field (@fields) {
4013: my $checked;
4014: if ($checkedfields{$field}) {
4015: $checked = ' checked="checked"';
4016: }
4017: $datatable .= '<label>'.
4018: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
4019: $lt{$field}.'</label>'.(' ' x2);
4020: }
4021: $datatable .= '</span></fieldset>'.
4022: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4023: foreach my $role (@courseroles) {
4024: my ($selected,$selectnone);
4025: if (!$rolemaps{$role}) {
4026: $selectnone = ' selected="selected"';
4027: }
1.306 raeburn 4028: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4029: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4030: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
4031: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
4032: foreach my $ltirole (@ltiroles) {
4033: unless ($selectnone) {
4034: if ($rolemaps{$role} eq $ltirole) {
4035: $selected = ' selected="selected"';
4036: } else {
4037: $selected = '';
4038: }
4039: }
4040: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
4041: }
4042: $datatable .= '</select></td>';
4043: }
1.273 raeburn 4044: $datatable .= '</tr></table></fieldset>';
4045: my %courseconfig;
4046: if (ref($settings->{$item}) eq 'HASH') {
4047: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
4048: %courseconfig = %{$settings->{$item}->{'crsconf'}};
4049: }
4050: }
4051: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 raeburn 4052: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 4053: my $checked;
4054: if ($courseconfig{$item}) {
4055: $checked = ' checked="checked"';
4056: }
4057: $datatable .= '<label>'.
4058: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
4059: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
4060: }
4061: $datatable .= '</span></fieldset>'.
1.267 raeburn 4062: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4063: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
4064: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
4065: my %custom = %{$settings->{$item}->{'custom'}};
4066: if (keys(%custom) > 0) {
4067: foreach my $key (sort(keys(%custom))) {
4068: $datatable .= '<tr><td><span class="LC_nobreak">'.
4069: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
4070: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
4071: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
4072: ' value="'.$custom{$key}.'" /></td></tr>';
4073: }
4074: }
4075: }
4076: $datatable .= '<tr><td><span class="LC_nobreak">'.
4077: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
4078: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
4079: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
4080: $datatable .= '</table></fieldset></td></tr>'."\n";
4081: $itemcount ++;
4082: }
4083: }
4084: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4085: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
4086: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
4087: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
4088: '<select name="ltitools_add_pos"'.$chgstr.'>';
4089: for (my $k=0; $k<$maxnum+1; $k++) {
4090: my $vpos = $k+1;
4091: my $selstr;
4092: if ($k == $maxnum) {
4093: $selstr = ' selected="selected" ';
4094: }
4095: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4096: }
4097: $datatable .= '</select> '."\n".
4098: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
4099: '<td colspan="2">'.
4100: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4101: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
4102: (' 'x2).
4103: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
4104: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
4105: (' 'x2).
4106: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
4107: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4108: '<br />'.
4109: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
4110: (' 'x2).
4111: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
4112: (' 'x2).
4113: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
4114: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
4115: '</fieldset>'.
4116: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4117: '<span class="LC_nobreak">'.&mt('Display target:');
4118: my %defaultdisp;
4119: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 4120: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 4121: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
4122: $lt{$disp}.'</label>'.(' 'x2);
4123: }
4124: $datatable .= (' 'x4);
4125: foreach my $dimen ('width','height') {
4126: $datatable .= '<label>'.$lt{$dimen}.' '.
4127: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
4128: (' 'x2);
4129: }
1.296 raeburn 4130: $datatable .= '<br />'.
4131: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4132: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
4133: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4134: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
4135: '</div><div style=""></div><br />';
1.267 raeburn 4136: foreach my $extra ('passback','roster') {
4137: $datatable .= $lt{$extra}.' '.
4138: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
4139: &mt('Yes').'</label>'.(' 'x2).
4140: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
4141: &mt('No').'</label>'.(' 'x4);
4142: }
4143: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
4144: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4145: if ($switchserver) {
4146: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4147: } else {
4148: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
4149: }
4150: $datatable .= '</span></fieldset>'.
4151: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4152: '<span class="LC_nobreak">';
4153: foreach my $field (@fields) {
4154: $datatable .= '<label>'.
4155: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
4156: $lt{$field}.'</label>'.(' ' x2);
4157: }
4158: $datatable .= '</span></fieldset>'.
4159: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4160: foreach my $role (@courseroles) {
4161: my ($checked,$checkednone);
1.306 raeburn 4162: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4163: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4164: '<select name="ltitools_add_roles_'.$role.'">'.
4165: '<option value="" selected="selected">'.&mt('Select').'</option>';
4166: foreach my $ltirole (@ltiroles) {
4167: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4168: }
4169: $datatable .= '</select></td>';
4170: }
4171: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4172: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 raeburn 4173: foreach my $item ('label','title','target','linktext','explanation') {
4174: $datatable .= '<label>'.
4175: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4176: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4177: }
4178: $datatable .= '</span></fieldset>'.
1.267 raeburn 4179: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4180: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4181: '<tr><td><span class="LC_nobreak">'.
4182: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4183: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4184: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4185: '</table></fieldset></td></tr>'."\n".
4186: '</td>'."\n".
4187: '</tr>'."\n";
4188: $itemcount ++;
4189: return $datatable;
4190: }
4191:
4192: sub ltitools_names {
4193: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4194: 'title' => 'Title',
4195: 'version' => 'Version',
4196: 'msgtype' => 'Message Type',
4197: 'url' => 'URL',
4198: 'key' => 'Key',
4199: 'secret' => 'Secret',
4200: 'icon' => 'Icon',
4201: 'user' => 'Username:domain',
4202: 'fullname' => 'Full Name',
4203: 'firstname' => 'First Name',
4204: 'lastname' => 'Last Name',
4205: 'email' => 'E-mail',
4206: 'roles' => 'Role',
1.298 raeburn 4207: 'window' => 'Window',
4208: 'tab' => 'Tab',
1.296 raeburn 4209: 'iframe' => 'iFrame',
4210: 'height' => 'Height',
4211: 'width' => 'Width',
4212: 'linktext' => 'Default Link Text',
4213: 'explanation' => 'Default Explanation',
4214: 'passback' => 'Tool can return grades:',
4215: 'roster' => 'Tool can retrieve roster:',
4216: 'crstarget' => 'Display target',
4217: 'crslabel' => 'Course label',
4218: 'crstitle' => 'Course title',
4219: 'crslinktext' => 'Link Text',
4220: 'crsexplanation' => 'Explanation',
1.267 raeburn 4221: );
4222: return %lt;
4223: }
4224:
1.121 raeburn 4225: sub print_coursedefaults {
1.139 raeburn 4226: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 4227: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4228: my $itemcount = 1;
1.192 raeburn 4229: my %choices = &Apache::lonlocal::texthash (
4230: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 4231: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 4232: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4233: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 4234: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4235: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314 raeburn 4236: texengine => 'Default method to display mathematics',
1.257 raeburn 4237: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4238: canclone => "People who may clone a course (besides course's owner and coordinators)",
4239: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4240: );
1.198 raeburn 4241: my %staticdefaults = (
1.314 raeburn 4242: texengine => 'MathJax',
1.198 raeburn 4243: anonsurvey_threshold => 10,
4244: uploadquota => 500,
1.257 raeburn 4245: postsubmit => 60,
1.276 raeburn 4246: mysqltables => 172800,
1.198 raeburn 4247: );
1.139 raeburn 4248: if ($position eq 'top') {
1.257 raeburn 4249: %defaultchecked = (
4250: 'canuse_pdfforms' => 'off',
4251: 'uselcmath' => 'on',
4252: 'usejsme' => 'on',
1.289 raeburn 4253: 'canclone' => 'none',
1.257 raeburn 4254: );
4255: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.314 raeburn 4256: my $deftex = $staticdefaults{'texengine'};
4257: if (ref($settings) eq 'HASH') {
4258: if ($settings->{'texengine'}) {
4259: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
4260: $deftex = $settings->{'texengine'};
4261: }
4262: }
4263: }
4264: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4265: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
4266: '<span class="LC_nobreak">'.$choices{'texengine'}.
4267: '</span></td><td class="LC_right_item">'.
4268: '<select name="texengine">'."\n";
4269: my %texoptions = (
4270: MathJax => 'MathJax',
4271: mimetex => &mt('Convert to Images'),
4272: tth => &mt('TeX to HTML'),
4273: );
4274: foreach my $renderer ('MathJax','mimetex','tth') {
4275: my $selected = '';
4276: if ($renderer eq $deftex) {
4277: $selected = ' selected="selected"';
4278: }
4279: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
4280: }
4281: $mathdisp .= '</select></td></tr>'."\n";
4282: $itemcount ++;
1.139 raeburn 4283: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4284: \%choices,$itemcount);
1.314 raeburn 4285: $datatable = $mathdisp.$datatable;
1.264 raeburn 4286: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4287: $datatable .=
1.306 raeburn 4288: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 4289: '<span class="LC_nobreak">'.$choices{'canclone'}.
4290: '</span></td><td class="LC_left_item">';
4291: my $currcanclone = 'none';
4292: my $onclick;
4293: my @cloneoptions = ('none','domain');
4294: my %clonetitles = (
4295: none => 'No additional course requesters',
4296: domain => "Any course requester in course's domain",
4297: instcode => 'Course requests for official courses ...',
4298: );
4299: my (%codedefaults,@code_order,@posscodes);
4300: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4301: \@code_order) eq 'ok') {
4302: if (@code_order > 0) {
4303: push(@cloneoptions,'instcode');
4304: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4305: }
4306: }
4307: if (ref($settings) eq 'HASH') {
4308: if ($settings->{'canclone'}) {
4309: if (ref($settings->{'canclone'}) eq 'HASH') {
4310: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4311: if (@code_order > 0) {
4312: $currcanclone = 'instcode';
4313: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4314: }
4315: }
4316: } elsif ($settings->{'canclone'} eq 'domain') {
4317: $currcanclone = $settings->{'canclone'};
4318: }
4319: }
1.289 raeburn 4320: }
1.264 raeburn 4321: foreach my $option (@cloneoptions) {
4322: my ($checked,$additional);
4323: if ($currcanclone eq $option) {
4324: $checked = ' checked="checked"';
4325: }
4326: if ($option eq 'instcode') {
4327: if (@code_order) {
4328: my $show = 'none';
4329: if ($checked) {
4330: $show = 'block';
4331: }
4332: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4333: &mt('Institutional codes for new and cloned course have identical:').
4334: '<br />';
4335: foreach my $item (@code_order) {
4336: my $codechk;
4337: if ($checked) {
4338: if (grep(/^\Q$item\E$/,@posscodes)) {
4339: $codechk = ' checked="checked"';
4340: }
4341: }
4342: $additional .= '<label>'.
4343: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4344: $item.'</label>';
4345: }
4346: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4347: }
4348: }
4349: $datatable .=
4350: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4351: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4352: '</label> '.$additional.'</span><br />';
4353: }
4354: $datatable .= '</td>'.
4355: '</tr>';
4356: $itemcount ++;
1.139 raeburn 4357: } else {
4358: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4359: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4360: my $currusecredits = 0;
1.257 raeburn 4361: my $postsubmitclient = 1;
1.271 raeburn 4362: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4363: if (ref($settings) eq 'HASH') {
4364: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4365: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4366: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4367: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4368: }
4369: }
1.192 raeburn 4370: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4371: foreach my $type (@types) {
4372: next if ($type eq 'community');
4373: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4374: if ($defcredits{$type} ne '') {
4375: $currusecredits = 1;
4376: }
4377: }
4378: }
4379: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4380: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4381: $postsubmitclient = 0;
4382: foreach my $type (@types) {
4383: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4384: }
4385: } else {
4386: foreach my $type (@types) {
4387: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4388: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 4389: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 4390: } else {
4391: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4392: }
4393: } else {
4394: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4395: }
4396: }
4397: }
4398: } else {
4399: foreach my $type (@types) {
4400: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 4401: }
4402: }
1.276 raeburn 4403: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4404: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4405: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4406: }
4407: } else {
4408: foreach my $type (@types) {
4409: $currmysql{$type} = $staticdefaults{'mysqltables'};
4410: }
4411: }
1.258 raeburn 4412: } else {
4413: foreach my $type (@types) {
4414: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4415: }
1.139 raeburn 4416: }
4417: if (!$currdefresponder) {
1.198 raeburn 4418: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4419: } elsif ($currdefresponder < 1) {
4420: $currdefresponder = 1;
4421: }
1.198 raeburn 4422: foreach my $type (@types) {
4423: if ($curruploadquota{$type} eq '') {
4424: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4425: }
4426: }
1.139 raeburn 4427: $datatable .=
1.192 raeburn 4428: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4429: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4430: '</span></td>'.
4431: '<td class="LC_right_item"><span class="LC_nobreak">'.
4432: '<input type="text" name="anonsurvey_threshold"'.
4433: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 4434: '</td></tr>'."\n";
4435: $itemcount ++;
4436: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4437: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4438: $choices{'uploadquota'}.
4439: '</span></td>'.
1.306 raeburn 4440: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 4441: '<table><tr>';
1.198 raeburn 4442: foreach my $type (@types) {
1.306 raeburn 4443: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 4444: '<input type="text" name="uploadquota_'.$type.'"'.
4445: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4446: }
4447: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 4448: $itemcount ++;
1.236 raeburn 4449: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 4450: my $display = 'none';
1.192 raeburn 4451: if ($currusecredits) {
4452: $display = 'block';
4453: }
4454: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 4455: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4456: foreach my $type (@types) {
4457: next if ($type eq 'community');
1.306 raeburn 4458: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 4459: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 4460: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 4461: }
4462: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 4463: %defaultchecked = ('coursecredits' => 'off');
4464: @toggles = ('coursecredits');
4465: my $current = {
4466: 'coursecredits' => $currusecredits,
4467: };
4468: (my $table,$itemcount) =
4469: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 4470: \%choices,$itemcount,$onclick,$additional,'left');
4471: $datatable .= $table;
4472: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4473: my $display = 'none';
4474: if ($postsubmitclient) {
4475: $display = 'block';
4476: }
4477: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 4478: &mt('Number of seconds submit is disabled').'<br />'.
4479: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4480: '<table><tr>';
1.257 raeburn 4481: foreach my $type (@types) {
1.306 raeburn 4482: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 4483: '<input type="text" name="'.$type.'_timeout" value="'.
4484: $deftimeout{$type}.'" size="5" /></td>';
4485: }
4486: $additional .= '</tr></table></div>'."\n";
4487: %defaultchecked = ('postsubmit' => 'on');
4488: @toggles = ('postsubmit');
1.280 raeburn 4489: $current = {
4490: 'postsubmit' => $postsubmitclient,
4491: };
1.257 raeburn 4492: ($table,$itemcount) =
4493: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4494: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 4495: $datatable .= $table;
1.276 raeburn 4496: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4497: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4498: $choices{'mysqltables'}.
4499: '</span></td>'.
1.306 raeburn 4500: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 4501: '<table><tr>';
4502: foreach my $type (@types) {
1.306 raeburn 4503: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 4504: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 4505: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 4506: }
4507: $datatable .= '</tr></table></td></tr>'."\n";
4508: $itemcount ++;
4509:
1.139 raeburn 4510: }
1.192 raeburn 4511: $$rowtotal += $itemcount;
1.121 raeburn 4512: return $datatable;
1.118 jms 4513: }
4514:
1.231 raeburn 4515: sub print_selfenrollment {
4516: my ($position,$dom,$settings,$rowtotal) = @_;
4517: my ($css_class,$datatable);
4518: my $itemcount = 1;
1.271 raeburn 4519: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 4520: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 4521: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4522: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 4523: my @rows;
4524: my $key;
4525: if ($position eq 'top') {
4526: $key = 'admin';
4527: if (ref($rowsref) eq 'ARRAY') {
4528: @rows = @{$rowsref};
4529: }
4530: } elsif ($position eq 'middle') {
4531: $key = 'default';
4532: @rows = ('types','registered','approval','limit');
4533: }
4534: foreach my $row (@rows) {
4535: if (defined($titlesref->{$row})) {
4536: $itemcount ++;
4537: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4538: $datatable .= '<tr'.$css_class.'>'.
4539: '<td>'.$titlesref->{$row}.'</td>'.
4540: '<td class="LC_left_item">'.
4541: '<table><tr>';
4542: my (%current,%currentcap);
4543: if (ref($settings) eq 'HASH') {
4544: if (ref($settings->{$key}) eq 'HASH') {
4545: foreach my $type (@types) {
4546: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4547: $current{$type} = $settings->{$key}->{$type}->{$row};
4548: }
4549: if (($row eq 'limit') && ($key eq 'default')) {
4550: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4551: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4552: }
4553: }
4554: }
4555: }
4556: }
4557: my %roles = (
4558: '0' => &Apache::lonnet::plaintext('dc'),
4559: );
4560:
4561: foreach my $type (@types) {
4562: unless (($row eq 'registered') && ($key eq 'default')) {
4563: $datatable .= '<th>'.&mt($type).'</th>';
4564: }
4565: }
4566: unless (($row eq 'registered') && ($key eq 'default')) {
4567: $datatable .= '</tr><tr>';
4568: }
4569: foreach my $type (@types) {
4570: if ($type eq 'community') {
4571: $roles{'1'} = &mt('Community personnel');
4572: } else {
4573: $roles{'1'} = &mt('Course personnel');
4574: }
4575: $datatable .= '<td style="vertical-align: top">';
4576: if ($position eq 'top') {
4577: my %checked;
4578: if ($current{$type} eq '0') {
4579: $checked{'0'} = ' checked="checked"';
4580: } else {
4581: $checked{'1'} = ' checked="checked"';
4582: }
4583: foreach my $role ('1','0') {
4584: $datatable .= '<span class="LC_nobreak"><label>'.
4585: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4586: 'value="'.$role.'"'.$checked{$role}.' />'.
4587: $roles{$role}.'</label></span> ';
4588: }
4589: } else {
4590: if ($row eq 'types') {
4591: my %checked;
4592: if ($current{$type} =~ /^(all|dom)$/) {
4593: $checked{$1} = ' checked="checked"';
4594: } else {
4595: $checked{''} = ' checked="checked"';
4596: }
4597: foreach my $val ('','dom','all') {
4598: $datatable .= '<span class="LC_nobreak"><label>'.
4599: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4600: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4601: }
4602: } elsif ($row eq 'registered') {
4603: my %checked;
4604: if ($current{$type} eq '1') {
4605: $checked{'1'} = ' checked="checked"';
4606: } else {
4607: $checked{'0'} = ' checked="checked"';
4608: }
4609: foreach my $val ('0','1') {
4610: $datatable .= '<span class="LC_nobreak"><label>'.
4611: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4612: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4613: }
4614: } elsif ($row eq 'approval') {
4615: my %checked;
4616: if ($current{$type} =~ /^([12])$/) {
4617: $checked{$1} = ' checked="checked"';
4618: } else {
4619: $checked{'0'} = ' checked="checked"';
4620: }
4621: for my $val (0..2) {
4622: $datatable .= '<span class="LC_nobreak"><label>'.
4623: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4624: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4625: }
4626: } elsif ($row eq 'limit') {
4627: my %checked;
4628: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4629: $checked{$1} = ' checked="checked"';
4630: } else {
4631: $checked{'none'} = ' checked="checked"';
4632: }
4633: my $cap;
4634: if ($currentcap{$type} =~ /^\d+$/) {
4635: $cap = $currentcap{$type};
4636: }
4637: foreach my $val ('none','allstudents','selfenrolled') {
4638: $datatable .= '<span class="LC_nobreak"><label>'.
4639: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4640: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4641: }
4642: $datatable .= '<br />'.
4643: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4644: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4645: '</span>';
4646: }
4647: }
4648: $datatable .= '</td>';
4649: }
4650: $datatable .= '</tr>';
4651: }
4652: $datatable .= '</table></td></tr>';
4653: }
4654: } elsif ($position eq 'bottom') {
1.235 raeburn 4655: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4656: }
4657: $$rowtotal += $itemcount;
4658: return $datatable;
4659: }
4660:
4661: sub print_validation_rows {
4662: my ($caller,$dom,$settings,$rowtotal) = @_;
4663: my ($itemsref,$namesref,$fieldsref);
4664: if ($caller eq 'selfenroll') {
4665: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4666: } elsif ($caller eq 'requestcourses') {
4667: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4668: }
4669: my %currvalidation;
4670: if (ref($settings) eq 'HASH') {
4671: if (ref($settings->{'validation'}) eq 'HASH') {
4672: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 4673: }
1.235 raeburn 4674: }
4675: my $datatable;
4676: my $itemcount = 0;
4677: foreach my $item (@{$itemsref}) {
4678: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4679: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4680: $namesref->{$item}.
4681: '</span></td>'.
4682: '<td class="LC_left_item">';
4683: if (($item eq 'url') || ($item eq 'button')) {
4684: $datatable .= '<span class="LC_nobreak">'.
4685: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4686: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4687: } elsif ($item eq 'fields') {
4688: my @currfields;
4689: if (ref($currvalidation{$item}) eq 'ARRAY') {
4690: @currfields = @{$currvalidation{$item}};
4691: }
4692: foreach my $field (@{$fieldsref}) {
4693: my $check = '';
4694: if (grep(/^\Q$field\E$/,@currfields)) {
4695: $check = ' checked="checked"';
4696: }
4697: $datatable .= '<span class="LC_nobreak"><label>'.
4698: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4699: ' value="'.$field.'"'.$check.' />'.$field.
4700: '</label></span> ';
4701: }
4702: } elsif ($item eq 'markup') {
4703: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4704: $currvalidation{$item}.
1.231 raeburn 4705: '</textarea>';
1.235 raeburn 4706: }
4707: $datatable .= '</td></tr>'."\n";
4708: if (ref($rowtotal)) {
1.231 raeburn 4709: $itemcount ++;
4710: }
4711: }
1.235 raeburn 4712: if ($caller eq 'requestcourses') {
4713: my %currhash;
1.248 raeburn 4714: if (ref($settings) eq 'HASH') {
4715: if (ref($settings->{'validation'}) eq 'HASH') {
4716: if ($settings->{'validation'}{'dc'} ne '') {
4717: $currhash{$settings->{'validation'}{'dc'}} = 1;
4718: }
1.235 raeburn 4719: }
4720: }
4721: my $numinrow = 2;
4722: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4723: 'validationdc',%currhash);
1.247 raeburn 4724: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4725: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 4726: if ($numdc > 1) {
1.247 raeburn 4727: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 4728: } else {
1.247 raeburn 4729: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 4730: }
1.247 raeburn 4731: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 4732: $itemcount ++;
4733: }
4734: if (ref($rowtotal)) {
4735: $$rowtotal += $itemcount;
4736: }
1.231 raeburn 4737: return $datatable;
4738: }
4739:
1.137 raeburn 4740: sub print_usersessions {
4741: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 4742: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 4743: my (%by_ip,%by_location,@intdoms,@instdoms);
4744: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 4745:
4746: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4747: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4748: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4749: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4750: if ($position eq 'top') {
1.152 raeburn 4751: if (keys(%serverhomes) > 1) {
1.145 raeburn 4752: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 4753: my $curroffloadnow;
4754: if (ref($settings) eq 'HASH') {
4755: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4756: $curroffloadnow = $settings->{'offloadnow'};
4757: }
4758: }
4759: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4760: } else {
1.140 raeburn 4761: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 4762: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
4763: '</td></tr>';
1.140 raeburn 4764: }
1.137 raeburn 4765: } else {
1.279 raeburn 4766: my %titles = &usersession_titles();
4767: my ($prefix,@types);
4768: if ($position eq 'bottom') {
4769: $prefix = 'remote';
4770: @types = ('version','excludedomain','includedomain');
1.145 raeburn 4771: } else {
1.279 raeburn 4772: $prefix = 'hosted';
4773: @types = ('excludedomain','includedomain');
4774: }
4775: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4776: }
4777: $$rowtotal += $itemcount;
4778: return $datatable;
4779: }
4780:
4781: sub rules_by_location {
4782: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
4783: my ($datatable,$itemcount,$css_class);
4784: if (keys(%{$by_location}) == 0) {
4785: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4786: $datatable = '<tr'.$css_class.'><td colspan="2">'.
4787: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
4788: '</td></tr>';
4789: $itemcount = 1;
4790: } else {
4791: $itemcount = 0;
4792: my $numinrow = 5;
4793: my (%current,%checkedon,%checkedoff);
4794: my @locations = sort(keys(%{$by_location}));
4795: foreach my $type (@{$types}) {
4796: $checkedon{$type} = '';
4797: $checkedoff{$type} = ' checked="checked"';
4798: }
4799: if (ref($settings) eq 'HASH') {
4800: if (ref($settings->{$prefix}) eq 'HASH') {
4801: foreach my $key (keys(%{$settings->{$prefix}})) {
4802: $current{$key} = $settings->{$prefix}{$key};
4803: if ($key eq 'version') {
4804: if ($current{$key} ne '') {
1.145 raeburn 4805: $checkedon{$key} = ' checked="checked"';
4806: $checkedoff{$key} = '';
4807: }
1.279 raeburn 4808: } elsif (ref($current{$key}) eq 'ARRAY') {
4809: $checkedon{$key} = ' checked="checked"';
4810: $checkedoff{$key} = '';
1.137 raeburn 4811: }
4812: }
4813: }
1.279 raeburn 4814: }
4815: foreach my $type (@{$types}) {
4816: next if ($type ne 'version' && !@locations);
4817: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4818: $datatable .= '<tr'.$css_class.'>
4819: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4820: <span class="LC_nobreak">
4821: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4822: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4823: if ($type eq 'version') {
4824: my @lcversions = &Apache::lonnet::all_loncaparevs();
4825: my $selector = '<select name="'.$prefix.'_version">';
4826: foreach my $version (@lcversions) {
4827: my $selected = '';
4828: if ($current{'version'} eq $version) {
4829: $selected = ' selected="selected"';
1.145 raeburn 4830: }
1.279 raeburn 4831: $selector .= ' <option value="'.$version.'"'.
4832: $selected.'>'.$version.'</option>';
4833: }
4834: $selector .= '</select> ';
4835: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4836: } else {
4837: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4838: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4839: ' />'.(' 'x2).
4840: '<input type="button" value="'.&mt('uncheck all').'" '.
4841: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4842: "\n".
4843: '</div><div><table>';
4844: my $rem;
4845: for (my $i=0; $i<@locations; $i++) {
4846: my ($showloc,$value,$checkedtype);
4847: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4848: my $ip = $by_location->{$locations[$i]}->[0];
4849: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4850: $value = join(':',@{$by_ip->{$ip}});
4851: $showloc = join(', ',@{$by_ip->{$ip}});
4852: if (ref($current{$type}) eq 'ARRAY') {
4853: foreach my $loc (@{$by_ip->{$ip}}) {
4854: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4855: $checkedtype = ' checked="checked"';
4856: last;
1.145 raeburn 4857: }
1.138 raeburn 4858: }
4859: }
4860: }
1.137 raeburn 4861: }
1.279 raeburn 4862: $rem = $i%($numinrow);
4863: if ($rem == 0) {
4864: if ($i > 0) {
4865: $datatable .= '</tr>';
4866: }
4867: $datatable .= '<tr>';
4868: }
4869: $datatable .= '<td class="LC_left_item">'.
4870: '<span class="LC_nobreak"><label>'.
4871: '<input type="checkbox" name="'.$prefix.'_'.$type.
4872: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4873: '</label></span></td>';
4874: }
4875: $rem = @locations%($numinrow);
4876: my $colsleft = $numinrow - $rem;
4877: if ($colsleft > 1 ) {
4878: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4879: ' </td>';
4880: } elsif ($colsleft == 1) {
4881: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4882: }
1.279 raeburn 4883: $datatable .= '</tr></table>';
1.137 raeburn 4884: }
1.279 raeburn 4885: $datatable .= '</td></tr>';
4886: $itemcount ++;
1.137 raeburn 4887: }
4888: }
1.279 raeburn 4889: return ($datatable,$itemcount);
1.137 raeburn 4890: }
4891:
1.275 raeburn 4892: sub print_ssl {
4893: my ($position,$dom,$settings,$rowtotal) = @_;
4894: my ($css_class,$datatable);
4895: my $itemcount = 1;
4896: if ($position eq 'top') {
1.281 raeburn 4897: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4898: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4899: my $same_institution;
4900: if ($intdom ne '') {
4901: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4902: if (ref($internet_names) eq 'ARRAY') {
4903: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4904: $same_institution = 1;
4905: }
4906: }
4907: }
1.275 raeburn 4908: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 4909: $datatable = '<tr'.$css_class.'><td colspan="2">';
4910: if ($same_institution) {
4911: my %domservers = &Apache::lonnet::get_servers($dom);
4912: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
4913: } else {
4914: $datatable .= &mt("You need to be logged into one of your own domain's servers to display information about the status of LON-CAPA SSL certificates.");
4915: }
4916: $datatable .= '</td></tr>';
1.275 raeburn 4917: $itemcount ++;
4918: } else {
4919: my %titles = &ssl_titles();
4920: my (%by_ip,%by_location,@intdoms,@instdoms);
4921: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4922: my @alldoms = &Apache::lonnet::all_domains();
4923: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4924: my @domservers = &Apache::lonnet::get_servers($dom);
4925: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4926: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 4927: if (($position eq 'connto') || ($position eq 'connfrom')) {
4928: my $legacy;
4929: unless (ref($settings) eq 'HASH') {
4930: my $name;
4931: if ($position eq 'connto') {
4932: $name = 'loncAllowInsecure';
4933: } else {
4934: $name = 'londAllowInsecure';
4935: }
4936: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
4937: my @ids=&Apache::lonnet::current_machine_ids();
4938: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
4939: my %what = (
4940: $name => 1,
4941: );
4942: my ($result,$returnhash) =
4943: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
4944: if ($result eq 'ok') {
4945: if (ref($returnhash) eq 'HASH') {
4946: $legacy = $returnhash->{$name};
4947: }
4948: }
4949: } else {
4950: $legacy = $Apache::lonnet::perlvar{$name};
4951: }
4952: }
1.275 raeburn 4953: foreach my $type ('dom','intdom','other') {
4954: my %checked;
4955: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4956: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4957: '<td class="LC_right_item">';
4958: my $skip;
4959: if ($type eq 'dom') {
4960: unless (keys(%servers) > 1) {
4961: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4962: $skip = 1;
4963: }
4964: }
4965: if ($type eq 'intdom') {
4966: unless (@instdoms > 1) {
4967: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4968: $skip = 1;
4969: }
4970: } elsif ($type eq 'other') {
4971: if (keys(%by_location) == 0) {
4972: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4973: $skip = 1;
4974: }
4975: }
4976: unless ($skip) {
4977: $checked{'yes'} = ' checked="checked"';
4978: if (ref($settings) eq 'HASH') {
1.293 raeburn 4979: if (ref($settings->{$position}) eq 'HASH') {
4980: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 4981: $checked{$1} = $checked{'yes'};
4982: delete($checked{'yes'});
4983: }
4984: }
1.293 raeburn 4985: } else {
4986: if ($legacy == 0) {
4987: $checked{'req'} = $checked{'yes'};
4988: delete($checked{'yes'});
4989: }
1.275 raeburn 4990: }
4991: foreach my $option ('no','yes','req') {
4992: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 4993: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 4994: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4995: '</label></span>'.(' 'x2);
4996: }
4997: }
4998: $datatable .= '</td></tr>';
4999: $itemcount ++;
5000: }
5001: } else {
5002: my $prefix = 'replication';
5003: my @types = ('certreq','nocertreq');
1.279 raeburn 5004: if (keys(%by_location) == 0) {
5005: $datatable .= '<tr'.$css_class.'><td>'.
5006: &mt('Nothing to set here, as there are no other institutions').
5007: '</td></tr>';
5008: $itemcount ++;
1.275 raeburn 5009: } else {
1.279 raeburn 5010: ($datatable,$itemcount) =
5011: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 5012: }
5013: }
5014: }
5015: $$rowtotal += $itemcount;
5016: return $datatable;
5017: }
5018:
5019: sub ssl_titles {
5020: return &Apache::lonlocal::texthash (
5021: dom => 'LON-CAPA servers/VMs from same domain',
5022: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
5023: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 5024: connto => 'Connections to other servers',
5025: connfrom => 'Connections from other servers',
1.275 raeburn 5026: replication => 'Replicating content to other institutions',
5027: certreq => 'Client certificate required, but specific domains exempt',
5028: nocertreq => 'No client certificate required, except for specific domains',
5029: no => 'SSL not used',
5030: yes => 'SSL Optional (used if available)',
5031: req => 'SSL Required',
5032: );
1.279 raeburn 5033: }
5034:
5035: sub print_trust {
5036: my ($prefix,$dom,$settings,$rowtotal) = @_;
5037: my ($css_class,$datatable,%checked,%choices);
5038: my (%by_ip,%by_location,@intdoms,@instdoms);
5039: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
5040: my $itemcount = 1;
5041: my %titles = &trust_titles();
5042: my @types = ('exc','inc');
5043: if ($prefix eq 'top') {
5044: $prefix = 'content';
5045: } elsif ($prefix eq 'bottom') {
5046: $prefix = 'msg';
5047: }
5048: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
5049: $$rowtotal += $itemcount;
5050: return $datatable;
5051: }
5052:
5053: sub trust_titles {
5054: return &Apache::lonlocal::texthash(
5055: content => "Access to this domain's content by others",
5056: shared => "Access to other domain's content by this domain",
5057: enroll => "Enrollment in this domain's courses by others",
5058: othcoau => "Co-author roles in this domain for others",
5059: coaurem => "Co-author roles for this domain's users elsewhere",
5060: domroles => "Domain roles in this domain assignable to others",
5061: catalog => "Course Catalog for this domain displayed elsewhere",
5062: reqcrs => "Requests for creation of courses in this domain by others",
5063: msg => "Users in other domains can send messages to this domain",
5064: exc => "Allow all, but exclude specific domains",
5065: inc => "Deny all, but include specific domains",
5066: );
1.275 raeburn 5067: }
5068:
1.138 raeburn 5069: sub build_location_hashes {
1.275 raeburn 5070: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 5071: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 5072: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 5073: my %iphost = &Apache::lonnet::get_iphost();
5074: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
5075: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
5076: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
5077: foreach my $id (@{$iphost{$primary_ip}}) {
5078: my $intdom = &Apache::lonnet::internet_dom($id);
5079: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
5080: push(@{$intdoms},$intdom);
5081: }
5082: }
5083: }
5084: foreach my $ip (keys(%iphost)) {
5085: if (ref($iphost{$ip}) eq 'ARRAY') {
5086: foreach my $id (@{$iphost{$ip}}) {
5087: my $location = &Apache::lonnet::internet_dom($id);
5088: if ($location) {
1.275 raeburn 5089: if (grep(/^\Q$location\E$/,@{$intdoms})) {
5090: my $dom = &Apache::lonnet::host_domain($id);
5091: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
5092: push(@{$instdoms},$dom);
5093: }
5094: next;
5095: }
1.138 raeburn 5096: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5097: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
5098: push(@{$by_ip->{$ip}},$location);
5099: }
5100: } else {
5101: $by_ip->{$ip} = [$location];
5102: }
5103: }
5104: }
5105: }
5106: }
5107: foreach my $ip (sort(keys(%{$by_ip}))) {
5108: if (ref($by_ip->{$ip}) eq 'ARRAY') {
5109: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
5110: my $first = $by_ip->{$ip}->[0];
5111: if (ref($by_location->{$first}) eq 'ARRAY') {
5112: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
5113: push(@{$by_location->{$first}},$ip);
5114: }
5115: } else {
5116: $by_location->{$first} = [$ip];
5117: }
5118: }
5119: }
5120: return;
5121: }
5122:
1.145 raeburn 5123: sub current_offloads_to {
5124: my ($dom,$settings,$servers) = @_;
5125: my (%spareid,%otherdomconfigs);
1.152 raeburn 5126: if (ref($servers) eq 'HASH') {
1.145 raeburn 5127: foreach my $lonhost (sort(keys(%{$servers}))) {
5128: my $gotspares;
1.152 raeburn 5129: if (ref($settings) eq 'HASH') {
5130: if (ref($settings->{'spares'}) eq 'HASH') {
5131: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
5132: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
5133: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
5134: $gotspares = 1;
5135: }
1.145 raeburn 5136: }
5137: }
5138: unless ($gotspares) {
5139: my $gotspares;
5140: my $serverhomeID =
5141: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
5142: my $serverhomedom =
5143: &Apache::lonnet::host_domain($serverhomeID);
5144: if ($serverhomedom ne $dom) {
5145: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
5146: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5147: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5148: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5149: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5150: $gotspares = 1;
5151: }
5152: }
5153: } else {
5154: $otherdomconfigs{$serverhomedom} =
5155: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
5156: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
5157: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
5158: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
5159: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
5160: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
5161: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
5162: $gotspares = 1;
5163: }
5164: }
5165: }
5166: }
5167: }
5168: }
5169: }
5170: unless ($gotspares) {
5171: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
5172: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5173: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5174: } else {
5175: my $server_hostname = &Apache::lonnet::hostname($lonhost);
5176: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
5177: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
5178: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
5179: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
5180: } else {
1.150 raeburn 5181: my %what = (
5182: spareid => 1,
5183: );
5184: my ($result,$returnhash) =
5185: &Apache::lonnet::get_remote_globals($lonhost,\%what);
5186: if ($result eq 'ok') {
5187: if (ref($returnhash) eq 'HASH') {
5188: if (ref($returnhash->{'spareid'}) eq 'HASH') {
5189: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5190: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5191: }
5192: }
1.145 raeburn 5193: }
5194: }
5195: }
5196: }
5197: }
5198: }
5199: return %spareid;
5200: }
5201:
5202: sub spares_row {
1.261 raeburn 5203: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 5204: my $css_class;
5205: my $numinrow = 4;
5206: my $itemcount = 1;
5207: my $datatable;
1.152 raeburn 5208: my %typetitles = &sparestype_titles();
5209: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5210: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5211: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5212: my ($othercontrol,$serverdom);
5213: if ($serverhome ne $server) {
5214: $serverdom = &Apache::lonnet::host_domain($serverhome);
5215: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5216: } else {
5217: $serverdom = &Apache::lonnet::host_domain($server);
5218: if ($serverdom ne $dom) {
5219: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5220: }
5221: }
5222: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 5223: my $checkednow;
5224: if (ref($curroffloadnow) eq 'HASH') {
5225: if ($curroffloadnow->{$server}) {
5226: $checkednow = ' checked="checked"';
5227: }
5228: }
1.145 raeburn 5229: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5230: $datatable .= '<tr'.$css_class.'>
5231: <td rowspan="2">
1.183 bisitz 5232: <span class="LC_nobreak">'.
5233: &mt('[_1] when busy, offloads to:'
1.261 raeburn 5234: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 5235: '<span class="LC_nobreak">'."\n".
1.261 raeburn 5236: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5237: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 5238: "\n";
1.145 raeburn 5239: my (%current,%canselect);
1.152 raeburn 5240: my @choices =
5241: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5242: foreach my $type ('primary','default') {
5243: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5244: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5245: my @spares = @{$spareid->{$server}{$type}};
5246: if (@spares > 0) {
1.152 raeburn 5247: if ($othercontrol) {
5248: $current{$type} = join(', ',@spares);
5249: } else {
5250: $current{$type} .= '<table>';
5251: my $numspares = scalar(@spares);
5252: for (my $i=0; $i<@spares; $i++) {
5253: my $rem = $i%($numinrow);
5254: if ($rem == 0) {
5255: if ($i > 0) {
5256: $current{$type} .= '</tr>';
5257: }
5258: $current{$type} .= '<tr>';
1.145 raeburn 5259: }
1.152 raeburn 5260: $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'".');" /> '.
5261: $spareid->{$server}{$type}[$i].
5262: '</label></td>'."\n";
5263: }
5264: my $rem = @spares%($numinrow);
5265: my $colsleft = $numinrow - $rem;
5266: if ($colsleft > 1 ) {
5267: $current{$type} .= '<td colspan="'.$colsleft.
5268: '" class="LC_left_item">'.
5269: ' </td>';
5270: } elsif ($colsleft == 1) {
5271: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5272: }
1.152 raeburn 5273: $current{$type} .= '</tr></table>';
1.150 raeburn 5274: }
1.145 raeburn 5275: }
5276: }
5277: if ($current{$type} eq '') {
5278: $current{$type} = &mt('None specified');
5279: }
1.152 raeburn 5280: if ($othercontrol) {
5281: if ($type eq 'primary') {
5282: $canselect{$type} = $othercontrol;
5283: }
5284: } else {
5285: $canselect{$type} =
5286: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5287: '<select name="newspare_'.$type.'_'.$server.'" '.
5288: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5289: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5290: if (@choices > 0) {
5291: foreach my $lonhost (@choices) {
5292: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5293: }
5294: }
5295: $canselect{$type} .= '</select>'."\n";
5296: }
5297: } else {
5298: $current{$type} = &mt('Could not be determined');
5299: if ($type eq 'primary') {
5300: $canselect{$type} = $othercontrol;
5301: }
1.145 raeburn 5302: }
1.152 raeburn 5303: if ($type eq 'default') {
5304: $datatable .= '<tr'.$css_class.'>';
5305: }
5306: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5307: '<td>'.$current{$type}.'</td>'."\n".
5308: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5309: }
5310: $itemcount ++;
5311: }
5312: }
5313: $$rowtotal += $itemcount;
5314: return $datatable;
5315: }
5316:
1.152 raeburn 5317: sub possible_newspares {
5318: my ($server,$currspares,$serverhomes,$altids) = @_;
5319: my $serverhostname = &Apache::lonnet::hostname($server);
5320: my %excluded;
5321: if ($serverhostname ne '') {
5322: %excluded = (
5323: $serverhostname => 1,
5324: );
5325: }
5326: if (ref($currspares) eq 'HASH') {
5327: foreach my $type (keys(%{$currspares})) {
5328: if (ref($currspares->{$type}) eq 'ARRAY') {
5329: if (@{$currspares->{$type}} > 0) {
5330: foreach my $curr (@{$currspares->{$type}}) {
5331: my $hostname = &Apache::lonnet::hostname($curr);
5332: $excluded{$hostname} = 1;
5333: }
5334: }
5335: }
5336: }
5337: }
5338: my @choices;
5339: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5340: if (keys(%{$serverhomes}) > 1) {
5341: foreach my $name (sort(keys(%{$serverhomes}))) {
5342: unless ($excluded{$name}) {
5343: if (exists($altids->{$serverhomes->{$name}})) {
5344: push(@choices,$altids->{$serverhomes->{$name}});
5345: } else {
5346: push(@choices,$serverhomes->{$name});
1.145 raeburn 5347: }
5348: }
5349: }
5350: }
5351: }
1.152 raeburn 5352: return sort(@choices);
1.145 raeburn 5353: }
5354:
1.150 raeburn 5355: sub print_loadbalancing {
5356: my ($dom,$settings,$rowtotal) = @_;
5357: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5358: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5359: my $numinrow = 1;
5360: my $datatable;
5361: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5362: my (%currbalancer,%currtargets,%currrules,%existing);
5363: if (ref($settings) eq 'HASH') {
5364: %existing = %{$settings};
5365: }
5366: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5367: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5368: \%currtargets,\%currrules);
1.150 raeburn 5369: } else {
5370: return;
5371: }
5372: my ($othertitle,$usertypes,$types) =
5373: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5374: my $rownum = 8;
1.150 raeburn 5375: if (ref($types) eq 'ARRAY') {
5376: $rownum += scalar(@{$types});
5377: }
1.171 raeburn 5378: my @css_class = ('LC_odd_row','LC_even_row');
5379: my $balnum = 0;
5380: my $islast;
5381: my (@toshow,$disabledtext);
5382: if (keys(%currbalancer) > 0) {
5383: @toshow = sort(keys(%currbalancer));
5384: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5385: push(@toshow,'');
5386: }
5387: } else {
5388: @toshow = ('');
5389: $disabledtext = &mt('No existing load balancer');
5390: }
5391: foreach my $lonhost (@toshow) {
5392: if ($balnum == scalar(@toshow)-1) {
5393: $islast = 1;
5394: } else {
5395: $islast = 0;
5396: }
5397: my $cssidx = $balnum%2;
5398: my $targets_div_style = 'display: none';
5399: my $disabled_div_style = 'display: block';
5400: my $homedom_div_style = 'display: none';
5401: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 5402: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 5403: '<p>';
5404: if ($lonhost eq '') {
1.210 raeburn 5405: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 5406: if (keys(%currbalancer) > 0) {
5407: $datatable .= &mt('Add balancer:');
5408: } else {
5409: $datatable .= &mt('Enable balancer:');
5410: }
5411: $datatable .= ' '.
5412: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5413: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5414: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5415: '<option value="" selected="selected">'.&mt('None').
5416: '</option>'."\n";
5417: foreach my $server (sort(keys(%servers))) {
5418: next if ($currbalancer{$server});
5419: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5420: }
1.210 raeburn 5421: $datatable .=
1.171 raeburn 5422: '</select>'."\n".
5423: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5424: } else {
5425: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5426: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5427: &mt('Stop balancing').'</label>'.
5428: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5429: $targets_div_style = 'display: block';
5430: $disabled_div_style = 'display: none';
5431: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5432: $homedom_div_style = 'display: block';
5433: }
5434: }
1.306 raeburn 5435: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 5436: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5437: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5438: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5439: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5440: my @sparestypes = ('primary','default');
5441: my %typetitles = &sparestype_titles();
1.284 raeburn 5442: my %hostherechecked = (
5443: no => ' checked="checked"',
5444: );
1.171 raeburn 5445: foreach my $sparetype (@sparestypes) {
5446: my $targettable;
5447: for (my $i=0; $i<$numspares; $i++) {
5448: my $checked;
5449: if (ref($currtargets{$lonhost}) eq 'HASH') {
5450: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5451: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5452: $checked = ' checked="checked"';
5453: }
5454: }
5455: }
5456: my ($chkboxval,$disabled);
5457: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5458: $chkboxval = $spares[$i];
5459: }
5460: if (exists($currbalancer{$spares[$i]})) {
5461: $disabled = ' disabled="disabled"';
5462: }
1.210 raeburn 5463: $targettable .=
1.253 raeburn 5464: '<td><span class="LC_nobreak"><label>'.
5465: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 5466: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.253 raeburn 5467: '</span></label></span></td>';
1.171 raeburn 5468: my $rem = $i%($numinrow);
5469: if ($rem == 0) {
5470: if (($i > 0) && ($i < $numspares-1)) {
5471: $targettable .= '</tr>';
5472: }
5473: if ($i < $numspares-1) {
5474: $targettable .= '<tr>';
1.150 raeburn 5475: }
5476: }
5477: }
1.171 raeburn 5478: if ($targettable ne '') {
5479: my $rem = $numspares%($numinrow);
5480: my $colsleft = $numinrow - $rem;
5481: if ($colsleft > 1 ) {
5482: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5483: ' </td>';
5484: } elsif ($colsleft == 1) {
5485: $targettable .= '<td class="LC_left_item"> </td>';
5486: }
5487: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5488: '<table><tr>'.$targettable.'</tr></table><br />';
5489: }
1.284 raeburn 5490: $hostherechecked{$sparetype} = '';
5491: if (ref($currtargets{$lonhost}) eq 'HASH') {
5492: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5493: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5494: $hostherechecked{$sparetype} = ' checked="checked"';
5495: $hostherechecked{'no'} = '';
5496: }
5497: }
5498: }
5499: }
5500: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5501: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5502: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5503: foreach my $sparetype (@sparestypes) {
5504: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5505: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5506: '</i></label><br />';
1.171 raeburn 5507: }
5508: $datatable .= '</div></td></tr>'.
5509: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5510: $othertitle,$usertypes,$types,\%servers,
5511: \%currbalancer,$lonhost,
5512: $targets_div_style,$homedom_div_style,
5513: $css_class[$cssidx],$balnum,$islast);
5514: $$rowtotal += $rownum;
5515: $balnum ++;
5516: }
5517: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5518: return $datatable;
5519: }
5520:
5521: sub get_loadbalancers_config {
5522: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5523: return unless ((ref($servers) eq 'HASH') &&
5524: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5525: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5526: if (keys(%{$existing}) > 0) {
5527: my $oldlonhost;
5528: foreach my $key (sort(keys(%{$existing}))) {
5529: if ($key eq 'lonhost') {
5530: $oldlonhost = $existing->{'lonhost'};
5531: $currbalancer->{$oldlonhost} = 1;
5532: } elsif ($key eq 'targets') {
5533: if ($oldlonhost) {
5534: $currtargets->{$oldlonhost} = $existing->{'targets'};
5535: }
5536: } elsif ($key eq 'rules') {
5537: if ($oldlonhost) {
5538: $currrules->{$oldlonhost} = $existing->{'rules'};
5539: }
5540: } elsif (ref($existing->{$key}) eq 'HASH') {
5541: $currbalancer->{$key} = 1;
5542: $currtargets->{$key} = $existing->{$key}{'targets'};
5543: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5544: }
5545: }
1.171 raeburn 5546: } else {
5547: my ($balancerref,$targetsref) =
5548: &Apache::lonnet::get_lonbalancer_config($servers);
5549: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5550: foreach my $server (sort(keys(%{$balancerref}))) {
5551: $currbalancer->{$server} = 1;
5552: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5553: }
5554: }
5555: }
1.171 raeburn 5556: return;
1.150 raeburn 5557: }
5558:
5559: sub loadbalancing_rules {
5560: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 5561: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5562: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5563: my $output;
1.171 raeburn 5564: my $num = 0;
1.210 raeburn 5565: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5566: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5567: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5568: foreach my $type (@{$alltypes}) {
1.171 raeburn 5569: $num ++;
1.150 raeburn 5570: my $current;
5571: if (ref($currrules) eq 'HASH') {
5572: $current = $currrules->{$type};
5573: }
1.253 raeburn 5574: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 5575: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5576: $current = '';
5577: }
5578: }
5579: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 5580: $servers,$currbalancer,$lonhost,$dom,
5581: $targets_div_style,$homedom_div_style,
5582: $css_class,$balnum,$num,$islast);
1.150 raeburn 5583: }
5584: }
5585: return $output;
5586: }
5587:
5588: sub loadbalancing_titles {
5589: my ($dom,$intdom,$usertypes,$types) = @_;
5590: my %othertypes = (
5591: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5592: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5593: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5594: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 5595: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5596: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5597: );
1.209 raeburn 5598: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 5599: my @available;
1.150 raeburn 5600: if (ref($types) eq 'ARRAY') {
1.302 raeburn 5601: @available = @{$types};
1.150 raeburn 5602: }
1.302 raeburn 5603: unless (grep(/^default$/,@available)) {
5604: push(@available,'default');
5605: }
5606: unshift(@alltypes,@available);
1.150 raeburn 5607: my %titles;
5608: foreach my $type (@alltypes) {
5609: if ($type =~ /^_LC_/) {
5610: $titles{$type} = $othertypes{$type};
5611: } elsif ($type eq 'default') {
5612: $titles{$type} = &mt('All users from [_1]',$dom);
5613: if (ref($types) eq 'ARRAY') {
5614: if (@{$types} > 0) {
5615: $titles{$type} = &mt('Other users from [_1]',$dom);
5616: }
5617: }
5618: } elsif (ref($usertypes) eq 'HASH') {
5619: $titles{$type} = $usertypes->{$type};
5620: }
5621: }
5622: return (\@alltypes,\%othertypes,\%titles);
5623: }
5624:
5625: sub loadbalance_rule_row {
1.171 raeburn 5626: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5627: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 5628: my @rulenames;
1.150 raeburn 5629: my %ruletitles = &offloadtype_text();
1.209 raeburn 5630: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 5631: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5632: } else {
1.209 raeburn 5633: @rulenames = ('default','homeserver');
5634: if ($type eq '_LC_external') {
5635: push(@rulenames,'externalbalancer');
5636: } else {
5637: push(@rulenames,'specific');
5638: }
5639: push(@rulenames,'none');
1.150 raeburn 5640: }
5641: my $style = $targets_div_style;
1.253 raeburn 5642: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5643: $style = $homedom_div_style;
5644: }
1.171 raeburn 5645: my $space;
5646: if ($islast && $num == 1) {
5647: $space = '<div display="inline-block"> </div>';
5648: }
1.210 raeburn 5649: my $output =
1.306 raeburn 5650: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 5651: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5652: '<td valaign="top">'.$space.
5653: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5654: for (my $i=0; $i<@rulenames; $i++) {
5655: my $rule = $rulenames[$i];
5656: my ($checked,$extra);
5657: if ($rulenames[$i] eq 'default') {
5658: $rule = '';
5659: }
5660: if ($rulenames[$i] eq 'specific') {
5661: if (ref($servers) eq 'HASH') {
5662: my $default;
5663: if (($current ne '') && (exists($servers->{$current}))) {
5664: $checked = ' checked="checked"';
5665: }
5666: unless ($checked) {
5667: $default = ' selected="selected"';
5668: }
1.210 raeburn 5669: $extra =
1.171 raeburn 5670: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5671: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5672: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5673: '<option value=""'.$default.'></option>'."\n";
5674: foreach my $server (sort(keys(%{$servers}))) {
5675: if (ref($currbalancer) eq 'HASH') {
5676: next if (exists($currbalancer->{$server}));
5677: }
1.150 raeburn 5678: my $selected;
1.171 raeburn 5679: if ($server eq $current) {
1.150 raeburn 5680: $selected = ' selected="selected"';
5681: }
1.171 raeburn 5682: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5683: }
5684: $extra .= '</select>';
5685: }
5686: } elsif ($rule eq $current) {
5687: $checked = ' checked="checked"';
5688: }
5689: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 5690: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5691: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5692: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 5693: ')"'.$checked.' /> ';
5694: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
5695: $output .= $ruletitles{'particular'};
5696: } else {
5697: $output .= $ruletitles{$rulenames[$i]};
5698: }
5699: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5700: }
5701: $output .= '</div></td></tr>'."\n";
5702: return $output;
5703: }
5704:
5705: sub offloadtype_text {
5706: my %ruletitles = &Apache::lonlocal::texthash (
5707: 'default' => 'Offloads to default destinations',
5708: 'homeserver' => "Offloads to user's home server",
5709: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5710: 'specific' => 'Offloads to specific server',
1.161 raeburn 5711: 'none' => 'No offload',
1.209 raeburn 5712: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5713: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 5714: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5715: );
5716: return %ruletitles;
5717: }
5718:
5719: sub sparestype_titles {
5720: my %typestitles = &Apache::lonlocal::texthash (
5721: 'primary' => 'primary',
5722: 'default' => 'default',
5723: );
5724: return %typestitles;
5725: }
5726:
1.28 raeburn 5727: sub contact_titles {
5728: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 5729: 'supportemail' => 'Support E-mail address',
5730: 'adminemail' => 'Default Server Admin E-mail address',
5731: 'errormail' => 'Error reports to be e-mailed to',
5732: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 ! raeburn 5733: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
! 5734: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 5735: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5736: 'requestsmail' => 'E-mail from course requests requiring approval',
5737: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 5738: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5739: );
5740: my %short_titles = &Apache::lonlocal::texthash (
5741: adminemail => 'Admin E-mail address',
5742: supportemail => 'Support E-mail',
5743: );
5744: return (\%titles,\%short_titles);
5745: }
5746:
1.286 raeburn 5747: sub helpform_fields {
5748: my %titles = &Apache::lonlocal::texthash (
5749: 'username' => 'Name',
5750: 'user' => 'Username/domain',
5751: 'phone' => 'Phone',
5752: 'cc' => 'Cc e-mail',
5753: 'course' => 'Course Details',
5754: 'section' => 'Sections',
1.289 raeburn 5755: 'screenshot' => 'File upload',
1.286 raeburn 5756: );
5757: my @fields = ('username','phone','user','course','section','cc','screenshot');
5758: my %possoptions = (
5759: username => ['yes','no','req'],
1.289 raeburn 5760: phone => ['yes','no','req'],
1.286 raeburn 5761: user => ['yes','no'],
1.289 raeburn 5762: cc => ['yes','no'],
1.286 raeburn 5763: course => ['yes','no'],
5764: section => ['yes','no'],
5765: screenshot => ['yes','no'],
5766: );
5767: my %fieldoptions = &Apache::lonlocal::texthash (
5768: 'yes' => 'Optional',
5769: 'req' => 'Required',
5770: 'no' => "Not shown",
5771: );
5772: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5773: }
5774:
1.72 raeburn 5775: sub tool_titles {
5776: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 5777: aboutme => 'Personal web page',
1.86 raeburn 5778: blog => 'Blog',
1.162 raeburn 5779: webdav => 'WebDAV',
1.86 raeburn 5780: portfolio => 'Portfolio',
1.88 bisitz 5781: official => 'Official courses (with institutional codes)',
5782: unofficial => 'Unofficial courses',
1.98 raeburn 5783: community => 'Communities',
1.216 raeburn 5784: textbook => 'Textbook courses',
1.271 raeburn 5785: placement => 'Placement tests',
1.86 raeburn 5786: );
1.72 raeburn 5787: return %titles;
5788: }
5789:
1.101 raeburn 5790: sub courserequest_titles {
5791: my %titles = &Apache::lonlocal::texthash (
5792: official => 'Official',
5793: unofficial => 'Unofficial',
5794: community => 'Communities',
1.216 raeburn 5795: textbook => 'Textbook',
1.271 raeburn 5796: placement => 'Placement tests',
1.101 raeburn 5797: norequest => 'Not allowed',
1.104 raeburn 5798: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5799: validate => 'With validation',
5800: autolimit => 'Numerical limit',
1.103 raeburn 5801: unlimited => '(blank for unlimited)',
1.101 raeburn 5802: );
5803: return %titles;
5804: }
5805:
1.163 raeburn 5806: sub authorrequest_titles {
5807: my %titles = &Apache::lonlocal::texthash (
5808: norequest => 'Not allowed',
5809: approval => 'Approval by Dom. Coord.',
5810: automatic => 'Automatic approval',
5811: );
5812: return %titles;
1.210 raeburn 5813: }
1.163 raeburn 5814:
1.101 raeburn 5815: sub courserequest_conditions {
5816: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5817: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 5818: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5819: );
5820: return %conditions;
5821: }
5822:
5823:
1.27 raeburn 5824: sub print_usercreation {
1.30 raeburn 5825: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5826: my $numinrow = 4;
1.28 raeburn 5827: my $datatable;
5828: if ($position eq 'top') {
1.30 raeburn 5829: $$rowtotal ++;
1.34 raeburn 5830: my $rowcount = 0;
1.32 raeburn 5831: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5832: if (ref($rules) eq 'HASH') {
5833: if (keys(%{$rules}) > 0) {
1.32 raeburn 5834: $datatable .= &user_formats_row('username',$settings,$rules,
5835: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5836: $$rowtotal ++;
1.32 raeburn 5837: $rowcount ++;
5838: }
5839: }
5840: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5841: if (ref($idrules) eq 'HASH') {
5842: if (keys(%{$idrules}) > 0) {
5843: $datatable .= &user_formats_row('id',$settings,$idrules,
5844: $idruleorder,$numinrow,$rowcount);
5845: $$rowtotal ++;
5846: $rowcount ++;
1.28 raeburn 5847: }
5848: }
1.39 raeburn 5849: if ($rowcount == 0) {
5850: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5851: $$rowtotal ++;
5852: $rowcount ++;
5853: }
1.34 raeburn 5854: } elsif ($position eq 'middle') {
1.224 raeburn 5855: my @creators = ('author','course','requestcrs');
1.37 raeburn 5856: my ($rules,$ruleorder) =
5857: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5858: my %lt = &usercreation_types();
5859: my %checked;
5860: if (ref($settings) eq 'HASH') {
5861: if (ref($settings->{'cancreate'}) eq 'HASH') {
5862: foreach my $item (@creators) {
5863: $checked{$item} = $settings->{'cancreate'}{$item};
5864: }
5865: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5866: foreach my $item (@creators) {
5867: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5868: $checked{$item} = 'none';
5869: }
5870: }
5871: }
5872: }
5873: my $rownum = 0;
5874: foreach my $item (@creators) {
5875: $rownum ++;
1.224 raeburn 5876: if ($checked{$item} eq '') {
5877: $checked{$item} = 'any';
1.34 raeburn 5878: }
5879: my $css_class;
5880: if ($rownum%2) {
5881: $css_class = '';
5882: } else {
5883: $css_class = ' class="LC_odd_row" ';
5884: }
5885: $datatable .= '<tr'.$css_class.'>'.
5886: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 5887: '</span></td><td style="text-align: right">';
1.224 raeburn 5888: my @options = ('any');
5889: if (ref($rules) eq 'HASH') {
5890: if (keys(%{$rules}) > 0) {
5891: push(@options,('official','unofficial'));
1.37 raeburn 5892: }
5893: }
1.224 raeburn 5894: push(@options,'none');
1.37 raeburn 5895: foreach my $option (@options) {
1.50 raeburn 5896: my $type = 'radio';
1.34 raeburn 5897: my $check = ' ';
1.224 raeburn 5898: if ($checked{$item} eq $option) {
5899: $check = ' checked="checked" ';
1.34 raeburn 5900: }
5901: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5902: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5903: $item.'" value="'.$option.'"'.$check.'/> '.
5904: $lt{$option}.'</label> </span>';
5905: }
5906: $datatable .= '</td></tr>';
5907: }
1.28 raeburn 5908: } else {
5909: my @contexts = ('author','course','domain');
5910: my @authtypes = ('int','krb4','krb5','loc');
5911: my %checked;
5912: if (ref($settings) eq 'HASH') {
5913: if (ref($settings->{'authtypes'}) eq 'HASH') {
5914: foreach my $item (@contexts) {
5915: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5916: foreach my $auth (@authtypes) {
5917: if ($settings->{'authtypes'}{$item}{$auth}) {
5918: $checked{$item}{$auth} = ' checked="checked" ';
5919: }
5920: }
5921: }
5922: }
1.27 raeburn 5923: }
1.35 raeburn 5924: } else {
5925: foreach my $item (@contexts) {
1.36 raeburn 5926: foreach my $auth (@authtypes) {
1.35 raeburn 5927: $checked{$item}{$auth} = ' checked="checked" ';
5928: }
5929: }
1.27 raeburn 5930: }
1.28 raeburn 5931: my %title = &context_names();
5932: my %authname = &authtype_names();
5933: my $rownum = 0;
5934: my $css_class;
5935: foreach my $item (@contexts) {
5936: if ($rownum%2) {
5937: $css_class = '';
5938: } else {
5939: $css_class = ' class="LC_odd_row" ';
5940: }
1.30 raeburn 5941: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5942: '<td>'.$title{$item}.
5943: '</td><td class="LC_left_item">'.
5944: '<span class="LC_nobreak">';
5945: foreach my $auth (@authtypes) {
5946: $datatable .= '<label>'.
5947: '<input type="checkbox" name="'.$item.'_auth" '.
5948: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5949: $authname{$auth}.'</label> ';
5950: }
5951: $datatable .= '</span></td></tr>';
5952: $rownum ++;
1.27 raeburn 5953: }
1.30 raeburn 5954: $$rowtotal += $rownum;
1.27 raeburn 5955: }
5956: return $datatable;
5957: }
5958:
1.224 raeburn 5959: sub print_selfcreation {
5960: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 5961: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
5962: $emaildomain,$datatable);
1.224 raeburn 5963: if (ref($settings) eq 'HASH') {
5964: if (ref($settings->{'cancreate'}) eq 'HASH') {
5965: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5966: if (ref($createsettings) eq 'HASH') {
5967: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5968: @selfcreate = @{$createsettings->{'selfcreate'}};
5969: } elsif ($createsettings->{'selfcreate'} ne '') {
5970: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5971: @selfcreate = ('email','login','sso');
5972: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5973: @selfcreate = ($createsettings->{'selfcreate'});
5974: }
5975: }
5976: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5977: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5978: }
1.305 raeburn 5979: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
5980: $emailoptions = $createsettings->{'emailoptions'};
5981: }
1.303 raeburn 5982: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
5983: $emailverified = $createsettings->{'emailverified'};
5984: }
5985: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
5986: $emaildomain = $createsettings->{'emaildomain'};
5987: }
1.224 raeburn 5988: }
5989: }
5990: }
5991: my %radiohash;
5992: my $numinrow = 4;
5993: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 5994: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 5995: if ($position eq 'top') {
5996: my %choices = &Apache::lonlocal::texthash (
5997: cancreate_login => 'Institutional Login',
5998: cancreate_sso => 'Institutional Single Sign On',
5999: );
6000: my @toggles = sort(keys(%choices));
6001: my %defaultchecked = (
6002: 'cancreate_login' => 'off',
6003: 'cancreate_sso' => 'off',
6004: );
1.228 raeburn 6005: my ($onclick,$itemcount);
1.224 raeburn 6006: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6007: \%choices,$itemcount,$onclick);
1.228 raeburn 6008: $$rowtotal += $itemcount;
6009:
1.224 raeburn 6010: if (ref($usertypes) eq 'HASH') {
6011: if (keys(%{$usertypes}) > 0) {
6012: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
6013: $dom,$numinrow,$othertitle,
1.305 raeburn 6014: 'statustocreate',$rowtotal);
1.224 raeburn 6015: $$rowtotal ++;
6016: }
6017: }
1.240 raeburn 6018: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
6019: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6020: $fieldtitles{'inststatus'} = &mt('Institutional status');
6021: my $rem;
6022: my $numperrow = 2;
6023: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
6024: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 6025: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 6026: '<td class="LC_left_item">'."\n".
6027: '<table><tr><td>'."\n";
6028: for (my $i=0; $i<@fields; $i++) {
6029: $rem = $i%($numperrow);
6030: if ($rem == 0) {
6031: if ($i > 0) {
6032: $datatable .= '</tr>';
6033: }
6034: $datatable .= '<tr>';
6035: }
6036: my $currval;
1.248 raeburn 6037: if (ref($createsettings) eq 'HASH') {
6038: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
6039: $currval = $createsettings->{'shibenv'}{$fields[$i]};
6040: }
1.240 raeburn 6041: }
6042: $datatable .= '<td class="LC_left_item">'.
6043: '<span class="LC_nobreak">'.
6044: '<input type="text" name="shibenv_'.$fields[$i].'" '.
6045: 'value="'.$currval.'" size="10" /> '.
6046: $fieldtitles{$fields[$i]}.'</span></td>';
6047: }
6048: my $colsleft = $numperrow - $rem;
6049: if ($colsleft > 1 ) {
6050: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6051: ' </td>';
6052: } elsif ($colsleft == 1) {
6053: $datatable .= '<td class="LC_left_item"> </td>';
6054: }
6055: $datatable .= '</tr></table></td></tr>';
6056: $$rowtotal ++;
1.224 raeburn 6057: } elsif ($position eq 'middle') {
6058: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 6059: my @posstypes;
1.224 raeburn 6060: if (ref($types) eq 'ARRAY') {
1.302 raeburn 6061: @posstypes = @{$types};
6062: }
6063: unless (grep(/^default$/,@posstypes)) {
6064: push(@posstypes,'default');
6065: }
6066: my %usertypeshash;
6067: if (ref($usertypes) eq 'HASH') {
6068: %usertypeshash = %{$usertypes};
6069: }
6070: $usertypeshash{'default'} = $othertitle;
6071: foreach my $status (@posstypes) {
6072: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
6073: $numinrow,$$rowtotal,\%usertypeshash);
6074: $$rowtotal ++;
1.224 raeburn 6075: }
6076: } else {
1.236 raeburn 6077: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 6078: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 6079: );
6080: my @toggles = sort(keys(%choices));
6081: my %defaultchecked = (
6082: 'cancreate_email' => 'off',
6083: );
1.305 raeburn 6084: my $customclass = 'LC_selfcreate_email';
6085: my $classprefix = 'LC_canmodify_emailusername_';
6086: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 6087: my $display = 'none';
1.305 raeburn 6088: my $rowstyle = 'display:none';
1.236 raeburn 6089: if (grep(/^\Qemail\E$/,@selfcreate)) {
6090: $display = 'block';
1.305 raeburn 6091: $rowstyle = 'display:table-row';
1.236 raeburn 6092: }
1.305 raeburn 6093: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
6094: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
6095: \%choices,$$rowtotal,$onclick);
6096: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
6097: $rowstyle);
6098: $$rowtotal ++;
6099: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
6100: $rowstyle);
6101: $$rowtotal ++;
6102: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 6103: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 6104: my ($emailrules,$emailruleorder) =
6105: &Apache::lonnet::inst_userrules($dom,'email');
6106: my $primary_id = &Apache::lonnet::domain($dom,'primary');
6107: my $intdom = &Apache::lonnet::internet_dom($primary_id);
6108: if (ref($types) eq 'ARRAY') {
6109: @posstypes = @{$types};
6110: }
6111: if (@posstypes) {
6112: unless (grep(/^default$/,@posstypes)) {
6113: push(@posstypes,'default');
1.302 raeburn 6114: }
6115: if (ref($usertypes) eq 'HASH') {
6116: %usertypeshash = %{$usertypes};
6117: }
1.305 raeburn 6118: my $currassign;
6119: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
6120: $currassign = {
6121: selfassign => $domdefaults{'inststatusguest'},
6122: };
6123: @ordered = @{$domdefaults{'inststatusguest'}};
6124: } else {
6125: $currassign = { selfassign => [] };
6126: }
6127: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
6128: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
6129: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
6130: $numinrow,$othertitle,'selfassign',
6131: $rowtotal,$onclicktypes,$customclass,
6132: $rowstyle);
6133: $$rowtotal ++;
1.302 raeburn 6134: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6135: foreach my $status (@posstypes) {
6136: my $css_class;
6137: if ($$rowtotal%2) {
6138: $css_class = 'LC_odd_row ';
6139: }
6140: $css_class .= $customclass;
6141: my $rowid = $optionsprefix.$status;
6142: my $hidden = 1;
6143: my $currstyle = 'display:none';
6144: if (grep(/^\Q$status\E$/,@ordered)) {
6145: $currstyle = $rowstyle;
6146: $hidden = 0;
6147: }
6148: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6149: $emailrules,$emailruleorder,$settings,$status,$rowid,
6150: $usertypeshash{$status},$css_class,$currstyle,$intdom);
6151: unless ($hidden) {
6152: $$rowtotal ++;
6153: }
1.224 raeburn 6154: }
1.302 raeburn 6155: } else {
1.305 raeburn 6156: my $css_class;
6157: if ($$rowtotal%2) {
6158: $css_class = 'LC_odd_row ';
6159: }
6160: $css_class .= $customclass;
1.302 raeburn 6161: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 6162: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
6163: $emailrules,$emailruleorder,$settings,'default','',
6164: $othertitle,$css_class,$rowstyle,$intdom);
6165: $$rowtotal ++;
1.224 raeburn 6166: }
6167: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 6168: $numinrow = 1;
1.305 raeburn 6169: if (@posstypes) {
6170: foreach my $status (@posstypes) {
6171: my $rowid = $classprefix.$status;
6172: my $datarowstyle = 'display:none';
6173: if (grep(/^\Q$status\E$/,@ordered)) {
6174: $datarowstyle = $rowstyle;
6175: }
6176: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
6177: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6178: $infotitles,$rowid,$customclass,$datarowstyle);
6179: unless ($datarowstyle eq 'display:none') {
6180: $$rowtotal ++;
6181: }
1.224 raeburn 6182: }
1.305 raeburn 6183: } else {
6184: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
6185: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
6186: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 6187: }
6188: }
6189: return $datatable;
6190: }
6191:
1.305 raeburn 6192: sub selfcreate_javascript {
6193: return <<"ENDSCRIPT";
6194:
6195: <script type="text/javascript">
6196: // <![CDATA[
6197:
6198: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6199: var x = document.getElementsByClassName(target);
6200: var insttypes = 0;
6201: var insttypeRegExp = new RegExp(prefix);
6202: if ((x.length != undefined) && (x.length > 0)) {
6203: if (form.elements[radio].length != undefined) {
6204: for (var i=0; i<form.elements[radio].length; i++) {
6205: if (form.elements[radio][i].checked) {
6206: if (form.elements[radio][i].value == 1) {
6207: for (var j=0; j<x.length; j++) {
6208: if (x[j].id == 'undefined') {
6209: x[j].style.display = 'table-row';
6210: } else if (insttypeRegExp.test(x[j].id)) {
6211: insttypes ++;
6212: } else {
6213: x[j].style.display = 'table-row';
6214: }
6215: }
6216: } else {
6217: for (var j=0; j<x.length; j++) {
6218: x[j].style.display = 'none';
6219: }
1.236 raeburn 6220: }
1.305 raeburn 6221: break;
6222: }
6223: }
6224: if (insttypes > 0) {
6225: toggleDataRow(form,checkbox,target,altprefix);
6226: toggleDataRow(form,checkbox,target,prefix,1);
6227: }
6228: }
6229: }
6230: return;
6231: }
6232:
6233: function toggleDataRow(form,checkbox,target,prefix,docount) {
6234: if (form.elements[checkbox].length != undefined) {
6235: var count = 0;
6236: if (docount) {
6237: for (var i=0; i<form.elements[checkbox].length; i++) {
6238: if (form.elements[checkbox][i].checked) {
6239: count ++;
1.236 raeburn 6240: }
1.305 raeburn 6241: }
6242: }
6243: for (var i=0; i<form.elements[checkbox].length; i++) {
6244: var type = form.elements[checkbox][i].value;
6245: if (document.getElementById(prefix+type)) {
6246: if (form.elements[checkbox][i].checked) {
6247: document.getElementById(prefix+type).style.display = 'table-row';
6248: if (count % 2 == 1) {
6249: document.getElementById(prefix+type).className = target+' LC_odd_row';
6250: } else {
6251: document.getElementById(prefix+type).className = target;
1.236 raeburn 6252: }
1.305 raeburn 6253: count ++;
1.236 raeburn 6254: } else {
1.305 raeburn 6255: document.getElementById(prefix+type).style.display = 'none';
6256: }
6257: }
6258: }
6259: }
6260: return;
6261: }
6262:
6263: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
6264: var caller = radio+'_'+status;
6265: if (form.elements[caller].length != undefined) {
6266: for (var i=0; i<form.elements[caller].length; i++) {
6267: if (form.elements[caller][i].checked) {
6268: if (document.getElementById(altprefix+'_inst_'+status)) {
6269: var curr = form.elements[caller][i].value;
6270: if (prefix) {
6271: document.getElementById(prefix+'_'+status).style.display = 'none';
6272: }
6273: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
6274: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
6275: if (curr == 'custom') {
6276: if (prefix) {
6277: document.getElementById(prefix+'_'+status).style.display = 'inline';
6278: }
6279: } else if (curr == 'inst') {
6280: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
6281: } else if (curr == 'noninst') {
6282: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 6283: }
1.305 raeburn 6284: break;
1.236 raeburn 6285: }
6286: }
6287: }
6288: }
6289: }
6290:
1.305 raeburn 6291: // ]]>
6292: </script>
6293:
6294: ENDSCRIPT
6295: }
6296:
6297: sub noninst_users {
6298: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
6299: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
6300: my $class = 'LC_left_item';
6301: if ($css_class) {
6302: $css_class = ' class="'.$css_class.'"';
6303: }
6304: if ($rowid) {
6305: $rowid = ' id="'.$rowid.'"';
6306: }
6307: if ($rowstyle) {
6308: $rowstyle = ' style="'.$rowstyle.'"';
6309: }
6310: my ($output,$description);
6311: if ($type eq 'default') {
6312: $description = &mt('Requests for: [_1]',$typetitle);
6313: } else {
6314: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
6315: }
6316: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
6317: "<td>$description</td>\n".
6318: '<td class="'.$class.'" colspan="2">'.
6319: '<table><tr>';
6320: my %headers = &Apache::lonlocal::texthash(
6321: approve => 'Processing',
6322: email => 'E-mail',
6323: username => 'Username',
6324: );
6325: foreach my $item ('approve','email','username') {
6326: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 6327: }
1.305 raeburn 6328: $output .= '</tr><tr>';
6329: foreach my $item ('approve','email','username') {
1.306 raeburn 6330: $output .= '<td style="vertical-align: top">';
1.305 raeburn 6331: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
6332: if ($item eq 'approve') {
6333: %choices = &Apache::lonlocal::texthash (
6334: automatic => 'Automatically approved',
6335: approval => 'Queued for approval',
6336: );
6337: @options = ('automatic','approval');
6338: $hashref = $processing;
6339: $defoption = 'automatic';
6340: $name = 'cancreate_emailprocess_'.$type;
6341: } elsif ($item eq 'email') {
6342: %choices = &Apache::lonlocal::texthash (
6343: any => 'Any e-mail',
6344: inst => 'Institutional only',
6345: noninst => 'Non-institutional only',
6346: custom => 'Custom restrictions',
6347: );
6348: @options = ('any','inst','noninst');
6349: my $showcustom;
6350: if (ref($emailrules) eq 'HASH') {
6351: if (keys(%{$emailrules}) > 0) {
6352: push(@options,'custom');
6353: $showcustom = 'cancreate_emailrule';
6354: if (ref($settings) eq 'HASH') {
6355: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
6356: foreach my $rule (@{$settings->{'email_rule'}}) {
6357: if (exists($emailrules->{$rule})) {
6358: $hascustom ++;
6359: }
6360: }
6361: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
6362: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
6363: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
6364: if (exists($emailrules->{$rule})) {
6365: $hascustom ++;
6366: }
6367: }
6368: }
6369: }
6370: }
6371: }
6372: }
6373: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
6374: "'cancreate_emaildomain','$type'".');"';
6375: $hashref = $emailoptions;
6376: $defoption = 'any';
6377: $name = 'cancreate_emailoptions_'.$type;
6378: } elsif ($item eq 'username') {
6379: %choices = &Apache::lonlocal::texthash (
6380: all => 'Same as e-mail',
6381: first => 'Omit @domain',
6382: free => 'Free to choose',
6383: );
6384: @options = ('all','first','free');
6385: $hashref = $emailverified;
6386: $defoption = 'all';
6387: $name = 'cancreate_usernameoptions_'.$type;
6388: }
6389: foreach my $option (@options) {
6390: my $checked;
6391: if (ref($hashref) eq 'HASH') {
6392: if ($type eq '') {
6393: if (!exists($hashref->{'default'})) {
6394: if ($option eq $defoption) {
6395: $checked = ' checked="checked"';
6396: }
6397: } else {
6398: if ($hashref->{'default'} eq $option) {
6399: $checked = ' checked="checked"';
6400: }
1.303 raeburn 6401: }
6402: } else {
1.305 raeburn 6403: if (!exists($hashref->{$type})) {
6404: if ($option eq $defoption) {
6405: $checked = ' checked="checked"';
6406: }
6407: } else {
6408: if ($hashref->{$type} eq $option) {
6409: $checked = ' checked="checked"';
6410: }
1.303 raeburn 6411: }
6412: }
1.305 raeburn 6413: } elsif (($item eq 'email') && ($hascustom)) {
6414: if ($option eq 'custom') {
6415: $checked = ' checked="checked"';
6416: }
6417: } elsif ($option eq $defoption) {
6418: $checked = ' checked="checked"';
6419: }
6420: $output .= '<span class="LC_nobreak"><label>'.
6421: '<input type="radio" name="'.$name.'"'.
6422: $checked.' value="'.$option.'"'.$onclick.' />'.
6423: $choices{$option}.'</label></span><br />';
6424: if ($item eq 'email') {
6425: if ($option eq 'custom') {
6426: my $id = 'cancreate_emailrule_'.$type;
6427: my $display = 'none';
6428: if ($checked) {
6429: $display = 'inline';
1.303 raeburn 6430: }
1.305 raeburn 6431: my $numinrow = 2;
6432: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
6433: '<legend>'.&mt('Disallow').'</legend><table>'.
6434: &user_formats_row('email',$settings,$emailrules,
6435: $emailruleorder,$numinrow,'',$type);
6436: '</table></fieldset>';
6437: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
6438: my %text = &Apache::lonlocal::texthash (
6439: inst => 'must end:',
6440: noninst => 'cannot end:',
6441: );
6442: my $value;
6443: if (ref($emaildomain) eq 'HASH') {
6444: if (ref($emaildomain->{$type}) eq 'HASH') {
6445: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 6446: }
6447: }
1.305 raeburn 6448: if ($value eq '') {
6449: $value = '@'.$intdom;
6450: }
6451: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
6452: my $display = 'none';
6453: if ($checked) {
6454: $display = 'inline';
6455: }
6456: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
6457: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
6458: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
6459: '</div>';
1.303 raeburn 6460: }
6461: }
6462: }
1.305 raeburn 6463: $output .= '</td>'."\n";
1.303 raeburn 6464: }
1.305 raeburn 6465: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 6466: return $output;
6467: }
6468:
1.165 raeburn 6469: sub captcha_choice {
1.305 raeburn 6470: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 6471: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
6472: $vertext,$currver);
1.165 raeburn 6473: my %lt = &captcha_phrases();
6474: $keyentry = 'hidden';
6475: if ($context eq 'cancreate') {
1.224 raeburn 6476: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 6477: } elsif ($context eq 'login') {
6478: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 6479: }
6480: if (ref($settings) eq 'HASH') {
6481: if ($settings->{'captcha'}) {
6482: $checked{$settings->{'captcha'}} = ' checked="checked"';
6483: } else {
6484: $checked{'original'} = ' checked="checked"';
6485: }
6486: if ($settings->{'captcha'} eq 'recaptcha') {
6487: $pubtext = $lt{'pub'};
6488: $privtext = $lt{'priv'};
6489: $keyentry = 'text';
1.269 raeburn 6490: $vertext = $lt{'ver'};
6491: $currver = $settings->{'recaptchaversion'};
6492: if ($currver ne '2') {
6493: $currver = 1;
6494: }
1.165 raeburn 6495: }
6496: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6497: $currpub = $settings->{'recaptchakeys'}{'public'};
6498: $currpriv = $settings->{'recaptchakeys'}{'private'};
6499: }
6500: } else {
6501: $checked{'original'} = ' checked="checked"';
6502: }
1.305 raeburn 6503: my $css_class;
6504: if ($itemcount%2) {
6505: $css_class = 'LC_odd_row';
6506: }
6507: if ($customcss) {
6508: $css_class .= " $customcss";
6509: }
6510: $css_class =~ s/^\s+//;
6511: if ($css_class) {
6512: $css_class = ' class="'.$css_class.'"';
6513: }
6514: if ($rowstyle) {
6515: $css_class .= ' style="'.$rowstyle.'"';
6516: }
1.169 raeburn 6517: my $output = '<tr'.$css_class.'>'.
6518: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 6519: '<table><tr><td>'."\n";
6520: foreach my $option ('original','recaptcha','notused') {
6521: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6522: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6523: $lt{$option}.'</label></span>';
6524: unless ($option eq 'notused') {
6525: $output .= (' 'x2)."\n";
6526: }
6527: }
6528: #
6529: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6530: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 6531: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 6532: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 6533: #
1.165 raeburn 6534: $output .= '</td></tr>'."\n".
1.305 raeburn 6535: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 6536: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6537: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6538: $currpub.'" size="40" /></span><br />'."\n".
6539: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6540: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 6541: $currpriv.'" size="40" /></span><br />'.
6542: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6543: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6544: $currver.'" size="3" /></span><br />'.
6545: '</td></tr></table>'."\n".
1.165 raeburn 6546: '</td></tr>';
6547: return $output;
6548: }
6549:
1.32 raeburn 6550: sub user_formats_row {
1.305 raeburn 6551: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 6552: my $output;
6553: my %text = (
6554: 'username' => 'new usernames',
6555: 'id' => 'IDs',
6556: );
1.305 raeburn 6557: unless ($type eq 'email') {
6558: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6559: $output = '<tr '.$css_class.'>'.
6560: '<td><span class="LC_nobreak">'.
6561: &mt("Format rules to check for $text{$type}: ").
6562: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 6563: }
1.27 raeburn 6564: my $rem;
6565: if (ref($ruleorder) eq 'ARRAY') {
6566: for (my $i=0; $i<@{$ruleorder}; $i++) {
6567: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6568: my $rem = $i%($numinrow);
6569: if ($rem == 0) {
6570: if ($i > 0) {
6571: $output .= '</tr>';
6572: }
6573: $output .= '<tr>';
6574: }
6575: my $check = ' ';
1.39 raeburn 6576: if (ref($settings) eq 'HASH') {
6577: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6578: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6579: $check = ' checked="checked" ';
6580: }
1.305 raeburn 6581: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
6582: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
6583: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
6584: $check = ' checked="checked" ';
6585: }
6586: }
1.27 raeburn 6587: }
6588: }
1.305 raeburn 6589: my $name = $type.'_rule';
6590: if ($type eq 'email') {
6591: $name .= '_'.$status;
6592: }
1.27 raeburn 6593: $output .= '<td class="LC_left_item">'.
6594: '<span class="LC_nobreak"><label>'.
1.311 raeburn 6595: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 6596: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6597: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6598: }
6599: }
6600: $rem = @{$ruleorder}%($numinrow);
6601: }
1.305 raeburn 6602: my $colsleft;
6603: if ($rem) {
6604: $colsleft = $numinrow - $rem;
6605: }
1.27 raeburn 6606: if ($colsleft > 1 ) {
6607: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6608: ' </td>';
6609: } elsif ($colsleft == 1) {
6610: $output .= '<td class="LC_left_item"> </td>';
6611: }
1.305 raeburn 6612: $output .= '</tr></table>';
6613: unless ($type eq 'email') {
6614: $output .= '</td></tr>';
6615: }
1.27 raeburn 6616: return $output;
6617: }
6618:
1.34 raeburn 6619: sub usercreation_types {
6620: my %lt = &Apache::lonlocal::texthash (
6621: author => 'When adding a co-author',
6622: course => 'When adding a user to a course',
1.100 raeburn 6623: requestcrs => 'When requesting a course',
1.34 raeburn 6624: any => 'Any',
6625: official => 'Institutional only ',
6626: unofficial => 'Non-institutional only',
6627: none => 'None',
6628: );
6629: return %lt;
1.48 raeburn 6630: }
1.34 raeburn 6631:
1.224 raeburn 6632: sub selfcreation_types {
6633: my %lt = &Apache::lonlocal::texthash (
6634: selfcreate => 'User creates own account',
6635: any => 'Any',
6636: official => 'Institutional only ',
6637: unofficial => 'Non-institutional only',
6638: email => 'E-mail address',
6639: login => 'Institutional Login',
6640: sso => 'SSO',
6641: );
6642: }
6643:
1.28 raeburn 6644: sub authtype_names {
6645: my %lt = &Apache::lonlocal::texthash(
6646: int => 'Internal',
6647: krb4 => 'Kerberos 4',
6648: krb5 => 'Kerberos 5',
6649: loc => 'Local',
6650: );
6651: return %lt;
6652: }
6653:
6654: sub context_names {
6655: my %context_title = &Apache::lonlocal::texthash(
6656: author => 'Creating users when an Author',
6657: course => 'Creating users when in a course',
6658: domain => 'Creating users when a Domain Coordinator',
6659: );
6660: return %context_title;
6661: }
6662:
1.33 raeburn 6663: sub print_usermodification {
6664: my ($position,$dom,$settings,$rowtotal) = @_;
6665: my $numinrow = 4;
6666: my ($context,$datatable,$rowcount);
6667: if ($position eq 'top') {
6668: $rowcount = 0;
6669: $context = 'author';
6670: foreach my $role ('ca','aa') {
6671: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6672: $numinrow,$rowcount);
6673: $$rowtotal ++;
6674: $rowcount ++;
6675: }
1.230 raeburn 6676: } elsif ($position eq 'bottom') {
1.33 raeburn 6677: $context = 'course';
6678: $rowcount = 0;
6679: foreach my $role ('st','ep','ta','in','cr') {
6680: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6681: $numinrow,$rowcount);
6682: $$rowtotal ++;
6683: $rowcount ++;
6684: }
6685: }
6686: return $datatable;
6687: }
6688:
1.43 raeburn 6689: sub print_defaults {
1.236 raeburn 6690: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6691: my $rownum = 0;
1.294 raeburn 6692: my ($datatable,$css_class,$titles);
6693: unless ($position eq 'bottom') {
6694: $titles = &defaults_titles($dom);
6695: }
1.236 raeburn 6696: if ($position eq 'top') {
6697: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6698: 'datelocale_def','portal_def');
6699: my %defaults;
6700: if (ref($settings) eq 'HASH') {
6701: %defaults = %{$settings};
1.43 raeburn 6702: } else {
1.236 raeburn 6703: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6704: foreach my $item (@items) {
6705: $defaults{$item} = $domdefaults{$item};
6706: }
1.43 raeburn 6707: }
1.236 raeburn 6708: foreach my $item (@items) {
6709: if ($rownum%2) {
6710: $css_class = '';
6711: } else {
6712: $css_class = ' class="LC_odd_row" ';
6713: }
6714: $datatable .= '<tr'.$css_class.'>'.
6715: '<td><span class="LC_nobreak">'.$titles->{$item}.
6716: '</span></td><td class="LC_right_item" colspan="3">';
6717: if ($item eq 'auth_def') {
6718: my @authtypes = ('internal','krb4','krb5','localauth');
6719: my %shortauth = (
6720: internal => 'int',
6721: krb4 => 'krb4',
6722: krb5 => 'krb5',
6723: localauth => 'loc'
6724: );
6725: my %authnames = &authtype_names();
6726: foreach my $auth (@authtypes) {
6727: my $checked = ' ';
6728: if ($defaults{$item} eq $auth) {
6729: $checked = ' checked="checked" ';
6730: }
6731: $datatable .= '<label><input type="radio" name="'.$item.
6732: '" value="'.$auth.'"'.$checked.'/>'.
6733: $authnames{$shortauth{$auth}}.'</label> ';
6734: }
6735: } elsif ($item eq 'timezone_def') {
6736: my $includeempty = 1;
6737: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6738: } elsif ($item eq 'datelocale_def') {
6739: my $includeempty = 1;
6740: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6741: } elsif ($item eq 'lang_def') {
1.263 raeburn 6742: my $includeempty = 1;
6743: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 6744: } else {
6745: my $size;
6746: if ($item eq 'portal_def') {
6747: $size = ' size="25"';
6748: }
6749: $datatable .= '<input type="text" name="'.$item.'" value="'.
6750: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 6751: }
1.236 raeburn 6752: $datatable .= '</td></tr>';
6753: $rownum ++;
6754: }
1.294 raeburn 6755: } elsif ($position eq 'middle') {
6756: my @items = ('intauth_cost','intauth_check','intauth_switch');
6757: my %defaults;
6758: if (ref($settings) eq 'HASH') {
6759: %defaults = %{$settings};
6760: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6761: $defaults{'intauth_cost'} = 10;
6762: }
6763: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6764: $defaults{'intauth_check'} = 0;
6765: }
6766: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6767: $defaults{'intauth_switch'} = 0;
6768: }
6769: } else {
6770: %defaults = (
6771: 'intauth_cost' => 10,
6772: 'intauth_check' => 0,
6773: 'intauth_switch' => 0,
6774: );
6775: }
6776: foreach my $item (@items) {
6777: if ($rownum%2) {
6778: $css_class = '';
6779: } else {
6780: $css_class = ' class="LC_odd_row" ';
6781: }
6782: $datatable .= '<tr'.$css_class.'>'.
6783: '<td><span class="LC_nobreak">'.$titles->{$item}.
6784: '</span></td><td class="LC_left_item" colspan="3">';
6785: if ($item eq 'intauth_switch') {
6786: my @options = (0,1,2);
6787: my %optiondesc = &Apache::lonlocal::texthash (
6788: 0 => 'No',
6789: 1 => 'Yes',
6790: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6791: );
6792: $datatable .= '<table width="100%">';
6793: foreach my $option (@options) {
6794: my $checked = ' ';
6795: if ($defaults{$item} eq $option) {
6796: $checked = ' checked="checked"';
6797: }
6798: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6799: '<label><input type="radio" name="'.$item.
6800: '" value="'.$option.'"'.$checked.' />'.
6801: $optiondesc{$option}.'</label></span></td></tr>';
6802: }
6803: $datatable .= '</table>';
6804: } elsif ($item eq 'intauth_check') {
6805: my @options = (0,1,2);
6806: my %optiondesc = &Apache::lonlocal::texthash (
6807: 0 => 'No',
6808: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6809: 2 => 'Yes, disallow login if stored cost is less than domain default',
6810: );
6811: $datatable .= '<table wisth="100%">';
6812: foreach my $option (@options) {
6813: my $checked = ' ';
6814: my $onclick;
6815: if ($defaults{$item} eq $option) {
6816: $checked = ' checked="checked"';
6817: }
6818: if ($option == 2) {
6819: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6820: }
6821: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6822: '<label><input type="radio" name="'.$item.
6823: '" value="'.$option.'"'.$checked.$onclick.' />'.
6824: $optiondesc{$option}.'</label></span></td></tr>';
6825: }
6826: $datatable .= '</table>';
6827: } else {
6828: $datatable .= '<input type="text" name="'.$item.'" value="'.
6829: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6830: }
6831: $datatable .= '</td></tr>';
6832: $rownum ++;
6833: }
1.236 raeburn 6834: } else {
1.294 raeburn 6835: my %defaults;
1.236 raeburn 6836: if (ref($settings) eq 'HASH') {
1.305 raeburn 6837: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 6838: my $maxnum = @{$settings->{'inststatusorder'}};
6839: for (my $i=0; $i<$maxnum; $i++) {
6840: $css_class = $rownum%2?' class="LC_odd_row"':'';
6841: my $item = $settings->{'inststatusorder'}->[$i];
6842: my $title = $settings->{'inststatustypes'}->{$item};
6843: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6844: $datatable .= '<tr'.$css_class.'>'.
6845: '<td><span class="LC_nobreak">'.
6846: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6847: for (my $k=0; $k<=$maxnum; $k++) {
6848: my $vpos = $k+1;
6849: my $selstr;
6850: if ($k == $i) {
6851: $selstr = ' selected="selected" ';
6852: }
6853: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6854: }
6855: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6856: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6857: &mt('delete').'</span></td>'.
1.305 raeburn 6858: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 6859: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 6860: '</span></td></tr>';
1.236 raeburn 6861: }
6862: $css_class = $rownum%2?' class="LC_odd_row"':'';
6863: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6864: $datatable .= '<tr '.$css_class.'>'.
6865: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6866: for (my $k=0; $k<=$maxnum; $k++) {
6867: my $vpos = $k+1;
6868: my $selstr;
6869: if ($k == $maxnum) {
6870: $selstr = ' selected="selected" ';
6871: }
6872: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6873: }
6874: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 6875: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 6876: ' '.&mt('(new)').
1.305 raeburn 6877: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 6878: &mt('Name displayed:').
6879: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6880: '</tr>'."\n";
6881: $rownum ++;
1.141 raeburn 6882: }
1.43 raeburn 6883: }
6884: }
6885: $$rowtotal += $rownum;
6886: return $datatable;
6887: }
6888:
1.168 raeburn 6889: sub get_languages_hash {
6890: my %langchoices;
6891: foreach my $id (&Apache::loncommon::languageids()) {
6892: my $code = &Apache::loncommon::supportedlanguagecode($id);
6893: if ($code ne '') {
6894: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6895: }
6896: }
6897: return %langchoices;
6898: }
6899:
1.43 raeburn 6900: sub defaults_titles {
1.141 raeburn 6901: my ($dom) = @_;
1.43 raeburn 6902: my %titles = &Apache::lonlocal::texthash (
6903: 'auth_def' => 'Default authentication type',
6904: 'auth_arg_def' => 'Default authentication argument',
6905: 'lang_def' => 'Default language',
1.54 raeburn 6906: 'timezone_def' => 'Default timezone',
1.68 raeburn 6907: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6908: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 6909: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6910: 'intauth_check' => 'Check bcrypt cost if authenticated',
6911: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6912: );
1.141 raeburn 6913: if ($dom) {
6914: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6915: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6916: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6917: $protocol = 'http' if ($protocol ne 'https');
6918: if ($uint_dom) {
6919: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6920: $uint_dom);
6921: }
6922: }
1.43 raeburn 6923: return (\%titles);
6924: }
6925:
1.46 raeburn 6926: sub print_scantronformat {
6927: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6928: my $itemcount = 1;
1.60 raeburn 6929: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6930: %confhash);
1.46 raeburn 6931: my $switchserver = &check_switchserver($dom,$confname);
6932: my %lt = &Apache::lonlocal::texthash (
1.95 www 6933: default => 'Default bubblesheet format file error',
6934: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6935: );
6936: my %scantronfiles = (
6937: default => 'default.tab',
6938: custom => 'custom.tab',
6939: );
6940: foreach my $key (keys(%scantronfiles)) {
6941: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6942: .$scantronfiles{$key};
6943: }
6944: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6945: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6946: if (!$switchserver) {
6947: my $servadm = $r->dir_config('lonAdmEMail');
6948: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6949: if ($configuserok eq 'ok') {
6950: if ($author_ok eq 'ok') {
6951: my %legacyfile = (
6952: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6953: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6954: );
6955: my %md5chk;
6956: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6957: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6958: chomp($md5chk{$type});
1.46 raeburn 6959: }
6960: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6961: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6962: ($scantronurls{$type},my $error) =
1.46 raeburn 6963: &legacy_scantronformat($r,$dom,$confname,
6964: $type,$legacyfile{$type},
6965: $scantronurls{$type},
6966: $scantronfiles{$type});
1.60 raeburn 6967: if ($error ne '') {
6968: $error{$type} = $error;
6969: }
6970: }
6971: if (keys(%error) == 0) {
6972: $is_custom = 1;
6973: $confhash{'scantron'}{'scantronformat'} =
6974: $scantronurls{'custom'};
6975: my $putresult =
6976: &Apache::lonnet::put_dom('configuration',
6977: \%confhash,$dom);
6978: if ($putresult ne 'ok') {
6979: $error{'custom'} =
6980: '<span class="LC_error">'.
6981: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6982: }
1.46 raeburn 6983: }
6984: } else {
1.60 raeburn 6985: ($scantronurls{'default'},my $error) =
1.46 raeburn 6986: &legacy_scantronformat($r,$dom,$confname,
6987: 'default',$legacyfile{'default'},
6988: $scantronurls{'default'},
6989: $scantronfiles{'default'});
1.60 raeburn 6990: if ($error eq '') {
6991: $confhash{'scantron'}{'scantronformat'} = '';
6992: my $putresult =
6993: &Apache::lonnet::put_dom('configuration',
6994: \%confhash,$dom);
6995: if ($putresult ne 'ok') {
6996: $error{'default'} =
6997: '<span class="LC_error">'.
6998: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6999: }
7000: } else {
7001: $error{'default'} = $error;
7002: }
1.46 raeburn 7003: }
7004: }
7005: }
7006: } else {
1.95 www 7007: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 7008: }
7009: }
7010: if (ref($settings) eq 'HASH') {
7011: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
7012: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
7013: if ((!@info) || ($info[0] eq 'no_such_dir')) {
7014: $scantronurl = '';
7015: } else {
7016: $scantronurl = $settings->{'scantronformat'};
7017: }
7018: $is_custom = 1;
7019: } else {
7020: $scantronurl = $scantronurls{'default'};
7021: }
7022: } else {
1.60 raeburn 7023: if ($is_custom) {
7024: $scantronurl = $scantronurls{'custom'};
7025: } else {
7026: $scantronurl = $scantronurls{'default'};
7027: }
1.46 raeburn 7028: }
7029: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7030: $datatable .= '<tr'.$css_class.'>';
7031: if (!$is_custom) {
1.65 raeburn 7032: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
7033: '<span class="LC_nobreak">';
1.46 raeburn 7034: if ($scantronurl) {
1.199 raeburn 7035: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
7036: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 7037: } else {
7038: $datatable = &mt('File unavailable for display');
7039: }
1.65 raeburn 7040: $datatable .= '</span></td>';
1.60 raeburn 7041: if (keys(%error) == 0) {
1.306 raeburn 7042: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 7043: if (!$switchserver) {
7044: $datatable .= &mt('Upload:').'<br />';
7045: }
7046: } else {
7047: my $errorstr;
7048: foreach my $key (sort(keys(%error))) {
7049: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7050: }
7051: $datatable .= '<td>'.$errorstr;
7052: }
1.46 raeburn 7053: } else {
7054: if (keys(%error) > 0) {
7055: my $errorstr;
7056: foreach my $key (sort(keys(%error))) {
7057: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
7058: }
1.60 raeburn 7059: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 7060: } elsif ($scantronurl) {
1.199 raeburn 7061: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
7062: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 7063: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 7064: $link.
7065: '<label><input type="checkbox" name="scantronformat_del"'.
7066: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 7067: '<td><span class="LC_nobreak"> '.
7068: &mt('Replace:').'</span><br />';
1.46 raeburn 7069: }
7070: }
7071: if (keys(%error) == 0) {
7072: if ($switchserver) {
7073: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
7074: } else {
1.65 raeburn 7075: $datatable .='<span class="LC_nobreak"> '.
7076: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 7077: }
7078: }
7079: $datatable .= '</td></tr>';
7080: $$rowtotal ++;
7081: return $datatable;
7082: }
7083:
7084: sub legacy_scantronformat {
7085: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
7086: my ($url,$error);
7087: my @statinfo = &Apache::lonnet::stat_file($newurl);
7088: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
7089: (my $result,$url) =
7090: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
7091: '','',$newfile);
7092: if ($result ne 'ok') {
1.130 raeburn 7093: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 7094: }
7095: }
7096: return ($url,$error);
7097: }
1.43 raeburn 7098:
1.49 raeburn 7099: sub print_coursecategories {
1.57 raeburn 7100: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
7101: my $datatable;
7102: if ($position eq 'top') {
1.238 raeburn 7103: my (%checked);
7104: my @catitems = ('unauth','auth');
7105: my @cattypes = ('std','domonly','codesrch','none');
7106: $checked{'unauth'} = 'std';
7107: $checked{'auth'} = 'std';
7108: if (ref($settings) eq 'HASH') {
7109: foreach my $type (@cattypes) {
7110: if ($type eq $settings->{'unauth'}) {
7111: $checked{'unauth'} = $type;
7112: }
7113: if ($type eq $settings->{'auth'}) {
7114: $checked{'auth'} = $type;
7115: }
7116: }
7117: }
7118: my %lt = &Apache::lonlocal::texthash (
7119: unauth => 'Catalog type for unauthenticated users',
7120: auth => 'Catalog type for authenticated users',
7121: none => 'No catalog',
7122: std => 'Standard catalog',
7123: domonly => 'Domain-only catalog',
7124: codesrch => "Code search form",
7125: );
7126: my $itemcount = 0;
7127: foreach my $item (@catitems) {
7128: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
7129: $datatable .= '<tr '.$css_class.'>'.
7130: '<td>'.$lt{$item}.'</td>'.
7131: '<td class="LC_right_item"><span class="LC_nobreak">';
7132: foreach my $type (@cattypes) {
7133: my $ischecked;
7134: if ($checked{$item} eq $type) {
7135: $ischecked=' checked="checked"';
7136: }
7137: $datatable .= '<label>'.
7138: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
7139: ' />'.$lt{$type}.'</label> ';
7140: }
7141: $datatable .= '</td></tr>';
7142: $itemcount ++;
7143: }
7144: $$rowtotal += $itemcount;
7145: } elsif ($position eq 'middle') {
1.57 raeburn 7146: my $toggle_cats_crs = ' ';
7147: my $toggle_cats_dom = ' checked="checked" ';
7148: my $can_cat_crs = ' ';
7149: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 7150: my $toggle_catscomm_comm = ' ';
7151: my $toggle_catscomm_dom = ' checked="checked" ';
7152: my $can_catcomm_comm = ' ';
7153: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 7154: my $toggle_catsplace_place = ' ';
7155: my $toggle_catsplace_dom = ' checked="checked" ';
7156: my $can_catplace_place = ' ';
7157: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 7158:
1.57 raeburn 7159: if (ref($settings) eq 'HASH') {
7160: if ($settings->{'togglecats'} eq 'crs') {
7161: $toggle_cats_crs = $toggle_cats_dom;
7162: $toggle_cats_dom = ' ';
7163: }
7164: if ($settings->{'categorize'} eq 'crs') {
7165: $can_cat_crs = $can_cat_dom;
7166: $can_cat_dom = ' ';
7167: }
1.120 raeburn 7168: if ($settings->{'togglecatscomm'} eq 'comm') {
7169: $toggle_catscomm_comm = $toggle_catscomm_dom;
7170: $toggle_catscomm_dom = ' ';
7171: }
7172: if ($settings->{'categorizecomm'} eq 'comm') {
7173: $can_catcomm_comm = $can_catcomm_dom;
7174: $can_catcomm_dom = ' ';
7175: }
1.272 raeburn 7176: if ($settings->{'togglecatsplace'} eq 'place') {
7177: $toggle_catsplace_place = $toggle_catsplace_dom;
7178: $toggle_catsplace_dom = ' ';
7179: }
7180: if ($settings->{'categorizeplace'} eq 'place') {
7181: $can_catplace_place = $can_catplace_dom;
7182: $can_catplace_dom = ' ';
7183: }
1.57 raeburn 7184: }
7185: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 7186: togglecats => 'Show/Hide a course in catalog',
7187: togglecatscomm => 'Show/Hide a community in catalog',
7188: togglecatsplace => 'Show/Hide a placement test in catalog',
7189: categorize => 'Assign a category to a course',
7190: categorizecomm => 'Assign a category to a community',
7191: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 7192: );
7193: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 7194: dom => 'Set in Domain',
7195: crs => 'Set in Course',
7196: comm => 'Set in Community',
7197: place => 'Set in Placement Test',
1.57 raeburn 7198: );
7199: $datatable = '<tr class="LC_odd_row">'.
7200: '<td>'.$title{'togglecats'}.'</td>'.
7201: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7202: '<input type="radio" name="togglecats"'.
7203: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7204: '<label><input type="radio" name="togglecats"'.
7205: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7206: '</tr><tr>'.
7207: '<td>'.$title{'categorize'}.'</td>'.
7208: '<td class="LC_right_item"><span class="LC_nobreak">'.
7209: '<label><input type="radio" name="categorize"'.
7210: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7211: '<label><input type="radio" name="categorize"'.
7212: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 7213: '</tr><tr class="LC_odd_row">'.
7214: '<td>'.$title{'togglecatscomm'}.'</td>'.
7215: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7216: '<input type="radio" name="togglecatscomm"'.
7217: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7218: '<label><input type="radio" name="togglecatscomm"'.
7219: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7220: '</tr><tr>'.
7221: '<td>'.$title{'categorizecomm'}.'</td>'.
7222: '<td class="LC_right_item"><span class="LC_nobreak">'.
7223: '<label><input type="radio" name="categorizecomm"'.
7224: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7225: '<label><input type="radio" name="categorizecomm"'.
7226: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 7227: '</tr><tr>'.
7228: '<td>'.$title{'togglecatsplace'}.'</td>'.
7229: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7230: '<input type="radio" name="togglecatsplace"'.
7231: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7232: '<label><input type="radio" name="togglecatscomm"'.
7233: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
7234: '</tr><tr>'.
7235: '<td>'.$title{'categorizeplace'}.'</td>'.
7236: '<td class="LC_right_item"><span class="LC_nobreak">'.
7237: '<label><input type="radio" name="categorizeplace"'.
7238: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7239: '<label><input type="radio" name="categorizeplace"'.
7240: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 7241: '</tr>';
1.272 raeburn 7242: $$rowtotal += 6;
1.57 raeburn 7243: } else {
7244: my $css_class;
7245: my $itemcount = 1;
7246: my $cathash;
7247: if (ref($settings) eq 'HASH') {
7248: $cathash = $settings->{'cats'};
7249: }
7250: if (ref($cathash) eq 'HASH') {
7251: my (@cats,@trails,%allitems,%idx,@jsarray);
7252: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7253: \%allitems,\%idx,\@jsarray);
7254: my $maxdepth = scalar(@cats);
7255: my $colattrib = '';
7256: if ($maxdepth > 2) {
7257: $colattrib = ' colspan="2" ';
7258: }
7259: my @path;
7260: if (@cats > 0) {
7261: if (ref($cats[0]) eq 'ARRAY') {
7262: my $numtop = @{$cats[0]};
7263: my $maxnum = $numtop;
1.120 raeburn 7264: my %default_names = (
7265: instcode => &mt('Official courses'),
7266: communities => &mt('Communities'),
1.272 raeburn 7267: placement => &mt('Placement Tests'),
1.120 raeburn 7268: );
7269:
7270: if ((!grep(/^instcode$/,@{$cats[0]})) ||
7271: ($cathash->{'instcode::0'} eq '') ||
7272: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 7273: ($cathash->{'communities::0'} eq '') ||
7274: (!grep(/^placement$/,@{$cats[0]})) ||
7275: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 7276: $maxnum ++;
7277: }
7278: my $lastidx;
7279: for (my $i=0; $i<$numtop; $i++) {
7280: my $parent = $cats[0][$i];
7281: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7282: my $item = &escape($parent).'::0';
7283: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
7284: $lastidx = $idx{$item};
7285: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7286: .'<select name="'.$item.'"'.$chgstr.'>';
7287: for (my $k=0; $k<=$maxnum; $k++) {
7288: my $vpos = $k+1;
7289: my $selstr;
7290: if ($k == $i) {
7291: $selstr = ' selected="selected" ';
7292: }
7293: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7294: }
1.214 raeburn 7295: $datatable .= '</select></span></td><td>';
1.272 raeburn 7296: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 7297: $datatable .= '<span class="LC_nobreak">'
7298: .$default_names{$parent}.'</span>';
7299: if ($parent eq 'instcode') {
7300: $datatable .= '<br /><span class="LC_nobreak">('
7301: .&mt('with institutional codes')
7302: .')</span></td><td'.$colattrib.'>';
7303: } else {
7304: $datatable .= '<table><tr><td>';
7305: }
7306: $datatable .= '<span class="LC_nobreak">'
7307: .'<label><input type="radio" name="'
7308: .$parent.'" value="1" checked="checked" />'
7309: .&mt('Display').'</label>';
7310: if ($parent eq 'instcode') {
7311: $datatable .= ' ';
7312: } else {
7313: $datatable .= '</span></td></tr><tr><td>'
7314: .'<span class="LC_nobreak">';
7315: }
7316: $datatable .= '<label><input type="radio" name="'
7317: .$parent.'" value="0" />'
7318: .&mt('Do not display').'</label></span>';
1.272 raeburn 7319: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 7320: $datatable .= '</td></tr></table>';
7321: }
7322: $datatable .= '</td>';
1.57 raeburn 7323: } else {
7324: $datatable .= $parent
1.214 raeburn 7325: .' <span class="LC_nobreak"><label>'
7326: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 7327: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
7328: }
7329: my $depth = 1;
7330: push(@path,$parent);
7331: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
7332: pop(@path);
7333: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
7334: $itemcount ++;
7335: }
1.48 raeburn 7336: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 7337: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
7338: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 7339: for (my $k=0; $k<=$maxnum; $k++) {
7340: my $vpos = $k+1;
7341: my $selstr;
1.57 raeburn 7342: if ($k == $numtop) {
1.48 raeburn 7343: $selstr = ' selected="selected" ';
7344: }
7345: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7346: }
1.59 bisitz 7347: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 7348: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
7349: .'</tr>'."\n";
1.48 raeburn 7350: $itemcount ++;
1.272 raeburn 7351: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7352: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
7353: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7354: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
7355: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
7356: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
7357: for (my $k=0; $k<=$maxnum; $k++) {
7358: my $vpos = $k+1;
7359: my $selstr;
7360: if ($k == $maxnum) {
7361: $selstr = ' selected="selected" ';
7362: }
7363: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 7364: }
1.120 raeburn 7365: $datatable .= '</select></span></td>'.
7366: '<td><span class="LC_nobreak">'.
7367: $default_names{$default}.'</span>';
7368: if ($default eq 'instcode') {
7369: $datatable .= '<br /><span class="LC_nobreak">('
7370: .&mt('with institutional codes').')</span>';
7371: }
7372: $datatable .= '</td>'
7373: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7374: .&mt('Display').'</label> '
7375: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7376: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 7377: }
7378: }
7379: }
1.57 raeburn 7380: } else {
7381: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 7382: }
7383: } else {
1.238 raeburn 7384: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 7385: .&initialize_categories($itemcount);
1.48 raeburn 7386: }
1.57 raeburn 7387: $$rowtotal += $itemcount;
1.48 raeburn 7388: }
7389: return $datatable;
7390: }
7391:
1.69 raeburn 7392: sub print_serverstatuses {
7393: my ($dom,$settings,$rowtotal) = @_;
7394: my $datatable;
7395: my @pages = &serverstatus_pages();
7396: my (%namedaccess,%machineaccess);
7397: foreach my $type (@pages) {
7398: $namedaccess{$type} = '';
7399: $machineaccess{$type}= '';
7400: }
7401: if (ref($settings) eq 'HASH') {
7402: foreach my $type (@pages) {
7403: if (exists($settings->{$type})) {
7404: if (ref($settings->{$type}) eq 'HASH') {
7405: foreach my $key (keys(%{$settings->{$type}})) {
7406: if ($key eq 'namedusers') {
7407: $namedaccess{$type} = $settings->{$type}->{$key};
7408: } elsif ($key eq 'machines') {
7409: $machineaccess{$type} = $settings->{$type}->{$key};
7410: }
7411: }
7412: }
7413: }
7414: }
7415: }
1.81 raeburn 7416: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7417: my $rownum = 0;
7418: my $css_class;
7419: foreach my $type (@pages) {
7420: $rownum ++;
7421: $css_class = $rownum%2?' class="LC_odd_row"':'';
7422: $datatable .= '<tr'.$css_class.'>'.
7423: '<td><span class="LC_nobreak">'.
7424: $titles->{$type}.'</span></td>'.
7425: '<td class="LC_left_item">'.
7426: '<input type="text" name="'.$type.'_namedusers" '.
7427: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
7428: '<td class="LC_right_item">'.
7429: '<span class="LC_nobreak">'.
7430: '<input type="text" name="'.$type.'_machines" '.
7431: 'value="'.$machineaccess{$type}.'" size="10" />'.
7432: '</td></tr>'."\n";
7433: }
7434: $$rowtotal += $rownum;
7435: return $datatable;
7436: }
7437:
7438: sub serverstatus_pages {
7439: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 7440: 'checksums','clusterstatus','certstatus','metadata_keywords',
7441: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
7442: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 7443: }
7444:
1.236 raeburn 7445: sub defaults_javascript {
7446: my ($settings) = @_;
1.294 raeburn 7447: my $intauthcheck = &mt('Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.');
7448: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
7449: &js_escape(\$intauthcheck);
7450: &js_escape(\$intauthcost);
7451: my $intauthjs = <<"ENDSCRIPT";
7452:
7453: function warnIntAuth(field) {
7454: if (field.name == 'intauth_check') {
7455: if (field.value == '2') {
7456: alert('$intauthcheck');
7457: }
7458: }
7459: if (field.name == 'intauth_cost') {
7460: field.value.replace(/\s/g,'');
7461: if (field.value != '') {
7462: var regexdigit=/^\\d+\$/;
7463: if (!regexdigit.test(field.value)) {
7464: alert('$intauthcost');
7465: }
7466: }
7467: }
7468: return;
7469: }
7470:
7471: ENDSCRIPT
7472:
7473: if (ref($settings) ne 'HASH') {
7474: return &Apache::lonhtmlcommon::scripttag($intauthjs);
7475: }
1.236 raeburn 7476: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7477: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
7478: if ($maxnum eq '') {
7479: $maxnum = 0;
7480: }
7481: $maxnum ++;
1.249 raeburn 7482: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 7483: return <<"ENDSCRIPT";
7484: <script type="text/javascript">
7485: // <![CDATA[
7486: function reorderTypes(form,caller) {
7487: var changedVal;
7488: $jstext
7489: var newpos = 'addinststatus_pos';
7490: var current = new Array;
7491: var maxh = $maxnum;
7492: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7493: var oldVal;
7494: if (caller == newpos) {
7495: changedVal = newitemVal;
7496: } else {
7497: var curritem = 'inststatus_pos_'+caller;
7498: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7499: current[newitemVal] = newpos;
7500: }
7501: for (var i=0; i<inststatuses.length; i++) {
7502: if (inststatuses[i] != caller) {
7503: var elementName = 'inststatus_pos_'+inststatuses[i];
7504: if (form.elements[elementName]) {
7505: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7506: current[currVal] = elementName;
7507: }
7508: }
7509: }
7510: for (var j=0; j<maxh; j++) {
7511: if (current[j] == undefined) {
7512: oldVal = j;
7513: }
7514: }
7515: if (oldVal < changedVal) {
7516: for (var k=oldVal+1; k<=changedVal ; k++) {
7517: var elementName = current[k];
7518: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7519: }
7520: } else {
7521: for (var k=changedVal; k<oldVal; k++) {
7522: var elementName = current[k];
7523: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7524: }
7525: }
7526: return;
7527: }
7528:
1.294 raeburn 7529: $intauthjs
7530:
1.236 raeburn 7531: // ]]>
7532: </script>
7533:
7534: ENDSCRIPT
1.294 raeburn 7535: } else {
7536: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 7537: }
7538: }
7539:
1.49 raeburn 7540: sub coursecategories_javascript {
7541: my ($settings) = @_;
1.57 raeburn 7542: my ($output,$jstext,$cathash);
1.49 raeburn 7543: if (ref($settings) eq 'HASH') {
1.57 raeburn 7544: $cathash = $settings->{'cats'};
7545: }
7546: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7547: my (@cats,@jsarray,%idx);
1.57 raeburn 7548: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7549: if (@jsarray > 0) {
7550: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7551: for (my $i=0; $i<@jsarray; $i++) {
7552: if (ref($jsarray[$i]) eq 'ARRAY') {
7553: my $catstr = join('","',@{$jsarray[$i]});
7554: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7555: }
7556: }
7557: }
7558: } else {
7559: $jstext = ' var categories = Array(1);'."\n".
7560: ' categories[0] = Array("instcode_pos");'."\n";
7561: }
1.237 bisitz 7562: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7563: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 7564: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 7565: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7566: &js_escape(\$instcode_reserved);
7567: &js_escape(\$communities_reserved);
1.272 raeburn 7568: &js_escape(\$placement_reserved);
1.265 damieng 7569: &js_escape(\$choose_again);
1.49 raeburn 7570: $output = <<"ENDSCRIPT";
7571: <script type="text/javascript">
1.109 raeburn 7572: // <![CDATA[
1.49 raeburn 7573: function reorderCats(form,parent,item,idx) {
7574: var changedVal;
7575: $jstext
7576: var newpos = 'addcategory_pos';
7577: if (parent == '') {
7578: var has_instcode = 0;
7579: var maxtop = categories[idx].length;
7580: for (var j=0; j<maxtop; j++) {
7581: if (categories[idx][j] == 'instcode::0') {
7582: has_instcode == 1;
7583: }
7584: }
7585: if (has_instcode == 0) {
7586: categories[idx][maxtop] = 'instcode_pos';
7587: }
7588: } else {
7589: newpos += '_'+parent;
7590: }
7591: var maxh = 1 + categories[idx].length;
7592: var current = new Array;
7593: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7594: if (item == newpos) {
7595: changedVal = newitemVal;
7596: } else {
7597: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7598: current[newitemVal] = newpos;
7599: }
7600: for (var i=0; i<categories[idx].length; i++) {
7601: var elementName = categories[idx][i];
7602: if (elementName != item) {
7603: if (form.elements[elementName]) {
7604: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7605: current[currVal] = elementName;
7606: }
7607: }
7608: }
7609: var oldVal;
7610: for (var j=0; j<maxh; j++) {
7611: if (current[j] == undefined) {
7612: oldVal = j;
7613: }
7614: }
7615: if (oldVal < changedVal) {
7616: for (var k=oldVal+1; k<=changedVal ; k++) {
7617: var elementName = current[k];
7618: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7619: }
7620: } else {
7621: for (var k=changedVal; k<oldVal; k++) {
7622: var elementName = current[k];
7623: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7624: }
7625: }
7626: return;
7627: }
1.120 raeburn 7628:
7629: function categoryCheck(form) {
7630: if (form.elements['addcategory_name'].value == 'instcode') {
7631: alert('$instcode_reserved\\n$choose_again');
7632: return false;
7633: }
7634: if (form.elements['addcategory_name'].value == 'communities') {
7635: alert('$communities_reserved\\n$choose_again');
7636: return false;
7637: }
1.272 raeburn 7638: if (form.elements['addcategory_name'].value == 'placement') {
7639: alert('$placement_reserved\\n$choose_again');
7640: return false;
7641: }
1.120 raeburn 7642: return true;
7643: }
7644:
1.109 raeburn 7645: // ]]>
1.49 raeburn 7646: </script>
7647:
7648: ENDSCRIPT
7649: return $output;
7650: }
7651:
1.48 raeburn 7652: sub initialize_categories {
7653: my ($itemcount) = @_;
1.120 raeburn 7654: my ($datatable,$css_class,$chgstr);
7655: my %default_names = (
7656: instcode => 'Official courses (with institutional codes)',
7657: communities => 'Communities',
1.272 raeburn 7658: placement => 'Placement Tests',
1.120 raeburn 7659: );
7660: my $select0 = ' selected="selected"';
7661: my $select1 = '';
1.272 raeburn 7662: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7663: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7664: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 7665: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 7666: $select1 = $select0;
7667: $select0 = '';
7668: }
7669: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7670: .'<select name="'.$default.'_pos">'
7671: .'<option value="0"'.$select0.'>1</option>'
7672: .'<option value="1"'.$select1.'>2</option>'
7673: .'<option value="2">3</option></select> '
7674: .$default_names{$default}
7675: .'</span></td><td><span class="LC_nobreak">'
7676: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7677: .&mt('Display').'</label> <label>'
7678: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7679: .'</label></span></td></tr>';
1.120 raeburn 7680: $itemcount ++;
7681: }
1.48 raeburn 7682: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7683: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7684: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7685: .'<select name="addcategory_pos"'.$chgstr.'>'
7686: .'<option value="0">1</option>'
7687: .'<option value="1">2</option>'
7688: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 7689: .&mt('Add category').'</td><td>'.&mt('Name:')
7690: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
7691: return $datatable;
7692: }
7693:
7694: sub build_category_rows {
1.49 raeburn 7695: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7696: my ($text,$name,$item,$chgstr);
1.48 raeburn 7697: if (ref($cats) eq 'ARRAY') {
7698: my $maxdepth = scalar(@{$cats});
7699: if (ref($cats->[$depth]) eq 'HASH') {
7700: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7701: my $numchildren = @{$cats->[$depth]{$parent}};
7702: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 7703: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7704: my ($idxnum,$parent_name,$parent_item);
7705: my $higher = $depth - 1;
7706: if ($higher == 0) {
7707: $parent_name = &escape($parent).'::'.$higher;
7708: } else {
7709: if (ref($path) eq 'ARRAY') {
7710: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7711: }
7712: }
7713: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7714: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7715: if ($j < $numchildren) {
1.48 raeburn 7716: $name = $cats->[$depth]{$parent}[$j];
7717: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7718: $idxnum = $idx->{$item};
7719: } else {
7720: $name = $parent_name;
7721: $item = $parent_item;
1.48 raeburn 7722: }
1.49 raeburn 7723: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7724: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7725: for (my $i=0; $i<=$numchildren; $i++) {
7726: my $vpos = $i+1;
7727: my $selstr;
7728: if ($j == $i) {
7729: $selstr = ' selected="selected" ';
7730: }
7731: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7732: }
7733: $text .= '</select> ';
7734: if ($j < $numchildren) {
7735: my $deeper = $depth+1;
7736: $text .= $name.' '
7737: .'<label><input type="checkbox" name="deletecategory" value="'
7738: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7739: if(ref($path) eq 'ARRAY') {
7740: push(@{$path},$name);
1.49 raeburn 7741: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7742: pop(@{$path});
7743: }
7744: } else {
1.59 bisitz 7745: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 7746: if ($j == $numchildren) {
7747: $text .= $name;
7748: } else {
7749: $text .= $item;
7750: }
7751: $text .= '" value="" />';
7752: }
7753: $text .= '</td></tr>';
7754: }
7755: $text .= '</table></td>';
7756: } else {
7757: my $higher = $depth-1;
7758: if ($higher == 0) {
7759: $name = &escape($parent).'::'.$higher;
7760: } else {
7761: if (ref($path) eq 'ARRAY') {
7762: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7763: }
7764: }
7765: my $colspan;
7766: if ($parent ne 'instcode') {
7767: $colspan = $maxdepth - $depth - 1;
7768: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7769: }
7770: }
7771: }
7772: }
7773: return $text;
7774: }
7775:
1.33 raeburn 7776: sub modifiable_userdata_row {
1.305 raeburn 7777: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
7778: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 7779: my ($role,$rolename,$statustype);
7780: $role = $item;
1.224 raeburn 7781: if ($context eq 'cancreate') {
1.305 raeburn 7782: if ($item =~ /^(emailusername)_(.+)$/) {
7783: $role = $1;
7784: $statustype = $2;
1.228 raeburn 7785: if (ref($usertypes) eq 'HASH') {
7786: if ($usertypes->{$statustype}) {
7787: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7788: } else {
7789: $rolename = &mt('Data provided by user');
7790: }
7791: }
1.224 raeburn 7792: }
7793: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7794: if (ref($usertypes) eq 'HASH') {
7795: $rolename = $usertypes->{$role};
7796: } else {
7797: $rolename = $role;
7798: }
1.33 raeburn 7799: } else {
1.63 raeburn 7800: if ($role eq 'cr') {
7801: $rolename = &mt('Custom role');
7802: } else {
7803: $rolename = &Apache::lonnet::plaintext($role);
7804: }
1.33 raeburn 7805: }
1.224 raeburn 7806: my (@fields,%fieldtitles);
7807: if (ref($fieldsref) eq 'ARRAY') {
7808: @fields = @{$fieldsref};
7809: } else {
7810: @fields = ('lastname','firstname','middlename','generation',
7811: 'permanentemail','id');
7812: }
7813: if ((ref($titlesref) eq 'HASH')) {
7814: %fieldtitles = %{$titlesref};
7815: } else {
7816: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7817: }
1.33 raeburn 7818: my $output;
1.305 raeburn 7819: my $css_class;
7820: if ($rowcount%2) {
7821: $css_class = 'LC_odd_row';
7822: }
7823: if ($customcss) {
7824: $css_class .= " $customcss";
7825: }
7826: $css_class =~ s/^\s+//;
7827: if ($css_class) {
7828: $css_class = ' class="'.$css_class.'"';
7829: }
7830: if ($rowstyle) {
7831: $css_class .= ' style="'.$rowstyle.'"';
7832: }
7833: if ($rowid) {
7834: $rowid = ' id="'.$rowid.'"';
7835: }
7836: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 7837: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7838: '<td class="LC_left_item" colspan="2"><table>';
7839: my $rem;
7840: my %checks;
7841: if (ref($settings) eq 'HASH') {
7842: if (ref($settings->{$context}) eq 'HASH') {
7843: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 7844: my $hashref = $settings->{$context}->{$role};
7845: if ($role eq 'emailusername') {
7846: if ($statustype) {
7847: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7848: $hashref = $settings->{$context}->{$role}->{$statustype};
7849: if (ref($hashref) eq 'HASH') {
7850: foreach my $field (@fields) {
7851: if ($hashref->{$field}) {
7852: $checks{$field} = $hashref->{$field};
7853: }
7854: }
7855: }
7856: }
7857: }
7858: } else {
7859: if (ref($hashref) eq 'HASH') {
7860: foreach my $field (@fields) {
7861: if ($hashref->{$field}) {
7862: $checks{$field} = ' checked="checked" ';
7863: }
7864: }
1.33 raeburn 7865: }
7866: }
7867: }
7868: }
7869: }
1.305 raeburn 7870:
7871: my $total = scalar(@fields);
7872: for (my $i=0; $i<$total; $i++) {
7873: $rem = $i%($numinrow);
1.33 raeburn 7874: if ($rem == 0) {
7875: if ($i > 0) {
7876: $output .= '</tr>';
7877: }
7878: $output .= '<tr>';
7879: }
7880: my $check = ' ';
1.228 raeburn 7881: unless ($role eq 'emailusername') {
7882: if (exists($checks{$fields[$i]})) {
7883: $check = $checks{$fields[$i]}
7884: } else {
7885: if ($role eq 'st') {
7886: if (ref($settings) ne 'HASH') {
7887: $check = ' checked="checked" ';
7888: }
1.33 raeburn 7889: }
7890: }
7891: }
7892: $output .= '<td class="LC_left_item">'.
1.228 raeburn 7893: '<span class="LC_nobreak">';
7894: if ($role eq 'emailusername') {
7895: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7896: $checks{$fields[$i]} = 'omit';
7897: }
7898: foreach my $option ('required','optional','omit') {
7899: my $checked='';
7900: if ($checks{$fields[$i]} eq $option) {
7901: $checked='checked="checked" ';
7902: }
7903: $output .= '<label>'.
7904: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7905: &mt($option).'</label>'.(' ' x2);
7906: }
7907: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7908: } else {
7909: $output .= '<label>'.
7910: '<input type="checkbox" name="canmodify_'.$role.'" '.
7911: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7912: '</label>';
7913: }
7914: $output .= '</span></td>';
1.33 raeburn 7915: }
1.305 raeburn 7916: $rem = $total%$numinrow;
7917: my $colsleft;
7918: if ($rem) {
7919: $colsleft = $numinrow - $rem;
7920: }
7921: if ($colsleft > 1) {
1.33 raeburn 7922: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7923: ' </td>';
7924: } elsif ($colsleft == 1) {
7925: $output .= '<td class="LC_left_item"> </td>';
7926: }
7927: $output .= '</tr></table></td></tr>';
7928: return $output;
7929: }
1.28 raeburn 7930:
1.93 raeburn 7931: sub insttypes_row {
1.305 raeburn 7932: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
7933: $customcss,$rowstyle) = @_;
1.93 raeburn 7934: my %lt = &Apache::lonlocal::texthash (
7935: cansearch => 'Users allowed to search',
7936: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7937: lockablenames => 'User preference to lock name',
1.305 raeburn 7938: selfassign => 'Self-reportable affiliations',
1.315 ! raeburn 7939: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 7940: );
7941: my $showdom;
7942: if ($context eq 'cansearch') {
7943: $showdom = ' ('.$dom.')';
7944: }
1.165 raeburn 7945: my $class = 'LC_left_item';
7946: if ($context eq 'statustocreate') {
7947: $class = 'LC_right_item';
7948: }
1.305 raeburn 7949: my $css_class;
7950: if ($$rowtotal%2) {
7951: $css_class = 'LC_odd_row';
7952: }
7953: if ($customcss) {
7954: $css_class .= ' '.$customcss;
7955: }
7956: $css_class =~ s/^\s+//;
7957: if ($css_class) {
7958: $css_class = ' class="'.$css_class.'"';
7959: }
7960: if ($rowstyle) {
7961: $css_class .= ' style="'.$rowstyle.'"';
7962: }
7963: if ($onclick) {
7964: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 7965: }
7966: my $output = '<tr'.$css_class.'>'.
7967: '<td>'.$lt{$context}.$showdom.
7968: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7969: my $rem;
7970: if (ref($types) eq 'ARRAY') {
7971: for (my $i=0; $i<@{$types}; $i++) {
7972: if (defined($usertypes->{$types->[$i]})) {
7973: my $rem = $i%($numinrow);
7974: if ($rem == 0) {
7975: if ($i > 0) {
7976: $output .= '</tr>';
7977: }
7978: $output .= '<tr>';
1.23 raeburn 7979: }
1.26 raeburn 7980: my $check = ' ';
1.99 raeburn 7981: if (ref($settings) eq 'HASH') {
7982: if (ref($settings->{$context}) eq 'ARRAY') {
7983: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7984: $check = ' checked="checked" ';
7985: }
1.315 ! raeburn 7986: } elsif (ref($settings->{$context}) eq 'HASH') {
! 7987: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
! 7988: $check = ' checked="checked" ';
! 7989: }
1.99 raeburn 7990: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7991: $check = ' checked="checked" ';
7992: }
1.23 raeburn 7993: }
1.26 raeburn 7994: $output .= '<td class="LC_left_item">'.
7995: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7996: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 7997: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 7998: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7999: }
8000: }
1.26 raeburn 8001: $rem = @{$types}%($numinrow);
1.23 raeburn 8002: }
8003: my $colsleft = $numinrow - $rem;
1.315 ! raeburn 8004: if ($context eq 'overrides') {
! 8005: if ($colsleft > 1) {
! 8006: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
! 8007: } else {
! 8008: $output .= '<td class="LC_left_item">';
! 8009: }
! 8010: $output .= ' ';
1.23 raeburn 8011: } else {
1.315 ! raeburn 8012: if (($rem == 0) && (@{$types} > 0)) {
! 8013: $output .= '<tr>';
! 8014: }
! 8015: if ($colsleft > 1) {
! 8016: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
! 8017: } else {
! 8018: $output .= '<td class="LC_left_item">';
! 8019: }
! 8020: my $defcheck = ' ';
! 8021: if (ref($settings) eq 'HASH') {
! 8022: if (ref($settings->{$context}) eq 'ARRAY') {
! 8023: if (grep(/^default$/,@{$settings->{$context}})) {
! 8024: $defcheck = ' checked="checked" ';
! 8025: }
! 8026: } elsif ($context eq 'statustocreate') {
1.99 raeburn 8027: $defcheck = ' checked="checked" ';
8028: }
1.26 raeburn 8029: }
1.315 ! raeburn 8030: $output .= '<span class="LC_nobreak"><label>'.
! 8031: '<input type="checkbox" name="'.$context.'" '.
! 8032: 'value="default"'.$defcheck.$onclick.' />'.
! 8033: $othertitle.'</label></span>';
1.23 raeburn 8034: }
1.315 ! raeburn 8035: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 8036: return $output;
1.23 raeburn 8037: }
8038:
8039: sub sorted_searchtitles {
8040: my %searchtitles = &Apache::lonlocal::texthash(
8041: 'uname' => 'username',
8042: 'lastname' => 'last name',
8043: 'lastfirst' => 'last name, first name',
8044: );
8045: my @titleorder = ('uname','lastname','lastfirst');
8046: return (\%searchtitles,\@titleorder);
8047: }
8048:
1.25 raeburn 8049: sub sorted_searchtypes {
8050: my %srchtypes_desc = (
8051: exact => 'is exact match',
8052: contains => 'contains ..',
8053: begins => 'begins with ..',
8054: );
8055: my @srchtypeorder = ('exact','begins','contains');
8056: return (\%srchtypes_desc,\@srchtypeorder);
8057: }
8058:
1.3 raeburn 8059: sub usertype_update_row {
8060: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
8061: my $datatable;
8062: my $numinrow = 4;
8063: foreach my $type (@{$types}) {
8064: if (defined($usertypes->{$type})) {
8065: $$rownums ++;
8066: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
8067: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
8068: '</td><td class="LC_left_item"><table>';
8069: for (my $i=0; $i<@{$fields}; $i++) {
8070: my $rem = $i%($numinrow);
8071: if ($rem == 0) {
8072: if ($i > 0) {
8073: $datatable .= '</tr>';
8074: }
8075: $datatable .= '<tr>';
8076: }
8077: my $check = ' ';
1.39 raeburn 8078: if (ref($settings) eq 'HASH') {
8079: if (ref($settings->{'fields'}) eq 'HASH') {
8080: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
8081: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
8082: $check = ' checked="checked" ';
8083: }
1.3 raeburn 8084: }
8085: }
8086: }
8087:
8088: if ($i == @{$fields}-1) {
8089: my $colsleft = $numinrow - $rem;
8090: if ($colsleft > 1) {
8091: $datatable .= '<td colspan="'.$colsleft.'">';
8092: } else {
8093: $datatable .= '<td>';
8094: }
8095: } else {
8096: $datatable .= '<td>';
8097: }
1.8 raeburn 8098: $datatable .= '<span class="LC_nobreak"><label>'.
8099: '<input type="checkbox" name="updateable_'.$type.
8100: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
8101: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 8102: }
8103: $datatable .= '</tr></table></td></tr>';
8104: }
8105: }
8106: return $datatable;
1.1 raeburn 8107: }
8108:
8109: sub modify_login {
1.205 raeburn 8110: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 8111: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
8112: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
8113: %title = ( coursecatalog => 'Display course catalog',
8114: adminmail => 'Display administrator E-mail address',
1.188 raeburn 8115: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 8116: newuser => 'Link for visitors to create a user account',
8117: loginheader => 'Log-in box header');
8118: @offon = ('off','on');
1.112 raeburn 8119: if (ref($domconfig{login}) eq 'HASH') {
8120: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
8121: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
8122: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
8123: }
8124: }
8125: }
1.9 raeburn 8126: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
8127: \%domconfig,\%loginhash);
1.188 raeburn 8128: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8129: foreach my $item (@toggles) {
8130: $loginhash{login}{$item} = $env{'form.'.$item};
8131: }
1.41 raeburn 8132: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 8133: if (ref($colchanges{'login'}) eq 'HASH') {
8134: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
8135: \%loginhash);
8136: }
1.110 raeburn 8137:
1.149 raeburn 8138: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 8139: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 8140: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 8141: if (keys(%servers) > 1) {
8142: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 8143: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
8144: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
8145: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
8146: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
8147: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
8148: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8149: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8150: $changes{'loginvia'}{$lonhost} = 1;
8151: } else {
8152: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
8153: $changes{'loginvia'}{$lonhost} = 1;
8154: }
8155: } else {
8156: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8157: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
8158: $changes{'loginvia'}{$lonhost} = 1;
8159: }
8160: }
8161: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
8162: foreach my $item (@loginvia_attribs) {
8163: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
8164: }
8165: } else {
8166: foreach my $item (@loginvia_attribs) {
8167: my $new = $env{'form.'.$lonhost.'_'.$item};
8168: if (($item eq 'serverpath') && ($new eq 'custom')) {
8169: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
8170: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8171: $new = '/';
8172: }
8173: }
8174: if (($item eq 'custompath') &&
8175: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8176: $new = '';
8177: }
8178: if ($new ne $curr_loginvia{$lonhost}{$item}) {
8179: $changes{'loginvia'}{$lonhost} = 1;
8180: }
8181: if ($item eq 'exempt') {
1.256 raeburn 8182: $new = &check_exempt_addresses($new);
1.128 raeburn 8183: }
8184: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8185: }
8186: }
1.112 raeburn 8187: } else {
1.128 raeburn 8188: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
8189: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 8190: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 8191: foreach my $item (@loginvia_attribs) {
8192: my $new = $env{'form.'.$lonhost.'_'.$item};
8193: if (($item eq 'serverpath') && ($new eq 'custom')) {
8194: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
8195: $new = '/';
8196: }
8197: }
8198: if (($item eq 'custompath') &&
8199: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
8200: $new = '';
8201: }
8202: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8203: }
1.110 raeburn 8204: }
8205: }
8206: }
8207: }
1.119 raeburn 8208:
1.168 raeburn 8209: my $servadm = $r->dir_config('lonAdmEMail');
8210: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8211: if (ref($domconfig{'login'}) eq 'HASH') {
8212: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8213: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8214: if ($lang eq 'nolang') {
8215: push(@currlangs,$lang);
8216: } elsif (defined($langchoices{$lang})) {
8217: push(@currlangs,$lang);
8218: } else {
8219: next;
8220: }
8221: }
8222: }
8223: }
8224: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8225: if (@currlangs > 0) {
8226: foreach my $lang (@currlangs) {
8227: if (grep(/^\Q$lang\E$/,@delurls)) {
8228: $changes{'helpurl'}{$lang} = 1;
8229: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8230: $changes{'helpurl'}{$lang} = 1;
8231: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8232: push(@newlangs,$lang);
8233: } else {
8234: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8235: }
8236: }
8237: }
8238: unless (grep(/^nolang$/,@currlangs)) {
8239: if ($env{'form.loginhelpurl_nolang.filename'}) {
8240: $changes{'helpurl'}{'nolang'} = 1;
8241: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8242: push(@newlangs,'nolang');
8243: }
8244: }
8245: if ($env{'form.loginhelpurl_add_lang'}) {
8246: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8247: ($env{'form.loginhelpurl_add_file.filename'})) {
8248: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8249: $addedfile = $env{'form.loginhelpurl_add_lang'};
8250: }
8251: }
8252: if ((@newlangs > 0) || ($addedfile)) {
8253: my $error;
8254: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8255: if ($configuserok eq 'ok') {
8256: if ($switchserver) {
8257: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8258: } elsif ($author_ok eq 'ok') {
8259: my @allnew = @newlangs;
8260: if ($addedfile ne '') {
8261: push(@allnew,$addedfile);
8262: }
8263: foreach my $lang (@allnew) {
8264: my $formelem = 'loginhelpurl_'.$lang;
8265: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8266: $formelem = 'loginhelpurl_add_file';
8267: }
8268: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8269: "help/$lang",'','',$newfile{$lang});
8270: if ($result eq 'ok') {
8271: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8272: $changes{'helpurl'}{$lang} = 1;
8273: } else {
8274: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8275: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 8276: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 8277: (!grep(/^\Q$lang\E$/,@delurls))) {
8278: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8279: }
8280: }
8281: }
8282: } else {
8283: $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);
8284: }
8285: } else {
8286: $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);
8287: }
8288: if ($error) {
8289: &Apache::lonnet::logthis($error);
8290: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8291: }
8292: }
1.256 raeburn 8293:
8294: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8295: if (ref($domconfig{'login'}) eq 'HASH') {
8296: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8297: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8298: if ($domservers{$lonhost}) {
8299: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8300: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 8301: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 8302: }
8303: }
8304: }
8305: }
8306: }
8307: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8308: foreach my $lonhost (sort(keys(%domservers))) {
8309: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8310: $changes{'headtag'}{$lonhost} = 1;
8311: } else {
8312: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8313: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8314: }
8315: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8316: push(@newhosts,$lonhost);
8317: } elsif ($currheadtagurls{$lonhost}) {
8318: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8319: if ($currexempt{$lonhost}) {
1.289 raeburn 8320: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 8321: $changes{'headtag'}{$lonhost} = 1;
8322: }
8323: } elsif ($possexempt{$lonhost}) {
8324: $changes{'headtag'}{$lonhost} = 1;
8325: }
8326: if ($possexempt{$lonhost}) {
8327: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8328: }
8329: }
8330: }
8331: }
8332: if (@newhosts) {
8333: my $error;
8334: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8335: if ($configuserok eq 'ok') {
8336: if ($switchserver) {
8337: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8338: } elsif ($author_ok eq 'ok') {
8339: foreach my $lonhost (@newhosts) {
8340: my $formelem = 'loginheadtag_'.$lonhost;
8341: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8342: "login/headtag/$lonhost",'','',
8343: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8344: if ($result eq 'ok') {
8345: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8346: $changes{'headtag'}{$lonhost} = 1;
8347: if ($possexempt{$lonhost}) {
8348: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8349: }
8350: } else {
8351: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8352: $newheadtagurls{$lonhost},$result);
8353: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8354: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8355: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8356: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8357: }
8358: }
8359: }
8360: } else {
8361: $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);
8362: }
8363: } else {
8364: $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);
8365: }
8366: if ($error) {
8367: &Apache::lonnet::logthis($error);
8368: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8369: }
8370: }
1.169 raeburn 8371: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 8372:
8373: my $defaulthelpfile = '/adm/loginproblems.html';
8374: my $defaulttext = &mt('Default in use');
8375:
1.1 raeburn 8376: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8377: $dom);
8378: if ($putresult eq 'ok') {
1.188 raeburn 8379: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8380: my %defaultchecked = (
8381: 'coursecatalog' => 'on',
1.188 raeburn 8382: 'helpdesk' => 'on',
1.42 raeburn 8383: 'adminmail' => 'off',
1.43 raeburn 8384: 'newuser' => 'off',
1.42 raeburn 8385: );
1.55 raeburn 8386: if (ref($domconfig{'login'}) eq 'HASH') {
8387: foreach my $item (@toggles) {
8388: if ($defaultchecked{$item} eq 'on') {
8389: if (($domconfig{'login'}{$item} eq '0') &&
8390: ($env{'form.'.$item} eq '1')) {
8391: $changes{$item} = 1;
8392: } elsif (($domconfig{'login'}{$item} eq '' ||
8393: $domconfig{'login'}{$item} eq '1') &&
8394: ($env{'form.'.$item} eq '0')) {
8395: $changes{$item} = 1;
8396: }
8397: } elsif ($defaultchecked{$item} eq 'off') {
8398: if (($domconfig{'login'}{$item} eq '1') &&
8399: ($env{'form.'.$item} eq '0')) {
8400: $changes{$item} = 1;
8401: } elsif (($domconfig{'login'}{$item} eq '' ||
8402: $domconfig{'login'}{$item} eq '0') &&
8403: ($env{'form.'.$item} eq '1')) {
8404: $changes{$item} = 1;
8405: }
1.42 raeburn 8406: }
8407: }
1.41 raeburn 8408: }
1.6 raeburn 8409: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 8410: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8411: if (ref($lastactref) eq 'HASH') {
8412: $lastactref->{'domainconfig'} = 1;
8413: }
1.1 raeburn 8414: $resulttext = &mt('Changes made:').'<ul>';
8415: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 8416: if ($item eq 'loginvia') {
1.112 raeburn 8417: if (ref($changes{$item}) eq 'HASH') {
8418: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8419: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 8420: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
8421: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
8422: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
8423: $protocol = 'http' if ($protocol ne 'https');
8424: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
8425:
8426: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
8427: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
8428: } else {
8429: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
8430: }
8431: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
8432: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
8433: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
8434: }
8435: $resulttext .= '</li>';
8436: } else {
8437: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8438: }
1.112 raeburn 8439: } else {
1.128 raeburn 8440: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 8441: }
8442: }
1.128 raeburn 8443: $resulttext .= '</ul></li>';
1.112 raeburn 8444: }
1.168 raeburn 8445: } elsif ($item eq 'helpurl') {
8446: if (ref($changes{$item}) eq 'HASH') {
8447: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8448: if (grep(/^\Q$lang\E$/,@delurls)) {
8449: my ($chg,$link);
8450: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8451: if ($lang eq 'nolang') {
8452: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8453: } else {
8454: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8455: }
8456: $resulttext .= '<li>'.$chg.'</li>';
8457: } else {
8458: my $chg;
8459: if ($lang eq 'nolang') {
8460: $chg = &mt('custom log-in help file for no preferred language');
8461: } else {
8462: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8463: }
8464: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8465: $loginhash{'login'}{'helpurl'}{$lang}.
8466: '?inhibitmenu=yes',$chg,600,500).
8467: '</li>';
8468: }
8469: }
8470: }
1.256 raeburn 8471: } elsif ($item eq 'headtag') {
8472: if (ref($changes{$item}) eq 'HASH') {
8473: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8474: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8475: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8476: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8477: $resulttext .= '<li><a href="'.
8478: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8479: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8480: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8481: if ($possexempt{$lonhost}) {
8482: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8483: } else {
8484: $resulttext .= &mt('included for any client IP');
8485: }
8486: $resulttext .= '</li>';
8487: }
8488: }
8489: }
1.169 raeburn 8490: } elsif ($item eq 'captcha') {
8491: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 8492: my $chgtxt;
1.169 raeburn 8493: if ($loginhash{'login'}{$item} eq 'notused') {
8494: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
8495: } else {
8496: my %captchas = &captcha_phrases();
8497: if ($captchas{$loginhash{'login'}{$item}}) {
8498: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
8499: } else {
8500: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
8501: }
8502: }
8503: $resulttext .= '<li>'.$chgtxt.'</li>';
8504: }
8505: } elsif ($item eq 'recaptchakeys') {
8506: if (ref($loginhash{'login'}) eq 'HASH') {
8507: my ($privkey,$pubkey);
8508: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
8509: $pubkey = $loginhash{'login'}{$item}{'public'};
8510: $privkey = $loginhash{'login'}{$item}{'private'};
8511: }
8512: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
8513: if (!$pubkey) {
8514: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
8515: } else {
8516: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8517: }
8518: if (!$privkey) {
8519: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
8520: } else {
1.251 raeburn 8521: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 8522: }
8523: $chgtxt .= '</ul>';
8524: $resulttext .= '<li>'.$chgtxt.'</li>';
8525: }
1.269 raeburn 8526: } elsif ($item eq 'recaptchaversion') {
8527: if (ref($loginhash{'login'}) eq 'HASH') {
8528: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 8529: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 8530: '</li>';
8531: }
8532: }
1.41 raeburn 8533: } else {
8534: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
8535: }
1.1 raeburn 8536: }
1.6 raeburn 8537: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 8538: } else {
8539: $resulttext = &mt('No changes made to log-in page settings');
8540: }
8541: } else {
1.11 albertel 8542: $resulttext = '<span class="LC_error">'.
8543: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8544: }
1.6 raeburn 8545: if ($errors) {
1.9 raeburn 8546: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 8547: $errors.'</ul>';
8548: }
8549: return $resulttext;
8550: }
8551:
1.256 raeburn 8552: sub check_exempt_addresses {
8553: my ($iplist) = @_;
8554: $iplist =~ s/^\s+//;
8555: $iplist =~ s/\s+$//;
8556: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8557: my (@okips,$new);
8558: foreach my $ip (@poss_ips) {
8559: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8560: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8561: push(@okips,$ip);
8562: }
8563: }
8564: }
8565: if (@okips > 0) {
8566: $new = join(',',@okips);
8567: } else {
8568: $new = '';
8569: }
8570: return $new;
8571: }
8572:
1.6 raeburn 8573: sub color_font_choices {
8574: my %choices =
8575: &Apache::lonlocal::texthash (
8576: img => "Header",
8577: bgs => "Background colors",
8578: links => "Link colors",
1.55 raeburn 8579: images => "Images",
1.6 raeburn 8580: font => "Font color",
1.201 raeburn 8581: fontmenu => "Font menu",
1.76 raeburn 8582: pgbg => "Page",
1.6 raeburn 8583: tabbg => "Header",
8584: sidebg => "Border",
8585: link => "Link",
8586: alink => "Active link",
8587: vlink => "Visited link",
8588: );
8589: return %choices;
8590: }
8591:
8592: sub modify_rolecolors {
1.205 raeburn 8593: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8594: my ($resulttext,%rolehash);
8595: $rolehash{'rolecolors'} = {};
1.55 raeburn 8596: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8597: if ($domconfig{'rolecolors'} eq '') {
8598: $domconfig{'rolecolors'} = {};
8599: }
8600: }
1.9 raeburn 8601: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8602: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8603: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8604: $dom);
8605: if ($putresult eq 'ok') {
8606: if (keys(%changes) > 0) {
1.41 raeburn 8607: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8608: if (ref($lastactref) eq 'HASH') {
8609: $lastactref->{'domainconfig'} = 1;
8610: }
1.6 raeburn 8611: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8612: $rolehash{'rolecolors'});
8613: } else {
8614: $resulttext = &mt('No changes made to default color schemes');
8615: }
8616: } else {
1.11 albertel 8617: $resulttext = '<span class="LC_error">'.
8618: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8619: }
8620: if ($errors) {
8621: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8622: $errors.'</ul>';
8623: }
8624: return $resulttext;
8625: }
8626:
8627: sub modify_colors {
1.9 raeburn 8628: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8629: my (%changes,%choices);
1.51 raeburn 8630: my @bgs;
1.6 raeburn 8631: my @links = ('link','alink','vlink');
1.41 raeburn 8632: my @logintext;
1.6 raeburn 8633: my @images;
8634: my $servadm = $r->dir_config('lonAdmEMail');
8635: my $errors;
1.200 raeburn 8636: my %defaults;
1.6 raeburn 8637: foreach my $role (@{$roles}) {
8638: if ($role eq 'login') {
1.12 raeburn 8639: %choices = &login_choices();
1.41 raeburn 8640: @logintext = ('textcol','bgcol');
1.12 raeburn 8641: } else {
8642: %choices = &color_font_choices();
8643: }
8644: if ($role eq 'login') {
1.41 raeburn 8645: @images = ('img','logo','domlogo','login');
1.51 raeburn 8646: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8647: } else {
8648: @images = ('img');
1.200 raeburn 8649: @bgs = ('pgbg','tabbg','sidebg');
8650: }
8651: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8652: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8653: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8654: }
8655: if ($role eq 'login') {
8656: foreach my $item (@logintext) {
1.234 raeburn 8657: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8658: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8659: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8660: }
8661: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 8662: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8663: }
8664: }
8665: } else {
1.234 raeburn 8666: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8667: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8668: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8669: }
8670: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 8671: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8672: }
1.6 raeburn 8673: }
1.200 raeburn 8674: foreach my $item (@bgs) {
1.234 raeburn 8675: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8676: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8677: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8678: }
8679: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 8680: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8681: }
8682: }
8683: foreach my $item (@links) {
1.234 raeburn 8684: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8685: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8686: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8687: }
8688: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 8689: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8690: }
1.6 raeburn 8691: }
1.46 raeburn 8692: my ($configuserok,$author_ok,$switchserver) =
8693: &config_check($dom,$confname,$servadm);
1.9 raeburn 8694: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8695: if (ref($domconfig->{$role}) ne 'HASH') {
8696: $domconfig->{$role} = {};
8697: }
1.8 raeburn 8698: foreach my $img (@images) {
1.70 raeburn 8699: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8700: if (defined($env{'form.login_showlogo_'.$img})) {
8701: $confhash->{$role}{'showlogo'}{$img} = 1;
8702: } else {
8703: $confhash->{$role}{'showlogo'}{$img} = 0;
8704: }
8705: }
1.18 albertel 8706: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8707: && !defined($domconfig->{$role}{$img})
8708: && !$env{'form.'.$role.'_del_'.$img}
8709: && $env{'form.'.$role.'_import_'.$img}) {
8710: # import the old configured image from the .tab setting
8711: # if they haven't provided a new one
8712: $domconfig->{$role}{$img} =
8713: $env{'form.'.$role.'_import_'.$img};
8714: }
1.6 raeburn 8715: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8716: my $error;
1.6 raeburn 8717: if ($configuserok eq 'ok') {
1.9 raeburn 8718: if ($switchserver) {
1.12 raeburn 8719: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8720: } else {
8721: if ($author_ok eq 'ok') {
8722: my ($result,$logourl) =
8723: &publishlogo($r,'upload',$role.'_'.$img,
8724: $dom,$confname,$img,$width,$height);
8725: if ($result eq 'ok') {
8726: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8727: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8728: } else {
1.12 raeburn 8729: $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 8730: }
8731: } else {
1.46 raeburn 8732: $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 8733: }
8734: }
8735: } else {
1.46 raeburn 8736: $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 8737: }
8738: if ($error) {
1.8 raeburn 8739: &Apache::lonnet::logthis($error);
1.11 albertel 8740: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8741: }
8742: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8743: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8744: my $error;
8745: if ($configuserok eq 'ok') {
8746: # is confname an author?
8747: if ($switchserver eq '') {
8748: if ($author_ok eq 'ok') {
8749: my ($result,$logourl) =
8750: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8751: $dom,$confname,$img,$width,$height);
8752: if ($result eq 'ok') {
8753: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8754: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8755: }
8756: }
8757: }
8758: }
1.6 raeburn 8759: }
8760: }
8761: }
8762: if (ref($domconfig) eq 'HASH') {
8763: if (ref($domconfig->{$role}) eq 'HASH') {
8764: foreach my $img (@images) {
8765: if ($domconfig->{$role}{$img} ne '') {
8766: if ($env{'form.'.$role.'_del_'.$img}) {
8767: $confhash->{$role}{$img} = '';
1.12 raeburn 8768: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8769: } else {
1.9 raeburn 8770: if ($confhash->{$role}{$img} eq '') {
8771: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8772: }
1.6 raeburn 8773: }
8774: } else {
8775: if ($env{'form.'.$role.'_del_'.$img}) {
8776: $confhash->{$role}{$img} = '';
1.12 raeburn 8777: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8778: }
8779: }
1.70 raeburn 8780: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8781: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8782: if ($confhash->{$role}{'showlogo'}{$img} ne
8783: $domconfig->{$role}{'showlogo'}{$img}) {
8784: $changes{$role}{'showlogo'}{$img} = 1;
8785: }
8786: } else {
8787: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8788: $changes{$role}{'showlogo'}{$img} = 1;
8789: }
8790: }
8791: }
8792: }
1.6 raeburn 8793: if ($domconfig->{$role}{'font'} ne '') {
8794: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8795: $changes{$role}{'font'} = 1;
8796: }
8797: } else {
8798: if ($confhash->{$role}{'font'}) {
8799: $changes{$role}{'font'} = 1;
8800: }
8801: }
1.107 raeburn 8802: if ($role ne 'login') {
8803: if ($domconfig->{$role}{'fontmenu'} ne '') {
8804: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8805: $changes{$role}{'fontmenu'} = 1;
8806: }
8807: } else {
8808: if ($confhash->{$role}{'fontmenu'}) {
8809: $changes{$role}{'fontmenu'} = 1;
8810: }
1.97 tempelho 8811: }
8812: }
1.6 raeburn 8813: foreach my $item (@bgs) {
8814: if ($domconfig->{$role}{$item} ne '') {
8815: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8816: $changes{$role}{'bgs'}{$item} = 1;
8817: }
8818: } else {
8819: if ($confhash->{$role}{$item}) {
8820: $changes{$role}{'bgs'}{$item} = 1;
8821: }
8822: }
8823: }
8824: foreach my $item (@links) {
8825: if ($domconfig->{$role}{$item} ne '') {
8826: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8827: $changes{$role}{'links'}{$item} = 1;
8828: }
8829: } else {
8830: if ($confhash->{$role}{$item}) {
8831: $changes{$role}{'links'}{$item} = 1;
8832: }
8833: }
8834: }
1.41 raeburn 8835: foreach my $item (@logintext) {
8836: if ($domconfig->{$role}{$item} ne '') {
8837: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8838: $changes{$role}{'logintext'}{$item} = 1;
8839: }
8840: } else {
8841: if ($confhash->{$role}{$item}) {
8842: $changes{$role}{'logintext'}{$item} = 1;
8843: }
8844: }
8845: }
1.6 raeburn 8846: } else {
8847: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8848: \@logintext,$confhash,\%changes);
1.6 raeburn 8849: }
8850: } else {
8851: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8852: \@logintext,$confhash,\%changes);
1.6 raeburn 8853: }
8854: }
8855: return ($errors,%changes);
8856: }
8857:
1.46 raeburn 8858: sub config_check {
8859: my ($dom,$confname,$servadm) = @_;
8860: my ($configuserok,$author_ok,$switchserver,%currroles);
8861: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8862: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8863: $confname,$servadm);
8864: if ($configuserok eq 'ok') {
8865: $switchserver = &check_switchserver($dom,$confname);
8866: if ($switchserver eq '') {
8867: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8868: }
8869: }
8870: return ($configuserok,$author_ok,$switchserver);
8871: }
8872:
1.6 raeburn 8873: sub default_change_checker {
1.41 raeburn 8874: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8875: foreach my $item (@{$links}) {
8876: if ($confhash->{$role}{$item}) {
8877: $changes->{$role}{'links'}{$item} = 1;
8878: }
8879: }
8880: foreach my $item (@{$bgs}) {
8881: if ($confhash->{$role}{$item}) {
8882: $changes->{$role}{'bgs'}{$item} = 1;
8883: }
8884: }
1.41 raeburn 8885: foreach my $item (@{$logintext}) {
8886: if ($confhash->{$role}{$item}) {
8887: $changes->{$role}{'logintext'}{$item} = 1;
8888: }
8889: }
1.6 raeburn 8890: foreach my $img (@{$images}) {
8891: if ($env{'form.'.$role.'_del_'.$img}) {
8892: $confhash->{$role}{$img} = '';
1.12 raeburn 8893: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8894: }
1.70 raeburn 8895: if ($role eq 'login') {
8896: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8897: $changes->{$role}{'showlogo'}{$img} = 1;
8898: }
8899: }
1.6 raeburn 8900: }
8901: if ($confhash->{$role}{'font'}) {
8902: $changes->{$role}{'font'} = 1;
8903: }
1.48 raeburn 8904: }
1.6 raeburn 8905:
8906: sub display_colorchgs {
8907: my ($dom,$changes,$roles,$confhash) = @_;
8908: my (%choices,$resulttext);
8909: if (!grep(/^login$/,@{$roles})) {
8910: $resulttext = &mt('Changes made:').'<br />';
8911: }
8912: foreach my $role (@{$roles}) {
8913: if ($role eq 'login') {
8914: %choices = &login_choices();
8915: } else {
8916: %choices = &color_font_choices();
8917: }
8918: if (ref($changes->{$role}) eq 'HASH') {
8919: if ($role ne 'login') {
8920: $resulttext .= '<h4>'.&mt($role).'</h4>';
8921: }
8922: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8923: if ($role ne 'login') {
8924: $resulttext .= '<ul>';
8925: }
8926: if (ref($changes->{$role}{$key}) eq 'HASH') {
8927: if ($role ne 'login') {
8928: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8929: }
8930: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8931: if (($role eq 'login') && ($key eq 'showlogo')) {
8932: if ($confhash->{$role}{$key}{$item}) {
8933: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8934: } else {
8935: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8936: }
8937: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8938: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8939: } else {
1.12 raeburn 8940: my $newitem = $confhash->{$role}{$item};
8941: if ($key eq 'images') {
1.306 raeburn 8942: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 8943: }
8944: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8945: }
8946: }
8947: if ($role ne 'login') {
8948: $resulttext .= '</ul></li>';
8949: }
8950: } else {
8951: if ($confhash->{$role}{$key} eq '') {
8952: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8953: } else {
8954: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8955: }
8956: }
8957: if ($role ne 'login') {
8958: $resulttext .= '</ul>';
8959: }
8960: }
8961: }
8962: }
1.3 raeburn 8963: return $resulttext;
1.1 raeburn 8964: }
8965:
1.9 raeburn 8966: sub thumb_dimensions {
8967: return ('200','50');
8968: }
8969:
1.16 raeburn 8970: sub check_dimensions {
8971: my ($inputfile) = @_;
8972: my ($fullwidth,$fullheight);
8973: if ($inputfile =~ m|^[/\w.\-]+$|) {
8974: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8975: my $imageinfo = <PIPE>;
8976: if (!close(PIPE)) {
8977: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8978: }
8979: chomp($imageinfo);
8980: my ($fullsize) =
1.21 raeburn 8981: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8982: if ($fullsize) {
8983: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8984: }
8985: }
8986: }
8987: return ($fullwidth,$fullheight);
8988: }
8989:
1.9 raeburn 8990: sub check_configuser {
8991: my ($uhome,$dom,$confname,$servadm) = @_;
8992: my ($configuserok,%currroles);
8993: if ($uhome eq 'no_host') {
8994: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8995: my $configpass = &LONCAPA::Enrollment::create_password();
8996: $configuserok =
8997: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8998: $configpass,'','','','','',undef,$servadm);
8999: } else {
9000: $configuserok = 'ok';
9001: %currroles =
9002: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
9003: }
9004: return ($configuserok,%currroles);
9005: }
9006:
9007: sub check_authorstatus {
9008: my ($dom,$confname,%currroles) = @_;
9009: my $author_ok;
1.40 raeburn 9010: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 9011: my $start = time;
9012: my $end = 0;
9013: $author_ok =
9014: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 9015: 'au',$end,$start,'','','domconfig');
1.9 raeburn 9016: } else {
9017: $author_ok = 'ok';
9018: }
9019: return $author_ok;
9020: }
9021:
9022: sub publishlogo {
1.46 raeburn 9023: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 9024: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 9025: if ($action eq 'upload') {
9026: $fname=$env{'form.'.$formname.'.filename'};
9027: chop($env{'form.'.$formname});
9028: } else {
9029: ($fname) = ($formname =~ /([^\/]+)$/);
9030: }
1.46 raeburn 9031: if ($savefileas ne '') {
9032: $fname = $savefileas;
9033: }
1.9 raeburn 9034: $fname=&Apache::lonnet::clean_filename($fname);
9035: # See if there is anything left
9036: unless ($fname) { return ('error: no uploaded file'); }
9037: $fname="$subdir/$fname";
1.210 raeburn 9038: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 9039: my $filepath="$docroot/priv";
9040: my $relpath = "$dom/$confname";
1.9 raeburn 9041: my ($fnamepath,$file,$fetchthumb);
9042: $file=$fname;
9043: if ($fname=~m|/|) {
9044: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
9045: }
1.164 raeburn 9046: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 9047: my $count;
1.164 raeburn 9048: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 9049: $filepath.="/$parts[$count]";
9050: if ((-e $filepath)!=1) {
9051: mkdir($filepath,02770);
9052: }
9053: }
9054: # Check for bad extension and disallow upload
9055: if ($file=~/\.(\w+)$/ &&
9056: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
9057: $output =
1.207 bisitz 9058: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 9059: } elsif ($file=~/\.(\w+)$/ &&
9060: !defined(&Apache::loncommon::fileembstyle($1))) {
9061: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
9062: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 9063: $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 9064: } elsif (-d "$filepath/$file") {
1.195 bisitz 9065: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 9066: } else {
9067: my $source = $filepath.'/'.$file;
9068: my $logfile;
9069: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 9070: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 9071: }
9072: print $logfile
9073: "\n================= Publish ".localtime()." ================\n".
9074: $env{'user.name'}.':'.$env{'user.domain'}."\n";
9075: # Save the file
9076: if (!open(FH,'>'.$source)) {
9077: &Apache::lonnet::logthis('Failed to create '.$source);
9078: return (&mt('Failed to create file'));
9079: }
9080: if ($action eq 'upload') {
9081: if (!print FH ($env{'form.'.$formname})) {
9082: &Apache::lonnet::logthis('Failed to write to '.$source);
9083: return (&mt('Failed to write file'));
9084: }
9085: } else {
9086: my $original = &Apache::lonnet::filelocation('',$formname);
9087: if(!copy($original,$source)) {
9088: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
9089: return (&mt('Failed to write file'));
9090: }
9091: }
9092: close(FH);
9093: chmod(0660, $source); # Permissions to rw-rw---.
9094:
9095: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
9096: my $copyfile=$targetdir.'/'.$file;
9097:
9098: my @parts=split(/\//,$targetdir);
9099: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
9100: for (my $count=5;$count<=$#parts;$count++) {
9101: $path.="/$parts[$count]";
9102: if (!-e $path) {
9103: print $logfile "\nCreating directory ".$path;
9104: mkdir($path,02770);
9105: }
9106: }
9107: my $versionresult;
9108: if (-e $copyfile) {
9109: $versionresult = &logo_versioning($targetdir,$file,$logfile);
9110: } else {
9111: $versionresult = 'ok';
9112: }
9113: if ($versionresult eq 'ok') {
9114: if (copy($source,$copyfile)) {
9115: print $logfile "\nCopied original source to ".$copyfile."\n";
9116: $output = 'ok';
9117: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 9118: push(@{$modified_urls},[$copyfile,$source]);
9119: my $metaoutput =
9120: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
9121: unless ($registered_cleanup) {
9122: my $handlers = $r->get_handlers('PerlCleanupHandler');
9123: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9124: $registered_cleanup=1;
9125: }
1.9 raeburn 9126: } else {
9127: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
9128: $output = &mt('Failed to copy file to RES space').", $!";
9129: }
9130: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
9131: my $inputfile = $filepath.'/'.$file;
9132: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 9133: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
9134: if ($fullwidth ne '' && $fullheight ne '') {
9135: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
9136: my $thumbsize = $thumbwidth.'x'.$thumbheight;
9137: system("convert -sample $thumbsize $inputfile $outfile");
9138: chmod(0660, $filepath.'/tn-'.$file);
9139: if (-e $outfile) {
9140: my $copyfile=$targetdir.'/tn-'.$file;
9141: if (copy($outfile,$copyfile)) {
9142: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 9143: my $thumb_metaoutput =
9144: &write_metadata($dom,$confname,$formname,
9145: $targetdir,'tn-'.$file,$logfile);
9146: push(@{$modified_urls},[$copyfile,$outfile]);
9147: unless ($registered_cleanup) {
9148: my $handlers = $r->get_handlers('PerlCleanupHandler');
9149: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
9150: $registered_cleanup=1;
9151: }
1.267 raeburn 9152: $madethumb = 1;
1.16 raeburn 9153: } else {
9154: print $logfile "\nUnable to write ".$copyfile.
9155: ':'.$!."\n";
9156: }
9157: }
1.9 raeburn 9158: }
9159: }
9160: }
9161: } else {
9162: $output = $versionresult;
9163: }
9164: }
1.267 raeburn 9165: return ($output,$logourl,$madethumb);
1.9 raeburn 9166: }
9167:
9168: sub logo_versioning {
9169: my ($targetdir,$file,$logfile) = @_;
9170: my $target = $targetdir.'/'.$file;
9171: my ($maxversion,$fn,$extn,$output);
9172: $maxversion = 0;
9173: if ($file =~ /^(.+)\.(\w+)$/) {
9174: $fn=$1;
9175: $extn=$2;
9176: }
9177: opendir(DIR,$targetdir);
9178: while (my $filename=readdir(DIR)) {
9179: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
9180: $maxversion=($1>$maxversion)?$1:$maxversion;
9181: }
9182: }
9183: $maxversion++;
9184: print $logfile "\nCreating old version ".$maxversion."\n";
9185: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
9186: if (copy($target,$copyfile)) {
9187: print $logfile "Copied old target to ".$copyfile."\n";
9188: $copyfile=$copyfile.'.meta';
9189: if (copy($target.'.meta',$copyfile)) {
9190: print $logfile "Copied old target metadata to ".$copyfile."\n";
9191: $output = 'ok';
9192: } else {
9193: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
9194: $output = &mt('Failed to copy old meta').", $!, ";
9195: }
9196: } else {
9197: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
9198: $output = &mt('Failed to copy old target').", $!, ";
9199: }
9200: return $output;
9201: }
9202:
9203: sub write_metadata {
9204: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9205: my (%metadatafields,%metadatakeys,$output);
9206: $metadatafields{'title'}=$formname;
9207: $metadatafields{'creationdate'}=time;
9208: $metadatafields{'lastrevisiondate'}=time;
9209: $metadatafields{'copyright'}='public';
9210: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9211: $env{'user.domain'};
9212: $metadatafields{'authorspace'}=$confname.':'.$dom;
9213: $metadatafields{'domain'}=$dom;
9214: {
9215: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9216: my $mfh;
1.155 raeburn 9217: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 9218: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 9219: unless ($_=~/\./) {
9220: my $unikey=$_;
9221: $unikey=~/^([A-Za-z]+)/;
9222: my $tag=$1;
9223: $tag=~tr/A-Z/a-z/;
9224: print $mfh "\n\<$tag";
9225: foreach (split(/\,/,$metadatakeys{$unikey})) {
9226: my $value=$metadatafields{$unikey.'.'.$_};
9227: $value=~s/\"/\'\'/g;
9228: print $mfh ' '.$_.'="'.$value.'"';
9229: }
9230: print $mfh '>'.
9231: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9232: .'</'.$tag.'>';
9233: }
9234: }
9235: $output = 'ok';
9236: print $logfile "\nWrote metadata";
9237: close($mfh);
9238: } else {
9239: print $logfile "\nFailed to open metadata file";
1.9 raeburn 9240: $output = &mt('Could not write metadata');
9241: }
9242: }
1.155 raeburn 9243: return $output;
9244: }
9245:
9246: sub notifysubscribed {
9247: foreach my $targetsource (@{$modified_urls}){
9248: next unless (ref($targetsource) eq 'ARRAY');
9249: my ($target,$source)=@{$targetsource};
9250: if ($source ne '') {
9251: if (open(my $logfh,'>>'.$source.'.log')) {
9252: print $logfh "\nCleanup phase: Notifications\n";
9253: my @subscribed=&subscribed_hosts($target);
9254: foreach my $subhost (@subscribed) {
9255: print $logfh "\nNotifying host ".$subhost.':';
9256: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9257: print $logfh $reply;
9258: }
9259: my @subscribedmeta=&subscribed_hosts("$target.meta");
9260: foreach my $subhost (@subscribedmeta) {
9261: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9262: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9263: $subhost);
9264: print $logfh $reply;
9265: }
9266: print $logfh "\n============ Done ============\n";
1.160 raeburn 9267: close($logfh);
1.155 raeburn 9268: }
9269: }
9270: }
9271: return OK;
9272: }
9273:
9274: sub subscribed_hosts {
9275: my ($target) = @_;
9276: my @subscribed;
9277: if (open(my $fh,"<$target.subscription")) {
9278: while (my $subline=<$fh>) {
9279: if ($subline =~ /^($match_lonid):/) {
9280: my $host = $1;
9281: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9282: unless (grep(/^\Q$host\E$/,@subscribed)) {
9283: push(@subscribed,$host);
9284: }
9285: }
9286: }
9287: }
9288: }
9289: return @subscribed;
1.9 raeburn 9290: }
9291:
9292: sub check_switchserver {
9293: my ($dom,$confname) = @_;
9294: my ($allowed,$switchserver);
9295: my $home = &Apache::lonnet::homeserver($confname,$dom);
9296: if ($home eq 'no_host') {
9297: $home = &Apache::lonnet::domain($dom,'primary');
9298: }
9299: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 9300: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9301: if (!$allowed) {
1.180 raeburn 9302: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 9303: }
9304: return $switchserver;
9305: }
9306:
1.1 raeburn 9307: sub modify_quotas {
1.216 raeburn 9308: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 9309: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 9310: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 9311: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9312: $validationfieldsref);
1.86 raeburn 9313: if ($action eq 'quotas') {
9314: $context = 'tools';
1.163 raeburn 9315: } else {
1.86 raeburn 9316: $context = $action;
9317: }
9318: if ($context eq 'requestcourses') {
1.271 raeburn 9319: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 9320: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 9321: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9322: %titles = &courserequest_titles();
9323: $toolregexp = join('|',@usertools);
9324: %conditions = &courserequest_conditions();
1.216 raeburn 9325: $confname = $dom.'-domainconfig';
9326: my $servadm = $r->dir_config('lonAdmEMail');
9327: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 9328: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9329: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 9330: } elsif ($context eq 'requestauthor') {
9331: @usertools = ('author');
9332: %titles = &authorrequest_titles();
1.86 raeburn 9333: } else {
1.162 raeburn 9334: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 9335: %titles = &tool_titles();
1.86 raeburn 9336: }
1.212 raeburn 9337: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 9338: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9339: foreach my $key (keys(%env)) {
1.101 raeburn 9340: if ($context eq 'requestcourses') {
9341: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9342: my $item = $1;
9343: my $type = $2;
9344: if ($type =~ /^limit_(.+)/) {
9345: $limithash{$item}{$1} = $env{$key};
9346: } else {
9347: $confhash{$item}{$type} = $env{$key};
9348: }
9349: }
1.163 raeburn 9350: } elsif ($context eq 'requestauthor') {
9351: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9352: $confhash{$1} = $env{$key};
9353: }
1.101 raeburn 9354: } else {
1.86 raeburn 9355: if ($key =~ /^form\.quota_(.+)$/) {
9356: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 9357: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9358: $confhash{'authorquota'}{$1} = $env{$key};
9359: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 9360: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9361: }
1.72 raeburn 9362: }
9363: }
1.163 raeburn 9364: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 9365: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 9366: @approvalnotify = sort(@approvalnotify);
9367: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 9368: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 9369: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9370: foreach my $type (@hasuniquecode) {
9371: if (grep(/^\Q$type\E$/,@crstypes)) {
9372: $confhash{'uniquecode'}{$type} = 1;
9373: }
1.216 raeburn 9374: }
1.242 raeburn 9375: my (%newbook,%allpos);
1.216 raeburn 9376: if ($context eq 'requestcourses') {
1.242 raeburn 9377: foreach my $type ('textbooks','templates') {
9378: @{$allpos{$type}} = ();
9379: my $invalid;
9380: if ($type eq 'textbooks') {
9381: $invalid = &mt('Invalid LON-CAPA course for textbook');
9382: } else {
9383: $invalid = &mt('Invalid LON-CAPA course for template');
9384: }
9385: if ($env{'form.'.$type.'_addbook'}) {
9386: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9387: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9388: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9389: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9390: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9391: } else {
9392: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9393: my $position = $env{'form.'.$type.'_addbook_pos'};
9394: $position =~ s/\D+//g;
9395: if ($position ne '') {
9396: $allpos{$type}[$position] = $newbook{$type};
9397: }
1.216 raeburn 9398: }
1.242 raeburn 9399: } else {
9400: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 9401: }
9402: }
1.242 raeburn 9403: }
1.216 raeburn 9404: }
1.102 raeburn 9405: if (ref($domconfig{$action}) eq 'HASH') {
9406: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9407: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9408: $changes{'notify'}{'approval'} = 1;
9409: }
9410: } else {
1.144 raeburn 9411: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9412: $changes{'notify'}{'approval'} = 1;
9413: }
9414: }
1.218 raeburn 9415: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9416: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9417: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9418: unless ($confhash{'uniquecode'}{$crstype}) {
9419: $changes{'uniquecode'} = 1;
9420: }
9421: }
9422: unless ($changes{'uniquecode'}) {
9423: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
9424: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
9425: $changes{'uniquecode'} = 1;
9426: }
9427: }
9428: }
9429: } else {
9430: $changes{'uniquecode'} = 1;
9431: }
9432: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
9433: $changes{'uniquecode'} = 1;
1.216 raeburn 9434: }
9435: if ($context eq 'requestcourses') {
1.242 raeburn 9436: foreach my $type ('textbooks','templates') {
9437: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9438: my %deletions;
9439: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9440: if (@todelete) {
9441: map { $deletions{$_} = 1; } @todelete;
9442: }
9443: my %imgdeletions;
9444: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9445: if (@todeleteimages) {
9446: map { $imgdeletions{$_} = 1; } @todeleteimages;
9447: }
9448: my $maxnum = $env{'form.'.$type.'_maxnum'};
9449: for (my $i=0; $i<=$maxnum; $i++) {
9450: my $itemid = $env{'form.'.$type.'_id_'.$i};
9451: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9452: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9453: if ($deletions{$key}) {
9454: if ($domconfig{$action}{$type}{$key}{'image'}) {
9455: #FIXME need to obsolete item in RES space
9456: }
9457: next;
9458: } else {
9459: my $newpos = $env{'form.'.$itemid};
9460: $newpos =~ s/\D+//g;
1.243 raeburn 9461: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 9462: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 9463: ($type eq 'templates'));
1.242 raeburn 9464: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9465: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9466: $changes{$type}{$key} = 1;
9467: }
9468: }
9469: $allpos{$type}[$newpos] = $key;
9470: }
9471: if ($imgdeletions{$key}) {
9472: $changes{$type}{$key} = 1;
1.216 raeburn 9473: #FIXME need to obsolete item in RES space
1.242 raeburn 9474: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9475: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 9476: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9477: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9478: } else {
9479: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9480: $cdom,$cnum,$type,$configuserok,
9481: $switchserver,$author_ok);
9482: if ($imgurl) {
9483: $confhash{$type}{$key}{'image'} = $imgurl;
9484: $changes{$type}{$key} = 1;
9485: }
9486: if ($error) {
9487: &Apache::lonnet::logthis($error);
9488: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9489: }
9490: }
1.242 raeburn 9491: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
9492: $confhash{$type}{$key}{'image'} =
9493: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 9494: }
9495: }
9496: }
9497: }
9498: }
9499: }
1.102 raeburn 9500: } else {
1.144 raeburn 9501: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9502: $changes{'notify'}{'approval'} = 1;
9503: }
1.218 raeburn 9504: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 9505: $changes{'uniquecode'} = 1;
9506: }
9507: }
9508: if ($context eq 'requestcourses') {
1.242 raeburn 9509: foreach my $type ('textbooks','templates') {
9510: if ($newbook{$type}) {
9511: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 9512: foreach my $item ('subject','title','publisher','author') {
9513: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9514: ($type eq 'template'));
1.242 raeburn 9515: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
9516: if ($env{'form.'.$type.'_addbook_'.$item}) {
9517: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
9518: }
9519: }
9520: if ($type eq 'textbooks') {
9521: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
9522: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 9523: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
9524: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
9525: } else {
9526: my ($imageurl,$error) =
9527: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
9528: $configuserok,$switchserver,$author_ok);
9529: if ($imageurl) {
9530: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
9531: }
9532: if ($error) {
9533: &Apache::lonnet::logthis($error);
9534: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9535: }
1.242 raeburn 9536: }
9537: }
1.216 raeburn 9538: }
9539: }
1.242 raeburn 9540: if (@{$allpos{$type}} > 0) {
9541: my $idx = 0;
9542: foreach my $item (@{$allpos{$type}}) {
9543: if ($item ne '') {
9544: $confhash{$type}{$item}{'order'} = $idx;
9545: if (ref($domconfig{$action}) eq 'HASH') {
9546: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9547: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
9548: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
9549: $changes{$type}{$item} = 1;
9550: }
1.216 raeburn 9551: }
9552: }
9553: }
1.242 raeburn 9554: $idx ++;
1.216 raeburn 9555: }
9556: }
9557: }
9558: }
1.235 raeburn 9559: if (ref($validationitemsref) eq 'ARRAY') {
9560: foreach my $item (@{$validationitemsref}) {
9561: if ($item eq 'fields') {
9562: my @changed;
9563: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9564: if (@{$confhash{'validation'}{$item}} > 0) {
9565: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9566: }
1.266 raeburn 9567: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9568: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9569: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9570: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9571: $domconfig{'requestcourses'}{'validation'}{$item});
9572: } else {
9573: @changed = @{$confhash{'validation'}{$item}};
9574: }
1.235 raeburn 9575: } else {
9576: @changed = @{$confhash{'validation'}{$item}};
9577: }
9578: } else {
9579: @changed = @{$confhash{'validation'}{$item}};
9580: }
9581: if (@changed) {
9582: if ($confhash{'validation'}{$item}) {
9583: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9584: } else {
9585: $changes{'validation'}{$item} = &mt('None');
9586: }
9587: }
9588: } else {
9589: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9590: if ($item eq 'markup') {
9591: if ($env{'form.requestcourses_validation_'.$item}) {
9592: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9593: }
9594: }
1.266 raeburn 9595: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9596: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9597: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9598: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9599: }
9600: } else {
9601: if ($confhash{'validation'}{$item} ne '') {
9602: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9603: }
1.235 raeburn 9604: }
9605: } else {
9606: if ($confhash{'validation'}{$item} ne '') {
9607: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9608: }
9609: }
9610: }
9611: }
9612: }
9613: if ($env{'form.validationdc'}) {
9614: my $newval = $env{'form.validationdc'};
1.285 raeburn 9615: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 9616: if (exists($domcoords{$newval})) {
9617: $confhash{'validation'}{'dc'} = $newval;
9618: }
9619: }
9620: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 9621: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9622: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9623: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9624: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9625: if ($confhash{'validation'}{'dc'} eq '') {
9626: $changes{'validation'}{'dc'} = &mt('None');
9627: } else {
9628: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9629: }
1.235 raeburn 9630: }
1.266 raeburn 9631: } elsif ($confhash{'validation'}{'dc'} ne '') {
9632: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 9633: }
9634: } elsif ($confhash{'validation'}{'dc'} ne '') {
9635: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9636: }
9637: } elsif ($confhash{'validation'}{'dc'} ne '') {
9638: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 9639: }
1.266 raeburn 9640: } else {
9641: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9642: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9643: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9644: $changes{'validation'}{'dc'} = &mt('None');
9645: }
9646: }
1.235 raeburn 9647: }
9648: }
1.102 raeburn 9649: }
9650: } else {
1.86 raeburn 9651: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 9652: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9653: }
1.72 raeburn 9654: foreach my $item (@usertools) {
9655: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9656: my $unset;
1.101 raeburn 9657: if ($context eq 'requestcourses') {
1.104 raeburn 9658: $unset = '0';
9659: if ($type eq '_LC_adv') {
9660: $unset = '';
9661: }
1.101 raeburn 9662: if ($confhash{$item}{$type} eq 'autolimit') {
9663: $confhash{$item}{$type} .= '=';
9664: unless ($limithash{$item}{$type} =~ /\D/) {
9665: $confhash{$item}{$type} .= $limithash{$item}{$type};
9666: }
9667: }
1.163 raeburn 9668: } elsif ($context eq 'requestauthor') {
9669: $unset = '0';
9670: if ($type eq '_LC_adv') {
9671: $unset = '';
9672: }
1.72 raeburn 9673: } else {
1.101 raeburn 9674: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9675: $confhash{$item}{$type} = 1;
9676: } else {
9677: $confhash{$item}{$type} = 0;
9678: }
1.72 raeburn 9679: }
1.86 raeburn 9680: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 9681: if ($action eq 'requestauthor') {
9682: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9683: $changes{$type} = 1;
9684: }
9685: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9686: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9687: $changes{$item}{$type} = 1;
9688: }
9689: } else {
9690: if ($context eq 'requestcourses') {
1.104 raeburn 9691: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9692: $changes{$item}{$type} = 1;
9693: }
9694: } else {
9695: if (!$confhash{$item}{$type}) {
9696: $changes{$item}{$type} = 1;
9697: }
9698: }
9699: }
9700: } else {
9701: if ($context eq 'requestcourses') {
1.104 raeburn 9702: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9703: $changes{$item}{$type} = 1;
9704: }
1.163 raeburn 9705: } elsif ($context eq 'requestauthor') {
9706: if ($confhash{$type} ne $unset) {
9707: $changes{$type} = 1;
9708: }
1.72 raeburn 9709: } else {
9710: if (!$confhash{$item}{$type}) {
9711: $changes{$item}{$type} = 1;
9712: }
9713: }
9714: }
1.1 raeburn 9715: }
9716: }
1.163 raeburn 9717: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9718: if (ref($domconfig{'quotas'}) eq 'HASH') {
9719: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9720: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9721: if (exists($confhash{'defaultquota'}{$key})) {
9722: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9723: $changes{'defaultquota'}{$key} = 1;
9724: }
9725: } else {
9726: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9727: }
9728: }
1.86 raeburn 9729: } else {
9730: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9731: if (exists($confhash{'defaultquota'}{$key})) {
9732: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9733: $changes{'defaultquota'}{$key} = 1;
9734: }
9735: } else {
9736: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9737: }
1.1 raeburn 9738: }
9739: }
1.197 raeburn 9740: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9741: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9742: if (exists($confhash{'authorquota'}{$key})) {
9743: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9744: $changes{'authorquota'}{$key} = 1;
9745: }
9746: } else {
9747: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9748: }
9749: }
9750: }
1.1 raeburn 9751: }
1.86 raeburn 9752: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9753: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9754: if (ref($domconfig{'quotas'}) eq 'HASH') {
9755: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9756: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9757: $changes{'defaultquota'}{$key} = 1;
9758: }
9759: } else {
9760: if (!exists($domconfig{'quotas'}{$key})) {
9761: $changes{'defaultquota'}{$key} = 1;
9762: }
1.72 raeburn 9763: }
9764: } else {
1.86 raeburn 9765: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9766: }
1.1 raeburn 9767: }
9768: }
1.197 raeburn 9769: if (ref($confhash{'authorquota'}) eq 'HASH') {
9770: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9771: if (ref($domconfig{'quotas'}) eq 'HASH') {
9772: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9773: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9774: $changes{'authorquota'}{$key} = 1;
9775: }
9776: } else {
9777: $changes{'authorquota'}{$key} = 1;
9778: }
9779: } else {
9780: $changes{'authorquota'}{$key} = 1;
9781: }
9782: }
9783: }
1.1 raeburn 9784: }
1.72 raeburn 9785:
1.163 raeburn 9786: if ($context eq 'requestauthor') {
9787: $domdefaults{'requestauthor'} = \%confhash;
9788: } else {
9789: foreach my $key (keys(%confhash)) {
1.242 raeburn 9790: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 9791: $domdefaults{$key} = $confhash{$key};
9792: }
1.163 raeburn 9793: }
1.72 raeburn 9794: }
1.163 raeburn 9795:
1.1 raeburn 9796: my %quotahash = (
1.86 raeburn 9797: $action => { %confhash }
1.1 raeburn 9798: );
9799: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9800: $dom);
9801: if ($putresult eq 'ok') {
9802: if (keys(%changes) > 0) {
1.72 raeburn 9803: my $cachetime = 24*60*60;
9804: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9805: if (ref($lastactref) eq 'HASH') {
9806: $lastactref->{'domdefaults'} = 1;
9807: }
1.1 raeburn 9808: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 9809: unless (($context eq 'requestcourses') ||
1.163 raeburn 9810: ($context eq 'requestauthor')) {
1.86 raeburn 9811: if (ref($changes{'defaultquota'}) eq 'HASH') {
9812: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9813: foreach my $type (@{$types},'default') {
9814: if (defined($changes{'defaultquota'}{$type})) {
9815: my $typetitle = $usertypes->{$type};
9816: if ($type eq 'default') {
9817: $typetitle = $othertitle;
9818: }
1.213 raeburn 9819: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9820: }
9821: }
1.86 raeburn 9822: $resulttext .= '</ul></li>';
1.72 raeburn 9823: }
1.197 raeburn 9824: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 9825: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 9826: foreach my $type (@{$types},'default') {
9827: if (defined($changes{'authorquota'}{$type})) {
9828: my $typetitle = $usertypes->{$type};
9829: if ($type eq 'default') {
9830: $typetitle = $othertitle;
9831: }
1.213 raeburn 9832: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 9833: }
9834: }
9835: $resulttext .= '</ul></li>';
9836: }
1.72 raeburn 9837: }
1.80 raeburn 9838: my %newenv;
1.72 raeburn 9839: foreach my $item (@usertools) {
1.163 raeburn 9840: my (%haschgs,%inconf);
9841: if ($context eq 'requestauthor') {
9842: %haschgs = %changes;
1.210 raeburn 9843: %inconf = %confhash;
1.163 raeburn 9844: } else {
9845: if (ref($changes{$item}) eq 'HASH') {
9846: %haschgs = %{$changes{$item}};
9847: }
9848: if (ref($confhash{$item}) eq 'HASH') {
9849: %inconf = %{$confhash{$item}};
9850: }
9851: }
9852: if (keys(%haschgs) > 0) {
1.80 raeburn 9853: my $newacc =
9854: &Apache::lonnet::usertools_access($env{'user.name'},
9855: $env{'user.domain'},
1.86 raeburn 9856: $item,'reload',$context);
1.210 raeburn 9857: if (($context eq 'requestcourses') ||
1.163 raeburn 9858: ($context eq 'requestauthor')) {
1.108 raeburn 9859: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9860: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9861: }
9862: } else {
9863: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9864: $newenv{'environment.availabletools.'.$item} = $newacc;
9865: }
1.80 raeburn 9866: }
1.163 raeburn 9867: unless ($context eq 'requestauthor') {
9868: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9869: }
1.72 raeburn 9870: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 9871: if ($haschgs{$type}) {
1.72 raeburn 9872: my $typetitle = $usertypes->{$type};
9873: if ($type eq 'default') {
9874: $typetitle = $othertitle;
9875: } elsif ($type eq '_LC_adv') {
9876: $typetitle = 'LON-CAPA Advanced Users';
9877: }
1.163 raeburn 9878: if ($inconf{$type}) {
1.101 raeburn 9879: if ($context eq 'requestcourses') {
9880: my $cond;
1.163 raeburn 9881: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9882: if ($1 eq '') {
9883: $cond = &mt('(Automatic processing of any request).');
9884: } else {
9885: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9886: }
9887: } else {
1.163 raeburn 9888: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9889: }
9890: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 9891: } elsif ($context eq 'requestauthor') {
9892: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9893: $titles{$inconf{$type}},$typetitle);
9894:
1.101 raeburn 9895: } else {
9896: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9897: }
1.72 raeburn 9898: } else {
1.104 raeburn 9899: if ($type eq '_LC_adv') {
1.163 raeburn 9900: if ($inconf{$type} eq '0') {
1.104 raeburn 9901: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9902: } else {
9903: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9904: }
9905: } else {
9906: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9907: }
1.72 raeburn 9908: }
9909: }
1.26 raeburn 9910: }
1.163 raeburn 9911: unless ($context eq 'requestauthor') {
9912: $resulttext .= '</ul></li>';
9913: }
1.26 raeburn 9914: }
1.1 raeburn 9915: }
1.163 raeburn 9916: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9917: if (ref($changes{'notify'}) eq 'HASH') {
9918: if ($changes{'notify'}{'approval'}) {
9919: if (ref($confhash{'notify'}) eq 'HASH') {
9920: if ($confhash{'notify'}{'approval'}) {
9921: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9922: } else {
1.163 raeburn 9923: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9924: }
9925: }
9926: }
9927: }
9928: }
1.216 raeburn 9929: if ($action eq 'requestcourses') {
9930: my @offon = ('off','on');
9931: if ($changes{'uniquecode'}) {
1.218 raeburn 9932: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9933: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9934: $resulttext .= '<li>'.
9935: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9936: '</li>';
9937: } else {
9938: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9939: '</li>';
9940: }
1.216 raeburn 9941: }
1.242 raeburn 9942: foreach my $type ('textbooks','templates') {
9943: if (ref($changes{$type}) eq 'HASH') {
9944: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9945: foreach my $key (sort(keys(%{$changes{$type}}))) {
9946: my %coursehash = &Apache::lonnet::coursedescription($key);
9947: my $coursetitle = $coursehash{'description'};
9948: my $position = $confhash{$type}{$key}{'order'} + 1;
9949: $resulttext .= '<li>';
1.243 raeburn 9950: foreach my $item ('subject','title','publisher','author') {
9951: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9952: ($type eq 'templates'));
1.242 raeburn 9953: my $name = $item.':';
9954: $name =~ s/^(\w)/\U$1/;
9955: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9956: }
9957: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9958: if ($type eq 'textbooks') {
9959: if ($confhash{$type}{$key}{'image'}) {
9960: $resulttext .= ' '.&mt('Image: [_1]',
9961: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9962: ' alt="Textbook cover" />').'<br />';
9963: }
9964: }
9965: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 9966: }
1.242 raeburn 9967: $resulttext .= '</ul></li>';
1.216 raeburn 9968: }
9969: }
1.235 raeburn 9970: if (ref($changes{'validation'}) eq 'HASH') {
9971: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9972: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9973: foreach my $item (@{$validationitemsref}) {
9974: if (exists($changes{'validation'}{$item})) {
9975: if ($item eq 'markup') {
9976: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9977: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9978: } else {
9979: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9980: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9981: }
9982: }
9983: }
9984: if (exists($changes{'validation'}{'dc'})) {
9985: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9986: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9987: }
9988: }
9989: }
1.216 raeburn 9990: }
1.1 raeburn 9991: $resulttext .= '</ul>';
1.80 raeburn 9992: if (keys(%newenv)) {
9993: &Apache::lonnet::appenv(\%newenv);
9994: }
1.1 raeburn 9995: } else {
1.86 raeburn 9996: if ($context eq 'requestcourses') {
9997: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 9998: } elsif ($context eq 'requestauthor') {
9999: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 10000: } else {
1.90 weissno 10001: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 10002: }
1.1 raeburn 10003: }
10004: } else {
1.11 albertel 10005: $resulttext = '<span class="LC_error">'.
10006: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10007: }
1.216 raeburn 10008: if ($errors) {
10009: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
10010: '<ul>'.$errors.'</ul></p>';
10011: }
1.3 raeburn 10012: return $resulttext;
1.1 raeburn 10013: }
10014:
1.216 raeburn 10015: sub process_textbook_image {
1.242 raeburn 10016: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 10017: my $filename = $env{'form.'.$caller.'.filename'};
10018: my ($error,$url);
10019: my ($width,$height) = (50,50);
10020: if ($configuserok eq 'ok') {
10021: if ($switchserver) {
10022: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
10023: $switchserver);
10024: } elsif ($author_ok eq 'ok') {
10025: my ($result,$imageurl) =
10026: &publishlogo($r,'upload',$caller,$dom,$confname,
1.312 raeburn 10027: "$type/$cdom/$cnum/cover",$width,$height);
1.216 raeburn 10028: if ($result eq 'ok') {
10029: $url = $imageurl;
10030: } else {
10031: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10032: }
10033: } else {
10034: $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);
10035: }
10036: } else {
10037: $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);
10038: }
10039: return ($url,$error);
10040: }
10041:
1.267 raeburn 10042: sub modify_ltitools {
10043: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
10044: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 10045: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 10046: my $confname = $dom.'-domainconfig';
10047: my $servadm = $r->dir_config('lonAdmEMail');
10048: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10049: my (%posslti,%possfield);
10050: my @courseroles = ('cc','in','ta','ep','st');
10051: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
10052: map { $posslti{$_} = 1; } @ltiroles;
10053: my @allfields = ('fullname','firstname','lastname','email','user','roles');
10054: map { $possfield{$_} = 1; } @allfields;
10055: my %lt = <itools_names();
10056: if ($env{'form.ltitools_add'}) {
10057: my $title = $env{'form.ltitools_add_title'};
10058: $title =~ s/(`)/'/g;
10059: ($newid,my $error) = &get_ltitools_id($dom,$title);
10060: if ($newid) {
10061: my $position = $env{'form.ltitools_add_pos'};
10062: $position =~ s/\D+//g;
10063: if ($position ne '') {
10064: $allpos[$position] = $newid;
10065: }
10066: $changes{$newid} = 1;
10067: foreach my $item ('title','url','key','secret') {
10068: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
10069: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 10070: if (($item eq 'key') || ($item eq 'secret')) {
10071: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10072: } else {
10073: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
10074: }
1.267 raeburn 10075: }
10076: }
10077: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
10078: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
10079: }
10080: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
10081: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
10082: }
1.296 raeburn 10083: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 10084: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
10085: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 10086: if (($item eq 'width') || ($item eq 'height')) {
10087: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
10088: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10089: }
10090: } else {
10091: if ($env{'form.ltitools_add_'.$item} ne '') {
10092: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
10093: }
1.267 raeburn 10094: }
10095: }
10096: if ($env{'form.ltitools_add_target'} eq 'window') {
10097: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 10098: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
10099: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 10100: } else {
10101: $confhash{$newid}{'display'}{'target'} = 'iframe';
10102: }
10103: foreach my $item ('passback','roster') {
10104: if ($env{'form.ltitools_add_'.$item}) {
10105: $confhash{$newid}{$item} = 1;
10106: }
10107: }
10108: if ($env{'form.ltitools_add_image.filename'} ne '') {
10109: my ($imageurl,$error) =
1.307 raeburn 10110: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 10111: $configuserok,$switchserver,$author_ok);
10112: if ($imageurl) {
10113: $confhash{$newid}{'image'} = $imageurl;
10114: }
10115: if ($error) {
10116: &Apache::lonnet::logthis($error);
10117: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10118: }
10119: }
10120: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
10121: foreach my $field (@fields) {
10122: if ($possfield{$field}) {
10123: if ($field eq 'roles') {
10124: foreach my $role (@courseroles) {
10125: my $choice = $env{'form.ltitools_add_roles_'.$role};
10126: if (($choice ne '') && ($posslti{$choice})) {
10127: $confhash{$newid}{'roles'}{$role} = $choice;
10128: if ($role eq 'cc') {
10129: $confhash{$newid}{'roles'}{'co'} = $choice;
10130: }
10131: }
10132: }
10133: } else {
10134: $confhash{$newid}{'fields'}{$field} = 1;
10135: }
10136: }
10137: }
1.273 raeburn 10138: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
10139: foreach my $item (@courseconfig) {
10140: $confhash{$newid}{'crsconf'}{$item} = 1;
10141: }
1.267 raeburn 10142: if ($env{'form.ltitools_add_custom'}) {
10143: my $name = $env{'form.ltitools_add_custom_name'};
10144: my $value = $env{'form.ltitools_add_custom_value'};
10145: $value =~ s/(`)/'/g;
10146: $name =~ s/(`)/'/g;
10147: $confhash{$newid}{'custom'}{$name} = $value;
10148: }
10149: } else {
10150: my $error = &mt('Failed to acquire unique ID for new external tool');
10151: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10152: }
10153: }
10154: if (ref($domconfig{$action}) eq 'HASH') {
10155: my %deletions;
10156: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
10157: if (@todelete) {
10158: map { $deletions{$_} = 1; } @todelete;
10159: }
10160: my %customadds;
10161: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
10162: if (@newcustom) {
10163: map { $customadds{$_} = 1; } @newcustom;
10164: }
10165: my %imgdeletions;
10166: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
10167: if (@todeleteimages) {
10168: map { $imgdeletions{$_} = 1; } @todeleteimages;
10169: }
10170: my $maxnum = $env{'form.ltitools_maxnum'};
10171: for (my $i=0; $i<=$maxnum; $i++) {
10172: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 10173: $itemid =~ s/\D+//g;
1.267 raeburn 10174: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10175: if ($deletions{$itemid}) {
10176: if ($domconfig{$action}{$itemid}{'image'}) {
10177: #FIXME need to obsolete item in RES space
10178: }
10179: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
10180: next;
10181: } else {
10182: my $newpos = $env{'form.ltitools_'.$itemid};
10183: $newpos =~ s/\D+//g;
1.297 raeburn 10184: foreach my $item ('title','url') {
1.267 raeburn 10185: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10186: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
10187: $changes{$itemid} = 1;
10188: }
10189: }
1.297 raeburn 10190: foreach my $item ('key','secret') {
10191: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10192: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
10193: $changes{$itemid} = 1;
10194: }
10195: }
1.267 raeburn 10196: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
10197: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
10198: }
10199: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
10200: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
10201: }
10202: foreach my $size ('width','height') {
10203: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
10204: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
10205: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
10206: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
10207: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10208: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
10209: $changes{$itemid} = 1;
10210: }
10211: } else {
10212: $changes{$itemid} = 1;
10213: }
1.296 raeburn 10214: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10215: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
10216: $changes{$itemid} = 1;
10217: }
10218: }
10219: }
10220: foreach my $item ('linktext','explanation') {
10221: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
10222: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
10223: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
10224: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10225: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10226: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
10227: $changes{$itemid} = 1;
10228: }
10229: } else {
10230: $changes{$itemid} = 1;
10231: }
10232: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10233: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
10234: $changes{$itemid} = 1;
10235: }
1.267 raeburn 10236: }
10237: }
10238: if ($env{'form.ltitools_target_'.$i} eq 'window') {
10239: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 10240: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
10241: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 10242: } else {
10243: $confhash{$itemid}{'display'}{'target'} = 'iframe';
10244: }
10245: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10246: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
10247: $changes{$itemid} = 1;
10248: }
10249: } else {
10250: $changes{$itemid} = 1;
10251: }
10252: foreach my $extra ('passback','roster') {
10253: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
10254: $confhash{$itemid}{$extra} = 1;
10255: }
10256: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
10257: $changes{$itemid} = 1;
10258: }
10259: }
1.273 raeburn 10260: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.296 raeburn 10261: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 10262: if (grep(/^\Q$item\E$/,@courseconfig)) {
10263: $confhash{$itemid}{'crsconf'}{$item} = 1;
10264: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
10265: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
10266: $changes{$itemid} = 1;
10267: }
10268: } else {
10269: $changes{$itemid} = 1;
10270: }
10271: }
10272: }
1.267 raeburn 10273: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
10274: foreach my $field (@fields) {
10275: if ($possfield{$field}) {
10276: if ($field eq 'roles') {
10277: foreach my $role (@courseroles) {
10278: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
10279: if (($choice ne '') && ($posslti{$choice})) {
10280: $confhash{$itemid}{'roles'}{$role} = $choice;
10281: if ($role eq 'cc') {
10282: $confhash{$itemid}{'roles'}{'co'} = $choice;
10283: }
10284: }
10285: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
10286: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
10287: $changes{$itemid} = 1;
10288: }
10289: } elsif ($confhash{$itemid}{'roles'}{$role}) {
10290: $changes{$itemid} = 1;
10291: }
10292: }
10293: } else {
10294: $confhash{$itemid}{'fields'}{$field} = 1;
10295: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
10296: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
10297: $changes{$itemid} = 1;
10298: }
10299: } else {
10300: $changes{$itemid} = 1;
10301: }
10302: }
10303: }
10304: }
10305: $allpos[$newpos] = $itemid;
10306: }
10307: if ($imgdeletions{$itemid}) {
10308: $changes{$itemid} = 1;
10309: #FIXME need to obsolete item in RES space
10310: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
10311: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
10312: $itemid,$configuserok,$switchserver,
10313: $author_ok);
10314: if ($imgurl) {
10315: $confhash{$itemid}{'image'} = $imgurl;
10316: $changes{$itemid} = 1;
10317: }
10318: if ($error) {
10319: &Apache::lonnet::logthis($error);
10320: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10321: }
10322: } elsif ($domconfig{$action}{$itemid}{'image'}) {
10323: $confhash{$itemid}{'image'} =
10324: $domconfig{$action}{$itemid}{'image'};
10325: }
10326: if ($customadds{$i}) {
10327: my $name = $env{'form.ltitools_custom_name_'.$i};
10328: $name =~ s/(`)/'/g;
10329: $name =~ s/^\s+//;
10330: $name =~ s/\s+$//;
10331: my $value = $env{'form.ltitools_custom_value_'.$i};
10332: $value =~ s/(`)/'/g;
10333: $value =~ s/^\s+//;
10334: $value =~ s/\s+$//;
10335: if ($name ne '') {
10336: $confhash{$itemid}{'custom'}{$name} = $value;
10337: $changes{$itemid} = 1;
10338: }
10339: }
10340: my %customdels;
10341: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
10342: if (@customdeletions) {
10343: $changes{$itemid} = 1;
10344: }
10345: map { $customdels{$_} = 1; } @customdeletions;
10346: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
10347: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
10348: unless ($customdels{$key}) {
10349: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
10350: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
10351: }
10352: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
10353: $changes{$itemid} = 1;
10354: }
10355: }
10356: }
10357: }
10358: unless ($changes{$itemid}) {
10359: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
10360: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
10361: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
10362: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
10363: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
10364: $changes{$itemid} = 1;
10365: last;
10366: }
10367: }
10368: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
10369: $changes{$itemid} = 1;
10370: }
10371: }
10372: last if ($changes{$itemid});
10373: }
10374: }
10375: }
10376: }
10377: }
10378: if (@allpos > 0) {
10379: my $idx = 0;
10380: foreach my $itemid (@allpos) {
10381: if ($itemid ne '') {
10382: $confhash{$itemid}{'order'} = $idx;
10383: if (ref($domconfig{$action}) eq 'HASH') {
10384: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10385: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
10386: $changes{$itemid} = 1;
10387: }
10388: }
10389: }
10390: $idx ++;
10391: }
10392: }
10393: }
10394: my %ltitoolshash = (
10395: $action => { %confhash }
10396: );
10397: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
10398: $dom);
10399: if ($putresult eq 'ok') {
1.297 raeburn 10400: my %ltienchash = (
10401: $action => { %encconfig }
10402: );
10403: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 10404: if (keys(%changes) > 0) {
10405: my $cachetime = 24*60*60;
1.297 raeburn 10406: my %ltiall = %confhash;
10407: foreach my $id (keys(%ltiall)) {
10408: if (ref($encconfig{$id}) eq 'HASH') {
10409: foreach my $item ('key','secret') {
10410: $ltiall{$id}{$item} = $encconfig{$id}{$item};
10411: }
10412: }
10413: }
10414: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 10415: if (ref($lastactref) eq 'HASH') {
10416: $lastactref->{'ltitools'} = 1;
10417: }
10418: $resulttext = &mt('Changes made:').'<ul>';
10419: my %bynum;
10420: foreach my $itemid (sort(keys(%changes))) {
10421: my $position = $confhash{$itemid}{'order'};
10422: $bynum{$position} = $itemid;
10423: }
10424: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10425: my $itemid = $bynum{$pos};
10426: if (ref($confhash{$itemid}) ne 'HASH') {
10427: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10428: } else {
10429: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
10430: if ($confhash{$itemid}{'image'}) {
10431: $resulttext .= ' '.
10432: '<img src="'.$confhash{$itemid}{'image'}.'"'.
10433: ' alt="'.&mt('Tool Provider icon').'" />';
10434: }
10435: $resulttext .= '</li><ul>';
10436: my $position = $pos + 1;
10437: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.297 raeburn 10438: foreach my $item ('version','msgtype','url') {
1.267 raeburn 10439: if ($confhash{$itemid}{$item} ne '') {
10440: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
10441: }
10442: }
1.297 raeburn 10443: if ($encconfig{$itemid}{'key'} ne '') {
10444: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
10445: }
10446: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 10447: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 10448: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 10449: $resulttext .= ('*'x$num).'</li>';
10450: }
1.273 raeburn 10451: $resulttext .= '<li>'.&mt('Configurable in course:');
1.296 raeburn 10452: my @possconfig = ('label','title','target','linktext','explanation');
1.273 raeburn 10453: my $numconfig = 0;
10454: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
10455: foreach my $item (@possconfig) {
10456: if ($confhash{$itemid}{'crsconf'}{$item}) {
10457: $numconfig ++;
1.296 raeburn 10458: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 10459: }
10460: }
10461: }
10462: if (!$numconfig) {
10463: $resulttext .= &mt('None');
10464: }
10465: $resulttext .= '</li>';
1.267 raeburn 10466: foreach my $item ('passback','roster') {
10467: $resulttext .= '<li>'.$lt{$item}.' ';
10468: if ($confhash{$itemid}{$item}) {
10469: $resulttext .= &mt('Yes');
10470: } else {
10471: $resulttext .= &mt('No');
10472: }
10473: $resulttext .= '</li>';
10474: }
10475: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
10476: my $displaylist;
10477: if ($confhash{$itemid}{'display'}{'target'}) {
10478: $displaylist = &mt('Display target').': '.
10479: $confhash{$itemid}{'display'}{'target'}.',';
10480: }
10481: foreach my $size ('width','height') {
10482: if ($confhash{$itemid}{'display'}{$size}) {
10483: $displaylist .= (' 'x2).$lt{$size}.': '.
10484: $confhash{$itemid}{'display'}{$size}.',';
10485: }
10486: }
10487: if ($displaylist) {
10488: $displaylist =~ s/,$//;
10489: $resulttext .= '<li>'.$displaylist.'</li>';
10490: }
1.296 raeburn 10491: foreach my $item ('linktext','explanation') {
10492: if ($confhash{$itemid}{'display'}{$item}) {
10493: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
10494: }
10495: }
10496: }
1.267 raeburn 10497: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
10498: my $fieldlist;
10499: foreach my $field (@allfields) {
10500: if ($confhash{$itemid}{'fields'}{$field}) {
10501: $fieldlist .= (' 'x2).$lt{$field}.',';
10502: }
10503: }
10504: if ($fieldlist) {
10505: $fieldlist =~ s/,$//;
10506: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
10507: }
10508: }
10509: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
10510: my $rolemaps;
10511: foreach my $role (@courseroles) {
10512: if ($confhash{$itemid}{'roles'}{$role}) {
10513: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
10514: $confhash{$itemid}{'roles'}{$role}.',';
10515: }
10516: }
10517: if ($rolemaps) {
10518: $rolemaps =~ s/,$//;
10519: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
10520: }
10521: }
10522: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
10523: my $customlist;
10524: if (keys(%{$confhash{$itemid}{'custom'}})) {
10525: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
10526: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
10527: }
10528: }
10529: if ($customlist) {
10530: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
10531: }
10532: }
10533: $resulttext .= '</ul></li>';
10534: }
10535: }
10536: $resulttext .= '</ul>';
10537: } else {
10538: $resulttext = &mt('No changes made.');
10539: }
10540: } else {
10541: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10542: }
10543: if ($errors) {
10544: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10545: $errors.'</ul>';
10546: }
10547: return $resulttext;
10548: }
10549:
10550: sub process_ltitools_image {
10551: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
10552: my $filename = $env{'form.'.$caller.'.filename'};
10553: my ($error,$url);
10554: my ($width,$height) = (21,21);
10555: if ($configuserok eq 'ok') {
10556: if ($switchserver) {
10557: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
10558: $switchserver);
10559: } elsif ($author_ok eq 'ok') {
10560: my ($result,$imageurl,$madethumb) =
10561: &publishlogo($r,'upload',$caller,$dom,$confname,
10562: "ltitools/$itemid/icon",$width,$height);
10563: if ($result eq 'ok') {
10564: if ($madethumb) {
10565: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
10566: my $imagethumb = "$path/tn-".$imagefile;
10567: $url = $imagethumb;
10568: } else {
10569: $url = $imageurl;
10570: }
10571: } else {
10572: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10573: }
10574: } else {
10575: $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);
10576: }
10577: } else {
10578: $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);
10579: }
10580: return ($url,$error);
10581: }
10582:
10583: sub get_ltitools_id {
10584: my ($cdom,$title) = @_;
10585: # get lock on ltitools db
10586: my $lockhash = {
10587: lock => $env{'user.name'}.
10588: ':'.$env{'user.domain'},
10589: };
10590: my $tries = 0;
10591: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10592: my ($id,$error);
10593:
10594: while (($gotlock ne 'ok') && ($tries<10)) {
10595: $tries ++;
10596: sleep (0.1);
10597: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10598: }
10599: if ($gotlock eq 'ok') {
10600: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
10601: if ($currids{'lock'}) {
10602: delete($currids{'lock'});
10603: if (keys(%currids)) {
10604: my @curr = sort { $a <=> $b } keys(%currids);
10605: if ($curr[-1] =~ /^\d+$/) {
10606: $id = 1 + $curr[-1];
10607: }
10608: } else {
10609: $id = 1;
10610: }
10611: if ($id) {
10612: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
10613: $error = 'nostore';
10614: }
10615: } else {
10616: $error = 'nonumber';
10617: }
10618: }
10619: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
10620: } else {
10621: $error = 'nolock';
10622: }
10623: return ($id,$error);
10624: }
10625:
1.3 raeburn 10626: sub modify_autoenroll {
1.205 raeburn 10627: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 10628: my ($resulttext,%changes);
10629: my %currautoenroll;
10630: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
10631: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
10632: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
10633: }
10634: }
10635: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
10636: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 10637: sender => 'Sender for notification messages',
1.274 raeburn 10638: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
10639: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 10640: my @offon = ('off','on');
1.17 raeburn 10641: my $sender_uname = $env{'form.sender_uname'};
10642: my $sender_domain = $env{'form.sender_domain'};
10643: if ($sender_domain eq '') {
10644: $sender_uname = '';
10645: } elsif ($sender_uname eq '') {
10646: $sender_domain = '';
10647: }
1.129 raeburn 10648: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 10649: my $failsafe = $env{'form.autoenroll_failsafe'};
10650: $failsafe =~ s{^\s+|\s+$}{}g;
10651: if ($failsafe =~ /\D/) {
10652: undef($failsafe);
10653: }
1.1 raeburn 10654: my %autoenrollhash = (
1.129 raeburn 10655: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10656: 'sender_uname' => $sender_uname,
10657: 'sender_domain' => $sender_domain,
10658: 'co-owners' => $coowners,
1.274 raeburn 10659: 'autofailsafe' => $failsafe,
1.1 raeburn 10660: }
10661: );
1.4 raeburn 10662: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10663: $dom);
1.1 raeburn 10664: if ($putresult eq 'ok') {
10665: if (exists($currautoenroll{'run'})) {
10666: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10667: $changes{'run'} = 1;
10668: }
10669: } elsif ($autorun) {
10670: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 10671: $changes{'run'} = 1;
1.1 raeburn 10672: }
10673: }
1.17 raeburn 10674: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 10675: $changes{'sender'} = 1;
10676: }
1.17 raeburn 10677: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 10678: $changes{'sender'} = 1;
10679: }
1.129 raeburn 10680: if ($currautoenroll{'co-owners'} ne '') {
10681: if ($currautoenroll{'co-owners'} ne $coowners) {
10682: $changes{'coowners'} = 1;
10683: }
10684: } elsif ($coowners) {
10685: $changes{'coowners'} = 1;
1.274 raeburn 10686: }
10687: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10688: $changes{'autofailsafe'} = 1;
10689: }
1.1 raeburn 10690: if (keys(%changes) > 0) {
10691: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 10692: if ($changes{'run'}) {
1.1 raeburn 10693: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10694: }
10695: if ($changes{'sender'}) {
1.17 raeburn 10696: if ($sender_uname eq '' || $sender_domain eq '') {
10697: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10698: } else {
10699: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10700: }
1.1 raeburn 10701: }
1.129 raeburn 10702: if ($changes{'coowners'}) {
10703: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10704: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10705: if (ref($lastactref) eq 'HASH') {
10706: $lastactref->{'domainconfig'} = 1;
10707: }
1.129 raeburn 10708: }
1.274 raeburn 10709: if ($changes{'autofailsafe'}) {
10710: if ($failsafe ne '') {
1.299 raeburn 10711: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 10712: } else {
1.299 raeburn 10713: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 10714: }
10715: &Apache::lonnet::get_domain_defaults($dom,1);
10716: if (ref($lastactref) eq 'HASH') {
10717: $lastactref->{'domdefaults'} = 1;
10718: }
10719: }
1.1 raeburn 10720: $resulttext .= '</ul>';
10721: } else {
10722: $resulttext = &mt('No changes made to auto-enrollment settings');
10723: }
10724: } else {
1.11 albertel 10725: $resulttext = '<span class="LC_error">'.
10726: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10727: }
1.3 raeburn 10728: return $resulttext;
1.1 raeburn 10729: }
10730:
10731: sub modify_autoupdate {
1.3 raeburn 10732: my ($dom,%domconfig) = @_;
1.1 raeburn 10733: my ($resulttext,%currautoupdate,%fields,%changes);
10734: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10735: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10736: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10737: }
10738: }
10739: my @offon = ('off','on');
10740: my %title = &Apache::lonlocal::texthash (
10741: run => 'Auto-update:',
10742: classlists => 'Updates to user information in classlists?'
10743: );
1.44 raeburn 10744: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10745: my %fieldtitles = &Apache::lonlocal::texthash (
10746: id => 'Student/Employee ID',
1.20 raeburn 10747: permanentemail => 'E-mail address',
1.1 raeburn 10748: lastname => 'Last Name',
10749: firstname => 'First Name',
10750: middlename => 'Middle Name',
1.132 raeburn 10751: generation => 'Generation',
1.1 raeburn 10752: );
1.142 raeburn 10753: $othertitle = &mt('All users');
1.1 raeburn 10754: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10755: $othertitle = &mt('Other users');
1.1 raeburn 10756: }
10757: foreach my $key (keys(%env)) {
10758: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10759: my ($usertype,$item) = ($1,$2);
10760: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10761: if ($usertype eq 'default') {
10762: push(@{$fields{$1}},$2);
10763: } elsif (ref($types) eq 'ARRAY') {
10764: if (grep(/^\Q$usertype\E$/,@{$types})) {
10765: push(@{$fields{$1}},$2);
10766: }
10767: }
10768: }
1.1 raeburn 10769: }
10770: }
1.131 raeburn 10771: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10772: @lockablenames = sort(@lockablenames);
10773: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10774: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10775: if (@changed) {
10776: $changes{'lockablenames'} = 1;
10777: }
10778: } else {
10779: if (@lockablenames) {
10780: $changes{'lockablenames'} = 1;
10781: }
10782: }
1.1 raeburn 10783: my %updatehash = (
10784: autoupdate => { run => $env{'form.autoupdate_run'},
10785: classlists => $env{'form.classlists'},
10786: fields => {%fields},
1.131 raeburn 10787: lockablenames => \@lockablenames,
1.1 raeburn 10788: }
10789: );
10790: foreach my $key (keys(%currautoupdate)) {
10791: if (($key eq 'run') || ($key eq 'classlists')) {
10792: if (exists($updatehash{autoupdate}{$key})) {
10793: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10794: $changes{$key} = 1;
10795: }
10796: }
10797: } elsif ($key eq 'fields') {
10798: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10799: foreach my $item (@{$types},'default') {
1.1 raeburn 10800: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10801: my $change = 0;
10802: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10803: if (!exists($fields{$item})) {
10804: $change = 1;
1.132 raeburn 10805: last;
1.1 raeburn 10806: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10807: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10808: $change = 1;
1.132 raeburn 10809: last;
1.1 raeburn 10810: }
10811: }
10812: }
10813: if ($change) {
10814: push(@{$changes{$key}},$item);
10815: }
1.26 raeburn 10816: }
1.1 raeburn 10817: }
10818: }
1.131 raeburn 10819: } elsif ($key eq 'lockablenames') {
10820: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10821: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10822: if (@changed) {
10823: $changes{'lockablenames'} = 1;
10824: }
10825: } else {
10826: if (@lockablenames) {
10827: $changes{'lockablenames'} = 1;
10828: }
10829: }
10830: }
10831: }
10832: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10833: if (@lockablenames) {
10834: $changes{'lockablenames'} = 1;
1.1 raeburn 10835: }
10836: }
1.26 raeburn 10837: foreach my $item (@{$types},'default') {
10838: if (defined($fields{$item})) {
10839: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10840: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10841: my $change = 0;
10842: if (ref($fields{$item}) eq 'ARRAY') {
10843: foreach my $type (@{$fields{$item}}) {
10844: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10845: $change = 1;
10846: last;
10847: }
10848: }
10849: }
10850: if ($change) {
10851: push(@{$changes{'fields'}},$item);
10852: }
10853: } else {
1.26 raeburn 10854: push(@{$changes{'fields'}},$item);
10855: }
10856: } else {
10857: push(@{$changes{'fields'}},$item);
1.1 raeburn 10858: }
10859: }
10860: }
10861: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10862: $dom);
10863: if ($putresult eq 'ok') {
10864: if (keys(%changes) > 0) {
10865: $resulttext = &mt('Changes made:').'<ul>';
10866: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10867: if ($key eq 'lockablenames') {
10868: $resulttext .= '<li>';
10869: if (@lockablenames) {
10870: $usertypes->{'default'} = $othertitle;
10871: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10872: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10873: } else {
10874: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10875: }
10876: $resulttext .= '</li>';
10877: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10878: foreach my $item (@{$changes{$key}}) {
10879: my @newvalues;
10880: foreach my $type (@{$fields{$item}}) {
10881: push(@newvalues,$fieldtitles{$type});
10882: }
1.3 raeburn 10883: my $newvaluestr;
10884: if (@newvalues > 0) {
10885: $newvaluestr = join(', ',@newvalues);
10886: } else {
10887: $newvaluestr = &mt('none');
1.6 raeburn 10888: }
1.1 raeburn 10889: if ($item eq 'default') {
1.26 raeburn 10890: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10891: } else {
1.26 raeburn 10892: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10893: }
10894: }
10895: } else {
10896: my $newvalue;
10897: if ($key eq 'run') {
10898: $newvalue = $offon[$env{'form.autoupdate_run'}];
10899: } else {
10900: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10901: }
1.1 raeburn 10902: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10903: }
10904: }
10905: $resulttext .= '</ul>';
10906: } else {
1.3 raeburn 10907: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10908: }
10909: } else {
1.11 albertel 10910: $resulttext = '<span class="LC_error">'.
10911: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10912: }
1.3 raeburn 10913: return $resulttext;
1.1 raeburn 10914: }
10915:
1.125 raeburn 10916: sub modify_autocreate {
10917: my ($dom,%domconfig) = @_;
10918: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10919: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10920: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10921: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10922: }
10923: }
10924: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10925: req => 'Auto-creation of validated requests for official courses',
10926: xmldc => 'Identity of course creator of courses from XML files',
10927: );
10928: my @types = ('xml','req');
10929: foreach my $item (@types) {
10930: $newvals{$item} = $env{'form.autocreate_'.$item};
10931: $newvals{$item} =~ s/\D//g;
10932: $newvals{$item} = 0 if ($newvals{$item} eq '');
10933: }
10934: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 10935: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10936: unless (exists($domcoords{$newvals{'xmldc'}})) {
10937: $newvals{'xmldc'} = '';
10938: }
10939: %autocreatehash = (
10940: autocreate => { xml => $newvals{'xml'},
10941: req => $newvals{'req'},
10942: }
10943: );
10944: if ($newvals{'xmldc'} ne '') {
10945: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10946: }
10947: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10948: $dom);
10949: if ($putresult eq 'ok') {
10950: my @items = @types;
10951: if ($newvals{'xml'}) {
10952: push(@items,'xmldc');
10953: }
10954: foreach my $item (@items) {
10955: if (exists($currautocreate{$item})) {
10956: if ($currautocreate{$item} ne $newvals{$item}) {
10957: $changes{$item} = 1;
10958: }
10959: } elsif ($newvals{$item}) {
10960: $changes{$item} = 1;
10961: }
10962: }
10963: if (keys(%changes) > 0) {
10964: my @offon = ('off','on');
10965: $resulttext = &mt('Changes made:').'<ul>';
10966: foreach my $item (@types) {
10967: if ($changes{$item}) {
10968: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 10969: $resulttext .= '<li>'.
10970: &mt("$title{$item} set to [_1]$newtxt [_2]",
10971: '<b>','</b>').
10972: '</li>';
1.125 raeburn 10973: }
10974: }
10975: if ($changes{'xmldc'}) {
10976: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10977: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 10978: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10979: }
10980: $resulttext .= '</ul>';
10981: } else {
10982: $resulttext = &mt('No changes made to auto-creation settings');
10983: }
10984: } else {
10985: $resulttext = '<span class="LC_error">'.
10986: &mt('An error occurred: [_1]',$putresult).'</span>';
10987: }
10988: return $resulttext;
10989: }
10990:
1.23 raeburn 10991: sub modify_directorysrch {
1.295 raeburn 10992: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10993: my ($resulttext,%changes);
10994: my %currdirsrch;
10995: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10996: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10997: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10998: }
10999: }
1.277 raeburn 11000: my %title = ( available => 'Institutional directory search available',
11001: localonly => 'Other domains can search institution',
11002: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 11003: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 11004: searchby => 'Search types',
11005: searchtypes => 'Search latitude');
11006: my @offon = ('off','on');
1.24 raeburn 11007: my @otherdoms = ('Yes','No');
1.23 raeburn 11008:
1.25 raeburn 11009: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 11010: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
11011: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
11012:
1.44 raeburn 11013: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 11014: if (keys(%{$usertypes}) == 0) {
11015: @cansearch = ('default');
11016: } else {
11017: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
11018: foreach my $type (@{$currdirsrch{'cansearch'}}) {
11019: if (!grep(/^\Q$type\E$/,@cansearch)) {
11020: push(@{$changes{'cansearch'}},$type);
11021: }
1.23 raeburn 11022: }
1.26 raeburn 11023: foreach my $type (@cansearch) {
11024: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
11025: push(@{$changes{'cansearch'}},$type);
11026: }
1.23 raeburn 11027: }
1.26 raeburn 11028: } else {
11029: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 11030: }
11031: }
11032:
11033: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
11034: foreach my $by (@{$currdirsrch{'searchby'}}) {
11035: if (!grep(/^\Q$by\E$/,@searchby)) {
11036: push(@{$changes{'searchby'}},$by);
11037: }
11038: }
11039: foreach my $by (@searchby) {
11040: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
11041: push(@{$changes{'searchby'}},$by);
11042: }
11043: }
11044: } else {
11045: push(@{$changes{'searchby'}},@searchby);
11046: }
1.25 raeburn 11047:
11048: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
11049: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
11050: if (!grep(/^\Q$type\E$/,@searchtypes)) {
11051: push(@{$changes{'searchtypes'}},$type);
11052: }
11053: }
11054: foreach my $type (@searchtypes) {
11055: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
11056: push(@{$changes{'searchtypes'}},$type);
11057: }
11058: }
11059: } else {
11060: if (exists($currdirsrch{'searchtypes'})) {
11061: foreach my $type (@searchtypes) {
11062: if ($type ne $currdirsrch{'searchtypes'}) {
11063: push(@{$changes{'searchtypes'}},$type);
11064: }
11065: }
11066: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
11067: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
11068: }
11069: } else {
11070: push(@{$changes{'searchtypes'}},@searchtypes);
11071: }
11072: }
11073:
1.23 raeburn 11074: my %dirsrch_hash = (
11075: directorysrch => { available => $env{'form.dirsrch_available'},
11076: cansearch => \@cansearch,
1.277 raeburn 11077: localonly => $env{'form.dirsrch_instlocalonly'},
11078: lclocalonly => $env{'form.dirsrch_domlocalonly'},
11079: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 11080: searchby => \@searchby,
1.25 raeburn 11081: searchtypes => \@searchtypes,
1.23 raeburn 11082: }
11083: );
11084: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
11085: $dom);
11086: if ($putresult eq 'ok') {
11087: if (exists($currdirsrch{'available'})) {
11088: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
11089: $changes{'available'} = 1;
11090: }
11091: } else {
11092: if ($env{'form.dirsrch_available'} eq '1') {
11093: $changes{'available'} = 1;
11094: }
11095: }
1.277 raeburn 11096: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 11097: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
11098: $changes{'lcavailable'} = 1;
11099: }
1.277 raeburn 11100: } else {
11101: if ($env{'form.dirsrch_lcavailable'} eq '1') {
11102: $changes{'lcavailable'} = 1;
11103: }
11104: }
1.24 raeburn 11105: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 11106: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
11107: $changes{'localonly'} = 1;
11108: }
1.24 raeburn 11109: } else {
1.277 raeburn 11110: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 11111: $changes{'localonly'} = 1;
11112: }
11113: }
1.277 raeburn 11114: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 11115: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
11116: $changes{'lclocalonly'} = 1;
11117: }
1.277 raeburn 11118: } else {
11119: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
11120: $changes{'lclocalonly'} = 1;
11121: }
11122: }
1.23 raeburn 11123: if (keys(%changes) > 0) {
11124: $resulttext = &mt('Changes made:').'<ul>';
11125: if ($changes{'available'}) {
11126: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
11127: }
1.277 raeburn 11128: if ($changes{'lcavailable'}) {
11129: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
11130: }
1.24 raeburn 11131: if ($changes{'localonly'}) {
1.277 raeburn 11132: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 11133: }
1.277 raeburn 11134: if ($changes{'lclocalonly'}) {
11135: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 11136: }
1.23 raeburn 11137: if (ref($changes{'cansearch'}) eq 'ARRAY') {
11138: my $chgtext;
1.26 raeburn 11139: if (ref($usertypes) eq 'HASH') {
11140: if (keys(%{$usertypes}) > 0) {
11141: foreach my $type (@{$types}) {
11142: if (grep(/^\Q$type\E$/,@cansearch)) {
11143: $chgtext .= $usertypes->{$type}.'; ';
11144: }
11145: }
11146: if (grep(/^default$/,@cansearch)) {
11147: $chgtext .= $othertitle;
11148: } else {
11149: $chgtext =~ s/\; $//;
11150: }
1.210 raeburn 11151: $resulttext .=
1.178 raeburn 11152: '<li>'.
11153: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
11154: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
11155: '</li>';
1.23 raeburn 11156: }
11157: }
11158: }
11159: if (ref($changes{'searchby'}) eq 'ARRAY') {
11160: my ($searchtitles,$titleorder) = &sorted_searchtitles();
11161: my $chgtext;
11162: foreach my $type (@{$titleorder}) {
11163: if (grep(/^\Q$type\E$/,@searchby)) {
11164: if (defined($searchtitles->{$type})) {
11165: $chgtext .= $searchtitles->{$type}.'; ';
11166: }
11167: }
11168: }
11169: $chgtext =~ s/\; $//;
11170: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
11171: }
1.25 raeburn 11172: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
11173: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
11174: my $chgtext;
11175: foreach my $type (@{$srchtypeorder}) {
11176: if (grep(/^\Q$type\E$/,@searchtypes)) {
11177: if (defined($srchtypes_desc->{$type})) {
11178: $chgtext .= $srchtypes_desc->{$type}.'; ';
11179: }
11180: }
11181: }
11182: $chgtext =~ s/\; $//;
1.178 raeburn 11183: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 11184: }
11185: $resulttext .= '</ul>';
1.295 raeburn 11186: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
11187: if (ref($lastactref) eq 'HASH') {
11188: $lastactref->{'directorysrch'} = 1;
11189: }
1.23 raeburn 11190: } else {
1.277 raeburn 11191: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 11192: }
11193: } else {
11194: $resulttext = '<span class="LC_error">'.
1.27 raeburn 11195: &mt('An error occurred: [_1]',$putresult).'</span>';
11196: }
11197: return $resulttext;
11198: }
11199:
1.28 raeburn 11200: sub modify_contacts {
1.205 raeburn 11201: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 11202: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
11203: if (ref($domconfig{'contacts'}) eq 'HASH') {
11204: foreach my $key (keys(%{$domconfig{'contacts'}})) {
11205: $currsetting{$key} = $domconfig{'contacts'}{$key};
11206: }
11207: }
1.286 raeburn 11208: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 11209: my @contacts = ('supportemail','adminemail');
1.286 raeburn 11210: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
11211: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 11212: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 11213: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 11214: foreach my $type (@mailings) {
11215: @{$newsetting{$type}} =
11216: &Apache::loncommon::get_env_multiple('form.'.$type);
11217: foreach my $item (@contacts) {
11218: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
11219: $contacts_hash{contacts}{$type}{$item} = 1;
11220: } else {
11221: $contacts_hash{contacts}{$type}{$item} = 0;
11222: }
1.289 raeburn 11223: }
1.28 raeburn 11224: $others{$type} = $env{'form.'.$type.'_others'};
11225: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 11226: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11227: $bcc{$type} = $env{'form.'.$type.'_bcc'};
11228: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 11229: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
11230: $includestr{$type} = $env{'form.'.$type.'_includestr'};
11231: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
11232: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11233: }
1.134 raeburn 11234: }
1.28 raeburn 11235: }
11236: foreach my $item (@contacts) {
11237: $to{$item} = $env{'form.'.$item};
11238: $contacts_hash{'contacts'}{$item} = $to{$item};
11239: }
1.203 raeburn 11240: foreach my $item (@toggles) {
11241: if ($env{'form.'.$item} =~ /^(0|1)$/) {
11242: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
11243: }
11244: }
1.286 raeburn 11245: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
11246: foreach my $field (@{$fields}) {
11247: if (ref($possoptions->{$field}) eq 'ARRAY') {
11248: my $value = $env{'form.helpform_'.$field};
11249: $value =~ s/^\s+|\s+$//g;
11250: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 ! raeburn 11251: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 11252: if ($field eq 'screenshot') {
11253: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
11254: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 ! raeburn 11255: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 11256: }
11257: }
11258: }
11259: }
11260: }
11261: }
1.315 ! raeburn 11262: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 11263: my (@statuses,%usertypeshash,@overrides);
! 11264: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
! 11265: @statuses = @{$types};
! 11266: if (ref($usertypes) eq 'HASH') {
! 11267: %usertypeshash = %{$usertypes};
! 11268: }
! 11269: }
! 11270: if (@statuses) {
! 11271: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
! 11272: foreach my $type (@possoverrides) {
! 11273: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
! 11274: push(@overrides,$type);
! 11275: }
! 11276: }
! 11277: if (@overrides) {
! 11278: foreach my $type (@overrides) {
! 11279: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
! 11280: foreach my $item (@contacts) {
! 11281: if (grep(/^\Q$item\E$/,@standard)) {
! 11282: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
! 11283: $newsetting{'override_'.$type}{$item} = 1;
! 11284: } else {
! 11285: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
! 11286: $newsetting{'override_'.$type}{$item} = 0;
! 11287: }
! 11288: }
! 11289: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
! 11290: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
! 11291: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
! 11292: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
! 11293: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
! 11294: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
! 11295: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
! 11296: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
! 11297: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
! 11298: }
! 11299: }
! 11300: }
! 11301: }
1.28 raeburn 11302: if (keys(%currsetting) > 0) {
11303: foreach my $item (@contacts) {
11304: if ($to{$item} ne $currsetting{$item}) {
11305: $changes{$item} = 1;
11306: }
11307: }
11308: foreach my $type (@mailings) {
11309: foreach my $item (@contacts) {
11310: if (ref($currsetting{$type}) eq 'HASH') {
11311: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
11312: push(@{$changes{$type}},$item);
11313: }
11314: } else {
11315: push(@{$changes{$type}},@{$newsetting{$type}});
11316: }
11317: }
11318: if ($others{$type} ne $currsetting{$type}{'others'}) {
11319: push(@{$changes{$type}},'others');
11320: }
1.289 raeburn 11321: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11322: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
11323: push(@{$changes{$type}},'bcc');
11324: }
1.286 raeburn 11325: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
11326: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
11327: push(@{$changes{$type}},'include');
11328: }
11329: }
11330: }
11331: if (ref($fields) eq 'ARRAY') {
11332: if (ref($currsetting{'helpform'}) eq 'HASH') {
11333: foreach my $field (@{$fields}) {
11334: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
11335: push(@{$changes{'helpform'}},$field);
11336: }
11337: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11338: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
11339: push(@{$changes{'helpform'}},'maxsize');
11340: }
11341: }
11342: }
11343: } else {
11344: foreach my $field (@{$fields}) {
11345: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11346: push(@{$changes{'helpform'}},$field);
11347: }
11348: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11349: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11350: push(@{$changes{'helpform'}},'maxsize');
11351: }
11352: }
11353: }
1.134 raeburn 11354: }
1.28 raeburn 11355: }
1.315 ! raeburn 11356: if (@statuses) {
! 11357: if (ref($currsetting{'overrides'}) eq 'HASH') {
! 11358: foreach my $key (keys(%{$currsetting{'overrides'}})) {
! 11359: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
! 11360: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
! 11361: foreach my $item (@contacts,'bcc','others','include') {
! 11362: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
! 11363: push(@{$changes{'overrides'}},$key);
! 11364: last;
! 11365: }
! 11366: }
! 11367: } else {
! 11368: push(@{$changes{'overrides'}},$key);
! 11369: }
! 11370: }
! 11371: }
! 11372: foreach my $key (@overrides) {
! 11373: unless (exists($currsetting{'overrides'}{$key})) {
! 11374: push(@{$changes{'overrides'}},$key);
! 11375: }
! 11376: }
! 11377: } else {
! 11378: foreach my $key (@overrides) {
! 11379: push(@{$changes{'overrides'}},$key);
! 11380: }
! 11381: }
! 11382: }
1.28 raeburn 11383: } else {
11384: my %default;
11385: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
11386: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
11387: $default{'errormail'} = 'adminemail';
11388: $default{'packagesmail'} = 'adminemail';
11389: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 11390: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 11391: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 11392: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 11393: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 11394: foreach my $item (@contacts) {
11395: if ($to{$item} ne $default{$item}) {
1.286 raeburn 11396: $changes{$item} = 1;
1.203 raeburn 11397: }
1.28 raeburn 11398: }
11399: foreach my $type (@mailings) {
11400: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
11401: push(@{$changes{$type}},@{$newsetting{$type}});
11402: }
11403: if ($others{$type} ne '') {
11404: push(@{$changes{$type}},'others');
1.134 raeburn 11405: }
1.286 raeburn 11406: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11407: if ($bcc{$type} ne '') {
11408: push(@{$changes{$type}},'bcc');
11409: }
1.286 raeburn 11410: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
11411: push(@{$changes{$type}},'include');
11412: }
1.134 raeburn 11413: }
1.28 raeburn 11414: }
1.286 raeburn 11415: if (ref($fields) eq 'ARRAY') {
11416: foreach my $field (@{$fields}) {
11417: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11418: push(@{$changes{'helpform'}},$field);
11419: }
11420: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11421: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11422: push(@{$changes{'helpform'}},'maxsize');
11423: }
11424: }
11425: }
1.289 raeburn 11426: }
1.28 raeburn 11427: }
1.203 raeburn 11428: foreach my $item (@toggles) {
11429: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
11430: $changes{$item} = 1;
11431: } elsif ((!$env{'form.'.$item}) &&
11432: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
11433: $changes{$item} = 1;
11434: }
11435: }
1.28 raeburn 11436: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
11437: $dom);
11438: if ($putresult eq 'ok') {
11439: if (keys(%changes) > 0) {
1.205 raeburn 11440: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11441: if (ref($lastactref) eq 'HASH') {
11442: $lastactref->{'domainconfig'} = 1;
11443: }
1.28 raeburn 11444: my ($titles,$short_titles) = &contact_titles();
11445: $resulttext = &mt('Changes made:').'<ul>';
11446: foreach my $item (@contacts) {
11447: if ($changes{$item}) {
11448: $resulttext .= '<li>'.$titles->{$item}.
11449: &mt(' set to: ').
11450: '<span class="LC_cusr_emph">'.
11451: $to{$item}.'</span></li>';
11452: }
11453: }
11454: foreach my $type (@mailings) {
11455: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 11456: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 11457: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 11458: } else {
11459: $resulttext .= '<li>'.$titles->{$type}.': ';
11460: }
1.28 raeburn 11461: my @text;
11462: foreach my $item (@{$newsetting{$type}}) {
11463: push(@text,$short_titles->{$item});
11464: }
11465: if ($others{$type} ne '') {
11466: push(@text,$others{$type});
11467: }
1.286 raeburn 11468: if (@text) {
11469: $resulttext .= '<span class="LC_cusr_emph">'.
11470: join(', ',@text).'</span>';
11471: }
11472: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11473: if ($bcc{$type} ne '') {
1.286 raeburn 11474: my $bcctext;
11475: if (@text) {
1.289 raeburn 11476: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 11477: } else {
11478: $bcctext = '(Bcc)';
11479: }
11480: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
11481: } elsif (!@text) {
11482: $resulttext .= &mt('No one');
11483: }
1.289 raeburn 11484: if ($includestr{$type} ne '') {
1.286 raeburn 11485: if ($includeloc{$type} eq 'b') {
11486: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
11487: } elsif ($includeloc{$type} eq 's') {
11488: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
11489: }
1.134 raeburn 11490: }
1.286 raeburn 11491: } elsif (!@text) {
11492: $resulttext .= &mt('No recipients');
1.134 raeburn 11493: }
11494: $resulttext .= '</li>';
1.28 raeburn 11495: }
11496: }
1.315 ! raeburn 11497: if (ref($changes{'overrides'}) eq 'ARRAY') {
! 11498: my @deletions;
! 11499: foreach my $type (@{$changes{'overrides'}}) {
! 11500: if ($usertypeshash{$type}) {
! 11501: if (grep(/^\Q$type\E/,@overrides)) {
! 11502: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
! 11503: $usertypeshash{$type}).'<ul><li>';
! 11504: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
! 11505: my @text;
! 11506: foreach my $item (@contacts) {
! 11507: if ($newsetting{'override_'.$type}{$item}) {
! 11508: push(@text,$short_titles->{$item});
! 11509: }
! 11510: }
! 11511: if ($newsetting{'override_'.$type}{'others'} ne '') {
! 11512: push(@text,$newsetting{'override_'.$type}{'others'});
! 11513: }
! 11514:
! 11515: if (@text) {
! 11516: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
! 11517: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
! 11518: }
! 11519: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
! 11520: my $bcctext;
! 11521: if (@text) {
! 11522: $bcctext = ' '.&mt('with Bcc to');
! 11523: } else {
! 11524: $bcctext = '(Bcc)';
! 11525: }
! 11526: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
! 11527: } elsif (!@text) {
! 11528: $resulttext .= &mt('Helpdesk e-mail sent to no one');
! 11529: }
! 11530: $resulttext .= '</li>';
! 11531: if ($newsetting{'override_'.$type}{'include'} ne '') {
! 11532: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
! 11533: if ($loc eq 'b') {
! 11534: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
! 11535: } elsif ($loc eq 's') {
! 11536: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
! 11537: }
! 11538: }
! 11539: }
! 11540: $resulttext .= '</li></ul></li>';
! 11541: } else {
! 11542: push(@deletions,$usertypeshash{$type});
! 11543: }
! 11544: }
! 11545: }
! 11546: if (@deletions) {
! 11547: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
! 11548: join(', ',@deletions)).'</li>';
! 11549: }
! 11550: }
1.203 raeburn 11551: my @offon = ('off','on');
11552: if ($changes{'reporterrors'}) {
11553: $resulttext .= '<li>'.
11554: &mt('E-mail error reports to [_1] set to "'.
11555: $offon[$env{'form.reporterrors'}].'".',
11556: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11557: &mt('LON-CAPA core group - MSU'),600,500)).
11558: '</li>';
11559: }
11560: if ($changes{'reportupdates'}) {
11561: $resulttext .= '<li>'.
11562: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
11563: $offon[$env{'form.reportupdates'}].'".',
11564: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11565: &mt('LON-CAPA core group - MSU'),600,500)).
11566: '</li>';
11567: }
1.286 raeburn 11568: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
11569: my (@optional,@required,@unused,$maxsizechg);
11570: foreach my $field (@{$changes{'helpform'}}) {
11571: if ($field eq 'maxsize') {
11572: $maxsizechg = 1;
11573: next;
11574: }
11575: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 11576: push(@optional,$field);
1.286 raeburn 11577: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
11578: push(@unused,$field);
11579: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 11580: push(@required,$field);
1.286 raeburn 11581: }
11582: }
11583: if (@optional) {
11584: $resulttext .= '<li>'.
11585: &mt('Help form fields changed to "Optional": [_1].',
11586: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
11587: '</li>';
11588: }
11589: if (@required) {
11590: $resulttext .= '<li>'.
11591: &mt('Help form fields changed to "Required": [_1].',
11592: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
11593: '</li>';
11594: }
11595: if (@unused) {
11596: $resulttext .= '<li>'.
11597: &mt('Help form fields changed to "Not shown": [_1].',
11598: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
11599: '</li>';
11600: }
11601: if ($maxsizechg) {
11602: $resulttext .= '<li>'.
11603: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
11604: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
11605: '</li>';
11606: }
11607: }
1.28 raeburn 11608: $resulttext .= '</ul>';
11609: } else {
1.288 raeburn 11610: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 11611: }
11612: } else {
11613: $resulttext = '<span class="LC_error">'.
11614: &mt('An error occurred: [_1].',$putresult).'</span>';
11615: }
11616: return $resulttext;
11617: }
11618:
11619: sub modify_usercreation {
1.27 raeburn 11620: my ($dom,%domconfig) = @_;
1.224 raeburn 11621: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 11622: my $warningmsg;
1.27 raeburn 11623: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11624: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 11625: if ($key eq 'cancreate') {
11626: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11627: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 11628: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
11629: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11630: } else {
1.224 raeburn 11631: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11632: }
11633: }
11634: }
11635: } elsif ($key eq 'email_rule') {
11636: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11637: } else {
11638: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11639: }
1.27 raeburn 11640: }
11641: }
11642: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 11643: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 11644: my @contexts = ('author','course','requestcrs');
1.34 raeburn 11645: foreach my $item(@contexts) {
1.224 raeburn 11646: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 11647: }
1.34 raeburn 11648: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11649: foreach my $item (@contexts) {
1.224 raeburn 11650: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
11651: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 11652: }
1.27 raeburn 11653: }
1.34 raeburn 11654: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
11655: foreach my $item (@contexts) {
1.43 raeburn 11656: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 11657: if ($cancreate{$item} ne 'any') {
11658: push(@{$changes{'cancreate'}},$item);
11659: }
11660: } else {
11661: if ($cancreate{$item} ne 'none') {
11662: push(@{$changes{'cancreate'}},$item);
11663: }
1.27 raeburn 11664: }
11665: }
11666: } else {
1.43 raeburn 11667: foreach my $item (@contexts) {
1.34 raeburn 11668: push(@{$changes{'cancreate'}},$item);
11669: }
1.27 raeburn 11670: }
1.34 raeburn 11671:
1.27 raeburn 11672: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
11673: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
11674: if (!grep(/^\Q$type\E$/,@username_rule)) {
11675: push(@{$changes{'username_rule'}},$type);
11676: }
11677: }
11678: foreach my $type (@username_rule) {
11679: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
11680: push(@{$changes{'username_rule'}},$type);
11681: }
11682: }
11683: } else {
11684: push(@{$changes{'username_rule'}},@username_rule);
11685: }
11686:
1.32 raeburn 11687: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11688: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11689: if (!grep(/^\Q$type\E$/,@id_rule)) {
11690: push(@{$changes{'id_rule'}},$type);
11691: }
11692: }
11693: foreach my $type (@id_rule) {
11694: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11695: push(@{$changes{'id_rule'}},$type);
11696: }
11697: }
11698: } else {
11699: push(@{$changes{'id_rule'}},@id_rule);
11700: }
11701:
1.43 raeburn 11702: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11703: my @authtypes = ('int','krb4','krb5','loc');
11704: my %authhash;
1.43 raeburn 11705: foreach my $item (@authen_contexts) {
1.28 raeburn 11706: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11707: foreach my $auth (@authtypes) {
11708: if (grep(/^\Q$auth\E$/,@authallowed)) {
11709: $authhash{$item}{$auth} = 1;
11710: } else {
11711: $authhash{$item}{$auth} = 0;
11712: }
11713: }
11714: }
11715: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11716: foreach my $item (@authen_contexts) {
1.28 raeburn 11717: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11718: foreach my $auth (@authtypes) {
11719: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11720: push(@{$changes{'authtypes'}},$item);
11721: last;
11722: }
11723: }
11724: }
11725: }
11726: } else {
1.43 raeburn 11727: foreach my $item (@authen_contexts) {
1.28 raeburn 11728: push(@{$changes{'authtypes'}},$item);
11729: }
11730: }
11731:
1.224 raeburn 11732: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11733: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11734: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11735: $save_usercreate{'id_rule'} = \@id_rule;
11736: $save_usercreate{'username_rule'} = \@username_rule,
11737: $save_usercreate{'authtypes'} = \%authhash;
11738:
1.27 raeburn 11739: my %usercreation_hash = (
1.224 raeburn 11740: usercreation => \%save_usercreate,
11741: );
1.27 raeburn 11742:
11743: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11744: $dom);
1.50 raeburn 11745:
1.224 raeburn 11746: if ($putresult eq 'ok') {
11747: if (keys(%changes) > 0) {
11748: $resulttext = &mt('Changes made:').'<ul>';
11749: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11750: my %lt = &usercreation_types();
11751: foreach my $type (@{$changes{'cancreate'}}) {
11752: my $chgtext = $lt{$type}.', ';
11753: if ($cancreate{$type} eq 'none') {
11754: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11755: } elsif ($cancreate{$type} eq 'any') {
11756: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11757: } elsif ($cancreate{$type} eq 'official') {
11758: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11759: } elsif ($cancreate{$type} eq 'unofficial') {
11760: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11761: }
11762: $resulttext .= '<li>'.$chgtext.'</li>';
11763: }
11764: }
11765: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11766: my ($rules,$ruleorder) =
11767: &Apache::lonnet::inst_userrules($dom,'username');
11768: my $chgtext = '<ul>';
11769: foreach my $type (@username_rule) {
11770: if (ref($rules->{$type}) eq 'HASH') {
11771: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11772: }
11773: }
11774: $chgtext .= '</ul>';
11775: if (@username_rule > 0) {
11776: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11777: } else {
11778: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11779: }
11780: }
11781: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11782: my ($idrules,$idruleorder) =
11783: &Apache::lonnet::inst_userrules($dom,'id');
11784: my $chgtext = '<ul>';
11785: foreach my $type (@id_rule) {
11786: if (ref($idrules->{$type}) eq 'HASH') {
11787: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11788: }
11789: }
11790: $chgtext .= '</ul>';
11791: if (@id_rule > 0) {
11792: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11793: } else {
11794: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11795: }
11796: }
11797: my %authname = &authtype_names();
11798: my %context_title = &context_names();
11799: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11800: my $chgtext = '<ul>';
11801: foreach my $type (@{$changes{'authtypes'}}) {
11802: my @allowed;
11803: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11804: foreach my $auth (@authtypes) {
11805: if ($authhash{$type}{$auth}) {
11806: push(@allowed,$authname{$auth});
11807: }
11808: }
11809: if (@allowed > 0) {
11810: $chgtext .= join(', ',@allowed).'</li>';
11811: } else {
11812: $chgtext .= &mt('none').'</li>';
11813: }
11814: }
11815: $chgtext .= '</ul>';
11816: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11817: $resulttext .= '</li>';
11818: }
11819: $resulttext .= '</ul>';
11820: } else {
11821: $resulttext = &mt('No changes made to user creation settings');
11822: }
11823: } else {
11824: $resulttext = '<span class="LC_error">'.
11825: &mt('An error occurred: [_1]',$putresult).'</span>';
11826: }
11827: if ($warningmsg ne '') {
11828: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11829: }
11830: return $resulttext;
11831: }
11832:
11833: sub modify_selfcreation {
1.305 raeburn 11834: my ($dom,$lastactref,%domconfig) = @_;
11835: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
11836: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
11837: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 11838: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
11839: if (ref($typesref) eq 'ARRAY') {
11840: @types = @{$typesref};
11841: }
11842: if (ref($usertypesref) eq 'HASH') {
11843: %usertypes = %{$usertypesref};
1.228 raeburn 11844: }
1.303 raeburn 11845: $usertypes{'default'} = $othertitle;
1.224 raeburn 11846: #
11847: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11848: #
11849: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11850: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11851: if ($key eq 'cancreate') {
11852: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11853: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11854: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 11855: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
11856: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
11857: ($item eq 'emailusername') || ($item eq 'shibenv') ||
11858: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 11859: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 11860: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11861: } else {
11862: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11863: }
11864: }
11865: }
11866: } elsif ($key eq 'email_rule') {
11867: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11868: } else {
11869: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11870: }
11871: }
11872: }
11873: #
11874: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11875: #
11876: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11877: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11878: if ($key eq 'selfcreate') {
11879: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11880: } else {
11881: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11882: }
11883: }
11884: }
1.305 raeburn 11885: #
11886: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
11887: #
11888: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11889: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
11890: if ($key eq 'inststatusguest') {
11891: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
11892: } else {
11893: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
11894: }
11895: }
11896: }
1.224 raeburn 11897:
11898: my @contexts = ('selfcreate');
11899: @{$cancreate{'selfcreate'}} = ();
11900: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 11901: if (@types) {
11902: @{$cancreate{'statustocreate'}} = ();
11903: }
1.236 raeburn 11904: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 11905: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 11906: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 11907: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 11908: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 11909: my %selfcreatetypes = (
11910: sso => 'users authenticated by institutional single sign on',
11911: login => 'users authenticated by institutional log-in',
1.303 raeburn 11912: email => 'users verified by e-mail',
1.50 raeburn 11913: );
1.224 raeburn 11914: #
11915: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11916: # is permitted.
11917: #
1.305 raeburn 11918: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 11919:
1.305 raeburn 11920: my (@statuses,%email_rule);
1.228 raeburn 11921: foreach my $item ('login','sso','email') {
1.224 raeburn 11922: if ($item eq 'email') {
1.236 raeburn 11923: if ($env{'form.cancreate_email'}) {
1.305 raeburn 11924: if (@types) {
11925: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
11926: foreach my $status (@poss_statuses) {
11927: if (grep(/^\Q$status\E$/,(@types,'default'))) {
11928: push(@statuses,$status);
11929: }
11930: }
11931: $save_inststatus{'inststatusguest'} = \@statuses;
11932: } else {
11933: push(@statuses,'default');
11934: }
11935: if (@statuses) {
11936: my %curr_rule;
11937: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11938: foreach my $type (@statuses) {
11939: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 11940: }
1.305 raeburn 11941: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
11942: foreach my $type (@statuses) {
11943: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
11944: }
11945: }
11946: push(@{$cancreate{'selfcreate'}},'email');
11947: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
11948: my %curremaildom;
11949: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
11950: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
11951: }
11952: foreach my $type (@statuses) {
11953: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
11954: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11955: }
11956: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
11957: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
11958: }
11959: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
11960: #
11961: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
11962: #
11963: my $chosen = $1;
11964: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
11965: my $emaildom;
11966: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
11967: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
11968: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
11969: if (ref($curremaildom{$type}) eq 'HASH') {
11970: if (exists($curremaildom{$type}{$chosen})) {
11971: if ($curremaildom{$type}{$chosen} ne $emaildom) {
11972: push(@{$changes{'cancreate'}},'emaildomain');
11973: }
11974: } elsif ($emaildom ne '') {
11975: push(@{$changes{'cancreate'}},'emaildomain');
11976: }
11977: } elsif ($emaildom ne '') {
11978: push(@{$changes{'cancreate'}},'emaildomain');
11979: }
11980: }
11981: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
11982: } elsif ($chosen eq 'custom') {
11983: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
11984: $email_rule{$type} = [];
11985: if (ref($emailrules) eq 'HASH') {
11986: foreach my $rule (@possemail_rules) {
11987: if (exists($emailrules->{$rule})) {
11988: push(@{$email_rule{$type}},$rule);
11989: }
11990: }
11991: }
11992: if (@{$email_rule{$type}}) {
11993: $cancreate{'emailoptions'}{$type} = 'custom';
11994: if (ref($curr_rule{$type}) eq 'ARRAY') {
11995: if (@{$curr_rule{$type}} > 0) {
11996: foreach my $rule (@{$curr_rule{$type}}) {
11997: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
11998: push(@{$changes{'email_rule'}},$type);
11999: }
12000: }
12001: }
12002: foreach my $type (@{$email_rule{$type}}) {
12003: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
12004: push(@{$changes{'email_rule'}},$type);
12005: }
12006: }
12007: } else {
12008: push(@{$changes{'email_rule'}},$type);
12009: }
12010: }
12011: } else {
12012: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
12013: }
12014: }
12015: }
12016: if (@types) {
12017: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
12018: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
12019: if (@changed) {
12020: push(@{$changes{'inststatus'}},'inststatusguest');
12021: }
12022: } else {
12023: push(@{$changes{'inststatus'}},'inststatusguest');
12024: }
12025: }
12026: } else {
12027: delete($env{'form.cancreate_email'});
12028: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
12029: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
12030: push(@{$changes{'inststatus'}},'inststatusguest');
12031: }
12032: }
12033: }
12034: } else {
12035: $save_inststatus{'inststatusguest'} = [];
12036: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
12037: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
12038: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 12039: }
12040: }
1.224 raeburn 12041: }
12042: } else {
12043: if ($env{'form.cancreate_'.$item}) {
12044: push(@{$cancreate{'selfcreate'}},$item);
12045: }
12046: }
12047: }
1.305 raeburn 12048: my (%userinfo,%savecaptcha);
1.224 raeburn 12049: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
12050: #
1.228 raeburn 12051: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
12052: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 12053: #
1.236 raeburn 12054:
1.244 raeburn 12055: if ($env{'form.cancreate_email'}) {
1.228 raeburn 12056: push(@contexts,'emailusername');
1.305 raeburn 12057: if (@statuses) {
12058: foreach my $type (@statuses) {
1.228 raeburn 12059: if (ref($infofields) eq 'ARRAY') {
12060: foreach my $field (@{$infofields}) {
12061: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
12062: $cancreate{'emailusername'}{$type}{$field} = $1;
12063: }
12064: }
1.224 raeburn 12065: }
12066: }
12067: }
12068: #
12069: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 12070: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 12071: #
12072:
12073: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
12074: @approvalnotify = sort(@approvalnotify);
12075: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
12076: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12077: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
12078: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
12079: push(@{$changes{'cancreate'}},'notify');
12080: }
12081: } else {
12082: if ($cancreate{'notify'}{'approval'}) {
12083: push(@{$changes{'cancreate'}},'notify');
12084: }
12085: }
12086: } elsif ($cancreate{'notify'}{'approval'}) {
12087: push(@{$changes{'cancreate'}},'notify');
12088: }
12089:
12090: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
12091: }
12092: #
1.236 raeburn 12093: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 12094: # institutional log-in.
12095: #
12096: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
12097: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
12098: ($domdefaults{'auth_def'} eq 'localauth'))) {
12099: $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.').' '.
12100: &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.');
12101: }
12102: }
12103: my @fields = ('lastname','firstname','middlename','generation',
12104: 'permanentemail','id');
1.240 raeburn 12105: my @shibfields = (@fields,'inststatus');
1.224 raeburn 12106: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12107: #
12108: # Where usernames may created for institutional log-in and/or institutional single sign on:
12109: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
12110: # may self-create accounts
12111: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
12112: # which the user may supply, if institutional data is unavailable.
12113: #
12114: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 12115: if (@types) {
1.305 raeburn 12116: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
12117: push(@contexts,'statustocreate');
1.303 raeburn 12118: foreach my $type (@types) {
1.224 raeburn 12119: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
12120: foreach my $field (@fields) {
12121: if (grep(/^\Q$field\E$/,@modifiable)) {
12122: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
12123: } else {
12124: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
12125: }
12126: }
12127: }
12128: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 12129: foreach my $type (@types) {
1.224 raeburn 12130: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
12131: foreach my $field (@fields) {
12132: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
12133: $curr_usermodify{'selfcreate'}{$type}{$field}) {
12134: push(@{$changes{'selfcreate'}},$type);
12135: last;
12136: }
12137: }
12138: }
12139: }
12140: } else {
1.303 raeburn 12141: foreach my $type (@types) {
1.224 raeburn 12142: push(@{$changes{'selfcreate'}},$type);
12143: }
12144: }
12145: }
1.240 raeburn 12146: foreach my $field (@shibfields) {
12147: if ($env{'form.shibenv_'.$field} ne '') {
12148: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
12149: }
12150: }
12151: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
12152: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
12153: foreach my $field (@shibfields) {
12154: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
12155: push(@{$changes{'cancreate'}},'shibenv');
12156: }
12157: }
12158: } else {
12159: foreach my $field (@shibfields) {
12160: if ($env{'form.shibenv_'.$field}) {
12161: push(@{$changes{'cancreate'}},'shibenv');
12162: last;
12163: }
12164: }
12165: }
12166: }
1.224 raeburn 12167: }
12168: foreach my $item (@contexts) {
12169: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
12170: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
12171: if (ref($cancreate{$item}) eq 'ARRAY') {
12172: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
12173: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12174: push(@{$changes{'cancreate'}},$item);
12175: }
12176: }
12177: }
12178: }
12179: if (ref($cancreate{$item}) eq 'ARRAY') {
12180: foreach my $type (@{$cancreate{$item}}) {
12181: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
12182: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12183: push(@{$changes{'cancreate'}},$item);
12184: }
12185: }
12186: }
12187: }
12188: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
12189: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 12190: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
12191: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
12192: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
12193: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 12194: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12195: push(@{$changes{'cancreate'}},$item);
12196: }
12197: }
12198: }
1.305 raeburn 12199: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
12200: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 12201: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12202: push(@{$changes{'cancreate'}},$item);
12203: }
1.224 raeburn 12204: }
12205: }
12206: }
1.305 raeburn 12207: foreach my $type (keys(%{$cancreate{$item}})) {
12208: if (ref($cancreate{$item}{$type}) eq 'HASH') {
12209: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
12210: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
12211: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 12212: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12213: push(@{$changes{'cancreate'}},$item);
12214: }
12215: }
12216: } else {
12217: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12218: push(@{$changes{'cancreate'}},$item);
12219: }
12220: }
12221: }
1.305 raeburn 12222: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
12223: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 12224: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12225: push(@{$changes{'cancreate'}},$item);
12226: }
1.224 raeburn 12227: }
12228: }
12229: }
12230: }
12231: } elsif ($curr_usercreation{'cancreate'}{$item}) {
12232: if (ref($cancreate{$item}) eq 'ARRAY') {
12233: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
12234: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12235: push(@{$changes{'cancreate'}},$item);
12236: }
12237: }
1.305 raeburn 12238: }
12239: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
12240: if (ref($cancreate{$item}) eq 'HASH') {
12241: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12242: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 12243: }
12244: }
12245: } elsif ($item eq 'emailusername') {
1.228 raeburn 12246: if (ref($cancreate{$item}) eq 'HASH') {
12247: foreach my $type (keys(%{$cancreate{$item}})) {
12248: if (ref($cancreate{$item}{$type}) eq 'HASH') {
12249: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
12250: if ($cancreate{$item}{$type}{$field}) {
12251: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
12252: push(@{$changes{'cancreate'}},$item);
12253: }
12254: last;
12255: }
12256: }
12257: }
12258: }
1.224 raeburn 12259: }
12260: }
12261: }
12262: #
12263: # Populate %save_usercreate hash with updates to self-creation configuration.
12264: #
12265: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
12266: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 12267: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 12268: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
12269: if (ref($cancreate{'notify'}) eq 'HASH') {
12270: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
12271: }
1.236 raeburn 12272: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
12273: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
12274: }
1.303 raeburn 12275: if (ref($cancreate{'emailverified'}) eq 'HASH') {
12276: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
12277: }
1.305 raeburn 12278: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
12279: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
12280: }
1.303 raeburn 12281: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
12282: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
12283: }
1.224 raeburn 12284: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
12285: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
12286: }
1.240 raeburn 12287: if (ref($cancreate{'shibenv'}) eq 'HASH') {
12288: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
12289: }
1.224 raeburn 12290: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 12291: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 12292:
12293: my %userconfig_hash = (
12294: usercreation => \%save_usercreate,
12295: usermodification => \%save_usermodify,
1.305 raeburn 12296: inststatus => \%save_inststatus,
1.224 raeburn 12297: );
1.305 raeburn 12298:
1.224 raeburn 12299: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
12300: $dom);
12301: #
1.305 raeburn 12302: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 12303: #
1.27 raeburn 12304: if ($putresult eq 'ok') {
12305: if (keys(%changes) > 0) {
12306: $resulttext = &mt('Changes made:').'<ul>';
12307: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 12308: my %lt = &selfcreation_types();
1.34 raeburn 12309: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 12310: my $chgtext = '';
1.45 raeburn 12311: if ($type eq 'selfcreate') {
1.50 raeburn 12312: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 12313: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 12314: } else {
1.224 raeburn 12315: $chgtext .= &mt('Self-creation of a new account is permitted for:').
12316: '<ul>';
1.50 raeburn 12317: foreach my $case (@{$cancreate{$type}}) {
12318: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
12319: }
12320: $chgtext .= '</ul>';
1.100 raeburn 12321: if (ref($cancreate{$type}) eq 'ARRAY') {
12322: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
12323: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
12324: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 12325: $chgtext .= '<span class="LC_warning">'.
12326: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
12327: '</span><br />';
12328: }
12329: }
12330: }
12331: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 12332: if (!@statuses) {
12333: $chgtext .= '<span class="LC_warning">'.
12334: &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.").
12335: '</span><br />';
1.303 raeburn 12336:
1.100 raeburn 12337: }
12338: }
12339: }
1.43 raeburn 12340: }
1.240 raeburn 12341: } elsif ($type eq 'shibenv') {
12342: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 12343: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 12344: } else {
12345: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
12346: '<ul>';
12347: foreach my $field (@shibfields) {
12348: next if ($cancreate{$type}{$field} eq '');
12349: if ($field eq 'inststatus') {
12350: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
12351: } else {
12352: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
12353: }
12354: }
12355: $chgtext .= '</ul>';
1.303 raeburn 12356: }
1.93 raeburn 12357: } elsif ($type eq 'statustocreate') {
1.96 raeburn 12358: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
12359: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
12360: if (@{$cancreate{'selfcreate'}} > 0) {
12361: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 12362: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 12363: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 12364: $chgtext .= '<br />'.
12365: '<span class="LC_warning">'.
12366: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
12367: '</span>';
12368: }
1.303 raeburn 12369: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 12370: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 12371: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
12372: } else {
12373: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
12374: }
12375: $chgtext .= '<ul>';
12376: foreach my $case (@{$cancreate{$type}}) {
12377: if ($case eq 'default') {
12378: $chgtext .= '<li>'.$othertitle.'</li>';
12379: } else {
1.303 raeburn 12380: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 12381: }
12382: }
1.100 raeburn 12383: $chgtext .= '</ul>';
12384: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 12385: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 12386: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
12387: '</span>';
1.100 raeburn 12388: }
12389: }
12390: } else {
12391: if (@{$cancreate{$type}} == 0) {
12392: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
12393: } else {
12394: $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 12395: }
12396: }
1.303 raeburn 12397: $chgtext .= '<br />';
1.93 raeburn 12398: }
1.236 raeburn 12399: } elsif ($type eq 'selfcreateprocessing') {
12400: my %choices = &Apache::lonlocal::texthash (
12401: automatic => 'Automatic approval',
12402: approval => 'Queued for approval',
12403: );
1.305 raeburn 12404: if (@types) {
12405: if (@statuses) {
1.303 raeburn 12406: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 12407: '<ul>';
1.305 raeburn 12408: foreach my $status (@statuses) {
12409: if ($status eq 'default') {
12410: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 12411: } else {
1.305 raeburn 12412: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 12413: }
12414: }
12415: $chgtext .= '</ul>';
12416: }
12417: } else {
12418: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
12419: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
12420: }
12421: } elsif ($type eq 'emailverified') {
12422: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 12423: all => 'Same as e-mail',
12424: first => 'Omit @domain',
12425: free => 'Free to choose',
1.303 raeburn 12426: );
1.305 raeburn 12427: if (@types) {
12428: if (@statuses) {
1.303 raeburn 12429: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
12430: '<ul>';
1.305 raeburn 12431: foreach my $status (@statuses) {
1.303 raeburn 12432: if ($type eq 'default') {
1.305 raeburn 12433: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 12434: } else {
1.305 raeburn 12435: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 12436: }
12437: }
12438: $chgtext .= '</ul>';
12439: }
12440: } else {
1.305 raeburn 12441: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 12442: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 12443: }
1.305 raeburn 12444: } elsif ($type eq 'emailoptions') {
12445: my %options = &Apache::lonlocal::texthash (
12446: any => 'Any e-mail',
12447: inst => 'Institutional only',
12448: noninst => 'Non-institutional only',
12449: custom => 'Custom restrictions',
12450: );
12451: if (@types) {
12452: if (@statuses) {
12453: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
12454: '<ul>';
12455: foreach my $status (@statuses) {
12456: if ($type eq 'default') {
12457: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
12458: } else {
12459: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 12460: }
12461: }
1.305 raeburn 12462: $chgtext .= '</ul>';
12463: }
12464: } else {
12465: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
12466: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
12467: } else {
12468: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
12469: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 12470: }
1.305 raeburn 12471: }
12472: } elsif ($type eq 'emaildomain') {
12473: my $output;
12474: if (@statuses) {
12475: foreach my $type (@statuses) {
12476: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
12477: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
12478: if ($type eq 'default') {
12479: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12480: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12481: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12482: } else {
12483: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
12484: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12485: }
1.303 raeburn 12486: } else {
1.305 raeburn 12487: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12488: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12489: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12490: } else {
12491: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
12492: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12493: }
1.303 raeburn 12494: }
1.305 raeburn 12495: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
12496: if ($type eq 'default') {
12497: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12498: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12499: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12500: } else {
12501: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
12502: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12503: }
1.303 raeburn 12504: } else {
1.305 raeburn 12505: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12506: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12507: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12508: } else {
12509: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
12510: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12511: }
1.303 raeburn 12512: }
12513: }
12514: }
12515: }
1.305 raeburn 12516: }
12517: if ($output ne '') {
12518: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
12519: '<ul>'.$output.'</ul>';
1.236 raeburn 12520: }
1.165 raeburn 12521: } elsif ($type eq 'captcha') {
1.224 raeburn 12522: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 12523: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
12524: } else {
12525: my %captchas = &captcha_phrases();
1.224 raeburn 12526: if ($captchas{$savecaptcha{$type}}) {
12527: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 12528: } else {
1.210 raeburn 12529: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 12530: }
12531: }
12532: } elsif ($type eq 'recaptchakeys') {
12533: my ($privkey,$pubkey);
1.224 raeburn 12534: if (ref($savecaptcha{$type}) eq 'HASH') {
12535: $pubkey = $savecaptcha{$type}{'public'};
12536: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 12537: }
12538: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
12539: if (!$pubkey) {
12540: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
12541: } else {
12542: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12543: }
12544: if (!$privkey) {
12545: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
12546: } else {
12547: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
12548: }
12549: $chgtext .= '</ul>';
1.269 raeburn 12550: } elsif ($type eq 'recaptchaversion') {
12551: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 12552: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 12553: }
1.224 raeburn 12554: } elsif ($type eq 'emailusername') {
12555: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 12556: if (@statuses) {
12557: foreach my $type (@statuses) {
1.228 raeburn 12558: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
12559: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 12560: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 12561: '<ul>';
12562: foreach my $field (@{$infofields}) {
12563: if ($cancreate{'emailusername'}{$type}{$field}) {
12564: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
12565: }
12566: }
1.245 raeburn 12567: $chgtext .= '</ul>';
12568: } else {
1.303 raeburn 12569: $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.228 raeburn 12570: }
12571: } else {
1.303 raeburn 12572: $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.224 raeburn 12573: }
12574: }
12575: }
12576: }
12577: } elsif ($type eq 'notify') {
1.303 raeburn 12578: my $numapprove = 0;
1.224 raeburn 12579: if (ref($changes{'cancreate'}) eq 'ARRAY') {
12580: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
12581: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 12582: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
12583: $numapprove ++;
1.224 raeburn 12584: }
12585: }
1.43 raeburn 12586: }
1.303 raeburn 12587: unless ($numapprove) {
12588: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
12589: }
1.34 raeburn 12590: }
1.224 raeburn 12591: if ($chgtext) {
12592: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 12593: }
12594: }
12595: }
1.305 raeburn 12596: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 12597: my ($emailrules,$emailruleorder) =
12598: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 12599: foreach my $type (@{$changes{'email_rule'}}) {
12600: if (ref($email_rule{$type}) eq 'ARRAY') {
12601: my $chgtext = '<ul>';
12602: foreach my $rule (@{$email_rule{$type}}) {
12603: if (ref($emailrules->{$rule}) eq 'HASH') {
12604: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
12605: }
12606: }
12607: $chgtext .= '</ul>';
1.310 raeburn 12608: my $typename;
1.305 raeburn 12609: if (@types) {
12610: if ($type eq 'default') {
12611: $typename = $othertitle;
12612: } else {
12613: $typename = $usertypes{$type};
12614: }
12615: $chgtext .= &mt('(Affiliation: [_1])',$typename);
12616: }
12617: if (@{$email_rule{$type}} > 0) {
12618: $resulttext .= '<li>'.
12619: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
12620: $usertypes{$type}).
12621: $chgtext.
12622: '</li>';
12623: } else {
12624: $resulttext .= '<li>'.
1.310 raeburn 12625: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
1.305 raeburn 12626: '</li>'.
1.310 raeburn 12627: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 12628: }
1.43 raeburn 12629: }
12630: }
1.305 raeburn 12631: }
12632: if (ref($changes{'inststatus'}) eq 'ARRAY') {
12633: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
12634: if (@{$save_inststatus{'inststatusguest'}} > 0) {
12635: my $chgtext = '<ul>';
12636: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
12637: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
12638: }
12639: $chgtext .= '</ul>';
12640: $resulttext .= '<li>'.
12641: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
12642: $chgtext.
12643: '</li>';
12644: } else {
12645: $resulttext .= '<li>'.
12646: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
12647: '</li>';
12648: }
1.43 raeburn 12649: }
12650: }
1.224 raeburn 12651: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
12652: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
12653: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12654: foreach my $type (@{$changes{'selfcreate'}}) {
12655: my $typename = $type;
1.303 raeburn 12656: if (keys(%usertypes) > 0) {
12657: if ($usertypes{$type} ne '') {
12658: $typename = $usertypes{$type};
1.224 raeburn 12659: }
12660: }
12661: my @modifiable;
12662: $resulttext .= '<li>'.
12663: &mt('Self-creation of account by users with status: [_1]',
12664: '<span class="LC_cusr_emph">'.$typename.'</span>').
12665: ' - '.&mt('modifiable fields (if institutional data blank): ');
12666: foreach my $field (@fields) {
12667: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
12668: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 12669: }
12670: }
1.224 raeburn 12671: if (@modifiable > 0) {
12672: $resulttext .= join(', ',@modifiable);
1.43 raeburn 12673: } else {
1.224 raeburn 12674: $resulttext .= &mt('none');
1.43 raeburn 12675: }
1.224 raeburn 12676: $resulttext .= '</li>';
1.28 raeburn 12677: }
1.224 raeburn 12678: $resulttext .= '</ul></li>';
1.28 raeburn 12679: }
1.27 raeburn 12680: $resulttext .= '</ul>';
1.305 raeburn 12681: my $cachetime = 24*60*60;
12682: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
12683: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12684: if (ref($lastactref) eq 'HASH') {
12685: $lastactref->{'domdefaults'} = 1;
12686: }
1.27 raeburn 12687: } else {
1.224 raeburn 12688: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 12689: }
12690: } else {
12691: $resulttext = '<span class="LC_error">'.
1.23 raeburn 12692: &mt('An error occurred: [_1]',$putresult).'</span>';
12693: }
1.43 raeburn 12694: if ($warningmsg ne '') {
12695: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12696: }
1.23 raeburn 12697: return $resulttext;
12698: }
12699:
1.165 raeburn 12700: sub process_captcha {
12701: my ($container,$changes,$newsettings,$current) = @_;
12702: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
12703: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
12704: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
12705: $newsettings->{'captcha'} = 'original';
12706: }
12707: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 12708: if ($container eq 'cancreate') {
1.169 raeburn 12709: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12710: push(@{$changes->{'cancreate'}},'captcha');
12711: } elsif (!defined($changes->{'cancreate'})) {
12712: $changes->{'cancreate'} = ['captcha'];
12713: }
12714: } else {
12715: $changes->{'captcha'} = 1;
1.165 raeburn 12716: }
12717: }
1.269 raeburn 12718: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 12719: if ($newsettings->{'captcha'} eq 'recaptcha') {
12720: $newpub = $env{'form.'.$container.'_recaptchapub'};
12721: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 12722: $newpub =~ s/[^\w\-]//g;
12723: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 12724: $newsettings->{'recaptchakeys'} = {
12725: public => $newpub,
12726: private => $newpriv,
12727: };
1.269 raeburn 12728: $newversion = $env{'form.'.$container.'_recaptchaversion'};
12729: $newversion =~ s/\D//g;
12730: if ($newversion ne '2') {
12731: $newversion = 1;
12732: }
12733: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 12734: }
12735: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
12736: $currpub = $current->{'recaptchakeys'}{'public'};
12737: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 12738: unless ($newsettings->{'captcha'} eq 'recaptcha') {
12739: $newsettings->{'recaptchakeys'} = {
12740: public => '',
12741: private => '',
12742: }
12743: }
1.165 raeburn 12744: }
1.269 raeburn 12745: if ($current->{'captcha'} eq 'recaptcha') {
12746: $currversion = $current->{'recaptchaversion'};
12747: if ($currversion ne '2') {
12748: $currversion = 1;
12749: }
12750: }
12751: if ($currversion ne $newversion) {
12752: if ($container eq 'cancreate') {
12753: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12754: push(@{$changes->{'cancreate'}},'recaptchaversion');
12755: } elsif (!defined($changes->{'cancreate'})) {
12756: $changes->{'cancreate'} = ['recaptchaversion'];
12757: }
12758: } else {
12759: $changes->{'recaptchaversion'} = 1;
12760: }
12761: }
1.165 raeburn 12762: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 12763: if ($container eq 'cancreate') {
12764: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12765: push(@{$changes->{'cancreate'}},'recaptchakeys');
12766: } elsif (!defined($changes->{'cancreate'})) {
12767: $changes->{'cancreate'} = ['recaptchakeys'];
12768: }
12769: } else {
1.210 raeburn 12770: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 12771: }
12772: }
12773: return;
12774: }
12775:
1.33 raeburn 12776: sub modify_usermodification {
12777: my ($dom,%domconfig) = @_;
1.224 raeburn 12778: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 12779: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12780: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 12781: if ($key eq 'selfcreate') {
12782: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
12783: } else {
12784: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
12785: }
1.33 raeburn 12786: }
12787: }
1.224 raeburn 12788: my @contexts = ('author','course');
1.33 raeburn 12789: my %context_title = (
12790: author => 'In author context',
12791: course => 'In course context',
12792: );
12793: my @fields = ('lastname','firstname','middlename','generation',
12794: 'permanentemail','id');
12795: my %roles = (
12796: author => ['ca','aa'],
12797: course => ['st','ep','ta','in','cr'],
12798: );
12799: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12800: foreach my $context (@contexts) {
12801: foreach my $role (@{$roles{$context}}) {
12802: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
12803: foreach my $item (@fields) {
12804: if (grep(/^\Q$item\E$/,@modifiable)) {
12805: $modifyhash{$context}{$role}{$item} = 1;
12806: } else {
12807: $modifyhash{$context}{$role}{$item} = 0;
12808: }
12809: }
12810: }
12811: if (ref($curr_usermodification{$context}) eq 'HASH') {
12812: foreach my $role (@{$roles{$context}}) {
12813: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
12814: foreach my $field (@fields) {
12815: if ($modifyhash{$context}{$role}{$field} ne
12816: $curr_usermodification{$context}{$role}{$field}) {
12817: push(@{$changes{$context}},$role);
12818: last;
12819: }
12820: }
12821: }
12822: }
12823: } else {
12824: foreach my $context (@contexts) {
12825: foreach my $role (@{$roles{$context}}) {
12826: push(@{$changes{$context}},$role);
12827: }
12828: }
12829: }
12830: }
12831: my %usermodification_hash = (
12832: usermodification => \%modifyhash,
12833: );
12834: my $putresult = &Apache::lonnet::put_dom('configuration',
12835: \%usermodification_hash,$dom);
12836: if ($putresult eq 'ok') {
12837: if (keys(%changes) > 0) {
12838: $resulttext = &mt('Changes made: ').'<ul>';
12839: foreach my $context (@contexts) {
12840: if (ref($changes{$context}) eq 'ARRAY') {
12841: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
12842: if (ref($changes{$context}) eq 'ARRAY') {
12843: foreach my $role (@{$changes{$context}}) {
12844: my $rolename;
1.224 raeburn 12845: if ($role eq 'cr') {
12846: $rolename = &mt('Custom');
1.33 raeburn 12847: } else {
1.224 raeburn 12848: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 12849: }
12850: my @modifiable;
1.224 raeburn 12851: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 12852: foreach my $field (@fields) {
12853: if ($modifyhash{$context}{$role}{$field}) {
12854: push(@modifiable,$fieldtitles{$field});
12855: }
12856: }
12857: if (@modifiable > 0) {
12858: $resulttext .= join(', ',@modifiable);
12859: } else {
12860: $resulttext .= &mt('none');
12861: }
12862: $resulttext .= '</li>';
12863: }
12864: $resulttext .= '</ul></li>';
12865: }
12866: }
12867: }
12868: $resulttext .= '</ul>';
12869: } else {
12870: $resulttext = &mt('No changes made to user modification settings');
12871: }
12872: } else {
12873: $resulttext = '<span class="LC_error">'.
12874: &mt('An error occurred: [_1]',$putresult).'</span>';
12875: }
12876: return $resulttext;
12877: }
12878:
1.43 raeburn 12879: sub modify_defaults {
1.212 raeburn 12880: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 12881: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 12882: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 12883: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
12884: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 12885: my @authtypes = ('internal','krb4','krb5','localauth');
12886: foreach my $item (@items) {
12887: $newvalues{$item} = $env{'form.'.$item};
12888: if ($item eq 'auth_def') {
12889: if ($newvalues{$item} ne '') {
12890: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
12891: push(@errors,$item);
12892: }
12893: }
12894: } elsif ($item eq 'lang_def') {
12895: if ($newvalues{$item} ne '') {
12896: if ($newvalues{$item} =~ /^(\w+)/) {
12897: my $langcode = $1;
1.103 raeburn 12898: if ($langcode ne 'x_chef') {
12899: if (code2language($langcode) eq '') {
12900: push(@errors,$item);
12901: }
1.43 raeburn 12902: }
12903: } else {
12904: push(@errors,$item);
12905: }
12906: }
1.54 raeburn 12907: } elsif ($item eq 'timezone_def') {
12908: if ($newvalues{$item} ne '') {
1.62 raeburn 12909: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 12910: push(@errors,$item);
12911: }
12912: }
1.68 raeburn 12913: } elsif ($item eq 'datelocale_def') {
12914: if ($newvalues{$item} ne '') {
12915: my @datelocale_ids = DateTime::Locale->ids();
12916: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
12917: push(@errors,$item);
12918: }
12919: }
1.141 raeburn 12920: } elsif ($item eq 'portal_def') {
12921: if ($newvalues{$item} ne '') {
12922: 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])\/?$/) {
12923: push(@errors,$item);
12924: }
12925: }
1.294 raeburn 12926: } elsif ($item eq 'intauth_cost') {
12927: if ($newvalues{$item} ne '') {
12928: if ($newvalues{$item} =~ /\D/) {
12929: push(@errors,$item);
12930: }
12931: }
12932: } elsif ($item eq 'intauth_check') {
12933: if ($newvalues{$item} ne '') {
12934: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12935: push(@errors,$item);
12936: }
12937: }
12938: } elsif ($item eq 'intauth_switch') {
12939: if ($newvalues{$item} ne '') {
12940: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12941: push(@errors,$item);
12942: }
12943: }
1.43 raeburn 12944: }
12945: if (grep(/^\Q$item\E$/,@errors)) {
12946: $newvalues{$item} = $domdefaults{$item};
12947: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12948: $changes{$item} = 1;
12949: }
1.72 raeburn 12950: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 12951: }
12952: my %defaults_hash = (
1.72 raeburn 12953: defaults => \%newvalues,
12954: );
1.43 raeburn 12955: my $title = &defaults_titles();
1.236 raeburn 12956:
12957: my $currinststatus;
12958: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12959: $currinststatus = $domconfig{'inststatus'};
12960: } else {
12961: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12962: $currinststatus = {
12963: inststatustypes => $usertypes,
12964: inststatusorder => $types,
12965: inststatusguest => [],
12966: };
12967: }
12968: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12969: my @allpos;
12970: my %alltypes;
1.305 raeburn 12971: my @inststatusguest;
12972: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12973: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
12974: unless (grep(/^\Q$type\E$/,@todelete)) {
12975: push(@inststatusguest,$type);
12976: }
12977: }
12978: }
12979: my ($currtitles,$currorder);
1.236 raeburn 12980: if (ref($currinststatus) eq 'HASH') {
12981: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12982: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12983: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12984: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12985: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12986: }
12987: }
12988: unless (grep(/^\Q$type\E$/,@todelete)) {
12989: my $position = $env{'form.inststatus_pos_'.$type};
12990: $position =~ s/\D+//g;
12991: $allpos[$position] = $type;
12992: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12993: $alltypes{$type} =~ s/`//g;
12994: }
12995: }
12996: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12997: $currtitles =~ s/,$//;
12998: }
12999: }
13000: if ($env{'form.addinststatus'}) {
13001: my $newtype = $env{'form.addinststatus'};
13002: $newtype =~ s/\W//g;
13003: unless (exists($alltypes{$newtype})) {
13004: $alltypes{$newtype} = $env{'form.addinststatus_title'};
13005: $alltypes{$newtype} =~ s/`//g;
13006: my $position = $env{'form.addinststatus_pos'};
13007: $position =~ s/\D+//g;
13008: if ($position ne '') {
13009: $allpos[$position] = $newtype;
13010: }
13011: }
13012: }
1.305 raeburn 13013: my @orderedstatus;
1.236 raeburn 13014: foreach my $type (@allpos) {
13015: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
13016: push(@orderedstatus,$type);
13017: }
13018: }
13019: foreach my $type (keys(%alltypes)) {
13020: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
13021: delete($alltypes{$type});
13022: }
13023: }
13024: $defaults_hash{'inststatus'} = {
13025: inststatustypes => \%alltypes,
13026: inststatusorder => \@orderedstatus,
1.305 raeburn 13027: inststatusguest => \@inststatusguest,
1.236 raeburn 13028: };
13029: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
13030: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
13031: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
13032: }
13033: }
13034: if ($currorder ne join(',',@orderedstatus)) {
13035: $changes{'inststatus'}{'inststatusorder'} = 1;
13036: }
13037: my $newtitles;
13038: foreach my $item (@orderedstatus) {
13039: $newtitles .= $alltypes{$item}.',';
13040: }
13041: $newtitles =~ s/,$//;
13042: if ($currtitles ne $newtitles) {
13043: $changes{'inststatus'}{'inststatustypes'} = 1;
13044: }
1.43 raeburn 13045: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
13046: $dom);
13047: if ($putresult eq 'ok') {
13048: if (keys(%changes) > 0) {
13049: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 13050: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 13051: 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";
13052: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 13053: if ($item eq 'inststatus') {
13054: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 13055: if (@orderedstatus) {
1.236 raeburn 13056: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
13057: foreach my $type (@orderedstatus) {
13058: $resulttext .= $alltypes{$type}.', ';
13059: }
13060: $resulttext =~ s/, $//;
13061: $resulttext .= '</li>';
1.305 raeburn 13062: } else {
13063: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 13064: }
13065: }
13066: } else {
13067: my $value = $env{'form.'.$item};
13068: if ($value eq '') {
13069: $value = &mt('none');
13070: } elsif ($item eq 'auth_def') {
13071: my %authnames = &authtype_names();
13072: my %shortauth = (
13073: internal => 'int',
13074: krb4 => 'krb4',
13075: krb5 => 'krb5',
13076: localauth => 'loc',
13077: );
13078: $value = $authnames{$shortauth{$value}};
1.294 raeburn 13079: } elsif ($item eq 'intauth_switch') {
13080: my %optiondesc = &Apache::lonlocal::texthash (
13081: 0 => 'No',
13082: 1 => 'Yes',
13083: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
13084: );
13085: if ($value =~ /^(0|1|2)$/) {
13086: $value = $optiondesc{$value};
13087: } else {
13088: $value = &mt('none -- defaults to No');
13089: }
13090: } elsif ($item eq 'intauth_check') {
13091: my %optiondesc = &Apache::lonlocal::texthash (
13092: 0 => 'No',
13093: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
13094: 2 => 'Yes, disallow login if stored cost is less than domain default',
13095: );
13096: if ($value =~ /^(0|1|2)$/) {
13097: $value = $optiondesc{$value};
13098: } else {
13099: $value = &mt('none -- defaults to No');
13100: }
1.236 raeburn 13101: }
13102: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
13103: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 13104: }
13105: }
13106: $resulttext .= '</ul>';
13107: $mailmsgtext .= "\n";
13108: my $cachetime = 24*60*60;
1.72 raeburn 13109: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13110: if (ref($lastactref) eq 'HASH') {
13111: $lastactref->{'domdefaults'} = 1;
13112: }
1.68 raeburn 13113: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 13114: my $notify = 1;
13115: if (ref($domconfig{'contacts'}) eq 'HASH') {
13116: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
13117: $notify = 0;
13118: }
13119: }
13120: if ($notify) {
13121: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
13122: "LON-CAPA Domain Settings Change - $dom",
13123: $mailmsgtext);
13124: }
1.54 raeburn 13125: }
1.43 raeburn 13126: } else {
1.54 raeburn 13127: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 13128: }
13129: } else {
13130: $resulttext = '<span class="LC_error">'.
13131: &mt('An error occurred: [_1]',$putresult).'</span>';
13132: }
13133: if (@errors > 0) {
13134: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
13135: foreach my $item (@errors) {
13136: $resulttext .= ' "'.$title->{$item}.'",';
13137: }
13138: $resulttext =~ s/,$//;
13139: }
13140: return $resulttext;
13141: }
13142:
1.46 raeburn 13143: sub modify_scantron {
1.205 raeburn 13144: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 13145: my ($resulttext,%confhash,%changes,$errors);
13146: my $custom = 'custom.tab';
13147: my $default = 'default.tab';
13148: my $servadm = $r->dir_config('lonAdmEMail');
13149: my ($configuserok,$author_ok,$switchserver) =
13150: &config_check($dom,$confname,$servadm);
13151: if ($env{'form.scantronformat.filename'} ne '') {
13152: my $error;
13153: if ($configuserok eq 'ok') {
13154: if ($switchserver) {
1.130 raeburn 13155: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 13156: } else {
13157: if ($author_ok eq 'ok') {
13158: my ($result,$scantronurl) =
13159: &publishlogo($r,'upload','scantronformat',$dom,
13160: $confname,'scantron','','',$custom);
13161: if ($result eq 'ok') {
13162: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 13163: $changes{'scantronformat'} = 1;
1.46 raeburn 13164: } else {
13165: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
13166: }
13167: } else {
13168: $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);
13169: }
13170: }
13171: } else {
13172: $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);
13173: }
13174: if ($error) {
13175: &Apache::lonnet::logthis($error);
13176: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13177: }
13178: }
1.48 raeburn 13179: if (ref($domconfig{'scantron'}) eq 'HASH') {
13180: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
13181: if ($env{'form.scantronformat_del'}) {
13182: $confhash{'scantron'}{'scantronformat'} = '';
13183: $changes{'scantronformat'} = 1;
1.46 raeburn 13184: }
13185: }
13186: }
13187: if (keys(%confhash) > 0) {
13188: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
13189: $dom);
13190: if ($putresult eq 'ok') {
13191: if (keys(%changes) > 0) {
1.48 raeburn 13192: if (ref($confhash{'scantron'}) eq 'HASH') {
13193: $resulttext = &mt('Changes made:').'<ul>';
13194: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 13195: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 13196: } else {
1.130 raeburn 13197: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 13198: }
1.48 raeburn 13199: $resulttext .= '</ul>';
13200: } else {
1.130 raeburn 13201: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 13202: }
13203: $resulttext .= '</ul>';
13204: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13205: if (ref($lastactref) eq 'HASH') {
13206: $lastactref->{'domainconfig'} = 1;
13207: }
1.46 raeburn 13208: } else {
1.130 raeburn 13209: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 13210: }
13211: } else {
13212: $resulttext = '<span class="LC_error">'.
13213: &mt('An error occurred: [_1]',$putresult).'</span>';
13214: }
13215: } else {
1.130 raeburn 13216: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 13217: }
13218: if ($errors) {
13219: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13220: $errors.'</ul>';
13221: }
13222: return $resulttext;
13223: }
13224:
1.48 raeburn 13225: sub modify_coursecategories {
1.239 raeburn 13226: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 13227: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
13228: $cathash);
1.48 raeburn 13229: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 13230: my @catitems = ('unauth','auth');
13231: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 13232: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 13233: $cathash = $domconfig{'coursecategories'}{'cats'};
13234: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
13235: $changes{'togglecats'} = 1;
13236: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
13237: }
13238: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
13239: $changes{'categorize'} = 1;
13240: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
13241: }
1.120 raeburn 13242: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
13243: $changes{'togglecatscomm'} = 1;
13244: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
13245: }
13246: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
13247: $changes{'categorizecomm'} = 1;
13248: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 13249:
13250: }
13251: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
13252: $changes{'togglecatsplace'} = 1;
13253: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
13254: }
13255: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
13256: $changes{'categorizeplace'} = 1;
13257: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 13258: }
1.238 raeburn 13259: foreach my $item (@catitems) {
13260: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
13261: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
13262: $changes{$item} = 1;
13263: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
13264: }
13265: }
13266: }
1.57 raeburn 13267: } else {
13268: $changes{'togglecats'} = 1;
13269: $changes{'categorize'} = 1;
1.124 raeburn 13270: $changes{'togglecatscomm'} = 1;
13271: $changes{'categorizecomm'} = 1;
1.272 raeburn 13272: $changes{'togglecatsplace'} = 1;
13273: $changes{'categorizeplace'} = 1;
1.87 raeburn 13274: $domconfig{'coursecategories'} = {
13275: togglecats => $env{'form.togglecats'},
13276: categorize => $env{'form.categorize'},
1.124 raeburn 13277: togglecatscomm => $env{'form.togglecatscomm'},
13278: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 13279: togglecatsplace => $env{'form.togglecatsplace'},
13280: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 13281: };
1.238 raeburn 13282: foreach my $item (@catitems) {
13283: if ($env{'form.coursecat_'.$item} ne 'std') {
13284: $changes{$item} = 1;
13285: }
13286: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
13287: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
13288: }
13289: }
1.57 raeburn 13290: }
13291: if (ref($cathash) eq 'HASH') {
13292: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 13293: push (@deletecategory,'instcode::0');
13294: }
1.120 raeburn 13295: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
13296: push(@deletecategory,'communities::0');
13297: }
1.272 raeburn 13298: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
13299: push(@deletecategory,'placement::0');
13300: }
1.48 raeburn 13301: }
1.57 raeburn 13302: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
13303: if (ref($cathash) eq 'HASH') {
1.48 raeburn 13304: if (@deletecategory > 0) {
13305: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 13306: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 13307: foreach my $item (@deletecategory) {
1.57 raeburn 13308: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
13309: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 13310: $deletions{$item} = 1;
1.57 raeburn 13311: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 13312: }
13313: }
13314: }
1.57 raeburn 13315: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 13316: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 13317: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 13318: $reorderings{$item} = 1;
1.57 raeburn 13319: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 13320: }
13321: if ($env{'form.addcategory_name_'.$item} ne '') {
13322: my $newcat = $env{'form.addcategory_name_'.$item};
13323: my $newdepth = $depth+1;
13324: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 13325: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 13326: $adds{$newitem} = 1;
13327: }
13328: if ($env{'form.subcat_'.$item} ne '') {
13329: my $newcat = $env{'form.subcat_'.$item};
13330: my $newdepth = $depth+1;
13331: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 13332: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 13333: $adds{$newitem} = 1;
13334: }
13335: }
13336: }
13337: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 13338: if (ref($cathash) eq 'HASH') {
1.48 raeburn 13339: my $newitem = 'instcode::0';
1.57 raeburn 13340: if ($cathash->{$newitem} eq '') {
13341: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 13342: $adds{$newitem} = 1;
13343: }
13344: } else {
13345: my $newitem = 'instcode::0';
1.57 raeburn 13346: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 13347: $adds{$newitem} = 1;
13348: }
13349: }
1.120 raeburn 13350: if ($env{'form.communities'} eq '1') {
13351: if (ref($cathash) eq 'HASH') {
13352: my $newitem = 'communities::0';
13353: if ($cathash->{$newitem} eq '') {
13354: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13355: $adds{$newitem} = 1;
13356: }
13357: } else {
13358: my $newitem = 'communities::0';
13359: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13360: $adds{$newitem} = 1;
13361: }
13362: }
1.272 raeburn 13363: if ($env{'form.placement'} eq '1') {
13364: if (ref($cathash) eq 'HASH') {
13365: my $newitem = 'placement::0';
13366: if ($cathash->{$newitem} eq '') {
13367: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
13368: $adds{$newitem} = 1;
13369: }
13370: } else {
13371: my $newitem = 'placement::0';
13372: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
13373: $adds{$newitem} = 1;
13374: }
13375: }
1.48 raeburn 13376: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 13377: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 13378: ($env{'form.addcategory_name'} ne 'communities') &&
13379: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 13380: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
13381: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
13382: $adds{$newitem} = 1;
13383: }
1.48 raeburn 13384: }
1.57 raeburn 13385: my $putresult;
1.48 raeburn 13386: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13387: if (keys(%deletions) > 0) {
13388: foreach my $key (keys(%deletions)) {
13389: if ($predelallitems{$key} ne '') {
13390: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
13391: }
13392: }
13393: }
13394: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 13395: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 13396: if (ref($chkcats[0]) eq 'ARRAY') {
13397: my $depth = 0;
13398: my $chg = 0;
13399: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
13400: my $name = $chkcats[0][$i];
13401: my $item;
13402: if ($name eq '') {
13403: $chg ++;
13404: } else {
13405: $item = &escape($name).'::0';
13406: if ($chg) {
1.57 raeburn 13407: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 13408: }
13409: $depth ++;
1.57 raeburn 13410: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 13411: $depth --;
13412: }
13413: }
13414: }
1.57 raeburn 13415: }
13416: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13417: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 13418: if ($putresult eq 'ok') {
1.57 raeburn 13419: my %title = (
1.120 raeburn 13420: togglecats => 'Show/Hide a course in catalog',
13421: categorize => 'Assign a category to a course',
13422: togglecatscomm => 'Show/Hide a community in catalog',
13423: categorizecomm => 'Assign a category to a community',
1.57 raeburn 13424: );
13425: my %level = (
1.120 raeburn 13426: dom => 'set in Domain ("Modify Course/Community")',
13427: crs => 'set in Course ("Course Configuration")',
13428: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 13429: none => 'No catalog',
13430: std => 'Standard catalog',
13431: domonly => 'Domain-only catalog',
13432: codesrch => 'Code search form',
1.57 raeburn 13433: );
1.48 raeburn 13434: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 13435: if ($changes{'togglecats'}) {
13436: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
13437: }
13438: if ($changes{'categorize'}) {
13439: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 13440: }
1.120 raeburn 13441: if ($changes{'togglecatscomm'}) {
13442: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
13443: }
13444: if ($changes{'categorizecomm'}) {
13445: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
13446: }
1.238 raeburn 13447: if ($changes{'unauth'}) {
13448: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
13449: }
13450: if ($changes{'auth'}) {
13451: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
13452: }
1.57 raeburn 13453: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13454: my $cathash;
13455: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
13456: $cathash = $domconfig{'coursecategories'}{'cats'};
13457: } else {
13458: $cathash = {};
13459: }
13460: my (@cats,@trails,%allitems);
13461: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
13462: if (keys(%deletions) > 0) {
13463: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
13464: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
13465: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
13466: }
13467: $resulttext .= '</ul></li>';
13468: }
13469: if (keys(%reorderings) > 0) {
13470: my %sort_by_trail;
13471: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
13472: foreach my $key (keys(%reorderings)) {
13473: if ($allitems{$key} ne '') {
13474: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13475: }
1.48 raeburn 13476: }
1.57 raeburn 13477: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13478: $resulttext .= '<li>'.$trails[$trail].'</li>';
13479: }
13480: $resulttext .= '</ul></li>';
1.48 raeburn 13481: }
1.57 raeburn 13482: if (keys(%adds) > 0) {
13483: my %sort_by_trail;
13484: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
13485: foreach my $key (keys(%adds)) {
13486: if ($allitems{$key} ne '') {
13487: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13488: }
13489: }
13490: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13491: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 13492: }
1.57 raeburn 13493: $resulttext .= '</ul></li>';
1.48 raeburn 13494: }
13495: }
13496: $resulttext .= '</ul>';
1.239 raeburn 13497: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 13498: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13499: if ($changes{'auth'}) {
13500: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
13501: }
13502: if ($changes{'unauth'}) {
13503: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
13504: }
13505: my $cachetime = 24*60*60;
13506: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 13507: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 13508: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 13509: }
13510: }
1.48 raeburn 13511: } else {
13512: $resulttext = '<span class="LC_error">'.
1.57 raeburn 13513: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 13514: }
13515: } else {
1.120 raeburn 13516: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 13517: }
13518: return $resulttext;
13519: }
13520:
1.69 raeburn 13521: sub modify_serverstatuses {
13522: my ($dom,%domconfig) = @_;
13523: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
13524: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
13525: %currserverstatus = %{$domconfig{'serverstatuses'}};
13526: }
13527: my @pages = &serverstatus_pages();
13528: foreach my $type (@pages) {
13529: $newserverstatus{$type}{'namedusers'} = '';
13530: $newserverstatus{$type}{'machines'} = '';
13531: if (defined($env{'form.'.$type.'_namedusers'})) {
13532: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
13533: my @okusers;
13534: foreach my $user (@users) {
13535: my ($uname,$udom) = split(/:/,$user);
13536: if (($udom =~ /^$match_domain$/) &&
13537: (&Apache::lonnet::domain($udom)) &&
13538: ($uname =~ /^$match_username$/)) {
13539: if (!grep(/^\Q$user\E/,@okusers)) {
13540: push(@okusers,$user);
13541: }
13542: }
13543: }
13544: if (@okusers > 0) {
13545: @okusers = sort(@okusers);
13546: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
13547: }
13548: }
13549: if (defined($env{'form.'.$type.'_machines'})) {
13550: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
13551: my @okmachines;
13552: foreach my $ip (@machines) {
13553: my @parts = split(/\./,$ip);
13554: next if (@parts < 4);
13555: my $badip = 0;
13556: for (my $i=0; $i<4; $i++) {
13557: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
13558: $badip = 1;
13559: last;
13560: }
13561: }
13562: if (!$badip) {
13563: push(@okmachines,$ip);
13564: }
13565: }
13566: @okmachines = sort(@okmachines);
13567: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
13568: }
13569: }
13570: my %serverstatushash = (
13571: serverstatuses => \%newserverstatus,
13572: );
13573: foreach my $type (@pages) {
1.83 raeburn 13574: foreach my $setting ('namedusers','machines') {
1.84 raeburn 13575: my (@current,@new);
1.83 raeburn 13576: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 13577: if ($currserverstatus{$type}{$setting} ne '') {
13578: @current = split(/,/,$currserverstatus{$type}{$setting});
13579: }
13580: }
13581: if ($newserverstatus{$type}{$setting} ne '') {
13582: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 13583: }
13584: if (@current > 0) {
13585: if (@new > 0) {
13586: foreach my $item (@current) {
13587: if (!grep(/^\Q$item\E$/,@new)) {
13588: $changes{$type}{$setting} = 1;
1.82 raeburn 13589: last;
13590: }
13591: }
1.84 raeburn 13592: foreach my $item (@new) {
13593: if (!grep(/^\Q$item\E$/,@current)) {
13594: $changes{$type}{$setting} = 1;
13595: last;
1.82 raeburn 13596: }
13597: }
13598: } else {
1.83 raeburn 13599: $changes{$type}{$setting} = 1;
1.69 raeburn 13600: }
1.83 raeburn 13601: } elsif (@new > 0) {
13602: $changes{$type}{$setting} = 1;
1.69 raeburn 13603: }
13604: }
13605: }
13606: if (keys(%changes) > 0) {
1.81 raeburn 13607: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 13608: my $putresult = &Apache::lonnet::put_dom('configuration',
13609: \%serverstatushash,$dom);
13610: if ($putresult eq 'ok') {
13611: $resulttext .= &mt('Changes made:').'<ul>';
13612: foreach my $type (@pages) {
1.84 raeburn 13613: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 13614: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 13615: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 13616: if ($newserverstatus{$type}{'namedusers'} eq '') {
13617: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
13618: } else {
13619: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
13620: }
1.84 raeburn 13621: }
13622: if ($changes{$type}{'machines'}) {
1.69 raeburn 13623: if ($newserverstatus{$type}{'machines'} eq '') {
13624: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
13625: } else {
13626: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
13627: }
13628:
13629: }
13630: $resulttext .= '</ul></li>';
13631: }
13632: }
13633: $resulttext .= '</ul>';
13634: } else {
13635: $resulttext = '<span class="LC_error">'.
13636: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
13637:
13638: }
13639: } else {
13640: $resulttext = &mt('No changes made to access to server status pages');
13641: }
13642: return $resulttext;
13643: }
13644:
1.118 jms 13645: sub modify_helpsettings {
1.285 raeburn 13646: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 13647: my ($resulttext,$errors,%changes,%helphash);
13648: my %defaultchecked = ('submitbugs' => 'on');
13649: my @offon = ('off','on');
1.118 jms 13650: my @toggles = ('submitbugs');
1.285 raeburn 13651: my %current = ('submitbugs' => '',
13652: 'adhoc' => {},
13653: );
1.118 jms 13654: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 13655: %current = %{$domconfig{'helpsettings'}};
13656: }
1.285 raeburn 13657: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 13658: foreach my $item (@toggles) {
13659: if ($defaultchecked{$item} eq 'on') {
13660: if ($current{$item} eq '') {
13661: if ($env{'form.'.$item} eq '0') {
13662: $changes{$item} = 1;
13663: }
13664: } elsif ($current{$item} ne $env{'form.'.$item}) {
13665: $changes{$item} = 1;
13666: }
13667: } elsif ($defaultchecked{$item} eq 'off') {
13668: if ($current{$item} eq '') {
13669: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 13670: $changes{$item} = 1;
13671: }
1.282 raeburn 13672: } elsif ($current{$item} ne $env{'form.'.$item}) {
13673: $changes{$item} = 1;
13674: }
13675: }
13676: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
13677: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
13678: }
13679: }
1.285 raeburn 13680: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 13681: my $confname = $dom.'-domainconfig';
13682: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 13683: my (@allpos,%newsettings,%changedprivs,$newrole);
13684: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 13685: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 13686: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 13687: my %lt = &Apache::lonlocal::texthash(
13688: s => 'system',
13689: d => 'domain',
13690: order => 'Display order',
13691: access => 'Role usage',
1.291 raeburn 13692: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 13693: dh => 'All with domain helpdesk role',
13694: da => 'All with domain helpdesk assistant role',
1.285 raeburn 13695: none => 'None',
13696: status => 'Determined based on institutional status',
13697: inc => 'Include all, but exclude specific personnel',
13698: exc => 'Exclude all, but include specific personnel',
13699: );
13700: for (my $num=0; $num<=$maxnum; $num++) {
13701: my ($prefix,$identifier,$rolename,%curr);
13702: if ($num == $maxnum) {
13703: next unless ($env{'form.newcusthelp'} == $maxnum);
13704: $identifier = 'custhelp'.$num;
13705: $prefix = 'helproles_'.$num;
13706: $rolename = $env{'form.custhelpname'.$num};
13707: $rolename=~s/[^A-Za-z0-9]//gs;
13708: next if ($rolename eq '');
13709: next if (exists($existing{'rolesdef_'.$rolename}));
13710: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13711: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13712: $newprivs{'c'},$confname,$dom);
13713: if ($result ne 'ok') {
13714: $errors .= '<li><span class="LC_error">'.
13715: &mt('An error occurred storing the new custom role: [_1]',
13716: $result).'</span></li>';
13717: next;
13718: } else {
13719: $changedprivs{$rolename} = \%newprivs;
13720: $newrole = $rolename;
13721: }
13722: } else {
13723: $prefix = 'helproles_'.$num;
13724: $rolename = $env{'form.'.$prefix};
13725: next if ($rolename eq '');
13726: next unless (exists($existing{'rolesdef_'.$rolename}));
13727: $identifier = 'custhelp'.$num;
13728: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13729: my %currprivs;
1.289 raeburn 13730: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 13731: split(/\_/,$existing{'rolesdef_'.$rolename});
13732: foreach my $level ('c','d','s') {
13733: if ($newprivs{$level} ne $currprivs{$level}) {
13734: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13735: $newprivs{'c'},$confname,$dom);
13736: if ($result ne 'ok') {
13737: $errors .= '<li><span class="LC_error">'.
13738: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
13739: $rolename,$result).'</span></li>';
13740: } else {
13741: $changedprivs{$rolename} = \%newprivs;
13742: }
13743: last;
13744: }
13745: }
13746: if (ref($current{'adhoc'}) eq 'HASH') {
13747: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13748: %curr = %{$current{'adhoc'}{$rolename}};
13749: }
13750: }
13751: }
13752: my $newpos = $env{'form.'.$prefix.'_pos'};
13753: $newpos =~ s/\D+//g;
13754: $allpos[$newpos] = $rolename;
13755: my $newdesc = $env{'form.'.$prefix.'_desc'};
13756: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
13757: if ($curr{'desc'}) {
13758: if ($curr{'desc'} ne $newdesc) {
13759: $changes{'customrole'}{$rolename}{'desc'} = 1;
13760: $newsettings{$rolename}{'desc'} = $newdesc;
13761: }
13762: } elsif ($newdesc ne '') {
13763: $changes{'customrole'}{$rolename}{'desc'} = 1;
13764: $newsettings{$rolename}{'desc'} = $newdesc;
13765: }
13766: my $access = $env{'form.'.$prefix.'_access'};
13767: if (grep(/^\Q$access\E$/,@accesstypes)) {
13768: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
13769: if ($access eq 'status') {
13770: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
13771: if (scalar(@statuses) == 0) {
1.289 raeburn 13772: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 13773: } else {
13774: my (@shownstatus,$numtypes);
13775: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13776: if (ref($types) eq 'ARRAY') {
13777: $numtypes = scalar(@{$types});
13778: foreach my $type (sort(@statuses)) {
13779: if ($type eq 'default') {
13780: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13781: } elsif (grep(/^\Q$type\E$/,@{$types})) {
13782: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13783: push(@shownstatus,$usertypes->{$type});
13784: }
13785: }
13786: }
13787: if (grep(/^default$/,@statuses)) {
13788: push(@shownstatus,$othertitle);
13789: }
13790: if (scalar(@shownstatus) == 1+$numtypes) {
13791: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
13792: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
13793: } else {
13794: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
13795: if (ref($curr{'status'}) eq 'ARRAY') {
13796: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13797: if (@diffs) {
13798: $changes{'customrole'}{$rolename}{$access} = 1;
13799: }
13800: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13801: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 13802: }
1.166 raeburn 13803: }
13804: }
1.285 raeburn 13805: } elsif (($access eq 'inc') || ($access eq 'exc')) {
13806: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
13807: my @newspecstaff;
13808: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13809: foreach my $person (sort(@personnel)) {
13810: if ($domhelpdesk{$person}) {
13811: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
13812: }
13813: }
13814: if (ref($curr{$access}) eq 'ARRAY') {
13815: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13816: if (@diffs) {
13817: $changes{'customrole'}{$rolename}{$access} = 1;
13818: }
13819: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13820: $changes{'customrole'}{$rolename}{$access} = 1;
13821: }
13822: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13823: my ($uname,$udom) = split(/:/,$person);
13824: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
13825: }
13826: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 13827: }
1.285 raeburn 13828: } else {
13829: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
13830: }
13831: unless ($curr{'access'} eq $access) {
13832: $changes{'customrole'}{$rolename}{'access'} = 1;
13833: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 13834: }
13835: }
1.285 raeburn 13836: if (@allpos > 0) {
13837: my $idx = 0;
13838: foreach my $rolename (@allpos) {
13839: if ($rolename ne '') {
13840: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
13841: if (ref($current{'adhoc'}) eq 'HASH') {
13842: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13843: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
13844: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 13845: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 13846: }
13847: }
1.282 raeburn 13848: }
1.285 raeburn 13849: $idx ++;
1.166 raeburn 13850: }
13851: }
1.118 jms 13852: }
1.123 jms 13853: my $putresult;
13854: if (keys(%changes) > 0) {
1.166 raeburn 13855: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 13856: if ($putresult eq 'ok') {
1.285 raeburn 13857: if (ref($helphash{'helpsettings'}) eq 'HASH') {
13858: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
13859: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
13860: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
13861: }
13862: }
13863: my $cachetime = 24*60*60;
13864: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13865: if (ref($lastactref) eq 'HASH') {
13866: $lastactref->{'domdefaults'} = 1;
13867: }
13868: } else {
13869: $errors .= '<li><span class="LC_error">'.
13870: &mt('An error occurred storing the settings: [_1]',
13871: $putresult).'</span></li>';
13872: }
13873: }
13874: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
13875: $resulttext = &mt('Changes made:').'<ul>';
13876: my (%shownprivs,@levelorder);
13877: @levelorder = ('c','d','s');
13878: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 13879: foreach my $item (sort(keys(%changes))) {
13880: if ($item eq 'submitbugs') {
13881: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
13882: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
13883: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 13884: } elsif ($item eq 'customrole') {
13885: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 13886: my @keyorder = ('order','desc','access','status','exc','inc');
13887: my %keytext = &Apache::lonlocal::texthash(
13888: order => 'Order',
13889: desc => 'Role description',
13890: access => 'Role usage',
1.300 droeschl 13891: status => 'Allowed institutional types',
1.285 raeburn 13892: exc => 'Allowed personnel',
13893: inc => 'Disallowed personnel',
13894: );
1.282 raeburn 13895: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 13896: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
13897: if ($role eq $newrole) {
13898: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
13899: $role).'<ul>';
13900: } else {
13901: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13902: $role).'<ul>';
13903: }
13904: foreach my $key (@keyorder) {
13905: if ($changes{'customrole'}{$role}{$key}) {
13906: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
13907: $keytext{$key},$newsettings{$role}{$key}).
13908: '</li>';
13909: }
13910: }
13911: if (ref($changedprivs{$role}) eq 'HASH') {
13912: $shownprivs{$role} = 1;
13913: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
13914: foreach my $level (@levelorder) {
13915: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13916: next if ($item eq '');
13917: my ($priv) = split(/\&/,$item,2);
13918: if (&Apache::lonnet::plaintext($priv)) {
13919: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13920: unless ($level eq 'c') {
13921: $resulttext .= ' ('.$lt{$level}.')';
13922: }
13923: $resulttext .= '</li>';
13924: }
13925: }
13926: }
13927: $resulttext .= '</ul>';
13928: }
13929: $resulttext .= '</ul></li>';
13930: }
13931: }
13932: }
13933: }
13934: }
13935: }
13936: if (keys(%changedprivs)) {
13937: foreach my $role (sort(keys(%changedprivs))) {
13938: unless ($shownprivs{$role}) {
13939: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13940: $role).'<ul>'.
13941: '<li>'.&mt('Privileges set to :').'<ul>';
13942: foreach my $level (@levelorder) {
13943: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13944: next if ($item eq '');
13945: my ($priv) = split(/\&/,$item,2);
13946: if (&Apache::lonnet::plaintext($priv)) {
13947: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13948: unless ($level eq 'c') {
13949: $resulttext .= ' ('.$lt{$level}.')';
13950: }
13951: $resulttext .= '</li>';
13952: }
1.282 raeburn 13953: }
13954: }
1.285 raeburn 13955: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 13956: }
13957: }
13958: }
1.285 raeburn 13959: $resulttext .= '</ul>';
13960: } else {
13961: $resulttext = &mt('No changes made to help settings');
1.118 jms 13962: }
13963: if ($errors) {
1.168 raeburn 13964: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 13965: $errors.'</ul>';
1.118 jms 13966: }
13967: return $resulttext;
13968: }
13969:
1.121 raeburn 13970: sub modify_coursedefaults {
1.212 raeburn 13971: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 13972: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 13973: my %defaultchecked = (
13974: 'canuse_pdfforms' => 'off',
13975: 'uselcmath' => 'on',
13976: 'usejsme' => 'on'
13977: );
13978: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 13979: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 13980: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
13981: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
13982: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 13983: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 13984: my %staticdefaults = (
13985: anonsurvey_threshold => 10,
13986: uploadquota => 500,
1.257 raeburn 13987: postsubmit => 60,
1.276 raeburn 13988: mysqltables => 172800,
1.198 raeburn 13989: );
1.314 raeburn 13990: my %texoptions = (
13991: MathJax => 'MathJax',
13992: mimetex => &mt('Convert to Images'),
13993: tth => &mt('TeX to HTML'),
13994: );
1.121 raeburn 13995: $defaultshash{'coursedefaults'} = {};
13996:
13997: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13998: if ($domconfig{'coursedefaults'} eq '') {
13999: $domconfig{'coursedefaults'} = {};
14000: }
14001: }
14002:
14003: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
14004: foreach my $item (@toggles) {
14005: if ($defaultchecked{$item} eq 'on') {
14006: if (($domconfig{'coursedefaults'}{$item} eq '') &&
14007: ($env{'form.'.$item} eq '0')) {
14008: $changes{$item} = 1;
1.192 raeburn 14009: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 14010: $changes{$item} = 1;
14011: }
14012: } elsif ($defaultchecked{$item} eq 'off') {
14013: if (($domconfig{'coursedefaults'}{$item} eq '') &&
14014: ($env{'form.'.$item} eq '1')) {
14015: $changes{$item} = 1;
14016: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
14017: $changes{$item} = 1;
14018: }
14019: }
14020: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
14021: }
1.198 raeburn 14022: foreach my $item (@numbers) {
14023: my ($currdef,$newdef);
1.208 raeburn 14024: $newdef = $env{'form.'.$item};
1.198 raeburn 14025: if ($item eq 'anonsurvey_threshold') {
14026: $currdef = $domconfig{'coursedefaults'}{$item};
14027: $newdef =~ s/\D//g;
14028: if ($newdef eq '' || $newdef < 1) {
14029: $newdef = 1;
14030: }
14031: $defaultshash{'coursedefaults'}{$item} = $newdef;
14032: } else {
1.276 raeburn 14033: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
14034: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
14035: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 14036: }
14037: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 14038: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 14039: }
14040: if ($currdef ne $newdef) {
14041: my $staticdef;
14042: if ($item eq 'anonsurvey_threshold') {
14043: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
14044: $changes{$item} = 1;
14045: }
1.276 raeburn 14046: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 14047: my $setting = $1;
1.276 raeburn 14048: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
14049: $changes{$setting} = 1;
1.198 raeburn 14050: }
14051: }
1.139 raeburn 14052: }
14053: }
1.314 raeburn 14054: my $texengine;
14055: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
14056: $texengine = $env{'form.texengine'};
14057: if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {
14058: unless ($texengine eq 'MathJax') {
14059: $changes{'texengine'} = 1;
14060: }
14061: } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {
14062: $changes{'texengine'} = 1;
14063: }
14064: }
14065: if ($texengine ne '') {
14066: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
14067: }
1.264 raeburn 14068: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
14069: my @currclonecode;
14070: if (ref($currclone) eq 'HASH') {
14071: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
14072: @currclonecode = @{$currclone->{'instcode'}};
14073: }
14074: }
14075: my $newclone;
1.289 raeburn 14076: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 14077: $newclone = $env{'form.canclone'};
14078: }
14079: if ($newclone eq 'instcode') {
14080: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
14081: my (%codedefaults,@code_order,@clonecode);
14082: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
14083: \@code_order);
14084: foreach my $item (@code_order) {
14085: if (grep(/^\Q$item\E$/,@newcodes)) {
14086: push(@clonecode,$item);
14087: }
14088: }
14089: if (@clonecode) {
14090: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
14091: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
14092: if (@diffs) {
14093: $changes{'canclone'} = 1;
14094: }
14095: } else {
14096: $newclone eq '';
14097: }
14098: } elsif ($newclone ne '') {
1.289 raeburn 14099: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
14100: }
1.264 raeburn 14101: if ($newclone ne $currclone) {
14102: $changes{'canclone'} = 1;
14103: }
1.257 raeburn 14104: my %credits;
14105: foreach my $type (@types) {
14106: unless ($type eq 'community') {
14107: $credits{$type} = $env{'form.'.$type.'_credits'};
14108: $credits{$type} =~ s/[^\d.]+//g;
14109: }
14110: }
14111: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
14112: ($env{'form.coursecredits'} eq '1')) {
14113: $changes{'coursecredits'} = 1;
14114: foreach my $type (keys(%credits)) {
14115: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
14116: }
14117: } else {
1.289 raeburn 14118: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 14119: foreach my $type (@types) {
14120: unless ($type eq 'community') {
1.289 raeburn 14121: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 14122: $changes{'coursecredits'} = 1;
14123: }
14124: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
14125: }
14126: }
14127: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
14128: foreach my $type (@types) {
14129: unless ($type eq 'community') {
14130: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
14131: $changes{'coursecredits'} = 1;
14132: last;
14133: }
14134: }
14135: }
14136: }
14137: }
14138: if ($env{'form.postsubmit'} eq '1') {
14139: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
14140: my %currtimeout;
14141: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
14142: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
14143: $changes{'postsubmit'} = 1;
14144: }
14145: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
14146: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
14147: }
14148: } else {
14149: $changes{'postsubmit'} = 1;
14150: }
14151: foreach my $type (@types) {
14152: my $timeout = $env{'form.'.$type.'_timeout'};
14153: $timeout =~ s/\D//g;
14154: if ($timeout == $staticdefaults{'postsubmit'}) {
14155: $timeout = '';
14156: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
14157: $timeout = '0';
14158: }
14159: unless ($timeout eq '') {
14160: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
14161: }
14162: if (exists($currtimeout{$type})) {
14163: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 14164: $changes{'postsubmit'} = 1;
1.257 raeburn 14165: }
14166: } elsif ($timeout ne '') {
14167: $changes{'postsubmit'} = 1;
14168: }
14169: }
14170: } else {
14171: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
14172: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
14173: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
14174: $changes{'postsubmit'} = 1;
14175: }
14176: } else {
14177: $changes{'postsubmit'} = 1;
14178: }
1.192 raeburn 14179: }
1.121 raeburn 14180: }
14181: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14182: $dom);
14183: if ($putresult eq 'ok') {
14184: if (keys(%changes) > 0) {
1.213 raeburn 14185: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 14186: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 14187: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314 raeburn 14188: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
14189: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257 raeburn 14190: if ($changes{$item}) {
14191: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
14192: }
1.289 raeburn 14193: }
1.192 raeburn 14194: if ($changes{'coursecredits'}) {
14195: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 14196: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
14197: $domdefaults{$type.'credits'} =
14198: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
14199: }
14200: }
14201: }
14202: if ($changes{'postsubmit'}) {
14203: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
14204: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
14205: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
14206: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
14207: $domdefaults{$type.'postsubtimeout'} =
14208: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
14209: }
14210: }
1.192 raeburn 14211: }
14212: }
1.198 raeburn 14213: if ($changes{'uploadquota'}) {
14214: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
14215: foreach my $type (@types) {
14216: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
14217: }
14218: }
14219: }
1.264 raeburn 14220: if ($changes{'canclone'}) {
14221: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
14222: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
14223: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
14224: if (@clonecodes) {
14225: $domdefaults{'canclone'} = join('+',@clonecodes);
14226: }
14227: }
14228: } else {
14229: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
14230: }
14231: }
1.121 raeburn 14232: my $cachetime = 24*60*60;
14233: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14234: if (ref($lastactref) eq 'HASH') {
14235: $lastactref->{'domdefaults'} = 1;
14236: }
1.121 raeburn 14237: }
14238: $resulttext = &mt('Changes made:').'<ul>';
14239: foreach my $item (sort(keys(%changes))) {
14240: if ($item eq 'canuse_pdfforms') {
14241: if ($env{'form.'.$item} eq '1') {
14242: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
14243: } else {
14244: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
14245: }
1.257 raeburn 14246: } elsif ($item eq 'uselcmath') {
14247: if ($env{'form.'.$item} eq '1') {
14248: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
14249: } else {
14250: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
14251: }
14252: } elsif ($item eq 'usejsme') {
14253: if ($env{'form.'.$item} eq '1') {
14254: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
14255: } else {
1.289 raeburn 14256: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 14257: }
1.314 raeburn 14258: } elsif ($item eq 'texengine') {
14259: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
14260: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
14261: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
14262: }
1.139 raeburn 14263: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 14264: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 14265: } elsif ($item eq 'uploadquota') {
14266: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
14267: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
14268: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
14269: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 14270: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 14271: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 14272: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
14273: '</ul>'.
14274: '</li>';
14275: } else {
14276: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
14277: }
1.276 raeburn 14278: } elsif ($item eq 'mysqltables') {
14279: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
14280: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
14281: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
14282: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
14283: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
14284: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
14285: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
14286: '</ul>'.
14287: '</li>';
14288: } else {
14289: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
14290: }
1.257 raeburn 14291: } elsif ($item eq 'postsubmit') {
14292: if ($domdefaults{'postsubmit'} eq 'off') {
14293: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
14294: } else {
14295: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 14296: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 14297: $resulttext .= &mt('durations:').'<ul>';
14298: foreach my $type (@types) {
14299: $resulttext .= '<li>';
14300: my $timeout;
14301: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
14302: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
14303: }
14304: my $display;
14305: if ($timeout eq '0') {
14306: $display = &mt('unlimited');
14307: } elsif ($timeout eq '') {
14308: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
14309: } else {
14310: $display = &mt('[quant,_1,second]',$timeout);
14311: }
14312: if ($type eq 'community') {
14313: $resulttext .= &mt('Communities');
14314: } elsif ($type eq 'official') {
14315: $resulttext .= &mt('Official courses');
14316: } elsif ($type eq 'unofficial') {
14317: $resulttext .= &mt('Unofficial courses');
14318: } elsif ($type eq 'textbook') {
14319: $resulttext .= &mt('Textbook courses');
1.271 raeburn 14320: } elsif ($type eq 'placement') {
14321: $resulttext .= &mt('Placement tests');
1.257 raeburn 14322: }
14323: $resulttext .= ' -- '.$display.'</li>';
14324: }
14325: $resulttext .= '</ul>';
14326: }
1.289 raeburn 14327: $resulttext .= '</li>';
1.257 raeburn 14328: }
1.192 raeburn 14329: } elsif ($item eq 'coursecredits') {
14330: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
14331: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 14332: ($domdefaults{'unofficialcredits'} eq '') &&
14333: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 14334: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
14335: } else {
14336: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
14337: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
14338: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 14339: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 14340: '</ul>'.
14341: '</li>';
14342: }
14343: } else {
14344: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
14345: }
1.264 raeburn 14346: } elsif ($item eq 'canclone') {
14347: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
14348: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
14349: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
14350: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
14351: }
14352: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
14353: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
14354: } else {
1.289 raeburn 14355: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 14356: }
1.140 raeburn 14357: }
1.121 raeburn 14358: }
14359: $resulttext .= '</ul>';
14360: } else {
14361: $resulttext = &mt('No changes made to course defaults');
14362: }
14363: } else {
14364: $resulttext = '<span class="LC_error">'.
14365: &mt('An error occurred: [_1]',$putresult).'</span>';
14366: }
14367: return $resulttext;
14368: }
14369:
1.231 raeburn 14370: sub modify_selfenrollment {
14371: my ($dom,$lastactref,%domconfig) = @_;
14372: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 14373: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 14374: my %titles = &tool_titles();
1.232 raeburn 14375: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
14376: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 14377: $ordered{'default'} = ['types','registered','approval','limit'];
14378:
14379: my (%roles,%shown,%toplevel);
14380: $roles{'0'} = &Apache::lonnet::plaintext('dc');
14381:
14382: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
14383: if ($domconfig{'selfenrollment'} eq '') {
14384: $domconfig{'selfenrollment'} = {};
14385: }
14386: }
14387: %toplevel = (
14388: admin => 'Configuration Rights',
14389: default => 'Default settings',
14390: validation => 'Validation of self-enrollment requests',
14391: );
1.233 raeburn 14392: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 14393:
14394: if (ref($ordered{'admin'}) eq 'ARRAY') {
14395: foreach my $item (@{$ordered{'admin'}}) {
14396: foreach my $type (@types) {
14397: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
14398: $selfenrollhash{'admin'}{$type}{$item} = 1;
14399: } else {
14400: $selfenrollhash{'admin'}{$type}{$item} = 0;
14401: }
14402: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
14403: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
14404: if ($selfenrollhash{'admin'}{$type}{$item} ne
14405: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
14406: push(@{$changes{'admin'}{$type}},$item);
14407: }
14408: } else {
14409: if (!$selfenrollhash{'admin'}{$type}{$item}) {
14410: push(@{$changes{'admin'}{$type}},$item);
14411: }
14412: }
14413: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
14414: push(@{$changes{'admin'}{$type}},$item);
14415: }
14416: }
14417: }
14418: }
14419:
14420: foreach my $item (@{$ordered{'default'}}) {
14421: foreach my $type (@types) {
14422: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
14423: if ($item eq 'types') {
14424: unless (($value eq 'all') || ($value eq 'dom')) {
14425: $value = '';
14426: }
14427: } elsif ($item eq 'registered') {
14428: unless ($value eq '1') {
14429: $value = 0;
14430: }
14431: } elsif ($item eq 'approval') {
14432: unless ($value =~ /^[012]$/) {
14433: $value = 0;
14434: }
14435: } else {
14436: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14437: $value = 'none';
14438: }
14439: }
14440: $selfenrollhash{'default'}{$type}{$item} = $value;
14441: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
14442: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14443: if ($selfenrollhash{'default'}{$type}{$item} ne
14444: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
14445: push(@{$changes{'default'}{$type}},$item);
14446: }
14447: } else {
14448: push(@{$changes{'default'}{$type}},$item);
14449: }
14450: } else {
14451: push(@{$changes{'default'}{$type}},$item);
14452: }
14453: if ($item eq 'limit') {
14454: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14455: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
14456: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
14457: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
14458: }
14459: } else {
14460: $selfenrollhash{'default'}{$type}{'cap'} = '';
14461: }
14462: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14463: if ($selfenrollhash{'default'}{$type}{'cap'} ne
14464: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
14465: push(@{$changes{'default'}{$type}},'cap');
14466: }
14467: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
14468: push(@{$changes{'default'}{$type}},'cap');
14469: }
14470: }
14471: }
14472: }
14473:
14474: foreach my $item (@{$itemsref}) {
14475: if ($item eq 'fields') {
14476: my @changed;
14477: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
14478: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
14479: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
14480: }
14481: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14482: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
14483: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
14484: $domconfig{'selfenrollment'}{'validation'}{$item});
14485: } else {
14486: @changed = @{$selfenrollhash{'validation'}{$item}};
14487: }
14488: } else {
14489: @changed = @{$selfenrollhash{'validation'}{$item}};
14490: }
14491: if (@changed) {
14492: if ($selfenrollhash{'validation'}{$item}) {
14493: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
14494: } else {
14495: $changes{'validation'}{$item} = &mt('None');
14496: }
14497: }
14498: } else {
14499: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
14500: if ($item eq 'markup') {
14501: if ($env{'form.selfenroll_validation_'.$item}) {
14502: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14503: }
14504: }
14505: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14506: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
14507: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
14508: }
14509: }
14510: }
14511: }
14512:
14513: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
14514: $dom);
14515: if ($putresult eq 'ok') {
14516: if (keys(%changes) > 0) {
14517: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14518: $resulttext = &mt('Changes made:').'<ul>';
14519: foreach my $key ('admin','default','validation') {
14520: if (ref($changes{$key}) eq 'HASH') {
14521: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
14522: if ($key eq 'validation') {
14523: foreach my $item (@{$itemsref}) {
14524: if (exists($changes{$key}{$item})) {
14525: if ($item eq 'markup') {
14526: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14527: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
14528: } else {
14529: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14530: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
14531: }
14532: }
14533: }
14534: } else {
14535: foreach my $type (@types) {
14536: if ($type eq 'community') {
14537: $roles{'1'} = &mt('Community personnel');
14538: } else {
14539: $roles{'1'} = &mt('Course personnel');
14540: }
14541: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 14542: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14543: if ($key eq 'admin') {
14544: my @mgrdc = ();
14545: if (ref($ordered{$key}) eq 'ARRAY') {
14546: foreach my $item (@{$ordered{'admin'}}) {
14547: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14548: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
14549: push(@mgrdc,$item);
14550: }
14551: }
14552: }
14553: if (@mgrdc) {
14554: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
14555: } else {
14556: delete($domdefaults{$type.'selfenrolladmdc'});
14557: }
14558: }
14559: } else {
14560: if (ref($ordered{$key}) eq 'ARRAY') {
14561: foreach my $item (@{$ordered{$key}}) {
14562: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14563: $domdefaults{$type.'selfenroll'.$item} =
14564: $selfenrollhash{$key}{$type}{$item};
14565: }
14566: }
14567: }
14568: }
14569: }
1.231 raeburn 14570: $resulttext .= '<li>'.$titles{$type}.'<ul>';
14571: foreach my $item (@{$ordered{$key}}) {
14572: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14573: $resulttext .= '<li>';
14574: if ($key eq 'admin') {
14575: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
14576: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
14577: } else {
14578: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
14579: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
14580: }
14581: $resulttext .= '</li>';
14582: }
14583: }
14584: $resulttext .= '</ul></li>';
14585: }
14586: }
14587: $resulttext .= '</ul></li>';
14588: }
14589: }
1.305 raeburn 14590: }
14591: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
14592: my $cachetime = 24*60*60;
14593: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14594: if (ref($lastactref) eq 'HASH') {
14595: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 14596: }
1.231 raeburn 14597: }
14598: $resulttext .= '</ul>';
14599: } else {
14600: $resulttext = &mt('No changes made to self-enrollment settings');
14601: }
14602: } else {
14603: $resulttext = '<span class="LC_error">'.
14604: &mt('An error occurred: [_1]',$putresult).'</span>';
14605: }
14606: return $resulttext;
14607: }
14608:
1.137 raeburn 14609: sub modify_usersessions {
1.212 raeburn 14610: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 14611: my @hostingtypes = ('version','excludedomain','includedomain');
14612: my @offloadtypes = ('primary','default');
14613: my %types = (
14614: remote => \@hostingtypes,
14615: hosted => \@hostingtypes,
14616: spares => \@offloadtypes,
14617: );
14618: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 14619: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 14620: my (%by_ip,%by_location,@intdoms,@instdoms);
14621: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 14622: my @locations = sort(keys(%by_location));
1.137 raeburn 14623: my (%defaultshash,%changes);
14624: foreach my $prefix (@prefixes) {
14625: $defaultshash{'usersessions'}{$prefix} = {};
14626: }
1.212 raeburn 14627: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 14628: my $resulttext;
1.138 raeburn 14629: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 14630: foreach my $prefix (@prefixes) {
1.145 raeburn 14631: next if ($prefix eq 'spares');
14632: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 14633: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14634: if ($type eq 'version') {
14635: my $value = $env{'form.'.$prefix.'_'.$type};
14636: my $okvalue;
14637: if ($value ne '') {
14638: if (grep(/^\Q$value\E$/,@lcversions)) {
14639: $okvalue = $value;
14640: }
14641: }
14642: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14643: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14644: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
14645: if ($inuse == 0) {
14646: $changes{$prefix}{$type} = 1;
14647: } else {
14648: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
14649: $changes{$prefix}{$type} = 1;
14650: }
14651: if ($okvalue ne '') {
14652: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14653: }
14654: }
14655: } else {
14656: if (($inuse == 1) && ($okvalue ne '')) {
14657: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14658: $changes{$prefix}{$type} = 1;
14659: }
14660: }
14661: } else {
14662: if (($inuse == 1) && ($okvalue ne '')) {
14663: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14664: $changes{$prefix}{$type} = 1;
14665: }
14666: }
14667: } else {
14668: if (($inuse == 1) && ($okvalue ne '')) {
14669: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14670: $changes{$prefix}{$type} = 1;
14671: }
14672: }
14673: } else {
14674: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14675: my @okvals;
14676: foreach my $val (@vals) {
1.138 raeburn 14677: if ($val =~ /:/) {
14678: my @items = split(/:/,$val);
14679: foreach my $item (@items) {
14680: if (ref($by_location{$item}) eq 'ARRAY') {
14681: push(@okvals,$item);
14682: }
14683: }
14684: } else {
14685: if (ref($by_location{$val}) eq 'ARRAY') {
14686: push(@okvals,$val);
14687: }
1.137 raeburn 14688: }
14689: }
14690: @okvals = sort(@okvals);
14691: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14692: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14693: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14694: if ($inuse == 0) {
14695: $changes{$prefix}{$type} = 1;
14696: } else {
14697: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14698: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
14699: if (@changed > 0) {
14700: $changes{$prefix}{$type} = 1;
14701: }
14702: }
14703: } else {
14704: if ($inuse == 1) {
14705: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14706: $changes{$prefix}{$type} = 1;
14707: }
14708: }
14709: } else {
14710: if ($inuse == 1) {
14711: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14712: $changes{$prefix}{$type} = 1;
14713: }
14714: }
14715: } else {
14716: if ($inuse == 1) {
14717: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14718: $changes{$prefix}{$type} = 1;
14719: }
14720: }
14721: }
14722: }
14723: }
1.145 raeburn 14724:
14725: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 14726: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 14727: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
14728: my $savespares;
14729:
14730: foreach my $lonhost (sort(keys(%servers))) {
14731: my $serverhomeID =
14732: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 14733: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 14734: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
14735: my %spareschg;
14736: foreach my $type (@{$types{'spares'}}) {
14737: my @okspares;
14738: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
14739: foreach my $server (@checked) {
1.152 raeburn 14740: if (&Apache::lonnet::hostname($server) ne '') {
14741: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
14742: unless (grep(/^\Q$server\E$/,@okspares)) {
14743: push(@okspares,$server);
14744: }
1.145 raeburn 14745: }
14746: }
14747: }
14748: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
14749: my $newspare;
1.152 raeburn 14750: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
14751: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 14752: $newspare = $new;
14753: }
14754: }
1.152 raeburn 14755: my @spares;
14756: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
14757: @spares = sort(@okspares,$newspare);
14758: } else {
14759: @spares = sort(@okspares);
14760: }
14761: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 14762: if (ref($spareid{$lonhost}) eq 'HASH') {
14763: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 14764: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 14765: if (@diffs > 0) {
14766: $spareschg{$type} = 1;
14767: }
14768: }
14769: }
14770: }
14771: if (keys(%spareschg) > 0) {
14772: $changes{'spares'}{$lonhost} = \%spareschg;
14773: }
14774: }
1.261 raeburn 14775: $defaultshash{'usersessions'}{'offloadnow'} = {};
14776: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
14777: my @okoffload;
14778: if (@offloadnow) {
14779: foreach my $server (@offloadnow) {
14780: if (&Apache::lonnet::hostname($server) ne '') {
14781: unless (grep(/^\Q$server\E$/,@okoffload)) {
14782: push(@okoffload,$server);
14783: }
14784: }
14785: }
14786: if (@okoffload) {
14787: foreach my $lonhost (@okoffload) {
14788: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
14789: }
14790: }
14791: }
1.145 raeburn 14792: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14793: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
14794: if (ref($changes{'spares'}) eq 'HASH') {
14795: if (keys(%{$changes{'spares'}}) > 0) {
14796: $savespares = 1;
14797: }
14798: }
14799: } else {
14800: $savespares = 1;
14801: }
1.261 raeburn 14802: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
14803: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
14804: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
14805: $changes{'offloadnow'} = 1;
14806: last;
14807: }
14808: }
14809: unless ($changes{'offloadnow'}) {
1.289 raeburn 14810: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 14811: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
14812: $changes{'offloadnow'} = 1;
14813: last;
14814: }
14815: }
14816: }
14817: } elsif (@okoffload) {
14818: $changes{'offloadnow'} = 1;
14819: }
14820: } elsif (@okoffload) {
14821: $changes{'offloadnow'} = 1;
1.145 raeburn 14822: }
1.147 raeburn 14823: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
14824: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 14825: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14826: $dom);
14827: if ($putresult eq 'ok') {
14828: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14829: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
14830: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
14831: }
14832: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
14833: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
14834: }
1.261 raeburn 14835: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14836: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
14837: }
1.137 raeburn 14838: }
14839: my $cachetime = 24*60*60;
14840: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 14841: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 14842: if (ref($lastactref) eq 'HASH') {
14843: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 14844: $lastactref->{'usersessions'} = 1;
1.212 raeburn 14845: }
1.147 raeburn 14846: if (keys(%changes) > 0) {
14847: my %lt = &usersession_titles();
14848: $resulttext = &mt('Changes made:').'<ul>';
14849: foreach my $prefix (@prefixes) {
14850: if (ref($changes{$prefix}) eq 'HASH') {
14851: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14852: if ($prefix eq 'spares') {
14853: if (ref($changes{$prefix}) eq 'HASH') {
14854: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
14855: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 14856: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 14857: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
14858: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 14859: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
14860: foreach my $type (@{$types{$prefix}}) {
14861: if ($changes{$prefix}{$lonhost}{$type}) {
14862: my $offloadto = &mt('None');
14863: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
14864: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
14865: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
14866: }
1.145 raeburn 14867: }
1.147 raeburn 14868: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 14869: }
1.137 raeburn 14870: }
14871: }
1.147 raeburn 14872: $resulttext .= '</li>';
1.137 raeburn 14873: }
14874: }
1.147 raeburn 14875: } else {
14876: foreach my $type (@{$types{$prefix}}) {
14877: if (defined($changes{$prefix}{$type})) {
14878: my $newvalue;
14879: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14880: if (ref($defaultshash{'usersessions'}{$prefix})) {
14881: if ($type eq 'version') {
14882: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
14883: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14884: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
14885: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
14886: }
1.145 raeburn 14887: }
14888: }
14889: }
1.147 raeburn 14890: if ($newvalue eq '') {
14891: if ($type eq 'version') {
14892: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
14893: } else {
14894: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14895: }
1.145 raeburn 14896: } else {
1.147 raeburn 14897: if ($type eq 'version') {
14898: $newvalue .= ' '.&mt('(or later)');
14899: }
14900: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 14901: }
1.137 raeburn 14902: }
14903: }
14904: }
1.147 raeburn 14905: $resulttext .= '</ul>';
1.137 raeburn 14906: }
14907: }
1.261 raeburn 14908: if ($changes{'offloadnow'}) {
14909: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14910: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
14911: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
14912: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
14913: $resulttext .= '<li>'.$lonhost.'</li>';
14914: }
14915: $resulttext .= '</ul>';
14916: } else {
14917: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
14918: }
14919: } else {
14920: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
14921: }
14922: }
1.147 raeburn 14923: $resulttext .= '</ul>';
14924: } else {
14925: $resulttext = $nochgmsg;
1.137 raeburn 14926: }
14927: } else {
14928: $resulttext = '<span class="LC_error">'.
14929: &mt('An error occurred: [_1]',$putresult).'</span>';
14930: }
14931: } else {
1.147 raeburn 14932: $resulttext = $nochgmsg;
1.137 raeburn 14933: }
14934: return $resulttext;
14935: }
14936:
1.275 raeburn 14937: sub modify_ssl {
14938: my ($dom,$lastactref,%domconfig) = @_;
14939: my (%by_ip,%by_location,@intdoms,@instdoms);
14940: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14941: my @locations = sort(keys(%by_location));
14942: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14943: my (%defaultshash,%changes);
14944: my $action = 'ssl';
1.293 raeburn 14945: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 14946: foreach my $prefix (@prefixes) {
14947: $defaultshash{$action}{$prefix} = {};
14948: }
14949: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14950: my $resulttext;
14951: my %iphost = &Apache::lonnet::get_iphost();
14952: my @reptypes = ('certreq','nocertreq');
14953: my @connecttypes = ('dom','intdom','other');
14954: my %types = (
1.293 raeburn 14955: connto => \@connecttypes,
14956: connfrom => \@connecttypes,
14957: replication => \@reptypes,
1.275 raeburn 14958: );
14959: foreach my $prefix (sort(keys(%types))) {
14960: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 14961: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14962: my $value = 'yes';
14963: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
14964: $value = $env{'form.'.$prefix.'_'.$type};
14965: }
14966: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14967: if ($domconfig{$action}{$prefix}{$type} ne '') {
14968: if ($value ne $domconfig{$action}{$prefix}{$type}) {
14969: $changes{$prefix}{$type} = 1;
14970: }
14971: $defaultshash{$action}{$prefix}{$type} = $value;
14972: } else {
14973: $defaultshash{$action}{$prefix}{$type} = $value;
14974: $changes{$prefix}{$type} = 1;
14975: }
14976: } else {
14977: $defaultshash{$action}{$prefix}{$type} = $value;
14978: $changes{$prefix}{$type} = 1;
14979: }
14980: if (($type eq 'dom') && (keys(%servers) == 1)) {
14981: delete($changes{$prefix}{$type});
14982: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
14983: delete($changes{$prefix}{$type});
14984: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
14985: delete($changes{$prefix}{$type});
14986: }
14987: } elsif ($prefix eq 'replication') {
14988: if (@locations > 0) {
14989: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14990: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14991: my @okvals;
14992: foreach my $val (@vals) {
14993: if ($val =~ /:/) {
14994: my @items = split(/:/,$val);
14995: foreach my $item (@items) {
14996: if (ref($by_location{$item}) eq 'ARRAY') {
14997: push(@okvals,$item);
14998: }
14999: }
15000: } else {
15001: if (ref($by_location{$val}) eq 'ARRAY') {
15002: push(@okvals,$val);
15003: }
15004: }
15005: }
15006: @okvals = sort(@okvals);
15007: if (ref($domconfig{$action}) eq 'HASH') {
15008: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
15009: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
15010: if ($inuse == 0) {
15011: $changes{$prefix}{$type} = 1;
15012: } else {
15013: $defaultshash{$action}{$prefix}{$type} = \@okvals;
15014: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
15015: if (@changed > 0) {
15016: $changes{$prefix}{$type} = 1;
15017: }
15018: }
15019: } else {
15020: if ($inuse == 1) {
15021: $defaultshash{$action}{$prefix}{$type} = \@okvals;
15022: $changes{$prefix}{$type} = 1;
15023: }
15024: }
15025: } else {
15026: if ($inuse == 1) {
15027: $defaultshash{$action}{$prefix}{$type} = \@okvals;
15028: $changes{$prefix}{$type} = 1;
15029: }
15030: }
15031: } else {
15032: if ($inuse == 1) {
15033: $defaultshash{$action}{$prefix}{$type} = \@okvals;
15034: $changes{$prefix}{$type} = 1;
15035: }
15036: }
15037: }
15038: }
15039: }
15040: }
15041: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
15042: if (keys(%changes) > 0) {
15043: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15044: $dom);
15045: if ($putresult eq 'ok') {
15046: if (ref($defaultshash{$action}) eq 'HASH') {
15047: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
15048: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
15049: }
1.293 raeburn 15050: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
15051: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
15052: }
15053: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
15054: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 15055: }
15056: }
15057: my $cachetime = 24*60*60;
15058: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15059: if (ref($lastactref) eq 'HASH') {
15060: $lastactref->{'domdefaults'} = 1;
15061: }
15062: if (keys(%changes) > 0) {
15063: my %titles = &ssl_titles();
15064: $resulttext = &mt('Changes made:').'<ul>';
15065: foreach my $prefix (@prefixes) {
15066: if (ref($changes{$prefix}) eq 'HASH') {
15067: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
15068: foreach my $type (@{$types{$prefix}}) {
15069: if (defined($changes{$prefix}{$type})) {
15070: my $newvalue;
15071: if (ref($defaultshash{$action}) eq 'HASH') {
15072: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 15073: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 15074: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
15075: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
15076: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
15077: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
15078: }
15079: }
15080: }
15081: if ($newvalue eq '') {
15082: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
15083: } else {
15084: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
15085: }
15086: }
15087: }
15088: }
15089: $resulttext .= '</ul>';
15090: }
15091: }
15092: } else {
15093: $resulttext = $nochgmsg;
15094: }
15095: } else {
15096: $resulttext = '<span class="LC_error">'.
15097: &mt('An error occurred: [_1]',$putresult).'</span>';
15098: }
15099: } else {
15100: $resulttext = $nochgmsg;
15101: }
15102: return $resulttext;
15103: }
15104:
1.279 raeburn 15105: sub modify_trust {
15106: my ($dom,$lastactref,%domconfig) = @_;
15107: my (%by_ip,%by_location,@intdoms,@instdoms);
15108: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
15109: my @locations = sort(keys(%by_location));
15110: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
15111: my @types = ('exc','inc');
15112: my (%defaultshash,%changes);
15113: foreach my $prefix (@prefixes) {
15114: $defaultshash{'trust'}{$prefix} = {};
15115: }
15116: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15117: my $resulttext;
15118: foreach my $prefix (@prefixes) {
15119: foreach my $type (@types) {
15120: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
15121: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
15122: my @okvals;
15123: foreach my $val (@vals) {
15124: if ($val =~ /:/) {
15125: my @items = split(/:/,$val);
15126: foreach my $item (@items) {
15127: if (ref($by_location{$item}) eq 'ARRAY') {
15128: push(@okvals,$item);
15129: }
15130: }
15131: } else {
15132: if (ref($by_location{$val}) eq 'ARRAY') {
15133: push(@okvals,$val);
15134: }
15135: }
15136: }
15137: @okvals = sort(@okvals);
15138: if (ref($domconfig{'trust'}) eq 'HASH') {
15139: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
15140: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
15141: if ($inuse == 0) {
15142: $changes{$prefix}{$type} = 1;
15143: } else {
15144: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
15145: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
15146: if (@changed > 0) {
15147: $changes{$prefix}{$type} = 1;
15148: }
15149: }
15150: } else {
15151: if ($inuse == 1) {
15152: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
15153: $changes{$prefix}{$type} = 1;
15154: }
15155: }
15156: } else {
15157: if ($inuse == 1) {
15158: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
15159: $changes{$prefix}{$type} = 1;
15160: }
15161: }
15162: } else {
15163: if ($inuse == 1) {
15164: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
15165: $changes{$prefix}{$type} = 1;
15166: }
15167: }
15168: }
15169: }
15170: my $nochgmsg = &mt('No changes made to trust settings.');
15171: if (keys(%changes) > 0) {
15172: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
15173: $dom);
15174: if ($putresult eq 'ok') {
15175: if (ref($defaultshash{'trust'}) eq 'HASH') {
15176: foreach my $prefix (@prefixes) {
15177: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
15178: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
15179: }
15180: }
15181: }
15182: my $cachetime = 24*60*60;
15183: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15184: if (ref($lastactref) eq 'HASH') {
15185: $lastactref->{'domdefaults'} = 1;
15186: }
15187: if (keys(%changes) > 0) {
15188: my %lt = &trust_titles();
15189: $resulttext = &mt('Changes made:').'<ul>';
15190: foreach my $prefix (@prefixes) {
15191: if (ref($changes{$prefix}) eq 'HASH') {
15192: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
15193: foreach my $type (@types) {
15194: if (defined($changes{$prefix}{$type})) {
15195: my $newvalue;
15196: if (ref($defaultshash{'trust'}) eq 'HASH') {
15197: if (ref($defaultshash{'trust'}{$prefix})) {
15198: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
15199: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
15200: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
15201: }
15202: }
15203: }
15204: }
15205: if ($newvalue eq '') {
15206: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
15207: } else {
15208: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
15209: }
15210: }
15211: }
15212: $resulttext .= '</ul>';
15213: }
15214: }
15215: $resulttext .= '</ul>';
15216: } else {
15217: $resulttext = $nochgmsg;
15218: }
15219: } else {
15220: $resulttext = '<span class="LC_error">'.
15221: &mt('An error occurred: [_1]',$putresult).'</span>';
15222: }
15223: } else {
15224: $resulttext = $nochgmsg;
15225: }
15226: return $resulttext;
15227: }
15228:
1.150 raeburn 15229: sub modify_loadbalancing {
15230: my ($dom,%domconfig) = @_;
15231: my $primary_id = &Apache::lonnet::domain($dom,'primary');
15232: my $intdom = &Apache::lonnet::internet_dom($primary_id);
15233: my ($othertitle,$usertypes,$types) =
15234: &Apache::loncommon::sorted_inst_types($dom);
15235: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 15236: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 15237: my @sparestypes = ('primary','default');
15238: my %typetitles = &sparestype_titles();
15239: my $resulttext;
1.171 raeburn 15240: my (%currbalancer,%currtargets,%currrules,%existing);
15241: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
15242: %existing = %{$domconfig{'loadbalancing'}};
15243: }
15244: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
15245: \%currtargets,\%currrules);
15246: my ($saveloadbalancing,%defaultshash,%changes);
15247: my ($alltypes,$othertypes,$titles) =
15248: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
15249: my %ruletitles = &offloadtype_text();
15250: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
15251: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
15252: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
15253: if ($balancer eq '') {
15254: next;
15255: }
1.210 raeburn 15256: if (!exists($servers{$balancer})) {
1.171 raeburn 15257: if (exists($currbalancer{$balancer})) {
15258: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 15259: }
1.171 raeburn 15260: next;
15261: }
15262: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
15263: push(@{$changes{'delete'}},$balancer);
15264: next;
15265: }
15266: if (!exists($currbalancer{$balancer})) {
15267: push(@{$changes{'add'}},$balancer);
15268: }
15269: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
15270: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
15271: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
15272: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
15273: $saveloadbalancing = 1;
15274: }
15275: foreach my $sparetype (@sparestypes) {
15276: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
15277: my @offloadto;
15278: foreach my $target (@targets) {
15279: if (($servers{$target}) && ($target ne $balancer)) {
15280: if ($sparetype eq 'default') {
15281: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
15282: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 15283: }
15284: }
1.171 raeburn 15285: unless(grep(/^\Q$target\E$/,@offloadto)) {
15286: push(@offloadto,$target);
15287: }
1.150 raeburn 15288: }
15289: }
1.284 raeburn 15290: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
15291: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
15292: push(@offloadto,$balancer);
15293: }
15294: }
15295: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 15296: }
1.171 raeburn 15297: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 15298: foreach my $sparetype (@sparestypes) {
1.171 raeburn 15299: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
15300: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 15301: if (@targetdiffs > 0) {
1.171 raeburn 15302: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 15303: }
1.171 raeburn 15304: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15305: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15306: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 15307: }
15308: }
15309: }
15310: } else {
1.171 raeburn 15311: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 15312: foreach my $sparetype (@sparestypes) {
1.171 raeburn 15313: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15314: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15315: $changes{'curr'}{$balancer}{'targets'} = 1;
15316: }
1.150 raeburn 15317: }
15318: }
1.210 raeburn 15319: }
1.150 raeburn 15320: }
15321: my $ishomedom;
1.171 raeburn 15322: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
15323: $ishomedom = 1;
1.150 raeburn 15324: }
15325: if (ref($alltypes) eq 'ARRAY') {
15326: foreach my $type (@{$alltypes}) {
15327: my $rule;
1.210 raeburn 15328: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 15329: (!$ishomedom)) {
1.171 raeburn 15330: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
15331: }
15332: if ($rule eq 'specific') {
1.255 raeburn 15333: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 15334: if (exists($servers{$specifiedhost})) {
1.255 raeburn 15335: $rule = $specifiedhost;
15336: }
1.150 raeburn 15337: }
1.171 raeburn 15338: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
15339: if (ref($currrules{$balancer}) eq 'HASH') {
15340: if ($rule ne $currrules{$balancer}{$type}) {
15341: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 15342: }
15343: } elsif ($rule ne '') {
1.171 raeburn 15344: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 15345: }
15346: }
15347: }
1.171 raeburn 15348: }
15349: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
15350: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
15351: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
15352: $defaultshash{'loadbalancing'} = {};
15353: }
15354: my $putresult = &Apache::lonnet::put_dom('configuration',
15355: \%defaultshash,$dom);
15356: if ($putresult eq 'ok') {
15357: if (keys(%changes) > 0) {
1.252 raeburn 15358: my %toupdate;
1.171 raeburn 15359: if (ref($changes{'delete'}) eq 'ARRAY') {
15360: foreach my $balancer (sort(@{$changes{'delete'}})) {
15361: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 15362: $toupdate{$balancer} = 1;
1.150 raeburn 15363: }
1.171 raeburn 15364: }
15365: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 15366: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 15367: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 15368: $toupdate{$balancer} = 1;
1.171 raeburn 15369: }
15370: }
15371: if (ref($changes{'curr'}) eq 'HASH') {
15372: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 15373: $toupdate{$balancer} = 1;
1.171 raeburn 15374: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
15375: if ($changes{'curr'}{$balancer}{'targets'}) {
15376: my %offloadstr;
15377: foreach my $sparetype (@sparestypes) {
15378: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15379: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15380: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15381: }
15382: }
1.150 raeburn 15383: }
1.171 raeburn 15384: if (keys(%offloadstr) == 0) {
15385: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 15386: } else {
1.171 raeburn 15387: my $showoffload;
15388: foreach my $sparetype (@sparestypes) {
15389: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
15390: if (defined($offloadstr{$sparetype})) {
15391: $showoffload .= $offloadstr{$sparetype};
15392: } else {
15393: $showoffload .= &mt('None');
15394: }
15395: $showoffload .= (' 'x3);
15396: }
15397: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 15398: }
15399: }
15400: }
1.171 raeburn 15401: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
15402: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
15403: foreach my $type (@{$alltypes}) {
15404: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
15405: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
15406: my $balancetext;
15407: if ($rule eq '') {
15408: $balancetext = $ruletitles{'default'};
1.209 raeburn 15409: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 15410: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 15411: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 15412: foreach my $sparetype (@sparestypes) {
15413: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15414: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15415: }
15416: }
1.253 raeburn 15417: foreach my $item (@{$alltypes}) {
15418: next if ($item =~ /^_LC_ipchange/);
15419: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
15420: if ($hasrule eq 'homeserver') {
15421: map { $toupdate{$_} = 1; } (keys(%libraryservers));
15422: } else {
15423: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
15424: if ($servers{$hasrule}) {
15425: $toupdate{$hasrule} = 1;
15426: }
15427: }
15428: }
15429: }
1.254 raeburn 15430: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
15431: $balancetext = $ruletitles{$rule};
15432: } else {
15433: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
15434: $balancetext = $ruletitles{'particular'}.' '.$receiver;
15435: if ($receiver) {
15436: $toupdate{$receiver};
15437: }
15438: }
15439: } else {
15440: $balancetext = $ruletitles{$rule};
1.252 raeburn 15441: }
1.171 raeburn 15442: } else {
15443: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
15444: }
1.210 raeburn 15445: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 15446: }
15447: }
15448: }
15449: }
1.252 raeburn 15450: if (keys(%toupdate)) {
15451: my %thismachine;
15452: my $updatedhere;
15453: my $cachetime = 60*60*24;
15454: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
15455: foreach my $lonhost (keys(%toupdate)) {
15456: if ($thismachine{$lonhost}) {
15457: unless ($updatedhere) {
15458: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
15459: $defaultshash{'loadbalancing'},
15460: $cachetime);
15461: $updatedhere = 1;
15462: }
15463: } else {
15464: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
15465: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
15466: }
15467: }
15468: }
1.150 raeburn 15469: }
1.171 raeburn 15470: }
15471: if ($resulttext ne '') {
15472: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 15473: } else {
15474: $resulttext = $nochgmsg;
15475: }
15476: } else {
1.171 raeburn 15477: $resulttext = $nochgmsg;
1.150 raeburn 15478: }
15479: } else {
1.171 raeburn 15480: $resulttext = '<span class="LC_error">'.
15481: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 15482: }
15483: } else {
1.171 raeburn 15484: $resulttext = $nochgmsg;
1.150 raeburn 15485: }
15486: return $resulttext;
15487: }
15488:
1.48 raeburn 15489: sub recurse_check {
15490: my ($chkcats,$categories,$depth,$name) = @_;
15491: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
15492: my $chg = 0;
15493: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
15494: my $category = $chkcats->[$depth]{$name}[$j];
15495: my $item;
15496: if ($category eq '') {
15497: $chg ++;
15498: } else {
15499: my $deeper = $depth + 1;
15500: $item = &escape($category).':'.&escape($name).':'.$depth;
15501: if ($chg) {
15502: $categories->{$item} -= $chg;
15503: }
15504: &recurse_check($chkcats,$categories,$deeper,$category);
15505: $deeper --;
15506: }
15507: }
15508: }
15509: return;
15510: }
15511:
15512: sub recurse_cat_deletes {
15513: my ($item,$coursecategories,$deletions) = @_;
15514: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15515: my $subdepth = $depth + 1;
15516: if (ref($coursecategories) eq 'HASH') {
15517: foreach my $subitem (keys(%{$coursecategories})) {
15518: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
15519: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
15520: delete($coursecategories->{$subitem});
15521: $deletions->{$subitem} = 1;
15522: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 15523: }
1.48 raeburn 15524: }
15525: }
15526: return;
15527: }
15528:
1.125 raeburn 15529: sub active_dc_picker {
1.191 raeburn 15530: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 15531: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 15532: my @domcoord = keys(%domcoords);
15533: if (keys(%currhash)) {
15534: foreach my $dc (keys(%currhash)) {
15535: unless (exists($domcoords{$dc})) {
15536: push(@domcoord,$dc);
15537: }
15538: }
15539: }
15540: @domcoord = sort(@domcoord);
1.210 raeburn 15541: my $numdcs = scalar(@domcoord);
1.191 raeburn 15542: my $rows = 0;
15543: my $table;
1.125 raeburn 15544: if ($numdcs > 1) {
1.191 raeburn 15545: $table = '<table>';
15546: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 15547: my $rem = $i%($numinrow);
15548: if ($rem == 0) {
15549: if ($i > 0) {
1.191 raeburn 15550: $table .= '</tr>';
1.125 raeburn 15551: }
1.191 raeburn 15552: $table .= '<tr>';
15553: $rows ++;
1.125 raeburn 15554: }
1.191 raeburn 15555: my $check = '';
15556: if ($inputtype eq 'radio') {
15557: if (keys(%currhash) == 0) {
15558: if (!$i) {
15559: $check = ' checked="checked"';
15560: }
15561: } elsif (exists($currhash{$domcoord[$i]})) {
15562: $check = ' checked="checked"';
15563: }
15564: } else {
15565: if (exists($currhash{$domcoord[$i]})) {
15566: $check = ' checked="checked"';
1.125 raeburn 15567: }
15568: }
1.191 raeburn 15569: if ($i == @domcoord - 1) {
1.125 raeburn 15570: my $colsleft = $numinrow - $rem;
15571: if ($colsleft > 1) {
1.191 raeburn 15572: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 15573: } else {
1.191 raeburn 15574: $table .= '<td class="LC_left_item">';
1.125 raeburn 15575: }
15576: } else {
1.191 raeburn 15577: $table .= '<td class="LC_left_item">';
15578: }
15579: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
15580: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
15581: $table .= '<span class="LC_nobreak"><label>'.
15582: '<input type="'.$inputtype.'" name="'.$name.'"'.
15583: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
15584: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 15585: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 15586: }
1.219 raeburn 15587: $table .= '</label></span></td>';
1.191 raeburn 15588: }
15589: $table .= '</tr></table>';
15590: } elsif ($numdcs == 1) {
1.219 raeburn 15591: my ($dcname,$dcdom) = split(':',$domcoord[0]);
15592: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 15593: if ($inputtype eq 'radio') {
1.247 raeburn 15594: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 15595: if ($user ne $dcname.':'.$dcdom) {
15596: $table .= ' ('.$dcname.':'.$dcdom.')';
15597: }
1.191 raeburn 15598: } else {
15599: my $check;
15600: if (exists($currhash{$domcoord[0]})) {
15601: $check = ' checked="checked"';
1.125 raeburn 15602: }
1.247 raeburn 15603: $table = '<span class="LC_nobreak"><label>'.
15604: '<input type="checkbox" name="'.$name.'" '.
15605: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 15606: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 15607: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 15608: }
1.220 raeburn 15609: $table .= '</label></span>';
1.191 raeburn 15610: $rows ++;
1.125 raeburn 15611: }
15612: }
1.191 raeburn 15613: return ($numdcs,$table,$rows);
1.125 raeburn 15614: }
15615:
1.137 raeburn 15616: sub usersession_titles {
15617: return &Apache::lonlocal::texthash(
15618: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
15619: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 15620: spares => 'Servers offloaded to, when busy',
1.137 raeburn 15621: version => 'LON-CAPA version requirement',
1.138 raeburn 15622: excludedomain => 'Allow all, but exclude specific domains',
15623: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 15624: primary => 'Primary (checked first)',
1.154 raeburn 15625: default => 'Default',
1.137 raeburn 15626: );
15627: }
15628:
1.152 raeburn 15629: sub id_for_thisdom {
15630: my (%servers) = @_;
15631: my %altids;
15632: foreach my $server (keys(%servers)) {
15633: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
15634: if ($serverhome ne $server) {
15635: $altids{$serverhome} = $server;
15636: }
15637: }
15638: return %altids;
15639: }
15640:
1.150 raeburn 15641: sub count_servers {
15642: my ($currbalancer,%servers) = @_;
15643: my (@spares,$numspares);
15644: foreach my $lonhost (sort(keys(%servers))) {
15645: next if ($currbalancer eq $lonhost);
15646: push(@spares,$lonhost);
15647: }
15648: if ($currbalancer) {
15649: $numspares = scalar(@spares);
15650: } else {
15651: $numspares = scalar(@spares) - 1;
15652: }
15653: return ($numspares,@spares);
15654: }
15655:
15656: sub lonbalance_targets_js {
1.171 raeburn 15657: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 15658: my $select = &mt('Select');
15659: my ($alltargets,$allishome,$allinsttypes,@alltypes);
15660: if (ref($servers) eq 'HASH') {
15661: $alltargets = join("','",sort(keys(%{$servers})));
15662: my @homedoms;
15663: foreach my $server (sort(keys(%{$servers}))) {
15664: if (&Apache::lonnet::host_domain($server) eq $dom) {
15665: push(@homedoms,'1');
15666: } else {
15667: push(@homedoms,'0');
15668: }
15669: }
15670: $allishome = join("','",@homedoms);
15671: }
15672: if (ref($types) eq 'ARRAY') {
15673: if (@{$types} > 0) {
15674: @alltypes = @{$types};
15675: }
15676: }
15677: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
15678: $allinsttypes = join("','",@alltypes);
1.171 raeburn 15679: my (%currbalancer,%currtargets,%currrules,%existing);
15680: if (ref($settings) eq 'HASH') {
15681: %existing = %{$settings};
15682: }
15683: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
15684: \%currtargets,\%currrules);
1.210 raeburn 15685: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 15686: return <<"END";
15687:
15688: <script type="text/javascript">
15689: // <![CDATA[
15690:
1.171 raeburn 15691: currBalancers = new Array('$balancers');
15692:
15693: function toggleTargets(balnum) {
15694: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15695: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
15696: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
15697: var prevbalancer = prevhostitem.value;
15698: var baltotal = document.getElementById('loadbalancing_total').value;
15699: prevhostitem.value = balancer;
15700: if (prevbalancer != '') {
15701: var prevIdx = currBalancers.indexOf(prevbalancer);
15702: if (prevIdx != -1) {
15703: currBalancers.splice(prevIdx,1);
15704: }
15705: }
1.150 raeburn 15706: if (balancer == '') {
1.171 raeburn 15707: hideSpares(balnum);
1.150 raeburn 15708: } else {
1.171 raeburn 15709: var currIdx = currBalancers.indexOf(balancer);
15710: if (currIdx == -1) {
15711: currBalancers.push(balancer);
15712: }
1.150 raeburn 15713: var homedoms = new Array('$allishome');
1.171 raeburn 15714: var ishomedom = homedoms[lonhostitem.selectedIndex];
15715: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 15716: }
1.171 raeburn 15717: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 15718: return;
15719: }
15720:
1.171 raeburn 15721: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 15722: var alltargets = new Array('$alltargets');
15723: var insttypes = new Array('$allinsttypes');
1.151 raeburn 15724: var offloadtypes = new Array('primary','default');
15725:
1.171 raeburn 15726: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
15727: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 15728:
1.151 raeburn 15729: for (var i=0; i<offloadtypes.length; i++) {
15730: var count = 0;
15731: for (var j=0; j<alltargets.length; j++) {
15732: if (alltargets[j] != balancer) {
1.171 raeburn 15733: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
15734: item.value = alltargets[j];
15735: item.style.textAlign='left';
15736: item.style.textFace='normal';
15737: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
15738: if (currBalancers.indexOf(alltargets[j]) == -1) {
15739: item.disabled = '';
15740: } else {
15741: item.disabled = 'disabled';
15742: item.checked = false;
15743: }
1.151 raeburn 15744: count ++;
15745: }
1.150 raeburn 15746: }
15747: }
1.151 raeburn 15748: for (var k=0; k<insttypes.length; k++) {
15749: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 15750: if (ishomedom == 1) {
1.171 raeburn 15751: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15752: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15753: } else {
1.171 raeburn 15754: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15755: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 15756: }
15757: } else {
1.171 raeburn 15758: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15759: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15760: }
1.151 raeburn 15761: if ((insttypes[k] != '_LC_external') &&
15762: ((insttypes[k] != '_LC_internetdom') ||
15763: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 15764: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
15765: item.options.length = 0;
15766: item.options[0] = new Option("","",true,true);
1.210 raeburn 15767: var idx = 0;
1.151 raeburn 15768: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 15769: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
15770: idx ++;
15771: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 15772: }
15773: }
15774: }
15775: }
15776: return;
15777: }
15778:
1.171 raeburn 15779: function hideSpares(balnum) {
1.150 raeburn 15780: var alltargets = new Array('$alltargets');
15781: var insttypes = new Array('$allinsttypes');
15782: var offloadtypes = new Array('primary','default');
15783:
1.171 raeburn 15784: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
15785: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 15786:
15787: var total = alltargets.length - 1;
15788: for (var i=0; i<offloadtypes; i++) {
15789: for (var j=0; j<total; j++) {
1.171 raeburn 15790: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
15791: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
15792: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 15793: }
1.150 raeburn 15794: }
15795: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 15796: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15797: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 15798: if (insttypes[k] != '_LC_external') {
1.171 raeburn 15799: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
15800: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 15801: }
15802: }
15803: return;
15804: }
15805:
1.171 raeburn 15806: function checkOffloads(item,balnum,type) {
1.150 raeburn 15807: var alltargets = new Array('$alltargets');
15808: var offloadtypes = new Array('primary','default');
15809: if (item.checked) {
15810: var total = alltargets.length - 1;
15811: var other;
15812: if (type == offloadtypes[0]) {
1.151 raeburn 15813: other = offloadtypes[1];
1.150 raeburn 15814: } else {
1.151 raeburn 15815: other = offloadtypes[0];
1.150 raeburn 15816: }
15817: for (var i=0; i<total; i++) {
1.171 raeburn 15818: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 15819: if (server == item.value) {
1.171 raeburn 15820: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
15821: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 15822: }
15823: }
15824: }
15825: }
15826: return;
15827: }
15828:
1.171 raeburn 15829: function singleServerToggle(balnum,type) {
15830: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 15831: if (offloadtoSelIdx == 0) {
1.171 raeburn 15832: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
15833: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15834:
15835: } else {
1.171 raeburn 15836: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
15837: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 15838: }
15839: return;
15840: }
15841:
1.171 raeburn 15842: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 15843: if (type == '_LC_external') {
1.171 raeburn 15844: return;
1.150 raeburn 15845: }
1.171 raeburn 15846: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 15847: for (var i=0; i<typesRules.length; i++) {
15848: if (formname.elements[typesRules[i]].checked) {
15849: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 15850: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
15851: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15852: } else {
1.171 raeburn 15853: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
15854: }
15855: }
15856: }
15857: return;
15858: }
15859:
15860: function balancerDeleteChange(balnum) {
15861: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15862: var baltotal = document.getElementById('loadbalancing_total').value;
15863: var addtarget;
15864: var removetarget;
15865: var action = 'delete';
15866: if (document.getElementById('loadbalancing_delete_'+balnum)) {
15867: var lonhost = hostitem.value;
15868: var currIdx = currBalancers.indexOf(lonhost);
15869: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
15870: if (currIdx != -1) {
15871: currBalancers.splice(currIdx,1);
15872: }
15873: addtarget = lonhost;
15874: } else {
15875: if (currIdx == -1) {
15876: currBalancers.push(lonhost);
15877: }
15878: removetarget = lonhost;
15879: action = 'undelete';
15880: }
15881: balancerChange(balnum,baltotal,action,addtarget,removetarget);
15882: }
15883: return;
15884: }
15885:
15886: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
15887: if (baltotal > 1) {
15888: var offloadtypes = new Array('primary','default');
15889: var alltargets = new Array('$alltargets');
15890: var insttypes = new Array('$allinsttypes');
15891: for (var i=0; i<baltotal; i++) {
15892: if (i != balnum) {
15893: for (var j=0; j<offloadtypes.length; j++) {
15894: var total = alltargets.length - 1;
15895: for (var k=0; k<total; k++) {
15896: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
15897: var server = serveritem.value;
15898: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15899: if (server == addtarget) {
15900: serveritem.disabled = '';
15901: }
15902: }
15903: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15904: if (server == removetarget) {
15905: serveritem.disabled = 'disabled';
15906: serveritem.checked = false;
15907: }
15908: }
15909: }
15910: }
15911: for (var j=0; j<insttypes.length; j++) {
15912: if (insttypes[j] != '_LC_external') {
15913: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
15914: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
15915: var currSel = singleserver.selectedIndex;
15916: var currVal = singleserver.options[currSel].value;
15917: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15918: var numoptions = singleserver.options.length;
15919: var needsnew = 1;
15920: for (var k=0; k<numoptions; k++) {
15921: if (singleserver.options[k] == addtarget) {
15922: needsnew = 0;
15923: break;
15924: }
15925: }
15926: if (needsnew == 1) {
15927: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
15928: }
15929: }
15930: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15931: singleserver.options.length = 0;
15932: if ((currVal) && (currVal != removetarget)) {
15933: singleserver.options[0] = new Option("","",false,false);
15934: } else {
15935: singleserver.options[0] = new Option("","",true,true);
15936: }
15937: var idx = 0;
15938: for (var m=0; m<alltargets.length; m++) {
15939: if (currBalancers.indexOf(alltargets[m]) == -1) {
15940: idx ++;
15941: if (currVal == alltargets[m]) {
15942: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
15943: } else {
15944: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
15945: }
15946: }
15947: }
15948: }
15949: }
15950: }
15951: }
1.150 raeburn 15952: }
15953: }
15954: }
15955: return;
15956: }
15957:
1.152 raeburn 15958: // ]]>
15959: </script>
15960:
15961: END
15962: }
15963:
15964: sub new_spares_js {
15965: my @sparestypes = ('primary','default');
15966: my $types = join("','",@sparestypes);
15967: my $select = &mt('Select');
15968: return <<"END";
15969:
15970: <script type="text/javascript">
15971: // <![CDATA[
15972:
15973: function updateNewSpares(formname,lonhost) {
15974: var types = new Array('$types');
15975: var include = new Array();
15976: var exclude = new Array();
15977: for (var i=0; i<types.length; i++) {
15978: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
15979: for (var j=0; j<spareboxes.length; j++) {
15980: if (formname.elements[spareboxes[j]].checked) {
15981: exclude.push(formname.elements[spareboxes[j]].value);
15982: } else {
15983: include.push(formname.elements[spareboxes[j]].value);
15984: }
15985: }
15986: }
15987: for (var i=0; i<types.length; i++) {
15988: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
15989: var selIdx = newSpare.selectedIndex;
15990: var currnew = newSpare.options[selIdx].value;
15991: var okSpares = new Array();
15992: for (var j=0; j<newSpare.options.length; j++) {
15993: var possible = newSpare.options[j].value;
15994: if (possible != '') {
15995: if (exclude.indexOf(possible) == -1) {
15996: okSpares.push(possible);
15997: } else {
15998: if (currnew == possible) {
15999: selIdx = 0;
16000: }
16001: }
16002: }
16003: }
16004: for (var k=0; k<include.length; k++) {
16005: if (okSpares.indexOf(include[k]) == -1) {
16006: okSpares.push(include[k]);
16007: }
16008: }
16009: okSpares.sort();
16010: newSpare.options.length = 0;
16011: if (selIdx == 0) {
16012: newSpare.options[0] = new Option("$select","",true,true);
16013: } else {
16014: newSpare.options[0] = new Option("$select","",false,false);
16015: }
16016: for (var m=0; m<okSpares.length; m++) {
16017: var idx = m+1;
16018: var selThis = 0;
16019: if (selIdx != 0) {
16020: if (okSpares[m] == currnew) {
16021: selThis = 1;
16022: }
16023: }
16024: if (selThis == 1) {
16025: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
16026: } else {
16027: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
16028: }
16029: }
16030: }
16031: return;
16032: }
16033:
16034: function checkNewSpares(lonhost,type) {
16035: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
16036: var chosen = newSpare.options[newSpare.selectedIndex].value;
16037: if (chosen != '') {
16038: var othertype;
16039: var othernewSpare;
16040: if (type == 'primary') {
16041: othernewSpare = document.getElementById('newspare_default_'+lonhost);
16042: }
16043: if (type == 'default') {
16044: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
16045: }
16046: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
16047: othernewSpare.selectedIndex = 0;
16048: }
16049: }
16050: return;
16051: }
16052:
16053: // ]]>
16054: </script>
16055:
16056: END
16057:
16058: }
16059:
16060: sub common_domprefs_js {
16061: return <<"END";
16062:
16063: <script type="text/javascript">
16064: // <![CDATA[
16065:
1.150 raeburn 16066: function getIndicesByName(formname,item) {
1.152 raeburn 16067: var group = new Array();
1.150 raeburn 16068: for (var i=0;i<formname.elements.length;i++) {
16069: if (formname.elements[i].name == item) {
1.152 raeburn 16070: group.push(formname.elements[i].id);
1.150 raeburn 16071: }
16072: }
1.152 raeburn 16073: return group;
1.150 raeburn 16074: }
16075:
16076: // ]]>
16077: </script>
16078:
16079: END
1.152 raeburn 16080:
1.150 raeburn 16081: }
16082:
1.165 raeburn 16083: sub recaptcha_js {
16084: my %lt = &captcha_phrases();
16085: return <<"END";
16086:
16087: <script type="text/javascript">
16088: // <![CDATA[
16089:
16090: function updateCaptcha(caller,context) {
16091: var privitem;
16092: var pubitem;
16093: var privtext;
16094: var pubtext;
1.269 raeburn 16095: var versionitem;
16096: var versiontext;
1.165 raeburn 16097: if (document.getElementById(context+'_recaptchapub')) {
16098: pubitem = document.getElementById(context+'_recaptchapub');
16099: } else {
16100: return;
16101: }
16102: if (document.getElementById(context+'_recaptchapriv')) {
16103: privitem = document.getElementById(context+'_recaptchapriv');
16104: } else {
16105: return;
16106: }
16107: if (document.getElementById(context+'_recaptchapubtxt')) {
16108: pubtext = document.getElementById(context+'_recaptchapubtxt');
16109: } else {
16110: return;
16111: }
16112: if (document.getElementById(context+'_recaptchaprivtxt')) {
16113: privtext = document.getElementById(context+'_recaptchaprivtxt');
16114: } else {
16115: return;
16116: }
1.269 raeburn 16117: if (document.getElementById(context+'_recaptchaversion')) {
16118: versionitem = document.getElementById(context+'_recaptchaversion');
16119: } else {
16120: return;
16121: }
16122: if (document.getElementById(context+'_recaptchavertxt')) {
16123: versiontext = document.getElementById(context+'_recaptchavertxt');
16124: } else {
16125: return;
16126: }
1.165 raeburn 16127: if (caller.checked) {
16128: if (caller.value == 'recaptcha') {
16129: pubitem.type = 'text';
16130: privitem.type = 'text';
16131: pubitem.size = '40';
16132: privitem.size = '40';
16133: pubtext.innerHTML = "$lt{'pub'}";
16134: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 16135: versionitem.type = 'text';
16136: versionitem.size = '3';
1.289 raeburn 16137: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 16138: } else {
16139: pubitem.type = 'hidden';
16140: privitem.type = 'hidden';
1.269 raeburn 16141: versionitem.type = 'hidden';
1.165 raeburn 16142: pubtext.innerHTML = '';
16143: privtext.innerHTML = '';
1.269 raeburn 16144: versiontext.innerHTML = '';
1.165 raeburn 16145: }
16146: }
16147: return;
16148: }
16149:
16150: // ]]>
16151: </script>
16152:
16153: END
16154:
16155: }
16156:
1.236 raeburn 16157: sub toggle_display_js {
1.192 raeburn 16158: return <<"END";
16159:
16160: <script type="text/javascript">
16161: // <![CDATA[
16162:
1.236 raeburn 16163: function toggleDisplay(domForm,caller) {
16164: if (document.getElementById(caller)) {
16165: var divitem = document.getElementById(caller);
16166: var optionsElement = domForm.coursecredits;
1.264 raeburn 16167: var checkval = 1;
16168: var dispval = 'block';
1.303 raeburn 16169: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 16170: if (caller == 'emailoptions') {
16171: optionsElement = domForm.cancreate_email;
16172: }
1.257 raeburn 16173: if (caller == 'studentsubmission') {
16174: optionsElement = domForm.postsubmit;
16175: }
1.264 raeburn 16176: if (caller == 'cloneinstcode') {
16177: optionsElement = domForm.canclone;
16178: checkval = 'instcode';
16179: }
1.303 raeburn 16180: if (selfcreateRegExp.test(caller)) {
16181: optionsElement = domForm.elements[caller];
16182: checkval = 'other';
16183: dispval = 'inline'
16184: }
1.236 raeburn 16185: if (optionsElement.length) {
1.192 raeburn 16186: var currval;
1.236 raeburn 16187: for (var i=0; i<optionsElement.length; i++) {
16188: if (optionsElement[i].checked) {
16189: currval = optionsElement[i].value;
1.192 raeburn 16190: }
16191: }
1.264 raeburn 16192: if (currval == checkval) {
16193: divitem.style.display = dispval;
1.192 raeburn 16194: } else {
1.236 raeburn 16195: divitem.style.display = 'none';
1.192 raeburn 16196: }
16197: }
16198: }
16199: return;
16200: }
16201:
16202: // ]]>
16203: </script>
16204:
16205: END
16206:
16207: }
16208:
1.165 raeburn 16209: sub captcha_phrases {
16210: return &Apache::lonlocal::texthash (
16211: priv => 'Private key',
16212: pub => 'Public key',
16213: original => 'original (CAPTCHA)',
16214: recaptcha => 'successor (ReCAPTCHA)',
16215: notused => 'unused',
1.289 raeburn 16216: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 16217: );
16218: }
16219:
1.205 raeburn 16220: sub devalidate_remote_domconfs {
1.212 raeburn 16221: my ($dom,$cachekeys) = @_;
16222: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 16223: my %servers = &Apache::lonnet::internet_dom_servers($dom);
16224: my %thismachine;
16225: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 16226: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 16227: if (keys(%servers)) {
1.205 raeburn 16228: foreach my $server (keys(%servers)) {
16229: next if ($thismachine{$server});
1.212 raeburn 16230: my @cached;
16231: foreach my $name (@posscached) {
16232: if ($cachekeys->{$name}) {
16233: push(@cached,&escape($name).':'.&escape($dom));
16234: }
16235: }
16236: if (@cached) {
16237: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
16238: }
1.205 raeburn 16239: }
16240: }
16241: return;
16242: }
16243:
1.3 raeburn 16244: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>