Annotation of loncom/interface/domainprefs.pm, revision 1.297
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.297 ! raeburn 4: # $Id: domainprefs.pm,v 1.296 2017/04/25 22:18:59 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',
284: col2 => 'Assignable to e-mail usernames'}],
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'},
366: {col1 => 'Self-creation with e-mail as username',
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.286 raeburn 601: if (grep(/^contacts$/,@actions)) {
602: $js .= &contacts_javascript();
603: }
1.150 raeburn 604: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 605: } else {
1.180 raeburn 606: # check if domconfig user exists for the domain.
607: my $servadm = $r->dir_config('lonAdmEMail');
608: my ($configuserok,$author_ok,$switchserver) =
609: &config_check($dom,$confname,$servadm);
610: unless ($configuserok eq 'ok') {
1.181 raeburn 611: &Apache::lonconfigsettings::print_header($r,$phase,$context);
612: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 613: $confname).
1.181 raeburn 614: '<br />'
615: );
1.180 raeburn 616: if ($switchserver) {
1.181 raeburn 617: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
618: '<br />'.
619: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
620: '<br />'.
621: &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).
622: '<br />'.
623: &mt('To do that now, use the following link: [_1]',$switchserver)
624: );
625: } else {
626: $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.').
627: '<br />'.
628: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
629: );
1.180 raeburn 630: }
631: $r->print(&Apache::loncommon::end_page());
632: return OK;
633: }
1.21 raeburn 634: if (keys(%domconfig) == 0) {
635: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 636: my @ids=&Apache::lonnet::current_machine_ids();
637: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 638: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 639: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 640: my $custom_img_count = 0;
641: foreach my $img (@loginimages) {
642: if ($designhash{$dom.'.login.'.$img} ne '') {
643: $custom_img_count ++;
644: }
645: }
646: foreach my $role (@roles) {
647: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
648: $custom_img_count ++;
649: }
650: }
651: if ($custom_img_count > 0) {
1.94 raeburn 652: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 653: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 654: $r->print(
655: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
656: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
657: &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 />'.
658: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
659: if ($switch_server) {
1.30 raeburn 660: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 661: }
1.91 raeburn 662: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 663: return OK;
664: }
665: }
666: }
1.91 raeburn 667: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 668: }
669: return OK;
670: }
671:
672: sub process_changes {
1.205 raeburn 673: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 674: my %domconfig;
675: if (ref($values) eq 'HASH') {
676: %domconfig = %{$values};
677: }
1.3 raeburn 678: my $output;
679: if ($action eq 'login') {
1.205 raeburn 680: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 681: } elsif ($action eq 'rolecolors') {
1.9 raeburn 682: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 683: $lastactref,%domconfig);
1.3 raeburn 684: } elsif ($action eq 'quotas') {
1.216 raeburn 685: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 686: } elsif ($action eq 'autoenroll') {
1.205 raeburn 687: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 688: } elsif ($action eq 'autoupdate') {
689: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 690: } elsif ($action eq 'autocreate') {
691: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 692: } elsif ($action eq 'directorysrch') {
1.295 raeburn 693: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 694: } elsif ($action eq 'usercreation') {
1.28 raeburn 695: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 696: } elsif ($action eq 'selfcreation') {
697: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 698: } elsif ($action eq 'usermodification') {
699: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 700: } elsif ($action eq 'contacts') {
1.205 raeburn 701: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 702: } elsif ($action eq 'defaults') {
1.212 raeburn 703: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 704: } elsif ($action eq 'scantron') {
1.205 raeburn 705: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 706: } elsif ($action eq 'coursecategories') {
1.239 raeburn 707: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 708: } elsif ($action eq 'serverstatuses') {
709: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 710: } elsif ($action eq 'requestcourses') {
1.216 raeburn 711: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 712: } elsif ($action eq 'requestauthor') {
1.216 raeburn 713: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 714: } elsif ($action eq 'helpsettings') {
1.285 raeburn 715: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 716: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 717: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 718: } elsif ($action eq 'selfenrollment') {
719: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 720: } elsif ($action eq 'usersessions') {
1.212 raeburn 721: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 722: } elsif ($action eq 'loadbalancing') {
723: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 724: } elsif ($action eq 'ltitools') {
725: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 726: } elsif ($action eq 'ssl') {
727: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 728: } elsif ($action eq 'trust') {
729: $output = &modify_trust($dom,$lastactref,%domconfig);
1.3 raeburn 730: }
731: return $output;
732: }
733:
734: sub print_config_box {
1.9 raeburn 735: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 736: my $rowtotal = 0;
1.49 raeburn 737: my $output;
738: if ($action eq 'coursecategories') {
739: $output = &coursecategories_javascript($settings);
1.236 raeburn 740: } elsif ($action eq 'defaults') {
741: $output = &defaults_javascript($settings);
1.282 raeburn 742: } elsif ($action eq 'helpsettings') {
743: my (%privs,%levelscurrent);
744: my %full=();
745: my %levels=(
746: course => {},
747: domain => {},
748: system => {},
749: );
750: my $context = 'domain';
751: my $crstype = 'Course';
752: my $formname = 'display';
753: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
754: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
755: $output =
756: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
757: \@templateroles);
1.91 raeburn 758: }
1.236 raeburn 759: $output .=
1.30 raeburn 760: '<table class="LC_nested_outer">
1.3 raeburn 761: <tr>
1.66 raeburn 762: <th align="left" valign="middle"><span class="LC_nobreak">'.
763: &mt($item->{text}).' '.
764: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
765: '</tr>';
1.30 raeburn 766: $rowtotal ++;
1.110 raeburn 767: my $numheaders = 1;
768: if (ref($item->{'header'}) eq 'ARRAY') {
769: $numheaders = scalar(@{$item->{'header'}});
770: }
771: if ($numheaders > 1) {
1.64 raeburn 772: my $colspan = '';
1.145 raeburn 773: my $rightcolspan = '';
1.238 raeburn 774: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 775: ($action eq 'directorysrch') ||
1.256 raeburn 776: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 777: $colspan = ' colspan="2"';
778: }
1.145 raeburn 779: if ($action eq 'usersessions') {
780: $rightcolspan = ' colspan="3"';
781: }
1.30 raeburn 782: $output .= '
1.3 raeburn 783: <tr>
784: <td>
785: <table class="LC_nested">
786: <tr class="LC_info_row">
1.59 bisitz 787: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 788: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 789: </tr>';
1.69 raeburn 790: $rowtotal ++;
1.230 raeburn 791: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 792: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 793: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 794: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
795: ($action eq 'contacts')) {
1.230 raeburn 796: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 797: } elsif ($action eq 'coursecategories') {
1.230 raeburn 798: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 799: } elsif ($action eq 'login') {
1.256 raeburn 800: if ($numheaders == 4) {
1.168 raeburn 801: $colspan = ' colspan="2"';
802: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
803: } else {
804: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
805: }
1.230 raeburn 806: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 807: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 808: } elsif ($action eq 'rolecolors') {
1.30 raeburn 809: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 810: }
1.30 raeburn 811: $output .= '
1.6 raeburn 812: </table>
813: </td>
814: </tr>
815: <tr>
816: <td>
817: <table class="LC_nested">
818: <tr class="LC_info_row">
1.230 raeburn 819: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 820: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 821: </tr>';
822: $rowtotal ++;
1.230 raeburn 823: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
824: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 825: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.294 raeburn 826: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238 raeburn 827: if ($action eq 'coursecategories') {
828: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
829: $colspan = ' colspan="2"';
1.279 raeburn 830: } elsif ($action eq 'trust') {
831: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 832: } else {
833: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
834: }
1.279 raeburn 835: if ($action eq 'trust') {
836: $output .= '
837: </table>
838: </td>
839: </tr>';
840: my @trusthdrs = qw(2 3 4 5 6 7);
841: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
842: for (my $i=0; $i<@trusthdrs; $i++) {
843: $output .= '
844: <tr>
845: <td>
846: <table class="LC_nested">
847: <tr class="LC_info_row">
848: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
849: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
850: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
851: </table>
852: </td>
853: </tr>';
854: }
855: $output .= '
856: <tr>
857: <td>
858: <table class="LC_nested">
859: <tr class="LC_info_row">
860: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
861: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
862: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
863: } else {
864: $output .= '
1.63 raeburn 865: </table>
866: </td>
867: </tr>
868: <tr>
869: <td>
870: <table class="LC_nested">
871: <tr class="LC_info_row">
872: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 873: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 874: </tr>'."\n";
1.279 raeburn 875: if ($action eq 'coursecategories') {
876: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
877: } else {
878: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
879: }
1.238 raeburn 880: }
1.63 raeburn 881: $rowtotal ++;
1.236 raeburn 882: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 883: ($action eq 'defaults') || ($action eq 'directorysrch') ||
884: ($action eq 'helpsettings')) {
1.230 raeburn 885: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.293 raeburn 886: } elsif ($action eq 'ssl') {
887: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
888: </table>
889: </td>
890: </tr>
891: <tr>
892: <td>
893: <table class="LC_nested">
894: <tr class="LC_info_row">
895: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
896: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
897: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
898: </table>
899: </td>
900: </tr>
901: <tr>
902: <td>
903: <table class="LC_nested">
904: <tr class="LC_info_row">
905: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
906: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
907: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 908: } elsif ($action eq 'login') {
1.256 raeburn 909: if ($numheaders == 4) {
1.168 raeburn 910: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
911: </table>
912: </td>
913: </tr>
914: <tr>
915: <td>
916: <table class="LC_nested">
917: <tr class="LC_info_row">
918: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 919: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 920: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
921: $rowtotal ++;
922: } else {
923: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
924: }
1.256 raeburn 925: $output .= '
926: </table>
927: </td>
928: </tr>
929: <tr>
930: <td>
931: <table class="LC_nested">
932: <tr class="LC_info_row">';
933: if ($numheaders == 4) {
934: $output .= '
935: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
936: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
937: </tr>';
938: } else {
939: $output .= '
940: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
941: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
942: </tr>';
943: }
944: $rowtotal ++;
945: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 946: } elsif ($action eq 'requestcourses') {
1.247 raeburn 947: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
948: $rowtotal ++;
949: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 950: </table>
951: </td>
952: </tr>
953: <tr>
954: <td>
955: <table class="LC_nested">
956: <tr class="LC_info_row">
957: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
958: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 959: &textbookcourses_javascript($settings).
960: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
961: </table>
962: </td>
963: </tr>
964: <tr>
965: <td>
966: <table class="LC_nested">
967: <tr class="LC_info_row">
968: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
969: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
970: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 971: </table>
972: </td>
973: </tr>
974: <tr>
975: <td>
976: <table class="LC_nested">
977: <tr class="LC_info_row">
1.242 raeburn 978: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
979: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 980: </tr>'.
981: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 982: } elsif ($action eq 'requestauthor') {
983: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 984: $rowtotal ++;
1.122 jms 985: } elsif ($action eq 'rolecolors') {
1.30 raeburn 986: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 987: </table>
988: </td>
989: </tr>
990: <tr>
991: <td>
992: <table class="LC_nested">
993: <tr class="LC_info_row">
1.69 raeburn 994: <td class="LC_left_item"'.$colspan.' valign="top">'.
995: &mt($item->{'header'}->[2]->{'col1'}).'</td>
996: <td class="LC_right_item" valign="top">'.
997: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 998: </tr>'.
1.30 raeburn 999: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1000: </table>
1001: </td>
1002: </tr>
1003: <tr>
1004: <td>
1005: <table class="LC_nested">
1006: <tr class="LC_info_row">
1.59 bisitz 1007: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1008: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1009: </tr>'.
1.30 raeburn 1010: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1011: $rowtotal += 2;
1.6 raeburn 1012: }
1.3 raeburn 1013: } else {
1.30 raeburn 1014: $output .= '
1.3 raeburn 1015: <tr>
1016: <td>
1017: <table class="LC_nested">
1.30 raeburn 1018: <tr class="LC_info_row">';
1.277 raeburn 1019: if ($action eq 'login') {
1.30 raeburn 1020: $output .= '
1.59 bisitz 1021: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1022: } elsif ($action eq 'serverstatuses') {
1023: $output .= '
1024: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1025: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1026:
1.6 raeburn 1027: } else {
1.30 raeburn 1028: $output .= '
1.69 raeburn 1029: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1030: }
1.72 raeburn 1031: if (defined($item->{'header'}->[0]->{'col3'})) {
1032: $output .= '<td class="LC_left_item" valign="top">'.
1033: &mt($item->{'header'}->[0]->{'col2'});
1034: if ($action eq 'serverstatuses') {
1035: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1036: }
1.69 raeburn 1037: } else {
1038: $output .= '<td class="LC_right_item" valign="top">'.
1039: &mt($item->{'header'}->[0]->{'col2'});
1040: }
1041: $output .= '</td>';
1042: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1043: if (defined($item->{'header'}->[0]->{'col4'})) {
1044: $output .= '<td class="LC_left_item" valign="top">'.
1045: &mt($item->{'header'}->[0]->{'col3'});
1046: } else {
1047: $output .= '<td class="LC_right_item" valign="top">'.
1048: &mt($item->{'header'}->[0]->{'col3'});
1049: }
1.69 raeburn 1050: if ($action eq 'serverstatuses') {
1051: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1052: }
1053: $output .= '</td>';
1.6 raeburn 1054: }
1.150 raeburn 1055: if ($item->{'header'}->[0]->{'col4'}) {
1056: $output .= '<td class="LC_right_item" valign="top">'.
1057: &mt($item->{'header'}->[0]->{'col4'});
1058: }
1.69 raeburn 1059: $output .= '</tr>';
1.48 raeburn 1060: $rowtotal ++;
1.168 raeburn 1061: if ($action eq 'quotas') {
1.86 raeburn 1062: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1063: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1064: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1065: ($action eq 'ltitools')) {
1.230 raeburn 1066: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1067: } elsif ($action eq 'scantron') {
1068: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1069: }
1.3 raeburn 1070: }
1.30 raeburn 1071: $output .= '
1.3 raeburn 1072: </table>
1073: </td>
1074: </tr>
1.30 raeburn 1075: </table><br />';
1076: return ($output,$rowtotal);
1.1 raeburn 1077: }
1078:
1.3 raeburn 1079: sub print_login {
1.168 raeburn 1080: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1081: my ($css_class,$datatable);
1.6 raeburn 1082: my %choices = &login_choices();
1.110 raeburn 1083:
1.168 raeburn 1084: if ($caller eq 'service') {
1.149 raeburn 1085: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1086: my $choice = $choices{'disallowlogin'};
1087: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1088: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1089: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1090: '<th>'.$choices{'server'}.'</th>'.
1091: '<th>'.$choices{'serverpath'}.'</th>'.
1092: '<th>'.$choices{'custompath'}.'</th>'.
1093: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1094: my %disallowed;
1095: if (ref($settings) eq 'HASH') {
1096: if (ref($settings->{'loginvia'}) eq 'HASH') {
1097: %disallowed = %{$settings->{'loginvia'}};
1098: }
1099: }
1100: foreach my $lonhost (sort(keys(%servers))) {
1101: my $direct = 'selected="selected"';
1.128 raeburn 1102: if (ref($disallowed{$lonhost}) eq 'HASH') {
1103: if ($disallowed{$lonhost}{'server'} ne '') {
1104: $direct = '';
1105: }
1.110 raeburn 1106: }
1.115 raeburn 1107: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1108: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1109: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1110: '</option>';
1.184 raeburn 1111: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1112: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1113: my $selected = '';
1.128 raeburn 1114: if (ref($disallowed{$lonhost}) eq 'HASH') {
1115: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1116: $selected = 'selected="selected"';
1117: }
1.110 raeburn 1118: }
1119: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1120: $servers{$hostid}.'</option>';
1121: }
1.128 raeburn 1122: $datatable .= '</select></td>'.
1123: '<td><select name="'.$lonhost.'_serverpath">';
1124: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1125: my $pathname = $path;
1126: if ($path eq 'custom') {
1127: $pathname = &mt('Custom Path').' ->';
1128: }
1129: my $selected = '';
1130: if (ref($disallowed{$lonhost}) eq 'HASH') {
1131: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1132: $selected = 'selected="selected"';
1133: }
1134: } elsif ($path eq '') {
1135: $selected = 'selected="selected"';
1136: }
1137: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1138: }
1139: $datatable .= '</select></td>';
1140: my ($custom,$exempt);
1141: if (ref($disallowed{$lonhost}) eq 'HASH') {
1142: $custom = $disallowed{$lonhost}{'custompath'};
1143: $exempt = $disallowed{$lonhost}{'exempt'};
1144: }
1145: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1146: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1147: '</tr>';
1.110 raeburn 1148: }
1149: $datatable .= '</table></td></tr>';
1150: return $datatable;
1.168 raeburn 1151: } elsif ($caller eq 'page') {
1152: my %defaultchecked = (
1153: 'coursecatalog' => 'on',
1.188 raeburn 1154: 'helpdesk' => 'on',
1.168 raeburn 1155: 'adminmail' => 'off',
1156: 'newuser' => 'off',
1157: );
1.188 raeburn 1158: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1159: my (%checkedon,%checkedoff);
1.42 raeburn 1160: foreach my $item (@toggles) {
1.168 raeburn 1161: if ($defaultchecked{$item} eq 'on') {
1162: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1163: $checkedoff{$item} = ' ';
1.168 raeburn 1164: } elsif ($defaultchecked{$item} eq 'off') {
1165: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1166: $checkedon{$item} = ' ';
1167: }
1.1 raeburn 1168: }
1.168 raeburn 1169: my @images = ('img','logo','domlogo','login');
1170: my @logintext = ('textcol','bgcol');
1171: my @bgs = ('pgbg','mainbg','sidebg');
1172: my @links = ('link','alink','vlink');
1173: my %designhash = &Apache::loncommon::get_domainconf($dom);
1174: my %defaultdesign = %Apache::loncommon::defaultdesign;
1175: my (%is_custom,%designs);
1176: my %defaults = (
1177: font => $defaultdesign{'login.font'},
1178: );
1.6 raeburn 1179: foreach my $item (@images) {
1.168 raeburn 1180: $defaults{$item} = $defaultdesign{'login.'.$item};
1181: $defaults{'showlogo'}{$item} = 1;
1182: }
1183: foreach my $item (@bgs) {
1184: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1185: }
1.41 raeburn 1186: foreach my $item (@logintext) {
1.168 raeburn 1187: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1188: }
1.168 raeburn 1189: foreach my $item (@links) {
1190: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1191: }
1.168 raeburn 1192: if (ref($settings) eq 'HASH') {
1193: foreach my $item (@toggles) {
1194: if ($settings->{$item} eq '1') {
1195: $checkedon{$item} = ' checked="checked" ';
1196: $checkedoff{$item} = ' ';
1197: } elsif ($settings->{$item} eq '0') {
1198: $checkedoff{$item} = ' checked="checked" ';
1199: $checkedon{$item} = ' ';
1200: }
1201: }
1202: foreach my $item (@images) {
1203: if (defined($settings->{$item})) {
1204: $designs{$item} = $settings->{$item};
1205: $is_custom{$item} = 1;
1206: }
1207: if (defined($settings->{'showlogo'}{$item})) {
1208: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1209: }
1210: }
1211: foreach my $item (@logintext) {
1212: if ($settings->{$item} ne '') {
1213: $designs{'logintext'}{$item} = $settings->{$item};
1214: $is_custom{$item} = 1;
1215: }
1216: }
1217: if ($settings->{'font'} ne '') {
1218: $designs{'font'} = $settings->{'font'};
1219: $is_custom{'font'} = 1;
1220: }
1221: foreach my $item (@bgs) {
1222: if ($settings->{$item} ne '') {
1223: $designs{'bgs'}{$item} = $settings->{$item};
1224: $is_custom{$item} = 1;
1225: }
1226: }
1227: foreach my $item (@links) {
1228: if ($settings->{$item} ne '') {
1229: $designs{'links'}{$item} = $settings->{$item};
1230: $is_custom{$item} = 1;
1231: }
1232: }
1233: } else {
1234: if ($designhash{$dom.'.login.font'} ne '') {
1235: $designs{'font'} = $designhash{$dom.'.login.font'};
1236: $is_custom{'font'} = 1;
1237: }
1238: foreach my $item (@images) {
1239: if ($designhash{$dom.'.login.'.$item} ne '') {
1240: $designs{$item} = $designhash{$dom.'.login.'.$item};
1241: $is_custom{$item} = 1;
1242: }
1243: }
1244: foreach my $item (@bgs) {
1245: if ($designhash{$dom.'.login.'.$item} ne '') {
1246: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1247: $is_custom{$item} = 1;
1248: }
1.6 raeburn 1249: }
1.168 raeburn 1250: foreach my $item (@links) {
1251: if ($designhash{$dom.'.login.'.$item} ne '') {
1252: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1253: $is_custom{$item} = 1;
1254: }
1.6 raeburn 1255: }
1256: }
1.168 raeburn 1257: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1258: logo => 'Institution Logo',
1259: domlogo => 'Domain Logo',
1260: login => 'Login box');
1261: my $itemcount = 1;
1262: foreach my $item (@toggles) {
1263: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1264: $datatable .=
1265: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1266: '</td><td>'.
1267: '<span class="LC_nobreak"><label><input type="radio" name="'.
1268: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1269: '</label> <label><input type="radio" name="'.$item.'"'.
1270: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1271: '</tr>';
1272: $itemcount ++;
1.6 raeburn 1273: }
1.168 raeburn 1274: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1275: $datatable .= '</tr></table></td></tr>';
1276: } elsif ($caller eq 'help') {
1277: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1278: my $switchserver = &check_switchserver($dom,$confname);
1279: my $itemcount = 1;
1280: $defaulturl = '/adm/loginproblems.html';
1281: $defaulttype = 'default';
1282: %lt = &Apache::lonlocal::texthash (
1283: del => 'Delete?',
1284: rep => 'Replace:',
1285: upl => 'Upload:',
1286: default => 'Default',
1287: custom => 'Custom',
1288: );
1289: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1290: my @currlangs;
1291: if (ref($settings) eq 'HASH') {
1292: if (ref($settings->{'helpurl'}) eq 'HASH') {
1293: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1294: next if ($settings->{'helpurl'}{$key} eq '');
1295: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1296: $type{$key} = 'custom';
1297: unless ($key eq 'nolang') {
1298: push(@currlangs,$key);
1299: }
1300: }
1301: } elsif ($settings->{'helpurl'} ne '') {
1302: $type{'nolang'} = 'custom';
1303: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1304: }
1305: }
1.168 raeburn 1306: foreach my $lang ('nolang',sort(@currlangs)) {
1307: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1308: $datatable .= '<tr'.$css_class.'>';
1309: if ($url{$lang} eq '') {
1310: $url{$lang} = $defaulturl;
1311: }
1312: if ($type{$lang} eq '') {
1313: $type{$lang} = $defaulttype;
1314: }
1315: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1316: if ($lang eq 'nolang') {
1317: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1318: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1319: } else {
1320: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1321: $langchoices{$lang},
1322: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1323: }
1324: $datatable .= '</span></td>'."\n".
1325: '<td class="LC_left_item">';
1326: if ($type{$lang} eq 'custom') {
1327: $datatable .= '<span class="LC_nobreak"><label>'.
1328: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1329: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1330: } else {
1331: $datatable .= $lt{'upl'};
1332: }
1333: $datatable .='<br />';
1334: if ($switchserver) {
1335: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1336: } else {
1337: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1338: }
1.168 raeburn 1339: $datatable .= '</td></tr>';
1340: $itemcount ++;
1.6 raeburn 1341: }
1.168 raeburn 1342: my @addlangs;
1343: foreach my $lang (sort(keys(%langchoices))) {
1344: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1345: push(@addlangs,$lang);
1346: }
1347: if (@addlangs > 0) {
1348: my %toadd;
1349: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1350: $toadd{''} = &mt('Select');
1351: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1352: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1353: &mt('Add log-in help page for a specific language:').' '.
1354: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1355: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1356: if ($switchserver) {
1357: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1358: } else {
1359: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1360: }
1.168 raeburn 1361: $datatable .= '</td></tr>';
1.169 raeburn 1362: $itemcount ++;
1.6 raeburn 1363: }
1.169 raeburn 1364: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1365: } elsif ($caller eq 'headtag') {
1366: my %domservers = &Apache::lonnet::get_servers($dom);
1367: my $choice = $choices{'headtag'};
1368: $css_class = ' class="LC_odd_row"';
1369: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1370: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1371: '<th>'.$choices{'current'}.'</th>'.
1372: '<th>'.$choices{'action'}.'</th>'.
1373: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1374: my (%currurls,%currexempt);
1375: if (ref($settings) eq 'HASH') {
1376: if (ref($settings->{'headtag'}) eq 'HASH') {
1377: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1378: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1379: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1380: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1381: }
1382: }
1383: }
1384: }
1385: my %lt = &Apache::lonlocal::texthash(
1386: del => 'Delete?',
1387: rep => 'Replace:',
1388: upl => 'Upload:',
1389: curr => 'View contents',
1390: none => 'None',
1391: );
1392: my $switchserver = &check_switchserver($dom,$confname);
1393: foreach my $lonhost (sort(keys(%domservers))) {
1394: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1395: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1396: if ($currurls{$lonhost}) {
1397: $datatable .= '<td class="LC_right_item"><a href="'.
1398: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1399: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1400: '">'.$lt{'curr'}.'</a></td>'.
1401: '<td><span class="LC_nobreak"><label>'.
1402: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1403: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1404: } else {
1405: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1406: }
1407: $datatable .='<br />';
1408: if ($switchserver) {
1409: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1410: } else {
1411: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1412: }
1413: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1414: }
1415: $datatable .= '</table></td></tr>';
1.1 raeburn 1416: }
1.6 raeburn 1417: return $datatable;
1418: }
1419:
1420: sub login_choices {
1421: my %choices =
1422: &Apache::lonlocal::texthash (
1.116 bisitz 1423: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1424: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1425: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1426: disallowlogin => "Login page requests redirected",
1427: hostid => "Server",
1.128 raeburn 1428: server => "Redirect to:",
1429: serverpath => "Path",
1430: custompath => "Custom",
1431: exempt => "Exempt IP(s)",
1.110 raeburn 1432: directlogin => "No redirect",
1433: newuser => "Link to create a user account",
1434: img => "Header",
1435: logo => "Main Logo",
1436: domlogo => "Domain Logo",
1437: login => "Log-in Header",
1438: textcol => "Text color",
1439: bgcol => "Box color",
1440: bgs => "Background colors",
1441: links => "Link colors",
1442: font => "Font color",
1443: pgbg => "Header",
1444: mainbg => "Page",
1445: sidebg => "Login box",
1446: link => "Link",
1447: alink => "Active link",
1448: vlink => "Visited link",
1.256 raeburn 1449: headtag => "Custom markup",
1450: action => "Action",
1451: current => "Current",
1.6 raeburn 1452: );
1453: return %choices;
1454: }
1455:
1456: sub print_rolecolors {
1.30 raeburn 1457: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1458: my %choices = &color_font_choices();
1459: my @bgs = ('pgbg','tabbg','sidebg');
1460: my @links = ('link','alink','vlink');
1461: my @images = ('img');
1462: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1463: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1464: my %defaultdesign = %Apache::loncommon::defaultdesign;
1465: my (%is_custom,%designs);
1.200 raeburn 1466: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1467: if (ref($settings) eq 'HASH') {
1468: if (ref($settings->{$role}) eq 'HASH') {
1469: if ($settings->{$role}->{'img'} ne '') {
1470: $designs{'img'} = $settings->{$role}->{'img'};
1471: $is_custom{'img'} = 1;
1472: }
1473: if ($settings->{$role}->{'font'} ne '') {
1474: $designs{'font'} = $settings->{$role}->{'font'};
1475: $is_custom{'font'} = 1;
1476: }
1.97 tempelho 1477: if ($settings->{$role}->{'fontmenu'} ne '') {
1478: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1479: $is_custom{'fontmenu'} = 1;
1480: }
1.6 raeburn 1481: foreach my $item (@bgs) {
1482: if ($settings->{$role}->{$item} ne '') {
1483: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1484: $is_custom{$item} = 1;
1485: }
1486: }
1487: foreach my $item (@links) {
1488: if ($settings->{$role}->{$item} ne '') {
1489: $designs{'links'}{$item} = $settings->{$role}->{$item};
1490: $is_custom{$item} = 1;
1491: }
1492: }
1493: }
1494: } else {
1495: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1496: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1497: $is_custom{'img'} = 1;
1498: }
1.97 tempelho 1499: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1500: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1501: $is_custom{'fontmenu'} = 1;
1502: }
1.6 raeburn 1503: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1504: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1505: $is_custom{'font'} = 1;
1506: }
1507: foreach my $item (@bgs) {
1508: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1509: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1510: $is_custom{$item} = 1;
1511:
1512: }
1513: }
1514: foreach my $item (@links) {
1515: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1516: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1517: $is_custom{$item} = 1;
1518: }
1519: }
1520: }
1521: my $itemcount = 1;
1.30 raeburn 1522: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1523: $datatable .= '</tr></table></td></tr>';
1524: return $datatable;
1525: }
1526:
1.200 raeburn 1527: sub role_defaults {
1528: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1529: my %defaults;
1530: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1531: return %defaults;
1532: }
1533: my %defaultdesign = %Apache::loncommon::defaultdesign;
1534: if ($role eq 'login') {
1535: %defaults = (
1536: font => $defaultdesign{$role.'.font'},
1537: );
1538: if (ref($logintext) eq 'ARRAY') {
1539: foreach my $item (@{$logintext}) {
1540: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1541: }
1542: }
1543: foreach my $item (@{$images}) {
1544: $defaults{'showlogo'}{$item} = 1;
1545: }
1546: } else {
1547: %defaults = (
1548: img => $defaultdesign{$role.'.img'},
1549: font => $defaultdesign{$role.'.font'},
1550: fontmenu => $defaultdesign{$role.'.fontmenu'},
1551: );
1552: }
1553: foreach my $item (@{$bgs}) {
1554: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1555: }
1556: foreach my $item (@{$links}) {
1557: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1558: }
1559: foreach my $item (@{$images}) {
1560: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1561: }
1562: return %defaults;
1563: }
1564:
1.6 raeburn 1565: sub display_color_options {
1.9 raeburn 1566: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1567: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1568: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1569: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1570: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1571: '<td>'.$choices->{'font'}.'</td>';
1572: if (!$is_custom->{'font'}) {
1.30 raeburn 1573: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1574: } else {
1575: $datatable .= '<td> </td>';
1576: }
1.174 foxr 1577: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1578:
1.8 raeburn 1579: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1580: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1581: ' value="'.$current_color.'" /> '.
1.174 foxr 1582: ' </td></tr>';
1.107 raeburn 1583: unless ($role eq 'login') {
1584: $datatable .= '<tr'.$css_class.'>'.
1585: '<td>'.$choices->{'fontmenu'}.'</td>';
1586: if (!$is_custom->{'fontmenu'}) {
1587: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1588: } else {
1589: $datatable .= '<td> </td>';
1590: }
1.202 raeburn 1591: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1592: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1593: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1594: '<input class="colorchooser" type="text" size="10" name="'
1595: .$role.'_fontmenu"'.
1596: ' value="'.$current_color.'" /> '.
1597: ' </td></tr>';
1.97 tempelho 1598: }
1.9 raeburn 1599: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1600: foreach my $img (@{$images}) {
1.18 albertel 1601: $itemcount ++;
1.6 raeburn 1602: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1603: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1604: '<td>'.$choices->{$img};
1.41 raeburn 1605: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1606: if ($role eq 'login') {
1607: if ($img eq 'login') {
1608: $login_hdr_pick =
1.135 bisitz 1609: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1610: $logincolors =
1611: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1612: $designs,$defaults);
1.70 raeburn 1613: } elsif ($img ne 'domlogo') {
1614: $datatable.= &logo_display_options($img,$defaults,$designs);
1615: }
1616: }
1617: $datatable .= '</td>';
1.6 raeburn 1618: if ($designs->{$img} ne '') {
1619: $imgfile = $designs->{$img};
1.18 albertel 1620: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1621: } else {
1622: $imgfile = $defaults->{$img};
1623: }
1624: if ($imgfile) {
1.9 raeburn 1625: my ($showfile,$fullsize);
1626: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1627: my $urldir = $1;
1628: my $filename = $2;
1629: my @info = &Apache::lonnet::stat_file($designs->{$img});
1630: if (@info) {
1631: my $thumbfile = 'tn-'.$filename;
1632: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1633: if (@thumb) {
1634: $showfile = $urldir.'/'.$thumbfile;
1635: } else {
1636: $showfile = $imgfile;
1637: }
1638: } else {
1639: $showfile = '';
1640: }
1641: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1642: $showfile = $imgfile;
1.6 raeburn 1643: my $imgdir = $1;
1644: my $filename = $2;
1.159 raeburn 1645: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1646: $showfile = "/$imgdir/tn-".$filename;
1647: } else {
1.159 raeburn 1648: my $input = $londocroot.$imgfile;
1649: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1650: if (!-e $output) {
1.9 raeburn 1651: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1652: my ($fullwidth,$fullheight) = &check_dimensions($input);
1653: if ($fullwidth ne '' && $fullheight ne '') {
1654: if ($fullwidth > $width && $fullheight > $height) {
1655: my $size = $width.'x'.$height;
1656: system("convert -sample $size $input $output");
1.159 raeburn 1657: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1658: }
1659: }
1.6 raeburn 1660: }
1661: }
1.16 raeburn 1662: }
1.6 raeburn 1663: if ($showfile) {
1.40 raeburn 1664: if ($showfile =~ m{^/(adm|res)/}) {
1665: if ($showfile =~ m{^/res/}) {
1666: my $local_showfile =
1667: &Apache::lonnet::filelocation('',$showfile);
1668: &Apache::lonnet::repcopy($local_showfile);
1669: }
1670: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1671: }
1672: if ($imgfile) {
1673: if ($imgfile =~ m{^/(adm|res)/}) {
1674: if ($imgfile =~ m{^/res/}) {
1675: my $local_imgfile =
1676: &Apache::lonnet::filelocation('',$imgfile);
1677: &Apache::lonnet::repcopy($local_imgfile);
1678: }
1679: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1680: } else {
1681: $fullsize = $imgfile;
1682: }
1683: }
1.41 raeburn 1684: $datatable .= '<td>';
1685: if ($img eq 'login') {
1.135 bisitz 1686: $datatable .= $login_hdr_pick;
1687: }
1.41 raeburn 1688: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1689: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1690: } else {
1.201 raeburn 1691: $datatable .= '<td> </td><td class="LC_left_item">'.
1692: &mt('Upload:').'<br />';
1.6 raeburn 1693: }
1694: } else {
1.201 raeburn 1695: $datatable .= '<td> </td><td class="LC_left_item">'.
1696: &mt('Upload:').'<br />';
1.6 raeburn 1697: }
1.9 raeburn 1698: if ($switchserver) {
1699: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1700: } else {
1.135 bisitz 1701: if ($img ne 'login') { # suppress file selection for Log-in header
1702: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1703: }
1.9 raeburn 1704: }
1705: $datatable .= '</td></tr>';
1.6 raeburn 1706: }
1707: $itemcount ++;
1708: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1709: $datatable .= '<tr'.$css_class.'>'.
1710: '<td>'.$choices->{'bgs'}.'</td>';
1711: my $bgs_def;
1712: foreach my $item (@{$bgs}) {
1713: if (!$is_custom->{$item}) {
1.70 raeburn 1714: $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 1715: }
1716: }
1717: if ($bgs_def) {
1.8 raeburn 1718: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1719: } else {
1720: $datatable .= '<td> </td>';
1721: }
1722: $datatable .= '<td class="LC_right_item">'.
1723: '<table border="0"><tr>';
1.174 foxr 1724:
1.6 raeburn 1725: foreach my $item (@{$bgs}) {
1.201 raeburn 1726: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1727: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1728: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1729: $datatable .= ' ';
1.6 raeburn 1730: }
1.174 foxr 1731: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1732: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1733: }
1734: $datatable .= '</tr></table></td></tr>';
1735: $itemcount ++;
1736: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1737: $datatable .= '<tr'.$css_class.'>'.
1738: '<td>'.$choices->{'links'}.'</td>';
1739: my $links_def;
1740: foreach my $item (@{$links}) {
1741: if (!$is_custom->{$item}) {
1.30 raeburn 1742: $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 1743: }
1744: }
1745: if ($links_def) {
1.8 raeburn 1746: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1747: } else {
1748: $datatable .= '<td> </td>';
1749: }
1750: $datatable .= '<td class="LC_right_item">'.
1751: '<table border="0"><tr>';
1752: foreach my $item (@{$links}) {
1.234 raeburn 1753: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1754: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1755: if ($designs->{'links'}{$item}) {
1.174 foxr 1756: $datatable.=' ';
1.6 raeburn 1757: }
1.174 foxr 1758: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1759: '" /></td>';
1760: }
1.30 raeburn 1761: $$rowtotal += $itemcount;
1.3 raeburn 1762: return $datatable;
1763: }
1764:
1.70 raeburn 1765: sub logo_display_options {
1766: my ($img,$defaults,$designs) = @_;
1767: my $checkedon;
1768: if (ref($defaults) eq 'HASH') {
1769: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1770: if ($defaults->{'showlogo'}{$img}) {
1771: $checkedon = 'checked="checked" ';
1772: }
1773: }
1774: }
1775: if (ref($designs) eq 'HASH') {
1776: if (ref($designs->{'showlogo'}) eq 'HASH') {
1777: if (defined($designs->{'showlogo'}{$img})) {
1778: if ($designs->{'showlogo'}{$img} == 0) {
1779: $checkedon = '';
1780: } elsif ($designs->{'showlogo'}{$img} == 1) {
1781: $checkedon = 'checked="checked" ';
1782: }
1783: }
1784: }
1785: }
1786: return '<br /><label> <input type="checkbox" name="'.
1787: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1788: &mt('show').'</label>'."\n";
1789: }
1790:
1.41 raeburn 1791: sub login_header_options {
1.135 bisitz 1792: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1793: my $output = '';
1.41 raeburn 1794: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1795: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1796: if (!$is_custom->{'textcol'}) {
1797: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1798: ' ';
1799: }
1800: if (!$is_custom->{'bgcol'}) {
1801: $output .= $choices->{'bgcol'}.': '.
1802: '<span id="css_'.$role.'_font" style="background-color: '.
1803: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1804: }
1805: $output .= '<br />';
1806: }
1807: $output .='<br />';
1808: return $output;
1809: }
1810:
1811: sub login_text_colors {
1.201 raeburn 1812: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1813: my $color_menu = '<table border="0"><tr>';
1814: foreach my $item (@{$logintext}) {
1.201 raeburn 1815: $color_menu .= '<td align="center">'.$choices->{$item};
1816: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1817: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1818: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1819: }
1820: $color_menu .= '</tr></table><br />';
1821: return $color_menu;
1822: }
1823:
1824: sub image_changes {
1825: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1826: my $output;
1.135 bisitz 1827: if ($img eq 'login') {
1828: # suppress image for Log-in header
1829: } elsif (!$is_custom) {
1.70 raeburn 1830: if ($img ne 'domlogo') {
1.41 raeburn 1831: $output .= &mt('Default image:').'<br />';
1832: } else {
1833: $output .= &mt('Default in use:').'<br />';
1834: }
1835: }
1.135 bisitz 1836: if ($img eq 'login') { # suppress image for Log-in header
1837: $output .= '<td>'.$logincolors;
1.41 raeburn 1838: } else {
1.135 bisitz 1839: if ($img_import) {
1840: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1841: }
1842: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1843: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1844: if ($is_custom) {
1845: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1846: '<input type="checkbox" name="'.
1847: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1848: '</label> '.&mt('Replace:').'</span><br />';
1849: } else {
1.201 raeburn 1850: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1851: }
1.41 raeburn 1852: }
1853: return $output;
1854: }
1855:
1.3 raeburn 1856: sub print_quotas {
1.86 raeburn 1857: my ($dom,$settings,$rowtotal,$action) = @_;
1858: my $context;
1859: if ($action eq 'quotas') {
1860: $context = 'tools';
1861: } else {
1862: $context = $action;
1863: }
1.197 raeburn 1864: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1865: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1866: my $typecount = 0;
1.101 raeburn 1867: my ($css_class,%titles);
1.86 raeburn 1868: if ($context eq 'requestcourses') {
1.271 raeburn 1869: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1870: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1871: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1872: %titles = &courserequest_titles();
1.163 raeburn 1873: } elsif ($context eq 'requestauthor') {
1874: @usertools = ('author');
1875: @options = ('norequest','approval','automatic');
1.210 raeburn 1876: %titles = &authorrequest_titles();
1.86 raeburn 1877: } else {
1.162 raeburn 1878: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1879: %titles = &tool_titles();
1.86 raeburn 1880: }
1.26 raeburn 1881: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1882: foreach my $type (@{$types}) {
1.197 raeburn 1883: my ($currdefquota,$currauthorquota);
1.163 raeburn 1884: unless (($context eq 'requestcourses') ||
1885: ($context eq 'requestauthor')) {
1.86 raeburn 1886: if (ref($settings) eq 'HASH') {
1887: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1888: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1889: } else {
1890: $currdefquota = $settings->{$type};
1891: }
1.197 raeburn 1892: if (ref($settings->{authorquota}) eq 'HASH') {
1893: $currauthorquota = $settings->{authorquota}->{$type};
1894: }
1.78 raeburn 1895: }
1.72 raeburn 1896: }
1.3 raeburn 1897: if (defined($usertypes->{$type})) {
1898: $typecount ++;
1899: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1900: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1901: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1902: '<td class="LC_left_item">';
1.101 raeburn 1903: if ($context eq 'requestcourses') {
1904: $datatable .= '<table><tr>';
1905: }
1906: my %cell;
1.72 raeburn 1907: foreach my $item (@usertools) {
1.101 raeburn 1908: if ($context eq 'requestcourses') {
1909: my ($curroption,$currlimit);
1910: if (ref($settings) eq 'HASH') {
1911: if (ref($settings->{$item}) eq 'HASH') {
1912: $curroption = $settings->{$item}->{$type};
1913: if ($curroption =~ /^autolimit=(\d*)$/) {
1914: $currlimit = $1;
1915: }
1916: }
1917: }
1918: if (!$curroption) {
1919: $curroption = 'norequest';
1920: }
1921: $datatable .= '<th>'.$titles{$item}.'</th>';
1922: foreach my $option (@options) {
1923: my $val = $option;
1924: if ($option eq 'norequest') {
1925: $val = 0;
1926: }
1927: if ($option eq 'validate') {
1928: my $canvalidate = 0;
1929: if (ref($validations{$item}) eq 'HASH') {
1930: if ($validations{$item}{$type}) {
1931: $canvalidate = 1;
1932: }
1933: }
1934: next if (!$canvalidate);
1935: }
1936: my $checked = '';
1937: if ($option eq $curroption) {
1938: $checked = ' checked="checked"';
1939: } elsif ($option eq 'autolimit') {
1940: if ($curroption =~ /^autolimit/) {
1941: $checked = ' checked="checked"';
1942: }
1943: }
1944: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1945: '<input type="radio" name="crsreq_'.$item.
1946: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1947: $titles{$option}.'</label>';
1.101 raeburn 1948: if ($option eq 'autolimit') {
1.127 raeburn 1949: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1950: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1951: 'value="'.$currlimit.'" />';
1.101 raeburn 1952: }
1.127 raeburn 1953: $cell{$item} .= '</span> ';
1.103 raeburn 1954: if ($option eq 'autolimit') {
1.127 raeburn 1955: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1956: }
1.101 raeburn 1957: }
1.163 raeburn 1958: } elsif ($context eq 'requestauthor') {
1959: my $curroption;
1960: if (ref($settings) eq 'HASH') {
1961: $curroption = $settings->{$type};
1962: }
1963: if (!$curroption) {
1964: $curroption = 'norequest';
1965: }
1966: foreach my $option (@options) {
1967: my $val = $option;
1968: if ($option eq 'norequest') {
1969: $val = 0;
1970: }
1971: my $checked = '';
1972: if ($option eq $curroption) {
1973: $checked = ' checked="checked"';
1974: }
1975: $datatable .= '<span class="LC_nobreak"><label>'.
1976: '<input type="radio" name="authorreq_'.$type.
1977: '" value="'.$val.'"'.$checked.' />'.
1978: $titles{$option}.'</label></span> ';
1979: }
1.101 raeburn 1980: } else {
1981: my $checked = 'checked="checked" ';
1982: if (ref($settings) eq 'HASH') {
1983: if (ref($settings->{$item}) eq 'HASH') {
1984: if ($settings->{$item}->{$type} == 0) {
1985: $checked = '';
1986: } elsif ($settings->{$item}->{$type} == 1) {
1987: $checked = 'checked="checked" ';
1988: }
1.78 raeburn 1989: }
1.72 raeburn 1990: }
1.101 raeburn 1991: $datatable .= '<span class="LC_nobreak"><label>'.
1992: '<input type="checkbox" name="'.$context.'_'.$item.
1993: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1994: '</label></span> ';
1.72 raeburn 1995: }
1.101 raeburn 1996: }
1997: if ($context eq 'requestcourses') {
1998: $datatable .= '</tr><tr>';
1999: foreach my $item (@usertools) {
1.106 raeburn 2000: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2001: }
2002: $datatable .= '</tr></table>';
1.72 raeburn 2003: }
1.86 raeburn 2004: $datatable .= '</td>';
1.163 raeburn 2005: unless (($context eq 'requestcourses') ||
2006: ($context eq 'requestauthor')) {
1.86 raeburn 2007: $datatable .=
1.197 raeburn 2008: '<td class="LC_right_item">'.
2009: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2010: '<input type="text" name="quota_'.$type.
1.72 raeburn 2011: '" value="'.$currdefquota.
1.197 raeburn 2012: '" size="5" /></span>'.(' ' x 2).
2013: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2014: '<input type="text" name="authorquota_'.$type.
2015: '" value="'.$currauthorquota.
2016: '" size="5" /></span></td>';
1.86 raeburn 2017: }
2018: $datatable .= '</tr>';
1.3 raeburn 2019: }
2020: }
2021: }
1.163 raeburn 2022: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2023: $defaultquota = '20';
1.197 raeburn 2024: $authorquota = '500';
1.86 raeburn 2025: if (ref($settings) eq 'HASH') {
2026: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2027: $defaultquota = $settings->{'defaultquota'}->{'default'};
2028: } elsif (defined($settings->{'default'})) {
2029: $defaultquota = $settings->{'default'};
2030: }
1.197 raeburn 2031: if (ref($settings->{'authorquota'}) eq 'HASH') {
2032: $authorquota = $settings->{'authorquota'}->{'default'};
2033: }
1.3 raeburn 2034: }
2035: }
2036: $typecount ++;
2037: $css_class = $typecount%2?' class="LC_odd_row"':'';
2038: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2039: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2040: '<td class="LC_left_item">';
1.101 raeburn 2041: if ($context eq 'requestcourses') {
2042: $datatable .= '<table><tr>';
2043: }
2044: my %defcell;
1.72 raeburn 2045: foreach my $item (@usertools) {
1.101 raeburn 2046: if ($context eq 'requestcourses') {
2047: my ($curroption,$currlimit);
2048: if (ref($settings) eq 'HASH') {
2049: if (ref($settings->{$item}) eq 'HASH') {
2050: $curroption = $settings->{$item}->{'default'};
2051: if ($curroption =~ /^autolimit=(\d*)$/) {
2052: $currlimit = $1;
2053: }
2054: }
2055: }
2056: if (!$curroption) {
2057: $curroption = 'norequest';
2058: }
2059: $datatable .= '<th>'.$titles{$item}.'</th>';
2060: foreach my $option (@options) {
2061: my $val = $option;
2062: if ($option eq 'norequest') {
2063: $val = 0;
2064: }
2065: if ($option eq 'validate') {
2066: my $canvalidate = 0;
2067: if (ref($validations{$item}) eq 'HASH') {
2068: if ($validations{$item}{'default'}) {
2069: $canvalidate = 1;
2070: }
2071: }
2072: next if (!$canvalidate);
2073: }
2074: my $checked = '';
2075: if ($option eq $curroption) {
2076: $checked = ' checked="checked"';
2077: } elsif ($option eq 'autolimit') {
2078: if ($curroption =~ /^autolimit/) {
2079: $checked = ' checked="checked"';
2080: }
2081: }
2082: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2083: '<input type="radio" name="crsreq_'.$item.
2084: '_default" value="'.$val.'"'.$checked.' />'.
2085: $titles{$option}.'</label>';
2086: if ($option eq 'autolimit') {
1.127 raeburn 2087: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2088: $item.'_limit_default" size="1" '.
2089: 'value="'.$currlimit.'" />';
2090: }
1.127 raeburn 2091: $defcell{$item} .= '</span> ';
1.104 raeburn 2092: if ($option eq 'autolimit') {
1.127 raeburn 2093: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2094: }
1.101 raeburn 2095: }
1.163 raeburn 2096: } elsif ($context eq 'requestauthor') {
2097: my $curroption;
2098: if (ref($settings) eq 'HASH') {
1.172 raeburn 2099: $curroption = $settings->{'default'};
1.163 raeburn 2100: }
2101: if (!$curroption) {
2102: $curroption = 'norequest';
2103: }
2104: foreach my $option (@options) {
2105: my $val = $option;
2106: if ($option eq 'norequest') {
2107: $val = 0;
2108: }
2109: my $checked = '';
2110: if ($option eq $curroption) {
2111: $checked = ' checked="checked"';
2112: }
2113: $datatable .= '<span class="LC_nobreak"><label>'.
2114: '<input type="radio" name="authorreq_default"'.
2115: ' value="'.$val.'"'.$checked.' />'.
2116: $titles{$option}.'</label></span> ';
2117: }
1.101 raeburn 2118: } else {
2119: my $checked = 'checked="checked" ';
2120: if (ref($settings) eq 'HASH') {
2121: if (ref($settings->{$item}) eq 'HASH') {
2122: if ($settings->{$item}->{'default'} == 0) {
2123: $checked = '';
2124: } elsif ($settings->{$item}->{'default'} == 1) {
2125: $checked = 'checked="checked" ';
2126: }
1.78 raeburn 2127: }
1.72 raeburn 2128: }
1.101 raeburn 2129: $datatable .= '<span class="LC_nobreak"><label>'.
2130: '<input type="checkbox" name="'.$context.'_'.$item.
2131: '" value="default" '.$checked.'/>'.$titles{$item}.
2132: '</label></span> ';
2133: }
2134: }
2135: if ($context eq 'requestcourses') {
2136: $datatable .= '</tr><tr>';
2137: foreach my $item (@usertools) {
1.106 raeburn 2138: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2139: }
1.101 raeburn 2140: $datatable .= '</tr></table>';
1.72 raeburn 2141: }
1.86 raeburn 2142: $datatable .= '</td>';
1.163 raeburn 2143: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2144: $datatable .= '<td class="LC_right_item">'.
2145: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2146: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2147: $defaultquota.'" size="5" /></span>'.(' ' x2).
2148: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2149: '<input type="text" name="authorquota" value="'.
2150: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2151: }
2152: $datatable .= '</tr>';
1.72 raeburn 2153: $typecount ++;
2154: $css_class = $typecount%2?' class="LC_odd_row"':'';
2155: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2156: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2157: if ($context eq 'requestcourses') {
1.109 raeburn 2158: $datatable .= &mt('(overrides affiliation, if set)').
2159: '</td>'.
2160: '<td class="LC_left_item">'.
2161: '<table><tr>';
1.101 raeburn 2162: } else {
1.109 raeburn 2163: $datatable .= &mt('(overrides affiliation, if checked)').
2164: '</td>'.
2165: '<td class="LC_left_item" colspan="2">'.
2166: '<br />';
1.101 raeburn 2167: }
2168: my %advcell;
1.72 raeburn 2169: foreach my $item (@usertools) {
1.101 raeburn 2170: if ($context eq 'requestcourses') {
2171: my ($curroption,$currlimit);
2172: if (ref($settings) eq 'HASH') {
2173: if (ref($settings->{$item}) eq 'HASH') {
2174: $curroption = $settings->{$item}->{'_LC_adv'};
2175: if ($curroption =~ /^autolimit=(\d*)$/) {
2176: $currlimit = $1;
2177: }
2178: }
2179: }
2180: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2181: my $checked = '';
2182: if ($curroption eq '') {
2183: $checked = ' checked="checked"';
2184: }
2185: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2186: '<input type="radio" name="crsreq_'.$item.
2187: '__LC_adv" value=""'.$checked.' />'.
2188: &mt('No override set').'</label></span> ';
1.101 raeburn 2189: foreach my $option (@options) {
2190: my $val = $option;
2191: if ($option eq 'norequest') {
2192: $val = 0;
2193: }
2194: if ($option eq 'validate') {
2195: my $canvalidate = 0;
2196: if (ref($validations{$item}) eq 'HASH') {
2197: if ($validations{$item}{'_LC_adv'}) {
2198: $canvalidate = 1;
2199: }
2200: }
2201: next if (!$canvalidate);
2202: }
2203: my $checked = '';
1.104 raeburn 2204: if ($val eq $curroption) {
1.101 raeburn 2205: $checked = ' checked="checked"';
2206: } elsif ($option eq 'autolimit') {
2207: if ($curroption =~ /^autolimit/) {
2208: $checked = ' checked="checked"';
2209: }
2210: }
2211: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2212: '<input type="radio" name="crsreq_'.$item.
2213: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2214: $titles{$option}.'</label>';
2215: if ($option eq 'autolimit') {
1.127 raeburn 2216: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2217: $item.'_limit__LC_adv" size="1" '.
2218: 'value="'.$currlimit.'" />';
2219: }
1.127 raeburn 2220: $advcell{$item} .= '</span> ';
1.104 raeburn 2221: if ($option eq 'autolimit') {
1.127 raeburn 2222: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2223: }
1.101 raeburn 2224: }
1.163 raeburn 2225: } elsif ($context eq 'requestauthor') {
2226: my $curroption;
2227: if (ref($settings) eq 'HASH') {
2228: $curroption = $settings->{'_LC_adv'};
2229: }
2230: my $checked = '';
2231: if ($curroption eq '') {
2232: $checked = ' checked="checked"';
2233: }
2234: $datatable .= '<span class="LC_nobreak"><label>'.
2235: '<input type="radio" name="authorreq__LC_adv"'.
2236: ' value=""'.$checked.' />'.
2237: &mt('No override set').'</label></span> ';
2238: foreach my $option (@options) {
2239: my $val = $option;
2240: if ($option eq 'norequest') {
2241: $val = 0;
2242: }
2243: my $checked = '';
2244: if ($val eq $curroption) {
2245: $checked = ' checked="checked"';
2246: }
2247: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2248: '<input type="radio" name="authorreq__LC_adv"'.
2249: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2250: $titles{$option}.'</label></span> ';
2251: }
1.101 raeburn 2252: } else {
2253: my $checked = 'checked="checked" ';
2254: if (ref($settings) eq 'HASH') {
2255: if (ref($settings->{$item}) eq 'HASH') {
2256: if ($settings->{$item}->{'_LC_adv'} == 0) {
2257: $checked = '';
2258: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2259: $checked = 'checked="checked" ';
2260: }
1.79 raeburn 2261: }
1.72 raeburn 2262: }
1.101 raeburn 2263: $datatable .= '<span class="LC_nobreak"><label>'.
2264: '<input type="checkbox" name="'.$context.'_'.$item.
2265: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2266: '</label></span> ';
2267: }
2268: }
2269: if ($context eq 'requestcourses') {
2270: $datatable .= '</tr><tr>';
2271: foreach my $item (@usertools) {
1.106 raeburn 2272: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2273: }
1.101 raeburn 2274: $datatable .= '</tr></table>';
1.72 raeburn 2275: }
1.98 raeburn 2276: $datatable .= '</td></tr>';
1.30 raeburn 2277: $$rowtotal += $typecount;
1.3 raeburn 2278: return $datatable;
2279: }
2280:
1.163 raeburn 2281: sub print_requestmail {
2282: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2283: my ($now,$datatable,%currapp);
1.102 raeburn 2284: $now = time;
2285: if (ref($settings) eq 'HASH') {
2286: if (ref($settings->{'notify'}) eq 'HASH') {
2287: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2288: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2289: }
2290: }
2291: }
1.191 raeburn 2292: my $numinrow = 2;
1.224 raeburn 2293: my $css_class;
2294: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2295: my $text;
2296: if ($action eq 'requestcourses') {
2297: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2298: } elsif ($action eq 'requestauthor') {
2299: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2300: } else {
1.224 raeburn 2301: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2302: }
1.224 raeburn 2303: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2304: ' <td>'.$text.'</td>'.
1.102 raeburn 2305: ' <td class="LC_left_item">';
1.191 raeburn 2306: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2307: $action.'notifyapproval',%currapp);
1.191 raeburn 2308: if ($numdc > 0) {
2309: $datatable .= $table;
1.102 raeburn 2310: } else {
2311: $datatable .= &mt('There are no active Domain Coordinators');
2312: }
2313: $datatable .='</td></tr>';
2314: return $datatable;
2315: }
2316:
1.216 raeburn 2317: sub print_studentcode {
2318: my ($settings,$rowtotal) = @_;
2319: my $rownum = 0;
1.218 raeburn 2320: my ($output,%current);
1.271 raeburn 2321: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2322: if (ref($settings) eq 'HASH') {
2323: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2324: foreach my $type (@crstypes) {
2325: $current{$type} = $settings->{'uniquecode'}{$type};
2326: }
1.218 raeburn 2327: }
2328: }
2329: $output .= '<tr>'.
2330: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2331: '<td class="LC_left_item">';
2332: foreach my $type (@crstypes) {
2333: my $check = ' ';
2334: if ($current{$type}) {
2335: $check = ' checked="checked" ';
2336: }
2337: $output .= '<span class="LC_nobreak"><label>'.
2338: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2339: &mt($type).'</label></span>'.(' 'x2).' ';
2340: }
2341: $output .= '</td></tr>';
2342: $$rowtotal ++;
2343: return $output;
1.216 raeburn 2344: }
2345:
2346: sub print_textbookcourses {
1.242 raeburn 2347: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2348: my $rownum = 0;
2349: my $css_class;
2350: my $itemcount = 1;
2351: my $maxnum = 0;
2352: my $bookshash;
2353: if (ref($settings) eq 'HASH') {
1.242 raeburn 2354: $bookshash = $settings->{$type};
1.216 raeburn 2355: }
2356: my %ordered;
2357: if (ref($bookshash) eq 'HASH') {
2358: foreach my $item (keys(%{$bookshash})) {
2359: if (ref($bookshash->{$item}) eq 'HASH') {
2360: my $num = $bookshash->{$item}{'order'};
2361: $ordered{$num} = $item;
2362: }
2363: }
2364: }
2365: my $confname = $dom.'-domainconfig';
2366: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2367: my $maxnum = scalar(keys(%ordered));
2368: my $datatable;
1.216 raeburn 2369: if (keys(%ordered)) {
2370: my @items = sort { $a <=> $b } keys(%ordered);
2371: for (my $i=0; $i<@items; $i++) {
2372: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2373: my $key = $ordered{$items[$i]};
2374: my %coursehash=&Apache::lonnet::coursedescription($key);
2375: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2376: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2377: if (ref($bookshash->{$key}) eq 'HASH') {
2378: $subject = $bookshash->{$key}->{'subject'};
2379: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2380: if ($type eq 'textbooks') {
1.243 raeburn 2381: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2382: $author = $bookshash->{$key}->{'author'};
2383: $image = $bookshash->{$key}->{'image'};
2384: if ($image ne '') {
2385: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2386: my $imagethumb = "$path/tn-".$imagefile;
2387: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2388: }
1.216 raeburn 2389: }
2390: }
1.242 raeburn 2391: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2392: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2393: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2394: for (my $k=0; $k<=$maxnum; $k++) {
2395: my $vpos = $k+1;
2396: my $selstr;
2397: if ($k == $i) {
2398: $selstr = ' selected="selected" ';
2399: }
2400: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2401: }
2402: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2403: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2404: &mt('Delete?').'</label></span></td>'.
2405: '<td colspan="2">'.
1.242 raeburn 2406: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2407: (' 'x2).
1.242 raeburn 2408: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2409: if ($type eq 'textbooks') {
2410: $datatable .= (' 'x2).
1.243 raeburn 2411: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2412: (' 'x2).
1.242 raeburn 2413: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2414: (' 'x2).
2415: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2416: if ($image) {
1.267 raeburn 2417: $datatable .= $imgsrc.
1.242 raeburn 2418: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2419: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2420: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2421: }
2422: if ($switchserver) {
2423: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2424: } else {
2425: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2426: }
1.216 raeburn 2427: }
1.242 raeburn 2428: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2429: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2430: $coursetitle.'</span></td></tr>'."\n";
2431: $itemcount ++;
2432: }
2433: }
2434: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2435: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2436: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2437: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2438: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2439: for (my $k=0; $k<$maxnum+1; $k++) {
2440: my $vpos = $k+1;
2441: my $selstr;
2442: if ($k == $maxnum) {
2443: $selstr = ' selected="selected" ';
2444: }
2445: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2446: }
2447: $datatable .= '</select> '."\n".
1.242 raeburn 2448: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2449: '<td colspan="2">'.
1.242 raeburn 2450: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2451: (' 'x2).
1.242 raeburn 2452: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2453: (' 'x2);
2454: if ($type eq 'textbooks') {
1.243 raeburn 2455: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2456: (' 'x2).
2457: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2458: (' 'x2).
2459: '<span class="LC_nobreak">'.&mt('Image:').' ';
2460: if ($switchserver) {
2461: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2462: } else {
2463: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2464: }
1.216 raeburn 2465: }
2466: $datatable .= '</span>'."\n".
2467: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2468: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2469: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2470: &Apache::loncommon::selectcourse_link
1.242 raeburn 2471: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2472: '</span></td>'."\n".
2473: '</tr>'."\n";
2474: $itemcount ++;
2475: return $datatable;
2476: }
2477:
1.217 raeburn 2478: sub textbookcourses_javascript {
1.242 raeburn 2479: my ($settings) = @_;
2480: return unless(ref($settings) eq 'HASH');
2481: my (%ordered,%total,%jstext);
2482: foreach my $type ('textbooks','templates') {
2483: $total{$type} = 0;
2484: if (ref($settings->{$type}) eq 'HASH') {
2485: foreach my $item (keys(%{$settings->{$type}})) {
2486: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2487: my $num = $settings->{$type}->{$item}{'order'};
2488: $ordered{$type}{$num} = $item;
2489: }
2490: }
2491: $total{$type} = scalar(keys(%{$settings->{$type}}));
2492: }
2493: my @jsarray = ();
2494: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2495: push(@jsarray,$ordered{$type}{$item});
2496: }
2497: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2498: }
2499: return <<"ENDSCRIPT";
2500: <script type="text/javascript">
2501: // <![CDATA[
1.242 raeburn 2502: function reorderBooks(form,item,caller) {
1.217 raeburn 2503: var changedVal;
1.242 raeburn 2504: $jstext{'textbooks'};
2505: $jstext{'templates'};
2506: var newpos;
2507: var maxh;
2508: if (caller == 'textbooks') {
2509: newpos = 'textbooks_addbook_pos';
2510: maxh = 1 + $total{'textbooks'};
2511: } else {
2512: newpos = 'templates_addbook_pos';
2513: maxh = 1 + $total{'templates'};
2514: }
1.217 raeburn 2515: var current = new Array;
2516: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2517: if (item == newpos) {
2518: changedVal = newitemVal;
2519: } else {
2520: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2521: current[newitemVal] = newpos;
2522: }
1.242 raeburn 2523: if (caller == 'textbooks') {
2524: for (var i=0; i<textbooks.length; i++) {
2525: var elementName = 'textbooks_'+textbooks[i];
2526: if (elementName != item) {
2527: if (form.elements[elementName]) {
2528: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2529: current[currVal] = elementName;
2530: }
2531: }
2532: }
2533: }
2534: if (caller == 'templates') {
2535: for (var i=0; i<templates.length; i++) {
2536: var elementName = 'templates_'+templates[i];
2537: if (elementName != item) {
2538: if (form.elements[elementName]) {
2539: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2540: current[currVal] = elementName;
2541: }
1.217 raeburn 2542: }
2543: }
2544: }
2545: var oldVal;
2546: for (var j=0; j<maxh; j++) {
2547: if (current[j] == undefined) {
2548: oldVal = j;
2549: }
2550: }
2551: if (oldVal < changedVal) {
2552: for (var k=oldVal+1; k<=changedVal ; k++) {
2553: var elementName = current[k];
2554: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2555: }
2556: } else {
2557: for (var k=changedVal; k<oldVal; k++) {
2558: var elementName = current[k];
2559: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2560: }
2561: }
2562: return;
2563: }
2564:
2565: // ]]>
2566: </script>
2567:
2568: ENDSCRIPT
2569: }
2570:
1.267 raeburn 2571: sub ltitools_javascript {
2572: my ($settings) = @_;
2573: return unless(ref($settings) eq 'HASH');
2574: my (%ordered,$total,%jstext);
2575: $total = 0;
2576: foreach my $item (keys(%{$settings})) {
2577: if (ref($settings->{$item}) eq 'HASH') {
2578: my $num = $settings->{$item}{'order'};
2579: $ordered{$num} = $item;
2580: }
2581: }
2582: $total = scalar(keys(%{$settings}));
2583: my @jsarray = ();
2584: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2585: push(@jsarray,$ordered{$item});
2586: }
2587: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2588: return <<"ENDSCRIPT";
2589: <script type="text/javascript">
2590: // <![CDATA[
2591: function reorderLTI(form,item) {
2592: var changedVal;
2593: $jstext
2594: var newpos = 'ltitools_add_pos';
2595: var maxh = 1 + $total;
2596: var current = new Array;
2597: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2598: if (item == newpos) {
2599: changedVal = newitemVal;
2600: } else {
2601: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2602: current[newitemVal] = newpos;
2603: }
2604: for (var i=0; i<ltitools.length; i++) {
2605: var elementName = 'ltitools_'+ltitools[i];
2606: if (elementName != item) {
2607: if (form.elements[elementName]) {
2608: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2609: current[currVal] = elementName;
2610: }
2611: }
2612: }
2613: var oldVal;
2614: for (var j=0; j<maxh; j++) {
2615: if (current[j] == undefined) {
2616: oldVal = j;
2617: }
2618: }
2619: if (oldVal < changedVal) {
2620: for (var k=oldVal+1; k<=changedVal ; k++) {
2621: var elementName = current[k];
2622: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2623: }
2624: } else {
2625: for (var k=changedVal; k<oldVal; k++) {
2626: var elementName = current[k];
2627: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2628: }
2629: }
2630: return;
2631: }
2632:
2633: // ]]>
2634: </script>
2635:
2636: ENDSCRIPT
2637: }
2638:
1.3 raeburn 2639: sub print_autoenroll {
1.30 raeburn 2640: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2641: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2642: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2643: if (ref($settings) eq 'HASH') {
2644: if (exists($settings->{'run'})) {
2645: if ($settings->{'run'} eq '0') {
2646: $runoff = ' checked="checked" ';
2647: $runon = ' ';
2648: } else {
2649: $runon = ' checked="checked" ';
2650: $runoff = ' ';
2651: }
2652: } else {
2653: if ($autorun) {
2654: $runon = ' checked="checked" ';
2655: $runoff = ' ';
2656: } else {
2657: $runoff = ' checked="checked" ';
2658: $runon = ' ';
2659: }
2660: }
1.129 raeburn 2661: if (exists($settings->{'co-owners'})) {
2662: if ($settings->{'co-owners'} eq '0') {
2663: $coownersoff = ' checked="checked" ';
2664: $coownerson = ' ';
2665: } else {
2666: $coownerson = ' checked="checked" ';
2667: $coownersoff = ' ';
2668: }
2669: } else {
2670: $coownersoff = ' checked="checked" ';
2671: $coownerson = ' ';
2672: }
1.3 raeburn 2673: if (exists($settings->{'sender_domain'})) {
2674: $defdom = $settings->{'sender_domain'};
2675: }
1.274 raeburn 2676: if (exists($settings->{'autofailsafe'})) {
2677: $failsafe = $settings->{'autofailsafe'};
2678: }
1.14 raeburn 2679: } else {
2680: if ($autorun) {
2681: $runon = ' checked="checked" ';
2682: $runoff = ' ';
2683: } else {
2684: $runoff = ' checked="checked" ';
2685: $runon = ' ';
2686: }
1.3 raeburn 2687: }
2688: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2689: my $notif_sender;
2690: if (ref($settings) eq 'HASH') {
2691: $notif_sender = $settings->{'sender_uname'};
2692: }
1.3 raeburn 2693: my $datatable='<tr class="LC_odd_row">'.
2694: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2695: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2696: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2697: $runon.' value="1" />'.&mt('Yes').'</label> '.
2698: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2699: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2700: '</tr><tr>'.
2701: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2702: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2703: &mt('username').': '.
2704: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2705: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2706: ': '.$domform.'</span></td></tr>'.
2707: '<tr class="LC_odd_row">'.
2708: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2709: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2710: '<input type="radio" name="autoassign_coowners"'.
2711: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2712: '<label><input type="radio" name="autoassign_coowners"'.
2713: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2714: '</tr><tr>'.
2715: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2716: '<td class="LC_right_item"><span class="LC_nobreak">'.
2717: '<input type="text" name="autoenroll_failsafe"'.
2718: ' value="'.$failsafe.'" size="4" /></td></tr>';
2719: $$rowtotal += 4;
1.3 raeburn 2720: return $datatable;
2721: }
2722:
2723: sub print_autoupdate {
1.30 raeburn 2724: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2725: my $datatable;
2726: if ($position eq 'top') {
2727: my $updateon = ' ';
2728: my $updateoff = ' checked="checked" ';
2729: my $classlistson = ' ';
2730: my $classlistsoff = ' checked="checked" ';
2731: if (ref($settings) eq 'HASH') {
2732: if ($settings->{'run'} eq '1') {
2733: $updateon = $updateoff;
2734: $updateoff = ' ';
2735: }
2736: if ($settings->{'classlists'} eq '1') {
2737: $classlistson = $classlistsoff;
2738: $classlistsoff = ' ';
2739: }
2740: }
2741: my %title = (
2742: run => 'Auto-update active?',
2743: classlists => 'Update information in classlists?',
2744: );
2745: $datatable = '<tr class="LC_odd_row">'.
2746: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2747: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2748: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2749: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2750: '<label><input type="radio" name="autoupdate_run"'.
2751: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2752: '</tr><tr>'.
2753: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2754: '<td class="LC_right_item"><span class="LC_nobreak">'.
2755: '<label><input type="radio" name="classlists"'.
2756: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2757: '<label><input type="radio" name="classlists"'.
2758: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2759: '</tr>';
1.30 raeburn 2760: $$rowtotal += 2;
1.131 raeburn 2761: } elsif ($position eq 'middle') {
2762: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2763: my $numinrow = 3;
2764: my $locknamesettings;
2765: $datatable .= &insttypes_row($settings,$types,$usertypes,
2766: $dom,$numinrow,$othertitle,
2767: 'lockablenames');
2768: $$rowtotal ++;
1.3 raeburn 2769: } else {
1.44 raeburn 2770: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2771: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2772: 'permanentemail','id');
1.33 raeburn 2773: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2774: my $numrows = 0;
1.26 raeburn 2775: if (ref($types) eq 'ARRAY') {
2776: if (@{$types} > 0) {
2777: $datatable =
2778: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2779: \@fields,$types,\$numrows);
1.30 raeburn 2780: $$rowtotal += @{$types};
1.26 raeburn 2781: }
1.3 raeburn 2782: }
2783: $datatable .=
2784: &usertype_update_row($settings,{'default' => $othertitle},
2785: \%fieldtitles,\@fields,['default'],
2786: \$numrows);
1.30 raeburn 2787: $$rowtotal ++;
1.3 raeburn 2788: }
2789: return $datatable;
2790: }
2791:
1.125 raeburn 2792: sub print_autocreate {
2793: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2794: my (%createon,%createoff,%currhash);
1.125 raeburn 2795: my @types = ('xml','req');
2796: if (ref($settings) eq 'HASH') {
2797: foreach my $item (@types) {
2798: $createoff{$item} = ' checked="checked" ';
2799: $createon{$item} = ' ';
2800: if (exists($settings->{$item})) {
2801: if ($settings->{$item}) {
2802: $createon{$item} = ' checked="checked" ';
2803: $createoff{$item} = ' ';
2804: }
2805: }
2806: }
1.210 raeburn 2807: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2808: $currhash{$settings->{'xmldc'}} = 1;
2809: }
1.125 raeburn 2810: } else {
2811: foreach my $item (@types) {
2812: $createoff{$item} = ' checked="checked" ';
2813: $createon{$item} = ' ';
2814: }
2815: }
2816: $$rowtotal += 2;
1.191 raeburn 2817: my $numinrow = 2;
1.125 raeburn 2818: my $datatable='<tr class="LC_odd_row">'.
2819: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2820: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2821: '<input type="radio" name="autocreate_xml"'.
2822: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2823: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2824: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2825: '</td></tr><tr>'.
2826: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2827: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2828: '<input type="radio" name="autocreate_req"'.
2829: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2830: '<label><input type="radio" name="autocreate_req"'.
2831: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2832: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2833: 'autocreate_xmldc',%currhash);
1.247 raeburn 2834: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2835: if ($numdc > 1) {
1.247 raeburn 2836: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2837: '</td><td class="LC_left_item">';
1.125 raeburn 2838: } else {
1.247 raeburn 2839: $datatable .= &mt('Course creation processed as:').
2840: '</td><td class="LC_right_item">';
1.125 raeburn 2841: }
1.247 raeburn 2842: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2843: $$rowtotal += $rows;
1.125 raeburn 2844: return $datatable;
2845: }
2846:
1.23 raeburn 2847: sub print_directorysrch {
1.277 raeburn 2848: my ($position,$dom,$settings,$rowtotal) = @_;
2849: my $datatable;
2850: if ($position eq 'top') {
2851: my $instsrchon = ' ';
2852: my $instsrchoff = ' checked="checked" ';
2853: my ($exacton,$containson,$beginson);
2854: my $instlocalon = ' ';
2855: my $instlocaloff = ' checked="checked" ';
2856: if (ref($settings) eq 'HASH') {
2857: if ($settings->{'available'} eq '1') {
2858: $instsrchon = $instsrchoff;
2859: $instsrchoff = ' ';
2860: }
2861: if ($settings->{'localonly'} eq '1') {
2862: $instlocalon = $instlocaloff;
2863: $instlocaloff = ' ';
2864: }
2865: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2866: foreach my $type (@{$settings->{'searchtypes'}}) {
2867: if ($type eq 'exact') {
2868: $exacton = ' checked="checked" ';
2869: } elsif ($type eq 'contains') {
2870: $containson = ' checked="checked" ';
2871: } elsif ($type eq 'begins') {
2872: $beginson = ' checked="checked" ';
2873: }
2874: }
2875: } else {
2876: if ($settings->{'searchtypes'} eq 'exact') {
2877: $exacton = ' checked="checked" ';
2878: } elsif ($settings->{'searchtypes'} eq 'contains') {
2879: $containson = ' checked="checked" ';
2880: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2881: $exacton = ' checked="checked" ';
2882: $containson = ' checked="checked" ';
2883: }
2884: }
1.277 raeburn 2885: }
2886: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2887: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2888:
2889: my $numinrow = 4;
2890: my $cansrchrow = 0;
2891: $datatable='<tr class="LC_odd_row">'.
2892: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2893: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2894: '<input type="radio" name="dirsrch_available"'.
2895: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2896: '<label><input type="radio" name="dirsrch_available"'.
2897: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2898: '</tr><tr>'.
2899: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2900: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2901: '<input type="radio" name="dirsrch_instlocalonly"'.
2902: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2903: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2904: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2905: '</tr>';
2906: $$rowtotal += 2;
2907: if (ref($usertypes) eq 'HASH') {
2908: if (keys(%{$usertypes}) > 0) {
2909: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2910: $numinrow,$othertitle,'cansearch');
2911: $cansrchrow = 1;
1.25 raeburn 2912: }
1.23 raeburn 2913: }
1.277 raeburn 2914: if ($cansrchrow) {
2915: $$rowtotal ++;
2916: $datatable .= '<tr>';
2917: } else {
2918: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 2919: }
1.277 raeburn 2920: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2921: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2922: foreach my $title (@{$titleorder}) {
2923: if (defined($searchtitles->{$title})) {
2924: my $check = ' ';
2925: if (ref($settings) eq 'HASH') {
2926: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2927: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2928: $check = ' checked="checked" ';
2929: }
1.39 raeburn 2930: }
1.25 raeburn 2931: }
1.277 raeburn 2932: $datatable .= '<td class="LC_left_item">'.
2933: '<span class="LC_nobreak"><label>'.
2934: '<input type="checkbox" name="searchby" '.
2935: 'value="'.$title.'"'.$check.'/>'.
2936: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2937: }
2938: }
1.277 raeburn 2939: $datatable .= '</tr></table></td></tr>';
2940: $$rowtotal ++;
2941: if ($cansrchrow) {
2942: $datatable .= '<tr class="LC_odd_row">';
2943: } else {
2944: $datatable .= '<tr>';
2945: }
2946: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2947: '<td class="LC_left_item" colspan="2">'.
2948: '<span class="LC_nobreak"><label>'.
2949: '<input type="checkbox" name="searchtypes" '.
2950: $exacton.' value="exact" />'.&mt('Exact match').
2951: '</label> '.
2952: '<label><input type="checkbox" name="searchtypes" '.
2953: $beginson.' value="begins" />'.&mt('Begins with').
2954: '</label> '.
2955: '<label><input type="checkbox" name="searchtypes" '.
2956: $containson.' value="contains" />'.&mt('Contains').
2957: '</label></span></td></tr>';
2958: $$rowtotal ++;
1.26 raeburn 2959: } else {
1.277 raeburn 2960: my $domsrchon = ' checked="checked" ';
2961: my $domsrchoff = ' ';
2962: my $domlocalon = ' ';
2963: my $domlocaloff = ' checked="checked" ';
2964: if (ref($settings) eq 'HASH') {
2965: if ($settings->{'lclocalonly'} eq '1') {
2966: $domlocalon = $domlocaloff;
2967: $domlocaloff = ' ';
2968: }
2969: if ($settings->{'lcavailable'} eq '0') {
2970: $domsrchoff = $domsrchon;
2971: $domsrchon = ' ';
2972: }
2973: }
2974: $datatable='<tr class="LC_odd_row">'.
2975: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2976: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2977: '<input type="radio" name="dirsrch_domavailable"'.
2978: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2979: '<label><input type="radio" name="dirsrch_domavailable"'.
2980: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2981: '</tr><tr>'.
2982: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2983: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2984: '<input type="radio" name="dirsrch_domlocalonly"'.
2985: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2986: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2987: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2988: '</tr>';
2989: $$rowtotal += 2;
1.26 raeburn 2990: }
1.25 raeburn 2991: return $datatable;
2992: }
2993:
1.28 raeburn 2994: sub print_contacts {
1.286 raeburn 2995: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2996: my $datatable;
2997: my @contacts = ('adminemail','supportemail');
1.286 raeburn 2998: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2999: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
3000: if ($position eq 'top') {
3001: if (ref($settings) eq 'HASH') {
3002: foreach my $item (@contacts) {
3003: if (exists($settings->{$item})) {
3004: $to{$item} = $settings->{$item};
3005: }
3006: }
3007: }
3008: } elsif ($position eq 'middle') {
3009: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
3010: 'updatesmail','idconflictsmail');
1.288 raeburn 3011: foreach my $type (@mailings) {
3012: $otheremails{$type} = '';
3013: }
1.286 raeburn 3014: } else {
3015: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3016: foreach my $type (@mailings) {
3017: $otheremails{$type} = '';
3018: }
1.286 raeburn 3019: $bccemails{'helpdeskmail'} = '';
3020: $bccemails{'otherdomsmail'} = '';
3021: $includestr{'helpdeskmail'} = '';
3022: $includestr{'otherdomsmail'} = '';
3023: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3024: }
1.28 raeburn 3025: if (ref($settings) eq 'HASH') {
1.286 raeburn 3026: unless ($position eq 'top') {
3027: foreach my $type (@mailings) {
3028: if (exists($settings->{$type})) {
3029: if (ref($settings->{$type}) eq 'HASH') {
3030: foreach my $item (@contacts) {
3031: if ($settings->{$type}{$item}) {
3032: $checked{$type}{$item} = ' checked="checked" ';
3033: }
3034: }
3035: $otheremails{$type} = $settings->{$type}{'others'};
3036: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3037: $bccemails{$type} = $settings->{$type}{'bcc'};
3038: if ($settings->{$type}{'include'} ne '') {
3039: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3040: $includestr{$type} = &unescape($includestr{$type});
3041: }
3042: }
3043: }
3044: } elsif ($type eq 'lonstatusmail') {
3045: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3046: }
1.28 raeburn 3047: }
3048: }
1.286 raeburn 3049: if ($position eq 'bottom') {
3050: foreach my $type (@mailings) {
3051: $bccemails{$type} = $settings->{$type}{'bcc'};
3052: if ($settings->{$type}{'include'} ne '') {
3053: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3054: $includestr{$type} = &unescape($includestr{$type});
3055: }
3056: }
3057: if (ref($settings->{'helpform'}) eq 'HASH') {
3058: if (ref($fields) eq 'ARRAY') {
3059: foreach my $field (@{$fields}) {
3060: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3061: }
1.286 raeburn 3062: }
3063: if (exists($settings->{'helpform'}{'maxsize'})) {
3064: $maxsize = $settings->{'helpform'}{'maxsize'};
3065: } else {
1.289 raeburn 3066: $maxsize = '1.0';
1.286 raeburn 3067: }
3068: } else {
3069: if (ref($fields) eq 'ARRAY') {
3070: foreach my $field (@{$fields}) {
3071: $currfield{$field} = 'yes';
1.134 raeburn 3072: }
1.28 raeburn 3073: }
1.286 raeburn 3074: $maxsize = '1.0';
1.28 raeburn 3075: }
3076: }
3077: } else {
1.286 raeburn 3078: if ($position eq 'top') {
3079: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3080: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3081: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3082: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3083: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3084: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3085: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3086: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3087: } elsif ($position eq 'bottom') {
3088: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3089: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3090: if (ref($fields) eq 'ARRAY') {
3091: foreach my $field (@{$fields}) {
3092: $currfield{$field} = 'yes';
3093: }
3094: }
3095: $maxsize = '1.0';
3096: }
1.28 raeburn 3097: }
3098: my ($titles,$short_titles) = &contact_titles();
3099: my $rownum = 0;
3100: my $css_class;
1.286 raeburn 3101: if ($position eq 'top') {
3102: foreach my $item (@contacts) {
3103: $css_class = $rownum%2?' class="LC_odd_row"':'';
3104: $datatable .= '<tr'.$css_class.'>'.
3105: '<td><span class="LC_nobreak">'.$titles->{$item}.
3106: '</span></td><td class="LC_right_item">'.
3107: '<input type="text" name="'.$item.'" value="'.
3108: $to{$item}.'" /></td></tr>';
3109: $rownum ++;
3110: }
3111: } else {
3112: foreach my $type (@mailings) {
3113: $css_class = $rownum%2?' class="LC_odd_row"':'';
3114: $datatable .= '<tr'.$css_class.'>'.
3115: '<td><span class="LC_nobreak">'.
3116: $titles->{$type}.': </span></td>'.
3117: '<td class="LC_left_item">';
3118: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3119: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3120: }
3121: $datatable .= '<span class="LC_nobreak">';
3122: foreach my $item (@contacts) {
3123: $datatable .= '<label>'.
3124: '<input type="checkbox" name="'.$type.'"'.
3125: $checked{$type}{$item}.
3126: ' value="'.$item.'" />'.$short_titles->{$item}.
3127: '</label> ';
3128: }
3129: $datatable .= '</span><br />'.&mt('Others').': '.
3130: '<input type="text" name="'.$type.'_others" '.
3131: 'value="'.$otheremails{$type}.'" />';
3132: my %locchecked;
3133: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3134: foreach my $loc ('s','b') {
3135: if ($includeloc{$type} eq $loc) {
3136: $locchecked{$loc} = ' checked="checked"';
3137: last;
3138: }
3139: }
3140: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3141: '<input type="text" name="'.$type.'_bcc" '.
3142: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3143: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3144: &mt('Text automatically added to e-mail:').' '.
3145: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3146: '<span class="LC_nobreak">'.&mt('Location:').' '.
3147: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3148: (' 'x2).
3149: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3150: '</span></fieldset>';
3151: }
3152: $datatable .= '</td></tr>'."\n";
3153: $rownum ++;
3154: }
1.28 raeburn 3155: }
1.286 raeburn 3156: if ($position eq 'middle') {
3157: my %choices;
3158: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289 raeburn 3159: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3160: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 3161: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3162: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3163: &mt('LON-CAPA core group - MSU'),600,500));
3164: my @toggles = ('reporterrors','reportupdates');
3165: my %defaultchecked = ('reporterrors' => 'on',
3166: 'reportupdates' => 'on');
3167: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3168: \%choices,$rownum);
3169: $datatable .= $reports;
3170: } elsif ($position eq 'bottom') {
1.69 raeburn 3171: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 3172: $datatable .= '<tr'.$css_class.'>'.
1.286 raeburn 3173: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3174: &mt('(e-mail, subject, and description always shown)').
3175: '</td><td class="LC_left_item">';
1.289 raeburn 3176: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
1.286 raeburn 3177: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3178: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3179: foreach my $field (@{$fields}) {
3180: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3181: if (($field eq 'screenshot') || ($field eq 'cc')) {
3182: $datatable .= ' '.&mt('(logged-in users)');
3183: }
3184: $datatable .='</td><td>';
3185: my $clickaction;
3186: if ($field eq 'screenshot') {
3187: $clickaction = ' onclick="screenshotSize(this);"';
3188: }
3189: if (ref($possoptions->{$field}) eq 'ARRAY') {
3190: foreach my $option (@{$possoptions->{$field}}) {
3191: my $checked;
3192: if ($currfield{$field} eq $option) {
3193: $checked = ' checked="checked"';
3194: }
3195: $datatable .= '<span class="LC_nobreak"><label>'.
3196: '<input type="radio" name="helpform_'.$field.'" '.
3197: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3198: '</label></span>'.(' 'x2);
3199: }
3200: }
3201: if ($field eq 'screenshot') {
3202: my $display;
3203: if ($currfield{$field} eq 'no') {
3204: $display = ' style="display:none"';
3205: }
3206: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3207: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3208: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3209: }
3210: $datatable .= '</td></tr>';
3211: }
3212: $datatable .= '</table>';
1.134 raeburn 3213: }
3214: $datatable .= '</td></tr>'."\n";
1.203 raeburn 3215: $rownum ++;
1.28 raeburn 3216: }
1.30 raeburn 3217: $$rowtotal += $rownum;
1.28 raeburn 3218: return $datatable;
3219: }
3220:
1.286 raeburn 3221: sub contacts_javascript {
3222: return <<"ENDSCRIPT";
3223:
3224: <script type="text/javascript">
3225: // <![CDATA[
3226:
3227: function screenshotSize(field) {
3228: if (document.getElementById('help_screenshotsize')) {
3229: if (field.value == 'no') {
1.289 raeburn 3230: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3231: } else {
3232: document.getElementById('help_screenshotsize').style.display="";
3233: }
3234: }
3235: return;
3236: }
3237:
3238: // ]]>
3239: </script>
3240:
3241: ENDSCRIPT
3242: }
3243:
1.118 jms 3244: sub print_helpsettings {
1.282 raeburn 3245: my ($position,$dom,$settings,$rowtotal) = @_;
3246: my $confname = $dom.'-domainconfig';
1.285 raeburn 3247: my $formname = 'display';
1.168 raeburn 3248: my ($datatable,$itemcount);
1.282 raeburn 3249: if ($position eq 'top') {
3250: $itemcount = 1;
3251: my (%choices,%defaultchecked,@toggles);
3252: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3253: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3254: &mt('LON-CAPA bug tracker'),600,500));
3255: %defaultchecked = ('submitbugs' => 'on');
3256: @toggles = ('submitbugs');
3257: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3258: \%choices,$itemcount);
3259: $$rowtotal ++;
3260: } else {
3261: my $css_class;
3262: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3263: my (%customroles,%ordered,%current);
3264: if (ref($settings->{'adhoc'}) eq 'HASH') {
3265: %current = %{$settings->{'adhoc'}};
3266: }
3267: my $count = 0;
3268: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3269: if ($key=~/^rolesdef\_(\w+)$/) {
3270: my $rolename = $1;
1.285 raeburn 3271: my (%privs,$order);
1.282 raeburn 3272: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3273: $customroles{$rolename} = \%privs;
1.285 raeburn 3274: if (ref($current{$rolename}) eq 'HASH') {
3275: $order = $current{$rolename}{'order'};
3276: }
3277: if ($order eq '') {
3278: $order = $count;
3279: }
3280: $ordered{$order} = $rolename;
3281: $count++;
3282: }
3283: }
3284: my $maxnum = scalar(keys(%ordered));
3285: my @roles_by_num = ();
3286: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3287: push(@roles_by_num,$item);
3288: }
3289: my $context = 'domprefs';
3290: my $crstype = 'Course';
3291: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3292: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3293: my ($numstatustypes,@jsarray);
3294: if (ref($types) eq 'ARRAY') {
3295: if (@{$types} > 0) {
3296: $numstatustypes = scalar(@{$types});
3297: push(@accesstypes,'status');
3298: @jsarray = ('bystatus');
1.282 raeburn 3299: }
3300: }
1.290 raeburn 3301: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3302: if (keys(%domhelpdesk)) {
3303: push(@accesstypes,('inc','exc'));
3304: push(@jsarray,('notinc','notexc'));
3305: }
3306: my $hiddenstr = join("','",@jsarray);
3307: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3308: my $context = 'domprefs';
3309: my $crstype = 'Course';
1.285 raeburn 3310: my $prefix = 'helproles_';
3311: my $add_class = 'LC_hidden';
3312: foreach my $num (@roles_by_num) {
3313: my $role = $ordered{$num};
3314: my ($desc,$access,@statuses);
3315: if (ref($current{$role}) eq 'HASH') {
3316: $desc = $current{$role}{'desc'};
3317: $access = $current{$role}{'access'};
3318: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3319: @statuses = @{$current{$role}{'insttypes'}};
3320: }
3321: }
3322: if ($desc eq '') {
3323: $desc = $role;
3324: }
3325: my $identifier = 'custhelp'.$num;
1.282 raeburn 3326: my %full=();
3327: my %levels= (
3328: course => {},
3329: domain => {},
3330: system => {},
3331: );
3332: my %levelscurrent=(
3333: course => {},
3334: domain => {},
3335: system => {},
3336: );
3337: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3338: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3339: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3340: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3341: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3342: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3343: for (my $k=0; $k<=$maxnum; $k++) {
3344: my $vpos = $k+1;
3345: my $selstr;
3346: if ($k == $num) {
3347: $selstr = ' selected="selected" ';
3348: }
3349: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3350: }
3351: $datatable .= '</select>'.(' 'x2).
3352: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3353: '</td>'.
3354: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3355: &mt('Name shown to users:').
3356: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3357: '</fieldset>'.
3358: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3359: $othertitle,$usertypes,$types,\%domhelpdesk).
3360: '<fieldset>'.
3361: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3362: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3363: \%levelscurrent,$identifier,
3364: 'LC_hidden',$prefix.$num.'_privs').
3365: '</fieldset></td>';
1.282 raeburn 3366: $itemcount ++;
3367: }
3368: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3369: my $newcust = 'custhelp'.$count;
3370: my (%privs,%levelscurrent);
3371: my %full=();
3372: my %levels= (
3373: course => {},
3374: domain => {},
3375: system => {},
3376: );
3377: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3378: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3379: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3380: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3381: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3382: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3383: for (my $k=0; $k<$maxnum+1; $k++) {
3384: my $vpos = $k+1;
3385: my $selstr;
3386: if ($k == $maxnum) {
3387: $selstr = ' selected="selected" ';
3388: }
3389: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3390: }
3391: $datatable .= '</select> '."\n".
1.282 raeburn 3392: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3393: '</label></span></td>'.
1.285 raeburn 3394: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3395: '<span class="LC_nobreak">'.
3396: &mt('Internal name:').
3397: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3398: '</span>'.(' 'x4).
3399: '<span class="LC_nobreak">'.
3400: &mt('Name shown to users:').
3401: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3402: '</span></fieldset>'.
3403: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3404: $usertypes,$types,\%domhelpdesk).
3405: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3406: &Apache::lonuserutils::custom_role_header($context,$crstype,
3407: \@templateroles,$newcust).
3408: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3409: \%levelscurrent,$newcust).
1.285 raeburn 3410: '</fieldset></td></tr>';
1.282 raeburn 3411: $count ++;
3412: $$rowtotal += $count;
3413: }
1.166 raeburn 3414: return $datatable;
1.121 raeburn 3415: }
3416:
1.285 raeburn 3417: sub adhocbutton {
3418: my ($prefix,$num,$field,$visibility) = @_;
3419: my %lt = &Apache::lonlocal::texthash(
3420: show => 'Show details',
3421: hide => 'Hide details',
3422: );
3423: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3424: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3425: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3426: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3427: }
3428:
3429: sub helpsettings_javascript {
3430: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3431: return unless(ref($roles_by_num) eq 'ARRAY');
3432: my %html_js_lt = &Apache::lonlocal::texthash(
3433: show => 'Show details',
3434: hide => 'Hide details',
3435: );
3436: &html_escape(\%html_js_lt);
3437: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3438: return <<"ENDSCRIPT";
3439: <script type="text/javascript">
3440: // <![CDATA[
3441:
3442: function reorderHelpRoles(form,item) {
3443: var changedVal;
3444: $jstext
3445: var newpos = 'helproles_${total}_pos';
3446: var maxh = 1 + $total;
3447: var current = new Array();
3448: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3449: if (item == newpos) {
3450: changedVal = newitemVal;
3451: } else {
3452: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3453: current[newitemVal] = newpos;
3454: }
3455: for (var i=0; i<helproles.length; i++) {
3456: var elementName = 'helproles_'+helproles[i]+'_pos';
3457: if (elementName != item) {
3458: if (form.elements[elementName]) {
3459: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3460: current[currVal] = elementName;
3461: }
3462: }
3463: }
3464: var oldVal;
3465: for (var j=0; j<maxh; j++) {
3466: if (current[j] == undefined) {
3467: oldVal = j;
3468: }
3469: }
3470: if (oldVal < changedVal) {
3471: for (var k=oldVal+1; k<=changedVal ; k++) {
3472: var elementName = current[k];
3473: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3474: }
3475: } else {
3476: for (var k=changedVal; k<oldVal; k++) {
3477: var elementName = current[k];
3478: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3479: }
3480: }
3481: return;
3482: }
3483:
3484: function helpdeskAccess(num) {
3485: var curraccess = null;
3486: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3487: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3488: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3489: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3490: }
3491: }
3492: }
3493: var shown = Array();
3494: var hidden = Array();
3495: if (curraccess == 'none') {
3496: hidden = Array('$hiddenstr');
3497: } else {
3498: if (curraccess == 'status') {
3499: shown = Array('bystatus');
3500: hidden = Array('notinc','notexc');
3501: } else {
3502: if (curraccess == 'exc') {
3503: shown = Array('notexc');
3504: hidden = Array('notinc','bystatus');
3505: }
3506: if (curraccess == 'inc') {
3507: shown = Array('notinc');
3508: hidden = Array('notexc','bystatus');
3509: }
1.293 raeburn 3510: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3511: hidden = Array('notinc','notexc','bystatus');
3512: }
3513: }
3514: }
3515: if (hidden.length > 0) {
3516: for (var i=0; i<hidden.length; i++) {
3517: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3518: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3519: }
3520: }
3521: }
3522: if (shown.length > 0) {
3523: for (var i=0; i<shown.length; i++) {
3524: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3525: if (shown[i] == 'privs') {
3526: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3527: } else {
3528: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3529: }
3530: }
3531: }
3532: }
3533: return;
3534: }
3535:
3536: function toggleHelpdeskItem(num,field) {
3537: if (document.getElementById('helproles_'+num+'_'+field)) {
3538: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 3539: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 3540: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3541: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3542: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3543: }
3544: } else {
3545: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3546: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3547: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3548: }
3549: }
3550: }
3551: return;
3552: }
3553:
3554: // ]]>
3555: </script>
3556:
3557: ENDSCRIPT
3558: }
3559:
3560: sub helpdeskroles_access {
3561: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3562: $usertypes,$types,$domhelpdesk) = @_;
3563: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3564: my %lt = &Apache::lonlocal::texthash(
3565: 'rou' => 'Role usage',
3566: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 3567: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3568: 'dh' => 'All with domain helpdesk role',
3569: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 3570: 'none' => 'None',
3571: 'status' => 'Determined based on institutional status',
3572: 'inc' => 'Include all, but exclude specific personnel',
3573: 'exc' => 'Exclude all, but include specific personnel',
3574: );
3575: my %usecheck = (
3576: all => ' checked="checked"',
3577: );
3578: my %displaydiv = (
3579: status => 'none',
3580: inc => 'none',
3581: exc => 'none',
3582: priv => 'block',
3583: );
3584: my $output;
3585: if (ref($current) eq 'HASH') {
3586: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3587: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3588: $usecheck{$current->{access}} = $usecheck{'all'};
3589: delete($usecheck{'all'});
3590: if ($current->{access} =~ /^(status|inc|exc)$/) {
3591: my $access = $1;
3592: $displaydiv{$access} = 'inline';
3593: } elsif ($current->{access} eq 'none') {
3594: $displaydiv{'priv'} = 'none';
3595: }
3596: }
3597: }
3598: }
3599: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3600: '<p>'.$lt{'whi'}.'</p>';
3601: foreach my $access (@{$accesstypes}) {
3602: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3603: ' onclick="helpdeskAccess('."'$num'".');" />'.
3604: $lt{$access}.'</label>';
3605: if ($access eq 'status') {
3606: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3607: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3608: $othertitle,$usertypes,$types).
3609: '</div>';
3610: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3611: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3612: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3613: '</div>';
3614: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3615: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3616: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3617: '</div>';
3618: }
3619: $output .= '</p>';
3620: }
3621: $output .= '</fieldset>';
3622: return $output;
3623: }
3624:
1.121 raeburn 3625: sub radiobutton_prefs {
1.192 raeburn 3626: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 3627: $additional,$align) = @_;
1.121 raeburn 3628: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3629: (ref($choices) eq 'HASH'));
3630:
1.170 raeburn 3631: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 3632:
3633: foreach my $item (@{$toggles}) {
3634: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3635: $checkedon{$item} = ' checked="checked" ';
3636: $checkedoff{$item} = ' ';
1.121 raeburn 3637: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3638: $checkedoff{$item} = ' checked="checked" ';
3639: $checkedon{$item} = ' ';
3640: }
3641: }
3642: if (ref($settings) eq 'HASH') {
1.121 raeburn 3643: foreach my $item (@{$toggles}) {
1.118 jms 3644: if ($settings->{$item} eq '1') {
3645: $checkedon{$item} = ' checked="checked" ';
3646: $checkedoff{$item} = ' ';
3647: } elsif ($settings->{$item} eq '0') {
3648: $checkedoff{$item} = ' checked="checked" ';
3649: $checkedon{$item} = ' ';
3650: }
3651: }
1.121 raeburn 3652: }
1.192 raeburn 3653: if ($onclick) {
3654: $onclick = ' onclick="'.$onclick.'"';
3655: }
1.121 raeburn 3656: foreach my $item (@{$toggles}) {
1.118 jms 3657: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3658: $datatable .=
1.192 raeburn 3659: '<tr'.$css_class.'><td valign="top">'.
3660: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3661: '</span></td>';
3662: if ($align eq 'left') {
3663: $datatable .= '<td class="LC_left_item">';
3664: } else {
3665: $datatable .= '<td class="LC_right_item">';
3666: }
1.289 raeburn 3667: $datatable .=
1.257 raeburn 3668: '<span class="LC_nobreak">'.
1.118 jms 3669: '<label><input type="radio" name="'.
1.192 raeburn 3670: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3671: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3672: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3673: '</span>'.$additional.
3674: '</td>'.
1.118 jms 3675: '</tr>';
3676: $itemcount ++;
1.121 raeburn 3677: }
3678: return ($datatable,$itemcount);
3679: }
3680:
1.267 raeburn 3681: sub print_ltitools {
3682: my ($dom,$settings,$rowtotal) = @_;
3683: my $rownum = 0;
3684: my $css_class;
3685: my $itemcount = 1;
3686: my $maxnum = 0;
3687: my %ordered;
3688: if (ref($settings) eq 'HASH') {
3689: foreach my $item (keys(%{$settings})) {
3690: if (ref($settings->{$item}) eq 'HASH') {
3691: my $num = $settings->{$item}{'order'};
3692: $ordered{$num} = $item;
3693: }
3694: }
3695: }
3696: my $confname = $dom.'-domainconfig';
3697: my $switchserver = &check_switchserver($dom,$confname);
3698: my $maxnum = scalar(keys(%ordered));
3699: my $datatable = <itools_javascript($settings);
3700: my %lt = <itools_names();
3701: my @courseroles = ('cc','in','ta','ep','st');
3702: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3703: my @fields = ('fullname','firstname','lastname','email','user','roles');
3704: if (keys(%ordered)) {
3705: my @items = sort { $a <=> $b } keys(%ordered);
3706: for (my $i=0; $i<@items; $i++) {
3707: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3708: my $item = $ordered{$items[$i]};
3709: my ($title,$key,$secret,$url,$imgsrc,$version);
3710: if (ref($settings->{$item}) eq 'HASH') {
3711: $title = $settings->{$item}->{'title'};
3712: $url = $settings->{$item}->{'url'};
3713: $key = $settings->{$item}->{'key'};
3714: $secret = $settings->{$item}->{'secret'};
3715: my $image = $settings->{$item}->{'image'};
3716: if ($image ne '') {
3717: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3718: }
3719: }
3720: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3721: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3722: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3723: for (my $k=0; $k<=$maxnum; $k++) {
3724: my $vpos = $k+1;
3725: my $selstr;
3726: if ($k == $i) {
3727: $selstr = ' selected="selected" ';
3728: }
3729: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3730: }
3731: $datatable .= '</select>'.(' 'x2).
3732: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3733: &mt('Delete?').'</label></span></td>'.
3734: '<td colspan="2">'.
3735: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3736: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3737: (' 'x2).
3738: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3739: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3740: (' 'x2).
3741: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3742: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3743: '<br /><br />'.
3744: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3745: ' value="'.$url.'" /></span>'.
3746: (' 'x2).
3747: '<span class="LC_nobreak">'.$lt{'key'}.
3748: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3749: (' 'x2).
3750: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3751: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3752: '<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>'.
3753: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3754: '</fieldset>'.
3755: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3756: '<span class="LC_nobreak">'.&mt('Display target:');
3757: my %currdisp;
3758: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3759: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3760: $currdisp{'window'} = ' checked="checked"';
3761: } else {
3762: $currdisp{'iframe'} = ' checked="checked"';
3763: }
3764: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3765: $currdisp{'width'} = $1;
3766: }
3767: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3768: $currdisp{'height'} = $1;
3769: }
1.296 raeburn 3770: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
3771: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 3772: } else {
3773: $currdisp{'iframe'} = ' checked="checked"';
3774: }
3775: foreach my $disp ('iframe','window') {
3776: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3777: $lt{$disp}.'</label>'.(' 'x2);
3778: }
3779: $datatable .= (' 'x4);
3780: foreach my $dimen ('width','height') {
3781: $datatable .= '<label>'.$lt{$dimen}.' '.
3782: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3783: (' 'x2);
3784: }
1.296 raeburn 3785: $datatable .= '<br />'.
3786: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3787: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
3788: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3789: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
3790: '</textarea></div><div style=""></div><br />';
1.267 raeburn 3791: $datatable .= '<br />';
3792: foreach my $extra ('passback','roster') {
3793: my $checkedon = '';
3794: my $checkedoff = ' checked="checked"';
3795: if ($settings->{$item}->{$extra}) {
3796: $checkedon = $checkedoff;
3797: $checkedoff = '';
3798: }
3799: $datatable .= $lt{$extra}.' '.
3800: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3801: &mt('Yes').'</label>'.(' 'x2).
3802: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3803: &mt('No').'</label>'.(' 'x4);
3804: }
3805: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3806: if ($imgsrc) {
3807: $datatable .= $imgsrc.
3808: '<label><input type="checkbox" name="ltitools_image_del"'.
3809: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3810: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3811: } else {
3812: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3813: }
3814: if ($switchserver) {
3815: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3816: } else {
3817: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3818: }
3819: $datatable .= '</span></fieldset>';
3820: my (%checkedfields,%rolemaps);
3821: if (ref($settings->{$item}) eq 'HASH') {
3822: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3823: %checkedfields = %{$settings->{$item}->{'fields'}};
3824: }
3825: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3826: %rolemaps = %{$settings->{$item}->{'roles'}};
3827: $checkedfields{'roles'} = 1;
3828: }
3829: }
3830: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3831: '<span class="LC_nobreak">';
3832: foreach my $field (@fields) {
3833: my $checked;
3834: if ($checkedfields{$field}) {
3835: $checked = ' checked="checked"';
3836: }
3837: $datatable .= '<label>'.
3838: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3839: $lt{$field}.'</label>'.(' ' x2);
3840: }
3841: $datatable .= '</span></fieldset>'.
3842: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3843: foreach my $role (@courseroles) {
3844: my ($selected,$selectnone);
3845: if (!$rolemaps{$role}) {
3846: $selectnone = ' selected="selected"';
3847: }
3848: $datatable .= '<td align="center">'.
3849: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3850: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3851: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3852: foreach my $ltirole (@ltiroles) {
3853: unless ($selectnone) {
3854: if ($rolemaps{$role} eq $ltirole) {
3855: $selected = ' selected="selected"';
3856: } else {
3857: $selected = '';
3858: }
3859: }
3860: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3861: }
3862: $datatable .= '</select></td>';
3863: }
1.273 raeburn 3864: $datatable .= '</tr></table></fieldset>';
3865: my %courseconfig;
3866: if (ref($settings->{$item}) eq 'HASH') {
3867: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3868: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3869: }
3870: }
3871: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 raeburn 3872: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 3873: my $checked;
3874: if ($courseconfig{$item}) {
3875: $checked = ' checked="checked"';
3876: }
3877: $datatable .= '<label>'.
3878: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3879: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3880: }
3881: $datatable .= '</span></fieldset>'.
1.267 raeburn 3882: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3883: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3884: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3885: my %custom = %{$settings->{$item}->{'custom'}};
3886: if (keys(%custom) > 0) {
3887: foreach my $key (sort(keys(%custom))) {
3888: $datatable .= '<tr><td><span class="LC_nobreak">'.
3889: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3890: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3891: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3892: ' value="'.$custom{$key}.'" /></td></tr>';
3893: }
3894: }
3895: }
3896: $datatable .= '<tr><td><span class="LC_nobreak">'.
3897: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3898: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3899: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3900: $datatable .= '</table></fieldset></td></tr>'."\n";
3901: $itemcount ++;
3902: }
3903: }
3904: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3905: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3906: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3907: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3908: '<select name="ltitools_add_pos"'.$chgstr.'>';
3909: for (my $k=0; $k<$maxnum+1; $k++) {
3910: my $vpos = $k+1;
3911: my $selstr;
3912: if ($k == $maxnum) {
3913: $selstr = ' selected="selected" ';
3914: }
3915: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3916: }
3917: $datatable .= '</select> '."\n".
3918: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3919: '<td colspan="2">'.
3920: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3921: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3922: (' 'x2).
3923: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3924: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3925: (' 'x2).
3926: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3927: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3928: '<br />'.
3929: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3930: (' 'x2).
3931: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3932: (' 'x2).
3933: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3934: '<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".
3935: '</fieldset>'.
3936: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3937: '<span class="LC_nobreak">'.&mt('Display target:');
3938: my %defaultdisp;
3939: $defaultdisp{'iframe'} = ' checked="checked"';
3940: foreach my $disp ('iframe','window') {
3941: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3942: $lt{$disp}.'</label>'.(' 'x2);
3943: }
3944: $datatable .= (' 'x4);
3945: foreach my $dimen ('width','height') {
3946: $datatable .= '<label>'.$lt{$dimen}.' '.
3947: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3948: (' 'x2);
3949: }
1.296 raeburn 3950: $datatable .= '<br />'.
3951: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3952: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
3953: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3954: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
3955: '</div><div style=""></div><br />';
1.267 raeburn 3956: foreach my $extra ('passback','roster') {
3957: $datatable .= $lt{$extra}.' '.
3958: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3959: &mt('Yes').'</label>'.(' 'x2).
3960: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3961: &mt('No').'</label>'.(' 'x4);
3962: }
3963: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3964: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3965: if ($switchserver) {
3966: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3967: } else {
3968: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3969: }
3970: $datatable .= '</span></fieldset>'.
3971: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3972: '<span class="LC_nobreak">';
3973: foreach my $field (@fields) {
3974: $datatable .= '<label>'.
3975: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3976: $lt{$field}.'</label>'.(' ' x2);
3977: }
3978: $datatable .= '</span></fieldset>'.
3979: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3980: foreach my $role (@courseroles) {
3981: my ($checked,$checkednone);
3982: $datatable .= '<td align="center">'.
3983: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3984: '<select name="ltitools_add_roles_'.$role.'">'.
3985: '<option value="" selected="selected">'.&mt('Select').'</option>';
3986: foreach my $ltirole (@ltiroles) {
3987: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3988: }
3989: $datatable .= '</select></td>';
3990: }
3991: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3992: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 raeburn 3993: foreach my $item ('label','title','target','linktext','explanation') {
3994: $datatable .= '<label>'.
3995: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3996: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 3997: }
3998: $datatable .= '</span></fieldset>'.
1.267 raeburn 3999: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4000: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4001: '<tr><td><span class="LC_nobreak">'.
4002: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4003: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4004: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4005: '</table></fieldset></td></tr>'."\n".
4006: '</td>'."\n".
4007: '</tr>'."\n";
4008: $itemcount ++;
4009: return $datatable;
4010: }
4011:
4012: sub ltitools_names {
4013: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4014: 'title' => 'Title',
4015: 'version' => 'Version',
4016: 'msgtype' => 'Message Type',
4017: 'url' => 'URL',
4018: 'key' => 'Key',
4019: 'secret' => 'Secret',
4020: 'icon' => 'Icon',
4021: 'user' => 'Username:domain',
4022: 'fullname' => 'Full Name',
4023: 'firstname' => 'First Name',
4024: 'lastname' => 'Last Name',
4025: 'email' => 'E-mail',
4026: 'roles' => 'Role',
4027: 'window' => 'Window/Tab',
4028: 'iframe' => 'iFrame',
4029: 'height' => 'Height',
4030: 'width' => 'Width',
4031: 'linktext' => 'Default Link Text',
4032: 'explanation' => 'Default Explanation',
4033: 'passback' => 'Tool can return grades:',
4034: 'roster' => 'Tool can retrieve roster:',
4035: 'crstarget' => 'Display target',
4036: 'crslabel' => 'Course label',
4037: 'crstitle' => 'Course title',
4038: 'crslinktext' => 'Link Text',
4039: 'crsexplanation' => 'Explanation',
1.267 raeburn 4040: );
4041: return %lt;
4042: }
4043:
1.121 raeburn 4044: sub print_coursedefaults {
1.139 raeburn 4045: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 4046: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4047: my $itemcount = 1;
1.192 raeburn 4048: my %choices = &Apache::lonlocal::texthash (
4049: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 4050: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 4051: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4052: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 4053: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4054: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4055: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4056: canclone => "People who may clone a course (besides course's owner and coordinators)",
4057: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4058: );
1.198 raeburn 4059: my %staticdefaults = (
4060: anonsurvey_threshold => 10,
4061: uploadquota => 500,
1.257 raeburn 4062: postsubmit => 60,
1.276 raeburn 4063: mysqltables => 172800,
1.198 raeburn 4064: );
1.139 raeburn 4065: if ($position eq 'top') {
1.257 raeburn 4066: %defaultchecked = (
4067: 'canuse_pdfforms' => 'off',
4068: 'uselcmath' => 'on',
4069: 'usejsme' => 'on',
1.289 raeburn 4070: 'canclone' => 'none',
1.257 raeburn 4071: );
4072: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 4073: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4074: \%choices,$itemcount);
1.264 raeburn 4075: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4076: $datatable .=
4077: '<tr'.$css_class.'><td valign="top">'.
4078: '<span class="LC_nobreak">'.$choices{'canclone'}.
4079: '</span></td><td class="LC_left_item">';
4080: my $currcanclone = 'none';
4081: my $onclick;
4082: my @cloneoptions = ('none','domain');
4083: my %clonetitles = (
4084: none => 'No additional course requesters',
4085: domain => "Any course requester in course's domain",
4086: instcode => 'Course requests for official courses ...',
4087: );
4088: my (%codedefaults,@code_order,@posscodes);
4089: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4090: \@code_order) eq 'ok') {
4091: if (@code_order > 0) {
4092: push(@cloneoptions,'instcode');
4093: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4094: }
4095: }
4096: if (ref($settings) eq 'HASH') {
4097: if ($settings->{'canclone'}) {
4098: if (ref($settings->{'canclone'}) eq 'HASH') {
4099: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4100: if (@code_order > 0) {
4101: $currcanclone = 'instcode';
4102: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4103: }
4104: }
4105: } elsif ($settings->{'canclone'} eq 'domain') {
4106: $currcanclone = $settings->{'canclone'};
4107: }
4108: }
1.289 raeburn 4109: }
1.264 raeburn 4110: foreach my $option (@cloneoptions) {
4111: my ($checked,$additional);
4112: if ($currcanclone eq $option) {
4113: $checked = ' checked="checked"';
4114: }
4115: if ($option eq 'instcode') {
4116: if (@code_order) {
4117: my $show = 'none';
4118: if ($checked) {
4119: $show = 'block';
4120: }
4121: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4122: &mt('Institutional codes for new and cloned course have identical:').
4123: '<br />';
4124: foreach my $item (@code_order) {
4125: my $codechk;
4126: if ($checked) {
4127: if (grep(/^\Q$item\E$/,@posscodes)) {
4128: $codechk = ' checked="checked"';
4129: }
4130: }
4131: $additional .= '<label>'.
4132: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4133: $item.'</label>';
4134: }
4135: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4136: }
4137: }
4138: $datatable .=
4139: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4140: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4141: '</label> '.$additional.'</span><br />';
4142: }
4143: $datatable .= '</td>'.
4144: '</tr>';
4145: $itemcount ++;
1.139 raeburn 4146: } else {
4147: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4148: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4149: my $currusecredits = 0;
1.257 raeburn 4150: my $postsubmitclient = 1;
1.271 raeburn 4151: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4152: if (ref($settings) eq 'HASH') {
4153: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4154: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4155: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4156: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4157: }
4158: }
1.192 raeburn 4159: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4160: foreach my $type (@types) {
4161: next if ($type eq 'community');
4162: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4163: if ($defcredits{$type} ne '') {
4164: $currusecredits = 1;
4165: }
4166: }
4167: }
4168: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4169: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4170: $postsubmitclient = 0;
4171: foreach my $type (@types) {
4172: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4173: }
4174: } else {
4175: foreach my $type (@types) {
4176: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4177: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 4178: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 4179: } else {
4180: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4181: }
4182: } else {
4183: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4184: }
4185: }
4186: }
4187: } else {
4188: foreach my $type (@types) {
4189: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 4190: }
4191: }
1.276 raeburn 4192: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4193: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4194: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4195: }
4196: } else {
4197: foreach my $type (@types) {
4198: $currmysql{$type} = $staticdefaults{'mysqltables'};
4199: }
4200: }
1.258 raeburn 4201: } else {
4202: foreach my $type (@types) {
4203: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4204: }
1.139 raeburn 4205: }
4206: if (!$currdefresponder) {
1.198 raeburn 4207: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4208: } elsif ($currdefresponder < 1) {
4209: $currdefresponder = 1;
4210: }
1.198 raeburn 4211: foreach my $type (@types) {
4212: if ($curruploadquota{$type} eq '') {
4213: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4214: }
4215: }
1.139 raeburn 4216: $datatable .=
1.192 raeburn 4217: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4218: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4219: '</span></td>'.
4220: '<td class="LC_right_item"><span class="LC_nobreak">'.
4221: '<input type="text" name="anonsurvey_threshold"'.
4222: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 4223: '</td></tr>'."\n";
4224: $itemcount ++;
4225: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4226: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4227: $choices{'uploadquota'}.
4228: '</span></td>'.
4229: '<td align="right" class="LC_right_item">'.
4230: '<table><tr>';
1.198 raeburn 4231: foreach my $type (@types) {
4232: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4233: '<input type="text" name="uploadquota_'.$type.'"'.
4234: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4235: }
4236: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 4237: $itemcount ++;
1.236 raeburn 4238: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 4239: my $display = 'none';
1.192 raeburn 4240: if ($currusecredits) {
4241: $display = 'block';
4242: }
4243: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 4244: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4245: foreach my $type (@types) {
4246: next if ($type eq 'community');
4247: $additional .= '<td align="center">'.&mt($type).'<br />'.
4248: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 4249: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 4250: }
4251: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 4252: %defaultchecked = ('coursecredits' => 'off');
4253: @toggles = ('coursecredits');
4254: my $current = {
4255: 'coursecredits' => $currusecredits,
4256: };
4257: (my $table,$itemcount) =
4258: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 4259: \%choices,$itemcount,$onclick,$additional,'left');
4260: $datatable .= $table;
4261: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4262: my $display = 'none';
4263: if ($postsubmitclient) {
4264: $display = 'block';
4265: }
4266: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 4267: &mt('Number of seconds submit is disabled').'<br />'.
4268: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4269: '<table><tr>';
1.257 raeburn 4270: foreach my $type (@types) {
4271: $additional .= '<td align="center">'.&mt($type).'<br />'.
4272: '<input type="text" name="'.$type.'_timeout" value="'.
4273: $deftimeout{$type}.'" size="5" /></td>';
4274: }
4275: $additional .= '</tr></table></div>'."\n";
4276: %defaultchecked = ('postsubmit' => 'on');
4277: @toggles = ('postsubmit');
1.280 raeburn 4278: $current = {
4279: 'postsubmit' => $postsubmitclient,
4280: };
1.257 raeburn 4281: ($table,$itemcount) =
4282: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4283: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 4284: $datatable .= $table;
1.276 raeburn 4285: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4286: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4287: $choices{'mysqltables'}.
4288: '</span></td>'.
4289: '<td align="right" class="LC_right_item">'.
4290: '<table><tr>';
4291: foreach my $type (@types) {
4292: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4293: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 4294: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 4295: }
4296: $datatable .= '</tr></table></td></tr>'."\n";
4297: $itemcount ++;
4298:
1.139 raeburn 4299: }
1.192 raeburn 4300: $$rowtotal += $itemcount;
1.121 raeburn 4301: return $datatable;
1.118 jms 4302: }
4303:
1.231 raeburn 4304: sub print_selfenrollment {
4305: my ($position,$dom,$settings,$rowtotal) = @_;
4306: my ($css_class,$datatable);
4307: my $itemcount = 1;
1.271 raeburn 4308: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 4309: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 4310: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4311: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 4312: my @rows;
4313: my $key;
4314: if ($position eq 'top') {
4315: $key = 'admin';
4316: if (ref($rowsref) eq 'ARRAY') {
4317: @rows = @{$rowsref};
4318: }
4319: } elsif ($position eq 'middle') {
4320: $key = 'default';
4321: @rows = ('types','registered','approval','limit');
4322: }
4323: foreach my $row (@rows) {
4324: if (defined($titlesref->{$row})) {
4325: $itemcount ++;
4326: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4327: $datatable .= '<tr'.$css_class.'>'.
4328: '<td>'.$titlesref->{$row}.'</td>'.
4329: '<td class="LC_left_item">'.
4330: '<table><tr>';
4331: my (%current,%currentcap);
4332: if (ref($settings) eq 'HASH') {
4333: if (ref($settings->{$key}) eq 'HASH') {
4334: foreach my $type (@types) {
4335: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4336: $current{$type} = $settings->{$key}->{$type}->{$row};
4337: }
4338: if (($row eq 'limit') && ($key eq 'default')) {
4339: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4340: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4341: }
4342: }
4343: }
4344: }
4345: }
4346: my %roles = (
4347: '0' => &Apache::lonnet::plaintext('dc'),
4348: );
4349:
4350: foreach my $type (@types) {
4351: unless (($row eq 'registered') && ($key eq 'default')) {
4352: $datatable .= '<th>'.&mt($type).'</th>';
4353: }
4354: }
4355: unless (($row eq 'registered') && ($key eq 'default')) {
4356: $datatable .= '</tr><tr>';
4357: }
4358: foreach my $type (@types) {
4359: if ($type eq 'community') {
4360: $roles{'1'} = &mt('Community personnel');
4361: } else {
4362: $roles{'1'} = &mt('Course personnel');
4363: }
4364: $datatable .= '<td style="vertical-align: top">';
4365: if ($position eq 'top') {
4366: my %checked;
4367: if ($current{$type} eq '0') {
4368: $checked{'0'} = ' checked="checked"';
4369: } else {
4370: $checked{'1'} = ' checked="checked"';
4371: }
4372: foreach my $role ('1','0') {
4373: $datatable .= '<span class="LC_nobreak"><label>'.
4374: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4375: 'value="'.$role.'"'.$checked{$role}.' />'.
4376: $roles{$role}.'</label></span> ';
4377: }
4378: } else {
4379: if ($row eq 'types') {
4380: my %checked;
4381: if ($current{$type} =~ /^(all|dom)$/) {
4382: $checked{$1} = ' checked="checked"';
4383: } else {
4384: $checked{''} = ' checked="checked"';
4385: }
4386: foreach my $val ('','dom','all') {
4387: $datatable .= '<span class="LC_nobreak"><label>'.
4388: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4389: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4390: }
4391: } elsif ($row eq 'registered') {
4392: my %checked;
4393: if ($current{$type} eq '1') {
4394: $checked{'1'} = ' checked="checked"';
4395: } else {
4396: $checked{'0'} = ' checked="checked"';
4397: }
4398: foreach my $val ('0','1') {
4399: $datatable .= '<span class="LC_nobreak"><label>'.
4400: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4401: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4402: }
4403: } elsif ($row eq 'approval') {
4404: my %checked;
4405: if ($current{$type} =~ /^([12])$/) {
4406: $checked{$1} = ' checked="checked"';
4407: } else {
4408: $checked{'0'} = ' checked="checked"';
4409: }
4410: for my $val (0..2) {
4411: $datatable .= '<span class="LC_nobreak"><label>'.
4412: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4413: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4414: }
4415: } elsif ($row eq 'limit') {
4416: my %checked;
4417: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4418: $checked{$1} = ' checked="checked"';
4419: } else {
4420: $checked{'none'} = ' checked="checked"';
4421: }
4422: my $cap;
4423: if ($currentcap{$type} =~ /^\d+$/) {
4424: $cap = $currentcap{$type};
4425: }
4426: foreach my $val ('none','allstudents','selfenrolled') {
4427: $datatable .= '<span class="LC_nobreak"><label>'.
4428: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4429: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4430: }
4431: $datatable .= '<br />'.
4432: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4433: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4434: '</span>';
4435: }
4436: }
4437: $datatable .= '</td>';
4438: }
4439: $datatable .= '</tr>';
4440: }
4441: $datatable .= '</table></td></tr>';
4442: }
4443: } elsif ($position eq 'bottom') {
1.235 raeburn 4444: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4445: }
4446: $$rowtotal += $itemcount;
4447: return $datatable;
4448: }
4449:
4450: sub print_validation_rows {
4451: my ($caller,$dom,$settings,$rowtotal) = @_;
4452: my ($itemsref,$namesref,$fieldsref);
4453: if ($caller eq 'selfenroll') {
4454: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4455: } elsif ($caller eq 'requestcourses') {
4456: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4457: }
4458: my %currvalidation;
4459: if (ref($settings) eq 'HASH') {
4460: if (ref($settings->{'validation'}) eq 'HASH') {
4461: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 4462: }
1.235 raeburn 4463: }
4464: my $datatable;
4465: my $itemcount = 0;
4466: foreach my $item (@{$itemsref}) {
4467: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4468: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4469: $namesref->{$item}.
4470: '</span></td>'.
4471: '<td class="LC_left_item">';
4472: if (($item eq 'url') || ($item eq 'button')) {
4473: $datatable .= '<span class="LC_nobreak">'.
4474: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4475: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4476: } elsif ($item eq 'fields') {
4477: my @currfields;
4478: if (ref($currvalidation{$item}) eq 'ARRAY') {
4479: @currfields = @{$currvalidation{$item}};
4480: }
4481: foreach my $field (@{$fieldsref}) {
4482: my $check = '';
4483: if (grep(/^\Q$field\E$/,@currfields)) {
4484: $check = ' checked="checked"';
4485: }
4486: $datatable .= '<span class="LC_nobreak"><label>'.
4487: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4488: ' value="'.$field.'"'.$check.' />'.$field.
4489: '</label></span> ';
4490: }
4491: } elsif ($item eq 'markup') {
4492: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4493: $currvalidation{$item}.
1.231 raeburn 4494: '</textarea>';
1.235 raeburn 4495: }
4496: $datatable .= '</td></tr>'."\n";
4497: if (ref($rowtotal)) {
1.231 raeburn 4498: $itemcount ++;
4499: }
4500: }
1.235 raeburn 4501: if ($caller eq 'requestcourses') {
4502: my %currhash;
1.248 raeburn 4503: if (ref($settings) eq 'HASH') {
4504: if (ref($settings->{'validation'}) eq 'HASH') {
4505: if ($settings->{'validation'}{'dc'} ne '') {
4506: $currhash{$settings->{'validation'}{'dc'}} = 1;
4507: }
1.235 raeburn 4508: }
4509: }
4510: my $numinrow = 2;
4511: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4512: 'validationdc',%currhash);
1.247 raeburn 4513: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4514: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 4515: if ($numdc > 1) {
1.247 raeburn 4516: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 4517: } else {
1.247 raeburn 4518: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 4519: }
1.247 raeburn 4520: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 4521: $itemcount ++;
4522: }
4523: if (ref($rowtotal)) {
4524: $$rowtotal += $itemcount;
4525: }
1.231 raeburn 4526: return $datatable;
4527: }
4528:
1.137 raeburn 4529: sub print_usersessions {
4530: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 4531: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 4532: my (%by_ip,%by_location,@intdoms,@instdoms);
4533: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 4534:
4535: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4536: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4537: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4538: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4539: if ($position eq 'top') {
1.152 raeburn 4540: if (keys(%serverhomes) > 1) {
1.145 raeburn 4541: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 4542: my $curroffloadnow;
4543: if (ref($settings) eq 'HASH') {
4544: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4545: $curroffloadnow = $settings->{'offloadnow'};
4546: }
4547: }
4548: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4549: } else {
1.140 raeburn 4550: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 4551: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
4552: '</td></tr>';
1.140 raeburn 4553: }
1.137 raeburn 4554: } else {
1.279 raeburn 4555: my %titles = &usersession_titles();
4556: my ($prefix,@types);
4557: if ($position eq 'bottom') {
4558: $prefix = 'remote';
4559: @types = ('version','excludedomain','includedomain');
1.145 raeburn 4560: } else {
1.279 raeburn 4561: $prefix = 'hosted';
4562: @types = ('excludedomain','includedomain');
4563: }
4564: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4565: }
4566: $$rowtotal += $itemcount;
4567: return $datatable;
4568: }
4569:
4570: sub rules_by_location {
4571: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
4572: my ($datatable,$itemcount,$css_class);
4573: if (keys(%{$by_location}) == 0) {
4574: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4575: $datatable = '<tr'.$css_class.'><td colspan="2">'.
4576: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
4577: '</td></tr>';
4578: $itemcount = 1;
4579: } else {
4580: $itemcount = 0;
4581: my $numinrow = 5;
4582: my (%current,%checkedon,%checkedoff);
4583: my @locations = sort(keys(%{$by_location}));
4584: foreach my $type (@{$types}) {
4585: $checkedon{$type} = '';
4586: $checkedoff{$type} = ' checked="checked"';
4587: }
4588: if (ref($settings) eq 'HASH') {
4589: if (ref($settings->{$prefix}) eq 'HASH') {
4590: foreach my $key (keys(%{$settings->{$prefix}})) {
4591: $current{$key} = $settings->{$prefix}{$key};
4592: if ($key eq 'version') {
4593: if ($current{$key} ne '') {
1.145 raeburn 4594: $checkedon{$key} = ' checked="checked"';
4595: $checkedoff{$key} = '';
4596: }
1.279 raeburn 4597: } elsif (ref($current{$key}) eq 'ARRAY') {
4598: $checkedon{$key} = ' checked="checked"';
4599: $checkedoff{$key} = '';
1.137 raeburn 4600: }
4601: }
4602: }
1.279 raeburn 4603: }
4604: foreach my $type (@{$types}) {
4605: next if ($type ne 'version' && !@locations);
4606: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4607: $datatable .= '<tr'.$css_class.'>
4608: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4609: <span class="LC_nobreak">
4610: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4611: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4612: if ($type eq 'version') {
4613: my @lcversions = &Apache::lonnet::all_loncaparevs();
4614: my $selector = '<select name="'.$prefix.'_version">';
4615: foreach my $version (@lcversions) {
4616: my $selected = '';
4617: if ($current{'version'} eq $version) {
4618: $selected = ' selected="selected"';
1.145 raeburn 4619: }
1.279 raeburn 4620: $selector .= ' <option value="'.$version.'"'.
4621: $selected.'>'.$version.'</option>';
4622: }
4623: $selector .= '</select> ';
4624: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4625: } else {
4626: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4627: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4628: ' />'.(' 'x2).
4629: '<input type="button" value="'.&mt('uncheck all').'" '.
4630: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4631: "\n".
4632: '</div><div><table>';
4633: my $rem;
4634: for (my $i=0; $i<@locations; $i++) {
4635: my ($showloc,$value,$checkedtype);
4636: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4637: my $ip = $by_location->{$locations[$i]}->[0];
4638: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4639: $value = join(':',@{$by_ip->{$ip}});
4640: $showloc = join(', ',@{$by_ip->{$ip}});
4641: if (ref($current{$type}) eq 'ARRAY') {
4642: foreach my $loc (@{$by_ip->{$ip}}) {
4643: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4644: $checkedtype = ' checked="checked"';
4645: last;
1.145 raeburn 4646: }
1.138 raeburn 4647: }
4648: }
4649: }
1.137 raeburn 4650: }
1.279 raeburn 4651: $rem = $i%($numinrow);
4652: if ($rem == 0) {
4653: if ($i > 0) {
4654: $datatable .= '</tr>';
4655: }
4656: $datatable .= '<tr>';
4657: }
4658: $datatable .= '<td class="LC_left_item">'.
4659: '<span class="LC_nobreak"><label>'.
4660: '<input type="checkbox" name="'.$prefix.'_'.$type.
4661: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4662: '</label></span></td>';
4663: }
4664: $rem = @locations%($numinrow);
4665: my $colsleft = $numinrow - $rem;
4666: if ($colsleft > 1 ) {
4667: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4668: ' </td>';
4669: } elsif ($colsleft == 1) {
4670: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4671: }
1.279 raeburn 4672: $datatable .= '</tr></table>';
1.137 raeburn 4673: }
1.279 raeburn 4674: $datatable .= '</td></tr>';
4675: $itemcount ++;
1.137 raeburn 4676: }
4677: }
1.279 raeburn 4678: return ($datatable,$itemcount);
1.137 raeburn 4679: }
4680:
1.275 raeburn 4681: sub print_ssl {
4682: my ($position,$dom,$settings,$rowtotal) = @_;
4683: my ($css_class,$datatable);
4684: my $itemcount = 1;
4685: if ($position eq 'top') {
1.281 raeburn 4686: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4687: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4688: my $same_institution;
4689: if ($intdom ne '') {
4690: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4691: if (ref($internet_names) eq 'ARRAY') {
4692: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4693: $same_institution = 1;
4694: }
4695: }
4696: }
1.275 raeburn 4697: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 4698: $datatable = '<tr'.$css_class.'><td colspan="2">';
4699: if ($same_institution) {
4700: my %domservers = &Apache::lonnet::get_servers($dom);
4701: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
4702: } else {
4703: $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.");
4704: }
4705: $datatable .= '</td></tr>';
1.275 raeburn 4706: $itemcount ++;
4707: } else {
4708: my %titles = &ssl_titles();
4709: my (%by_ip,%by_location,@intdoms,@instdoms);
4710: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4711: my @alldoms = &Apache::lonnet::all_domains();
4712: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4713: my @domservers = &Apache::lonnet::get_servers($dom);
4714: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4715: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 4716: if (($position eq 'connto') || ($position eq 'connfrom')) {
4717: my $legacy;
4718: unless (ref($settings) eq 'HASH') {
4719: my $name;
4720: if ($position eq 'connto') {
4721: $name = 'loncAllowInsecure';
4722: } else {
4723: $name = 'londAllowInsecure';
4724: }
4725: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
4726: my @ids=&Apache::lonnet::current_machine_ids();
4727: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
4728: my %what = (
4729: $name => 1,
4730: );
4731: my ($result,$returnhash) =
4732: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
4733: if ($result eq 'ok') {
4734: if (ref($returnhash) eq 'HASH') {
4735: $legacy = $returnhash->{$name};
4736: }
4737: }
4738: } else {
4739: $legacy = $Apache::lonnet::perlvar{$name};
4740: }
4741: }
1.275 raeburn 4742: foreach my $type ('dom','intdom','other') {
4743: my %checked;
4744: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4745: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4746: '<td class="LC_right_item">';
4747: my $skip;
4748: if ($type eq 'dom') {
4749: unless (keys(%servers) > 1) {
4750: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4751: $skip = 1;
4752: }
4753: }
4754: if ($type eq 'intdom') {
4755: unless (@instdoms > 1) {
4756: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4757: $skip = 1;
4758: }
4759: } elsif ($type eq 'other') {
4760: if (keys(%by_location) == 0) {
4761: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4762: $skip = 1;
4763: }
4764: }
4765: unless ($skip) {
4766: $checked{'yes'} = ' checked="checked"';
4767: if (ref($settings) eq 'HASH') {
1.293 raeburn 4768: if (ref($settings->{$position}) eq 'HASH') {
4769: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 4770: $checked{$1} = $checked{'yes'};
4771: delete($checked{'yes'});
4772: }
4773: }
1.293 raeburn 4774: } else {
4775: if ($legacy == 0) {
4776: $checked{'req'} = $checked{'yes'};
4777: delete($checked{'yes'});
4778: }
1.275 raeburn 4779: }
4780: foreach my $option ('no','yes','req') {
4781: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 4782: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 4783: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4784: '</label></span>'.(' 'x2);
4785: }
4786: }
4787: $datatable .= '</td></tr>';
4788: $itemcount ++;
4789: }
4790: } else {
4791: my $prefix = 'replication';
4792: my @types = ('certreq','nocertreq');
1.279 raeburn 4793: if (keys(%by_location) == 0) {
4794: $datatable .= '<tr'.$css_class.'><td>'.
4795: &mt('Nothing to set here, as there are no other institutions').
4796: '</td></tr>';
4797: $itemcount ++;
1.275 raeburn 4798: } else {
1.279 raeburn 4799: ($datatable,$itemcount) =
4800: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 4801: }
4802: }
4803: }
4804: $$rowtotal += $itemcount;
4805: return $datatable;
4806: }
4807:
4808: sub ssl_titles {
4809: return &Apache::lonlocal::texthash (
4810: dom => 'LON-CAPA servers/VMs from same domain',
4811: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4812: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 4813: connto => 'Connections to other servers',
4814: connfrom => 'Connections from other servers',
1.275 raeburn 4815: replication => 'Replicating content to other institutions',
4816: certreq => 'Client certificate required, but specific domains exempt',
4817: nocertreq => 'No client certificate required, except for specific domains',
4818: no => 'SSL not used',
4819: yes => 'SSL Optional (used if available)',
4820: req => 'SSL Required',
4821: );
1.279 raeburn 4822: }
4823:
4824: sub print_trust {
4825: my ($prefix,$dom,$settings,$rowtotal) = @_;
4826: my ($css_class,$datatable,%checked,%choices);
4827: my (%by_ip,%by_location,@intdoms,@instdoms);
4828: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4829: my $itemcount = 1;
4830: my %titles = &trust_titles();
4831: my @types = ('exc','inc');
4832: if ($prefix eq 'top') {
4833: $prefix = 'content';
4834: } elsif ($prefix eq 'bottom') {
4835: $prefix = 'msg';
4836: }
4837: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4838: $$rowtotal += $itemcount;
4839: return $datatable;
4840: }
4841:
4842: sub trust_titles {
4843: return &Apache::lonlocal::texthash(
4844: content => "Access to this domain's content by others",
4845: shared => "Access to other domain's content by this domain",
4846: enroll => "Enrollment in this domain's courses by others",
4847: othcoau => "Co-author roles in this domain for others",
4848: coaurem => "Co-author roles for this domain's users elsewhere",
4849: domroles => "Domain roles in this domain assignable to others",
4850: catalog => "Course Catalog for this domain displayed elsewhere",
4851: reqcrs => "Requests for creation of courses in this domain by others",
4852: msg => "Users in other domains can send messages to this domain",
4853: exc => "Allow all, but exclude specific domains",
4854: inc => "Deny all, but include specific domains",
4855: );
1.275 raeburn 4856: }
4857:
1.138 raeburn 4858: sub build_location_hashes {
1.275 raeburn 4859: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4860: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4861: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4862: my %iphost = &Apache::lonnet::get_iphost();
4863: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4864: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4865: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4866: foreach my $id (@{$iphost{$primary_ip}}) {
4867: my $intdom = &Apache::lonnet::internet_dom($id);
4868: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4869: push(@{$intdoms},$intdom);
4870: }
4871: }
4872: }
4873: foreach my $ip (keys(%iphost)) {
4874: if (ref($iphost{$ip}) eq 'ARRAY') {
4875: foreach my $id (@{$iphost{$ip}}) {
4876: my $location = &Apache::lonnet::internet_dom($id);
4877: if ($location) {
1.275 raeburn 4878: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4879: my $dom = &Apache::lonnet::host_domain($id);
4880: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4881: push(@{$instdoms},$dom);
4882: }
4883: next;
4884: }
1.138 raeburn 4885: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4886: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4887: push(@{$by_ip->{$ip}},$location);
4888: }
4889: } else {
4890: $by_ip->{$ip} = [$location];
4891: }
4892: }
4893: }
4894: }
4895: }
4896: foreach my $ip (sort(keys(%{$by_ip}))) {
4897: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4898: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4899: my $first = $by_ip->{$ip}->[0];
4900: if (ref($by_location->{$first}) eq 'ARRAY') {
4901: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4902: push(@{$by_location->{$first}},$ip);
4903: }
4904: } else {
4905: $by_location->{$first} = [$ip];
4906: }
4907: }
4908: }
4909: return;
4910: }
4911:
1.145 raeburn 4912: sub current_offloads_to {
4913: my ($dom,$settings,$servers) = @_;
4914: my (%spareid,%otherdomconfigs);
1.152 raeburn 4915: if (ref($servers) eq 'HASH') {
1.145 raeburn 4916: foreach my $lonhost (sort(keys(%{$servers}))) {
4917: my $gotspares;
1.152 raeburn 4918: if (ref($settings) eq 'HASH') {
4919: if (ref($settings->{'spares'}) eq 'HASH') {
4920: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4921: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4922: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4923: $gotspares = 1;
4924: }
1.145 raeburn 4925: }
4926: }
4927: unless ($gotspares) {
4928: my $gotspares;
4929: my $serverhomeID =
4930: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4931: my $serverhomedom =
4932: &Apache::lonnet::host_domain($serverhomeID);
4933: if ($serverhomedom ne $dom) {
4934: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4935: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4936: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4937: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4938: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4939: $gotspares = 1;
4940: }
4941: }
4942: } else {
4943: $otherdomconfigs{$serverhomedom} =
4944: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4945: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4946: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4947: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4948: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4949: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4950: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4951: $gotspares = 1;
4952: }
4953: }
4954: }
4955: }
4956: }
4957: }
4958: }
4959: unless ($gotspares) {
4960: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4961: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4962: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4963: } else {
4964: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4965: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4966: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4967: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4968: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4969: } else {
1.150 raeburn 4970: my %what = (
4971: spareid => 1,
4972: );
4973: my ($result,$returnhash) =
4974: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4975: if ($result eq 'ok') {
4976: if (ref($returnhash) eq 'HASH') {
4977: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4978: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4979: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4980: }
4981: }
1.145 raeburn 4982: }
4983: }
4984: }
4985: }
4986: }
4987: }
4988: return %spareid;
4989: }
4990:
4991: sub spares_row {
1.261 raeburn 4992: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4993: my $css_class;
4994: my $numinrow = 4;
4995: my $itemcount = 1;
4996: my $datatable;
1.152 raeburn 4997: my %typetitles = &sparestype_titles();
4998: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4999: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5000: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5001: my ($othercontrol,$serverdom);
5002: if ($serverhome ne $server) {
5003: $serverdom = &Apache::lonnet::host_domain($serverhome);
5004: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5005: } else {
5006: $serverdom = &Apache::lonnet::host_domain($server);
5007: if ($serverdom ne $dom) {
5008: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5009: }
5010: }
5011: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 5012: my $checkednow;
5013: if (ref($curroffloadnow) eq 'HASH') {
5014: if ($curroffloadnow->{$server}) {
5015: $checkednow = ' checked="checked"';
5016: }
5017: }
1.145 raeburn 5018: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5019: $datatable .= '<tr'.$css_class.'>
5020: <td rowspan="2">
1.183 bisitz 5021: <span class="LC_nobreak">'.
5022: &mt('[_1] when busy, offloads to:'
1.261 raeburn 5023: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 5024: '<span class="LC_nobreak">'."\n".
1.261 raeburn 5025: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5026: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 5027: "\n";
1.145 raeburn 5028: my (%current,%canselect);
1.152 raeburn 5029: my @choices =
5030: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5031: foreach my $type ('primary','default') {
5032: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5033: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5034: my @spares = @{$spareid->{$server}{$type}};
5035: if (@spares > 0) {
1.152 raeburn 5036: if ($othercontrol) {
5037: $current{$type} = join(', ',@spares);
5038: } else {
5039: $current{$type} .= '<table>';
5040: my $numspares = scalar(@spares);
5041: for (my $i=0; $i<@spares; $i++) {
5042: my $rem = $i%($numinrow);
5043: if ($rem == 0) {
5044: if ($i > 0) {
5045: $current{$type} .= '</tr>';
5046: }
5047: $current{$type} .= '<tr>';
1.145 raeburn 5048: }
1.152 raeburn 5049: $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'".');" /> '.
5050: $spareid->{$server}{$type}[$i].
5051: '</label></td>'."\n";
5052: }
5053: my $rem = @spares%($numinrow);
5054: my $colsleft = $numinrow - $rem;
5055: if ($colsleft > 1 ) {
5056: $current{$type} .= '<td colspan="'.$colsleft.
5057: '" class="LC_left_item">'.
5058: ' </td>';
5059: } elsif ($colsleft == 1) {
5060: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5061: }
1.152 raeburn 5062: $current{$type} .= '</tr></table>';
1.150 raeburn 5063: }
1.145 raeburn 5064: }
5065: }
5066: if ($current{$type} eq '') {
5067: $current{$type} = &mt('None specified');
5068: }
1.152 raeburn 5069: if ($othercontrol) {
5070: if ($type eq 'primary') {
5071: $canselect{$type} = $othercontrol;
5072: }
5073: } else {
5074: $canselect{$type} =
5075: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5076: '<select name="newspare_'.$type.'_'.$server.'" '.
5077: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5078: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5079: if (@choices > 0) {
5080: foreach my $lonhost (@choices) {
5081: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5082: }
5083: }
5084: $canselect{$type} .= '</select>'."\n";
5085: }
5086: } else {
5087: $current{$type} = &mt('Could not be determined');
5088: if ($type eq 'primary') {
5089: $canselect{$type} = $othercontrol;
5090: }
1.145 raeburn 5091: }
1.152 raeburn 5092: if ($type eq 'default') {
5093: $datatable .= '<tr'.$css_class.'>';
5094: }
5095: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5096: '<td>'.$current{$type}.'</td>'."\n".
5097: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5098: }
5099: $itemcount ++;
5100: }
5101: }
5102: $$rowtotal += $itemcount;
5103: return $datatable;
5104: }
5105:
1.152 raeburn 5106: sub possible_newspares {
5107: my ($server,$currspares,$serverhomes,$altids) = @_;
5108: my $serverhostname = &Apache::lonnet::hostname($server);
5109: my %excluded;
5110: if ($serverhostname ne '') {
5111: %excluded = (
5112: $serverhostname => 1,
5113: );
5114: }
5115: if (ref($currspares) eq 'HASH') {
5116: foreach my $type (keys(%{$currspares})) {
5117: if (ref($currspares->{$type}) eq 'ARRAY') {
5118: if (@{$currspares->{$type}} > 0) {
5119: foreach my $curr (@{$currspares->{$type}}) {
5120: my $hostname = &Apache::lonnet::hostname($curr);
5121: $excluded{$hostname} = 1;
5122: }
5123: }
5124: }
5125: }
5126: }
5127: my @choices;
5128: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5129: if (keys(%{$serverhomes}) > 1) {
5130: foreach my $name (sort(keys(%{$serverhomes}))) {
5131: unless ($excluded{$name}) {
5132: if (exists($altids->{$serverhomes->{$name}})) {
5133: push(@choices,$altids->{$serverhomes->{$name}});
5134: } else {
5135: push(@choices,$serverhomes->{$name});
1.145 raeburn 5136: }
5137: }
5138: }
5139: }
5140: }
1.152 raeburn 5141: return sort(@choices);
1.145 raeburn 5142: }
5143:
1.150 raeburn 5144: sub print_loadbalancing {
5145: my ($dom,$settings,$rowtotal) = @_;
5146: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5147: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5148: my $numinrow = 1;
5149: my $datatable;
5150: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5151: my (%currbalancer,%currtargets,%currrules,%existing);
5152: if (ref($settings) eq 'HASH') {
5153: %existing = %{$settings};
5154: }
5155: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5156: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5157: \%currtargets,\%currrules);
1.150 raeburn 5158: } else {
5159: return;
5160: }
5161: my ($othertitle,$usertypes,$types) =
5162: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5163: my $rownum = 8;
1.150 raeburn 5164: if (ref($types) eq 'ARRAY') {
5165: $rownum += scalar(@{$types});
5166: }
1.171 raeburn 5167: my @css_class = ('LC_odd_row','LC_even_row');
5168: my $balnum = 0;
5169: my $islast;
5170: my (@toshow,$disabledtext);
5171: if (keys(%currbalancer) > 0) {
5172: @toshow = sort(keys(%currbalancer));
5173: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5174: push(@toshow,'');
5175: }
5176: } else {
5177: @toshow = ('');
5178: $disabledtext = &mt('No existing load balancer');
5179: }
5180: foreach my $lonhost (@toshow) {
5181: if ($balnum == scalar(@toshow)-1) {
5182: $islast = 1;
5183: } else {
5184: $islast = 0;
5185: }
5186: my $cssidx = $balnum%2;
5187: my $targets_div_style = 'display: none';
5188: my $disabled_div_style = 'display: block';
5189: my $homedom_div_style = 'display: none';
5190: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5191: '<td rowspan="'.$rownum.'" valign="top">'.
5192: '<p>';
5193: if ($lonhost eq '') {
1.210 raeburn 5194: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 5195: if (keys(%currbalancer) > 0) {
5196: $datatable .= &mt('Add balancer:');
5197: } else {
5198: $datatable .= &mt('Enable balancer:');
5199: }
5200: $datatable .= ' '.
5201: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5202: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5203: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5204: '<option value="" selected="selected">'.&mt('None').
5205: '</option>'."\n";
5206: foreach my $server (sort(keys(%servers))) {
5207: next if ($currbalancer{$server});
5208: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5209: }
1.210 raeburn 5210: $datatable .=
1.171 raeburn 5211: '</select>'."\n".
5212: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5213: } else {
5214: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5215: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5216: &mt('Stop balancing').'</label>'.
5217: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5218: $targets_div_style = 'display: block';
5219: $disabled_div_style = 'display: none';
5220: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5221: $homedom_div_style = 'display: block';
5222: }
5223: }
5224: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5225: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5226: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5227: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5228: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5229: my @sparestypes = ('primary','default');
5230: my %typetitles = &sparestype_titles();
1.284 raeburn 5231: my %hostherechecked = (
5232: no => ' checked="checked"',
5233: );
1.171 raeburn 5234: foreach my $sparetype (@sparestypes) {
5235: my $targettable;
5236: for (my $i=0; $i<$numspares; $i++) {
5237: my $checked;
5238: if (ref($currtargets{$lonhost}) eq 'HASH') {
5239: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5240: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5241: $checked = ' checked="checked"';
5242: }
5243: }
5244: }
5245: my ($chkboxval,$disabled);
5246: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5247: $chkboxval = $spares[$i];
5248: }
5249: if (exists($currbalancer{$spares[$i]})) {
5250: $disabled = ' disabled="disabled"';
5251: }
1.210 raeburn 5252: $targettable .=
1.253 raeburn 5253: '<td><span class="LC_nobreak"><label>'.
5254: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 5255: $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 5256: '</span></label></span></td>';
1.171 raeburn 5257: my $rem = $i%($numinrow);
5258: if ($rem == 0) {
5259: if (($i > 0) && ($i < $numspares-1)) {
5260: $targettable .= '</tr>';
5261: }
5262: if ($i < $numspares-1) {
5263: $targettable .= '<tr>';
1.150 raeburn 5264: }
5265: }
5266: }
1.171 raeburn 5267: if ($targettable ne '') {
5268: my $rem = $numspares%($numinrow);
5269: my $colsleft = $numinrow - $rem;
5270: if ($colsleft > 1 ) {
5271: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5272: ' </td>';
5273: } elsif ($colsleft == 1) {
5274: $targettable .= '<td class="LC_left_item"> </td>';
5275: }
5276: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5277: '<table><tr>'.$targettable.'</tr></table><br />';
5278: }
1.284 raeburn 5279: $hostherechecked{$sparetype} = '';
5280: if (ref($currtargets{$lonhost}) eq 'HASH') {
5281: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5282: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5283: $hostherechecked{$sparetype} = ' checked="checked"';
5284: $hostherechecked{'no'} = '';
5285: }
5286: }
5287: }
5288: }
5289: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5290: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5291: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5292: foreach my $sparetype (@sparestypes) {
5293: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5294: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5295: '</i></label><br />';
1.171 raeburn 5296: }
5297: $datatable .= '</div></td></tr>'.
5298: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5299: $othertitle,$usertypes,$types,\%servers,
5300: \%currbalancer,$lonhost,
5301: $targets_div_style,$homedom_div_style,
5302: $css_class[$cssidx],$balnum,$islast);
5303: $$rowtotal += $rownum;
5304: $balnum ++;
5305: }
5306: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5307: return $datatable;
5308: }
5309:
5310: sub get_loadbalancers_config {
5311: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5312: return unless ((ref($servers) eq 'HASH') &&
5313: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5314: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5315: if (keys(%{$existing}) > 0) {
5316: my $oldlonhost;
5317: foreach my $key (sort(keys(%{$existing}))) {
5318: if ($key eq 'lonhost') {
5319: $oldlonhost = $existing->{'lonhost'};
5320: $currbalancer->{$oldlonhost} = 1;
5321: } elsif ($key eq 'targets') {
5322: if ($oldlonhost) {
5323: $currtargets->{$oldlonhost} = $existing->{'targets'};
5324: }
5325: } elsif ($key eq 'rules') {
5326: if ($oldlonhost) {
5327: $currrules->{$oldlonhost} = $existing->{'rules'};
5328: }
5329: } elsif (ref($existing->{$key}) eq 'HASH') {
5330: $currbalancer->{$key} = 1;
5331: $currtargets->{$key} = $existing->{$key}{'targets'};
5332: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5333: }
5334: }
1.171 raeburn 5335: } else {
5336: my ($balancerref,$targetsref) =
5337: &Apache::lonnet::get_lonbalancer_config($servers);
5338: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5339: foreach my $server (sort(keys(%{$balancerref}))) {
5340: $currbalancer->{$server} = 1;
5341: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5342: }
5343: }
5344: }
1.171 raeburn 5345: return;
1.150 raeburn 5346: }
5347:
5348: sub loadbalancing_rules {
5349: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 5350: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5351: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5352: my $output;
1.171 raeburn 5353: my $num = 0;
1.210 raeburn 5354: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5355: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5356: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5357: foreach my $type (@{$alltypes}) {
1.171 raeburn 5358: $num ++;
1.150 raeburn 5359: my $current;
5360: if (ref($currrules) eq 'HASH') {
5361: $current = $currrules->{$type};
5362: }
1.253 raeburn 5363: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 5364: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5365: $current = '';
5366: }
5367: }
5368: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 5369: $servers,$currbalancer,$lonhost,$dom,
5370: $targets_div_style,$homedom_div_style,
5371: $css_class,$balnum,$num,$islast);
1.150 raeburn 5372: }
5373: }
5374: return $output;
5375: }
5376:
5377: sub loadbalancing_titles {
5378: my ($dom,$intdom,$usertypes,$types) = @_;
5379: my %othertypes = (
5380: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5381: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5382: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5383: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 5384: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5385: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5386: );
1.209 raeburn 5387: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 5388: if (ref($types) eq 'ARRAY') {
5389: unshift(@alltypes,@{$types},'default');
5390: }
5391: my %titles;
5392: foreach my $type (@alltypes) {
5393: if ($type =~ /^_LC_/) {
5394: $titles{$type} = $othertypes{$type};
5395: } elsif ($type eq 'default') {
5396: $titles{$type} = &mt('All users from [_1]',$dom);
5397: if (ref($types) eq 'ARRAY') {
5398: if (@{$types} > 0) {
5399: $titles{$type} = &mt('Other users from [_1]',$dom);
5400: }
5401: }
5402: } elsif (ref($usertypes) eq 'HASH') {
5403: $titles{$type} = $usertypes->{$type};
5404: }
5405: }
5406: return (\@alltypes,\%othertypes,\%titles);
5407: }
5408:
5409: sub loadbalance_rule_row {
1.171 raeburn 5410: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5411: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 5412: my @rulenames;
1.150 raeburn 5413: my %ruletitles = &offloadtype_text();
1.209 raeburn 5414: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 5415: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5416: } else {
1.209 raeburn 5417: @rulenames = ('default','homeserver');
5418: if ($type eq '_LC_external') {
5419: push(@rulenames,'externalbalancer');
5420: } else {
5421: push(@rulenames,'specific');
5422: }
5423: push(@rulenames,'none');
1.150 raeburn 5424: }
5425: my $style = $targets_div_style;
1.253 raeburn 5426: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5427: $style = $homedom_div_style;
5428: }
1.171 raeburn 5429: my $space;
5430: if ($islast && $num == 1) {
5431: $space = '<div display="inline-block"> </div>';
5432: }
1.210 raeburn 5433: my $output =
1.171 raeburn 5434: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5435: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5436: '<td valaign="top">'.$space.
5437: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5438: for (my $i=0; $i<@rulenames; $i++) {
5439: my $rule = $rulenames[$i];
5440: my ($checked,$extra);
5441: if ($rulenames[$i] eq 'default') {
5442: $rule = '';
5443: }
5444: if ($rulenames[$i] eq 'specific') {
5445: if (ref($servers) eq 'HASH') {
5446: my $default;
5447: if (($current ne '') && (exists($servers->{$current}))) {
5448: $checked = ' checked="checked"';
5449: }
5450: unless ($checked) {
5451: $default = ' selected="selected"';
5452: }
1.210 raeburn 5453: $extra =
1.171 raeburn 5454: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5455: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5456: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5457: '<option value=""'.$default.'></option>'."\n";
5458: foreach my $server (sort(keys(%{$servers}))) {
5459: if (ref($currbalancer) eq 'HASH') {
5460: next if (exists($currbalancer->{$server}));
5461: }
1.150 raeburn 5462: my $selected;
1.171 raeburn 5463: if ($server eq $current) {
1.150 raeburn 5464: $selected = ' selected="selected"';
5465: }
1.171 raeburn 5466: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5467: }
5468: $extra .= '</select>';
5469: }
5470: } elsif ($rule eq $current) {
5471: $checked = ' checked="checked"';
5472: }
5473: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 5474: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5475: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5476: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 5477: ')"'.$checked.' /> ';
5478: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
5479: $output .= $ruletitles{'particular'};
5480: } else {
5481: $output .= $ruletitles{$rulenames[$i]};
5482: }
5483: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5484: }
5485: $output .= '</div></td></tr>'."\n";
5486: return $output;
5487: }
5488:
5489: sub offloadtype_text {
5490: my %ruletitles = &Apache::lonlocal::texthash (
5491: 'default' => 'Offloads to default destinations',
5492: 'homeserver' => "Offloads to user's home server",
5493: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5494: 'specific' => 'Offloads to specific server',
1.161 raeburn 5495: 'none' => 'No offload',
1.209 raeburn 5496: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5497: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 5498: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5499: );
5500: return %ruletitles;
5501: }
5502:
5503: sub sparestype_titles {
5504: my %typestitles = &Apache::lonlocal::texthash (
5505: 'primary' => 'primary',
5506: 'default' => 'default',
5507: );
5508: return %typestitles;
5509: }
5510:
1.28 raeburn 5511: sub contact_titles {
5512: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 5513: 'supportemail' => 'Support E-mail address',
5514: 'adminemail' => 'Default Server Admin E-mail address',
5515: 'errormail' => 'Error reports to be e-mailed to',
5516: 'packagesmail' => 'Package update alerts to be e-mailed to',
5517: 'helpdeskmail' => "Helpdesk requests for this domain's users",
1.289 raeburn 5518: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
1.286 raeburn 5519: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5520: 'requestsmail' => 'E-mail from course requests requiring approval',
5521: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 5522: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5523: );
5524: my %short_titles = &Apache::lonlocal::texthash (
5525: adminemail => 'Admin E-mail address',
5526: supportemail => 'Support E-mail',
5527: );
5528: return (\%titles,\%short_titles);
5529: }
5530:
1.286 raeburn 5531: sub helpform_fields {
5532: my %titles = &Apache::lonlocal::texthash (
5533: 'username' => 'Name',
5534: 'user' => 'Username/domain',
5535: 'phone' => 'Phone',
5536: 'cc' => 'Cc e-mail',
5537: 'course' => 'Course Details',
5538: 'section' => 'Sections',
1.289 raeburn 5539: 'screenshot' => 'File upload',
1.286 raeburn 5540: );
5541: my @fields = ('username','phone','user','course','section','cc','screenshot');
5542: my %possoptions = (
5543: username => ['yes','no','req'],
1.289 raeburn 5544: phone => ['yes','no','req'],
1.286 raeburn 5545: user => ['yes','no'],
1.289 raeburn 5546: cc => ['yes','no'],
1.286 raeburn 5547: course => ['yes','no'],
5548: section => ['yes','no'],
5549: screenshot => ['yes','no'],
5550: );
5551: my %fieldoptions = &Apache::lonlocal::texthash (
5552: 'yes' => 'Optional',
5553: 'req' => 'Required',
5554: 'no' => "Not shown",
5555: );
5556: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5557: }
5558:
1.72 raeburn 5559: sub tool_titles {
5560: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 5561: aboutme => 'Personal web page',
1.86 raeburn 5562: blog => 'Blog',
1.162 raeburn 5563: webdav => 'WebDAV',
1.86 raeburn 5564: portfolio => 'Portfolio',
1.88 bisitz 5565: official => 'Official courses (with institutional codes)',
5566: unofficial => 'Unofficial courses',
1.98 raeburn 5567: community => 'Communities',
1.216 raeburn 5568: textbook => 'Textbook courses',
1.271 raeburn 5569: placement => 'Placement tests',
1.86 raeburn 5570: );
1.72 raeburn 5571: return %titles;
5572: }
5573:
1.101 raeburn 5574: sub courserequest_titles {
5575: my %titles = &Apache::lonlocal::texthash (
5576: official => 'Official',
5577: unofficial => 'Unofficial',
5578: community => 'Communities',
1.216 raeburn 5579: textbook => 'Textbook',
1.271 raeburn 5580: placement => 'Placement tests',
1.101 raeburn 5581: norequest => 'Not allowed',
1.104 raeburn 5582: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5583: validate => 'With validation',
5584: autolimit => 'Numerical limit',
1.103 raeburn 5585: unlimited => '(blank for unlimited)',
1.101 raeburn 5586: );
5587: return %titles;
5588: }
5589:
1.163 raeburn 5590: sub authorrequest_titles {
5591: my %titles = &Apache::lonlocal::texthash (
5592: norequest => 'Not allowed',
5593: approval => 'Approval by Dom. Coord.',
5594: automatic => 'Automatic approval',
5595: );
5596: return %titles;
1.210 raeburn 5597: }
1.163 raeburn 5598:
1.101 raeburn 5599: sub courserequest_conditions {
5600: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5601: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 5602: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5603: );
5604: return %conditions;
5605: }
5606:
5607:
1.27 raeburn 5608: sub print_usercreation {
1.30 raeburn 5609: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5610: my $numinrow = 4;
1.28 raeburn 5611: my $datatable;
5612: if ($position eq 'top') {
1.30 raeburn 5613: $$rowtotal ++;
1.34 raeburn 5614: my $rowcount = 0;
1.32 raeburn 5615: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5616: if (ref($rules) eq 'HASH') {
5617: if (keys(%{$rules}) > 0) {
1.32 raeburn 5618: $datatable .= &user_formats_row('username',$settings,$rules,
5619: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5620: $$rowtotal ++;
1.32 raeburn 5621: $rowcount ++;
5622: }
5623: }
5624: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5625: if (ref($idrules) eq 'HASH') {
5626: if (keys(%{$idrules}) > 0) {
5627: $datatable .= &user_formats_row('id',$settings,$idrules,
5628: $idruleorder,$numinrow,$rowcount);
5629: $$rowtotal ++;
5630: $rowcount ++;
1.28 raeburn 5631: }
5632: }
1.39 raeburn 5633: if ($rowcount == 0) {
5634: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5635: $$rowtotal ++;
5636: $rowcount ++;
5637: }
1.34 raeburn 5638: } elsif ($position eq 'middle') {
1.224 raeburn 5639: my @creators = ('author','course','requestcrs');
1.37 raeburn 5640: my ($rules,$ruleorder) =
5641: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5642: my %lt = &usercreation_types();
5643: my %checked;
5644: if (ref($settings) eq 'HASH') {
5645: if (ref($settings->{'cancreate'}) eq 'HASH') {
5646: foreach my $item (@creators) {
5647: $checked{$item} = $settings->{'cancreate'}{$item};
5648: }
5649: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5650: foreach my $item (@creators) {
5651: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5652: $checked{$item} = 'none';
5653: }
5654: }
5655: }
5656: }
5657: my $rownum = 0;
5658: foreach my $item (@creators) {
5659: $rownum ++;
1.224 raeburn 5660: if ($checked{$item} eq '') {
5661: $checked{$item} = 'any';
1.34 raeburn 5662: }
5663: my $css_class;
5664: if ($rownum%2) {
5665: $css_class = '';
5666: } else {
5667: $css_class = ' class="LC_odd_row" ';
5668: }
5669: $datatable .= '<tr'.$css_class.'>'.
5670: '<td><span class="LC_nobreak">'.$lt{$item}.
5671: '</span></td><td align="right">';
1.224 raeburn 5672: my @options = ('any');
5673: if (ref($rules) eq 'HASH') {
5674: if (keys(%{$rules}) > 0) {
5675: push(@options,('official','unofficial'));
1.37 raeburn 5676: }
5677: }
1.224 raeburn 5678: push(@options,'none');
1.37 raeburn 5679: foreach my $option (@options) {
1.50 raeburn 5680: my $type = 'radio';
1.34 raeburn 5681: my $check = ' ';
1.224 raeburn 5682: if ($checked{$item} eq $option) {
5683: $check = ' checked="checked" ';
1.34 raeburn 5684: }
5685: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5686: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5687: $item.'" value="'.$option.'"'.$check.'/> '.
5688: $lt{$option}.'</label> </span>';
5689: }
5690: $datatable .= '</td></tr>';
5691: }
1.28 raeburn 5692: } else {
5693: my @contexts = ('author','course','domain');
5694: my @authtypes = ('int','krb4','krb5','loc');
5695: my %checked;
5696: if (ref($settings) eq 'HASH') {
5697: if (ref($settings->{'authtypes'}) eq 'HASH') {
5698: foreach my $item (@contexts) {
5699: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5700: foreach my $auth (@authtypes) {
5701: if ($settings->{'authtypes'}{$item}{$auth}) {
5702: $checked{$item}{$auth} = ' checked="checked" ';
5703: }
5704: }
5705: }
5706: }
1.27 raeburn 5707: }
1.35 raeburn 5708: } else {
5709: foreach my $item (@contexts) {
1.36 raeburn 5710: foreach my $auth (@authtypes) {
1.35 raeburn 5711: $checked{$item}{$auth} = ' checked="checked" ';
5712: }
5713: }
1.27 raeburn 5714: }
1.28 raeburn 5715: my %title = &context_names();
5716: my %authname = &authtype_names();
5717: my $rownum = 0;
5718: my $css_class;
5719: foreach my $item (@contexts) {
5720: if ($rownum%2) {
5721: $css_class = '';
5722: } else {
5723: $css_class = ' class="LC_odd_row" ';
5724: }
1.30 raeburn 5725: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5726: '<td>'.$title{$item}.
5727: '</td><td class="LC_left_item">'.
5728: '<span class="LC_nobreak">';
5729: foreach my $auth (@authtypes) {
5730: $datatable .= '<label>'.
5731: '<input type="checkbox" name="'.$item.'_auth" '.
5732: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5733: $authname{$auth}.'</label> ';
5734: }
5735: $datatable .= '</span></td></tr>';
5736: $rownum ++;
1.27 raeburn 5737: }
1.30 raeburn 5738: $$rowtotal += $rownum;
1.27 raeburn 5739: }
5740: return $datatable;
5741: }
5742:
1.224 raeburn 5743: sub print_selfcreation {
5744: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 5745: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 5746: if (ref($settings) eq 'HASH') {
5747: if (ref($settings->{'cancreate'}) eq 'HASH') {
5748: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5749: if (ref($createsettings) eq 'HASH') {
5750: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5751: @selfcreate = @{$createsettings->{'selfcreate'}};
5752: } elsif ($createsettings->{'selfcreate'} ne '') {
5753: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5754: @selfcreate = ('email','login','sso');
5755: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5756: @selfcreate = ($createsettings->{'selfcreate'});
5757: }
5758: }
5759: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5760: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5761: }
5762: }
5763: }
5764: }
5765: my %radiohash;
5766: my $numinrow = 4;
5767: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5768: if ($position eq 'top') {
5769: my %choices = &Apache::lonlocal::texthash (
5770: cancreate_login => 'Institutional Login',
5771: cancreate_sso => 'Institutional Single Sign On',
5772: );
5773: my @toggles = sort(keys(%choices));
5774: my %defaultchecked = (
5775: 'cancreate_login' => 'off',
5776: 'cancreate_sso' => 'off',
5777: );
1.228 raeburn 5778: my ($onclick,$itemcount);
1.224 raeburn 5779: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5780: \%choices,$itemcount,$onclick);
1.228 raeburn 5781: $$rowtotal += $itemcount;
5782:
1.224 raeburn 5783: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5784:
5785: if (ref($usertypes) eq 'HASH') {
5786: if (keys(%{$usertypes}) > 0) {
5787: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5788: $dom,$numinrow,$othertitle,
1.228 raeburn 5789: 'statustocreate',$$rowtotal);
1.224 raeburn 5790: $$rowtotal ++;
5791: }
5792: }
1.240 raeburn 5793: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5794: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5795: $fieldtitles{'inststatus'} = &mt('Institutional status');
5796: my $rem;
5797: my $numperrow = 2;
5798: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5799: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5800: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5801: '<td class="LC_left_item">'."\n".
5802: '<table><tr><td>'."\n";
5803: for (my $i=0; $i<@fields; $i++) {
5804: $rem = $i%($numperrow);
5805: if ($rem == 0) {
5806: if ($i > 0) {
5807: $datatable .= '</tr>';
5808: }
5809: $datatable .= '<tr>';
5810: }
5811: my $currval;
1.248 raeburn 5812: if (ref($createsettings) eq 'HASH') {
5813: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5814: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5815: }
1.240 raeburn 5816: }
5817: $datatable .= '<td class="LC_left_item">'.
5818: '<span class="LC_nobreak">'.
5819: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5820: 'value="'.$currval.'" size="10" /> '.
5821: $fieldtitles{$fields[$i]}.'</span></td>';
5822: }
5823: my $colsleft = $numperrow - $rem;
5824: if ($colsleft > 1 ) {
5825: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5826: ' </td>';
5827: } elsif ($colsleft == 1) {
5828: $datatable .= '<td class="LC_left_item"> </td>';
5829: }
5830: $datatable .= '</tr></table></td></tr>';
5831: $$rowtotal ++;
1.224 raeburn 5832: } elsif ($position eq 'middle') {
5833: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5834: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5835: $usertypes->{'default'} = $othertitle;
5836: if (ref($types) eq 'ARRAY') {
5837: push(@{$types},'default');
5838: $usertypes->{'default'} = $othertitle;
5839: foreach my $status (@{$types}) {
5840: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5841: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5842: $$rowtotal ++;
1.224 raeburn 5843: }
5844: }
5845: } else {
1.236 raeburn 5846: my %choices = &Apache::lonlocal::texthash (
5847: cancreate_email => 'E-mail address as username',
5848: );
5849: my @toggles = sort(keys(%choices));
5850: my %defaultchecked = (
5851: 'cancreate_email' => 'off',
5852: );
5853: my $itemcount = 0;
5854: my $display = 'none';
5855: if (grep(/^\Qemail\E$/,@selfcreate)) {
5856: $display = 'block';
5857: }
5858: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5859: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5860: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5861: my $usertypes = {};
5862: my $order = [];
5863: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5864: $usertypes = $domdefaults{'inststatustypes'};
5865: $order = $domdefaults{'inststatusguest'};
5866: }
5867: if (ref($order) eq 'ARRAY') {
5868: push(@{$order},'default');
5869: if (@{$order} > 1) {
5870: $usertypes->{'default'} = &mt('Other users');
5871: $additional .= '<table><tr>';
5872: foreach my $status (@{$order}) {
5873: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5874: }
5875: $additional .= '</tr><tr>';
5876: foreach my $status (@{$order}) {
5877: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5878: }
1.236 raeburn 5879: $additional .= '</tr></table>';
1.224 raeburn 5880: } else {
1.236 raeburn 5881: $usertypes->{'default'} = &mt('All users');
5882: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5883: }
5884: }
1.236 raeburn 5885: $additional .= '</div>'."\n";
5886:
5887: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5888: \%choices,$$rowtotal,$onclick,$additional);
5889: $$rowtotal ++;
1.236 raeburn 5890: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5891: $$rowtotal ++;
1.224 raeburn 5892: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5893: $numinrow = 1;
1.236 raeburn 5894: if (ref($order) eq 'ARRAY') {
5895: foreach my $status (@{$order}) {
1.228 raeburn 5896: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5897: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5898: $$rowtotal ++;
5899: }
5900: }
1.224 raeburn 5901: my ($emailrules,$emailruleorder) =
5902: &Apache::lonnet::inst_userrules($dom,'email');
5903: if (ref($emailrules) eq 'HASH') {
5904: if (keys(%{$emailrules}) > 0) {
5905: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5906: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5907: $$rowtotal ++;
5908: }
5909: }
1.228 raeburn 5910: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5911: }
5912: return $datatable;
5913: }
5914:
1.236 raeburn 5915: sub email_as_username {
5916: my ($rowtotal,$processing,$type) = @_;
5917: my %choices =
5918: &Apache::lonlocal::texthash (
5919: automatic => 'Automatic approval',
5920: approval => 'Queued for approval',
5921: );
5922: my $output;
5923: foreach my $option ('automatic','approval') {
5924: my $checked;
5925: if (ref($processing) eq 'HASH') {
5926: if ($type eq '') {
5927: if (!exists($processing->{'default'})) {
5928: if ($option eq 'automatic') {
5929: $checked = ' checked="checked"';
5930: }
5931: } else {
5932: if ($processing->{'default'} eq $option) {
5933: $checked = ' checked="checked"';
5934: }
5935: }
5936: } else {
5937: if (!exists($processing->{$type})) {
5938: if ($option eq 'automatic') {
5939: $checked = ' checked="checked"';
5940: }
5941: } else {
5942: if ($processing->{$type} eq $option) {
5943: $checked = ' checked="checked"';
5944: }
5945: }
5946: }
5947: } elsif ($option eq 'automatic') {
5948: $checked = ' checked="checked"';
5949: }
5950: my $name = 'cancreate_emailprocess';
5951: if (($type ne '') && ($type ne 'default')) {
5952: $name .= '_'.$type;
5953: }
5954: $output .= '<span class="LC_nobreak"><label>'.
5955: '<input type="radio" name="'.$name.'"'.
5956: $checked.' value="'.$option.'" />'.
5957: $choices{$option}.'</label></span>';
5958: if ($type eq '') {
5959: $output .= ' ';
5960: } else {
5961: $output .= '<br />';
5962: }
5963: }
5964: $$rowtotal ++;
5965: return $output;
5966: }
5967:
1.165 raeburn 5968: sub captcha_choice {
1.169 raeburn 5969: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5970: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5971: $vertext,$currver);
1.165 raeburn 5972: my %lt = &captcha_phrases();
5973: $keyentry = 'hidden';
5974: if ($context eq 'cancreate') {
1.224 raeburn 5975: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5976: } elsif ($context eq 'login') {
5977: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5978: }
5979: if (ref($settings) eq 'HASH') {
5980: if ($settings->{'captcha'}) {
5981: $checked{$settings->{'captcha'}} = ' checked="checked"';
5982: } else {
5983: $checked{'original'} = ' checked="checked"';
5984: }
5985: if ($settings->{'captcha'} eq 'recaptcha') {
5986: $pubtext = $lt{'pub'};
5987: $privtext = $lt{'priv'};
5988: $keyentry = 'text';
1.269 raeburn 5989: $vertext = $lt{'ver'};
5990: $currver = $settings->{'recaptchaversion'};
5991: if ($currver ne '2') {
5992: $currver = 1;
5993: }
1.165 raeburn 5994: }
5995: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5996: $currpub = $settings->{'recaptchakeys'}{'public'};
5997: $currpriv = $settings->{'recaptchakeys'}{'private'};
5998: }
5999: } else {
6000: $checked{'original'} = ' checked="checked"';
6001: }
1.169 raeburn 6002: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
6003: my $output = '<tr'.$css_class.'>'.
6004: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 6005: '<table><tr><td>'."\n";
6006: foreach my $option ('original','recaptcha','notused') {
6007: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6008: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6009: $lt{$option}.'</label></span>';
6010: unless ($option eq 'notused') {
6011: $output .= (' 'x2)."\n";
6012: }
6013: }
6014: #
6015: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6016: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 6017: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 6018: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 6019: #
1.165 raeburn 6020: $output .= '</td></tr>'."\n".
6021: '<tr><td>'."\n".
6022: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6023: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6024: $currpub.'" size="40" /></span><br />'."\n".
6025: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6026: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 6027: $currpriv.'" size="40" /></span><br />'.
6028: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6029: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6030: $currver.'" size="3" /></span><br />'.
6031: '</td></tr></table>'."\n".
1.165 raeburn 6032: '</td></tr>';
6033: return $output;
6034: }
6035:
1.32 raeburn 6036: sub user_formats_row {
6037: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
6038: my $output;
6039: my %text = (
6040: 'username' => 'new usernames',
6041: 'id' => 'IDs',
1.45 raeburn 6042: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 6043: );
6044: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6045: $output = '<tr '.$css_class.'>'.
1.63 raeburn 6046: '<td><span class="LC_nobreak">';
6047: if ($type eq 'email') {
6048: $output .= &mt("Formats disallowed for $text{$type}: ");
6049: } else {
6050: $output .= &mt("Format rules to check for $text{$type}: ");
6051: }
6052: $output .= '</span></td>'.
6053: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 6054: my $rem;
6055: if (ref($ruleorder) eq 'ARRAY') {
6056: for (my $i=0; $i<@{$ruleorder}; $i++) {
6057: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6058: my $rem = $i%($numinrow);
6059: if ($rem == 0) {
6060: if ($i > 0) {
6061: $output .= '</tr>';
6062: }
6063: $output .= '<tr>';
6064: }
6065: my $check = ' ';
1.39 raeburn 6066: if (ref($settings) eq 'HASH') {
6067: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6068: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6069: $check = ' checked="checked" ';
6070: }
1.27 raeburn 6071: }
6072: }
6073: $output .= '<td class="LC_left_item">'.
6074: '<span class="LC_nobreak"><label>'.
1.32 raeburn 6075: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 6076: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6077: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6078: }
6079: }
6080: $rem = @{$ruleorder}%($numinrow);
6081: }
6082: my $colsleft = $numinrow - $rem;
6083: if ($colsleft > 1 ) {
6084: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6085: ' </td>';
6086: } elsif ($colsleft == 1) {
6087: $output .= '<td class="LC_left_item"> </td>';
6088: }
6089: $output .= '</tr></table></td></tr>';
6090: return $output;
6091: }
6092:
1.34 raeburn 6093: sub usercreation_types {
6094: my %lt = &Apache::lonlocal::texthash (
6095: author => 'When adding a co-author',
6096: course => 'When adding a user to a course',
1.100 raeburn 6097: requestcrs => 'When requesting a course',
1.34 raeburn 6098: any => 'Any',
6099: official => 'Institutional only ',
6100: unofficial => 'Non-institutional only',
6101: none => 'None',
6102: );
6103: return %lt;
1.48 raeburn 6104: }
1.34 raeburn 6105:
1.224 raeburn 6106: sub selfcreation_types {
6107: my %lt = &Apache::lonlocal::texthash (
6108: selfcreate => 'User creates own account',
6109: any => 'Any',
6110: official => 'Institutional only ',
6111: unofficial => 'Non-institutional only',
6112: email => 'E-mail address',
6113: login => 'Institutional Login',
6114: sso => 'SSO',
6115: );
6116: }
6117:
1.28 raeburn 6118: sub authtype_names {
6119: my %lt = &Apache::lonlocal::texthash(
6120: int => 'Internal',
6121: krb4 => 'Kerberos 4',
6122: krb5 => 'Kerberos 5',
6123: loc => 'Local',
6124: );
6125: return %lt;
6126: }
6127:
6128: sub context_names {
6129: my %context_title = &Apache::lonlocal::texthash(
6130: author => 'Creating users when an Author',
6131: course => 'Creating users when in a course',
6132: domain => 'Creating users when a Domain Coordinator',
6133: );
6134: return %context_title;
6135: }
6136:
1.33 raeburn 6137: sub print_usermodification {
6138: my ($position,$dom,$settings,$rowtotal) = @_;
6139: my $numinrow = 4;
6140: my ($context,$datatable,$rowcount);
6141: if ($position eq 'top') {
6142: $rowcount = 0;
6143: $context = 'author';
6144: foreach my $role ('ca','aa') {
6145: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6146: $numinrow,$rowcount);
6147: $$rowtotal ++;
6148: $rowcount ++;
6149: }
1.230 raeburn 6150: } elsif ($position eq 'bottom') {
1.33 raeburn 6151: $context = 'course';
6152: $rowcount = 0;
6153: foreach my $role ('st','ep','ta','in','cr') {
6154: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6155: $numinrow,$rowcount);
6156: $$rowtotal ++;
6157: $rowcount ++;
6158: }
6159: }
6160: return $datatable;
6161: }
6162:
1.43 raeburn 6163: sub print_defaults {
1.236 raeburn 6164: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6165: my $rownum = 0;
1.294 raeburn 6166: my ($datatable,$css_class,$titles);
6167: unless ($position eq 'bottom') {
6168: $titles = &defaults_titles($dom);
6169: }
1.236 raeburn 6170: if ($position eq 'top') {
6171: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6172: 'datelocale_def','portal_def');
6173: my %defaults;
6174: if (ref($settings) eq 'HASH') {
6175: %defaults = %{$settings};
1.43 raeburn 6176: } else {
1.236 raeburn 6177: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6178: foreach my $item (@items) {
6179: $defaults{$item} = $domdefaults{$item};
6180: }
1.43 raeburn 6181: }
1.236 raeburn 6182: foreach my $item (@items) {
6183: if ($rownum%2) {
6184: $css_class = '';
6185: } else {
6186: $css_class = ' class="LC_odd_row" ';
6187: }
6188: $datatable .= '<tr'.$css_class.'>'.
6189: '<td><span class="LC_nobreak">'.$titles->{$item}.
6190: '</span></td><td class="LC_right_item" colspan="3">';
6191: if ($item eq 'auth_def') {
6192: my @authtypes = ('internal','krb4','krb5','localauth');
6193: my %shortauth = (
6194: internal => 'int',
6195: krb4 => 'krb4',
6196: krb5 => 'krb5',
6197: localauth => 'loc'
6198: );
6199: my %authnames = &authtype_names();
6200: foreach my $auth (@authtypes) {
6201: my $checked = ' ';
6202: if ($defaults{$item} eq $auth) {
6203: $checked = ' checked="checked" ';
6204: }
6205: $datatable .= '<label><input type="radio" name="'.$item.
6206: '" value="'.$auth.'"'.$checked.'/>'.
6207: $authnames{$shortauth{$auth}}.'</label> ';
6208: }
6209: } elsif ($item eq 'timezone_def') {
6210: my $includeempty = 1;
6211: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6212: } elsif ($item eq 'datelocale_def') {
6213: my $includeempty = 1;
6214: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6215: } elsif ($item eq 'lang_def') {
1.263 raeburn 6216: my $includeempty = 1;
6217: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 6218: } else {
6219: my $size;
6220: if ($item eq 'portal_def') {
6221: $size = ' size="25"';
6222: }
6223: $datatable .= '<input type="text" name="'.$item.'" value="'.
6224: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 6225: }
1.236 raeburn 6226: $datatable .= '</td></tr>';
6227: $rownum ++;
6228: }
1.294 raeburn 6229: } elsif ($position eq 'middle') {
6230: my @items = ('intauth_cost','intauth_check','intauth_switch');
6231: my %defaults;
6232: if (ref($settings) eq 'HASH') {
6233: %defaults = %{$settings};
6234: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6235: $defaults{'intauth_cost'} = 10;
6236: }
6237: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6238: $defaults{'intauth_check'} = 0;
6239: }
6240: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6241: $defaults{'intauth_switch'} = 0;
6242: }
6243: } else {
6244: %defaults = (
6245: 'intauth_cost' => 10,
6246: 'intauth_check' => 0,
6247: 'intauth_switch' => 0,
6248: );
6249: }
6250: foreach my $item (@items) {
6251: if ($rownum%2) {
6252: $css_class = '';
6253: } else {
6254: $css_class = ' class="LC_odd_row" ';
6255: }
6256: $datatable .= '<tr'.$css_class.'>'.
6257: '<td><span class="LC_nobreak">'.$titles->{$item}.
6258: '</span></td><td class="LC_left_item" colspan="3">';
6259: if ($item eq 'intauth_switch') {
6260: my @options = (0,1,2);
6261: my %optiondesc = &Apache::lonlocal::texthash (
6262: 0 => 'No',
6263: 1 => 'Yes',
6264: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6265: );
6266: $datatable .= '<table width="100%">';
6267: foreach my $option (@options) {
6268: my $checked = ' ';
6269: if ($defaults{$item} eq $option) {
6270: $checked = ' checked="checked"';
6271: }
6272: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6273: '<label><input type="radio" name="'.$item.
6274: '" value="'.$option.'"'.$checked.' />'.
6275: $optiondesc{$option}.'</label></span></td></tr>';
6276: }
6277: $datatable .= '</table>';
6278: } elsif ($item eq 'intauth_check') {
6279: my @options = (0,1,2);
6280: my %optiondesc = &Apache::lonlocal::texthash (
6281: 0 => 'No',
6282: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6283: 2 => 'Yes, disallow login if stored cost is less than domain default',
6284: );
6285: $datatable .= '<table wisth="100%">';
6286: foreach my $option (@options) {
6287: my $checked = ' ';
6288: my $onclick;
6289: if ($defaults{$item} eq $option) {
6290: $checked = ' checked="checked"';
6291: }
6292: if ($option == 2) {
6293: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6294: }
6295: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6296: '<label><input type="radio" name="'.$item.
6297: '" value="'.$option.'"'.$checked.$onclick.' />'.
6298: $optiondesc{$option}.'</label></span></td></tr>';
6299: }
6300: $datatable .= '</table>';
6301: } else {
6302: $datatable .= '<input type="text" name="'.$item.'" value="'.
6303: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6304: }
6305: $datatable .= '</td></tr>';
6306: $rownum ++;
6307: }
1.236 raeburn 6308: } else {
1.294 raeburn 6309: my %defaults;
1.236 raeburn 6310: if (ref($settings) eq 'HASH') {
6311: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
6312: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
6313: my $maxnum = @{$settings->{'inststatusorder'}};
6314: for (my $i=0; $i<$maxnum; $i++) {
6315: $css_class = $rownum%2?' class="LC_odd_row"':'';
6316: my $item = $settings->{'inststatusorder'}->[$i];
6317: my $title = $settings->{'inststatustypes'}->{$item};
6318: my $guestok;
6319: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
6320: $guestok = 1;
6321: }
6322: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6323: $datatable .= '<tr'.$css_class.'>'.
6324: '<td><span class="LC_nobreak">'.
6325: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6326: for (my $k=0; $k<=$maxnum; $k++) {
6327: my $vpos = $k+1;
6328: my $selstr;
6329: if ($k == $i) {
6330: $selstr = ' selected="selected" ';
6331: }
6332: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6333: }
6334: my ($checkedon,$checkedoff);
6335: $checkedoff = ' checked="checked"';
6336: if ($guestok) {
6337: $checkedon = $checkedoff;
6338: $checkedoff = '';
6339: }
6340: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6341: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6342: &mt('delete').'</span></td>'.
6343: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6344: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
6345: '</span></td>'.
6346: '<td class="LC_right_item"><span class="LC_nobreak">'.
6347: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
6348: &mt('Yes').'</label>'.(' 'x2).
6349: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
6350: &mt('No').'</label></span></td></tr>';
6351: }
6352: $css_class = $rownum%2?' class="LC_odd_row"':'';
6353: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6354: $datatable .= '<tr '.$css_class.'>'.
6355: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6356: for (my $k=0; $k<=$maxnum; $k++) {
6357: my $vpos = $k+1;
6358: my $selstr;
6359: if ($k == $maxnum) {
6360: $selstr = ' selected="selected" ';
6361: }
6362: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6363: }
6364: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 6365: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 6366: ' '.&mt('(new)').
6367: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6368: &mt('Name displayed:').
6369: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6370: '<td class="LC_right_item"><span class="LC_nobreak">'.
6371: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
6372: &mt('Yes').'</label>'.(' 'x2).
6373: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
6374: &mt('No').'</label></span></td></tr>';
6375: '</tr>'."\n";
6376: $rownum ++;
1.141 raeburn 6377: }
1.43 raeburn 6378: }
6379: }
6380: $$rowtotal += $rownum;
6381: return $datatable;
6382: }
6383:
1.168 raeburn 6384: sub get_languages_hash {
6385: my %langchoices;
6386: foreach my $id (&Apache::loncommon::languageids()) {
6387: my $code = &Apache::loncommon::supportedlanguagecode($id);
6388: if ($code ne '') {
6389: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6390: }
6391: }
6392: return %langchoices;
6393: }
6394:
1.43 raeburn 6395: sub defaults_titles {
1.141 raeburn 6396: my ($dom) = @_;
1.43 raeburn 6397: my %titles = &Apache::lonlocal::texthash (
6398: 'auth_def' => 'Default authentication type',
6399: 'auth_arg_def' => 'Default authentication argument',
6400: 'lang_def' => 'Default language',
1.54 raeburn 6401: 'timezone_def' => 'Default timezone',
1.68 raeburn 6402: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6403: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 6404: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6405: 'intauth_check' => 'Check bcrypt cost if authenticated',
6406: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6407: );
1.141 raeburn 6408: if ($dom) {
6409: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6410: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6411: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6412: $protocol = 'http' if ($protocol ne 'https');
6413: if ($uint_dom) {
6414: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6415: $uint_dom);
6416: }
6417: }
1.43 raeburn 6418: return (\%titles);
6419: }
6420:
1.46 raeburn 6421: sub print_scantronformat {
6422: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6423: my $itemcount = 1;
1.60 raeburn 6424: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6425: %confhash);
1.46 raeburn 6426: my $switchserver = &check_switchserver($dom,$confname);
6427: my %lt = &Apache::lonlocal::texthash (
1.95 www 6428: default => 'Default bubblesheet format file error',
6429: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6430: );
6431: my %scantronfiles = (
6432: default => 'default.tab',
6433: custom => 'custom.tab',
6434: );
6435: foreach my $key (keys(%scantronfiles)) {
6436: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6437: .$scantronfiles{$key};
6438: }
6439: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6440: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6441: if (!$switchserver) {
6442: my $servadm = $r->dir_config('lonAdmEMail');
6443: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6444: if ($configuserok eq 'ok') {
6445: if ($author_ok eq 'ok') {
6446: my %legacyfile = (
6447: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6448: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6449: );
6450: my %md5chk;
6451: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6452: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6453: chomp($md5chk{$type});
1.46 raeburn 6454: }
6455: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6456: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6457: ($scantronurls{$type},my $error) =
1.46 raeburn 6458: &legacy_scantronformat($r,$dom,$confname,
6459: $type,$legacyfile{$type},
6460: $scantronurls{$type},
6461: $scantronfiles{$type});
1.60 raeburn 6462: if ($error ne '') {
6463: $error{$type} = $error;
6464: }
6465: }
6466: if (keys(%error) == 0) {
6467: $is_custom = 1;
6468: $confhash{'scantron'}{'scantronformat'} =
6469: $scantronurls{'custom'};
6470: my $putresult =
6471: &Apache::lonnet::put_dom('configuration',
6472: \%confhash,$dom);
6473: if ($putresult ne 'ok') {
6474: $error{'custom'} =
6475: '<span class="LC_error">'.
6476: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6477: }
1.46 raeburn 6478: }
6479: } else {
1.60 raeburn 6480: ($scantronurls{'default'},my $error) =
1.46 raeburn 6481: &legacy_scantronformat($r,$dom,$confname,
6482: 'default',$legacyfile{'default'},
6483: $scantronurls{'default'},
6484: $scantronfiles{'default'});
1.60 raeburn 6485: if ($error eq '') {
6486: $confhash{'scantron'}{'scantronformat'} = '';
6487: my $putresult =
6488: &Apache::lonnet::put_dom('configuration',
6489: \%confhash,$dom);
6490: if ($putresult ne 'ok') {
6491: $error{'default'} =
6492: '<span class="LC_error">'.
6493: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6494: }
6495: } else {
6496: $error{'default'} = $error;
6497: }
1.46 raeburn 6498: }
6499: }
6500: }
6501: } else {
1.95 www 6502: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6503: }
6504: }
6505: if (ref($settings) eq 'HASH') {
6506: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6507: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6508: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6509: $scantronurl = '';
6510: } else {
6511: $scantronurl = $settings->{'scantronformat'};
6512: }
6513: $is_custom = 1;
6514: } else {
6515: $scantronurl = $scantronurls{'default'};
6516: }
6517: } else {
1.60 raeburn 6518: if ($is_custom) {
6519: $scantronurl = $scantronurls{'custom'};
6520: } else {
6521: $scantronurl = $scantronurls{'default'};
6522: }
1.46 raeburn 6523: }
6524: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6525: $datatable .= '<tr'.$css_class.'>';
6526: if (!$is_custom) {
1.65 raeburn 6527: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6528: '<span class="LC_nobreak">';
1.46 raeburn 6529: if ($scantronurl) {
1.199 raeburn 6530: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6531: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6532: } else {
6533: $datatable = &mt('File unavailable for display');
6534: }
1.65 raeburn 6535: $datatable .= '</span></td>';
1.60 raeburn 6536: if (keys(%error) == 0) {
6537: $datatable .= '<td valign="bottom">';
6538: if (!$switchserver) {
6539: $datatable .= &mt('Upload:').'<br />';
6540: }
6541: } else {
6542: my $errorstr;
6543: foreach my $key (sort(keys(%error))) {
6544: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6545: }
6546: $datatable .= '<td>'.$errorstr;
6547: }
1.46 raeburn 6548: } else {
6549: if (keys(%error) > 0) {
6550: my $errorstr;
6551: foreach my $key (sort(keys(%error))) {
6552: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6553: }
1.60 raeburn 6554: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6555: } elsif ($scantronurl) {
1.199 raeburn 6556: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
6557: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6558: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 6559: $link.
6560: '<label><input type="checkbox" name="scantronformat_del"'.
6561: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6562: '<td><span class="LC_nobreak"> '.
6563: &mt('Replace:').'</span><br />';
1.46 raeburn 6564: }
6565: }
6566: if (keys(%error) == 0) {
6567: if ($switchserver) {
6568: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6569: } else {
1.65 raeburn 6570: $datatable .='<span class="LC_nobreak"> '.
6571: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6572: }
6573: }
6574: $datatable .= '</td></tr>';
6575: $$rowtotal ++;
6576: return $datatable;
6577: }
6578:
6579: sub legacy_scantronformat {
6580: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6581: my ($url,$error);
6582: my @statinfo = &Apache::lonnet::stat_file($newurl);
6583: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6584: (my $result,$url) =
6585: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6586: '','',$newfile);
6587: if ($result ne 'ok') {
1.130 raeburn 6588: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6589: }
6590: }
6591: return ($url,$error);
6592: }
1.43 raeburn 6593:
1.49 raeburn 6594: sub print_coursecategories {
1.57 raeburn 6595: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6596: my $datatable;
6597: if ($position eq 'top') {
1.238 raeburn 6598: my (%checked);
6599: my @catitems = ('unauth','auth');
6600: my @cattypes = ('std','domonly','codesrch','none');
6601: $checked{'unauth'} = 'std';
6602: $checked{'auth'} = 'std';
6603: if (ref($settings) eq 'HASH') {
6604: foreach my $type (@cattypes) {
6605: if ($type eq $settings->{'unauth'}) {
6606: $checked{'unauth'} = $type;
6607: }
6608: if ($type eq $settings->{'auth'}) {
6609: $checked{'auth'} = $type;
6610: }
6611: }
6612: }
6613: my %lt = &Apache::lonlocal::texthash (
6614: unauth => 'Catalog type for unauthenticated users',
6615: auth => 'Catalog type for authenticated users',
6616: none => 'No catalog',
6617: std => 'Standard catalog',
6618: domonly => 'Domain-only catalog',
6619: codesrch => "Code search form",
6620: );
6621: my $itemcount = 0;
6622: foreach my $item (@catitems) {
6623: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6624: $datatable .= '<tr '.$css_class.'>'.
6625: '<td>'.$lt{$item}.'</td>'.
6626: '<td class="LC_right_item"><span class="LC_nobreak">';
6627: foreach my $type (@cattypes) {
6628: my $ischecked;
6629: if ($checked{$item} eq $type) {
6630: $ischecked=' checked="checked"';
6631: }
6632: $datatable .= '<label>'.
6633: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6634: ' />'.$lt{$type}.'</label> ';
6635: }
6636: $datatable .= '</td></tr>';
6637: $itemcount ++;
6638: }
6639: $$rowtotal += $itemcount;
6640: } elsif ($position eq 'middle') {
1.57 raeburn 6641: my $toggle_cats_crs = ' ';
6642: my $toggle_cats_dom = ' checked="checked" ';
6643: my $can_cat_crs = ' ';
6644: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6645: my $toggle_catscomm_comm = ' ';
6646: my $toggle_catscomm_dom = ' checked="checked" ';
6647: my $can_catcomm_comm = ' ';
6648: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 6649: my $toggle_catsplace_place = ' ';
6650: my $toggle_catsplace_dom = ' checked="checked" ';
6651: my $can_catplace_place = ' ';
6652: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 6653:
1.57 raeburn 6654: if (ref($settings) eq 'HASH') {
6655: if ($settings->{'togglecats'} eq 'crs') {
6656: $toggle_cats_crs = $toggle_cats_dom;
6657: $toggle_cats_dom = ' ';
6658: }
6659: if ($settings->{'categorize'} eq 'crs') {
6660: $can_cat_crs = $can_cat_dom;
6661: $can_cat_dom = ' ';
6662: }
1.120 raeburn 6663: if ($settings->{'togglecatscomm'} eq 'comm') {
6664: $toggle_catscomm_comm = $toggle_catscomm_dom;
6665: $toggle_catscomm_dom = ' ';
6666: }
6667: if ($settings->{'categorizecomm'} eq 'comm') {
6668: $can_catcomm_comm = $can_catcomm_dom;
6669: $can_catcomm_dom = ' ';
6670: }
1.272 raeburn 6671: if ($settings->{'togglecatsplace'} eq 'place') {
6672: $toggle_catsplace_place = $toggle_catsplace_dom;
6673: $toggle_catsplace_dom = ' ';
6674: }
6675: if ($settings->{'categorizeplace'} eq 'place') {
6676: $can_catplace_place = $can_catplace_dom;
6677: $can_catplace_dom = ' ';
6678: }
1.57 raeburn 6679: }
6680: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 6681: togglecats => 'Show/Hide a course in catalog',
6682: togglecatscomm => 'Show/Hide a community in catalog',
6683: togglecatsplace => 'Show/Hide a placement test in catalog',
6684: categorize => 'Assign a category to a course',
6685: categorizecomm => 'Assign a category to a community',
6686: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 6687: );
6688: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 6689: dom => 'Set in Domain',
6690: crs => 'Set in Course',
6691: comm => 'Set in Community',
6692: place => 'Set in Placement Test',
1.57 raeburn 6693: );
6694: $datatable = '<tr class="LC_odd_row">'.
6695: '<td>'.$title{'togglecats'}.'</td>'.
6696: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6697: '<input type="radio" name="togglecats"'.
6698: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6699: '<label><input type="radio" name="togglecats"'.
6700: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6701: '</tr><tr>'.
6702: '<td>'.$title{'categorize'}.'</td>'.
6703: '<td class="LC_right_item"><span class="LC_nobreak">'.
6704: '<label><input type="radio" name="categorize"'.
6705: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6706: '<label><input type="radio" name="categorize"'.
6707: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6708: '</tr><tr class="LC_odd_row">'.
6709: '<td>'.$title{'togglecatscomm'}.'</td>'.
6710: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6711: '<input type="radio" name="togglecatscomm"'.
6712: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6713: '<label><input type="radio" name="togglecatscomm"'.
6714: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6715: '</tr><tr>'.
6716: '<td>'.$title{'categorizecomm'}.'</td>'.
6717: '<td class="LC_right_item"><span class="LC_nobreak">'.
6718: '<label><input type="radio" name="categorizecomm"'.
6719: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6720: '<label><input type="radio" name="categorizecomm"'.
6721: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 6722: '</tr><tr>'.
6723: '<td>'.$title{'togglecatsplace'}.'</td>'.
6724: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6725: '<input type="radio" name="togglecatsplace"'.
6726: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6727: '<label><input type="radio" name="togglecatscomm"'.
6728: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
6729: '</tr><tr>'.
6730: '<td>'.$title{'categorizeplace'}.'</td>'.
6731: '<td class="LC_right_item"><span class="LC_nobreak">'.
6732: '<label><input type="radio" name="categorizeplace"'.
6733: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6734: '<label><input type="radio" name="categorizeplace"'.
6735: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 6736: '</tr>';
1.272 raeburn 6737: $$rowtotal += 6;
1.57 raeburn 6738: } else {
6739: my $css_class;
6740: my $itemcount = 1;
6741: my $cathash;
6742: if (ref($settings) eq 'HASH') {
6743: $cathash = $settings->{'cats'};
6744: }
6745: if (ref($cathash) eq 'HASH') {
6746: my (@cats,@trails,%allitems,%idx,@jsarray);
6747: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6748: \%allitems,\%idx,\@jsarray);
6749: my $maxdepth = scalar(@cats);
6750: my $colattrib = '';
6751: if ($maxdepth > 2) {
6752: $colattrib = ' colspan="2" ';
6753: }
6754: my @path;
6755: if (@cats > 0) {
6756: if (ref($cats[0]) eq 'ARRAY') {
6757: my $numtop = @{$cats[0]};
6758: my $maxnum = $numtop;
1.120 raeburn 6759: my %default_names = (
6760: instcode => &mt('Official courses'),
6761: communities => &mt('Communities'),
1.272 raeburn 6762: placement => &mt('Placement Tests'),
1.120 raeburn 6763: );
6764:
6765: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6766: ($cathash->{'instcode::0'} eq '') ||
6767: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 6768: ($cathash->{'communities::0'} eq '') ||
6769: (!grep(/^placement$/,@{$cats[0]})) ||
6770: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 6771: $maxnum ++;
6772: }
6773: my $lastidx;
6774: for (my $i=0; $i<$numtop; $i++) {
6775: my $parent = $cats[0][$i];
6776: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6777: my $item = &escape($parent).'::0';
6778: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6779: $lastidx = $idx{$item};
6780: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6781: .'<select name="'.$item.'"'.$chgstr.'>';
6782: for (my $k=0; $k<=$maxnum; $k++) {
6783: my $vpos = $k+1;
6784: my $selstr;
6785: if ($k == $i) {
6786: $selstr = ' selected="selected" ';
6787: }
6788: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6789: }
1.214 raeburn 6790: $datatable .= '</select></span></td><td>';
1.272 raeburn 6791: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 6792: $datatable .= '<span class="LC_nobreak">'
6793: .$default_names{$parent}.'</span>';
6794: if ($parent eq 'instcode') {
6795: $datatable .= '<br /><span class="LC_nobreak">('
6796: .&mt('with institutional codes')
6797: .')</span></td><td'.$colattrib.'>';
6798: } else {
6799: $datatable .= '<table><tr><td>';
6800: }
6801: $datatable .= '<span class="LC_nobreak">'
6802: .'<label><input type="radio" name="'
6803: .$parent.'" value="1" checked="checked" />'
6804: .&mt('Display').'</label>';
6805: if ($parent eq 'instcode') {
6806: $datatable .= ' ';
6807: } else {
6808: $datatable .= '</span></td></tr><tr><td>'
6809: .'<span class="LC_nobreak">';
6810: }
6811: $datatable .= '<label><input type="radio" name="'
6812: .$parent.'" value="0" />'
6813: .&mt('Do not display').'</label></span>';
1.272 raeburn 6814: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 6815: $datatable .= '</td></tr></table>';
6816: }
6817: $datatable .= '</td>';
1.57 raeburn 6818: } else {
6819: $datatable .= $parent
1.214 raeburn 6820: .' <span class="LC_nobreak"><label>'
6821: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6822: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6823: }
6824: my $depth = 1;
6825: push(@path,$parent);
6826: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6827: pop(@path);
6828: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6829: $itemcount ++;
6830: }
1.48 raeburn 6831: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6832: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6833: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6834: for (my $k=0; $k<=$maxnum; $k++) {
6835: my $vpos = $k+1;
6836: my $selstr;
1.57 raeburn 6837: if ($k == $numtop) {
1.48 raeburn 6838: $selstr = ' selected="selected" ';
6839: }
6840: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6841: }
1.59 bisitz 6842: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6843: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6844: .'</tr>'."\n";
1.48 raeburn 6845: $itemcount ++;
1.272 raeburn 6846: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6847: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6848: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6849: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6850: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6851: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6852: for (my $k=0; $k<=$maxnum; $k++) {
6853: my $vpos = $k+1;
6854: my $selstr;
6855: if ($k == $maxnum) {
6856: $selstr = ' selected="selected" ';
6857: }
6858: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6859: }
1.120 raeburn 6860: $datatable .= '</select></span></td>'.
6861: '<td><span class="LC_nobreak">'.
6862: $default_names{$default}.'</span>';
6863: if ($default eq 'instcode') {
6864: $datatable .= '<br /><span class="LC_nobreak">('
6865: .&mt('with institutional codes').')</span>';
6866: }
6867: $datatable .= '</td>'
6868: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6869: .&mt('Display').'</label> '
6870: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6871: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6872: }
6873: }
6874: }
1.57 raeburn 6875: } else {
6876: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6877: }
6878: } else {
1.238 raeburn 6879: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6880: .&initialize_categories($itemcount);
1.48 raeburn 6881: }
1.57 raeburn 6882: $$rowtotal += $itemcount;
1.48 raeburn 6883: }
6884: return $datatable;
6885: }
6886:
1.69 raeburn 6887: sub print_serverstatuses {
6888: my ($dom,$settings,$rowtotal) = @_;
6889: my $datatable;
6890: my @pages = &serverstatus_pages();
6891: my (%namedaccess,%machineaccess);
6892: foreach my $type (@pages) {
6893: $namedaccess{$type} = '';
6894: $machineaccess{$type}= '';
6895: }
6896: if (ref($settings) eq 'HASH') {
6897: foreach my $type (@pages) {
6898: if (exists($settings->{$type})) {
6899: if (ref($settings->{$type}) eq 'HASH') {
6900: foreach my $key (keys(%{$settings->{$type}})) {
6901: if ($key eq 'namedusers') {
6902: $namedaccess{$type} = $settings->{$type}->{$key};
6903: } elsif ($key eq 'machines') {
6904: $machineaccess{$type} = $settings->{$type}->{$key};
6905: }
6906: }
6907: }
6908: }
6909: }
6910: }
1.81 raeburn 6911: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6912: my $rownum = 0;
6913: my $css_class;
6914: foreach my $type (@pages) {
6915: $rownum ++;
6916: $css_class = $rownum%2?' class="LC_odd_row"':'';
6917: $datatable .= '<tr'.$css_class.'>'.
6918: '<td><span class="LC_nobreak">'.
6919: $titles->{$type}.'</span></td>'.
6920: '<td class="LC_left_item">'.
6921: '<input type="text" name="'.$type.'_namedusers" '.
6922: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6923: '<td class="LC_right_item">'.
6924: '<span class="LC_nobreak">'.
6925: '<input type="text" name="'.$type.'_machines" '.
6926: 'value="'.$machineaccess{$type}.'" size="10" />'.
6927: '</td></tr>'."\n";
6928: }
6929: $$rowtotal += $rownum;
6930: return $datatable;
6931: }
6932:
6933: sub serverstatus_pages {
6934: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 6935: 'checksums','clusterstatus','certstatus','metadata_keywords',
6936: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
6937: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6938: }
6939:
1.236 raeburn 6940: sub defaults_javascript {
6941: my ($settings) = @_;
1.294 raeburn 6942: 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.');
6943: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6944: &js_escape(\$intauthcheck);
6945: &js_escape(\$intauthcost);
6946: my $intauthjs = <<"ENDSCRIPT";
6947:
6948: function warnIntAuth(field) {
6949: if (field.name == 'intauth_check') {
6950: if (field.value == '2') {
6951: alert('$intauthcheck');
6952: }
6953: }
6954: if (field.name == 'intauth_cost') {
6955: field.value.replace(/\s/g,'');
6956: if (field.value != '') {
6957: var regexdigit=/^\\d+\$/;
6958: if (!regexdigit.test(field.value)) {
6959: alert('$intauthcost');
6960: }
6961: }
6962: }
6963: return;
6964: }
6965:
6966: ENDSCRIPT
6967:
6968: if (ref($settings) ne 'HASH') {
6969: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6970: }
1.236 raeburn 6971: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6972: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6973: if ($maxnum eq '') {
6974: $maxnum = 0;
6975: }
6976: $maxnum ++;
1.249 raeburn 6977: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6978: return <<"ENDSCRIPT";
6979: <script type="text/javascript">
6980: // <![CDATA[
6981: function reorderTypes(form,caller) {
6982: var changedVal;
6983: $jstext
6984: var newpos = 'addinststatus_pos';
6985: var current = new Array;
6986: var maxh = $maxnum;
6987: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6988: var oldVal;
6989: if (caller == newpos) {
6990: changedVal = newitemVal;
6991: } else {
6992: var curritem = 'inststatus_pos_'+caller;
6993: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6994: current[newitemVal] = newpos;
6995: }
6996: for (var i=0; i<inststatuses.length; i++) {
6997: if (inststatuses[i] != caller) {
6998: var elementName = 'inststatus_pos_'+inststatuses[i];
6999: if (form.elements[elementName]) {
7000: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7001: current[currVal] = elementName;
7002: }
7003: }
7004: }
7005: for (var j=0; j<maxh; j++) {
7006: if (current[j] == undefined) {
7007: oldVal = j;
7008: }
7009: }
7010: if (oldVal < changedVal) {
7011: for (var k=oldVal+1; k<=changedVal ; k++) {
7012: var elementName = current[k];
7013: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7014: }
7015: } else {
7016: for (var k=changedVal; k<oldVal; k++) {
7017: var elementName = current[k];
7018: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7019: }
7020: }
7021: return;
7022: }
7023:
1.294 raeburn 7024: $intauthjs
7025:
1.236 raeburn 7026: // ]]>
7027: </script>
7028:
7029: ENDSCRIPT
1.294 raeburn 7030: } else {
7031: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 7032: }
7033: }
7034:
1.49 raeburn 7035: sub coursecategories_javascript {
7036: my ($settings) = @_;
1.57 raeburn 7037: my ($output,$jstext,$cathash);
1.49 raeburn 7038: if (ref($settings) eq 'HASH') {
1.57 raeburn 7039: $cathash = $settings->{'cats'};
7040: }
7041: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7042: my (@cats,@jsarray,%idx);
1.57 raeburn 7043: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7044: if (@jsarray > 0) {
7045: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7046: for (my $i=0; $i<@jsarray; $i++) {
7047: if (ref($jsarray[$i]) eq 'ARRAY') {
7048: my $catstr = join('","',@{$jsarray[$i]});
7049: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7050: }
7051: }
7052: }
7053: } else {
7054: $jstext = ' var categories = Array(1);'."\n".
7055: ' categories[0] = Array("instcode_pos");'."\n";
7056: }
1.237 bisitz 7057: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7058: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 7059: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 7060: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7061: &js_escape(\$instcode_reserved);
7062: &js_escape(\$communities_reserved);
1.272 raeburn 7063: &js_escape(\$placement_reserved);
1.265 damieng 7064: &js_escape(\$choose_again);
1.49 raeburn 7065: $output = <<"ENDSCRIPT";
7066: <script type="text/javascript">
1.109 raeburn 7067: // <![CDATA[
1.49 raeburn 7068: function reorderCats(form,parent,item,idx) {
7069: var changedVal;
7070: $jstext
7071: var newpos = 'addcategory_pos';
7072: if (parent == '') {
7073: var has_instcode = 0;
7074: var maxtop = categories[idx].length;
7075: for (var j=0; j<maxtop; j++) {
7076: if (categories[idx][j] == 'instcode::0') {
7077: has_instcode == 1;
7078: }
7079: }
7080: if (has_instcode == 0) {
7081: categories[idx][maxtop] = 'instcode_pos';
7082: }
7083: } else {
7084: newpos += '_'+parent;
7085: }
7086: var maxh = 1 + categories[idx].length;
7087: var current = new Array;
7088: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7089: if (item == newpos) {
7090: changedVal = newitemVal;
7091: } else {
7092: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7093: current[newitemVal] = newpos;
7094: }
7095: for (var i=0; i<categories[idx].length; i++) {
7096: var elementName = categories[idx][i];
7097: if (elementName != item) {
7098: if (form.elements[elementName]) {
7099: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7100: current[currVal] = elementName;
7101: }
7102: }
7103: }
7104: var oldVal;
7105: for (var j=0; j<maxh; j++) {
7106: if (current[j] == undefined) {
7107: oldVal = j;
7108: }
7109: }
7110: if (oldVal < changedVal) {
7111: for (var k=oldVal+1; k<=changedVal ; k++) {
7112: var elementName = current[k];
7113: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7114: }
7115: } else {
7116: for (var k=changedVal; k<oldVal; k++) {
7117: var elementName = current[k];
7118: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7119: }
7120: }
7121: return;
7122: }
1.120 raeburn 7123:
7124: function categoryCheck(form) {
7125: if (form.elements['addcategory_name'].value == 'instcode') {
7126: alert('$instcode_reserved\\n$choose_again');
7127: return false;
7128: }
7129: if (form.elements['addcategory_name'].value == 'communities') {
7130: alert('$communities_reserved\\n$choose_again');
7131: return false;
7132: }
1.272 raeburn 7133: if (form.elements['addcategory_name'].value == 'placement') {
7134: alert('$placement_reserved\\n$choose_again');
7135: return false;
7136: }
1.120 raeburn 7137: return true;
7138: }
7139:
1.109 raeburn 7140: // ]]>
1.49 raeburn 7141: </script>
7142:
7143: ENDSCRIPT
7144: return $output;
7145: }
7146:
1.48 raeburn 7147: sub initialize_categories {
7148: my ($itemcount) = @_;
1.120 raeburn 7149: my ($datatable,$css_class,$chgstr);
7150: my %default_names = (
7151: instcode => 'Official courses (with institutional codes)',
7152: communities => 'Communities',
1.272 raeburn 7153: placement => 'Placement Tests',
1.120 raeburn 7154: );
7155: my $select0 = ' selected="selected"';
7156: my $select1 = '';
1.272 raeburn 7157: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7158: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7159: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 7160: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 7161: $select1 = $select0;
7162: $select0 = '';
7163: }
7164: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7165: .'<select name="'.$default.'_pos">'
7166: .'<option value="0"'.$select0.'>1</option>'
7167: .'<option value="1"'.$select1.'>2</option>'
7168: .'<option value="2">3</option></select> '
7169: .$default_names{$default}
7170: .'</span></td><td><span class="LC_nobreak">'
7171: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7172: .&mt('Display').'</label> <label>'
7173: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7174: .'</label></span></td></tr>';
1.120 raeburn 7175: $itemcount ++;
7176: }
1.48 raeburn 7177: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7178: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7179: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7180: .'<select name="addcategory_pos"'.$chgstr.'>'
7181: .'<option value="0">1</option>'
7182: .'<option value="1">2</option>'
7183: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 7184: .&mt('Add category').'</td><td>'.&mt('Name:')
7185: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
7186: return $datatable;
7187: }
7188:
7189: sub build_category_rows {
1.49 raeburn 7190: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7191: my ($text,$name,$item,$chgstr);
1.48 raeburn 7192: if (ref($cats) eq 'ARRAY') {
7193: my $maxdepth = scalar(@{$cats});
7194: if (ref($cats->[$depth]) eq 'HASH') {
7195: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7196: my $numchildren = @{$cats->[$depth]{$parent}};
7197: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 7198: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7199: my ($idxnum,$parent_name,$parent_item);
7200: my $higher = $depth - 1;
7201: if ($higher == 0) {
7202: $parent_name = &escape($parent).'::'.$higher;
7203: } else {
7204: if (ref($path) eq 'ARRAY') {
7205: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7206: }
7207: }
7208: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7209: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7210: if ($j < $numchildren) {
1.48 raeburn 7211: $name = $cats->[$depth]{$parent}[$j];
7212: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7213: $idxnum = $idx->{$item};
7214: } else {
7215: $name = $parent_name;
7216: $item = $parent_item;
1.48 raeburn 7217: }
1.49 raeburn 7218: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7219: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7220: for (my $i=0; $i<=$numchildren; $i++) {
7221: my $vpos = $i+1;
7222: my $selstr;
7223: if ($j == $i) {
7224: $selstr = ' selected="selected" ';
7225: }
7226: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7227: }
7228: $text .= '</select> ';
7229: if ($j < $numchildren) {
7230: my $deeper = $depth+1;
7231: $text .= $name.' '
7232: .'<label><input type="checkbox" name="deletecategory" value="'
7233: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7234: if(ref($path) eq 'ARRAY') {
7235: push(@{$path},$name);
1.49 raeburn 7236: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7237: pop(@{$path});
7238: }
7239: } else {
1.59 bisitz 7240: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 7241: if ($j == $numchildren) {
7242: $text .= $name;
7243: } else {
7244: $text .= $item;
7245: }
7246: $text .= '" value="" />';
7247: }
7248: $text .= '</td></tr>';
7249: }
7250: $text .= '</table></td>';
7251: } else {
7252: my $higher = $depth-1;
7253: if ($higher == 0) {
7254: $name = &escape($parent).'::'.$higher;
7255: } else {
7256: if (ref($path) eq 'ARRAY') {
7257: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7258: }
7259: }
7260: my $colspan;
7261: if ($parent ne 'instcode') {
7262: $colspan = $maxdepth - $depth - 1;
7263: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7264: }
7265: }
7266: }
7267: }
7268: return $text;
7269: }
7270:
1.33 raeburn 7271: sub modifiable_userdata_row {
1.228 raeburn 7272: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
7273: my ($role,$rolename,$statustype);
7274: $role = $item;
1.224 raeburn 7275: if ($context eq 'cancreate') {
1.228 raeburn 7276: if ($item =~ /^emailusername_(.+)$/) {
7277: $statustype = $1;
7278: $role = 'emailusername';
7279: if (ref($usertypes) eq 'HASH') {
7280: if ($usertypes->{$statustype}) {
7281: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7282: } else {
7283: $rolename = &mt('Data provided by user');
7284: }
7285: }
1.224 raeburn 7286: }
7287: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7288: if (ref($usertypes) eq 'HASH') {
7289: $rolename = $usertypes->{$role};
7290: } else {
7291: $rolename = $role;
7292: }
1.33 raeburn 7293: } else {
1.63 raeburn 7294: if ($role eq 'cr') {
7295: $rolename = &mt('Custom role');
7296: } else {
7297: $rolename = &Apache::lonnet::plaintext($role);
7298: }
1.33 raeburn 7299: }
1.224 raeburn 7300: my (@fields,%fieldtitles);
7301: if (ref($fieldsref) eq 'ARRAY') {
7302: @fields = @{$fieldsref};
7303: } else {
7304: @fields = ('lastname','firstname','middlename','generation',
7305: 'permanentemail','id');
7306: }
7307: if ((ref($titlesref) eq 'HASH')) {
7308: %fieldtitles = %{$titlesref};
7309: } else {
7310: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7311: }
1.33 raeburn 7312: my $output;
7313: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7314: $output = '<tr '.$css_class.'>'.
7315: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7316: '<td class="LC_left_item" colspan="2"><table>';
7317: my $rem;
7318: my %checks;
7319: if (ref($settings) eq 'HASH') {
7320: if (ref($settings->{$context}) eq 'HASH') {
7321: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 7322: my $hashref = $settings->{$context}->{$role};
7323: if ($role eq 'emailusername') {
7324: if ($statustype) {
7325: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7326: $hashref = $settings->{$context}->{$role}->{$statustype};
7327: if (ref($hashref) eq 'HASH') {
7328: foreach my $field (@fields) {
7329: if ($hashref->{$field}) {
7330: $checks{$field} = $hashref->{$field};
7331: }
7332: }
7333: }
7334: }
7335: }
7336: } else {
7337: if (ref($hashref) eq 'HASH') {
7338: foreach my $field (@fields) {
7339: if ($hashref->{$field}) {
7340: $checks{$field} = ' checked="checked" ';
7341: }
7342: }
1.33 raeburn 7343: }
7344: }
7345: }
7346: }
7347: }
1.228 raeburn 7348:
1.33 raeburn 7349: for (my $i=0; $i<@fields; $i++) {
7350: my $rem = $i%($numinrow);
7351: if ($rem == 0) {
7352: if ($i > 0) {
7353: $output .= '</tr>';
7354: }
7355: $output .= '<tr>';
7356: }
7357: my $check = ' ';
1.228 raeburn 7358: unless ($role eq 'emailusername') {
7359: if (exists($checks{$fields[$i]})) {
7360: $check = $checks{$fields[$i]}
7361: } else {
7362: if ($role eq 'st') {
7363: if (ref($settings) ne 'HASH') {
7364: $check = ' checked="checked" ';
7365: }
1.33 raeburn 7366: }
7367: }
7368: }
7369: $output .= '<td class="LC_left_item">'.
1.228 raeburn 7370: '<span class="LC_nobreak">';
7371: if ($role eq 'emailusername') {
7372: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7373: $checks{$fields[$i]} = 'omit';
7374: }
7375: foreach my $option ('required','optional','omit') {
7376: my $checked='';
7377: if ($checks{$fields[$i]} eq $option) {
7378: $checked='checked="checked" ';
7379: }
7380: $output .= '<label>'.
7381: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7382: &mt($option).'</label>'.(' ' x2);
7383: }
7384: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7385: } else {
7386: $output .= '<label>'.
7387: '<input type="checkbox" name="canmodify_'.$role.'" '.
7388: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7389: '</label>';
7390: }
7391: $output .= '</span></td>';
1.33 raeburn 7392: $rem = @fields%($numinrow);
7393: }
7394: my $colsleft = $numinrow - $rem;
7395: if ($colsleft > 1 ) {
7396: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7397: ' </td>';
7398: } elsif ($colsleft == 1) {
7399: $output .= '<td class="LC_left_item"> </td>';
7400: }
7401: $output .= '</tr></table></td></tr>';
7402: return $output;
7403: }
1.28 raeburn 7404:
1.93 raeburn 7405: sub insttypes_row {
1.224 raeburn 7406: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 7407: my %lt = &Apache::lonlocal::texthash (
7408: cansearch => 'Users allowed to search',
7409: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7410: lockablenames => 'User preference to lock name',
1.93 raeburn 7411: );
7412: my $showdom;
7413: if ($context eq 'cansearch') {
7414: $showdom = ' ('.$dom.')';
7415: }
1.165 raeburn 7416: my $class = 'LC_left_item';
7417: if ($context eq 'statustocreate') {
7418: $class = 'LC_right_item';
7419: }
1.224 raeburn 7420: my $css_class = ' class="LC_odd_row"';
7421: if ($rownum ne '') {
7422: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
7423: }
7424: my $output = '<tr'.$css_class.'>'.
7425: '<td>'.$lt{$context}.$showdom.
7426: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7427: my $rem;
7428: if (ref($types) eq 'ARRAY') {
7429: for (my $i=0; $i<@{$types}; $i++) {
7430: if (defined($usertypes->{$types->[$i]})) {
7431: my $rem = $i%($numinrow);
7432: if ($rem == 0) {
7433: if ($i > 0) {
7434: $output .= '</tr>';
7435: }
7436: $output .= '<tr>';
1.23 raeburn 7437: }
1.26 raeburn 7438: my $check = ' ';
1.99 raeburn 7439: if (ref($settings) eq 'HASH') {
7440: if (ref($settings->{$context}) eq 'ARRAY') {
7441: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7442: $check = ' checked="checked" ';
7443: }
7444: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7445: $check = ' checked="checked" ';
7446: }
1.23 raeburn 7447: }
1.26 raeburn 7448: $output .= '<td class="LC_left_item">'.
7449: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7450: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 7451: 'value="'.$types->[$i].'"'.$check.'/>'.
7452: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7453: }
7454: }
1.26 raeburn 7455: $rem = @{$types}%($numinrow);
1.23 raeburn 7456: }
7457: my $colsleft = $numinrow - $rem;
1.131 raeburn 7458: if (($rem == 0) && (@{$types} > 0)) {
7459: $output .= '<tr>';
7460: }
1.23 raeburn 7461: if ($colsleft > 1) {
1.25 raeburn 7462: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7463: } else {
1.25 raeburn 7464: $output .= '<td class="LC_left_item">';
1.23 raeburn 7465: }
7466: my $defcheck = ' ';
1.99 raeburn 7467: if (ref($settings) eq 'HASH') {
7468: if (ref($settings->{$context}) eq 'ARRAY') {
7469: if (grep(/^default$/,@{$settings->{$context}})) {
7470: $defcheck = ' checked="checked" ';
7471: }
7472: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7473: $defcheck = ' checked="checked" ';
7474: }
1.23 raeburn 7475: }
1.25 raeburn 7476: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7477: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 7478: 'value="default"'.$defcheck.'/>'.
7479: $othertitle.'</label></span></td>'.
7480: '</tr></table></td></tr>';
7481: return $output;
1.23 raeburn 7482: }
7483:
7484: sub sorted_searchtitles {
7485: my %searchtitles = &Apache::lonlocal::texthash(
7486: 'uname' => 'username',
7487: 'lastname' => 'last name',
7488: 'lastfirst' => 'last name, first name',
7489: );
7490: my @titleorder = ('uname','lastname','lastfirst');
7491: return (\%searchtitles,\@titleorder);
7492: }
7493:
1.25 raeburn 7494: sub sorted_searchtypes {
7495: my %srchtypes_desc = (
7496: exact => 'is exact match',
7497: contains => 'contains ..',
7498: begins => 'begins with ..',
7499: );
7500: my @srchtypeorder = ('exact','begins','contains');
7501: return (\%srchtypes_desc,\@srchtypeorder);
7502: }
7503:
1.3 raeburn 7504: sub usertype_update_row {
7505: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7506: my $datatable;
7507: my $numinrow = 4;
7508: foreach my $type (@{$types}) {
7509: if (defined($usertypes->{$type})) {
7510: $$rownums ++;
7511: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7512: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7513: '</td><td class="LC_left_item"><table>';
7514: for (my $i=0; $i<@{$fields}; $i++) {
7515: my $rem = $i%($numinrow);
7516: if ($rem == 0) {
7517: if ($i > 0) {
7518: $datatable .= '</tr>';
7519: }
7520: $datatable .= '<tr>';
7521: }
7522: my $check = ' ';
1.39 raeburn 7523: if (ref($settings) eq 'HASH') {
7524: if (ref($settings->{'fields'}) eq 'HASH') {
7525: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7526: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7527: $check = ' checked="checked" ';
7528: }
1.3 raeburn 7529: }
7530: }
7531: }
7532:
7533: if ($i == @{$fields}-1) {
7534: my $colsleft = $numinrow - $rem;
7535: if ($colsleft > 1) {
7536: $datatable .= '<td colspan="'.$colsleft.'">';
7537: } else {
7538: $datatable .= '<td>';
7539: }
7540: } else {
7541: $datatable .= '<td>';
7542: }
1.8 raeburn 7543: $datatable .= '<span class="LC_nobreak"><label>'.
7544: '<input type="checkbox" name="updateable_'.$type.
7545: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7546: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7547: }
7548: $datatable .= '</tr></table></td></tr>';
7549: }
7550: }
7551: return $datatable;
1.1 raeburn 7552: }
7553:
7554: sub modify_login {
1.205 raeburn 7555: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 7556: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7557: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7558: %title = ( coursecatalog => 'Display course catalog',
7559: adminmail => 'Display administrator E-mail address',
1.188 raeburn 7560: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 7561: newuser => 'Link for visitors to create a user account',
7562: loginheader => 'Log-in box header');
7563: @offon = ('off','on');
1.112 raeburn 7564: if (ref($domconfig{login}) eq 'HASH') {
7565: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7566: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7567: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7568: }
7569: }
7570: }
1.9 raeburn 7571: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7572: \%domconfig,\%loginhash);
1.188 raeburn 7573: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7574: foreach my $item (@toggles) {
7575: $loginhash{login}{$item} = $env{'form.'.$item};
7576: }
1.41 raeburn 7577: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7578: if (ref($colchanges{'login'}) eq 'HASH') {
7579: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7580: \%loginhash);
7581: }
1.110 raeburn 7582:
1.149 raeburn 7583: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 7584: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7585: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7586: if (keys(%servers) > 1) {
7587: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7588: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7589: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7590: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7591: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7592: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7593: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7594: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7595: $changes{'loginvia'}{$lonhost} = 1;
7596: } else {
7597: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7598: $changes{'loginvia'}{$lonhost} = 1;
7599: }
7600: } else {
7601: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7602: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7603: $changes{'loginvia'}{$lonhost} = 1;
7604: }
7605: }
7606: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7607: foreach my $item (@loginvia_attribs) {
7608: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7609: }
7610: } else {
7611: foreach my $item (@loginvia_attribs) {
7612: my $new = $env{'form.'.$lonhost.'_'.$item};
7613: if (($item eq 'serverpath') && ($new eq 'custom')) {
7614: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7615: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7616: $new = '/';
7617: }
7618: }
7619: if (($item eq 'custompath') &&
7620: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7621: $new = '';
7622: }
7623: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7624: $changes{'loginvia'}{$lonhost} = 1;
7625: }
7626: if ($item eq 'exempt') {
1.256 raeburn 7627: $new = &check_exempt_addresses($new);
1.128 raeburn 7628: }
7629: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7630: }
7631: }
1.112 raeburn 7632: } else {
1.128 raeburn 7633: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7634: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7635: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7636: foreach my $item (@loginvia_attribs) {
7637: my $new = $env{'form.'.$lonhost.'_'.$item};
7638: if (($item eq 'serverpath') && ($new eq 'custom')) {
7639: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7640: $new = '/';
7641: }
7642: }
7643: if (($item eq 'custompath') &&
7644: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7645: $new = '';
7646: }
7647: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7648: }
1.110 raeburn 7649: }
7650: }
7651: }
7652: }
1.119 raeburn 7653:
1.168 raeburn 7654: my $servadm = $r->dir_config('lonAdmEMail');
7655: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7656: if (ref($domconfig{'login'}) eq 'HASH') {
7657: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7658: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7659: if ($lang eq 'nolang') {
7660: push(@currlangs,$lang);
7661: } elsif (defined($langchoices{$lang})) {
7662: push(@currlangs,$lang);
7663: } else {
7664: next;
7665: }
7666: }
7667: }
7668: }
7669: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7670: if (@currlangs > 0) {
7671: foreach my $lang (@currlangs) {
7672: if (grep(/^\Q$lang\E$/,@delurls)) {
7673: $changes{'helpurl'}{$lang} = 1;
7674: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7675: $changes{'helpurl'}{$lang} = 1;
7676: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7677: push(@newlangs,$lang);
7678: } else {
7679: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7680: }
7681: }
7682: }
7683: unless (grep(/^nolang$/,@currlangs)) {
7684: if ($env{'form.loginhelpurl_nolang.filename'}) {
7685: $changes{'helpurl'}{'nolang'} = 1;
7686: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7687: push(@newlangs,'nolang');
7688: }
7689: }
7690: if ($env{'form.loginhelpurl_add_lang'}) {
7691: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7692: ($env{'form.loginhelpurl_add_file.filename'})) {
7693: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7694: $addedfile = $env{'form.loginhelpurl_add_lang'};
7695: }
7696: }
7697: if ((@newlangs > 0) || ($addedfile)) {
7698: my $error;
7699: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7700: if ($configuserok eq 'ok') {
7701: if ($switchserver) {
7702: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7703: } elsif ($author_ok eq 'ok') {
7704: my @allnew = @newlangs;
7705: if ($addedfile ne '') {
7706: push(@allnew,$addedfile);
7707: }
7708: foreach my $lang (@allnew) {
7709: my $formelem = 'loginhelpurl_'.$lang;
7710: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7711: $formelem = 'loginhelpurl_add_file';
7712: }
7713: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7714: "help/$lang",'','',$newfile{$lang});
7715: if ($result eq 'ok') {
7716: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7717: $changes{'helpurl'}{$lang} = 1;
7718: } else {
7719: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7720: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 7721: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 7722: (!grep(/^\Q$lang\E$/,@delurls))) {
7723: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7724: }
7725: }
7726: }
7727: } else {
7728: $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);
7729: }
7730: } else {
7731: $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);
7732: }
7733: if ($error) {
7734: &Apache::lonnet::logthis($error);
7735: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7736: }
7737: }
1.256 raeburn 7738:
7739: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7740: if (ref($domconfig{'login'}) eq 'HASH') {
7741: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7742: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7743: if ($domservers{$lonhost}) {
7744: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7745: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 7746: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 7747: }
7748: }
7749: }
7750: }
7751: }
7752: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7753: foreach my $lonhost (sort(keys(%domservers))) {
7754: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7755: $changes{'headtag'}{$lonhost} = 1;
7756: } else {
7757: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7758: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7759: }
7760: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7761: push(@newhosts,$lonhost);
7762: } elsif ($currheadtagurls{$lonhost}) {
7763: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7764: if ($currexempt{$lonhost}) {
1.289 raeburn 7765: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 7766: $changes{'headtag'}{$lonhost} = 1;
7767: }
7768: } elsif ($possexempt{$lonhost}) {
7769: $changes{'headtag'}{$lonhost} = 1;
7770: }
7771: if ($possexempt{$lonhost}) {
7772: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7773: }
7774: }
7775: }
7776: }
7777: if (@newhosts) {
7778: my $error;
7779: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7780: if ($configuserok eq 'ok') {
7781: if ($switchserver) {
7782: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7783: } elsif ($author_ok eq 'ok') {
7784: foreach my $lonhost (@newhosts) {
7785: my $formelem = 'loginheadtag_'.$lonhost;
7786: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7787: "login/headtag/$lonhost",'','',
7788: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7789: if ($result eq 'ok') {
7790: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7791: $changes{'headtag'}{$lonhost} = 1;
7792: if ($possexempt{$lonhost}) {
7793: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7794: }
7795: } else {
7796: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7797: $newheadtagurls{$lonhost},$result);
7798: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7799: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7800: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7801: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7802: }
7803: }
7804: }
7805: } else {
7806: $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);
7807: }
7808: } else {
7809: $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);
7810: }
7811: if ($error) {
7812: &Apache::lonnet::logthis($error);
7813: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7814: }
7815: }
1.169 raeburn 7816: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 7817:
7818: my $defaulthelpfile = '/adm/loginproblems.html';
7819: my $defaulttext = &mt('Default in use');
7820:
1.1 raeburn 7821: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7822: $dom);
7823: if ($putresult eq 'ok') {
1.188 raeburn 7824: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7825: my %defaultchecked = (
7826: 'coursecatalog' => 'on',
1.188 raeburn 7827: 'helpdesk' => 'on',
1.42 raeburn 7828: 'adminmail' => 'off',
1.43 raeburn 7829: 'newuser' => 'off',
1.42 raeburn 7830: );
1.55 raeburn 7831: if (ref($domconfig{'login'}) eq 'HASH') {
7832: foreach my $item (@toggles) {
7833: if ($defaultchecked{$item} eq 'on') {
7834: if (($domconfig{'login'}{$item} eq '0') &&
7835: ($env{'form.'.$item} eq '1')) {
7836: $changes{$item} = 1;
7837: } elsif (($domconfig{'login'}{$item} eq '' ||
7838: $domconfig{'login'}{$item} eq '1') &&
7839: ($env{'form.'.$item} eq '0')) {
7840: $changes{$item} = 1;
7841: }
7842: } elsif ($defaultchecked{$item} eq 'off') {
7843: if (($domconfig{'login'}{$item} eq '1') &&
7844: ($env{'form.'.$item} eq '0')) {
7845: $changes{$item} = 1;
7846: } elsif (($domconfig{'login'}{$item} eq '' ||
7847: $domconfig{'login'}{$item} eq '0') &&
7848: ($env{'form.'.$item} eq '1')) {
7849: $changes{$item} = 1;
7850: }
1.42 raeburn 7851: }
7852: }
1.41 raeburn 7853: }
1.6 raeburn 7854: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7855: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7856: if (ref($lastactref) eq 'HASH') {
7857: $lastactref->{'domainconfig'} = 1;
7858: }
1.1 raeburn 7859: $resulttext = &mt('Changes made:').'<ul>';
7860: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7861: if ($item eq 'loginvia') {
1.112 raeburn 7862: if (ref($changes{$item}) eq 'HASH') {
7863: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7864: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7865: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7866: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7867: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7868: $protocol = 'http' if ($protocol ne 'https');
7869: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7870:
7871: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7872: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7873: } else {
7874: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7875: }
7876: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7877: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7878: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7879: }
7880: $resulttext .= '</li>';
7881: } else {
7882: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7883: }
1.112 raeburn 7884: } else {
1.128 raeburn 7885: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7886: }
7887: }
1.128 raeburn 7888: $resulttext .= '</ul></li>';
1.112 raeburn 7889: }
1.168 raeburn 7890: } elsif ($item eq 'helpurl') {
7891: if (ref($changes{$item}) eq 'HASH') {
7892: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7893: if (grep(/^\Q$lang\E$/,@delurls)) {
7894: my ($chg,$link);
7895: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7896: if ($lang eq 'nolang') {
7897: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7898: } else {
7899: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7900: }
7901: $resulttext .= '<li>'.$chg.'</li>';
7902: } else {
7903: my $chg;
7904: if ($lang eq 'nolang') {
7905: $chg = &mt('custom log-in help file for no preferred language');
7906: } else {
7907: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7908: }
7909: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7910: $loginhash{'login'}{'helpurl'}{$lang}.
7911: '?inhibitmenu=yes',$chg,600,500).
7912: '</li>';
7913: }
7914: }
7915: }
1.256 raeburn 7916: } elsif ($item eq 'headtag') {
7917: if (ref($changes{$item}) eq 'HASH') {
7918: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7919: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7920: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7921: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7922: $resulttext .= '<li><a href="'.
7923: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7924: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7925: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7926: if ($possexempt{$lonhost}) {
7927: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7928: } else {
7929: $resulttext .= &mt('included for any client IP');
7930: }
7931: $resulttext .= '</li>';
7932: }
7933: }
7934: }
1.169 raeburn 7935: } elsif ($item eq 'captcha') {
7936: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7937: my $chgtxt;
1.169 raeburn 7938: if ($loginhash{'login'}{$item} eq 'notused') {
7939: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7940: } else {
7941: my %captchas = &captcha_phrases();
7942: if ($captchas{$loginhash{'login'}{$item}}) {
7943: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7944: } else {
7945: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7946: }
7947: }
7948: $resulttext .= '<li>'.$chgtxt.'</li>';
7949: }
7950: } elsif ($item eq 'recaptchakeys') {
7951: if (ref($loginhash{'login'}) eq 'HASH') {
7952: my ($privkey,$pubkey);
7953: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7954: $pubkey = $loginhash{'login'}{$item}{'public'};
7955: $privkey = $loginhash{'login'}{$item}{'private'};
7956: }
7957: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7958: if (!$pubkey) {
7959: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7960: } else {
7961: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7962: }
7963: if (!$privkey) {
7964: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7965: } else {
1.251 raeburn 7966: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7967: }
7968: $chgtxt .= '</ul>';
7969: $resulttext .= '<li>'.$chgtxt.'</li>';
7970: }
1.269 raeburn 7971: } elsif ($item eq 'recaptchaversion') {
7972: if (ref($loginhash{'login'}) eq 'HASH') {
7973: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7974: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7975: '</li>';
7976: }
7977: }
1.41 raeburn 7978: } else {
7979: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7980: }
1.1 raeburn 7981: }
1.6 raeburn 7982: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7983: } else {
7984: $resulttext = &mt('No changes made to log-in page settings');
7985: }
7986: } else {
1.11 albertel 7987: $resulttext = '<span class="LC_error">'.
7988: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7989: }
1.6 raeburn 7990: if ($errors) {
1.9 raeburn 7991: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7992: $errors.'</ul>';
7993: }
7994: return $resulttext;
7995: }
7996:
1.256 raeburn 7997: sub check_exempt_addresses {
7998: my ($iplist) = @_;
7999: $iplist =~ s/^\s+//;
8000: $iplist =~ s/\s+$//;
8001: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8002: my (@okips,$new);
8003: foreach my $ip (@poss_ips) {
8004: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8005: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8006: push(@okips,$ip);
8007: }
8008: }
8009: }
8010: if (@okips > 0) {
8011: $new = join(',',@okips);
8012: } else {
8013: $new = '';
8014: }
8015: return $new;
8016: }
8017:
1.6 raeburn 8018: sub color_font_choices {
8019: my %choices =
8020: &Apache::lonlocal::texthash (
8021: img => "Header",
8022: bgs => "Background colors",
8023: links => "Link colors",
1.55 raeburn 8024: images => "Images",
1.6 raeburn 8025: font => "Font color",
1.201 raeburn 8026: fontmenu => "Font menu",
1.76 raeburn 8027: pgbg => "Page",
1.6 raeburn 8028: tabbg => "Header",
8029: sidebg => "Border",
8030: link => "Link",
8031: alink => "Active link",
8032: vlink => "Visited link",
8033: );
8034: return %choices;
8035: }
8036:
8037: sub modify_rolecolors {
1.205 raeburn 8038: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8039: my ($resulttext,%rolehash);
8040: $rolehash{'rolecolors'} = {};
1.55 raeburn 8041: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8042: if ($domconfig{'rolecolors'} eq '') {
8043: $domconfig{'rolecolors'} = {};
8044: }
8045: }
1.9 raeburn 8046: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8047: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8048: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8049: $dom);
8050: if ($putresult eq 'ok') {
8051: if (keys(%changes) > 0) {
1.41 raeburn 8052: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8053: if (ref($lastactref) eq 'HASH') {
8054: $lastactref->{'domainconfig'} = 1;
8055: }
1.6 raeburn 8056: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8057: $rolehash{'rolecolors'});
8058: } else {
8059: $resulttext = &mt('No changes made to default color schemes');
8060: }
8061: } else {
1.11 albertel 8062: $resulttext = '<span class="LC_error">'.
8063: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8064: }
8065: if ($errors) {
8066: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8067: $errors.'</ul>';
8068: }
8069: return $resulttext;
8070: }
8071:
8072: sub modify_colors {
1.9 raeburn 8073: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8074: my (%changes,%choices);
1.51 raeburn 8075: my @bgs;
1.6 raeburn 8076: my @links = ('link','alink','vlink');
1.41 raeburn 8077: my @logintext;
1.6 raeburn 8078: my @images;
8079: my $servadm = $r->dir_config('lonAdmEMail');
8080: my $errors;
1.200 raeburn 8081: my %defaults;
1.6 raeburn 8082: foreach my $role (@{$roles}) {
8083: if ($role eq 'login') {
1.12 raeburn 8084: %choices = &login_choices();
1.41 raeburn 8085: @logintext = ('textcol','bgcol');
1.12 raeburn 8086: } else {
8087: %choices = &color_font_choices();
8088: }
8089: if ($role eq 'login') {
1.41 raeburn 8090: @images = ('img','logo','domlogo','login');
1.51 raeburn 8091: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8092: } else {
8093: @images = ('img');
1.200 raeburn 8094: @bgs = ('pgbg','tabbg','sidebg');
8095: }
8096: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8097: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8098: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8099: }
8100: if ($role eq 'login') {
8101: foreach my $item (@logintext) {
1.234 raeburn 8102: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8103: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8104: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8105: }
8106: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 8107: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8108: }
8109: }
8110: } else {
1.234 raeburn 8111: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8112: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8113: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8114: }
8115: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 8116: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8117: }
1.6 raeburn 8118: }
1.200 raeburn 8119: foreach my $item (@bgs) {
1.234 raeburn 8120: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8121: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8122: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8123: }
8124: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 8125: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8126: }
8127: }
8128: foreach my $item (@links) {
1.234 raeburn 8129: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8130: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8131: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8132: }
8133: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 8134: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8135: }
1.6 raeburn 8136: }
1.46 raeburn 8137: my ($configuserok,$author_ok,$switchserver) =
8138: &config_check($dom,$confname,$servadm);
1.9 raeburn 8139: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8140: if (ref($domconfig->{$role}) ne 'HASH') {
8141: $domconfig->{$role} = {};
8142: }
1.8 raeburn 8143: foreach my $img (@images) {
1.70 raeburn 8144: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8145: if (defined($env{'form.login_showlogo_'.$img})) {
8146: $confhash->{$role}{'showlogo'}{$img} = 1;
8147: } else {
8148: $confhash->{$role}{'showlogo'}{$img} = 0;
8149: }
8150: }
1.18 albertel 8151: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8152: && !defined($domconfig->{$role}{$img})
8153: && !$env{'form.'.$role.'_del_'.$img}
8154: && $env{'form.'.$role.'_import_'.$img}) {
8155: # import the old configured image from the .tab setting
8156: # if they haven't provided a new one
8157: $domconfig->{$role}{$img} =
8158: $env{'form.'.$role.'_import_'.$img};
8159: }
1.6 raeburn 8160: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8161: my $error;
1.6 raeburn 8162: if ($configuserok eq 'ok') {
1.9 raeburn 8163: if ($switchserver) {
1.12 raeburn 8164: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8165: } else {
8166: if ($author_ok eq 'ok') {
8167: my ($result,$logourl) =
8168: &publishlogo($r,'upload',$role.'_'.$img,
8169: $dom,$confname,$img,$width,$height);
8170: if ($result eq 'ok') {
8171: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8172: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8173: } else {
1.12 raeburn 8174: $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 8175: }
8176: } else {
1.46 raeburn 8177: $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 8178: }
8179: }
8180: } else {
1.46 raeburn 8181: $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 8182: }
8183: if ($error) {
1.8 raeburn 8184: &Apache::lonnet::logthis($error);
1.11 albertel 8185: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8186: }
8187: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8188: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8189: my $error;
8190: if ($configuserok eq 'ok') {
8191: # is confname an author?
8192: if ($switchserver eq '') {
8193: if ($author_ok eq 'ok') {
8194: my ($result,$logourl) =
8195: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8196: $dom,$confname,$img,$width,$height);
8197: if ($result eq 'ok') {
8198: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8199: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8200: }
8201: }
8202: }
8203: }
1.6 raeburn 8204: }
8205: }
8206: }
8207: if (ref($domconfig) eq 'HASH') {
8208: if (ref($domconfig->{$role}) eq 'HASH') {
8209: foreach my $img (@images) {
8210: if ($domconfig->{$role}{$img} ne '') {
8211: if ($env{'form.'.$role.'_del_'.$img}) {
8212: $confhash->{$role}{$img} = '';
1.12 raeburn 8213: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8214: } else {
1.9 raeburn 8215: if ($confhash->{$role}{$img} eq '') {
8216: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8217: }
1.6 raeburn 8218: }
8219: } else {
8220: if ($env{'form.'.$role.'_del_'.$img}) {
8221: $confhash->{$role}{$img} = '';
1.12 raeburn 8222: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8223: }
8224: }
1.70 raeburn 8225: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8226: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8227: if ($confhash->{$role}{'showlogo'}{$img} ne
8228: $domconfig->{$role}{'showlogo'}{$img}) {
8229: $changes{$role}{'showlogo'}{$img} = 1;
8230: }
8231: } else {
8232: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8233: $changes{$role}{'showlogo'}{$img} = 1;
8234: }
8235: }
8236: }
8237: }
1.6 raeburn 8238: if ($domconfig->{$role}{'font'} ne '') {
8239: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8240: $changes{$role}{'font'} = 1;
8241: }
8242: } else {
8243: if ($confhash->{$role}{'font'}) {
8244: $changes{$role}{'font'} = 1;
8245: }
8246: }
1.107 raeburn 8247: if ($role ne 'login') {
8248: if ($domconfig->{$role}{'fontmenu'} ne '') {
8249: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8250: $changes{$role}{'fontmenu'} = 1;
8251: }
8252: } else {
8253: if ($confhash->{$role}{'fontmenu'}) {
8254: $changes{$role}{'fontmenu'} = 1;
8255: }
1.97 tempelho 8256: }
8257: }
1.6 raeburn 8258: foreach my $item (@bgs) {
8259: if ($domconfig->{$role}{$item} ne '') {
8260: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8261: $changes{$role}{'bgs'}{$item} = 1;
8262: }
8263: } else {
8264: if ($confhash->{$role}{$item}) {
8265: $changes{$role}{'bgs'}{$item} = 1;
8266: }
8267: }
8268: }
8269: foreach my $item (@links) {
8270: if ($domconfig->{$role}{$item} ne '') {
8271: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8272: $changes{$role}{'links'}{$item} = 1;
8273: }
8274: } else {
8275: if ($confhash->{$role}{$item}) {
8276: $changes{$role}{'links'}{$item} = 1;
8277: }
8278: }
8279: }
1.41 raeburn 8280: foreach my $item (@logintext) {
8281: if ($domconfig->{$role}{$item} ne '') {
8282: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8283: $changes{$role}{'logintext'}{$item} = 1;
8284: }
8285: } else {
8286: if ($confhash->{$role}{$item}) {
8287: $changes{$role}{'logintext'}{$item} = 1;
8288: }
8289: }
8290: }
1.6 raeburn 8291: } else {
8292: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8293: \@logintext,$confhash,\%changes);
1.6 raeburn 8294: }
8295: } else {
8296: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8297: \@logintext,$confhash,\%changes);
1.6 raeburn 8298: }
8299: }
8300: return ($errors,%changes);
8301: }
8302:
1.46 raeburn 8303: sub config_check {
8304: my ($dom,$confname,$servadm) = @_;
8305: my ($configuserok,$author_ok,$switchserver,%currroles);
8306: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8307: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8308: $confname,$servadm);
8309: if ($configuserok eq 'ok') {
8310: $switchserver = &check_switchserver($dom,$confname);
8311: if ($switchserver eq '') {
8312: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8313: }
8314: }
8315: return ($configuserok,$author_ok,$switchserver);
8316: }
8317:
1.6 raeburn 8318: sub default_change_checker {
1.41 raeburn 8319: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8320: foreach my $item (@{$links}) {
8321: if ($confhash->{$role}{$item}) {
8322: $changes->{$role}{'links'}{$item} = 1;
8323: }
8324: }
8325: foreach my $item (@{$bgs}) {
8326: if ($confhash->{$role}{$item}) {
8327: $changes->{$role}{'bgs'}{$item} = 1;
8328: }
8329: }
1.41 raeburn 8330: foreach my $item (@{$logintext}) {
8331: if ($confhash->{$role}{$item}) {
8332: $changes->{$role}{'logintext'}{$item} = 1;
8333: }
8334: }
1.6 raeburn 8335: foreach my $img (@{$images}) {
8336: if ($env{'form.'.$role.'_del_'.$img}) {
8337: $confhash->{$role}{$img} = '';
1.12 raeburn 8338: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8339: }
1.70 raeburn 8340: if ($role eq 'login') {
8341: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8342: $changes->{$role}{'showlogo'}{$img} = 1;
8343: }
8344: }
1.6 raeburn 8345: }
8346: if ($confhash->{$role}{'font'}) {
8347: $changes->{$role}{'font'} = 1;
8348: }
1.48 raeburn 8349: }
1.6 raeburn 8350:
8351: sub display_colorchgs {
8352: my ($dom,$changes,$roles,$confhash) = @_;
8353: my (%choices,$resulttext);
8354: if (!grep(/^login$/,@{$roles})) {
8355: $resulttext = &mt('Changes made:').'<br />';
8356: }
8357: foreach my $role (@{$roles}) {
8358: if ($role eq 'login') {
8359: %choices = &login_choices();
8360: } else {
8361: %choices = &color_font_choices();
8362: }
8363: if (ref($changes->{$role}) eq 'HASH') {
8364: if ($role ne 'login') {
8365: $resulttext .= '<h4>'.&mt($role).'</h4>';
8366: }
8367: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8368: if ($role ne 'login') {
8369: $resulttext .= '<ul>';
8370: }
8371: if (ref($changes->{$role}{$key}) eq 'HASH') {
8372: if ($role ne 'login') {
8373: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8374: }
8375: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8376: if (($role eq 'login') && ($key eq 'showlogo')) {
8377: if ($confhash->{$role}{$key}{$item}) {
8378: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8379: } else {
8380: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8381: }
8382: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8383: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8384: } else {
1.12 raeburn 8385: my $newitem = $confhash->{$role}{$item};
8386: if ($key eq 'images') {
8387: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8388: }
8389: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8390: }
8391: }
8392: if ($role ne 'login') {
8393: $resulttext .= '</ul></li>';
8394: }
8395: } else {
8396: if ($confhash->{$role}{$key} eq '') {
8397: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8398: } else {
8399: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8400: }
8401: }
8402: if ($role ne 'login') {
8403: $resulttext .= '</ul>';
8404: }
8405: }
8406: }
8407: }
1.3 raeburn 8408: return $resulttext;
1.1 raeburn 8409: }
8410:
1.9 raeburn 8411: sub thumb_dimensions {
8412: return ('200','50');
8413: }
8414:
1.16 raeburn 8415: sub check_dimensions {
8416: my ($inputfile) = @_;
8417: my ($fullwidth,$fullheight);
8418: if ($inputfile =~ m|^[/\w.\-]+$|) {
8419: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8420: my $imageinfo = <PIPE>;
8421: if (!close(PIPE)) {
8422: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8423: }
8424: chomp($imageinfo);
8425: my ($fullsize) =
1.21 raeburn 8426: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8427: if ($fullsize) {
8428: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8429: }
8430: }
8431: }
8432: return ($fullwidth,$fullheight);
8433: }
8434:
1.9 raeburn 8435: sub check_configuser {
8436: my ($uhome,$dom,$confname,$servadm) = @_;
8437: my ($configuserok,%currroles);
8438: if ($uhome eq 'no_host') {
8439: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8440: my $configpass = &LONCAPA::Enrollment::create_password();
8441: $configuserok =
8442: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8443: $configpass,'','','','','',undef,$servadm);
8444: } else {
8445: $configuserok = 'ok';
8446: %currroles =
8447: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8448: }
8449: return ($configuserok,%currroles);
8450: }
8451:
8452: sub check_authorstatus {
8453: my ($dom,$confname,%currroles) = @_;
8454: my $author_ok;
1.40 raeburn 8455: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8456: my $start = time;
8457: my $end = 0;
8458: $author_ok =
8459: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8460: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8461: } else {
8462: $author_ok = 'ok';
8463: }
8464: return $author_ok;
8465: }
8466:
8467: sub publishlogo {
1.46 raeburn 8468: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 8469: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 8470: if ($action eq 'upload') {
8471: $fname=$env{'form.'.$formname.'.filename'};
8472: chop($env{'form.'.$formname});
8473: } else {
8474: ($fname) = ($formname =~ /([^\/]+)$/);
8475: }
1.46 raeburn 8476: if ($savefileas ne '') {
8477: $fname = $savefileas;
8478: }
1.9 raeburn 8479: $fname=&Apache::lonnet::clean_filename($fname);
8480: # See if there is anything left
8481: unless ($fname) { return ('error: no uploaded file'); }
8482: $fname="$subdir/$fname";
1.210 raeburn 8483: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 8484: my $filepath="$docroot/priv";
8485: my $relpath = "$dom/$confname";
1.9 raeburn 8486: my ($fnamepath,$file,$fetchthumb);
8487: $file=$fname;
8488: if ($fname=~m|/|) {
8489: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8490: }
1.164 raeburn 8491: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8492: my $count;
1.164 raeburn 8493: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8494: $filepath.="/$parts[$count]";
8495: if ((-e $filepath)!=1) {
8496: mkdir($filepath,02770);
8497: }
8498: }
8499: # Check for bad extension and disallow upload
8500: if ($file=~/\.(\w+)$/ &&
8501: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8502: $output =
1.207 bisitz 8503: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8504: } elsif ($file=~/\.(\w+)$/ &&
8505: !defined(&Apache::loncommon::fileembstyle($1))) {
8506: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8507: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 8508: $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 8509: } elsif (-d "$filepath/$file") {
1.195 bisitz 8510: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8511: } else {
8512: my $source = $filepath.'/'.$file;
8513: my $logfile;
8514: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 8515: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8516: }
8517: print $logfile
8518: "\n================= Publish ".localtime()." ================\n".
8519: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8520: # Save the file
8521: if (!open(FH,'>'.$source)) {
8522: &Apache::lonnet::logthis('Failed to create '.$source);
8523: return (&mt('Failed to create file'));
8524: }
8525: if ($action eq 'upload') {
8526: if (!print FH ($env{'form.'.$formname})) {
8527: &Apache::lonnet::logthis('Failed to write to '.$source);
8528: return (&mt('Failed to write file'));
8529: }
8530: } else {
8531: my $original = &Apache::lonnet::filelocation('',$formname);
8532: if(!copy($original,$source)) {
8533: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8534: return (&mt('Failed to write file'));
8535: }
8536: }
8537: close(FH);
8538: chmod(0660, $source); # Permissions to rw-rw---.
8539:
8540: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8541: my $copyfile=$targetdir.'/'.$file;
8542:
8543: my @parts=split(/\//,$targetdir);
8544: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8545: for (my $count=5;$count<=$#parts;$count++) {
8546: $path.="/$parts[$count]";
8547: if (!-e $path) {
8548: print $logfile "\nCreating directory ".$path;
8549: mkdir($path,02770);
8550: }
8551: }
8552: my $versionresult;
8553: if (-e $copyfile) {
8554: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8555: } else {
8556: $versionresult = 'ok';
8557: }
8558: if ($versionresult eq 'ok') {
8559: if (copy($source,$copyfile)) {
8560: print $logfile "\nCopied original source to ".$copyfile."\n";
8561: $output = 'ok';
8562: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8563: push(@{$modified_urls},[$copyfile,$source]);
8564: my $metaoutput =
8565: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8566: unless ($registered_cleanup) {
8567: my $handlers = $r->get_handlers('PerlCleanupHandler');
8568: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8569: $registered_cleanup=1;
8570: }
1.9 raeburn 8571: } else {
8572: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8573: $output = &mt('Failed to copy file to RES space').", $!";
8574: }
8575: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8576: my $inputfile = $filepath.'/'.$file;
8577: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8578: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8579: if ($fullwidth ne '' && $fullheight ne '') {
8580: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8581: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8582: system("convert -sample $thumbsize $inputfile $outfile");
8583: chmod(0660, $filepath.'/tn-'.$file);
8584: if (-e $outfile) {
8585: my $copyfile=$targetdir.'/tn-'.$file;
8586: if (copy($outfile,$copyfile)) {
8587: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8588: my $thumb_metaoutput =
8589: &write_metadata($dom,$confname,$formname,
8590: $targetdir,'tn-'.$file,$logfile);
8591: push(@{$modified_urls},[$copyfile,$outfile]);
8592: unless ($registered_cleanup) {
8593: my $handlers = $r->get_handlers('PerlCleanupHandler');
8594: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8595: $registered_cleanup=1;
8596: }
1.267 raeburn 8597: $madethumb = 1;
1.16 raeburn 8598: } else {
8599: print $logfile "\nUnable to write ".$copyfile.
8600: ':'.$!."\n";
8601: }
8602: }
1.9 raeburn 8603: }
8604: }
8605: }
8606: } else {
8607: $output = $versionresult;
8608: }
8609: }
1.267 raeburn 8610: return ($output,$logourl,$madethumb);
1.9 raeburn 8611: }
8612:
8613: sub logo_versioning {
8614: my ($targetdir,$file,$logfile) = @_;
8615: my $target = $targetdir.'/'.$file;
8616: my ($maxversion,$fn,$extn,$output);
8617: $maxversion = 0;
8618: if ($file =~ /^(.+)\.(\w+)$/) {
8619: $fn=$1;
8620: $extn=$2;
8621: }
8622: opendir(DIR,$targetdir);
8623: while (my $filename=readdir(DIR)) {
8624: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8625: $maxversion=($1>$maxversion)?$1:$maxversion;
8626: }
8627: }
8628: $maxversion++;
8629: print $logfile "\nCreating old version ".$maxversion."\n";
8630: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8631: if (copy($target,$copyfile)) {
8632: print $logfile "Copied old target to ".$copyfile."\n";
8633: $copyfile=$copyfile.'.meta';
8634: if (copy($target.'.meta',$copyfile)) {
8635: print $logfile "Copied old target metadata to ".$copyfile."\n";
8636: $output = 'ok';
8637: } else {
8638: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8639: $output = &mt('Failed to copy old meta').", $!, ";
8640: }
8641: } else {
8642: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8643: $output = &mt('Failed to copy old target').", $!, ";
8644: }
8645: return $output;
8646: }
8647:
8648: sub write_metadata {
8649: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8650: my (%metadatafields,%metadatakeys,$output);
8651: $metadatafields{'title'}=$formname;
8652: $metadatafields{'creationdate'}=time;
8653: $metadatafields{'lastrevisiondate'}=time;
8654: $metadatafields{'copyright'}='public';
8655: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8656: $env{'user.domain'};
8657: $metadatafields{'authorspace'}=$confname.':'.$dom;
8658: $metadatafields{'domain'}=$dom;
8659: {
8660: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8661: my $mfh;
1.155 raeburn 8662: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 8663: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8664: unless ($_=~/\./) {
8665: my $unikey=$_;
8666: $unikey=~/^([A-Za-z]+)/;
8667: my $tag=$1;
8668: $tag=~tr/A-Z/a-z/;
8669: print $mfh "\n\<$tag";
8670: foreach (split(/\,/,$metadatakeys{$unikey})) {
8671: my $value=$metadatafields{$unikey.'.'.$_};
8672: $value=~s/\"/\'\'/g;
8673: print $mfh ' '.$_.'="'.$value.'"';
8674: }
8675: print $mfh '>'.
8676: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8677: .'</'.$tag.'>';
8678: }
8679: }
8680: $output = 'ok';
8681: print $logfile "\nWrote metadata";
8682: close($mfh);
8683: } else {
8684: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8685: $output = &mt('Could not write metadata');
8686: }
8687: }
1.155 raeburn 8688: return $output;
8689: }
8690:
8691: sub notifysubscribed {
8692: foreach my $targetsource (@{$modified_urls}){
8693: next unless (ref($targetsource) eq 'ARRAY');
8694: my ($target,$source)=@{$targetsource};
8695: if ($source ne '') {
8696: if (open(my $logfh,'>>'.$source.'.log')) {
8697: print $logfh "\nCleanup phase: Notifications\n";
8698: my @subscribed=&subscribed_hosts($target);
8699: foreach my $subhost (@subscribed) {
8700: print $logfh "\nNotifying host ".$subhost.':';
8701: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8702: print $logfh $reply;
8703: }
8704: my @subscribedmeta=&subscribed_hosts("$target.meta");
8705: foreach my $subhost (@subscribedmeta) {
8706: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8707: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8708: $subhost);
8709: print $logfh $reply;
8710: }
8711: print $logfh "\n============ Done ============\n";
1.160 raeburn 8712: close($logfh);
1.155 raeburn 8713: }
8714: }
8715: }
8716: return OK;
8717: }
8718:
8719: sub subscribed_hosts {
8720: my ($target) = @_;
8721: my @subscribed;
8722: if (open(my $fh,"<$target.subscription")) {
8723: while (my $subline=<$fh>) {
8724: if ($subline =~ /^($match_lonid):/) {
8725: my $host = $1;
8726: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8727: unless (grep(/^\Q$host\E$/,@subscribed)) {
8728: push(@subscribed,$host);
8729: }
8730: }
8731: }
8732: }
8733: }
8734: return @subscribed;
1.9 raeburn 8735: }
8736:
8737: sub check_switchserver {
8738: my ($dom,$confname) = @_;
8739: my ($allowed,$switchserver);
8740: my $home = &Apache::lonnet::homeserver($confname,$dom);
8741: if ($home eq 'no_host') {
8742: $home = &Apache::lonnet::domain($dom,'primary');
8743: }
8744: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8745: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8746: if (!$allowed) {
1.180 raeburn 8747: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8748: }
8749: return $switchserver;
8750: }
8751:
1.1 raeburn 8752: sub modify_quotas {
1.216 raeburn 8753: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8754: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 8755: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 8756: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8757: $validationfieldsref);
1.86 raeburn 8758: if ($action eq 'quotas') {
8759: $context = 'tools';
1.163 raeburn 8760: } else {
1.86 raeburn 8761: $context = $action;
8762: }
8763: if ($context eq 'requestcourses') {
1.271 raeburn 8764: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 8765: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8766: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8767: %titles = &courserequest_titles();
8768: $toolregexp = join('|',@usertools);
8769: %conditions = &courserequest_conditions();
1.216 raeburn 8770: $confname = $dom.'-domainconfig';
8771: my $servadm = $r->dir_config('lonAdmEMail');
8772: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 8773: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8774: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 8775: } elsif ($context eq 'requestauthor') {
8776: @usertools = ('author');
8777: %titles = &authorrequest_titles();
1.86 raeburn 8778: } else {
1.162 raeburn 8779: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8780: %titles = &tool_titles();
1.86 raeburn 8781: }
1.212 raeburn 8782: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8783: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8784: foreach my $key (keys(%env)) {
1.101 raeburn 8785: if ($context eq 'requestcourses') {
8786: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8787: my $item = $1;
8788: my $type = $2;
8789: if ($type =~ /^limit_(.+)/) {
8790: $limithash{$item}{$1} = $env{$key};
8791: } else {
8792: $confhash{$item}{$type} = $env{$key};
8793: }
8794: }
1.163 raeburn 8795: } elsif ($context eq 'requestauthor') {
8796: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8797: $confhash{$1} = $env{$key};
8798: }
1.101 raeburn 8799: } else {
1.86 raeburn 8800: if ($key =~ /^form\.quota_(.+)$/) {
8801: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 8802: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8803: $confhash{'authorquota'}{$1} = $env{$key};
8804: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8805: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8806: }
1.72 raeburn 8807: }
8808: }
1.163 raeburn 8809: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 8810: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8811: @approvalnotify = sort(@approvalnotify);
8812: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 8813: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 8814: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8815: foreach my $type (@hasuniquecode) {
8816: if (grep(/^\Q$type\E$/,@crstypes)) {
8817: $confhash{'uniquecode'}{$type} = 1;
8818: }
1.216 raeburn 8819: }
1.242 raeburn 8820: my (%newbook,%allpos);
1.216 raeburn 8821: if ($context eq 'requestcourses') {
1.242 raeburn 8822: foreach my $type ('textbooks','templates') {
8823: @{$allpos{$type}} = ();
8824: my $invalid;
8825: if ($type eq 'textbooks') {
8826: $invalid = &mt('Invalid LON-CAPA course for textbook');
8827: } else {
8828: $invalid = &mt('Invalid LON-CAPA course for template');
8829: }
8830: if ($env{'form.'.$type.'_addbook'}) {
8831: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8832: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8833: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8834: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8835: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8836: } else {
8837: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8838: my $position = $env{'form.'.$type.'_addbook_pos'};
8839: $position =~ s/\D+//g;
8840: if ($position ne '') {
8841: $allpos{$type}[$position] = $newbook{$type};
8842: }
1.216 raeburn 8843: }
1.242 raeburn 8844: } else {
8845: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8846: }
8847: }
1.242 raeburn 8848: }
1.216 raeburn 8849: }
1.102 raeburn 8850: if (ref($domconfig{$action}) eq 'HASH') {
8851: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8852: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8853: $changes{'notify'}{'approval'} = 1;
8854: }
8855: } else {
1.144 raeburn 8856: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8857: $changes{'notify'}{'approval'} = 1;
8858: }
8859: }
1.218 raeburn 8860: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8861: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8862: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8863: unless ($confhash{'uniquecode'}{$crstype}) {
8864: $changes{'uniquecode'} = 1;
8865: }
8866: }
8867: unless ($changes{'uniquecode'}) {
8868: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8869: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8870: $changes{'uniquecode'} = 1;
8871: }
8872: }
8873: }
8874: } else {
8875: $changes{'uniquecode'} = 1;
8876: }
8877: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8878: $changes{'uniquecode'} = 1;
1.216 raeburn 8879: }
8880: if ($context eq 'requestcourses') {
1.242 raeburn 8881: foreach my $type ('textbooks','templates') {
8882: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8883: my %deletions;
8884: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8885: if (@todelete) {
8886: map { $deletions{$_} = 1; } @todelete;
8887: }
8888: my %imgdeletions;
8889: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8890: if (@todeleteimages) {
8891: map { $imgdeletions{$_} = 1; } @todeleteimages;
8892: }
8893: my $maxnum = $env{'form.'.$type.'_maxnum'};
8894: for (my $i=0; $i<=$maxnum; $i++) {
8895: my $itemid = $env{'form.'.$type.'_id_'.$i};
8896: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8897: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8898: if ($deletions{$key}) {
8899: if ($domconfig{$action}{$type}{$key}{'image'}) {
8900: #FIXME need to obsolete item in RES space
8901: }
8902: next;
8903: } else {
8904: my $newpos = $env{'form.'.$itemid};
8905: $newpos =~ s/\D+//g;
1.243 raeburn 8906: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 8907: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 8908: ($type eq 'templates'));
1.242 raeburn 8909: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8910: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8911: $changes{$type}{$key} = 1;
8912: }
8913: }
8914: $allpos{$type}[$newpos] = $key;
8915: }
8916: if ($imgdeletions{$key}) {
8917: $changes{$type}{$key} = 1;
1.216 raeburn 8918: #FIXME need to obsolete item in RES space
1.242 raeburn 8919: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8920: my ($cdom,$cnum) = split(/_/,$key);
8921: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8922: $cdom,$cnum,$type,$configuserok,
8923: $switchserver,$author_ok);
8924: if ($imgurl) {
8925: $confhash{$type}{$key}{'image'} = $imgurl;
8926: $changes{$type}{$key} = 1;
1.216 raeburn 8927: }
1.242 raeburn 8928: if ($error) {
8929: &Apache::lonnet::logthis($error);
8930: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8931: }
8932: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8933: $confhash{$type}{$key}{'image'} =
8934: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8935: }
8936: }
8937: }
8938: }
8939: }
8940: }
1.102 raeburn 8941: } else {
1.144 raeburn 8942: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8943: $changes{'notify'}{'approval'} = 1;
8944: }
1.218 raeburn 8945: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8946: $changes{'uniquecode'} = 1;
8947: }
8948: }
8949: if ($context eq 'requestcourses') {
1.242 raeburn 8950: foreach my $type ('textbooks','templates') {
8951: if ($newbook{$type}) {
8952: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8953: foreach my $item ('subject','title','publisher','author') {
8954: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8955: ($type eq 'template'));
1.242 raeburn 8956: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8957: if ($env{'form.'.$type.'_addbook_'.$item}) {
8958: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8959: }
8960: }
8961: if ($type eq 'textbooks') {
8962: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8963: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8964: my ($imageurl,$error) =
8965: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8966: $configuserok,$switchserver,$author_ok);
8967: if ($imageurl) {
8968: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8969: }
8970: if ($error) {
8971: &Apache::lonnet::logthis($error);
8972: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8973: }
8974: }
1.216 raeburn 8975: }
8976: }
1.242 raeburn 8977: if (@{$allpos{$type}} > 0) {
8978: my $idx = 0;
8979: foreach my $item (@{$allpos{$type}}) {
8980: if ($item ne '') {
8981: $confhash{$type}{$item}{'order'} = $idx;
8982: if (ref($domconfig{$action}) eq 'HASH') {
8983: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8984: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8985: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8986: $changes{$type}{$item} = 1;
8987: }
1.216 raeburn 8988: }
8989: }
8990: }
1.242 raeburn 8991: $idx ++;
1.216 raeburn 8992: }
8993: }
8994: }
8995: }
1.235 raeburn 8996: if (ref($validationitemsref) eq 'ARRAY') {
8997: foreach my $item (@{$validationitemsref}) {
8998: if ($item eq 'fields') {
8999: my @changed;
9000: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9001: if (@{$confhash{'validation'}{$item}} > 0) {
9002: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9003: }
1.266 raeburn 9004: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9005: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9006: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9007: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9008: $domconfig{'requestcourses'}{'validation'}{$item});
9009: } else {
9010: @changed = @{$confhash{'validation'}{$item}};
9011: }
1.235 raeburn 9012: } else {
9013: @changed = @{$confhash{'validation'}{$item}};
9014: }
9015: } else {
9016: @changed = @{$confhash{'validation'}{$item}};
9017: }
9018: if (@changed) {
9019: if ($confhash{'validation'}{$item}) {
9020: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9021: } else {
9022: $changes{'validation'}{$item} = &mt('None');
9023: }
9024: }
9025: } else {
9026: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9027: if ($item eq 'markup') {
9028: if ($env{'form.requestcourses_validation_'.$item}) {
9029: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9030: }
9031: }
1.266 raeburn 9032: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9033: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9034: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9035: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9036: }
9037: } else {
9038: if ($confhash{'validation'}{$item} ne '') {
9039: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9040: }
1.235 raeburn 9041: }
9042: } else {
9043: if ($confhash{'validation'}{$item} ne '') {
9044: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9045: }
9046: }
9047: }
9048: }
9049: }
9050: if ($env{'form.validationdc'}) {
9051: my $newval = $env{'form.validationdc'};
1.285 raeburn 9052: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 9053: if (exists($domcoords{$newval})) {
9054: $confhash{'validation'}{'dc'} = $newval;
9055: }
9056: }
9057: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 9058: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9059: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9060: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9061: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9062: if ($confhash{'validation'}{'dc'} eq '') {
9063: $changes{'validation'}{'dc'} = &mt('None');
9064: } else {
9065: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9066: }
1.235 raeburn 9067: }
1.266 raeburn 9068: } elsif ($confhash{'validation'}{'dc'} ne '') {
9069: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 9070: }
9071: } elsif ($confhash{'validation'}{'dc'} ne '') {
9072: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9073: }
9074: } elsif ($confhash{'validation'}{'dc'} ne '') {
9075: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 9076: }
1.266 raeburn 9077: } else {
9078: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9079: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9080: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9081: $changes{'validation'}{'dc'} = &mt('None');
9082: }
9083: }
1.235 raeburn 9084: }
9085: }
1.102 raeburn 9086: }
9087: } else {
1.86 raeburn 9088: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 9089: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9090: }
1.72 raeburn 9091: foreach my $item (@usertools) {
9092: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9093: my $unset;
1.101 raeburn 9094: if ($context eq 'requestcourses') {
1.104 raeburn 9095: $unset = '0';
9096: if ($type eq '_LC_adv') {
9097: $unset = '';
9098: }
1.101 raeburn 9099: if ($confhash{$item}{$type} eq 'autolimit') {
9100: $confhash{$item}{$type} .= '=';
9101: unless ($limithash{$item}{$type} =~ /\D/) {
9102: $confhash{$item}{$type} .= $limithash{$item}{$type};
9103: }
9104: }
1.163 raeburn 9105: } elsif ($context eq 'requestauthor') {
9106: $unset = '0';
9107: if ($type eq '_LC_adv') {
9108: $unset = '';
9109: }
1.72 raeburn 9110: } else {
1.101 raeburn 9111: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9112: $confhash{$item}{$type} = 1;
9113: } else {
9114: $confhash{$item}{$type} = 0;
9115: }
1.72 raeburn 9116: }
1.86 raeburn 9117: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 9118: if ($action eq 'requestauthor') {
9119: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9120: $changes{$type} = 1;
9121: }
9122: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9123: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9124: $changes{$item}{$type} = 1;
9125: }
9126: } else {
9127: if ($context eq 'requestcourses') {
1.104 raeburn 9128: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9129: $changes{$item}{$type} = 1;
9130: }
9131: } else {
9132: if (!$confhash{$item}{$type}) {
9133: $changes{$item}{$type} = 1;
9134: }
9135: }
9136: }
9137: } else {
9138: if ($context eq 'requestcourses') {
1.104 raeburn 9139: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9140: $changes{$item}{$type} = 1;
9141: }
1.163 raeburn 9142: } elsif ($context eq 'requestauthor') {
9143: if ($confhash{$type} ne $unset) {
9144: $changes{$type} = 1;
9145: }
1.72 raeburn 9146: } else {
9147: if (!$confhash{$item}{$type}) {
9148: $changes{$item}{$type} = 1;
9149: }
9150: }
9151: }
1.1 raeburn 9152: }
9153: }
1.163 raeburn 9154: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9155: if (ref($domconfig{'quotas'}) eq 'HASH') {
9156: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9157: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9158: if (exists($confhash{'defaultquota'}{$key})) {
9159: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9160: $changes{'defaultquota'}{$key} = 1;
9161: }
9162: } else {
9163: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9164: }
9165: }
1.86 raeburn 9166: } else {
9167: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9168: if (exists($confhash{'defaultquota'}{$key})) {
9169: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9170: $changes{'defaultquota'}{$key} = 1;
9171: }
9172: } else {
9173: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9174: }
1.1 raeburn 9175: }
9176: }
1.197 raeburn 9177: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9178: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9179: if (exists($confhash{'authorquota'}{$key})) {
9180: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9181: $changes{'authorquota'}{$key} = 1;
9182: }
9183: } else {
9184: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9185: }
9186: }
9187: }
1.1 raeburn 9188: }
1.86 raeburn 9189: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9190: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9191: if (ref($domconfig{'quotas'}) eq 'HASH') {
9192: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9193: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9194: $changes{'defaultquota'}{$key} = 1;
9195: }
9196: } else {
9197: if (!exists($domconfig{'quotas'}{$key})) {
9198: $changes{'defaultquota'}{$key} = 1;
9199: }
1.72 raeburn 9200: }
9201: } else {
1.86 raeburn 9202: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9203: }
1.1 raeburn 9204: }
9205: }
1.197 raeburn 9206: if (ref($confhash{'authorquota'}) eq 'HASH') {
9207: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9208: if (ref($domconfig{'quotas'}) eq 'HASH') {
9209: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9210: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9211: $changes{'authorquota'}{$key} = 1;
9212: }
9213: } else {
9214: $changes{'authorquota'}{$key} = 1;
9215: }
9216: } else {
9217: $changes{'authorquota'}{$key} = 1;
9218: }
9219: }
9220: }
1.1 raeburn 9221: }
1.72 raeburn 9222:
1.163 raeburn 9223: if ($context eq 'requestauthor') {
9224: $domdefaults{'requestauthor'} = \%confhash;
9225: } else {
9226: foreach my $key (keys(%confhash)) {
1.242 raeburn 9227: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 9228: $domdefaults{$key} = $confhash{$key};
9229: }
1.163 raeburn 9230: }
1.72 raeburn 9231: }
1.163 raeburn 9232:
1.1 raeburn 9233: my %quotahash = (
1.86 raeburn 9234: $action => { %confhash }
1.1 raeburn 9235: );
9236: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9237: $dom);
9238: if ($putresult eq 'ok') {
9239: if (keys(%changes) > 0) {
1.72 raeburn 9240: my $cachetime = 24*60*60;
9241: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9242: if (ref($lastactref) eq 'HASH') {
9243: $lastactref->{'domdefaults'} = 1;
9244: }
1.1 raeburn 9245: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 9246: unless (($context eq 'requestcourses') ||
1.163 raeburn 9247: ($context eq 'requestauthor')) {
1.86 raeburn 9248: if (ref($changes{'defaultquota'}) eq 'HASH') {
9249: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9250: foreach my $type (@{$types},'default') {
9251: if (defined($changes{'defaultquota'}{$type})) {
9252: my $typetitle = $usertypes->{$type};
9253: if ($type eq 'default') {
9254: $typetitle = $othertitle;
9255: }
1.213 raeburn 9256: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9257: }
9258: }
1.86 raeburn 9259: $resulttext .= '</ul></li>';
1.72 raeburn 9260: }
1.197 raeburn 9261: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 9262: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 9263: foreach my $type (@{$types},'default') {
9264: if (defined($changes{'authorquota'}{$type})) {
9265: my $typetitle = $usertypes->{$type};
9266: if ($type eq 'default') {
9267: $typetitle = $othertitle;
9268: }
1.213 raeburn 9269: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 9270: }
9271: }
9272: $resulttext .= '</ul></li>';
9273: }
1.72 raeburn 9274: }
1.80 raeburn 9275: my %newenv;
1.72 raeburn 9276: foreach my $item (@usertools) {
1.163 raeburn 9277: my (%haschgs,%inconf);
9278: if ($context eq 'requestauthor') {
9279: %haschgs = %changes;
1.210 raeburn 9280: %inconf = %confhash;
1.163 raeburn 9281: } else {
9282: if (ref($changes{$item}) eq 'HASH') {
9283: %haschgs = %{$changes{$item}};
9284: }
9285: if (ref($confhash{$item}) eq 'HASH') {
9286: %inconf = %{$confhash{$item}};
9287: }
9288: }
9289: if (keys(%haschgs) > 0) {
1.80 raeburn 9290: my $newacc =
9291: &Apache::lonnet::usertools_access($env{'user.name'},
9292: $env{'user.domain'},
1.86 raeburn 9293: $item,'reload',$context);
1.210 raeburn 9294: if (($context eq 'requestcourses') ||
1.163 raeburn 9295: ($context eq 'requestauthor')) {
1.108 raeburn 9296: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9297: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9298: }
9299: } else {
9300: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9301: $newenv{'environment.availabletools.'.$item} = $newacc;
9302: }
1.80 raeburn 9303: }
1.163 raeburn 9304: unless ($context eq 'requestauthor') {
9305: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9306: }
1.72 raeburn 9307: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 9308: if ($haschgs{$type}) {
1.72 raeburn 9309: my $typetitle = $usertypes->{$type};
9310: if ($type eq 'default') {
9311: $typetitle = $othertitle;
9312: } elsif ($type eq '_LC_adv') {
9313: $typetitle = 'LON-CAPA Advanced Users';
9314: }
1.163 raeburn 9315: if ($inconf{$type}) {
1.101 raeburn 9316: if ($context eq 'requestcourses') {
9317: my $cond;
1.163 raeburn 9318: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9319: if ($1 eq '') {
9320: $cond = &mt('(Automatic processing of any request).');
9321: } else {
9322: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9323: }
9324: } else {
1.163 raeburn 9325: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9326: }
9327: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 9328: } elsif ($context eq 'requestauthor') {
9329: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9330: $titles{$inconf{$type}},$typetitle);
9331:
1.101 raeburn 9332: } else {
9333: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9334: }
1.72 raeburn 9335: } else {
1.104 raeburn 9336: if ($type eq '_LC_adv') {
1.163 raeburn 9337: if ($inconf{$type} eq '0') {
1.104 raeburn 9338: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9339: } else {
9340: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9341: }
9342: } else {
9343: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9344: }
1.72 raeburn 9345: }
9346: }
1.26 raeburn 9347: }
1.163 raeburn 9348: unless ($context eq 'requestauthor') {
9349: $resulttext .= '</ul></li>';
9350: }
1.26 raeburn 9351: }
1.1 raeburn 9352: }
1.163 raeburn 9353: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9354: if (ref($changes{'notify'}) eq 'HASH') {
9355: if ($changes{'notify'}{'approval'}) {
9356: if (ref($confhash{'notify'}) eq 'HASH') {
9357: if ($confhash{'notify'}{'approval'}) {
9358: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9359: } else {
1.163 raeburn 9360: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9361: }
9362: }
9363: }
9364: }
9365: }
1.216 raeburn 9366: if ($action eq 'requestcourses') {
9367: my @offon = ('off','on');
9368: if ($changes{'uniquecode'}) {
1.218 raeburn 9369: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9370: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9371: $resulttext .= '<li>'.
9372: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9373: '</li>';
9374: } else {
9375: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9376: '</li>';
9377: }
1.216 raeburn 9378: }
1.242 raeburn 9379: foreach my $type ('textbooks','templates') {
9380: if (ref($changes{$type}) eq 'HASH') {
9381: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9382: foreach my $key (sort(keys(%{$changes{$type}}))) {
9383: my %coursehash = &Apache::lonnet::coursedescription($key);
9384: my $coursetitle = $coursehash{'description'};
9385: my $position = $confhash{$type}{$key}{'order'} + 1;
9386: $resulttext .= '<li>';
1.243 raeburn 9387: foreach my $item ('subject','title','publisher','author') {
9388: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9389: ($type eq 'templates'));
1.242 raeburn 9390: my $name = $item.':';
9391: $name =~ s/^(\w)/\U$1/;
9392: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9393: }
9394: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9395: if ($type eq 'textbooks') {
9396: if ($confhash{$type}{$key}{'image'}) {
9397: $resulttext .= ' '.&mt('Image: [_1]',
9398: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9399: ' alt="Textbook cover" />').'<br />';
9400: }
9401: }
9402: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 9403: }
1.242 raeburn 9404: $resulttext .= '</ul></li>';
1.216 raeburn 9405: }
9406: }
1.235 raeburn 9407: if (ref($changes{'validation'}) eq 'HASH') {
9408: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9409: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9410: foreach my $item (@{$validationitemsref}) {
9411: if (exists($changes{'validation'}{$item})) {
9412: if ($item eq 'markup') {
9413: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9414: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9415: } else {
9416: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9417: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9418: }
9419: }
9420: }
9421: if (exists($changes{'validation'}{'dc'})) {
9422: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9423: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9424: }
9425: }
9426: }
1.216 raeburn 9427: }
1.1 raeburn 9428: $resulttext .= '</ul>';
1.80 raeburn 9429: if (keys(%newenv)) {
9430: &Apache::lonnet::appenv(\%newenv);
9431: }
1.1 raeburn 9432: } else {
1.86 raeburn 9433: if ($context eq 'requestcourses') {
9434: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 9435: } elsif ($context eq 'requestauthor') {
9436: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9437: } else {
1.90 weissno 9438: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9439: }
1.1 raeburn 9440: }
9441: } else {
1.11 albertel 9442: $resulttext = '<span class="LC_error">'.
9443: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9444: }
1.216 raeburn 9445: if ($errors) {
9446: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9447: '<ul>'.$errors.'</ul></p>';
9448: }
1.3 raeburn 9449: return $resulttext;
1.1 raeburn 9450: }
9451:
1.216 raeburn 9452: sub process_textbook_image {
1.242 raeburn 9453: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 9454: my $filename = $env{'form.'.$caller.'.filename'};
9455: my ($error,$url);
9456: my ($width,$height) = (50,50);
9457: if ($configuserok eq 'ok') {
9458: if ($switchserver) {
9459: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9460: $switchserver);
9461: } elsif ($author_ok eq 'ok') {
9462: my ($result,$imageurl) =
9463: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 9464: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 9465: if ($result eq 'ok') {
9466: $url = $imageurl;
9467: } else {
9468: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9469: }
9470: } else {
9471: $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);
9472: }
9473: } else {
9474: $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);
9475: }
9476: return ($url,$error);
9477: }
9478:
1.267 raeburn 9479: sub modify_ltitools {
9480: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9481: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 ! raeburn 9482: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 9483: my $confname = $dom.'-domainconfig';
9484: my $servadm = $r->dir_config('lonAdmEMail');
9485: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9486: my (%posslti,%possfield);
9487: my @courseroles = ('cc','in','ta','ep','st');
9488: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9489: map { $posslti{$_} = 1; } @ltiroles;
9490: my @allfields = ('fullname','firstname','lastname','email','user','roles');
9491: map { $possfield{$_} = 1; } @allfields;
9492: my %lt = <itools_names();
9493: if ($env{'form.ltitools_add'}) {
9494: my $title = $env{'form.ltitools_add_title'};
9495: $title =~ s/(`)/'/g;
9496: ($newid,my $error) = &get_ltitools_id($dom,$title);
9497: if ($newid) {
9498: my $position = $env{'form.ltitools_add_pos'};
9499: $position =~ s/\D+//g;
9500: if ($position ne '') {
9501: $allpos[$position] = $newid;
9502: }
9503: $changes{$newid} = 1;
9504: foreach my $item ('title','url','key','secret') {
9505: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9506: if ($env{'form.ltitools_add_'.$item}) {
1.297 ! raeburn 9507: if (($item eq 'key') || ($item eq 'secret')) {
! 9508: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
! 9509: } else {
! 9510: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
! 9511: }
1.267 raeburn 9512: }
9513: }
9514: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9515: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9516: }
9517: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9518: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9519: }
1.296 raeburn 9520: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 9521: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9522: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 9523: if (($item eq 'width') || ($item eq 'height')) {
9524: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9525: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9526: }
9527: } else {
9528: if ($env{'form.ltitools_add_'.$item} ne '') {
9529: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9530: }
1.267 raeburn 9531: }
9532: }
9533: if ($env{'form.ltitools_add_target'} eq 'window') {
9534: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9535: } else {
9536: $confhash{$newid}{'display'}{'target'} = 'iframe';
9537: }
9538: foreach my $item ('passback','roster') {
9539: if ($env{'form.ltitools_add_'.$item}) {
9540: $confhash{$newid}{$item} = 1;
9541: }
9542: }
9543: if ($env{'form.ltitools_add_image.filename'} ne '') {
9544: my ($imageurl,$error) =
9545: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
9546: $configuserok,$switchserver,$author_ok);
9547: if ($imageurl) {
9548: $confhash{$newid}{'image'} = $imageurl;
9549: }
9550: if ($error) {
9551: &Apache::lonnet::logthis($error);
9552: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9553: }
9554: }
9555: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9556: foreach my $field (@fields) {
9557: if ($possfield{$field}) {
9558: if ($field eq 'roles') {
9559: foreach my $role (@courseroles) {
9560: my $choice = $env{'form.ltitools_add_roles_'.$role};
9561: if (($choice ne '') && ($posslti{$choice})) {
9562: $confhash{$newid}{'roles'}{$role} = $choice;
9563: if ($role eq 'cc') {
9564: $confhash{$newid}{'roles'}{'co'} = $choice;
9565: }
9566: }
9567: }
9568: } else {
9569: $confhash{$newid}{'fields'}{$field} = 1;
9570: }
9571: }
9572: }
1.273 raeburn 9573: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9574: foreach my $item (@courseconfig) {
9575: $confhash{$newid}{'crsconf'}{$item} = 1;
9576: }
1.267 raeburn 9577: if ($env{'form.ltitools_add_custom'}) {
9578: my $name = $env{'form.ltitools_add_custom_name'};
9579: my $value = $env{'form.ltitools_add_custom_value'};
9580: $value =~ s/(`)/'/g;
9581: $name =~ s/(`)/'/g;
9582: $confhash{$newid}{'custom'}{$name} = $value;
9583: }
9584: } else {
9585: my $error = &mt('Failed to acquire unique ID for new external tool');
9586: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9587: }
9588: }
9589: if (ref($domconfig{$action}) eq 'HASH') {
9590: my %deletions;
9591: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9592: if (@todelete) {
9593: map { $deletions{$_} = 1; } @todelete;
9594: }
9595: my %customadds;
9596: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9597: if (@newcustom) {
9598: map { $customadds{$_} = 1; } @newcustom;
9599: }
9600: my %imgdeletions;
9601: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9602: if (@todeleteimages) {
9603: map { $imgdeletions{$_} = 1; } @todeleteimages;
9604: }
9605: my $maxnum = $env{'form.ltitools_maxnum'};
9606: for (my $i=0; $i<=$maxnum; $i++) {
9607: my $itemid = $env{'form.ltitools_id_'.$i};
9608: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9609: if ($deletions{$itemid}) {
9610: if ($domconfig{$action}{$itemid}{'image'}) {
9611: #FIXME need to obsolete item in RES space
9612: }
9613: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9614: next;
9615: } else {
9616: my $newpos = $env{'form.ltitools_'.$itemid};
9617: $newpos =~ s/\D+//g;
1.297 ! raeburn 9618: foreach my $item ('title','url') {
1.267 raeburn 9619: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9620: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9621: $changes{$itemid} = 1;
9622: }
9623: }
1.297 ! raeburn 9624: foreach my $item ('key','secret') {
! 9625: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
! 9626: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
! 9627: $changes{$itemid} = 1;
! 9628: }
! 9629: }
1.267 raeburn 9630: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9631: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9632: }
9633: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9634: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9635: }
9636: foreach my $size ('width','height') {
9637: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9638: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9639: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9640: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9641: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9642: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9643: $changes{$itemid} = 1;
9644: }
9645: } else {
9646: $changes{$itemid} = 1;
9647: }
1.296 raeburn 9648: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9649: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
9650: $changes{$itemid} = 1;
9651: }
9652: }
9653: }
9654: foreach my $item ('linktext','explanation') {
9655: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
9656: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
9657: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
9658: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9659: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9660: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
9661: $changes{$itemid} = 1;
9662: }
9663: } else {
9664: $changes{$itemid} = 1;
9665: }
9666: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9667: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
9668: $changes{$itemid} = 1;
9669: }
1.267 raeburn 9670: }
9671: }
9672: if ($env{'form.ltitools_target_'.$i} eq 'window') {
9673: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9674: } else {
9675: $confhash{$itemid}{'display'}{'target'} = 'iframe';
9676: }
9677: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9678: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
9679: $changes{$itemid} = 1;
9680: }
9681: } else {
9682: $changes{$itemid} = 1;
9683: }
9684: foreach my $extra ('passback','roster') {
9685: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
9686: $confhash{$itemid}{$extra} = 1;
9687: }
9688: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
9689: $changes{$itemid} = 1;
9690: }
9691: }
1.273 raeburn 9692: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.296 raeburn 9693: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 9694: if (grep(/^\Q$item\E$/,@courseconfig)) {
9695: $confhash{$itemid}{'crsconf'}{$item} = 1;
9696: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
9697: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
9698: $changes{$itemid} = 1;
9699: }
9700: } else {
9701: $changes{$itemid} = 1;
9702: }
9703: }
9704: }
1.267 raeburn 9705: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
9706: foreach my $field (@fields) {
9707: if ($possfield{$field}) {
9708: if ($field eq 'roles') {
9709: foreach my $role (@courseroles) {
9710: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
9711: if (($choice ne '') && ($posslti{$choice})) {
9712: $confhash{$itemid}{'roles'}{$role} = $choice;
9713: if ($role eq 'cc') {
9714: $confhash{$itemid}{'roles'}{'co'} = $choice;
9715: }
9716: }
9717: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
9718: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
9719: $changes{$itemid} = 1;
9720: }
9721: } elsif ($confhash{$itemid}{'roles'}{$role}) {
9722: $changes{$itemid} = 1;
9723: }
9724: }
9725: } else {
9726: $confhash{$itemid}{'fields'}{$field} = 1;
9727: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9728: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9729: $changes{$itemid} = 1;
9730: }
9731: } else {
9732: $changes{$itemid} = 1;
9733: }
9734: }
9735: }
9736: }
9737: $allpos[$newpos] = $itemid;
9738: }
9739: if ($imgdeletions{$itemid}) {
9740: $changes{$itemid} = 1;
9741: #FIXME need to obsolete item in RES space
9742: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9743: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9744: $itemid,$configuserok,$switchserver,
9745: $author_ok);
9746: if ($imgurl) {
9747: $confhash{$itemid}{'image'} = $imgurl;
9748: $changes{$itemid} = 1;
9749: }
9750: if ($error) {
9751: &Apache::lonnet::logthis($error);
9752: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9753: }
9754: } elsif ($domconfig{$action}{$itemid}{'image'}) {
9755: $confhash{$itemid}{'image'} =
9756: $domconfig{$action}{$itemid}{'image'};
9757: }
9758: if ($customadds{$i}) {
9759: my $name = $env{'form.ltitools_custom_name_'.$i};
9760: $name =~ s/(`)/'/g;
9761: $name =~ s/^\s+//;
9762: $name =~ s/\s+$//;
9763: my $value = $env{'form.ltitools_custom_value_'.$i};
9764: $value =~ s/(`)/'/g;
9765: $value =~ s/^\s+//;
9766: $value =~ s/\s+$//;
9767: if ($name ne '') {
9768: $confhash{$itemid}{'custom'}{$name} = $value;
9769: $changes{$itemid} = 1;
9770: }
9771: }
9772: my %customdels;
9773: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9774: if (@customdeletions) {
9775: $changes{$itemid} = 1;
9776: }
9777: map { $customdels{$_} = 1; } @customdeletions;
9778: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9779: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9780: unless ($customdels{$key}) {
9781: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9782: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9783: }
9784: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9785: $changes{$itemid} = 1;
9786: }
9787: }
9788: }
9789: }
9790: unless ($changes{$itemid}) {
9791: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9792: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9793: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9794: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9795: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9796: $changes{$itemid} = 1;
9797: last;
9798: }
9799: }
9800: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9801: $changes{$itemid} = 1;
9802: }
9803: }
9804: last if ($changes{$itemid});
9805: }
9806: }
9807: }
9808: }
9809: }
9810: if (@allpos > 0) {
9811: my $idx = 0;
9812: foreach my $itemid (@allpos) {
9813: if ($itemid ne '') {
9814: $confhash{$itemid}{'order'} = $idx;
9815: if (ref($domconfig{$action}) eq 'HASH') {
9816: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9817: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9818: $changes{$itemid} = 1;
9819: }
9820: }
9821: }
9822: $idx ++;
9823: }
9824: }
9825: }
9826: my %ltitoolshash = (
9827: $action => { %confhash }
9828: );
9829: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9830: $dom);
9831: if ($putresult eq 'ok') {
1.297 ! raeburn 9832: my %ltienchash = (
! 9833: $action => { %encconfig }
! 9834: );
! 9835: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 9836: if (keys(%changes) > 0) {
9837: my $cachetime = 24*60*60;
1.297 ! raeburn 9838: my %ltiall = %confhash;
! 9839: foreach my $id (keys(%ltiall)) {
! 9840: if (ref($encconfig{$id}) eq 'HASH') {
! 9841: foreach my $item ('key','secret') {
! 9842: $ltiall{$id}{$item} = $encconfig{$id}{$item};
! 9843: }
! 9844: }
! 9845: }
! 9846: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 9847: if (ref($lastactref) eq 'HASH') {
9848: $lastactref->{'ltitools'} = 1;
9849: }
9850: $resulttext = &mt('Changes made:').'<ul>';
9851: my %bynum;
9852: foreach my $itemid (sort(keys(%changes))) {
9853: my $position = $confhash{$itemid}{'order'};
9854: $bynum{$position} = $itemid;
9855: }
9856: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9857: my $itemid = $bynum{$pos};
9858: if (ref($confhash{$itemid}) ne 'HASH') {
9859: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9860: } else {
9861: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9862: if ($confhash{$itemid}{'image'}) {
9863: $resulttext .= ' '.
9864: '<img src="'.$confhash{$itemid}{'image'}.'"'.
9865: ' alt="'.&mt('Tool Provider icon').'" />';
9866: }
9867: $resulttext .= '</li><ul>';
9868: my $position = $pos + 1;
9869: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.297 ! raeburn 9870: foreach my $item ('version','msgtype','url') {
1.267 raeburn 9871: if ($confhash{$itemid}{$item} ne '') {
9872: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9873: }
9874: }
1.297 ! raeburn 9875: if ($encconfig{$itemid}{'key'} ne '') {
! 9876: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
! 9877: }
! 9878: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 9879: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 ! raeburn 9880: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 9881: $resulttext .= ('*'x$num).'</li>';
9882: }
1.273 raeburn 9883: $resulttext .= '<li>'.&mt('Configurable in course:');
1.296 raeburn 9884: my @possconfig = ('label','title','target','linktext','explanation');
1.273 raeburn 9885: my $numconfig = 0;
9886: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9887: foreach my $item (@possconfig) {
9888: if ($confhash{$itemid}{'crsconf'}{$item}) {
9889: $numconfig ++;
1.296 raeburn 9890: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 9891: }
9892: }
9893: }
9894: if (!$numconfig) {
9895: $resulttext .= &mt('None');
9896: }
9897: $resulttext .= '</li>';
1.267 raeburn 9898: foreach my $item ('passback','roster') {
9899: $resulttext .= '<li>'.$lt{$item}.' ';
9900: if ($confhash{$itemid}{$item}) {
9901: $resulttext .= &mt('Yes');
9902: } else {
9903: $resulttext .= &mt('No');
9904: }
9905: $resulttext .= '</li>';
9906: }
9907: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9908: my $displaylist;
9909: if ($confhash{$itemid}{'display'}{'target'}) {
9910: $displaylist = &mt('Display target').': '.
9911: $confhash{$itemid}{'display'}{'target'}.',';
9912: }
9913: foreach my $size ('width','height') {
9914: if ($confhash{$itemid}{'display'}{$size}) {
9915: $displaylist .= (' 'x2).$lt{$size}.': '.
9916: $confhash{$itemid}{'display'}{$size}.',';
9917: }
9918: }
9919: if ($displaylist) {
9920: $displaylist =~ s/,$//;
9921: $resulttext .= '<li>'.$displaylist.'</li>';
9922: }
1.296 raeburn 9923: foreach my $item ('linktext','explanation') {
9924: if ($confhash{$itemid}{'display'}{$item}) {
9925: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
9926: }
9927: }
9928: }
1.267 raeburn 9929: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9930: my $fieldlist;
9931: foreach my $field (@allfields) {
9932: if ($confhash{$itemid}{'fields'}{$field}) {
9933: $fieldlist .= (' 'x2).$lt{$field}.',';
9934: }
9935: }
9936: if ($fieldlist) {
9937: $fieldlist =~ s/,$//;
9938: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9939: }
9940: }
9941: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9942: my $rolemaps;
9943: foreach my $role (@courseroles) {
9944: if ($confhash{$itemid}{'roles'}{$role}) {
9945: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9946: $confhash{$itemid}{'roles'}{$role}.',';
9947: }
9948: }
9949: if ($rolemaps) {
9950: $rolemaps =~ s/,$//;
9951: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9952: }
9953: }
9954: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9955: my $customlist;
9956: if (keys(%{$confhash{$itemid}{'custom'}})) {
9957: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9958: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9959: }
9960: }
9961: if ($customlist) {
9962: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9963: }
9964: }
9965: $resulttext .= '</ul></li>';
9966: }
9967: }
9968: $resulttext .= '</ul>';
9969: } else {
9970: $resulttext = &mt('No changes made.');
9971: }
9972: } else {
9973: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9974: }
9975: if ($errors) {
9976: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9977: $errors.'</ul>';
9978: }
9979: return $resulttext;
9980: }
9981:
9982: sub process_ltitools_image {
9983: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9984: my $filename = $env{'form.'.$caller.'.filename'};
9985: my ($error,$url);
9986: my ($width,$height) = (21,21);
9987: if ($configuserok eq 'ok') {
9988: if ($switchserver) {
9989: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9990: $switchserver);
9991: } elsif ($author_ok eq 'ok') {
9992: my ($result,$imageurl,$madethumb) =
9993: &publishlogo($r,'upload',$caller,$dom,$confname,
9994: "ltitools/$itemid/icon",$width,$height);
9995: if ($result eq 'ok') {
9996: if ($madethumb) {
9997: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9998: my $imagethumb = "$path/tn-".$imagefile;
9999: $url = $imagethumb;
10000: } else {
10001: $url = $imageurl;
10002: }
10003: } else {
10004: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10005: }
10006: } else {
10007: $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);
10008: }
10009: } else {
10010: $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);
10011: }
10012: return ($url,$error);
10013: }
10014:
10015: sub get_ltitools_id {
10016: my ($cdom,$title) = @_;
10017: # get lock on ltitools db
10018: my $lockhash = {
10019: lock => $env{'user.name'}.
10020: ':'.$env{'user.domain'},
10021: };
10022: my $tries = 0;
10023: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10024: my ($id,$error);
10025:
10026: while (($gotlock ne 'ok') && ($tries<10)) {
10027: $tries ++;
10028: sleep (0.1);
10029: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10030: }
10031: if ($gotlock eq 'ok') {
10032: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
10033: if ($currids{'lock'}) {
10034: delete($currids{'lock'});
10035: if (keys(%currids)) {
10036: my @curr = sort { $a <=> $b } keys(%currids);
10037: if ($curr[-1] =~ /^\d+$/) {
10038: $id = 1 + $curr[-1];
10039: }
10040: } else {
10041: $id = 1;
10042: }
10043: if ($id) {
10044: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
10045: $error = 'nostore';
10046: }
10047: } else {
10048: $error = 'nonumber';
10049: }
10050: }
10051: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
10052: } else {
10053: $error = 'nolock';
10054: }
10055: return ($id,$error);
10056: }
10057:
1.3 raeburn 10058: sub modify_autoenroll {
1.205 raeburn 10059: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 10060: my ($resulttext,%changes);
10061: my %currautoenroll;
10062: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
10063: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
10064: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
10065: }
10066: }
10067: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
10068: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 10069: sender => 'Sender for notification messages',
1.274 raeburn 10070: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
10071: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 10072: my @offon = ('off','on');
1.17 raeburn 10073: my $sender_uname = $env{'form.sender_uname'};
10074: my $sender_domain = $env{'form.sender_domain'};
10075: if ($sender_domain eq '') {
10076: $sender_uname = '';
10077: } elsif ($sender_uname eq '') {
10078: $sender_domain = '';
10079: }
1.129 raeburn 10080: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 10081: my $failsafe = $env{'form.autoenroll_failsafe'};
10082: $failsafe =~ s{^\s+|\s+$}{}g;
10083: if ($failsafe =~ /\D/) {
10084: undef($failsafe);
10085: }
1.1 raeburn 10086: my %autoenrollhash = (
1.129 raeburn 10087: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10088: 'sender_uname' => $sender_uname,
10089: 'sender_domain' => $sender_domain,
10090: 'co-owners' => $coowners,
1.274 raeburn 10091: 'autofailsafe' => $failsafe,
1.1 raeburn 10092: }
10093: );
1.4 raeburn 10094: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10095: $dom);
1.1 raeburn 10096: if ($putresult eq 'ok') {
10097: if (exists($currautoenroll{'run'})) {
10098: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10099: $changes{'run'} = 1;
10100: }
10101: } elsif ($autorun) {
10102: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 10103: $changes{'run'} = 1;
1.1 raeburn 10104: }
10105: }
1.17 raeburn 10106: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 10107: $changes{'sender'} = 1;
10108: }
1.17 raeburn 10109: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 10110: $changes{'sender'} = 1;
10111: }
1.129 raeburn 10112: if ($currautoenroll{'co-owners'} ne '') {
10113: if ($currautoenroll{'co-owners'} ne $coowners) {
10114: $changes{'coowners'} = 1;
10115: }
10116: } elsif ($coowners) {
10117: $changes{'coowners'} = 1;
1.274 raeburn 10118: }
10119: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10120: $changes{'autofailsafe'} = 1;
10121: }
1.1 raeburn 10122: if (keys(%changes) > 0) {
10123: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 10124: if ($changes{'run'}) {
1.1 raeburn 10125: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10126: }
10127: if ($changes{'sender'}) {
1.17 raeburn 10128: if ($sender_uname eq '' || $sender_domain eq '') {
10129: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10130: } else {
10131: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10132: }
1.1 raeburn 10133: }
1.129 raeburn 10134: if ($changes{'coowners'}) {
10135: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10136: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10137: if (ref($lastactref) eq 'HASH') {
10138: $lastactref->{'domainconfig'} = 1;
10139: }
1.129 raeburn 10140: }
1.274 raeburn 10141: if ($changes{'autofailsafe'}) {
10142: if ($failsafe ne '') {
10143: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
10144: } else {
10145: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
10146: }
10147: &Apache::lonnet::get_domain_defaults($dom,1);
10148: if (ref($lastactref) eq 'HASH') {
10149: $lastactref->{'domdefaults'} = 1;
10150: }
10151: }
1.1 raeburn 10152: $resulttext .= '</ul>';
10153: } else {
10154: $resulttext = &mt('No changes made to auto-enrollment settings');
10155: }
10156: } else {
1.11 albertel 10157: $resulttext = '<span class="LC_error">'.
10158: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10159: }
1.3 raeburn 10160: return $resulttext;
1.1 raeburn 10161: }
10162:
10163: sub modify_autoupdate {
1.3 raeburn 10164: my ($dom,%domconfig) = @_;
1.1 raeburn 10165: my ($resulttext,%currautoupdate,%fields,%changes);
10166: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10167: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10168: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10169: }
10170: }
10171: my @offon = ('off','on');
10172: my %title = &Apache::lonlocal::texthash (
10173: run => 'Auto-update:',
10174: classlists => 'Updates to user information in classlists?'
10175: );
1.44 raeburn 10176: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10177: my %fieldtitles = &Apache::lonlocal::texthash (
10178: id => 'Student/Employee ID',
1.20 raeburn 10179: permanentemail => 'E-mail address',
1.1 raeburn 10180: lastname => 'Last Name',
10181: firstname => 'First Name',
10182: middlename => 'Middle Name',
1.132 raeburn 10183: generation => 'Generation',
1.1 raeburn 10184: );
1.142 raeburn 10185: $othertitle = &mt('All users');
1.1 raeburn 10186: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10187: $othertitle = &mt('Other users');
1.1 raeburn 10188: }
10189: foreach my $key (keys(%env)) {
10190: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10191: my ($usertype,$item) = ($1,$2);
10192: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10193: if ($usertype eq 'default') {
10194: push(@{$fields{$1}},$2);
10195: } elsif (ref($types) eq 'ARRAY') {
10196: if (grep(/^\Q$usertype\E$/,@{$types})) {
10197: push(@{$fields{$1}},$2);
10198: }
10199: }
10200: }
1.1 raeburn 10201: }
10202: }
1.131 raeburn 10203: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10204: @lockablenames = sort(@lockablenames);
10205: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10206: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10207: if (@changed) {
10208: $changes{'lockablenames'} = 1;
10209: }
10210: } else {
10211: if (@lockablenames) {
10212: $changes{'lockablenames'} = 1;
10213: }
10214: }
1.1 raeburn 10215: my %updatehash = (
10216: autoupdate => { run => $env{'form.autoupdate_run'},
10217: classlists => $env{'form.classlists'},
10218: fields => {%fields},
1.131 raeburn 10219: lockablenames => \@lockablenames,
1.1 raeburn 10220: }
10221: );
10222: foreach my $key (keys(%currautoupdate)) {
10223: if (($key eq 'run') || ($key eq 'classlists')) {
10224: if (exists($updatehash{autoupdate}{$key})) {
10225: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10226: $changes{$key} = 1;
10227: }
10228: }
10229: } elsif ($key eq 'fields') {
10230: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10231: foreach my $item (@{$types},'default') {
1.1 raeburn 10232: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10233: my $change = 0;
10234: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10235: if (!exists($fields{$item})) {
10236: $change = 1;
1.132 raeburn 10237: last;
1.1 raeburn 10238: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10239: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10240: $change = 1;
1.132 raeburn 10241: last;
1.1 raeburn 10242: }
10243: }
10244: }
10245: if ($change) {
10246: push(@{$changes{$key}},$item);
10247: }
1.26 raeburn 10248: }
1.1 raeburn 10249: }
10250: }
1.131 raeburn 10251: } elsif ($key eq 'lockablenames') {
10252: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10253: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10254: if (@changed) {
10255: $changes{'lockablenames'} = 1;
10256: }
10257: } else {
10258: if (@lockablenames) {
10259: $changes{'lockablenames'} = 1;
10260: }
10261: }
10262: }
10263: }
10264: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10265: if (@lockablenames) {
10266: $changes{'lockablenames'} = 1;
1.1 raeburn 10267: }
10268: }
1.26 raeburn 10269: foreach my $item (@{$types},'default') {
10270: if (defined($fields{$item})) {
10271: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10272: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10273: my $change = 0;
10274: if (ref($fields{$item}) eq 'ARRAY') {
10275: foreach my $type (@{$fields{$item}}) {
10276: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10277: $change = 1;
10278: last;
10279: }
10280: }
10281: }
10282: if ($change) {
10283: push(@{$changes{'fields'}},$item);
10284: }
10285: } else {
1.26 raeburn 10286: push(@{$changes{'fields'}},$item);
10287: }
10288: } else {
10289: push(@{$changes{'fields'}},$item);
1.1 raeburn 10290: }
10291: }
10292: }
10293: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10294: $dom);
10295: if ($putresult eq 'ok') {
10296: if (keys(%changes) > 0) {
10297: $resulttext = &mt('Changes made:').'<ul>';
10298: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10299: if ($key eq 'lockablenames') {
10300: $resulttext .= '<li>';
10301: if (@lockablenames) {
10302: $usertypes->{'default'} = $othertitle;
10303: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10304: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10305: } else {
10306: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10307: }
10308: $resulttext .= '</li>';
10309: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10310: foreach my $item (@{$changes{$key}}) {
10311: my @newvalues;
10312: foreach my $type (@{$fields{$item}}) {
10313: push(@newvalues,$fieldtitles{$type});
10314: }
1.3 raeburn 10315: my $newvaluestr;
10316: if (@newvalues > 0) {
10317: $newvaluestr = join(', ',@newvalues);
10318: } else {
10319: $newvaluestr = &mt('none');
1.6 raeburn 10320: }
1.1 raeburn 10321: if ($item eq 'default') {
1.26 raeburn 10322: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10323: } else {
1.26 raeburn 10324: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10325: }
10326: }
10327: } else {
10328: my $newvalue;
10329: if ($key eq 'run') {
10330: $newvalue = $offon[$env{'form.autoupdate_run'}];
10331: } else {
10332: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10333: }
1.1 raeburn 10334: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10335: }
10336: }
10337: $resulttext .= '</ul>';
10338: } else {
1.3 raeburn 10339: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10340: }
10341: } else {
1.11 albertel 10342: $resulttext = '<span class="LC_error">'.
10343: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10344: }
1.3 raeburn 10345: return $resulttext;
1.1 raeburn 10346: }
10347:
1.125 raeburn 10348: sub modify_autocreate {
10349: my ($dom,%domconfig) = @_;
10350: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10351: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10352: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10353: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10354: }
10355: }
10356: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10357: req => 'Auto-creation of validated requests for official courses',
10358: xmldc => 'Identity of course creator of courses from XML files',
10359: );
10360: my @types = ('xml','req');
10361: foreach my $item (@types) {
10362: $newvals{$item} = $env{'form.autocreate_'.$item};
10363: $newvals{$item} =~ s/\D//g;
10364: $newvals{$item} = 0 if ($newvals{$item} eq '');
10365: }
10366: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 10367: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10368: unless (exists($domcoords{$newvals{'xmldc'}})) {
10369: $newvals{'xmldc'} = '';
10370: }
10371: %autocreatehash = (
10372: autocreate => { xml => $newvals{'xml'},
10373: req => $newvals{'req'},
10374: }
10375: );
10376: if ($newvals{'xmldc'} ne '') {
10377: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10378: }
10379: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10380: $dom);
10381: if ($putresult eq 'ok') {
10382: my @items = @types;
10383: if ($newvals{'xml'}) {
10384: push(@items,'xmldc');
10385: }
10386: foreach my $item (@items) {
10387: if (exists($currautocreate{$item})) {
10388: if ($currautocreate{$item} ne $newvals{$item}) {
10389: $changes{$item} = 1;
10390: }
10391: } elsif ($newvals{$item}) {
10392: $changes{$item} = 1;
10393: }
10394: }
10395: if (keys(%changes) > 0) {
10396: my @offon = ('off','on');
10397: $resulttext = &mt('Changes made:').'<ul>';
10398: foreach my $item (@types) {
10399: if ($changes{$item}) {
10400: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 10401: $resulttext .= '<li>'.
10402: &mt("$title{$item} set to [_1]$newtxt [_2]",
10403: '<b>','</b>').
10404: '</li>';
1.125 raeburn 10405: }
10406: }
10407: if ($changes{'xmldc'}) {
10408: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10409: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 10410: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10411: }
10412: $resulttext .= '</ul>';
10413: } else {
10414: $resulttext = &mt('No changes made to auto-creation settings');
10415: }
10416: } else {
10417: $resulttext = '<span class="LC_error">'.
10418: &mt('An error occurred: [_1]',$putresult).'</span>';
10419: }
10420: return $resulttext;
10421: }
10422:
1.23 raeburn 10423: sub modify_directorysrch {
1.295 raeburn 10424: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10425: my ($resulttext,%changes);
10426: my %currdirsrch;
10427: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10428: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10429: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10430: }
10431: }
1.277 raeburn 10432: my %title = ( available => 'Institutional directory search available',
10433: localonly => 'Other domains can search institution',
10434: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 10435: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10436: searchby => 'Search types',
10437: searchtypes => 'Search latitude');
10438: my @offon = ('off','on');
1.24 raeburn 10439: my @otherdoms = ('Yes','No');
1.23 raeburn 10440:
1.25 raeburn 10441: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10442: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10443: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10444:
1.44 raeburn 10445: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10446: if (keys(%{$usertypes}) == 0) {
10447: @cansearch = ('default');
10448: } else {
10449: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10450: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10451: if (!grep(/^\Q$type\E$/,@cansearch)) {
10452: push(@{$changes{'cansearch'}},$type);
10453: }
1.23 raeburn 10454: }
1.26 raeburn 10455: foreach my $type (@cansearch) {
10456: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10457: push(@{$changes{'cansearch'}},$type);
10458: }
1.23 raeburn 10459: }
1.26 raeburn 10460: } else {
10461: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10462: }
10463: }
10464:
10465: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10466: foreach my $by (@{$currdirsrch{'searchby'}}) {
10467: if (!grep(/^\Q$by\E$/,@searchby)) {
10468: push(@{$changes{'searchby'}},$by);
10469: }
10470: }
10471: foreach my $by (@searchby) {
10472: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10473: push(@{$changes{'searchby'}},$by);
10474: }
10475: }
10476: } else {
10477: push(@{$changes{'searchby'}},@searchby);
10478: }
1.25 raeburn 10479:
10480: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10481: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10482: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10483: push(@{$changes{'searchtypes'}},$type);
10484: }
10485: }
10486: foreach my $type (@searchtypes) {
10487: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10488: push(@{$changes{'searchtypes'}},$type);
10489: }
10490: }
10491: } else {
10492: if (exists($currdirsrch{'searchtypes'})) {
10493: foreach my $type (@searchtypes) {
10494: if ($type ne $currdirsrch{'searchtypes'}) {
10495: push(@{$changes{'searchtypes'}},$type);
10496: }
10497: }
10498: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10499: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10500: }
10501: } else {
10502: push(@{$changes{'searchtypes'}},@searchtypes);
10503: }
10504: }
10505:
1.23 raeburn 10506: my %dirsrch_hash = (
10507: directorysrch => { available => $env{'form.dirsrch_available'},
10508: cansearch => \@cansearch,
1.277 raeburn 10509: localonly => $env{'form.dirsrch_instlocalonly'},
10510: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10511: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10512: searchby => \@searchby,
1.25 raeburn 10513: searchtypes => \@searchtypes,
1.23 raeburn 10514: }
10515: );
10516: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10517: $dom);
10518: if ($putresult eq 'ok') {
10519: if (exists($currdirsrch{'available'})) {
10520: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10521: $changes{'available'} = 1;
10522: }
10523: } else {
10524: if ($env{'form.dirsrch_available'} eq '1') {
10525: $changes{'available'} = 1;
10526: }
10527: }
1.277 raeburn 10528: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 10529: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10530: $changes{'lcavailable'} = 1;
10531: }
1.277 raeburn 10532: } else {
10533: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10534: $changes{'lcavailable'} = 1;
10535: }
10536: }
1.24 raeburn 10537: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 10538: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
10539: $changes{'localonly'} = 1;
10540: }
1.24 raeburn 10541: } else {
1.277 raeburn 10542: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 10543: $changes{'localonly'} = 1;
10544: }
10545: }
1.277 raeburn 10546: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 10547: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10548: $changes{'lclocalonly'} = 1;
10549: }
1.277 raeburn 10550: } else {
10551: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10552: $changes{'lclocalonly'} = 1;
10553: }
10554: }
1.23 raeburn 10555: if (keys(%changes) > 0) {
10556: $resulttext = &mt('Changes made:').'<ul>';
10557: if ($changes{'available'}) {
10558: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10559: }
1.277 raeburn 10560: if ($changes{'lcavailable'}) {
10561: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10562: }
1.24 raeburn 10563: if ($changes{'localonly'}) {
1.277 raeburn 10564: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 10565: }
1.277 raeburn 10566: if ($changes{'lclocalonly'}) {
10567: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 10568: }
1.23 raeburn 10569: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10570: my $chgtext;
1.26 raeburn 10571: if (ref($usertypes) eq 'HASH') {
10572: if (keys(%{$usertypes}) > 0) {
10573: foreach my $type (@{$types}) {
10574: if (grep(/^\Q$type\E$/,@cansearch)) {
10575: $chgtext .= $usertypes->{$type}.'; ';
10576: }
10577: }
10578: if (grep(/^default$/,@cansearch)) {
10579: $chgtext .= $othertitle;
10580: } else {
10581: $chgtext =~ s/\; $//;
10582: }
1.210 raeburn 10583: $resulttext .=
1.178 raeburn 10584: '<li>'.
10585: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10586: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10587: '</li>';
1.23 raeburn 10588: }
10589: }
10590: }
10591: if (ref($changes{'searchby'}) eq 'ARRAY') {
10592: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10593: my $chgtext;
10594: foreach my $type (@{$titleorder}) {
10595: if (grep(/^\Q$type\E$/,@searchby)) {
10596: if (defined($searchtitles->{$type})) {
10597: $chgtext .= $searchtitles->{$type}.'; ';
10598: }
10599: }
10600: }
10601: $chgtext =~ s/\; $//;
10602: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10603: }
1.25 raeburn 10604: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10605: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10606: my $chgtext;
10607: foreach my $type (@{$srchtypeorder}) {
10608: if (grep(/^\Q$type\E$/,@searchtypes)) {
10609: if (defined($srchtypes_desc->{$type})) {
10610: $chgtext .= $srchtypes_desc->{$type}.'; ';
10611: }
10612: }
10613: }
10614: $chgtext =~ s/\; $//;
1.178 raeburn 10615: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10616: }
10617: $resulttext .= '</ul>';
1.295 raeburn 10618: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10619: if (ref($lastactref) eq 'HASH') {
10620: $lastactref->{'directorysrch'} = 1;
10621: }
1.23 raeburn 10622: } else {
1.277 raeburn 10623: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10624: }
10625: } else {
10626: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10627: &mt('An error occurred: [_1]',$putresult).'</span>';
10628: }
10629: return $resulttext;
10630: }
10631:
1.28 raeburn 10632: sub modify_contacts {
1.205 raeburn 10633: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10634: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10635: if (ref($domconfig{'contacts'}) eq 'HASH') {
10636: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10637: $currsetting{$key} = $domconfig{'contacts'}{$key};
10638: }
10639: }
1.286 raeburn 10640: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10641: my @contacts = ('supportemail','adminemail');
1.286 raeburn 10642: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10643: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 10644: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 10645: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10646: foreach my $type (@mailings) {
10647: @{$newsetting{$type}} =
10648: &Apache::loncommon::get_env_multiple('form.'.$type);
10649: foreach my $item (@contacts) {
10650: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10651: $contacts_hash{contacts}{$type}{$item} = 1;
10652: } else {
10653: $contacts_hash{contacts}{$type}{$item} = 0;
10654: }
1.289 raeburn 10655: }
1.28 raeburn 10656: $others{$type} = $env{'form.'.$type.'_others'};
10657: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 10658: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10659: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10660: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 10661: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10662: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10663: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10664: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10665: }
1.134 raeburn 10666: }
1.28 raeburn 10667: }
10668: foreach my $item (@contacts) {
10669: $to{$item} = $env{'form.'.$item};
10670: $contacts_hash{'contacts'}{$item} = $to{$item};
10671: }
1.203 raeburn 10672: foreach my $item (@toggles) {
10673: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10674: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10675: }
10676: }
1.286 raeburn 10677: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10678: foreach my $field (@{$fields}) {
10679: if (ref($possoptions->{$field}) eq 'ARRAY') {
10680: my $value = $env{'form.helpform_'.$field};
10681: $value =~ s/^\s+|\s+$//g;
10682: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10683: $contacts_hash{contacts}{'helpform'}{$field} = $value;
10684: if ($field eq 'screenshot') {
10685: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10686: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10687: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10688: }
10689: }
10690: }
10691: }
10692: }
10693: }
1.28 raeburn 10694: if (keys(%currsetting) > 0) {
10695: foreach my $item (@contacts) {
10696: if ($to{$item} ne $currsetting{$item}) {
10697: $changes{$item} = 1;
10698: }
10699: }
10700: foreach my $type (@mailings) {
10701: foreach my $item (@contacts) {
10702: if (ref($currsetting{$type}) eq 'HASH') {
10703: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10704: push(@{$changes{$type}},$item);
10705: }
10706: } else {
10707: push(@{$changes{$type}},@{$newsetting{$type}});
10708: }
10709: }
10710: if ($others{$type} ne $currsetting{$type}{'others'}) {
10711: push(@{$changes{$type}},'others');
10712: }
1.289 raeburn 10713: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10714: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10715: push(@{$changes{$type}},'bcc');
10716: }
1.286 raeburn 10717: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10718: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10719: push(@{$changes{$type}},'include');
10720: }
10721: }
10722: }
10723: if (ref($fields) eq 'ARRAY') {
10724: if (ref($currsetting{'helpform'}) eq 'HASH') {
10725: foreach my $field (@{$fields}) {
10726: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10727: push(@{$changes{'helpform'}},$field);
10728: }
10729: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10730: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10731: push(@{$changes{'helpform'}},'maxsize');
10732: }
10733: }
10734: }
10735: } else {
10736: foreach my $field (@{$fields}) {
10737: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10738: push(@{$changes{'helpform'}},$field);
10739: }
10740: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10741: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10742: push(@{$changes{'helpform'}},'maxsize');
10743: }
10744: }
10745: }
1.134 raeburn 10746: }
1.28 raeburn 10747: }
10748: } else {
10749: my %default;
10750: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10751: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10752: $default{'errormail'} = 'adminemail';
10753: $default{'packagesmail'} = 'adminemail';
10754: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 10755: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10756: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10757: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 10758: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 10759: foreach my $item (@contacts) {
10760: if ($to{$item} ne $default{$item}) {
1.286 raeburn 10761: $changes{$item} = 1;
1.203 raeburn 10762: }
1.28 raeburn 10763: }
10764: foreach my $type (@mailings) {
10765: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10766: push(@{$changes{$type}},@{$newsetting{$type}});
10767: }
10768: if ($others{$type} ne '') {
10769: push(@{$changes{$type}},'others');
1.134 raeburn 10770: }
1.286 raeburn 10771: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10772: if ($bcc{$type} ne '') {
10773: push(@{$changes{$type}},'bcc');
10774: }
1.286 raeburn 10775: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10776: push(@{$changes{$type}},'include');
10777: }
1.134 raeburn 10778: }
1.28 raeburn 10779: }
1.286 raeburn 10780: if (ref($fields) eq 'ARRAY') {
10781: foreach my $field (@{$fields}) {
10782: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10783: push(@{$changes{'helpform'}},$field);
10784: }
10785: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10786: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10787: push(@{$changes{'helpform'}},'maxsize');
10788: }
10789: }
10790: }
1.289 raeburn 10791: }
1.28 raeburn 10792: }
1.203 raeburn 10793: foreach my $item (@toggles) {
10794: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10795: $changes{$item} = 1;
10796: } elsif ((!$env{'form.'.$item}) &&
10797: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10798: $changes{$item} = 1;
10799: }
10800: }
1.28 raeburn 10801: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10802: $dom);
10803: if ($putresult eq 'ok') {
10804: if (keys(%changes) > 0) {
1.205 raeburn 10805: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10806: if (ref($lastactref) eq 'HASH') {
10807: $lastactref->{'domainconfig'} = 1;
10808: }
1.28 raeburn 10809: my ($titles,$short_titles) = &contact_titles();
10810: $resulttext = &mt('Changes made:').'<ul>';
10811: foreach my $item (@contacts) {
10812: if ($changes{$item}) {
10813: $resulttext .= '<li>'.$titles->{$item}.
10814: &mt(' set to: ').
10815: '<span class="LC_cusr_emph">'.
10816: $to{$item}.'</span></li>';
10817: }
10818: }
10819: foreach my $type (@mailings) {
10820: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 10821: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 10822: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 10823: } else {
10824: $resulttext .= '<li>'.$titles->{$type}.': ';
10825: }
1.28 raeburn 10826: my @text;
10827: foreach my $item (@{$newsetting{$type}}) {
10828: push(@text,$short_titles->{$item});
10829: }
10830: if ($others{$type} ne '') {
10831: push(@text,$others{$type});
10832: }
1.286 raeburn 10833: if (@text) {
10834: $resulttext .= '<span class="LC_cusr_emph">'.
10835: join(', ',@text).'</span>';
10836: }
10837: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10838: if ($bcc{$type} ne '') {
1.286 raeburn 10839: my $bcctext;
10840: if (@text) {
1.289 raeburn 10841: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 10842: } else {
10843: $bcctext = '(Bcc)';
10844: }
10845: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10846: } elsif (!@text) {
10847: $resulttext .= &mt('No one');
10848: }
1.289 raeburn 10849: if ($includestr{$type} ne '') {
1.286 raeburn 10850: if ($includeloc{$type} eq 'b') {
10851: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10852: } elsif ($includeloc{$type} eq 's') {
10853: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10854: }
1.134 raeburn 10855: }
1.286 raeburn 10856: } elsif (!@text) {
10857: $resulttext .= &mt('No recipients');
1.134 raeburn 10858: }
10859: $resulttext .= '</li>';
1.28 raeburn 10860: }
10861: }
1.203 raeburn 10862: my @offon = ('off','on');
10863: if ($changes{'reporterrors'}) {
10864: $resulttext .= '<li>'.
10865: &mt('E-mail error reports to [_1] set to "'.
10866: $offon[$env{'form.reporterrors'}].'".',
10867: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10868: &mt('LON-CAPA core group - MSU'),600,500)).
10869: '</li>';
10870: }
10871: if ($changes{'reportupdates'}) {
10872: $resulttext .= '<li>'.
10873: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10874: $offon[$env{'form.reportupdates'}].'".',
10875: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10876: &mt('LON-CAPA core group - MSU'),600,500)).
10877: '</li>';
10878: }
1.286 raeburn 10879: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10880: my (@optional,@required,@unused,$maxsizechg);
10881: foreach my $field (@{$changes{'helpform'}}) {
10882: if ($field eq 'maxsize') {
10883: $maxsizechg = 1;
10884: next;
10885: }
10886: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 10887: push(@optional,$field);
1.286 raeburn 10888: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10889: push(@unused,$field);
10890: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 10891: push(@required,$field);
1.286 raeburn 10892: }
10893: }
10894: if (@optional) {
10895: $resulttext .= '<li>'.
10896: &mt('Help form fields changed to "Optional": [_1].',
10897: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10898: '</li>';
10899: }
10900: if (@required) {
10901: $resulttext .= '<li>'.
10902: &mt('Help form fields changed to "Required": [_1].',
10903: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10904: '</li>';
10905: }
10906: if (@unused) {
10907: $resulttext .= '<li>'.
10908: &mt('Help form fields changed to "Not shown": [_1].',
10909: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10910: '</li>';
10911: }
10912: if ($maxsizechg) {
10913: $resulttext .= '<li>'.
10914: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10915: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10916: '</li>';
10917:
10918: }
10919: }
1.28 raeburn 10920: $resulttext .= '</ul>';
10921: } else {
1.288 raeburn 10922: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10923: }
10924: } else {
10925: $resulttext = '<span class="LC_error">'.
10926: &mt('An error occurred: [_1].',$putresult).'</span>';
10927: }
10928: return $resulttext;
10929: }
10930:
10931: sub modify_usercreation {
1.27 raeburn 10932: my ($dom,%domconfig) = @_;
1.224 raeburn 10933: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 10934: my $warningmsg;
1.27 raeburn 10935: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10936: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 10937: if ($key eq 'cancreate') {
10938: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10939: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10940: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 10941: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10942: ($item eq 'recaptchaversion')) {
1.224 raeburn 10943: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10944: } else {
10945: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10946: }
10947: }
10948: }
10949: } elsif ($key eq 'email_rule') {
10950: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10951: } else {
10952: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10953: }
1.27 raeburn 10954: }
10955: }
10956: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 10957: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 10958: my @contexts = ('author','course','requestcrs');
1.34 raeburn 10959: foreach my $item(@contexts) {
1.224 raeburn 10960: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 10961: }
1.34 raeburn 10962: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10963: foreach my $item (@contexts) {
1.224 raeburn 10964: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10965: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 10966: }
1.27 raeburn 10967: }
1.34 raeburn 10968: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10969: foreach my $item (@contexts) {
1.43 raeburn 10970: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10971: if ($cancreate{$item} ne 'any') {
10972: push(@{$changes{'cancreate'}},$item);
10973: }
10974: } else {
10975: if ($cancreate{$item} ne 'none') {
10976: push(@{$changes{'cancreate'}},$item);
10977: }
1.27 raeburn 10978: }
10979: }
10980: } else {
1.43 raeburn 10981: foreach my $item (@contexts) {
1.34 raeburn 10982: push(@{$changes{'cancreate'}},$item);
10983: }
1.27 raeburn 10984: }
1.34 raeburn 10985:
1.27 raeburn 10986: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10987: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10988: if (!grep(/^\Q$type\E$/,@username_rule)) {
10989: push(@{$changes{'username_rule'}},$type);
10990: }
10991: }
10992: foreach my $type (@username_rule) {
10993: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10994: push(@{$changes{'username_rule'}},$type);
10995: }
10996: }
10997: } else {
10998: push(@{$changes{'username_rule'}},@username_rule);
10999: }
11000:
1.32 raeburn 11001: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11002: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11003: if (!grep(/^\Q$type\E$/,@id_rule)) {
11004: push(@{$changes{'id_rule'}},$type);
11005: }
11006: }
11007: foreach my $type (@id_rule) {
11008: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11009: push(@{$changes{'id_rule'}},$type);
11010: }
11011: }
11012: } else {
11013: push(@{$changes{'id_rule'}},@id_rule);
11014: }
11015:
1.43 raeburn 11016: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11017: my @authtypes = ('int','krb4','krb5','loc');
11018: my %authhash;
1.43 raeburn 11019: foreach my $item (@authen_contexts) {
1.28 raeburn 11020: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11021: foreach my $auth (@authtypes) {
11022: if (grep(/^\Q$auth\E$/,@authallowed)) {
11023: $authhash{$item}{$auth} = 1;
11024: } else {
11025: $authhash{$item}{$auth} = 0;
11026: }
11027: }
11028: }
11029: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11030: foreach my $item (@authen_contexts) {
1.28 raeburn 11031: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11032: foreach my $auth (@authtypes) {
11033: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11034: push(@{$changes{'authtypes'}},$item);
11035: last;
11036: }
11037: }
11038: }
11039: }
11040: } else {
1.43 raeburn 11041: foreach my $item (@authen_contexts) {
1.28 raeburn 11042: push(@{$changes{'authtypes'}},$item);
11043: }
11044: }
11045:
1.224 raeburn 11046: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11047: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11048: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11049: $save_usercreate{'id_rule'} = \@id_rule;
11050: $save_usercreate{'username_rule'} = \@username_rule,
11051: $save_usercreate{'authtypes'} = \%authhash;
11052:
1.27 raeburn 11053: my %usercreation_hash = (
1.224 raeburn 11054: usercreation => \%save_usercreate,
11055: );
1.27 raeburn 11056:
11057: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11058: $dom);
1.50 raeburn 11059:
1.224 raeburn 11060: if ($putresult eq 'ok') {
11061: if (keys(%changes) > 0) {
11062: $resulttext = &mt('Changes made:').'<ul>';
11063: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11064: my %lt = &usercreation_types();
11065: foreach my $type (@{$changes{'cancreate'}}) {
11066: my $chgtext = $lt{$type}.', ';
11067: if ($cancreate{$type} eq 'none') {
11068: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11069: } elsif ($cancreate{$type} eq 'any') {
11070: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11071: } elsif ($cancreate{$type} eq 'official') {
11072: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11073: } elsif ($cancreate{$type} eq 'unofficial') {
11074: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11075: }
11076: $resulttext .= '<li>'.$chgtext.'</li>';
11077: }
11078: }
11079: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11080: my ($rules,$ruleorder) =
11081: &Apache::lonnet::inst_userrules($dom,'username');
11082: my $chgtext = '<ul>';
11083: foreach my $type (@username_rule) {
11084: if (ref($rules->{$type}) eq 'HASH') {
11085: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11086: }
11087: }
11088: $chgtext .= '</ul>';
11089: if (@username_rule > 0) {
11090: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11091: } else {
11092: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11093: }
11094: }
11095: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11096: my ($idrules,$idruleorder) =
11097: &Apache::lonnet::inst_userrules($dom,'id');
11098: my $chgtext = '<ul>';
11099: foreach my $type (@id_rule) {
11100: if (ref($idrules->{$type}) eq 'HASH') {
11101: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11102: }
11103: }
11104: $chgtext .= '</ul>';
11105: if (@id_rule > 0) {
11106: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11107: } else {
11108: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11109: }
11110: }
11111: my %authname = &authtype_names();
11112: my %context_title = &context_names();
11113: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11114: my $chgtext = '<ul>';
11115: foreach my $type (@{$changes{'authtypes'}}) {
11116: my @allowed;
11117: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11118: foreach my $auth (@authtypes) {
11119: if ($authhash{$type}{$auth}) {
11120: push(@allowed,$authname{$auth});
11121: }
11122: }
11123: if (@allowed > 0) {
11124: $chgtext .= join(', ',@allowed).'</li>';
11125: } else {
11126: $chgtext .= &mt('none').'</li>';
11127: }
11128: }
11129: $chgtext .= '</ul>';
11130: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11131: $resulttext .= '</li>';
11132: }
11133: $resulttext .= '</ul>';
11134: } else {
11135: $resulttext = &mt('No changes made to user creation settings');
11136: }
11137: } else {
11138: $resulttext = '<span class="LC_error">'.
11139: &mt('An error occurred: [_1]',$putresult).'</span>';
11140: }
11141: if ($warningmsg ne '') {
11142: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11143: }
11144: return $resulttext;
11145: }
11146:
11147: sub modify_selfcreation {
11148: my ($dom,%domconfig) = @_;
11149: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
11150: my (%save_usercreate,%save_usermodify);
1.228 raeburn 11151: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11152: if (ref($types) eq 'ARRAY') {
11153: $usertypes->{'default'} = $othertitle;
11154: push(@{$types},'default');
11155: }
1.224 raeburn 11156: #
11157: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11158: #
11159: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11160: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11161: if ($key eq 'cancreate') {
11162: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11163: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11164: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
11165: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 11166: ($item eq 'recaptchaversion') ||
1.236 raeburn 11167: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 11168: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 11169: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11170: } else {
11171: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11172: }
11173: }
11174: }
11175: } elsif ($key eq 'email_rule') {
11176: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11177: } else {
11178: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11179: }
11180: }
11181: }
11182: #
11183: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11184: #
11185: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11186: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11187: if ($key eq 'selfcreate') {
11188: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11189: } else {
11190: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11191: }
11192: }
11193: }
11194:
11195: my @contexts = ('selfcreate');
11196: @{$cancreate{'selfcreate'}} = ();
11197: %{$cancreate{'emailusername'}} = ();
11198: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 11199: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 11200: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 11201: my %selfcreatetypes = (
11202: sso => 'users authenticated by institutional single sign on',
11203: login => 'users authenticated by institutional log-in',
1.236 raeburn 11204: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 11205: );
1.224 raeburn 11206: #
11207: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11208: # is permitted.
11209: #
1.236 raeburn 11210:
11211: my @statuses;
11212: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11213: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
11214: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
11215: }
11216: }
11217: push(@statuses,'default');
11218:
1.228 raeburn 11219: foreach my $item ('login','sso','email') {
1.224 raeburn 11220: if ($item eq 'email') {
1.236 raeburn 11221: if ($env{'form.cancreate_email'}) {
1.224 raeburn 11222: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 11223: push(@contexts,'selfcreateprocessing');
11224: foreach my $type (@statuses) {
11225: if ($type eq 'default') {
11226: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
11227: } else {
11228: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11229: }
11230: }
1.224 raeburn 11231: }
11232: } else {
11233: if ($env{'form.cancreate_'.$item}) {
11234: push(@{$cancreate{'selfcreate'}},$item);
11235: }
11236: }
11237: }
11238: my (@email_rule,%userinfo,%savecaptcha);
11239: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11240: #
1.228 raeburn 11241: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11242: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 11243: #
1.236 raeburn 11244:
1.244 raeburn 11245: if ($env{'form.cancreate_email'}) {
1.228 raeburn 11246: push(@contexts,'emailusername');
11247: if (ref($types) eq 'ARRAY') {
11248: foreach my $type (@{$types}) {
11249: if (ref($infofields) eq 'ARRAY') {
11250: foreach my $field (@{$infofields}) {
11251: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11252: $cancreate{'emailusername'}{$type}{$field} = $1;
11253: }
11254: }
1.224 raeburn 11255: }
11256: }
11257: }
11258: #
11259: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
11260: # queued requests for self-creation of account using e-mail address as username
11261: #
11262:
11263: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11264: @approvalnotify = sort(@approvalnotify);
11265: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11266: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11267: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11268: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11269: push(@{$changes{'cancreate'}},'notify');
11270: }
11271: } else {
11272: if ($cancreate{'notify'}{'approval'}) {
11273: push(@{$changes{'cancreate'}},'notify');
11274: }
11275: }
11276: } elsif ($cancreate{'notify'}{'approval'}) {
11277: push(@{$changes{'cancreate'}},'notify');
11278: }
11279:
11280: #
11281: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
11282: #
11283: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11284: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11285: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11286: if (@{$curr_usercreation{'email_rule'}} > 0) {
11287: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11288: if (!grep(/^\Q$type\E$/,@email_rule)) {
11289: push(@{$changes{'email_rule'}},$type);
11290: }
11291: }
11292: }
11293: if (@email_rule > 0) {
11294: foreach my $type (@email_rule) {
11295: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11296: push(@{$changes{'email_rule'}},$type);
11297: }
11298: }
11299: }
11300: } elsif (@email_rule > 0) {
11301: push(@{$changes{'email_rule'}},@email_rule);
11302: }
11303: }
11304: #
1.236 raeburn 11305: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 11306: # institutional log-in.
11307: #
11308: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11309: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11310: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11311: ($domdefaults{'auth_def'} eq 'localauth'))) {
11312: $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.').' '.
11313: &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.');
11314: }
11315: }
11316: my @fields = ('lastname','firstname','middlename','generation',
11317: 'permanentemail','id');
1.240 raeburn 11318: my @shibfields = (@fields,'inststatus');
1.224 raeburn 11319: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11320: #
11321: # Where usernames may created for institutional log-in and/or institutional single sign on:
11322: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11323: # may self-create accounts
11324: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11325: # which the user may supply, if institutional data is unavailable.
11326: #
11327: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11328: if (ref($types) eq 'ARRAY') {
1.228 raeburn 11329: if (@{$types} > 1) {
1.224 raeburn 11330: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11331: push(@contexts,'statustocreate');
11332: } else {
11333: undef($cancreate{'statustocreate'});
11334: }
11335: foreach my $type (@{$types}) {
11336: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11337: foreach my $field (@fields) {
11338: if (grep(/^\Q$field\E$/,@modifiable)) {
11339: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11340: } else {
11341: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11342: }
11343: }
11344: }
11345: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11346: foreach my $type (@{$types}) {
11347: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11348: foreach my $field (@fields) {
11349: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11350: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11351: push(@{$changes{'selfcreate'}},$type);
11352: last;
11353: }
11354: }
11355: }
11356: }
11357: } else {
11358: foreach my $type (@{$types}) {
11359: push(@{$changes{'selfcreate'}},$type);
11360: }
11361: }
11362: }
1.240 raeburn 11363: foreach my $field (@shibfields) {
11364: if ($env{'form.shibenv_'.$field} ne '') {
11365: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11366: }
11367: }
11368: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11369: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11370: foreach my $field (@shibfields) {
11371: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11372: push(@{$changes{'cancreate'}},'shibenv');
11373: }
11374: }
11375: } else {
11376: foreach my $field (@shibfields) {
11377: if ($env{'form.shibenv_'.$field}) {
11378: push(@{$changes{'cancreate'}},'shibenv');
11379: last;
11380: }
11381: }
11382: }
11383: }
1.224 raeburn 11384: }
11385: foreach my $item (@contexts) {
11386: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11387: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11388: if (ref($cancreate{$item}) eq 'ARRAY') {
11389: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11390: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11391: push(@{$changes{'cancreate'}},$item);
11392: }
11393: }
11394: }
11395: }
11396: if (ref($cancreate{$item}) eq 'ARRAY') {
11397: foreach my $type (@{$cancreate{$item}}) {
11398: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11399: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11400: push(@{$changes{'cancreate'}},$item);
11401: }
11402: }
11403: }
11404: }
11405: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11406: if (ref($cancreate{$item}) eq 'HASH') {
11407: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 11408: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11409: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11410: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11411: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11412: push(@{$changes{'cancreate'}},$item);
11413: }
11414: }
11415: }
1.236 raeburn 11416: } elsif ($item eq 'selfcreateprocessing') {
11417: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11418: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11419: push(@{$changes{'cancreate'}},$item);
11420: }
11421: }
1.228 raeburn 11422: } else {
11423: if (!$cancreate{$item}{$curr}) {
11424: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11425: push(@{$changes{'cancreate'}},$item);
11426: }
1.224 raeburn 11427: }
11428: }
11429: }
11430: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 11431: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11432: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11433: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11434: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11435: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11436: push(@{$changes{'cancreate'}},$item);
11437: }
11438: }
11439: } else {
11440: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11441: push(@{$changes{'cancreate'}},$item);
11442: }
11443: }
11444: }
1.236 raeburn 11445: } elsif ($item eq 'selfcreateprocessing') {
11446: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11447: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11448: push(@{$changes{'cancreate'}},$item);
11449: }
11450: }
1.228 raeburn 11451: } else {
11452: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11453: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11454: push(@{$changes{'cancreate'}},$item);
11455: }
1.224 raeburn 11456: }
11457: }
11458: }
11459: }
11460: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11461: if (ref($cancreate{$item}) eq 'ARRAY') {
11462: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11463: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11464: push(@{$changes{'cancreate'}},$item);
11465: }
11466: }
11467: } elsif (ref($cancreate{$item}) eq 'HASH') {
11468: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11469: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11470: push(@{$changes{'cancreate'}},$item);
11471: }
11472: }
11473: }
11474: } elsif ($item eq 'emailusername') {
1.228 raeburn 11475: if (ref($cancreate{$item}) eq 'HASH') {
11476: foreach my $type (keys(%{$cancreate{$item}})) {
11477: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11478: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11479: if ($cancreate{$item}{$type}{$field}) {
11480: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11481: push(@{$changes{'cancreate'}},$item);
11482: }
11483: last;
11484: }
11485: }
11486: }
11487: }
1.224 raeburn 11488: }
11489: }
11490: }
11491: #
11492: # Populate %save_usercreate hash with updates to self-creation configuration.
11493: #
11494: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11495: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 11496: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 11497: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11498: if (ref($cancreate{'notify'}) eq 'HASH') {
11499: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11500: }
1.236 raeburn 11501: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11502: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11503: }
1.224 raeburn 11504: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11505: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11506: }
1.240 raeburn 11507: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11508: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11509: }
1.224 raeburn 11510: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
11511: $save_usercreate{'emailrule'} = \@email_rule;
11512:
11513: my %userconfig_hash = (
11514: usercreation => \%save_usercreate,
11515: usermodification => \%save_usermodify,
11516: );
11517: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11518: $dom);
11519: #
11520: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11521: #
1.27 raeburn 11522: if ($putresult eq 'ok') {
11523: if (keys(%changes) > 0) {
11524: $resulttext = &mt('Changes made:').'<ul>';
11525: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 11526: my %lt = &selfcreation_types();
1.34 raeburn 11527: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 11528: my $chgtext;
1.45 raeburn 11529: if ($type eq 'selfcreate') {
1.50 raeburn 11530: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 11531: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11532: } else {
1.224 raeburn 11533: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11534: '<ul>';
1.50 raeburn 11535: foreach my $case (@{$cancreate{$type}}) {
11536: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11537: }
11538: $chgtext .= '</ul>';
1.100 raeburn 11539: if (ref($cancreate{$type}) eq 'ARRAY') {
11540: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11541: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11542: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 11543: $chgtext .= '<br />'.
11544: '<span class="LC_warning">'.
11545: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11546: '</span>';
1.100 raeburn 11547: }
11548: }
11549: }
11550: }
1.43 raeburn 11551: }
1.240 raeburn 11552: } elsif ($type eq 'shibenv') {
11553: if (keys(%{$cancreate{$type}}) == 0) {
11554: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
11555: } else {
11556: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11557: '<ul>';
11558: foreach my $field (@shibfields) {
11559: next if ($cancreate{$type}{$field} eq '');
11560: if ($field eq 'inststatus') {
11561: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11562: } else {
11563: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11564: }
11565: }
11566: $chgtext .= '</ul>';
11567: }
1.93 raeburn 11568: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11569: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11570: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11571: if (@{$cancreate{'selfcreate'}} > 0) {
11572: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11573: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11574: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11575: $chgtext .= '<br />'.
11576: '<span class="LC_warning">'.
11577: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11578: '</span>';
11579: }
1.96 raeburn 11580: } elsif (ref($usertypes) eq 'HASH') {
11581: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11582: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11583: } else {
11584: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11585: }
11586: $chgtext .= '<ul>';
11587: foreach my $case (@{$cancreate{$type}}) {
11588: if ($case eq 'default') {
11589: $chgtext .= '<li>'.$othertitle.'</li>';
11590: } else {
11591: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 11592: }
11593: }
1.100 raeburn 11594: $chgtext .= '</ul>';
11595: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11596: $chgtext .= '<br /><span class="LC_warning">'.
11597: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11598: '</span>';
1.100 raeburn 11599: }
11600: }
11601: } else {
11602: if (@{$cancreate{$type}} == 0) {
11603: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11604: } else {
11605: $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 11606: }
11607: }
11608: }
1.236 raeburn 11609: } elsif ($type eq 'selfcreateprocessing') {
11610: my %choices = &Apache::lonlocal::texthash (
11611: automatic => 'Automatic approval',
11612: approval => 'Queued for approval',
11613: );
11614: if (@statuses > 1) {
11615: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
11616: '<ul>';
11617: foreach my $type (@statuses) {
11618: if ($type eq 'default') {
11619: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11620: } else {
11621: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11622: }
11623: }
11624: $chgtext .= '</ul>';
11625: } else {
11626: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
11627: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11628: }
1.165 raeburn 11629: } elsif ($type eq 'captcha') {
1.224 raeburn 11630: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 11631: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11632: } else {
11633: my %captchas = &captcha_phrases();
1.224 raeburn 11634: if ($captchas{$savecaptcha{$type}}) {
11635: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 11636: } else {
1.210 raeburn 11637: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 11638: }
11639: }
11640: } elsif ($type eq 'recaptchakeys') {
11641: my ($privkey,$pubkey);
1.224 raeburn 11642: if (ref($savecaptcha{$type}) eq 'HASH') {
11643: $pubkey = $savecaptcha{$type}{'public'};
11644: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 11645: }
11646: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11647: if (!$pubkey) {
11648: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11649: } else {
11650: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11651: }
11652: if (!$privkey) {
11653: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11654: } else {
11655: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11656: }
11657: $chgtext .= '</ul>';
1.269 raeburn 11658: } elsif ($type eq 'recaptchaversion') {
11659: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 11660: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 11661: }
1.224 raeburn 11662: } elsif ($type eq 'emailusername') {
11663: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 11664: if (ref($types) eq 'ARRAY') {
11665: foreach my $type (@{$types}) {
11666: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11667: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 11668: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 11669: '<ul>';
11670: foreach my $field (@{$infofields}) {
11671: if ($cancreate{'emailusername'}{$type}{$field}) {
11672: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11673: }
11674: }
1.245 raeburn 11675: $chgtext .= '</ul>';
11676: } else {
11677: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.228 raeburn 11678: }
11679: } else {
1.245 raeburn 11680: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.224 raeburn 11681: }
11682: }
11683: }
11684: }
11685: } elsif ($type eq 'notify') {
11686: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11687: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11688: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11689: if ($cancreate{'notify'}{'approval'}) {
11690: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11691: }
11692: }
1.43 raeburn 11693: }
1.34 raeburn 11694: }
1.224 raeburn 11695: if ($chgtext) {
11696: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11697: }
11698: }
11699: }
1.43 raeburn 11700: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11701: my ($emailrules,$emailruleorder) =
11702: &Apache::lonnet::inst_userrules($dom,'email');
11703: my $chgtext = '<ul>';
11704: foreach my $type (@email_rule) {
11705: if (ref($emailrules->{$type}) eq 'HASH') {
11706: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11707: }
11708: }
11709: $chgtext .= '</ul>';
11710: if (@email_rule > 0) {
1.224 raeburn 11711: $resulttext .= '<li>'.
11712: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
11713: $chgtext.
11714: '</li>';
1.43 raeburn 11715: } else {
1.224 raeburn 11716: $resulttext .= '<li>'.
11717: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
11718: '</li>';
1.43 raeburn 11719: }
11720: }
1.224 raeburn 11721: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11722: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11723: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11724: foreach my $type (@{$changes{'selfcreate'}}) {
11725: my $typename = $type;
11726: if (ref($usertypes) eq 'HASH') {
11727: if ($usertypes->{$type} ne '') {
11728: $typename = $usertypes->{$type};
11729: }
11730: }
11731: my @modifiable;
11732: $resulttext .= '<li>'.
11733: &mt('Self-creation of account by users with status: [_1]',
11734: '<span class="LC_cusr_emph">'.$typename.'</span>').
11735: ' - '.&mt('modifiable fields (if institutional data blank): ');
11736: foreach my $field (@fields) {
11737: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11738: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 11739: }
11740: }
1.224 raeburn 11741: if (@modifiable > 0) {
11742: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11743: } else {
1.224 raeburn 11744: $resulttext .= &mt('none');
1.43 raeburn 11745: }
1.224 raeburn 11746: $resulttext .= '</li>';
1.28 raeburn 11747: }
1.224 raeburn 11748: $resulttext .= '</ul></li>';
1.28 raeburn 11749: }
1.27 raeburn 11750: $resulttext .= '</ul>';
11751: } else {
1.224 raeburn 11752: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11753: }
11754: } else {
11755: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11756: &mt('An error occurred: [_1]',$putresult).'</span>';
11757: }
1.43 raeburn 11758: if ($warningmsg ne '') {
11759: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11760: }
1.23 raeburn 11761: return $resulttext;
11762: }
11763:
1.165 raeburn 11764: sub process_captcha {
11765: my ($container,$changes,$newsettings,$current) = @_;
11766: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11767: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11768: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11769: $newsettings->{'captcha'} = 'original';
11770: }
11771: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 11772: if ($container eq 'cancreate') {
1.169 raeburn 11773: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11774: push(@{$changes->{'cancreate'}},'captcha');
11775: } elsif (!defined($changes->{'cancreate'})) {
11776: $changes->{'cancreate'} = ['captcha'];
11777: }
11778: } else {
11779: $changes->{'captcha'} = 1;
1.165 raeburn 11780: }
11781: }
1.269 raeburn 11782: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 11783: if ($newsettings->{'captcha'} eq 'recaptcha') {
11784: $newpub = $env{'form.'.$container.'_recaptchapub'};
11785: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 11786: $newpub =~ s/[^\w\-]//g;
11787: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 11788: $newsettings->{'recaptchakeys'} = {
11789: public => $newpub,
11790: private => $newpriv,
11791: };
1.269 raeburn 11792: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11793: $newversion =~ s/\D//g;
11794: if ($newversion ne '2') {
11795: $newversion = 1;
11796: }
11797: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 11798: }
11799: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11800: $currpub = $current->{'recaptchakeys'}{'public'};
11801: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 11802: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11803: $newsettings->{'recaptchakeys'} = {
11804: public => '',
11805: private => '',
11806: }
11807: }
1.165 raeburn 11808: }
1.269 raeburn 11809: if ($current->{'captcha'} eq 'recaptcha') {
11810: $currversion = $current->{'recaptchaversion'};
11811: if ($currversion ne '2') {
11812: $currversion = 1;
11813: }
11814: }
11815: if ($currversion ne $newversion) {
11816: if ($container eq 'cancreate') {
11817: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11818: push(@{$changes->{'cancreate'}},'recaptchaversion');
11819: } elsif (!defined($changes->{'cancreate'})) {
11820: $changes->{'cancreate'} = ['recaptchaversion'];
11821: }
11822: } else {
11823: $changes->{'recaptchaversion'} = 1;
11824: }
11825: }
1.165 raeburn 11826: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 11827: if ($container eq 'cancreate') {
11828: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11829: push(@{$changes->{'cancreate'}},'recaptchakeys');
11830: } elsif (!defined($changes->{'cancreate'})) {
11831: $changes->{'cancreate'} = ['recaptchakeys'];
11832: }
11833: } else {
1.210 raeburn 11834: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 11835: }
11836: }
11837: return;
11838: }
11839:
1.33 raeburn 11840: sub modify_usermodification {
11841: my ($dom,%domconfig) = @_;
1.224 raeburn 11842: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11843: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11844: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 11845: if ($key eq 'selfcreate') {
11846: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11847: } else {
11848: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11849: }
1.33 raeburn 11850: }
11851: }
1.224 raeburn 11852: my @contexts = ('author','course');
1.33 raeburn 11853: my %context_title = (
11854: author => 'In author context',
11855: course => 'In course context',
11856: );
11857: my @fields = ('lastname','firstname','middlename','generation',
11858: 'permanentemail','id');
11859: my %roles = (
11860: author => ['ca','aa'],
11861: course => ['st','ep','ta','in','cr'],
11862: );
11863: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11864: foreach my $context (@contexts) {
11865: foreach my $role (@{$roles{$context}}) {
11866: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11867: foreach my $item (@fields) {
11868: if (grep(/^\Q$item\E$/,@modifiable)) {
11869: $modifyhash{$context}{$role}{$item} = 1;
11870: } else {
11871: $modifyhash{$context}{$role}{$item} = 0;
11872: }
11873: }
11874: }
11875: if (ref($curr_usermodification{$context}) eq 'HASH') {
11876: foreach my $role (@{$roles{$context}}) {
11877: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11878: foreach my $field (@fields) {
11879: if ($modifyhash{$context}{$role}{$field} ne
11880: $curr_usermodification{$context}{$role}{$field}) {
11881: push(@{$changes{$context}},$role);
11882: last;
11883: }
11884: }
11885: }
11886: }
11887: } else {
11888: foreach my $context (@contexts) {
11889: foreach my $role (@{$roles{$context}}) {
11890: push(@{$changes{$context}},$role);
11891: }
11892: }
11893: }
11894: }
11895: my %usermodification_hash = (
11896: usermodification => \%modifyhash,
11897: );
11898: my $putresult = &Apache::lonnet::put_dom('configuration',
11899: \%usermodification_hash,$dom);
11900: if ($putresult eq 'ok') {
11901: if (keys(%changes) > 0) {
11902: $resulttext = &mt('Changes made: ').'<ul>';
11903: foreach my $context (@contexts) {
11904: if (ref($changes{$context}) eq 'ARRAY') {
11905: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11906: if (ref($changes{$context}) eq 'ARRAY') {
11907: foreach my $role (@{$changes{$context}}) {
11908: my $rolename;
1.224 raeburn 11909: if ($role eq 'cr') {
11910: $rolename = &mt('Custom');
1.33 raeburn 11911: } else {
1.224 raeburn 11912: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11913: }
11914: my @modifiable;
1.224 raeburn 11915: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11916: foreach my $field (@fields) {
11917: if ($modifyhash{$context}{$role}{$field}) {
11918: push(@modifiable,$fieldtitles{$field});
11919: }
11920: }
11921: if (@modifiable > 0) {
11922: $resulttext .= join(', ',@modifiable);
11923: } else {
11924: $resulttext .= &mt('none');
11925: }
11926: $resulttext .= '</li>';
11927: }
11928: $resulttext .= '</ul></li>';
11929: }
11930: }
11931: }
11932: $resulttext .= '</ul>';
11933: } else {
11934: $resulttext = &mt('No changes made to user modification settings');
11935: }
11936: } else {
11937: $resulttext = '<span class="LC_error">'.
11938: &mt('An error occurred: [_1]',$putresult).'</span>';
11939: }
11940: return $resulttext;
11941: }
11942:
1.43 raeburn 11943: sub modify_defaults {
1.212 raeburn 11944: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11945: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 11946: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 11947: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
11948: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 11949: my @authtypes = ('internal','krb4','krb5','localauth');
11950: foreach my $item (@items) {
11951: $newvalues{$item} = $env{'form.'.$item};
11952: if ($item eq 'auth_def') {
11953: if ($newvalues{$item} ne '') {
11954: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11955: push(@errors,$item);
11956: }
11957: }
11958: } elsif ($item eq 'lang_def') {
11959: if ($newvalues{$item} ne '') {
11960: if ($newvalues{$item} =~ /^(\w+)/) {
11961: my $langcode = $1;
1.103 raeburn 11962: if ($langcode ne 'x_chef') {
11963: if (code2language($langcode) eq '') {
11964: push(@errors,$item);
11965: }
1.43 raeburn 11966: }
11967: } else {
11968: push(@errors,$item);
11969: }
11970: }
1.54 raeburn 11971: } elsif ($item eq 'timezone_def') {
11972: if ($newvalues{$item} ne '') {
1.62 raeburn 11973: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11974: push(@errors,$item);
11975: }
11976: }
1.68 raeburn 11977: } elsif ($item eq 'datelocale_def') {
11978: if ($newvalues{$item} ne '') {
11979: my @datelocale_ids = DateTime::Locale->ids();
11980: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11981: push(@errors,$item);
11982: }
11983: }
1.141 raeburn 11984: } elsif ($item eq 'portal_def') {
11985: if ($newvalues{$item} ne '') {
11986: 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])\/?$/) {
11987: push(@errors,$item);
11988: }
11989: }
1.294 raeburn 11990: } elsif ($item eq 'intauth_cost') {
11991: if ($newvalues{$item} ne '') {
11992: if ($newvalues{$item} =~ /\D/) {
11993: push(@errors,$item);
11994: }
11995: }
11996: } elsif ($item eq 'intauth_check') {
11997: if ($newvalues{$item} ne '') {
11998: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11999: push(@errors,$item);
12000: }
12001: }
12002: } elsif ($item eq 'intauth_switch') {
12003: if ($newvalues{$item} ne '') {
12004: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12005: push(@errors,$item);
12006: }
12007: }
1.43 raeburn 12008: }
12009: if (grep(/^\Q$item\E$/,@errors)) {
12010: $newvalues{$item} = $domdefaults{$item};
12011: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12012: $changes{$item} = 1;
12013: }
1.72 raeburn 12014: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 12015: }
12016: my %defaults_hash = (
1.72 raeburn 12017: defaults => \%newvalues,
12018: );
1.43 raeburn 12019: my $title = &defaults_titles();
1.236 raeburn 12020:
12021: my $currinststatus;
12022: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12023: $currinststatus = $domconfig{'inststatus'};
12024: } else {
12025: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12026: $currinststatus = {
12027: inststatustypes => $usertypes,
12028: inststatusorder => $types,
12029: inststatusguest => [],
12030: };
12031: }
12032: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12033: my @allpos;
12034: my %guests;
12035: my %alltypes;
12036: my ($currtitles,$currguests,$currorder);
12037: if (ref($currinststatus) eq 'HASH') {
12038: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12039: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12040: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12041: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12042: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12043: }
12044: }
12045: unless (grep(/^\Q$type\E$/,@todelete)) {
12046: my $position = $env{'form.inststatus_pos_'.$type};
12047: $position =~ s/\D+//g;
12048: $allpos[$position] = $type;
12049: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12050: $alltypes{$type} =~ s/`//g;
12051: if ($env{'form.inststatus_guest_'.$type}) {
12052: $guests{$type} = 1;
12053: }
12054: }
12055: }
12056: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12057: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
12058: }
12059: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12060: $currtitles =~ s/,$//;
12061: }
12062: }
12063: if ($env{'form.addinststatus'}) {
12064: my $newtype = $env{'form.addinststatus'};
12065: $newtype =~ s/\W//g;
12066: unless (exists($alltypes{$newtype})) {
12067: if ($env{'form.addinststatus_guest'}) {
12068: $guests{$newtype} = 1;
12069: }
12070: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12071: $alltypes{$newtype} =~ s/`//g;
12072: my $position = $env{'form.addinststatus_pos'};
12073: $position =~ s/\D+//g;
12074: if ($position ne '') {
12075: $allpos[$position] = $newtype;
12076: }
12077: }
12078: }
12079: my (@orderedstatus,@orderedguests);
12080: foreach my $type (@allpos) {
12081: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12082: push(@orderedstatus,$type);
12083: if ($guests{$type}) {
12084: push(@orderedguests,$type);
12085: }
12086: }
12087: }
12088: foreach my $type (keys(%alltypes)) {
12089: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12090: delete($alltypes{$type});
12091: }
12092: }
12093: $defaults_hash{'inststatus'} = {
12094: inststatustypes => \%alltypes,
12095: inststatusorder => \@orderedstatus,
12096: inststatusguest => \@orderedguests,
12097: };
12098: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12099: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12100: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12101: }
12102: }
12103: if ($currorder ne join(',',@orderedstatus)) {
12104: $changes{'inststatus'}{'inststatusorder'} = 1;
12105: }
12106: if ($currguests ne join(',',@orderedguests)) {
12107: $changes{'inststatus'}{'inststatusguest'} = 1;
12108: }
12109: my $newtitles;
12110: foreach my $item (@orderedstatus) {
12111: $newtitles .= $alltypes{$item}.',';
12112: }
12113: $newtitles =~ s/,$//;
12114: if ($currtitles ne $newtitles) {
12115: $changes{'inststatus'}{'inststatustypes'} = 1;
12116: }
1.43 raeburn 12117: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12118: $dom);
12119: if ($putresult eq 'ok') {
12120: if (keys(%changes) > 0) {
12121: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 12122: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12123: 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";
12124: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 12125: if ($item eq 'inststatus') {
12126: if (ref($changes{'inststatus'}) eq 'HASH') {
12127: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
12128: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12129: foreach my $type (@orderedstatus) {
12130: $resulttext .= $alltypes{$type}.', ';
12131: }
12132: $resulttext =~ s/, $//;
12133: $resulttext .= '</li>';
12134: }
12135: if ($changes{'inststatus'}{'inststatusguest'}) {
12136: $resulttext .= '<li>';
12137: if (@orderedguests) {
12138: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
12139: foreach my $type (@orderedguests) {
12140: $resulttext .= $alltypes{$type}.', ';
12141: }
12142: $resulttext =~ s/, $//;
12143: } else {
12144: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
12145: }
12146: $resulttext .= '</li>';
12147: }
12148: }
12149: } else {
12150: my $value = $env{'form.'.$item};
12151: if ($value eq '') {
12152: $value = &mt('none');
12153: } elsif ($item eq 'auth_def') {
12154: my %authnames = &authtype_names();
12155: my %shortauth = (
12156: internal => 'int',
12157: krb4 => 'krb4',
12158: krb5 => 'krb5',
12159: localauth => 'loc',
12160: );
12161: $value = $authnames{$shortauth{$value}};
1.294 raeburn 12162: } elsif ($item eq 'intauth_switch') {
12163: my %optiondesc = &Apache::lonlocal::texthash (
12164: 0 => 'No',
12165: 1 => 'Yes',
12166: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12167: );
12168: if ($value =~ /^(0|1|2)$/) {
12169: $value = $optiondesc{$value};
12170: } else {
12171: $value = &mt('none -- defaults to No');
12172: }
12173: } elsif ($item eq 'intauth_check') {
12174: my %optiondesc = &Apache::lonlocal::texthash (
12175: 0 => 'No',
12176: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12177: 2 => 'Yes, disallow login if stored cost is less than domain default',
12178: );
12179: if ($value =~ /^(0|1|2)$/) {
12180: $value = $optiondesc{$value};
12181: } else {
12182: $value = &mt('none -- defaults to No');
12183: }
1.236 raeburn 12184: }
12185: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12186: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12187: }
12188: }
12189: $resulttext .= '</ul>';
12190: $mailmsgtext .= "\n";
12191: my $cachetime = 24*60*60;
1.72 raeburn 12192: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12193: if (ref($lastactref) eq 'HASH') {
12194: $lastactref->{'domdefaults'} = 1;
12195: }
1.68 raeburn 12196: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 12197: my $notify = 1;
12198: if (ref($domconfig{'contacts'}) eq 'HASH') {
12199: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12200: $notify = 0;
12201: }
12202: }
12203: if ($notify) {
12204: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12205: "LON-CAPA Domain Settings Change - $dom",
12206: $mailmsgtext);
12207: }
1.54 raeburn 12208: }
1.43 raeburn 12209: } else {
1.54 raeburn 12210: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12211: }
12212: } else {
12213: $resulttext = '<span class="LC_error">'.
12214: &mt('An error occurred: [_1]',$putresult).'</span>';
12215: }
12216: if (@errors > 0) {
12217: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12218: foreach my $item (@errors) {
12219: $resulttext .= ' "'.$title->{$item}.'",';
12220: }
12221: $resulttext =~ s/,$//;
12222: }
12223: return $resulttext;
12224: }
12225:
1.46 raeburn 12226: sub modify_scantron {
1.205 raeburn 12227: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12228: my ($resulttext,%confhash,%changes,$errors);
12229: my $custom = 'custom.tab';
12230: my $default = 'default.tab';
12231: my $servadm = $r->dir_config('lonAdmEMail');
12232: my ($configuserok,$author_ok,$switchserver) =
12233: &config_check($dom,$confname,$servadm);
12234: if ($env{'form.scantronformat.filename'} ne '') {
12235: my $error;
12236: if ($configuserok eq 'ok') {
12237: if ($switchserver) {
1.130 raeburn 12238: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12239: } else {
12240: if ($author_ok eq 'ok') {
12241: my ($result,$scantronurl) =
12242: &publishlogo($r,'upload','scantronformat',$dom,
12243: $confname,'scantron','','',$custom);
12244: if ($result eq 'ok') {
12245: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12246: $changes{'scantronformat'} = 1;
1.46 raeburn 12247: } else {
12248: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12249: }
12250: } else {
12251: $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);
12252: }
12253: }
12254: } else {
12255: $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);
12256: }
12257: if ($error) {
12258: &Apache::lonnet::logthis($error);
12259: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12260: }
12261: }
1.48 raeburn 12262: if (ref($domconfig{'scantron'}) eq 'HASH') {
12263: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12264: if ($env{'form.scantronformat_del'}) {
12265: $confhash{'scantron'}{'scantronformat'} = '';
12266: $changes{'scantronformat'} = 1;
1.46 raeburn 12267: }
12268: }
12269: }
12270: if (keys(%confhash) > 0) {
12271: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12272: $dom);
12273: if ($putresult eq 'ok') {
12274: if (keys(%changes) > 0) {
1.48 raeburn 12275: if (ref($confhash{'scantron'}) eq 'HASH') {
12276: $resulttext = &mt('Changes made:').'<ul>';
12277: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 12278: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 12279: } else {
1.130 raeburn 12280: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 12281: }
1.48 raeburn 12282: $resulttext .= '</ul>';
12283: } else {
1.130 raeburn 12284: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12285: }
12286: $resulttext .= '</ul>';
12287: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12288: if (ref($lastactref) eq 'HASH') {
12289: $lastactref->{'domainconfig'} = 1;
12290: }
1.46 raeburn 12291: } else {
1.130 raeburn 12292: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12293: }
12294: } else {
12295: $resulttext = '<span class="LC_error">'.
12296: &mt('An error occurred: [_1]',$putresult).'</span>';
12297: }
12298: } else {
1.130 raeburn 12299: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12300: }
12301: if ($errors) {
12302: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12303: $errors.'</ul>';
12304: }
12305: return $resulttext;
12306: }
12307:
1.48 raeburn 12308: sub modify_coursecategories {
1.239 raeburn 12309: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12310: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12311: $cathash);
1.48 raeburn 12312: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 12313: my @catitems = ('unauth','auth');
12314: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12315: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12316: $cathash = $domconfig{'coursecategories'}{'cats'};
12317: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12318: $changes{'togglecats'} = 1;
12319: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12320: }
12321: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12322: $changes{'categorize'} = 1;
12323: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12324: }
1.120 raeburn 12325: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12326: $changes{'togglecatscomm'} = 1;
12327: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12328: }
12329: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12330: $changes{'categorizecomm'} = 1;
12331: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 12332:
12333: }
12334: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
12335: $changes{'togglecatsplace'} = 1;
12336: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
12337: }
12338: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
12339: $changes{'categorizeplace'} = 1;
12340: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 12341: }
1.238 raeburn 12342: foreach my $item (@catitems) {
12343: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12344: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12345: $changes{$item} = 1;
12346: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12347: }
12348: }
12349: }
1.57 raeburn 12350: } else {
12351: $changes{'togglecats'} = 1;
12352: $changes{'categorize'} = 1;
1.124 raeburn 12353: $changes{'togglecatscomm'} = 1;
12354: $changes{'categorizecomm'} = 1;
1.272 raeburn 12355: $changes{'togglecatsplace'} = 1;
12356: $changes{'categorizeplace'} = 1;
1.87 raeburn 12357: $domconfig{'coursecategories'} = {
12358: togglecats => $env{'form.togglecats'},
12359: categorize => $env{'form.categorize'},
1.124 raeburn 12360: togglecatscomm => $env{'form.togglecatscomm'},
12361: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 12362: togglecatsplace => $env{'form.togglecatsplace'},
12363: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 12364: };
1.238 raeburn 12365: foreach my $item (@catitems) {
12366: if ($env{'form.coursecat_'.$item} ne 'std') {
12367: $changes{$item} = 1;
12368: }
12369: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12370: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12371: }
12372: }
1.57 raeburn 12373: }
12374: if (ref($cathash) eq 'HASH') {
12375: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12376: push (@deletecategory,'instcode::0');
12377: }
1.120 raeburn 12378: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12379: push(@deletecategory,'communities::0');
12380: }
1.272 raeburn 12381: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
12382: push(@deletecategory,'placement::0');
12383: }
1.48 raeburn 12384: }
1.57 raeburn 12385: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12386: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12387: if (@deletecategory > 0) {
12388: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12389: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12390: foreach my $item (@deletecategory) {
1.57 raeburn 12391: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12392: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12393: $deletions{$item} = 1;
1.57 raeburn 12394: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12395: }
12396: }
12397: }
1.57 raeburn 12398: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12399: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12400: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12401: $reorderings{$item} = 1;
1.57 raeburn 12402: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12403: }
12404: if ($env{'form.addcategory_name_'.$item} ne '') {
12405: my $newcat = $env{'form.addcategory_name_'.$item};
12406: my $newdepth = $depth+1;
12407: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12408: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12409: $adds{$newitem} = 1;
12410: }
12411: if ($env{'form.subcat_'.$item} ne '') {
12412: my $newcat = $env{'form.subcat_'.$item};
12413: my $newdepth = $depth+1;
12414: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12415: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12416: $adds{$newitem} = 1;
12417: }
12418: }
12419: }
12420: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12421: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12422: my $newitem = 'instcode::0';
1.57 raeburn 12423: if ($cathash->{$newitem} eq '') {
12424: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12425: $adds{$newitem} = 1;
12426: }
12427: } else {
12428: my $newitem = 'instcode::0';
1.57 raeburn 12429: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12430: $adds{$newitem} = 1;
12431: }
12432: }
1.120 raeburn 12433: if ($env{'form.communities'} eq '1') {
12434: if (ref($cathash) eq 'HASH') {
12435: my $newitem = 'communities::0';
12436: if ($cathash->{$newitem} eq '') {
12437: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12438: $adds{$newitem} = 1;
12439: }
12440: } else {
12441: my $newitem = 'communities::0';
12442: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12443: $adds{$newitem} = 1;
12444: }
12445: }
1.272 raeburn 12446: if ($env{'form.placement'} eq '1') {
12447: if (ref($cathash) eq 'HASH') {
12448: my $newitem = 'placement::0';
12449: if ($cathash->{$newitem} eq '') {
12450: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12451: $adds{$newitem} = 1;
12452: }
12453: } else {
12454: my $newitem = 'placement::0';
12455: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12456: $adds{$newitem} = 1;
12457: }
12458: }
1.48 raeburn 12459: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12460: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 12461: ($env{'form.addcategory_name'} ne 'communities') &&
12462: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 12463: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12464: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12465: $adds{$newitem} = 1;
12466: }
1.48 raeburn 12467: }
1.57 raeburn 12468: my $putresult;
1.48 raeburn 12469: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12470: if (keys(%deletions) > 0) {
12471: foreach my $key (keys(%deletions)) {
12472: if ($predelallitems{$key} ne '') {
12473: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12474: }
12475: }
12476: }
12477: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12478: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12479: if (ref($chkcats[0]) eq 'ARRAY') {
12480: my $depth = 0;
12481: my $chg = 0;
12482: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12483: my $name = $chkcats[0][$i];
12484: my $item;
12485: if ($name eq '') {
12486: $chg ++;
12487: } else {
12488: $item = &escape($name).'::0';
12489: if ($chg) {
1.57 raeburn 12490: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12491: }
12492: $depth ++;
1.57 raeburn 12493: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12494: $depth --;
12495: }
12496: }
12497: }
1.57 raeburn 12498: }
12499: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12500: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12501: if ($putresult eq 'ok') {
1.57 raeburn 12502: my %title = (
1.120 raeburn 12503: togglecats => 'Show/Hide a course in catalog',
12504: categorize => 'Assign a category to a course',
12505: togglecatscomm => 'Show/Hide a community in catalog',
12506: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12507: );
12508: my %level = (
1.120 raeburn 12509: dom => 'set in Domain ("Modify Course/Community")',
12510: crs => 'set in Course ("Course Configuration")',
12511: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 12512: none => 'No catalog',
12513: std => 'Standard catalog',
12514: domonly => 'Domain-only catalog',
12515: codesrch => 'Code search form',
1.57 raeburn 12516: );
1.48 raeburn 12517: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12518: if ($changes{'togglecats'}) {
12519: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12520: }
12521: if ($changes{'categorize'}) {
12522: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12523: }
1.120 raeburn 12524: if ($changes{'togglecatscomm'}) {
12525: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12526: }
12527: if ($changes{'categorizecomm'}) {
12528: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12529: }
1.238 raeburn 12530: if ($changes{'unauth'}) {
12531: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12532: }
12533: if ($changes{'auth'}) {
12534: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12535: }
1.57 raeburn 12536: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12537: my $cathash;
12538: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12539: $cathash = $domconfig{'coursecategories'}{'cats'};
12540: } else {
12541: $cathash = {};
12542: }
12543: my (@cats,@trails,%allitems);
12544: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12545: if (keys(%deletions) > 0) {
12546: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12547: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12548: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12549: }
12550: $resulttext .= '</ul></li>';
12551: }
12552: if (keys(%reorderings) > 0) {
12553: my %sort_by_trail;
12554: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12555: foreach my $key (keys(%reorderings)) {
12556: if ($allitems{$key} ne '') {
12557: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12558: }
1.48 raeburn 12559: }
1.57 raeburn 12560: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12561: $resulttext .= '<li>'.$trails[$trail].'</li>';
12562: }
12563: $resulttext .= '</ul></li>';
1.48 raeburn 12564: }
1.57 raeburn 12565: if (keys(%adds) > 0) {
12566: my %sort_by_trail;
12567: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12568: foreach my $key (keys(%adds)) {
12569: if ($allitems{$key} ne '') {
12570: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12571: }
12572: }
12573: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12574: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12575: }
1.57 raeburn 12576: $resulttext .= '</ul></li>';
1.48 raeburn 12577: }
12578: }
12579: $resulttext .= '</ul>';
1.239 raeburn 12580: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 12581: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12582: if ($changes{'auth'}) {
12583: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12584: }
12585: if ($changes{'unauth'}) {
12586: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12587: }
12588: my $cachetime = 24*60*60;
12589: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 12590: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 12591: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 12592: }
12593: }
1.48 raeburn 12594: } else {
12595: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12596: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12597: }
12598: } else {
1.120 raeburn 12599: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12600: }
12601: return $resulttext;
12602: }
12603:
1.69 raeburn 12604: sub modify_serverstatuses {
12605: my ($dom,%domconfig) = @_;
12606: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12607: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12608: %currserverstatus = %{$domconfig{'serverstatuses'}};
12609: }
12610: my @pages = &serverstatus_pages();
12611: foreach my $type (@pages) {
12612: $newserverstatus{$type}{'namedusers'} = '';
12613: $newserverstatus{$type}{'machines'} = '';
12614: if (defined($env{'form.'.$type.'_namedusers'})) {
12615: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12616: my @okusers;
12617: foreach my $user (@users) {
12618: my ($uname,$udom) = split(/:/,$user);
12619: if (($udom =~ /^$match_domain$/) &&
12620: (&Apache::lonnet::domain($udom)) &&
12621: ($uname =~ /^$match_username$/)) {
12622: if (!grep(/^\Q$user\E/,@okusers)) {
12623: push(@okusers,$user);
12624: }
12625: }
12626: }
12627: if (@okusers > 0) {
12628: @okusers = sort(@okusers);
12629: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12630: }
12631: }
12632: if (defined($env{'form.'.$type.'_machines'})) {
12633: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12634: my @okmachines;
12635: foreach my $ip (@machines) {
12636: my @parts = split(/\./,$ip);
12637: next if (@parts < 4);
12638: my $badip = 0;
12639: for (my $i=0; $i<4; $i++) {
12640: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12641: $badip = 1;
12642: last;
12643: }
12644: }
12645: if (!$badip) {
12646: push(@okmachines,$ip);
12647: }
12648: }
12649: @okmachines = sort(@okmachines);
12650: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12651: }
12652: }
12653: my %serverstatushash = (
12654: serverstatuses => \%newserverstatus,
12655: );
12656: foreach my $type (@pages) {
1.83 raeburn 12657: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12658: my (@current,@new);
1.83 raeburn 12659: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12660: if ($currserverstatus{$type}{$setting} ne '') {
12661: @current = split(/,/,$currserverstatus{$type}{$setting});
12662: }
12663: }
12664: if ($newserverstatus{$type}{$setting} ne '') {
12665: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12666: }
12667: if (@current > 0) {
12668: if (@new > 0) {
12669: foreach my $item (@current) {
12670: if (!grep(/^\Q$item\E$/,@new)) {
12671: $changes{$type}{$setting} = 1;
1.82 raeburn 12672: last;
12673: }
12674: }
1.84 raeburn 12675: foreach my $item (@new) {
12676: if (!grep(/^\Q$item\E$/,@current)) {
12677: $changes{$type}{$setting} = 1;
12678: last;
1.82 raeburn 12679: }
12680: }
12681: } else {
1.83 raeburn 12682: $changes{$type}{$setting} = 1;
1.69 raeburn 12683: }
1.83 raeburn 12684: } elsif (@new > 0) {
12685: $changes{$type}{$setting} = 1;
1.69 raeburn 12686: }
12687: }
12688: }
12689: if (keys(%changes) > 0) {
1.81 raeburn 12690: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12691: my $putresult = &Apache::lonnet::put_dom('configuration',
12692: \%serverstatushash,$dom);
12693: if ($putresult eq 'ok') {
12694: $resulttext .= &mt('Changes made:').'<ul>';
12695: foreach my $type (@pages) {
1.84 raeburn 12696: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12697: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12698: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12699: if ($newserverstatus{$type}{'namedusers'} eq '') {
12700: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12701: } else {
12702: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12703: }
1.84 raeburn 12704: }
12705: if ($changes{$type}{'machines'}) {
1.69 raeburn 12706: if ($newserverstatus{$type}{'machines'} eq '') {
12707: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12708: } else {
12709: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12710: }
12711:
12712: }
12713: $resulttext .= '</ul></li>';
12714: }
12715: }
12716: $resulttext .= '</ul>';
12717: } else {
12718: $resulttext = '<span class="LC_error">'.
12719: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12720:
12721: }
12722: } else {
12723: $resulttext = &mt('No changes made to access to server status pages');
12724: }
12725: return $resulttext;
12726: }
12727:
1.118 jms 12728: sub modify_helpsettings {
1.285 raeburn 12729: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 12730: my ($resulttext,$errors,%changes,%helphash);
12731: my %defaultchecked = ('submitbugs' => 'on');
12732: my @offon = ('off','on');
1.118 jms 12733: my @toggles = ('submitbugs');
1.285 raeburn 12734: my %current = ('submitbugs' => '',
12735: 'adhoc' => {},
12736: );
1.118 jms 12737: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 12738: %current = %{$domconfig{'helpsettings'}};
12739: }
1.285 raeburn 12740: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 12741: foreach my $item (@toggles) {
12742: if ($defaultchecked{$item} eq 'on') {
12743: if ($current{$item} eq '') {
12744: if ($env{'form.'.$item} eq '0') {
12745: $changes{$item} = 1;
12746: }
12747: } elsif ($current{$item} ne $env{'form.'.$item}) {
12748: $changes{$item} = 1;
12749: }
12750: } elsif ($defaultchecked{$item} eq 'off') {
12751: if ($current{$item} eq '') {
12752: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 12753: $changes{$item} = 1;
12754: }
1.282 raeburn 12755: } elsif ($current{$item} ne $env{'form.'.$item}) {
12756: $changes{$item} = 1;
12757: }
12758: }
12759: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
12760: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
12761: }
12762: }
1.285 raeburn 12763: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 12764: my $confname = $dom.'-domainconfig';
12765: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 12766: my (@allpos,%newsettings,%changedprivs,$newrole);
12767: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 12768: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 12769: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 12770: my %lt = &Apache::lonlocal::texthash(
12771: s => 'system',
12772: d => 'domain',
12773: order => 'Display order',
12774: access => 'Role usage',
1.291 raeburn 12775: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 12776: dh => 'All with domain helpdesk role',
12777: da => 'All with domain helpdesk assistant role',
1.285 raeburn 12778: none => 'None',
12779: status => 'Determined based on institutional status',
12780: inc => 'Include all, but exclude specific personnel',
12781: exc => 'Exclude all, but include specific personnel',
12782: );
12783: for (my $num=0; $num<=$maxnum; $num++) {
12784: my ($prefix,$identifier,$rolename,%curr);
12785: if ($num == $maxnum) {
12786: next unless ($env{'form.newcusthelp'} == $maxnum);
12787: $identifier = 'custhelp'.$num;
12788: $prefix = 'helproles_'.$num;
12789: $rolename = $env{'form.custhelpname'.$num};
12790: $rolename=~s/[^A-Za-z0-9]//gs;
12791: next if ($rolename eq '');
12792: next if (exists($existing{'rolesdef_'.$rolename}));
12793: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12794: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12795: $newprivs{'c'},$confname,$dom);
12796: if ($result ne 'ok') {
12797: $errors .= '<li><span class="LC_error">'.
12798: &mt('An error occurred storing the new custom role: [_1]',
12799: $result).'</span></li>';
12800: next;
12801: } else {
12802: $changedprivs{$rolename} = \%newprivs;
12803: $newrole = $rolename;
12804: }
12805: } else {
12806: $prefix = 'helproles_'.$num;
12807: $rolename = $env{'form.'.$prefix};
12808: next if ($rolename eq '');
12809: next unless (exists($existing{'rolesdef_'.$rolename}));
12810: $identifier = 'custhelp'.$num;
12811: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12812: my %currprivs;
1.289 raeburn 12813: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 12814: split(/\_/,$existing{'rolesdef_'.$rolename});
12815: foreach my $level ('c','d','s') {
12816: if ($newprivs{$level} ne $currprivs{$level}) {
12817: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12818: $newprivs{'c'},$confname,$dom);
12819: if ($result ne 'ok') {
12820: $errors .= '<li><span class="LC_error">'.
12821: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12822: $rolename,$result).'</span></li>';
12823: } else {
12824: $changedprivs{$rolename} = \%newprivs;
12825: }
12826: last;
12827: }
12828: }
12829: if (ref($current{'adhoc'}) eq 'HASH') {
12830: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12831: %curr = %{$current{'adhoc'}{$rolename}};
12832: }
12833: }
12834: }
12835: my $newpos = $env{'form.'.$prefix.'_pos'};
12836: $newpos =~ s/\D+//g;
12837: $allpos[$newpos] = $rolename;
12838: my $newdesc = $env{'form.'.$prefix.'_desc'};
12839: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12840: if ($curr{'desc'}) {
12841: if ($curr{'desc'} ne $newdesc) {
12842: $changes{'customrole'}{$rolename}{'desc'} = 1;
12843: $newsettings{$rolename}{'desc'} = $newdesc;
12844: }
12845: } elsif ($newdesc ne '') {
12846: $changes{'customrole'}{$rolename}{'desc'} = 1;
12847: $newsettings{$rolename}{'desc'} = $newdesc;
12848: }
12849: my $access = $env{'form.'.$prefix.'_access'};
12850: if (grep(/^\Q$access\E$/,@accesstypes)) {
12851: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12852: if ($access eq 'status') {
12853: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12854: if (scalar(@statuses) == 0) {
1.289 raeburn 12855: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 12856: } else {
12857: my (@shownstatus,$numtypes);
12858: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12859: if (ref($types) eq 'ARRAY') {
12860: $numtypes = scalar(@{$types});
12861: foreach my $type (sort(@statuses)) {
12862: if ($type eq 'default') {
12863: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12864: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12865: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12866: push(@shownstatus,$usertypes->{$type});
12867: }
12868: }
12869: }
12870: if (grep(/^default$/,@statuses)) {
12871: push(@shownstatus,$othertitle);
12872: }
12873: if (scalar(@shownstatus) == 1+$numtypes) {
12874: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12875: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12876: } else {
12877: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12878: if (ref($curr{'status'}) eq 'ARRAY') {
12879: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12880: if (@diffs) {
12881: $changes{'customrole'}{$rolename}{$access} = 1;
12882: }
12883: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12884: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 12885: }
1.166 raeburn 12886: }
12887: }
1.285 raeburn 12888: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12889: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12890: my @newspecstaff;
12891: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12892: foreach my $person (sort(@personnel)) {
12893: if ($domhelpdesk{$person}) {
12894: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12895: }
12896: }
12897: if (ref($curr{$access}) eq 'ARRAY') {
12898: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12899: if (@diffs) {
12900: $changes{'customrole'}{$rolename}{$access} = 1;
12901: }
12902: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12903: $changes{'customrole'}{$rolename}{$access} = 1;
12904: }
12905: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12906: my ($uname,$udom) = split(/:/,$person);
12907: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12908: }
12909: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 12910: }
1.285 raeburn 12911: } else {
12912: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12913: }
12914: unless ($curr{'access'} eq $access) {
12915: $changes{'customrole'}{$rolename}{'access'} = 1;
12916: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 12917: }
12918: }
1.285 raeburn 12919: if (@allpos > 0) {
12920: my $idx = 0;
12921: foreach my $rolename (@allpos) {
12922: if ($rolename ne '') {
12923: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12924: if (ref($current{'adhoc'}) eq 'HASH') {
12925: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12926: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12927: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 12928: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 12929: }
12930: }
1.282 raeburn 12931: }
1.285 raeburn 12932: $idx ++;
1.166 raeburn 12933: }
12934: }
1.118 jms 12935: }
1.123 jms 12936: my $putresult;
12937: if (keys(%changes) > 0) {
1.166 raeburn 12938: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 12939: if ($putresult eq 'ok') {
1.285 raeburn 12940: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12941: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12942: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12943: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12944: }
12945: }
12946: my $cachetime = 24*60*60;
12947: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12948: if (ref($lastactref) eq 'HASH') {
12949: $lastactref->{'domdefaults'} = 1;
12950: }
12951: } else {
12952: $errors .= '<li><span class="LC_error">'.
12953: &mt('An error occurred storing the settings: [_1]',
12954: $putresult).'</span></li>';
12955: }
12956: }
12957: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12958: $resulttext = &mt('Changes made:').'<ul>';
12959: my (%shownprivs,@levelorder);
12960: @levelorder = ('c','d','s');
12961: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 12962: foreach my $item (sort(keys(%changes))) {
12963: if ($item eq 'submitbugs') {
12964: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12965: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12966: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 12967: } elsif ($item eq 'customrole') {
12968: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 12969: my @keyorder = ('order','desc','access','status','exc','inc');
12970: my %keytext = &Apache::lonlocal::texthash(
12971: order => 'Order',
12972: desc => 'Role description',
12973: access => 'Role usage',
12974: status => 'Allowed instituional types',
12975: exc => 'Allowed personnel',
12976: inc => 'Disallowed personnel',
12977: );
1.282 raeburn 12978: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 12979: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12980: if ($role eq $newrole) {
12981: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12982: $role).'<ul>';
12983: } else {
12984: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12985: $role).'<ul>';
12986: }
12987: foreach my $key (@keyorder) {
12988: if ($changes{'customrole'}{$role}{$key}) {
12989: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12990: $keytext{$key},$newsettings{$role}{$key}).
12991: '</li>';
12992: }
12993: }
12994: if (ref($changedprivs{$role}) eq 'HASH') {
12995: $shownprivs{$role} = 1;
12996: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
12997: foreach my $level (@levelorder) {
12998: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12999: next if ($item eq '');
13000: my ($priv) = split(/\&/,$item,2);
13001: if (&Apache::lonnet::plaintext($priv)) {
13002: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13003: unless ($level eq 'c') {
13004: $resulttext .= ' ('.$lt{$level}.')';
13005: }
13006: $resulttext .= '</li>';
13007: }
13008: }
13009: }
13010: $resulttext .= '</ul>';
13011: }
13012: $resulttext .= '</ul></li>';
13013: }
13014: }
13015: }
13016: }
13017: }
13018: }
13019: if (keys(%changedprivs)) {
13020: foreach my $role (sort(keys(%changedprivs))) {
13021: unless ($shownprivs{$role}) {
13022: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13023: $role).'<ul>'.
13024: '<li>'.&mt('Privileges set to :').'<ul>';
13025: foreach my $level (@levelorder) {
13026: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13027: next if ($item eq '');
13028: my ($priv) = split(/\&/,$item,2);
13029: if (&Apache::lonnet::plaintext($priv)) {
13030: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13031: unless ($level eq 'c') {
13032: $resulttext .= ' ('.$lt{$level}.')';
13033: }
13034: $resulttext .= '</li>';
13035: }
1.282 raeburn 13036: }
13037: }
1.285 raeburn 13038: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 13039: }
13040: }
13041: }
1.285 raeburn 13042: $resulttext .= '</ul>';
13043: } else {
13044: $resulttext = &mt('No changes made to help settings');
1.118 jms 13045: }
13046: if ($errors) {
1.168 raeburn 13047: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 13048: $errors.'</ul>';
1.118 jms 13049: }
13050: return $resulttext;
13051: }
13052:
1.121 raeburn 13053: sub modify_coursedefaults {
1.212 raeburn 13054: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 13055: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 13056: my %defaultchecked = (
13057: 'canuse_pdfforms' => 'off',
13058: 'uselcmath' => 'on',
13059: 'usejsme' => 'on'
13060: );
13061: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 13062: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 13063: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
13064: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
13065: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 13066: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 13067: my %staticdefaults = (
13068: anonsurvey_threshold => 10,
13069: uploadquota => 500,
1.257 raeburn 13070: postsubmit => 60,
1.276 raeburn 13071: mysqltables => 172800,
1.198 raeburn 13072: );
1.121 raeburn 13073:
13074: $defaultshash{'coursedefaults'} = {};
13075:
13076: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13077: if ($domconfig{'coursedefaults'} eq '') {
13078: $domconfig{'coursedefaults'} = {};
13079: }
13080: }
13081:
13082: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13083: foreach my $item (@toggles) {
13084: if ($defaultchecked{$item} eq 'on') {
13085: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13086: ($env{'form.'.$item} eq '0')) {
13087: $changes{$item} = 1;
1.192 raeburn 13088: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 13089: $changes{$item} = 1;
13090: }
13091: } elsif ($defaultchecked{$item} eq 'off') {
13092: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13093: ($env{'form.'.$item} eq '1')) {
13094: $changes{$item} = 1;
13095: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13096: $changes{$item} = 1;
13097: }
13098: }
13099: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13100: }
1.198 raeburn 13101: foreach my $item (@numbers) {
13102: my ($currdef,$newdef);
1.208 raeburn 13103: $newdef = $env{'form.'.$item};
1.198 raeburn 13104: if ($item eq 'anonsurvey_threshold') {
13105: $currdef = $domconfig{'coursedefaults'}{$item};
13106: $newdef =~ s/\D//g;
13107: if ($newdef eq '' || $newdef < 1) {
13108: $newdef = 1;
13109: }
13110: $defaultshash{'coursedefaults'}{$item} = $newdef;
13111: } else {
1.276 raeburn 13112: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13113: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13114: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 13115: }
13116: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 13117: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 13118: }
13119: if ($currdef ne $newdef) {
13120: my $staticdef;
13121: if ($item eq 'anonsurvey_threshold') {
13122: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13123: $changes{$item} = 1;
13124: }
1.276 raeburn 13125: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 13126: my $setting = $1;
1.276 raeburn 13127: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13128: $changes{$setting} = 1;
1.198 raeburn 13129: }
13130: }
1.139 raeburn 13131: }
13132: }
1.264 raeburn 13133: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13134: my @currclonecode;
13135: if (ref($currclone) eq 'HASH') {
13136: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13137: @currclonecode = @{$currclone->{'instcode'}};
13138: }
13139: }
13140: my $newclone;
1.289 raeburn 13141: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 13142: $newclone = $env{'form.canclone'};
13143: }
13144: if ($newclone eq 'instcode') {
13145: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13146: my (%codedefaults,@code_order,@clonecode);
13147: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13148: \@code_order);
13149: foreach my $item (@code_order) {
13150: if (grep(/^\Q$item\E$/,@newcodes)) {
13151: push(@clonecode,$item);
13152: }
13153: }
13154: if (@clonecode) {
13155: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13156: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13157: if (@diffs) {
13158: $changes{'canclone'} = 1;
13159: }
13160: } else {
13161: $newclone eq '';
13162: }
13163: } elsif ($newclone ne '') {
1.289 raeburn 13164: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13165: }
1.264 raeburn 13166: if ($newclone ne $currclone) {
13167: $changes{'canclone'} = 1;
13168: }
1.257 raeburn 13169: my %credits;
13170: foreach my $type (@types) {
13171: unless ($type eq 'community') {
13172: $credits{$type} = $env{'form.'.$type.'_credits'};
13173: $credits{$type} =~ s/[^\d.]+//g;
13174: }
13175: }
13176: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13177: ($env{'form.coursecredits'} eq '1')) {
13178: $changes{'coursecredits'} = 1;
13179: foreach my $type (keys(%credits)) {
13180: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13181: }
13182: } else {
1.289 raeburn 13183: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 13184: foreach my $type (@types) {
13185: unless ($type eq 'community') {
1.289 raeburn 13186: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 13187: $changes{'coursecredits'} = 1;
13188: }
13189: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13190: }
13191: }
13192: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13193: foreach my $type (@types) {
13194: unless ($type eq 'community') {
13195: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13196: $changes{'coursecredits'} = 1;
13197: last;
13198: }
13199: }
13200: }
13201: }
13202: }
13203: if ($env{'form.postsubmit'} eq '1') {
13204: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13205: my %currtimeout;
13206: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13207: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13208: $changes{'postsubmit'} = 1;
13209: }
13210: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13211: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13212: }
13213: } else {
13214: $changes{'postsubmit'} = 1;
13215: }
13216: foreach my $type (@types) {
13217: my $timeout = $env{'form.'.$type.'_timeout'};
13218: $timeout =~ s/\D//g;
13219: if ($timeout == $staticdefaults{'postsubmit'}) {
13220: $timeout = '';
13221: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13222: $timeout = '0';
13223: }
13224: unless ($timeout eq '') {
13225: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13226: }
13227: if (exists($currtimeout{$type})) {
13228: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 13229: $changes{'postsubmit'} = 1;
1.257 raeburn 13230: }
13231: } elsif ($timeout ne '') {
13232: $changes{'postsubmit'} = 1;
13233: }
13234: }
13235: } else {
13236: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13237: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13238: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13239: $changes{'postsubmit'} = 1;
13240: }
13241: } else {
13242: $changes{'postsubmit'} = 1;
13243: }
1.192 raeburn 13244: }
1.121 raeburn 13245: }
13246: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13247: $dom);
13248: if ($putresult eq 'ok') {
13249: if (keys(%changes) > 0) {
1.213 raeburn 13250: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 13251: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 13252: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 13253: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 13254: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
13255: if ($changes{$item}) {
13256: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13257: }
1.289 raeburn 13258: }
1.192 raeburn 13259: if ($changes{'coursecredits'}) {
13260: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 13261: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13262: $domdefaults{$type.'credits'} =
13263: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13264: }
13265: }
13266: }
13267: if ($changes{'postsubmit'}) {
13268: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13269: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13270: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13271: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13272: $domdefaults{$type.'postsubtimeout'} =
13273: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13274: }
13275: }
1.192 raeburn 13276: }
13277: }
1.198 raeburn 13278: if ($changes{'uploadquota'}) {
13279: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13280: foreach my $type (@types) {
13281: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13282: }
13283: }
13284: }
1.264 raeburn 13285: if ($changes{'canclone'}) {
13286: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13287: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13288: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13289: if (@clonecodes) {
13290: $domdefaults{'canclone'} = join('+',@clonecodes);
13291: }
13292: }
13293: } else {
13294: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13295: }
13296: }
1.121 raeburn 13297: my $cachetime = 24*60*60;
13298: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13299: if (ref($lastactref) eq 'HASH') {
13300: $lastactref->{'domdefaults'} = 1;
13301: }
1.121 raeburn 13302: }
13303: $resulttext = &mt('Changes made:').'<ul>';
13304: foreach my $item (sort(keys(%changes))) {
13305: if ($item eq 'canuse_pdfforms') {
13306: if ($env{'form.'.$item} eq '1') {
13307: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
13308: } else {
13309: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
13310: }
1.257 raeburn 13311: } elsif ($item eq 'uselcmath') {
13312: if ($env{'form.'.$item} eq '1') {
13313: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13314: } else {
13315: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13316: }
13317: } elsif ($item eq 'usejsme') {
13318: if ($env{'form.'.$item} eq '1') {
13319: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13320: } else {
1.289 raeburn 13321: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 13322: }
1.139 raeburn 13323: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 13324: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 13325: } elsif ($item eq 'uploadquota') {
13326: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13327: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13328: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13329: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 13330: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 13331: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 13332: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13333: '</ul>'.
13334: '</li>';
13335: } else {
13336: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13337: }
1.276 raeburn 13338: } elsif ($item eq 'mysqltables') {
13339: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13340: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13341: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13342: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13343: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13344: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
13345: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13346: '</ul>'.
13347: '</li>';
13348: } else {
13349: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13350: }
1.257 raeburn 13351: } elsif ($item eq 'postsubmit') {
13352: if ($domdefaults{'postsubmit'} eq 'off') {
13353: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13354: } else {
13355: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 13356: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 13357: $resulttext .= &mt('durations:').'<ul>';
13358: foreach my $type (@types) {
13359: $resulttext .= '<li>';
13360: my $timeout;
13361: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13362: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13363: }
13364: my $display;
13365: if ($timeout eq '0') {
13366: $display = &mt('unlimited');
13367: } elsif ($timeout eq '') {
13368: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13369: } else {
13370: $display = &mt('[quant,_1,second]',$timeout);
13371: }
13372: if ($type eq 'community') {
13373: $resulttext .= &mt('Communities');
13374: } elsif ($type eq 'official') {
13375: $resulttext .= &mt('Official courses');
13376: } elsif ($type eq 'unofficial') {
13377: $resulttext .= &mt('Unofficial courses');
13378: } elsif ($type eq 'textbook') {
13379: $resulttext .= &mt('Textbook courses');
1.271 raeburn 13380: } elsif ($type eq 'placement') {
13381: $resulttext .= &mt('Placement tests');
1.257 raeburn 13382: }
13383: $resulttext .= ' -- '.$display.'</li>';
13384: }
13385: $resulttext .= '</ul>';
13386: }
1.289 raeburn 13387: $resulttext .= '</li>';
1.257 raeburn 13388: }
1.192 raeburn 13389: } elsif ($item eq 'coursecredits') {
13390: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13391: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 13392: ($domdefaults{'unofficialcredits'} eq '') &&
13393: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 13394: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13395: } else {
13396: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13397: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13398: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 13399: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 13400: '</ul>'.
13401: '</li>';
13402: }
13403: } else {
13404: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13405: }
1.264 raeburn 13406: } elsif ($item eq 'canclone') {
13407: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13408: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13409: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13410: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13411: }
13412: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13413: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13414: } else {
1.289 raeburn 13415: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 13416: }
1.140 raeburn 13417: }
1.121 raeburn 13418: }
13419: $resulttext .= '</ul>';
13420: } else {
13421: $resulttext = &mt('No changes made to course defaults');
13422: }
13423: } else {
13424: $resulttext = '<span class="LC_error">'.
13425: &mt('An error occurred: [_1]',$putresult).'</span>';
13426: }
13427: return $resulttext;
13428: }
13429:
1.231 raeburn 13430: sub modify_selfenrollment {
13431: my ($dom,$lastactref,%domconfig) = @_;
13432: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 13433: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 13434: my %titles = &tool_titles();
1.232 raeburn 13435: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13436: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 13437: $ordered{'default'} = ['types','registered','approval','limit'];
13438:
13439: my (%roles,%shown,%toplevel);
13440: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13441:
13442: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13443: if ($domconfig{'selfenrollment'} eq '') {
13444: $domconfig{'selfenrollment'} = {};
13445: }
13446: }
13447: %toplevel = (
13448: admin => 'Configuration Rights',
13449: default => 'Default settings',
13450: validation => 'Validation of self-enrollment requests',
13451: );
1.233 raeburn 13452: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 13453:
13454: if (ref($ordered{'admin'}) eq 'ARRAY') {
13455: foreach my $item (@{$ordered{'admin'}}) {
13456: foreach my $type (@types) {
13457: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13458: $selfenrollhash{'admin'}{$type}{$item} = 1;
13459: } else {
13460: $selfenrollhash{'admin'}{$type}{$item} = 0;
13461: }
13462: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13463: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13464: if ($selfenrollhash{'admin'}{$type}{$item} ne
13465: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13466: push(@{$changes{'admin'}{$type}},$item);
13467: }
13468: } else {
13469: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13470: push(@{$changes{'admin'}{$type}},$item);
13471: }
13472: }
13473: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13474: push(@{$changes{'admin'}{$type}},$item);
13475: }
13476: }
13477: }
13478: }
13479:
13480: foreach my $item (@{$ordered{'default'}}) {
13481: foreach my $type (@types) {
13482: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13483: if ($item eq 'types') {
13484: unless (($value eq 'all') || ($value eq 'dom')) {
13485: $value = '';
13486: }
13487: } elsif ($item eq 'registered') {
13488: unless ($value eq '1') {
13489: $value = 0;
13490: }
13491: } elsif ($item eq 'approval') {
13492: unless ($value =~ /^[012]$/) {
13493: $value = 0;
13494: }
13495: } else {
13496: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13497: $value = 'none';
13498: }
13499: }
13500: $selfenrollhash{'default'}{$type}{$item} = $value;
13501: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13502: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13503: if ($selfenrollhash{'default'}{$type}{$item} ne
13504: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13505: push(@{$changes{'default'}{$type}},$item);
13506: }
13507: } else {
13508: push(@{$changes{'default'}{$type}},$item);
13509: }
13510: } else {
13511: push(@{$changes{'default'}{$type}},$item);
13512: }
13513: if ($item eq 'limit') {
13514: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13515: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13516: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13517: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13518: }
13519: } else {
13520: $selfenrollhash{'default'}{$type}{'cap'} = '';
13521: }
13522: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13523: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13524: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13525: push(@{$changes{'default'}{$type}},'cap');
13526: }
13527: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13528: push(@{$changes{'default'}{$type}},'cap');
13529: }
13530: }
13531: }
13532: }
13533:
13534: foreach my $item (@{$itemsref}) {
13535: if ($item eq 'fields') {
13536: my @changed;
13537: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13538: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13539: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13540: }
13541: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13542: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13543: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13544: $domconfig{'selfenrollment'}{'validation'}{$item});
13545: } else {
13546: @changed = @{$selfenrollhash{'validation'}{$item}};
13547: }
13548: } else {
13549: @changed = @{$selfenrollhash{'validation'}{$item}};
13550: }
13551: if (@changed) {
13552: if ($selfenrollhash{'validation'}{$item}) {
13553: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13554: } else {
13555: $changes{'validation'}{$item} = &mt('None');
13556: }
13557: }
13558: } else {
13559: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13560: if ($item eq 'markup') {
13561: if ($env{'form.selfenroll_validation_'.$item}) {
13562: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13563: }
13564: }
13565: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13566: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13567: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13568: }
13569: }
13570: }
13571: }
13572:
13573: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13574: $dom);
13575: if ($putresult eq 'ok') {
13576: if (keys(%changes) > 0) {
13577: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13578: $resulttext = &mt('Changes made:').'<ul>';
13579: foreach my $key ('admin','default','validation') {
13580: if (ref($changes{$key}) eq 'HASH') {
13581: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13582: if ($key eq 'validation') {
13583: foreach my $item (@{$itemsref}) {
13584: if (exists($changes{$key}{$item})) {
13585: if ($item eq 'markup') {
13586: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13587: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13588: } else {
13589: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13590: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13591: }
13592: }
13593: }
13594: } else {
13595: foreach my $type (@types) {
13596: if ($type eq 'community') {
13597: $roles{'1'} = &mt('Community personnel');
13598: } else {
13599: $roles{'1'} = &mt('Course personnel');
13600: }
13601: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 13602: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13603: if ($key eq 'admin') {
13604: my @mgrdc = ();
13605: if (ref($ordered{$key}) eq 'ARRAY') {
13606: foreach my $item (@{$ordered{'admin'}}) {
13607: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13608: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13609: push(@mgrdc,$item);
13610: }
13611: }
13612: }
13613: if (@mgrdc) {
13614: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13615: } else {
13616: delete($domdefaults{$type.'selfenrolladmdc'});
13617: }
13618: }
13619: } else {
13620: if (ref($ordered{$key}) eq 'ARRAY') {
13621: foreach my $item (@{$ordered{$key}}) {
13622: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13623: $domdefaults{$type.'selfenroll'.$item} =
13624: $selfenrollhash{$key}{$type}{$item};
13625: }
13626: }
13627: }
13628: }
13629: }
1.231 raeburn 13630: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13631: foreach my $item (@{$ordered{$key}}) {
13632: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13633: $resulttext .= '<li>';
13634: if ($key eq 'admin') {
13635: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13636: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13637: } else {
13638: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13639: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13640: }
13641: $resulttext .= '</li>';
13642: }
13643: }
13644: $resulttext .= '</ul></li>';
13645: }
13646: }
13647: $resulttext .= '</ul></li>';
13648: }
13649: }
1.232 raeburn 13650: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13651: my $cachetime = 24*60*60;
13652: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13653: if (ref($lastactref) eq 'HASH') {
13654: $lastactref->{'domdefaults'} = 1;
13655: }
13656: }
1.231 raeburn 13657: }
13658: $resulttext .= '</ul>';
13659: } else {
13660: $resulttext = &mt('No changes made to self-enrollment settings');
13661: }
13662: } else {
13663: $resulttext = '<span class="LC_error">'.
13664: &mt('An error occurred: [_1]',$putresult).'</span>';
13665: }
13666: return $resulttext;
13667: }
13668:
1.137 raeburn 13669: sub modify_usersessions {
1.212 raeburn 13670: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13671: my @hostingtypes = ('version','excludedomain','includedomain');
13672: my @offloadtypes = ('primary','default');
13673: my %types = (
13674: remote => \@hostingtypes,
13675: hosted => \@hostingtypes,
13676: spares => \@offloadtypes,
13677: );
13678: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13679: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 13680: my (%by_ip,%by_location,@intdoms,@instdoms);
13681: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 13682: my @locations = sort(keys(%by_location));
1.137 raeburn 13683: my (%defaultshash,%changes);
13684: foreach my $prefix (@prefixes) {
13685: $defaultshash{'usersessions'}{$prefix} = {};
13686: }
1.212 raeburn 13687: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13688: my $resulttext;
1.138 raeburn 13689: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13690: foreach my $prefix (@prefixes) {
1.145 raeburn 13691: next if ($prefix eq 'spares');
13692: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13693: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13694: if ($type eq 'version') {
13695: my $value = $env{'form.'.$prefix.'_'.$type};
13696: my $okvalue;
13697: if ($value ne '') {
13698: if (grep(/^\Q$value\E$/,@lcversions)) {
13699: $okvalue = $value;
13700: }
13701: }
13702: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13703: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13704: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13705: if ($inuse == 0) {
13706: $changes{$prefix}{$type} = 1;
13707: } else {
13708: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13709: $changes{$prefix}{$type} = 1;
13710: }
13711: if ($okvalue ne '') {
13712: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13713: }
13714: }
13715: } else {
13716: if (($inuse == 1) && ($okvalue ne '')) {
13717: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13718: $changes{$prefix}{$type} = 1;
13719: }
13720: }
13721: } else {
13722: if (($inuse == 1) && ($okvalue ne '')) {
13723: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13724: $changes{$prefix}{$type} = 1;
13725: }
13726: }
13727: } else {
13728: if (($inuse == 1) && ($okvalue ne '')) {
13729: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13730: $changes{$prefix}{$type} = 1;
13731: }
13732: }
13733: } else {
13734: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13735: my @okvals;
13736: foreach my $val (@vals) {
1.138 raeburn 13737: if ($val =~ /:/) {
13738: my @items = split(/:/,$val);
13739: foreach my $item (@items) {
13740: if (ref($by_location{$item}) eq 'ARRAY') {
13741: push(@okvals,$item);
13742: }
13743: }
13744: } else {
13745: if (ref($by_location{$val}) eq 'ARRAY') {
13746: push(@okvals,$val);
13747: }
1.137 raeburn 13748: }
13749: }
13750: @okvals = sort(@okvals);
13751: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13752: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13753: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13754: if ($inuse == 0) {
13755: $changes{$prefix}{$type} = 1;
13756: } else {
13757: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13758: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13759: if (@changed > 0) {
13760: $changes{$prefix}{$type} = 1;
13761: }
13762: }
13763: } else {
13764: if ($inuse == 1) {
13765: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13766: $changes{$prefix}{$type} = 1;
13767: }
13768: }
13769: } else {
13770: if ($inuse == 1) {
13771: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13772: $changes{$prefix}{$type} = 1;
13773: }
13774: }
13775: } else {
13776: if ($inuse == 1) {
13777: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13778: $changes{$prefix}{$type} = 1;
13779: }
13780: }
13781: }
13782: }
13783: }
1.145 raeburn 13784:
13785: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 13786: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 13787: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13788: my $savespares;
13789:
13790: foreach my $lonhost (sort(keys(%servers))) {
13791: my $serverhomeID =
13792: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 13793: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 13794: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13795: my %spareschg;
13796: foreach my $type (@{$types{'spares'}}) {
13797: my @okspares;
13798: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13799: foreach my $server (@checked) {
1.152 raeburn 13800: if (&Apache::lonnet::hostname($server) ne '') {
13801: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13802: unless (grep(/^\Q$server\E$/,@okspares)) {
13803: push(@okspares,$server);
13804: }
1.145 raeburn 13805: }
13806: }
13807: }
13808: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13809: my $newspare;
1.152 raeburn 13810: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13811: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 13812: $newspare = $new;
13813: }
13814: }
1.152 raeburn 13815: my @spares;
13816: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13817: @spares = sort(@okspares,$newspare);
13818: } else {
13819: @spares = sort(@okspares);
13820: }
13821: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 13822: if (ref($spareid{$lonhost}) eq 'HASH') {
13823: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 13824: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 13825: if (@diffs > 0) {
13826: $spareschg{$type} = 1;
13827: }
13828: }
13829: }
13830: }
13831: if (keys(%spareschg) > 0) {
13832: $changes{'spares'}{$lonhost} = \%spareschg;
13833: }
13834: }
1.261 raeburn 13835: $defaultshash{'usersessions'}{'offloadnow'} = {};
13836: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13837: my @okoffload;
13838: if (@offloadnow) {
13839: foreach my $server (@offloadnow) {
13840: if (&Apache::lonnet::hostname($server) ne '') {
13841: unless (grep(/^\Q$server\E$/,@okoffload)) {
13842: push(@okoffload,$server);
13843: }
13844: }
13845: }
13846: if (@okoffload) {
13847: foreach my $lonhost (@okoffload) {
13848: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13849: }
13850: }
13851: }
1.145 raeburn 13852: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13853: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13854: if (ref($changes{'spares'}) eq 'HASH') {
13855: if (keys(%{$changes{'spares'}}) > 0) {
13856: $savespares = 1;
13857: }
13858: }
13859: } else {
13860: $savespares = 1;
13861: }
1.261 raeburn 13862: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13863: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13864: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13865: $changes{'offloadnow'} = 1;
13866: last;
13867: }
13868: }
13869: unless ($changes{'offloadnow'}) {
1.289 raeburn 13870: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 13871: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13872: $changes{'offloadnow'} = 1;
13873: last;
13874: }
13875: }
13876: }
13877: } elsif (@okoffload) {
13878: $changes{'offloadnow'} = 1;
13879: }
13880: } elsif (@okoffload) {
13881: $changes{'offloadnow'} = 1;
1.145 raeburn 13882: }
1.147 raeburn 13883: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13884: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13885: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13886: $dom);
13887: if ($putresult eq 'ok') {
13888: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13889: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13890: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13891: }
13892: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13893: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13894: }
1.261 raeburn 13895: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13896: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13897: }
1.137 raeburn 13898: }
13899: my $cachetime = 24*60*60;
13900: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 13901: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 13902: if (ref($lastactref) eq 'HASH') {
13903: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 13904: $lastactref->{'usersessions'} = 1;
1.212 raeburn 13905: }
1.147 raeburn 13906: if (keys(%changes) > 0) {
13907: my %lt = &usersession_titles();
13908: $resulttext = &mt('Changes made:').'<ul>';
13909: foreach my $prefix (@prefixes) {
13910: if (ref($changes{$prefix}) eq 'HASH') {
13911: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13912: if ($prefix eq 'spares') {
13913: if (ref($changes{$prefix}) eq 'HASH') {
13914: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13915: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13916: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 13917: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13918: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13919: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13920: foreach my $type (@{$types{$prefix}}) {
13921: if ($changes{$prefix}{$lonhost}{$type}) {
13922: my $offloadto = &mt('None');
13923: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13924: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13925: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13926: }
1.145 raeburn 13927: }
1.147 raeburn 13928: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13929: }
1.137 raeburn 13930: }
13931: }
1.147 raeburn 13932: $resulttext .= '</li>';
1.137 raeburn 13933: }
13934: }
1.147 raeburn 13935: } else {
13936: foreach my $type (@{$types{$prefix}}) {
13937: if (defined($changes{$prefix}{$type})) {
13938: my $newvalue;
13939: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13940: if (ref($defaultshash{'usersessions'}{$prefix})) {
13941: if ($type eq 'version') {
13942: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13943: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13944: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13945: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13946: }
1.145 raeburn 13947: }
13948: }
13949: }
1.147 raeburn 13950: if ($newvalue eq '') {
13951: if ($type eq 'version') {
13952: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13953: } else {
13954: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13955: }
1.145 raeburn 13956: } else {
1.147 raeburn 13957: if ($type eq 'version') {
13958: $newvalue .= ' '.&mt('(or later)');
13959: }
13960: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13961: }
1.137 raeburn 13962: }
13963: }
13964: }
1.147 raeburn 13965: $resulttext .= '</ul>';
1.137 raeburn 13966: }
13967: }
1.261 raeburn 13968: if ($changes{'offloadnow'}) {
13969: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13970: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13971: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13972: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13973: $resulttext .= '<li>'.$lonhost.'</li>';
13974: }
13975: $resulttext .= '</ul>';
13976: } else {
13977: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13978: }
13979: } else {
13980: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13981: }
13982: }
1.147 raeburn 13983: $resulttext .= '</ul>';
13984: } else {
13985: $resulttext = $nochgmsg;
1.137 raeburn 13986: }
13987: } else {
13988: $resulttext = '<span class="LC_error">'.
13989: &mt('An error occurred: [_1]',$putresult).'</span>';
13990: }
13991: } else {
1.147 raeburn 13992: $resulttext = $nochgmsg;
1.137 raeburn 13993: }
13994: return $resulttext;
13995: }
13996:
1.275 raeburn 13997: sub modify_ssl {
13998: my ($dom,$lastactref,%domconfig) = @_;
13999: my (%by_ip,%by_location,@intdoms,@instdoms);
14000: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14001: my @locations = sort(keys(%by_location));
14002: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14003: my (%defaultshash,%changes);
14004: my $action = 'ssl';
1.293 raeburn 14005: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 14006: foreach my $prefix (@prefixes) {
14007: $defaultshash{$action}{$prefix} = {};
14008: }
14009: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14010: my $resulttext;
14011: my %iphost = &Apache::lonnet::get_iphost();
14012: my @reptypes = ('certreq','nocertreq');
14013: my @connecttypes = ('dom','intdom','other');
14014: my %types = (
1.293 raeburn 14015: connto => \@connecttypes,
14016: connfrom => \@connecttypes,
14017: replication => \@reptypes,
1.275 raeburn 14018: );
14019: foreach my $prefix (sort(keys(%types))) {
14020: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 14021: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14022: my $value = 'yes';
14023: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
14024: $value = $env{'form.'.$prefix.'_'.$type};
14025: }
14026: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14027: if ($domconfig{$action}{$prefix}{$type} ne '') {
14028: if ($value ne $domconfig{$action}{$prefix}{$type}) {
14029: $changes{$prefix}{$type} = 1;
14030: }
14031: $defaultshash{$action}{$prefix}{$type} = $value;
14032: } else {
14033: $defaultshash{$action}{$prefix}{$type} = $value;
14034: $changes{$prefix}{$type} = 1;
14035: }
14036: } else {
14037: $defaultshash{$action}{$prefix}{$type} = $value;
14038: $changes{$prefix}{$type} = 1;
14039: }
14040: if (($type eq 'dom') && (keys(%servers) == 1)) {
14041: delete($changes{$prefix}{$type});
14042: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
14043: delete($changes{$prefix}{$type});
14044: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
14045: delete($changes{$prefix}{$type});
14046: }
14047: } elsif ($prefix eq 'replication') {
14048: if (@locations > 0) {
14049: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14050: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14051: my @okvals;
14052: foreach my $val (@vals) {
14053: if ($val =~ /:/) {
14054: my @items = split(/:/,$val);
14055: foreach my $item (@items) {
14056: if (ref($by_location{$item}) eq 'ARRAY') {
14057: push(@okvals,$item);
14058: }
14059: }
14060: } else {
14061: if (ref($by_location{$val}) eq 'ARRAY') {
14062: push(@okvals,$val);
14063: }
14064: }
14065: }
14066: @okvals = sort(@okvals);
14067: if (ref($domconfig{$action}) eq 'HASH') {
14068: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14069: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
14070: if ($inuse == 0) {
14071: $changes{$prefix}{$type} = 1;
14072: } else {
14073: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14074: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
14075: if (@changed > 0) {
14076: $changes{$prefix}{$type} = 1;
14077: }
14078: }
14079: } else {
14080: if ($inuse == 1) {
14081: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14082: $changes{$prefix}{$type} = 1;
14083: }
14084: }
14085: } else {
14086: if ($inuse == 1) {
14087: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14088: $changes{$prefix}{$type} = 1;
14089: }
14090: }
14091: } else {
14092: if ($inuse == 1) {
14093: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14094: $changes{$prefix}{$type} = 1;
14095: }
14096: }
14097: }
14098: }
14099: }
14100: }
14101: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
14102: if (keys(%changes) > 0) {
14103: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14104: $dom);
14105: if ($putresult eq 'ok') {
14106: if (ref($defaultshash{$action}) eq 'HASH') {
14107: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
14108: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
14109: }
1.293 raeburn 14110: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
14111: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
14112: }
14113: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
14114: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 14115: }
14116: }
14117: my $cachetime = 24*60*60;
14118: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14119: if (ref($lastactref) eq 'HASH') {
14120: $lastactref->{'domdefaults'} = 1;
14121: }
14122: if (keys(%changes) > 0) {
14123: my %titles = &ssl_titles();
14124: $resulttext = &mt('Changes made:').'<ul>';
14125: foreach my $prefix (@prefixes) {
14126: if (ref($changes{$prefix}) eq 'HASH') {
14127: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
14128: foreach my $type (@{$types{$prefix}}) {
14129: if (defined($changes{$prefix}{$type})) {
14130: my $newvalue;
14131: if (ref($defaultshash{$action}) eq 'HASH') {
14132: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 14133: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14134: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
14135: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
14136: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
14137: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
14138: }
14139: }
14140: }
14141: if ($newvalue eq '') {
14142: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
14143: } else {
14144: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
14145: }
14146: }
14147: }
14148: }
14149: $resulttext .= '</ul>';
14150: }
14151: }
14152: } else {
14153: $resulttext = $nochgmsg;
14154: }
14155: } else {
14156: $resulttext = '<span class="LC_error">'.
14157: &mt('An error occurred: [_1]',$putresult).'</span>';
14158: }
14159: } else {
14160: $resulttext = $nochgmsg;
14161: }
14162: return $resulttext;
14163: }
14164:
1.279 raeburn 14165: sub modify_trust {
14166: my ($dom,$lastactref,%domconfig) = @_;
14167: my (%by_ip,%by_location,@intdoms,@instdoms);
14168: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14169: my @locations = sort(keys(%by_location));
14170: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
14171: my @types = ('exc','inc');
14172: my (%defaultshash,%changes);
14173: foreach my $prefix (@prefixes) {
14174: $defaultshash{'trust'}{$prefix} = {};
14175: }
14176: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14177: my $resulttext;
14178: foreach my $prefix (@prefixes) {
14179: foreach my $type (@types) {
14180: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14181: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14182: my @okvals;
14183: foreach my $val (@vals) {
14184: if ($val =~ /:/) {
14185: my @items = split(/:/,$val);
14186: foreach my $item (@items) {
14187: if (ref($by_location{$item}) eq 'ARRAY') {
14188: push(@okvals,$item);
14189: }
14190: }
14191: } else {
14192: if (ref($by_location{$val}) eq 'ARRAY') {
14193: push(@okvals,$val);
14194: }
14195: }
14196: }
14197: @okvals = sort(@okvals);
14198: if (ref($domconfig{'trust'}) eq 'HASH') {
14199: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
14200: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14201: if ($inuse == 0) {
14202: $changes{$prefix}{$type} = 1;
14203: } else {
14204: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14205: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
14206: if (@changed > 0) {
14207: $changes{$prefix}{$type} = 1;
14208: }
14209: }
14210: } else {
14211: if ($inuse == 1) {
14212: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14213: $changes{$prefix}{$type} = 1;
14214: }
14215: }
14216: } else {
14217: if ($inuse == 1) {
14218: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14219: $changes{$prefix}{$type} = 1;
14220: }
14221: }
14222: } else {
14223: if ($inuse == 1) {
14224: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14225: $changes{$prefix}{$type} = 1;
14226: }
14227: }
14228: }
14229: }
14230: my $nochgmsg = &mt('No changes made to trust settings.');
14231: if (keys(%changes) > 0) {
14232: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14233: $dom);
14234: if ($putresult eq 'ok') {
14235: if (ref($defaultshash{'trust'}) eq 'HASH') {
14236: foreach my $prefix (@prefixes) {
14237: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
14238: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
14239: }
14240: }
14241: }
14242: my $cachetime = 24*60*60;
14243: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14244: if (ref($lastactref) eq 'HASH') {
14245: $lastactref->{'domdefaults'} = 1;
14246: }
14247: if (keys(%changes) > 0) {
14248: my %lt = &trust_titles();
14249: $resulttext = &mt('Changes made:').'<ul>';
14250: foreach my $prefix (@prefixes) {
14251: if (ref($changes{$prefix}) eq 'HASH') {
14252: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14253: foreach my $type (@types) {
14254: if (defined($changes{$prefix}{$type})) {
14255: my $newvalue;
14256: if (ref($defaultshash{'trust'}) eq 'HASH') {
14257: if (ref($defaultshash{'trust'}{$prefix})) {
14258: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14259: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
14260: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
14261: }
14262: }
14263: }
14264: }
14265: if ($newvalue eq '') {
14266: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14267: } else {
14268: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
14269: }
14270: }
14271: }
14272: $resulttext .= '</ul>';
14273: }
14274: }
14275: $resulttext .= '</ul>';
14276: } else {
14277: $resulttext = $nochgmsg;
14278: }
14279: } else {
14280: $resulttext = '<span class="LC_error">'.
14281: &mt('An error occurred: [_1]',$putresult).'</span>';
14282: }
14283: } else {
14284: $resulttext = $nochgmsg;
14285: }
14286: return $resulttext;
14287: }
14288:
1.150 raeburn 14289: sub modify_loadbalancing {
14290: my ($dom,%domconfig) = @_;
14291: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14292: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14293: my ($othertitle,$usertypes,$types) =
14294: &Apache::loncommon::sorted_inst_types($dom);
14295: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 14296: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 14297: my @sparestypes = ('primary','default');
14298: my %typetitles = &sparestype_titles();
14299: my $resulttext;
1.171 raeburn 14300: my (%currbalancer,%currtargets,%currrules,%existing);
14301: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14302: %existing = %{$domconfig{'loadbalancing'}};
14303: }
14304: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
14305: \%currtargets,\%currrules);
14306: my ($saveloadbalancing,%defaultshash,%changes);
14307: my ($alltypes,$othertypes,$titles) =
14308: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14309: my %ruletitles = &offloadtype_text();
14310: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14311: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14312: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14313: if ($balancer eq '') {
14314: next;
14315: }
1.210 raeburn 14316: if (!exists($servers{$balancer})) {
1.171 raeburn 14317: if (exists($currbalancer{$balancer})) {
14318: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14319: }
1.171 raeburn 14320: next;
14321: }
14322: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14323: push(@{$changes{'delete'}},$balancer);
14324: next;
14325: }
14326: if (!exists($currbalancer{$balancer})) {
14327: push(@{$changes{'add'}},$balancer);
14328: }
14329: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14330: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14331: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14332: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14333: $saveloadbalancing = 1;
14334: }
14335: foreach my $sparetype (@sparestypes) {
14336: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14337: my @offloadto;
14338: foreach my $target (@targets) {
14339: if (($servers{$target}) && ($target ne $balancer)) {
14340: if ($sparetype eq 'default') {
14341: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14342: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14343: }
14344: }
1.171 raeburn 14345: unless(grep(/^\Q$target\E$/,@offloadto)) {
14346: push(@offloadto,$target);
14347: }
1.150 raeburn 14348: }
14349: }
1.284 raeburn 14350: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14351: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14352: push(@offloadto,$balancer);
14353: }
14354: }
14355: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14356: }
1.171 raeburn 14357: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14358: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14359: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14360: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14361: if (@targetdiffs > 0) {
1.171 raeburn 14362: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14363: }
1.171 raeburn 14364: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14365: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14366: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14367: }
14368: }
14369: }
14370: } else {
1.171 raeburn 14371: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 14372: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14373: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14374: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14375: $changes{'curr'}{$balancer}{'targets'} = 1;
14376: }
1.150 raeburn 14377: }
14378: }
1.210 raeburn 14379: }
1.150 raeburn 14380: }
14381: my $ishomedom;
1.171 raeburn 14382: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14383: $ishomedom = 1;
1.150 raeburn 14384: }
14385: if (ref($alltypes) eq 'ARRAY') {
14386: foreach my $type (@{$alltypes}) {
14387: my $rule;
1.210 raeburn 14388: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14389: (!$ishomedom)) {
1.171 raeburn 14390: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14391: }
14392: if ($rule eq 'specific') {
1.255 raeburn 14393: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 14394: if (exists($servers{$specifiedhost})) {
1.255 raeburn 14395: $rule = $specifiedhost;
14396: }
1.150 raeburn 14397: }
1.171 raeburn 14398: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14399: if (ref($currrules{$balancer}) eq 'HASH') {
14400: if ($rule ne $currrules{$balancer}{$type}) {
14401: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14402: }
14403: } elsif ($rule ne '') {
1.171 raeburn 14404: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14405: }
14406: }
14407: }
1.171 raeburn 14408: }
14409: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14410: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14411: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14412: $defaultshash{'loadbalancing'} = {};
14413: }
14414: my $putresult = &Apache::lonnet::put_dom('configuration',
14415: \%defaultshash,$dom);
14416: if ($putresult eq 'ok') {
14417: if (keys(%changes) > 0) {
1.252 raeburn 14418: my %toupdate;
1.171 raeburn 14419: if (ref($changes{'delete'}) eq 'ARRAY') {
14420: foreach my $balancer (sort(@{$changes{'delete'}})) {
14421: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 14422: $toupdate{$balancer} = 1;
1.150 raeburn 14423: }
1.171 raeburn 14424: }
14425: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 14426: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 14427: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 14428: $toupdate{$balancer} = 1;
1.171 raeburn 14429: }
14430: }
14431: if (ref($changes{'curr'}) eq 'HASH') {
14432: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 14433: $toupdate{$balancer} = 1;
1.171 raeburn 14434: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14435: if ($changes{'curr'}{$balancer}{'targets'}) {
14436: my %offloadstr;
14437: foreach my $sparetype (@sparestypes) {
14438: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14439: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14440: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14441: }
14442: }
1.150 raeburn 14443: }
1.171 raeburn 14444: if (keys(%offloadstr) == 0) {
14445: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14446: } else {
1.171 raeburn 14447: my $showoffload;
14448: foreach my $sparetype (@sparestypes) {
14449: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14450: if (defined($offloadstr{$sparetype})) {
14451: $showoffload .= $offloadstr{$sparetype};
14452: } else {
14453: $showoffload .= &mt('None');
14454: }
14455: $showoffload .= (' 'x3);
14456: }
14457: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14458: }
14459: }
14460: }
1.171 raeburn 14461: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14462: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14463: foreach my $type (@{$alltypes}) {
14464: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14465: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14466: my $balancetext;
14467: if ($rule eq '') {
14468: $balancetext = $ruletitles{'default'};
1.209 raeburn 14469: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 14470: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 14471: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 14472: foreach my $sparetype (@sparestypes) {
14473: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14474: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14475: }
14476: }
1.253 raeburn 14477: foreach my $item (@{$alltypes}) {
14478: next if ($item =~ /^_LC_ipchange/);
14479: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14480: if ($hasrule eq 'homeserver') {
14481: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14482: } else {
14483: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14484: if ($servers{$hasrule}) {
14485: $toupdate{$hasrule} = 1;
14486: }
14487: }
14488: }
14489: }
1.254 raeburn 14490: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14491: $balancetext = $ruletitles{$rule};
14492: } else {
14493: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14494: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14495: if ($receiver) {
14496: $toupdate{$receiver};
14497: }
14498: }
14499: } else {
14500: $balancetext = $ruletitles{$rule};
1.252 raeburn 14501: }
1.171 raeburn 14502: } else {
14503: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14504: }
1.210 raeburn 14505: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14506: }
14507: }
14508: }
14509: }
1.252 raeburn 14510: if (keys(%toupdate)) {
14511: my %thismachine;
14512: my $updatedhere;
14513: my $cachetime = 60*60*24;
14514: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14515: foreach my $lonhost (keys(%toupdate)) {
14516: if ($thismachine{$lonhost}) {
14517: unless ($updatedhere) {
14518: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14519: $defaultshash{'loadbalancing'},
14520: $cachetime);
14521: $updatedhere = 1;
14522: }
14523: } else {
14524: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14525: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14526: }
14527: }
14528: }
1.150 raeburn 14529: }
1.171 raeburn 14530: }
14531: if ($resulttext ne '') {
14532: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14533: } else {
14534: $resulttext = $nochgmsg;
14535: }
14536: } else {
1.171 raeburn 14537: $resulttext = $nochgmsg;
1.150 raeburn 14538: }
14539: } else {
1.171 raeburn 14540: $resulttext = '<span class="LC_error">'.
14541: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14542: }
14543: } else {
1.171 raeburn 14544: $resulttext = $nochgmsg;
1.150 raeburn 14545: }
14546: return $resulttext;
14547: }
14548:
1.48 raeburn 14549: sub recurse_check {
14550: my ($chkcats,$categories,$depth,$name) = @_;
14551: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14552: my $chg = 0;
14553: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14554: my $category = $chkcats->[$depth]{$name}[$j];
14555: my $item;
14556: if ($category eq '') {
14557: $chg ++;
14558: } else {
14559: my $deeper = $depth + 1;
14560: $item = &escape($category).':'.&escape($name).':'.$depth;
14561: if ($chg) {
14562: $categories->{$item} -= $chg;
14563: }
14564: &recurse_check($chkcats,$categories,$deeper,$category);
14565: $deeper --;
14566: }
14567: }
14568: }
14569: return;
14570: }
14571:
14572: sub recurse_cat_deletes {
14573: my ($item,$coursecategories,$deletions) = @_;
14574: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14575: my $subdepth = $depth + 1;
14576: if (ref($coursecategories) eq 'HASH') {
14577: foreach my $subitem (keys(%{$coursecategories})) {
14578: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14579: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14580: delete($coursecategories->{$subitem});
14581: $deletions->{$subitem} = 1;
14582: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 14583: }
1.48 raeburn 14584: }
14585: }
14586: return;
14587: }
14588:
1.125 raeburn 14589: sub active_dc_picker {
1.191 raeburn 14590: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 14591: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 14592: my @domcoord = keys(%domcoords);
14593: if (keys(%currhash)) {
14594: foreach my $dc (keys(%currhash)) {
14595: unless (exists($domcoords{$dc})) {
14596: push(@domcoord,$dc);
14597: }
14598: }
14599: }
14600: @domcoord = sort(@domcoord);
1.210 raeburn 14601: my $numdcs = scalar(@domcoord);
1.191 raeburn 14602: my $rows = 0;
14603: my $table;
1.125 raeburn 14604: if ($numdcs > 1) {
1.191 raeburn 14605: $table = '<table>';
14606: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14607: my $rem = $i%($numinrow);
14608: if ($rem == 0) {
14609: if ($i > 0) {
1.191 raeburn 14610: $table .= '</tr>';
1.125 raeburn 14611: }
1.191 raeburn 14612: $table .= '<tr>';
14613: $rows ++;
1.125 raeburn 14614: }
1.191 raeburn 14615: my $check = '';
14616: if ($inputtype eq 'radio') {
14617: if (keys(%currhash) == 0) {
14618: if (!$i) {
14619: $check = ' checked="checked"';
14620: }
14621: } elsif (exists($currhash{$domcoord[$i]})) {
14622: $check = ' checked="checked"';
14623: }
14624: } else {
14625: if (exists($currhash{$domcoord[$i]})) {
14626: $check = ' checked="checked"';
1.125 raeburn 14627: }
14628: }
1.191 raeburn 14629: if ($i == @domcoord - 1) {
1.125 raeburn 14630: my $colsleft = $numinrow - $rem;
14631: if ($colsleft > 1) {
1.191 raeburn 14632: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14633: } else {
1.191 raeburn 14634: $table .= '<td class="LC_left_item">';
1.125 raeburn 14635: }
14636: } else {
1.191 raeburn 14637: $table .= '<td class="LC_left_item">';
14638: }
14639: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14640: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14641: $table .= '<span class="LC_nobreak"><label>'.
14642: '<input type="'.$inputtype.'" name="'.$name.'"'.
14643: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14644: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 14645: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 14646: }
1.219 raeburn 14647: $table .= '</label></span></td>';
1.191 raeburn 14648: }
14649: $table .= '</tr></table>';
14650: } elsif ($numdcs == 1) {
1.219 raeburn 14651: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14652: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 14653: if ($inputtype eq 'radio') {
1.247 raeburn 14654: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 14655: if ($user ne $dcname.':'.$dcdom) {
14656: $table .= ' ('.$dcname.':'.$dcdom.')';
14657: }
1.191 raeburn 14658: } else {
14659: my $check;
14660: if (exists($currhash{$domcoord[0]})) {
14661: $check = ' checked="checked"';
1.125 raeburn 14662: }
1.247 raeburn 14663: $table = '<span class="LC_nobreak"><label>'.
14664: '<input type="checkbox" name="'.$name.'" '.
14665: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 14666: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 14667: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 14668: }
1.220 raeburn 14669: $table .= '</label></span>';
1.191 raeburn 14670: $rows ++;
1.125 raeburn 14671: }
14672: }
1.191 raeburn 14673: return ($numdcs,$table,$rows);
1.125 raeburn 14674: }
14675:
1.137 raeburn 14676: sub usersession_titles {
14677: return &Apache::lonlocal::texthash(
14678: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14679: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14680: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14681: version => 'LON-CAPA version requirement',
1.138 raeburn 14682: excludedomain => 'Allow all, but exclude specific domains',
14683: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14684: primary => 'Primary (checked first)',
1.154 raeburn 14685: default => 'Default',
1.137 raeburn 14686: );
14687: }
14688:
1.152 raeburn 14689: sub id_for_thisdom {
14690: my (%servers) = @_;
14691: my %altids;
14692: foreach my $server (keys(%servers)) {
14693: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14694: if ($serverhome ne $server) {
14695: $altids{$serverhome} = $server;
14696: }
14697: }
14698: return %altids;
14699: }
14700:
1.150 raeburn 14701: sub count_servers {
14702: my ($currbalancer,%servers) = @_;
14703: my (@spares,$numspares);
14704: foreach my $lonhost (sort(keys(%servers))) {
14705: next if ($currbalancer eq $lonhost);
14706: push(@spares,$lonhost);
14707: }
14708: if ($currbalancer) {
14709: $numspares = scalar(@spares);
14710: } else {
14711: $numspares = scalar(@spares) - 1;
14712: }
14713: return ($numspares,@spares);
14714: }
14715:
14716: sub lonbalance_targets_js {
1.171 raeburn 14717: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14718: my $select = &mt('Select');
14719: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14720: if (ref($servers) eq 'HASH') {
14721: $alltargets = join("','",sort(keys(%{$servers})));
14722: my @homedoms;
14723: foreach my $server (sort(keys(%{$servers}))) {
14724: if (&Apache::lonnet::host_domain($server) eq $dom) {
14725: push(@homedoms,'1');
14726: } else {
14727: push(@homedoms,'0');
14728: }
14729: }
14730: $allishome = join("','",@homedoms);
14731: }
14732: if (ref($types) eq 'ARRAY') {
14733: if (@{$types} > 0) {
14734: @alltypes = @{$types};
14735: }
14736: }
14737: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14738: $allinsttypes = join("','",@alltypes);
1.171 raeburn 14739: my (%currbalancer,%currtargets,%currrules,%existing);
14740: if (ref($settings) eq 'HASH') {
14741: %existing = %{$settings};
14742: }
14743: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14744: \%currtargets,\%currrules);
1.210 raeburn 14745: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14746: return <<"END";
14747:
14748: <script type="text/javascript">
14749: // <![CDATA[
14750:
1.171 raeburn 14751: currBalancers = new Array('$balancers');
14752:
14753: function toggleTargets(balnum) {
14754: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14755: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14756: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14757: var prevbalancer = prevhostitem.value;
14758: var baltotal = document.getElementById('loadbalancing_total').value;
14759: prevhostitem.value = balancer;
14760: if (prevbalancer != '') {
14761: var prevIdx = currBalancers.indexOf(prevbalancer);
14762: if (prevIdx != -1) {
14763: currBalancers.splice(prevIdx,1);
14764: }
14765: }
1.150 raeburn 14766: if (balancer == '') {
1.171 raeburn 14767: hideSpares(balnum);
1.150 raeburn 14768: } else {
1.171 raeburn 14769: var currIdx = currBalancers.indexOf(balancer);
14770: if (currIdx == -1) {
14771: currBalancers.push(balancer);
14772: }
1.150 raeburn 14773: var homedoms = new Array('$allishome');
1.171 raeburn 14774: var ishomedom = homedoms[lonhostitem.selectedIndex];
14775: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14776: }
1.171 raeburn 14777: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14778: return;
14779: }
14780:
1.171 raeburn 14781: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14782: var alltargets = new Array('$alltargets');
14783: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14784: var offloadtypes = new Array('primary','default');
14785:
1.171 raeburn 14786: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14787: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14788:
1.151 raeburn 14789: for (var i=0; i<offloadtypes.length; i++) {
14790: var count = 0;
14791: for (var j=0; j<alltargets.length; j++) {
14792: if (alltargets[j] != balancer) {
1.171 raeburn 14793: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14794: item.value = alltargets[j];
14795: item.style.textAlign='left';
14796: item.style.textFace='normal';
14797: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14798: if (currBalancers.indexOf(alltargets[j]) == -1) {
14799: item.disabled = '';
14800: } else {
14801: item.disabled = 'disabled';
14802: item.checked = false;
14803: }
1.151 raeburn 14804: count ++;
14805: }
1.150 raeburn 14806: }
14807: }
1.151 raeburn 14808: for (var k=0; k<insttypes.length; k++) {
14809: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14810: if (ishomedom == 1) {
1.171 raeburn 14811: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14812: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14813: } else {
1.171 raeburn 14814: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14815: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14816: }
14817: } else {
1.171 raeburn 14818: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14819: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14820: }
1.151 raeburn 14821: if ((insttypes[k] != '_LC_external') &&
14822: ((insttypes[k] != '_LC_internetdom') ||
14823: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 14824: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14825: item.options.length = 0;
14826: item.options[0] = new Option("","",true,true);
1.210 raeburn 14827: var idx = 0;
1.151 raeburn 14828: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 14829: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14830: idx ++;
14831: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14832: }
14833: }
14834: }
14835: }
14836: return;
14837: }
14838:
1.171 raeburn 14839: function hideSpares(balnum) {
1.150 raeburn 14840: var alltargets = new Array('$alltargets');
14841: var insttypes = new Array('$allinsttypes');
14842: var offloadtypes = new Array('primary','default');
14843:
1.171 raeburn 14844: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14845: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14846:
14847: var total = alltargets.length - 1;
14848: for (var i=0; i<offloadtypes; i++) {
14849: for (var j=0; j<total; j++) {
1.171 raeburn 14850: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14851: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14852: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14853: }
1.150 raeburn 14854: }
14855: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 14856: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14857: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14858: if (insttypes[k] != '_LC_external') {
1.171 raeburn 14859: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14860: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14861: }
14862: }
14863: return;
14864: }
14865:
1.171 raeburn 14866: function checkOffloads(item,balnum,type) {
1.150 raeburn 14867: var alltargets = new Array('$alltargets');
14868: var offloadtypes = new Array('primary','default');
14869: if (item.checked) {
14870: var total = alltargets.length - 1;
14871: var other;
14872: if (type == offloadtypes[0]) {
1.151 raeburn 14873: other = offloadtypes[1];
1.150 raeburn 14874: } else {
1.151 raeburn 14875: other = offloadtypes[0];
1.150 raeburn 14876: }
14877: for (var i=0; i<total; i++) {
1.171 raeburn 14878: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14879: if (server == item.value) {
1.171 raeburn 14880: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14881: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14882: }
14883: }
14884: }
14885: }
14886: return;
14887: }
14888:
1.171 raeburn 14889: function singleServerToggle(balnum,type) {
14890: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 14891: if (offloadtoSelIdx == 0) {
1.171 raeburn 14892: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14893: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14894:
14895: } else {
1.171 raeburn 14896: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14897: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 14898: }
14899: return;
14900: }
14901:
1.171 raeburn 14902: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 14903: if (type == '_LC_external') {
1.171 raeburn 14904: return;
1.150 raeburn 14905: }
1.171 raeburn 14906: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 14907: for (var i=0; i<typesRules.length; i++) {
14908: if (formname.elements[typesRules[i]].checked) {
14909: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 14910: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14911: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14912: } else {
1.171 raeburn 14913: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14914: }
14915: }
14916: }
14917: return;
14918: }
14919:
14920: function balancerDeleteChange(balnum) {
14921: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14922: var baltotal = document.getElementById('loadbalancing_total').value;
14923: var addtarget;
14924: var removetarget;
14925: var action = 'delete';
14926: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14927: var lonhost = hostitem.value;
14928: var currIdx = currBalancers.indexOf(lonhost);
14929: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14930: if (currIdx != -1) {
14931: currBalancers.splice(currIdx,1);
14932: }
14933: addtarget = lonhost;
14934: } else {
14935: if (currIdx == -1) {
14936: currBalancers.push(lonhost);
14937: }
14938: removetarget = lonhost;
14939: action = 'undelete';
14940: }
14941: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14942: }
14943: return;
14944: }
14945:
14946: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14947: if (baltotal > 1) {
14948: var offloadtypes = new Array('primary','default');
14949: var alltargets = new Array('$alltargets');
14950: var insttypes = new Array('$allinsttypes');
14951: for (var i=0; i<baltotal; i++) {
14952: if (i != balnum) {
14953: for (var j=0; j<offloadtypes.length; j++) {
14954: var total = alltargets.length - 1;
14955: for (var k=0; k<total; k++) {
14956: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14957: var server = serveritem.value;
14958: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14959: if (server == addtarget) {
14960: serveritem.disabled = '';
14961: }
14962: }
14963: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14964: if (server == removetarget) {
14965: serveritem.disabled = 'disabled';
14966: serveritem.checked = false;
14967: }
14968: }
14969: }
14970: }
14971: for (var j=0; j<insttypes.length; j++) {
14972: if (insttypes[j] != '_LC_external') {
14973: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14974: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14975: var currSel = singleserver.selectedIndex;
14976: var currVal = singleserver.options[currSel].value;
14977: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14978: var numoptions = singleserver.options.length;
14979: var needsnew = 1;
14980: for (var k=0; k<numoptions; k++) {
14981: if (singleserver.options[k] == addtarget) {
14982: needsnew = 0;
14983: break;
14984: }
14985: }
14986: if (needsnew == 1) {
14987: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14988: }
14989: }
14990: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14991: singleserver.options.length = 0;
14992: if ((currVal) && (currVal != removetarget)) {
14993: singleserver.options[0] = new Option("","",false,false);
14994: } else {
14995: singleserver.options[0] = new Option("","",true,true);
14996: }
14997: var idx = 0;
14998: for (var m=0; m<alltargets.length; m++) {
14999: if (currBalancers.indexOf(alltargets[m]) == -1) {
15000: idx ++;
15001: if (currVal == alltargets[m]) {
15002: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
15003: } else {
15004: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
15005: }
15006: }
15007: }
15008: }
15009: }
15010: }
15011: }
1.150 raeburn 15012: }
15013: }
15014: }
15015: return;
15016: }
15017:
1.152 raeburn 15018: // ]]>
15019: </script>
15020:
15021: END
15022: }
15023:
15024: sub new_spares_js {
15025: my @sparestypes = ('primary','default');
15026: my $types = join("','",@sparestypes);
15027: my $select = &mt('Select');
15028: return <<"END";
15029:
15030: <script type="text/javascript">
15031: // <![CDATA[
15032:
15033: function updateNewSpares(formname,lonhost) {
15034: var types = new Array('$types');
15035: var include = new Array();
15036: var exclude = new Array();
15037: for (var i=0; i<types.length; i++) {
15038: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
15039: for (var j=0; j<spareboxes.length; j++) {
15040: if (formname.elements[spareboxes[j]].checked) {
15041: exclude.push(formname.elements[spareboxes[j]].value);
15042: } else {
15043: include.push(formname.elements[spareboxes[j]].value);
15044: }
15045: }
15046: }
15047: for (var i=0; i<types.length; i++) {
15048: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
15049: var selIdx = newSpare.selectedIndex;
15050: var currnew = newSpare.options[selIdx].value;
15051: var okSpares = new Array();
15052: for (var j=0; j<newSpare.options.length; j++) {
15053: var possible = newSpare.options[j].value;
15054: if (possible != '') {
15055: if (exclude.indexOf(possible) == -1) {
15056: okSpares.push(possible);
15057: } else {
15058: if (currnew == possible) {
15059: selIdx = 0;
15060: }
15061: }
15062: }
15063: }
15064: for (var k=0; k<include.length; k++) {
15065: if (okSpares.indexOf(include[k]) == -1) {
15066: okSpares.push(include[k]);
15067: }
15068: }
15069: okSpares.sort();
15070: newSpare.options.length = 0;
15071: if (selIdx == 0) {
15072: newSpare.options[0] = new Option("$select","",true,true);
15073: } else {
15074: newSpare.options[0] = new Option("$select","",false,false);
15075: }
15076: for (var m=0; m<okSpares.length; m++) {
15077: var idx = m+1;
15078: var selThis = 0;
15079: if (selIdx != 0) {
15080: if (okSpares[m] == currnew) {
15081: selThis = 1;
15082: }
15083: }
15084: if (selThis == 1) {
15085: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
15086: } else {
15087: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15088: }
15089: }
15090: }
15091: return;
15092: }
15093:
15094: function checkNewSpares(lonhost,type) {
15095: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15096: var chosen = newSpare.options[newSpare.selectedIndex].value;
15097: if (chosen != '') {
15098: var othertype;
15099: var othernewSpare;
15100: if (type == 'primary') {
15101: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15102: }
15103: if (type == 'default') {
15104: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15105: }
15106: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15107: othernewSpare.selectedIndex = 0;
15108: }
15109: }
15110: return;
15111: }
15112:
15113: // ]]>
15114: </script>
15115:
15116: END
15117:
15118: }
15119:
15120: sub common_domprefs_js {
15121: return <<"END";
15122:
15123: <script type="text/javascript">
15124: // <![CDATA[
15125:
1.150 raeburn 15126: function getIndicesByName(formname,item) {
1.152 raeburn 15127: var group = new Array();
1.150 raeburn 15128: for (var i=0;i<formname.elements.length;i++) {
15129: if (formname.elements[i].name == item) {
1.152 raeburn 15130: group.push(formname.elements[i].id);
1.150 raeburn 15131: }
15132: }
1.152 raeburn 15133: return group;
1.150 raeburn 15134: }
15135:
15136: // ]]>
15137: </script>
15138:
15139: END
1.152 raeburn 15140:
1.150 raeburn 15141: }
15142:
1.165 raeburn 15143: sub recaptcha_js {
15144: my %lt = &captcha_phrases();
15145: return <<"END";
15146:
15147: <script type="text/javascript">
15148: // <![CDATA[
15149:
15150: function updateCaptcha(caller,context) {
15151: var privitem;
15152: var pubitem;
15153: var privtext;
15154: var pubtext;
1.269 raeburn 15155: var versionitem;
15156: var versiontext;
1.165 raeburn 15157: if (document.getElementById(context+'_recaptchapub')) {
15158: pubitem = document.getElementById(context+'_recaptchapub');
15159: } else {
15160: return;
15161: }
15162: if (document.getElementById(context+'_recaptchapriv')) {
15163: privitem = document.getElementById(context+'_recaptchapriv');
15164: } else {
15165: return;
15166: }
15167: if (document.getElementById(context+'_recaptchapubtxt')) {
15168: pubtext = document.getElementById(context+'_recaptchapubtxt');
15169: } else {
15170: return;
15171: }
15172: if (document.getElementById(context+'_recaptchaprivtxt')) {
15173: privtext = document.getElementById(context+'_recaptchaprivtxt');
15174: } else {
15175: return;
15176: }
1.269 raeburn 15177: if (document.getElementById(context+'_recaptchaversion')) {
15178: versionitem = document.getElementById(context+'_recaptchaversion');
15179: } else {
15180: return;
15181: }
15182: if (document.getElementById(context+'_recaptchavertxt')) {
15183: versiontext = document.getElementById(context+'_recaptchavertxt');
15184: } else {
15185: return;
15186: }
1.165 raeburn 15187: if (caller.checked) {
15188: if (caller.value == 'recaptcha') {
15189: pubitem.type = 'text';
15190: privitem.type = 'text';
15191: pubitem.size = '40';
15192: privitem.size = '40';
15193: pubtext.innerHTML = "$lt{'pub'}";
15194: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 15195: versionitem.type = 'text';
15196: versionitem.size = '3';
1.289 raeburn 15197: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 15198: } else {
15199: pubitem.type = 'hidden';
15200: privitem.type = 'hidden';
1.269 raeburn 15201: versionitem.type = 'hidden';
1.165 raeburn 15202: pubtext.innerHTML = '';
15203: privtext.innerHTML = '';
1.269 raeburn 15204: versiontext.innerHTML = '';
1.165 raeburn 15205: }
15206: }
15207: return;
15208: }
15209:
15210: // ]]>
15211: </script>
15212:
15213: END
15214:
15215: }
15216:
1.236 raeburn 15217: sub toggle_display_js {
1.192 raeburn 15218: return <<"END";
15219:
15220: <script type="text/javascript">
15221: // <![CDATA[
15222:
1.236 raeburn 15223: function toggleDisplay(domForm,caller) {
15224: if (document.getElementById(caller)) {
15225: var divitem = document.getElementById(caller);
15226: var optionsElement = domForm.coursecredits;
1.264 raeburn 15227: var checkval = 1;
15228: var dispval = 'block';
1.236 raeburn 15229: if (caller == 'emailoptions') {
15230: optionsElement = domForm.cancreate_email;
15231: }
1.257 raeburn 15232: if (caller == 'studentsubmission') {
15233: optionsElement = domForm.postsubmit;
15234: }
1.264 raeburn 15235: if (caller == 'cloneinstcode') {
15236: optionsElement = domForm.canclone;
15237: checkval = 'instcode';
15238: }
1.236 raeburn 15239: if (optionsElement.length) {
1.192 raeburn 15240: var currval;
1.236 raeburn 15241: for (var i=0; i<optionsElement.length; i++) {
15242: if (optionsElement[i].checked) {
15243: currval = optionsElement[i].value;
1.192 raeburn 15244: }
15245: }
1.264 raeburn 15246: if (currval == checkval) {
15247: divitem.style.display = dispval;
1.192 raeburn 15248: } else {
1.236 raeburn 15249: divitem.style.display = 'none';
1.192 raeburn 15250: }
15251: }
15252: }
15253: return;
15254: }
15255:
15256: // ]]>
15257: </script>
15258:
15259: END
15260:
15261: }
15262:
1.165 raeburn 15263: sub captcha_phrases {
15264: return &Apache::lonlocal::texthash (
15265: priv => 'Private key',
15266: pub => 'Public key',
15267: original => 'original (CAPTCHA)',
15268: recaptcha => 'successor (ReCAPTCHA)',
15269: notused => 'unused',
1.289 raeburn 15270: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 15271: );
15272: }
15273:
1.205 raeburn 15274: sub devalidate_remote_domconfs {
1.212 raeburn 15275: my ($dom,$cachekeys) = @_;
15276: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 15277: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15278: my %thismachine;
15279: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 15280: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 15281: if (keys(%servers)) {
1.205 raeburn 15282: foreach my $server (keys(%servers)) {
15283: next if ($thismachine{$server});
1.212 raeburn 15284: my @cached;
15285: foreach my $name (@posscached) {
15286: if ($cachekeys->{$name}) {
15287: push(@cached,&escape($name).':'.&escape($dom));
15288: }
15289: }
15290: if (@cached) {
15291: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15292: }
1.205 raeburn 15293: }
15294: }
15295: return;
15296: }
15297:
1.3 raeburn 15298: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>