Annotation of loncom/interface/domainprefs.pm, revision 1.295
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.295 ! raeburn 4: # $Id: domainprefs.pm,v 1.294 2017/03/13 18:30:07 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') {
1.295 ! raeburn 680: $output = &modify_directorysrch($dom,$lastactref,%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.'"'.
1.295 ! raeburn 4264: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 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 {
1.295 ! raeburn 10336: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 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>';
1.295 ! raeburn 10530: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
! 10531: if (ref($lastactref) eq 'HASH') {
! 10532: $lastactref->{'directorysrch'} = 1;
! 10533: }
1.23 raeburn 10534: } else {
1.277 raeburn 10535: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10536: }
10537: } else {
10538: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10539: &mt('An error occurred: [_1]',$putresult).'</span>';
10540: }
10541: return $resulttext;
10542: }
10543:
1.28 raeburn 10544: sub modify_contacts {
1.205 raeburn 10545: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10546: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10547: if (ref($domconfig{'contacts'}) eq 'HASH') {
10548: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10549: $currsetting{$key} = $domconfig{'contacts'}{$key};
10550: }
10551: }
1.286 raeburn 10552: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10553: my @contacts = ('supportemail','adminemail');
1.286 raeburn 10554: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10555: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 10556: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 10557: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10558: foreach my $type (@mailings) {
10559: @{$newsetting{$type}} =
10560: &Apache::loncommon::get_env_multiple('form.'.$type);
10561: foreach my $item (@contacts) {
10562: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10563: $contacts_hash{contacts}{$type}{$item} = 1;
10564: } else {
10565: $contacts_hash{contacts}{$type}{$item} = 0;
10566: }
1.289 raeburn 10567: }
1.28 raeburn 10568: $others{$type} = $env{'form.'.$type.'_others'};
10569: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 10570: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10571: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10572: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 10573: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10574: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10575: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10576: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10577: }
1.134 raeburn 10578: }
1.28 raeburn 10579: }
10580: foreach my $item (@contacts) {
10581: $to{$item} = $env{'form.'.$item};
10582: $contacts_hash{'contacts'}{$item} = $to{$item};
10583: }
1.203 raeburn 10584: foreach my $item (@toggles) {
10585: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10586: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10587: }
10588: }
1.286 raeburn 10589: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10590: foreach my $field (@{$fields}) {
10591: if (ref($possoptions->{$field}) eq 'ARRAY') {
10592: my $value = $env{'form.helpform_'.$field};
10593: $value =~ s/^\s+|\s+$//g;
10594: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10595: $contacts_hash{contacts}{'helpform'}{$field} = $value;
10596: if ($field eq 'screenshot') {
10597: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10598: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10599: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10600: }
10601: }
10602: }
10603: }
10604: }
10605: }
1.28 raeburn 10606: if (keys(%currsetting) > 0) {
10607: foreach my $item (@contacts) {
10608: if ($to{$item} ne $currsetting{$item}) {
10609: $changes{$item} = 1;
10610: }
10611: }
10612: foreach my $type (@mailings) {
10613: foreach my $item (@contacts) {
10614: if (ref($currsetting{$type}) eq 'HASH') {
10615: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10616: push(@{$changes{$type}},$item);
10617: }
10618: } else {
10619: push(@{$changes{$type}},@{$newsetting{$type}});
10620: }
10621: }
10622: if ($others{$type} ne $currsetting{$type}{'others'}) {
10623: push(@{$changes{$type}},'others');
10624: }
1.289 raeburn 10625: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10626: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10627: push(@{$changes{$type}},'bcc');
10628: }
1.286 raeburn 10629: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10630: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10631: push(@{$changes{$type}},'include');
10632: }
10633: }
10634: }
10635: if (ref($fields) eq 'ARRAY') {
10636: if (ref($currsetting{'helpform'}) eq 'HASH') {
10637: foreach my $field (@{$fields}) {
10638: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10639: push(@{$changes{'helpform'}},$field);
10640: }
10641: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10642: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10643: push(@{$changes{'helpform'}},'maxsize');
10644: }
10645: }
10646: }
10647: } else {
10648: foreach my $field (@{$fields}) {
10649: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10650: push(@{$changes{'helpform'}},$field);
10651: }
10652: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10653: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10654: push(@{$changes{'helpform'}},'maxsize');
10655: }
10656: }
10657: }
1.134 raeburn 10658: }
1.28 raeburn 10659: }
10660: } else {
10661: my %default;
10662: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10663: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10664: $default{'errormail'} = 'adminemail';
10665: $default{'packagesmail'} = 'adminemail';
10666: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 10667: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10668: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10669: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 10670: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 10671: foreach my $item (@contacts) {
10672: if ($to{$item} ne $default{$item}) {
1.286 raeburn 10673: $changes{$item} = 1;
1.203 raeburn 10674: }
1.28 raeburn 10675: }
10676: foreach my $type (@mailings) {
10677: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10678: push(@{$changes{$type}},@{$newsetting{$type}});
10679: }
10680: if ($others{$type} ne '') {
10681: push(@{$changes{$type}},'others');
1.134 raeburn 10682: }
1.286 raeburn 10683: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10684: if ($bcc{$type} ne '') {
10685: push(@{$changes{$type}},'bcc');
10686: }
1.286 raeburn 10687: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10688: push(@{$changes{$type}},'include');
10689: }
1.134 raeburn 10690: }
1.28 raeburn 10691: }
1.286 raeburn 10692: if (ref($fields) eq 'ARRAY') {
10693: foreach my $field (@{$fields}) {
10694: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10695: push(@{$changes{'helpform'}},$field);
10696: }
10697: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10698: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10699: push(@{$changes{'helpform'}},'maxsize');
10700: }
10701: }
10702: }
1.289 raeburn 10703: }
1.28 raeburn 10704: }
1.203 raeburn 10705: foreach my $item (@toggles) {
10706: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10707: $changes{$item} = 1;
10708: } elsif ((!$env{'form.'.$item}) &&
10709: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10710: $changes{$item} = 1;
10711: }
10712: }
1.28 raeburn 10713: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10714: $dom);
10715: if ($putresult eq 'ok') {
10716: if (keys(%changes) > 0) {
1.205 raeburn 10717: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10718: if (ref($lastactref) eq 'HASH') {
10719: $lastactref->{'domainconfig'} = 1;
10720: }
1.28 raeburn 10721: my ($titles,$short_titles) = &contact_titles();
10722: $resulttext = &mt('Changes made:').'<ul>';
10723: foreach my $item (@contacts) {
10724: if ($changes{$item}) {
10725: $resulttext .= '<li>'.$titles->{$item}.
10726: &mt(' set to: ').
10727: '<span class="LC_cusr_emph">'.
10728: $to{$item}.'</span></li>';
10729: }
10730: }
10731: foreach my $type (@mailings) {
10732: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 10733: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 10734: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 10735: } else {
10736: $resulttext .= '<li>'.$titles->{$type}.': ';
10737: }
1.28 raeburn 10738: my @text;
10739: foreach my $item (@{$newsetting{$type}}) {
10740: push(@text,$short_titles->{$item});
10741: }
10742: if ($others{$type} ne '') {
10743: push(@text,$others{$type});
10744: }
1.286 raeburn 10745: if (@text) {
10746: $resulttext .= '<span class="LC_cusr_emph">'.
10747: join(', ',@text).'</span>';
10748: }
10749: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10750: if ($bcc{$type} ne '') {
1.286 raeburn 10751: my $bcctext;
10752: if (@text) {
1.289 raeburn 10753: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 10754: } else {
10755: $bcctext = '(Bcc)';
10756: }
10757: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10758: } elsif (!@text) {
10759: $resulttext .= &mt('No one');
10760: }
1.289 raeburn 10761: if ($includestr{$type} ne '') {
1.286 raeburn 10762: if ($includeloc{$type} eq 'b') {
10763: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10764: } elsif ($includeloc{$type} eq 's') {
10765: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10766: }
1.134 raeburn 10767: }
1.286 raeburn 10768: } elsif (!@text) {
10769: $resulttext .= &mt('No recipients');
1.134 raeburn 10770: }
10771: $resulttext .= '</li>';
1.28 raeburn 10772: }
10773: }
1.203 raeburn 10774: my @offon = ('off','on');
10775: if ($changes{'reporterrors'}) {
10776: $resulttext .= '<li>'.
10777: &mt('E-mail error reports to [_1] set to "'.
10778: $offon[$env{'form.reporterrors'}].'".',
10779: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10780: &mt('LON-CAPA core group - MSU'),600,500)).
10781: '</li>';
10782: }
10783: if ($changes{'reportupdates'}) {
10784: $resulttext .= '<li>'.
10785: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10786: $offon[$env{'form.reportupdates'}].'".',
10787: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10788: &mt('LON-CAPA core group - MSU'),600,500)).
10789: '</li>';
10790: }
1.286 raeburn 10791: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10792: my (@optional,@required,@unused,$maxsizechg);
10793: foreach my $field (@{$changes{'helpform'}}) {
10794: if ($field eq 'maxsize') {
10795: $maxsizechg = 1;
10796: next;
10797: }
10798: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 10799: push(@optional,$field);
1.286 raeburn 10800: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10801: push(@unused,$field);
10802: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 10803: push(@required,$field);
1.286 raeburn 10804: }
10805: }
10806: if (@optional) {
10807: $resulttext .= '<li>'.
10808: &mt('Help form fields changed to "Optional": [_1].',
10809: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10810: '</li>';
10811: }
10812: if (@required) {
10813: $resulttext .= '<li>'.
10814: &mt('Help form fields changed to "Required": [_1].',
10815: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10816: '</li>';
10817: }
10818: if (@unused) {
10819: $resulttext .= '<li>'.
10820: &mt('Help form fields changed to "Not shown": [_1].',
10821: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10822: '</li>';
10823: }
10824: if ($maxsizechg) {
10825: $resulttext .= '<li>'.
10826: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10827: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10828: '</li>';
10829:
10830: }
10831: }
1.28 raeburn 10832: $resulttext .= '</ul>';
10833: } else {
1.288 raeburn 10834: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10835: }
10836: } else {
10837: $resulttext = '<span class="LC_error">'.
10838: &mt('An error occurred: [_1].',$putresult).'</span>';
10839: }
10840: return $resulttext;
10841: }
10842:
10843: sub modify_usercreation {
1.27 raeburn 10844: my ($dom,%domconfig) = @_;
1.224 raeburn 10845: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 10846: my $warningmsg;
1.27 raeburn 10847: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10848: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 10849: if ($key eq 'cancreate') {
10850: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10851: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10852: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 10853: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10854: ($item eq 'recaptchaversion')) {
1.224 raeburn 10855: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10856: } else {
10857: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10858: }
10859: }
10860: }
10861: } elsif ($key eq 'email_rule') {
10862: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10863: } else {
10864: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10865: }
1.27 raeburn 10866: }
10867: }
10868: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 10869: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 10870: my @contexts = ('author','course','requestcrs');
1.34 raeburn 10871: foreach my $item(@contexts) {
1.224 raeburn 10872: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 10873: }
1.34 raeburn 10874: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10875: foreach my $item (@contexts) {
1.224 raeburn 10876: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10877: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 10878: }
1.27 raeburn 10879: }
1.34 raeburn 10880: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10881: foreach my $item (@contexts) {
1.43 raeburn 10882: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10883: if ($cancreate{$item} ne 'any') {
10884: push(@{$changes{'cancreate'}},$item);
10885: }
10886: } else {
10887: if ($cancreate{$item} ne 'none') {
10888: push(@{$changes{'cancreate'}},$item);
10889: }
1.27 raeburn 10890: }
10891: }
10892: } else {
1.43 raeburn 10893: foreach my $item (@contexts) {
1.34 raeburn 10894: push(@{$changes{'cancreate'}},$item);
10895: }
1.27 raeburn 10896: }
1.34 raeburn 10897:
1.27 raeburn 10898: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10899: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10900: if (!grep(/^\Q$type\E$/,@username_rule)) {
10901: push(@{$changes{'username_rule'}},$type);
10902: }
10903: }
10904: foreach my $type (@username_rule) {
10905: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10906: push(@{$changes{'username_rule'}},$type);
10907: }
10908: }
10909: } else {
10910: push(@{$changes{'username_rule'}},@username_rule);
10911: }
10912:
1.32 raeburn 10913: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10914: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10915: if (!grep(/^\Q$type\E$/,@id_rule)) {
10916: push(@{$changes{'id_rule'}},$type);
10917: }
10918: }
10919: foreach my $type (@id_rule) {
10920: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10921: push(@{$changes{'id_rule'}},$type);
10922: }
10923: }
10924: } else {
10925: push(@{$changes{'id_rule'}},@id_rule);
10926: }
10927:
1.43 raeburn 10928: my @authen_contexts = ('author','course','domain');
1.28 raeburn 10929: my @authtypes = ('int','krb4','krb5','loc');
10930: my %authhash;
1.43 raeburn 10931: foreach my $item (@authen_contexts) {
1.28 raeburn 10932: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
10933: foreach my $auth (@authtypes) {
10934: if (grep(/^\Q$auth\E$/,@authallowed)) {
10935: $authhash{$item}{$auth} = 1;
10936: } else {
10937: $authhash{$item}{$auth} = 0;
10938: }
10939: }
10940: }
10941: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 10942: foreach my $item (@authen_contexts) {
1.28 raeburn 10943: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10944: foreach my $auth (@authtypes) {
10945: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10946: push(@{$changes{'authtypes'}},$item);
10947: last;
10948: }
10949: }
10950: }
10951: }
10952: } else {
1.43 raeburn 10953: foreach my $item (@authen_contexts) {
1.28 raeburn 10954: push(@{$changes{'authtypes'}},$item);
10955: }
10956: }
10957:
1.224 raeburn 10958: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10959: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10960: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10961: $save_usercreate{'id_rule'} = \@id_rule;
10962: $save_usercreate{'username_rule'} = \@username_rule,
10963: $save_usercreate{'authtypes'} = \%authhash;
10964:
1.27 raeburn 10965: my %usercreation_hash = (
1.224 raeburn 10966: usercreation => \%save_usercreate,
10967: );
1.27 raeburn 10968:
10969: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10970: $dom);
1.50 raeburn 10971:
1.224 raeburn 10972: if ($putresult eq 'ok') {
10973: if (keys(%changes) > 0) {
10974: $resulttext = &mt('Changes made:').'<ul>';
10975: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10976: my %lt = &usercreation_types();
10977: foreach my $type (@{$changes{'cancreate'}}) {
10978: my $chgtext = $lt{$type}.', ';
10979: if ($cancreate{$type} eq 'none') {
10980: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10981: } elsif ($cancreate{$type} eq 'any') {
10982: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10983: } elsif ($cancreate{$type} eq 'official') {
10984: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10985: } elsif ($cancreate{$type} eq 'unofficial') {
10986: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10987: }
10988: $resulttext .= '<li>'.$chgtext.'</li>';
10989: }
10990: }
10991: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10992: my ($rules,$ruleorder) =
10993: &Apache::lonnet::inst_userrules($dom,'username');
10994: my $chgtext = '<ul>';
10995: foreach my $type (@username_rule) {
10996: if (ref($rules->{$type}) eq 'HASH') {
10997: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10998: }
10999: }
11000: $chgtext .= '</ul>';
11001: if (@username_rule > 0) {
11002: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11003: } else {
11004: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11005: }
11006: }
11007: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11008: my ($idrules,$idruleorder) =
11009: &Apache::lonnet::inst_userrules($dom,'id');
11010: my $chgtext = '<ul>';
11011: foreach my $type (@id_rule) {
11012: if (ref($idrules->{$type}) eq 'HASH') {
11013: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11014: }
11015: }
11016: $chgtext .= '</ul>';
11017: if (@id_rule > 0) {
11018: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11019: } else {
11020: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11021: }
11022: }
11023: my %authname = &authtype_names();
11024: my %context_title = &context_names();
11025: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11026: my $chgtext = '<ul>';
11027: foreach my $type (@{$changes{'authtypes'}}) {
11028: my @allowed;
11029: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11030: foreach my $auth (@authtypes) {
11031: if ($authhash{$type}{$auth}) {
11032: push(@allowed,$authname{$auth});
11033: }
11034: }
11035: if (@allowed > 0) {
11036: $chgtext .= join(', ',@allowed).'</li>';
11037: } else {
11038: $chgtext .= &mt('none').'</li>';
11039: }
11040: }
11041: $chgtext .= '</ul>';
11042: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11043: $resulttext .= '</li>';
11044: }
11045: $resulttext .= '</ul>';
11046: } else {
11047: $resulttext = &mt('No changes made to user creation settings');
11048: }
11049: } else {
11050: $resulttext = '<span class="LC_error">'.
11051: &mt('An error occurred: [_1]',$putresult).'</span>';
11052: }
11053: if ($warningmsg ne '') {
11054: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11055: }
11056: return $resulttext;
11057: }
11058:
11059: sub modify_selfcreation {
11060: my ($dom,%domconfig) = @_;
11061: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
11062: my (%save_usercreate,%save_usermodify);
1.228 raeburn 11063: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11064: if (ref($types) eq 'ARRAY') {
11065: $usertypes->{'default'} = $othertitle;
11066: push(@{$types},'default');
11067: }
1.224 raeburn 11068: #
11069: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11070: #
11071: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11072: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11073: if ($key eq 'cancreate') {
11074: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11075: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11076: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
11077: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 11078: ($item eq 'recaptchaversion') ||
1.236 raeburn 11079: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 11080: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 11081: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11082: } else {
11083: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11084: }
11085: }
11086: }
11087: } elsif ($key eq 'email_rule') {
11088: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11089: } else {
11090: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11091: }
11092: }
11093: }
11094: #
11095: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11096: #
11097: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11098: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11099: if ($key eq 'selfcreate') {
11100: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11101: } else {
11102: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11103: }
11104: }
11105: }
11106:
11107: my @contexts = ('selfcreate');
11108: @{$cancreate{'selfcreate'}} = ();
11109: %{$cancreate{'emailusername'}} = ();
11110: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 11111: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 11112: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 11113: my %selfcreatetypes = (
11114: sso => 'users authenticated by institutional single sign on',
11115: login => 'users authenticated by institutional log-in',
1.236 raeburn 11116: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 11117: );
1.224 raeburn 11118: #
11119: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11120: # is permitted.
11121: #
1.236 raeburn 11122:
11123: my @statuses;
11124: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11125: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
11126: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
11127: }
11128: }
11129: push(@statuses,'default');
11130:
1.228 raeburn 11131: foreach my $item ('login','sso','email') {
1.224 raeburn 11132: if ($item eq 'email') {
1.236 raeburn 11133: if ($env{'form.cancreate_email'}) {
1.224 raeburn 11134: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 11135: push(@contexts,'selfcreateprocessing');
11136: foreach my $type (@statuses) {
11137: if ($type eq 'default') {
11138: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
11139: } else {
11140: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11141: }
11142: }
1.224 raeburn 11143: }
11144: } else {
11145: if ($env{'form.cancreate_'.$item}) {
11146: push(@{$cancreate{'selfcreate'}},$item);
11147: }
11148: }
11149: }
11150: my (@email_rule,%userinfo,%savecaptcha);
11151: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11152: #
1.228 raeburn 11153: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11154: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 11155: #
1.236 raeburn 11156:
1.244 raeburn 11157: if ($env{'form.cancreate_email'}) {
1.228 raeburn 11158: push(@contexts,'emailusername');
11159: if (ref($types) eq 'ARRAY') {
11160: foreach my $type (@{$types}) {
11161: if (ref($infofields) eq 'ARRAY') {
11162: foreach my $field (@{$infofields}) {
11163: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11164: $cancreate{'emailusername'}{$type}{$field} = $1;
11165: }
11166: }
1.224 raeburn 11167: }
11168: }
11169: }
11170: #
11171: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
11172: # queued requests for self-creation of account using e-mail address as username
11173: #
11174:
11175: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11176: @approvalnotify = sort(@approvalnotify);
11177: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11178: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11179: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11180: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11181: push(@{$changes{'cancreate'}},'notify');
11182: }
11183: } else {
11184: if ($cancreate{'notify'}{'approval'}) {
11185: push(@{$changes{'cancreate'}},'notify');
11186: }
11187: }
11188: } elsif ($cancreate{'notify'}{'approval'}) {
11189: push(@{$changes{'cancreate'}},'notify');
11190: }
11191:
11192: #
11193: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
11194: #
11195: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11196: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11197: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11198: if (@{$curr_usercreation{'email_rule'}} > 0) {
11199: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11200: if (!grep(/^\Q$type\E$/,@email_rule)) {
11201: push(@{$changes{'email_rule'}},$type);
11202: }
11203: }
11204: }
11205: if (@email_rule > 0) {
11206: foreach my $type (@email_rule) {
11207: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11208: push(@{$changes{'email_rule'}},$type);
11209: }
11210: }
11211: }
11212: } elsif (@email_rule > 0) {
11213: push(@{$changes{'email_rule'}},@email_rule);
11214: }
11215: }
11216: #
1.236 raeburn 11217: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 11218: # institutional log-in.
11219: #
11220: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11221: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11222: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11223: ($domdefaults{'auth_def'} eq 'localauth'))) {
11224: $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.').' '.
11225: &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.');
11226: }
11227: }
11228: my @fields = ('lastname','firstname','middlename','generation',
11229: 'permanentemail','id');
1.240 raeburn 11230: my @shibfields = (@fields,'inststatus');
1.224 raeburn 11231: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11232: #
11233: # Where usernames may created for institutional log-in and/or institutional single sign on:
11234: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11235: # may self-create accounts
11236: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11237: # which the user may supply, if institutional data is unavailable.
11238: #
11239: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11240: if (ref($types) eq 'ARRAY') {
1.228 raeburn 11241: if (@{$types} > 1) {
1.224 raeburn 11242: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11243: push(@contexts,'statustocreate');
11244: } else {
11245: undef($cancreate{'statustocreate'});
11246: }
11247: foreach my $type (@{$types}) {
11248: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11249: foreach my $field (@fields) {
11250: if (grep(/^\Q$field\E$/,@modifiable)) {
11251: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11252: } else {
11253: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11254: }
11255: }
11256: }
11257: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11258: foreach my $type (@{$types}) {
11259: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11260: foreach my $field (@fields) {
11261: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11262: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11263: push(@{$changes{'selfcreate'}},$type);
11264: last;
11265: }
11266: }
11267: }
11268: }
11269: } else {
11270: foreach my $type (@{$types}) {
11271: push(@{$changes{'selfcreate'}},$type);
11272: }
11273: }
11274: }
1.240 raeburn 11275: foreach my $field (@shibfields) {
11276: if ($env{'form.shibenv_'.$field} ne '') {
11277: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11278: }
11279: }
11280: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11281: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11282: foreach my $field (@shibfields) {
11283: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11284: push(@{$changes{'cancreate'}},'shibenv');
11285: }
11286: }
11287: } else {
11288: foreach my $field (@shibfields) {
11289: if ($env{'form.shibenv_'.$field}) {
11290: push(@{$changes{'cancreate'}},'shibenv');
11291: last;
11292: }
11293: }
11294: }
11295: }
1.224 raeburn 11296: }
11297: foreach my $item (@contexts) {
11298: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11299: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11300: if (ref($cancreate{$item}) eq 'ARRAY') {
11301: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11302: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11303: push(@{$changes{'cancreate'}},$item);
11304: }
11305: }
11306: }
11307: }
11308: if (ref($cancreate{$item}) eq 'ARRAY') {
11309: foreach my $type (@{$cancreate{$item}}) {
11310: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11311: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11312: push(@{$changes{'cancreate'}},$item);
11313: }
11314: }
11315: }
11316: }
11317: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11318: if (ref($cancreate{$item}) eq 'HASH') {
11319: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 11320: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11321: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11322: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11323: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11324: push(@{$changes{'cancreate'}},$item);
11325: }
11326: }
11327: }
1.236 raeburn 11328: } elsif ($item eq 'selfcreateprocessing') {
11329: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11330: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11331: push(@{$changes{'cancreate'}},$item);
11332: }
11333: }
1.228 raeburn 11334: } else {
11335: if (!$cancreate{$item}{$curr}) {
11336: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11337: push(@{$changes{'cancreate'}},$item);
11338: }
1.224 raeburn 11339: }
11340: }
11341: }
11342: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 11343: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11344: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11345: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11346: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11347: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11348: push(@{$changes{'cancreate'}},$item);
11349: }
11350: }
11351: } else {
11352: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11353: push(@{$changes{'cancreate'}},$item);
11354: }
11355: }
11356: }
1.236 raeburn 11357: } elsif ($item eq 'selfcreateprocessing') {
11358: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11359: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11360: push(@{$changes{'cancreate'}},$item);
11361: }
11362: }
1.228 raeburn 11363: } else {
11364: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11365: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11366: push(@{$changes{'cancreate'}},$item);
11367: }
1.224 raeburn 11368: }
11369: }
11370: }
11371: }
11372: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11373: if (ref($cancreate{$item}) eq 'ARRAY') {
11374: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11375: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11376: push(@{$changes{'cancreate'}},$item);
11377: }
11378: }
11379: } elsif (ref($cancreate{$item}) eq 'HASH') {
11380: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11381: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11382: push(@{$changes{'cancreate'}},$item);
11383: }
11384: }
11385: }
11386: } elsif ($item eq 'emailusername') {
1.228 raeburn 11387: if (ref($cancreate{$item}) eq 'HASH') {
11388: foreach my $type (keys(%{$cancreate{$item}})) {
11389: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11390: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11391: if ($cancreate{$item}{$type}{$field}) {
11392: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11393: push(@{$changes{'cancreate'}},$item);
11394: }
11395: last;
11396: }
11397: }
11398: }
11399: }
1.224 raeburn 11400: }
11401: }
11402: }
11403: #
11404: # Populate %save_usercreate hash with updates to self-creation configuration.
11405: #
11406: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11407: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 11408: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 11409: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11410: if (ref($cancreate{'notify'}) eq 'HASH') {
11411: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11412: }
1.236 raeburn 11413: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11414: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11415: }
1.224 raeburn 11416: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11417: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11418: }
1.240 raeburn 11419: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11420: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11421: }
1.224 raeburn 11422: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
11423: $save_usercreate{'emailrule'} = \@email_rule;
11424:
11425: my %userconfig_hash = (
11426: usercreation => \%save_usercreate,
11427: usermodification => \%save_usermodify,
11428: );
11429: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11430: $dom);
11431: #
11432: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11433: #
1.27 raeburn 11434: if ($putresult eq 'ok') {
11435: if (keys(%changes) > 0) {
11436: $resulttext = &mt('Changes made:').'<ul>';
11437: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 11438: my %lt = &selfcreation_types();
1.34 raeburn 11439: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 11440: my $chgtext;
1.45 raeburn 11441: if ($type eq 'selfcreate') {
1.50 raeburn 11442: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 11443: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11444: } else {
1.224 raeburn 11445: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11446: '<ul>';
1.50 raeburn 11447: foreach my $case (@{$cancreate{$type}}) {
11448: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11449: }
11450: $chgtext .= '</ul>';
1.100 raeburn 11451: if (ref($cancreate{$type}) eq 'ARRAY') {
11452: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11453: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11454: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 11455: $chgtext .= '<br />'.
11456: '<span class="LC_warning">'.
11457: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11458: '</span>';
1.100 raeburn 11459: }
11460: }
11461: }
11462: }
1.43 raeburn 11463: }
1.240 raeburn 11464: } elsif ($type eq 'shibenv') {
11465: if (keys(%{$cancreate{$type}}) == 0) {
11466: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
11467: } else {
11468: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11469: '<ul>';
11470: foreach my $field (@shibfields) {
11471: next if ($cancreate{$type}{$field} eq '');
11472: if ($field eq 'inststatus') {
11473: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11474: } else {
11475: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11476: }
11477: }
11478: $chgtext .= '</ul>';
11479: }
1.93 raeburn 11480: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11481: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11482: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11483: if (@{$cancreate{'selfcreate'}} > 0) {
11484: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11485: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11486: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11487: $chgtext .= '<br />'.
11488: '<span class="LC_warning">'.
11489: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11490: '</span>';
11491: }
1.96 raeburn 11492: } elsif (ref($usertypes) eq 'HASH') {
11493: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11494: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11495: } else {
11496: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11497: }
11498: $chgtext .= '<ul>';
11499: foreach my $case (@{$cancreate{$type}}) {
11500: if ($case eq 'default') {
11501: $chgtext .= '<li>'.$othertitle.'</li>';
11502: } else {
11503: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 11504: }
11505: }
1.100 raeburn 11506: $chgtext .= '</ul>';
11507: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11508: $chgtext .= '<br /><span class="LC_warning">'.
11509: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11510: '</span>';
1.100 raeburn 11511: }
11512: }
11513: } else {
11514: if (@{$cancreate{$type}} == 0) {
11515: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11516: } else {
11517: $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 11518: }
11519: }
11520: }
1.236 raeburn 11521: } elsif ($type eq 'selfcreateprocessing') {
11522: my %choices = &Apache::lonlocal::texthash (
11523: automatic => 'Automatic approval',
11524: approval => 'Queued for approval',
11525: );
11526: if (@statuses > 1) {
11527: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
11528: '<ul>';
11529: foreach my $type (@statuses) {
11530: if ($type eq 'default') {
11531: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11532: } else {
11533: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11534: }
11535: }
11536: $chgtext .= '</ul>';
11537: } else {
11538: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
11539: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11540: }
1.165 raeburn 11541: } elsif ($type eq 'captcha') {
1.224 raeburn 11542: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 11543: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11544: } else {
11545: my %captchas = &captcha_phrases();
1.224 raeburn 11546: if ($captchas{$savecaptcha{$type}}) {
11547: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 11548: } else {
1.210 raeburn 11549: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 11550: }
11551: }
11552: } elsif ($type eq 'recaptchakeys') {
11553: my ($privkey,$pubkey);
1.224 raeburn 11554: if (ref($savecaptcha{$type}) eq 'HASH') {
11555: $pubkey = $savecaptcha{$type}{'public'};
11556: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 11557: }
11558: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11559: if (!$pubkey) {
11560: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11561: } else {
11562: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11563: }
11564: if (!$privkey) {
11565: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11566: } else {
11567: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11568: }
11569: $chgtext .= '</ul>';
1.269 raeburn 11570: } elsif ($type eq 'recaptchaversion') {
11571: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 11572: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 11573: }
1.224 raeburn 11574: } elsif ($type eq 'emailusername') {
11575: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 11576: if (ref($types) eq 'ARRAY') {
11577: foreach my $type (@{$types}) {
11578: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11579: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 11580: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 11581: '<ul>';
11582: foreach my $field (@{$infofields}) {
11583: if ($cancreate{'emailusername'}{$type}{$field}) {
11584: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11585: }
11586: }
1.245 raeburn 11587: $chgtext .= '</ul>';
11588: } else {
11589: $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 11590: }
11591: } else {
1.245 raeburn 11592: $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 11593: }
11594: }
11595: }
11596: }
11597: } elsif ($type eq 'notify') {
11598: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11599: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11600: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11601: if ($cancreate{'notify'}{'approval'}) {
11602: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11603: }
11604: }
1.43 raeburn 11605: }
1.34 raeburn 11606: }
1.224 raeburn 11607: if ($chgtext) {
11608: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11609: }
11610: }
11611: }
1.43 raeburn 11612: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11613: my ($emailrules,$emailruleorder) =
11614: &Apache::lonnet::inst_userrules($dom,'email');
11615: my $chgtext = '<ul>';
11616: foreach my $type (@email_rule) {
11617: if (ref($emailrules->{$type}) eq 'HASH') {
11618: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11619: }
11620: }
11621: $chgtext .= '</ul>';
11622: if (@email_rule > 0) {
1.224 raeburn 11623: $resulttext .= '<li>'.
11624: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
11625: $chgtext.
11626: '</li>';
1.43 raeburn 11627: } else {
1.224 raeburn 11628: $resulttext .= '<li>'.
11629: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
11630: '</li>';
1.43 raeburn 11631: }
11632: }
1.224 raeburn 11633: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11634: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11635: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11636: foreach my $type (@{$changes{'selfcreate'}}) {
11637: my $typename = $type;
11638: if (ref($usertypes) eq 'HASH') {
11639: if ($usertypes->{$type} ne '') {
11640: $typename = $usertypes->{$type};
11641: }
11642: }
11643: my @modifiable;
11644: $resulttext .= '<li>'.
11645: &mt('Self-creation of account by users with status: [_1]',
11646: '<span class="LC_cusr_emph">'.$typename.'</span>').
11647: ' - '.&mt('modifiable fields (if institutional data blank): ');
11648: foreach my $field (@fields) {
11649: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11650: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 11651: }
11652: }
1.224 raeburn 11653: if (@modifiable > 0) {
11654: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11655: } else {
1.224 raeburn 11656: $resulttext .= &mt('none');
1.43 raeburn 11657: }
1.224 raeburn 11658: $resulttext .= '</li>';
1.28 raeburn 11659: }
1.224 raeburn 11660: $resulttext .= '</ul></li>';
1.28 raeburn 11661: }
1.27 raeburn 11662: $resulttext .= '</ul>';
11663: } else {
1.224 raeburn 11664: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11665: }
11666: } else {
11667: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11668: &mt('An error occurred: [_1]',$putresult).'</span>';
11669: }
1.43 raeburn 11670: if ($warningmsg ne '') {
11671: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11672: }
1.23 raeburn 11673: return $resulttext;
11674: }
11675:
1.165 raeburn 11676: sub process_captcha {
11677: my ($container,$changes,$newsettings,$current) = @_;
11678: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11679: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11680: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11681: $newsettings->{'captcha'} = 'original';
11682: }
11683: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 11684: if ($container eq 'cancreate') {
1.169 raeburn 11685: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11686: push(@{$changes->{'cancreate'}},'captcha');
11687: } elsif (!defined($changes->{'cancreate'})) {
11688: $changes->{'cancreate'} = ['captcha'];
11689: }
11690: } else {
11691: $changes->{'captcha'} = 1;
1.165 raeburn 11692: }
11693: }
1.269 raeburn 11694: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 11695: if ($newsettings->{'captcha'} eq 'recaptcha') {
11696: $newpub = $env{'form.'.$container.'_recaptchapub'};
11697: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 11698: $newpub =~ s/[^\w\-]//g;
11699: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 11700: $newsettings->{'recaptchakeys'} = {
11701: public => $newpub,
11702: private => $newpriv,
11703: };
1.269 raeburn 11704: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11705: $newversion =~ s/\D//g;
11706: if ($newversion ne '2') {
11707: $newversion = 1;
11708: }
11709: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 11710: }
11711: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11712: $currpub = $current->{'recaptchakeys'}{'public'};
11713: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 11714: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11715: $newsettings->{'recaptchakeys'} = {
11716: public => '',
11717: private => '',
11718: }
11719: }
1.165 raeburn 11720: }
1.269 raeburn 11721: if ($current->{'captcha'} eq 'recaptcha') {
11722: $currversion = $current->{'recaptchaversion'};
11723: if ($currversion ne '2') {
11724: $currversion = 1;
11725: }
11726: }
11727: if ($currversion ne $newversion) {
11728: if ($container eq 'cancreate') {
11729: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11730: push(@{$changes->{'cancreate'}},'recaptchaversion');
11731: } elsif (!defined($changes->{'cancreate'})) {
11732: $changes->{'cancreate'} = ['recaptchaversion'];
11733: }
11734: } else {
11735: $changes->{'recaptchaversion'} = 1;
11736: }
11737: }
1.165 raeburn 11738: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 11739: if ($container eq 'cancreate') {
11740: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11741: push(@{$changes->{'cancreate'}},'recaptchakeys');
11742: } elsif (!defined($changes->{'cancreate'})) {
11743: $changes->{'cancreate'} = ['recaptchakeys'];
11744: }
11745: } else {
1.210 raeburn 11746: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 11747: }
11748: }
11749: return;
11750: }
11751:
1.33 raeburn 11752: sub modify_usermodification {
11753: my ($dom,%domconfig) = @_;
1.224 raeburn 11754: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11755: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11756: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 11757: if ($key eq 'selfcreate') {
11758: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11759: } else {
11760: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11761: }
1.33 raeburn 11762: }
11763: }
1.224 raeburn 11764: my @contexts = ('author','course');
1.33 raeburn 11765: my %context_title = (
11766: author => 'In author context',
11767: course => 'In course context',
11768: );
11769: my @fields = ('lastname','firstname','middlename','generation',
11770: 'permanentemail','id');
11771: my %roles = (
11772: author => ['ca','aa'],
11773: course => ['st','ep','ta','in','cr'],
11774: );
11775: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11776: foreach my $context (@contexts) {
11777: foreach my $role (@{$roles{$context}}) {
11778: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11779: foreach my $item (@fields) {
11780: if (grep(/^\Q$item\E$/,@modifiable)) {
11781: $modifyhash{$context}{$role}{$item} = 1;
11782: } else {
11783: $modifyhash{$context}{$role}{$item} = 0;
11784: }
11785: }
11786: }
11787: if (ref($curr_usermodification{$context}) eq 'HASH') {
11788: foreach my $role (@{$roles{$context}}) {
11789: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11790: foreach my $field (@fields) {
11791: if ($modifyhash{$context}{$role}{$field} ne
11792: $curr_usermodification{$context}{$role}{$field}) {
11793: push(@{$changes{$context}},$role);
11794: last;
11795: }
11796: }
11797: }
11798: }
11799: } else {
11800: foreach my $context (@contexts) {
11801: foreach my $role (@{$roles{$context}}) {
11802: push(@{$changes{$context}},$role);
11803: }
11804: }
11805: }
11806: }
11807: my %usermodification_hash = (
11808: usermodification => \%modifyhash,
11809: );
11810: my $putresult = &Apache::lonnet::put_dom('configuration',
11811: \%usermodification_hash,$dom);
11812: if ($putresult eq 'ok') {
11813: if (keys(%changes) > 0) {
11814: $resulttext = &mt('Changes made: ').'<ul>';
11815: foreach my $context (@contexts) {
11816: if (ref($changes{$context}) eq 'ARRAY') {
11817: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11818: if (ref($changes{$context}) eq 'ARRAY') {
11819: foreach my $role (@{$changes{$context}}) {
11820: my $rolename;
1.224 raeburn 11821: if ($role eq 'cr') {
11822: $rolename = &mt('Custom');
1.33 raeburn 11823: } else {
1.224 raeburn 11824: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11825: }
11826: my @modifiable;
1.224 raeburn 11827: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11828: foreach my $field (@fields) {
11829: if ($modifyhash{$context}{$role}{$field}) {
11830: push(@modifiable,$fieldtitles{$field});
11831: }
11832: }
11833: if (@modifiable > 0) {
11834: $resulttext .= join(', ',@modifiable);
11835: } else {
11836: $resulttext .= &mt('none');
11837: }
11838: $resulttext .= '</li>';
11839: }
11840: $resulttext .= '</ul></li>';
11841: }
11842: }
11843: }
11844: $resulttext .= '</ul>';
11845: } else {
11846: $resulttext = &mt('No changes made to user modification settings');
11847: }
11848: } else {
11849: $resulttext = '<span class="LC_error">'.
11850: &mt('An error occurred: [_1]',$putresult).'</span>';
11851: }
11852: return $resulttext;
11853: }
11854:
1.43 raeburn 11855: sub modify_defaults {
1.212 raeburn 11856: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11857: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 11858: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 11859: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
11860: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 11861: my @authtypes = ('internal','krb4','krb5','localauth');
11862: foreach my $item (@items) {
11863: $newvalues{$item} = $env{'form.'.$item};
11864: if ($item eq 'auth_def') {
11865: if ($newvalues{$item} ne '') {
11866: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11867: push(@errors,$item);
11868: }
11869: }
11870: } elsif ($item eq 'lang_def') {
11871: if ($newvalues{$item} ne '') {
11872: if ($newvalues{$item} =~ /^(\w+)/) {
11873: my $langcode = $1;
1.103 raeburn 11874: if ($langcode ne 'x_chef') {
11875: if (code2language($langcode) eq '') {
11876: push(@errors,$item);
11877: }
1.43 raeburn 11878: }
11879: } else {
11880: push(@errors,$item);
11881: }
11882: }
1.54 raeburn 11883: } elsif ($item eq 'timezone_def') {
11884: if ($newvalues{$item} ne '') {
1.62 raeburn 11885: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11886: push(@errors,$item);
11887: }
11888: }
1.68 raeburn 11889: } elsif ($item eq 'datelocale_def') {
11890: if ($newvalues{$item} ne '') {
11891: my @datelocale_ids = DateTime::Locale->ids();
11892: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11893: push(@errors,$item);
11894: }
11895: }
1.141 raeburn 11896: } elsif ($item eq 'portal_def') {
11897: if ($newvalues{$item} ne '') {
11898: 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])\/?$/) {
11899: push(@errors,$item);
11900: }
11901: }
1.294 raeburn 11902: } elsif ($item eq 'intauth_cost') {
11903: if ($newvalues{$item} ne '') {
11904: if ($newvalues{$item} =~ /\D/) {
11905: push(@errors,$item);
11906: }
11907: }
11908: } elsif ($item eq 'intauth_check') {
11909: if ($newvalues{$item} ne '') {
11910: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11911: push(@errors,$item);
11912: }
11913: }
11914: } elsif ($item eq 'intauth_switch') {
11915: if ($newvalues{$item} ne '') {
11916: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11917: push(@errors,$item);
11918: }
11919: }
1.43 raeburn 11920: }
11921: if (grep(/^\Q$item\E$/,@errors)) {
11922: $newvalues{$item} = $domdefaults{$item};
11923: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
11924: $changes{$item} = 1;
11925: }
1.72 raeburn 11926: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 11927: }
11928: my %defaults_hash = (
1.72 raeburn 11929: defaults => \%newvalues,
11930: );
1.43 raeburn 11931: my $title = &defaults_titles();
1.236 raeburn 11932:
11933: my $currinststatus;
11934: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11935: $currinststatus = $domconfig{'inststatus'};
11936: } else {
11937: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11938: $currinststatus = {
11939: inststatustypes => $usertypes,
11940: inststatusorder => $types,
11941: inststatusguest => [],
11942: };
11943: }
11944: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
11945: my @allpos;
11946: my %guests;
11947: my %alltypes;
11948: my ($currtitles,$currguests,$currorder);
11949: if (ref($currinststatus) eq 'HASH') {
11950: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
11951: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
11952: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
11953: if ($currinststatus->{inststatustypes}->{$type} ne '') {
11954: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
11955: }
11956: }
11957: unless (grep(/^\Q$type\E$/,@todelete)) {
11958: my $position = $env{'form.inststatus_pos_'.$type};
11959: $position =~ s/\D+//g;
11960: $allpos[$position] = $type;
11961: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
11962: $alltypes{$type} =~ s/`//g;
11963: if ($env{'form.inststatus_guest_'.$type}) {
11964: $guests{$type} = 1;
11965: }
11966: }
11967: }
11968: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11969: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
11970: }
11971: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11972: $currtitles =~ s/,$//;
11973: }
11974: }
11975: if ($env{'form.addinststatus'}) {
11976: my $newtype = $env{'form.addinststatus'};
11977: $newtype =~ s/\W//g;
11978: unless (exists($alltypes{$newtype})) {
11979: if ($env{'form.addinststatus_guest'}) {
11980: $guests{$newtype} = 1;
11981: }
11982: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11983: $alltypes{$newtype} =~ s/`//g;
11984: my $position = $env{'form.addinststatus_pos'};
11985: $position =~ s/\D+//g;
11986: if ($position ne '') {
11987: $allpos[$position] = $newtype;
11988: }
11989: }
11990: }
11991: my (@orderedstatus,@orderedguests);
11992: foreach my $type (@allpos) {
11993: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11994: push(@orderedstatus,$type);
11995: if ($guests{$type}) {
11996: push(@orderedguests,$type);
11997: }
11998: }
11999: }
12000: foreach my $type (keys(%alltypes)) {
12001: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12002: delete($alltypes{$type});
12003: }
12004: }
12005: $defaults_hash{'inststatus'} = {
12006: inststatustypes => \%alltypes,
12007: inststatusorder => \@orderedstatus,
12008: inststatusguest => \@orderedguests,
12009: };
12010: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12011: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12012: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12013: }
12014: }
12015: if ($currorder ne join(',',@orderedstatus)) {
12016: $changes{'inststatus'}{'inststatusorder'} = 1;
12017: }
12018: if ($currguests ne join(',',@orderedguests)) {
12019: $changes{'inststatus'}{'inststatusguest'} = 1;
12020: }
12021: my $newtitles;
12022: foreach my $item (@orderedstatus) {
12023: $newtitles .= $alltypes{$item}.',';
12024: }
12025: $newtitles =~ s/,$//;
12026: if ($currtitles ne $newtitles) {
12027: $changes{'inststatus'}{'inststatustypes'} = 1;
12028: }
1.43 raeburn 12029: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12030: $dom);
12031: if ($putresult eq 'ok') {
12032: if (keys(%changes) > 0) {
12033: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 12034: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12035: 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";
12036: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 12037: if ($item eq 'inststatus') {
12038: if (ref($changes{'inststatus'}) eq 'HASH') {
12039: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
12040: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12041: foreach my $type (@orderedstatus) {
12042: $resulttext .= $alltypes{$type}.', ';
12043: }
12044: $resulttext =~ s/, $//;
12045: $resulttext .= '</li>';
12046: }
12047: if ($changes{'inststatus'}{'inststatusguest'}) {
12048: $resulttext .= '<li>';
12049: if (@orderedguests) {
12050: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
12051: foreach my $type (@orderedguests) {
12052: $resulttext .= $alltypes{$type}.', ';
12053: }
12054: $resulttext =~ s/, $//;
12055: } else {
12056: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
12057: }
12058: $resulttext .= '</li>';
12059: }
12060: }
12061: } else {
12062: my $value = $env{'form.'.$item};
12063: if ($value eq '') {
12064: $value = &mt('none');
12065: } elsif ($item eq 'auth_def') {
12066: my %authnames = &authtype_names();
12067: my %shortauth = (
12068: internal => 'int',
12069: krb4 => 'krb4',
12070: krb5 => 'krb5',
12071: localauth => 'loc',
12072: );
12073: $value = $authnames{$shortauth{$value}};
1.294 raeburn 12074: } elsif ($item eq 'intauth_switch') {
12075: my %optiondesc = &Apache::lonlocal::texthash (
12076: 0 => 'No',
12077: 1 => 'Yes',
12078: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12079: );
12080: if ($value =~ /^(0|1|2)$/) {
12081: $value = $optiondesc{$value};
12082: } else {
12083: $value = &mt('none -- defaults to No');
12084: }
12085: } elsif ($item eq 'intauth_check') {
12086: my %optiondesc = &Apache::lonlocal::texthash (
12087: 0 => 'No',
12088: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12089: 2 => 'Yes, disallow login if stored cost is less than domain default',
12090: );
12091: if ($value =~ /^(0|1|2)$/) {
12092: $value = $optiondesc{$value};
12093: } else {
12094: $value = &mt('none -- defaults to No');
12095: }
1.236 raeburn 12096: }
12097: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12098: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12099: }
12100: }
12101: $resulttext .= '</ul>';
12102: $mailmsgtext .= "\n";
12103: my $cachetime = 24*60*60;
1.72 raeburn 12104: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12105: if (ref($lastactref) eq 'HASH') {
12106: $lastactref->{'domdefaults'} = 1;
12107: }
1.68 raeburn 12108: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 12109: my $notify = 1;
12110: if (ref($domconfig{'contacts'}) eq 'HASH') {
12111: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12112: $notify = 0;
12113: }
12114: }
12115: if ($notify) {
12116: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12117: "LON-CAPA Domain Settings Change - $dom",
12118: $mailmsgtext);
12119: }
1.54 raeburn 12120: }
1.43 raeburn 12121: } else {
1.54 raeburn 12122: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12123: }
12124: } else {
12125: $resulttext = '<span class="LC_error">'.
12126: &mt('An error occurred: [_1]',$putresult).'</span>';
12127: }
12128: if (@errors > 0) {
12129: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12130: foreach my $item (@errors) {
12131: $resulttext .= ' "'.$title->{$item}.'",';
12132: }
12133: $resulttext =~ s/,$//;
12134: }
12135: return $resulttext;
12136: }
12137:
1.46 raeburn 12138: sub modify_scantron {
1.205 raeburn 12139: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12140: my ($resulttext,%confhash,%changes,$errors);
12141: my $custom = 'custom.tab';
12142: my $default = 'default.tab';
12143: my $servadm = $r->dir_config('lonAdmEMail');
12144: my ($configuserok,$author_ok,$switchserver) =
12145: &config_check($dom,$confname,$servadm);
12146: if ($env{'form.scantronformat.filename'} ne '') {
12147: my $error;
12148: if ($configuserok eq 'ok') {
12149: if ($switchserver) {
1.130 raeburn 12150: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12151: } else {
12152: if ($author_ok eq 'ok') {
12153: my ($result,$scantronurl) =
12154: &publishlogo($r,'upload','scantronformat',$dom,
12155: $confname,'scantron','','',$custom);
12156: if ($result eq 'ok') {
12157: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12158: $changes{'scantronformat'} = 1;
1.46 raeburn 12159: } else {
12160: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12161: }
12162: } else {
12163: $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);
12164: }
12165: }
12166: } else {
12167: $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);
12168: }
12169: if ($error) {
12170: &Apache::lonnet::logthis($error);
12171: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12172: }
12173: }
1.48 raeburn 12174: if (ref($domconfig{'scantron'}) eq 'HASH') {
12175: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12176: if ($env{'form.scantronformat_del'}) {
12177: $confhash{'scantron'}{'scantronformat'} = '';
12178: $changes{'scantronformat'} = 1;
1.46 raeburn 12179: }
12180: }
12181: }
12182: if (keys(%confhash) > 0) {
12183: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12184: $dom);
12185: if ($putresult eq 'ok') {
12186: if (keys(%changes) > 0) {
1.48 raeburn 12187: if (ref($confhash{'scantron'}) eq 'HASH') {
12188: $resulttext = &mt('Changes made:').'<ul>';
12189: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 12190: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 12191: } else {
1.130 raeburn 12192: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 12193: }
1.48 raeburn 12194: $resulttext .= '</ul>';
12195: } else {
1.130 raeburn 12196: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12197: }
12198: $resulttext .= '</ul>';
12199: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12200: if (ref($lastactref) eq 'HASH') {
12201: $lastactref->{'domainconfig'} = 1;
12202: }
1.46 raeburn 12203: } else {
1.130 raeburn 12204: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12205: }
12206: } else {
12207: $resulttext = '<span class="LC_error">'.
12208: &mt('An error occurred: [_1]',$putresult).'</span>';
12209: }
12210: } else {
1.130 raeburn 12211: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12212: }
12213: if ($errors) {
12214: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12215: $errors.'</ul>';
12216: }
12217: return $resulttext;
12218: }
12219:
1.48 raeburn 12220: sub modify_coursecategories {
1.239 raeburn 12221: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12222: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12223: $cathash);
1.48 raeburn 12224: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 12225: my @catitems = ('unauth','auth');
12226: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12227: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12228: $cathash = $domconfig{'coursecategories'}{'cats'};
12229: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12230: $changes{'togglecats'} = 1;
12231: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12232: }
12233: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12234: $changes{'categorize'} = 1;
12235: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12236: }
1.120 raeburn 12237: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12238: $changes{'togglecatscomm'} = 1;
12239: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12240: }
12241: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12242: $changes{'categorizecomm'} = 1;
12243: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 12244:
12245: }
12246: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
12247: $changes{'togglecatsplace'} = 1;
12248: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
12249: }
12250: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
12251: $changes{'categorizeplace'} = 1;
12252: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 12253: }
1.238 raeburn 12254: foreach my $item (@catitems) {
12255: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12256: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12257: $changes{$item} = 1;
12258: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12259: }
12260: }
12261: }
1.57 raeburn 12262: } else {
12263: $changes{'togglecats'} = 1;
12264: $changes{'categorize'} = 1;
1.124 raeburn 12265: $changes{'togglecatscomm'} = 1;
12266: $changes{'categorizecomm'} = 1;
1.272 raeburn 12267: $changes{'togglecatsplace'} = 1;
12268: $changes{'categorizeplace'} = 1;
1.87 raeburn 12269: $domconfig{'coursecategories'} = {
12270: togglecats => $env{'form.togglecats'},
12271: categorize => $env{'form.categorize'},
1.124 raeburn 12272: togglecatscomm => $env{'form.togglecatscomm'},
12273: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 12274: togglecatsplace => $env{'form.togglecatsplace'},
12275: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 12276: };
1.238 raeburn 12277: foreach my $item (@catitems) {
12278: if ($env{'form.coursecat_'.$item} ne 'std') {
12279: $changes{$item} = 1;
12280: }
12281: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12282: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12283: }
12284: }
1.57 raeburn 12285: }
12286: if (ref($cathash) eq 'HASH') {
12287: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12288: push (@deletecategory,'instcode::0');
12289: }
1.120 raeburn 12290: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12291: push(@deletecategory,'communities::0');
12292: }
1.272 raeburn 12293: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
12294: push(@deletecategory,'placement::0');
12295: }
1.48 raeburn 12296: }
1.57 raeburn 12297: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12298: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12299: if (@deletecategory > 0) {
12300: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12301: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12302: foreach my $item (@deletecategory) {
1.57 raeburn 12303: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12304: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12305: $deletions{$item} = 1;
1.57 raeburn 12306: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12307: }
12308: }
12309: }
1.57 raeburn 12310: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12311: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12312: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12313: $reorderings{$item} = 1;
1.57 raeburn 12314: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12315: }
12316: if ($env{'form.addcategory_name_'.$item} ne '') {
12317: my $newcat = $env{'form.addcategory_name_'.$item};
12318: my $newdepth = $depth+1;
12319: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12320: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12321: $adds{$newitem} = 1;
12322: }
12323: if ($env{'form.subcat_'.$item} ne '') {
12324: my $newcat = $env{'form.subcat_'.$item};
12325: my $newdepth = $depth+1;
12326: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12327: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12328: $adds{$newitem} = 1;
12329: }
12330: }
12331: }
12332: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12333: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12334: my $newitem = 'instcode::0';
1.57 raeburn 12335: if ($cathash->{$newitem} eq '') {
12336: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12337: $adds{$newitem} = 1;
12338: }
12339: } else {
12340: my $newitem = 'instcode::0';
1.57 raeburn 12341: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12342: $adds{$newitem} = 1;
12343: }
12344: }
1.120 raeburn 12345: if ($env{'form.communities'} eq '1') {
12346: if (ref($cathash) eq 'HASH') {
12347: my $newitem = 'communities::0';
12348: if ($cathash->{$newitem} eq '') {
12349: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12350: $adds{$newitem} = 1;
12351: }
12352: } else {
12353: my $newitem = 'communities::0';
12354: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12355: $adds{$newitem} = 1;
12356: }
12357: }
1.272 raeburn 12358: if ($env{'form.placement'} eq '1') {
12359: if (ref($cathash) eq 'HASH') {
12360: my $newitem = 'placement::0';
12361: if ($cathash->{$newitem} eq '') {
12362: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12363: $adds{$newitem} = 1;
12364: }
12365: } else {
12366: my $newitem = 'placement::0';
12367: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12368: $adds{$newitem} = 1;
12369: }
12370: }
1.48 raeburn 12371: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12372: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 12373: ($env{'form.addcategory_name'} ne 'communities') &&
12374: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 12375: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12376: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12377: $adds{$newitem} = 1;
12378: }
1.48 raeburn 12379: }
1.57 raeburn 12380: my $putresult;
1.48 raeburn 12381: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12382: if (keys(%deletions) > 0) {
12383: foreach my $key (keys(%deletions)) {
12384: if ($predelallitems{$key} ne '') {
12385: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12386: }
12387: }
12388: }
12389: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12390: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12391: if (ref($chkcats[0]) eq 'ARRAY') {
12392: my $depth = 0;
12393: my $chg = 0;
12394: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12395: my $name = $chkcats[0][$i];
12396: my $item;
12397: if ($name eq '') {
12398: $chg ++;
12399: } else {
12400: $item = &escape($name).'::0';
12401: if ($chg) {
1.57 raeburn 12402: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12403: }
12404: $depth ++;
1.57 raeburn 12405: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12406: $depth --;
12407: }
12408: }
12409: }
1.57 raeburn 12410: }
12411: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12412: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12413: if ($putresult eq 'ok') {
1.57 raeburn 12414: my %title = (
1.120 raeburn 12415: togglecats => 'Show/Hide a course in catalog',
12416: categorize => 'Assign a category to a course',
12417: togglecatscomm => 'Show/Hide a community in catalog',
12418: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12419: );
12420: my %level = (
1.120 raeburn 12421: dom => 'set in Domain ("Modify Course/Community")',
12422: crs => 'set in Course ("Course Configuration")',
12423: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 12424: none => 'No catalog',
12425: std => 'Standard catalog',
12426: domonly => 'Domain-only catalog',
12427: codesrch => 'Code search form',
1.57 raeburn 12428: );
1.48 raeburn 12429: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12430: if ($changes{'togglecats'}) {
12431: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12432: }
12433: if ($changes{'categorize'}) {
12434: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12435: }
1.120 raeburn 12436: if ($changes{'togglecatscomm'}) {
12437: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12438: }
12439: if ($changes{'categorizecomm'}) {
12440: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12441: }
1.238 raeburn 12442: if ($changes{'unauth'}) {
12443: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12444: }
12445: if ($changes{'auth'}) {
12446: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12447: }
1.57 raeburn 12448: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12449: my $cathash;
12450: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12451: $cathash = $domconfig{'coursecategories'}{'cats'};
12452: } else {
12453: $cathash = {};
12454: }
12455: my (@cats,@trails,%allitems);
12456: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12457: if (keys(%deletions) > 0) {
12458: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12459: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12460: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12461: }
12462: $resulttext .= '</ul></li>';
12463: }
12464: if (keys(%reorderings) > 0) {
12465: my %sort_by_trail;
12466: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12467: foreach my $key (keys(%reorderings)) {
12468: if ($allitems{$key} ne '') {
12469: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12470: }
1.48 raeburn 12471: }
1.57 raeburn 12472: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12473: $resulttext .= '<li>'.$trails[$trail].'</li>';
12474: }
12475: $resulttext .= '</ul></li>';
1.48 raeburn 12476: }
1.57 raeburn 12477: if (keys(%adds) > 0) {
12478: my %sort_by_trail;
12479: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12480: foreach my $key (keys(%adds)) {
12481: if ($allitems{$key} ne '') {
12482: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12483: }
12484: }
12485: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12486: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12487: }
1.57 raeburn 12488: $resulttext .= '</ul></li>';
1.48 raeburn 12489: }
12490: }
12491: $resulttext .= '</ul>';
1.239 raeburn 12492: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 12493: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12494: if ($changes{'auth'}) {
12495: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12496: }
12497: if ($changes{'unauth'}) {
12498: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12499: }
12500: my $cachetime = 24*60*60;
12501: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 12502: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 12503: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 12504: }
12505: }
1.48 raeburn 12506: } else {
12507: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12508: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12509: }
12510: } else {
1.120 raeburn 12511: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12512: }
12513: return $resulttext;
12514: }
12515:
1.69 raeburn 12516: sub modify_serverstatuses {
12517: my ($dom,%domconfig) = @_;
12518: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12519: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12520: %currserverstatus = %{$domconfig{'serverstatuses'}};
12521: }
12522: my @pages = &serverstatus_pages();
12523: foreach my $type (@pages) {
12524: $newserverstatus{$type}{'namedusers'} = '';
12525: $newserverstatus{$type}{'machines'} = '';
12526: if (defined($env{'form.'.$type.'_namedusers'})) {
12527: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12528: my @okusers;
12529: foreach my $user (@users) {
12530: my ($uname,$udom) = split(/:/,$user);
12531: if (($udom =~ /^$match_domain$/) &&
12532: (&Apache::lonnet::domain($udom)) &&
12533: ($uname =~ /^$match_username$/)) {
12534: if (!grep(/^\Q$user\E/,@okusers)) {
12535: push(@okusers,$user);
12536: }
12537: }
12538: }
12539: if (@okusers > 0) {
12540: @okusers = sort(@okusers);
12541: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12542: }
12543: }
12544: if (defined($env{'form.'.$type.'_machines'})) {
12545: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12546: my @okmachines;
12547: foreach my $ip (@machines) {
12548: my @parts = split(/\./,$ip);
12549: next if (@parts < 4);
12550: my $badip = 0;
12551: for (my $i=0; $i<4; $i++) {
12552: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12553: $badip = 1;
12554: last;
12555: }
12556: }
12557: if (!$badip) {
12558: push(@okmachines,$ip);
12559: }
12560: }
12561: @okmachines = sort(@okmachines);
12562: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12563: }
12564: }
12565: my %serverstatushash = (
12566: serverstatuses => \%newserverstatus,
12567: );
12568: foreach my $type (@pages) {
1.83 raeburn 12569: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12570: my (@current,@new);
1.83 raeburn 12571: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12572: if ($currserverstatus{$type}{$setting} ne '') {
12573: @current = split(/,/,$currserverstatus{$type}{$setting});
12574: }
12575: }
12576: if ($newserverstatus{$type}{$setting} ne '') {
12577: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12578: }
12579: if (@current > 0) {
12580: if (@new > 0) {
12581: foreach my $item (@current) {
12582: if (!grep(/^\Q$item\E$/,@new)) {
12583: $changes{$type}{$setting} = 1;
1.82 raeburn 12584: last;
12585: }
12586: }
1.84 raeburn 12587: foreach my $item (@new) {
12588: if (!grep(/^\Q$item\E$/,@current)) {
12589: $changes{$type}{$setting} = 1;
12590: last;
1.82 raeburn 12591: }
12592: }
12593: } else {
1.83 raeburn 12594: $changes{$type}{$setting} = 1;
1.69 raeburn 12595: }
1.83 raeburn 12596: } elsif (@new > 0) {
12597: $changes{$type}{$setting} = 1;
1.69 raeburn 12598: }
12599: }
12600: }
12601: if (keys(%changes) > 0) {
1.81 raeburn 12602: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12603: my $putresult = &Apache::lonnet::put_dom('configuration',
12604: \%serverstatushash,$dom);
12605: if ($putresult eq 'ok') {
12606: $resulttext .= &mt('Changes made:').'<ul>';
12607: foreach my $type (@pages) {
1.84 raeburn 12608: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12609: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12610: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12611: if ($newserverstatus{$type}{'namedusers'} eq '') {
12612: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12613: } else {
12614: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12615: }
1.84 raeburn 12616: }
12617: if ($changes{$type}{'machines'}) {
1.69 raeburn 12618: if ($newserverstatus{$type}{'machines'} eq '') {
12619: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12620: } else {
12621: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12622: }
12623:
12624: }
12625: $resulttext .= '</ul></li>';
12626: }
12627: }
12628: $resulttext .= '</ul>';
12629: } else {
12630: $resulttext = '<span class="LC_error">'.
12631: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12632:
12633: }
12634: } else {
12635: $resulttext = &mt('No changes made to access to server status pages');
12636: }
12637: return $resulttext;
12638: }
12639:
1.118 jms 12640: sub modify_helpsettings {
1.285 raeburn 12641: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 12642: my ($resulttext,$errors,%changes,%helphash);
12643: my %defaultchecked = ('submitbugs' => 'on');
12644: my @offon = ('off','on');
1.118 jms 12645: my @toggles = ('submitbugs');
1.285 raeburn 12646: my %current = ('submitbugs' => '',
12647: 'adhoc' => {},
12648: );
1.118 jms 12649: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 12650: %current = %{$domconfig{'helpsettings'}};
12651: }
1.285 raeburn 12652: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 12653: foreach my $item (@toggles) {
12654: if ($defaultchecked{$item} eq 'on') {
12655: if ($current{$item} eq '') {
12656: if ($env{'form.'.$item} eq '0') {
12657: $changes{$item} = 1;
12658: }
12659: } elsif ($current{$item} ne $env{'form.'.$item}) {
12660: $changes{$item} = 1;
12661: }
12662: } elsif ($defaultchecked{$item} eq 'off') {
12663: if ($current{$item} eq '') {
12664: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 12665: $changes{$item} = 1;
12666: }
1.282 raeburn 12667: } elsif ($current{$item} ne $env{'form.'.$item}) {
12668: $changes{$item} = 1;
12669: }
12670: }
12671: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
12672: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
12673: }
12674: }
1.285 raeburn 12675: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 12676: my $confname = $dom.'-domainconfig';
12677: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 12678: my (@allpos,%newsettings,%changedprivs,$newrole);
12679: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 12680: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 12681: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 12682: my %lt = &Apache::lonlocal::texthash(
12683: s => 'system',
12684: d => 'domain',
12685: order => 'Display order',
12686: access => 'Role usage',
1.291 raeburn 12687: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 12688: dh => 'All with domain helpdesk role',
12689: da => 'All with domain helpdesk assistant role',
1.285 raeburn 12690: none => 'None',
12691: status => 'Determined based on institutional status',
12692: inc => 'Include all, but exclude specific personnel',
12693: exc => 'Exclude all, but include specific personnel',
12694: );
12695: for (my $num=0; $num<=$maxnum; $num++) {
12696: my ($prefix,$identifier,$rolename,%curr);
12697: if ($num == $maxnum) {
12698: next unless ($env{'form.newcusthelp'} == $maxnum);
12699: $identifier = 'custhelp'.$num;
12700: $prefix = 'helproles_'.$num;
12701: $rolename = $env{'form.custhelpname'.$num};
12702: $rolename=~s/[^A-Za-z0-9]//gs;
12703: next if ($rolename eq '');
12704: next if (exists($existing{'rolesdef_'.$rolename}));
12705: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12706: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12707: $newprivs{'c'},$confname,$dom);
12708: if ($result ne 'ok') {
12709: $errors .= '<li><span class="LC_error">'.
12710: &mt('An error occurred storing the new custom role: [_1]',
12711: $result).'</span></li>';
12712: next;
12713: } else {
12714: $changedprivs{$rolename} = \%newprivs;
12715: $newrole = $rolename;
12716: }
12717: } else {
12718: $prefix = 'helproles_'.$num;
12719: $rolename = $env{'form.'.$prefix};
12720: next if ($rolename eq '');
12721: next unless (exists($existing{'rolesdef_'.$rolename}));
12722: $identifier = 'custhelp'.$num;
12723: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12724: my %currprivs;
1.289 raeburn 12725: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 12726: split(/\_/,$existing{'rolesdef_'.$rolename});
12727: foreach my $level ('c','d','s') {
12728: if ($newprivs{$level} ne $currprivs{$level}) {
12729: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12730: $newprivs{'c'},$confname,$dom);
12731: if ($result ne 'ok') {
12732: $errors .= '<li><span class="LC_error">'.
12733: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12734: $rolename,$result).'</span></li>';
12735: } else {
12736: $changedprivs{$rolename} = \%newprivs;
12737: }
12738: last;
12739: }
12740: }
12741: if (ref($current{'adhoc'}) eq 'HASH') {
12742: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12743: %curr = %{$current{'adhoc'}{$rolename}};
12744: }
12745: }
12746: }
12747: my $newpos = $env{'form.'.$prefix.'_pos'};
12748: $newpos =~ s/\D+//g;
12749: $allpos[$newpos] = $rolename;
12750: my $newdesc = $env{'form.'.$prefix.'_desc'};
12751: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12752: if ($curr{'desc'}) {
12753: if ($curr{'desc'} ne $newdesc) {
12754: $changes{'customrole'}{$rolename}{'desc'} = 1;
12755: $newsettings{$rolename}{'desc'} = $newdesc;
12756: }
12757: } elsif ($newdesc ne '') {
12758: $changes{'customrole'}{$rolename}{'desc'} = 1;
12759: $newsettings{$rolename}{'desc'} = $newdesc;
12760: }
12761: my $access = $env{'form.'.$prefix.'_access'};
12762: if (grep(/^\Q$access\E$/,@accesstypes)) {
12763: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12764: if ($access eq 'status') {
12765: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12766: if (scalar(@statuses) == 0) {
1.289 raeburn 12767: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 12768: } else {
12769: my (@shownstatus,$numtypes);
12770: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12771: if (ref($types) eq 'ARRAY') {
12772: $numtypes = scalar(@{$types});
12773: foreach my $type (sort(@statuses)) {
12774: if ($type eq 'default') {
12775: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12776: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12777: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12778: push(@shownstatus,$usertypes->{$type});
12779: }
12780: }
12781: }
12782: if (grep(/^default$/,@statuses)) {
12783: push(@shownstatus,$othertitle);
12784: }
12785: if (scalar(@shownstatus) == 1+$numtypes) {
12786: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12787: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12788: } else {
12789: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12790: if (ref($curr{'status'}) eq 'ARRAY') {
12791: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12792: if (@diffs) {
12793: $changes{'customrole'}{$rolename}{$access} = 1;
12794: }
12795: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12796: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 12797: }
1.166 raeburn 12798: }
12799: }
1.285 raeburn 12800: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12801: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12802: my @newspecstaff;
12803: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12804: foreach my $person (sort(@personnel)) {
12805: if ($domhelpdesk{$person}) {
12806: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12807: }
12808: }
12809: if (ref($curr{$access}) eq 'ARRAY') {
12810: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12811: if (@diffs) {
12812: $changes{'customrole'}{$rolename}{$access} = 1;
12813: }
12814: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12815: $changes{'customrole'}{$rolename}{$access} = 1;
12816: }
12817: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12818: my ($uname,$udom) = split(/:/,$person);
12819: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12820: }
12821: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 12822: }
1.285 raeburn 12823: } else {
12824: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12825: }
12826: unless ($curr{'access'} eq $access) {
12827: $changes{'customrole'}{$rolename}{'access'} = 1;
12828: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 12829: }
12830: }
1.285 raeburn 12831: if (@allpos > 0) {
12832: my $idx = 0;
12833: foreach my $rolename (@allpos) {
12834: if ($rolename ne '') {
12835: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12836: if (ref($current{'adhoc'}) eq 'HASH') {
12837: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12838: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12839: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 12840: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 12841: }
12842: }
1.282 raeburn 12843: }
1.285 raeburn 12844: $idx ++;
1.166 raeburn 12845: }
12846: }
1.118 jms 12847: }
1.123 jms 12848: my $putresult;
12849: if (keys(%changes) > 0) {
1.166 raeburn 12850: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 12851: if ($putresult eq 'ok') {
1.285 raeburn 12852: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12853: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12854: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12855: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12856: }
12857: }
12858: my $cachetime = 24*60*60;
12859: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12860: if (ref($lastactref) eq 'HASH') {
12861: $lastactref->{'domdefaults'} = 1;
12862: }
12863: } else {
12864: $errors .= '<li><span class="LC_error">'.
12865: &mt('An error occurred storing the settings: [_1]',
12866: $putresult).'</span></li>';
12867: }
12868: }
12869: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12870: $resulttext = &mt('Changes made:').'<ul>';
12871: my (%shownprivs,@levelorder);
12872: @levelorder = ('c','d','s');
12873: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 12874: foreach my $item (sort(keys(%changes))) {
12875: if ($item eq 'submitbugs') {
12876: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12877: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12878: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 12879: } elsif ($item eq 'customrole') {
12880: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 12881: my @keyorder = ('order','desc','access','status','exc','inc');
12882: my %keytext = &Apache::lonlocal::texthash(
12883: order => 'Order',
12884: desc => 'Role description',
12885: access => 'Role usage',
12886: status => 'Allowed instituional types',
12887: exc => 'Allowed personnel',
12888: inc => 'Disallowed personnel',
12889: );
1.282 raeburn 12890: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 12891: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12892: if ($role eq $newrole) {
12893: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12894: $role).'<ul>';
12895: } else {
12896: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12897: $role).'<ul>';
12898: }
12899: foreach my $key (@keyorder) {
12900: if ($changes{'customrole'}{$role}{$key}) {
12901: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12902: $keytext{$key},$newsettings{$role}{$key}).
12903: '</li>';
12904: }
12905: }
12906: if (ref($changedprivs{$role}) eq 'HASH') {
12907: $shownprivs{$role} = 1;
12908: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
12909: foreach my $level (@levelorder) {
12910: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12911: next if ($item eq '');
12912: my ($priv) = split(/\&/,$item,2);
12913: if (&Apache::lonnet::plaintext($priv)) {
12914: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12915: unless ($level eq 'c') {
12916: $resulttext .= ' ('.$lt{$level}.')';
12917: }
12918: $resulttext .= '</li>';
12919: }
12920: }
12921: }
12922: $resulttext .= '</ul>';
12923: }
12924: $resulttext .= '</ul></li>';
12925: }
12926: }
12927: }
12928: }
12929: }
12930: }
12931: if (keys(%changedprivs)) {
12932: foreach my $role (sort(keys(%changedprivs))) {
12933: unless ($shownprivs{$role}) {
12934: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12935: $role).'<ul>'.
12936: '<li>'.&mt('Privileges set to :').'<ul>';
12937: foreach my $level (@levelorder) {
12938: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12939: next if ($item eq '');
12940: my ($priv) = split(/\&/,$item,2);
12941: if (&Apache::lonnet::plaintext($priv)) {
12942: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12943: unless ($level eq 'c') {
12944: $resulttext .= ' ('.$lt{$level}.')';
12945: }
12946: $resulttext .= '</li>';
12947: }
1.282 raeburn 12948: }
12949: }
1.285 raeburn 12950: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 12951: }
12952: }
12953: }
1.285 raeburn 12954: $resulttext .= '</ul>';
12955: } else {
12956: $resulttext = &mt('No changes made to help settings');
1.118 jms 12957: }
12958: if ($errors) {
1.168 raeburn 12959: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 12960: $errors.'</ul>';
1.118 jms 12961: }
12962: return $resulttext;
12963: }
12964:
1.121 raeburn 12965: sub modify_coursedefaults {
1.212 raeburn 12966: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 12967: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 12968: my %defaultchecked = (
12969: 'canuse_pdfforms' => 'off',
12970: 'uselcmath' => 'on',
12971: 'usejsme' => 'on'
12972: );
12973: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 12974: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 12975: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
12976: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
12977: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 12978: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 12979: my %staticdefaults = (
12980: anonsurvey_threshold => 10,
12981: uploadquota => 500,
1.257 raeburn 12982: postsubmit => 60,
1.276 raeburn 12983: mysqltables => 172800,
1.198 raeburn 12984: );
1.121 raeburn 12985:
12986: $defaultshash{'coursedefaults'} = {};
12987:
12988: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
12989: if ($domconfig{'coursedefaults'} eq '') {
12990: $domconfig{'coursedefaults'} = {};
12991: }
12992: }
12993:
12994: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
12995: foreach my $item (@toggles) {
12996: if ($defaultchecked{$item} eq 'on') {
12997: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12998: ($env{'form.'.$item} eq '0')) {
12999: $changes{$item} = 1;
1.192 raeburn 13000: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 13001: $changes{$item} = 1;
13002: }
13003: } elsif ($defaultchecked{$item} eq 'off') {
13004: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13005: ($env{'form.'.$item} eq '1')) {
13006: $changes{$item} = 1;
13007: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13008: $changes{$item} = 1;
13009: }
13010: }
13011: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13012: }
1.198 raeburn 13013: foreach my $item (@numbers) {
13014: my ($currdef,$newdef);
1.208 raeburn 13015: $newdef = $env{'form.'.$item};
1.198 raeburn 13016: if ($item eq 'anonsurvey_threshold') {
13017: $currdef = $domconfig{'coursedefaults'}{$item};
13018: $newdef =~ s/\D//g;
13019: if ($newdef eq '' || $newdef < 1) {
13020: $newdef = 1;
13021: }
13022: $defaultshash{'coursedefaults'}{$item} = $newdef;
13023: } else {
1.276 raeburn 13024: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13025: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13026: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 13027: }
13028: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 13029: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 13030: }
13031: if ($currdef ne $newdef) {
13032: my $staticdef;
13033: if ($item eq 'anonsurvey_threshold') {
13034: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13035: $changes{$item} = 1;
13036: }
1.276 raeburn 13037: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 13038: my $setting = $1;
1.276 raeburn 13039: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13040: $changes{$setting} = 1;
1.198 raeburn 13041: }
13042: }
1.139 raeburn 13043: }
13044: }
1.264 raeburn 13045: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13046: my @currclonecode;
13047: if (ref($currclone) eq 'HASH') {
13048: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13049: @currclonecode = @{$currclone->{'instcode'}};
13050: }
13051: }
13052: my $newclone;
1.289 raeburn 13053: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 13054: $newclone = $env{'form.canclone'};
13055: }
13056: if ($newclone eq 'instcode') {
13057: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13058: my (%codedefaults,@code_order,@clonecode);
13059: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13060: \@code_order);
13061: foreach my $item (@code_order) {
13062: if (grep(/^\Q$item\E$/,@newcodes)) {
13063: push(@clonecode,$item);
13064: }
13065: }
13066: if (@clonecode) {
13067: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13068: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13069: if (@diffs) {
13070: $changes{'canclone'} = 1;
13071: }
13072: } else {
13073: $newclone eq '';
13074: }
13075: } elsif ($newclone ne '') {
1.289 raeburn 13076: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13077: }
1.264 raeburn 13078: if ($newclone ne $currclone) {
13079: $changes{'canclone'} = 1;
13080: }
1.257 raeburn 13081: my %credits;
13082: foreach my $type (@types) {
13083: unless ($type eq 'community') {
13084: $credits{$type} = $env{'form.'.$type.'_credits'};
13085: $credits{$type} =~ s/[^\d.]+//g;
13086: }
13087: }
13088: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13089: ($env{'form.coursecredits'} eq '1')) {
13090: $changes{'coursecredits'} = 1;
13091: foreach my $type (keys(%credits)) {
13092: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13093: }
13094: } else {
1.289 raeburn 13095: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 13096: foreach my $type (@types) {
13097: unless ($type eq 'community') {
1.289 raeburn 13098: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 13099: $changes{'coursecredits'} = 1;
13100: }
13101: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13102: }
13103: }
13104: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13105: foreach my $type (@types) {
13106: unless ($type eq 'community') {
13107: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13108: $changes{'coursecredits'} = 1;
13109: last;
13110: }
13111: }
13112: }
13113: }
13114: }
13115: if ($env{'form.postsubmit'} eq '1') {
13116: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13117: my %currtimeout;
13118: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13119: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13120: $changes{'postsubmit'} = 1;
13121: }
13122: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13123: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13124: }
13125: } else {
13126: $changes{'postsubmit'} = 1;
13127: }
13128: foreach my $type (@types) {
13129: my $timeout = $env{'form.'.$type.'_timeout'};
13130: $timeout =~ s/\D//g;
13131: if ($timeout == $staticdefaults{'postsubmit'}) {
13132: $timeout = '';
13133: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13134: $timeout = '0';
13135: }
13136: unless ($timeout eq '') {
13137: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13138: }
13139: if (exists($currtimeout{$type})) {
13140: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 13141: $changes{'postsubmit'} = 1;
1.257 raeburn 13142: }
13143: } elsif ($timeout ne '') {
13144: $changes{'postsubmit'} = 1;
13145: }
13146: }
13147: } else {
13148: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13149: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13150: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13151: $changes{'postsubmit'} = 1;
13152: }
13153: } else {
13154: $changes{'postsubmit'} = 1;
13155: }
1.192 raeburn 13156: }
1.121 raeburn 13157: }
13158: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13159: $dom);
13160: if ($putresult eq 'ok') {
13161: if (keys(%changes) > 0) {
1.213 raeburn 13162: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 13163: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 13164: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 13165: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 13166: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
13167: if ($changes{$item}) {
13168: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13169: }
1.289 raeburn 13170: }
1.192 raeburn 13171: if ($changes{'coursecredits'}) {
13172: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 13173: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13174: $domdefaults{$type.'credits'} =
13175: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13176: }
13177: }
13178: }
13179: if ($changes{'postsubmit'}) {
13180: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13181: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13182: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13183: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13184: $domdefaults{$type.'postsubtimeout'} =
13185: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13186: }
13187: }
1.192 raeburn 13188: }
13189: }
1.198 raeburn 13190: if ($changes{'uploadquota'}) {
13191: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13192: foreach my $type (@types) {
13193: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13194: }
13195: }
13196: }
1.264 raeburn 13197: if ($changes{'canclone'}) {
13198: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13199: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13200: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13201: if (@clonecodes) {
13202: $domdefaults{'canclone'} = join('+',@clonecodes);
13203: }
13204: }
13205: } else {
13206: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13207: }
13208: }
1.121 raeburn 13209: my $cachetime = 24*60*60;
13210: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13211: if (ref($lastactref) eq 'HASH') {
13212: $lastactref->{'domdefaults'} = 1;
13213: }
1.121 raeburn 13214: }
13215: $resulttext = &mt('Changes made:').'<ul>';
13216: foreach my $item (sort(keys(%changes))) {
13217: if ($item eq 'canuse_pdfforms') {
13218: if ($env{'form.'.$item} eq '1') {
13219: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
13220: } else {
13221: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
13222: }
1.257 raeburn 13223: } elsif ($item eq 'uselcmath') {
13224: if ($env{'form.'.$item} eq '1') {
13225: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13226: } else {
13227: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13228: }
13229: } elsif ($item eq 'usejsme') {
13230: if ($env{'form.'.$item} eq '1') {
13231: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13232: } else {
1.289 raeburn 13233: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 13234: }
1.139 raeburn 13235: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 13236: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 13237: } elsif ($item eq 'uploadquota') {
13238: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13239: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13240: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13241: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 13242: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 13243: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 13244: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13245: '</ul>'.
13246: '</li>';
13247: } else {
13248: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13249: }
1.276 raeburn 13250: } elsif ($item eq 'mysqltables') {
13251: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13252: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13253: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13254: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13255: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13256: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
13257: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13258: '</ul>'.
13259: '</li>';
13260: } else {
13261: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13262: }
1.257 raeburn 13263: } elsif ($item eq 'postsubmit') {
13264: if ($domdefaults{'postsubmit'} eq 'off') {
13265: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13266: } else {
13267: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 13268: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 13269: $resulttext .= &mt('durations:').'<ul>';
13270: foreach my $type (@types) {
13271: $resulttext .= '<li>';
13272: my $timeout;
13273: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13274: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13275: }
13276: my $display;
13277: if ($timeout eq '0') {
13278: $display = &mt('unlimited');
13279: } elsif ($timeout eq '') {
13280: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13281: } else {
13282: $display = &mt('[quant,_1,second]',$timeout);
13283: }
13284: if ($type eq 'community') {
13285: $resulttext .= &mt('Communities');
13286: } elsif ($type eq 'official') {
13287: $resulttext .= &mt('Official courses');
13288: } elsif ($type eq 'unofficial') {
13289: $resulttext .= &mt('Unofficial courses');
13290: } elsif ($type eq 'textbook') {
13291: $resulttext .= &mt('Textbook courses');
1.271 raeburn 13292: } elsif ($type eq 'placement') {
13293: $resulttext .= &mt('Placement tests');
1.257 raeburn 13294: }
13295: $resulttext .= ' -- '.$display.'</li>';
13296: }
13297: $resulttext .= '</ul>';
13298: }
1.289 raeburn 13299: $resulttext .= '</li>';
1.257 raeburn 13300: }
1.192 raeburn 13301: } elsif ($item eq 'coursecredits') {
13302: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13303: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 13304: ($domdefaults{'unofficialcredits'} eq '') &&
13305: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 13306: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13307: } else {
13308: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13309: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13310: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 13311: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 13312: '</ul>'.
13313: '</li>';
13314: }
13315: } else {
13316: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13317: }
1.264 raeburn 13318: } elsif ($item eq 'canclone') {
13319: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13320: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13321: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13322: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13323: }
13324: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13325: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13326: } else {
1.289 raeburn 13327: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 13328: }
1.140 raeburn 13329: }
1.121 raeburn 13330: }
13331: $resulttext .= '</ul>';
13332: } else {
13333: $resulttext = &mt('No changes made to course defaults');
13334: }
13335: } else {
13336: $resulttext = '<span class="LC_error">'.
13337: &mt('An error occurred: [_1]',$putresult).'</span>';
13338: }
13339: return $resulttext;
13340: }
13341:
1.231 raeburn 13342: sub modify_selfenrollment {
13343: my ($dom,$lastactref,%domconfig) = @_;
13344: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 13345: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 13346: my %titles = &tool_titles();
1.232 raeburn 13347: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13348: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 13349: $ordered{'default'} = ['types','registered','approval','limit'];
13350:
13351: my (%roles,%shown,%toplevel);
13352: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13353:
13354: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13355: if ($domconfig{'selfenrollment'} eq '') {
13356: $domconfig{'selfenrollment'} = {};
13357: }
13358: }
13359: %toplevel = (
13360: admin => 'Configuration Rights',
13361: default => 'Default settings',
13362: validation => 'Validation of self-enrollment requests',
13363: );
1.233 raeburn 13364: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 13365:
13366: if (ref($ordered{'admin'}) eq 'ARRAY') {
13367: foreach my $item (@{$ordered{'admin'}}) {
13368: foreach my $type (@types) {
13369: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13370: $selfenrollhash{'admin'}{$type}{$item} = 1;
13371: } else {
13372: $selfenrollhash{'admin'}{$type}{$item} = 0;
13373: }
13374: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13375: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13376: if ($selfenrollhash{'admin'}{$type}{$item} ne
13377: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13378: push(@{$changes{'admin'}{$type}},$item);
13379: }
13380: } else {
13381: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13382: push(@{$changes{'admin'}{$type}},$item);
13383: }
13384: }
13385: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13386: push(@{$changes{'admin'}{$type}},$item);
13387: }
13388: }
13389: }
13390: }
13391:
13392: foreach my $item (@{$ordered{'default'}}) {
13393: foreach my $type (@types) {
13394: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13395: if ($item eq 'types') {
13396: unless (($value eq 'all') || ($value eq 'dom')) {
13397: $value = '';
13398: }
13399: } elsif ($item eq 'registered') {
13400: unless ($value eq '1') {
13401: $value = 0;
13402: }
13403: } elsif ($item eq 'approval') {
13404: unless ($value =~ /^[012]$/) {
13405: $value = 0;
13406: }
13407: } else {
13408: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13409: $value = 'none';
13410: }
13411: }
13412: $selfenrollhash{'default'}{$type}{$item} = $value;
13413: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13414: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13415: if ($selfenrollhash{'default'}{$type}{$item} ne
13416: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13417: push(@{$changes{'default'}{$type}},$item);
13418: }
13419: } else {
13420: push(@{$changes{'default'}{$type}},$item);
13421: }
13422: } else {
13423: push(@{$changes{'default'}{$type}},$item);
13424: }
13425: if ($item eq 'limit') {
13426: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13427: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13428: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13429: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13430: }
13431: } else {
13432: $selfenrollhash{'default'}{$type}{'cap'} = '';
13433: }
13434: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13435: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13436: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13437: push(@{$changes{'default'}{$type}},'cap');
13438: }
13439: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13440: push(@{$changes{'default'}{$type}},'cap');
13441: }
13442: }
13443: }
13444: }
13445:
13446: foreach my $item (@{$itemsref}) {
13447: if ($item eq 'fields') {
13448: my @changed;
13449: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13450: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13451: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13452: }
13453: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13454: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13455: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13456: $domconfig{'selfenrollment'}{'validation'}{$item});
13457: } else {
13458: @changed = @{$selfenrollhash{'validation'}{$item}};
13459: }
13460: } else {
13461: @changed = @{$selfenrollhash{'validation'}{$item}};
13462: }
13463: if (@changed) {
13464: if ($selfenrollhash{'validation'}{$item}) {
13465: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13466: } else {
13467: $changes{'validation'}{$item} = &mt('None');
13468: }
13469: }
13470: } else {
13471: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13472: if ($item eq 'markup') {
13473: if ($env{'form.selfenroll_validation_'.$item}) {
13474: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13475: }
13476: }
13477: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13478: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13479: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13480: }
13481: }
13482: }
13483: }
13484:
13485: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13486: $dom);
13487: if ($putresult eq 'ok') {
13488: if (keys(%changes) > 0) {
13489: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13490: $resulttext = &mt('Changes made:').'<ul>';
13491: foreach my $key ('admin','default','validation') {
13492: if (ref($changes{$key}) eq 'HASH') {
13493: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13494: if ($key eq 'validation') {
13495: foreach my $item (@{$itemsref}) {
13496: if (exists($changes{$key}{$item})) {
13497: if ($item eq 'markup') {
13498: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13499: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13500: } else {
13501: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13502: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13503: }
13504: }
13505: }
13506: } else {
13507: foreach my $type (@types) {
13508: if ($type eq 'community') {
13509: $roles{'1'} = &mt('Community personnel');
13510: } else {
13511: $roles{'1'} = &mt('Course personnel');
13512: }
13513: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 13514: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13515: if ($key eq 'admin') {
13516: my @mgrdc = ();
13517: if (ref($ordered{$key}) eq 'ARRAY') {
13518: foreach my $item (@{$ordered{'admin'}}) {
13519: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13520: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13521: push(@mgrdc,$item);
13522: }
13523: }
13524: }
13525: if (@mgrdc) {
13526: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13527: } else {
13528: delete($domdefaults{$type.'selfenrolladmdc'});
13529: }
13530: }
13531: } else {
13532: if (ref($ordered{$key}) eq 'ARRAY') {
13533: foreach my $item (@{$ordered{$key}}) {
13534: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13535: $domdefaults{$type.'selfenroll'.$item} =
13536: $selfenrollhash{$key}{$type}{$item};
13537: }
13538: }
13539: }
13540: }
13541: }
1.231 raeburn 13542: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13543: foreach my $item (@{$ordered{$key}}) {
13544: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13545: $resulttext .= '<li>';
13546: if ($key eq 'admin') {
13547: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13548: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13549: } else {
13550: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13551: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13552: }
13553: $resulttext .= '</li>';
13554: }
13555: }
13556: $resulttext .= '</ul></li>';
13557: }
13558: }
13559: $resulttext .= '</ul></li>';
13560: }
13561: }
1.232 raeburn 13562: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13563: my $cachetime = 24*60*60;
13564: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13565: if (ref($lastactref) eq 'HASH') {
13566: $lastactref->{'domdefaults'} = 1;
13567: }
13568: }
1.231 raeburn 13569: }
13570: $resulttext .= '</ul>';
13571: } else {
13572: $resulttext = &mt('No changes made to self-enrollment settings');
13573: }
13574: } else {
13575: $resulttext = '<span class="LC_error">'.
13576: &mt('An error occurred: [_1]',$putresult).'</span>';
13577: }
13578: return $resulttext;
13579: }
13580:
1.137 raeburn 13581: sub modify_usersessions {
1.212 raeburn 13582: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13583: my @hostingtypes = ('version','excludedomain','includedomain');
13584: my @offloadtypes = ('primary','default');
13585: my %types = (
13586: remote => \@hostingtypes,
13587: hosted => \@hostingtypes,
13588: spares => \@offloadtypes,
13589: );
13590: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13591: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 13592: my (%by_ip,%by_location,@intdoms,@instdoms);
13593: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 13594: my @locations = sort(keys(%by_location));
1.137 raeburn 13595: my (%defaultshash,%changes);
13596: foreach my $prefix (@prefixes) {
13597: $defaultshash{'usersessions'}{$prefix} = {};
13598: }
1.212 raeburn 13599: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13600: my $resulttext;
1.138 raeburn 13601: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13602: foreach my $prefix (@prefixes) {
1.145 raeburn 13603: next if ($prefix eq 'spares');
13604: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13605: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13606: if ($type eq 'version') {
13607: my $value = $env{'form.'.$prefix.'_'.$type};
13608: my $okvalue;
13609: if ($value ne '') {
13610: if (grep(/^\Q$value\E$/,@lcversions)) {
13611: $okvalue = $value;
13612: }
13613: }
13614: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13615: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13616: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13617: if ($inuse == 0) {
13618: $changes{$prefix}{$type} = 1;
13619: } else {
13620: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13621: $changes{$prefix}{$type} = 1;
13622: }
13623: if ($okvalue ne '') {
13624: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13625: }
13626: }
13627: } else {
13628: if (($inuse == 1) && ($okvalue ne '')) {
13629: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13630: $changes{$prefix}{$type} = 1;
13631: }
13632: }
13633: } else {
13634: if (($inuse == 1) && ($okvalue ne '')) {
13635: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13636: $changes{$prefix}{$type} = 1;
13637: }
13638: }
13639: } else {
13640: if (($inuse == 1) && ($okvalue ne '')) {
13641: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13642: $changes{$prefix}{$type} = 1;
13643: }
13644: }
13645: } else {
13646: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13647: my @okvals;
13648: foreach my $val (@vals) {
1.138 raeburn 13649: if ($val =~ /:/) {
13650: my @items = split(/:/,$val);
13651: foreach my $item (@items) {
13652: if (ref($by_location{$item}) eq 'ARRAY') {
13653: push(@okvals,$item);
13654: }
13655: }
13656: } else {
13657: if (ref($by_location{$val}) eq 'ARRAY') {
13658: push(@okvals,$val);
13659: }
1.137 raeburn 13660: }
13661: }
13662: @okvals = sort(@okvals);
13663: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13664: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13665: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13666: if ($inuse == 0) {
13667: $changes{$prefix}{$type} = 1;
13668: } else {
13669: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13670: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13671: if (@changed > 0) {
13672: $changes{$prefix}{$type} = 1;
13673: }
13674: }
13675: } else {
13676: if ($inuse == 1) {
13677: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13678: $changes{$prefix}{$type} = 1;
13679: }
13680: }
13681: } else {
13682: if ($inuse == 1) {
13683: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13684: $changes{$prefix}{$type} = 1;
13685: }
13686: }
13687: } else {
13688: if ($inuse == 1) {
13689: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13690: $changes{$prefix}{$type} = 1;
13691: }
13692: }
13693: }
13694: }
13695: }
1.145 raeburn 13696:
13697: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 13698: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 13699: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13700: my $savespares;
13701:
13702: foreach my $lonhost (sort(keys(%servers))) {
13703: my $serverhomeID =
13704: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 13705: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 13706: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13707: my %spareschg;
13708: foreach my $type (@{$types{'spares'}}) {
13709: my @okspares;
13710: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13711: foreach my $server (@checked) {
1.152 raeburn 13712: if (&Apache::lonnet::hostname($server) ne '') {
13713: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13714: unless (grep(/^\Q$server\E$/,@okspares)) {
13715: push(@okspares,$server);
13716: }
1.145 raeburn 13717: }
13718: }
13719: }
13720: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13721: my $newspare;
1.152 raeburn 13722: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13723: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 13724: $newspare = $new;
13725: }
13726: }
1.152 raeburn 13727: my @spares;
13728: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13729: @spares = sort(@okspares,$newspare);
13730: } else {
13731: @spares = sort(@okspares);
13732: }
13733: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 13734: if (ref($spareid{$lonhost}) eq 'HASH') {
13735: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 13736: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 13737: if (@diffs > 0) {
13738: $spareschg{$type} = 1;
13739: }
13740: }
13741: }
13742: }
13743: if (keys(%spareschg) > 0) {
13744: $changes{'spares'}{$lonhost} = \%spareschg;
13745: }
13746: }
1.261 raeburn 13747: $defaultshash{'usersessions'}{'offloadnow'} = {};
13748: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13749: my @okoffload;
13750: if (@offloadnow) {
13751: foreach my $server (@offloadnow) {
13752: if (&Apache::lonnet::hostname($server) ne '') {
13753: unless (grep(/^\Q$server\E$/,@okoffload)) {
13754: push(@okoffload,$server);
13755: }
13756: }
13757: }
13758: if (@okoffload) {
13759: foreach my $lonhost (@okoffload) {
13760: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13761: }
13762: }
13763: }
1.145 raeburn 13764: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13765: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13766: if (ref($changes{'spares'}) eq 'HASH') {
13767: if (keys(%{$changes{'spares'}}) > 0) {
13768: $savespares = 1;
13769: }
13770: }
13771: } else {
13772: $savespares = 1;
13773: }
1.261 raeburn 13774: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13775: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13776: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13777: $changes{'offloadnow'} = 1;
13778: last;
13779: }
13780: }
13781: unless ($changes{'offloadnow'}) {
1.289 raeburn 13782: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 13783: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13784: $changes{'offloadnow'} = 1;
13785: last;
13786: }
13787: }
13788: }
13789: } elsif (@okoffload) {
13790: $changes{'offloadnow'} = 1;
13791: }
13792: } elsif (@okoffload) {
13793: $changes{'offloadnow'} = 1;
1.145 raeburn 13794: }
1.147 raeburn 13795: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13796: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13797: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13798: $dom);
13799: if ($putresult eq 'ok') {
13800: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13801: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13802: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13803: }
13804: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13805: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13806: }
1.261 raeburn 13807: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13808: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13809: }
1.137 raeburn 13810: }
13811: my $cachetime = 24*60*60;
13812: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 ! raeburn 13813: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 13814: if (ref($lastactref) eq 'HASH') {
13815: $lastactref->{'domdefaults'} = 1;
1.295 ! raeburn 13816: $lastactref->{'usersessions'} = 1;
1.212 raeburn 13817: }
1.147 raeburn 13818: if (keys(%changes) > 0) {
13819: my %lt = &usersession_titles();
13820: $resulttext = &mt('Changes made:').'<ul>';
13821: foreach my $prefix (@prefixes) {
13822: if (ref($changes{$prefix}) eq 'HASH') {
13823: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13824: if ($prefix eq 'spares') {
13825: if (ref($changes{$prefix}) eq 'HASH') {
13826: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13827: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13828: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 13829: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13830: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13831: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13832: foreach my $type (@{$types{$prefix}}) {
13833: if ($changes{$prefix}{$lonhost}{$type}) {
13834: my $offloadto = &mt('None');
13835: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13836: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13837: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13838: }
1.145 raeburn 13839: }
1.147 raeburn 13840: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13841: }
1.137 raeburn 13842: }
13843: }
1.147 raeburn 13844: $resulttext .= '</li>';
1.137 raeburn 13845: }
13846: }
1.147 raeburn 13847: } else {
13848: foreach my $type (@{$types{$prefix}}) {
13849: if (defined($changes{$prefix}{$type})) {
13850: my $newvalue;
13851: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13852: if (ref($defaultshash{'usersessions'}{$prefix})) {
13853: if ($type eq 'version') {
13854: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13855: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13856: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13857: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13858: }
1.145 raeburn 13859: }
13860: }
13861: }
1.147 raeburn 13862: if ($newvalue eq '') {
13863: if ($type eq 'version') {
13864: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13865: } else {
13866: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13867: }
1.145 raeburn 13868: } else {
1.147 raeburn 13869: if ($type eq 'version') {
13870: $newvalue .= ' '.&mt('(or later)');
13871: }
13872: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13873: }
1.137 raeburn 13874: }
13875: }
13876: }
1.147 raeburn 13877: $resulttext .= '</ul>';
1.137 raeburn 13878: }
13879: }
1.261 raeburn 13880: if ($changes{'offloadnow'}) {
13881: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13882: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13883: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13884: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13885: $resulttext .= '<li>'.$lonhost.'</li>';
13886: }
13887: $resulttext .= '</ul>';
13888: } else {
13889: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13890: }
13891: } else {
13892: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13893: }
13894: }
1.147 raeburn 13895: $resulttext .= '</ul>';
13896: } else {
13897: $resulttext = $nochgmsg;
1.137 raeburn 13898: }
13899: } else {
13900: $resulttext = '<span class="LC_error">'.
13901: &mt('An error occurred: [_1]',$putresult).'</span>';
13902: }
13903: } else {
1.147 raeburn 13904: $resulttext = $nochgmsg;
1.137 raeburn 13905: }
13906: return $resulttext;
13907: }
13908:
1.275 raeburn 13909: sub modify_ssl {
13910: my ($dom,$lastactref,%domconfig) = @_;
13911: my (%by_ip,%by_location,@intdoms,@instdoms);
13912: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
13913: my @locations = sort(keys(%by_location));
13914: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13915: my (%defaultshash,%changes);
13916: my $action = 'ssl';
1.293 raeburn 13917: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 13918: foreach my $prefix (@prefixes) {
13919: $defaultshash{$action}{$prefix} = {};
13920: }
13921: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13922: my $resulttext;
13923: my %iphost = &Apache::lonnet::get_iphost();
13924: my @reptypes = ('certreq','nocertreq');
13925: my @connecttypes = ('dom','intdom','other');
13926: my %types = (
1.293 raeburn 13927: connto => \@connecttypes,
13928: connfrom => \@connecttypes,
13929: replication => \@reptypes,
1.275 raeburn 13930: );
13931: foreach my $prefix (sort(keys(%types))) {
13932: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 13933: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 13934: my $value = 'yes';
13935: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
13936: $value = $env{'form.'.$prefix.'_'.$type};
13937: }
13938: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
13939: if ($domconfig{$action}{$prefix}{$type} ne '') {
13940: if ($value ne $domconfig{$action}{$prefix}{$type}) {
13941: $changes{$prefix}{$type} = 1;
13942: }
13943: $defaultshash{$action}{$prefix}{$type} = $value;
13944: } else {
13945: $defaultshash{$action}{$prefix}{$type} = $value;
13946: $changes{$prefix}{$type} = 1;
13947: }
13948: } else {
13949: $defaultshash{$action}{$prefix}{$type} = $value;
13950: $changes{$prefix}{$type} = 1;
13951: }
13952: if (($type eq 'dom') && (keys(%servers) == 1)) {
13953: delete($changes{$prefix}{$type});
13954: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
13955: delete($changes{$prefix}{$type});
13956: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
13957: delete($changes{$prefix}{$type});
13958: }
13959: } elsif ($prefix eq 'replication') {
13960: if (@locations > 0) {
13961: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13962: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13963: my @okvals;
13964: foreach my $val (@vals) {
13965: if ($val =~ /:/) {
13966: my @items = split(/:/,$val);
13967: foreach my $item (@items) {
13968: if (ref($by_location{$item}) eq 'ARRAY') {
13969: push(@okvals,$item);
13970: }
13971: }
13972: } else {
13973: if (ref($by_location{$val}) eq 'ARRAY') {
13974: push(@okvals,$val);
13975: }
13976: }
13977: }
13978: @okvals = sort(@okvals);
13979: if (ref($domconfig{$action}) eq 'HASH') {
13980: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
13981: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
13982: if ($inuse == 0) {
13983: $changes{$prefix}{$type} = 1;
13984: } else {
13985: $defaultshash{$action}{$prefix}{$type} = \@okvals;
13986: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
13987: if (@changed > 0) {
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: } else {
14004: if ($inuse == 1) {
14005: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14006: $changes{$prefix}{$type} = 1;
14007: }
14008: }
14009: }
14010: }
14011: }
14012: }
14013: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
14014: if (keys(%changes) > 0) {
14015: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14016: $dom);
14017: if ($putresult eq 'ok') {
14018: if (ref($defaultshash{$action}) eq 'HASH') {
14019: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
14020: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
14021: }
1.293 raeburn 14022: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
14023: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
14024: }
14025: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
14026: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 14027: }
14028: }
14029: my $cachetime = 24*60*60;
14030: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14031: if (ref($lastactref) eq 'HASH') {
14032: $lastactref->{'domdefaults'} = 1;
14033: }
14034: if (keys(%changes) > 0) {
14035: my %titles = &ssl_titles();
14036: $resulttext = &mt('Changes made:').'<ul>';
14037: foreach my $prefix (@prefixes) {
14038: if (ref($changes{$prefix}) eq 'HASH') {
14039: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
14040: foreach my $type (@{$types{$prefix}}) {
14041: if (defined($changes{$prefix}{$type})) {
14042: my $newvalue;
14043: if (ref($defaultshash{$action}) eq 'HASH') {
14044: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 14045: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14046: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
14047: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
14048: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
14049: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
14050: }
14051: }
14052: }
14053: if ($newvalue eq '') {
14054: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
14055: } else {
14056: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
14057: }
14058: }
14059: }
14060: }
14061: $resulttext .= '</ul>';
14062: }
14063: }
14064: } else {
14065: $resulttext = $nochgmsg;
14066: }
14067: } else {
14068: $resulttext = '<span class="LC_error">'.
14069: &mt('An error occurred: [_1]',$putresult).'</span>';
14070: }
14071: } else {
14072: $resulttext = $nochgmsg;
14073: }
14074: return $resulttext;
14075: }
14076:
1.279 raeburn 14077: sub modify_trust {
14078: my ($dom,$lastactref,%domconfig) = @_;
14079: my (%by_ip,%by_location,@intdoms,@instdoms);
14080: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14081: my @locations = sort(keys(%by_location));
14082: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
14083: my @types = ('exc','inc');
14084: my (%defaultshash,%changes);
14085: foreach my $prefix (@prefixes) {
14086: $defaultshash{'trust'}{$prefix} = {};
14087: }
14088: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14089: my $resulttext;
14090: foreach my $prefix (@prefixes) {
14091: foreach my $type (@types) {
14092: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14093: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14094: my @okvals;
14095: foreach my $val (@vals) {
14096: if ($val =~ /:/) {
14097: my @items = split(/:/,$val);
14098: foreach my $item (@items) {
14099: if (ref($by_location{$item}) eq 'ARRAY') {
14100: push(@okvals,$item);
14101: }
14102: }
14103: } else {
14104: if (ref($by_location{$val}) eq 'ARRAY') {
14105: push(@okvals,$val);
14106: }
14107: }
14108: }
14109: @okvals = sort(@okvals);
14110: if (ref($domconfig{'trust'}) eq 'HASH') {
14111: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
14112: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14113: if ($inuse == 0) {
14114: $changes{$prefix}{$type} = 1;
14115: } else {
14116: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14117: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
14118: if (@changed > 0) {
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: } else {
14135: if ($inuse == 1) {
14136: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14137: $changes{$prefix}{$type} = 1;
14138: }
14139: }
14140: }
14141: }
14142: my $nochgmsg = &mt('No changes made to trust settings.');
14143: if (keys(%changes) > 0) {
14144: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14145: $dom);
14146: if ($putresult eq 'ok') {
14147: if (ref($defaultshash{'trust'}) eq 'HASH') {
14148: foreach my $prefix (@prefixes) {
14149: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
14150: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
14151: }
14152: }
14153: }
14154: my $cachetime = 24*60*60;
14155: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14156: if (ref($lastactref) eq 'HASH') {
14157: $lastactref->{'domdefaults'} = 1;
14158: }
14159: if (keys(%changes) > 0) {
14160: my %lt = &trust_titles();
14161: $resulttext = &mt('Changes made:').'<ul>';
14162: foreach my $prefix (@prefixes) {
14163: if (ref($changes{$prefix}) eq 'HASH') {
14164: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14165: foreach my $type (@types) {
14166: if (defined($changes{$prefix}{$type})) {
14167: my $newvalue;
14168: if (ref($defaultshash{'trust'}) eq 'HASH') {
14169: if (ref($defaultshash{'trust'}{$prefix})) {
14170: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14171: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
14172: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
14173: }
14174: }
14175: }
14176: }
14177: if ($newvalue eq '') {
14178: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14179: } else {
14180: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
14181: }
14182: }
14183: }
14184: $resulttext .= '</ul>';
14185: }
14186: }
14187: $resulttext .= '</ul>';
14188: } else {
14189: $resulttext = $nochgmsg;
14190: }
14191: } else {
14192: $resulttext = '<span class="LC_error">'.
14193: &mt('An error occurred: [_1]',$putresult).'</span>';
14194: }
14195: } else {
14196: $resulttext = $nochgmsg;
14197: }
14198: return $resulttext;
14199: }
14200:
1.150 raeburn 14201: sub modify_loadbalancing {
14202: my ($dom,%domconfig) = @_;
14203: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14204: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14205: my ($othertitle,$usertypes,$types) =
14206: &Apache::loncommon::sorted_inst_types($dom);
14207: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 14208: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 14209: my @sparestypes = ('primary','default');
14210: my %typetitles = &sparestype_titles();
14211: my $resulttext;
1.171 raeburn 14212: my (%currbalancer,%currtargets,%currrules,%existing);
14213: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14214: %existing = %{$domconfig{'loadbalancing'}};
14215: }
14216: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
14217: \%currtargets,\%currrules);
14218: my ($saveloadbalancing,%defaultshash,%changes);
14219: my ($alltypes,$othertypes,$titles) =
14220: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14221: my %ruletitles = &offloadtype_text();
14222: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14223: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14224: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14225: if ($balancer eq '') {
14226: next;
14227: }
1.210 raeburn 14228: if (!exists($servers{$balancer})) {
1.171 raeburn 14229: if (exists($currbalancer{$balancer})) {
14230: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14231: }
1.171 raeburn 14232: next;
14233: }
14234: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14235: push(@{$changes{'delete'}},$balancer);
14236: next;
14237: }
14238: if (!exists($currbalancer{$balancer})) {
14239: push(@{$changes{'add'}},$balancer);
14240: }
14241: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14242: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14243: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14244: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14245: $saveloadbalancing = 1;
14246: }
14247: foreach my $sparetype (@sparestypes) {
14248: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14249: my @offloadto;
14250: foreach my $target (@targets) {
14251: if (($servers{$target}) && ($target ne $balancer)) {
14252: if ($sparetype eq 'default') {
14253: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14254: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14255: }
14256: }
1.171 raeburn 14257: unless(grep(/^\Q$target\E$/,@offloadto)) {
14258: push(@offloadto,$target);
14259: }
1.150 raeburn 14260: }
14261: }
1.284 raeburn 14262: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14263: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14264: push(@offloadto,$balancer);
14265: }
14266: }
14267: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14268: }
1.171 raeburn 14269: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14270: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14271: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14272: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14273: if (@targetdiffs > 0) {
1.171 raeburn 14274: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14275: }
1.171 raeburn 14276: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14277: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14278: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14279: }
14280: }
14281: }
14282: } else {
1.171 raeburn 14283: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 14284: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14285: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14286: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14287: $changes{'curr'}{$balancer}{'targets'} = 1;
14288: }
1.150 raeburn 14289: }
14290: }
1.210 raeburn 14291: }
1.150 raeburn 14292: }
14293: my $ishomedom;
1.171 raeburn 14294: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14295: $ishomedom = 1;
1.150 raeburn 14296: }
14297: if (ref($alltypes) eq 'ARRAY') {
14298: foreach my $type (@{$alltypes}) {
14299: my $rule;
1.210 raeburn 14300: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14301: (!$ishomedom)) {
1.171 raeburn 14302: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14303: }
14304: if ($rule eq 'specific') {
1.255 raeburn 14305: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 14306: if (exists($servers{$specifiedhost})) {
1.255 raeburn 14307: $rule = $specifiedhost;
14308: }
1.150 raeburn 14309: }
1.171 raeburn 14310: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14311: if (ref($currrules{$balancer}) eq 'HASH') {
14312: if ($rule ne $currrules{$balancer}{$type}) {
14313: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14314: }
14315: } elsif ($rule ne '') {
1.171 raeburn 14316: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14317: }
14318: }
14319: }
1.171 raeburn 14320: }
14321: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14322: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14323: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14324: $defaultshash{'loadbalancing'} = {};
14325: }
14326: my $putresult = &Apache::lonnet::put_dom('configuration',
14327: \%defaultshash,$dom);
14328: if ($putresult eq 'ok') {
14329: if (keys(%changes) > 0) {
1.252 raeburn 14330: my %toupdate;
1.171 raeburn 14331: if (ref($changes{'delete'}) eq 'ARRAY') {
14332: foreach my $balancer (sort(@{$changes{'delete'}})) {
14333: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 14334: $toupdate{$balancer} = 1;
1.150 raeburn 14335: }
1.171 raeburn 14336: }
14337: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 14338: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 14339: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 14340: $toupdate{$balancer} = 1;
1.171 raeburn 14341: }
14342: }
14343: if (ref($changes{'curr'}) eq 'HASH') {
14344: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 14345: $toupdate{$balancer} = 1;
1.171 raeburn 14346: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14347: if ($changes{'curr'}{$balancer}{'targets'}) {
14348: my %offloadstr;
14349: foreach my $sparetype (@sparestypes) {
14350: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14351: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14352: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14353: }
14354: }
1.150 raeburn 14355: }
1.171 raeburn 14356: if (keys(%offloadstr) == 0) {
14357: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14358: } else {
1.171 raeburn 14359: my $showoffload;
14360: foreach my $sparetype (@sparestypes) {
14361: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14362: if (defined($offloadstr{$sparetype})) {
14363: $showoffload .= $offloadstr{$sparetype};
14364: } else {
14365: $showoffload .= &mt('None');
14366: }
14367: $showoffload .= (' 'x3);
14368: }
14369: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14370: }
14371: }
14372: }
1.171 raeburn 14373: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14374: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14375: foreach my $type (@{$alltypes}) {
14376: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14377: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14378: my $balancetext;
14379: if ($rule eq '') {
14380: $balancetext = $ruletitles{'default'};
1.209 raeburn 14381: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 14382: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 14383: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 14384: foreach my $sparetype (@sparestypes) {
14385: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14386: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14387: }
14388: }
1.253 raeburn 14389: foreach my $item (@{$alltypes}) {
14390: next if ($item =~ /^_LC_ipchange/);
14391: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14392: if ($hasrule eq 'homeserver') {
14393: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14394: } else {
14395: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14396: if ($servers{$hasrule}) {
14397: $toupdate{$hasrule} = 1;
14398: }
14399: }
14400: }
14401: }
1.254 raeburn 14402: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14403: $balancetext = $ruletitles{$rule};
14404: } else {
14405: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14406: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14407: if ($receiver) {
14408: $toupdate{$receiver};
14409: }
14410: }
14411: } else {
14412: $balancetext = $ruletitles{$rule};
1.252 raeburn 14413: }
1.171 raeburn 14414: } else {
14415: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14416: }
1.210 raeburn 14417: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14418: }
14419: }
14420: }
14421: }
1.252 raeburn 14422: if (keys(%toupdate)) {
14423: my %thismachine;
14424: my $updatedhere;
14425: my $cachetime = 60*60*24;
14426: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14427: foreach my $lonhost (keys(%toupdate)) {
14428: if ($thismachine{$lonhost}) {
14429: unless ($updatedhere) {
14430: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14431: $defaultshash{'loadbalancing'},
14432: $cachetime);
14433: $updatedhere = 1;
14434: }
14435: } else {
14436: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14437: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14438: }
14439: }
14440: }
1.150 raeburn 14441: }
1.171 raeburn 14442: }
14443: if ($resulttext ne '') {
14444: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14445: } else {
14446: $resulttext = $nochgmsg;
14447: }
14448: } else {
1.171 raeburn 14449: $resulttext = $nochgmsg;
1.150 raeburn 14450: }
14451: } else {
1.171 raeburn 14452: $resulttext = '<span class="LC_error">'.
14453: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14454: }
14455: } else {
1.171 raeburn 14456: $resulttext = $nochgmsg;
1.150 raeburn 14457: }
14458: return $resulttext;
14459: }
14460:
1.48 raeburn 14461: sub recurse_check {
14462: my ($chkcats,$categories,$depth,$name) = @_;
14463: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14464: my $chg = 0;
14465: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14466: my $category = $chkcats->[$depth]{$name}[$j];
14467: my $item;
14468: if ($category eq '') {
14469: $chg ++;
14470: } else {
14471: my $deeper = $depth + 1;
14472: $item = &escape($category).':'.&escape($name).':'.$depth;
14473: if ($chg) {
14474: $categories->{$item} -= $chg;
14475: }
14476: &recurse_check($chkcats,$categories,$deeper,$category);
14477: $deeper --;
14478: }
14479: }
14480: }
14481: return;
14482: }
14483:
14484: sub recurse_cat_deletes {
14485: my ($item,$coursecategories,$deletions) = @_;
14486: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14487: my $subdepth = $depth + 1;
14488: if (ref($coursecategories) eq 'HASH') {
14489: foreach my $subitem (keys(%{$coursecategories})) {
14490: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14491: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14492: delete($coursecategories->{$subitem});
14493: $deletions->{$subitem} = 1;
14494: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 14495: }
1.48 raeburn 14496: }
14497: }
14498: return;
14499: }
14500:
1.125 raeburn 14501: sub active_dc_picker {
1.191 raeburn 14502: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 14503: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 14504: my @domcoord = keys(%domcoords);
14505: if (keys(%currhash)) {
14506: foreach my $dc (keys(%currhash)) {
14507: unless (exists($domcoords{$dc})) {
14508: push(@domcoord,$dc);
14509: }
14510: }
14511: }
14512: @domcoord = sort(@domcoord);
1.210 raeburn 14513: my $numdcs = scalar(@domcoord);
1.191 raeburn 14514: my $rows = 0;
14515: my $table;
1.125 raeburn 14516: if ($numdcs > 1) {
1.191 raeburn 14517: $table = '<table>';
14518: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14519: my $rem = $i%($numinrow);
14520: if ($rem == 0) {
14521: if ($i > 0) {
1.191 raeburn 14522: $table .= '</tr>';
1.125 raeburn 14523: }
1.191 raeburn 14524: $table .= '<tr>';
14525: $rows ++;
1.125 raeburn 14526: }
1.191 raeburn 14527: my $check = '';
14528: if ($inputtype eq 'radio') {
14529: if (keys(%currhash) == 0) {
14530: if (!$i) {
14531: $check = ' checked="checked"';
14532: }
14533: } elsif (exists($currhash{$domcoord[$i]})) {
14534: $check = ' checked="checked"';
14535: }
14536: } else {
14537: if (exists($currhash{$domcoord[$i]})) {
14538: $check = ' checked="checked"';
1.125 raeburn 14539: }
14540: }
1.191 raeburn 14541: if ($i == @domcoord - 1) {
1.125 raeburn 14542: my $colsleft = $numinrow - $rem;
14543: if ($colsleft > 1) {
1.191 raeburn 14544: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14545: } else {
1.191 raeburn 14546: $table .= '<td class="LC_left_item">';
1.125 raeburn 14547: }
14548: } else {
1.191 raeburn 14549: $table .= '<td class="LC_left_item">';
14550: }
14551: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14552: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14553: $table .= '<span class="LC_nobreak"><label>'.
14554: '<input type="'.$inputtype.'" name="'.$name.'"'.
14555: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14556: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 14557: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 14558: }
1.219 raeburn 14559: $table .= '</label></span></td>';
1.191 raeburn 14560: }
14561: $table .= '</tr></table>';
14562: } elsif ($numdcs == 1) {
1.219 raeburn 14563: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14564: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 14565: if ($inputtype eq 'radio') {
1.247 raeburn 14566: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 14567: if ($user ne $dcname.':'.$dcdom) {
14568: $table .= ' ('.$dcname.':'.$dcdom.')';
14569: }
1.191 raeburn 14570: } else {
14571: my $check;
14572: if (exists($currhash{$domcoord[0]})) {
14573: $check = ' checked="checked"';
1.125 raeburn 14574: }
1.247 raeburn 14575: $table = '<span class="LC_nobreak"><label>'.
14576: '<input type="checkbox" name="'.$name.'" '.
14577: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 14578: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 14579: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 14580: }
1.220 raeburn 14581: $table .= '</label></span>';
1.191 raeburn 14582: $rows ++;
1.125 raeburn 14583: }
14584: }
1.191 raeburn 14585: return ($numdcs,$table,$rows);
1.125 raeburn 14586: }
14587:
1.137 raeburn 14588: sub usersession_titles {
14589: return &Apache::lonlocal::texthash(
14590: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14591: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14592: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14593: version => 'LON-CAPA version requirement',
1.138 raeburn 14594: excludedomain => 'Allow all, but exclude specific domains',
14595: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14596: primary => 'Primary (checked first)',
1.154 raeburn 14597: default => 'Default',
1.137 raeburn 14598: );
14599: }
14600:
1.152 raeburn 14601: sub id_for_thisdom {
14602: my (%servers) = @_;
14603: my %altids;
14604: foreach my $server (keys(%servers)) {
14605: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14606: if ($serverhome ne $server) {
14607: $altids{$serverhome} = $server;
14608: }
14609: }
14610: return %altids;
14611: }
14612:
1.150 raeburn 14613: sub count_servers {
14614: my ($currbalancer,%servers) = @_;
14615: my (@spares,$numspares);
14616: foreach my $lonhost (sort(keys(%servers))) {
14617: next if ($currbalancer eq $lonhost);
14618: push(@spares,$lonhost);
14619: }
14620: if ($currbalancer) {
14621: $numspares = scalar(@spares);
14622: } else {
14623: $numspares = scalar(@spares) - 1;
14624: }
14625: return ($numspares,@spares);
14626: }
14627:
14628: sub lonbalance_targets_js {
1.171 raeburn 14629: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14630: my $select = &mt('Select');
14631: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14632: if (ref($servers) eq 'HASH') {
14633: $alltargets = join("','",sort(keys(%{$servers})));
14634: my @homedoms;
14635: foreach my $server (sort(keys(%{$servers}))) {
14636: if (&Apache::lonnet::host_domain($server) eq $dom) {
14637: push(@homedoms,'1');
14638: } else {
14639: push(@homedoms,'0');
14640: }
14641: }
14642: $allishome = join("','",@homedoms);
14643: }
14644: if (ref($types) eq 'ARRAY') {
14645: if (@{$types} > 0) {
14646: @alltypes = @{$types};
14647: }
14648: }
14649: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14650: $allinsttypes = join("','",@alltypes);
1.171 raeburn 14651: my (%currbalancer,%currtargets,%currrules,%existing);
14652: if (ref($settings) eq 'HASH') {
14653: %existing = %{$settings};
14654: }
14655: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14656: \%currtargets,\%currrules);
1.210 raeburn 14657: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14658: return <<"END";
14659:
14660: <script type="text/javascript">
14661: // <![CDATA[
14662:
1.171 raeburn 14663: currBalancers = new Array('$balancers');
14664:
14665: function toggleTargets(balnum) {
14666: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14667: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14668: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14669: var prevbalancer = prevhostitem.value;
14670: var baltotal = document.getElementById('loadbalancing_total').value;
14671: prevhostitem.value = balancer;
14672: if (prevbalancer != '') {
14673: var prevIdx = currBalancers.indexOf(prevbalancer);
14674: if (prevIdx != -1) {
14675: currBalancers.splice(prevIdx,1);
14676: }
14677: }
1.150 raeburn 14678: if (balancer == '') {
1.171 raeburn 14679: hideSpares(balnum);
1.150 raeburn 14680: } else {
1.171 raeburn 14681: var currIdx = currBalancers.indexOf(balancer);
14682: if (currIdx == -1) {
14683: currBalancers.push(balancer);
14684: }
1.150 raeburn 14685: var homedoms = new Array('$allishome');
1.171 raeburn 14686: var ishomedom = homedoms[lonhostitem.selectedIndex];
14687: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14688: }
1.171 raeburn 14689: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14690: return;
14691: }
14692:
1.171 raeburn 14693: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14694: var alltargets = new Array('$alltargets');
14695: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14696: var offloadtypes = new Array('primary','default');
14697:
1.171 raeburn 14698: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14699: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14700:
1.151 raeburn 14701: for (var i=0; i<offloadtypes.length; i++) {
14702: var count = 0;
14703: for (var j=0; j<alltargets.length; j++) {
14704: if (alltargets[j] != balancer) {
1.171 raeburn 14705: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14706: item.value = alltargets[j];
14707: item.style.textAlign='left';
14708: item.style.textFace='normal';
14709: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14710: if (currBalancers.indexOf(alltargets[j]) == -1) {
14711: item.disabled = '';
14712: } else {
14713: item.disabled = 'disabled';
14714: item.checked = false;
14715: }
1.151 raeburn 14716: count ++;
14717: }
1.150 raeburn 14718: }
14719: }
1.151 raeburn 14720: for (var k=0; k<insttypes.length; k++) {
14721: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14722: if (ishomedom == 1) {
1.171 raeburn 14723: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14724: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14725: } else {
1.171 raeburn 14726: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14727: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14728: }
14729: } else {
1.171 raeburn 14730: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14731: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14732: }
1.151 raeburn 14733: if ((insttypes[k] != '_LC_external') &&
14734: ((insttypes[k] != '_LC_internetdom') ||
14735: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 14736: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14737: item.options.length = 0;
14738: item.options[0] = new Option("","",true,true);
1.210 raeburn 14739: var idx = 0;
1.151 raeburn 14740: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 14741: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14742: idx ++;
14743: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14744: }
14745: }
14746: }
14747: }
14748: return;
14749: }
14750:
1.171 raeburn 14751: function hideSpares(balnum) {
1.150 raeburn 14752: var alltargets = new Array('$alltargets');
14753: var insttypes = new Array('$allinsttypes');
14754: var offloadtypes = new Array('primary','default');
14755:
1.171 raeburn 14756: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14757: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14758:
14759: var total = alltargets.length - 1;
14760: for (var i=0; i<offloadtypes; i++) {
14761: for (var j=0; j<total; j++) {
1.171 raeburn 14762: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14763: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14764: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14765: }
1.150 raeburn 14766: }
14767: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 14768: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14769: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14770: if (insttypes[k] != '_LC_external') {
1.171 raeburn 14771: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14772: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14773: }
14774: }
14775: return;
14776: }
14777:
1.171 raeburn 14778: function checkOffloads(item,balnum,type) {
1.150 raeburn 14779: var alltargets = new Array('$alltargets');
14780: var offloadtypes = new Array('primary','default');
14781: if (item.checked) {
14782: var total = alltargets.length - 1;
14783: var other;
14784: if (type == offloadtypes[0]) {
1.151 raeburn 14785: other = offloadtypes[1];
1.150 raeburn 14786: } else {
1.151 raeburn 14787: other = offloadtypes[0];
1.150 raeburn 14788: }
14789: for (var i=0; i<total; i++) {
1.171 raeburn 14790: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14791: if (server == item.value) {
1.171 raeburn 14792: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14793: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14794: }
14795: }
14796: }
14797: }
14798: return;
14799: }
14800:
1.171 raeburn 14801: function singleServerToggle(balnum,type) {
14802: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 14803: if (offloadtoSelIdx == 0) {
1.171 raeburn 14804: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14805: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14806:
14807: } else {
1.171 raeburn 14808: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14809: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 14810: }
14811: return;
14812: }
14813:
1.171 raeburn 14814: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 14815: if (type == '_LC_external') {
1.171 raeburn 14816: return;
1.150 raeburn 14817: }
1.171 raeburn 14818: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 14819: for (var i=0; i<typesRules.length; i++) {
14820: if (formname.elements[typesRules[i]].checked) {
14821: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 14822: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14823: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14824: } else {
1.171 raeburn 14825: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14826: }
14827: }
14828: }
14829: return;
14830: }
14831:
14832: function balancerDeleteChange(balnum) {
14833: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14834: var baltotal = document.getElementById('loadbalancing_total').value;
14835: var addtarget;
14836: var removetarget;
14837: var action = 'delete';
14838: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14839: var lonhost = hostitem.value;
14840: var currIdx = currBalancers.indexOf(lonhost);
14841: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14842: if (currIdx != -1) {
14843: currBalancers.splice(currIdx,1);
14844: }
14845: addtarget = lonhost;
14846: } else {
14847: if (currIdx == -1) {
14848: currBalancers.push(lonhost);
14849: }
14850: removetarget = lonhost;
14851: action = 'undelete';
14852: }
14853: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14854: }
14855: return;
14856: }
14857:
14858: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14859: if (baltotal > 1) {
14860: var offloadtypes = new Array('primary','default');
14861: var alltargets = new Array('$alltargets');
14862: var insttypes = new Array('$allinsttypes');
14863: for (var i=0; i<baltotal; i++) {
14864: if (i != balnum) {
14865: for (var j=0; j<offloadtypes.length; j++) {
14866: var total = alltargets.length - 1;
14867: for (var k=0; k<total; k++) {
14868: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14869: var server = serveritem.value;
14870: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14871: if (server == addtarget) {
14872: serveritem.disabled = '';
14873: }
14874: }
14875: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14876: if (server == removetarget) {
14877: serveritem.disabled = 'disabled';
14878: serveritem.checked = false;
14879: }
14880: }
14881: }
14882: }
14883: for (var j=0; j<insttypes.length; j++) {
14884: if (insttypes[j] != '_LC_external') {
14885: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14886: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14887: var currSel = singleserver.selectedIndex;
14888: var currVal = singleserver.options[currSel].value;
14889: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14890: var numoptions = singleserver.options.length;
14891: var needsnew = 1;
14892: for (var k=0; k<numoptions; k++) {
14893: if (singleserver.options[k] == addtarget) {
14894: needsnew = 0;
14895: break;
14896: }
14897: }
14898: if (needsnew == 1) {
14899: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14900: }
14901: }
14902: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14903: singleserver.options.length = 0;
14904: if ((currVal) && (currVal != removetarget)) {
14905: singleserver.options[0] = new Option("","",false,false);
14906: } else {
14907: singleserver.options[0] = new Option("","",true,true);
14908: }
14909: var idx = 0;
14910: for (var m=0; m<alltargets.length; m++) {
14911: if (currBalancers.indexOf(alltargets[m]) == -1) {
14912: idx ++;
14913: if (currVal == alltargets[m]) {
14914: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
14915: } else {
14916: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
14917: }
14918: }
14919: }
14920: }
14921: }
14922: }
14923: }
1.150 raeburn 14924: }
14925: }
14926: }
14927: return;
14928: }
14929:
1.152 raeburn 14930: // ]]>
14931: </script>
14932:
14933: END
14934: }
14935:
14936: sub new_spares_js {
14937: my @sparestypes = ('primary','default');
14938: my $types = join("','",@sparestypes);
14939: my $select = &mt('Select');
14940: return <<"END";
14941:
14942: <script type="text/javascript">
14943: // <![CDATA[
14944:
14945: function updateNewSpares(formname,lonhost) {
14946: var types = new Array('$types');
14947: var include = new Array();
14948: var exclude = new Array();
14949: for (var i=0; i<types.length; i++) {
14950: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
14951: for (var j=0; j<spareboxes.length; j++) {
14952: if (formname.elements[spareboxes[j]].checked) {
14953: exclude.push(formname.elements[spareboxes[j]].value);
14954: } else {
14955: include.push(formname.elements[spareboxes[j]].value);
14956: }
14957: }
14958: }
14959: for (var i=0; i<types.length; i++) {
14960: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
14961: var selIdx = newSpare.selectedIndex;
14962: var currnew = newSpare.options[selIdx].value;
14963: var okSpares = new Array();
14964: for (var j=0; j<newSpare.options.length; j++) {
14965: var possible = newSpare.options[j].value;
14966: if (possible != '') {
14967: if (exclude.indexOf(possible) == -1) {
14968: okSpares.push(possible);
14969: } else {
14970: if (currnew == possible) {
14971: selIdx = 0;
14972: }
14973: }
14974: }
14975: }
14976: for (var k=0; k<include.length; k++) {
14977: if (okSpares.indexOf(include[k]) == -1) {
14978: okSpares.push(include[k]);
14979: }
14980: }
14981: okSpares.sort();
14982: newSpare.options.length = 0;
14983: if (selIdx == 0) {
14984: newSpare.options[0] = new Option("$select","",true,true);
14985: } else {
14986: newSpare.options[0] = new Option("$select","",false,false);
14987: }
14988: for (var m=0; m<okSpares.length; m++) {
14989: var idx = m+1;
14990: var selThis = 0;
14991: if (selIdx != 0) {
14992: if (okSpares[m] == currnew) {
14993: selThis = 1;
14994: }
14995: }
14996: if (selThis == 1) {
14997: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
14998: } else {
14999: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15000: }
15001: }
15002: }
15003: return;
15004: }
15005:
15006: function checkNewSpares(lonhost,type) {
15007: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15008: var chosen = newSpare.options[newSpare.selectedIndex].value;
15009: if (chosen != '') {
15010: var othertype;
15011: var othernewSpare;
15012: if (type == 'primary') {
15013: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15014: }
15015: if (type == 'default') {
15016: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15017: }
15018: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15019: othernewSpare.selectedIndex = 0;
15020: }
15021: }
15022: return;
15023: }
15024:
15025: // ]]>
15026: </script>
15027:
15028: END
15029:
15030: }
15031:
15032: sub common_domprefs_js {
15033: return <<"END";
15034:
15035: <script type="text/javascript">
15036: // <![CDATA[
15037:
1.150 raeburn 15038: function getIndicesByName(formname,item) {
1.152 raeburn 15039: var group = new Array();
1.150 raeburn 15040: for (var i=0;i<formname.elements.length;i++) {
15041: if (formname.elements[i].name == item) {
1.152 raeburn 15042: group.push(formname.elements[i].id);
1.150 raeburn 15043: }
15044: }
1.152 raeburn 15045: return group;
1.150 raeburn 15046: }
15047:
15048: // ]]>
15049: </script>
15050:
15051: END
1.152 raeburn 15052:
1.150 raeburn 15053: }
15054:
1.165 raeburn 15055: sub recaptcha_js {
15056: my %lt = &captcha_phrases();
15057: return <<"END";
15058:
15059: <script type="text/javascript">
15060: // <![CDATA[
15061:
15062: function updateCaptcha(caller,context) {
15063: var privitem;
15064: var pubitem;
15065: var privtext;
15066: var pubtext;
1.269 raeburn 15067: var versionitem;
15068: var versiontext;
1.165 raeburn 15069: if (document.getElementById(context+'_recaptchapub')) {
15070: pubitem = document.getElementById(context+'_recaptchapub');
15071: } else {
15072: return;
15073: }
15074: if (document.getElementById(context+'_recaptchapriv')) {
15075: privitem = document.getElementById(context+'_recaptchapriv');
15076: } else {
15077: return;
15078: }
15079: if (document.getElementById(context+'_recaptchapubtxt')) {
15080: pubtext = document.getElementById(context+'_recaptchapubtxt');
15081: } else {
15082: return;
15083: }
15084: if (document.getElementById(context+'_recaptchaprivtxt')) {
15085: privtext = document.getElementById(context+'_recaptchaprivtxt');
15086: } else {
15087: return;
15088: }
1.269 raeburn 15089: if (document.getElementById(context+'_recaptchaversion')) {
15090: versionitem = document.getElementById(context+'_recaptchaversion');
15091: } else {
15092: return;
15093: }
15094: if (document.getElementById(context+'_recaptchavertxt')) {
15095: versiontext = document.getElementById(context+'_recaptchavertxt');
15096: } else {
15097: return;
15098: }
1.165 raeburn 15099: if (caller.checked) {
15100: if (caller.value == 'recaptcha') {
15101: pubitem.type = 'text';
15102: privitem.type = 'text';
15103: pubitem.size = '40';
15104: privitem.size = '40';
15105: pubtext.innerHTML = "$lt{'pub'}";
15106: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 15107: versionitem.type = 'text';
15108: versionitem.size = '3';
1.289 raeburn 15109: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 15110: } else {
15111: pubitem.type = 'hidden';
15112: privitem.type = 'hidden';
1.269 raeburn 15113: versionitem.type = 'hidden';
1.165 raeburn 15114: pubtext.innerHTML = '';
15115: privtext.innerHTML = '';
1.269 raeburn 15116: versiontext.innerHTML = '';
1.165 raeburn 15117: }
15118: }
15119: return;
15120: }
15121:
15122: // ]]>
15123: </script>
15124:
15125: END
15126:
15127: }
15128:
1.236 raeburn 15129: sub toggle_display_js {
1.192 raeburn 15130: return <<"END";
15131:
15132: <script type="text/javascript">
15133: // <![CDATA[
15134:
1.236 raeburn 15135: function toggleDisplay(domForm,caller) {
15136: if (document.getElementById(caller)) {
15137: var divitem = document.getElementById(caller);
15138: var optionsElement = domForm.coursecredits;
1.264 raeburn 15139: var checkval = 1;
15140: var dispval = 'block';
1.236 raeburn 15141: if (caller == 'emailoptions') {
15142: optionsElement = domForm.cancreate_email;
15143: }
1.257 raeburn 15144: if (caller == 'studentsubmission') {
15145: optionsElement = domForm.postsubmit;
15146: }
1.264 raeburn 15147: if (caller == 'cloneinstcode') {
15148: optionsElement = domForm.canclone;
15149: checkval = 'instcode';
15150: }
1.236 raeburn 15151: if (optionsElement.length) {
1.192 raeburn 15152: var currval;
1.236 raeburn 15153: for (var i=0; i<optionsElement.length; i++) {
15154: if (optionsElement[i].checked) {
15155: currval = optionsElement[i].value;
1.192 raeburn 15156: }
15157: }
1.264 raeburn 15158: if (currval == checkval) {
15159: divitem.style.display = dispval;
1.192 raeburn 15160: } else {
1.236 raeburn 15161: divitem.style.display = 'none';
1.192 raeburn 15162: }
15163: }
15164: }
15165: return;
15166: }
15167:
15168: // ]]>
15169: </script>
15170:
15171: END
15172:
15173: }
15174:
1.165 raeburn 15175: sub captcha_phrases {
15176: return &Apache::lonlocal::texthash (
15177: priv => 'Private key',
15178: pub => 'Public key',
15179: original => 'original (CAPTCHA)',
15180: recaptcha => 'successor (ReCAPTCHA)',
15181: notused => 'unused',
1.289 raeburn 15182: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 15183: );
15184: }
15185:
1.205 raeburn 15186: sub devalidate_remote_domconfs {
1.212 raeburn 15187: my ($dom,$cachekeys) = @_;
15188: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 15189: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15190: my %thismachine;
15191: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 ! raeburn 15192: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 15193: if (keys(%servers)) {
1.205 raeburn 15194: foreach my $server (keys(%servers)) {
15195: next if ($thismachine{$server});
1.212 raeburn 15196: my @cached;
15197: foreach my $name (@posscached) {
15198: if ($cachekeys->{$name}) {
15199: push(@cached,&escape($name).':'.&escape($dom));
15200: }
15201: }
15202: if (@cached) {
15203: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15204: }
1.205 raeburn 15205: }
15206: }
15207: return;
15208: }
15209:
1.3 raeburn 15210: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>