Annotation of loncom/interface/domainprefs.pm, revision 1.303
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.303 ! raeburn 4: # $Id: domainprefs.pm,v 1.302 2017/07/18 16:03:08 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.271 raeburn 107: (official, unofficial, community, textbook, and placement).
108: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.1 raeburn 179:
1.155 raeburn 180: my $registered_cleanup;
181: my $modified_urls;
182:
1.1 raeburn 183: sub handler {
184: my $r=shift;
185: if ($r->header_only) {
186: &Apache::loncommon::content_type($r,'text/html');
187: $r->send_http_header;
188: return OK;
189: }
190:
1.91 raeburn 191: my $context = 'domain';
1.1 raeburn 192: my $dom = $env{'request.role.domain'};
1.5 albertel 193: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 194: if (&Apache::lonnet::allowed('mau',$dom)) {
195: &Apache::loncommon::content_type($r,'text/html');
196: $r->send_http_header;
197: } else {
198: $env{'user.error.msg'}=
199: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
200: return HTTP_NOT_ACCEPTABLE;
201: }
1.155 raeburn 202:
203: $registered_cleanup=0;
204: @{$modified_urls}=();
205:
1.1 raeburn 206: &Apache::lonhtmlcommon::clear_breadcrumbs();
207: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 208: ['phase','actions']);
1.30 raeburn 209: my $phase = 'pickactions';
1.3 raeburn 210: if ( exists($env{'form.phase'}) ) {
211: $phase = $env{'form.phase'};
212: }
1.150 raeburn 213: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 214: my %domconfig =
1.6 raeburn 215: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 216: 'quotas','autoenroll','autoupdate','autocreate',
217: 'directorysrch','usercreation','usermodification',
218: 'contacts','defaults','scantron','coursecategories',
219: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 220: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 221: 'requestauthor','selfenrollment','inststatus',
1.279 raeburn 222: 'ltitools','ssl','trust'],$dom);
1.297 raeburn 223: if (ref($domconfig{'ltitools'}) eq 'HASH') {
224: my %encconfig =
225: &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom);
226: if (ref($encconfig{'ltitools'}) eq 'HASH') {
227: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
228: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
229: foreach my $item ('key','secret') {
230: $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
231: }
232: }
233: }
234: }
235: }
1.43 raeburn 236: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 237: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 238: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 239: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 240: 'serverstatuses','helpsettings','coursedefaults',
1.279 raeburn 241: 'ltitools','selfenrollment','usersessions','ssl','trust');
1.171 raeburn 242: my %existing;
243: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
244: %existing = %{$domconfig{'loadbalancing'}};
245: }
246: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 247: push(@prefs_order,'loadbalancing');
248: }
1.30 raeburn 249: my %prefs = (
250: 'rolecolors' =>
251: { text => 'Default color schemes',
1.67 raeburn 252: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 253: header => [{col1 => 'Student Settings',
254: col2 => '',},
255: {col1 => 'Coordinator Settings',
256: col2 => '',},
257: {col1 => 'Author Settings',
258: col2 => '',},
259: {col1 => 'Administrator Settings',
260: col2 => '',}],
1.230 raeburn 261: print => \&print_rolecolors,
262: modify => \&modify_rolecolors,
1.30 raeburn 263: },
1.110 raeburn 264: 'login' =>
1.30 raeburn 265: { text => 'Log-in page options',
1.67 raeburn 266: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 267: header => [{col1 => 'Log-in Page Items',
268: col2 => '',},
269: {col1 => 'Log-in Help',
1.256 raeburn 270: col2 => 'Value'},
271: {col1 => 'Custom HTML in document head',
1.168 raeburn 272: col2 => 'Value'}],
1.230 raeburn 273: print => \&print_login,
274: modify => \&modify_login,
1.30 raeburn 275: },
1.43 raeburn 276: 'defaults' =>
1.236 raeburn 277: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 278: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 279: header => [{col1 => 'Setting',
1.236 raeburn 280: col2 => 'Value'},
1.294 raeburn 281: {col1 => 'Internal Authentication',
282: col2 => 'Value'},
1.236 raeburn 283: {col1 => 'Institutional user types',
1.303 ! raeburn 284: col2 => 'Assignable to non-institutional users'}],
1.230 raeburn 285: print => \&print_defaults,
286: modify => \&modify_defaults,
1.43 raeburn 287: },
1.30 raeburn 288: 'quotas' =>
1.197 raeburn 289: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 290: help => 'Domain_Configuration_Quotas',
1.77 raeburn 291: header => [{col1 => 'User affiliation',
1.72 raeburn 292: col2 => 'Available tools',
1.213 raeburn 293: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 294: print => \&print_quotas,
295: modify => \&modify_quotas,
1.30 raeburn 296: },
297: 'autoenroll' =>
298: { text => 'Auto-enrollment settings',
1.67 raeburn 299: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 300: header => [{col1 => 'Configuration setting',
301: col2 => 'Value(s)'}],
1.230 raeburn 302: print => \&print_autoenroll,
303: modify => \&modify_autoenroll,
1.30 raeburn 304: },
305: 'autoupdate' =>
306: { text => 'Auto-update settings',
1.67 raeburn 307: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 308: header => [{col1 => 'Setting',
309: col2 => 'Value',},
1.131 raeburn 310: {col1 => 'Setting',
311: col2 => 'Affiliation'},
1.43 raeburn 312: {col1 => 'User population',
1.227 bisitz 313: col2 => 'Updatable user data'}],
1.230 raeburn 314: print => \&print_autoupdate,
315: modify => \&modify_autoupdate,
1.30 raeburn 316: },
1.125 raeburn 317: 'autocreate' =>
318: { text => 'Auto-course creation settings',
319: help => 'Domain_Configuration_Auto_Creation',
320: header => [{col1 => 'Configuration Setting',
321: col2 => 'Value',}],
1.230 raeburn 322: print => \&print_autocreate,
323: modify => \&modify_autocreate,
1.125 raeburn 324: },
1.30 raeburn 325: 'directorysrch' =>
1.277 raeburn 326: { text => 'Directory searches',
1.67 raeburn 327: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 328: header => [{col1 => 'Institutional Directory Setting',
329: col2 => 'Value',},
330: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 331: col2 => 'Value',}],
1.230 raeburn 332: print => \&print_directorysrch,
333: modify => \&modify_directorysrch,
1.30 raeburn 334: },
335: 'contacts' =>
1.286 raeburn 336: { text => 'E-mail addresses and helpform',
1.67 raeburn 337: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 338: header => [{col1 => 'Default e-mail addresses',
339: col2 => 'Value',},
340: {col1 => 'Recipient(s) for notifications',
341: col2 => 'Value',},
342: {col1 => 'Ask helpdesk form settings',
343: col2 => 'Value',},],
1.230 raeburn 344: print => \&print_contacts,
345: modify => \&modify_contacts,
1.30 raeburn 346: },
347: 'usercreation' =>
348: { text => 'User creation',
1.67 raeburn 349: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 350: header => [{col1 => 'Format rule type',
351: col2 => 'Format rules in force'},
1.34 raeburn 352: {col1 => 'User account creation',
353: col2 => 'Usernames which may be created',},
1.30 raeburn 354: {col1 => 'Context',
1.43 raeburn 355: col2 => 'Assignable authentication types'}],
1.230 raeburn 356: print => \&print_usercreation,
357: modify => \&modify_usercreation,
1.30 raeburn 358: },
1.224 raeburn 359: 'selfcreation' =>
360: { text => 'Users self-creating accounts',
361: help => 'Domain_Configuration_Self_Creation',
362: header => [{col1 => 'Self-creation with institutional username',
363: col2 => 'Enabled?'},
364: {col1 => 'Institutional user type (login/SSO self-creation)',
365: col2 => 'Information user can enter'},
1.303 ! raeburn 366: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 367: col2 => 'Settings'}],
1.230 raeburn 368: print => \&print_selfcreation,
369: modify => \&modify_selfcreation,
1.224 raeburn 370: },
1.69 raeburn 371: 'usermodification' =>
1.33 raeburn 372: { text => 'User modification',
1.67 raeburn 373: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 374: header => [{col1 => 'Target user has role',
1.227 bisitz 375: col2 => 'User information updatable in author context'},
1.33 raeburn 376: {col1 => 'Target user has role',
1.227 bisitz 377: col2 => 'User information updatable in course context'}],
1.230 raeburn 378: print => \&print_usermodification,
379: modify => \&modify_usermodification,
1.33 raeburn 380: },
1.69 raeburn 381: 'scantron' =>
1.95 www 382: { text => 'Bubblesheet format file',
1.67 raeburn 383: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 384: header => [ {col1 => 'Item',
385: col2 => '',
386: }],
1.230 raeburn 387: print => \&print_scantron,
388: modify => \&modify_scantron,
1.46 raeburn 389: },
1.86 raeburn 390: 'requestcourses' =>
391: {text => 'Request creation of courses',
392: help => 'Domain_Configuration_Request_Courses',
393: header => [{col1 => 'User affiliation',
1.102 raeburn 394: col2 => 'Availability/Processing of requests',},
395: {col1 => 'Setting',
1.216 raeburn 396: col2 => 'Value'},
397: {col1 => 'Available textbooks',
1.235 raeburn 398: col2 => ''},
1.242 raeburn 399: {col1 => 'Available templates',
400: col2 => ''},
1.235 raeburn 401: {col1 => 'Validation (not official courses)',
402: col2 => 'Value'},],
1.230 raeburn 403: print => \&print_quotas,
404: modify => \&modify_quotas,
1.86 raeburn 405: },
1.163 raeburn 406: 'requestauthor' =>
1.223 bisitz 407: {text => 'Request Authoring Space',
1.163 raeburn 408: help => 'Domain_Configuration_Request_Author',
409: header => [{col1 => 'User affiliation',
410: col2 => 'Availability/Processing of requests',},
411: {col1 => 'Setting',
412: col2 => 'Value'}],
1.230 raeburn 413: print => \&print_quotas,
414: modify => \&modify_quotas,
1.163 raeburn 415: },
1.69 raeburn 416: 'coursecategories' =>
1.120 raeburn 417: { text => 'Cataloging of courses/communities',
1.67 raeburn 418: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 419: header => [{col1 => 'Catalog type/availability',
420: col2 => '',},
421: {col1 => 'Category settings for standard catalog',
1.57 raeburn 422: col2 => '',},
423: {col1 => 'Categories',
424: col2 => '',
425: }],
1.230 raeburn 426: print => \&print_coursecategories,
427: modify => \&modify_coursecategories,
1.69 raeburn 428: },
429: 'serverstatuses' =>
1.77 raeburn 430: {text => 'Access to server status pages',
1.69 raeburn 431: help => 'Domain_Configuration_Server_Status',
432: header => [{col1 => 'Status Page',
433: col2 => 'Other named users',
434: col3 => 'Specific IPs',
435: }],
1.230 raeburn 436: print => \&print_serverstatuses,
437: modify => \&modify_serverstatuses,
1.69 raeburn 438: },
1.118 jms 439: 'helpsettings' =>
1.282 raeburn 440: {text => 'Support settings',
1.118 jms 441: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 442: header => [{col1 => 'Help Page Settings (logged-in users)',
443: col2 => 'Value'},
444: {col1 => 'Helpdesk Roles',
445: col2 => 'Settings'},],
1.230 raeburn 446: print => \&print_helpsettings,
447: modify => \&modify_helpsettings,
1.118 jms 448: },
1.121 raeburn 449: 'coursedefaults' =>
450: {text => 'Course/Community defaults',
451: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 452: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
453: col2 => 'Value',},
454: {col1 => 'Defaults which can be overridden for each course by a DC',
455: col2 => 'Value',},],
1.230 raeburn 456: print => \&print_coursedefaults,
457: modify => \&modify_coursedefaults,
1.121 raeburn 458: },
1.231 raeburn 459: 'selfenrollment' =>
460: {text => 'Self-enrollment in Course/Community',
461: help => 'Domain_Configuration_Selfenrollment',
462: header => [{col1 => 'Configuration Rights',
463: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
464: {col1 => 'Defaults',
465: col2 => 'Value'},
466: {col1 => 'Self-enrollment validation (optional)',
467: col2 => 'Value'},],
468: print => \&print_selfenrollment,
469: modify => \&modify_selfenrollment,
470: },
1.120 raeburn 471: 'privacy' =>
472: {text => 'User Privacy',
473: help => 'Domain_Configuration_User_Privacy',
474: header => [{col1 => 'Setting',
475: col2 => 'Value',}],
1.230 raeburn 476: print => \&print_privacy,
477: modify => \&modify_privacy,
1.120 raeburn 478: },
1.141 raeburn 479: 'usersessions' =>
1.145 raeburn 480: {text => 'User session hosting/offloading',
1.137 raeburn 481: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 482: header => [{col1 => 'Domain server',
483: col2 => 'Servers to offload sessions to when busy'},
484: {col1 => 'Hosting of users from other domains',
1.137 raeburn 485: col2 => 'Rules'},
486: {col1 => "Hosting domain's own users elsewhere",
487: col2 => 'Rules'}],
1.230 raeburn 488: print => \&print_usersessions,
489: modify => \&modify_usersessions,
1.137 raeburn 490: },
1.279 raeburn 491: 'loadbalancing' =>
1.185 raeburn 492: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 493: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 494: header => [{col1 => 'Balancers',
1.150 raeburn 495: col2 => 'Default destinations',
1.183 bisitz 496: col3 => 'User affiliation',
1.150 raeburn 497: col4 => 'Overrides'},
498: ],
1.230 raeburn 499: print => \&print_loadbalancing,
500: modify => \&modify_loadbalancing,
1.150 raeburn 501: },
1.279 raeburn 502: 'ltitools' =>
1.267 raeburn 503: {text => 'External Tools (LTI)',
1.296 raeburn 504: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 505: header => [{col1 => 'Setting',
506: col2 => 'Value',}],
507: print => \&print_ltitools,
508: modify => \&modify_ltitools,
509: },
1.279 raeburn 510: 'ssl' =>
1.275 raeburn 511: {text => 'LON-CAPA Network (SSL)',
512: help => 'Domain_Configuration_Network_SSL',
513: header => [{col1 => 'Server',
514: col2 => 'Certificate Status'},
515: {col1 => 'Connections to other servers',
516: col2 => 'Rules'},
1.293 raeburn 517: {col1 => 'Connections from other servers',
518: col2 => 'Rules'},
1.275 raeburn 519: {col1 => "Replicating domain's published content",
520: col2 => 'Rules'}],
521: print => \&print_ssl,
522: modify => \&modify_ssl,
523: },
1.279 raeburn 524: 'trust' =>
525: {text => 'Trust Settings',
526: help => 'Domain_Configuration_Trust',
527: header => [{col1 => "Access to this domain's content by others",
528: col2 => 'Rules'},
529: {col1 => "Access to other domain's content by this domain",
530: col2 => 'Rules'},
531: {col1 => "Enrollment in this domain's courses by others",
532: col2 => 'Rules',},
533: {col1 => "Co-author roles in this domain for others",
534: col2 => 'Rules',},
535: {col1 => "Co-author roles for this domain's users elsewhere",
536: col2 => 'Rules',},
537: {col1 => "Domain roles in this domain assignable to others",
538: col2 => 'Rules'},
539: {col1 => "Course catalog for this domain displayed elsewhere",
540: col2 => 'Rules'},
541: {col1 => "Requests for creation of courses in this domain by others",
542: col2 => 'Rules'},
543: {col1 => "Users in other domains can send messages to this domain",
544: col2 => 'Rules'},],
545: print => \&print_trust,
546: modify => \&modify_trust,
547: },
1.3 raeburn 548: );
1.110 raeburn 549: if (keys(%servers) > 1) {
550: $prefs{'login'} = { text => 'Log-in page options',
551: help => 'Domain_Configuration_Login_Page',
552: header => [{col1 => 'Log-in Service',
553: col2 => 'Server Setting',},
554: {col1 => 'Log-in Page Items',
1.168 raeburn 555: col2 => ''},
556: {col1 => 'Log-in Help',
1.256 raeburn 557: col2 => 'Value'},
558: {col1 => 'Custom HTML in document head',
1.168 raeburn 559: col2 => 'Value'}],
1.230 raeburn 560: print => \&print_login,
561: modify => \&modify_login,
1.110 raeburn 562: };
563: }
1.174 foxr 564:
1.6 raeburn 565: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 566: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 567: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 568: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 569: text=>"Settings to display/modify"});
1.9 raeburn 570: my $confname = $dom.'-domainconfig';
1.174 foxr 571:
1.3 raeburn 572: if ($phase eq 'process') {
1.212 raeburn 573: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
574: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 575: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 576: $r->rflush();
1.212 raeburn 577: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 578: }
1.30 raeburn 579: } elsif ($phase eq 'display') {
1.192 raeburn 580: my $js = &recaptcha_js().
1.236 raeburn 581: &toggle_display_js();
1.171 raeburn 582: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 583: my ($othertitle,$usertypes,$types) =
584: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 585: $js .= &lonbalance_targets_js($dom,$types,\%servers,
586: $domconfig{'loadbalancing'}).
1.170 raeburn 587: &new_spares_js().
588: &common_domprefs_js().
589: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 590: }
1.216 raeburn 591: if (grep(/^requestcourses$/,@actions)) {
592: my $javascript_validations;
593: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
594: $js .= <<END;
595: <script type="text/javascript">
596: $javascript_validations
597: </script>
598: $coursebrowserjs
599: END
600: }
1.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);
1.301 raeburn 3264: if (ref($settings) eq 'HASH') {
3265: if (ref($settings->{'adhoc'}) eq 'HASH') {
3266: %current = %{$settings->{'adhoc'}};
3267: }
1.285 raeburn 3268: }
3269: my $count = 0;
3270: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3271: if ($key=~/^rolesdef\_(\w+)$/) {
3272: my $rolename = $1;
1.285 raeburn 3273: my (%privs,$order);
1.282 raeburn 3274: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3275: $customroles{$rolename} = \%privs;
1.285 raeburn 3276: if (ref($current{$rolename}) eq 'HASH') {
3277: $order = $current{$rolename}{'order'};
3278: }
3279: if ($order eq '') {
3280: $order = $count;
3281: }
3282: $ordered{$order} = $rolename;
3283: $count++;
3284: }
3285: }
3286: my $maxnum = scalar(keys(%ordered));
3287: my @roles_by_num = ();
3288: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3289: push(@roles_by_num,$item);
3290: }
3291: my $context = 'domprefs';
3292: my $crstype = 'Course';
3293: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3294: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3295: my ($numstatustypes,@jsarray);
3296: if (ref($types) eq 'ARRAY') {
3297: if (@{$types} > 0) {
3298: $numstatustypes = scalar(@{$types});
3299: push(@accesstypes,'status');
3300: @jsarray = ('bystatus');
1.282 raeburn 3301: }
3302: }
1.290 raeburn 3303: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3304: if (keys(%domhelpdesk)) {
3305: push(@accesstypes,('inc','exc'));
3306: push(@jsarray,('notinc','notexc'));
3307: }
3308: my $hiddenstr = join("','",@jsarray);
3309: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3310: my $context = 'domprefs';
3311: my $crstype = 'Course';
1.285 raeburn 3312: my $prefix = 'helproles_';
3313: my $add_class = 'LC_hidden';
3314: foreach my $num (@roles_by_num) {
3315: my $role = $ordered{$num};
3316: my ($desc,$access,@statuses);
3317: if (ref($current{$role}) eq 'HASH') {
3318: $desc = $current{$role}{'desc'};
3319: $access = $current{$role}{'access'};
3320: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3321: @statuses = @{$current{$role}{'insttypes'}};
3322: }
3323: }
3324: if ($desc eq '') {
3325: $desc = $role;
3326: }
3327: my $identifier = 'custhelp'.$num;
1.282 raeburn 3328: my %full=();
3329: my %levels= (
3330: course => {},
3331: domain => {},
3332: system => {},
3333: );
3334: my %levelscurrent=(
3335: course => {},
3336: domain => {},
3337: system => {},
3338: );
3339: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3340: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3341: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3342: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3343: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3344: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3345: for (my $k=0; $k<=$maxnum; $k++) {
3346: my $vpos = $k+1;
3347: my $selstr;
3348: if ($k == $num) {
3349: $selstr = ' selected="selected" ';
3350: }
3351: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3352: }
3353: $datatable .= '</select>'.(' 'x2).
3354: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3355: '</td>'.
3356: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3357: &mt('Name shown to users:').
3358: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3359: '</fieldset>'.
3360: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3361: $othertitle,$usertypes,$types,\%domhelpdesk).
3362: '<fieldset>'.
3363: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3364: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3365: \%levelscurrent,$identifier,
3366: 'LC_hidden',$prefix.$num.'_privs').
3367: '</fieldset></td>';
1.282 raeburn 3368: $itemcount ++;
3369: }
3370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3371: my $newcust = 'custhelp'.$count;
3372: my (%privs,%levelscurrent);
3373: my %full=();
3374: my %levels= (
3375: course => {},
3376: domain => {},
3377: system => {},
3378: );
3379: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3380: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3381: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3382: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3383: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3384: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3385: for (my $k=0; $k<$maxnum+1; $k++) {
3386: my $vpos = $k+1;
3387: my $selstr;
3388: if ($k == $maxnum) {
3389: $selstr = ' selected="selected" ';
3390: }
3391: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3392: }
3393: $datatable .= '</select> '."\n".
1.282 raeburn 3394: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3395: '</label></span></td>'.
1.285 raeburn 3396: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3397: '<span class="LC_nobreak">'.
3398: &mt('Internal name:').
3399: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3400: '</span>'.(' 'x4).
3401: '<span class="LC_nobreak">'.
3402: &mt('Name shown to users:').
3403: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3404: '</span></fieldset>'.
3405: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3406: $usertypes,$types,\%domhelpdesk).
3407: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3408: &Apache::lonuserutils::custom_role_header($context,$crstype,
3409: \@templateroles,$newcust).
3410: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3411: \%levelscurrent,$newcust).
1.285 raeburn 3412: '</fieldset></td></tr>';
1.282 raeburn 3413: $count ++;
3414: $$rowtotal += $count;
3415: }
1.166 raeburn 3416: return $datatable;
1.121 raeburn 3417: }
3418:
1.285 raeburn 3419: sub adhocbutton {
3420: my ($prefix,$num,$field,$visibility) = @_;
3421: my %lt = &Apache::lonlocal::texthash(
3422: show => 'Show details',
3423: hide => 'Hide details',
3424: );
3425: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3426: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3427: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3428: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3429: }
3430:
3431: sub helpsettings_javascript {
3432: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3433: return unless(ref($roles_by_num) eq 'ARRAY');
3434: my %html_js_lt = &Apache::lonlocal::texthash(
3435: show => 'Show details',
3436: hide => 'Hide details',
3437: );
3438: &html_escape(\%html_js_lt);
3439: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3440: return <<"ENDSCRIPT";
3441: <script type="text/javascript">
3442: // <![CDATA[
3443:
3444: function reorderHelpRoles(form,item) {
3445: var changedVal;
3446: $jstext
3447: var newpos = 'helproles_${total}_pos';
3448: var maxh = 1 + $total;
3449: var current = new Array();
3450: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3451: if (item == newpos) {
3452: changedVal = newitemVal;
3453: } else {
3454: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3455: current[newitemVal] = newpos;
3456: }
3457: for (var i=0; i<helproles.length; i++) {
3458: var elementName = 'helproles_'+helproles[i]+'_pos';
3459: if (elementName != item) {
3460: if (form.elements[elementName]) {
3461: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3462: current[currVal] = elementName;
3463: }
3464: }
3465: }
3466: var oldVal;
3467: for (var j=0; j<maxh; j++) {
3468: if (current[j] == undefined) {
3469: oldVal = j;
3470: }
3471: }
3472: if (oldVal < changedVal) {
3473: for (var k=oldVal+1; k<=changedVal ; k++) {
3474: var elementName = current[k];
3475: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3476: }
3477: } else {
3478: for (var k=changedVal; k<oldVal; k++) {
3479: var elementName = current[k];
3480: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3481: }
3482: }
3483: return;
3484: }
3485:
3486: function helpdeskAccess(num) {
3487: var curraccess = null;
3488: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3489: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3490: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3491: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3492: }
3493: }
3494: }
3495: var shown = Array();
3496: var hidden = Array();
3497: if (curraccess == 'none') {
3498: hidden = Array('$hiddenstr');
3499: } else {
3500: if (curraccess == 'status') {
3501: shown = Array('bystatus');
3502: hidden = Array('notinc','notexc');
3503: } else {
3504: if (curraccess == 'exc') {
3505: shown = Array('notexc');
3506: hidden = Array('notinc','bystatus');
3507: }
3508: if (curraccess == 'inc') {
3509: shown = Array('notinc');
3510: hidden = Array('notexc','bystatus');
3511: }
1.293 raeburn 3512: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3513: hidden = Array('notinc','notexc','bystatus');
3514: }
3515: }
3516: }
3517: if (hidden.length > 0) {
3518: for (var i=0; i<hidden.length; i++) {
3519: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3520: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3521: }
3522: }
3523: }
3524: if (shown.length > 0) {
3525: for (var i=0; i<shown.length; i++) {
3526: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3527: if (shown[i] == 'privs') {
3528: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3529: } else {
3530: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3531: }
3532: }
3533: }
3534: }
3535: return;
3536: }
3537:
3538: function toggleHelpdeskItem(num,field) {
3539: if (document.getElementById('helproles_'+num+'_'+field)) {
3540: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 3541: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 3542: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3543: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3544: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3545: }
3546: } else {
3547: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3548: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3549: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3550: }
3551: }
3552: }
3553: return;
3554: }
3555:
3556: // ]]>
3557: </script>
3558:
3559: ENDSCRIPT
3560: }
3561:
3562: sub helpdeskroles_access {
3563: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3564: $usertypes,$types,$domhelpdesk) = @_;
3565: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3566: my %lt = &Apache::lonlocal::texthash(
3567: 'rou' => 'Role usage',
3568: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 3569: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3570: 'dh' => 'All with domain helpdesk role',
3571: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 3572: 'none' => 'None',
3573: 'status' => 'Determined based on institutional status',
3574: 'inc' => 'Include all, but exclude specific personnel',
3575: 'exc' => 'Exclude all, but include specific personnel',
3576: );
3577: my %usecheck = (
3578: all => ' checked="checked"',
3579: );
3580: my %displaydiv = (
3581: status => 'none',
3582: inc => 'none',
3583: exc => 'none',
3584: priv => 'block',
3585: );
3586: my $output;
3587: if (ref($current) eq 'HASH') {
3588: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3589: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3590: $usecheck{$current->{access}} = $usecheck{'all'};
3591: delete($usecheck{'all'});
3592: if ($current->{access} =~ /^(status|inc|exc)$/) {
3593: my $access = $1;
3594: $displaydiv{$access} = 'inline';
3595: } elsif ($current->{access} eq 'none') {
3596: $displaydiv{'priv'} = 'none';
3597: }
3598: }
3599: }
3600: }
3601: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3602: '<p>'.$lt{'whi'}.'</p>';
3603: foreach my $access (@{$accesstypes}) {
3604: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3605: ' onclick="helpdeskAccess('."'$num'".');" />'.
3606: $lt{$access}.'</label>';
3607: if ($access eq 'status') {
3608: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3609: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3610: $othertitle,$usertypes,$types).
3611: '</div>';
3612: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3613: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3614: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3615: '</div>';
3616: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3617: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3618: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3619: '</div>';
3620: }
3621: $output .= '</p>';
3622: }
3623: $output .= '</fieldset>';
3624: return $output;
3625: }
3626:
1.121 raeburn 3627: sub radiobutton_prefs {
1.192 raeburn 3628: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 3629: $additional,$align) = @_;
1.121 raeburn 3630: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3631: (ref($choices) eq 'HASH'));
3632:
1.170 raeburn 3633: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 3634:
3635: foreach my $item (@{$toggles}) {
3636: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3637: $checkedon{$item} = ' checked="checked" ';
3638: $checkedoff{$item} = ' ';
1.121 raeburn 3639: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3640: $checkedoff{$item} = ' checked="checked" ';
3641: $checkedon{$item} = ' ';
3642: }
3643: }
3644: if (ref($settings) eq 'HASH') {
1.121 raeburn 3645: foreach my $item (@{$toggles}) {
1.118 jms 3646: if ($settings->{$item} eq '1') {
3647: $checkedon{$item} = ' checked="checked" ';
3648: $checkedoff{$item} = ' ';
3649: } elsif ($settings->{$item} eq '0') {
3650: $checkedoff{$item} = ' checked="checked" ';
3651: $checkedon{$item} = ' ';
3652: }
3653: }
1.121 raeburn 3654: }
1.192 raeburn 3655: if ($onclick) {
3656: $onclick = ' onclick="'.$onclick.'"';
3657: }
1.121 raeburn 3658: foreach my $item (@{$toggles}) {
1.118 jms 3659: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3660: $datatable .=
1.192 raeburn 3661: '<tr'.$css_class.'><td valign="top">'.
3662: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3663: '</span></td>';
3664: if ($align eq 'left') {
3665: $datatable .= '<td class="LC_left_item">';
3666: } else {
3667: $datatable .= '<td class="LC_right_item">';
3668: }
1.289 raeburn 3669: $datatable .=
1.257 raeburn 3670: '<span class="LC_nobreak">'.
1.118 jms 3671: '<label><input type="radio" name="'.
1.192 raeburn 3672: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3673: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3674: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3675: '</span>'.$additional.
3676: '</td>'.
1.118 jms 3677: '</tr>';
3678: $itemcount ++;
1.121 raeburn 3679: }
3680: return ($datatable,$itemcount);
3681: }
3682:
1.267 raeburn 3683: sub print_ltitools {
3684: my ($dom,$settings,$rowtotal) = @_;
3685: my $rownum = 0;
3686: my $css_class;
3687: my $itemcount = 1;
3688: my $maxnum = 0;
3689: my %ordered;
3690: if (ref($settings) eq 'HASH') {
3691: foreach my $item (keys(%{$settings})) {
3692: if (ref($settings->{$item}) eq 'HASH') {
3693: my $num = $settings->{$item}{'order'};
3694: $ordered{$num} = $item;
3695: }
3696: }
3697: }
3698: my $confname = $dom.'-domainconfig';
3699: my $switchserver = &check_switchserver($dom,$confname);
3700: my $maxnum = scalar(keys(%ordered));
3701: my $datatable = <itools_javascript($settings);
3702: my %lt = <itools_names();
3703: my @courseroles = ('cc','in','ta','ep','st');
3704: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3705: my @fields = ('fullname','firstname','lastname','email','user','roles');
3706: if (keys(%ordered)) {
3707: my @items = sort { $a <=> $b } keys(%ordered);
3708: for (my $i=0; $i<@items; $i++) {
3709: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3710: my $item = $ordered{$items[$i]};
3711: my ($title,$key,$secret,$url,$imgsrc,$version);
3712: if (ref($settings->{$item}) eq 'HASH') {
3713: $title = $settings->{$item}->{'title'};
3714: $url = $settings->{$item}->{'url'};
3715: $key = $settings->{$item}->{'key'};
3716: $secret = $settings->{$item}->{'secret'};
3717: my $image = $settings->{$item}->{'image'};
3718: if ($image ne '') {
3719: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3720: }
3721: }
3722: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3723: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3724: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3725: for (my $k=0; $k<=$maxnum; $k++) {
3726: my $vpos = $k+1;
3727: my $selstr;
3728: if ($k == $i) {
3729: $selstr = ' selected="selected" ';
3730: }
3731: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3732: }
3733: $datatable .= '</select>'.(' 'x2).
3734: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3735: &mt('Delete?').'</label></span></td>'.
3736: '<td colspan="2">'.
3737: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3738: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3739: (' 'x2).
3740: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3741: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3742: (' 'x2).
3743: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3744: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3745: '<br /><br />'.
3746: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3747: ' value="'.$url.'" /></span>'.
3748: (' 'x2).
3749: '<span class="LC_nobreak">'.$lt{'key'}.
3750: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3751: (' 'x2).
3752: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3753: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3754: '<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>'.
3755: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3756: '</fieldset>'.
3757: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3758: '<span class="LC_nobreak">'.&mt('Display target:');
3759: my %currdisp;
3760: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3761: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3762: $currdisp{'window'} = ' checked="checked"';
1.298 raeburn 3763: } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
3764: $currdisp{'tab'} = ' checked="checked"';
1.267 raeburn 3765: } else {
3766: $currdisp{'iframe'} = ' checked="checked"';
3767: }
3768: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3769: $currdisp{'width'} = $1;
3770: }
3771: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3772: $currdisp{'height'} = $1;
3773: }
1.296 raeburn 3774: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
3775: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 3776: } else {
3777: $currdisp{'iframe'} = ' checked="checked"';
3778: }
1.298 raeburn 3779: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 3780: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3781: $lt{$disp}.'</label>'.(' 'x2);
3782: }
3783: $datatable .= (' 'x4);
3784: foreach my $dimen ('width','height') {
3785: $datatable .= '<label>'.$lt{$dimen}.' '.
3786: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3787: (' 'x2);
3788: }
1.296 raeburn 3789: $datatable .= '<br />'.
3790: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3791: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
3792: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3793: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
3794: '</textarea></div><div style=""></div><br />';
1.267 raeburn 3795: $datatable .= '<br />';
3796: foreach my $extra ('passback','roster') {
3797: my $checkedon = '';
3798: my $checkedoff = ' checked="checked"';
3799: if ($settings->{$item}->{$extra}) {
3800: $checkedon = $checkedoff;
3801: $checkedoff = '';
3802: }
3803: $datatable .= $lt{$extra}.' '.
3804: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3805: &mt('Yes').'</label>'.(' 'x2).
3806: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3807: &mt('No').'</label>'.(' 'x4);
3808: }
3809: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3810: if ($imgsrc) {
3811: $datatable .= $imgsrc.
3812: '<label><input type="checkbox" name="ltitools_image_del"'.
3813: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3814: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3815: } else {
3816: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3817: }
3818: if ($switchserver) {
3819: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3820: } else {
3821: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3822: }
3823: $datatable .= '</span></fieldset>';
3824: my (%checkedfields,%rolemaps);
3825: if (ref($settings->{$item}) eq 'HASH') {
3826: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3827: %checkedfields = %{$settings->{$item}->{'fields'}};
3828: }
3829: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3830: %rolemaps = %{$settings->{$item}->{'roles'}};
3831: $checkedfields{'roles'} = 1;
3832: }
3833: }
3834: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3835: '<span class="LC_nobreak">';
3836: foreach my $field (@fields) {
3837: my $checked;
3838: if ($checkedfields{$field}) {
3839: $checked = ' checked="checked"';
3840: }
3841: $datatable .= '<label>'.
3842: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3843: $lt{$field}.'</label>'.(' ' x2);
3844: }
3845: $datatable .= '</span></fieldset>'.
3846: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3847: foreach my $role (@courseroles) {
3848: my ($selected,$selectnone);
3849: if (!$rolemaps{$role}) {
3850: $selectnone = ' selected="selected"';
3851: }
3852: $datatable .= '<td align="center">'.
3853: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3854: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3855: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3856: foreach my $ltirole (@ltiroles) {
3857: unless ($selectnone) {
3858: if ($rolemaps{$role} eq $ltirole) {
3859: $selected = ' selected="selected"';
3860: } else {
3861: $selected = '';
3862: }
3863: }
3864: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3865: }
3866: $datatable .= '</select></td>';
3867: }
1.273 raeburn 3868: $datatable .= '</tr></table></fieldset>';
3869: my %courseconfig;
3870: if (ref($settings->{$item}) eq 'HASH') {
3871: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3872: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3873: }
3874: }
3875: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 raeburn 3876: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 3877: my $checked;
3878: if ($courseconfig{$item}) {
3879: $checked = ' checked="checked"';
3880: }
3881: $datatable .= '<label>'.
3882: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3883: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3884: }
3885: $datatable .= '</span></fieldset>'.
1.267 raeburn 3886: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3887: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3888: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3889: my %custom = %{$settings->{$item}->{'custom'}};
3890: if (keys(%custom) > 0) {
3891: foreach my $key (sort(keys(%custom))) {
3892: $datatable .= '<tr><td><span class="LC_nobreak">'.
3893: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3894: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3895: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3896: ' value="'.$custom{$key}.'" /></td></tr>';
3897: }
3898: }
3899: }
3900: $datatable .= '<tr><td><span class="LC_nobreak">'.
3901: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3902: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3903: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3904: $datatable .= '</table></fieldset></td></tr>'."\n";
3905: $itemcount ++;
3906: }
3907: }
3908: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3909: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3910: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3911: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3912: '<select name="ltitools_add_pos"'.$chgstr.'>';
3913: for (my $k=0; $k<$maxnum+1; $k++) {
3914: my $vpos = $k+1;
3915: my $selstr;
3916: if ($k == $maxnum) {
3917: $selstr = ' selected="selected" ';
3918: }
3919: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3920: }
3921: $datatable .= '</select> '."\n".
3922: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3923: '<td colspan="2">'.
3924: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3925: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3926: (' 'x2).
3927: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3928: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3929: (' 'x2).
3930: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3931: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3932: '<br />'.
3933: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3934: (' 'x2).
3935: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3936: (' 'x2).
3937: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3938: '<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".
3939: '</fieldset>'.
3940: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3941: '<span class="LC_nobreak">'.&mt('Display target:');
3942: my %defaultdisp;
3943: $defaultdisp{'iframe'} = ' checked="checked"';
1.298 raeburn 3944: foreach my $disp ('iframe','tab','window') {
1.267 raeburn 3945: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3946: $lt{$disp}.'</label>'.(' 'x2);
3947: }
3948: $datatable .= (' 'x4);
3949: foreach my $dimen ('width','height') {
3950: $datatable .= '<label>'.$lt{$dimen}.' '.
3951: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3952: (' 'x2);
3953: }
1.296 raeburn 3954: $datatable .= '<br />'.
3955: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
3956: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
3957: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
3958: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
3959: '</div><div style=""></div><br />';
1.267 raeburn 3960: foreach my $extra ('passback','roster') {
3961: $datatable .= $lt{$extra}.' '.
3962: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3963: &mt('Yes').'</label>'.(' 'x2).
3964: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3965: &mt('No').'</label>'.(' 'x4);
3966: }
3967: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3968: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3969: if ($switchserver) {
3970: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3971: } else {
3972: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3973: }
3974: $datatable .= '</span></fieldset>'.
3975: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3976: '<span class="LC_nobreak">';
3977: foreach my $field (@fields) {
3978: $datatable .= '<label>'.
3979: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3980: $lt{$field}.'</label>'.(' ' x2);
3981: }
3982: $datatable .= '</span></fieldset>'.
3983: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3984: foreach my $role (@courseroles) {
3985: my ($checked,$checkednone);
3986: $datatable .= '<td align="center">'.
3987: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3988: '<select name="ltitools_add_roles_'.$role.'">'.
3989: '<option value="" selected="selected">'.&mt('Select').'</option>';
3990: foreach my $ltirole (@ltiroles) {
3991: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3992: }
3993: $datatable .= '</select></td>';
3994: }
3995: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3996: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 raeburn 3997: foreach my $item ('label','title','target','linktext','explanation') {
3998: $datatable .= '<label>'.
3999: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
4000: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 4001: }
4002: $datatable .= '</span></fieldset>'.
1.267 raeburn 4003: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
4004: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
4005: '<tr><td><span class="LC_nobreak">'.
4006: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
4007: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
4008: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
4009: '</table></fieldset></td></tr>'."\n".
4010: '</td>'."\n".
4011: '</tr>'."\n";
4012: $itemcount ++;
4013: return $datatable;
4014: }
4015:
4016: sub ltitools_names {
4017: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 4018: 'title' => 'Title',
4019: 'version' => 'Version',
4020: 'msgtype' => 'Message Type',
4021: 'url' => 'URL',
4022: 'key' => 'Key',
4023: 'secret' => 'Secret',
4024: 'icon' => 'Icon',
4025: 'user' => 'Username:domain',
4026: 'fullname' => 'Full Name',
4027: 'firstname' => 'First Name',
4028: 'lastname' => 'Last Name',
4029: 'email' => 'E-mail',
4030: 'roles' => 'Role',
1.298 raeburn 4031: 'window' => 'Window',
4032: 'tab' => 'Tab',
1.296 raeburn 4033: 'iframe' => 'iFrame',
4034: 'height' => 'Height',
4035: 'width' => 'Width',
4036: 'linktext' => 'Default Link Text',
4037: 'explanation' => 'Default Explanation',
4038: 'passback' => 'Tool can return grades:',
4039: 'roster' => 'Tool can retrieve roster:',
4040: 'crstarget' => 'Display target',
4041: 'crslabel' => 'Course label',
4042: 'crstitle' => 'Course title',
4043: 'crslinktext' => 'Link Text',
4044: 'crsexplanation' => 'Explanation',
1.267 raeburn 4045: );
4046: return %lt;
4047: }
4048:
1.121 raeburn 4049: sub print_coursedefaults {
1.139 raeburn 4050: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 4051: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4052: my $itemcount = 1;
1.192 raeburn 4053: my %choices = &Apache::lonlocal::texthash (
4054: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 4055: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 4056: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4057: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 4058: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4059: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4060: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4061: canclone => "People who may clone a course (besides course's owner and coordinators)",
4062: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4063: );
1.198 raeburn 4064: my %staticdefaults = (
4065: anonsurvey_threshold => 10,
4066: uploadquota => 500,
1.257 raeburn 4067: postsubmit => 60,
1.276 raeburn 4068: mysqltables => 172800,
1.198 raeburn 4069: );
1.139 raeburn 4070: if ($position eq 'top') {
1.257 raeburn 4071: %defaultchecked = (
4072: 'canuse_pdfforms' => 'off',
4073: 'uselcmath' => 'on',
4074: 'usejsme' => 'on',
1.289 raeburn 4075: 'canclone' => 'none',
1.257 raeburn 4076: );
4077: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 4078: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4079: \%choices,$itemcount);
1.264 raeburn 4080: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4081: $datatable .=
4082: '<tr'.$css_class.'><td valign="top">'.
4083: '<span class="LC_nobreak">'.$choices{'canclone'}.
4084: '</span></td><td class="LC_left_item">';
4085: my $currcanclone = 'none';
4086: my $onclick;
4087: my @cloneoptions = ('none','domain');
4088: my %clonetitles = (
4089: none => 'No additional course requesters',
4090: domain => "Any course requester in course's domain",
4091: instcode => 'Course requests for official courses ...',
4092: );
4093: my (%codedefaults,@code_order,@posscodes);
4094: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4095: \@code_order) eq 'ok') {
4096: if (@code_order > 0) {
4097: push(@cloneoptions,'instcode');
4098: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4099: }
4100: }
4101: if (ref($settings) eq 'HASH') {
4102: if ($settings->{'canclone'}) {
4103: if (ref($settings->{'canclone'}) eq 'HASH') {
4104: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4105: if (@code_order > 0) {
4106: $currcanclone = 'instcode';
4107: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4108: }
4109: }
4110: } elsif ($settings->{'canclone'} eq 'domain') {
4111: $currcanclone = $settings->{'canclone'};
4112: }
4113: }
1.289 raeburn 4114: }
1.264 raeburn 4115: foreach my $option (@cloneoptions) {
4116: my ($checked,$additional);
4117: if ($currcanclone eq $option) {
4118: $checked = ' checked="checked"';
4119: }
4120: if ($option eq 'instcode') {
4121: if (@code_order) {
4122: my $show = 'none';
4123: if ($checked) {
4124: $show = 'block';
4125: }
4126: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4127: &mt('Institutional codes for new and cloned course have identical:').
4128: '<br />';
4129: foreach my $item (@code_order) {
4130: my $codechk;
4131: if ($checked) {
4132: if (grep(/^\Q$item\E$/,@posscodes)) {
4133: $codechk = ' checked="checked"';
4134: }
4135: }
4136: $additional .= '<label>'.
4137: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4138: $item.'</label>';
4139: }
4140: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4141: }
4142: }
4143: $datatable .=
4144: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4145: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4146: '</label> '.$additional.'</span><br />';
4147: }
4148: $datatable .= '</td>'.
4149: '</tr>';
4150: $itemcount ++;
1.139 raeburn 4151: } else {
4152: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4153: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4154: my $currusecredits = 0;
1.257 raeburn 4155: my $postsubmitclient = 1;
1.271 raeburn 4156: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4157: if (ref($settings) eq 'HASH') {
4158: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4159: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4160: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4161: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4162: }
4163: }
1.192 raeburn 4164: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4165: foreach my $type (@types) {
4166: next if ($type eq 'community');
4167: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4168: if ($defcredits{$type} ne '') {
4169: $currusecredits = 1;
4170: }
4171: }
4172: }
4173: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4174: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4175: $postsubmitclient = 0;
4176: foreach my $type (@types) {
4177: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4178: }
4179: } else {
4180: foreach my $type (@types) {
4181: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4182: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 4183: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 4184: } else {
4185: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4186: }
4187: } else {
4188: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4189: }
4190: }
4191: }
4192: } else {
4193: foreach my $type (@types) {
4194: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 4195: }
4196: }
1.276 raeburn 4197: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4198: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4199: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4200: }
4201: } else {
4202: foreach my $type (@types) {
4203: $currmysql{$type} = $staticdefaults{'mysqltables'};
4204: }
4205: }
1.258 raeburn 4206: } else {
4207: foreach my $type (@types) {
4208: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4209: }
1.139 raeburn 4210: }
4211: if (!$currdefresponder) {
1.198 raeburn 4212: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4213: } elsif ($currdefresponder < 1) {
4214: $currdefresponder = 1;
4215: }
1.198 raeburn 4216: foreach my $type (@types) {
4217: if ($curruploadquota{$type} eq '') {
4218: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4219: }
4220: }
1.139 raeburn 4221: $datatable .=
1.192 raeburn 4222: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4223: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4224: '</span></td>'.
4225: '<td class="LC_right_item"><span class="LC_nobreak">'.
4226: '<input type="text" name="anonsurvey_threshold"'.
4227: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 4228: '</td></tr>'."\n";
4229: $itemcount ++;
4230: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4231: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4232: $choices{'uploadquota'}.
4233: '</span></td>'.
4234: '<td align="right" class="LC_right_item">'.
4235: '<table><tr>';
1.198 raeburn 4236: foreach my $type (@types) {
4237: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4238: '<input type="text" name="uploadquota_'.$type.'"'.
4239: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4240: }
4241: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 4242: $itemcount ++;
1.236 raeburn 4243: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 4244: my $display = 'none';
1.192 raeburn 4245: if ($currusecredits) {
4246: $display = 'block';
4247: }
4248: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 4249: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4250: foreach my $type (@types) {
4251: next if ($type eq 'community');
4252: $additional .= '<td align="center">'.&mt($type).'<br />'.
4253: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 4254: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 4255: }
4256: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 4257: %defaultchecked = ('coursecredits' => 'off');
4258: @toggles = ('coursecredits');
4259: my $current = {
4260: 'coursecredits' => $currusecredits,
4261: };
4262: (my $table,$itemcount) =
4263: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 4264: \%choices,$itemcount,$onclick,$additional,'left');
4265: $datatable .= $table;
4266: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4267: my $display = 'none';
4268: if ($postsubmitclient) {
4269: $display = 'block';
4270: }
4271: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 4272: &mt('Number of seconds submit is disabled').'<br />'.
4273: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4274: '<table><tr>';
1.257 raeburn 4275: foreach my $type (@types) {
4276: $additional .= '<td align="center">'.&mt($type).'<br />'.
4277: '<input type="text" name="'.$type.'_timeout" value="'.
4278: $deftimeout{$type}.'" size="5" /></td>';
4279: }
4280: $additional .= '</tr></table></div>'."\n";
4281: %defaultchecked = ('postsubmit' => 'on');
4282: @toggles = ('postsubmit');
1.280 raeburn 4283: $current = {
4284: 'postsubmit' => $postsubmitclient,
4285: };
1.257 raeburn 4286: ($table,$itemcount) =
4287: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4288: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 4289: $datatable .= $table;
1.276 raeburn 4290: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4291: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4292: $choices{'mysqltables'}.
4293: '</span></td>'.
4294: '<td align="right" class="LC_right_item">'.
4295: '<table><tr>';
4296: foreach my $type (@types) {
4297: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4298: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 4299: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 4300: }
4301: $datatable .= '</tr></table></td></tr>'."\n";
4302: $itemcount ++;
4303:
1.139 raeburn 4304: }
1.192 raeburn 4305: $$rowtotal += $itemcount;
1.121 raeburn 4306: return $datatable;
1.118 jms 4307: }
4308:
1.231 raeburn 4309: sub print_selfenrollment {
4310: my ($position,$dom,$settings,$rowtotal) = @_;
4311: my ($css_class,$datatable);
4312: my $itemcount = 1;
1.271 raeburn 4313: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 4314: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 4315: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4316: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 4317: my @rows;
4318: my $key;
4319: if ($position eq 'top') {
4320: $key = 'admin';
4321: if (ref($rowsref) eq 'ARRAY') {
4322: @rows = @{$rowsref};
4323: }
4324: } elsif ($position eq 'middle') {
4325: $key = 'default';
4326: @rows = ('types','registered','approval','limit');
4327: }
4328: foreach my $row (@rows) {
4329: if (defined($titlesref->{$row})) {
4330: $itemcount ++;
4331: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4332: $datatable .= '<tr'.$css_class.'>'.
4333: '<td>'.$titlesref->{$row}.'</td>'.
4334: '<td class="LC_left_item">'.
4335: '<table><tr>';
4336: my (%current,%currentcap);
4337: if (ref($settings) eq 'HASH') {
4338: if (ref($settings->{$key}) eq 'HASH') {
4339: foreach my $type (@types) {
4340: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4341: $current{$type} = $settings->{$key}->{$type}->{$row};
4342: }
4343: if (($row eq 'limit') && ($key eq 'default')) {
4344: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4345: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4346: }
4347: }
4348: }
4349: }
4350: }
4351: my %roles = (
4352: '0' => &Apache::lonnet::plaintext('dc'),
4353: );
4354:
4355: foreach my $type (@types) {
4356: unless (($row eq 'registered') && ($key eq 'default')) {
4357: $datatable .= '<th>'.&mt($type).'</th>';
4358: }
4359: }
4360: unless (($row eq 'registered') && ($key eq 'default')) {
4361: $datatable .= '</tr><tr>';
4362: }
4363: foreach my $type (@types) {
4364: if ($type eq 'community') {
4365: $roles{'1'} = &mt('Community personnel');
4366: } else {
4367: $roles{'1'} = &mt('Course personnel');
4368: }
4369: $datatable .= '<td style="vertical-align: top">';
4370: if ($position eq 'top') {
4371: my %checked;
4372: if ($current{$type} eq '0') {
4373: $checked{'0'} = ' checked="checked"';
4374: } else {
4375: $checked{'1'} = ' checked="checked"';
4376: }
4377: foreach my $role ('1','0') {
4378: $datatable .= '<span class="LC_nobreak"><label>'.
4379: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4380: 'value="'.$role.'"'.$checked{$role}.' />'.
4381: $roles{$role}.'</label></span> ';
4382: }
4383: } else {
4384: if ($row eq 'types') {
4385: my %checked;
4386: if ($current{$type} =~ /^(all|dom)$/) {
4387: $checked{$1} = ' checked="checked"';
4388: } else {
4389: $checked{''} = ' checked="checked"';
4390: }
4391: foreach my $val ('','dom','all') {
4392: $datatable .= '<span class="LC_nobreak"><label>'.
4393: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4394: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4395: }
4396: } elsif ($row eq 'registered') {
4397: my %checked;
4398: if ($current{$type} eq '1') {
4399: $checked{'1'} = ' checked="checked"';
4400: } else {
4401: $checked{'0'} = ' checked="checked"';
4402: }
4403: foreach my $val ('0','1') {
4404: $datatable .= '<span class="LC_nobreak"><label>'.
4405: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4406: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4407: }
4408: } elsif ($row eq 'approval') {
4409: my %checked;
4410: if ($current{$type} =~ /^([12])$/) {
4411: $checked{$1} = ' checked="checked"';
4412: } else {
4413: $checked{'0'} = ' checked="checked"';
4414: }
4415: for my $val (0..2) {
4416: $datatable .= '<span class="LC_nobreak"><label>'.
4417: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4418: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4419: }
4420: } elsif ($row eq 'limit') {
4421: my %checked;
4422: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4423: $checked{$1} = ' checked="checked"';
4424: } else {
4425: $checked{'none'} = ' checked="checked"';
4426: }
4427: my $cap;
4428: if ($currentcap{$type} =~ /^\d+$/) {
4429: $cap = $currentcap{$type};
4430: }
4431: foreach my $val ('none','allstudents','selfenrolled') {
4432: $datatable .= '<span class="LC_nobreak"><label>'.
4433: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4434: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4435: }
4436: $datatable .= '<br />'.
4437: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4438: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4439: '</span>';
4440: }
4441: }
4442: $datatable .= '</td>';
4443: }
4444: $datatable .= '</tr>';
4445: }
4446: $datatable .= '</table></td></tr>';
4447: }
4448: } elsif ($position eq 'bottom') {
1.235 raeburn 4449: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4450: }
4451: $$rowtotal += $itemcount;
4452: return $datatable;
4453: }
4454:
4455: sub print_validation_rows {
4456: my ($caller,$dom,$settings,$rowtotal) = @_;
4457: my ($itemsref,$namesref,$fieldsref);
4458: if ($caller eq 'selfenroll') {
4459: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4460: } elsif ($caller eq 'requestcourses') {
4461: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4462: }
4463: my %currvalidation;
4464: if (ref($settings) eq 'HASH') {
4465: if (ref($settings->{'validation'}) eq 'HASH') {
4466: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 4467: }
1.235 raeburn 4468: }
4469: my $datatable;
4470: my $itemcount = 0;
4471: foreach my $item (@{$itemsref}) {
4472: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4473: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4474: $namesref->{$item}.
4475: '</span></td>'.
4476: '<td class="LC_left_item">';
4477: if (($item eq 'url') || ($item eq 'button')) {
4478: $datatable .= '<span class="LC_nobreak">'.
4479: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4480: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4481: } elsif ($item eq 'fields') {
4482: my @currfields;
4483: if (ref($currvalidation{$item}) eq 'ARRAY') {
4484: @currfields = @{$currvalidation{$item}};
4485: }
4486: foreach my $field (@{$fieldsref}) {
4487: my $check = '';
4488: if (grep(/^\Q$field\E$/,@currfields)) {
4489: $check = ' checked="checked"';
4490: }
4491: $datatable .= '<span class="LC_nobreak"><label>'.
4492: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4493: ' value="'.$field.'"'.$check.' />'.$field.
4494: '</label></span> ';
4495: }
4496: } elsif ($item eq 'markup') {
4497: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4498: $currvalidation{$item}.
1.231 raeburn 4499: '</textarea>';
1.235 raeburn 4500: }
4501: $datatable .= '</td></tr>'."\n";
4502: if (ref($rowtotal)) {
1.231 raeburn 4503: $itemcount ++;
4504: }
4505: }
1.235 raeburn 4506: if ($caller eq 'requestcourses') {
4507: my %currhash;
1.248 raeburn 4508: if (ref($settings) eq 'HASH') {
4509: if (ref($settings->{'validation'}) eq 'HASH') {
4510: if ($settings->{'validation'}{'dc'} ne '') {
4511: $currhash{$settings->{'validation'}{'dc'}} = 1;
4512: }
1.235 raeburn 4513: }
4514: }
4515: my $numinrow = 2;
4516: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4517: 'validationdc',%currhash);
1.247 raeburn 4518: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4519: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 4520: if ($numdc > 1) {
1.247 raeburn 4521: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 4522: } else {
1.247 raeburn 4523: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 4524: }
1.247 raeburn 4525: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 4526: $itemcount ++;
4527: }
4528: if (ref($rowtotal)) {
4529: $$rowtotal += $itemcount;
4530: }
1.231 raeburn 4531: return $datatable;
4532: }
4533:
1.137 raeburn 4534: sub print_usersessions {
4535: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 4536: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 4537: my (%by_ip,%by_location,@intdoms,@instdoms);
4538: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 4539:
4540: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4541: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4542: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4543: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4544: if ($position eq 'top') {
1.152 raeburn 4545: if (keys(%serverhomes) > 1) {
1.145 raeburn 4546: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 4547: my $curroffloadnow;
4548: if (ref($settings) eq 'HASH') {
4549: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4550: $curroffloadnow = $settings->{'offloadnow'};
4551: }
4552: }
4553: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4554: } else {
1.140 raeburn 4555: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 4556: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
4557: '</td></tr>';
1.140 raeburn 4558: }
1.137 raeburn 4559: } else {
1.279 raeburn 4560: my %titles = &usersession_titles();
4561: my ($prefix,@types);
4562: if ($position eq 'bottom') {
4563: $prefix = 'remote';
4564: @types = ('version','excludedomain','includedomain');
1.145 raeburn 4565: } else {
1.279 raeburn 4566: $prefix = 'hosted';
4567: @types = ('excludedomain','includedomain');
4568: }
4569: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4570: }
4571: $$rowtotal += $itemcount;
4572: return $datatable;
4573: }
4574:
4575: sub rules_by_location {
4576: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
4577: my ($datatable,$itemcount,$css_class);
4578: if (keys(%{$by_location}) == 0) {
4579: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4580: $datatable = '<tr'.$css_class.'><td colspan="2">'.
4581: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
4582: '</td></tr>';
4583: $itemcount = 1;
4584: } else {
4585: $itemcount = 0;
4586: my $numinrow = 5;
4587: my (%current,%checkedon,%checkedoff);
4588: my @locations = sort(keys(%{$by_location}));
4589: foreach my $type (@{$types}) {
4590: $checkedon{$type} = '';
4591: $checkedoff{$type} = ' checked="checked"';
4592: }
4593: if (ref($settings) eq 'HASH') {
4594: if (ref($settings->{$prefix}) eq 'HASH') {
4595: foreach my $key (keys(%{$settings->{$prefix}})) {
4596: $current{$key} = $settings->{$prefix}{$key};
4597: if ($key eq 'version') {
4598: if ($current{$key} ne '') {
1.145 raeburn 4599: $checkedon{$key} = ' checked="checked"';
4600: $checkedoff{$key} = '';
4601: }
1.279 raeburn 4602: } elsif (ref($current{$key}) eq 'ARRAY') {
4603: $checkedon{$key} = ' checked="checked"';
4604: $checkedoff{$key} = '';
1.137 raeburn 4605: }
4606: }
4607: }
1.279 raeburn 4608: }
4609: foreach my $type (@{$types}) {
4610: next if ($type ne 'version' && !@locations);
4611: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4612: $datatable .= '<tr'.$css_class.'>
4613: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4614: <span class="LC_nobreak">
4615: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4616: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4617: if ($type eq 'version') {
4618: my @lcversions = &Apache::lonnet::all_loncaparevs();
4619: my $selector = '<select name="'.$prefix.'_version">';
4620: foreach my $version (@lcversions) {
4621: my $selected = '';
4622: if ($current{'version'} eq $version) {
4623: $selected = ' selected="selected"';
1.145 raeburn 4624: }
1.279 raeburn 4625: $selector .= ' <option value="'.$version.'"'.
4626: $selected.'>'.$version.'</option>';
4627: }
4628: $selector .= '</select> ';
4629: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4630: } else {
4631: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4632: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4633: ' />'.(' 'x2).
4634: '<input type="button" value="'.&mt('uncheck all').'" '.
4635: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4636: "\n".
4637: '</div><div><table>';
4638: my $rem;
4639: for (my $i=0; $i<@locations; $i++) {
4640: my ($showloc,$value,$checkedtype);
4641: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4642: my $ip = $by_location->{$locations[$i]}->[0];
4643: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4644: $value = join(':',@{$by_ip->{$ip}});
4645: $showloc = join(', ',@{$by_ip->{$ip}});
4646: if (ref($current{$type}) eq 'ARRAY') {
4647: foreach my $loc (@{$by_ip->{$ip}}) {
4648: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4649: $checkedtype = ' checked="checked"';
4650: last;
1.145 raeburn 4651: }
1.138 raeburn 4652: }
4653: }
4654: }
1.137 raeburn 4655: }
1.279 raeburn 4656: $rem = $i%($numinrow);
4657: if ($rem == 0) {
4658: if ($i > 0) {
4659: $datatable .= '</tr>';
4660: }
4661: $datatable .= '<tr>';
4662: }
4663: $datatable .= '<td class="LC_left_item">'.
4664: '<span class="LC_nobreak"><label>'.
4665: '<input type="checkbox" name="'.$prefix.'_'.$type.
4666: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4667: '</label></span></td>';
4668: }
4669: $rem = @locations%($numinrow);
4670: my $colsleft = $numinrow - $rem;
4671: if ($colsleft > 1 ) {
4672: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4673: ' </td>';
4674: } elsif ($colsleft == 1) {
4675: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4676: }
1.279 raeburn 4677: $datatable .= '</tr></table>';
1.137 raeburn 4678: }
1.279 raeburn 4679: $datatable .= '</td></tr>';
4680: $itemcount ++;
1.137 raeburn 4681: }
4682: }
1.279 raeburn 4683: return ($datatable,$itemcount);
1.137 raeburn 4684: }
4685:
1.275 raeburn 4686: sub print_ssl {
4687: my ($position,$dom,$settings,$rowtotal) = @_;
4688: my ($css_class,$datatable);
4689: my $itemcount = 1;
4690: if ($position eq 'top') {
1.281 raeburn 4691: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4692: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4693: my $same_institution;
4694: if ($intdom ne '') {
4695: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4696: if (ref($internet_names) eq 'ARRAY') {
4697: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4698: $same_institution = 1;
4699: }
4700: }
4701: }
1.275 raeburn 4702: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 4703: $datatable = '<tr'.$css_class.'><td colspan="2">';
4704: if ($same_institution) {
4705: my %domservers = &Apache::lonnet::get_servers($dom);
4706: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
4707: } else {
4708: $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.");
4709: }
4710: $datatable .= '</td></tr>';
1.275 raeburn 4711: $itemcount ++;
4712: } else {
4713: my %titles = &ssl_titles();
4714: my (%by_ip,%by_location,@intdoms,@instdoms);
4715: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4716: my @alldoms = &Apache::lonnet::all_domains();
4717: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4718: my @domservers = &Apache::lonnet::get_servers($dom);
4719: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4720: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 4721: if (($position eq 'connto') || ($position eq 'connfrom')) {
4722: my $legacy;
4723: unless (ref($settings) eq 'HASH') {
4724: my $name;
4725: if ($position eq 'connto') {
4726: $name = 'loncAllowInsecure';
4727: } else {
4728: $name = 'londAllowInsecure';
4729: }
4730: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
4731: my @ids=&Apache::lonnet::current_machine_ids();
4732: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
4733: my %what = (
4734: $name => 1,
4735: );
4736: my ($result,$returnhash) =
4737: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
4738: if ($result eq 'ok') {
4739: if (ref($returnhash) eq 'HASH') {
4740: $legacy = $returnhash->{$name};
4741: }
4742: }
4743: } else {
4744: $legacy = $Apache::lonnet::perlvar{$name};
4745: }
4746: }
1.275 raeburn 4747: foreach my $type ('dom','intdom','other') {
4748: my %checked;
4749: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4750: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4751: '<td class="LC_right_item">';
4752: my $skip;
4753: if ($type eq 'dom') {
4754: unless (keys(%servers) > 1) {
4755: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4756: $skip = 1;
4757: }
4758: }
4759: if ($type eq 'intdom') {
4760: unless (@instdoms > 1) {
4761: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4762: $skip = 1;
4763: }
4764: } elsif ($type eq 'other') {
4765: if (keys(%by_location) == 0) {
4766: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4767: $skip = 1;
4768: }
4769: }
4770: unless ($skip) {
4771: $checked{'yes'} = ' checked="checked"';
4772: if (ref($settings) eq 'HASH') {
1.293 raeburn 4773: if (ref($settings->{$position}) eq 'HASH') {
4774: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 4775: $checked{$1} = $checked{'yes'};
4776: delete($checked{'yes'});
4777: }
4778: }
1.293 raeburn 4779: } else {
4780: if ($legacy == 0) {
4781: $checked{'req'} = $checked{'yes'};
4782: delete($checked{'yes'});
4783: }
1.275 raeburn 4784: }
4785: foreach my $option ('no','yes','req') {
4786: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 4787: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 4788: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4789: '</label></span>'.(' 'x2);
4790: }
4791: }
4792: $datatable .= '</td></tr>';
4793: $itemcount ++;
4794: }
4795: } else {
4796: my $prefix = 'replication';
4797: my @types = ('certreq','nocertreq');
1.279 raeburn 4798: if (keys(%by_location) == 0) {
4799: $datatable .= '<tr'.$css_class.'><td>'.
4800: &mt('Nothing to set here, as there are no other institutions').
4801: '</td></tr>';
4802: $itemcount ++;
1.275 raeburn 4803: } else {
1.279 raeburn 4804: ($datatable,$itemcount) =
4805: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 4806: }
4807: }
4808: }
4809: $$rowtotal += $itemcount;
4810: return $datatable;
4811: }
4812:
4813: sub ssl_titles {
4814: return &Apache::lonlocal::texthash (
4815: dom => 'LON-CAPA servers/VMs from same domain',
4816: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4817: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 4818: connto => 'Connections to other servers',
4819: connfrom => 'Connections from other servers',
1.275 raeburn 4820: replication => 'Replicating content to other institutions',
4821: certreq => 'Client certificate required, but specific domains exempt',
4822: nocertreq => 'No client certificate required, except for specific domains',
4823: no => 'SSL not used',
4824: yes => 'SSL Optional (used if available)',
4825: req => 'SSL Required',
4826: );
1.279 raeburn 4827: }
4828:
4829: sub print_trust {
4830: my ($prefix,$dom,$settings,$rowtotal) = @_;
4831: my ($css_class,$datatable,%checked,%choices);
4832: my (%by_ip,%by_location,@intdoms,@instdoms);
4833: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4834: my $itemcount = 1;
4835: my %titles = &trust_titles();
4836: my @types = ('exc','inc');
4837: if ($prefix eq 'top') {
4838: $prefix = 'content';
4839: } elsif ($prefix eq 'bottom') {
4840: $prefix = 'msg';
4841: }
4842: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4843: $$rowtotal += $itemcount;
4844: return $datatable;
4845: }
4846:
4847: sub trust_titles {
4848: return &Apache::lonlocal::texthash(
4849: content => "Access to this domain's content by others",
4850: shared => "Access to other domain's content by this domain",
4851: enroll => "Enrollment in this domain's courses by others",
4852: othcoau => "Co-author roles in this domain for others",
4853: coaurem => "Co-author roles for this domain's users elsewhere",
4854: domroles => "Domain roles in this domain assignable to others",
4855: catalog => "Course Catalog for this domain displayed elsewhere",
4856: reqcrs => "Requests for creation of courses in this domain by others",
4857: msg => "Users in other domains can send messages to this domain",
4858: exc => "Allow all, but exclude specific domains",
4859: inc => "Deny all, but include specific domains",
4860: );
1.275 raeburn 4861: }
4862:
1.138 raeburn 4863: sub build_location_hashes {
1.275 raeburn 4864: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4865: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4866: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4867: my %iphost = &Apache::lonnet::get_iphost();
4868: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4869: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4870: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4871: foreach my $id (@{$iphost{$primary_ip}}) {
4872: my $intdom = &Apache::lonnet::internet_dom($id);
4873: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4874: push(@{$intdoms},$intdom);
4875: }
4876: }
4877: }
4878: foreach my $ip (keys(%iphost)) {
4879: if (ref($iphost{$ip}) eq 'ARRAY') {
4880: foreach my $id (@{$iphost{$ip}}) {
4881: my $location = &Apache::lonnet::internet_dom($id);
4882: if ($location) {
1.275 raeburn 4883: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4884: my $dom = &Apache::lonnet::host_domain($id);
4885: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4886: push(@{$instdoms},$dom);
4887: }
4888: next;
4889: }
1.138 raeburn 4890: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4891: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4892: push(@{$by_ip->{$ip}},$location);
4893: }
4894: } else {
4895: $by_ip->{$ip} = [$location];
4896: }
4897: }
4898: }
4899: }
4900: }
4901: foreach my $ip (sort(keys(%{$by_ip}))) {
4902: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4903: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4904: my $first = $by_ip->{$ip}->[0];
4905: if (ref($by_location->{$first}) eq 'ARRAY') {
4906: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4907: push(@{$by_location->{$first}},$ip);
4908: }
4909: } else {
4910: $by_location->{$first} = [$ip];
4911: }
4912: }
4913: }
4914: return;
4915: }
4916:
1.145 raeburn 4917: sub current_offloads_to {
4918: my ($dom,$settings,$servers) = @_;
4919: my (%spareid,%otherdomconfigs);
1.152 raeburn 4920: if (ref($servers) eq 'HASH') {
1.145 raeburn 4921: foreach my $lonhost (sort(keys(%{$servers}))) {
4922: my $gotspares;
1.152 raeburn 4923: if (ref($settings) eq 'HASH') {
4924: if (ref($settings->{'spares'}) eq 'HASH') {
4925: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4926: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4927: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4928: $gotspares = 1;
4929: }
1.145 raeburn 4930: }
4931: }
4932: unless ($gotspares) {
4933: my $gotspares;
4934: my $serverhomeID =
4935: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4936: my $serverhomedom =
4937: &Apache::lonnet::host_domain($serverhomeID);
4938: if ($serverhomedom ne $dom) {
4939: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4940: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4941: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4942: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4943: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4944: $gotspares = 1;
4945: }
4946: }
4947: } else {
4948: $otherdomconfigs{$serverhomedom} =
4949: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4950: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4951: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4952: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4953: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4954: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4955: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4956: $gotspares = 1;
4957: }
4958: }
4959: }
4960: }
4961: }
4962: }
4963: }
4964: unless ($gotspares) {
4965: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4966: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4967: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4968: } else {
4969: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4970: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4971: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4972: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4973: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4974: } else {
1.150 raeburn 4975: my %what = (
4976: spareid => 1,
4977: );
4978: my ($result,$returnhash) =
4979: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4980: if ($result eq 'ok') {
4981: if (ref($returnhash) eq 'HASH') {
4982: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4983: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4984: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4985: }
4986: }
1.145 raeburn 4987: }
4988: }
4989: }
4990: }
4991: }
4992: }
4993: return %spareid;
4994: }
4995:
4996: sub spares_row {
1.261 raeburn 4997: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4998: my $css_class;
4999: my $numinrow = 4;
5000: my $itemcount = 1;
5001: my $datatable;
1.152 raeburn 5002: my %typetitles = &sparestype_titles();
5003: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 5004: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 5005: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
5006: my ($othercontrol,$serverdom);
5007: if ($serverhome ne $server) {
5008: $serverdom = &Apache::lonnet::host_domain($serverhome);
5009: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5010: } else {
5011: $serverdom = &Apache::lonnet::host_domain($server);
5012: if ($serverdom ne $dom) {
5013: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
5014: }
5015: }
5016: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 5017: my $checkednow;
5018: if (ref($curroffloadnow) eq 'HASH') {
5019: if ($curroffloadnow->{$server}) {
5020: $checkednow = ' checked="checked"';
5021: }
5022: }
1.145 raeburn 5023: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5024: $datatable .= '<tr'.$css_class.'>
5025: <td rowspan="2">
1.183 bisitz 5026: <span class="LC_nobreak">'.
5027: &mt('[_1] when busy, offloads to:'
1.261 raeburn 5028: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 5029: '<span class="LC_nobreak">'."\n".
1.261 raeburn 5030: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5031: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 5032: "\n";
1.145 raeburn 5033: my (%current,%canselect);
1.152 raeburn 5034: my @choices =
5035: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5036: foreach my $type ('primary','default') {
5037: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5038: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5039: my @spares = @{$spareid->{$server}{$type}};
5040: if (@spares > 0) {
1.152 raeburn 5041: if ($othercontrol) {
5042: $current{$type} = join(', ',@spares);
5043: } else {
5044: $current{$type} .= '<table>';
5045: my $numspares = scalar(@spares);
5046: for (my $i=0; $i<@spares; $i++) {
5047: my $rem = $i%($numinrow);
5048: if ($rem == 0) {
5049: if ($i > 0) {
5050: $current{$type} .= '</tr>';
5051: }
5052: $current{$type} .= '<tr>';
1.145 raeburn 5053: }
1.152 raeburn 5054: $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'".');" /> '.
5055: $spareid->{$server}{$type}[$i].
5056: '</label></td>'."\n";
5057: }
5058: my $rem = @spares%($numinrow);
5059: my $colsleft = $numinrow - $rem;
5060: if ($colsleft > 1 ) {
5061: $current{$type} .= '<td colspan="'.$colsleft.
5062: '" class="LC_left_item">'.
5063: ' </td>';
5064: } elsif ($colsleft == 1) {
5065: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5066: }
1.152 raeburn 5067: $current{$type} .= '</tr></table>';
1.150 raeburn 5068: }
1.145 raeburn 5069: }
5070: }
5071: if ($current{$type} eq '') {
5072: $current{$type} = &mt('None specified');
5073: }
1.152 raeburn 5074: if ($othercontrol) {
5075: if ($type eq 'primary') {
5076: $canselect{$type} = $othercontrol;
5077: }
5078: } else {
5079: $canselect{$type} =
5080: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5081: '<select name="newspare_'.$type.'_'.$server.'" '.
5082: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5083: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5084: if (@choices > 0) {
5085: foreach my $lonhost (@choices) {
5086: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5087: }
5088: }
5089: $canselect{$type} .= '</select>'."\n";
5090: }
5091: } else {
5092: $current{$type} = &mt('Could not be determined');
5093: if ($type eq 'primary') {
5094: $canselect{$type} = $othercontrol;
5095: }
1.145 raeburn 5096: }
1.152 raeburn 5097: if ($type eq 'default') {
5098: $datatable .= '<tr'.$css_class.'>';
5099: }
5100: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5101: '<td>'.$current{$type}.'</td>'."\n".
5102: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5103: }
5104: $itemcount ++;
5105: }
5106: }
5107: $$rowtotal += $itemcount;
5108: return $datatable;
5109: }
5110:
1.152 raeburn 5111: sub possible_newspares {
5112: my ($server,$currspares,$serverhomes,$altids) = @_;
5113: my $serverhostname = &Apache::lonnet::hostname($server);
5114: my %excluded;
5115: if ($serverhostname ne '') {
5116: %excluded = (
5117: $serverhostname => 1,
5118: );
5119: }
5120: if (ref($currspares) eq 'HASH') {
5121: foreach my $type (keys(%{$currspares})) {
5122: if (ref($currspares->{$type}) eq 'ARRAY') {
5123: if (@{$currspares->{$type}} > 0) {
5124: foreach my $curr (@{$currspares->{$type}}) {
5125: my $hostname = &Apache::lonnet::hostname($curr);
5126: $excluded{$hostname} = 1;
5127: }
5128: }
5129: }
5130: }
5131: }
5132: my @choices;
5133: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5134: if (keys(%{$serverhomes}) > 1) {
5135: foreach my $name (sort(keys(%{$serverhomes}))) {
5136: unless ($excluded{$name}) {
5137: if (exists($altids->{$serverhomes->{$name}})) {
5138: push(@choices,$altids->{$serverhomes->{$name}});
5139: } else {
5140: push(@choices,$serverhomes->{$name});
1.145 raeburn 5141: }
5142: }
5143: }
5144: }
5145: }
1.152 raeburn 5146: return sort(@choices);
1.145 raeburn 5147: }
5148:
1.150 raeburn 5149: sub print_loadbalancing {
5150: my ($dom,$settings,$rowtotal) = @_;
5151: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5152: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5153: my $numinrow = 1;
5154: my $datatable;
5155: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5156: my (%currbalancer,%currtargets,%currrules,%existing);
5157: if (ref($settings) eq 'HASH') {
5158: %existing = %{$settings};
5159: }
5160: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5161: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5162: \%currtargets,\%currrules);
1.150 raeburn 5163: } else {
5164: return;
5165: }
5166: my ($othertitle,$usertypes,$types) =
5167: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5168: my $rownum = 8;
1.150 raeburn 5169: if (ref($types) eq 'ARRAY') {
5170: $rownum += scalar(@{$types});
5171: }
1.171 raeburn 5172: my @css_class = ('LC_odd_row','LC_even_row');
5173: my $balnum = 0;
5174: my $islast;
5175: my (@toshow,$disabledtext);
5176: if (keys(%currbalancer) > 0) {
5177: @toshow = sort(keys(%currbalancer));
5178: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5179: push(@toshow,'');
5180: }
5181: } else {
5182: @toshow = ('');
5183: $disabledtext = &mt('No existing load balancer');
5184: }
5185: foreach my $lonhost (@toshow) {
5186: if ($balnum == scalar(@toshow)-1) {
5187: $islast = 1;
5188: } else {
5189: $islast = 0;
5190: }
5191: my $cssidx = $balnum%2;
5192: my $targets_div_style = 'display: none';
5193: my $disabled_div_style = 'display: block';
5194: my $homedom_div_style = 'display: none';
5195: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5196: '<td rowspan="'.$rownum.'" valign="top">'.
5197: '<p>';
5198: if ($lonhost eq '') {
1.210 raeburn 5199: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 5200: if (keys(%currbalancer) > 0) {
5201: $datatable .= &mt('Add balancer:');
5202: } else {
5203: $datatable .= &mt('Enable balancer:');
5204: }
5205: $datatable .= ' '.
5206: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5207: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5208: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5209: '<option value="" selected="selected">'.&mt('None').
5210: '</option>'."\n";
5211: foreach my $server (sort(keys(%servers))) {
5212: next if ($currbalancer{$server});
5213: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5214: }
1.210 raeburn 5215: $datatable .=
1.171 raeburn 5216: '</select>'."\n".
5217: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5218: } else {
5219: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5220: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5221: &mt('Stop balancing').'</label>'.
5222: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5223: $targets_div_style = 'display: block';
5224: $disabled_div_style = 'display: none';
5225: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5226: $homedom_div_style = 'display: block';
5227: }
5228: }
5229: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5230: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5231: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5232: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5233: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5234: my @sparestypes = ('primary','default');
5235: my %typetitles = &sparestype_titles();
1.284 raeburn 5236: my %hostherechecked = (
5237: no => ' checked="checked"',
5238: );
1.171 raeburn 5239: foreach my $sparetype (@sparestypes) {
5240: my $targettable;
5241: for (my $i=0; $i<$numspares; $i++) {
5242: my $checked;
5243: if (ref($currtargets{$lonhost}) eq 'HASH') {
5244: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5245: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5246: $checked = ' checked="checked"';
5247: }
5248: }
5249: }
5250: my ($chkboxval,$disabled);
5251: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5252: $chkboxval = $spares[$i];
5253: }
5254: if (exists($currbalancer{$spares[$i]})) {
5255: $disabled = ' disabled="disabled"';
5256: }
1.210 raeburn 5257: $targettable .=
1.253 raeburn 5258: '<td><span class="LC_nobreak"><label>'.
5259: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 5260: $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 5261: '</span></label></span></td>';
1.171 raeburn 5262: my $rem = $i%($numinrow);
5263: if ($rem == 0) {
5264: if (($i > 0) && ($i < $numspares-1)) {
5265: $targettable .= '</tr>';
5266: }
5267: if ($i < $numspares-1) {
5268: $targettable .= '<tr>';
1.150 raeburn 5269: }
5270: }
5271: }
1.171 raeburn 5272: if ($targettable ne '') {
5273: my $rem = $numspares%($numinrow);
5274: my $colsleft = $numinrow - $rem;
5275: if ($colsleft > 1 ) {
5276: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5277: ' </td>';
5278: } elsif ($colsleft == 1) {
5279: $targettable .= '<td class="LC_left_item"> </td>';
5280: }
5281: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5282: '<table><tr>'.$targettable.'</tr></table><br />';
5283: }
1.284 raeburn 5284: $hostherechecked{$sparetype} = '';
5285: if (ref($currtargets{$lonhost}) eq 'HASH') {
5286: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5287: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5288: $hostherechecked{$sparetype} = ' checked="checked"';
5289: $hostherechecked{'no'} = '';
5290: }
5291: }
5292: }
5293: }
5294: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5295: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5296: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5297: foreach my $sparetype (@sparestypes) {
5298: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5299: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5300: '</i></label><br />';
1.171 raeburn 5301: }
5302: $datatable .= '</div></td></tr>'.
5303: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5304: $othertitle,$usertypes,$types,\%servers,
5305: \%currbalancer,$lonhost,
5306: $targets_div_style,$homedom_div_style,
5307: $css_class[$cssidx],$balnum,$islast);
5308: $$rowtotal += $rownum;
5309: $balnum ++;
5310: }
5311: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5312: return $datatable;
5313: }
5314:
5315: sub get_loadbalancers_config {
5316: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5317: return unless ((ref($servers) eq 'HASH') &&
5318: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5319: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5320: if (keys(%{$existing}) > 0) {
5321: my $oldlonhost;
5322: foreach my $key (sort(keys(%{$existing}))) {
5323: if ($key eq 'lonhost') {
5324: $oldlonhost = $existing->{'lonhost'};
5325: $currbalancer->{$oldlonhost} = 1;
5326: } elsif ($key eq 'targets') {
5327: if ($oldlonhost) {
5328: $currtargets->{$oldlonhost} = $existing->{'targets'};
5329: }
5330: } elsif ($key eq 'rules') {
5331: if ($oldlonhost) {
5332: $currrules->{$oldlonhost} = $existing->{'rules'};
5333: }
5334: } elsif (ref($existing->{$key}) eq 'HASH') {
5335: $currbalancer->{$key} = 1;
5336: $currtargets->{$key} = $existing->{$key}{'targets'};
5337: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5338: }
5339: }
1.171 raeburn 5340: } else {
5341: my ($balancerref,$targetsref) =
5342: &Apache::lonnet::get_lonbalancer_config($servers);
5343: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5344: foreach my $server (sort(keys(%{$balancerref}))) {
5345: $currbalancer->{$server} = 1;
5346: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5347: }
5348: }
5349: }
1.171 raeburn 5350: return;
1.150 raeburn 5351: }
5352:
5353: sub loadbalancing_rules {
5354: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 5355: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5356: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5357: my $output;
1.171 raeburn 5358: my $num = 0;
1.210 raeburn 5359: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5360: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5361: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5362: foreach my $type (@{$alltypes}) {
1.171 raeburn 5363: $num ++;
1.150 raeburn 5364: my $current;
5365: if (ref($currrules) eq 'HASH') {
5366: $current = $currrules->{$type};
5367: }
1.253 raeburn 5368: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 5369: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5370: $current = '';
5371: }
5372: }
5373: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 5374: $servers,$currbalancer,$lonhost,$dom,
5375: $targets_div_style,$homedom_div_style,
5376: $css_class,$balnum,$num,$islast);
1.150 raeburn 5377: }
5378: }
5379: return $output;
5380: }
5381:
5382: sub loadbalancing_titles {
5383: my ($dom,$intdom,$usertypes,$types) = @_;
5384: my %othertypes = (
5385: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5386: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5387: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5388: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 5389: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5390: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5391: );
1.209 raeburn 5392: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 5393: my @available;
1.150 raeburn 5394: if (ref($types) eq 'ARRAY') {
1.302 raeburn 5395: @available = @{$types};
1.150 raeburn 5396: }
1.302 raeburn 5397: unless (grep(/^default$/,@available)) {
5398: push(@available,'default');
5399: }
5400: unshift(@alltypes,@available);
1.150 raeburn 5401: my %titles;
5402: foreach my $type (@alltypes) {
5403: if ($type =~ /^_LC_/) {
5404: $titles{$type} = $othertypes{$type};
5405: } elsif ($type eq 'default') {
5406: $titles{$type} = &mt('All users from [_1]',$dom);
5407: if (ref($types) eq 'ARRAY') {
5408: if (@{$types} > 0) {
5409: $titles{$type} = &mt('Other users from [_1]',$dom);
5410: }
5411: }
5412: } elsif (ref($usertypes) eq 'HASH') {
5413: $titles{$type} = $usertypes->{$type};
5414: }
5415: }
5416: return (\@alltypes,\%othertypes,\%titles);
5417: }
5418:
5419: sub loadbalance_rule_row {
1.171 raeburn 5420: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5421: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 5422: my @rulenames;
1.150 raeburn 5423: my %ruletitles = &offloadtype_text();
1.209 raeburn 5424: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 5425: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5426: } else {
1.209 raeburn 5427: @rulenames = ('default','homeserver');
5428: if ($type eq '_LC_external') {
5429: push(@rulenames,'externalbalancer');
5430: } else {
5431: push(@rulenames,'specific');
5432: }
5433: push(@rulenames,'none');
1.150 raeburn 5434: }
5435: my $style = $targets_div_style;
1.253 raeburn 5436: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5437: $style = $homedom_div_style;
5438: }
1.171 raeburn 5439: my $space;
5440: if ($islast && $num == 1) {
5441: $space = '<div display="inline-block"> </div>';
5442: }
1.210 raeburn 5443: my $output =
1.171 raeburn 5444: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5445: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5446: '<td valaign="top">'.$space.
5447: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5448: for (my $i=0; $i<@rulenames; $i++) {
5449: my $rule = $rulenames[$i];
5450: my ($checked,$extra);
5451: if ($rulenames[$i] eq 'default') {
5452: $rule = '';
5453: }
5454: if ($rulenames[$i] eq 'specific') {
5455: if (ref($servers) eq 'HASH') {
5456: my $default;
5457: if (($current ne '') && (exists($servers->{$current}))) {
5458: $checked = ' checked="checked"';
5459: }
5460: unless ($checked) {
5461: $default = ' selected="selected"';
5462: }
1.210 raeburn 5463: $extra =
1.171 raeburn 5464: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5465: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5466: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5467: '<option value=""'.$default.'></option>'."\n";
5468: foreach my $server (sort(keys(%{$servers}))) {
5469: if (ref($currbalancer) eq 'HASH') {
5470: next if (exists($currbalancer->{$server}));
5471: }
1.150 raeburn 5472: my $selected;
1.171 raeburn 5473: if ($server eq $current) {
1.150 raeburn 5474: $selected = ' selected="selected"';
5475: }
1.171 raeburn 5476: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5477: }
5478: $extra .= '</select>';
5479: }
5480: } elsif ($rule eq $current) {
5481: $checked = ' checked="checked"';
5482: }
5483: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 5484: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5485: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5486: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 5487: ')"'.$checked.' /> ';
5488: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
5489: $output .= $ruletitles{'particular'};
5490: } else {
5491: $output .= $ruletitles{$rulenames[$i]};
5492: }
5493: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5494: }
5495: $output .= '</div></td></tr>'."\n";
5496: return $output;
5497: }
5498:
5499: sub offloadtype_text {
5500: my %ruletitles = &Apache::lonlocal::texthash (
5501: 'default' => 'Offloads to default destinations',
5502: 'homeserver' => "Offloads to user's home server",
5503: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5504: 'specific' => 'Offloads to specific server',
1.161 raeburn 5505: 'none' => 'No offload',
1.209 raeburn 5506: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5507: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 5508: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5509: );
5510: return %ruletitles;
5511: }
5512:
5513: sub sparestype_titles {
5514: my %typestitles = &Apache::lonlocal::texthash (
5515: 'primary' => 'primary',
5516: 'default' => 'default',
5517: );
5518: return %typestitles;
5519: }
5520:
1.28 raeburn 5521: sub contact_titles {
5522: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 5523: 'supportemail' => 'Support E-mail address',
5524: 'adminemail' => 'Default Server Admin E-mail address',
5525: 'errormail' => 'Error reports to be e-mailed to',
5526: 'packagesmail' => 'Package update alerts to be e-mailed to',
5527: 'helpdeskmail' => "Helpdesk requests for this domain's users",
1.289 raeburn 5528: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
1.286 raeburn 5529: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5530: 'requestsmail' => 'E-mail from course requests requiring approval',
5531: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 5532: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5533: );
5534: my %short_titles = &Apache::lonlocal::texthash (
5535: adminemail => 'Admin E-mail address',
5536: supportemail => 'Support E-mail',
5537: );
5538: return (\%titles,\%short_titles);
5539: }
5540:
1.286 raeburn 5541: sub helpform_fields {
5542: my %titles = &Apache::lonlocal::texthash (
5543: 'username' => 'Name',
5544: 'user' => 'Username/domain',
5545: 'phone' => 'Phone',
5546: 'cc' => 'Cc e-mail',
5547: 'course' => 'Course Details',
5548: 'section' => 'Sections',
1.289 raeburn 5549: 'screenshot' => 'File upload',
1.286 raeburn 5550: );
5551: my @fields = ('username','phone','user','course','section','cc','screenshot');
5552: my %possoptions = (
5553: username => ['yes','no','req'],
1.289 raeburn 5554: phone => ['yes','no','req'],
1.286 raeburn 5555: user => ['yes','no'],
1.289 raeburn 5556: cc => ['yes','no'],
1.286 raeburn 5557: course => ['yes','no'],
5558: section => ['yes','no'],
5559: screenshot => ['yes','no'],
5560: );
5561: my %fieldoptions = &Apache::lonlocal::texthash (
5562: 'yes' => 'Optional',
5563: 'req' => 'Required',
5564: 'no' => "Not shown",
5565: );
5566: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5567: }
5568:
1.72 raeburn 5569: sub tool_titles {
5570: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 5571: aboutme => 'Personal web page',
1.86 raeburn 5572: blog => 'Blog',
1.162 raeburn 5573: webdav => 'WebDAV',
1.86 raeburn 5574: portfolio => 'Portfolio',
1.88 bisitz 5575: official => 'Official courses (with institutional codes)',
5576: unofficial => 'Unofficial courses',
1.98 raeburn 5577: community => 'Communities',
1.216 raeburn 5578: textbook => 'Textbook courses',
1.271 raeburn 5579: placement => 'Placement tests',
1.86 raeburn 5580: );
1.72 raeburn 5581: return %titles;
5582: }
5583:
1.101 raeburn 5584: sub courserequest_titles {
5585: my %titles = &Apache::lonlocal::texthash (
5586: official => 'Official',
5587: unofficial => 'Unofficial',
5588: community => 'Communities',
1.216 raeburn 5589: textbook => 'Textbook',
1.271 raeburn 5590: placement => 'Placement tests',
1.101 raeburn 5591: norequest => 'Not allowed',
1.104 raeburn 5592: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5593: validate => 'With validation',
5594: autolimit => 'Numerical limit',
1.103 raeburn 5595: unlimited => '(blank for unlimited)',
1.101 raeburn 5596: );
5597: return %titles;
5598: }
5599:
1.163 raeburn 5600: sub authorrequest_titles {
5601: my %titles = &Apache::lonlocal::texthash (
5602: norequest => 'Not allowed',
5603: approval => 'Approval by Dom. Coord.',
5604: automatic => 'Automatic approval',
5605: );
5606: return %titles;
1.210 raeburn 5607: }
1.163 raeburn 5608:
1.101 raeburn 5609: sub courserequest_conditions {
5610: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5611: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 5612: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5613: );
5614: return %conditions;
5615: }
5616:
5617:
1.27 raeburn 5618: sub print_usercreation {
1.30 raeburn 5619: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5620: my $numinrow = 4;
1.28 raeburn 5621: my $datatable;
5622: if ($position eq 'top') {
1.30 raeburn 5623: $$rowtotal ++;
1.34 raeburn 5624: my $rowcount = 0;
1.32 raeburn 5625: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5626: if (ref($rules) eq 'HASH') {
5627: if (keys(%{$rules}) > 0) {
1.32 raeburn 5628: $datatable .= &user_formats_row('username',$settings,$rules,
5629: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5630: $$rowtotal ++;
1.32 raeburn 5631: $rowcount ++;
5632: }
5633: }
5634: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5635: if (ref($idrules) eq 'HASH') {
5636: if (keys(%{$idrules}) > 0) {
5637: $datatable .= &user_formats_row('id',$settings,$idrules,
5638: $idruleorder,$numinrow,$rowcount);
5639: $$rowtotal ++;
5640: $rowcount ++;
1.28 raeburn 5641: }
5642: }
1.39 raeburn 5643: if ($rowcount == 0) {
5644: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5645: $$rowtotal ++;
5646: $rowcount ++;
5647: }
1.34 raeburn 5648: } elsif ($position eq 'middle') {
1.224 raeburn 5649: my @creators = ('author','course','requestcrs');
1.37 raeburn 5650: my ($rules,$ruleorder) =
5651: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5652: my %lt = &usercreation_types();
5653: my %checked;
5654: if (ref($settings) eq 'HASH') {
5655: if (ref($settings->{'cancreate'}) eq 'HASH') {
5656: foreach my $item (@creators) {
5657: $checked{$item} = $settings->{'cancreate'}{$item};
5658: }
5659: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5660: foreach my $item (@creators) {
5661: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5662: $checked{$item} = 'none';
5663: }
5664: }
5665: }
5666: }
5667: my $rownum = 0;
5668: foreach my $item (@creators) {
5669: $rownum ++;
1.224 raeburn 5670: if ($checked{$item} eq '') {
5671: $checked{$item} = 'any';
1.34 raeburn 5672: }
5673: my $css_class;
5674: if ($rownum%2) {
5675: $css_class = '';
5676: } else {
5677: $css_class = ' class="LC_odd_row" ';
5678: }
5679: $datatable .= '<tr'.$css_class.'>'.
5680: '<td><span class="LC_nobreak">'.$lt{$item}.
5681: '</span></td><td align="right">';
1.224 raeburn 5682: my @options = ('any');
5683: if (ref($rules) eq 'HASH') {
5684: if (keys(%{$rules}) > 0) {
5685: push(@options,('official','unofficial'));
1.37 raeburn 5686: }
5687: }
1.224 raeburn 5688: push(@options,'none');
1.37 raeburn 5689: foreach my $option (@options) {
1.50 raeburn 5690: my $type = 'radio';
1.34 raeburn 5691: my $check = ' ';
1.224 raeburn 5692: if ($checked{$item} eq $option) {
5693: $check = ' checked="checked" ';
1.34 raeburn 5694: }
5695: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5696: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5697: $item.'" value="'.$option.'"'.$check.'/> '.
5698: $lt{$option}.'</label> </span>';
5699: }
5700: $datatable .= '</td></tr>';
5701: }
1.28 raeburn 5702: } else {
5703: my @contexts = ('author','course','domain');
5704: my @authtypes = ('int','krb4','krb5','loc');
5705: my %checked;
5706: if (ref($settings) eq 'HASH') {
5707: if (ref($settings->{'authtypes'}) eq 'HASH') {
5708: foreach my $item (@contexts) {
5709: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5710: foreach my $auth (@authtypes) {
5711: if ($settings->{'authtypes'}{$item}{$auth}) {
5712: $checked{$item}{$auth} = ' checked="checked" ';
5713: }
5714: }
5715: }
5716: }
1.27 raeburn 5717: }
1.35 raeburn 5718: } else {
5719: foreach my $item (@contexts) {
1.36 raeburn 5720: foreach my $auth (@authtypes) {
1.35 raeburn 5721: $checked{$item}{$auth} = ' checked="checked" ';
5722: }
5723: }
1.27 raeburn 5724: }
1.28 raeburn 5725: my %title = &context_names();
5726: my %authname = &authtype_names();
5727: my $rownum = 0;
5728: my $css_class;
5729: foreach my $item (@contexts) {
5730: if ($rownum%2) {
5731: $css_class = '';
5732: } else {
5733: $css_class = ' class="LC_odd_row" ';
5734: }
1.30 raeburn 5735: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5736: '<td>'.$title{$item}.
5737: '</td><td class="LC_left_item">'.
5738: '<span class="LC_nobreak">';
5739: foreach my $auth (@authtypes) {
5740: $datatable .= '<label>'.
5741: '<input type="checkbox" name="'.$item.'_auth" '.
5742: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5743: $authname{$auth}.'</label> ';
5744: }
5745: $datatable .= '</span></td></tr>';
5746: $rownum ++;
1.27 raeburn 5747: }
1.30 raeburn 5748: $$rowtotal += $rownum;
1.27 raeburn 5749: }
5750: return $datatable;
5751: }
5752:
1.224 raeburn 5753: sub print_selfcreation {
5754: my ($position,$dom,$settings,$rowtotal) = @_;
1.303 ! raeburn 5755: my (@selfcreate,$createsettings,$processing,$emailverified,$emaildomain,$datatable);
1.224 raeburn 5756: if (ref($settings) eq 'HASH') {
5757: if (ref($settings->{'cancreate'}) eq 'HASH') {
5758: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5759: if (ref($createsettings) eq 'HASH') {
5760: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5761: @selfcreate = @{$createsettings->{'selfcreate'}};
5762: } elsif ($createsettings->{'selfcreate'} ne '') {
5763: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5764: @selfcreate = ('email','login','sso');
5765: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5766: @selfcreate = ($createsettings->{'selfcreate'});
5767: }
5768: }
5769: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5770: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5771: }
1.303 ! raeburn 5772: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
! 5773: $emailverified = $createsettings->{'emailverified'};
! 5774: }
! 5775: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
! 5776: $emaildomain = $createsettings->{'emaildomain'};
! 5777: }
1.224 raeburn 5778: }
5779: }
5780: }
5781: my %radiohash;
5782: my $numinrow = 4;
5783: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 5784: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 5785: if ($position eq 'top') {
5786: my %choices = &Apache::lonlocal::texthash (
5787: cancreate_login => 'Institutional Login',
5788: cancreate_sso => 'Institutional Single Sign On',
5789: );
5790: my @toggles = sort(keys(%choices));
5791: my %defaultchecked = (
5792: 'cancreate_login' => 'off',
5793: 'cancreate_sso' => 'off',
5794: );
1.228 raeburn 5795: my ($onclick,$itemcount);
1.224 raeburn 5796: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5797: \%choices,$itemcount,$onclick);
1.228 raeburn 5798: $$rowtotal += $itemcount;
5799:
1.224 raeburn 5800: if (ref($usertypes) eq 'HASH') {
5801: if (keys(%{$usertypes}) > 0) {
5802: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5803: $dom,$numinrow,$othertitle,
1.228 raeburn 5804: 'statustocreate',$$rowtotal);
1.224 raeburn 5805: $$rowtotal ++;
5806: }
5807: }
1.240 raeburn 5808: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5809: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5810: $fieldtitles{'inststatus'} = &mt('Institutional status');
5811: my $rem;
5812: my $numperrow = 2;
5813: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5814: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5815: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5816: '<td class="LC_left_item">'."\n".
5817: '<table><tr><td>'."\n";
5818: for (my $i=0; $i<@fields; $i++) {
5819: $rem = $i%($numperrow);
5820: if ($rem == 0) {
5821: if ($i > 0) {
5822: $datatable .= '</tr>';
5823: }
5824: $datatable .= '<tr>';
5825: }
5826: my $currval;
1.248 raeburn 5827: if (ref($createsettings) eq 'HASH') {
5828: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5829: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5830: }
1.240 raeburn 5831: }
5832: $datatable .= '<td class="LC_left_item">'.
5833: '<span class="LC_nobreak">'.
5834: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5835: 'value="'.$currval.'" size="10" /> '.
5836: $fieldtitles{$fields[$i]}.'</span></td>';
5837: }
5838: my $colsleft = $numperrow - $rem;
5839: if ($colsleft > 1 ) {
5840: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5841: ' </td>';
5842: } elsif ($colsleft == 1) {
5843: $datatable .= '<td class="LC_left_item"> </td>';
5844: }
5845: $datatable .= '</tr></table></td></tr>';
5846: $$rowtotal ++;
1.224 raeburn 5847: } elsif ($position eq 'middle') {
5848: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 5849: my @posstypes;
1.224 raeburn 5850: if (ref($types) eq 'ARRAY') {
1.302 raeburn 5851: @posstypes = @{$types};
5852: }
5853: unless (grep(/^default$/,@posstypes)) {
5854: push(@posstypes,'default');
5855: }
5856: my %usertypeshash;
5857: if (ref($usertypes) eq 'HASH') {
5858: %usertypeshash = %{$usertypes};
5859: }
5860: $usertypeshash{'default'} = $othertitle;
5861: foreach my $status (@posstypes) {
5862: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5863: $numinrow,$$rowtotal,\%usertypeshash);
5864: $$rowtotal ++;
1.224 raeburn 5865: }
5866: } else {
1.236 raeburn 5867: my %choices = &Apache::lonlocal::texthash (
1.303 ! raeburn 5868: cancreate_email => 'Non-institutional username (e-mail verification)',
1.236 raeburn 5869: );
5870: my @toggles = sort(keys(%choices));
5871: my %defaultchecked = (
5872: 'cancreate_email' => 'off',
5873: );
5874: my $itemcount = 0;
5875: my $display = 'none';
5876: if (grep(/^\Qemail\E$/,@selfcreate)) {
5877: $display = 'block';
5878: }
5879: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5880: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5881: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.302 raeburn 5882: my $order;
5883: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
1.236 raeburn 5884: $order = $domdefaults{'inststatusguest'};
5885: }
1.302 raeburn 5886: my (@ordered,%usertypeshash);
1.236 raeburn 5887: if (ref($order) eq 'ARRAY') {
1.302 raeburn 5888: @ordered = @{$order};
5889: }
5890: if (@ordered) {
5891: unless (grep(/^default$/,@ordered)) {
5892: push(@ordered,'default');
5893: }
5894: if (ref($usertypes) eq 'HASH') {
5895: %usertypeshash = %{$usertypes};
5896: }
5897: $usertypeshash{'default'} = $othertitle;
5898: $additional .= '<table><tr>';
5899: foreach my $status (@ordered) {
1.303 ! raeburn 5900: $additional .= '<th align="center">'.$usertypeshash{$status}.'</th>';
! 5901: }
! 5902: $additional .= '</tr><tr>';
! 5903: foreach my $status (@ordered) {
! 5904: $additional .= '<td align="left" valign="top">'.&validate_by_email($rowtotal,$processing,$status).'</td>';
! 5905: }
! 5906: $additional .= '</tr></table><br />'.
! 5907: '<table><tr>';
! 5908: foreach my $status (@ordered) {
! 5909: $additional .= '<th align="center">'.$usertypeshash{$status}.'</th>';
1.302 raeburn 5910: }
5911: $additional .= '</tr><tr>';
5912: foreach my $status (@ordered) {
1.303 ! raeburn 5913: $additional .= '<td align="left" valign="top">'.&email_as_username($rowtotal,$emailverified,$emaildomain,$status).'</td>';
1.224 raeburn 5914: }
1.302 raeburn 5915: $additional .= '</tr></table>';
1.303 ! raeburn 5916:
1.302 raeburn 5917: } else {
5918: $usertypeshash{'default'} = $othertitle;
1.303 ! raeburn 5919: $additional .= &mt('Approval:').' '.&validate_by_email($rowtotal,$processing).'<br />'.
! 5920: &mt('Username:').' '.&email_as_username($rowtotal,$emailverified,$emaildomain);
1.224 raeburn 5921: }
1.236 raeburn 5922: $additional .= '</div>'."\n";
5923:
5924: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5925: \%choices,$$rowtotal,$onclick,$additional);
5926: $$rowtotal ++;
1.236 raeburn 5927: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5928: $$rowtotal ++;
1.224 raeburn 5929: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5930: $numinrow = 1;
1.302 raeburn 5931: foreach my $status (@ordered) {
5932: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5933: $numinrow,$$rowtotal,\%usertypeshash,$infofields,$infotitles);
5934: $$rowtotal ++;
1.228 raeburn 5935: }
1.224 raeburn 5936: my ($emailrules,$emailruleorder) =
5937: &Apache::lonnet::inst_userrules($dom,'email');
5938: if (ref($emailrules) eq 'HASH') {
5939: if (keys(%{$emailrules}) > 0) {
5940: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5941: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5942: $$rowtotal ++;
5943: }
5944: }
1.228 raeburn 5945: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5946: }
5947: return $datatable;
5948: }
5949:
1.303 ! raeburn 5950: sub validate_by_email {
1.236 raeburn 5951: my ($rowtotal,$processing,$type) = @_;
5952: my %choices =
5953: &Apache::lonlocal::texthash (
5954: automatic => 'Automatic approval',
5955: approval => 'Queued for approval',
1.303 ! raeburn 5956: notinuse => 'Unavailable',
1.236 raeburn 5957: );
5958: my $output;
1.303 ! raeburn 5959: my @options = ('automatic','approval');
! 5960: unless ($type eq '') {
! 5961: push(@options,'notinuse');
! 5962: }
! 5963: foreach my $option (@options) {
1.236 raeburn 5964: my $checked;
5965: if (ref($processing) eq 'HASH') {
5966: if ($type eq '') {
5967: if (!exists($processing->{'default'})) {
5968: if ($option eq 'automatic') {
5969: $checked = ' checked="checked"';
5970: }
5971: } else {
5972: if ($processing->{'default'} eq $option) {
5973: $checked = ' checked="checked"';
5974: }
5975: }
5976: } else {
5977: if (!exists($processing->{$type})) {
5978: if ($option eq 'automatic') {
5979: $checked = ' checked="checked"';
5980: }
5981: } else {
5982: if ($processing->{$type} eq $option) {
5983: $checked = ' checked="checked"';
5984: }
5985: }
5986: }
5987: } elsif ($option eq 'automatic') {
5988: $checked = ' checked="checked"';
5989: }
5990: my $name = 'cancreate_emailprocess';
5991: if (($type ne '') && ($type ne 'default')) {
5992: $name .= '_'.$type;
5993: }
5994: $output .= '<span class="LC_nobreak"><label>'.
5995: '<input type="radio" name="'.$name.'"'.
5996: $checked.' value="'.$option.'" />'.
5997: $choices{$option}.'</label></span>';
5998: if ($type eq '') {
5999: $output .= ' ';
6000: } else {
6001: $output .= '<br />';
6002: }
6003: }
6004: $$rowtotal ++;
6005: return $output;
6006: }
6007:
1.303 ! raeburn 6008: sub email_as_username {
! 6009: my ($rowtotal,$emailverified,$emaildomain,$type) = @_;
! 6010: my %choices =
! 6011: &Apache::lonlocal::texthash (
! 6012: email => 'Username is e-mail',
! 6013: other => 'Username is chosen',
! 6014: );
! 6015: my $name = 'cancreate_emailverified';
! 6016: my $condition = 'cancreate_emaildomain';
! 6017: if (($type ne '') && ($type ne 'default')) {
! 6018: $name .= '_'.$type;
! 6019: $condition .= '_'.$type;
! 6020: }
! 6021: my $display = 'none';
! 6022: my $onclick = "toggleDisplay(this.form,'$name');";
! 6023:
! 6024: my $output;
! 6025: foreach my $option ('email','other') {
! 6026: my ($checked,$domain);
! 6027: if (ref($emailverified) eq 'HASH') {
! 6028: if ($type eq '') {
! 6029: if (!exists($emailverified->{'default'})) {
! 6030: if ($option eq 'email') {
! 6031: $checked = ' checked="checked"';
! 6032: }
! 6033: } else {
! 6034: if ($emailverified->{'default'} eq $option) {
! 6035: $checked = ' checked="checked"';
! 6036: }
! 6037: }
! 6038: } else {
! 6039: if (!exists($emailverified->{$type})) {
! 6040: if ($option eq 'email') {
! 6041: $checked = ' checked="checked"';
! 6042: }
! 6043: } else {
! 6044: if ($emailverified->{$type} eq $option) {
! 6045: $checked = ' checked="checked"';
! 6046: if ($option eq 'other') {
! 6047: $display = 'inline';
! 6048: }
! 6049: }
! 6050: }
! 6051: }
! 6052: } elsif ($option eq 'email') {
! 6053: $checked = ' checked="checked"';
! 6054: }
! 6055: $output .= '<span class="LC_nobreak"><label>'.
! 6056: '<input type="radio" name="'.$name.'"'.
! 6057: $checked.' value="'.$option.'" onclick="'.$onclick.'" />'.
! 6058: $choices{$option}.'</label></span>';
! 6059: if ($type eq '') {
! 6060: $output .= ' ';
! 6061: } else {
! 6062: $output .= '<br />';
! 6063: }
! 6064: }
! 6065: my $domain;
! 6066: if (ref($emaildomain) eq 'HASH') {
! 6067: if ($type eq '') {
! 6068: if (exists($emaildomain->{'default'})) {
! 6069: $domain = $emaildomain->{'default'};
! 6070: }
! 6071: } else {
! 6072: if (exists($emaildomain->{$type})) {
! 6073: $domain = $emaildomain->{$type};
! 6074: }
! 6075: }
! 6076: }
! 6077: $output .= '<div id="'.$name.'" style="display: '.$display.';">'.
! 6078: '<span class="LC_domprefs_email">'.&mt('E-mail domain').'</span> '.
! 6079: '<input type="text" name="'.$condition.'" value="'.$domain.'" size="10" />'.
! 6080: '</div>';
! 6081: $$rowtotal ++;
! 6082: return $output;
! 6083: }
! 6084:
1.165 raeburn 6085: sub captcha_choice {
1.169 raeburn 6086: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 6087: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
6088: $vertext,$currver);
1.165 raeburn 6089: my %lt = &captcha_phrases();
6090: $keyentry = 'hidden';
6091: if ($context eq 'cancreate') {
1.224 raeburn 6092: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 6093: } elsif ($context eq 'login') {
6094: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 6095: }
6096: if (ref($settings) eq 'HASH') {
6097: if ($settings->{'captcha'}) {
6098: $checked{$settings->{'captcha'}} = ' checked="checked"';
6099: } else {
6100: $checked{'original'} = ' checked="checked"';
6101: }
6102: if ($settings->{'captcha'} eq 'recaptcha') {
6103: $pubtext = $lt{'pub'};
6104: $privtext = $lt{'priv'};
6105: $keyentry = 'text';
1.269 raeburn 6106: $vertext = $lt{'ver'};
6107: $currver = $settings->{'recaptchaversion'};
6108: if ($currver ne '2') {
6109: $currver = 1;
6110: }
1.165 raeburn 6111: }
6112: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
6113: $currpub = $settings->{'recaptchakeys'}{'public'};
6114: $currpriv = $settings->{'recaptchakeys'}{'private'};
6115: }
6116: } else {
6117: $checked{'original'} = ' checked="checked"';
6118: }
1.169 raeburn 6119: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
6120: my $output = '<tr'.$css_class.'>'.
6121: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 6122: '<table><tr><td>'."\n";
6123: foreach my $option ('original','recaptcha','notused') {
6124: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
6125: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
6126: $lt{$option}.'</label></span>';
6127: unless ($option eq 'notused') {
6128: $output .= (' 'x2)."\n";
6129: }
6130: }
6131: #
6132: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6133: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 6134: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 6135: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 6136: #
1.165 raeburn 6137: $output .= '</td></tr>'."\n".
6138: '<tr><td>'."\n".
6139: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6140: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6141: $currpub.'" size="40" /></span><br />'."\n".
6142: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6143: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 6144: $currpriv.'" size="40" /></span><br />'.
6145: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6146: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6147: $currver.'" size="3" /></span><br />'.
6148: '</td></tr></table>'."\n".
1.165 raeburn 6149: '</td></tr>';
6150: return $output;
6151: }
6152:
1.32 raeburn 6153: sub user_formats_row {
6154: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
6155: my $output;
6156: my %text = (
6157: 'username' => 'new usernames',
6158: 'id' => 'IDs',
1.45 raeburn 6159: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 6160: );
6161: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6162: $output = '<tr '.$css_class.'>'.
1.63 raeburn 6163: '<td><span class="LC_nobreak">';
6164: if ($type eq 'email') {
6165: $output .= &mt("Formats disallowed for $text{$type}: ");
6166: } else {
6167: $output .= &mt("Format rules to check for $text{$type}: ");
6168: }
6169: $output .= '</span></td>'.
6170: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 6171: my $rem;
6172: if (ref($ruleorder) eq 'ARRAY') {
6173: for (my $i=0; $i<@{$ruleorder}; $i++) {
6174: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6175: my $rem = $i%($numinrow);
6176: if ($rem == 0) {
6177: if ($i > 0) {
6178: $output .= '</tr>';
6179: }
6180: $output .= '<tr>';
6181: }
6182: my $check = ' ';
1.39 raeburn 6183: if (ref($settings) eq 'HASH') {
6184: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6185: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6186: $check = ' checked="checked" ';
6187: }
1.27 raeburn 6188: }
6189: }
6190: $output .= '<td class="LC_left_item">'.
6191: '<span class="LC_nobreak"><label>'.
1.32 raeburn 6192: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 6193: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6194: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6195: }
6196: }
6197: $rem = @{$ruleorder}%($numinrow);
6198: }
6199: my $colsleft = $numinrow - $rem;
6200: if ($colsleft > 1 ) {
6201: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6202: ' </td>';
6203: } elsif ($colsleft == 1) {
6204: $output .= '<td class="LC_left_item"> </td>';
6205: }
6206: $output .= '</tr></table></td></tr>';
6207: return $output;
6208: }
6209:
1.34 raeburn 6210: sub usercreation_types {
6211: my %lt = &Apache::lonlocal::texthash (
6212: author => 'When adding a co-author',
6213: course => 'When adding a user to a course',
1.100 raeburn 6214: requestcrs => 'When requesting a course',
1.34 raeburn 6215: any => 'Any',
6216: official => 'Institutional only ',
6217: unofficial => 'Non-institutional only',
6218: none => 'None',
6219: );
6220: return %lt;
1.48 raeburn 6221: }
1.34 raeburn 6222:
1.224 raeburn 6223: sub selfcreation_types {
6224: my %lt = &Apache::lonlocal::texthash (
6225: selfcreate => 'User creates own account',
6226: any => 'Any',
6227: official => 'Institutional only ',
6228: unofficial => 'Non-institutional only',
6229: email => 'E-mail address',
6230: login => 'Institutional Login',
6231: sso => 'SSO',
6232: );
6233: }
6234:
1.28 raeburn 6235: sub authtype_names {
6236: my %lt = &Apache::lonlocal::texthash(
6237: int => 'Internal',
6238: krb4 => 'Kerberos 4',
6239: krb5 => 'Kerberos 5',
6240: loc => 'Local',
6241: );
6242: return %lt;
6243: }
6244:
6245: sub context_names {
6246: my %context_title = &Apache::lonlocal::texthash(
6247: author => 'Creating users when an Author',
6248: course => 'Creating users when in a course',
6249: domain => 'Creating users when a Domain Coordinator',
6250: );
6251: return %context_title;
6252: }
6253:
1.33 raeburn 6254: sub print_usermodification {
6255: my ($position,$dom,$settings,$rowtotal) = @_;
6256: my $numinrow = 4;
6257: my ($context,$datatable,$rowcount);
6258: if ($position eq 'top') {
6259: $rowcount = 0;
6260: $context = 'author';
6261: foreach my $role ('ca','aa') {
6262: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6263: $numinrow,$rowcount);
6264: $$rowtotal ++;
6265: $rowcount ++;
6266: }
1.230 raeburn 6267: } elsif ($position eq 'bottom') {
1.33 raeburn 6268: $context = 'course';
6269: $rowcount = 0;
6270: foreach my $role ('st','ep','ta','in','cr') {
6271: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6272: $numinrow,$rowcount);
6273: $$rowtotal ++;
6274: $rowcount ++;
6275: }
6276: }
6277: return $datatable;
6278: }
6279:
1.43 raeburn 6280: sub print_defaults {
1.236 raeburn 6281: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6282: my $rownum = 0;
1.294 raeburn 6283: my ($datatable,$css_class,$titles);
6284: unless ($position eq 'bottom') {
6285: $titles = &defaults_titles($dom);
6286: }
1.236 raeburn 6287: if ($position eq 'top') {
6288: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6289: 'datelocale_def','portal_def');
6290: my %defaults;
6291: if (ref($settings) eq 'HASH') {
6292: %defaults = %{$settings};
1.43 raeburn 6293: } else {
1.236 raeburn 6294: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6295: foreach my $item (@items) {
6296: $defaults{$item} = $domdefaults{$item};
6297: }
1.43 raeburn 6298: }
1.236 raeburn 6299: foreach my $item (@items) {
6300: if ($rownum%2) {
6301: $css_class = '';
6302: } else {
6303: $css_class = ' class="LC_odd_row" ';
6304: }
6305: $datatable .= '<tr'.$css_class.'>'.
6306: '<td><span class="LC_nobreak">'.$titles->{$item}.
6307: '</span></td><td class="LC_right_item" colspan="3">';
6308: if ($item eq 'auth_def') {
6309: my @authtypes = ('internal','krb4','krb5','localauth');
6310: my %shortauth = (
6311: internal => 'int',
6312: krb4 => 'krb4',
6313: krb5 => 'krb5',
6314: localauth => 'loc'
6315: );
6316: my %authnames = &authtype_names();
6317: foreach my $auth (@authtypes) {
6318: my $checked = ' ';
6319: if ($defaults{$item} eq $auth) {
6320: $checked = ' checked="checked" ';
6321: }
6322: $datatable .= '<label><input type="radio" name="'.$item.
6323: '" value="'.$auth.'"'.$checked.'/>'.
6324: $authnames{$shortauth{$auth}}.'</label> ';
6325: }
6326: } elsif ($item eq 'timezone_def') {
6327: my $includeempty = 1;
6328: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6329: } elsif ($item eq 'datelocale_def') {
6330: my $includeempty = 1;
6331: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6332: } elsif ($item eq 'lang_def') {
1.263 raeburn 6333: my $includeempty = 1;
6334: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 6335: } else {
6336: my $size;
6337: if ($item eq 'portal_def') {
6338: $size = ' size="25"';
6339: }
6340: $datatable .= '<input type="text" name="'.$item.'" value="'.
6341: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 6342: }
1.236 raeburn 6343: $datatable .= '</td></tr>';
6344: $rownum ++;
6345: }
1.294 raeburn 6346: } elsif ($position eq 'middle') {
6347: my @items = ('intauth_cost','intauth_check','intauth_switch');
6348: my %defaults;
6349: if (ref($settings) eq 'HASH') {
6350: %defaults = %{$settings};
6351: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6352: $defaults{'intauth_cost'} = 10;
6353: }
6354: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6355: $defaults{'intauth_check'} = 0;
6356: }
6357: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6358: $defaults{'intauth_switch'} = 0;
6359: }
6360: } else {
6361: %defaults = (
6362: 'intauth_cost' => 10,
6363: 'intauth_check' => 0,
6364: 'intauth_switch' => 0,
6365: );
6366: }
6367: foreach my $item (@items) {
6368: if ($rownum%2) {
6369: $css_class = '';
6370: } else {
6371: $css_class = ' class="LC_odd_row" ';
6372: }
6373: $datatable .= '<tr'.$css_class.'>'.
6374: '<td><span class="LC_nobreak">'.$titles->{$item}.
6375: '</span></td><td class="LC_left_item" colspan="3">';
6376: if ($item eq 'intauth_switch') {
6377: my @options = (0,1,2);
6378: my %optiondesc = &Apache::lonlocal::texthash (
6379: 0 => 'No',
6380: 1 => 'Yes',
6381: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6382: );
6383: $datatable .= '<table width="100%">';
6384: foreach my $option (@options) {
6385: my $checked = ' ';
6386: if ($defaults{$item} eq $option) {
6387: $checked = ' checked="checked"';
6388: }
6389: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6390: '<label><input type="radio" name="'.$item.
6391: '" value="'.$option.'"'.$checked.' />'.
6392: $optiondesc{$option}.'</label></span></td></tr>';
6393: }
6394: $datatable .= '</table>';
6395: } elsif ($item eq 'intauth_check') {
6396: my @options = (0,1,2);
6397: my %optiondesc = &Apache::lonlocal::texthash (
6398: 0 => 'No',
6399: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6400: 2 => 'Yes, disallow login if stored cost is less than domain default',
6401: );
6402: $datatable .= '<table wisth="100%">';
6403: foreach my $option (@options) {
6404: my $checked = ' ';
6405: my $onclick;
6406: if ($defaults{$item} eq $option) {
6407: $checked = ' checked="checked"';
6408: }
6409: if ($option == 2) {
6410: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6411: }
6412: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6413: '<label><input type="radio" name="'.$item.
6414: '" value="'.$option.'"'.$checked.$onclick.' />'.
6415: $optiondesc{$option}.'</label></span></td></tr>';
6416: }
6417: $datatable .= '</table>';
6418: } else {
6419: $datatable .= '<input type="text" name="'.$item.'" value="'.
6420: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6421: }
6422: $datatable .= '</td></tr>';
6423: $rownum ++;
6424: }
1.236 raeburn 6425: } else {
1.294 raeburn 6426: my %defaults;
1.236 raeburn 6427: if (ref($settings) eq 'HASH') {
6428: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
6429: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
6430: my $maxnum = @{$settings->{'inststatusorder'}};
6431: for (my $i=0; $i<$maxnum; $i++) {
6432: $css_class = $rownum%2?' class="LC_odd_row"':'';
6433: my $item = $settings->{'inststatusorder'}->[$i];
6434: my $title = $settings->{'inststatustypes'}->{$item};
6435: my $guestok;
6436: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
6437: $guestok = 1;
6438: }
6439: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6440: $datatable .= '<tr'.$css_class.'>'.
6441: '<td><span class="LC_nobreak">'.
6442: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6443: for (my $k=0; $k<=$maxnum; $k++) {
6444: my $vpos = $k+1;
6445: my $selstr;
6446: if ($k == $i) {
6447: $selstr = ' selected="selected" ';
6448: }
6449: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6450: }
6451: my ($checkedon,$checkedoff);
6452: $checkedoff = ' checked="checked"';
6453: if ($guestok) {
6454: $checkedon = $checkedoff;
6455: $checkedoff = '';
6456: }
6457: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6458: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6459: &mt('delete').'</span></td>'.
6460: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6461: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
6462: '</span></td>'.
6463: '<td class="LC_right_item"><span class="LC_nobreak">'.
6464: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
6465: &mt('Yes').'</label>'.(' 'x2).
6466: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
6467: &mt('No').'</label></span></td></tr>';
6468: }
6469: $css_class = $rownum%2?' class="LC_odd_row"':'';
6470: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6471: $datatable .= '<tr '.$css_class.'>'.
6472: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6473: for (my $k=0; $k<=$maxnum; $k++) {
6474: my $vpos = $k+1;
6475: my $selstr;
6476: if ($k == $maxnum) {
6477: $selstr = ' selected="selected" ';
6478: }
6479: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6480: }
6481: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 6482: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 6483: ' '.&mt('(new)').
6484: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6485: &mt('Name displayed:').
6486: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6487: '<td class="LC_right_item"><span class="LC_nobreak">'.
6488: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
6489: &mt('Yes').'</label>'.(' 'x2).
6490: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
6491: &mt('No').'</label></span></td></tr>';
6492: '</tr>'."\n";
6493: $rownum ++;
1.141 raeburn 6494: }
1.43 raeburn 6495: }
6496: }
6497: $$rowtotal += $rownum;
6498: return $datatable;
6499: }
6500:
1.168 raeburn 6501: sub get_languages_hash {
6502: my %langchoices;
6503: foreach my $id (&Apache::loncommon::languageids()) {
6504: my $code = &Apache::loncommon::supportedlanguagecode($id);
6505: if ($code ne '') {
6506: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6507: }
6508: }
6509: return %langchoices;
6510: }
6511:
1.43 raeburn 6512: sub defaults_titles {
1.141 raeburn 6513: my ($dom) = @_;
1.43 raeburn 6514: my %titles = &Apache::lonlocal::texthash (
6515: 'auth_def' => 'Default authentication type',
6516: 'auth_arg_def' => 'Default authentication argument',
6517: 'lang_def' => 'Default language',
1.54 raeburn 6518: 'timezone_def' => 'Default timezone',
1.68 raeburn 6519: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6520: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 6521: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6522: 'intauth_check' => 'Check bcrypt cost if authenticated',
6523: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6524: );
1.141 raeburn 6525: if ($dom) {
6526: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6527: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6528: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6529: $protocol = 'http' if ($protocol ne 'https');
6530: if ($uint_dom) {
6531: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6532: $uint_dom);
6533: }
6534: }
1.43 raeburn 6535: return (\%titles);
6536: }
6537:
1.46 raeburn 6538: sub print_scantronformat {
6539: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6540: my $itemcount = 1;
1.60 raeburn 6541: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6542: %confhash);
1.46 raeburn 6543: my $switchserver = &check_switchserver($dom,$confname);
6544: my %lt = &Apache::lonlocal::texthash (
1.95 www 6545: default => 'Default bubblesheet format file error',
6546: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6547: );
6548: my %scantronfiles = (
6549: default => 'default.tab',
6550: custom => 'custom.tab',
6551: );
6552: foreach my $key (keys(%scantronfiles)) {
6553: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6554: .$scantronfiles{$key};
6555: }
6556: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6557: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6558: if (!$switchserver) {
6559: my $servadm = $r->dir_config('lonAdmEMail');
6560: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6561: if ($configuserok eq 'ok') {
6562: if ($author_ok eq 'ok') {
6563: my %legacyfile = (
6564: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6565: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6566: );
6567: my %md5chk;
6568: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6569: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6570: chomp($md5chk{$type});
1.46 raeburn 6571: }
6572: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6573: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6574: ($scantronurls{$type},my $error) =
1.46 raeburn 6575: &legacy_scantronformat($r,$dom,$confname,
6576: $type,$legacyfile{$type},
6577: $scantronurls{$type},
6578: $scantronfiles{$type});
1.60 raeburn 6579: if ($error ne '') {
6580: $error{$type} = $error;
6581: }
6582: }
6583: if (keys(%error) == 0) {
6584: $is_custom = 1;
6585: $confhash{'scantron'}{'scantronformat'} =
6586: $scantronurls{'custom'};
6587: my $putresult =
6588: &Apache::lonnet::put_dom('configuration',
6589: \%confhash,$dom);
6590: if ($putresult ne 'ok') {
6591: $error{'custom'} =
6592: '<span class="LC_error">'.
6593: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6594: }
1.46 raeburn 6595: }
6596: } else {
1.60 raeburn 6597: ($scantronurls{'default'},my $error) =
1.46 raeburn 6598: &legacy_scantronformat($r,$dom,$confname,
6599: 'default',$legacyfile{'default'},
6600: $scantronurls{'default'},
6601: $scantronfiles{'default'});
1.60 raeburn 6602: if ($error eq '') {
6603: $confhash{'scantron'}{'scantronformat'} = '';
6604: my $putresult =
6605: &Apache::lonnet::put_dom('configuration',
6606: \%confhash,$dom);
6607: if ($putresult ne 'ok') {
6608: $error{'default'} =
6609: '<span class="LC_error">'.
6610: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6611: }
6612: } else {
6613: $error{'default'} = $error;
6614: }
1.46 raeburn 6615: }
6616: }
6617: }
6618: } else {
1.95 www 6619: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6620: }
6621: }
6622: if (ref($settings) eq 'HASH') {
6623: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6624: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6625: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6626: $scantronurl = '';
6627: } else {
6628: $scantronurl = $settings->{'scantronformat'};
6629: }
6630: $is_custom = 1;
6631: } else {
6632: $scantronurl = $scantronurls{'default'};
6633: }
6634: } else {
1.60 raeburn 6635: if ($is_custom) {
6636: $scantronurl = $scantronurls{'custom'};
6637: } else {
6638: $scantronurl = $scantronurls{'default'};
6639: }
1.46 raeburn 6640: }
6641: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6642: $datatable .= '<tr'.$css_class.'>';
6643: if (!$is_custom) {
1.65 raeburn 6644: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6645: '<span class="LC_nobreak">';
1.46 raeburn 6646: if ($scantronurl) {
1.199 raeburn 6647: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6648: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6649: } else {
6650: $datatable = &mt('File unavailable for display');
6651: }
1.65 raeburn 6652: $datatable .= '</span></td>';
1.60 raeburn 6653: if (keys(%error) == 0) {
6654: $datatable .= '<td valign="bottom">';
6655: if (!$switchserver) {
6656: $datatable .= &mt('Upload:').'<br />';
6657: }
6658: } else {
6659: my $errorstr;
6660: foreach my $key (sort(keys(%error))) {
6661: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6662: }
6663: $datatable .= '<td>'.$errorstr;
6664: }
1.46 raeburn 6665: } else {
6666: if (keys(%error) > 0) {
6667: my $errorstr;
6668: foreach my $key (sort(keys(%error))) {
6669: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6670: }
1.60 raeburn 6671: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6672: } elsif ($scantronurl) {
1.199 raeburn 6673: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
6674: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6675: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 6676: $link.
6677: '<label><input type="checkbox" name="scantronformat_del"'.
6678: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6679: '<td><span class="LC_nobreak"> '.
6680: &mt('Replace:').'</span><br />';
1.46 raeburn 6681: }
6682: }
6683: if (keys(%error) == 0) {
6684: if ($switchserver) {
6685: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6686: } else {
1.65 raeburn 6687: $datatable .='<span class="LC_nobreak"> '.
6688: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6689: }
6690: }
6691: $datatable .= '</td></tr>';
6692: $$rowtotal ++;
6693: return $datatable;
6694: }
6695:
6696: sub legacy_scantronformat {
6697: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6698: my ($url,$error);
6699: my @statinfo = &Apache::lonnet::stat_file($newurl);
6700: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6701: (my $result,$url) =
6702: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6703: '','',$newfile);
6704: if ($result ne 'ok') {
1.130 raeburn 6705: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6706: }
6707: }
6708: return ($url,$error);
6709: }
1.43 raeburn 6710:
1.49 raeburn 6711: sub print_coursecategories {
1.57 raeburn 6712: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6713: my $datatable;
6714: if ($position eq 'top') {
1.238 raeburn 6715: my (%checked);
6716: my @catitems = ('unauth','auth');
6717: my @cattypes = ('std','domonly','codesrch','none');
6718: $checked{'unauth'} = 'std';
6719: $checked{'auth'} = 'std';
6720: if (ref($settings) eq 'HASH') {
6721: foreach my $type (@cattypes) {
6722: if ($type eq $settings->{'unauth'}) {
6723: $checked{'unauth'} = $type;
6724: }
6725: if ($type eq $settings->{'auth'}) {
6726: $checked{'auth'} = $type;
6727: }
6728: }
6729: }
6730: my %lt = &Apache::lonlocal::texthash (
6731: unauth => 'Catalog type for unauthenticated users',
6732: auth => 'Catalog type for authenticated users',
6733: none => 'No catalog',
6734: std => 'Standard catalog',
6735: domonly => 'Domain-only catalog',
6736: codesrch => "Code search form",
6737: );
6738: my $itemcount = 0;
6739: foreach my $item (@catitems) {
6740: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6741: $datatable .= '<tr '.$css_class.'>'.
6742: '<td>'.$lt{$item}.'</td>'.
6743: '<td class="LC_right_item"><span class="LC_nobreak">';
6744: foreach my $type (@cattypes) {
6745: my $ischecked;
6746: if ($checked{$item} eq $type) {
6747: $ischecked=' checked="checked"';
6748: }
6749: $datatable .= '<label>'.
6750: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6751: ' />'.$lt{$type}.'</label> ';
6752: }
6753: $datatable .= '</td></tr>';
6754: $itemcount ++;
6755: }
6756: $$rowtotal += $itemcount;
6757: } elsif ($position eq 'middle') {
1.57 raeburn 6758: my $toggle_cats_crs = ' ';
6759: my $toggle_cats_dom = ' checked="checked" ';
6760: my $can_cat_crs = ' ';
6761: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6762: my $toggle_catscomm_comm = ' ';
6763: my $toggle_catscomm_dom = ' checked="checked" ';
6764: my $can_catcomm_comm = ' ';
6765: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 6766: my $toggle_catsplace_place = ' ';
6767: my $toggle_catsplace_dom = ' checked="checked" ';
6768: my $can_catplace_place = ' ';
6769: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 6770:
1.57 raeburn 6771: if (ref($settings) eq 'HASH') {
6772: if ($settings->{'togglecats'} eq 'crs') {
6773: $toggle_cats_crs = $toggle_cats_dom;
6774: $toggle_cats_dom = ' ';
6775: }
6776: if ($settings->{'categorize'} eq 'crs') {
6777: $can_cat_crs = $can_cat_dom;
6778: $can_cat_dom = ' ';
6779: }
1.120 raeburn 6780: if ($settings->{'togglecatscomm'} eq 'comm') {
6781: $toggle_catscomm_comm = $toggle_catscomm_dom;
6782: $toggle_catscomm_dom = ' ';
6783: }
6784: if ($settings->{'categorizecomm'} eq 'comm') {
6785: $can_catcomm_comm = $can_catcomm_dom;
6786: $can_catcomm_dom = ' ';
6787: }
1.272 raeburn 6788: if ($settings->{'togglecatsplace'} eq 'place') {
6789: $toggle_catsplace_place = $toggle_catsplace_dom;
6790: $toggle_catsplace_dom = ' ';
6791: }
6792: if ($settings->{'categorizeplace'} eq 'place') {
6793: $can_catplace_place = $can_catplace_dom;
6794: $can_catplace_dom = ' ';
6795: }
1.57 raeburn 6796: }
6797: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 6798: togglecats => 'Show/Hide a course in catalog',
6799: togglecatscomm => 'Show/Hide a community in catalog',
6800: togglecatsplace => 'Show/Hide a placement test in catalog',
6801: categorize => 'Assign a category to a course',
6802: categorizecomm => 'Assign a category to a community',
6803: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 6804: );
6805: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 6806: dom => 'Set in Domain',
6807: crs => 'Set in Course',
6808: comm => 'Set in Community',
6809: place => 'Set in Placement Test',
1.57 raeburn 6810: );
6811: $datatable = '<tr class="LC_odd_row">'.
6812: '<td>'.$title{'togglecats'}.'</td>'.
6813: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6814: '<input type="radio" name="togglecats"'.
6815: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6816: '<label><input type="radio" name="togglecats"'.
6817: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6818: '</tr><tr>'.
6819: '<td>'.$title{'categorize'}.'</td>'.
6820: '<td class="LC_right_item"><span class="LC_nobreak">'.
6821: '<label><input type="radio" name="categorize"'.
6822: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6823: '<label><input type="radio" name="categorize"'.
6824: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6825: '</tr><tr class="LC_odd_row">'.
6826: '<td>'.$title{'togglecatscomm'}.'</td>'.
6827: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6828: '<input type="radio" name="togglecatscomm"'.
6829: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6830: '<label><input type="radio" name="togglecatscomm"'.
6831: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6832: '</tr><tr>'.
6833: '<td>'.$title{'categorizecomm'}.'</td>'.
6834: '<td class="LC_right_item"><span class="LC_nobreak">'.
6835: '<label><input type="radio" name="categorizecomm"'.
6836: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6837: '<label><input type="radio" name="categorizecomm"'.
6838: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 6839: '</tr><tr>'.
6840: '<td>'.$title{'togglecatsplace'}.'</td>'.
6841: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6842: '<input type="radio" name="togglecatsplace"'.
6843: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6844: '<label><input type="radio" name="togglecatscomm"'.
6845: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
6846: '</tr><tr>'.
6847: '<td>'.$title{'categorizeplace'}.'</td>'.
6848: '<td class="LC_right_item"><span class="LC_nobreak">'.
6849: '<label><input type="radio" name="categorizeplace"'.
6850: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6851: '<label><input type="radio" name="categorizeplace"'.
6852: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 6853: '</tr>';
1.272 raeburn 6854: $$rowtotal += 6;
1.57 raeburn 6855: } else {
6856: my $css_class;
6857: my $itemcount = 1;
6858: my $cathash;
6859: if (ref($settings) eq 'HASH') {
6860: $cathash = $settings->{'cats'};
6861: }
6862: if (ref($cathash) eq 'HASH') {
6863: my (@cats,@trails,%allitems,%idx,@jsarray);
6864: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6865: \%allitems,\%idx,\@jsarray);
6866: my $maxdepth = scalar(@cats);
6867: my $colattrib = '';
6868: if ($maxdepth > 2) {
6869: $colattrib = ' colspan="2" ';
6870: }
6871: my @path;
6872: if (@cats > 0) {
6873: if (ref($cats[0]) eq 'ARRAY') {
6874: my $numtop = @{$cats[0]};
6875: my $maxnum = $numtop;
1.120 raeburn 6876: my %default_names = (
6877: instcode => &mt('Official courses'),
6878: communities => &mt('Communities'),
1.272 raeburn 6879: placement => &mt('Placement Tests'),
1.120 raeburn 6880: );
6881:
6882: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6883: ($cathash->{'instcode::0'} eq '') ||
6884: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 6885: ($cathash->{'communities::0'} eq '') ||
6886: (!grep(/^placement$/,@{$cats[0]})) ||
6887: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 6888: $maxnum ++;
6889: }
6890: my $lastidx;
6891: for (my $i=0; $i<$numtop; $i++) {
6892: my $parent = $cats[0][$i];
6893: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6894: my $item = &escape($parent).'::0';
6895: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6896: $lastidx = $idx{$item};
6897: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6898: .'<select name="'.$item.'"'.$chgstr.'>';
6899: for (my $k=0; $k<=$maxnum; $k++) {
6900: my $vpos = $k+1;
6901: my $selstr;
6902: if ($k == $i) {
6903: $selstr = ' selected="selected" ';
6904: }
6905: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6906: }
1.214 raeburn 6907: $datatable .= '</select></span></td><td>';
1.272 raeburn 6908: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 6909: $datatable .= '<span class="LC_nobreak">'
6910: .$default_names{$parent}.'</span>';
6911: if ($parent eq 'instcode') {
6912: $datatable .= '<br /><span class="LC_nobreak">('
6913: .&mt('with institutional codes')
6914: .')</span></td><td'.$colattrib.'>';
6915: } else {
6916: $datatable .= '<table><tr><td>';
6917: }
6918: $datatable .= '<span class="LC_nobreak">'
6919: .'<label><input type="radio" name="'
6920: .$parent.'" value="1" checked="checked" />'
6921: .&mt('Display').'</label>';
6922: if ($parent eq 'instcode') {
6923: $datatable .= ' ';
6924: } else {
6925: $datatable .= '</span></td></tr><tr><td>'
6926: .'<span class="LC_nobreak">';
6927: }
6928: $datatable .= '<label><input type="radio" name="'
6929: .$parent.'" value="0" />'
6930: .&mt('Do not display').'</label></span>';
1.272 raeburn 6931: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 6932: $datatable .= '</td></tr></table>';
6933: }
6934: $datatable .= '</td>';
1.57 raeburn 6935: } else {
6936: $datatable .= $parent
1.214 raeburn 6937: .' <span class="LC_nobreak"><label>'
6938: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6939: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6940: }
6941: my $depth = 1;
6942: push(@path,$parent);
6943: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6944: pop(@path);
6945: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6946: $itemcount ++;
6947: }
1.48 raeburn 6948: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6949: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6950: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6951: for (my $k=0; $k<=$maxnum; $k++) {
6952: my $vpos = $k+1;
6953: my $selstr;
1.57 raeburn 6954: if ($k == $numtop) {
1.48 raeburn 6955: $selstr = ' selected="selected" ';
6956: }
6957: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6958: }
1.59 bisitz 6959: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6960: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6961: .'</tr>'."\n";
1.48 raeburn 6962: $itemcount ++;
1.272 raeburn 6963: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6964: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6965: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6966: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6967: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6968: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6969: for (my $k=0; $k<=$maxnum; $k++) {
6970: my $vpos = $k+1;
6971: my $selstr;
6972: if ($k == $maxnum) {
6973: $selstr = ' selected="selected" ';
6974: }
6975: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6976: }
1.120 raeburn 6977: $datatable .= '</select></span></td>'.
6978: '<td><span class="LC_nobreak">'.
6979: $default_names{$default}.'</span>';
6980: if ($default eq 'instcode') {
6981: $datatable .= '<br /><span class="LC_nobreak">('
6982: .&mt('with institutional codes').')</span>';
6983: }
6984: $datatable .= '</td>'
6985: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6986: .&mt('Display').'</label> '
6987: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6988: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6989: }
6990: }
6991: }
1.57 raeburn 6992: } else {
6993: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6994: }
6995: } else {
1.238 raeburn 6996: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6997: .&initialize_categories($itemcount);
1.48 raeburn 6998: }
1.57 raeburn 6999: $$rowtotal += $itemcount;
1.48 raeburn 7000: }
7001: return $datatable;
7002: }
7003:
1.69 raeburn 7004: sub print_serverstatuses {
7005: my ($dom,$settings,$rowtotal) = @_;
7006: my $datatable;
7007: my @pages = &serverstatus_pages();
7008: my (%namedaccess,%machineaccess);
7009: foreach my $type (@pages) {
7010: $namedaccess{$type} = '';
7011: $machineaccess{$type}= '';
7012: }
7013: if (ref($settings) eq 'HASH') {
7014: foreach my $type (@pages) {
7015: if (exists($settings->{$type})) {
7016: if (ref($settings->{$type}) eq 'HASH') {
7017: foreach my $key (keys(%{$settings->{$type}})) {
7018: if ($key eq 'namedusers') {
7019: $namedaccess{$type} = $settings->{$type}->{$key};
7020: } elsif ($key eq 'machines') {
7021: $machineaccess{$type} = $settings->{$type}->{$key};
7022: }
7023: }
7024: }
7025: }
7026: }
7027: }
1.81 raeburn 7028: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7029: my $rownum = 0;
7030: my $css_class;
7031: foreach my $type (@pages) {
7032: $rownum ++;
7033: $css_class = $rownum%2?' class="LC_odd_row"':'';
7034: $datatable .= '<tr'.$css_class.'>'.
7035: '<td><span class="LC_nobreak">'.
7036: $titles->{$type}.'</span></td>'.
7037: '<td class="LC_left_item">'.
7038: '<input type="text" name="'.$type.'_namedusers" '.
7039: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
7040: '<td class="LC_right_item">'.
7041: '<span class="LC_nobreak">'.
7042: '<input type="text" name="'.$type.'_machines" '.
7043: 'value="'.$machineaccess{$type}.'" size="10" />'.
7044: '</td></tr>'."\n";
7045: }
7046: $$rowtotal += $rownum;
7047: return $datatable;
7048: }
7049:
7050: sub serverstatus_pages {
7051: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 7052: 'checksums','clusterstatus','certstatus','metadata_keywords',
7053: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
7054: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 7055: }
7056:
1.236 raeburn 7057: sub defaults_javascript {
7058: my ($settings) = @_;
1.294 raeburn 7059: 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.');
7060: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
7061: &js_escape(\$intauthcheck);
7062: &js_escape(\$intauthcost);
7063: my $intauthjs = <<"ENDSCRIPT";
7064:
7065: function warnIntAuth(field) {
7066: if (field.name == 'intauth_check') {
7067: if (field.value == '2') {
7068: alert('$intauthcheck');
7069: }
7070: }
7071: if (field.name == 'intauth_cost') {
7072: field.value.replace(/\s/g,'');
7073: if (field.value != '') {
7074: var regexdigit=/^\\d+\$/;
7075: if (!regexdigit.test(field.value)) {
7076: alert('$intauthcost');
7077: }
7078: }
7079: }
7080: return;
7081: }
7082:
7083: ENDSCRIPT
7084:
7085: if (ref($settings) ne 'HASH') {
7086: return &Apache::lonhtmlcommon::scripttag($intauthjs);
7087: }
1.236 raeburn 7088: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
7089: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
7090: if ($maxnum eq '') {
7091: $maxnum = 0;
7092: }
7093: $maxnum ++;
1.249 raeburn 7094: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 7095: return <<"ENDSCRIPT";
7096: <script type="text/javascript">
7097: // <![CDATA[
7098: function reorderTypes(form,caller) {
7099: var changedVal;
7100: $jstext
7101: var newpos = 'addinststatus_pos';
7102: var current = new Array;
7103: var maxh = $maxnum;
7104: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7105: var oldVal;
7106: if (caller == newpos) {
7107: changedVal = newitemVal;
7108: } else {
7109: var curritem = 'inststatus_pos_'+caller;
7110: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
7111: current[newitemVal] = newpos;
7112: }
7113: for (var i=0; i<inststatuses.length; i++) {
7114: if (inststatuses[i] != caller) {
7115: var elementName = 'inststatus_pos_'+inststatuses[i];
7116: if (form.elements[elementName]) {
7117: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7118: current[currVal] = elementName;
7119: }
7120: }
7121: }
7122: for (var j=0; j<maxh; j++) {
7123: if (current[j] == undefined) {
7124: oldVal = j;
7125: }
7126: }
7127: if (oldVal < changedVal) {
7128: for (var k=oldVal+1; k<=changedVal ; k++) {
7129: var elementName = current[k];
7130: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7131: }
7132: } else {
7133: for (var k=changedVal; k<oldVal; k++) {
7134: var elementName = current[k];
7135: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7136: }
7137: }
7138: return;
7139: }
7140:
1.294 raeburn 7141: $intauthjs
7142:
1.236 raeburn 7143: // ]]>
7144: </script>
7145:
7146: ENDSCRIPT
1.294 raeburn 7147: } else {
7148: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 7149: }
7150: }
7151:
1.49 raeburn 7152: sub coursecategories_javascript {
7153: my ($settings) = @_;
1.57 raeburn 7154: my ($output,$jstext,$cathash);
1.49 raeburn 7155: if (ref($settings) eq 'HASH') {
1.57 raeburn 7156: $cathash = $settings->{'cats'};
7157: }
7158: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7159: my (@cats,@jsarray,%idx);
1.57 raeburn 7160: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7161: if (@jsarray > 0) {
7162: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7163: for (my $i=0; $i<@jsarray; $i++) {
7164: if (ref($jsarray[$i]) eq 'ARRAY') {
7165: my $catstr = join('","',@{$jsarray[$i]});
7166: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7167: }
7168: }
7169: }
7170: } else {
7171: $jstext = ' var categories = Array(1);'."\n".
7172: ' categories[0] = Array("instcode_pos");'."\n";
7173: }
1.237 bisitz 7174: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7175: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 7176: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 7177: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7178: &js_escape(\$instcode_reserved);
7179: &js_escape(\$communities_reserved);
1.272 raeburn 7180: &js_escape(\$placement_reserved);
1.265 damieng 7181: &js_escape(\$choose_again);
1.49 raeburn 7182: $output = <<"ENDSCRIPT";
7183: <script type="text/javascript">
1.109 raeburn 7184: // <![CDATA[
1.49 raeburn 7185: function reorderCats(form,parent,item,idx) {
7186: var changedVal;
7187: $jstext
7188: var newpos = 'addcategory_pos';
7189: if (parent == '') {
7190: var has_instcode = 0;
7191: var maxtop = categories[idx].length;
7192: for (var j=0; j<maxtop; j++) {
7193: if (categories[idx][j] == 'instcode::0') {
7194: has_instcode == 1;
7195: }
7196: }
7197: if (has_instcode == 0) {
7198: categories[idx][maxtop] = 'instcode_pos';
7199: }
7200: } else {
7201: newpos += '_'+parent;
7202: }
7203: var maxh = 1 + categories[idx].length;
7204: var current = new Array;
7205: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7206: if (item == newpos) {
7207: changedVal = newitemVal;
7208: } else {
7209: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7210: current[newitemVal] = newpos;
7211: }
7212: for (var i=0; i<categories[idx].length; i++) {
7213: var elementName = categories[idx][i];
7214: if (elementName != item) {
7215: if (form.elements[elementName]) {
7216: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7217: current[currVal] = elementName;
7218: }
7219: }
7220: }
7221: var oldVal;
7222: for (var j=0; j<maxh; j++) {
7223: if (current[j] == undefined) {
7224: oldVal = j;
7225: }
7226: }
7227: if (oldVal < changedVal) {
7228: for (var k=oldVal+1; k<=changedVal ; k++) {
7229: var elementName = current[k];
7230: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7231: }
7232: } else {
7233: for (var k=changedVal; k<oldVal; k++) {
7234: var elementName = current[k];
7235: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7236: }
7237: }
7238: return;
7239: }
1.120 raeburn 7240:
7241: function categoryCheck(form) {
7242: if (form.elements['addcategory_name'].value == 'instcode') {
7243: alert('$instcode_reserved\\n$choose_again');
7244: return false;
7245: }
7246: if (form.elements['addcategory_name'].value == 'communities') {
7247: alert('$communities_reserved\\n$choose_again');
7248: return false;
7249: }
1.272 raeburn 7250: if (form.elements['addcategory_name'].value == 'placement') {
7251: alert('$placement_reserved\\n$choose_again');
7252: return false;
7253: }
1.120 raeburn 7254: return true;
7255: }
7256:
1.109 raeburn 7257: // ]]>
1.49 raeburn 7258: </script>
7259:
7260: ENDSCRIPT
7261: return $output;
7262: }
7263:
1.48 raeburn 7264: sub initialize_categories {
7265: my ($itemcount) = @_;
1.120 raeburn 7266: my ($datatable,$css_class,$chgstr);
7267: my %default_names = (
7268: instcode => 'Official courses (with institutional codes)',
7269: communities => 'Communities',
1.272 raeburn 7270: placement => 'Placement Tests',
1.120 raeburn 7271: );
7272: my $select0 = ' selected="selected"';
7273: my $select1 = '';
1.272 raeburn 7274: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7275: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7276: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 7277: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 7278: $select1 = $select0;
7279: $select0 = '';
7280: }
7281: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7282: .'<select name="'.$default.'_pos">'
7283: .'<option value="0"'.$select0.'>1</option>'
7284: .'<option value="1"'.$select1.'>2</option>'
7285: .'<option value="2">3</option></select> '
7286: .$default_names{$default}
7287: .'</span></td><td><span class="LC_nobreak">'
7288: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7289: .&mt('Display').'</label> <label>'
7290: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7291: .'</label></span></td></tr>';
1.120 raeburn 7292: $itemcount ++;
7293: }
1.48 raeburn 7294: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7295: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7296: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7297: .'<select name="addcategory_pos"'.$chgstr.'>'
7298: .'<option value="0">1</option>'
7299: .'<option value="1">2</option>'
7300: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 7301: .&mt('Add category').'</td><td>'.&mt('Name:')
7302: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
7303: return $datatable;
7304: }
7305:
7306: sub build_category_rows {
1.49 raeburn 7307: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7308: my ($text,$name,$item,$chgstr);
1.48 raeburn 7309: if (ref($cats) eq 'ARRAY') {
7310: my $maxdepth = scalar(@{$cats});
7311: if (ref($cats->[$depth]) eq 'HASH') {
7312: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7313: my $numchildren = @{$cats->[$depth]{$parent}};
7314: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 7315: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7316: my ($idxnum,$parent_name,$parent_item);
7317: my $higher = $depth - 1;
7318: if ($higher == 0) {
7319: $parent_name = &escape($parent).'::'.$higher;
7320: } else {
7321: if (ref($path) eq 'ARRAY') {
7322: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7323: }
7324: }
7325: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7326: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7327: if ($j < $numchildren) {
1.48 raeburn 7328: $name = $cats->[$depth]{$parent}[$j];
7329: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7330: $idxnum = $idx->{$item};
7331: } else {
7332: $name = $parent_name;
7333: $item = $parent_item;
1.48 raeburn 7334: }
1.49 raeburn 7335: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7336: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7337: for (my $i=0; $i<=$numchildren; $i++) {
7338: my $vpos = $i+1;
7339: my $selstr;
7340: if ($j == $i) {
7341: $selstr = ' selected="selected" ';
7342: }
7343: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7344: }
7345: $text .= '</select> ';
7346: if ($j < $numchildren) {
7347: my $deeper = $depth+1;
7348: $text .= $name.' '
7349: .'<label><input type="checkbox" name="deletecategory" value="'
7350: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7351: if(ref($path) eq 'ARRAY') {
7352: push(@{$path},$name);
1.49 raeburn 7353: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7354: pop(@{$path});
7355: }
7356: } else {
1.59 bisitz 7357: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 7358: if ($j == $numchildren) {
7359: $text .= $name;
7360: } else {
7361: $text .= $item;
7362: }
7363: $text .= '" value="" />';
7364: }
7365: $text .= '</td></tr>';
7366: }
7367: $text .= '</table></td>';
7368: } else {
7369: my $higher = $depth-1;
7370: if ($higher == 0) {
7371: $name = &escape($parent).'::'.$higher;
7372: } else {
7373: if (ref($path) eq 'ARRAY') {
7374: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7375: }
7376: }
7377: my $colspan;
7378: if ($parent ne 'instcode') {
7379: $colspan = $maxdepth - $depth - 1;
7380: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7381: }
7382: }
7383: }
7384: }
7385: return $text;
7386: }
7387:
1.33 raeburn 7388: sub modifiable_userdata_row {
1.228 raeburn 7389: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
7390: my ($role,$rolename,$statustype);
7391: $role = $item;
1.224 raeburn 7392: if ($context eq 'cancreate') {
1.228 raeburn 7393: if ($item =~ /^emailusername_(.+)$/) {
7394: $statustype = $1;
7395: $role = 'emailusername';
7396: if (ref($usertypes) eq 'HASH') {
7397: if ($usertypes->{$statustype}) {
7398: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7399: } else {
7400: $rolename = &mt('Data provided by user');
7401: }
7402: }
1.224 raeburn 7403: }
7404: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7405: if (ref($usertypes) eq 'HASH') {
7406: $rolename = $usertypes->{$role};
7407: } else {
7408: $rolename = $role;
7409: }
1.33 raeburn 7410: } else {
1.63 raeburn 7411: if ($role eq 'cr') {
7412: $rolename = &mt('Custom role');
7413: } else {
7414: $rolename = &Apache::lonnet::plaintext($role);
7415: }
1.33 raeburn 7416: }
1.224 raeburn 7417: my (@fields,%fieldtitles);
7418: if (ref($fieldsref) eq 'ARRAY') {
7419: @fields = @{$fieldsref};
7420: } else {
7421: @fields = ('lastname','firstname','middlename','generation',
7422: 'permanentemail','id');
7423: }
7424: if ((ref($titlesref) eq 'HASH')) {
7425: %fieldtitles = %{$titlesref};
7426: } else {
7427: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7428: }
1.33 raeburn 7429: my $output;
7430: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7431: $output = '<tr '.$css_class.'>'.
7432: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7433: '<td class="LC_left_item" colspan="2"><table>';
7434: my $rem;
7435: my %checks;
7436: if (ref($settings) eq 'HASH') {
7437: if (ref($settings->{$context}) eq 'HASH') {
7438: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 7439: my $hashref = $settings->{$context}->{$role};
7440: if ($role eq 'emailusername') {
7441: if ($statustype) {
7442: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7443: $hashref = $settings->{$context}->{$role}->{$statustype};
7444: if (ref($hashref) eq 'HASH') {
7445: foreach my $field (@fields) {
7446: if ($hashref->{$field}) {
7447: $checks{$field} = $hashref->{$field};
7448: }
7449: }
7450: }
7451: }
7452: }
7453: } else {
7454: if (ref($hashref) eq 'HASH') {
7455: foreach my $field (@fields) {
7456: if ($hashref->{$field}) {
7457: $checks{$field} = ' checked="checked" ';
7458: }
7459: }
1.33 raeburn 7460: }
7461: }
7462: }
7463: }
7464: }
1.228 raeburn 7465:
1.33 raeburn 7466: for (my $i=0; $i<@fields; $i++) {
7467: my $rem = $i%($numinrow);
7468: if ($rem == 0) {
7469: if ($i > 0) {
7470: $output .= '</tr>';
7471: }
7472: $output .= '<tr>';
7473: }
7474: my $check = ' ';
1.228 raeburn 7475: unless ($role eq 'emailusername') {
7476: if (exists($checks{$fields[$i]})) {
7477: $check = $checks{$fields[$i]}
7478: } else {
7479: if ($role eq 'st') {
7480: if (ref($settings) ne 'HASH') {
7481: $check = ' checked="checked" ';
7482: }
1.33 raeburn 7483: }
7484: }
7485: }
7486: $output .= '<td class="LC_left_item">'.
1.228 raeburn 7487: '<span class="LC_nobreak">';
7488: if ($role eq 'emailusername') {
7489: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7490: $checks{$fields[$i]} = 'omit';
7491: }
7492: foreach my $option ('required','optional','omit') {
7493: my $checked='';
7494: if ($checks{$fields[$i]} eq $option) {
7495: $checked='checked="checked" ';
7496: }
7497: $output .= '<label>'.
7498: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7499: &mt($option).'</label>'.(' ' x2);
7500: }
7501: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7502: } else {
7503: $output .= '<label>'.
7504: '<input type="checkbox" name="canmodify_'.$role.'" '.
7505: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7506: '</label>';
7507: }
7508: $output .= '</span></td>';
1.33 raeburn 7509: $rem = @fields%($numinrow);
7510: }
7511: my $colsleft = $numinrow - $rem;
7512: if ($colsleft > 1 ) {
7513: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7514: ' </td>';
7515: } elsif ($colsleft == 1) {
7516: $output .= '<td class="LC_left_item"> </td>';
7517: }
7518: $output .= '</tr></table></td></tr>';
7519: return $output;
7520: }
1.28 raeburn 7521:
1.93 raeburn 7522: sub insttypes_row {
1.224 raeburn 7523: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 7524: my %lt = &Apache::lonlocal::texthash (
7525: cansearch => 'Users allowed to search',
7526: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7527: lockablenames => 'User preference to lock name',
1.93 raeburn 7528: );
7529: my $showdom;
7530: if ($context eq 'cansearch') {
7531: $showdom = ' ('.$dom.')';
7532: }
1.165 raeburn 7533: my $class = 'LC_left_item';
7534: if ($context eq 'statustocreate') {
7535: $class = 'LC_right_item';
7536: }
1.224 raeburn 7537: my $css_class = ' class="LC_odd_row"';
7538: if ($rownum ne '') {
7539: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
7540: }
7541: my $output = '<tr'.$css_class.'>'.
7542: '<td>'.$lt{$context}.$showdom.
7543: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7544: my $rem;
7545: if (ref($types) eq 'ARRAY') {
7546: for (my $i=0; $i<@{$types}; $i++) {
7547: if (defined($usertypes->{$types->[$i]})) {
7548: my $rem = $i%($numinrow);
7549: if ($rem == 0) {
7550: if ($i > 0) {
7551: $output .= '</tr>';
7552: }
7553: $output .= '<tr>';
1.23 raeburn 7554: }
1.26 raeburn 7555: my $check = ' ';
1.99 raeburn 7556: if (ref($settings) eq 'HASH') {
7557: if (ref($settings->{$context}) eq 'ARRAY') {
7558: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7559: $check = ' checked="checked" ';
7560: }
7561: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7562: $check = ' checked="checked" ';
7563: }
1.23 raeburn 7564: }
1.26 raeburn 7565: $output .= '<td class="LC_left_item">'.
7566: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7567: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 7568: 'value="'.$types->[$i].'"'.$check.'/>'.
7569: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7570: }
7571: }
1.26 raeburn 7572: $rem = @{$types}%($numinrow);
1.23 raeburn 7573: }
7574: my $colsleft = $numinrow - $rem;
1.131 raeburn 7575: if (($rem == 0) && (@{$types} > 0)) {
7576: $output .= '<tr>';
7577: }
1.23 raeburn 7578: if ($colsleft > 1) {
1.25 raeburn 7579: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7580: } else {
1.25 raeburn 7581: $output .= '<td class="LC_left_item">';
1.23 raeburn 7582: }
7583: my $defcheck = ' ';
1.99 raeburn 7584: if (ref($settings) eq 'HASH') {
7585: if (ref($settings->{$context}) eq 'ARRAY') {
7586: if (grep(/^default$/,@{$settings->{$context}})) {
7587: $defcheck = ' checked="checked" ';
7588: }
7589: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7590: $defcheck = ' checked="checked" ';
7591: }
1.23 raeburn 7592: }
1.25 raeburn 7593: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7594: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 7595: 'value="default"'.$defcheck.'/>'.
7596: $othertitle.'</label></span></td>'.
7597: '</tr></table></td></tr>';
7598: return $output;
1.23 raeburn 7599: }
7600:
7601: sub sorted_searchtitles {
7602: my %searchtitles = &Apache::lonlocal::texthash(
7603: 'uname' => 'username',
7604: 'lastname' => 'last name',
7605: 'lastfirst' => 'last name, first name',
7606: );
7607: my @titleorder = ('uname','lastname','lastfirst');
7608: return (\%searchtitles,\@titleorder);
7609: }
7610:
1.25 raeburn 7611: sub sorted_searchtypes {
7612: my %srchtypes_desc = (
7613: exact => 'is exact match',
7614: contains => 'contains ..',
7615: begins => 'begins with ..',
7616: );
7617: my @srchtypeorder = ('exact','begins','contains');
7618: return (\%srchtypes_desc,\@srchtypeorder);
7619: }
7620:
1.3 raeburn 7621: sub usertype_update_row {
7622: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7623: my $datatable;
7624: my $numinrow = 4;
7625: foreach my $type (@{$types}) {
7626: if (defined($usertypes->{$type})) {
7627: $$rownums ++;
7628: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7629: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7630: '</td><td class="LC_left_item"><table>';
7631: for (my $i=0; $i<@{$fields}; $i++) {
7632: my $rem = $i%($numinrow);
7633: if ($rem == 0) {
7634: if ($i > 0) {
7635: $datatable .= '</tr>';
7636: }
7637: $datatable .= '<tr>';
7638: }
7639: my $check = ' ';
1.39 raeburn 7640: if (ref($settings) eq 'HASH') {
7641: if (ref($settings->{'fields'}) eq 'HASH') {
7642: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7643: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7644: $check = ' checked="checked" ';
7645: }
1.3 raeburn 7646: }
7647: }
7648: }
7649:
7650: if ($i == @{$fields}-1) {
7651: my $colsleft = $numinrow - $rem;
7652: if ($colsleft > 1) {
7653: $datatable .= '<td colspan="'.$colsleft.'">';
7654: } else {
7655: $datatable .= '<td>';
7656: }
7657: } else {
7658: $datatable .= '<td>';
7659: }
1.8 raeburn 7660: $datatable .= '<span class="LC_nobreak"><label>'.
7661: '<input type="checkbox" name="updateable_'.$type.
7662: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7663: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7664: }
7665: $datatable .= '</tr></table></td></tr>';
7666: }
7667: }
7668: return $datatable;
1.1 raeburn 7669: }
7670:
7671: sub modify_login {
1.205 raeburn 7672: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 7673: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7674: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7675: %title = ( coursecatalog => 'Display course catalog',
7676: adminmail => 'Display administrator E-mail address',
1.188 raeburn 7677: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 7678: newuser => 'Link for visitors to create a user account',
7679: loginheader => 'Log-in box header');
7680: @offon = ('off','on');
1.112 raeburn 7681: if (ref($domconfig{login}) eq 'HASH') {
7682: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7683: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7684: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7685: }
7686: }
7687: }
1.9 raeburn 7688: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7689: \%domconfig,\%loginhash);
1.188 raeburn 7690: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7691: foreach my $item (@toggles) {
7692: $loginhash{login}{$item} = $env{'form.'.$item};
7693: }
1.41 raeburn 7694: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7695: if (ref($colchanges{'login'}) eq 'HASH') {
7696: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7697: \%loginhash);
7698: }
1.110 raeburn 7699:
1.149 raeburn 7700: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 7701: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7702: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7703: if (keys(%servers) > 1) {
7704: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7705: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7706: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7707: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7708: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7709: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7710: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7711: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7712: $changes{'loginvia'}{$lonhost} = 1;
7713: } else {
7714: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7715: $changes{'loginvia'}{$lonhost} = 1;
7716: }
7717: } else {
7718: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7719: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7720: $changes{'loginvia'}{$lonhost} = 1;
7721: }
7722: }
7723: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7724: foreach my $item (@loginvia_attribs) {
7725: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7726: }
7727: } else {
7728: foreach my $item (@loginvia_attribs) {
7729: my $new = $env{'form.'.$lonhost.'_'.$item};
7730: if (($item eq 'serverpath') && ($new eq 'custom')) {
7731: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7732: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7733: $new = '/';
7734: }
7735: }
7736: if (($item eq 'custompath') &&
7737: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7738: $new = '';
7739: }
7740: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7741: $changes{'loginvia'}{$lonhost} = 1;
7742: }
7743: if ($item eq 'exempt') {
1.256 raeburn 7744: $new = &check_exempt_addresses($new);
1.128 raeburn 7745: }
7746: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7747: }
7748: }
1.112 raeburn 7749: } else {
1.128 raeburn 7750: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7751: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7752: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7753: foreach my $item (@loginvia_attribs) {
7754: my $new = $env{'form.'.$lonhost.'_'.$item};
7755: if (($item eq 'serverpath') && ($new eq 'custom')) {
7756: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7757: $new = '/';
7758: }
7759: }
7760: if (($item eq 'custompath') &&
7761: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7762: $new = '';
7763: }
7764: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7765: }
1.110 raeburn 7766: }
7767: }
7768: }
7769: }
1.119 raeburn 7770:
1.168 raeburn 7771: my $servadm = $r->dir_config('lonAdmEMail');
7772: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7773: if (ref($domconfig{'login'}) eq 'HASH') {
7774: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7775: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7776: if ($lang eq 'nolang') {
7777: push(@currlangs,$lang);
7778: } elsif (defined($langchoices{$lang})) {
7779: push(@currlangs,$lang);
7780: } else {
7781: next;
7782: }
7783: }
7784: }
7785: }
7786: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7787: if (@currlangs > 0) {
7788: foreach my $lang (@currlangs) {
7789: if (grep(/^\Q$lang\E$/,@delurls)) {
7790: $changes{'helpurl'}{$lang} = 1;
7791: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7792: $changes{'helpurl'}{$lang} = 1;
7793: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7794: push(@newlangs,$lang);
7795: } else {
7796: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7797: }
7798: }
7799: }
7800: unless (grep(/^nolang$/,@currlangs)) {
7801: if ($env{'form.loginhelpurl_nolang.filename'}) {
7802: $changes{'helpurl'}{'nolang'} = 1;
7803: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7804: push(@newlangs,'nolang');
7805: }
7806: }
7807: if ($env{'form.loginhelpurl_add_lang'}) {
7808: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7809: ($env{'form.loginhelpurl_add_file.filename'})) {
7810: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7811: $addedfile = $env{'form.loginhelpurl_add_lang'};
7812: }
7813: }
7814: if ((@newlangs > 0) || ($addedfile)) {
7815: my $error;
7816: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7817: if ($configuserok eq 'ok') {
7818: if ($switchserver) {
7819: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7820: } elsif ($author_ok eq 'ok') {
7821: my @allnew = @newlangs;
7822: if ($addedfile ne '') {
7823: push(@allnew,$addedfile);
7824: }
7825: foreach my $lang (@allnew) {
7826: my $formelem = 'loginhelpurl_'.$lang;
7827: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7828: $formelem = 'loginhelpurl_add_file';
7829: }
7830: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7831: "help/$lang",'','',$newfile{$lang});
7832: if ($result eq 'ok') {
7833: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7834: $changes{'helpurl'}{$lang} = 1;
7835: } else {
7836: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7837: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 7838: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 7839: (!grep(/^\Q$lang\E$/,@delurls))) {
7840: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7841: }
7842: }
7843: }
7844: } else {
7845: $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);
7846: }
7847: } else {
7848: $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);
7849: }
7850: if ($error) {
7851: &Apache::lonnet::logthis($error);
7852: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7853: }
7854: }
1.256 raeburn 7855:
7856: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7857: if (ref($domconfig{'login'}) eq 'HASH') {
7858: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7859: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7860: if ($domservers{$lonhost}) {
7861: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7862: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 7863: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 7864: }
7865: }
7866: }
7867: }
7868: }
7869: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7870: foreach my $lonhost (sort(keys(%domservers))) {
7871: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7872: $changes{'headtag'}{$lonhost} = 1;
7873: } else {
7874: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7875: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7876: }
7877: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7878: push(@newhosts,$lonhost);
7879: } elsif ($currheadtagurls{$lonhost}) {
7880: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7881: if ($currexempt{$lonhost}) {
1.289 raeburn 7882: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 7883: $changes{'headtag'}{$lonhost} = 1;
7884: }
7885: } elsif ($possexempt{$lonhost}) {
7886: $changes{'headtag'}{$lonhost} = 1;
7887: }
7888: if ($possexempt{$lonhost}) {
7889: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7890: }
7891: }
7892: }
7893: }
7894: if (@newhosts) {
7895: my $error;
7896: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7897: if ($configuserok eq 'ok') {
7898: if ($switchserver) {
7899: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7900: } elsif ($author_ok eq 'ok') {
7901: foreach my $lonhost (@newhosts) {
7902: my $formelem = 'loginheadtag_'.$lonhost;
7903: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7904: "login/headtag/$lonhost",'','',
7905: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7906: if ($result eq 'ok') {
7907: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7908: $changes{'headtag'}{$lonhost} = 1;
7909: if ($possexempt{$lonhost}) {
7910: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7911: }
7912: } else {
7913: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7914: $newheadtagurls{$lonhost},$result);
7915: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7916: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7917: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7918: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7919: }
7920: }
7921: }
7922: } else {
7923: $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);
7924: }
7925: } else {
7926: $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);
7927: }
7928: if ($error) {
7929: &Apache::lonnet::logthis($error);
7930: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7931: }
7932: }
1.169 raeburn 7933: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 7934:
7935: my $defaulthelpfile = '/adm/loginproblems.html';
7936: my $defaulttext = &mt('Default in use');
7937:
1.1 raeburn 7938: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7939: $dom);
7940: if ($putresult eq 'ok') {
1.188 raeburn 7941: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7942: my %defaultchecked = (
7943: 'coursecatalog' => 'on',
1.188 raeburn 7944: 'helpdesk' => 'on',
1.42 raeburn 7945: 'adminmail' => 'off',
1.43 raeburn 7946: 'newuser' => 'off',
1.42 raeburn 7947: );
1.55 raeburn 7948: if (ref($domconfig{'login'}) eq 'HASH') {
7949: foreach my $item (@toggles) {
7950: if ($defaultchecked{$item} eq 'on') {
7951: if (($domconfig{'login'}{$item} eq '0') &&
7952: ($env{'form.'.$item} eq '1')) {
7953: $changes{$item} = 1;
7954: } elsif (($domconfig{'login'}{$item} eq '' ||
7955: $domconfig{'login'}{$item} eq '1') &&
7956: ($env{'form.'.$item} eq '0')) {
7957: $changes{$item} = 1;
7958: }
7959: } elsif ($defaultchecked{$item} eq 'off') {
7960: if (($domconfig{'login'}{$item} eq '1') &&
7961: ($env{'form.'.$item} eq '0')) {
7962: $changes{$item} = 1;
7963: } elsif (($domconfig{'login'}{$item} eq '' ||
7964: $domconfig{'login'}{$item} eq '0') &&
7965: ($env{'form.'.$item} eq '1')) {
7966: $changes{$item} = 1;
7967: }
1.42 raeburn 7968: }
7969: }
1.41 raeburn 7970: }
1.6 raeburn 7971: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7972: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7973: if (ref($lastactref) eq 'HASH') {
7974: $lastactref->{'domainconfig'} = 1;
7975: }
1.1 raeburn 7976: $resulttext = &mt('Changes made:').'<ul>';
7977: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7978: if ($item eq 'loginvia') {
1.112 raeburn 7979: if (ref($changes{$item}) eq 'HASH') {
7980: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7981: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7982: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7983: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7984: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7985: $protocol = 'http' if ($protocol ne 'https');
7986: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7987:
7988: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7989: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7990: } else {
7991: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7992: }
7993: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7994: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7995: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7996: }
7997: $resulttext .= '</li>';
7998: } else {
7999: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
8000: }
1.112 raeburn 8001: } else {
1.128 raeburn 8002: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 8003: }
8004: }
1.128 raeburn 8005: $resulttext .= '</ul></li>';
1.112 raeburn 8006: }
1.168 raeburn 8007: } elsif ($item eq 'helpurl') {
8008: if (ref($changes{$item}) eq 'HASH') {
8009: foreach my $lang (sort(keys(%{$changes{$item}}))) {
8010: if (grep(/^\Q$lang\E$/,@delurls)) {
8011: my ($chg,$link);
8012: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
8013: if ($lang eq 'nolang') {
8014: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
8015: } else {
8016: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
8017: }
8018: $resulttext .= '<li>'.$chg.'</li>';
8019: } else {
8020: my $chg;
8021: if ($lang eq 'nolang') {
8022: $chg = &mt('custom log-in help file for no preferred language');
8023: } else {
8024: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
8025: }
8026: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
8027: $loginhash{'login'}{'helpurl'}{$lang}.
8028: '?inhibitmenu=yes',$chg,600,500).
8029: '</li>';
8030: }
8031: }
8032: }
1.256 raeburn 8033: } elsif ($item eq 'headtag') {
8034: if (ref($changes{$item}) eq 'HASH') {
8035: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
8036: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
8037: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
8038: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
8039: $resulttext .= '<li><a href="'.
8040: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
8041: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
8042: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
8043: if ($possexempt{$lonhost}) {
8044: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
8045: } else {
8046: $resulttext .= &mt('included for any client IP');
8047: }
8048: $resulttext .= '</li>';
8049: }
8050: }
8051: }
1.169 raeburn 8052: } elsif ($item eq 'captcha') {
8053: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 8054: my $chgtxt;
1.169 raeburn 8055: if ($loginhash{'login'}{$item} eq 'notused') {
8056: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
8057: } else {
8058: my %captchas = &captcha_phrases();
8059: if ($captchas{$loginhash{'login'}{$item}}) {
8060: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
8061: } else {
8062: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
8063: }
8064: }
8065: $resulttext .= '<li>'.$chgtxt.'</li>';
8066: }
8067: } elsif ($item eq 'recaptchakeys') {
8068: if (ref($loginhash{'login'}) eq 'HASH') {
8069: my ($privkey,$pubkey);
8070: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
8071: $pubkey = $loginhash{'login'}{$item}{'public'};
8072: $privkey = $loginhash{'login'}{$item}{'private'};
8073: }
8074: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
8075: if (!$pubkey) {
8076: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
8077: } else {
8078: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
8079: }
8080: if (!$privkey) {
8081: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
8082: } else {
1.251 raeburn 8083: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 8084: }
8085: $chgtxt .= '</ul>';
8086: $resulttext .= '<li>'.$chgtxt.'</li>';
8087: }
1.269 raeburn 8088: } elsif ($item eq 'recaptchaversion') {
8089: if (ref($loginhash{'login'}) eq 'HASH') {
8090: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 8091: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 8092: '</li>';
8093: }
8094: }
1.41 raeburn 8095: } else {
8096: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
8097: }
1.1 raeburn 8098: }
1.6 raeburn 8099: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 8100: } else {
8101: $resulttext = &mt('No changes made to log-in page settings');
8102: }
8103: } else {
1.11 albertel 8104: $resulttext = '<span class="LC_error">'.
8105: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8106: }
1.6 raeburn 8107: if ($errors) {
1.9 raeburn 8108: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 8109: $errors.'</ul>';
8110: }
8111: return $resulttext;
8112: }
8113:
1.256 raeburn 8114: sub check_exempt_addresses {
8115: my ($iplist) = @_;
8116: $iplist =~ s/^\s+//;
8117: $iplist =~ s/\s+$//;
8118: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
8119: my (@okips,$new);
8120: foreach my $ip (@poss_ips) {
8121: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
8122: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
8123: push(@okips,$ip);
8124: }
8125: }
8126: }
8127: if (@okips > 0) {
8128: $new = join(',',@okips);
8129: } else {
8130: $new = '';
8131: }
8132: return $new;
8133: }
8134:
1.6 raeburn 8135: sub color_font_choices {
8136: my %choices =
8137: &Apache::lonlocal::texthash (
8138: img => "Header",
8139: bgs => "Background colors",
8140: links => "Link colors",
1.55 raeburn 8141: images => "Images",
1.6 raeburn 8142: font => "Font color",
1.201 raeburn 8143: fontmenu => "Font menu",
1.76 raeburn 8144: pgbg => "Page",
1.6 raeburn 8145: tabbg => "Header",
8146: sidebg => "Border",
8147: link => "Link",
8148: alink => "Active link",
8149: vlink => "Visited link",
8150: );
8151: return %choices;
8152: }
8153:
8154: sub modify_rolecolors {
1.205 raeburn 8155: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8156: my ($resulttext,%rolehash);
8157: $rolehash{'rolecolors'} = {};
1.55 raeburn 8158: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8159: if ($domconfig{'rolecolors'} eq '') {
8160: $domconfig{'rolecolors'} = {};
8161: }
8162: }
1.9 raeburn 8163: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8164: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8165: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8166: $dom);
8167: if ($putresult eq 'ok') {
8168: if (keys(%changes) > 0) {
1.41 raeburn 8169: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8170: if (ref($lastactref) eq 'HASH') {
8171: $lastactref->{'domainconfig'} = 1;
8172: }
1.6 raeburn 8173: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8174: $rolehash{'rolecolors'});
8175: } else {
8176: $resulttext = &mt('No changes made to default color schemes');
8177: }
8178: } else {
1.11 albertel 8179: $resulttext = '<span class="LC_error">'.
8180: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8181: }
8182: if ($errors) {
8183: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8184: $errors.'</ul>';
8185: }
8186: return $resulttext;
8187: }
8188:
8189: sub modify_colors {
1.9 raeburn 8190: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8191: my (%changes,%choices);
1.51 raeburn 8192: my @bgs;
1.6 raeburn 8193: my @links = ('link','alink','vlink');
1.41 raeburn 8194: my @logintext;
1.6 raeburn 8195: my @images;
8196: my $servadm = $r->dir_config('lonAdmEMail');
8197: my $errors;
1.200 raeburn 8198: my %defaults;
1.6 raeburn 8199: foreach my $role (@{$roles}) {
8200: if ($role eq 'login') {
1.12 raeburn 8201: %choices = &login_choices();
1.41 raeburn 8202: @logintext = ('textcol','bgcol');
1.12 raeburn 8203: } else {
8204: %choices = &color_font_choices();
8205: }
8206: if ($role eq 'login') {
1.41 raeburn 8207: @images = ('img','logo','domlogo','login');
1.51 raeburn 8208: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8209: } else {
8210: @images = ('img');
1.200 raeburn 8211: @bgs = ('pgbg','tabbg','sidebg');
8212: }
8213: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8214: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8215: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8216: }
8217: if ($role eq 'login') {
8218: foreach my $item (@logintext) {
1.234 raeburn 8219: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8220: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8221: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8222: }
8223: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 8224: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8225: }
8226: }
8227: } else {
1.234 raeburn 8228: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8229: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8230: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8231: }
8232: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 8233: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8234: }
1.6 raeburn 8235: }
1.200 raeburn 8236: foreach my $item (@bgs) {
1.234 raeburn 8237: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8238: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8239: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8240: }
8241: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 8242: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8243: }
8244: }
8245: foreach my $item (@links) {
1.234 raeburn 8246: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8247: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8248: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8249: }
8250: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 8251: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8252: }
1.6 raeburn 8253: }
1.46 raeburn 8254: my ($configuserok,$author_ok,$switchserver) =
8255: &config_check($dom,$confname,$servadm);
1.9 raeburn 8256: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8257: if (ref($domconfig->{$role}) ne 'HASH') {
8258: $domconfig->{$role} = {};
8259: }
1.8 raeburn 8260: foreach my $img (@images) {
1.70 raeburn 8261: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8262: if (defined($env{'form.login_showlogo_'.$img})) {
8263: $confhash->{$role}{'showlogo'}{$img} = 1;
8264: } else {
8265: $confhash->{$role}{'showlogo'}{$img} = 0;
8266: }
8267: }
1.18 albertel 8268: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8269: && !defined($domconfig->{$role}{$img})
8270: && !$env{'form.'.$role.'_del_'.$img}
8271: && $env{'form.'.$role.'_import_'.$img}) {
8272: # import the old configured image from the .tab setting
8273: # if they haven't provided a new one
8274: $domconfig->{$role}{$img} =
8275: $env{'form.'.$role.'_import_'.$img};
8276: }
1.6 raeburn 8277: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8278: my $error;
1.6 raeburn 8279: if ($configuserok eq 'ok') {
1.9 raeburn 8280: if ($switchserver) {
1.12 raeburn 8281: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8282: } else {
8283: if ($author_ok eq 'ok') {
8284: my ($result,$logourl) =
8285: &publishlogo($r,'upload',$role.'_'.$img,
8286: $dom,$confname,$img,$width,$height);
8287: if ($result eq 'ok') {
8288: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8289: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8290: } else {
1.12 raeburn 8291: $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 8292: }
8293: } else {
1.46 raeburn 8294: $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 8295: }
8296: }
8297: } else {
1.46 raeburn 8298: $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 8299: }
8300: if ($error) {
1.8 raeburn 8301: &Apache::lonnet::logthis($error);
1.11 albertel 8302: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8303: }
8304: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8305: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8306: my $error;
8307: if ($configuserok eq 'ok') {
8308: # is confname an author?
8309: if ($switchserver eq '') {
8310: if ($author_ok eq 'ok') {
8311: my ($result,$logourl) =
8312: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8313: $dom,$confname,$img,$width,$height);
8314: if ($result eq 'ok') {
8315: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8316: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8317: }
8318: }
8319: }
8320: }
1.6 raeburn 8321: }
8322: }
8323: }
8324: if (ref($domconfig) eq 'HASH') {
8325: if (ref($domconfig->{$role}) eq 'HASH') {
8326: foreach my $img (@images) {
8327: if ($domconfig->{$role}{$img} ne '') {
8328: if ($env{'form.'.$role.'_del_'.$img}) {
8329: $confhash->{$role}{$img} = '';
1.12 raeburn 8330: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8331: } else {
1.9 raeburn 8332: if ($confhash->{$role}{$img} eq '') {
8333: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8334: }
1.6 raeburn 8335: }
8336: } else {
8337: if ($env{'form.'.$role.'_del_'.$img}) {
8338: $confhash->{$role}{$img} = '';
1.12 raeburn 8339: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8340: }
8341: }
1.70 raeburn 8342: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8343: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8344: if ($confhash->{$role}{'showlogo'}{$img} ne
8345: $domconfig->{$role}{'showlogo'}{$img}) {
8346: $changes{$role}{'showlogo'}{$img} = 1;
8347: }
8348: } else {
8349: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8350: $changes{$role}{'showlogo'}{$img} = 1;
8351: }
8352: }
8353: }
8354: }
1.6 raeburn 8355: if ($domconfig->{$role}{'font'} ne '') {
8356: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8357: $changes{$role}{'font'} = 1;
8358: }
8359: } else {
8360: if ($confhash->{$role}{'font'}) {
8361: $changes{$role}{'font'} = 1;
8362: }
8363: }
1.107 raeburn 8364: if ($role ne 'login') {
8365: if ($domconfig->{$role}{'fontmenu'} ne '') {
8366: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8367: $changes{$role}{'fontmenu'} = 1;
8368: }
8369: } else {
8370: if ($confhash->{$role}{'fontmenu'}) {
8371: $changes{$role}{'fontmenu'} = 1;
8372: }
1.97 tempelho 8373: }
8374: }
1.6 raeburn 8375: foreach my $item (@bgs) {
8376: if ($domconfig->{$role}{$item} ne '') {
8377: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8378: $changes{$role}{'bgs'}{$item} = 1;
8379: }
8380: } else {
8381: if ($confhash->{$role}{$item}) {
8382: $changes{$role}{'bgs'}{$item} = 1;
8383: }
8384: }
8385: }
8386: foreach my $item (@links) {
8387: if ($domconfig->{$role}{$item} ne '') {
8388: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8389: $changes{$role}{'links'}{$item} = 1;
8390: }
8391: } else {
8392: if ($confhash->{$role}{$item}) {
8393: $changes{$role}{'links'}{$item} = 1;
8394: }
8395: }
8396: }
1.41 raeburn 8397: foreach my $item (@logintext) {
8398: if ($domconfig->{$role}{$item} ne '') {
8399: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8400: $changes{$role}{'logintext'}{$item} = 1;
8401: }
8402: } else {
8403: if ($confhash->{$role}{$item}) {
8404: $changes{$role}{'logintext'}{$item} = 1;
8405: }
8406: }
8407: }
1.6 raeburn 8408: } else {
8409: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8410: \@logintext,$confhash,\%changes);
1.6 raeburn 8411: }
8412: } else {
8413: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8414: \@logintext,$confhash,\%changes);
1.6 raeburn 8415: }
8416: }
8417: return ($errors,%changes);
8418: }
8419:
1.46 raeburn 8420: sub config_check {
8421: my ($dom,$confname,$servadm) = @_;
8422: my ($configuserok,$author_ok,$switchserver,%currroles);
8423: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8424: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8425: $confname,$servadm);
8426: if ($configuserok eq 'ok') {
8427: $switchserver = &check_switchserver($dom,$confname);
8428: if ($switchserver eq '') {
8429: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8430: }
8431: }
8432: return ($configuserok,$author_ok,$switchserver);
8433: }
8434:
1.6 raeburn 8435: sub default_change_checker {
1.41 raeburn 8436: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8437: foreach my $item (@{$links}) {
8438: if ($confhash->{$role}{$item}) {
8439: $changes->{$role}{'links'}{$item} = 1;
8440: }
8441: }
8442: foreach my $item (@{$bgs}) {
8443: if ($confhash->{$role}{$item}) {
8444: $changes->{$role}{'bgs'}{$item} = 1;
8445: }
8446: }
1.41 raeburn 8447: foreach my $item (@{$logintext}) {
8448: if ($confhash->{$role}{$item}) {
8449: $changes->{$role}{'logintext'}{$item} = 1;
8450: }
8451: }
1.6 raeburn 8452: foreach my $img (@{$images}) {
8453: if ($env{'form.'.$role.'_del_'.$img}) {
8454: $confhash->{$role}{$img} = '';
1.12 raeburn 8455: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8456: }
1.70 raeburn 8457: if ($role eq 'login') {
8458: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8459: $changes->{$role}{'showlogo'}{$img} = 1;
8460: }
8461: }
1.6 raeburn 8462: }
8463: if ($confhash->{$role}{'font'}) {
8464: $changes->{$role}{'font'} = 1;
8465: }
1.48 raeburn 8466: }
1.6 raeburn 8467:
8468: sub display_colorchgs {
8469: my ($dom,$changes,$roles,$confhash) = @_;
8470: my (%choices,$resulttext);
8471: if (!grep(/^login$/,@{$roles})) {
8472: $resulttext = &mt('Changes made:').'<br />';
8473: }
8474: foreach my $role (@{$roles}) {
8475: if ($role eq 'login') {
8476: %choices = &login_choices();
8477: } else {
8478: %choices = &color_font_choices();
8479: }
8480: if (ref($changes->{$role}) eq 'HASH') {
8481: if ($role ne 'login') {
8482: $resulttext .= '<h4>'.&mt($role).'</h4>';
8483: }
8484: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8485: if ($role ne 'login') {
8486: $resulttext .= '<ul>';
8487: }
8488: if (ref($changes->{$role}{$key}) eq 'HASH') {
8489: if ($role ne 'login') {
8490: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8491: }
8492: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8493: if (($role eq 'login') && ($key eq 'showlogo')) {
8494: if ($confhash->{$role}{$key}{$item}) {
8495: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8496: } else {
8497: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8498: }
8499: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8500: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8501: } else {
1.12 raeburn 8502: my $newitem = $confhash->{$role}{$item};
8503: if ($key eq 'images') {
8504: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8505: }
8506: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8507: }
8508: }
8509: if ($role ne 'login') {
8510: $resulttext .= '</ul></li>';
8511: }
8512: } else {
8513: if ($confhash->{$role}{$key} eq '') {
8514: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8515: } else {
8516: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8517: }
8518: }
8519: if ($role ne 'login') {
8520: $resulttext .= '</ul>';
8521: }
8522: }
8523: }
8524: }
1.3 raeburn 8525: return $resulttext;
1.1 raeburn 8526: }
8527:
1.9 raeburn 8528: sub thumb_dimensions {
8529: return ('200','50');
8530: }
8531:
1.16 raeburn 8532: sub check_dimensions {
8533: my ($inputfile) = @_;
8534: my ($fullwidth,$fullheight);
8535: if ($inputfile =~ m|^[/\w.\-]+$|) {
8536: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8537: my $imageinfo = <PIPE>;
8538: if (!close(PIPE)) {
8539: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8540: }
8541: chomp($imageinfo);
8542: my ($fullsize) =
1.21 raeburn 8543: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8544: if ($fullsize) {
8545: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8546: }
8547: }
8548: }
8549: return ($fullwidth,$fullheight);
8550: }
8551:
1.9 raeburn 8552: sub check_configuser {
8553: my ($uhome,$dom,$confname,$servadm) = @_;
8554: my ($configuserok,%currroles);
8555: if ($uhome eq 'no_host') {
8556: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8557: my $configpass = &LONCAPA::Enrollment::create_password();
8558: $configuserok =
8559: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8560: $configpass,'','','','','',undef,$servadm);
8561: } else {
8562: $configuserok = 'ok';
8563: %currroles =
8564: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8565: }
8566: return ($configuserok,%currroles);
8567: }
8568:
8569: sub check_authorstatus {
8570: my ($dom,$confname,%currroles) = @_;
8571: my $author_ok;
1.40 raeburn 8572: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8573: my $start = time;
8574: my $end = 0;
8575: $author_ok =
8576: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8577: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8578: } else {
8579: $author_ok = 'ok';
8580: }
8581: return $author_ok;
8582: }
8583:
8584: sub publishlogo {
1.46 raeburn 8585: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 8586: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 8587: if ($action eq 'upload') {
8588: $fname=$env{'form.'.$formname.'.filename'};
8589: chop($env{'form.'.$formname});
8590: } else {
8591: ($fname) = ($formname =~ /([^\/]+)$/);
8592: }
1.46 raeburn 8593: if ($savefileas ne '') {
8594: $fname = $savefileas;
8595: }
1.9 raeburn 8596: $fname=&Apache::lonnet::clean_filename($fname);
8597: # See if there is anything left
8598: unless ($fname) { return ('error: no uploaded file'); }
8599: $fname="$subdir/$fname";
1.210 raeburn 8600: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 8601: my $filepath="$docroot/priv";
8602: my $relpath = "$dom/$confname";
1.9 raeburn 8603: my ($fnamepath,$file,$fetchthumb);
8604: $file=$fname;
8605: if ($fname=~m|/|) {
8606: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8607: }
1.164 raeburn 8608: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8609: my $count;
1.164 raeburn 8610: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8611: $filepath.="/$parts[$count]";
8612: if ((-e $filepath)!=1) {
8613: mkdir($filepath,02770);
8614: }
8615: }
8616: # Check for bad extension and disallow upload
8617: if ($file=~/\.(\w+)$/ &&
8618: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8619: $output =
1.207 bisitz 8620: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8621: } elsif ($file=~/\.(\w+)$/ &&
8622: !defined(&Apache::loncommon::fileembstyle($1))) {
8623: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8624: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 8625: $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 8626: } elsif (-d "$filepath/$file") {
1.195 bisitz 8627: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8628: } else {
8629: my $source = $filepath.'/'.$file;
8630: my $logfile;
8631: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 8632: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8633: }
8634: print $logfile
8635: "\n================= Publish ".localtime()." ================\n".
8636: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8637: # Save the file
8638: if (!open(FH,'>'.$source)) {
8639: &Apache::lonnet::logthis('Failed to create '.$source);
8640: return (&mt('Failed to create file'));
8641: }
8642: if ($action eq 'upload') {
8643: if (!print FH ($env{'form.'.$formname})) {
8644: &Apache::lonnet::logthis('Failed to write to '.$source);
8645: return (&mt('Failed to write file'));
8646: }
8647: } else {
8648: my $original = &Apache::lonnet::filelocation('',$formname);
8649: if(!copy($original,$source)) {
8650: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8651: return (&mt('Failed to write file'));
8652: }
8653: }
8654: close(FH);
8655: chmod(0660, $source); # Permissions to rw-rw---.
8656:
8657: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8658: my $copyfile=$targetdir.'/'.$file;
8659:
8660: my @parts=split(/\//,$targetdir);
8661: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8662: for (my $count=5;$count<=$#parts;$count++) {
8663: $path.="/$parts[$count]";
8664: if (!-e $path) {
8665: print $logfile "\nCreating directory ".$path;
8666: mkdir($path,02770);
8667: }
8668: }
8669: my $versionresult;
8670: if (-e $copyfile) {
8671: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8672: } else {
8673: $versionresult = 'ok';
8674: }
8675: if ($versionresult eq 'ok') {
8676: if (copy($source,$copyfile)) {
8677: print $logfile "\nCopied original source to ".$copyfile."\n";
8678: $output = 'ok';
8679: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8680: push(@{$modified_urls},[$copyfile,$source]);
8681: my $metaoutput =
8682: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8683: unless ($registered_cleanup) {
8684: my $handlers = $r->get_handlers('PerlCleanupHandler');
8685: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8686: $registered_cleanup=1;
8687: }
1.9 raeburn 8688: } else {
8689: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8690: $output = &mt('Failed to copy file to RES space').", $!";
8691: }
8692: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8693: my $inputfile = $filepath.'/'.$file;
8694: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8695: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8696: if ($fullwidth ne '' && $fullheight ne '') {
8697: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8698: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8699: system("convert -sample $thumbsize $inputfile $outfile");
8700: chmod(0660, $filepath.'/tn-'.$file);
8701: if (-e $outfile) {
8702: my $copyfile=$targetdir.'/tn-'.$file;
8703: if (copy($outfile,$copyfile)) {
8704: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8705: my $thumb_metaoutput =
8706: &write_metadata($dom,$confname,$formname,
8707: $targetdir,'tn-'.$file,$logfile);
8708: push(@{$modified_urls},[$copyfile,$outfile]);
8709: unless ($registered_cleanup) {
8710: my $handlers = $r->get_handlers('PerlCleanupHandler');
8711: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8712: $registered_cleanup=1;
8713: }
1.267 raeburn 8714: $madethumb = 1;
1.16 raeburn 8715: } else {
8716: print $logfile "\nUnable to write ".$copyfile.
8717: ':'.$!."\n";
8718: }
8719: }
1.9 raeburn 8720: }
8721: }
8722: }
8723: } else {
8724: $output = $versionresult;
8725: }
8726: }
1.267 raeburn 8727: return ($output,$logourl,$madethumb);
1.9 raeburn 8728: }
8729:
8730: sub logo_versioning {
8731: my ($targetdir,$file,$logfile) = @_;
8732: my $target = $targetdir.'/'.$file;
8733: my ($maxversion,$fn,$extn,$output);
8734: $maxversion = 0;
8735: if ($file =~ /^(.+)\.(\w+)$/) {
8736: $fn=$1;
8737: $extn=$2;
8738: }
8739: opendir(DIR,$targetdir);
8740: while (my $filename=readdir(DIR)) {
8741: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8742: $maxversion=($1>$maxversion)?$1:$maxversion;
8743: }
8744: }
8745: $maxversion++;
8746: print $logfile "\nCreating old version ".$maxversion."\n";
8747: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8748: if (copy($target,$copyfile)) {
8749: print $logfile "Copied old target to ".$copyfile."\n";
8750: $copyfile=$copyfile.'.meta';
8751: if (copy($target.'.meta',$copyfile)) {
8752: print $logfile "Copied old target metadata to ".$copyfile."\n";
8753: $output = 'ok';
8754: } else {
8755: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8756: $output = &mt('Failed to copy old meta').", $!, ";
8757: }
8758: } else {
8759: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8760: $output = &mt('Failed to copy old target').", $!, ";
8761: }
8762: return $output;
8763: }
8764:
8765: sub write_metadata {
8766: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8767: my (%metadatafields,%metadatakeys,$output);
8768: $metadatafields{'title'}=$formname;
8769: $metadatafields{'creationdate'}=time;
8770: $metadatafields{'lastrevisiondate'}=time;
8771: $metadatafields{'copyright'}='public';
8772: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8773: $env{'user.domain'};
8774: $metadatafields{'authorspace'}=$confname.':'.$dom;
8775: $metadatafields{'domain'}=$dom;
8776: {
8777: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8778: my $mfh;
1.155 raeburn 8779: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 8780: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8781: unless ($_=~/\./) {
8782: my $unikey=$_;
8783: $unikey=~/^([A-Za-z]+)/;
8784: my $tag=$1;
8785: $tag=~tr/A-Z/a-z/;
8786: print $mfh "\n\<$tag";
8787: foreach (split(/\,/,$metadatakeys{$unikey})) {
8788: my $value=$metadatafields{$unikey.'.'.$_};
8789: $value=~s/\"/\'\'/g;
8790: print $mfh ' '.$_.'="'.$value.'"';
8791: }
8792: print $mfh '>'.
8793: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8794: .'</'.$tag.'>';
8795: }
8796: }
8797: $output = 'ok';
8798: print $logfile "\nWrote metadata";
8799: close($mfh);
8800: } else {
8801: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8802: $output = &mt('Could not write metadata');
8803: }
8804: }
1.155 raeburn 8805: return $output;
8806: }
8807:
8808: sub notifysubscribed {
8809: foreach my $targetsource (@{$modified_urls}){
8810: next unless (ref($targetsource) eq 'ARRAY');
8811: my ($target,$source)=@{$targetsource};
8812: if ($source ne '') {
8813: if (open(my $logfh,'>>'.$source.'.log')) {
8814: print $logfh "\nCleanup phase: Notifications\n";
8815: my @subscribed=&subscribed_hosts($target);
8816: foreach my $subhost (@subscribed) {
8817: print $logfh "\nNotifying host ".$subhost.':';
8818: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8819: print $logfh $reply;
8820: }
8821: my @subscribedmeta=&subscribed_hosts("$target.meta");
8822: foreach my $subhost (@subscribedmeta) {
8823: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8824: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8825: $subhost);
8826: print $logfh $reply;
8827: }
8828: print $logfh "\n============ Done ============\n";
1.160 raeburn 8829: close($logfh);
1.155 raeburn 8830: }
8831: }
8832: }
8833: return OK;
8834: }
8835:
8836: sub subscribed_hosts {
8837: my ($target) = @_;
8838: my @subscribed;
8839: if (open(my $fh,"<$target.subscription")) {
8840: while (my $subline=<$fh>) {
8841: if ($subline =~ /^($match_lonid):/) {
8842: my $host = $1;
8843: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8844: unless (grep(/^\Q$host\E$/,@subscribed)) {
8845: push(@subscribed,$host);
8846: }
8847: }
8848: }
8849: }
8850: }
8851: return @subscribed;
1.9 raeburn 8852: }
8853:
8854: sub check_switchserver {
8855: my ($dom,$confname) = @_;
8856: my ($allowed,$switchserver);
8857: my $home = &Apache::lonnet::homeserver($confname,$dom);
8858: if ($home eq 'no_host') {
8859: $home = &Apache::lonnet::domain($dom,'primary');
8860: }
8861: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8862: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8863: if (!$allowed) {
1.180 raeburn 8864: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8865: }
8866: return $switchserver;
8867: }
8868:
1.1 raeburn 8869: sub modify_quotas {
1.216 raeburn 8870: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8871: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 8872: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 8873: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8874: $validationfieldsref);
1.86 raeburn 8875: if ($action eq 'quotas') {
8876: $context = 'tools';
1.163 raeburn 8877: } else {
1.86 raeburn 8878: $context = $action;
8879: }
8880: if ($context eq 'requestcourses') {
1.271 raeburn 8881: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 8882: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8883: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8884: %titles = &courserequest_titles();
8885: $toolregexp = join('|',@usertools);
8886: %conditions = &courserequest_conditions();
1.216 raeburn 8887: $confname = $dom.'-domainconfig';
8888: my $servadm = $r->dir_config('lonAdmEMail');
8889: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 8890: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8891: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 8892: } elsif ($context eq 'requestauthor') {
8893: @usertools = ('author');
8894: %titles = &authorrequest_titles();
1.86 raeburn 8895: } else {
1.162 raeburn 8896: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8897: %titles = &tool_titles();
1.86 raeburn 8898: }
1.212 raeburn 8899: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8900: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8901: foreach my $key (keys(%env)) {
1.101 raeburn 8902: if ($context eq 'requestcourses') {
8903: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8904: my $item = $1;
8905: my $type = $2;
8906: if ($type =~ /^limit_(.+)/) {
8907: $limithash{$item}{$1} = $env{$key};
8908: } else {
8909: $confhash{$item}{$type} = $env{$key};
8910: }
8911: }
1.163 raeburn 8912: } elsif ($context eq 'requestauthor') {
8913: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8914: $confhash{$1} = $env{$key};
8915: }
1.101 raeburn 8916: } else {
1.86 raeburn 8917: if ($key =~ /^form\.quota_(.+)$/) {
8918: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 8919: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8920: $confhash{'authorquota'}{$1} = $env{$key};
8921: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8922: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8923: }
1.72 raeburn 8924: }
8925: }
1.163 raeburn 8926: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 8927: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8928: @approvalnotify = sort(@approvalnotify);
8929: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 8930: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 8931: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8932: foreach my $type (@hasuniquecode) {
8933: if (grep(/^\Q$type\E$/,@crstypes)) {
8934: $confhash{'uniquecode'}{$type} = 1;
8935: }
1.216 raeburn 8936: }
1.242 raeburn 8937: my (%newbook,%allpos);
1.216 raeburn 8938: if ($context eq 'requestcourses') {
1.242 raeburn 8939: foreach my $type ('textbooks','templates') {
8940: @{$allpos{$type}} = ();
8941: my $invalid;
8942: if ($type eq 'textbooks') {
8943: $invalid = &mt('Invalid LON-CAPA course for textbook');
8944: } else {
8945: $invalid = &mt('Invalid LON-CAPA course for template');
8946: }
8947: if ($env{'form.'.$type.'_addbook'}) {
8948: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8949: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8950: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8951: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8952: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8953: } else {
8954: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8955: my $position = $env{'form.'.$type.'_addbook_pos'};
8956: $position =~ s/\D+//g;
8957: if ($position ne '') {
8958: $allpos{$type}[$position] = $newbook{$type};
8959: }
1.216 raeburn 8960: }
1.242 raeburn 8961: } else {
8962: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8963: }
8964: }
1.242 raeburn 8965: }
1.216 raeburn 8966: }
1.102 raeburn 8967: if (ref($domconfig{$action}) eq 'HASH') {
8968: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8969: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8970: $changes{'notify'}{'approval'} = 1;
8971: }
8972: } else {
1.144 raeburn 8973: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8974: $changes{'notify'}{'approval'} = 1;
8975: }
8976: }
1.218 raeburn 8977: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8978: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8979: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8980: unless ($confhash{'uniquecode'}{$crstype}) {
8981: $changes{'uniquecode'} = 1;
8982: }
8983: }
8984: unless ($changes{'uniquecode'}) {
8985: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8986: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8987: $changes{'uniquecode'} = 1;
8988: }
8989: }
8990: }
8991: } else {
8992: $changes{'uniquecode'} = 1;
8993: }
8994: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8995: $changes{'uniquecode'} = 1;
1.216 raeburn 8996: }
8997: if ($context eq 'requestcourses') {
1.242 raeburn 8998: foreach my $type ('textbooks','templates') {
8999: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9000: my %deletions;
9001: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
9002: if (@todelete) {
9003: map { $deletions{$_} = 1; } @todelete;
9004: }
9005: my %imgdeletions;
9006: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
9007: if (@todeleteimages) {
9008: map { $imgdeletions{$_} = 1; } @todeleteimages;
9009: }
9010: my $maxnum = $env{'form.'.$type.'_maxnum'};
9011: for (my $i=0; $i<=$maxnum; $i++) {
9012: my $itemid = $env{'form.'.$type.'_id_'.$i};
9013: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
9014: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
9015: if ($deletions{$key}) {
9016: if ($domconfig{$action}{$type}{$key}{'image'}) {
9017: #FIXME need to obsolete item in RES space
9018: }
9019: next;
9020: } else {
9021: my $newpos = $env{'form.'.$itemid};
9022: $newpos =~ s/\D+//g;
1.243 raeburn 9023: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 9024: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 9025: ($type eq 'templates'));
1.242 raeburn 9026: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
9027: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
9028: $changes{$type}{$key} = 1;
9029: }
9030: }
9031: $allpos{$type}[$newpos] = $key;
9032: }
9033: if ($imgdeletions{$key}) {
9034: $changes{$type}{$key} = 1;
1.216 raeburn 9035: #FIXME need to obsolete item in RES space
1.242 raeburn 9036: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
9037: my ($cdom,$cnum) = split(/_/,$key);
9038: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
9039: $cdom,$cnum,$type,$configuserok,
9040: $switchserver,$author_ok);
9041: if ($imgurl) {
9042: $confhash{$type}{$key}{'image'} = $imgurl;
9043: $changes{$type}{$key} = 1;
1.216 raeburn 9044: }
1.242 raeburn 9045: if ($error) {
9046: &Apache::lonnet::logthis($error);
9047: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9048: }
9049: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
9050: $confhash{$type}{$key}{'image'} =
9051: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 9052: }
9053: }
9054: }
9055: }
9056: }
9057: }
1.102 raeburn 9058: } else {
1.144 raeburn 9059: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 9060: $changes{'notify'}{'approval'} = 1;
9061: }
1.218 raeburn 9062: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 9063: $changes{'uniquecode'} = 1;
9064: }
9065: }
9066: if ($context eq 'requestcourses') {
1.242 raeburn 9067: foreach my $type ('textbooks','templates') {
9068: if ($newbook{$type}) {
9069: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 9070: foreach my $item ('subject','title','publisher','author') {
9071: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9072: ($type eq 'template'));
1.242 raeburn 9073: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
9074: if ($env{'form.'.$type.'_addbook_'.$item}) {
9075: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
9076: }
9077: }
9078: if ($type eq 'textbooks') {
9079: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
9080: my ($cdom,$cnum) = split(/_/,$newbook{$type});
9081: my ($imageurl,$error) =
9082: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
9083: $configuserok,$switchserver,$author_ok);
9084: if ($imageurl) {
9085: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
9086: }
9087: if ($error) {
9088: &Apache::lonnet::logthis($error);
9089: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9090: }
9091: }
1.216 raeburn 9092: }
9093: }
1.242 raeburn 9094: if (@{$allpos{$type}} > 0) {
9095: my $idx = 0;
9096: foreach my $item (@{$allpos{$type}}) {
9097: if ($item ne '') {
9098: $confhash{$type}{$item}{'order'} = $idx;
9099: if (ref($domconfig{$action}) eq 'HASH') {
9100: if (ref($domconfig{$action}{$type}) eq 'HASH') {
9101: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
9102: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
9103: $changes{$type}{$item} = 1;
9104: }
1.216 raeburn 9105: }
9106: }
9107: }
1.242 raeburn 9108: $idx ++;
1.216 raeburn 9109: }
9110: }
9111: }
9112: }
1.235 raeburn 9113: if (ref($validationitemsref) eq 'ARRAY') {
9114: foreach my $item (@{$validationitemsref}) {
9115: if ($item eq 'fields') {
9116: my @changed;
9117: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
9118: if (@{$confhash{'validation'}{$item}} > 0) {
9119: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
9120: }
1.266 raeburn 9121: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9122: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9123: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
9124: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
9125: $domconfig{'requestcourses'}{'validation'}{$item});
9126: } else {
9127: @changed = @{$confhash{'validation'}{$item}};
9128: }
1.235 raeburn 9129: } else {
9130: @changed = @{$confhash{'validation'}{$item}};
9131: }
9132: } else {
9133: @changed = @{$confhash{'validation'}{$item}};
9134: }
9135: if (@changed) {
9136: if ($confhash{'validation'}{$item}) {
9137: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9138: } else {
9139: $changes{'validation'}{$item} = &mt('None');
9140: }
9141: }
9142: } else {
9143: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9144: if ($item eq 'markup') {
9145: if ($env{'form.requestcourses_validation_'.$item}) {
9146: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9147: }
9148: }
1.266 raeburn 9149: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9150: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9151: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9152: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9153: }
9154: } else {
9155: if ($confhash{'validation'}{$item} ne '') {
9156: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9157: }
1.235 raeburn 9158: }
9159: } else {
9160: if ($confhash{'validation'}{$item} ne '') {
9161: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9162: }
9163: }
9164: }
9165: }
9166: }
9167: if ($env{'form.validationdc'}) {
9168: my $newval = $env{'form.validationdc'};
1.285 raeburn 9169: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 9170: if (exists($domcoords{$newval})) {
9171: $confhash{'validation'}{'dc'} = $newval;
9172: }
9173: }
9174: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 9175: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9176: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9177: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9178: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9179: if ($confhash{'validation'}{'dc'} eq '') {
9180: $changes{'validation'}{'dc'} = &mt('None');
9181: } else {
9182: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9183: }
1.235 raeburn 9184: }
1.266 raeburn 9185: } elsif ($confhash{'validation'}{'dc'} ne '') {
9186: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 9187: }
9188: } elsif ($confhash{'validation'}{'dc'} ne '') {
9189: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9190: }
9191: } elsif ($confhash{'validation'}{'dc'} ne '') {
9192: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 9193: }
1.266 raeburn 9194: } else {
9195: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9196: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9197: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9198: $changes{'validation'}{'dc'} = &mt('None');
9199: }
9200: }
1.235 raeburn 9201: }
9202: }
1.102 raeburn 9203: }
9204: } else {
1.86 raeburn 9205: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 9206: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9207: }
1.72 raeburn 9208: foreach my $item (@usertools) {
9209: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9210: my $unset;
1.101 raeburn 9211: if ($context eq 'requestcourses') {
1.104 raeburn 9212: $unset = '0';
9213: if ($type eq '_LC_adv') {
9214: $unset = '';
9215: }
1.101 raeburn 9216: if ($confhash{$item}{$type} eq 'autolimit') {
9217: $confhash{$item}{$type} .= '=';
9218: unless ($limithash{$item}{$type} =~ /\D/) {
9219: $confhash{$item}{$type} .= $limithash{$item}{$type};
9220: }
9221: }
1.163 raeburn 9222: } elsif ($context eq 'requestauthor') {
9223: $unset = '0';
9224: if ($type eq '_LC_adv') {
9225: $unset = '';
9226: }
1.72 raeburn 9227: } else {
1.101 raeburn 9228: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9229: $confhash{$item}{$type} = 1;
9230: } else {
9231: $confhash{$item}{$type} = 0;
9232: }
1.72 raeburn 9233: }
1.86 raeburn 9234: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 9235: if ($action eq 'requestauthor') {
9236: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9237: $changes{$type} = 1;
9238: }
9239: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9240: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9241: $changes{$item}{$type} = 1;
9242: }
9243: } else {
9244: if ($context eq 'requestcourses') {
1.104 raeburn 9245: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9246: $changes{$item}{$type} = 1;
9247: }
9248: } else {
9249: if (!$confhash{$item}{$type}) {
9250: $changes{$item}{$type} = 1;
9251: }
9252: }
9253: }
9254: } else {
9255: if ($context eq 'requestcourses') {
1.104 raeburn 9256: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9257: $changes{$item}{$type} = 1;
9258: }
1.163 raeburn 9259: } elsif ($context eq 'requestauthor') {
9260: if ($confhash{$type} ne $unset) {
9261: $changes{$type} = 1;
9262: }
1.72 raeburn 9263: } else {
9264: if (!$confhash{$item}{$type}) {
9265: $changes{$item}{$type} = 1;
9266: }
9267: }
9268: }
1.1 raeburn 9269: }
9270: }
1.163 raeburn 9271: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9272: if (ref($domconfig{'quotas'}) eq 'HASH') {
9273: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9274: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9275: if (exists($confhash{'defaultquota'}{$key})) {
9276: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9277: $changes{'defaultquota'}{$key} = 1;
9278: }
9279: } else {
9280: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9281: }
9282: }
1.86 raeburn 9283: } else {
9284: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9285: if (exists($confhash{'defaultquota'}{$key})) {
9286: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9287: $changes{'defaultquota'}{$key} = 1;
9288: }
9289: } else {
9290: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9291: }
1.1 raeburn 9292: }
9293: }
1.197 raeburn 9294: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9295: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9296: if (exists($confhash{'authorquota'}{$key})) {
9297: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9298: $changes{'authorquota'}{$key} = 1;
9299: }
9300: } else {
9301: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9302: }
9303: }
9304: }
1.1 raeburn 9305: }
1.86 raeburn 9306: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9307: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9308: if (ref($domconfig{'quotas'}) eq 'HASH') {
9309: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9310: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9311: $changes{'defaultquota'}{$key} = 1;
9312: }
9313: } else {
9314: if (!exists($domconfig{'quotas'}{$key})) {
9315: $changes{'defaultquota'}{$key} = 1;
9316: }
1.72 raeburn 9317: }
9318: } else {
1.86 raeburn 9319: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9320: }
1.1 raeburn 9321: }
9322: }
1.197 raeburn 9323: if (ref($confhash{'authorquota'}) eq 'HASH') {
9324: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9325: if (ref($domconfig{'quotas'}) eq 'HASH') {
9326: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9327: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9328: $changes{'authorquota'}{$key} = 1;
9329: }
9330: } else {
9331: $changes{'authorquota'}{$key} = 1;
9332: }
9333: } else {
9334: $changes{'authorquota'}{$key} = 1;
9335: }
9336: }
9337: }
1.1 raeburn 9338: }
1.72 raeburn 9339:
1.163 raeburn 9340: if ($context eq 'requestauthor') {
9341: $domdefaults{'requestauthor'} = \%confhash;
9342: } else {
9343: foreach my $key (keys(%confhash)) {
1.242 raeburn 9344: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 9345: $domdefaults{$key} = $confhash{$key};
9346: }
1.163 raeburn 9347: }
1.72 raeburn 9348: }
1.163 raeburn 9349:
1.1 raeburn 9350: my %quotahash = (
1.86 raeburn 9351: $action => { %confhash }
1.1 raeburn 9352: );
9353: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9354: $dom);
9355: if ($putresult eq 'ok') {
9356: if (keys(%changes) > 0) {
1.72 raeburn 9357: my $cachetime = 24*60*60;
9358: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9359: if (ref($lastactref) eq 'HASH') {
9360: $lastactref->{'domdefaults'} = 1;
9361: }
1.1 raeburn 9362: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 9363: unless (($context eq 'requestcourses') ||
1.163 raeburn 9364: ($context eq 'requestauthor')) {
1.86 raeburn 9365: if (ref($changes{'defaultquota'}) eq 'HASH') {
9366: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9367: foreach my $type (@{$types},'default') {
9368: if (defined($changes{'defaultquota'}{$type})) {
9369: my $typetitle = $usertypes->{$type};
9370: if ($type eq 'default') {
9371: $typetitle = $othertitle;
9372: }
1.213 raeburn 9373: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9374: }
9375: }
1.86 raeburn 9376: $resulttext .= '</ul></li>';
1.72 raeburn 9377: }
1.197 raeburn 9378: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 9379: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 9380: foreach my $type (@{$types},'default') {
9381: if (defined($changes{'authorquota'}{$type})) {
9382: my $typetitle = $usertypes->{$type};
9383: if ($type eq 'default') {
9384: $typetitle = $othertitle;
9385: }
1.213 raeburn 9386: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 9387: }
9388: }
9389: $resulttext .= '</ul></li>';
9390: }
1.72 raeburn 9391: }
1.80 raeburn 9392: my %newenv;
1.72 raeburn 9393: foreach my $item (@usertools) {
1.163 raeburn 9394: my (%haschgs,%inconf);
9395: if ($context eq 'requestauthor') {
9396: %haschgs = %changes;
1.210 raeburn 9397: %inconf = %confhash;
1.163 raeburn 9398: } else {
9399: if (ref($changes{$item}) eq 'HASH') {
9400: %haschgs = %{$changes{$item}};
9401: }
9402: if (ref($confhash{$item}) eq 'HASH') {
9403: %inconf = %{$confhash{$item}};
9404: }
9405: }
9406: if (keys(%haschgs) > 0) {
1.80 raeburn 9407: my $newacc =
9408: &Apache::lonnet::usertools_access($env{'user.name'},
9409: $env{'user.domain'},
1.86 raeburn 9410: $item,'reload',$context);
1.210 raeburn 9411: if (($context eq 'requestcourses') ||
1.163 raeburn 9412: ($context eq 'requestauthor')) {
1.108 raeburn 9413: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9414: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9415: }
9416: } else {
9417: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9418: $newenv{'environment.availabletools.'.$item} = $newacc;
9419: }
1.80 raeburn 9420: }
1.163 raeburn 9421: unless ($context eq 'requestauthor') {
9422: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9423: }
1.72 raeburn 9424: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 9425: if ($haschgs{$type}) {
1.72 raeburn 9426: my $typetitle = $usertypes->{$type};
9427: if ($type eq 'default') {
9428: $typetitle = $othertitle;
9429: } elsif ($type eq '_LC_adv') {
9430: $typetitle = 'LON-CAPA Advanced Users';
9431: }
1.163 raeburn 9432: if ($inconf{$type}) {
1.101 raeburn 9433: if ($context eq 'requestcourses') {
9434: my $cond;
1.163 raeburn 9435: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9436: if ($1 eq '') {
9437: $cond = &mt('(Automatic processing of any request).');
9438: } else {
9439: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9440: }
9441: } else {
1.163 raeburn 9442: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9443: }
9444: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 9445: } elsif ($context eq 'requestauthor') {
9446: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9447: $titles{$inconf{$type}},$typetitle);
9448:
1.101 raeburn 9449: } else {
9450: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9451: }
1.72 raeburn 9452: } else {
1.104 raeburn 9453: if ($type eq '_LC_adv') {
1.163 raeburn 9454: if ($inconf{$type} eq '0') {
1.104 raeburn 9455: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9456: } else {
9457: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9458: }
9459: } else {
9460: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9461: }
1.72 raeburn 9462: }
9463: }
1.26 raeburn 9464: }
1.163 raeburn 9465: unless ($context eq 'requestauthor') {
9466: $resulttext .= '</ul></li>';
9467: }
1.26 raeburn 9468: }
1.1 raeburn 9469: }
1.163 raeburn 9470: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9471: if (ref($changes{'notify'}) eq 'HASH') {
9472: if ($changes{'notify'}{'approval'}) {
9473: if (ref($confhash{'notify'}) eq 'HASH') {
9474: if ($confhash{'notify'}{'approval'}) {
9475: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9476: } else {
1.163 raeburn 9477: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9478: }
9479: }
9480: }
9481: }
9482: }
1.216 raeburn 9483: if ($action eq 'requestcourses') {
9484: my @offon = ('off','on');
9485: if ($changes{'uniquecode'}) {
1.218 raeburn 9486: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9487: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9488: $resulttext .= '<li>'.
9489: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9490: '</li>';
9491: } else {
9492: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9493: '</li>';
9494: }
1.216 raeburn 9495: }
1.242 raeburn 9496: foreach my $type ('textbooks','templates') {
9497: if (ref($changes{$type}) eq 'HASH') {
9498: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9499: foreach my $key (sort(keys(%{$changes{$type}}))) {
9500: my %coursehash = &Apache::lonnet::coursedescription($key);
9501: my $coursetitle = $coursehash{'description'};
9502: my $position = $confhash{$type}{$key}{'order'} + 1;
9503: $resulttext .= '<li>';
1.243 raeburn 9504: foreach my $item ('subject','title','publisher','author') {
9505: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9506: ($type eq 'templates'));
1.242 raeburn 9507: my $name = $item.':';
9508: $name =~ s/^(\w)/\U$1/;
9509: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9510: }
9511: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9512: if ($type eq 'textbooks') {
9513: if ($confhash{$type}{$key}{'image'}) {
9514: $resulttext .= ' '.&mt('Image: [_1]',
9515: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9516: ' alt="Textbook cover" />').'<br />';
9517: }
9518: }
9519: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 9520: }
1.242 raeburn 9521: $resulttext .= '</ul></li>';
1.216 raeburn 9522: }
9523: }
1.235 raeburn 9524: if (ref($changes{'validation'}) eq 'HASH') {
9525: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9526: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9527: foreach my $item (@{$validationitemsref}) {
9528: if (exists($changes{'validation'}{$item})) {
9529: if ($item eq 'markup') {
9530: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9531: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9532: } else {
9533: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9534: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9535: }
9536: }
9537: }
9538: if (exists($changes{'validation'}{'dc'})) {
9539: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9540: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9541: }
9542: }
9543: }
1.216 raeburn 9544: }
1.1 raeburn 9545: $resulttext .= '</ul>';
1.80 raeburn 9546: if (keys(%newenv)) {
9547: &Apache::lonnet::appenv(\%newenv);
9548: }
1.1 raeburn 9549: } else {
1.86 raeburn 9550: if ($context eq 'requestcourses') {
9551: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 9552: } elsif ($context eq 'requestauthor') {
9553: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9554: } else {
1.90 weissno 9555: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9556: }
1.1 raeburn 9557: }
9558: } else {
1.11 albertel 9559: $resulttext = '<span class="LC_error">'.
9560: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9561: }
1.216 raeburn 9562: if ($errors) {
9563: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9564: '<ul>'.$errors.'</ul></p>';
9565: }
1.3 raeburn 9566: return $resulttext;
1.1 raeburn 9567: }
9568:
1.216 raeburn 9569: sub process_textbook_image {
1.242 raeburn 9570: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 9571: my $filename = $env{'form.'.$caller.'.filename'};
9572: my ($error,$url);
9573: my ($width,$height) = (50,50);
9574: if ($configuserok eq 'ok') {
9575: if ($switchserver) {
9576: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9577: $switchserver);
9578: } elsif ($author_ok eq 'ok') {
9579: my ($result,$imageurl) =
9580: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 9581: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 9582: if ($result eq 'ok') {
9583: $url = $imageurl;
9584: } else {
9585: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9586: }
9587: } else {
9588: $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);
9589: }
9590: } else {
9591: $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);
9592: }
9593: return ($url,$error);
9594: }
9595:
1.267 raeburn 9596: sub modify_ltitools {
9597: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9598: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297 raeburn 9599: my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267 raeburn 9600: my $confname = $dom.'-domainconfig';
9601: my $servadm = $r->dir_config('lonAdmEMail');
9602: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9603: my (%posslti,%possfield);
9604: my @courseroles = ('cc','in','ta','ep','st');
9605: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9606: map { $posslti{$_} = 1; } @ltiroles;
9607: my @allfields = ('fullname','firstname','lastname','email','user','roles');
9608: map { $possfield{$_} = 1; } @allfields;
9609: my %lt = <itools_names();
9610: if ($env{'form.ltitools_add'}) {
9611: my $title = $env{'form.ltitools_add_title'};
9612: $title =~ s/(`)/'/g;
9613: ($newid,my $error) = &get_ltitools_id($dom,$title);
9614: if ($newid) {
9615: my $position = $env{'form.ltitools_add_pos'};
9616: $position =~ s/\D+//g;
9617: if ($position ne '') {
9618: $allpos[$position] = $newid;
9619: }
9620: $changes{$newid} = 1;
9621: foreach my $item ('title','url','key','secret') {
9622: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9623: if ($env{'form.ltitools_add_'.$item}) {
1.297 raeburn 9624: if (($item eq 'key') || ($item eq 'secret')) {
9625: $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9626: } else {
9627: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9628: }
1.267 raeburn 9629: }
9630: }
9631: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9632: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9633: }
9634: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9635: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9636: }
1.296 raeburn 9637: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 9638: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9639: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 raeburn 9640: if (($item eq 'width') || ($item eq 'height')) {
9641: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9642: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9643: }
9644: } else {
9645: if ($env{'form.ltitools_add_'.$item} ne '') {
9646: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9647: }
1.267 raeburn 9648: }
9649: }
9650: if ($env{'form.ltitools_add_target'} eq 'window') {
9651: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298 raeburn 9652: } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
9653: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267 raeburn 9654: } else {
9655: $confhash{$newid}{'display'}{'target'} = 'iframe';
9656: }
9657: foreach my $item ('passback','roster') {
9658: if ($env{'form.ltitools_add_'.$item}) {
9659: $confhash{$newid}{$item} = 1;
9660: }
9661: }
9662: if ($env{'form.ltitools_add_image.filename'} ne '') {
9663: my ($imageurl,$error) =
9664: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
9665: $configuserok,$switchserver,$author_ok);
9666: if ($imageurl) {
9667: $confhash{$newid}{'image'} = $imageurl;
9668: }
9669: if ($error) {
9670: &Apache::lonnet::logthis($error);
9671: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9672: }
9673: }
9674: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9675: foreach my $field (@fields) {
9676: if ($possfield{$field}) {
9677: if ($field eq 'roles') {
9678: foreach my $role (@courseroles) {
9679: my $choice = $env{'form.ltitools_add_roles_'.$role};
9680: if (($choice ne '') && ($posslti{$choice})) {
9681: $confhash{$newid}{'roles'}{$role} = $choice;
9682: if ($role eq 'cc') {
9683: $confhash{$newid}{'roles'}{'co'} = $choice;
9684: }
9685: }
9686: }
9687: } else {
9688: $confhash{$newid}{'fields'}{$field} = 1;
9689: }
9690: }
9691: }
1.273 raeburn 9692: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9693: foreach my $item (@courseconfig) {
9694: $confhash{$newid}{'crsconf'}{$item} = 1;
9695: }
1.267 raeburn 9696: if ($env{'form.ltitools_add_custom'}) {
9697: my $name = $env{'form.ltitools_add_custom_name'};
9698: my $value = $env{'form.ltitools_add_custom_value'};
9699: $value =~ s/(`)/'/g;
9700: $name =~ s/(`)/'/g;
9701: $confhash{$newid}{'custom'}{$name} = $value;
9702: }
9703: } else {
9704: my $error = &mt('Failed to acquire unique ID for new external tool');
9705: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9706: }
9707: }
9708: if (ref($domconfig{$action}) eq 'HASH') {
9709: my %deletions;
9710: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9711: if (@todelete) {
9712: map { $deletions{$_} = 1; } @todelete;
9713: }
9714: my %customadds;
9715: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9716: if (@newcustom) {
9717: map { $customadds{$_} = 1; } @newcustom;
9718: }
9719: my %imgdeletions;
9720: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9721: if (@todeleteimages) {
9722: map { $imgdeletions{$_} = 1; } @todeleteimages;
9723: }
9724: my $maxnum = $env{'form.ltitools_maxnum'};
9725: for (my $i=0; $i<=$maxnum; $i++) {
9726: my $itemid = $env{'form.ltitools_id_'.$i};
9727: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9728: if ($deletions{$itemid}) {
9729: if ($domconfig{$action}{$itemid}{'image'}) {
9730: #FIXME need to obsolete item in RES space
9731: }
9732: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9733: next;
9734: } else {
9735: my $newpos = $env{'form.ltitools_'.$itemid};
9736: $newpos =~ s/\D+//g;
1.297 raeburn 9737: foreach my $item ('title','url') {
1.267 raeburn 9738: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9739: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9740: $changes{$itemid} = 1;
9741: }
9742: }
1.297 raeburn 9743: foreach my $item ('key','secret') {
9744: $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9745: if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
9746: $changes{$itemid} = 1;
9747: }
9748: }
1.267 raeburn 9749: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9750: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9751: }
9752: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9753: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9754: }
9755: foreach my $size ('width','height') {
9756: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9757: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9758: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9759: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9760: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9761: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9762: $changes{$itemid} = 1;
9763: }
9764: } else {
9765: $changes{$itemid} = 1;
9766: }
1.296 raeburn 9767: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9768: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
9769: $changes{$itemid} = 1;
9770: }
9771: }
9772: }
9773: foreach my $item ('linktext','explanation') {
9774: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
9775: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
9776: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
9777: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9778: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9779: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
9780: $changes{$itemid} = 1;
9781: }
9782: } else {
9783: $changes{$itemid} = 1;
9784: }
9785: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9786: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
9787: $changes{$itemid} = 1;
9788: }
1.267 raeburn 9789: }
9790: }
9791: if ($env{'form.ltitools_target_'.$i} eq 'window') {
9792: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298 raeburn 9793: } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
9794: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267 raeburn 9795: } else {
9796: $confhash{$itemid}{'display'}{'target'} = 'iframe';
9797: }
9798: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9799: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
9800: $changes{$itemid} = 1;
9801: }
9802: } else {
9803: $changes{$itemid} = 1;
9804: }
9805: foreach my $extra ('passback','roster') {
9806: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
9807: $confhash{$itemid}{$extra} = 1;
9808: }
9809: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
9810: $changes{$itemid} = 1;
9811: }
9812: }
1.273 raeburn 9813: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.296 raeburn 9814: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 9815: if (grep(/^\Q$item\E$/,@courseconfig)) {
9816: $confhash{$itemid}{'crsconf'}{$item} = 1;
9817: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
9818: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
9819: $changes{$itemid} = 1;
9820: }
9821: } else {
9822: $changes{$itemid} = 1;
9823: }
9824: }
9825: }
1.267 raeburn 9826: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
9827: foreach my $field (@fields) {
9828: if ($possfield{$field}) {
9829: if ($field eq 'roles') {
9830: foreach my $role (@courseroles) {
9831: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
9832: if (($choice ne '') && ($posslti{$choice})) {
9833: $confhash{$itemid}{'roles'}{$role} = $choice;
9834: if ($role eq 'cc') {
9835: $confhash{$itemid}{'roles'}{'co'} = $choice;
9836: }
9837: }
9838: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
9839: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
9840: $changes{$itemid} = 1;
9841: }
9842: } elsif ($confhash{$itemid}{'roles'}{$role}) {
9843: $changes{$itemid} = 1;
9844: }
9845: }
9846: } else {
9847: $confhash{$itemid}{'fields'}{$field} = 1;
9848: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9849: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9850: $changes{$itemid} = 1;
9851: }
9852: } else {
9853: $changes{$itemid} = 1;
9854: }
9855: }
9856: }
9857: }
9858: $allpos[$newpos] = $itemid;
9859: }
9860: if ($imgdeletions{$itemid}) {
9861: $changes{$itemid} = 1;
9862: #FIXME need to obsolete item in RES space
9863: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9864: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9865: $itemid,$configuserok,$switchserver,
9866: $author_ok);
9867: if ($imgurl) {
9868: $confhash{$itemid}{'image'} = $imgurl;
9869: $changes{$itemid} = 1;
9870: }
9871: if ($error) {
9872: &Apache::lonnet::logthis($error);
9873: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9874: }
9875: } elsif ($domconfig{$action}{$itemid}{'image'}) {
9876: $confhash{$itemid}{'image'} =
9877: $domconfig{$action}{$itemid}{'image'};
9878: }
9879: if ($customadds{$i}) {
9880: my $name = $env{'form.ltitools_custom_name_'.$i};
9881: $name =~ s/(`)/'/g;
9882: $name =~ s/^\s+//;
9883: $name =~ s/\s+$//;
9884: my $value = $env{'form.ltitools_custom_value_'.$i};
9885: $value =~ s/(`)/'/g;
9886: $value =~ s/^\s+//;
9887: $value =~ s/\s+$//;
9888: if ($name ne '') {
9889: $confhash{$itemid}{'custom'}{$name} = $value;
9890: $changes{$itemid} = 1;
9891: }
9892: }
9893: my %customdels;
9894: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9895: if (@customdeletions) {
9896: $changes{$itemid} = 1;
9897: }
9898: map { $customdels{$_} = 1; } @customdeletions;
9899: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9900: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9901: unless ($customdels{$key}) {
9902: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9903: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9904: }
9905: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9906: $changes{$itemid} = 1;
9907: }
9908: }
9909: }
9910: }
9911: unless ($changes{$itemid}) {
9912: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9913: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9914: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9915: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9916: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9917: $changes{$itemid} = 1;
9918: last;
9919: }
9920: }
9921: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9922: $changes{$itemid} = 1;
9923: }
9924: }
9925: last if ($changes{$itemid});
9926: }
9927: }
9928: }
9929: }
9930: }
9931: if (@allpos > 0) {
9932: my $idx = 0;
9933: foreach my $itemid (@allpos) {
9934: if ($itemid ne '') {
9935: $confhash{$itemid}{'order'} = $idx;
9936: if (ref($domconfig{$action}) eq 'HASH') {
9937: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9938: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9939: $changes{$itemid} = 1;
9940: }
9941: }
9942: }
9943: $idx ++;
9944: }
9945: }
9946: }
9947: my %ltitoolshash = (
9948: $action => { %confhash }
9949: );
9950: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9951: $dom);
9952: if ($putresult eq 'ok') {
1.297 raeburn 9953: my %ltienchash = (
9954: $action => { %encconfig }
9955: );
9956: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267 raeburn 9957: if (keys(%changes) > 0) {
9958: my $cachetime = 24*60*60;
1.297 raeburn 9959: my %ltiall = %confhash;
9960: foreach my $id (keys(%ltiall)) {
9961: if (ref($encconfig{$id}) eq 'HASH') {
9962: foreach my $item ('key','secret') {
9963: $ltiall{$id}{$item} = $encconfig{$id}{$item};
9964: }
9965: }
9966: }
9967: &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267 raeburn 9968: if (ref($lastactref) eq 'HASH') {
9969: $lastactref->{'ltitools'} = 1;
9970: }
9971: $resulttext = &mt('Changes made:').'<ul>';
9972: my %bynum;
9973: foreach my $itemid (sort(keys(%changes))) {
9974: my $position = $confhash{$itemid}{'order'};
9975: $bynum{$position} = $itemid;
9976: }
9977: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9978: my $itemid = $bynum{$pos};
9979: if (ref($confhash{$itemid}) ne 'HASH') {
9980: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9981: } else {
9982: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9983: if ($confhash{$itemid}{'image'}) {
9984: $resulttext .= ' '.
9985: '<img src="'.$confhash{$itemid}{'image'}.'"'.
9986: ' alt="'.&mt('Tool Provider icon').'" />';
9987: }
9988: $resulttext .= '</li><ul>';
9989: my $position = $pos + 1;
9990: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.297 raeburn 9991: foreach my $item ('version','msgtype','url') {
1.267 raeburn 9992: if ($confhash{$itemid}{$item} ne '') {
9993: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9994: }
9995: }
1.297 raeburn 9996: if ($encconfig{$itemid}{'key'} ne '') {
9997: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
9998: }
9999: if ($encconfig{$itemid}{'secret'} ne '') {
1.267 raeburn 10000: $resulttext .= '<li>'.$lt{'secret'}.': ';
1.297 raeburn 10001: my $num = length($encconfig{$itemid}{'secret'});
1.267 raeburn 10002: $resulttext .= ('*'x$num).'</li>';
10003: }
1.273 raeburn 10004: $resulttext .= '<li>'.&mt('Configurable in course:');
1.296 raeburn 10005: my @possconfig = ('label','title','target','linktext','explanation');
1.273 raeburn 10006: my $numconfig = 0;
10007: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
10008: foreach my $item (@possconfig) {
10009: if ($confhash{$itemid}{'crsconf'}{$item}) {
10010: $numconfig ++;
1.296 raeburn 10011: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 10012: }
10013: }
10014: }
10015: if (!$numconfig) {
10016: $resulttext .= &mt('None');
10017: }
10018: $resulttext .= '</li>';
1.267 raeburn 10019: foreach my $item ('passback','roster') {
10020: $resulttext .= '<li>'.$lt{$item}.' ';
10021: if ($confhash{$itemid}{$item}) {
10022: $resulttext .= &mt('Yes');
10023: } else {
10024: $resulttext .= &mt('No');
10025: }
10026: $resulttext .= '</li>';
10027: }
10028: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
10029: my $displaylist;
10030: if ($confhash{$itemid}{'display'}{'target'}) {
10031: $displaylist = &mt('Display target').': '.
10032: $confhash{$itemid}{'display'}{'target'}.',';
10033: }
10034: foreach my $size ('width','height') {
10035: if ($confhash{$itemid}{'display'}{$size}) {
10036: $displaylist .= (' 'x2).$lt{$size}.': '.
10037: $confhash{$itemid}{'display'}{$size}.',';
10038: }
10039: }
10040: if ($displaylist) {
10041: $displaylist =~ s/,$//;
10042: $resulttext .= '<li>'.$displaylist.'</li>';
10043: }
1.296 raeburn 10044: foreach my $item ('linktext','explanation') {
10045: if ($confhash{$itemid}{'display'}{$item}) {
10046: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
10047: }
10048: }
10049: }
1.267 raeburn 10050: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
10051: my $fieldlist;
10052: foreach my $field (@allfields) {
10053: if ($confhash{$itemid}{'fields'}{$field}) {
10054: $fieldlist .= (' 'x2).$lt{$field}.',';
10055: }
10056: }
10057: if ($fieldlist) {
10058: $fieldlist =~ s/,$//;
10059: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
10060: }
10061: }
10062: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
10063: my $rolemaps;
10064: foreach my $role (@courseroles) {
10065: if ($confhash{$itemid}{'roles'}{$role}) {
10066: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
10067: $confhash{$itemid}{'roles'}{$role}.',';
10068: }
10069: }
10070: if ($rolemaps) {
10071: $rolemaps =~ s/,$//;
10072: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
10073: }
10074: }
10075: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
10076: my $customlist;
10077: if (keys(%{$confhash{$itemid}{'custom'}})) {
10078: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
10079: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
10080: }
10081: }
10082: if ($customlist) {
10083: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
10084: }
10085: }
10086: $resulttext .= '</ul></li>';
10087: }
10088: }
10089: $resulttext .= '</ul>';
10090: } else {
10091: $resulttext = &mt('No changes made.');
10092: }
10093: } else {
10094: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10095: }
10096: if ($errors) {
10097: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10098: $errors.'</ul>';
10099: }
10100: return $resulttext;
10101: }
10102:
10103: sub process_ltitools_image {
10104: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
10105: my $filename = $env{'form.'.$caller.'.filename'};
10106: my ($error,$url);
10107: my ($width,$height) = (21,21);
10108: if ($configuserok eq 'ok') {
10109: if ($switchserver) {
10110: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
10111: $switchserver);
10112: } elsif ($author_ok eq 'ok') {
10113: my ($result,$imageurl,$madethumb) =
10114: &publishlogo($r,'upload',$caller,$dom,$confname,
10115: "ltitools/$itemid/icon",$width,$height);
10116: if ($result eq 'ok') {
10117: if ($madethumb) {
10118: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
10119: my $imagethumb = "$path/tn-".$imagefile;
10120: $url = $imagethumb;
10121: } else {
10122: $url = $imageurl;
10123: }
10124: } else {
10125: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
10126: }
10127: } else {
10128: $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);
10129: }
10130: } else {
10131: $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);
10132: }
10133: return ($url,$error);
10134: }
10135:
10136: sub get_ltitools_id {
10137: my ($cdom,$title) = @_;
10138: # get lock on ltitools db
10139: my $lockhash = {
10140: lock => $env{'user.name'}.
10141: ':'.$env{'user.domain'},
10142: };
10143: my $tries = 0;
10144: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10145: my ($id,$error);
10146:
10147: while (($gotlock ne 'ok') && ($tries<10)) {
10148: $tries ++;
10149: sleep (0.1);
10150: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
10151: }
10152: if ($gotlock eq 'ok') {
10153: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
10154: if ($currids{'lock'}) {
10155: delete($currids{'lock'});
10156: if (keys(%currids)) {
10157: my @curr = sort { $a <=> $b } keys(%currids);
10158: if ($curr[-1] =~ /^\d+$/) {
10159: $id = 1 + $curr[-1];
10160: }
10161: } else {
10162: $id = 1;
10163: }
10164: if ($id) {
10165: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
10166: $error = 'nostore';
10167: }
10168: } else {
10169: $error = 'nonumber';
10170: }
10171: }
10172: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
10173: } else {
10174: $error = 'nolock';
10175: }
10176: return ($id,$error);
10177: }
10178:
1.3 raeburn 10179: sub modify_autoenroll {
1.205 raeburn 10180: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 10181: my ($resulttext,%changes);
10182: my %currautoenroll;
10183: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
10184: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
10185: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
10186: }
10187: }
10188: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
10189: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 10190: sender => 'Sender for notification messages',
1.274 raeburn 10191: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
10192: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 10193: my @offon = ('off','on');
1.17 raeburn 10194: my $sender_uname = $env{'form.sender_uname'};
10195: my $sender_domain = $env{'form.sender_domain'};
10196: if ($sender_domain eq '') {
10197: $sender_uname = '';
10198: } elsif ($sender_uname eq '') {
10199: $sender_domain = '';
10200: }
1.129 raeburn 10201: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 10202: my $failsafe = $env{'form.autoenroll_failsafe'};
10203: $failsafe =~ s{^\s+|\s+$}{}g;
10204: if ($failsafe =~ /\D/) {
10205: undef($failsafe);
10206: }
1.1 raeburn 10207: my %autoenrollhash = (
1.129 raeburn 10208: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10209: 'sender_uname' => $sender_uname,
10210: 'sender_domain' => $sender_domain,
10211: 'co-owners' => $coowners,
1.274 raeburn 10212: 'autofailsafe' => $failsafe,
1.1 raeburn 10213: }
10214: );
1.4 raeburn 10215: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10216: $dom);
1.1 raeburn 10217: if ($putresult eq 'ok') {
10218: if (exists($currautoenroll{'run'})) {
10219: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10220: $changes{'run'} = 1;
10221: }
10222: } elsif ($autorun) {
10223: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 10224: $changes{'run'} = 1;
1.1 raeburn 10225: }
10226: }
1.17 raeburn 10227: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 10228: $changes{'sender'} = 1;
10229: }
1.17 raeburn 10230: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 10231: $changes{'sender'} = 1;
10232: }
1.129 raeburn 10233: if ($currautoenroll{'co-owners'} ne '') {
10234: if ($currautoenroll{'co-owners'} ne $coowners) {
10235: $changes{'coowners'} = 1;
10236: }
10237: } elsif ($coowners) {
10238: $changes{'coowners'} = 1;
1.274 raeburn 10239: }
10240: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10241: $changes{'autofailsafe'} = 1;
10242: }
1.1 raeburn 10243: if (keys(%changes) > 0) {
10244: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 10245: if ($changes{'run'}) {
1.1 raeburn 10246: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10247: }
10248: if ($changes{'sender'}) {
1.17 raeburn 10249: if ($sender_uname eq '' || $sender_domain eq '') {
10250: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10251: } else {
10252: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10253: }
1.1 raeburn 10254: }
1.129 raeburn 10255: if ($changes{'coowners'}) {
10256: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10257: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10258: if (ref($lastactref) eq 'HASH') {
10259: $lastactref->{'domainconfig'} = 1;
10260: }
1.129 raeburn 10261: }
1.274 raeburn 10262: if ($changes{'autofailsafe'}) {
10263: if ($failsafe ne '') {
1.299 raeburn 10264: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274 raeburn 10265: } else {
1.299 raeburn 10266: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274 raeburn 10267: }
10268: &Apache::lonnet::get_domain_defaults($dom,1);
10269: if (ref($lastactref) eq 'HASH') {
10270: $lastactref->{'domdefaults'} = 1;
10271: }
10272: }
1.1 raeburn 10273: $resulttext .= '</ul>';
10274: } else {
10275: $resulttext = &mt('No changes made to auto-enrollment settings');
10276: }
10277: } else {
1.11 albertel 10278: $resulttext = '<span class="LC_error">'.
10279: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10280: }
1.3 raeburn 10281: return $resulttext;
1.1 raeburn 10282: }
10283:
10284: sub modify_autoupdate {
1.3 raeburn 10285: my ($dom,%domconfig) = @_;
1.1 raeburn 10286: my ($resulttext,%currautoupdate,%fields,%changes);
10287: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10288: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10289: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10290: }
10291: }
10292: my @offon = ('off','on');
10293: my %title = &Apache::lonlocal::texthash (
10294: run => 'Auto-update:',
10295: classlists => 'Updates to user information in classlists?'
10296: );
1.44 raeburn 10297: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10298: my %fieldtitles = &Apache::lonlocal::texthash (
10299: id => 'Student/Employee ID',
1.20 raeburn 10300: permanentemail => 'E-mail address',
1.1 raeburn 10301: lastname => 'Last Name',
10302: firstname => 'First Name',
10303: middlename => 'Middle Name',
1.132 raeburn 10304: generation => 'Generation',
1.1 raeburn 10305: );
1.142 raeburn 10306: $othertitle = &mt('All users');
1.1 raeburn 10307: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10308: $othertitle = &mt('Other users');
1.1 raeburn 10309: }
10310: foreach my $key (keys(%env)) {
10311: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10312: my ($usertype,$item) = ($1,$2);
10313: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10314: if ($usertype eq 'default') {
10315: push(@{$fields{$1}},$2);
10316: } elsif (ref($types) eq 'ARRAY') {
10317: if (grep(/^\Q$usertype\E$/,@{$types})) {
10318: push(@{$fields{$1}},$2);
10319: }
10320: }
10321: }
1.1 raeburn 10322: }
10323: }
1.131 raeburn 10324: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10325: @lockablenames = sort(@lockablenames);
10326: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10327: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10328: if (@changed) {
10329: $changes{'lockablenames'} = 1;
10330: }
10331: } else {
10332: if (@lockablenames) {
10333: $changes{'lockablenames'} = 1;
10334: }
10335: }
1.1 raeburn 10336: my %updatehash = (
10337: autoupdate => { run => $env{'form.autoupdate_run'},
10338: classlists => $env{'form.classlists'},
10339: fields => {%fields},
1.131 raeburn 10340: lockablenames => \@lockablenames,
1.1 raeburn 10341: }
10342: );
10343: foreach my $key (keys(%currautoupdate)) {
10344: if (($key eq 'run') || ($key eq 'classlists')) {
10345: if (exists($updatehash{autoupdate}{$key})) {
10346: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10347: $changes{$key} = 1;
10348: }
10349: }
10350: } elsif ($key eq 'fields') {
10351: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10352: foreach my $item (@{$types},'default') {
1.1 raeburn 10353: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10354: my $change = 0;
10355: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10356: if (!exists($fields{$item})) {
10357: $change = 1;
1.132 raeburn 10358: last;
1.1 raeburn 10359: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10360: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10361: $change = 1;
1.132 raeburn 10362: last;
1.1 raeburn 10363: }
10364: }
10365: }
10366: if ($change) {
10367: push(@{$changes{$key}},$item);
10368: }
1.26 raeburn 10369: }
1.1 raeburn 10370: }
10371: }
1.131 raeburn 10372: } elsif ($key eq 'lockablenames') {
10373: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10374: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10375: if (@changed) {
10376: $changes{'lockablenames'} = 1;
10377: }
10378: } else {
10379: if (@lockablenames) {
10380: $changes{'lockablenames'} = 1;
10381: }
10382: }
10383: }
10384: }
10385: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10386: if (@lockablenames) {
10387: $changes{'lockablenames'} = 1;
1.1 raeburn 10388: }
10389: }
1.26 raeburn 10390: foreach my $item (@{$types},'default') {
10391: if (defined($fields{$item})) {
10392: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10393: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10394: my $change = 0;
10395: if (ref($fields{$item}) eq 'ARRAY') {
10396: foreach my $type (@{$fields{$item}}) {
10397: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10398: $change = 1;
10399: last;
10400: }
10401: }
10402: }
10403: if ($change) {
10404: push(@{$changes{'fields'}},$item);
10405: }
10406: } else {
1.26 raeburn 10407: push(@{$changes{'fields'}},$item);
10408: }
10409: } else {
10410: push(@{$changes{'fields'}},$item);
1.1 raeburn 10411: }
10412: }
10413: }
10414: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10415: $dom);
10416: if ($putresult eq 'ok') {
10417: if (keys(%changes) > 0) {
10418: $resulttext = &mt('Changes made:').'<ul>';
10419: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10420: if ($key eq 'lockablenames') {
10421: $resulttext .= '<li>';
10422: if (@lockablenames) {
10423: $usertypes->{'default'} = $othertitle;
10424: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10425: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10426: } else {
10427: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10428: }
10429: $resulttext .= '</li>';
10430: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10431: foreach my $item (@{$changes{$key}}) {
10432: my @newvalues;
10433: foreach my $type (@{$fields{$item}}) {
10434: push(@newvalues,$fieldtitles{$type});
10435: }
1.3 raeburn 10436: my $newvaluestr;
10437: if (@newvalues > 0) {
10438: $newvaluestr = join(', ',@newvalues);
10439: } else {
10440: $newvaluestr = &mt('none');
1.6 raeburn 10441: }
1.1 raeburn 10442: if ($item eq 'default') {
1.26 raeburn 10443: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10444: } else {
1.26 raeburn 10445: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10446: }
10447: }
10448: } else {
10449: my $newvalue;
10450: if ($key eq 'run') {
10451: $newvalue = $offon[$env{'form.autoupdate_run'}];
10452: } else {
10453: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10454: }
1.1 raeburn 10455: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10456: }
10457: }
10458: $resulttext .= '</ul>';
10459: } else {
1.3 raeburn 10460: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10461: }
10462: } else {
1.11 albertel 10463: $resulttext = '<span class="LC_error">'.
10464: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10465: }
1.3 raeburn 10466: return $resulttext;
1.1 raeburn 10467: }
10468:
1.125 raeburn 10469: sub modify_autocreate {
10470: my ($dom,%domconfig) = @_;
10471: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10472: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10473: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10474: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10475: }
10476: }
10477: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10478: req => 'Auto-creation of validated requests for official courses',
10479: xmldc => 'Identity of course creator of courses from XML files',
10480: );
10481: my @types = ('xml','req');
10482: foreach my $item (@types) {
10483: $newvals{$item} = $env{'form.autocreate_'.$item};
10484: $newvals{$item} =~ s/\D//g;
10485: $newvals{$item} = 0 if ($newvals{$item} eq '');
10486: }
10487: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 10488: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10489: unless (exists($domcoords{$newvals{'xmldc'}})) {
10490: $newvals{'xmldc'} = '';
10491: }
10492: %autocreatehash = (
10493: autocreate => { xml => $newvals{'xml'},
10494: req => $newvals{'req'},
10495: }
10496: );
10497: if ($newvals{'xmldc'} ne '') {
10498: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10499: }
10500: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10501: $dom);
10502: if ($putresult eq 'ok') {
10503: my @items = @types;
10504: if ($newvals{'xml'}) {
10505: push(@items,'xmldc');
10506: }
10507: foreach my $item (@items) {
10508: if (exists($currautocreate{$item})) {
10509: if ($currautocreate{$item} ne $newvals{$item}) {
10510: $changes{$item} = 1;
10511: }
10512: } elsif ($newvals{$item}) {
10513: $changes{$item} = 1;
10514: }
10515: }
10516: if (keys(%changes) > 0) {
10517: my @offon = ('off','on');
10518: $resulttext = &mt('Changes made:').'<ul>';
10519: foreach my $item (@types) {
10520: if ($changes{$item}) {
10521: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 10522: $resulttext .= '<li>'.
10523: &mt("$title{$item} set to [_1]$newtxt [_2]",
10524: '<b>','</b>').
10525: '</li>';
1.125 raeburn 10526: }
10527: }
10528: if ($changes{'xmldc'}) {
10529: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10530: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 10531: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10532: }
10533: $resulttext .= '</ul>';
10534: } else {
10535: $resulttext = &mt('No changes made to auto-creation settings');
10536: }
10537: } else {
10538: $resulttext = '<span class="LC_error">'.
10539: &mt('An error occurred: [_1]',$putresult).'</span>';
10540: }
10541: return $resulttext;
10542: }
10543:
1.23 raeburn 10544: sub modify_directorysrch {
1.295 raeburn 10545: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10546: my ($resulttext,%changes);
10547: my %currdirsrch;
10548: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10549: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10550: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10551: }
10552: }
1.277 raeburn 10553: my %title = ( available => 'Institutional directory search available',
10554: localonly => 'Other domains can search institution',
10555: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 10556: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10557: searchby => 'Search types',
10558: searchtypes => 'Search latitude');
10559: my @offon = ('off','on');
1.24 raeburn 10560: my @otherdoms = ('Yes','No');
1.23 raeburn 10561:
1.25 raeburn 10562: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10563: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10564: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10565:
1.44 raeburn 10566: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10567: if (keys(%{$usertypes}) == 0) {
10568: @cansearch = ('default');
10569: } else {
10570: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10571: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10572: if (!grep(/^\Q$type\E$/,@cansearch)) {
10573: push(@{$changes{'cansearch'}},$type);
10574: }
1.23 raeburn 10575: }
1.26 raeburn 10576: foreach my $type (@cansearch) {
10577: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10578: push(@{$changes{'cansearch'}},$type);
10579: }
1.23 raeburn 10580: }
1.26 raeburn 10581: } else {
10582: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10583: }
10584: }
10585:
10586: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10587: foreach my $by (@{$currdirsrch{'searchby'}}) {
10588: if (!grep(/^\Q$by\E$/,@searchby)) {
10589: push(@{$changes{'searchby'}},$by);
10590: }
10591: }
10592: foreach my $by (@searchby) {
10593: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10594: push(@{$changes{'searchby'}},$by);
10595: }
10596: }
10597: } else {
10598: push(@{$changes{'searchby'}},@searchby);
10599: }
1.25 raeburn 10600:
10601: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10602: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10603: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10604: push(@{$changes{'searchtypes'}},$type);
10605: }
10606: }
10607: foreach my $type (@searchtypes) {
10608: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10609: push(@{$changes{'searchtypes'}},$type);
10610: }
10611: }
10612: } else {
10613: if (exists($currdirsrch{'searchtypes'})) {
10614: foreach my $type (@searchtypes) {
10615: if ($type ne $currdirsrch{'searchtypes'}) {
10616: push(@{$changes{'searchtypes'}},$type);
10617: }
10618: }
10619: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10620: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10621: }
10622: } else {
10623: push(@{$changes{'searchtypes'}},@searchtypes);
10624: }
10625: }
10626:
1.23 raeburn 10627: my %dirsrch_hash = (
10628: directorysrch => { available => $env{'form.dirsrch_available'},
10629: cansearch => \@cansearch,
1.277 raeburn 10630: localonly => $env{'form.dirsrch_instlocalonly'},
10631: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10632: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10633: searchby => \@searchby,
1.25 raeburn 10634: searchtypes => \@searchtypes,
1.23 raeburn 10635: }
10636: );
10637: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10638: $dom);
10639: if ($putresult eq 'ok') {
10640: if (exists($currdirsrch{'available'})) {
10641: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10642: $changes{'available'} = 1;
10643: }
10644: } else {
10645: if ($env{'form.dirsrch_available'} eq '1') {
10646: $changes{'available'} = 1;
10647: }
10648: }
1.277 raeburn 10649: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 10650: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10651: $changes{'lcavailable'} = 1;
10652: }
1.277 raeburn 10653: } else {
10654: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10655: $changes{'lcavailable'} = 1;
10656: }
10657: }
1.24 raeburn 10658: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 10659: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
10660: $changes{'localonly'} = 1;
10661: }
1.24 raeburn 10662: } else {
1.277 raeburn 10663: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 10664: $changes{'localonly'} = 1;
10665: }
10666: }
1.277 raeburn 10667: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 10668: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10669: $changes{'lclocalonly'} = 1;
10670: }
1.277 raeburn 10671: } else {
10672: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10673: $changes{'lclocalonly'} = 1;
10674: }
10675: }
1.23 raeburn 10676: if (keys(%changes) > 0) {
10677: $resulttext = &mt('Changes made:').'<ul>';
10678: if ($changes{'available'}) {
10679: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10680: }
1.277 raeburn 10681: if ($changes{'lcavailable'}) {
10682: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10683: }
1.24 raeburn 10684: if ($changes{'localonly'}) {
1.277 raeburn 10685: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 10686: }
1.277 raeburn 10687: if ($changes{'lclocalonly'}) {
10688: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 10689: }
1.23 raeburn 10690: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10691: my $chgtext;
1.26 raeburn 10692: if (ref($usertypes) eq 'HASH') {
10693: if (keys(%{$usertypes}) > 0) {
10694: foreach my $type (@{$types}) {
10695: if (grep(/^\Q$type\E$/,@cansearch)) {
10696: $chgtext .= $usertypes->{$type}.'; ';
10697: }
10698: }
10699: if (grep(/^default$/,@cansearch)) {
10700: $chgtext .= $othertitle;
10701: } else {
10702: $chgtext =~ s/\; $//;
10703: }
1.210 raeburn 10704: $resulttext .=
1.178 raeburn 10705: '<li>'.
10706: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10707: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10708: '</li>';
1.23 raeburn 10709: }
10710: }
10711: }
10712: if (ref($changes{'searchby'}) eq 'ARRAY') {
10713: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10714: my $chgtext;
10715: foreach my $type (@{$titleorder}) {
10716: if (grep(/^\Q$type\E$/,@searchby)) {
10717: if (defined($searchtitles->{$type})) {
10718: $chgtext .= $searchtitles->{$type}.'; ';
10719: }
10720: }
10721: }
10722: $chgtext =~ s/\; $//;
10723: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10724: }
1.25 raeburn 10725: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10726: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10727: my $chgtext;
10728: foreach my $type (@{$srchtypeorder}) {
10729: if (grep(/^\Q$type\E$/,@searchtypes)) {
10730: if (defined($srchtypes_desc->{$type})) {
10731: $chgtext .= $srchtypes_desc->{$type}.'; ';
10732: }
10733: }
10734: }
10735: $chgtext =~ s/\; $//;
1.178 raeburn 10736: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10737: }
10738: $resulttext .= '</ul>';
1.295 raeburn 10739: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10740: if (ref($lastactref) eq 'HASH') {
10741: $lastactref->{'directorysrch'} = 1;
10742: }
1.23 raeburn 10743: } else {
1.277 raeburn 10744: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10745: }
10746: } else {
10747: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10748: &mt('An error occurred: [_1]',$putresult).'</span>';
10749: }
10750: return $resulttext;
10751: }
10752:
1.28 raeburn 10753: sub modify_contacts {
1.205 raeburn 10754: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10755: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10756: if (ref($domconfig{'contacts'}) eq 'HASH') {
10757: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10758: $currsetting{$key} = $domconfig{'contacts'}{$key};
10759: }
10760: }
1.286 raeburn 10761: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10762: my @contacts = ('supportemail','adminemail');
1.286 raeburn 10763: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10764: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 10765: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 10766: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10767: foreach my $type (@mailings) {
10768: @{$newsetting{$type}} =
10769: &Apache::loncommon::get_env_multiple('form.'.$type);
10770: foreach my $item (@contacts) {
10771: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10772: $contacts_hash{contacts}{$type}{$item} = 1;
10773: } else {
10774: $contacts_hash{contacts}{$type}{$item} = 0;
10775: }
1.289 raeburn 10776: }
1.28 raeburn 10777: $others{$type} = $env{'form.'.$type.'_others'};
10778: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 10779: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10780: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10781: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 10782: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10783: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10784: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10785: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10786: }
1.134 raeburn 10787: }
1.28 raeburn 10788: }
10789: foreach my $item (@contacts) {
10790: $to{$item} = $env{'form.'.$item};
10791: $contacts_hash{'contacts'}{$item} = $to{$item};
10792: }
1.203 raeburn 10793: foreach my $item (@toggles) {
10794: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10795: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10796: }
10797: }
1.286 raeburn 10798: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10799: foreach my $field (@{$fields}) {
10800: if (ref($possoptions->{$field}) eq 'ARRAY') {
10801: my $value = $env{'form.helpform_'.$field};
10802: $value =~ s/^\s+|\s+$//g;
10803: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10804: $contacts_hash{contacts}{'helpform'}{$field} = $value;
10805: if ($field eq 'screenshot') {
10806: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10807: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10808: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10809: }
10810: }
10811: }
10812: }
10813: }
10814: }
1.28 raeburn 10815: if (keys(%currsetting) > 0) {
10816: foreach my $item (@contacts) {
10817: if ($to{$item} ne $currsetting{$item}) {
10818: $changes{$item} = 1;
10819: }
10820: }
10821: foreach my $type (@mailings) {
10822: foreach my $item (@contacts) {
10823: if (ref($currsetting{$type}) eq 'HASH') {
10824: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10825: push(@{$changes{$type}},$item);
10826: }
10827: } else {
10828: push(@{$changes{$type}},@{$newsetting{$type}});
10829: }
10830: }
10831: if ($others{$type} ne $currsetting{$type}{'others'}) {
10832: push(@{$changes{$type}},'others');
10833: }
1.289 raeburn 10834: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10835: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10836: push(@{$changes{$type}},'bcc');
10837: }
1.286 raeburn 10838: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10839: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10840: push(@{$changes{$type}},'include');
10841: }
10842: }
10843: }
10844: if (ref($fields) eq 'ARRAY') {
10845: if (ref($currsetting{'helpform'}) eq 'HASH') {
10846: foreach my $field (@{$fields}) {
10847: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10848: push(@{$changes{'helpform'}},$field);
10849: }
10850: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10851: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10852: push(@{$changes{'helpform'}},'maxsize');
10853: }
10854: }
10855: }
10856: } else {
10857: foreach my $field (@{$fields}) {
10858: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10859: push(@{$changes{'helpform'}},$field);
10860: }
10861: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10862: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10863: push(@{$changes{'helpform'}},'maxsize');
10864: }
10865: }
10866: }
1.134 raeburn 10867: }
1.28 raeburn 10868: }
10869: } else {
10870: my %default;
10871: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10872: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10873: $default{'errormail'} = 'adminemail';
10874: $default{'packagesmail'} = 'adminemail';
10875: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 10876: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10877: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10878: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 10879: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 10880: foreach my $item (@contacts) {
10881: if ($to{$item} ne $default{$item}) {
1.286 raeburn 10882: $changes{$item} = 1;
1.203 raeburn 10883: }
1.28 raeburn 10884: }
10885: foreach my $type (@mailings) {
10886: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10887: push(@{$changes{$type}},@{$newsetting{$type}});
10888: }
10889: if ($others{$type} ne '') {
10890: push(@{$changes{$type}},'others');
1.134 raeburn 10891: }
1.286 raeburn 10892: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10893: if ($bcc{$type} ne '') {
10894: push(@{$changes{$type}},'bcc');
10895: }
1.286 raeburn 10896: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10897: push(@{$changes{$type}},'include');
10898: }
1.134 raeburn 10899: }
1.28 raeburn 10900: }
1.286 raeburn 10901: if (ref($fields) eq 'ARRAY') {
10902: foreach my $field (@{$fields}) {
10903: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10904: push(@{$changes{'helpform'}},$field);
10905: }
10906: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10907: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10908: push(@{$changes{'helpform'}},'maxsize');
10909: }
10910: }
10911: }
1.289 raeburn 10912: }
1.28 raeburn 10913: }
1.203 raeburn 10914: foreach my $item (@toggles) {
10915: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10916: $changes{$item} = 1;
10917: } elsif ((!$env{'form.'.$item}) &&
10918: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10919: $changes{$item} = 1;
10920: }
10921: }
1.28 raeburn 10922: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10923: $dom);
10924: if ($putresult eq 'ok') {
10925: if (keys(%changes) > 0) {
1.205 raeburn 10926: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10927: if (ref($lastactref) eq 'HASH') {
10928: $lastactref->{'domainconfig'} = 1;
10929: }
1.28 raeburn 10930: my ($titles,$short_titles) = &contact_titles();
10931: $resulttext = &mt('Changes made:').'<ul>';
10932: foreach my $item (@contacts) {
10933: if ($changes{$item}) {
10934: $resulttext .= '<li>'.$titles->{$item}.
10935: &mt(' set to: ').
10936: '<span class="LC_cusr_emph">'.
10937: $to{$item}.'</span></li>';
10938: }
10939: }
10940: foreach my $type (@mailings) {
10941: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 10942: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 10943: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 10944: } else {
10945: $resulttext .= '<li>'.$titles->{$type}.': ';
10946: }
1.28 raeburn 10947: my @text;
10948: foreach my $item (@{$newsetting{$type}}) {
10949: push(@text,$short_titles->{$item});
10950: }
10951: if ($others{$type} ne '') {
10952: push(@text,$others{$type});
10953: }
1.286 raeburn 10954: if (@text) {
10955: $resulttext .= '<span class="LC_cusr_emph">'.
10956: join(', ',@text).'</span>';
10957: }
10958: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10959: if ($bcc{$type} ne '') {
1.286 raeburn 10960: my $bcctext;
10961: if (@text) {
1.289 raeburn 10962: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 10963: } else {
10964: $bcctext = '(Bcc)';
10965: }
10966: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10967: } elsif (!@text) {
10968: $resulttext .= &mt('No one');
10969: }
1.289 raeburn 10970: if ($includestr{$type} ne '') {
1.286 raeburn 10971: if ($includeloc{$type} eq 'b') {
10972: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10973: } elsif ($includeloc{$type} eq 's') {
10974: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10975: }
1.134 raeburn 10976: }
1.286 raeburn 10977: } elsif (!@text) {
10978: $resulttext .= &mt('No recipients');
1.134 raeburn 10979: }
10980: $resulttext .= '</li>';
1.28 raeburn 10981: }
10982: }
1.203 raeburn 10983: my @offon = ('off','on');
10984: if ($changes{'reporterrors'}) {
10985: $resulttext .= '<li>'.
10986: &mt('E-mail error reports to [_1] set to "'.
10987: $offon[$env{'form.reporterrors'}].'".',
10988: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10989: &mt('LON-CAPA core group - MSU'),600,500)).
10990: '</li>';
10991: }
10992: if ($changes{'reportupdates'}) {
10993: $resulttext .= '<li>'.
10994: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10995: $offon[$env{'form.reportupdates'}].'".',
10996: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10997: &mt('LON-CAPA core group - MSU'),600,500)).
10998: '</li>';
10999: }
1.286 raeburn 11000: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
11001: my (@optional,@required,@unused,$maxsizechg);
11002: foreach my $field (@{$changes{'helpform'}}) {
11003: if ($field eq 'maxsize') {
11004: $maxsizechg = 1;
11005: next;
11006: }
11007: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 11008: push(@optional,$field);
1.286 raeburn 11009: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
11010: push(@unused,$field);
11011: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 11012: push(@required,$field);
1.286 raeburn 11013: }
11014: }
11015: if (@optional) {
11016: $resulttext .= '<li>'.
11017: &mt('Help form fields changed to "Optional": [_1].',
11018: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
11019: '</li>';
11020: }
11021: if (@required) {
11022: $resulttext .= '<li>'.
11023: &mt('Help form fields changed to "Required": [_1].',
11024: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
11025: '</li>';
11026: }
11027: if (@unused) {
11028: $resulttext .= '<li>'.
11029: &mt('Help form fields changed to "Not shown": [_1].',
11030: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
11031: '</li>';
11032: }
11033: if ($maxsizechg) {
11034: $resulttext .= '<li>'.
11035: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
11036: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
11037: '</li>';
11038:
11039: }
11040: }
1.28 raeburn 11041: $resulttext .= '</ul>';
11042: } else {
1.288 raeburn 11043: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 11044: }
11045: } else {
11046: $resulttext = '<span class="LC_error">'.
11047: &mt('An error occurred: [_1].',$putresult).'</span>';
11048: }
11049: return $resulttext;
11050: }
11051:
11052: sub modify_usercreation {
1.27 raeburn 11053: my ($dom,%domconfig) = @_;
1.224 raeburn 11054: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 11055: my $warningmsg;
1.27 raeburn 11056: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11057: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 11058: if ($key eq 'cancreate') {
11059: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11060: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 ! raeburn 11061: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
! 11062: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
! 11063: } else {
1.224 raeburn 11064: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11065: }
11066: }
11067: }
11068: } elsif ($key eq 'email_rule') {
11069: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11070: } else {
11071: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11072: }
1.27 raeburn 11073: }
11074: }
11075: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 11076: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 11077: my @contexts = ('author','course','requestcrs');
1.34 raeburn 11078: foreach my $item(@contexts) {
1.224 raeburn 11079: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 11080: }
1.34 raeburn 11081: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11082: foreach my $item (@contexts) {
1.224 raeburn 11083: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
11084: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 11085: }
1.27 raeburn 11086: }
1.34 raeburn 11087: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
11088: foreach my $item (@contexts) {
1.43 raeburn 11089: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 11090: if ($cancreate{$item} ne 'any') {
11091: push(@{$changes{'cancreate'}},$item);
11092: }
11093: } else {
11094: if ($cancreate{$item} ne 'none') {
11095: push(@{$changes{'cancreate'}},$item);
11096: }
1.27 raeburn 11097: }
11098: }
11099: } else {
1.43 raeburn 11100: foreach my $item (@contexts) {
1.34 raeburn 11101: push(@{$changes{'cancreate'}},$item);
11102: }
1.27 raeburn 11103: }
1.34 raeburn 11104:
1.27 raeburn 11105: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
11106: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
11107: if (!grep(/^\Q$type\E$/,@username_rule)) {
11108: push(@{$changes{'username_rule'}},$type);
11109: }
11110: }
11111: foreach my $type (@username_rule) {
11112: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
11113: push(@{$changes{'username_rule'}},$type);
11114: }
11115: }
11116: } else {
11117: push(@{$changes{'username_rule'}},@username_rule);
11118: }
11119:
1.32 raeburn 11120: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
11121: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
11122: if (!grep(/^\Q$type\E$/,@id_rule)) {
11123: push(@{$changes{'id_rule'}},$type);
11124: }
11125: }
11126: foreach my $type (@id_rule) {
11127: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
11128: push(@{$changes{'id_rule'}},$type);
11129: }
11130: }
11131: } else {
11132: push(@{$changes{'id_rule'}},@id_rule);
11133: }
11134:
1.43 raeburn 11135: my @authen_contexts = ('author','course','domain');
1.28 raeburn 11136: my @authtypes = ('int','krb4','krb5','loc');
11137: my %authhash;
1.43 raeburn 11138: foreach my $item (@authen_contexts) {
1.28 raeburn 11139: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
11140: foreach my $auth (@authtypes) {
11141: if (grep(/^\Q$auth\E$/,@authallowed)) {
11142: $authhash{$item}{$auth} = 1;
11143: } else {
11144: $authhash{$item}{$auth} = 0;
11145: }
11146: }
11147: }
11148: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 11149: foreach my $item (@authen_contexts) {
1.28 raeburn 11150: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
11151: foreach my $auth (@authtypes) {
11152: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
11153: push(@{$changes{'authtypes'}},$item);
11154: last;
11155: }
11156: }
11157: }
11158: }
11159: } else {
1.43 raeburn 11160: foreach my $item (@authen_contexts) {
1.28 raeburn 11161: push(@{$changes{'authtypes'}},$item);
11162: }
11163: }
11164:
1.224 raeburn 11165: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11166: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11167: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11168: $save_usercreate{'id_rule'} = \@id_rule;
11169: $save_usercreate{'username_rule'} = \@username_rule,
11170: $save_usercreate{'authtypes'} = \%authhash;
11171:
1.27 raeburn 11172: my %usercreation_hash = (
1.224 raeburn 11173: usercreation => \%save_usercreate,
11174: );
1.27 raeburn 11175:
11176: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11177: $dom);
1.50 raeburn 11178:
1.224 raeburn 11179: if ($putresult eq 'ok') {
11180: if (keys(%changes) > 0) {
11181: $resulttext = &mt('Changes made:').'<ul>';
11182: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11183: my %lt = &usercreation_types();
11184: foreach my $type (@{$changes{'cancreate'}}) {
11185: my $chgtext = $lt{$type}.', ';
11186: if ($cancreate{$type} eq 'none') {
11187: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11188: } elsif ($cancreate{$type} eq 'any') {
11189: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11190: } elsif ($cancreate{$type} eq 'official') {
11191: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11192: } elsif ($cancreate{$type} eq 'unofficial') {
11193: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11194: }
11195: $resulttext .= '<li>'.$chgtext.'</li>';
11196: }
11197: }
11198: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11199: my ($rules,$ruleorder) =
11200: &Apache::lonnet::inst_userrules($dom,'username');
11201: my $chgtext = '<ul>';
11202: foreach my $type (@username_rule) {
11203: if (ref($rules->{$type}) eq 'HASH') {
11204: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11205: }
11206: }
11207: $chgtext .= '</ul>';
11208: if (@username_rule > 0) {
11209: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11210: } else {
11211: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11212: }
11213: }
11214: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11215: my ($idrules,$idruleorder) =
11216: &Apache::lonnet::inst_userrules($dom,'id');
11217: my $chgtext = '<ul>';
11218: foreach my $type (@id_rule) {
11219: if (ref($idrules->{$type}) eq 'HASH') {
11220: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11221: }
11222: }
11223: $chgtext .= '</ul>';
11224: if (@id_rule > 0) {
11225: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11226: } else {
11227: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11228: }
11229: }
11230: my %authname = &authtype_names();
11231: my %context_title = &context_names();
11232: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11233: my $chgtext = '<ul>';
11234: foreach my $type (@{$changes{'authtypes'}}) {
11235: my @allowed;
11236: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11237: foreach my $auth (@authtypes) {
11238: if ($authhash{$type}{$auth}) {
11239: push(@allowed,$authname{$auth});
11240: }
11241: }
11242: if (@allowed > 0) {
11243: $chgtext .= join(', ',@allowed).'</li>';
11244: } else {
11245: $chgtext .= &mt('none').'</li>';
11246: }
11247: }
11248: $chgtext .= '</ul>';
11249: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11250: $resulttext .= '</li>';
11251: }
11252: $resulttext .= '</ul>';
11253: } else {
11254: $resulttext = &mt('No changes made to user creation settings');
11255: }
11256: } else {
11257: $resulttext = '<span class="LC_error">'.
11258: &mt('An error occurred: [_1]',$putresult).'</span>';
11259: }
11260: if ($warningmsg ne '') {
11261: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11262: }
11263: return $resulttext;
11264: }
11265:
11266: sub modify_selfcreation {
11267: my ($dom,%domconfig) = @_;
11268: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
1.303 ! raeburn 11269: my (%save_usercreate,%save_usermodify,@types,%usertypes);
! 11270: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
! 11271: if (ref($typesref) eq 'ARRAY') {
! 11272: @types = @{$typesref};
! 11273: }
! 11274: unless (grep(/^default$/,@types)) {
! 11275: push(@types,'default');
! 11276: }
! 11277: if (ref($usertypesref) eq 'HASH') {
! 11278: %usertypes = %{$usertypesref};
1.228 raeburn 11279: }
1.303 ! raeburn 11280: $usertypes{'default'} = $othertitle;
1.224 raeburn 11281: #
11282: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11283: #
11284: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11285: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11286: if ($key eq 'cancreate') {
11287: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11288: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11289: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 ! raeburn 11290: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
! 11291: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
! 11292: ($item eq 'emailusername') || ($item eq 'shibenv') ||
! 11293: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
! 11294: ($item eq 'emaildomain')) {
1.224 raeburn 11295: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11296: } else {
11297: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11298: }
11299: }
11300: }
11301: } elsif ($key eq 'email_rule') {
11302: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11303: } else {
11304: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11305: }
11306: }
11307: }
11308: #
11309: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11310: #
11311: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11312: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11313: if ($key eq 'selfcreate') {
11314: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11315: } else {
11316: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11317: }
11318: }
11319: }
11320:
11321: my @contexts = ('selfcreate');
11322: @{$cancreate{'selfcreate'}} = ();
11323: %{$cancreate{'emailusername'}} = ();
11324: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 11325: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 11326: %{$cancreate{'shibenv'}} = ();
1.303 ! raeburn 11327: %{$cancreate{'emailverified'}} = ();
! 11328: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 11329: my %selfcreatetypes = (
11330: sso => 'users authenticated by institutional single sign on',
11331: login => 'users authenticated by institutional log-in',
1.303 ! raeburn 11332: email => 'users verified by e-mail',
1.50 raeburn 11333: );
1.224 raeburn 11334: #
11335: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11336: # is permitted.
11337: #
1.236 raeburn 11338:
11339: my @statuses;
11340: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11341: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
11342: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
11343: }
11344: }
11345: push(@statuses,'default');
11346:
1.228 raeburn 11347: foreach my $item ('login','sso','email') {
1.224 raeburn 11348: if ($item eq 'email') {
1.236 raeburn 11349: if ($env{'form.cancreate_email'}) {
1.224 raeburn 11350: push(@{$cancreate{'selfcreate'}},'email');
1.303 ! raeburn 11351: push(@contexts,('selfcreateprocessing','emailverified','emaildomain'));
1.236 raeburn 11352: foreach my $type (@statuses) {
11353: if ($type eq 'default') {
11354: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
1.303 ! raeburn 11355: unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {
! 11356: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_emailverified'};
! 11357: if ($cancreate{'emailverified'}{$type} eq 'other') {
! 11358: $cancreate{'emaildomain'}{$type} =$env{'form.cancreate_emaildomain'};
! 11359: }
! 11360: }
1.236 raeburn 11361: } else {
11362: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
1.303 ! raeburn 11363: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_emailverified_'.$type};
! 11364: if ($cancreate{'emailverified'}{$type} eq 'other') {
! 11365: $cancreate{'emaildomain'}{$type} =$env{'form.cancreate_emaildomain_'.$type};
! 11366: }
1.236 raeburn 11367: }
11368: }
1.224 raeburn 11369: }
11370: } else {
11371: if ($env{'form.cancreate_'.$item}) {
11372: push(@{$cancreate{'selfcreate'}},$item);
11373: }
11374: }
11375: }
11376: my (@email_rule,%userinfo,%savecaptcha);
11377: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11378: #
1.228 raeburn 11379: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11380: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 11381: #
1.236 raeburn 11382:
1.244 raeburn 11383: if ($env{'form.cancreate_email'}) {
1.228 raeburn 11384: push(@contexts,'emailusername');
1.303 ! raeburn 11385: if (@types) {
! 11386: foreach my $type (@types) {
1.228 raeburn 11387: if (ref($infofields) eq 'ARRAY') {
11388: foreach my $field (@{$infofields}) {
11389: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11390: $cancreate{'emailusername'}{$type}{$field} = $1;
11391: }
11392: }
1.224 raeburn 11393: }
11394: }
11395: }
11396: #
11397: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 ! raeburn 11398: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 11399: #
11400:
11401: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11402: @approvalnotify = sort(@approvalnotify);
11403: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11404: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11405: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11406: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11407: push(@{$changes{'cancreate'}},'notify');
11408: }
11409: } else {
11410: if ($cancreate{'notify'}{'approval'}) {
11411: push(@{$changes{'cancreate'}},'notify');
11412: }
11413: }
11414: } elsif ($cancreate{'notify'}{'approval'}) {
11415: push(@{$changes{'cancreate'}},'notify');
11416: }
11417:
11418: #
1.303 ! raeburn 11419: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
1.224 raeburn 11420: #
11421: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11422: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11423: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11424: if (@{$curr_usercreation{'email_rule'}} > 0) {
11425: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11426: if (!grep(/^\Q$type\E$/,@email_rule)) {
11427: push(@{$changes{'email_rule'}},$type);
11428: }
11429: }
11430: }
11431: if (@email_rule > 0) {
11432: foreach my $type (@email_rule) {
11433: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11434: push(@{$changes{'email_rule'}},$type);
11435: }
11436: }
11437: }
11438: } elsif (@email_rule > 0) {
11439: push(@{$changes{'email_rule'}},@email_rule);
11440: }
11441: }
11442: #
1.236 raeburn 11443: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 11444: # institutional log-in.
11445: #
11446: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11447: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11448: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11449: ($domdefaults{'auth_def'} eq 'localauth'))) {
11450: $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.').' '.
11451: &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.');
11452: }
11453: }
11454: my @fields = ('lastname','firstname','middlename','generation',
11455: 'permanentemail','id');
1.240 raeburn 11456: my @shibfields = (@fields,'inststatus');
1.224 raeburn 11457: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11458: #
11459: # Where usernames may created for institutional log-in and/or institutional single sign on:
11460: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11461: # may self-create accounts
11462: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11463: # which the user may supply, if institutional data is unavailable.
11464: #
11465: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 ! raeburn 11466: if (@types) {
! 11467: if (@types > 1) {
1.224 raeburn 11468: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11469: push(@contexts,'statustocreate');
11470: } else {
11471: undef($cancreate{'statustocreate'});
11472: }
1.303 ! raeburn 11473: foreach my $type (@types) {
1.224 raeburn 11474: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11475: foreach my $field (@fields) {
11476: if (grep(/^\Q$field\E$/,@modifiable)) {
11477: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11478: } else {
11479: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11480: }
11481: }
11482: }
11483: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 ! raeburn 11484: foreach my $type (@types) {
1.224 raeburn 11485: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11486: foreach my $field (@fields) {
11487: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11488: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11489: push(@{$changes{'selfcreate'}},$type);
11490: last;
11491: }
11492: }
11493: }
11494: }
11495: } else {
1.303 ! raeburn 11496: foreach my $type (@types) {
1.224 raeburn 11497: push(@{$changes{'selfcreate'}},$type);
11498: }
11499: }
11500: }
1.240 raeburn 11501: foreach my $field (@shibfields) {
11502: if ($env{'form.shibenv_'.$field} ne '') {
11503: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11504: }
11505: }
11506: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11507: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11508: foreach my $field (@shibfields) {
11509: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11510: push(@{$changes{'cancreate'}},'shibenv');
11511: }
11512: }
11513: } else {
11514: foreach my $field (@shibfields) {
11515: if ($env{'form.shibenv_'.$field}) {
11516: push(@{$changes{'cancreate'}},'shibenv');
11517: last;
11518: }
11519: }
11520: }
11521: }
1.224 raeburn 11522: }
11523: foreach my $item (@contexts) {
11524: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11525: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11526: if (ref($cancreate{$item}) eq 'ARRAY') {
11527: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11528: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11529: push(@{$changes{'cancreate'}},$item);
11530: }
11531: }
11532: }
11533: }
11534: if (ref($cancreate{$item}) eq 'ARRAY') {
11535: foreach my $type (@{$cancreate{$item}}) {
11536: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11537: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11538: push(@{$changes{'cancreate'}},$item);
11539: }
11540: }
11541: }
11542: }
11543: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11544: if (ref($cancreate{$item}) eq 'HASH') {
11545: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 11546: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11547: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11548: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11549: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11550: push(@{$changes{'cancreate'}},$item);
11551: }
11552: }
11553: }
1.303 ! raeburn 11554: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emaildomain')) {
1.236 raeburn 11555: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11556: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11557: push(@{$changes{'cancreate'}},$item);
11558: }
11559: }
1.228 raeburn 11560: } else {
11561: if (!$cancreate{$item}{$curr}) {
11562: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11563: push(@{$changes{'cancreate'}},$item);
11564: }
1.224 raeburn 11565: }
11566: }
11567: }
11568: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 11569: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11570: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11571: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11572: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11573: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11574: push(@{$changes{'cancreate'}},$item);
11575: }
11576: }
11577: } else {
11578: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11579: push(@{$changes{'cancreate'}},$item);
11580: }
11581: }
11582: }
1.236 raeburn 11583: } elsif ($item eq 'selfcreateprocessing') {
11584: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11585: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11586: push(@{$changes{'cancreate'}},$item);
11587: }
11588: }
1.228 raeburn 11589: } else {
11590: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11591: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11592: push(@{$changes{'cancreate'}},$item);
11593: }
1.224 raeburn 11594: }
11595: }
11596: }
11597: }
11598: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11599: if (ref($cancreate{$item}) eq 'ARRAY') {
11600: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11601: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11602: push(@{$changes{'cancreate'}},$item);
11603: }
11604: }
11605: } elsif (ref($cancreate{$item}) eq 'HASH') {
11606: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11607: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11608: push(@{$changes{'cancreate'}},$item);
11609: }
11610: }
11611: }
11612: } elsif ($item eq 'emailusername') {
1.228 raeburn 11613: if (ref($cancreate{$item}) eq 'HASH') {
11614: foreach my $type (keys(%{$cancreate{$item}})) {
11615: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11616: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11617: if ($cancreate{$item}{$type}{$field}) {
11618: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11619: push(@{$changes{'cancreate'}},$item);
11620: }
11621: last;
11622: }
11623: }
11624: }
11625: }
1.224 raeburn 11626: }
11627: }
11628: }
11629: #
11630: # Populate %save_usercreate hash with updates to self-creation configuration.
11631: #
11632: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11633: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 11634: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 11635: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11636: if (ref($cancreate{'notify'}) eq 'HASH') {
11637: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11638: }
1.236 raeburn 11639: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11640: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11641: }
1.303 ! raeburn 11642: if (ref($cancreate{'emailverified'}) eq 'HASH') {
! 11643: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
! 11644: }
! 11645: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
! 11646: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
! 11647: }
1.224 raeburn 11648: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11649: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11650: }
1.240 raeburn 11651: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11652: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11653: }
1.224 raeburn 11654: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
11655: $save_usercreate{'emailrule'} = \@email_rule;
11656:
11657: my %userconfig_hash = (
11658: usercreation => \%save_usercreate,
11659: usermodification => \%save_usermodify,
11660: );
11661: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11662: $dom);
11663: #
11664: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11665: #
1.27 raeburn 11666: if ($putresult eq 'ok') {
11667: if (keys(%changes) > 0) {
11668: $resulttext = &mt('Changes made:').'<ul>';
11669: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 11670: my %lt = &selfcreation_types();
1.34 raeburn 11671: foreach my $type (@{$changes{'cancreate'}}) {
1.303 ! raeburn 11672: my $chgtext = '';
1.45 raeburn 11673: if ($type eq 'selfcreate') {
1.50 raeburn 11674: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 11675: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11676: } else {
1.224 raeburn 11677: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11678: '<ul>';
1.50 raeburn 11679: foreach my $case (@{$cancreate{$type}}) {
11680: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11681: }
11682: $chgtext .= '</ul>';
1.100 raeburn 11683: if (ref($cancreate{$type}) eq 'ARRAY') {
11684: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11685: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11686: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 ! raeburn 11687: $chgtext .= '<span class="LC_warning">'.
! 11688: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
! 11689: '</span><br />';
! 11690: }
! 11691: }
! 11692: }
! 11693: if (grep(/^email$/,@{$cancreate{$type}})) {
! 11694: if (@statuses > 1) {
! 11695: my $numtypes = 0;
! 11696: foreach my $type (@statuses) {
! 11697: unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {
! 11698: $numtypes ++;
! 11699: }
! 11700: }
! 11701: if (!$numtypes) {
! 11702: $chgtext .= '<span class="LC_warning">'.
! 11703: &mt("However, e-mail verification is currently set to 'unavailable' for all user types (including 'other'), so self-creation of accounts is not possible for non-institutional log-in.").
! 11704: '</span><br />';
! 11705:
1.100 raeburn 11706: }
11707: }
11708: }
11709: }
1.43 raeburn 11710: }
1.240 raeburn 11711: } elsif ($type eq 'shibenv') {
11712: if (keys(%{$cancreate{$type}}) == 0) {
1.303 ! raeburn 11713: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 11714: } else {
11715: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11716: '<ul>';
11717: foreach my $field (@shibfields) {
11718: next if ($cancreate{$type}{$field} eq '');
11719: if ($field eq 'inststatus') {
11720: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11721: } else {
11722: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11723: }
11724: }
11725: $chgtext .= '</ul>';
1.303 ! raeburn 11726: }
1.93 raeburn 11727: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11728: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11729: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11730: if (@{$cancreate{'selfcreate'}} > 0) {
11731: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11732: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11733: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11734: $chgtext .= '<br />'.
11735: '<span class="LC_warning">'.
11736: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11737: '</span>';
11738: }
1.303 ! raeburn 11739: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 11740: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11741: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11742: } else {
11743: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11744: }
11745: $chgtext .= '<ul>';
11746: foreach my $case (@{$cancreate{$type}}) {
11747: if ($case eq 'default') {
11748: $chgtext .= '<li>'.$othertitle.'</li>';
11749: } else {
1.303 ! raeburn 11750: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 11751: }
11752: }
1.100 raeburn 11753: $chgtext .= '</ul>';
11754: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 ! raeburn 11755: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 11756: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11757: '</span>';
1.100 raeburn 11758: }
11759: }
11760: } else {
11761: if (@{$cancreate{$type}} == 0) {
11762: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11763: } else {
11764: $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 11765: }
11766: }
1.303 ! raeburn 11767: $chgtext .= '<br />';
1.93 raeburn 11768: }
1.236 raeburn 11769: } elsif ($type eq 'selfcreateprocessing') {
11770: my %choices = &Apache::lonlocal::texthash (
11771: automatic => 'Automatic approval',
11772: approval => 'Queued for approval',
1.303 ! raeburn 11773: notinuse => 'Unavailable',
1.236 raeburn 11774: );
11775: if (@statuses > 1) {
1.303 ! raeburn 11776: my $numtypes = 0;
! 11777: foreach my $type (@statuses) {
! 11778: unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {
! 11779: $numtypes ++;
! 11780: }
! 11781: }
! 11782: if ($numtypes) {
! 11783: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
! 11784: '<ul>';
! 11785: foreach my $type (@statuses) {
! 11786: if ($type eq 'default') {
! 11787: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
! 11788: } else {
! 11789: $chgtext .= '<li>'.$usertypes{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
! 11790: }
! 11791: }
! 11792: $chgtext .= '</ul>';
! 11793: }
! 11794: } else {
! 11795: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
! 11796: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
! 11797: }
! 11798: } elsif ($type eq 'emailverified') {
! 11799: my %options = &Apache::lonlocal::texthash (
! 11800: email => 'Username is e-mail',
! 11801: other => 'Username is chosen',
! 11802: );
! 11803: if (@statuses > 1) {
! 11804: my $numtypes = 0;
! 11805: foreach my $type (@statuses) {
! 11806: unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {
! 11807: $numtypes ++;
! 11808: }
! 11809: }
! 11810: if ($numtypes) {
! 11811: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
! 11812: '<ul>';
! 11813: foreach my $type (@statuses) {
! 11814: next if ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse');
! 11815: if ($type eq 'default') {
! 11816: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$type}}.'</li>';
! 11817: } else {
! 11818: $chgtext .= '<li>'.$usertypes{$type}.' -- '.$options{$cancreate{'emailverified'}{$type}}.'</li>';
! 11819: }
! 11820: }
! 11821: $chgtext .= '</ul>';
! 11822: }
! 11823: } else {
! 11824: $chgtext .= &mt('For self-created accounts verified by e-mail address: "[_1]"',
! 11825: $choices{$cancreate{'emailverified'}{'default'}});
! 11826: }
! 11827: } elsif ($type eq 'emaildomain') {
! 11828: if (@statuses > 1) {
! 11829: my $numtypes = 0;
! 11830: foreach my $type (@statuses) {
! 11831: unless ($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') {
! 11832: if ($cancreate{'emailverified'}{$type} eq 'other') {
! 11833: $numtypes ++;
! 11834: }
! 11835: }
! 11836: }
! 11837: if ($numtypes) {
! 11838: $chgtext .= &mt('For self-created accounts verified by e-mail address, with username chosen by user ...').
! 11839: '<ul>';
! 11840: foreach my $type (@statuses) {
! 11841: next if (($cancreate{'selfcreateprocessing'}{$type} eq 'notinuse') ||
! 11842: ($cancreate{'emailverified'}{$type} eq 'email'));
! 11843: if ($type eq 'default') {
! 11844: if ($cancreate{'emaildomain'}{$type} eq '') {
! 11845: $chgtext .= '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
! 11846: } else {
! 11847: $chgtext .= '<li>'.$othertitle.' -- '.&mt("User's e-mail domain needs to be: [_1]",
! 11848: $cancreate{'emaildomain'}{$type}).'</li>';
! 11849: }
! 11850: } else {
! 11851: if ($cancreate{'emaildomain'}{$type} eq '') {
! 11852: $chgtext .= '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
! 11853: } else {
! 11854: $chgtext .= '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail domain needs to be: [_1]",
! 11855: $cancreate{'emaildomain'}{$type}).'</li>';
! 11856: }
! 11857: }
! 11858: }
! 11859: $chgtext .= '</ul>';
! 11860: }
1.236 raeburn 11861: } else {
1.303 ! raeburn 11862: if ($cancreate{'emailverified'}{'default'} eq 'other') {
! 11863: if ($cancreate{'emaildomain'}{'default'} eq '') {
! 11864: $chgtext .= &mt('No restriction on e-mail domain for self-created accounts verified by e-mail address, where username is chosen by user.');
! 11865: } else {
! 11866: $chgtext .= &mt('For self-created accounts verified by e-mail address, where username is chosen by user, e-mail domain needs to be: [_1],
! 11867: $cancreate{'selfcreateprocessing'}{'default'});
! 11868: }
! 11869: }
1.236 raeburn 11870: }
1.165 raeburn 11871: } elsif ($type eq 'captcha') {
1.224 raeburn 11872: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 11873: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11874: } else {
11875: my %captchas = &captcha_phrases();
1.224 raeburn 11876: if ($captchas{$savecaptcha{$type}}) {
11877: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 11878: } else {
1.210 raeburn 11879: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 11880: }
11881: }
11882: } elsif ($type eq 'recaptchakeys') {
11883: my ($privkey,$pubkey);
1.224 raeburn 11884: if (ref($savecaptcha{$type}) eq 'HASH') {
11885: $pubkey = $savecaptcha{$type}{'public'};
11886: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 11887: }
11888: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11889: if (!$pubkey) {
11890: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11891: } else {
11892: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11893: }
11894: if (!$privkey) {
11895: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11896: } else {
11897: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11898: }
11899: $chgtext .= '</ul>';
1.269 raeburn 11900: } elsif ($type eq 'recaptchaversion') {
11901: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 11902: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 11903: }
1.224 raeburn 11904: } elsif ($type eq 'emailusername') {
11905: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.303 ! raeburn 11906: if (@types) {
! 11907: foreach my $type (@types) {
1.228 raeburn 11908: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11909: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 ! raeburn 11910: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 11911: '<ul>';
11912: foreach my $field (@{$infofields}) {
11913: if ($cancreate{'emailusername'}{$type}{$field}) {
11914: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11915: }
11916: }
1.245 raeburn 11917: $chgtext .= '</ul>';
11918: } else {
1.303 ! raeburn 11919: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.228 raeburn 11920: }
11921: } else {
1.303 ! raeburn 11922: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.224 raeburn 11923: }
11924: }
11925: }
11926: }
11927: } elsif ($type eq 'notify') {
1.303 ! raeburn 11928: my $numapprove = 0;
1.224 raeburn 11929: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11930: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11931: if ($cancreate{'notify'}{'approval'}) {
1.303 ! raeburn 11932: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
! 11933: $numapprove ++;
1.224 raeburn 11934: }
11935: }
1.43 raeburn 11936: }
1.303 ! raeburn 11937: unless ($numapprove) {
! 11938: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
! 11939: }
1.34 raeburn 11940: }
1.224 raeburn 11941: if ($chgtext) {
11942: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11943: }
11944: }
11945: }
1.43 raeburn 11946: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11947: my ($emailrules,$emailruleorder) =
11948: &Apache::lonnet::inst_userrules($dom,'email');
11949: my $chgtext = '<ul>';
11950: foreach my $type (@email_rule) {
11951: if (ref($emailrules->{$type}) eq 'HASH') {
11952: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11953: }
11954: }
11955: $chgtext .= '</ul>';
11956: if (@email_rule > 0) {
1.224 raeburn 11957: $resulttext .= '<li>'.
1.303 ! raeburn 11958: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ').
1.224 raeburn 11959: $chgtext.
11960: '</li>';
1.43 raeburn 11961: } else {
1.224 raeburn 11962: $resulttext .= '<li>'.
1.303 ! raeburn 11963: &mt('There are now no restrictions on e-mail addresses which may be used for verification when self-enrolling.').
1.224 raeburn 11964: '</li>';
1.43 raeburn 11965: }
11966: }
1.224 raeburn 11967: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11968: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11969: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11970: foreach my $type (@{$changes{'selfcreate'}}) {
11971: my $typename = $type;
1.303 ! raeburn 11972: if (keys(%usertypes) > 0) {
! 11973: if ($usertypes{$type} ne '') {
! 11974: $typename = $usertypes{$type};
1.224 raeburn 11975: }
11976: }
11977: my @modifiable;
11978: $resulttext .= '<li>'.
11979: &mt('Self-creation of account by users with status: [_1]',
11980: '<span class="LC_cusr_emph">'.$typename.'</span>').
11981: ' - '.&mt('modifiable fields (if institutional data blank): ');
11982: foreach my $field (@fields) {
11983: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11984: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 11985: }
11986: }
1.224 raeburn 11987: if (@modifiable > 0) {
11988: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11989: } else {
1.224 raeburn 11990: $resulttext .= &mt('none');
1.43 raeburn 11991: }
1.224 raeburn 11992: $resulttext .= '</li>';
1.28 raeburn 11993: }
1.224 raeburn 11994: $resulttext .= '</ul></li>';
1.28 raeburn 11995: }
1.27 raeburn 11996: $resulttext .= '</ul>';
11997: } else {
1.224 raeburn 11998: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11999: }
12000: } else {
12001: $resulttext = '<span class="LC_error">'.
1.23 raeburn 12002: &mt('An error occurred: [_1]',$putresult).'</span>';
12003: }
1.43 raeburn 12004: if ($warningmsg ne '') {
12005: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
12006: }
1.23 raeburn 12007: return $resulttext;
12008: }
12009:
1.165 raeburn 12010: sub process_captcha {
12011: my ($container,$changes,$newsettings,$current) = @_;
12012: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
12013: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
12014: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
12015: $newsettings->{'captcha'} = 'original';
12016: }
12017: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 12018: if ($container eq 'cancreate') {
1.169 raeburn 12019: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12020: push(@{$changes->{'cancreate'}},'captcha');
12021: } elsif (!defined($changes->{'cancreate'})) {
12022: $changes->{'cancreate'} = ['captcha'];
12023: }
12024: } else {
12025: $changes->{'captcha'} = 1;
1.165 raeburn 12026: }
12027: }
1.269 raeburn 12028: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 12029: if ($newsettings->{'captcha'} eq 'recaptcha') {
12030: $newpub = $env{'form.'.$container.'_recaptchapub'};
12031: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 12032: $newpub =~ s/[^\w\-]//g;
12033: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 12034: $newsettings->{'recaptchakeys'} = {
12035: public => $newpub,
12036: private => $newpriv,
12037: };
1.269 raeburn 12038: $newversion = $env{'form.'.$container.'_recaptchaversion'};
12039: $newversion =~ s/\D//g;
12040: if ($newversion ne '2') {
12041: $newversion = 1;
12042: }
12043: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 12044: }
12045: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
12046: $currpub = $current->{'recaptchakeys'}{'public'};
12047: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 12048: unless ($newsettings->{'captcha'} eq 'recaptcha') {
12049: $newsettings->{'recaptchakeys'} = {
12050: public => '',
12051: private => '',
12052: }
12053: }
1.165 raeburn 12054: }
1.269 raeburn 12055: if ($current->{'captcha'} eq 'recaptcha') {
12056: $currversion = $current->{'recaptchaversion'};
12057: if ($currversion ne '2') {
12058: $currversion = 1;
12059: }
12060: }
12061: if ($currversion ne $newversion) {
12062: if ($container eq 'cancreate') {
12063: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12064: push(@{$changes->{'cancreate'}},'recaptchaversion');
12065: } elsif (!defined($changes->{'cancreate'})) {
12066: $changes->{'cancreate'} = ['recaptchaversion'];
12067: }
12068: } else {
12069: $changes->{'recaptchaversion'} = 1;
12070: }
12071: }
1.165 raeburn 12072: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 12073: if ($container eq 'cancreate') {
12074: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
12075: push(@{$changes->{'cancreate'}},'recaptchakeys');
12076: } elsif (!defined($changes->{'cancreate'})) {
12077: $changes->{'cancreate'} = ['recaptchakeys'];
12078: }
12079: } else {
1.210 raeburn 12080: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 12081: }
12082: }
12083: return;
12084: }
12085:
1.33 raeburn 12086: sub modify_usermodification {
12087: my ($dom,%domconfig) = @_;
1.224 raeburn 12088: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 12089: if (ref($domconfig{'usermodification'}) eq 'HASH') {
12090: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 12091: if ($key eq 'selfcreate') {
12092: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
12093: } else {
12094: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
12095: }
1.33 raeburn 12096: }
12097: }
1.224 raeburn 12098: my @contexts = ('author','course');
1.33 raeburn 12099: my %context_title = (
12100: author => 'In author context',
12101: course => 'In course context',
12102: );
12103: my @fields = ('lastname','firstname','middlename','generation',
12104: 'permanentemail','id');
12105: my %roles = (
12106: author => ['ca','aa'],
12107: course => ['st','ep','ta','in','cr'],
12108: );
12109: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12110: foreach my $context (@contexts) {
12111: foreach my $role (@{$roles{$context}}) {
12112: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
12113: foreach my $item (@fields) {
12114: if (grep(/^\Q$item\E$/,@modifiable)) {
12115: $modifyhash{$context}{$role}{$item} = 1;
12116: } else {
12117: $modifyhash{$context}{$role}{$item} = 0;
12118: }
12119: }
12120: }
12121: if (ref($curr_usermodification{$context}) eq 'HASH') {
12122: foreach my $role (@{$roles{$context}}) {
12123: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
12124: foreach my $field (@fields) {
12125: if ($modifyhash{$context}{$role}{$field} ne
12126: $curr_usermodification{$context}{$role}{$field}) {
12127: push(@{$changes{$context}},$role);
12128: last;
12129: }
12130: }
12131: }
12132: }
12133: } else {
12134: foreach my $context (@contexts) {
12135: foreach my $role (@{$roles{$context}}) {
12136: push(@{$changes{$context}},$role);
12137: }
12138: }
12139: }
12140: }
12141: my %usermodification_hash = (
12142: usermodification => \%modifyhash,
12143: );
12144: my $putresult = &Apache::lonnet::put_dom('configuration',
12145: \%usermodification_hash,$dom);
12146: if ($putresult eq 'ok') {
12147: if (keys(%changes) > 0) {
12148: $resulttext = &mt('Changes made: ').'<ul>';
12149: foreach my $context (@contexts) {
12150: if (ref($changes{$context}) eq 'ARRAY') {
12151: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
12152: if (ref($changes{$context}) eq 'ARRAY') {
12153: foreach my $role (@{$changes{$context}}) {
12154: my $rolename;
1.224 raeburn 12155: if ($role eq 'cr') {
12156: $rolename = &mt('Custom');
1.33 raeburn 12157: } else {
1.224 raeburn 12158: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 12159: }
12160: my @modifiable;
1.224 raeburn 12161: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 12162: foreach my $field (@fields) {
12163: if ($modifyhash{$context}{$role}{$field}) {
12164: push(@modifiable,$fieldtitles{$field});
12165: }
12166: }
12167: if (@modifiable > 0) {
12168: $resulttext .= join(', ',@modifiable);
12169: } else {
12170: $resulttext .= &mt('none');
12171: }
12172: $resulttext .= '</li>';
12173: }
12174: $resulttext .= '</ul></li>';
12175: }
12176: }
12177: }
12178: $resulttext .= '</ul>';
12179: } else {
12180: $resulttext = &mt('No changes made to user modification settings');
12181: }
12182: } else {
12183: $resulttext = '<span class="LC_error">'.
12184: &mt('An error occurred: [_1]',$putresult).'</span>';
12185: }
12186: return $resulttext;
12187: }
12188:
1.43 raeburn 12189: sub modify_defaults {
1.212 raeburn 12190: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 12191: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 12192: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 12193: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
12194: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 12195: my @authtypes = ('internal','krb4','krb5','localauth');
12196: foreach my $item (@items) {
12197: $newvalues{$item} = $env{'form.'.$item};
12198: if ($item eq 'auth_def') {
12199: if ($newvalues{$item} ne '') {
12200: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
12201: push(@errors,$item);
12202: }
12203: }
12204: } elsif ($item eq 'lang_def') {
12205: if ($newvalues{$item} ne '') {
12206: if ($newvalues{$item} =~ /^(\w+)/) {
12207: my $langcode = $1;
1.103 raeburn 12208: if ($langcode ne 'x_chef') {
12209: if (code2language($langcode) eq '') {
12210: push(@errors,$item);
12211: }
1.43 raeburn 12212: }
12213: } else {
12214: push(@errors,$item);
12215: }
12216: }
1.54 raeburn 12217: } elsif ($item eq 'timezone_def') {
12218: if ($newvalues{$item} ne '') {
1.62 raeburn 12219: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 12220: push(@errors,$item);
12221: }
12222: }
1.68 raeburn 12223: } elsif ($item eq 'datelocale_def') {
12224: if ($newvalues{$item} ne '') {
12225: my @datelocale_ids = DateTime::Locale->ids();
12226: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
12227: push(@errors,$item);
12228: }
12229: }
1.141 raeburn 12230: } elsif ($item eq 'portal_def') {
12231: if ($newvalues{$item} ne '') {
12232: 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])\/?$/) {
12233: push(@errors,$item);
12234: }
12235: }
1.294 raeburn 12236: } elsif ($item eq 'intauth_cost') {
12237: if ($newvalues{$item} ne '') {
12238: if ($newvalues{$item} =~ /\D/) {
12239: push(@errors,$item);
12240: }
12241: }
12242: } elsif ($item eq 'intauth_check') {
12243: if ($newvalues{$item} ne '') {
12244: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12245: push(@errors,$item);
12246: }
12247: }
12248: } elsif ($item eq 'intauth_switch') {
12249: if ($newvalues{$item} ne '') {
12250: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
12251: push(@errors,$item);
12252: }
12253: }
1.43 raeburn 12254: }
12255: if (grep(/^\Q$item\E$/,@errors)) {
12256: $newvalues{$item} = $domdefaults{$item};
12257: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
12258: $changes{$item} = 1;
12259: }
1.72 raeburn 12260: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 12261: }
12262: my %defaults_hash = (
1.72 raeburn 12263: defaults => \%newvalues,
12264: );
1.43 raeburn 12265: my $title = &defaults_titles();
1.236 raeburn 12266:
12267: my $currinststatus;
12268: if (ref($domconfig{'inststatus'}) eq 'HASH') {
12269: $currinststatus = $domconfig{'inststatus'};
12270: } else {
12271: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12272: $currinststatus = {
12273: inststatustypes => $usertypes,
12274: inststatusorder => $types,
12275: inststatusguest => [],
12276: };
12277: }
12278: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
12279: my @allpos;
12280: my %guests;
12281: my %alltypes;
12282: my ($currtitles,$currguests,$currorder);
12283: if (ref($currinststatus) eq 'HASH') {
12284: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12285: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12286: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12287: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12288: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12289: }
12290: }
12291: unless (grep(/^\Q$type\E$/,@todelete)) {
12292: my $position = $env{'form.inststatus_pos_'.$type};
12293: $position =~ s/\D+//g;
12294: $allpos[$position] = $type;
12295: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12296: $alltypes{$type} =~ s/`//g;
12297: if ($env{'form.inststatus_guest_'.$type}) {
12298: $guests{$type} = 1;
12299: }
12300: }
12301: }
12302: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12303: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
12304: }
12305: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12306: $currtitles =~ s/,$//;
12307: }
12308: }
12309: if ($env{'form.addinststatus'}) {
12310: my $newtype = $env{'form.addinststatus'};
12311: $newtype =~ s/\W//g;
12312: unless (exists($alltypes{$newtype})) {
12313: if ($env{'form.addinststatus_guest'}) {
12314: $guests{$newtype} = 1;
12315: }
12316: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12317: $alltypes{$newtype} =~ s/`//g;
12318: my $position = $env{'form.addinststatus_pos'};
12319: $position =~ s/\D+//g;
12320: if ($position ne '') {
12321: $allpos[$position] = $newtype;
12322: }
12323: }
12324: }
12325: my (@orderedstatus,@orderedguests);
12326: foreach my $type (@allpos) {
12327: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12328: push(@orderedstatus,$type);
12329: if ($guests{$type}) {
12330: push(@orderedguests,$type);
12331: }
12332: }
12333: }
12334: foreach my $type (keys(%alltypes)) {
12335: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12336: delete($alltypes{$type});
12337: }
12338: }
12339: $defaults_hash{'inststatus'} = {
12340: inststatustypes => \%alltypes,
12341: inststatusorder => \@orderedstatus,
12342: inststatusguest => \@orderedguests,
12343: };
12344: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12345: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12346: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12347: }
12348: }
12349: if ($currorder ne join(',',@orderedstatus)) {
12350: $changes{'inststatus'}{'inststatusorder'} = 1;
12351: }
12352: if ($currguests ne join(',',@orderedguests)) {
12353: $changes{'inststatus'}{'inststatusguest'} = 1;
12354: }
12355: my $newtitles;
12356: foreach my $item (@orderedstatus) {
12357: $newtitles .= $alltypes{$item}.',';
12358: }
12359: $newtitles =~ s/,$//;
12360: if ($currtitles ne $newtitles) {
12361: $changes{'inststatus'}{'inststatustypes'} = 1;
12362: }
1.43 raeburn 12363: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12364: $dom);
12365: if ($putresult eq 'ok') {
12366: if (keys(%changes) > 0) {
12367: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 12368: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12369: 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";
12370: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 12371: if ($item eq 'inststatus') {
12372: if (ref($changes{'inststatus'}) eq 'HASH') {
12373: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
12374: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12375: foreach my $type (@orderedstatus) {
12376: $resulttext .= $alltypes{$type}.', ';
12377: }
12378: $resulttext =~ s/, $//;
12379: $resulttext .= '</li>';
12380: }
12381: if ($changes{'inststatus'}{'inststatusguest'}) {
12382: $resulttext .= '<li>';
12383: if (@orderedguests) {
12384: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
12385: foreach my $type (@orderedguests) {
12386: $resulttext .= $alltypes{$type}.', ';
12387: }
12388: $resulttext =~ s/, $//;
12389: } else {
12390: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
12391: }
12392: $resulttext .= '</li>';
12393: }
12394: }
12395: } else {
12396: my $value = $env{'form.'.$item};
12397: if ($value eq '') {
12398: $value = &mt('none');
12399: } elsif ($item eq 'auth_def') {
12400: my %authnames = &authtype_names();
12401: my %shortauth = (
12402: internal => 'int',
12403: krb4 => 'krb4',
12404: krb5 => 'krb5',
12405: localauth => 'loc',
12406: );
12407: $value = $authnames{$shortauth{$value}};
1.294 raeburn 12408: } elsif ($item eq 'intauth_switch') {
12409: my %optiondesc = &Apache::lonlocal::texthash (
12410: 0 => 'No',
12411: 1 => 'Yes',
12412: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12413: );
12414: if ($value =~ /^(0|1|2)$/) {
12415: $value = $optiondesc{$value};
12416: } else {
12417: $value = &mt('none -- defaults to No');
12418: }
12419: } elsif ($item eq 'intauth_check') {
12420: my %optiondesc = &Apache::lonlocal::texthash (
12421: 0 => 'No',
12422: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12423: 2 => 'Yes, disallow login if stored cost is less than domain default',
12424: );
12425: if ($value =~ /^(0|1|2)$/) {
12426: $value = $optiondesc{$value};
12427: } else {
12428: $value = &mt('none -- defaults to No');
12429: }
1.236 raeburn 12430: }
12431: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12432: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12433: }
12434: }
12435: $resulttext .= '</ul>';
12436: $mailmsgtext .= "\n";
12437: my $cachetime = 24*60*60;
1.72 raeburn 12438: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12439: if (ref($lastactref) eq 'HASH') {
12440: $lastactref->{'domdefaults'} = 1;
12441: }
1.68 raeburn 12442: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 12443: my $notify = 1;
12444: if (ref($domconfig{'contacts'}) eq 'HASH') {
12445: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12446: $notify = 0;
12447: }
12448: }
12449: if ($notify) {
12450: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12451: "LON-CAPA Domain Settings Change - $dom",
12452: $mailmsgtext);
12453: }
1.54 raeburn 12454: }
1.43 raeburn 12455: } else {
1.54 raeburn 12456: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12457: }
12458: } else {
12459: $resulttext = '<span class="LC_error">'.
12460: &mt('An error occurred: [_1]',$putresult).'</span>';
12461: }
12462: if (@errors > 0) {
12463: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12464: foreach my $item (@errors) {
12465: $resulttext .= ' "'.$title->{$item}.'",';
12466: }
12467: $resulttext =~ s/,$//;
12468: }
12469: return $resulttext;
12470: }
12471:
1.46 raeburn 12472: sub modify_scantron {
1.205 raeburn 12473: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12474: my ($resulttext,%confhash,%changes,$errors);
12475: my $custom = 'custom.tab';
12476: my $default = 'default.tab';
12477: my $servadm = $r->dir_config('lonAdmEMail');
12478: my ($configuserok,$author_ok,$switchserver) =
12479: &config_check($dom,$confname,$servadm);
12480: if ($env{'form.scantronformat.filename'} ne '') {
12481: my $error;
12482: if ($configuserok eq 'ok') {
12483: if ($switchserver) {
1.130 raeburn 12484: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12485: } else {
12486: if ($author_ok eq 'ok') {
12487: my ($result,$scantronurl) =
12488: &publishlogo($r,'upload','scantronformat',$dom,
12489: $confname,'scantron','','',$custom);
12490: if ($result eq 'ok') {
12491: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12492: $changes{'scantronformat'} = 1;
1.46 raeburn 12493: } else {
12494: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12495: }
12496: } else {
12497: $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);
12498: }
12499: }
12500: } else {
12501: $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);
12502: }
12503: if ($error) {
12504: &Apache::lonnet::logthis($error);
12505: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12506: }
12507: }
1.48 raeburn 12508: if (ref($domconfig{'scantron'}) eq 'HASH') {
12509: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12510: if ($env{'form.scantronformat_del'}) {
12511: $confhash{'scantron'}{'scantronformat'} = '';
12512: $changes{'scantronformat'} = 1;
1.46 raeburn 12513: }
12514: }
12515: }
12516: if (keys(%confhash) > 0) {
12517: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12518: $dom);
12519: if ($putresult eq 'ok') {
12520: if (keys(%changes) > 0) {
1.48 raeburn 12521: if (ref($confhash{'scantron'}) eq 'HASH') {
12522: $resulttext = &mt('Changes made:').'<ul>';
12523: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 12524: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 12525: } else {
1.130 raeburn 12526: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 12527: }
1.48 raeburn 12528: $resulttext .= '</ul>';
12529: } else {
1.130 raeburn 12530: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12531: }
12532: $resulttext .= '</ul>';
12533: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12534: if (ref($lastactref) eq 'HASH') {
12535: $lastactref->{'domainconfig'} = 1;
12536: }
1.46 raeburn 12537: } else {
1.130 raeburn 12538: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12539: }
12540: } else {
12541: $resulttext = '<span class="LC_error">'.
12542: &mt('An error occurred: [_1]',$putresult).'</span>';
12543: }
12544: } else {
1.130 raeburn 12545: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12546: }
12547: if ($errors) {
12548: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12549: $errors.'</ul>';
12550: }
12551: return $resulttext;
12552: }
12553:
1.48 raeburn 12554: sub modify_coursecategories {
1.239 raeburn 12555: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12556: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12557: $cathash);
1.48 raeburn 12558: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 12559: my @catitems = ('unauth','auth');
12560: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12561: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12562: $cathash = $domconfig{'coursecategories'}{'cats'};
12563: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12564: $changes{'togglecats'} = 1;
12565: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12566: }
12567: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12568: $changes{'categorize'} = 1;
12569: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12570: }
1.120 raeburn 12571: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12572: $changes{'togglecatscomm'} = 1;
12573: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12574: }
12575: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12576: $changes{'categorizecomm'} = 1;
12577: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 12578:
12579: }
12580: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
12581: $changes{'togglecatsplace'} = 1;
12582: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
12583: }
12584: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
12585: $changes{'categorizeplace'} = 1;
12586: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 12587: }
1.238 raeburn 12588: foreach my $item (@catitems) {
12589: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12590: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12591: $changes{$item} = 1;
12592: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12593: }
12594: }
12595: }
1.57 raeburn 12596: } else {
12597: $changes{'togglecats'} = 1;
12598: $changes{'categorize'} = 1;
1.124 raeburn 12599: $changes{'togglecatscomm'} = 1;
12600: $changes{'categorizecomm'} = 1;
1.272 raeburn 12601: $changes{'togglecatsplace'} = 1;
12602: $changes{'categorizeplace'} = 1;
1.87 raeburn 12603: $domconfig{'coursecategories'} = {
12604: togglecats => $env{'form.togglecats'},
12605: categorize => $env{'form.categorize'},
1.124 raeburn 12606: togglecatscomm => $env{'form.togglecatscomm'},
12607: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 12608: togglecatsplace => $env{'form.togglecatsplace'},
12609: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 12610: };
1.238 raeburn 12611: foreach my $item (@catitems) {
12612: if ($env{'form.coursecat_'.$item} ne 'std') {
12613: $changes{$item} = 1;
12614: }
12615: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12616: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12617: }
12618: }
1.57 raeburn 12619: }
12620: if (ref($cathash) eq 'HASH') {
12621: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12622: push (@deletecategory,'instcode::0');
12623: }
1.120 raeburn 12624: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12625: push(@deletecategory,'communities::0');
12626: }
1.272 raeburn 12627: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
12628: push(@deletecategory,'placement::0');
12629: }
1.48 raeburn 12630: }
1.57 raeburn 12631: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12632: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12633: if (@deletecategory > 0) {
12634: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12635: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12636: foreach my $item (@deletecategory) {
1.57 raeburn 12637: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12638: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12639: $deletions{$item} = 1;
1.57 raeburn 12640: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12641: }
12642: }
12643: }
1.57 raeburn 12644: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12645: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12646: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12647: $reorderings{$item} = 1;
1.57 raeburn 12648: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12649: }
12650: if ($env{'form.addcategory_name_'.$item} ne '') {
12651: my $newcat = $env{'form.addcategory_name_'.$item};
12652: my $newdepth = $depth+1;
12653: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12654: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12655: $adds{$newitem} = 1;
12656: }
12657: if ($env{'form.subcat_'.$item} ne '') {
12658: my $newcat = $env{'form.subcat_'.$item};
12659: my $newdepth = $depth+1;
12660: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12661: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12662: $adds{$newitem} = 1;
12663: }
12664: }
12665: }
12666: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12667: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12668: my $newitem = 'instcode::0';
1.57 raeburn 12669: if ($cathash->{$newitem} eq '') {
12670: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12671: $adds{$newitem} = 1;
12672: }
12673: } else {
12674: my $newitem = 'instcode::0';
1.57 raeburn 12675: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12676: $adds{$newitem} = 1;
12677: }
12678: }
1.120 raeburn 12679: if ($env{'form.communities'} eq '1') {
12680: if (ref($cathash) eq 'HASH') {
12681: my $newitem = 'communities::0';
12682: if ($cathash->{$newitem} eq '') {
12683: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12684: $adds{$newitem} = 1;
12685: }
12686: } else {
12687: my $newitem = 'communities::0';
12688: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12689: $adds{$newitem} = 1;
12690: }
12691: }
1.272 raeburn 12692: if ($env{'form.placement'} eq '1') {
12693: if (ref($cathash) eq 'HASH') {
12694: my $newitem = 'placement::0';
12695: if ($cathash->{$newitem} eq '') {
12696: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12697: $adds{$newitem} = 1;
12698: }
12699: } else {
12700: my $newitem = 'placement::0';
12701: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12702: $adds{$newitem} = 1;
12703: }
12704: }
1.48 raeburn 12705: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12706: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 12707: ($env{'form.addcategory_name'} ne 'communities') &&
12708: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 12709: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12710: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12711: $adds{$newitem} = 1;
12712: }
1.48 raeburn 12713: }
1.57 raeburn 12714: my $putresult;
1.48 raeburn 12715: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12716: if (keys(%deletions) > 0) {
12717: foreach my $key (keys(%deletions)) {
12718: if ($predelallitems{$key} ne '') {
12719: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12720: }
12721: }
12722: }
12723: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12724: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12725: if (ref($chkcats[0]) eq 'ARRAY') {
12726: my $depth = 0;
12727: my $chg = 0;
12728: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12729: my $name = $chkcats[0][$i];
12730: my $item;
12731: if ($name eq '') {
12732: $chg ++;
12733: } else {
12734: $item = &escape($name).'::0';
12735: if ($chg) {
1.57 raeburn 12736: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12737: }
12738: $depth ++;
1.57 raeburn 12739: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12740: $depth --;
12741: }
12742: }
12743: }
1.57 raeburn 12744: }
12745: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12746: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12747: if ($putresult eq 'ok') {
1.57 raeburn 12748: my %title = (
1.120 raeburn 12749: togglecats => 'Show/Hide a course in catalog',
12750: categorize => 'Assign a category to a course',
12751: togglecatscomm => 'Show/Hide a community in catalog',
12752: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12753: );
12754: my %level = (
1.120 raeburn 12755: dom => 'set in Domain ("Modify Course/Community")',
12756: crs => 'set in Course ("Course Configuration")',
12757: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 12758: none => 'No catalog',
12759: std => 'Standard catalog',
12760: domonly => 'Domain-only catalog',
12761: codesrch => 'Code search form',
1.57 raeburn 12762: );
1.48 raeburn 12763: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12764: if ($changes{'togglecats'}) {
12765: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12766: }
12767: if ($changes{'categorize'}) {
12768: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12769: }
1.120 raeburn 12770: if ($changes{'togglecatscomm'}) {
12771: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12772: }
12773: if ($changes{'categorizecomm'}) {
12774: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12775: }
1.238 raeburn 12776: if ($changes{'unauth'}) {
12777: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12778: }
12779: if ($changes{'auth'}) {
12780: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12781: }
1.57 raeburn 12782: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12783: my $cathash;
12784: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12785: $cathash = $domconfig{'coursecategories'}{'cats'};
12786: } else {
12787: $cathash = {};
12788: }
12789: my (@cats,@trails,%allitems);
12790: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12791: if (keys(%deletions) > 0) {
12792: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12793: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12794: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12795: }
12796: $resulttext .= '</ul></li>';
12797: }
12798: if (keys(%reorderings) > 0) {
12799: my %sort_by_trail;
12800: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12801: foreach my $key (keys(%reorderings)) {
12802: if ($allitems{$key} ne '') {
12803: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12804: }
1.48 raeburn 12805: }
1.57 raeburn 12806: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12807: $resulttext .= '<li>'.$trails[$trail].'</li>';
12808: }
12809: $resulttext .= '</ul></li>';
1.48 raeburn 12810: }
1.57 raeburn 12811: if (keys(%adds) > 0) {
12812: my %sort_by_trail;
12813: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12814: foreach my $key (keys(%adds)) {
12815: if ($allitems{$key} ne '') {
12816: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12817: }
12818: }
12819: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12820: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12821: }
1.57 raeburn 12822: $resulttext .= '</ul></li>';
1.48 raeburn 12823: }
12824: }
12825: $resulttext .= '</ul>';
1.239 raeburn 12826: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 12827: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12828: if ($changes{'auth'}) {
12829: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12830: }
12831: if ($changes{'unauth'}) {
12832: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12833: }
12834: my $cachetime = 24*60*60;
12835: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 12836: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 12837: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 12838: }
12839: }
1.48 raeburn 12840: } else {
12841: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12842: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12843: }
12844: } else {
1.120 raeburn 12845: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12846: }
12847: return $resulttext;
12848: }
12849:
1.69 raeburn 12850: sub modify_serverstatuses {
12851: my ($dom,%domconfig) = @_;
12852: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12853: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12854: %currserverstatus = %{$domconfig{'serverstatuses'}};
12855: }
12856: my @pages = &serverstatus_pages();
12857: foreach my $type (@pages) {
12858: $newserverstatus{$type}{'namedusers'} = '';
12859: $newserverstatus{$type}{'machines'} = '';
12860: if (defined($env{'form.'.$type.'_namedusers'})) {
12861: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12862: my @okusers;
12863: foreach my $user (@users) {
12864: my ($uname,$udom) = split(/:/,$user);
12865: if (($udom =~ /^$match_domain$/) &&
12866: (&Apache::lonnet::domain($udom)) &&
12867: ($uname =~ /^$match_username$/)) {
12868: if (!grep(/^\Q$user\E/,@okusers)) {
12869: push(@okusers,$user);
12870: }
12871: }
12872: }
12873: if (@okusers > 0) {
12874: @okusers = sort(@okusers);
12875: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12876: }
12877: }
12878: if (defined($env{'form.'.$type.'_machines'})) {
12879: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12880: my @okmachines;
12881: foreach my $ip (@machines) {
12882: my @parts = split(/\./,$ip);
12883: next if (@parts < 4);
12884: my $badip = 0;
12885: for (my $i=0; $i<4; $i++) {
12886: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12887: $badip = 1;
12888: last;
12889: }
12890: }
12891: if (!$badip) {
12892: push(@okmachines,$ip);
12893: }
12894: }
12895: @okmachines = sort(@okmachines);
12896: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12897: }
12898: }
12899: my %serverstatushash = (
12900: serverstatuses => \%newserverstatus,
12901: );
12902: foreach my $type (@pages) {
1.83 raeburn 12903: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12904: my (@current,@new);
1.83 raeburn 12905: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12906: if ($currserverstatus{$type}{$setting} ne '') {
12907: @current = split(/,/,$currserverstatus{$type}{$setting});
12908: }
12909: }
12910: if ($newserverstatus{$type}{$setting} ne '') {
12911: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12912: }
12913: if (@current > 0) {
12914: if (@new > 0) {
12915: foreach my $item (@current) {
12916: if (!grep(/^\Q$item\E$/,@new)) {
12917: $changes{$type}{$setting} = 1;
1.82 raeburn 12918: last;
12919: }
12920: }
1.84 raeburn 12921: foreach my $item (@new) {
12922: if (!grep(/^\Q$item\E$/,@current)) {
12923: $changes{$type}{$setting} = 1;
12924: last;
1.82 raeburn 12925: }
12926: }
12927: } else {
1.83 raeburn 12928: $changes{$type}{$setting} = 1;
1.69 raeburn 12929: }
1.83 raeburn 12930: } elsif (@new > 0) {
12931: $changes{$type}{$setting} = 1;
1.69 raeburn 12932: }
12933: }
12934: }
12935: if (keys(%changes) > 0) {
1.81 raeburn 12936: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12937: my $putresult = &Apache::lonnet::put_dom('configuration',
12938: \%serverstatushash,$dom);
12939: if ($putresult eq 'ok') {
12940: $resulttext .= &mt('Changes made:').'<ul>';
12941: foreach my $type (@pages) {
1.84 raeburn 12942: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12943: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12944: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12945: if ($newserverstatus{$type}{'namedusers'} eq '') {
12946: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12947: } else {
12948: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12949: }
1.84 raeburn 12950: }
12951: if ($changes{$type}{'machines'}) {
1.69 raeburn 12952: if ($newserverstatus{$type}{'machines'} eq '') {
12953: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12954: } else {
12955: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12956: }
12957:
12958: }
12959: $resulttext .= '</ul></li>';
12960: }
12961: }
12962: $resulttext .= '</ul>';
12963: } else {
12964: $resulttext = '<span class="LC_error">'.
12965: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12966:
12967: }
12968: } else {
12969: $resulttext = &mt('No changes made to access to server status pages');
12970: }
12971: return $resulttext;
12972: }
12973:
1.118 jms 12974: sub modify_helpsettings {
1.285 raeburn 12975: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 12976: my ($resulttext,$errors,%changes,%helphash);
12977: my %defaultchecked = ('submitbugs' => 'on');
12978: my @offon = ('off','on');
1.118 jms 12979: my @toggles = ('submitbugs');
1.285 raeburn 12980: my %current = ('submitbugs' => '',
12981: 'adhoc' => {},
12982: );
1.118 jms 12983: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 12984: %current = %{$domconfig{'helpsettings'}};
12985: }
1.285 raeburn 12986: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 12987: foreach my $item (@toggles) {
12988: if ($defaultchecked{$item} eq 'on') {
12989: if ($current{$item} eq '') {
12990: if ($env{'form.'.$item} eq '0') {
12991: $changes{$item} = 1;
12992: }
12993: } elsif ($current{$item} ne $env{'form.'.$item}) {
12994: $changes{$item} = 1;
12995: }
12996: } elsif ($defaultchecked{$item} eq 'off') {
12997: if ($current{$item} eq '') {
12998: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 12999: $changes{$item} = 1;
13000: }
1.282 raeburn 13001: } elsif ($current{$item} ne $env{'form.'.$item}) {
13002: $changes{$item} = 1;
13003: }
13004: }
13005: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
13006: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
13007: }
13008: }
1.285 raeburn 13009: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 13010: my $confname = $dom.'-domainconfig';
13011: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 13012: my (@allpos,%newsettings,%changedprivs,$newrole);
13013: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 13014: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 13015: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 13016: my %lt = &Apache::lonlocal::texthash(
13017: s => 'system',
13018: d => 'domain',
13019: order => 'Display order',
13020: access => 'Role usage',
1.291 raeburn 13021: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 13022: dh => 'All with domain helpdesk role',
13023: da => 'All with domain helpdesk assistant role',
1.285 raeburn 13024: none => 'None',
13025: status => 'Determined based on institutional status',
13026: inc => 'Include all, but exclude specific personnel',
13027: exc => 'Exclude all, but include specific personnel',
13028: );
13029: for (my $num=0; $num<=$maxnum; $num++) {
13030: my ($prefix,$identifier,$rolename,%curr);
13031: if ($num == $maxnum) {
13032: next unless ($env{'form.newcusthelp'} == $maxnum);
13033: $identifier = 'custhelp'.$num;
13034: $prefix = 'helproles_'.$num;
13035: $rolename = $env{'form.custhelpname'.$num};
13036: $rolename=~s/[^A-Za-z0-9]//gs;
13037: next if ($rolename eq '');
13038: next if (exists($existing{'rolesdef_'.$rolename}));
13039: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13040: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13041: $newprivs{'c'},$confname,$dom);
13042: if ($result ne 'ok') {
13043: $errors .= '<li><span class="LC_error">'.
13044: &mt('An error occurred storing the new custom role: [_1]',
13045: $result).'</span></li>';
13046: next;
13047: } else {
13048: $changedprivs{$rolename} = \%newprivs;
13049: $newrole = $rolename;
13050: }
13051: } else {
13052: $prefix = 'helproles_'.$num;
13053: $rolename = $env{'form.'.$prefix};
13054: next if ($rolename eq '');
13055: next unless (exists($existing{'rolesdef_'.$rolename}));
13056: $identifier = 'custhelp'.$num;
13057: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
13058: my %currprivs;
1.289 raeburn 13059: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 13060: split(/\_/,$existing{'rolesdef_'.$rolename});
13061: foreach my $level ('c','d','s') {
13062: if ($newprivs{$level} ne $currprivs{$level}) {
13063: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
13064: $newprivs{'c'},$confname,$dom);
13065: if ($result ne 'ok') {
13066: $errors .= '<li><span class="LC_error">'.
13067: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
13068: $rolename,$result).'</span></li>';
13069: } else {
13070: $changedprivs{$rolename} = \%newprivs;
13071: }
13072: last;
13073: }
13074: }
13075: if (ref($current{'adhoc'}) eq 'HASH') {
13076: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13077: %curr = %{$current{'adhoc'}{$rolename}};
13078: }
13079: }
13080: }
13081: my $newpos = $env{'form.'.$prefix.'_pos'};
13082: $newpos =~ s/\D+//g;
13083: $allpos[$newpos] = $rolename;
13084: my $newdesc = $env{'form.'.$prefix.'_desc'};
13085: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
13086: if ($curr{'desc'}) {
13087: if ($curr{'desc'} ne $newdesc) {
13088: $changes{'customrole'}{$rolename}{'desc'} = 1;
13089: $newsettings{$rolename}{'desc'} = $newdesc;
13090: }
13091: } elsif ($newdesc ne '') {
13092: $changes{'customrole'}{$rolename}{'desc'} = 1;
13093: $newsettings{$rolename}{'desc'} = $newdesc;
13094: }
13095: my $access = $env{'form.'.$prefix.'_access'};
13096: if (grep(/^\Q$access\E$/,@accesstypes)) {
13097: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
13098: if ($access eq 'status') {
13099: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
13100: if (scalar(@statuses) == 0) {
1.289 raeburn 13101: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 13102: } else {
13103: my (@shownstatus,$numtypes);
13104: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13105: if (ref($types) eq 'ARRAY') {
13106: $numtypes = scalar(@{$types});
13107: foreach my $type (sort(@statuses)) {
13108: if ($type eq 'default') {
13109: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13110: } elsif (grep(/^\Q$type\E$/,@{$types})) {
13111: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
13112: push(@shownstatus,$usertypes->{$type});
13113: }
13114: }
13115: }
13116: if (grep(/^default$/,@statuses)) {
13117: push(@shownstatus,$othertitle);
13118: }
13119: if (scalar(@shownstatus) == 1+$numtypes) {
13120: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
13121: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
13122: } else {
13123: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
13124: if (ref($curr{'status'}) eq 'ARRAY') {
13125: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13126: if (@diffs) {
13127: $changes{'customrole'}{$rolename}{$access} = 1;
13128: }
13129: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13130: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 13131: }
1.166 raeburn 13132: }
13133: }
1.285 raeburn 13134: } elsif (($access eq 'inc') || ($access eq 'exc')) {
13135: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
13136: my @newspecstaff;
13137: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
13138: foreach my $person (sort(@personnel)) {
13139: if ($domhelpdesk{$person}) {
13140: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
13141: }
13142: }
13143: if (ref($curr{$access}) eq 'ARRAY') {
13144: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
13145: if (@diffs) {
13146: $changes{'customrole'}{$rolename}{$access} = 1;
13147: }
13148: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13149: $changes{'customrole'}{$rolename}{$access} = 1;
13150: }
13151: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
13152: my ($uname,$udom) = split(/:/,$person);
13153: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
13154: }
13155: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 13156: }
1.285 raeburn 13157: } else {
13158: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
13159: }
13160: unless ($curr{'access'} eq $access) {
13161: $changes{'customrole'}{$rolename}{'access'} = 1;
13162: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 13163: }
13164: }
1.285 raeburn 13165: if (@allpos > 0) {
13166: my $idx = 0;
13167: foreach my $rolename (@allpos) {
13168: if ($rolename ne '') {
13169: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
13170: if (ref($current{'adhoc'}) eq 'HASH') {
13171: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
13172: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
13173: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 13174: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 13175: }
13176: }
1.282 raeburn 13177: }
1.285 raeburn 13178: $idx ++;
1.166 raeburn 13179: }
13180: }
1.118 jms 13181: }
1.123 jms 13182: my $putresult;
13183: if (keys(%changes) > 0) {
1.166 raeburn 13184: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 13185: if ($putresult eq 'ok') {
1.285 raeburn 13186: if (ref($helphash{'helpsettings'}) eq 'HASH') {
13187: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
13188: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
13189: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
13190: }
13191: }
13192: my $cachetime = 24*60*60;
13193: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13194: if (ref($lastactref) eq 'HASH') {
13195: $lastactref->{'domdefaults'} = 1;
13196: }
13197: } else {
13198: $errors .= '<li><span class="LC_error">'.
13199: &mt('An error occurred storing the settings: [_1]',
13200: $putresult).'</span></li>';
13201: }
13202: }
13203: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
13204: $resulttext = &mt('Changes made:').'<ul>';
13205: my (%shownprivs,@levelorder);
13206: @levelorder = ('c','d','s');
13207: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 13208: foreach my $item (sort(keys(%changes))) {
13209: if ($item eq 'submitbugs') {
13210: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
13211: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
13212: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 13213: } elsif ($item eq 'customrole') {
13214: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 13215: my @keyorder = ('order','desc','access','status','exc','inc');
13216: my %keytext = &Apache::lonlocal::texthash(
13217: order => 'Order',
13218: desc => 'Role description',
13219: access => 'Role usage',
1.300 droeschl 13220: status => 'Allowed institutional types',
1.285 raeburn 13221: exc => 'Allowed personnel',
13222: inc => 'Disallowed personnel',
13223: );
1.282 raeburn 13224: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 13225: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
13226: if ($role eq $newrole) {
13227: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
13228: $role).'<ul>';
13229: } else {
13230: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13231: $role).'<ul>';
13232: }
13233: foreach my $key (@keyorder) {
13234: if ($changes{'customrole'}{$role}{$key}) {
13235: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
13236: $keytext{$key},$newsettings{$role}{$key}).
13237: '</li>';
13238: }
13239: }
13240: if (ref($changedprivs{$role}) eq 'HASH') {
13241: $shownprivs{$role} = 1;
13242: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
13243: foreach my $level (@levelorder) {
13244: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13245: next if ($item eq '');
13246: my ($priv) = split(/\&/,$item,2);
13247: if (&Apache::lonnet::plaintext($priv)) {
13248: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13249: unless ($level eq 'c') {
13250: $resulttext .= ' ('.$lt{$level}.')';
13251: }
13252: $resulttext .= '</li>';
13253: }
13254: }
13255: }
13256: $resulttext .= '</ul>';
13257: }
13258: $resulttext .= '</ul></li>';
13259: }
13260: }
13261: }
13262: }
13263: }
13264: }
13265: if (keys(%changedprivs)) {
13266: foreach my $role (sort(keys(%changedprivs))) {
13267: unless ($shownprivs{$role}) {
13268: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
13269: $role).'<ul>'.
13270: '<li>'.&mt('Privileges set to :').'<ul>';
13271: foreach my $level (@levelorder) {
13272: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
13273: next if ($item eq '');
13274: my ($priv) = split(/\&/,$item,2);
13275: if (&Apache::lonnet::plaintext($priv)) {
13276: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
13277: unless ($level eq 'c') {
13278: $resulttext .= ' ('.$lt{$level}.')';
13279: }
13280: $resulttext .= '</li>';
13281: }
1.282 raeburn 13282: }
13283: }
1.285 raeburn 13284: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 13285: }
13286: }
13287: }
1.285 raeburn 13288: $resulttext .= '</ul>';
13289: } else {
13290: $resulttext = &mt('No changes made to help settings');
1.118 jms 13291: }
13292: if ($errors) {
1.168 raeburn 13293: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 13294: $errors.'</ul>';
1.118 jms 13295: }
13296: return $resulttext;
13297: }
13298:
1.121 raeburn 13299: sub modify_coursedefaults {
1.212 raeburn 13300: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 13301: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 13302: my %defaultchecked = (
13303: 'canuse_pdfforms' => 'off',
13304: 'uselcmath' => 'on',
13305: 'usejsme' => 'on'
13306: );
13307: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 13308: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 13309: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
13310: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
13311: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 13312: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 13313: my %staticdefaults = (
13314: anonsurvey_threshold => 10,
13315: uploadquota => 500,
1.257 raeburn 13316: postsubmit => 60,
1.276 raeburn 13317: mysqltables => 172800,
1.198 raeburn 13318: );
1.121 raeburn 13319:
13320: $defaultshash{'coursedefaults'} = {};
13321:
13322: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13323: if ($domconfig{'coursedefaults'} eq '') {
13324: $domconfig{'coursedefaults'} = {};
13325: }
13326: }
13327:
13328: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13329: foreach my $item (@toggles) {
13330: if ($defaultchecked{$item} eq 'on') {
13331: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13332: ($env{'form.'.$item} eq '0')) {
13333: $changes{$item} = 1;
1.192 raeburn 13334: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 13335: $changes{$item} = 1;
13336: }
13337: } elsif ($defaultchecked{$item} eq 'off') {
13338: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13339: ($env{'form.'.$item} eq '1')) {
13340: $changes{$item} = 1;
13341: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13342: $changes{$item} = 1;
13343: }
13344: }
13345: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13346: }
1.198 raeburn 13347: foreach my $item (@numbers) {
13348: my ($currdef,$newdef);
1.208 raeburn 13349: $newdef = $env{'form.'.$item};
1.198 raeburn 13350: if ($item eq 'anonsurvey_threshold') {
13351: $currdef = $domconfig{'coursedefaults'}{$item};
13352: $newdef =~ s/\D//g;
13353: if ($newdef eq '' || $newdef < 1) {
13354: $newdef = 1;
13355: }
13356: $defaultshash{'coursedefaults'}{$item} = $newdef;
13357: } else {
1.276 raeburn 13358: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13359: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13360: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 13361: }
13362: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 13363: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 13364: }
13365: if ($currdef ne $newdef) {
13366: my $staticdef;
13367: if ($item eq 'anonsurvey_threshold') {
13368: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13369: $changes{$item} = 1;
13370: }
1.276 raeburn 13371: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 13372: my $setting = $1;
1.276 raeburn 13373: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13374: $changes{$setting} = 1;
1.198 raeburn 13375: }
13376: }
1.139 raeburn 13377: }
13378: }
1.264 raeburn 13379: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13380: my @currclonecode;
13381: if (ref($currclone) eq 'HASH') {
13382: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13383: @currclonecode = @{$currclone->{'instcode'}};
13384: }
13385: }
13386: my $newclone;
1.289 raeburn 13387: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 13388: $newclone = $env{'form.canclone'};
13389: }
13390: if ($newclone eq 'instcode') {
13391: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13392: my (%codedefaults,@code_order,@clonecode);
13393: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13394: \@code_order);
13395: foreach my $item (@code_order) {
13396: if (grep(/^\Q$item\E$/,@newcodes)) {
13397: push(@clonecode,$item);
13398: }
13399: }
13400: if (@clonecode) {
13401: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13402: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13403: if (@diffs) {
13404: $changes{'canclone'} = 1;
13405: }
13406: } else {
13407: $newclone eq '';
13408: }
13409: } elsif ($newclone ne '') {
1.289 raeburn 13410: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13411: }
1.264 raeburn 13412: if ($newclone ne $currclone) {
13413: $changes{'canclone'} = 1;
13414: }
1.257 raeburn 13415: my %credits;
13416: foreach my $type (@types) {
13417: unless ($type eq 'community') {
13418: $credits{$type} = $env{'form.'.$type.'_credits'};
13419: $credits{$type} =~ s/[^\d.]+//g;
13420: }
13421: }
13422: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13423: ($env{'form.coursecredits'} eq '1')) {
13424: $changes{'coursecredits'} = 1;
13425: foreach my $type (keys(%credits)) {
13426: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13427: }
13428: } else {
1.289 raeburn 13429: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 13430: foreach my $type (@types) {
13431: unless ($type eq 'community') {
1.289 raeburn 13432: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 13433: $changes{'coursecredits'} = 1;
13434: }
13435: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13436: }
13437: }
13438: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13439: foreach my $type (@types) {
13440: unless ($type eq 'community') {
13441: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13442: $changes{'coursecredits'} = 1;
13443: last;
13444: }
13445: }
13446: }
13447: }
13448: }
13449: if ($env{'form.postsubmit'} eq '1') {
13450: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13451: my %currtimeout;
13452: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13453: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13454: $changes{'postsubmit'} = 1;
13455: }
13456: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13457: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13458: }
13459: } else {
13460: $changes{'postsubmit'} = 1;
13461: }
13462: foreach my $type (@types) {
13463: my $timeout = $env{'form.'.$type.'_timeout'};
13464: $timeout =~ s/\D//g;
13465: if ($timeout == $staticdefaults{'postsubmit'}) {
13466: $timeout = '';
13467: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13468: $timeout = '0';
13469: }
13470: unless ($timeout eq '') {
13471: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13472: }
13473: if (exists($currtimeout{$type})) {
13474: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 13475: $changes{'postsubmit'} = 1;
1.257 raeburn 13476: }
13477: } elsif ($timeout ne '') {
13478: $changes{'postsubmit'} = 1;
13479: }
13480: }
13481: } else {
13482: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13483: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13484: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13485: $changes{'postsubmit'} = 1;
13486: }
13487: } else {
13488: $changes{'postsubmit'} = 1;
13489: }
1.192 raeburn 13490: }
1.121 raeburn 13491: }
13492: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13493: $dom);
13494: if ($putresult eq 'ok') {
13495: if (keys(%changes) > 0) {
1.213 raeburn 13496: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 13497: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 13498: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 13499: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 13500: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
13501: if ($changes{$item}) {
13502: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13503: }
1.289 raeburn 13504: }
1.192 raeburn 13505: if ($changes{'coursecredits'}) {
13506: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 13507: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13508: $domdefaults{$type.'credits'} =
13509: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13510: }
13511: }
13512: }
13513: if ($changes{'postsubmit'}) {
13514: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13515: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13516: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13517: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13518: $domdefaults{$type.'postsubtimeout'} =
13519: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13520: }
13521: }
1.192 raeburn 13522: }
13523: }
1.198 raeburn 13524: if ($changes{'uploadquota'}) {
13525: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13526: foreach my $type (@types) {
13527: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13528: }
13529: }
13530: }
1.264 raeburn 13531: if ($changes{'canclone'}) {
13532: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13533: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13534: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13535: if (@clonecodes) {
13536: $domdefaults{'canclone'} = join('+',@clonecodes);
13537: }
13538: }
13539: } else {
13540: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13541: }
13542: }
1.121 raeburn 13543: my $cachetime = 24*60*60;
13544: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13545: if (ref($lastactref) eq 'HASH') {
13546: $lastactref->{'domdefaults'} = 1;
13547: }
1.121 raeburn 13548: }
13549: $resulttext = &mt('Changes made:').'<ul>';
13550: foreach my $item (sort(keys(%changes))) {
13551: if ($item eq 'canuse_pdfforms') {
13552: if ($env{'form.'.$item} eq '1') {
13553: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
13554: } else {
13555: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
13556: }
1.257 raeburn 13557: } elsif ($item eq 'uselcmath') {
13558: if ($env{'form.'.$item} eq '1') {
13559: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13560: } else {
13561: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13562: }
13563: } elsif ($item eq 'usejsme') {
13564: if ($env{'form.'.$item} eq '1') {
13565: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13566: } else {
1.289 raeburn 13567: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 13568: }
1.139 raeburn 13569: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 13570: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 13571: } elsif ($item eq 'uploadquota') {
13572: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13573: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13574: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13575: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 13576: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 13577: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 13578: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13579: '</ul>'.
13580: '</li>';
13581: } else {
13582: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13583: }
1.276 raeburn 13584: } elsif ($item eq 'mysqltables') {
13585: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13586: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13587: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13588: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13589: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13590: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
13591: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13592: '</ul>'.
13593: '</li>';
13594: } else {
13595: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13596: }
1.257 raeburn 13597: } elsif ($item eq 'postsubmit') {
13598: if ($domdefaults{'postsubmit'} eq 'off') {
13599: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13600: } else {
13601: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 13602: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 13603: $resulttext .= &mt('durations:').'<ul>';
13604: foreach my $type (@types) {
13605: $resulttext .= '<li>';
13606: my $timeout;
13607: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13608: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13609: }
13610: my $display;
13611: if ($timeout eq '0') {
13612: $display = &mt('unlimited');
13613: } elsif ($timeout eq '') {
13614: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13615: } else {
13616: $display = &mt('[quant,_1,second]',$timeout);
13617: }
13618: if ($type eq 'community') {
13619: $resulttext .= &mt('Communities');
13620: } elsif ($type eq 'official') {
13621: $resulttext .= &mt('Official courses');
13622: } elsif ($type eq 'unofficial') {
13623: $resulttext .= &mt('Unofficial courses');
13624: } elsif ($type eq 'textbook') {
13625: $resulttext .= &mt('Textbook courses');
1.271 raeburn 13626: } elsif ($type eq 'placement') {
13627: $resulttext .= &mt('Placement tests');
1.257 raeburn 13628: }
13629: $resulttext .= ' -- '.$display.'</li>';
13630: }
13631: $resulttext .= '</ul>';
13632: }
1.289 raeburn 13633: $resulttext .= '</li>';
1.257 raeburn 13634: }
1.192 raeburn 13635: } elsif ($item eq 'coursecredits') {
13636: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13637: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 13638: ($domdefaults{'unofficialcredits'} eq '') &&
13639: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 13640: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13641: } else {
13642: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13643: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13644: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 13645: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 13646: '</ul>'.
13647: '</li>';
13648: }
13649: } else {
13650: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13651: }
1.264 raeburn 13652: } elsif ($item eq 'canclone') {
13653: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13654: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13655: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13656: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13657: }
13658: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13659: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13660: } else {
1.289 raeburn 13661: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 13662: }
1.140 raeburn 13663: }
1.121 raeburn 13664: }
13665: $resulttext .= '</ul>';
13666: } else {
13667: $resulttext = &mt('No changes made to course defaults');
13668: }
13669: } else {
13670: $resulttext = '<span class="LC_error">'.
13671: &mt('An error occurred: [_1]',$putresult).'</span>';
13672: }
13673: return $resulttext;
13674: }
13675:
1.231 raeburn 13676: sub modify_selfenrollment {
13677: my ($dom,$lastactref,%domconfig) = @_;
13678: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 13679: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 13680: my %titles = &tool_titles();
1.232 raeburn 13681: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13682: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 13683: $ordered{'default'} = ['types','registered','approval','limit'];
13684:
13685: my (%roles,%shown,%toplevel);
13686: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13687:
13688: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13689: if ($domconfig{'selfenrollment'} eq '') {
13690: $domconfig{'selfenrollment'} = {};
13691: }
13692: }
13693: %toplevel = (
13694: admin => 'Configuration Rights',
13695: default => 'Default settings',
13696: validation => 'Validation of self-enrollment requests',
13697: );
1.233 raeburn 13698: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 13699:
13700: if (ref($ordered{'admin'}) eq 'ARRAY') {
13701: foreach my $item (@{$ordered{'admin'}}) {
13702: foreach my $type (@types) {
13703: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13704: $selfenrollhash{'admin'}{$type}{$item} = 1;
13705: } else {
13706: $selfenrollhash{'admin'}{$type}{$item} = 0;
13707: }
13708: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13709: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13710: if ($selfenrollhash{'admin'}{$type}{$item} ne
13711: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13712: push(@{$changes{'admin'}{$type}},$item);
13713: }
13714: } else {
13715: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13716: push(@{$changes{'admin'}{$type}},$item);
13717: }
13718: }
13719: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13720: push(@{$changes{'admin'}{$type}},$item);
13721: }
13722: }
13723: }
13724: }
13725:
13726: foreach my $item (@{$ordered{'default'}}) {
13727: foreach my $type (@types) {
13728: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13729: if ($item eq 'types') {
13730: unless (($value eq 'all') || ($value eq 'dom')) {
13731: $value = '';
13732: }
13733: } elsif ($item eq 'registered') {
13734: unless ($value eq '1') {
13735: $value = 0;
13736: }
13737: } elsif ($item eq 'approval') {
13738: unless ($value =~ /^[012]$/) {
13739: $value = 0;
13740: }
13741: } else {
13742: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13743: $value = 'none';
13744: }
13745: }
13746: $selfenrollhash{'default'}{$type}{$item} = $value;
13747: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13748: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13749: if ($selfenrollhash{'default'}{$type}{$item} ne
13750: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13751: push(@{$changes{'default'}{$type}},$item);
13752: }
13753: } else {
13754: push(@{$changes{'default'}{$type}},$item);
13755: }
13756: } else {
13757: push(@{$changes{'default'}{$type}},$item);
13758: }
13759: if ($item eq 'limit') {
13760: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13761: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13762: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13763: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13764: }
13765: } else {
13766: $selfenrollhash{'default'}{$type}{'cap'} = '';
13767: }
13768: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13769: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13770: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13771: push(@{$changes{'default'}{$type}},'cap');
13772: }
13773: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13774: push(@{$changes{'default'}{$type}},'cap');
13775: }
13776: }
13777: }
13778: }
13779:
13780: foreach my $item (@{$itemsref}) {
13781: if ($item eq 'fields') {
13782: my @changed;
13783: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13784: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13785: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13786: }
13787: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13788: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13789: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13790: $domconfig{'selfenrollment'}{'validation'}{$item});
13791: } else {
13792: @changed = @{$selfenrollhash{'validation'}{$item}};
13793: }
13794: } else {
13795: @changed = @{$selfenrollhash{'validation'}{$item}};
13796: }
13797: if (@changed) {
13798: if ($selfenrollhash{'validation'}{$item}) {
13799: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13800: } else {
13801: $changes{'validation'}{$item} = &mt('None');
13802: }
13803: }
13804: } else {
13805: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13806: if ($item eq 'markup') {
13807: if ($env{'form.selfenroll_validation_'.$item}) {
13808: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13809: }
13810: }
13811: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13812: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13813: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13814: }
13815: }
13816: }
13817: }
13818:
13819: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13820: $dom);
13821: if ($putresult eq 'ok') {
13822: if (keys(%changes) > 0) {
13823: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13824: $resulttext = &mt('Changes made:').'<ul>';
13825: foreach my $key ('admin','default','validation') {
13826: if (ref($changes{$key}) eq 'HASH') {
13827: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13828: if ($key eq 'validation') {
13829: foreach my $item (@{$itemsref}) {
13830: if (exists($changes{$key}{$item})) {
13831: if ($item eq 'markup') {
13832: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13833: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13834: } else {
13835: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13836: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13837: }
13838: }
13839: }
13840: } else {
13841: foreach my $type (@types) {
13842: if ($type eq 'community') {
13843: $roles{'1'} = &mt('Community personnel');
13844: } else {
13845: $roles{'1'} = &mt('Course personnel');
13846: }
13847: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 13848: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13849: if ($key eq 'admin') {
13850: my @mgrdc = ();
13851: if (ref($ordered{$key}) eq 'ARRAY') {
13852: foreach my $item (@{$ordered{'admin'}}) {
13853: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13854: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13855: push(@mgrdc,$item);
13856: }
13857: }
13858: }
13859: if (@mgrdc) {
13860: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13861: } else {
13862: delete($domdefaults{$type.'selfenrolladmdc'});
13863: }
13864: }
13865: } else {
13866: if (ref($ordered{$key}) eq 'ARRAY') {
13867: foreach my $item (@{$ordered{$key}}) {
13868: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13869: $domdefaults{$type.'selfenroll'.$item} =
13870: $selfenrollhash{$key}{$type}{$item};
13871: }
13872: }
13873: }
13874: }
13875: }
1.231 raeburn 13876: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13877: foreach my $item (@{$ordered{$key}}) {
13878: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13879: $resulttext .= '<li>';
13880: if ($key eq 'admin') {
13881: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13882: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13883: } else {
13884: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13885: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13886: }
13887: $resulttext .= '</li>';
13888: }
13889: }
13890: $resulttext .= '</ul></li>';
13891: }
13892: }
13893: $resulttext .= '</ul></li>';
13894: }
13895: }
1.232 raeburn 13896: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13897: my $cachetime = 24*60*60;
13898: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13899: if (ref($lastactref) eq 'HASH') {
13900: $lastactref->{'domdefaults'} = 1;
13901: }
13902: }
1.231 raeburn 13903: }
13904: $resulttext .= '</ul>';
13905: } else {
13906: $resulttext = &mt('No changes made to self-enrollment settings');
13907: }
13908: } else {
13909: $resulttext = '<span class="LC_error">'.
13910: &mt('An error occurred: [_1]',$putresult).'</span>';
13911: }
13912: return $resulttext;
13913: }
13914:
1.137 raeburn 13915: sub modify_usersessions {
1.212 raeburn 13916: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13917: my @hostingtypes = ('version','excludedomain','includedomain');
13918: my @offloadtypes = ('primary','default');
13919: my %types = (
13920: remote => \@hostingtypes,
13921: hosted => \@hostingtypes,
13922: spares => \@offloadtypes,
13923: );
13924: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13925: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 13926: my (%by_ip,%by_location,@intdoms,@instdoms);
13927: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 13928: my @locations = sort(keys(%by_location));
1.137 raeburn 13929: my (%defaultshash,%changes);
13930: foreach my $prefix (@prefixes) {
13931: $defaultshash{'usersessions'}{$prefix} = {};
13932: }
1.212 raeburn 13933: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13934: my $resulttext;
1.138 raeburn 13935: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13936: foreach my $prefix (@prefixes) {
1.145 raeburn 13937: next if ($prefix eq 'spares');
13938: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13939: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13940: if ($type eq 'version') {
13941: my $value = $env{'form.'.$prefix.'_'.$type};
13942: my $okvalue;
13943: if ($value ne '') {
13944: if (grep(/^\Q$value\E$/,@lcversions)) {
13945: $okvalue = $value;
13946: }
13947: }
13948: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13949: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13950: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13951: if ($inuse == 0) {
13952: $changes{$prefix}{$type} = 1;
13953: } else {
13954: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13955: $changes{$prefix}{$type} = 1;
13956: }
13957: if ($okvalue ne '') {
13958: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13959: }
13960: }
13961: } else {
13962: if (($inuse == 1) && ($okvalue ne '')) {
13963: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13964: $changes{$prefix}{$type} = 1;
13965: }
13966: }
13967: } else {
13968: if (($inuse == 1) && ($okvalue ne '')) {
13969: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13970: $changes{$prefix}{$type} = 1;
13971: }
13972: }
13973: } else {
13974: if (($inuse == 1) && ($okvalue ne '')) {
13975: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13976: $changes{$prefix}{$type} = 1;
13977: }
13978: }
13979: } else {
13980: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13981: my @okvals;
13982: foreach my $val (@vals) {
1.138 raeburn 13983: if ($val =~ /:/) {
13984: my @items = split(/:/,$val);
13985: foreach my $item (@items) {
13986: if (ref($by_location{$item}) eq 'ARRAY') {
13987: push(@okvals,$item);
13988: }
13989: }
13990: } else {
13991: if (ref($by_location{$val}) eq 'ARRAY') {
13992: push(@okvals,$val);
13993: }
1.137 raeburn 13994: }
13995: }
13996: @okvals = sort(@okvals);
13997: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13998: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13999: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14000: if ($inuse == 0) {
14001: $changes{$prefix}{$type} = 1;
14002: } else {
14003: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14004: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
14005: if (@changed > 0) {
14006: $changes{$prefix}{$type} = 1;
14007: }
14008: }
14009: } else {
14010: if ($inuse == 1) {
14011: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14012: $changes{$prefix}{$type} = 1;
14013: }
14014: }
14015: } else {
14016: if ($inuse == 1) {
14017: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14018: $changes{$prefix}{$type} = 1;
14019: }
14020: }
14021: } else {
14022: if ($inuse == 1) {
14023: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
14024: $changes{$prefix}{$type} = 1;
14025: }
14026: }
14027: }
14028: }
14029: }
1.145 raeburn 14030:
14031: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 14032: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 14033: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
14034: my $savespares;
14035:
14036: foreach my $lonhost (sort(keys(%servers))) {
14037: my $serverhomeID =
14038: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 14039: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 14040: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
14041: my %spareschg;
14042: foreach my $type (@{$types{'spares'}}) {
14043: my @okspares;
14044: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
14045: foreach my $server (@checked) {
1.152 raeburn 14046: if (&Apache::lonnet::hostname($server) ne '') {
14047: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
14048: unless (grep(/^\Q$server\E$/,@okspares)) {
14049: push(@okspares,$server);
14050: }
1.145 raeburn 14051: }
14052: }
14053: }
14054: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
14055: my $newspare;
1.152 raeburn 14056: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
14057: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 14058: $newspare = $new;
14059: }
14060: }
1.152 raeburn 14061: my @spares;
14062: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
14063: @spares = sort(@okspares,$newspare);
14064: } else {
14065: @spares = sort(@okspares);
14066: }
14067: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 14068: if (ref($spareid{$lonhost}) eq 'HASH') {
14069: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 14070: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 14071: if (@diffs > 0) {
14072: $spareschg{$type} = 1;
14073: }
14074: }
14075: }
14076: }
14077: if (keys(%spareschg) > 0) {
14078: $changes{'spares'}{$lonhost} = \%spareschg;
14079: }
14080: }
1.261 raeburn 14081: $defaultshash{'usersessions'}{'offloadnow'} = {};
14082: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
14083: my @okoffload;
14084: if (@offloadnow) {
14085: foreach my $server (@offloadnow) {
14086: if (&Apache::lonnet::hostname($server) ne '') {
14087: unless (grep(/^\Q$server\E$/,@okoffload)) {
14088: push(@okoffload,$server);
14089: }
14090: }
14091: }
14092: if (@okoffload) {
14093: foreach my $lonhost (@okoffload) {
14094: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
14095: }
14096: }
14097: }
1.145 raeburn 14098: if (ref($domconfig{'usersessions'}) eq 'HASH') {
14099: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
14100: if (ref($changes{'spares'}) eq 'HASH') {
14101: if (keys(%{$changes{'spares'}}) > 0) {
14102: $savespares = 1;
14103: }
14104: }
14105: } else {
14106: $savespares = 1;
14107: }
1.261 raeburn 14108: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
14109: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
14110: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
14111: $changes{'offloadnow'} = 1;
14112: last;
14113: }
14114: }
14115: unless ($changes{'offloadnow'}) {
1.289 raeburn 14116: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 14117: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
14118: $changes{'offloadnow'} = 1;
14119: last;
14120: }
14121: }
14122: }
14123: } elsif (@okoffload) {
14124: $changes{'offloadnow'} = 1;
14125: }
14126: } elsif (@okoffload) {
14127: $changes{'offloadnow'} = 1;
1.145 raeburn 14128: }
1.147 raeburn 14129: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
14130: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 14131: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14132: $dom);
14133: if ($putresult eq 'ok') {
14134: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14135: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
14136: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
14137: }
14138: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
14139: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
14140: }
1.261 raeburn 14141: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14142: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
14143: }
1.137 raeburn 14144: }
14145: my $cachetime = 24*60*60;
14146: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 14147: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 14148: if (ref($lastactref) eq 'HASH') {
14149: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 14150: $lastactref->{'usersessions'} = 1;
1.212 raeburn 14151: }
1.147 raeburn 14152: if (keys(%changes) > 0) {
14153: my %lt = &usersession_titles();
14154: $resulttext = &mt('Changes made:').'<ul>';
14155: foreach my $prefix (@prefixes) {
14156: if (ref($changes{$prefix}) eq 'HASH') {
14157: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14158: if ($prefix eq 'spares') {
14159: if (ref($changes{$prefix}) eq 'HASH') {
14160: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
14161: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 14162: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 14163: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
14164: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 14165: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
14166: foreach my $type (@{$types{$prefix}}) {
14167: if ($changes{$prefix}{$lonhost}{$type}) {
14168: my $offloadto = &mt('None');
14169: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
14170: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
14171: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
14172: }
1.145 raeburn 14173: }
1.147 raeburn 14174: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 14175: }
1.137 raeburn 14176: }
14177: }
1.147 raeburn 14178: $resulttext .= '</li>';
1.137 raeburn 14179: }
14180: }
1.147 raeburn 14181: } else {
14182: foreach my $type (@{$types{$prefix}}) {
14183: if (defined($changes{$prefix}{$type})) {
14184: my $newvalue;
14185: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
14186: if (ref($defaultshash{'usersessions'}{$prefix})) {
14187: if ($type eq 'version') {
14188: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
14189: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
14190: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
14191: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
14192: }
1.145 raeburn 14193: }
14194: }
14195: }
1.147 raeburn 14196: if ($newvalue eq '') {
14197: if ($type eq 'version') {
14198: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
14199: } else {
14200: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14201: }
1.145 raeburn 14202: } else {
1.147 raeburn 14203: if ($type eq 'version') {
14204: $newvalue .= ' '.&mt('(or later)');
14205: }
14206: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 14207: }
1.137 raeburn 14208: }
14209: }
14210: }
1.147 raeburn 14211: $resulttext .= '</ul>';
1.137 raeburn 14212: }
14213: }
1.261 raeburn 14214: if ($changes{'offloadnow'}) {
14215: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
14216: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
14217: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
14218: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
14219: $resulttext .= '<li>'.$lonhost.'</li>';
14220: }
14221: $resulttext .= '</ul>';
14222: } else {
14223: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
14224: }
14225: } else {
14226: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
14227: }
14228: }
1.147 raeburn 14229: $resulttext .= '</ul>';
14230: } else {
14231: $resulttext = $nochgmsg;
1.137 raeburn 14232: }
14233: } else {
14234: $resulttext = '<span class="LC_error">'.
14235: &mt('An error occurred: [_1]',$putresult).'</span>';
14236: }
14237: } else {
1.147 raeburn 14238: $resulttext = $nochgmsg;
1.137 raeburn 14239: }
14240: return $resulttext;
14241: }
14242:
1.275 raeburn 14243: sub modify_ssl {
14244: my ($dom,$lastactref,%domconfig) = @_;
14245: my (%by_ip,%by_location,@intdoms,@instdoms);
14246: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14247: my @locations = sort(keys(%by_location));
14248: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14249: my (%defaultshash,%changes);
14250: my $action = 'ssl';
1.293 raeburn 14251: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 14252: foreach my $prefix (@prefixes) {
14253: $defaultshash{$action}{$prefix} = {};
14254: }
14255: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14256: my $resulttext;
14257: my %iphost = &Apache::lonnet::get_iphost();
14258: my @reptypes = ('certreq','nocertreq');
14259: my @connecttypes = ('dom','intdom','other');
14260: my %types = (
1.293 raeburn 14261: connto => \@connecttypes,
14262: connfrom => \@connecttypes,
14263: replication => \@reptypes,
1.275 raeburn 14264: );
14265: foreach my $prefix (sort(keys(%types))) {
14266: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 14267: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14268: my $value = 'yes';
14269: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
14270: $value = $env{'form.'.$prefix.'_'.$type};
14271: }
14272: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14273: if ($domconfig{$action}{$prefix}{$type} ne '') {
14274: if ($value ne $domconfig{$action}{$prefix}{$type}) {
14275: $changes{$prefix}{$type} = 1;
14276: }
14277: $defaultshash{$action}{$prefix}{$type} = $value;
14278: } else {
14279: $defaultshash{$action}{$prefix}{$type} = $value;
14280: $changes{$prefix}{$type} = 1;
14281: }
14282: } else {
14283: $defaultshash{$action}{$prefix}{$type} = $value;
14284: $changes{$prefix}{$type} = 1;
14285: }
14286: if (($type eq 'dom') && (keys(%servers) == 1)) {
14287: delete($changes{$prefix}{$type});
14288: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
14289: delete($changes{$prefix}{$type});
14290: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
14291: delete($changes{$prefix}{$type});
14292: }
14293: } elsif ($prefix eq 'replication') {
14294: if (@locations > 0) {
14295: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14296: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14297: my @okvals;
14298: foreach my $val (@vals) {
14299: if ($val =~ /:/) {
14300: my @items = split(/:/,$val);
14301: foreach my $item (@items) {
14302: if (ref($by_location{$item}) eq 'ARRAY') {
14303: push(@okvals,$item);
14304: }
14305: }
14306: } else {
14307: if (ref($by_location{$val}) eq 'ARRAY') {
14308: push(@okvals,$val);
14309: }
14310: }
14311: }
14312: @okvals = sort(@okvals);
14313: if (ref($domconfig{$action}) eq 'HASH') {
14314: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14315: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
14316: if ($inuse == 0) {
14317: $changes{$prefix}{$type} = 1;
14318: } else {
14319: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14320: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
14321: if (@changed > 0) {
14322: $changes{$prefix}{$type} = 1;
14323: }
14324: }
14325: } else {
14326: if ($inuse == 1) {
14327: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14328: $changes{$prefix}{$type} = 1;
14329: }
14330: }
14331: } else {
14332: if ($inuse == 1) {
14333: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14334: $changes{$prefix}{$type} = 1;
14335: }
14336: }
14337: } else {
14338: if ($inuse == 1) {
14339: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14340: $changes{$prefix}{$type} = 1;
14341: }
14342: }
14343: }
14344: }
14345: }
14346: }
14347: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
14348: if (keys(%changes) > 0) {
14349: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14350: $dom);
14351: if ($putresult eq 'ok') {
14352: if (ref($defaultshash{$action}) eq 'HASH') {
14353: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
14354: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
14355: }
1.293 raeburn 14356: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
14357: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
14358: }
14359: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
14360: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 14361: }
14362: }
14363: my $cachetime = 24*60*60;
14364: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14365: if (ref($lastactref) eq 'HASH') {
14366: $lastactref->{'domdefaults'} = 1;
14367: }
14368: if (keys(%changes) > 0) {
14369: my %titles = &ssl_titles();
14370: $resulttext = &mt('Changes made:').'<ul>';
14371: foreach my $prefix (@prefixes) {
14372: if (ref($changes{$prefix}) eq 'HASH') {
14373: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
14374: foreach my $type (@{$types{$prefix}}) {
14375: if (defined($changes{$prefix}{$type})) {
14376: my $newvalue;
14377: if (ref($defaultshash{$action}) eq 'HASH') {
14378: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 14379: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14380: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
14381: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
14382: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
14383: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
14384: }
14385: }
14386: }
14387: if ($newvalue eq '') {
14388: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
14389: } else {
14390: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
14391: }
14392: }
14393: }
14394: }
14395: $resulttext .= '</ul>';
14396: }
14397: }
14398: } else {
14399: $resulttext = $nochgmsg;
14400: }
14401: } else {
14402: $resulttext = '<span class="LC_error">'.
14403: &mt('An error occurred: [_1]',$putresult).'</span>';
14404: }
14405: } else {
14406: $resulttext = $nochgmsg;
14407: }
14408: return $resulttext;
14409: }
14410:
1.279 raeburn 14411: sub modify_trust {
14412: my ($dom,$lastactref,%domconfig) = @_;
14413: my (%by_ip,%by_location,@intdoms,@instdoms);
14414: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14415: my @locations = sort(keys(%by_location));
14416: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
14417: my @types = ('exc','inc');
14418: my (%defaultshash,%changes);
14419: foreach my $prefix (@prefixes) {
14420: $defaultshash{'trust'}{$prefix} = {};
14421: }
14422: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14423: my $resulttext;
14424: foreach my $prefix (@prefixes) {
14425: foreach my $type (@types) {
14426: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14427: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14428: my @okvals;
14429: foreach my $val (@vals) {
14430: if ($val =~ /:/) {
14431: my @items = split(/:/,$val);
14432: foreach my $item (@items) {
14433: if (ref($by_location{$item}) eq 'ARRAY') {
14434: push(@okvals,$item);
14435: }
14436: }
14437: } else {
14438: if (ref($by_location{$val}) eq 'ARRAY') {
14439: push(@okvals,$val);
14440: }
14441: }
14442: }
14443: @okvals = sort(@okvals);
14444: if (ref($domconfig{'trust'}) eq 'HASH') {
14445: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
14446: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14447: if ($inuse == 0) {
14448: $changes{$prefix}{$type} = 1;
14449: } else {
14450: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14451: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
14452: if (@changed > 0) {
14453: $changes{$prefix}{$type} = 1;
14454: }
14455: }
14456: } else {
14457: if ($inuse == 1) {
14458: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14459: $changes{$prefix}{$type} = 1;
14460: }
14461: }
14462: } else {
14463: if ($inuse == 1) {
14464: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14465: $changes{$prefix}{$type} = 1;
14466: }
14467: }
14468: } else {
14469: if ($inuse == 1) {
14470: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14471: $changes{$prefix}{$type} = 1;
14472: }
14473: }
14474: }
14475: }
14476: my $nochgmsg = &mt('No changes made to trust settings.');
14477: if (keys(%changes) > 0) {
14478: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14479: $dom);
14480: if ($putresult eq 'ok') {
14481: if (ref($defaultshash{'trust'}) eq 'HASH') {
14482: foreach my $prefix (@prefixes) {
14483: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
14484: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
14485: }
14486: }
14487: }
14488: my $cachetime = 24*60*60;
14489: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14490: if (ref($lastactref) eq 'HASH') {
14491: $lastactref->{'domdefaults'} = 1;
14492: }
14493: if (keys(%changes) > 0) {
14494: my %lt = &trust_titles();
14495: $resulttext = &mt('Changes made:').'<ul>';
14496: foreach my $prefix (@prefixes) {
14497: if (ref($changes{$prefix}) eq 'HASH') {
14498: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14499: foreach my $type (@types) {
14500: if (defined($changes{$prefix}{$type})) {
14501: my $newvalue;
14502: if (ref($defaultshash{'trust'}) eq 'HASH') {
14503: if (ref($defaultshash{'trust'}{$prefix})) {
14504: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14505: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
14506: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
14507: }
14508: }
14509: }
14510: }
14511: if ($newvalue eq '') {
14512: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14513: } else {
14514: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
14515: }
14516: }
14517: }
14518: $resulttext .= '</ul>';
14519: }
14520: }
14521: $resulttext .= '</ul>';
14522: } else {
14523: $resulttext = $nochgmsg;
14524: }
14525: } else {
14526: $resulttext = '<span class="LC_error">'.
14527: &mt('An error occurred: [_1]',$putresult).'</span>';
14528: }
14529: } else {
14530: $resulttext = $nochgmsg;
14531: }
14532: return $resulttext;
14533: }
14534:
1.150 raeburn 14535: sub modify_loadbalancing {
14536: my ($dom,%domconfig) = @_;
14537: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14538: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14539: my ($othertitle,$usertypes,$types) =
14540: &Apache::loncommon::sorted_inst_types($dom);
14541: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 14542: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 14543: my @sparestypes = ('primary','default');
14544: my %typetitles = &sparestype_titles();
14545: my $resulttext;
1.171 raeburn 14546: my (%currbalancer,%currtargets,%currrules,%existing);
14547: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14548: %existing = %{$domconfig{'loadbalancing'}};
14549: }
14550: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
14551: \%currtargets,\%currrules);
14552: my ($saveloadbalancing,%defaultshash,%changes);
14553: my ($alltypes,$othertypes,$titles) =
14554: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14555: my %ruletitles = &offloadtype_text();
14556: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14557: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14558: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14559: if ($balancer eq '') {
14560: next;
14561: }
1.210 raeburn 14562: if (!exists($servers{$balancer})) {
1.171 raeburn 14563: if (exists($currbalancer{$balancer})) {
14564: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14565: }
1.171 raeburn 14566: next;
14567: }
14568: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14569: push(@{$changes{'delete'}},$balancer);
14570: next;
14571: }
14572: if (!exists($currbalancer{$balancer})) {
14573: push(@{$changes{'add'}},$balancer);
14574: }
14575: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14576: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14577: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14578: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14579: $saveloadbalancing = 1;
14580: }
14581: foreach my $sparetype (@sparestypes) {
14582: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14583: my @offloadto;
14584: foreach my $target (@targets) {
14585: if (($servers{$target}) && ($target ne $balancer)) {
14586: if ($sparetype eq 'default') {
14587: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14588: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14589: }
14590: }
1.171 raeburn 14591: unless(grep(/^\Q$target\E$/,@offloadto)) {
14592: push(@offloadto,$target);
14593: }
1.150 raeburn 14594: }
14595: }
1.284 raeburn 14596: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14597: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14598: push(@offloadto,$balancer);
14599: }
14600: }
14601: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14602: }
1.171 raeburn 14603: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14604: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14605: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14606: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14607: if (@targetdiffs > 0) {
1.171 raeburn 14608: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14609: }
1.171 raeburn 14610: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14611: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14612: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14613: }
14614: }
14615: }
14616: } else {
1.171 raeburn 14617: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 14618: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14619: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14620: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14621: $changes{'curr'}{$balancer}{'targets'} = 1;
14622: }
1.150 raeburn 14623: }
14624: }
1.210 raeburn 14625: }
1.150 raeburn 14626: }
14627: my $ishomedom;
1.171 raeburn 14628: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14629: $ishomedom = 1;
1.150 raeburn 14630: }
14631: if (ref($alltypes) eq 'ARRAY') {
14632: foreach my $type (@{$alltypes}) {
14633: my $rule;
1.210 raeburn 14634: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14635: (!$ishomedom)) {
1.171 raeburn 14636: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14637: }
14638: if ($rule eq 'specific') {
1.255 raeburn 14639: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 14640: if (exists($servers{$specifiedhost})) {
1.255 raeburn 14641: $rule = $specifiedhost;
14642: }
1.150 raeburn 14643: }
1.171 raeburn 14644: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14645: if (ref($currrules{$balancer}) eq 'HASH') {
14646: if ($rule ne $currrules{$balancer}{$type}) {
14647: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14648: }
14649: } elsif ($rule ne '') {
1.171 raeburn 14650: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14651: }
14652: }
14653: }
1.171 raeburn 14654: }
14655: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14656: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14657: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14658: $defaultshash{'loadbalancing'} = {};
14659: }
14660: my $putresult = &Apache::lonnet::put_dom('configuration',
14661: \%defaultshash,$dom);
14662: if ($putresult eq 'ok') {
14663: if (keys(%changes) > 0) {
1.252 raeburn 14664: my %toupdate;
1.171 raeburn 14665: if (ref($changes{'delete'}) eq 'ARRAY') {
14666: foreach my $balancer (sort(@{$changes{'delete'}})) {
14667: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 14668: $toupdate{$balancer} = 1;
1.150 raeburn 14669: }
1.171 raeburn 14670: }
14671: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 14672: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 14673: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 14674: $toupdate{$balancer} = 1;
1.171 raeburn 14675: }
14676: }
14677: if (ref($changes{'curr'}) eq 'HASH') {
14678: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 14679: $toupdate{$balancer} = 1;
1.171 raeburn 14680: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14681: if ($changes{'curr'}{$balancer}{'targets'}) {
14682: my %offloadstr;
14683: foreach my $sparetype (@sparestypes) {
14684: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14685: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14686: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14687: }
14688: }
1.150 raeburn 14689: }
1.171 raeburn 14690: if (keys(%offloadstr) == 0) {
14691: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14692: } else {
1.171 raeburn 14693: my $showoffload;
14694: foreach my $sparetype (@sparestypes) {
14695: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14696: if (defined($offloadstr{$sparetype})) {
14697: $showoffload .= $offloadstr{$sparetype};
14698: } else {
14699: $showoffload .= &mt('None');
14700: }
14701: $showoffload .= (' 'x3);
14702: }
14703: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14704: }
14705: }
14706: }
1.171 raeburn 14707: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14708: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14709: foreach my $type (@{$alltypes}) {
14710: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14711: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14712: my $balancetext;
14713: if ($rule eq '') {
14714: $balancetext = $ruletitles{'default'};
1.209 raeburn 14715: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 14716: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 14717: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 14718: foreach my $sparetype (@sparestypes) {
14719: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14720: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14721: }
14722: }
1.253 raeburn 14723: foreach my $item (@{$alltypes}) {
14724: next if ($item =~ /^_LC_ipchange/);
14725: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14726: if ($hasrule eq 'homeserver') {
14727: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14728: } else {
14729: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14730: if ($servers{$hasrule}) {
14731: $toupdate{$hasrule} = 1;
14732: }
14733: }
14734: }
14735: }
1.254 raeburn 14736: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14737: $balancetext = $ruletitles{$rule};
14738: } else {
14739: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14740: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14741: if ($receiver) {
14742: $toupdate{$receiver};
14743: }
14744: }
14745: } else {
14746: $balancetext = $ruletitles{$rule};
1.252 raeburn 14747: }
1.171 raeburn 14748: } else {
14749: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14750: }
1.210 raeburn 14751: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14752: }
14753: }
14754: }
14755: }
1.252 raeburn 14756: if (keys(%toupdate)) {
14757: my %thismachine;
14758: my $updatedhere;
14759: my $cachetime = 60*60*24;
14760: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14761: foreach my $lonhost (keys(%toupdate)) {
14762: if ($thismachine{$lonhost}) {
14763: unless ($updatedhere) {
14764: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14765: $defaultshash{'loadbalancing'},
14766: $cachetime);
14767: $updatedhere = 1;
14768: }
14769: } else {
14770: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14771: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14772: }
14773: }
14774: }
1.150 raeburn 14775: }
1.171 raeburn 14776: }
14777: if ($resulttext ne '') {
14778: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14779: } else {
14780: $resulttext = $nochgmsg;
14781: }
14782: } else {
1.171 raeburn 14783: $resulttext = $nochgmsg;
1.150 raeburn 14784: }
14785: } else {
1.171 raeburn 14786: $resulttext = '<span class="LC_error">'.
14787: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14788: }
14789: } else {
1.171 raeburn 14790: $resulttext = $nochgmsg;
1.150 raeburn 14791: }
14792: return $resulttext;
14793: }
14794:
1.48 raeburn 14795: sub recurse_check {
14796: my ($chkcats,$categories,$depth,$name) = @_;
14797: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14798: my $chg = 0;
14799: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14800: my $category = $chkcats->[$depth]{$name}[$j];
14801: my $item;
14802: if ($category eq '') {
14803: $chg ++;
14804: } else {
14805: my $deeper = $depth + 1;
14806: $item = &escape($category).':'.&escape($name).':'.$depth;
14807: if ($chg) {
14808: $categories->{$item} -= $chg;
14809: }
14810: &recurse_check($chkcats,$categories,$deeper,$category);
14811: $deeper --;
14812: }
14813: }
14814: }
14815: return;
14816: }
14817:
14818: sub recurse_cat_deletes {
14819: my ($item,$coursecategories,$deletions) = @_;
14820: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14821: my $subdepth = $depth + 1;
14822: if (ref($coursecategories) eq 'HASH') {
14823: foreach my $subitem (keys(%{$coursecategories})) {
14824: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14825: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14826: delete($coursecategories->{$subitem});
14827: $deletions->{$subitem} = 1;
14828: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 14829: }
1.48 raeburn 14830: }
14831: }
14832: return;
14833: }
14834:
1.125 raeburn 14835: sub active_dc_picker {
1.191 raeburn 14836: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 14837: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 14838: my @domcoord = keys(%domcoords);
14839: if (keys(%currhash)) {
14840: foreach my $dc (keys(%currhash)) {
14841: unless (exists($domcoords{$dc})) {
14842: push(@domcoord,$dc);
14843: }
14844: }
14845: }
14846: @domcoord = sort(@domcoord);
1.210 raeburn 14847: my $numdcs = scalar(@domcoord);
1.191 raeburn 14848: my $rows = 0;
14849: my $table;
1.125 raeburn 14850: if ($numdcs > 1) {
1.191 raeburn 14851: $table = '<table>';
14852: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14853: my $rem = $i%($numinrow);
14854: if ($rem == 0) {
14855: if ($i > 0) {
1.191 raeburn 14856: $table .= '</tr>';
1.125 raeburn 14857: }
1.191 raeburn 14858: $table .= '<tr>';
14859: $rows ++;
1.125 raeburn 14860: }
1.191 raeburn 14861: my $check = '';
14862: if ($inputtype eq 'radio') {
14863: if (keys(%currhash) == 0) {
14864: if (!$i) {
14865: $check = ' checked="checked"';
14866: }
14867: } elsif (exists($currhash{$domcoord[$i]})) {
14868: $check = ' checked="checked"';
14869: }
14870: } else {
14871: if (exists($currhash{$domcoord[$i]})) {
14872: $check = ' checked="checked"';
1.125 raeburn 14873: }
14874: }
1.191 raeburn 14875: if ($i == @domcoord - 1) {
1.125 raeburn 14876: my $colsleft = $numinrow - $rem;
14877: if ($colsleft > 1) {
1.191 raeburn 14878: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14879: } else {
1.191 raeburn 14880: $table .= '<td class="LC_left_item">';
1.125 raeburn 14881: }
14882: } else {
1.191 raeburn 14883: $table .= '<td class="LC_left_item">';
14884: }
14885: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14886: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14887: $table .= '<span class="LC_nobreak"><label>'.
14888: '<input type="'.$inputtype.'" name="'.$name.'"'.
14889: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14890: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 14891: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 14892: }
1.219 raeburn 14893: $table .= '</label></span></td>';
1.191 raeburn 14894: }
14895: $table .= '</tr></table>';
14896: } elsif ($numdcs == 1) {
1.219 raeburn 14897: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14898: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 14899: if ($inputtype eq 'radio') {
1.247 raeburn 14900: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 14901: if ($user ne $dcname.':'.$dcdom) {
14902: $table .= ' ('.$dcname.':'.$dcdom.')';
14903: }
1.191 raeburn 14904: } else {
14905: my $check;
14906: if (exists($currhash{$domcoord[0]})) {
14907: $check = ' checked="checked"';
1.125 raeburn 14908: }
1.247 raeburn 14909: $table = '<span class="LC_nobreak"><label>'.
14910: '<input type="checkbox" name="'.$name.'" '.
14911: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 14912: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 14913: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 14914: }
1.220 raeburn 14915: $table .= '</label></span>';
1.191 raeburn 14916: $rows ++;
1.125 raeburn 14917: }
14918: }
1.191 raeburn 14919: return ($numdcs,$table,$rows);
1.125 raeburn 14920: }
14921:
1.137 raeburn 14922: sub usersession_titles {
14923: return &Apache::lonlocal::texthash(
14924: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14925: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14926: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14927: version => 'LON-CAPA version requirement',
1.138 raeburn 14928: excludedomain => 'Allow all, but exclude specific domains',
14929: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14930: primary => 'Primary (checked first)',
1.154 raeburn 14931: default => 'Default',
1.137 raeburn 14932: );
14933: }
14934:
1.152 raeburn 14935: sub id_for_thisdom {
14936: my (%servers) = @_;
14937: my %altids;
14938: foreach my $server (keys(%servers)) {
14939: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14940: if ($serverhome ne $server) {
14941: $altids{$serverhome} = $server;
14942: }
14943: }
14944: return %altids;
14945: }
14946:
1.150 raeburn 14947: sub count_servers {
14948: my ($currbalancer,%servers) = @_;
14949: my (@spares,$numspares);
14950: foreach my $lonhost (sort(keys(%servers))) {
14951: next if ($currbalancer eq $lonhost);
14952: push(@spares,$lonhost);
14953: }
14954: if ($currbalancer) {
14955: $numspares = scalar(@spares);
14956: } else {
14957: $numspares = scalar(@spares) - 1;
14958: }
14959: return ($numspares,@spares);
14960: }
14961:
14962: sub lonbalance_targets_js {
1.171 raeburn 14963: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14964: my $select = &mt('Select');
14965: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14966: if (ref($servers) eq 'HASH') {
14967: $alltargets = join("','",sort(keys(%{$servers})));
14968: my @homedoms;
14969: foreach my $server (sort(keys(%{$servers}))) {
14970: if (&Apache::lonnet::host_domain($server) eq $dom) {
14971: push(@homedoms,'1');
14972: } else {
14973: push(@homedoms,'0');
14974: }
14975: }
14976: $allishome = join("','",@homedoms);
14977: }
14978: if (ref($types) eq 'ARRAY') {
14979: if (@{$types} > 0) {
14980: @alltypes = @{$types};
14981: }
14982: }
14983: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14984: $allinsttypes = join("','",@alltypes);
1.171 raeburn 14985: my (%currbalancer,%currtargets,%currrules,%existing);
14986: if (ref($settings) eq 'HASH') {
14987: %existing = %{$settings};
14988: }
14989: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14990: \%currtargets,\%currrules);
1.210 raeburn 14991: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14992: return <<"END";
14993:
14994: <script type="text/javascript">
14995: // <![CDATA[
14996:
1.171 raeburn 14997: currBalancers = new Array('$balancers');
14998:
14999: function toggleTargets(balnum) {
15000: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15001: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
15002: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
15003: var prevbalancer = prevhostitem.value;
15004: var baltotal = document.getElementById('loadbalancing_total').value;
15005: prevhostitem.value = balancer;
15006: if (prevbalancer != '') {
15007: var prevIdx = currBalancers.indexOf(prevbalancer);
15008: if (prevIdx != -1) {
15009: currBalancers.splice(prevIdx,1);
15010: }
15011: }
1.150 raeburn 15012: if (balancer == '') {
1.171 raeburn 15013: hideSpares(balnum);
1.150 raeburn 15014: } else {
1.171 raeburn 15015: var currIdx = currBalancers.indexOf(balancer);
15016: if (currIdx == -1) {
15017: currBalancers.push(balancer);
15018: }
1.150 raeburn 15019: var homedoms = new Array('$allishome');
1.171 raeburn 15020: var ishomedom = homedoms[lonhostitem.selectedIndex];
15021: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 15022: }
1.171 raeburn 15023: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 15024: return;
15025: }
15026:
1.171 raeburn 15027: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 15028: var alltargets = new Array('$alltargets');
15029: var insttypes = new Array('$allinsttypes');
1.151 raeburn 15030: var offloadtypes = new Array('primary','default');
15031:
1.171 raeburn 15032: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
15033: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 15034:
1.151 raeburn 15035: for (var i=0; i<offloadtypes.length; i++) {
15036: var count = 0;
15037: for (var j=0; j<alltargets.length; j++) {
15038: if (alltargets[j] != balancer) {
1.171 raeburn 15039: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
15040: item.value = alltargets[j];
15041: item.style.textAlign='left';
15042: item.style.textFace='normal';
15043: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
15044: if (currBalancers.indexOf(alltargets[j]) == -1) {
15045: item.disabled = '';
15046: } else {
15047: item.disabled = 'disabled';
15048: item.checked = false;
15049: }
1.151 raeburn 15050: count ++;
15051: }
1.150 raeburn 15052: }
15053: }
1.151 raeburn 15054: for (var k=0; k<insttypes.length; k++) {
15055: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 15056: if (ishomedom == 1) {
1.171 raeburn 15057: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15058: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15059: } else {
1.171 raeburn 15060: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15061: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 15062: }
15063: } else {
1.171 raeburn 15064: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
15065: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 15066: }
1.151 raeburn 15067: if ((insttypes[k] != '_LC_external') &&
15068: ((insttypes[k] != '_LC_internetdom') ||
15069: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 15070: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
15071: item.options.length = 0;
15072: item.options[0] = new Option("","",true,true);
1.210 raeburn 15073: var idx = 0;
1.151 raeburn 15074: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 15075: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
15076: idx ++;
15077: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 15078: }
15079: }
15080: }
15081: }
15082: return;
15083: }
15084:
1.171 raeburn 15085: function hideSpares(balnum) {
1.150 raeburn 15086: var alltargets = new Array('$alltargets');
15087: var insttypes = new Array('$allinsttypes');
15088: var offloadtypes = new Array('primary','default');
15089:
1.171 raeburn 15090: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
15091: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 15092:
15093: var total = alltargets.length - 1;
15094: for (var i=0; i<offloadtypes; i++) {
15095: for (var j=0; j<total; j++) {
1.171 raeburn 15096: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
15097: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
15098: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 15099: }
1.150 raeburn 15100: }
15101: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 15102: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
15103: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 15104: if (insttypes[k] != '_LC_external') {
1.171 raeburn 15105: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
15106: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 15107: }
15108: }
15109: return;
15110: }
15111:
1.171 raeburn 15112: function checkOffloads(item,balnum,type) {
1.150 raeburn 15113: var alltargets = new Array('$alltargets');
15114: var offloadtypes = new Array('primary','default');
15115: if (item.checked) {
15116: var total = alltargets.length - 1;
15117: var other;
15118: if (type == offloadtypes[0]) {
1.151 raeburn 15119: other = offloadtypes[1];
1.150 raeburn 15120: } else {
1.151 raeburn 15121: other = offloadtypes[0];
1.150 raeburn 15122: }
15123: for (var i=0; i<total; i++) {
1.171 raeburn 15124: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 15125: if (server == item.value) {
1.171 raeburn 15126: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
15127: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 15128: }
15129: }
15130: }
15131: }
15132: return;
15133: }
15134:
1.171 raeburn 15135: function singleServerToggle(balnum,type) {
15136: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 15137: if (offloadtoSelIdx == 0) {
1.171 raeburn 15138: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
15139: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15140:
15141: } else {
1.171 raeburn 15142: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
15143: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 15144: }
15145: return;
15146: }
15147:
1.171 raeburn 15148: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 15149: if (type == '_LC_external') {
1.171 raeburn 15150: return;
1.150 raeburn 15151: }
1.171 raeburn 15152: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 15153: for (var i=0; i<typesRules.length; i++) {
15154: if (formname.elements[typesRules[i]].checked) {
15155: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 15156: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
15157: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 15158: } else {
1.171 raeburn 15159: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
15160: }
15161: }
15162: }
15163: return;
15164: }
15165:
15166: function balancerDeleteChange(balnum) {
15167: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
15168: var baltotal = document.getElementById('loadbalancing_total').value;
15169: var addtarget;
15170: var removetarget;
15171: var action = 'delete';
15172: if (document.getElementById('loadbalancing_delete_'+balnum)) {
15173: var lonhost = hostitem.value;
15174: var currIdx = currBalancers.indexOf(lonhost);
15175: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
15176: if (currIdx != -1) {
15177: currBalancers.splice(currIdx,1);
15178: }
15179: addtarget = lonhost;
15180: } else {
15181: if (currIdx == -1) {
15182: currBalancers.push(lonhost);
15183: }
15184: removetarget = lonhost;
15185: action = 'undelete';
15186: }
15187: balancerChange(balnum,baltotal,action,addtarget,removetarget);
15188: }
15189: return;
15190: }
15191:
15192: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
15193: if (baltotal > 1) {
15194: var offloadtypes = new Array('primary','default');
15195: var alltargets = new Array('$alltargets');
15196: var insttypes = new Array('$allinsttypes');
15197: for (var i=0; i<baltotal; i++) {
15198: if (i != balnum) {
15199: for (var j=0; j<offloadtypes.length; j++) {
15200: var total = alltargets.length - 1;
15201: for (var k=0; k<total; k++) {
15202: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
15203: var server = serveritem.value;
15204: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15205: if (server == addtarget) {
15206: serveritem.disabled = '';
15207: }
15208: }
15209: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15210: if (server == removetarget) {
15211: serveritem.disabled = 'disabled';
15212: serveritem.checked = false;
15213: }
15214: }
15215: }
15216: }
15217: for (var j=0; j<insttypes.length; j++) {
15218: if (insttypes[j] != '_LC_external') {
15219: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
15220: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
15221: var currSel = singleserver.selectedIndex;
15222: var currVal = singleserver.options[currSel].value;
15223: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
15224: var numoptions = singleserver.options.length;
15225: var needsnew = 1;
15226: for (var k=0; k<numoptions; k++) {
15227: if (singleserver.options[k] == addtarget) {
15228: needsnew = 0;
15229: break;
15230: }
15231: }
15232: if (needsnew == 1) {
15233: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
15234: }
15235: }
15236: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
15237: singleserver.options.length = 0;
15238: if ((currVal) && (currVal != removetarget)) {
15239: singleserver.options[0] = new Option("","",false,false);
15240: } else {
15241: singleserver.options[0] = new Option("","",true,true);
15242: }
15243: var idx = 0;
15244: for (var m=0; m<alltargets.length; m++) {
15245: if (currBalancers.indexOf(alltargets[m]) == -1) {
15246: idx ++;
15247: if (currVal == alltargets[m]) {
15248: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
15249: } else {
15250: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
15251: }
15252: }
15253: }
15254: }
15255: }
15256: }
15257: }
1.150 raeburn 15258: }
15259: }
15260: }
15261: return;
15262: }
15263:
1.152 raeburn 15264: // ]]>
15265: </script>
15266:
15267: END
15268: }
15269:
15270: sub new_spares_js {
15271: my @sparestypes = ('primary','default');
15272: my $types = join("','",@sparestypes);
15273: my $select = &mt('Select');
15274: return <<"END";
15275:
15276: <script type="text/javascript">
15277: // <![CDATA[
15278:
15279: function updateNewSpares(formname,lonhost) {
15280: var types = new Array('$types');
15281: var include = new Array();
15282: var exclude = new Array();
15283: for (var i=0; i<types.length; i++) {
15284: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
15285: for (var j=0; j<spareboxes.length; j++) {
15286: if (formname.elements[spareboxes[j]].checked) {
15287: exclude.push(formname.elements[spareboxes[j]].value);
15288: } else {
15289: include.push(formname.elements[spareboxes[j]].value);
15290: }
15291: }
15292: }
15293: for (var i=0; i<types.length; i++) {
15294: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
15295: var selIdx = newSpare.selectedIndex;
15296: var currnew = newSpare.options[selIdx].value;
15297: var okSpares = new Array();
15298: for (var j=0; j<newSpare.options.length; j++) {
15299: var possible = newSpare.options[j].value;
15300: if (possible != '') {
15301: if (exclude.indexOf(possible) == -1) {
15302: okSpares.push(possible);
15303: } else {
15304: if (currnew == possible) {
15305: selIdx = 0;
15306: }
15307: }
15308: }
15309: }
15310: for (var k=0; k<include.length; k++) {
15311: if (okSpares.indexOf(include[k]) == -1) {
15312: okSpares.push(include[k]);
15313: }
15314: }
15315: okSpares.sort();
15316: newSpare.options.length = 0;
15317: if (selIdx == 0) {
15318: newSpare.options[0] = new Option("$select","",true,true);
15319: } else {
15320: newSpare.options[0] = new Option("$select","",false,false);
15321: }
15322: for (var m=0; m<okSpares.length; m++) {
15323: var idx = m+1;
15324: var selThis = 0;
15325: if (selIdx != 0) {
15326: if (okSpares[m] == currnew) {
15327: selThis = 1;
15328: }
15329: }
15330: if (selThis == 1) {
15331: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
15332: } else {
15333: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15334: }
15335: }
15336: }
15337: return;
15338: }
15339:
15340: function checkNewSpares(lonhost,type) {
15341: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15342: var chosen = newSpare.options[newSpare.selectedIndex].value;
15343: if (chosen != '') {
15344: var othertype;
15345: var othernewSpare;
15346: if (type == 'primary') {
15347: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15348: }
15349: if (type == 'default') {
15350: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15351: }
15352: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15353: othernewSpare.selectedIndex = 0;
15354: }
15355: }
15356: return;
15357: }
15358:
15359: // ]]>
15360: </script>
15361:
15362: END
15363:
15364: }
15365:
15366: sub common_domprefs_js {
15367: return <<"END";
15368:
15369: <script type="text/javascript">
15370: // <![CDATA[
15371:
1.150 raeburn 15372: function getIndicesByName(formname,item) {
1.152 raeburn 15373: var group = new Array();
1.150 raeburn 15374: for (var i=0;i<formname.elements.length;i++) {
15375: if (formname.elements[i].name == item) {
1.152 raeburn 15376: group.push(formname.elements[i].id);
1.150 raeburn 15377: }
15378: }
1.152 raeburn 15379: return group;
1.150 raeburn 15380: }
15381:
15382: // ]]>
15383: </script>
15384:
15385: END
1.152 raeburn 15386:
1.150 raeburn 15387: }
15388:
1.165 raeburn 15389: sub recaptcha_js {
15390: my %lt = &captcha_phrases();
15391: return <<"END";
15392:
15393: <script type="text/javascript">
15394: // <![CDATA[
15395:
15396: function updateCaptcha(caller,context) {
15397: var privitem;
15398: var pubitem;
15399: var privtext;
15400: var pubtext;
1.269 raeburn 15401: var versionitem;
15402: var versiontext;
1.165 raeburn 15403: if (document.getElementById(context+'_recaptchapub')) {
15404: pubitem = document.getElementById(context+'_recaptchapub');
15405: } else {
15406: return;
15407: }
15408: if (document.getElementById(context+'_recaptchapriv')) {
15409: privitem = document.getElementById(context+'_recaptchapriv');
15410: } else {
15411: return;
15412: }
15413: if (document.getElementById(context+'_recaptchapubtxt')) {
15414: pubtext = document.getElementById(context+'_recaptchapubtxt');
15415: } else {
15416: return;
15417: }
15418: if (document.getElementById(context+'_recaptchaprivtxt')) {
15419: privtext = document.getElementById(context+'_recaptchaprivtxt');
15420: } else {
15421: return;
15422: }
1.269 raeburn 15423: if (document.getElementById(context+'_recaptchaversion')) {
15424: versionitem = document.getElementById(context+'_recaptchaversion');
15425: } else {
15426: return;
15427: }
15428: if (document.getElementById(context+'_recaptchavertxt')) {
15429: versiontext = document.getElementById(context+'_recaptchavertxt');
15430: } else {
15431: return;
15432: }
1.165 raeburn 15433: if (caller.checked) {
15434: if (caller.value == 'recaptcha') {
15435: pubitem.type = 'text';
15436: privitem.type = 'text';
15437: pubitem.size = '40';
15438: privitem.size = '40';
15439: pubtext.innerHTML = "$lt{'pub'}";
15440: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 15441: versionitem.type = 'text';
15442: versionitem.size = '3';
1.289 raeburn 15443: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 15444: } else {
15445: pubitem.type = 'hidden';
15446: privitem.type = 'hidden';
1.269 raeburn 15447: versionitem.type = 'hidden';
1.165 raeburn 15448: pubtext.innerHTML = '';
15449: privtext.innerHTML = '';
1.269 raeburn 15450: versiontext.innerHTML = '';
1.165 raeburn 15451: }
15452: }
15453: return;
15454: }
15455:
15456: // ]]>
15457: </script>
15458:
15459: END
15460:
15461: }
15462:
1.236 raeburn 15463: sub toggle_display_js {
1.192 raeburn 15464: return <<"END";
15465:
15466: <script type="text/javascript">
15467: // <![CDATA[
15468:
1.236 raeburn 15469: function toggleDisplay(domForm,caller) {
15470: if (document.getElementById(caller)) {
15471: var divitem = document.getElementById(caller);
15472: var optionsElement = domForm.coursecredits;
1.264 raeburn 15473: var checkval = 1;
15474: var dispval = 'block';
1.303 ! raeburn 15475: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 15476: if (caller == 'emailoptions') {
15477: optionsElement = domForm.cancreate_email;
15478: }
1.257 raeburn 15479: if (caller == 'studentsubmission') {
15480: optionsElement = domForm.postsubmit;
15481: }
1.264 raeburn 15482: if (caller == 'cloneinstcode') {
15483: optionsElement = domForm.canclone;
15484: checkval = 'instcode';
15485: }
1.303 ! raeburn 15486: if (selfcreateRegExp.test(caller)) {
! 15487: optionsElement = domForm.elements[caller];
! 15488: checkval = 'other';
! 15489: dispval = 'inline'
! 15490: }
1.236 raeburn 15491: if (optionsElement.length) {
1.192 raeburn 15492: var currval;
1.236 raeburn 15493: for (var i=0; i<optionsElement.length; i++) {
15494: if (optionsElement[i].checked) {
15495: currval = optionsElement[i].value;
1.192 raeburn 15496: }
15497: }
1.264 raeburn 15498: if (currval == checkval) {
15499: divitem.style.display = dispval;
1.192 raeburn 15500: } else {
1.236 raeburn 15501: divitem.style.display = 'none';
1.192 raeburn 15502: }
15503: }
15504: }
15505: return;
15506: }
15507:
15508: // ]]>
15509: </script>
15510:
15511: END
15512:
15513: }
15514:
1.165 raeburn 15515: sub captcha_phrases {
15516: return &Apache::lonlocal::texthash (
15517: priv => 'Private key',
15518: pub => 'Public key',
15519: original => 'original (CAPTCHA)',
15520: recaptcha => 'successor (ReCAPTCHA)',
15521: notused => 'unused',
1.289 raeburn 15522: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 15523: );
15524: }
15525:
1.205 raeburn 15526: sub devalidate_remote_domconfs {
1.212 raeburn 15527: my ($dom,$cachekeys) = @_;
15528: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 15529: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15530: my %thismachine;
15531: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 15532: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 15533: if (keys(%servers)) {
1.205 raeburn 15534: foreach my $server (keys(%servers)) {
15535: next if ($thismachine{$server});
1.212 raeburn 15536: my @cached;
15537: foreach my $name (@posscached) {
15538: if ($cachekeys->{$name}) {
15539: push(@cached,&escape($name).':'.&escape($dom));
15540: }
15541: }
15542: if (@cached) {
15543: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15544: }
1.205 raeburn 15545: }
15546: }
15547: return;
15548: }
15549:
1.3 raeburn 15550: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>