Annotation of loncom/interface/domainprefs.pm, revision 1.294
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.294 ! raeburn 4: # $Id: domainprefs.pm,v 1.293 2017/02/25 20:30:52 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: ###############################################################
30: ##############################################################
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.43 raeburn 223: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 224: 'autoupdate','autocreate','directorysrch','contacts',
1.224 raeburn 225: 'usercreation','selfcreation','usermodification','scantron',
1.163 raeburn 226: 'requestcourses','requestauthor','coursecategories',
1.267 raeburn 227: 'serverstatuses','helpsettings','coursedefaults',
1.279 raeburn 228: 'ltitools','selfenrollment','usersessions','ssl','trust');
1.171 raeburn 229: my %existing;
230: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
231: %existing = %{$domconfig{'loadbalancing'}};
232: }
233: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 234: push(@prefs_order,'loadbalancing');
235: }
1.30 raeburn 236: my %prefs = (
237: 'rolecolors' =>
238: { text => 'Default color schemes',
1.67 raeburn 239: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 240: header => [{col1 => 'Student Settings',
241: col2 => '',},
242: {col1 => 'Coordinator Settings',
243: col2 => '',},
244: {col1 => 'Author Settings',
245: col2 => '',},
246: {col1 => 'Administrator Settings',
247: col2 => '',}],
1.230 raeburn 248: print => \&print_rolecolors,
249: modify => \&modify_rolecolors,
1.30 raeburn 250: },
1.110 raeburn 251: 'login' =>
1.30 raeburn 252: { text => 'Log-in page options',
1.67 raeburn 253: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 254: header => [{col1 => 'Log-in Page Items',
255: col2 => '',},
256: {col1 => 'Log-in Help',
1.256 raeburn 257: col2 => 'Value'},
258: {col1 => 'Custom HTML in document head',
1.168 raeburn 259: col2 => 'Value'}],
1.230 raeburn 260: print => \&print_login,
261: modify => \&modify_login,
1.30 raeburn 262: },
1.43 raeburn 263: 'defaults' =>
1.236 raeburn 264: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 265: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 266: header => [{col1 => 'Setting',
1.236 raeburn 267: col2 => 'Value'},
1.294 ! raeburn 268: {col1 => 'Internal Authentication',
! 269: col2 => 'Value'},
1.236 raeburn 270: {col1 => 'Institutional user types',
271: col2 => 'Assignable to e-mail usernames'}],
1.230 raeburn 272: print => \&print_defaults,
273: modify => \&modify_defaults,
1.43 raeburn 274: },
1.30 raeburn 275: 'quotas' =>
1.197 raeburn 276: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 277: help => 'Domain_Configuration_Quotas',
1.77 raeburn 278: header => [{col1 => 'User affiliation',
1.72 raeburn 279: col2 => 'Available tools',
1.213 raeburn 280: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 281: print => \&print_quotas,
282: modify => \&modify_quotas,
1.30 raeburn 283: },
284: 'autoenroll' =>
285: { text => 'Auto-enrollment settings',
1.67 raeburn 286: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 287: header => [{col1 => 'Configuration setting',
288: col2 => 'Value(s)'}],
1.230 raeburn 289: print => \&print_autoenroll,
290: modify => \&modify_autoenroll,
1.30 raeburn 291: },
292: 'autoupdate' =>
293: { text => 'Auto-update settings',
1.67 raeburn 294: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 295: header => [{col1 => 'Setting',
296: col2 => 'Value',},
1.131 raeburn 297: {col1 => 'Setting',
298: col2 => 'Affiliation'},
1.43 raeburn 299: {col1 => 'User population',
1.227 bisitz 300: col2 => 'Updatable user data'}],
1.230 raeburn 301: print => \&print_autoupdate,
302: modify => \&modify_autoupdate,
1.30 raeburn 303: },
1.125 raeburn 304: 'autocreate' =>
305: { text => 'Auto-course creation settings',
306: help => 'Domain_Configuration_Auto_Creation',
307: header => [{col1 => 'Configuration Setting',
308: col2 => 'Value',}],
1.230 raeburn 309: print => \&print_autocreate,
310: modify => \&modify_autocreate,
1.125 raeburn 311: },
1.30 raeburn 312: 'directorysrch' =>
1.277 raeburn 313: { text => 'Directory searches',
1.67 raeburn 314: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 315: header => [{col1 => 'Institutional Directory Setting',
316: col2 => 'Value',},
317: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 318: col2 => 'Value',}],
1.230 raeburn 319: print => \&print_directorysrch,
320: modify => \&modify_directorysrch,
1.30 raeburn 321: },
322: 'contacts' =>
1.286 raeburn 323: { text => 'E-mail addresses and helpform',
1.67 raeburn 324: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 325: header => [{col1 => 'Default e-mail addresses',
326: col2 => 'Value',},
327: {col1 => 'Recipient(s) for notifications',
328: col2 => 'Value',},
329: {col1 => 'Ask helpdesk form settings',
330: col2 => 'Value',},],
1.230 raeburn 331: print => \&print_contacts,
332: modify => \&modify_contacts,
1.30 raeburn 333: },
334: 'usercreation' =>
335: { text => 'User creation',
1.67 raeburn 336: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 337: header => [{col1 => 'Format rule type',
338: col2 => 'Format rules in force'},
1.34 raeburn 339: {col1 => 'User account creation',
340: col2 => 'Usernames which may be created',},
1.30 raeburn 341: {col1 => 'Context',
1.43 raeburn 342: col2 => 'Assignable authentication types'}],
1.230 raeburn 343: print => \&print_usercreation,
344: modify => \&modify_usercreation,
1.30 raeburn 345: },
1.224 raeburn 346: 'selfcreation' =>
347: { text => 'Users self-creating accounts',
348: help => 'Domain_Configuration_Self_Creation',
349: header => [{col1 => 'Self-creation with institutional username',
350: col2 => 'Enabled?'},
351: {col1 => 'Institutional user type (login/SSO self-creation)',
352: col2 => 'Information user can enter'},
353: {col1 => 'Self-creation with e-mail as username',
354: col2 => 'Settings'}],
1.230 raeburn 355: print => \&print_selfcreation,
356: modify => \&modify_selfcreation,
1.224 raeburn 357: },
1.69 raeburn 358: 'usermodification' =>
1.33 raeburn 359: { text => 'User modification',
1.67 raeburn 360: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 361: header => [{col1 => 'Target user has role',
1.227 bisitz 362: col2 => 'User information updatable in author context'},
1.33 raeburn 363: {col1 => 'Target user has role',
1.227 bisitz 364: col2 => 'User information updatable in course context'}],
1.230 raeburn 365: print => \&print_usermodification,
366: modify => \&modify_usermodification,
1.33 raeburn 367: },
1.69 raeburn 368: 'scantron' =>
1.95 www 369: { text => 'Bubblesheet format file',
1.67 raeburn 370: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 371: header => [ {col1 => 'Item',
372: col2 => '',
373: }],
1.230 raeburn 374: print => \&print_scantron,
375: modify => \&modify_scantron,
1.46 raeburn 376: },
1.86 raeburn 377: 'requestcourses' =>
378: {text => 'Request creation of courses',
379: help => 'Domain_Configuration_Request_Courses',
380: header => [{col1 => 'User affiliation',
1.102 raeburn 381: col2 => 'Availability/Processing of requests',},
382: {col1 => 'Setting',
1.216 raeburn 383: col2 => 'Value'},
384: {col1 => 'Available textbooks',
1.235 raeburn 385: col2 => ''},
1.242 raeburn 386: {col1 => 'Available templates',
387: col2 => ''},
1.235 raeburn 388: {col1 => 'Validation (not official courses)',
389: col2 => 'Value'},],
1.230 raeburn 390: print => \&print_quotas,
391: modify => \&modify_quotas,
1.86 raeburn 392: },
1.163 raeburn 393: 'requestauthor' =>
1.223 bisitz 394: {text => 'Request Authoring Space',
1.163 raeburn 395: help => 'Domain_Configuration_Request_Author',
396: header => [{col1 => 'User affiliation',
397: col2 => 'Availability/Processing of requests',},
398: {col1 => 'Setting',
399: col2 => 'Value'}],
1.230 raeburn 400: print => \&print_quotas,
401: modify => \&modify_quotas,
1.163 raeburn 402: },
1.69 raeburn 403: 'coursecategories' =>
1.120 raeburn 404: { text => 'Cataloging of courses/communities',
1.67 raeburn 405: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 406: header => [{col1 => 'Catalog type/availability',
407: col2 => '',},
408: {col1 => 'Category settings for standard catalog',
1.57 raeburn 409: col2 => '',},
410: {col1 => 'Categories',
411: col2 => '',
412: }],
1.230 raeburn 413: print => \&print_coursecategories,
414: modify => \&modify_coursecategories,
1.69 raeburn 415: },
416: 'serverstatuses' =>
1.77 raeburn 417: {text => 'Access to server status pages',
1.69 raeburn 418: help => 'Domain_Configuration_Server_Status',
419: header => [{col1 => 'Status Page',
420: col2 => 'Other named users',
421: col3 => 'Specific IPs',
422: }],
1.230 raeburn 423: print => \&print_serverstatuses,
424: modify => \&modify_serverstatuses,
1.69 raeburn 425: },
1.118 jms 426: 'helpsettings' =>
1.282 raeburn 427: {text => 'Support settings',
1.118 jms 428: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 429: header => [{col1 => 'Help Page Settings (logged-in users)',
430: col2 => 'Value'},
431: {col1 => 'Helpdesk Roles',
432: col2 => 'Settings'},],
1.230 raeburn 433: print => \&print_helpsettings,
434: modify => \&modify_helpsettings,
1.118 jms 435: },
1.121 raeburn 436: 'coursedefaults' =>
437: {text => 'Course/Community defaults',
438: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 439: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
440: col2 => 'Value',},
441: {col1 => 'Defaults which can be overridden for each course by a DC',
442: col2 => 'Value',},],
1.230 raeburn 443: print => \&print_coursedefaults,
444: modify => \&modify_coursedefaults,
1.121 raeburn 445: },
1.231 raeburn 446: 'selfenrollment' =>
447: {text => 'Self-enrollment in Course/Community',
448: help => 'Domain_Configuration_Selfenrollment',
449: header => [{col1 => 'Configuration Rights',
450: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
451: {col1 => 'Defaults',
452: col2 => 'Value'},
453: {col1 => 'Self-enrollment validation (optional)',
454: col2 => 'Value'},],
455: print => \&print_selfenrollment,
456: modify => \&modify_selfenrollment,
457: },
1.120 raeburn 458: 'privacy' =>
459: {text => 'User Privacy',
460: help => 'Domain_Configuration_User_Privacy',
461: header => [{col1 => 'Setting',
462: col2 => 'Value',}],
1.230 raeburn 463: print => \&print_privacy,
464: modify => \&modify_privacy,
1.120 raeburn 465: },
1.141 raeburn 466: 'usersessions' =>
1.145 raeburn 467: {text => 'User session hosting/offloading',
1.137 raeburn 468: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 469: header => [{col1 => 'Domain server',
470: col2 => 'Servers to offload sessions to when busy'},
471: {col1 => 'Hosting of users from other domains',
1.137 raeburn 472: col2 => 'Rules'},
473: {col1 => "Hosting domain's own users elsewhere",
474: col2 => 'Rules'}],
1.230 raeburn 475: print => \&print_usersessions,
476: modify => \&modify_usersessions,
1.137 raeburn 477: },
1.279 raeburn 478: 'loadbalancing' =>
1.185 raeburn 479: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 480: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 481: header => [{col1 => 'Balancers',
1.150 raeburn 482: col2 => 'Default destinations',
1.183 bisitz 483: col3 => 'User affiliation',
1.150 raeburn 484: col4 => 'Overrides'},
485: ],
1.230 raeburn 486: print => \&print_loadbalancing,
487: modify => \&modify_loadbalancing,
1.150 raeburn 488: },
1.279 raeburn 489: 'ltitools' =>
1.267 raeburn 490: {text => 'External Tools (LTI)',
491: help => 'Domain_configuration_LTI_Tools',
492: header => [{col1 => 'Setting',
493: col2 => 'Value',}],
494: print => \&print_ltitools,
495: modify => \&modify_ltitools,
496: },
1.279 raeburn 497: 'ssl' =>
1.275 raeburn 498: {text => 'LON-CAPA Network (SSL)',
499: help => 'Domain_Configuration_Network_SSL',
500: header => [{col1 => 'Server',
501: col2 => 'Certificate Status'},
502: {col1 => 'Connections to other servers',
503: col2 => 'Rules'},
1.293 raeburn 504: {col1 => 'Connections from other servers',
505: col2 => 'Rules'},
1.275 raeburn 506: {col1 => "Replicating domain's published content",
507: col2 => 'Rules'}],
508: print => \&print_ssl,
509: modify => \&modify_ssl,
510: },
1.279 raeburn 511: 'trust' =>
512: {text => 'Trust Settings',
513: help => 'Domain_Configuration_Trust',
514: header => [{col1 => "Access to this domain's content by others",
515: col2 => 'Rules'},
516: {col1 => "Access to other domain's content by this domain",
517: col2 => 'Rules'},
518: {col1 => "Enrollment in this domain's courses by others",
519: col2 => 'Rules',},
520: {col1 => "Co-author roles in this domain for others",
521: col2 => 'Rules',},
522: {col1 => "Co-author roles for this domain's users elsewhere",
523: col2 => 'Rules',},
524: {col1 => "Domain roles in this domain assignable to others",
525: col2 => 'Rules'},
526: {col1 => "Course catalog for this domain displayed elsewhere",
527: col2 => 'Rules'},
528: {col1 => "Requests for creation of courses in this domain by others",
529: col2 => 'Rules'},
530: {col1 => "Users in other domains can send messages to this domain",
531: col2 => 'Rules'},],
532: print => \&print_trust,
533: modify => \&modify_trust,
534: },
1.3 raeburn 535: );
1.110 raeburn 536: if (keys(%servers) > 1) {
537: $prefs{'login'} = { text => 'Log-in page options',
538: help => 'Domain_Configuration_Login_Page',
539: header => [{col1 => 'Log-in Service',
540: col2 => 'Server Setting',},
541: {col1 => 'Log-in Page Items',
1.168 raeburn 542: col2 => ''},
543: {col1 => 'Log-in Help',
1.256 raeburn 544: col2 => 'Value'},
545: {col1 => 'Custom HTML in document head',
1.168 raeburn 546: col2 => 'Value'}],
1.230 raeburn 547: print => \&print_login,
548: modify => \&modify_login,
1.110 raeburn 549: };
550: }
1.174 foxr 551:
1.6 raeburn 552: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 553: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 554: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 555: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 556: text=>"Settings to display/modify"});
1.9 raeburn 557: my $confname = $dom.'-domainconfig';
1.174 foxr 558:
1.3 raeburn 559: if ($phase eq 'process') {
1.212 raeburn 560: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
561: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 562: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 563: $r->rflush();
1.212 raeburn 564: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 565: }
1.30 raeburn 566: } elsif ($phase eq 'display') {
1.192 raeburn 567: my $js = &recaptcha_js().
1.236 raeburn 568: &toggle_display_js();
1.171 raeburn 569: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 570: my ($othertitle,$usertypes,$types) =
571: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 572: $js .= &lonbalance_targets_js($dom,$types,\%servers,
573: $domconfig{'loadbalancing'}).
1.170 raeburn 574: &new_spares_js().
575: &common_domprefs_js().
576: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 577: }
1.216 raeburn 578: if (grep(/^requestcourses$/,@actions)) {
579: my $javascript_validations;
580: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
581: $js .= <<END;
582: <script type="text/javascript">
583: $javascript_validations
584: </script>
585: $coursebrowserjs
586: END
587: }
1.286 raeburn 588: if (grep(/^contacts$/,@actions)) {
589: $js .= &contacts_javascript();
590: }
1.150 raeburn 591: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 592: } else {
1.180 raeburn 593: # check if domconfig user exists for the domain.
594: my $servadm = $r->dir_config('lonAdmEMail');
595: my ($configuserok,$author_ok,$switchserver) =
596: &config_check($dom,$confname,$servadm);
597: unless ($configuserok eq 'ok') {
1.181 raeburn 598: &Apache::lonconfigsettings::print_header($r,$phase,$context);
599: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 600: $confname).
1.181 raeburn 601: '<br />'
602: );
1.180 raeburn 603: if ($switchserver) {
1.181 raeburn 604: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
605: '<br />'.
606: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
607: '<br />'.
608: &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).
609: '<br />'.
610: &mt('To do that now, use the following link: [_1]',$switchserver)
611: );
612: } else {
613: $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.').
614: '<br />'.
615: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
616: );
1.180 raeburn 617: }
618: $r->print(&Apache::loncommon::end_page());
619: return OK;
620: }
1.21 raeburn 621: if (keys(%domconfig) == 0) {
622: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 623: my @ids=&Apache::lonnet::current_machine_ids();
624: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 625: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 626: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 627: my $custom_img_count = 0;
628: foreach my $img (@loginimages) {
629: if ($designhash{$dom.'.login.'.$img} ne '') {
630: $custom_img_count ++;
631: }
632: }
633: foreach my $role (@roles) {
634: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
635: $custom_img_count ++;
636: }
637: }
638: if ($custom_img_count > 0) {
1.94 raeburn 639: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 640: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 641: $r->print(
642: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
643: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
644: &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 />'.
645: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
646: if ($switch_server) {
1.30 raeburn 647: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 648: }
1.91 raeburn 649: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 650: return OK;
651: }
652: }
653: }
1.91 raeburn 654: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 655: }
656: return OK;
657: }
658:
659: sub process_changes {
1.205 raeburn 660: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 661: my %domconfig;
662: if (ref($values) eq 'HASH') {
663: %domconfig = %{$values};
664: }
1.3 raeburn 665: my $output;
666: if ($action eq 'login') {
1.205 raeburn 667: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 668: } elsif ($action eq 'rolecolors') {
1.9 raeburn 669: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 670: $lastactref,%domconfig);
1.3 raeburn 671: } elsif ($action eq 'quotas') {
1.216 raeburn 672: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 673: } elsif ($action eq 'autoenroll') {
1.205 raeburn 674: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 675: } elsif ($action eq 'autoupdate') {
676: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 677: } elsif ($action eq 'autocreate') {
678: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 679: } elsif ($action eq 'directorysrch') {
680: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 681: } elsif ($action eq 'usercreation') {
1.28 raeburn 682: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 683: } elsif ($action eq 'selfcreation') {
684: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 685: } elsif ($action eq 'usermodification') {
686: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 687: } elsif ($action eq 'contacts') {
1.205 raeburn 688: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 689: } elsif ($action eq 'defaults') {
1.212 raeburn 690: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 691: } elsif ($action eq 'scantron') {
1.205 raeburn 692: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 693: } elsif ($action eq 'coursecategories') {
1.239 raeburn 694: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 695: } elsif ($action eq 'serverstatuses') {
696: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 697: } elsif ($action eq 'requestcourses') {
1.216 raeburn 698: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 699: } elsif ($action eq 'requestauthor') {
1.216 raeburn 700: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 701: } elsif ($action eq 'helpsettings') {
1.285 raeburn 702: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 703: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 704: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 705: } elsif ($action eq 'selfenrollment') {
706: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 707: } elsif ($action eq 'usersessions') {
1.212 raeburn 708: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 709: } elsif ($action eq 'loadbalancing') {
710: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 711: } elsif ($action eq 'ltitools') {
712: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 713: } elsif ($action eq 'ssl') {
714: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 715: } elsif ($action eq 'trust') {
716: $output = &modify_trust($dom,$lastactref,%domconfig);
1.3 raeburn 717: }
718: return $output;
719: }
720:
721: sub print_config_box {
1.9 raeburn 722: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 723: my $rowtotal = 0;
1.49 raeburn 724: my $output;
725: if ($action eq 'coursecategories') {
726: $output = &coursecategories_javascript($settings);
1.236 raeburn 727: } elsif ($action eq 'defaults') {
728: $output = &defaults_javascript($settings);
1.282 raeburn 729: } elsif ($action eq 'helpsettings') {
730: my (%privs,%levelscurrent);
731: my %full=();
732: my %levels=(
733: course => {},
734: domain => {},
735: system => {},
736: );
737: my $context = 'domain';
738: my $crstype = 'Course';
739: my $formname = 'display';
740: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
741: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
742: $output =
743: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
744: \@templateroles);
1.91 raeburn 745: }
1.236 raeburn 746: $output .=
1.30 raeburn 747: '<table class="LC_nested_outer">
1.3 raeburn 748: <tr>
1.66 raeburn 749: <th align="left" valign="middle"><span class="LC_nobreak">'.
750: &mt($item->{text}).' '.
751: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
752: '</tr>';
1.30 raeburn 753: $rowtotal ++;
1.110 raeburn 754: my $numheaders = 1;
755: if (ref($item->{'header'}) eq 'ARRAY') {
756: $numheaders = scalar(@{$item->{'header'}});
757: }
758: if ($numheaders > 1) {
1.64 raeburn 759: my $colspan = '';
1.145 raeburn 760: my $rightcolspan = '';
1.238 raeburn 761: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 762: ($action eq 'directorysrch') ||
1.256 raeburn 763: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 764: $colspan = ' colspan="2"';
765: }
1.145 raeburn 766: if ($action eq 'usersessions') {
767: $rightcolspan = ' colspan="3"';
768: }
1.30 raeburn 769: $output .= '
1.3 raeburn 770: <tr>
771: <td>
772: <table class="LC_nested">
773: <tr class="LC_info_row">
1.59 bisitz 774: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 775: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 776: </tr>';
1.69 raeburn 777: $rowtotal ++;
1.230 raeburn 778: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 779: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 780: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 781: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
782: ($action eq 'contacts')) {
1.230 raeburn 783: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 784: } elsif ($action eq 'coursecategories') {
1.230 raeburn 785: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 786: } elsif ($action eq 'login') {
1.256 raeburn 787: if ($numheaders == 4) {
1.168 raeburn 788: $colspan = ' colspan="2"';
789: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
790: } else {
791: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
792: }
1.230 raeburn 793: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 794: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 795: } elsif ($action eq 'rolecolors') {
1.30 raeburn 796: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 797: }
1.30 raeburn 798: $output .= '
1.6 raeburn 799: </table>
800: </td>
801: </tr>
802: <tr>
803: <td>
804: <table class="LC_nested">
805: <tr class="LC_info_row">
1.230 raeburn 806: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 807: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 808: </tr>';
809: $rowtotal ++;
1.230 raeburn 810: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
811: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 812: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.294 ! raeburn 813: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {
1.238 raeburn 814: if ($action eq 'coursecategories') {
815: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
816: $colspan = ' colspan="2"';
1.279 raeburn 817: } elsif ($action eq 'trust') {
818: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.238 raeburn 819: } else {
820: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
821: }
1.279 raeburn 822: if ($action eq 'trust') {
823: $output .= '
824: </table>
825: </td>
826: </tr>';
827: my @trusthdrs = qw(2 3 4 5 6 7);
828: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
829: for (my $i=0; $i<@trusthdrs; $i++) {
830: $output .= '
831: <tr>
832: <td>
833: <table class="LC_nested">
834: <tr class="LC_info_row">
835: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
836: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
837: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
838: </table>
839: </td>
840: </tr>';
841: }
842: $output .= '
843: <tr>
844: <td>
845: <table class="LC_nested">
846: <tr class="LC_info_row">
847: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
848: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
849: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
850: } else {
851: $output .= '
1.63 raeburn 852: </table>
853: </td>
854: </tr>
855: <tr>
856: <td>
857: <table class="LC_nested">
858: <tr class="LC_info_row">
859: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 860: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 861: </tr>'."\n";
1.279 raeburn 862: if ($action eq 'coursecategories') {
863: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
864: } else {
865: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
866: }
1.238 raeburn 867: }
1.63 raeburn 868: $rowtotal ++;
1.236 raeburn 869: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282 raeburn 870: ($action eq 'defaults') || ($action eq 'directorysrch') ||
871: ($action eq 'helpsettings')) {
1.230 raeburn 872: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.293 raeburn 873: } elsif ($action eq 'ssl') {
874: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
875: </table>
876: </td>
877: </tr>
878: <tr>
879: <td>
880: <table class="LC_nested">
881: <tr class="LC_info_row">
882: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
883: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
884: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
885: </table>
886: </td>
887: </tr>
888: <tr>
889: <td>
890: <table class="LC_nested">
891: <tr class="LC_info_row">
892: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
893: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
894: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 895: } elsif ($action eq 'login') {
1.256 raeburn 896: if ($numheaders == 4) {
1.168 raeburn 897: $output .= &print_login('page',$dom,$confname,$phase,$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'}->[2]->{'col1'}).'</td>
1.216 raeburn 906: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 907: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
908: $rowtotal ++;
909: } else {
910: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
911: }
1.256 raeburn 912: $output .= '
913: </table>
914: </td>
915: </tr>
916: <tr>
917: <td>
918: <table class="LC_nested">
919: <tr class="LC_info_row">';
920: if ($numheaders == 4) {
921: $output .= '
922: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
923: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
924: </tr>';
925: } else {
926: $output .= '
927: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
928: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
929: </tr>';
930: }
931: $rowtotal ++;
932: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 933: } elsif ($action eq 'requestcourses') {
1.247 raeburn 934: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
935: $rowtotal ++;
936: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 937: </table>
938: </td>
939: </tr>
940: <tr>
941: <td>
942: <table class="LC_nested">
943: <tr class="LC_info_row">
944: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
945: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 946: &textbookcourses_javascript($settings).
947: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
948: </table>
949: </td>
950: </tr>
951: <tr>
952: <td>
953: <table class="LC_nested">
954: <tr class="LC_info_row">
955: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
956: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
957: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 958: </table>
959: </td>
960: </tr>
961: <tr>
962: <td>
963: <table class="LC_nested">
964: <tr class="LC_info_row">
1.242 raeburn 965: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
966: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 967: </tr>'.
968: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 969: } elsif ($action eq 'requestauthor') {
970: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 971: $rowtotal ++;
1.122 jms 972: } elsif ($action eq 'rolecolors') {
1.30 raeburn 973: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 974: </table>
975: </td>
976: </tr>
977: <tr>
978: <td>
979: <table class="LC_nested">
980: <tr class="LC_info_row">
1.69 raeburn 981: <td class="LC_left_item"'.$colspan.' valign="top">'.
982: &mt($item->{'header'}->[2]->{'col1'}).'</td>
983: <td class="LC_right_item" valign="top">'.
984: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 985: </tr>'.
1.30 raeburn 986: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 987: </table>
988: </td>
989: </tr>
990: <tr>
991: <td>
992: <table class="LC_nested">
993: <tr class="LC_info_row">
1.59 bisitz 994: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
995: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 996: </tr>'.
1.30 raeburn 997: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
998: $rowtotal += 2;
1.6 raeburn 999: }
1.3 raeburn 1000: } else {
1.30 raeburn 1001: $output .= '
1.3 raeburn 1002: <tr>
1003: <td>
1004: <table class="LC_nested">
1.30 raeburn 1005: <tr class="LC_info_row">';
1.277 raeburn 1006: if ($action eq 'login') {
1.30 raeburn 1007: $output .= '
1.59 bisitz 1008: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1009: } elsif ($action eq 'serverstatuses') {
1010: $output .= '
1011: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1012: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1013:
1.6 raeburn 1014: } else {
1.30 raeburn 1015: $output .= '
1.69 raeburn 1016: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1017: }
1.72 raeburn 1018: if (defined($item->{'header'}->[0]->{'col3'})) {
1019: $output .= '<td class="LC_left_item" valign="top">'.
1020: &mt($item->{'header'}->[0]->{'col2'});
1021: if ($action eq 'serverstatuses') {
1022: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1023: }
1.69 raeburn 1024: } else {
1025: $output .= '<td class="LC_right_item" valign="top">'.
1026: &mt($item->{'header'}->[0]->{'col2'});
1027: }
1028: $output .= '</td>';
1029: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1030: if (defined($item->{'header'}->[0]->{'col4'})) {
1031: $output .= '<td class="LC_left_item" valign="top">'.
1032: &mt($item->{'header'}->[0]->{'col3'});
1033: } else {
1034: $output .= '<td class="LC_right_item" valign="top">'.
1035: &mt($item->{'header'}->[0]->{'col3'});
1036: }
1.69 raeburn 1037: if ($action eq 'serverstatuses') {
1038: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1039: }
1040: $output .= '</td>';
1.6 raeburn 1041: }
1.150 raeburn 1042: if ($item->{'header'}->[0]->{'col4'}) {
1043: $output .= '<td class="LC_right_item" valign="top">'.
1044: &mt($item->{'header'}->[0]->{'col4'});
1045: }
1.69 raeburn 1046: $output .= '</tr>';
1.48 raeburn 1047: $rowtotal ++;
1.168 raeburn 1048: if ($action eq 'quotas') {
1.86 raeburn 1049: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1050: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1051: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1052: ($action eq 'ltitools')) {
1.230 raeburn 1053: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 1054: } elsif ($action eq 'scantron') {
1055: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 1056: }
1.3 raeburn 1057: }
1.30 raeburn 1058: $output .= '
1.3 raeburn 1059: </table>
1060: </td>
1061: </tr>
1.30 raeburn 1062: </table><br />';
1063: return ($output,$rowtotal);
1.1 raeburn 1064: }
1065:
1.3 raeburn 1066: sub print_login {
1.168 raeburn 1067: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 1068: my ($css_class,$datatable);
1.6 raeburn 1069: my %choices = &login_choices();
1.110 raeburn 1070:
1.168 raeburn 1071: if ($caller eq 'service') {
1.149 raeburn 1072: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1073: my $choice = $choices{'disallowlogin'};
1074: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1075: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1076: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1077: '<th>'.$choices{'server'}.'</th>'.
1078: '<th>'.$choices{'serverpath'}.'</th>'.
1079: '<th>'.$choices{'custompath'}.'</th>'.
1080: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1081: my %disallowed;
1082: if (ref($settings) eq 'HASH') {
1083: if (ref($settings->{'loginvia'}) eq 'HASH') {
1084: %disallowed = %{$settings->{'loginvia'}};
1085: }
1086: }
1087: foreach my $lonhost (sort(keys(%servers))) {
1088: my $direct = 'selected="selected"';
1.128 raeburn 1089: if (ref($disallowed{$lonhost}) eq 'HASH') {
1090: if ($disallowed{$lonhost}{'server'} ne '') {
1091: $direct = '';
1092: }
1.110 raeburn 1093: }
1.115 raeburn 1094: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1095: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1096: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1097: '</option>';
1.184 raeburn 1098: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1099: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1100: my $selected = '';
1.128 raeburn 1101: if (ref($disallowed{$lonhost}) eq 'HASH') {
1102: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1103: $selected = 'selected="selected"';
1104: }
1.110 raeburn 1105: }
1106: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1107: $servers{$hostid}.'</option>';
1108: }
1.128 raeburn 1109: $datatable .= '</select></td>'.
1110: '<td><select name="'.$lonhost.'_serverpath">';
1111: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1112: my $pathname = $path;
1113: if ($path eq 'custom') {
1114: $pathname = &mt('Custom Path').' ->';
1115: }
1116: my $selected = '';
1117: if (ref($disallowed{$lonhost}) eq 'HASH') {
1118: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1119: $selected = 'selected="selected"';
1120: }
1121: } elsif ($path eq '') {
1122: $selected = 'selected="selected"';
1123: }
1124: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1125: }
1126: $datatable .= '</select></td>';
1127: my ($custom,$exempt);
1128: if (ref($disallowed{$lonhost}) eq 'HASH') {
1129: $custom = $disallowed{$lonhost}{'custompath'};
1130: $exempt = $disallowed{$lonhost}{'exempt'};
1131: }
1132: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1133: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1134: '</tr>';
1.110 raeburn 1135: }
1136: $datatable .= '</table></td></tr>';
1137: return $datatable;
1.168 raeburn 1138: } elsif ($caller eq 'page') {
1139: my %defaultchecked = (
1140: 'coursecatalog' => 'on',
1.188 raeburn 1141: 'helpdesk' => 'on',
1.168 raeburn 1142: 'adminmail' => 'off',
1143: 'newuser' => 'off',
1144: );
1.188 raeburn 1145: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1146: my (%checkedon,%checkedoff);
1.42 raeburn 1147: foreach my $item (@toggles) {
1.168 raeburn 1148: if ($defaultchecked{$item} eq 'on') {
1149: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1150: $checkedoff{$item} = ' ';
1.168 raeburn 1151: } elsif ($defaultchecked{$item} eq 'off') {
1152: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1153: $checkedon{$item} = ' ';
1154: }
1.1 raeburn 1155: }
1.168 raeburn 1156: my @images = ('img','logo','domlogo','login');
1157: my @logintext = ('textcol','bgcol');
1158: my @bgs = ('pgbg','mainbg','sidebg');
1159: my @links = ('link','alink','vlink');
1160: my %designhash = &Apache::loncommon::get_domainconf($dom);
1161: my %defaultdesign = %Apache::loncommon::defaultdesign;
1162: my (%is_custom,%designs);
1163: my %defaults = (
1164: font => $defaultdesign{'login.font'},
1165: );
1.6 raeburn 1166: foreach my $item (@images) {
1.168 raeburn 1167: $defaults{$item} = $defaultdesign{'login.'.$item};
1168: $defaults{'showlogo'}{$item} = 1;
1169: }
1170: foreach my $item (@bgs) {
1171: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1172: }
1.41 raeburn 1173: foreach my $item (@logintext) {
1.168 raeburn 1174: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1175: }
1.168 raeburn 1176: foreach my $item (@links) {
1177: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1178: }
1.168 raeburn 1179: if (ref($settings) eq 'HASH') {
1180: foreach my $item (@toggles) {
1181: if ($settings->{$item} eq '1') {
1182: $checkedon{$item} = ' checked="checked" ';
1183: $checkedoff{$item} = ' ';
1184: } elsif ($settings->{$item} eq '0') {
1185: $checkedoff{$item} = ' checked="checked" ';
1186: $checkedon{$item} = ' ';
1187: }
1188: }
1189: foreach my $item (@images) {
1190: if (defined($settings->{$item})) {
1191: $designs{$item} = $settings->{$item};
1192: $is_custom{$item} = 1;
1193: }
1194: if (defined($settings->{'showlogo'}{$item})) {
1195: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1196: }
1197: }
1198: foreach my $item (@logintext) {
1199: if ($settings->{$item} ne '') {
1200: $designs{'logintext'}{$item} = $settings->{$item};
1201: $is_custom{$item} = 1;
1202: }
1203: }
1204: if ($settings->{'font'} ne '') {
1205: $designs{'font'} = $settings->{'font'};
1206: $is_custom{'font'} = 1;
1207: }
1208: foreach my $item (@bgs) {
1209: if ($settings->{$item} ne '') {
1210: $designs{'bgs'}{$item} = $settings->{$item};
1211: $is_custom{$item} = 1;
1212: }
1213: }
1214: foreach my $item (@links) {
1215: if ($settings->{$item} ne '') {
1216: $designs{'links'}{$item} = $settings->{$item};
1217: $is_custom{$item} = 1;
1218: }
1219: }
1220: } else {
1221: if ($designhash{$dom.'.login.font'} ne '') {
1222: $designs{'font'} = $designhash{$dom.'.login.font'};
1223: $is_custom{'font'} = 1;
1224: }
1225: foreach my $item (@images) {
1226: if ($designhash{$dom.'.login.'.$item} ne '') {
1227: $designs{$item} = $designhash{$dom.'.login.'.$item};
1228: $is_custom{$item} = 1;
1229: }
1230: }
1231: foreach my $item (@bgs) {
1232: if ($designhash{$dom.'.login.'.$item} ne '') {
1233: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1234: $is_custom{$item} = 1;
1235: }
1.6 raeburn 1236: }
1.168 raeburn 1237: foreach my $item (@links) {
1238: if ($designhash{$dom.'.login.'.$item} ne '') {
1239: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1240: $is_custom{$item} = 1;
1241: }
1.6 raeburn 1242: }
1243: }
1.168 raeburn 1244: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1245: logo => 'Institution Logo',
1246: domlogo => 'Domain Logo',
1247: login => 'Login box');
1248: my $itemcount = 1;
1249: foreach my $item (@toggles) {
1250: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1251: $datatable .=
1252: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1253: '</td><td>'.
1254: '<span class="LC_nobreak"><label><input type="radio" name="'.
1255: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1256: '</label> <label><input type="radio" name="'.$item.'"'.
1257: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1258: '</tr>';
1259: $itemcount ++;
1.6 raeburn 1260: }
1.168 raeburn 1261: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1262: $datatable .= '</tr></table></td></tr>';
1263: } elsif ($caller eq 'help') {
1264: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1265: my $switchserver = &check_switchserver($dom,$confname);
1266: my $itemcount = 1;
1267: $defaulturl = '/adm/loginproblems.html';
1268: $defaulttype = 'default';
1269: %lt = &Apache::lonlocal::texthash (
1270: del => 'Delete?',
1271: rep => 'Replace:',
1272: upl => 'Upload:',
1273: default => 'Default',
1274: custom => 'Custom',
1275: );
1276: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1277: my @currlangs;
1278: if (ref($settings) eq 'HASH') {
1279: if (ref($settings->{'helpurl'}) eq 'HASH') {
1280: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1281: next if ($settings->{'helpurl'}{$key} eq '');
1282: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1283: $type{$key} = 'custom';
1284: unless ($key eq 'nolang') {
1285: push(@currlangs,$key);
1286: }
1287: }
1288: } elsif ($settings->{'helpurl'} ne '') {
1289: $type{'nolang'} = 'custom';
1290: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1291: }
1292: }
1.168 raeburn 1293: foreach my $lang ('nolang',sort(@currlangs)) {
1294: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1295: $datatable .= '<tr'.$css_class.'>';
1296: if ($url{$lang} eq '') {
1297: $url{$lang} = $defaulturl;
1298: }
1299: if ($type{$lang} eq '') {
1300: $type{$lang} = $defaulttype;
1301: }
1302: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1303: if ($lang eq 'nolang') {
1304: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1305: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1306: } else {
1307: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1308: $langchoices{$lang},
1309: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1310: }
1311: $datatable .= '</span></td>'."\n".
1312: '<td class="LC_left_item">';
1313: if ($type{$lang} eq 'custom') {
1314: $datatable .= '<span class="LC_nobreak"><label>'.
1315: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1316: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1317: } else {
1318: $datatable .= $lt{'upl'};
1319: }
1320: $datatable .='<br />';
1321: if ($switchserver) {
1322: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1323: } else {
1324: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1325: }
1.168 raeburn 1326: $datatable .= '</td></tr>';
1327: $itemcount ++;
1.6 raeburn 1328: }
1.168 raeburn 1329: my @addlangs;
1330: foreach my $lang (sort(keys(%langchoices))) {
1331: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1332: push(@addlangs,$lang);
1333: }
1334: if (@addlangs > 0) {
1335: my %toadd;
1336: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1337: $toadd{''} = &mt('Select');
1338: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1339: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1340: &mt('Add log-in help page for a specific language:').' '.
1341: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1342: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1343: if ($switchserver) {
1344: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1345: } else {
1346: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1347: }
1.168 raeburn 1348: $datatable .= '</td></tr>';
1.169 raeburn 1349: $itemcount ++;
1.6 raeburn 1350: }
1.169 raeburn 1351: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1352: } elsif ($caller eq 'headtag') {
1353: my %domservers = &Apache::lonnet::get_servers($dom);
1354: my $choice = $choices{'headtag'};
1355: $css_class = ' class="LC_odd_row"';
1356: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1357: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1358: '<th>'.$choices{'current'}.'</th>'.
1359: '<th>'.$choices{'action'}.'</th>'.
1360: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1361: my (%currurls,%currexempt);
1362: if (ref($settings) eq 'HASH') {
1363: if (ref($settings->{'headtag'}) eq 'HASH') {
1364: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1365: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1366: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1367: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1368: }
1369: }
1370: }
1371: }
1372: my %lt = &Apache::lonlocal::texthash(
1373: del => 'Delete?',
1374: rep => 'Replace:',
1375: upl => 'Upload:',
1376: curr => 'View contents',
1377: none => 'None',
1378: );
1379: my $switchserver = &check_switchserver($dom,$confname);
1380: foreach my $lonhost (sort(keys(%domservers))) {
1381: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1382: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1383: if ($currurls{$lonhost}) {
1384: $datatable .= '<td class="LC_right_item"><a href="'.
1385: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1386: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1387: '">'.$lt{'curr'}.'</a></td>'.
1388: '<td><span class="LC_nobreak"><label>'.
1389: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1390: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1391: } else {
1392: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1393: }
1394: $datatable .='<br />';
1395: if ($switchserver) {
1396: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1397: } else {
1398: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1399: }
1400: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1401: }
1402: $datatable .= '</table></td></tr>';
1.1 raeburn 1403: }
1.6 raeburn 1404: return $datatable;
1405: }
1406:
1407: sub login_choices {
1408: my %choices =
1409: &Apache::lonlocal::texthash (
1.116 bisitz 1410: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1411: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1412: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1413: disallowlogin => "Login page requests redirected",
1414: hostid => "Server",
1.128 raeburn 1415: server => "Redirect to:",
1416: serverpath => "Path",
1417: custompath => "Custom",
1418: exempt => "Exempt IP(s)",
1.110 raeburn 1419: directlogin => "No redirect",
1420: newuser => "Link to create a user account",
1421: img => "Header",
1422: logo => "Main Logo",
1423: domlogo => "Domain Logo",
1424: login => "Log-in Header",
1425: textcol => "Text color",
1426: bgcol => "Box color",
1427: bgs => "Background colors",
1428: links => "Link colors",
1429: font => "Font color",
1430: pgbg => "Header",
1431: mainbg => "Page",
1432: sidebg => "Login box",
1433: link => "Link",
1434: alink => "Active link",
1435: vlink => "Visited link",
1.256 raeburn 1436: headtag => "Custom markup",
1437: action => "Action",
1438: current => "Current",
1.6 raeburn 1439: );
1440: return %choices;
1441: }
1442:
1443: sub print_rolecolors {
1.30 raeburn 1444: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1445: my %choices = &color_font_choices();
1446: my @bgs = ('pgbg','tabbg','sidebg');
1447: my @links = ('link','alink','vlink');
1448: my @images = ('img');
1449: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1450: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1451: my %defaultdesign = %Apache::loncommon::defaultdesign;
1452: my (%is_custom,%designs);
1.200 raeburn 1453: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1454: if (ref($settings) eq 'HASH') {
1455: if (ref($settings->{$role}) eq 'HASH') {
1456: if ($settings->{$role}->{'img'} ne '') {
1457: $designs{'img'} = $settings->{$role}->{'img'};
1458: $is_custom{'img'} = 1;
1459: }
1460: if ($settings->{$role}->{'font'} ne '') {
1461: $designs{'font'} = $settings->{$role}->{'font'};
1462: $is_custom{'font'} = 1;
1463: }
1.97 tempelho 1464: if ($settings->{$role}->{'fontmenu'} ne '') {
1465: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1466: $is_custom{'fontmenu'} = 1;
1467: }
1.6 raeburn 1468: foreach my $item (@bgs) {
1469: if ($settings->{$role}->{$item} ne '') {
1470: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1471: $is_custom{$item} = 1;
1472: }
1473: }
1474: foreach my $item (@links) {
1475: if ($settings->{$role}->{$item} ne '') {
1476: $designs{'links'}{$item} = $settings->{$role}->{$item};
1477: $is_custom{$item} = 1;
1478: }
1479: }
1480: }
1481: } else {
1482: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1483: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1484: $is_custom{'img'} = 1;
1485: }
1.97 tempelho 1486: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1487: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1488: $is_custom{'fontmenu'} = 1;
1489: }
1.6 raeburn 1490: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1491: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1492: $is_custom{'font'} = 1;
1493: }
1494: foreach my $item (@bgs) {
1495: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1496: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1497: $is_custom{$item} = 1;
1498:
1499: }
1500: }
1501: foreach my $item (@links) {
1502: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1503: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1504: $is_custom{$item} = 1;
1505: }
1506: }
1507: }
1508: my $itemcount = 1;
1.30 raeburn 1509: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1510: $datatable .= '</tr></table></td></tr>';
1511: return $datatable;
1512: }
1513:
1.200 raeburn 1514: sub role_defaults {
1515: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1516: my %defaults;
1517: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1518: return %defaults;
1519: }
1520: my %defaultdesign = %Apache::loncommon::defaultdesign;
1521: if ($role eq 'login') {
1522: %defaults = (
1523: font => $defaultdesign{$role.'.font'},
1524: );
1525: if (ref($logintext) eq 'ARRAY') {
1526: foreach my $item (@{$logintext}) {
1527: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1528: }
1529: }
1530: foreach my $item (@{$images}) {
1531: $defaults{'showlogo'}{$item} = 1;
1532: }
1533: } else {
1534: %defaults = (
1535: img => $defaultdesign{$role.'.img'},
1536: font => $defaultdesign{$role.'.font'},
1537: fontmenu => $defaultdesign{$role.'.fontmenu'},
1538: );
1539: }
1540: foreach my $item (@{$bgs}) {
1541: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1542: }
1543: foreach my $item (@{$links}) {
1544: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1545: }
1546: foreach my $item (@{$images}) {
1547: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1548: }
1549: return %defaults;
1550: }
1551:
1.6 raeburn 1552: sub display_color_options {
1.9 raeburn 1553: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1554: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1555: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1556: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1557: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1558: '<td>'.$choices->{'font'}.'</td>';
1559: if (!$is_custom->{'font'}) {
1.30 raeburn 1560: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1561: } else {
1562: $datatable .= '<td> </td>';
1563: }
1.174 foxr 1564: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1565:
1.8 raeburn 1566: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1567: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1568: ' value="'.$current_color.'" /> '.
1.174 foxr 1569: ' </td></tr>';
1.107 raeburn 1570: unless ($role eq 'login') {
1571: $datatable .= '<tr'.$css_class.'>'.
1572: '<td>'.$choices->{'fontmenu'}.'</td>';
1573: if (!$is_custom->{'fontmenu'}) {
1574: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1575: } else {
1576: $datatable .= '<td> </td>';
1577: }
1.202 raeburn 1578: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1579: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1580: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1581: '<input class="colorchooser" type="text" size="10" name="'
1582: .$role.'_fontmenu"'.
1583: ' value="'.$current_color.'" /> '.
1584: ' </td></tr>';
1.97 tempelho 1585: }
1.9 raeburn 1586: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1587: foreach my $img (@{$images}) {
1.18 albertel 1588: $itemcount ++;
1.6 raeburn 1589: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1590: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1591: '<td>'.$choices->{$img};
1.41 raeburn 1592: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1593: if ($role eq 'login') {
1594: if ($img eq 'login') {
1595: $login_hdr_pick =
1.135 bisitz 1596: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1597: $logincolors =
1598: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1599: $designs,$defaults);
1.70 raeburn 1600: } elsif ($img ne 'domlogo') {
1601: $datatable.= &logo_display_options($img,$defaults,$designs);
1602: }
1603: }
1604: $datatable .= '</td>';
1.6 raeburn 1605: if ($designs->{$img} ne '') {
1606: $imgfile = $designs->{$img};
1.18 albertel 1607: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1608: } else {
1609: $imgfile = $defaults->{$img};
1610: }
1611: if ($imgfile) {
1.9 raeburn 1612: my ($showfile,$fullsize);
1613: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1614: my $urldir = $1;
1615: my $filename = $2;
1616: my @info = &Apache::lonnet::stat_file($designs->{$img});
1617: if (@info) {
1618: my $thumbfile = 'tn-'.$filename;
1619: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1620: if (@thumb) {
1621: $showfile = $urldir.'/'.$thumbfile;
1622: } else {
1623: $showfile = $imgfile;
1624: }
1625: } else {
1626: $showfile = '';
1627: }
1628: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1629: $showfile = $imgfile;
1.6 raeburn 1630: my $imgdir = $1;
1631: my $filename = $2;
1.159 raeburn 1632: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1633: $showfile = "/$imgdir/tn-".$filename;
1634: } else {
1.159 raeburn 1635: my $input = $londocroot.$imgfile;
1636: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1637: if (!-e $output) {
1.9 raeburn 1638: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1639: my ($fullwidth,$fullheight) = &check_dimensions($input);
1640: if ($fullwidth ne '' && $fullheight ne '') {
1641: if ($fullwidth > $width && $fullheight > $height) {
1642: my $size = $width.'x'.$height;
1643: system("convert -sample $size $input $output");
1.159 raeburn 1644: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1645: }
1646: }
1.6 raeburn 1647: }
1648: }
1.16 raeburn 1649: }
1.6 raeburn 1650: if ($showfile) {
1.40 raeburn 1651: if ($showfile =~ m{^/(adm|res)/}) {
1652: if ($showfile =~ m{^/res/}) {
1653: my $local_showfile =
1654: &Apache::lonnet::filelocation('',$showfile);
1655: &Apache::lonnet::repcopy($local_showfile);
1656: }
1657: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1658: }
1659: if ($imgfile) {
1660: if ($imgfile =~ m{^/(adm|res)/}) {
1661: if ($imgfile =~ m{^/res/}) {
1662: my $local_imgfile =
1663: &Apache::lonnet::filelocation('',$imgfile);
1664: &Apache::lonnet::repcopy($local_imgfile);
1665: }
1666: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1667: } else {
1668: $fullsize = $imgfile;
1669: }
1670: }
1.41 raeburn 1671: $datatable .= '<td>';
1672: if ($img eq 'login') {
1.135 bisitz 1673: $datatable .= $login_hdr_pick;
1674: }
1.41 raeburn 1675: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1676: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1677: } else {
1.201 raeburn 1678: $datatable .= '<td> </td><td class="LC_left_item">'.
1679: &mt('Upload:').'<br />';
1.6 raeburn 1680: }
1681: } else {
1.201 raeburn 1682: $datatable .= '<td> </td><td class="LC_left_item">'.
1683: &mt('Upload:').'<br />';
1.6 raeburn 1684: }
1.9 raeburn 1685: if ($switchserver) {
1686: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1687: } else {
1.135 bisitz 1688: if ($img ne 'login') { # suppress file selection for Log-in header
1689: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1690: }
1.9 raeburn 1691: }
1692: $datatable .= '</td></tr>';
1.6 raeburn 1693: }
1694: $itemcount ++;
1695: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1696: $datatable .= '<tr'.$css_class.'>'.
1697: '<td>'.$choices->{'bgs'}.'</td>';
1698: my $bgs_def;
1699: foreach my $item (@{$bgs}) {
1700: if (!$is_custom->{$item}) {
1.70 raeburn 1701: $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 1702: }
1703: }
1704: if ($bgs_def) {
1.8 raeburn 1705: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1706: } else {
1707: $datatable .= '<td> </td>';
1708: }
1709: $datatable .= '<td class="LC_right_item">'.
1710: '<table border="0"><tr>';
1.174 foxr 1711:
1.6 raeburn 1712: foreach my $item (@{$bgs}) {
1.201 raeburn 1713: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1714: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1715: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1716: $datatable .= ' ';
1.6 raeburn 1717: }
1.174 foxr 1718: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1719: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1720: }
1721: $datatable .= '</tr></table></td></tr>';
1722: $itemcount ++;
1723: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1724: $datatable .= '<tr'.$css_class.'>'.
1725: '<td>'.$choices->{'links'}.'</td>';
1726: my $links_def;
1727: foreach my $item (@{$links}) {
1728: if (!$is_custom->{$item}) {
1.30 raeburn 1729: $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 1730: }
1731: }
1732: if ($links_def) {
1.8 raeburn 1733: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1734: } else {
1735: $datatable .= '<td> </td>';
1736: }
1737: $datatable .= '<td class="LC_right_item">'.
1738: '<table border="0"><tr>';
1739: foreach my $item (@{$links}) {
1.234 raeburn 1740: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1741: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1742: if ($designs->{'links'}{$item}) {
1.174 foxr 1743: $datatable.=' ';
1.6 raeburn 1744: }
1.174 foxr 1745: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1746: '" /></td>';
1747: }
1.30 raeburn 1748: $$rowtotal += $itemcount;
1.3 raeburn 1749: return $datatable;
1750: }
1751:
1.70 raeburn 1752: sub logo_display_options {
1753: my ($img,$defaults,$designs) = @_;
1754: my $checkedon;
1755: if (ref($defaults) eq 'HASH') {
1756: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1757: if ($defaults->{'showlogo'}{$img}) {
1758: $checkedon = 'checked="checked" ';
1759: }
1760: }
1761: }
1762: if (ref($designs) eq 'HASH') {
1763: if (ref($designs->{'showlogo'}) eq 'HASH') {
1764: if (defined($designs->{'showlogo'}{$img})) {
1765: if ($designs->{'showlogo'}{$img} == 0) {
1766: $checkedon = '';
1767: } elsif ($designs->{'showlogo'}{$img} == 1) {
1768: $checkedon = 'checked="checked" ';
1769: }
1770: }
1771: }
1772: }
1773: return '<br /><label> <input type="checkbox" name="'.
1774: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1775: &mt('show').'</label>'."\n";
1776: }
1777:
1.41 raeburn 1778: sub login_header_options {
1.135 bisitz 1779: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1780: my $output = '';
1.41 raeburn 1781: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1782: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1783: if (!$is_custom->{'textcol'}) {
1784: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1785: ' ';
1786: }
1787: if (!$is_custom->{'bgcol'}) {
1788: $output .= $choices->{'bgcol'}.': '.
1789: '<span id="css_'.$role.'_font" style="background-color: '.
1790: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1791: }
1792: $output .= '<br />';
1793: }
1794: $output .='<br />';
1795: return $output;
1796: }
1797:
1798: sub login_text_colors {
1.201 raeburn 1799: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1800: my $color_menu = '<table border="0"><tr>';
1801: foreach my $item (@{$logintext}) {
1.201 raeburn 1802: $color_menu .= '<td align="center">'.$choices->{$item};
1803: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1804: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1805: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1806: }
1807: $color_menu .= '</tr></table><br />';
1808: return $color_menu;
1809: }
1810:
1811: sub image_changes {
1812: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1813: my $output;
1.135 bisitz 1814: if ($img eq 'login') {
1815: # suppress image for Log-in header
1816: } elsif (!$is_custom) {
1.70 raeburn 1817: if ($img ne 'domlogo') {
1.41 raeburn 1818: $output .= &mt('Default image:').'<br />';
1819: } else {
1820: $output .= &mt('Default in use:').'<br />';
1821: }
1822: }
1.135 bisitz 1823: if ($img eq 'login') { # suppress image for Log-in header
1824: $output .= '<td>'.$logincolors;
1.41 raeburn 1825: } else {
1.135 bisitz 1826: if ($img_import) {
1827: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1828: }
1829: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1830: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1831: if ($is_custom) {
1832: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1833: '<input type="checkbox" name="'.
1834: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1835: '</label> '.&mt('Replace:').'</span><br />';
1836: } else {
1.201 raeburn 1837: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1838: }
1.41 raeburn 1839: }
1840: return $output;
1841: }
1842:
1.3 raeburn 1843: sub print_quotas {
1.86 raeburn 1844: my ($dom,$settings,$rowtotal,$action) = @_;
1845: my $context;
1846: if ($action eq 'quotas') {
1847: $context = 'tools';
1848: } else {
1849: $context = $action;
1850: }
1.197 raeburn 1851: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1852: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1853: my $typecount = 0;
1.101 raeburn 1854: my ($css_class,%titles);
1.86 raeburn 1855: if ($context eq 'requestcourses') {
1.271 raeburn 1856: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 1857: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1858: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1859: %titles = &courserequest_titles();
1.163 raeburn 1860: } elsif ($context eq 'requestauthor') {
1861: @usertools = ('author');
1862: @options = ('norequest','approval','automatic');
1.210 raeburn 1863: %titles = &authorrequest_titles();
1.86 raeburn 1864: } else {
1.162 raeburn 1865: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1866: %titles = &tool_titles();
1.86 raeburn 1867: }
1.26 raeburn 1868: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1869: foreach my $type (@{$types}) {
1.197 raeburn 1870: my ($currdefquota,$currauthorquota);
1.163 raeburn 1871: unless (($context eq 'requestcourses') ||
1872: ($context eq 'requestauthor')) {
1.86 raeburn 1873: if (ref($settings) eq 'HASH') {
1874: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1875: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1876: } else {
1877: $currdefquota = $settings->{$type};
1878: }
1.197 raeburn 1879: if (ref($settings->{authorquota}) eq 'HASH') {
1880: $currauthorquota = $settings->{authorquota}->{$type};
1881: }
1.78 raeburn 1882: }
1.72 raeburn 1883: }
1.3 raeburn 1884: if (defined($usertypes->{$type})) {
1885: $typecount ++;
1886: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1887: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1888: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1889: '<td class="LC_left_item">';
1.101 raeburn 1890: if ($context eq 'requestcourses') {
1891: $datatable .= '<table><tr>';
1892: }
1893: my %cell;
1.72 raeburn 1894: foreach my $item (@usertools) {
1.101 raeburn 1895: if ($context eq 'requestcourses') {
1896: my ($curroption,$currlimit);
1897: if (ref($settings) eq 'HASH') {
1898: if (ref($settings->{$item}) eq 'HASH') {
1899: $curroption = $settings->{$item}->{$type};
1900: if ($curroption =~ /^autolimit=(\d*)$/) {
1901: $currlimit = $1;
1902: }
1903: }
1904: }
1905: if (!$curroption) {
1906: $curroption = 'norequest';
1907: }
1908: $datatable .= '<th>'.$titles{$item}.'</th>';
1909: foreach my $option (@options) {
1910: my $val = $option;
1911: if ($option eq 'norequest') {
1912: $val = 0;
1913: }
1914: if ($option eq 'validate') {
1915: my $canvalidate = 0;
1916: if (ref($validations{$item}) eq 'HASH') {
1917: if ($validations{$item}{$type}) {
1918: $canvalidate = 1;
1919: }
1920: }
1921: next if (!$canvalidate);
1922: }
1923: my $checked = '';
1924: if ($option eq $curroption) {
1925: $checked = ' checked="checked"';
1926: } elsif ($option eq 'autolimit') {
1927: if ($curroption =~ /^autolimit/) {
1928: $checked = ' checked="checked"';
1929: }
1930: }
1931: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1932: '<input type="radio" name="crsreq_'.$item.
1933: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1934: $titles{$option}.'</label>';
1.101 raeburn 1935: if ($option eq 'autolimit') {
1.127 raeburn 1936: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1937: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1938: 'value="'.$currlimit.'" />';
1.101 raeburn 1939: }
1.127 raeburn 1940: $cell{$item} .= '</span> ';
1.103 raeburn 1941: if ($option eq 'autolimit') {
1.127 raeburn 1942: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1943: }
1.101 raeburn 1944: }
1.163 raeburn 1945: } elsif ($context eq 'requestauthor') {
1946: my $curroption;
1947: if (ref($settings) eq 'HASH') {
1948: $curroption = $settings->{$type};
1949: }
1950: if (!$curroption) {
1951: $curroption = 'norequest';
1952: }
1953: foreach my $option (@options) {
1954: my $val = $option;
1955: if ($option eq 'norequest') {
1956: $val = 0;
1957: }
1958: my $checked = '';
1959: if ($option eq $curroption) {
1960: $checked = ' checked="checked"';
1961: }
1962: $datatable .= '<span class="LC_nobreak"><label>'.
1963: '<input type="radio" name="authorreq_'.$type.
1964: '" value="'.$val.'"'.$checked.' />'.
1965: $titles{$option}.'</label></span> ';
1966: }
1.101 raeburn 1967: } else {
1968: my $checked = 'checked="checked" ';
1969: if (ref($settings) eq 'HASH') {
1970: if (ref($settings->{$item}) eq 'HASH') {
1971: if ($settings->{$item}->{$type} == 0) {
1972: $checked = '';
1973: } elsif ($settings->{$item}->{$type} == 1) {
1974: $checked = 'checked="checked" ';
1975: }
1.78 raeburn 1976: }
1.72 raeburn 1977: }
1.101 raeburn 1978: $datatable .= '<span class="LC_nobreak"><label>'.
1979: '<input type="checkbox" name="'.$context.'_'.$item.
1980: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1981: '</label></span> ';
1.72 raeburn 1982: }
1.101 raeburn 1983: }
1984: if ($context eq 'requestcourses') {
1985: $datatable .= '</tr><tr>';
1986: foreach my $item (@usertools) {
1.106 raeburn 1987: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1988: }
1989: $datatable .= '</tr></table>';
1.72 raeburn 1990: }
1.86 raeburn 1991: $datatable .= '</td>';
1.163 raeburn 1992: unless (($context eq 'requestcourses') ||
1993: ($context eq 'requestauthor')) {
1.86 raeburn 1994: $datatable .=
1.197 raeburn 1995: '<td class="LC_right_item">'.
1996: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1997: '<input type="text" name="quota_'.$type.
1.72 raeburn 1998: '" value="'.$currdefquota.
1.197 raeburn 1999: '" size="5" /></span>'.(' ' x 2).
2000: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2001: '<input type="text" name="authorquota_'.$type.
2002: '" value="'.$currauthorquota.
2003: '" size="5" /></span></td>';
1.86 raeburn 2004: }
2005: $datatable .= '</tr>';
1.3 raeburn 2006: }
2007: }
2008: }
1.163 raeburn 2009: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2010: $defaultquota = '20';
1.197 raeburn 2011: $authorquota = '500';
1.86 raeburn 2012: if (ref($settings) eq 'HASH') {
2013: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2014: $defaultquota = $settings->{'defaultquota'}->{'default'};
2015: } elsif (defined($settings->{'default'})) {
2016: $defaultquota = $settings->{'default'};
2017: }
1.197 raeburn 2018: if (ref($settings->{'authorquota'}) eq 'HASH') {
2019: $authorquota = $settings->{'authorquota'}->{'default'};
2020: }
1.3 raeburn 2021: }
2022: }
2023: $typecount ++;
2024: $css_class = $typecount%2?' class="LC_odd_row"':'';
2025: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2026: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2027: '<td class="LC_left_item">';
1.101 raeburn 2028: if ($context eq 'requestcourses') {
2029: $datatable .= '<table><tr>';
2030: }
2031: my %defcell;
1.72 raeburn 2032: foreach my $item (@usertools) {
1.101 raeburn 2033: if ($context eq 'requestcourses') {
2034: my ($curroption,$currlimit);
2035: if (ref($settings) eq 'HASH') {
2036: if (ref($settings->{$item}) eq 'HASH') {
2037: $curroption = $settings->{$item}->{'default'};
2038: if ($curroption =~ /^autolimit=(\d*)$/) {
2039: $currlimit = $1;
2040: }
2041: }
2042: }
2043: if (!$curroption) {
2044: $curroption = 'norequest';
2045: }
2046: $datatable .= '<th>'.$titles{$item}.'</th>';
2047: foreach my $option (@options) {
2048: my $val = $option;
2049: if ($option eq 'norequest') {
2050: $val = 0;
2051: }
2052: if ($option eq 'validate') {
2053: my $canvalidate = 0;
2054: if (ref($validations{$item}) eq 'HASH') {
2055: if ($validations{$item}{'default'}) {
2056: $canvalidate = 1;
2057: }
2058: }
2059: next if (!$canvalidate);
2060: }
2061: my $checked = '';
2062: if ($option eq $curroption) {
2063: $checked = ' checked="checked"';
2064: } elsif ($option eq 'autolimit') {
2065: if ($curroption =~ /^autolimit/) {
2066: $checked = ' checked="checked"';
2067: }
2068: }
2069: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2070: '<input type="radio" name="crsreq_'.$item.
2071: '_default" value="'.$val.'"'.$checked.' />'.
2072: $titles{$option}.'</label>';
2073: if ($option eq 'autolimit') {
1.127 raeburn 2074: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2075: $item.'_limit_default" size="1" '.
2076: 'value="'.$currlimit.'" />';
2077: }
1.127 raeburn 2078: $defcell{$item} .= '</span> ';
1.104 raeburn 2079: if ($option eq 'autolimit') {
1.127 raeburn 2080: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2081: }
1.101 raeburn 2082: }
1.163 raeburn 2083: } elsif ($context eq 'requestauthor') {
2084: my $curroption;
2085: if (ref($settings) eq 'HASH') {
1.172 raeburn 2086: $curroption = $settings->{'default'};
1.163 raeburn 2087: }
2088: if (!$curroption) {
2089: $curroption = 'norequest';
2090: }
2091: foreach my $option (@options) {
2092: my $val = $option;
2093: if ($option eq 'norequest') {
2094: $val = 0;
2095: }
2096: my $checked = '';
2097: if ($option eq $curroption) {
2098: $checked = ' checked="checked"';
2099: }
2100: $datatable .= '<span class="LC_nobreak"><label>'.
2101: '<input type="radio" name="authorreq_default"'.
2102: ' value="'.$val.'"'.$checked.' />'.
2103: $titles{$option}.'</label></span> ';
2104: }
1.101 raeburn 2105: } else {
2106: my $checked = 'checked="checked" ';
2107: if (ref($settings) eq 'HASH') {
2108: if (ref($settings->{$item}) eq 'HASH') {
2109: if ($settings->{$item}->{'default'} == 0) {
2110: $checked = '';
2111: } elsif ($settings->{$item}->{'default'} == 1) {
2112: $checked = 'checked="checked" ';
2113: }
1.78 raeburn 2114: }
1.72 raeburn 2115: }
1.101 raeburn 2116: $datatable .= '<span class="LC_nobreak"><label>'.
2117: '<input type="checkbox" name="'.$context.'_'.$item.
2118: '" value="default" '.$checked.'/>'.$titles{$item}.
2119: '</label></span> ';
2120: }
2121: }
2122: if ($context eq 'requestcourses') {
2123: $datatable .= '</tr><tr>';
2124: foreach my $item (@usertools) {
1.106 raeburn 2125: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2126: }
1.101 raeburn 2127: $datatable .= '</tr></table>';
1.72 raeburn 2128: }
1.86 raeburn 2129: $datatable .= '</td>';
1.163 raeburn 2130: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2131: $datatable .= '<td class="LC_right_item">'.
2132: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2133: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2134: $defaultquota.'" size="5" /></span>'.(' ' x2).
2135: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2136: '<input type="text" name="authorquota" value="'.
2137: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2138: }
2139: $datatable .= '</tr>';
1.72 raeburn 2140: $typecount ++;
2141: $css_class = $typecount%2?' class="LC_odd_row"':'';
2142: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2143: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2144: if ($context eq 'requestcourses') {
1.109 raeburn 2145: $datatable .= &mt('(overrides affiliation, if set)').
2146: '</td>'.
2147: '<td class="LC_left_item">'.
2148: '<table><tr>';
1.101 raeburn 2149: } else {
1.109 raeburn 2150: $datatable .= &mt('(overrides affiliation, if checked)').
2151: '</td>'.
2152: '<td class="LC_left_item" colspan="2">'.
2153: '<br />';
1.101 raeburn 2154: }
2155: my %advcell;
1.72 raeburn 2156: foreach my $item (@usertools) {
1.101 raeburn 2157: if ($context eq 'requestcourses') {
2158: my ($curroption,$currlimit);
2159: if (ref($settings) eq 'HASH') {
2160: if (ref($settings->{$item}) eq 'HASH') {
2161: $curroption = $settings->{$item}->{'_LC_adv'};
2162: if ($curroption =~ /^autolimit=(\d*)$/) {
2163: $currlimit = $1;
2164: }
2165: }
2166: }
2167: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2168: my $checked = '';
2169: if ($curroption eq '') {
2170: $checked = ' checked="checked"';
2171: }
2172: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2173: '<input type="radio" name="crsreq_'.$item.
2174: '__LC_adv" value=""'.$checked.' />'.
2175: &mt('No override set').'</label></span> ';
1.101 raeburn 2176: foreach my $option (@options) {
2177: my $val = $option;
2178: if ($option eq 'norequest') {
2179: $val = 0;
2180: }
2181: if ($option eq 'validate') {
2182: my $canvalidate = 0;
2183: if (ref($validations{$item}) eq 'HASH') {
2184: if ($validations{$item}{'_LC_adv'}) {
2185: $canvalidate = 1;
2186: }
2187: }
2188: next if (!$canvalidate);
2189: }
2190: my $checked = '';
1.104 raeburn 2191: if ($val eq $curroption) {
1.101 raeburn 2192: $checked = ' checked="checked"';
2193: } elsif ($option eq 'autolimit') {
2194: if ($curroption =~ /^autolimit/) {
2195: $checked = ' checked="checked"';
2196: }
2197: }
2198: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2199: '<input type="radio" name="crsreq_'.$item.
2200: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2201: $titles{$option}.'</label>';
2202: if ($option eq 'autolimit') {
1.127 raeburn 2203: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2204: $item.'_limit__LC_adv" size="1" '.
2205: 'value="'.$currlimit.'" />';
2206: }
1.127 raeburn 2207: $advcell{$item} .= '</span> ';
1.104 raeburn 2208: if ($option eq 'autolimit') {
1.127 raeburn 2209: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2210: }
1.101 raeburn 2211: }
1.163 raeburn 2212: } elsif ($context eq 'requestauthor') {
2213: my $curroption;
2214: if (ref($settings) eq 'HASH') {
2215: $curroption = $settings->{'_LC_adv'};
2216: }
2217: my $checked = '';
2218: if ($curroption eq '') {
2219: $checked = ' checked="checked"';
2220: }
2221: $datatable .= '<span class="LC_nobreak"><label>'.
2222: '<input type="radio" name="authorreq__LC_adv"'.
2223: ' value=""'.$checked.' />'.
2224: &mt('No override set').'</label></span> ';
2225: foreach my $option (@options) {
2226: my $val = $option;
2227: if ($option eq 'norequest') {
2228: $val = 0;
2229: }
2230: my $checked = '';
2231: if ($val eq $curroption) {
2232: $checked = ' checked="checked"';
2233: }
2234: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2235: '<input type="radio" name="authorreq__LC_adv"'.
2236: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2237: $titles{$option}.'</label></span> ';
2238: }
1.101 raeburn 2239: } else {
2240: my $checked = 'checked="checked" ';
2241: if (ref($settings) eq 'HASH') {
2242: if (ref($settings->{$item}) eq 'HASH') {
2243: if ($settings->{$item}->{'_LC_adv'} == 0) {
2244: $checked = '';
2245: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2246: $checked = 'checked="checked" ';
2247: }
1.79 raeburn 2248: }
1.72 raeburn 2249: }
1.101 raeburn 2250: $datatable .= '<span class="LC_nobreak"><label>'.
2251: '<input type="checkbox" name="'.$context.'_'.$item.
2252: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2253: '</label></span> ';
2254: }
2255: }
2256: if ($context eq 'requestcourses') {
2257: $datatable .= '</tr><tr>';
2258: foreach my $item (@usertools) {
1.106 raeburn 2259: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2260: }
1.101 raeburn 2261: $datatable .= '</tr></table>';
1.72 raeburn 2262: }
1.98 raeburn 2263: $datatable .= '</td></tr>';
1.30 raeburn 2264: $$rowtotal += $typecount;
1.3 raeburn 2265: return $datatable;
2266: }
2267:
1.163 raeburn 2268: sub print_requestmail {
2269: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 2270: my ($now,$datatable,%currapp);
1.102 raeburn 2271: $now = time;
2272: if (ref($settings) eq 'HASH') {
2273: if (ref($settings->{'notify'}) eq 'HASH') {
2274: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2275: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2276: }
2277: }
2278: }
1.191 raeburn 2279: my $numinrow = 2;
1.224 raeburn 2280: my $css_class;
2281: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163 raeburn 2282: my $text;
2283: if ($action eq 'requestcourses') {
2284: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2285: } elsif ($action eq 'requestauthor') {
2286: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2287: } else {
1.224 raeburn 2288: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2289: }
1.224 raeburn 2290: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2291: ' <td>'.$text.'</td>'.
1.102 raeburn 2292: ' <td class="LC_left_item">';
1.191 raeburn 2293: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2294: $action.'notifyapproval',%currapp);
1.191 raeburn 2295: if ($numdc > 0) {
2296: $datatable .= $table;
1.102 raeburn 2297: } else {
2298: $datatable .= &mt('There are no active Domain Coordinators');
2299: }
2300: $datatable .='</td></tr>';
2301: return $datatable;
2302: }
2303:
1.216 raeburn 2304: sub print_studentcode {
2305: my ($settings,$rowtotal) = @_;
2306: my $rownum = 0;
1.218 raeburn 2307: my ($output,%current);
1.271 raeburn 2308: my @crstypes = ('official','unofficial','community','textbook','placement');
1.248 raeburn 2309: if (ref($settings) eq 'HASH') {
2310: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2311: foreach my $type (@crstypes) {
2312: $current{$type} = $settings->{'uniquecode'}{$type};
2313: }
1.218 raeburn 2314: }
2315: }
2316: $output .= '<tr>'.
2317: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2318: '<td class="LC_left_item">';
2319: foreach my $type (@crstypes) {
2320: my $check = ' ';
2321: if ($current{$type}) {
2322: $check = ' checked="checked" ';
2323: }
2324: $output .= '<span class="LC_nobreak"><label>'.
2325: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2326: &mt($type).'</label></span>'.(' 'x2).' ';
2327: }
2328: $output .= '</td></tr>';
2329: $$rowtotal ++;
2330: return $output;
1.216 raeburn 2331: }
2332:
2333: sub print_textbookcourses {
1.242 raeburn 2334: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2335: my $rownum = 0;
2336: my $css_class;
2337: my $itemcount = 1;
2338: my $maxnum = 0;
2339: my $bookshash;
2340: if (ref($settings) eq 'HASH') {
1.242 raeburn 2341: $bookshash = $settings->{$type};
1.216 raeburn 2342: }
2343: my %ordered;
2344: if (ref($bookshash) eq 'HASH') {
2345: foreach my $item (keys(%{$bookshash})) {
2346: if (ref($bookshash->{$item}) eq 'HASH') {
2347: my $num = $bookshash->{$item}{'order'};
2348: $ordered{$num} = $item;
2349: }
2350: }
2351: }
2352: my $confname = $dom.'-domainconfig';
2353: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2354: my $maxnum = scalar(keys(%ordered));
2355: my $datatable;
1.216 raeburn 2356: if (keys(%ordered)) {
2357: my @items = sort { $a <=> $b } keys(%ordered);
2358: for (my $i=0; $i<@items; $i++) {
2359: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2360: my $key = $ordered{$items[$i]};
2361: my %coursehash=&Apache::lonnet::coursedescription($key);
2362: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2363: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2364: if (ref($bookshash->{$key}) eq 'HASH') {
2365: $subject = $bookshash->{$key}->{'subject'};
2366: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2367: if ($type eq 'textbooks') {
1.243 raeburn 2368: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2369: $author = $bookshash->{$key}->{'author'};
2370: $image = $bookshash->{$key}->{'image'};
2371: if ($image ne '') {
2372: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2373: my $imagethumb = "$path/tn-".$imagefile;
2374: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2375: }
1.216 raeburn 2376: }
2377: }
1.242 raeburn 2378: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2379: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2380: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2381: for (my $k=0; $k<=$maxnum; $k++) {
2382: my $vpos = $k+1;
2383: my $selstr;
2384: if ($k == $i) {
2385: $selstr = ' selected="selected" ';
2386: }
2387: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2388: }
2389: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2390: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2391: &mt('Delete?').'</label></span></td>'.
2392: '<td colspan="2">'.
1.242 raeburn 2393: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2394: (' 'x2).
1.242 raeburn 2395: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2396: if ($type eq 'textbooks') {
2397: $datatable .= (' 'x2).
1.243 raeburn 2398: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2399: (' 'x2).
1.242 raeburn 2400: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2401: (' 'x2).
2402: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2403: if ($image) {
1.267 raeburn 2404: $datatable .= $imgsrc.
1.242 raeburn 2405: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2406: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2407: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2408: }
2409: if ($switchserver) {
2410: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2411: } else {
2412: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2413: }
1.216 raeburn 2414: }
1.242 raeburn 2415: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2416: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2417: $coursetitle.'</span></td></tr>'."\n";
2418: $itemcount ++;
2419: }
2420: }
2421: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2422: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2423: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2424: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2425: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2426: for (my $k=0; $k<$maxnum+1; $k++) {
2427: my $vpos = $k+1;
2428: my $selstr;
2429: if ($k == $maxnum) {
2430: $selstr = ' selected="selected" ';
2431: }
2432: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2433: }
2434: $datatable .= '</select> '."\n".
1.242 raeburn 2435: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216 raeburn 2436: '<td colspan="2">'.
1.242 raeburn 2437: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 2438: (' 'x2).
1.242 raeburn 2439: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2440: (' 'x2);
2441: if ($type eq 'textbooks') {
1.243 raeburn 2442: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2443: (' 'x2).
2444: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 2445: (' 'x2).
2446: '<span class="LC_nobreak">'.&mt('Image:').' ';
2447: if ($switchserver) {
2448: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2449: } else {
2450: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2451: }
1.216 raeburn 2452: }
2453: $datatable .= '</span>'."\n".
2454: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 2455: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2456: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 2457: &Apache::loncommon::selectcourse_link
1.242 raeburn 2458: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216 raeburn 2459: '</span></td>'."\n".
2460: '</tr>'."\n";
2461: $itemcount ++;
2462: return $datatable;
2463: }
2464:
1.217 raeburn 2465: sub textbookcourses_javascript {
1.242 raeburn 2466: my ($settings) = @_;
2467: return unless(ref($settings) eq 'HASH');
2468: my (%ordered,%total,%jstext);
2469: foreach my $type ('textbooks','templates') {
2470: $total{$type} = 0;
2471: if (ref($settings->{$type}) eq 'HASH') {
2472: foreach my $item (keys(%{$settings->{$type}})) {
2473: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2474: my $num = $settings->{$type}->{$item}{'order'};
2475: $ordered{$type}{$num} = $item;
2476: }
2477: }
2478: $total{$type} = scalar(keys(%{$settings->{$type}}));
2479: }
2480: my @jsarray = ();
2481: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2482: push(@jsarray,$ordered{$type}{$item});
2483: }
2484: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 2485: }
2486: return <<"ENDSCRIPT";
2487: <script type="text/javascript">
2488: // <![CDATA[
1.242 raeburn 2489: function reorderBooks(form,item,caller) {
1.217 raeburn 2490: var changedVal;
1.242 raeburn 2491: $jstext{'textbooks'};
2492: $jstext{'templates'};
2493: var newpos;
2494: var maxh;
2495: if (caller == 'textbooks') {
2496: newpos = 'textbooks_addbook_pos';
2497: maxh = 1 + $total{'textbooks'};
2498: } else {
2499: newpos = 'templates_addbook_pos';
2500: maxh = 1 + $total{'templates'};
2501: }
1.217 raeburn 2502: var current = new Array;
2503: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2504: if (item == newpos) {
2505: changedVal = newitemVal;
2506: } else {
2507: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2508: current[newitemVal] = newpos;
2509: }
1.242 raeburn 2510: if (caller == 'textbooks') {
2511: for (var i=0; i<textbooks.length; i++) {
2512: var elementName = 'textbooks_'+textbooks[i];
2513: if (elementName != item) {
2514: if (form.elements[elementName]) {
2515: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2516: current[currVal] = elementName;
2517: }
2518: }
2519: }
2520: }
2521: if (caller == 'templates') {
2522: for (var i=0; i<templates.length; i++) {
2523: var elementName = 'templates_'+templates[i];
2524: if (elementName != item) {
2525: if (form.elements[elementName]) {
2526: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2527: current[currVal] = elementName;
2528: }
1.217 raeburn 2529: }
2530: }
2531: }
2532: var oldVal;
2533: for (var j=0; j<maxh; j++) {
2534: if (current[j] == undefined) {
2535: oldVal = j;
2536: }
2537: }
2538: if (oldVal < changedVal) {
2539: for (var k=oldVal+1; k<=changedVal ; k++) {
2540: var elementName = current[k];
2541: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2542: }
2543: } else {
2544: for (var k=changedVal; k<oldVal; k++) {
2545: var elementName = current[k];
2546: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2547: }
2548: }
2549: return;
2550: }
2551:
2552: // ]]>
2553: </script>
2554:
2555: ENDSCRIPT
2556: }
2557:
1.267 raeburn 2558: sub ltitools_javascript {
2559: my ($settings) = @_;
2560: return unless(ref($settings) eq 'HASH');
2561: my (%ordered,$total,%jstext);
2562: $total = 0;
2563: foreach my $item (keys(%{$settings})) {
2564: if (ref($settings->{$item}) eq 'HASH') {
2565: my $num = $settings->{$item}{'order'};
2566: $ordered{$num} = $item;
2567: }
2568: }
2569: $total = scalar(keys(%{$settings}));
2570: my @jsarray = ();
2571: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2572: push(@jsarray,$ordered{$item});
2573: }
2574: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2575: return <<"ENDSCRIPT";
2576: <script type="text/javascript">
2577: // <![CDATA[
2578: function reorderLTI(form,item) {
2579: var changedVal;
2580: $jstext
2581: var newpos = 'ltitools_add_pos';
2582: var maxh = 1 + $total;
2583: var current = new Array;
2584: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2585: if (item == newpos) {
2586: changedVal = newitemVal;
2587: } else {
2588: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2589: current[newitemVal] = newpos;
2590: }
2591: for (var i=0; i<ltitools.length; i++) {
2592: var elementName = 'ltitools_'+ltitools[i];
2593: if (elementName != item) {
2594: if (form.elements[elementName]) {
2595: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2596: current[currVal] = elementName;
2597: }
2598: }
2599: }
2600: var oldVal;
2601: for (var j=0; j<maxh; j++) {
2602: if (current[j] == undefined) {
2603: oldVal = j;
2604: }
2605: }
2606: if (oldVal < changedVal) {
2607: for (var k=oldVal+1; k<=changedVal ; k++) {
2608: var elementName = current[k];
2609: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2610: }
2611: } else {
2612: for (var k=changedVal; k<oldVal; k++) {
2613: var elementName = current[k];
2614: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2615: }
2616: }
2617: return;
2618: }
2619:
2620: // ]]>
2621: </script>
2622:
2623: ENDSCRIPT
2624: }
2625:
1.3 raeburn 2626: sub print_autoenroll {
1.30 raeburn 2627: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2628: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274 raeburn 2629: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2630: if (ref($settings) eq 'HASH') {
2631: if (exists($settings->{'run'})) {
2632: if ($settings->{'run'} eq '0') {
2633: $runoff = ' checked="checked" ';
2634: $runon = ' ';
2635: } else {
2636: $runon = ' checked="checked" ';
2637: $runoff = ' ';
2638: }
2639: } else {
2640: if ($autorun) {
2641: $runon = ' checked="checked" ';
2642: $runoff = ' ';
2643: } else {
2644: $runoff = ' checked="checked" ';
2645: $runon = ' ';
2646: }
2647: }
1.129 raeburn 2648: if (exists($settings->{'co-owners'})) {
2649: if ($settings->{'co-owners'} eq '0') {
2650: $coownersoff = ' checked="checked" ';
2651: $coownerson = ' ';
2652: } else {
2653: $coownerson = ' checked="checked" ';
2654: $coownersoff = ' ';
2655: }
2656: } else {
2657: $coownersoff = ' checked="checked" ';
2658: $coownerson = ' ';
2659: }
1.3 raeburn 2660: if (exists($settings->{'sender_domain'})) {
2661: $defdom = $settings->{'sender_domain'};
2662: }
1.274 raeburn 2663: if (exists($settings->{'autofailsafe'})) {
2664: $failsafe = $settings->{'autofailsafe'};
2665: }
1.14 raeburn 2666: } else {
2667: if ($autorun) {
2668: $runon = ' checked="checked" ';
2669: $runoff = ' ';
2670: } else {
2671: $runoff = ' checked="checked" ';
2672: $runon = ' ';
2673: }
1.3 raeburn 2674: }
2675: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2676: my $notif_sender;
2677: if (ref($settings) eq 'HASH') {
2678: $notif_sender = $settings->{'sender_uname'};
2679: }
1.3 raeburn 2680: my $datatable='<tr class="LC_odd_row">'.
2681: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2682: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2683: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2684: $runon.' value="1" />'.&mt('Yes').'</label> '.
2685: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2686: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2687: '</tr><tr>'.
2688: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2689: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2690: &mt('username').': '.
2691: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2692: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2693: ': '.$domform.'</span></td></tr>'.
2694: '<tr class="LC_odd_row">'.
2695: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2696: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2697: '<input type="radio" name="autoassign_coowners"'.
2698: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2699: '<label><input type="radio" name="autoassign_coowners"'.
2700: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 2701: '</tr><tr>'.
2702: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2703: '<td class="LC_right_item"><span class="LC_nobreak">'.
2704: '<input type="text" name="autoenroll_failsafe"'.
2705: ' value="'.$failsafe.'" size="4" /></td></tr>';
2706: $$rowtotal += 4;
1.3 raeburn 2707: return $datatable;
2708: }
2709:
2710: sub print_autoupdate {
1.30 raeburn 2711: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2712: my $datatable;
2713: if ($position eq 'top') {
2714: my $updateon = ' ';
2715: my $updateoff = ' checked="checked" ';
2716: my $classlistson = ' ';
2717: my $classlistsoff = ' checked="checked" ';
2718: if (ref($settings) eq 'HASH') {
2719: if ($settings->{'run'} eq '1') {
2720: $updateon = $updateoff;
2721: $updateoff = ' ';
2722: }
2723: if ($settings->{'classlists'} eq '1') {
2724: $classlistson = $classlistsoff;
2725: $classlistsoff = ' ';
2726: }
2727: }
2728: my %title = (
2729: run => 'Auto-update active?',
2730: classlists => 'Update information in classlists?',
2731: );
2732: $datatable = '<tr class="LC_odd_row">'.
2733: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2734: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2735: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2736: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2737: '<label><input type="radio" name="autoupdate_run"'.
2738: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2739: '</tr><tr>'.
2740: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2741: '<td class="LC_right_item"><span class="LC_nobreak">'.
2742: '<label><input type="radio" name="classlists"'.
2743: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2744: '<label><input type="radio" name="classlists"'.
2745: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2746: '</tr>';
1.30 raeburn 2747: $$rowtotal += 2;
1.131 raeburn 2748: } elsif ($position eq 'middle') {
2749: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2750: my $numinrow = 3;
2751: my $locknamesettings;
2752: $datatable .= &insttypes_row($settings,$types,$usertypes,
2753: $dom,$numinrow,$othertitle,
2754: 'lockablenames');
2755: $$rowtotal ++;
1.3 raeburn 2756: } else {
1.44 raeburn 2757: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2758: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2759: 'permanentemail','id');
1.33 raeburn 2760: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2761: my $numrows = 0;
1.26 raeburn 2762: if (ref($types) eq 'ARRAY') {
2763: if (@{$types} > 0) {
2764: $datatable =
2765: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2766: \@fields,$types,\$numrows);
1.30 raeburn 2767: $$rowtotal += @{$types};
1.26 raeburn 2768: }
1.3 raeburn 2769: }
2770: $datatable .=
2771: &usertype_update_row($settings,{'default' => $othertitle},
2772: \%fieldtitles,\@fields,['default'],
2773: \$numrows);
1.30 raeburn 2774: $$rowtotal ++;
1.3 raeburn 2775: }
2776: return $datatable;
2777: }
2778:
1.125 raeburn 2779: sub print_autocreate {
2780: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2781: my (%createon,%createoff,%currhash);
1.125 raeburn 2782: my @types = ('xml','req');
2783: if (ref($settings) eq 'HASH') {
2784: foreach my $item (@types) {
2785: $createoff{$item} = ' checked="checked" ';
2786: $createon{$item} = ' ';
2787: if (exists($settings->{$item})) {
2788: if ($settings->{$item}) {
2789: $createon{$item} = ' checked="checked" ';
2790: $createoff{$item} = ' ';
2791: }
2792: }
2793: }
1.210 raeburn 2794: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2795: $currhash{$settings->{'xmldc'}} = 1;
2796: }
1.125 raeburn 2797: } else {
2798: foreach my $item (@types) {
2799: $createoff{$item} = ' checked="checked" ';
2800: $createon{$item} = ' ';
2801: }
2802: }
2803: $$rowtotal += 2;
1.191 raeburn 2804: my $numinrow = 2;
1.125 raeburn 2805: my $datatable='<tr class="LC_odd_row">'.
2806: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2807: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2808: '<input type="radio" name="autocreate_xml"'.
2809: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2810: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2811: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2812: '</td></tr><tr>'.
2813: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2814: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2815: '<input type="radio" name="autocreate_req"'.
2816: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2817: '<label><input type="radio" name="autocreate_req"'.
2818: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2819: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2820: 'autocreate_xmldc',%currhash);
1.247 raeburn 2821: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2822: if ($numdc > 1) {
1.247 raeburn 2823: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2824: '</td><td class="LC_left_item">';
1.125 raeburn 2825: } else {
1.247 raeburn 2826: $datatable .= &mt('Course creation processed as:').
2827: '</td><td class="LC_right_item">';
1.125 raeburn 2828: }
1.247 raeburn 2829: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 2830: $$rowtotal += $rows;
1.125 raeburn 2831: return $datatable;
2832: }
2833:
1.23 raeburn 2834: sub print_directorysrch {
1.277 raeburn 2835: my ($position,$dom,$settings,$rowtotal) = @_;
2836: my $datatable;
2837: if ($position eq 'top') {
2838: my $instsrchon = ' ';
2839: my $instsrchoff = ' checked="checked" ';
2840: my ($exacton,$containson,$beginson);
2841: my $instlocalon = ' ';
2842: my $instlocaloff = ' checked="checked" ';
2843: if (ref($settings) eq 'HASH') {
2844: if ($settings->{'available'} eq '1') {
2845: $instsrchon = $instsrchoff;
2846: $instsrchoff = ' ';
2847: }
2848: if ($settings->{'localonly'} eq '1') {
2849: $instlocalon = $instlocaloff;
2850: $instlocaloff = ' ';
2851: }
2852: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2853: foreach my $type (@{$settings->{'searchtypes'}}) {
2854: if ($type eq 'exact') {
2855: $exacton = ' checked="checked" ';
2856: } elsif ($type eq 'contains') {
2857: $containson = ' checked="checked" ';
2858: } elsif ($type eq 'begins') {
2859: $beginson = ' checked="checked" ';
2860: }
2861: }
2862: } else {
2863: if ($settings->{'searchtypes'} eq 'exact') {
2864: $exacton = ' checked="checked" ';
2865: } elsif ($settings->{'searchtypes'} eq 'contains') {
2866: $containson = ' checked="checked" ';
2867: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2868: $exacton = ' checked="checked" ';
2869: $containson = ' checked="checked" ';
2870: }
2871: }
1.277 raeburn 2872: }
2873: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2874: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2875:
2876: my $numinrow = 4;
2877: my $cansrchrow = 0;
2878: $datatable='<tr class="LC_odd_row">'.
2879: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2880: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2881: '<input type="radio" name="dirsrch_available"'.
2882: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2883: '<label><input type="radio" name="dirsrch_available"'.
2884: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2885: '</tr><tr>'.
2886: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2887: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2888: '<input type="radio" name="dirsrch_instlocalonly"'.
2889: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2890: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2891: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2892: '</tr>';
2893: $$rowtotal += 2;
2894: if (ref($usertypes) eq 'HASH') {
2895: if (keys(%{$usertypes}) > 0) {
2896: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2897: $numinrow,$othertitle,'cansearch');
2898: $cansrchrow = 1;
1.25 raeburn 2899: }
1.23 raeburn 2900: }
1.277 raeburn 2901: if ($cansrchrow) {
2902: $$rowtotal ++;
2903: $datatable .= '<tr>';
2904: } else {
2905: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 2906: }
1.277 raeburn 2907: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2908: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2909: foreach my $title (@{$titleorder}) {
2910: if (defined($searchtitles->{$title})) {
2911: my $check = ' ';
2912: if (ref($settings) eq 'HASH') {
2913: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2914: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2915: $check = ' checked="checked" ';
2916: }
1.39 raeburn 2917: }
1.25 raeburn 2918: }
1.277 raeburn 2919: $datatable .= '<td class="LC_left_item">'.
2920: '<span class="LC_nobreak"><label>'.
2921: '<input type="checkbox" name="searchby" '.
2922: 'value="'.$title.'"'.$check.'/>'.
2923: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2924: }
2925: }
1.277 raeburn 2926: $datatable .= '</tr></table></td></tr>';
2927: $$rowtotal ++;
2928: if ($cansrchrow) {
2929: $datatable .= '<tr class="LC_odd_row">';
2930: } else {
2931: $datatable .= '<tr>';
2932: }
2933: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2934: '<td class="LC_left_item" colspan="2">'.
2935: '<span class="LC_nobreak"><label>'.
2936: '<input type="checkbox" name="searchtypes" '.
2937: $exacton.' value="exact" />'.&mt('Exact match').
2938: '</label> '.
2939: '<label><input type="checkbox" name="searchtypes" '.
2940: $beginson.' value="begins" />'.&mt('Begins with').
2941: '</label> '.
2942: '<label><input type="checkbox" name="searchtypes" '.
2943: $containson.' value="contains" />'.&mt('Contains').
2944: '</label></span></td></tr>';
2945: $$rowtotal ++;
1.26 raeburn 2946: } else {
1.277 raeburn 2947: my $domsrchon = ' checked="checked" ';
2948: my $domsrchoff = ' ';
2949: my $domlocalon = ' ';
2950: my $domlocaloff = ' checked="checked" ';
2951: if (ref($settings) eq 'HASH') {
2952: if ($settings->{'lclocalonly'} eq '1') {
2953: $domlocalon = $domlocaloff;
2954: $domlocaloff = ' ';
2955: }
2956: if ($settings->{'lcavailable'} eq '0') {
2957: $domsrchoff = $domsrchon;
2958: $domsrchon = ' ';
2959: }
2960: }
2961: $datatable='<tr class="LC_odd_row">'.
2962: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2963: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2964: '<input type="radio" name="dirsrch_domavailable"'.
2965: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2966: '<label><input type="radio" name="dirsrch_domavailable"'.
2967: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2968: '</tr><tr>'.
2969: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2970: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2971: '<input type="radio" name="dirsrch_domlocalonly"'.
2972: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2973: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2974: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2975: '</tr>';
2976: $$rowtotal += 2;
1.26 raeburn 2977: }
1.25 raeburn 2978: return $datatable;
2979: }
2980:
1.28 raeburn 2981: sub print_contacts {
1.286 raeburn 2982: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2983: my $datatable;
2984: my @contacts = ('adminemail','supportemail');
1.286 raeburn 2985: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2986: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2987: if ($position eq 'top') {
2988: if (ref($settings) eq 'HASH') {
2989: foreach my $item (@contacts) {
2990: if (exists($settings->{$item})) {
2991: $to{$item} = $settings->{$item};
2992: }
2993: }
2994: }
2995: } elsif ($position eq 'middle') {
2996: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
2997: 'updatesmail','idconflictsmail');
1.288 raeburn 2998: foreach my $type (@mailings) {
2999: $otheremails{$type} = '';
3000: }
1.286 raeburn 3001: } else {
3002: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 3003: foreach my $type (@mailings) {
3004: $otheremails{$type} = '';
3005: }
1.286 raeburn 3006: $bccemails{'helpdeskmail'} = '';
3007: $bccemails{'otherdomsmail'} = '';
3008: $includestr{'helpdeskmail'} = '';
3009: $includestr{'otherdomsmail'} = '';
3010: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3011: }
1.28 raeburn 3012: if (ref($settings) eq 'HASH') {
1.286 raeburn 3013: unless ($position eq 'top') {
3014: foreach my $type (@mailings) {
3015: if (exists($settings->{$type})) {
3016: if (ref($settings->{$type}) eq 'HASH') {
3017: foreach my $item (@contacts) {
3018: if ($settings->{$type}{$item}) {
3019: $checked{$type}{$item} = ' checked="checked" ';
3020: }
3021: }
3022: $otheremails{$type} = $settings->{$type}{'others'};
3023: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3024: $bccemails{$type} = $settings->{$type}{'bcc'};
3025: if ($settings->{$type}{'include'} ne '') {
3026: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3027: $includestr{$type} = &unescape($includestr{$type});
3028: }
3029: }
3030: }
3031: } elsif ($type eq 'lonstatusmail') {
3032: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3033: }
1.28 raeburn 3034: }
3035: }
1.286 raeburn 3036: if ($position eq 'bottom') {
3037: foreach my $type (@mailings) {
3038: $bccemails{$type} = $settings->{$type}{'bcc'};
3039: if ($settings->{$type}{'include'} ne '') {
3040: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3041: $includestr{$type} = &unescape($includestr{$type});
3042: }
3043: }
3044: if (ref($settings->{'helpform'}) eq 'HASH') {
3045: if (ref($fields) eq 'ARRAY') {
3046: foreach my $field (@{$fields}) {
3047: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3048: }
1.286 raeburn 3049: }
3050: if (exists($settings->{'helpform'}{'maxsize'})) {
3051: $maxsize = $settings->{'helpform'}{'maxsize'};
3052: } else {
1.289 raeburn 3053: $maxsize = '1.0';
1.286 raeburn 3054: }
3055: } else {
3056: if (ref($fields) eq 'ARRAY') {
3057: foreach my $field (@{$fields}) {
3058: $currfield{$field} = 'yes';
1.134 raeburn 3059: }
1.28 raeburn 3060: }
1.286 raeburn 3061: $maxsize = '1.0';
1.28 raeburn 3062: }
3063: }
3064: } else {
1.286 raeburn 3065: if ($position eq 'top') {
3066: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3067: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3068: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3069: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 3070: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 3071: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3072: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3073: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
3074: } elsif ($position eq 'bottom') {
3075: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3076: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3077: if (ref($fields) eq 'ARRAY') {
3078: foreach my $field (@{$fields}) {
3079: $currfield{$field} = 'yes';
3080: }
3081: }
3082: $maxsize = '1.0';
3083: }
1.28 raeburn 3084: }
3085: my ($titles,$short_titles) = &contact_titles();
3086: my $rownum = 0;
3087: my $css_class;
1.286 raeburn 3088: if ($position eq 'top') {
3089: foreach my $item (@contacts) {
3090: $css_class = $rownum%2?' class="LC_odd_row"':'';
3091: $datatable .= '<tr'.$css_class.'>'.
3092: '<td><span class="LC_nobreak">'.$titles->{$item}.
3093: '</span></td><td class="LC_right_item">'.
3094: '<input type="text" name="'.$item.'" value="'.
3095: $to{$item}.'" /></td></tr>';
3096: $rownum ++;
3097: }
3098: } else {
3099: foreach my $type (@mailings) {
3100: $css_class = $rownum%2?' class="LC_odd_row"':'';
3101: $datatable .= '<tr'.$css_class.'>'.
3102: '<td><span class="LC_nobreak">'.
3103: $titles->{$type}.': </span></td>'.
3104: '<td class="LC_left_item">';
3105: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3106: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
3107: }
3108: $datatable .= '<span class="LC_nobreak">';
3109: foreach my $item (@contacts) {
3110: $datatable .= '<label>'.
3111: '<input type="checkbox" name="'.$type.'"'.
3112: $checked{$type}{$item}.
3113: ' value="'.$item.'" />'.$short_titles->{$item}.
3114: '</label> ';
3115: }
3116: $datatable .= '</span><br />'.&mt('Others').': '.
3117: '<input type="text" name="'.$type.'_others" '.
3118: 'value="'.$otheremails{$type}.'" />';
3119: my %locchecked;
3120: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3121: foreach my $loc ('s','b') {
3122: if ($includeloc{$type} eq $loc) {
3123: $locchecked{$loc} = ' checked="checked"';
3124: last;
3125: }
3126: }
3127: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
3128: '<input type="text" name="'.$type.'_bcc" '.
3129: 'value="'.$bccemails{$type}.'" /></fieldset>'.
3130: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
3131: &mt('Text automatically added to e-mail:').' '.
3132: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
3133: '<span class="LC_nobreak">'.&mt('Location:').' '.
3134: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
3135: (' 'x2).
3136: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
3137: '</span></fieldset>';
3138: }
3139: $datatable .= '</td></tr>'."\n";
3140: $rownum ++;
3141: }
1.28 raeburn 3142: }
1.286 raeburn 3143: if ($position eq 'middle') {
3144: my %choices;
3145: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
1.289 raeburn 3146: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3147: &mt('LON-CAPA core group - MSU'),600,500));
1.286 raeburn 3148: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
3149: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
3150: &mt('LON-CAPA core group - MSU'),600,500));
3151: my @toggles = ('reporterrors','reportupdates');
3152: my %defaultchecked = ('reporterrors' => 'on',
3153: 'reportupdates' => 'on');
3154: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3155: \%choices,$rownum);
3156: $datatable .= $reports;
3157: } elsif ($position eq 'bottom') {
1.69 raeburn 3158: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 3159: $datatable .= '<tr'.$css_class.'>'.
1.286 raeburn 3160: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3161: &mt('(e-mail, subject, and description always shown)').
3162: '</td><td class="LC_left_item">';
1.289 raeburn 3163: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
1.286 raeburn 3164: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3165: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3166: foreach my $field (@{$fields}) {
3167: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3168: if (($field eq 'screenshot') || ($field eq 'cc')) {
3169: $datatable .= ' '.&mt('(logged-in users)');
3170: }
3171: $datatable .='</td><td>';
3172: my $clickaction;
3173: if ($field eq 'screenshot') {
3174: $clickaction = ' onclick="screenshotSize(this);"';
3175: }
3176: if (ref($possoptions->{$field}) eq 'ARRAY') {
3177: foreach my $option (@{$possoptions->{$field}}) {
3178: my $checked;
3179: if ($currfield{$field} eq $option) {
3180: $checked = ' checked="checked"';
3181: }
3182: $datatable .= '<span class="LC_nobreak"><label>'.
3183: '<input type="radio" name="helpform_'.$field.'" '.
3184: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3185: '</label></span>'.(' 'x2);
3186: }
3187: }
3188: if ($field eq 'screenshot') {
3189: my $display;
3190: if ($currfield{$field} eq 'no') {
3191: $display = ' style="display:none"';
3192: }
3193: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3194: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3195: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3196: }
3197: $datatable .= '</td></tr>';
3198: }
3199: $datatable .= '</table>';
1.134 raeburn 3200: }
3201: $datatable .= '</td></tr>'."\n";
1.203 raeburn 3202: $rownum ++;
1.28 raeburn 3203: }
1.30 raeburn 3204: $$rowtotal += $rownum;
1.28 raeburn 3205: return $datatable;
3206: }
3207:
1.286 raeburn 3208: sub contacts_javascript {
3209: return <<"ENDSCRIPT";
3210:
3211: <script type="text/javascript">
3212: // <![CDATA[
3213:
3214: function screenshotSize(field) {
3215: if (document.getElementById('help_screenshotsize')) {
3216: if (field.value == 'no') {
1.289 raeburn 3217: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 3218: } else {
3219: document.getElementById('help_screenshotsize').style.display="";
3220: }
3221: }
3222: return;
3223: }
3224:
3225: // ]]>
3226: </script>
3227:
3228: ENDSCRIPT
3229: }
3230:
1.118 jms 3231: sub print_helpsettings {
1.282 raeburn 3232: my ($position,$dom,$settings,$rowtotal) = @_;
3233: my $confname = $dom.'-domainconfig';
1.285 raeburn 3234: my $formname = 'display';
1.168 raeburn 3235: my ($datatable,$itemcount);
1.282 raeburn 3236: if ($position eq 'top') {
3237: $itemcount = 1;
3238: my (%choices,%defaultchecked,@toggles);
3239: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3240: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3241: &mt('LON-CAPA bug tracker'),600,500));
3242: %defaultchecked = ('submitbugs' => 'on');
3243: @toggles = ('submitbugs');
3244: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3245: \%choices,$itemcount);
3246: $$rowtotal ++;
3247: } else {
3248: my $css_class;
3249: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 3250: my (%customroles,%ordered,%current);
3251: if (ref($settings->{'adhoc'}) eq 'HASH') {
3252: %current = %{$settings->{'adhoc'}};
3253: }
3254: my $count = 0;
3255: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 3256: if ($key=~/^rolesdef\_(\w+)$/) {
3257: my $rolename = $1;
1.285 raeburn 3258: my (%privs,$order);
1.282 raeburn 3259: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3260: $customroles{$rolename} = \%privs;
1.285 raeburn 3261: if (ref($current{$rolename}) eq 'HASH') {
3262: $order = $current{$rolename}{'order'};
3263: }
3264: if ($order eq '') {
3265: $order = $count;
3266: }
3267: $ordered{$order} = $rolename;
3268: $count++;
3269: }
3270: }
3271: my $maxnum = scalar(keys(%ordered));
3272: my @roles_by_num = ();
3273: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3274: push(@roles_by_num,$item);
3275: }
3276: my $context = 'domprefs';
3277: my $crstype = 'Course';
3278: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 3279: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 3280: my ($numstatustypes,@jsarray);
3281: if (ref($types) eq 'ARRAY') {
3282: if (@{$types} > 0) {
3283: $numstatustypes = scalar(@{$types});
3284: push(@accesstypes,'status');
3285: @jsarray = ('bystatus');
1.282 raeburn 3286: }
3287: }
1.290 raeburn 3288: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 3289: if (keys(%domhelpdesk)) {
3290: push(@accesstypes,('inc','exc'));
3291: push(@jsarray,('notinc','notexc'));
3292: }
3293: my $hiddenstr = join("','",@jsarray);
3294: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.282 raeburn 3295: my $context = 'domprefs';
3296: my $crstype = 'Course';
1.285 raeburn 3297: my $prefix = 'helproles_';
3298: my $add_class = 'LC_hidden';
3299: foreach my $num (@roles_by_num) {
3300: my $role = $ordered{$num};
3301: my ($desc,$access,@statuses);
3302: if (ref($current{$role}) eq 'HASH') {
3303: $desc = $current{$role}{'desc'};
3304: $access = $current{$role}{'access'};
3305: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3306: @statuses = @{$current{$role}{'insttypes'}};
3307: }
3308: }
3309: if ($desc eq '') {
3310: $desc = $role;
3311: }
3312: my $identifier = 'custhelp'.$num;
1.282 raeburn 3313: my %full=();
3314: my %levels= (
3315: course => {},
3316: domain => {},
3317: system => {},
3318: );
3319: my %levelscurrent=(
3320: course => {},
3321: domain => {},
3322: system => {},
3323: );
3324: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3325: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3326: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 3327: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3328: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3329: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3330: for (my $k=0; $k<=$maxnum; $k++) {
3331: my $vpos = $k+1;
3332: my $selstr;
3333: if ($k == $num) {
3334: $selstr = ' selected="selected" ';
3335: }
3336: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3337: }
3338: $datatable .= '</select>'.(' 'x2).
3339: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3340: '</td>'.
3341: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3342: &mt('Name shown to users:').
3343: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3344: '</fieldset>'.
3345: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3346: $othertitle,$usertypes,$types,\%domhelpdesk).
3347: '<fieldset>'.
3348: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 3349: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 3350: \%levelscurrent,$identifier,
3351: 'LC_hidden',$prefix.$num.'_privs').
3352: '</fieldset></td>';
1.282 raeburn 3353: $itemcount ++;
3354: }
3355: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3356: my $newcust = 'custhelp'.$count;
3357: my (%privs,%levelscurrent);
3358: my %full=();
3359: my %levels= (
3360: course => {},
3361: domain => {},
3362: system => {},
3363: );
3364: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3365: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 3366: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3367: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3368: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3369: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3370: for (my $k=0; $k<$maxnum+1; $k++) {
3371: my $vpos = $k+1;
3372: my $selstr;
3373: if ($k == $maxnum) {
3374: $selstr = ' selected="selected" ';
3375: }
3376: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3377: }
3378: $datatable .= '</select> '."\n".
1.282 raeburn 3379: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3380: '</label></span></td>'.
1.285 raeburn 3381: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3382: '<span class="LC_nobreak">'.
3383: &mt('Internal name:').
3384: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3385: '</span>'.(' 'x4).
3386: '<span class="LC_nobreak">'.
3387: &mt('Name shown to users:').
3388: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3389: '</span></fieldset>'.
3390: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3391: $usertypes,$types,\%domhelpdesk).
3392: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 3393: &Apache::lonuserutils::custom_role_header($context,$crstype,
3394: \@templateroles,$newcust).
3395: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3396: \%levelscurrent,$newcust).
1.285 raeburn 3397: '</fieldset></td></tr>';
1.282 raeburn 3398: $count ++;
3399: $$rowtotal += $count;
3400: }
1.166 raeburn 3401: return $datatable;
1.121 raeburn 3402: }
3403:
1.285 raeburn 3404: sub adhocbutton {
3405: my ($prefix,$num,$field,$visibility) = @_;
3406: my %lt = &Apache::lonlocal::texthash(
3407: show => 'Show details',
3408: hide => 'Hide details',
3409: );
3410: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3411: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3412: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3413: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3414: }
3415:
3416: sub helpsettings_javascript {
3417: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3418: return unless(ref($roles_by_num) eq 'ARRAY');
3419: my %html_js_lt = &Apache::lonlocal::texthash(
3420: show => 'Show details',
3421: hide => 'Hide details',
3422: );
3423: &html_escape(\%html_js_lt);
3424: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3425: return <<"ENDSCRIPT";
3426: <script type="text/javascript">
3427: // <![CDATA[
3428:
3429: function reorderHelpRoles(form,item) {
3430: var changedVal;
3431: $jstext
3432: var newpos = 'helproles_${total}_pos';
3433: var maxh = 1 + $total;
3434: var current = new Array();
3435: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3436: if (item == newpos) {
3437: changedVal = newitemVal;
3438: } else {
3439: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3440: current[newitemVal] = newpos;
3441: }
3442: for (var i=0; i<helproles.length; i++) {
3443: var elementName = 'helproles_'+helproles[i]+'_pos';
3444: if (elementName != item) {
3445: if (form.elements[elementName]) {
3446: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3447: current[currVal] = elementName;
3448: }
3449: }
3450: }
3451: var oldVal;
3452: for (var j=0; j<maxh; j++) {
3453: if (current[j] == undefined) {
3454: oldVal = j;
3455: }
3456: }
3457: if (oldVal < changedVal) {
3458: for (var k=oldVal+1; k<=changedVal ; k++) {
3459: var elementName = current[k];
3460: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3461: }
3462: } else {
3463: for (var k=changedVal; k<oldVal; k++) {
3464: var elementName = current[k];
3465: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3466: }
3467: }
3468: return;
3469: }
3470:
3471: function helpdeskAccess(num) {
3472: var curraccess = null;
3473: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3474: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3475: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3476: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3477: }
3478: }
3479: }
3480: var shown = Array();
3481: var hidden = Array();
3482: if (curraccess == 'none') {
3483: hidden = Array('$hiddenstr');
3484: } else {
3485: if (curraccess == 'status') {
3486: shown = Array('bystatus');
3487: hidden = Array('notinc','notexc');
3488: } else {
3489: if (curraccess == 'exc') {
3490: shown = Array('notexc');
3491: hidden = Array('notinc','bystatus');
3492: }
3493: if (curraccess == 'inc') {
3494: shown = Array('notinc');
3495: hidden = Array('notexc','bystatus');
3496: }
1.293 raeburn 3497: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 3498: hidden = Array('notinc','notexc','bystatus');
3499: }
3500: }
3501: }
3502: if (hidden.length > 0) {
3503: for (var i=0; i<hidden.length; i++) {
3504: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3505: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3506: }
3507: }
3508: }
3509: if (shown.length > 0) {
3510: for (var i=0; i<shown.length; i++) {
3511: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3512: if (shown[i] == 'privs') {
3513: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3514: } else {
3515: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3516: }
3517: }
3518: }
3519: }
3520: return;
3521: }
3522:
3523: function toggleHelpdeskItem(num,field) {
3524: if (document.getElementById('helproles_'+num+'_'+field)) {
3525: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 3526: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 3527: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3528: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3529: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3530: }
3531: } else {
3532: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3533: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3534: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3535: }
3536: }
3537: }
3538: return;
3539: }
3540:
3541: // ]]>
3542: </script>
3543:
3544: ENDSCRIPT
3545: }
3546:
3547: sub helpdeskroles_access {
3548: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3549: $usertypes,$types,$domhelpdesk) = @_;
3550: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3551: my %lt = &Apache::lonlocal::texthash(
3552: 'rou' => 'Role usage',
3553: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 3554: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3555: 'dh' => 'All with domain helpdesk role',
3556: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 3557: 'none' => 'None',
3558: 'status' => 'Determined based on institutional status',
3559: 'inc' => 'Include all, but exclude specific personnel',
3560: 'exc' => 'Exclude all, but include specific personnel',
3561: );
3562: my %usecheck = (
3563: all => ' checked="checked"',
3564: );
3565: my %displaydiv = (
3566: status => 'none',
3567: inc => 'none',
3568: exc => 'none',
3569: priv => 'block',
3570: );
3571: my $output;
3572: if (ref($current) eq 'HASH') {
3573: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3574: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3575: $usecheck{$current->{access}} = $usecheck{'all'};
3576: delete($usecheck{'all'});
3577: if ($current->{access} =~ /^(status|inc|exc)$/) {
3578: my $access = $1;
3579: $displaydiv{$access} = 'inline';
3580: } elsif ($current->{access} eq 'none') {
3581: $displaydiv{'priv'} = 'none';
3582: }
3583: }
3584: }
3585: }
3586: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3587: '<p>'.$lt{'whi'}.'</p>';
3588: foreach my $access (@{$accesstypes}) {
3589: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3590: ' onclick="helpdeskAccess('."'$num'".');" />'.
3591: $lt{$access}.'</label>';
3592: if ($access eq 'status') {
3593: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3594: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3595: $othertitle,$usertypes,$types).
3596: '</div>';
3597: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3598: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3599: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3600: '</div>';
3601: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3602: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3603: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3604: '</div>';
3605: }
3606: $output .= '</p>';
3607: }
3608: $output .= '</fieldset>';
3609: return $output;
3610: }
3611:
1.121 raeburn 3612: sub radiobutton_prefs {
1.192 raeburn 3613: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257 raeburn 3614: $additional,$align) = @_;
1.121 raeburn 3615: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3616: (ref($choices) eq 'HASH'));
3617:
1.170 raeburn 3618: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 3619:
3620: foreach my $item (@{$toggles}) {
3621: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3622: $checkedon{$item} = ' checked="checked" ';
3623: $checkedoff{$item} = ' ';
1.121 raeburn 3624: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3625: $checkedoff{$item} = ' checked="checked" ';
3626: $checkedon{$item} = ' ';
3627: }
3628: }
3629: if (ref($settings) eq 'HASH') {
1.121 raeburn 3630: foreach my $item (@{$toggles}) {
1.118 jms 3631: if ($settings->{$item} eq '1') {
3632: $checkedon{$item} = ' checked="checked" ';
3633: $checkedoff{$item} = ' ';
3634: } elsif ($settings->{$item} eq '0') {
3635: $checkedoff{$item} = ' checked="checked" ';
3636: $checkedon{$item} = ' ';
3637: }
3638: }
1.121 raeburn 3639: }
1.192 raeburn 3640: if ($onclick) {
3641: $onclick = ' onclick="'.$onclick.'"';
3642: }
1.121 raeburn 3643: foreach my $item (@{$toggles}) {
1.118 jms 3644: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3645: $datatable .=
1.192 raeburn 3646: '<tr'.$css_class.'><td valign="top">'.
3647: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 3648: '</span></td>';
3649: if ($align eq 'left') {
3650: $datatable .= '<td class="LC_left_item">';
3651: } else {
3652: $datatable .= '<td class="LC_right_item">';
3653: }
1.289 raeburn 3654: $datatable .=
1.257 raeburn 3655: '<span class="LC_nobreak">'.
1.118 jms 3656: '<label><input type="radio" name="'.
1.192 raeburn 3657: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3658: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 3659: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3660: '</span>'.$additional.
3661: '</td>'.
1.118 jms 3662: '</tr>';
3663: $itemcount ++;
1.121 raeburn 3664: }
3665: return ($datatable,$itemcount);
3666: }
3667:
1.267 raeburn 3668: sub print_ltitools {
3669: my ($dom,$settings,$rowtotal) = @_;
3670: my $rownum = 0;
3671: my $css_class;
3672: my $itemcount = 1;
3673: my $maxnum = 0;
3674: my %ordered;
3675: if (ref($settings) eq 'HASH') {
3676: foreach my $item (keys(%{$settings})) {
3677: if (ref($settings->{$item}) eq 'HASH') {
3678: my $num = $settings->{$item}{'order'};
3679: $ordered{$num} = $item;
3680: }
3681: }
3682: }
3683: my $confname = $dom.'-domainconfig';
3684: my $switchserver = &check_switchserver($dom,$confname);
3685: my $maxnum = scalar(keys(%ordered));
3686: my $datatable = <itools_javascript($settings);
3687: my %lt = <itools_names();
3688: my @courseroles = ('cc','in','ta','ep','st');
3689: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
3690: my @fields = ('fullname','firstname','lastname','email','user','roles');
3691: if (keys(%ordered)) {
3692: my @items = sort { $a <=> $b } keys(%ordered);
3693: for (my $i=0; $i<@items; $i++) {
3694: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3695: my $item = $ordered{$items[$i]};
3696: my ($title,$key,$secret,$url,$imgsrc,$version);
3697: if (ref($settings->{$item}) eq 'HASH') {
3698: $title = $settings->{$item}->{'title'};
3699: $url = $settings->{$item}->{'url'};
3700: $key = $settings->{$item}->{'key'};
3701: $secret = $settings->{$item}->{'secret'};
3702: my $image = $settings->{$item}->{'image'};
3703: if ($image ne '') {
3704: $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
3705: }
3706: }
3707: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
3708: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3709: .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
3710: for (my $k=0; $k<=$maxnum; $k++) {
3711: my $vpos = $k+1;
3712: my $selstr;
3713: if ($k == $i) {
3714: $selstr = ' selected="selected" ';
3715: }
3716: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3717: }
3718: $datatable .= '</select>'.(' 'x2).
3719: '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
3720: &mt('Delete?').'</label></span></td>'.
3721: '<td colspan="2">'.
3722: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3723: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
3724: (' 'x2).
3725: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
3726: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
3727: (' 'x2).
3728: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
3729: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3730: '<br /><br />'.
3731: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
3732: ' value="'.$url.'" /></span>'.
3733: (' 'x2).
3734: '<span class="LC_nobreak">'.$lt{'key'}.
3735: '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
3736: (' 'x2).
3737: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
3738: '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
3739: '<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>'.
3740: '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
3741: '</fieldset>'.
3742: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3743: '<span class="LC_nobreak">'.&mt('Display target:');
3744: my %currdisp;
3745: if (ref($settings->{$item}->{'display'}) eq 'HASH') {
3746: if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
3747: $currdisp{'window'} = ' checked="checked"';
3748: } else {
3749: $currdisp{'iframe'} = ' checked="checked"';
3750: }
3751: if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
3752: $currdisp{'width'} = $1;
3753: }
3754: if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
3755: $currdisp{'height'} = $1;
3756: }
3757: } else {
3758: $currdisp{'iframe'} = ' checked="checked"';
3759: }
3760: foreach my $disp ('iframe','window') {
3761: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3762: $lt{$disp}.'</label>'.(' 'x2);
3763: }
3764: $datatable .= (' 'x4);
3765: foreach my $dimen ('width','height') {
3766: $datatable .= '<label>'.$lt{$dimen}.' '.
3767: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3768: (' 'x2);
3769: }
3770: $datatable .= '<br />';
3771: foreach my $extra ('passback','roster') {
3772: my $checkedon = '';
3773: my $checkedoff = ' checked="checked"';
3774: if ($settings->{$item}->{$extra}) {
3775: $checkedon = $checkedoff;
3776: $checkedoff = '';
3777: }
3778: $datatable .= $lt{$extra}.' '.
3779: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3780: &mt('Yes').'</label>'.(' 'x2).
3781: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3782: &mt('No').'</label>'.(' 'x4);
3783: }
3784: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3785: if ($imgsrc) {
3786: $datatable .= $imgsrc.
3787: '<label><input type="checkbox" name="ltitools_image_del"'.
3788: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3789: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3790: } else {
3791: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3792: }
3793: if ($switchserver) {
3794: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3795: } else {
3796: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3797: }
3798: $datatable .= '</span></fieldset>';
3799: my (%checkedfields,%rolemaps);
3800: if (ref($settings->{$item}) eq 'HASH') {
3801: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3802: %checkedfields = %{$settings->{$item}->{'fields'}};
3803: }
3804: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3805: %rolemaps = %{$settings->{$item}->{'roles'}};
3806: $checkedfields{'roles'} = 1;
3807: }
3808: }
3809: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3810: '<span class="LC_nobreak">';
3811: foreach my $field (@fields) {
3812: my $checked;
3813: if ($checkedfields{$field}) {
3814: $checked = ' checked="checked"';
3815: }
3816: $datatable .= '<label>'.
3817: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3818: $lt{$field}.'</label>'.(' ' x2);
3819: }
3820: $datatable .= '</span></fieldset>'.
3821: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3822: foreach my $role (@courseroles) {
3823: my ($selected,$selectnone);
3824: if (!$rolemaps{$role}) {
3825: $selectnone = ' selected="selected"';
3826: }
3827: $datatable .= '<td align="center">'.
3828: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3829: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3830: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3831: foreach my $ltirole (@ltiroles) {
3832: unless ($selectnone) {
3833: if ($rolemaps{$role} eq $ltirole) {
3834: $selected = ' selected="selected"';
3835: } else {
3836: $selected = '';
3837: }
3838: }
3839: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3840: }
3841: $datatable .= '</select></td>';
3842: }
1.273 raeburn 3843: $datatable .= '</tr></table></fieldset>';
3844: my %courseconfig;
3845: if (ref($settings->{$item}) eq 'HASH') {
3846: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3847: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3848: }
3849: }
3850: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3851: foreach my $item ('label','title','target') {
3852: my $checked;
3853: if ($courseconfig{$item}) {
3854: $checked = ' checked="checked"';
3855: }
3856: $datatable .= '<label>'.
3857: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3858: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3859: }
3860: $datatable .= '</span></fieldset>'.
1.267 raeburn 3861: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3862: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3863: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3864: my %custom = %{$settings->{$item}->{'custom'}};
3865: if (keys(%custom) > 0) {
3866: foreach my $key (sort(keys(%custom))) {
3867: $datatable .= '<tr><td><span class="LC_nobreak">'.
3868: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3869: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3870: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3871: ' value="'.$custom{$key}.'" /></td></tr>';
3872: }
3873: }
3874: }
3875: $datatable .= '<tr><td><span class="LC_nobreak">'.
3876: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3877: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3878: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3879: $datatable .= '</table></fieldset></td></tr>'."\n";
3880: $itemcount ++;
3881: }
3882: }
3883: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3884: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3885: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3886: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3887: '<select name="ltitools_add_pos"'.$chgstr.'>';
3888: for (my $k=0; $k<$maxnum+1; $k++) {
3889: my $vpos = $k+1;
3890: my $selstr;
3891: if ($k == $maxnum) {
3892: $selstr = ' selected="selected" ';
3893: }
3894: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3895: }
3896: $datatable .= '</select> '."\n".
3897: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3898: '<td colspan="2">'.
3899: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3900: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3901: (' 'x2).
3902: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3903: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3904: (' 'x2).
3905: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3906: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3907: '<br />'.
3908: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3909: (' 'x2).
3910: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3911: (' 'x2).
3912: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3913: '<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".
3914: '</fieldset>'.
3915: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3916: '<span class="LC_nobreak">'.&mt('Display target:');
3917: my %defaultdisp;
3918: $defaultdisp{'iframe'} = ' checked="checked"';
3919: foreach my $disp ('iframe','window') {
3920: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3921: $lt{$disp}.'</label>'.(' 'x2);
3922: }
3923: $datatable .= (' 'x4);
3924: foreach my $dimen ('width','height') {
3925: $datatable .= '<label>'.$lt{$dimen}.' '.
3926: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3927: (' 'x2);
3928: }
3929: $datatable .= '<br />';
3930: foreach my $extra ('passback','roster') {
3931: $datatable .= $lt{$extra}.' '.
3932: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3933: &mt('Yes').'</label>'.(' 'x2).
3934: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3935: &mt('No').'</label>'.(' 'x4);
3936: }
3937: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3938: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3939: if ($switchserver) {
3940: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3941: } else {
3942: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3943: }
3944: $datatable .= '</span></fieldset>'.
3945: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3946: '<span class="LC_nobreak">';
3947: foreach my $field (@fields) {
3948: $datatable .= '<label>'.
3949: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3950: $lt{$field}.'</label>'.(' ' x2);
3951: }
3952: $datatable .= '</span></fieldset>'.
3953: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3954: foreach my $role (@courseroles) {
3955: my ($checked,$checkednone);
3956: $datatable .= '<td align="center">'.
3957: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3958: '<select name="ltitools_add_roles_'.$role.'">'.
3959: '<option value="" selected="selected">'.&mt('Select').'</option>';
3960: foreach my $ltirole (@ltiroles) {
3961: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3962: }
3963: $datatable .= '</select></td>';
3964: }
3965: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3966: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
3967: foreach my $item ('label','title','target') {
3968: $datatable .= '<label>'.
3969: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
3970: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3971: }
3972: $datatable .= '</span></fieldset>'.
1.267 raeburn 3973: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3974: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3975: '<tr><td><span class="LC_nobreak">'.
3976: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3977: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3978: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3979: '</table></fieldset></td></tr>'."\n".
3980: '</td>'."\n".
3981: '</tr>'."\n";
3982: $itemcount ++;
3983: return $datatable;
3984: }
3985:
3986: sub ltitools_names {
3987: my %lt = &Apache::lonlocal::texthash(
3988: 'title' => 'Title',
3989: 'version' => 'Version',
3990: 'msgtype' => 'Message Type',
3991: 'url' => 'URL',
3992: 'key' => 'Key',
3993: 'secret' => 'Secret',
3994: 'icon' => 'Icon',
3995: 'user' => 'Username:domain',
3996: 'fullname' => 'Full Name',
3997: 'firstname' => 'First Name',
3998: 'lastname' => 'Last Name',
3999: 'email' => 'E-mail',
4000: 'roles' => 'Role',
4001: 'window' => 'Window/Tab',
4002: 'iframe' => 'iFrame',
4003: 'height' => 'Height',
4004: 'width' => 'Width',
4005: 'passback' => 'Tool can return grades:',
4006: 'roster' => 'Tool can retrieve roster:',
1.273 raeburn 4007: 'crstarget' => 'Display target',
4008: 'crslabel' => 'Course label',
4009: 'crstitle' => 'Course title',
1.267 raeburn 4010: );
4011: return %lt;
4012: }
4013:
1.121 raeburn 4014: sub print_coursedefaults {
1.139 raeburn 4015: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 4016: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4017: my $itemcount = 1;
1.192 raeburn 4018: my %choices = &Apache::lonlocal::texthash (
4019: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 4020: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 4021: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4022: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 4023: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4024: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4025: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4026: canclone => "People who may clone a course (besides course's owner and coordinators)",
4027: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4028: );
1.198 raeburn 4029: my %staticdefaults = (
4030: anonsurvey_threshold => 10,
4031: uploadquota => 500,
1.257 raeburn 4032: postsubmit => 60,
1.276 raeburn 4033: mysqltables => 172800,
1.198 raeburn 4034: );
1.139 raeburn 4035: if ($position eq 'top') {
1.257 raeburn 4036: %defaultchecked = (
4037: 'canuse_pdfforms' => 'off',
4038: 'uselcmath' => 'on',
4039: 'usejsme' => 'on',
1.289 raeburn 4040: 'canclone' => 'none',
1.257 raeburn 4041: );
4042: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 4043: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4044: \%choices,$itemcount);
1.264 raeburn 4045: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4046: $datatable .=
4047: '<tr'.$css_class.'><td valign="top">'.
4048: '<span class="LC_nobreak">'.$choices{'canclone'}.
4049: '</span></td><td class="LC_left_item">';
4050: my $currcanclone = 'none';
4051: my $onclick;
4052: my @cloneoptions = ('none','domain');
4053: my %clonetitles = (
4054: none => 'No additional course requesters',
4055: domain => "Any course requester in course's domain",
4056: instcode => 'Course requests for official courses ...',
4057: );
4058: my (%codedefaults,@code_order,@posscodes);
4059: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4060: \@code_order) eq 'ok') {
4061: if (@code_order > 0) {
4062: push(@cloneoptions,'instcode');
4063: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4064: }
4065: }
4066: if (ref($settings) eq 'HASH') {
4067: if ($settings->{'canclone'}) {
4068: if (ref($settings->{'canclone'}) eq 'HASH') {
4069: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4070: if (@code_order > 0) {
4071: $currcanclone = 'instcode';
4072: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4073: }
4074: }
4075: } elsif ($settings->{'canclone'} eq 'domain') {
4076: $currcanclone = $settings->{'canclone'};
4077: }
4078: }
1.289 raeburn 4079: }
1.264 raeburn 4080: foreach my $option (@cloneoptions) {
4081: my ($checked,$additional);
4082: if ($currcanclone eq $option) {
4083: $checked = ' checked="checked"';
4084: }
4085: if ($option eq 'instcode') {
4086: if (@code_order) {
4087: my $show = 'none';
4088: if ($checked) {
4089: $show = 'block';
4090: }
4091: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4092: &mt('Institutional codes for new and cloned course have identical:').
4093: '<br />';
4094: foreach my $item (@code_order) {
4095: my $codechk;
4096: if ($checked) {
4097: if (grep(/^\Q$item\E$/,@posscodes)) {
4098: $codechk = ' checked="checked"';
4099: }
4100: }
4101: $additional .= '<label>'.
4102: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4103: $item.'</label>';
4104: }
4105: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4106: }
4107: }
4108: $datatable .=
4109: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4110: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4111: '</label> '.$additional.'</span><br />';
4112: }
4113: $datatable .= '</td>'.
4114: '</tr>';
4115: $itemcount ++;
1.139 raeburn 4116: } else {
4117: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4118: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4119: my $currusecredits = 0;
1.257 raeburn 4120: my $postsubmitclient = 1;
1.271 raeburn 4121: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4122: if (ref($settings) eq 'HASH') {
4123: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4124: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4125: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4126: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4127: }
4128: }
1.192 raeburn 4129: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4130: foreach my $type (@types) {
4131: next if ($type eq 'community');
4132: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4133: if ($defcredits{$type} ne '') {
4134: $currusecredits = 1;
4135: }
4136: }
4137: }
4138: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4139: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4140: $postsubmitclient = 0;
4141: foreach my $type (@types) {
4142: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4143: }
4144: } else {
4145: foreach my $type (@types) {
4146: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4147: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 4148: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 4149: } else {
4150: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4151: }
4152: } else {
4153: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4154: }
4155: }
4156: }
4157: } else {
4158: foreach my $type (@types) {
4159: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 4160: }
4161: }
1.276 raeburn 4162: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4163: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4164: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4165: }
4166: } else {
4167: foreach my $type (@types) {
4168: $currmysql{$type} = $staticdefaults{'mysqltables'};
4169: }
4170: }
1.258 raeburn 4171: } else {
4172: foreach my $type (@types) {
4173: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4174: }
1.139 raeburn 4175: }
4176: if (!$currdefresponder) {
1.198 raeburn 4177: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4178: } elsif ($currdefresponder < 1) {
4179: $currdefresponder = 1;
4180: }
1.198 raeburn 4181: foreach my $type (@types) {
4182: if ($curruploadquota{$type} eq '') {
4183: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4184: }
4185: }
1.139 raeburn 4186: $datatable .=
1.192 raeburn 4187: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4188: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4189: '</span></td>'.
4190: '<td class="LC_right_item"><span class="LC_nobreak">'.
4191: '<input type="text" name="anonsurvey_threshold"'.
4192: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 4193: '</td></tr>'."\n";
4194: $itemcount ++;
4195: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4196: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4197: $choices{'uploadquota'}.
4198: '</span></td>'.
4199: '<td align="right" class="LC_right_item">'.
4200: '<table><tr>';
1.198 raeburn 4201: foreach my $type (@types) {
4202: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4203: '<input type="text" name="uploadquota_'.$type.'"'.
4204: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4205: }
4206: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 4207: $itemcount ++;
1.236 raeburn 4208: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 4209: my $display = 'none';
1.192 raeburn 4210: if ($currusecredits) {
4211: $display = 'block';
4212: }
4213: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 4214: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4215: foreach my $type (@types) {
4216: next if ($type eq 'community');
4217: $additional .= '<td align="center">'.&mt($type).'<br />'.
4218: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 4219: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 4220: }
4221: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 4222: %defaultchecked = ('coursecredits' => 'off');
4223: @toggles = ('coursecredits');
4224: my $current = {
4225: 'coursecredits' => $currusecredits,
4226: };
4227: (my $table,$itemcount) =
4228: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 4229: \%choices,$itemcount,$onclick,$additional,'left');
4230: $datatable .= $table;
4231: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4232: my $display = 'none';
4233: if ($postsubmitclient) {
4234: $display = 'block';
4235: }
4236: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 4237: &mt('Number of seconds submit is disabled').'<br />'.
4238: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4239: '<table><tr>';
1.257 raeburn 4240: foreach my $type (@types) {
4241: $additional .= '<td align="center">'.&mt($type).'<br />'.
4242: '<input type="text" name="'.$type.'_timeout" value="'.
4243: $deftimeout{$type}.'" size="5" /></td>';
4244: }
4245: $additional .= '</tr></table></div>'."\n";
4246: %defaultchecked = ('postsubmit' => 'on');
4247: @toggles = ('postsubmit');
1.280 raeburn 4248: $current = {
4249: 'postsubmit' => $postsubmitclient,
4250: };
1.257 raeburn 4251: ($table,$itemcount) =
4252: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4253: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 4254: $datatable .= $table;
1.276 raeburn 4255: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4256: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4257: $choices{'mysqltables'}.
4258: '</span></td>'.
4259: '<td align="right" class="LC_right_item">'.
4260: '<table><tr>';
4261: foreach my $type (@types) {
4262: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4263: '<input type="text" name="mysqltables_'.$type.'"'.
4264: ' value="'.$currmysql{$type}.'" size="5" /></td>';
4265: }
4266: $datatable .= '</tr></table></td></tr>'."\n";
4267: $itemcount ++;
4268:
1.139 raeburn 4269: }
1.192 raeburn 4270: $$rowtotal += $itemcount;
1.121 raeburn 4271: return $datatable;
1.118 jms 4272: }
4273:
1.231 raeburn 4274: sub print_selfenrollment {
4275: my ($position,$dom,$settings,$rowtotal) = @_;
4276: my ($css_class,$datatable);
4277: my $itemcount = 1;
1.271 raeburn 4278: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 4279: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 4280: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4281: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 4282: my @rows;
4283: my $key;
4284: if ($position eq 'top') {
4285: $key = 'admin';
4286: if (ref($rowsref) eq 'ARRAY') {
4287: @rows = @{$rowsref};
4288: }
4289: } elsif ($position eq 'middle') {
4290: $key = 'default';
4291: @rows = ('types','registered','approval','limit');
4292: }
4293: foreach my $row (@rows) {
4294: if (defined($titlesref->{$row})) {
4295: $itemcount ++;
4296: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4297: $datatable .= '<tr'.$css_class.'>'.
4298: '<td>'.$titlesref->{$row}.'</td>'.
4299: '<td class="LC_left_item">'.
4300: '<table><tr>';
4301: my (%current,%currentcap);
4302: if (ref($settings) eq 'HASH') {
4303: if (ref($settings->{$key}) eq 'HASH') {
4304: foreach my $type (@types) {
4305: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4306: $current{$type} = $settings->{$key}->{$type}->{$row};
4307: }
4308: if (($row eq 'limit') && ($key eq 'default')) {
4309: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4310: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4311: }
4312: }
4313: }
4314: }
4315: }
4316: my %roles = (
4317: '0' => &Apache::lonnet::plaintext('dc'),
4318: );
4319:
4320: foreach my $type (@types) {
4321: unless (($row eq 'registered') && ($key eq 'default')) {
4322: $datatable .= '<th>'.&mt($type).'</th>';
4323: }
4324: }
4325: unless (($row eq 'registered') && ($key eq 'default')) {
4326: $datatable .= '</tr><tr>';
4327: }
4328: foreach my $type (@types) {
4329: if ($type eq 'community') {
4330: $roles{'1'} = &mt('Community personnel');
4331: } else {
4332: $roles{'1'} = &mt('Course personnel');
4333: }
4334: $datatable .= '<td style="vertical-align: top">';
4335: if ($position eq 'top') {
4336: my %checked;
4337: if ($current{$type} eq '0') {
4338: $checked{'0'} = ' checked="checked"';
4339: } else {
4340: $checked{'1'} = ' checked="checked"';
4341: }
4342: foreach my $role ('1','0') {
4343: $datatable .= '<span class="LC_nobreak"><label>'.
4344: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4345: 'value="'.$role.'"'.$checked{$role}.' />'.
4346: $roles{$role}.'</label></span> ';
4347: }
4348: } else {
4349: if ($row eq 'types') {
4350: my %checked;
4351: if ($current{$type} =~ /^(all|dom)$/) {
4352: $checked{$1} = ' checked="checked"';
4353: } else {
4354: $checked{''} = ' checked="checked"';
4355: }
4356: foreach my $val ('','dom','all') {
4357: $datatable .= '<span class="LC_nobreak"><label>'.
4358: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4359: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4360: }
4361: } elsif ($row eq 'registered') {
4362: my %checked;
4363: if ($current{$type} eq '1') {
4364: $checked{'1'} = ' checked="checked"';
4365: } else {
4366: $checked{'0'} = ' checked="checked"';
4367: }
4368: foreach my $val ('0','1') {
4369: $datatable .= '<span class="LC_nobreak"><label>'.
4370: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4371: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4372: }
4373: } elsif ($row eq 'approval') {
4374: my %checked;
4375: if ($current{$type} =~ /^([12])$/) {
4376: $checked{$1} = ' checked="checked"';
4377: } else {
4378: $checked{'0'} = ' checked="checked"';
4379: }
4380: for my $val (0..2) {
4381: $datatable .= '<span class="LC_nobreak"><label>'.
4382: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4383: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4384: }
4385: } elsif ($row eq 'limit') {
4386: my %checked;
4387: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4388: $checked{$1} = ' checked="checked"';
4389: } else {
4390: $checked{'none'} = ' checked="checked"';
4391: }
4392: my $cap;
4393: if ($currentcap{$type} =~ /^\d+$/) {
4394: $cap = $currentcap{$type};
4395: }
4396: foreach my $val ('none','allstudents','selfenrolled') {
4397: $datatable .= '<span class="LC_nobreak"><label>'.
4398: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4399: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4400: }
4401: $datatable .= '<br />'.
4402: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4403: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4404: '</span>';
4405: }
4406: }
4407: $datatable .= '</td>';
4408: }
4409: $datatable .= '</tr>';
4410: }
4411: $datatable .= '</table></td></tr>';
4412: }
4413: } elsif ($position eq 'bottom') {
1.235 raeburn 4414: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4415: }
4416: $$rowtotal += $itemcount;
4417: return $datatable;
4418: }
4419:
4420: sub print_validation_rows {
4421: my ($caller,$dom,$settings,$rowtotal) = @_;
4422: my ($itemsref,$namesref,$fieldsref);
4423: if ($caller eq 'selfenroll') {
4424: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4425: } elsif ($caller eq 'requestcourses') {
4426: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4427: }
4428: my %currvalidation;
4429: if (ref($settings) eq 'HASH') {
4430: if (ref($settings->{'validation'}) eq 'HASH') {
4431: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 4432: }
1.235 raeburn 4433: }
4434: my $datatable;
4435: my $itemcount = 0;
4436: foreach my $item (@{$itemsref}) {
4437: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4438: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4439: $namesref->{$item}.
4440: '</span></td>'.
4441: '<td class="LC_left_item">';
4442: if (($item eq 'url') || ($item eq 'button')) {
4443: $datatable .= '<span class="LC_nobreak">'.
4444: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4445: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4446: } elsif ($item eq 'fields') {
4447: my @currfields;
4448: if (ref($currvalidation{$item}) eq 'ARRAY') {
4449: @currfields = @{$currvalidation{$item}};
4450: }
4451: foreach my $field (@{$fieldsref}) {
4452: my $check = '';
4453: if (grep(/^\Q$field\E$/,@currfields)) {
4454: $check = ' checked="checked"';
4455: }
4456: $datatable .= '<span class="LC_nobreak"><label>'.
4457: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4458: ' value="'.$field.'"'.$check.' />'.$field.
4459: '</label></span> ';
4460: }
4461: } elsif ($item eq 'markup') {
4462: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4463: $currvalidation{$item}.
1.231 raeburn 4464: '</textarea>';
1.235 raeburn 4465: }
4466: $datatable .= '</td></tr>'."\n";
4467: if (ref($rowtotal)) {
1.231 raeburn 4468: $itemcount ++;
4469: }
4470: }
1.235 raeburn 4471: if ($caller eq 'requestcourses') {
4472: my %currhash;
1.248 raeburn 4473: if (ref($settings) eq 'HASH') {
4474: if (ref($settings->{'validation'}) eq 'HASH') {
4475: if ($settings->{'validation'}{'dc'} ne '') {
4476: $currhash{$settings->{'validation'}{'dc'}} = 1;
4477: }
1.235 raeburn 4478: }
4479: }
4480: my $numinrow = 2;
4481: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4482: 'validationdc',%currhash);
1.247 raeburn 4483: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4484: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 4485: if ($numdc > 1) {
1.247 raeburn 4486: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 4487: } else {
1.247 raeburn 4488: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 4489: }
1.247 raeburn 4490: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 4491: $itemcount ++;
4492: }
4493: if (ref($rowtotal)) {
4494: $$rowtotal += $itemcount;
4495: }
1.231 raeburn 4496: return $datatable;
4497: }
4498:
1.137 raeburn 4499: sub print_usersessions {
4500: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 4501: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 4502: my (%by_ip,%by_location,@intdoms,@instdoms);
4503: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 4504:
4505: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4506: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4507: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4508: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4509: if ($position eq 'top') {
1.152 raeburn 4510: if (keys(%serverhomes) > 1) {
1.145 raeburn 4511: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 4512: my $curroffloadnow;
4513: if (ref($settings) eq 'HASH') {
4514: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4515: $curroffloadnow = $settings->{'offloadnow'};
4516: }
4517: }
4518: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4519: } else {
1.140 raeburn 4520: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 4521: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
4522: '</td></tr>';
1.140 raeburn 4523: }
1.137 raeburn 4524: } else {
1.279 raeburn 4525: my %titles = &usersession_titles();
4526: my ($prefix,@types);
4527: if ($position eq 'bottom') {
4528: $prefix = 'remote';
4529: @types = ('version','excludedomain','includedomain');
1.145 raeburn 4530: } else {
1.279 raeburn 4531: $prefix = 'hosted';
4532: @types = ('excludedomain','includedomain');
4533: }
4534: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4535: }
4536: $$rowtotal += $itemcount;
4537: return $datatable;
4538: }
4539:
4540: sub rules_by_location {
4541: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
4542: my ($datatable,$itemcount,$css_class);
4543: if (keys(%{$by_location}) == 0) {
4544: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4545: $datatable = '<tr'.$css_class.'><td colspan="2">'.
4546: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
4547: '</td></tr>';
4548: $itemcount = 1;
4549: } else {
4550: $itemcount = 0;
4551: my $numinrow = 5;
4552: my (%current,%checkedon,%checkedoff);
4553: my @locations = sort(keys(%{$by_location}));
4554: foreach my $type (@{$types}) {
4555: $checkedon{$type} = '';
4556: $checkedoff{$type} = ' checked="checked"';
4557: }
4558: if (ref($settings) eq 'HASH') {
4559: if (ref($settings->{$prefix}) eq 'HASH') {
4560: foreach my $key (keys(%{$settings->{$prefix}})) {
4561: $current{$key} = $settings->{$prefix}{$key};
4562: if ($key eq 'version') {
4563: if ($current{$key} ne '') {
1.145 raeburn 4564: $checkedon{$key} = ' checked="checked"';
4565: $checkedoff{$key} = '';
4566: }
1.279 raeburn 4567: } elsif (ref($current{$key}) eq 'ARRAY') {
4568: $checkedon{$key} = ' checked="checked"';
4569: $checkedoff{$key} = '';
1.137 raeburn 4570: }
4571: }
4572: }
1.279 raeburn 4573: }
4574: foreach my $type (@{$types}) {
4575: next if ($type ne 'version' && !@locations);
4576: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4577: $datatable .= '<tr'.$css_class.'>
4578: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4579: <span class="LC_nobreak">
4580: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4581: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4582: if ($type eq 'version') {
4583: my @lcversions = &Apache::lonnet::all_loncaparevs();
4584: my $selector = '<select name="'.$prefix.'_version">';
4585: foreach my $version (@lcversions) {
4586: my $selected = '';
4587: if ($current{'version'} eq $version) {
4588: $selected = ' selected="selected"';
1.145 raeburn 4589: }
1.279 raeburn 4590: $selector .= ' <option value="'.$version.'"'.
4591: $selected.'>'.$version.'</option>';
4592: }
4593: $selector .= '</select> ';
4594: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4595: } else {
4596: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4597: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4598: ' />'.(' 'x2).
4599: '<input type="button" value="'.&mt('uncheck all').'" '.
4600: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4601: "\n".
4602: '</div><div><table>';
4603: my $rem;
4604: for (my $i=0; $i<@locations; $i++) {
4605: my ($showloc,$value,$checkedtype);
4606: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4607: my $ip = $by_location->{$locations[$i]}->[0];
4608: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4609: $value = join(':',@{$by_ip->{$ip}});
4610: $showloc = join(', ',@{$by_ip->{$ip}});
4611: if (ref($current{$type}) eq 'ARRAY') {
4612: foreach my $loc (@{$by_ip->{$ip}}) {
4613: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4614: $checkedtype = ' checked="checked"';
4615: last;
1.145 raeburn 4616: }
1.138 raeburn 4617: }
4618: }
4619: }
1.137 raeburn 4620: }
1.279 raeburn 4621: $rem = $i%($numinrow);
4622: if ($rem == 0) {
4623: if ($i > 0) {
4624: $datatable .= '</tr>';
4625: }
4626: $datatable .= '<tr>';
4627: }
4628: $datatable .= '<td class="LC_left_item">'.
4629: '<span class="LC_nobreak"><label>'.
4630: '<input type="checkbox" name="'.$prefix.'_'.$type.
4631: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4632: '</label></span></td>';
4633: }
4634: $rem = @locations%($numinrow);
4635: my $colsleft = $numinrow - $rem;
4636: if ($colsleft > 1 ) {
4637: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4638: ' </td>';
4639: } elsif ($colsleft == 1) {
4640: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4641: }
1.279 raeburn 4642: $datatable .= '</tr></table>';
1.137 raeburn 4643: }
1.279 raeburn 4644: $datatable .= '</td></tr>';
4645: $itemcount ++;
1.137 raeburn 4646: }
4647: }
1.279 raeburn 4648: return ($datatable,$itemcount);
1.137 raeburn 4649: }
4650:
1.275 raeburn 4651: sub print_ssl {
4652: my ($position,$dom,$settings,$rowtotal) = @_;
4653: my ($css_class,$datatable);
4654: my $itemcount = 1;
4655: if ($position eq 'top') {
1.281 raeburn 4656: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4657: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4658: my $same_institution;
4659: if ($intdom ne '') {
4660: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4661: if (ref($internet_names) eq 'ARRAY') {
4662: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4663: $same_institution = 1;
4664: }
4665: }
4666: }
1.275 raeburn 4667: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 4668: $datatable = '<tr'.$css_class.'><td colspan="2">';
4669: if ($same_institution) {
4670: my %domservers = &Apache::lonnet::get_servers($dom);
4671: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
4672: } else {
4673: $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.");
4674: }
4675: $datatable .= '</td></tr>';
1.275 raeburn 4676: $itemcount ++;
4677: } else {
4678: my %titles = &ssl_titles();
4679: my (%by_ip,%by_location,@intdoms,@instdoms);
4680: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4681: my @alldoms = &Apache::lonnet::all_domains();
4682: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4683: my @domservers = &Apache::lonnet::get_servers($dom);
4684: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4685: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 4686: if (($position eq 'connto') || ($position eq 'connfrom')) {
4687: my $legacy;
4688: unless (ref($settings) eq 'HASH') {
4689: my $name;
4690: if ($position eq 'connto') {
4691: $name = 'loncAllowInsecure';
4692: } else {
4693: $name = 'londAllowInsecure';
4694: }
4695: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
4696: my @ids=&Apache::lonnet::current_machine_ids();
4697: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
4698: my %what = (
4699: $name => 1,
4700: );
4701: my ($result,$returnhash) =
4702: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
4703: if ($result eq 'ok') {
4704: if (ref($returnhash) eq 'HASH') {
4705: $legacy = $returnhash->{$name};
4706: }
4707: }
4708: } else {
4709: $legacy = $Apache::lonnet::perlvar{$name};
4710: }
4711: }
1.275 raeburn 4712: foreach my $type ('dom','intdom','other') {
4713: my %checked;
4714: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4715: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4716: '<td class="LC_right_item">';
4717: my $skip;
4718: if ($type eq 'dom') {
4719: unless (keys(%servers) > 1) {
4720: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4721: $skip = 1;
4722: }
4723: }
4724: if ($type eq 'intdom') {
4725: unless (@instdoms > 1) {
4726: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4727: $skip = 1;
4728: }
4729: } elsif ($type eq 'other') {
4730: if (keys(%by_location) == 0) {
4731: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4732: $skip = 1;
4733: }
4734: }
4735: unless ($skip) {
4736: $checked{'yes'} = ' checked="checked"';
4737: if (ref($settings) eq 'HASH') {
1.293 raeburn 4738: if (ref($settings->{$position}) eq 'HASH') {
4739: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 4740: $checked{$1} = $checked{'yes'};
4741: delete($checked{'yes'});
4742: }
4743: }
1.293 raeburn 4744: } else {
4745: if ($legacy == 0) {
4746: $checked{'req'} = $checked{'yes'};
4747: delete($checked{'yes'});
4748: }
1.275 raeburn 4749: }
4750: foreach my $option ('no','yes','req') {
4751: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 4752: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 4753: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4754: '</label></span>'.(' 'x2);
4755: }
4756: }
4757: $datatable .= '</td></tr>';
4758: $itemcount ++;
4759: }
4760: } else {
4761: my $prefix = 'replication';
4762: my @types = ('certreq','nocertreq');
1.279 raeburn 4763: if (keys(%by_location) == 0) {
4764: $datatable .= '<tr'.$css_class.'><td>'.
4765: &mt('Nothing to set here, as there are no other institutions').
4766: '</td></tr>';
4767: $itemcount ++;
1.275 raeburn 4768: } else {
1.279 raeburn 4769: ($datatable,$itemcount) =
4770: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 4771: }
4772: }
4773: }
4774: $$rowtotal += $itemcount;
4775: return $datatable;
4776: }
4777:
4778: sub ssl_titles {
4779: return &Apache::lonlocal::texthash (
4780: dom => 'LON-CAPA servers/VMs from same domain',
4781: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4782: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 4783: connto => 'Connections to other servers',
4784: connfrom => 'Connections from other servers',
1.275 raeburn 4785: replication => 'Replicating content to other institutions',
4786: certreq => 'Client certificate required, but specific domains exempt',
4787: nocertreq => 'No client certificate required, except for specific domains',
4788: no => 'SSL not used',
4789: yes => 'SSL Optional (used if available)',
4790: req => 'SSL Required',
4791: );
1.279 raeburn 4792: }
4793:
4794: sub print_trust {
4795: my ($prefix,$dom,$settings,$rowtotal) = @_;
4796: my ($css_class,$datatable,%checked,%choices);
4797: my (%by_ip,%by_location,@intdoms,@instdoms);
4798: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4799: my $itemcount = 1;
4800: my %titles = &trust_titles();
4801: my @types = ('exc','inc');
4802: if ($prefix eq 'top') {
4803: $prefix = 'content';
4804: } elsif ($prefix eq 'bottom') {
4805: $prefix = 'msg';
4806: }
4807: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4808: $$rowtotal += $itemcount;
4809: return $datatable;
4810: }
4811:
4812: sub trust_titles {
4813: return &Apache::lonlocal::texthash(
4814: content => "Access to this domain's content by others",
4815: shared => "Access to other domain's content by this domain",
4816: enroll => "Enrollment in this domain's courses by others",
4817: othcoau => "Co-author roles in this domain for others",
4818: coaurem => "Co-author roles for this domain's users elsewhere",
4819: domroles => "Domain roles in this domain assignable to others",
4820: catalog => "Course Catalog for this domain displayed elsewhere",
4821: reqcrs => "Requests for creation of courses in this domain by others",
4822: msg => "Users in other domains can send messages to this domain",
4823: exc => "Allow all, but exclude specific domains",
4824: inc => "Deny all, but include specific domains",
4825: );
1.275 raeburn 4826: }
4827:
1.138 raeburn 4828: sub build_location_hashes {
1.275 raeburn 4829: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4830: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4831: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4832: my %iphost = &Apache::lonnet::get_iphost();
4833: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4834: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4835: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4836: foreach my $id (@{$iphost{$primary_ip}}) {
4837: my $intdom = &Apache::lonnet::internet_dom($id);
4838: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4839: push(@{$intdoms},$intdom);
4840: }
4841: }
4842: }
4843: foreach my $ip (keys(%iphost)) {
4844: if (ref($iphost{$ip}) eq 'ARRAY') {
4845: foreach my $id (@{$iphost{$ip}}) {
4846: my $location = &Apache::lonnet::internet_dom($id);
4847: if ($location) {
1.275 raeburn 4848: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4849: my $dom = &Apache::lonnet::host_domain($id);
4850: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4851: push(@{$instdoms},$dom);
4852: }
4853: next;
4854: }
1.138 raeburn 4855: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4856: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4857: push(@{$by_ip->{$ip}},$location);
4858: }
4859: } else {
4860: $by_ip->{$ip} = [$location];
4861: }
4862: }
4863: }
4864: }
4865: }
4866: foreach my $ip (sort(keys(%{$by_ip}))) {
4867: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4868: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4869: my $first = $by_ip->{$ip}->[0];
4870: if (ref($by_location->{$first}) eq 'ARRAY') {
4871: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4872: push(@{$by_location->{$first}},$ip);
4873: }
4874: } else {
4875: $by_location->{$first} = [$ip];
4876: }
4877: }
4878: }
4879: return;
4880: }
4881:
1.145 raeburn 4882: sub current_offloads_to {
4883: my ($dom,$settings,$servers) = @_;
4884: my (%spareid,%otherdomconfigs);
1.152 raeburn 4885: if (ref($servers) eq 'HASH') {
1.145 raeburn 4886: foreach my $lonhost (sort(keys(%{$servers}))) {
4887: my $gotspares;
1.152 raeburn 4888: if (ref($settings) eq 'HASH') {
4889: if (ref($settings->{'spares'}) eq 'HASH') {
4890: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4891: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4892: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4893: $gotspares = 1;
4894: }
1.145 raeburn 4895: }
4896: }
4897: unless ($gotspares) {
4898: my $gotspares;
4899: my $serverhomeID =
4900: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4901: my $serverhomedom =
4902: &Apache::lonnet::host_domain($serverhomeID);
4903: if ($serverhomedom ne $dom) {
4904: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4905: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4906: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4907: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4908: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4909: $gotspares = 1;
4910: }
4911: }
4912: } else {
4913: $otherdomconfigs{$serverhomedom} =
4914: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4915: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4916: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4917: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4918: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4919: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4920: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4921: $gotspares = 1;
4922: }
4923: }
4924: }
4925: }
4926: }
4927: }
4928: }
4929: unless ($gotspares) {
4930: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4931: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4932: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4933: } else {
4934: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4935: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4936: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4937: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4938: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4939: } else {
1.150 raeburn 4940: my %what = (
4941: spareid => 1,
4942: );
4943: my ($result,$returnhash) =
4944: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4945: if ($result eq 'ok') {
4946: if (ref($returnhash) eq 'HASH') {
4947: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4948: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4949: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4950: }
4951: }
1.145 raeburn 4952: }
4953: }
4954: }
4955: }
4956: }
4957: }
4958: return %spareid;
4959: }
4960:
4961: sub spares_row {
1.261 raeburn 4962: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4963: my $css_class;
4964: my $numinrow = 4;
4965: my $itemcount = 1;
4966: my $datatable;
1.152 raeburn 4967: my %typetitles = &sparestype_titles();
4968: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4969: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4970: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4971: my ($othercontrol,$serverdom);
4972: if ($serverhome ne $server) {
4973: $serverdom = &Apache::lonnet::host_domain($serverhome);
4974: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4975: } else {
4976: $serverdom = &Apache::lonnet::host_domain($server);
4977: if ($serverdom ne $dom) {
4978: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4979: }
4980: }
4981: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 4982: my $checkednow;
4983: if (ref($curroffloadnow) eq 'HASH') {
4984: if ($curroffloadnow->{$server}) {
4985: $checkednow = ' checked="checked"';
4986: }
4987: }
1.145 raeburn 4988: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4989: $datatable .= '<tr'.$css_class.'>
4990: <td rowspan="2">
1.183 bisitz 4991: <span class="LC_nobreak">'.
4992: &mt('[_1] when busy, offloads to:'
1.261 raeburn 4993: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 4994: '<span class="LC_nobreak">'."\n".
1.261 raeburn 4995: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4996: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 4997: "\n";
1.145 raeburn 4998: my (%current,%canselect);
1.152 raeburn 4999: my @choices =
5000: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5001: foreach my $type ('primary','default') {
5002: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5003: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5004: my @spares = @{$spareid->{$server}{$type}};
5005: if (@spares > 0) {
1.152 raeburn 5006: if ($othercontrol) {
5007: $current{$type} = join(', ',@spares);
5008: } else {
5009: $current{$type} .= '<table>';
5010: my $numspares = scalar(@spares);
5011: for (my $i=0; $i<@spares; $i++) {
5012: my $rem = $i%($numinrow);
5013: if ($rem == 0) {
5014: if ($i > 0) {
5015: $current{$type} .= '</tr>';
5016: }
5017: $current{$type} .= '<tr>';
1.145 raeburn 5018: }
1.152 raeburn 5019: $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'".');" /> '.
5020: $spareid->{$server}{$type}[$i].
5021: '</label></td>'."\n";
5022: }
5023: my $rem = @spares%($numinrow);
5024: my $colsleft = $numinrow - $rem;
5025: if ($colsleft > 1 ) {
5026: $current{$type} .= '<td colspan="'.$colsleft.
5027: '" class="LC_left_item">'.
5028: ' </td>';
5029: } elsif ($colsleft == 1) {
5030: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5031: }
1.152 raeburn 5032: $current{$type} .= '</tr></table>';
1.150 raeburn 5033: }
1.145 raeburn 5034: }
5035: }
5036: if ($current{$type} eq '') {
5037: $current{$type} = &mt('None specified');
5038: }
1.152 raeburn 5039: if ($othercontrol) {
5040: if ($type eq 'primary') {
5041: $canselect{$type} = $othercontrol;
5042: }
5043: } else {
5044: $canselect{$type} =
5045: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5046: '<select name="newspare_'.$type.'_'.$server.'" '.
5047: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5048: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5049: if (@choices > 0) {
5050: foreach my $lonhost (@choices) {
5051: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5052: }
5053: }
5054: $canselect{$type} .= '</select>'."\n";
5055: }
5056: } else {
5057: $current{$type} = &mt('Could not be determined');
5058: if ($type eq 'primary') {
5059: $canselect{$type} = $othercontrol;
5060: }
1.145 raeburn 5061: }
1.152 raeburn 5062: if ($type eq 'default') {
5063: $datatable .= '<tr'.$css_class.'>';
5064: }
5065: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5066: '<td>'.$current{$type}.'</td>'."\n".
5067: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5068: }
5069: $itemcount ++;
5070: }
5071: }
5072: $$rowtotal += $itemcount;
5073: return $datatable;
5074: }
5075:
1.152 raeburn 5076: sub possible_newspares {
5077: my ($server,$currspares,$serverhomes,$altids) = @_;
5078: my $serverhostname = &Apache::lonnet::hostname($server);
5079: my %excluded;
5080: if ($serverhostname ne '') {
5081: %excluded = (
5082: $serverhostname => 1,
5083: );
5084: }
5085: if (ref($currspares) eq 'HASH') {
5086: foreach my $type (keys(%{$currspares})) {
5087: if (ref($currspares->{$type}) eq 'ARRAY') {
5088: if (@{$currspares->{$type}} > 0) {
5089: foreach my $curr (@{$currspares->{$type}}) {
5090: my $hostname = &Apache::lonnet::hostname($curr);
5091: $excluded{$hostname} = 1;
5092: }
5093: }
5094: }
5095: }
5096: }
5097: my @choices;
5098: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5099: if (keys(%{$serverhomes}) > 1) {
5100: foreach my $name (sort(keys(%{$serverhomes}))) {
5101: unless ($excluded{$name}) {
5102: if (exists($altids->{$serverhomes->{$name}})) {
5103: push(@choices,$altids->{$serverhomes->{$name}});
5104: } else {
5105: push(@choices,$serverhomes->{$name});
1.145 raeburn 5106: }
5107: }
5108: }
5109: }
5110: }
1.152 raeburn 5111: return sort(@choices);
1.145 raeburn 5112: }
5113:
1.150 raeburn 5114: sub print_loadbalancing {
5115: my ($dom,$settings,$rowtotal) = @_;
5116: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5117: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5118: my $numinrow = 1;
5119: my $datatable;
5120: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5121: my (%currbalancer,%currtargets,%currrules,%existing);
5122: if (ref($settings) eq 'HASH') {
5123: %existing = %{$settings};
5124: }
5125: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5126: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5127: \%currtargets,\%currrules);
1.150 raeburn 5128: } else {
5129: return;
5130: }
5131: my ($othertitle,$usertypes,$types) =
5132: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5133: my $rownum = 8;
1.150 raeburn 5134: if (ref($types) eq 'ARRAY') {
5135: $rownum += scalar(@{$types});
5136: }
1.171 raeburn 5137: my @css_class = ('LC_odd_row','LC_even_row');
5138: my $balnum = 0;
5139: my $islast;
5140: my (@toshow,$disabledtext);
5141: if (keys(%currbalancer) > 0) {
5142: @toshow = sort(keys(%currbalancer));
5143: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5144: push(@toshow,'');
5145: }
5146: } else {
5147: @toshow = ('');
5148: $disabledtext = &mt('No existing load balancer');
5149: }
5150: foreach my $lonhost (@toshow) {
5151: if ($balnum == scalar(@toshow)-1) {
5152: $islast = 1;
5153: } else {
5154: $islast = 0;
5155: }
5156: my $cssidx = $balnum%2;
5157: my $targets_div_style = 'display: none';
5158: my $disabled_div_style = 'display: block';
5159: my $homedom_div_style = 'display: none';
5160: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5161: '<td rowspan="'.$rownum.'" valign="top">'.
5162: '<p>';
5163: if ($lonhost eq '') {
1.210 raeburn 5164: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 5165: if (keys(%currbalancer) > 0) {
5166: $datatable .= &mt('Add balancer:');
5167: } else {
5168: $datatable .= &mt('Enable balancer:');
5169: }
5170: $datatable .= ' '.
5171: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5172: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5173: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5174: '<option value="" selected="selected">'.&mt('None').
5175: '</option>'."\n";
5176: foreach my $server (sort(keys(%servers))) {
5177: next if ($currbalancer{$server});
5178: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5179: }
1.210 raeburn 5180: $datatable .=
1.171 raeburn 5181: '</select>'."\n".
5182: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5183: } else {
5184: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5185: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5186: &mt('Stop balancing').'</label>'.
5187: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5188: $targets_div_style = 'display: block';
5189: $disabled_div_style = 'display: none';
5190: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5191: $homedom_div_style = 'display: block';
5192: }
5193: }
5194: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5195: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5196: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5197: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5198: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5199: my @sparestypes = ('primary','default');
5200: my %typetitles = &sparestype_titles();
1.284 raeburn 5201: my %hostherechecked = (
5202: no => ' checked="checked"',
5203: );
1.171 raeburn 5204: foreach my $sparetype (@sparestypes) {
5205: my $targettable;
5206: for (my $i=0; $i<$numspares; $i++) {
5207: my $checked;
5208: if (ref($currtargets{$lonhost}) eq 'HASH') {
5209: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5210: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5211: $checked = ' checked="checked"';
5212: }
5213: }
5214: }
5215: my ($chkboxval,$disabled);
5216: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5217: $chkboxval = $spares[$i];
5218: }
5219: if (exists($currbalancer{$spares[$i]})) {
5220: $disabled = ' disabled="disabled"';
5221: }
1.210 raeburn 5222: $targettable .=
1.253 raeburn 5223: '<td><span class="LC_nobreak"><label>'.
5224: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 5225: $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 5226: '</span></label></span></td>';
1.171 raeburn 5227: my $rem = $i%($numinrow);
5228: if ($rem == 0) {
5229: if (($i > 0) && ($i < $numspares-1)) {
5230: $targettable .= '</tr>';
5231: }
5232: if ($i < $numspares-1) {
5233: $targettable .= '<tr>';
1.150 raeburn 5234: }
5235: }
5236: }
1.171 raeburn 5237: if ($targettable ne '') {
5238: my $rem = $numspares%($numinrow);
5239: my $colsleft = $numinrow - $rem;
5240: if ($colsleft > 1 ) {
5241: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5242: ' </td>';
5243: } elsif ($colsleft == 1) {
5244: $targettable .= '<td class="LC_left_item"> </td>';
5245: }
5246: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5247: '<table><tr>'.$targettable.'</tr></table><br />';
5248: }
1.284 raeburn 5249: $hostherechecked{$sparetype} = '';
5250: if (ref($currtargets{$lonhost}) eq 'HASH') {
5251: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5252: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5253: $hostherechecked{$sparetype} = ' checked="checked"';
5254: $hostherechecked{'no'} = '';
5255: }
5256: }
5257: }
5258: }
5259: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5260: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5261: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5262: foreach my $sparetype (@sparestypes) {
5263: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5264: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5265: '</i></label><br />';
1.171 raeburn 5266: }
5267: $datatable .= '</div></td></tr>'.
5268: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5269: $othertitle,$usertypes,$types,\%servers,
5270: \%currbalancer,$lonhost,
5271: $targets_div_style,$homedom_div_style,
5272: $css_class[$cssidx],$balnum,$islast);
5273: $$rowtotal += $rownum;
5274: $balnum ++;
5275: }
5276: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5277: return $datatable;
5278: }
5279:
5280: sub get_loadbalancers_config {
5281: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5282: return unless ((ref($servers) eq 'HASH') &&
5283: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5284: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5285: if (keys(%{$existing}) > 0) {
5286: my $oldlonhost;
5287: foreach my $key (sort(keys(%{$existing}))) {
5288: if ($key eq 'lonhost') {
5289: $oldlonhost = $existing->{'lonhost'};
5290: $currbalancer->{$oldlonhost} = 1;
5291: } elsif ($key eq 'targets') {
5292: if ($oldlonhost) {
5293: $currtargets->{$oldlonhost} = $existing->{'targets'};
5294: }
5295: } elsif ($key eq 'rules') {
5296: if ($oldlonhost) {
5297: $currrules->{$oldlonhost} = $existing->{'rules'};
5298: }
5299: } elsif (ref($existing->{$key}) eq 'HASH') {
5300: $currbalancer->{$key} = 1;
5301: $currtargets->{$key} = $existing->{$key}{'targets'};
5302: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5303: }
5304: }
1.171 raeburn 5305: } else {
5306: my ($balancerref,$targetsref) =
5307: &Apache::lonnet::get_lonbalancer_config($servers);
5308: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5309: foreach my $server (sort(keys(%{$balancerref}))) {
5310: $currbalancer->{$server} = 1;
5311: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5312: }
5313: }
5314: }
1.171 raeburn 5315: return;
1.150 raeburn 5316: }
5317:
5318: sub loadbalancing_rules {
5319: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 5320: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5321: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5322: my $output;
1.171 raeburn 5323: my $num = 0;
1.210 raeburn 5324: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5325: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5326: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5327: foreach my $type (@{$alltypes}) {
1.171 raeburn 5328: $num ++;
1.150 raeburn 5329: my $current;
5330: if (ref($currrules) eq 'HASH') {
5331: $current = $currrules->{$type};
5332: }
1.253 raeburn 5333: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 5334: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5335: $current = '';
5336: }
5337: }
5338: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 5339: $servers,$currbalancer,$lonhost,$dom,
5340: $targets_div_style,$homedom_div_style,
5341: $css_class,$balnum,$num,$islast);
1.150 raeburn 5342: }
5343: }
5344: return $output;
5345: }
5346:
5347: sub loadbalancing_titles {
5348: my ($dom,$intdom,$usertypes,$types) = @_;
5349: my %othertypes = (
5350: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5351: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5352: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5353: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 5354: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5355: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5356: );
1.209 raeburn 5357: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 5358: if (ref($types) eq 'ARRAY') {
5359: unshift(@alltypes,@{$types},'default');
5360: }
5361: my %titles;
5362: foreach my $type (@alltypes) {
5363: if ($type =~ /^_LC_/) {
5364: $titles{$type} = $othertypes{$type};
5365: } elsif ($type eq 'default') {
5366: $titles{$type} = &mt('All users from [_1]',$dom);
5367: if (ref($types) eq 'ARRAY') {
5368: if (@{$types} > 0) {
5369: $titles{$type} = &mt('Other users from [_1]',$dom);
5370: }
5371: }
5372: } elsif (ref($usertypes) eq 'HASH') {
5373: $titles{$type} = $usertypes->{$type};
5374: }
5375: }
5376: return (\@alltypes,\%othertypes,\%titles);
5377: }
5378:
5379: sub loadbalance_rule_row {
1.171 raeburn 5380: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5381: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 5382: my @rulenames;
1.150 raeburn 5383: my %ruletitles = &offloadtype_text();
1.209 raeburn 5384: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 5385: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5386: } else {
1.209 raeburn 5387: @rulenames = ('default','homeserver');
5388: if ($type eq '_LC_external') {
5389: push(@rulenames,'externalbalancer');
5390: } else {
5391: push(@rulenames,'specific');
5392: }
5393: push(@rulenames,'none');
1.150 raeburn 5394: }
5395: my $style = $targets_div_style;
1.253 raeburn 5396: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5397: $style = $homedom_div_style;
5398: }
1.171 raeburn 5399: my $space;
5400: if ($islast && $num == 1) {
5401: $space = '<div display="inline-block"> </div>';
5402: }
1.210 raeburn 5403: my $output =
1.171 raeburn 5404: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5405: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5406: '<td valaign="top">'.$space.
5407: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5408: for (my $i=0; $i<@rulenames; $i++) {
5409: my $rule = $rulenames[$i];
5410: my ($checked,$extra);
5411: if ($rulenames[$i] eq 'default') {
5412: $rule = '';
5413: }
5414: if ($rulenames[$i] eq 'specific') {
5415: if (ref($servers) eq 'HASH') {
5416: my $default;
5417: if (($current ne '') && (exists($servers->{$current}))) {
5418: $checked = ' checked="checked"';
5419: }
5420: unless ($checked) {
5421: $default = ' selected="selected"';
5422: }
1.210 raeburn 5423: $extra =
1.171 raeburn 5424: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5425: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5426: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5427: '<option value=""'.$default.'></option>'."\n";
5428: foreach my $server (sort(keys(%{$servers}))) {
5429: if (ref($currbalancer) eq 'HASH') {
5430: next if (exists($currbalancer->{$server}));
5431: }
1.150 raeburn 5432: my $selected;
1.171 raeburn 5433: if ($server eq $current) {
1.150 raeburn 5434: $selected = ' selected="selected"';
5435: }
1.171 raeburn 5436: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5437: }
5438: $extra .= '</select>';
5439: }
5440: } elsif ($rule eq $current) {
5441: $checked = ' checked="checked"';
5442: }
5443: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 5444: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5445: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5446: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 5447: ')"'.$checked.' /> ';
5448: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
5449: $output .= $ruletitles{'particular'};
5450: } else {
5451: $output .= $ruletitles{$rulenames[$i]};
5452: }
5453: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5454: }
5455: $output .= '</div></td></tr>'."\n";
5456: return $output;
5457: }
5458:
5459: sub offloadtype_text {
5460: my %ruletitles = &Apache::lonlocal::texthash (
5461: 'default' => 'Offloads to default destinations',
5462: 'homeserver' => "Offloads to user's home server",
5463: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5464: 'specific' => 'Offloads to specific server',
1.161 raeburn 5465: 'none' => 'No offload',
1.209 raeburn 5466: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5467: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 5468: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5469: );
5470: return %ruletitles;
5471: }
5472:
5473: sub sparestype_titles {
5474: my %typestitles = &Apache::lonlocal::texthash (
5475: 'primary' => 'primary',
5476: 'default' => 'default',
5477: );
5478: return %typestitles;
5479: }
5480:
1.28 raeburn 5481: sub contact_titles {
5482: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 5483: 'supportemail' => 'Support E-mail address',
5484: 'adminemail' => 'Default Server Admin E-mail address',
5485: 'errormail' => 'Error reports to be e-mailed to',
5486: 'packagesmail' => 'Package update alerts to be e-mailed to',
5487: 'helpdeskmail' => "Helpdesk requests for this domain's users",
1.289 raeburn 5488: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
1.286 raeburn 5489: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5490: 'requestsmail' => 'E-mail from course requests requiring approval',
5491: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 5492: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5493: );
5494: my %short_titles = &Apache::lonlocal::texthash (
5495: adminemail => 'Admin E-mail address',
5496: supportemail => 'Support E-mail',
5497: );
5498: return (\%titles,\%short_titles);
5499: }
5500:
1.286 raeburn 5501: sub helpform_fields {
5502: my %titles = &Apache::lonlocal::texthash (
5503: 'username' => 'Name',
5504: 'user' => 'Username/domain',
5505: 'phone' => 'Phone',
5506: 'cc' => 'Cc e-mail',
5507: 'course' => 'Course Details',
5508: 'section' => 'Sections',
1.289 raeburn 5509: 'screenshot' => 'File upload',
1.286 raeburn 5510: );
5511: my @fields = ('username','phone','user','course','section','cc','screenshot');
5512: my %possoptions = (
5513: username => ['yes','no','req'],
1.289 raeburn 5514: phone => ['yes','no','req'],
1.286 raeburn 5515: user => ['yes','no'],
1.289 raeburn 5516: cc => ['yes','no'],
1.286 raeburn 5517: course => ['yes','no'],
5518: section => ['yes','no'],
5519: screenshot => ['yes','no'],
5520: );
5521: my %fieldoptions = &Apache::lonlocal::texthash (
5522: 'yes' => 'Optional',
5523: 'req' => 'Required',
5524: 'no' => "Not shown",
5525: );
5526: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5527: }
5528:
1.72 raeburn 5529: sub tool_titles {
5530: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 5531: aboutme => 'Personal web page',
1.86 raeburn 5532: blog => 'Blog',
1.162 raeburn 5533: webdav => 'WebDAV',
1.86 raeburn 5534: portfolio => 'Portfolio',
1.88 bisitz 5535: official => 'Official courses (with institutional codes)',
5536: unofficial => 'Unofficial courses',
1.98 raeburn 5537: community => 'Communities',
1.216 raeburn 5538: textbook => 'Textbook courses',
1.271 raeburn 5539: placement => 'Placement tests',
1.86 raeburn 5540: );
1.72 raeburn 5541: return %titles;
5542: }
5543:
1.101 raeburn 5544: sub courserequest_titles {
5545: my %titles = &Apache::lonlocal::texthash (
5546: official => 'Official',
5547: unofficial => 'Unofficial',
5548: community => 'Communities',
1.216 raeburn 5549: textbook => 'Textbook',
1.271 raeburn 5550: placement => 'Placement tests',
1.101 raeburn 5551: norequest => 'Not allowed',
1.104 raeburn 5552: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5553: validate => 'With validation',
5554: autolimit => 'Numerical limit',
1.103 raeburn 5555: unlimited => '(blank for unlimited)',
1.101 raeburn 5556: );
5557: return %titles;
5558: }
5559:
1.163 raeburn 5560: sub authorrequest_titles {
5561: my %titles = &Apache::lonlocal::texthash (
5562: norequest => 'Not allowed',
5563: approval => 'Approval by Dom. Coord.',
5564: automatic => 'Automatic approval',
5565: );
5566: return %titles;
1.210 raeburn 5567: }
1.163 raeburn 5568:
1.101 raeburn 5569: sub courserequest_conditions {
5570: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5571: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 5572: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5573: );
5574: return %conditions;
5575: }
5576:
5577:
1.27 raeburn 5578: sub print_usercreation {
1.30 raeburn 5579: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5580: my $numinrow = 4;
1.28 raeburn 5581: my $datatable;
5582: if ($position eq 'top') {
1.30 raeburn 5583: $$rowtotal ++;
1.34 raeburn 5584: my $rowcount = 0;
1.32 raeburn 5585: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5586: if (ref($rules) eq 'HASH') {
5587: if (keys(%{$rules}) > 0) {
1.32 raeburn 5588: $datatable .= &user_formats_row('username',$settings,$rules,
5589: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5590: $$rowtotal ++;
1.32 raeburn 5591: $rowcount ++;
5592: }
5593: }
5594: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5595: if (ref($idrules) eq 'HASH') {
5596: if (keys(%{$idrules}) > 0) {
5597: $datatable .= &user_formats_row('id',$settings,$idrules,
5598: $idruleorder,$numinrow,$rowcount);
5599: $$rowtotal ++;
5600: $rowcount ++;
1.28 raeburn 5601: }
5602: }
1.39 raeburn 5603: if ($rowcount == 0) {
5604: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5605: $$rowtotal ++;
5606: $rowcount ++;
5607: }
1.34 raeburn 5608: } elsif ($position eq 'middle') {
1.224 raeburn 5609: my @creators = ('author','course','requestcrs');
1.37 raeburn 5610: my ($rules,$ruleorder) =
5611: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5612: my %lt = &usercreation_types();
5613: my %checked;
5614: if (ref($settings) eq 'HASH') {
5615: if (ref($settings->{'cancreate'}) eq 'HASH') {
5616: foreach my $item (@creators) {
5617: $checked{$item} = $settings->{'cancreate'}{$item};
5618: }
5619: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5620: foreach my $item (@creators) {
5621: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5622: $checked{$item} = 'none';
5623: }
5624: }
5625: }
5626: }
5627: my $rownum = 0;
5628: foreach my $item (@creators) {
5629: $rownum ++;
1.224 raeburn 5630: if ($checked{$item} eq '') {
5631: $checked{$item} = 'any';
1.34 raeburn 5632: }
5633: my $css_class;
5634: if ($rownum%2) {
5635: $css_class = '';
5636: } else {
5637: $css_class = ' class="LC_odd_row" ';
5638: }
5639: $datatable .= '<tr'.$css_class.'>'.
5640: '<td><span class="LC_nobreak">'.$lt{$item}.
5641: '</span></td><td align="right">';
1.224 raeburn 5642: my @options = ('any');
5643: if (ref($rules) eq 'HASH') {
5644: if (keys(%{$rules}) > 0) {
5645: push(@options,('official','unofficial'));
1.37 raeburn 5646: }
5647: }
1.224 raeburn 5648: push(@options,'none');
1.37 raeburn 5649: foreach my $option (@options) {
1.50 raeburn 5650: my $type = 'radio';
1.34 raeburn 5651: my $check = ' ';
1.224 raeburn 5652: if ($checked{$item} eq $option) {
5653: $check = ' checked="checked" ';
1.34 raeburn 5654: }
5655: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5656: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5657: $item.'" value="'.$option.'"'.$check.'/> '.
5658: $lt{$option}.'</label> </span>';
5659: }
5660: $datatable .= '</td></tr>';
5661: }
1.28 raeburn 5662: } else {
5663: my @contexts = ('author','course','domain');
5664: my @authtypes = ('int','krb4','krb5','loc');
5665: my %checked;
5666: if (ref($settings) eq 'HASH') {
5667: if (ref($settings->{'authtypes'}) eq 'HASH') {
5668: foreach my $item (@contexts) {
5669: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5670: foreach my $auth (@authtypes) {
5671: if ($settings->{'authtypes'}{$item}{$auth}) {
5672: $checked{$item}{$auth} = ' checked="checked" ';
5673: }
5674: }
5675: }
5676: }
1.27 raeburn 5677: }
1.35 raeburn 5678: } else {
5679: foreach my $item (@contexts) {
1.36 raeburn 5680: foreach my $auth (@authtypes) {
1.35 raeburn 5681: $checked{$item}{$auth} = ' checked="checked" ';
5682: }
5683: }
1.27 raeburn 5684: }
1.28 raeburn 5685: my %title = &context_names();
5686: my %authname = &authtype_names();
5687: my $rownum = 0;
5688: my $css_class;
5689: foreach my $item (@contexts) {
5690: if ($rownum%2) {
5691: $css_class = '';
5692: } else {
5693: $css_class = ' class="LC_odd_row" ';
5694: }
1.30 raeburn 5695: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5696: '<td>'.$title{$item}.
5697: '</td><td class="LC_left_item">'.
5698: '<span class="LC_nobreak">';
5699: foreach my $auth (@authtypes) {
5700: $datatable .= '<label>'.
5701: '<input type="checkbox" name="'.$item.'_auth" '.
5702: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5703: $authname{$auth}.'</label> ';
5704: }
5705: $datatable .= '</span></td></tr>';
5706: $rownum ++;
1.27 raeburn 5707: }
1.30 raeburn 5708: $$rowtotal += $rownum;
1.27 raeburn 5709: }
5710: return $datatable;
5711: }
5712:
1.224 raeburn 5713: sub print_selfcreation {
5714: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 5715: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 5716: if (ref($settings) eq 'HASH') {
5717: if (ref($settings->{'cancreate'}) eq 'HASH') {
5718: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5719: if (ref($createsettings) eq 'HASH') {
5720: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5721: @selfcreate = @{$createsettings->{'selfcreate'}};
5722: } elsif ($createsettings->{'selfcreate'} ne '') {
5723: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5724: @selfcreate = ('email','login','sso');
5725: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5726: @selfcreate = ($createsettings->{'selfcreate'});
5727: }
5728: }
5729: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5730: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5731: }
5732: }
5733: }
5734: }
5735: my %radiohash;
5736: my $numinrow = 4;
5737: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5738: if ($position eq 'top') {
5739: my %choices = &Apache::lonlocal::texthash (
5740: cancreate_login => 'Institutional Login',
5741: cancreate_sso => 'Institutional Single Sign On',
5742: );
5743: my @toggles = sort(keys(%choices));
5744: my %defaultchecked = (
5745: 'cancreate_login' => 'off',
5746: 'cancreate_sso' => 'off',
5747: );
1.228 raeburn 5748: my ($onclick,$itemcount);
1.224 raeburn 5749: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5750: \%choices,$itemcount,$onclick);
1.228 raeburn 5751: $$rowtotal += $itemcount;
5752:
1.224 raeburn 5753: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5754:
5755: if (ref($usertypes) eq 'HASH') {
5756: if (keys(%{$usertypes}) > 0) {
5757: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5758: $dom,$numinrow,$othertitle,
1.228 raeburn 5759: 'statustocreate',$$rowtotal);
1.224 raeburn 5760: $$rowtotal ++;
5761: }
5762: }
1.240 raeburn 5763: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5764: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5765: $fieldtitles{'inststatus'} = &mt('Institutional status');
5766: my $rem;
5767: my $numperrow = 2;
5768: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5769: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5770: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5771: '<td class="LC_left_item">'."\n".
5772: '<table><tr><td>'."\n";
5773: for (my $i=0; $i<@fields; $i++) {
5774: $rem = $i%($numperrow);
5775: if ($rem == 0) {
5776: if ($i > 0) {
5777: $datatable .= '</tr>';
5778: }
5779: $datatable .= '<tr>';
5780: }
5781: my $currval;
1.248 raeburn 5782: if (ref($createsettings) eq 'HASH') {
5783: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5784: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5785: }
1.240 raeburn 5786: }
5787: $datatable .= '<td class="LC_left_item">'.
5788: '<span class="LC_nobreak">'.
5789: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5790: 'value="'.$currval.'" size="10" /> '.
5791: $fieldtitles{$fields[$i]}.'</span></td>';
5792: }
5793: my $colsleft = $numperrow - $rem;
5794: if ($colsleft > 1 ) {
5795: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5796: ' </td>';
5797: } elsif ($colsleft == 1) {
5798: $datatable .= '<td class="LC_left_item"> </td>';
5799: }
5800: $datatable .= '</tr></table></td></tr>';
5801: $$rowtotal ++;
1.224 raeburn 5802: } elsif ($position eq 'middle') {
5803: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5804: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5805: $usertypes->{'default'} = $othertitle;
5806: if (ref($types) eq 'ARRAY') {
5807: push(@{$types},'default');
5808: $usertypes->{'default'} = $othertitle;
5809: foreach my $status (@{$types}) {
5810: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5811: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5812: $$rowtotal ++;
1.224 raeburn 5813: }
5814: }
5815: } else {
1.236 raeburn 5816: my %choices = &Apache::lonlocal::texthash (
5817: cancreate_email => 'E-mail address as username',
5818: );
5819: my @toggles = sort(keys(%choices));
5820: my %defaultchecked = (
5821: 'cancreate_email' => 'off',
5822: );
5823: my $itemcount = 0;
5824: my $display = 'none';
5825: if (grep(/^\Qemail\E$/,@selfcreate)) {
5826: $display = 'block';
5827: }
5828: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5829: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5830: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5831: my $usertypes = {};
5832: my $order = [];
5833: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5834: $usertypes = $domdefaults{'inststatustypes'};
5835: $order = $domdefaults{'inststatusguest'};
5836: }
5837: if (ref($order) eq 'ARRAY') {
5838: push(@{$order},'default');
5839: if (@{$order} > 1) {
5840: $usertypes->{'default'} = &mt('Other users');
5841: $additional .= '<table><tr>';
5842: foreach my $status (@{$order}) {
5843: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5844: }
5845: $additional .= '</tr><tr>';
5846: foreach my $status (@{$order}) {
5847: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5848: }
1.236 raeburn 5849: $additional .= '</tr></table>';
1.224 raeburn 5850: } else {
1.236 raeburn 5851: $usertypes->{'default'} = &mt('All users');
5852: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5853: }
5854: }
1.236 raeburn 5855: $additional .= '</div>'."\n";
5856:
5857: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5858: \%choices,$$rowtotal,$onclick,$additional);
5859: $$rowtotal ++;
1.236 raeburn 5860: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5861: $$rowtotal ++;
1.224 raeburn 5862: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5863: $numinrow = 1;
1.236 raeburn 5864: if (ref($order) eq 'ARRAY') {
5865: foreach my $status (@{$order}) {
1.228 raeburn 5866: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5867: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5868: $$rowtotal ++;
5869: }
5870: }
1.224 raeburn 5871: my ($emailrules,$emailruleorder) =
5872: &Apache::lonnet::inst_userrules($dom,'email');
5873: if (ref($emailrules) eq 'HASH') {
5874: if (keys(%{$emailrules}) > 0) {
5875: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5876: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5877: $$rowtotal ++;
5878: }
5879: }
1.228 raeburn 5880: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5881: }
5882: return $datatable;
5883: }
5884:
1.236 raeburn 5885: sub email_as_username {
5886: my ($rowtotal,$processing,$type) = @_;
5887: my %choices =
5888: &Apache::lonlocal::texthash (
5889: automatic => 'Automatic approval',
5890: approval => 'Queued for approval',
5891: );
5892: my $output;
5893: foreach my $option ('automatic','approval') {
5894: my $checked;
5895: if (ref($processing) eq 'HASH') {
5896: if ($type eq '') {
5897: if (!exists($processing->{'default'})) {
5898: if ($option eq 'automatic') {
5899: $checked = ' checked="checked"';
5900: }
5901: } else {
5902: if ($processing->{'default'} eq $option) {
5903: $checked = ' checked="checked"';
5904: }
5905: }
5906: } else {
5907: if (!exists($processing->{$type})) {
5908: if ($option eq 'automatic') {
5909: $checked = ' checked="checked"';
5910: }
5911: } else {
5912: if ($processing->{$type} eq $option) {
5913: $checked = ' checked="checked"';
5914: }
5915: }
5916: }
5917: } elsif ($option eq 'automatic') {
5918: $checked = ' checked="checked"';
5919: }
5920: my $name = 'cancreate_emailprocess';
5921: if (($type ne '') && ($type ne 'default')) {
5922: $name .= '_'.$type;
5923: }
5924: $output .= '<span class="LC_nobreak"><label>'.
5925: '<input type="radio" name="'.$name.'"'.
5926: $checked.' value="'.$option.'" />'.
5927: $choices{$option}.'</label></span>';
5928: if ($type eq '') {
5929: $output .= ' ';
5930: } else {
5931: $output .= '<br />';
5932: }
5933: }
5934: $$rowtotal ++;
5935: return $output;
5936: }
5937:
1.165 raeburn 5938: sub captcha_choice {
1.169 raeburn 5939: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5940: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5941: $vertext,$currver);
1.165 raeburn 5942: my %lt = &captcha_phrases();
5943: $keyentry = 'hidden';
5944: if ($context eq 'cancreate') {
1.224 raeburn 5945: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5946: } elsif ($context eq 'login') {
5947: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5948: }
5949: if (ref($settings) eq 'HASH') {
5950: if ($settings->{'captcha'}) {
5951: $checked{$settings->{'captcha'}} = ' checked="checked"';
5952: } else {
5953: $checked{'original'} = ' checked="checked"';
5954: }
5955: if ($settings->{'captcha'} eq 'recaptcha') {
5956: $pubtext = $lt{'pub'};
5957: $privtext = $lt{'priv'};
5958: $keyentry = 'text';
1.269 raeburn 5959: $vertext = $lt{'ver'};
5960: $currver = $settings->{'recaptchaversion'};
5961: if ($currver ne '2') {
5962: $currver = 1;
5963: }
1.165 raeburn 5964: }
5965: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5966: $currpub = $settings->{'recaptchakeys'}{'public'};
5967: $currpriv = $settings->{'recaptchakeys'}{'private'};
5968: }
5969: } else {
5970: $checked{'original'} = ' checked="checked"';
5971: }
1.169 raeburn 5972: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5973: my $output = '<tr'.$css_class.'>'.
5974: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 5975: '<table><tr><td>'."\n";
5976: foreach my $option ('original','recaptcha','notused') {
5977: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5978: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5979: $lt{$option}.'</label></span>';
5980: unless ($option eq 'notused') {
5981: $output .= (' 'x2)."\n";
5982: }
5983: }
5984: #
5985: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5986: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 5987: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 5988: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 5989: #
1.165 raeburn 5990: $output .= '</td></tr>'."\n".
5991: '<tr><td>'."\n".
5992: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5993: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5994: $currpub.'" size="40" /></span><br />'."\n".
5995: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5996: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 5997: $currpriv.'" size="40" /></span><br />'.
5998: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5999: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6000: $currver.'" size="3" /></span><br />'.
6001: '</td></tr></table>'."\n".
1.165 raeburn 6002: '</td></tr>';
6003: return $output;
6004: }
6005:
1.32 raeburn 6006: sub user_formats_row {
6007: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
6008: my $output;
6009: my %text = (
6010: 'username' => 'new usernames',
6011: 'id' => 'IDs',
1.45 raeburn 6012: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 6013: );
6014: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6015: $output = '<tr '.$css_class.'>'.
1.63 raeburn 6016: '<td><span class="LC_nobreak">';
6017: if ($type eq 'email') {
6018: $output .= &mt("Formats disallowed for $text{$type}: ");
6019: } else {
6020: $output .= &mt("Format rules to check for $text{$type}: ");
6021: }
6022: $output .= '</span></td>'.
6023: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 6024: my $rem;
6025: if (ref($ruleorder) eq 'ARRAY') {
6026: for (my $i=0; $i<@{$ruleorder}; $i++) {
6027: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6028: my $rem = $i%($numinrow);
6029: if ($rem == 0) {
6030: if ($i > 0) {
6031: $output .= '</tr>';
6032: }
6033: $output .= '<tr>';
6034: }
6035: my $check = ' ';
1.39 raeburn 6036: if (ref($settings) eq 'HASH') {
6037: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6038: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6039: $check = ' checked="checked" ';
6040: }
1.27 raeburn 6041: }
6042: }
6043: $output .= '<td class="LC_left_item">'.
6044: '<span class="LC_nobreak"><label>'.
1.32 raeburn 6045: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 6046: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6047: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6048: }
6049: }
6050: $rem = @{$ruleorder}%($numinrow);
6051: }
6052: my $colsleft = $numinrow - $rem;
6053: if ($colsleft > 1 ) {
6054: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6055: ' </td>';
6056: } elsif ($colsleft == 1) {
6057: $output .= '<td class="LC_left_item"> </td>';
6058: }
6059: $output .= '</tr></table></td></tr>';
6060: return $output;
6061: }
6062:
1.34 raeburn 6063: sub usercreation_types {
6064: my %lt = &Apache::lonlocal::texthash (
6065: author => 'When adding a co-author',
6066: course => 'When adding a user to a course',
1.100 raeburn 6067: requestcrs => 'When requesting a course',
1.34 raeburn 6068: any => 'Any',
6069: official => 'Institutional only ',
6070: unofficial => 'Non-institutional only',
6071: none => 'None',
6072: );
6073: return %lt;
1.48 raeburn 6074: }
1.34 raeburn 6075:
1.224 raeburn 6076: sub selfcreation_types {
6077: my %lt = &Apache::lonlocal::texthash (
6078: selfcreate => 'User creates own account',
6079: any => 'Any',
6080: official => 'Institutional only ',
6081: unofficial => 'Non-institutional only',
6082: email => 'E-mail address',
6083: login => 'Institutional Login',
6084: sso => 'SSO',
6085: );
6086: }
6087:
1.28 raeburn 6088: sub authtype_names {
6089: my %lt = &Apache::lonlocal::texthash(
6090: int => 'Internal',
6091: krb4 => 'Kerberos 4',
6092: krb5 => 'Kerberos 5',
6093: loc => 'Local',
6094: );
6095: return %lt;
6096: }
6097:
6098: sub context_names {
6099: my %context_title = &Apache::lonlocal::texthash(
6100: author => 'Creating users when an Author',
6101: course => 'Creating users when in a course',
6102: domain => 'Creating users when a Domain Coordinator',
6103: );
6104: return %context_title;
6105: }
6106:
1.33 raeburn 6107: sub print_usermodification {
6108: my ($position,$dom,$settings,$rowtotal) = @_;
6109: my $numinrow = 4;
6110: my ($context,$datatable,$rowcount);
6111: if ($position eq 'top') {
6112: $rowcount = 0;
6113: $context = 'author';
6114: foreach my $role ('ca','aa') {
6115: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6116: $numinrow,$rowcount);
6117: $$rowtotal ++;
6118: $rowcount ++;
6119: }
1.230 raeburn 6120: } elsif ($position eq 'bottom') {
1.33 raeburn 6121: $context = 'course';
6122: $rowcount = 0;
6123: foreach my $role ('st','ep','ta','in','cr') {
6124: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6125: $numinrow,$rowcount);
6126: $$rowtotal ++;
6127: $rowcount ++;
6128: }
6129: }
6130: return $datatable;
6131: }
6132:
1.43 raeburn 6133: sub print_defaults {
1.236 raeburn 6134: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6135: my $rownum = 0;
1.294 ! raeburn 6136: my ($datatable,$css_class,$titles);
! 6137: unless ($position eq 'bottom') {
! 6138: $titles = &defaults_titles($dom);
! 6139: }
1.236 raeburn 6140: if ($position eq 'top') {
6141: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6142: 'datelocale_def','portal_def');
6143: my %defaults;
6144: if (ref($settings) eq 'HASH') {
6145: %defaults = %{$settings};
1.43 raeburn 6146: } else {
1.236 raeburn 6147: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6148: foreach my $item (@items) {
6149: $defaults{$item} = $domdefaults{$item};
6150: }
1.43 raeburn 6151: }
1.236 raeburn 6152: foreach my $item (@items) {
6153: if ($rownum%2) {
6154: $css_class = '';
6155: } else {
6156: $css_class = ' class="LC_odd_row" ';
6157: }
6158: $datatable .= '<tr'.$css_class.'>'.
6159: '<td><span class="LC_nobreak">'.$titles->{$item}.
6160: '</span></td><td class="LC_right_item" colspan="3">';
6161: if ($item eq 'auth_def') {
6162: my @authtypes = ('internal','krb4','krb5','localauth');
6163: my %shortauth = (
6164: internal => 'int',
6165: krb4 => 'krb4',
6166: krb5 => 'krb5',
6167: localauth => 'loc'
6168: );
6169: my %authnames = &authtype_names();
6170: foreach my $auth (@authtypes) {
6171: my $checked = ' ';
6172: if ($defaults{$item} eq $auth) {
6173: $checked = ' checked="checked" ';
6174: }
6175: $datatable .= '<label><input type="radio" name="'.$item.
6176: '" value="'.$auth.'"'.$checked.'/>'.
6177: $authnames{$shortauth{$auth}}.'</label> ';
6178: }
6179: } elsif ($item eq 'timezone_def') {
6180: my $includeempty = 1;
6181: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6182: } elsif ($item eq 'datelocale_def') {
6183: my $includeempty = 1;
6184: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6185: } elsif ($item eq 'lang_def') {
1.263 raeburn 6186: my $includeempty = 1;
6187: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 6188: } else {
6189: my $size;
6190: if ($item eq 'portal_def') {
6191: $size = ' size="25"';
6192: }
6193: $datatable .= '<input type="text" name="'.$item.'" value="'.
6194: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 6195: }
1.236 raeburn 6196: $datatable .= '</td></tr>';
6197: $rownum ++;
6198: }
1.294 ! raeburn 6199: } elsif ($position eq 'middle') {
! 6200: my @items = ('intauth_cost','intauth_check','intauth_switch');
! 6201: my %defaults;
! 6202: if (ref($settings) eq 'HASH') {
! 6203: %defaults = %{$settings};
! 6204: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
! 6205: $defaults{'intauth_cost'} = 10;
! 6206: }
! 6207: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
! 6208: $defaults{'intauth_check'} = 0;
! 6209: }
! 6210: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
! 6211: $defaults{'intauth_switch'} = 0;
! 6212: }
! 6213: } else {
! 6214: %defaults = (
! 6215: 'intauth_cost' => 10,
! 6216: 'intauth_check' => 0,
! 6217: 'intauth_switch' => 0,
! 6218: );
! 6219: }
! 6220: foreach my $item (@items) {
! 6221: if ($rownum%2) {
! 6222: $css_class = '';
! 6223: } else {
! 6224: $css_class = ' class="LC_odd_row" ';
! 6225: }
! 6226: $datatable .= '<tr'.$css_class.'>'.
! 6227: '<td><span class="LC_nobreak">'.$titles->{$item}.
! 6228: '</span></td><td class="LC_left_item" colspan="3">';
! 6229: if ($item eq 'intauth_switch') {
! 6230: my @options = (0,1,2);
! 6231: my %optiondesc = &Apache::lonlocal::texthash (
! 6232: 0 => 'No',
! 6233: 1 => 'Yes',
! 6234: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
! 6235: );
! 6236: $datatable .= '<table width="100%">';
! 6237: foreach my $option (@options) {
! 6238: my $checked = ' ';
! 6239: if ($defaults{$item} eq $option) {
! 6240: $checked = ' checked="checked"';
! 6241: }
! 6242: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
! 6243: '<label><input type="radio" name="'.$item.
! 6244: '" value="'.$option.'"'.$checked.' />'.
! 6245: $optiondesc{$option}.'</label></span></td></tr>';
! 6246: }
! 6247: $datatable .= '</table>';
! 6248: } elsif ($item eq 'intauth_check') {
! 6249: my @options = (0,1,2);
! 6250: my %optiondesc = &Apache::lonlocal::texthash (
! 6251: 0 => 'No',
! 6252: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
! 6253: 2 => 'Yes, disallow login if stored cost is less than domain default',
! 6254: );
! 6255: $datatable .= '<table wisth="100%">';
! 6256: foreach my $option (@options) {
! 6257: my $checked = ' ';
! 6258: my $onclick;
! 6259: if ($defaults{$item} eq $option) {
! 6260: $checked = ' checked="checked"';
! 6261: }
! 6262: if ($option == 2) {
! 6263: $onclick = ' onclick="javascript:warnIntAuth(this);"';
! 6264: }
! 6265: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
! 6266: '<label><input type="radio" name="'.$item.
! 6267: '" value="'.$option.'"'.$checked.$onclick.' />'.
! 6268: $optiondesc{$option}.'</label></span></td></tr>';
! 6269: }
! 6270: $datatable .= '</table>';
! 6271: } else {
! 6272: $datatable .= '<input type="text" name="'.$item.'" value="'.
! 6273: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
! 6274: }
! 6275: $datatable .= '</td></tr>';
! 6276: $rownum ++;
! 6277: }
1.236 raeburn 6278: } else {
1.294 ! raeburn 6279: my %defaults;
1.236 raeburn 6280: if (ref($settings) eq 'HASH') {
6281: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
6282: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
6283: my $maxnum = @{$settings->{'inststatusorder'}};
6284: for (my $i=0; $i<$maxnum; $i++) {
6285: $css_class = $rownum%2?' class="LC_odd_row"':'';
6286: my $item = $settings->{'inststatusorder'}->[$i];
6287: my $title = $settings->{'inststatustypes'}->{$item};
6288: my $guestok;
6289: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
6290: $guestok = 1;
6291: }
6292: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6293: $datatable .= '<tr'.$css_class.'>'.
6294: '<td><span class="LC_nobreak">'.
6295: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6296: for (my $k=0; $k<=$maxnum; $k++) {
6297: my $vpos = $k+1;
6298: my $selstr;
6299: if ($k == $i) {
6300: $selstr = ' selected="selected" ';
6301: }
6302: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6303: }
6304: my ($checkedon,$checkedoff);
6305: $checkedoff = ' checked="checked"';
6306: if ($guestok) {
6307: $checkedon = $checkedoff;
6308: $checkedoff = '';
6309: }
6310: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6311: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6312: &mt('delete').'</span></td>'.
6313: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6314: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
6315: '</span></td>'.
6316: '<td class="LC_right_item"><span class="LC_nobreak">'.
6317: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
6318: &mt('Yes').'</label>'.(' 'x2).
6319: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
6320: &mt('No').'</label></span></td></tr>';
6321: }
6322: $css_class = $rownum%2?' class="LC_odd_row"':'';
6323: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6324: $datatable .= '<tr '.$css_class.'>'.
6325: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6326: for (my $k=0; $k<=$maxnum; $k++) {
6327: my $vpos = $k+1;
6328: my $selstr;
6329: if ($k == $maxnum) {
6330: $selstr = ' selected="selected" ';
6331: }
6332: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6333: }
6334: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 6335: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 6336: ' '.&mt('(new)').
6337: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6338: &mt('Name displayed:').
6339: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6340: '<td class="LC_right_item"><span class="LC_nobreak">'.
6341: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
6342: &mt('Yes').'</label>'.(' 'x2).
6343: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
6344: &mt('No').'</label></span></td></tr>';
6345: '</tr>'."\n";
6346: $rownum ++;
1.141 raeburn 6347: }
1.43 raeburn 6348: }
6349: }
6350: $$rowtotal += $rownum;
6351: return $datatable;
6352: }
6353:
1.168 raeburn 6354: sub get_languages_hash {
6355: my %langchoices;
6356: foreach my $id (&Apache::loncommon::languageids()) {
6357: my $code = &Apache::loncommon::supportedlanguagecode($id);
6358: if ($code ne '') {
6359: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6360: }
6361: }
6362: return %langchoices;
6363: }
6364:
1.43 raeburn 6365: sub defaults_titles {
1.141 raeburn 6366: my ($dom) = @_;
1.43 raeburn 6367: my %titles = &Apache::lonlocal::texthash (
6368: 'auth_def' => 'Default authentication type',
6369: 'auth_arg_def' => 'Default authentication argument',
6370: 'lang_def' => 'Default language',
1.54 raeburn 6371: 'timezone_def' => 'Default timezone',
1.68 raeburn 6372: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6373: 'portal_def' => 'Portal/Default URL',
1.294 ! raeburn 6374: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
! 6375: 'intauth_check' => 'Check bcrypt cost if authenticated',
! 6376: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6377: );
1.141 raeburn 6378: if ($dom) {
6379: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6380: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6381: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6382: $protocol = 'http' if ($protocol ne 'https');
6383: if ($uint_dom) {
6384: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6385: $uint_dom);
6386: }
6387: }
1.43 raeburn 6388: return (\%titles);
6389: }
6390:
1.46 raeburn 6391: sub print_scantronformat {
6392: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6393: my $itemcount = 1;
1.60 raeburn 6394: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6395: %confhash);
1.46 raeburn 6396: my $switchserver = &check_switchserver($dom,$confname);
6397: my %lt = &Apache::lonlocal::texthash (
1.95 www 6398: default => 'Default bubblesheet format file error',
6399: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6400: );
6401: my %scantronfiles = (
6402: default => 'default.tab',
6403: custom => 'custom.tab',
6404: );
6405: foreach my $key (keys(%scantronfiles)) {
6406: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6407: .$scantronfiles{$key};
6408: }
6409: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6410: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6411: if (!$switchserver) {
6412: my $servadm = $r->dir_config('lonAdmEMail');
6413: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6414: if ($configuserok eq 'ok') {
6415: if ($author_ok eq 'ok') {
6416: my %legacyfile = (
6417: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6418: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6419: );
6420: my %md5chk;
6421: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6422: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6423: chomp($md5chk{$type});
1.46 raeburn 6424: }
6425: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6426: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6427: ($scantronurls{$type},my $error) =
1.46 raeburn 6428: &legacy_scantronformat($r,$dom,$confname,
6429: $type,$legacyfile{$type},
6430: $scantronurls{$type},
6431: $scantronfiles{$type});
1.60 raeburn 6432: if ($error ne '') {
6433: $error{$type} = $error;
6434: }
6435: }
6436: if (keys(%error) == 0) {
6437: $is_custom = 1;
6438: $confhash{'scantron'}{'scantronformat'} =
6439: $scantronurls{'custom'};
6440: my $putresult =
6441: &Apache::lonnet::put_dom('configuration',
6442: \%confhash,$dom);
6443: if ($putresult ne 'ok') {
6444: $error{'custom'} =
6445: '<span class="LC_error">'.
6446: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6447: }
1.46 raeburn 6448: }
6449: } else {
1.60 raeburn 6450: ($scantronurls{'default'},my $error) =
1.46 raeburn 6451: &legacy_scantronformat($r,$dom,$confname,
6452: 'default',$legacyfile{'default'},
6453: $scantronurls{'default'},
6454: $scantronfiles{'default'});
1.60 raeburn 6455: if ($error eq '') {
6456: $confhash{'scantron'}{'scantronformat'} = '';
6457: my $putresult =
6458: &Apache::lonnet::put_dom('configuration',
6459: \%confhash,$dom);
6460: if ($putresult ne 'ok') {
6461: $error{'default'} =
6462: '<span class="LC_error">'.
6463: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6464: }
6465: } else {
6466: $error{'default'} = $error;
6467: }
1.46 raeburn 6468: }
6469: }
6470: }
6471: } else {
1.95 www 6472: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6473: }
6474: }
6475: if (ref($settings) eq 'HASH') {
6476: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6477: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6478: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6479: $scantronurl = '';
6480: } else {
6481: $scantronurl = $settings->{'scantronformat'};
6482: }
6483: $is_custom = 1;
6484: } else {
6485: $scantronurl = $scantronurls{'default'};
6486: }
6487: } else {
1.60 raeburn 6488: if ($is_custom) {
6489: $scantronurl = $scantronurls{'custom'};
6490: } else {
6491: $scantronurl = $scantronurls{'default'};
6492: }
1.46 raeburn 6493: }
6494: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6495: $datatable .= '<tr'.$css_class.'>';
6496: if (!$is_custom) {
1.65 raeburn 6497: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6498: '<span class="LC_nobreak">';
1.46 raeburn 6499: if ($scantronurl) {
1.199 raeburn 6500: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6501: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6502: } else {
6503: $datatable = &mt('File unavailable for display');
6504: }
1.65 raeburn 6505: $datatable .= '</span></td>';
1.60 raeburn 6506: if (keys(%error) == 0) {
6507: $datatable .= '<td valign="bottom">';
6508: if (!$switchserver) {
6509: $datatable .= &mt('Upload:').'<br />';
6510: }
6511: } else {
6512: my $errorstr;
6513: foreach my $key (sort(keys(%error))) {
6514: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6515: }
6516: $datatable .= '<td>'.$errorstr;
6517: }
1.46 raeburn 6518: } else {
6519: if (keys(%error) > 0) {
6520: my $errorstr;
6521: foreach my $key (sort(keys(%error))) {
6522: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6523: }
1.60 raeburn 6524: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6525: } elsif ($scantronurl) {
1.199 raeburn 6526: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
6527: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6528: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 6529: $link.
6530: '<label><input type="checkbox" name="scantronformat_del"'.
6531: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6532: '<td><span class="LC_nobreak"> '.
6533: &mt('Replace:').'</span><br />';
1.46 raeburn 6534: }
6535: }
6536: if (keys(%error) == 0) {
6537: if ($switchserver) {
6538: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6539: } else {
1.65 raeburn 6540: $datatable .='<span class="LC_nobreak"> '.
6541: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6542: }
6543: }
6544: $datatable .= '</td></tr>';
6545: $$rowtotal ++;
6546: return $datatable;
6547: }
6548:
6549: sub legacy_scantronformat {
6550: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6551: my ($url,$error);
6552: my @statinfo = &Apache::lonnet::stat_file($newurl);
6553: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6554: (my $result,$url) =
6555: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6556: '','',$newfile);
6557: if ($result ne 'ok') {
1.130 raeburn 6558: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6559: }
6560: }
6561: return ($url,$error);
6562: }
1.43 raeburn 6563:
1.49 raeburn 6564: sub print_coursecategories {
1.57 raeburn 6565: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6566: my $datatable;
6567: if ($position eq 'top') {
1.238 raeburn 6568: my (%checked);
6569: my @catitems = ('unauth','auth');
6570: my @cattypes = ('std','domonly','codesrch','none');
6571: $checked{'unauth'} = 'std';
6572: $checked{'auth'} = 'std';
6573: if (ref($settings) eq 'HASH') {
6574: foreach my $type (@cattypes) {
6575: if ($type eq $settings->{'unauth'}) {
6576: $checked{'unauth'} = $type;
6577: }
6578: if ($type eq $settings->{'auth'}) {
6579: $checked{'auth'} = $type;
6580: }
6581: }
6582: }
6583: my %lt = &Apache::lonlocal::texthash (
6584: unauth => 'Catalog type for unauthenticated users',
6585: auth => 'Catalog type for authenticated users',
6586: none => 'No catalog',
6587: std => 'Standard catalog',
6588: domonly => 'Domain-only catalog',
6589: codesrch => "Code search form",
6590: );
6591: my $itemcount = 0;
6592: foreach my $item (@catitems) {
6593: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6594: $datatable .= '<tr '.$css_class.'>'.
6595: '<td>'.$lt{$item}.'</td>'.
6596: '<td class="LC_right_item"><span class="LC_nobreak">';
6597: foreach my $type (@cattypes) {
6598: my $ischecked;
6599: if ($checked{$item} eq $type) {
6600: $ischecked=' checked="checked"';
6601: }
6602: $datatable .= '<label>'.
6603: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6604: ' />'.$lt{$type}.'</label> ';
6605: }
6606: $datatable .= '</td></tr>';
6607: $itemcount ++;
6608: }
6609: $$rowtotal += $itemcount;
6610: } elsif ($position eq 'middle') {
1.57 raeburn 6611: my $toggle_cats_crs = ' ';
6612: my $toggle_cats_dom = ' checked="checked" ';
6613: my $can_cat_crs = ' ';
6614: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6615: my $toggle_catscomm_comm = ' ';
6616: my $toggle_catscomm_dom = ' checked="checked" ';
6617: my $can_catcomm_comm = ' ';
6618: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 6619: my $toggle_catsplace_place = ' ';
6620: my $toggle_catsplace_dom = ' checked="checked" ';
6621: my $can_catplace_place = ' ';
6622: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 6623:
1.57 raeburn 6624: if (ref($settings) eq 'HASH') {
6625: if ($settings->{'togglecats'} eq 'crs') {
6626: $toggle_cats_crs = $toggle_cats_dom;
6627: $toggle_cats_dom = ' ';
6628: }
6629: if ($settings->{'categorize'} eq 'crs') {
6630: $can_cat_crs = $can_cat_dom;
6631: $can_cat_dom = ' ';
6632: }
1.120 raeburn 6633: if ($settings->{'togglecatscomm'} eq 'comm') {
6634: $toggle_catscomm_comm = $toggle_catscomm_dom;
6635: $toggle_catscomm_dom = ' ';
6636: }
6637: if ($settings->{'categorizecomm'} eq 'comm') {
6638: $can_catcomm_comm = $can_catcomm_dom;
6639: $can_catcomm_dom = ' ';
6640: }
1.272 raeburn 6641: if ($settings->{'togglecatsplace'} eq 'place') {
6642: $toggle_catsplace_place = $toggle_catsplace_dom;
6643: $toggle_catsplace_dom = ' ';
6644: }
6645: if ($settings->{'categorizeplace'} eq 'place') {
6646: $can_catplace_place = $can_catplace_dom;
6647: $can_catplace_dom = ' ';
6648: }
1.57 raeburn 6649: }
6650: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 6651: togglecats => 'Show/Hide a course in catalog',
6652: togglecatscomm => 'Show/Hide a community in catalog',
6653: togglecatsplace => 'Show/Hide a placement test in catalog',
6654: categorize => 'Assign a category to a course',
6655: categorizecomm => 'Assign a category to a community',
6656: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 6657: );
6658: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 6659: dom => 'Set in Domain',
6660: crs => 'Set in Course',
6661: comm => 'Set in Community',
6662: place => 'Set in Placement Test',
1.57 raeburn 6663: );
6664: $datatable = '<tr class="LC_odd_row">'.
6665: '<td>'.$title{'togglecats'}.'</td>'.
6666: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6667: '<input type="radio" name="togglecats"'.
6668: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6669: '<label><input type="radio" name="togglecats"'.
6670: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6671: '</tr><tr>'.
6672: '<td>'.$title{'categorize'}.'</td>'.
6673: '<td class="LC_right_item"><span class="LC_nobreak">'.
6674: '<label><input type="radio" name="categorize"'.
6675: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6676: '<label><input type="radio" name="categorize"'.
6677: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6678: '</tr><tr class="LC_odd_row">'.
6679: '<td>'.$title{'togglecatscomm'}.'</td>'.
6680: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6681: '<input type="radio" name="togglecatscomm"'.
6682: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6683: '<label><input type="radio" name="togglecatscomm"'.
6684: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6685: '</tr><tr>'.
6686: '<td>'.$title{'categorizecomm'}.'</td>'.
6687: '<td class="LC_right_item"><span class="LC_nobreak">'.
6688: '<label><input type="radio" name="categorizecomm"'.
6689: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6690: '<label><input type="radio" name="categorizecomm"'.
6691: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 6692: '</tr><tr>'.
6693: '<td>'.$title{'togglecatsplace'}.'</td>'.
6694: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6695: '<input type="radio" name="togglecatsplace"'.
6696: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6697: '<label><input type="radio" name="togglecatscomm"'.
6698: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
6699: '</tr><tr>'.
6700: '<td>'.$title{'categorizeplace'}.'</td>'.
6701: '<td class="LC_right_item"><span class="LC_nobreak">'.
6702: '<label><input type="radio" name="categorizeplace"'.
6703: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6704: '<label><input type="radio" name="categorizeplace"'.
6705: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 6706: '</tr>';
1.272 raeburn 6707: $$rowtotal += 6;
1.57 raeburn 6708: } else {
6709: my $css_class;
6710: my $itemcount = 1;
6711: my $cathash;
6712: if (ref($settings) eq 'HASH') {
6713: $cathash = $settings->{'cats'};
6714: }
6715: if (ref($cathash) eq 'HASH') {
6716: my (@cats,@trails,%allitems,%idx,@jsarray);
6717: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6718: \%allitems,\%idx,\@jsarray);
6719: my $maxdepth = scalar(@cats);
6720: my $colattrib = '';
6721: if ($maxdepth > 2) {
6722: $colattrib = ' colspan="2" ';
6723: }
6724: my @path;
6725: if (@cats > 0) {
6726: if (ref($cats[0]) eq 'ARRAY') {
6727: my $numtop = @{$cats[0]};
6728: my $maxnum = $numtop;
1.120 raeburn 6729: my %default_names = (
6730: instcode => &mt('Official courses'),
6731: communities => &mt('Communities'),
1.272 raeburn 6732: placement => &mt('Placement Tests'),
1.120 raeburn 6733: );
6734:
6735: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6736: ($cathash->{'instcode::0'} eq '') ||
6737: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 6738: ($cathash->{'communities::0'} eq '') ||
6739: (!grep(/^placement$/,@{$cats[0]})) ||
6740: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 6741: $maxnum ++;
6742: }
6743: my $lastidx;
6744: for (my $i=0; $i<$numtop; $i++) {
6745: my $parent = $cats[0][$i];
6746: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6747: my $item = &escape($parent).'::0';
6748: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6749: $lastidx = $idx{$item};
6750: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6751: .'<select name="'.$item.'"'.$chgstr.'>';
6752: for (my $k=0; $k<=$maxnum; $k++) {
6753: my $vpos = $k+1;
6754: my $selstr;
6755: if ($k == $i) {
6756: $selstr = ' selected="selected" ';
6757: }
6758: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6759: }
1.214 raeburn 6760: $datatable .= '</select></span></td><td>';
1.272 raeburn 6761: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 6762: $datatable .= '<span class="LC_nobreak">'
6763: .$default_names{$parent}.'</span>';
6764: if ($parent eq 'instcode') {
6765: $datatable .= '<br /><span class="LC_nobreak">('
6766: .&mt('with institutional codes')
6767: .')</span></td><td'.$colattrib.'>';
6768: } else {
6769: $datatable .= '<table><tr><td>';
6770: }
6771: $datatable .= '<span class="LC_nobreak">'
6772: .'<label><input type="radio" name="'
6773: .$parent.'" value="1" checked="checked" />'
6774: .&mt('Display').'</label>';
6775: if ($parent eq 'instcode') {
6776: $datatable .= ' ';
6777: } else {
6778: $datatable .= '</span></td></tr><tr><td>'
6779: .'<span class="LC_nobreak">';
6780: }
6781: $datatable .= '<label><input type="radio" name="'
6782: .$parent.'" value="0" />'
6783: .&mt('Do not display').'</label></span>';
1.272 raeburn 6784: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 6785: $datatable .= '</td></tr></table>';
6786: }
6787: $datatable .= '</td>';
1.57 raeburn 6788: } else {
6789: $datatable .= $parent
1.214 raeburn 6790: .' <span class="LC_nobreak"><label>'
6791: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6792: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6793: }
6794: my $depth = 1;
6795: push(@path,$parent);
6796: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6797: pop(@path);
6798: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6799: $itemcount ++;
6800: }
1.48 raeburn 6801: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6802: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6803: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6804: for (my $k=0; $k<=$maxnum; $k++) {
6805: my $vpos = $k+1;
6806: my $selstr;
1.57 raeburn 6807: if ($k == $numtop) {
1.48 raeburn 6808: $selstr = ' selected="selected" ';
6809: }
6810: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6811: }
1.59 bisitz 6812: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6813: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6814: .'</tr>'."\n";
1.48 raeburn 6815: $itemcount ++;
1.272 raeburn 6816: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6817: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6818: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6819: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6820: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6821: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6822: for (my $k=0; $k<=$maxnum; $k++) {
6823: my $vpos = $k+1;
6824: my $selstr;
6825: if ($k == $maxnum) {
6826: $selstr = ' selected="selected" ';
6827: }
6828: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6829: }
1.120 raeburn 6830: $datatable .= '</select></span></td>'.
6831: '<td><span class="LC_nobreak">'.
6832: $default_names{$default}.'</span>';
6833: if ($default eq 'instcode') {
6834: $datatable .= '<br /><span class="LC_nobreak">('
6835: .&mt('with institutional codes').')</span>';
6836: }
6837: $datatable .= '</td>'
6838: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6839: .&mt('Display').'</label> '
6840: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6841: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6842: }
6843: }
6844: }
1.57 raeburn 6845: } else {
6846: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6847: }
6848: } else {
1.238 raeburn 6849: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6850: .&initialize_categories($itemcount);
1.48 raeburn 6851: }
1.57 raeburn 6852: $$rowtotal += $itemcount;
1.48 raeburn 6853: }
6854: return $datatable;
6855: }
6856:
1.69 raeburn 6857: sub print_serverstatuses {
6858: my ($dom,$settings,$rowtotal) = @_;
6859: my $datatable;
6860: my @pages = &serverstatus_pages();
6861: my (%namedaccess,%machineaccess);
6862: foreach my $type (@pages) {
6863: $namedaccess{$type} = '';
6864: $machineaccess{$type}= '';
6865: }
6866: if (ref($settings) eq 'HASH') {
6867: foreach my $type (@pages) {
6868: if (exists($settings->{$type})) {
6869: if (ref($settings->{$type}) eq 'HASH') {
6870: foreach my $key (keys(%{$settings->{$type}})) {
6871: if ($key eq 'namedusers') {
6872: $namedaccess{$type} = $settings->{$type}->{$key};
6873: } elsif ($key eq 'machines') {
6874: $machineaccess{$type} = $settings->{$type}->{$key};
6875: }
6876: }
6877: }
6878: }
6879: }
6880: }
1.81 raeburn 6881: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6882: my $rownum = 0;
6883: my $css_class;
6884: foreach my $type (@pages) {
6885: $rownum ++;
6886: $css_class = $rownum%2?' class="LC_odd_row"':'';
6887: $datatable .= '<tr'.$css_class.'>'.
6888: '<td><span class="LC_nobreak">'.
6889: $titles->{$type}.'</span></td>'.
6890: '<td class="LC_left_item">'.
6891: '<input type="text" name="'.$type.'_namedusers" '.
6892: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6893: '<td class="LC_right_item">'.
6894: '<span class="LC_nobreak">'.
6895: '<input type="text" name="'.$type.'_machines" '.
6896: 'value="'.$machineaccess{$type}.'" size="10" />'.
6897: '</td></tr>'."\n";
6898: }
6899: $$rowtotal += $rownum;
6900: return $datatable;
6901: }
6902:
6903: sub serverstatus_pages {
6904: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 6905: 'checksums','clusterstatus','certstatus','metadata_keywords',
6906: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
6907: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6908: }
6909:
1.236 raeburn 6910: sub defaults_javascript {
6911: my ($settings) = @_;
1.294 ! raeburn 6912: 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.');
! 6913: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
! 6914: &js_escape(\$intauthcheck);
! 6915: &js_escape(\$intauthcost);
! 6916: my $intauthjs = <<"ENDSCRIPT";
! 6917:
! 6918: function warnIntAuth(field) {
! 6919: if (field.name == 'intauth_check') {
! 6920: if (field.value == '2') {
! 6921: alert('$intauthcheck');
! 6922: }
! 6923: }
! 6924: if (field.name == 'intauth_cost') {
! 6925: field.value.replace(/\s/g,'');
! 6926: if (field.value != '') {
! 6927: var regexdigit=/^\\d+\$/;
! 6928: if (!regexdigit.test(field.value)) {
! 6929: alert('$intauthcost');
! 6930: }
! 6931: }
! 6932: }
! 6933: return;
! 6934: }
! 6935:
! 6936: ENDSCRIPT
! 6937:
! 6938: if (ref($settings) ne 'HASH') {
! 6939: return &Apache::lonhtmlcommon::scripttag($intauthjs);
! 6940: }
1.236 raeburn 6941: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6942: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6943: if ($maxnum eq '') {
6944: $maxnum = 0;
6945: }
6946: $maxnum ++;
1.249 raeburn 6947: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6948: return <<"ENDSCRIPT";
6949: <script type="text/javascript">
6950: // <![CDATA[
6951: function reorderTypes(form,caller) {
6952: var changedVal;
6953: $jstext
6954: var newpos = 'addinststatus_pos';
6955: var current = new Array;
6956: var maxh = $maxnum;
6957: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6958: var oldVal;
6959: if (caller == newpos) {
6960: changedVal = newitemVal;
6961: } else {
6962: var curritem = 'inststatus_pos_'+caller;
6963: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6964: current[newitemVal] = newpos;
6965: }
6966: for (var i=0; i<inststatuses.length; i++) {
6967: if (inststatuses[i] != caller) {
6968: var elementName = 'inststatus_pos_'+inststatuses[i];
6969: if (form.elements[elementName]) {
6970: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6971: current[currVal] = elementName;
6972: }
6973: }
6974: }
6975: for (var j=0; j<maxh; j++) {
6976: if (current[j] == undefined) {
6977: oldVal = j;
6978: }
6979: }
6980: if (oldVal < changedVal) {
6981: for (var k=oldVal+1; k<=changedVal ; k++) {
6982: var elementName = current[k];
6983: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6984: }
6985: } else {
6986: for (var k=changedVal; k<oldVal; k++) {
6987: var elementName = current[k];
6988: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6989: }
6990: }
6991: return;
6992: }
6993:
1.294 ! raeburn 6994: $intauthjs
! 6995:
1.236 raeburn 6996: // ]]>
6997: </script>
6998:
6999: ENDSCRIPT
1.294 ! raeburn 7000: } else {
! 7001: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 7002: }
7003: }
7004:
1.49 raeburn 7005: sub coursecategories_javascript {
7006: my ($settings) = @_;
1.57 raeburn 7007: my ($output,$jstext,$cathash);
1.49 raeburn 7008: if (ref($settings) eq 'HASH') {
1.57 raeburn 7009: $cathash = $settings->{'cats'};
7010: }
7011: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7012: my (@cats,@jsarray,%idx);
1.57 raeburn 7013: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7014: if (@jsarray > 0) {
7015: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7016: for (my $i=0; $i<@jsarray; $i++) {
7017: if (ref($jsarray[$i]) eq 'ARRAY') {
7018: my $catstr = join('","',@{$jsarray[$i]});
7019: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7020: }
7021: }
7022: }
7023: } else {
7024: $jstext = ' var categories = Array(1);'."\n".
7025: ' categories[0] = Array("instcode_pos");'."\n";
7026: }
1.237 bisitz 7027: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7028: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 7029: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 7030: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7031: &js_escape(\$instcode_reserved);
7032: &js_escape(\$communities_reserved);
1.272 raeburn 7033: &js_escape(\$placement_reserved);
1.265 damieng 7034: &js_escape(\$choose_again);
1.49 raeburn 7035: $output = <<"ENDSCRIPT";
7036: <script type="text/javascript">
1.109 raeburn 7037: // <![CDATA[
1.49 raeburn 7038: function reorderCats(form,parent,item,idx) {
7039: var changedVal;
7040: $jstext
7041: var newpos = 'addcategory_pos';
7042: if (parent == '') {
7043: var has_instcode = 0;
7044: var maxtop = categories[idx].length;
7045: for (var j=0; j<maxtop; j++) {
7046: if (categories[idx][j] == 'instcode::0') {
7047: has_instcode == 1;
7048: }
7049: }
7050: if (has_instcode == 0) {
7051: categories[idx][maxtop] = 'instcode_pos';
7052: }
7053: } else {
7054: newpos += '_'+parent;
7055: }
7056: var maxh = 1 + categories[idx].length;
7057: var current = new Array;
7058: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7059: if (item == newpos) {
7060: changedVal = newitemVal;
7061: } else {
7062: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7063: current[newitemVal] = newpos;
7064: }
7065: for (var i=0; i<categories[idx].length; i++) {
7066: var elementName = categories[idx][i];
7067: if (elementName != item) {
7068: if (form.elements[elementName]) {
7069: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7070: current[currVal] = elementName;
7071: }
7072: }
7073: }
7074: var oldVal;
7075: for (var j=0; j<maxh; j++) {
7076: if (current[j] == undefined) {
7077: oldVal = j;
7078: }
7079: }
7080: if (oldVal < changedVal) {
7081: for (var k=oldVal+1; k<=changedVal ; k++) {
7082: var elementName = current[k];
7083: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7084: }
7085: } else {
7086: for (var k=changedVal; k<oldVal; k++) {
7087: var elementName = current[k];
7088: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7089: }
7090: }
7091: return;
7092: }
1.120 raeburn 7093:
7094: function categoryCheck(form) {
7095: if (form.elements['addcategory_name'].value == 'instcode') {
7096: alert('$instcode_reserved\\n$choose_again');
7097: return false;
7098: }
7099: if (form.elements['addcategory_name'].value == 'communities') {
7100: alert('$communities_reserved\\n$choose_again');
7101: return false;
7102: }
1.272 raeburn 7103: if (form.elements['addcategory_name'].value == 'placement') {
7104: alert('$placement_reserved\\n$choose_again');
7105: return false;
7106: }
1.120 raeburn 7107: return true;
7108: }
7109:
1.109 raeburn 7110: // ]]>
1.49 raeburn 7111: </script>
7112:
7113: ENDSCRIPT
7114: return $output;
7115: }
7116:
1.48 raeburn 7117: sub initialize_categories {
7118: my ($itemcount) = @_;
1.120 raeburn 7119: my ($datatable,$css_class,$chgstr);
7120: my %default_names = (
7121: instcode => 'Official courses (with institutional codes)',
7122: communities => 'Communities',
1.272 raeburn 7123: placement => 'Placement Tests',
1.120 raeburn 7124: );
7125: my $select0 = ' selected="selected"';
7126: my $select1 = '';
1.272 raeburn 7127: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7128: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7129: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 7130: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 7131: $select1 = $select0;
7132: $select0 = '';
7133: }
7134: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7135: .'<select name="'.$default.'_pos">'
7136: .'<option value="0"'.$select0.'>1</option>'
7137: .'<option value="1"'.$select1.'>2</option>'
7138: .'<option value="2">3</option></select> '
7139: .$default_names{$default}
7140: .'</span></td><td><span class="LC_nobreak">'
7141: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7142: .&mt('Display').'</label> <label>'
7143: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7144: .'</label></span></td></tr>';
1.120 raeburn 7145: $itemcount ++;
7146: }
1.48 raeburn 7147: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7148: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7149: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7150: .'<select name="addcategory_pos"'.$chgstr.'>'
7151: .'<option value="0">1</option>'
7152: .'<option value="1">2</option>'
7153: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 7154: .&mt('Add category').'</td><td>'.&mt('Name:')
7155: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
7156: return $datatable;
7157: }
7158:
7159: sub build_category_rows {
1.49 raeburn 7160: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7161: my ($text,$name,$item,$chgstr);
1.48 raeburn 7162: if (ref($cats) eq 'ARRAY') {
7163: my $maxdepth = scalar(@{$cats});
7164: if (ref($cats->[$depth]) eq 'HASH') {
7165: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7166: my $numchildren = @{$cats->[$depth]{$parent}};
7167: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 7168: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7169: my ($idxnum,$parent_name,$parent_item);
7170: my $higher = $depth - 1;
7171: if ($higher == 0) {
7172: $parent_name = &escape($parent).'::'.$higher;
7173: } else {
7174: if (ref($path) eq 'ARRAY') {
7175: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7176: }
7177: }
7178: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7179: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7180: if ($j < $numchildren) {
1.48 raeburn 7181: $name = $cats->[$depth]{$parent}[$j];
7182: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7183: $idxnum = $idx->{$item};
7184: } else {
7185: $name = $parent_name;
7186: $item = $parent_item;
1.48 raeburn 7187: }
1.49 raeburn 7188: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7189: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7190: for (my $i=0; $i<=$numchildren; $i++) {
7191: my $vpos = $i+1;
7192: my $selstr;
7193: if ($j == $i) {
7194: $selstr = ' selected="selected" ';
7195: }
7196: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7197: }
7198: $text .= '</select> ';
7199: if ($j < $numchildren) {
7200: my $deeper = $depth+1;
7201: $text .= $name.' '
7202: .'<label><input type="checkbox" name="deletecategory" value="'
7203: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7204: if(ref($path) eq 'ARRAY') {
7205: push(@{$path},$name);
1.49 raeburn 7206: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7207: pop(@{$path});
7208: }
7209: } else {
1.59 bisitz 7210: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 7211: if ($j == $numchildren) {
7212: $text .= $name;
7213: } else {
7214: $text .= $item;
7215: }
7216: $text .= '" value="" />';
7217: }
7218: $text .= '</td></tr>';
7219: }
7220: $text .= '</table></td>';
7221: } else {
7222: my $higher = $depth-1;
7223: if ($higher == 0) {
7224: $name = &escape($parent).'::'.$higher;
7225: } else {
7226: if (ref($path) eq 'ARRAY') {
7227: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7228: }
7229: }
7230: my $colspan;
7231: if ($parent ne 'instcode') {
7232: $colspan = $maxdepth - $depth - 1;
7233: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7234: }
7235: }
7236: }
7237: }
7238: return $text;
7239: }
7240:
1.33 raeburn 7241: sub modifiable_userdata_row {
1.228 raeburn 7242: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
7243: my ($role,$rolename,$statustype);
7244: $role = $item;
1.224 raeburn 7245: if ($context eq 'cancreate') {
1.228 raeburn 7246: if ($item =~ /^emailusername_(.+)$/) {
7247: $statustype = $1;
7248: $role = 'emailusername';
7249: if (ref($usertypes) eq 'HASH') {
7250: if ($usertypes->{$statustype}) {
7251: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7252: } else {
7253: $rolename = &mt('Data provided by user');
7254: }
7255: }
1.224 raeburn 7256: }
7257: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7258: if (ref($usertypes) eq 'HASH') {
7259: $rolename = $usertypes->{$role};
7260: } else {
7261: $rolename = $role;
7262: }
1.33 raeburn 7263: } else {
1.63 raeburn 7264: if ($role eq 'cr') {
7265: $rolename = &mt('Custom role');
7266: } else {
7267: $rolename = &Apache::lonnet::plaintext($role);
7268: }
1.33 raeburn 7269: }
1.224 raeburn 7270: my (@fields,%fieldtitles);
7271: if (ref($fieldsref) eq 'ARRAY') {
7272: @fields = @{$fieldsref};
7273: } else {
7274: @fields = ('lastname','firstname','middlename','generation',
7275: 'permanentemail','id');
7276: }
7277: if ((ref($titlesref) eq 'HASH')) {
7278: %fieldtitles = %{$titlesref};
7279: } else {
7280: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7281: }
1.33 raeburn 7282: my $output;
7283: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7284: $output = '<tr '.$css_class.'>'.
7285: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7286: '<td class="LC_left_item" colspan="2"><table>';
7287: my $rem;
7288: my %checks;
7289: if (ref($settings) eq 'HASH') {
7290: if (ref($settings->{$context}) eq 'HASH') {
7291: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 7292: my $hashref = $settings->{$context}->{$role};
7293: if ($role eq 'emailusername') {
7294: if ($statustype) {
7295: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7296: $hashref = $settings->{$context}->{$role}->{$statustype};
7297: if (ref($hashref) eq 'HASH') {
7298: foreach my $field (@fields) {
7299: if ($hashref->{$field}) {
7300: $checks{$field} = $hashref->{$field};
7301: }
7302: }
7303: }
7304: }
7305: }
7306: } else {
7307: if (ref($hashref) eq 'HASH') {
7308: foreach my $field (@fields) {
7309: if ($hashref->{$field}) {
7310: $checks{$field} = ' checked="checked" ';
7311: }
7312: }
1.33 raeburn 7313: }
7314: }
7315: }
7316: }
7317: }
1.228 raeburn 7318:
1.33 raeburn 7319: for (my $i=0; $i<@fields; $i++) {
7320: my $rem = $i%($numinrow);
7321: if ($rem == 0) {
7322: if ($i > 0) {
7323: $output .= '</tr>';
7324: }
7325: $output .= '<tr>';
7326: }
7327: my $check = ' ';
1.228 raeburn 7328: unless ($role eq 'emailusername') {
7329: if (exists($checks{$fields[$i]})) {
7330: $check = $checks{$fields[$i]}
7331: } else {
7332: if ($role eq 'st') {
7333: if (ref($settings) ne 'HASH') {
7334: $check = ' checked="checked" ';
7335: }
1.33 raeburn 7336: }
7337: }
7338: }
7339: $output .= '<td class="LC_left_item">'.
1.228 raeburn 7340: '<span class="LC_nobreak">';
7341: if ($role eq 'emailusername') {
7342: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7343: $checks{$fields[$i]} = 'omit';
7344: }
7345: foreach my $option ('required','optional','omit') {
7346: my $checked='';
7347: if ($checks{$fields[$i]} eq $option) {
7348: $checked='checked="checked" ';
7349: }
7350: $output .= '<label>'.
7351: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7352: &mt($option).'</label>'.(' ' x2);
7353: }
7354: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7355: } else {
7356: $output .= '<label>'.
7357: '<input type="checkbox" name="canmodify_'.$role.'" '.
7358: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7359: '</label>';
7360: }
7361: $output .= '</span></td>';
1.33 raeburn 7362: $rem = @fields%($numinrow);
7363: }
7364: my $colsleft = $numinrow - $rem;
7365: if ($colsleft > 1 ) {
7366: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7367: ' </td>';
7368: } elsif ($colsleft == 1) {
7369: $output .= '<td class="LC_left_item"> </td>';
7370: }
7371: $output .= '</tr></table></td></tr>';
7372: return $output;
7373: }
1.28 raeburn 7374:
1.93 raeburn 7375: sub insttypes_row {
1.224 raeburn 7376: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 7377: my %lt = &Apache::lonlocal::texthash (
7378: cansearch => 'Users allowed to search',
7379: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7380: lockablenames => 'User preference to lock name',
1.93 raeburn 7381: );
7382: my $showdom;
7383: if ($context eq 'cansearch') {
7384: $showdom = ' ('.$dom.')';
7385: }
1.165 raeburn 7386: my $class = 'LC_left_item';
7387: if ($context eq 'statustocreate') {
7388: $class = 'LC_right_item';
7389: }
1.224 raeburn 7390: my $css_class = ' class="LC_odd_row"';
7391: if ($rownum ne '') {
7392: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
7393: }
7394: my $output = '<tr'.$css_class.'>'.
7395: '<td>'.$lt{$context}.$showdom.
7396: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7397: my $rem;
7398: if (ref($types) eq 'ARRAY') {
7399: for (my $i=0; $i<@{$types}; $i++) {
7400: if (defined($usertypes->{$types->[$i]})) {
7401: my $rem = $i%($numinrow);
7402: if ($rem == 0) {
7403: if ($i > 0) {
7404: $output .= '</tr>';
7405: }
7406: $output .= '<tr>';
1.23 raeburn 7407: }
1.26 raeburn 7408: my $check = ' ';
1.99 raeburn 7409: if (ref($settings) eq 'HASH') {
7410: if (ref($settings->{$context}) eq 'ARRAY') {
7411: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7412: $check = ' checked="checked" ';
7413: }
7414: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7415: $check = ' checked="checked" ';
7416: }
1.23 raeburn 7417: }
1.26 raeburn 7418: $output .= '<td class="LC_left_item">'.
7419: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7420: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 7421: 'value="'.$types->[$i].'"'.$check.'/>'.
7422: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7423: }
7424: }
1.26 raeburn 7425: $rem = @{$types}%($numinrow);
1.23 raeburn 7426: }
7427: my $colsleft = $numinrow - $rem;
1.131 raeburn 7428: if (($rem == 0) && (@{$types} > 0)) {
7429: $output .= '<tr>';
7430: }
1.23 raeburn 7431: if ($colsleft > 1) {
1.25 raeburn 7432: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7433: } else {
1.25 raeburn 7434: $output .= '<td class="LC_left_item">';
1.23 raeburn 7435: }
7436: my $defcheck = ' ';
1.99 raeburn 7437: if (ref($settings) eq 'HASH') {
7438: if (ref($settings->{$context}) eq 'ARRAY') {
7439: if (grep(/^default$/,@{$settings->{$context}})) {
7440: $defcheck = ' checked="checked" ';
7441: }
7442: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7443: $defcheck = ' checked="checked" ';
7444: }
1.23 raeburn 7445: }
1.25 raeburn 7446: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7447: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 7448: 'value="default"'.$defcheck.'/>'.
7449: $othertitle.'</label></span></td>'.
7450: '</tr></table></td></tr>';
7451: return $output;
1.23 raeburn 7452: }
7453:
7454: sub sorted_searchtitles {
7455: my %searchtitles = &Apache::lonlocal::texthash(
7456: 'uname' => 'username',
7457: 'lastname' => 'last name',
7458: 'lastfirst' => 'last name, first name',
7459: );
7460: my @titleorder = ('uname','lastname','lastfirst');
7461: return (\%searchtitles,\@titleorder);
7462: }
7463:
1.25 raeburn 7464: sub sorted_searchtypes {
7465: my %srchtypes_desc = (
7466: exact => 'is exact match',
7467: contains => 'contains ..',
7468: begins => 'begins with ..',
7469: );
7470: my @srchtypeorder = ('exact','begins','contains');
7471: return (\%srchtypes_desc,\@srchtypeorder);
7472: }
7473:
1.3 raeburn 7474: sub usertype_update_row {
7475: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7476: my $datatable;
7477: my $numinrow = 4;
7478: foreach my $type (@{$types}) {
7479: if (defined($usertypes->{$type})) {
7480: $$rownums ++;
7481: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7482: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7483: '</td><td class="LC_left_item"><table>';
7484: for (my $i=0; $i<@{$fields}; $i++) {
7485: my $rem = $i%($numinrow);
7486: if ($rem == 0) {
7487: if ($i > 0) {
7488: $datatable .= '</tr>';
7489: }
7490: $datatable .= '<tr>';
7491: }
7492: my $check = ' ';
1.39 raeburn 7493: if (ref($settings) eq 'HASH') {
7494: if (ref($settings->{'fields'}) eq 'HASH') {
7495: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7496: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7497: $check = ' checked="checked" ';
7498: }
1.3 raeburn 7499: }
7500: }
7501: }
7502:
7503: if ($i == @{$fields}-1) {
7504: my $colsleft = $numinrow - $rem;
7505: if ($colsleft > 1) {
7506: $datatable .= '<td colspan="'.$colsleft.'">';
7507: } else {
7508: $datatable .= '<td>';
7509: }
7510: } else {
7511: $datatable .= '<td>';
7512: }
1.8 raeburn 7513: $datatable .= '<span class="LC_nobreak"><label>'.
7514: '<input type="checkbox" name="updateable_'.$type.
7515: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7516: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7517: }
7518: $datatable .= '</tr></table></td></tr>';
7519: }
7520: }
7521: return $datatable;
1.1 raeburn 7522: }
7523:
7524: sub modify_login {
1.205 raeburn 7525: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 7526: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7527: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7528: %title = ( coursecatalog => 'Display course catalog',
7529: adminmail => 'Display administrator E-mail address',
1.188 raeburn 7530: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 7531: newuser => 'Link for visitors to create a user account',
7532: loginheader => 'Log-in box header');
7533: @offon = ('off','on');
1.112 raeburn 7534: if (ref($domconfig{login}) eq 'HASH') {
7535: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7536: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7537: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7538: }
7539: }
7540: }
1.9 raeburn 7541: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7542: \%domconfig,\%loginhash);
1.188 raeburn 7543: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7544: foreach my $item (@toggles) {
7545: $loginhash{login}{$item} = $env{'form.'.$item};
7546: }
1.41 raeburn 7547: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7548: if (ref($colchanges{'login'}) eq 'HASH') {
7549: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7550: \%loginhash);
7551: }
1.110 raeburn 7552:
1.149 raeburn 7553: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 7554: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7555: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7556: if (keys(%servers) > 1) {
7557: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7558: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7559: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7560: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7561: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7562: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7563: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7564: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7565: $changes{'loginvia'}{$lonhost} = 1;
7566: } else {
7567: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7568: $changes{'loginvia'}{$lonhost} = 1;
7569: }
7570: } else {
7571: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7572: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7573: $changes{'loginvia'}{$lonhost} = 1;
7574: }
7575: }
7576: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7577: foreach my $item (@loginvia_attribs) {
7578: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7579: }
7580: } else {
7581: foreach my $item (@loginvia_attribs) {
7582: my $new = $env{'form.'.$lonhost.'_'.$item};
7583: if (($item eq 'serverpath') && ($new eq 'custom')) {
7584: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7585: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7586: $new = '/';
7587: }
7588: }
7589: if (($item eq 'custompath') &&
7590: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7591: $new = '';
7592: }
7593: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7594: $changes{'loginvia'}{$lonhost} = 1;
7595: }
7596: if ($item eq 'exempt') {
1.256 raeburn 7597: $new = &check_exempt_addresses($new);
1.128 raeburn 7598: }
7599: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7600: }
7601: }
1.112 raeburn 7602: } else {
1.128 raeburn 7603: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7604: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7605: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7606: foreach my $item (@loginvia_attribs) {
7607: my $new = $env{'form.'.$lonhost.'_'.$item};
7608: if (($item eq 'serverpath') && ($new eq 'custom')) {
7609: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7610: $new = '/';
7611: }
7612: }
7613: if (($item eq 'custompath') &&
7614: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7615: $new = '';
7616: }
7617: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7618: }
1.110 raeburn 7619: }
7620: }
7621: }
7622: }
1.119 raeburn 7623:
1.168 raeburn 7624: my $servadm = $r->dir_config('lonAdmEMail');
7625: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7626: if (ref($domconfig{'login'}) eq 'HASH') {
7627: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7628: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7629: if ($lang eq 'nolang') {
7630: push(@currlangs,$lang);
7631: } elsif (defined($langchoices{$lang})) {
7632: push(@currlangs,$lang);
7633: } else {
7634: next;
7635: }
7636: }
7637: }
7638: }
7639: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7640: if (@currlangs > 0) {
7641: foreach my $lang (@currlangs) {
7642: if (grep(/^\Q$lang\E$/,@delurls)) {
7643: $changes{'helpurl'}{$lang} = 1;
7644: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7645: $changes{'helpurl'}{$lang} = 1;
7646: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7647: push(@newlangs,$lang);
7648: } else {
7649: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7650: }
7651: }
7652: }
7653: unless (grep(/^nolang$/,@currlangs)) {
7654: if ($env{'form.loginhelpurl_nolang.filename'}) {
7655: $changes{'helpurl'}{'nolang'} = 1;
7656: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7657: push(@newlangs,'nolang');
7658: }
7659: }
7660: if ($env{'form.loginhelpurl_add_lang'}) {
7661: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7662: ($env{'form.loginhelpurl_add_file.filename'})) {
7663: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7664: $addedfile = $env{'form.loginhelpurl_add_lang'};
7665: }
7666: }
7667: if ((@newlangs > 0) || ($addedfile)) {
7668: my $error;
7669: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7670: if ($configuserok eq 'ok') {
7671: if ($switchserver) {
7672: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7673: } elsif ($author_ok eq 'ok') {
7674: my @allnew = @newlangs;
7675: if ($addedfile ne '') {
7676: push(@allnew,$addedfile);
7677: }
7678: foreach my $lang (@allnew) {
7679: my $formelem = 'loginhelpurl_'.$lang;
7680: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7681: $formelem = 'loginhelpurl_add_file';
7682: }
7683: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7684: "help/$lang",'','',$newfile{$lang});
7685: if ($result eq 'ok') {
7686: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7687: $changes{'helpurl'}{$lang} = 1;
7688: } else {
7689: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7690: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 7691: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 7692: (!grep(/^\Q$lang\E$/,@delurls))) {
7693: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7694: }
7695: }
7696: }
7697: } else {
7698: $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);
7699: }
7700: } else {
7701: $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);
7702: }
7703: if ($error) {
7704: &Apache::lonnet::logthis($error);
7705: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7706: }
7707: }
1.256 raeburn 7708:
7709: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7710: if (ref($domconfig{'login'}) eq 'HASH') {
7711: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7712: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7713: if ($domservers{$lonhost}) {
7714: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7715: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 7716: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 7717: }
7718: }
7719: }
7720: }
7721: }
7722: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7723: foreach my $lonhost (sort(keys(%domservers))) {
7724: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7725: $changes{'headtag'}{$lonhost} = 1;
7726: } else {
7727: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7728: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7729: }
7730: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7731: push(@newhosts,$lonhost);
7732: } elsif ($currheadtagurls{$lonhost}) {
7733: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7734: if ($currexempt{$lonhost}) {
1.289 raeburn 7735: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 7736: $changes{'headtag'}{$lonhost} = 1;
7737: }
7738: } elsif ($possexempt{$lonhost}) {
7739: $changes{'headtag'}{$lonhost} = 1;
7740: }
7741: if ($possexempt{$lonhost}) {
7742: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7743: }
7744: }
7745: }
7746: }
7747: if (@newhosts) {
7748: my $error;
7749: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7750: if ($configuserok eq 'ok') {
7751: if ($switchserver) {
7752: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7753: } elsif ($author_ok eq 'ok') {
7754: foreach my $lonhost (@newhosts) {
7755: my $formelem = 'loginheadtag_'.$lonhost;
7756: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7757: "login/headtag/$lonhost",'','',
7758: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7759: if ($result eq 'ok') {
7760: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7761: $changes{'headtag'}{$lonhost} = 1;
7762: if ($possexempt{$lonhost}) {
7763: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7764: }
7765: } else {
7766: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7767: $newheadtagurls{$lonhost},$result);
7768: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7769: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7770: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7771: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7772: }
7773: }
7774: }
7775: } else {
7776: $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);
7777: }
7778: } else {
7779: $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);
7780: }
7781: if ($error) {
7782: &Apache::lonnet::logthis($error);
7783: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7784: }
7785: }
1.169 raeburn 7786: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 7787:
7788: my $defaulthelpfile = '/adm/loginproblems.html';
7789: my $defaulttext = &mt('Default in use');
7790:
1.1 raeburn 7791: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7792: $dom);
7793: if ($putresult eq 'ok') {
1.188 raeburn 7794: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7795: my %defaultchecked = (
7796: 'coursecatalog' => 'on',
1.188 raeburn 7797: 'helpdesk' => 'on',
1.42 raeburn 7798: 'adminmail' => 'off',
1.43 raeburn 7799: 'newuser' => 'off',
1.42 raeburn 7800: );
1.55 raeburn 7801: if (ref($domconfig{'login'}) eq 'HASH') {
7802: foreach my $item (@toggles) {
7803: if ($defaultchecked{$item} eq 'on') {
7804: if (($domconfig{'login'}{$item} eq '0') &&
7805: ($env{'form.'.$item} eq '1')) {
7806: $changes{$item} = 1;
7807: } elsif (($domconfig{'login'}{$item} eq '' ||
7808: $domconfig{'login'}{$item} eq '1') &&
7809: ($env{'form.'.$item} eq '0')) {
7810: $changes{$item} = 1;
7811: }
7812: } elsif ($defaultchecked{$item} eq 'off') {
7813: if (($domconfig{'login'}{$item} eq '1') &&
7814: ($env{'form.'.$item} eq '0')) {
7815: $changes{$item} = 1;
7816: } elsif (($domconfig{'login'}{$item} eq '' ||
7817: $domconfig{'login'}{$item} eq '0') &&
7818: ($env{'form.'.$item} eq '1')) {
7819: $changes{$item} = 1;
7820: }
1.42 raeburn 7821: }
7822: }
1.41 raeburn 7823: }
1.6 raeburn 7824: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7825: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7826: if (ref($lastactref) eq 'HASH') {
7827: $lastactref->{'domainconfig'} = 1;
7828: }
1.1 raeburn 7829: $resulttext = &mt('Changes made:').'<ul>';
7830: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7831: if ($item eq 'loginvia') {
1.112 raeburn 7832: if (ref($changes{$item}) eq 'HASH') {
7833: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7834: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7835: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7836: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7837: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7838: $protocol = 'http' if ($protocol ne 'https');
7839: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7840:
7841: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7842: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7843: } else {
7844: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7845: }
7846: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7847: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7848: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7849: }
7850: $resulttext .= '</li>';
7851: } else {
7852: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7853: }
1.112 raeburn 7854: } else {
1.128 raeburn 7855: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7856: }
7857: }
1.128 raeburn 7858: $resulttext .= '</ul></li>';
1.112 raeburn 7859: }
1.168 raeburn 7860: } elsif ($item eq 'helpurl') {
7861: if (ref($changes{$item}) eq 'HASH') {
7862: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7863: if (grep(/^\Q$lang\E$/,@delurls)) {
7864: my ($chg,$link);
7865: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7866: if ($lang eq 'nolang') {
7867: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7868: } else {
7869: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7870: }
7871: $resulttext .= '<li>'.$chg.'</li>';
7872: } else {
7873: my $chg;
7874: if ($lang eq 'nolang') {
7875: $chg = &mt('custom log-in help file for no preferred language');
7876: } else {
7877: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7878: }
7879: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7880: $loginhash{'login'}{'helpurl'}{$lang}.
7881: '?inhibitmenu=yes',$chg,600,500).
7882: '</li>';
7883: }
7884: }
7885: }
1.256 raeburn 7886: } elsif ($item eq 'headtag') {
7887: if (ref($changes{$item}) eq 'HASH') {
7888: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7889: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7890: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7891: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7892: $resulttext .= '<li><a href="'.
7893: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7894: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7895: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7896: if ($possexempt{$lonhost}) {
7897: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7898: } else {
7899: $resulttext .= &mt('included for any client IP');
7900: }
7901: $resulttext .= '</li>';
7902: }
7903: }
7904: }
1.169 raeburn 7905: } elsif ($item eq 'captcha') {
7906: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7907: my $chgtxt;
1.169 raeburn 7908: if ($loginhash{'login'}{$item} eq 'notused') {
7909: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7910: } else {
7911: my %captchas = &captcha_phrases();
7912: if ($captchas{$loginhash{'login'}{$item}}) {
7913: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7914: } else {
7915: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7916: }
7917: }
7918: $resulttext .= '<li>'.$chgtxt.'</li>';
7919: }
7920: } elsif ($item eq 'recaptchakeys') {
7921: if (ref($loginhash{'login'}) eq 'HASH') {
7922: my ($privkey,$pubkey);
7923: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7924: $pubkey = $loginhash{'login'}{$item}{'public'};
7925: $privkey = $loginhash{'login'}{$item}{'private'};
7926: }
7927: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7928: if (!$pubkey) {
7929: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7930: } else {
7931: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7932: }
7933: if (!$privkey) {
7934: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7935: } else {
1.251 raeburn 7936: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7937: }
7938: $chgtxt .= '</ul>';
7939: $resulttext .= '<li>'.$chgtxt.'</li>';
7940: }
1.269 raeburn 7941: } elsif ($item eq 'recaptchaversion') {
7942: if (ref($loginhash{'login'}) eq 'HASH') {
7943: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7944: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7945: '</li>';
7946: }
7947: }
1.41 raeburn 7948: } else {
7949: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7950: }
1.1 raeburn 7951: }
1.6 raeburn 7952: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7953: } else {
7954: $resulttext = &mt('No changes made to log-in page settings');
7955: }
7956: } else {
1.11 albertel 7957: $resulttext = '<span class="LC_error">'.
7958: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7959: }
1.6 raeburn 7960: if ($errors) {
1.9 raeburn 7961: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7962: $errors.'</ul>';
7963: }
7964: return $resulttext;
7965: }
7966:
1.256 raeburn 7967: sub check_exempt_addresses {
7968: my ($iplist) = @_;
7969: $iplist =~ s/^\s+//;
7970: $iplist =~ s/\s+$//;
7971: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7972: my (@okips,$new);
7973: foreach my $ip (@poss_ips) {
7974: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7975: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7976: push(@okips,$ip);
7977: }
7978: }
7979: }
7980: if (@okips > 0) {
7981: $new = join(',',@okips);
7982: } else {
7983: $new = '';
7984: }
7985: return $new;
7986: }
7987:
1.6 raeburn 7988: sub color_font_choices {
7989: my %choices =
7990: &Apache::lonlocal::texthash (
7991: img => "Header",
7992: bgs => "Background colors",
7993: links => "Link colors",
1.55 raeburn 7994: images => "Images",
1.6 raeburn 7995: font => "Font color",
1.201 raeburn 7996: fontmenu => "Font menu",
1.76 raeburn 7997: pgbg => "Page",
1.6 raeburn 7998: tabbg => "Header",
7999: sidebg => "Border",
8000: link => "Link",
8001: alink => "Active link",
8002: vlink => "Visited link",
8003: );
8004: return %choices;
8005: }
8006:
8007: sub modify_rolecolors {
1.205 raeburn 8008: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8009: my ($resulttext,%rolehash);
8010: $rolehash{'rolecolors'} = {};
1.55 raeburn 8011: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8012: if ($domconfig{'rolecolors'} eq '') {
8013: $domconfig{'rolecolors'} = {};
8014: }
8015: }
1.9 raeburn 8016: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8017: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8018: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8019: $dom);
8020: if ($putresult eq 'ok') {
8021: if (keys(%changes) > 0) {
1.41 raeburn 8022: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8023: if (ref($lastactref) eq 'HASH') {
8024: $lastactref->{'domainconfig'} = 1;
8025: }
1.6 raeburn 8026: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8027: $rolehash{'rolecolors'});
8028: } else {
8029: $resulttext = &mt('No changes made to default color schemes');
8030: }
8031: } else {
1.11 albertel 8032: $resulttext = '<span class="LC_error">'.
8033: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8034: }
8035: if ($errors) {
8036: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8037: $errors.'</ul>';
8038: }
8039: return $resulttext;
8040: }
8041:
8042: sub modify_colors {
1.9 raeburn 8043: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8044: my (%changes,%choices);
1.51 raeburn 8045: my @bgs;
1.6 raeburn 8046: my @links = ('link','alink','vlink');
1.41 raeburn 8047: my @logintext;
1.6 raeburn 8048: my @images;
8049: my $servadm = $r->dir_config('lonAdmEMail');
8050: my $errors;
1.200 raeburn 8051: my %defaults;
1.6 raeburn 8052: foreach my $role (@{$roles}) {
8053: if ($role eq 'login') {
1.12 raeburn 8054: %choices = &login_choices();
1.41 raeburn 8055: @logintext = ('textcol','bgcol');
1.12 raeburn 8056: } else {
8057: %choices = &color_font_choices();
8058: }
8059: if ($role eq 'login') {
1.41 raeburn 8060: @images = ('img','logo','domlogo','login');
1.51 raeburn 8061: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8062: } else {
8063: @images = ('img');
1.200 raeburn 8064: @bgs = ('pgbg','tabbg','sidebg');
8065: }
8066: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8067: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8068: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8069: }
8070: if ($role eq 'login') {
8071: foreach my $item (@logintext) {
1.234 raeburn 8072: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8073: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8074: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8075: }
8076: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 8077: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8078: }
8079: }
8080: } else {
1.234 raeburn 8081: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8082: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8083: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8084: }
8085: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 8086: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8087: }
1.6 raeburn 8088: }
1.200 raeburn 8089: foreach my $item (@bgs) {
1.234 raeburn 8090: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8091: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8092: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8093: }
8094: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 8095: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8096: }
8097: }
8098: foreach my $item (@links) {
1.234 raeburn 8099: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8100: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8101: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8102: }
8103: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 8104: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8105: }
1.6 raeburn 8106: }
1.46 raeburn 8107: my ($configuserok,$author_ok,$switchserver) =
8108: &config_check($dom,$confname,$servadm);
1.9 raeburn 8109: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8110: if (ref($domconfig->{$role}) ne 'HASH') {
8111: $domconfig->{$role} = {};
8112: }
1.8 raeburn 8113: foreach my $img (@images) {
1.70 raeburn 8114: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8115: if (defined($env{'form.login_showlogo_'.$img})) {
8116: $confhash->{$role}{'showlogo'}{$img} = 1;
8117: } else {
8118: $confhash->{$role}{'showlogo'}{$img} = 0;
8119: }
8120: }
1.18 albertel 8121: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8122: && !defined($domconfig->{$role}{$img})
8123: && !$env{'form.'.$role.'_del_'.$img}
8124: && $env{'form.'.$role.'_import_'.$img}) {
8125: # import the old configured image from the .tab setting
8126: # if they haven't provided a new one
8127: $domconfig->{$role}{$img} =
8128: $env{'form.'.$role.'_import_'.$img};
8129: }
1.6 raeburn 8130: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8131: my $error;
1.6 raeburn 8132: if ($configuserok eq 'ok') {
1.9 raeburn 8133: if ($switchserver) {
1.12 raeburn 8134: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8135: } else {
8136: if ($author_ok eq 'ok') {
8137: my ($result,$logourl) =
8138: &publishlogo($r,'upload',$role.'_'.$img,
8139: $dom,$confname,$img,$width,$height);
8140: if ($result eq 'ok') {
8141: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8142: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8143: } else {
1.12 raeburn 8144: $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 8145: }
8146: } else {
1.46 raeburn 8147: $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 8148: }
8149: }
8150: } else {
1.46 raeburn 8151: $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 8152: }
8153: if ($error) {
1.8 raeburn 8154: &Apache::lonnet::logthis($error);
1.11 albertel 8155: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8156: }
8157: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8158: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8159: my $error;
8160: if ($configuserok eq 'ok') {
8161: # is confname an author?
8162: if ($switchserver eq '') {
8163: if ($author_ok eq 'ok') {
8164: my ($result,$logourl) =
8165: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8166: $dom,$confname,$img,$width,$height);
8167: if ($result eq 'ok') {
8168: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8169: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8170: }
8171: }
8172: }
8173: }
1.6 raeburn 8174: }
8175: }
8176: }
8177: if (ref($domconfig) eq 'HASH') {
8178: if (ref($domconfig->{$role}) eq 'HASH') {
8179: foreach my $img (@images) {
8180: if ($domconfig->{$role}{$img} ne '') {
8181: if ($env{'form.'.$role.'_del_'.$img}) {
8182: $confhash->{$role}{$img} = '';
1.12 raeburn 8183: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8184: } else {
1.9 raeburn 8185: if ($confhash->{$role}{$img} eq '') {
8186: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8187: }
1.6 raeburn 8188: }
8189: } else {
8190: if ($env{'form.'.$role.'_del_'.$img}) {
8191: $confhash->{$role}{$img} = '';
1.12 raeburn 8192: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8193: }
8194: }
1.70 raeburn 8195: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8196: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8197: if ($confhash->{$role}{'showlogo'}{$img} ne
8198: $domconfig->{$role}{'showlogo'}{$img}) {
8199: $changes{$role}{'showlogo'}{$img} = 1;
8200: }
8201: } else {
8202: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8203: $changes{$role}{'showlogo'}{$img} = 1;
8204: }
8205: }
8206: }
8207: }
1.6 raeburn 8208: if ($domconfig->{$role}{'font'} ne '') {
8209: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8210: $changes{$role}{'font'} = 1;
8211: }
8212: } else {
8213: if ($confhash->{$role}{'font'}) {
8214: $changes{$role}{'font'} = 1;
8215: }
8216: }
1.107 raeburn 8217: if ($role ne 'login') {
8218: if ($domconfig->{$role}{'fontmenu'} ne '') {
8219: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8220: $changes{$role}{'fontmenu'} = 1;
8221: }
8222: } else {
8223: if ($confhash->{$role}{'fontmenu'}) {
8224: $changes{$role}{'fontmenu'} = 1;
8225: }
1.97 tempelho 8226: }
8227: }
1.6 raeburn 8228: foreach my $item (@bgs) {
8229: if ($domconfig->{$role}{$item} ne '') {
8230: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8231: $changes{$role}{'bgs'}{$item} = 1;
8232: }
8233: } else {
8234: if ($confhash->{$role}{$item}) {
8235: $changes{$role}{'bgs'}{$item} = 1;
8236: }
8237: }
8238: }
8239: foreach my $item (@links) {
8240: if ($domconfig->{$role}{$item} ne '') {
8241: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8242: $changes{$role}{'links'}{$item} = 1;
8243: }
8244: } else {
8245: if ($confhash->{$role}{$item}) {
8246: $changes{$role}{'links'}{$item} = 1;
8247: }
8248: }
8249: }
1.41 raeburn 8250: foreach my $item (@logintext) {
8251: if ($domconfig->{$role}{$item} ne '') {
8252: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8253: $changes{$role}{'logintext'}{$item} = 1;
8254: }
8255: } else {
8256: if ($confhash->{$role}{$item}) {
8257: $changes{$role}{'logintext'}{$item} = 1;
8258: }
8259: }
8260: }
1.6 raeburn 8261: } else {
8262: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8263: \@logintext,$confhash,\%changes);
1.6 raeburn 8264: }
8265: } else {
8266: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8267: \@logintext,$confhash,\%changes);
1.6 raeburn 8268: }
8269: }
8270: return ($errors,%changes);
8271: }
8272:
1.46 raeburn 8273: sub config_check {
8274: my ($dom,$confname,$servadm) = @_;
8275: my ($configuserok,$author_ok,$switchserver,%currroles);
8276: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8277: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8278: $confname,$servadm);
8279: if ($configuserok eq 'ok') {
8280: $switchserver = &check_switchserver($dom,$confname);
8281: if ($switchserver eq '') {
8282: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8283: }
8284: }
8285: return ($configuserok,$author_ok,$switchserver);
8286: }
8287:
1.6 raeburn 8288: sub default_change_checker {
1.41 raeburn 8289: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8290: foreach my $item (@{$links}) {
8291: if ($confhash->{$role}{$item}) {
8292: $changes->{$role}{'links'}{$item} = 1;
8293: }
8294: }
8295: foreach my $item (@{$bgs}) {
8296: if ($confhash->{$role}{$item}) {
8297: $changes->{$role}{'bgs'}{$item} = 1;
8298: }
8299: }
1.41 raeburn 8300: foreach my $item (@{$logintext}) {
8301: if ($confhash->{$role}{$item}) {
8302: $changes->{$role}{'logintext'}{$item} = 1;
8303: }
8304: }
1.6 raeburn 8305: foreach my $img (@{$images}) {
8306: if ($env{'form.'.$role.'_del_'.$img}) {
8307: $confhash->{$role}{$img} = '';
1.12 raeburn 8308: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8309: }
1.70 raeburn 8310: if ($role eq 'login') {
8311: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8312: $changes->{$role}{'showlogo'}{$img} = 1;
8313: }
8314: }
1.6 raeburn 8315: }
8316: if ($confhash->{$role}{'font'}) {
8317: $changes->{$role}{'font'} = 1;
8318: }
1.48 raeburn 8319: }
1.6 raeburn 8320:
8321: sub display_colorchgs {
8322: my ($dom,$changes,$roles,$confhash) = @_;
8323: my (%choices,$resulttext);
8324: if (!grep(/^login$/,@{$roles})) {
8325: $resulttext = &mt('Changes made:').'<br />';
8326: }
8327: foreach my $role (@{$roles}) {
8328: if ($role eq 'login') {
8329: %choices = &login_choices();
8330: } else {
8331: %choices = &color_font_choices();
8332: }
8333: if (ref($changes->{$role}) eq 'HASH') {
8334: if ($role ne 'login') {
8335: $resulttext .= '<h4>'.&mt($role).'</h4>';
8336: }
8337: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8338: if ($role ne 'login') {
8339: $resulttext .= '<ul>';
8340: }
8341: if (ref($changes->{$role}{$key}) eq 'HASH') {
8342: if ($role ne 'login') {
8343: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8344: }
8345: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8346: if (($role eq 'login') && ($key eq 'showlogo')) {
8347: if ($confhash->{$role}{$key}{$item}) {
8348: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8349: } else {
8350: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8351: }
8352: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8353: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8354: } else {
1.12 raeburn 8355: my $newitem = $confhash->{$role}{$item};
8356: if ($key eq 'images') {
8357: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8358: }
8359: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8360: }
8361: }
8362: if ($role ne 'login') {
8363: $resulttext .= '</ul></li>';
8364: }
8365: } else {
8366: if ($confhash->{$role}{$key} eq '') {
8367: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8368: } else {
8369: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8370: }
8371: }
8372: if ($role ne 'login') {
8373: $resulttext .= '</ul>';
8374: }
8375: }
8376: }
8377: }
1.3 raeburn 8378: return $resulttext;
1.1 raeburn 8379: }
8380:
1.9 raeburn 8381: sub thumb_dimensions {
8382: return ('200','50');
8383: }
8384:
1.16 raeburn 8385: sub check_dimensions {
8386: my ($inputfile) = @_;
8387: my ($fullwidth,$fullheight);
8388: if ($inputfile =~ m|^[/\w.\-]+$|) {
8389: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8390: my $imageinfo = <PIPE>;
8391: if (!close(PIPE)) {
8392: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8393: }
8394: chomp($imageinfo);
8395: my ($fullsize) =
1.21 raeburn 8396: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8397: if ($fullsize) {
8398: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8399: }
8400: }
8401: }
8402: return ($fullwidth,$fullheight);
8403: }
8404:
1.9 raeburn 8405: sub check_configuser {
8406: my ($uhome,$dom,$confname,$servadm) = @_;
8407: my ($configuserok,%currroles);
8408: if ($uhome eq 'no_host') {
8409: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8410: my $configpass = &LONCAPA::Enrollment::create_password();
8411: $configuserok =
8412: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8413: $configpass,'','','','','',undef,$servadm);
8414: } else {
8415: $configuserok = 'ok';
8416: %currroles =
8417: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8418: }
8419: return ($configuserok,%currroles);
8420: }
8421:
8422: sub check_authorstatus {
8423: my ($dom,$confname,%currroles) = @_;
8424: my $author_ok;
1.40 raeburn 8425: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8426: my $start = time;
8427: my $end = 0;
8428: $author_ok =
8429: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8430: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8431: } else {
8432: $author_ok = 'ok';
8433: }
8434: return $author_ok;
8435: }
8436:
8437: sub publishlogo {
1.46 raeburn 8438: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 8439: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 8440: if ($action eq 'upload') {
8441: $fname=$env{'form.'.$formname.'.filename'};
8442: chop($env{'form.'.$formname});
8443: } else {
8444: ($fname) = ($formname =~ /([^\/]+)$/);
8445: }
1.46 raeburn 8446: if ($savefileas ne '') {
8447: $fname = $savefileas;
8448: }
1.9 raeburn 8449: $fname=&Apache::lonnet::clean_filename($fname);
8450: # See if there is anything left
8451: unless ($fname) { return ('error: no uploaded file'); }
8452: $fname="$subdir/$fname";
1.210 raeburn 8453: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 8454: my $filepath="$docroot/priv";
8455: my $relpath = "$dom/$confname";
1.9 raeburn 8456: my ($fnamepath,$file,$fetchthumb);
8457: $file=$fname;
8458: if ($fname=~m|/|) {
8459: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8460: }
1.164 raeburn 8461: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8462: my $count;
1.164 raeburn 8463: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8464: $filepath.="/$parts[$count]";
8465: if ((-e $filepath)!=1) {
8466: mkdir($filepath,02770);
8467: }
8468: }
8469: # Check for bad extension and disallow upload
8470: if ($file=~/\.(\w+)$/ &&
8471: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8472: $output =
1.207 bisitz 8473: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8474: } elsif ($file=~/\.(\w+)$/ &&
8475: !defined(&Apache::loncommon::fileembstyle($1))) {
8476: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8477: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 8478: $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 8479: } elsif (-d "$filepath/$file") {
1.195 bisitz 8480: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8481: } else {
8482: my $source = $filepath.'/'.$file;
8483: my $logfile;
8484: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 8485: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8486: }
8487: print $logfile
8488: "\n================= Publish ".localtime()." ================\n".
8489: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8490: # Save the file
8491: if (!open(FH,'>'.$source)) {
8492: &Apache::lonnet::logthis('Failed to create '.$source);
8493: return (&mt('Failed to create file'));
8494: }
8495: if ($action eq 'upload') {
8496: if (!print FH ($env{'form.'.$formname})) {
8497: &Apache::lonnet::logthis('Failed to write to '.$source);
8498: return (&mt('Failed to write file'));
8499: }
8500: } else {
8501: my $original = &Apache::lonnet::filelocation('',$formname);
8502: if(!copy($original,$source)) {
8503: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8504: return (&mt('Failed to write file'));
8505: }
8506: }
8507: close(FH);
8508: chmod(0660, $source); # Permissions to rw-rw---.
8509:
8510: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8511: my $copyfile=$targetdir.'/'.$file;
8512:
8513: my @parts=split(/\//,$targetdir);
8514: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8515: for (my $count=5;$count<=$#parts;$count++) {
8516: $path.="/$parts[$count]";
8517: if (!-e $path) {
8518: print $logfile "\nCreating directory ".$path;
8519: mkdir($path,02770);
8520: }
8521: }
8522: my $versionresult;
8523: if (-e $copyfile) {
8524: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8525: } else {
8526: $versionresult = 'ok';
8527: }
8528: if ($versionresult eq 'ok') {
8529: if (copy($source,$copyfile)) {
8530: print $logfile "\nCopied original source to ".$copyfile."\n";
8531: $output = 'ok';
8532: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8533: push(@{$modified_urls},[$copyfile,$source]);
8534: my $metaoutput =
8535: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8536: unless ($registered_cleanup) {
8537: my $handlers = $r->get_handlers('PerlCleanupHandler');
8538: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8539: $registered_cleanup=1;
8540: }
1.9 raeburn 8541: } else {
8542: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8543: $output = &mt('Failed to copy file to RES space').", $!";
8544: }
8545: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8546: my $inputfile = $filepath.'/'.$file;
8547: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8548: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8549: if ($fullwidth ne '' && $fullheight ne '') {
8550: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8551: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8552: system("convert -sample $thumbsize $inputfile $outfile");
8553: chmod(0660, $filepath.'/tn-'.$file);
8554: if (-e $outfile) {
8555: my $copyfile=$targetdir.'/tn-'.$file;
8556: if (copy($outfile,$copyfile)) {
8557: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8558: my $thumb_metaoutput =
8559: &write_metadata($dom,$confname,$formname,
8560: $targetdir,'tn-'.$file,$logfile);
8561: push(@{$modified_urls},[$copyfile,$outfile]);
8562: unless ($registered_cleanup) {
8563: my $handlers = $r->get_handlers('PerlCleanupHandler');
8564: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8565: $registered_cleanup=1;
8566: }
1.267 raeburn 8567: $madethumb = 1;
1.16 raeburn 8568: } else {
8569: print $logfile "\nUnable to write ".$copyfile.
8570: ':'.$!."\n";
8571: }
8572: }
1.9 raeburn 8573: }
8574: }
8575: }
8576: } else {
8577: $output = $versionresult;
8578: }
8579: }
1.267 raeburn 8580: return ($output,$logourl,$madethumb);
1.9 raeburn 8581: }
8582:
8583: sub logo_versioning {
8584: my ($targetdir,$file,$logfile) = @_;
8585: my $target = $targetdir.'/'.$file;
8586: my ($maxversion,$fn,$extn,$output);
8587: $maxversion = 0;
8588: if ($file =~ /^(.+)\.(\w+)$/) {
8589: $fn=$1;
8590: $extn=$2;
8591: }
8592: opendir(DIR,$targetdir);
8593: while (my $filename=readdir(DIR)) {
8594: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8595: $maxversion=($1>$maxversion)?$1:$maxversion;
8596: }
8597: }
8598: $maxversion++;
8599: print $logfile "\nCreating old version ".$maxversion."\n";
8600: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8601: if (copy($target,$copyfile)) {
8602: print $logfile "Copied old target to ".$copyfile."\n";
8603: $copyfile=$copyfile.'.meta';
8604: if (copy($target.'.meta',$copyfile)) {
8605: print $logfile "Copied old target metadata to ".$copyfile."\n";
8606: $output = 'ok';
8607: } else {
8608: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8609: $output = &mt('Failed to copy old meta').", $!, ";
8610: }
8611: } else {
8612: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8613: $output = &mt('Failed to copy old target').", $!, ";
8614: }
8615: return $output;
8616: }
8617:
8618: sub write_metadata {
8619: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8620: my (%metadatafields,%metadatakeys,$output);
8621: $metadatafields{'title'}=$formname;
8622: $metadatafields{'creationdate'}=time;
8623: $metadatafields{'lastrevisiondate'}=time;
8624: $metadatafields{'copyright'}='public';
8625: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8626: $env{'user.domain'};
8627: $metadatafields{'authorspace'}=$confname.':'.$dom;
8628: $metadatafields{'domain'}=$dom;
8629: {
8630: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8631: my $mfh;
1.155 raeburn 8632: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 8633: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8634: unless ($_=~/\./) {
8635: my $unikey=$_;
8636: $unikey=~/^([A-Za-z]+)/;
8637: my $tag=$1;
8638: $tag=~tr/A-Z/a-z/;
8639: print $mfh "\n\<$tag";
8640: foreach (split(/\,/,$metadatakeys{$unikey})) {
8641: my $value=$metadatafields{$unikey.'.'.$_};
8642: $value=~s/\"/\'\'/g;
8643: print $mfh ' '.$_.'="'.$value.'"';
8644: }
8645: print $mfh '>'.
8646: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8647: .'</'.$tag.'>';
8648: }
8649: }
8650: $output = 'ok';
8651: print $logfile "\nWrote metadata";
8652: close($mfh);
8653: } else {
8654: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8655: $output = &mt('Could not write metadata');
8656: }
8657: }
1.155 raeburn 8658: return $output;
8659: }
8660:
8661: sub notifysubscribed {
8662: foreach my $targetsource (@{$modified_urls}){
8663: next unless (ref($targetsource) eq 'ARRAY');
8664: my ($target,$source)=@{$targetsource};
8665: if ($source ne '') {
8666: if (open(my $logfh,'>>'.$source.'.log')) {
8667: print $logfh "\nCleanup phase: Notifications\n";
8668: my @subscribed=&subscribed_hosts($target);
8669: foreach my $subhost (@subscribed) {
8670: print $logfh "\nNotifying host ".$subhost.':';
8671: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8672: print $logfh $reply;
8673: }
8674: my @subscribedmeta=&subscribed_hosts("$target.meta");
8675: foreach my $subhost (@subscribedmeta) {
8676: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8677: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8678: $subhost);
8679: print $logfh $reply;
8680: }
8681: print $logfh "\n============ Done ============\n";
1.160 raeburn 8682: close($logfh);
1.155 raeburn 8683: }
8684: }
8685: }
8686: return OK;
8687: }
8688:
8689: sub subscribed_hosts {
8690: my ($target) = @_;
8691: my @subscribed;
8692: if (open(my $fh,"<$target.subscription")) {
8693: while (my $subline=<$fh>) {
8694: if ($subline =~ /^($match_lonid):/) {
8695: my $host = $1;
8696: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8697: unless (grep(/^\Q$host\E$/,@subscribed)) {
8698: push(@subscribed,$host);
8699: }
8700: }
8701: }
8702: }
8703: }
8704: return @subscribed;
1.9 raeburn 8705: }
8706:
8707: sub check_switchserver {
8708: my ($dom,$confname) = @_;
8709: my ($allowed,$switchserver);
8710: my $home = &Apache::lonnet::homeserver($confname,$dom);
8711: if ($home eq 'no_host') {
8712: $home = &Apache::lonnet::domain($dom,'primary');
8713: }
8714: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8715: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8716: if (!$allowed) {
1.180 raeburn 8717: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8718: }
8719: return $switchserver;
8720: }
8721:
1.1 raeburn 8722: sub modify_quotas {
1.216 raeburn 8723: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8724: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 8725: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 8726: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8727: $validationfieldsref);
1.86 raeburn 8728: if ($action eq 'quotas') {
8729: $context = 'tools';
1.163 raeburn 8730: } else {
1.86 raeburn 8731: $context = $action;
8732: }
8733: if ($context eq 'requestcourses') {
1.271 raeburn 8734: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 8735: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8736: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8737: %titles = &courserequest_titles();
8738: $toolregexp = join('|',@usertools);
8739: %conditions = &courserequest_conditions();
1.216 raeburn 8740: $confname = $dom.'-domainconfig';
8741: my $servadm = $r->dir_config('lonAdmEMail');
8742: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 8743: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8744: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 8745: } elsif ($context eq 'requestauthor') {
8746: @usertools = ('author');
8747: %titles = &authorrequest_titles();
1.86 raeburn 8748: } else {
1.162 raeburn 8749: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8750: %titles = &tool_titles();
1.86 raeburn 8751: }
1.212 raeburn 8752: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8753: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8754: foreach my $key (keys(%env)) {
1.101 raeburn 8755: if ($context eq 'requestcourses') {
8756: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8757: my $item = $1;
8758: my $type = $2;
8759: if ($type =~ /^limit_(.+)/) {
8760: $limithash{$item}{$1} = $env{$key};
8761: } else {
8762: $confhash{$item}{$type} = $env{$key};
8763: }
8764: }
1.163 raeburn 8765: } elsif ($context eq 'requestauthor') {
8766: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8767: $confhash{$1} = $env{$key};
8768: }
1.101 raeburn 8769: } else {
1.86 raeburn 8770: if ($key =~ /^form\.quota_(.+)$/) {
8771: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 8772: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8773: $confhash{'authorquota'}{$1} = $env{$key};
8774: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8775: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8776: }
1.72 raeburn 8777: }
8778: }
1.163 raeburn 8779: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 8780: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8781: @approvalnotify = sort(@approvalnotify);
8782: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 8783: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 8784: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8785: foreach my $type (@hasuniquecode) {
8786: if (grep(/^\Q$type\E$/,@crstypes)) {
8787: $confhash{'uniquecode'}{$type} = 1;
8788: }
1.216 raeburn 8789: }
1.242 raeburn 8790: my (%newbook,%allpos);
1.216 raeburn 8791: if ($context eq 'requestcourses') {
1.242 raeburn 8792: foreach my $type ('textbooks','templates') {
8793: @{$allpos{$type}} = ();
8794: my $invalid;
8795: if ($type eq 'textbooks') {
8796: $invalid = &mt('Invalid LON-CAPA course for textbook');
8797: } else {
8798: $invalid = &mt('Invalid LON-CAPA course for template');
8799: }
8800: if ($env{'form.'.$type.'_addbook'}) {
8801: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8802: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8803: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8804: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8805: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8806: } else {
8807: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8808: my $position = $env{'form.'.$type.'_addbook_pos'};
8809: $position =~ s/\D+//g;
8810: if ($position ne '') {
8811: $allpos{$type}[$position] = $newbook{$type};
8812: }
1.216 raeburn 8813: }
1.242 raeburn 8814: } else {
8815: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8816: }
8817: }
1.242 raeburn 8818: }
1.216 raeburn 8819: }
1.102 raeburn 8820: if (ref($domconfig{$action}) eq 'HASH') {
8821: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8822: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8823: $changes{'notify'}{'approval'} = 1;
8824: }
8825: } else {
1.144 raeburn 8826: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8827: $changes{'notify'}{'approval'} = 1;
8828: }
8829: }
1.218 raeburn 8830: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8831: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8832: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8833: unless ($confhash{'uniquecode'}{$crstype}) {
8834: $changes{'uniquecode'} = 1;
8835: }
8836: }
8837: unless ($changes{'uniquecode'}) {
8838: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8839: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8840: $changes{'uniquecode'} = 1;
8841: }
8842: }
8843: }
8844: } else {
8845: $changes{'uniquecode'} = 1;
8846: }
8847: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8848: $changes{'uniquecode'} = 1;
1.216 raeburn 8849: }
8850: if ($context eq 'requestcourses') {
1.242 raeburn 8851: foreach my $type ('textbooks','templates') {
8852: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8853: my %deletions;
8854: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8855: if (@todelete) {
8856: map { $deletions{$_} = 1; } @todelete;
8857: }
8858: my %imgdeletions;
8859: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8860: if (@todeleteimages) {
8861: map { $imgdeletions{$_} = 1; } @todeleteimages;
8862: }
8863: my $maxnum = $env{'form.'.$type.'_maxnum'};
8864: for (my $i=0; $i<=$maxnum; $i++) {
8865: my $itemid = $env{'form.'.$type.'_id_'.$i};
8866: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8867: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8868: if ($deletions{$key}) {
8869: if ($domconfig{$action}{$type}{$key}{'image'}) {
8870: #FIXME need to obsolete item in RES space
8871: }
8872: next;
8873: } else {
8874: my $newpos = $env{'form.'.$itemid};
8875: $newpos =~ s/\D+//g;
1.243 raeburn 8876: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 8877: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 8878: ($type eq 'templates'));
1.242 raeburn 8879: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8880: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8881: $changes{$type}{$key} = 1;
8882: }
8883: }
8884: $allpos{$type}[$newpos] = $key;
8885: }
8886: if ($imgdeletions{$key}) {
8887: $changes{$type}{$key} = 1;
1.216 raeburn 8888: #FIXME need to obsolete item in RES space
1.242 raeburn 8889: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8890: my ($cdom,$cnum) = split(/_/,$key);
8891: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8892: $cdom,$cnum,$type,$configuserok,
8893: $switchserver,$author_ok);
8894: if ($imgurl) {
8895: $confhash{$type}{$key}{'image'} = $imgurl;
8896: $changes{$type}{$key} = 1;
1.216 raeburn 8897: }
1.242 raeburn 8898: if ($error) {
8899: &Apache::lonnet::logthis($error);
8900: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8901: }
8902: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8903: $confhash{$type}{$key}{'image'} =
8904: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8905: }
8906: }
8907: }
8908: }
8909: }
8910: }
1.102 raeburn 8911: } else {
1.144 raeburn 8912: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8913: $changes{'notify'}{'approval'} = 1;
8914: }
1.218 raeburn 8915: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8916: $changes{'uniquecode'} = 1;
8917: }
8918: }
8919: if ($context eq 'requestcourses') {
1.242 raeburn 8920: foreach my $type ('textbooks','templates') {
8921: if ($newbook{$type}) {
8922: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8923: foreach my $item ('subject','title','publisher','author') {
8924: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8925: ($type eq 'template'));
1.242 raeburn 8926: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8927: if ($env{'form.'.$type.'_addbook_'.$item}) {
8928: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8929: }
8930: }
8931: if ($type eq 'textbooks') {
8932: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8933: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8934: my ($imageurl,$error) =
8935: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8936: $configuserok,$switchserver,$author_ok);
8937: if ($imageurl) {
8938: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8939: }
8940: if ($error) {
8941: &Apache::lonnet::logthis($error);
8942: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8943: }
8944: }
1.216 raeburn 8945: }
8946: }
1.242 raeburn 8947: if (@{$allpos{$type}} > 0) {
8948: my $idx = 0;
8949: foreach my $item (@{$allpos{$type}}) {
8950: if ($item ne '') {
8951: $confhash{$type}{$item}{'order'} = $idx;
8952: if (ref($domconfig{$action}) eq 'HASH') {
8953: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8954: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8955: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8956: $changes{$type}{$item} = 1;
8957: }
1.216 raeburn 8958: }
8959: }
8960: }
1.242 raeburn 8961: $idx ++;
1.216 raeburn 8962: }
8963: }
8964: }
8965: }
1.235 raeburn 8966: if (ref($validationitemsref) eq 'ARRAY') {
8967: foreach my $item (@{$validationitemsref}) {
8968: if ($item eq 'fields') {
8969: my @changed;
8970: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8971: if (@{$confhash{'validation'}{$item}} > 0) {
8972: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8973: }
1.266 raeburn 8974: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8975: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8976: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8977: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8978: $domconfig{'requestcourses'}{'validation'}{$item});
8979: } else {
8980: @changed = @{$confhash{'validation'}{$item}};
8981: }
1.235 raeburn 8982: } else {
8983: @changed = @{$confhash{'validation'}{$item}};
8984: }
8985: } else {
8986: @changed = @{$confhash{'validation'}{$item}};
8987: }
8988: if (@changed) {
8989: if ($confhash{'validation'}{$item}) {
8990: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8991: } else {
8992: $changes{'validation'}{$item} = &mt('None');
8993: }
8994: }
8995: } else {
8996: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8997: if ($item eq 'markup') {
8998: if ($env{'form.requestcourses_validation_'.$item}) {
8999: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9000: }
9001: }
1.266 raeburn 9002: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9003: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9004: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9005: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9006: }
9007: } else {
9008: if ($confhash{'validation'}{$item} ne '') {
9009: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9010: }
1.235 raeburn 9011: }
9012: } else {
9013: if ($confhash{'validation'}{$item} ne '') {
9014: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9015: }
9016: }
9017: }
9018: }
9019: }
9020: if ($env{'form.validationdc'}) {
9021: my $newval = $env{'form.validationdc'};
1.285 raeburn 9022: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 9023: if (exists($domcoords{$newval})) {
9024: $confhash{'validation'}{'dc'} = $newval;
9025: }
9026: }
9027: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 9028: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9029: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9030: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9031: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9032: if ($confhash{'validation'}{'dc'} eq '') {
9033: $changes{'validation'}{'dc'} = &mt('None');
9034: } else {
9035: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9036: }
1.235 raeburn 9037: }
1.266 raeburn 9038: } elsif ($confhash{'validation'}{'dc'} ne '') {
9039: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 9040: }
9041: } elsif ($confhash{'validation'}{'dc'} ne '') {
9042: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9043: }
9044: } elsif ($confhash{'validation'}{'dc'} ne '') {
9045: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 9046: }
1.266 raeburn 9047: } else {
9048: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9049: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9050: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9051: $changes{'validation'}{'dc'} = &mt('None');
9052: }
9053: }
1.235 raeburn 9054: }
9055: }
1.102 raeburn 9056: }
9057: } else {
1.86 raeburn 9058: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 9059: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9060: }
1.72 raeburn 9061: foreach my $item (@usertools) {
9062: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9063: my $unset;
1.101 raeburn 9064: if ($context eq 'requestcourses') {
1.104 raeburn 9065: $unset = '0';
9066: if ($type eq '_LC_adv') {
9067: $unset = '';
9068: }
1.101 raeburn 9069: if ($confhash{$item}{$type} eq 'autolimit') {
9070: $confhash{$item}{$type} .= '=';
9071: unless ($limithash{$item}{$type} =~ /\D/) {
9072: $confhash{$item}{$type} .= $limithash{$item}{$type};
9073: }
9074: }
1.163 raeburn 9075: } elsif ($context eq 'requestauthor') {
9076: $unset = '0';
9077: if ($type eq '_LC_adv') {
9078: $unset = '';
9079: }
1.72 raeburn 9080: } else {
1.101 raeburn 9081: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9082: $confhash{$item}{$type} = 1;
9083: } else {
9084: $confhash{$item}{$type} = 0;
9085: }
1.72 raeburn 9086: }
1.86 raeburn 9087: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 9088: if ($action eq 'requestauthor') {
9089: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9090: $changes{$type} = 1;
9091: }
9092: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9093: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9094: $changes{$item}{$type} = 1;
9095: }
9096: } else {
9097: if ($context eq 'requestcourses') {
1.104 raeburn 9098: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9099: $changes{$item}{$type} = 1;
9100: }
9101: } else {
9102: if (!$confhash{$item}{$type}) {
9103: $changes{$item}{$type} = 1;
9104: }
9105: }
9106: }
9107: } else {
9108: if ($context eq 'requestcourses') {
1.104 raeburn 9109: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9110: $changes{$item}{$type} = 1;
9111: }
1.163 raeburn 9112: } elsif ($context eq 'requestauthor') {
9113: if ($confhash{$type} ne $unset) {
9114: $changes{$type} = 1;
9115: }
1.72 raeburn 9116: } else {
9117: if (!$confhash{$item}{$type}) {
9118: $changes{$item}{$type} = 1;
9119: }
9120: }
9121: }
1.1 raeburn 9122: }
9123: }
1.163 raeburn 9124: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9125: if (ref($domconfig{'quotas'}) eq 'HASH') {
9126: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9127: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9128: if (exists($confhash{'defaultquota'}{$key})) {
9129: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9130: $changes{'defaultquota'}{$key} = 1;
9131: }
9132: } else {
9133: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9134: }
9135: }
1.86 raeburn 9136: } else {
9137: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9138: if (exists($confhash{'defaultquota'}{$key})) {
9139: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9140: $changes{'defaultquota'}{$key} = 1;
9141: }
9142: } else {
9143: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9144: }
1.1 raeburn 9145: }
9146: }
1.197 raeburn 9147: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9148: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9149: if (exists($confhash{'authorquota'}{$key})) {
9150: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9151: $changes{'authorquota'}{$key} = 1;
9152: }
9153: } else {
9154: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9155: }
9156: }
9157: }
1.1 raeburn 9158: }
1.86 raeburn 9159: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9160: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9161: if (ref($domconfig{'quotas'}) eq 'HASH') {
9162: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9163: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9164: $changes{'defaultquota'}{$key} = 1;
9165: }
9166: } else {
9167: if (!exists($domconfig{'quotas'}{$key})) {
9168: $changes{'defaultquota'}{$key} = 1;
9169: }
1.72 raeburn 9170: }
9171: } else {
1.86 raeburn 9172: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9173: }
1.1 raeburn 9174: }
9175: }
1.197 raeburn 9176: if (ref($confhash{'authorquota'}) eq 'HASH') {
9177: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9178: if (ref($domconfig{'quotas'}) eq 'HASH') {
9179: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9180: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9181: $changes{'authorquota'}{$key} = 1;
9182: }
9183: } else {
9184: $changes{'authorquota'}{$key} = 1;
9185: }
9186: } else {
9187: $changes{'authorquota'}{$key} = 1;
9188: }
9189: }
9190: }
1.1 raeburn 9191: }
1.72 raeburn 9192:
1.163 raeburn 9193: if ($context eq 'requestauthor') {
9194: $domdefaults{'requestauthor'} = \%confhash;
9195: } else {
9196: foreach my $key (keys(%confhash)) {
1.242 raeburn 9197: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 9198: $domdefaults{$key} = $confhash{$key};
9199: }
1.163 raeburn 9200: }
1.72 raeburn 9201: }
1.163 raeburn 9202:
1.1 raeburn 9203: my %quotahash = (
1.86 raeburn 9204: $action => { %confhash }
1.1 raeburn 9205: );
9206: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9207: $dom);
9208: if ($putresult eq 'ok') {
9209: if (keys(%changes) > 0) {
1.72 raeburn 9210: my $cachetime = 24*60*60;
9211: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9212: if (ref($lastactref) eq 'HASH') {
9213: $lastactref->{'domdefaults'} = 1;
9214: }
1.1 raeburn 9215: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 9216: unless (($context eq 'requestcourses') ||
1.163 raeburn 9217: ($context eq 'requestauthor')) {
1.86 raeburn 9218: if (ref($changes{'defaultquota'}) eq 'HASH') {
9219: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9220: foreach my $type (@{$types},'default') {
9221: if (defined($changes{'defaultquota'}{$type})) {
9222: my $typetitle = $usertypes->{$type};
9223: if ($type eq 'default') {
9224: $typetitle = $othertitle;
9225: }
1.213 raeburn 9226: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9227: }
9228: }
1.86 raeburn 9229: $resulttext .= '</ul></li>';
1.72 raeburn 9230: }
1.197 raeburn 9231: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 9232: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 9233: foreach my $type (@{$types},'default') {
9234: if (defined($changes{'authorquota'}{$type})) {
9235: my $typetitle = $usertypes->{$type};
9236: if ($type eq 'default') {
9237: $typetitle = $othertitle;
9238: }
1.213 raeburn 9239: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 9240: }
9241: }
9242: $resulttext .= '</ul></li>';
9243: }
1.72 raeburn 9244: }
1.80 raeburn 9245: my %newenv;
1.72 raeburn 9246: foreach my $item (@usertools) {
1.163 raeburn 9247: my (%haschgs,%inconf);
9248: if ($context eq 'requestauthor') {
9249: %haschgs = %changes;
1.210 raeburn 9250: %inconf = %confhash;
1.163 raeburn 9251: } else {
9252: if (ref($changes{$item}) eq 'HASH') {
9253: %haschgs = %{$changes{$item}};
9254: }
9255: if (ref($confhash{$item}) eq 'HASH') {
9256: %inconf = %{$confhash{$item}};
9257: }
9258: }
9259: if (keys(%haschgs) > 0) {
1.80 raeburn 9260: my $newacc =
9261: &Apache::lonnet::usertools_access($env{'user.name'},
9262: $env{'user.domain'},
1.86 raeburn 9263: $item,'reload',$context);
1.210 raeburn 9264: if (($context eq 'requestcourses') ||
1.163 raeburn 9265: ($context eq 'requestauthor')) {
1.108 raeburn 9266: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9267: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9268: }
9269: } else {
9270: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9271: $newenv{'environment.availabletools.'.$item} = $newacc;
9272: }
1.80 raeburn 9273: }
1.163 raeburn 9274: unless ($context eq 'requestauthor') {
9275: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9276: }
1.72 raeburn 9277: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 9278: if ($haschgs{$type}) {
1.72 raeburn 9279: my $typetitle = $usertypes->{$type};
9280: if ($type eq 'default') {
9281: $typetitle = $othertitle;
9282: } elsif ($type eq '_LC_adv') {
9283: $typetitle = 'LON-CAPA Advanced Users';
9284: }
1.163 raeburn 9285: if ($inconf{$type}) {
1.101 raeburn 9286: if ($context eq 'requestcourses') {
9287: my $cond;
1.163 raeburn 9288: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9289: if ($1 eq '') {
9290: $cond = &mt('(Automatic processing of any request).');
9291: } else {
9292: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9293: }
9294: } else {
1.163 raeburn 9295: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9296: }
9297: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 9298: } elsif ($context eq 'requestauthor') {
9299: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9300: $titles{$inconf{$type}},$typetitle);
9301:
1.101 raeburn 9302: } else {
9303: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9304: }
1.72 raeburn 9305: } else {
1.104 raeburn 9306: if ($type eq '_LC_adv') {
1.163 raeburn 9307: if ($inconf{$type} eq '0') {
1.104 raeburn 9308: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9309: } else {
9310: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9311: }
9312: } else {
9313: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9314: }
1.72 raeburn 9315: }
9316: }
1.26 raeburn 9317: }
1.163 raeburn 9318: unless ($context eq 'requestauthor') {
9319: $resulttext .= '</ul></li>';
9320: }
1.26 raeburn 9321: }
1.1 raeburn 9322: }
1.163 raeburn 9323: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9324: if (ref($changes{'notify'}) eq 'HASH') {
9325: if ($changes{'notify'}{'approval'}) {
9326: if (ref($confhash{'notify'}) eq 'HASH') {
9327: if ($confhash{'notify'}{'approval'}) {
9328: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9329: } else {
1.163 raeburn 9330: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9331: }
9332: }
9333: }
9334: }
9335: }
1.216 raeburn 9336: if ($action eq 'requestcourses') {
9337: my @offon = ('off','on');
9338: if ($changes{'uniquecode'}) {
1.218 raeburn 9339: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9340: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9341: $resulttext .= '<li>'.
9342: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9343: '</li>';
9344: } else {
9345: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9346: '</li>';
9347: }
1.216 raeburn 9348: }
1.242 raeburn 9349: foreach my $type ('textbooks','templates') {
9350: if (ref($changes{$type}) eq 'HASH') {
9351: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9352: foreach my $key (sort(keys(%{$changes{$type}}))) {
9353: my %coursehash = &Apache::lonnet::coursedescription($key);
9354: my $coursetitle = $coursehash{'description'};
9355: my $position = $confhash{$type}{$key}{'order'} + 1;
9356: $resulttext .= '<li>';
1.243 raeburn 9357: foreach my $item ('subject','title','publisher','author') {
9358: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9359: ($type eq 'templates'));
1.242 raeburn 9360: my $name = $item.':';
9361: $name =~ s/^(\w)/\U$1/;
9362: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9363: }
9364: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9365: if ($type eq 'textbooks') {
9366: if ($confhash{$type}{$key}{'image'}) {
9367: $resulttext .= ' '.&mt('Image: [_1]',
9368: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9369: ' alt="Textbook cover" />').'<br />';
9370: }
9371: }
9372: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 9373: }
1.242 raeburn 9374: $resulttext .= '</ul></li>';
1.216 raeburn 9375: }
9376: }
1.235 raeburn 9377: if (ref($changes{'validation'}) eq 'HASH') {
9378: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9379: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9380: foreach my $item (@{$validationitemsref}) {
9381: if (exists($changes{'validation'}{$item})) {
9382: if ($item eq 'markup') {
9383: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9384: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9385: } else {
9386: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9387: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9388: }
9389: }
9390: }
9391: if (exists($changes{'validation'}{'dc'})) {
9392: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9393: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9394: }
9395: }
9396: }
1.216 raeburn 9397: }
1.1 raeburn 9398: $resulttext .= '</ul>';
1.80 raeburn 9399: if (keys(%newenv)) {
9400: &Apache::lonnet::appenv(\%newenv);
9401: }
1.1 raeburn 9402: } else {
1.86 raeburn 9403: if ($context eq 'requestcourses') {
9404: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 9405: } elsif ($context eq 'requestauthor') {
9406: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9407: } else {
1.90 weissno 9408: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9409: }
1.1 raeburn 9410: }
9411: } else {
1.11 albertel 9412: $resulttext = '<span class="LC_error">'.
9413: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9414: }
1.216 raeburn 9415: if ($errors) {
9416: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9417: '<ul>'.$errors.'</ul></p>';
9418: }
1.3 raeburn 9419: return $resulttext;
1.1 raeburn 9420: }
9421:
1.216 raeburn 9422: sub process_textbook_image {
1.242 raeburn 9423: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 9424: my $filename = $env{'form.'.$caller.'.filename'};
9425: my ($error,$url);
9426: my ($width,$height) = (50,50);
9427: if ($configuserok eq 'ok') {
9428: if ($switchserver) {
9429: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9430: $switchserver);
9431: } elsif ($author_ok eq 'ok') {
9432: my ($result,$imageurl) =
9433: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 9434: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 9435: if ($result eq 'ok') {
9436: $url = $imageurl;
9437: } else {
9438: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9439: }
9440: } else {
9441: $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);
9442: }
9443: } else {
9444: $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);
9445: }
9446: return ($url,$error);
9447: }
9448:
1.267 raeburn 9449: sub modify_ltitools {
9450: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9451: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9452: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
9453: my $confname = $dom.'-domainconfig';
9454: my $servadm = $r->dir_config('lonAdmEMail');
9455: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9456: my (%posslti,%possfield);
9457: my @courseroles = ('cc','in','ta','ep','st');
9458: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9459: map { $posslti{$_} = 1; } @ltiroles;
9460: my @allfields = ('fullname','firstname','lastname','email','user','roles');
9461: map { $possfield{$_} = 1; } @allfields;
9462: my %lt = <itools_names();
9463: if ($env{'form.ltitools_add'}) {
9464: my $title = $env{'form.ltitools_add_title'};
9465: $title =~ s/(`)/'/g;
9466: ($newid,my $error) = &get_ltitools_id($dom,$title);
9467: if ($newid) {
9468: my $position = $env{'form.ltitools_add_pos'};
9469: $position =~ s/\D+//g;
9470: if ($position ne '') {
9471: $allpos[$position] = $newid;
9472: }
9473: $changes{$newid} = 1;
9474: foreach my $item ('title','url','key','secret') {
9475: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9476: if ($env{'form.ltitools_add_'.$item}) {
9477: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9478: }
9479: }
9480: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9481: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9482: }
9483: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9484: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9485: }
9486: foreach my $item ('width','height') {
9487: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9488: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
9489: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
9490: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
9491: }
9492: }
9493: if ($env{'form.ltitools_add_target'} eq 'window') {
9494: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9495: } else {
9496: $confhash{$newid}{'display'}{'target'} = 'iframe';
9497: }
9498: foreach my $item ('passback','roster') {
9499: if ($env{'form.ltitools_add_'.$item}) {
9500: $confhash{$newid}{$item} = 1;
9501: }
9502: }
9503: if ($env{'form.ltitools_add_image.filename'} ne '') {
9504: my ($imageurl,$error) =
9505: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
9506: $configuserok,$switchserver,$author_ok);
9507: if ($imageurl) {
9508: $confhash{$newid}{'image'} = $imageurl;
9509: }
9510: if ($error) {
9511: &Apache::lonnet::logthis($error);
9512: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9513: }
9514: }
9515: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9516: foreach my $field (@fields) {
9517: if ($possfield{$field}) {
9518: if ($field eq 'roles') {
9519: foreach my $role (@courseroles) {
9520: my $choice = $env{'form.ltitools_add_roles_'.$role};
9521: if (($choice ne '') && ($posslti{$choice})) {
9522: $confhash{$newid}{'roles'}{$role} = $choice;
9523: if ($role eq 'cc') {
9524: $confhash{$newid}{'roles'}{'co'} = $choice;
9525: }
9526: }
9527: }
9528: } else {
9529: $confhash{$newid}{'fields'}{$field} = 1;
9530: }
9531: }
9532: }
1.273 raeburn 9533: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9534: foreach my $item (@courseconfig) {
9535: $confhash{$newid}{'crsconf'}{$item} = 1;
9536: }
1.267 raeburn 9537: if ($env{'form.ltitools_add_custom'}) {
9538: my $name = $env{'form.ltitools_add_custom_name'};
9539: my $value = $env{'form.ltitools_add_custom_value'};
9540: $value =~ s/(`)/'/g;
9541: $name =~ s/(`)/'/g;
9542: $confhash{$newid}{'custom'}{$name} = $value;
9543: }
9544: } else {
9545: my $error = &mt('Failed to acquire unique ID for new external tool');
9546: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9547: }
9548: }
9549: if (ref($domconfig{$action}) eq 'HASH') {
9550: my %deletions;
9551: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9552: if (@todelete) {
9553: map { $deletions{$_} = 1; } @todelete;
9554: }
9555: my %customadds;
9556: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9557: if (@newcustom) {
9558: map { $customadds{$_} = 1; } @newcustom;
9559: }
9560: my %imgdeletions;
9561: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9562: if (@todeleteimages) {
9563: map { $imgdeletions{$_} = 1; } @todeleteimages;
9564: }
9565: my $maxnum = $env{'form.ltitools_maxnum'};
9566: for (my $i=0; $i<=$maxnum; $i++) {
9567: my $itemid = $env{'form.ltitools_id_'.$i};
9568: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9569: if ($deletions{$itemid}) {
9570: if ($domconfig{$action}{$itemid}{'image'}) {
9571: #FIXME need to obsolete item in RES space
9572: }
9573: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9574: next;
9575: } else {
9576: my $newpos = $env{'form.ltitools_'.$itemid};
9577: $newpos =~ s/\D+//g;
9578: foreach my $item ('title','url','key','secret') {
9579: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9580: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9581: $changes{$itemid} = 1;
9582: }
9583: }
9584: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9585: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9586: }
9587: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9588: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9589: }
9590: foreach my $size ('width','height') {
9591: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9592: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9593: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9594: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9595: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9596: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9597: $changes{$itemid} = 1;
9598: }
9599: } else {
9600: $changes{$itemid} = 1;
9601: }
9602: }
9603: }
9604: if ($env{'form.ltitools_target_'.$i} eq 'window') {
9605: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9606: } else {
9607: $confhash{$itemid}{'display'}{'target'} = 'iframe';
9608: }
9609: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9610: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
9611: $changes{$itemid} = 1;
9612: }
9613: } else {
9614: $changes{$itemid} = 1;
9615: }
9616: foreach my $extra ('passback','roster') {
9617: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
9618: $confhash{$itemid}{$extra} = 1;
9619: }
9620: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
9621: $changes{$itemid} = 1;
9622: }
9623: }
1.273 raeburn 9624: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
9625: foreach my $item ('label','title','target') {
9626: if (grep(/^\Q$item\E$/,@courseconfig)) {
9627: $confhash{$itemid}{'crsconf'}{$item} = 1;
9628: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
9629: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
9630: $changes{$itemid} = 1;
9631: }
9632: } else {
9633: $changes{$itemid} = 1;
9634: }
9635: }
9636: }
1.267 raeburn 9637: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
9638: foreach my $field (@fields) {
9639: if ($possfield{$field}) {
9640: if ($field eq 'roles') {
9641: foreach my $role (@courseroles) {
9642: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
9643: if (($choice ne '') && ($posslti{$choice})) {
9644: $confhash{$itemid}{'roles'}{$role} = $choice;
9645: if ($role eq 'cc') {
9646: $confhash{$itemid}{'roles'}{'co'} = $choice;
9647: }
9648: }
9649: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
9650: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
9651: $changes{$itemid} = 1;
9652: }
9653: } elsif ($confhash{$itemid}{'roles'}{$role}) {
9654: $changes{$itemid} = 1;
9655: }
9656: }
9657: } else {
9658: $confhash{$itemid}{'fields'}{$field} = 1;
9659: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9660: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9661: $changes{$itemid} = 1;
9662: }
9663: } else {
9664: $changes{$itemid} = 1;
9665: }
9666: }
9667: }
9668: }
9669: $allpos[$newpos] = $itemid;
9670: }
9671: if ($imgdeletions{$itemid}) {
9672: $changes{$itemid} = 1;
9673: #FIXME need to obsolete item in RES space
9674: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9675: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9676: $itemid,$configuserok,$switchserver,
9677: $author_ok);
9678: if ($imgurl) {
9679: $confhash{$itemid}{'image'} = $imgurl;
9680: $changes{$itemid} = 1;
9681: }
9682: if ($error) {
9683: &Apache::lonnet::logthis($error);
9684: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9685: }
9686: } elsif ($domconfig{$action}{$itemid}{'image'}) {
9687: $confhash{$itemid}{'image'} =
9688: $domconfig{$action}{$itemid}{'image'};
9689: }
9690: if ($customadds{$i}) {
9691: my $name = $env{'form.ltitools_custom_name_'.$i};
9692: $name =~ s/(`)/'/g;
9693: $name =~ s/^\s+//;
9694: $name =~ s/\s+$//;
9695: my $value = $env{'form.ltitools_custom_value_'.$i};
9696: $value =~ s/(`)/'/g;
9697: $value =~ s/^\s+//;
9698: $value =~ s/\s+$//;
9699: if ($name ne '') {
9700: $confhash{$itemid}{'custom'}{$name} = $value;
9701: $changes{$itemid} = 1;
9702: }
9703: }
9704: my %customdels;
9705: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9706: if (@customdeletions) {
9707: $changes{$itemid} = 1;
9708: }
9709: map { $customdels{$_} = 1; } @customdeletions;
9710: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9711: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9712: unless ($customdels{$key}) {
9713: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9714: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9715: }
9716: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9717: $changes{$itemid} = 1;
9718: }
9719: }
9720: }
9721: }
9722: unless ($changes{$itemid}) {
9723: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9724: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9725: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9726: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9727: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9728: $changes{$itemid} = 1;
9729: last;
9730: }
9731: }
9732: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9733: $changes{$itemid} = 1;
9734: }
9735: }
9736: last if ($changes{$itemid});
9737: }
9738: }
9739: }
9740: }
9741: }
9742: if (@allpos > 0) {
9743: my $idx = 0;
9744: foreach my $itemid (@allpos) {
9745: if ($itemid ne '') {
9746: $confhash{$itemid}{'order'} = $idx;
9747: if (ref($domconfig{$action}) eq 'HASH') {
9748: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9749: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9750: $changes{$itemid} = 1;
9751: }
9752: }
9753: }
9754: $idx ++;
9755: }
9756: }
9757: }
9758: my %ltitoolshash = (
9759: $action => { %confhash }
9760: );
9761: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9762: $dom);
9763: if ($putresult eq 'ok') {
9764: if (keys(%changes) > 0) {
9765: my $cachetime = 24*60*60;
9766: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
9767: if (ref($lastactref) eq 'HASH') {
9768: $lastactref->{'ltitools'} = 1;
9769: }
9770: $resulttext = &mt('Changes made:').'<ul>';
9771: my %bynum;
9772: foreach my $itemid (sort(keys(%changes))) {
9773: my $position = $confhash{$itemid}{'order'};
9774: $bynum{$position} = $itemid;
9775: }
9776: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9777: my $itemid = $bynum{$pos};
9778: if (ref($confhash{$itemid}) ne 'HASH') {
9779: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9780: } else {
9781: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9782: if ($confhash{$itemid}{'image'}) {
9783: $resulttext .= ' '.
9784: '<img src="'.$confhash{$itemid}{'image'}.'"'.
9785: ' alt="'.&mt('Tool Provider icon').'" />';
9786: }
9787: $resulttext .= '</li><ul>';
9788: my $position = $pos + 1;
9789: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9790: foreach my $item ('version','msgtype','url','key') {
9791: if ($confhash{$itemid}{$item} ne '') {
9792: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9793: }
9794: }
9795: if ($confhash{$itemid}{'secret'} ne '') {
9796: $resulttext .= '<li>'.$lt{'secret'}.': ';
9797: my $num = length($confhash{$itemid}{'secret'});
9798: $resulttext .= ('*'x$num).'</li>';
9799: }
1.273 raeburn 9800: $resulttext .= '<li>'.&mt('Configurable in course:');
9801: my @possconfig = ('label','title','target');
9802: my $numconfig = 0;
9803: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9804: foreach my $item (@possconfig) {
9805: if ($confhash{$itemid}{'crsconf'}{$item}) {
9806: $numconfig ++;
9807: $resulttext .= ' '.$lt{'crs'.$item};
9808: }
9809: }
9810: }
9811: if (!$numconfig) {
9812: $resulttext .= &mt('None');
9813: }
9814: $resulttext .= '</li>';
1.267 raeburn 9815: foreach my $item ('passback','roster') {
9816: $resulttext .= '<li>'.$lt{$item}.' ';
9817: if ($confhash{$itemid}{$item}) {
9818: $resulttext .= &mt('Yes');
9819: } else {
9820: $resulttext .= &mt('No');
9821: }
9822: $resulttext .= '</li>';
9823: }
9824: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9825: my $displaylist;
9826: if ($confhash{$itemid}{'display'}{'target'}) {
9827: $displaylist = &mt('Display target').': '.
9828: $confhash{$itemid}{'display'}{'target'}.',';
9829: }
9830: foreach my $size ('width','height') {
9831: if ($confhash{$itemid}{'display'}{$size}) {
9832: $displaylist .= (' 'x2).$lt{$size}.': '.
9833: $confhash{$itemid}{'display'}{$size}.',';
9834: }
9835: }
9836: if ($displaylist) {
9837: $displaylist =~ s/,$//;
9838: $resulttext .= '<li>'.$displaylist.'</li>';
9839: }
9840: }
9841: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9842: my $fieldlist;
9843: foreach my $field (@allfields) {
9844: if ($confhash{$itemid}{'fields'}{$field}) {
9845: $fieldlist .= (' 'x2).$lt{$field}.',';
9846: }
9847: }
9848: if ($fieldlist) {
9849: $fieldlist =~ s/,$//;
9850: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9851: }
9852: }
9853: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9854: my $rolemaps;
9855: foreach my $role (@courseroles) {
9856: if ($confhash{$itemid}{'roles'}{$role}) {
9857: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9858: $confhash{$itemid}{'roles'}{$role}.',';
9859: }
9860: }
9861: if ($rolemaps) {
9862: $rolemaps =~ s/,$//;
9863: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9864: }
9865: }
9866: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9867: my $customlist;
9868: if (keys(%{$confhash{$itemid}{'custom'}})) {
9869: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9870: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9871: }
9872: }
9873: if ($customlist) {
9874: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9875: }
9876: }
9877: $resulttext .= '</ul></li>';
9878: }
9879: }
9880: $resulttext .= '</ul>';
9881: } else {
9882: $resulttext = &mt('No changes made.');
9883: }
9884: } else {
9885: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9886: }
9887: if ($errors) {
9888: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9889: $errors.'</ul>';
9890: }
9891: return $resulttext;
9892: }
9893:
9894: sub process_ltitools_image {
9895: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9896: my $filename = $env{'form.'.$caller.'.filename'};
9897: my ($error,$url);
9898: my ($width,$height) = (21,21);
9899: if ($configuserok eq 'ok') {
9900: if ($switchserver) {
9901: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9902: $switchserver);
9903: } elsif ($author_ok eq 'ok') {
9904: my ($result,$imageurl,$madethumb) =
9905: &publishlogo($r,'upload',$caller,$dom,$confname,
9906: "ltitools/$itemid/icon",$width,$height);
9907: if ($result eq 'ok') {
9908: if ($madethumb) {
9909: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9910: my $imagethumb = "$path/tn-".$imagefile;
9911: $url = $imagethumb;
9912: } else {
9913: $url = $imageurl;
9914: }
9915: } else {
9916: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9917: }
9918: } else {
9919: $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);
9920: }
9921: } else {
9922: $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);
9923: }
9924: return ($url,$error);
9925: }
9926:
9927: sub get_ltitools_id {
9928: my ($cdom,$title) = @_;
9929: # get lock on ltitools db
9930: my $lockhash = {
9931: lock => $env{'user.name'}.
9932: ':'.$env{'user.domain'},
9933: };
9934: my $tries = 0;
9935: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9936: my ($id,$error);
9937:
9938: while (($gotlock ne 'ok') && ($tries<10)) {
9939: $tries ++;
9940: sleep (0.1);
9941: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9942: }
9943: if ($gotlock eq 'ok') {
9944: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9945: if ($currids{'lock'}) {
9946: delete($currids{'lock'});
9947: if (keys(%currids)) {
9948: my @curr = sort { $a <=> $b } keys(%currids);
9949: if ($curr[-1] =~ /^\d+$/) {
9950: $id = 1 + $curr[-1];
9951: }
9952: } else {
9953: $id = 1;
9954: }
9955: if ($id) {
9956: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
9957: $error = 'nostore';
9958: }
9959: } else {
9960: $error = 'nonumber';
9961: }
9962: }
9963: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
9964: } else {
9965: $error = 'nolock';
9966: }
9967: return ($id,$error);
9968: }
9969:
1.3 raeburn 9970: sub modify_autoenroll {
1.205 raeburn 9971: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9972: my ($resulttext,%changes);
9973: my %currautoenroll;
9974: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9975: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9976: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9977: }
9978: }
9979: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9980: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9981: sender => 'Sender for notification messages',
1.274 raeburn 9982: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9983: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9984: my @offon = ('off','on');
1.17 raeburn 9985: my $sender_uname = $env{'form.sender_uname'};
9986: my $sender_domain = $env{'form.sender_domain'};
9987: if ($sender_domain eq '') {
9988: $sender_uname = '';
9989: } elsif ($sender_uname eq '') {
9990: $sender_domain = '';
9991: }
1.129 raeburn 9992: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 9993: my $failsafe = $env{'form.autoenroll_failsafe'};
9994: $failsafe =~ s{^\s+|\s+$}{}g;
9995: if ($failsafe =~ /\D/) {
9996: undef($failsafe);
9997: }
1.1 raeburn 9998: my %autoenrollhash = (
1.129 raeburn 9999: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10000: 'sender_uname' => $sender_uname,
10001: 'sender_domain' => $sender_domain,
10002: 'co-owners' => $coowners,
1.274 raeburn 10003: 'autofailsafe' => $failsafe,
1.1 raeburn 10004: }
10005: );
1.4 raeburn 10006: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10007: $dom);
1.1 raeburn 10008: if ($putresult eq 'ok') {
10009: if (exists($currautoenroll{'run'})) {
10010: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10011: $changes{'run'} = 1;
10012: }
10013: } elsif ($autorun) {
10014: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 10015: $changes{'run'} = 1;
1.1 raeburn 10016: }
10017: }
1.17 raeburn 10018: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 10019: $changes{'sender'} = 1;
10020: }
1.17 raeburn 10021: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 10022: $changes{'sender'} = 1;
10023: }
1.129 raeburn 10024: if ($currautoenroll{'co-owners'} ne '') {
10025: if ($currautoenroll{'co-owners'} ne $coowners) {
10026: $changes{'coowners'} = 1;
10027: }
10028: } elsif ($coowners) {
10029: $changes{'coowners'} = 1;
1.274 raeburn 10030: }
10031: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10032: $changes{'autofailsafe'} = 1;
10033: }
1.1 raeburn 10034: if (keys(%changes) > 0) {
10035: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 10036: if ($changes{'run'}) {
1.1 raeburn 10037: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10038: }
10039: if ($changes{'sender'}) {
1.17 raeburn 10040: if ($sender_uname eq '' || $sender_domain eq '') {
10041: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10042: } else {
10043: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10044: }
1.1 raeburn 10045: }
1.129 raeburn 10046: if ($changes{'coowners'}) {
10047: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10048: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10049: if (ref($lastactref) eq 'HASH') {
10050: $lastactref->{'domainconfig'} = 1;
10051: }
1.129 raeburn 10052: }
1.274 raeburn 10053: if ($changes{'autofailsafe'}) {
10054: if ($failsafe ne '') {
10055: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
10056: } else {
10057: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
10058: }
10059: &Apache::lonnet::get_domain_defaults($dom,1);
10060: if (ref($lastactref) eq 'HASH') {
10061: $lastactref->{'domdefaults'} = 1;
10062: }
10063: }
1.1 raeburn 10064: $resulttext .= '</ul>';
10065: } else {
10066: $resulttext = &mt('No changes made to auto-enrollment settings');
10067: }
10068: } else {
1.11 albertel 10069: $resulttext = '<span class="LC_error">'.
10070: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10071: }
1.3 raeburn 10072: return $resulttext;
1.1 raeburn 10073: }
10074:
10075: sub modify_autoupdate {
1.3 raeburn 10076: my ($dom,%domconfig) = @_;
1.1 raeburn 10077: my ($resulttext,%currautoupdate,%fields,%changes);
10078: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10079: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10080: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10081: }
10082: }
10083: my @offon = ('off','on');
10084: my %title = &Apache::lonlocal::texthash (
10085: run => 'Auto-update:',
10086: classlists => 'Updates to user information in classlists?'
10087: );
1.44 raeburn 10088: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10089: my %fieldtitles = &Apache::lonlocal::texthash (
10090: id => 'Student/Employee ID',
1.20 raeburn 10091: permanentemail => 'E-mail address',
1.1 raeburn 10092: lastname => 'Last Name',
10093: firstname => 'First Name',
10094: middlename => 'Middle Name',
1.132 raeburn 10095: generation => 'Generation',
1.1 raeburn 10096: );
1.142 raeburn 10097: $othertitle = &mt('All users');
1.1 raeburn 10098: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10099: $othertitle = &mt('Other users');
1.1 raeburn 10100: }
10101: foreach my $key (keys(%env)) {
10102: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10103: my ($usertype,$item) = ($1,$2);
10104: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10105: if ($usertype eq 'default') {
10106: push(@{$fields{$1}},$2);
10107: } elsif (ref($types) eq 'ARRAY') {
10108: if (grep(/^\Q$usertype\E$/,@{$types})) {
10109: push(@{$fields{$1}},$2);
10110: }
10111: }
10112: }
1.1 raeburn 10113: }
10114: }
1.131 raeburn 10115: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10116: @lockablenames = sort(@lockablenames);
10117: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10118: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10119: if (@changed) {
10120: $changes{'lockablenames'} = 1;
10121: }
10122: } else {
10123: if (@lockablenames) {
10124: $changes{'lockablenames'} = 1;
10125: }
10126: }
1.1 raeburn 10127: my %updatehash = (
10128: autoupdate => { run => $env{'form.autoupdate_run'},
10129: classlists => $env{'form.classlists'},
10130: fields => {%fields},
1.131 raeburn 10131: lockablenames => \@lockablenames,
1.1 raeburn 10132: }
10133: );
10134: foreach my $key (keys(%currautoupdate)) {
10135: if (($key eq 'run') || ($key eq 'classlists')) {
10136: if (exists($updatehash{autoupdate}{$key})) {
10137: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10138: $changes{$key} = 1;
10139: }
10140: }
10141: } elsif ($key eq 'fields') {
10142: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10143: foreach my $item (@{$types},'default') {
1.1 raeburn 10144: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10145: my $change = 0;
10146: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10147: if (!exists($fields{$item})) {
10148: $change = 1;
1.132 raeburn 10149: last;
1.1 raeburn 10150: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10151: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10152: $change = 1;
1.132 raeburn 10153: last;
1.1 raeburn 10154: }
10155: }
10156: }
10157: if ($change) {
10158: push(@{$changes{$key}},$item);
10159: }
1.26 raeburn 10160: }
1.1 raeburn 10161: }
10162: }
1.131 raeburn 10163: } elsif ($key eq 'lockablenames') {
10164: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10165: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10166: if (@changed) {
10167: $changes{'lockablenames'} = 1;
10168: }
10169: } else {
10170: if (@lockablenames) {
10171: $changes{'lockablenames'} = 1;
10172: }
10173: }
10174: }
10175: }
10176: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10177: if (@lockablenames) {
10178: $changes{'lockablenames'} = 1;
1.1 raeburn 10179: }
10180: }
1.26 raeburn 10181: foreach my $item (@{$types},'default') {
10182: if (defined($fields{$item})) {
10183: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10184: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10185: my $change = 0;
10186: if (ref($fields{$item}) eq 'ARRAY') {
10187: foreach my $type (@{$fields{$item}}) {
10188: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10189: $change = 1;
10190: last;
10191: }
10192: }
10193: }
10194: if ($change) {
10195: push(@{$changes{'fields'}},$item);
10196: }
10197: } else {
1.26 raeburn 10198: push(@{$changes{'fields'}},$item);
10199: }
10200: } else {
10201: push(@{$changes{'fields'}},$item);
1.1 raeburn 10202: }
10203: }
10204: }
10205: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10206: $dom);
10207: if ($putresult eq 'ok') {
10208: if (keys(%changes) > 0) {
10209: $resulttext = &mt('Changes made:').'<ul>';
10210: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10211: if ($key eq 'lockablenames') {
10212: $resulttext .= '<li>';
10213: if (@lockablenames) {
10214: $usertypes->{'default'} = $othertitle;
10215: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10216: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10217: } else {
10218: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10219: }
10220: $resulttext .= '</li>';
10221: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10222: foreach my $item (@{$changes{$key}}) {
10223: my @newvalues;
10224: foreach my $type (@{$fields{$item}}) {
10225: push(@newvalues,$fieldtitles{$type});
10226: }
1.3 raeburn 10227: my $newvaluestr;
10228: if (@newvalues > 0) {
10229: $newvaluestr = join(', ',@newvalues);
10230: } else {
10231: $newvaluestr = &mt('none');
1.6 raeburn 10232: }
1.1 raeburn 10233: if ($item eq 'default') {
1.26 raeburn 10234: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10235: } else {
1.26 raeburn 10236: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10237: }
10238: }
10239: } else {
10240: my $newvalue;
10241: if ($key eq 'run') {
10242: $newvalue = $offon[$env{'form.autoupdate_run'}];
10243: } else {
10244: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10245: }
1.1 raeburn 10246: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10247: }
10248: }
10249: $resulttext .= '</ul>';
10250: } else {
1.3 raeburn 10251: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10252: }
10253: } else {
1.11 albertel 10254: $resulttext = '<span class="LC_error">'.
10255: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10256: }
1.3 raeburn 10257: return $resulttext;
1.1 raeburn 10258: }
10259:
1.125 raeburn 10260: sub modify_autocreate {
10261: my ($dom,%domconfig) = @_;
10262: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10263: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10264: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10265: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10266: }
10267: }
10268: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10269: req => 'Auto-creation of validated requests for official courses',
10270: xmldc => 'Identity of course creator of courses from XML files',
10271: );
10272: my @types = ('xml','req');
10273: foreach my $item (@types) {
10274: $newvals{$item} = $env{'form.autocreate_'.$item};
10275: $newvals{$item} =~ s/\D//g;
10276: $newvals{$item} = 0 if ($newvals{$item} eq '');
10277: }
10278: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 10279: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10280: unless (exists($domcoords{$newvals{'xmldc'}})) {
10281: $newvals{'xmldc'} = '';
10282: }
10283: %autocreatehash = (
10284: autocreate => { xml => $newvals{'xml'},
10285: req => $newvals{'req'},
10286: }
10287: );
10288: if ($newvals{'xmldc'} ne '') {
10289: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10290: }
10291: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10292: $dom);
10293: if ($putresult eq 'ok') {
10294: my @items = @types;
10295: if ($newvals{'xml'}) {
10296: push(@items,'xmldc');
10297: }
10298: foreach my $item (@items) {
10299: if (exists($currautocreate{$item})) {
10300: if ($currautocreate{$item} ne $newvals{$item}) {
10301: $changes{$item} = 1;
10302: }
10303: } elsif ($newvals{$item}) {
10304: $changes{$item} = 1;
10305: }
10306: }
10307: if (keys(%changes) > 0) {
10308: my @offon = ('off','on');
10309: $resulttext = &mt('Changes made:').'<ul>';
10310: foreach my $item (@types) {
10311: if ($changes{$item}) {
10312: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 10313: $resulttext .= '<li>'.
10314: &mt("$title{$item} set to [_1]$newtxt [_2]",
10315: '<b>','</b>').
10316: '</li>';
1.125 raeburn 10317: }
10318: }
10319: if ($changes{'xmldc'}) {
10320: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10321: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 10322: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10323: }
10324: $resulttext .= '</ul>';
10325: } else {
10326: $resulttext = &mt('No changes made to auto-creation settings');
10327: }
10328: } else {
10329: $resulttext = '<span class="LC_error">'.
10330: &mt('An error occurred: [_1]',$putresult).'</span>';
10331: }
10332: return $resulttext;
10333: }
10334:
1.23 raeburn 10335: sub modify_directorysrch {
10336: my ($dom,%domconfig) = @_;
10337: my ($resulttext,%changes);
10338: my %currdirsrch;
10339: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10340: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10341: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10342: }
10343: }
1.277 raeburn 10344: my %title = ( available => 'Institutional directory search available',
10345: localonly => 'Other domains can search institution',
10346: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 10347: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10348: searchby => 'Search types',
10349: searchtypes => 'Search latitude');
10350: my @offon = ('off','on');
1.24 raeburn 10351: my @otherdoms = ('Yes','No');
1.23 raeburn 10352:
1.25 raeburn 10353: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10354: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10355: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10356:
1.44 raeburn 10357: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10358: if (keys(%{$usertypes}) == 0) {
10359: @cansearch = ('default');
10360: } else {
10361: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10362: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10363: if (!grep(/^\Q$type\E$/,@cansearch)) {
10364: push(@{$changes{'cansearch'}},$type);
10365: }
1.23 raeburn 10366: }
1.26 raeburn 10367: foreach my $type (@cansearch) {
10368: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10369: push(@{$changes{'cansearch'}},$type);
10370: }
1.23 raeburn 10371: }
1.26 raeburn 10372: } else {
10373: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10374: }
10375: }
10376:
10377: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10378: foreach my $by (@{$currdirsrch{'searchby'}}) {
10379: if (!grep(/^\Q$by\E$/,@searchby)) {
10380: push(@{$changes{'searchby'}},$by);
10381: }
10382: }
10383: foreach my $by (@searchby) {
10384: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10385: push(@{$changes{'searchby'}},$by);
10386: }
10387: }
10388: } else {
10389: push(@{$changes{'searchby'}},@searchby);
10390: }
1.25 raeburn 10391:
10392: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10393: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10394: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10395: push(@{$changes{'searchtypes'}},$type);
10396: }
10397: }
10398: foreach my $type (@searchtypes) {
10399: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10400: push(@{$changes{'searchtypes'}},$type);
10401: }
10402: }
10403: } else {
10404: if (exists($currdirsrch{'searchtypes'})) {
10405: foreach my $type (@searchtypes) {
10406: if ($type ne $currdirsrch{'searchtypes'}) {
10407: push(@{$changes{'searchtypes'}},$type);
10408: }
10409: }
10410: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10411: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10412: }
10413: } else {
10414: push(@{$changes{'searchtypes'}},@searchtypes);
10415: }
10416: }
10417:
1.23 raeburn 10418: my %dirsrch_hash = (
10419: directorysrch => { available => $env{'form.dirsrch_available'},
10420: cansearch => \@cansearch,
1.277 raeburn 10421: localonly => $env{'form.dirsrch_instlocalonly'},
10422: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10423: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10424: searchby => \@searchby,
1.25 raeburn 10425: searchtypes => \@searchtypes,
1.23 raeburn 10426: }
10427: );
10428: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10429: $dom);
10430: if ($putresult eq 'ok') {
10431: if (exists($currdirsrch{'available'})) {
10432: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10433: $changes{'available'} = 1;
10434: }
10435: } else {
10436: if ($env{'form.dirsrch_available'} eq '1') {
10437: $changes{'available'} = 1;
10438: }
10439: }
1.277 raeburn 10440: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 10441: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10442: $changes{'lcavailable'} = 1;
10443: }
1.277 raeburn 10444: } else {
10445: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10446: $changes{'lcavailable'} = 1;
10447: }
10448: }
1.24 raeburn 10449: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 10450: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
10451: $changes{'localonly'} = 1;
10452: }
1.24 raeburn 10453: } else {
1.277 raeburn 10454: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 10455: $changes{'localonly'} = 1;
10456: }
10457: }
1.277 raeburn 10458: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 10459: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10460: $changes{'lclocalonly'} = 1;
10461: }
1.277 raeburn 10462: } else {
10463: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10464: $changes{'lclocalonly'} = 1;
10465: }
10466: }
1.23 raeburn 10467: if (keys(%changes) > 0) {
10468: $resulttext = &mt('Changes made:').'<ul>';
10469: if ($changes{'available'}) {
10470: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10471: }
1.277 raeburn 10472: if ($changes{'lcavailable'}) {
10473: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10474: }
1.24 raeburn 10475: if ($changes{'localonly'}) {
1.277 raeburn 10476: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 10477: }
1.277 raeburn 10478: if ($changes{'lclocalonly'}) {
10479: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 10480: }
1.23 raeburn 10481: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10482: my $chgtext;
1.26 raeburn 10483: if (ref($usertypes) eq 'HASH') {
10484: if (keys(%{$usertypes}) > 0) {
10485: foreach my $type (@{$types}) {
10486: if (grep(/^\Q$type\E$/,@cansearch)) {
10487: $chgtext .= $usertypes->{$type}.'; ';
10488: }
10489: }
10490: if (grep(/^default$/,@cansearch)) {
10491: $chgtext .= $othertitle;
10492: } else {
10493: $chgtext =~ s/\; $//;
10494: }
1.210 raeburn 10495: $resulttext .=
1.178 raeburn 10496: '<li>'.
10497: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10498: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10499: '</li>';
1.23 raeburn 10500: }
10501: }
10502: }
10503: if (ref($changes{'searchby'}) eq 'ARRAY') {
10504: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10505: my $chgtext;
10506: foreach my $type (@{$titleorder}) {
10507: if (grep(/^\Q$type\E$/,@searchby)) {
10508: if (defined($searchtitles->{$type})) {
10509: $chgtext .= $searchtitles->{$type}.'; ';
10510: }
10511: }
10512: }
10513: $chgtext =~ s/\; $//;
10514: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10515: }
1.25 raeburn 10516: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10517: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10518: my $chgtext;
10519: foreach my $type (@{$srchtypeorder}) {
10520: if (grep(/^\Q$type\E$/,@searchtypes)) {
10521: if (defined($srchtypes_desc->{$type})) {
10522: $chgtext .= $srchtypes_desc->{$type}.'; ';
10523: }
10524: }
10525: }
10526: $chgtext =~ s/\; $//;
1.178 raeburn 10527: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10528: }
10529: $resulttext .= '</ul>';
10530: } else {
1.277 raeburn 10531: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10532: }
10533: } else {
10534: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10535: &mt('An error occurred: [_1]',$putresult).'</span>';
10536: }
10537: return $resulttext;
10538: }
10539:
1.28 raeburn 10540: sub modify_contacts {
1.205 raeburn 10541: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10542: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10543: if (ref($domconfig{'contacts'}) eq 'HASH') {
10544: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10545: $currsetting{$key} = $domconfig{'contacts'}{$key};
10546: }
10547: }
1.286 raeburn 10548: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10549: my @contacts = ('supportemail','adminemail');
1.286 raeburn 10550: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10551: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 10552: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 10553: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10554: foreach my $type (@mailings) {
10555: @{$newsetting{$type}} =
10556: &Apache::loncommon::get_env_multiple('form.'.$type);
10557: foreach my $item (@contacts) {
10558: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10559: $contacts_hash{contacts}{$type}{$item} = 1;
10560: } else {
10561: $contacts_hash{contacts}{$type}{$item} = 0;
10562: }
1.289 raeburn 10563: }
1.28 raeburn 10564: $others{$type} = $env{'form.'.$type.'_others'};
10565: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 10566: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10567: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10568: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 10569: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10570: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10571: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10572: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10573: }
1.134 raeburn 10574: }
1.28 raeburn 10575: }
10576: foreach my $item (@contacts) {
10577: $to{$item} = $env{'form.'.$item};
10578: $contacts_hash{'contacts'}{$item} = $to{$item};
10579: }
1.203 raeburn 10580: foreach my $item (@toggles) {
10581: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10582: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10583: }
10584: }
1.286 raeburn 10585: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10586: foreach my $field (@{$fields}) {
10587: if (ref($possoptions->{$field}) eq 'ARRAY') {
10588: my $value = $env{'form.helpform_'.$field};
10589: $value =~ s/^\s+|\s+$//g;
10590: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10591: $contacts_hash{contacts}{'helpform'}{$field} = $value;
10592: if ($field eq 'screenshot') {
10593: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10594: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10595: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10596: }
10597: }
10598: }
10599: }
10600: }
10601: }
1.28 raeburn 10602: if (keys(%currsetting) > 0) {
10603: foreach my $item (@contacts) {
10604: if ($to{$item} ne $currsetting{$item}) {
10605: $changes{$item} = 1;
10606: }
10607: }
10608: foreach my $type (@mailings) {
10609: foreach my $item (@contacts) {
10610: if (ref($currsetting{$type}) eq 'HASH') {
10611: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10612: push(@{$changes{$type}},$item);
10613: }
10614: } else {
10615: push(@{$changes{$type}},@{$newsetting{$type}});
10616: }
10617: }
10618: if ($others{$type} ne $currsetting{$type}{'others'}) {
10619: push(@{$changes{$type}},'others');
10620: }
1.289 raeburn 10621: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10622: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10623: push(@{$changes{$type}},'bcc');
10624: }
1.286 raeburn 10625: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10626: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10627: push(@{$changes{$type}},'include');
10628: }
10629: }
10630: }
10631: if (ref($fields) eq 'ARRAY') {
10632: if (ref($currsetting{'helpform'}) eq 'HASH') {
10633: foreach my $field (@{$fields}) {
10634: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10635: push(@{$changes{'helpform'}},$field);
10636: }
10637: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10638: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10639: push(@{$changes{'helpform'}},'maxsize');
10640: }
10641: }
10642: }
10643: } else {
10644: foreach my $field (@{$fields}) {
10645: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10646: push(@{$changes{'helpform'}},$field);
10647: }
10648: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10649: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10650: push(@{$changes{'helpform'}},'maxsize');
10651: }
10652: }
10653: }
1.134 raeburn 10654: }
1.28 raeburn 10655: }
10656: } else {
10657: my %default;
10658: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10659: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10660: $default{'errormail'} = 'adminemail';
10661: $default{'packagesmail'} = 'adminemail';
10662: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 10663: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10664: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10665: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 10666: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 10667: foreach my $item (@contacts) {
10668: if ($to{$item} ne $default{$item}) {
1.286 raeburn 10669: $changes{$item} = 1;
1.203 raeburn 10670: }
1.28 raeburn 10671: }
10672: foreach my $type (@mailings) {
10673: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10674: push(@{$changes{$type}},@{$newsetting{$type}});
10675: }
10676: if ($others{$type} ne '') {
10677: push(@{$changes{$type}},'others');
1.134 raeburn 10678: }
1.286 raeburn 10679: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10680: if ($bcc{$type} ne '') {
10681: push(@{$changes{$type}},'bcc');
10682: }
1.286 raeburn 10683: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10684: push(@{$changes{$type}},'include');
10685: }
1.134 raeburn 10686: }
1.28 raeburn 10687: }
1.286 raeburn 10688: if (ref($fields) eq 'ARRAY') {
10689: foreach my $field (@{$fields}) {
10690: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10691: push(@{$changes{'helpform'}},$field);
10692: }
10693: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10694: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10695: push(@{$changes{'helpform'}},'maxsize');
10696: }
10697: }
10698: }
1.289 raeburn 10699: }
1.28 raeburn 10700: }
1.203 raeburn 10701: foreach my $item (@toggles) {
10702: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10703: $changes{$item} = 1;
10704: } elsif ((!$env{'form.'.$item}) &&
10705: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10706: $changes{$item} = 1;
10707: }
10708: }
1.28 raeburn 10709: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10710: $dom);
10711: if ($putresult eq 'ok') {
10712: if (keys(%changes) > 0) {
1.205 raeburn 10713: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10714: if (ref($lastactref) eq 'HASH') {
10715: $lastactref->{'domainconfig'} = 1;
10716: }
1.28 raeburn 10717: my ($titles,$short_titles) = &contact_titles();
10718: $resulttext = &mt('Changes made:').'<ul>';
10719: foreach my $item (@contacts) {
10720: if ($changes{$item}) {
10721: $resulttext .= '<li>'.$titles->{$item}.
10722: &mt(' set to: ').
10723: '<span class="LC_cusr_emph">'.
10724: $to{$item}.'</span></li>';
10725: }
10726: }
10727: foreach my $type (@mailings) {
10728: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 10729: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 10730: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 10731: } else {
10732: $resulttext .= '<li>'.$titles->{$type}.': ';
10733: }
1.28 raeburn 10734: my @text;
10735: foreach my $item (@{$newsetting{$type}}) {
10736: push(@text,$short_titles->{$item});
10737: }
10738: if ($others{$type} ne '') {
10739: push(@text,$others{$type});
10740: }
1.286 raeburn 10741: if (@text) {
10742: $resulttext .= '<span class="LC_cusr_emph">'.
10743: join(', ',@text).'</span>';
10744: }
10745: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10746: if ($bcc{$type} ne '') {
1.286 raeburn 10747: my $bcctext;
10748: if (@text) {
1.289 raeburn 10749: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 10750: } else {
10751: $bcctext = '(Bcc)';
10752: }
10753: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10754: } elsif (!@text) {
10755: $resulttext .= &mt('No one');
10756: }
1.289 raeburn 10757: if ($includestr{$type} ne '') {
1.286 raeburn 10758: if ($includeloc{$type} eq 'b') {
10759: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10760: } elsif ($includeloc{$type} eq 's') {
10761: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10762: }
1.134 raeburn 10763: }
1.286 raeburn 10764: } elsif (!@text) {
10765: $resulttext .= &mt('No recipients');
1.134 raeburn 10766: }
10767: $resulttext .= '</li>';
1.28 raeburn 10768: }
10769: }
1.203 raeburn 10770: my @offon = ('off','on');
10771: if ($changes{'reporterrors'}) {
10772: $resulttext .= '<li>'.
10773: &mt('E-mail error reports to [_1] set to "'.
10774: $offon[$env{'form.reporterrors'}].'".',
10775: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10776: &mt('LON-CAPA core group - MSU'),600,500)).
10777: '</li>';
10778: }
10779: if ($changes{'reportupdates'}) {
10780: $resulttext .= '<li>'.
10781: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10782: $offon[$env{'form.reportupdates'}].'".',
10783: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10784: &mt('LON-CAPA core group - MSU'),600,500)).
10785: '</li>';
10786: }
1.286 raeburn 10787: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10788: my (@optional,@required,@unused,$maxsizechg);
10789: foreach my $field (@{$changes{'helpform'}}) {
10790: if ($field eq 'maxsize') {
10791: $maxsizechg = 1;
10792: next;
10793: }
10794: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 10795: push(@optional,$field);
1.286 raeburn 10796: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10797: push(@unused,$field);
10798: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 10799: push(@required,$field);
1.286 raeburn 10800: }
10801: }
10802: if (@optional) {
10803: $resulttext .= '<li>'.
10804: &mt('Help form fields changed to "Optional": [_1].',
10805: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10806: '</li>';
10807: }
10808: if (@required) {
10809: $resulttext .= '<li>'.
10810: &mt('Help form fields changed to "Required": [_1].',
10811: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10812: '</li>';
10813: }
10814: if (@unused) {
10815: $resulttext .= '<li>'.
10816: &mt('Help form fields changed to "Not shown": [_1].',
10817: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10818: '</li>';
10819: }
10820: if ($maxsizechg) {
10821: $resulttext .= '<li>'.
10822: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10823: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10824: '</li>';
10825:
10826: }
10827: }
1.28 raeburn 10828: $resulttext .= '</ul>';
10829: } else {
1.288 raeburn 10830: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10831: }
10832: } else {
10833: $resulttext = '<span class="LC_error">'.
10834: &mt('An error occurred: [_1].',$putresult).'</span>';
10835: }
10836: return $resulttext;
10837: }
10838:
10839: sub modify_usercreation {
1.27 raeburn 10840: my ($dom,%domconfig) = @_;
1.224 raeburn 10841: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 10842: my $warningmsg;
1.27 raeburn 10843: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10844: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 10845: if ($key eq 'cancreate') {
10846: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10847: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10848: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 10849: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10850: ($item eq 'recaptchaversion')) {
1.224 raeburn 10851: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10852: } else {
10853: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10854: }
10855: }
10856: }
10857: } elsif ($key eq 'email_rule') {
10858: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10859: } else {
10860: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10861: }
1.27 raeburn 10862: }
10863: }
10864: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 10865: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 10866: my @contexts = ('author','course','requestcrs');
1.34 raeburn 10867: foreach my $item(@contexts) {
1.224 raeburn 10868: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 10869: }
1.34 raeburn 10870: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10871: foreach my $item (@contexts) {
1.224 raeburn 10872: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10873: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 10874: }
1.27 raeburn 10875: }
1.34 raeburn 10876: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10877: foreach my $item (@contexts) {
1.43 raeburn 10878: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10879: if ($cancreate{$item} ne 'any') {
10880: push(@{$changes{'cancreate'}},$item);
10881: }
10882: } else {
10883: if ($cancreate{$item} ne 'none') {
10884: push(@{$changes{'cancreate'}},$item);
10885: }
1.27 raeburn 10886: }
10887: }
10888: } else {
1.43 raeburn 10889: foreach my $item (@contexts) {
1.34 raeburn 10890: push(@{$changes{'cancreate'}},$item);
10891: }
1.27 raeburn 10892: }
1.34 raeburn 10893:
1.27 raeburn 10894: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10895: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10896: if (!grep(/^\Q$type\E$/,@username_rule)) {
10897: push(@{$changes{'username_rule'}},$type);
10898: }
10899: }
10900: foreach my $type (@username_rule) {
10901: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10902: push(@{$changes{'username_rule'}},$type);
10903: }
10904: }
10905: } else {
10906: push(@{$changes{'username_rule'}},@username_rule);
10907: }
10908:
1.32 raeburn 10909: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10910: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10911: if (!grep(/^\Q$type\E$/,@id_rule)) {
10912: push(@{$changes{'id_rule'}},$type);
10913: }
10914: }
10915: foreach my $type (@id_rule) {
10916: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10917: push(@{$changes{'id_rule'}},$type);
10918: }
10919: }
10920: } else {
10921: push(@{$changes{'id_rule'}},@id_rule);
10922: }
10923:
1.43 raeburn 10924: my @authen_contexts = ('author','course','domain');
1.28 raeburn 10925: my @authtypes = ('int','krb4','krb5','loc');
10926: my %authhash;
1.43 raeburn 10927: foreach my $item (@authen_contexts) {
1.28 raeburn 10928: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
10929: foreach my $auth (@authtypes) {
10930: if (grep(/^\Q$auth\E$/,@authallowed)) {
10931: $authhash{$item}{$auth} = 1;
10932: } else {
10933: $authhash{$item}{$auth} = 0;
10934: }
10935: }
10936: }
10937: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 10938: foreach my $item (@authen_contexts) {
1.28 raeburn 10939: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10940: foreach my $auth (@authtypes) {
10941: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10942: push(@{$changes{'authtypes'}},$item);
10943: last;
10944: }
10945: }
10946: }
10947: }
10948: } else {
1.43 raeburn 10949: foreach my $item (@authen_contexts) {
1.28 raeburn 10950: push(@{$changes{'authtypes'}},$item);
10951: }
10952: }
10953:
1.224 raeburn 10954: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10955: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10956: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10957: $save_usercreate{'id_rule'} = \@id_rule;
10958: $save_usercreate{'username_rule'} = \@username_rule,
10959: $save_usercreate{'authtypes'} = \%authhash;
10960:
1.27 raeburn 10961: my %usercreation_hash = (
1.224 raeburn 10962: usercreation => \%save_usercreate,
10963: );
1.27 raeburn 10964:
10965: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10966: $dom);
1.50 raeburn 10967:
1.224 raeburn 10968: if ($putresult eq 'ok') {
10969: if (keys(%changes) > 0) {
10970: $resulttext = &mt('Changes made:').'<ul>';
10971: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10972: my %lt = &usercreation_types();
10973: foreach my $type (@{$changes{'cancreate'}}) {
10974: my $chgtext = $lt{$type}.', ';
10975: if ($cancreate{$type} eq 'none') {
10976: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10977: } elsif ($cancreate{$type} eq 'any') {
10978: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10979: } elsif ($cancreate{$type} eq 'official') {
10980: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10981: } elsif ($cancreate{$type} eq 'unofficial') {
10982: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10983: }
10984: $resulttext .= '<li>'.$chgtext.'</li>';
10985: }
10986: }
10987: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10988: my ($rules,$ruleorder) =
10989: &Apache::lonnet::inst_userrules($dom,'username');
10990: my $chgtext = '<ul>';
10991: foreach my $type (@username_rule) {
10992: if (ref($rules->{$type}) eq 'HASH') {
10993: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10994: }
10995: }
10996: $chgtext .= '</ul>';
10997: if (@username_rule > 0) {
10998: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10999: } else {
11000: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11001: }
11002: }
11003: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11004: my ($idrules,$idruleorder) =
11005: &Apache::lonnet::inst_userrules($dom,'id');
11006: my $chgtext = '<ul>';
11007: foreach my $type (@id_rule) {
11008: if (ref($idrules->{$type}) eq 'HASH') {
11009: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11010: }
11011: }
11012: $chgtext .= '</ul>';
11013: if (@id_rule > 0) {
11014: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11015: } else {
11016: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11017: }
11018: }
11019: my %authname = &authtype_names();
11020: my %context_title = &context_names();
11021: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11022: my $chgtext = '<ul>';
11023: foreach my $type (@{$changes{'authtypes'}}) {
11024: my @allowed;
11025: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11026: foreach my $auth (@authtypes) {
11027: if ($authhash{$type}{$auth}) {
11028: push(@allowed,$authname{$auth});
11029: }
11030: }
11031: if (@allowed > 0) {
11032: $chgtext .= join(', ',@allowed).'</li>';
11033: } else {
11034: $chgtext .= &mt('none').'</li>';
11035: }
11036: }
11037: $chgtext .= '</ul>';
11038: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11039: $resulttext .= '</li>';
11040: }
11041: $resulttext .= '</ul>';
11042: } else {
11043: $resulttext = &mt('No changes made to user creation settings');
11044: }
11045: } else {
11046: $resulttext = '<span class="LC_error">'.
11047: &mt('An error occurred: [_1]',$putresult).'</span>';
11048: }
11049: if ($warningmsg ne '') {
11050: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11051: }
11052: return $resulttext;
11053: }
11054:
11055: sub modify_selfcreation {
11056: my ($dom,%domconfig) = @_;
11057: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
11058: my (%save_usercreate,%save_usermodify);
1.228 raeburn 11059: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11060: if (ref($types) eq 'ARRAY') {
11061: $usertypes->{'default'} = $othertitle;
11062: push(@{$types},'default');
11063: }
1.224 raeburn 11064: #
11065: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11066: #
11067: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11068: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11069: if ($key eq 'cancreate') {
11070: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11071: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11072: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
11073: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 11074: ($item eq 'recaptchaversion') ||
1.236 raeburn 11075: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 11076: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 11077: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11078: } else {
11079: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11080: }
11081: }
11082: }
11083: } elsif ($key eq 'email_rule') {
11084: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11085: } else {
11086: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11087: }
11088: }
11089: }
11090: #
11091: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11092: #
11093: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11094: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11095: if ($key eq 'selfcreate') {
11096: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11097: } else {
11098: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11099: }
11100: }
11101: }
11102:
11103: my @contexts = ('selfcreate');
11104: @{$cancreate{'selfcreate'}} = ();
11105: %{$cancreate{'emailusername'}} = ();
11106: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 11107: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 11108: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 11109: my %selfcreatetypes = (
11110: sso => 'users authenticated by institutional single sign on',
11111: login => 'users authenticated by institutional log-in',
1.236 raeburn 11112: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 11113: );
1.224 raeburn 11114: #
11115: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11116: # is permitted.
11117: #
1.236 raeburn 11118:
11119: my @statuses;
11120: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11121: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
11122: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
11123: }
11124: }
11125: push(@statuses,'default');
11126:
1.228 raeburn 11127: foreach my $item ('login','sso','email') {
1.224 raeburn 11128: if ($item eq 'email') {
1.236 raeburn 11129: if ($env{'form.cancreate_email'}) {
1.224 raeburn 11130: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 11131: push(@contexts,'selfcreateprocessing');
11132: foreach my $type (@statuses) {
11133: if ($type eq 'default') {
11134: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
11135: } else {
11136: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11137: }
11138: }
1.224 raeburn 11139: }
11140: } else {
11141: if ($env{'form.cancreate_'.$item}) {
11142: push(@{$cancreate{'selfcreate'}},$item);
11143: }
11144: }
11145: }
11146: my (@email_rule,%userinfo,%savecaptcha);
11147: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11148: #
1.228 raeburn 11149: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11150: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 11151: #
1.236 raeburn 11152:
1.244 raeburn 11153: if ($env{'form.cancreate_email'}) {
1.228 raeburn 11154: push(@contexts,'emailusername');
11155: if (ref($types) eq 'ARRAY') {
11156: foreach my $type (@{$types}) {
11157: if (ref($infofields) eq 'ARRAY') {
11158: foreach my $field (@{$infofields}) {
11159: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11160: $cancreate{'emailusername'}{$type}{$field} = $1;
11161: }
11162: }
1.224 raeburn 11163: }
11164: }
11165: }
11166: #
11167: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
11168: # queued requests for self-creation of account using e-mail address as username
11169: #
11170:
11171: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11172: @approvalnotify = sort(@approvalnotify);
11173: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11174: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11175: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11176: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11177: push(@{$changes{'cancreate'}},'notify');
11178: }
11179: } else {
11180: if ($cancreate{'notify'}{'approval'}) {
11181: push(@{$changes{'cancreate'}},'notify');
11182: }
11183: }
11184: } elsif ($cancreate{'notify'}{'approval'}) {
11185: push(@{$changes{'cancreate'}},'notify');
11186: }
11187:
11188: #
11189: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
11190: #
11191: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11192: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11193: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11194: if (@{$curr_usercreation{'email_rule'}} > 0) {
11195: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11196: if (!grep(/^\Q$type\E$/,@email_rule)) {
11197: push(@{$changes{'email_rule'}},$type);
11198: }
11199: }
11200: }
11201: if (@email_rule > 0) {
11202: foreach my $type (@email_rule) {
11203: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11204: push(@{$changes{'email_rule'}},$type);
11205: }
11206: }
11207: }
11208: } elsif (@email_rule > 0) {
11209: push(@{$changes{'email_rule'}},@email_rule);
11210: }
11211: }
11212: #
1.236 raeburn 11213: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 11214: # institutional log-in.
11215: #
11216: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11217: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11218: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11219: ($domdefaults{'auth_def'} eq 'localauth'))) {
11220: $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.').' '.
11221: &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.');
11222: }
11223: }
11224: my @fields = ('lastname','firstname','middlename','generation',
11225: 'permanentemail','id');
1.240 raeburn 11226: my @shibfields = (@fields,'inststatus');
1.224 raeburn 11227: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11228: #
11229: # Where usernames may created for institutional log-in and/or institutional single sign on:
11230: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11231: # may self-create accounts
11232: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11233: # which the user may supply, if institutional data is unavailable.
11234: #
11235: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11236: if (ref($types) eq 'ARRAY') {
1.228 raeburn 11237: if (@{$types} > 1) {
1.224 raeburn 11238: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11239: push(@contexts,'statustocreate');
11240: } else {
11241: undef($cancreate{'statustocreate'});
11242: }
11243: foreach my $type (@{$types}) {
11244: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11245: foreach my $field (@fields) {
11246: if (grep(/^\Q$field\E$/,@modifiable)) {
11247: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11248: } else {
11249: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11250: }
11251: }
11252: }
11253: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11254: foreach my $type (@{$types}) {
11255: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11256: foreach my $field (@fields) {
11257: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11258: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11259: push(@{$changes{'selfcreate'}},$type);
11260: last;
11261: }
11262: }
11263: }
11264: }
11265: } else {
11266: foreach my $type (@{$types}) {
11267: push(@{$changes{'selfcreate'}},$type);
11268: }
11269: }
11270: }
1.240 raeburn 11271: foreach my $field (@shibfields) {
11272: if ($env{'form.shibenv_'.$field} ne '') {
11273: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11274: }
11275: }
11276: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11277: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11278: foreach my $field (@shibfields) {
11279: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11280: push(@{$changes{'cancreate'}},'shibenv');
11281: }
11282: }
11283: } else {
11284: foreach my $field (@shibfields) {
11285: if ($env{'form.shibenv_'.$field}) {
11286: push(@{$changes{'cancreate'}},'shibenv');
11287: last;
11288: }
11289: }
11290: }
11291: }
1.224 raeburn 11292: }
11293: foreach my $item (@contexts) {
11294: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11295: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11296: if (ref($cancreate{$item}) eq 'ARRAY') {
11297: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11298: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11299: push(@{$changes{'cancreate'}},$item);
11300: }
11301: }
11302: }
11303: }
11304: if (ref($cancreate{$item}) eq 'ARRAY') {
11305: foreach my $type (@{$cancreate{$item}}) {
11306: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11307: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11308: push(@{$changes{'cancreate'}},$item);
11309: }
11310: }
11311: }
11312: }
11313: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11314: if (ref($cancreate{$item}) eq 'HASH') {
11315: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 11316: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11317: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11318: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11319: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11320: push(@{$changes{'cancreate'}},$item);
11321: }
11322: }
11323: }
1.236 raeburn 11324: } elsif ($item eq 'selfcreateprocessing') {
11325: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11326: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11327: push(@{$changes{'cancreate'}},$item);
11328: }
11329: }
1.228 raeburn 11330: } else {
11331: if (!$cancreate{$item}{$curr}) {
11332: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11333: push(@{$changes{'cancreate'}},$item);
11334: }
1.224 raeburn 11335: }
11336: }
11337: }
11338: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 11339: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11340: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11341: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11342: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11343: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11344: push(@{$changes{'cancreate'}},$item);
11345: }
11346: }
11347: } else {
11348: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11349: push(@{$changes{'cancreate'}},$item);
11350: }
11351: }
11352: }
1.236 raeburn 11353: } elsif ($item eq 'selfcreateprocessing') {
11354: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11355: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11356: push(@{$changes{'cancreate'}},$item);
11357: }
11358: }
1.228 raeburn 11359: } else {
11360: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11361: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11362: push(@{$changes{'cancreate'}},$item);
11363: }
1.224 raeburn 11364: }
11365: }
11366: }
11367: }
11368: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11369: if (ref($cancreate{$item}) eq 'ARRAY') {
11370: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11371: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11372: push(@{$changes{'cancreate'}},$item);
11373: }
11374: }
11375: } elsif (ref($cancreate{$item}) eq 'HASH') {
11376: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11377: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11378: push(@{$changes{'cancreate'}},$item);
11379: }
11380: }
11381: }
11382: } elsif ($item eq 'emailusername') {
1.228 raeburn 11383: if (ref($cancreate{$item}) eq 'HASH') {
11384: foreach my $type (keys(%{$cancreate{$item}})) {
11385: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11386: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11387: if ($cancreate{$item}{$type}{$field}) {
11388: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11389: push(@{$changes{'cancreate'}},$item);
11390: }
11391: last;
11392: }
11393: }
11394: }
11395: }
1.224 raeburn 11396: }
11397: }
11398: }
11399: #
11400: # Populate %save_usercreate hash with updates to self-creation configuration.
11401: #
11402: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11403: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 11404: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 11405: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11406: if (ref($cancreate{'notify'}) eq 'HASH') {
11407: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11408: }
1.236 raeburn 11409: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11410: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11411: }
1.224 raeburn 11412: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11413: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11414: }
1.240 raeburn 11415: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11416: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11417: }
1.224 raeburn 11418: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
11419: $save_usercreate{'emailrule'} = \@email_rule;
11420:
11421: my %userconfig_hash = (
11422: usercreation => \%save_usercreate,
11423: usermodification => \%save_usermodify,
11424: );
11425: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11426: $dom);
11427: #
11428: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11429: #
1.27 raeburn 11430: if ($putresult eq 'ok') {
11431: if (keys(%changes) > 0) {
11432: $resulttext = &mt('Changes made:').'<ul>';
11433: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 11434: my %lt = &selfcreation_types();
1.34 raeburn 11435: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 11436: my $chgtext;
1.45 raeburn 11437: if ($type eq 'selfcreate') {
1.50 raeburn 11438: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 11439: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11440: } else {
1.224 raeburn 11441: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11442: '<ul>';
1.50 raeburn 11443: foreach my $case (@{$cancreate{$type}}) {
11444: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11445: }
11446: $chgtext .= '</ul>';
1.100 raeburn 11447: if (ref($cancreate{$type}) eq 'ARRAY') {
11448: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11449: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11450: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 11451: $chgtext .= '<br />'.
11452: '<span class="LC_warning">'.
11453: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11454: '</span>';
1.100 raeburn 11455: }
11456: }
11457: }
11458: }
1.43 raeburn 11459: }
1.240 raeburn 11460: } elsif ($type eq 'shibenv') {
11461: if (keys(%{$cancreate{$type}}) == 0) {
11462: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
11463: } else {
11464: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11465: '<ul>';
11466: foreach my $field (@shibfields) {
11467: next if ($cancreate{$type}{$field} eq '');
11468: if ($field eq 'inststatus') {
11469: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11470: } else {
11471: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11472: }
11473: }
11474: $chgtext .= '</ul>';
11475: }
1.93 raeburn 11476: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11477: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11478: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11479: if (@{$cancreate{'selfcreate'}} > 0) {
11480: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11481: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11482: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11483: $chgtext .= '<br />'.
11484: '<span class="LC_warning">'.
11485: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11486: '</span>';
11487: }
1.96 raeburn 11488: } elsif (ref($usertypes) eq 'HASH') {
11489: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11490: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11491: } else {
11492: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11493: }
11494: $chgtext .= '<ul>';
11495: foreach my $case (@{$cancreate{$type}}) {
11496: if ($case eq 'default') {
11497: $chgtext .= '<li>'.$othertitle.'</li>';
11498: } else {
11499: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 11500: }
11501: }
1.100 raeburn 11502: $chgtext .= '</ul>';
11503: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11504: $chgtext .= '<br /><span class="LC_warning">'.
11505: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11506: '</span>';
1.100 raeburn 11507: }
11508: }
11509: } else {
11510: if (@{$cancreate{$type}} == 0) {
11511: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11512: } else {
11513: $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 11514: }
11515: }
11516: }
1.236 raeburn 11517: } elsif ($type eq 'selfcreateprocessing') {
11518: my %choices = &Apache::lonlocal::texthash (
11519: automatic => 'Automatic approval',
11520: approval => 'Queued for approval',
11521: );
11522: if (@statuses > 1) {
11523: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
11524: '<ul>';
11525: foreach my $type (@statuses) {
11526: if ($type eq 'default') {
11527: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11528: } else {
11529: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11530: }
11531: }
11532: $chgtext .= '</ul>';
11533: } else {
11534: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
11535: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11536: }
1.165 raeburn 11537: } elsif ($type eq 'captcha') {
1.224 raeburn 11538: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 11539: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11540: } else {
11541: my %captchas = &captcha_phrases();
1.224 raeburn 11542: if ($captchas{$savecaptcha{$type}}) {
11543: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 11544: } else {
1.210 raeburn 11545: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 11546: }
11547: }
11548: } elsif ($type eq 'recaptchakeys') {
11549: my ($privkey,$pubkey);
1.224 raeburn 11550: if (ref($savecaptcha{$type}) eq 'HASH') {
11551: $pubkey = $savecaptcha{$type}{'public'};
11552: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 11553: }
11554: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11555: if (!$pubkey) {
11556: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11557: } else {
11558: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11559: }
11560: if (!$privkey) {
11561: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11562: } else {
11563: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11564: }
11565: $chgtext .= '</ul>';
1.269 raeburn 11566: } elsif ($type eq 'recaptchaversion') {
11567: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 11568: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 11569: }
1.224 raeburn 11570: } elsif ($type eq 'emailusername') {
11571: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 11572: if (ref($types) eq 'ARRAY') {
11573: foreach my $type (@{$types}) {
11574: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11575: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 11576: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 11577: '<ul>';
11578: foreach my $field (@{$infofields}) {
11579: if ($cancreate{'emailusername'}{$type}{$field}) {
11580: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11581: }
11582: }
1.245 raeburn 11583: $chgtext .= '</ul>';
11584: } else {
11585: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.228 raeburn 11586: }
11587: } else {
1.245 raeburn 11588: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.224 raeburn 11589: }
11590: }
11591: }
11592: }
11593: } elsif ($type eq 'notify') {
11594: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11595: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11596: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11597: if ($cancreate{'notify'}{'approval'}) {
11598: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11599: }
11600: }
1.43 raeburn 11601: }
1.34 raeburn 11602: }
1.224 raeburn 11603: if ($chgtext) {
11604: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11605: }
11606: }
11607: }
1.43 raeburn 11608: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11609: my ($emailrules,$emailruleorder) =
11610: &Apache::lonnet::inst_userrules($dom,'email');
11611: my $chgtext = '<ul>';
11612: foreach my $type (@email_rule) {
11613: if (ref($emailrules->{$type}) eq 'HASH') {
11614: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11615: }
11616: }
11617: $chgtext .= '</ul>';
11618: if (@email_rule > 0) {
1.224 raeburn 11619: $resulttext .= '<li>'.
11620: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
11621: $chgtext.
11622: '</li>';
1.43 raeburn 11623: } else {
1.224 raeburn 11624: $resulttext .= '<li>'.
11625: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
11626: '</li>';
1.43 raeburn 11627: }
11628: }
1.224 raeburn 11629: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11630: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11631: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11632: foreach my $type (@{$changes{'selfcreate'}}) {
11633: my $typename = $type;
11634: if (ref($usertypes) eq 'HASH') {
11635: if ($usertypes->{$type} ne '') {
11636: $typename = $usertypes->{$type};
11637: }
11638: }
11639: my @modifiable;
11640: $resulttext .= '<li>'.
11641: &mt('Self-creation of account by users with status: [_1]',
11642: '<span class="LC_cusr_emph">'.$typename.'</span>').
11643: ' - '.&mt('modifiable fields (if institutional data blank): ');
11644: foreach my $field (@fields) {
11645: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11646: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 11647: }
11648: }
1.224 raeburn 11649: if (@modifiable > 0) {
11650: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11651: } else {
1.224 raeburn 11652: $resulttext .= &mt('none');
1.43 raeburn 11653: }
1.224 raeburn 11654: $resulttext .= '</li>';
1.28 raeburn 11655: }
1.224 raeburn 11656: $resulttext .= '</ul></li>';
1.28 raeburn 11657: }
1.27 raeburn 11658: $resulttext .= '</ul>';
11659: } else {
1.224 raeburn 11660: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11661: }
11662: } else {
11663: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11664: &mt('An error occurred: [_1]',$putresult).'</span>';
11665: }
1.43 raeburn 11666: if ($warningmsg ne '') {
11667: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11668: }
1.23 raeburn 11669: return $resulttext;
11670: }
11671:
1.165 raeburn 11672: sub process_captcha {
11673: my ($container,$changes,$newsettings,$current) = @_;
11674: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11675: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11676: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11677: $newsettings->{'captcha'} = 'original';
11678: }
11679: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 11680: if ($container eq 'cancreate') {
1.169 raeburn 11681: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11682: push(@{$changes->{'cancreate'}},'captcha');
11683: } elsif (!defined($changes->{'cancreate'})) {
11684: $changes->{'cancreate'} = ['captcha'];
11685: }
11686: } else {
11687: $changes->{'captcha'} = 1;
1.165 raeburn 11688: }
11689: }
1.269 raeburn 11690: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 11691: if ($newsettings->{'captcha'} eq 'recaptcha') {
11692: $newpub = $env{'form.'.$container.'_recaptchapub'};
11693: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 11694: $newpub =~ s/[^\w\-]//g;
11695: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 11696: $newsettings->{'recaptchakeys'} = {
11697: public => $newpub,
11698: private => $newpriv,
11699: };
1.269 raeburn 11700: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11701: $newversion =~ s/\D//g;
11702: if ($newversion ne '2') {
11703: $newversion = 1;
11704: }
11705: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 11706: }
11707: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11708: $currpub = $current->{'recaptchakeys'}{'public'};
11709: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 11710: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11711: $newsettings->{'recaptchakeys'} = {
11712: public => '',
11713: private => '',
11714: }
11715: }
1.165 raeburn 11716: }
1.269 raeburn 11717: if ($current->{'captcha'} eq 'recaptcha') {
11718: $currversion = $current->{'recaptchaversion'};
11719: if ($currversion ne '2') {
11720: $currversion = 1;
11721: }
11722: }
11723: if ($currversion ne $newversion) {
11724: if ($container eq 'cancreate') {
11725: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11726: push(@{$changes->{'cancreate'}},'recaptchaversion');
11727: } elsif (!defined($changes->{'cancreate'})) {
11728: $changes->{'cancreate'} = ['recaptchaversion'];
11729: }
11730: } else {
11731: $changes->{'recaptchaversion'} = 1;
11732: }
11733: }
1.165 raeburn 11734: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 11735: if ($container eq 'cancreate') {
11736: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11737: push(@{$changes->{'cancreate'}},'recaptchakeys');
11738: } elsif (!defined($changes->{'cancreate'})) {
11739: $changes->{'cancreate'} = ['recaptchakeys'];
11740: }
11741: } else {
1.210 raeburn 11742: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 11743: }
11744: }
11745: return;
11746: }
11747:
1.33 raeburn 11748: sub modify_usermodification {
11749: my ($dom,%domconfig) = @_;
1.224 raeburn 11750: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11751: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11752: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 11753: if ($key eq 'selfcreate') {
11754: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11755: } else {
11756: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11757: }
1.33 raeburn 11758: }
11759: }
1.224 raeburn 11760: my @contexts = ('author','course');
1.33 raeburn 11761: my %context_title = (
11762: author => 'In author context',
11763: course => 'In course context',
11764: );
11765: my @fields = ('lastname','firstname','middlename','generation',
11766: 'permanentemail','id');
11767: my %roles = (
11768: author => ['ca','aa'],
11769: course => ['st','ep','ta','in','cr'],
11770: );
11771: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11772: foreach my $context (@contexts) {
11773: foreach my $role (@{$roles{$context}}) {
11774: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11775: foreach my $item (@fields) {
11776: if (grep(/^\Q$item\E$/,@modifiable)) {
11777: $modifyhash{$context}{$role}{$item} = 1;
11778: } else {
11779: $modifyhash{$context}{$role}{$item} = 0;
11780: }
11781: }
11782: }
11783: if (ref($curr_usermodification{$context}) eq 'HASH') {
11784: foreach my $role (@{$roles{$context}}) {
11785: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11786: foreach my $field (@fields) {
11787: if ($modifyhash{$context}{$role}{$field} ne
11788: $curr_usermodification{$context}{$role}{$field}) {
11789: push(@{$changes{$context}},$role);
11790: last;
11791: }
11792: }
11793: }
11794: }
11795: } else {
11796: foreach my $context (@contexts) {
11797: foreach my $role (@{$roles{$context}}) {
11798: push(@{$changes{$context}},$role);
11799: }
11800: }
11801: }
11802: }
11803: my %usermodification_hash = (
11804: usermodification => \%modifyhash,
11805: );
11806: my $putresult = &Apache::lonnet::put_dom('configuration',
11807: \%usermodification_hash,$dom);
11808: if ($putresult eq 'ok') {
11809: if (keys(%changes) > 0) {
11810: $resulttext = &mt('Changes made: ').'<ul>';
11811: foreach my $context (@contexts) {
11812: if (ref($changes{$context}) eq 'ARRAY') {
11813: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11814: if (ref($changes{$context}) eq 'ARRAY') {
11815: foreach my $role (@{$changes{$context}}) {
11816: my $rolename;
1.224 raeburn 11817: if ($role eq 'cr') {
11818: $rolename = &mt('Custom');
1.33 raeburn 11819: } else {
1.224 raeburn 11820: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11821: }
11822: my @modifiable;
1.224 raeburn 11823: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11824: foreach my $field (@fields) {
11825: if ($modifyhash{$context}{$role}{$field}) {
11826: push(@modifiable,$fieldtitles{$field});
11827: }
11828: }
11829: if (@modifiable > 0) {
11830: $resulttext .= join(', ',@modifiable);
11831: } else {
11832: $resulttext .= &mt('none');
11833: }
11834: $resulttext .= '</li>';
11835: }
11836: $resulttext .= '</ul></li>';
11837: }
11838: }
11839: }
11840: $resulttext .= '</ul>';
11841: } else {
11842: $resulttext = &mt('No changes made to user modification settings');
11843: }
11844: } else {
11845: $resulttext = '<span class="LC_error">'.
11846: &mt('An error occurred: [_1]',$putresult).'</span>';
11847: }
11848: return $resulttext;
11849: }
11850:
1.43 raeburn 11851: sub modify_defaults {
1.212 raeburn 11852: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11853: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 11854: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 ! raeburn 11855: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
! 11856: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 11857: my @authtypes = ('internal','krb4','krb5','localauth');
11858: foreach my $item (@items) {
11859: $newvalues{$item} = $env{'form.'.$item};
11860: if ($item eq 'auth_def') {
11861: if ($newvalues{$item} ne '') {
11862: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11863: push(@errors,$item);
11864: }
11865: }
11866: } elsif ($item eq 'lang_def') {
11867: if ($newvalues{$item} ne '') {
11868: if ($newvalues{$item} =~ /^(\w+)/) {
11869: my $langcode = $1;
1.103 raeburn 11870: if ($langcode ne 'x_chef') {
11871: if (code2language($langcode) eq '') {
11872: push(@errors,$item);
11873: }
1.43 raeburn 11874: }
11875: } else {
11876: push(@errors,$item);
11877: }
11878: }
1.54 raeburn 11879: } elsif ($item eq 'timezone_def') {
11880: if ($newvalues{$item} ne '') {
1.62 raeburn 11881: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11882: push(@errors,$item);
11883: }
11884: }
1.68 raeburn 11885: } elsif ($item eq 'datelocale_def') {
11886: if ($newvalues{$item} ne '') {
11887: my @datelocale_ids = DateTime::Locale->ids();
11888: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11889: push(@errors,$item);
11890: }
11891: }
1.141 raeburn 11892: } elsif ($item eq 'portal_def') {
11893: if ($newvalues{$item} ne '') {
11894: 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])\/?$/) {
11895: push(@errors,$item);
11896: }
11897: }
1.294 ! raeburn 11898: } elsif ($item eq 'intauth_cost') {
! 11899: if ($newvalues{$item} ne '') {
! 11900: if ($newvalues{$item} =~ /\D/) {
! 11901: push(@errors,$item);
! 11902: }
! 11903: }
! 11904: } elsif ($item eq 'intauth_check') {
! 11905: if ($newvalues{$item} ne '') {
! 11906: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
! 11907: push(@errors,$item);
! 11908: }
! 11909: }
! 11910: } elsif ($item eq 'intauth_switch') {
! 11911: if ($newvalues{$item} ne '') {
! 11912: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
! 11913: push(@errors,$item);
! 11914: }
! 11915: }
1.43 raeburn 11916: }
11917: if (grep(/^\Q$item\E$/,@errors)) {
11918: $newvalues{$item} = $domdefaults{$item};
11919: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
11920: $changes{$item} = 1;
11921: }
1.72 raeburn 11922: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 11923: }
11924: my %defaults_hash = (
1.72 raeburn 11925: defaults => \%newvalues,
11926: );
1.43 raeburn 11927: my $title = &defaults_titles();
1.236 raeburn 11928:
11929: my $currinststatus;
11930: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11931: $currinststatus = $domconfig{'inststatus'};
11932: } else {
11933: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11934: $currinststatus = {
11935: inststatustypes => $usertypes,
11936: inststatusorder => $types,
11937: inststatusguest => [],
11938: };
11939: }
11940: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
11941: my @allpos;
11942: my %guests;
11943: my %alltypes;
11944: my ($currtitles,$currguests,$currorder);
11945: if (ref($currinststatus) eq 'HASH') {
11946: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
11947: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
11948: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
11949: if ($currinststatus->{inststatustypes}->{$type} ne '') {
11950: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
11951: }
11952: }
11953: unless (grep(/^\Q$type\E$/,@todelete)) {
11954: my $position = $env{'form.inststatus_pos_'.$type};
11955: $position =~ s/\D+//g;
11956: $allpos[$position] = $type;
11957: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
11958: $alltypes{$type} =~ s/`//g;
11959: if ($env{'form.inststatus_guest_'.$type}) {
11960: $guests{$type} = 1;
11961: }
11962: }
11963: }
11964: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11965: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
11966: }
11967: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11968: $currtitles =~ s/,$//;
11969: }
11970: }
11971: if ($env{'form.addinststatus'}) {
11972: my $newtype = $env{'form.addinststatus'};
11973: $newtype =~ s/\W//g;
11974: unless (exists($alltypes{$newtype})) {
11975: if ($env{'form.addinststatus_guest'}) {
11976: $guests{$newtype} = 1;
11977: }
11978: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11979: $alltypes{$newtype} =~ s/`//g;
11980: my $position = $env{'form.addinststatus_pos'};
11981: $position =~ s/\D+//g;
11982: if ($position ne '') {
11983: $allpos[$position] = $newtype;
11984: }
11985: }
11986: }
11987: my (@orderedstatus,@orderedguests);
11988: foreach my $type (@allpos) {
11989: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11990: push(@orderedstatus,$type);
11991: if ($guests{$type}) {
11992: push(@orderedguests,$type);
11993: }
11994: }
11995: }
11996: foreach my $type (keys(%alltypes)) {
11997: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
11998: delete($alltypes{$type});
11999: }
12000: }
12001: $defaults_hash{'inststatus'} = {
12002: inststatustypes => \%alltypes,
12003: inststatusorder => \@orderedstatus,
12004: inststatusguest => \@orderedguests,
12005: };
12006: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12007: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12008: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12009: }
12010: }
12011: if ($currorder ne join(',',@orderedstatus)) {
12012: $changes{'inststatus'}{'inststatusorder'} = 1;
12013: }
12014: if ($currguests ne join(',',@orderedguests)) {
12015: $changes{'inststatus'}{'inststatusguest'} = 1;
12016: }
12017: my $newtitles;
12018: foreach my $item (@orderedstatus) {
12019: $newtitles .= $alltypes{$item}.',';
12020: }
12021: $newtitles =~ s/,$//;
12022: if ($currtitles ne $newtitles) {
12023: $changes{'inststatus'}{'inststatustypes'} = 1;
12024: }
1.43 raeburn 12025: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12026: $dom);
12027: if ($putresult eq 'ok') {
12028: if (keys(%changes) > 0) {
12029: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 12030: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12031: 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";
12032: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 12033: if ($item eq 'inststatus') {
12034: if (ref($changes{'inststatus'}) eq 'HASH') {
12035: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
12036: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12037: foreach my $type (@orderedstatus) {
12038: $resulttext .= $alltypes{$type}.', ';
12039: }
12040: $resulttext =~ s/, $//;
12041: $resulttext .= '</li>';
12042: }
12043: if ($changes{'inststatus'}{'inststatusguest'}) {
12044: $resulttext .= '<li>';
12045: if (@orderedguests) {
12046: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
12047: foreach my $type (@orderedguests) {
12048: $resulttext .= $alltypes{$type}.', ';
12049: }
12050: $resulttext =~ s/, $//;
12051: } else {
12052: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
12053: }
12054: $resulttext .= '</li>';
12055: }
12056: }
12057: } else {
12058: my $value = $env{'form.'.$item};
12059: if ($value eq '') {
12060: $value = &mt('none');
12061: } elsif ($item eq 'auth_def') {
12062: my %authnames = &authtype_names();
12063: my %shortauth = (
12064: internal => 'int',
12065: krb4 => 'krb4',
12066: krb5 => 'krb5',
12067: localauth => 'loc',
12068: );
12069: $value = $authnames{$shortauth{$value}};
1.294 ! raeburn 12070: } elsif ($item eq 'intauth_switch') {
! 12071: my %optiondesc = &Apache::lonlocal::texthash (
! 12072: 0 => 'No',
! 12073: 1 => 'Yes',
! 12074: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
! 12075: );
! 12076: if ($value =~ /^(0|1|2)$/) {
! 12077: $value = $optiondesc{$value};
! 12078: } else {
! 12079: $value = &mt('none -- defaults to No');
! 12080: }
! 12081: } elsif ($item eq 'intauth_check') {
! 12082: my %optiondesc = &Apache::lonlocal::texthash (
! 12083: 0 => 'No',
! 12084: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
! 12085: 2 => 'Yes, disallow login if stored cost is less than domain default',
! 12086: );
! 12087: if ($value =~ /^(0|1|2)$/) {
! 12088: $value = $optiondesc{$value};
! 12089: } else {
! 12090: $value = &mt('none -- defaults to No');
! 12091: }
1.236 raeburn 12092: }
12093: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12094: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12095: }
12096: }
12097: $resulttext .= '</ul>';
12098: $mailmsgtext .= "\n";
12099: my $cachetime = 24*60*60;
1.72 raeburn 12100: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12101: if (ref($lastactref) eq 'HASH') {
12102: $lastactref->{'domdefaults'} = 1;
12103: }
1.68 raeburn 12104: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 12105: my $notify = 1;
12106: if (ref($domconfig{'contacts'}) eq 'HASH') {
12107: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12108: $notify = 0;
12109: }
12110: }
12111: if ($notify) {
12112: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12113: "LON-CAPA Domain Settings Change - $dom",
12114: $mailmsgtext);
12115: }
1.54 raeburn 12116: }
1.43 raeburn 12117: } else {
1.54 raeburn 12118: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12119: }
12120: } else {
12121: $resulttext = '<span class="LC_error">'.
12122: &mt('An error occurred: [_1]',$putresult).'</span>';
12123: }
12124: if (@errors > 0) {
12125: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12126: foreach my $item (@errors) {
12127: $resulttext .= ' "'.$title->{$item}.'",';
12128: }
12129: $resulttext =~ s/,$//;
12130: }
12131: return $resulttext;
12132: }
12133:
1.46 raeburn 12134: sub modify_scantron {
1.205 raeburn 12135: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12136: my ($resulttext,%confhash,%changes,$errors);
12137: my $custom = 'custom.tab';
12138: my $default = 'default.tab';
12139: my $servadm = $r->dir_config('lonAdmEMail');
12140: my ($configuserok,$author_ok,$switchserver) =
12141: &config_check($dom,$confname,$servadm);
12142: if ($env{'form.scantronformat.filename'} ne '') {
12143: my $error;
12144: if ($configuserok eq 'ok') {
12145: if ($switchserver) {
1.130 raeburn 12146: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12147: } else {
12148: if ($author_ok eq 'ok') {
12149: my ($result,$scantronurl) =
12150: &publishlogo($r,'upload','scantronformat',$dom,
12151: $confname,'scantron','','',$custom);
12152: if ($result eq 'ok') {
12153: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12154: $changes{'scantronformat'} = 1;
1.46 raeburn 12155: } else {
12156: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12157: }
12158: } else {
12159: $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);
12160: }
12161: }
12162: } else {
12163: $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);
12164: }
12165: if ($error) {
12166: &Apache::lonnet::logthis($error);
12167: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12168: }
12169: }
1.48 raeburn 12170: if (ref($domconfig{'scantron'}) eq 'HASH') {
12171: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12172: if ($env{'form.scantronformat_del'}) {
12173: $confhash{'scantron'}{'scantronformat'} = '';
12174: $changes{'scantronformat'} = 1;
1.46 raeburn 12175: }
12176: }
12177: }
12178: if (keys(%confhash) > 0) {
12179: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12180: $dom);
12181: if ($putresult eq 'ok') {
12182: if (keys(%changes) > 0) {
1.48 raeburn 12183: if (ref($confhash{'scantron'}) eq 'HASH') {
12184: $resulttext = &mt('Changes made:').'<ul>';
12185: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 12186: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 12187: } else {
1.130 raeburn 12188: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 12189: }
1.48 raeburn 12190: $resulttext .= '</ul>';
12191: } else {
1.130 raeburn 12192: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12193: }
12194: $resulttext .= '</ul>';
12195: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12196: if (ref($lastactref) eq 'HASH') {
12197: $lastactref->{'domainconfig'} = 1;
12198: }
1.46 raeburn 12199: } else {
1.130 raeburn 12200: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12201: }
12202: } else {
12203: $resulttext = '<span class="LC_error">'.
12204: &mt('An error occurred: [_1]',$putresult).'</span>';
12205: }
12206: } else {
1.130 raeburn 12207: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12208: }
12209: if ($errors) {
12210: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12211: $errors.'</ul>';
12212: }
12213: return $resulttext;
12214: }
12215:
1.48 raeburn 12216: sub modify_coursecategories {
1.239 raeburn 12217: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12218: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12219: $cathash);
1.48 raeburn 12220: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 12221: my @catitems = ('unauth','auth');
12222: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12223: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12224: $cathash = $domconfig{'coursecategories'}{'cats'};
12225: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12226: $changes{'togglecats'} = 1;
12227: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12228: }
12229: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12230: $changes{'categorize'} = 1;
12231: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12232: }
1.120 raeburn 12233: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12234: $changes{'togglecatscomm'} = 1;
12235: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12236: }
12237: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12238: $changes{'categorizecomm'} = 1;
12239: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 12240:
12241: }
12242: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
12243: $changes{'togglecatsplace'} = 1;
12244: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
12245: }
12246: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
12247: $changes{'categorizeplace'} = 1;
12248: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 12249: }
1.238 raeburn 12250: foreach my $item (@catitems) {
12251: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12252: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12253: $changes{$item} = 1;
12254: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12255: }
12256: }
12257: }
1.57 raeburn 12258: } else {
12259: $changes{'togglecats'} = 1;
12260: $changes{'categorize'} = 1;
1.124 raeburn 12261: $changes{'togglecatscomm'} = 1;
12262: $changes{'categorizecomm'} = 1;
1.272 raeburn 12263: $changes{'togglecatsplace'} = 1;
12264: $changes{'categorizeplace'} = 1;
1.87 raeburn 12265: $domconfig{'coursecategories'} = {
12266: togglecats => $env{'form.togglecats'},
12267: categorize => $env{'form.categorize'},
1.124 raeburn 12268: togglecatscomm => $env{'form.togglecatscomm'},
12269: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 12270: togglecatsplace => $env{'form.togglecatsplace'},
12271: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 12272: };
1.238 raeburn 12273: foreach my $item (@catitems) {
12274: if ($env{'form.coursecat_'.$item} ne 'std') {
12275: $changes{$item} = 1;
12276: }
12277: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12278: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12279: }
12280: }
1.57 raeburn 12281: }
12282: if (ref($cathash) eq 'HASH') {
12283: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12284: push (@deletecategory,'instcode::0');
12285: }
1.120 raeburn 12286: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12287: push(@deletecategory,'communities::0');
12288: }
1.272 raeburn 12289: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
12290: push(@deletecategory,'placement::0');
12291: }
1.48 raeburn 12292: }
1.57 raeburn 12293: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12294: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12295: if (@deletecategory > 0) {
12296: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12297: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12298: foreach my $item (@deletecategory) {
1.57 raeburn 12299: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12300: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12301: $deletions{$item} = 1;
1.57 raeburn 12302: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12303: }
12304: }
12305: }
1.57 raeburn 12306: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12307: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12308: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12309: $reorderings{$item} = 1;
1.57 raeburn 12310: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12311: }
12312: if ($env{'form.addcategory_name_'.$item} ne '') {
12313: my $newcat = $env{'form.addcategory_name_'.$item};
12314: my $newdepth = $depth+1;
12315: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12316: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12317: $adds{$newitem} = 1;
12318: }
12319: if ($env{'form.subcat_'.$item} ne '') {
12320: my $newcat = $env{'form.subcat_'.$item};
12321: my $newdepth = $depth+1;
12322: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12323: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12324: $adds{$newitem} = 1;
12325: }
12326: }
12327: }
12328: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12329: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12330: my $newitem = 'instcode::0';
1.57 raeburn 12331: if ($cathash->{$newitem} eq '') {
12332: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12333: $adds{$newitem} = 1;
12334: }
12335: } else {
12336: my $newitem = 'instcode::0';
1.57 raeburn 12337: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12338: $adds{$newitem} = 1;
12339: }
12340: }
1.120 raeburn 12341: if ($env{'form.communities'} eq '1') {
12342: if (ref($cathash) eq 'HASH') {
12343: my $newitem = 'communities::0';
12344: if ($cathash->{$newitem} eq '') {
12345: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12346: $adds{$newitem} = 1;
12347: }
12348: } else {
12349: my $newitem = 'communities::0';
12350: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12351: $adds{$newitem} = 1;
12352: }
12353: }
1.272 raeburn 12354: if ($env{'form.placement'} eq '1') {
12355: if (ref($cathash) eq 'HASH') {
12356: my $newitem = 'placement::0';
12357: if ($cathash->{$newitem} eq '') {
12358: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12359: $adds{$newitem} = 1;
12360: }
12361: } else {
12362: my $newitem = 'placement::0';
12363: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12364: $adds{$newitem} = 1;
12365: }
12366: }
1.48 raeburn 12367: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12368: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 12369: ($env{'form.addcategory_name'} ne 'communities') &&
12370: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 12371: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12372: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12373: $adds{$newitem} = 1;
12374: }
1.48 raeburn 12375: }
1.57 raeburn 12376: my $putresult;
1.48 raeburn 12377: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12378: if (keys(%deletions) > 0) {
12379: foreach my $key (keys(%deletions)) {
12380: if ($predelallitems{$key} ne '') {
12381: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12382: }
12383: }
12384: }
12385: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12386: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12387: if (ref($chkcats[0]) eq 'ARRAY') {
12388: my $depth = 0;
12389: my $chg = 0;
12390: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12391: my $name = $chkcats[0][$i];
12392: my $item;
12393: if ($name eq '') {
12394: $chg ++;
12395: } else {
12396: $item = &escape($name).'::0';
12397: if ($chg) {
1.57 raeburn 12398: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12399: }
12400: $depth ++;
1.57 raeburn 12401: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12402: $depth --;
12403: }
12404: }
12405: }
1.57 raeburn 12406: }
12407: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12408: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12409: if ($putresult eq 'ok') {
1.57 raeburn 12410: my %title = (
1.120 raeburn 12411: togglecats => 'Show/Hide a course in catalog',
12412: categorize => 'Assign a category to a course',
12413: togglecatscomm => 'Show/Hide a community in catalog',
12414: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12415: );
12416: my %level = (
1.120 raeburn 12417: dom => 'set in Domain ("Modify Course/Community")',
12418: crs => 'set in Course ("Course Configuration")',
12419: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 12420: none => 'No catalog',
12421: std => 'Standard catalog',
12422: domonly => 'Domain-only catalog',
12423: codesrch => 'Code search form',
1.57 raeburn 12424: );
1.48 raeburn 12425: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12426: if ($changes{'togglecats'}) {
12427: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12428: }
12429: if ($changes{'categorize'}) {
12430: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12431: }
1.120 raeburn 12432: if ($changes{'togglecatscomm'}) {
12433: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12434: }
12435: if ($changes{'categorizecomm'}) {
12436: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12437: }
1.238 raeburn 12438: if ($changes{'unauth'}) {
12439: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12440: }
12441: if ($changes{'auth'}) {
12442: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12443: }
1.57 raeburn 12444: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12445: my $cathash;
12446: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12447: $cathash = $domconfig{'coursecategories'}{'cats'};
12448: } else {
12449: $cathash = {};
12450: }
12451: my (@cats,@trails,%allitems);
12452: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12453: if (keys(%deletions) > 0) {
12454: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12455: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12456: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12457: }
12458: $resulttext .= '</ul></li>';
12459: }
12460: if (keys(%reorderings) > 0) {
12461: my %sort_by_trail;
12462: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12463: foreach my $key (keys(%reorderings)) {
12464: if ($allitems{$key} ne '') {
12465: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12466: }
1.48 raeburn 12467: }
1.57 raeburn 12468: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12469: $resulttext .= '<li>'.$trails[$trail].'</li>';
12470: }
12471: $resulttext .= '</ul></li>';
1.48 raeburn 12472: }
1.57 raeburn 12473: if (keys(%adds) > 0) {
12474: my %sort_by_trail;
12475: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12476: foreach my $key (keys(%adds)) {
12477: if ($allitems{$key} ne '') {
12478: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12479: }
12480: }
12481: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12482: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12483: }
1.57 raeburn 12484: $resulttext .= '</ul></li>';
1.48 raeburn 12485: }
12486: }
12487: $resulttext .= '</ul>';
1.239 raeburn 12488: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 12489: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12490: if ($changes{'auth'}) {
12491: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12492: }
12493: if ($changes{'unauth'}) {
12494: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12495: }
12496: my $cachetime = 24*60*60;
12497: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 12498: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 12499: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 12500: }
12501: }
1.48 raeburn 12502: } else {
12503: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12504: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12505: }
12506: } else {
1.120 raeburn 12507: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12508: }
12509: return $resulttext;
12510: }
12511:
1.69 raeburn 12512: sub modify_serverstatuses {
12513: my ($dom,%domconfig) = @_;
12514: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12515: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12516: %currserverstatus = %{$domconfig{'serverstatuses'}};
12517: }
12518: my @pages = &serverstatus_pages();
12519: foreach my $type (@pages) {
12520: $newserverstatus{$type}{'namedusers'} = '';
12521: $newserverstatus{$type}{'machines'} = '';
12522: if (defined($env{'form.'.$type.'_namedusers'})) {
12523: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12524: my @okusers;
12525: foreach my $user (@users) {
12526: my ($uname,$udom) = split(/:/,$user);
12527: if (($udom =~ /^$match_domain$/) &&
12528: (&Apache::lonnet::domain($udom)) &&
12529: ($uname =~ /^$match_username$/)) {
12530: if (!grep(/^\Q$user\E/,@okusers)) {
12531: push(@okusers,$user);
12532: }
12533: }
12534: }
12535: if (@okusers > 0) {
12536: @okusers = sort(@okusers);
12537: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12538: }
12539: }
12540: if (defined($env{'form.'.$type.'_machines'})) {
12541: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12542: my @okmachines;
12543: foreach my $ip (@machines) {
12544: my @parts = split(/\./,$ip);
12545: next if (@parts < 4);
12546: my $badip = 0;
12547: for (my $i=0; $i<4; $i++) {
12548: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12549: $badip = 1;
12550: last;
12551: }
12552: }
12553: if (!$badip) {
12554: push(@okmachines,$ip);
12555: }
12556: }
12557: @okmachines = sort(@okmachines);
12558: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12559: }
12560: }
12561: my %serverstatushash = (
12562: serverstatuses => \%newserverstatus,
12563: );
12564: foreach my $type (@pages) {
1.83 raeburn 12565: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12566: my (@current,@new);
1.83 raeburn 12567: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12568: if ($currserverstatus{$type}{$setting} ne '') {
12569: @current = split(/,/,$currserverstatus{$type}{$setting});
12570: }
12571: }
12572: if ($newserverstatus{$type}{$setting} ne '') {
12573: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12574: }
12575: if (@current > 0) {
12576: if (@new > 0) {
12577: foreach my $item (@current) {
12578: if (!grep(/^\Q$item\E$/,@new)) {
12579: $changes{$type}{$setting} = 1;
1.82 raeburn 12580: last;
12581: }
12582: }
1.84 raeburn 12583: foreach my $item (@new) {
12584: if (!grep(/^\Q$item\E$/,@current)) {
12585: $changes{$type}{$setting} = 1;
12586: last;
1.82 raeburn 12587: }
12588: }
12589: } else {
1.83 raeburn 12590: $changes{$type}{$setting} = 1;
1.69 raeburn 12591: }
1.83 raeburn 12592: } elsif (@new > 0) {
12593: $changes{$type}{$setting} = 1;
1.69 raeburn 12594: }
12595: }
12596: }
12597: if (keys(%changes) > 0) {
1.81 raeburn 12598: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12599: my $putresult = &Apache::lonnet::put_dom('configuration',
12600: \%serverstatushash,$dom);
12601: if ($putresult eq 'ok') {
12602: $resulttext .= &mt('Changes made:').'<ul>';
12603: foreach my $type (@pages) {
1.84 raeburn 12604: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12605: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12606: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12607: if ($newserverstatus{$type}{'namedusers'} eq '') {
12608: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12609: } else {
12610: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12611: }
1.84 raeburn 12612: }
12613: if ($changes{$type}{'machines'}) {
1.69 raeburn 12614: if ($newserverstatus{$type}{'machines'} eq '') {
12615: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12616: } else {
12617: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12618: }
12619:
12620: }
12621: $resulttext .= '</ul></li>';
12622: }
12623: }
12624: $resulttext .= '</ul>';
12625: } else {
12626: $resulttext = '<span class="LC_error">'.
12627: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12628:
12629: }
12630: } else {
12631: $resulttext = &mt('No changes made to access to server status pages');
12632: }
12633: return $resulttext;
12634: }
12635:
1.118 jms 12636: sub modify_helpsettings {
1.285 raeburn 12637: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 12638: my ($resulttext,$errors,%changes,%helphash);
12639: my %defaultchecked = ('submitbugs' => 'on');
12640: my @offon = ('off','on');
1.118 jms 12641: my @toggles = ('submitbugs');
1.285 raeburn 12642: my %current = ('submitbugs' => '',
12643: 'adhoc' => {},
12644: );
1.118 jms 12645: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 12646: %current = %{$domconfig{'helpsettings'}};
12647: }
1.285 raeburn 12648: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 12649: foreach my $item (@toggles) {
12650: if ($defaultchecked{$item} eq 'on') {
12651: if ($current{$item} eq '') {
12652: if ($env{'form.'.$item} eq '0') {
12653: $changes{$item} = 1;
12654: }
12655: } elsif ($current{$item} ne $env{'form.'.$item}) {
12656: $changes{$item} = 1;
12657: }
12658: } elsif ($defaultchecked{$item} eq 'off') {
12659: if ($current{$item} eq '') {
12660: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 12661: $changes{$item} = 1;
12662: }
1.282 raeburn 12663: } elsif ($current{$item} ne $env{'form.'.$item}) {
12664: $changes{$item} = 1;
12665: }
12666: }
12667: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
12668: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
12669: }
12670: }
1.285 raeburn 12671: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 12672: my $confname = $dom.'-domainconfig';
12673: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 12674: my (@allpos,%newsettings,%changedprivs,$newrole);
12675: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 12676: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 12677: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 12678: my %lt = &Apache::lonlocal::texthash(
12679: s => 'system',
12680: d => 'domain',
12681: order => 'Display order',
12682: access => 'Role usage',
1.291 raeburn 12683: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 12684: dh => 'All with domain helpdesk role',
12685: da => 'All with domain helpdesk assistant role',
1.285 raeburn 12686: none => 'None',
12687: status => 'Determined based on institutional status',
12688: inc => 'Include all, but exclude specific personnel',
12689: exc => 'Exclude all, but include specific personnel',
12690: );
12691: for (my $num=0; $num<=$maxnum; $num++) {
12692: my ($prefix,$identifier,$rolename,%curr);
12693: if ($num == $maxnum) {
12694: next unless ($env{'form.newcusthelp'} == $maxnum);
12695: $identifier = 'custhelp'.$num;
12696: $prefix = 'helproles_'.$num;
12697: $rolename = $env{'form.custhelpname'.$num};
12698: $rolename=~s/[^A-Za-z0-9]//gs;
12699: next if ($rolename eq '');
12700: next if (exists($existing{'rolesdef_'.$rolename}));
12701: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12702: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12703: $newprivs{'c'},$confname,$dom);
12704: if ($result ne 'ok') {
12705: $errors .= '<li><span class="LC_error">'.
12706: &mt('An error occurred storing the new custom role: [_1]',
12707: $result).'</span></li>';
12708: next;
12709: } else {
12710: $changedprivs{$rolename} = \%newprivs;
12711: $newrole = $rolename;
12712: }
12713: } else {
12714: $prefix = 'helproles_'.$num;
12715: $rolename = $env{'form.'.$prefix};
12716: next if ($rolename eq '');
12717: next unless (exists($existing{'rolesdef_'.$rolename}));
12718: $identifier = 'custhelp'.$num;
12719: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12720: my %currprivs;
1.289 raeburn 12721: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 12722: split(/\_/,$existing{'rolesdef_'.$rolename});
12723: foreach my $level ('c','d','s') {
12724: if ($newprivs{$level} ne $currprivs{$level}) {
12725: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12726: $newprivs{'c'},$confname,$dom);
12727: if ($result ne 'ok') {
12728: $errors .= '<li><span class="LC_error">'.
12729: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12730: $rolename,$result).'</span></li>';
12731: } else {
12732: $changedprivs{$rolename} = \%newprivs;
12733: }
12734: last;
12735: }
12736: }
12737: if (ref($current{'adhoc'}) eq 'HASH') {
12738: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12739: %curr = %{$current{'adhoc'}{$rolename}};
12740: }
12741: }
12742: }
12743: my $newpos = $env{'form.'.$prefix.'_pos'};
12744: $newpos =~ s/\D+//g;
12745: $allpos[$newpos] = $rolename;
12746: my $newdesc = $env{'form.'.$prefix.'_desc'};
12747: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12748: if ($curr{'desc'}) {
12749: if ($curr{'desc'} ne $newdesc) {
12750: $changes{'customrole'}{$rolename}{'desc'} = 1;
12751: $newsettings{$rolename}{'desc'} = $newdesc;
12752: }
12753: } elsif ($newdesc ne '') {
12754: $changes{'customrole'}{$rolename}{'desc'} = 1;
12755: $newsettings{$rolename}{'desc'} = $newdesc;
12756: }
12757: my $access = $env{'form.'.$prefix.'_access'};
12758: if (grep(/^\Q$access\E$/,@accesstypes)) {
12759: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12760: if ($access eq 'status') {
12761: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12762: if (scalar(@statuses) == 0) {
1.289 raeburn 12763: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 12764: } else {
12765: my (@shownstatus,$numtypes);
12766: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12767: if (ref($types) eq 'ARRAY') {
12768: $numtypes = scalar(@{$types});
12769: foreach my $type (sort(@statuses)) {
12770: if ($type eq 'default') {
12771: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12772: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12773: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12774: push(@shownstatus,$usertypes->{$type});
12775: }
12776: }
12777: }
12778: if (grep(/^default$/,@statuses)) {
12779: push(@shownstatus,$othertitle);
12780: }
12781: if (scalar(@shownstatus) == 1+$numtypes) {
12782: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12783: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12784: } else {
12785: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12786: if (ref($curr{'status'}) eq 'ARRAY') {
12787: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12788: if (@diffs) {
12789: $changes{'customrole'}{$rolename}{$access} = 1;
12790: }
12791: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12792: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 12793: }
1.166 raeburn 12794: }
12795: }
1.285 raeburn 12796: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12797: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12798: my @newspecstaff;
12799: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12800: foreach my $person (sort(@personnel)) {
12801: if ($domhelpdesk{$person}) {
12802: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12803: }
12804: }
12805: if (ref($curr{$access}) eq 'ARRAY') {
12806: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12807: if (@diffs) {
12808: $changes{'customrole'}{$rolename}{$access} = 1;
12809: }
12810: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12811: $changes{'customrole'}{$rolename}{$access} = 1;
12812: }
12813: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12814: my ($uname,$udom) = split(/:/,$person);
12815: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12816: }
12817: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 12818: }
1.285 raeburn 12819: } else {
12820: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12821: }
12822: unless ($curr{'access'} eq $access) {
12823: $changes{'customrole'}{$rolename}{'access'} = 1;
12824: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 12825: }
12826: }
1.285 raeburn 12827: if (@allpos > 0) {
12828: my $idx = 0;
12829: foreach my $rolename (@allpos) {
12830: if ($rolename ne '') {
12831: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12832: if (ref($current{'adhoc'}) eq 'HASH') {
12833: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12834: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12835: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 12836: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 12837: }
12838: }
1.282 raeburn 12839: }
1.285 raeburn 12840: $idx ++;
1.166 raeburn 12841: }
12842: }
1.118 jms 12843: }
1.123 jms 12844: my $putresult;
12845: if (keys(%changes) > 0) {
1.166 raeburn 12846: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 12847: if ($putresult eq 'ok') {
1.285 raeburn 12848: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12849: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12850: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12851: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12852: }
12853: }
12854: my $cachetime = 24*60*60;
12855: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12856: if (ref($lastactref) eq 'HASH') {
12857: $lastactref->{'domdefaults'} = 1;
12858: }
12859: } else {
12860: $errors .= '<li><span class="LC_error">'.
12861: &mt('An error occurred storing the settings: [_1]',
12862: $putresult).'</span></li>';
12863: }
12864: }
12865: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12866: $resulttext = &mt('Changes made:').'<ul>';
12867: my (%shownprivs,@levelorder);
12868: @levelorder = ('c','d','s');
12869: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 12870: foreach my $item (sort(keys(%changes))) {
12871: if ($item eq 'submitbugs') {
12872: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12873: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12874: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 12875: } elsif ($item eq 'customrole') {
12876: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 12877: my @keyorder = ('order','desc','access','status','exc','inc');
12878: my %keytext = &Apache::lonlocal::texthash(
12879: order => 'Order',
12880: desc => 'Role description',
12881: access => 'Role usage',
12882: status => 'Allowed instituional types',
12883: exc => 'Allowed personnel',
12884: inc => 'Disallowed personnel',
12885: );
1.282 raeburn 12886: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 12887: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12888: if ($role eq $newrole) {
12889: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12890: $role).'<ul>';
12891: } else {
12892: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12893: $role).'<ul>';
12894: }
12895: foreach my $key (@keyorder) {
12896: if ($changes{'customrole'}{$role}{$key}) {
12897: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12898: $keytext{$key},$newsettings{$role}{$key}).
12899: '</li>';
12900: }
12901: }
12902: if (ref($changedprivs{$role}) eq 'HASH') {
12903: $shownprivs{$role} = 1;
12904: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
12905: foreach my $level (@levelorder) {
12906: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12907: next if ($item eq '');
12908: my ($priv) = split(/\&/,$item,2);
12909: if (&Apache::lonnet::plaintext($priv)) {
12910: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12911: unless ($level eq 'c') {
12912: $resulttext .= ' ('.$lt{$level}.')';
12913: }
12914: $resulttext .= '</li>';
12915: }
12916: }
12917: }
12918: $resulttext .= '</ul>';
12919: }
12920: $resulttext .= '</ul></li>';
12921: }
12922: }
12923: }
12924: }
12925: }
12926: }
12927: if (keys(%changedprivs)) {
12928: foreach my $role (sort(keys(%changedprivs))) {
12929: unless ($shownprivs{$role}) {
12930: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12931: $role).'<ul>'.
12932: '<li>'.&mt('Privileges set to :').'<ul>';
12933: foreach my $level (@levelorder) {
12934: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12935: next if ($item eq '');
12936: my ($priv) = split(/\&/,$item,2);
12937: if (&Apache::lonnet::plaintext($priv)) {
12938: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12939: unless ($level eq 'c') {
12940: $resulttext .= ' ('.$lt{$level}.')';
12941: }
12942: $resulttext .= '</li>';
12943: }
1.282 raeburn 12944: }
12945: }
1.285 raeburn 12946: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 12947: }
12948: }
12949: }
1.285 raeburn 12950: $resulttext .= '</ul>';
12951: } else {
12952: $resulttext = &mt('No changes made to help settings');
1.118 jms 12953: }
12954: if ($errors) {
1.168 raeburn 12955: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 12956: $errors.'</ul>';
1.118 jms 12957: }
12958: return $resulttext;
12959: }
12960:
1.121 raeburn 12961: sub modify_coursedefaults {
1.212 raeburn 12962: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 12963: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 12964: my %defaultchecked = (
12965: 'canuse_pdfforms' => 'off',
12966: 'uselcmath' => 'on',
12967: 'usejsme' => 'on'
12968: );
12969: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 12970: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 12971: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
12972: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
12973: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 12974: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 12975: my %staticdefaults = (
12976: anonsurvey_threshold => 10,
12977: uploadquota => 500,
1.257 raeburn 12978: postsubmit => 60,
1.276 raeburn 12979: mysqltables => 172800,
1.198 raeburn 12980: );
1.121 raeburn 12981:
12982: $defaultshash{'coursedefaults'} = {};
12983:
12984: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
12985: if ($domconfig{'coursedefaults'} eq '') {
12986: $domconfig{'coursedefaults'} = {};
12987: }
12988: }
12989:
12990: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
12991: foreach my $item (@toggles) {
12992: if ($defaultchecked{$item} eq 'on') {
12993: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12994: ($env{'form.'.$item} eq '0')) {
12995: $changes{$item} = 1;
1.192 raeburn 12996: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 12997: $changes{$item} = 1;
12998: }
12999: } elsif ($defaultchecked{$item} eq 'off') {
13000: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13001: ($env{'form.'.$item} eq '1')) {
13002: $changes{$item} = 1;
13003: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13004: $changes{$item} = 1;
13005: }
13006: }
13007: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13008: }
1.198 raeburn 13009: foreach my $item (@numbers) {
13010: my ($currdef,$newdef);
1.208 raeburn 13011: $newdef = $env{'form.'.$item};
1.198 raeburn 13012: if ($item eq 'anonsurvey_threshold') {
13013: $currdef = $domconfig{'coursedefaults'}{$item};
13014: $newdef =~ s/\D//g;
13015: if ($newdef eq '' || $newdef < 1) {
13016: $newdef = 1;
13017: }
13018: $defaultshash{'coursedefaults'}{$item} = $newdef;
13019: } else {
1.276 raeburn 13020: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13021: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13022: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 13023: }
13024: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 13025: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 13026: }
13027: if ($currdef ne $newdef) {
13028: my $staticdef;
13029: if ($item eq 'anonsurvey_threshold') {
13030: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13031: $changes{$item} = 1;
13032: }
1.276 raeburn 13033: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 13034: my $setting = $1;
1.276 raeburn 13035: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13036: $changes{$setting} = 1;
1.198 raeburn 13037: }
13038: }
1.139 raeburn 13039: }
13040: }
1.264 raeburn 13041: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13042: my @currclonecode;
13043: if (ref($currclone) eq 'HASH') {
13044: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13045: @currclonecode = @{$currclone->{'instcode'}};
13046: }
13047: }
13048: my $newclone;
1.289 raeburn 13049: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 13050: $newclone = $env{'form.canclone'};
13051: }
13052: if ($newclone eq 'instcode') {
13053: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13054: my (%codedefaults,@code_order,@clonecode);
13055: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13056: \@code_order);
13057: foreach my $item (@code_order) {
13058: if (grep(/^\Q$item\E$/,@newcodes)) {
13059: push(@clonecode,$item);
13060: }
13061: }
13062: if (@clonecode) {
13063: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13064: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13065: if (@diffs) {
13066: $changes{'canclone'} = 1;
13067: }
13068: } else {
13069: $newclone eq '';
13070: }
13071: } elsif ($newclone ne '') {
1.289 raeburn 13072: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13073: }
1.264 raeburn 13074: if ($newclone ne $currclone) {
13075: $changes{'canclone'} = 1;
13076: }
1.257 raeburn 13077: my %credits;
13078: foreach my $type (@types) {
13079: unless ($type eq 'community') {
13080: $credits{$type} = $env{'form.'.$type.'_credits'};
13081: $credits{$type} =~ s/[^\d.]+//g;
13082: }
13083: }
13084: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13085: ($env{'form.coursecredits'} eq '1')) {
13086: $changes{'coursecredits'} = 1;
13087: foreach my $type (keys(%credits)) {
13088: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13089: }
13090: } else {
1.289 raeburn 13091: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 13092: foreach my $type (@types) {
13093: unless ($type eq 'community') {
1.289 raeburn 13094: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 13095: $changes{'coursecredits'} = 1;
13096: }
13097: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13098: }
13099: }
13100: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13101: foreach my $type (@types) {
13102: unless ($type eq 'community') {
13103: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13104: $changes{'coursecredits'} = 1;
13105: last;
13106: }
13107: }
13108: }
13109: }
13110: }
13111: if ($env{'form.postsubmit'} eq '1') {
13112: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13113: my %currtimeout;
13114: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13115: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13116: $changes{'postsubmit'} = 1;
13117: }
13118: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13119: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13120: }
13121: } else {
13122: $changes{'postsubmit'} = 1;
13123: }
13124: foreach my $type (@types) {
13125: my $timeout = $env{'form.'.$type.'_timeout'};
13126: $timeout =~ s/\D//g;
13127: if ($timeout == $staticdefaults{'postsubmit'}) {
13128: $timeout = '';
13129: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13130: $timeout = '0';
13131: }
13132: unless ($timeout eq '') {
13133: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13134: }
13135: if (exists($currtimeout{$type})) {
13136: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 13137: $changes{'postsubmit'} = 1;
1.257 raeburn 13138: }
13139: } elsif ($timeout ne '') {
13140: $changes{'postsubmit'} = 1;
13141: }
13142: }
13143: } else {
13144: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13145: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13146: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13147: $changes{'postsubmit'} = 1;
13148: }
13149: } else {
13150: $changes{'postsubmit'} = 1;
13151: }
1.192 raeburn 13152: }
1.121 raeburn 13153: }
13154: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13155: $dom);
13156: if ($putresult eq 'ok') {
13157: if (keys(%changes) > 0) {
1.213 raeburn 13158: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 13159: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 13160: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 13161: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 13162: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
13163: if ($changes{$item}) {
13164: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13165: }
1.289 raeburn 13166: }
1.192 raeburn 13167: if ($changes{'coursecredits'}) {
13168: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 13169: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13170: $domdefaults{$type.'credits'} =
13171: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13172: }
13173: }
13174: }
13175: if ($changes{'postsubmit'}) {
13176: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13177: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13178: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13179: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13180: $domdefaults{$type.'postsubtimeout'} =
13181: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13182: }
13183: }
1.192 raeburn 13184: }
13185: }
1.198 raeburn 13186: if ($changes{'uploadquota'}) {
13187: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13188: foreach my $type (@types) {
13189: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13190: }
13191: }
13192: }
1.264 raeburn 13193: if ($changes{'canclone'}) {
13194: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13195: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13196: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13197: if (@clonecodes) {
13198: $domdefaults{'canclone'} = join('+',@clonecodes);
13199: }
13200: }
13201: } else {
13202: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13203: }
13204: }
1.121 raeburn 13205: my $cachetime = 24*60*60;
13206: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13207: if (ref($lastactref) eq 'HASH') {
13208: $lastactref->{'domdefaults'} = 1;
13209: }
1.121 raeburn 13210: }
13211: $resulttext = &mt('Changes made:').'<ul>';
13212: foreach my $item (sort(keys(%changes))) {
13213: if ($item eq 'canuse_pdfforms') {
13214: if ($env{'form.'.$item} eq '1') {
13215: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
13216: } else {
13217: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
13218: }
1.257 raeburn 13219: } elsif ($item eq 'uselcmath') {
13220: if ($env{'form.'.$item} eq '1') {
13221: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13222: } else {
13223: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13224: }
13225: } elsif ($item eq 'usejsme') {
13226: if ($env{'form.'.$item} eq '1') {
13227: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13228: } else {
1.289 raeburn 13229: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 13230: }
1.139 raeburn 13231: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 13232: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 13233: } elsif ($item eq 'uploadquota') {
13234: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13235: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13236: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13237: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 13238: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 13239: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 13240: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13241: '</ul>'.
13242: '</li>';
13243: } else {
13244: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13245: }
1.276 raeburn 13246: } elsif ($item eq 'mysqltables') {
13247: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13248: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13249: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13250: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13251: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13252: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
13253: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13254: '</ul>'.
13255: '</li>';
13256: } else {
13257: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13258: }
1.257 raeburn 13259: } elsif ($item eq 'postsubmit') {
13260: if ($domdefaults{'postsubmit'} eq 'off') {
13261: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13262: } else {
13263: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 13264: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 13265: $resulttext .= &mt('durations:').'<ul>';
13266: foreach my $type (@types) {
13267: $resulttext .= '<li>';
13268: my $timeout;
13269: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13270: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13271: }
13272: my $display;
13273: if ($timeout eq '0') {
13274: $display = &mt('unlimited');
13275: } elsif ($timeout eq '') {
13276: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13277: } else {
13278: $display = &mt('[quant,_1,second]',$timeout);
13279: }
13280: if ($type eq 'community') {
13281: $resulttext .= &mt('Communities');
13282: } elsif ($type eq 'official') {
13283: $resulttext .= &mt('Official courses');
13284: } elsif ($type eq 'unofficial') {
13285: $resulttext .= &mt('Unofficial courses');
13286: } elsif ($type eq 'textbook') {
13287: $resulttext .= &mt('Textbook courses');
1.271 raeburn 13288: } elsif ($type eq 'placement') {
13289: $resulttext .= &mt('Placement tests');
1.257 raeburn 13290: }
13291: $resulttext .= ' -- '.$display.'</li>';
13292: }
13293: $resulttext .= '</ul>';
13294: }
1.289 raeburn 13295: $resulttext .= '</li>';
1.257 raeburn 13296: }
1.192 raeburn 13297: } elsif ($item eq 'coursecredits') {
13298: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13299: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 13300: ($domdefaults{'unofficialcredits'} eq '') &&
13301: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 13302: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13303: } else {
13304: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13305: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13306: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 13307: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 13308: '</ul>'.
13309: '</li>';
13310: }
13311: } else {
13312: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13313: }
1.264 raeburn 13314: } elsif ($item eq 'canclone') {
13315: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13316: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13317: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13318: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13319: }
13320: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13321: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13322: } else {
1.289 raeburn 13323: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 13324: }
1.140 raeburn 13325: }
1.121 raeburn 13326: }
13327: $resulttext .= '</ul>';
13328: } else {
13329: $resulttext = &mt('No changes made to course defaults');
13330: }
13331: } else {
13332: $resulttext = '<span class="LC_error">'.
13333: &mt('An error occurred: [_1]',$putresult).'</span>';
13334: }
13335: return $resulttext;
13336: }
13337:
1.231 raeburn 13338: sub modify_selfenrollment {
13339: my ($dom,$lastactref,%domconfig) = @_;
13340: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 13341: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 13342: my %titles = &tool_titles();
1.232 raeburn 13343: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13344: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 13345: $ordered{'default'} = ['types','registered','approval','limit'];
13346:
13347: my (%roles,%shown,%toplevel);
13348: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13349:
13350: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13351: if ($domconfig{'selfenrollment'} eq '') {
13352: $domconfig{'selfenrollment'} = {};
13353: }
13354: }
13355: %toplevel = (
13356: admin => 'Configuration Rights',
13357: default => 'Default settings',
13358: validation => 'Validation of self-enrollment requests',
13359: );
1.233 raeburn 13360: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 13361:
13362: if (ref($ordered{'admin'}) eq 'ARRAY') {
13363: foreach my $item (@{$ordered{'admin'}}) {
13364: foreach my $type (@types) {
13365: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13366: $selfenrollhash{'admin'}{$type}{$item} = 1;
13367: } else {
13368: $selfenrollhash{'admin'}{$type}{$item} = 0;
13369: }
13370: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13371: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13372: if ($selfenrollhash{'admin'}{$type}{$item} ne
13373: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13374: push(@{$changes{'admin'}{$type}},$item);
13375: }
13376: } else {
13377: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13378: push(@{$changes{'admin'}{$type}},$item);
13379: }
13380: }
13381: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13382: push(@{$changes{'admin'}{$type}},$item);
13383: }
13384: }
13385: }
13386: }
13387:
13388: foreach my $item (@{$ordered{'default'}}) {
13389: foreach my $type (@types) {
13390: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13391: if ($item eq 'types') {
13392: unless (($value eq 'all') || ($value eq 'dom')) {
13393: $value = '';
13394: }
13395: } elsif ($item eq 'registered') {
13396: unless ($value eq '1') {
13397: $value = 0;
13398: }
13399: } elsif ($item eq 'approval') {
13400: unless ($value =~ /^[012]$/) {
13401: $value = 0;
13402: }
13403: } else {
13404: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13405: $value = 'none';
13406: }
13407: }
13408: $selfenrollhash{'default'}{$type}{$item} = $value;
13409: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13410: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13411: if ($selfenrollhash{'default'}{$type}{$item} ne
13412: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13413: push(@{$changes{'default'}{$type}},$item);
13414: }
13415: } else {
13416: push(@{$changes{'default'}{$type}},$item);
13417: }
13418: } else {
13419: push(@{$changes{'default'}{$type}},$item);
13420: }
13421: if ($item eq 'limit') {
13422: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13423: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13424: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13425: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13426: }
13427: } else {
13428: $selfenrollhash{'default'}{$type}{'cap'} = '';
13429: }
13430: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13431: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13432: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13433: push(@{$changes{'default'}{$type}},'cap');
13434: }
13435: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13436: push(@{$changes{'default'}{$type}},'cap');
13437: }
13438: }
13439: }
13440: }
13441:
13442: foreach my $item (@{$itemsref}) {
13443: if ($item eq 'fields') {
13444: my @changed;
13445: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13446: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13447: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13448: }
13449: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13450: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13451: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13452: $domconfig{'selfenrollment'}{'validation'}{$item});
13453: } else {
13454: @changed = @{$selfenrollhash{'validation'}{$item}};
13455: }
13456: } else {
13457: @changed = @{$selfenrollhash{'validation'}{$item}};
13458: }
13459: if (@changed) {
13460: if ($selfenrollhash{'validation'}{$item}) {
13461: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13462: } else {
13463: $changes{'validation'}{$item} = &mt('None');
13464: }
13465: }
13466: } else {
13467: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13468: if ($item eq 'markup') {
13469: if ($env{'form.selfenroll_validation_'.$item}) {
13470: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13471: }
13472: }
13473: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13474: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13475: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13476: }
13477: }
13478: }
13479: }
13480:
13481: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13482: $dom);
13483: if ($putresult eq 'ok') {
13484: if (keys(%changes) > 0) {
13485: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13486: $resulttext = &mt('Changes made:').'<ul>';
13487: foreach my $key ('admin','default','validation') {
13488: if (ref($changes{$key}) eq 'HASH') {
13489: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13490: if ($key eq 'validation') {
13491: foreach my $item (@{$itemsref}) {
13492: if (exists($changes{$key}{$item})) {
13493: if ($item eq 'markup') {
13494: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13495: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13496: } else {
13497: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13498: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13499: }
13500: }
13501: }
13502: } else {
13503: foreach my $type (@types) {
13504: if ($type eq 'community') {
13505: $roles{'1'} = &mt('Community personnel');
13506: } else {
13507: $roles{'1'} = &mt('Course personnel');
13508: }
13509: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 13510: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13511: if ($key eq 'admin') {
13512: my @mgrdc = ();
13513: if (ref($ordered{$key}) eq 'ARRAY') {
13514: foreach my $item (@{$ordered{'admin'}}) {
13515: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13516: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13517: push(@mgrdc,$item);
13518: }
13519: }
13520: }
13521: if (@mgrdc) {
13522: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13523: } else {
13524: delete($domdefaults{$type.'selfenrolladmdc'});
13525: }
13526: }
13527: } else {
13528: if (ref($ordered{$key}) eq 'ARRAY') {
13529: foreach my $item (@{$ordered{$key}}) {
13530: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13531: $domdefaults{$type.'selfenroll'.$item} =
13532: $selfenrollhash{$key}{$type}{$item};
13533: }
13534: }
13535: }
13536: }
13537: }
1.231 raeburn 13538: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13539: foreach my $item (@{$ordered{$key}}) {
13540: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13541: $resulttext .= '<li>';
13542: if ($key eq 'admin') {
13543: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13544: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13545: } else {
13546: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13547: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13548: }
13549: $resulttext .= '</li>';
13550: }
13551: }
13552: $resulttext .= '</ul></li>';
13553: }
13554: }
13555: $resulttext .= '</ul></li>';
13556: }
13557: }
1.232 raeburn 13558: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13559: my $cachetime = 24*60*60;
13560: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13561: if (ref($lastactref) eq 'HASH') {
13562: $lastactref->{'domdefaults'} = 1;
13563: }
13564: }
1.231 raeburn 13565: }
13566: $resulttext .= '</ul>';
13567: } else {
13568: $resulttext = &mt('No changes made to self-enrollment settings');
13569: }
13570: } else {
13571: $resulttext = '<span class="LC_error">'.
13572: &mt('An error occurred: [_1]',$putresult).'</span>';
13573: }
13574: return $resulttext;
13575: }
13576:
1.137 raeburn 13577: sub modify_usersessions {
1.212 raeburn 13578: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13579: my @hostingtypes = ('version','excludedomain','includedomain');
13580: my @offloadtypes = ('primary','default');
13581: my %types = (
13582: remote => \@hostingtypes,
13583: hosted => \@hostingtypes,
13584: spares => \@offloadtypes,
13585: );
13586: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13587: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 13588: my (%by_ip,%by_location,@intdoms,@instdoms);
13589: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 13590: my @locations = sort(keys(%by_location));
1.137 raeburn 13591: my (%defaultshash,%changes);
13592: foreach my $prefix (@prefixes) {
13593: $defaultshash{'usersessions'}{$prefix} = {};
13594: }
1.212 raeburn 13595: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13596: my $resulttext;
1.138 raeburn 13597: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13598: foreach my $prefix (@prefixes) {
1.145 raeburn 13599: next if ($prefix eq 'spares');
13600: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13601: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13602: if ($type eq 'version') {
13603: my $value = $env{'form.'.$prefix.'_'.$type};
13604: my $okvalue;
13605: if ($value ne '') {
13606: if (grep(/^\Q$value\E$/,@lcversions)) {
13607: $okvalue = $value;
13608: }
13609: }
13610: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13611: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13612: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13613: if ($inuse == 0) {
13614: $changes{$prefix}{$type} = 1;
13615: } else {
13616: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13617: $changes{$prefix}{$type} = 1;
13618: }
13619: if ($okvalue ne '') {
13620: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13621: }
13622: }
13623: } else {
13624: if (($inuse == 1) && ($okvalue ne '')) {
13625: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13626: $changes{$prefix}{$type} = 1;
13627: }
13628: }
13629: } else {
13630: if (($inuse == 1) && ($okvalue ne '')) {
13631: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13632: $changes{$prefix}{$type} = 1;
13633: }
13634: }
13635: } else {
13636: if (($inuse == 1) && ($okvalue ne '')) {
13637: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13638: $changes{$prefix}{$type} = 1;
13639: }
13640: }
13641: } else {
13642: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13643: my @okvals;
13644: foreach my $val (@vals) {
1.138 raeburn 13645: if ($val =~ /:/) {
13646: my @items = split(/:/,$val);
13647: foreach my $item (@items) {
13648: if (ref($by_location{$item}) eq 'ARRAY') {
13649: push(@okvals,$item);
13650: }
13651: }
13652: } else {
13653: if (ref($by_location{$val}) eq 'ARRAY') {
13654: push(@okvals,$val);
13655: }
1.137 raeburn 13656: }
13657: }
13658: @okvals = sort(@okvals);
13659: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13660: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13661: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13662: if ($inuse == 0) {
13663: $changes{$prefix}{$type} = 1;
13664: } else {
13665: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13666: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13667: if (@changed > 0) {
13668: $changes{$prefix}{$type} = 1;
13669: }
13670: }
13671: } else {
13672: if ($inuse == 1) {
13673: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13674: $changes{$prefix}{$type} = 1;
13675: }
13676: }
13677: } else {
13678: if ($inuse == 1) {
13679: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13680: $changes{$prefix}{$type} = 1;
13681: }
13682: }
13683: } else {
13684: if ($inuse == 1) {
13685: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13686: $changes{$prefix}{$type} = 1;
13687: }
13688: }
13689: }
13690: }
13691: }
1.145 raeburn 13692:
13693: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 13694: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 13695: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13696: my $savespares;
13697:
13698: foreach my $lonhost (sort(keys(%servers))) {
13699: my $serverhomeID =
13700: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 13701: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 13702: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13703: my %spareschg;
13704: foreach my $type (@{$types{'spares'}}) {
13705: my @okspares;
13706: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13707: foreach my $server (@checked) {
1.152 raeburn 13708: if (&Apache::lonnet::hostname($server) ne '') {
13709: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13710: unless (grep(/^\Q$server\E$/,@okspares)) {
13711: push(@okspares,$server);
13712: }
1.145 raeburn 13713: }
13714: }
13715: }
13716: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13717: my $newspare;
1.152 raeburn 13718: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13719: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 13720: $newspare = $new;
13721: }
13722: }
1.152 raeburn 13723: my @spares;
13724: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13725: @spares = sort(@okspares,$newspare);
13726: } else {
13727: @spares = sort(@okspares);
13728: }
13729: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 13730: if (ref($spareid{$lonhost}) eq 'HASH') {
13731: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 13732: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 13733: if (@diffs > 0) {
13734: $spareschg{$type} = 1;
13735: }
13736: }
13737: }
13738: }
13739: if (keys(%spareschg) > 0) {
13740: $changes{'spares'}{$lonhost} = \%spareschg;
13741: }
13742: }
1.261 raeburn 13743: $defaultshash{'usersessions'}{'offloadnow'} = {};
13744: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13745: my @okoffload;
13746: if (@offloadnow) {
13747: foreach my $server (@offloadnow) {
13748: if (&Apache::lonnet::hostname($server) ne '') {
13749: unless (grep(/^\Q$server\E$/,@okoffload)) {
13750: push(@okoffload,$server);
13751: }
13752: }
13753: }
13754: if (@okoffload) {
13755: foreach my $lonhost (@okoffload) {
13756: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13757: }
13758: }
13759: }
1.145 raeburn 13760: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13761: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13762: if (ref($changes{'spares'}) eq 'HASH') {
13763: if (keys(%{$changes{'spares'}}) > 0) {
13764: $savespares = 1;
13765: }
13766: }
13767: } else {
13768: $savespares = 1;
13769: }
1.261 raeburn 13770: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13771: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13772: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13773: $changes{'offloadnow'} = 1;
13774: last;
13775: }
13776: }
13777: unless ($changes{'offloadnow'}) {
1.289 raeburn 13778: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 13779: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13780: $changes{'offloadnow'} = 1;
13781: last;
13782: }
13783: }
13784: }
13785: } elsif (@okoffload) {
13786: $changes{'offloadnow'} = 1;
13787: }
13788: } elsif (@okoffload) {
13789: $changes{'offloadnow'} = 1;
1.145 raeburn 13790: }
1.147 raeburn 13791: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13792: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13793: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13794: $dom);
13795: if ($putresult eq 'ok') {
13796: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13797: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13798: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13799: }
13800: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13801: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13802: }
1.261 raeburn 13803: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13804: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13805: }
1.137 raeburn 13806: }
13807: my $cachetime = 24*60*60;
13808: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13809: if (ref($lastactref) eq 'HASH') {
13810: $lastactref->{'domdefaults'} = 1;
13811: }
1.147 raeburn 13812: if (keys(%changes) > 0) {
13813: my %lt = &usersession_titles();
13814: $resulttext = &mt('Changes made:').'<ul>';
13815: foreach my $prefix (@prefixes) {
13816: if (ref($changes{$prefix}) eq 'HASH') {
13817: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13818: if ($prefix eq 'spares') {
13819: if (ref($changes{$prefix}) eq 'HASH') {
13820: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13821: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13822: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 13823: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13824: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13825: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13826: foreach my $type (@{$types{$prefix}}) {
13827: if ($changes{$prefix}{$lonhost}{$type}) {
13828: my $offloadto = &mt('None');
13829: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13830: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13831: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13832: }
1.145 raeburn 13833: }
1.147 raeburn 13834: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13835: }
1.137 raeburn 13836: }
13837: }
1.147 raeburn 13838: $resulttext .= '</li>';
1.137 raeburn 13839: }
13840: }
1.147 raeburn 13841: } else {
13842: foreach my $type (@{$types{$prefix}}) {
13843: if (defined($changes{$prefix}{$type})) {
13844: my $newvalue;
13845: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13846: if (ref($defaultshash{'usersessions'}{$prefix})) {
13847: if ($type eq 'version') {
13848: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13849: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13850: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13851: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13852: }
1.145 raeburn 13853: }
13854: }
13855: }
1.147 raeburn 13856: if ($newvalue eq '') {
13857: if ($type eq 'version') {
13858: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13859: } else {
13860: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13861: }
1.145 raeburn 13862: } else {
1.147 raeburn 13863: if ($type eq 'version') {
13864: $newvalue .= ' '.&mt('(or later)');
13865: }
13866: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13867: }
1.137 raeburn 13868: }
13869: }
13870: }
1.147 raeburn 13871: $resulttext .= '</ul>';
1.137 raeburn 13872: }
13873: }
1.261 raeburn 13874: if ($changes{'offloadnow'}) {
13875: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13876: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13877: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13878: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13879: $resulttext .= '<li>'.$lonhost.'</li>';
13880: }
13881: $resulttext .= '</ul>';
13882: } else {
13883: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13884: }
13885: } else {
13886: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13887: }
13888: }
1.147 raeburn 13889: $resulttext .= '</ul>';
13890: } else {
13891: $resulttext = $nochgmsg;
1.137 raeburn 13892: }
13893: } else {
13894: $resulttext = '<span class="LC_error">'.
13895: &mt('An error occurred: [_1]',$putresult).'</span>';
13896: }
13897: } else {
1.147 raeburn 13898: $resulttext = $nochgmsg;
1.137 raeburn 13899: }
13900: return $resulttext;
13901: }
13902:
1.275 raeburn 13903: sub modify_ssl {
13904: my ($dom,$lastactref,%domconfig) = @_;
13905: my (%by_ip,%by_location,@intdoms,@instdoms);
13906: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
13907: my @locations = sort(keys(%by_location));
13908: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13909: my (%defaultshash,%changes);
13910: my $action = 'ssl';
1.293 raeburn 13911: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 13912: foreach my $prefix (@prefixes) {
13913: $defaultshash{$action}{$prefix} = {};
13914: }
13915: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13916: my $resulttext;
13917: my %iphost = &Apache::lonnet::get_iphost();
13918: my @reptypes = ('certreq','nocertreq');
13919: my @connecttypes = ('dom','intdom','other');
13920: my %types = (
1.293 raeburn 13921: connto => \@connecttypes,
13922: connfrom => \@connecttypes,
13923: replication => \@reptypes,
1.275 raeburn 13924: );
13925: foreach my $prefix (sort(keys(%types))) {
13926: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 13927: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 13928: my $value = 'yes';
13929: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
13930: $value = $env{'form.'.$prefix.'_'.$type};
13931: }
13932: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
13933: if ($domconfig{$action}{$prefix}{$type} ne '') {
13934: if ($value ne $domconfig{$action}{$prefix}{$type}) {
13935: $changes{$prefix}{$type} = 1;
13936: }
13937: $defaultshash{$action}{$prefix}{$type} = $value;
13938: } else {
13939: $defaultshash{$action}{$prefix}{$type} = $value;
13940: $changes{$prefix}{$type} = 1;
13941: }
13942: } else {
13943: $defaultshash{$action}{$prefix}{$type} = $value;
13944: $changes{$prefix}{$type} = 1;
13945: }
13946: if (($type eq 'dom') && (keys(%servers) == 1)) {
13947: delete($changes{$prefix}{$type});
13948: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
13949: delete($changes{$prefix}{$type});
13950: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
13951: delete($changes{$prefix}{$type});
13952: }
13953: } elsif ($prefix eq 'replication') {
13954: if (@locations > 0) {
13955: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13956: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13957: my @okvals;
13958: foreach my $val (@vals) {
13959: if ($val =~ /:/) {
13960: my @items = split(/:/,$val);
13961: foreach my $item (@items) {
13962: if (ref($by_location{$item}) eq 'ARRAY') {
13963: push(@okvals,$item);
13964: }
13965: }
13966: } else {
13967: if (ref($by_location{$val}) eq 'ARRAY') {
13968: push(@okvals,$val);
13969: }
13970: }
13971: }
13972: @okvals = sort(@okvals);
13973: if (ref($domconfig{$action}) eq 'HASH') {
13974: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
13975: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
13976: if ($inuse == 0) {
13977: $changes{$prefix}{$type} = 1;
13978: } else {
13979: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13980: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
13981: if (@changed > 0) {
13982: $changes{$prefix}{$type} = 1;
13983: }
13984: }
13985: } else {
13986: if ($inuse == 1) {
13987: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13988: $changes{$prefix}{$type} = 1;
13989: }
13990: }
13991: } else {
13992: if ($inuse == 1) {
13993: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13994: $changes{$prefix}{$type} = 1;
13995: }
13996: }
13997: } else {
13998: if ($inuse == 1) {
13999: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14000: $changes{$prefix}{$type} = 1;
14001: }
14002: }
14003: }
14004: }
14005: }
14006: }
14007: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
14008: if (keys(%changes) > 0) {
14009: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14010: $dom);
14011: if ($putresult eq 'ok') {
14012: if (ref($defaultshash{$action}) eq 'HASH') {
14013: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
14014: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
14015: }
1.293 raeburn 14016: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
14017: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
14018: }
14019: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
14020: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 14021: }
14022: }
14023: my $cachetime = 24*60*60;
14024: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14025: if (ref($lastactref) eq 'HASH') {
14026: $lastactref->{'domdefaults'} = 1;
14027: }
14028: if (keys(%changes) > 0) {
14029: my %titles = &ssl_titles();
14030: $resulttext = &mt('Changes made:').'<ul>';
14031: foreach my $prefix (@prefixes) {
14032: if (ref($changes{$prefix}) eq 'HASH') {
14033: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
14034: foreach my $type (@{$types{$prefix}}) {
14035: if (defined($changes{$prefix}{$type})) {
14036: my $newvalue;
14037: if (ref($defaultshash{$action}) eq 'HASH') {
14038: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 14039: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14040: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
14041: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
14042: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
14043: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
14044: }
14045: }
14046: }
14047: if ($newvalue eq '') {
14048: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
14049: } else {
14050: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
14051: }
14052: }
14053: }
14054: }
14055: $resulttext .= '</ul>';
14056: }
14057: }
14058: } else {
14059: $resulttext = $nochgmsg;
14060: }
14061: } else {
14062: $resulttext = '<span class="LC_error">'.
14063: &mt('An error occurred: [_1]',$putresult).'</span>';
14064: }
14065: } else {
14066: $resulttext = $nochgmsg;
14067: }
14068: return $resulttext;
14069: }
14070:
1.279 raeburn 14071: sub modify_trust {
14072: my ($dom,$lastactref,%domconfig) = @_;
14073: my (%by_ip,%by_location,@intdoms,@instdoms);
14074: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14075: my @locations = sort(keys(%by_location));
14076: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
14077: my @types = ('exc','inc');
14078: my (%defaultshash,%changes);
14079: foreach my $prefix (@prefixes) {
14080: $defaultshash{'trust'}{$prefix} = {};
14081: }
14082: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14083: my $resulttext;
14084: foreach my $prefix (@prefixes) {
14085: foreach my $type (@types) {
14086: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14087: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14088: my @okvals;
14089: foreach my $val (@vals) {
14090: if ($val =~ /:/) {
14091: my @items = split(/:/,$val);
14092: foreach my $item (@items) {
14093: if (ref($by_location{$item}) eq 'ARRAY') {
14094: push(@okvals,$item);
14095: }
14096: }
14097: } else {
14098: if (ref($by_location{$val}) eq 'ARRAY') {
14099: push(@okvals,$val);
14100: }
14101: }
14102: }
14103: @okvals = sort(@okvals);
14104: if (ref($domconfig{'trust'}) eq 'HASH') {
14105: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
14106: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14107: if ($inuse == 0) {
14108: $changes{$prefix}{$type} = 1;
14109: } else {
14110: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14111: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
14112: if (@changed > 0) {
14113: $changes{$prefix}{$type} = 1;
14114: }
14115: }
14116: } else {
14117: if ($inuse == 1) {
14118: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14119: $changes{$prefix}{$type} = 1;
14120: }
14121: }
14122: } else {
14123: if ($inuse == 1) {
14124: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14125: $changes{$prefix}{$type} = 1;
14126: }
14127: }
14128: } else {
14129: if ($inuse == 1) {
14130: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14131: $changes{$prefix}{$type} = 1;
14132: }
14133: }
14134: }
14135: }
14136: my $nochgmsg = &mt('No changes made to trust settings.');
14137: if (keys(%changes) > 0) {
14138: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14139: $dom);
14140: if ($putresult eq 'ok') {
14141: if (ref($defaultshash{'trust'}) eq 'HASH') {
14142: foreach my $prefix (@prefixes) {
14143: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
14144: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
14145: }
14146: }
14147: }
14148: my $cachetime = 24*60*60;
14149: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14150: if (ref($lastactref) eq 'HASH') {
14151: $lastactref->{'domdefaults'} = 1;
14152: }
14153: if (keys(%changes) > 0) {
14154: my %lt = &trust_titles();
14155: $resulttext = &mt('Changes made:').'<ul>';
14156: foreach my $prefix (@prefixes) {
14157: if (ref($changes{$prefix}) eq 'HASH') {
14158: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14159: foreach my $type (@types) {
14160: if (defined($changes{$prefix}{$type})) {
14161: my $newvalue;
14162: if (ref($defaultshash{'trust'}) eq 'HASH') {
14163: if (ref($defaultshash{'trust'}{$prefix})) {
14164: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14165: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
14166: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
14167: }
14168: }
14169: }
14170: }
14171: if ($newvalue eq '') {
14172: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14173: } else {
14174: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
14175: }
14176: }
14177: }
14178: $resulttext .= '</ul>';
14179: }
14180: }
14181: $resulttext .= '</ul>';
14182: } else {
14183: $resulttext = $nochgmsg;
14184: }
14185: } else {
14186: $resulttext = '<span class="LC_error">'.
14187: &mt('An error occurred: [_1]',$putresult).'</span>';
14188: }
14189: } else {
14190: $resulttext = $nochgmsg;
14191: }
14192: return $resulttext;
14193: }
14194:
1.150 raeburn 14195: sub modify_loadbalancing {
14196: my ($dom,%domconfig) = @_;
14197: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14198: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14199: my ($othertitle,$usertypes,$types) =
14200: &Apache::loncommon::sorted_inst_types($dom);
14201: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 14202: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 14203: my @sparestypes = ('primary','default');
14204: my %typetitles = &sparestype_titles();
14205: my $resulttext;
1.171 raeburn 14206: my (%currbalancer,%currtargets,%currrules,%existing);
14207: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14208: %existing = %{$domconfig{'loadbalancing'}};
14209: }
14210: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
14211: \%currtargets,\%currrules);
14212: my ($saveloadbalancing,%defaultshash,%changes);
14213: my ($alltypes,$othertypes,$titles) =
14214: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14215: my %ruletitles = &offloadtype_text();
14216: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14217: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14218: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14219: if ($balancer eq '') {
14220: next;
14221: }
1.210 raeburn 14222: if (!exists($servers{$balancer})) {
1.171 raeburn 14223: if (exists($currbalancer{$balancer})) {
14224: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14225: }
1.171 raeburn 14226: next;
14227: }
14228: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14229: push(@{$changes{'delete'}},$balancer);
14230: next;
14231: }
14232: if (!exists($currbalancer{$balancer})) {
14233: push(@{$changes{'add'}},$balancer);
14234: }
14235: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14236: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14237: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14238: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14239: $saveloadbalancing = 1;
14240: }
14241: foreach my $sparetype (@sparestypes) {
14242: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14243: my @offloadto;
14244: foreach my $target (@targets) {
14245: if (($servers{$target}) && ($target ne $balancer)) {
14246: if ($sparetype eq 'default') {
14247: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14248: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14249: }
14250: }
1.171 raeburn 14251: unless(grep(/^\Q$target\E$/,@offloadto)) {
14252: push(@offloadto,$target);
14253: }
1.150 raeburn 14254: }
14255: }
1.284 raeburn 14256: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14257: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14258: push(@offloadto,$balancer);
14259: }
14260: }
14261: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14262: }
1.171 raeburn 14263: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14264: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14265: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14266: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14267: if (@targetdiffs > 0) {
1.171 raeburn 14268: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14269: }
1.171 raeburn 14270: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14271: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14272: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14273: }
14274: }
14275: }
14276: } else {
1.171 raeburn 14277: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 14278: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14279: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14280: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14281: $changes{'curr'}{$balancer}{'targets'} = 1;
14282: }
1.150 raeburn 14283: }
14284: }
1.210 raeburn 14285: }
1.150 raeburn 14286: }
14287: my $ishomedom;
1.171 raeburn 14288: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14289: $ishomedom = 1;
1.150 raeburn 14290: }
14291: if (ref($alltypes) eq 'ARRAY') {
14292: foreach my $type (@{$alltypes}) {
14293: my $rule;
1.210 raeburn 14294: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14295: (!$ishomedom)) {
1.171 raeburn 14296: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14297: }
14298: if ($rule eq 'specific') {
1.255 raeburn 14299: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 14300: if (exists($servers{$specifiedhost})) {
1.255 raeburn 14301: $rule = $specifiedhost;
14302: }
1.150 raeburn 14303: }
1.171 raeburn 14304: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14305: if (ref($currrules{$balancer}) eq 'HASH') {
14306: if ($rule ne $currrules{$balancer}{$type}) {
14307: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14308: }
14309: } elsif ($rule ne '') {
1.171 raeburn 14310: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14311: }
14312: }
14313: }
1.171 raeburn 14314: }
14315: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14316: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14317: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14318: $defaultshash{'loadbalancing'} = {};
14319: }
14320: my $putresult = &Apache::lonnet::put_dom('configuration',
14321: \%defaultshash,$dom);
14322: if ($putresult eq 'ok') {
14323: if (keys(%changes) > 0) {
1.252 raeburn 14324: my %toupdate;
1.171 raeburn 14325: if (ref($changes{'delete'}) eq 'ARRAY') {
14326: foreach my $balancer (sort(@{$changes{'delete'}})) {
14327: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 14328: $toupdate{$balancer} = 1;
1.150 raeburn 14329: }
1.171 raeburn 14330: }
14331: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 14332: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 14333: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 14334: $toupdate{$balancer} = 1;
1.171 raeburn 14335: }
14336: }
14337: if (ref($changes{'curr'}) eq 'HASH') {
14338: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 14339: $toupdate{$balancer} = 1;
1.171 raeburn 14340: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14341: if ($changes{'curr'}{$balancer}{'targets'}) {
14342: my %offloadstr;
14343: foreach my $sparetype (@sparestypes) {
14344: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14345: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14346: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14347: }
14348: }
1.150 raeburn 14349: }
1.171 raeburn 14350: if (keys(%offloadstr) == 0) {
14351: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14352: } else {
1.171 raeburn 14353: my $showoffload;
14354: foreach my $sparetype (@sparestypes) {
14355: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14356: if (defined($offloadstr{$sparetype})) {
14357: $showoffload .= $offloadstr{$sparetype};
14358: } else {
14359: $showoffload .= &mt('None');
14360: }
14361: $showoffload .= (' 'x3);
14362: }
14363: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14364: }
14365: }
14366: }
1.171 raeburn 14367: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14368: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14369: foreach my $type (@{$alltypes}) {
14370: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14371: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14372: my $balancetext;
14373: if ($rule eq '') {
14374: $balancetext = $ruletitles{'default'};
1.209 raeburn 14375: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 14376: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 14377: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 14378: foreach my $sparetype (@sparestypes) {
14379: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14380: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14381: }
14382: }
1.253 raeburn 14383: foreach my $item (@{$alltypes}) {
14384: next if ($item =~ /^_LC_ipchange/);
14385: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14386: if ($hasrule eq 'homeserver') {
14387: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14388: } else {
14389: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14390: if ($servers{$hasrule}) {
14391: $toupdate{$hasrule} = 1;
14392: }
14393: }
14394: }
14395: }
1.254 raeburn 14396: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14397: $balancetext = $ruletitles{$rule};
14398: } else {
14399: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14400: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14401: if ($receiver) {
14402: $toupdate{$receiver};
14403: }
14404: }
14405: } else {
14406: $balancetext = $ruletitles{$rule};
1.252 raeburn 14407: }
1.171 raeburn 14408: } else {
14409: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14410: }
1.210 raeburn 14411: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14412: }
14413: }
14414: }
14415: }
1.252 raeburn 14416: if (keys(%toupdate)) {
14417: my %thismachine;
14418: my $updatedhere;
14419: my $cachetime = 60*60*24;
14420: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14421: foreach my $lonhost (keys(%toupdate)) {
14422: if ($thismachine{$lonhost}) {
14423: unless ($updatedhere) {
14424: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14425: $defaultshash{'loadbalancing'},
14426: $cachetime);
14427: $updatedhere = 1;
14428: }
14429: } else {
14430: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14431: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14432: }
14433: }
14434: }
1.150 raeburn 14435: }
1.171 raeburn 14436: }
14437: if ($resulttext ne '') {
14438: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14439: } else {
14440: $resulttext = $nochgmsg;
14441: }
14442: } else {
1.171 raeburn 14443: $resulttext = $nochgmsg;
1.150 raeburn 14444: }
14445: } else {
1.171 raeburn 14446: $resulttext = '<span class="LC_error">'.
14447: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14448: }
14449: } else {
1.171 raeburn 14450: $resulttext = $nochgmsg;
1.150 raeburn 14451: }
14452: return $resulttext;
14453: }
14454:
1.48 raeburn 14455: sub recurse_check {
14456: my ($chkcats,$categories,$depth,$name) = @_;
14457: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14458: my $chg = 0;
14459: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14460: my $category = $chkcats->[$depth]{$name}[$j];
14461: my $item;
14462: if ($category eq '') {
14463: $chg ++;
14464: } else {
14465: my $deeper = $depth + 1;
14466: $item = &escape($category).':'.&escape($name).':'.$depth;
14467: if ($chg) {
14468: $categories->{$item} -= $chg;
14469: }
14470: &recurse_check($chkcats,$categories,$deeper,$category);
14471: $deeper --;
14472: }
14473: }
14474: }
14475: return;
14476: }
14477:
14478: sub recurse_cat_deletes {
14479: my ($item,$coursecategories,$deletions) = @_;
14480: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14481: my $subdepth = $depth + 1;
14482: if (ref($coursecategories) eq 'HASH') {
14483: foreach my $subitem (keys(%{$coursecategories})) {
14484: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14485: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14486: delete($coursecategories->{$subitem});
14487: $deletions->{$subitem} = 1;
14488: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 14489: }
1.48 raeburn 14490: }
14491: }
14492: return;
14493: }
14494:
1.125 raeburn 14495: sub active_dc_picker {
1.191 raeburn 14496: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 14497: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 14498: my @domcoord = keys(%domcoords);
14499: if (keys(%currhash)) {
14500: foreach my $dc (keys(%currhash)) {
14501: unless (exists($domcoords{$dc})) {
14502: push(@domcoord,$dc);
14503: }
14504: }
14505: }
14506: @domcoord = sort(@domcoord);
1.210 raeburn 14507: my $numdcs = scalar(@domcoord);
1.191 raeburn 14508: my $rows = 0;
14509: my $table;
1.125 raeburn 14510: if ($numdcs > 1) {
1.191 raeburn 14511: $table = '<table>';
14512: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14513: my $rem = $i%($numinrow);
14514: if ($rem == 0) {
14515: if ($i > 0) {
1.191 raeburn 14516: $table .= '</tr>';
1.125 raeburn 14517: }
1.191 raeburn 14518: $table .= '<tr>';
14519: $rows ++;
1.125 raeburn 14520: }
1.191 raeburn 14521: my $check = '';
14522: if ($inputtype eq 'radio') {
14523: if (keys(%currhash) == 0) {
14524: if (!$i) {
14525: $check = ' checked="checked"';
14526: }
14527: } elsif (exists($currhash{$domcoord[$i]})) {
14528: $check = ' checked="checked"';
14529: }
14530: } else {
14531: if (exists($currhash{$domcoord[$i]})) {
14532: $check = ' checked="checked"';
1.125 raeburn 14533: }
14534: }
1.191 raeburn 14535: if ($i == @domcoord - 1) {
1.125 raeburn 14536: my $colsleft = $numinrow - $rem;
14537: if ($colsleft > 1) {
1.191 raeburn 14538: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14539: } else {
1.191 raeburn 14540: $table .= '<td class="LC_left_item">';
1.125 raeburn 14541: }
14542: } else {
1.191 raeburn 14543: $table .= '<td class="LC_left_item">';
14544: }
14545: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14546: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14547: $table .= '<span class="LC_nobreak"><label>'.
14548: '<input type="'.$inputtype.'" name="'.$name.'"'.
14549: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14550: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 14551: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 14552: }
1.219 raeburn 14553: $table .= '</label></span></td>';
1.191 raeburn 14554: }
14555: $table .= '</tr></table>';
14556: } elsif ($numdcs == 1) {
1.219 raeburn 14557: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14558: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 14559: if ($inputtype eq 'radio') {
1.247 raeburn 14560: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 14561: if ($user ne $dcname.':'.$dcdom) {
14562: $table .= ' ('.$dcname.':'.$dcdom.')';
14563: }
1.191 raeburn 14564: } else {
14565: my $check;
14566: if (exists($currhash{$domcoord[0]})) {
14567: $check = ' checked="checked"';
1.125 raeburn 14568: }
1.247 raeburn 14569: $table = '<span class="LC_nobreak"><label>'.
14570: '<input type="checkbox" name="'.$name.'" '.
14571: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 14572: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 14573: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 14574: }
1.220 raeburn 14575: $table .= '</label></span>';
1.191 raeburn 14576: $rows ++;
1.125 raeburn 14577: }
14578: }
1.191 raeburn 14579: return ($numdcs,$table,$rows);
1.125 raeburn 14580: }
14581:
1.137 raeburn 14582: sub usersession_titles {
14583: return &Apache::lonlocal::texthash(
14584: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14585: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14586: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14587: version => 'LON-CAPA version requirement',
1.138 raeburn 14588: excludedomain => 'Allow all, but exclude specific domains',
14589: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14590: primary => 'Primary (checked first)',
1.154 raeburn 14591: default => 'Default',
1.137 raeburn 14592: );
14593: }
14594:
1.152 raeburn 14595: sub id_for_thisdom {
14596: my (%servers) = @_;
14597: my %altids;
14598: foreach my $server (keys(%servers)) {
14599: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14600: if ($serverhome ne $server) {
14601: $altids{$serverhome} = $server;
14602: }
14603: }
14604: return %altids;
14605: }
14606:
1.150 raeburn 14607: sub count_servers {
14608: my ($currbalancer,%servers) = @_;
14609: my (@spares,$numspares);
14610: foreach my $lonhost (sort(keys(%servers))) {
14611: next if ($currbalancer eq $lonhost);
14612: push(@spares,$lonhost);
14613: }
14614: if ($currbalancer) {
14615: $numspares = scalar(@spares);
14616: } else {
14617: $numspares = scalar(@spares) - 1;
14618: }
14619: return ($numspares,@spares);
14620: }
14621:
14622: sub lonbalance_targets_js {
1.171 raeburn 14623: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14624: my $select = &mt('Select');
14625: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14626: if (ref($servers) eq 'HASH') {
14627: $alltargets = join("','",sort(keys(%{$servers})));
14628: my @homedoms;
14629: foreach my $server (sort(keys(%{$servers}))) {
14630: if (&Apache::lonnet::host_domain($server) eq $dom) {
14631: push(@homedoms,'1');
14632: } else {
14633: push(@homedoms,'0');
14634: }
14635: }
14636: $allishome = join("','",@homedoms);
14637: }
14638: if (ref($types) eq 'ARRAY') {
14639: if (@{$types} > 0) {
14640: @alltypes = @{$types};
14641: }
14642: }
14643: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14644: $allinsttypes = join("','",@alltypes);
1.171 raeburn 14645: my (%currbalancer,%currtargets,%currrules,%existing);
14646: if (ref($settings) eq 'HASH') {
14647: %existing = %{$settings};
14648: }
14649: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14650: \%currtargets,\%currrules);
1.210 raeburn 14651: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14652: return <<"END";
14653:
14654: <script type="text/javascript">
14655: // <![CDATA[
14656:
1.171 raeburn 14657: currBalancers = new Array('$balancers');
14658:
14659: function toggleTargets(balnum) {
14660: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14661: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14662: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14663: var prevbalancer = prevhostitem.value;
14664: var baltotal = document.getElementById('loadbalancing_total').value;
14665: prevhostitem.value = balancer;
14666: if (prevbalancer != '') {
14667: var prevIdx = currBalancers.indexOf(prevbalancer);
14668: if (prevIdx != -1) {
14669: currBalancers.splice(prevIdx,1);
14670: }
14671: }
1.150 raeburn 14672: if (balancer == '') {
1.171 raeburn 14673: hideSpares(balnum);
1.150 raeburn 14674: } else {
1.171 raeburn 14675: var currIdx = currBalancers.indexOf(balancer);
14676: if (currIdx == -1) {
14677: currBalancers.push(balancer);
14678: }
1.150 raeburn 14679: var homedoms = new Array('$allishome');
1.171 raeburn 14680: var ishomedom = homedoms[lonhostitem.selectedIndex];
14681: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14682: }
1.171 raeburn 14683: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14684: return;
14685: }
14686:
1.171 raeburn 14687: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14688: var alltargets = new Array('$alltargets');
14689: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14690: var offloadtypes = new Array('primary','default');
14691:
1.171 raeburn 14692: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14693: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14694:
1.151 raeburn 14695: for (var i=0; i<offloadtypes.length; i++) {
14696: var count = 0;
14697: for (var j=0; j<alltargets.length; j++) {
14698: if (alltargets[j] != balancer) {
1.171 raeburn 14699: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14700: item.value = alltargets[j];
14701: item.style.textAlign='left';
14702: item.style.textFace='normal';
14703: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14704: if (currBalancers.indexOf(alltargets[j]) == -1) {
14705: item.disabled = '';
14706: } else {
14707: item.disabled = 'disabled';
14708: item.checked = false;
14709: }
1.151 raeburn 14710: count ++;
14711: }
1.150 raeburn 14712: }
14713: }
1.151 raeburn 14714: for (var k=0; k<insttypes.length; k++) {
14715: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14716: if (ishomedom == 1) {
1.171 raeburn 14717: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14718: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14719: } else {
1.171 raeburn 14720: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14721: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14722: }
14723: } else {
1.171 raeburn 14724: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14725: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14726: }
1.151 raeburn 14727: if ((insttypes[k] != '_LC_external') &&
14728: ((insttypes[k] != '_LC_internetdom') ||
14729: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 14730: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14731: item.options.length = 0;
14732: item.options[0] = new Option("","",true,true);
1.210 raeburn 14733: var idx = 0;
1.151 raeburn 14734: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 14735: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14736: idx ++;
14737: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14738: }
14739: }
14740: }
14741: }
14742: return;
14743: }
14744:
1.171 raeburn 14745: function hideSpares(balnum) {
1.150 raeburn 14746: var alltargets = new Array('$alltargets');
14747: var insttypes = new Array('$allinsttypes');
14748: var offloadtypes = new Array('primary','default');
14749:
1.171 raeburn 14750: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14751: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14752:
14753: var total = alltargets.length - 1;
14754: for (var i=0; i<offloadtypes; i++) {
14755: for (var j=0; j<total; j++) {
1.171 raeburn 14756: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14757: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14758: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14759: }
1.150 raeburn 14760: }
14761: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 14762: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14763: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14764: if (insttypes[k] != '_LC_external') {
1.171 raeburn 14765: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14766: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14767: }
14768: }
14769: return;
14770: }
14771:
1.171 raeburn 14772: function checkOffloads(item,balnum,type) {
1.150 raeburn 14773: var alltargets = new Array('$alltargets');
14774: var offloadtypes = new Array('primary','default');
14775: if (item.checked) {
14776: var total = alltargets.length - 1;
14777: var other;
14778: if (type == offloadtypes[0]) {
1.151 raeburn 14779: other = offloadtypes[1];
1.150 raeburn 14780: } else {
1.151 raeburn 14781: other = offloadtypes[0];
1.150 raeburn 14782: }
14783: for (var i=0; i<total; i++) {
1.171 raeburn 14784: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14785: if (server == item.value) {
1.171 raeburn 14786: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14787: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14788: }
14789: }
14790: }
14791: }
14792: return;
14793: }
14794:
1.171 raeburn 14795: function singleServerToggle(balnum,type) {
14796: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 14797: if (offloadtoSelIdx == 0) {
1.171 raeburn 14798: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14799: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14800:
14801: } else {
1.171 raeburn 14802: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14803: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 14804: }
14805: return;
14806: }
14807:
1.171 raeburn 14808: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 14809: if (type == '_LC_external') {
1.171 raeburn 14810: return;
1.150 raeburn 14811: }
1.171 raeburn 14812: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 14813: for (var i=0; i<typesRules.length; i++) {
14814: if (formname.elements[typesRules[i]].checked) {
14815: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 14816: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14817: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14818: } else {
1.171 raeburn 14819: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14820: }
14821: }
14822: }
14823: return;
14824: }
14825:
14826: function balancerDeleteChange(balnum) {
14827: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14828: var baltotal = document.getElementById('loadbalancing_total').value;
14829: var addtarget;
14830: var removetarget;
14831: var action = 'delete';
14832: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14833: var lonhost = hostitem.value;
14834: var currIdx = currBalancers.indexOf(lonhost);
14835: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14836: if (currIdx != -1) {
14837: currBalancers.splice(currIdx,1);
14838: }
14839: addtarget = lonhost;
14840: } else {
14841: if (currIdx == -1) {
14842: currBalancers.push(lonhost);
14843: }
14844: removetarget = lonhost;
14845: action = 'undelete';
14846: }
14847: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14848: }
14849: return;
14850: }
14851:
14852: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14853: if (baltotal > 1) {
14854: var offloadtypes = new Array('primary','default');
14855: var alltargets = new Array('$alltargets');
14856: var insttypes = new Array('$allinsttypes');
14857: for (var i=0; i<baltotal; i++) {
14858: if (i != balnum) {
14859: for (var j=0; j<offloadtypes.length; j++) {
14860: var total = alltargets.length - 1;
14861: for (var k=0; k<total; k++) {
14862: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14863: var server = serveritem.value;
14864: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14865: if (server == addtarget) {
14866: serveritem.disabled = '';
14867: }
14868: }
14869: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14870: if (server == removetarget) {
14871: serveritem.disabled = 'disabled';
14872: serveritem.checked = false;
14873: }
14874: }
14875: }
14876: }
14877: for (var j=0; j<insttypes.length; j++) {
14878: if (insttypes[j] != '_LC_external') {
14879: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14880: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14881: var currSel = singleserver.selectedIndex;
14882: var currVal = singleserver.options[currSel].value;
14883: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14884: var numoptions = singleserver.options.length;
14885: var needsnew = 1;
14886: for (var k=0; k<numoptions; k++) {
14887: if (singleserver.options[k] == addtarget) {
14888: needsnew = 0;
14889: break;
14890: }
14891: }
14892: if (needsnew == 1) {
14893: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14894: }
14895: }
14896: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14897: singleserver.options.length = 0;
14898: if ((currVal) && (currVal != removetarget)) {
14899: singleserver.options[0] = new Option("","",false,false);
14900: } else {
14901: singleserver.options[0] = new Option("","",true,true);
14902: }
14903: var idx = 0;
14904: for (var m=0; m<alltargets.length; m++) {
14905: if (currBalancers.indexOf(alltargets[m]) == -1) {
14906: idx ++;
14907: if (currVal == alltargets[m]) {
14908: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
14909: } else {
14910: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
14911: }
14912: }
14913: }
14914: }
14915: }
14916: }
14917: }
1.150 raeburn 14918: }
14919: }
14920: }
14921: return;
14922: }
14923:
1.152 raeburn 14924: // ]]>
14925: </script>
14926:
14927: END
14928: }
14929:
14930: sub new_spares_js {
14931: my @sparestypes = ('primary','default');
14932: my $types = join("','",@sparestypes);
14933: my $select = &mt('Select');
14934: return <<"END";
14935:
14936: <script type="text/javascript">
14937: // <![CDATA[
14938:
14939: function updateNewSpares(formname,lonhost) {
14940: var types = new Array('$types');
14941: var include = new Array();
14942: var exclude = new Array();
14943: for (var i=0; i<types.length; i++) {
14944: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
14945: for (var j=0; j<spareboxes.length; j++) {
14946: if (formname.elements[spareboxes[j]].checked) {
14947: exclude.push(formname.elements[spareboxes[j]].value);
14948: } else {
14949: include.push(formname.elements[spareboxes[j]].value);
14950: }
14951: }
14952: }
14953: for (var i=0; i<types.length; i++) {
14954: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
14955: var selIdx = newSpare.selectedIndex;
14956: var currnew = newSpare.options[selIdx].value;
14957: var okSpares = new Array();
14958: for (var j=0; j<newSpare.options.length; j++) {
14959: var possible = newSpare.options[j].value;
14960: if (possible != '') {
14961: if (exclude.indexOf(possible) == -1) {
14962: okSpares.push(possible);
14963: } else {
14964: if (currnew == possible) {
14965: selIdx = 0;
14966: }
14967: }
14968: }
14969: }
14970: for (var k=0; k<include.length; k++) {
14971: if (okSpares.indexOf(include[k]) == -1) {
14972: okSpares.push(include[k]);
14973: }
14974: }
14975: okSpares.sort();
14976: newSpare.options.length = 0;
14977: if (selIdx == 0) {
14978: newSpare.options[0] = new Option("$select","",true,true);
14979: } else {
14980: newSpare.options[0] = new Option("$select","",false,false);
14981: }
14982: for (var m=0; m<okSpares.length; m++) {
14983: var idx = m+1;
14984: var selThis = 0;
14985: if (selIdx != 0) {
14986: if (okSpares[m] == currnew) {
14987: selThis = 1;
14988: }
14989: }
14990: if (selThis == 1) {
14991: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
14992: } else {
14993: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
14994: }
14995: }
14996: }
14997: return;
14998: }
14999:
15000: function checkNewSpares(lonhost,type) {
15001: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15002: var chosen = newSpare.options[newSpare.selectedIndex].value;
15003: if (chosen != '') {
15004: var othertype;
15005: var othernewSpare;
15006: if (type == 'primary') {
15007: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15008: }
15009: if (type == 'default') {
15010: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15011: }
15012: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15013: othernewSpare.selectedIndex = 0;
15014: }
15015: }
15016: return;
15017: }
15018:
15019: // ]]>
15020: </script>
15021:
15022: END
15023:
15024: }
15025:
15026: sub common_domprefs_js {
15027: return <<"END";
15028:
15029: <script type="text/javascript">
15030: // <![CDATA[
15031:
1.150 raeburn 15032: function getIndicesByName(formname,item) {
1.152 raeburn 15033: var group = new Array();
1.150 raeburn 15034: for (var i=0;i<formname.elements.length;i++) {
15035: if (formname.elements[i].name == item) {
1.152 raeburn 15036: group.push(formname.elements[i].id);
1.150 raeburn 15037: }
15038: }
1.152 raeburn 15039: return group;
1.150 raeburn 15040: }
15041:
15042: // ]]>
15043: </script>
15044:
15045: END
1.152 raeburn 15046:
1.150 raeburn 15047: }
15048:
1.165 raeburn 15049: sub recaptcha_js {
15050: my %lt = &captcha_phrases();
15051: return <<"END";
15052:
15053: <script type="text/javascript">
15054: // <![CDATA[
15055:
15056: function updateCaptcha(caller,context) {
15057: var privitem;
15058: var pubitem;
15059: var privtext;
15060: var pubtext;
1.269 raeburn 15061: var versionitem;
15062: var versiontext;
1.165 raeburn 15063: if (document.getElementById(context+'_recaptchapub')) {
15064: pubitem = document.getElementById(context+'_recaptchapub');
15065: } else {
15066: return;
15067: }
15068: if (document.getElementById(context+'_recaptchapriv')) {
15069: privitem = document.getElementById(context+'_recaptchapriv');
15070: } else {
15071: return;
15072: }
15073: if (document.getElementById(context+'_recaptchapubtxt')) {
15074: pubtext = document.getElementById(context+'_recaptchapubtxt');
15075: } else {
15076: return;
15077: }
15078: if (document.getElementById(context+'_recaptchaprivtxt')) {
15079: privtext = document.getElementById(context+'_recaptchaprivtxt');
15080: } else {
15081: return;
15082: }
1.269 raeburn 15083: if (document.getElementById(context+'_recaptchaversion')) {
15084: versionitem = document.getElementById(context+'_recaptchaversion');
15085: } else {
15086: return;
15087: }
15088: if (document.getElementById(context+'_recaptchavertxt')) {
15089: versiontext = document.getElementById(context+'_recaptchavertxt');
15090: } else {
15091: return;
15092: }
1.165 raeburn 15093: if (caller.checked) {
15094: if (caller.value == 'recaptcha') {
15095: pubitem.type = 'text';
15096: privitem.type = 'text';
15097: pubitem.size = '40';
15098: privitem.size = '40';
15099: pubtext.innerHTML = "$lt{'pub'}";
15100: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 15101: versionitem.type = 'text';
15102: versionitem.size = '3';
1.289 raeburn 15103: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 15104: } else {
15105: pubitem.type = 'hidden';
15106: privitem.type = 'hidden';
1.269 raeburn 15107: versionitem.type = 'hidden';
1.165 raeburn 15108: pubtext.innerHTML = '';
15109: privtext.innerHTML = '';
1.269 raeburn 15110: versiontext.innerHTML = '';
1.165 raeburn 15111: }
15112: }
15113: return;
15114: }
15115:
15116: // ]]>
15117: </script>
15118:
15119: END
15120:
15121: }
15122:
1.236 raeburn 15123: sub toggle_display_js {
1.192 raeburn 15124: return <<"END";
15125:
15126: <script type="text/javascript">
15127: // <![CDATA[
15128:
1.236 raeburn 15129: function toggleDisplay(domForm,caller) {
15130: if (document.getElementById(caller)) {
15131: var divitem = document.getElementById(caller);
15132: var optionsElement = domForm.coursecredits;
1.264 raeburn 15133: var checkval = 1;
15134: var dispval = 'block';
1.236 raeburn 15135: if (caller == 'emailoptions') {
15136: optionsElement = domForm.cancreate_email;
15137: }
1.257 raeburn 15138: if (caller == 'studentsubmission') {
15139: optionsElement = domForm.postsubmit;
15140: }
1.264 raeburn 15141: if (caller == 'cloneinstcode') {
15142: optionsElement = domForm.canclone;
15143: checkval = 'instcode';
15144: }
1.236 raeburn 15145: if (optionsElement.length) {
1.192 raeburn 15146: var currval;
1.236 raeburn 15147: for (var i=0; i<optionsElement.length; i++) {
15148: if (optionsElement[i].checked) {
15149: currval = optionsElement[i].value;
1.192 raeburn 15150: }
15151: }
1.264 raeburn 15152: if (currval == checkval) {
15153: divitem.style.display = dispval;
1.192 raeburn 15154: } else {
1.236 raeburn 15155: divitem.style.display = 'none';
1.192 raeburn 15156: }
15157: }
15158: }
15159: return;
15160: }
15161:
15162: // ]]>
15163: </script>
15164:
15165: END
15166:
15167: }
15168:
1.165 raeburn 15169: sub captcha_phrases {
15170: return &Apache::lonlocal::texthash (
15171: priv => 'Private key',
15172: pub => 'Public key',
15173: original => 'original (CAPTCHA)',
15174: recaptcha => 'successor (ReCAPTCHA)',
15175: notused => 'unused',
1.289 raeburn 15176: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 15177: );
15178: }
15179:
1.205 raeburn 15180: sub devalidate_remote_domconfs {
1.212 raeburn 15181: my ($dom,$cachekeys) = @_;
15182: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 15183: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15184: my %thismachine;
15185: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267 raeburn 15186: my @posscached = ('domainconfig','domdefaults','ltitools');
1.260 raeburn 15187: if (keys(%servers)) {
1.205 raeburn 15188: foreach my $server (keys(%servers)) {
15189: next if ($thismachine{$server});
1.212 raeburn 15190: my @cached;
15191: foreach my $name (@posscached) {
15192: if ($cachekeys->{$name}) {
15193: push(@cached,&escape($name).':'.&escape($dom));
15194: }
15195: }
15196: if (@cached) {
15197: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15198: }
1.205 raeburn 15199: }
15200: }
15201: return;
15202: }
15203:
1.3 raeburn 15204: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>