Annotation of loncom/interface/domainprefs.pm, revision 1.309
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.309 ! raeburn 4: # $Id: domainprefs.pm,v 1.308 2017/08/15 21:02:40 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: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 7647: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7648: '<td class="LC_left_item" colspan="2"><table>';
7649: my $rem;
7650: my %checks;
7651: if (ref($settings) eq 'HASH') {
7652: if (ref($settings->{$context}) eq 'HASH') {
7653: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 7654: my $hashref = $settings->{$context}->{$role};
7655: if ($role eq 'emailusername') {
7656: if ($statustype) {
7657: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7658: $hashref = $settings->{$context}->{$role}->{$statustype};
7659: if (ref($hashref) eq 'HASH') {
7660: foreach my $field (@fields) {
7661: if ($hashref->{$field}) {
7662: $checks{$field} = $hashref->{$field};
7663: }
7664: }
7665: }
7666: }
7667: }
7668: } else {
7669: if (ref($hashref) eq 'HASH') {
7670: foreach my $field (@fields) {
7671: if ($hashref->{$field}) {
7672: $checks{$field} = ' checked="checked" ';
7673: }
7674: }
1.33 raeburn 7675: }
7676: }
7677: }
7678: }
7679: }
1.305 raeburn 7680:
7681: my $total = scalar(@fields);
7682: for (my $i=0; $i<$total; $i++) {
7683: $rem = $i%($numinrow);
1.33 raeburn 7684: if ($rem == 0) {
7685: if ($i > 0) {
7686: $output .= '</tr>';
7687: }
7688: $output .= '<tr>';
7689: }
7690: my $check = ' ';
1.228 raeburn 7691: unless ($role eq 'emailusername') {
7692: if (exists($checks{$fields[$i]})) {
7693: $check = $checks{$fields[$i]}
7694: } else {
7695: if ($role eq 'st') {
7696: if (ref($settings) ne 'HASH') {
7697: $check = ' checked="checked" ';
7698: }
1.33 raeburn 7699: }
7700: }
7701: }
7702: $output .= '<td class="LC_left_item">'.
1.228 raeburn 7703: '<span class="LC_nobreak">';
7704: if ($role eq 'emailusername') {
7705: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7706: $checks{$fields[$i]} = 'omit';
7707: }
7708: foreach my $option ('required','optional','omit') {
7709: my $checked='';
7710: if ($checks{$fields[$i]} eq $option) {
7711: $checked='checked="checked" ';
7712: }
7713: $output .= '<label>'.
7714: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7715: &mt($option).'</label>'.(' ' x2);
7716: }
7717: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7718: } else {
7719: $output .= '<label>'.
7720: '<input type="checkbox" name="canmodify_'.$role.'" '.
7721: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7722: '</label>';
7723: }
7724: $output .= '</span></td>';
1.33 raeburn 7725: }
1.305 raeburn 7726: $rem = $total%$numinrow;
7727: my $colsleft;
7728: if ($rem) {
7729: $colsleft = $numinrow - $rem;
7730: }
7731: if ($colsleft > 1) {
1.33 raeburn 7732: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7733: ' </td>';
7734: } elsif ($colsleft == 1) {
7735: $output .= '<td class="LC_left_item"> </td>';
7736: }
7737: $output .= '</tr></table></td></tr>';
7738: return $output;
7739: }
1.28 raeburn 7740:
1.93 raeburn 7741: sub insttypes_row {
1.305 raeburn 7742: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
7743: $customcss,$rowstyle) = @_;
1.93 raeburn 7744: my %lt = &Apache::lonlocal::texthash (
7745: cansearch => 'Users allowed to search',
7746: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7747: lockablenames => 'User preference to lock name',
1.305 raeburn 7748: selfassign => 'Self-reportable affiliations',
1.93 raeburn 7749: );
7750: my $showdom;
7751: if ($context eq 'cansearch') {
7752: $showdom = ' ('.$dom.')';
7753: }
1.165 raeburn 7754: my $class = 'LC_left_item';
7755: if ($context eq 'statustocreate') {
7756: $class = 'LC_right_item';
7757: }
1.305 raeburn 7758: my $css_class;
7759: if ($$rowtotal%2) {
7760: $css_class = 'LC_odd_row';
7761: }
7762: if ($customcss) {
7763: $css_class .= ' '.$customcss;
7764: }
7765: $css_class =~ s/^\s+//;
7766: if ($css_class) {
7767: $css_class = ' class="'.$css_class.'"';
7768: }
7769: if ($rowstyle) {
7770: $css_class .= ' style="'.$rowstyle.'"';
7771: }
7772: if ($onclick) {
7773: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 7774: }
7775: my $output = '<tr'.$css_class.'>'.
7776: '<td>'.$lt{$context}.$showdom.
7777: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7778: my $rem;
7779: if (ref($types) eq 'ARRAY') {
7780: for (my $i=0; $i<@{$types}; $i++) {
7781: if (defined($usertypes->{$types->[$i]})) {
7782: my $rem = $i%($numinrow);
7783: if ($rem == 0) {
7784: if ($i > 0) {
7785: $output .= '</tr>';
7786: }
7787: $output .= '<tr>';
1.23 raeburn 7788: }
1.26 raeburn 7789: my $check = ' ';
1.99 raeburn 7790: if (ref($settings) eq 'HASH') {
7791: if (ref($settings->{$context}) eq 'ARRAY') {
7792: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7793: $check = ' checked="checked" ';
7794: }
7795: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7796: $check = ' checked="checked" ';
7797: }
1.23 raeburn 7798: }
1.26 raeburn 7799: $output .= '<td class="LC_left_item">'.
7800: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7801: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 7802: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 7803: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7804: }
7805: }
1.26 raeburn 7806: $rem = @{$types}%($numinrow);
1.23 raeburn 7807: }
7808: my $colsleft = $numinrow - $rem;
1.131 raeburn 7809: if (($rem == 0) && (@{$types} > 0)) {
7810: $output .= '<tr>';
7811: }
1.23 raeburn 7812: if ($colsleft > 1) {
1.25 raeburn 7813: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7814: } else {
1.25 raeburn 7815: $output .= '<td class="LC_left_item">';
1.23 raeburn 7816: }
7817: my $defcheck = ' ';
1.99 raeburn 7818: if (ref($settings) eq 'HASH') {
7819: if (ref($settings->{$context}) eq 'ARRAY') {
7820: if (grep(/^default$/,@{$settings->{$context}})) {
7821: $defcheck = ' checked="checked" ';
7822: }
7823: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7824: $defcheck = ' checked="checked" ';
7825: }
1.23 raeburn 7826: }
1.25 raeburn 7827: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7828: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 7829: 'value="default"'.$defcheck.$onclick.' />'.
1.25 raeburn 7830: $othertitle.'</label></span></td>'.
7831: '</tr></table></td></tr>';
7832: return $output;
1.23 raeburn 7833: }
7834:
7835: sub sorted_searchtitles {
7836: my %searchtitles = &Apache::lonlocal::texthash(
7837: 'uname' => 'username',
7838: 'lastname' => 'last name',
7839: 'lastfirst' => 'last name, first name',
7840: );
7841: my @titleorder = ('uname','lastname','lastfirst');
7842: return (\%searchtitles,\@titleorder);
7843: }
7844:
1.25 raeburn 7845: sub sorted_searchtypes {
7846: my %srchtypes_desc = (
7847: exact => 'is exact match',
7848: contains => 'contains ..',
7849: begins => 'begins with ..',
7850: );
7851: my @srchtypeorder = ('exact','begins','contains');
7852: return (\%srchtypes_desc,\@srchtypeorder);
7853: }
7854:
1.3 raeburn 7855: sub usertype_update_row {
7856: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7857: my $datatable;
7858: my $numinrow = 4;
7859: foreach my $type (@{$types}) {
7860: if (defined($usertypes->{$type})) {
7861: $$rownums ++;
7862: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7863: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7864: '</td><td class="LC_left_item"><table>';
7865: for (my $i=0; $i<@{$fields}; $i++) {
7866: my $rem = $i%($numinrow);
7867: if ($rem == 0) {
7868: if ($i > 0) {
7869: $datatable .= '</tr>';
7870: }
7871: $datatable .= '<tr>';
7872: }
7873: my $check = ' ';
1.39 raeburn 7874: if (ref($settings) eq 'HASH') {
7875: if (ref($settings->{'fields'}) eq 'HASH') {
7876: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7877: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7878: $check = ' checked="checked" ';
7879: }
1.3 raeburn 7880: }
7881: }
7882: }
7883:
7884: if ($i == @{$fields}-1) {
7885: my $colsleft = $numinrow - $rem;
7886: if ($colsleft > 1) {
7887: $datatable .= '<td colspan="'.$colsleft.'">';
7888: } else {
7889: $datatable .= '<td>';
7890: }
7891: } else {
7892: $datatable .= '<td>';
7893: }
1.8 raeburn 7894: $datatable .= '<span class="LC_nobreak"><label>'.
7895: '<input type="checkbox" name="updateable_'.$type.
7896: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7897: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7898: }
7899: $datatable .= '</tr></table></td></tr>';
7900: }
7901: }
7902: return $datatable;
1.1 raeburn 7903: }
7904:
7905: sub modify_login {
1.205 raeburn 7906: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 7907: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7908: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7909: %title = ( coursecatalog => 'Display course catalog',
7910: adminmail => 'Display administrator E-mail address',
1.188 raeburn 7911: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 7912: newuser => 'Link for visitors to create a user account',
7913: loginheader => 'Log-in box header');
7914: @offon = ('off','on');
1.112 raeburn 7915: if (ref($domconfig{login}) eq 'HASH') {
7916: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7917: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7918: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7919: }
7920: }
7921: }
1.9 raeburn 7922: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7923: \%domconfig,\%loginhash);
1.188 raeburn 7924: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7925: foreach my $item (@toggles) {
7926: $loginhash{login}{$item} = $env{'form.'.$item};
7927: }
1.41 raeburn 7928: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7929: if (ref($colchanges{'login'}) eq 'HASH') {
7930: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7931: \%loginhash);
7932: }
1.110 raeburn 7933:
1.149 raeburn 7934: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 7935: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7936: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7937: if (keys(%servers) > 1) {
7938: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7939: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7940: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7941: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7942: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7943: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7944: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7945: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7946: $changes{'loginvia'}{$lonhost} = 1;
7947: } else {
7948: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7949: $changes{'loginvia'}{$lonhost} = 1;
7950: }
7951: } else {
7952: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7953: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7954: $changes{'loginvia'}{$lonhost} = 1;
7955: }
7956: }
7957: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7958: foreach my $item (@loginvia_attribs) {
7959: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7960: }
7961: } else {
7962: foreach my $item (@loginvia_attribs) {
7963: my $new = $env{'form.'.$lonhost.'_'.$item};
7964: if (($item eq 'serverpath') && ($new eq 'custom')) {
7965: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7966: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7967: $new = '/';
7968: }
7969: }
7970: if (($item eq 'custompath') &&
7971: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7972: $new = '';
7973: }
7974: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7975: $changes{'loginvia'}{$lonhost} = 1;
7976: }
7977: if ($item eq 'exempt') {
1.256 raeburn 7978: $new = &check_exempt_addresses($new);
1.128 raeburn 7979: }
7980: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7981: }
7982: }
1.112 raeburn 7983: } else {
1.128 raeburn 7984: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7985: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7986: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7987: foreach my $item (@loginvia_attribs) {
7988: my $new = $env{'form.'.$lonhost.'_'.$item};
7989: if (($item eq 'serverpath') && ($new eq 'custom')) {
7990: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7991: $new = '/';
7992: }
7993: }
7994: if (($item eq 'custompath') &&
7995: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7996: $new = '';
7997: }
7998: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7999: }
1.110 raeburn 8000: }
8001: }
8002: }
8003: }
1.119 raeburn 8004:
1.168 raeburn 8005: my $servadm = $r->dir_config('lonAdmEMail');
8006: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
8007: if (ref($domconfig{'login'}) eq 'HASH') {
8008: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
8009: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
8010: if ($lang eq 'nolang') {
8011: push(@currlangs,$lang);
8012: } elsif (defined($langchoices{$lang})) {
8013: push(@currlangs,$lang);
8014: } else {
8015: next;
8016: }
8017: }
8018: }
8019: }
8020: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
8021: if (@currlangs > 0) {
8022: foreach my $lang (@currlangs) {
8023: if (grep(/^\Q$lang\E$/,@delurls)) {
8024: $changes{'helpurl'}{$lang} = 1;
8025: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
8026: $changes{'helpurl'}{$lang} = 1;
8027: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
8028: push(@newlangs,$lang);
8029: } else {
8030: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8031: }
8032: }
8033: }
8034: unless (grep(/^nolang$/,@currlangs)) {
8035: if ($env{'form.loginhelpurl_nolang.filename'}) {
8036: $changes{'helpurl'}{'nolang'} = 1;
8037: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
8038: push(@newlangs,'nolang');
8039: }
8040: }
8041: if ($env{'form.loginhelpurl_add_lang'}) {
8042: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
8043: ($env{'form.loginhelpurl_add_file.filename'})) {
8044: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
8045: $addedfile = $env{'form.loginhelpurl_add_lang'};
8046: }
8047: }
8048: if ((@newlangs > 0) || ($addedfile)) {
8049: my $error;
8050: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8051: if ($configuserok eq 'ok') {
8052: if ($switchserver) {
8053: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
8054: } elsif ($author_ok eq 'ok') {
8055: my @allnew = @newlangs;
8056: if ($addedfile ne '') {
8057: push(@allnew,$addedfile);
8058: }
8059: foreach my $lang (@allnew) {
8060: my $formelem = 'loginhelpurl_'.$lang;
8061: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
8062: $formelem = 'loginhelpurl_add_file';
8063: }
8064: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8065: "help/$lang",'','',$newfile{$lang});
8066: if ($result eq 'ok') {
8067: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
8068: $changes{'helpurl'}{$lang} = 1;
8069: } else {
8070: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
8071: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 8072: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 8073: (!grep(/^\Q$lang\E$/,@delurls))) {
8074: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
8075: }
8076: }
8077: }
8078: } else {
8079: $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);
8080: }
8081: } else {
8082: $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);
8083: }
8084: if ($error) {
8085: &Apache::lonnet::logthis($error);
8086: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8087: }
8088: }
1.256 raeburn 8089:
8090: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
8091: if (ref($domconfig{'login'}) eq 'HASH') {
8092: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
8093: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
8094: if ($domservers{$lonhost}) {
8095: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8096: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 8097: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 8098: }
8099: }
8100: }
8101: }
8102: }
8103: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
8104: foreach my $lonhost (sort(keys(%domservers))) {
8105: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8106: $changes{'headtag'}{$lonhost} = 1;
8107: } else {
8108: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
8109: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
8110: }
8111: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
8112: push(@newhosts,$lonhost);
8113: } elsif ($currheadtagurls{$lonhost}) {
8114: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
8115: if ($currexempt{$lonhost}) {
1.289 raeburn 8116: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 8117: $changes{'headtag'}{$lonhost} = 1;
8118: }
8119: } elsif ($possexempt{$lonhost}) {
8120: $changes{'headtag'}{$lonhost} = 1;
8121: }
8122: if ($possexempt{$lonhost}) {
8123: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8124: }
8125: }
8126: }
8127: }
8128: if (@newhosts) {
8129: my $error;
8130: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
8131: if ($configuserok eq 'ok') {
8132: if ($switchserver) {
8133: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
8134: } elsif ($author_ok eq 'ok') {
8135: foreach my $lonhost (@newhosts) {
8136: my $formelem = 'loginheadtag_'.$lonhost;
8137: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
8138: "login/headtag/$lonhost",'','',
8139: $env{'form.loginheadtag_'.$lonhost.'.filename'});
8140: if ($result eq 'ok') {
8141: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
8142: $changes{'headtag'}{$lonhost} = 1;
8143: if ($possexempt{$lonhost}) {
8144: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
8145: }
8146: } else {
8147: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
8148: $newheadtagurls{$lonhost},$result);
8149: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
8150: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
8151: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
8152: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
8153: }
8154: }
8155: }
8156: } else {
8157: $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);
8158: }
8159: } else {
8160: $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);
8161: }
8162: if ($error) {
8163: &Apache::lonnet::logthis($error);
8164: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8165: }
8166: }
1.169 raeburn 8167: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 8168:
8169: my $defaulthelpfile = '/adm/loginproblems.html';
8170: my $defaulttext = &mt('Default in use');
8171:
1.1 raeburn 8172: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
8173: $dom);
8174: if ($putresult eq 'ok') {
1.188 raeburn 8175: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 8176: my %defaultchecked = (
8177: 'coursecatalog' => 'on',
1.188 raeburn 8178: 'helpdesk' => 'on',
1.42 raeburn 8179: 'adminmail' => 'off',
1.43 raeburn 8180: 'newuser' => 'off',
1.42 raeburn 8181: );
1.55 raeburn 8182: if (ref($domconfig{'login'}) eq 'HASH') {
8183: foreach my $item (@toggles) {
8184: if ($defaultchecked{$item} eq 'on') {
8185: if (($domconfig{'login'}{$item} eq '0') &&
8186: ($env{'form.'.$item} eq '1')) {
8187: $changes{$item} = 1;
8188: } elsif (($domconfig{'login'}{$item} eq '' ||
8189: $domconfig{'login'}{$item} eq '1') &&
8190: ($env{'form.'.$item} eq '0')) {
8191: $changes{$item} = 1;
8192: }
8193: } elsif ($defaultchecked{$item} eq 'off') {
8194: if (($domconfig{'login'}{$item} eq '1') &&
8195: ($env{'form.'.$item} eq '0')) {
8196: $changes{$item} = 1;
8197: } elsif (($domconfig{'login'}{$item} eq '' ||
8198: $domconfig{'login'}{$item} eq '0') &&
8199: ($env{'form.'.$item} eq '1')) {
8200: $changes{$item} = 1;
8201: }
1.42 raeburn 8202: }
8203: }
1.41 raeburn 8204: }
1.6 raeburn 8205: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 8206: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8207: if (ref($lastactref) eq 'HASH') {
8208: $lastactref->{'domainconfig'} = 1;
8209: }
1.1 raeburn 8210: $resulttext = &mt('Changes made:').'<ul>';
8211: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 8212: if ($item eq 'loginvia') {
1.112 raeburn 8213: if (ref($changes{$item}) eq 'HASH') {
8214: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
8215: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 8216: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
8217: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
8218: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
8219: $protocol = 'http' if ($protocol ne 'https');
8220: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
8221:
8222: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
8223: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
8224: } else {
8225: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
8226: }
8227: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
8228: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
8229: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
8230: }
8231: $resulttext .= '</li>';
8232: } else {
8233: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8234: }
1.112 raeburn 8235: } else {
1.128 raeburn 8236: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 8237: }
8238: }
1.128 raeburn 8239: $resulttext .= '</ul></li>';
1.112 raeburn 8240: }
1.168 raeburn 8241: } elsif ($item eq 'helpurl') {
8242: if (ref($changes{$item}) eq 'HASH') {
8243: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8244: if (grep(/^\Q$lang\E$/,@delurls)) {
8245: my ($chg,$link);
8246: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8247: if ($lang eq 'nolang') {
8248: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8249: } else {
8250: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8251: }
8252: $resulttext .= '<li>'.$chg.'</li>';
8253: } else {
8254: my $chg;
8255: if ($lang eq 'nolang') {
8256: $chg = &mt('custom log-in help file for no preferred language');
8257: } else {
8258: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8259: }
8260: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8261: $loginhash{'login'}{'helpurl'}{$lang}.
8262: '?inhibitmenu=yes',$chg,600,500).
8263: '</li>';
8264: }
8265: }
8266: }
1.256 raeburn 8267: } elsif ($item eq 'headtag') {
8268: if (ref($changes{$item}) eq 'HASH') {
8269: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8270: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8271: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8272: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8273: $resulttext .= '<li><a href="'.
8274: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8275: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8276: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8277: if ($possexempt{$lonhost}) {
8278: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8279: } else {
8280: $resulttext .= &mt('included for any client IP');
8281: }
8282: $resulttext .= '</li>';
8283: }
8284: }
8285: }
1.169 raeburn 8286: } elsif ($item eq 'captcha') {
8287: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 8288: my $chgtxt;
1.169 raeburn 8289: if ($loginhash{'login'}{$item} eq 'notused') {
8290: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
8291: } else {
8292: my %captchas = &captcha_phrases();
8293: if ($captchas{$loginhash{'login'}{$item}}) {
8294: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
8295: } else {
8296: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
8297: }
8298: }
8299: $resulttext .= '<li>'.$chgtxt.'</li>';
8300: }
8301: } elsif ($item eq 'recaptchakeys') {
8302: if (ref($loginhash{'login'}) eq 'HASH') {
8303: my ($privkey,$pubkey);
8304: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
8305: $pubkey = $loginhash{'login'}{$item}{'public'};
8306: $privkey = $loginhash{'login'}{$item}{'private'};
8307: }
8308: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
8309: if (!$pubkey) {
8310: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
8311: } else {
8312: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8313: }
8314: if (!$privkey) {
8315: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
8316: } else {
1.251 raeburn 8317: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 8318: }
8319: $chgtxt .= '</ul>';
8320: $resulttext .= '<li>'.$chgtxt.'</li>';
8321: }
1.269 raeburn 8322: } elsif ($item eq 'recaptchaversion') {
8323: if (ref($loginhash{'login'}) eq 'HASH') {
8324: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 8325: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 8326: '</li>';
8327: }
8328: }
1.41 raeburn 8329: } else {
8330: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
8331: }
1.1 raeburn 8332: }
1.6 raeburn 8333: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 8334: } else {
8335: $resulttext = &mt('No changes made to log-in page settings');
8336: }
8337: } else {
1.11 albertel 8338: $resulttext = '<span class="LC_error">'.
8339: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8340: }
1.6 raeburn 8341: if ($errors) {
1.9 raeburn 8342: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 8343: $errors.'</ul>';
8344: }
8345: return $resulttext;
8346: }
8347:
1.256 raeburn 8348: sub check_exempt_addresses {
8349: my ($iplist) = @_;
8350: $iplist =~ s/^\s+//;
8351: $iplist =~ s/\s+$//;
8352: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8353: my (@okips,$new);
8354: foreach my $ip (@poss_ips) {
8355: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8356: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8357: push(@okips,$ip);
8358: }
8359: }
8360: }
8361: if (@okips > 0) {
8362: $new = join(',',@okips);
8363: } else {
8364: $new = '';
8365: }
8366: return $new;
8367: }
8368:
1.6 raeburn 8369: sub color_font_choices {
8370: my %choices =
8371: &Apache::lonlocal::texthash (
8372: img => "Header",
8373: bgs => "Background colors",
8374: links => "Link colors",
1.55 raeburn 8375: images => "Images",
1.6 raeburn 8376: font => "Font color",
1.201 raeburn 8377: fontmenu => "Font menu",
1.76 raeburn 8378: pgbg => "Page",
1.6 raeburn 8379: tabbg => "Header",
8380: sidebg => "Border",
8381: link => "Link",
8382: alink => "Active link",
8383: vlink => "Visited link",
8384: );
8385: return %choices;
8386: }
8387:
8388: sub modify_rolecolors {
1.205 raeburn 8389: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8390: my ($resulttext,%rolehash);
8391: $rolehash{'rolecolors'} = {};
1.55 raeburn 8392: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8393: if ($domconfig{'rolecolors'} eq '') {
8394: $domconfig{'rolecolors'} = {};
8395: }
8396: }
1.9 raeburn 8397: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8398: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8399: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8400: $dom);
8401: if ($putresult eq 'ok') {
8402: if (keys(%changes) > 0) {
1.41 raeburn 8403: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8404: if (ref($lastactref) eq 'HASH') {
8405: $lastactref->{'domainconfig'} = 1;
8406: }
1.6 raeburn 8407: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8408: $rolehash{'rolecolors'});
8409: } else {
8410: $resulttext = &mt('No changes made to default color schemes');
8411: }
8412: } else {
1.11 albertel 8413: $resulttext = '<span class="LC_error">'.
8414: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8415: }
8416: if ($errors) {
8417: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8418: $errors.'</ul>';
8419: }
8420: return $resulttext;
8421: }
8422:
8423: sub modify_colors {
1.9 raeburn 8424: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8425: my (%changes,%choices);
1.51 raeburn 8426: my @bgs;
1.6 raeburn 8427: my @links = ('link','alink','vlink');
1.41 raeburn 8428: my @logintext;
1.6 raeburn 8429: my @images;
8430: my $servadm = $r->dir_config('lonAdmEMail');
8431: my $errors;
1.200 raeburn 8432: my %defaults;
1.6 raeburn 8433: foreach my $role (@{$roles}) {
8434: if ($role eq 'login') {
1.12 raeburn 8435: %choices = &login_choices();
1.41 raeburn 8436: @logintext = ('textcol','bgcol');
1.12 raeburn 8437: } else {
8438: %choices = &color_font_choices();
8439: }
8440: if ($role eq 'login') {
1.41 raeburn 8441: @images = ('img','logo','domlogo','login');
1.51 raeburn 8442: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8443: } else {
8444: @images = ('img');
1.200 raeburn 8445: @bgs = ('pgbg','tabbg','sidebg');
8446: }
8447: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8448: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8449: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8450: }
8451: if ($role eq 'login') {
8452: foreach my $item (@logintext) {
1.234 raeburn 8453: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8454: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8455: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8456: }
8457: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 8458: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8459: }
8460: }
8461: } else {
1.234 raeburn 8462: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8463: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8464: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8465: }
8466: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 8467: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8468: }
1.6 raeburn 8469: }
1.200 raeburn 8470: foreach my $item (@bgs) {
1.234 raeburn 8471: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8472: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8473: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8474: }
8475: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 8476: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8477: }
8478: }
8479: foreach my $item (@links) {
1.234 raeburn 8480: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8481: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8482: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8483: }
8484: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 8485: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8486: }
1.6 raeburn 8487: }
1.46 raeburn 8488: my ($configuserok,$author_ok,$switchserver) =
8489: &config_check($dom,$confname,$servadm);
1.9 raeburn 8490: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8491: if (ref($domconfig->{$role}) ne 'HASH') {
8492: $domconfig->{$role} = {};
8493: }
1.8 raeburn 8494: foreach my $img (@images) {
1.70 raeburn 8495: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8496: if (defined($env{'form.login_showlogo_'.$img})) {
8497: $confhash->{$role}{'showlogo'}{$img} = 1;
8498: } else {
8499: $confhash->{$role}{'showlogo'}{$img} = 0;
8500: }
8501: }
1.18 albertel 8502: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8503: && !defined($domconfig->{$role}{$img})
8504: && !$env{'form.'.$role.'_del_'.$img}
8505: && $env{'form.'.$role.'_import_'.$img}) {
8506: # import the old configured image from the .tab setting
8507: # if they haven't provided a new one
8508: $domconfig->{$role}{$img} =
8509: $env{'form.'.$role.'_import_'.$img};
8510: }
1.6 raeburn 8511: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8512: my $error;
1.6 raeburn 8513: if ($configuserok eq 'ok') {
1.9 raeburn 8514: if ($switchserver) {
1.12 raeburn 8515: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8516: } else {
8517: if ($author_ok eq 'ok') {
8518: my ($result,$logourl) =
8519: &publishlogo($r,'upload',$role.'_'.$img,
8520: $dom,$confname,$img,$width,$height);
8521: if ($result eq 'ok') {
8522: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8523: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8524: } else {
1.12 raeburn 8525: $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 8526: }
8527: } else {
1.46 raeburn 8528: $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 8529: }
8530: }
8531: } else {
1.46 raeburn 8532: $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 8533: }
8534: if ($error) {
1.8 raeburn 8535: &Apache::lonnet::logthis($error);
1.11 albertel 8536: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8537: }
8538: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8539: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8540: my $error;
8541: if ($configuserok eq 'ok') {
8542: # is confname an author?
8543: if ($switchserver eq '') {
8544: if ($author_ok eq 'ok') {
8545: my ($result,$logourl) =
8546: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8547: $dom,$confname,$img,$width,$height);
8548: if ($result eq 'ok') {
8549: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8550: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8551: }
8552: }
8553: }
8554: }
1.6 raeburn 8555: }
8556: }
8557: }
8558: if (ref($domconfig) eq 'HASH') {
8559: if (ref($domconfig->{$role}) eq 'HASH') {
8560: foreach my $img (@images) {
8561: if ($domconfig->{$role}{$img} ne '') {
8562: if ($env{'form.'.$role.'_del_'.$img}) {
8563: $confhash->{$role}{$img} = '';
1.12 raeburn 8564: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8565: } else {
1.9 raeburn 8566: if ($confhash->{$role}{$img} eq '') {
8567: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8568: }
1.6 raeburn 8569: }
8570: } else {
8571: if ($env{'form.'.$role.'_del_'.$img}) {
8572: $confhash->{$role}{$img} = '';
1.12 raeburn 8573: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8574: }
8575: }
1.70 raeburn 8576: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8577: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8578: if ($confhash->{$role}{'showlogo'}{$img} ne
8579: $domconfig->{$role}{'showlogo'}{$img}) {
8580: $changes{$role}{'showlogo'}{$img} = 1;
8581: }
8582: } else {
8583: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8584: $changes{$role}{'showlogo'}{$img} = 1;
8585: }
8586: }
8587: }
8588: }
1.6 raeburn 8589: if ($domconfig->{$role}{'font'} ne '') {
8590: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8591: $changes{$role}{'font'} = 1;
8592: }
8593: } else {
8594: if ($confhash->{$role}{'font'}) {
8595: $changes{$role}{'font'} = 1;
8596: }
8597: }
1.107 raeburn 8598: if ($role ne 'login') {
8599: if ($domconfig->{$role}{'fontmenu'} ne '') {
8600: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8601: $changes{$role}{'fontmenu'} = 1;
8602: }
8603: } else {
8604: if ($confhash->{$role}{'fontmenu'}) {
8605: $changes{$role}{'fontmenu'} = 1;
8606: }
1.97 tempelho 8607: }
8608: }
1.6 raeburn 8609: foreach my $item (@bgs) {
8610: if ($domconfig->{$role}{$item} ne '') {
8611: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8612: $changes{$role}{'bgs'}{$item} = 1;
8613: }
8614: } else {
8615: if ($confhash->{$role}{$item}) {
8616: $changes{$role}{'bgs'}{$item} = 1;
8617: }
8618: }
8619: }
8620: foreach my $item (@links) {
8621: if ($domconfig->{$role}{$item} ne '') {
8622: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8623: $changes{$role}{'links'}{$item} = 1;
8624: }
8625: } else {
8626: if ($confhash->{$role}{$item}) {
8627: $changes{$role}{'links'}{$item} = 1;
8628: }
8629: }
8630: }
1.41 raeburn 8631: foreach my $item (@logintext) {
8632: if ($domconfig->{$role}{$item} ne '') {
8633: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8634: $changes{$role}{'logintext'}{$item} = 1;
8635: }
8636: } else {
8637: if ($confhash->{$role}{$item}) {
8638: $changes{$role}{'logintext'}{$item} = 1;
8639: }
8640: }
8641: }
1.6 raeburn 8642: } else {
8643: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8644: \@logintext,$confhash,\%changes);
1.6 raeburn 8645: }
8646: } else {
8647: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8648: \@logintext,$confhash,\%changes);
1.6 raeburn 8649: }
8650: }
8651: return ($errors,%changes);
8652: }
8653:
1.46 raeburn 8654: sub config_check {
8655: my ($dom,$confname,$servadm) = @_;
8656: my ($configuserok,$author_ok,$switchserver,%currroles);
8657: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8658: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8659: $confname,$servadm);
8660: if ($configuserok eq 'ok') {
8661: $switchserver = &check_switchserver($dom,$confname);
8662: if ($switchserver eq '') {
8663: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8664: }
8665: }
8666: return ($configuserok,$author_ok,$switchserver);
8667: }
8668:
1.6 raeburn 8669: sub default_change_checker {
1.41 raeburn 8670: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8671: foreach my $item (@{$links}) {
8672: if ($confhash->{$role}{$item}) {
8673: $changes->{$role}{'links'}{$item} = 1;
8674: }
8675: }
8676: foreach my $item (@{$bgs}) {
8677: if ($confhash->{$role}{$item}) {
8678: $changes->{$role}{'bgs'}{$item} = 1;
8679: }
8680: }
1.41 raeburn 8681: foreach my $item (@{$logintext}) {
8682: if ($confhash->{$role}{$item}) {
8683: $changes->{$role}{'logintext'}{$item} = 1;
8684: }
8685: }
1.6 raeburn 8686: foreach my $img (@{$images}) {
8687: if ($env{'form.'.$role.'_del_'.$img}) {
8688: $confhash->{$role}{$img} = '';
1.12 raeburn 8689: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8690: }
1.70 raeburn 8691: if ($role eq 'login') {
8692: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8693: $changes->{$role}{'showlogo'}{$img} = 1;
8694: }
8695: }
1.6 raeburn 8696: }
8697: if ($confhash->{$role}{'font'}) {
8698: $changes->{$role}{'font'} = 1;
8699: }
1.48 raeburn 8700: }
1.6 raeburn 8701:
8702: sub display_colorchgs {
8703: my ($dom,$changes,$roles,$confhash) = @_;
8704: my (%choices,$resulttext);
8705: if (!grep(/^login$/,@{$roles})) {
8706: $resulttext = &mt('Changes made:').'<br />';
8707: }
8708: foreach my $role (@{$roles}) {
8709: if ($role eq 'login') {
8710: %choices = &login_choices();
8711: } else {
8712: %choices = &color_font_choices();
8713: }
8714: if (ref($changes->{$role}) eq 'HASH') {
8715: if ($role ne 'login') {
8716: $resulttext .= '<h4>'.&mt($role).'</h4>';
8717: }
8718: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8719: if ($role ne 'login') {
8720: $resulttext .= '<ul>';
8721: }
8722: if (ref($changes->{$role}{$key}) eq 'HASH') {
8723: if ($role ne 'login') {
8724: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8725: }
8726: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8727: if (($role eq 'login') && ($key eq 'showlogo')) {
8728: if ($confhash->{$role}{$key}{$item}) {
8729: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8730: } else {
8731: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8732: }
8733: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8734: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8735: } else {
1.12 raeburn 8736: my $newitem = $confhash->{$role}{$item};
8737: if ($key eq 'images') {
1.306 raeburn 8738: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 8739: }
8740: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8741: }
8742: }
8743: if ($role ne 'login') {
8744: $resulttext .= '</ul></li>';
8745: }
8746: } else {
8747: if ($confhash->{$role}{$key} eq '') {
8748: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8749: } else {
8750: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8751: }
8752: }
8753: if ($role ne 'login') {
8754: $resulttext .= '</ul>';
8755: }
8756: }
8757: }
8758: }
1.3 raeburn 8759: return $resulttext;
1.1 raeburn 8760: }
8761:
1.9 raeburn 8762: sub thumb_dimensions {
8763: return ('200','50');
8764: }
8765:
1.16 raeburn 8766: sub check_dimensions {
8767: my ($inputfile) = @_;
8768: my ($fullwidth,$fullheight);
8769: if ($inputfile =~ m|^[/\w.\-]+$|) {
8770: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8771: my $imageinfo = <PIPE>;
8772: if (!close(PIPE)) {
8773: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8774: }
8775: chomp($imageinfo);
8776: my ($fullsize) =
1.21 raeburn 8777: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8778: if ($fullsize) {
8779: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8780: }
8781: }
8782: }
8783: return ($fullwidth,$fullheight);
8784: }
8785:
1.9 raeburn 8786: sub check_configuser {
8787: my ($uhome,$dom,$confname,$servadm) = @_;
8788: my ($configuserok,%currroles);
8789: if ($uhome eq 'no_host') {
8790: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8791: my $configpass = &LONCAPA::Enrollment::create_password();
8792: $configuserok =
8793: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8794: $configpass,'','','','','',undef,$servadm);
8795: } else {
8796: $configuserok = 'ok';
8797: %currroles =
8798: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8799: }
8800: return ($configuserok,%currroles);
8801: }
8802:
8803: sub check_authorstatus {
8804: my ($dom,$confname,%currroles) = @_;
8805: my $author_ok;
1.40 raeburn 8806: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8807: my $start = time;
8808: my $end = 0;
8809: $author_ok =
8810: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8811: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8812: } else {
8813: $author_ok = 'ok';
8814: }
8815: return $author_ok;
8816: }
8817:
8818: sub publishlogo {
1.46 raeburn 8819: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 8820: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 8821: if ($action eq 'upload') {
8822: $fname=$env{'form.'.$formname.'.filename'};
8823: chop($env{'form.'.$formname});
8824: } else {
8825: ($fname) = ($formname =~ /([^\/]+)$/);
8826: }
1.46 raeburn 8827: if ($savefileas ne '') {
8828: $fname = $savefileas;
8829: }
1.9 raeburn 8830: $fname=&Apache::lonnet::clean_filename($fname);
8831: # See if there is anything left
8832: unless ($fname) { return ('error: no uploaded file'); }
8833: $fname="$subdir/$fname";
1.210 raeburn 8834: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 8835: my $filepath="$docroot/priv";
8836: my $relpath = "$dom/$confname";
1.9 raeburn 8837: my ($fnamepath,$file,$fetchthumb);
8838: $file=$fname;
8839: if ($fname=~m|/|) {
8840: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8841: }
1.164 raeburn 8842: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8843: my $count;
1.164 raeburn 8844: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8845: $filepath.="/$parts[$count]";
8846: if ((-e $filepath)!=1) {
8847: mkdir($filepath,02770);
8848: }
8849: }
8850: # Check for bad extension and disallow upload
8851: if ($file=~/\.(\w+)$/ &&
8852: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8853: $output =
1.207 bisitz 8854: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8855: } elsif ($file=~/\.(\w+)$/ &&
8856: !defined(&Apache::loncommon::fileembstyle($1))) {
8857: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8858: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 8859: $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 8860: } elsif (-d "$filepath/$file") {
1.195 bisitz 8861: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8862: } else {
8863: my $source = $filepath.'/'.$file;
8864: my $logfile;
8865: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 8866: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8867: }
8868: print $logfile
8869: "\n================= Publish ".localtime()." ================\n".
8870: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8871: # Save the file
8872: if (!open(FH,'>'.$source)) {
8873: &Apache::lonnet::logthis('Failed to create '.$source);
8874: return (&mt('Failed to create file'));
8875: }
8876: if ($action eq 'upload') {
8877: if (!print FH ($env{'form.'.$formname})) {
8878: &Apache::lonnet::logthis('Failed to write to '.$source);
8879: return (&mt('Failed to write file'));
8880: }
8881: } else {
8882: my $original = &Apache::lonnet::filelocation('',$formname);
8883: if(!copy($original,$source)) {
8884: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8885: return (&mt('Failed to write file'));
8886: }
8887: }
8888: close(FH);
8889: chmod(0660, $source); # Permissions to rw-rw---.
8890:
8891: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8892: my $copyfile=$targetdir.'/'.$file;
8893:
8894: my @parts=split(/\//,$targetdir);
8895: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8896: for (my $count=5;$count<=$#parts;$count++) {
8897: $path.="/$parts[$count]";
8898: if (!-e $path) {
8899: print $logfile "\nCreating directory ".$path;
8900: mkdir($path,02770);
8901: }
8902: }
8903: my $versionresult;
8904: if (-e $copyfile) {
8905: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8906: } else {
8907: $versionresult = 'ok';
8908: }
8909: if ($versionresult eq 'ok') {
8910: if (copy($source,$copyfile)) {
8911: print $logfile "\nCopied original source to ".$copyfile."\n";
8912: $output = 'ok';
8913: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8914: push(@{$modified_urls},[$copyfile,$source]);
8915: my $metaoutput =
8916: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8917: unless ($registered_cleanup) {
8918: my $handlers = $r->get_handlers('PerlCleanupHandler');
8919: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8920: $registered_cleanup=1;
8921: }
1.9 raeburn 8922: } else {
8923: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8924: $output = &mt('Failed to copy file to RES space').", $!";
8925: }
8926: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8927: my $inputfile = $filepath.'/'.$file;
8928: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8929: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8930: if ($fullwidth ne '' && $fullheight ne '') {
8931: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8932: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8933: system("convert -sample $thumbsize $inputfile $outfile");
8934: chmod(0660, $filepath.'/tn-'.$file);
8935: if (-e $outfile) {
8936: my $copyfile=$targetdir.'/tn-'.$file;
8937: if (copy($outfile,$copyfile)) {
8938: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8939: my $thumb_metaoutput =
8940: &write_metadata($dom,$confname,$formname,
8941: $targetdir,'tn-'.$file,$logfile);
8942: push(@{$modified_urls},[$copyfile,$outfile]);
8943: unless ($registered_cleanup) {
8944: my $handlers = $r->get_handlers('PerlCleanupHandler');
8945: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8946: $registered_cleanup=1;
8947: }
1.267 raeburn 8948: $madethumb = 1;
1.16 raeburn 8949: } else {
8950: print $logfile "\nUnable to write ".$copyfile.
8951: ':'.$!."\n";
8952: }
8953: }
1.9 raeburn 8954: }
8955: }
8956: }
8957: } else {
8958: $output = $versionresult;
8959: }
8960: }
1.267 raeburn 8961: return ($output,$logourl,$madethumb);
1.9 raeburn 8962: }
8963:
8964: sub logo_versioning {
8965: my ($targetdir,$file,$logfile) = @_;
8966: my $target = $targetdir.'/'.$file;
8967: my ($maxversion,$fn,$extn,$output);
8968: $maxversion = 0;
8969: if ($file =~ /^(.+)\.(\w+)$/) {
8970: $fn=$1;
8971: $extn=$2;
8972: }
8973: opendir(DIR,$targetdir);
8974: while (my $filename=readdir(DIR)) {
8975: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8976: $maxversion=($1>$maxversion)?$1:$maxversion;
8977: }
8978: }
8979: $maxversion++;
8980: print $logfile "\nCreating old version ".$maxversion."\n";
8981: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8982: if (copy($target,$copyfile)) {
8983: print $logfile "Copied old target to ".$copyfile."\n";
8984: $copyfile=$copyfile.'.meta';
8985: if (copy($target.'.meta',$copyfile)) {
8986: print $logfile "Copied old target metadata to ".$copyfile."\n";
8987: $output = 'ok';
8988: } else {
8989: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8990: $output = &mt('Failed to copy old meta').", $!, ";
8991: }
8992: } else {
8993: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8994: $output = &mt('Failed to copy old target').", $!, ";
8995: }
8996: return $output;
8997: }
8998:
8999: sub write_metadata {
9000: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
9001: my (%metadatafields,%metadatakeys,$output);
9002: $metadatafields{'title'}=$formname;
9003: $metadatafields{'creationdate'}=time;
9004: $metadatafields{'lastrevisiondate'}=time;
9005: $metadatafields{'copyright'}='public';
9006: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
9007: $env{'user.domain'};
9008: $metadatafields{'authorspace'}=$confname.':'.$dom;
9009: $metadatafields{'domain'}=$dom;
9010: {
9011: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
9012: my $mfh;
1.155 raeburn 9013: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 9014: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 9015: unless ($_=~/\./) {
9016: my $unikey=$_;
9017: $unikey=~/^([A-Za-z]+)/;
9018: my $tag=$1;
9019: $tag=~tr/A-Z/a-z/;
9020: print $mfh "\n\<$tag";
9021: foreach (split(/\,/,$metadatakeys{$unikey})) {
9022: my $value=$metadatafields{$unikey.'.'.$_};
9023: $value=~s/\"/\'\'/g;
9024: print $mfh ' '.$_.'="'.$value.'"';
9025: }
9026: print $mfh '>'.
9027: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
9028: .'</'.$tag.'>';
9029: }
9030: }
9031: $output = 'ok';
9032: print $logfile "\nWrote metadata";
9033: close($mfh);
9034: } else {
9035: print $logfile "\nFailed to open metadata file";
1.9 raeburn 9036: $output = &mt('Could not write metadata');
9037: }
9038: }
1.155 raeburn 9039: return $output;
9040: }
9041:
9042: sub notifysubscribed {
9043: foreach my $targetsource (@{$modified_urls}){
9044: next unless (ref($targetsource) eq 'ARRAY');
9045: my ($target,$source)=@{$targetsource};
9046: if ($source ne '') {
9047: if (open(my $logfh,'>>'.$source.'.log')) {
9048: print $logfh "\nCleanup phase: Notifications\n";
9049: my @subscribed=&subscribed_hosts($target);
9050: foreach my $subhost (@subscribed) {
9051: print $logfh "\nNotifying host ".$subhost.':';
9052: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
9053: print $logfh $reply;
9054: }
9055: my @subscribedmeta=&subscribed_hosts("$target.meta");
9056: foreach my $subhost (@subscribedmeta) {
9057: print $logfh "\nNotifying host for metadata only ".$subhost.':';
9058: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
9059: $subhost);
9060: print $logfh $reply;
9061: }
9062: print $logfh "\n============ Done ============\n";
1.160 raeburn 9063: close($logfh);
1.155 raeburn 9064: }
9065: }
9066: }
9067: return OK;
9068: }
9069:
9070: sub subscribed_hosts {
9071: my ($target) = @_;
9072: my @subscribed;
9073: if (open(my $fh,"<$target.subscription")) {
9074: while (my $subline=<$fh>) {
9075: if ($subline =~ /^($match_lonid):/) {
9076: my $host = $1;
9077: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
9078: unless (grep(/^\Q$host\E$/,@subscribed)) {
9079: push(@subscribed,$host);
9080: }
9081: }
9082: }
9083: }
9084: }
9085: return @subscribed;
1.9 raeburn 9086: }
9087:
9088: sub check_switchserver {
9089: my ($dom,$confname) = @_;
9090: my ($allowed,$switchserver);
9091: my $home = &Apache::lonnet::homeserver($confname,$dom);
9092: if ($home eq 'no_host') {
9093: $home = &Apache::lonnet::domain($dom,'primary');
9094: }
9095: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 9096: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
9097: if (!$allowed) {
1.180 raeburn 9098: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 9099: }
9100: return $switchserver;
9101: }
9102:
1.1 raeburn 9103: sub modify_quotas {
1.216 raeburn 9104: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 9105: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 9106: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 9107: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
9108: $validationfieldsref);
1.86 raeburn 9109: if ($action eq 'quotas') {
9110: $context = 'tools';
1.163 raeburn 9111: } else {
1.86 raeburn 9112: $context = $action;
9113: }
9114: if ($context eq 'requestcourses') {
1.271 raeburn 9115: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 9116: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 9117: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
9118: %titles = &courserequest_titles();
9119: $toolregexp = join('|',@usertools);
9120: %conditions = &courserequest_conditions();
1.216 raeburn 9121: $confname = $dom.'-domainconfig';
9122: my $servadm = $r->dir_config('lonAdmEMail');
9123: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 9124: ($validationitemsref,$validationnamesref,$validationfieldsref) =
9125: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 9126: } elsif ($context eq 'requestauthor') {
9127: @usertools = ('author');
9128: %titles = &authorrequest_titles();
1.86 raeburn 9129: } else {
1.162 raeburn 9130: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 9131: %titles = &tool_titles();
1.86 raeburn 9132: }
1.212 raeburn 9133: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 9134: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9135: foreach my $key (keys(%env)) {
1.101 raeburn 9136: if ($context eq 'requestcourses') {
9137: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
9138: my $item = $1;
9139: my $type = $2;
9140: if ($type =~ /^limit_(.+)/) {
9141: $limithash{$item}{$1} = $env{$key};
9142: } else {
9143: $confhash{$item}{$type} = $env{$key};
9144: }
9145: }
1.163 raeburn 9146: } elsif ($context eq 'requestauthor') {
9147: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
9148: $confhash{$1} = $env{$key};
9149: }
1.101 raeburn 9150: } else {
1.86 raeburn 9151: if ($key =~ /^form\.quota_(.+)$/) {
9152: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 9153: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
9154: $confhash{'authorquota'}{$1} = $env{$key};
9155: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 9156: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
9157: }
1.72 raeburn 9158: }
9159: }
1.163 raeburn 9160: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 9161: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 9162: @approvalnotify = sort(@approvalnotify);
9163: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 9164: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 9165: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
9166: foreach my $type (@hasuniquecode) {
9167: if (grep(/^\Q$type\E$/,@crstypes)) {
9168: $confhash{'uniquecode'}{$type} = 1;
9169: }
1.216 raeburn 9170: }
1.242 raeburn 9171: my (%newbook,%allpos);
1.216 raeburn 9172: if ($context eq 'requestcourses') {
1.242 raeburn 9173: foreach my $type ('textbooks','templates') {
9174: @{$allpos{$type}} = ();
9175: my $invalid;
9176: if ($type eq 'textbooks') {
9177: $invalid = &mt('Invalid LON-CAPA course for textbook');
9178: } else {
9179: $invalid = &mt('Invalid LON-CAPA course for template');
9180: }
9181: if ($env{'form.'.$type.'_addbook'}) {
9182: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
9183: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
9184: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
9185: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
9186: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
9187: } else {
9188: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
9189: my $position = $env{'form.'.$type.'_addbook_pos'};
9190: $position =~ s/\D+//g;
9191: if ($position ne '') {
9192: $allpos{$type}[$position] = $newbook{$type};
9193: }
1.216 raeburn 9194: }
1.242 raeburn 9195: } else {
9196: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 9197: }
9198: }
1.242 raeburn 9199: }
1.216 raeburn 9200: }
1.102 raeburn 9201: if (ref($domconfig{$action}) eq 'HASH') {
9202: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
9203: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
9204: $changes{'notify'}{'approval'} = 1;
9205: }
9206: } else {
1.144 raeburn 9207: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9208: $changes{'notify'}{'approval'} = 1;
9209: }
9210: }
1.218 raeburn 9211: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
9212: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9213: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
9214: unless ($confhash{'uniquecode'}{$crstype}) {
9215: $changes{'uniquecode'} = 1;
9216: }
9217: }
9218: unless ($changes{'uniquecode'}) {
9219: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
9220: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
9221: $changes{'uniquecode'} = 1;
9222: }
9223: }
9224: }
9225: } else {
9226: $changes{'uniquecode'} = 1;
9227: }
9228: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
9229: $changes{'uniquecode'} = 1;
1.216 raeburn 9230: }
9231: if ($context eq 'requestcourses') {
1.242 raeburn 9232: foreach my $type ('textbooks','templates') {
9233: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9234: my %deletions;
9235: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9236: if (@todelete) {
9237: map { $deletions{$_} = 1; } @todelete;
9238: }
9239: my %imgdeletions;
9240: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9241: if (@todeleteimages) {
9242: map { $imgdeletions{$_} = 1; } @todeleteimages;
9243: }
9244: my $maxnum = $env{'form.'.$type.'_maxnum'};
9245: for (my $i=0; $i<=$maxnum; $i++) {
9246: my $itemid = $env{'form.'.$type.'_id_'.$i};
9247: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9248: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9249: if ($deletions{$key}) {
9250: if ($domconfig{$action}{$type}{$key}{'image'}) {
9251: #FIXME need to obsolete item in RES space
9252: }
9253: next;
9254: } else {
9255: my $newpos = $env{'form.'.$itemid};
9256: $newpos =~ s/\D+//g;
1.243 raeburn 9257: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 9258: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 9259: ($type eq 'templates'));
1.242 raeburn 9260: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9261: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9262: $changes{$type}{$key} = 1;
9263: }
9264: }
9265: $allpos{$type}[$newpos] = $key;
9266: }
9267: if ($imgdeletions{$key}) {
9268: $changes{$type}{$key} = 1;
1.216 raeburn 9269: #FIXME need to obsolete item in RES space
1.242 raeburn 9270: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9271: my ($cdom,$cnum) = split(/_/,$key);
9272: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9273: $cdom,$cnum,$type,$configuserok,
9274: $switchserver,$author_ok);
9275: if ($imgurl) {
9276: $confhash{$type}{$key}{'image'} = $imgurl;
9277: $changes{$type}{$key} = 1;
1.216 raeburn 9278: }
1.242 raeburn 9279: if ($error) {
9280: &Apache::lonnet::logthis($error);
9281: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9282: }
9283: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
9284: $confhash{$type}{$key}{'image'} =
9285: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 9286: }
9287: }
9288: }
9289: }
9290: }
9291: }
1.102 raeburn 9292: } else {
1.144 raeburn 9293: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9294: $changes{'notify'}{'approval'} = 1;
9295: }
1.218 raeburn 9296: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 9297: $changes{'uniquecode'} = 1;
9298: }
9299: }
9300: if ($context eq 'requestcourses') {
1.242 raeburn 9301: foreach my $type ('textbooks','templates') {
9302: if ($newbook{$type}) {
9303: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 9304: foreach my $item ('subject','title','publisher','author') {
9305: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9306: ($type eq 'template'));
1.242 raeburn 9307: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
9308: if ($env{'form.'.$type.'_addbook_'.$item}) {
9309: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
9310: }
9311: }
9312: if ($type eq 'textbooks') {
9313: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
9314: my ($cdom,$cnum) = split(/_/,$newbook{$type});
9315: my ($imageurl,$error) =
9316: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
9317: $configuserok,$switchserver,$author_ok);
9318: if ($imageurl) {
9319: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
9320: }
9321: if ($error) {
9322: &Apache::lonnet::logthis($error);
9323: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9324: }
9325: }
1.216 raeburn 9326: }
9327: }
1.242 raeburn 9328: if (@{$allpos{$type}} > 0) {
9329: my $idx = 0;
9330: foreach my $item (@{$allpos{$type}}) {
9331: if ($item ne '') {
9332: $confhash{$type}{$item}{'order'} = $idx;
9333: if (ref($domconfig{$action}) eq 'HASH') {
9334: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9335: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
9336: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
9337: $changes{$type}{$item} = 1;
9338: }
1.216 raeburn 9339: }
9340: }
9341: }
1.242 raeburn 9342: $idx ++;
1.216 raeburn 9343: }
9344: }
9345: }
9346: }
1.235 raeburn 9347: if (ref($validationitemsref) eq 'ARRAY') {
9348: foreach my $item (@{$validationitemsref}) {
9349: if ($item eq 'fields') {
9350: my @changed;
9351: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9352: if (@{$confhash{'validation'}{$item}} > 0) {
9353: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9354: }
1.266 raeburn 9355: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9356: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9357: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9358: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9359: $domconfig{'requestcourses'}{'validation'}{$item});
9360: } else {
9361: @changed = @{$confhash{'validation'}{$item}};
9362: }
1.235 raeburn 9363: } else {
9364: @changed = @{$confhash{'validation'}{$item}};
9365: }
9366: } else {
9367: @changed = @{$confhash{'validation'}{$item}};
9368: }
9369: if (@changed) {
9370: if ($confhash{'validation'}{$item}) {
9371: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9372: } else {
9373: $changes{'validation'}{$item} = &mt('None');
9374: }
9375: }
9376: } else {
9377: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9378: if ($item eq 'markup') {
9379: if ($env{'form.requestcourses_validation_'.$item}) {
9380: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9381: }
9382: }
1.266 raeburn 9383: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9384: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9385: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9386: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9387: }
9388: } else {
9389: if ($confhash{'validation'}{$item} ne '') {
9390: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9391: }
1.235 raeburn 9392: }
9393: } else {
9394: if ($confhash{'validation'}{$item} ne '') {
9395: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9396: }
9397: }
9398: }
9399: }
9400: }
9401: if ($env{'form.validationdc'}) {
9402: my $newval = $env{'form.validationdc'};
1.285 raeburn 9403: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 9404: if (exists($domcoords{$newval})) {
9405: $confhash{'validation'}{'dc'} = $newval;
9406: }
9407: }
9408: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 9409: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9410: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9411: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9412: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9413: if ($confhash{'validation'}{'dc'} eq '') {
9414: $changes{'validation'}{'dc'} = &mt('None');
9415: } else {
9416: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9417: }
1.235 raeburn 9418: }
1.266 raeburn 9419: } elsif ($confhash{'validation'}{'dc'} ne '') {
9420: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 9421: }
9422: } elsif ($confhash{'validation'}{'dc'} ne '') {
9423: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9424: }
9425: } elsif ($confhash{'validation'}{'dc'} ne '') {
9426: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 9427: }
1.266 raeburn 9428: } else {
9429: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9430: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9431: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9432: $changes{'validation'}{'dc'} = &mt('None');
9433: }
9434: }
1.235 raeburn 9435: }
9436: }
1.102 raeburn 9437: }
9438: } else {
1.86 raeburn 9439: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 9440: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9441: }
1.72 raeburn 9442: foreach my $item (@usertools) {
9443: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9444: my $unset;
1.101 raeburn 9445: if ($context eq 'requestcourses') {
1.104 raeburn 9446: $unset = '0';
9447: if ($type eq '_LC_adv') {
9448: $unset = '';
9449: }
1.101 raeburn 9450: if ($confhash{$item}{$type} eq 'autolimit') {
9451: $confhash{$item}{$type} .= '=';
9452: unless ($limithash{$item}{$type} =~ /\D/) {
9453: $confhash{$item}{$type} .= $limithash{$item}{$type};
9454: }
9455: }
1.163 raeburn 9456: } elsif ($context eq 'requestauthor') {
9457: $unset = '0';
9458: if ($type eq '_LC_adv') {
9459: $unset = '';
9460: }
1.72 raeburn 9461: } else {
1.101 raeburn 9462: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9463: $confhash{$item}{$type} = 1;
9464: } else {
9465: $confhash{$item}{$type} = 0;
9466: }
1.72 raeburn 9467: }
1.86 raeburn 9468: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 9469: if ($action eq 'requestauthor') {
9470: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9471: $changes{$type} = 1;
9472: }
9473: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9474: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9475: $changes{$item}{$type} = 1;
9476: }
9477: } else {
9478: if ($context eq 'requestcourses') {
1.104 raeburn 9479: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9480: $changes{$item}{$type} = 1;
9481: }
9482: } else {
9483: if (!$confhash{$item}{$type}) {
9484: $changes{$item}{$type} = 1;
9485: }
9486: }
9487: }
9488: } else {
9489: if ($context eq 'requestcourses') {
1.104 raeburn 9490: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9491: $changes{$item}{$type} = 1;
9492: }
1.163 raeburn 9493: } elsif ($context eq 'requestauthor') {
9494: if ($confhash{$type} ne $unset) {
9495: $changes{$type} = 1;
9496: }
1.72 raeburn 9497: } else {
9498: if (!$confhash{$item}{$type}) {
9499: $changes{$item}{$type} = 1;
9500: }
9501: }
9502: }
1.1 raeburn 9503: }
9504: }
1.163 raeburn 9505: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9506: if (ref($domconfig{'quotas'}) eq 'HASH') {
9507: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9508: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9509: if (exists($confhash{'defaultquota'}{$key})) {
9510: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9511: $changes{'defaultquota'}{$key} = 1;
9512: }
9513: } else {
9514: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9515: }
9516: }
1.86 raeburn 9517: } else {
9518: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9519: if (exists($confhash{'defaultquota'}{$key})) {
9520: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9521: $changes{'defaultquota'}{$key} = 1;
9522: }
9523: } else {
9524: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9525: }
1.1 raeburn 9526: }
9527: }
1.197 raeburn 9528: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9529: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9530: if (exists($confhash{'authorquota'}{$key})) {
9531: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9532: $changes{'authorquota'}{$key} = 1;
9533: }
9534: } else {
9535: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9536: }
9537: }
9538: }
1.1 raeburn 9539: }
1.86 raeburn 9540: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9541: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9542: if (ref($domconfig{'quotas'}) eq 'HASH') {
9543: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9544: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9545: $changes{'defaultquota'}{$key} = 1;
9546: }
9547: } else {
9548: if (!exists($domconfig{'quotas'}{$key})) {
9549: $changes{'defaultquota'}{$key} = 1;
9550: }
1.72 raeburn 9551: }
9552: } else {
1.86 raeburn 9553: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9554: }
1.1 raeburn 9555: }
9556: }
1.197 raeburn 9557: if (ref($confhash{'authorquota'}) eq 'HASH') {
9558: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9559: if (ref($domconfig{'quotas'}) eq 'HASH') {
9560: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9561: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9562: $changes{'authorquota'}{$key} = 1;
9563: }
9564: } else {
9565: $changes{'authorquota'}{$key} = 1;
9566: }
9567: } else {
9568: $changes{'authorquota'}{$key} = 1;
9569: }
9570: }
9571: }
1.1 raeburn 9572: }
1.72 raeburn 9573:
1.163 raeburn 9574: if ($context eq 'requestauthor') {
9575: $domdefaults{'requestauthor'} = \%confhash;
9576: } else {
9577: foreach my $key (keys(%confhash)) {
1.242 raeburn 9578: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 9579: $domdefaults{$key} = $confhash{$key};
9580: }
1.163 raeburn 9581: }
1.72 raeburn 9582: }
1.163 raeburn 9583:
1.1 raeburn 9584: my %quotahash = (
1.86 raeburn 9585: $action => { %confhash }
1.1 raeburn 9586: );
9587: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9588: $dom);
9589: if ($putresult eq 'ok') {
9590: if (keys(%changes) > 0) {
1.72 raeburn 9591: my $cachetime = 24*60*60;
9592: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9593: if (ref($lastactref) eq 'HASH') {
9594: $lastactref->{'domdefaults'} = 1;
9595: }
1.1 raeburn 9596: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 9597: unless (($context eq 'requestcourses') ||
1.163 raeburn 9598: ($context eq 'requestauthor')) {
1.86 raeburn 9599: if (ref($changes{'defaultquota'}) eq 'HASH') {
9600: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9601: foreach my $type (@{$types},'default') {
9602: if (defined($changes{'defaultquota'}{$type})) {
9603: my $typetitle = $usertypes->{$type};
9604: if ($type eq 'default') {
9605: $typetitle = $othertitle;
9606: }
1.213 raeburn 9607: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9608: }
9609: }
1.86 raeburn 9610: $resulttext .= '</ul></li>';
1.72 raeburn 9611: }
1.197 raeburn 9612: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 9613: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 9614: foreach my $type (@{$types},'default') {
9615: if (defined($changes{'authorquota'}{$type})) {
9616: my $typetitle = $usertypes->{$type};
9617: if ($type eq 'default') {
9618: $typetitle = $othertitle;
9619: }
1.213 raeburn 9620: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 9621: }
9622: }
9623: $resulttext .= '</ul></li>';
9624: }
1.72 raeburn 9625: }
1.80 raeburn 9626: my %newenv;
1.72 raeburn 9627: foreach my $item (@usertools) {
1.163 raeburn 9628: my (%haschgs,%inconf);
9629: if ($context eq 'requestauthor') {
9630: %haschgs = %changes;
1.210 raeburn 9631: %inconf = %confhash;
1.163 raeburn 9632: } else {
9633: if (ref($changes{$item}) eq 'HASH') {
9634: %haschgs = %{$changes{$item}};
9635: }
9636: if (ref($confhash{$item}) eq 'HASH') {
9637: %inconf = %{$confhash{$item}};
9638: }
9639: }
9640: if (keys(%haschgs) > 0) {
1.80 raeburn 9641: my $newacc =
9642: &Apache::lonnet::usertools_access($env{'user.name'},
9643: $env{'user.domain'},
1.86 raeburn 9644: $item,'reload',$context);
1.210 raeburn 9645: if (($context eq 'requestcourses') ||
1.163 raeburn 9646: ($context eq 'requestauthor')) {
1.108 raeburn 9647: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9648: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9649: }
9650: } else {
9651: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9652: $newenv{'environment.availabletools.'.$item} = $newacc;
9653: }
1.80 raeburn 9654: }
1.163 raeburn 9655: unless ($context eq 'requestauthor') {
9656: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9657: }
1.72 raeburn 9658: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 9659: if ($haschgs{$type}) {
1.72 raeburn 9660: my $typetitle = $usertypes->{$type};
9661: if ($type eq 'default') {
9662: $typetitle = $othertitle;
9663: } elsif ($type eq '_LC_adv') {
9664: $typetitle = 'LON-CAPA Advanced Users';
9665: }
1.163 raeburn 9666: if ($inconf{$type}) {
1.101 raeburn 9667: if ($context eq 'requestcourses') {
9668: my $cond;
1.163 raeburn 9669: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9670: if ($1 eq '') {
9671: $cond = &mt('(Automatic processing of any request).');
9672: } else {
9673: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9674: }
9675: } else {
1.163 raeburn 9676: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9677: }
9678: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 9679: } elsif ($context eq 'requestauthor') {
9680: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9681: $titles{$inconf{$type}},$typetitle);
9682:
1.101 raeburn 9683: } else {
9684: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9685: }
1.72 raeburn 9686: } else {
1.104 raeburn 9687: if ($type eq '_LC_adv') {
1.163 raeburn 9688: if ($inconf{$type} eq '0') {
1.104 raeburn 9689: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9690: } else {
9691: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9692: }
9693: } else {
9694: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9695: }
1.72 raeburn 9696: }
9697: }
1.26 raeburn 9698: }
1.163 raeburn 9699: unless ($context eq 'requestauthor') {
9700: $resulttext .= '</ul></li>';
9701: }
1.26 raeburn 9702: }
1.1 raeburn 9703: }
1.163 raeburn 9704: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9705: if (ref($changes{'notify'}) eq 'HASH') {
9706: if ($changes{'notify'}{'approval'}) {
9707: if (ref($confhash{'notify'}) eq 'HASH') {
9708: if ($confhash{'notify'}{'approval'}) {
9709: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9710: } else {
1.163 raeburn 9711: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9712: }
9713: }
9714: }
9715: }
9716: }
1.216 raeburn 9717: if ($action eq 'requestcourses') {
9718: my @offon = ('off','on');
9719: if ($changes{'uniquecode'}) {
1.218 raeburn 9720: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9721: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9722: $resulttext .= '<li>'.
9723: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9724: '</li>';
9725: } else {
9726: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9727: '</li>';
9728: }
1.216 raeburn 9729: }
1.242 raeburn 9730: foreach my $type ('textbooks','templates') {
9731: if (ref($changes{$type}) eq 'HASH') {
9732: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9733: foreach my $key (sort(keys(%{$changes{$type}}))) {
9734: my %coursehash = &Apache::lonnet::coursedescription($key);
9735: my $coursetitle = $coursehash{'description'};
9736: my $position = $confhash{$type}{$key}{'order'} + 1;
9737: $resulttext .= '<li>';
1.243 raeburn 9738: foreach my $item ('subject','title','publisher','author') {
9739: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9740: ($type eq 'templates'));
1.242 raeburn 9741: my $name = $item.':';
9742: $name =~ s/^(\w)/\U$1/;
9743: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9744: }
9745: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9746: if ($type eq 'textbooks') {
9747: if ($confhash{$type}{$key}{'image'}) {
9748: $resulttext .= ' '.&mt('Image: [_1]',
9749: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9750: ' alt="Textbook cover" />').'<br />';
9751: }
9752: }
9753: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 9754: }
1.242 raeburn 9755: $resulttext .= '</ul></li>';
1.216 raeburn 9756: }
9757: }
1.235 raeburn 9758: if (ref($changes{'validation'}) eq 'HASH') {
9759: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9760: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9761: foreach my $item (@{$validationitemsref}) {
9762: if (exists($changes{'validation'}{$item})) {
9763: if ($item eq 'markup') {
9764: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9765: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9766: } else {
9767: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9768: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9769: }
9770: }
9771: }
9772: if (exists($changes{'validation'}{'dc'})) {
9773: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9774: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9775: }
9776: }
9777: }
1.216 raeburn 9778: }
1.1 raeburn 9779: $resulttext .= '</ul>';
1.80 raeburn 9780: if (keys(%newenv)) {
9781: &Apache::lonnet::appenv(\%newenv);
9782: }
1.1 raeburn 9783: } else {
1.86 raeburn 9784: if ($context eq 'requestcourses') {
9785: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 9786: } elsif ($context eq 'requestauthor') {
9787: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9788: } else {
1.90 weissno 9789: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9790: }
1.1 raeburn 9791: }
9792: } else {
1.11 albertel 9793: $resulttext = '<span class="LC_error">'.
9794: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9795: }
1.216 raeburn 9796: if ($errors) {
9797: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9798: '<ul>'.$errors.'</ul></p>';
9799: }
1.3 raeburn 9800: return $resulttext;
1.1 raeburn 9801: }
9802:
1.216 raeburn 9803: sub process_textbook_image {
1.242 raeburn 9804: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 9805: my $filename = $env{'form.'.$caller.'.filename'};
9806: my ($error,$url);
9807: my ($width,$height) = (50,50);
9808: if ($configuserok eq 'ok') {
9809: if ($switchserver) {
9810: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9811: $switchserver);
9812: } elsif ($author_ok eq 'ok') {
9813: my ($result,$imageurl) =
9814: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 9815: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 9816: if ($result eq 'ok') {
9817: $url = $imageurl;
9818: } else {
9819: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9820: }
9821: } else {
9822: $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);
9823: }
9824: } else {
9825: $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);
9826: }
9827: return ($url,$error);
9828: }
9829:
1.267 raeburn 9830: sub modify_ltitools {
9831: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9832: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 9833: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 9834: my $confname = $dom.'-domainconfig';
9835: my $servadm = $r->dir_config('lonAdmEMail');
9836: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9837: my (%posslti,%possfield);
9838: my @courseroles = ('cc','in','ta','ep','st');
9839: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9840: map { $posslti{$_} = 1; } @ltiroles;
9841: my @allfields = ('fullname','firstname','lastname','email','user','roles');
9842: map { $possfield{$_} = 1; } @allfields;
9843: my %lt = <itools_names();
9844: if ($env{'form.ltitools_add'}) {
9845: my $title = $env{'form.ltitools_add_title'};
9846: $title =~ s/(`)/'/g;
9847: ($newid,my $error) = &get_ltitools_id($dom,$title);
9848: if ($newid) {
9849: my $position = $env{'form.ltitools_add_pos'};
9850: $position =~ s/\D+//g;
9851: if ($position ne '') {
9852: $allpos[$position] = $newid;
9853: }
9854: $changes{$newid} = 1;
9855: foreach my $item ('title','url','key','secret') {
9856: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9857: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 9858: if (($item eq 'key') || ($item eq 'secret')) {
9859: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9860: } else {
9861: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9862: }
1.267 raeburn 9863: }
9864: }
9865: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9866: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9867: }
9868: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9869: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9870: }
1.296 raeburn 9871: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 9872: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9873: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 9874: if (($item eq 'width') || ($item eq 'height')) {
9875: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9876: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9877: }
9878: } else {
9879: if ($env{'form.ltitools_add_'.$item} ne '') {
9880: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9881: }
1.267 raeburn 9882: }
9883: }
9884: if ($env{'form.ltitools_add_target'} eq 'window') {
9885: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 9886: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
9887: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 9888: } else {
9889: $confhash{$newid}{'display'}{'target'} = 'iframe';
9890: }
9891: foreach my $item ('passback','roster') {
9892: if ($env{'form.ltitools_add_'.$item}) {
9893: $confhash{$newid}{$item} = 1;
9894: }
9895: }
9896: if ($env{'form.ltitools_add_image.filename'} ne '') {
9897: my ($imageurl,$error) =
1.307 raeburn 9898: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267 raeburn 9899: $configuserok,$switchserver,$author_ok);
9900: if ($imageurl) {
9901: $confhash{$newid}{'image'} = $imageurl;
9902: }
9903: if ($error) {
9904: &Apache::lonnet::logthis($error);
9905: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9906: }
9907: }
9908: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9909: foreach my $field (@fields) {
9910: if ($possfield{$field}) {
9911: if ($field eq 'roles') {
9912: foreach my $role (@courseroles) {
9913: my $choice = $env{'form.ltitools_add_roles_'.$role};
9914: if (($choice ne '') && ($posslti{$choice})) {
9915: $confhash{$newid}{'roles'}{$role} = $choice;
9916: if ($role eq 'cc') {
9917: $confhash{$newid}{'roles'}{'co'} = $choice;
9918: }
9919: }
9920: }
9921: } else {
9922: $confhash{$newid}{'fields'}{$field} = 1;
9923: }
9924: }
9925: }
1.273 raeburn 9926: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9927: foreach my $item (@courseconfig) {
9928: $confhash{$newid}{'crsconf'}{$item} = 1;
9929: }
1.267 raeburn 9930: if ($env{'form.ltitools_add_custom'}) {
9931: my $name = $env{'form.ltitools_add_custom_name'};
9932: my $value = $env{'form.ltitools_add_custom_value'};
9933: $value =~ s/(`)/'/g;
9934: $name =~ s/(`)/'/g;
9935: $confhash{$newid}{'custom'}{$name} = $value;
9936: }
9937: } else {
9938: my $error = &mt('Failed to acquire unique ID for new external tool');
9939: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9940: }
9941: }
9942: if (ref($domconfig{$action}) eq 'HASH') {
9943: my %deletions;
9944: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9945: if (@todelete) {
9946: map { $deletions{$_} = 1; } @todelete;
9947: }
9948: my %customadds;
9949: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9950: if (@newcustom) {
9951: map { $customadds{$_} = 1; } @newcustom;
9952: }
9953: my %imgdeletions;
9954: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9955: if (@todeleteimages) {
9956: map { $imgdeletions{$_} = 1; } @todeleteimages;
9957: }
9958: my $maxnum = $env{'form.ltitools_maxnum'};
9959: for (my $i=0; $i<=$maxnum; $i++) {
9960: my $itemid = $env{'form.ltitools_id_'.$i};
1.308 raeburn 9961: $itemid =~ s/\D+//g;
1.267 raeburn 9962: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9963: if ($deletions{$itemid}) {
9964: if ($domconfig{$action}{$itemid}{'image'}) {
9965: #FIXME need to obsolete item in RES space
9966: }
9967: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9968: next;
9969: } else {
9970: my $newpos = $env{'form.ltitools_'.$itemid};
9971: $newpos =~ s/\D+//g;
1.297 raeburn 9972: foreach my $item ('title','url') {
1.267 raeburn 9973: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9974: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9975: $changes{$itemid} = 1;
9976: }
9977: }
1.297 raeburn 9978: foreach my $item ('key','secret') {
9979: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9980: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
9981: $changes{$itemid} = 1;
9982: }
9983: }
1.267 raeburn 9984: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9985: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9986: }
9987: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9988: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9989: }
9990: foreach my $size ('width','height') {
9991: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9992: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9993: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9994: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9995: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9996: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9997: $changes{$itemid} = 1;
9998: }
9999: } else {
10000: $changes{$itemid} = 1;
10001: }
1.296 raeburn 10002: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10003: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
10004: $changes{$itemid} = 1;
10005: }
10006: }
10007: }
10008: foreach my $item ('linktext','explanation') {
10009: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
10010: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
10011: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
10012: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
10013: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10014: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
10015: $changes{$itemid} = 1;
10016: }
10017: } else {
10018: $changes{$itemid} = 1;
10019: }
10020: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10021: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
10022: $changes{$itemid} = 1;
10023: }
1.267 raeburn 10024: }
10025: }
10026: if ($env{'form.ltitools_target_'.$i} eq 'window') {
10027: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 10028: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
10029: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 10030: } else {
10031: $confhash{$itemid}{'display'}{'target'} = 'iframe';
10032: }
10033: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
10034: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
10035: $changes{$itemid} = 1;
10036: }
10037: } else {
10038: $changes{$itemid} = 1;
10039: }
10040: foreach my $extra ('passback','roster') {
10041: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
10042: $confhash{$itemid}{$extra} = 1;
10043: }
10044: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
10045: $changes{$itemid} = 1;
10046: }
10047: }
1.273 raeburn 10048: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.296 raeburn 10049: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 10050: if (grep(/^\Q$item\E$/,@courseconfig)) {
10051: $confhash{$itemid}{'crsconf'}{$item} = 1;
10052: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
10053: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
10054: $changes{$itemid} = 1;
10055: }
10056: } else {
10057: $changes{$itemid} = 1;
10058: }
10059: }
10060: }
1.267 raeburn 10061: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
10062: foreach my $field (@fields) {
10063: if ($possfield{$field}) {
10064: if ($field eq 'roles') {
10065: foreach my $role (@courseroles) {
10066: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
10067: if (($choice ne '') && ($posslti{$choice})) {
10068: $confhash{$itemid}{'roles'}{$role} = $choice;
10069: if ($role eq 'cc') {
10070: $confhash{$itemid}{'roles'}{'co'} = $choice;
10071: }
10072: }
10073: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
10074: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
10075: $changes{$itemid} = 1;
10076: }
10077: } elsif ($confhash{$itemid}{'roles'}{$role}) {
10078: $changes{$itemid} = 1;
10079: }
10080: }
10081: } else {
10082: $confhash{$itemid}{'fields'}{$field} = 1;
10083: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
10084: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
10085: $changes{$itemid} = 1;
10086: }
10087: } else {
10088: $changes{$itemid} = 1;
10089: }
10090: }
10091: }
10092: }
10093: $allpos[$newpos] = $itemid;
10094: }
10095: if ($imgdeletions{$itemid}) {
10096: $changes{$itemid} = 1;
10097: #FIXME need to obsolete item in RES space
10098: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
10099: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
10100: $itemid,$configuserok,$switchserver,
10101: $author_ok);
10102: if ($imgurl) {
10103: $confhash{$itemid}{'image'} = $imgurl;
10104: $changes{$itemid} = 1;
10105: }
10106: if ($error) {
10107: &Apache::lonnet::logthis($error);
10108: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10109: }
10110: } elsif ($domconfig{$action}{$itemid}{'image'}) {
10111: $confhash{$itemid}{'image'} =
10112: $domconfig{$action}{$itemid}{'image'};
10113: }
10114: if ($customadds{$i}) {
10115: my $name = $env{'form.ltitools_custom_name_'.$i};
10116: $name =~ s/(`)/'/g;
10117: $name =~ s/^\s+//;
10118: $name =~ s/\s+$//;
10119: my $value = $env{'form.ltitools_custom_value_'.$i};
10120: $value =~ s/(`)/'/g;
10121: $value =~ s/^\s+//;
10122: $value =~ s/\s+$//;
10123: if ($name ne '') {
10124: $confhash{$itemid}{'custom'}{$name} = $value;
10125: $changes{$itemid} = 1;
10126: }
10127: }
10128: my %customdels;
10129: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
10130: if (@customdeletions) {
10131: $changes{$itemid} = 1;
10132: }
10133: map { $customdels{$_} = 1; } @customdeletions;
10134: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
10135: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
10136: unless ($customdels{$key}) {
10137: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
10138: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
10139: }
10140: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
10141: $changes{$itemid} = 1;
10142: }
10143: }
10144: }
10145: }
10146: unless ($changes{$itemid}) {
10147: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
10148: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
10149: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
10150: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
10151: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
10152: $changes{$itemid} = 1;
10153: last;
10154: }
10155: }
10156: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
10157: $changes{$itemid} = 1;
10158: }
10159: }
10160: last if ($changes{$itemid});
10161: }
10162: }
10163: }
10164: }
10165: }
10166: if (@allpos > 0) {
10167: my $idx = 0;
10168: foreach my $itemid (@allpos) {
10169: if ($itemid ne '') {
10170: $confhash{$itemid}{'order'} = $idx;
10171: if (ref($domconfig{$action}) eq 'HASH') {
10172: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
10173: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
10174: $changes{$itemid} = 1;
10175: }
10176: }
10177: }
10178: $idx ++;
10179: }
10180: }
10181: }
10182: my %ltitoolshash = (
10183: $action => { %confhash }
10184: );
10185: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
10186: $dom);
10187: if ($putresult eq 'ok') {
1.297 raeburn 10188: my %ltienchash = (
10189: $action => { %encconfig }
10190: );
10191: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 10192: if (keys(%changes) > 0) {
10193: my $cachetime = 24*60*60;
1.297 raeburn 10194: my %ltiall = %confhash;
10195: foreach my $id (keys(%ltiall)) {
10196: if (ref($encconfig{$id}) eq 'HASH') {
10197: foreach my $item ('key','secret') {
10198: $ltiall{$id}{$item} = $encconfig{$id}{$item};
10199: }
10200: }
10201: }
10202: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 10203: if (ref($lastactref) eq 'HASH') {
10204: $lastactref->{'ltitools'} = 1;
10205: }
10206: $resulttext = &mt('Changes made:').'<ul>';
10207: my %bynum;
10208: foreach my $itemid (sort(keys(%changes))) {
10209: my $position = $confhash{$itemid}{'order'};
10210: $bynum{$position} = $itemid;
10211: }
10212: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10213: my $itemid = $bynum{$pos};
10214: if (ref($confhash{$itemid}) ne 'HASH') {
10215: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10216: } else {
10217: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
10218: if ($confhash{$itemid}{'image'}) {
10219: $resulttext .= ' '.
10220: '<img src="'.$confhash{$itemid}{'image'}.'"'.
10221: ' alt="'.&mt('Tool Provider icon').'" />';
10222: }
10223: $resulttext .= '</li><ul>';
10224: my $position = $pos + 1;
10225: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.297 raeburn 10226: foreach my $item ('version','msgtype','url') {
1.267 raeburn 10227: if ($confhash{$itemid}{$item} ne '') {
10228: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
10229: }
10230: }
1.297 raeburn 10231: if ($encconfig{$itemid}{'key'} ne '') {
10232: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
10233: }
10234: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 10235: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 10236: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 10237: $resulttext .= ('*'x$num).'</li>';
10238: }
1.273 raeburn 10239: $resulttext .= '<li>'.&mt('Configurable in course:');
1.296 raeburn 10240: my @possconfig = ('label','title','target','linktext','explanation');
1.273 raeburn 10241: my $numconfig = 0;
10242: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
10243: foreach my $item (@possconfig) {
10244: if ($confhash{$itemid}{'crsconf'}{$item}) {
10245: $numconfig ++;
1.296 raeburn 10246: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 10247: }
10248: }
10249: }
10250: if (!$numconfig) {
10251: $resulttext .= &mt('None');
10252: }
10253: $resulttext .= '</li>';
1.267 raeburn 10254: foreach my $item ('passback','roster') {
10255: $resulttext .= '<li>'.$lt{$item}.' ';
10256: if ($confhash{$itemid}{$item}) {
10257: $resulttext .= &mt('Yes');
10258: } else {
10259: $resulttext .= &mt('No');
10260: }
10261: $resulttext .= '</li>';
10262: }
10263: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
10264: my $displaylist;
10265: if ($confhash{$itemid}{'display'}{'target'}) {
10266: $displaylist = &mt('Display target').': '.
10267: $confhash{$itemid}{'display'}{'target'}.',';
10268: }
10269: foreach my $size ('width','height') {
10270: if ($confhash{$itemid}{'display'}{$size}) {
10271: $displaylist .= (' 'x2).$lt{$size}.': '.
10272: $confhash{$itemid}{'display'}{$size}.',';
10273: }
10274: }
10275: if ($displaylist) {
10276: $displaylist =~ s/,$//;
10277: $resulttext .= '<li>'.$displaylist.'</li>';
10278: }
1.296 raeburn 10279: foreach my $item ('linktext','explanation') {
10280: if ($confhash{$itemid}{'display'}{$item}) {
10281: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
10282: }
10283: }
10284: }
1.267 raeburn 10285: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
10286: my $fieldlist;
10287: foreach my $field (@allfields) {
10288: if ($confhash{$itemid}{'fields'}{$field}) {
10289: $fieldlist .= (' 'x2).$lt{$field}.',';
10290: }
10291: }
10292: if ($fieldlist) {
10293: $fieldlist =~ s/,$//;
10294: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
10295: }
10296: }
10297: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
10298: my $rolemaps;
10299: foreach my $role (@courseroles) {
10300: if ($confhash{$itemid}{'roles'}{$role}) {
10301: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
10302: $confhash{$itemid}{'roles'}{$role}.',';
10303: }
10304: }
10305: if ($rolemaps) {
10306: $rolemaps =~ s/,$//;
10307: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
10308: }
10309: }
10310: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
10311: my $customlist;
10312: if (keys(%{$confhash{$itemid}{'custom'}})) {
10313: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
10314: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
10315: }
10316: }
10317: if ($customlist) {
10318: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
10319: }
10320: }
10321: $resulttext .= '</ul></li>';
10322: }
10323: }
10324: $resulttext .= '</ul>';
10325: } else {
10326: $resulttext = &mt('No changes made.');
10327: }
10328: } else {
10329: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10330: }
10331: if ($errors) {
10332: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10333: $errors.'</ul>';
10334: }
10335: return $resulttext;
10336: }
10337:
10338: sub process_ltitools_image {
10339: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
10340: my $filename = $env{'form.'.$caller.'.filename'};
10341: my ($error,$url);
10342: my ($width,$height) = (21,21);
10343: if ($configuserok eq 'ok') {
10344: if ($switchserver) {
10345: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
10346: $switchserver);
10347: } elsif ($author_ok eq 'ok') {
10348: my ($result,$imageurl,$madethumb) =
10349: &publishlogo($r,'upload',$caller,$dom,$confname,
10350: "ltitools/$itemid/icon",$width,$height);
10351: if ($result eq 'ok') {
10352: if ($madethumb) {
10353: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
10354: my $imagethumb = "$path/tn-".$imagefile;
10355: $url = $imagethumb;
10356: } else {
10357: $url = $imageurl;
10358: }
10359: } else {
10360: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10361: }
10362: } else {
10363: $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);
10364: }
10365: } else {
10366: $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);
10367: }
10368: return ($url,$error);
10369: }
10370:
10371: sub get_ltitools_id {
10372: my ($cdom,$title) = @_;
10373: # get lock on ltitools db
10374: my $lockhash = {
10375: lock => $env{'user.name'}.
10376: ':'.$env{'user.domain'},
10377: };
10378: my $tries = 0;
10379: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10380: my ($id,$error);
10381:
10382: while (($gotlock ne 'ok') && ($tries<10)) {
10383: $tries ++;
10384: sleep (0.1);
10385: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10386: }
10387: if ($gotlock eq 'ok') {
10388: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
10389: if ($currids{'lock'}) {
10390: delete($currids{'lock'});
10391: if (keys(%currids)) {
10392: my @curr = sort { $a <=> $b } keys(%currids);
10393: if ($curr[-1] =~ /^\d+$/) {
10394: $id = 1 + $curr[-1];
10395: }
10396: } else {
10397: $id = 1;
10398: }
10399: if ($id) {
10400: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
10401: $error = 'nostore';
10402: }
10403: } else {
10404: $error = 'nonumber';
10405: }
10406: }
10407: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
10408: } else {
10409: $error = 'nolock';
10410: }
10411: return ($id,$error);
10412: }
10413:
1.3 raeburn 10414: sub modify_autoenroll {
1.205 raeburn 10415: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 10416: my ($resulttext,%changes);
10417: my %currautoenroll;
10418: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
10419: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
10420: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
10421: }
10422: }
10423: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
10424: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 10425: sender => 'Sender for notification messages',
1.274 raeburn 10426: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
10427: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 10428: my @offon = ('off','on');
1.17 raeburn 10429: my $sender_uname = $env{'form.sender_uname'};
10430: my $sender_domain = $env{'form.sender_domain'};
10431: if ($sender_domain eq '') {
10432: $sender_uname = '';
10433: } elsif ($sender_uname eq '') {
10434: $sender_domain = '';
10435: }
1.129 raeburn 10436: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 10437: my $failsafe = $env{'form.autoenroll_failsafe'};
10438: $failsafe =~ s{^\s+|\s+$}{}g;
10439: if ($failsafe =~ /\D/) {
10440: undef($failsafe);
10441: }
1.1 raeburn 10442: my %autoenrollhash = (
1.129 raeburn 10443: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10444: 'sender_uname' => $sender_uname,
10445: 'sender_domain' => $sender_domain,
10446: 'co-owners' => $coowners,
1.274 raeburn 10447: 'autofailsafe' => $failsafe,
1.1 raeburn 10448: }
10449: );
1.4 raeburn 10450: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10451: $dom);
1.1 raeburn 10452: if ($putresult eq 'ok') {
10453: if (exists($currautoenroll{'run'})) {
10454: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10455: $changes{'run'} = 1;
10456: }
10457: } elsif ($autorun) {
10458: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 10459: $changes{'run'} = 1;
1.1 raeburn 10460: }
10461: }
1.17 raeburn 10462: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 10463: $changes{'sender'} = 1;
10464: }
1.17 raeburn 10465: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 10466: $changes{'sender'} = 1;
10467: }
1.129 raeburn 10468: if ($currautoenroll{'co-owners'} ne '') {
10469: if ($currautoenroll{'co-owners'} ne $coowners) {
10470: $changes{'coowners'} = 1;
10471: }
10472: } elsif ($coowners) {
10473: $changes{'coowners'} = 1;
1.274 raeburn 10474: }
10475: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10476: $changes{'autofailsafe'} = 1;
10477: }
1.1 raeburn 10478: if (keys(%changes) > 0) {
10479: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 10480: if ($changes{'run'}) {
1.1 raeburn 10481: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10482: }
10483: if ($changes{'sender'}) {
1.17 raeburn 10484: if ($sender_uname eq '' || $sender_domain eq '') {
10485: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10486: } else {
10487: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10488: }
1.1 raeburn 10489: }
1.129 raeburn 10490: if ($changes{'coowners'}) {
10491: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10492: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10493: if (ref($lastactref) eq 'HASH') {
10494: $lastactref->{'domainconfig'} = 1;
10495: }
1.129 raeburn 10496: }
1.274 raeburn 10497: if ($changes{'autofailsafe'}) {
10498: if ($failsafe ne '') {
1.299 raeburn 10499: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 10500: } else {
1.299 raeburn 10501: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 10502: }
10503: &Apache::lonnet::get_domain_defaults($dom,1);
10504: if (ref($lastactref) eq 'HASH') {
10505: $lastactref->{'domdefaults'} = 1;
10506: }
10507: }
1.1 raeburn 10508: $resulttext .= '</ul>';
10509: } else {
10510: $resulttext = &mt('No changes made to auto-enrollment settings');
10511: }
10512: } else {
1.11 albertel 10513: $resulttext = '<span class="LC_error">'.
10514: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10515: }
1.3 raeburn 10516: return $resulttext;
1.1 raeburn 10517: }
10518:
10519: sub modify_autoupdate {
1.3 raeburn 10520: my ($dom,%domconfig) = @_;
1.1 raeburn 10521: my ($resulttext,%currautoupdate,%fields,%changes);
10522: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10523: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10524: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10525: }
10526: }
10527: my @offon = ('off','on');
10528: my %title = &Apache::lonlocal::texthash (
10529: run => 'Auto-update:',
10530: classlists => 'Updates to user information in classlists?'
10531: );
1.44 raeburn 10532: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10533: my %fieldtitles = &Apache::lonlocal::texthash (
10534: id => 'Student/Employee ID',
1.20 raeburn 10535: permanentemail => 'E-mail address',
1.1 raeburn 10536: lastname => 'Last Name',
10537: firstname => 'First Name',
10538: middlename => 'Middle Name',
1.132 raeburn 10539: generation => 'Generation',
1.1 raeburn 10540: );
1.142 raeburn 10541: $othertitle = &mt('All users');
1.1 raeburn 10542: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10543: $othertitle = &mt('Other users');
1.1 raeburn 10544: }
10545: foreach my $key (keys(%env)) {
10546: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10547: my ($usertype,$item) = ($1,$2);
10548: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10549: if ($usertype eq 'default') {
10550: push(@{$fields{$1}},$2);
10551: } elsif (ref($types) eq 'ARRAY') {
10552: if (grep(/^\Q$usertype\E$/,@{$types})) {
10553: push(@{$fields{$1}},$2);
10554: }
10555: }
10556: }
1.1 raeburn 10557: }
10558: }
1.131 raeburn 10559: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10560: @lockablenames = sort(@lockablenames);
10561: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10562: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10563: if (@changed) {
10564: $changes{'lockablenames'} = 1;
10565: }
10566: } else {
10567: if (@lockablenames) {
10568: $changes{'lockablenames'} = 1;
10569: }
10570: }
1.1 raeburn 10571: my %updatehash = (
10572: autoupdate => { run => $env{'form.autoupdate_run'},
10573: classlists => $env{'form.classlists'},
10574: fields => {%fields},
1.131 raeburn 10575: lockablenames => \@lockablenames,
1.1 raeburn 10576: }
10577: );
10578: foreach my $key (keys(%currautoupdate)) {
10579: if (($key eq 'run') || ($key eq 'classlists')) {
10580: if (exists($updatehash{autoupdate}{$key})) {
10581: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10582: $changes{$key} = 1;
10583: }
10584: }
10585: } elsif ($key eq 'fields') {
10586: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10587: foreach my $item (@{$types},'default') {
1.1 raeburn 10588: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10589: my $change = 0;
10590: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10591: if (!exists($fields{$item})) {
10592: $change = 1;
1.132 raeburn 10593: last;
1.1 raeburn 10594: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10595: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10596: $change = 1;
1.132 raeburn 10597: last;
1.1 raeburn 10598: }
10599: }
10600: }
10601: if ($change) {
10602: push(@{$changes{$key}},$item);
10603: }
1.26 raeburn 10604: }
1.1 raeburn 10605: }
10606: }
1.131 raeburn 10607: } elsif ($key eq 'lockablenames') {
10608: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10609: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10610: if (@changed) {
10611: $changes{'lockablenames'} = 1;
10612: }
10613: } else {
10614: if (@lockablenames) {
10615: $changes{'lockablenames'} = 1;
10616: }
10617: }
10618: }
10619: }
10620: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10621: if (@lockablenames) {
10622: $changes{'lockablenames'} = 1;
1.1 raeburn 10623: }
10624: }
1.26 raeburn 10625: foreach my $item (@{$types},'default') {
10626: if (defined($fields{$item})) {
10627: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10628: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10629: my $change = 0;
10630: if (ref($fields{$item}) eq 'ARRAY') {
10631: foreach my $type (@{$fields{$item}}) {
10632: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10633: $change = 1;
10634: last;
10635: }
10636: }
10637: }
10638: if ($change) {
10639: push(@{$changes{'fields'}},$item);
10640: }
10641: } else {
1.26 raeburn 10642: push(@{$changes{'fields'}},$item);
10643: }
10644: } else {
10645: push(@{$changes{'fields'}},$item);
1.1 raeburn 10646: }
10647: }
10648: }
10649: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10650: $dom);
10651: if ($putresult eq 'ok') {
10652: if (keys(%changes) > 0) {
10653: $resulttext = &mt('Changes made:').'<ul>';
10654: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10655: if ($key eq 'lockablenames') {
10656: $resulttext .= '<li>';
10657: if (@lockablenames) {
10658: $usertypes->{'default'} = $othertitle;
10659: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10660: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10661: } else {
10662: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10663: }
10664: $resulttext .= '</li>';
10665: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10666: foreach my $item (@{$changes{$key}}) {
10667: my @newvalues;
10668: foreach my $type (@{$fields{$item}}) {
10669: push(@newvalues,$fieldtitles{$type});
10670: }
1.3 raeburn 10671: my $newvaluestr;
10672: if (@newvalues > 0) {
10673: $newvaluestr = join(', ',@newvalues);
10674: } else {
10675: $newvaluestr = &mt('none');
1.6 raeburn 10676: }
1.1 raeburn 10677: if ($item eq 'default') {
1.26 raeburn 10678: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10679: } else {
1.26 raeburn 10680: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10681: }
10682: }
10683: } else {
10684: my $newvalue;
10685: if ($key eq 'run') {
10686: $newvalue = $offon[$env{'form.autoupdate_run'}];
10687: } else {
10688: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10689: }
1.1 raeburn 10690: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10691: }
10692: }
10693: $resulttext .= '</ul>';
10694: } else {
1.3 raeburn 10695: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10696: }
10697: } else {
1.11 albertel 10698: $resulttext = '<span class="LC_error">'.
10699: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10700: }
1.3 raeburn 10701: return $resulttext;
1.1 raeburn 10702: }
10703:
1.125 raeburn 10704: sub modify_autocreate {
10705: my ($dom,%domconfig) = @_;
10706: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10707: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10708: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10709: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10710: }
10711: }
10712: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10713: req => 'Auto-creation of validated requests for official courses',
10714: xmldc => 'Identity of course creator of courses from XML files',
10715: );
10716: my @types = ('xml','req');
10717: foreach my $item (@types) {
10718: $newvals{$item} = $env{'form.autocreate_'.$item};
10719: $newvals{$item} =~ s/\D//g;
10720: $newvals{$item} = 0 if ($newvals{$item} eq '');
10721: }
10722: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 10723: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10724: unless (exists($domcoords{$newvals{'xmldc'}})) {
10725: $newvals{'xmldc'} = '';
10726: }
10727: %autocreatehash = (
10728: autocreate => { xml => $newvals{'xml'},
10729: req => $newvals{'req'},
10730: }
10731: );
10732: if ($newvals{'xmldc'} ne '') {
10733: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10734: }
10735: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10736: $dom);
10737: if ($putresult eq 'ok') {
10738: my @items = @types;
10739: if ($newvals{'xml'}) {
10740: push(@items,'xmldc');
10741: }
10742: foreach my $item (@items) {
10743: if (exists($currautocreate{$item})) {
10744: if ($currautocreate{$item} ne $newvals{$item}) {
10745: $changes{$item} = 1;
10746: }
10747: } elsif ($newvals{$item}) {
10748: $changes{$item} = 1;
10749: }
10750: }
10751: if (keys(%changes) > 0) {
10752: my @offon = ('off','on');
10753: $resulttext = &mt('Changes made:').'<ul>';
10754: foreach my $item (@types) {
10755: if ($changes{$item}) {
10756: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 10757: $resulttext .= '<li>'.
10758: &mt("$title{$item} set to [_1]$newtxt [_2]",
10759: '<b>','</b>').
10760: '</li>';
1.125 raeburn 10761: }
10762: }
10763: if ($changes{'xmldc'}) {
10764: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10765: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 10766: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10767: }
10768: $resulttext .= '</ul>';
10769: } else {
10770: $resulttext = &mt('No changes made to auto-creation settings');
10771: }
10772: } else {
10773: $resulttext = '<span class="LC_error">'.
10774: &mt('An error occurred: [_1]',$putresult).'</span>';
10775: }
10776: return $resulttext;
10777: }
10778:
1.23 raeburn 10779: sub modify_directorysrch {
1.295 raeburn 10780: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10781: my ($resulttext,%changes);
10782: my %currdirsrch;
10783: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10784: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10785: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10786: }
10787: }
1.277 raeburn 10788: my %title = ( available => 'Institutional directory search available',
10789: localonly => 'Other domains can search institution',
10790: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 10791: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10792: searchby => 'Search types',
10793: searchtypes => 'Search latitude');
10794: my @offon = ('off','on');
1.24 raeburn 10795: my @otherdoms = ('Yes','No');
1.23 raeburn 10796:
1.25 raeburn 10797: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10798: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10799: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10800:
1.44 raeburn 10801: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10802: if (keys(%{$usertypes}) == 0) {
10803: @cansearch = ('default');
10804: } else {
10805: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10806: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10807: if (!grep(/^\Q$type\E$/,@cansearch)) {
10808: push(@{$changes{'cansearch'}},$type);
10809: }
1.23 raeburn 10810: }
1.26 raeburn 10811: foreach my $type (@cansearch) {
10812: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10813: push(@{$changes{'cansearch'}},$type);
10814: }
1.23 raeburn 10815: }
1.26 raeburn 10816: } else {
10817: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10818: }
10819: }
10820:
10821: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10822: foreach my $by (@{$currdirsrch{'searchby'}}) {
10823: if (!grep(/^\Q$by\E$/,@searchby)) {
10824: push(@{$changes{'searchby'}},$by);
10825: }
10826: }
10827: foreach my $by (@searchby) {
10828: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10829: push(@{$changes{'searchby'}},$by);
10830: }
10831: }
10832: } else {
10833: push(@{$changes{'searchby'}},@searchby);
10834: }
1.25 raeburn 10835:
10836: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10837: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10838: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10839: push(@{$changes{'searchtypes'}},$type);
10840: }
10841: }
10842: foreach my $type (@searchtypes) {
10843: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10844: push(@{$changes{'searchtypes'}},$type);
10845: }
10846: }
10847: } else {
10848: if (exists($currdirsrch{'searchtypes'})) {
10849: foreach my $type (@searchtypes) {
10850: if ($type ne $currdirsrch{'searchtypes'}) {
10851: push(@{$changes{'searchtypes'}},$type);
10852: }
10853: }
10854: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10855: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10856: }
10857: } else {
10858: push(@{$changes{'searchtypes'}},@searchtypes);
10859: }
10860: }
10861:
1.23 raeburn 10862: my %dirsrch_hash = (
10863: directorysrch => { available => $env{'form.dirsrch_available'},
10864: cansearch => \@cansearch,
1.277 raeburn 10865: localonly => $env{'form.dirsrch_instlocalonly'},
10866: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10867: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10868: searchby => \@searchby,
1.25 raeburn 10869: searchtypes => \@searchtypes,
1.23 raeburn 10870: }
10871: );
10872: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10873: $dom);
10874: if ($putresult eq 'ok') {
10875: if (exists($currdirsrch{'available'})) {
10876: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10877: $changes{'available'} = 1;
10878: }
10879: } else {
10880: if ($env{'form.dirsrch_available'} eq '1') {
10881: $changes{'available'} = 1;
10882: }
10883: }
1.277 raeburn 10884: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 10885: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10886: $changes{'lcavailable'} = 1;
10887: }
1.277 raeburn 10888: } else {
10889: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10890: $changes{'lcavailable'} = 1;
10891: }
10892: }
1.24 raeburn 10893: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 10894: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
10895: $changes{'localonly'} = 1;
10896: }
1.24 raeburn 10897: } else {
1.277 raeburn 10898: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 10899: $changes{'localonly'} = 1;
10900: }
10901: }
1.277 raeburn 10902: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 10903: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10904: $changes{'lclocalonly'} = 1;
10905: }
1.277 raeburn 10906: } else {
10907: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10908: $changes{'lclocalonly'} = 1;
10909: }
10910: }
1.23 raeburn 10911: if (keys(%changes) > 0) {
10912: $resulttext = &mt('Changes made:').'<ul>';
10913: if ($changes{'available'}) {
10914: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10915: }
1.277 raeburn 10916: if ($changes{'lcavailable'}) {
10917: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10918: }
1.24 raeburn 10919: if ($changes{'localonly'}) {
1.277 raeburn 10920: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 10921: }
1.277 raeburn 10922: if ($changes{'lclocalonly'}) {
10923: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 10924: }
1.23 raeburn 10925: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10926: my $chgtext;
1.26 raeburn 10927: if (ref($usertypes) eq 'HASH') {
10928: if (keys(%{$usertypes}) > 0) {
10929: foreach my $type (@{$types}) {
10930: if (grep(/^\Q$type\E$/,@cansearch)) {
10931: $chgtext .= $usertypes->{$type}.'; ';
10932: }
10933: }
10934: if (grep(/^default$/,@cansearch)) {
10935: $chgtext .= $othertitle;
10936: } else {
10937: $chgtext =~ s/\; $//;
10938: }
1.210 raeburn 10939: $resulttext .=
1.178 raeburn 10940: '<li>'.
10941: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10942: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10943: '</li>';
1.23 raeburn 10944: }
10945: }
10946: }
10947: if (ref($changes{'searchby'}) eq 'ARRAY') {
10948: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10949: my $chgtext;
10950: foreach my $type (@{$titleorder}) {
10951: if (grep(/^\Q$type\E$/,@searchby)) {
10952: if (defined($searchtitles->{$type})) {
10953: $chgtext .= $searchtitles->{$type}.'; ';
10954: }
10955: }
10956: }
10957: $chgtext =~ s/\; $//;
10958: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10959: }
1.25 raeburn 10960: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10961: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10962: my $chgtext;
10963: foreach my $type (@{$srchtypeorder}) {
10964: if (grep(/^\Q$type\E$/,@searchtypes)) {
10965: if (defined($srchtypes_desc->{$type})) {
10966: $chgtext .= $srchtypes_desc->{$type}.'; ';
10967: }
10968: }
10969: }
10970: $chgtext =~ s/\; $//;
1.178 raeburn 10971: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10972: }
10973: $resulttext .= '</ul>';
1.295 raeburn 10974: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10975: if (ref($lastactref) eq 'HASH') {
10976: $lastactref->{'directorysrch'} = 1;
10977: }
1.23 raeburn 10978: } else {
1.277 raeburn 10979: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10980: }
10981: } else {
10982: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10983: &mt('An error occurred: [_1]',$putresult).'</span>';
10984: }
10985: return $resulttext;
10986: }
10987:
1.28 raeburn 10988: sub modify_contacts {
1.205 raeburn 10989: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10990: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10991: if (ref($domconfig{'contacts'}) eq 'HASH') {
10992: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10993: $currsetting{$key} = $domconfig{'contacts'}{$key};
10994: }
10995: }
1.286 raeburn 10996: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10997: my @contacts = ('supportemail','adminemail');
1.286 raeburn 10998: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10999: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 11000: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 11001: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 11002: foreach my $type (@mailings) {
11003: @{$newsetting{$type}} =
11004: &Apache::loncommon::get_env_multiple('form.'.$type);
11005: foreach my $item (@contacts) {
11006: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
11007: $contacts_hash{contacts}{$type}{$item} = 1;
11008: } else {
11009: $contacts_hash{contacts}{$type}{$item} = 0;
11010: }
1.289 raeburn 11011: }
1.28 raeburn 11012: $others{$type} = $env{'form.'.$type.'_others'};
11013: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 11014: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11015: $bcc{$type} = $env{'form.'.$type.'_bcc'};
11016: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 11017: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
11018: $includestr{$type} = $env{'form.'.$type.'_includestr'};
11019: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
11020: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
11021: }
1.134 raeburn 11022: }
1.28 raeburn 11023: }
11024: foreach my $item (@contacts) {
11025: $to{$item} = $env{'form.'.$item};
11026: $contacts_hash{'contacts'}{$item} = $to{$item};
11027: }
1.203 raeburn 11028: foreach my $item (@toggles) {
11029: if ($env{'form.'.$item} =~ /^(0|1)$/) {
11030: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
11031: }
11032: }
1.286 raeburn 11033: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
11034: foreach my $field (@{$fields}) {
11035: if (ref($possoptions->{$field}) eq 'ARRAY') {
11036: my $value = $env{'form.helpform_'.$field};
11037: $value =~ s/^\s+|\s+$//g;
11038: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
11039: $contacts_hash{contacts}{'helpform'}{$field} = $value;
11040: if ($field eq 'screenshot') {
11041: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
11042: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
11043: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
11044: }
11045: }
11046: }
11047: }
11048: }
11049: }
1.28 raeburn 11050: if (keys(%currsetting) > 0) {
11051: foreach my $item (@contacts) {
11052: if ($to{$item} ne $currsetting{$item}) {
11053: $changes{$item} = 1;
11054: }
11055: }
11056: foreach my $type (@mailings) {
11057: foreach my $item (@contacts) {
11058: if (ref($currsetting{$type}) eq 'HASH') {
11059: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
11060: push(@{$changes{$type}},$item);
11061: }
11062: } else {
11063: push(@{$changes{$type}},@{$newsetting{$type}});
11064: }
11065: }
11066: if ($others{$type} ne $currsetting{$type}{'others'}) {
11067: push(@{$changes{$type}},'others');
11068: }
1.289 raeburn 11069: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11070: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
11071: push(@{$changes{$type}},'bcc');
11072: }
1.286 raeburn 11073: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
11074: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
11075: push(@{$changes{$type}},'include');
11076: }
11077: }
11078: }
11079: if (ref($fields) eq 'ARRAY') {
11080: if (ref($currsetting{'helpform'}) eq 'HASH') {
11081: foreach my $field (@{$fields}) {
11082: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
11083: push(@{$changes{'helpform'}},$field);
11084: }
11085: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11086: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
11087: push(@{$changes{'helpform'}},'maxsize');
11088: }
11089: }
11090: }
11091: } else {
11092: foreach my $field (@{$fields}) {
11093: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11094: push(@{$changes{'helpform'}},$field);
11095: }
11096: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11097: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11098: push(@{$changes{'helpform'}},'maxsize');
11099: }
11100: }
11101: }
1.134 raeburn 11102: }
1.28 raeburn 11103: }
11104: } else {
11105: my %default;
11106: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
11107: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
11108: $default{'errormail'} = 'adminemail';
11109: $default{'packagesmail'} = 'adminemail';
11110: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 11111: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 11112: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 11113: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 11114: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 11115: foreach my $item (@contacts) {
11116: if ($to{$item} ne $default{$item}) {
1.286 raeburn 11117: $changes{$item} = 1;
1.203 raeburn 11118: }
1.28 raeburn 11119: }
11120: foreach my $type (@mailings) {
11121: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
11122: push(@{$changes{$type}},@{$newsetting{$type}});
11123: }
11124: if ($others{$type} ne '') {
11125: push(@{$changes{$type}},'others');
1.134 raeburn 11126: }
1.286 raeburn 11127: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11128: if ($bcc{$type} ne '') {
11129: push(@{$changes{$type}},'bcc');
11130: }
1.286 raeburn 11131: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
11132: push(@{$changes{$type}},'include');
11133: }
1.134 raeburn 11134: }
1.28 raeburn 11135: }
1.286 raeburn 11136: if (ref($fields) eq 'ARRAY') {
11137: foreach my $field (@{$fields}) {
11138: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
11139: push(@{$changes{'helpform'}},$field);
11140: }
11141: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
11142: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
11143: push(@{$changes{'helpform'}},'maxsize');
11144: }
11145: }
11146: }
1.289 raeburn 11147: }
1.28 raeburn 11148: }
1.203 raeburn 11149: foreach my $item (@toggles) {
11150: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
11151: $changes{$item} = 1;
11152: } elsif ((!$env{'form.'.$item}) &&
11153: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
11154: $changes{$item} = 1;
11155: }
11156: }
1.28 raeburn 11157: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
11158: $dom);
11159: if ($putresult eq 'ok') {
11160: if (keys(%changes) > 0) {
1.205 raeburn 11161: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 11162: if (ref($lastactref) eq 'HASH') {
11163: $lastactref->{'domainconfig'} = 1;
11164: }
1.28 raeburn 11165: my ($titles,$short_titles) = &contact_titles();
11166: $resulttext = &mt('Changes made:').'<ul>';
11167: foreach my $item (@contacts) {
11168: if ($changes{$item}) {
11169: $resulttext .= '<li>'.$titles->{$item}.
11170: &mt(' set to: ').
11171: '<span class="LC_cusr_emph">'.
11172: $to{$item}.'</span></li>';
11173: }
11174: }
11175: foreach my $type (@mailings) {
11176: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 11177: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 11178: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 11179: } else {
11180: $resulttext .= '<li>'.$titles->{$type}.': ';
11181: }
1.28 raeburn 11182: my @text;
11183: foreach my $item (@{$newsetting{$type}}) {
11184: push(@text,$short_titles->{$item});
11185: }
11186: if ($others{$type} ne '') {
11187: push(@text,$others{$type});
11188: }
1.286 raeburn 11189: if (@text) {
11190: $resulttext .= '<span class="LC_cusr_emph">'.
11191: join(', ',@text).'</span>';
11192: }
11193: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 11194: if ($bcc{$type} ne '') {
1.286 raeburn 11195: my $bcctext;
11196: if (@text) {
1.289 raeburn 11197: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 11198: } else {
11199: $bcctext = '(Bcc)';
11200: }
11201: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
11202: } elsif (!@text) {
11203: $resulttext .= &mt('No one');
11204: }
1.289 raeburn 11205: if ($includestr{$type} ne '') {
1.286 raeburn 11206: if ($includeloc{$type} eq 'b') {
11207: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
11208: } elsif ($includeloc{$type} eq 's') {
11209: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
11210: }
1.134 raeburn 11211: }
1.286 raeburn 11212: } elsif (!@text) {
11213: $resulttext .= &mt('No recipients');
1.134 raeburn 11214: }
11215: $resulttext .= '</li>';
1.28 raeburn 11216: }
11217: }
1.203 raeburn 11218: my @offon = ('off','on');
11219: if ($changes{'reporterrors'}) {
11220: $resulttext .= '<li>'.
11221: &mt('E-mail error reports to [_1] set to "'.
11222: $offon[$env{'form.reporterrors'}].'".',
11223: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11224: &mt('LON-CAPA core group - MSU'),600,500)).
11225: '</li>';
11226: }
11227: if ($changes{'reportupdates'}) {
11228: $resulttext .= '<li>'.
11229: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
11230: $offon[$env{'form.reportupdates'}].'".',
11231: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
11232: &mt('LON-CAPA core group - MSU'),600,500)).
11233: '</li>';
11234: }
1.286 raeburn 11235: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
11236: my (@optional,@required,@unused,$maxsizechg);
11237: foreach my $field (@{$changes{'helpform'}}) {
11238: if ($field eq 'maxsize') {
11239: $maxsizechg = 1;
11240: next;
11241: }
11242: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 11243: push(@optional,$field);
1.286 raeburn 11244: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
11245: push(@unused,$field);
11246: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 11247: push(@required,$field);
1.286 raeburn 11248: }
11249: }
11250: if (@optional) {
11251: $resulttext .= '<li>'.
11252: &mt('Help form fields changed to "Optional": [_1].',
11253: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
11254: '</li>';
11255: }
11256: if (@required) {
11257: $resulttext .= '<li>'.
11258: &mt('Help form fields changed to "Required": [_1].',
11259: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
11260: '</li>';
11261: }
11262: if (@unused) {
11263: $resulttext .= '<li>'.
11264: &mt('Help form fields changed to "Not shown": [_1].',
11265: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
11266: '</li>';
11267: }
11268: if ($maxsizechg) {
11269: $resulttext .= '<li>'.
11270: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
11271: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
11272: '</li>';
11273:
11274: }
11275: }
1.28 raeburn 11276: $resulttext .= '</ul>';
11277: } else {
1.288 raeburn 11278: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 11279: }
11280: } else {
11281: $resulttext = '<span class="LC_error">'.
11282: &mt('An error occurred: [_1].',$putresult).'</span>';
11283: }
11284: return $resulttext;
11285: }
11286:
11287: sub modify_usercreation {
1.27 raeburn 11288: my ($dom,%domconfig) = @_;
1.224 raeburn 11289: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 11290: my $warningmsg;
1.27 raeburn 11291: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11292: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 11293: if ($key eq 'cancreate') {
11294: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11295: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 11296: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
11297: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11298: } else {
1.224 raeburn 11299: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11300: }
11301: }
11302: }
11303: } elsif ($key eq 'email_rule') {
11304: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11305: } else {
11306: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11307: }
1.27 raeburn 11308: }
11309: }
11310: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 11311: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 11312: my @contexts = ('author','course','requestcrs');
1.34 raeburn 11313: foreach my $item(@contexts) {
1.224 raeburn 11314: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 11315: }
1.34 raeburn 11316: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11317: foreach my $item (@contexts) {
1.224 raeburn 11318: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
11319: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 11320: }
1.27 raeburn 11321: }
1.34 raeburn 11322: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
11323: foreach my $item (@contexts) {
1.43 raeburn 11324: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 11325: if ($cancreate{$item} ne 'any') {
11326: push(@{$changes{'cancreate'}},$item);
11327: }
11328: } else {
11329: if ($cancreate{$item} ne 'none') {
11330: push(@{$changes{'cancreate'}},$item);
11331: }
1.27 raeburn 11332: }
11333: }
11334: } else {
1.43 raeburn 11335: foreach my $item (@contexts) {
1.34 raeburn 11336: push(@{$changes{'cancreate'}},$item);
11337: }
1.27 raeburn 11338: }
1.34 raeburn 11339:
1.27 raeburn 11340: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
11341: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
11342: if (!grep(/^\Q$type\E$/,@username_rule)) {
11343: push(@{$changes{'username_rule'}},$type);
11344: }
11345: }
11346: foreach my $type (@username_rule) {
11347: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
11348: push(@{$changes{'username_rule'}},$type);
11349: }
11350: }
11351: } else {
11352: push(@{$changes{'username_rule'}},@username_rule);
11353: }
11354:
1.32 raeburn 11355: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11356: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11357: if (!grep(/^\Q$type\E$/,@id_rule)) {
11358: push(@{$changes{'id_rule'}},$type);
11359: }
11360: }
11361: foreach my $type (@id_rule) {
11362: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11363: push(@{$changes{'id_rule'}},$type);
11364: }
11365: }
11366: } else {
11367: push(@{$changes{'id_rule'}},@id_rule);
11368: }
11369:
1.43 raeburn 11370: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11371: my @authtypes = ('int','krb4','krb5','loc');
11372: my %authhash;
1.43 raeburn 11373: foreach my $item (@authen_contexts) {
1.28 raeburn 11374: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11375: foreach my $auth (@authtypes) {
11376: if (grep(/^\Q$auth\E$/,@authallowed)) {
11377: $authhash{$item}{$auth} = 1;
11378: } else {
11379: $authhash{$item}{$auth} = 0;
11380: }
11381: }
11382: }
11383: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11384: foreach my $item (@authen_contexts) {
1.28 raeburn 11385: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11386: foreach my $auth (@authtypes) {
11387: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11388: push(@{$changes{'authtypes'}},$item);
11389: last;
11390: }
11391: }
11392: }
11393: }
11394: } else {
1.43 raeburn 11395: foreach my $item (@authen_contexts) {
1.28 raeburn 11396: push(@{$changes{'authtypes'}},$item);
11397: }
11398: }
11399:
1.224 raeburn 11400: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11401: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11402: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11403: $save_usercreate{'id_rule'} = \@id_rule;
11404: $save_usercreate{'username_rule'} = \@username_rule,
11405: $save_usercreate{'authtypes'} = \%authhash;
11406:
1.27 raeburn 11407: my %usercreation_hash = (
1.224 raeburn 11408: usercreation => \%save_usercreate,
11409: );
1.27 raeburn 11410:
11411: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11412: $dom);
1.50 raeburn 11413:
1.224 raeburn 11414: if ($putresult eq 'ok') {
11415: if (keys(%changes) > 0) {
11416: $resulttext = &mt('Changes made:').'<ul>';
11417: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11418: my %lt = &usercreation_types();
11419: foreach my $type (@{$changes{'cancreate'}}) {
11420: my $chgtext = $lt{$type}.', ';
11421: if ($cancreate{$type} eq 'none') {
11422: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11423: } elsif ($cancreate{$type} eq 'any') {
11424: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11425: } elsif ($cancreate{$type} eq 'official') {
11426: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11427: } elsif ($cancreate{$type} eq 'unofficial') {
11428: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11429: }
11430: $resulttext .= '<li>'.$chgtext.'</li>';
11431: }
11432: }
11433: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11434: my ($rules,$ruleorder) =
11435: &Apache::lonnet::inst_userrules($dom,'username');
11436: my $chgtext = '<ul>';
11437: foreach my $type (@username_rule) {
11438: if (ref($rules->{$type}) eq 'HASH') {
11439: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11440: }
11441: }
11442: $chgtext .= '</ul>';
11443: if (@username_rule > 0) {
11444: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11445: } else {
11446: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11447: }
11448: }
11449: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11450: my ($idrules,$idruleorder) =
11451: &Apache::lonnet::inst_userrules($dom,'id');
11452: my $chgtext = '<ul>';
11453: foreach my $type (@id_rule) {
11454: if (ref($idrules->{$type}) eq 'HASH') {
11455: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11456: }
11457: }
11458: $chgtext .= '</ul>';
11459: if (@id_rule > 0) {
11460: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11461: } else {
11462: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11463: }
11464: }
11465: my %authname = &authtype_names();
11466: my %context_title = &context_names();
11467: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11468: my $chgtext = '<ul>';
11469: foreach my $type (@{$changes{'authtypes'}}) {
11470: my @allowed;
11471: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11472: foreach my $auth (@authtypes) {
11473: if ($authhash{$type}{$auth}) {
11474: push(@allowed,$authname{$auth});
11475: }
11476: }
11477: if (@allowed > 0) {
11478: $chgtext .= join(', ',@allowed).'</li>';
11479: } else {
11480: $chgtext .= &mt('none').'</li>';
11481: }
11482: }
11483: $chgtext .= '</ul>';
11484: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11485: $resulttext .= '</li>';
11486: }
11487: $resulttext .= '</ul>';
11488: } else {
11489: $resulttext = &mt('No changes made to user creation settings');
11490: }
11491: } else {
11492: $resulttext = '<span class="LC_error">'.
11493: &mt('An error occurred: [_1]',$putresult).'</span>';
11494: }
11495: if ($warningmsg ne '') {
11496: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11497: }
11498: return $resulttext;
11499: }
11500:
11501: sub modify_selfcreation {
1.305 raeburn 11502: my ($dom,$lastactref,%domconfig) = @_;
11503: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
11504: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
11505: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 11506: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
11507: if (ref($typesref) eq 'ARRAY') {
11508: @types = @{$typesref};
11509: }
11510: if (ref($usertypesref) eq 'HASH') {
11511: %usertypes = %{$usertypesref};
1.228 raeburn 11512: }
1.303 raeburn 11513: $usertypes{'default'} = $othertitle;
1.224 raeburn 11514: #
11515: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11516: #
11517: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11518: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11519: if ($key eq 'cancreate') {
11520: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11521: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11522: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 11523: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
11524: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
11525: ($item eq 'emailusername') || ($item eq 'shibenv') ||
11526: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 11527: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 11528: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11529: } else {
11530: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11531: }
11532: }
11533: }
11534: } elsif ($key eq 'email_rule') {
11535: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11536: } else {
11537: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11538: }
11539: }
11540: }
11541: #
11542: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11543: #
11544: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11545: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11546: if ($key eq 'selfcreate') {
11547: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11548: } else {
11549: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11550: }
11551: }
11552: }
1.305 raeburn 11553: #
11554: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
11555: #
11556: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11557: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
11558: if ($key eq 'inststatusguest') {
11559: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
11560: } else {
11561: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
11562: }
11563: }
11564: }
1.224 raeburn 11565:
11566: my @contexts = ('selfcreate');
11567: @{$cancreate{'selfcreate'}} = ();
11568: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 11569: if (@types) {
11570: @{$cancreate{'statustocreate'}} = ();
11571: }
1.236 raeburn 11572: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 11573: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 11574: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 11575: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 11576: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 11577: my %selfcreatetypes = (
11578: sso => 'users authenticated by institutional single sign on',
11579: login => 'users authenticated by institutional log-in',
1.303 raeburn 11580: email => 'users verified by e-mail',
1.50 raeburn 11581: );
1.224 raeburn 11582: #
11583: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11584: # is permitted.
11585: #
1.305 raeburn 11586: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 11587:
1.305 raeburn 11588: my (@statuses,%email_rule);
1.228 raeburn 11589: foreach my $item ('login','sso','email') {
1.224 raeburn 11590: if ($item eq 'email') {
1.236 raeburn 11591: if ($env{'form.cancreate_email'}) {
1.305 raeburn 11592: if (@types) {
11593: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
11594: foreach my $status (@poss_statuses) {
11595: if (grep(/^\Q$status\E$/,(@types,'default'))) {
11596: push(@statuses,$status);
11597: }
11598: }
11599: $save_inststatus{'inststatusguest'} = \@statuses;
11600: } else {
11601: push(@statuses,'default');
11602: }
11603: if (@statuses) {
11604: my %curr_rule;
11605: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11606: foreach my $type (@statuses) {
11607: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 11608: }
1.305 raeburn 11609: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
11610: foreach my $type (@statuses) {
11611: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
11612: }
11613: }
11614: push(@{$cancreate{'selfcreate'}},'email');
11615: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
11616: my %curremaildom;
11617: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
11618: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
11619: }
11620: foreach my $type (@statuses) {
11621: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
11622: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11623: }
11624: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
11625: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
11626: }
11627: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
11628: #
11629: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
11630: #
11631: my $chosen = $1;
11632: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
11633: my $emaildom;
11634: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
11635: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
11636: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
11637: if (ref($curremaildom{$type}) eq 'HASH') {
11638: if (exists($curremaildom{$type}{$chosen})) {
11639: if ($curremaildom{$type}{$chosen} ne $emaildom) {
11640: push(@{$changes{'cancreate'}},'emaildomain');
11641: }
11642: } elsif ($emaildom ne '') {
11643: push(@{$changes{'cancreate'}},'emaildomain');
11644: }
11645: } elsif ($emaildom ne '') {
11646: push(@{$changes{'cancreate'}},'emaildomain');
11647: }
11648: }
11649: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
11650: } elsif ($chosen eq 'custom') {
11651: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
11652: $email_rule{$type} = [];
11653: if (ref($emailrules) eq 'HASH') {
11654: foreach my $rule (@possemail_rules) {
11655: if (exists($emailrules->{$rule})) {
11656: push(@{$email_rule{$type}},$rule);
11657: }
11658: }
11659: }
11660: if (@{$email_rule{$type}}) {
11661: $cancreate{'emailoptions'}{$type} = 'custom';
11662: if (ref($curr_rule{$type}) eq 'ARRAY') {
11663: if (@{$curr_rule{$type}} > 0) {
11664: foreach my $rule (@{$curr_rule{$type}}) {
11665: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
11666: push(@{$changes{'email_rule'}},$type);
11667: }
11668: }
11669: }
11670: foreach my $type (@{$email_rule{$type}}) {
11671: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
11672: push(@{$changes{'email_rule'}},$type);
11673: }
11674: }
11675: } else {
11676: push(@{$changes{'email_rule'}},$type);
11677: }
11678: }
11679: } else {
11680: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
11681: }
11682: }
11683: }
11684: if (@types) {
11685: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11686: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
11687: if (@changed) {
11688: push(@{$changes{'inststatus'}},'inststatusguest');
11689: }
11690: } else {
11691: push(@{$changes{'inststatus'}},'inststatusguest');
11692: }
11693: }
11694: } else {
11695: delete($env{'form.cancreate_email'});
11696: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11697: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
11698: push(@{$changes{'inststatus'}},'inststatusguest');
11699: }
11700: }
11701: }
11702: } else {
11703: $save_inststatus{'inststatusguest'} = [];
11704: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
11705: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
11706: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 11707: }
11708: }
1.224 raeburn 11709: }
11710: } else {
11711: if ($env{'form.cancreate_'.$item}) {
11712: push(@{$cancreate{'selfcreate'}},$item);
11713: }
11714: }
11715: }
1.305 raeburn 11716: my (%userinfo,%savecaptcha);
1.224 raeburn 11717: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11718: #
1.228 raeburn 11719: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11720: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 11721: #
1.236 raeburn 11722:
1.244 raeburn 11723: if ($env{'form.cancreate_email'}) {
1.228 raeburn 11724: push(@contexts,'emailusername');
1.305 raeburn 11725: if (@statuses) {
11726: foreach my $type (@statuses) {
1.228 raeburn 11727: if (ref($infofields) eq 'ARRAY') {
11728: foreach my $field (@{$infofields}) {
11729: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11730: $cancreate{'emailusername'}{$type}{$field} = $1;
11731: }
11732: }
1.224 raeburn 11733: }
11734: }
11735: }
11736: #
11737: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 11738: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 11739: #
11740:
11741: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11742: @approvalnotify = sort(@approvalnotify);
11743: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11744: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11745: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11746: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11747: push(@{$changes{'cancreate'}},'notify');
11748: }
11749: } else {
11750: if ($cancreate{'notify'}{'approval'}) {
11751: push(@{$changes{'cancreate'}},'notify');
11752: }
11753: }
11754: } elsif ($cancreate{'notify'}{'approval'}) {
11755: push(@{$changes{'cancreate'}},'notify');
11756: }
11757:
11758: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11759: }
11760: #
1.236 raeburn 11761: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 11762: # institutional log-in.
11763: #
11764: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11765: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11766: ($domdefaults{'auth_def'} eq 'localauth'))) {
11767: $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.').' '.
11768: &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.');
11769: }
11770: }
11771: my @fields = ('lastname','firstname','middlename','generation',
11772: 'permanentemail','id');
1.240 raeburn 11773: my @shibfields = (@fields,'inststatus');
1.224 raeburn 11774: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11775: #
11776: # Where usernames may created for institutional log-in and/or institutional single sign on:
11777: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11778: # may self-create accounts
11779: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11780: # which the user may supply, if institutional data is unavailable.
11781: #
11782: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 11783: if (@types) {
1.305 raeburn 11784: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11785: push(@contexts,'statustocreate');
1.303 raeburn 11786: foreach my $type (@types) {
1.224 raeburn 11787: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11788: foreach my $field (@fields) {
11789: if (grep(/^\Q$field\E$/,@modifiable)) {
11790: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11791: } else {
11792: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11793: }
11794: }
11795: }
11796: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 11797: foreach my $type (@types) {
1.224 raeburn 11798: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11799: foreach my $field (@fields) {
11800: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11801: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11802: push(@{$changes{'selfcreate'}},$type);
11803: last;
11804: }
11805: }
11806: }
11807: }
11808: } else {
1.303 raeburn 11809: foreach my $type (@types) {
1.224 raeburn 11810: push(@{$changes{'selfcreate'}},$type);
11811: }
11812: }
11813: }
1.240 raeburn 11814: foreach my $field (@shibfields) {
11815: if ($env{'form.shibenv_'.$field} ne '') {
11816: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11817: }
11818: }
11819: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11820: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11821: foreach my $field (@shibfields) {
11822: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11823: push(@{$changes{'cancreate'}},'shibenv');
11824: }
11825: }
11826: } else {
11827: foreach my $field (@shibfields) {
11828: if ($env{'form.shibenv_'.$field}) {
11829: push(@{$changes{'cancreate'}},'shibenv');
11830: last;
11831: }
11832: }
11833: }
11834: }
1.224 raeburn 11835: }
11836: foreach my $item (@contexts) {
11837: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11838: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11839: if (ref($cancreate{$item}) eq 'ARRAY') {
11840: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11841: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11842: push(@{$changes{'cancreate'}},$item);
11843: }
11844: }
11845: }
11846: }
11847: if (ref($cancreate{$item}) eq 'ARRAY') {
11848: foreach my $type (@{$cancreate{$item}}) {
11849: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11850: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11851: push(@{$changes{'cancreate'}},$item);
11852: }
11853: }
11854: }
11855: }
11856: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11857: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 11858: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
11859: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
11860: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
11861: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 11862: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11863: push(@{$changes{'cancreate'}},$item);
11864: }
11865: }
11866: }
1.305 raeburn 11867: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11868: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 11869: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11870: push(@{$changes{'cancreate'}},$item);
11871: }
1.224 raeburn 11872: }
11873: }
11874: }
1.305 raeburn 11875: foreach my $type (keys(%{$cancreate{$item}})) {
11876: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11877: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11878: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
11879: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 11880: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11881: push(@{$changes{'cancreate'}},$item);
11882: }
11883: }
11884: } else {
11885: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11886: push(@{$changes{'cancreate'}},$item);
11887: }
11888: }
11889: }
1.305 raeburn 11890: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11891: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 11892: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11893: push(@{$changes{'cancreate'}},$item);
11894: }
1.224 raeburn 11895: }
11896: }
11897: }
11898: }
11899: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11900: if (ref($cancreate{$item}) eq 'ARRAY') {
11901: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11902: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11903: push(@{$changes{'cancreate'}},$item);
11904: }
11905: }
1.305 raeburn 11906: }
11907: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
11908: if (ref($cancreate{$item}) eq 'HASH') {
11909: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11910: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 11911: }
11912: }
11913: } elsif ($item eq 'emailusername') {
1.228 raeburn 11914: if (ref($cancreate{$item}) eq 'HASH') {
11915: foreach my $type (keys(%{$cancreate{$item}})) {
11916: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11917: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11918: if ($cancreate{$item}{$type}{$field}) {
11919: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11920: push(@{$changes{'cancreate'}},$item);
11921: }
11922: last;
11923: }
11924: }
11925: }
11926: }
1.224 raeburn 11927: }
11928: }
11929: }
11930: #
11931: # Populate %save_usercreate hash with updates to self-creation configuration.
11932: #
11933: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11934: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 11935: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 11936: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11937: if (ref($cancreate{'notify'}) eq 'HASH') {
11938: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11939: }
1.236 raeburn 11940: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11941: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11942: }
1.303 raeburn 11943: if (ref($cancreate{'emailverified'}) eq 'HASH') {
11944: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
11945: }
1.305 raeburn 11946: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
11947: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
11948: }
1.303 raeburn 11949: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
11950: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
11951: }
1.224 raeburn 11952: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11953: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11954: }
1.240 raeburn 11955: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11956: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11957: }
1.224 raeburn 11958: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 11959: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 11960:
11961: my %userconfig_hash = (
11962: usercreation => \%save_usercreate,
11963: usermodification => \%save_usermodify,
1.305 raeburn 11964: inststatus => \%save_inststatus,
1.224 raeburn 11965: );
1.305 raeburn 11966:
1.224 raeburn 11967: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11968: $dom);
11969: #
1.305 raeburn 11970: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 11971: #
1.27 raeburn 11972: if ($putresult eq 'ok') {
11973: if (keys(%changes) > 0) {
11974: $resulttext = &mt('Changes made:').'<ul>';
11975: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 11976: my %lt = &selfcreation_types();
1.34 raeburn 11977: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 11978: my $chgtext = '';
1.45 raeburn 11979: if ($type eq 'selfcreate') {
1.50 raeburn 11980: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 11981: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11982: } else {
1.224 raeburn 11983: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11984: '<ul>';
1.50 raeburn 11985: foreach my $case (@{$cancreate{$type}}) {
11986: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11987: }
11988: $chgtext .= '</ul>';
1.100 raeburn 11989: if (ref($cancreate{$type}) eq 'ARRAY') {
11990: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11991: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11992: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 11993: $chgtext .= '<span class="LC_warning">'.
11994: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
11995: '</span><br />';
11996: }
11997: }
11998: }
11999: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 12000: if (!@statuses) {
12001: $chgtext .= '<span class="LC_warning">'.
12002: &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.").
12003: '</span><br />';
1.303 raeburn 12004:
1.100 raeburn 12005: }
12006: }
12007: }
1.43 raeburn 12008: }
1.240 raeburn 12009: } elsif ($type eq 'shibenv') {
12010: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 12011: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 12012: } else {
12013: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
12014: '<ul>';
12015: foreach my $field (@shibfields) {
12016: next if ($cancreate{$type}{$field} eq '');
12017: if ($field eq 'inststatus') {
12018: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
12019: } else {
12020: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
12021: }
12022: }
12023: $chgtext .= '</ul>';
1.303 raeburn 12024: }
1.93 raeburn 12025: } elsif ($type eq 'statustocreate') {
1.96 raeburn 12026: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
12027: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
12028: if (@{$cancreate{'selfcreate'}} > 0) {
12029: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 12030: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 12031: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 12032: $chgtext .= '<br />'.
12033: '<span class="LC_warning">'.
12034: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
12035: '</span>';
12036: }
1.303 raeburn 12037: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 12038: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 12039: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
12040: } else {
12041: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
12042: }
12043: $chgtext .= '<ul>';
12044: foreach my $case (@{$cancreate{$type}}) {
12045: if ($case eq 'default') {
12046: $chgtext .= '<li>'.$othertitle.'</li>';
12047: } else {
1.303 raeburn 12048: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 12049: }
12050: }
1.100 raeburn 12051: $chgtext .= '</ul>';
12052: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 12053: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 12054: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
12055: '</span>';
1.100 raeburn 12056: }
12057: }
12058: } else {
12059: if (@{$cancreate{$type}} == 0) {
12060: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
12061: } else {
12062: $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 12063: }
12064: }
1.303 raeburn 12065: $chgtext .= '<br />';
1.93 raeburn 12066: }
1.236 raeburn 12067: } elsif ($type eq 'selfcreateprocessing') {
12068: my %choices = &Apache::lonlocal::texthash (
12069: automatic => 'Automatic approval',
12070: approval => 'Queued for approval',
12071: );
1.305 raeburn 12072: if (@types) {
12073: if (@statuses) {
1.303 raeburn 12074: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 ! raeburn 12075: '<ul>';
1.305 raeburn 12076: foreach my $status (@statuses) {
12077: if ($status eq 'default') {
12078: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 12079: } else {
1.305 raeburn 12080: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 12081: }
12082: }
12083: $chgtext .= '</ul>';
12084: }
12085: } else {
12086: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
12087: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
12088: }
12089: } elsif ($type eq 'emailverified') {
12090: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 12091: all => 'Same as e-mail',
12092: first => 'Omit @domain',
12093: free => 'Free to choose',
1.303 raeburn 12094: );
1.305 raeburn 12095: if (@types) {
12096: if (@statuses) {
1.303 raeburn 12097: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
12098: '<ul>';
1.305 raeburn 12099: foreach my $status (@statuses) {
1.303 raeburn 12100: if ($type eq 'default') {
1.305 raeburn 12101: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 12102: } else {
1.305 raeburn 12103: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 12104: }
12105: }
12106: $chgtext .= '</ul>';
12107: }
12108: } else {
1.305 raeburn 12109: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 12110: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 12111: }
1.305 raeburn 12112: } elsif ($type eq 'emailoptions') {
12113: my %options = &Apache::lonlocal::texthash (
12114: any => 'Any e-mail',
12115: inst => 'Institutional only',
12116: noninst => 'Non-institutional only',
12117: custom => 'Custom restrictions',
12118: );
12119: if (@types) {
12120: if (@statuses) {
12121: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
12122: '<ul>';
12123: foreach my $status (@statuses) {
12124: if ($type eq 'default') {
12125: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
12126: } else {
12127: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 12128: }
12129: }
1.305 raeburn 12130: $chgtext .= '</ul>';
12131: }
12132: } else {
12133: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
12134: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
12135: } else {
12136: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
12137: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 12138: }
1.305 raeburn 12139: }
12140: } elsif ($type eq 'emaildomain') {
12141: my $output;
12142: if (@statuses) {
12143: foreach my $type (@statuses) {
12144: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
12145: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
12146: if ($type eq 'default') {
12147: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12148: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12149: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12150: } else {
12151: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
12152: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12153: }
1.303 raeburn 12154: } else {
1.305 raeburn 12155: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12156: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
12157: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12158: } else {
12159: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
12160: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
12161: }
1.303 raeburn 12162: }
1.305 raeburn 12163: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
12164: if ($type eq 'default') {
12165: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12166: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12167: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
12168: } else {
12169: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
12170: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12171: }
1.303 raeburn 12172: } else {
1.305 raeburn 12173: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
12174: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
12175: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
12176: } else {
12177: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
12178: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
12179: }
1.303 raeburn 12180: }
12181: }
12182: }
12183: }
1.305 raeburn 12184: }
12185: if ($output ne '') {
12186: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
12187: '<ul>'.$output.'</ul>';
1.236 raeburn 12188: }
1.165 raeburn 12189: } elsif ($type eq 'captcha') {
1.224 raeburn 12190: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 12191: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
12192: } else {
12193: my %captchas = &captcha_phrases();
1.224 raeburn 12194: if ($captchas{$savecaptcha{$type}}) {
12195: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 12196: } else {
1.210 raeburn 12197: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 12198: }
12199: }
12200: } elsif ($type eq 'recaptchakeys') {
12201: my ($privkey,$pubkey);
1.224 raeburn 12202: if (ref($savecaptcha{$type}) eq 'HASH') {
12203: $pubkey = $savecaptcha{$type}{'public'};
12204: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 12205: }
12206: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
12207: if (!$pubkey) {
12208: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
12209: } else {
12210: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12211: }
12212: if (!$privkey) {
12213: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
12214: } else {
12215: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
12216: }
12217: $chgtext .= '</ul>';
1.269 raeburn 12218: } elsif ($type eq 'recaptchaversion') {
12219: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 12220: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 12221: }
1.224 raeburn 12222: } elsif ($type eq 'emailusername') {
12223: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 12224: if (@statuses) {
12225: foreach my $type (@statuses) {
1.228 raeburn 12226: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
12227: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 12228: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 12229: '<ul>';
12230: foreach my $field (@{$infofields}) {
12231: if ($cancreate{'emailusername'}{$type}{$field}) {
12232: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
12233: }
12234: }
1.245 raeburn 12235: $chgtext .= '</ul>';
12236: } else {
1.303 raeburn 12237: $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 12238: }
12239: } else {
1.303 raeburn 12240: $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 12241: }
12242: }
12243: }
12244: }
12245: } elsif ($type eq 'notify') {
1.303 raeburn 12246: my $numapprove = 0;
1.224 raeburn 12247: if (ref($changes{'cancreate'}) eq 'ARRAY') {
12248: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
12249: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 12250: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
12251: $numapprove ++;
1.224 raeburn 12252: }
12253: }
1.43 raeburn 12254: }
1.303 raeburn 12255: unless ($numapprove) {
12256: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
12257: }
1.34 raeburn 12258: }
1.224 raeburn 12259: if ($chgtext) {
12260: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 12261: }
12262: }
12263: }
1.305 raeburn 12264: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 12265: my ($emailrules,$emailruleorder) =
12266: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 12267: foreach my $type (@{$changes{'email_rule'}}) {
12268: if (ref($email_rule{$type}) eq 'ARRAY') {
12269: my $chgtext = '<ul>';
12270: foreach my $rule (@{$email_rule{$type}}) {
12271: if (ref($emailrules->{$rule}) eq 'HASH') {
12272: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
12273: }
12274: }
12275: $chgtext .= '</ul>';
12276: if (@types) {
12277: my $typename;
12278: if ($type eq 'default') {
12279: $typename = $othertitle;
12280: } else {
12281: $typename = $usertypes{$type};
12282: }
12283: $chgtext .= &mt('(Affiliation: [_1])',$typename);
12284: }
12285: if (@{$email_rule{$type}} > 0) {
12286: $resulttext .= '<li>'.
12287: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
12288: $usertypes{$type}).
12289: $chgtext.
12290: '</li>';
12291: } else {
12292: $resulttext .= '<li>'.
12293: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.',
12294: $usertypes{$type}).
12295: '</li>'.
12296: &mt('(Affiliation: [_1])',$type);
12297: }
1.43 raeburn 12298: }
12299: }
1.305 raeburn 12300: }
12301: if (ref($changes{'inststatus'}) eq 'ARRAY') {
12302: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
12303: if (@{$save_inststatus{'inststatusguest'}} > 0) {
12304: my $chgtext = '<ul>';
12305: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
12306: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
12307: }
12308: $chgtext .= '</ul>';
12309: $resulttext .= '<li>'.
12310: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
12311: $chgtext.
12312: '</li>';
12313: } else {
12314: $resulttext .= '<li>'.
12315: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
12316: '</li>';
12317: }
1.43 raeburn 12318: }
12319: }
1.224 raeburn 12320: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
12321: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
12322: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12323: foreach my $type (@{$changes{'selfcreate'}}) {
12324: my $typename = $type;
1.303 raeburn 12325: if (keys(%usertypes) > 0) {
12326: if ($usertypes{$type} ne '') {
12327: $typename = $usertypes{$type};
1.224 raeburn 12328: }
12329: }
12330: my @modifiable;
12331: $resulttext .= '<li>'.
12332: &mt('Self-creation of account by users with status: [_1]',
12333: '<span class="LC_cusr_emph">'.$typename.'</span>').
12334: ' - '.&mt('modifiable fields (if institutional data blank): ');
12335: foreach my $field (@fields) {
12336: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
12337: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 12338: }
12339: }
1.224 raeburn 12340: if (@modifiable > 0) {
12341: $resulttext .= join(', ',@modifiable);
1.43 raeburn 12342: } else {
1.224 raeburn 12343: $resulttext .= &mt('none');
1.43 raeburn 12344: }
1.224 raeburn 12345: $resulttext .= '</li>';
1.28 raeburn 12346: }
1.224 raeburn 12347: $resulttext .= '</ul></li>';
1.28 raeburn 12348: }
1.27 raeburn 12349: $resulttext .= '</ul>';
1.305 raeburn 12350: my $cachetime = 24*60*60;
12351: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
12352: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12353: if (ref($lastactref) eq 'HASH') {
12354: $lastactref->{'domdefaults'} = 1;
12355: }
1.27 raeburn 12356: } else {
1.224 raeburn 12357: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 12358: }
12359: } else {
12360: $resulttext = '<span class="LC_error">'.
1.23 raeburn 12361: &mt('An error occurred: [_1]',$putresult).'</span>';
12362: }
1.43 raeburn 12363: if ($warningmsg ne '') {
12364: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12365: }
1.23 raeburn 12366: return $resulttext;
12367: }
12368:
1.165 raeburn 12369: sub process_captcha {
12370: my ($container,$changes,$newsettings,$current) = @_;
12371: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
12372: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
12373: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
12374: $newsettings->{'captcha'} = 'original';
12375: }
12376: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 12377: if ($container eq 'cancreate') {
1.169 raeburn 12378: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12379: push(@{$changes->{'cancreate'}},'captcha');
12380: } elsif (!defined($changes->{'cancreate'})) {
12381: $changes->{'cancreate'} = ['captcha'];
12382: }
12383: } else {
12384: $changes->{'captcha'} = 1;
1.165 raeburn 12385: }
12386: }
1.269 raeburn 12387: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 12388: if ($newsettings->{'captcha'} eq 'recaptcha') {
12389: $newpub = $env{'form.'.$container.'_recaptchapub'};
12390: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 12391: $newpub =~ s/[^\w\-]//g;
12392: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 12393: $newsettings->{'recaptchakeys'} = {
12394: public => $newpub,
12395: private => $newpriv,
12396: };
1.269 raeburn 12397: $newversion = $env{'form.'.$container.'_recaptchaversion'};
12398: $newversion =~ s/\D//g;
12399: if ($newversion ne '2') {
12400: $newversion = 1;
12401: }
12402: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 12403: }
12404: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
12405: $currpub = $current->{'recaptchakeys'}{'public'};
12406: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 12407: unless ($newsettings->{'captcha'} eq 'recaptcha') {
12408: $newsettings->{'recaptchakeys'} = {
12409: public => '',
12410: private => '',
12411: }
12412: }
1.165 raeburn 12413: }
1.269 raeburn 12414: if ($current->{'captcha'} eq 'recaptcha') {
12415: $currversion = $current->{'recaptchaversion'};
12416: if ($currversion ne '2') {
12417: $currversion = 1;
12418: }
12419: }
12420: if ($currversion ne $newversion) {
12421: if ($container eq 'cancreate') {
12422: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12423: push(@{$changes->{'cancreate'}},'recaptchaversion');
12424: } elsif (!defined($changes->{'cancreate'})) {
12425: $changes->{'cancreate'} = ['recaptchaversion'];
12426: }
12427: } else {
12428: $changes->{'recaptchaversion'} = 1;
12429: }
12430: }
1.165 raeburn 12431: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 12432: if ($container eq 'cancreate') {
12433: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12434: push(@{$changes->{'cancreate'}},'recaptchakeys');
12435: } elsif (!defined($changes->{'cancreate'})) {
12436: $changes->{'cancreate'} = ['recaptchakeys'];
12437: }
12438: } else {
1.210 raeburn 12439: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 12440: }
12441: }
12442: return;
12443: }
12444:
1.33 raeburn 12445: sub modify_usermodification {
12446: my ($dom,%domconfig) = @_;
1.224 raeburn 12447: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 12448: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12449: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 12450: if ($key eq 'selfcreate') {
12451: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
12452: } else {
12453: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
12454: }
1.33 raeburn 12455: }
12456: }
1.224 raeburn 12457: my @contexts = ('author','course');
1.33 raeburn 12458: my %context_title = (
12459: author => 'In author context',
12460: course => 'In course context',
12461: );
12462: my @fields = ('lastname','firstname','middlename','generation',
12463: 'permanentemail','id');
12464: my %roles = (
12465: author => ['ca','aa'],
12466: course => ['st','ep','ta','in','cr'],
12467: );
12468: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12469: foreach my $context (@contexts) {
12470: foreach my $role (@{$roles{$context}}) {
12471: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
12472: foreach my $item (@fields) {
12473: if (grep(/^\Q$item\E$/,@modifiable)) {
12474: $modifyhash{$context}{$role}{$item} = 1;
12475: } else {
12476: $modifyhash{$context}{$role}{$item} = 0;
12477: }
12478: }
12479: }
12480: if (ref($curr_usermodification{$context}) eq 'HASH') {
12481: foreach my $role (@{$roles{$context}}) {
12482: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
12483: foreach my $field (@fields) {
12484: if ($modifyhash{$context}{$role}{$field} ne
12485: $curr_usermodification{$context}{$role}{$field}) {
12486: push(@{$changes{$context}},$role);
12487: last;
12488: }
12489: }
12490: }
12491: }
12492: } else {
12493: foreach my $context (@contexts) {
12494: foreach my $role (@{$roles{$context}}) {
12495: push(@{$changes{$context}},$role);
12496: }
12497: }
12498: }
12499: }
12500: my %usermodification_hash = (
12501: usermodification => \%modifyhash,
12502: );
12503: my $putresult = &Apache::lonnet::put_dom('configuration',
12504: \%usermodification_hash,$dom);
12505: if ($putresult eq 'ok') {
12506: if (keys(%changes) > 0) {
12507: $resulttext = &mt('Changes made: ').'<ul>';
12508: foreach my $context (@contexts) {
12509: if (ref($changes{$context}) eq 'ARRAY') {
12510: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
12511: if (ref($changes{$context}) eq 'ARRAY') {
12512: foreach my $role (@{$changes{$context}}) {
12513: my $rolename;
1.224 raeburn 12514: if ($role eq 'cr') {
12515: $rolename = &mt('Custom');
1.33 raeburn 12516: } else {
1.224 raeburn 12517: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 12518: }
12519: my @modifiable;
1.224 raeburn 12520: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 12521: foreach my $field (@fields) {
12522: if ($modifyhash{$context}{$role}{$field}) {
12523: push(@modifiable,$fieldtitles{$field});
12524: }
12525: }
12526: if (@modifiable > 0) {
12527: $resulttext .= join(', ',@modifiable);
12528: } else {
12529: $resulttext .= &mt('none');
12530: }
12531: $resulttext .= '</li>';
12532: }
12533: $resulttext .= '</ul></li>';
12534: }
12535: }
12536: }
12537: $resulttext .= '</ul>';
12538: } else {
12539: $resulttext = &mt('No changes made to user modification settings');
12540: }
12541: } else {
12542: $resulttext = '<span class="LC_error">'.
12543: &mt('An error occurred: [_1]',$putresult).'</span>';
12544: }
12545: return $resulttext;
12546: }
12547:
1.43 raeburn 12548: sub modify_defaults {
1.212 raeburn 12549: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 12550: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 12551: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 12552: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
12553: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 12554: my @authtypes = ('internal','krb4','krb5','localauth');
12555: foreach my $item (@items) {
12556: $newvalues{$item} = $env{'form.'.$item};
12557: if ($item eq 'auth_def') {
12558: if ($newvalues{$item} ne '') {
12559: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
12560: push(@errors,$item);
12561: }
12562: }
12563: } elsif ($item eq 'lang_def') {
12564: if ($newvalues{$item} ne '') {
12565: if ($newvalues{$item} =~ /^(\w+)/) {
12566: my $langcode = $1;
1.103 raeburn 12567: if ($langcode ne 'x_chef') {
12568: if (code2language($langcode) eq '') {
12569: push(@errors,$item);
12570: }
1.43 raeburn 12571: }
12572: } else {
12573: push(@errors,$item);
12574: }
12575: }
1.54 raeburn 12576: } elsif ($item eq 'timezone_def') {
12577: if ($newvalues{$item} ne '') {
1.62 raeburn 12578: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 12579: push(@errors,$item);
12580: }
12581: }
1.68 raeburn 12582: } elsif ($item eq 'datelocale_def') {
12583: if ($newvalues{$item} ne '') {
12584: my @datelocale_ids = DateTime::Locale->ids();
12585: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
12586: push(@errors,$item);
12587: }
12588: }
1.141 raeburn 12589: } elsif ($item eq 'portal_def') {
12590: if ($newvalues{$item} ne '') {
12591: 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])\/?$/) {
12592: push(@errors,$item);
12593: }
12594: }
1.294 raeburn 12595: } elsif ($item eq 'intauth_cost') {
12596: if ($newvalues{$item} ne '') {
12597: if ($newvalues{$item} =~ /\D/) {
12598: push(@errors,$item);
12599: }
12600: }
12601: } elsif ($item eq 'intauth_check') {
12602: if ($newvalues{$item} ne '') {
12603: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12604: push(@errors,$item);
12605: }
12606: }
12607: } elsif ($item eq 'intauth_switch') {
12608: if ($newvalues{$item} ne '') {
12609: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12610: push(@errors,$item);
12611: }
12612: }
1.43 raeburn 12613: }
12614: if (grep(/^\Q$item\E$/,@errors)) {
12615: $newvalues{$item} = $domdefaults{$item};
12616: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12617: $changes{$item} = 1;
12618: }
1.72 raeburn 12619: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 12620: }
12621: my %defaults_hash = (
1.72 raeburn 12622: defaults => \%newvalues,
12623: );
1.43 raeburn 12624: my $title = &defaults_titles();
1.236 raeburn 12625:
12626: my $currinststatus;
12627: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12628: $currinststatus = $domconfig{'inststatus'};
12629: } else {
12630: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12631: $currinststatus = {
12632: inststatustypes => $usertypes,
12633: inststatusorder => $types,
12634: inststatusguest => [],
12635: };
12636: }
12637: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12638: my @allpos;
12639: my %alltypes;
1.305 raeburn 12640: my @inststatusguest;
12641: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12642: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
12643: unless (grep(/^\Q$type\E$/,@todelete)) {
12644: push(@inststatusguest,$type);
12645: }
12646: }
12647: }
12648: my ($currtitles,$currorder);
1.236 raeburn 12649: if (ref($currinststatus) eq 'HASH') {
12650: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12651: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12652: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12653: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12654: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12655: }
12656: }
12657: unless (grep(/^\Q$type\E$/,@todelete)) {
12658: my $position = $env{'form.inststatus_pos_'.$type};
12659: $position =~ s/\D+//g;
12660: $allpos[$position] = $type;
12661: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12662: $alltypes{$type} =~ s/`//g;
12663: }
12664: }
12665: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12666: $currtitles =~ s/,$//;
12667: }
12668: }
12669: if ($env{'form.addinststatus'}) {
12670: my $newtype = $env{'form.addinststatus'};
12671: $newtype =~ s/\W//g;
12672: unless (exists($alltypes{$newtype})) {
12673: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12674: $alltypes{$newtype} =~ s/`//g;
12675: my $position = $env{'form.addinststatus_pos'};
12676: $position =~ s/\D+//g;
12677: if ($position ne '') {
12678: $allpos[$position] = $newtype;
12679: }
12680: }
12681: }
1.305 raeburn 12682: my @orderedstatus;
1.236 raeburn 12683: foreach my $type (@allpos) {
12684: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12685: push(@orderedstatus,$type);
12686: }
12687: }
12688: foreach my $type (keys(%alltypes)) {
12689: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12690: delete($alltypes{$type});
12691: }
12692: }
12693: $defaults_hash{'inststatus'} = {
12694: inststatustypes => \%alltypes,
12695: inststatusorder => \@orderedstatus,
1.305 raeburn 12696: inststatusguest => \@inststatusguest,
1.236 raeburn 12697: };
12698: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12699: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12700: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12701: }
12702: }
12703: if ($currorder ne join(',',@orderedstatus)) {
12704: $changes{'inststatus'}{'inststatusorder'} = 1;
12705: }
12706: my $newtitles;
12707: foreach my $item (@orderedstatus) {
12708: $newtitles .= $alltypes{$item}.',';
12709: }
12710: $newtitles =~ s/,$//;
12711: if ($currtitles ne $newtitles) {
12712: $changes{'inststatus'}{'inststatustypes'} = 1;
12713: }
1.43 raeburn 12714: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12715: $dom);
12716: if ($putresult eq 'ok') {
12717: if (keys(%changes) > 0) {
12718: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 12719: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12720: 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";
12721: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 12722: if ($item eq 'inststatus') {
12723: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 12724: if (@orderedstatus) {
1.236 raeburn 12725: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12726: foreach my $type (@orderedstatus) {
12727: $resulttext .= $alltypes{$type}.', ';
12728: }
12729: $resulttext =~ s/, $//;
12730: $resulttext .= '</li>';
1.305 raeburn 12731: } else {
12732: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 12733: }
12734: }
12735: } else {
12736: my $value = $env{'form.'.$item};
12737: if ($value eq '') {
12738: $value = &mt('none');
12739: } elsif ($item eq 'auth_def') {
12740: my %authnames = &authtype_names();
12741: my %shortauth = (
12742: internal => 'int',
12743: krb4 => 'krb4',
12744: krb5 => 'krb5',
12745: localauth => 'loc',
12746: );
12747: $value = $authnames{$shortauth{$value}};
1.294 raeburn 12748: } elsif ($item eq 'intauth_switch') {
12749: my %optiondesc = &Apache::lonlocal::texthash (
12750: 0 => 'No',
12751: 1 => 'Yes',
12752: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12753: );
12754: if ($value =~ /^(0|1|2)$/) {
12755: $value = $optiondesc{$value};
12756: } else {
12757: $value = &mt('none -- defaults to No');
12758: }
12759: } elsif ($item eq 'intauth_check') {
12760: my %optiondesc = &Apache::lonlocal::texthash (
12761: 0 => 'No',
12762: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12763: 2 => 'Yes, disallow login if stored cost is less than domain default',
12764: );
12765: if ($value =~ /^(0|1|2)$/) {
12766: $value = $optiondesc{$value};
12767: } else {
12768: $value = &mt('none -- defaults to No');
12769: }
1.236 raeburn 12770: }
12771: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12772: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12773: }
12774: }
12775: $resulttext .= '</ul>';
12776: $mailmsgtext .= "\n";
12777: my $cachetime = 24*60*60;
1.72 raeburn 12778: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12779: if (ref($lastactref) eq 'HASH') {
12780: $lastactref->{'domdefaults'} = 1;
12781: }
1.68 raeburn 12782: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 12783: my $notify = 1;
12784: if (ref($domconfig{'contacts'}) eq 'HASH') {
12785: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12786: $notify = 0;
12787: }
12788: }
12789: if ($notify) {
12790: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12791: "LON-CAPA Domain Settings Change - $dom",
12792: $mailmsgtext);
12793: }
1.54 raeburn 12794: }
1.43 raeburn 12795: } else {
1.54 raeburn 12796: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12797: }
12798: } else {
12799: $resulttext = '<span class="LC_error">'.
12800: &mt('An error occurred: [_1]',$putresult).'</span>';
12801: }
12802: if (@errors > 0) {
12803: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12804: foreach my $item (@errors) {
12805: $resulttext .= ' "'.$title->{$item}.'",';
12806: }
12807: $resulttext =~ s/,$//;
12808: }
12809: return $resulttext;
12810: }
12811:
1.46 raeburn 12812: sub modify_scantron {
1.205 raeburn 12813: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12814: my ($resulttext,%confhash,%changes,$errors);
12815: my $custom = 'custom.tab';
12816: my $default = 'default.tab';
12817: my $servadm = $r->dir_config('lonAdmEMail');
12818: my ($configuserok,$author_ok,$switchserver) =
12819: &config_check($dom,$confname,$servadm);
12820: if ($env{'form.scantronformat.filename'} ne '') {
12821: my $error;
12822: if ($configuserok eq 'ok') {
12823: if ($switchserver) {
1.130 raeburn 12824: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12825: } else {
12826: if ($author_ok eq 'ok') {
12827: my ($result,$scantronurl) =
12828: &publishlogo($r,'upload','scantronformat',$dom,
12829: $confname,'scantron','','',$custom);
12830: if ($result eq 'ok') {
12831: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12832: $changes{'scantronformat'} = 1;
1.46 raeburn 12833: } else {
12834: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12835: }
12836: } else {
12837: $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);
12838: }
12839: }
12840: } else {
12841: $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);
12842: }
12843: if ($error) {
12844: &Apache::lonnet::logthis($error);
12845: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12846: }
12847: }
1.48 raeburn 12848: if (ref($domconfig{'scantron'}) eq 'HASH') {
12849: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12850: if ($env{'form.scantronformat_del'}) {
12851: $confhash{'scantron'}{'scantronformat'} = '';
12852: $changes{'scantronformat'} = 1;
1.46 raeburn 12853: }
12854: }
12855: }
12856: if (keys(%confhash) > 0) {
12857: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12858: $dom);
12859: if ($putresult eq 'ok') {
12860: if (keys(%changes) > 0) {
1.48 raeburn 12861: if (ref($confhash{'scantron'}) eq 'HASH') {
12862: $resulttext = &mt('Changes made:').'<ul>';
12863: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 12864: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 12865: } else {
1.130 raeburn 12866: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 12867: }
1.48 raeburn 12868: $resulttext .= '</ul>';
12869: } else {
1.130 raeburn 12870: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12871: }
12872: $resulttext .= '</ul>';
12873: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12874: if (ref($lastactref) eq 'HASH') {
12875: $lastactref->{'domainconfig'} = 1;
12876: }
1.46 raeburn 12877: } else {
1.130 raeburn 12878: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12879: }
12880: } else {
12881: $resulttext = '<span class="LC_error">'.
12882: &mt('An error occurred: [_1]',$putresult).'</span>';
12883: }
12884: } else {
1.130 raeburn 12885: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12886: }
12887: if ($errors) {
12888: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12889: $errors.'</ul>';
12890: }
12891: return $resulttext;
12892: }
12893:
1.48 raeburn 12894: sub modify_coursecategories {
1.239 raeburn 12895: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12896: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12897: $cathash);
1.48 raeburn 12898: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 12899: my @catitems = ('unauth','auth');
12900: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12901: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12902: $cathash = $domconfig{'coursecategories'}{'cats'};
12903: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12904: $changes{'togglecats'} = 1;
12905: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12906: }
12907: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12908: $changes{'categorize'} = 1;
12909: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12910: }
1.120 raeburn 12911: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12912: $changes{'togglecatscomm'} = 1;
12913: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12914: }
12915: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12916: $changes{'categorizecomm'} = 1;
12917: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 12918:
12919: }
12920: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
12921: $changes{'togglecatsplace'} = 1;
12922: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
12923: }
12924: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
12925: $changes{'categorizeplace'} = 1;
12926: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 12927: }
1.238 raeburn 12928: foreach my $item (@catitems) {
12929: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12930: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12931: $changes{$item} = 1;
12932: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12933: }
12934: }
12935: }
1.57 raeburn 12936: } else {
12937: $changes{'togglecats'} = 1;
12938: $changes{'categorize'} = 1;
1.124 raeburn 12939: $changes{'togglecatscomm'} = 1;
12940: $changes{'categorizecomm'} = 1;
1.272 raeburn 12941: $changes{'togglecatsplace'} = 1;
12942: $changes{'categorizeplace'} = 1;
1.87 raeburn 12943: $domconfig{'coursecategories'} = {
12944: togglecats => $env{'form.togglecats'},
12945: categorize => $env{'form.categorize'},
1.124 raeburn 12946: togglecatscomm => $env{'form.togglecatscomm'},
12947: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 12948: togglecatsplace => $env{'form.togglecatsplace'},
12949: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 12950: };
1.238 raeburn 12951: foreach my $item (@catitems) {
12952: if ($env{'form.coursecat_'.$item} ne 'std') {
12953: $changes{$item} = 1;
12954: }
12955: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12956: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12957: }
12958: }
1.57 raeburn 12959: }
12960: if (ref($cathash) eq 'HASH') {
12961: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12962: push (@deletecategory,'instcode::0');
12963: }
1.120 raeburn 12964: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12965: push(@deletecategory,'communities::0');
12966: }
1.272 raeburn 12967: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
12968: push(@deletecategory,'placement::0');
12969: }
1.48 raeburn 12970: }
1.57 raeburn 12971: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12972: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12973: if (@deletecategory > 0) {
12974: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12975: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12976: foreach my $item (@deletecategory) {
1.57 raeburn 12977: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12978: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12979: $deletions{$item} = 1;
1.57 raeburn 12980: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12981: }
12982: }
12983: }
1.57 raeburn 12984: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12985: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12986: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12987: $reorderings{$item} = 1;
1.57 raeburn 12988: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12989: }
12990: if ($env{'form.addcategory_name_'.$item} ne '') {
12991: my $newcat = $env{'form.addcategory_name_'.$item};
12992: my $newdepth = $depth+1;
12993: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12994: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12995: $adds{$newitem} = 1;
12996: }
12997: if ($env{'form.subcat_'.$item} ne '') {
12998: my $newcat = $env{'form.subcat_'.$item};
12999: my $newdepth = $depth+1;
13000: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 13001: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 13002: $adds{$newitem} = 1;
13003: }
13004: }
13005: }
13006: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 13007: if (ref($cathash) eq 'HASH') {
1.48 raeburn 13008: my $newitem = 'instcode::0';
1.57 raeburn 13009: if ($cathash->{$newitem} eq '') {
13010: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 13011: $adds{$newitem} = 1;
13012: }
13013: } else {
13014: my $newitem = 'instcode::0';
1.57 raeburn 13015: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 13016: $adds{$newitem} = 1;
13017: }
13018: }
1.120 raeburn 13019: if ($env{'form.communities'} eq '1') {
13020: if (ref($cathash) eq 'HASH') {
13021: my $newitem = 'communities::0';
13022: if ($cathash->{$newitem} eq '') {
13023: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13024: $adds{$newitem} = 1;
13025: }
13026: } else {
13027: my $newitem = 'communities::0';
13028: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
13029: $adds{$newitem} = 1;
13030: }
13031: }
1.272 raeburn 13032: if ($env{'form.placement'} eq '1') {
13033: if (ref($cathash) eq 'HASH') {
13034: my $newitem = 'placement::0';
13035: if ($cathash->{$newitem} eq '') {
13036: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
13037: $adds{$newitem} = 1;
13038: }
13039: } else {
13040: my $newitem = 'placement::0';
13041: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
13042: $adds{$newitem} = 1;
13043: }
13044: }
1.48 raeburn 13045: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 13046: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 13047: ($env{'form.addcategory_name'} ne 'communities') &&
13048: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 13049: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
13050: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
13051: $adds{$newitem} = 1;
13052: }
1.48 raeburn 13053: }
1.57 raeburn 13054: my $putresult;
1.48 raeburn 13055: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13056: if (keys(%deletions) > 0) {
13057: foreach my $key (keys(%deletions)) {
13058: if ($predelallitems{$key} ne '') {
13059: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
13060: }
13061: }
13062: }
13063: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 13064: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 13065: if (ref($chkcats[0]) eq 'ARRAY') {
13066: my $depth = 0;
13067: my $chg = 0;
13068: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
13069: my $name = $chkcats[0][$i];
13070: my $item;
13071: if ($name eq '') {
13072: $chg ++;
13073: } else {
13074: $item = &escape($name).'::0';
13075: if ($chg) {
1.57 raeburn 13076: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 13077: }
13078: $depth ++;
1.57 raeburn 13079: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 13080: $depth --;
13081: }
13082: }
13083: }
1.57 raeburn 13084: }
13085: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13086: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 13087: if ($putresult eq 'ok') {
1.57 raeburn 13088: my %title = (
1.120 raeburn 13089: togglecats => 'Show/Hide a course in catalog',
13090: categorize => 'Assign a category to a course',
13091: togglecatscomm => 'Show/Hide a community in catalog',
13092: categorizecomm => 'Assign a category to a community',
1.57 raeburn 13093: );
13094: my %level = (
1.120 raeburn 13095: dom => 'set in Domain ("Modify Course/Community")',
13096: crs => 'set in Course ("Course Configuration")',
13097: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 13098: none => 'No catalog',
13099: std => 'Standard catalog',
13100: domonly => 'Domain-only catalog',
13101: codesrch => 'Code search form',
1.57 raeburn 13102: );
1.48 raeburn 13103: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 13104: if ($changes{'togglecats'}) {
13105: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
13106: }
13107: if ($changes{'categorize'}) {
13108: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 13109: }
1.120 raeburn 13110: if ($changes{'togglecatscomm'}) {
13111: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
13112: }
13113: if ($changes{'categorizecomm'}) {
13114: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
13115: }
1.238 raeburn 13116: if ($changes{'unauth'}) {
13117: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
13118: }
13119: if ($changes{'auth'}) {
13120: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
13121: }
1.57 raeburn 13122: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
13123: my $cathash;
13124: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
13125: $cathash = $domconfig{'coursecategories'}{'cats'};
13126: } else {
13127: $cathash = {};
13128: }
13129: my (@cats,@trails,%allitems);
13130: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
13131: if (keys(%deletions) > 0) {
13132: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
13133: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
13134: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
13135: }
13136: $resulttext .= '</ul></li>';
13137: }
13138: if (keys(%reorderings) > 0) {
13139: my %sort_by_trail;
13140: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
13141: foreach my $key (keys(%reorderings)) {
13142: if ($allitems{$key} ne '') {
13143: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13144: }
1.48 raeburn 13145: }
1.57 raeburn 13146: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13147: $resulttext .= '<li>'.$trails[$trail].'</li>';
13148: }
13149: $resulttext .= '</ul></li>';
1.48 raeburn 13150: }
1.57 raeburn 13151: if (keys(%adds) > 0) {
13152: my %sort_by_trail;
13153: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
13154: foreach my $key (keys(%adds)) {
13155: if ($allitems{$key} ne '') {
13156: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
13157: }
13158: }
13159: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
13160: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 13161: }
1.57 raeburn 13162: $resulttext .= '</ul></li>';
1.48 raeburn 13163: }
13164: }
13165: $resulttext .= '</ul>';
1.239 raeburn 13166: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 13167: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13168: if ($changes{'auth'}) {
13169: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
13170: }
13171: if ($changes{'unauth'}) {
13172: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
13173: }
13174: my $cachetime = 24*60*60;
13175: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 13176: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 13177: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 13178: }
13179: }
1.48 raeburn 13180: } else {
13181: $resulttext = '<span class="LC_error">'.
1.57 raeburn 13182: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 13183: }
13184: } else {
1.120 raeburn 13185: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 13186: }
13187: return $resulttext;
13188: }
13189:
1.69 raeburn 13190: sub modify_serverstatuses {
13191: my ($dom,%domconfig) = @_;
13192: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
13193: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
13194: %currserverstatus = %{$domconfig{'serverstatuses'}};
13195: }
13196: my @pages = &serverstatus_pages();
13197: foreach my $type (@pages) {
13198: $newserverstatus{$type}{'namedusers'} = '';
13199: $newserverstatus{$type}{'machines'} = '';
13200: if (defined($env{'form.'.$type.'_namedusers'})) {
13201: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
13202: my @okusers;
13203: foreach my $user (@users) {
13204: my ($uname,$udom) = split(/:/,$user);
13205: if (($udom =~ /^$match_domain$/) &&
13206: (&Apache::lonnet::domain($udom)) &&
13207: ($uname =~ /^$match_username$/)) {
13208: if (!grep(/^\Q$user\E/,@okusers)) {
13209: push(@okusers,$user);
13210: }
13211: }
13212: }
13213: if (@okusers > 0) {
13214: @okusers = sort(@okusers);
13215: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
13216: }
13217: }
13218: if (defined($env{'form.'.$type.'_machines'})) {
13219: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
13220: my @okmachines;
13221: foreach my $ip (@machines) {
13222: my @parts = split(/\./,$ip);
13223: next if (@parts < 4);
13224: my $badip = 0;
13225: for (my $i=0; $i<4; $i++) {
13226: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
13227: $badip = 1;
13228: last;
13229: }
13230: }
13231: if (!$badip) {
13232: push(@okmachines,$ip);
13233: }
13234: }
13235: @okmachines = sort(@okmachines);
13236: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
13237: }
13238: }
13239: my %serverstatushash = (
13240: serverstatuses => \%newserverstatus,
13241: );
13242: foreach my $type (@pages) {
1.83 raeburn 13243: foreach my $setting ('namedusers','machines') {
1.84 raeburn 13244: my (@current,@new);
1.83 raeburn 13245: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 13246: if ($currserverstatus{$type}{$setting} ne '') {
13247: @current = split(/,/,$currserverstatus{$type}{$setting});
13248: }
13249: }
13250: if ($newserverstatus{$type}{$setting} ne '') {
13251: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 13252: }
13253: if (@current > 0) {
13254: if (@new > 0) {
13255: foreach my $item (@current) {
13256: if (!grep(/^\Q$item\E$/,@new)) {
13257: $changes{$type}{$setting} = 1;
1.82 raeburn 13258: last;
13259: }
13260: }
1.84 raeburn 13261: foreach my $item (@new) {
13262: if (!grep(/^\Q$item\E$/,@current)) {
13263: $changes{$type}{$setting} = 1;
13264: last;
1.82 raeburn 13265: }
13266: }
13267: } else {
1.83 raeburn 13268: $changes{$type}{$setting} = 1;
1.69 raeburn 13269: }
1.83 raeburn 13270: } elsif (@new > 0) {
13271: $changes{$type}{$setting} = 1;
1.69 raeburn 13272: }
13273: }
13274: }
13275: if (keys(%changes) > 0) {
1.81 raeburn 13276: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 13277: my $putresult = &Apache::lonnet::put_dom('configuration',
13278: \%serverstatushash,$dom);
13279: if ($putresult eq 'ok') {
13280: $resulttext .= &mt('Changes made:').'<ul>';
13281: foreach my $type (@pages) {
1.84 raeburn 13282: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 13283: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 13284: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 13285: if ($newserverstatus{$type}{'namedusers'} eq '') {
13286: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
13287: } else {
13288: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
13289: }
1.84 raeburn 13290: }
13291: if ($changes{$type}{'machines'}) {
1.69 raeburn 13292: if ($newserverstatus{$type}{'machines'} eq '') {
13293: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
13294: } else {
13295: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
13296: }
13297:
13298: }
13299: $resulttext .= '</ul></li>';
13300: }
13301: }
13302: $resulttext .= '</ul>';
13303: } else {
13304: $resulttext = '<span class="LC_error">'.
13305: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
13306:
13307: }
13308: } else {
13309: $resulttext = &mt('No changes made to access to server status pages');
13310: }
13311: return $resulttext;
13312: }
13313:
1.118 jms 13314: sub modify_helpsettings {
1.285 raeburn 13315: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 13316: my ($resulttext,$errors,%changes,%helphash);
13317: my %defaultchecked = ('submitbugs' => 'on');
13318: my @offon = ('off','on');
1.118 jms 13319: my @toggles = ('submitbugs');
1.285 raeburn 13320: my %current = ('submitbugs' => '',
13321: 'adhoc' => {},
13322: );
1.118 jms 13323: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 13324: %current = %{$domconfig{'helpsettings'}};
13325: }
1.285 raeburn 13326: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 13327: foreach my $item (@toggles) {
13328: if ($defaultchecked{$item} eq 'on') {
13329: if ($current{$item} eq '') {
13330: if ($env{'form.'.$item} eq '0') {
13331: $changes{$item} = 1;
13332: }
13333: } elsif ($current{$item} ne $env{'form.'.$item}) {
13334: $changes{$item} = 1;
13335: }
13336: } elsif ($defaultchecked{$item} eq 'off') {
13337: if ($current{$item} eq '') {
13338: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 13339: $changes{$item} = 1;
13340: }
1.282 raeburn 13341: } elsif ($current{$item} ne $env{'form.'.$item}) {
13342: $changes{$item} = 1;
13343: }
13344: }
13345: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
13346: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
13347: }
13348: }
1.285 raeburn 13349: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 13350: my $confname = $dom.'-domainconfig';
13351: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 13352: my (@allpos,%newsettings,%changedprivs,$newrole);
13353: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 13354: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 13355: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 13356: my %lt = &Apache::lonlocal::texthash(
13357: s => 'system',
13358: d => 'domain',
13359: order => 'Display order',
13360: access => 'Role usage',
1.291 raeburn 13361: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 13362: dh => 'All with domain helpdesk role',
13363: da => 'All with domain helpdesk assistant role',
1.285 raeburn 13364: none => 'None',
13365: status => 'Determined based on institutional status',
13366: inc => 'Include all, but exclude specific personnel',
13367: exc => 'Exclude all, but include specific personnel',
13368: );
13369: for (my $num=0; $num<=$maxnum; $num++) {
13370: my ($prefix,$identifier,$rolename,%curr);
13371: if ($num == $maxnum) {
13372: next unless ($env{'form.newcusthelp'} == $maxnum);
13373: $identifier = 'custhelp'.$num;
13374: $prefix = 'helproles_'.$num;
13375: $rolename = $env{'form.custhelpname'.$num};
13376: $rolename=~s/[^A-Za-z0-9]//gs;
13377: next if ($rolename eq '');
13378: next if (exists($existing{'rolesdef_'.$rolename}));
13379: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13380: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13381: $newprivs{'c'},$confname,$dom);
13382: if ($result ne 'ok') {
13383: $errors .= '<li><span class="LC_error">'.
13384: &mt('An error occurred storing the new custom role: [_1]',
13385: $result).'</span></li>';
13386: next;
13387: } else {
13388: $changedprivs{$rolename} = \%newprivs;
13389: $newrole = $rolename;
13390: }
13391: } else {
13392: $prefix = 'helproles_'.$num;
13393: $rolename = $env{'form.'.$prefix};
13394: next if ($rolename eq '');
13395: next unless (exists($existing{'rolesdef_'.$rolename}));
13396: $identifier = 'custhelp'.$num;
13397: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13398: my %currprivs;
1.289 raeburn 13399: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 13400: split(/\_/,$existing{'rolesdef_'.$rolename});
13401: foreach my $level ('c','d','s') {
13402: if ($newprivs{$level} ne $currprivs{$level}) {
13403: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13404: $newprivs{'c'},$confname,$dom);
13405: if ($result ne 'ok') {
13406: $errors .= '<li><span class="LC_error">'.
13407: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
13408: $rolename,$result).'</span></li>';
13409: } else {
13410: $changedprivs{$rolename} = \%newprivs;
13411: }
13412: last;
13413: }
13414: }
13415: if (ref($current{'adhoc'}) eq 'HASH') {
13416: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13417: %curr = %{$current{'adhoc'}{$rolename}};
13418: }
13419: }
13420: }
13421: my $newpos = $env{'form.'.$prefix.'_pos'};
13422: $newpos =~ s/\D+//g;
13423: $allpos[$newpos] = $rolename;
13424: my $newdesc = $env{'form.'.$prefix.'_desc'};
13425: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
13426: if ($curr{'desc'}) {
13427: if ($curr{'desc'} ne $newdesc) {
13428: $changes{'customrole'}{$rolename}{'desc'} = 1;
13429: $newsettings{$rolename}{'desc'} = $newdesc;
13430: }
13431: } elsif ($newdesc ne '') {
13432: $changes{'customrole'}{$rolename}{'desc'} = 1;
13433: $newsettings{$rolename}{'desc'} = $newdesc;
13434: }
13435: my $access = $env{'form.'.$prefix.'_access'};
13436: if (grep(/^\Q$access\E$/,@accesstypes)) {
13437: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
13438: if ($access eq 'status') {
13439: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
13440: if (scalar(@statuses) == 0) {
1.289 raeburn 13441: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 13442: } else {
13443: my (@shownstatus,$numtypes);
13444: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13445: if (ref($types) eq 'ARRAY') {
13446: $numtypes = scalar(@{$types});
13447: foreach my $type (sort(@statuses)) {
13448: if ($type eq 'default') {
13449: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13450: } elsif (grep(/^\Q$type\E$/,@{$types})) {
13451: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13452: push(@shownstatus,$usertypes->{$type});
13453: }
13454: }
13455: }
13456: if (grep(/^default$/,@statuses)) {
13457: push(@shownstatus,$othertitle);
13458: }
13459: if (scalar(@shownstatus) == 1+$numtypes) {
13460: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
13461: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
13462: } else {
13463: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
13464: if (ref($curr{'status'}) eq 'ARRAY') {
13465: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13466: if (@diffs) {
13467: $changes{'customrole'}{$rolename}{$access} = 1;
13468: }
13469: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13470: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 13471: }
1.166 raeburn 13472: }
13473: }
1.285 raeburn 13474: } elsif (($access eq 'inc') || ($access eq 'exc')) {
13475: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
13476: my @newspecstaff;
13477: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13478: foreach my $person (sort(@personnel)) {
13479: if ($domhelpdesk{$person}) {
13480: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
13481: }
13482: }
13483: if (ref($curr{$access}) eq 'ARRAY') {
13484: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13485: if (@diffs) {
13486: $changes{'customrole'}{$rolename}{$access} = 1;
13487: }
13488: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13489: $changes{'customrole'}{$rolename}{$access} = 1;
13490: }
13491: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13492: my ($uname,$udom) = split(/:/,$person);
13493: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
13494: }
13495: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 13496: }
1.285 raeburn 13497: } else {
13498: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
13499: }
13500: unless ($curr{'access'} eq $access) {
13501: $changes{'customrole'}{$rolename}{'access'} = 1;
13502: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 13503: }
13504: }
1.285 raeburn 13505: if (@allpos > 0) {
13506: my $idx = 0;
13507: foreach my $rolename (@allpos) {
13508: if ($rolename ne '') {
13509: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
13510: if (ref($current{'adhoc'}) eq 'HASH') {
13511: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13512: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
13513: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 13514: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 13515: }
13516: }
1.282 raeburn 13517: }
1.285 raeburn 13518: $idx ++;
1.166 raeburn 13519: }
13520: }
1.118 jms 13521: }
1.123 jms 13522: my $putresult;
13523: if (keys(%changes) > 0) {
1.166 raeburn 13524: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 13525: if ($putresult eq 'ok') {
1.285 raeburn 13526: if (ref($helphash{'helpsettings'}) eq 'HASH') {
13527: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
13528: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
13529: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
13530: }
13531: }
13532: my $cachetime = 24*60*60;
13533: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13534: if (ref($lastactref) eq 'HASH') {
13535: $lastactref->{'domdefaults'} = 1;
13536: }
13537: } else {
13538: $errors .= '<li><span class="LC_error">'.
13539: &mt('An error occurred storing the settings: [_1]',
13540: $putresult).'</span></li>';
13541: }
13542: }
13543: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
13544: $resulttext = &mt('Changes made:').'<ul>';
13545: my (%shownprivs,@levelorder);
13546: @levelorder = ('c','d','s');
13547: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 13548: foreach my $item (sort(keys(%changes))) {
13549: if ($item eq 'submitbugs') {
13550: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
13551: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
13552: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 13553: } elsif ($item eq 'customrole') {
13554: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 13555: my @keyorder = ('order','desc','access','status','exc','inc');
13556: my %keytext = &Apache::lonlocal::texthash(
13557: order => 'Order',
13558: desc => 'Role description',
13559: access => 'Role usage',
1.300 droeschl 13560: status => 'Allowed institutional types',
1.285 raeburn 13561: exc => 'Allowed personnel',
13562: inc => 'Disallowed personnel',
13563: );
1.282 raeburn 13564: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 13565: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
13566: if ($role eq $newrole) {
13567: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
13568: $role).'<ul>';
13569: } else {
13570: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13571: $role).'<ul>';
13572: }
13573: foreach my $key (@keyorder) {
13574: if ($changes{'customrole'}{$role}{$key}) {
13575: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
13576: $keytext{$key},$newsettings{$role}{$key}).
13577: '</li>';
13578: }
13579: }
13580: if (ref($changedprivs{$role}) eq 'HASH') {
13581: $shownprivs{$role} = 1;
13582: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
13583: foreach my $level (@levelorder) {
13584: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13585: next if ($item eq '');
13586: my ($priv) = split(/\&/,$item,2);
13587: if (&Apache::lonnet::plaintext($priv)) {
13588: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13589: unless ($level eq 'c') {
13590: $resulttext .= ' ('.$lt{$level}.')';
13591: }
13592: $resulttext .= '</li>';
13593: }
13594: }
13595: }
13596: $resulttext .= '</ul>';
13597: }
13598: $resulttext .= '</ul></li>';
13599: }
13600: }
13601: }
13602: }
13603: }
13604: }
13605: if (keys(%changedprivs)) {
13606: foreach my $role (sort(keys(%changedprivs))) {
13607: unless ($shownprivs{$role}) {
13608: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13609: $role).'<ul>'.
13610: '<li>'.&mt('Privileges set to :').'<ul>';
13611: foreach my $level (@levelorder) {
13612: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13613: next if ($item eq '');
13614: my ($priv) = split(/\&/,$item,2);
13615: if (&Apache::lonnet::plaintext($priv)) {
13616: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13617: unless ($level eq 'c') {
13618: $resulttext .= ' ('.$lt{$level}.')';
13619: }
13620: $resulttext .= '</li>';
13621: }
1.282 raeburn 13622: }
13623: }
1.285 raeburn 13624: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 13625: }
13626: }
13627: }
1.285 raeburn 13628: $resulttext .= '</ul>';
13629: } else {
13630: $resulttext = &mt('No changes made to help settings');
1.118 jms 13631: }
13632: if ($errors) {
1.168 raeburn 13633: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 13634: $errors.'</ul>';
1.118 jms 13635: }
13636: return $resulttext;
13637: }
13638:
1.121 raeburn 13639: sub modify_coursedefaults {
1.212 raeburn 13640: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 13641: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 13642: my %defaultchecked = (
13643: 'canuse_pdfforms' => 'off',
13644: 'uselcmath' => 'on',
13645: 'usejsme' => 'on'
13646: );
13647: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 13648: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 13649: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
13650: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
13651: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 13652: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 13653: my %staticdefaults = (
13654: anonsurvey_threshold => 10,
13655: uploadquota => 500,
1.257 raeburn 13656: postsubmit => 60,
1.276 raeburn 13657: mysqltables => 172800,
1.198 raeburn 13658: );
1.121 raeburn 13659:
13660: $defaultshash{'coursedefaults'} = {};
13661:
13662: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13663: if ($domconfig{'coursedefaults'} eq '') {
13664: $domconfig{'coursedefaults'} = {};
13665: }
13666: }
13667:
13668: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13669: foreach my $item (@toggles) {
13670: if ($defaultchecked{$item} eq 'on') {
13671: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13672: ($env{'form.'.$item} eq '0')) {
13673: $changes{$item} = 1;
1.192 raeburn 13674: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 13675: $changes{$item} = 1;
13676: }
13677: } elsif ($defaultchecked{$item} eq 'off') {
13678: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13679: ($env{'form.'.$item} eq '1')) {
13680: $changes{$item} = 1;
13681: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13682: $changes{$item} = 1;
13683: }
13684: }
13685: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13686: }
1.198 raeburn 13687: foreach my $item (@numbers) {
13688: my ($currdef,$newdef);
1.208 raeburn 13689: $newdef = $env{'form.'.$item};
1.198 raeburn 13690: if ($item eq 'anonsurvey_threshold') {
13691: $currdef = $domconfig{'coursedefaults'}{$item};
13692: $newdef =~ s/\D//g;
13693: if ($newdef eq '' || $newdef < 1) {
13694: $newdef = 1;
13695: }
13696: $defaultshash{'coursedefaults'}{$item} = $newdef;
13697: } else {
1.276 raeburn 13698: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13699: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13700: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 13701: }
13702: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 13703: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 13704: }
13705: if ($currdef ne $newdef) {
13706: my $staticdef;
13707: if ($item eq 'anonsurvey_threshold') {
13708: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13709: $changes{$item} = 1;
13710: }
1.276 raeburn 13711: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 13712: my $setting = $1;
1.276 raeburn 13713: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13714: $changes{$setting} = 1;
1.198 raeburn 13715: }
13716: }
1.139 raeburn 13717: }
13718: }
1.264 raeburn 13719: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13720: my @currclonecode;
13721: if (ref($currclone) eq 'HASH') {
13722: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13723: @currclonecode = @{$currclone->{'instcode'}};
13724: }
13725: }
13726: my $newclone;
1.289 raeburn 13727: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 13728: $newclone = $env{'form.canclone'};
13729: }
13730: if ($newclone eq 'instcode') {
13731: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13732: my (%codedefaults,@code_order,@clonecode);
13733: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13734: \@code_order);
13735: foreach my $item (@code_order) {
13736: if (grep(/^\Q$item\E$/,@newcodes)) {
13737: push(@clonecode,$item);
13738: }
13739: }
13740: if (@clonecode) {
13741: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13742: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13743: if (@diffs) {
13744: $changes{'canclone'} = 1;
13745: }
13746: } else {
13747: $newclone eq '';
13748: }
13749: } elsif ($newclone ne '') {
1.289 raeburn 13750: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13751: }
1.264 raeburn 13752: if ($newclone ne $currclone) {
13753: $changes{'canclone'} = 1;
13754: }
1.257 raeburn 13755: my %credits;
13756: foreach my $type (@types) {
13757: unless ($type eq 'community') {
13758: $credits{$type} = $env{'form.'.$type.'_credits'};
13759: $credits{$type} =~ s/[^\d.]+//g;
13760: }
13761: }
13762: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13763: ($env{'form.coursecredits'} eq '1')) {
13764: $changes{'coursecredits'} = 1;
13765: foreach my $type (keys(%credits)) {
13766: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13767: }
13768: } else {
1.289 raeburn 13769: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 13770: foreach my $type (@types) {
13771: unless ($type eq 'community') {
1.289 raeburn 13772: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 13773: $changes{'coursecredits'} = 1;
13774: }
13775: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13776: }
13777: }
13778: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13779: foreach my $type (@types) {
13780: unless ($type eq 'community') {
13781: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13782: $changes{'coursecredits'} = 1;
13783: last;
13784: }
13785: }
13786: }
13787: }
13788: }
13789: if ($env{'form.postsubmit'} eq '1') {
13790: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13791: my %currtimeout;
13792: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13793: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13794: $changes{'postsubmit'} = 1;
13795: }
13796: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13797: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13798: }
13799: } else {
13800: $changes{'postsubmit'} = 1;
13801: }
13802: foreach my $type (@types) {
13803: my $timeout = $env{'form.'.$type.'_timeout'};
13804: $timeout =~ s/\D//g;
13805: if ($timeout == $staticdefaults{'postsubmit'}) {
13806: $timeout = '';
13807: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13808: $timeout = '0';
13809: }
13810: unless ($timeout eq '') {
13811: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13812: }
13813: if (exists($currtimeout{$type})) {
13814: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 13815: $changes{'postsubmit'} = 1;
1.257 raeburn 13816: }
13817: } elsif ($timeout ne '') {
13818: $changes{'postsubmit'} = 1;
13819: }
13820: }
13821: } else {
13822: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13823: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13824: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13825: $changes{'postsubmit'} = 1;
13826: }
13827: } else {
13828: $changes{'postsubmit'} = 1;
13829: }
1.192 raeburn 13830: }
1.121 raeburn 13831: }
13832: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13833: $dom);
13834: if ($putresult eq 'ok') {
13835: if (keys(%changes) > 0) {
1.213 raeburn 13836: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 13837: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 13838: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 13839: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 13840: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
13841: if ($changes{$item}) {
13842: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13843: }
1.289 raeburn 13844: }
1.192 raeburn 13845: if ($changes{'coursecredits'}) {
13846: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 13847: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13848: $domdefaults{$type.'credits'} =
13849: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13850: }
13851: }
13852: }
13853: if ($changes{'postsubmit'}) {
13854: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13855: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13856: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13857: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13858: $domdefaults{$type.'postsubtimeout'} =
13859: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13860: }
13861: }
1.192 raeburn 13862: }
13863: }
1.198 raeburn 13864: if ($changes{'uploadquota'}) {
13865: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13866: foreach my $type (@types) {
13867: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13868: }
13869: }
13870: }
1.264 raeburn 13871: if ($changes{'canclone'}) {
13872: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13873: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13874: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13875: if (@clonecodes) {
13876: $domdefaults{'canclone'} = join('+',@clonecodes);
13877: }
13878: }
13879: } else {
13880: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13881: }
13882: }
1.121 raeburn 13883: my $cachetime = 24*60*60;
13884: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13885: if (ref($lastactref) eq 'HASH') {
13886: $lastactref->{'domdefaults'} = 1;
13887: }
1.121 raeburn 13888: }
13889: $resulttext = &mt('Changes made:').'<ul>';
13890: foreach my $item (sort(keys(%changes))) {
13891: if ($item eq 'canuse_pdfforms') {
13892: if ($env{'form.'.$item} eq '1') {
13893: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
13894: } else {
13895: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
13896: }
1.257 raeburn 13897: } elsif ($item eq 'uselcmath') {
13898: if ($env{'form.'.$item} eq '1') {
13899: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13900: } else {
13901: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13902: }
13903: } elsif ($item eq 'usejsme') {
13904: if ($env{'form.'.$item} eq '1') {
13905: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13906: } else {
1.289 raeburn 13907: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 13908: }
1.139 raeburn 13909: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 13910: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 13911: } elsif ($item eq 'uploadquota') {
13912: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13913: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13914: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13915: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 13916: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 13917: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 13918: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13919: '</ul>'.
13920: '</li>';
13921: } else {
13922: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13923: }
1.276 raeburn 13924: } elsif ($item eq 'mysqltables') {
13925: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13926: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13927: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13928: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13929: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13930: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
13931: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13932: '</ul>'.
13933: '</li>';
13934: } else {
13935: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13936: }
1.257 raeburn 13937: } elsif ($item eq 'postsubmit') {
13938: if ($domdefaults{'postsubmit'} eq 'off') {
13939: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13940: } else {
13941: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 13942: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 13943: $resulttext .= &mt('durations:').'<ul>';
13944: foreach my $type (@types) {
13945: $resulttext .= '<li>';
13946: my $timeout;
13947: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13948: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13949: }
13950: my $display;
13951: if ($timeout eq '0') {
13952: $display = &mt('unlimited');
13953: } elsif ($timeout eq '') {
13954: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13955: } else {
13956: $display = &mt('[quant,_1,second]',$timeout);
13957: }
13958: if ($type eq 'community') {
13959: $resulttext .= &mt('Communities');
13960: } elsif ($type eq 'official') {
13961: $resulttext .= &mt('Official courses');
13962: } elsif ($type eq 'unofficial') {
13963: $resulttext .= &mt('Unofficial courses');
13964: } elsif ($type eq 'textbook') {
13965: $resulttext .= &mt('Textbook courses');
1.271 raeburn 13966: } elsif ($type eq 'placement') {
13967: $resulttext .= &mt('Placement tests');
1.257 raeburn 13968: }
13969: $resulttext .= ' -- '.$display.'</li>';
13970: }
13971: $resulttext .= '</ul>';
13972: }
1.289 raeburn 13973: $resulttext .= '</li>';
1.257 raeburn 13974: }
1.192 raeburn 13975: } elsif ($item eq 'coursecredits') {
13976: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13977: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 13978: ($domdefaults{'unofficialcredits'} eq '') &&
13979: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 13980: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13981: } else {
13982: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13983: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13984: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 13985: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 13986: '</ul>'.
13987: '</li>';
13988: }
13989: } else {
13990: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13991: }
1.264 raeburn 13992: } elsif ($item eq 'canclone') {
13993: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13994: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13995: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13996: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13997: }
13998: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13999: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
14000: } else {
1.289 raeburn 14001: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 14002: }
1.140 raeburn 14003: }
1.121 raeburn 14004: }
14005: $resulttext .= '</ul>';
14006: } else {
14007: $resulttext = &mt('No changes made to course defaults');
14008: }
14009: } else {
14010: $resulttext = '<span class="LC_error">'.
14011: &mt('An error occurred: [_1]',$putresult).'</span>';
14012: }
14013: return $resulttext;
14014: }
14015:
1.231 raeburn 14016: sub modify_selfenrollment {
14017: my ($dom,$lastactref,%domconfig) = @_;
14018: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 14019: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 14020: my %titles = &tool_titles();
1.232 raeburn 14021: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
14022: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 14023: $ordered{'default'} = ['types','registered','approval','limit'];
14024:
14025: my (%roles,%shown,%toplevel);
14026: $roles{'0'} = &Apache::lonnet::plaintext('dc');
14027:
14028: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
14029: if ($domconfig{'selfenrollment'} eq '') {
14030: $domconfig{'selfenrollment'} = {};
14031: }
14032: }
14033: %toplevel = (
14034: admin => 'Configuration Rights',
14035: default => 'Default settings',
14036: validation => 'Validation of self-enrollment requests',
14037: );
1.233 raeburn 14038: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 14039:
14040: if (ref($ordered{'admin'}) eq 'ARRAY') {
14041: foreach my $item (@{$ordered{'admin'}}) {
14042: foreach my $type (@types) {
14043: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
14044: $selfenrollhash{'admin'}{$type}{$item} = 1;
14045: } else {
14046: $selfenrollhash{'admin'}{$type}{$item} = 0;
14047: }
14048: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
14049: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
14050: if ($selfenrollhash{'admin'}{$type}{$item} ne
14051: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
14052: push(@{$changes{'admin'}{$type}},$item);
14053: }
14054: } else {
14055: if (!$selfenrollhash{'admin'}{$type}{$item}) {
14056: push(@{$changes{'admin'}{$type}},$item);
14057: }
14058: }
14059: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
14060: push(@{$changes{'admin'}{$type}},$item);
14061: }
14062: }
14063: }
14064: }
14065:
14066: foreach my $item (@{$ordered{'default'}}) {
14067: foreach my $type (@types) {
14068: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
14069: if ($item eq 'types') {
14070: unless (($value eq 'all') || ($value eq 'dom')) {
14071: $value = '';
14072: }
14073: } elsif ($item eq 'registered') {
14074: unless ($value eq '1') {
14075: $value = 0;
14076: }
14077: } elsif ($item eq 'approval') {
14078: unless ($value =~ /^[012]$/) {
14079: $value = 0;
14080: }
14081: } else {
14082: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14083: $value = 'none';
14084: }
14085: }
14086: $selfenrollhash{'default'}{$type}{$item} = $value;
14087: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
14088: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14089: if ($selfenrollhash{'default'}{$type}{$item} ne
14090: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
14091: push(@{$changes{'default'}{$type}},$item);
14092: }
14093: } else {
14094: push(@{$changes{'default'}{$type}},$item);
14095: }
14096: } else {
14097: push(@{$changes{'default'}{$type}},$item);
14098: }
14099: if ($item eq 'limit') {
14100: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
14101: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
14102: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
14103: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
14104: }
14105: } else {
14106: $selfenrollhash{'default'}{$type}{'cap'} = '';
14107: }
14108: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
14109: if ($selfenrollhash{'default'}{$type}{'cap'} ne
14110: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
14111: push(@{$changes{'default'}{$type}},'cap');
14112: }
14113: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
14114: push(@{$changes{'default'}{$type}},'cap');
14115: }
14116: }
14117: }
14118: }
14119:
14120: foreach my $item (@{$itemsref}) {
14121: if ($item eq 'fields') {
14122: my @changed;
14123: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
14124: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
14125: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
14126: }
14127: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14128: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
14129: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
14130: $domconfig{'selfenrollment'}{'validation'}{$item});
14131: } else {
14132: @changed = @{$selfenrollhash{'validation'}{$item}};
14133: }
14134: } else {
14135: @changed = @{$selfenrollhash{'validation'}{$item}};
14136: }
14137: if (@changed) {
14138: if ($selfenrollhash{'validation'}{$item}) {
14139: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
14140: } else {
14141: $changes{'validation'}{$item} = &mt('None');
14142: }
14143: }
14144: } else {
14145: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
14146: if ($item eq 'markup') {
14147: if ($env{'form.selfenroll_validation_'.$item}) {
14148: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14149: }
14150: }
14151: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
14152: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
14153: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
14154: }
14155: }
14156: }
14157: }
14158:
14159: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
14160: $dom);
14161: if ($putresult eq 'ok') {
14162: if (keys(%changes) > 0) {
14163: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14164: $resulttext = &mt('Changes made:').'<ul>';
14165: foreach my $key ('admin','default','validation') {
14166: if (ref($changes{$key}) eq 'HASH') {
14167: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
14168: if ($key eq 'validation') {
14169: foreach my $item (@{$itemsref}) {
14170: if (exists($changes{$key}{$item})) {
14171: if ($item eq 'markup') {
14172: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14173: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
14174: } else {
14175: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
14176: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
14177: }
14178: }
14179: }
14180: } else {
14181: foreach my $type (@types) {
14182: if ($type eq 'community') {
14183: $roles{'1'} = &mt('Community personnel');
14184: } else {
14185: $roles{'1'} = &mt('Course personnel');
14186: }
14187: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 14188: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14189: if ($key eq 'admin') {
14190: my @mgrdc = ();
14191: if (ref($ordered{$key}) eq 'ARRAY') {
14192: foreach my $item (@{$ordered{'admin'}}) {
14193: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
14194: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
14195: push(@mgrdc,$item);
14196: }
14197: }
14198: }
14199: if (@mgrdc) {
14200: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
14201: } else {
14202: delete($domdefaults{$type.'selfenrolladmdc'});
14203: }
14204: }
14205: } else {
14206: if (ref($ordered{$key}) eq 'ARRAY') {
14207: foreach my $item (@{$ordered{$key}}) {
14208: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14209: $domdefaults{$type.'selfenroll'.$item} =
14210: $selfenrollhash{$key}{$type}{$item};
14211: }
14212: }
14213: }
14214: }
14215: }
1.231 raeburn 14216: $resulttext .= '<li>'.$titles{$type}.'<ul>';
14217: foreach my $item (@{$ordered{$key}}) {
14218: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
14219: $resulttext .= '<li>';
14220: if ($key eq 'admin') {
14221: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
14222: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
14223: } else {
14224: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
14225: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
14226: }
14227: $resulttext .= '</li>';
14228: }
14229: }
14230: $resulttext .= '</ul></li>';
14231: }
14232: }
14233: $resulttext .= '</ul></li>';
14234: }
14235: }
1.305 raeburn 14236: }
14237: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
14238: my $cachetime = 24*60*60;
14239: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14240: if (ref($lastactref) eq 'HASH') {
14241: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 14242: }
1.231 raeburn 14243: }
14244: $resulttext .= '</ul>';
14245: } else {
14246: $resulttext = &mt('No changes made to self-enrollment settings');
14247: }
14248: } else {
14249: $resulttext = '<span class="LC_error">'.
14250: &mt('An error occurred: [_1]',$putresult).'</span>';
14251: }
14252: return $resulttext;
14253: }
14254:
1.137 raeburn 14255: sub modify_usersessions {
1.212 raeburn 14256: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 14257: my @hostingtypes = ('version','excludedomain','includedomain');
14258: my @offloadtypes = ('primary','default');
14259: my %types = (
14260: remote => \@hostingtypes,
14261: hosted => \@hostingtypes,
14262: spares => \@offloadtypes,
14263: );
14264: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 14265: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 14266: my (%by_ip,%by_location,@intdoms,@instdoms);
14267: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 14268: my @locations = sort(keys(%by_location));
1.137 raeburn 14269: my (%defaultshash,%changes);
14270: foreach my $prefix (@prefixes) {
14271: $defaultshash{'usersessions'}{$prefix} = {};
14272: }
1.212 raeburn 14273: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 14274: my $resulttext;
1.138 raeburn 14275: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 14276: foreach my $prefix (@prefixes) {
1.145 raeburn 14277: next if ($prefix eq 'spares');
14278: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 14279: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14280: if ($type eq 'version') {
14281: my $value = $env{'form.'.$prefix.'_'.$type};
14282: my $okvalue;
14283: if ($value ne '') {
14284: if (grep(/^\Q$value\E$/,@lcversions)) {
14285: $okvalue = $value;
14286: }
14287: }
14288: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14289: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14290: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
14291: if ($inuse == 0) {
14292: $changes{$prefix}{$type} = 1;
14293: } else {
14294: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
14295: $changes{$prefix}{$type} = 1;
14296: }
14297: if ($okvalue ne '') {
14298: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14299: }
14300: }
14301: } else {
14302: if (($inuse == 1) && ($okvalue ne '')) {
14303: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14304: $changes{$prefix}{$type} = 1;
14305: }
14306: }
14307: } else {
14308: if (($inuse == 1) && ($okvalue ne '')) {
14309: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14310: $changes{$prefix}{$type} = 1;
14311: }
14312: }
14313: } else {
14314: if (($inuse == 1) && ($okvalue ne '')) {
14315: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
14316: $changes{$prefix}{$type} = 1;
14317: }
14318: }
14319: } else {
14320: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14321: my @okvals;
14322: foreach my $val (@vals) {
1.138 raeburn 14323: if ($val =~ /:/) {
14324: my @items = split(/:/,$val);
14325: foreach my $item (@items) {
14326: if (ref($by_location{$item}) eq 'ARRAY') {
14327: push(@okvals,$item);
14328: }
14329: }
14330: } else {
14331: if (ref($by_location{$val}) eq 'ARRAY') {
14332: push(@okvals,$val);
14333: }
1.137 raeburn 14334: }
14335: }
14336: @okvals = sort(@okvals);
14337: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14338: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
14339: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14340: if ($inuse == 0) {
14341: $changes{$prefix}{$type} = 1;
14342: } else {
14343: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14344: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
14345: if (@changed > 0) {
14346: $changes{$prefix}{$type} = 1;
14347: }
14348: }
14349: } else {
14350: if ($inuse == 1) {
14351: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14352: $changes{$prefix}{$type} = 1;
14353: }
14354: }
14355: } else {
14356: if ($inuse == 1) {
14357: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14358: $changes{$prefix}{$type} = 1;
14359: }
14360: }
14361: } else {
14362: if ($inuse == 1) {
14363: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14364: $changes{$prefix}{$type} = 1;
14365: }
14366: }
14367: }
14368: }
14369: }
1.145 raeburn 14370:
14371: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 14372: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 14373: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
14374: my $savespares;
14375:
14376: foreach my $lonhost (sort(keys(%servers))) {
14377: my $serverhomeID =
14378: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 14379: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 14380: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
14381: my %spareschg;
14382: foreach my $type (@{$types{'spares'}}) {
14383: my @okspares;
14384: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
14385: foreach my $server (@checked) {
1.152 raeburn 14386: if (&Apache::lonnet::hostname($server) ne '') {
14387: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
14388: unless (grep(/^\Q$server\E$/,@okspares)) {
14389: push(@okspares,$server);
14390: }
1.145 raeburn 14391: }
14392: }
14393: }
14394: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
14395: my $newspare;
1.152 raeburn 14396: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
14397: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 14398: $newspare = $new;
14399: }
14400: }
1.152 raeburn 14401: my @spares;
14402: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
14403: @spares = sort(@okspares,$newspare);
14404: } else {
14405: @spares = sort(@okspares);
14406: }
14407: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 14408: if (ref($spareid{$lonhost}) eq 'HASH') {
14409: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 14410: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 14411: if (@diffs > 0) {
14412: $spareschg{$type} = 1;
14413: }
14414: }
14415: }
14416: }
14417: if (keys(%spareschg) > 0) {
14418: $changes{'spares'}{$lonhost} = \%spareschg;
14419: }
14420: }
1.261 raeburn 14421: $defaultshash{'usersessions'}{'offloadnow'} = {};
14422: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
14423: my @okoffload;
14424: if (@offloadnow) {
14425: foreach my $server (@offloadnow) {
14426: if (&Apache::lonnet::hostname($server) ne '') {
14427: unless (grep(/^\Q$server\E$/,@okoffload)) {
14428: push(@okoffload,$server);
14429: }
14430: }
14431: }
14432: if (@okoffload) {
14433: foreach my $lonhost (@okoffload) {
14434: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
14435: }
14436: }
14437: }
1.145 raeburn 14438: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14439: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
14440: if (ref($changes{'spares'}) eq 'HASH') {
14441: if (keys(%{$changes{'spares'}}) > 0) {
14442: $savespares = 1;
14443: }
14444: }
14445: } else {
14446: $savespares = 1;
14447: }
1.261 raeburn 14448: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
14449: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
14450: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
14451: $changes{'offloadnow'} = 1;
14452: last;
14453: }
14454: }
14455: unless ($changes{'offloadnow'}) {
1.289 raeburn 14456: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 14457: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
14458: $changes{'offloadnow'} = 1;
14459: last;
14460: }
14461: }
14462: }
14463: } elsif (@okoffload) {
14464: $changes{'offloadnow'} = 1;
14465: }
14466: } elsif (@okoffload) {
14467: $changes{'offloadnow'} = 1;
1.145 raeburn 14468: }
1.147 raeburn 14469: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
14470: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 14471: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14472: $dom);
14473: if ($putresult eq 'ok') {
14474: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14475: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
14476: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
14477: }
14478: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
14479: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
14480: }
1.261 raeburn 14481: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14482: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
14483: }
1.137 raeburn 14484: }
14485: my $cachetime = 24*60*60;
14486: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 14487: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 14488: if (ref($lastactref) eq 'HASH') {
14489: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 14490: $lastactref->{'usersessions'} = 1;
1.212 raeburn 14491: }
1.147 raeburn 14492: if (keys(%changes) > 0) {
14493: my %lt = &usersession_titles();
14494: $resulttext = &mt('Changes made:').'<ul>';
14495: foreach my $prefix (@prefixes) {
14496: if (ref($changes{$prefix}) eq 'HASH') {
14497: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14498: if ($prefix eq 'spares') {
14499: if (ref($changes{$prefix}) eq 'HASH') {
14500: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
14501: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 14502: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 14503: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
14504: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 14505: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
14506: foreach my $type (@{$types{$prefix}}) {
14507: if ($changes{$prefix}{$lonhost}{$type}) {
14508: my $offloadto = &mt('None');
14509: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
14510: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
14511: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
14512: }
1.145 raeburn 14513: }
1.147 raeburn 14514: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 14515: }
1.137 raeburn 14516: }
14517: }
1.147 raeburn 14518: $resulttext .= '</li>';
1.137 raeburn 14519: }
14520: }
1.147 raeburn 14521: } else {
14522: foreach my $type (@{$types{$prefix}}) {
14523: if (defined($changes{$prefix}{$type})) {
14524: my $newvalue;
14525: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14526: if (ref($defaultshash{'usersessions'}{$prefix})) {
14527: if ($type eq 'version') {
14528: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
14529: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14530: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
14531: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
14532: }
1.145 raeburn 14533: }
14534: }
14535: }
1.147 raeburn 14536: if ($newvalue eq '') {
14537: if ($type eq 'version') {
14538: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
14539: } else {
14540: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14541: }
1.145 raeburn 14542: } else {
1.147 raeburn 14543: if ($type eq 'version') {
14544: $newvalue .= ' '.&mt('(or later)');
14545: }
14546: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 14547: }
1.137 raeburn 14548: }
14549: }
14550: }
1.147 raeburn 14551: $resulttext .= '</ul>';
1.137 raeburn 14552: }
14553: }
1.261 raeburn 14554: if ($changes{'offloadnow'}) {
14555: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14556: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
14557: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
14558: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
14559: $resulttext .= '<li>'.$lonhost.'</li>';
14560: }
14561: $resulttext .= '</ul>';
14562: } else {
14563: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
14564: }
14565: } else {
14566: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
14567: }
14568: }
1.147 raeburn 14569: $resulttext .= '</ul>';
14570: } else {
14571: $resulttext = $nochgmsg;
1.137 raeburn 14572: }
14573: } else {
14574: $resulttext = '<span class="LC_error">'.
14575: &mt('An error occurred: [_1]',$putresult).'</span>';
14576: }
14577: } else {
1.147 raeburn 14578: $resulttext = $nochgmsg;
1.137 raeburn 14579: }
14580: return $resulttext;
14581: }
14582:
1.275 raeburn 14583: sub modify_ssl {
14584: my ($dom,$lastactref,%domconfig) = @_;
14585: my (%by_ip,%by_location,@intdoms,@instdoms);
14586: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14587: my @locations = sort(keys(%by_location));
14588: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14589: my (%defaultshash,%changes);
14590: my $action = 'ssl';
1.293 raeburn 14591: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 14592: foreach my $prefix (@prefixes) {
14593: $defaultshash{$action}{$prefix} = {};
14594: }
14595: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14596: my $resulttext;
14597: my %iphost = &Apache::lonnet::get_iphost();
14598: my @reptypes = ('certreq','nocertreq');
14599: my @connecttypes = ('dom','intdom','other');
14600: my %types = (
1.293 raeburn 14601: connto => \@connecttypes,
14602: connfrom => \@connecttypes,
14603: replication => \@reptypes,
1.275 raeburn 14604: );
14605: foreach my $prefix (sort(keys(%types))) {
14606: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 14607: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14608: my $value = 'yes';
14609: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
14610: $value = $env{'form.'.$prefix.'_'.$type};
14611: }
14612: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14613: if ($domconfig{$action}{$prefix}{$type} ne '') {
14614: if ($value ne $domconfig{$action}{$prefix}{$type}) {
14615: $changes{$prefix}{$type} = 1;
14616: }
14617: $defaultshash{$action}{$prefix}{$type} = $value;
14618: } else {
14619: $defaultshash{$action}{$prefix}{$type} = $value;
14620: $changes{$prefix}{$type} = 1;
14621: }
14622: } else {
14623: $defaultshash{$action}{$prefix}{$type} = $value;
14624: $changes{$prefix}{$type} = 1;
14625: }
14626: if (($type eq 'dom') && (keys(%servers) == 1)) {
14627: delete($changes{$prefix}{$type});
14628: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
14629: delete($changes{$prefix}{$type});
14630: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
14631: delete($changes{$prefix}{$type});
14632: }
14633: } elsif ($prefix eq 'replication') {
14634: if (@locations > 0) {
14635: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14636: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14637: my @okvals;
14638: foreach my $val (@vals) {
14639: if ($val =~ /:/) {
14640: my @items = split(/:/,$val);
14641: foreach my $item (@items) {
14642: if (ref($by_location{$item}) eq 'ARRAY') {
14643: push(@okvals,$item);
14644: }
14645: }
14646: } else {
14647: if (ref($by_location{$val}) eq 'ARRAY') {
14648: push(@okvals,$val);
14649: }
14650: }
14651: }
14652: @okvals = sort(@okvals);
14653: if (ref($domconfig{$action}) eq 'HASH') {
14654: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14655: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
14656: if ($inuse == 0) {
14657: $changes{$prefix}{$type} = 1;
14658: } else {
14659: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14660: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
14661: if (@changed > 0) {
14662: $changes{$prefix}{$type} = 1;
14663: }
14664: }
14665: } else {
14666: if ($inuse == 1) {
14667: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14668: $changes{$prefix}{$type} = 1;
14669: }
14670: }
14671: } else {
14672: if ($inuse == 1) {
14673: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14674: $changes{$prefix}{$type} = 1;
14675: }
14676: }
14677: } else {
14678: if ($inuse == 1) {
14679: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14680: $changes{$prefix}{$type} = 1;
14681: }
14682: }
14683: }
14684: }
14685: }
14686: }
14687: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
14688: if (keys(%changes) > 0) {
14689: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14690: $dom);
14691: if ($putresult eq 'ok') {
14692: if (ref($defaultshash{$action}) eq 'HASH') {
14693: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
14694: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
14695: }
1.293 raeburn 14696: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
14697: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
14698: }
14699: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
14700: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 14701: }
14702: }
14703: my $cachetime = 24*60*60;
14704: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14705: if (ref($lastactref) eq 'HASH') {
14706: $lastactref->{'domdefaults'} = 1;
14707: }
14708: if (keys(%changes) > 0) {
14709: my %titles = &ssl_titles();
14710: $resulttext = &mt('Changes made:').'<ul>';
14711: foreach my $prefix (@prefixes) {
14712: if (ref($changes{$prefix}) eq 'HASH') {
14713: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
14714: foreach my $type (@{$types{$prefix}}) {
14715: if (defined($changes{$prefix}{$type})) {
14716: my $newvalue;
14717: if (ref($defaultshash{$action}) eq 'HASH') {
14718: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 14719: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14720: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
14721: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
14722: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
14723: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
14724: }
14725: }
14726: }
14727: if ($newvalue eq '') {
14728: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
14729: } else {
14730: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
14731: }
14732: }
14733: }
14734: }
14735: $resulttext .= '</ul>';
14736: }
14737: }
14738: } else {
14739: $resulttext = $nochgmsg;
14740: }
14741: } else {
14742: $resulttext = '<span class="LC_error">'.
14743: &mt('An error occurred: [_1]',$putresult).'</span>';
14744: }
14745: } else {
14746: $resulttext = $nochgmsg;
14747: }
14748: return $resulttext;
14749: }
14750:
1.279 raeburn 14751: sub modify_trust {
14752: my ($dom,$lastactref,%domconfig) = @_;
14753: my (%by_ip,%by_location,@intdoms,@instdoms);
14754: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14755: my @locations = sort(keys(%by_location));
14756: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
14757: my @types = ('exc','inc');
14758: my (%defaultshash,%changes);
14759: foreach my $prefix (@prefixes) {
14760: $defaultshash{'trust'}{$prefix} = {};
14761: }
14762: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14763: my $resulttext;
14764: foreach my $prefix (@prefixes) {
14765: foreach my $type (@types) {
14766: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14767: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14768: my @okvals;
14769: foreach my $val (@vals) {
14770: if ($val =~ /:/) {
14771: my @items = split(/:/,$val);
14772: foreach my $item (@items) {
14773: if (ref($by_location{$item}) eq 'ARRAY') {
14774: push(@okvals,$item);
14775: }
14776: }
14777: } else {
14778: if (ref($by_location{$val}) eq 'ARRAY') {
14779: push(@okvals,$val);
14780: }
14781: }
14782: }
14783: @okvals = sort(@okvals);
14784: if (ref($domconfig{'trust'}) eq 'HASH') {
14785: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
14786: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14787: if ($inuse == 0) {
14788: $changes{$prefix}{$type} = 1;
14789: } else {
14790: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14791: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
14792: if (@changed > 0) {
14793: $changes{$prefix}{$type} = 1;
14794: }
14795: }
14796: } else {
14797: if ($inuse == 1) {
14798: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14799: $changes{$prefix}{$type} = 1;
14800: }
14801: }
14802: } else {
14803: if ($inuse == 1) {
14804: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14805: $changes{$prefix}{$type} = 1;
14806: }
14807: }
14808: } else {
14809: if ($inuse == 1) {
14810: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14811: $changes{$prefix}{$type} = 1;
14812: }
14813: }
14814: }
14815: }
14816: my $nochgmsg = &mt('No changes made to trust settings.');
14817: if (keys(%changes) > 0) {
14818: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14819: $dom);
14820: if ($putresult eq 'ok') {
14821: if (ref($defaultshash{'trust'}) eq 'HASH') {
14822: foreach my $prefix (@prefixes) {
14823: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
14824: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
14825: }
14826: }
14827: }
14828: my $cachetime = 24*60*60;
14829: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14830: if (ref($lastactref) eq 'HASH') {
14831: $lastactref->{'domdefaults'} = 1;
14832: }
14833: if (keys(%changes) > 0) {
14834: my %lt = &trust_titles();
14835: $resulttext = &mt('Changes made:').'<ul>';
14836: foreach my $prefix (@prefixes) {
14837: if (ref($changes{$prefix}) eq 'HASH') {
14838: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14839: foreach my $type (@types) {
14840: if (defined($changes{$prefix}{$type})) {
14841: my $newvalue;
14842: if (ref($defaultshash{'trust'}) eq 'HASH') {
14843: if (ref($defaultshash{'trust'}{$prefix})) {
14844: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14845: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
14846: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
14847: }
14848: }
14849: }
14850: }
14851: if ($newvalue eq '') {
14852: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14853: } else {
14854: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
14855: }
14856: }
14857: }
14858: $resulttext .= '</ul>';
14859: }
14860: }
14861: $resulttext .= '</ul>';
14862: } else {
14863: $resulttext = $nochgmsg;
14864: }
14865: } else {
14866: $resulttext = '<span class="LC_error">'.
14867: &mt('An error occurred: [_1]',$putresult).'</span>';
14868: }
14869: } else {
14870: $resulttext = $nochgmsg;
14871: }
14872: return $resulttext;
14873: }
14874:
1.150 raeburn 14875: sub modify_loadbalancing {
14876: my ($dom,%domconfig) = @_;
14877: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14878: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14879: my ($othertitle,$usertypes,$types) =
14880: &Apache::loncommon::sorted_inst_types($dom);
14881: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 14882: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 14883: my @sparestypes = ('primary','default');
14884: my %typetitles = &sparestype_titles();
14885: my $resulttext;
1.171 raeburn 14886: my (%currbalancer,%currtargets,%currrules,%existing);
14887: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14888: %existing = %{$domconfig{'loadbalancing'}};
14889: }
14890: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
14891: \%currtargets,\%currrules);
14892: my ($saveloadbalancing,%defaultshash,%changes);
14893: my ($alltypes,$othertypes,$titles) =
14894: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14895: my %ruletitles = &offloadtype_text();
14896: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14897: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14898: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14899: if ($balancer eq '') {
14900: next;
14901: }
1.210 raeburn 14902: if (!exists($servers{$balancer})) {
1.171 raeburn 14903: if (exists($currbalancer{$balancer})) {
14904: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14905: }
1.171 raeburn 14906: next;
14907: }
14908: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14909: push(@{$changes{'delete'}},$balancer);
14910: next;
14911: }
14912: if (!exists($currbalancer{$balancer})) {
14913: push(@{$changes{'add'}},$balancer);
14914: }
14915: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14916: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14917: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14918: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14919: $saveloadbalancing = 1;
14920: }
14921: foreach my $sparetype (@sparestypes) {
14922: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14923: my @offloadto;
14924: foreach my $target (@targets) {
14925: if (($servers{$target}) && ($target ne $balancer)) {
14926: if ($sparetype eq 'default') {
14927: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14928: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14929: }
14930: }
1.171 raeburn 14931: unless(grep(/^\Q$target\E$/,@offloadto)) {
14932: push(@offloadto,$target);
14933: }
1.150 raeburn 14934: }
14935: }
1.284 raeburn 14936: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14937: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14938: push(@offloadto,$balancer);
14939: }
14940: }
14941: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14942: }
1.171 raeburn 14943: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14944: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14945: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14946: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14947: if (@targetdiffs > 0) {
1.171 raeburn 14948: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14949: }
1.171 raeburn 14950: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14951: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14952: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14953: }
14954: }
14955: }
14956: } else {
1.171 raeburn 14957: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 14958: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14959: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14960: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14961: $changes{'curr'}{$balancer}{'targets'} = 1;
14962: }
1.150 raeburn 14963: }
14964: }
1.210 raeburn 14965: }
1.150 raeburn 14966: }
14967: my $ishomedom;
1.171 raeburn 14968: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14969: $ishomedom = 1;
1.150 raeburn 14970: }
14971: if (ref($alltypes) eq 'ARRAY') {
14972: foreach my $type (@{$alltypes}) {
14973: my $rule;
1.210 raeburn 14974: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14975: (!$ishomedom)) {
1.171 raeburn 14976: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14977: }
14978: if ($rule eq 'specific') {
1.255 raeburn 14979: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 14980: if (exists($servers{$specifiedhost})) {
1.255 raeburn 14981: $rule = $specifiedhost;
14982: }
1.150 raeburn 14983: }
1.171 raeburn 14984: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14985: if (ref($currrules{$balancer}) eq 'HASH') {
14986: if ($rule ne $currrules{$balancer}{$type}) {
14987: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14988: }
14989: } elsif ($rule ne '') {
1.171 raeburn 14990: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14991: }
14992: }
14993: }
1.171 raeburn 14994: }
14995: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14996: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14997: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14998: $defaultshash{'loadbalancing'} = {};
14999: }
15000: my $putresult = &Apache::lonnet::put_dom('configuration',
15001: \%defaultshash,$dom);
15002: if ($putresult eq 'ok') {
15003: if (keys(%changes) > 0) {
1.252 raeburn 15004: my %toupdate;
1.171 raeburn 15005: if (ref($changes{'delete'}) eq 'ARRAY') {
15006: foreach my $balancer (sort(@{$changes{'delete'}})) {
15007: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 15008: $toupdate{$balancer} = 1;
1.150 raeburn 15009: }
1.171 raeburn 15010: }
15011: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 15012: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 15013: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 15014: $toupdate{$balancer} = 1;
1.171 raeburn 15015: }
15016: }
15017: if (ref($changes{'curr'}) eq 'HASH') {
15018: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 15019: $toupdate{$balancer} = 1;
1.171 raeburn 15020: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
15021: if ($changes{'curr'}{$balancer}{'targets'}) {
15022: my %offloadstr;
15023: foreach my $sparetype (@sparestypes) {
15024: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15025: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
15026: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15027: }
15028: }
1.150 raeburn 15029: }
1.171 raeburn 15030: if (keys(%offloadstr) == 0) {
15031: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 15032: } else {
1.171 raeburn 15033: my $showoffload;
15034: foreach my $sparetype (@sparestypes) {
15035: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
15036: if (defined($offloadstr{$sparetype})) {
15037: $showoffload .= $offloadstr{$sparetype};
15038: } else {
15039: $showoffload .= &mt('None');
15040: }
15041: $showoffload .= (' 'x3);
15042: }
15043: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 15044: }
15045: }
15046: }
1.171 raeburn 15047: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
15048: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
15049: foreach my $type (@{$alltypes}) {
15050: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
15051: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
15052: my $balancetext;
15053: if ($rule eq '') {
15054: $balancetext = $ruletitles{'default'};
1.209 raeburn 15055: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 15056: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 15057: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 15058: foreach my $sparetype (@sparestypes) {
15059: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
15060: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
15061: }
15062: }
1.253 raeburn 15063: foreach my $item (@{$alltypes}) {
15064: next if ($item =~ /^_LC_ipchange/);
15065: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
15066: if ($hasrule eq 'homeserver') {
15067: map { $toupdate{$_} = 1; } (keys(%libraryservers));
15068: } else {
15069: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
15070: if ($servers{$hasrule}) {
15071: $toupdate{$hasrule} = 1;
15072: }
15073: }
15074: }
15075: }
1.254 raeburn 15076: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
15077: $balancetext = $ruletitles{$rule};
15078: } else {
15079: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
15080: $balancetext = $ruletitles{'particular'}.' '.$receiver;
15081: if ($receiver) {
15082: $toupdate{$receiver};
15083: }
15084: }
15085: } else {
15086: $balancetext = $ruletitles{$rule};
1.252 raeburn 15087: }
1.171 raeburn 15088: } else {
15089: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
15090: }
1.210 raeburn 15091: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 15092: }
15093: }
15094: }
15095: }
1.252 raeburn 15096: if (keys(%toupdate)) {
15097: my %thismachine;
15098: my $updatedhere;
15099: my $cachetime = 60*60*24;
15100: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
15101: foreach my $lonhost (keys(%toupdate)) {
15102: if ($thismachine{$lonhost}) {
15103: unless ($updatedhere) {
15104: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
15105: $defaultshash{'loadbalancing'},
15106: $cachetime);
15107: $updatedhere = 1;
15108: }
15109: } else {
15110: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
15111: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
15112: }
15113: }
15114: }
1.150 raeburn 15115: }
1.171 raeburn 15116: }
15117: if ($resulttext ne '') {
15118: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 15119: } else {
15120: $resulttext = $nochgmsg;
15121: }
15122: } else {
1.171 raeburn 15123: $resulttext = $nochgmsg;
1.150 raeburn 15124: }
15125: } else {
1.171 raeburn 15126: $resulttext = '<span class="LC_error">'.
15127: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 15128: }
15129: } else {
1.171 raeburn 15130: $resulttext = $nochgmsg;
1.150 raeburn 15131: }
15132: return $resulttext;
15133: }
15134:
1.48 raeburn 15135: sub recurse_check {
15136: my ($chkcats,$categories,$depth,$name) = @_;
15137: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
15138: my $chg = 0;
15139: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
15140: my $category = $chkcats->[$depth]{$name}[$j];
15141: my $item;
15142: if ($category eq '') {
15143: $chg ++;
15144: } else {
15145: my $deeper = $depth + 1;
15146: $item = &escape($category).':'.&escape($name).':'.$depth;
15147: if ($chg) {
15148: $categories->{$item} -= $chg;
15149: }
15150: &recurse_check($chkcats,$categories,$deeper,$category);
15151: $deeper --;
15152: }
15153: }
15154: }
15155: return;
15156: }
15157:
15158: sub recurse_cat_deletes {
15159: my ($item,$coursecategories,$deletions) = @_;
15160: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15161: my $subdepth = $depth + 1;
15162: if (ref($coursecategories) eq 'HASH') {
15163: foreach my $subitem (keys(%{$coursecategories})) {
15164: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
15165: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
15166: delete($coursecategories->{$subitem});
15167: $deletions->{$subitem} = 1;
15168: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 15169: }
1.48 raeburn 15170: }
15171: }
15172: return;
15173: }
15174:
1.125 raeburn 15175: sub active_dc_picker {
1.191 raeburn 15176: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 15177: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 15178: my @domcoord = keys(%domcoords);
15179: if (keys(%currhash)) {
15180: foreach my $dc (keys(%currhash)) {
15181: unless (exists($domcoords{$dc})) {
15182: push(@domcoord,$dc);
15183: }
15184: }
15185: }
15186: @domcoord = sort(@domcoord);
1.210 raeburn 15187: my $numdcs = scalar(@domcoord);
1.191 raeburn 15188: my $rows = 0;
15189: my $table;
1.125 raeburn 15190: if ($numdcs > 1) {
1.191 raeburn 15191: $table = '<table>';
15192: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 15193: my $rem = $i%($numinrow);
15194: if ($rem == 0) {
15195: if ($i > 0) {
1.191 raeburn 15196: $table .= '</tr>';
1.125 raeburn 15197: }
1.191 raeburn 15198: $table .= '<tr>';
15199: $rows ++;
1.125 raeburn 15200: }
1.191 raeburn 15201: my $check = '';
15202: if ($inputtype eq 'radio') {
15203: if (keys(%currhash) == 0) {
15204: if (!$i) {
15205: $check = ' checked="checked"';
15206: }
15207: } elsif (exists($currhash{$domcoord[$i]})) {
15208: $check = ' checked="checked"';
15209: }
15210: } else {
15211: if (exists($currhash{$domcoord[$i]})) {
15212: $check = ' checked="checked"';
1.125 raeburn 15213: }
15214: }
1.191 raeburn 15215: if ($i == @domcoord - 1) {
1.125 raeburn 15216: my $colsleft = $numinrow - $rem;
15217: if ($colsleft > 1) {
1.191 raeburn 15218: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 15219: } else {
1.191 raeburn 15220: $table .= '<td class="LC_left_item">';
1.125 raeburn 15221: }
15222: } else {
1.191 raeburn 15223: $table .= '<td class="LC_left_item">';
15224: }
15225: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
15226: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
15227: $table .= '<span class="LC_nobreak"><label>'.
15228: '<input type="'.$inputtype.'" name="'.$name.'"'.
15229: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
15230: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 15231: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 15232: }
1.219 raeburn 15233: $table .= '</label></span></td>';
1.191 raeburn 15234: }
15235: $table .= '</tr></table>';
15236: } elsif ($numdcs == 1) {
1.219 raeburn 15237: my ($dcname,$dcdom) = split(':',$domcoord[0]);
15238: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 15239: if ($inputtype eq 'radio') {
1.247 raeburn 15240: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 15241: if ($user ne $dcname.':'.$dcdom) {
15242: $table .= ' ('.$dcname.':'.$dcdom.')';
15243: }
1.191 raeburn 15244: } else {
15245: my $check;
15246: if (exists($currhash{$domcoord[0]})) {
15247: $check = ' checked="checked"';
1.125 raeburn 15248: }
1.247 raeburn 15249: $table = '<span class="LC_nobreak"><label>'.
15250: '<input type="checkbox" name="'.$name.'" '.
15251: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 15252: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 15253: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 15254: }
1.220 raeburn 15255: $table .= '</label></span>';
1.191 raeburn 15256: $rows ++;
1.125 raeburn 15257: }
15258: }
1.191 raeburn 15259: return ($numdcs,$table,$rows);
1.125 raeburn 15260: }
15261:
1.137 raeburn 15262: sub usersession_titles {
15263: return &Apache::lonlocal::texthash(
15264: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
15265: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 15266: spares => 'Servers offloaded to, when busy',
1.137 raeburn 15267: version => 'LON-CAPA version requirement',
1.138 raeburn 15268: excludedomain => 'Allow all, but exclude specific domains',
15269: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 15270: primary => 'Primary (checked first)',
1.154 raeburn 15271: default => 'Default',
1.137 raeburn 15272: );
15273: }
15274:
1.152 raeburn 15275: sub id_for_thisdom {
15276: my (%servers) = @_;
15277: my %altids;
15278: foreach my $server (keys(%servers)) {
15279: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
15280: if ($serverhome ne $server) {
15281: $altids{$serverhome} = $server;
15282: }
15283: }
15284: return %altids;
15285: }
15286:
1.150 raeburn 15287: sub count_servers {
15288: my ($currbalancer,%servers) = @_;
15289: my (@spares,$numspares);
15290: foreach my $lonhost (sort(keys(%servers))) {
15291: next if ($currbalancer eq $lonhost);
15292: push(@spares,$lonhost);
15293: }
15294: if ($currbalancer) {
15295: $numspares = scalar(@spares);
15296: } else {
15297: $numspares = scalar(@spares) - 1;
15298: }
15299: return ($numspares,@spares);
15300: }
15301:
15302: sub lonbalance_targets_js {
1.171 raeburn 15303: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 15304: my $select = &mt('Select');
15305: my ($alltargets,$allishome,$allinsttypes,@alltypes);
15306: if (ref($servers) eq 'HASH') {
15307: $alltargets = join("','",sort(keys(%{$servers})));
15308: my @homedoms;
15309: foreach my $server (sort(keys(%{$servers}))) {
15310: if (&Apache::lonnet::host_domain($server) eq $dom) {
15311: push(@homedoms,'1');
15312: } else {
15313: push(@homedoms,'0');
15314: }
15315: }
15316: $allishome = join("','",@homedoms);
15317: }
15318: if (ref($types) eq 'ARRAY') {
15319: if (@{$types} > 0) {
15320: @alltypes = @{$types};
15321: }
15322: }
15323: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
15324: $allinsttypes = join("','",@alltypes);
1.171 raeburn 15325: my (%currbalancer,%currtargets,%currrules,%existing);
15326: if (ref($settings) eq 'HASH') {
15327: %existing = %{$settings};
15328: }
15329: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
15330: \%currtargets,\%currrules);
1.210 raeburn 15331: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 15332: return <<"END";
15333:
15334: <script type="text/javascript">
15335: // <![CDATA[
15336:
1.171 raeburn 15337: currBalancers = new Array('$balancers');
15338:
15339: function toggleTargets(balnum) {
15340: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15341: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
15342: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
15343: var prevbalancer = prevhostitem.value;
15344: var baltotal = document.getElementById('loadbalancing_total').value;
15345: prevhostitem.value = balancer;
15346: if (prevbalancer != '') {
15347: var prevIdx = currBalancers.indexOf(prevbalancer);
15348: if (prevIdx != -1) {
15349: currBalancers.splice(prevIdx,1);
15350: }
15351: }
1.150 raeburn 15352: if (balancer == '') {
1.171 raeburn 15353: hideSpares(balnum);
1.150 raeburn 15354: } else {
1.171 raeburn 15355: var currIdx = currBalancers.indexOf(balancer);
15356: if (currIdx == -1) {
15357: currBalancers.push(balancer);
15358: }
1.150 raeburn 15359: var homedoms = new Array('$allishome');
1.171 raeburn 15360: var ishomedom = homedoms[lonhostitem.selectedIndex];
15361: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 15362: }
1.171 raeburn 15363: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 15364: return;
15365: }
15366:
1.171 raeburn 15367: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 15368: var alltargets = new Array('$alltargets');
15369: var insttypes = new Array('$allinsttypes');
1.151 raeburn 15370: var offloadtypes = new Array('primary','default');
15371:
1.171 raeburn 15372: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
15373: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 15374:
1.151 raeburn 15375: for (var i=0; i<offloadtypes.length; i++) {
15376: var count = 0;
15377: for (var j=0; j<alltargets.length; j++) {
15378: if (alltargets[j] != balancer) {
1.171 raeburn 15379: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
15380: item.value = alltargets[j];
15381: item.style.textAlign='left';
15382: item.style.textFace='normal';
15383: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
15384: if (currBalancers.indexOf(alltargets[j]) == -1) {
15385: item.disabled = '';
15386: } else {
15387: item.disabled = 'disabled';
15388: item.checked = false;
15389: }
1.151 raeburn 15390: count ++;
15391: }
1.150 raeburn 15392: }
15393: }
1.151 raeburn 15394: for (var k=0; k<insttypes.length; k++) {
15395: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 15396: if (ishomedom == 1) {
1.171 raeburn 15397: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15398: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15399: } else {
1.171 raeburn 15400: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15401: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 15402: }
15403: } else {
1.171 raeburn 15404: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15405: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15406: }
1.151 raeburn 15407: if ((insttypes[k] != '_LC_external') &&
15408: ((insttypes[k] != '_LC_internetdom') ||
15409: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 15410: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
15411: item.options.length = 0;
15412: item.options[0] = new Option("","",true,true);
1.210 raeburn 15413: var idx = 0;
1.151 raeburn 15414: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 15415: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
15416: idx ++;
15417: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 15418: }
15419: }
15420: }
15421: }
15422: return;
15423: }
15424:
1.171 raeburn 15425: function hideSpares(balnum) {
1.150 raeburn 15426: var alltargets = new Array('$alltargets');
15427: var insttypes = new Array('$allinsttypes');
15428: var offloadtypes = new Array('primary','default');
15429:
1.171 raeburn 15430: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
15431: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 15432:
15433: var total = alltargets.length - 1;
15434: for (var i=0; i<offloadtypes; i++) {
15435: for (var j=0; j<total; j++) {
1.171 raeburn 15436: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
15437: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
15438: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 15439: }
1.150 raeburn 15440: }
15441: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 15442: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15443: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 15444: if (insttypes[k] != '_LC_external') {
1.171 raeburn 15445: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
15446: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 15447: }
15448: }
15449: return;
15450: }
15451:
1.171 raeburn 15452: function checkOffloads(item,balnum,type) {
1.150 raeburn 15453: var alltargets = new Array('$alltargets');
15454: var offloadtypes = new Array('primary','default');
15455: if (item.checked) {
15456: var total = alltargets.length - 1;
15457: var other;
15458: if (type == offloadtypes[0]) {
1.151 raeburn 15459: other = offloadtypes[1];
1.150 raeburn 15460: } else {
1.151 raeburn 15461: other = offloadtypes[0];
1.150 raeburn 15462: }
15463: for (var i=0; i<total; i++) {
1.171 raeburn 15464: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 15465: if (server == item.value) {
1.171 raeburn 15466: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
15467: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 15468: }
15469: }
15470: }
15471: }
15472: return;
15473: }
15474:
1.171 raeburn 15475: function singleServerToggle(balnum,type) {
15476: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 15477: if (offloadtoSelIdx == 0) {
1.171 raeburn 15478: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
15479: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15480:
15481: } else {
1.171 raeburn 15482: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
15483: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 15484: }
15485: return;
15486: }
15487:
1.171 raeburn 15488: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 15489: if (type == '_LC_external') {
1.171 raeburn 15490: return;
1.150 raeburn 15491: }
1.171 raeburn 15492: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 15493: for (var i=0; i<typesRules.length; i++) {
15494: if (formname.elements[typesRules[i]].checked) {
15495: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 15496: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
15497: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15498: } else {
1.171 raeburn 15499: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
15500: }
15501: }
15502: }
15503: return;
15504: }
15505:
15506: function balancerDeleteChange(balnum) {
15507: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15508: var baltotal = document.getElementById('loadbalancing_total').value;
15509: var addtarget;
15510: var removetarget;
15511: var action = 'delete';
15512: if (document.getElementById('loadbalancing_delete_'+balnum)) {
15513: var lonhost = hostitem.value;
15514: var currIdx = currBalancers.indexOf(lonhost);
15515: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
15516: if (currIdx != -1) {
15517: currBalancers.splice(currIdx,1);
15518: }
15519: addtarget = lonhost;
15520: } else {
15521: if (currIdx == -1) {
15522: currBalancers.push(lonhost);
15523: }
15524: removetarget = lonhost;
15525: action = 'undelete';
15526: }
15527: balancerChange(balnum,baltotal,action,addtarget,removetarget);
15528: }
15529: return;
15530: }
15531:
15532: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
15533: if (baltotal > 1) {
15534: var offloadtypes = new Array('primary','default');
15535: var alltargets = new Array('$alltargets');
15536: var insttypes = new Array('$allinsttypes');
15537: for (var i=0; i<baltotal; i++) {
15538: if (i != balnum) {
15539: for (var j=0; j<offloadtypes.length; j++) {
15540: var total = alltargets.length - 1;
15541: for (var k=0; k<total; k++) {
15542: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
15543: var server = serveritem.value;
15544: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15545: if (server == addtarget) {
15546: serveritem.disabled = '';
15547: }
15548: }
15549: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15550: if (server == removetarget) {
15551: serveritem.disabled = 'disabled';
15552: serveritem.checked = false;
15553: }
15554: }
15555: }
15556: }
15557: for (var j=0; j<insttypes.length; j++) {
15558: if (insttypes[j] != '_LC_external') {
15559: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
15560: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
15561: var currSel = singleserver.selectedIndex;
15562: var currVal = singleserver.options[currSel].value;
15563: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15564: var numoptions = singleserver.options.length;
15565: var needsnew = 1;
15566: for (var k=0; k<numoptions; k++) {
15567: if (singleserver.options[k] == addtarget) {
15568: needsnew = 0;
15569: break;
15570: }
15571: }
15572: if (needsnew == 1) {
15573: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
15574: }
15575: }
15576: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15577: singleserver.options.length = 0;
15578: if ((currVal) && (currVal != removetarget)) {
15579: singleserver.options[0] = new Option("","",false,false);
15580: } else {
15581: singleserver.options[0] = new Option("","",true,true);
15582: }
15583: var idx = 0;
15584: for (var m=0; m<alltargets.length; m++) {
15585: if (currBalancers.indexOf(alltargets[m]) == -1) {
15586: idx ++;
15587: if (currVal == alltargets[m]) {
15588: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
15589: } else {
15590: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
15591: }
15592: }
15593: }
15594: }
15595: }
15596: }
15597: }
1.150 raeburn 15598: }
15599: }
15600: }
15601: return;
15602: }
15603:
1.152 raeburn 15604: // ]]>
15605: </script>
15606:
15607: END
15608: }
15609:
15610: sub new_spares_js {
15611: my @sparestypes = ('primary','default');
15612: my $types = join("','",@sparestypes);
15613: my $select = &mt('Select');
15614: return <<"END";
15615:
15616: <script type="text/javascript">
15617: // <![CDATA[
15618:
15619: function updateNewSpares(formname,lonhost) {
15620: var types = new Array('$types');
15621: var include = new Array();
15622: var exclude = new Array();
15623: for (var i=0; i<types.length; i++) {
15624: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
15625: for (var j=0; j<spareboxes.length; j++) {
15626: if (formname.elements[spareboxes[j]].checked) {
15627: exclude.push(formname.elements[spareboxes[j]].value);
15628: } else {
15629: include.push(formname.elements[spareboxes[j]].value);
15630: }
15631: }
15632: }
15633: for (var i=0; i<types.length; i++) {
15634: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
15635: var selIdx = newSpare.selectedIndex;
15636: var currnew = newSpare.options[selIdx].value;
15637: var okSpares = new Array();
15638: for (var j=0; j<newSpare.options.length; j++) {
15639: var possible = newSpare.options[j].value;
15640: if (possible != '') {
15641: if (exclude.indexOf(possible) == -1) {
15642: okSpares.push(possible);
15643: } else {
15644: if (currnew == possible) {
15645: selIdx = 0;
15646: }
15647: }
15648: }
15649: }
15650: for (var k=0; k<include.length; k++) {
15651: if (okSpares.indexOf(include[k]) == -1) {
15652: okSpares.push(include[k]);
15653: }
15654: }
15655: okSpares.sort();
15656: newSpare.options.length = 0;
15657: if (selIdx == 0) {
15658: newSpare.options[0] = new Option("$select","",true,true);
15659: } else {
15660: newSpare.options[0] = new Option("$select","",false,false);
15661: }
15662: for (var m=0; m<okSpares.length; m++) {
15663: var idx = m+1;
15664: var selThis = 0;
15665: if (selIdx != 0) {
15666: if (okSpares[m] == currnew) {
15667: selThis = 1;
15668: }
15669: }
15670: if (selThis == 1) {
15671: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
15672: } else {
15673: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15674: }
15675: }
15676: }
15677: return;
15678: }
15679:
15680: function checkNewSpares(lonhost,type) {
15681: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15682: var chosen = newSpare.options[newSpare.selectedIndex].value;
15683: if (chosen != '') {
15684: var othertype;
15685: var othernewSpare;
15686: if (type == 'primary') {
15687: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15688: }
15689: if (type == 'default') {
15690: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15691: }
15692: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15693: othernewSpare.selectedIndex = 0;
15694: }
15695: }
15696: return;
15697: }
15698:
15699: // ]]>
15700: </script>
15701:
15702: END
15703:
15704: }
15705:
15706: sub common_domprefs_js {
15707: return <<"END";
15708:
15709: <script type="text/javascript">
15710: // <![CDATA[
15711:
1.150 raeburn 15712: function getIndicesByName(formname,item) {
1.152 raeburn 15713: var group = new Array();
1.150 raeburn 15714: for (var i=0;i<formname.elements.length;i++) {
15715: if (formname.elements[i].name == item) {
1.152 raeburn 15716: group.push(formname.elements[i].id);
1.150 raeburn 15717: }
15718: }
1.152 raeburn 15719: return group;
1.150 raeburn 15720: }
15721:
15722: // ]]>
15723: </script>
15724:
15725: END
1.152 raeburn 15726:
1.150 raeburn 15727: }
15728:
1.165 raeburn 15729: sub recaptcha_js {
15730: my %lt = &captcha_phrases();
15731: return <<"END";
15732:
15733: <script type="text/javascript">
15734: // <![CDATA[
15735:
15736: function updateCaptcha(caller,context) {
15737: var privitem;
15738: var pubitem;
15739: var privtext;
15740: var pubtext;
1.269 raeburn 15741: var versionitem;
15742: var versiontext;
1.165 raeburn 15743: if (document.getElementById(context+'_recaptchapub')) {
15744: pubitem = document.getElementById(context+'_recaptchapub');
15745: } else {
15746: return;
15747: }
15748: if (document.getElementById(context+'_recaptchapriv')) {
15749: privitem = document.getElementById(context+'_recaptchapriv');
15750: } else {
15751: return;
15752: }
15753: if (document.getElementById(context+'_recaptchapubtxt')) {
15754: pubtext = document.getElementById(context+'_recaptchapubtxt');
15755: } else {
15756: return;
15757: }
15758: if (document.getElementById(context+'_recaptchaprivtxt')) {
15759: privtext = document.getElementById(context+'_recaptchaprivtxt');
15760: } else {
15761: return;
15762: }
1.269 raeburn 15763: if (document.getElementById(context+'_recaptchaversion')) {
15764: versionitem = document.getElementById(context+'_recaptchaversion');
15765: } else {
15766: return;
15767: }
15768: if (document.getElementById(context+'_recaptchavertxt')) {
15769: versiontext = document.getElementById(context+'_recaptchavertxt');
15770: } else {
15771: return;
15772: }
1.165 raeburn 15773: if (caller.checked) {
15774: if (caller.value == 'recaptcha') {
15775: pubitem.type = 'text';
15776: privitem.type = 'text';
15777: pubitem.size = '40';
15778: privitem.size = '40';
15779: pubtext.innerHTML = "$lt{'pub'}";
15780: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 15781: versionitem.type = 'text';
15782: versionitem.size = '3';
1.289 raeburn 15783: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 15784: } else {
15785: pubitem.type = 'hidden';
15786: privitem.type = 'hidden';
1.269 raeburn 15787: versionitem.type = 'hidden';
1.165 raeburn 15788: pubtext.innerHTML = '';
15789: privtext.innerHTML = '';
1.269 raeburn 15790: versiontext.innerHTML = '';
1.165 raeburn 15791: }
15792: }
15793: return;
15794: }
15795:
15796: // ]]>
15797: </script>
15798:
15799: END
15800:
15801: }
15802:
1.236 raeburn 15803: sub toggle_display_js {
1.192 raeburn 15804: return <<"END";
15805:
15806: <script type="text/javascript">
15807: // <![CDATA[
15808:
1.236 raeburn 15809: function toggleDisplay(domForm,caller) {
15810: if (document.getElementById(caller)) {
15811: var divitem = document.getElementById(caller);
15812: var optionsElement = domForm.coursecredits;
1.264 raeburn 15813: var checkval = 1;
15814: var dispval = 'block';
1.303 raeburn 15815: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 15816: if (caller == 'emailoptions') {
15817: optionsElement = domForm.cancreate_email;
15818: }
1.257 raeburn 15819: if (caller == 'studentsubmission') {
15820: optionsElement = domForm.postsubmit;
15821: }
1.264 raeburn 15822: if (caller == 'cloneinstcode') {
15823: optionsElement = domForm.canclone;
15824: checkval = 'instcode';
15825: }
1.303 raeburn 15826: if (selfcreateRegExp.test(caller)) {
15827: optionsElement = domForm.elements[caller];
15828: checkval = 'other';
15829: dispval = 'inline'
15830: }
1.236 raeburn 15831: if (optionsElement.length) {
1.192 raeburn 15832: var currval;
1.236 raeburn 15833: for (var i=0; i<optionsElement.length; i++) {
15834: if (optionsElement[i].checked) {
15835: currval = optionsElement[i].value;
1.192 raeburn 15836: }
15837: }
1.264 raeburn 15838: if (currval == checkval) {
15839: divitem.style.display = dispval;
1.192 raeburn 15840: } else {
1.236 raeburn 15841: divitem.style.display = 'none';
1.192 raeburn 15842: }
15843: }
15844: }
15845: return;
15846: }
15847:
15848: // ]]>
15849: </script>
15850:
15851: END
15852:
15853: }
15854:
1.165 raeburn 15855: sub captcha_phrases {
15856: return &Apache::lonlocal::texthash (
15857: priv => 'Private key',
15858: pub => 'Public key',
15859: original => 'original (CAPTCHA)',
15860: recaptcha => 'successor (ReCAPTCHA)',
15861: notused => 'unused',
1.289 raeburn 15862: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 15863: );
15864: }
15865:
1.205 raeburn 15866: sub devalidate_remote_domconfs {
1.212 raeburn 15867: my ($dom,$cachekeys) = @_;
15868: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 15869: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15870: my %thismachine;
15871: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 15872: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 15873: if (keys(%servers)) {
1.205 raeburn 15874: foreach my $server (keys(%servers)) {
15875: next if ($thismachine{$server});
1.212 raeburn 15876: my @cached;
15877: foreach my $name (@posscached) {
15878: if ($cachekeys->{$name}) {
15879: push(@cached,&escape($name).':'.&escape($dom));
15880: }
15881: }
15882: if (@cached) {
15883: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15884: }
1.205 raeburn 15885: }
15886: }
15887: return;
15888: }
15889:
1.3 raeburn 15890: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>