Annotation of loncom/interface/domainprefs.pm, revision 1.308
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.308 ! raeburn 4: # $Id: domainprefs.pm,v 1.307 2017/08/15 21:01:06 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: }
3127: } else {
3128: foreach my $type (@mailings) {
3129: $css_class = $rownum%2?' class="LC_odd_row"':'';
3130: $datatable .= '<tr'.$css_class.'>'.
3131: '<td><span class="LC_nobreak">'.
3132: $titles->{$type}.': </span></td>'.
3133: '<td class="LC_left_item">';
3134: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3135: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3136: }
3137: $datatable .= '<span class="LC_nobreak">';
3138: foreach my $item (@contacts) {
3139: $datatable .= '<label>'.
3140: '<input type="checkbox" name="'.$type.'"'.
3141: $checked{$type}{$item}.
3142: ' value="'.$item.'" />'.$short_titles->{$item}.
3143: '</label> ';
3144: }
3145: $datatable .= '</span><br />'.&mt('Others').': '.
3146: '<input type="text" name="'.$type.'_others" '.
3147: 'value="'.$otheremails{$type}.'" />';
3148: my %locchecked;
3149: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3150: foreach my $loc ('s','b') {
3151: if ($includeloc{$type} eq $loc) {
3152: $locchecked{$loc} = ' checked="checked"';
3153: last;
3154: }
3155: }
3156: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3157: '<input type="text" name="'.$type.'_bcc" '.
3158: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3159: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3160: &mt('Text automatically added to e-mail:').' '.
3161: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3162: '<span class="LC_nobreak">'.&mt('Location:').' '.
3163: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3164: (' 'x2).
3165: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3166: '</span></fieldset>';
3167: }
3168: $datatable .= '</td></tr>'."\n";
3169: $rownum ++;
3170: }
1.28 raeburn 3171: }
1.286 raeburn 3172: if ($position eq 'middle') {
3173: my %choices;
3174: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289 raeburn 3175: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3176: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 3177: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3178: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3179: &mt('LON-CAPA core group - MSU'),600,500));
3180: my @toggles = ('reporterrors','reportupdates');
3181: my %defaultchecked = ('reporterrors' => 'on',
3182: 'reportupdates' => 'on');
3183: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3184: \%choices,$rownum);
3185: $datatable .= $reports;
3186: } elsif ($position eq 'bottom') {
1.69 raeburn 3187: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 3188: $datatable .= '<tr'.$css_class.'>'.
1.286 raeburn 3189: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3190: &mt('(e-mail, subject, and description always shown)').
3191: '</td><td class="LC_left_item">';
1.289 raeburn 3192: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
1.286 raeburn 3193: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3194: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3195: foreach my $field (@{$fields}) {
3196: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3197: if (($field eq 'screenshot') || ($field eq 'cc')) {
3198: $datatable .= ' '.&mt('(logged-in users)');
3199: }
3200: $datatable .='</td><td>';
3201: my $clickaction;
3202: if ($field eq 'screenshot') {
3203: $clickaction = ' onclick="screenshotSize(this);"';
3204: }
3205: if (ref($possoptions->{$field}) eq 'ARRAY') {
3206: foreach my $option (@{$possoptions->{$field}}) {
3207: my $checked;
3208: if ($currfield{$field} eq $option) {
3209: $checked = ' checked="checked"';
3210: }
3211: $datatable .= '<span class="LC_nobreak"><label>'.
3212: '<input type="radio" name="helpform_'.$field.'" '.
3213: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3214: '</label></span>'.(' 'x2);
3215: }
3216: }
3217: if ($field eq 'screenshot') {
3218: my $display;
3219: if ($currfield{$field} eq 'no') {
3220: $display = ' style="display:none"';
3221: }
3222: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3223: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3224: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3225: }
3226: $datatable .= '</td></tr>';
3227: }
3228: $datatable .= '</table>';
1.134 raeburn 3229: }
3230: $datatable .= '</td></tr>'."\n";
1.203 raeburn 3231: $rownum ++;
1.28 raeburn 3232: }
1.30 raeburn 3233: $$rowtotal += $rownum;
1.28 raeburn 3234: return $datatable;
3235: }
3236:
1.286 raeburn 3237: sub contacts_javascript {
3238: return <<"ENDSCRIPT";
3239:
3240: <script type="text/javascript">
3241: // <![CDATA[
3242:
3243: function screenshotSize(field) {
3244: if (document.getElementById('help_screenshotsize')) {
3245: if (field.value == 'no') {
1.289 raeburn 3246: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3247: } else {
3248: document.getElementById('help_screenshotsize').style.display="";
3249: }
3250: }
3251: return;
3252: }
3253:
3254: // ]]>
3255: </script>
3256:
3257: ENDSCRIPT
3258: }
3259:
1.118 jms 3260: sub print_helpsettings {
1.282 raeburn 3261: my ($position,$dom,$settings,$rowtotal) = @_;
3262: my $confname = $dom.'-domainconfig';
1.285 raeburn 3263: my $formname = 'display';
1.168 raeburn 3264: my ($datatable,$itemcount);
1.282 raeburn 3265: if ($position eq 'top') {
3266: $itemcount = 1;
3267: my (%choices,%defaultchecked,@toggles);
3268: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3269: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3270: &mt('LON-CAPA bug tracker'),600,500));
3271: %defaultchecked = ('submitbugs' => 'on');
3272: @toggles = ('submitbugs');
3273: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3274: \%choices,$itemcount);
3275: $$rowtotal ++;
3276: } else {
3277: my $css_class;
3278: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3279: my (%customroles,%ordered,%current);
1.301 raeburn 3280: if (ref($settings) eq 'HASH') {
3281: if (ref($settings->{'adhoc'}) eq 'HASH') {
3282: %current = %{$settings->{'adhoc'}};
3283: }
1.285 raeburn 3284: }
3285: my $count = 0;
3286: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3287: if ($key=~/^rolesdef\_(\w+)$/) {
3288: my $rolename = $1;
1.285 raeburn 3289: my (%privs,$order);
1.282 raeburn 3290: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3291: $customroles{$rolename} = \%privs;
1.285 raeburn 3292: if (ref($current{$rolename}) eq 'HASH') {
3293: $order = $current{$rolename}{'order'};
3294: }
3295: if ($order eq '') {
3296: $order = $count;
3297: }
3298: $ordered{$order} = $rolename;
3299: $count++;
3300: }
3301: }
3302: my $maxnum = scalar(keys(%ordered));
3303: my @roles_by_num = ();
3304: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3305: push(@roles_by_num,$item);
3306: }
3307: my $context = 'domprefs';
3308: my $crstype = 'Course';
3309: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3310: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3311: my ($numstatustypes,@jsarray);
3312: if (ref($types) eq 'ARRAY') {
3313: if (@{$types} > 0) {
3314: $numstatustypes = scalar(@{$types});
3315: push(@accesstypes,'status');
3316: @jsarray = ('bystatus');
1.282 raeburn 3317: }
3318: }
1.290 raeburn 3319: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3320: if (keys(%domhelpdesk)) {
3321: push(@accesstypes,('inc','exc'));
3322: push(@jsarray,('notinc','notexc'));
3323: }
3324: my $hiddenstr = join("','",@jsarray);
3325: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3326: my $context = 'domprefs';
3327: my $crstype = 'Course';
1.285 raeburn 3328: my $prefix = 'helproles_';
3329: my $add_class = 'LC_hidden';
3330: foreach my $num (@roles_by_num) {
3331: my $role = $ordered{$num};
3332: my ($desc,$access,@statuses);
3333: if (ref($current{$role}) eq 'HASH') {
3334: $desc = $current{$role}{'desc'};
3335: $access = $current{$role}{'access'};
3336: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3337: @statuses = @{$current{$role}{'insttypes'}};
3338: }
3339: }
3340: if ($desc eq '') {
3341: $desc = $role;
3342: }
3343: my $identifier = 'custhelp'.$num;
1.282 raeburn 3344: my %full=();
3345: my %levels= (
3346: course => {},
3347: domain => {},
3348: system => {},
3349: );
3350: my %levelscurrent=(
3351: course => {},
3352: domain => {},
3353: system => {},
3354: );
3355: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3356: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3357: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3358: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 3359: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 3360: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3361: for (my $k=0; $k<=$maxnum; $k++) {
3362: my $vpos = $k+1;
3363: my $selstr;
3364: if ($k == $num) {
3365: $selstr = ' selected="selected" ';
3366: }
3367: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3368: }
3369: $datatable .= '</select>'.(' 'x2).
3370: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3371: '</td>'.
3372: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3373: &mt('Name shown to users:').
3374: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3375: '</fieldset>'.
3376: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3377: $othertitle,$usertypes,$types,\%domhelpdesk).
3378: '<fieldset>'.
3379: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3380: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3381: \%levelscurrent,$identifier,
3382: 'LC_hidden',$prefix.$num.'_privs').
3383: '</fieldset></td>';
1.282 raeburn 3384: $itemcount ++;
3385: }
3386: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3387: my $newcust = 'custhelp'.$count;
3388: my (%privs,%levelscurrent);
3389: my %full=();
3390: my %levels= (
3391: course => {},
3392: domain => {},
3393: system => {},
3394: );
3395: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3396: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3397: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 3398: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 3399: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3400: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3401: for (my $k=0; $k<$maxnum+1; $k++) {
3402: my $vpos = $k+1;
3403: my $selstr;
3404: if ($k == $maxnum) {
3405: $selstr = ' selected="selected" ';
3406: }
3407: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3408: }
3409: $datatable .= '</select> '."\n".
1.282 raeburn 3410: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3411: '</label></span></td>'.
1.285 raeburn 3412: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3413: '<span class="LC_nobreak">'.
3414: &mt('Internal name:').
3415: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3416: '</span>'.(' 'x4).
3417: '<span class="LC_nobreak">'.
3418: &mt('Name shown to users:').
3419: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3420: '</span></fieldset>'.
3421: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3422: $usertypes,$types,\%domhelpdesk).
3423: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3424: &Apache::lonuserutils::custom_role_header($context,$crstype,
3425: \@templateroles,$newcust).
3426: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3427: \%levelscurrent,$newcust).
1.285 raeburn 3428: '</fieldset></td></tr>';
1.282 raeburn 3429: $count ++;
3430: $$rowtotal += $count;
3431: }
1.166 raeburn 3432: return $datatable;
1.121 raeburn 3433: }
3434:
1.285 raeburn 3435: sub adhocbutton {
3436: my ($prefix,$num,$field,$visibility) = @_;
3437: my %lt = &Apache::lonlocal::texthash(
3438: show => 'Show details',
3439: hide => 'Hide details',
3440: );
3441: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3442: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3443: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3444: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3445: }
3446:
3447: sub helpsettings_javascript {
3448: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3449: return unless(ref($roles_by_num) eq 'ARRAY');
3450: my %html_js_lt = &Apache::lonlocal::texthash(
3451: show => 'Show details',
3452: hide => 'Hide details',
3453: );
3454: &html_escape(\%html_js_lt);
3455: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3456: return <<"ENDSCRIPT";
3457: <script type="text/javascript">
3458: // <![CDATA[
3459:
3460: function reorderHelpRoles(form,item) {
3461: var changedVal;
3462: $jstext
3463: var newpos = 'helproles_${total}_pos';
3464: var maxh = 1 + $total;
3465: var current = new Array();
3466: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3467: if (item == newpos) {
3468: changedVal = newitemVal;
3469: } else {
3470: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3471: current[newitemVal] = newpos;
3472: }
3473: for (var i=0; i<helproles.length; i++) {
3474: var elementName = 'helproles_'+helproles[i]+'_pos';
3475: if (elementName != item) {
3476: if (form.elements[elementName]) {
3477: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3478: current[currVal] = elementName;
3479: }
3480: }
3481: }
3482: var oldVal;
3483: for (var j=0; j<maxh; j++) {
3484: if (current[j] == undefined) {
3485: oldVal = j;
3486: }
3487: }
3488: if (oldVal < changedVal) {
3489: for (var k=oldVal+1; k<=changedVal ; k++) {
3490: var elementName = current[k];
3491: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3492: }
3493: } else {
3494: for (var k=changedVal; k<oldVal; k++) {
3495: var elementName = current[k];
3496: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3497: }
3498: }
3499: return;
3500: }
3501:
3502: function helpdeskAccess(num) {
3503: var curraccess = null;
3504: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3505: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3506: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3507: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3508: }
3509: }
3510: }
3511: var shown = Array();
3512: var hidden = Array();
3513: if (curraccess == 'none') {
3514: hidden = Array('$hiddenstr');
3515: } else {
3516: if (curraccess == 'status') {
3517: shown = Array('bystatus');
3518: hidden = Array('notinc','notexc');
3519: } else {
3520: if (curraccess == 'exc') {
3521: shown = Array('notexc');
3522: hidden = Array('notinc','bystatus');
3523: }
3524: if (curraccess == 'inc') {
3525: shown = Array('notinc');
3526: hidden = Array('notexc','bystatus');
3527: }
1.293 raeburn 3528: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3529: hidden = Array('notinc','notexc','bystatus');
3530: }
3531: }
3532: }
3533: if (hidden.length > 0) {
3534: for (var i=0; i<hidden.length; i++) {
3535: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3536: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3537: }
3538: }
3539: }
3540: if (shown.length > 0) {
3541: for (var i=0; i<shown.length; i++) {
3542: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3543: if (shown[i] == 'privs') {
3544: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3545: } else {
3546: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3547: }
3548: }
3549: }
3550: }
3551: return;
3552: }
3553:
3554: function toggleHelpdeskItem(num,field) {
3555: if (document.getElementById('helproles_'+num+'_'+field)) {
3556: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 3557: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 3558: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3559: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3560: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3561: }
3562: } else {
3563: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3564: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3565: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3566: }
3567: }
3568: }
3569: return;
3570: }
3571:
3572: // ]]>
3573: </script>
3574:
3575: ENDSCRIPT
3576: }
3577:
3578: sub helpdeskroles_access {
3579: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3580: $usertypes,$types,$domhelpdesk) = @_;
3581: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3582: my %lt = &Apache::lonlocal::texthash(
3583: 'rou' => 'Role usage',
3584: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 3585: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3586: 'dh' => 'All with domain helpdesk role',
3587: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 3588: 'none' => 'None',
3589: 'status' => 'Determined based on institutional status',
3590: 'inc' => 'Include all, but exclude specific personnel',
3591: 'exc' => 'Exclude all, but include specific personnel',
3592: );
3593: my %usecheck = (
3594: all => ' checked="checked"',
3595: );
3596: my %displaydiv = (
3597: status => 'none',
3598: inc => 'none',
3599: exc => 'none',
3600: priv => 'block',
3601: );
3602: my $output;
3603: if (ref($current) eq 'HASH') {
3604: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3605: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3606: $usecheck{$current->{access}} = $usecheck{'all'};
3607: delete($usecheck{'all'});
3608: if ($current->{access} =~ /^(status|inc|exc)$/) {
3609: my $access = $1;
3610: $displaydiv{$access} = 'inline';
3611: } elsif ($current->{access} eq 'none') {
3612: $displaydiv{'priv'} = 'none';
3613: }
3614: }
3615: }
3616: }
3617: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3618: '<p>'.$lt{'whi'}.'</p>';
3619: foreach my $access (@{$accesstypes}) {
3620: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3621: ' onclick="helpdeskAccess('."'$num'".');" />'.
3622: $lt{$access}.'</label>';
3623: if ($access eq 'status') {
3624: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3625: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3626: $othertitle,$usertypes,$types).
3627: '</div>';
3628: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3629: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3630: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3631: '</div>';
3632: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3633: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3634: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3635: '</div>';
3636: }
3637: $output .= '</p>';
3638: }
3639: $output .= '</fieldset>';
3640: return $output;
3641: }
3642:
1.121 raeburn 3643: sub radiobutton_prefs {
1.192 raeburn 3644: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 3645: $additional,$align) = @_;
1.121 raeburn 3646: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3647: (ref($choices) eq 'HASH'));
3648:
1.170 raeburn 3649: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 3650:
3651: foreach my $item (@{$toggles}) {
3652: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3653: $checkedon{$item} = ' checked="checked" ';
3654: $checkedoff{$item} = ' ';
1.121 raeburn 3655: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3656: $checkedoff{$item} = ' checked="checked" ';
3657: $checkedon{$item} = ' ';
3658: }
3659: }
3660: if (ref($settings) eq 'HASH') {
1.121 raeburn 3661: foreach my $item (@{$toggles}) {
1.118 jms 3662: if ($settings->{$item} eq '1') {
3663: $checkedon{$item} = ' checked="checked" ';
3664: $checkedoff{$item} = ' ';
3665: } elsif ($settings->{$item} eq '0') {
3666: $checkedoff{$item} = ' checked="checked" ';
3667: $checkedon{$item} = ' ';
3668: }
3669: }
1.121 raeburn 3670: }
1.192 raeburn 3671: if ($onclick) {
3672: $onclick = ' onclick="'.$onclick.'"';
3673: }
1.121 raeburn 3674: foreach my $item (@{$toggles}) {
1.118 jms 3675: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3676: $datatable .=
1.306 raeburn 3677: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 3678: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3679: '</span></td>';
3680: if ($align eq 'left') {
3681: $datatable .= '<td class="LC_left_item">';
3682: } else {
3683: $datatable .= '<td class="LC_right_item">';
3684: }
1.289 raeburn 3685: $datatable .=
1.257 raeburn 3686: '<span class="LC_nobreak">'.
1.118 jms 3687: '<label><input type="radio" name="'.
1.192 raeburn 3688: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3689: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3690: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3691: '</span>'.$additional.
3692: '</td>'.
1.118 jms 3693: '</tr>';
3694: $itemcount ++;
1.121 raeburn 3695: }
3696: return ($datatable,$itemcount);
3697: }
3698:
1.267 raeburn 3699: sub print_ltitools {
3700: my ($dom,$settings,$rowtotal) = @_;
3701: my $rownum = 0;
3702: my $css_class;
3703: my $itemcount = 1;
3704: my $maxnum = 0;
3705: my %ordered;
3706: if (ref($settings) eq 'HASH') {
3707: foreach my $item (keys(%{$settings})) {
3708: if (ref($settings->{$item}) eq 'HASH') {
3709: my $num = $settings->{$item}{'order'};
3710: $ordered{$num} = $item;
3711: }
3712: }
3713: }
3714: my $confname = $dom.'-domainconfig';
3715: my $switchserver = &check_switchserver($dom,$confname);
3716: my $maxnum = scalar(keys(%ordered));
3717: my $datatable = <itools_javascript($settings);
3718: my %lt = <itools_names();
3719: my @courseroles = ('cc','in','ta','ep','st');
3720: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3721: my @fields = ('fullname','firstname','lastname','email','user','roles');
3722: if (keys(%ordered)) {
3723: my @items = sort { $a <=> $b } keys(%ordered);
3724: for (my $i=0; $i<@items; $i++) {
3725: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3726: my $item = $ordered{$items[$i]};
3727: my ($title,$key,$secret,$url,$imgsrc,$version);
3728: if (ref($settings->{$item}) eq 'HASH') {
3729: $title = $settings->{$item}->{'title'};
3730: $url = $settings->{$item}->{'url'};
3731: $key = $settings->{$item}->{'key'};
3732: $secret = $settings->{$item}->{'secret'};
3733: my $image = $settings->{$item}->{'image'};
3734: if ($image ne '') {
3735: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3736: }
3737: }
3738: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3739: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3740: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3741: for (my $k=0; $k<=$maxnum; $k++) {
3742: my $vpos = $k+1;
3743: my $selstr;
3744: if ($k == $i) {
3745: $selstr = ' selected="selected" ';
3746: }
3747: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3748: }
3749: $datatable .= '</select>'.(' 'x2).
3750: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3751: &mt('Delete?').'</label></span></td>'.
3752: '<td colspan="2">'.
3753: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3754: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3755: (' 'x2).
3756: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3757: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3758: (' 'x2).
3759: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3760: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3761: '<br /><br />'.
3762: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3763: ' value="'.$url.'" /></span>'.
3764: (' 'x2).
3765: '<span class="LC_nobreak">'.$lt{'key'}.
3766: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3767: (' 'x2).
3768: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3769: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3770: '<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>'.
3771: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3772: '</fieldset>'.
3773: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3774: '<span class="LC_nobreak">'.&mt('Display target:');
3775: my %currdisp;
3776: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3777: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3778: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 3779: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
3780: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 3781: } else {
3782: $currdisp{'iframe'} = ' checked="checked"';
3783: }
3784: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3785: $currdisp{'width'} = $1;
3786: }
3787: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3788: $currdisp{'height'} = $1;
3789: }
1.296 raeburn 3790: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
3791: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 3792: } else {
3793: $currdisp{'iframe'} = ' checked="checked"';
3794: }
1.298 raeburn 3795: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 3796: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3797: $lt{$disp}.'</label>'.(' 'x2);
3798: }
3799: $datatable .= (' 'x4);
3800: foreach my $dimen ('width','height') {
3801: $datatable .= '<label>'.$lt{$dimen}.' '.
3802: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3803: (' 'x2);
3804: }
1.296 raeburn 3805: $datatable .= '<br />'.
3806: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3807: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
3808: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3809: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
3810: '</textarea></div><div style=""></div><br />';
1.267 raeburn 3811: $datatable .= '<br />';
3812: foreach my $extra ('passback','roster') {
3813: my $checkedon = '';
3814: my $checkedoff = ' checked="checked"';
3815: if ($settings->{$item}->{$extra}) {
3816: $checkedon = $checkedoff;
3817: $checkedoff = '';
3818: }
3819: $datatable .= $lt{$extra}.' '.
3820: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3821: &mt('Yes').'</label>'.(' 'x2).
3822: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3823: &mt('No').'</label>'.(' 'x4);
3824: }
3825: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3826: if ($imgsrc) {
3827: $datatable .= $imgsrc.
3828: '<label><input type="checkbox" name="ltitools_image_del"'.
3829: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3830: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3831: } else {
3832: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3833: }
3834: if ($switchserver) {
3835: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3836: } else {
3837: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3838: }
3839: $datatable .= '</span></fieldset>';
3840: my (%checkedfields,%rolemaps);
3841: if (ref($settings->{$item}) eq 'HASH') {
3842: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3843: %checkedfields = %{$settings->{$item}->{'fields'}};
3844: }
3845: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3846: %rolemaps = %{$settings->{$item}->{'roles'}};
3847: $checkedfields{'roles'} = 1;
3848: }
3849: }
3850: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3851: '<span class="LC_nobreak">';
3852: foreach my $field (@fields) {
3853: my $checked;
3854: if ($checkedfields{$field}) {
3855: $checked = ' checked="checked"';
3856: }
3857: $datatable .= '<label>'.
3858: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3859: $lt{$field}.'</label>'.(' ' x2);
3860: }
3861: $datatable .= '</span></fieldset>'.
3862: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3863: foreach my $role (@courseroles) {
3864: my ($selected,$selectnone);
3865: if (!$rolemaps{$role}) {
3866: $selectnone = ' selected="selected"';
3867: }
1.306 raeburn 3868: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 3869: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3870: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3871: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3872: foreach my $ltirole (@ltiroles) {
3873: unless ($selectnone) {
3874: if ($rolemaps{$role} eq $ltirole) {
3875: $selected = ' selected="selected"';
3876: } else {
3877: $selected = '';
3878: }
3879: }
3880: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3881: }
3882: $datatable .= '</select></td>';
3883: }
1.273 raeburn 3884: $datatable .= '</tr></table></fieldset>';
3885: my %courseconfig;
3886: if (ref($settings->{$item}) eq 'HASH') {
3887: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3888: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3889: }
3890: }
3891: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 raeburn 3892: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 3893: my $checked;
3894: if ($courseconfig{$item}) {
3895: $checked = ' checked="checked"';
3896: }
3897: $datatable .= '<label>'.
3898: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3899: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3900: }
3901: $datatable .= '</span></fieldset>'.
1.267 raeburn 3902: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3903: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3904: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3905: my %custom = %{$settings->{$item}->{'custom'}};
3906: if (keys(%custom) > 0) {
3907: foreach my $key (sort(keys(%custom))) {
3908: $datatable .= '<tr><td><span class="LC_nobreak">'.
3909: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3910: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3911: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3912: ' value="'.$custom{$key}.'" /></td></tr>';
3913: }
3914: }
3915: }
3916: $datatable .= '<tr><td><span class="LC_nobreak">'.
3917: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3918: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3919: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3920: $datatable .= '</table></fieldset></td></tr>'."\n";
3921: $itemcount ++;
3922: }
3923: }
3924: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3925: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3926: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3927: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3928: '<select name="ltitools_add_pos"'.$chgstr.'>';
3929: for (my $k=0; $k<$maxnum+1; $k++) {
3930: my $vpos = $k+1;
3931: my $selstr;
3932: if ($k == $maxnum) {
3933: $selstr = ' selected="selected" ';
3934: }
3935: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3936: }
3937: $datatable .= '</select> '."\n".
3938: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3939: '<td colspan="2">'.
3940: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3941: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3942: (' 'x2).
3943: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3944: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3945: (' 'x2).
3946: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3947: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3948: '<br />'.
3949: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3950: (' 'x2).
3951: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3952: (' 'x2).
3953: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3954: '<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".
3955: '</fieldset>'.
3956: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3957: '<span class="LC_nobreak">'.&mt('Display target:');
3958: my %defaultdisp;
3959: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 3960: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 3961: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3962: $lt{$disp}.'</label>'.(' 'x2);
3963: }
3964: $datatable .= (' 'x4);
3965: foreach my $dimen ('width','height') {
3966: $datatable .= '<label>'.$lt{$dimen}.' '.
3967: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3968: (' 'x2);
3969: }
1.296 raeburn 3970: $datatable .= '<br />'.
3971: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3972: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
3973: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3974: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
3975: '</div><div style=""></div><br />';
1.267 raeburn 3976: foreach my $extra ('passback','roster') {
3977: $datatable .= $lt{$extra}.' '.
3978: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3979: &mt('Yes').'</label>'.(' 'x2).
3980: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3981: &mt('No').'</label>'.(' 'x4);
3982: }
3983: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3984: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3985: if ($switchserver) {
3986: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3987: } else {
3988: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3989: }
3990: $datatable .= '</span></fieldset>'.
3991: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3992: '<span class="LC_nobreak">';
3993: foreach my $field (@fields) {
3994: $datatable .= '<label>'.
3995: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3996: $lt{$field}.'</label>'.(' ' x2);
3997: }
3998: $datatable .= '</span></fieldset>'.
3999: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
4000: foreach my $role (@courseroles) {
4001: my ($checked,$checkednone);
1.306 raeburn 4002: $datatable .= '<td style="text-align: center">'.
1.267 raeburn 4003: &Apache::lonnet::plaintext($role,'Course').'<br />'.
4004: '<select name="ltitools_add_roles_'.$role.'">'.
4005: '<option value="" selected="selected">'.&mt('Select').'</option>';
4006: foreach my $ltirole (@ltiroles) {
4007: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
4008: }
4009: $datatable .= '</select></td>';
4010: }
4011: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 4012: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 raeburn 4013: foreach my $item ('label','title','target','linktext','explanation') {
4014: $datatable .= '<label>'.
4015: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4016: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4017: }
4018: $datatable .= '</span></fieldset>'.
1.267 raeburn 4019: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4020: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4021: '<tr><td><span class="LC_nobreak">'.
4022: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4023: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4024: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4025: '</table></fieldset></td></tr>'."\n".
4026: '</td>'."\n".
4027: '</tr>'."\n";
4028: $itemcount ++;
4029: return $datatable;
4030: }
4031:
4032: sub ltitools_names {
4033: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4034: 'title' => 'Title',
4035: 'version' => 'Version',
4036: 'msgtype' => 'Message Type',
4037: 'url' => 'URL',
4038: 'key' => 'Key',
4039: 'secret' => 'Secret',
4040: 'icon' => 'Icon',
4041: 'user' => 'Username:domain',
4042: 'fullname' => 'Full Name',
4043: 'firstname' => 'First Name',
4044: 'lastname' => 'Last Name',
4045: 'email' => 'E-mail',
4046: 'roles' => 'Role',
1.298 raeburn 4047: 'window' => 'Window',
4048: 'tab' => 'Tab',
1.296 raeburn 4049: 'iframe' => 'iFrame',
4050: 'height' => 'Height',
4051: 'width' => 'Width',
4052: 'linktext' => 'Default Link Text',
4053: 'explanation' => 'Default Explanation',
4054: 'passback' => 'Tool can return grades:',
4055: 'roster' => 'Tool can retrieve roster:',
4056: 'crstarget' => 'Display target',
4057: 'crslabel' => 'Course label',
4058: 'crstitle' => 'Course title',
4059: 'crslinktext' => 'Link Text',
4060: 'crsexplanation' => 'Explanation',
1.267 raeburn 4061: );
4062: return %lt;
4063: }
4064:
1.121 raeburn 4065: sub print_coursedefaults {
1.139 raeburn 4066: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 4067: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4068: my $itemcount = 1;
1.192 raeburn 4069: my %choices = &Apache::lonlocal::texthash (
4070: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 4071: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 4072: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4073: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 4074: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4075: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4076: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4077: canclone => "People who may clone a course (besides course's owner and coordinators)",
4078: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4079: );
1.198 raeburn 4080: my %staticdefaults = (
4081: anonsurvey_threshold => 10,
4082: uploadquota => 500,
1.257 raeburn 4083: postsubmit => 60,
1.276 raeburn 4084: mysqltables => 172800,
1.198 raeburn 4085: );
1.139 raeburn 4086: if ($position eq 'top') {
1.257 raeburn 4087: %defaultchecked = (
4088: 'canuse_pdfforms' => 'off',
4089: 'uselcmath' => 'on',
4090: 'usejsme' => 'on',
1.289 raeburn 4091: 'canclone' => 'none',
1.257 raeburn 4092: );
4093: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 4094: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4095: \%choices,$itemcount);
1.264 raeburn 4096: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4097: $datatable .=
1.306 raeburn 4098: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 4099: '<span class="LC_nobreak">'.$choices{'canclone'}.
4100: '</span></td><td class="LC_left_item">';
4101: my $currcanclone = 'none';
4102: my $onclick;
4103: my @cloneoptions = ('none','domain');
4104: my %clonetitles = (
4105: none => 'No additional course requesters',
4106: domain => "Any course requester in course's domain",
4107: instcode => 'Course requests for official courses ...',
4108: );
4109: my (%codedefaults,@code_order,@posscodes);
4110: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4111: \@code_order) eq 'ok') {
4112: if (@code_order > 0) {
4113: push(@cloneoptions,'instcode');
4114: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4115: }
4116: }
4117: if (ref($settings) eq 'HASH') {
4118: if ($settings->{'canclone'}) {
4119: if (ref($settings->{'canclone'}) eq 'HASH') {
4120: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4121: if (@code_order > 0) {
4122: $currcanclone = 'instcode';
4123: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4124: }
4125: }
4126: } elsif ($settings->{'canclone'} eq 'domain') {
4127: $currcanclone = $settings->{'canclone'};
4128: }
4129: }
1.289 raeburn 4130: }
1.264 raeburn 4131: foreach my $option (@cloneoptions) {
4132: my ($checked,$additional);
4133: if ($currcanclone eq $option) {
4134: $checked = ' checked="checked"';
4135: }
4136: if ($option eq 'instcode') {
4137: if (@code_order) {
4138: my $show = 'none';
4139: if ($checked) {
4140: $show = 'block';
4141: }
4142: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4143: &mt('Institutional codes for new and cloned course have identical:').
4144: '<br />';
4145: foreach my $item (@code_order) {
4146: my $codechk;
4147: if ($checked) {
4148: if (grep(/^\Q$item\E$/,@posscodes)) {
4149: $codechk = ' checked="checked"';
4150: }
4151: }
4152: $additional .= '<label>'.
4153: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4154: $item.'</label>';
4155: }
4156: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4157: }
4158: }
4159: $datatable .=
4160: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4161: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4162: '</label> '.$additional.'</span><br />';
4163: }
4164: $datatable .= '</td>'.
4165: '</tr>';
4166: $itemcount ++;
1.139 raeburn 4167: } else {
4168: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4169: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4170: my $currusecredits = 0;
1.257 raeburn 4171: my $postsubmitclient = 1;
1.271 raeburn 4172: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4173: if (ref($settings) eq 'HASH') {
4174: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4175: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4176: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4177: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4178: }
4179: }
1.192 raeburn 4180: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4181: foreach my $type (@types) {
4182: next if ($type eq 'community');
4183: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4184: if ($defcredits{$type} ne '') {
4185: $currusecredits = 1;
4186: }
4187: }
4188: }
4189: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4190: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4191: $postsubmitclient = 0;
4192: foreach my $type (@types) {
4193: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4194: }
4195: } else {
4196: foreach my $type (@types) {
4197: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4198: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 4199: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 4200: } else {
4201: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4202: }
4203: } else {
4204: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4205: }
4206: }
4207: }
4208: } else {
4209: foreach my $type (@types) {
4210: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 4211: }
4212: }
1.276 raeburn 4213: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4214: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4215: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4216: }
4217: } else {
4218: foreach my $type (@types) {
4219: $currmysql{$type} = $staticdefaults{'mysqltables'};
4220: }
4221: }
1.258 raeburn 4222: } else {
4223: foreach my $type (@types) {
4224: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4225: }
1.139 raeburn 4226: }
4227: if (!$currdefresponder) {
1.198 raeburn 4228: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4229: } elsif ($currdefresponder < 1) {
4230: $currdefresponder = 1;
4231: }
1.198 raeburn 4232: foreach my $type (@types) {
4233: if ($curruploadquota{$type} eq '') {
4234: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4235: }
4236: }
1.139 raeburn 4237: $datatable .=
1.192 raeburn 4238: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4239: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4240: '</span></td>'.
4241: '<td class="LC_right_item"><span class="LC_nobreak">'.
4242: '<input type="text" name="anonsurvey_threshold"'.
4243: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 4244: '</td></tr>'."\n";
4245: $itemcount ++;
4246: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4247: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4248: $choices{'uploadquota'}.
4249: '</span></td>'.
1.306 raeburn 4250: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 4251: '<table><tr>';
1.198 raeburn 4252: foreach my $type (@types) {
1.306 raeburn 4253: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 4254: '<input type="text" name="uploadquota_'.$type.'"'.
4255: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4256: }
4257: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 4258: $itemcount ++;
1.236 raeburn 4259: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 4260: my $display = 'none';
1.192 raeburn 4261: if ($currusecredits) {
4262: $display = 'block';
4263: }
4264: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 4265: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4266: foreach my $type (@types) {
4267: next if ($type eq 'community');
1.306 raeburn 4268: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 4269: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 4270: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 4271: }
4272: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 4273: %defaultchecked = ('coursecredits' => 'off');
4274: @toggles = ('coursecredits');
4275: my $current = {
4276: 'coursecredits' => $currusecredits,
4277: };
4278: (my $table,$itemcount) =
4279: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 4280: \%choices,$itemcount,$onclick,$additional,'left');
4281: $datatable .= $table;
4282: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4283: my $display = 'none';
4284: if ($postsubmitclient) {
4285: $display = 'block';
4286: }
4287: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 4288: &mt('Number of seconds submit is disabled').'<br />'.
4289: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4290: '<table><tr>';
1.257 raeburn 4291: foreach my $type (@types) {
1.306 raeburn 4292: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 4293: '<input type="text" name="'.$type.'_timeout" value="'.
4294: $deftimeout{$type}.'" size="5" /></td>';
4295: }
4296: $additional .= '</tr></table></div>'."\n";
4297: %defaultchecked = ('postsubmit' => 'on');
4298: @toggles = ('postsubmit');
1.280 raeburn 4299: $current = {
4300: 'postsubmit' => $postsubmitclient,
4301: };
1.257 raeburn 4302: ($table,$itemcount) =
4303: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4304: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 4305: $datatable .= $table;
1.276 raeburn 4306: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4307: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4308: $choices{'mysqltables'}.
4309: '</span></td>'.
1.306 raeburn 4310: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 4311: '<table><tr>';
4312: foreach my $type (@types) {
1.306 raeburn 4313: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 4314: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 4315: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 4316: }
4317: $datatable .= '</tr></table></td></tr>'."\n";
4318: $itemcount ++;
4319:
1.139 raeburn 4320: }
1.192 raeburn 4321: $$rowtotal += $itemcount;
1.121 raeburn 4322: return $datatable;
1.118 jms 4323: }
4324:
1.231 raeburn 4325: sub print_selfenrollment {
4326: my ($position,$dom,$settings,$rowtotal) = @_;
4327: my ($css_class,$datatable);
4328: my $itemcount = 1;
1.271 raeburn 4329: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 4330: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 4331: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4332: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 4333: my @rows;
4334: my $key;
4335: if ($position eq 'top') {
4336: $key = 'admin';
4337: if (ref($rowsref) eq 'ARRAY') {
4338: @rows = @{$rowsref};
4339: }
4340: } elsif ($position eq 'middle') {
4341: $key = 'default';
4342: @rows = ('types','registered','approval','limit');
4343: }
4344: foreach my $row (@rows) {
4345: if (defined($titlesref->{$row})) {
4346: $itemcount ++;
4347: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4348: $datatable .= '<tr'.$css_class.'>'.
4349: '<td>'.$titlesref->{$row}.'</td>'.
4350: '<td class="LC_left_item">'.
4351: '<table><tr>';
4352: my (%current,%currentcap);
4353: if (ref($settings) eq 'HASH') {
4354: if (ref($settings->{$key}) eq 'HASH') {
4355: foreach my $type (@types) {
4356: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4357: $current{$type} = $settings->{$key}->{$type}->{$row};
4358: }
4359: if (($row eq 'limit') && ($key eq 'default')) {
4360: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4361: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4362: }
4363: }
4364: }
4365: }
4366: }
4367: my %roles = (
4368: '0' => &Apache::lonnet::plaintext('dc'),
4369: );
4370:
4371: foreach my $type (@types) {
4372: unless (($row eq 'registered') && ($key eq 'default')) {
4373: $datatable .= '<th>'.&mt($type).'</th>';
4374: }
4375: }
4376: unless (($row eq 'registered') && ($key eq 'default')) {
4377: $datatable .= '</tr><tr>';
4378: }
4379: foreach my $type (@types) {
4380: if ($type eq 'community') {
4381: $roles{'1'} = &mt('Community personnel');
4382: } else {
4383: $roles{'1'} = &mt('Course personnel');
4384: }
4385: $datatable .= '<td style="vertical-align: top">';
4386: if ($position eq 'top') {
4387: my %checked;
4388: if ($current{$type} eq '0') {
4389: $checked{'0'} = ' checked="checked"';
4390: } else {
4391: $checked{'1'} = ' checked="checked"';
4392: }
4393: foreach my $role ('1','0') {
4394: $datatable .= '<span class="LC_nobreak"><label>'.
4395: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4396: 'value="'.$role.'"'.$checked{$role}.' />'.
4397: $roles{$role}.'</label></span> ';
4398: }
4399: } else {
4400: if ($row eq 'types') {
4401: my %checked;
4402: if ($current{$type} =~ /^(all|dom)$/) {
4403: $checked{$1} = ' checked="checked"';
4404: } else {
4405: $checked{''} = ' checked="checked"';
4406: }
4407: foreach my $val ('','dom','all') {
4408: $datatable .= '<span class="LC_nobreak"><label>'.
4409: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4410: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4411: }
4412: } elsif ($row eq 'registered') {
4413: my %checked;
4414: if ($current{$type} eq '1') {
4415: $checked{'1'} = ' checked="checked"';
4416: } else {
4417: $checked{'0'} = ' checked="checked"';
4418: }
4419: foreach my $val ('0','1') {
4420: $datatable .= '<span class="LC_nobreak"><label>'.
4421: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4422: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4423: }
4424: } elsif ($row eq 'approval') {
4425: my %checked;
4426: if ($current{$type} =~ /^([12])$/) {
4427: $checked{$1} = ' checked="checked"';
4428: } else {
4429: $checked{'0'} = ' checked="checked"';
4430: }
4431: for my $val (0..2) {
4432: $datatable .= '<span class="LC_nobreak"><label>'.
4433: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4434: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4435: }
4436: } elsif ($row eq 'limit') {
4437: my %checked;
4438: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4439: $checked{$1} = ' checked="checked"';
4440: } else {
4441: $checked{'none'} = ' checked="checked"';
4442: }
4443: my $cap;
4444: if ($currentcap{$type} =~ /^\d+$/) {
4445: $cap = $currentcap{$type};
4446: }
4447: foreach my $val ('none','allstudents','selfenrolled') {
4448: $datatable .= '<span class="LC_nobreak"><label>'.
4449: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4450: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4451: }
4452: $datatable .= '<br />'.
4453: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4454: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4455: '</span>';
4456: }
4457: }
4458: $datatable .= '</td>';
4459: }
4460: $datatable .= '</tr>';
4461: }
4462: $datatable .= '</table></td></tr>';
4463: }
4464: } elsif ($position eq 'bottom') {
1.235 raeburn 4465: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4466: }
4467: $$rowtotal += $itemcount;
4468: return $datatable;
4469: }
4470:
4471: sub print_validation_rows {
4472: my ($caller,$dom,$settings,$rowtotal) = @_;
4473: my ($itemsref,$namesref,$fieldsref);
4474: if ($caller eq 'selfenroll') {
4475: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4476: } elsif ($caller eq 'requestcourses') {
4477: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4478: }
4479: my %currvalidation;
4480: if (ref($settings) eq 'HASH') {
4481: if (ref($settings->{'validation'}) eq 'HASH') {
4482: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 4483: }
1.235 raeburn 4484: }
4485: my $datatable;
4486: my $itemcount = 0;
4487: foreach my $item (@{$itemsref}) {
4488: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4489: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4490: $namesref->{$item}.
4491: '</span></td>'.
4492: '<td class="LC_left_item">';
4493: if (($item eq 'url') || ($item eq 'button')) {
4494: $datatable .= '<span class="LC_nobreak">'.
4495: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4496: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4497: } elsif ($item eq 'fields') {
4498: my @currfields;
4499: if (ref($currvalidation{$item}) eq 'ARRAY') {
4500: @currfields = @{$currvalidation{$item}};
4501: }
4502: foreach my $field (@{$fieldsref}) {
4503: my $check = '';
4504: if (grep(/^\Q$field\E$/,@currfields)) {
4505: $check = ' checked="checked"';
4506: }
4507: $datatable .= '<span class="LC_nobreak"><label>'.
4508: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4509: ' value="'.$field.'"'.$check.' />'.$field.
4510: '</label></span> ';
4511: }
4512: } elsif ($item eq 'markup') {
4513: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4514: $currvalidation{$item}.
1.231 raeburn 4515: '</textarea>';
1.235 raeburn 4516: }
4517: $datatable .= '</td></tr>'."\n";
4518: if (ref($rowtotal)) {
1.231 raeburn 4519: $itemcount ++;
4520: }
4521: }
1.235 raeburn 4522: if ($caller eq 'requestcourses') {
4523: my %currhash;
1.248 raeburn 4524: if (ref($settings) eq 'HASH') {
4525: if (ref($settings->{'validation'}) eq 'HASH') {
4526: if ($settings->{'validation'}{'dc'} ne '') {
4527: $currhash{$settings->{'validation'}{'dc'}} = 1;
4528: }
1.235 raeburn 4529: }
4530: }
4531: my $numinrow = 2;
4532: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4533: 'validationdc',%currhash);
1.247 raeburn 4534: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4535: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 4536: if ($numdc > 1) {
1.247 raeburn 4537: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 4538: } else {
1.247 raeburn 4539: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 4540: }
1.247 raeburn 4541: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 4542: $itemcount ++;
4543: }
4544: if (ref($rowtotal)) {
4545: $$rowtotal += $itemcount;
4546: }
1.231 raeburn 4547: return $datatable;
4548: }
4549:
1.137 raeburn 4550: sub print_usersessions {
4551: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 4552: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 4553: my (%by_ip,%by_location,@intdoms,@instdoms);
4554: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 4555:
4556: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4557: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4558: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4559: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4560: if ($position eq 'top') {
1.152 raeburn 4561: if (keys(%serverhomes) > 1) {
1.145 raeburn 4562: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 4563: my $curroffloadnow;
4564: if (ref($settings) eq 'HASH') {
4565: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4566: $curroffloadnow = $settings->{'offloadnow'};
4567: }
4568: }
4569: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4570: } else {
1.140 raeburn 4571: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 4572: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
4573: '</td></tr>';
1.140 raeburn 4574: }
1.137 raeburn 4575: } else {
1.279 raeburn 4576: my %titles = &usersession_titles();
4577: my ($prefix,@types);
4578: if ($position eq 'bottom') {
4579: $prefix = 'remote';
4580: @types = ('version','excludedomain','includedomain');
1.145 raeburn 4581: } else {
1.279 raeburn 4582: $prefix = 'hosted';
4583: @types = ('excludedomain','includedomain');
4584: }
4585: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4586: }
4587: $$rowtotal += $itemcount;
4588: return $datatable;
4589: }
4590:
4591: sub rules_by_location {
4592: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
4593: my ($datatable,$itemcount,$css_class);
4594: if (keys(%{$by_location}) == 0) {
4595: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4596: $datatable = '<tr'.$css_class.'><td colspan="2">'.
4597: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
4598: '</td></tr>';
4599: $itemcount = 1;
4600: } else {
4601: $itemcount = 0;
4602: my $numinrow = 5;
4603: my (%current,%checkedon,%checkedoff);
4604: my @locations = sort(keys(%{$by_location}));
4605: foreach my $type (@{$types}) {
4606: $checkedon{$type} = '';
4607: $checkedoff{$type} = ' checked="checked"';
4608: }
4609: if (ref($settings) eq 'HASH') {
4610: if (ref($settings->{$prefix}) eq 'HASH') {
4611: foreach my $key (keys(%{$settings->{$prefix}})) {
4612: $current{$key} = $settings->{$prefix}{$key};
4613: if ($key eq 'version') {
4614: if ($current{$key} ne '') {
1.145 raeburn 4615: $checkedon{$key} = ' checked="checked"';
4616: $checkedoff{$key} = '';
4617: }
1.279 raeburn 4618: } elsif (ref($current{$key}) eq 'ARRAY') {
4619: $checkedon{$key} = ' checked="checked"';
4620: $checkedoff{$key} = '';
1.137 raeburn 4621: }
4622: }
4623: }
1.279 raeburn 4624: }
4625: foreach my $type (@{$types}) {
4626: next if ($type ne 'version' && !@locations);
4627: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4628: $datatable .= '<tr'.$css_class.'>
4629: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4630: <span class="LC_nobreak">
4631: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4632: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4633: if ($type eq 'version') {
4634: my @lcversions = &Apache::lonnet::all_loncaparevs();
4635: my $selector = '<select name="'.$prefix.'_version">';
4636: foreach my $version (@lcversions) {
4637: my $selected = '';
4638: if ($current{'version'} eq $version) {
4639: $selected = ' selected="selected"';
1.145 raeburn 4640: }
1.279 raeburn 4641: $selector .= ' <option value="'.$version.'"'.
4642: $selected.'>'.$version.'</option>';
4643: }
4644: $selector .= '</select> ';
4645: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4646: } else {
4647: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4648: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4649: ' />'.(' 'x2).
4650: '<input type="button" value="'.&mt('uncheck all').'" '.
4651: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4652: "\n".
4653: '</div><div><table>';
4654: my $rem;
4655: for (my $i=0; $i<@locations; $i++) {
4656: my ($showloc,$value,$checkedtype);
4657: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4658: my $ip = $by_location->{$locations[$i]}->[0];
4659: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4660: $value = join(':',@{$by_ip->{$ip}});
4661: $showloc = join(', ',@{$by_ip->{$ip}});
4662: if (ref($current{$type}) eq 'ARRAY') {
4663: foreach my $loc (@{$by_ip->{$ip}}) {
4664: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4665: $checkedtype = ' checked="checked"';
4666: last;
1.145 raeburn 4667: }
1.138 raeburn 4668: }
4669: }
4670: }
1.137 raeburn 4671: }
1.279 raeburn 4672: $rem = $i%($numinrow);
4673: if ($rem == 0) {
4674: if ($i > 0) {
4675: $datatable .= '</tr>';
4676: }
4677: $datatable .= '<tr>';
4678: }
4679: $datatable .= '<td class="LC_left_item">'.
4680: '<span class="LC_nobreak"><label>'.
4681: '<input type="checkbox" name="'.$prefix.'_'.$type.
4682: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4683: '</label></span></td>';
4684: }
4685: $rem = @locations%($numinrow);
4686: my $colsleft = $numinrow - $rem;
4687: if ($colsleft > 1 ) {
4688: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4689: ' </td>';
4690: } elsif ($colsleft == 1) {
4691: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4692: }
1.279 raeburn 4693: $datatable .= '</tr></table>';
1.137 raeburn 4694: }
1.279 raeburn 4695: $datatable .= '</td></tr>';
4696: $itemcount ++;
1.137 raeburn 4697: }
4698: }
1.279 raeburn 4699: return ($datatable,$itemcount);
1.137 raeburn 4700: }
4701:
1.275 raeburn 4702: sub print_ssl {
4703: my ($position,$dom,$settings,$rowtotal) = @_;
4704: my ($css_class,$datatable);
4705: my $itemcount = 1;
4706: if ($position eq 'top') {
1.281 raeburn 4707: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4708: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4709: my $same_institution;
4710: if ($intdom ne '') {
4711: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4712: if (ref($internet_names) eq 'ARRAY') {
4713: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4714: $same_institution = 1;
4715: }
4716: }
4717: }
1.275 raeburn 4718: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 4719: $datatable = '<tr'.$css_class.'><td colspan="2">';
4720: if ($same_institution) {
4721: my %domservers = &Apache::lonnet::get_servers($dom);
4722: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
4723: } else {
4724: $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.");
4725: }
4726: $datatable .= '</td></tr>';
1.275 raeburn 4727: $itemcount ++;
4728: } else {
4729: my %titles = &ssl_titles();
4730: my (%by_ip,%by_location,@intdoms,@instdoms);
4731: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4732: my @alldoms = &Apache::lonnet::all_domains();
4733: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4734: my @domservers = &Apache::lonnet::get_servers($dom);
4735: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4736: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 4737: if (($position eq 'connto') || ($position eq 'connfrom')) {
4738: my $legacy;
4739: unless (ref($settings) eq 'HASH') {
4740: my $name;
4741: if ($position eq 'connto') {
4742: $name = 'loncAllowInsecure';
4743: } else {
4744: $name = 'londAllowInsecure';
4745: }
4746: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
4747: my @ids=&Apache::lonnet::current_machine_ids();
4748: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
4749: my %what = (
4750: $name => 1,
4751: );
4752: my ($result,$returnhash) =
4753: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
4754: if ($result eq 'ok') {
4755: if (ref($returnhash) eq 'HASH') {
4756: $legacy = $returnhash->{$name};
4757: }
4758: }
4759: } else {
4760: $legacy = $Apache::lonnet::perlvar{$name};
4761: }
4762: }
1.275 raeburn 4763: foreach my $type ('dom','intdom','other') {
4764: my %checked;
4765: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4766: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4767: '<td class="LC_right_item">';
4768: my $skip;
4769: if ($type eq 'dom') {
4770: unless (keys(%servers) > 1) {
4771: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4772: $skip = 1;
4773: }
4774: }
4775: if ($type eq 'intdom') {
4776: unless (@instdoms > 1) {
4777: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4778: $skip = 1;
4779: }
4780: } elsif ($type eq 'other') {
4781: if (keys(%by_location) == 0) {
4782: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4783: $skip = 1;
4784: }
4785: }
4786: unless ($skip) {
4787: $checked{'yes'} = ' checked="checked"';
4788: if (ref($settings) eq 'HASH') {
1.293 raeburn 4789: if (ref($settings->{$position}) eq 'HASH') {
4790: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 4791: $checked{$1} = $checked{'yes'};
4792: delete($checked{'yes'});
4793: }
4794: }
1.293 raeburn 4795: } else {
4796: if ($legacy == 0) {
4797: $checked{'req'} = $checked{'yes'};
4798: delete($checked{'yes'});
4799: }
1.275 raeburn 4800: }
4801: foreach my $option ('no','yes','req') {
4802: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 4803: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 4804: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4805: '</label></span>'.(' 'x2);
4806: }
4807: }
4808: $datatable .= '</td></tr>';
4809: $itemcount ++;
4810: }
4811: } else {
4812: my $prefix = 'replication';
4813: my @types = ('certreq','nocertreq');
1.279 raeburn 4814: if (keys(%by_location) == 0) {
4815: $datatable .= '<tr'.$css_class.'><td>'.
4816: &mt('Nothing to set here, as there are no other institutions').
4817: '</td></tr>';
4818: $itemcount ++;
1.275 raeburn 4819: } else {
1.279 raeburn 4820: ($datatable,$itemcount) =
4821: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 4822: }
4823: }
4824: }
4825: $$rowtotal += $itemcount;
4826: return $datatable;
4827: }
4828:
4829: sub ssl_titles {
4830: return &Apache::lonlocal::texthash (
4831: dom => 'LON-CAPA servers/VMs from same domain',
4832: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4833: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 4834: connto => 'Connections to other servers',
4835: connfrom => 'Connections from other servers',
1.275 raeburn 4836: replication => 'Replicating content to other institutions',
4837: certreq => 'Client certificate required, but specific domains exempt',
4838: nocertreq => 'No client certificate required, except for specific domains',
4839: no => 'SSL not used',
4840: yes => 'SSL Optional (used if available)',
4841: req => 'SSL Required',
4842: );
1.279 raeburn 4843: }
4844:
4845: sub print_trust {
4846: my ($prefix,$dom,$settings,$rowtotal) = @_;
4847: my ($css_class,$datatable,%checked,%choices);
4848: my (%by_ip,%by_location,@intdoms,@instdoms);
4849: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4850: my $itemcount = 1;
4851: my %titles = &trust_titles();
4852: my @types = ('exc','inc');
4853: if ($prefix eq 'top') {
4854: $prefix = 'content';
4855: } elsif ($prefix eq 'bottom') {
4856: $prefix = 'msg';
4857: }
4858: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4859: $$rowtotal += $itemcount;
4860: return $datatable;
4861: }
4862:
4863: sub trust_titles {
4864: return &Apache::lonlocal::texthash(
4865: content => "Access to this domain's content by others",
4866: shared => "Access to other domain's content by this domain",
4867: enroll => "Enrollment in this domain's courses by others",
4868: othcoau => "Co-author roles in this domain for others",
4869: coaurem => "Co-author roles for this domain's users elsewhere",
4870: domroles => "Domain roles in this domain assignable to others",
4871: catalog => "Course Catalog for this domain displayed elsewhere",
4872: reqcrs => "Requests for creation of courses in this domain by others",
4873: msg => "Users in other domains can send messages to this domain",
4874: exc => "Allow all, but exclude specific domains",
4875: inc => "Deny all, but include specific domains",
4876: );
1.275 raeburn 4877: }
4878:
1.138 raeburn 4879: sub build_location_hashes {
1.275 raeburn 4880: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4881: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4882: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4883: my %iphost = &Apache::lonnet::get_iphost();
4884: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4885: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4886: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4887: foreach my $id (@{$iphost{$primary_ip}}) {
4888: my $intdom = &Apache::lonnet::internet_dom($id);
4889: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4890: push(@{$intdoms},$intdom);
4891: }
4892: }
4893: }
4894: foreach my $ip (keys(%iphost)) {
4895: if (ref($iphost{$ip}) eq 'ARRAY') {
4896: foreach my $id (@{$iphost{$ip}}) {
4897: my $location = &Apache::lonnet::internet_dom($id);
4898: if ($location) {
1.275 raeburn 4899: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4900: my $dom = &Apache::lonnet::host_domain($id);
4901: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4902: push(@{$instdoms},$dom);
4903: }
4904: next;
4905: }
1.138 raeburn 4906: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4907: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4908: push(@{$by_ip->{$ip}},$location);
4909: }
4910: } else {
4911: $by_ip->{$ip} = [$location];
4912: }
4913: }
4914: }
4915: }
4916: }
4917: foreach my $ip (sort(keys(%{$by_ip}))) {
4918: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4919: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4920: my $first = $by_ip->{$ip}->[0];
4921: if (ref($by_location->{$first}) eq 'ARRAY') {
4922: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4923: push(@{$by_location->{$first}},$ip);
4924: }
4925: } else {
4926: $by_location->{$first} = [$ip];
4927: }
4928: }
4929: }
4930: return;
4931: }
4932:
1.145 raeburn 4933: sub current_offloads_to {
4934: my ($dom,$settings,$servers) = @_;
4935: my (%spareid,%otherdomconfigs);
1.152 raeburn 4936: if (ref($servers) eq 'HASH') {
1.145 raeburn 4937: foreach my $lonhost (sort(keys(%{$servers}))) {
4938: my $gotspares;
1.152 raeburn 4939: if (ref($settings) eq 'HASH') {
4940: if (ref($settings->{'spares'}) eq 'HASH') {
4941: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4942: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4943: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4944: $gotspares = 1;
4945: }
1.145 raeburn 4946: }
4947: }
4948: unless ($gotspares) {
4949: my $gotspares;
4950: my $serverhomeID =
4951: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4952: my $serverhomedom =
4953: &Apache::lonnet::host_domain($serverhomeID);
4954: if ($serverhomedom ne $dom) {
4955: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4956: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4957: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4958: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4959: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4960: $gotspares = 1;
4961: }
4962: }
4963: } else {
4964: $otherdomconfigs{$serverhomedom} =
4965: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4966: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4967: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4968: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4969: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4970: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4971: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4972: $gotspares = 1;
4973: }
4974: }
4975: }
4976: }
4977: }
4978: }
4979: }
4980: unless ($gotspares) {
4981: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4982: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4983: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4984: } else {
4985: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4986: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4987: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4988: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4989: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4990: } else {
1.150 raeburn 4991: my %what = (
4992: spareid => 1,
4993: );
4994: my ($result,$returnhash) =
4995: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4996: if ($result eq 'ok') {
4997: if (ref($returnhash) eq 'HASH') {
4998: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4999: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
5000: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
5001: }
5002: }
1.145 raeburn 5003: }
5004: }
5005: }
5006: }
5007: }
5008: }
5009: return %spareid;
5010: }
5011:
5012: sub spares_row {
1.261 raeburn 5013: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 5014: my $css_class;
5015: my $numinrow = 4;
5016: my $itemcount = 1;
5017: my $datatable;
1.152 raeburn 5018: my %typetitles = &sparestype_titles();
5019: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5020: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5021: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5022: my ($othercontrol,$serverdom);
5023: if ($serverhome ne $server) {
5024: $serverdom = &Apache::lonnet::host_domain($serverhome);
5025: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5026: } else {
5027: $serverdom = &Apache::lonnet::host_domain($server);
5028: if ($serverdom ne $dom) {
5029: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5030: }
5031: }
5032: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 5033: my $checkednow;
5034: if (ref($curroffloadnow) eq 'HASH') {
5035: if ($curroffloadnow->{$server}) {
5036: $checkednow = ' checked="checked"';
5037: }
5038: }
1.145 raeburn 5039: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5040: $datatable .= '<tr'.$css_class.'>
5041: <td rowspan="2">
1.183 bisitz 5042: <span class="LC_nobreak">'.
5043: &mt('[_1] when busy, offloads to:'
1.261 raeburn 5044: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 5045: '<span class="LC_nobreak">'."\n".
1.261 raeburn 5046: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5047: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 5048: "\n";
1.145 raeburn 5049: my (%current,%canselect);
1.152 raeburn 5050: my @choices =
5051: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5052: foreach my $type ('primary','default') {
5053: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5054: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5055: my @spares = @{$spareid->{$server}{$type}};
5056: if (@spares > 0) {
1.152 raeburn 5057: if ($othercontrol) {
5058: $current{$type} = join(', ',@spares);
5059: } else {
5060: $current{$type} .= '<table>';
5061: my $numspares = scalar(@spares);
5062: for (my $i=0; $i<@spares; $i++) {
5063: my $rem = $i%($numinrow);
5064: if ($rem == 0) {
5065: if ($i > 0) {
5066: $current{$type} .= '</tr>';
5067: }
5068: $current{$type} .= '<tr>';
1.145 raeburn 5069: }
1.152 raeburn 5070: $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'".');" /> '.
5071: $spareid->{$server}{$type}[$i].
5072: '</label></td>'."\n";
5073: }
5074: my $rem = @spares%($numinrow);
5075: my $colsleft = $numinrow - $rem;
5076: if ($colsleft > 1 ) {
5077: $current{$type} .= '<td colspan="'.$colsleft.
5078: '" class="LC_left_item">'.
5079: ' </td>';
5080: } elsif ($colsleft == 1) {
5081: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5082: }
1.152 raeburn 5083: $current{$type} .= '</tr></table>';
1.150 raeburn 5084: }
1.145 raeburn 5085: }
5086: }
5087: if ($current{$type} eq '') {
5088: $current{$type} = &mt('None specified');
5089: }
1.152 raeburn 5090: if ($othercontrol) {
5091: if ($type eq 'primary') {
5092: $canselect{$type} = $othercontrol;
5093: }
5094: } else {
5095: $canselect{$type} =
5096: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5097: '<select name="newspare_'.$type.'_'.$server.'" '.
5098: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5099: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5100: if (@choices > 0) {
5101: foreach my $lonhost (@choices) {
5102: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5103: }
5104: }
5105: $canselect{$type} .= '</select>'."\n";
5106: }
5107: } else {
5108: $current{$type} = &mt('Could not be determined');
5109: if ($type eq 'primary') {
5110: $canselect{$type} = $othercontrol;
5111: }
1.145 raeburn 5112: }
1.152 raeburn 5113: if ($type eq 'default') {
5114: $datatable .= '<tr'.$css_class.'>';
5115: }
5116: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5117: '<td>'.$current{$type}.'</td>'."\n".
5118: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5119: }
5120: $itemcount ++;
5121: }
5122: }
5123: $$rowtotal += $itemcount;
5124: return $datatable;
5125: }
5126:
1.152 raeburn 5127: sub possible_newspares {
5128: my ($server,$currspares,$serverhomes,$altids) = @_;
5129: my $serverhostname = &Apache::lonnet::hostname($server);
5130: my %excluded;
5131: if ($serverhostname ne '') {
5132: %excluded = (
5133: $serverhostname => 1,
5134: );
5135: }
5136: if (ref($currspares) eq 'HASH') {
5137: foreach my $type (keys(%{$currspares})) {
5138: if (ref($currspares->{$type}) eq 'ARRAY') {
5139: if (@{$currspares->{$type}} > 0) {
5140: foreach my $curr (@{$currspares->{$type}}) {
5141: my $hostname = &Apache::lonnet::hostname($curr);
5142: $excluded{$hostname} = 1;
5143: }
5144: }
5145: }
5146: }
5147: }
5148: my @choices;
5149: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5150: if (keys(%{$serverhomes}) > 1) {
5151: foreach my $name (sort(keys(%{$serverhomes}))) {
5152: unless ($excluded{$name}) {
5153: if (exists($altids->{$serverhomes->{$name}})) {
5154: push(@choices,$altids->{$serverhomes->{$name}});
5155: } else {
5156: push(@choices,$serverhomes->{$name});
1.145 raeburn 5157: }
5158: }
5159: }
5160: }
5161: }
1.152 raeburn 5162: return sort(@choices);
1.145 raeburn 5163: }
5164:
1.150 raeburn 5165: sub print_loadbalancing {
5166: my ($dom,$settings,$rowtotal) = @_;
5167: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5168: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5169: my $numinrow = 1;
5170: my $datatable;
5171: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5172: my (%currbalancer,%currtargets,%currrules,%existing);
5173: if (ref($settings) eq 'HASH') {
5174: %existing = %{$settings};
5175: }
5176: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5177: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5178: \%currtargets,\%currrules);
1.150 raeburn 5179: } else {
5180: return;
5181: }
5182: my ($othertitle,$usertypes,$types) =
5183: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5184: my $rownum = 8;
1.150 raeburn 5185: if (ref($types) eq 'ARRAY') {
5186: $rownum += scalar(@{$types});
5187: }
1.171 raeburn 5188: my @css_class = ('LC_odd_row','LC_even_row');
5189: my $balnum = 0;
5190: my $islast;
5191: my (@toshow,$disabledtext);
5192: if (keys(%currbalancer) > 0) {
5193: @toshow = sort(keys(%currbalancer));
5194: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5195: push(@toshow,'');
5196: }
5197: } else {
5198: @toshow = ('');
5199: $disabledtext = &mt('No existing load balancer');
5200: }
5201: foreach my $lonhost (@toshow) {
5202: if ($balnum == scalar(@toshow)-1) {
5203: $islast = 1;
5204: } else {
5205: $islast = 0;
5206: }
5207: my $cssidx = $balnum%2;
5208: my $targets_div_style = 'display: none';
5209: my $disabled_div_style = 'display: block';
5210: my $homedom_div_style = 'display: none';
5211: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 5212: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 5213: '<p>';
5214: if ($lonhost eq '') {
1.210 raeburn 5215: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 5216: if (keys(%currbalancer) > 0) {
5217: $datatable .= &mt('Add balancer:');
5218: } else {
5219: $datatable .= &mt('Enable balancer:');
5220: }
5221: $datatable .= ' '.
5222: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5223: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5224: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5225: '<option value="" selected="selected">'.&mt('None').
5226: '</option>'."\n";
5227: foreach my $server (sort(keys(%servers))) {
5228: next if ($currbalancer{$server});
5229: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5230: }
1.210 raeburn 5231: $datatable .=
1.171 raeburn 5232: '</select>'."\n".
5233: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5234: } else {
5235: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5236: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5237: &mt('Stop balancing').'</label>'.
5238: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5239: $targets_div_style = 'display: block';
5240: $disabled_div_style = 'display: none';
5241: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5242: $homedom_div_style = 'display: block';
5243: }
5244: }
1.306 raeburn 5245: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 5246: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5247: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5248: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5249: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5250: my @sparestypes = ('primary','default');
5251: my %typetitles = &sparestype_titles();
1.284 raeburn 5252: my %hostherechecked = (
5253: no => ' checked="checked"',
5254: );
1.171 raeburn 5255: foreach my $sparetype (@sparestypes) {
5256: my $targettable;
5257: for (my $i=0; $i<$numspares; $i++) {
5258: my $checked;
5259: if (ref($currtargets{$lonhost}) eq 'HASH') {
5260: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5261: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5262: $checked = ' checked="checked"';
5263: }
5264: }
5265: }
5266: my ($chkboxval,$disabled);
5267: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5268: $chkboxval = $spares[$i];
5269: }
5270: if (exists($currbalancer{$spares[$i]})) {
5271: $disabled = ' disabled="disabled"';
5272: }
1.210 raeburn 5273: $targettable .=
1.253 raeburn 5274: '<td><span class="LC_nobreak"><label>'.
5275: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 5276: $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 5277: '</span></label></span></td>';
1.171 raeburn 5278: my $rem = $i%($numinrow);
5279: if ($rem == 0) {
5280: if (($i > 0) && ($i < $numspares-1)) {
5281: $targettable .= '</tr>';
5282: }
5283: if ($i < $numspares-1) {
5284: $targettable .= '<tr>';
1.150 raeburn 5285: }
5286: }
5287: }
1.171 raeburn 5288: if ($targettable ne '') {
5289: my $rem = $numspares%($numinrow);
5290: my $colsleft = $numinrow - $rem;
5291: if ($colsleft > 1 ) {
5292: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5293: ' </td>';
5294: } elsif ($colsleft == 1) {
5295: $targettable .= '<td class="LC_left_item"> </td>';
5296: }
5297: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5298: '<table><tr>'.$targettable.'</tr></table><br />';
5299: }
1.284 raeburn 5300: $hostherechecked{$sparetype} = '';
5301: if (ref($currtargets{$lonhost}) eq 'HASH') {
5302: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5303: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5304: $hostherechecked{$sparetype} = ' checked="checked"';
5305: $hostherechecked{'no'} = '';
5306: }
5307: }
5308: }
5309: }
5310: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5311: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5312: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5313: foreach my $sparetype (@sparestypes) {
5314: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5315: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5316: '</i></label><br />';
1.171 raeburn 5317: }
5318: $datatable .= '</div></td></tr>'.
5319: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5320: $othertitle,$usertypes,$types,\%servers,
5321: \%currbalancer,$lonhost,
5322: $targets_div_style,$homedom_div_style,
5323: $css_class[$cssidx],$balnum,$islast);
5324: $$rowtotal += $rownum;
5325: $balnum ++;
5326: }
5327: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5328: return $datatable;
5329: }
5330:
5331: sub get_loadbalancers_config {
5332: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5333: return unless ((ref($servers) eq 'HASH') &&
5334: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5335: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5336: if (keys(%{$existing}) > 0) {
5337: my $oldlonhost;
5338: foreach my $key (sort(keys(%{$existing}))) {
5339: if ($key eq 'lonhost') {
5340: $oldlonhost = $existing->{'lonhost'};
5341: $currbalancer->{$oldlonhost} = 1;
5342: } elsif ($key eq 'targets') {
5343: if ($oldlonhost) {
5344: $currtargets->{$oldlonhost} = $existing->{'targets'};
5345: }
5346: } elsif ($key eq 'rules') {
5347: if ($oldlonhost) {
5348: $currrules->{$oldlonhost} = $existing->{'rules'};
5349: }
5350: } elsif (ref($existing->{$key}) eq 'HASH') {
5351: $currbalancer->{$key} = 1;
5352: $currtargets->{$key} = $existing->{$key}{'targets'};
5353: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5354: }
5355: }
1.171 raeburn 5356: } else {
5357: my ($balancerref,$targetsref) =
5358: &Apache::lonnet::get_lonbalancer_config($servers);
5359: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5360: foreach my $server (sort(keys(%{$balancerref}))) {
5361: $currbalancer->{$server} = 1;
5362: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5363: }
5364: }
5365: }
1.171 raeburn 5366: return;
1.150 raeburn 5367: }
5368:
5369: sub loadbalancing_rules {
5370: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 5371: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5372: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5373: my $output;
1.171 raeburn 5374: my $num = 0;
1.210 raeburn 5375: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5376: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5377: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5378: foreach my $type (@{$alltypes}) {
1.171 raeburn 5379: $num ++;
1.150 raeburn 5380: my $current;
5381: if (ref($currrules) eq 'HASH') {
5382: $current = $currrules->{$type};
5383: }
1.253 raeburn 5384: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 5385: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5386: $current = '';
5387: }
5388: }
5389: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 5390: $servers,$currbalancer,$lonhost,$dom,
5391: $targets_div_style,$homedom_div_style,
5392: $css_class,$balnum,$num,$islast);
1.150 raeburn 5393: }
5394: }
5395: return $output;
5396: }
5397:
5398: sub loadbalancing_titles {
5399: my ($dom,$intdom,$usertypes,$types) = @_;
5400: my %othertypes = (
5401: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5402: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5403: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5404: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 5405: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5406: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5407: );
1.209 raeburn 5408: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 5409: my @available;
1.150 raeburn 5410: if (ref($types) eq 'ARRAY') {
1.302 raeburn 5411: @available = @{$types};
1.150 raeburn 5412: }
1.302 raeburn 5413: unless (grep(/^default$/,@available)) {
5414: push(@available,'default');
5415: }
5416: unshift(@alltypes,@available);
1.150 raeburn 5417: my %titles;
5418: foreach my $type (@alltypes) {
5419: if ($type =~ /^_LC_/) {
5420: $titles{$type} = $othertypes{$type};
5421: } elsif ($type eq 'default') {
5422: $titles{$type} = &mt('All users from [_1]',$dom);
5423: if (ref($types) eq 'ARRAY') {
5424: if (@{$types} > 0) {
5425: $titles{$type} = &mt('Other users from [_1]',$dom);
5426: }
5427: }
5428: } elsif (ref($usertypes) eq 'HASH') {
5429: $titles{$type} = $usertypes->{$type};
5430: }
5431: }
5432: return (\@alltypes,\%othertypes,\%titles);
5433: }
5434:
5435: sub loadbalance_rule_row {
1.171 raeburn 5436: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5437: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 5438: my @rulenames;
1.150 raeburn 5439: my %ruletitles = &offloadtype_text();
1.209 raeburn 5440: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 5441: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5442: } else {
1.209 raeburn 5443: @rulenames = ('default','homeserver');
5444: if ($type eq '_LC_external') {
5445: push(@rulenames,'externalbalancer');
5446: } else {
5447: push(@rulenames,'specific');
5448: }
5449: push(@rulenames,'none');
1.150 raeburn 5450: }
5451: my $style = $targets_div_style;
1.253 raeburn 5452: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5453: $style = $homedom_div_style;
5454: }
1.171 raeburn 5455: my $space;
5456: if ($islast && $num == 1) {
5457: $space = '<div display="inline-block"> </div>';
5458: }
1.210 raeburn 5459: my $output =
1.306 raeburn 5460: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 5461: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5462: '<td valaign="top">'.$space.
5463: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5464: for (my $i=0; $i<@rulenames; $i++) {
5465: my $rule = $rulenames[$i];
5466: my ($checked,$extra);
5467: if ($rulenames[$i] eq 'default') {
5468: $rule = '';
5469: }
5470: if ($rulenames[$i] eq 'specific') {
5471: if (ref($servers) eq 'HASH') {
5472: my $default;
5473: if (($current ne '') && (exists($servers->{$current}))) {
5474: $checked = ' checked="checked"';
5475: }
5476: unless ($checked) {
5477: $default = ' selected="selected"';
5478: }
1.210 raeburn 5479: $extra =
1.171 raeburn 5480: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5481: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5482: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5483: '<option value=""'.$default.'></option>'."\n";
5484: foreach my $server (sort(keys(%{$servers}))) {
5485: if (ref($currbalancer) eq 'HASH') {
5486: next if (exists($currbalancer->{$server}));
5487: }
1.150 raeburn 5488: my $selected;
1.171 raeburn 5489: if ($server eq $current) {
1.150 raeburn 5490: $selected = ' selected="selected"';
5491: }
1.171 raeburn 5492: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5493: }
5494: $extra .= '</select>';
5495: }
5496: } elsif ($rule eq $current) {
5497: $checked = ' checked="checked"';
5498: }
5499: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 5500: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5501: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5502: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 5503: ')"'.$checked.' /> ';
5504: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
5505: $output .= $ruletitles{'particular'};
5506: } else {
5507: $output .= $ruletitles{$rulenames[$i]};
5508: }
5509: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5510: }
5511: $output .= '</div></td></tr>'."\n";
5512: return $output;
5513: }
5514:
5515: sub offloadtype_text {
5516: my %ruletitles = &Apache::lonlocal::texthash (
5517: 'default' => 'Offloads to default destinations',
5518: 'homeserver' => "Offloads to user's home server",
5519: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5520: 'specific' => 'Offloads to specific server',
1.161 raeburn 5521: 'none' => 'No offload',
1.209 raeburn 5522: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5523: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 5524: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5525: );
5526: return %ruletitles;
5527: }
5528:
5529: sub sparestype_titles {
5530: my %typestitles = &Apache::lonlocal::texthash (
5531: 'primary' => 'primary',
5532: 'default' => 'default',
5533: );
5534: return %typestitles;
5535: }
5536:
1.28 raeburn 5537: sub contact_titles {
5538: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 5539: 'supportemail' => 'Support E-mail address',
5540: 'adminemail' => 'Default Server Admin E-mail address',
5541: 'errormail' => 'Error reports to be e-mailed to',
5542: 'packagesmail' => 'Package update alerts to be e-mailed to',
5543: 'helpdeskmail' => "Helpdesk requests for this domain's users",
1.289 raeburn 5544: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
1.286 raeburn 5545: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5546: 'requestsmail' => 'E-mail from course requests requiring approval',
5547: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 5548: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5549: );
5550: my %short_titles = &Apache::lonlocal::texthash (
5551: adminemail => 'Admin E-mail address',
5552: supportemail => 'Support E-mail',
5553: );
5554: return (\%titles,\%short_titles);
5555: }
5556:
1.286 raeburn 5557: sub helpform_fields {
5558: my %titles = &Apache::lonlocal::texthash (
5559: 'username' => 'Name',
5560: 'user' => 'Username/domain',
5561: 'phone' => 'Phone',
5562: 'cc' => 'Cc e-mail',
5563: 'course' => 'Course Details',
5564: 'section' => 'Sections',
1.289 raeburn 5565: 'screenshot' => 'File upload',
1.286 raeburn 5566: );
5567: my @fields = ('username','phone','user','course','section','cc','screenshot');
5568: my %possoptions = (
5569: username => ['yes','no','req'],
1.289 raeburn 5570: phone => ['yes','no','req'],
1.286 raeburn 5571: user => ['yes','no'],
1.289 raeburn 5572: cc => ['yes','no'],
1.286 raeburn 5573: course => ['yes','no'],
5574: section => ['yes','no'],
5575: screenshot => ['yes','no'],
5576: );
5577: my %fieldoptions = &Apache::lonlocal::texthash (
5578: 'yes' => 'Optional',
5579: 'req' => 'Required',
5580: 'no' => "Not shown",
5581: );
5582: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5583: }
5584:
1.72 raeburn 5585: sub tool_titles {
5586: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 5587: aboutme => 'Personal web page',
1.86 raeburn 5588: blog => 'Blog',
1.162 raeburn 5589: webdav => 'WebDAV',
1.86 raeburn 5590: portfolio => 'Portfolio',
1.88 bisitz 5591: official => 'Official courses (with institutional codes)',
5592: unofficial => 'Unofficial courses',
1.98 raeburn 5593: community => 'Communities',
1.216 raeburn 5594: textbook => 'Textbook courses',
1.271 raeburn 5595: placement => 'Placement tests',
1.86 raeburn 5596: );
1.72 raeburn 5597: return %titles;
5598: }
5599:
1.101 raeburn 5600: sub courserequest_titles {
5601: my %titles = &Apache::lonlocal::texthash (
5602: official => 'Official',
5603: unofficial => 'Unofficial',
5604: community => 'Communities',
1.216 raeburn 5605: textbook => 'Textbook',
1.271 raeburn 5606: placement => 'Placement tests',
1.101 raeburn 5607: norequest => 'Not allowed',
1.104 raeburn 5608: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5609: validate => 'With validation',
5610: autolimit => 'Numerical limit',
1.103 raeburn 5611: unlimited => '(blank for unlimited)',
1.101 raeburn 5612: );
5613: return %titles;
5614: }
5615:
1.163 raeburn 5616: sub authorrequest_titles {
5617: my %titles = &Apache::lonlocal::texthash (
5618: norequest => 'Not allowed',
5619: approval => 'Approval by Dom. Coord.',
5620: automatic => 'Automatic approval',
5621: );
5622: return %titles;
1.210 raeburn 5623: }
1.163 raeburn 5624:
1.101 raeburn 5625: sub courserequest_conditions {
5626: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5627: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 5628: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5629: );
5630: return %conditions;
5631: }
5632:
5633:
1.27 raeburn 5634: sub print_usercreation {
1.30 raeburn 5635: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5636: my $numinrow = 4;
1.28 raeburn 5637: my $datatable;
5638: if ($position eq 'top') {
1.30 raeburn 5639: $$rowtotal ++;
1.34 raeburn 5640: my $rowcount = 0;
1.32 raeburn 5641: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5642: if (ref($rules) eq 'HASH') {
5643: if (keys(%{$rules}) > 0) {
1.32 raeburn 5644: $datatable .= &user_formats_row('username',$settings,$rules,
5645: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5646: $$rowtotal ++;
1.32 raeburn 5647: $rowcount ++;
5648: }
5649: }
5650: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5651: if (ref($idrules) eq 'HASH') {
5652: if (keys(%{$idrules}) > 0) {
5653: $datatable .= &user_formats_row('id',$settings,$idrules,
5654: $idruleorder,$numinrow,$rowcount);
5655: $$rowtotal ++;
5656: $rowcount ++;
1.28 raeburn 5657: }
5658: }
1.39 raeburn 5659: if ($rowcount == 0) {
5660: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5661: $$rowtotal ++;
5662: $rowcount ++;
5663: }
1.34 raeburn 5664: } elsif ($position eq 'middle') {
1.224 raeburn 5665: my @creators = ('author','course','requestcrs');
1.37 raeburn 5666: my ($rules,$ruleorder) =
5667: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5668: my %lt = &usercreation_types();
5669: my %checked;
5670: if (ref($settings) eq 'HASH') {
5671: if (ref($settings->{'cancreate'}) eq 'HASH') {
5672: foreach my $item (@creators) {
5673: $checked{$item} = $settings->{'cancreate'}{$item};
5674: }
5675: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5676: foreach my $item (@creators) {
5677: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5678: $checked{$item} = 'none';
5679: }
5680: }
5681: }
5682: }
5683: my $rownum = 0;
5684: foreach my $item (@creators) {
5685: $rownum ++;
1.224 raeburn 5686: if ($checked{$item} eq '') {
5687: $checked{$item} = 'any';
1.34 raeburn 5688: }
5689: my $css_class;
5690: if ($rownum%2) {
5691: $css_class = '';
5692: } else {
5693: $css_class = ' class="LC_odd_row" ';
5694: }
5695: $datatable .= '<tr'.$css_class.'>'.
5696: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 5697: '</span></td><td style="text-align: right">';
1.224 raeburn 5698: my @options = ('any');
5699: if (ref($rules) eq 'HASH') {
5700: if (keys(%{$rules}) > 0) {
5701: push(@options,('official','unofficial'));
1.37 raeburn 5702: }
5703: }
1.224 raeburn 5704: push(@options,'none');
1.37 raeburn 5705: foreach my $option (@options) {
1.50 raeburn 5706: my $type = 'radio';
1.34 raeburn 5707: my $check = ' ';
1.224 raeburn 5708: if ($checked{$item} eq $option) {
5709: $check = ' checked="checked" ';
1.34 raeburn 5710: }
5711: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5712: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5713: $item.'" value="'.$option.'"'.$check.'/> '.
5714: $lt{$option}.'</label> </span>';
5715: }
5716: $datatable .= '</td></tr>';
5717: }
1.28 raeburn 5718: } else {
5719: my @contexts = ('author','course','domain');
5720: my @authtypes = ('int','krb4','krb5','loc');
5721: my %checked;
5722: if (ref($settings) eq 'HASH') {
5723: if (ref($settings->{'authtypes'}) eq 'HASH') {
5724: foreach my $item (@contexts) {
5725: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5726: foreach my $auth (@authtypes) {
5727: if ($settings->{'authtypes'}{$item}{$auth}) {
5728: $checked{$item}{$auth} = ' checked="checked" ';
5729: }
5730: }
5731: }
5732: }
1.27 raeburn 5733: }
1.35 raeburn 5734: } else {
5735: foreach my $item (@contexts) {
1.36 raeburn 5736: foreach my $auth (@authtypes) {
1.35 raeburn 5737: $checked{$item}{$auth} = ' checked="checked" ';
5738: }
5739: }
1.27 raeburn 5740: }
1.28 raeburn 5741: my %title = &context_names();
5742: my %authname = &authtype_names();
5743: my $rownum = 0;
5744: my $css_class;
5745: foreach my $item (@contexts) {
5746: if ($rownum%2) {
5747: $css_class = '';
5748: } else {
5749: $css_class = ' class="LC_odd_row" ';
5750: }
1.30 raeburn 5751: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5752: '<td>'.$title{$item}.
5753: '</td><td class="LC_left_item">'.
5754: '<span class="LC_nobreak">';
5755: foreach my $auth (@authtypes) {
5756: $datatable .= '<label>'.
5757: '<input type="checkbox" name="'.$item.'_auth" '.
5758: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5759: $authname{$auth}.'</label> ';
5760: }
5761: $datatable .= '</span></td></tr>';
5762: $rownum ++;
1.27 raeburn 5763: }
1.30 raeburn 5764: $$rowtotal += $rownum;
1.27 raeburn 5765: }
5766: return $datatable;
5767: }
5768:
1.224 raeburn 5769: sub print_selfcreation {
5770: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 5771: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
5772: $emaildomain,$datatable);
1.224 raeburn 5773: if (ref($settings) eq 'HASH') {
5774: if (ref($settings->{'cancreate'}) eq 'HASH') {
5775: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5776: if (ref($createsettings) eq 'HASH') {
5777: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5778: @selfcreate = @{$createsettings->{'selfcreate'}};
5779: } elsif ($createsettings->{'selfcreate'} ne '') {
5780: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5781: @selfcreate = ('email','login','sso');
5782: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5783: @selfcreate = ($createsettings->{'selfcreate'});
5784: }
5785: }
5786: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5787: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5788: }
1.305 raeburn 5789: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
5790: $emailoptions = $createsettings->{'emailoptions'};
5791: }
1.303 raeburn 5792: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
5793: $emailverified = $createsettings->{'emailverified'};
5794: }
5795: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
5796: $emaildomain = $createsettings->{'emaildomain'};
5797: }
1.224 raeburn 5798: }
5799: }
5800: }
5801: my %radiohash;
5802: my $numinrow = 4;
5803: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 5804: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 5805: if ($position eq 'top') {
5806: my %choices = &Apache::lonlocal::texthash (
5807: cancreate_login => 'Institutional Login',
5808: cancreate_sso => 'Institutional Single Sign On',
5809: );
5810: my @toggles = sort(keys(%choices));
5811: my %defaultchecked = (
5812: 'cancreate_login' => 'off',
5813: 'cancreate_sso' => 'off',
5814: );
1.228 raeburn 5815: my ($onclick,$itemcount);
1.224 raeburn 5816: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5817: \%choices,$itemcount,$onclick);
1.228 raeburn 5818: $$rowtotal += $itemcount;
5819:
1.224 raeburn 5820: if (ref($usertypes) eq 'HASH') {
5821: if (keys(%{$usertypes}) > 0) {
5822: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5823: $dom,$numinrow,$othertitle,
1.305 raeburn 5824: 'statustocreate',$rowtotal);
1.224 raeburn 5825: $$rowtotal ++;
5826: }
5827: }
1.240 raeburn 5828: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5829: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5830: $fieldtitles{'inststatus'} = &mt('Institutional status');
5831: my $rem;
5832: my $numperrow = 2;
5833: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5834: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5835: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5836: '<td class="LC_left_item">'."\n".
5837: '<table><tr><td>'."\n";
5838: for (my $i=0; $i<@fields; $i++) {
5839: $rem = $i%($numperrow);
5840: if ($rem == 0) {
5841: if ($i > 0) {
5842: $datatable .= '</tr>';
5843: }
5844: $datatable .= '<tr>';
5845: }
5846: my $currval;
1.248 raeburn 5847: if (ref($createsettings) eq 'HASH') {
5848: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5849: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5850: }
1.240 raeburn 5851: }
5852: $datatable .= '<td class="LC_left_item">'.
5853: '<span class="LC_nobreak">'.
5854: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5855: 'value="'.$currval.'" size="10" /> '.
5856: $fieldtitles{$fields[$i]}.'</span></td>';
5857: }
5858: my $colsleft = $numperrow - $rem;
5859: if ($colsleft > 1 ) {
5860: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5861: ' </td>';
5862: } elsif ($colsleft == 1) {
5863: $datatable .= '<td class="LC_left_item"> </td>';
5864: }
5865: $datatable .= '</tr></table></td></tr>';
5866: $$rowtotal ++;
1.224 raeburn 5867: } elsif ($position eq 'middle') {
5868: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 5869: my @posstypes;
1.224 raeburn 5870: if (ref($types) eq 'ARRAY') {
1.302 raeburn 5871: @posstypes = @{$types};
5872: }
5873: unless (grep(/^default$/,@posstypes)) {
5874: push(@posstypes,'default');
5875: }
5876: my %usertypeshash;
5877: if (ref($usertypes) eq 'HASH') {
5878: %usertypeshash = %{$usertypes};
5879: }
5880: $usertypeshash{'default'} = $othertitle;
5881: foreach my $status (@posstypes) {
5882: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5883: $numinrow,$$rowtotal,\%usertypeshash);
5884: $$rowtotal ++;
1.224 raeburn 5885: }
5886: } else {
1.236 raeburn 5887: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 5888: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 5889: );
5890: my @toggles = sort(keys(%choices));
5891: my %defaultchecked = (
5892: 'cancreate_email' => 'off',
5893: );
1.305 raeburn 5894: my $customclass = 'LC_selfcreate_email';
5895: my $classprefix = 'LC_canmodify_emailusername_';
5896: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 5897: my $display = 'none';
1.305 raeburn 5898: my $rowstyle = 'display:none';
1.236 raeburn 5899: if (grep(/^\Qemail\E$/,@selfcreate)) {
5900: $display = 'block';
1.305 raeburn 5901: $rowstyle = 'display:table-row';
1.236 raeburn 5902: }
1.305 raeburn 5903: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
5904: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5905: \%choices,$$rowtotal,$onclick);
5906: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
5907: $rowstyle);
5908: $$rowtotal ++;
5909: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
5910: $rowstyle);
5911: $$rowtotal ++;
5912: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 5913: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 5914: my ($emailrules,$emailruleorder) =
5915: &Apache::lonnet::inst_userrules($dom,'email');
5916: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5917: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5918: if (ref($types) eq 'ARRAY') {
5919: @posstypes = @{$types};
5920: }
5921: if (@posstypes) {
5922: unless (grep(/^default$/,@posstypes)) {
5923: push(@posstypes,'default');
1.302 raeburn 5924: }
5925: if (ref($usertypes) eq 'HASH') {
5926: %usertypeshash = %{$usertypes};
5927: }
1.305 raeburn 5928: my $currassign;
5929: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
5930: $currassign = {
5931: selfassign => $domdefaults{'inststatusguest'},
5932: };
5933: @ordered = @{$domdefaults{'inststatusguest'}};
5934: } else {
5935: $currassign = { selfassign => [] };
5936: }
5937: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
5938: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
5939: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
5940: $numinrow,$othertitle,'selfassign',
5941: $rowtotal,$onclicktypes,$customclass,
5942: $rowstyle);
5943: $$rowtotal ++;
1.302 raeburn 5944: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 5945: foreach my $status (@posstypes) {
5946: my $css_class;
5947: if ($$rowtotal%2) {
5948: $css_class = 'LC_odd_row ';
5949: }
5950: $css_class .= $customclass;
5951: my $rowid = $optionsprefix.$status;
5952: my $hidden = 1;
5953: my $currstyle = 'display:none';
5954: if (grep(/^\Q$status\E$/,@ordered)) {
5955: $currstyle = $rowstyle;
5956: $hidden = 0;
5957: }
5958: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5959: $emailrules,$emailruleorder,$settings,$status,$rowid,
5960: $usertypeshash{$status},$css_class,$currstyle,$intdom);
5961: unless ($hidden) {
5962: $$rowtotal ++;
5963: }
1.224 raeburn 5964: }
1.302 raeburn 5965: } else {
1.305 raeburn 5966: my $css_class;
5967: if ($$rowtotal%2) {
5968: $css_class = 'LC_odd_row ';
5969: }
5970: $css_class .= $customclass;
1.302 raeburn 5971: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 5972: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5973: $emailrules,$emailruleorder,$settings,'default','',
5974: $othertitle,$css_class,$rowstyle,$intdom);
5975: $$rowtotal ++;
1.224 raeburn 5976: }
5977: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5978: $numinrow = 1;
1.305 raeburn 5979: if (@posstypes) {
5980: foreach my $status (@posstypes) {
5981: my $rowid = $classprefix.$status;
5982: my $datarowstyle = 'display:none';
5983: if (grep(/^\Q$status\E$/,@ordered)) {
5984: $datarowstyle = $rowstyle;
5985: }
5986: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5987: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5988: $infotitles,$rowid,$customclass,$datarowstyle);
5989: unless ($datarowstyle eq 'display:none') {
5990: $$rowtotal ++;
5991: }
1.224 raeburn 5992: }
1.305 raeburn 5993: } else {
5994: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
5995: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5996: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 5997: }
5998: }
5999: return $datatable;
6000: }
6001:
1.305 raeburn 6002: sub selfcreate_javascript {
6003: return <<"ENDSCRIPT";
6004:
6005: <script type="text/javascript">
6006: // <![CDATA[
6007:
6008: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
6009: var x = document.getElementsByClassName(target);
6010: var insttypes = 0;
6011: var insttypeRegExp = new RegExp(prefix);
6012: if ((x.length != undefined) && (x.length > 0)) {
6013: if (form.elements[radio].length != undefined) {
6014: for (var i=0; i<form.elements[radio].length; i++) {
6015: if (form.elements[radio][i].checked) {
6016: if (form.elements[radio][i].value == 1) {
6017: for (var j=0; j<x.length; j++) {
6018: if (x[j].id == 'undefined') {
6019: x[j].style.display = 'table-row';
6020: } else if (insttypeRegExp.test(x[j].id)) {
6021: insttypes ++;
6022: } else {
6023: x[j].style.display = 'table-row';
6024: }
6025: }
6026: } else {
6027: for (var j=0; j<x.length; j++) {
6028: x[j].style.display = 'none';
6029: }
1.236 raeburn 6030: }
1.305 raeburn 6031: break;
6032: }
6033: }
6034: if (insttypes > 0) {
6035: toggleDataRow(form,checkbox,target,altprefix);
6036: toggleDataRow(form,checkbox,target,prefix,1);
6037: }
6038: }
6039: }
6040: return;
6041: }
6042:
6043: function toggleDataRow(form,checkbox,target,prefix,docount) {
6044: if (form.elements[checkbox].length != undefined) {
6045: var count = 0;
6046: if (docount) {
6047: for (var i=0; i<form.elements[checkbox].length; i++) {
6048: if (form.elements[checkbox][i].checked) {
6049: count ++;
1.236 raeburn 6050: }
1.305 raeburn 6051: }
6052: }
6053: for (var i=0; i<form.elements[checkbox].length; i++) {
6054: var type = form.elements[checkbox][i].value;
6055: if (document.getElementById(prefix+type)) {
6056: if (form.elements[checkbox][i].checked) {
6057: document.getElementById(prefix+type).style.display = 'table-row';
6058: if (count % 2 == 1) {
6059: document.getElementById(prefix+type).className = target+' LC_odd_row';
6060: } else {
6061: document.getElementById(prefix+type).className = target;
1.236 raeburn 6062: }
1.305 raeburn 6063: count ++;
1.236 raeburn 6064: } else {
1.305 raeburn 6065: document.getElementById(prefix+type).style.display = 'none';
6066: }
6067: }
6068: }
6069: }
6070: return;
6071: }
6072:
6073: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
6074: var caller = radio+'_'+status;
6075: if (form.elements[caller].length != undefined) {
6076: for (var i=0; i<form.elements[caller].length; i++) {
6077: if (form.elements[caller][i].checked) {
6078: if (document.getElementById(altprefix+'_inst_'+status)) {
6079: var curr = form.elements[caller][i].value;
6080: if (prefix) {
6081: document.getElementById(prefix+'_'+status).style.display = 'none';
6082: }
6083: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
6084: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
6085: if (curr == 'custom') {
6086: if (prefix) {
6087: document.getElementById(prefix+'_'+status).style.display = 'inline';
6088: }
6089: } else if (curr == 'inst') {
6090: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
6091: } else if (curr == 'noninst') {
6092: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 6093: }
1.305 raeburn 6094: break;
1.236 raeburn 6095: }
6096: }
6097: }
6098: }
6099: }
6100:
1.305 raeburn 6101: // ]]>
6102: </script>
6103:
6104: ENDSCRIPT
6105: }
6106:
6107: sub noninst_users {
6108: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
6109: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
6110: my $class = 'LC_left_item';
6111: if ($css_class) {
6112: $css_class = ' class="'.$css_class.'"';
6113: }
6114: if ($rowid) {
6115: $rowid = ' id="'.$rowid.'"';
6116: }
6117: if ($rowstyle) {
6118: $rowstyle = ' style="'.$rowstyle.'"';
6119: }
6120: my ($output,$description);
6121: if ($type eq 'default') {
6122: $description = &mt('Requests for: [_1]',$typetitle);
6123: } else {
6124: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
6125: }
6126: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
6127: "<td>$description</td>\n".
6128: '<td class="'.$class.'" colspan="2">'.
6129: '<table><tr>';
6130: my %headers = &Apache::lonlocal::texthash(
6131: approve => 'Processing',
6132: email => 'E-mail',
6133: username => 'Username',
6134: );
6135: foreach my $item ('approve','email','username') {
6136: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 6137: }
1.305 raeburn 6138: $output .= '</tr><tr>';
6139: foreach my $item ('approve','email','username') {
1.306 raeburn 6140: $output .= '<td style="vertical-align: top">';
1.305 raeburn 6141: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
6142: if ($item eq 'approve') {
6143: %choices = &Apache::lonlocal::texthash (
6144: automatic => 'Automatically approved',
6145: approval => 'Queued for approval',
6146: );
6147: @options = ('automatic','approval');
6148: $hashref = $processing;
6149: $defoption = 'automatic';
6150: $name = 'cancreate_emailprocess_'.$type;
6151: } elsif ($item eq 'email') {
6152: %choices = &Apache::lonlocal::texthash (
6153: any => 'Any e-mail',
6154: inst => 'Institutional only',
6155: noninst => 'Non-institutional only',
6156: custom => 'Custom restrictions',
6157: );
6158: @options = ('any','inst','noninst');
6159: my $showcustom;
6160: if (ref($emailrules) eq 'HASH') {
6161: if (keys(%{$emailrules}) > 0) {
6162: push(@options,'custom');
6163: $showcustom = 'cancreate_emailrule';
6164: if (ref($settings) eq 'HASH') {
6165: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
6166: foreach my $rule (@{$settings->{'email_rule'}}) {
6167: if (exists($emailrules->{$rule})) {
6168: $hascustom ++;
6169: }
6170: }
6171: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
6172: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
6173: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
6174: if (exists($emailrules->{$rule})) {
6175: $hascustom ++;
6176: }
6177: }
6178: }
6179: }
6180: }
6181: }
6182: }
6183: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
6184: "'cancreate_emaildomain','$type'".');"';
6185: $hashref = $emailoptions;
6186: $defoption = 'any';
6187: $name = 'cancreate_emailoptions_'.$type;
6188: } elsif ($item eq 'username') {
6189: %choices = &Apache::lonlocal::texthash (
6190: all => 'Same as e-mail',
6191: first => 'Omit @domain',
6192: free => 'Free to choose',
6193: );
6194: @options = ('all','first','free');
6195: $hashref = $emailverified;
6196: $defoption = 'all';
6197: $name = 'cancreate_usernameoptions_'.$type;
6198: }
6199: foreach my $option (@options) {
6200: my $checked;
6201: if (ref($hashref) eq 'HASH') {
6202: if ($type eq '') {
6203: if (!exists($hashref->{'default'})) {
6204: if ($option eq $defoption) {
6205: $checked = ' checked="checked"';
6206: }
6207: } else {
6208: if ($hashref->{'default'} eq $option) {
6209: $checked = ' checked="checked"';
6210: }
1.303 raeburn 6211: }
6212: } else {
1.305 raeburn 6213: if (!exists($hashref->{$type})) {
6214: if ($option eq $defoption) {
6215: $checked = ' checked="checked"';
6216: }
6217: } else {
6218: if ($hashref->{$type} eq $option) {
6219: $checked = ' checked="checked"';
6220: }
1.303 raeburn 6221: }
6222: }
1.305 raeburn 6223: } elsif (($item eq 'email') && ($hascustom)) {
6224: if ($option eq 'custom') {
6225: $checked = ' checked="checked"';
6226: }
6227: } elsif ($option eq $defoption) {
6228: $checked = ' checked="checked"';
6229: }
6230: $output .= '<span class="LC_nobreak"><label>'.
6231: '<input type="radio" name="'.$name.'"'.
6232: $checked.' value="'.$option.'"'.$onclick.' />'.
6233: $choices{$option}.'</label></span><br />';
6234: if ($item eq 'email') {
6235: if ($option eq 'custom') {
6236: my $id = 'cancreate_emailrule_'.$type;
6237: my $display = 'none';
6238: if ($checked) {
6239: $display = 'inline';
1.303 raeburn 6240: }
1.305 raeburn 6241: my $numinrow = 2;
6242: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
6243: '<legend>'.&mt('Disallow').'</legend><table>'.
6244: &user_formats_row('email',$settings,$emailrules,
6245: $emailruleorder,$numinrow,'',$type);
6246: '</table></fieldset>';
6247: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
6248: my %text = &Apache::lonlocal::texthash (
6249: inst => 'must end:',
6250: noninst => 'cannot end:',
6251: );
6252: my $value;
6253: if (ref($emaildomain) eq 'HASH') {
6254: if (ref($emaildomain->{$type}) eq 'HASH') {
6255: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 6256: }
6257: }
1.305 raeburn 6258: if ($value eq '') {
6259: $value = '@'.$intdom;
6260: }
6261: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
6262: my $display = 'none';
6263: if ($checked) {
6264: $display = 'inline';
6265: }
6266: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
6267: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
6268: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
6269: '</div>';
1.303 raeburn 6270: }
6271: }
6272: }
1.305 raeburn 6273: $output .= '</td>'."\n";
1.303 raeburn 6274: }
1.305 raeburn 6275: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 6276: return $output;
6277: }
6278:
1.165 raeburn 6279: sub captcha_choice {
1.305 raeburn 6280: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 6281: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
6282: $vertext,$currver);
1.165 raeburn 6283: my %lt = &captcha_phrases();
6284: $keyentry = 'hidden';
6285: if ($context eq 'cancreate') {
1.224 raeburn 6286: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 6287: } elsif ($context eq 'login') {
6288: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 6289: }
6290: if (ref($settings) eq 'HASH') {
6291: if ($settings->{'captcha'}) {
6292: $checked{$settings->{'captcha'}} = ' checked="checked"';
6293: } else {
6294: $checked{'original'} = ' checked="checked"';
6295: }
6296: if ($settings->{'captcha'} eq 'recaptcha') {
6297: $pubtext = $lt{'pub'};
6298: $privtext = $lt{'priv'};
6299: $keyentry = 'text';
1.269 raeburn 6300: $vertext = $lt{'ver'};
6301: $currver = $settings->{'recaptchaversion'};
6302: if ($currver ne '2') {
6303: $currver = 1;
6304: }
1.165 raeburn 6305: }
6306: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6307: $currpub = $settings->{'recaptchakeys'}{'public'};
6308: $currpriv = $settings->{'recaptchakeys'}{'private'};
6309: }
6310: } else {
6311: $checked{'original'} = ' checked="checked"';
6312: }
1.305 raeburn 6313: my $css_class;
6314: if ($itemcount%2) {
6315: $css_class = 'LC_odd_row';
6316: }
6317: if ($customcss) {
6318: $css_class .= " $customcss";
6319: }
6320: $css_class =~ s/^\s+//;
6321: if ($css_class) {
6322: $css_class = ' class="'.$css_class.'"';
6323: }
6324: if ($rowstyle) {
6325: $css_class .= ' style="'.$rowstyle.'"';
6326: }
1.169 raeburn 6327: my $output = '<tr'.$css_class.'>'.
6328: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 6329: '<table><tr><td>'."\n";
6330: foreach my $option ('original','recaptcha','notused') {
6331: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6332: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6333: $lt{$option}.'</label></span>';
6334: unless ($option eq 'notused') {
6335: $output .= (' 'x2)."\n";
6336: }
6337: }
6338: #
6339: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6340: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 6341: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 6342: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 6343: #
1.165 raeburn 6344: $output .= '</td></tr>'."\n".
1.305 raeburn 6345: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 6346: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6347: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6348: $currpub.'" size="40" /></span><br />'."\n".
6349: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6350: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 6351: $currpriv.'" size="40" /></span><br />'.
6352: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6353: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6354: $currver.'" size="3" /></span><br />'.
6355: '</td></tr></table>'."\n".
1.165 raeburn 6356: '</td></tr>';
6357: return $output;
6358: }
6359:
1.32 raeburn 6360: sub user_formats_row {
1.305 raeburn 6361: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 6362: my $output;
6363: my %text = (
6364: 'username' => 'new usernames',
6365: 'id' => 'IDs',
6366: );
1.305 raeburn 6367: unless ($type eq 'email') {
6368: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6369: $output = '<tr '.$css_class.'>'.
6370: '<td><span class="LC_nobreak">'.
6371: &mt("Format rules to check for $text{$type}: ").
6372: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 6373: }
1.27 raeburn 6374: my $rem;
6375: if (ref($ruleorder) eq 'ARRAY') {
6376: for (my $i=0; $i<@{$ruleorder}; $i++) {
6377: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6378: my $rem = $i%($numinrow);
6379: if ($rem == 0) {
6380: if ($i > 0) {
6381: $output .= '</tr>';
6382: }
6383: $output .= '<tr>';
6384: }
6385: my $check = ' ';
1.39 raeburn 6386: if (ref($settings) eq 'HASH') {
6387: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6388: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6389: $check = ' checked="checked" ';
6390: }
1.305 raeburn 6391: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
6392: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
6393: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
6394: $check = ' checked="checked" ';
6395: }
6396: }
1.27 raeburn 6397: }
6398: }
1.305 raeburn 6399: my $name = $type.'_rule';
6400: if ($type eq 'email') {
6401: $name .= '_'.$status;
6402: }
1.27 raeburn 6403: $output .= '<td class="LC_left_item">'.
6404: '<span class="LC_nobreak"><label>'.
1.305 raeburn 6405: '<input type="checkbox" name="'.$name.'"'.
1.27 raeburn 6406: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6407: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6408: }
6409: }
6410: $rem = @{$ruleorder}%($numinrow);
6411: }
1.305 raeburn 6412: my $colsleft;
6413: if ($rem) {
6414: $colsleft = $numinrow - $rem;
6415: }
1.27 raeburn 6416: if ($colsleft > 1 ) {
6417: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6418: ' </td>';
6419: } elsif ($colsleft == 1) {
6420: $output .= '<td class="LC_left_item"> </td>';
6421: }
1.305 raeburn 6422: $output .= '</tr></table>';
6423: unless ($type eq 'email') {
6424: $output .= '</td></tr>';
6425: }
1.27 raeburn 6426: return $output;
6427: }
6428:
1.34 raeburn 6429: sub usercreation_types {
6430: my %lt = &Apache::lonlocal::texthash (
6431: author => 'When adding a co-author',
6432: course => 'When adding a user to a course',
1.100 raeburn 6433: requestcrs => 'When requesting a course',
1.34 raeburn 6434: any => 'Any',
6435: official => 'Institutional only ',
6436: unofficial => 'Non-institutional only',
6437: none => 'None',
6438: );
6439: return %lt;
1.48 raeburn 6440: }
1.34 raeburn 6441:
1.224 raeburn 6442: sub selfcreation_types {
6443: my %lt = &Apache::lonlocal::texthash (
6444: selfcreate => 'User creates own account',
6445: any => 'Any',
6446: official => 'Institutional only ',
6447: unofficial => 'Non-institutional only',
6448: email => 'E-mail address',
6449: login => 'Institutional Login',
6450: sso => 'SSO',
6451: );
6452: }
6453:
1.28 raeburn 6454: sub authtype_names {
6455: my %lt = &Apache::lonlocal::texthash(
6456: int => 'Internal',
6457: krb4 => 'Kerberos 4',
6458: krb5 => 'Kerberos 5',
6459: loc => 'Local',
6460: );
6461: return %lt;
6462: }
6463:
6464: sub context_names {
6465: my %context_title = &Apache::lonlocal::texthash(
6466: author => 'Creating users when an Author',
6467: course => 'Creating users when in a course',
6468: domain => 'Creating users when a Domain Coordinator',
6469: );
6470: return %context_title;
6471: }
6472:
1.33 raeburn 6473: sub print_usermodification {
6474: my ($position,$dom,$settings,$rowtotal) = @_;
6475: my $numinrow = 4;
6476: my ($context,$datatable,$rowcount);
6477: if ($position eq 'top') {
6478: $rowcount = 0;
6479: $context = 'author';
6480: foreach my $role ('ca','aa') {
6481: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6482: $numinrow,$rowcount);
6483: $$rowtotal ++;
6484: $rowcount ++;
6485: }
1.230 raeburn 6486: } elsif ($position eq 'bottom') {
1.33 raeburn 6487: $context = 'course';
6488: $rowcount = 0;
6489: foreach my $role ('st','ep','ta','in','cr') {
6490: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6491: $numinrow,$rowcount);
6492: $$rowtotal ++;
6493: $rowcount ++;
6494: }
6495: }
6496: return $datatable;
6497: }
6498:
1.43 raeburn 6499: sub print_defaults {
1.236 raeburn 6500: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6501: my $rownum = 0;
1.294 raeburn 6502: my ($datatable,$css_class,$titles);
6503: unless ($position eq 'bottom') {
6504: $titles = &defaults_titles($dom);
6505: }
1.236 raeburn 6506: if ($position eq 'top') {
6507: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6508: 'datelocale_def','portal_def');
6509: my %defaults;
6510: if (ref($settings) eq 'HASH') {
6511: %defaults = %{$settings};
1.43 raeburn 6512: } else {
1.236 raeburn 6513: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6514: foreach my $item (@items) {
6515: $defaults{$item} = $domdefaults{$item};
6516: }
1.43 raeburn 6517: }
1.236 raeburn 6518: foreach my $item (@items) {
6519: if ($rownum%2) {
6520: $css_class = '';
6521: } else {
6522: $css_class = ' class="LC_odd_row" ';
6523: }
6524: $datatable .= '<tr'.$css_class.'>'.
6525: '<td><span class="LC_nobreak">'.$titles->{$item}.
6526: '</span></td><td class="LC_right_item" colspan="3">';
6527: if ($item eq 'auth_def') {
6528: my @authtypes = ('internal','krb4','krb5','localauth');
6529: my %shortauth = (
6530: internal => 'int',
6531: krb4 => 'krb4',
6532: krb5 => 'krb5',
6533: localauth => 'loc'
6534: );
6535: my %authnames = &authtype_names();
6536: foreach my $auth (@authtypes) {
6537: my $checked = ' ';
6538: if ($defaults{$item} eq $auth) {
6539: $checked = ' checked="checked" ';
6540: }
6541: $datatable .= '<label><input type="radio" name="'.$item.
6542: '" value="'.$auth.'"'.$checked.'/>'.
6543: $authnames{$shortauth{$auth}}.'</label> ';
6544: }
6545: } elsif ($item eq 'timezone_def') {
6546: my $includeempty = 1;
6547: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6548: } elsif ($item eq 'datelocale_def') {
6549: my $includeempty = 1;
6550: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6551: } elsif ($item eq 'lang_def') {
1.263 raeburn 6552: my $includeempty = 1;
6553: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 6554: } else {
6555: my $size;
6556: if ($item eq 'portal_def') {
6557: $size = ' size="25"';
6558: }
6559: $datatable .= '<input type="text" name="'.$item.'" value="'.
6560: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 6561: }
1.236 raeburn 6562: $datatable .= '</td></tr>';
6563: $rownum ++;
6564: }
1.294 raeburn 6565: } elsif ($position eq 'middle') {
6566: my @items = ('intauth_cost','intauth_check','intauth_switch');
6567: my %defaults;
6568: if (ref($settings) eq 'HASH') {
6569: %defaults = %{$settings};
6570: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6571: $defaults{'intauth_cost'} = 10;
6572: }
6573: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6574: $defaults{'intauth_check'} = 0;
6575: }
6576: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6577: $defaults{'intauth_switch'} = 0;
6578: }
6579: } else {
6580: %defaults = (
6581: 'intauth_cost' => 10,
6582: 'intauth_check' => 0,
6583: 'intauth_switch' => 0,
6584: );
6585: }
6586: foreach my $item (@items) {
6587: if ($rownum%2) {
6588: $css_class = '';
6589: } else {
6590: $css_class = ' class="LC_odd_row" ';
6591: }
6592: $datatable .= '<tr'.$css_class.'>'.
6593: '<td><span class="LC_nobreak">'.$titles->{$item}.
6594: '</span></td><td class="LC_left_item" colspan="3">';
6595: if ($item eq 'intauth_switch') {
6596: my @options = (0,1,2);
6597: my %optiondesc = &Apache::lonlocal::texthash (
6598: 0 => 'No',
6599: 1 => 'Yes',
6600: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6601: );
6602: $datatable .= '<table width="100%">';
6603: foreach my $option (@options) {
6604: my $checked = ' ';
6605: if ($defaults{$item} eq $option) {
6606: $checked = ' checked="checked"';
6607: }
6608: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6609: '<label><input type="radio" name="'.$item.
6610: '" value="'.$option.'"'.$checked.' />'.
6611: $optiondesc{$option}.'</label></span></td></tr>';
6612: }
6613: $datatable .= '</table>';
6614: } elsif ($item eq 'intauth_check') {
6615: my @options = (0,1,2);
6616: my %optiondesc = &Apache::lonlocal::texthash (
6617: 0 => 'No',
6618: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6619: 2 => 'Yes, disallow login if stored cost is less than domain default',
6620: );
6621: $datatable .= '<table wisth="100%">';
6622: foreach my $option (@options) {
6623: my $checked = ' ';
6624: my $onclick;
6625: if ($defaults{$item} eq $option) {
6626: $checked = ' checked="checked"';
6627: }
6628: if ($option == 2) {
6629: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6630: }
6631: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6632: '<label><input type="radio" name="'.$item.
6633: '" value="'.$option.'"'.$checked.$onclick.' />'.
6634: $optiondesc{$option}.'</label></span></td></tr>';
6635: }
6636: $datatable .= '</table>';
6637: } else {
6638: $datatable .= '<input type="text" name="'.$item.'" value="'.
6639: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6640: }
6641: $datatable .= '</td></tr>';
6642: $rownum ++;
6643: }
1.236 raeburn 6644: } else {
1.294 raeburn 6645: my %defaults;
1.236 raeburn 6646: if (ref($settings) eq 'HASH') {
1.305 raeburn 6647: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.236 raeburn 6648: my $maxnum = @{$settings->{'inststatusorder'}};
6649: for (my $i=0; $i<$maxnum; $i++) {
6650: $css_class = $rownum%2?' class="LC_odd_row"':'';
6651: my $item = $settings->{'inststatusorder'}->[$i];
6652: my $title = $settings->{'inststatustypes'}->{$item};
6653: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6654: $datatable .= '<tr'.$css_class.'>'.
6655: '<td><span class="LC_nobreak">'.
6656: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6657: for (my $k=0; $k<=$maxnum; $k++) {
6658: my $vpos = $k+1;
6659: my $selstr;
6660: if ($k == $i) {
6661: $selstr = ' selected="selected" ';
6662: }
6663: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6664: }
6665: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6666: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6667: &mt('delete').'</span></td>'.
1.305 raeburn 6668: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.236 raeburn 6669: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.305 raeburn 6670: '</span></td></tr>';
1.236 raeburn 6671: }
6672: $css_class = $rownum%2?' class="LC_odd_row"':'';
6673: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6674: $datatable .= '<tr '.$css_class.'>'.
6675: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6676: for (my $k=0; $k<=$maxnum; $k++) {
6677: my $vpos = $k+1;
6678: my $selstr;
6679: if ($k == $maxnum) {
6680: $selstr = ' selected="selected" ';
6681: }
6682: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6683: }
6684: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 6685: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 6686: ' '.&mt('(new)').
1.305 raeburn 6687: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.236 raeburn 6688: &mt('Name displayed:').
6689: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6690: '</tr>'."\n";
6691: $rownum ++;
1.141 raeburn 6692: }
1.43 raeburn 6693: }
6694: }
6695: $$rowtotal += $rownum;
6696: return $datatable;
6697: }
6698:
1.168 raeburn 6699: sub get_languages_hash {
6700: my %langchoices;
6701: foreach my $id (&Apache::loncommon::languageids()) {
6702: my $code = &Apache::loncommon::supportedlanguagecode($id);
6703: if ($code ne '') {
6704: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6705: }
6706: }
6707: return %langchoices;
6708: }
6709:
1.43 raeburn 6710: sub defaults_titles {
1.141 raeburn 6711: my ($dom) = @_;
1.43 raeburn 6712: my %titles = &Apache::lonlocal::texthash (
6713: 'auth_def' => 'Default authentication type',
6714: 'auth_arg_def' => 'Default authentication argument',
6715: 'lang_def' => 'Default language',
1.54 raeburn 6716: 'timezone_def' => 'Default timezone',
1.68 raeburn 6717: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6718: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 6719: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6720: 'intauth_check' => 'Check bcrypt cost if authenticated',
6721: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6722: );
1.141 raeburn 6723: if ($dom) {
6724: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6725: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6726: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6727: $protocol = 'http' if ($protocol ne 'https');
6728: if ($uint_dom) {
6729: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6730: $uint_dom);
6731: }
6732: }
1.43 raeburn 6733: return (\%titles);
6734: }
6735:
1.46 raeburn 6736: sub print_scantronformat {
6737: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6738: my $itemcount = 1;
1.60 raeburn 6739: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6740: %confhash);
1.46 raeburn 6741: my $switchserver = &check_switchserver($dom,$confname);
6742: my %lt = &Apache::lonlocal::texthash (
1.95 www 6743: default => 'Default bubblesheet format file error',
6744: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6745: );
6746: my %scantronfiles = (
6747: default => 'default.tab',
6748: custom => 'custom.tab',
6749: );
6750: foreach my $key (keys(%scantronfiles)) {
6751: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6752: .$scantronfiles{$key};
6753: }
6754: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6755: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6756: if (!$switchserver) {
6757: my $servadm = $r->dir_config('lonAdmEMail');
6758: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6759: if ($configuserok eq 'ok') {
6760: if ($author_ok eq 'ok') {
6761: my %legacyfile = (
6762: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6763: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6764: );
6765: my %md5chk;
6766: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6767: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6768: chomp($md5chk{$type});
1.46 raeburn 6769: }
6770: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6771: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6772: ($scantronurls{$type},my $error) =
1.46 raeburn 6773: &legacy_scantronformat($r,$dom,$confname,
6774: $type,$legacyfile{$type},
6775: $scantronurls{$type},
6776: $scantronfiles{$type});
1.60 raeburn 6777: if ($error ne '') {
6778: $error{$type} = $error;
6779: }
6780: }
6781: if (keys(%error) == 0) {
6782: $is_custom = 1;
6783: $confhash{'scantron'}{'scantronformat'} =
6784: $scantronurls{'custom'};
6785: my $putresult =
6786: &Apache::lonnet::put_dom('configuration',
6787: \%confhash,$dom);
6788: if ($putresult ne 'ok') {
6789: $error{'custom'} =
6790: '<span class="LC_error">'.
6791: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6792: }
1.46 raeburn 6793: }
6794: } else {
1.60 raeburn 6795: ($scantronurls{'default'},my $error) =
1.46 raeburn 6796: &legacy_scantronformat($r,$dom,$confname,
6797: 'default',$legacyfile{'default'},
6798: $scantronurls{'default'},
6799: $scantronfiles{'default'});
1.60 raeburn 6800: if ($error eq '') {
6801: $confhash{'scantron'}{'scantronformat'} = '';
6802: my $putresult =
6803: &Apache::lonnet::put_dom('configuration',
6804: \%confhash,$dom);
6805: if ($putresult ne 'ok') {
6806: $error{'default'} =
6807: '<span class="LC_error">'.
6808: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6809: }
6810: } else {
6811: $error{'default'} = $error;
6812: }
1.46 raeburn 6813: }
6814: }
6815: }
6816: } else {
1.95 www 6817: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6818: }
6819: }
6820: if (ref($settings) eq 'HASH') {
6821: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6822: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6823: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6824: $scantronurl = '';
6825: } else {
6826: $scantronurl = $settings->{'scantronformat'};
6827: }
6828: $is_custom = 1;
6829: } else {
6830: $scantronurl = $scantronurls{'default'};
6831: }
6832: } else {
1.60 raeburn 6833: if ($is_custom) {
6834: $scantronurl = $scantronurls{'custom'};
6835: } else {
6836: $scantronurl = $scantronurls{'default'};
6837: }
1.46 raeburn 6838: }
6839: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6840: $datatable .= '<tr'.$css_class.'>';
6841: if (!$is_custom) {
1.65 raeburn 6842: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6843: '<span class="LC_nobreak">';
1.46 raeburn 6844: if ($scantronurl) {
1.199 raeburn 6845: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6846: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6847: } else {
6848: $datatable = &mt('File unavailable for display');
6849: }
1.65 raeburn 6850: $datatable .= '</span></td>';
1.60 raeburn 6851: if (keys(%error) == 0) {
1.306 raeburn 6852: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 6853: if (!$switchserver) {
6854: $datatable .= &mt('Upload:').'<br />';
6855: }
6856: } else {
6857: my $errorstr;
6858: foreach my $key (sort(keys(%error))) {
6859: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6860: }
6861: $datatable .= '<td>'.$errorstr;
6862: }
1.46 raeburn 6863: } else {
6864: if (keys(%error) > 0) {
6865: my $errorstr;
6866: foreach my $key (sort(keys(%error))) {
6867: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6868: }
1.60 raeburn 6869: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6870: } elsif ($scantronurl) {
1.199 raeburn 6871: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
6872: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6873: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 6874: $link.
6875: '<label><input type="checkbox" name="scantronformat_del"'.
6876: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6877: '<td><span class="LC_nobreak"> '.
6878: &mt('Replace:').'</span><br />';
1.46 raeburn 6879: }
6880: }
6881: if (keys(%error) == 0) {
6882: if ($switchserver) {
6883: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6884: } else {
1.65 raeburn 6885: $datatable .='<span class="LC_nobreak"> '.
6886: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6887: }
6888: }
6889: $datatable .= '</td></tr>';
6890: $$rowtotal ++;
6891: return $datatable;
6892: }
6893:
6894: sub legacy_scantronformat {
6895: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6896: my ($url,$error);
6897: my @statinfo = &Apache::lonnet::stat_file($newurl);
6898: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6899: (my $result,$url) =
6900: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6901: '','',$newfile);
6902: if ($result ne 'ok') {
1.130 raeburn 6903: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6904: }
6905: }
6906: return ($url,$error);
6907: }
1.43 raeburn 6908:
1.49 raeburn 6909: sub print_coursecategories {
1.57 raeburn 6910: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6911: my $datatable;
6912: if ($position eq 'top') {
1.238 raeburn 6913: my (%checked);
6914: my @catitems = ('unauth','auth');
6915: my @cattypes = ('std','domonly','codesrch','none');
6916: $checked{'unauth'} = 'std';
6917: $checked{'auth'} = 'std';
6918: if (ref($settings) eq 'HASH') {
6919: foreach my $type (@cattypes) {
6920: if ($type eq $settings->{'unauth'}) {
6921: $checked{'unauth'} = $type;
6922: }
6923: if ($type eq $settings->{'auth'}) {
6924: $checked{'auth'} = $type;
6925: }
6926: }
6927: }
6928: my %lt = &Apache::lonlocal::texthash (
6929: unauth => 'Catalog type for unauthenticated users',
6930: auth => 'Catalog type for authenticated users',
6931: none => 'No catalog',
6932: std => 'Standard catalog',
6933: domonly => 'Domain-only catalog',
6934: codesrch => "Code search form",
6935: );
6936: my $itemcount = 0;
6937: foreach my $item (@catitems) {
6938: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6939: $datatable .= '<tr '.$css_class.'>'.
6940: '<td>'.$lt{$item}.'</td>'.
6941: '<td class="LC_right_item"><span class="LC_nobreak">';
6942: foreach my $type (@cattypes) {
6943: my $ischecked;
6944: if ($checked{$item} eq $type) {
6945: $ischecked=' checked="checked"';
6946: }
6947: $datatable .= '<label>'.
6948: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6949: ' />'.$lt{$type}.'</label> ';
6950: }
6951: $datatable .= '</td></tr>';
6952: $itemcount ++;
6953: }
6954: $$rowtotal += $itemcount;
6955: } elsif ($position eq 'middle') {
1.57 raeburn 6956: my $toggle_cats_crs = ' ';
6957: my $toggle_cats_dom = ' checked="checked" ';
6958: my $can_cat_crs = ' ';
6959: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6960: my $toggle_catscomm_comm = ' ';
6961: my $toggle_catscomm_dom = ' checked="checked" ';
6962: my $can_catcomm_comm = ' ';
6963: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 6964: my $toggle_catsplace_place = ' ';
6965: my $toggle_catsplace_dom = ' checked="checked" ';
6966: my $can_catplace_place = ' ';
6967: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 6968:
1.57 raeburn 6969: if (ref($settings) eq 'HASH') {
6970: if ($settings->{'togglecats'} eq 'crs') {
6971: $toggle_cats_crs = $toggle_cats_dom;
6972: $toggle_cats_dom = ' ';
6973: }
6974: if ($settings->{'categorize'} eq 'crs') {
6975: $can_cat_crs = $can_cat_dom;
6976: $can_cat_dom = ' ';
6977: }
1.120 raeburn 6978: if ($settings->{'togglecatscomm'} eq 'comm') {
6979: $toggle_catscomm_comm = $toggle_catscomm_dom;
6980: $toggle_catscomm_dom = ' ';
6981: }
6982: if ($settings->{'categorizecomm'} eq 'comm') {
6983: $can_catcomm_comm = $can_catcomm_dom;
6984: $can_catcomm_dom = ' ';
6985: }
1.272 raeburn 6986: if ($settings->{'togglecatsplace'} eq 'place') {
6987: $toggle_catsplace_place = $toggle_catsplace_dom;
6988: $toggle_catsplace_dom = ' ';
6989: }
6990: if ($settings->{'categorizeplace'} eq 'place') {
6991: $can_catplace_place = $can_catplace_dom;
6992: $can_catplace_dom = ' ';
6993: }
1.57 raeburn 6994: }
6995: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 6996: togglecats => 'Show/Hide a course in catalog',
6997: togglecatscomm => 'Show/Hide a community in catalog',
6998: togglecatsplace => 'Show/Hide a placement test in catalog',
6999: categorize => 'Assign a category to a course',
7000: categorizecomm => 'Assign a category to a community',
7001: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 7002: );
7003: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 7004: dom => 'Set in Domain',
7005: crs => 'Set in Course',
7006: comm => 'Set in Community',
7007: place => 'Set in Placement Test',
1.57 raeburn 7008: );
7009: $datatable = '<tr class="LC_odd_row">'.
7010: '<td>'.$title{'togglecats'}.'</td>'.
7011: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7012: '<input type="radio" name="togglecats"'.
7013: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7014: '<label><input type="radio" name="togglecats"'.
7015: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
7016: '</tr><tr>'.
7017: '<td>'.$title{'categorize'}.'</td>'.
7018: '<td class="LC_right_item"><span class="LC_nobreak">'.
7019: '<label><input type="radio" name="categorize"'.
7020: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7021: '<label><input type="radio" name="categorize"'.
7022: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 7023: '</tr><tr class="LC_odd_row">'.
7024: '<td>'.$title{'togglecatscomm'}.'</td>'.
7025: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7026: '<input type="radio" name="togglecatscomm"'.
7027: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7028: '<label><input type="radio" name="togglecatscomm"'.
7029: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
7030: '</tr><tr>'.
7031: '<td>'.$title{'categorizecomm'}.'</td>'.
7032: '<td class="LC_right_item"><span class="LC_nobreak">'.
7033: '<label><input type="radio" name="categorizecomm"'.
7034: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7035: '<label><input type="radio" name="categorizecomm"'.
7036: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 7037: '</tr><tr>'.
7038: '<td>'.$title{'togglecatsplace'}.'</td>'.
7039: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
7040: '<input type="radio" name="togglecatsplace"'.
7041: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7042: '<label><input type="radio" name="togglecatscomm"'.
7043: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
7044: '</tr><tr>'.
7045: '<td>'.$title{'categorizeplace'}.'</td>'.
7046: '<td class="LC_right_item"><span class="LC_nobreak">'.
7047: '<label><input type="radio" name="categorizeplace"'.
7048: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
7049: '<label><input type="radio" name="categorizeplace"'.
7050: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 7051: '</tr>';
1.272 raeburn 7052: $$rowtotal += 6;
1.57 raeburn 7053: } else {
7054: my $css_class;
7055: my $itemcount = 1;
7056: my $cathash;
7057: if (ref($settings) eq 'HASH') {
7058: $cathash = $settings->{'cats'};
7059: }
7060: if (ref($cathash) eq 'HASH') {
7061: my (@cats,@trails,%allitems,%idx,@jsarray);
7062: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
7063: \%allitems,\%idx,\@jsarray);
7064: my $maxdepth = scalar(@cats);
7065: my $colattrib = '';
7066: if ($maxdepth > 2) {
7067: $colattrib = ' colspan="2" ';
7068: }
7069: my @path;
7070: if (@cats > 0) {
7071: if (ref($cats[0]) eq 'ARRAY') {
7072: my $numtop = @{$cats[0]};
7073: my $maxnum = $numtop;
1.120 raeburn 7074: my %default_names = (
7075: instcode => &mt('Official courses'),
7076: communities => &mt('Communities'),
1.272 raeburn 7077: placement => &mt('Placement Tests'),
1.120 raeburn 7078: );
7079:
7080: if ((!grep(/^instcode$/,@{$cats[0]})) ||
7081: ($cathash->{'instcode::0'} eq '') ||
7082: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 7083: ($cathash->{'communities::0'} eq '') ||
7084: (!grep(/^placement$/,@{$cats[0]})) ||
7085: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 7086: $maxnum ++;
7087: }
7088: my $lastidx;
7089: for (my $i=0; $i<$numtop; $i++) {
7090: my $parent = $cats[0][$i];
7091: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7092: my $item = &escape($parent).'::0';
7093: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
7094: $lastidx = $idx{$item};
7095: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7096: .'<select name="'.$item.'"'.$chgstr.'>';
7097: for (my $k=0; $k<=$maxnum; $k++) {
7098: my $vpos = $k+1;
7099: my $selstr;
7100: if ($k == $i) {
7101: $selstr = ' selected="selected" ';
7102: }
7103: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7104: }
1.214 raeburn 7105: $datatable .= '</select></span></td><td>';
1.272 raeburn 7106: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 7107: $datatable .= '<span class="LC_nobreak">'
7108: .$default_names{$parent}.'</span>';
7109: if ($parent eq 'instcode') {
7110: $datatable .= '<br /><span class="LC_nobreak">('
7111: .&mt('with institutional codes')
7112: .')</span></td><td'.$colattrib.'>';
7113: } else {
7114: $datatable .= '<table><tr><td>';
7115: }
7116: $datatable .= '<span class="LC_nobreak">'
7117: .'<label><input type="radio" name="'
7118: .$parent.'" value="1" checked="checked" />'
7119: .&mt('Display').'</label>';
7120: if ($parent eq 'instcode') {
7121: $datatable .= ' ';
7122: } else {
7123: $datatable .= '</span></td></tr><tr><td>'
7124: .'<span class="LC_nobreak">';
7125: }
7126: $datatable .= '<label><input type="radio" name="'
7127: .$parent.'" value="0" />'
7128: .&mt('Do not display').'</label></span>';
1.272 raeburn 7129: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 7130: $datatable .= '</td></tr></table>';
7131: }
7132: $datatable .= '</td>';
1.57 raeburn 7133: } else {
7134: $datatable .= $parent
1.214 raeburn 7135: .' <span class="LC_nobreak"><label>'
7136: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 7137: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
7138: }
7139: my $depth = 1;
7140: push(@path,$parent);
7141: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
7142: pop(@path);
7143: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
7144: $itemcount ++;
7145: }
1.48 raeburn 7146: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 7147: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
7148: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 7149: for (my $k=0; $k<=$maxnum; $k++) {
7150: my $vpos = $k+1;
7151: my $selstr;
1.57 raeburn 7152: if ($k == $numtop) {
1.48 raeburn 7153: $selstr = ' selected="selected" ';
7154: }
7155: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
7156: }
1.59 bisitz 7157: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 7158: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
7159: .'</tr>'."\n";
1.48 raeburn 7160: $itemcount ++;
1.272 raeburn 7161: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7162: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
7163: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7164: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
7165: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
7166: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
7167: for (my $k=0; $k<=$maxnum; $k++) {
7168: my $vpos = $k+1;
7169: my $selstr;
7170: if ($k == $maxnum) {
7171: $selstr = ' selected="selected" ';
7172: }
7173: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 7174: }
1.120 raeburn 7175: $datatable .= '</select></span></td>'.
7176: '<td><span class="LC_nobreak">'.
7177: $default_names{$default}.'</span>';
7178: if ($default eq 'instcode') {
7179: $datatable .= '<br /><span class="LC_nobreak">('
7180: .&mt('with institutional codes').')</span>';
7181: }
7182: $datatable .= '</td>'
7183: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
7184: .&mt('Display').'</label> '
7185: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
7186: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 7187: }
7188: }
7189: }
1.57 raeburn 7190: } else {
7191: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 7192: }
7193: } else {
1.238 raeburn 7194: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 7195: .&initialize_categories($itemcount);
1.48 raeburn 7196: }
1.57 raeburn 7197: $$rowtotal += $itemcount;
1.48 raeburn 7198: }
7199: return $datatable;
7200: }
7201:
1.69 raeburn 7202: sub print_serverstatuses {
7203: my ($dom,$settings,$rowtotal) = @_;
7204: my $datatable;
7205: my @pages = &serverstatus_pages();
7206: my (%namedaccess,%machineaccess);
7207: foreach my $type (@pages) {
7208: $namedaccess{$type} = '';
7209: $machineaccess{$type}= '';
7210: }
7211: if (ref($settings) eq 'HASH') {
7212: foreach my $type (@pages) {
7213: if (exists($settings->{$type})) {
7214: if (ref($settings->{$type}) eq 'HASH') {
7215: foreach my $key (keys(%{$settings->{$type}})) {
7216: if ($key eq 'namedusers') {
7217: $namedaccess{$type} = $settings->{$type}->{$key};
7218: } elsif ($key eq 'machines') {
7219: $machineaccess{$type} = $settings->{$type}->{$key};
7220: }
7221: }
7222: }
7223: }
7224: }
7225: }
1.81 raeburn 7226: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7227: my $rownum = 0;
7228: my $css_class;
7229: foreach my $type (@pages) {
7230: $rownum ++;
7231: $css_class = $rownum%2?' class="LC_odd_row"':'';
7232: $datatable .= '<tr'.$css_class.'>'.
7233: '<td><span class="LC_nobreak">'.
7234: $titles->{$type}.'</span></td>'.
7235: '<td class="LC_left_item">'.
7236: '<input type="text" name="'.$type.'_namedusers" '.
7237: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
7238: '<td class="LC_right_item">'.
7239: '<span class="LC_nobreak">'.
7240: '<input type="text" name="'.$type.'_machines" '.
7241: 'value="'.$machineaccess{$type}.'" size="10" />'.
7242: '</td></tr>'."\n";
7243: }
7244: $$rowtotal += $rownum;
7245: return $datatable;
7246: }
7247:
7248: sub serverstatus_pages {
7249: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 7250: 'checksums','clusterstatus','certstatus','metadata_keywords',
7251: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
7252: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 7253: }
7254:
1.236 raeburn 7255: sub defaults_javascript {
7256: my ($settings) = @_;
1.294 raeburn 7257: 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.');
7258: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
7259: &js_escape(\$intauthcheck);
7260: &js_escape(\$intauthcost);
7261: my $intauthjs = <<"ENDSCRIPT";
7262:
7263: function warnIntAuth(field) {
7264: if (field.name == 'intauth_check') {
7265: if (field.value == '2') {
7266: alert('$intauthcheck');
7267: }
7268: }
7269: if (field.name == 'intauth_cost') {
7270: field.value.replace(/\s/g,'');
7271: if (field.value != '') {
7272: var regexdigit=/^\\d+\$/;
7273: if (!regexdigit.test(field.value)) {
7274: alert('$intauthcost');
7275: }
7276: }
7277: }
7278: return;
7279: }
7280:
7281: ENDSCRIPT
7282:
7283: if (ref($settings) ne 'HASH') {
7284: return &Apache::lonhtmlcommon::scripttag($intauthjs);
7285: }
1.236 raeburn 7286: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7287: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
7288: if ($maxnum eq '') {
7289: $maxnum = 0;
7290: }
7291: $maxnum ++;
1.249 raeburn 7292: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 7293: return <<"ENDSCRIPT";
7294: <script type="text/javascript">
7295: // <![CDATA[
7296: function reorderTypes(form,caller) {
7297: var changedVal;
7298: $jstext
7299: var newpos = 'addinststatus_pos';
7300: var current = new Array;
7301: var maxh = $maxnum;
7302: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7303: var oldVal;
7304: if (caller == newpos) {
7305: changedVal = newitemVal;
7306: } else {
7307: var curritem = 'inststatus_pos_'+caller;
7308: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7309: current[newitemVal] = newpos;
7310: }
7311: for (var i=0; i<inststatuses.length; i++) {
7312: if (inststatuses[i] != caller) {
7313: var elementName = 'inststatus_pos_'+inststatuses[i];
7314: if (form.elements[elementName]) {
7315: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7316: current[currVal] = elementName;
7317: }
7318: }
7319: }
7320: for (var j=0; j<maxh; j++) {
7321: if (current[j] == undefined) {
7322: oldVal = j;
7323: }
7324: }
7325: if (oldVal < changedVal) {
7326: for (var k=oldVal+1; k<=changedVal ; k++) {
7327: var elementName = current[k];
7328: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7329: }
7330: } else {
7331: for (var k=changedVal; k<oldVal; k++) {
7332: var elementName = current[k];
7333: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7334: }
7335: }
7336: return;
7337: }
7338:
1.294 raeburn 7339: $intauthjs
7340:
1.236 raeburn 7341: // ]]>
7342: </script>
7343:
7344: ENDSCRIPT
1.294 raeburn 7345: } else {
7346: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 7347: }
7348: }
7349:
1.49 raeburn 7350: sub coursecategories_javascript {
7351: my ($settings) = @_;
1.57 raeburn 7352: my ($output,$jstext,$cathash);
1.49 raeburn 7353: if (ref($settings) eq 'HASH') {
1.57 raeburn 7354: $cathash = $settings->{'cats'};
7355: }
7356: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7357: my (@cats,@jsarray,%idx);
1.57 raeburn 7358: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7359: if (@jsarray > 0) {
7360: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7361: for (my $i=0; $i<@jsarray; $i++) {
7362: if (ref($jsarray[$i]) eq 'ARRAY') {
7363: my $catstr = join('","',@{$jsarray[$i]});
7364: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7365: }
7366: }
7367: }
7368: } else {
7369: $jstext = ' var categories = Array(1);'."\n".
7370: ' categories[0] = Array("instcode_pos");'."\n";
7371: }
1.237 bisitz 7372: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7373: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 7374: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 7375: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7376: &js_escape(\$instcode_reserved);
7377: &js_escape(\$communities_reserved);
1.272 raeburn 7378: &js_escape(\$placement_reserved);
1.265 damieng 7379: &js_escape(\$choose_again);
1.49 raeburn 7380: $output = <<"ENDSCRIPT";
7381: <script type="text/javascript">
1.109 raeburn 7382: // <![CDATA[
1.49 raeburn 7383: function reorderCats(form,parent,item,idx) {
7384: var changedVal;
7385: $jstext
7386: var newpos = 'addcategory_pos';
7387: if (parent == '') {
7388: var has_instcode = 0;
7389: var maxtop = categories[idx].length;
7390: for (var j=0; j<maxtop; j++) {
7391: if (categories[idx][j] == 'instcode::0') {
7392: has_instcode == 1;
7393: }
7394: }
7395: if (has_instcode == 0) {
7396: categories[idx][maxtop] = 'instcode_pos';
7397: }
7398: } else {
7399: newpos += '_'+parent;
7400: }
7401: var maxh = 1 + categories[idx].length;
7402: var current = new Array;
7403: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7404: if (item == newpos) {
7405: changedVal = newitemVal;
7406: } else {
7407: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7408: current[newitemVal] = newpos;
7409: }
7410: for (var i=0; i<categories[idx].length; i++) {
7411: var elementName = categories[idx][i];
7412: if (elementName != item) {
7413: if (form.elements[elementName]) {
7414: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7415: current[currVal] = elementName;
7416: }
7417: }
7418: }
7419: var oldVal;
7420: for (var j=0; j<maxh; j++) {
7421: if (current[j] == undefined) {
7422: oldVal = j;
7423: }
7424: }
7425: if (oldVal < changedVal) {
7426: for (var k=oldVal+1; k<=changedVal ; k++) {
7427: var elementName = current[k];
7428: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7429: }
7430: } else {
7431: for (var k=changedVal; k<oldVal; k++) {
7432: var elementName = current[k];
7433: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7434: }
7435: }
7436: return;
7437: }
1.120 raeburn 7438:
7439: function categoryCheck(form) {
7440: if (form.elements['addcategory_name'].value == 'instcode') {
7441: alert('$instcode_reserved\\n$choose_again');
7442: return false;
7443: }
7444: if (form.elements['addcategory_name'].value == 'communities') {
7445: alert('$communities_reserved\\n$choose_again');
7446: return false;
7447: }
1.272 raeburn 7448: if (form.elements['addcategory_name'].value == 'placement') {
7449: alert('$placement_reserved\\n$choose_again');
7450: return false;
7451: }
1.120 raeburn 7452: return true;
7453: }
7454:
1.109 raeburn 7455: // ]]>
1.49 raeburn 7456: </script>
7457:
7458: ENDSCRIPT
7459: return $output;
7460: }
7461:
1.48 raeburn 7462: sub initialize_categories {
7463: my ($itemcount) = @_;
1.120 raeburn 7464: my ($datatable,$css_class,$chgstr);
7465: my %default_names = (
7466: instcode => 'Official courses (with institutional codes)',
7467: communities => 'Communities',
1.272 raeburn 7468: placement => 'Placement Tests',
1.120 raeburn 7469: );
7470: my $select0 = ' selected="selected"';
7471: my $select1 = '';
1.272 raeburn 7472: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7474: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 7475: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 7476: $select1 = $select0;
7477: $select0 = '';
7478: }
7479: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7480: .'<select name="'.$default.'_pos">'
7481: .'<option value="0"'.$select0.'>1</option>'
7482: .'<option value="1"'.$select1.'>2</option>'
7483: .'<option value="2">3</option></select> '
7484: .$default_names{$default}
7485: .'</span></td><td><span class="LC_nobreak">'
7486: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7487: .&mt('Display').'</label> <label>'
7488: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7489: .'</label></span></td></tr>';
1.120 raeburn 7490: $itemcount ++;
7491: }
1.48 raeburn 7492: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7493: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7494: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7495: .'<select name="addcategory_pos"'.$chgstr.'>'
7496: .'<option value="0">1</option>'
7497: .'<option value="1">2</option>'
7498: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 7499: .&mt('Add category').'</td><td>'.&mt('Name:')
7500: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
7501: return $datatable;
7502: }
7503:
7504: sub build_category_rows {
1.49 raeburn 7505: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7506: my ($text,$name,$item,$chgstr);
1.48 raeburn 7507: if (ref($cats) eq 'ARRAY') {
7508: my $maxdepth = scalar(@{$cats});
7509: if (ref($cats->[$depth]) eq 'HASH') {
7510: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7511: my $numchildren = @{$cats->[$depth]{$parent}};
7512: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 7513: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7514: my ($idxnum,$parent_name,$parent_item);
7515: my $higher = $depth - 1;
7516: if ($higher == 0) {
7517: $parent_name = &escape($parent).'::'.$higher;
7518: } else {
7519: if (ref($path) eq 'ARRAY') {
7520: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7521: }
7522: }
7523: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7524: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7525: if ($j < $numchildren) {
1.48 raeburn 7526: $name = $cats->[$depth]{$parent}[$j];
7527: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7528: $idxnum = $idx->{$item};
7529: } else {
7530: $name = $parent_name;
7531: $item = $parent_item;
1.48 raeburn 7532: }
1.49 raeburn 7533: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7534: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7535: for (my $i=0; $i<=$numchildren; $i++) {
7536: my $vpos = $i+1;
7537: my $selstr;
7538: if ($j == $i) {
7539: $selstr = ' selected="selected" ';
7540: }
7541: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7542: }
7543: $text .= '</select> ';
7544: if ($j < $numchildren) {
7545: my $deeper = $depth+1;
7546: $text .= $name.' '
7547: .'<label><input type="checkbox" name="deletecategory" value="'
7548: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7549: if(ref($path) eq 'ARRAY') {
7550: push(@{$path},$name);
1.49 raeburn 7551: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7552: pop(@{$path});
7553: }
7554: } else {
1.59 bisitz 7555: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 7556: if ($j == $numchildren) {
7557: $text .= $name;
7558: } else {
7559: $text .= $item;
7560: }
7561: $text .= '" value="" />';
7562: }
7563: $text .= '</td></tr>';
7564: }
7565: $text .= '</table></td>';
7566: } else {
7567: my $higher = $depth-1;
7568: if ($higher == 0) {
7569: $name = &escape($parent).'::'.$higher;
7570: } else {
7571: if (ref($path) eq 'ARRAY') {
7572: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7573: }
7574: }
7575: my $colspan;
7576: if ($parent ne 'instcode') {
7577: $colspan = $maxdepth - $depth - 1;
7578: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7579: }
7580: }
7581: }
7582: }
7583: return $text;
7584: }
7585:
1.33 raeburn 7586: sub modifiable_userdata_row {
1.305 raeburn 7587: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
7588: $rowid,$customcss,$rowstyle) = @_;
1.228 raeburn 7589: my ($role,$rolename,$statustype);
7590: $role = $item;
1.224 raeburn 7591: if ($context eq 'cancreate') {
1.305 raeburn 7592: if ($item =~ /^(emailusername)_(.+)$/) {
7593: $role = $1;
7594: $statustype = $2;
1.228 raeburn 7595: if (ref($usertypes) eq 'HASH') {
7596: if ($usertypes->{$statustype}) {
7597: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7598: } else {
7599: $rolename = &mt('Data provided by user');
7600: }
7601: }
1.224 raeburn 7602: }
7603: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7604: if (ref($usertypes) eq 'HASH') {
7605: $rolename = $usertypes->{$role};
7606: } else {
7607: $rolename = $role;
7608: }
1.33 raeburn 7609: } else {
1.63 raeburn 7610: if ($role eq 'cr') {
7611: $rolename = &mt('Custom role');
7612: } else {
7613: $rolename = &Apache::lonnet::plaintext($role);
7614: }
1.33 raeburn 7615: }
1.224 raeburn 7616: my (@fields,%fieldtitles);
7617: if (ref($fieldsref) eq 'ARRAY') {
7618: @fields = @{$fieldsref};
7619: } else {
7620: @fields = ('lastname','firstname','middlename','generation',
7621: 'permanentemail','id');
7622: }
7623: if ((ref($titlesref) eq 'HASH')) {
7624: %fieldtitles = %{$titlesref};
7625: } else {
7626: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7627: }
1.33 raeburn 7628: my $output;
1.305 raeburn 7629: my $css_class;
7630: if ($rowcount%2) {
7631: $css_class = 'LC_odd_row';
7632: }
7633: if ($customcss) {
7634: $css_class .= " $customcss";
7635: }
7636: $css_class =~ s/^\s+//;
7637: if ($css_class) {
7638: $css_class = ' class="'.$css_class.'"';
7639: }
7640: if ($rowstyle) {
7641: $css_class .= ' style="'.$rowstyle.'"';
7642: }
7643: if ($rowid) {
7644: $rowid = ' id="'.$rowid.'"';
7645: }
7646:
7647: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 7648: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7649: '<td class="LC_left_item" colspan="2"><table>';
7650: my $rem;
7651: my %checks;
7652: if (ref($settings) eq 'HASH') {
7653: if (ref($settings->{$context}) eq 'HASH') {
7654: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 7655: my $hashref = $settings->{$context}->{$role};
7656: if ($role eq 'emailusername') {
7657: if ($statustype) {
7658: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7659: $hashref = $settings->{$context}->{$role}->{$statustype};
7660: if (ref($hashref) eq 'HASH') {
7661: foreach my $field (@fields) {
7662: if ($hashref->{$field}) {
7663: $checks{$field} = $hashref->{$field};
7664: }
7665: }
7666: }
7667: }
7668: }
7669: } else {
7670: if (ref($hashref) eq 'HASH') {
7671: foreach my $field (@fields) {
7672: if ($hashref->{$field}) {
7673: $checks{$field} = ' checked="checked" ';
7674: }
7675: }
1.33 raeburn 7676: }
7677: }
7678: }
7679: }
7680: }
1.305 raeburn 7681:
7682: my $total = scalar(@fields);
7683: for (my $i=0; $i<$total; $i++) {
7684: $rem = $i%($numinrow);
1.33 raeburn 7685: if ($rem == 0) {
7686: if ($i > 0) {
7687: $output .= '</tr>';
7688: }
7689: $output .= '<tr>';
7690: }
7691: my $check = ' ';
1.228 raeburn 7692: unless ($role eq 'emailusername') {
7693: if (exists($checks{$fields[$i]})) {
7694: $check = $checks{$fields[$i]}
7695: } else {
7696: if ($role eq 'st') {
7697: if (ref($settings) ne 'HASH') {
7698: $check = ' checked="checked" ';
7699: }
1.33 raeburn 7700: }
7701: }
7702: }
7703: $output .= '<td class="LC_left_item">'.
1.228 raeburn 7704: '<span class="LC_nobreak">';
7705: if ($role eq 'emailusername') {
7706: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7707: $checks{$fields[$i]} = 'omit';
7708: }
7709: foreach my $option ('required','optional','omit') {
7710: my $checked='';
7711: if ($checks{$fields[$i]} eq $option) {
7712: $checked='checked="checked" ';
7713: }
7714: $output .= '<label>'.
7715: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7716: &mt($option).'</label>'.(' ' x2);
7717: }
7718: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7719: } else {
7720: $output .= '<label>'.
7721: '<input type="checkbox" name="canmodify_'.$role.'" '.
7722: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7723: '</label>';
7724: }
7725: $output .= '</span></td>';
1.33 raeburn 7726: }
1.305 raeburn 7727: $rem = $total%$numinrow;
7728: my $colsleft;
7729: if ($rem) {
7730: $colsleft = $numinrow - $rem;
7731: }
7732: if ($colsleft > 1) {
1.33 raeburn 7733: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7734: ' </td>';
7735: } elsif ($colsleft == 1) {
7736: $output .= '<td class="LC_left_item"> </td>';
7737: }
7738: $output .= '</tr></table></td></tr>';
7739: return $output;
7740: }
1.28 raeburn 7741:
1.93 raeburn 7742: sub insttypes_row {
1.305 raeburn 7743: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
7744: $customcss,$rowstyle) = @_;
1.93 raeburn 7745: my %lt = &Apache::lonlocal::texthash (
7746: cansearch => 'Users allowed to search',
7747: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7748: lockablenames => 'User preference to lock name',
1.305 raeburn 7749: selfassign => 'Self-reportable affiliations',
1.93 raeburn 7750: );
7751: my $showdom;
7752: if ($context eq 'cansearch') {
7753: $showdom = ' ('.$dom.')';
7754: }
1.165 raeburn 7755: my $class = 'LC_left_item';
7756: if ($context eq 'statustocreate') {
7757: $class = 'LC_right_item';
7758: }
1.305 raeburn 7759: my $css_class;
7760: if ($$rowtotal%2) {
7761: $css_class = 'LC_odd_row';
7762: }
7763: if ($customcss) {
7764: $css_class .= ' '.$customcss;
7765: }
7766: $css_class =~ s/^\s+//;
7767: if ($css_class) {
7768: $css_class = ' class="'.$css_class.'"';
7769: }
7770: if ($rowstyle) {
7771: $css_class .= ' style="'.$rowstyle.'"';
7772: }
7773: if ($onclick) {
7774: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 7775: }
7776: my $output = '<tr'.$css_class.'>'.
7777: '<td>'.$lt{$context}.$showdom.
7778: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7779: my $rem;
7780: if (ref($types) eq 'ARRAY') {
7781: for (my $i=0; $i<@{$types}; $i++) {
7782: if (defined($usertypes->{$types->[$i]})) {
7783: my $rem = $i%($numinrow);
7784: if ($rem == 0) {
7785: if ($i > 0) {
7786: $output .= '</tr>';
7787: }
7788: $output .= '<tr>';
1.23 raeburn 7789: }
1.26 raeburn 7790: my $check = ' ';
1.99 raeburn 7791: if (ref($settings) eq 'HASH') {
7792: if (ref($settings->{$context}) eq 'ARRAY') {
7793: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7794: $check = ' checked="checked" ';
7795: }
7796: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7797: $check = ' checked="checked" ';
7798: }
1.23 raeburn 7799: }
1.26 raeburn 7800: $output .= '<td class="LC_left_item">'.
7801: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7802: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 7803: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 7804: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7805: }
7806: }
1.26 raeburn 7807: $rem = @{$types}%($numinrow);
1.23 raeburn 7808: }
7809: my $colsleft = $numinrow - $rem;
1.131 raeburn 7810: if (($rem == 0) && (@{$types} > 0)) {
7811: $output .= '<tr>';
7812: }
1.23 raeburn 7813: if ($colsleft > 1) {
1.25 raeburn 7814: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7815: } else {
1.25 raeburn 7816: $output .= '<td class="LC_left_item">';
1.23 raeburn 7817: }
7818: my $defcheck = ' ';
1.99 raeburn 7819: if (ref($settings) eq 'HASH') {
7820: if (ref($settings->{$context}) eq 'ARRAY') {
7821: if (grep(/^default$/,@{$settings->{$context}})) {
7822: $defcheck = ' checked="checked" ';
7823: }
7824: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7825: $defcheck = ' checked="checked" ';
7826: }
1.23 raeburn 7827: }
1.25 raeburn 7828: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7829: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 7830: 'value="default"'.$defcheck.$onclick.' />'.
1.25 raeburn 7831: $othertitle.'</label></span></td>'.
7832: '</tr></table></td></tr>';
7833: return $output;
1.23 raeburn 7834: }
7835:
7836: sub sorted_searchtitles {
7837: my %searchtitles = &Apache::lonlocal::texthash(
7838: 'uname' => 'username',
7839: 'lastname' => 'last name',
7840: 'lastfirst' => 'last name, first name',
7841: );
7842: my @titleorder = ('uname','lastname','lastfirst');
7843: return (\%searchtitles,\@titleorder);
7844: }
7845:
1.25 raeburn 7846: sub sorted_searchtypes {
7847: my %srchtypes_desc = (
7848: exact => 'is exact match',
7849: contains => 'contains ..',
7850: begins => 'begins with ..',
7851: );
7852: my @srchtypeorder = ('exact','begins','contains');
7853: return (\%srchtypes_desc,\@srchtypeorder);
7854: }
7855:
1.3 raeburn 7856: sub usertype_update_row {
7857: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7858: my $datatable;
7859: my $numinrow = 4;
7860: foreach my $type (@{$types}) {
7861: if (defined($usertypes->{$type})) {
7862: $$rownums ++;
7863: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7864: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7865: '</td><td class="LC_left_item"><table>';
7866: for (my $i=0; $i<@{$fields}; $i++) {
7867: my $rem = $i%($numinrow);
7868: if ($rem == 0) {
7869: if ($i > 0) {
7870: $datatable .= '</tr>';
7871: }
7872: $datatable .= '<tr>';
7873: }
7874: my $check = ' ';
1.39 raeburn 7875: if (ref($settings) eq 'HASH') {
7876: if (ref($settings->{'fields'}) eq 'HASH') {
7877: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7878: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7879: $check = ' checked="checked" ';
7880: }
1.3 raeburn 7881: }
7882: }
7883: }
7884:
7885: if ($i == @{$fields}-1) {
7886: my $colsleft = $numinrow - $rem;
7887: if ($colsleft > 1) {
7888: $datatable .= '<td colspan="'.$colsleft.'">';
7889: } else {
7890: $datatable .= '<td>';
7891: }
7892: } else {
7893: $datatable .= '<td>';
7894: }
1.8 raeburn 7895: $datatable .= '<span class="LC_nobreak"><label>'.
7896: '<input type="checkbox" name="updateable_'.$type.
7897: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7898: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7899: }
7900: $datatable .= '</tr></table></td></tr>';
7901: }
7902: }
7903: return $datatable;
1.1 raeburn 7904: }
7905:
7906: sub modify_login {
1.205 raeburn 7907: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 7908: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7909: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7910: %title = ( coursecatalog => 'Display course catalog',
7911: adminmail => 'Display administrator E-mail address',
1.188 raeburn 7912: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 7913: newuser => 'Link for visitors to create a user account',
7914: loginheader => 'Log-in box header');
7915: @offon = ('off','on');
1.112 raeburn 7916: if (ref($domconfig{login}) eq 'HASH') {
7917: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7918: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7919: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7920: }
7921: }
7922: }
1.9 raeburn 7923: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7924: \%domconfig,\%loginhash);
1.188 raeburn 7925: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7926: foreach my $item (@toggles) {
7927: $loginhash{login}{$item} = $env{'form.'.$item};
7928: }
1.41 raeburn 7929: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7930: if (ref($colchanges{'login'}) eq 'HASH') {
7931: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7932: \%loginhash);
7933: }
1.110 raeburn 7934:
1.149 raeburn 7935: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 7936: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7937: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7938: if (keys(%servers) > 1) {
7939: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7940: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7941: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7942: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7943: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7944: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7945: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7946: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7947: $changes{'loginvia'}{$lonhost} = 1;
7948: } else {
7949: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7950: $changes{'loginvia'}{$lonhost} = 1;
7951: }
7952: } else {
7953: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7954: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7955: $changes{'loginvia'}{$lonhost} = 1;
7956: }
7957: }
7958: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7959: foreach my $item (@loginvia_attribs) {
7960: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7961: }
7962: } else {
7963: foreach my $item (@loginvia_attribs) {
7964: my $new = $env{'form.'.$lonhost.'_'.$item};
7965: if (($item eq 'serverpath') && ($new eq 'custom')) {
7966: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7967: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7968: $new = '/';
7969: }
7970: }
7971: if (($item eq 'custompath') &&
7972: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7973: $new = '';
7974: }
7975: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7976: $changes{'loginvia'}{$lonhost} = 1;
7977: }
7978: if ($item eq 'exempt') {
1.256 raeburn 7979: $new = &check_exempt_addresses($new);
1.128 raeburn 7980: }
7981: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7982: }
7983: }
1.112 raeburn 7984: } else {
1.128 raeburn 7985: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7986: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7987: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7988: foreach my $item (@loginvia_attribs) {
7989: my $new = $env{'form.'.$lonhost.'_'.$item};
7990: if (($item eq 'serverpath') && ($new eq 'custom')) {
7991: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7992: $new = '/';
7993: }
7994: }
7995: if (($item eq 'custompath') &&
7996: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7997: $new = '';
7998: }
7999: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
8000: }
1.110 raeburn 8001: }
8002: }
8003: }
8004: }
1.119 raeburn 8005:
1.168 raeburn 8006: my $servadm = $r->dir_config('lonAdmEMail');
8007: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8008: if (ref($domconfig{'login'}) eq 'HASH') {
8009: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8010: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8011: if ($lang eq 'nolang') {
8012: push(@currlangs,$lang);
8013: } elsif (defined($langchoices{$lang})) {
8014: push(@currlangs,$lang);
8015: } else {
8016: next;
8017: }
8018: }
8019: }
8020: }
8021: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8022: if (@currlangs > 0) {
8023: foreach my $lang (@currlangs) {
8024: if (grep(/^\Q$lang\E$/,@delurls)) {
8025: $changes{'helpurl'}{$lang} = 1;
8026: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8027: $changes{'helpurl'}{$lang} = 1;
8028: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8029: push(@newlangs,$lang);
8030: } else {
8031: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8032: }
8033: }
8034: }
8035: unless (grep(/^nolang$/,@currlangs)) {
8036: if ($env{'form.loginhelpurl_nolang.filename'}) {
8037: $changes{'helpurl'}{'nolang'} = 1;
8038: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8039: push(@newlangs,'nolang');
8040: }
8041: }
8042: if ($env{'form.loginhelpurl_add_lang'}) {
8043: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8044: ($env{'form.loginhelpurl_add_file.filename'})) {
8045: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8046: $addedfile = $env{'form.loginhelpurl_add_lang'};
8047: }
8048: }
8049: if ((@newlangs > 0) || ($addedfile)) {
8050: my $error;
8051: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8052: if ($configuserok eq 'ok') {
8053: if ($switchserver) {
8054: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8055: } elsif ($author_ok eq 'ok') {
8056: my @allnew = @newlangs;
8057: if ($addedfile ne '') {
8058: push(@allnew,$addedfile);
8059: }
8060: foreach my $lang (@allnew) {
8061: my $formelem = 'loginhelpurl_'.$lang;
8062: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8063: $formelem = 'loginhelpurl_add_file';
8064: }
8065: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8066: "help/$lang",'','',$newfile{$lang});
8067: if ($result eq 'ok') {
8068: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8069: $changes{'helpurl'}{$lang} = 1;
8070: } else {
8071: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8072: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 8073: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 8074: (!grep(/^\Q$lang\E$/,@delurls))) {
8075: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8076: }
8077: }
8078: }
8079: } else {
8080: $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);
8081: }
8082: } else {
8083: $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);
8084: }
8085: if ($error) {
8086: &Apache::lonnet::logthis($error);
8087: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8088: }
8089: }
1.256 raeburn 8090:
8091: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8092: if (ref($domconfig{'login'}) eq 'HASH') {
8093: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8094: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8095: if ($domservers{$lonhost}) {
8096: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8097: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 8098: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 8099: }
8100: }
8101: }
8102: }
8103: }
8104: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8105: foreach my $lonhost (sort(keys(%domservers))) {
8106: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8107: $changes{'headtag'}{$lonhost} = 1;
8108: } else {
8109: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8110: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8111: }
8112: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8113: push(@newhosts,$lonhost);
8114: } elsif ($currheadtagurls{$lonhost}) {
8115: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8116: if ($currexempt{$lonhost}) {
1.289 raeburn 8117: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 8118: $changes{'headtag'}{$lonhost} = 1;
8119: }
8120: } elsif ($possexempt{$lonhost}) {
8121: $changes{'headtag'}{$lonhost} = 1;
8122: }
8123: if ($possexempt{$lonhost}) {
8124: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8125: }
8126: }
8127: }
8128: }
8129: if (@newhosts) {
8130: my $error;
8131: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8132: if ($configuserok eq 'ok') {
8133: if ($switchserver) {
8134: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8135: } elsif ($author_ok eq 'ok') {
8136: foreach my $lonhost (@newhosts) {
8137: my $formelem = 'loginheadtag_'.$lonhost;
8138: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8139: "login/headtag/$lonhost",'','',
8140: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8141: if ($result eq 'ok') {
8142: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8143: $changes{'headtag'}{$lonhost} = 1;
8144: if ($possexempt{$lonhost}) {
8145: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8146: }
8147: } else {
8148: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8149: $newheadtagurls{$lonhost},$result);
8150: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8151: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8152: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8153: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8154: }
8155: }
8156: }
8157: } else {
8158: $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);
8159: }
8160: } else {
8161: $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);
8162: }
8163: if ($error) {
8164: &Apache::lonnet::logthis($error);
8165: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8166: }
8167: }
1.169 raeburn 8168: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 8169:
8170: my $defaulthelpfile = '/adm/loginproblems.html';
8171: my $defaulttext = &mt('Default in use');
8172:
1.1 raeburn 8173: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8174: $dom);
8175: if ($putresult eq 'ok') {
1.188 raeburn 8176: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8177: my %defaultchecked = (
8178: 'coursecatalog' => 'on',
1.188 raeburn 8179: 'helpdesk' => 'on',
1.42 raeburn 8180: 'adminmail' => 'off',
1.43 raeburn 8181: 'newuser' => 'off',
1.42 raeburn 8182: );
1.55 raeburn 8183: if (ref($domconfig{'login'}) eq 'HASH') {
8184: foreach my $item (@toggles) {
8185: if ($defaultchecked{$item} eq 'on') {
8186: if (($domconfig{'login'}{$item} eq '0') &&
8187: ($env{'form.'.$item} eq '1')) {
8188: $changes{$item} = 1;
8189: } elsif (($domconfig{'login'}{$item} eq '' ||
8190: $domconfig{'login'}{$item} eq '1') &&
8191: ($env{'form.'.$item} eq '0')) {
8192: $changes{$item} = 1;
8193: }
8194: } elsif ($defaultchecked{$item} eq 'off') {
8195: if (($domconfig{'login'}{$item} eq '1') &&
8196: ($env{'form.'.$item} eq '0')) {
8197: $changes{$item} = 1;
8198: } elsif (($domconfig{'login'}{$item} eq '' ||
8199: $domconfig{'login'}{$item} eq '0') &&
8200: ($env{'form.'.$item} eq '1')) {
8201: $changes{$item} = 1;
8202: }
1.42 raeburn 8203: }
8204: }
1.41 raeburn 8205: }
1.6 raeburn 8206: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 8207: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8208: if (ref($lastactref) eq 'HASH') {
8209: $lastactref->{'domainconfig'} = 1;
8210: }
1.1 raeburn 8211: $resulttext = &mt('Changes made:').'<ul>';
8212: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 8213: if ($item eq 'loginvia') {
1.112 raeburn 8214: if (ref($changes{$item}) eq 'HASH') {
8215: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8216: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 8217: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
8218: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
8219: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
8220: $protocol = 'http' if ($protocol ne 'https');
8221: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
8222:
8223: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
8224: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
8225: } else {
8226: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
8227: }
8228: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
8229: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
8230: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
8231: }
8232: $resulttext .= '</li>';
8233: } else {
8234: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8235: }
1.112 raeburn 8236: } else {
1.128 raeburn 8237: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 8238: }
8239: }
1.128 raeburn 8240: $resulttext .= '</ul></li>';
1.112 raeburn 8241: }
1.168 raeburn 8242: } elsif ($item eq 'helpurl') {
8243: if (ref($changes{$item}) eq 'HASH') {
8244: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8245: if (grep(/^\Q$lang\E$/,@delurls)) {
8246: my ($chg,$link);
8247: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8248: if ($lang eq 'nolang') {
8249: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8250: } else {
8251: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8252: }
8253: $resulttext .= '<li>'.$chg.'</li>';
8254: } else {
8255: my $chg;
8256: if ($lang eq 'nolang') {
8257: $chg = &mt('custom log-in help file for no preferred language');
8258: } else {
8259: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8260: }
8261: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8262: $loginhash{'login'}{'helpurl'}{$lang}.
8263: '?inhibitmenu=yes',$chg,600,500).
8264: '</li>';
8265: }
8266: }
8267: }
1.256 raeburn 8268: } elsif ($item eq 'headtag') {
8269: if (ref($changes{$item}) eq 'HASH') {
8270: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8271: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8272: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8273: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8274: $resulttext .= '<li><a href="'.
8275: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8276: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8277: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8278: if ($possexempt{$lonhost}) {
8279: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8280: } else {
8281: $resulttext .= &mt('included for any client IP');
8282: }
8283: $resulttext .= '</li>';
8284: }
8285: }
8286: }
1.169 raeburn 8287: } elsif ($item eq 'captcha') {
8288: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 8289: my $chgtxt;
1.169 raeburn 8290: if ($loginhash{'login'}{$item} eq 'notused') {
8291: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
8292: } else {
8293: my %captchas = &captcha_phrases();
8294: if ($captchas{$loginhash{'login'}{$item}}) {
8295: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
8296: } else {
8297: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
8298: }
8299: }
8300: $resulttext .= '<li>'.$chgtxt.'</li>';
8301: }
8302: } elsif ($item eq 'recaptchakeys') {
8303: if (ref($loginhash{'login'}) eq 'HASH') {
8304: my ($privkey,$pubkey);
8305: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
8306: $pubkey = $loginhash{'login'}{$item}{'public'};
8307: $privkey = $loginhash{'login'}{$item}{'private'};
8308: }
8309: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
8310: if (!$pubkey) {
8311: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
8312: } else {
8313: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8314: }
8315: if (!$privkey) {
8316: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
8317: } else {
1.251 raeburn 8318: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 8319: }
8320: $chgtxt .= '</ul>';
8321: $resulttext .= '<li>'.$chgtxt.'</li>';
8322: }
1.269 raeburn 8323: } elsif ($item eq 'recaptchaversion') {
8324: if (ref($loginhash{'login'}) eq 'HASH') {
8325: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 8326: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 8327: '</li>';
8328: }
8329: }
1.41 raeburn 8330: } else {
8331: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
8332: }
1.1 raeburn 8333: }
1.6 raeburn 8334: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 8335: } else {
8336: $resulttext = &mt('No changes made to log-in page settings');
8337: }
8338: } else {
1.11 albertel 8339: $resulttext = '<span class="LC_error">'.
8340: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8341: }
1.6 raeburn 8342: if ($errors) {
1.9 raeburn 8343: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 8344: $errors.'</ul>';
8345: }
8346: return $resulttext;
8347: }
8348:
1.256 raeburn 8349: sub check_exempt_addresses {
8350: my ($iplist) = @_;
8351: $iplist =~ s/^\s+//;
8352: $iplist =~ s/\s+$//;
8353: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8354: my (@okips,$new);
8355: foreach my $ip (@poss_ips) {
8356: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8357: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8358: push(@okips,$ip);
8359: }
8360: }
8361: }
8362: if (@okips > 0) {
8363: $new = join(',',@okips);
8364: } else {
8365: $new = '';
8366: }
8367: return $new;
8368: }
8369:
1.6 raeburn 8370: sub color_font_choices {
8371: my %choices =
8372: &Apache::lonlocal::texthash (
8373: img => "Header",
8374: bgs => "Background colors",
8375: links => "Link colors",
1.55 raeburn 8376: images => "Images",
1.6 raeburn 8377: font => "Font color",
1.201 raeburn 8378: fontmenu => "Font menu",
1.76 raeburn 8379: pgbg => "Page",
1.6 raeburn 8380: tabbg => "Header",
8381: sidebg => "Border",
8382: link => "Link",
8383: alink => "Active link",
8384: vlink => "Visited link",
8385: );
8386: return %choices;
8387: }
8388:
8389: sub modify_rolecolors {
1.205 raeburn 8390: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8391: my ($resulttext,%rolehash);
8392: $rolehash{'rolecolors'} = {};
1.55 raeburn 8393: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8394: if ($domconfig{'rolecolors'} eq '') {
8395: $domconfig{'rolecolors'} = {};
8396: }
8397: }
1.9 raeburn 8398: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8399: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8400: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8401: $dom);
8402: if ($putresult eq 'ok') {
8403: if (keys(%changes) > 0) {
1.41 raeburn 8404: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8405: if (ref($lastactref) eq 'HASH') {
8406: $lastactref->{'domainconfig'} = 1;
8407: }
1.6 raeburn 8408: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8409: $rolehash{'rolecolors'});
8410: } else {
8411: $resulttext = &mt('No changes made to default color schemes');
8412: }
8413: } else {
1.11 albertel 8414: $resulttext = '<span class="LC_error">'.
8415: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8416: }
8417: if ($errors) {
8418: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8419: $errors.'</ul>';
8420: }
8421: return $resulttext;
8422: }
8423:
8424: sub modify_colors {
1.9 raeburn 8425: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8426: my (%changes,%choices);
1.51 raeburn 8427: my @bgs;
1.6 raeburn 8428: my @links = ('link','alink','vlink');
1.41 raeburn 8429: my @logintext;
1.6 raeburn 8430: my @images;
8431: my $servadm = $r->dir_config('lonAdmEMail');
8432: my $errors;
1.200 raeburn 8433: my %defaults;
1.6 raeburn 8434: foreach my $role (@{$roles}) {
8435: if ($role eq 'login') {
1.12 raeburn 8436: %choices = &login_choices();
1.41 raeburn 8437: @logintext = ('textcol','bgcol');
1.12 raeburn 8438: } else {
8439: %choices = &color_font_choices();
8440: }
8441: if ($role eq 'login') {
1.41 raeburn 8442: @images = ('img','logo','domlogo','login');
1.51 raeburn 8443: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8444: } else {
8445: @images = ('img');
1.200 raeburn 8446: @bgs = ('pgbg','tabbg','sidebg');
8447: }
8448: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8449: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8450: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8451: }
8452: if ($role eq 'login') {
8453: foreach my $item (@logintext) {
1.234 raeburn 8454: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8455: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8456: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8457: }
8458: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 8459: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8460: }
8461: }
8462: } else {
1.234 raeburn 8463: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8464: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8465: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8466: }
8467: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 8468: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8469: }
1.6 raeburn 8470: }
1.200 raeburn 8471: foreach my $item (@bgs) {
1.234 raeburn 8472: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8473: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8474: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8475: }
8476: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 8477: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8478: }
8479: }
8480: foreach my $item (@links) {
1.234 raeburn 8481: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8482: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8483: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8484: }
8485: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 8486: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8487: }
1.6 raeburn 8488: }
1.46 raeburn 8489: my ($configuserok,$author_ok,$switchserver) =
8490: &config_check($dom,$confname,$servadm);
1.9 raeburn 8491: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8492: if (ref($domconfig->{$role}) ne 'HASH') {
8493: $domconfig->{$role} = {};
8494: }
1.8 raeburn 8495: foreach my $img (@images) {
1.70 raeburn 8496: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8497: if (defined($env{'form.login_showlogo_'.$img})) {
8498: $confhash->{$role}{'showlogo'}{$img} = 1;
8499: } else {
8500: $confhash->{$role}{'showlogo'}{$img} = 0;
8501: }
8502: }
1.18 albertel 8503: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8504: && !defined($domconfig->{$role}{$img})
8505: && !$env{'form.'.$role.'_del_'.$img}
8506: && $env{'form.'.$role.'_import_'.$img}) {
8507: # import the old configured image from the .tab setting
8508: # if they haven't provided a new one
8509: $domconfig->{$role}{$img} =
8510: $env{'form.'.$role.'_import_'.$img};
8511: }
1.6 raeburn 8512: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8513: my $error;
1.6 raeburn 8514: if ($configuserok eq 'ok') {
1.9 raeburn 8515: if ($switchserver) {
1.12 raeburn 8516: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8517: } else {
8518: if ($author_ok eq 'ok') {
8519: my ($result,$logourl) =
8520: &publishlogo($r,'upload',$role.'_'.$img,
8521: $dom,$confname,$img,$width,$height);
8522: if ($result eq 'ok') {
8523: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8524: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8525: } else {
1.12 raeburn 8526: $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 8527: }
8528: } else {
1.46 raeburn 8529: $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 8530: }
8531: }
8532: } else {
1.46 raeburn 8533: $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 8534: }
8535: if ($error) {
1.8 raeburn 8536: &Apache::lonnet::logthis($error);
1.11 albertel 8537: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8538: }
8539: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8540: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8541: my $error;
8542: if ($configuserok eq 'ok') {
8543: # is confname an author?
8544: if ($switchserver eq '') {
8545: if ($author_ok eq 'ok') {
8546: my ($result,$logourl) =
8547: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8548: $dom,$confname,$img,$width,$height);
8549: if ($result eq 'ok') {
8550: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8551: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8552: }
8553: }
8554: }
8555: }
1.6 raeburn 8556: }
8557: }
8558: }
8559: if (ref($domconfig) eq 'HASH') {
8560: if (ref($domconfig->{$role}) eq 'HASH') {
8561: foreach my $img (@images) {
8562: if ($domconfig->{$role}{$img} ne '') {
8563: if ($env{'form.'.$role.'_del_'.$img}) {
8564: $confhash->{$role}{$img} = '';
1.12 raeburn 8565: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8566: } else {
1.9 raeburn 8567: if ($confhash->{$role}{$img} eq '') {
8568: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8569: }
1.6 raeburn 8570: }
8571: } else {
8572: if ($env{'form.'.$role.'_del_'.$img}) {
8573: $confhash->{$role}{$img} = '';
1.12 raeburn 8574: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8575: }
8576: }
1.70 raeburn 8577: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8578: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8579: if ($confhash->{$role}{'showlogo'}{$img} ne
8580: $domconfig->{$role}{'showlogo'}{$img}) {
8581: $changes{$role}{'showlogo'}{$img} = 1;
8582: }
8583: } else {
8584: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8585: $changes{$role}{'showlogo'}{$img} = 1;
8586: }
8587: }
8588: }
8589: }
1.6 raeburn 8590: if ($domconfig->{$role}{'font'} ne '') {
8591: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8592: $changes{$role}{'font'} = 1;
8593: }
8594: } else {
8595: if ($confhash->{$role}{'font'}) {
8596: $changes{$role}{'font'} = 1;
8597: }
8598: }
1.107 raeburn 8599: if ($role ne 'login') {
8600: if ($domconfig->{$role}{'fontmenu'} ne '') {
8601: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8602: $changes{$role}{'fontmenu'} = 1;
8603: }
8604: } else {
8605: if ($confhash->{$role}{'fontmenu'}) {
8606: $changes{$role}{'fontmenu'} = 1;
8607: }
1.97 tempelho 8608: }
8609: }
1.6 raeburn 8610: foreach my $item (@bgs) {
8611: if ($domconfig->{$role}{$item} ne '') {
8612: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8613: $changes{$role}{'bgs'}{$item} = 1;
8614: }
8615: } else {
8616: if ($confhash->{$role}{$item}) {
8617: $changes{$role}{'bgs'}{$item} = 1;
8618: }
8619: }
8620: }
8621: foreach my $item (@links) {
8622: if ($domconfig->{$role}{$item} ne '') {
8623: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8624: $changes{$role}{'links'}{$item} = 1;
8625: }
8626: } else {
8627: if ($confhash->{$role}{$item}) {
8628: $changes{$role}{'links'}{$item} = 1;
8629: }
8630: }
8631: }
1.41 raeburn 8632: foreach my $item (@logintext) {
8633: if ($domconfig->{$role}{$item} ne '') {
8634: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8635: $changes{$role}{'logintext'}{$item} = 1;
8636: }
8637: } else {
8638: if ($confhash->{$role}{$item}) {
8639: $changes{$role}{'logintext'}{$item} = 1;
8640: }
8641: }
8642: }
1.6 raeburn 8643: } else {
8644: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8645: \@logintext,$confhash,\%changes);
1.6 raeburn 8646: }
8647: } else {
8648: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8649: \@logintext,$confhash,\%changes);
1.6 raeburn 8650: }
8651: }
8652: return ($errors,%changes);
8653: }
8654:
1.46 raeburn 8655: sub config_check {
8656: my ($dom,$confname,$servadm) = @_;
8657: my ($configuserok,$author_ok,$switchserver,%currroles);
8658: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8659: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8660: $confname,$servadm);
8661: if ($configuserok eq 'ok') {
8662: $switchserver = &check_switchserver($dom,$confname);
8663: if ($switchserver eq '') {
8664: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8665: }
8666: }
8667: return ($configuserok,$author_ok,$switchserver);
8668: }
8669:
1.6 raeburn 8670: sub default_change_checker {
1.41 raeburn 8671: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8672: foreach my $item (@{$links}) {
8673: if ($confhash->{$role}{$item}) {
8674: $changes->{$role}{'links'}{$item} = 1;
8675: }
8676: }
8677: foreach my $item (@{$bgs}) {
8678: if ($confhash->{$role}{$item}) {
8679: $changes->{$role}{'bgs'}{$item} = 1;
8680: }
8681: }
1.41 raeburn 8682: foreach my $item (@{$logintext}) {
8683: if ($confhash->{$role}{$item}) {
8684: $changes->{$role}{'logintext'}{$item} = 1;
8685: }
8686: }
1.6 raeburn 8687: foreach my $img (@{$images}) {
8688: if ($env{'form.'.$role.'_del_'.$img}) {
8689: $confhash->{$role}{$img} = '';
1.12 raeburn 8690: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8691: }
1.70 raeburn 8692: if ($role eq 'login') {
8693: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8694: $changes->{$role}{'showlogo'}{$img} = 1;
8695: }
8696: }
1.6 raeburn 8697: }
8698: if ($confhash->{$role}{'font'}) {
8699: $changes->{$role}{'font'} = 1;
8700: }
1.48 raeburn 8701: }
1.6 raeburn 8702:
8703: sub display_colorchgs {
8704: my ($dom,$changes,$roles,$confhash) = @_;
8705: my (%choices,$resulttext);
8706: if (!grep(/^login$/,@{$roles})) {
8707: $resulttext = &mt('Changes made:').'<br />';
8708: }
8709: foreach my $role (@{$roles}) {
8710: if ($role eq 'login') {
8711: %choices = &login_choices();
8712: } else {
8713: %choices = &color_font_choices();
8714: }
8715: if (ref($changes->{$role}) eq 'HASH') {
8716: if ($role ne 'login') {
8717: $resulttext .= '<h4>'.&mt($role).'</h4>';
8718: }
8719: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8720: if ($role ne 'login') {
8721: $resulttext .= '<ul>';
8722: }
8723: if (ref($changes->{$role}{$key}) eq 'HASH') {
8724: if ($role ne 'login') {
8725: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8726: }
8727: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8728: if (($role eq 'login') && ($key eq 'showlogo')) {
8729: if ($confhash->{$role}{$key}{$item}) {
8730: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8731: } else {
8732: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8733: }
8734: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8735: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8736: } else {
1.12 raeburn 8737: my $newitem = $confhash->{$role}{$item};
8738: if ($key eq 'images') {
1.306 raeburn 8739: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 8740: }
8741: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8742: }
8743: }
8744: if ($role ne 'login') {
8745: $resulttext .= '</ul></li>';
8746: }
8747: } else {
8748: if ($confhash->{$role}{$key} eq '') {
8749: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8750: } else {
8751: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8752: }
8753: }
8754: if ($role ne 'login') {
8755: $resulttext .= '</ul>';
8756: }
8757: }
8758: }
8759: }
1.3 raeburn 8760: return $resulttext;
1.1 raeburn 8761: }
8762:
1.9 raeburn 8763: sub thumb_dimensions {
8764: return ('200','50');
8765: }
8766:
1.16 raeburn 8767: sub check_dimensions {
8768: my ($inputfile) = @_;
8769: my ($fullwidth,$fullheight);
8770: if ($inputfile =~ m|^[/\w.\-]+$|) {
8771: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8772: my $imageinfo = <PIPE>;
8773: if (!close(PIPE)) {
8774: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8775: }
8776: chomp($imageinfo);
8777: my ($fullsize) =
1.21 raeburn 8778: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8779: if ($fullsize) {
8780: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8781: }
8782: }
8783: }
8784: return ($fullwidth,$fullheight);
8785: }
8786:
1.9 raeburn 8787: sub check_configuser {
8788: my ($uhome,$dom,$confname,$servadm) = @_;
8789: my ($configuserok,%currroles);
8790: if ($uhome eq 'no_host') {
8791: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8792: my $configpass = &LONCAPA::Enrollment::create_password();
8793: $configuserok =
8794: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8795: $configpass,'','','','','',undef,$servadm);
8796: } else {
8797: $configuserok = 'ok';
8798: %currroles =
8799: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8800: }
8801: return ($configuserok,%currroles);
8802: }
8803:
8804: sub check_authorstatus {
8805: my ($dom,$confname,%currroles) = @_;
8806: my $author_ok;
1.40 raeburn 8807: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8808: my $start = time;
8809: my $end = 0;
8810: $author_ok =
8811: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8812: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8813: } else {
8814: $author_ok = 'ok';
8815: }
8816: return $author_ok;
8817: }
8818:
8819: sub publishlogo {
1.46 raeburn 8820: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 8821: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 8822: if ($action eq 'upload') {
8823: $fname=$env{'form.'.$formname.'.filename'};
8824: chop($env{'form.'.$formname});
8825: } else {
8826: ($fname) = ($formname =~ /([^\/]+)$/);
8827: }
1.46 raeburn 8828: if ($savefileas ne '') {
8829: $fname = $savefileas;
8830: }
1.9 raeburn 8831: $fname=&Apache::lonnet::clean_filename($fname);
8832: # See if there is anything left
8833: unless ($fname) { return ('error: no uploaded file'); }
8834: $fname="$subdir/$fname";
1.210 raeburn 8835: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 8836: my $filepath="$docroot/priv";
8837: my $relpath = "$dom/$confname";
1.9 raeburn 8838: my ($fnamepath,$file,$fetchthumb);
8839: $file=$fname;
8840: if ($fname=~m|/|) {
8841: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8842: }
1.164 raeburn 8843: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8844: my $count;
1.164 raeburn 8845: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8846: $filepath.="/$parts[$count]";
8847: if ((-e $filepath)!=1) {
8848: mkdir($filepath,02770);
8849: }
8850: }
8851: # Check for bad extension and disallow upload
8852: if ($file=~/\.(\w+)$/ &&
8853: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8854: $output =
1.207 bisitz 8855: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8856: } elsif ($file=~/\.(\w+)$/ &&
8857: !defined(&Apache::loncommon::fileembstyle($1))) {
8858: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8859: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 8860: $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 8861: } elsif (-d "$filepath/$file") {
1.195 bisitz 8862: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8863: } else {
8864: my $source = $filepath.'/'.$file;
8865: my $logfile;
8866: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 8867: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8868: }
8869: print $logfile
8870: "\n================= Publish ".localtime()." ================\n".
8871: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8872: # Save the file
8873: if (!open(FH,'>'.$source)) {
8874: &Apache::lonnet::logthis('Failed to create '.$source);
8875: return (&mt('Failed to create file'));
8876: }
8877: if ($action eq 'upload') {
8878: if (!print FH ($env{'form.'.$formname})) {
8879: &Apache::lonnet::logthis('Failed to write to '.$source);
8880: return (&mt('Failed to write file'));
8881: }
8882: } else {
8883: my $original = &Apache::lonnet::filelocation('',$formname);
8884: if(!copy($original,$source)) {
8885: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8886: return (&mt('Failed to write file'));
8887: }
8888: }
8889: close(FH);
8890: chmod(0660, $source); # Permissions to rw-rw---.
8891:
8892: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8893: my $copyfile=$targetdir.'/'.$file;
8894:
8895: my @parts=split(/\//,$targetdir);
8896: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8897: for (my $count=5;$count<=$#parts;$count++) {
8898: $path.="/$parts[$count]";
8899: if (!-e $path) {
8900: print $logfile "\nCreating directory ".$path;
8901: mkdir($path,02770);
8902: }
8903: }
8904: my $versionresult;
8905: if (-e $copyfile) {
8906: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8907: } else {
8908: $versionresult = 'ok';
8909: }
8910: if ($versionresult eq 'ok') {
8911: if (copy($source,$copyfile)) {
8912: print $logfile "\nCopied original source to ".$copyfile."\n";
8913: $output = 'ok';
8914: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8915: push(@{$modified_urls},[$copyfile,$source]);
8916: my $metaoutput =
8917: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8918: unless ($registered_cleanup) {
8919: my $handlers = $r->get_handlers('PerlCleanupHandler');
8920: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8921: $registered_cleanup=1;
8922: }
1.9 raeburn 8923: } else {
8924: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8925: $output = &mt('Failed to copy file to RES space').", $!";
8926: }
8927: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8928: my $inputfile = $filepath.'/'.$file;
8929: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8930: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8931: if ($fullwidth ne '' && $fullheight ne '') {
8932: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8933: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8934: system("convert -sample $thumbsize $inputfile $outfile");
8935: chmod(0660, $filepath.'/tn-'.$file);
8936: if (-e $outfile) {
8937: my $copyfile=$targetdir.'/tn-'.$file;
8938: if (copy($outfile,$copyfile)) {
8939: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8940: my $thumb_metaoutput =
8941: &write_metadata($dom,$confname,$formname,
8942: $targetdir,'tn-'.$file,$logfile);
8943: push(@{$modified_urls},[$copyfile,$outfile]);
8944: unless ($registered_cleanup) {
8945: my $handlers = $r->get_handlers('PerlCleanupHandler');
8946: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8947: $registered_cleanup=1;
8948: }
1.267 raeburn 8949: $madethumb = 1;
1.16 raeburn 8950: } else {
8951: print $logfile "\nUnable to write ".$copyfile.
8952: ':'.$!."\n";
8953: }
8954: }
1.9 raeburn 8955: }
8956: }
8957: }
8958: } else {
8959: $output = $versionresult;
8960: }
8961: }
1.267 raeburn 8962: return ($output,$logourl,$madethumb);
1.9 raeburn 8963: }
8964:
8965: sub logo_versioning {
8966: my ($targetdir,$file,$logfile) = @_;
8967: my $target = $targetdir.'/'.$file;
8968: my ($maxversion,$fn,$extn,$output);
8969: $maxversion = 0;
8970: if ($file =~ /^(.+)\.(\w+)$/) {
8971: $fn=$1;
8972: $extn=$2;
8973: }
8974: opendir(DIR,$targetdir);
8975: while (my $filename=readdir(DIR)) {
8976: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8977: $maxversion=($1>$maxversion)?$1:$maxversion;
8978: }
8979: }
8980: $maxversion++;
8981: print $logfile "\nCreating old version ".$maxversion."\n";
8982: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8983: if (copy($target,$copyfile)) {
8984: print $logfile "Copied old target to ".$copyfile."\n";
8985: $copyfile=$copyfile.'.meta';
8986: if (copy($target.'.meta',$copyfile)) {
8987: print $logfile "Copied old target metadata to ".$copyfile."\n";
8988: $output = 'ok';
8989: } else {
8990: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8991: $output = &mt('Failed to copy old meta').", $!, ";
8992: }
8993: } else {
8994: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8995: $output = &mt('Failed to copy old target').", $!, ";
8996: }
8997: return $output;
8998: }
8999:
9000: sub write_metadata {
9001: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9002: my (%metadatafields,%metadatakeys,$output);
9003: $metadatafields{'title'}=$formname;
9004: $metadatafields{'creationdate'}=time;
9005: $metadatafields{'lastrevisiondate'}=time;
9006: $metadatafields{'copyright'}='public';
9007: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9008: $env{'user.domain'};
9009: $metadatafields{'authorspace'}=$confname.':'.$dom;
9010: $metadatafields{'domain'}=$dom;
9011: {
9012: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9013: my $mfh;
1.155 raeburn 9014: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 9015: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 9016: unless ($_=~/\./) {
9017: my $unikey=$_;
9018: $unikey=~/^([A-Za-z]+)/;
9019: my $tag=$1;
9020: $tag=~tr/A-Z/a-z/;
9021: print $mfh "\n\<$tag";
9022: foreach (split(/\,/,$metadatakeys{$unikey})) {
9023: my $value=$metadatafields{$unikey.'.'.$_};
9024: $value=~s/\"/\'\'/g;
9025: print $mfh ' '.$_.'="'.$value.'"';
9026: }
9027: print $mfh '>'.
9028: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9029: .'</'.$tag.'>';
9030: }
9031: }
9032: $output = 'ok';
9033: print $logfile "\nWrote metadata";
9034: close($mfh);
9035: } else {
9036: print $logfile "\nFailed to open metadata file";
1.9 raeburn 9037: $output = &mt('Could not write metadata');
9038: }
9039: }
1.155 raeburn 9040: return $output;
9041: }
9042:
9043: sub notifysubscribed {
9044: foreach my $targetsource (@{$modified_urls}){
9045: next unless (ref($targetsource) eq 'ARRAY');
9046: my ($target,$source)=@{$targetsource};
9047: if ($source ne '') {
9048: if (open(my $logfh,'>>'.$source.'.log')) {
9049: print $logfh "\nCleanup phase: Notifications\n";
9050: my @subscribed=&subscribed_hosts($target);
9051: foreach my $subhost (@subscribed) {
9052: print $logfh "\nNotifying host ".$subhost.':';
9053: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9054: print $logfh $reply;
9055: }
9056: my @subscribedmeta=&subscribed_hosts("$target.meta");
9057: foreach my $subhost (@subscribedmeta) {
9058: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9059: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9060: $subhost);
9061: print $logfh $reply;
9062: }
9063: print $logfh "\n============ Done ============\n";
1.160 raeburn 9064: close($logfh);
1.155 raeburn 9065: }
9066: }
9067: }
9068: return OK;
9069: }
9070:
9071: sub subscribed_hosts {
9072: my ($target) = @_;
9073: my @subscribed;
9074: if (open(my $fh,"<$target.subscription")) {
9075: while (my $subline=<$fh>) {
9076: if ($subline =~ /^($match_lonid):/) {
9077: my $host = $1;
9078: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9079: unless (grep(/^\Q$host\E$/,@subscribed)) {
9080: push(@subscribed,$host);
9081: }
9082: }
9083: }
9084: }
9085: }
9086: return @subscribed;
1.9 raeburn 9087: }
9088:
9089: sub check_switchserver {
9090: my ($dom,$confname) = @_;
9091: my ($allowed,$switchserver);
9092: my $home = &Apache::lonnet::homeserver($confname,$dom);
9093: if ($home eq 'no_host') {
9094: $home = &Apache::lonnet::domain($dom,'primary');
9095: }
9096: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 9097: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9098: if (!$allowed) {
1.180 raeburn 9099: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 9100: }
9101: return $switchserver;
9102: }
9103:
1.1 raeburn 9104: sub modify_quotas {
1.216 raeburn 9105: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 9106: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 9107: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 9108: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9109: $validationfieldsref);
1.86 raeburn 9110: if ($action eq 'quotas') {
9111: $context = 'tools';
1.163 raeburn 9112: } else {
1.86 raeburn 9113: $context = $action;
9114: }
9115: if ($context eq 'requestcourses') {
1.271 raeburn 9116: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 9117: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 9118: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9119: %titles = &courserequest_titles();
9120: $toolregexp = join('|',@usertools);
9121: %conditions = &courserequest_conditions();
1.216 raeburn 9122: $confname = $dom.'-domainconfig';
9123: my $servadm = $r->dir_config('lonAdmEMail');
9124: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 9125: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9126: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 9127: } elsif ($context eq 'requestauthor') {
9128: @usertools = ('author');
9129: %titles = &authorrequest_titles();
1.86 raeburn 9130: } else {
1.162 raeburn 9131: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 9132: %titles = &tool_titles();
1.86 raeburn 9133: }
1.212 raeburn 9134: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 9135: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9136: foreach my $key (keys(%env)) {
1.101 raeburn 9137: if ($context eq 'requestcourses') {
9138: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9139: my $item = $1;
9140: my $type = $2;
9141: if ($type =~ /^limit_(.+)/) {
9142: $limithash{$item}{$1} = $env{$key};
9143: } else {
9144: $confhash{$item}{$type} = $env{$key};
9145: }
9146: }
1.163 raeburn 9147: } elsif ($context eq 'requestauthor') {
9148: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9149: $confhash{$1} = $env{$key};
9150: }
1.101 raeburn 9151: } else {
1.86 raeburn 9152: if ($key =~ /^form\.quota_(.+)$/) {
9153: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 9154: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9155: $confhash{'authorquota'}{$1} = $env{$key};
9156: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 9157: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9158: }
1.72 raeburn 9159: }
9160: }
1.163 raeburn 9161: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 9162: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 9163: @approvalnotify = sort(@approvalnotify);
9164: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 9165: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 9166: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9167: foreach my $type (@hasuniquecode) {
9168: if (grep(/^\Q$type\E$/,@crstypes)) {
9169: $confhash{'uniquecode'}{$type} = 1;
9170: }
1.216 raeburn 9171: }
1.242 raeburn 9172: my (%newbook,%allpos);
1.216 raeburn 9173: if ($context eq 'requestcourses') {
1.242 raeburn 9174: foreach my $type ('textbooks','templates') {
9175: @{$allpos{$type}} = ();
9176: my $invalid;
9177: if ($type eq 'textbooks') {
9178: $invalid = &mt('Invalid LON-CAPA course for textbook');
9179: } else {
9180: $invalid = &mt('Invalid LON-CAPA course for template');
9181: }
9182: if ($env{'form.'.$type.'_addbook'}) {
9183: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9184: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9185: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9186: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9187: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9188: } else {
9189: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9190: my $position = $env{'form.'.$type.'_addbook_pos'};
9191: $position =~ s/\D+//g;
9192: if ($position ne '') {
9193: $allpos{$type}[$position] = $newbook{$type};
9194: }
1.216 raeburn 9195: }
1.242 raeburn 9196: } else {
9197: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 9198: }
9199: }
1.242 raeburn 9200: }
1.216 raeburn 9201: }
1.102 raeburn 9202: if (ref($domconfig{$action}) eq 'HASH') {
9203: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9204: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9205: $changes{'notify'}{'approval'} = 1;
9206: }
9207: } else {
1.144 raeburn 9208: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9209: $changes{'notify'}{'approval'} = 1;
9210: }
9211: }
1.218 raeburn 9212: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9213: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9214: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9215: unless ($confhash{'uniquecode'}{$crstype}) {
9216: $changes{'uniquecode'} = 1;
9217: }
9218: }
9219: unless ($changes{'uniquecode'}) {
9220: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
9221: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
9222: $changes{'uniquecode'} = 1;
9223: }
9224: }
9225: }
9226: } else {
9227: $changes{'uniquecode'} = 1;
9228: }
9229: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
9230: $changes{'uniquecode'} = 1;
1.216 raeburn 9231: }
9232: if ($context eq 'requestcourses') {
1.242 raeburn 9233: foreach my $type ('textbooks','templates') {
9234: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9235: my %deletions;
9236: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9237: if (@todelete) {
9238: map { $deletions{$_} = 1; } @todelete;
9239: }
9240: my %imgdeletions;
9241: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9242: if (@todeleteimages) {
9243: map { $imgdeletions{$_} = 1; } @todeleteimages;
9244: }
9245: my $maxnum = $env{'form.'.$type.'_maxnum'};
9246: for (my $i=0; $i<=$maxnum; $i++) {
9247: my $itemid = $env{'form.'.$type.'_id_'.$i};
9248: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9249: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9250: if ($deletions{$key}) {
9251: if ($domconfig{$action}{$type}{$key}{'image'}) {
9252: #FIXME need to obsolete item in RES space
9253: }
9254: next;
9255: } else {
9256: my $newpos = $env{'form.'.$itemid};
9257: $newpos =~ s/\D+//g;
1.243 raeburn 9258: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 9259: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 9260: ($type eq 'templates'));
1.242 raeburn 9261: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9262: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9263: $changes{$type}{$key} = 1;
9264: }
9265: }
9266: $allpos{$type}[$newpos] = $key;
9267: }
9268: if ($imgdeletions{$key}) {
9269: $changes{$type}{$key} = 1;
1.216 raeburn 9270: #FIXME need to obsolete item in RES space
1.242 raeburn 9271: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9272: my ($cdom,$cnum) = split(/_/,$key);
9273: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9274: $cdom,$cnum,$type,$configuserok,
9275: $switchserver,$author_ok);
9276: if ($imgurl) {
9277: $confhash{$type}{$key}{'image'} = $imgurl;
9278: $changes{$type}{$key} = 1;
1.216 raeburn 9279: }
1.242 raeburn 9280: if ($error) {
9281: &Apache::lonnet::logthis($error);
9282: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9283: }
9284: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
9285: $confhash{$type}{$key}{'image'} =
9286: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 9287: }
9288: }
9289: }
9290: }
9291: }
9292: }
1.102 raeburn 9293: } else {
1.144 raeburn 9294: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9295: $changes{'notify'}{'approval'} = 1;
9296: }
1.218 raeburn 9297: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 9298: $changes{'uniquecode'} = 1;
9299: }
9300: }
9301: if ($context eq 'requestcourses') {
1.242 raeburn 9302: foreach my $type ('textbooks','templates') {
9303: if ($newbook{$type}) {
9304: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 9305: foreach my $item ('subject','title','publisher','author') {
9306: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9307: ($type eq 'template'));
1.242 raeburn 9308: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
9309: if ($env{'form.'.$type.'_addbook_'.$item}) {
9310: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
9311: }
9312: }
9313: if ($type eq 'textbooks') {
9314: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
9315: my ($cdom,$cnum) = split(/_/,$newbook{$type});
9316: my ($imageurl,$error) =
9317: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
9318: $configuserok,$switchserver,$author_ok);
9319: if ($imageurl) {
9320: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
9321: }
9322: if ($error) {
9323: &Apache::lonnet::logthis($error);
9324: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9325: }
9326: }
1.216 raeburn 9327: }
9328: }
1.242 raeburn 9329: if (@{$allpos{$type}} > 0) {
9330: my $idx = 0;
9331: foreach my $item (@{$allpos{$type}}) {
9332: if ($item ne '') {
9333: $confhash{$type}{$item}{'order'} = $idx;
9334: if (ref($domconfig{$action}) eq 'HASH') {
9335: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9336: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
9337: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
9338: $changes{$type}{$item} = 1;
9339: }
1.216 raeburn 9340: }
9341: }
9342: }
1.242 raeburn 9343: $idx ++;
1.216 raeburn 9344: }
9345: }
9346: }
9347: }
1.235 raeburn 9348: if (ref($validationitemsref) eq 'ARRAY') {
9349: foreach my $item (@{$validationitemsref}) {
9350: if ($item eq 'fields') {
9351: my @changed;
9352: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9353: if (@{$confhash{'validation'}{$item}} > 0) {
9354: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9355: }
1.266 raeburn 9356: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9357: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9358: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9359: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9360: $domconfig{'requestcourses'}{'validation'}{$item});
9361: } else {
9362: @changed = @{$confhash{'validation'}{$item}};
9363: }
1.235 raeburn 9364: } else {
9365: @changed = @{$confhash{'validation'}{$item}};
9366: }
9367: } else {
9368: @changed = @{$confhash{'validation'}{$item}};
9369: }
9370: if (@changed) {
9371: if ($confhash{'validation'}{$item}) {
9372: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9373: } else {
9374: $changes{'validation'}{$item} = &mt('None');
9375: }
9376: }
9377: } else {
9378: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9379: if ($item eq 'markup') {
9380: if ($env{'form.requestcourses_validation_'.$item}) {
9381: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9382: }
9383: }
1.266 raeburn 9384: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9385: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9386: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9387: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9388: }
9389: } else {
9390: if ($confhash{'validation'}{$item} ne '') {
9391: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9392: }
1.235 raeburn 9393: }
9394: } else {
9395: if ($confhash{'validation'}{$item} ne '') {
9396: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9397: }
9398: }
9399: }
9400: }
9401: }
9402: if ($env{'form.validationdc'}) {
9403: my $newval = $env{'form.validationdc'};
1.285 raeburn 9404: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 9405: if (exists($domcoords{$newval})) {
9406: $confhash{'validation'}{'dc'} = $newval;
9407: }
9408: }
9409: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 9410: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9411: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9412: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9413: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9414: if ($confhash{'validation'}{'dc'} eq '') {
9415: $changes{'validation'}{'dc'} = &mt('None');
9416: } else {
9417: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9418: }
1.235 raeburn 9419: }
1.266 raeburn 9420: } elsif ($confhash{'validation'}{'dc'} ne '') {
9421: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 9422: }
9423: } elsif ($confhash{'validation'}{'dc'} ne '') {
9424: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9425: }
9426: } elsif ($confhash{'validation'}{'dc'} ne '') {
9427: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 9428: }
1.266 raeburn 9429: } else {
9430: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9431: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9432: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9433: $changes{'validation'}{'dc'} = &mt('None');
9434: }
9435: }
1.235 raeburn 9436: }
9437: }
1.102 raeburn 9438: }
9439: } else {
1.86 raeburn 9440: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 9441: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9442: }
1.72 raeburn 9443: foreach my $item (@usertools) {
9444: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9445: my $unset;
1.101 raeburn 9446: if ($context eq 'requestcourses') {
1.104 raeburn 9447: $unset = '0';
9448: if ($type eq '_LC_adv') {
9449: $unset = '';
9450: }
1.101 raeburn 9451: if ($confhash{$item}{$type} eq 'autolimit') {
9452: $confhash{$item}{$type} .= '=';
9453: unless ($limithash{$item}{$type} =~ /\D/) {
9454: $confhash{$item}{$type} .= $limithash{$item}{$type};
9455: }
9456: }
1.163 raeburn 9457: } elsif ($context eq 'requestauthor') {
9458: $unset = '0';
9459: if ($type eq '_LC_adv') {
9460: $unset = '';
9461: }
1.72 raeburn 9462: } else {
1.101 raeburn 9463: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9464: $confhash{$item}{$type} = 1;
9465: } else {
9466: $confhash{$item}{$type} = 0;
9467: }
1.72 raeburn 9468: }
1.86 raeburn 9469: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 9470: if ($action eq 'requestauthor') {
9471: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9472: $changes{$type} = 1;
9473: }
9474: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9475: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9476: $changes{$item}{$type} = 1;
9477: }
9478: } else {
9479: if ($context eq 'requestcourses') {
1.104 raeburn 9480: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9481: $changes{$item}{$type} = 1;
9482: }
9483: } else {
9484: if (!$confhash{$item}{$type}) {
9485: $changes{$item}{$type} = 1;
9486: }
9487: }
9488: }
9489: } else {
9490: if ($context eq 'requestcourses') {
1.104 raeburn 9491: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9492: $changes{$item}{$type} = 1;
9493: }
1.163 raeburn 9494: } elsif ($context eq 'requestauthor') {
9495: if ($confhash{$type} ne $unset) {
9496: $changes{$type} = 1;
9497: }
1.72 raeburn 9498: } else {
9499: if (!$confhash{$item}{$type}) {
9500: $changes{$item}{$type} = 1;
9501: }
9502: }
9503: }
1.1 raeburn 9504: }
9505: }
1.163 raeburn 9506: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9507: if (ref($domconfig{'quotas'}) eq 'HASH') {
9508: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9509: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9510: if (exists($confhash{'defaultquota'}{$key})) {
9511: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9512: $changes{'defaultquota'}{$key} = 1;
9513: }
9514: } else {
9515: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9516: }
9517: }
1.86 raeburn 9518: } else {
9519: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9520: if (exists($confhash{'defaultquota'}{$key})) {
9521: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9522: $changes{'defaultquota'}{$key} = 1;
9523: }
9524: } else {
9525: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9526: }
1.1 raeburn 9527: }
9528: }
1.197 raeburn 9529: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9530: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9531: if (exists($confhash{'authorquota'}{$key})) {
9532: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9533: $changes{'authorquota'}{$key} = 1;
9534: }
9535: } else {
9536: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9537: }
9538: }
9539: }
1.1 raeburn 9540: }
1.86 raeburn 9541: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9542: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9543: if (ref($domconfig{'quotas'}) eq 'HASH') {
9544: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9545: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9546: $changes{'defaultquota'}{$key} = 1;
9547: }
9548: } else {
9549: if (!exists($domconfig{'quotas'}{$key})) {
9550: $changes{'defaultquota'}{$key} = 1;
9551: }
1.72 raeburn 9552: }
9553: } else {
1.86 raeburn 9554: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9555: }
1.1 raeburn 9556: }
9557: }
1.197 raeburn 9558: if (ref($confhash{'authorquota'}) eq 'HASH') {
9559: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9560: if (ref($domconfig{'quotas'}) eq 'HASH') {
9561: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9562: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9563: $changes{'authorquota'}{$key} = 1;
9564: }
9565: } else {
9566: $changes{'authorquota'}{$key} = 1;
9567: }
9568: } else {
9569: $changes{'authorquota'}{$key} = 1;
9570: }
9571: }
9572: }
1.1 raeburn 9573: }
1.72 raeburn 9574:
1.163 raeburn 9575: if ($context eq 'requestauthor') {
9576: $domdefaults{'requestauthor'} = \%confhash;
9577: } else {
9578: foreach my $key (keys(%confhash)) {
1.242 raeburn 9579: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 9580: $domdefaults{$key} = $confhash{$key};
9581: }
1.163 raeburn 9582: }
1.72 raeburn 9583: }
1.163 raeburn 9584:
1.1 raeburn 9585: my %quotahash = (
1.86 raeburn 9586: $action => { %confhash }
1.1 raeburn 9587: );
9588: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9589: $dom);
9590: if ($putresult eq 'ok') {
9591: if (keys(%changes) > 0) {
1.72 raeburn 9592: my $cachetime = 24*60*60;
9593: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9594: if (ref($lastactref) eq 'HASH') {
9595: $lastactref->{'domdefaults'} = 1;
9596: }
1.1 raeburn 9597: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 9598: unless (($context eq 'requestcourses') ||
1.163 raeburn 9599: ($context eq 'requestauthor')) {
1.86 raeburn 9600: if (ref($changes{'defaultquota'}) eq 'HASH') {
9601: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9602: foreach my $type (@{$types},'default') {
9603: if (defined($changes{'defaultquota'}{$type})) {
9604: my $typetitle = $usertypes->{$type};
9605: if ($type eq 'default') {
9606: $typetitle = $othertitle;
9607: }
1.213 raeburn 9608: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9609: }
9610: }
1.86 raeburn 9611: $resulttext .= '</ul></li>';
1.72 raeburn 9612: }
1.197 raeburn 9613: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 9614: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 9615: foreach my $type (@{$types},'default') {
9616: if (defined($changes{'authorquota'}{$type})) {
9617: my $typetitle = $usertypes->{$type};
9618: if ($type eq 'default') {
9619: $typetitle = $othertitle;
9620: }
1.213 raeburn 9621: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 9622: }
9623: }
9624: $resulttext .= '</ul></li>';
9625: }
1.72 raeburn 9626: }
1.80 raeburn 9627: my %newenv;
1.72 raeburn 9628: foreach my $item (@usertools) {
1.163 raeburn 9629: my (%haschgs,%inconf);
9630: if ($context eq 'requestauthor') {
9631: %haschgs = %changes;
1.210 raeburn 9632: %inconf = %confhash;
1.163 raeburn 9633: } else {
9634: if (ref($changes{$item}) eq 'HASH') {
9635: %haschgs = %{$changes{$item}};
9636: }
9637: if (ref($confhash{$item}) eq 'HASH') {
9638: %inconf = %{$confhash{$item}};
9639: }
9640: }
9641: if (keys(%haschgs) > 0) {
1.80 raeburn 9642: my $newacc =
9643: &Apache::lonnet::usertools_access($env{'user.name'},
9644: $env{'user.domain'},
1.86 raeburn 9645: $item,'reload',$context);
1.210 raeburn 9646: if (($context eq 'requestcourses') ||
1.163 raeburn 9647: ($context eq 'requestauthor')) {
1.108 raeburn 9648: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9649: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9650: }
9651: } else {
9652: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9653: $newenv{'environment.availabletools.'.$item} = $newacc;
9654: }
1.80 raeburn 9655: }
1.163 raeburn 9656: unless ($context eq 'requestauthor') {
9657: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9658: }
1.72 raeburn 9659: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 9660: if ($haschgs{$type}) {
1.72 raeburn 9661: my $typetitle = $usertypes->{$type};
9662: if ($type eq 'default') {
9663: $typetitle = $othertitle;
9664: } elsif ($type eq '_LC_adv') {
9665: $typetitle = 'LON-CAPA Advanced Users';
9666: }
1.163 raeburn 9667: if ($inconf{$type}) {
1.101 raeburn 9668: if ($context eq 'requestcourses') {
9669: my $cond;
1.163 raeburn 9670: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9671: if ($1 eq '') {
9672: $cond = &mt('(Automatic processing of any request).');
9673: } else {
9674: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9675: }
9676: } else {
1.163 raeburn 9677: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9678: }
9679: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 9680: } elsif ($context eq 'requestauthor') {
9681: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9682: $titles{$inconf{$type}},$typetitle);
9683:
1.101 raeburn 9684: } else {
9685: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9686: }
1.72 raeburn 9687: } else {
1.104 raeburn 9688: if ($type eq '_LC_adv') {
1.163 raeburn 9689: if ($inconf{$type} eq '0') {
1.104 raeburn 9690: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9691: } else {
9692: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9693: }
9694: } else {
9695: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9696: }
1.72 raeburn 9697: }
9698: }
1.26 raeburn 9699: }
1.163 raeburn 9700: unless ($context eq 'requestauthor') {
9701: $resulttext .= '</ul></li>';
9702: }
1.26 raeburn 9703: }
1.1 raeburn 9704: }
1.163 raeburn 9705: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9706: if (ref($changes{'notify'}) eq 'HASH') {
9707: if ($changes{'notify'}{'approval'}) {
9708: if (ref($confhash{'notify'}) eq 'HASH') {
9709: if ($confhash{'notify'}{'approval'}) {
9710: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9711: } else {
1.163 raeburn 9712: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9713: }
9714: }
9715: }
9716: }
9717: }
1.216 raeburn 9718: if ($action eq 'requestcourses') {
9719: my @offon = ('off','on');
9720: if ($changes{'uniquecode'}) {
1.218 raeburn 9721: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9722: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9723: $resulttext .= '<li>'.
9724: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9725: '</li>';
9726: } else {
9727: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9728: '</li>';
9729: }
1.216 raeburn 9730: }
1.242 raeburn 9731: foreach my $type ('textbooks','templates') {
9732: if (ref($changes{$type}) eq 'HASH') {
9733: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9734: foreach my $key (sort(keys(%{$changes{$type}}))) {
9735: my %coursehash = &Apache::lonnet::coursedescription($key);
9736: my $coursetitle = $coursehash{'description'};
9737: my $position = $confhash{$type}{$key}{'order'} + 1;
9738: $resulttext .= '<li>';
1.243 raeburn 9739: foreach my $item ('subject','title','publisher','author') {
9740: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9741: ($type eq 'templates'));
1.242 raeburn 9742: my $name = $item.':';
9743: $name =~ s/^(\w)/\U$1/;
9744: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9745: }
9746: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9747: if ($type eq 'textbooks') {
9748: if ($confhash{$type}{$key}{'image'}) {
9749: $resulttext .= ' '.&mt('Image: [_1]',
9750: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9751: ' alt="Textbook cover" />').'<br />';
9752: }
9753: }
9754: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 9755: }
1.242 raeburn 9756: $resulttext .= '</ul></li>';
1.216 raeburn 9757: }
9758: }
1.235 raeburn 9759: if (ref($changes{'validation'}) eq 'HASH') {
9760: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9761: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9762: foreach my $item (@{$validationitemsref}) {
9763: if (exists($changes{'validation'}{$item})) {
9764: if ($item eq 'markup') {
9765: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9766: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9767: } else {
9768: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9769: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9770: }
9771: }
9772: }
9773: if (exists($changes{'validation'}{'dc'})) {
9774: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9775: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9776: }
9777: }
9778: }
1.216 raeburn 9779: }
1.1 raeburn 9780: $resulttext .= '</ul>';
1.80 raeburn 9781: if (keys(%newenv)) {
9782: &Apache::lonnet::appenv(\%newenv);
9783: }
1.1 raeburn 9784: } else {
1.86 raeburn 9785: if ($context eq 'requestcourses') {
9786: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 9787: } elsif ($context eq 'requestauthor') {
9788: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9789: } else {
1.90 weissno 9790: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9791: }
1.1 raeburn 9792: }
9793: } else {
1.11 albertel 9794: $resulttext = '<span class="LC_error">'.
9795: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9796: }
1.216 raeburn 9797: if ($errors) {
9798: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9799: '<ul>'.$errors.'</ul></p>';
9800: }
1.3 raeburn 9801: return $resulttext;
1.1 raeburn 9802: }
9803:
1.216 raeburn 9804: sub process_textbook_image {
1.242 raeburn 9805: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 9806: my $filename = $env{'form.'.$caller.'.filename'};
9807: my ($error,$url);
9808: my ($width,$height) = (50,50);
9809: if ($configuserok eq 'ok') {
9810: if ($switchserver) {
9811: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9812: $switchserver);
9813: } elsif ($author_ok eq 'ok') {
9814: my ($result,$imageurl) =
9815: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 9816: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 9817: if ($result eq 'ok') {
9818: $url = $imageurl;
9819: } else {
9820: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9821: }
9822: } else {
9823: $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);
9824: }
9825: } else {
9826: $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);
9827: }
9828: return ($url,$error);
9829: }
9830:
1.267 raeburn 9831: sub modify_ltitools {
9832: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9833: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 9834: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 9835: my $confname = $dom.'-domainconfig';
9836: my $servadm = $r->dir_config('lonAdmEMail');
9837: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9838: my (%posslti,%possfield);
9839: my @courseroles = ('cc','in','ta','ep','st');
9840: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9841: map { $posslti{$_} = 1; } @ltiroles;
9842: my @allfields = ('fullname','firstname','lastname','email','user','roles');
9843: map { $possfield{$_} = 1; } @allfields;
9844: my %lt = <itools_names();
9845: if ($env{'form.ltitools_add'}) {
9846: my $title = $env{'form.ltitools_add_title'};
9847: $title =~ s/(`)/'/g;
9848: ($newid,my $error) = &get_ltitools_id($dom,$title);
9849: if ($newid) {
9850: my $position = $env{'form.ltitools_add_pos'};
9851: $position =~ s/\D+//g;
9852: if ($position ne '') {
9853: $allpos[$position] = $newid;
9854: }
9855: $changes{$newid} = 1;
9856: foreach my $item ('title','url','key','secret') {
9857: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9858: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 9859: if (($item eq 'key') || ($item eq 'secret')) {
9860: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9861: } else {
9862: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9863: }
1.267 raeburn 9864: }
9865: }
9866: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9867: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9868: }
9869: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9870: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9871: }
1.296 raeburn 9872: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 9873: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9874: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 9875: if (($item eq 'width') || ($item eq 'height')) {
9876: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9877: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9878: }
9879: } else {
9880: if ($env{'form.ltitools_add_'.$item} ne '') {
9881: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9882: }
1.267 raeburn 9883: }
9884: }
9885: if ($env{'form.ltitools_add_target'} eq 'window') {
9886: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 9887: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
9888: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 9889: } else {
9890: $confhash{$newid}{'display'}{'target'} = 'iframe';
9891: }
9892: foreach my $item ('passback','roster') {
9893: if ($env{'form.ltitools_add_'.$item}) {
9894: $confhash{$newid}{$item} = 1;
9895: }
9896: }
9897: if ($env{'form.ltitools_add_image.filename'} ne '') {
9898: my ($imageurl,$error) =
1.307 raeburn 9899: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 9900: $configuserok,$switchserver,$author_ok);
9901: if ($imageurl) {
9902: $confhash{$newid}{'image'} = $imageurl;
9903: }
9904: if ($error) {
9905: &Apache::lonnet::logthis($error);
9906: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9907: }
9908: }
9909: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9910: foreach my $field (@fields) {
9911: if ($possfield{$field}) {
9912: if ($field eq 'roles') {
9913: foreach my $role (@courseroles) {
9914: my $choice = $env{'form.ltitools_add_roles_'.$role};
9915: if (($choice ne '') && ($posslti{$choice})) {
9916: $confhash{$newid}{'roles'}{$role} = $choice;
9917: if ($role eq 'cc') {
9918: $confhash{$newid}{'roles'}{'co'} = $choice;
9919: }
9920: }
9921: }
9922: } else {
9923: $confhash{$newid}{'fields'}{$field} = 1;
9924: }
9925: }
9926: }
1.273 raeburn 9927: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9928: foreach my $item (@courseconfig) {
9929: $confhash{$newid}{'crsconf'}{$item} = 1;
9930: }
1.267 raeburn 9931: if ($env{'form.ltitools_add_custom'}) {
9932: my $name = $env{'form.ltitools_add_custom_name'};
9933: my $value = $env{'form.ltitools_add_custom_value'};
9934: $value =~ s/(`)/'/g;
9935: $name =~ s/(`)/'/g;
9936: $confhash{$newid}{'custom'}{$name} = $value;
9937: }
9938: } else {
9939: my $error = &mt('Failed to acquire unique ID for new external tool');
9940: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9941: }
9942: }
9943: if (ref($domconfig{$action}) eq 'HASH') {
9944: my %deletions;
9945: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9946: if (@todelete) {
9947: map { $deletions{$_} = 1; } @todelete;
9948: }
9949: my %customadds;
9950: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9951: if (@newcustom) {
9952: map { $customadds{$_} = 1; } @newcustom;
9953: }
9954: my %imgdeletions;
9955: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9956: if (@todeleteimages) {
9957: map { $imgdeletions{$_} = 1; } @todeleteimages;
9958: }
9959: my $maxnum = $env{'form.ltitools_maxnum'};
9960: for (my $i=0; $i<=$maxnum; $i++) {
9961: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 ! raeburn 9962: $itemid =~ s/\D+//g;
1.267 raeburn 9963: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9964: if ($deletions{$itemid}) {
9965: if ($domconfig{$action}{$itemid}{'image'}) {
9966: #FIXME need to obsolete item in RES space
9967: }
9968: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9969: next;
9970: } else {
9971: my $newpos = $env{'form.ltitools_'.$itemid};
9972: $newpos =~ s/\D+//g;
1.297 raeburn 9973: foreach my $item ('title','url') {
1.267 raeburn 9974: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9975: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9976: $changes{$itemid} = 1;
9977: }
9978: }
1.297 raeburn 9979: foreach my $item ('key','secret') {
9980: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9981: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
9982: $changes{$itemid} = 1;
9983: }
9984: }
1.267 raeburn 9985: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9986: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9987: }
9988: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9989: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9990: }
9991: foreach my $size ('width','height') {
9992: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9993: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9994: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9995: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9996: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9997: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9998: $changes{$itemid} = 1;
9999: }
10000: } else {
10001: $changes{$itemid} = 1;
10002: }
1.296 raeburn 10003: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10004: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
10005: $changes{$itemid} = 1;
10006: }
10007: }
10008: }
10009: foreach my $item ('linktext','explanation') {
10010: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
10011: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
10012: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
10013: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10014: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10015: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
10016: $changes{$itemid} = 1;
10017: }
10018: } else {
10019: $changes{$itemid} = 1;
10020: }
10021: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10022: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
10023: $changes{$itemid} = 1;
10024: }
1.267 raeburn 10025: }
10026: }
10027: if ($env{'form.ltitools_target_'.$i} eq 'window') {
10028: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 10029: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
10030: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 10031: } else {
10032: $confhash{$itemid}{'display'}{'target'} = 'iframe';
10033: }
10034: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10035: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
10036: $changes{$itemid} = 1;
10037: }
10038: } else {
10039: $changes{$itemid} = 1;
10040: }
10041: foreach my $extra ('passback','roster') {
10042: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
10043: $confhash{$itemid}{$extra} = 1;
10044: }
10045: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
10046: $changes{$itemid} = 1;
10047: }
10048: }
1.273 raeburn 10049: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.296 raeburn 10050: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 10051: if (grep(/^\Q$item\E$/,@courseconfig)) {
10052: $confhash{$itemid}{'crsconf'}{$item} = 1;
10053: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
10054: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
10055: $changes{$itemid} = 1;
10056: }
10057: } else {
10058: $changes{$itemid} = 1;
10059: }
10060: }
10061: }
1.267 raeburn 10062: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
10063: foreach my $field (@fields) {
10064: if ($possfield{$field}) {
10065: if ($field eq 'roles') {
10066: foreach my $role (@courseroles) {
10067: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
10068: if (($choice ne '') && ($posslti{$choice})) {
10069: $confhash{$itemid}{'roles'}{$role} = $choice;
10070: if ($role eq 'cc') {
10071: $confhash{$itemid}{'roles'}{'co'} = $choice;
10072: }
10073: }
10074: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
10075: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
10076: $changes{$itemid} = 1;
10077: }
10078: } elsif ($confhash{$itemid}{'roles'}{$role}) {
10079: $changes{$itemid} = 1;
10080: }
10081: }
10082: } else {
10083: $confhash{$itemid}{'fields'}{$field} = 1;
10084: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
10085: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
10086: $changes{$itemid} = 1;
10087: }
10088: } else {
10089: $changes{$itemid} = 1;
10090: }
10091: }
10092: }
10093: }
10094: $allpos[$newpos] = $itemid;
10095: }
10096: if ($imgdeletions{$itemid}) {
10097: $changes{$itemid} = 1;
10098: #FIXME need to obsolete item in RES space
10099: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
10100: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
10101: $itemid,$configuserok,$switchserver,
10102: $author_ok);
10103: if ($imgurl) {
10104: $confhash{$itemid}{'image'} = $imgurl;
10105: $changes{$itemid} = 1;
10106: }
10107: if ($error) {
10108: &Apache::lonnet::logthis($error);
10109: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10110: }
10111: } elsif ($domconfig{$action}{$itemid}{'image'}) {
10112: $confhash{$itemid}{'image'} =
10113: $domconfig{$action}{$itemid}{'image'};
10114: }
10115: if ($customadds{$i}) {
10116: my $name = $env{'form.ltitools_custom_name_'.$i};
10117: $name =~ s/(`)/'/g;
10118: $name =~ s/^\s+//;
10119: $name =~ s/\s+$//;
10120: my $value = $env{'form.ltitools_custom_value_'.$i};
10121: $value =~ s/(`)/'/g;
10122: $value =~ s/^\s+//;
10123: $value =~ s/\s+$//;
10124: if ($name ne '') {
10125: $confhash{$itemid}{'custom'}{$name} = $value;
10126: $changes{$itemid} = 1;
10127: }
10128: }
10129: my %customdels;
10130: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
10131: if (@customdeletions) {
10132: $changes{$itemid} = 1;
10133: }
10134: map { $customdels{$_} = 1; } @customdeletions;
10135: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
10136: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
10137: unless ($customdels{$key}) {
10138: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
10139: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
10140: }
10141: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
10142: $changes{$itemid} = 1;
10143: }
10144: }
10145: }
10146: }
10147: unless ($changes{$itemid}) {
10148: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
10149: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
10150: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
10151: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
10152: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
10153: $changes{$itemid} = 1;
10154: last;
10155: }
10156: }
10157: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
10158: $changes{$itemid} = 1;
10159: }
10160: }
10161: last if ($changes{$itemid});
10162: }
10163: }
10164: }
10165: }
10166: }
10167: if (@allpos > 0) {
10168: my $idx = 0;
10169: foreach my $itemid (@allpos) {
10170: if ($itemid ne '') {
10171: $confhash{$itemid}{'order'} = $idx;
10172: if (ref($domconfig{$action}) eq 'HASH') {
10173: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10174: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
10175: $changes{$itemid} = 1;
10176: }
10177: }
10178: }
10179: $idx ++;
10180: }
10181: }
10182: }
10183: my %ltitoolshash = (
10184: $action => { %confhash }
10185: );
10186: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
10187: $dom);
10188: if ($putresult eq 'ok') {
1.297 raeburn 10189: my %ltienchash = (
10190: $action => { %encconfig }
10191: );
10192: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 10193: if (keys(%changes) > 0) {
10194: my $cachetime = 24*60*60;
1.297 raeburn 10195: my %ltiall = %confhash;
10196: foreach my $id (keys(%ltiall)) {
10197: if (ref($encconfig{$id}) eq 'HASH') {
10198: foreach my $item ('key','secret') {
10199: $ltiall{$id}{$item} = $encconfig{$id}{$item};
10200: }
10201: }
10202: }
10203: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 10204: if (ref($lastactref) eq 'HASH') {
10205: $lastactref->{'ltitools'} = 1;
10206: }
10207: $resulttext = &mt('Changes made:').'<ul>';
10208: my %bynum;
10209: foreach my $itemid (sort(keys(%changes))) {
10210: my $position = $confhash{$itemid}{'order'};
10211: $bynum{$position} = $itemid;
10212: }
10213: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10214: my $itemid = $bynum{$pos};
10215: if (ref($confhash{$itemid}) ne 'HASH') {
10216: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10217: } else {
10218: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
10219: if ($confhash{$itemid}{'image'}) {
10220: $resulttext .= ' '.
10221: '<img src="'.$confhash{$itemid}{'image'}.'"'.
10222: ' alt="'.&mt('Tool Provider icon').'" />';
10223: }
10224: $resulttext .= '</li><ul>';
10225: my $position = $pos + 1;
10226: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.297 raeburn 10227: foreach my $item ('version','msgtype','url') {
1.267 raeburn 10228: if ($confhash{$itemid}{$item} ne '') {
10229: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
10230: }
10231: }
1.297 raeburn 10232: if ($encconfig{$itemid}{'key'} ne '') {
10233: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
10234: }
10235: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 10236: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 10237: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 10238: $resulttext .= ('*'x$num).'</li>';
10239: }
1.273 raeburn 10240: $resulttext .= '<li>'.&mt('Configurable in course:');
1.296 raeburn 10241: my @possconfig = ('label','title','target','linktext','explanation');
1.273 raeburn 10242: my $numconfig = 0;
10243: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
10244: foreach my $item (@possconfig) {
10245: if ($confhash{$itemid}{'crsconf'}{$item}) {
10246: $numconfig ++;
1.296 raeburn 10247: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 10248: }
10249: }
10250: }
10251: if (!$numconfig) {
10252: $resulttext .= &mt('None');
10253: }
10254: $resulttext .= '</li>';
1.267 raeburn 10255: foreach my $item ('passback','roster') {
10256: $resulttext .= '<li>'.$lt{$item}.' ';
10257: if ($confhash{$itemid}{$item}) {
10258: $resulttext .= &mt('Yes');
10259: } else {
10260: $resulttext .= &mt('No');
10261: }
10262: $resulttext .= '</li>';
10263: }
10264: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
10265: my $displaylist;
10266: if ($confhash{$itemid}{'display'}{'target'}) {
10267: $displaylist = &mt('Display target').': '.
10268: $confhash{$itemid}{'display'}{'target'}.',';
10269: }
10270: foreach my $size ('width','height') {
10271: if ($confhash{$itemid}{'display'}{$size}) {
10272: $displaylist .= (' 'x2).$lt{$size}.': '.
10273: $confhash{$itemid}{'display'}{$size}.',';
10274: }
10275: }
10276: if ($displaylist) {
10277: $displaylist =~ s/,$//;
10278: $resulttext .= '<li>'.$displaylist.'</li>';
10279: }
1.296 raeburn 10280: foreach my $item ('linktext','explanation') {
10281: if ($confhash{$itemid}{'display'}{$item}) {
10282: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
10283: }
10284: }
10285: }
1.267 raeburn 10286: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
10287: my $fieldlist;
10288: foreach my $field (@allfields) {
10289: if ($confhash{$itemid}{'fields'}{$field}) {
10290: $fieldlist .= (' 'x2).$lt{$field}.',';
10291: }
10292: }
10293: if ($fieldlist) {
10294: $fieldlist =~ s/,$//;
10295: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
10296: }
10297: }
10298: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
10299: my $rolemaps;
10300: foreach my $role (@courseroles) {
10301: if ($confhash{$itemid}{'roles'}{$role}) {
10302: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
10303: $confhash{$itemid}{'roles'}{$role}.',';
10304: }
10305: }
10306: if ($rolemaps) {
10307: $rolemaps =~ s/,$//;
10308: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
10309: }
10310: }
10311: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
10312: my $customlist;
10313: if (keys(%{$confhash{$itemid}{'custom'}})) {
10314: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
10315: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
10316: }
10317: }
10318: if ($customlist) {
10319: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
10320: }
10321: }
10322: $resulttext .= '</ul></li>';
10323: }
10324: }
10325: $resulttext .= '</ul>';
10326: } else {
10327: $resulttext = &mt('No changes made.');
10328: }
10329: } else {
10330: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10331: }
10332: if ($errors) {
10333: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10334: $errors.'</ul>';
10335: }
10336: return $resulttext;
10337: }
10338:
10339: sub process_ltitools_image {
10340: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
10341: my $filename = $env{'form.'.$caller.'.filename'};
10342: my ($error,$url);
10343: my ($width,$height) = (21,21);
10344: if ($configuserok eq 'ok') {
10345: if ($switchserver) {
10346: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
10347: $switchserver);
10348: } elsif ($author_ok eq 'ok') {
10349: my ($result,$imageurl,$madethumb) =
10350: &publishlogo($r,'upload',$caller,$dom,$confname,
10351: "ltitools/$itemid/icon",$width,$height);
10352: if ($result eq 'ok') {
10353: if ($madethumb) {
10354: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
10355: my $imagethumb = "$path/tn-".$imagefile;
10356: $url = $imagethumb;
10357: } else {
10358: $url = $imageurl;
10359: }
10360: } else {
10361: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10362: }
10363: } else {
10364: $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);
10365: }
10366: } else {
10367: $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);
10368: }
10369: return ($url,$error);
10370: }
10371:
10372: sub get_ltitools_id {
10373: my ($cdom,$title) = @_;
10374: # get lock on ltitools db
10375: my $lockhash = {
10376: lock => $env{'user.name'}.
10377: ':'.$env{'user.domain'},
10378: };
10379: my $tries = 0;
10380: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10381: my ($id,$error);
10382:
10383: while (($gotlock ne 'ok') && ($tries<10)) {
10384: $tries ++;
10385: sleep (0.1);
10386: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10387: }
10388: if ($gotlock eq 'ok') {
10389: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
10390: if ($currids{'lock'}) {
10391: delete($currids{'lock'});
10392: if (keys(%currids)) {
10393: my @curr = sort { $a <=> $b } keys(%currids);
10394: if ($curr[-1] =~ /^\d+$/) {
10395: $id = 1 + $curr[-1];
10396: }
10397: } else {
10398: $id = 1;
10399: }
10400: if ($id) {
10401: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
10402: $error = 'nostore';
10403: }
10404: } else {
10405: $error = 'nonumber';
10406: }
10407: }
10408: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
10409: } else {
10410: $error = 'nolock';
10411: }
10412: return ($id,$error);
10413: }
10414:
1.3 raeburn 10415: sub modify_autoenroll {
1.205 raeburn 10416: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 10417: my ($resulttext,%changes);
10418: my %currautoenroll;
10419: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
10420: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
10421: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
10422: }
10423: }
10424: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
10425: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 10426: sender => 'Sender for notification messages',
1.274 raeburn 10427: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
10428: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 10429: my @offon = ('off','on');
1.17 raeburn 10430: my $sender_uname = $env{'form.sender_uname'};
10431: my $sender_domain = $env{'form.sender_domain'};
10432: if ($sender_domain eq '') {
10433: $sender_uname = '';
10434: } elsif ($sender_uname eq '') {
10435: $sender_domain = '';
10436: }
1.129 raeburn 10437: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 10438: my $failsafe = $env{'form.autoenroll_failsafe'};
10439: $failsafe =~ s{^\s+|\s+$}{}g;
10440: if ($failsafe =~ /\D/) {
10441: undef($failsafe);
10442: }
1.1 raeburn 10443: my %autoenrollhash = (
1.129 raeburn 10444: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10445: 'sender_uname' => $sender_uname,
10446: 'sender_domain' => $sender_domain,
10447: 'co-owners' => $coowners,
1.274 raeburn 10448: 'autofailsafe' => $failsafe,
1.1 raeburn 10449: }
10450: );
1.4 raeburn 10451: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10452: $dom);
1.1 raeburn 10453: if ($putresult eq 'ok') {
10454: if (exists($currautoenroll{'run'})) {
10455: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10456: $changes{'run'} = 1;
10457: }
10458: } elsif ($autorun) {
10459: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 10460: $changes{'run'} = 1;
1.1 raeburn 10461: }
10462: }
1.17 raeburn 10463: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 10464: $changes{'sender'} = 1;
10465: }
1.17 raeburn 10466: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 10467: $changes{'sender'} = 1;
10468: }
1.129 raeburn 10469: if ($currautoenroll{'co-owners'} ne '') {
10470: if ($currautoenroll{'co-owners'} ne $coowners) {
10471: $changes{'coowners'} = 1;
10472: }
10473: } elsif ($coowners) {
10474: $changes{'coowners'} = 1;
1.274 raeburn 10475: }
10476: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10477: $changes{'autofailsafe'} = 1;
10478: }
1.1 raeburn 10479: if (keys(%changes) > 0) {
10480: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 10481: if ($changes{'run'}) {
1.1 raeburn 10482: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10483: }
10484: if ($changes{'sender'}) {
1.17 raeburn 10485: if ($sender_uname eq '' || $sender_domain eq '') {
10486: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10487: } else {
10488: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10489: }
1.1 raeburn 10490: }
1.129 raeburn 10491: if ($changes{'coowners'}) {
10492: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10493: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10494: if (ref($lastactref) eq 'HASH') {
10495: $lastactref->{'domainconfig'} = 1;
10496: }
1.129 raeburn 10497: }
1.274 raeburn 10498: if ($changes{'autofailsafe'}) {
10499: if ($failsafe ne '') {
1.299 raeburn 10500: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 10501: } else {
1.299 raeburn 10502: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 10503: }
10504: &Apache::lonnet::get_domain_defaults($dom,1);
10505: if (ref($lastactref) eq 'HASH') {
10506: $lastactref->{'domdefaults'} = 1;
10507: }
10508: }
1.1 raeburn 10509: $resulttext .= '</ul>';
10510: } else {
10511: $resulttext = &mt('No changes made to auto-enrollment settings');
10512: }
10513: } else {
1.11 albertel 10514: $resulttext = '<span class="LC_error">'.
10515: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10516: }
1.3 raeburn 10517: return $resulttext;
1.1 raeburn 10518: }
10519:
10520: sub modify_autoupdate {
1.3 raeburn 10521: my ($dom,%domconfig) = @_;
1.1 raeburn 10522: my ($resulttext,%currautoupdate,%fields,%changes);
10523: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10524: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10525: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10526: }
10527: }
10528: my @offon = ('off','on');
10529: my %title = &Apache::lonlocal::texthash (
10530: run => 'Auto-update:',
10531: classlists => 'Updates to user information in classlists?'
10532: );
1.44 raeburn 10533: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10534: my %fieldtitles = &Apache::lonlocal::texthash (
10535: id => 'Student/Employee ID',
1.20 raeburn 10536: permanentemail => 'E-mail address',
1.1 raeburn 10537: lastname => 'Last Name',
10538: firstname => 'First Name',
10539: middlename => 'Middle Name',
1.132 raeburn 10540: generation => 'Generation',
1.1 raeburn 10541: );
1.142 raeburn 10542: $othertitle = &mt('All users');
1.1 raeburn 10543: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10544: $othertitle = &mt('Other users');
1.1 raeburn 10545: }
10546: foreach my $key (keys(%env)) {
10547: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10548: my ($usertype,$item) = ($1,$2);
10549: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10550: if ($usertype eq 'default') {
10551: push(@{$fields{$1}},$2);
10552: } elsif (ref($types) eq 'ARRAY') {
10553: if (grep(/^\Q$usertype\E$/,@{$types})) {
10554: push(@{$fields{$1}},$2);
10555: }
10556: }
10557: }
1.1 raeburn 10558: }
10559: }
1.131 raeburn 10560: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10561: @lockablenames = sort(@lockablenames);
10562: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10563: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10564: if (@changed) {
10565: $changes{'lockablenames'} = 1;
10566: }
10567: } else {
10568: if (@lockablenames) {
10569: $changes{'lockablenames'} = 1;
10570: }
10571: }
1.1 raeburn 10572: my %updatehash = (
10573: autoupdate => { run => $env{'form.autoupdate_run'},
10574: classlists => $env{'form.classlists'},
10575: fields => {%fields},
1.131 raeburn 10576: lockablenames => \@lockablenames,
1.1 raeburn 10577: }
10578: );
10579: foreach my $key (keys(%currautoupdate)) {
10580: if (($key eq 'run') || ($key eq 'classlists')) {
10581: if (exists($updatehash{autoupdate}{$key})) {
10582: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10583: $changes{$key} = 1;
10584: }
10585: }
10586: } elsif ($key eq 'fields') {
10587: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10588: foreach my $item (@{$types},'default') {
1.1 raeburn 10589: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10590: my $change = 0;
10591: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10592: if (!exists($fields{$item})) {
10593: $change = 1;
1.132 raeburn 10594: last;
1.1 raeburn 10595: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10596: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10597: $change = 1;
1.132 raeburn 10598: last;
1.1 raeburn 10599: }
10600: }
10601: }
10602: if ($change) {
10603: push(@{$changes{$key}},$item);
10604: }
1.26 raeburn 10605: }
1.1 raeburn 10606: }
10607: }
1.131 raeburn 10608: } elsif ($key eq 'lockablenames') {
10609: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10610: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10611: if (@changed) {
10612: $changes{'lockablenames'} = 1;
10613: }
10614: } else {
10615: if (@lockablenames) {
10616: $changes{'lockablenames'} = 1;
10617: }
10618: }
10619: }
10620: }
10621: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10622: if (@lockablenames) {
10623: $changes{'lockablenames'} = 1;
1.1 raeburn 10624: }
10625: }
1.26 raeburn 10626: foreach my $item (@{$types},'default') {
10627: if (defined($fields{$item})) {
10628: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10629: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10630: my $change = 0;
10631: if (ref($fields{$item}) eq 'ARRAY') {
10632: foreach my $type (@{$fields{$item}}) {
10633: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10634: $change = 1;
10635: last;
10636: }
10637: }
10638: }
10639: if ($change) {
10640: push(@{$changes{'fields'}},$item);
10641: }
10642: } else {
1.26 raeburn 10643: push(@{$changes{'fields'}},$item);
10644: }
10645: } else {
10646: push(@{$changes{'fields'}},$item);
1.1 raeburn 10647: }
10648: }
10649: }
10650: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10651: $dom);
10652: if ($putresult eq 'ok') {
10653: if (keys(%changes) > 0) {
10654: $resulttext = &mt('Changes made:').'<ul>';
10655: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10656: if ($key eq 'lockablenames') {
10657: $resulttext .= '<li>';
10658: if (@lockablenames) {
10659: $usertypes->{'default'} = $othertitle;
10660: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10661: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10662: } else {
10663: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10664: }
10665: $resulttext .= '</li>';
10666: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10667: foreach my $item (@{$changes{$key}}) {
10668: my @newvalues;
10669: foreach my $type (@{$fields{$item}}) {
10670: push(@newvalues,$fieldtitles{$type});
10671: }
1.3 raeburn 10672: my $newvaluestr;
10673: if (@newvalues > 0) {
10674: $newvaluestr = join(', ',@newvalues);
10675: } else {
10676: $newvaluestr = &mt('none');
1.6 raeburn 10677: }
1.1 raeburn 10678: if ($item eq 'default') {
1.26 raeburn 10679: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10680: } else {
1.26 raeburn 10681: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10682: }
10683: }
10684: } else {
10685: my $newvalue;
10686: if ($key eq 'run') {
10687: $newvalue = $offon[$env{'form.autoupdate_run'}];
10688: } else {
10689: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10690: }
1.1 raeburn 10691: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10692: }
10693: }
10694: $resulttext .= '</ul>';
10695: } else {
1.3 raeburn 10696: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10697: }
10698: } else {
1.11 albertel 10699: $resulttext = '<span class="LC_error">'.
10700: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10701: }
1.3 raeburn 10702: return $resulttext;
1.1 raeburn 10703: }
10704:
1.125 raeburn 10705: sub modify_autocreate {
10706: my ($dom,%domconfig) = @_;
10707: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10708: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10709: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10710: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10711: }
10712: }
10713: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10714: req => 'Auto-creation of validated requests for official courses',
10715: xmldc => 'Identity of course creator of courses from XML files',
10716: );
10717: my @types = ('xml','req');
10718: foreach my $item (@types) {
10719: $newvals{$item} = $env{'form.autocreate_'.$item};
10720: $newvals{$item} =~ s/\D//g;
10721: $newvals{$item} = 0 if ($newvals{$item} eq '');
10722: }
10723: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 10724: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10725: unless (exists($domcoords{$newvals{'xmldc'}})) {
10726: $newvals{'xmldc'} = '';
10727: }
10728: %autocreatehash = (
10729: autocreate => { xml => $newvals{'xml'},
10730: req => $newvals{'req'},
10731: }
10732: );
10733: if ($newvals{'xmldc'} ne '') {
10734: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10735: }
10736: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10737: $dom);
10738: if ($putresult eq 'ok') {
10739: my @items = @types;
10740: if ($newvals{'xml'}) {
10741: push(@items,'xmldc');
10742: }
10743: foreach my $item (@items) {
10744: if (exists($currautocreate{$item})) {
10745: if ($currautocreate{$item} ne $newvals{$item}) {
10746: $changes{$item} = 1;
10747: }
10748: } elsif ($newvals{$item}) {
10749: $changes{$item} = 1;
10750: }
10751: }
10752: if (keys(%changes) > 0) {
10753: my @offon = ('off','on');
10754: $resulttext = &mt('Changes made:').'<ul>';
10755: foreach my $item (@types) {
10756: if ($changes{$item}) {
10757: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 10758: $resulttext .= '<li>'.
10759: &mt("$title{$item} set to [_1]$newtxt [_2]",
10760: '<b>','</b>').
10761: '</li>';
1.125 raeburn 10762: }
10763: }
10764: if ($changes{'xmldc'}) {
10765: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10766: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 10767: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10768: }
10769: $resulttext .= '</ul>';
10770: } else {
10771: $resulttext = &mt('No changes made to auto-creation settings');
10772: }
10773: } else {
10774: $resulttext = '<span class="LC_error">'.
10775: &mt('An error occurred: [_1]',$putresult).'</span>';
10776: }
10777: return $resulttext;
10778: }
10779:
1.23 raeburn 10780: sub modify_directorysrch {
1.295 raeburn 10781: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10782: my ($resulttext,%changes);
10783: my %currdirsrch;
10784: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10785: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10786: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10787: }
10788: }
1.277 raeburn 10789: my %title = ( available => 'Institutional directory search available',
10790: localonly => 'Other domains can search institution',
10791: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 10792: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10793: searchby => 'Search types',
10794: searchtypes => 'Search latitude');
10795: my @offon = ('off','on');
1.24 raeburn 10796: my @otherdoms = ('Yes','No');
1.23 raeburn 10797:
1.25 raeburn 10798: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10799: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10800: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10801:
1.44 raeburn 10802: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10803: if (keys(%{$usertypes}) == 0) {
10804: @cansearch = ('default');
10805: } else {
10806: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10807: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10808: if (!grep(/^\Q$type\E$/,@cansearch)) {
10809: push(@{$changes{'cansearch'}},$type);
10810: }
1.23 raeburn 10811: }
1.26 raeburn 10812: foreach my $type (@cansearch) {
10813: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10814: push(@{$changes{'cansearch'}},$type);
10815: }
1.23 raeburn 10816: }
1.26 raeburn 10817: } else {
10818: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10819: }
10820: }
10821:
10822: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10823: foreach my $by (@{$currdirsrch{'searchby'}}) {
10824: if (!grep(/^\Q$by\E$/,@searchby)) {
10825: push(@{$changes{'searchby'}},$by);
10826: }
10827: }
10828: foreach my $by (@searchby) {
10829: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10830: push(@{$changes{'searchby'}},$by);
10831: }
10832: }
10833: } else {
10834: push(@{$changes{'searchby'}},@searchby);
10835: }
1.25 raeburn 10836:
10837: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10838: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10839: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10840: push(@{$changes{'searchtypes'}},$type);
10841: }
10842: }
10843: foreach my $type (@searchtypes) {
10844: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10845: push(@{$changes{'searchtypes'}},$type);
10846: }
10847: }
10848: } else {
10849: if (exists($currdirsrch{'searchtypes'})) {
10850: foreach my $type (@searchtypes) {
10851: if ($type ne $currdirsrch{'searchtypes'}) {
10852: push(@{$changes{'searchtypes'}},$type);
10853: }
10854: }
10855: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10856: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10857: }
10858: } else {
10859: push(@{$changes{'searchtypes'}},@searchtypes);
10860: }
10861: }
10862:
1.23 raeburn 10863: my %dirsrch_hash = (
10864: directorysrch => { available => $env{'form.dirsrch_available'},
10865: cansearch => \@cansearch,
1.277 raeburn 10866: localonly => $env{'form.dirsrch_instlocalonly'},
10867: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10868: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10869: searchby => \@searchby,
1.25 raeburn 10870: searchtypes => \@searchtypes,
1.23 raeburn 10871: }
10872: );
10873: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10874: $dom);
10875: if ($putresult eq 'ok') {
10876: if (exists($currdirsrch{'available'})) {
10877: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10878: $changes{'available'} = 1;
10879: }
10880: } else {
10881: if ($env{'form.dirsrch_available'} eq '1') {
10882: $changes{'available'} = 1;
10883: }
10884: }
1.277 raeburn 10885: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 10886: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10887: $changes{'lcavailable'} = 1;
10888: }
1.277 raeburn 10889: } else {
10890: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10891: $changes{'lcavailable'} = 1;
10892: }
10893: }
1.24 raeburn 10894: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 10895: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
10896: $changes{'localonly'} = 1;
10897: }
1.24 raeburn 10898: } else {
1.277 raeburn 10899: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 10900: $changes{'localonly'} = 1;
10901: }
10902: }
1.277 raeburn 10903: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 10904: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10905: $changes{'lclocalonly'} = 1;
10906: }
1.277 raeburn 10907: } else {
10908: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10909: $changes{'lclocalonly'} = 1;
10910: }
10911: }
1.23 raeburn 10912: if (keys(%changes) > 0) {
10913: $resulttext = &mt('Changes made:').'<ul>';
10914: if ($changes{'available'}) {
10915: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10916: }
1.277 raeburn 10917: if ($changes{'lcavailable'}) {
10918: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10919: }
1.24 raeburn 10920: if ($changes{'localonly'}) {
1.277 raeburn 10921: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 10922: }
1.277 raeburn 10923: if ($changes{'lclocalonly'}) {
10924: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 10925: }
1.23 raeburn 10926: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10927: my $chgtext;
1.26 raeburn 10928: if (ref($usertypes) eq 'HASH') {
10929: if (keys(%{$usertypes}) > 0) {
10930: foreach my $type (@{$types}) {
10931: if (grep(/^\Q$type\E$/,@cansearch)) {
10932: $chgtext .= $usertypes->{$type}.'; ';
10933: }
10934: }
10935: if (grep(/^default$/,@cansearch)) {
10936: $chgtext .= $othertitle;
10937: } else {
10938: $chgtext =~ s/\; $//;
10939: }
1.210 raeburn 10940: $resulttext .=
1.178 raeburn 10941: '<li>'.
10942: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10943: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10944: '</li>';
1.23 raeburn 10945: }
10946: }
10947: }
10948: if (ref($changes{'searchby'}) eq 'ARRAY') {
10949: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10950: my $chgtext;
10951: foreach my $type (@{$titleorder}) {
10952: if (grep(/^\Q$type\E$/,@searchby)) {
10953: if (defined($searchtitles->{$type})) {
10954: $chgtext .= $searchtitles->{$type}.'; ';
10955: }
10956: }
10957: }
10958: $chgtext =~ s/\; $//;
10959: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10960: }
1.25 raeburn 10961: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10962: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10963: my $chgtext;
10964: foreach my $type (@{$srchtypeorder}) {
10965: if (grep(/^\Q$type\E$/,@searchtypes)) {
10966: if (defined($srchtypes_desc->{$type})) {
10967: $chgtext .= $srchtypes_desc->{$type}.'; ';
10968: }
10969: }
10970: }
10971: $chgtext =~ s/\; $//;
1.178 raeburn 10972: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10973: }
10974: $resulttext .= '</ul>';
1.295 raeburn 10975: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10976: if (ref($lastactref) eq 'HASH') {
10977: $lastactref->{'directorysrch'} = 1;
10978: }
1.23 raeburn 10979: } else {
1.277 raeburn 10980: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10981: }
10982: } else {
10983: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10984: &mt('An error occurred: [_1]',$putresult).'</span>';
10985: }
10986: return $resulttext;
10987: }
10988:
1.28 raeburn 10989: sub modify_contacts {
1.205 raeburn 10990: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10991: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10992: if (ref($domconfig{'contacts'}) eq 'HASH') {
10993: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10994: $currsetting{$key} = $domconfig{'contacts'}{$key};
10995: }
10996: }
1.286 raeburn 10997: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10998: my @contacts = ('supportemail','adminemail');
1.286 raeburn 10999: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
11000: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 11001: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 11002: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 11003: foreach my $type (@mailings) {
11004: @{$newsetting{$type}} =
11005: &Apache::loncommon::get_env_multiple('form.'.$type);
11006: foreach my $item (@contacts) {
11007: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
11008: $contacts_hash{contacts}{$type}{$item} = 1;
11009: } else {
11010: $contacts_hash{contacts}{$type}{$item} = 0;
11011: }
1.289 raeburn 11012: }
1.28 raeburn 11013: $others{$type} = $env{'form.'.$type.'_others'};
11014: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 11015: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11016: $bcc{$type} = $env{'form.'.$type.'_bcc'};
11017: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 11018: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
11019: $includestr{$type} = $env{'form.'.$type.'_includestr'};
11020: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
11021: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11022: }
1.134 raeburn 11023: }
1.28 raeburn 11024: }
11025: foreach my $item (@contacts) {
11026: $to{$item} = $env{'form.'.$item};
11027: $contacts_hash{'contacts'}{$item} = $to{$item};
11028: }
1.203 raeburn 11029: foreach my $item (@toggles) {
11030: if ($env{'form.'.$item} =~ /^(0|1)$/) {
11031: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
11032: }
11033: }
1.286 raeburn 11034: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
11035: foreach my $field (@{$fields}) {
11036: if (ref($possoptions->{$field}) eq 'ARRAY') {
11037: my $value = $env{'form.helpform_'.$field};
11038: $value =~ s/^\s+|\s+$//g;
11039: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
11040: $contacts_hash{contacts}{'helpform'}{$field} = $value;
11041: if ($field eq 'screenshot') {
11042: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
11043: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
11044: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
11045: }
11046: }
11047: }
11048: }
11049: }
11050: }
1.28 raeburn 11051: if (keys(%currsetting) > 0) {
11052: foreach my $item (@contacts) {
11053: if ($to{$item} ne $currsetting{$item}) {
11054: $changes{$item} = 1;
11055: }
11056: }
11057: foreach my $type (@mailings) {
11058: foreach my $item (@contacts) {
11059: if (ref($currsetting{$type}) eq 'HASH') {
11060: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
11061: push(@{$changes{$type}},$item);
11062: }
11063: } else {
11064: push(@{$changes{$type}},@{$newsetting{$type}});
11065: }
11066: }
11067: if ($others{$type} ne $currsetting{$type}{'others'}) {
11068: push(@{$changes{$type}},'others');
11069: }
1.289 raeburn 11070: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11071: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
11072: push(@{$changes{$type}},'bcc');
11073: }
1.286 raeburn 11074: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
11075: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
11076: push(@{$changes{$type}},'include');
11077: }
11078: }
11079: }
11080: if (ref($fields) eq 'ARRAY') {
11081: if (ref($currsetting{'helpform'}) eq 'HASH') {
11082: foreach my $field (@{$fields}) {
11083: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
11084: push(@{$changes{'helpform'}},$field);
11085: }
11086: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11087: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
11088: push(@{$changes{'helpform'}},'maxsize');
11089: }
11090: }
11091: }
11092: } else {
11093: foreach my $field (@{$fields}) {
11094: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11095: push(@{$changes{'helpform'}},$field);
11096: }
11097: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11098: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11099: push(@{$changes{'helpform'}},'maxsize');
11100: }
11101: }
11102: }
1.134 raeburn 11103: }
1.28 raeburn 11104: }
11105: } else {
11106: my %default;
11107: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
11108: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
11109: $default{'errormail'} = 'adminemail';
11110: $default{'packagesmail'} = 'adminemail';
11111: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 11112: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 11113: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 11114: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 11115: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 11116: foreach my $item (@contacts) {
11117: if ($to{$item} ne $default{$item}) {
1.286 raeburn 11118: $changes{$item} = 1;
1.203 raeburn 11119: }
1.28 raeburn 11120: }
11121: foreach my $type (@mailings) {
11122: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
11123: push(@{$changes{$type}},@{$newsetting{$type}});
11124: }
11125: if ($others{$type} ne '') {
11126: push(@{$changes{$type}},'others');
1.134 raeburn 11127: }
1.286 raeburn 11128: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11129: if ($bcc{$type} ne '') {
11130: push(@{$changes{$type}},'bcc');
11131: }
1.286 raeburn 11132: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
11133: push(@{$changes{$type}},'include');
11134: }
1.134 raeburn 11135: }
1.28 raeburn 11136: }
1.286 raeburn 11137: if (ref($fields) eq 'ARRAY') {
11138: foreach my $field (@{$fields}) {
11139: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11140: push(@{$changes{'helpform'}},$field);
11141: }
11142: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11143: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11144: push(@{$changes{'helpform'}},'maxsize');
11145: }
11146: }
11147: }
1.289 raeburn 11148: }
1.28 raeburn 11149: }
1.203 raeburn 11150: foreach my $item (@toggles) {
11151: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
11152: $changes{$item} = 1;
11153: } elsif ((!$env{'form.'.$item}) &&
11154: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
11155: $changes{$item} = 1;
11156: }
11157: }
1.28 raeburn 11158: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
11159: $dom);
11160: if ($putresult eq 'ok') {
11161: if (keys(%changes) > 0) {
1.205 raeburn 11162: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11163: if (ref($lastactref) eq 'HASH') {
11164: $lastactref->{'domainconfig'} = 1;
11165: }
1.28 raeburn 11166: my ($titles,$short_titles) = &contact_titles();
11167: $resulttext = &mt('Changes made:').'<ul>';
11168: foreach my $item (@contacts) {
11169: if ($changes{$item}) {
11170: $resulttext .= '<li>'.$titles->{$item}.
11171: &mt(' set to: ').
11172: '<span class="LC_cusr_emph">'.
11173: $to{$item}.'</span></li>';
11174: }
11175: }
11176: foreach my $type (@mailings) {
11177: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 11178: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 11179: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 11180: } else {
11181: $resulttext .= '<li>'.$titles->{$type}.': ';
11182: }
1.28 raeburn 11183: my @text;
11184: foreach my $item (@{$newsetting{$type}}) {
11185: push(@text,$short_titles->{$item});
11186: }
11187: if ($others{$type} ne '') {
11188: push(@text,$others{$type});
11189: }
1.286 raeburn 11190: if (@text) {
11191: $resulttext .= '<span class="LC_cusr_emph">'.
11192: join(', ',@text).'</span>';
11193: }
11194: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11195: if ($bcc{$type} ne '') {
1.286 raeburn 11196: my $bcctext;
11197: if (@text) {
1.289 raeburn 11198: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 11199: } else {
11200: $bcctext = '(Bcc)';
11201: }
11202: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
11203: } elsif (!@text) {
11204: $resulttext .= &mt('No one');
11205: }
1.289 raeburn 11206: if ($includestr{$type} ne '') {
1.286 raeburn 11207: if ($includeloc{$type} eq 'b') {
11208: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
11209: } elsif ($includeloc{$type} eq 's') {
11210: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
11211: }
1.134 raeburn 11212: }
1.286 raeburn 11213: } elsif (!@text) {
11214: $resulttext .= &mt('No recipients');
1.134 raeburn 11215: }
11216: $resulttext .= '</li>';
1.28 raeburn 11217: }
11218: }
1.203 raeburn 11219: my @offon = ('off','on');
11220: if ($changes{'reporterrors'}) {
11221: $resulttext .= '<li>'.
11222: &mt('E-mail error reports to [_1] set to "'.
11223: $offon[$env{'form.reporterrors'}].'".',
11224: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11225: &mt('LON-CAPA core group - MSU'),600,500)).
11226: '</li>';
11227: }
11228: if ($changes{'reportupdates'}) {
11229: $resulttext .= '<li>'.
11230: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
11231: $offon[$env{'form.reportupdates'}].'".',
11232: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11233: &mt('LON-CAPA core group - MSU'),600,500)).
11234: '</li>';
11235: }
1.286 raeburn 11236: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
11237: my (@optional,@required,@unused,$maxsizechg);
11238: foreach my $field (@{$changes{'helpform'}}) {
11239: if ($field eq 'maxsize') {
11240: $maxsizechg = 1;
11241: next;
11242: }
11243: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 11244: push(@optional,$field);
1.286 raeburn 11245: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
11246: push(@unused,$field);
11247: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 11248: push(@required,$field);
1.286 raeburn 11249: }
11250: }
11251: if (@optional) {
11252: $resulttext .= '<li>'.
11253: &mt('Help form fields changed to "Optional": [_1].',
11254: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
11255: '</li>';
11256: }
11257: if (@required) {
11258: $resulttext .= '<li>'.
11259: &mt('Help form fields changed to "Required": [_1].',
11260: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
11261: '</li>';
11262: }
11263: if (@unused) {
11264: $resulttext .= '<li>'.
11265: &mt('Help form fields changed to "Not shown": [_1].',
11266: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
11267: '</li>';
11268: }
11269: if ($maxsizechg) {
11270: $resulttext .= '<li>'.
11271: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
11272: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
11273: '</li>';
11274:
11275: }
11276: }
1.28 raeburn 11277: $resulttext .= '</ul>';
11278: } else {
1.288 raeburn 11279: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 11280: }
11281: } else {
11282: $resulttext = '<span class="LC_error">'.
11283: &mt('An error occurred: [_1].',$putresult).'</span>';
11284: }
11285: return $resulttext;
11286: }
11287:
11288: sub modify_usercreation {
1.27 raeburn 11289: my ($dom,%domconfig) = @_;
1.224 raeburn 11290: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 11291: my $warningmsg;
1.27 raeburn 11292: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11293: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 11294: if ($key eq 'cancreate') {
11295: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11296: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 11297: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
11298: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11299: } else {
1.224 raeburn 11300: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11301: }
11302: }
11303: }
11304: } elsif ($key eq 'email_rule') {
11305: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11306: } else {
11307: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11308: }
1.27 raeburn 11309: }
11310: }
11311: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 11312: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 11313: my @contexts = ('author','course','requestcrs');
1.34 raeburn 11314: foreach my $item(@contexts) {
1.224 raeburn 11315: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 11316: }
1.34 raeburn 11317: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11318: foreach my $item (@contexts) {
1.224 raeburn 11319: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
11320: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 11321: }
1.27 raeburn 11322: }
1.34 raeburn 11323: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
11324: foreach my $item (@contexts) {
1.43 raeburn 11325: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 11326: if ($cancreate{$item} ne 'any') {
11327: push(@{$changes{'cancreate'}},$item);
11328: }
11329: } else {
11330: if ($cancreate{$item} ne 'none') {
11331: push(@{$changes{'cancreate'}},$item);
11332: }
1.27 raeburn 11333: }
11334: }
11335: } else {
1.43 raeburn 11336: foreach my $item (@contexts) {
1.34 raeburn 11337: push(@{$changes{'cancreate'}},$item);
11338: }
1.27 raeburn 11339: }
1.34 raeburn 11340:
1.27 raeburn 11341: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
11342: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
11343: if (!grep(/^\Q$type\E$/,@username_rule)) {
11344: push(@{$changes{'username_rule'}},$type);
11345: }
11346: }
11347: foreach my $type (@username_rule) {
11348: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
11349: push(@{$changes{'username_rule'}},$type);
11350: }
11351: }
11352: } else {
11353: push(@{$changes{'username_rule'}},@username_rule);
11354: }
11355:
1.32 raeburn 11356: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11357: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11358: if (!grep(/^\Q$type\E$/,@id_rule)) {
11359: push(@{$changes{'id_rule'}},$type);
11360: }
11361: }
11362: foreach my $type (@id_rule) {
11363: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11364: push(@{$changes{'id_rule'}},$type);
11365: }
11366: }
11367: } else {
11368: push(@{$changes{'id_rule'}},@id_rule);
11369: }
11370:
1.43 raeburn 11371: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11372: my @authtypes = ('int','krb4','krb5','loc');
11373: my %authhash;
1.43 raeburn 11374: foreach my $item (@authen_contexts) {
1.28 raeburn 11375: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11376: foreach my $auth (@authtypes) {
11377: if (grep(/^\Q$auth\E$/,@authallowed)) {
11378: $authhash{$item}{$auth} = 1;
11379: } else {
11380: $authhash{$item}{$auth} = 0;
11381: }
11382: }
11383: }
11384: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11385: foreach my $item (@authen_contexts) {
1.28 raeburn 11386: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11387: foreach my $auth (@authtypes) {
11388: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11389: push(@{$changes{'authtypes'}},$item);
11390: last;
11391: }
11392: }
11393: }
11394: }
11395: } else {
1.43 raeburn 11396: foreach my $item (@authen_contexts) {
1.28 raeburn 11397: push(@{$changes{'authtypes'}},$item);
11398: }
11399: }
11400:
1.224 raeburn 11401: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11402: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11403: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11404: $save_usercreate{'id_rule'} = \@id_rule;
11405: $save_usercreate{'username_rule'} = \@username_rule,
11406: $save_usercreate{'authtypes'} = \%authhash;
11407:
1.27 raeburn 11408: my %usercreation_hash = (
1.224 raeburn 11409: usercreation => \%save_usercreate,
11410: );
1.27 raeburn 11411:
11412: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11413: $dom);
1.50 raeburn 11414:
1.224 raeburn 11415: if ($putresult eq 'ok') {
11416: if (keys(%changes) > 0) {
11417: $resulttext = &mt('Changes made:').'<ul>';
11418: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11419: my %lt = &usercreation_types();
11420: foreach my $type (@{$changes{'cancreate'}}) {
11421: my $chgtext = $lt{$type}.', ';
11422: if ($cancreate{$type} eq 'none') {
11423: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11424: } elsif ($cancreate{$type} eq 'any') {
11425: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11426: } elsif ($cancreate{$type} eq 'official') {
11427: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11428: } elsif ($cancreate{$type} eq 'unofficial') {
11429: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11430: }
11431: $resulttext .= '<li>'.$chgtext.'</li>';
11432: }
11433: }
11434: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11435: my ($rules,$ruleorder) =
11436: &Apache::lonnet::inst_userrules($dom,'username');
11437: my $chgtext = '<ul>';
11438: foreach my $type (@username_rule) {
11439: if (ref($rules->{$type}) eq 'HASH') {
11440: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11441: }
11442: }
11443: $chgtext .= '</ul>';
11444: if (@username_rule > 0) {
11445: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11446: } else {
11447: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11448: }
11449: }
11450: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11451: my ($idrules,$idruleorder) =
11452: &Apache::lonnet::inst_userrules($dom,'id');
11453: my $chgtext = '<ul>';
11454: foreach my $type (@id_rule) {
11455: if (ref($idrules->{$type}) eq 'HASH') {
11456: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11457: }
11458: }
11459: $chgtext .= '</ul>';
11460: if (@id_rule > 0) {
11461: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11462: } else {
11463: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11464: }
11465: }
11466: my %authname = &authtype_names();
11467: my %context_title = &context_names();
11468: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11469: my $chgtext = '<ul>';
11470: foreach my $type (@{$changes{'authtypes'}}) {
11471: my @allowed;
11472: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11473: foreach my $auth (@authtypes) {
11474: if ($authhash{$type}{$auth}) {
11475: push(@allowed,$authname{$auth});
11476: }
11477: }
11478: if (@allowed > 0) {
11479: $chgtext .= join(', ',@allowed).'</li>';
11480: } else {
11481: $chgtext .= &mt('none').'</li>';
11482: }
11483: }
11484: $chgtext .= '</ul>';
11485: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11486: $resulttext .= '</li>';
11487: }
11488: $resulttext .= '</ul>';
11489: } else {
11490: $resulttext = &mt('No changes made to user creation settings');
11491: }
11492: } else {
11493: $resulttext = '<span class="LC_error">'.
11494: &mt('An error occurred: [_1]',$putresult).'</span>';
11495: }
11496: if ($warningmsg ne '') {
11497: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11498: }
11499: return $resulttext;
11500: }
11501:
11502: sub modify_selfcreation {
1.305 raeburn 11503: my ($dom,$lastactref,%domconfig) = @_;
11504: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
11505: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
11506: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 11507: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
11508: if (ref($typesref) eq 'ARRAY') {
11509: @types = @{$typesref};
11510: }
11511: if (ref($usertypesref) eq 'HASH') {
11512: %usertypes = %{$usertypesref};
1.228 raeburn 11513: }
1.303 raeburn 11514: $usertypes{'default'} = $othertitle;
1.224 raeburn 11515: #
11516: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11517: #
11518: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11519: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11520: if ($key eq 'cancreate') {
11521: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11522: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11523: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 11524: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
11525: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
11526: ($item eq 'emailusername') || ($item eq 'shibenv') ||
11527: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 11528: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 11529: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11530: } else {
11531: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11532: }
11533: }
11534: }
11535: } elsif ($key eq 'email_rule') {
11536: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11537: } else {
11538: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11539: }
11540: }
11541: }
11542: #
11543: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11544: #
11545: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11546: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11547: if ($key eq 'selfcreate') {
11548: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11549: } else {
11550: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11551: }
11552: }
11553: }
1.305 raeburn 11554: #
11555: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
11556: #
11557: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11558: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
11559: if ($key eq 'inststatusguest') {
11560: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
11561: } else {
11562: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
11563: }
11564: }
11565: }
1.224 raeburn 11566:
11567: my @contexts = ('selfcreate');
11568: @{$cancreate{'selfcreate'}} = ();
11569: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 11570: if (@types) {
11571: @{$cancreate{'statustocreate'}} = ();
11572: }
1.236 raeburn 11573: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 11574: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 11575: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 11576: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 11577: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 11578: my %selfcreatetypes = (
11579: sso => 'users authenticated by institutional single sign on',
11580: login => 'users authenticated by institutional log-in',
1.303 raeburn 11581: email => 'users verified by e-mail',
1.50 raeburn 11582: );
1.224 raeburn 11583: #
11584: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11585: # is permitted.
11586: #
1.305 raeburn 11587: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 11588:
1.305 raeburn 11589: my (@statuses,%email_rule);
1.228 raeburn 11590: foreach my $item ('login','sso','email') {
1.224 raeburn 11591: if ($item eq 'email') {
1.236 raeburn 11592: if ($env{'form.cancreate_email'}) {
1.305 raeburn 11593: if (@types) {
11594: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
11595: foreach my $status (@poss_statuses) {
11596: if (grep(/^\Q$status\E$/,(@types,'default'))) {
11597: push(@statuses,$status);
11598: }
11599: }
11600: $save_inststatus{'inststatusguest'} = \@statuses;
11601: } else {
11602: push(@statuses,'default');
11603: }
11604: if (@statuses) {
11605: my %curr_rule;
11606: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11607: foreach my $type (@statuses) {
11608: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 11609: }
1.305 raeburn 11610: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
11611: foreach my $type (@statuses) {
11612: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
11613: }
11614: }
11615: push(@{$cancreate{'selfcreate'}},'email');
11616: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
11617: my %curremaildom;
11618: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
11619: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
11620: }
11621: foreach my $type (@statuses) {
11622: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
11623: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11624: }
11625: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
11626: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
11627: }
11628: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
11629: #
11630: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
11631: #
11632: my $chosen = $1;
11633: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
11634: my $emaildom;
11635: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
11636: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
11637: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
11638: if (ref($curremaildom{$type}) eq 'HASH') {
11639: if (exists($curremaildom{$type}{$chosen})) {
11640: if ($curremaildom{$type}{$chosen} ne $emaildom) {
11641: push(@{$changes{'cancreate'}},'emaildomain');
11642: }
11643: } elsif ($emaildom ne '') {
11644: push(@{$changes{'cancreate'}},'emaildomain');
11645: }
11646: } elsif ($emaildom ne '') {
11647: push(@{$changes{'cancreate'}},'emaildomain');
11648: }
11649: }
11650: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
11651: } elsif ($chosen eq 'custom') {
11652: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
11653: $email_rule{$type} = [];
11654: if (ref($emailrules) eq 'HASH') {
11655: foreach my $rule (@possemail_rules) {
11656: if (exists($emailrules->{$rule})) {
11657: push(@{$email_rule{$type}},$rule);
11658: }
11659: }
11660: }
11661: if (@{$email_rule{$type}}) {
11662: $cancreate{'emailoptions'}{$type} = 'custom';
11663: if (ref($curr_rule{$type}) eq 'ARRAY') {
11664: if (@{$curr_rule{$type}} > 0) {
11665: foreach my $rule (@{$curr_rule{$type}}) {
11666: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
11667: push(@{$changes{'email_rule'}},$type);
11668: }
11669: }
11670: }
11671: foreach my $type (@{$email_rule{$type}}) {
11672: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
11673: push(@{$changes{'email_rule'}},$type);
11674: }
11675: }
11676: } else {
11677: push(@{$changes{'email_rule'}},$type);
11678: }
11679: }
11680: } else {
11681: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
11682: }
11683: }
11684: }
11685: if (@types) {
11686: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11687: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
11688: if (@changed) {
11689: push(@{$changes{'inststatus'}},'inststatusguest');
11690: }
11691: } else {
11692: push(@{$changes{'inststatus'}},'inststatusguest');
11693: }
11694: }
11695: } else {
11696: delete($env{'form.cancreate_email'});
11697: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11698: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
11699: push(@{$changes{'inststatus'}},'inststatusguest');
11700: }
11701: }
11702: }
11703: } else {
11704: $save_inststatus{'inststatusguest'} = [];
11705: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11706: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
11707: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 11708: }
11709: }
1.224 raeburn 11710: }
11711: } else {
11712: if ($env{'form.cancreate_'.$item}) {
11713: push(@{$cancreate{'selfcreate'}},$item);
11714: }
11715: }
11716: }
1.305 raeburn 11717: my (%userinfo,%savecaptcha);
1.224 raeburn 11718: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11719: #
1.228 raeburn 11720: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11721: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 11722: #
1.236 raeburn 11723:
1.244 raeburn 11724: if ($env{'form.cancreate_email'}) {
1.228 raeburn 11725: push(@contexts,'emailusername');
1.305 raeburn 11726: if (@statuses) {
11727: foreach my $type (@statuses) {
1.228 raeburn 11728: if (ref($infofields) eq 'ARRAY') {
11729: foreach my $field (@{$infofields}) {
11730: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11731: $cancreate{'emailusername'}{$type}{$field} = $1;
11732: }
11733: }
1.224 raeburn 11734: }
11735: }
11736: }
11737: #
11738: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 11739: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 11740: #
11741:
11742: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11743: @approvalnotify = sort(@approvalnotify);
11744: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11745: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11746: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11747: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11748: push(@{$changes{'cancreate'}},'notify');
11749: }
11750: } else {
11751: if ($cancreate{'notify'}{'approval'}) {
11752: push(@{$changes{'cancreate'}},'notify');
11753: }
11754: }
11755: } elsif ($cancreate{'notify'}{'approval'}) {
11756: push(@{$changes{'cancreate'}},'notify');
11757: }
11758:
11759: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11760: }
11761: #
1.236 raeburn 11762: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 11763: # institutional log-in.
11764: #
11765: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11766: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11767: ($domdefaults{'auth_def'} eq 'localauth'))) {
11768: $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.').' '.
11769: &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.');
11770: }
11771: }
11772: my @fields = ('lastname','firstname','middlename','generation',
11773: 'permanentemail','id');
1.240 raeburn 11774: my @shibfields = (@fields,'inststatus');
1.224 raeburn 11775: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11776: #
11777: # Where usernames may created for institutional log-in and/or institutional single sign on:
11778: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11779: # may self-create accounts
11780: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11781: # which the user may supply, if institutional data is unavailable.
11782: #
11783: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 11784: if (@types) {
1.305 raeburn 11785: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11786: push(@contexts,'statustocreate');
1.303 raeburn 11787: foreach my $type (@types) {
1.224 raeburn 11788: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11789: foreach my $field (@fields) {
11790: if (grep(/^\Q$field\E$/,@modifiable)) {
11791: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11792: } else {
11793: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11794: }
11795: }
11796: }
11797: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 11798: foreach my $type (@types) {
1.224 raeburn 11799: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11800: foreach my $field (@fields) {
11801: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11802: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11803: push(@{$changes{'selfcreate'}},$type);
11804: last;
11805: }
11806: }
11807: }
11808: }
11809: } else {
1.303 raeburn 11810: foreach my $type (@types) {
1.224 raeburn 11811: push(@{$changes{'selfcreate'}},$type);
11812: }
11813: }
11814: }
1.240 raeburn 11815: foreach my $field (@shibfields) {
11816: if ($env{'form.shibenv_'.$field} ne '') {
11817: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11818: }
11819: }
11820: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11821: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11822: foreach my $field (@shibfields) {
11823: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11824: push(@{$changes{'cancreate'}},'shibenv');
11825: }
11826: }
11827: } else {
11828: foreach my $field (@shibfields) {
11829: if ($env{'form.shibenv_'.$field}) {
11830: push(@{$changes{'cancreate'}},'shibenv');
11831: last;
11832: }
11833: }
11834: }
11835: }
1.224 raeburn 11836: }
11837: foreach my $item (@contexts) {
11838: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11839: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11840: if (ref($cancreate{$item}) eq 'ARRAY') {
11841: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11842: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11843: push(@{$changes{'cancreate'}},$item);
11844: }
11845: }
11846: }
11847: }
11848: if (ref($cancreate{$item}) eq 'ARRAY') {
11849: foreach my $type (@{$cancreate{$item}}) {
11850: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11851: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11852: push(@{$changes{'cancreate'}},$item);
11853: }
11854: }
11855: }
11856: }
11857: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11858: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 11859: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
11860: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
11861: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
11862: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 11863: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11864: push(@{$changes{'cancreate'}},$item);
11865: }
11866: }
11867: }
1.305 raeburn 11868: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11869: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 11870: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11871: push(@{$changes{'cancreate'}},$item);
11872: }
1.224 raeburn 11873: }
11874: }
11875: }
1.305 raeburn 11876: foreach my $type (keys(%{$cancreate{$item}})) {
11877: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11878: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11879: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
11880: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 11881: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11882: push(@{$changes{'cancreate'}},$item);
11883: }
11884: }
11885: } else {
11886: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11887: push(@{$changes{'cancreate'}},$item);
11888: }
11889: }
11890: }
1.305 raeburn 11891: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11892: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 11893: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11894: push(@{$changes{'cancreate'}},$item);
11895: }
1.224 raeburn 11896: }
11897: }
11898: }
11899: }
11900: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11901: if (ref($cancreate{$item}) eq 'ARRAY') {
11902: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11903: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11904: push(@{$changes{'cancreate'}},$item);
11905: }
11906: }
1.305 raeburn 11907: }
11908: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11909: if (ref($cancreate{$item}) eq 'HASH') {
11910: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11911: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 11912: }
11913: }
11914: } elsif ($item eq 'emailusername') {
1.228 raeburn 11915: if (ref($cancreate{$item}) eq 'HASH') {
11916: foreach my $type (keys(%{$cancreate{$item}})) {
11917: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11918: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11919: if ($cancreate{$item}{$type}{$field}) {
11920: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11921: push(@{$changes{'cancreate'}},$item);
11922: }
11923: last;
11924: }
11925: }
11926: }
11927: }
1.224 raeburn 11928: }
11929: }
11930: }
11931: #
11932: # Populate %save_usercreate hash with updates to self-creation configuration.
11933: #
11934: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11935: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 11936: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 11937: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11938: if (ref($cancreate{'notify'}) eq 'HASH') {
11939: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11940: }
1.236 raeburn 11941: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11942: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11943: }
1.303 raeburn 11944: if (ref($cancreate{'emailverified'}) eq 'HASH') {
11945: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
11946: }
1.305 raeburn 11947: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
11948: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
11949: }
1.303 raeburn 11950: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
11951: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
11952: }
1.224 raeburn 11953: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11954: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11955: }
1.240 raeburn 11956: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11957: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11958: }
1.224 raeburn 11959: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 11960: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 11961:
11962: my %userconfig_hash = (
11963: usercreation => \%save_usercreate,
11964: usermodification => \%save_usermodify,
1.305 raeburn 11965: inststatus => \%save_inststatus,
1.224 raeburn 11966: );
1.305 raeburn 11967:
1.224 raeburn 11968: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11969: $dom);
11970: #
1.305 raeburn 11971: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 11972: #
1.27 raeburn 11973: if ($putresult eq 'ok') {
11974: if (keys(%changes) > 0) {
11975: $resulttext = &mt('Changes made:').'<ul>';
11976: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 11977: my %lt = &selfcreation_types();
1.34 raeburn 11978: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 11979: my $chgtext = '';
1.45 raeburn 11980: if ($type eq 'selfcreate') {
1.50 raeburn 11981: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 11982: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11983: } else {
1.224 raeburn 11984: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11985: '<ul>';
1.50 raeburn 11986: foreach my $case (@{$cancreate{$type}}) {
11987: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11988: }
11989: $chgtext .= '</ul>';
1.100 raeburn 11990: if (ref($cancreate{$type}) eq 'ARRAY') {
11991: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11992: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11993: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 11994: $chgtext .= '<span class="LC_warning">'.
11995: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
11996: '</span><br />';
11997: }
11998: }
11999: }
12000: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 12001: if (!@statuses) {
12002: $chgtext .= '<span class="LC_warning">'.
12003: &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.").
12004: '</span><br />';
1.303 raeburn 12005:
1.100 raeburn 12006: }
12007: }
12008: }
1.43 raeburn 12009: }
1.240 raeburn 12010: } elsif ($type eq 'shibenv') {
12011: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 12012: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 12013: } else {
12014: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
12015: '<ul>';
12016: foreach my $field (@shibfields) {
12017: next if ($cancreate{$type}{$field} eq '');
12018: if ($field eq 'inststatus') {
12019: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
12020: } else {
12021: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
12022: }
12023: }
12024: $chgtext .= '</ul>';
1.303 raeburn 12025: }
1.93 raeburn 12026: } elsif ($type eq 'statustocreate') {
1.96 raeburn 12027: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
12028: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
12029: if (@{$cancreate{'selfcreate'}} > 0) {
12030: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 12031: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 12032: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 12033: $chgtext .= '<br />'.
12034: '<span class="LC_warning">'.
12035: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
12036: '</span>';
12037: }
1.303 raeburn 12038: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 12039: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 12040: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
12041: } else {
12042: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
12043: }
12044: $chgtext .= '<ul>';
12045: foreach my $case (@{$cancreate{$type}}) {
12046: if ($case eq 'default') {
12047: $chgtext .= '<li>'.$othertitle.'</li>';
12048: } else {
1.303 raeburn 12049: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 12050: }
12051: }
1.100 raeburn 12052: $chgtext .= '</ul>';
12053: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 12054: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 12055: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
12056: '</span>';
1.100 raeburn 12057: }
12058: }
12059: } else {
12060: if (@{$cancreate{$type}} == 0) {
12061: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
12062: } else {
12063: $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 12064: }
12065: }
1.303 raeburn 12066: $chgtext .= '<br />';
1.93 raeburn 12067: }
1.236 raeburn 12068: } elsif ($type eq 'selfcreateprocessing') {
12069: my %choices = &Apache::lonlocal::texthash (
12070: automatic => 'Automatic approval',
12071: approval => 'Queued for approval',
12072: );
1.305 raeburn 12073: if (@types) {
12074: if (@statuses) {
1.303 raeburn 12075: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.305 raeburn 12076: '<ul>';
12077: foreach my $status (@statuses) {
12078: if ($status eq 'default') {
12079: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 12080: } else {
1.305 raeburn 12081: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 12082: }
12083: }
12084: $chgtext .= '</ul>';
12085: }
12086: } else {
12087: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
12088: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
12089: }
12090: } elsif ($type eq 'emailverified') {
12091: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 12092: all => 'Same as e-mail',
12093: first => 'Omit @domain',
12094: free => 'Free to choose',
1.303 raeburn 12095: );
1.305 raeburn 12096: if (@types) {
12097: if (@statuses) {
1.303 raeburn 12098: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
12099: '<ul>';
1.305 raeburn 12100: foreach my $status (@statuses) {
1.303 raeburn 12101: if ($type eq 'default') {
1.305 raeburn 12102: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 12103: } else {
1.305 raeburn 12104: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 12105: }
12106: }
12107: $chgtext .= '</ul>';
12108: }
12109: } else {
1.305 raeburn 12110: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 12111: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 12112: }
1.305 raeburn 12113: } elsif ($type eq 'emailoptions') {
12114: my %options = &Apache::lonlocal::texthash (
12115: any => 'Any e-mail',
12116: inst => 'Institutional only',
12117: noninst => 'Non-institutional only',
12118: custom => 'Custom restrictions',
12119: );
12120: if (@types) {
12121: if (@statuses) {
12122: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
12123: '<ul>';
12124: foreach my $status (@statuses) {
12125: if ($type eq 'default') {
12126: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
12127: } else {
12128: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 12129: }
12130: }
1.305 raeburn 12131: $chgtext .= '</ul>';
12132: }
12133: } else {
12134: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
12135: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
12136: } else {
12137: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
12138: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 12139: }
1.305 raeburn 12140: }
12141: } elsif ($type eq 'emaildomain') {
12142: my $output;
12143: if (@statuses) {
12144: foreach my $type (@statuses) {
12145: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
12146: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
12147: if ($type eq 'default') {
12148: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12149: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12150: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12151: } else {
12152: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
12153: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12154: }
1.303 raeburn 12155: } else {
1.305 raeburn 12156: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12157: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12158: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12159: } else {
12160: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
12161: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12162: }
1.303 raeburn 12163: }
1.305 raeburn 12164: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
12165: if ($type eq 'default') {
12166: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12167: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12168: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12169: } else {
12170: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
12171: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12172: }
1.303 raeburn 12173: } else {
1.305 raeburn 12174: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12175: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12176: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12177: } else {
12178: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
12179: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12180: }
1.303 raeburn 12181: }
12182: }
12183: }
12184: }
1.305 raeburn 12185: }
12186: if ($output ne '') {
12187: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
12188: '<ul>'.$output.'</ul>';
1.236 raeburn 12189: }
1.165 raeburn 12190: } elsif ($type eq 'captcha') {
1.224 raeburn 12191: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 12192: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
12193: } else {
12194: my %captchas = &captcha_phrases();
1.224 raeburn 12195: if ($captchas{$savecaptcha{$type}}) {
12196: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 12197: } else {
1.210 raeburn 12198: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 12199: }
12200: }
12201: } elsif ($type eq 'recaptchakeys') {
12202: my ($privkey,$pubkey);
1.224 raeburn 12203: if (ref($savecaptcha{$type}) eq 'HASH') {
12204: $pubkey = $savecaptcha{$type}{'public'};
12205: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 12206: }
12207: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
12208: if (!$pubkey) {
12209: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
12210: } else {
12211: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12212: }
12213: if (!$privkey) {
12214: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
12215: } else {
12216: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
12217: }
12218: $chgtext .= '</ul>';
1.269 raeburn 12219: } elsif ($type eq 'recaptchaversion') {
12220: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 12221: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 12222: }
1.224 raeburn 12223: } elsif ($type eq 'emailusername') {
12224: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 12225: if (@statuses) {
12226: foreach my $type (@statuses) {
1.228 raeburn 12227: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
12228: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 12229: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 12230: '<ul>';
12231: foreach my $field (@{$infofields}) {
12232: if ($cancreate{'emailusername'}{$type}{$field}) {
12233: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
12234: }
12235: }
1.245 raeburn 12236: $chgtext .= '</ul>';
12237: } else {
1.303 raeburn 12238: $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 12239: }
12240: } else {
1.303 raeburn 12241: $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 12242: }
12243: }
12244: }
12245: }
12246: } elsif ($type eq 'notify') {
1.303 raeburn 12247: my $numapprove = 0;
1.224 raeburn 12248: if (ref($changes{'cancreate'}) eq 'ARRAY') {
12249: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
12250: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 12251: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
12252: $numapprove ++;
1.224 raeburn 12253: }
12254: }
1.43 raeburn 12255: }
1.303 raeburn 12256: unless ($numapprove) {
12257: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
12258: }
1.34 raeburn 12259: }
1.224 raeburn 12260: if ($chgtext) {
12261: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 12262: }
12263: }
12264: }
1.305 raeburn 12265: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 12266: my ($emailrules,$emailruleorder) =
12267: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 12268: foreach my $type (@{$changes{'email_rule'}}) {
12269: if (ref($email_rule{$type}) eq 'ARRAY') {
12270: my $chgtext = '<ul>';
12271: foreach my $rule (@{$email_rule{$type}}) {
12272: if (ref($emailrules->{$rule}) eq 'HASH') {
12273: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
12274: }
12275: }
12276: $chgtext .= '</ul>';
12277: if (@types) {
12278: my $typename;
12279: if ($type eq 'default') {
12280: $typename = $othertitle;
12281: } else {
12282: $typename = $usertypes{$type};
12283: }
12284: $chgtext .= &mt('(Affiliation: [_1])',$typename);
12285: }
12286: if (@{$email_rule{$type}} > 0) {
12287: $resulttext .= '<li>'.
12288: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
12289: $usertypes{$type}).
12290: $chgtext.
12291: '</li>';
12292: } else {
12293: $resulttext .= '<li>'.
12294: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.',
12295: $usertypes{$type}).
12296: '</li>'.
12297: &mt('(Affiliation: [_1])',$type);
12298: }
1.43 raeburn 12299: }
12300: }
1.305 raeburn 12301: }
12302: if (ref($changes{'inststatus'}) eq 'ARRAY') {
12303: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
12304: if (@{$save_inststatus{'inststatusguest'}} > 0) {
12305: my $chgtext = '<ul>';
12306: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
12307: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
12308: }
12309: $chgtext .= '</ul>';
12310: $resulttext .= '<li>'.
12311: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
12312: $chgtext.
12313: '</li>';
12314: } else {
12315: $resulttext .= '<li>'.
12316: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
12317: '</li>';
12318: }
1.43 raeburn 12319: }
12320: }
1.224 raeburn 12321: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
12322: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
12323: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12324: foreach my $type (@{$changes{'selfcreate'}}) {
12325: my $typename = $type;
1.303 raeburn 12326: if (keys(%usertypes) > 0) {
12327: if ($usertypes{$type} ne '') {
12328: $typename = $usertypes{$type};
1.224 raeburn 12329: }
12330: }
12331: my @modifiable;
12332: $resulttext .= '<li>'.
12333: &mt('Self-creation of account by users with status: [_1]',
12334: '<span class="LC_cusr_emph">'.$typename.'</span>').
12335: ' - '.&mt('modifiable fields (if institutional data blank): ');
12336: foreach my $field (@fields) {
12337: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
12338: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 12339: }
12340: }
1.224 raeburn 12341: if (@modifiable > 0) {
12342: $resulttext .= join(', ',@modifiable);
1.43 raeburn 12343: } else {
1.224 raeburn 12344: $resulttext .= &mt('none');
1.43 raeburn 12345: }
1.224 raeburn 12346: $resulttext .= '</li>';
1.28 raeburn 12347: }
1.224 raeburn 12348: $resulttext .= '</ul></li>';
1.28 raeburn 12349: }
1.27 raeburn 12350: $resulttext .= '</ul>';
1.305 raeburn 12351: my $cachetime = 24*60*60;
12352: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
12353: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12354: if (ref($lastactref) eq 'HASH') {
12355: $lastactref->{'domdefaults'} = 1;
12356: }
1.27 raeburn 12357: } else {
1.224 raeburn 12358: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 12359: }
12360: } else {
12361: $resulttext = '<span class="LC_error">'.
1.23 raeburn 12362: &mt('An error occurred: [_1]',$putresult).'</span>';
12363: }
1.43 raeburn 12364: if ($warningmsg ne '') {
12365: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12366: }
1.23 raeburn 12367: return $resulttext;
12368: }
12369:
1.165 raeburn 12370: sub process_captcha {
12371: my ($container,$changes,$newsettings,$current) = @_;
12372: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
12373: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
12374: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
12375: $newsettings->{'captcha'} = 'original';
12376: }
12377: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 12378: if ($container eq 'cancreate') {
1.169 raeburn 12379: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12380: push(@{$changes->{'cancreate'}},'captcha');
12381: } elsif (!defined($changes->{'cancreate'})) {
12382: $changes->{'cancreate'} = ['captcha'];
12383: }
12384: } else {
12385: $changes->{'captcha'} = 1;
1.165 raeburn 12386: }
12387: }
1.269 raeburn 12388: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 12389: if ($newsettings->{'captcha'} eq 'recaptcha') {
12390: $newpub = $env{'form.'.$container.'_recaptchapub'};
12391: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 12392: $newpub =~ s/[^\w\-]//g;
12393: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 12394: $newsettings->{'recaptchakeys'} = {
12395: public => $newpub,
12396: private => $newpriv,
12397: };
1.269 raeburn 12398: $newversion = $env{'form.'.$container.'_recaptchaversion'};
12399: $newversion =~ s/\D//g;
12400: if ($newversion ne '2') {
12401: $newversion = 1;
12402: }
12403: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 12404: }
12405: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
12406: $currpub = $current->{'recaptchakeys'}{'public'};
12407: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 12408: unless ($newsettings->{'captcha'} eq 'recaptcha') {
12409: $newsettings->{'recaptchakeys'} = {
12410: public => '',
12411: private => '',
12412: }
12413: }
1.165 raeburn 12414: }
1.269 raeburn 12415: if ($current->{'captcha'} eq 'recaptcha') {
12416: $currversion = $current->{'recaptchaversion'};
12417: if ($currversion ne '2') {
12418: $currversion = 1;
12419: }
12420: }
12421: if ($currversion ne $newversion) {
12422: if ($container eq 'cancreate') {
12423: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12424: push(@{$changes->{'cancreate'}},'recaptchaversion');
12425: } elsif (!defined($changes->{'cancreate'})) {
12426: $changes->{'cancreate'} = ['recaptchaversion'];
12427: }
12428: } else {
12429: $changes->{'recaptchaversion'} = 1;
12430: }
12431: }
1.165 raeburn 12432: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 12433: if ($container eq 'cancreate') {
12434: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12435: push(@{$changes->{'cancreate'}},'recaptchakeys');
12436: } elsif (!defined($changes->{'cancreate'})) {
12437: $changes->{'cancreate'} = ['recaptchakeys'];
12438: }
12439: } else {
1.210 raeburn 12440: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 12441: }
12442: }
12443: return;
12444: }
12445:
1.33 raeburn 12446: sub modify_usermodification {
12447: my ($dom,%domconfig) = @_;
1.224 raeburn 12448: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 12449: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12450: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 12451: if ($key eq 'selfcreate') {
12452: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
12453: } else {
12454: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
12455: }
1.33 raeburn 12456: }
12457: }
1.224 raeburn 12458: my @contexts = ('author','course');
1.33 raeburn 12459: my %context_title = (
12460: author => 'In author context',
12461: course => 'In course context',
12462: );
12463: my @fields = ('lastname','firstname','middlename','generation',
12464: 'permanentemail','id');
12465: my %roles = (
12466: author => ['ca','aa'],
12467: course => ['st','ep','ta','in','cr'],
12468: );
12469: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12470: foreach my $context (@contexts) {
12471: foreach my $role (@{$roles{$context}}) {
12472: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
12473: foreach my $item (@fields) {
12474: if (grep(/^\Q$item\E$/,@modifiable)) {
12475: $modifyhash{$context}{$role}{$item} = 1;
12476: } else {
12477: $modifyhash{$context}{$role}{$item} = 0;
12478: }
12479: }
12480: }
12481: if (ref($curr_usermodification{$context}) eq 'HASH') {
12482: foreach my $role (@{$roles{$context}}) {
12483: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
12484: foreach my $field (@fields) {
12485: if ($modifyhash{$context}{$role}{$field} ne
12486: $curr_usermodification{$context}{$role}{$field}) {
12487: push(@{$changes{$context}},$role);
12488: last;
12489: }
12490: }
12491: }
12492: }
12493: } else {
12494: foreach my $context (@contexts) {
12495: foreach my $role (@{$roles{$context}}) {
12496: push(@{$changes{$context}},$role);
12497: }
12498: }
12499: }
12500: }
12501: my %usermodification_hash = (
12502: usermodification => \%modifyhash,
12503: );
12504: my $putresult = &Apache::lonnet::put_dom('configuration',
12505: \%usermodification_hash,$dom);
12506: if ($putresult eq 'ok') {
12507: if (keys(%changes) > 0) {
12508: $resulttext = &mt('Changes made: ').'<ul>';
12509: foreach my $context (@contexts) {
12510: if (ref($changes{$context}) eq 'ARRAY') {
12511: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
12512: if (ref($changes{$context}) eq 'ARRAY') {
12513: foreach my $role (@{$changes{$context}}) {
12514: my $rolename;
1.224 raeburn 12515: if ($role eq 'cr') {
12516: $rolename = &mt('Custom');
1.33 raeburn 12517: } else {
1.224 raeburn 12518: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 12519: }
12520: my @modifiable;
1.224 raeburn 12521: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 12522: foreach my $field (@fields) {
12523: if ($modifyhash{$context}{$role}{$field}) {
12524: push(@modifiable,$fieldtitles{$field});
12525: }
12526: }
12527: if (@modifiable > 0) {
12528: $resulttext .= join(', ',@modifiable);
12529: } else {
12530: $resulttext .= &mt('none');
12531: }
12532: $resulttext .= '</li>';
12533: }
12534: $resulttext .= '</ul></li>';
12535: }
12536: }
12537: }
12538: $resulttext .= '</ul>';
12539: } else {
12540: $resulttext = &mt('No changes made to user modification settings');
12541: }
12542: } else {
12543: $resulttext = '<span class="LC_error">'.
12544: &mt('An error occurred: [_1]',$putresult).'</span>';
12545: }
12546: return $resulttext;
12547: }
12548:
1.43 raeburn 12549: sub modify_defaults {
1.212 raeburn 12550: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 12551: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 12552: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 12553: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
12554: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 12555: my @authtypes = ('internal','krb4','krb5','localauth');
12556: foreach my $item (@items) {
12557: $newvalues{$item} = $env{'form.'.$item};
12558: if ($item eq 'auth_def') {
12559: if ($newvalues{$item} ne '') {
12560: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
12561: push(@errors,$item);
12562: }
12563: }
12564: } elsif ($item eq 'lang_def') {
12565: if ($newvalues{$item} ne '') {
12566: if ($newvalues{$item} =~ /^(\w+)/) {
12567: my $langcode = $1;
1.103 raeburn 12568: if ($langcode ne 'x_chef') {
12569: if (code2language($langcode) eq '') {
12570: push(@errors,$item);
12571: }
1.43 raeburn 12572: }
12573: } else {
12574: push(@errors,$item);
12575: }
12576: }
1.54 raeburn 12577: } elsif ($item eq 'timezone_def') {
12578: if ($newvalues{$item} ne '') {
1.62 raeburn 12579: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 12580: push(@errors,$item);
12581: }
12582: }
1.68 raeburn 12583: } elsif ($item eq 'datelocale_def') {
12584: if ($newvalues{$item} ne '') {
12585: my @datelocale_ids = DateTime::Locale->ids();
12586: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
12587: push(@errors,$item);
12588: }
12589: }
1.141 raeburn 12590: } elsif ($item eq 'portal_def') {
12591: if ($newvalues{$item} ne '') {
12592: 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])\/?$/) {
12593: push(@errors,$item);
12594: }
12595: }
1.294 raeburn 12596: } elsif ($item eq 'intauth_cost') {
12597: if ($newvalues{$item} ne '') {
12598: if ($newvalues{$item} =~ /\D/) {
12599: push(@errors,$item);
12600: }
12601: }
12602: } elsif ($item eq 'intauth_check') {
12603: if ($newvalues{$item} ne '') {
12604: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12605: push(@errors,$item);
12606: }
12607: }
12608: } elsif ($item eq 'intauth_switch') {
12609: if ($newvalues{$item} ne '') {
12610: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12611: push(@errors,$item);
12612: }
12613: }
1.43 raeburn 12614: }
12615: if (grep(/^\Q$item\E$/,@errors)) {
12616: $newvalues{$item} = $domdefaults{$item};
12617: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12618: $changes{$item} = 1;
12619: }
1.72 raeburn 12620: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 12621: }
12622: my %defaults_hash = (
1.72 raeburn 12623: defaults => \%newvalues,
12624: );
1.43 raeburn 12625: my $title = &defaults_titles();
1.236 raeburn 12626:
12627: my $currinststatus;
12628: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12629: $currinststatus = $domconfig{'inststatus'};
12630: } else {
12631: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12632: $currinststatus = {
12633: inststatustypes => $usertypes,
12634: inststatusorder => $types,
12635: inststatusguest => [],
12636: };
12637: }
12638: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12639: my @allpos;
12640: my %alltypes;
1.305 raeburn 12641: my @inststatusguest;
12642: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12643: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
12644: unless (grep(/^\Q$type\E$/,@todelete)) {
12645: push(@inststatusguest,$type);
12646: }
12647: }
12648: }
12649: my ($currtitles,$currorder);
1.236 raeburn 12650: if (ref($currinststatus) eq 'HASH') {
12651: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12652: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12653: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12654: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12655: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12656: }
12657: }
12658: unless (grep(/^\Q$type\E$/,@todelete)) {
12659: my $position = $env{'form.inststatus_pos_'.$type};
12660: $position =~ s/\D+//g;
12661: $allpos[$position] = $type;
12662: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12663: $alltypes{$type} =~ s/`//g;
12664: }
12665: }
12666: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12667: $currtitles =~ s/,$//;
12668: }
12669: }
12670: if ($env{'form.addinststatus'}) {
12671: my $newtype = $env{'form.addinststatus'};
12672: $newtype =~ s/\W//g;
12673: unless (exists($alltypes{$newtype})) {
12674: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12675: $alltypes{$newtype} =~ s/`//g;
12676: my $position = $env{'form.addinststatus_pos'};
12677: $position =~ s/\D+//g;
12678: if ($position ne '') {
12679: $allpos[$position] = $newtype;
12680: }
12681: }
12682: }
1.305 raeburn 12683: my @orderedstatus;
1.236 raeburn 12684: foreach my $type (@allpos) {
12685: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12686: push(@orderedstatus,$type);
12687: }
12688: }
12689: foreach my $type (keys(%alltypes)) {
12690: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12691: delete($alltypes{$type});
12692: }
12693: }
12694: $defaults_hash{'inststatus'} = {
12695: inststatustypes => \%alltypes,
12696: inststatusorder => \@orderedstatus,
1.305 raeburn 12697: inststatusguest => \@inststatusguest,
1.236 raeburn 12698: };
12699: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12700: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12701: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12702: }
12703: }
12704: if ($currorder ne join(',',@orderedstatus)) {
12705: $changes{'inststatus'}{'inststatusorder'} = 1;
12706: }
12707: my $newtitles;
12708: foreach my $item (@orderedstatus) {
12709: $newtitles .= $alltypes{$item}.',';
12710: }
12711: $newtitles =~ s/,$//;
12712: if ($currtitles ne $newtitles) {
12713: $changes{'inststatus'}{'inststatustypes'} = 1;
12714: }
1.43 raeburn 12715: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12716: $dom);
12717: if ($putresult eq 'ok') {
12718: if (keys(%changes) > 0) {
12719: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 12720: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12721: 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";
12722: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 12723: if ($item eq 'inststatus') {
12724: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 12725: if (@orderedstatus) {
1.236 raeburn 12726: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12727: foreach my $type (@orderedstatus) {
12728: $resulttext .= $alltypes{$type}.', ';
12729: }
12730: $resulttext =~ s/, $//;
12731: $resulttext .= '</li>';
1.305 raeburn 12732: } else {
12733: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 12734: }
12735: }
12736: } else {
12737: my $value = $env{'form.'.$item};
12738: if ($value eq '') {
12739: $value = &mt('none');
12740: } elsif ($item eq 'auth_def') {
12741: my %authnames = &authtype_names();
12742: my %shortauth = (
12743: internal => 'int',
12744: krb4 => 'krb4',
12745: krb5 => 'krb5',
12746: localauth => 'loc',
12747: );
12748: $value = $authnames{$shortauth{$value}};
1.294 raeburn 12749: } elsif ($item eq 'intauth_switch') {
12750: my %optiondesc = &Apache::lonlocal::texthash (
12751: 0 => 'No',
12752: 1 => 'Yes',
12753: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12754: );
12755: if ($value =~ /^(0|1|2)$/) {
12756: $value = $optiondesc{$value};
12757: } else {
12758: $value = &mt('none -- defaults to No');
12759: }
12760: } elsif ($item eq 'intauth_check') {
12761: my %optiondesc = &Apache::lonlocal::texthash (
12762: 0 => 'No',
12763: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12764: 2 => 'Yes, disallow login if stored cost is less than domain default',
12765: );
12766: if ($value =~ /^(0|1|2)$/) {
12767: $value = $optiondesc{$value};
12768: } else {
12769: $value = &mt('none -- defaults to No');
12770: }
1.236 raeburn 12771: }
12772: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12773: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12774: }
12775: }
12776: $resulttext .= '</ul>';
12777: $mailmsgtext .= "\n";
12778: my $cachetime = 24*60*60;
1.72 raeburn 12779: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12780: if (ref($lastactref) eq 'HASH') {
12781: $lastactref->{'domdefaults'} = 1;
12782: }
1.68 raeburn 12783: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 12784: my $notify = 1;
12785: if (ref($domconfig{'contacts'}) eq 'HASH') {
12786: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12787: $notify = 0;
12788: }
12789: }
12790: if ($notify) {
12791: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12792: "LON-CAPA Domain Settings Change - $dom",
12793: $mailmsgtext);
12794: }
1.54 raeburn 12795: }
1.43 raeburn 12796: } else {
1.54 raeburn 12797: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12798: }
12799: } else {
12800: $resulttext = '<span class="LC_error">'.
12801: &mt('An error occurred: [_1]',$putresult).'</span>';
12802: }
12803: if (@errors > 0) {
12804: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12805: foreach my $item (@errors) {
12806: $resulttext .= ' "'.$title->{$item}.'",';
12807: }
12808: $resulttext =~ s/,$//;
12809: }
12810: return $resulttext;
12811: }
12812:
1.46 raeburn 12813: sub modify_scantron {
1.205 raeburn 12814: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12815: my ($resulttext,%confhash,%changes,$errors);
12816: my $custom = 'custom.tab';
12817: my $default = 'default.tab';
12818: my $servadm = $r->dir_config('lonAdmEMail');
12819: my ($configuserok,$author_ok,$switchserver) =
12820: &config_check($dom,$confname,$servadm);
12821: if ($env{'form.scantronformat.filename'} ne '') {
12822: my $error;
12823: if ($configuserok eq 'ok') {
12824: if ($switchserver) {
1.130 raeburn 12825: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12826: } else {
12827: if ($author_ok eq 'ok') {
12828: my ($result,$scantronurl) =
12829: &publishlogo($r,'upload','scantronformat',$dom,
12830: $confname,'scantron','','',$custom);
12831: if ($result eq 'ok') {
12832: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12833: $changes{'scantronformat'} = 1;
1.46 raeburn 12834: } else {
12835: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12836: }
12837: } else {
12838: $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);
12839: }
12840: }
12841: } else {
12842: $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);
12843: }
12844: if ($error) {
12845: &Apache::lonnet::logthis($error);
12846: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12847: }
12848: }
1.48 raeburn 12849: if (ref($domconfig{'scantron'}) eq 'HASH') {
12850: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12851: if ($env{'form.scantronformat_del'}) {
12852: $confhash{'scantron'}{'scantronformat'} = '';
12853: $changes{'scantronformat'} = 1;
1.46 raeburn 12854: }
12855: }
12856: }
12857: if (keys(%confhash) > 0) {
12858: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12859: $dom);
12860: if ($putresult eq 'ok') {
12861: if (keys(%changes) > 0) {
1.48 raeburn 12862: if (ref($confhash{'scantron'}) eq 'HASH') {
12863: $resulttext = &mt('Changes made:').'<ul>';
12864: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 12865: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 12866: } else {
1.130 raeburn 12867: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 12868: }
1.48 raeburn 12869: $resulttext .= '</ul>';
12870: } else {
1.130 raeburn 12871: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12872: }
12873: $resulttext .= '</ul>';
12874: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12875: if (ref($lastactref) eq 'HASH') {
12876: $lastactref->{'domainconfig'} = 1;
12877: }
1.46 raeburn 12878: } else {
1.130 raeburn 12879: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12880: }
12881: } else {
12882: $resulttext = '<span class="LC_error">'.
12883: &mt('An error occurred: [_1]',$putresult).'</span>';
12884: }
12885: } else {
1.130 raeburn 12886: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12887: }
12888: if ($errors) {
12889: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12890: $errors.'</ul>';
12891: }
12892: return $resulttext;
12893: }
12894:
1.48 raeburn 12895: sub modify_coursecategories {
1.239 raeburn 12896: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12897: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12898: $cathash);
1.48 raeburn 12899: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 12900: my @catitems = ('unauth','auth');
12901: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12902: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12903: $cathash = $domconfig{'coursecategories'}{'cats'};
12904: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12905: $changes{'togglecats'} = 1;
12906: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12907: }
12908: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12909: $changes{'categorize'} = 1;
12910: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12911: }
1.120 raeburn 12912: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12913: $changes{'togglecatscomm'} = 1;
12914: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12915: }
12916: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12917: $changes{'categorizecomm'} = 1;
12918: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 12919:
12920: }
12921: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
12922: $changes{'togglecatsplace'} = 1;
12923: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
12924: }
12925: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
12926: $changes{'categorizeplace'} = 1;
12927: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 12928: }
1.238 raeburn 12929: foreach my $item (@catitems) {
12930: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12931: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12932: $changes{$item} = 1;
12933: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12934: }
12935: }
12936: }
1.57 raeburn 12937: } else {
12938: $changes{'togglecats'} = 1;
12939: $changes{'categorize'} = 1;
1.124 raeburn 12940: $changes{'togglecatscomm'} = 1;
12941: $changes{'categorizecomm'} = 1;
1.272 raeburn 12942: $changes{'togglecatsplace'} = 1;
12943: $changes{'categorizeplace'} = 1;
1.87 raeburn 12944: $domconfig{'coursecategories'} = {
12945: togglecats => $env{'form.togglecats'},
12946: categorize => $env{'form.categorize'},
1.124 raeburn 12947: togglecatscomm => $env{'form.togglecatscomm'},
12948: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 12949: togglecatsplace => $env{'form.togglecatsplace'},
12950: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 12951: };
1.238 raeburn 12952: foreach my $item (@catitems) {
12953: if ($env{'form.coursecat_'.$item} ne 'std') {
12954: $changes{$item} = 1;
12955: }
12956: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12957: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12958: }
12959: }
1.57 raeburn 12960: }
12961: if (ref($cathash) eq 'HASH') {
12962: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12963: push (@deletecategory,'instcode::0');
12964: }
1.120 raeburn 12965: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12966: push(@deletecategory,'communities::0');
12967: }
1.272 raeburn 12968: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
12969: push(@deletecategory,'placement::0');
12970: }
1.48 raeburn 12971: }
1.57 raeburn 12972: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12973: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12974: if (@deletecategory > 0) {
12975: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12976: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12977: foreach my $item (@deletecategory) {
1.57 raeburn 12978: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12979: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12980: $deletions{$item} = 1;
1.57 raeburn 12981: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12982: }
12983: }
12984: }
1.57 raeburn 12985: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12986: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12987: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12988: $reorderings{$item} = 1;
1.57 raeburn 12989: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12990: }
12991: if ($env{'form.addcategory_name_'.$item} ne '') {
12992: my $newcat = $env{'form.addcategory_name_'.$item};
12993: my $newdepth = $depth+1;
12994: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12995: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12996: $adds{$newitem} = 1;
12997: }
12998: if ($env{'form.subcat_'.$item} ne '') {
12999: my $newcat = $env{'form.subcat_'.$item};
13000: my $newdepth = $depth+1;
13001: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 13002: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 13003: $adds{$newitem} = 1;
13004: }
13005: }
13006: }
13007: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 13008: if (ref($cathash) eq 'HASH') {
1.48 raeburn 13009: my $newitem = 'instcode::0';
1.57 raeburn 13010: if ($cathash->{$newitem} eq '') {
13011: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 13012: $adds{$newitem} = 1;
13013: }
13014: } else {
13015: my $newitem = 'instcode::0';
1.57 raeburn 13016: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 13017: $adds{$newitem} = 1;
13018: }
13019: }
1.120 raeburn 13020: if ($env{'form.communities'} eq '1') {
13021: if (ref($cathash) eq 'HASH') {
13022: my $newitem = 'communities::0';
13023: if ($cathash->{$newitem} eq '') {
13024: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13025: $adds{$newitem} = 1;
13026: }
13027: } else {
13028: my $newitem = 'communities::0';
13029: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13030: $adds{$newitem} = 1;
13031: }
13032: }
1.272 raeburn 13033: if ($env{'form.placement'} eq '1') {
13034: if (ref($cathash) eq 'HASH') {
13035: my $newitem = 'placement::0';
13036: if ($cathash->{$newitem} eq '') {
13037: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
13038: $adds{$newitem} = 1;
13039: }
13040: } else {
13041: my $newitem = 'placement::0';
13042: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
13043: $adds{$newitem} = 1;
13044: }
13045: }
1.48 raeburn 13046: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 13047: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 13048: ($env{'form.addcategory_name'} ne 'communities') &&
13049: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 13050: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
13051: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
13052: $adds{$newitem} = 1;
13053: }
1.48 raeburn 13054: }
1.57 raeburn 13055: my $putresult;
1.48 raeburn 13056: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13057: if (keys(%deletions) > 0) {
13058: foreach my $key (keys(%deletions)) {
13059: if ($predelallitems{$key} ne '') {
13060: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
13061: }
13062: }
13063: }
13064: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 13065: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 13066: if (ref($chkcats[0]) eq 'ARRAY') {
13067: my $depth = 0;
13068: my $chg = 0;
13069: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
13070: my $name = $chkcats[0][$i];
13071: my $item;
13072: if ($name eq '') {
13073: $chg ++;
13074: } else {
13075: $item = &escape($name).'::0';
13076: if ($chg) {
1.57 raeburn 13077: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 13078: }
13079: $depth ++;
1.57 raeburn 13080: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 13081: $depth --;
13082: }
13083: }
13084: }
1.57 raeburn 13085: }
13086: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13087: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 13088: if ($putresult eq 'ok') {
1.57 raeburn 13089: my %title = (
1.120 raeburn 13090: togglecats => 'Show/Hide a course in catalog',
13091: categorize => 'Assign a category to a course',
13092: togglecatscomm => 'Show/Hide a community in catalog',
13093: categorizecomm => 'Assign a category to a community',
1.57 raeburn 13094: );
13095: my %level = (
1.120 raeburn 13096: dom => 'set in Domain ("Modify Course/Community")',
13097: crs => 'set in Course ("Course Configuration")',
13098: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 13099: none => 'No catalog',
13100: std => 'Standard catalog',
13101: domonly => 'Domain-only catalog',
13102: codesrch => 'Code search form',
1.57 raeburn 13103: );
1.48 raeburn 13104: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 13105: if ($changes{'togglecats'}) {
13106: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
13107: }
13108: if ($changes{'categorize'}) {
13109: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 13110: }
1.120 raeburn 13111: if ($changes{'togglecatscomm'}) {
13112: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
13113: }
13114: if ($changes{'categorizecomm'}) {
13115: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
13116: }
1.238 raeburn 13117: if ($changes{'unauth'}) {
13118: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
13119: }
13120: if ($changes{'auth'}) {
13121: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
13122: }
1.57 raeburn 13123: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13124: my $cathash;
13125: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
13126: $cathash = $domconfig{'coursecategories'}{'cats'};
13127: } else {
13128: $cathash = {};
13129: }
13130: my (@cats,@trails,%allitems);
13131: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
13132: if (keys(%deletions) > 0) {
13133: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
13134: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
13135: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
13136: }
13137: $resulttext .= '</ul></li>';
13138: }
13139: if (keys(%reorderings) > 0) {
13140: my %sort_by_trail;
13141: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
13142: foreach my $key (keys(%reorderings)) {
13143: if ($allitems{$key} ne '') {
13144: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13145: }
1.48 raeburn 13146: }
1.57 raeburn 13147: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13148: $resulttext .= '<li>'.$trails[$trail].'</li>';
13149: }
13150: $resulttext .= '</ul></li>';
1.48 raeburn 13151: }
1.57 raeburn 13152: if (keys(%adds) > 0) {
13153: my %sort_by_trail;
13154: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
13155: foreach my $key (keys(%adds)) {
13156: if ($allitems{$key} ne '') {
13157: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13158: }
13159: }
13160: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13161: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 13162: }
1.57 raeburn 13163: $resulttext .= '</ul></li>';
1.48 raeburn 13164: }
13165: }
13166: $resulttext .= '</ul>';
1.239 raeburn 13167: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 13168: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13169: if ($changes{'auth'}) {
13170: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
13171: }
13172: if ($changes{'unauth'}) {
13173: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
13174: }
13175: my $cachetime = 24*60*60;
13176: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 13177: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 13178: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 13179: }
13180: }
1.48 raeburn 13181: } else {
13182: $resulttext = '<span class="LC_error">'.
1.57 raeburn 13183: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 13184: }
13185: } else {
1.120 raeburn 13186: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 13187: }
13188: return $resulttext;
13189: }
13190:
1.69 raeburn 13191: sub modify_serverstatuses {
13192: my ($dom,%domconfig) = @_;
13193: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
13194: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
13195: %currserverstatus = %{$domconfig{'serverstatuses'}};
13196: }
13197: my @pages = &serverstatus_pages();
13198: foreach my $type (@pages) {
13199: $newserverstatus{$type}{'namedusers'} = '';
13200: $newserverstatus{$type}{'machines'} = '';
13201: if (defined($env{'form.'.$type.'_namedusers'})) {
13202: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
13203: my @okusers;
13204: foreach my $user (@users) {
13205: my ($uname,$udom) = split(/:/,$user);
13206: if (($udom =~ /^$match_domain$/) &&
13207: (&Apache::lonnet::domain($udom)) &&
13208: ($uname =~ /^$match_username$/)) {
13209: if (!grep(/^\Q$user\E/,@okusers)) {
13210: push(@okusers,$user);
13211: }
13212: }
13213: }
13214: if (@okusers > 0) {
13215: @okusers = sort(@okusers);
13216: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
13217: }
13218: }
13219: if (defined($env{'form.'.$type.'_machines'})) {
13220: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
13221: my @okmachines;
13222: foreach my $ip (@machines) {
13223: my @parts = split(/\./,$ip);
13224: next if (@parts < 4);
13225: my $badip = 0;
13226: for (my $i=0; $i<4; $i++) {
13227: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
13228: $badip = 1;
13229: last;
13230: }
13231: }
13232: if (!$badip) {
13233: push(@okmachines,$ip);
13234: }
13235: }
13236: @okmachines = sort(@okmachines);
13237: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
13238: }
13239: }
13240: my %serverstatushash = (
13241: serverstatuses => \%newserverstatus,
13242: );
13243: foreach my $type (@pages) {
1.83 raeburn 13244: foreach my $setting ('namedusers','machines') {
1.84 raeburn 13245: my (@current,@new);
1.83 raeburn 13246: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 13247: if ($currserverstatus{$type}{$setting} ne '') {
13248: @current = split(/,/,$currserverstatus{$type}{$setting});
13249: }
13250: }
13251: if ($newserverstatus{$type}{$setting} ne '') {
13252: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 13253: }
13254: if (@current > 0) {
13255: if (@new > 0) {
13256: foreach my $item (@current) {
13257: if (!grep(/^\Q$item\E$/,@new)) {
13258: $changes{$type}{$setting} = 1;
1.82 raeburn 13259: last;
13260: }
13261: }
1.84 raeburn 13262: foreach my $item (@new) {
13263: if (!grep(/^\Q$item\E$/,@current)) {
13264: $changes{$type}{$setting} = 1;
13265: last;
1.82 raeburn 13266: }
13267: }
13268: } else {
1.83 raeburn 13269: $changes{$type}{$setting} = 1;
1.69 raeburn 13270: }
1.83 raeburn 13271: } elsif (@new > 0) {
13272: $changes{$type}{$setting} = 1;
1.69 raeburn 13273: }
13274: }
13275: }
13276: if (keys(%changes) > 0) {
1.81 raeburn 13277: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 13278: my $putresult = &Apache::lonnet::put_dom('configuration',
13279: \%serverstatushash,$dom);
13280: if ($putresult eq 'ok') {
13281: $resulttext .= &mt('Changes made:').'<ul>';
13282: foreach my $type (@pages) {
1.84 raeburn 13283: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 13284: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 13285: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 13286: if ($newserverstatus{$type}{'namedusers'} eq '') {
13287: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
13288: } else {
13289: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
13290: }
1.84 raeburn 13291: }
13292: if ($changes{$type}{'machines'}) {
1.69 raeburn 13293: if ($newserverstatus{$type}{'machines'} eq '') {
13294: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
13295: } else {
13296: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
13297: }
13298:
13299: }
13300: $resulttext .= '</ul></li>';
13301: }
13302: }
13303: $resulttext .= '</ul>';
13304: } else {
13305: $resulttext = '<span class="LC_error">'.
13306: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
13307:
13308: }
13309: } else {
13310: $resulttext = &mt('No changes made to access to server status pages');
13311: }
13312: return $resulttext;
13313: }
13314:
1.118 jms 13315: sub modify_helpsettings {
1.285 raeburn 13316: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 13317: my ($resulttext,$errors,%changes,%helphash);
13318: my %defaultchecked = ('submitbugs' => 'on');
13319: my @offon = ('off','on');
1.118 jms 13320: my @toggles = ('submitbugs');
1.285 raeburn 13321: my %current = ('submitbugs' => '',
13322: 'adhoc' => {},
13323: );
1.118 jms 13324: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 13325: %current = %{$domconfig{'helpsettings'}};
13326: }
1.285 raeburn 13327: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 13328: foreach my $item (@toggles) {
13329: if ($defaultchecked{$item} eq 'on') {
13330: if ($current{$item} eq '') {
13331: if ($env{'form.'.$item} eq '0') {
13332: $changes{$item} = 1;
13333: }
13334: } elsif ($current{$item} ne $env{'form.'.$item}) {
13335: $changes{$item} = 1;
13336: }
13337: } elsif ($defaultchecked{$item} eq 'off') {
13338: if ($current{$item} eq '') {
13339: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 13340: $changes{$item} = 1;
13341: }
1.282 raeburn 13342: } elsif ($current{$item} ne $env{'form.'.$item}) {
13343: $changes{$item} = 1;
13344: }
13345: }
13346: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
13347: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
13348: }
13349: }
1.285 raeburn 13350: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 13351: my $confname = $dom.'-domainconfig';
13352: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 13353: my (@allpos,%newsettings,%changedprivs,$newrole);
13354: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 13355: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 13356: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 13357: my %lt = &Apache::lonlocal::texthash(
13358: s => 'system',
13359: d => 'domain',
13360: order => 'Display order',
13361: access => 'Role usage',
1.291 raeburn 13362: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 13363: dh => 'All with domain helpdesk role',
13364: da => 'All with domain helpdesk assistant role',
1.285 raeburn 13365: none => 'None',
13366: status => 'Determined based on institutional status',
13367: inc => 'Include all, but exclude specific personnel',
13368: exc => 'Exclude all, but include specific personnel',
13369: );
13370: for (my $num=0; $num<=$maxnum; $num++) {
13371: my ($prefix,$identifier,$rolename,%curr);
13372: if ($num == $maxnum) {
13373: next unless ($env{'form.newcusthelp'} == $maxnum);
13374: $identifier = 'custhelp'.$num;
13375: $prefix = 'helproles_'.$num;
13376: $rolename = $env{'form.custhelpname'.$num};
13377: $rolename=~s/[^A-Za-z0-9]//gs;
13378: next if ($rolename eq '');
13379: next if (exists($existing{'rolesdef_'.$rolename}));
13380: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13381: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13382: $newprivs{'c'},$confname,$dom);
13383: if ($result ne 'ok') {
13384: $errors .= '<li><span class="LC_error">'.
13385: &mt('An error occurred storing the new custom role: [_1]',
13386: $result).'</span></li>';
13387: next;
13388: } else {
13389: $changedprivs{$rolename} = \%newprivs;
13390: $newrole = $rolename;
13391: }
13392: } else {
13393: $prefix = 'helproles_'.$num;
13394: $rolename = $env{'form.'.$prefix};
13395: next if ($rolename eq '');
13396: next unless (exists($existing{'rolesdef_'.$rolename}));
13397: $identifier = 'custhelp'.$num;
13398: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13399: my %currprivs;
1.289 raeburn 13400: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 13401: split(/\_/,$existing{'rolesdef_'.$rolename});
13402: foreach my $level ('c','d','s') {
13403: if ($newprivs{$level} ne $currprivs{$level}) {
13404: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13405: $newprivs{'c'},$confname,$dom);
13406: if ($result ne 'ok') {
13407: $errors .= '<li><span class="LC_error">'.
13408: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
13409: $rolename,$result).'</span></li>';
13410: } else {
13411: $changedprivs{$rolename} = \%newprivs;
13412: }
13413: last;
13414: }
13415: }
13416: if (ref($current{'adhoc'}) eq 'HASH') {
13417: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13418: %curr = %{$current{'adhoc'}{$rolename}};
13419: }
13420: }
13421: }
13422: my $newpos = $env{'form.'.$prefix.'_pos'};
13423: $newpos =~ s/\D+//g;
13424: $allpos[$newpos] = $rolename;
13425: my $newdesc = $env{'form.'.$prefix.'_desc'};
13426: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
13427: if ($curr{'desc'}) {
13428: if ($curr{'desc'} ne $newdesc) {
13429: $changes{'customrole'}{$rolename}{'desc'} = 1;
13430: $newsettings{$rolename}{'desc'} = $newdesc;
13431: }
13432: } elsif ($newdesc ne '') {
13433: $changes{'customrole'}{$rolename}{'desc'} = 1;
13434: $newsettings{$rolename}{'desc'} = $newdesc;
13435: }
13436: my $access = $env{'form.'.$prefix.'_access'};
13437: if (grep(/^\Q$access\E$/,@accesstypes)) {
13438: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
13439: if ($access eq 'status') {
13440: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
13441: if (scalar(@statuses) == 0) {
1.289 raeburn 13442: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 13443: } else {
13444: my (@shownstatus,$numtypes);
13445: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13446: if (ref($types) eq 'ARRAY') {
13447: $numtypes = scalar(@{$types});
13448: foreach my $type (sort(@statuses)) {
13449: if ($type eq 'default') {
13450: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13451: } elsif (grep(/^\Q$type\E$/,@{$types})) {
13452: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13453: push(@shownstatus,$usertypes->{$type});
13454: }
13455: }
13456: }
13457: if (grep(/^default$/,@statuses)) {
13458: push(@shownstatus,$othertitle);
13459: }
13460: if (scalar(@shownstatus) == 1+$numtypes) {
13461: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
13462: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
13463: } else {
13464: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
13465: if (ref($curr{'status'}) eq 'ARRAY') {
13466: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13467: if (@diffs) {
13468: $changes{'customrole'}{$rolename}{$access} = 1;
13469: }
13470: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13471: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 13472: }
1.166 raeburn 13473: }
13474: }
1.285 raeburn 13475: } elsif (($access eq 'inc') || ($access eq 'exc')) {
13476: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
13477: my @newspecstaff;
13478: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13479: foreach my $person (sort(@personnel)) {
13480: if ($domhelpdesk{$person}) {
13481: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
13482: }
13483: }
13484: if (ref($curr{$access}) eq 'ARRAY') {
13485: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13486: if (@diffs) {
13487: $changes{'customrole'}{$rolename}{$access} = 1;
13488: }
13489: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13490: $changes{'customrole'}{$rolename}{$access} = 1;
13491: }
13492: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13493: my ($uname,$udom) = split(/:/,$person);
13494: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
13495: }
13496: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 13497: }
1.285 raeburn 13498: } else {
13499: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
13500: }
13501: unless ($curr{'access'} eq $access) {
13502: $changes{'customrole'}{$rolename}{'access'} = 1;
13503: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 13504: }
13505: }
1.285 raeburn 13506: if (@allpos > 0) {
13507: my $idx = 0;
13508: foreach my $rolename (@allpos) {
13509: if ($rolename ne '') {
13510: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
13511: if (ref($current{'adhoc'}) eq 'HASH') {
13512: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13513: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
13514: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 13515: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 13516: }
13517: }
1.282 raeburn 13518: }
1.285 raeburn 13519: $idx ++;
1.166 raeburn 13520: }
13521: }
1.118 jms 13522: }
1.123 jms 13523: my $putresult;
13524: if (keys(%changes) > 0) {
1.166 raeburn 13525: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 13526: if ($putresult eq 'ok') {
1.285 raeburn 13527: if (ref($helphash{'helpsettings'}) eq 'HASH') {
13528: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
13529: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
13530: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
13531: }
13532: }
13533: my $cachetime = 24*60*60;
13534: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13535: if (ref($lastactref) eq 'HASH') {
13536: $lastactref->{'domdefaults'} = 1;
13537: }
13538: } else {
13539: $errors .= '<li><span class="LC_error">'.
13540: &mt('An error occurred storing the settings: [_1]',
13541: $putresult).'</span></li>';
13542: }
13543: }
13544: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
13545: $resulttext = &mt('Changes made:').'<ul>';
13546: my (%shownprivs,@levelorder);
13547: @levelorder = ('c','d','s');
13548: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 13549: foreach my $item (sort(keys(%changes))) {
13550: if ($item eq 'submitbugs') {
13551: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
13552: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
13553: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 13554: } elsif ($item eq 'customrole') {
13555: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 13556: my @keyorder = ('order','desc','access','status','exc','inc');
13557: my %keytext = &Apache::lonlocal::texthash(
13558: order => 'Order',
13559: desc => 'Role description',
13560: access => 'Role usage',
1.300 droeschl 13561: status => 'Allowed institutional types',
1.285 raeburn 13562: exc => 'Allowed personnel',
13563: inc => 'Disallowed personnel',
13564: );
1.282 raeburn 13565: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 13566: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
13567: if ($role eq $newrole) {
13568: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
13569: $role).'<ul>';
13570: } else {
13571: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13572: $role).'<ul>';
13573: }
13574: foreach my $key (@keyorder) {
13575: if ($changes{'customrole'}{$role}{$key}) {
13576: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
13577: $keytext{$key},$newsettings{$role}{$key}).
13578: '</li>';
13579: }
13580: }
13581: if (ref($changedprivs{$role}) eq 'HASH') {
13582: $shownprivs{$role} = 1;
13583: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
13584: foreach my $level (@levelorder) {
13585: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13586: next if ($item eq '');
13587: my ($priv) = split(/\&/,$item,2);
13588: if (&Apache::lonnet::plaintext($priv)) {
13589: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13590: unless ($level eq 'c') {
13591: $resulttext .= ' ('.$lt{$level}.')';
13592: }
13593: $resulttext .= '</li>';
13594: }
13595: }
13596: }
13597: $resulttext .= '</ul>';
13598: }
13599: $resulttext .= '</ul></li>';
13600: }
13601: }
13602: }
13603: }
13604: }
13605: }
13606: if (keys(%changedprivs)) {
13607: foreach my $role (sort(keys(%changedprivs))) {
13608: unless ($shownprivs{$role}) {
13609: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13610: $role).'<ul>'.
13611: '<li>'.&mt('Privileges set to :').'<ul>';
13612: foreach my $level (@levelorder) {
13613: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13614: next if ($item eq '');
13615: my ($priv) = split(/\&/,$item,2);
13616: if (&Apache::lonnet::plaintext($priv)) {
13617: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13618: unless ($level eq 'c') {
13619: $resulttext .= ' ('.$lt{$level}.')';
13620: }
13621: $resulttext .= '</li>';
13622: }
1.282 raeburn 13623: }
13624: }
1.285 raeburn 13625: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 13626: }
13627: }
13628: }
1.285 raeburn 13629: $resulttext .= '</ul>';
13630: } else {
13631: $resulttext = &mt('No changes made to help settings');
1.118 jms 13632: }
13633: if ($errors) {
1.168 raeburn 13634: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 13635: $errors.'</ul>';
1.118 jms 13636: }
13637: return $resulttext;
13638: }
13639:
1.121 raeburn 13640: sub modify_coursedefaults {
1.212 raeburn 13641: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 13642: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 13643: my %defaultchecked = (
13644: 'canuse_pdfforms' => 'off',
13645: 'uselcmath' => 'on',
13646: 'usejsme' => 'on'
13647: );
13648: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 13649: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 13650: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
13651: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
13652: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 13653: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 13654: my %staticdefaults = (
13655: anonsurvey_threshold => 10,
13656: uploadquota => 500,
1.257 raeburn 13657: postsubmit => 60,
1.276 raeburn 13658: mysqltables => 172800,
1.198 raeburn 13659: );
1.121 raeburn 13660:
13661: $defaultshash{'coursedefaults'} = {};
13662:
13663: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13664: if ($domconfig{'coursedefaults'} eq '') {
13665: $domconfig{'coursedefaults'} = {};
13666: }
13667: }
13668:
13669: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13670: foreach my $item (@toggles) {
13671: if ($defaultchecked{$item} eq 'on') {
13672: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13673: ($env{'form.'.$item} eq '0')) {
13674: $changes{$item} = 1;
1.192 raeburn 13675: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 13676: $changes{$item} = 1;
13677: }
13678: } elsif ($defaultchecked{$item} eq 'off') {
13679: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13680: ($env{'form.'.$item} eq '1')) {
13681: $changes{$item} = 1;
13682: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13683: $changes{$item} = 1;
13684: }
13685: }
13686: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13687: }
1.198 raeburn 13688: foreach my $item (@numbers) {
13689: my ($currdef,$newdef);
1.208 raeburn 13690: $newdef = $env{'form.'.$item};
1.198 raeburn 13691: if ($item eq 'anonsurvey_threshold') {
13692: $currdef = $domconfig{'coursedefaults'}{$item};
13693: $newdef =~ s/\D//g;
13694: if ($newdef eq '' || $newdef < 1) {
13695: $newdef = 1;
13696: }
13697: $defaultshash{'coursedefaults'}{$item} = $newdef;
13698: } else {
1.276 raeburn 13699: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13700: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13701: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 13702: }
13703: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 13704: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 13705: }
13706: if ($currdef ne $newdef) {
13707: my $staticdef;
13708: if ($item eq 'anonsurvey_threshold') {
13709: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13710: $changes{$item} = 1;
13711: }
1.276 raeburn 13712: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 13713: my $setting = $1;
1.276 raeburn 13714: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13715: $changes{$setting} = 1;
1.198 raeburn 13716: }
13717: }
1.139 raeburn 13718: }
13719: }
1.264 raeburn 13720: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13721: my @currclonecode;
13722: if (ref($currclone) eq 'HASH') {
13723: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13724: @currclonecode = @{$currclone->{'instcode'}};
13725: }
13726: }
13727: my $newclone;
1.289 raeburn 13728: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 13729: $newclone = $env{'form.canclone'};
13730: }
13731: if ($newclone eq 'instcode') {
13732: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13733: my (%codedefaults,@code_order,@clonecode);
13734: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13735: \@code_order);
13736: foreach my $item (@code_order) {
13737: if (grep(/^\Q$item\E$/,@newcodes)) {
13738: push(@clonecode,$item);
13739: }
13740: }
13741: if (@clonecode) {
13742: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13743: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13744: if (@diffs) {
13745: $changes{'canclone'} = 1;
13746: }
13747: } else {
13748: $newclone eq '';
13749: }
13750: } elsif ($newclone ne '') {
1.289 raeburn 13751: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13752: }
1.264 raeburn 13753: if ($newclone ne $currclone) {
13754: $changes{'canclone'} = 1;
13755: }
1.257 raeburn 13756: my %credits;
13757: foreach my $type (@types) {
13758: unless ($type eq 'community') {
13759: $credits{$type} = $env{'form.'.$type.'_credits'};
13760: $credits{$type} =~ s/[^\d.]+//g;
13761: }
13762: }
13763: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13764: ($env{'form.coursecredits'} eq '1')) {
13765: $changes{'coursecredits'} = 1;
13766: foreach my $type (keys(%credits)) {
13767: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13768: }
13769: } else {
1.289 raeburn 13770: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 13771: foreach my $type (@types) {
13772: unless ($type eq 'community') {
1.289 raeburn 13773: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 13774: $changes{'coursecredits'} = 1;
13775: }
13776: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13777: }
13778: }
13779: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13780: foreach my $type (@types) {
13781: unless ($type eq 'community') {
13782: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13783: $changes{'coursecredits'} = 1;
13784: last;
13785: }
13786: }
13787: }
13788: }
13789: }
13790: if ($env{'form.postsubmit'} eq '1') {
13791: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13792: my %currtimeout;
13793: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13794: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13795: $changes{'postsubmit'} = 1;
13796: }
13797: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13798: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13799: }
13800: } else {
13801: $changes{'postsubmit'} = 1;
13802: }
13803: foreach my $type (@types) {
13804: my $timeout = $env{'form.'.$type.'_timeout'};
13805: $timeout =~ s/\D//g;
13806: if ($timeout == $staticdefaults{'postsubmit'}) {
13807: $timeout = '';
13808: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13809: $timeout = '0';
13810: }
13811: unless ($timeout eq '') {
13812: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13813: }
13814: if (exists($currtimeout{$type})) {
13815: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 13816: $changes{'postsubmit'} = 1;
1.257 raeburn 13817: }
13818: } elsif ($timeout ne '') {
13819: $changes{'postsubmit'} = 1;
13820: }
13821: }
13822: } else {
13823: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13824: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13825: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13826: $changes{'postsubmit'} = 1;
13827: }
13828: } else {
13829: $changes{'postsubmit'} = 1;
13830: }
1.192 raeburn 13831: }
1.121 raeburn 13832: }
13833: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13834: $dom);
13835: if ($putresult eq 'ok') {
13836: if (keys(%changes) > 0) {
1.213 raeburn 13837: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 13838: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 13839: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 13840: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 13841: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
13842: if ($changes{$item}) {
13843: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13844: }
1.289 raeburn 13845: }
1.192 raeburn 13846: if ($changes{'coursecredits'}) {
13847: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 13848: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13849: $domdefaults{$type.'credits'} =
13850: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13851: }
13852: }
13853: }
13854: if ($changes{'postsubmit'}) {
13855: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13856: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13857: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13858: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13859: $domdefaults{$type.'postsubtimeout'} =
13860: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13861: }
13862: }
1.192 raeburn 13863: }
13864: }
1.198 raeburn 13865: if ($changes{'uploadquota'}) {
13866: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13867: foreach my $type (@types) {
13868: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13869: }
13870: }
13871: }
1.264 raeburn 13872: if ($changes{'canclone'}) {
13873: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13874: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13875: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13876: if (@clonecodes) {
13877: $domdefaults{'canclone'} = join('+',@clonecodes);
13878: }
13879: }
13880: } else {
13881: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13882: }
13883: }
1.121 raeburn 13884: my $cachetime = 24*60*60;
13885: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13886: if (ref($lastactref) eq 'HASH') {
13887: $lastactref->{'domdefaults'} = 1;
13888: }
1.121 raeburn 13889: }
13890: $resulttext = &mt('Changes made:').'<ul>';
13891: foreach my $item (sort(keys(%changes))) {
13892: if ($item eq 'canuse_pdfforms') {
13893: if ($env{'form.'.$item} eq '1') {
13894: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
13895: } else {
13896: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
13897: }
1.257 raeburn 13898: } elsif ($item eq 'uselcmath') {
13899: if ($env{'form.'.$item} eq '1') {
13900: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13901: } else {
13902: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13903: }
13904: } elsif ($item eq 'usejsme') {
13905: if ($env{'form.'.$item} eq '1') {
13906: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13907: } else {
1.289 raeburn 13908: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 13909: }
1.139 raeburn 13910: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 13911: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 13912: } elsif ($item eq 'uploadquota') {
13913: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13914: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13915: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13916: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 13917: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 13918: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 13919: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13920: '</ul>'.
13921: '</li>';
13922: } else {
13923: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13924: }
1.276 raeburn 13925: } elsif ($item eq 'mysqltables') {
13926: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13927: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13928: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13929: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13930: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13931: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
13932: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13933: '</ul>'.
13934: '</li>';
13935: } else {
13936: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13937: }
1.257 raeburn 13938: } elsif ($item eq 'postsubmit') {
13939: if ($domdefaults{'postsubmit'} eq 'off') {
13940: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13941: } else {
13942: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 13943: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 13944: $resulttext .= &mt('durations:').'<ul>';
13945: foreach my $type (@types) {
13946: $resulttext .= '<li>';
13947: my $timeout;
13948: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13949: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13950: }
13951: my $display;
13952: if ($timeout eq '0') {
13953: $display = &mt('unlimited');
13954: } elsif ($timeout eq '') {
13955: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13956: } else {
13957: $display = &mt('[quant,_1,second]',$timeout);
13958: }
13959: if ($type eq 'community') {
13960: $resulttext .= &mt('Communities');
13961: } elsif ($type eq 'official') {
13962: $resulttext .= &mt('Official courses');
13963: } elsif ($type eq 'unofficial') {
13964: $resulttext .= &mt('Unofficial courses');
13965: } elsif ($type eq 'textbook') {
13966: $resulttext .= &mt('Textbook courses');
1.271 raeburn 13967: } elsif ($type eq 'placement') {
13968: $resulttext .= &mt('Placement tests');
1.257 raeburn 13969: }
13970: $resulttext .= ' -- '.$display.'</li>';
13971: }
13972: $resulttext .= '</ul>';
13973: }
1.289 raeburn 13974: $resulttext .= '</li>';
1.257 raeburn 13975: }
1.192 raeburn 13976: } elsif ($item eq 'coursecredits') {
13977: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13978: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 13979: ($domdefaults{'unofficialcredits'} eq '') &&
13980: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 13981: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13982: } else {
13983: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13984: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13985: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 13986: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 13987: '</ul>'.
13988: '</li>';
13989: }
13990: } else {
13991: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13992: }
1.264 raeburn 13993: } elsif ($item eq 'canclone') {
13994: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13995: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13996: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13997: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13998: }
13999: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
14000: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
14001: } else {
1.289 raeburn 14002: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 14003: }
1.140 raeburn 14004: }
1.121 raeburn 14005: }
14006: $resulttext .= '</ul>';
14007: } else {
14008: $resulttext = &mt('No changes made to course defaults');
14009: }
14010: } else {
14011: $resulttext = '<span class="LC_error">'.
14012: &mt('An error occurred: [_1]',$putresult).'</span>';
14013: }
14014: return $resulttext;
14015: }
14016:
1.231 raeburn 14017: sub modify_selfenrollment {
14018: my ($dom,$lastactref,%domconfig) = @_;
14019: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 14020: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 14021: my %titles = &tool_titles();
1.232 raeburn 14022: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
14023: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 14024: $ordered{'default'} = ['types','registered','approval','limit'];
14025:
14026: my (%roles,%shown,%toplevel);
14027: $roles{'0'} = &Apache::lonnet::plaintext('dc');
14028:
14029: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
14030: if ($domconfig{'selfenrollment'} eq '') {
14031: $domconfig{'selfenrollment'} = {};
14032: }
14033: }
14034: %toplevel = (
14035: admin => 'Configuration Rights',
14036: default => 'Default settings',
14037: validation => 'Validation of self-enrollment requests',
14038: );
1.233 raeburn 14039: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 14040:
14041: if (ref($ordered{'admin'}) eq 'ARRAY') {
14042: foreach my $item (@{$ordered{'admin'}}) {
14043: foreach my $type (@types) {
14044: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
14045: $selfenrollhash{'admin'}{$type}{$item} = 1;
14046: } else {
14047: $selfenrollhash{'admin'}{$type}{$item} = 0;
14048: }
14049: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
14050: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
14051: if ($selfenrollhash{'admin'}{$type}{$item} ne
14052: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
14053: push(@{$changes{'admin'}{$type}},$item);
14054: }
14055: } else {
14056: if (!$selfenrollhash{'admin'}{$type}{$item}) {
14057: push(@{$changes{'admin'}{$type}},$item);
14058: }
14059: }
14060: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
14061: push(@{$changes{'admin'}{$type}},$item);
14062: }
14063: }
14064: }
14065: }
14066:
14067: foreach my $item (@{$ordered{'default'}}) {
14068: foreach my $type (@types) {
14069: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
14070: if ($item eq 'types') {
14071: unless (($value eq 'all') || ($value eq 'dom')) {
14072: $value = '';
14073: }
14074: } elsif ($item eq 'registered') {
14075: unless ($value eq '1') {
14076: $value = 0;
14077: }
14078: } elsif ($item eq 'approval') {
14079: unless ($value =~ /^[012]$/) {
14080: $value = 0;
14081: }
14082: } else {
14083: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14084: $value = 'none';
14085: }
14086: }
14087: $selfenrollhash{'default'}{$type}{$item} = $value;
14088: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
14089: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14090: if ($selfenrollhash{'default'}{$type}{$item} ne
14091: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
14092: push(@{$changes{'default'}{$type}},$item);
14093: }
14094: } else {
14095: push(@{$changes{'default'}{$type}},$item);
14096: }
14097: } else {
14098: push(@{$changes{'default'}{$type}},$item);
14099: }
14100: if ($item eq 'limit') {
14101: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14102: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
14103: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
14104: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
14105: }
14106: } else {
14107: $selfenrollhash{'default'}{$type}{'cap'} = '';
14108: }
14109: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14110: if ($selfenrollhash{'default'}{$type}{'cap'} ne
14111: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
14112: push(@{$changes{'default'}{$type}},'cap');
14113: }
14114: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
14115: push(@{$changes{'default'}{$type}},'cap');
14116: }
14117: }
14118: }
14119: }
14120:
14121: foreach my $item (@{$itemsref}) {
14122: if ($item eq 'fields') {
14123: my @changed;
14124: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
14125: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
14126: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
14127: }
14128: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14129: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
14130: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
14131: $domconfig{'selfenrollment'}{'validation'}{$item});
14132: } else {
14133: @changed = @{$selfenrollhash{'validation'}{$item}};
14134: }
14135: } else {
14136: @changed = @{$selfenrollhash{'validation'}{$item}};
14137: }
14138: if (@changed) {
14139: if ($selfenrollhash{'validation'}{$item}) {
14140: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
14141: } else {
14142: $changes{'validation'}{$item} = &mt('None');
14143: }
14144: }
14145: } else {
14146: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
14147: if ($item eq 'markup') {
14148: if ($env{'form.selfenroll_validation_'.$item}) {
14149: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14150: }
14151: }
14152: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14153: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
14154: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
14155: }
14156: }
14157: }
14158: }
14159:
14160: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
14161: $dom);
14162: if ($putresult eq 'ok') {
14163: if (keys(%changes) > 0) {
14164: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14165: $resulttext = &mt('Changes made:').'<ul>';
14166: foreach my $key ('admin','default','validation') {
14167: if (ref($changes{$key}) eq 'HASH') {
14168: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
14169: if ($key eq 'validation') {
14170: foreach my $item (@{$itemsref}) {
14171: if (exists($changes{$key}{$item})) {
14172: if ($item eq 'markup') {
14173: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14174: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
14175: } else {
14176: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14177: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
14178: }
14179: }
14180: }
14181: } else {
14182: foreach my $type (@types) {
14183: if ($type eq 'community') {
14184: $roles{'1'} = &mt('Community personnel');
14185: } else {
14186: $roles{'1'} = &mt('Course personnel');
14187: }
14188: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 14189: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14190: if ($key eq 'admin') {
14191: my @mgrdc = ();
14192: if (ref($ordered{$key}) eq 'ARRAY') {
14193: foreach my $item (@{$ordered{'admin'}}) {
14194: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14195: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
14196: push(@mgrdc,$item);
14197: }
14198: }
14199: }
14200: if (@mgrdc) {
14201: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
14202: } else {
14203: delete($domdefaults{$type.'selfenrolladmdc'});
14204: }
14205: }
14206: } else {
14207: if (ref($ordered{$key}) eq 'ARRAY') {
14208: foreach my $item (@{$ordered{$key}}) {
14209: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14210: $domdefaults{$type.'selfenroll'.$item} =
14211: $selfenrollhash{$key}{$type}{$item};
14212: }
14213: }
14214: }
14215: }
14216: }
1.231 raeburn 14217: $resulttext .= '<li>'.$titles{$type}.'<ul>';
14218: foreach my $item (@{$ordered{$key}}) {
14219: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14220: $resulttext .= '<li>';
14221: if ($key eq 'admin') {
14222: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
14223: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
14224: } else {
14225: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
14226: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
14227: }
14228: $resulttext .= '</li>';
14229: }
14230: }
14231: $resulttext .= '</ul></li>';
14232: }
14233: }
14234: $resulttext .= '</ul></li>';
14235: }
14236: }
1.305 raeburn 14237: }
14238: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
14239: my $cachetime = 24*60*60;
14240: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14241: if (ref($lastactref) eq 'HASH') {
14242: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 14243: }
1.231 raeburn 14244: }
14245: $resulttext .= '</ul>';
14246: } else {
14247: $resulttext = &mt('No changes made to self-enrollment settings');
14248: }
14249: } else {
14250: $resulttext = '<span class="LC_error">'.
14251: &mt('An error occurred: [_1]',$putresult).'</span>';
14252: }
14253: return $resulttext;
14254: }
14255:
1.137 raeburn 14256: sub modify_usersessions {
1.212 raeburn 14257: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 14258: my @hostingtypes = ('version','excludedomain','includedomain');
14259: my @offloadtypes = ('primary','default');
14260: my %types = (
14261: remote => \@hostingtypes,
14262: hosted => \@hostingtypes,
14263: spares => \@offloadtypes,
14264: );
14265: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 14266: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 14267: my (%by_ip,%by_location,@intdoms,@instdoms);
14268: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 14269: my @locations = sort(keys(%by_location));
1.137 raeburn 14270: my (%defaultshash,%changes);
14271: foreach my $prefix (@prefixes) {
14272: $defaultshash{'usersessions'}{$prefix} = {};
14273: }
1.212 raeburn 14274: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 14275: my $resulttext;
1.138 raeburn 14276: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 14277: foreach my $prefix (@prefixes) {
1.145 raeburn 14278: next if ($prefix eq 'spares');
14279: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 14280: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14281: if ($type eq 'version') {
14282: my $value = $env{'form.'.$prefix.'_'.$type};
14283: my $okvalue;
14284: if ($value ne '') {
14285: if (grep(/^\Q$value\E$/,@lcversions)) {
14286: $okvalue = $value;
14287: }
14288: }
14289: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14290: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14291: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
14292: if ($inuse == 0) {
14293: $changes{$prefix}{$type} = 1;
14294: } else {
14295: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
14296: $changes{$prefix}{$type} = 1;
14297: }
14298: if ($okvalue ne '') {
14299: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14300: }
14301: }
14302: } else {
14303: if (($inuse == 1) && ($okvalue ne '')) {
14304: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14305: $changes{$prefix}{$type} = 1;
14306: }
14307: }
14308: } else {
14309: if (($inuse == 1) && ($okvalue ne '')) {
14310: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14311: $changes{$prefix}{$type} = 1;
14312: }
14313: }
14314: } else {
14315: if (($inuse == 1) && ($okvalue ne '')) {
14316: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14317: $changes{$prefix}{$type} = 1;
14318: }
14319: }
14320: } else {
14321: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14322: my @okvals;
14323: foreach my $val (@vals) {
1.138 raeburn 14324: if ($val =~ /:/) {
14325: my @items = split(/:/,$val);
14326: foreach my $item (@items) {
14327: if (ref($by_location{$item}) eq 'ARRAY') {
14328: push(@okvals,$item);
14329: }
14330: }
14331: } else {
14332: if (ref($by_location{$val}) eq 'ARRAY') {
14333: push(@okvals,$val);
14334: }
1.137 raeburn 14335: }
14336: }
14337: @okvals = sort(@okvals);
14338: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14339: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14340: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14341: if ($inuse == 0) {
14342: $changes{$prefix}{$type} = 1;
14343: } else {
14344: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14345: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
14346: if (@changed > 0) {
14347: $changes{$prefix}{$type} = 1;
14348: }
14349: }
14350: } else {
14351: if ($inuse == 1) {
14352: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14353: $changes{$prefix}{$type} = 1;
14354: }
14355: }
14356: } else {
14357: if ($inuse == 1) {
14358: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14359: $changes{$prefix}{$type} = 1;
14360: }
14361: }
14362: } else {
14363: if ($inuse == 1) {
14364: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14365: $changes{$prefix}{$type} = 1;
14366: }
14367: }
14368: }
14369: }
14370: }
1.145 raeburn 14371:
14372: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 14373: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 14374: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
14375: my $savespares;
14376:
14377: foreach my $lonhost (sort(keys(%servers))) {
14378: my $serverhomeID =
14379: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 14380: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 14381: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
14382: my %spareschg;
14383: foreach my $type (@{$types{'spares'}}) {
14384: my @okspares;
14385: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
14386: foreach my $server (@checked) {
1.152 raeburn 14387: if (&Apache::lonnet::hostname($server) ne '') {
14388: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
14389: unless (grep(/^\Q$server\E$/,@okspares)) {
14390: push(@okspares,$server);
14391: }
1.145 raeburn 14392: }
14393: }
14394: }
14395: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
14396: my $newspare;
1.152 raeburn 14397: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
14398: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 14399: $newspare = $new;
14400: }
14401: }
1.152 raeburn 14402: my @spares;
14403: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
14404: @spares = sort(@okspares,$newspare);
14405: } else {
14406: @spares = sort(@okspares);
14407: }
14408: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 14409: if (ref($spareid{$lonhost}) eq 'HASH') {
14410: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 14411: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 14412: if (@diffs > 0) {
14413: $spareschg{$type} = 1;
14414: }
14415: }
14416: }
14417: }
14418: if (keys(%spareschg) > 0) {
14419: $changes{'spares'}{$lonhost} = \%spareschg;
14420: }
14421: }
1.261 raeburn 14422: $defaultshash{'usersessions'}{'offloadnow'} = {};
14423: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
14424: my @okoffload;
14425: if (@offloadnow) {
14426: foreach my $server (@offloadnow) {
14427: if (&Apache::lonnet::hostname($server) ne '') {
14428: unless (grep(/^\Q$server\E$/,@okoffload)) {
14429: push(@okoffload,$server);
14430: }
14431: }
14432: }
14433: if (@okoffload) {
14434: foreach my $lonhost (@okoffload) {
14435: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
14436: }
14437: }
14438: }
1.145 raeburn 14439: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14440: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
14441: if (ref($changes{'spares'}) eq 'HASH') {
14442: if (keys(%{$changes{'spares'}}) > 0) {
14443: $savespares = 1;
14444: }
14445: }
14446: } else {
14447: $savespares = 1;
14448: }
1.261 raeburn 14449: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
14450: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
14451: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
14452: $changes{'offloadnow'} = 1;
14453: last;
14454: }
14455: }
14456: unless ($changes{'offloadnow'}) {
1.289 raeburn 14457: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 14458: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
14459: $changes{'offloadnow'} = 1;
14460: last;
14461: }
14462: }
14463: }
14464: } elsif (@okoffload) {
14465: $changes{'offloadnow'} = 1;
14466: }
14467: } elsif (@okoffload) {
14468: $changes{'offloadnow'} = 1;
1.145 raeburn 14469: }
1.147 raeburn 14470: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
14471: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 14472: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14473: $dom);
14474: if ($putresult eq 'ok') {
14475: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14476: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
14477: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
14478: }
14479: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
14480: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
14481: }
1.261 raeburn 14482: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14483: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
14484: }
1.137 raeburn 14485: }
14486: my $cachetime = 24*60*60;
14487: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 14488: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 14489: if (ref($lastactref) eq 'HASH') {
14490: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 14491: $lastactref->{'usersessions'} = 1;
1.212 raeburn 14492: }
1.147 raeburn 14493: if (keys(%changes) > 0) {
14494: my %lt = &usersession_titles();
14495: $resulttext = &mt('Changes made:').'<ul>';
14496: foreach my $prefix (@prefixes) {
14497: if (ref($changes{$prefix}) eq 'HASH') {
14498: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14499: if ($prefix eq 'spares') {
14500: if (ref($changes{$prefix}) eq 'HASH') {
14501: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
14502: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 14503: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 14504: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
14505: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 14506: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
14507: foreach my $type (@{$types{$prefix}}) {
14508: if ($changes{$prefix}{$lonhost}{$type}) {
14509: my $offloadto = &mt('None');
14510: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
14511: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
14512: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
14513: }
1.145 raeburn 14514: }
1.147 raeburn 14515: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 14516: }
1.137 raeburn 14517: }
14518: }
1.147 raeburn 14519: $resulttext .= '</li>';
1.137 raeburn 14520: }
14521: }
1.147 raeburn 14522: } else {
14523: foreach my $type (@{$types{$prefix}}) {
14524: if (defined($changes{$prefix}{$type})) {
14525: my $newvalue;
14526: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14527: if (ref($defaultshash{'usersessions'}{$prefix})) {
14528: if ($type eq 'version') {
14529: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
14530: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14531: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
14532: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
14533: }
1.145 raeburn 14534: }
14535: }
14536: }
1.147 raeburn 14537: if ($newvalue eq '') {
14538: if ($type eq 'version') {
14539: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
14540: } else {
14541: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14542: }
1.145 raeburn 14543: } else {
1.147 raeburn 14544: if ($type eq 'version') {
14545: $newvalue .= ' '.&mt('(or later)');
14546: }
14547: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 14548: }
1.137 raeburn 14549: }
14550: }
14551: }
1.147 raeburn 14552: $resulttext .= '</ul>';
1.137 raeburn 14553: }
14554: }
1.261 raeburn 14555: if ($changes{'offloadnow'}) {
14556: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14557: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
14558: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
14559: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
14560: $resulttext .= '<li>'.$lonhost.'</li>';
14561: }
14562: $resulttext .= '</ul>';
14563: } else {
14564: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
14565: }
14566: } else {
14567: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
14568: }
14569: }
1.147 raeburn 14570: $resulttext .= '</ul>';
14571: } else {
14572: $resulttext = $nochgmsg;
1.137 raeburn 14573: }
14574: } else {
14575: $resulttext = '<span class="LC_error">'.
14576: &mt('An error occurred: [_1]',$putresult).'</span>';
14577: }
14578: } else {
1.147 raeburn 14579: $resulttext = $nochgmsg;
1.137 raeburn 14580: }
14581: return $resulttext;
14582: }
14583:
1.275 raeburn 14584: sub modify_ssl {
14585: my ($dom,$lastactref,%domconfig) = @_;
14586: my (%by_ip,%by_location,@intdoms,@instdoms);
14587: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14588: my @locations = sort(keys(%by_location));
14589: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14590: my (%defaultshash,%changes);
14591: my $action = 'ssl';
1.293 raeburn 14592: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 14593: foreach my $prefix (@prefixes) {
14594: $defaultshash{$action}{$prefix} = {};
14595: }
14596: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14597: my $resulttext;
14598: my %iphost = &Apache::lonnet::get_iphost();
14599: my @reptypes = ('certreq','nocertreq');
14600: my @connecttypes = ('dom','intdom','other');
14601: my %types = (
1.293 raeburn 14602: connto => \@connecttypes,
14603: connfrom => \@connecttypes,
14604: replication => \@reptypes,
1.275 raeburn 14605: );
14606: foreach my $prefix (sort(keys(%types))) {
14607: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 14608: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14609: my $value = 'yes';
14610: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
14611: $value = $env{'form.'.$prefix.'_'.$type};
14612: }
14613: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14614: if ($domconfig{$action}{$prefix}{$type} ne '') {
14615: if ($value ne $domconfig{$action}{$prefix}{$type}) {
14616: $changes{$prefix}{$type} = 1;
14617: }
14618: $defaultshash{$action}{$prefix}{$type} = $value;
14619: } else {
14620: $defaultshash{$action}{$prefix}{$type} = $value;
14621: $changes{$prefix}{$type} = 1;
14622: }
14623: } else {
14624: $defaultshash{$action}{$prefix}{$type} = $value;
14625: $changes{$prefix}{$type} = 1;
14626: }
14627: if (($type eq 'dom') && (keys(%servers) == 1)) {
14628: delete($changes{$prefix}{$type});
14629: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
14630: delete($changes{$prefix}{$type});
14631: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
14632: delete($changes{$prefix}{$type});
14633: }
14634: } elsif ($prefix eq 'replication') {
14635: if (@locations > 0) {
14636: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14637: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14638: my @okvals;
14639: foreach my $val (@vals) {
14640: if ($val =~ /:/) {
14641: my @items = split(/:/,$val);
14642: foreach my $item (@items) {
14643: if (ref($by_location{$item}) eq 'ARRAY') {
14644: push(@okvals,$item);
14645: }
14646: }
14647: } else {
14648: if (ref($by_location{$val}) eq 'ARRAY') {
14649: push(@okvals,$val);
14650: }
14651: }
14652: }
14653: @okvals = sort(@okvals);
14654: if (ref($domconfig{$action}) eq 'HASH') {
14655: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14656: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
14657: if ($inuse == 0) {
14658: $changes{$prefix}{$type} = 1;
14659: } else {
14660: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14661: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
14662: if (@changed > 0) {
14663: $changes{$prefix}{$type} = 1;
14664: }
14665: }
14666: } else {
14667: if ($inuse == 1) {
14668: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14669: $changes{$prefix}{$type} = 1;
14670: }
14671: }
14672: } else {
14673: if ($inuse == 1) {
14674: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14675: $changes{$prefix}{$type} = 1;
14676: }
14677: }
14678: } else {
14679: if ($inuse == 1) {
14680: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14681: $changes{$prefix}{$type} = 1;
14682: }
14683: }
14684: }
14685: }
14686: }
14687: }
14688: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
14689: if (keys(%changes) > 0) {
14690: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14691: $dom);
14692: if ($putresult eq 'ok') {
14693: if (ref($defaultshash{$action}) eq 'HASH') {
14694: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
14695: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
14696: }
1.293 raeburn 14697: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
14698: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
14699: }
14700: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
14701: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 14702: }
14703: }
14704: my $cachetime = 24*60*60;
14705: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14706: if (ref($lastactref) eq 'HASH') {
14707: $lastactref->{'domdefaults'} = 1;
14708: }
14709: if (keys(%changes) > 0) {
14710: my %titles = &ssl_titles();
14711: $resulttext = &mt('Changes made:').'<ul>';
14712: foreach my $prefix (@prefixes) {
14713: if (ref($changes{$prefix}) eq 'HASH') {
14714: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
14715: foreach my $type (@{$types{$prefix}}) {
14716: if (defined($changes{$prefix}{$type})) {
14717: my $newvalue;
14718: if (ref($defaultshash{$action}) eq 'HASH') {
14719: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 14720: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14721: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
14722: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
14723: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
14724: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
14725: }
14726: }
14727: }
14728: if ($newvalue eq '') {
14729: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
14730: } else {
14731: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
14732: }
14733: }
14734: }
14735: }
14736: $resulttext .= '</ul>';
14737: }
14738: }
14739: } else {
14740: $resulttext = $nochgmsg;
14741: }
14742: } else {
14743: $resulttext = '<span class="LC_error">'.
14744: &mt('An error occurred: [_1]',$putresult).'</span>';
14745: }
14746: } else {
14747: $resulttext = $nochgmsg;
14748: }
14749: return $resulttext;
14750: }
14751:
1.279 raeburn 14752: sub modify_trust {
14753: my ($dom,$lastactref,%domconfig) = @_;
14754: my (%by_ip,%by_location,@intdoms,@instdoms);
14755: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14756: my @locations = sort(keys(%by_location));
14757: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
14758: my @types = ('exc','inc');
14759: my (%defaultshash,%changes);
14760: foreach my $prefix (@prefixes) {
14761: $defaultshash{'trust'}{$prefix} = {};
14762: }
14763: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14764: my $resulttext;
14765: foreach my $prefix (@prefixes) {
14766: foreach my $type (@types) {
14767: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14768: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14769: my @okvals;
14770: foreach my $val (@vals) {
14771: if ($val =~ /:/) {
14772: my @items = split(/:/,$val);
14773: foreach my $item (@items) {
14774: if (ref($by_location{$item}) eq 'ARRAY') {
14775: push(@okvals,$item);
14776: }
14777: }
14778: } else {
14779: if (ref($by_location{$val}) eq 'ARRAY') {
14780: push(@okvals,$val);
14781: }
14782: }
14783: }
14784: @okvals = sort(@okvals);
14785: if (ref($domconfig{'trust'}) eq 'HASH') {
14786: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
14787: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14788: if ($inuse == 0) {
14789: $changes{$prefix}{$type} = 1;
14790: } else {
14791: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14792: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
14793: if (@changed > 0) {
14794: $changes{$prefix}{$type} = 1;
14795: }
14796: }
14797: } else {
14798: if ($inuse == 1) {
14799: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14800: $changes{$prefix}{$type} = 1;
14801: }
14802: }
14803: } else {
14804: if ($inuse == 1) {
14805: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14806: $changes{$prefix}{$type} = 1;
14807: }
14808: }
14809: } else {
14810: if ($inuse == 1) {
14811: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14812: $changes{$prefix}{$type} = 1;
14813: }
14814: }
14815: }
14816: }
14817: my $nochgmsg = &mt('No changes made to trust settings.');
14818: if (keys(%changes) > 0) {
14819: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14820: $dom);
14821: if ($putresult eq 'ok') {
14822: if (ref($defaultshash{'trust'}) eq 'HASH') {
14823: foreach my $prefix (@prefixes) {
14824: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
14825: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
14826: }
14827: }
14828: }
14829: my $cachetime = 24*60*60;
14830: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14831: if (ref($lastactref) eq 'HASH') {
14832: $lastactref->{'domdefaults'} = 1;
14833: }
14834: if (keys(%changes) > 0) {
14835: my %lt = &trust_titles();
14836: $resulttext = &mt('Changes made:').'<ul>';
14837: foreach my $prefix (@prefixes) {
14838: if (ref($changes{$prefix}) eq 'HASH') {
14839: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14840: foreach my $type (@types) {
14841: if (defined($changes{$prefix}{$type})) {
14842: my $newvalue;
14843: if (ref($defaultshash{'trust'}) eq 'HASH') {
14844: if (ref($defaultshash{'trust'}{$prefix})) {
14845: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14846: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
14847: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
14848: }
14849: }
14850: }
14851: }
14852: if ($newvalue eq '') {
14853: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14854: } else {
14855: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
14856: }
14857: }
14858: }
14859: $resulttext .= '</ul>';
14860: }
14861: }
14862: $resulttext .= '</ul>';
14863: } else {
14864: $resulttext = $nochgmsg;
14865: }
14866: } else {
14867: $resulttext = '<span class="LC_error">'.
14868: &mt('An error occurred: [_1]',$putresult).'</span>';
14869: }
14870: } else {
14871: $resulttext = $nochgmsg;
14872: }
14873: return $resulttext;
14874: }
14875:
1.150 raeburn 14876: sub modify_loadbalancing {
14877: my ($dom,%domconfig) = @_;
14878: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14879: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14880: my ($othertitle,$usertypes,$types) =
14881: &Apache::loncommon::sorted_inst_types($dom);
14882: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 14883: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 14884: my @sparestypes = ('primary','default');
14885: my %typetitles = &sparestype_titles();
14886: my $resulttext;
1.171 raeburn 14887: my (%currbalancer,%currtargets,%currrules,%existing);
14888: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14889: %existing = %{$domconfig{'loadbalancing'}};
14890: }
14891: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
14892: \%currtargets,\%currrules);
14893: my ($saveloadbalancing,%defaultshash,%changes);
14894: my ($alltypes,$othertypes,$titles) =
14895: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14896: my %ruletitles = &offloadtype_text();
14897: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14898: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14899: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14900: if ($balancer eq '') {
14901: next;
14902: }
1.210 raeburn 14903: if (!exists($servers{$balancer})) {
1.171 raeburn 14904: if (exists($currbalancer{$balancer})) {
14905: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14906: }
1.171 raeburn 14907: next;
14908: }
14909: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14910: push(@{$changes{'delete'}},$balancer);
14911: next;
14912: }
14913: if (!exists($currbalancer{$balancer})) {
14914: push(@{$changes{'add'}},$balancer);
14915: }
14916: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14917: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14918: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14919: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14920: $saveloadbalancing = 1;
14921: }
14922: foreach my $sparetype (@sparestypes) {
14923: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14924: my @offloadto;
14925: foreach my $target (@targets) {
14926: if (($servers{$target}) && ($target ne $balancer)) {
14927: if ($sparetype eq 'default') {
14928: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14929: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14930: }
14931: }
1.171 raeburn 14932: unless(grep(/^\Q$target\E$/,@offloadto)) {
14933: push(@offloadto,$target);
14934: }
1.150 raeburn 14935: }
14936: }
1.284 raeburn 14937: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14938: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14939: push(@offloadto,$balancer);
14940: }
14941: }
14942: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14943: }
1.171 raeburn 14944: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14945: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14946: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14947: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14948: if (@targetdiffs > 0) {
1.171 raeburn 14949: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14950: }
1.171 raeburn 14951: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14952: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14953: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14954: }
14955: }
14956: }
14957: } else {
1.171 raeburn 14958: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 14959: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14960: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14961: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14962: $changes{'curr'}{$balancer}{'targets'} = 1;
14963: }
1.150 raeburn 14964: }
14965: }
1.210 raeburn 14966: }
1.150 raeburn 14967: }
14968: my $ishomedom;
1.171 raeburn 14969: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14970: $ishomedom = 1;
1.150 raeburn 14971: }
14972: if (ref($alltypes) eq 'ARRAY') {
14973: foreach my $type (@{$alltypes}) {
14974: my $rule;
1.210 raeburn 14975: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14976: (!$ishomedom)) {
1.171 raeburn 14977: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14978: }
14979: if ($rule eq 'specific') {
1.255 raeburn 14980: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 14981: if (exists($servers{$specifiedhost})) {
1.255 raeburn 14982: $rule = $specifiedhost;
14983: }
1.150 raeburn 14984: }
1.171 raeburn 14985: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14986: if (ref($currrules{$balancer}) eq 'HASH') {
14987: if ($rule ne $currrules{$balancer}{$type}) {
14988: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14989: }
14990: } elsif ($rule ne '') {
1.171 raeburn 14991: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14992: }
14993: }
14994: }
1.171 raeburn 14995: }
14996: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14997: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14998: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14999: $defaultshash{'loadbalancing'} = {};
15000: }
15001: my $putresult = &Apache::lonnet::put_dom('configuration',
15002: \%defaultshash,$dom);
15003: if ($putresult eq 'ok') {
15004: if (keys(%changes) > 0) {
1.252 raeburn 15005: my %toupdate;
1.171 raeburn 15006: if (ref($changes{'delete'}) eq 'ARRAY') {
15007: foreach my $balancer (sort(@{$changes{'delete'}})) {
15008: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 15009: $toupdate{$balancer} = 1;
1.150 raeburn 15010: }
1.171 raeburn 15011: }
15012: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 15013: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 15014: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 15015: $toupdate{$balancer} = 1;
1.171 raeburn 15016: }
15017: }
15018: if (ref($changes{'curr'}) eq 'HASH') {
15019: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 15020: $toupdate{$balancer} = 1;
1.171 raeburn 15021: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
15022: if ($changes{'curr'}{$balancer}{'targets'}) {
15023: my %offloadstr;
15024: foreach my $sparetype (@sparestypes) {
15025: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15026: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15027: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15028: }
15029: }
1.150 raeburn 15030: }
1.171 raeburn 15031: if (keys(%offloadstr) == 0) {
15032: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 15033: } else {
1.171 raeburn 15034: my $showoffload;
15035: foreach my $sparetype (@sparestypes) {
15036: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
15037: if (defined($offloadstr{$sparetype})) {
15038: $showoffload .= $offloadstr{$sparetype};
15039: } else {
15040: $showoffload .= &mt('None');
15041: }
15042: $showoffload .= (' 'x3);
15043: }
15044: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 15045: }
15046: }
15047: }
1.171 raeburn 15048: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
15049: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
15050: foreach my $type (@{$alltypes}) {
15051: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
15052: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
15053: my $balancetext;
15054: if ($rule eq '') {
15055: $balancetext = $ruletitles{'default'};
1.209 raeburn 15056: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 15057: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 15058: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 15059: foreach my $sparetype (@sparestypes) {
15060: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15061: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15062: }
15063: }
1.253 raeburn 15064: foreach my $item (@{$alltypes}) {
15065: next if ($item =~ /^_LC_ipchange/);
15066: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
15067: if ($hasrule eq 'homeserver') {
15068: map { $toupdate{$_} = 1; } (keys(%libraryservers));
15069: } else {
15070: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
15071: if ($servers{$hasrule}) {
15072: $toupdate{$hasrule} = 1;
15073: }
15074: }
15075: }
15076: }
1.254 raeburn 15077: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
15078: $balancetext = $ruletitles{$rule};
15079: } else {
15080: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
15081: $balancetext = $ruletitles{'particular'}.' '.$receiver;
15082: if ($receiver) {
15083: $toupdate{$receiver};
15084: }
15085: }
15086: } else {
15087: $balancetext = $ruletitles{$rule};
1.252 raeburn 15088: }
1.171 raeburn 15089: } else {
15090: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
15091: }
1.210 raeburn 15092: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 15093: }
15094: }
15095: }
15096: }
1.252 raeburn 15097: if (keys(%toupdate)) {
15098: my %thismachine;
15099: my $updatedhere;
15100: my $cachetime = 60*60*24;
15101: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
15102: foreach my $lonhost (keys(%toupdate)) {
15103: if ($thismachine{$lonhost}) {
15104: unless ($updatedhere) {
15105: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
15106: $defaultshash{'loadbalancing'},
15107: $cachetime);
15108: $updatedhere = 1;
15109: }
15110: } else {
15111: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
15112: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
15113: }
15114: }
15115: }
1.150 raeburn 15116: }
1.171 raeburn 15117: }
15118: if ($resulttext ne '') {
15119: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 15120: } else {
15121: $resulttext = $nochgmsg;
15122: }
15123: } else {
1.171 raeburn 15124: $resulttext = $nochgmsg;
1.150 raeburn 15125: }
15126: } else {
1.171 raeburn 15127: $resulttext = '<span class="LC_error">'.
15128: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 15129: }
15130: } else {
1.171 raeburn 15131: $resulttext = $nochgmsg;
1.150 raeburn 15132: }
15133: return $resulttext;
15134: }
15135:
1.48 raeburn 15136: sub recurse_check {
15137: my ($chkcats,$categories,$depth,$name) = @_;
15138: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
15139: my $chg = 0;
15140: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
15141: my $category = $chkcats->[$depth]{$name}[$j];
15142: my $item;
15143: if ($category eq '') {
15144: $chg ++;
15145: } else {
15146: my $deeper = $depth + 1;
15147: $item = &escape($category).':'.&escape($name).':'.$depth;
15148: if ($chg) {
15149: $categories->{$item} -= $chg;
15150: }
15151: &recurse_check($chkcats,$categories,$deeper,$category);
15152: $deeper --;
15153: }
15154: }
15155: }
15156: return;
15157: }
15158:
15159: sub recurse_cat_deletes {
15160: my ($item,$coursecategories,$deletions) = @_;
15161: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15162: my $subdepth = $depth + 1;
15163: if (ref($coursecategories) eq 'HASH') {
15164: foreach my $subitem (keys(%{$coursecategories})) {
15165: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
15166: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
15167: delete($coursecategories->{$subitem});
15168: $deletions->{$subitem} = 1;
15169: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 15170: }
1.48 raeburn 15171: }
15172: }
15173: return;
15174: }
15175:
1.125 raeburn 15176: sub active_dc_picker {
1.191 raeburn 15177: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 15178: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 15179: my @domcoord = keys(%domcoords);
15180: if (keys(%currhash)) {
15181: foreach my $dc (keys(%currhash)) {
15182: unless (exists($domcoords{$dc})) {
15183: push(@domcoord,$dc);
15184: }
15185: }
15186: }
15187: @domcoord = sort(@domcoord);
1.210 raeburn 15188: my $numdcs = scalar(@domcoord);
1.191 raeburn 15189: my $rows = 0;
15190: my $table;
1.125 raeburn 15191: if ($numdcs > 1) {
1.191 raeburn 15192: $table = '<table>';
15193: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 15194: my $rem = $i%($numinrow);
15195: if ($rem == 0) {
15196: if ($i > 0) {
1.191 raeburn 15197: $table .= '</tr>';
1.125 raeburn 15198: }
1.191 raeburn 15199: $table .= '<tr>';
15200: $rows ++;
1.125 raeburn 15201: }
1.191 raeburn 15202: my $check = '';
15203: if ($inputtype eq 'radio') {
15204: if (keys(%currhash) == 0) {
15205: if (!$i) {
15206: $check = ' checked="checked"';
15207: }
15208: } elsif (exists($currhash{$domcoord[$i]})) {
15209: $check = ' checked="checked"';
15210: }
15211: } else {
15212: if (exists($currhash{$domcoord[$i]})) {
15213: $check = ' checked="checked"';
1.125 raeburn 15214: }
15215: }
1.191 raeburn 15216: if ($i == @domcoord - 1) {
1.125 raeburn 15217: my $colsleft = $numinrow - $rem;
15218: if ($colsleft > 1) {
1.191 raeburn 15219: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 15220: } else {
1.191 raeburn 15221: $table .= '<td class="LC_left_item">';
1.125 raeburn 15222: }
15223: } else {
1.191 raeburn 15224: $table .= '<td class="LC_left_item">';
15225: }
15226: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
15227: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
15228: $table .= '<span class="LC_nobreak"><label>'.
15229: '<input type="'.$inputtype.'" name="'.$name.'"'.
15230: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
15231: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 15232: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 15233: }
1.219 raeburn 15234: $table .= '</label></span></td>';
1.191 raeburn 15235: }
15236: $table .= '</tr></table>';
15237: } elsif ($numdcs == 1) {
1.219 raeburn 15238: my ($dcname,$dcdom) = split(':',$domcoord[0]);
15239: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 15240: if ($inputtype eq 'radio') {
1.247 raeburn 15241: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 15242: if ($user ne $dcname.':'.$dcdom) {
15243: $table .= ' ('.$dcname.':'.$dcdom.')';
15244: }
1.191 raeburn 15245: } else {
15246: my $check;
15247: if (exists($currhash{$domcoord[0]})) {
15248: $check = ' checked="checked"';
1.125 raeburn 15249: }
1.247 raeburn 15250: $table = '<span class="LC_nobreak"><label>'.
15251: '<input type="checkbox" name="'.$name.'" '.
15252: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 15253: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 15254: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 15255: }
1.220 raeburn 15256: $table .= '</label></span>';
1.191 raeburn 15257: $rows ++;
1.125 raeburn 15258: }
15259: }
1.191 raeburn 15260: return ($numdcs,$table,$rows);
1.125 raeburn 15261: }
15262:
1.137 raeburn 15263: sub usersession_titles {
15264: return &Apache::lonlocal::texthash(
15265: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
15266: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 15267: spares => 'Servers offloaded to, when busy',
1.137 raeburn 15268: version => 'LON-CAPA version requirement',
1.138 raeburn 15269: excludedomain => 'Allow all, but exclude specific domains',
15270: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 15271: primary => 'Primary (checked first)',
1.154 raeburn 15272: default => 'Default',
1.137 raeburn 15273: );
15274: }
15275:
1.152 raeburn 15276: sub id_for_thisdom {
15277: my (%servers) = @_;
15278: my %altids;
15279: foreach my $server (keys(%servers)) {
15280: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
15281: if ($serverhome ne $server) {
15282: $altids{$serverhome} = $server;
15283: }
15284: }
15285: return %altids;
15286: }
15287:
1.150 raeburn 15288: sub count_servers {
15289: my ($currbalancer,%servers) = @_;
15290: my (@spares,$numspares);
15291: foreach my $lonhost (sort(keys(%servers))) {
15292: next if ($currbalancer eq $lonhost);
15293: push(@spares,$lonhost);
15294: }
15295: if ($currbalancer) {
15296: $numspares = scalar(@spares);
15297: } else {
15298: $numspares = scalar(@spares) - 1;
15299: }
15300: return ($numspares,@spares);
15301: }
15302:
15303: sub lonbalance_targets_js {
1.171 raeburn 15304: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 15305: my $select = &mt('Select');
15306: my ($alltargets,$allishome,$allinsttypes,@alltypes);
15307: if (ref($servers) eq 'HASH') {
15308: $alltargets = join("','",sort(keys(%{$servers})));
15309: my @homedoms;
15310: foreach my $server (sort(keys(%{$servers}))) {
15311: if (&Apache::lonnet::host_domain($server) eq $dom) {
15312: push(@homedoms,'1');
15313: } else {
15314: push(@homedoms,'0');
15315: }
15316: }
15317: $allishome = join("','",@homedoms);
15318: }
15319: if (ref($types) eq 'ARRAY') {
15320: if (@{$types} > 0) {
15321: @alltypes = @{$types};
15322: }
15323: }
15324: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
15325: $allinsttypes = join("','",@alltypes);
1.171 raeburn 15326: my (%currbalancer,%currtargets,%currrules,%existing);
15327: if (ref($settings) eq 'HASH') {
15328: %existing = %{$settings};
15329: }
15330: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
15331: \%currtargets,\%currrules);
1.210 raeburn 15332: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 15333: return <<"END";
15334:
15335: <script type="text/javascript">
15336: // <![CDATA[
15337:
1.171 raeburn 15338: currBalancers = new Array('$balancers');
15339:
15340: function toggleTargets(balnum) {
15341: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15342: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
15343: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
15344: var prevbalancer = prevhostitem.value;
15345: var baltotal = document.getElementById('loadbalancing_total').value;
15346: prevhostitem.value = balancer;
15347: if (prevbalancer != '') {
15348: var prevIdx = currBalancers.indexOf(prevbalancer);
15349: if (prevIdx != -1) {
15350: currBalancers.splice(prevIdx,1);
15351: }
15352: }
1.150 raeburn 15353: if (balancer == '') {
1.171 raeburn 15354: hideSpares(balnum);
1.150 raeburn 15355: } else {
1.171 raeburn 15356: var currIdx = currBalancers.indexOf(balancer);
15357: if (currIdx == -1) {
15358: currBalancers.push(balancer);
15359: }
1.150 raeburn 15360: var homedoms = new Array('$allishome');
1.171 raeburn 15361: var ishomedom = homedoms[lonhostitem.selectedIndex];
15362: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 15363: }
1.171 raeburn 15364: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 15365: return;
15366: }
15367:
1.171 raeburn 15368: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 15369: var alltargets = new Array('$alltargets');
15370: var insttypes = new Array('$allinsttypes');
1.151 raeburn 15371: var offloadtypes = new Array('primary','default');
15372:
1.171 raeburn 15373: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
15374: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 15375:
1.151 raeburn 15376: for (var i=0; i<offloadtypes.length; i++) {
15377: var count = 0;
15378: for (var j=0; j<alltargets.length; j++) {
15379: if (alltargets[j] != balancer) {
1.171 raeburn 15380: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
15381: item.value = alltargets[j];
15382: item.style.textAlign='left';
15383: item.style.textFace='normal';
15384: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
15385: if (currBalancers.indexOf(alltargets[j]) == -1) {
15386: item.disabled = '';
15387: } else {
15388: item.disabled = 'disabled';
15389: item.checked = false;
15390: }
1.151 raeburn 15391: count ++;
15392: }
1.150 raeburn 15393: }
15394: }
1.151 raeburn 15395: for (var k=0; k<insttypes.length; k++) {
15396: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 15397: if (ishomedom == 1) {
1.171 raeburn 15398: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15399: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15400: } else {
1.171 raeburn 15401: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15402: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 15403: }
15404: } else {
1.171 raeburn 15405: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15406: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15407: }
1.151 raeburn 15408: if ((insttypes[k] != '_LC_external') &&
15409: ((insttypes[k] != '_LC_internetdom') ||
15410: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 15411: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
15412: item.options.length = 0;
15413: item.options[0] = new Option("","",true,true);
1.210 raeburn 15414: var idx = 0;
1.151 raeburn 15415: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 15416: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
15417: idx ++;
15418: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 15419: }
15420: }
15421: }
15422: }
15423: return;
15424: }
15425:
1.171 raeburn 15426: function hideSpares(balnum) {
1.150 raeburn 15427: var alltargets = new Array('$alltargets');
15428: var insttypes = new Array('$allinsttypes');
15429: var offloadtypes = new Array('primary','default');
15430:
1.171 raeburn 15431: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
15432: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 15433:
15434: var total = alltargets.length - 1;
15435: for (var i=0; i<offloadtypes; i++) {
15436: for (var j=0; j<total; j++) {
1.171 raeburn 15437: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
15438: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
15439: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 15440: }
1.150 raeburn 15441: }
15442: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 15443: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15444: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 15445: if (insttypes[k] != '_LC_external') {
1.171 raeburn 15446: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
15447: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 15448: }
15449: }
15450: return;
15451: }
15452:
1.171 raeburn 15453: function checkOffloads(item,balnum,type) {
1.150 raeburn 15454: var alltargets = new Array('$alltargets');
15455: var offloadtypes = new Array('primary','default');
15456: if (item.checked) {
15457: var total = alltargets.length - 1;
15458: var other;
15459: if (type == offloadtypes[0]) {
1.151 raeburn 15460: other = offloadtypes[1];
1.150 raeburn 15461: } else {
1.151 raeburn 15462: other = offloadtypes[0];
1.150 raeburn 15463: }
15464: for (var i=0; i<total; i++) {
1.171 raeburn 15465: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 15466: if (server == item.value) {
1.171 raeburn 15467: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
15468: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 15469: }
15470: }
15471: }
15472: }
15473: return;
15474: }
15475:
1.171 raeburn 15476: function singleServerToggle(balnum,type) {
15477: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 15478: if (offloadtoSelIdx == 0) {
1.171 raeburn 15479: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
15480: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15481:
15482: } else {
1.171 raeburn 15483: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
15484: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 15485: }
15486: return;
15487: }
15488:
1.171 raeburn 15489: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 15490: if (type == '_LC_external') {
1.171 raeburn 15491: return;
1.150 raeburn 15492: }
1.171 raeburn 15493: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 15494: for (var i=0; i<typesRules.length; i++) {
15495: if (formname.elements[typesRules[i]].checked) {
15496: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 15497: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
15498: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15499: } else {
1.171 raeburn 15500: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
15501: }
15502: }
15503: }
15504: return;
15505: }
15506:
15507: function balancerDeleteChange(balnum) {
15508: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15509: var baltotal = document.getElementById('loadbalancing_total').value;
15510: var addtarget;
15511: var removetarget;
15512: var action = 'delete';
15513: if (document.getElementById('loadbalancing_delete_'+balnum)) {
15514: var lonhost = hostitem.value;
15515: var currIdx = currBalancers.indexOf(lonhost);
15516: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
15517: if (currIdx != -1) {
15518: currBalancers.splice(currIdx,1);
15519: }
15520: addtarget = lonhost;
15521: } else {
15522: if (currIdx == -1) {
15523: currBalancers.push(lonhost);
15524: }
15525: removetarget = lonhost;
15526: action = 'undelete';
15527: }
15528: balancerChange(balnum,baltotal,action,addtarget,removetarget);
15529: }
15530: return;
15531: }
15532:
15533: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
15534: if (baltotal > 1) {
15535: var offloadtypes = new Array('primary','default');
15536: var alltargets = new Array('$alltargets');
15537: var insttypes = new Array('$allinsttypes');
15538: for (var i=0; i<baltotal; i++) {
15539: if (i != balnum) {
15540: for (var j=0; j<offloadtypes.length; j++) {
15541: var total = alltargets.length - 1;
15542: for (var k=0; k<total; k++) {
15543: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
15544: var server = serveritem.value;
15545: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15546: if (server == addtarget) {
15547: serveritem.disabled = '';
15548: }
15549: }
15550: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15551: if (server == removetarget) {
15552: serveritem.disabled = 'disabled';
15553: serveritem.checked = false;
15554: }
15555: }
15556: }
15557: }
15558: for (var j=0; j<insttypes.length; j++) {
15559: if (insttypes[j] != '_LC_external') {
15560: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
15561: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
15562: var currSel = singleserver.selectedIndex;
15563: var currVal = singleserver.options[currSel].value;
15564: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15565: var numoptions = singleserver.options.length;
15566: var needsnew = 1;
15567: for (var k=0; k<numoptions; k++) {
15568: if (singleserver.options[k] == addtarget) {
15569: needsnew = 0;
15570: break;
15571: }
15572: }
15573: if (needsnew == 1) {
15574: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
15575: }
15576: }
15577: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15578: singleserver.options.length = 0;
15579: if ((currVal) && (currVal != removetarget)) {
15580: singleserver.options[0] = new Option("","",false,false);
15581: } else {
15582: singleserver.options[0] = new Option("","",true,true);
15583: }
15584: var idx = 0;
15585: for (var m=0; m<alltargets.length; m++) {
15586: if (currBalancers.indexOf(alltargets[m]) == -1) {
15587: idx ++;
15588: if (currVal == alltargets[m]) {
15589: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
15590: } else {
15591: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
15592: }
15593: }
15594: }
15595: }
15596: }
15597: }
15598: }
1.150 raeburn 15599: }
15600: }
15601: }
15602: return;
15603: }
15604:
1.152 raeburn 15605: // ]]>
15606: </script>
15607:
15608: END
15609: }
15610:
15611: sub new_spares_js {
15612: my @sparestypes = ('primary','default');
15613: my $types = join("','",@sparestypes);
15614: my $select = &mt('Select');
15615: return <<"END";
15616:
15617: <script type="text/javascript">
15618: // <![CDATA[
15619:
15620: function updateNewSpares(formname,lonhost) {
15621: var types = new Array('$types');
15622: var include = new Array();
15623: var exclude = new Array();
15624: for (var i=0; i<types.length; i++) {
15625: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
15626: for (var j=0; j<spareboxes.length; j++) {
15627: if (formname.elements[spareboxes[j]].checked) {
15628: exclude.push(formname.elements[spareboxes[j]].value);
15629: } else {
15630: include.push(formname.elements[spareboxes[j]].value);
15631: }
15632: }
15633: }
15634: for (var i=0; i<types.length; i++) {
15635: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
15636: var selIdx = newSpare.selectedIndex;
15637: var currnew = newSpare.options[selIdx].value;
15638: var okSpares = new Array();
15639: for (var j=0; j<newSpare.options.length; j++) {
15640: var possible = newSpare.options[j].value;
15641: if (possible != '') {
15642: if (exclude.indexOf(possible) == -1) {
15643: okSpares.push(possible);
15644: } else {
15645: if (currnew == possible) {
15646: selIdx = 0;
15647: }
15648: }
15649: }
15650: }
15651: for (var k=0; k<include.length; k++) {
15652: if (okSpares.indexOf(include[k]) == -1) {
15653: okSpares.push(include[k]);
15654: }
15655: }
15656: okSpares.sort();
15657: newSpare.options.length = 0;
15658: if (selIdx == 0) {
15659: newSpare.options[0] = new Option("$select","",true,true);
15660: } else {
15661: newSpare.options[0] = new Option("$select","",false,false);
15662: }
15663: for (var m=0; m<okSpares.length; m++) {
15664: var idx = m+1;
15665: var selThis = 0;
15666: if (selIdx != 0) {
15667: if (okSpares[m] == currnew) {
15668: selThis = 1;
15669: }
15670: }
15671: if (selThis == 1) {
15672: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
15673: } else {
15674: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15675: }
15676: }
15677: }
15678: return;
15679: }
15680:
15681: function checkNewSpares(lonhost,type) {
15682: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15683: var chosen = newSpare.options[newSpare.selectedIndex].value;
15684: if (chosen != '') {
15685: var othertype;
15686: var othernewSpare;
15687: if (type == 'primary') {
15688: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15689: }
15690: if (type == 'default') {
15691: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15692: }
15693: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15694: othernewSpare.selectedIndex = 0;
15695: }
15696: }
15697: return;
15698: }
15699:
15700: // ]]>
15701: </script>
15702:
15703: END
15704:
15705: }
15706:
15707: sub common_domprefs_js {
15708: return <<"END";
15709:
15710: <script type="text/javascript">
15711: // <![CDATA[
15712:
1.150 raeburn 15713: function getIndicesByName(formname,item) {
1.152 raeburn 15714: var group = new Array();
1.150 raeburn 15715: for (var i=0;i<formname.elements.length;i++) {
15716: if (formname.elements[i].name == item) {
1.152 raeburn 15717: group.push(formname.elements[i].id);
1.150 raeburn 15718: }
15719: }
1.152 raeburn 15720: return group;
1.150 raeburn 15721: }
15722:
15723: // ]]>
15724: </script>
15725:
15726: END
1.152 raeburn 15727:
1.150 raeburn 15728: }
15729:
1.165 raeburn 15730: sub recaptcha_js {
15731: my %lt = &captcha_phrases();
15732: return <<"END";
15733:
15734: <script type="text/javascript">
15735: // <![CDATA[
15736:
15737: function updateCaptcha(caller,context) {
15738: var privitem;
15739: var pubitem;
15740: var privtext;
15741: var pubtext;
1.269 raeburn 15742: var versionitem;
15743: var versiontext;
1.165 raeburn 15744: if (document.getElementById(context+'_recaptchapub')) {
15745: pubitem = document.getElementById(context+'_recaptchapub');
15746: } else {
15747: return;
15748: }
15749: if (document.getElementById(context+'_recaptchapriv')) {
15750: privitem = document.getElementById(context+'_recaptchapriv');
15751: } else {
15752: return;
15753: }
15754: if (document.getElementById(context+'_recaptchapubtxt')) {
15755: pubtext = document.getElementById(context+'_recaptchapubtxt');
15756: } else {
15757: return;
15758: }
15759: if (document.getElementById(context+'_recaptchaprivtxt')) {
15760: privtext = document.getElementById(context+'_recaptchaprivtxt');
15761: } else {
15762: return;
15763: }
1.269 raeburn 15764: if (document.getElementById(context+'_recaptchaversion')) {
15765: versionitem = document.getElementById(context+'_recaptchaversion');
15766: } else {
15767: return;
15768: }
15769: if (document.getElementById(context+'_recaptchavertxt')) {
15770: versiontext = document.getElementById(context+'_recaptchavertxt');
15771: } else {
15772: return;
15773: }
1.165 raeburn 15774: if (caller.checked) {
15775: if (caller.value == 'recaptcha') {
15776: pubitem.type = 'text';
15777: privitem.type = 'text';
15778: pubitem.size = '40';
15779: privitem.size = '40';
15780: pubtext.innerHTML = "$lt{'pub'}";
15781: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 15782: versionitem.type = 'text';
15783: versionitem.size = '3';
1.289 raeburn 15784: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 15785: } else {
15786: pubitem.type = 'hidden';
15787: privitem.type = 'hidden';
1.269 raeburn 15788: versionitem.type = 'hidden';
1.165 raeburn 15789: pubtext.innerHTML = '';
15790: privtext.innerHTML = '';
1.269 raeburn 15791: versiontext.innerHTML = '';
1.165 raeburn 15792: }
15793: }
15794: return;
15795: }
15796:
15797: // ]]>
15798: </script>
15799:
15800: END
15801:
15802: }
15803:
1.236 raeburn 15804: sub toggle_display_js {
1.192 raeburn 15805: return <<"END";
15806:
15807: <script type="text/javascript">
15808: // <![CDATA[
15809:
1.236 raeburn 15810: function toggleDisplay(domForm,caller) {
15811: if (document.getElementById(caller)) {
15812: var divitem = document.getElementById(caller);
15813: var optionsElement = domForm.coursecredits;
1.264 raeburn 15814: var checkval = 1;
15815: var dispval = 'block';
1.303 raeburn 15816: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 15817: if (caller == 'emailoptions') {
15818: optionsElement = domForm.cancreate_email;
15819: }
1.257 raeburn 15820: if (caller == 'studentsubmission') {
15821: optionsElement = domForm.postsubmit;
15822: }
1.264 raeburn 15823: if (caller == 'cloneinstcode') {
15824: optionsElement = domForm.canclone;
15825: checkval = 'instcode';
15826: }
1.303 raeburn 15827: if (selfcreateRegExp.test(caller)) {
15828: optionsElement = domForm.elements[caller];
15829: checkval = 'other';
15830: dispval = 'inline'
15831: }
1.236 raeburn 15832: if (optionsElement.length) {
1.192 raeburn 15833: var currval;
1.236 raeburn 15834: for (var i=0; i<optionsElement.length; i++) {
15835: if (optionsElement[i].checked) {
15836: currval = optionsElement[i].value;
1.192 raeburn 15837: }
15838: }
1.264 raeburn 15839: if (currval == checkval) {
15840: divitem.style.display = dispval;
1.192 raeburn 15841: } else {
1.236 raeburn 15842: divitem.style.display = 'none';
1.192 raeburn 15843: }
15844: }
15845: }
15846: return;
15847: }
15848:
15849: // ]]>
15850: </script>
15851:
15852: END
15853:
15854: }
15855:
1.165 raeburn 15856: sub captcha_phrases {
15857: return &Apache::lonlocal::texthash (
15858: priv => 'Private key',
15859: pub => 'Public key',
15860: original => 'original (CAPTCHA)',
15861: recaptcha => 'successor (ReCAPTCHA)',
15862: notused => 'unused',
1.289 raeburn 15863: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 15864: );
15865: }
15866:
1.205 raeburn 15867: sub devalidate_remote_domconfs {
1.212 raeburn 15868: my ($dom,$cachekeys) = @_;
15869: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 15870: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15871: my %thismachine;
15872: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 15873: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 15874: if (keys(%servers)) {
1.205 raeburn 15875: foreach my $server (keys(%servers)) {
15876: next if ($thismachine{$server});
1.212 raeburn 15877: my @cached;
15878: foreach my $name (@posscached) {
15879: if ($cachekeys->{$name}) {
15880: push(@cached,&escape($name).':'.&escape($dom));
15881: }
15882: }
15883: if (@cached) {
15884: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15885: }
1.205 raeburn 15886: }
15887: }
15888: return;
15889: }
15890:
1.3 raeburn 15891: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>