Annotation of loncom/interface/domainprefs.pm, revision 1.296
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.296 ! raeburn 4: # $Id: domainprefs.pm,v 1.295 2017/03/20 03:19:43 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)',
1.296 ! raeburn 491: help => 'Domain_Configuration_LTI_Tools',
1.267 raeburn 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: }
1.296 ! raeburn 3757: $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
! 3758: $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267 raeburn 3759: } else {
3760: $currdisp{'iframe'} = ' checked="checked"';
3761: }
3762: foreach my $disp ('iframe','window') {
3763: $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
3764: $lt{$disp}.'</label>'.(' 'x2);
3765: }
3766: $datatable .= (' 'x4);
3767: foreach my $dimen ('width','height') {
3768: $datatable .= '<label>'.$lt{$dimen}.' '.
3769: '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
3770: (' 'x2);
3771: }
1.296 ! raeburn 3772: $datatable .= '<br />'.
! 3773: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
! 3774: '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
! 3775: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
! 3776: '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
! 3777: '</textarea></div><div style=""></div><br />';
1.267 raeburn 3778: $datatable .= '<br />';
3779: foreach my $extra ('passback','roster') {
3780: my $checkedon = '';
3781: my $checkedoff = ' checked="checked"';
3782: if ($settings->{$item}->{$extra}) {
3783: $checkedon = $checkedoff;
3784: $checkedoff = '';
3785: }
3786: $datatable .= $lt{$extra}.' '.
3787: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
3788: &mt('Yes').'</label>'.(' 'x2).
3789: '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
3790: &mt('No').'</label>'.(' 'x4);
3791: }
3792: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': ';
3793: if ($imgsrc) {
3794: $datatable .= $imgsrc.
3795: '<label><input type="checkbox" name="ltitools_image_del"'.
3796: ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
3797: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
3798: } else {
3799: $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3800: }
3801: if ($switchserver) {
3802: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3803: } else {
3804: $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
3805: }
3806: $datatable .= '</span></fieldset>';
3807: my (%checkedfields,%rolemaps);
3808: if (ref($settings->{$item}) eq 'HASH') {
3809: if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
3810: %checkedfields = %{$settings->{$item}->{'fields'}};
3811: }
3812: if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
3813: %rolemaps = %{$settings->{$item}->{'roles'}};
3814: $checkedfields{'roles'} = 1;
3815: }
3816: }
3817: $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3818: '<span class="LC_nobreak">';
3819: foreach my $field (@fields) {
3820: my $checked;
3821: if ($checkedfields{$field}) {
3822: $checked = ' checked="checked"';
3823: }
3824: $datatable .= '<label>'.
3825: '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
3826: $lt{$field}.'</label>'.(' ' x2);
3827: }
3828: $datatable .= '</span></fieldset>'.
3829: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3830: foreach my $role (@courseroles) {
3831: my ($selected,$selectnone);
3832: if (!$rolemaps{$role}) {
3833: $selectnone = ' selected="selected"';
3834: }
3835: $datatable .= '<td align="center">'.
3836: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3837: '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
3838: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
3839: foreach my $ltirole (@ltiroles) {
3840: unless ($selectnone) {
3841: if ($rolemaps{$role} eq $ltirole) {
3842: $selected = ' selected="selected"';
3843: } else {
3844: $selected = '';
3845: }
3846: }
3847: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
3848: }
3849: $datatable .= '</select></td>';
3850: }
1.273 raeburn 3851: $datatable .= '</tr></table></fieldset>';
3852: my %courseconfig;
3853: if (ref($settings->{$item}) eq 'HASH') {
3854: if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
3855: %courseconfig = %{$settings->{$item}->{'crsconf'}};
3856: }
3857: }
3858: $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 ! raeburn 3859: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 3860: my $checked;
3861: if ($courseconfig{$item}) {
3862: $checked = ' checked="checked"';
3863: }
3864: $datatable .= '<label>'.
3865: '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
3866: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
3867: }
3868: $datatable .= '</span></fieldset>'.
1.267 raeburn 3869: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3870: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
3871: if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
3872: my %custom = %{$settings->{$item}->{'custom'}};
3873: if (keys(%custom) > 0) {
3874: foreach my $key (sort(keys(%custom))) {
3875: $datatable .= '<tr><td><span class="LC_nobreak">'.
3876: '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
3877: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
3878: '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
3879: ' value="'.$custom{$key}.'" /></td></tr>';
3880: }
3881: }
3882: }
3883: $datatable .= '<tr><td><span class="LC_nobreak">'.
3884: '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
3885: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
3886: '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
3887: $datatable .= '</table></fieldset></td></tr>'."\n";
3888: $itemcount ++;
3889: }
3890: }
3891: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3892: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
3893: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
3894: '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
3895: '<select name="ltitools_add_pos"'.$chgstr.'>';
3896: for (my $k=0; $k<$maxnum+1; $k++) {
3897: my $vpos = $k+1;
3898: my $selstr;
3899: if ($k == $maxnum) {
3900: $selstr = ' selected="selected" ';
3901: }
3902: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3903: }
3904: $datatable .= '</select> '."\n".
3905: '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
3906: '<td colspan="2">'.
3907: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
3908: '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
3909: (' 'x2).
3910: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
3911: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
3912: (' 'x2).
3913: '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
3914: '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
3915: '<br />'.
3916: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
3917: (' 'x2).
3918: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
3919: (' 'x2).
3920: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
3921: '<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".
3922: '</fieldset>'.
3923: '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
3924: '<span class="LC_nobreak">'.&mt('Display target:');
3925: my %defaultdisp;
3926: $defaultdisp{'iframe'} = ' checked="checked"';
3927: foreach my $disp ('iframe','window') {
3928: $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
3929: $lt{$disp}.'</label>'.(' 'x2);
3930: }
3931: $datatable .= (' 'x4);
3932: foreach my $dimen ('width','height') {
3933: $datatable .= '<label>'.$lt{$dimen}.' '.
3934: '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
3935: (' 'x2);
3936: }
1.296 ! raeburn 3937: $datatable .= '<br />'.
! 3938: '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
! 3939: '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
! 3940: '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
! 3941: '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
! 3942: '</div><div style=""></div><br />';
1.267 raeburn 3943: foreach my $extra ('passback','roster') {
3944: $datatable .= $lt{$extra}.' '.
3945: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
3946: &mt('Yes').'</label>'.(' 'x2).
3947: '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
3948: &mt('No').'</label>'.(' 'x4);
3949: }
3950: $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.': '.
3951: '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
3952: if ($switchserver) {
3953: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3954: } else {
3955: $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
3956: }
3957: $datatable .= '</span></fieldset>'.
3958: '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
3959: '<span class="LC_nobreak">';
3960: foreach my $field (@fields) {
3961: $datatable .= '<label>'.
3962: '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
3963: $lt{$field}.'</label>'.(' ' x2);
3964: }
3965: $datatable .= '</span></fieldset>'.
3966: '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
3967: foreach my $role (@courseroles) {
3968: my ($checked,$checkednone);
3969: $datatable .= '<td align="center">'.
3970: &Apache::lonnet::plaintext($role,'Course').'<br />'.
3971: '<select name="ltitools_add_roles_'.$role.'">'.
3972: '<option value="" selected="selected">'.&mt('Select').'</option>';
3973: foreach my $ltirole (@ltiroles) {
3974: $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
3975: }
3976: $datatable .= '</select></td>';
3977: }
3978: $datatable .= '</tr></table></fieldset>'.
1.273 raeburn 3979: '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.296 ! raeburn 3980: foreach my $item ('label','title','target','linktext','explanation') {
! 3981: $datatable .= '<label>'.
! 3982: '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
! 3983: $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
1.273 raeburn 3984: }
3985: $datatable .= '</span></fieldset>'.
1.267 raeburn 3986: '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
3987: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
3988: '<tr><td><span class="LC_nobreak">'.
3989: '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
3990: &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
3991: '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
3992: '</table></fieldset></td></tr>'."\n".
3993: '</td>'."\n".
3994: '</tr>'."\n";
3995: $itemcount ++;
3996: return $datatable;
3997: }
3998:
3999: sub ltitools_names {
4000: my %lt = &Apache::lonlocal::texthash(
1.296 ! raeburn 4001: 'title' => 'Title',
! 4002: 'version' => 'Version',
! 4003: 'msgtype' => 'Message Type',
! 4004: 'url' => 'URL',
! 4005: 'key' => 'Key',
! 4006: 'secret' => 'Secret',
! 4007: 'icon' => 'Icon',
! 4008: 'user' => 'Username:domain',
! 4009: 'fullname' => 'Full Name',
! 4010: 'firstname' => 'First Name',
! 4011: 'lastname' => 'Last Name',
! 4012: 'email' => 'E-mail',
! 4013: 'roles' => 'Role',
! 4014: 'window' => 'Window/Tab',
! 4015: 'iframe' => 'iFrame',
! 4016: 'height' => 'Height',
! 4017: 'width' => 'Width',
! 4018: 'linktext' => 'Default Link Text',
! 4019: 'explanation' => 'Default Explanation',
! 4020: 'passback' => 'Tool can return grades:',
! 4021: 'roster' => 'Tool can retrieve roster:',
! 4022: 'crstarget' => 'Display target',
! 4023: 'crslabel' => 'Course label',
! 4024: 'crstitle' => 'Course title',
! 4025: 'crslinktext' => 'Link Text',
! 4026: 'crsexplanation' => 'Explanation',
1.267 raeburn 4027: );
4028: return %lt;
4029: }
4030:
1.121 raeburn 4031: sub print_coursedefaults {
1.139 raeburn 4032: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 4033: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 4034: my $itemcount = 1;
1.192 raeburn 4035: my %choices = &Apache::lonlocal::texthash (
4036: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 4037: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 4038: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
4039: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 4040: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
4041: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
4042: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 4043: canclone => "People who may clone a course (besides course's owner and coordinators)",
4044: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192 raeburn 4045: );
1.198 raeburn 4046: my %staticdefaults = (
4047: anonsurvey_threshold => 10,
4048: uploadquota => 500,
1.257 raeburn 4049: postsubmit => 60,
1.276 raeburn 4050: mysqltables => 172800,
1.198 raeburn 4051: );
1.139 raeburn 4052: if ($position eq 'top') {
1.257 raeburn 4053: %defaultchecked = (
4054: 'canuse_pdfforms' => 'off',
4055: 'uselcmath' => 'on',
4056: 'usejsme' => 'on',
1.289 raeburn 4057: 'canclone' => 'none',
1.257 raeburn 4058: );
4059: @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139 raeburn 4060: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 4061: \%choices,$itemcount);
1.264 raeburn 4062: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4063: $datatable .=
4064: '<tr'.$css_class.'><td valign="top">'.
4065: '<span class="LC_nobreak">'.$choices{'canclone'}.
4066: '</span></td><td class="LC_left_item">';
4067: my $currcanclone = 'none';
4068: my $onclick;
4069: my @cloneoptions = ('none','domain');
4070: my %clonetitles = (
4071: none => 'No additional course requesters',
4072: domain => "Any course requester in course's domain",
4073: instcode => 'Course requests for official courses ...',
4074: );
4075: my (%codedefaults,@code_order,@posscodes);
4076: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
4077: \@code_order) eq 'ok') {
4078: if (@code_order > 0) {
4079: push(@cloneoptions,'instcode');
4080: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
4081: }
4082: }
4083: if (ref($settings) eq 'HASH') {
4084: if ($settings->{'canclone'}) {
4085: if (ref($settings->{'canclone'}) eq 'HASH') {
4086: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
4087: if (@code_order > 0) {
4088: $currcanclone = 'instcode';
4089: @posscodes = @{$settings->{'canclone'}{'instcode'}};
4090: }
4091: }
4092: } elsif ($settings->{'canclone'} eq 'domain') {
4093: $currcanclone = $settings->{'canclone'};
4094: }
4095: }
1.289 raeburn 4096: }
1.264 raeburn 4097: foreach my $option (@cloneoptions) {
4098: my ($checked,$additional);
4099: if ($currcanclone eq $option) {
4100: $checked = ' checked="checked"';
4101: }
4102: if ($option eq 'instcode') {
4103: if (@code_order) {
4104: my $show = 'none';
4105: if ($checked) {
4106: $show = 'block';
4107: }
4108: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
4109: &mt('Institutional codes for new and cloned course have identical:').
4110: '<br />';
4111: foreach my $item (@code_order) {
4112: my $codechk;
4113: if ($checked) {
4114: if (grep(/^\Q$item\E$/,@posscodes)) {
4115: $codechk = ' checked="checked"';
4116: }
4117: }
4118: $additional .= '<label>'.
4119: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
4120: $item.'</label>';
4121: }
4122: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
4123: }
4124: }
4125: $datatable .=
4126: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
4127: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
4128: '</label> '.$additional.'</span><br />';
4129: }
4130: $datatable .= '</td>'.
4131: '</tr>';
4132: $itemcount ++;
1.139 raeburn 4133: } else {
4134: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 4135: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 4136: my $currusecredits = 0;
1.257 raeburn 4137: my $postsubmitclient = 1;
1.271 raeburn 4138: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 4139: if (ref($settings) eq 'HASH') {
4140: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 4141: if (ref($settings->{'uploadquota'}) eq 'HASH') {
4142: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
4143: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
4144: }
4145: }
1.192 raeburn 4146: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 4147: foreach my $type (@types) {
4148: next if ($type eq 'community');
4149: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
4150: if ($defcredits{$type} ne '') {
4151: $currusecredits = 1;
4152: }
4153: }
4154: }
4155: if (ref($settings->{'postsubmit'}) eq 'HASH') {
4156: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
4157: $postsubmitclient = 0;
4158: foreach my $type (@types) {
4159: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4160: }
4161: } else {
4162: foreach my $type (@types) {
4163: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
4164: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 4165: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 4166: } else {
4167: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4168: }
4169: } else {
4170: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4171: }
4172: }
4173: }
4174: } else {
4175: foreach my $type (@types) {
4176: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 4177: }
4178: }
1.276 raeburn 4179: if (ref($settings->{'mysqltables'}) eq 'HASH') {
4180: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
4181: $currmysql{$type} = $settings->{'mysqltables'}{$type};
4182: }
4183: } else {
4184: foreach my $type (@types) {
4185: $currmysql{$type} = $staticdefaults{'mysqltables'};
4186: }
4187: }
1.258 raeburn 4188: } else {
4189: foreach my $type (@types) {
4190: $deftimeout{$type} = $staticdefaults{'postsubmit'};
4191: }
1.139 raeburn 4192: }
4193: if (!$currdefresponder) {
1.198 raeburn 4194: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 4195: } elsif ($currdefresponder < 1) {
4196: $currdefresponder = 1;
4197: }
1.198 raeburn 4198: foreach my $type (@types) {
4199: if ($curruploadquota{$type} eq '') {
4200: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
4201: }
4202: }
1.139 raeburn 4203: $datatable .=
1.192 raeburn 4204: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4205: $choices{'anonsurvey_threshold'}.
1.139 raeburn 4206: '</span></td>'.
4207: '<td class="LC_right_item"><span class="LC_nobreak">'.
4208: '<input type="text" name="anonsurvey_threshold"'.
4209: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 4210: '</td></tr>'."\n";
4211: $itemcount ++;
4212: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4213: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4214: $choices{'uploadquota'}.
4215: '</span></td>'.
4216: '<td align="right" class="LC_right_item">'.
4217: '<table><tr>';
1.198 raeburn 4218: foreach my $type (@types) {
4219: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4220: '<input type="text" name="uploadquota_'.$type.'"'.
4221: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
4222: }
4223: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 4224: $itemcount ++;
1.236 raeburn 4225: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 4226: my $display = 'none';
1.192 raeburn 4227: if ($currusecredits) {
4228: $display = 'block';
4229: }
4230: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 4231: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
4232: foreach my $type (@types) {
4233: next if ($type eq 'community');
4234: $additional .= '<td align="center">'.&mt($type).'<br />'.
4235: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 4236: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 4237: }
4238: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 4239: %defaultchecked = ('coursecredits' => 'off');
4240: @toggles = ('coursecredits');
4241: my $current = {
4242: 'coursecredits' => $currusecredits,
4243: };
4244: (my $table,$itemcount) =
4245: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 4246: \%choices,$itemcount,$onclick,$additional,'left');
4247: $datatable .= $table;
4248: $onclick = "toggleDisplay(this.form,'studentsubmission');";
4249: my $display = 'none';
4250: if ($postsubmitclient) {
4251: $display = 'block';
4252: }
4253: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 4254: &mt('Number of seconds submit is disabled').'<br />'.
4255: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
4256: '<table><tr>';
1.257 raeburn 4257: foreach my $type (@types) {
4258: $additional .= '<td align="center">'.&mt($type).'<br />'.
4259: '<input type="text" name="'.$type.'_timeout" value="'.
4260: $deftimeout{$type}.'" size="5" /></td>';
4261: }
4262: $additional .= '</tr></table></div>'."\n";
4263: %defaultchecked = ('postsubmit' => 'on');
4264: @toggles = ('postsubmit');
1.280 raeburn 4265: $current = {
4266: 'postsubmit' => $postsubmitclient,
4267: };
1.257 raeburn 4268: ($table,$itemcount) =
4269: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
4270: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 4271: $datatable .= $table;
1.276 raeburn 4272: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4273: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4274: $choices{'mysqltables'}.
4275: '</span></td>'.
4276: '<td align="right" class="LC_right_item">'.
4277: '<table><tr>';
4278: foreach my $type (@types) {
4279: $datatable .= '<td align="center">'.&mt($type).'<br />'.
4280: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 4281: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 4282: }
4283: $datatable .= '</tr></table></td></tr>'."\n";
4284: $itemcount ++;
4285:
1.139 raeburn 4286: }
1.192 raeburn 4287: $$rowtotal += $itemcount;
1.121 raeburn 4288: return $datatable;
1.118 jms 4289: }
4290:
1.231 raeburn 4291: sub print_selfenrollment {
4292: my ($position,$dom,$settings,$rowtotal) = @_;
4293: my ($css_class,$datatable);
4294: my $itemcount = 1;
1.271 raeburn 4295: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 4296: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 4297: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
4298: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 4299: my @rows;
4300: my $key;
4301: if ($position eq 'top') {
4302: $key = 'admin';
4303: if (ref($rowsref) eq 'ARRAY') {
4304: @rows = @{$rowsref};
4305: }
4306: } elsif ($position eq 'middle') {
4307: $key = 'default';
4308: @rows = ('types','registered','approval','limit');
4309: }
4310: foreach my $row (@rows) {
4311: if (defined($titlesref->{$row})) {
4312: $itemcount ++;
4313: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4314: $datatable .= '<tr'.$css_class.'>'.
4315: '<td>'.$titlesref->{$row}.'</td>'.
4316: '<td class="LC_left_item">'.
4317: '<table><tr>';
4318: my (%current,%currentcap);
4319: if (ref($settings) eq 'HASH') {
4320: if (ref($settings->{$key}) eq 'HASH') {
4321: foreach my $type (@types) {
4322: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4323: $current{$type} = $settings->{$key}->{$type}->{$row};
4324: }
4325: if (($row eq 'limit') && ($key eq 'default')) {
4326: if (ref($settings->{$key}->{$type}) eq 'HASH') {
4327: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
4328: }
4329: }
4330: }
4331: }
4332: }
4333: my %roles = (
4334: '0' => &Apache::lonnet::plaintext('dc'),
4335: );
4336:
4337: foreach my $type (@types) {
4338: unless (($row eq 'registered') && ($key eq 'default')) {
4339: $datatable .= '<th>'.&mt($type).'</th>';
4340: }
4341: }
4342: unless (($row eq 'registered') && ($key eq 'default')) {
4343: $datatable .= '</tr><tr>';
4344: }
4345: foreach my $type (@types) {
4346: if ($type eq 'community') {
4347: $roles{'1'} = &mt('Community personnel');
4348: } else {
4349: $roles{'1'} = &mt('Course personnel');
4350: }
4351: $datatable .= '<td style="vertical-align: top">';
4352: if ($position eq 'top') {
4353: my %checked;
4354: if ($current{$type} eq '0') {
4355: $checked{'0'} = ' checked="checked"';
4356: } else {
4357: $checked{'1'} = ' checked="checked"';
4358: }
4359: foreach my $role ('1','0') {
4360: $datatable .= '<span class="LC_nobreak"><label>'.
4361: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
4362: 'value="'.$role.'"'.$checked{$role}.' />'.
4363: $roles{$role}.'</label></span> ';
4364: }
4365: } else {
4366: if ($row eq 'types') {
4367: my %checked;
4368: if ($current{$type} =~ /^(all|dom)$/) {
4369: $checked{$1} = ' checked="checked"';
4370: } else {
4371: $checked{''} = ' checked="checked"';
4372: }
4373: foreach my $val ('','dom','all') {
4374: $datatable .= '<span class="LC_nobreak"><label>'.
4375: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4376: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4377: }
4378: } elsif ($row eq 'registered') {
4379: my %checked;
4380: if ($current{$type} eq '1') {
4381: $checked{'1'} = ' checked="checked"';
4382: } else {
4383: $checked{'0'} = ' checked="checked"';
4384: }
4385: foreach my $val ('0','1') {
4386: $datatable .= '<span class="LC_nobreak"><label>'.
4387: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4388: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4389: }
4390: } elsif ($row eq 'approval') {
4391: my %checked;
4392: if ($current{$type} =~ /^([12])$/) {
4393: $checked{$1} = ' checked="checked"';
4394: } else {
4395: $checked{'0'} = ' checked="checked"';
4396: }
4397: for my $val (0..2) {
4398: $datatable .= '<span class="LC_nobreak"><label>'.
4399: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4400: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4401: }
4402: } elsif ($row eq 'limit') {
4403: my %checked;
4404: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
4405: $checked{$1} = ' checked="checked"';
4406: } else {
4407: $checked{'none'} = ' checked="checked"';
4408: }
4409: my $cap;
4410: if ($currentcap{$type} =~ /^\d+$/) {
4411: $cap = $currentcap{$type};
4412: }
4413: foreach my $val ('none','allstudents','selfenrolled') {
4414: $datatable .= '<span class="LC_nobreak"><label>'.
4415: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
4416: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
4417: }
4418: $datatable .= '<br />'.
4419: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
4420: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
4421: '</span>';
4422: }
4423: }
4424: $datatable .= '</td>';
4425: }
4426: $datatable .= '</tr>';
4427: }
4428: $datatable .= '</table></td></tr>';
4429: }
4430: } elsif ($position eq 'bottom') {
1.235 raeburn 4431: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
4432: }
4433: $$rowtotal += $itemcount;
4434: return $datatable;
4435: }
4436:
4437: sub print_validation_rows {
4438: my ($caller,$dom,$settings,$rowtotal) = @_;
4439: my ($itemsref,$namesref,$fieldsref);
4440: if ($caller eq 'selfenroll') {
4441: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
4442: } elsif ($caller eq 'requestcourses') {
4443: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
4444: }
4445: my %currvalidation;
4446: if (ref($settings) eq 'HASH') {
4447: if (ref($settings->{'validation'}) eq 'HASH') {
4448: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 4449: }
1.235 raeburn 4450: }
4451: my $datatable;
4452: my $itemcount = 0;
4453: foreach my $item (@{$itemsref}) {
4454: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4455: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
4456: $namesref->{$item}.
4457: '</span></td>'.
4458: '<td class="LC_left_item">';
4459: if (($item eq 'url') || ($item eq 'button')) {
4460: $datatable .= '<span class="LC_nobreak">'.
4461: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
4462: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
4463: } elsif ($item eq 'fields') {
4464: my @currfields;
4465: if (ref($currvalidation{$item}) eq 'ARRAY') {
4466: @currfields = @{$currvalidation{$item}};
4467: }
4468: foreach my $field (@{$fieldsref}) {
4469: my $check = '';
4470: if (grep(/^\Q$field\E$/,@currfields)) {
4471: $check = ' checked="checked"';
4472: }
4473: $datatable .= '<span class="LC_nobreak"><label>'.
4474: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
4475: ' value="'.$field.'"'.$check.' />'.$field.
4476: '</label></span> ';
4477: }
4478: } elsif ($item eq 'markup') {
4479: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
4480: $currvalidation{$item}.
1.231 raeburn 4481: '</textarea>';
1.235 raeburn 4482: }
4483: $datatable .= '</td></tr>'."\n";
4484: if (ref($rowtotal)) {
1.231 raeburn 4485: $itemcount ++;
4486: }
4487: }
1.235 raeburn 4488: if ($caller eq 'requestcourses') {
4489: my %currhash;
1.248 raeburn 4490: if (ref($settings) eq 'HASH') {
4491: if (ref($settings->{'validation'}) eq 'HASH') {
4492: if ($settings->{'validation'}{'dc'} ne '') {
4493: $currhash{$settings->{'validation'}{'dc'}} = 1;
4494: }
1.235 raeburn 4495: }
4496: }
4497: my $numinrow = 2;
4498: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4499: 'validationdc',%currhash);
1.247 raeburn 4500: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4501: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235 raeburn 4502: if ($numdc > 1) {
1.247 raeburn 4503: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 4504: } else {
1.247 raeburn 4505: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 4506: }
1.247 raeburn 4507: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 4508: $itemcount ++;
4509: }
4510: if (ref($rowtotal)) {
4511: $$rowtotal += $itemcount;
4512: }
1.231 raeburn 4513: return $datatable;
4514: }
4515:
1.137 raeburn 4516: sub print_usersessions {
4517: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 4518: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 4519: my (%by_ip,%by_location,@intdoms,@instdoms);
4520: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 4521:
4522: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4523: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4524: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4525: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4526: if ($position eq 'top') {
1.152 raeburn 4527: if (keys(%serverhomes) > 1) {
1.145 raeburn 4528: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.261 raeburn 4529: my $curroffloadnow;
4530: if (ref($settings) eq 'HASH') {
4531: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4532: $curroffloadnow = $settings->{'offloadnow'};
4533: }
4534: }
4535: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4536: } else {
1.140 raeburn 4537: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 4538: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
4539: '</td></tr>';
1.140 raeburn 4540: }
1.137 raeburn 4541: } else {
1.279 raeburn 4542: my %titles = &usersession_titles();
4543: my ($prefix,@types);
4544: if ($position eq 'bottom') {
4545: $prefix = 'remote';
4546: @types = ('version','excludedomain','includedomain');
1.145 raeburn 4547: } else {
1.279 raeburn 4548: $prefix = 'hosted';
4549: @types = ('excludedomain','includedomain');
4550: }
4551: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4552: }
4553: $$rowtotal += $itemcount;
4554: return $datatable;
4555: }
4556:
4557: sub rules_by_location {
4558: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
4559: my ($datatable,$itemcount,$css_class);
4560: if (keys(%{$by_location}) == 0) {
4561: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4562: $datatable = '<tr'.$css_class.'><td colspan="2">'.
4563: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
4564: '</td></tr>';
4565: $itemcount = 1;
4566: } else {
4567: $itemcount = 0;
4568: my $numinrow = 5;
4569: my (%current,%checkedon,%checkedoff);
4570: my @locations = sort(keys(%{$by_location}));
4571: foreach my $type (@{$types}) {
4572: $checkedon{$type} = '';
4573: $checkedoff{$type} = ' checked="checked"';
4574: }
4575: if (ref($settings) eq 'HASH') {
4576: if (ref($settings->{$prefix}) eq 'HASH') {
4577: foreach my $key (keys(%{$settings->{$prefix}})) {
4578: $current{$key} = $settings->{$prefix}{$key};
4579: if ($key eq 'version') {
4580: if ($current{$key} ne '') {
1.145 raeburn 4581: $checkedon{$key} = ' checked="checked"';
4582: $checkedoff{$key} = '';
4583: }
1.279 raeburn 4584: } elsif (ref($current{$key}) eq 'ARRAY') {
4585: $checkedon{$key} = ' checked="checked"';
4586: $checkedoff{$key} = '';
1.137 raeburn 4587: }
4588: }
4589: }
1.279 raeburn 4590: }
4591: foreach my $type (@{$types}) {
4592: next if ($type ne 'version' && !@locations);
4593: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4594: $datatable .= '<tr'.$css_class.'>
4595: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
4596: <span class="LC_nobreak">
4597: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4598: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4599: if ($type eq 'version') {
4600: my @lcversions = &Apache::lonnet::all_loncaparevs();
4601: my $selector = '<select name="'.$prefix.'_version">';
4602: foreach my $version (@lcversions) {
4603: my $selected = '';
4604: if ($current{'version'} eq $version) {
4605: $selected = ' selected="selected"';
1.145 raeburn 4606: }
1.279 raeburn 4607: $selector .= ' <option value="'.$version.'"'.
4608: $selected.'>'.$version.'</option>';
4609: }
4610: $selector .= '</select> ';
4611: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4612: } else {
4613: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4614: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4615: ' />'.(' 'x2).
4616: '<input type="button" value="'.&mt('uncheck all').'" '.
4617: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4618: "\n".
4619: '</div><div><table>';
4620: my $rem;
4621: for (my $i=0; $i<@locations; $i++) {
4622: my ($showloc,$value,$checkedtype);
4623: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
4624: my $ip = $by_location->{$locations[$i]}->[0];
4625: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4626: $value = join(':',@{$by_ip->{$ip}});
4627: $showloc = join(', ',@{$by_ip->{$ip}});
4628: if (ref($current{$type}) eq 'ARRAY') {
4629: foreach my $loc (@{$by_ip->{$ip}}) {
4630: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4631: $checkedtype = ' checked="checked"';
4632: last;
1.145 raeburn 4633: }
1.138 raeburn 4634: }
4635: }
4636: }
1.137 raeburn 4637: }
1.279 raeburn 4638: $rem = $i%($numinrow);
4639: if ($rem == 0) {
4640: if ($i > 0) {
4641: $datatable .= '</tr>';
4642: }
4643: $datatable .= '<tr>';
4644: }
4645: $datatable .= '<td class="LC_left_item">'.
4646: '<span class="LC_nobreak"><label>'.
4647: '<input type="checkbox" name="'.$prefix.'_'.$type.
4648: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4649: '</label></span></td>';
4650: }
4651: $rem = @locations%($numinrow);
4652: my $colsleft = $numinrow - $rem;
4653: if ($colsleft > 1 ) {
4654: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4655: ' </td>';
4656: } elsif ($colsleft == 1) {
4657: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4658: }
1.279 raeburn 4659: $datatable .= '</tr></table>';
1.137 raeburn 4660: }
1.279 raeburn 4661: $datatable .= '</td></tr>';
4662: $itemcount ++;
1.137 raeburn 4663: }
4664: }
1.279 raeburn 4665: return ($datatable,$itemcount);
1.137 raeburn 4666: }
4667:
1.275 raeburn 4668: sub print_ssl {
4669: my ($position,$dom,$settings,$rowtotal) = @_;
4670: my ($css_class,$datatable);
4671: my $itemcount = 1;
4672: if ($position eq 'top') {
1.281 raeburn 4673: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4674: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4675: my $same_institution;
4676: if ($intdom ne '') {
4677: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
4678: if (ref($internet_names) eq 'ARRAY') {
4679: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
4680: $same_institution = 1;
4681: }
4682: }
4683: }
1.275 raeburn 4684: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 4685: $datatable = '<tr'.$css_class.'><td colspan="2">';
4686: if ($same_institution) {
4687: my %domservers = &Apache::lonnet::get_servers($dom);
4688: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
4689: } else {
4690: $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.");
4691: }
4692: $datatable .= '</td></tr>';
1.275 raeburn 4693: $itemcount ++;
4694: } else {
4695: my %titles = &ssl_titles();
4696: my (%by_ip,%by_location,@intdoms,@instdoms);
4697: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4698: my @alldoms = &Apache::lonnet::all_domains();
4699: my %serverhomes = %Apache::lonnet::serverhomeIDs;
4700: my @domservers = &Apache::lonnet::get_servers($dom);
4701: my %servers = &Apache::lonnet::internet_dom_servers($dom);
4702: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 4703: if (($position eq 'connto') || ($position eq 'connfrom')) {
4704: my $legacy;
4705: unless (ref($settings) eq 'HASH') {
4706: my $name;
4707: if ($position eq 'connto') {
4708: $name = 'loncAllowInsecure';
4709: } else {
4710: $name = 'londAllowInsecure';
4711: }
4712: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
4713: my @ids=&Apache::lonnet::current_machine_ids();
4714: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
4715: my %what = (
4716: $name => 1,
4717: );
4718: my ($result,$returnhash) =
4719: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
4720: if ($result eq 'ok') {
4721: if (ref($returnhash) eq 'HASH') {
4722: $legacy = $returnhash->{$name};
4723: }
4724: }
4725: } else {
4726: $legacy = $Apache::lonnet::perlvar{$name};
4727: }
4728: }
1.275 raeburn 4729: foreach my $type ('dom','intdom','other') {
4730: my %checked;
4731: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4732: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
4733: '<td class="LC_right_item">';
4734: my $skip;
4735: if ($type eq 'dom') {
4736: unless (keys(%servers) > 1) {
4737: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
4738: $skip = 1;
4739: }
4740: }
4741: if ($type eq 'intdom') {
4742: unless (@instdoms > 1) {
4743: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
4744: $skip = 1;
4745: }
4746: } elsif ($type eq 'other') {
4747: if (keys(%by_location) == 0) {
4748: $datatable .= &mt('Nothing to set here, as there are no other institutions');
4749: $skip = 1;
4750: }
4751: }
4752: unless ($skip) {
4753: $checked{'yes'} = ' checked="checked"';
4754: if (ref($settings) eq 'HASH') {
1.293 raeburn 4755: if (ref($settings->{$position}) eq 'HASH') {
4756: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 4757: $checked{$1} = $checked{'yes'};
4758: delete($checked{'yes'});
4759: }
4760: }
1.293 raeburn 4761: } else {
4762: if ($legacy == 0) {
4763: $checked{'req'} = $checked{'yes'};
4764: delete($checked{'yes'});
4765: }
1.275 raeburn 4766: }
4767: foreach my $option ('no','yes','req') {
4768: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 4769: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 4770: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
4771: '</label></span>'.(' 'x2);
4772: }
4773: }
4774: $datatable .= '</td></tr>';
4775: $itemcount ++;
4776: }
4777: } else {
4778: my $prefix = 'replication';
4779: my @types = ('certreq','nocertreq');
1.279 raeburn 4780: if (keys(%by_location) == 0) {
4781: $datatable .= '<tr'.$css_class.'><td>'.
4782: &mt('Nothing to set here, as there are no other institutions').
4783: '</td></tr>';
4784: $itemcount ++;
1.275 raeburn 4785: } else {
1.279 raeburn 4786: ($datatable,$itemcount) =
4787: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 4788: }
4789: }
4790: }
4791: $$rowtotal += $itemcount;
4792: return $datatable;
4793: }
4794:
4795: sub ssl_titles {
4796: return &Apache::lonlocal::texthash (
4797: dom => 'LON-CAPA servers/VMs from same domain',
4798: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
4799: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 4800: connto => 'Connections to other servers',
4801: connfrom => 'Connections from other servers',
1.275 raeburn 4802: replication => 'Replicating content to other institutions',
4803: certreq => 'Client certificate required, but specific domains exempt',
4804: nocertreq => 'No client certificate required, except for specific domains',
4805: no => 'SSL not used',
4806: yes => 'SSL Optional (used if available)',
4807: req => 'SSL Required',
4808: );
1.279 raeburn 4809: }
4810:
4811: sub print_trust {
4812: my ($prefix,$dom,$settings,$rowtotal) = @_;
4813: my ($css_class,$datatable,%checked,%choices);
4814: my (%by_ip,%by_location,@intdoms,@instdoms);
4815: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
4816: my $itemcount = 1;
4817: my %titles = &trust_titles();
4818: my @types = ('exc','inc');
4819: if ($prefix eq 'top') {
4820: $prefix = 'content';
4821: } elsif ($prefix eq 'bottom') {
4822: $prefix = 'msg';
4823: }
4824: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
4825: $$rowtotal += $itemcount;
4826: return $datatable;
4827: }
4828:
4829: sub trust_titles {
4830: return &Apache::lonlocal::texthash(
4831: content => "Access to this domain's content by others",
4832: shared => "Access to other domain's content by this domain",
4833: enroll => "Enrollment in this domain's courses by others",
4834: othcoau => "Co-author roles in this domain for others",
4835: coaurem => "Co-author roles for this domain's users elsewhere",
4836: domroles => "Domain roles in this domain assignable to others",
4837: catalog => "Course Catalog for this domain displayed elsewhere",
4838: reqcrs => "Requests for creation of courses in this domain by others",
4839: msg => "Users in other domains can send messages to this domain",
4840: exc => "Allow all, but exclude specific domains",
4841: inc => "Deny all, but include specific domains",
4842: );
1.275 raeburn 4843: }
4844:
1.138 raeburn 4845: sub build_location_hashes {
1.275 raeburn 4846: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 4847: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 4848: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 4849: my %iphost = &Apache::lonnet::get_iphost();
4850: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4851: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4852: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4853: foreach my $id (@{$iphost{$primary_ip}}) {
4854: my $intdom = &Apache::lonnet::internet_dom($id);
4855: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4856: push(@{$intdoms},$intdom);
4857: }
4858: }
4859: }
4860: foreach my $ip (keys(%iphost)) {
4861: if (ref($iphost{$ip}) eq 'ARRAY') {
4862: foreach my $id (@{$iphost{$ip}}) {
4863: my $location = &Apache::lonnet::internet_dom($id);
4864: if ($location) {
1.275 raeburn 4865: if (grep(/^\Q$location\E$/,@{$intdoms})) {
4866: my $dom = &Apache::lonnet::host_domain($id);
4867: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
4868: push(@{$instdoms},$dom);
4869: }
4870: next;
4871: }
1.138 raeburn 4872: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4873: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4874: push(@{$by_ip->{$ip}},$location);
4875: }
4876: } else {
4877: $by_ip->{$ip} = [$location];
4878: }
4879: }
4880: }
4881: }
4882: }
4883: foreach my $ip (sort(keys(%{$by_ip}))) {
4884: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4885: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4886: my $first = $by_ip->{$ip}->[0];
4887: if (ref($by_location->{$first}) eq 'ARRAY') {
4888: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4889: push(@{$by_location->{$first}},$ip);
4890: }
4891: } else {
4892: $by_location->{$first} = [$ip];
4893: }
4894: }
4895: }
4896: return;
4897: }
4898:
1.145 raeburn 4899: sub current_offloads_to {
4900: my ($dom,$settings,$servers) = @_;
4901: my (%spareid,%otherdomconfigs);
1.152 raeburn 4902: if (ref($servers) eq 'HASH') {
1.145 raeburn 4903: foreach my $lonhost (sort(keys(%{$servers}))) {
4904: my $gotspares;
1.152 raeburn 4905: if (ref($settings) eq 'HASH') {
4906: if (ref($settings->{'spares'}) eq 'HASH') {
4907: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4908: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4909: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4910: $gotspares = 1;
4911: }
1.145 raeburn 4912: }
4913: }
4914: unless ($gotspares) {
4915: my $gotspares;
4916: my $serverhomeID =
4917: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4918: my $serverhomedom =
4919: &Apache::lonnet::host_domain($serverhomeID);
4920: if ($serverhomedom ne $dom) {
4921: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4922: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4923: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4924: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4925: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4926: $gotspares = 1;
4927: }
4928: }
4929: } else {
4930: $otherdomconfigs{$serverhomedom} =
4931: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4932: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4933: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4934: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4935: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4936: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4937: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4938: $gotspares = 1;
4939: }
4940: }
4941: }
4942: }
4943: }
4944: }
4945: }
4946: unless ($gotspares) {
4947: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4948: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4949: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4950: } else {
4951: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4952: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4953: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4954: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4955: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4956: } else {
1.150 raeburn 4957: my %what = (
4958: spareid => 1,
4959: );
4960: my ($result,$returnhash) =
4961: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4962: if ($result eq 'ok') {
4963: if (ref($returnhash) eq 'HASH') {
4964: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4965: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4966: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4967: }
4968: }
1.145 raeburn 4969: }
4970: }
4971: }
4972: }
4973: }
4974: }
4975: return %spareid;
4976: }
4977:
4978: sub spares_row {
1.261 raeburn 4979: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4980: my $css_class;
4981: my $numinrow = 4;
4982: my $itemcount = 1;
4983: my $datatable;
1.152 raeburn 4984: my %typetitles = &sparestype_titles();
4985: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4986: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4987: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4988: my ($othercontrol,$serverdom);
4989: if ($serverhome ne $server) {
4990: $serverdom = &Apache::lonnet::host_domain($serverhome);
4991: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4992: } else {
4993: $serverdom = &Apache::lonnet::host_domain($server);
4994: if ($serverdom ne $dom) {
4995: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4996: }
4997: }
4998: next unless (ref($spareid->{$server}) eq 'HASH');
1.261 raeburn 4999: my $checkednow;
5000: if (ref($curroffloadnow) eq 'HASH') {
5001: if ($curroffloadnow->{$server}) {
5002: $checkednow = ' checked="checked"';
5003: }
5004: }
1.145 raeburn 5005: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5006: $datatable .= '<tr'.$css_class.'>
5007: <td rowspan="2">
1.183 bisitz 5008: <span class="LC_nobreak">'.
5009: &mt('[_1] when busy, offloads to:'
1.261 raeburn 5010: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 5011: '<span class="LC_nobreak">'."\n".
1.261 raeburn 5012: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
5013: ' '.&mt('Switch active users on next access').'</label></span>'.
1.183 bisitz 5014: "\n";
1.145 raeburn 5015: my (%current,%canselect);
1.152 raeburn 5016: my @choices =
5017: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
5018: foreach my $type ('primary','default') {
5019: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 5020: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
5021: my @spares = @{$spareid->{$server}{$type}};
5022: if (@spares > 0) {
1.152 raeburn 5023: if ($othercontrol) {
5024: $current{$type} = join(', ',@spares);
5025: } else {
5026: $current{$type} .= '<table>';
5027: my $numspares = scalar(@spares);
5028: for (my $i=0; $i<@spares; $i++) {
5029: my $rem = $i%($numinrow);
5030: if ($rem == 0) {
5031: if ($i > 0) {
5032: $current{$type} .= '</tr>';
5033: }
5034: $current{$type} .= '<tr>';
1.145 raeburn 5035: }
1.152 raeburn 5036: $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'".');" /> '.
5037: $spareid->{$server}{$type}[$i].
5038: '</label></td>'."\n";
5039: }
5040: my $rem = @spares%($numinrow);
5041: my $colsleft = $numinrow - $rem;
5042: if ($colsleft > 1 ) {
5043: $current{$type} .= '<td colspan="'.$colsleft.
5044: '" class="LC_left_item">'.
5045: ' </td>';
5046: } elsif ($colsleft == 1) {
5047: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 5048: }
1.152 raeburn 5049: $current{$type} .= '</tr></table>';
1.150 raeburn 5050: }
1.145 raeburn 5051: }
5052: }
5053: if ($current{$type} eq '') {
5054: $current{$type} = &mt('None specified');
5055: }
1.152 raeburn 5056: if ($othercontrol) {
5057: if ($type eq 'primary') {
5058: $canselect{$type} = $othercontrol;
5059: }
5060: } else {
5061: $canselect{$type} =
5062: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
5063: '<select name="newspare_'.$type.'_'.$server.'" '.
5064: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
5065: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
5066: if (@choices > 0) {
5067: foreach my $lonhost (@choices) {
5068: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
5069: }
5070: }
5071: $canselect{$type} .= '</select>'."\n";
5072: }
5073: } else {
5074: $current{$type} = &mt('Could not be determined');
5075: if ($type eq 'primary') {
5076: $canselect{$type} = $othercontrol;
5077: }
1.145 raeburn 5078: }
1.152 raeburn 5079: if ($type eq 'default') {
5080: $datatable .= '<tr'.$css_class.'>';
5081: }
5082: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
5083: '<td>'.$current{$type}.'</td>'."\n".
5084: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 5085: }
5086: $itemcount ++;
5087: }
5088: }
5089: $$rowtotal += $itemcount;
5090: return $datatable;
5091: }
5092:
1.152 raeburn 5093: sub possible_newspares {
5094: my ($server,$currspares,$serverhomes,$altids) = @_;
5095: my $serverhostname = &Apache::lonnet::hostname($server);
5096: my %excluded;
5097: if ($serverhostname ne '') {
5098: %excluded = (
5099: $serverhostname => 1,
5100: );
5101: }
5102: if (ref($currspares) eq 'HASH') {
5103: foreach my $type (keys(%{$currspares})) {
5104: if (ref($currspares->{$type}) eq 'ARRAY') {
5105: if (@{$currspares->{$type}} > 0) {
5106: foreach my $curr (@{$currspares->{$type}}) {
5107: my $hostname = &Apache::lonnet::hostname($curr);
5108: $excluded{$hostname} = 1;
5109: }
5110: }
5111: }
5112: }
5113: }
5114: my @choices;
5115: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
5116: if (keys(%{$serverhomes}) > 1) {
5117: foreach my $name (sort(keys(%{$serverhomes}))) {
5118: unless ($excluded{$name}) {
5119: if (exists($altids->{$serverhomes->{$name}})) {
5120: push(@choices,$altids->{$serverhomes->{$name}});
5121: } else {
5122: push(@choices,$serverhomes->{$name});
1.145 raeburn 5123: }
5124: }
5125: }
5126: }
5127: }
1.152 raeburn 5128: return sort(@choices);
1.145 raeburn 5129: }
5130:
1.150 raeburn 5131: sub print_loadbalancing {
5132: my ($dom,$settings,$rowtotal) = @_;
5133: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5134: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5135: my $numinrow = 1;
5136: my $datatable;
5137: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 5138: my (%currbalancer,%currtargets,%currrules,%existing);
5139: if (ref($settings) eq 'HASH') {
5140: %existing = %{$settings};
5141: }
5142: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
5143: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
5144: \%currtargets,\%currrules);
1.150 raeburn 5145: } else {
5146: return;
5147: }
5148: my ($othertitle,$usertypes,$types) =
5149: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 5150: my $rownum = 8;
1.150 raeburn 5151: if (ref($types) eq 'ARRAY') {
5152: $rownum += scalar(@{$types});
5153: }
1.171 raeburn 5154: my @css_class = ('LC_odd_row','LC_even_row');
5155: my $balnum = 0;
5156: my $islast;
5157: my (@toshow,$disabledtext);
5158: if (keys(%currbalancer) > 0) {
5159: @toshow = sort(keys(%currbalancer));
5160: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
5161: push(@toshow,'');
5162: }
5163: } else {
5164: @toshow = ('');
5165: $disabledtext = &mt('No existing load balancer');
5166: }
5167: foreach my $lonhost (@toshow) {
5168: if ($balnum == scalar(@toshow)-1) {
5169: $islast = 1;
5170: } else {
5171: $islast = 0;
5172: }
5173: my $cssidx = $balnum%2;
5174: my $targets_div_style = 'display: none';
5175: my $disabled_div_style = 'display: block';
5176: my $homedom_div_style = 'display: none';
5177: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
5178: '<td rowspan="'.$rownum.'" valign="top">'.
5179: '<p>';
5180: if ($lonhost eq '') {
1.210 raeburn 5181: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 5182: if (keys(%currbalancer) > 0) {
5183: $datatable .= &mt('Add balancer:');
5184: } else {
5185: $datatable .= &mt('Enable balancer:');
5186: }
5187: $datatable .= ' '.
5188: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
5189: ' id="loadbalancing_lonhost_'.$balnum.'"'.
5190: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
5191: '<option value="" selected="selected">'.&mt('None').
5192: '</option>'."\n";
5193: foreach my $server (sort(keys(%servers))) {
5194: next if ($currbalancer{$server});
5195: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
5196: }
1.210 raeburn 5197: $datatable .=
1.171 raeburn 5198: '</select>'."\n".
5199: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
5200: } else {
5201: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
5202: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
5203: &mt('Stop balancing').'</label>'.
5204: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
5205: $targets_div_style = 'display: block';
5206: $disabled_div_style = 'display: none';
5207: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
5208: $homedom_div_style = 'display: block';
5209: }
5210: }
5211: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
5212: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
5213: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
5214: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
5215: my ($numspares,@spares) = &count_servers($lonhost,%servers);
5216: my @sparestypes = ('primary','default');
5217: my %typetitles = &sparestype_titles();
1.284 raeburn 5218: my %hostherechecked = (
5219: no => ' checked="checked"',
5220: );
1.171 raeburn 5221: foreach my $sparetype (@sparestypes) {
5222: my $targettable;
5223: for (my $i=0; $i<$numspares; $i++) {
5224: my $checked;
5225: if (ref($currtargets{$lonhost}) eq 'HASH') {
5226: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5227: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5228: $checked = ' checked="checked"';
5229: }
5230: }
5231: }
5232: my ($chkboxval,$disabled);
5233: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
5234: $chkboxval = $spares[$i];
5235: }
5236: if (exists($currbalancer{$spares[$i]})) {
5237: $disabled = ' disabled="disabled"';
5238: }
1.210 raeburn 5239: $targettable .=
1.253 raeburn 5240: '<td><span class="LC_nobreak"><label>'.
5241: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 5242: $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 5243: '</span></label></span></td>';
1.171 raeburn 5244: my $rem = $i%($numinrow);
5245: if ($rem == 0) {
5246: if (($i > 0) && ($i < $numspares-1)) {
5247: $targettable .= '</tr>';
5248: }
5249: if ($i < $numspares-1) {
5250: $targettable .= '<tr>';
1.150 raeburn 5251: }
5252: }
5253: }
1.171 raeburn 5254: if ($targettable ne '') {
5255: my $rem = $numspares%($numinrow);
5256: my $colsleft = $numinrow - $rem;
5257: if ($colsleft > 1 ) {
5258: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5259: ' </td>';
5260: } elsif ($colsleft == 1) {
5261: $targettable .= '<td class="LC_left_item"> </td>';
5262: }
5263: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
5264: '<table><tr>'.$targettable.'</tr></table><br />';
5265: }
1.284 raeburn 5266: $hostherechecked{$sparetype} = '';
5267: if (ref($currtargets{$lonhost}) eq 'HASH') {
5268: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
5269: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
5270: $hostherechecked{$sparetype} = ' checked="checked"';
5271: $hostherechecked{'no'} = '';
5272: }
5273: }
5274: }
5275: }
5276: $datatable .= &mt('Hosting on balancer itself').'<br />'.
5277: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
5278: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
5279: foreach my $sparetype (@sparestypes) {
5280: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
5281: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
5282: '</i></label><br />';
1.171 raeburn 5283: }
5284: $datatable .= '</div></td></tr>'.
5285: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
5286: $othertitle,$usertypes,$types,\%servers,
5287: \%currbalancer,$lonhost,
5288: $targets_div_style,$homedom_div_style,
5289: $css_class[$cssidx],$balnum,$islast);
5290: $$rowtotal += $rownum;
5291: $balnum ++;
5292: }
5293: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
5294: return $datatable;
5295: }
5296:
5297: sub get_loadbalancers_config {
5298: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
5299: return unless ((ref($servers) eq 'HASH') &&
5300: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
5301: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
5302: if (keys(%{$existing}) > 0) {
5303: my $oldlonhost;
5304: foreach my $key (sort(keys(%{$existing}))) {
5305: if ($key eq 'lonhost') {
5306: $oldlonhost = $existing->{'lonhost'};
5307: $currbalancer->{$oldlonhost} = 1;
5308: } elsif ($key eq 'targets') {
5309: if ($oldlonhost) {
5310: $currtargets->{$oldlonhost} = $existing->{'targets'};
5311: }
5312: } elsif ($key eq 'rules') {
5313: if ($oldlonhost) {
5314: $currrules->{$oldlonhost} = $existing->{'rules'};
5315: }
5316: } elsif (ref($existing->{$key}) eq 'HASH') {
5317: $currbalancer->{$key} = 1;
5318: $currtargets->{$key} = $existing->{$key}{'targets'};
5319: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 5320: }
5321: }
1.171 raeburn 5322: } else {
5323: my ($balancerref,$targetsref) =
5324: &Apache::lonnet::get_lonbalancer_config($servers);
5325: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
5326: foreach my $server (sort(keys(%{$balancerref}))) {
5327: $currbalancer->{$server} = 1;
5328: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 5329: }
5330: }
5331: }
1.171 raeburn 5332: return;
1.150 raeburn 5333: }
5334:
5335: sub loadbalancing_rules {
5336: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 5337: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
5338: $css_class,$balnum,$islast) = @_;
1.150 raeburn 5339: my $output;
1.171 raeburn 5340: my $num = 0;
1.210 raeburn 5341: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 5342: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
5343: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
5344: foreach my $type (@{$alltypes}) {
1.171 raeburn 5345: $num ++;
1.150 raeburn 5346: my $current;
5347: if (ref($currrules) eq 'HASH') {
5348: $current = $currrules->{$type};
5349: }
1.253 raeburn 5350: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 5351: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 5352: $current = '';
5353: }
5354: }
5355: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 5356: $servers,$currbalancer,$lonhost,$dom,
5357: $targets_div_style,$homedom_div_style,
5358: $css_class,$balnum,$num,$islast);
1.150 raeburn 5359: }
5360: }
5361: return $output;
5362: }
5363:
5364: sub loadbalancing_titles {
5365: my ($dom,$intdom,$usertypes,$types) = @_;
5366: my %othertypes = (
5367: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
5368: '_LC_author' => &mt('Users from [_1] with author role',$dom),
5369: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
5370: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 5371: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
5372: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 5373: );
1.209 raeburn 5374: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 5375: if (ref($types) eq 'ARRAY') {
5376: unshift(@alltypes,@{$types},'default');
5377: }
5378: my %titles;
5379: foreach my $type (@alltypes) {
5380: if ($type =~ /^_LC_/) {
5381: $titles{$type} = $othertypes{$type};
5382: } elsif ($type eq 'default') {
5383: $titles{$type} = &mt('All users from [_1]',$dom);
5384: if (ref($types) eq 'ARRAY') {
5385: if (@{$types} > 0) {
5386: $titles{$type} = &mt('Other users from [_1]',$dom);
5387: }
5388: }
5389: } elsif (ref($usertypes) eq 'HASH') {
5390: $titles{$type} = $usertypes->{$type};
5391: }
5392: }
5393: return (\@alltypes,\%othertypes,\%titles);
5394: }
5395:
5396: sub loadbalance_rule_row {
1.171 raeburn 5397: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
5398: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 5399: my @rulenames;
1.150 raeburn 5400: my %ruletitles = &offloadtype_text();
1.209 raeburn 5401: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 5402: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 5403: } else {
1.209 raeburn 5404: @rulenames = ('default','homeserver');
5405: if ($type eq '_LC_external') {
5406: push(@rulenames,'externalbalancer');
5407: } else {
5408: push(@rulenames,'specific');
5409: }
5410: push(@rulenames,'none');
1.150 raeburn 5411: }
5412: my $style = $targets_div_style;
1.253 raeburn 5413: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 5414: $style = $homedom_div_style;
5415: }
1.171 raeburn 5416: my $space;
5417: if ($islast && $num == 1) {
5418: $space = '<div display="inline-block"> </div>';
5419: }
1.210 raeburn 5420: my $output =
1.171 raeburn 5421: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
5422: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
5423: '<td valaign="top">'.$space.
5424: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 5425: for (my $i=0; $i<@rulenames; $i++) {
5426: my $rule = $rulenames[$i];
5427: my ($checked,$extra);
5428: if ($rulenames[$i] eq 'default') {
5429: $rule = '';
5430: }
5431: if ($rulenames[$i] eq 'specific') {
5432: if (ref($servers) eq 'HASH') {
5433: my $default;
5434: if (($current ne '') && (exists($servers->{$current}))) {
5435: $checked = ' checked="checked"';
5436: }
5437: unless ($checked) {
5438: $default = ' selected="selected"';
5439: }
1.210 raeburn 5440: $extra =
1.171 raeburn 5441: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
5442: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
5443: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
5444: '<option value=""'.$default.'></option>'."\n";
5445: foreach my $server (sort(keys(%{$servers}))) {
5446: if (ref($currbalancer) eq 'HASH') {
5447: next if (exists($currbalancer->{$server}));
5448: }
1.150 raeburn 5449: my $selected;
1.171 raeburn 5450: if ($server eq $current) {
1.150 raeburn 5451: $selected = ' selected="selected"';
5452: }
1.171 raeburn 5453: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 5454: }
5455: $extra .= '</select>';
5456: }
5457: } elsif ($rule eq $current) {
5458: $checked = ' checked="checked"';
5459: }
5460: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 5461: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
5462: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
5463: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 5464: ')"'.$checked.' /> ';
5465: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
5466: $output .= $ruletitles{'particular'};
5467: } else {
5468: $output .= $ruletitles{$rulenames[$i]};
5469: }
5470: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 5471: }
5472: $output .= '</div></td></tr>'."\n";
5473: return $output;
5474: }
5475:
5476: sub offloadtype_text {
5477: my %ruletitles = &Apache::lonlocal::texthash (
5478: 'default' => 'Offloads to default destinations',
5479: 'homeserver' => "Offloads to user's home server",
5480: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
5481: 'specific' => 'Offloads to specific server',
1.161 raeburn 5482: 'none' => 'No offload',
1.209 raeburn 5483: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
5484: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 5485: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 5486: );
5487: return %ruletitles;
5488: }
5489:
5490: sub sparestype_titles {
5491: my %typestitles = &Apache::lonlocal::texthash (
5492: 'primary' => 'primary',
5493: 'default' => 'default',
5494: );
5495: return %typestitles;
5496: }
5497:
1.28 raeburn 5498: sub contact_titles {
5499: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 5500: 'supportemail' => 'Support E-mail address',
5501: 'adminemail' => 'Default Server Admin E-mail address',
5502: 'errormail' => 'Error reports to be e-mailed to',
5503: 'packagesmail' => 'Package update alerts to be e-mailed to',
5504: 'helpdeskmail' => "Helpdesk requests for this domain's users",
1.289 raeburn 5505: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
1.286 raeburn 5506: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
5507: 'requestsmail' => 'E-mail from course requests requiring approval',
5508: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 5509: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 5510: );
5511: my %short_titles = &Apache::lonlocal::texthash (
5512: adminemail => 'Admin E-mail address',
5513: supportemail => 'Support E-mail',
5514: );
5515: return (\%titles,\%short_titles);
5516: }
5517:
1.286 raeburn 5518: sub helpform_fields {
5519: my %titles = &Apache::lonlocal::texthash (
5520: 'username' => 'Name',
5521: 'user' => 'Username/domain',
5522: 'phone' => 'Phone',
5523: 'cc' => 'Cc e-mail',
5524: 'course' => 'Course Details',
5525: 'section' => 'Sections',
1.289 raeburn 5526: 'screenshot' => 'File upload',
1.286 raeburn 5527: );
5528: my @fields = ('username','phone','user','course','section','cc','screenshot');
5529: my %possoptions = (
5530: username => ['yes','no','req'],
1.289 raeburn 5531: phone => ['yes','no','req'],
1.286 raeburn 5532: user => ['yes','no'],
1.289 raeburn 5533: cc => ['yes','no'],
1.286 raeburn 5534: course => ['yes','no'],
5535: section => ['yes','no'],
5536: screenshot => ['yes','no'],
5537: );
5538: my %fieldoptions = &Apache::lonlocal::texthash (
5539: 'yes' => 'Optional',
5540: 'req' => 'Required',
5541: 'no' => "Not shown",
5542: );
5543: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
5544: }
5545:
1.72 raeburn 5546: sub tool_titles {
5547: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 5548: aboutme => 'Personal web page',
1.86 raeburn 5549: blog => 'Blog',
1.162 raeburn 5550: webdav => 'WebDAV',
1.86 raeburn 5551: portfolio => 'Portfolio',
1.88 bisitz 5552: official => 'Official courses (with institutional codes)',
5553: unofficial => 'Unofficial courses',
1.98 raeburn 5554: community => 'Communities',
1.216 raeburn 5555: textbook => 'Textbook courses',
1.271 raeburn 5556: placement => 'Placement tests',
1.86 raeburn 5557: );
1.72 raeburn 5558: return %titles;
5559: }
5560:
1.101 raeburn 5561: sub courserequest_titles {
5562: my %titles = &Apache::lonlocal::texthash (
5563: official => 'Official',
5564: unofficial => 'Unofficial',
5565: community => 'Communities',
1.216 raeburn 5566: textbook => 'Textbook',
1.271 raeburn 5567: placement => 'Placement tests',
1.101 raeburn 5568: norequest => 'Not allowed',
1.104 raeburn 5569: approval => 'Approval by Dom. Coord.',
1.101 raeburn 5570: validate => 'With validation',
5571: autolimit => 'Numerical limit',
1.103 raeburn 5572: unlimited => '(blank for unlimited)',
1.101 raeburn 5573: );
5574: return %titles;
5575: }
5576:
1.163 raeburn 5577: sub authorrequest_titles {
5578: my %titles = &Apache::lonlocal::texthash (
5579: norequest => 'Not allowed',
5580: approval => 'Approval by Dom. Coord.',
5581: automatic => 'Automatic approval',
5582: );
5583: return %titles;
1.210 raeburn 5584: }
1.163 raeburn 5585:
1.101 raeburn 5586: sub courserequest_conditions {
5587: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 5588: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 5589: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 5590: );
5591: return %conditions;
5592: }
5593:
5594:
1.27 raeburn 5595: sub print_usercreation {
1.30 raeburn 5596: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 5597: my $numinrow = 4;
1.28 raeburn 5598: my $datatable;
5599: if ($position eq 'top') {
1.30 raeburn 5600: $$rowtotal ++;
1.34 raeburn 5601: my $rowcount = 0;
1.32 raeburn 5602: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 5603: if (ref($rules) eq 'HASH') {
5604: if (keys(%{$rules}) > 0) {
1.32 raeburn 5605: $datatable .= &user_formats_row('username',$settings,$rules,
5606: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 5607: $$rowtotal ++;
1.32 raeburn 5608: $rowcount ++;
5609: }
5610: }
5611: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
5612: if (ref($idrules) eq 'HASH') {
5613: if (keys(%{$idrules}) > 0) {
5614: $datatable .= &user_formats_row('id',$settings,$idrules,
5615: $idruleorder,$numinrow,$rowcount);
5616: $$rowtotal ++;
5617: $rowcount ++;
1.28 raeburn 5618: }
5619: }
1.39 raeburn 5620: if ($rowcount == 0) {
5621: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
5622: $$rowtotal ++;
5623: $rowcount ++;
5624: }
1.34 raeburn 5625: } elsif ($position eq 'middle') {
1.224 raeburn 5626: my @creators = ('author','course','requestcrs');
1.37 raeburn 5627: my ($rules,$ruleorder) =
5628: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 5629: my %lt = &usercreation_types();
5630: my %checked;
5631: if (ref($settings) eq 'HASH') {
5632: if (ref($settings->{'cancreate'}) eq 'HASH') {
5633: foreach my $item (@creators) {
5634: $checked{$item} = $settings->{'cancreate'}{$item};
5635: }
5636: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
5637: foreach my $item (@creators) {
5638: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
5639: $checked{$item} = 'none';
5640: }
5641: }
5642: }
5643: }
5644: my $rownum = 0;
5645: foreach my $item (@creators) {
5646: $rownum ++;
1.224 raeburn 5647: if ($checked{$item} eq '') {
5648: $checked{$item} = 'any';
1.34 raeburn 5649: }
5650: my $css_class;
5651: if ($rownum%2) {
5652: $css_class = '';
5653: } else {
5654: $css_class = ' class="LC_odd_row" ';
5655: }
5656: $datatable .= '<tr'.$css_class.'>'.
5657: '<td><span class="LC_nobreak">'.$lt{$item}.
5658: '</span></td><td align="right">';
1.224 raeburn 5659: my @options = ('any');
5660: if (ref($rules) eq 'HASH') {
5661: if (keys(%{$rules}) > 0) {
5662: push(@options,('official','unofficial'));
1.37 raeburn 5663: }
5664: }
1.224 raeburn 5665: push(@options,'none');
1.37 raeburn 5666: foreach my $option (@options) {
1.50 raeburn 5667: my $type = 'radio';
1.34 raeburn 5668: my $check = ' ';
1.224 raeburn 5669: if ($checked{$item} eq $option) {
5670: $check = ' checked="checked" ';
1.34 raeburn 5671: }
5672: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5673: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5674: $item.'" value="'.$option.'"'.$check.'/> '.
5675: $lt{$option}.'</label> </span>';
5676: }
5677: $datatable .= '</td></tr>';
5678: }
1.28 raeburn 5679: } else {
5680: my @contexts = ('author','course','domain');
5681: my @authtypes = ('int','krb4','krb5','loc');
5682: my %checked;
5683: if (ref($settings) eq 'HASH') {
5684: if (ref($settings->{'authtypes'}) eq 'HASH') {
5685: foreach my $item (@contexts) {
5686: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5687: foreach my $auth (@authtypes) {
5688: if ($settings->{'authtypes'}{$item}{$auth}) {
5689: $checked{$item}{$auth} = ' checked="checked" ';
5690: }
5691: }
5692: }
5693: }
1.27 raeburn 5694: }
1.35 raeburn 5695: } else {
5696: foreach my $item (@contexts) {
1.36 raeburn 5697: foreach my $auth (@authtypes) {
1.35 raeburn 5698: $checked{$item}{$auth} = ' checked="checked" ';
5699: }
5700: }
1.27 raeburn 5701: }
1.28 raeburn 5702: my %title = &context_names();
5703: my %authname = &authtype_names();
5704: my $rownum = 0;
5705: my $css_class;
5706: foreach my $item (@contexts) {
5707: if ($rownum%2) {
5708: $css_class = '';
5709: } else {
5710: $css_class = ' class="LC_odd_row" ';
5711: }
1.30 raeburn 5712: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5713: '<td>'.$title{$item}.
5714: '</td><td class="LC_left_item">'.
5715: '<span class="LC_nobreak">';
5716: foreach my $auth (@authtypes) {
5717: $datatable .= '<label>'.
5718: '<input type="checkbox" name="'.$item.'_auth" '.
5719: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5720: $authname{$auth}.'</label> ';
5721: }
5722: $datatable .= '</span></td></tr>';
5723: $rownum ++;
1.27 raeburn 5724: }
1.30 raeburn 5725: $$rowtotal += $rownum;
1.27 raeburn 5726: }
5727: return $datatable;
5728: }
5729:
1.224 raeburn 5730: sub print_selfcreation {
5731: my ($position,$dom,$settings,$rowtotal) = @_;
1.236 raeburn 5732: my (@selfcreate,$createsettings,$processing,$datatable);
1.224 raeburn 5733: if (ref($settings) eq 'HASH') {
5734: if (ref($settings->{'cancreate'}) eq 'HASH') {
5735: $createsettings = $settings->{'cancreate'};
1.236 raeburn 5736: if (ref($createsettings) eq 'HASH') {
5737: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5738: @selfcreate = @{$createsettings->{'selfcreate'}};
5739: } elsif ($createsettings->{'selfcreate'} ne '') {
5740: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5741: @selfcreate = ('email','login','sso');
5742: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5743: @selfcreate = ($createsettings->{'selfcreate'});
5744: }
5745: }
5746: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5747: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 5748: }
5749: }
5750: }
5751: }
5752: my %radiohash;
5753: my $numinrow = 4;
5754: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5755: if ($position eq 'top') {
5756: my %choices = &Apache::lonlocal::texthash (
5757: cancreate_login => 'Institutional Login',
5758: cancreate_sso => 'Institutional Single Sign On',
5759: );
5760: my @toggles = sort(keys(%choices));
5761: my %defaultchecked = (
5762: 'cancreate_login' => 'off',
5763: 'cancreate_sso' => 'off',
5764: );
1.228 raeburn 5765: my ($onclick,$itemcount);
1.224 raeburn 5766: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5767: \%choices,$itemcount,$onclick);
1.228 raeburn 5768: $$rowtotal += $itemcount;
5769:
1.224 raeburn 5770: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5771:
5772: if (ref($usertypes) eq 'HASH') {
5773: if (keys(%{$usertypes}) > 0) {
5774: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5775: $dom,$numinrow,$othertitle,
1.228 raeburn 5776: 'statustocreate',$$rowtotal);
1.224 raeburn 5777: $$rowtotal ++;
5778: }
5779: }
1.240 raeburn 5780: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5781: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5782: $fieldtitles{'inststatus'} = &mt('Institutional status');
5783: my $rem;
5784: my $numperrow = 2;
5785: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5786: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 5787: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 5788: '<td class="LC_left_item">'."\n".
5789: '<table><tr><td>'."\n";
5790: for (my $i=0; $i<@fields; $i++) {
5791: $rem = $i%($numperrow);
5792: if ($rem == 0) {
5793: if ($i > 0) {
5794: $datatable .= '</tr>';
5795: }
5796: $datatable .= '<tr>';
5797: }
5798: my $currval;
1.248 raeburn 5799: if (ref($createsettings) eq 'HASH') {
5800: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5801: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5802: }
1.240 raeburn 5803: }
5804: $datatable .= '<td class="LC_left_item">'.
5805: '<span class="LC_nobreak">'.
5806: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5807: 'value="'.$currval.'" size="10" /> '.
5808: $fieldtitles{$fields[$i]}.'</span></td>';
5809: }
5810: my $colsleft = $numperrow - $rem;
5811: if ($colsleft > 1 ) {
5812: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5813: ' </td>';
5814: } elsif ($colsleft == 1) {
5815: $datatable .= '<td class="LC_left_item"> </td>';
5816: }
5817: $datatable .= '</tr></table></td></tr>';
5818: $$rowtotal ++;
1.224 raeburn 5819: } elsif ($position eq 'middle') {
5820: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5821: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5822: $usertypes->{'default'} = $othertitle;
5823: if (ref($types) eq 'ARRAY') {
5824: push(@{$types},'default');
5825: $usertypes->{'default'} = $othertitle;
5826: foreach my $status (@{$types}) {
5827: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228 raeburn 5828: $numinrow,$$rowtotal,$usertypes);
1.240 raeburn 5829: $$rowtotal ++;
1.224 raeburn 5830: }
5831: }
5832: } else {
1.236 raeburn 5833: my %choices = &Apache::lonlocal::texthash (
5834: cancreate_email => 'E-mail address as username',
5835: );
5836: my @toggles = sort(keys(%choices));
5837: my %defaultchecked = (
5838: 'cancreate_email' => 'off',
5839: );
5840: my $itemcount = 0;
5841: my $display = 'none';
5842: if (grep(/^\Qemail\E$/,@selfcreate)) {
5843: $display = 'block';
5844: }
5845: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5846: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5847: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5848: my $usertypes = {};
5849: my $order = [];
5850: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5851: $usertypes = $domdefaults{'inststatustypes'};
5852: $order = $domdefaults{'inststatusguest'};
5853: }
5854: if (ref($order) eq 'ARRAY') {
5855: push(@{$order},'default');
5856: if (@{$order} > 1) {
5857: $usertypes->{'default'} = &mt('Other users');
5858: $additional .= '<table><tr>';
5859: foreach my $status (@{$order}) {
5860: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5861: }
5862: $additional .= '</tr><tr>';
5863: foreach my $status (@{$order}) {
5864: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224 raeburn 5865: }
1.236 raeburn 5866: $additional .= '</tr></table>';
1.224 raeburn 5867: } else {
1.236 raeburn 5868: $usertypes->{'default'} = &mt('All users');
5869: $additional .= &email_as_username($rowtotal,$processing);
1.224 raeburn 5870: }
5871: }
1.236 raeburn 5872: $additional .= '</div>'."\n";
5873:
5874: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240 raeburn 5875: \%choices,$$rowtotal,$onclick,$additional);
5876: $$rowtotal ++;
1.236 raeburn 5877: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228 raeburn 5878: $$rowtotal ++;
1.224 raeburn 5879: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 5880: $numinrow = 1;
1.236 raeburn 5881: if (ref($order) eq 'ARRAY') {
5882: foreach my $status (@{$order}) {
1.228 raeburn 5883: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5884: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5885: $$rowtotal ++;
5886: }
5887: }
1.224 raeburn 5888: my ($emailrules,$emailruleorder) =
5889: &Apache::lonnet::inst_userrules($dom,'email');
5890: if (ref($emailrules) eq 'HASH') {
5891: if (keys(%{$emailrules}) > 0) {
5892: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228 raeburn 5893: $emailruleorder,$numinrow,$$rowtotal);
1.224 raeburn 5894: $$rowtotal ++;
5895: }
5896: }
1.228 raeburn 5897: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224 raeburn 5898: }
5899: return $datatable;
5900: }
5901:
1.236 raeburn 5902: sub email_as_username {
5903: my ($rowtotal,$processing,$type) = @_;
5904: my %choices =
5905: &Apache::lonlocal::texthash (
5906: automatic => 'Automatic approval',
5907: approval => 'Queued for approval',
5908: );
5909: my $output;
5910: foreach my $option ('automatic','approval') {
5911: my $checked;
5912: if (ref($processing) eq 'HASH') {
5913: if ($type eq '') {
5914: if (!exists($processing->{'default'})) {
5915: if ($option eq 'automatic') {
5916: $checked = ' checked="checked"';
5917: }
5918: } else {
5919: if ($processing->{'default'} eq $option) {
5920: $checked = ' checked="checked"';
5921: }
5922: }
5923: } else {
5924: if (!exists($processing->{$type})) {
5925: if ($option eq 'automatic') {
5926: $checked = ' checked="checked"';
5927: }
5928: } else {
5929: if ($processing->{$type} eq $option) {
5930: $checked = ' checked="checked"';
5931: }
5932: }
5933: }
5934: } elsif ($option eq 'automatic') {
5935: $checked = ' checked="checked"';
5936: }
5937: my $name = 'cancreate_emailprocess';
5938: if (($type ne '') && ($type ne 'default')) {
5939: $name .= '_'.$type;
5940: }
5941: $output .= '<span class="LC_nobreak"><label>'.
5942: '<input type="radio" name="'.$name.'"'.
5943: $checked.' value="'.$option.'" />'.
5944: $choices{$option}.'</label></span>';
5945: if ($type eq '') {
5946: $output .= ' ';
5947: } else {
5948: $output .= '<br />';
5949: }
5950: }
5951: $$rowtotal ++;
5952: return $output;
5953: }
5954:
1.165 raeburn 5955: sub captcha_choice {
1.169 raeburn 5956: my ($context,$settings,$itemcount) = @_;
1.269 raeburn 5957: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5958: $vertext,$currver);
1.165 raeburn 5959: my %lt = &captcha_phrases();
5960: $keyentry = 'hidden';
5961: if ($context eq 'cancreate') {
1.224 raeburn 5962: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 5963: } elsif ($context eq 'login') {
5964: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 5965: }
5966: if (ref($settings) eq 'HASH') {
5967: if ($settings->{'captcha'}) {
5968: $checked{$settings->{'captcha'}} = ' checked="checked"';
5969: } else {
5970: $checked{'original'} = ' checked="checked"';
5971: }
5972: if ($settings->{'captcha'} eq 'recaptcha') {
5973: $pubtext = $lt{'pub'};
5974: $privtext = $lt{'priv'};
5975: $keyentry = 'text';
1.269 raeburn 5976: $vertext = $lt{'ver'};
5977: $currver = $settings->{'recaptchaversion'};
5978: if ($currver ne '2') {
5979: $currver = 1;
5980: }
1.165 raeburn 5981: }
5982: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5983: $currpub = $settings->{'recaptchakeys'}{'public'};
5984: $currpriv = $settings->{'recaptchakeys'}{'private'};
5985: }
5986: } else {
5987: $checked{'original'} = ' checked="checked"';
5988: }
1.169 raeburn 5989: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5990: my $output = '<tr'.$css_class.'>'.
5991: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 5992: '<table><tr><td>'."\n";
5993: foreach my $option ('original','recaptcha','notused') {
5994: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5995: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5996: $lt{$option}.'</label></span>';
5997: unless ($option eq 'notused') {
5998: $output .= (' 'x2)."\n";
5999: }
6000: }
6001: #
6002: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
6003: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 6004: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 6005: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 6006: #
1.165 raeburn 6007: $output .= '</td></tr>'."\n".
6008: '<tr><td>'."\n".
6009: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
6010: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
6011: $currpub.'" size="40" /></span><br />'."\n".
6012: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
6013: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 6014: $currpriv.'" size="40" /></span><br />'.
6015: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
6016: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
6017: $currver.'" size="3" /></span><br />'.
6018: '</td></tr></table>'."\n".
1.165 raeburn 6019: '</td></tr>';
6020: return $output;
6021: }
6022:
1.32 raeburn 6023: sub user_formats_row {
6024: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
6025: my $output;
6026: my %text = (
6027: 'username' => 'new usernames',
6028: 'id' => 'IDs',
1.45 raeburn 6029: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 6030: );
6031: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6032: $output = '<tr '.$css_class.'>'.
1.63 raeburn 6033: '<td><span class="LC_nobreak">';
6034: if ($type eq 'email') {
6035: $output .= &mt("Formats disallowed for $text{$type}: ");
6036: } else {
6037: $output .= &mt("Format rules to check for $text{$type}: ");
6038: }
6039: $output .= '</span></td>'.
6040: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 6041: my $rem;
6042: if (ref($ruleorder) eq 'ARRAY') {
6043: for (my $i=0; $i<@{$ruleorder}; $i++) {
6044: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
6045: my $rem = $i%($numinrow);
6046: if ($rem == 0) {
6047: if ($i > 0) {
6048: $output .= '</tr>';
6049: }
6050: $output .= '<tr>';
6051: }
6052: my $check = ' ';
1.39 raeburn 6053: if (ref($settings) eq 'HASH') {
6054: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
6055: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
6056: $check = ' checked="checked" ';
6057: }
1.27 raeburn 6058: }
6059: }
6060: $output .= '<td class="LC_left_item">'.
6061: '<span class="LC_nobreak"><label>'.
1.32 raeburn 6062: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 6063: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
6064: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
6065: }
6066: }
6067: $rem = @{$ruleorder}%($numinrow);
6068: }
6069: my $colsleft = $numinrow - $rem;
6070: if ($colsleft > 1 ) {
6071: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6072: ' </td>';
6073: } elsif ($colsleft == 1) {
6074: $output .= '<td class="LC_left_item"> </td>';
6075: }
6076: $output .= '</tr></table></td></tr>';
6077: return $output;
6078: }
6079:
1.34 raeburn 6080: sub usercreation_types {
6081: my %lt = &Apache::lonlocal::texthash (
6082: author => 'When adding a co-author',
6083: course => 'When adding a user to a course',
1.100 raeburn 6084: requestcrs => 'When requesting a course',
1.34 raeburn 6085: any => 'Any',
6086: official => 'Institutional only ',
6087: unofficial => 'Non-institutional only',
6088: none => 'None',
6089: );
6090: return %lt;
1.48 raeburn 6091: }
1.34 raeburn 6092:
1.224 raeburn 6093: sub selfcreation_types {
6094: my %lt = &Apache::lonlocal::texthash (
6095: selfcreate => 'User creates own account',
6096: any => 'Any',
6097: official => 'Institutional only ',
6098: unofficial => 'Non-institutional only',
6099: email => 'E-mail address',
6100: login => 'Institutional Login',
6101: sso => 'SSO',
6102: );
6103: }
6104:
1.28 raeburn 6105: sub authtype_names {
6106: my %lt = &Apache::lonlocal::texthash(
6107: int => 'Internal',
6108: krb4 => 'Kerberos 4',
6109: krb5 => 'Kerberos 5',
6110: loc => 'Local',
6111: );
6112: return %lt;
6113: }
6114:
6115: sub context_names {
6116: my %context_title = &Apache::lonlocal::texthash(
6117: author => 'Creating users when an Author',
6118: course => 'Creating users when in a course',
6119: domain => 'Creating users when a Domain Coordinator',
6120: );
6121: return %context_title;
6122: }
6123:
1.33 raeburn 6124: sub print_usermodification {
6125: my ($position,$dom,$settings,$rowtotal) = @_;
6126: my $numinrow = 4;
6127: my ($context,$datatable,$rowcount);
6128: if ($position eq 'top') {
6129: $rowcount = 0;
6130: $context = 'author';
6131: foreach my $role ('ca','aa') {
6132: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6133: $numinrow,$rowcount);
6134: $$rowtotal ++;
6135: $rowcount ++;
6136: }
1.230 raeburn 6137: } elsif ($position eq 'bottom') {
1.33 raeburn 6138: $context = 'course';
6139: $rowcount = 0;
6140: foreach my $role ('st','ep','ta','in','cr') {
6141: $datatable .= &modifiable_userdata_row($context,$role,$settings,
6142: $numinrow,$rowcount);
6143: $$rowtotal ++;
6144: $rowcount ++;
6145: }
6146: }
6147: return $datatable;
6148: }
6149:
1.43 raeburn 6150: sub print_defaults {
1.236 raeburn 6151: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 6152: my $rownum = 0;
1.294 raeburn 6153: my ($datatable,$css_class,$titles);
6154: unless ($position eq 'bottom') {
6155: $titles = &defaults_titles($dom);
6156: }
1.236 raeburn 6157: if ($position eq 'top') {
6158: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
6159: 'datelocale_def','portal_def');
6160: my %defaults;
6161: if (ref($settings) eq 'HASH') {
6162: %defaults = %{$settings};
1.43 raeburn 6163: } else {
1.236 raeburn 6164: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
6165: foreach my $item (@items) {
6166: $defaults{$item} = $domdefaults{$item};
6167: }
1.43 raeburn 6168: }
1.236 raeburn 6169: foreach my $item (@items) {
6170: if ($rownum%2) {
6171: $css_class = '';
6172: } else {
6173: $css_class = ' class="LC_odd_row" ';
6174: }
6175: $datatable .= '<tr'.$css_class.'>'.
6176: '<td><span class="LC_nobreak">'.$titles->{$item}.
6177: '</span></td><td class="LC_right_item" colspan="3">';
6178: if ($item eq 'auth_def') {
6179: my @authtypes = ('internal','krb4','krb5','localauth');
6180: my %shortauth = (
6181: internal => 'int',
6182: krb4 => 'krb4',
6183: krb5 => 'krb5',
6184: localauth => 'loc'
6185: );
6186: my %authnames = &authtype_names();
6187: foreach my $auth (@authtypes) {
6188: my $checked = ' ';
6189: if ($defaults{$item} eq $auth) {
6190: $checked = ' checked="checked" ';
6191: }
6192: $datatable .= '<label><input type="radio" name="'.$item.
6193: '" value="'.$auth.'"'.$checked.'/>'.
6194: $authnames{$shortauth{$auth}}.'</label> ';
6195: }
6196: } elsif ($item eq 'timezone_def') {
6197: my $includeempty = 1;
6198: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
6199: } elsif ($item eq 'datelocale_def') {
6200: my $includeempty = 1;
6201: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
6202: } elsif ($item eq 'lang_def') {
1.263 raeburn 6203: my $includeempty = 1;
6204: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236 raeburn 6205: } else {
6206: my $size;
6207: if ($item eq 'portal_def') {
6208: $size = ' size="25"';
6209: }
6210: $datatable .= '<input type="text" name="'.$item.'" value="'.
6211: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 6212: }
1.236 raeburn 6213: $datatable .= '</td></tr>';
6214: $rownum ++;
6215: }
1.294 raeburn 6216: } elsif ($position eq 'middle') {
6217: my @items = ('intauth_cost','intauth_check','intauth_switch');
6218: my %defaults;
6219: if (ref($settings) eq 'HASH') {
6220: %defaults = %{$settings};
6221: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6222: $defaults{'intauth_cost'} = 10;
6223: }
6224: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6225: $defaults{'intauth_check'} = 0;
6226: }
6227: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6228: $defaults{'intauth_switch'} = 0;
6229: }
6230: } else {
6231: %defaults = (
6232: 'intauth_cost' => 10,
6233: 'intauth_check' => 0,
6234: 'intauth_switch' => 0,
6235: );
6236: }
6237: foreach my $item (@items) {
6238: if ($rownum%2) {
6239: $css_class = '';
6240: } else {
6241: $css_class = ' class="LC_odd_row" ';
6242: }
6243: $datatable .= '<tr'.$css_class.'>'.
6244: '<td><span class="LC_nobreak">'.$titles->{$item}.
6245: '</span></td><td class="LC_left_item" colspan="3">';
6246: if ($item eq 'intauth_switch') {
6247: my @options = (0,1,2);
6248: my %optiondesc = &Apache::lonlocal::texthash (
6249: 0 => 'No',
6250: 1 => 'Yes',
6251: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6252: );
6253: $datatable .= '<table width="100%">';
6254: foreach my $option (@options) {
6255: my $checked = ' ';
6256: if ($defaults{$item} eq $option) {
6257: $checked = ' checked="checked"';
6258: }
6259: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6260: '<label><input type="radio" name="'.$item.
6261: '" value="'.$option.'"'.$checked.' />'.
6262: $optiondesc{$option}.'</label></span></td></tr>';
6263: }
6264: $datatable .= '</table>';
6265: } elsif ($item eq 'intauth_check') {
6266: my @options = (0,1,2);
6267: my %optiondesc = &Apache::lonlocal::texthash (
6268: 0 => 'No',
6269: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6270: 2 => 'Yes, disallow login if stored cost is less than domain default',
6271: );
6272: $datatable .= '<table wisth="100%">';
6273: foreach my $option (@options) {
6274: my $checked = ' ';
6275: my $onclick;
6276: if ($defaults{$item} eq $option) {
6277: $checked = ' checked="checked"';
6278: }
6279: if ($option == 2) {
6280: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6281: }
6282: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6283: '<label><input type="radio" name="'.$item.
6284: '" value="'.$option.'"'.$checked.$onclick.' />'.
6285: $optiondesc{$option}.'</label></span></td></tr>';
6286: }
6287: $datatable .= '</table>';
6288: } else {
6289: $datatable .= '<input type="text" name="'.$item.'" value="'.
6290: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6291: }
6292: $datatable .= '</td></tr>';
6293: $rownum ++;
6294: }
1.236 raeburn 6295: } else {
1.294 raeburn 6296: my %defaults;
1.236 raeburn 6297: if (ref($settings) eq 'HASH') {
6298: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
6299: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
6300: my $maxnum = @{$settings->{'inststatusorder'}};
6301: for (my $i=0; $i<$maxnum; $i++) {
6302: $css_class = $rownum%2?' class="LC_odd_row"':'';
6303: my $item = $settings->{'inststatusorder'}->[$i];
6304: my $title = $settings->{'inststatustypes'}->{$item};
6305: my $guestok;
6306: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
6307: $guestok = 1;
6308: }
6309: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
6310: $datatable .= '<tr'.$css_class.'>'.
6311: '<td><span class="LC_nobreak">'.
6312: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
6313: for (my $k=0; $k<=$maxnum; $k++) {
6314: my $vpos = $k+1;
6315: my $selstr;
6316: if ($k == $i) {
6317: $selstr = ' selected="selected" ';
6318: }
6319: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6320: }
6321: my ($checkedon,$checkedoff);
6322: $checkedoff = ' checked="checked"';
6323: if ($guestok) {
6324: $checkedon = $checkedoff;
6325: $checkedoff = '';
6326: }
6327: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
6328: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
6329: &mt('delete').'</span></td>'.
6330: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
6331: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
6332: '</span></td>'.
6333: '<td class="LC_right_item"><span class="LC_nobreak">'.
6334: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
6335: &mt('Yes').'</label>'.(' 'x2).
6336: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
6337: &mt('No').'</label></span></td></tr>';
6338: }
6339: $css_class = $rownum%2?' class="LC_odd_row"':'';
6340: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
6341: $datatable .= '<tr '.$css_class.'>'.
6342: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
6343: for (my $k=0; $k<=$maxnum; $k++) {
6344: my $vpos = $k+1;
6345: my $selstr;
6346: if ($k == $maxnum) {
6347: $selstr = ' selected="selected" ';
6348: }
6349: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6350: }
6351: $datatable .= '</select> '.&mt('Internal ID:').
1.263 raeburn 6352: '<input type="text" size="10" name="addinststatus" value="" />'.
1.236 raeburn 6353: ' '.&mt('(new)').
6354: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
6355: &mt('Name displayed:').
6356: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
6357: '<td class="LC_right_item"><span class="LC_nobreak">'.
6358: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
6359: &mt('Yes').'</label>'.(' 'x2).
6360: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
6361: &mt('No').'</label></span></td></tr>';
6362: '</tr>'."\n";
6363: $rownum ++;
1.141 raeburn 6364: }
1.43 raeburn 6365: }
6366: }
6367: $$rowtotal += $rownum;
6368: return $datatable;
6369: }
6370:
1.168 raeburn 6371: sub get_languages_hash {
6372: my %langchoices;
6373: foreach my $id (&Apache::loncommon::languageids()) {
6374: my $code = &Apache::loncommon::supportedlanguagecode($id);
6375: if ($code ne '') {
6376: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
6377: }
6378: }
6379: return %langchoices;
6380: }
6381:
1.43 raeburn 6382: sub defaults_titles {
1.141 raeburn 6383: my ($dom) = @_;
1.43 raeburn 6384: my %titles = &Apache::lonlocal::texthash (
6385: 'auth_def' => 'Default authentication type',
6386: 'auth_arg_def' => 'Default authentication argument',
6387: 'lang_def' => 'Default language',
1.54 raeburn 6388: 'timezone_def' => 'Default timezone',
1.68 raeburn 6389: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6390: 'portal_def' => 'Portal/Default URL',
1.294 raeburn 6391: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6392: 'intauth_check' => 'Check bcrypt cost if authenticated',
6393: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6394: );
1.141 raeburn 6395: if ($dom) {
6396: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6397: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6398: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6399: $protocol = 'http' if ($protocol ne 'https');
6400: if ($uint_dom) {
6401: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6402: $uint_dom);
6403: }
6404: }
1.43 raeburn 6405: return (\%titles);
6406: }
6407:
1.46 raeburn 6408: sub print_scantronformat {
6409: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6410: my $itemcount = 1;
1.60 raeburn 6411: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6412: %confhash);
1.46 raeburn 6413: my $switchserver = &check_switchserver($dom,$confname);
6414: my %lt = &Apache::lonlocal::texthash (
1.95 www 6415: default => 'Default bubblesheet format file error',
6416: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6417: );
6418: my %scantronfiles = (
6419: default => 'default.tab',
6420: custom => 'custom.tab',
6421: );
6422: foreach my $key (keys(%scantronfiles)) {
6423: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6424: .$scantronfiles{$key};
6425: }
6426: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6427: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6428: if (!$switchserver) {
6429: my $servadm = $r->dir_config('lonAdmEMail');
6430: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6431: if ($configuserok eq 'ok') {
6432: if ($author_ok eq 'ok') {
6433: my %legacyfile = (
6434: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6435: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6436: );
6437: my %md5chk;
6438: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6439: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6440: chomp($md5chk{$type});
1.46 raeburn 6441: }
6442: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6443: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6444: ($scantronurls{$type},my $error) =
1.46 raeburn 6445: &legacy_scantronformat($r,$dom,$confname,
6446: $type,$legacyfile{$type},
6447: $scantronurls{$type},
6448: $scantronfiles{$type});
1.60 raeburn 6449: if ($error ne '') {
6450: $error{$type} = $error;
6451: }
6452: }
6453: if (keys(%error) == 0) {
6454: $is_custom = 1;
6455: $confhash{'scantron'}{'scantronformat'} =
6456: $scantronurls{'custom'};
6457: my $putresult =
6458: &Apache::lonnet::put_dom('configuration',
6459: \%confhash,$dom);
6460: if ($putresult ne 'ok') {
6461: $error{'custom'} =
6462: '<span class="LC_error">'.
6463: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6464: }
1.46 raeburn 6465: }
6466: } else {
1.60 raeburn 6467: ($scantronurls{'default'},my $error) =
1.46 raeburn 6468: &legacy_scantronformat($r,$dom,$confname,
6469: 'default',$legacyfile{'default'},
6470: $scantronurls{'default'},
6471: $scantronfiles{'default'});
1.60 raeburn 6472: if ($error eq '') {
6473: $confhash{'scantron'}{'scantronformat'} = '';
6474: my $putresult =
6475: &Apache::lonnet::put_dom('configuration',
6476: \%confhash,$dom);
6477: if ($putresult ne 'ok') {
6478: $error{'default'} =
6479: '<span class="LC_error">'.
6480: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6481: }
6482: } else {
6483: $error{'default'} = $error;
6484: }
1.46 raeburn 6485: }
6486: }
6487: }
6488: } else {
1.95 www 6489: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6490: }
6491: }
6492: if (ref($settings) eq 'HASH') {
6493: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6494: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6495: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6496: $scantronurl = '';
6497: } else {
6498: $scantronurl = $settings->{'scantronformat'};
6499: }
6500: $is_custom = 1;
6501: } else {
6502: $scantronurl = $scantronurls{'default'};
6503: }
6504: } else {
1.60 raeburn 6505: if ($is_custom) {
6506: $scantronurl = $scantronurls{'custom'};
6507: } else {
6508: $scantronurl = $scantronurls{'default'};
6509: }
1.46 raeburn 6510: }
6511: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6512: $datatable .= '<tr'.$css_class.'>';
6513: if (!$is_custom) {
1.65 raeburn 6514: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6515: '<span class="LC_nobreak">';
1.46 raeburn 6516: if ($scantronurl) {
1.199 raeburn 6517: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6518: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6519: } else {
6520: $datatable = &mt('File unavailable for display');
6521: }
1.65 raeburn 6522: $datatable .= '</span></td>';
1.60 raeburn 6523: if (keys(%error) == 0) {
6524: $datatable .= '<td valign="bottom">';
6525: if (!$switchserver) {
6526: $datatable .= &mt('Upload:').'<br />';
6527: }
6528: } else {
6529: my $errorstr;
6530: foreach my $key (sort(keys(%error))) {
6531: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6532: }
6533: $datatable .= '<td>'.$errorstr;
6534: }
1.46 raeburn 6535: } else {
6536: if (keys(%error) > 0) {
6537: my $errorstr;
6538: foreach my $key (sort(keys(%error))) {
6539: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6540: }
1.60 raeburn 6541: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6542: } elsif ($scantronurl) {
1.199 raeburn 6543: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
6544: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6545: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 6546: $link.
6547: '<label><input type="checkbox" name="scantronformat_del"'.
6548: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6549: '<td><span class="LC_nobreak"> '.
6550: &mt('Replace:').'</span><br />';
1.46 raeburn 6551: }
6552: }
6553: if (keys(%error) == 0) {
6554: if ($switchserver) {
6555: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6556: } else {
1.65 raeburn 6557: $datatable .='<span class="LC_nobreak"> '.
6558: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6559: }
6560: }
6561: $datatable .= '</td></tr>';
6562: $$rowtotal ++;
6563: return $datatable;
6564: }
6565:
6566: sub legacy_scantronformat {
6567: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6568: my ($url,$error);
6569: my @statinfo = &Apache::lonnet::stat_file($newurl);
6570: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6571: (my $result,$url) =
6572: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6573: '','',$newfile);
6574: if ($result ne 'ok') {
1.130 raeburn 6575: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6576: }
6577: }
6578: return ($url,$error);
6579: }
1.43 raeburn 6580:
1.49 raeburn 6581: sub print_coursecategories {
1.57 raeburn 6582: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6583: my $datatable;
6584: if ($position eq 'top') {
1.238 raeburn 6585: my (%checked);
6586: my @catitems = ('unauth','auth');
6587: my @cattypes = ('std','domonly','codesrch','none');
6588: $checked{'unauth'} = 'std';
6589: $checked{'auth'} = 'std';
6590: if (ref($settings) eq 'HASH') {
6591: foreach my $type (@cattypes) {
6592: if ($type eq $settings->{'unauth'}) {
6593: $checked{'unauth'} = $type;
6594: }
6595: if ($type eq $settings->{'auth'}) {
6596: $checked{'auth'} = $type;
6597: }
6598: }
6599: }
6600: my %lt = &Apache::lonlocal::texthash (
6601: unauth => 'Catalog type for unauthenticated users',
6602: auth => 'Catalog type for authenticated users',
6603: none => 'No catalog',
6604: std => 'Standard catalog',
6605: domonly => 'Domain-only catalog',
6606: codesrch => "Code search form",
6607: );
6608: my $itemcount = 0;
6609: foreach my $item (@catitems) {
6610: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6611: $datatable .= '<tr '.$css_class.'>'.
6612: '<td>'.$lt{$item}.'</td>'.
6613: '<td class="LC_right_item"><span class="LC_nobreak">';
6614: foreach my $type (@cattypes) {
6615: my $ischecked;
6616: if ($checked{$item} eq $type) {
6617: $ischecked=' checked="checked"';
6618: }
6619: $datatable .= '<label>'.
6620: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6621: ' />'.$lt{$type}.'</label> ';
6622: }
6623: $datatable .= '</td></tr>';
6624: $itemcount ++;
6625: }
6626: $$rowtotal += $itemcount;
6627: } elsif ($position eq 'middle') {
1.57 raeburn 6628: my $toggle_cats_crs = ' ';
6629: my $toggle_cats_dom = ' checked="checked" ';
6630: my $can_cat_crs = ' ';
6631: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6632: my $toggle_catscomm_comm = ' ';
6633: my $toggle_catscomm_dom = ' checked="checked" ';
6634: my $can_catcomm_comm = ' ';
6635: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 6636: my $toggle_catsplace_place = ' ';
6637: my $toggle_catsplace_dom = ' checked="checked" ';
6638: my $can_catplace_place = ' ';
6639: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 6640:
1.57 raeburn 6641: if (ref($settings) eq 'HASH') {
6642: if ($settings->{'togglecats'} eq 'crs') {
6643: $toggle_cats_crs = $toggle_cats_dom;
6644: $toggle_cats_dom = ' ';
6645: }
6646: if ($settings->{'categorize'} eq 'crs') {
6647: $can_cat_crs = $can_cat_dom;
6648: $can_cat_dom = ' ';
6649: }
1.120 raeburn 6650: if ($settings->{'togglecatscomm'} eq 'comm') {
6651: $toggle_catscomm_comm = $toggle_catscomm_dom;
6652: $toggle_catscomm_dom = ' ';
6653: }
6654: if ($settings->{'categorizecomm'} eq 'comm') {
6655: $can_catcomm_comm = $can_catcomm_dom;
6656: $can_catcomm_dom = ' ';
6657: }
1.272 raeburn 6658: if ($settings->{'togglecatsplace'} eq 'place') {
6659: $toggle_catsplace_place = $toggle_catsplace_dom;
6660: $toggle_catsplace_dom = ' ';
6661: }
6662: if ($settings->{'categorizeplace'} eq 'place') {
6663: $can_catplace_place = $can_catplace_dom;
6664: $can_catplace_dom = ' ';
6665: }
1.57 raeburn 6666: }
6667: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 6668: togglecats => 'Show/Hide a course in catalog',
6669: togglecatscomm => 'Show/Hide a community in catalog',
6670: togglecatsplace => 'Show/Hide a placement test in catalog',
6671: categorize => 'Assign a category to a course',
6672: categorizecomm => 'Assign a category to a community',
6673: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 6674: );
6675: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 6676: dom => 'Set in Domain',
6677: crs => 'Set in Course',
6678: comm => 'Set in Community',
6679: place => 'Set in Placement Test',
1.57 raeburn 6680: );
6681: $datatable = '<tr class="LC_odd_row">'.
6682: '<td>'.$title{'togglecats'}.'</td>'.
6683: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6684: '<input type="radio" name="togglecats"'.
6685: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6686: '<label><input type="radio" name="togglecats"'.
6687: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6688: '</tr><tr>'.
6689: '<td>'.$title{'categorize'}.'</td>'.
6690: '<td class="LC_right_item"><span class="LC_nobreak">'.
6691: '<label><input type="radio" name="categorize"'.
6692: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6693: '<label><input type="radio" name="categorize"'.
6694: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6695: '</tr><tr class="LC_odd_row">'.
6696: '<td>'.$title{'togglecatscomm'}.'</td>'.
6697: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6698: '<input type="radio" name="togglecatscomm"'.
6699: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6700: '<label><input type="radio" name="togglecatscomm"'.
6701: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6702: '</tr><tr>'.
6703: '<td>'.$title{'categorizecomm'}.'</td>'.
6704: '<td class="LC_right_item"><span class="LC_nobreak">'.
6705: '<label><input type="radio" name="categorizecomm"'.
6706: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6707: '<label><input type="radio" name="categorizecomm"'.
6708: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272 raeburn 6709: '</tr><tr>'.
6710: '<td>'.$title{'togglecatsplace'}.'</td>'.
6711: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6712: '<input type="radio" name="togglecatsplace"'.
6713: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6714: '<label><input type="radio" name="togglecatscomm"'.
6715: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
6716: '</tr><tr>'.
6717: '<td>'.$title{'categorizeplace'}.'</td>'.
6718: '<td class="LC_right_item"><span class="LC_nobreak">'.
6719: '<label><input type="radio" name="categorizeplace"'.
6720: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6721: '<label><input type="radio" name="categorizeplace"'.
6722: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 6723: '</tr>';
1.272 raeburn 6724: $$rowtotal += 6;
1.57 raeburn 6725: } else {
6726: my $css_class;
6727: my $itemcount = 1;
6728: my $cathash;
6729: if (ref($settings) eq 'HASH') {
6730: $cathash = $settings->{'cats'};
6731: }
6732: if (ref($cathash) eq 'HASH') {
6733: my (@cats,@trails,%allitems,%idx,@jsarray);
6734: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6735: \%allitems,\%idx,\@jsarray);
6736: my $maxdepth = scalar(@cats);
6737: my $colattrib = '';
6738: if ($maxdepth > 2) {
6739: $colattrib = ' colspan="2" ';
6740: }
6741: my @path;
6742: if (@cats > 0) {
6743: if (ref($cats[0]) eq 'ARRAY') {
6744: my $numtop = @{$cats[0]};
6745: my $maxnum = $numtop;
1.120 raeburn 6746: my %default_names = (
6747: instcode => &mt('Official courses'),
6748: communities => &mt('Communities'),
1.272 raeburn 6749: placement => &mt('Placement Tests'),
1.120 raeburn 6750: );
6751:
6752: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6753: ($cathash->{'instcode::0'} eq '') ||
6754: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 6755: ($cathash->{'communities::0'} eq '') ||
6756: (!grep(/^placement$/,@{$cats[0]})) ||
6757: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 6758: $maxnum ++;
6759: }
6760: my $lastidx;
6761: for (my $i=0; $i<$numtop; $i++) {
6762: my $parent = $cats[0][$i];
6763: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6764: my $item = &escape($parent).'::0';
6765: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6766: $lastidx = $idx{$item};
6767: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6768: .'<select name="'.$item.'"'.$chgstr.'>';
6769: for (my $k=0; $k<=$maxnum; $k++) {
6770: my $vpos = $k+1;
6771: my $selstr;
6772: if ($k == $i) {
6773: $selstr = ' selected="selected" ';
6774: }
6775: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6776: }
1.214 raeburn 6777: $datatable .= '</select></span></td><td>';
1.272 raeburn 6778: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 6779: $datatable .= '<span class="LC_nobreak">'
6780: .$default_names{$parent}.'</span>';
6781: if ($parent eq 'instcode') {
6782: $datatable .= '<br /><span class="LC_nobreak">('
6783: .&mt('with institutional codes')
6784: .')</span></td><td'.$colattrib.'>';
6785: } else {
6786: $datatable .= '<table><tr><td>';
6787: }
6788: $datatable .= '<span class="LC_nobreak">'
6789: .'<label><input type="radio" name="'
6790: .$parent.'" value="1" checked="checked" />'
6791: .&mt('Display').'</label>';
6792: if ($parent eq 'instcode') {
6793: $datatable .= ' ';
6794: } else {
6795: $datatable .= '</span></td></tr><tr><td>'
6796: .'<span class="LC_nobreak">';
6797: }
6798: $datatable .= '<label><input type="radio" name="'
6799: .$parent.'" value="0" />'
6800: .&mt('Do not display').'</label></span>';
1.272 raeburn 6801: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 6802: $datatable .= '</td></tr></table>';
6803: }
6804: $datatable .= '</td>';
1.57 raeburn 6805: } else {
6806: $datatable .= $parent
1.214 raeburn 6807: .' <span class="LC_nobreak"><label>'
6808: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6809: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6810: }
6811: my $depth = 1;
6812: push(@path,$parent);
6813: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6814: pop(@path);
6815: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6816: $itemcount ++;
6817: }
1.48 raeburn 6818: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6819: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6820: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6821: for (my $k=0; $k<=$maxnum; $k++) {
6822: my $vpos = $k+1;
6823: my $selstr;
1.57 raeburn 6824: if ($k == $numtop) {
1.48 raeburn 6825: $selstr = ' selected="selected" ';
6826: }
6827: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6828: }
1.59 bisitz 6829: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6830: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6831: .'</tr>'."\n";
1.48 raeburn 6832: $itemcount ++;
1.272 raeburn 6833: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 6834: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6835: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6836: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6837: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6838: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6839: for (my $k=0; $k<=$maxnum; $k++) {
6840: my $vpos = $k+1;
6841: my $selstr;
6842: if ($k == $maxnum) {
6843: $selstr = ' selected="selected" ';
6844: }
6845: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6846: }
1.120 raeburn 6847: $datatable .= '</select></span></td>'.
6848: '<td><span class="LC_nobreak">'.
6849: $default_names{$default}.'</span>';
6850: if ($default eq 'instcode') {
6851: $datatable .= '<br /><span class="LC_nobreak">('
6852: .&mt('with institutional codes').')</span>';
6853: }
6854: $datatable .= '</td>'
6855: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6856: .&mt('Display').'</label> '
6857: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6858: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6859: }
6860: }
6861: }
1.57 raeburn 6862: } else {
6863: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6864: }
6865: } else {
1.238 raeburn 6866: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6867: .&initialize_categories($itemcount);
1.48 raeburn 6868: }
1.57 raeburn 6869: $$rowtotal += $itemcount;
1.48 raeburn 6870: }
6871: return $datatable;
6872: }
6873:
1.69 raeburn 6874: sub print_serverstatuses {
6875: my ($dom,$settings,$rowtotal) = @_;
6876: my $datatable;
6877: my @pages = &serverstatus_pages();
6878: my (%namedaccess,%machineaccess);
6879: foreach my $type (@pages) {
6880: $namedaccess{$type} = '';
6881: $machineaccess{$type}= '';
6882: }
6883: if (ref($settings) eq 'HASH') {
6884: foreach my $type (@pages) {
6885: if (exists($settings->{$type})) {
6886: if (ref($settings->{$type}) eq 'HASH') {
6887: foreach my $key (keys(%{$settings->{$type}})) {
6888: if ($key eq 'namedusers') {
6889: $namedaccess{$type} = $settings->{$type}->{$key};
6890: } elsif ($key eq 'machines') {
6891: $machineaccess{$type} = $settings->{$type}->{$key};
6892: }
6893: }
6894: }
6895: }
6896: }
6897: }
1.81 raeburn 6898: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6899: my $rownum = 0;
6900: my $css_class;
6901: foreach my $type (@pages) {
6902: $rownum ++;
6903: $css_class = $rownum%2?' class="LC_odd_row"':'';
6904: $datatable .= '<tr'.$css_class.'>'.
6905: '<td><span class="LC_nobreak">'.
6906: $titles->{$type}.'</span></td>'.
6907: '<td class="LC_left_item">'.
6908: '<input type="text" name="'.$type.'_namedusers" '.
6909: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6910: '<td class="LC_right_item">'.
6911: '<span class="LC_nobreak">'.
6912: '<input type="text" name="'.$type.'_machines" '.
6913: 'value="'.$machineaccess{$type}.'" size="10" />'.
6914: '</td></tr>'."\n";
6915: }
6916: $$rowtotal += $rownum;
6917: return $datatable;
6918: }
6919:
6920: sub serverstatus_pages {
6921: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 6922: 'checksums','clusterstatus','certstatus','metadata_keywords',
6923: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
6924: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6925: }
6926:
1.236 raeburn 6927: sub defaults_javascript {
6928: my ($settings) = @_;
1.294 raeburn 6929: 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.');
6930: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6931: &js_escape(\$intauthcheck);
6932: &js_escape(\$intauthcost);
6933: my $intauthjs = <<"ENDSCRIPT";
6934:
6935: function warnIntAuth(field) {
6936: if (field.name == 'intauth_check') {
6937: if (field.value == '2') {
6938: alert('$intauthcheck');
6939: }
6940: }
6941: if (field.name == 'intauth_cost') {
6942: field.value.replace(/\s/g,'');
6943: if (field.value != '') {
6944: var regexdigit=/^\\d+\$/;
6945: if (!regexdigit.test(field.value)) {
6946: alert('$intauthcost');
6947: }
6948: }
6949: }
6950: return;
6951: }
6952:
6953: ENDSCRIPT
6954:
6955: if (ref($settings) ne 'HASH') {
6956: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6957: }
1.236 raeburn 6958: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6959: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6960: if ($maxnum eq '') {
6961: $maxnum = 0;
6962: }
6963: $maxnum ++;
1.249 raeburn 6964: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 6965: return <<"ENDSCRIPT";
6966: <script type="text/javascript">
6967: // <![CDATA[
6968: function reorderTypes(form,caller) {
6969: var changedVal;
6970: $jstext
6971: var newpos = 'addinststatus_pos';
6972: var current = new Array;
6973: var maxh = $maxnum;
6974: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6975: var oldVal;
6976: if (caller == newpos) {
6977: changedVal = newitemVal;
6978: } else {
6979: var curritem = 'inststatus_pos_'+caller;
6980: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6981: current[newitemVal] = newpos;
6982: }
6983: for (var i=0; i<inststatuses.length; i++) {
6984: if (inststatuses[i] != caller) {
6985: var elementName = 'inststatus_pos_'+inststatuses[i];
6986: if (form.elements[elementName]) {
6987: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6988: current[currVal] = elementName;
6989: }
6990: }
6991: }
6992: for (var j=0; j<maxh; j++) {
6993: if (current[j] == undefined) {
6994: oldVal = j;
6995: }
6996: }
6997: if (oldVal < changedVal) {
6998: for (var k=oldVal+1; k<=changedVal ; k++) {
6999: var elementName = current[k];
7000: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7001: }
7002: } else {
7003: for (var k=changedVal; k<oldVal; k++) {
7004: var elementName = current[k];
7005: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7006: }
7007: }
7008: return;
7009: }
7010:
1.294 raeburn 7011: $intauthjs
7012:
1.236 raeburn 7013: // ]]>
7014: </script>
7015:
7016: ENDSCRIPT
1.294 raeburn 7017: } else {
7018: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 7019: }
7020: }
7021:
1.49 raeburn 7022: sub coursecategories_javascript {
7023: my ($settings) = @_;
1.57 raeburn 7024: my ($output,$jstext,$cathash);
1.49 raeburn 7025: if (ref($settings) eq 'HASH') {
1.57 raeburn 7026: $cathash = $settings->{'cats'};
7027: }
7028: if (ref($cathash) eq 'HASH') {
1.49 raeburn 7029: my (@cats,@jsarray,%idx);
1.57 raeburn 7030: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 7031: if (@jsarray > 0) {
7032: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
7033: for (my $i=0; $i<@jsarray; $i++) {
7034: if (ref($jsarray[$i]) eq 'ARRAY') {
7035: my $catstr = join('","',@{$jsarray[$i]});
7036: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
7037: }
7038: }
7039: }
7040: } else {
7041: $jstext = ' var categories = Array(1);'."\n".
7042: ' categories[0] = Array("instcode_pos");'."\n";
7043: }
1.237 bisitz 7044: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
7045: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 7046: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 7047: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
7048: &js_escape(\$instcode_reserved);
7049: &js_escape(\$communities_reserved);
1.272 raeburn 7050: &js_escape(\$placement_reserved);
1.265 damieng 7051: &js_escape(\$choose_again);
1.49 raeburn 7052: $output = <<"ENDSCRIPT";
7053: <script type="text/javascript">
1.109 raeburn 7054: // <![CDATA[
1.49 raeburn 7055: function reorderCats(form,parent,item,idx) {
7056: var changedVal;
7057: $jstext
7058: var newpos = 'addcategory_pos';
7059: if (parent == '') {
7060: var has_instcode = 0;
7061: var maxtop = categories[idx].length;
7062: for (var j=0; j<maxtop; j++) {
7063: if (categories[idx][j] == 'instcode::0') {
7064: has_instcode == 1;
7065: }
7066: }
7067: if (has_instcode == 0) {
7068: categories[idx][maxtop] = 'instcode_pos';
7069: }
7070: } else {
7071: newpos += '_'+parent;
7072: }
7073: var maxh = 1 + categories[idx].length;
7074: var current = new Array;
7075: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
7076: if (item == newpos) {
7077: changedVal = newitemVal;
7078: } else {
7079: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
7080: current[newitemVal] = newpos;
7081: }
7082: for (var i=0; i<categories[idx].length; i++) {
7083: var elementName = categories[idx][i];
7084: if (elementName != item) {
7085: if (form.elements[elementName]) {
7086: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
7087: current[currVal] = elementName;
7088: }
7089: }
7090: }
7091: var oldVal;
7092: for (var j=0; j<maxh; j++) {
7093: if (current[j] == undefined) {
7094: oldVal = j;
7095: }
7096: }
7097: if (oldVal < changedVal) {
7098: for (var k=oldVal+1; k<=changedVal ; k++) {
7099: var elementName = current[k];
7100: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
7101: }
7102: } else {
7103: for (var k=changedVal; k<oldVal; k++) {
7104: var elementName = current[k];
7105: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
7106: }
7107: }
7108: return;
7109: }
1.120 raeburn 7110:
7111: function categoryCheck(form) {
7112: if (form.elements['addcategory_name'].value == 'instcode') {
7113: alert('$instcode_reserved\\n$choose_again');
7114: return false;
7115: }
7116: if (form.elements['addcategory_name'].value == 'communities') {
7117: alert('$communities_reserved\\n$choose_again');
7118: return false;
7119: }
1.272 raeburn 7120: if (form.elements['addcategory_name'].value == 'placement') {
7121: alert('$placement_reserved\\n$choose_again');
7122: return false;
7123: }
1.120 raeburn 7124: return true;
7125: }
7126:
1.109 raeburn 7127: // ]]>
1.49 raeburn 7128: </script>
7129:
7130: ENDSCRIPT
7131: return $output;
7132: }
7133:
1.48 raeburn 7134: sub initialize_categories {
7135: my ($itemcount) = @_;
1.120 raeburn 7136: my ($datatable,$css_class,$chgstr);
7137: my %default_names = (
7138: instcode => 'Official courses (with institutional codes)',
7139: communities => 'Communities',
1.272 raeburn 7140: placement => 'Placement Tests',
1.120 raeburn 7141: );
7142: my $select0 = ' selected="selected"';
7143: my $select1 = '';
1.272 raeburn 7144: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 7145: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7146: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272 raeburn 7147: if (($default eq 'communities') || ($default eq 'placement')) {
1.120 raeburn 7148: $select1 = $select0;
7149: $select0 = '';
7150: }
7151: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
7152: .'<select name="'.$default.'_pos">'
7153: .'<option value="0"'.$select0.'>1</option>'
7154: .'<option value="1"'.$select1.'>2</option>'
7155: .'<option value="2">3</option></select> '
7156: .$default_names{$default}
7157: .'</span></td><td><span class="LC_nobreak">'
7158: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
7159: .&mt('Display').'</label> <label>'
7160: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 7161: .'</label></span></td></tr>';
1.120 raeburn 7162: $itemcount ++;
7163: }
1.48 raeburn 7164: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 7165: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 7166: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 7167: .'<select name="addcategory_pos"'.$chgstr.'>'
7168: .'<option value="0">1</option>'
7169: .'<option value="1">2</option>'
7170: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 7171: .&mt('Add category').'</td><td>'.&mt('Name:')
7172: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
7173: return $datatable;
7174: }
7175:
7176: sub build_category_rows {
1.49 raeburn 7177: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
7178: my ($text,$name,$item,$chgstr);
1.48 raeburn 7179: if (ref($cats) eq 'ARRAY') {
7180: my $maxdepth = scalar(@{$cats});
7181: if (ref($cats->[$depth]) eq 'HASH') {
7182: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
7183: my $numchildren = @{$cats->[$depth]{$parent}};
7184: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 7185: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 7186: my ($idxnum,$parent_name,$parent_item);
7187: my $higher = $depth - 1;
7188: if ($higher == 0) {
7189: $parent_name = &escape($parent).'::'.$higher;
7190: } else {
7191: if (ref($path) eq 'ARRAY') {
7192: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7193: }
7194: }
7195: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 7196: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 7197: if ($j < $numchildren) {
1.48 raeburn 7198: $name = $cats->[$depth]{$parent}[$j];
7199: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 7200: $idxnum = $idx->{$item};
7201: } else {
7202: $name = $parent_name;
7203: $item = $parent_item;
1.48 raeburn 7204: }
1.49 raeburn 7205: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
7206: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 7207: for (my $i=0; $i<=$numchildren; $i++) {
7208: my $vpos = $i+1;
7209: my $selstr;
7210: if ($j == $i) {
7211: $selstr = ' selected="selected" ';
7212: }
7213: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
7214: }
7215: $text .= '</select> ';
7216: if ($j < $numchildren) {
7217: my $deeper = $depth+1;
7218: $text .= $name.' '
7219: .'<label><input type="checkbox" name="deletecategory" value="'
7220: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
7221: if(ref($path) eq 'ARRAY') {
7222: push(@{$path},$name);
1.49 raeburn 7223: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 7224: pop(@{$path});
7225: }
7226: } else {
1.59 bisitz 7227: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 7228: if ($j == $numchildren) {
7229: $text .= $name;
7230: } else {
7231: $text .= $item;
7232: }
7233: $text .= '" value="" />';
7234: }
7235: $text .= '</td></tr>';
7236: }
7237: $text .= '</table></td>';
7238: } else {
7239: my $higher = $depth-1;
7240: if ($higher == 0) {
7241: $name = &escape($parent).'::'.$higher;
7242: } else {
7243: if (ref($path) eq 'ARRAY') {
7244: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7245: }
7246: }
7247: my $colspan;
7248: if ($parent ne 'instcode') {
7249: $colspan = $maxdepth - $depth - 1;
7250: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
7251: }
7252: }
7253: }
7254: }
7255: return $text;
7256: }
7257:
1.33 raeburn 7258: sub modifiable_userdata_row {
1.228 raeburn 7259: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
7260: my ($role,$rolename,$statustype);
7261: $role = $item;
1.224 raeburn 7262: if ($context eq 'cancreate') {
1.228 raeburn 7263: if ($item =~ /^emailusername_(.+)$/) {
7264: $statustype = $1;
7265: $role = 'emailusername';
7266: if (ref($usertypes) eq 'HASH') {
7267: if ($usertypes->{$statustype}) {
7268: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7269: } else {
7270: $rolename = &mt('Data provided by user');
7271: }
7272: }
1.224 raeburn 7273: }
7274: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7275: if (ref($usertypes) eq 'HASH') {
7276: $rolename = $usertypes->{$role};
7277: } else {
7278: $rolename = $role;
7279: }
1.33 raeburn 7280: } else {
1.63 raeburn 7281: if ($role eq 'cr') {
7282: $rolename = &mt('Custom role');
7283: } else {
7284: $rolename = &Apache::lonnet::plaintext($role);
7285: }
1.33 raeburn 7286: }
1.224 raeburn 7287: my (@fields,%fieldtitles);
7288: if (ref($fieldsref) eq 'ARRAY') {
7289: @fields = @{$fieldsref};
7290: } else {
7291: @fields = ('lastname','firstname','middlename','generation',
7292: 'permanentemail','id');
7293: }
7294: if ((ref($titlesref) eq 'HASH')) {
7295: %fieldtitles = %{$titlesref};
7296: } else {
7297: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7298: }
1.33 raeburn 7299: my $output;
7300: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
7301: $output = '<tr '.$css_class.'>'.
7302: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7303: '<td class="LC_left_item" colspan="2"><table>';
7304: my $rem;
7305: my %checks;
7306: if (ref($settings) eq 'HASH') {
7307: if (ref($settings->{$context}) eq 'HASH') {
7308: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228 raeburn 7309: my $hashref = $settings->{$context}->{$role};
7310: if ($role eq 'emailusername') {
7311: if ($statustype) {
7312: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7313: $hashref = $settings->{$context}->{$role}->{$statustype};
7314: if (ref($hashref) eq 'HASH') {
7315: foreach my $field (@fields) {
7316: if ($hashref->{$field}) {
7317: $checks{$field} = $hashref->{$field};
7318: }
7319: }
7320: }
7321: }
7322: }
7323: } else {
7324: if (ref($hashref) eq 'HASH') {
7325: foreach my $field (@fields) {
7326: if ($hashref->{$field}) {
7327: $checks{$field} = ' checked="checked" ';
7328: }
7329: }
1.33 raeburn 7330: }
7331: }
7332: }
7333: }
7334: }
1.228 raeburn 7335:
1.33 raeburn 7336: for (my $i=0; $i<@fields; $i++) {
7337: my $rem = $i%($numinrow);
7338: if ($rem == 0) {
7339: if ($i > 0) {
7340: $output .= '</tr>';
7341: }
7342: $output .= '<tr>';
7343: }
7344: my $check = ' ';
1.228 raeburn 7345: unless ($role eq 'emailusername') {
7346: if (exists($checks{$fields[$i]})) {
7347: $check = $checks{$fields[$i]}
7348: } else {
7349: if ($role eq 'st') {
7350: if (ref($settings) ne 'HASH') {
7351: $check = ' checked="checked" ';
7352: }
1.33 raeburn 7353: }
7354: }
7355: }
7356: $output .= '<td class="LC_left_item">'.
1.228 raeburn 7357: '<span class="LC_nobreak">';
7358: if ($role eq 'emailusername') {
7359: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7360: $checks{$fields[$i]} = 'omit';
7361: }
7362: foreach my $option ('required','optional','omit') {
7363: my $checked='';
7364: if ($checks{$fields[$i]} eq $option) {
7365: $checked='checked="checked" ';
7366: }
7367: $output .= '<label>'.
7368: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7369: &mt($option).'</label>'.(' ' x2);
7370: }
7371: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7372: } else {
7373: $output .= '<label>'.
7374: '<input type="checkbox" name="canmodify_'.$role.'" '.
7375: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7376: '</label>';
7377: }
7378: $output .= '</span></td>';
1.33 raeburn 7379: $rem = @fields%($numinrow);
7380: }
7381: my $colsleft = $numinrow - $rem;
7382: if ($colsleft > 1 ) {
7383: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7384: ' </td>';
7385: } elsif ($colsleft == 1) {
7386: $output .= '<td class="LC_left_item"> </td>';
7387: }
7388: $output .= '</tr></table></td></tr>';
7389: return $output;
7390: }
1.28 raeburn 7391:
1.93 raeburn 7392: sub insttypes_row {
1.224 raeburn 7393: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 7394: my %lt = &Apache::lonlocal::texthash (
7395: cansearch => 'Users allowed to search',
7396: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7397: lockablenames => 'User preference to lock name',
1.93 raeburn 7398: );
7399: my $showdom;
7400: if ($context eq 'cansearch') {
7401: $showdom = ' ('.$dom.')';
7402: }
1.165 raeburn 7403: my $class = 'LC_left_item';
7404: if ($context eq 'statustocreate') {
7405: $class = 'LC_right_item';
7406: }
1.224 raeburn 7407: my $css_class = ' class="LC_odd_row"';
7408: if ($rownum ne '') {
7409: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
7410: }
7411: my $output = '<tr'.$css_class.'>'.
7412: '<td>'.$lt{$context}.$showdom.
7413: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7414: my $rem;
7415: if (ref($types) eq 'ARRAY') {
7416: for (my $i=0; $i<@{$types}; $i++) {
7417: if (defined($usertypes->{$types->[$i]})) {
7418: my $rem = $i%($numinrow);
7419: if ($rem == 0) {
7420: if ($i > 0) {
7421: $output .= '</tr>';
7422: }
7423: $output .= '<tr>';
1.23 raeburn 7424: }
1.26 raeburn 7425: my $check = ' ';
1.99 raeburn 7426: if (ref($settings) eq 'HASH') {
7427: if (ref($settings->{$context}) eq 'ARRAY') {
7428: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7429: $check = ' checked="checked" ';
7430: }
7431: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7432: $check = ' checked="checked" ';
7433: }
1.23 raeburn 7434: }
1.26 raeburn 7435: $output .= '<td class="LC_left_item">'.
7436: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7437: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 7438: 'value="'.$types->[$i].'"'.$check.'/>'.
7439: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7440: }
7441: }
1.26 raeburn 7442: $rem = @{$types}%($numinrow);
1.23 raeburn 7443: }
7444: my $colsleft = $numinrow - $rem;
1.131 raeburn 7445: if (($rem == 0) && (@{$types} > 0)) {
7446: $output .= '<tr>';
7447: }
1.23 raeburn 7448: if ($colsleft > 1) {
1.25 raeburn 7449: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7450: } else {
1.25 raeburn 7451: $output .= '<td class="LC_left_item">';
1.23 raeburn 7452: }
7453: my $defcheck = ' ';
1.99 raeburn 7454: if (ref($settings) eq 'HASH') {
7455: if (ref($settings->{$context}) eq 'ARRAY') {
7456: if (grep(/^default$/,@{$settings->{$context}})) {
7457: $defcheck = ' checked="checked" ';
7458: }
7459: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7460: $defcheck = ' checked="checked" ';
7461: }
1.23 raeburn 7462: }
1.25 raeburn 7463: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7464: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 7465: 'value="default"'.$defcheck.'/>'.
7466: $othertitle.'</label></span></td>'.
7467: '</tr></table></td></tr>';
7468: return $output;
1.23 raeburn 7469: }
7470:
7471: sub sorted_searchtitles {
7472: my %searchtitles = &Apache::lonlocal::texthash(
7473: 'uname' => 'username',
7474: 'lastname' => 'last name',
7475: 'lastfirst' => 'last name, first name',
7476: );
7477: my @titleorder = ('uname','lastname','lastfirst');
7478: return (\%searchtitles,\@titleorder);
7479: }
7480:
1.25 raeburn 7481: sub sorted_searchtypes {
7482: my %srchtypes_desc = (
7483: exact => 'is exact match',
7484: contains => 'contains ..',
7485: begins => 'begins with ..',
7486: );
7487: my @srchtypeorder = ('exact','begins','contains');
7488: return (\%srchtypes_desc,\@srchtypeorder);
7489: }
7490:
1.3 raeburn 7491: sub usertype_update_row {
7492: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7493: my $datatable;
7494: my $numinrow = 4;
7495: foreach my $type (@{$types}) {
7496: if (defined($usertypes->{$type})) {
7497: $$rownums ++;
7498: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7499: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7500: '</td><td class="LC_left_item"><table>';
7501: for (my $i=0; $i<@{$fields}; $i++) {
7502: my $rem = $i%($numinrow);
7503: if ($rem == 0) {
7504: if ($i > 0) {
7505: $datatable .= '</tr>';
7506: }
7507: $datatable .= '<tr>';
7508: }
7509: my $check = ' ';
1.39 raeburn 7510: if (ref($settings) eq 'HASH') {
7511: if (ref($settings->{'fields'}) eq 'HASH') {
7512: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7513: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7514: $check = ' checked="checked" ';
7515: }
1.3 raeburn 7516: }
7517: }
7518: }
7519:
7520: if ($i == @{$fields}-1) {
7521: my $colsleft = $numinrow - $rem;
7522: if ($colsleft > 1) {
7523: $datatable .= '<td colspan="'.$colsleft.'">';
7524: } else {
7525: $datatable .= '<td>';
7526: }
7527: } else {
7528: $datatable .= '<td>';
7529: }
1.8 raeburn 7530: $datatable .= '<span class="LC_nobreak"><label>'.
7531: '<input type="checkbox" name="updateable_'.$type.
7532: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7533: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7534: }
7535: $datatable .= '</tr></table></td></tr>';
7536: }
7537: }
7538: return $datatable;
1.1 raeburn 7539: }
7540:
7541: sub modify_login {
1.205 raeburn 7542: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 7543: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7544: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7545: %title = ( coursecatalog => 'Display course catalog',
7546: adminmail => 'Display administrator E-mail address',
1.188 raeburn 7547: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 7548: newuser => 'Link for visitors to create a user account',
7549: loginheader => 'Log-in box header');
7550: @offon = ('off','on');
1.112 raeburn 7551: if (ref($domconfig{login}) eq 'HASH') {
7552: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7553: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7554: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7555: }
7556: }
7557: }
1.9 raeburn 7558: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7559: \%domconfig,\%loginhash);
1.188 raeburn 7560: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7561: foreach my $item (@toggles) {
7562: $loginhash{login}{$item} = $env{'form.'.$item};
7563: }
1.41 raeburn 7564: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7565: if (ref($colchanges{'login'}) eq 'HASH') {
7566: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7567: \%loginhash);
7568: }
1.110 raeburn 7569:
1.149 raeburn 7570: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 7571: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7572: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7573: if (keys(%servers) > 1) {
7574: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7575: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7576: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7577: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7578: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7579: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7580: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7581: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7582: $changes{'loginvia'}{$lonhost} = 1;
7583: } else {
7584: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7585: $changes{'loginvia'}{$lonhost} = 1;
7586: }
7587: } else {
7588: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7589: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7590: $changes{'loginvia'}{$lonhost} = 1;
7591: }
7592: }
7593: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7594: foreach my $item (@loginvia_attribs) {
7595: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7596: }
7597: } else {
7598: foreach my $item (@loginvia_attribs) {
7599: my $new = $env{'form.'.$lonhost.'_'.$item};
7600: if (($item eq 'serverpath') && ($new eq 'custom')) {
7601: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7602: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7603: $new = '/';
7604: }
7605: }
7606: if (($item eq 'custompath') &&
7607: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7608: $new = '';
7609: }
7610: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7611: $changes{'loginvia'}{$lonhost} = 1;
7612: }
7613: if ($item eq 'exempt') {
1.256 raeburn 7614: $new = &check_exempt_addresses($new);
1.128 raeburn 7615: }
7616: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7617: }
7618: }
1.112 raeburn 7619: } else {
1.128 raeburn 7620: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7621: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7622: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7623: foreach my $item (@loginvia_attribs) {
7624: my $new = $env{'form.'.$lonhost.'_'.$item};
7625: if (($item eq 'serverpath') && ($new eq 'custom')) {
7626: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7627: $new = '/';
7628: }
7629: }
7630: if (($item eq 'custompath') &&
7631: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7632: $new = '';
7633: }
7634: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7635: }
1.110 raeburn 7636: }
7637: }
7638: }
7639: }
1.119 raeburn 7640:
1.168 raeburn 7641: my $servadm = $r->dir_config('lonAdmEMail');
7642: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7643: if (ref($domconfig{'login'}) eq 'HASH') {
7644: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7645: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7646: if ($lang eq 'nolang') {
7647: push(@currlangs,$lang);
7648: } elsif (defined($langchoices{$lang})) {
7649: push(@currlangs,$lang);
7650: } else {
7651: next;
7652: }
7653: }
7654: }
7655: }
7656: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7657: if (@currlangs > 0) {
7658: foreach my $lang (@currlangs) {
7659: if (grep(/^\Q$lang\E$/,@delurls)) {
7660: $changes{'helpurl'}{$lang} = 1;
7661: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7662: $changes{'helpurl'}{$lang} = 1;
7663: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7664: push(@newlangs,$lang);
7665: } else {
7666: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7667: }
7668: }
7669: }
7670: unless (grep(/^nolang$/,@currlangs)) {
7671: if ($env{'form.loginhelpurl_nolang.filename'}) {
7672: $changes{'helpurl'}{'nolang'} = 1;
7673: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7674: push(@newlangs,'nolang');
7675: }
7676: }
7677: if ($env{'form.loginhelpurl_add_lang'}) {
7678: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7679: ($env{'form.loginhelpurl_add_file.filename'})) {
7680: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7681: $addedfile = $env{'form.loginhelpurl_add_lang'};
7682: }
7683: }
7684: if ((@newlangs > 0) || ($addedfile)) {
7685: my $error;
7686: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7687: if ($configuserok eq 'ok') {
7688: if ($switchserver) {
7689: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7690: } elsif ($author_ok eq 'ok') {
7691: my @allnew = @newlangs;
7692: if ($addedfile ne '') {
7693: push(@allnew,$addedfile);
7694: }
7695: foreach my $lang (@allnew) {
7696: my $formelem = 'loginhelpurl_'.$lang;
7697: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7698: $formelem = 'loginhelpurl_add_file';
7699: }
7700: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7701: "help/$lang",'','',$newfile{$lang});
7702: if ($result eq 'ok') {
7703: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7704: $changes{'helpurl'}{$lang} = 1;
7705: } else {
7706: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7707: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 7708: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 7709: (!grep(/^\Q$lang\E$/,@delurls))) {
7710: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7711: }
7712: }
7713: }
7714: } else {
7715: $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);
7716: }
7717: } else {
7718: $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);
7719: }
7720: if ($error) {
7721: &Apache::lonnet::logthis($error);
7722: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7723: }
7724: }
1.256 raeburn 7725:
7726: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7727: if (ref($domconfig{'login'}) eq 'HASH') {
7728: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7729: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7730: if ($domservers{$lonhost}) {
7731: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7732: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 7733: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 7734: }
7735: }
7736: }
7737: }
7738: }
7739: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7740: foreach my $lonhost (sort(keys(%domservers))) {
7741: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7742: $changes{'headtag'}{$lonhost} = 1;
7743: } else {
7744: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7745: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7746: }
7747: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7748: push(@newhosts,$lonhost);
7749: } elsif ($currheadtagurls{$lonhost}) {
7750: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7751: if ($currexempt{$lonhost}) {
1.289 raeburn 7752: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 7753: $changes{'headtag'}{$lonhost} = 1;
7754: }
7755: } elsif ($possexempt{$lonhost}) {
7756: $changes{'headtag'}{$lonhost} = 1;
7757: }
7758: if ($possexempt{$lonhost}) {
7759: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7760: }
7761: }
7762: }
7763: }
7764: if (@newhosts) {
7765: my $error;
7766: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7767: if ($configuserok eq 'ok') {
7768: if ($switchserver) {
7769: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7770: } elsif ($author_ok eq 'ok') {
7771: foreach my $lonhost (@newhosts) {
7772: my $formelem = 'loginheadtag_'.$lonhost;
7773: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7774: "login/headtag/$lonhost",'','',
7775: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7776: if ($result eq 'ok') {
7777: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7778: $changes{'headtag'}{$lonhost} = 1;
7779: if ($possexempt{$lonhost}) {
7780: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7781: }
7782: } else {
7783: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7784: $newheadtagurls{$lonhost},$result);
7785: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7786: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7787: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7788: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7789: }
7790: }
7791: }
7792: } else {
7793: $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);
7794: }
7795: } else {
7796: $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);
7797: }
7798: if ($error) {
7799: &Apache::lonnet::logthis($error);
7800: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7801: }
7802: }
1.169 raeburn 7803: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 7804:
7805: my $defaulthelpfile = '/adm/loginproblems.html';
7806: my $defaulttext = &mt('Default in use');
7807:
1.1 raeburn 7808: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7809: $dom);
7810: if ($putresult eq 'ok') {
1.188 raeburn 7811: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7812: my %defaultchecked = (
7813: 'coursecatalog' => 'on',
1.188 raeburn 7814: 'helpdesk' => 'on',
1.42 raeburn 7815: 'adminmail' => 'off',
1.43 raeburn 7816: 'newuser' => 'off',
1.42 raeburn 7817: );
1.55 raeburn 7818: if (ref($domconfig{'login'}) eq 'HASH') {
7819: foreach my $item (@toggles) {
7820: if ($defaultchecked{$item} eq 'on') {
7821: if (($domconfig{'login'}{$item} eq '0') &&
7822: ($env{'form.'.$item} eq '1')) {
7823: $changes{$item} = 1;
7824: } elsif (($domconfig{'login'}{$item} eq '' ||
7825: $domconfig{'login'}{$item} eq '1') &&
7826: ($env{'form.'.$item} eq '0')) {
7827: $changes{$item} = 1;
7828: }
7829: } elsif ($defaultchecked{$item} eq 'off') {
7830: if (($domconfig{'login'}{$item} eq '1') &&
7831: ($env{'form.'.$item} eq '0')) {
7832: $changes{$item} = 1;
7833: } elsif (($domconfig{'login'}{$item} eq '' ||
7834: $domconfig{'login'}{$item} eq '0') &&
7835: ($env{'form.'.$item} eq '1')) {
7836: $changes{$item} = 1;
7837: }
1.42 raeburn 7838: }
7839: }
1.41 raeburn 7840: }
1.6 raeburn 7841: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7842: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 7843: if (ref($lastactref) eq 'HASH') {
7844: $lastactref->{'domainconfig'} = 1;
7845: }
1.1 raeburn 7846: $resulttext = &mt('Changes made:').'<ul>';
7847: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7848: if ($item eq 'loginvia') {
1.112 raeburn 7849: if (ref($changes{$item}) eq 'HASH') {
7850: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7851: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7852: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7853: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7854: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7855: $protocol = 'http' if ($protocol ne 'https');
7856: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7857:
7858: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7859: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7860: } else {
7861: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7862: }
7863: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7864: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7865: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7866: }
7867: $resulttext .= '</li>';
7868: } else {
7869: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7870: }
1.112 raeburn 7871: } else {
1.128 raeburn 7872: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7873: }
7874: }
1.128 raeburn 7875: $resulttext .= '</ul></li>';
1.112 raeburn 7876: }
1.168 raeburn 7877: } elsif ($item eq 'helpurl') {
7878: if (ref($changes{$item}) eq 'HASH') {
7879: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7880: if (grep(/^\Q$lang\E$/,@delurls)) {
7881: my ($chg,$link);
7882: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7883: if ($lang eq 'nolang') {
7884: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7885: } else {
7886: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7887: }
7888: $resulttext .= '<li>'.$chg.'</li>';
7889: } else {
7890: my $chg;
7891: if ($lang eq 'nolang') {
7892: $chg = &mt('custom log-in help file for no preferred language');
7893: } else {
7894: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7895: }
7896: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7897: $loginhash{'login'}{'helpurl'}{$lang}.
7898: '?inhibitmenu=yes',$chg,600,500).
7899: '</li>';
7900: }
7901: }
7902: }
1.256 raeburn 7903: } elsif ($item eq 'headtag') {
7904: if (ref($changes{$item}) eq 'HASH') {
7905: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7906: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7907: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7908: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7909: $resulttext .= '<li><a href="'.
7910: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7911: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7912: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7913: if ($possexempt{$lonhost}) {
7914: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7915: } else {
7916: $resulttext .= &mt('included for any client IP');
7917: }
7918: $resulttext .= '</li>';
7919: }
7920: }
7921: }
1.169 raeburn 7922: } elsif ($item eq 'captcha') {
7923: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 7924: my $chgtxt;
1.169 raeburn 7925: if ($loginhash{'login'}{$item} eq 'notused') {
7926: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7927: } else {
7928: my %captchas = &captcha_phrases();
7929: if ($captchas{$loginhash{'login'}{$item}}) {
7930: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7931: } else {
7932: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7933: }
7934: }
7935: $resulttext .= '<li>'.$chgtxt.'</li>';
7936: }
7937: } elsif ($item eq 'recaptchakeys') {
7938: if (ref($loginhash{'login'}) eq 'HASH') {
7939: my ($privkey,$pubkey);
7940: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7941: $pubkey = $loginhash{'login'}{$item}{'public'};
7942: $privkey = $loginhash{'login'}{$item}{'private'};
7943: }
7944: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7945: if (!$pubkey) {
7946: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7947: } else {
7948: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7949: }
7950: if (!$privkey) {
7951: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7952: } else {
1.251 raeburn 7953: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 7954: }
7955: $chgtxt .= '</ul>';
7956: $resulttext .= '<li>'.$chgtxt.'</li>';
7957: }
1.269 raeburn 7958: } elsif ($item eq 'recaptchaversion') {
7959: if (ref($loginhash{'login'}) eq 'HASH') {
7960: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 7961: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 7962: '</li>';
7963: }
7964: }
1.41 raeburn 7965: } else {
7966: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7967: }
1.1 raeburn 7968: }
1.6 raeburn 7969: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7970: } else {
7971: $resulttext = &mt('No changes made to log-in page settings');
7972: }
7973: } else {
1.11 albertel 7974: $resulttext = '<span class="LC_error">'.
7975: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7976: }
1.6 raeburn 7977: if ($errors) {
1.9 raeburn 7978: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7979: $errors.'</ul>';
7980: }
7981: return $resulttext;
7982: }
7983:
1.256 raeburn 7984: sub check_exempt_addresses {
7985: my ($iplist) = @_;
7986: $iplist =~ s/^\s+//;
7987: $iplist =~ s/\s+$//;
7988: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7989: my (@okips,$new);
7990: foreach my $ip (@poss_ips) {
7991: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7992: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7993: push(@okips,$ip);
7994: }
7995: }
7996: }
7997: if (@okips > 0) {
7998: $new = join(',',@okips);
7999: } else {
8000: $new = '';
8001: }
8002: return $new;
8003: }
8004:
1.6 raeburn 8005: sub color_font_choices {
8006: my %choices =
8007: &Apache::lonlocal::texthash (
8008: img => "Header",
8009: bgs => "Background colors",
8010: links => "Link colors",
1.55 raeburn 8011: images => "Images",
1.6 raeburn 8012: font => "Font color",
1.201 raeburn 8013: fontmenu => "Font menu",
1.76 raeburn 8014: pgbg => "Page",
1.6 raeburn 8015: tabbg => "Header",
8016: sidebg => "Border",
8017: link => "Link",
8018: alink => "Active link",
8019: vlink => "Visited link",
8020: );
8021: return %choices;
8022: }
8023:
8024: sub modify_rolecolors {
1.205 raeburn 8025: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 8026: my ($resulttext,%rolehash);
8027: $rolehash{'rolecolors'} = {};
1.55 raeburn 8028: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
8029: if ($domconfig{'rolecolors'} eq '') {
8030: $domconfig{'rolecolors'} = {};
8031: }
8032: }
1.9 raeburn 8033: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 8034: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
8035: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
8036: $dom);
8037: if ($putresult eq 'ok') {
8038: if (keys(%changes) > 0) {
1.41 raeburn 8039: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 8040: if (ref($lastactref) eq 'HASH') {
8041: $lastactref->{'domainconfig'} = 1;
8042: }
1.6 raeburn 8043: $resulttext = &display_colorchgs($dom,\%changes,$roles,
8044: $rolehash{'rolecolors'});
8045: } else {
8046: $resulttext = &mt('No changes made to default color schemes');
8047: }
8048: } else {
1.11 albertel 8049: $resulttext = '<span class="LC_error">'.
8050: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 8051: }
8052: if ($errors) {
8053: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
8054: $errors.'</ul>';
8055: }
8056: return $resulttext;
8057: }
8058:
8059: sub modify_colors {
1.9 raeburn 8060: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 8061: my (%changes,%choices);
1.51 raeburn 8062: my @bgs;
1.6 raeburn 8063: my @links = ('link','alink','vlink');
1.41 raeburn 8064: my @logintext;
1.6 raeburn 8065: my @images;
8066: my $servadm = $r->dir_config('lonAdmEMail');
8067: my $errors;
1.200 raeburn 8068: my %defaults;
1.6 raeburn 8069: foreach my $role (@{$roles}) {
8070: if ($role eq 'login') {
1.12 raeburn 8071: %choices = &login_choices();
1.41 raeburn 8072: @logintext = ('textcol','bgcol');
1.12 raeburn 8073: } else {
8074: %choices = &color_font_choices();
8075: }
8076: if ($role eq 'login') {
1.41 raeburn 8077: @images = ('img','logo','domlogo','login');
1.51 raeburn 8078: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 8079: } else {
8080: @images = ('img');
1.200 raeburn 8081: @bgs = ('pgbg','tabbg','sidebg');
8082: }
8083: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
8084: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
8085: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
8086: }
8087: if ($role eq 'login') {
8088: foreach my $item (@logintext) {
1.234 raeburn 8089: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8090: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8091: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8092: }
8093: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 8094: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8095: }
8096: }
8097: } else {
1.234 raeburn 8098: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
8099: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
8100: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
8101: }
8102: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 8103: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
8104: }
1.6 raeburn 8105: }
1.200 raeburn 8106: foreach my $item (@bgs) {
1.234 raeburn 8107: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8108: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8109: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8110: }
8111: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 8112: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8113: }
8114: }
8115: foreach my $item (@links) {
1.234 raeburn 8116: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
8117: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
8118: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
8119: }
8120: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 8121: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
8122: }
1.6 raeburn 8123: }
1.46 raeburn 8124: my ($configuserok,$author_ok,$switchserver) =
8125: &config_check($dom,$confname,$servadm);
1.9 raeburn 8126: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 8127: if (ref($domconfig->{$role}) ne 'HASH') {
8128: $domconfig->{$role} = {};
8129: }
1.8 raeburn 8130: foreach my $img (@images) {
1.70 raeburn 8131: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
8132: if (defined($env{'form.login_showlogo_'.$img})) {
8133: $confhash->{$role}{'showlogo'}{$img} = 1;
8134: } else {
8135: $confhash->{$role}{'showlogo'}{$img} = 0;
8136: }
8137: }
1.18 albertel 8138: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
8139: && !defined($domconfig->{$role}{$img})
8140: && !$env{'form.'.$role.'_del_'.$img}
8141: && $env{'form.'.$role.'_import_'.$img}) {
8142: # import the old configured image from the .tab setting
8143: # if they haven't provided a new one
8144: $domconfig->{$role}{$img} =
8145: $env{'form.'.$role.'_import_'.$img};
8146: }
1.6 raeburn 8147: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 8148: my $error;
1.6 raeburn 8149: if ($configuserok eq 'ok') {
1.9 raeburn 8150: if ($switchserver) {
1.12 raeburn 8151: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 8152: } else {
8153: if ($author_ok eq 'ok') {
8154: my ($result,$logourl) =
8155: &publishlogo($r,'upload',$role.'_'.$img,
8156: $dom,$confname,$img,$width,$height);
8157: if ($result eq 'ok') {
8158: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 8159: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8160: } else {
1.12 raeburn 8161: $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 8162: }
8163: } else {
1.46 raeburn 8164: $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 8165: }
8166: }
8167: } else {
1.46 raeburn 8168: $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 8169: }
8170: if ($error) {
1.8 raeburn 8171: &Apache::lonnet::logthis($error);
1.11 albertel 8172: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 8173: }
8174: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 8175: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
8176: my $error;
8177: if ($configuserok eq 'ok') {
8178: # is confname an author?
8179: if ($switchserver eq '') {
8180: if ($author_ok eq 'ok') {
8181: my ($result,$logourl) =
8182: &publishlogo($r,'copy',$domconfig->{$role}{$img},
8183: $dom,$confname,$img,$width,$height);
8184: if ($result eq 'ok') {
8185: $confhash->{$role}{$img} = $logourl;
1.18 albertel 8186: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 8187: }
8188: }
8189: }
8190: }
1.6 raeburn 8191: }
8192: }
8193: }
8194: if (ref($domconfig) eq 'HASH') {
8195: if (ref($domconfig->{$role}) eq 'HASH') {
8196: foreach my $img (@images) {
8197: if ($domconfig->{$role}{$img} ne '') {
8198: if ($env{'form.'.$role.'_del_'.$img}) {
8199: $confhash->{$role}{$img} = '';
1.12 raeburn 8200: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8201: } else {
1.9 raeburn 8202: if ($confhash->{$role}{$img} eq '') {
8203: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
8204: }
1.6 raeburn 8205: }
8206: } else {
8207: if ($env{'form.'.$role.'_del_'.$img}) {
8208: $confhash->{$role}{$img} = '';
1.12 raeburn 8209: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8210: }
8211: }
1.70 raeburn 8212: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8213: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8214: if ($confhash->{$role}{'showlogo'}{$img} ne
8215: $domconfig->{$role}{'showlogo'}{$img}) {
8216: $changes{$role}{'showlogo'}{$img} = 1;
8217: }
8218: } else {
8219: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8220: $changes{$role}{'showlogo'}{$img} = 1;
8221: }
8222: }
8223: }
8224: }
1.6 raeburn 8225: if ($domconfig->{$role}{'font'} ne '') {
8226: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8227: $changes{$role}{'font'} = 1;
8228: }
8229: } else {
8230: if ($confhash->{$role}{'font'}) {
8231: $changes{$role}{'font'} = 1;
8232: }
8233: }
1.107 raeburn 8234: if ($role ne 'login') {
8235: if ($domconfig->{$role}{'fontmenu'} ne '') {
8236: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8237: $changes{$role}{'fontmenu'} = 1;
8238: }
8239: } else {
8240: if ($confhash->{$role}{'fontmenu'}) {
8241: $changes{$role}{'fontmenu'} = 1;
8242: }
1.97 tempelho 8243: }
8244: }
1.6 raeburn 8245: foreach my $item (@bgs) {
8246: if ($domconfig->{$role}{$item} ne '') {
8247: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8248: $changes{$role}{'bgs'}{$item} = 1;
8249: }
8250: } else {
8251: if ($confhash->{$role}{$item}) {
8252: $changes{$role}{'bgs'}{$item} = 1;
8253: }
8254: }
8255: }
8256: foreach my $item (@links) {
8257: if ($domconfig->{$role}{$item} ne '') {
8258: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8259: $changes{$role}{'links'}{$item} = 1;
8260: }
8261: } else {
8262: if ($confhash->{$role}{$item}) {
8263: $changes{$role}{'links'}{$item} = 1;
8264: }
8265: }
8266: }
1.41 raeburn 8267: foreach my $item (@logintext) {
8268: if ($domconfig->{$role}{$item} ne '') {
8269: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8270: $changes{$role}{'logintext'}{$item} = 1;
8271: }
8272: } else {
8273: if ($confhash->{$role}{$item}) {
8274: $changes{$role}{'logintext'}{$item} = 1;
8275: }
8276: }
8277: }
1.6 raeburn 8278: } else {
8279: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8280: \@logintext,$confhash,\%changes);
1.6 raeburn 8281: }
8282: } else {
8283: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8284: \@logintext,$confhash,\%changes);
1.6 raeburn 8285: }
8286: }
8287: return ($errors,%changes);
8288: }
8289:
1.46 raeburn 8290: sub config_check {
8291: my ($dom,$confname,$servadm) = @_;
8292: my ($configuserok,$author_ok,$switchserver,%currroles);
8293: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8294: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8295: $confname,$servadm);
8296: if ($configuserok eq 'ok') {
8297: $switchserver = &check_switchserver($dom,$confname);
8298: if ($switchserver eq '') {
8299: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8300: }
8301: }
8302: return ($configuserok,$author_ok,$switchserver);
8303: }
8304:
1.6 raeburn 8305: sub default_change_checker {
1.41 raeburn 8306: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8307: foreach my $item (@{$links}) {
8308: if ($confhash->{$role}{$item}) {
8309: $changes->{$role}{'links'}{$item} = 1;
8310: }
8311: }
8312: foreach my $item (@{$bgs}) {
8313: if ($confhash->{$role}{$item}) {
8314: $changes->{$role}{'bgs'}{$item} = 1;
8315: }
8316: }
1.41 raeburn 8317: foreach my $item (@{$logintext}) {
8318: if ($confhash->{$role}{$item}) {
8319: $changes->{$role}{'logintext'}{$item} = 1;
8320: }
8321: }
1.6 raeburn 8322: foreach my $img (@{$images}) {
8323: if ($env{'form.'.$role.'_del_'.$img}) {
8324: $confhash->{$role}{$img} = '';
1.12 raeburn 8325: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8326: }
1.70 raeburn 8327: if ($role eq 'login') {
8328: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8329: $changes->{$role}{'showlogo'}{$img} = 1;
8330: }
8331: }
1.6 raeburn 8332: }
8333: if ($confhash->{$role}{'font'}) {
8334: $changes->{$role}{'font'} = 1;
8335: }
1.48 raeburn 8336: }
1.6 raeburn 8337:
8338: sub display_colorchgs {
8339: my ($dom,$changes,$roles,$confhash) = @_;
8340: my (%choices,$resulttext);
8341: if (!grep(/^login$/,@{$roles})) {
8342: $resulttext = &mt('Changes made:').'<br />';
8343: }
8344: foreach my $role (@{$roles}) {
8345: if ($role eq 'login') {
8346: %choices = &login_choices();
8347: } else {
8348: %choices = &color_font_choices();
8349: }
8350: if (ref($changes->{$role}) eq 'HASH') {
8351: if ($role ne 'login') {
8352: $resulttext .= '<h4>'.&mt($role).'</h4>';
8353: }
8354: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8355: if ($role ne 'login') {
8356: $resulttext .= '<ul>';
8357: }
8358: if (ref($changes->{$role}{$key}) eq 'HASH') {
8359: if ($role ne 'login') {
8360: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8361: }
8362: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8363: if (($role eq 'login') && ($key eq 'showlogo')) {
8364: if ($confhash->{$role}{$key}{$item}) {
8365: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8366: } else {
8367: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8368: }
8369: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8370: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8371: } else {
1.12 raeburn 8372: my $newitem = $confhash->{$role}{$item};
8373: if ($key eq 'images') {
8374: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8375: }
8376: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8377: }
8378: }
8379: if ($role ne 'login') {
8380: $resulttext .= '</ul></li>';
8381: }
8382: } else {
8383: if ($confhash->{$role}{$key} eq '') {
8384: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8385: } else {
8386: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8387: }
8388: }
8389: if ($role ne 'login') {
8390: $resulttext .= '</ul>';
8391: }
8392: }
8393: }
8394: }
1.3 raeburn 8395: return $resulttext;
1.1 raeburn 8396: }
8397:
1.9 raeburn 8398: sub thumb_dimensions {
8399: return ('200','50');
8400: }
8401:
1.16 raeburn 8402: sub check_dimensions {
8403: my ($inputfile) = @_;
8404: my ($fullwidth,$fullheight);
8405: if ($inputfile =~ m|^[/\w.\-]+$|) {
8406: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8407: my $imageinfo = <PIPE>;
8408: if (!close(PIPE)) {
8409: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8410: }
8411: chomp($imageinfo);
8412: my ($fullsize) =
1.21 raeburn 8413: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8414: if ($fullsize) {
8415: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8416: }
8417: }
8418: }
8419: return ($fullwidth,$fullheight);
8420: }
8421:
1.9 raeburn 8422: sub check_configuser {
8423: my ($uhome,$dom,$confname,$servadm) = @_;
8424: my ($configuserok,%currroles);
8425: if ($uhome eq 'no_host') {
8426: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8427: my $configpass = &LONCAPA::Enrollment::create_password();
8428: $configuserok =
8429: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8430: $configpass,'','','','','',undef,$servadm);
8431: } else {
8432: $configuserok = 'ok';
8433: %currroles =
8434: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8435: }
8436: return ($configuserok,%currroles);
8437: }
8438:
8439: sub check_authorstatus {
8440: my ($dom,$confname,%currroles) = @_;
8441: my $author_ok;
1.40 raeburn 8442: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8443: my $start = time;
8444: my $end = 0;
8445: $author_ok =
8446: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8447: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8448: } else {
8449: $author_ok = 'ok';
8450: }
8451: return $author_ok;
8452: }
8453:
8454: sub publishlogo {
1.46 raeburn 8455: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267 raeburn 8456: my ($output,$fname,$logourl,$madethumb);
1.9 raeburn 8457: if ($action eq 'upload') {
8458: $fname=$env{'form.'.$formname.'.filename'};
8459: chop($env{'form.'.$formname});
8460: } else {
8461: ($fname) = ($formname =~ /([^\/]+)$/);
8462: }
1.46 raeburn 8463: if ($savefileas ne '') {
8464: $fname = $savefileas;
8465: }
1.9 raeburn 8466: $fname=&Apache::lonnet::clean_filename($fname);
8467: # See if there is anything left
8468: unless ($fname) { return ('error: no uploaded file'); }
8469: $fname="$subdir/$fname";
1.210 raeburn 8470: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 8471: my $filepath="$docroot/priv";
8472: my $relpath = "$dom/$confname";
1.9 raeburn 8473: my ($fnamepath,$file,$fetchthumb);
8474: $file=$fname;
8475: if ($fname=~m|/|) {
8476: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8477: }
1.164 raeburn 8478: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8479: my $count;
1.164 raeburn 8480: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8481: $filepath.="/$parts[$count]";
8482: if ((-e $filepath)!=1) {
8483: mkdir($filepath,02770);
8484: }
8485: }
8486: # Check for bad extension and disallow upload
8487: if ($file=~/\.(\w+)$/ &&
8488: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8489: $output =
1.207 bisitz 8490: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8491: } elsif ($file=~/\.(\w+)$/ &&
8492: !defined(&Apache::loncommon::fileembstyle($1))) {
8493: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8494: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 8495: $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 8496: } elsif (-d "$filepath/$file") {
1.195 bisitz 8497: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8498: } else {
8499: my $source = $filepath.'/'.$file;
8500: my $logfile;
8501: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 8502: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8503: }
8504: print $logfile
8505: "\n================= Publish ".localtime()." ================\n".
8506: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8507: # Save the file
8508: if (!open(FH,'>'.$source)) {
8509: &Apache::lonnet::logthis('Failed to create '.$source);
8510: return (&mt('Failed to create file'));
8511: }
8512: if ($action eq 'upload') {
8513: if (!print FH ($env{'form.'.$formname})) {
8514: &Apache::lonnet::logthis('Failed to write to '.$source);
8515: return (&mt('Failed to write file'));
8516: }
8517: } else {
8518: my $original = &Apache::lonnet::filelocation('',$formname);
8519: if(!copy($original,$source)) {
8520: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8521: return (&mt('Failed to write file'));
8522: }
8523: }
8524: close(FH);
8525: chmod(0660, $source); # Permissions to rw-rw---.
8526:
8527: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8528: my $copyfile=$targetdir.'/'.$file;
8529:
8530: my @parts=split(/\//,$targetdir);
8531: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8532: for (my $count=5;$count<=$#parts;$count++) {
8533: $path.="/$parts[$count]";
8534: if (!-e $path) {
8535: print $logfile "\nCreating directory ".$path;
8536: mkdir($path,02770);
8537: }
8538: }
8539: my $versionresult;
8540: if (-e $copyfile) {
8541: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8542: } else {
8543: $versionresult = 'ok';
8544: }
8545: if ($versionresult eq 'ok') {
8546: if (copy($source,$copyfile)) {
8547: print $logfile "\nCopied original source to ".$copyfile."\n";
8548: $output = 'ok';
8549: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8550: push(@{$modified_urls},[$copyfile,$source]);
8551: my $metaoutput =
8552: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8553: unless ($registered_cleanup) {
8554: my $handlers = $r->get_handlers('PerlCleanupHandler');
8555: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8556: $registered_cleanup=1;
8557: }
1.9 raeburn 8558: } else {
8559: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8560: $output = &mt('Failed to copy file to RES space').", $!";
8561: }
8562: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8563: my $inputfile = $filepath.'/'.$file;
8564: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8565: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8566: if ($fullwidth ne '' && $fullheight ne '') {
8567: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8568: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8569: system("convert -sample $thumbsize $inputfile $outfile");
8570: chmod(0660, $filepath.'/tn-'.$file);
8571: if (-e $outfile) {
8572: my $copyfile=$targetdir.'/tn-'.$file;
8573: if (copy($outfile,$copyfile)) {
8574: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8575: my $thumb_metaoutput =
8576: &write_metadata($dom,$confname,$formname,
8577: $targetdir,'tn-'.$file,$logfile);
8578: push(@{$modified_urls},[$copyfile,$outfile]);
8579: unless ($registered_cleanup) {
8580: my $handlers = $r->get_handlers('PerlCleanupHandler');
8581: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8582: $registered_cleanup=1;
8583: }
1.267 raeburn 8584: $madethumb = 1;
1.16 raeburn 8585: } else {
8586: print $logfile "\nUnable to write ".$copyfile.
8587: ':'.$!."\n";
8588: }
8589: }
1.9 raeburn 8590: }
8591: }
8592: }
8593: } else {
8594: $output = $versionresult;
8595: }
8596: }
1.267 raeburn 8597: return ($output,$logourl,$madethumb);
1.9 raeburn 8598: }
8599:
8600: sub logo_versioning {
8601: my ($targetdir,$file,$logfile) = @_;
8602: my $target = $targetdir.'/'.$file;
8603: my ($maxversion,$fn,$extn,$output);
8604: $maxversion = 0;
8605: if ($file =~ /^(.+)\.(\w+)$/) {
8606: $fn=$1;
8607: $extn=$2;
8608: }
8609: opendir(DIR,$targetdir);
8610: while (my $filename=readdir(DIR)) {
8611: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8612: $maxversion=($1>$maxversion)?$1:$maxversion;
8613: }
8614: }
8615: $maxversion++;
8616: print $logfile "\nCreating old version ".$maxversion."\n";
8617: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8618: if (copy($target,$copyfile)) {
8619: print $logfile "Copied old target to ".$copyfile."\n";
8620: $copyfile=$copyfile.'.meta';
8621: if (copy($target.'.meta',$copyfile)) {
8622: print $logfile "Copied old target metadata to ".$copyfile."\n";
8623: $output = 'ok';
8624: } else {
8625: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8626: $output = &mt('Failed to copy old meta').", $!, ";
8627: }
8628: } else {
8629: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8630: $output = &mt('Failed to copy old target').", $!, ";
8631: }
8632: return $output;
8633: }
8634:
8635: sub write_metadata {
8636: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8637: my (%metadatafields,%metadatakeys,$output);
8638: $metadatafields{'title'}=$formname;
8639: $metadatafields{'creationdate'}=time;
8640: $metadatafields{'lastrevisiondate'}=time;
8641: $metadatafields{'copyright'}='public';
8642: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8643: $env{'user.domain'};
8644: $metadatafields{'authorspace'}=$confname.':'.$dom;
8645: $metadatafields{'domain'}=$dom;
8646: {
8647: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8648: my $mfh;
1.155 raeburn 8649: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 8650: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8651: unless ($_=~/\./) {
8652: my $unikey=$_;
8653: $unikey=~/^([A-Za-z]+)/;
8654: my $tag=$1;
8655: $tag=~tr/A-Z/a-z/;
8656: print $mfh "\n\<$tag";
8657: foreach (split(/\,/,$metadatakeys{$unikey})) {
8658: my $value=$metadatafields{$unikey.'.'.$_};
8659: $value=~s/\"/\'\'/g;
8660: print $mfh ' '.$_.'="'.$value.'"';
8661: }
8662: print $mfh '>'.
8663: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8664: .'</'.$tag.'>';
8665: }
8666: }
8667: $output = 'ok';
8668: print $logfile "\nWrote metadata";
8669: close($mfh);
8670: } else {
8671: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8672: $output = &mt('Could not write metadata');
8673: }
8674: }
1.155 raeburn 8675: return $output;
8676: }
8677:
8678: sub notifysubscribed {
8679: foreach my $targetsource (@{$modified_urls}){
8680: next unless (ref($targetsource) eq 'ARRAY');
8681: my ($target,$source)=@{$targetsource};
8682: if ($source ne '') {
8683: if (open(my $logfh,'>>'.$source.'.log')) {
8684: print $logfh "\nCleanup phase: Notifications\n";
8685: my @subscribed=&subscribed_hosts($target);
8686: foreach my $subhost (@subscribed) {
8687: print $logfh "\nNotifying host ".$subhost.':';
8688: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8689: print $logfh $reply;
8690: }
8691: my @subscribedmeta=&subscribed_hosts("$target.meta");
8692: foreach my $subhost (@subscribedmeta) {
8693: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8694: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8695: $subhost);
8696: print $logfh $reply;
8697: }
8698: print $logfh "\n============ Done ============\n";
1.160 raeburn 8699: close($logfh);
1.155 raeburn 8700: }
8701: }
8702: }
8703: return OK;
8704: }
8705:
8706: sub subscribed_hosts {
8707: my ($target) = @_;
8708: my @subscribed;
8709: if (open(my $fh,"<$target.subscription")) {
8710: while (my $subline=<$fh>) {
8711: if ($subline =~ /^($match_lonid):/) {
8712: my $host = $1;
8713: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8714: unless (grep(/^\Q$host\E$/,@subscribed)) {
8715: push(@subscribed,$host);
8716: }
8717: }
8718: }
8719: }
8720: }
8721: return @subscribed;
1.9 raeburn 8722: }
8723:
8724: sub check_switchserver {
8725: my ($dom,$confname) = @_;
8726: my ($allowed,$switchserver);
8727: my $home = &Apache::lonnet::homeserver($confname,$dom);
8728: if ($home eq 'no_host') {
8729: $home = &Apache::lonnet::domain($dom,'primary');
8730: }
8731: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8732: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8733: if (!$allowed) {
1.180 raeburn 8734: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8735: }
8736: return $switchserver;
8737: }
8738:
1.1 raeburn 8739: sub modify_quotas {
1.216 raeburn 8740: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8741: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 8742: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 8743: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8744: $validationfieldsref);
1.86 raeburn 8745: if ($action eq 'quotas') {
8746: $context = 'tools';
1.163 raeburn 8747: } else {
1.86 raeburn 8748: $context = $action;
8749: }
8750: if ($context eq 'requestcourses') {
1.271 raeburn 8751: @usertools = ('official','unofficial','community','textbook','placement');
1.106 raeburn 8752: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8753: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8754: %titles = &courserequest_titles();
8755: $toolregexp = join('|',@usertools);
8756: %conditions = &courserequest_conditions();
1.216 raeburn 8757: $confname = $dom.'-domainconfig';
8758: my $servadm = $r->dir_config('lonAdmEMail');
8759: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 8760: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8761: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 8762: } elsif ($context eq 'requestauthor') {
8763: @usertools = ('author');
8764: %titles = &authorrequest_titles();
1.86 raeburn 8765: } else {
1.162 raeburn 8766: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8767: %titles = &tool_titles();
1.86 raeburn 8768: }
1.212 raeburn 8769: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8770: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8771: foreach my $key (keys(%env)) {
1.101 raeburn 8772: if ($context eq 'requestcourses') {
8773: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8774: my $item = $1;
8775: my $type = $2;
8776: if ($type =~ /^limit_(.+)/) {
8777: $limithash{$item}{$1} = $env{$key};
8778: } else {
8779: $confhash{$item}{$type} = $env{$key};
8780: }
8781: }
1.163 raeburn 8782: } elsif ($context eq 'requestauthor') {
8783: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8784: $confhash{$1} = $env{$key};
8785: }
1.101 raeburn 8786: } else {
1.86 raeburn 8787: if ($key =~ /^form\.quota_(.+)$/) {
8788: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 8789: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8790: $confhash{'authorquota'}{$1} = $env{$key};
8791: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8792: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8793: }
1.72 raeburn 8794: }
8795: }
1.163 raeburn 8796: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 8797: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8798: @approvalnotify = sort(@approvalnotify);
8799: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271 raeburn 8800: my @crstypes = ('official','unofficial','community','textbook','placement');
1.218 raeburn 8801: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8802: foreach my $type (@hasuniquecode) {
8803: if (grep(/^\Q$type\E$/,@crstypes)) {
8804: $confhash{'uniquecode'}{$type} = 1;
8805: }
1.216 raeburn 8806: }
1.242 raeburn 8807: my (%newbook,%allpos);
1.216 raeburn 8808: if ($context eq 'requestcourses') {
1.242 raeburn 8809: foreach my $type ('textbooks','templates') {
8810: @{$allpos{$type}} = ();
8811: my $invalid;
8812: if ($type eq 'textbooks') {
8813: $invalid = &mt('Invalid LON-CAPA course for textbook');
8814: } else {
8815: $invalid = &mt('Invalid LON-CAPA course for template');
8816: }
8817: if ($env{'form.'.$type.'_addbook'}) {
8818: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8819: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8820: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8821: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8822: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8823: } else {
8824: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8825: my $position = $env{'form.'.$type.'_addbook_pos'};
8826: $position =~ s/\D+//g;
8827: if ($position ne '') {
8828: $allpos{$type}[$position] = $newbook{$type};
8829: }
1.216 raeburn 8830: }
1.242 raeburn 8831: } else {
8832: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 8833: }
8834: }
1.242 raeburn 8835: }
1.216 raeburn 8836: }
1.102 raeburn 8837: if (ref($domconfig{$action}) eq 'HASH') {
8838: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8839: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8840: $changes{'notify'}{'approval'} = 1;
8841: }
8842: } else {
1.144 raeburn 8843: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8844: $changes{'notify'}{'approval'} = 1;
8845: }
8846: }
1.218 raeburn 8847: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8848: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8849: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8850: unless ($confhash{'uniquecode'}{$crstype}) {
8851: $changes{'uniquecode'} = 1;
8852: }
8853: }
8854: unless ($changes{'uniquecode'}) {
8855: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8856: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8857: $changes{'uniquecode'} = 1;
8858: }
8859: }
8860: }
8861: } else {
8862: $changes{'uniquecode'} = 1;
8863: }
8864: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8865: $changes{'uniquecode'} = 1;
1.216 raeburn 8866: }
8867: if ($context eq 'requestcourses') {
1.242 raeburn 8868: foreach my $type ('textbooks','templates') {
8869: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8870: my %deletions;
8871: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8872: if (@todelete) {
8873: map { $deletions{$_} = 1; } @todelete;
8874: }
8875: my %imgdeletions;
8876: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8877: if (@todeleteimages) {
8878: map { $imgdeletions{$_} = 1; } @todeleteimages;
8879: }
8880: my $maxnum = $env{'form.'.$type.'_maxnum'};
8881: for (my $i=0; $i<=$maxnum; $i++) {
8882: my $itemid = $env{'form.'.$type.'_id_'.$i};
8883: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8884: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8885: if ($deletions{$key}) {
8886: if ($domconfig{$action}{$type}{$key}{'image'}) {
8887: #FIXME need to obsolete item in RES space
8888: }
8889: next;
8890: } else {
8891: my $newpos = $env{'form.'.$itemid};
8892: $newpos =~ s/\D+//g;
1.243 raeburn 8893: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 8894: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 8895: ($type eq 'templates'));
1.242 raeburn 8896: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8897: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8898: $changes{$type}{$key} = 1;
8899: }
8900: }
8901: $allpos{$type}[$newpos] = $key;
8902: }
8903: if ($imgdeletions{$key}) {
8904: $changes{$type}{$key} = 1;
1.216 raeburn 8905: #FIXME need to obsolete item in RES space
1.242 raeburn 8906: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8907: my ($cdom,$cnum) = split(/_/,$key);
8908: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8909: $cdom,$cnum,$type,$configuserok,
8910: $switchserver,$author_ok);
8911: if ($imgurl) {
8912: $confhash{$type}{$key}{'image'} = $imgurl;
8913: $changes{$type}{$key} = 1;
1.216 raeburn 8914: }
1.242 raeburn 8915: if ($error) {
8916: &Apache::lonnet::logthis($error);
8917: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8918: }
8919: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8920: $confhash{$type}{$key}{'image'} =
8921: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 8922: }
8923: }
8924: }
8925: }
8926: }
8927: }
1.102 raeburn 8928: } else {
1.144 raeburn 8929: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8930: $changes{'notify'}{'approval'} = 1;
8931: }
1.218 raeburn 8932: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 8933: $changes{'uniquecode'} = 1;
8934: }
8935: }
8936: if ($context eq 'requestcourses') {
1.242 raeburn 8937: foreach my $type ('textbooks','templates') {
8938: if ($newbook{$type}) {
8939: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 8940: foreach my $item ('subject','title','publisher','author') {
8941: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8942: ($type eq 'template'));
1.242 raeburn 8943: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8944: if ($env{'form.'.$type.'_addbook_'.$item}) {
8945: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8946: }
8947: }
8948: if ($type eq 'textbooks') {
8949: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8950: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8951: my ($imageurl,$error) =
8952: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8953: $configuserok,$switchserver,$author_ok);
8954: if ($imageurl) {
8955: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8956: }
8957: if ($error) {
8958: &Apache::lonnet::logthis($error);
8959: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8960: }
8961: }
1.216 raeburn 8962: }
8963: }
1.242 raeburn 8964: if (@{$allpos{$type}} > 0) {
8965: my $idx = 0;
8966: foreach my $item (@{$allpos{$type}}) {
8967: if ($item ne '') {
8968: $confhash{$type}{$item}{'order'} = $idx;
8969: if (ref($domconfig{$action}) eq 'HASH') {
8970: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8971: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8972: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8973: $changes{$type}{$item} = 1;
8974: }
1.216 raeburn 8975: }
8976: }
8977: }
1.242 raeburn 8978: $idx ++;
1.216 raeburn 8979: }
8980: }
8981: }
8982: }
1.235 raeburn 8983: if (ref($validationitemsref) eq 'ARRAY') {
8984: foreach my $item (@{$validationitemsref}) {
8985: if ($item eq 'fields') {
8986: my @changed;
8987: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8988: if (@{$confhash{'validation'}{$item}} > 0) {
8989: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8990: }
1.266 raeburn 8991: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8992: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8993: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8994: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8995: $domconfig{'requestcourses'}{'validation'}{$item});
8996: } else {
8997: @changed = @{$confhash{'validation'}{$item}};
8998: }
1.235 raeburn 8999: } else {
9000: @changed = @{$confhash{'validation'}{$item}};
9001: }
9002: } else {
9003: @changed = @{$confhash{'validation'}{$item}};
9004: }
9005: if (@changed) {
9006: if ($confhash{'validation'}{$item}) {
9007: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
9008: } else {
9009: $changes{'validation'}{$item} = &mt('None');
9010: }
9011: }
9012: } else {
9013: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
9014: if ($item eq 'markup') {
9015: if ($env{'form.requestcourses_validation_'.$item}) {
9016: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
9017: }
9018: }
1.266 raeburn 9019: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9020: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9021: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
9022: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9023: }
9024: } else {
9025: if ($confhash{'validation'}{$item} ne '') {
9026: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9027: }
1.235 raeburn 9028: }
9029: } else {
9030: if ($confhash{'validation'}{$item} ne '') {
9031: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
9032: }
9033: }
9034: }
9035: }
9036: }
9037: if ($env{'form.validationdc'}) {
9038: my $newval = $env{'form.validationdc'};
1.285 raeburn 9039: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 9040: if (exists($domcoords{$newval})) {
9041: $confhash{'validation'}{'dc'} = $newval;
9042: }
9043: }
9044: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 9045: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9046: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9047: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9048: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
9049: if ($confhash{'validation'}{'dc'} eq '') {
9050: $changes{'validation'}{'dc'} = &mt('None');
9051: } else {
9052: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9053: }
1.235 raeburn 9054: }
1.266 raeburn 9055: } elsif ($confhash{'validation'}{'dc'} ne '') {
9056: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 9057: }
9058: } elsif ($confhash{'validation'}{'dc'} ne '') {
9059: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
9060: }
9061: } elsif ($confhash{'validation'}{'dc'} ne '') {
9062: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 9063: }
1.266 raeburn 9064: } else {
9065: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
9066: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
9067: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
9068: $changes{'validation'}{'dc'} = &mt('None');
9069: }
9070: }
1.235 raeburn 9071: }
9072: }
1.102 raeburn 9073: }
9074: } else {
1.86 raeburn 9075: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 9076: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 9077: }
1.72 raeburn 9078: foreach my $item (@usertools) {
9079: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 9080: my $unset;
1.101 raeburn 9081: if ($context eq 'requestcourses') {
1.104 raeburn 9082: $unset = '0';
9083: if ($type eq '_LC_adv') {
9084: $unset = '';
9085: }
1.101 raeburn 9086: if ($confhash{$item}{$type} eq 'autolimit') {
9087: $confhash{$item}{$type} .= '=';
9088: unless ($limithash{$item}{$type} =~ /\D/) {
9089: $confhash{$item}{$type} .= $limithash{$item}{$type};
9090: }
9091: }
1.163 raeburn 9092: } elsif ($context eq 'requestauthor') {
9093: $unset = '0';
9094: if ($type eq '_LC_adv') {
9095: $unset = '';
9096: }
1.72 raeburn 9097: } else {
1.101 raeburn 9098: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
9099: $confhash{$item}{$type} = 1;
9100: } else {
9101: $confhash{$item}{$type} = 0;
9102: }
1.72 raeburn 9103: }
1.86 raeburn 9104: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 9105: if ($action eq 'requestauthor') {
9106: if ($domconfig{$action}{$type} ne $confhash{$type}) {
9107: $changes{$type} = 1;
9108: }
9109: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 9110: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
9111: $changes{$item}{$type} = 1;
9112: }
9113: } else {
9114: if ($context eq 'requestcourses') {
1.104 raeburn 9115: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 9116: $changes{$item}{$type} = 1;
9117: }
9118: } else {
9119: if (!$confhash{$item}{$type}) {
9120: $changes{$item}{$type} = 1;
9121: }
9122: }
9123: }
9124: } else {
9125: if ($context eq 'requestcourses') {
1.104 raeburn 9126: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 9127: $changes{$item}{$type} = 1;
9128: }
1.163 raeburn 9129: } elsif ($context eq 'requestauthor') {
9130: if ($confhash{$type} ne $unset) {
9131: $changes{$type} = 1;
9132: }
1.72 raeburn 9133: } else {
9134: if (!$confhash{$item}{$type}) {
9135: $changes{$item}{$type} = 1;
9136: }
9137: }
9138: }
1.1 raeburn 9139: }
9140: }
1.163 raeburn 9141: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 9142: if (ref($domconfig{'quotas'}) eq 'HASH') {
9143: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9144: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
9145: if (exists($confhash{'defaultquota'}{$key})) {
9146: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
9147: $changes{'defaultquota'}{$key} = 1;
9148: }
9149: } else {
9150: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 9151: }
9152: }
1.86 raeburn 9153: } else {
9154: foreach my $key (keys(%{$domconfig{'quotas'}})) {
9155: if (exists($confhash{'defaultquota'}{$key})) {
9156: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
9157: $changes{'defaultquota'}{$key} = 1;
9158: }
9159: } else {
9160: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 9161: }
1.1 raeburn 9162: }
9163: }
1.197 raeburn 9164: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9165: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
9166: if (exists($confhash{'authorquota'}{$key})) {
9167: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
9168: $changes{'authorquota'}{$key} = 1;
9169: }
9170: } else {
9171: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
9172: }
9173: }
9174: }
1.1 raeburn 9175: }
1.86 raeburn 9176: if (ref($confhash{'defaultquota'}) eq 'HASH') {
9177: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
9178: if (ref($domconfig{'quotas'}) eq 'HASH') {
9179: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
9180: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
9181: $changes{'defaultquota'}{$key} = 1;
9182: }
9183: } else {
9184: if (!exists($domconfig{'quotas'}{$key})) {
9185: $changes{'defaultquota'}{$key} = 1;
9186: }
1.72 raeburn 9187: }
9188: } else {
1.86 raeburn 9189: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 9190: }
1.1 raeburn 9191: }
9192: }
1.197 raeburn 9193: if (ref($confhash{'authorquota'}) eq 'HASH') {
9194: foreach my $key (keys(%{$confhash{'authorquota'}})) {
9195: if (ref($domconfig{'quotas'}) eq 'HASH') {
9196: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9197: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9198: $changes{'authorquota'}{$key} = 1;
9199: }
9200: } else {
9201: $changes{'authorquota'}{$key} = 1;
9202: }
9203: } else {
9204: $changes{'authorquota'}{$key} = 1;
9205: }
9206: }
9207: }
1.1 raeburn 9208: }
1.72 raeburn 9209:
1.163 raeburn 9210: if ($context eq 'requestauthor') {
9211: $domdefaults{'requestauthor'} = \%confhash;
9212: } else {
9213: foreach my $key (keys(%confhash)) {
1.242 raeburn 9214: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 9215: $domdefaults{$key} = $confhash{$key};
9216: }
1.163 raeburn 9217: }
1.72 raeburn 9218: }
1.163 raeburn 9219:
1.1 raeburn 9220: my %quotahash = (
1.86 raeburn 9221: $action => { %confhash }
1.1 raeburn 9222: );
9223: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9224: $dom);
9225: if ($putresult eq 'ok') {
9226: if (keys(%changes) > 0) {
1.72 raeburn 9227: my $cachetime = 24*60*60;
9228: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 9229: if (ref($lastactref) eq 'HASH') {
9230: $lastactref->{'domdefaults'} = 1;
9231: }
1.1 raeburn 9232: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 9233: unless (($context eq 'requestcourses') ||
1.163 raeburn 9234: ($context eq 'requestauthor')) {
1.86 raeburn 9235: if (ref($changes{'defaultquota'}) eq 'HASH') {
9236: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9237: foreach my $type (@{$types},'default') {
9238: if (defined($changes{'defaultquota'}{$type})) {
9239: my $typetitle = $usertypes->{$type};
9240: if ($type eq 'default') {
9241: $typetitle = $othertitle;
9242: }
1.213 raeburn 9243: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9244: }
9245: }
1.86 raeburn 9246: $resulttext .= '</ul></li>';
1.72 raeburn 9247: }
1.197 raeburn 9248: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 9249: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 9250: foreach my $type (@{$types},'default') {
9251: if (defined($changes{'authorquota'}{$type})) {
9252: my $typetitle = $usertypes->{$type};
9253: if ($type eq 'default') {
9254: $typetitle = $othertitle;
9255: }
1.213 raeburn 9256: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 9257: }
9258: }
9259: $resulttext .= '</ul></li>';
9260: }
1.72 raeburn 9261: }
1.80 raeburn 9262: my %newenv;
1.72 raeburn 9263: foreach my $item (@usertools) {
1.163 raeburn 9264: my (%haschgs,%inconf);
9265: if ($context eq 'requestauthor') {
9266: %haschgs = %changes;
1.210 raeburn 9267: %inconf = %confhash;
1.163 raeburn 9268: } else {
9269: if (ref($changes{$item}) eq 'HASH') {
9270: %haschgs = %{$changes{$item}};
9271: }
9272: if (ref($confhash{$item}) eq 'HASH') {
9273: %inconf = %{$confhash{$item}};
9274: }
9275: }
9276: if (keys(%haschgs) > 0) {
1.80 raeburn 9277: my $newacc =
9278: &Apache::lonnet::usertools_access($env{'user.name'},
9279: $env{'user.domain'},
1.86 raeburn 9280: $item,'reload',$context);
1.210 raeburn 9281: if (($context eq 'requestcourses') ||
1.163 raeburn 9282: ($context eq 'requestauthor')) {
1.108 raeburn 9283: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9284: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9285: }
9286: } else {
9287: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9288: $newenv{'environment.availabletools.'.$item} = $newacc;
9289: }
1.80 raeburn 9290: }
1.163 raeburn 9291: unless ($context eq 'requestauthor') {
9292: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9293: }
1.72 raeburn 9294: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 9295: if ($haschgs{$type}) {
1.72 raeburn 9296: my $typetitle = $usertypes->{$type};
9297: if ($type eq 'default') {
9298: $typetitle = $othertitle;
9299: } elsif ($type eq '_LC_adv') {
9300: $typetitle = 'LON-CAPA Advanced Users';
9301: }
1.163 raeburn 9302: if ($inconf{$type}) {
1.101 raeburn 9303: if ($context eq 'requestcourses') {
9304: my $cond;
1.163 raeburn 9305: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9306: if ($1 eq '') {
9307: $cond = &mt('(Automatic processing of any request).');
9308: } else {
9309: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9310: }
9311: } else {
1.163 raeburn 9312: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9313: }
9314: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 9315: } elsif ($context eq 'requestauthor') {
9316: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9317: $titles{$inconf{$type}},$typetitle);
9318:
1.101 raeburn 9319: } else {
9320: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9321: }
1.72 raeburn 9322: } else {
1.104 raeburn 9323: if ($type eq '_LC_adv') {
1.163 raeburn 9324: if ($inconf{$type} eq '0') {
1.104 raeburn 9325: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9326: } else {
9327: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9328: }
9329: } else {
9330: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9331: }
1.72 raeburn 9332: }
9333: }
1.26 raeburn 9334: }
1.163 raeburn 9335: unless ($context eq 'requestauthor') {
9336: $resulttext .= '</ul></li>';
9337: }
1.26 raeburn 9338: }
1.1 raeburn 9339: }
1.163 raeburn 9340: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9341: if (ref($changes{'notify'}) eq 'HASH') {
9342: if ($changes{'notify'}{'approval'}) {
9343: if (ref($confhash{'notify'}) eq 'HASH') {
9344: if ($confhash{'notify'}{'approval'}) {
9345: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9346: } else {
1.163 raeburn 9347: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9348: }
9349: }
9350: }
9351: }
9352: }
1.216 raeburn 9353: if ($action eq 'requestcourses') {
9354: my @offon = ('off','on');
9355: if ($changes{'uniquecode'}) {
1.218 raeburn 9356: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9357: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9358: $resulttext .= '<li>'.
9359: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9360: '</li>';
9361: } else {
9362: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9363: '</li>';
9364: }
1.216 raeburn 9365: }
1.242 raeburn 9366: foreach my $type ('textbooks','templates') {
9367: if (ref($changes{$type}) eq 'HASH') {
9368: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9369: foreach my $key (sort(keys(%{$changes{$type}}))) {
9370: my %coursehash = &Apache::lonnet::coursedescription($key);
9371: my $coursetitle = $coursehash{'description'};
9372: my $position = $confhash{$type}{$key}{'order'} + 1;
9373: $resulttext .= '<li>';
1.243 raeburn 9374: foreach my $item ('subject','title','publisher','author') {
9375: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9376: ($type eq 'templates'));
1.242 raeburn 9377: my $name = $item.':';
9378: $name =~ s/^(\w)/\U$1/;
9379: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9380: }
9381: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9382: if ($type eq 'textbooks') {
9383: if ($confhash{$type}{$key}{'image'}) {
9384: $resulttext .= ' '.&mt('Image: [_1]',
9385: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9386: ' alt="Textbook cover" />').'<br />';
9387: }
9388: }
9389: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 9390: }
1.242 raeburn 9391: $resulttext .= '</ul></li>';
1.216 raeburn 9392: }
9393: }
1.235 raeburn 9394: if (ref($changes{'validation'}) eq 'HASH') {
9395: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9396: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9397: foreach my $item (@{$validationitemsref}) {
9398: if (exists($changes{'validation'}{$item})) {
9399: if ($item eq 'markup') {
9400: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9401: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9402: } else {
9403: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9404: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9405: }
9406: }
9407: }
9408: if (exists($changes{'validation'}{'dc'})) {
9409: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9410: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9411: }
9412: }
9413: }
1.216 raeburn 9414: }
1.1 raeburn 9415: $resulttext .= '</ul>';
1.80 raeburn 9416: if (keys(%newenv)) {
9417: &Apache::lonnet::appenv(\%newenv);
9418: }
1.1 raeburn 9419: } else {
1.86 raeburn 9420: if ($context eq 'requestcourses') {
9421: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 9422: } elsif ($context eq 'requestauthor') {
9423: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9424: } else {
1.90 weissno 9425: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9426: }
1.1 raeburn 9427: }
9428: } else {
1.11 albertel 9429: $resulttext = '<span class="LC_error">'.
9430: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9431: }
1.216 raeburn 9432: if ($errors) {
9433: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9434: '<ul>'.$errors.'</ul></p>';
9435: }
1.3 raeburn 9436: return $resulttext;
1.1 raeburn 9437: }
9438:
1.216 raeburn 9439: sub process_textbook_image {
1.242 raeburn 9440: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 9441: my $filename = $env{'form.'.$caller.'.filename'};
9442: my ($error,$url);
9443: my ($width,$height) = (50,50);
9444: if ($configuserok eq 'ok') {
9445: if ($switchserver) {
9446: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9447: $switchserver);
9448: } elsif ($author_ok eq 'ok') {
9449: my ($result,$imageurl) =
9450: &publishlogo($r,'upload',$caller,$dom,$confname,
1.242 raeburn 9451: "$type/$dom/$cnum/cover",$width,$height);
1.216 raeburn 9452: if ($result eq 'ok') {
9453: $url = $imageurl;
9454: } else {
9455: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9456: }
9457: } else {
9458: $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);
9459: }
9460: } else {
9461: $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);
9462: }
9463: return ($url,$error);
9464: }
9465:
1.267 raeburn 9466: sub modify_ltitools {
9467: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
9468: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9469: my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
9470: my $confname = $dom.'-domainconfig';
9471: my $servadm = $r->dir_config('lonAdmEMail');
9472: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
9473: my (%posslti,%possfield);
9474: my @courseroles = ('cc','in','ta','ep','st');
9475: my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
9476: map { $posslti{$_} = 1; } @ltiroles;
9477: my @allfields = ('fullname','firstname','lastname','email','user','roles');
9478: map { $possfield{$_} = 1; } @allfields;
9479: my %lt = <itools_names();
9480: if ($env{'form.ltitools_add'}) {
9481: my $title = $env{'form.ltitools_add_title'};
9482: $title =~ s/(`)/'/g;
9483: ($newid,my $error) = &get_ltitools_id($dom,$title);
9484: if ($newid) {
9485: my $position = $env{'form.ltitools_add_pos'};
9486: $position =~ s/\D+//g;
9487: if ($position ne '') {
9488: $allpos[$position] = $newid;
9489: }
9490: $changes{$newid} = 1;
9491: foreach my $item ('title','url','key','secret') {
9492: $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
9493: if ($env{'form.ltitools_add_'.$item}) {
9494: $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
9495: }
9496: }
9497: if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
9498: $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
9499: }
9500: if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
9501: $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
9502: }
1.296 ! raeburn 9503: foreach my $item ('width','height','linktext','explanation') {
1.267 raeburn 9504: $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
9505: $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296 ! raeburn 9506: if (($item eq 'width') || ($item eq 'height')) {
! 9507: if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
! 9508: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
! 9509: }
! 9510: } else {
! 9511: if ($env{'form.ltitools_add_'.$item} ne '') {
! 9512: $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
! 9513: }
1.267 raeburn 9514: }
9515: }
9516: if ($env{'form.ltitools_add_target'} eq 'window') {
9517: $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
9518: } else {
9519: $confhash{$newid}{'display'}{'target'} = 'iframe';
9520: }
9521: foreach my $item ('passback','roster') {
9522: if ($env{'form.ltitools_add_'.$item}) {
9523: $confhash{$newid}{$item} = 1;
9524: }
9525: }
9526: if ($env{'form.ltitools_add_image.filename'} ne '') {
9527: my ($imageurl,$error) =
9528: &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
9529: $configuserok,$switchserver,$author_ok);
9530: if ($imageurl) {
9531: $confhash{$newid}{'image'} = $imageurl;
9532: }
9533: if ($error) {
9534: &Apache::lonnet::logthis($error);
9535: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9536: }
9537: }
9538: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
9539: foreach my $field (@fields) {
9540: if ($possfield{$field}) {
9541: if ($field eq 'roles') {
9542: foreach my $role (@courseroles) {
9543: my $choice = $env{'form.ltitools_add_roles_'.$role};
9544: if (($choice ne '') && ($posslti{$choice})) {
9545: $confhash{$newid}{'roles'}{$role} = $choice;
9546: if ($role eq 'cc') {
9547: $confhash{$newid}{'roles'}{'co'} = $choice;
9548: }
9549: }
9550: }
9551: } else {
9552: $confhash{$newid}{'fields'}{$field} = 1;
9553: }
9554: }
9555: }
1.273 raeburn 9556: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
9557: foreach my $item (@courseconfig) {
9558: $confhash{$newid}{'crsconf'}{$item} = 1;
9559: }
1.267 raeburn 9560: if ($env{'form.ltitools_add_custom'}) {
9561: my $name = $env{'form.ltitools_add_custom_name'};
9562: my $value = $env{'form.ltitools_add_custom_value'};
9563: $value =~ s/(`)/'/g;
9564: $name =~ s/(`)/'/g;
9565: $confhash{$newid}{'custom'}{$name} = $value;
9566: }
9567: } else {
9568: my $error = &mt('Failed to acquire unique ID for new external tool');
9569: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9570: }
9571: }
9572: if (ref($domconfig{$action}) eq 'HASH') {
9573: my %deletions;
9574: my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
9575: if (@todelete) {
9576: map { $deletions{$_} = 1; } @todelete;
9577: }
9578: my %customadds;
9579: my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
9580: if (@newcustom) {
9581: map { $customadds{$_} = 1; } @newcustom;
9582: }
9583: my %imgdeletions;
9584: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
9585: if (@todeleteimages) {
9586: map { $imgdeletions{$_} = 1; } @todeleteimages;
9587: }
9588: my $maxnum = $env{'form.ltitools_maxnum'};
9589: for (my $i=0; $i<=$maxnum; $i++) {
9590: my $itemid = $env{'form.ltitools_id_'.$i};
9591: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9592: if ($deletions{$itemid}) {
9593: if ($domconfig{$action}{$itemid}{'image'}) {
9594: #FIXME need to obsolete item in RES space
9595: }
9596: $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
9597: next;
9598: } else {
9599: my $newpos = $env{'form.ltitools_'.$itemid};
9600: $newpos =~ s/\D+//g;
9601: foreach my $item ('title','url','key','secret') {
9602: $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
9603: if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
9604: $changes{$itemid} = 1;
9605: }
9606: }
9607: if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
9608: $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
9609: }
9610: if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
9611: $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
9612: }
9613: foreach my $size ('width','height') {
9614: $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
9615: $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
9616: if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
9617: $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
9618: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9619: if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
9620: $changes{$itemid} = 1;
9621: }
9622: } else {
9623: $changes{$itemid} = 1;
9624: }
1.296 ! raeburn 9625: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
! 9626: if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
! 9627: $changes{$itemid} = 1;
! 9628: }
! 9629: }
! 9630: }
! 9631: foreach my $item ('linktext','explanation') {
! 9632: $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
! 9633: $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
! 9634: if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
! 9635: $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
! 9636: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
! 9637: if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
! 9638: $changes{$itemid} = 1;
! 9639: }
! 9640: } else {
! 9641: $changes{$itemid} = 1;
! 9642: }
! 9643: } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
! 9644: if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
! 9645: $changes{$itemid} = 1;
! 9646: }
1.267 raeburn 9647: }
9648: }
9649: if ($env{'form.ltitools_target_'.$i} eq 'window') {
9650: $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
9651: } else {
9652: $confhash{$itemid}{'display'}{'target'} = 'iframe';
9653: }
9654: if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
9655: if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
9656: $changes{$itemid} = 1;
9657: }
9658: } else {
9659: $changes{$itemid} = 1;
9660: }
9661: foreach my $extra ('passback','roster') {
9662: if ($env{'form.ltitools_'.$extra.'_'.$i}) {
9663: $confhash{$itemid}{$extra} = 1;
9664: }
9665: if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
9666: $changes{$itemid} = 1;
9667: }
9668: }
1.273 raeburn 9669: my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.296 ! raeburn 9670: foreach my $item ('label','title','target','linktext','explanation') {
1.273 raeburn 9671: if (grep(/^\Q$item\E$/,@courseconfig)) {
9672: $confhash{$itemid}{'crsconf'}{$item} = 1;
9673: if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
9674: if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
9675: $changes{$itemid} = 1;
9676: }
9677: } else {
9678: $changes{$itemid} = 1;
9679: }
9680: }
9681: }
1.267 raeburn 9682: my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
9683: foreach my $field (@fields) {
9684: if ($possfield{$field}) {
9685: if ($field eq 'roles') {
9686: foreach my $role (@courseroles) {
9687: my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
9688: if (($choice ne '') && ($posslti{$choice})) {
9689: $confhash{$itemid}{'roles'}{$role} = $choice;
9690: if ($role eq 'cc') {
9691: $confhash{$itemid}{'roles'}{'co'} = $choice;
9692: }
9693: }
9694: if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
9695: if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
9696: $changes{$itemid} = 1;
9697: }
9698: } elsif ($confhash{$itemid}{'roles'}{$role}) {
9699: $changes{$itemid} = 1;
9700: }
9701: }
9702: } else {
9703: $confhash{$itemid}{'fields'}{$field} = 1;
9704: if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
9705: if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
9706: $changes{$itemid} = 1;
9707: }
9708: } else {
9709: $changes{$itemid} = 1;
9710: }
9711: }
9712: }
9713: }
9714: $allpos[$newpos] = $itemid;
9715: }
9716: if ($imgdeletions{$itemid}) {
9717: $changes{$itemid} = 1;
9718: #FIXME need to obsolete item in RES space
9719: } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
9720: my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
9721: $itemid,$configuserok,$switchserver,
9722: $author_ok);
9723: if ($imgurl) {
9724: $confhash{$itemid}{'image'} = $imgurl;
9725: $changes{$itemid} = 1;
9726: }
9727: if ($error) {
9728: &Apache::lonnet::logthis($error);
9729: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
9730: }
9731: } elsif ($domconfig{$action}{$itemid}{'image'}) {
9732: $confhash{$itemid}{'image'} =
9733: $domconfig{$action}{$itemid}{'image'};
9734: }
9735: if ($customadds{$i}) {
9736: my $name = $env{'form.ltitools_custom_name_'.$i};
9737: $name =~ s/(`)/'/g;
9738: $name =~ s/^\s+//;
9739: $name =~ s/\s+$//;
9740: my $value = $env{'form.ltitools_custom_value_'.$i};
9741: $value =~ s/(`)/'/g;
9742: $value =~ s/^\s+//;
9743: $value =~ s/\s+$//;
9744: if ($name ne '') {
9745: $confhash{$itemid}{'custom'}{$name} = $value;
9746: $changes{$itemid} = 1;
9747: }
9748: }
9749: my %customdels;
9750: my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
9751: if (@customdeletions) {
9752: $changes{$itemid} = 1;
9753: }
9754: map { $customdels{$_} = 1; } @customdeletions;
9755: if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
9756: foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
9757: unless ($customdels{$key}) {
9758: if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
9759: $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
9760: }
9761: if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
9762: $changes{$itemid} = 1;
9763: }
9764: }
9765: }
9766: }
9767: unless ($changes{$itemid}) {
9768: foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
9769: if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
9770: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
9771: foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
9772: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
9773: $changes{$itemid} = 1;
9774: last;
9775: }
9776: }
9777: } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
9778: $changes{$itemid} = 1;
9779: }
9780: }
9781: last if ($changes{$itemid});
9782: }
9783: }
9784: }
9785: }
9786: }
9787: if (@allpos > 0) {
9788: my $idx = 0;
9789: foreach my $itemid (@allpos) {
9790: if ($itemid ne '') {
9791: $confhash{$itemid}{'order'} = $idx;
9792: if (ref($domconfig{$action}) eq 'HASH') {
9793: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
9794: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
9795: $changes{$itemid} = 1;
9796: }
9797: }
9798: }
9799: $idx ++;
9800: }
9801: }
9802: }
9803: my %ltitoolshash = (
9804: $action => { %confhash }
9805: );
9806: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
9807: $dom);
9808: if ($putresult eq 'ok') {
9809: if (keys(%changes) > 0) {
9810: my $cachetime = 24*60*60;
9811: &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
9812: if (ref($lastactref) eq 'HASH') {
9813: $lastactref->{'ltitools'} = 1;
9814: }
9815: $resulttext = &mt('Changes made:').'<ul>';
9816: my %bynum;
9817: foreach my $itemid (sort(keys(%changes))) {
9818: my $position = $confhash{$itemid}{'order'};
9819: $bynum{$position} = $itemid;
9820: }
9821: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
9822: my $itemid = $bynum{$pos};
9823: if (ref($confhash{$itemid}) ne 'HASH') {
9824: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
9825: } else {
9826: $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
9827: if ($confhash{$itemid}{'image'}) {
9828: $resulttext .= ' '.
9829: '<img src="'.$confhash{$itemid}{'image'}.'"'.
9830: ' alt="'.&mt('Tool Provider icon').'" />';
9831: }
9832: $resulttext .= '</li><ul>';
9833: my $position = $pos + 1;
9834: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
9835: foreach my $item ('version','msgtype','url','key') {
9836: if ($confhash{$itemid}{$item} ne '') {
9837: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
9838: }
9839: }
9840: if ($confhash{$itemid}{'secret'} ne '') {
9841: $resulttext .= '<li>'.$lt{'secret'}.': ';
9842: my $num = length($confhash{$itemid}{'secret'});
9843: $resulttext .= ('*'x$num).'</li>';
9844: }
1.273 raeburn 9845: $resulttext .= '<li>'.&mt('Configurable in course:');
1.296 ! raeburn 9846: my @possconfig = ('label','title','target','linktext','explanation');
1.273 raeburn 9847: my $numconfig = 0;
9848: if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
9849: foreach my $item (@possconfig) {
9850: if ($confhash{$itemid}{'crsconf'}{$item}) {
9851: $numconfig ++;
1.296 ! raeburn 9852: $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273 raeburn 9853: }
9854: }
9855: }
9856: if (!$numconfig) {
9857: $resulttext .= &mt('None');
9858: }
9859: $resulttext .= '</li>';
1.267 raeburn 9860: foreach my $item ('passback','roster') {
9861: $resulttext .= '<li>'.$lt{$item}.' ';
9862: if ($confhash{$itemid}{$item}) {
9863: $resulttext .= &mt('Yes');
9864: } else {
9865: $resulttext .= &mt('No');
9866: }
9867: $resulttext .= '</li>';
9868: }
9869: if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
9870: my $displaylist;
9871: if ($confhash{$itemid}{'display'}{'target'}) {
9872: $displaylist = &mt('Display target').': '.
9873: $confhash{$itemid}{'display'}{'target'}.',';
9874: }
9875: foreach my $size ('width','height') {
9876: if ($confhash{$itemid}{'display'}{$size}) {
9877: $displaylist .= (' 'x2).$lt{$size}.': '.
9878: $confhash{$itemid}{'display'}{$size}.',';
9879: }
9880: }
9881: if ($displaylist) {
9882: $displaylist =~ s/,$//;
9883: $resulttext .= '<li>'.$displaylist.'</li>';
9884: }
1.296 ! raeburn 9885: foreach my $item ('linktext','explanation') {
! 9886: if ($confhash{$itemid}{'display'}{$item}) {
! 9887: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
! 9888: }
! 9889: }
! 9890: }
1.267 raeburn 9891: if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
9892: my $fieldlist;
9893: foreach my $field (@allfields) {
9894: if ($confhash{$itemid}{'fields'}{$field}) {
9895: $fieldlist .= (' 'x2).$lt{$field}.',';
9896: }
9897: }
9898: if ($fieldlist) {
9899: $fieldlist =~ s/,$//;
9900: $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
9901: }
9902: }
9903: if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
9904: my $rolemaps;
9905: foreach my $role (@courseroles) {
9906: if ($confhash{$itemid}{'roles'}{$role}) {
9907: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
9908: $confhash{$itemid}{'roles'}{$role}.',';
9909: }
9910: }
9911: if ($rolemaps) {
9912: $rolemaps =~ s/,$//;
9913: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
9914: }
9915: }
9916: if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
9917: my $customlist;
9918: if (keys(%{$confhash{$itemid}{'custom'}})) {
9919: foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
9920: $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
9921: }
9922: }
9923: if ($customlist) {
9924: $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
9925: }
9926: }
9927: $resulttext .= '</ul></li>';
9928: }
9929: }
9930: $resulttext .= '</ul>';
9931: } else {
9932: $resulttext = &mt('No changes made.');
9933: }
9934: } else {
9935: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
9936: }
9937: if ($errors) {
9938: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
9939: $errors.'</ul>';
9940: }
9941: return $resulttext;
9942: }
9943:
9944: sub process_ltitools_image {
9945: my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
9946: my $filename = $env{'form.'.$caller.'.filename'};
9947: my ($error,$url);
9948: my ($width,$height) = (21,21);
9949: if ($configuserok eq 'ok') {
9950: if ($switchserver) {
9951: $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
9952: $switchserver);
9953: } elsif ($author_ok eq 'ok') {
9954: my ($result,$imageurl,$madethumb) =
9955: &publishlogo($r,'upload',$caller,$dom,$confname,
9956: "ltitools/$itemid/icon",$width,$height);
9957: if ($result eq 'ok') {
9958: if ($madethumb) {
9959: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
9960: my $imagethumb = "$path/tn-".$imagefile;
9961: $url = $imagethumb;
9962: } else {
9963: $url = $imageurl;
9964: }
9965: } else {
9966: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9967: }
9968: } else {
9969: $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);
9970: }
9971: } else {
9972: $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);
9973: }
9974: return ($url,$error);
9975: }
9976:
9977: sub get_ltitools_id {
9978: my ($cdom,$title) = @_;
9979: # get lock on ltitools db
9980: my $lockhash = {
9981: lock => $env{'user.name'}.
9982: ':'.$env{'user.domain'},
9983: };
9984: my $tries = 0;
9985: my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9986: my ($id,$error);
9987:
9988: while (($gotlock ne 'ok') && ($tries<10)) {
9989: $tries ++;
9990: sleep (0.1);
9991: $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
9992: }
9993: if ($gotlock eq 'ok') {
9994: my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
9995: if ($currids{'lock'}) {
9996: delete($currids{'lock'});
9997: if (keys(%currids)) {
9998: my @curr = sort { $a <=> $b } keys(%currids);
9999: if ($curr[-1] =~ /^\d+$/) {
10000: $id = 1 + $curr[-1];
10001: }
10002: } else {
10003: $id = 1;
10004: }
10005: if ($id) {
10006: unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
10007: $error = 'nostore';
10008: }
10009: } else {
10010: $error = 'nonumber';
10011: }
10012: }
10013: my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
10014: } else {
10015: $error = 'nolock';
10016: }
10017: return ($id,$error);
10018: }
10019:
1.3 raeburn 10020: sub modify_autoenroll {
1.205 raeburn 10021: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 10022: my ($resulttext,%changes);
10023: my %currautoenroll;
10024: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
10025: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
10026: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
10027: }
10028: }
10029: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
10030: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 10031: sender => 'Sender for notification messages',
1.274 raeburn 10032: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
10033: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 10034: my @offon = ('off','on');
1.17 raeburn 10035: my $sender_uname = $env{'form.sender_uname'};
10036: my $sender_domain = $env{'form.sender_domain'};
10037: if ($sender_domain eq '') {
10038: $sender_uname = '';
10039: } elsif ($sender_uname eq '') {
10040: $sender_domain = '';
10041: }
1.129 raeburn 10042: my $coowners = $env{'form.autoassign_coowners'};
1.274 raeburn 10043: my $failsafe = $env{'form.autoenroll_failsafe'};
10044: $failsafe =~ s{^\s+|\s+$}{}g;
10045: if ($failsafe =~ /\D/) {
10046: undef($failsafe);
10047: }
1.1 raeburn 10048: my %autoenrollhash = (
1.129 raeburn 10049: autoenroll => { 'run' => $env{'form.autoenroll_run'},
10050: 'sender_uname' => $sender_uname,
10051: 'sender_domain' => $sender_domain,
10052: 'co-owners' => $coowners,
1.274 raeburn 10053: 'autofailsafe' => $failsafe,
1.1 raeburn 10054: }
10055: );
1.4 raeburn 10056: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
10057: $dom);
1.1 raeburn 10058: if ($putresult eq 'ok') {
10059: if (exists($currautoenroll{'run'})) {
10060: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
10061: $changes{'run'} = 1;
10062: }
10063: } elsif ($autorun) {
10064: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 10065: $changes{'run'} = 1;
1.1 raeburn 10066: }
10067: }
1.17 raeburn 10068: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 10069: $changes{'sender'} = 1;
10070: }
1.17 raeburn 10071: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 10072: $changes{'sender'} = 1;
10073: }
1.129 raeburn 10074: if ($currautoenroll{'co-owners'} ne '') {
10075: if ($currautoenroll{'co-owners'} ne $coowners) {
10076: $changes{'coowners'} = 1;
10077: }
10078: } elsif ($coowners) {
10079: $changes{'coowners'} = 1;
1.274 raeburn 10080: }
10081: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
10082: $changes{'autofailsafe'} = 1;
10083: }
1.1 raeburn 10084: if (keys(%changes) > 0) {
10085: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 10086: if ($changes{'run'}) {
1.1 raeburn 10087: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
10088: }
10089: if ($changes{'sender'}) {
1.17 raeburn 10090: if ($sender_uname eq '' || $sender_domain eq '') {
10091: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
10092: } else {
10093: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
10094: }
1.1 raeburn 10095: }
1.129 raeburn 10096: if ($changes{'coowners'}) {
10097: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
10098: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10099: if (ref($lastactref) eq 'HASH') {
10100: $lastactref->{'domainconfig'} = 1;
10101: }
1.129 raeburn 10102: }
1.274 raeburn 10103: if ($changes{'autofailsafe'}) {
10104: if ($failsafe ne '') {
10105: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
10106: } else {
10107: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
10108: }
10109: &Apache::lonnet::get_domain_defaults($dom,1);
10110: if (ref($lastactref) eq 'HASH') {
10111: $lastactref->{'domdefaults'} = 1;
10112: }
10113: }
1.1 raeburn 10114: $resulttext .= '</ul>';
10115: } else {
10116: $resulttext = &mt('No changes made to auto-enrollment settings');
10117: }
10118: } else {
1.11 albertel 10119: $resulttext = '<span class="LC_error">'.
10120: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10121: }
1.3 raeburn 10122: return $resulttext;
1.1 raeburn 10123: }
10124:
10125: sub modify_autoupdate {
1.3 raeburn 10126: my ($dom,%domconfig) = @_;
1.1 raeburn 10127: my ($resulttext,%currautoupdate,%fields,%changes);
10128: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
10129: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
10130: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
10131: }
10132: }
10133: my @offon = ('off','on');
10134: my %title = &Apache::lonlocal::texthash (
10135: run => 'Auto-update:',
10136: classlists => 'Updates to user information in classlists?'
10137: );
1.44 raeburn 10138: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 10139: my %fieldtitles = &Apache::lonlocal::texthash (
10140: id => 'Student/Employee ID',
1.20 raeburn 10141: permanentemail => 'E-mail address',
1.1 raeburn 10142: lastname => 'Last Name',
10143: firstname => 'First Name',
10144: middlename => 'Middle Name',
1.132 raeburn 10145: generation => 'Generation',
1.1 raeburn 10146: );
1.142 raeburn 10147: $othertitle = &mt('All users');
1.1 raeburn 10148: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 10149: $othertitle = &mt('Other users');
1.1 raeburn 10150: }
10151: foreach my $key (keys(%env)) {
10152: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 10153: my ($usertype,$item) = ($1,$2);
10154: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
10155: if ($usertype eq 'default') {
10156: push(@{$fields{$1}},$2);
10157: } elsif (ref($types) eq 'ARRAY') {
10158: if (grep(/^\Q$usertype\E$/,@{$types})) {
10159: push(@{$fields{$1}},$2);
10160: }
10161: }
10162: }
1.1 raeburn 10163: }
10164: }
1.131 raeburn 10165: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
10166: @lockablenames = sort(@lockablenames);
10167: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
10168: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10169: if (@changed) {
10170: $changes{'lockablenames'} = 1;
10171: }
10172: } else {
10173: if (@lockablenames) {
10174: $changes{'lockablenames'} = 1;
10175: }
10176: }
1.1 raeburn 10177: my %updatehash = (
10178: autoupdate => { run => $env{'form.autoupdate_run'},
10179: classlists => $env{'form.classlists'},
10180: fields => {%fields},
1.131 raeburn 10181: lockablenames => \@lockablenames,
1.1 raeburn 10182: }
10183: );
10184: foreach my $key (keys(%currautoupdate)) {
10185: if (($key eq 'run') || ($key eq 'classlists')) {
10186: if (exists($updatehash{autoupdate}{$key})) {
10187: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
10188: $changes{$key} = 1;
10189: }
10190: }
10191: } elsif ($key eq 'fields') {
10192: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 10193: foreach my $item (@{$types},'default') {
1.1 raeburn 10194: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
10195: my $change = 0;
10196: foreach my $type (@{$currautoupdate{$key}{$item}}) {
10197: if (!exists($fields{$item})) {
10198: $change = 1;
1.132 raeburn 10199: last;
1.1 raeburn 10200: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 10201: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 10202: $change = 1;
1.132 raeburn 10203: last;
1.1 raeburn 10204: }
10205: }
10206: }
10207: if ($change) {
10208: push(@{$changes{$key}},$item);
10209: }
1.26 raeburn 10210: }
1.1 raeburn 10211: }
10212: }
1.131 raeburn 10213: } elsif ($key eq 'lockablenames') {
10214: if (ref($currautoupdate{$key}) eq 'ARRAY') {
10215: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
10216: if (@changed) {
10217: $changes{'lockablenames'} = 1;
10218: }
10219: } else {
10220: if (@lockablenames) {
10221: $changes{'lockablenames'} = 1;
10222: }
10223: }
10224: }
10225: }
10226: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
10227: if (@lockablenames) {
10228: $changes{'lockablenames'} = 1;
1.1 raeburn 10229: }
10230: }
1.26 raeburn 10231: foreach my $item (@{$types},'default') {
10232: if (defined($fields{$item})) {
10233: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 10234: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
10235: my $change = 0;
10236: if (ref($fields{$item}) eq 'ARRAY') {
10237: foreach my $type (@{$fields{$item}}) {
10238: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
10239: $change = 1;
10240: last;
10241: }
10242: }
10243: }
10244: if ($change) {
10245: push(@{$changes{'fields'}},$item);
10246: }
10247: } else {
1.26 raeburn 10248: push(@{$changes{'fields'}},$item);
10249: }
10250: } else {
10251: push(@{$changes{'fields'}},$item);
1.1 raeburn 10252: }
10253: }
10254: }
10255: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
10256: $dom);
10257: if ($putresult eq 'ok') {
10258: if (keys(%changes) > 0) {
10259: $resulttext = &mt('Changes made:').'<ul>';
10260: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 10261: if ($key eq 'lockablenames') {
10262: $resulttext .= '<li>';
10263: if (@lockablenames) {
10264: $usertypes->{'default'} = $othertitle;
10265: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
10266: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
10267: } else {
10268: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
10269: }
10270: $resulttext .= '</li>';
10271: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 10272: foreach my $item (@{$changes{$key}}) {
10273: my @newvalues;
10274: foreach my $type (@{$fields{$item}}) {
10275: push(@newvalues,$fieldtitles{$type});
10276: }
1.3 raeburn 10277: my $newvaluestr;
10278: if (@newvalues > 0) {
10279: $newvaluestr = join(', ',@newvalues);
10280: } else {
10281: $newvaluestr = &mt('none');
1.6 raeburn 10282: }
1.1 raeburn 10283: if ($item eq 'default') {
1.26 raeburn 10284: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 10285: } else {
1.26 raeburn 10286: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 10287: }
10288: }
10289: } else {
10290: my $newvalue;
10291: if ($key eq 'run') {
10292: $newvalue = $offon[$env{'form.autoupdate_run'}];
10293: } else {
10294: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 10295: }
1.1 raeburn 10296: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
10297: }
10298: }
10299: $resulttext .= '</ul>';
10300: } else {
1.3 raeburn 10301: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 10302: }
10303: } else {
1.11 albertel 10304: $resulttext = '<span class="LC_error">'.
10305: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10306: }
1.3 raeburn 10307: return $resulttext;
1.1 raeburn 10308: }
10309:
1.125 raeburn 10310: sub modify_autocreate {
10311: my ($dom,%domconfig) = @_;
10312: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
10313: if (ref($domconfig{'autocreate'}) eq 'HASH') {
10314: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
10315: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
10316: }
10317: }
10318: my %title= ( xml => 'Auto-creation of courses in XML course description files',
10319: req => 'Auto-creation of validated requests for official courses',
10320: xmldc => 'Identity of course creator of courses from XML files',
10321: );
10322: my @types = ('xml','req');
10323: foreach my $item (@types) {
10324: $newvals{$item} = $env{'form.autocreate_'.$item};
10325: $newvals{$item} =~ s/\D//g;
10326: $newvals{$item} = 0 if ($newvals{$item} eq '');
10327: }
10328: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 10329: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 10330: unless (exists($domcoords{$newvals{'xmldc'}})) {
10331: $newvals{'xmldc'} = '';
10332: }
10333: %autocreatehash = (
10334: autocreate => { xml => $newvals{'xml'},
10335: req => $newvals{'req'},
10336: }
10337: );
10338: if ($newvals{'xmldc'} ne '') {
10339: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
10340: }
10341: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
10342: $dom);
10343: if ($putresult eq 'ok') {
10344: my @items = @types;
10345: if ($newvals{'xml'}) {
10346: push(@items,'xmldc');
10347: }
10348: foreach my $item (@items) {
10349: if (exists($currautocreate{$item})) {
10350: if ($currautocreate{$item} ne $newvals{$item}) {
10351: $changes{$item} = 1;
10352: }
10353: } elsif ($newvals{$item}) {
10354: $changes{$item} = 1;
10355: }
10356: }
10357: if (keys(%changes) > 0) {
10358: my @offon = ('off','on');
10359: $resulttext = &mt('Changes made:').'<ul>';
10360: foreach my $item (@types) {
10361: if ($changes{$item}) {
10362: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 10363: $resulttext .= '<li>'.
10364: &mt("$title{$item} set to [_1]$newtxt [_2]",
10365: '<b>','</b>').
10366: '</li>';
1.125 raeburn 10367: }
10368: }
10369: if ($changes{'xmldc'}) {
10370: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
10371: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 10372: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 10373: }
10374: $resulttext .= '</ul>';
10375: } else {
10376: $resulttext = &mt('No changes made to auto-creation settings');
10377: }
10378: } else {
10379: $resulttext = '<span class="LC_error">'.
10380: &mt('An error occurred: [_1]',$putresult).'</span>';
10381: }
10382: return $resulttext;
10383: }
10384:
1.23 raeburn 10385: sub modify_directorysrch {
1.295 raeburn 10386: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 10387: my ($resulttext,%changes);
10388: my %currdirsrch;
10389: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
10390: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
10391: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
10392: }
10393: }
1.277 raeburn 10394: my %title = ( available => 'Institutional directory search available',
10395: localonly => 'Other domains can search institution',
10396: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 10397: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 10398: searchby => 'Search types',
10399: searchtypes => 'Search latitude');
10400: my @offon = ('off','on');
1.24 raeburn 10401: my @otherdoms = ('Yes','No');
1.23 raeburn 10402:
1.25 raeburn 10403: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 10404: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
10405: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
10406:
1.44 raeburn 10407: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 10408: if (keys(%{$usertypes}) == 0) {
10409: @cansearch = ('default');
10410: } else {
10411: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
10412: foreach my $type (@{$currdirsrch{'cansearch'}}) {
10413: if (!grep(/^\Q$type\E$/,@cansearch)) {
10414: push(@{$changes{'cansearch'}},$type);
10415: }
1.23 raeburn 10416: }
1.26 raeburn 10417: foreach my $type (@cansearch) {
10418: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
10419: push(@{$changes{'cansearch'}},$type);
10420: }
1.23 raeburn 10421: }
1.26 raeburn 10422: } else {
10423: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 10424: }
10425: }
10426:
10427: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
10428: foreach my $by (@{$currdirsrch{'searchby'}}) {
10429: if (!grep(/^\Q$by\E$/,@searchby)) {
10430: push(@{$changes{'searchby'}},$by);
10431: }
10432: }
10433: foreach my $by (@searchby) {
10434: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
10435: push(@{$changes{'searchby'}},$by);
10436: }
10437: }
10438: } else {
10439: push(@{$changes{'searchby'}},@searchby);
10440: }
1.25 raeburn 10441:
10442: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
10443: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
10444: if (!grep(/^\Q$type\E$/,@searchtypes)) {
10445: push(@{$changes{'searchtypes'}},$type);
10446: }
10447: }
10448: foreach my $type (@searchtypes) {
10449: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
10450: push(@{$changes{'searchtypes'}},$type);
10451: }
10452: }
10453: } else {
10454: if (exists($currdirsrch{'searchtypes'})) {
10455: foreach my $type (@searchtypes) {
10456: if ($type ne $currdirsrch{'searchtypes'}) {
10457: push(@{$changes{'searchtypes'}},$type);
10458: }
10459: }
10460: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
10461: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
10462: }
10463: } else {
10464: push(@{$changes{'searchtypes'}},@searchtypes);
10465: }
10466: }
10467:
1.23 raeburn 10468: my %dirsrch_hash = (
10469: directorysrch => { available => $env{'form.dirsrch_available'},
10470: cansearch => \@cansearch,
1.277 raeburn 10471: localonly => $env{'form.dirsrch_instlocalonly'},
10472: lclocalonly => $env{'form.dirsrch_domlocalonly'},
10473: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 10474: searchby => \@searchby,
1.25 raeburn 10475: searchtypes => \@searchtypes,
1.23 raeburn 10476: }
10477: );
10478: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
10479: $dom);
10480: if ($putresult eq 'ok') {
10481: if (exists($currdirsrch{'available'})) {
10482: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
10483: $changes{'available'} = 1;
10484: }
10485: } else {
10486: if ($env{'form.dirsrch_available'} eq '1') {
10487: $changes{'available'} = 1;
10488: }
10489: }
1.277 raeburn 10490: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 10491: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
10492: $changes{'lcavailable'} = 1;
10493: }
1.277 raeburn 10494: } else {
10495: if ($env{'form.dirsrch_lcavailable'} eq '1') {
10496: $changes{'lcavailable'} = 1;
10497: }
10498: }
1.24 raeburn 10499: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 10500: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
10501: $changes{'localonly'} = 1;
10502: }
1.24 raeburn 10503: } else {
1.277 raeburn 10504: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 10505: $changes{'localonly'} = 1;
10506: }
10507: }
1.277 raeburn 10508: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 10509: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
10510: $changes{'lclocalonly'} = 1;
10511: }
1.277 raeburn 10512: } else {
10513: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
10514: $changes{'lclocalonly'} = 1;
10515: }
10516: }
1.23 raeburn 10517: if (keys(%changes) > 0) {
10518: $resulttext = &mt('Changes made:').'<ul>';
10519: if ($changes{'available'}) {
10520: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
10521: }
1.277 raeburn 10522: if ($changes{'lcavailable'}) {
10523: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
10524: }
1.24 raeburn 10525: if ($changes{'localonly'}) {
1.277 raeburn 10526: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 10527: }
1.277 raeburn 10528: if ($changes{'lclocalonly'}) {
10529: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 10530: }
1.23 raeburn 10531: if (ref($changes{'cansearch'}) eq 'ARRAY') {
10532: my $chgtext;
1.26 raeburn 10533: if (ref($usertypes) eq 'HASH') {
10534: if (keys(%{$usertypes}) > 0) {
10535: foreach my $type (@{$types}) {
10536: if (grep(/^\Q$type\E$/,@cansearch)) {
10537: $chgtext .= $usertypes->{$type}.'; ';
10538: }
10539: }
10540: if (grep(/^default$/,@cansearch)) {
10541: $chgtext .= $othertitle;
10542: } else {
10543: $chgtext =~ s/\; $//;
10544: }
1.210 raeburn 10545: $resulttext .=
1.178 raeburn 10546: '<li>'.
10547: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
10548: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
10549: '</li>';
1.23 raeburn 10550: }
10551: }
10552: }
10553: if (ref($changes{'searchby'}) eq 'ARRAY') {
10554: my ($searchtitles,$titleorder) = &sorted_searchtitles();
10555: my $chgtext;
10556: foreach my $type (@{$titleorder}) {
10557: if (grep(/^\Q$type\E$/,@searchby)) {
10558: if (defined($searchtitles->{$type})) {
10559: $chgtext .= $searchtitles->{$type}.'; ';
10560: }
10561: }
10562: }
10563: $chgtext =~ s/\; $//;
10564: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
10565: }
1.25 raeburn 10566: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
10567: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
10568: my $chgtext;
10569: foreach my $type (@{$srchtypeorder}) {
10570: if (grep(/^\Q$type\E$/,@searchtypes)) {
10571: if (defined($srchtypes_desc->{$type})) {
10572: $chgtext .= $srchtypes_desc->{$type}.'; ';
10573: }
10574: }
10575: }
10576: $chgtext =~ s/\; $//;
1.178 raeburn 10577: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 10578: }
10579: $resulttext .= '</ul>';
1.295 raeburn 10580: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
10581: if (ref($lastactref) eq 'HASH') {
10582: $lastactref->{'directorysrch'} = 1;
10583: }
1.23 raeburn 10584: } else {
1.277 raeburn 10585: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 10586: }
10587: } else {
10588: $resulttext = '<span class="LC_error">'.
1.27 raeburn 10589: &mt('An error occurred: [_1]',$putresult).'</span>';
10590: }
10591: return $resulttext;
10592: }
10593:
1.28 raeburn 10594: sub modify_contacts {
1.205 raeburn 10595: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 10596: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
10597: if (ref($domconfig{'contacts'}) eq 'HASH') {
10598: foreach my $key (keys(%{$domconfig{'contacts'}})) {
10599: $currsetting{$key} = $domconfig{'contacts'}{$key};
10600: }
10601: }
1.286 raeburn 10602: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 10603: my @contacts = ('supportemail','adminemail');
1.286 raeburn 10604: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
10605: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.203 raeburn 10606: my @toggles = ('reporterrors','reportupdates');
1.286 raeburn 10607: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 10608: foreach my $type (@mailings) {
10609: @{$newsetting{$type}} =
10610: &Apache::loncommon::get_env_multiple('form.'.$type);
10611: foreach my $item (@contacts) {
10612: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
10613: $contacts_hash{contacts}{$type}{$item} = 1;
10614: } else {
10615: $contacts_hash{contacts}{$type}{$item} = 0;
10616: }
1.289 raeburn 10617: }
1.28 raeburn 10618: $others{$type} = $env{'form.'.$type.'_others'};
10619: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 10620: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10621: $bcc{$type} = $env{'form.'.$type.'_bcc'};
10622: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 10623: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
10624: $includestr{$type} = $env{'form.'.$type.'_includestr'};
10625: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
10626: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
10627: }
1.134 raeburn 10628: }
1.28 raeburn 10629: }
10630: foreach my $item (@contacts) {
10631: $to{$item} = $env{'form.'.$item};
10632: $contacts_hash{'contacts'}{$item} = $to{$item};
10633: }
1.203 raeburn 10634: foreach my $item (@toggles) {
10635: if ($env{'form.'.$item} =~ /^(0|1)$/) {
10636: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
10637: }
10638: }
1.286 raeburn 10639: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
10640: foreach my $field (@{$fields}) {
10641: if (ref($possoptions->{$field}) eq 'ARRAY') {
10642: my $value = $env{'form.helpform_'.$field};
10643: $value =~ s/^\s+|\s+$//g;
10644: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
10645: $contacts_hash{contacts}{'helpform'}{$field} = $value;
10646: if ($field eq 'screenshot') {
10647: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
10648: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
10649: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
10650: }
10651: }
10652: }
10653: }
10654: }
10655: }
1.28 raeburn 10656: if (keys(%currsetting) > 0) {
10657: foreach my $item (@contacts) {
10658: if ($to{$item} ne $currsetting{$item}) {
10659: $changes{$item} = 1;
10660: }
10661: }
10662: foreach my $type (@mailings) {
10663: foreach my $item (@contacts) {
10664: if (ref($currsetting{$type}) eq 'HASH') {
10665: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
10666: push(@{$changes{$type}},$item);
10667: }
10668: } else {
10669: push(@{$changes{$type}},@{$newsetting{$type}});
10670: }
10671: }
10672: if ($others{$type} ne $currsetting{$type}{'others'}) {
10673: push(@{$changes{$type}},'others');
10674: }
1.289 raeburn 10675: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10676: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
10677: push(@{$changes{$type}},'bcc');
10678: }
1.286 raeburn 10679: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
10680: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
10681: push(@{$changes{$type}},'include');
10682: }
10683: }
10684: }
10685: if (ref($fields) eq 'ARRAY') {
10686: if (ref($currsetting{'helpform'}) eq 'HASH') {
10687: foreach my $field (@{$fields}) {
10688: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
10689: push(@{$changes{'helpform'}},$field);
10690: }
10691: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10692: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
10693: push(@{$changes{'helpform'}},'maxsize');
10694: }
10695: }
10696: }
10697: } else {
10698: foreach my $field (@{$fields}) {
10699: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10700: push(@{$changes{'helpform'}},$field);
10701: }
10702: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10703: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10704: push(@{$changes{'helpform'}},'maxsize');
10705: }
10706: }
10707: }
1.134 raeburn 10708: }
1.28 raeburn 10709: }
10710: } else {
10711: my %default;
10712: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
10713: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
10714: $default{'errormail'} = 'adminemail';
10715: $default{'packagesmail'} = 'adminemail';
10716: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 10717: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 10718: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 10719: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 10720: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 10721: foreach my $item (@contacts) {
10722: if ($to{$item} ne $default{$item}) {
1.286 raeburn 10723: $changes{$item} = 1;
1.203 raeburn 10724: }
1.28 raeburn 10725: }
10726: foreach my $type (@mailings) {
10727: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
10728: push(@{$changes{$type}},@{$newsetting{$type}});
10729: }
10730: if ($others{$type} ne '') {
10731: push(@{$changes{$type}},'others');
1.134 raeburn 10732: }
1.286 raeburn 10733: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10734: if ($bcc{$type} ne '') {
10735: push(@{$changes{$type}},'bcc');
10736: }
1.286 raeburn 10737: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
10738: push(@{$changes{$type}},'include');
10739: }
1.134 raeburn 10740: }
1.28 raeburn 10741: }
1.286 raeburn 10742: if (ref($fields) eq 'ARRAY') {
10743: foreach my $field (@{$fields}) {
10744: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
10745: push(@{$changes{'helpform'}},$field);
10746: }
10747: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
10748: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
10749: push(@{$changes{'helpform'}},'maxsize');
10750: }
10751: }
10752: }
1.289 raeburn 10753: }
1.28 raeburn 10754: }
1.203 raeburn 10755: foreach my $item (@toggles) {
10756: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10757: $changes{$item} = 1;
10758: } elsif ((!$env{'form.'.$item}) &&
10759: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10760: $changes{$item} = 1;
10761: }
10762: }
1.28 raeburn 10763: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10764: $dom);
10765: if ($putresult eq 'ok') {
10766: if (keys(%changes) > 0) {
1.205 raeburn 10767: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 10768: if (ref($lastactref) eq 'HASH') {
10769: $lastactref->{'domainconfig'} = 1;
10770: }
1.28 raeburn 10771: my ($titles,$short_titles) = &contact_titles();
10772: $resulttext = &mt('Changes made:').'<ul>';
10773: foreach my $item (@contacts) {
10774: if ($changes{$item}) {
10775: $resulttext .= '<li>'.$titles->{$item}.
10776: &mt(' set to: ').
10777: '<span class="LC_cusr_emph">'.
10778: $to{$item}.'</span></li>';
10779: }
10780: }
10781: foreach my $type (@mailings) {
10782: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 10783: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 10784: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 10785: } else {
10786: $resulttext .= '<li>'.$titles->{$type}.': ';
10787: }
1.28 raeburn 10788: my @text;
10789: foreach my $item (@{$newsetting{$type}}) {
10790: push(@text,$short_titles->{$item});
10791: }
10792: if ($others{$type} ne '') {
10793: push(@text,$others{$type});
10794: }
1.286 raeburn 10795: if (@text) {
10796: $resulttext .= '<span class="LC_cusr_emph">'.
10797: join(', ',@text).'</span>';
10798: }
10799: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10800: if ($bcc{$type} ne '') {
1.286 raeburn 10801: my $bcctext;
10802: if (@text) {
1.289 raeburn 10803: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 10804: } else {
10805: $bcctext = '(Bcc)';
10806: }
10807: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10808: } elsif (!@text) {
10809: $resulttext .= &mt('No one');
10810: }
1.289 raeburn 10811: if ($includestr{$type} ne '') {
1.286 raeburn 10812: if ($includeloc{$type} eq 'b') {
10813: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10814: } elsif ($includeloc{$type} eq 's') {
10815: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10816: }
1.134 raeburn 10817: }
1.286 raeburn 10818: } elsif (!@text) {
10819: $resulttext .= &mt('No recipients');
1.134 raeburn 10820: }
10821: $resulttext .= '</li>';
1.28 raeburn 10822: }
10823: }
1.203 raeburn 10824: my @offon = ('off','on');
10825: if ($changes{'reporterrors'}) {
10826: $resulttext .= '<li>'.
10827: &mt('E-mail error reports to [_1] set to "'.
10828: $offon[$env{'form.reporterrors'}].'".',
10829: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10830: &mt('LON-CAPA core group - MSU'),600,500)).
10831: '</li>';
10832: }
10833: if ($changes{'reportupdates'}) {
10834: $resulttext .= '<li>'.
10835: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10836: $offon[$env{'form.reportupdates'}].'".',
10837: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10838: &mt('LON-CAPA core group - MSU'),600,500)).
10839: '</li>';
10840: }
1.286 raeburn 10841: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10842: my (@optional,@required,@unused,$maxsizechg);
10843: foreach my $field (@{$changes{'helpform'}}) {
10844: if ($field eq 'maxsize') {
10845: $maxsizechg = 1;
10846: next;
10847: }
10848: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 10849: push(@optional,$field);
1.286 raeburn 10850: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10851: push(@unused,$field);
10852: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 10853: push(@required,$field);
1.286 raeburn 10854: }
10855: }
10856: if (@optional) {
10857: $resulttext .= '<li>'.
10858: &mt('Help form fields changed to "Optional": [_1].',
10859: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10860: '</li>';
10861: }
10862: if (@required) {
10863: $resulttext .= '<li>'.
10864: &mt('Help form fields changed to "Required": [_1].',
10865: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10866: '</li>';
10867: }
10868: if (@unused) {
10869: $resulttext .= '<li>'.
10870: &mt('Help form fields changed to "Not shown": [_1].',
10871: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10872: '</li>';
10873: }
10874: if ($maxsizechg) {
10875: $resulttext .= '<li>'.
10876: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10877: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10878: '</li>';
10879:
10880: }
10881: }
1.28 raeburn 10882: $resulttext .= '</ul>';
10883: } else {
1.288 raeburn 10884: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10885: }
10886: } else {
10887: $resulttext = '<span class="LC_error">'.
10888: &mt('An error occurred: [_1].',$putresult).'</span>';
10889: }
10890: return $resulttext;
10891: }
10892:
10893: sub modify_usercreation {
1.27 raeburn 10894: my ($dom,%domconfig) = @_;
1.224 raeburn 10895: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 10896: my $warningmsg;
1.27 raeburn 10897: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10898: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 10899: if ($key eq 'cancreate') {
10900: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10901: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10902: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269 raeburn 10903: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10904: ($item eq 'recaptchaversion')) {
1.224 raeburn 10905: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10906: } else {
10907: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10908: }
10909: }
10910: }
10911: } elsif ($key eq 'email_rule') {
10912: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10913: } else {
10914: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10915: }
1.27 raeburn 10916: }
10917: }
10918: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 10919: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 10920: my @contexts = ('author','course','requestcrs');
1.34 raeburn 10921: foreach my $item(@contexts) {
1.224 raeburn 10922: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 10923: }
1.34 raeburn 10924: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10925: foreach my $item (@contexts) {
1.224 raeburn 10926: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10927: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 10928: }
1.27 raeburn 10929: }
1.34 raeburn 10930: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10931: foreach my $item (@contexts) {
1.43 raeburn 10932: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10933: if ($cancreate{$item} ne 'any') {
10934: push(@{$changes{'cancreate'}},$item);
10935: }
10936: } else {
10937: if ($cancreate{$item} ne 'none') {
10938: push(@{$changes{'cancreate'}},$item);
10939: }
1.27 raeburn 10940: }
10941: }
10942: } else {
1.43 raeburn 10943: foreach my $item (@contexts) {
1.34 raeburn 10944: push(@{$changes{'cancreate'}},$item);
10945: }
1.27 raeburn 10946: }
1.34 raeburn 10947:
1.27 raeburn 10948: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10949: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10950: if (!grep(/^\Q$type\E$/,@username_rule)) {
10951: push(@{$changes{'username_rule'}},$type);
10952: }
10953: }
10954: foreach my $type (@username_rule) {
10955: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10956: push(@{$changes{'username_rule'}},$type);
10957: }
10958: }
10959: } else {
10960: push(@{$changes{'username_rule'}},@username_rule);
10961: }
10962:
1.32 raeburn 10963: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10964: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10965: if (!grep(/^\Q$type\E$/,@id_rule)) {
10966: push(@{$changes{'id_rule'}},$type);
10967: }
10968: }
10969: foreach my $type (@id_rule) {
10970: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10971: push(@{$changes{'id_rule'}},$type);
10972: }
10973: }
10974: } else {
10975: push(@{$changes{'id_rule'}},@id_rule);
10976: }
10977:
1.43 raeburn 10978: my @authen_contexts = ('author','course','domain');
1.28 raeburn 10979: my @authtypes = ('int','krb4','krb5','loc');
10980: my %authhash;
1.43 raeburn 10981: foreach my $item (@authen_contexts) {
1.28 raeburn 10982: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
10983: foreach my $auth (@authtypes) {
10984: if (grep(/^\Q$auth\E$/,@authallowed)) {
10985: $authhash{$item}{$auth} = 1;
10986: } else {
10987: $authhash{$item}{$auth} = 0;
10988: }
10989: }
10990: }
10991: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 10992: foreach my $item (@authen_contexts) {
1.28 raeburn 10993: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10994: foreach my $auth (@authtypes) {
10995: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10996: push(@{$changes{'authtypes'}},$item);
10997: last;
10998: }
10999: }
11000: }
11001: }
11002: } else {
1.43 raeburn 11003: foreach my $item (@authen_contexts) {
1.28 raeburn 11004: push(@{$changes{'authtypes'}},$item);
11005: }
11006: }
11007:
1.224 raeburn 11008: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
11009: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
11010: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
11011: $save_usercreate{'id_rule'} = \@id_rule;
11012: $save_usercreate{'username_rule'} = \@username_rule,
11013: $save_usercreate{'authtypes'} = \%authhash;
11014:
1.27 raeburn 11015: my %usercreation_hash = (
1.224 raeburn 11016: usercreation => \%save_usercreate,
11017: );
1.27 raeburn 11018:
11019: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
11020: $dom);
1.50 raeburn 11021:
1.224 raeburn 11022: if ($putresult eq 'ok') {
11023: if (keys(%changes) > 0) {
11024: $resulttext = &mt('Changes made:').'<ul>';
11025: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11026: my %lt = &usercreation_types();
11027: foreach my $type (@{$changes{'cancreate'}}) {
11028: my $chgtext = $lt{$type}.', ';
11029: if ($cancreate{$type} eq 'none') {
11030: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
11031: } elsif ($cancreate{$type} eq 'any') {
11032: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
11033: } elsif ($cancreate{$type} eq 'official') {
11034: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
11035: } elsif ($cancreate{$type} eq 'unofficial') {
11036: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
11037: }
11038: $resulttext .= '<li>'.$chgtext.'</li>';
11039: }
11040: }
11041: if (ref($changes{'username_rule'}) eq 'ARRAY') {
11042: my ($rules,$ruleorder) =
11043: &Apache::lonnet::inst_userrules($dom,'username');
11044: my $chgtext = '<ul>';
11045: foreach my $type (@username_rule) {
11046: if (ref($rules->{$type}) eq 'HASH') {
11047: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
11048: }
11049: }
11050: $chgtext .= '</ul>';
11051: if (@username_rule > 0) {
11052: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11053: } else {
11054: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
11055: }
11056: }
11057: if (ref($changes{'id_rule'}) eq 'ARRAY') {
11058: my ($idrules,$idruleorder) =
11059: &Apache::lonnet::inst_userrules($dom,'id');
11060: my $chgtext = '<ul>';
11061: foreach my $type (@id_rule) {
11062: if (ref($idrules->{$type}) eq 'HASH') {
11063: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
11064: }
11065: }
11066: $chgtext .= '</ul>';
11067: if (@id_rule > 0) {
11068: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
11069: } else {
11070: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
11071: }
11072: }
11073: my %authname = &authtype_names();
11074: my %context_title = &context_names();
11075: if (ref($changes{'authtypes'}) eq 'ARRAY') {
11076: my $chgtext = '<ul>';
11077: foreach my $type (@{$changes{'authtypes'}}) {
11078: my @allowed;
11079: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
11080: foreach my $auth (@authtypes) {
11081: if ($authhash{$type}{$auth}) {
11082: push(@allowed,$authname{$auth});
11083: }
11084: }
11085: if (@allowed > 0) {
11086: $chgtext .= join(', ',@allowed).'</li>';
11087: } else {
11088: $chgtext .= &mt('none').'</li>';
11089: }
11090: }
11091: $chgtext .= '</ul>';
11092: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
11093: $resulttext .= '</li>';
11094: }
11095: $resulttext .= '</ul>';
11096: } else {
11097: $resulttext = &mt('No changes made to user creation settings');
11098: }
11099: } else {
11100: $resulttext = '<span class="LC_error">'.
11101: &mt('An error occurred: [_1]',$putresult).'</span>';
11102: }
11103: if ($warningmsg ne '') {
11104: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11105: }
11106: return $resulttext;
11107: }
11108:
11109: sub modify_selfcreation {
11110: my ($dom,%domconfig) = @_;
11111: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
11112: my (%save_usercreate,%save_usermodify);
1.228 raeburn 11113: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11114: if (ref($types) eq 'ARRAY') {
11115: $usertypes->{'default'} = $othertitle;
11116: push(@{$types},'default');
11117: }
1.224 raeburn 11118: #
11119: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
11120: #
11121: if (ref($domconfig{'usercreation'}) eq 'HASH') {
11122: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
11123: if ($key eq 'cancreate') {
11124: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
11125: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
11126: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
11127: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.269 raeburn 11128: ($item eq 'recaptchaversion') ||
1.236 raeburn 11129: ($item eq 'emailusername') || ($item eq 'notify') ||
1.240 raeburn 11130: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224 raeburn 11131: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11132: } else {
11133: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
11134: }
11135: }
11136: }
11137: } elsif ($key eq 'email_rule') {
11138: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
11139: } else {
11140: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
11141: }
11142: }
11143: }
11144: #
11145: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
11146: #
11147: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11148: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
11149: if ($key eq 'selfcreate') {
11150: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
11151: } else {
11152: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
11153: }
11154: }
11155: }
11156:
11157: my @contexts = ('selfcreate');
11158: @{$cancreate{'selfcreate'}} = ();
11159: %{$cancreate{'emailusername'}} = ();
11160: @{$cancreate{'statustocreate'}} = ();
1.236 raeburn 11161: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 11162: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 11163: my %selfcreatetypes = (
11164: sso => 'users authenticated by institutional single sign on',
11165: login => 'users authenticated by institutional log-in',
1.236 raeburn 11166: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 11167: );
1.224 raeburn 11168: #
11169: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
11170: # is permitted.
11171: #
1.236 raeburn 11172:
11173: my @statuses;
11174: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11175: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
11176: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
11177: }
11178: }
11179: push(@statuses,'default');
11180:
1.228 raeburn 11181: foreach my $item ('login','sso','email') {
1.224 raeburn 11182: if ($item eq 'email') {
1.236 raeburn 11183: if ($env{'form.cancreate_email'}) {
1.224 raeburn 11184: push(@{$cancreate{'selfcreate'}},'email');
1.236 raeburn 11185: push(@contexts,'selfcreateprocessing');
11186: foreach my $type (@statuses) {
11187: if ($type eq 'default') {
11188: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
11189: } else {
11190: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
11191: }
11192: }
1.224 raeburn 11193: }
11194: } else {
11195: if ($env{'form.cancreate_'.$item}) {
11196: push(@{$cancreate{'selfcreate'}},$item);
11197: }
11198: }
11199: }
11200: my (@email_rule,%userinfo,%savecaptcha);
11201: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
11202: #
1.228 raeburn 11203: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
11204: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 11205: #
1.236 raeburn 11206:
1.244 raeburn 11207: if ($env{'form.cancreate_email'}) {
1.228 raeburn 11208: push(@contexts,'emailusername');
11209: if (ref($types) eq 'ARRAY') {
11210: foreach my $type (@{$types}) {
11211: if (ref($infofields) eq 'ARRAY') {
11212: foreach my $field (@{$infofields}) {
11213: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
11214: $cancreate{'emailusername'}{$type}{$field} = $1;
11215: }
11216: }
1.224 raeburn 11217: }
11218: }
11219: }
11220: #
11221: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
11222: # queued requests for self-creation of account using e-mail address as username
11223: #
11224:
11225: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
11226: @approvalnotify = sort(@approvalnotify);
11227: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
11228: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11229: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
11230: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
11231: push(@{$changes{'cancreate'}},'notify');
11232: }
11233: } else {
11234: if ($cancreate{'notify'}{'approval'}) {
11235: push(@{$changes{'cancreate'}},'notify');
11236: }
11237: }
11238: } elsif ($cancreate{'notify'}{'approval'}) {
11239: push(@{$changes{'cancreate'}},'notify');
11240: }
11241:
11242: #
11243: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
11244: #
11245: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
11246: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
11247: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
11248: if (@{$curr_usercreation{'email_rule'}} > 0) {
11249: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
11250: if (!grep(/^\Q$type\E$/,@email_rule)) {
11251: push(@{$changes{'email_rule'}},$type);
11252: }
11253: }
11254: }
11255: if (@email_rule > 0) {
11256: foreach my $type (@email_rule) {
11257: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
11258: push(@{$changes{'email_rule'}},$type);
11259: }
11260: }
11261: }
11262: } elsif (@email_rule > 0) {
11263: push(@{$changes{'email_rule'}},@email_rule);
11264: }
11265: }
11266: #
1.236 raeburn 11267: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 11268: # institutional log-in.
11269: #
11270: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
11271: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
11272: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
11273: ($domdefaults{'auth_def'} eq 'localauth'))) {
11274: $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.').' '.
11275: &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.');
11276: }
11277: }
11278: my @fields = ('lastname','firstname','middlename','generation',
11279: 'permanentemail','id');
1.240 raeburn 11280: my @shibfields = (@fields,'inststatus');
1.224 raeburn 11281: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11282: #
11283: # Where usernames may created for institutional log-in and/or institutional single sign on:
11284: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
11285: # may self-create accounts
11286: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
11287: # which the user may supply, if institutional data is unavailable.
11288: #
11289: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
11290: if (ref($types) eq 'ARRAY') {
1.228 raeburn 11291: if (@{$types} > 1) {
1.224 raeburn 11292: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
11293: push(@contexts,'statustocreate');
11294: } else {
11295: undef($cancreate{'statustocreate'});
11296: }
11297: foreach my $type (@{$types}) {
11298: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
11299: foreach my $field (@fields) {
11300: if (grep(/^\Q$field\E$/,@modifiable)) {
11301: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
11302: } else {
11303: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
11304: }
11305: }
11306: }
11307: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
11308: foreach my $type (@{$types}) {
11309: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
11310: foreach my $field (@fields) {
11311: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
11312: $curr_usermodify{'selfcreate'}{$type}{$field}) {
11313: push(@{$changes{'selfcreate'}},$type);
11314: last;
11315: }
11316: }
11317: }
11318: }
11319: } else {
11320: foreach my $type (@{$types}) {
11321: push(@{$changes{'selfcreate'}},$type);
11322: }
11323: }
11324: }
1.240 raeburn 11325: foreach my $field (@shibfields) {
11326: if ($env{'form.shibenv_'.$field} ne '') {
11327: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
11328: }
11329: }
11330: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
11331: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
11332: foreach my $field (@shibfields) {
11333: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
11334: push(@{$changes{'cancreate'}},'shibenv');
11335: }
11336: }
11337: } else {
11338: foreach my $field (@shibfields) {
11339: if ($env{'form.shibenv_'.$field}) {
11340: push(@{$changes{'cancreate'}},'shibenv');
11341: last;
11342: }
11343: }
11344: }
11345: }
1.224 raeburn 11346: }
11347: foreach my $item (@contexts) {
11348: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
11349: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
11350: if (ref($cancreate{$item}) eq 'ARRAY') {
11351: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
11352: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11353: push(@{$changes{'cancreate'}},$item);
11354: }
11355: }
11356: }
11357: }
11358: if (ref($cancreate{$item}) eq 'ARRAY') {
11359: foreach my $type (@{$cancreate{$item}}) {
11360: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
11361: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11362: push(@{$changes{'cancreate'}},$item);
11363: }
11364: }
11365: }
11366: }
11367: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
11368: if (ref($cancreate{$item}) eq 'HASH') {
11369: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228 raeburn 11370: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
11371: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
11372: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
11373: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11374: push(@{$changes{'cancreate'}},$item);
11375: }
11376: }
11377: }
1.236 raeburn 11378: } elsif ($item eq 'selfcreateprocessing') {
11379: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
11380: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11381: push(@{$changes{'cancreate'}},$item);
11382: }
11383: }
1.228 raeburn 11384: } else {
11385: if (!$cancreate{$item}{$curr}) {
11386: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11387: push(@{$changes{'cancreate'}},$item);
11388: }
1.224 raeburn 11389: }
11390: }
11391: }
11392: foreach my $field (keys(%{$cancreate{$item}})) {
1.228 raeburn 11393: if (ref($cancreate{$item}{$field}) eq 'HASH') {
11394: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
11395: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
11396: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
11397: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11398: push(@{$changes{'cancreate'}},$item);
11399: }
11400: }
11401: } else {
11402: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11403: push(@{$changes{'cancreate'}},$item);
11404: }
11405: }
11406: }
1.236 raeburn 11407: } elsif ($item eq 'selfcreateprocessing') {
11408: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
11409: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11410: push(@{$changes{'cancreate'}},$item);
11411: }
11412: }
1.228 raeburn 11413: } else {
11414: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
11415: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11416: push(@{$changes{'cancreate'}},$item);
11417: }
1.224 raeburn 11418: }
11419: }
11420: }
11421: }
11422: } elsif ($curr_usercreation{'cancreate'}{$item}) {
11423: if (ref($cancreate{$item}) eq 'ARRAY') {
11424: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
11425: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11426: push(@{$changes{'cancreate'}},$item);
11427: }
11428: }
11429: } elsif (ref($cancreate{$item}) eq 'HASH') {
11430: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
11431: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11432: push(@{$changes{'cancreate'}},$item);
11433: }
11434: }
11435: }
11436: } elsif ($item eq 'emailusername') {
1.228 raeburn 11437: if (ref($cancreate{$item}) eq 'HASH') {
11438: foreach my $type (keys(%{$cancreate{$item}})) {
11439: if (ref($cancreate{$item}{$type}) eq 'HASH') {
11440: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
11441: if ($cancreate{$item}{$type}{$field}) {
11442: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
11443: push(@{$changes{'cancreate'}},$item);
11444: }
11445: last;
11446: }
11447: }
11448: }
11449: }
1.224 raeburn 11450: }
11451: }
11452: }
11453: #
11454: # Populate %save_usercreate hash with updates to self-creation configuration.
11455: #
11456: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
11457: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 11458: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 11459: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
11460: if (ref($cancreate{'notify'}) eq 'HASH') {
11461: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
11462: }
1.236 raeburn 11463: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
11464: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
11465: }
1.224 raeburn 11466: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11467: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
11468: }
1.240 raeburn 11469: if (ref($cancreate{'shibenv'}) eq 'HASH') {
11470: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
11471: }
1.224 raeburn 11472: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
11473: $save_usercreate{'emailrule'} = \@email_rule;
11474:
11475: my %userconfig_hash = (
11476: usercreation => \%save_usercreate,
11477: usermodification => \%save_usermodify,
11478: );
11479: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
11480: $dom);
11481: #
11482: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
11483: #
1.27 raeburn 11484: if ($putresult eq 'ok') {
11485: if (keys(%changes) > 0) {
11486: $resulttext = &mt('Changes made:').'<ul>';
11487: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 11488: my %lt = &selfcreation_types();
1.34 raeburn 11489: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 11490: my $chgtext;
1.45 raeburn 11491: if ($type eq 'selfcreate') {
1.50 raeburn 11492: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 11493: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 11494: } else {
1.224 raeburn 11495: $chgtext .= &mt('Self-creation of a new account is permitted for:').
11496: '<ul>';
1.50 raeburn 11497: foreach my $case (@{$cancreate{$type}}) {
11498: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
11499: }
11500: $chgtext .= '</ul>';
1.100 raeburn 11501: if (ref($cancreate{$type}) eq 'ARRAY') {
11502: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
11503: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
11504: if (@{$cancreate{'statustocreate'}} == 0) {
1.224 raeburn 11505: $chgtext .= '<br />'.
11506: '<span class="LC_warning">'.
11507: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11508: '</span>';
1.100 raeburn 11509: }
11510: }
11511: }
11512: }
1.43 raeburn 11513: }
1.240 raeburn 11514: } elsif ($type eq 'shibenv') {
11515: if (keys(%{$cancreate{$type}}) == 0) {
11516: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
11517: } else {
11518: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
11519: '<ul>';
11520: foreach my $field (@shibfields) {
11521: next if ($cancreate{$type}{$field} eq '');
11522: if ($field eq 'inststatus') {
11523: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
11524: } else {
11525: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
11526: }
11527: }
11528: $chgtext .= '</ul>';
11529: }
1.93 raeburn 11530: } elsif ($type eq 'statustocreate') {
1.96 raeburn 11531: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
11532: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
11533: if (@{$cancreate{'selfcreate'}} > 0) {
11534: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 11535: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 11536: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11537: $chgtext .= '<br />'.
11538: '<span class="LC_warning">'.
11539: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
11540: '</span>';
11541: }
1.96 raeburn 11542: } elsif (ref($usertypes) eq 'HASH') {
11543: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 11544: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
11545: } else {
11546: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
11547: }
11548: $chgtext .= '<ul>';
11549: foreach my $case (@{$cancreate{$type}}) {
11550: if ($case eq 'default') {
11551: $chgtext .= '<li>'.$othertitle.'</li>';
11552: } else {
11553: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 11554: }
11555: }
1.100 raeburn 11556: $chgtext .= '</ul>';
11557: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 11558: $chgtext .= '<br /><span class="LC_warning">'.
11559: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
11560: '</span>';
1.100 raeburn 11561: }
11562: }
11563: } else {
11564: if (@{$cancreate{$type}} == 0) {
11565: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
11566: } else {
11567: $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 11568: }
11569: }
11570: }
1.236 raeburn 11571: } elsif ($type eq 'selfcreateprocessing') {
11572: my %choices = &Apache::lonlocal::texthash (
11573: automatic => 'Automatic approval',
11574: approval => 'Queued for approval',
11575: );
11576: if (@statuses > 1) {
11577: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
11578: '<ul>';
11579: foreach my $type (@statuses) {
11580: if ($type eq 'default') {
11581: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11582: } else {
11583: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
11584: }
11585: }
11586: $chgtext .= '</ul>';
11587: } else {
11588: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
11589: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
11590: }
1.165 raeburn 11591: } elsif ($type eq 'captcha') {
1.224 raeburn 11592: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 11593: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11594: } else {
11595: my %captchas = &captcha_phrases();
1.224 raeburn 11596: if ($captchas{$savecaptcha{$type}}) {
11597: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 11598: } else {
1.210 raeburn 11599: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 11600: }
11601: }
11602: } elsif ($type eq 'recaptchakeys') {
11603: my ($privkey,$pubkey);
1.224 raeburn 11604: if (ref($savecaptcha{$type}) eq 'HASH') {
11605: $pubkey = $savecaptcha{$type}{'public'};
11606: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 11607: }
11608: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11609: if (!$pubkey) {
11610: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11611: } else {
11612: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11613: }
11614: if (!$privkey) {
11615: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11616: } else {
11617: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11618: }
11619: $chgtext .= '</ul>';
1.269 raeburn 11620: } elsif ($type eq 'recaptchaversion') {
11621: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 11622: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 11623: }
1.224 raeburn 11624: } elsif ($type eq 'emailusername') {
11625: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228 raeburn 11626: if (ref($types) eq 'ARRAY') {
11627: foreach my $type (@{$types}) {
11628: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11629: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245 raeburn 11630: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228 raeburn 11631: '<ul>';
11632: foreach my $field (@{$infofields}) {
11633: if ($cancreate{'emailusername'}{$type}{$field}) {
11634: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11635: }
11636: }
1.245 raeburn 11637: $chgtext .= '</ul>';
11638: } else {
11639: $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 11640: }
11641: } else {
1.245 raeburn 11642: $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 11643: }
11644: }
11645: }
11646: }
11647: } elsif ($type eq 'notify') {
11648: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11649: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11650: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11651: if ($cancreate{'notify'}{'approval'}) {
11652: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11653: }
11654: }
1.43 raeburn 11655: }
1.34 raeburn 11656: }
1.224 raeburn 11657: if ($chgtext) {
11658: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11659: }
11660: }
11661: }
1.43 raeburn 11662: if (ref($changes{'email_rule'}) eq 'ARRAY') {
11663: my ($emailrules,$emailruleorder) =
11664: &Apache::lonnet::inst_userrules($dom,'email');
11665: my $chgtext = '<ul>';
11666: foreach my $type (@email_rule) {
11667: if (ref($emailrules->{$type}) eq 'HASH') {
11668: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
11669: }
11670: }
11671: $chgtext .= '</ul>';
11672: if (@email_rule > 0) {
1.224 raeburn 11673: $resulttext .= '<li>'.
11674: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
11675: $chgtext.
11676: '</li>';
1.43 raeburn 11677: } else {
1.224 raeburn 11678: $resulttext .= '<li>'.
11679: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
11680: '</li>';
1.43 raeburn 11681: }
11682: }
1.224 raeburn 11683: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11684: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11685: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11686: foreach my $type (@{$changes{'selfcreate'}}) {
11687: my $typename = $type;
11688: if (ref($usertypes) eq 'HASH') {
11689: if ($usertypes->{$type} ne '') {
11690: $typename = $usertypes->{$type};
11691: }
11692: }
11693: my @modifiable;
11694: $resulttext .= '<li>'.
11695: &mt('Self-creation of account by users with status: [_1]',
11696: '<span class="LC_cusr_emph">'.$typename.'</span>').
11697: ' - '.&mt('modifiable fields (if institutional data blank): ');
11698: foreach my $field (@fields) {
11699: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11700: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 11701: }
11702: }
1.224 raeburn 11703: if (@modifiable > 0) {
11704: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11705: } else {
1.224 raeburn 11706: $resulttext .= &mt('none');
1.43 raeburn 11707: }
1.224 raeburn 11708: $resulttext .= '</li>';
1.28 raeburn 11709: }
1.224 raeburn 11710: $resulttext .= '</ul></li>';
1.28 raeburn 11711: }
1.27 raeburn 11712: $resulttext .= '</ul>';
11713: } else {
1.224 raeburn 11714: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11715: }
11716: } else {
11717: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11718: &mt('An error occurred: [_1]',$putresult).'</span>';
11719: }
1.43 raeburn 11720: if ($warningmsg ne '') {
11721: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11722: }
1.23 raeburn 11723: return $resulttext;
11724: }
11725:
1.165 raeburn 11726: sub process_captcha {
11727: my ($container,$changes,$newsettings,$current) = @_;
11728: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11729: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11730: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11731: $newsettings->{'captcha'} = 'original';
11732: }
11733: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 11734: if ($container eq 'cancreate') {
1.169 raeburn 11735: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11736: push(@{$changes->{'cancreate'}},'captcha');
11737: } elsif (!defined($changes->{'cancreate'})) {
11738: $changes->{'cancreate'} = ['captcha'];
11739: }
11740: } else {
11741: $changes->{'captcha'} = 1;
1.165 raeburn 11742: }
11743: }
1.269 raeburn 11744: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 11745: if ($newsettings->{'captcha'} eq 'recaptcha') {
11746: $newpub = $env{'form.'.$container.'_recaptchapub'};
11747: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 11748: $newpub =~ s/[^\w\-]//g;
11749: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 11750: $newsettings->{'recaptchakeys'} = {
11751: public => $newpub,
11752: private => $newpriv,
11753: };
1.269 raeburn 11754: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11755: $newversion =~ s/\D//g;
11756: if ($newversion ne '2') {
11757: $newversion = 1;
11758: }
11759: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 11760: }
11761: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11762: $currpub = $current->{'recaptchakeys'}{'public'};
11763: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 11764: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11765: $newsettings->{'recaptchakeys'} = {
11766: public => '',
11767: private => '',
11768: }
11769: }
1.165 raeburn 11770: }
1.269 raeburn 11771: if ($current->{'captcha'} eq 'recaptcha') {
11772: $currversion = $current->{'recaptchaversion'};
11773: if ($currversion ne '2') {
11774: $currversion = 1;
11775: }
11776: }
11777: if ($currversion ne $newversion) {
11778: if ($container eq 'cancreate') {
11779: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11780: push(@{$changes->{'cancreate'}},'recaptchaversion');
11781: } elsif (!defined($changes->{'cancreate'})) {
11782: $changes->{'cancreate'} = ['recaptchaversion'];
11783: }
11784: } else {
11785: $changes->{'recaptchaversion'} = 1;
11786: }
11787: }
1.165 raeburn 11788: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 11789: if ($container eq 'cancreate') {
11790: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11791: push(@{$changes->{'cancreate'}},'recaptchakeys');
11792: } elsif (!defined($changes->{'cancreate'})) {
11793: $changes->{'cancreate'} = ['recaptchakeys'];
11794: }
11795: } else {
1.210 raeburn 11796: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 11797: }
11798: }
11799: return;
11800: }
11801:
1.33 raeburn 11802: sub modify_usermodification {
11803: my ($dom,%domconfig) = @_;
1.224 raeburn 11804: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11805: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11806: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 11807: if ($key eq 'selfcreate') {
11808: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11809: } else {
11810: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11811: }
1.33 raeburn 11812: }
11813: }
1.224 raeburn 11814: my @contexts = ('author','course');
1.33 raeburn 11815: my %context_title = (
11816: author => 'In author context',
11817: course => 'In course context',
11818: );
11819: my @fields = ('lastname','firstname','middlename','generation',
11820: 'permanentemail','id');
11821: my %roles = (
11822: author => ['ca','aa'],
11823: course => ['st','ep','ta','in','cr'],
11824: );
11825: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11826: foreach my $context (@contexts) {
11827: foreach my $role (@{$roles{$context}}) {
11828: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11829: foreach my $item (@fields) {
11830: if (grep(/^\Q$item\E$/,@modifiable)) {
11831: $modifyhash{$context}{$role}{$item} = 1;
11832: } else {
11833: $modifyhash{$context}{$role}{$item} = 0;
11834: }
11835: }
11836: }
11837: if (ref($curr_usermodification{$context}) eq 'HASH') {
11838: foreach my $role (@{$roles{$context}}) {
11839: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11840: foreach my $field (@fields) {
11841: if ($modifyhash{$context}{$role}{$field} ne
11842: $curr_usermodification{$context}{$role}{$field}) {
11843: push(@{$changes{$context}},$role);
11844: last;
11845: }
11846: }
11847: }
11848: }
11849: } else {
11850: foreach my $context (@contexts) {
11851: foreach my $role (@{$roles{$context}}) {
11852: push(@{$changes{$context}},$role);
11853: }
11854: }
11855: }
11856: }
11857: my %usermodification_hash = (
11858: usermodification => \%modifyhash,
11859: );
11860: my $putresult = &Apache::lonnet::put_dom('configuration',
11861: \%usermodification_hash,$dom);
11862: if ($putresult eq 'ok') {
11863: if (keys(%changes) > 0) {
11864: $resulttext = &mt('Changes made: ').'<ul>';
11865: foreach my $context (@contexts) {
11866: if (ref($changes{$context}) eq 'ARRAY') {
11867: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11868: if (ref($changes{$context}) eq 'ARRAY') {
11869: foreach my $role (@{$changes{$context}}) {
11870: my $rolename;
1.224 raeburn 11871: if ($role eq 'cr') {
11872: $rolename = &mt('Custom');
1.33 raeburn 11873: } else {
1.224 raeburn 11874: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11875: }
11876: my @modifiable;
1.224 raeburn 11877: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11878: foreach my $field (@fields) {
11879: if ($modifyhash{$context}{$role}{$field}) {
11880: push(@modifiable,$fieldtitles{$field});
11881: }
11882: }
11883: if (@modifiable > 0) {
11884: $resulttext .= join(', ',@modifiable);
11885: } else {
11886: $resulttext .= &mt('none');
11887: }
11888: $resulttext .= '</li>';
11889: }
11890: $resulttext .= '</ul></li>';
11891: }
11892: }
11893: }
11894: $resulttext .= '</ul>';
11895: } else {
11896: $resulttext = &mt('No changes made to user modification settings');
11897: }
11898: } else {
11899: $resulttext = '<span class="LC_error">'.
11900: &mt('An error occurred: [_1]',$putresult).'</span>';
11901: }
11902: return $resulttext;
11903: }
11904:
1.43 raeburn 11905: sub modify_defaults {
1.212 raeburn 11906: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11907: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 11908: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 11909: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
11910: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 11911: my @authtypes = ('internal','krb4','krb5','localauth');
11912: foreach my $item (@items) {
11913: $newvalues{$item} = $env{'form.'.$item};
11914: if ($item eq 'auth_def') {
11915: if ($newvalues{$item} ne '') {
11916: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11917: push(@errors,$item);
11918: }
11919: }
11920: } elsif ($item eq 'lang_def') {
11921: if ($newvalues{$item} ne '') {
11922: if ($newvalues{$item} =~ /^(\w+)/) {
11923: my $langcode = $1;
1.103 raeburn 11924: if ($langcode ne 'x_chef') {
11925: if (code2language($langcode) eq '') {
11926: push(@errors,$item);
11927: }
1.43 raeburn 11928: }
11929: } else {
11930: push(@errors,$item);
11931: }
11932: }
1.54 raeburn 11933: } elsif ($item eq 'timezone_def') {
11934: if ($newvalues{$item} ne '') {
1.62 raeburn 11935: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11936: push(@errors,$item);
11937: }
11938: }
1.68 raeburn 11939: } elsif ($item eq 'datelocale_def') {
11940: if ($newvalues{$item} ne '') {
11941: my @datelocale_ids = DateTime::Locale->ids();
11942: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11943: push(@errors,$item);
11944: }
11945: }
1.141 raeburn 11946: } elsif ($item eq 'portal_def') {
11947: if ($newvalues{$item} ne '') {
11948: 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])\/?$/) {
11949: push(@errors,$item);
11950: }
11951: }
1.294 raeburn 11952: } elsif ($item eq 'intauth_cost') {
11953: if ($newvalues{$item} ne '') {
11954: if ($newvalues{$item} =~ /\D/) {
11955: push(@errors,$item);
11956: }
11957: }
11958: } elsif ($item eq 'intauth_check') {
11959: if ($newvalues{$item} ne '') {
11960: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11961: push(@errors,$item);
11962: }
11963: }
11964: } elsif ($item eq 'intauth_switch') {
11965: if ($newvalues{$item} ne '') {
11966: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11967: push(@errors,$item);
11968: }
11969: }
1.43 raeburn 11970: }
11971: if (grep(/^\Q$item\E$/,@errors)) {
11972: $newvalues{$item} = $domdefaults{$item};
11973: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
11974: $changes{$item} = 1;
11975: }
1.72 raeburn 11976: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 11977: }
11978: my %defaults_hash = (
1.72 raeburn 11979: defaults => \%newvalues,
11980: );
1.43 raeburn 11981: my $title = &defaults_titles();
1.236 raeburn 11982:
11983: my $currinststatus;
11984: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11985: $currinststatus = $domconfig{'inststatus'};
11986: } else {
11987: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11988: $currinststatus = {
11989: inststatustypes => $usertypes,
11990: inststatusorder => $types,
11991: inststatusguest => [],
11992: };
11993: }
11994: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
11995: my @allpos;
11996: my %guests;
11997: my %alltypes;
11998: my ($currtitles,$currguests,$currorder);
11999: if (ref($currinststatus) eq 'HASH') {
12000: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
12001: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
12002: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
12003: if ($currinststatus->{inststatustypes}->{$type} ne '') {
12004: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
12005: }
12006: }
12007: unless (grep(/^\Q$type\E$/,@todelete)) {
12008: my $position = $env{'form.inststatus_pos_'.$type};
12009: $position =~ s/\D+//g;
12010: $allpos[$position] = $type;
12011: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
12012: $alltypes{$type} =~ s/`//g;
12013: if ($env{'form.inststatus_guest_'.$type}) {
12014: $guests{$type} = 1;
12015: }
12016: }
12017: }
12018: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
12019: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
12020: }
12021: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
12022: $currtitles =~ s/,$//;
12023: }
12024: }
12025: if ($env{'form.addinststatus'}) {
12026: my $newtype = $env{'form.addinststatus'};
12027: $newtype =~ s/\W//g;
12028: unless (exists($alltypes{$newtype})) {
12029: if ($env{'form.addinststatus_guest'}) {
12030: $guests{$newtype} = 1;
12031: }
12032: $alltypes{$newtype} = $env{'form.addinststatus_title'};
12033: $alltypes{$newtype} =~ s/`//g;
12034: my $position = $env{'form.addinststatus_pos'};
12035: $position =~ s/\D+//g;
12036: if ($position ne '') {
12037: $allpos[$position] = $newtype;
12038: }
12039: }
12040: }
12041: my (@orderedstatus,@orderedguests);
12042: foreach my $type (@allpos) {
12043: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
12044: push(@orderedstatus,$type);
12045: if ($guests{$type}) {
12046: push(@orderedguests,$type);
12047: }
12048: }
12049: }
12050: foreach my $type (keys(%alltypes)) {
12051: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
12052: delete($alltypes{$type});
12053: }
12054: }
12055: $defaults_hash{'inststatus'} = {
12056: inststatustypes => \%alltypes,
12057: inststatusorder => \@orderedstatus,
12058: inststatusguest => \@orderedguests,
12059: };
12060: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
12061: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
12062: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
12063: }
12064: }
12065: if ($currorder ne join(',',@orderedstatus)) {
12066: $changes{'inststatus'}{'inststatusorder'} = 1;
12067: }
12068: if ($currguests ne join(',',@orderedguests)) {
12069: $changes{'inststatus'}{'inststatusguest'} = 1;
12070: }
12071: my $newtitles;
12072: foreach my $item (@orderedstatus) {
12073: $newtitles .= $alltypes{$item}.',';
12074: }
12075: $newtitles =~ s/,$//;
12076: if ($currtitles ne $newtitles) {
12077: $changes{'inststatus'}{'inststatustypes'} = 1;
12078: }
1.43 raeburn 12079: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
12080: $dom);
12081: if ($putresult eq 'ok') {
12082: if (keys(%changes) > 0) {
12083: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 12084: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 12085: 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";
12086: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 12087: if ($item eq 'inststatus') {
12088: if (ref($changes{'inststatus'}) eq 'HASH') {
12089: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
12090: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
12091: foreach my $type (@orderedstatus) {
12092: $resulttext .= $alltypes{$type}.', ';
12093: }
12094: $resulttext =~ s/, $//;
12095: $resulttext .= '</li>';
12096: }
12097: if ($changes{'inststatus'}{'inststatusguest'}) {
12098: $resulttext .= '<li>';
12099: if (@orderedguests) {
12100: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
12101: foreach my $type (@orderedguests) {
12102: $resulttext .= $alltypes{$type}.', ';
12103: }
12104: $resulttext =~ s/, $//;
12105: } else {
12106: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
12107: }
12108: $resulttext .= '</li>';
12109: }
12110: }
12111: } else {
12112: my $value = $env{'form.'.$item};
12113: if ($value eq '') {
12114: $value = &mt('none');
12115: } elsif ($item eq 'auth_def') {
12116: my %authnames = &authtype_names();
12117: my %shortauth = (
12118: internal => 'int',
12119: krb4 => 'krb4',
12120: krb5 => 'krb5',
12121: localauth => 'loc',
12122: );
12123: $value = $authnames{$shortauth{$value}};
1.294 raeburn 12124: } elsif ($item eq 'intauth_switch') {
12125: my %optiondesc = &Apache::lonlocal::texthash (
12126: 0 => 'No',
12127: 1 => 'Yes',
12128: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
12129: );
12130: if ($value =~ /^(0|1|2)$/) {
12131: $value = $optiondesc{$value};
12132: } else {
12133: $value = &mt('none -- defaults to No');
12134: }
12135: } elsif ($item eq 'intauth_check') {
12136: my %optiondesc = &Apache::lonlocal::texthash (
12137: 0 => 'No',
12138: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
12139: 2 => 'Yes, disallow login if stored cost is less than domain default',
12140: );
12141: if ($value =~ /^(0|1|2)$/) {
12142: $value = $optiondesc{$value};
12143: } else {
12144: $value = &mt('none -- defaults to No');
12145: }
1.236 raeburn 12146: }
12147: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
12148: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 12149: }
12150: }
12151: $resulttext .= '</ul>';
12152: $mailmsgtext .= "\n";
12153: my $cachetime = 24*60*60;
1.72 raeburn 12154: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 12155: if (ref($lastactref) eq 'HASH') {
12156: $lastactref->{'domdefaults'} = 1;
12157: }
1.68 raeburn 12158: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 12159: my $notify = 1;
12160: if (ref($domconfig{'contacts'}) eq 'HASH') {
12161: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
12162: $notify = 0;
12163: }
12164: }
12165: if ($notify) {
12166: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
12167: "LON-CAPA Domain Settings Change - $dom",
12168: $mailmsgtext);
12169: }
1.54 raeburn 12170: }
1.43 raeburn 12171: } else {
1.54 raeburn 12172: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 12173: }
12174: } else {
12175: $resulttext = '<span class="LC_error">'.
12176: &mt('An error occurred: [_1]',$putresult).'</span>';
12177: }
12178: if (@errors > 0) {
12179: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
12180: foreach my $item (@errors) {
12181: $resulttext .= ' "'.$title->{$item}.'",';
12182: }
12183: $resulttext =~ s/,$//;
12184: }
12185: return $resulttext;
12186: }
12187:
1.46 raeburn 12188: sub modify_scantron {
1.205 raeburn 12189: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 12190: my ($resulttext,%confhash,%changes,$errors);
12191: my $custom = 'custom.tab';
12192: my $default = 'default.tab';
12193: my $servadm = $r->dir_config('lonAdmEMail');
12194: my ($configuserok,$author_ok,$switchserver) =
12195: &config_check($dom,$confname,$servadm);
12196: if ($env{'form.scantronformat.filename'} ne '') {
12197: my $error;
12198: if ($configuserok eq 'ok') {
12199: if ($switchserver) {
1.130 raeburn 12200: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 12201: } else {
12202: if ($author_ok eq 'ok') {
12203: my ($result,$scantronurl) =
12204: &publishlogo($r,'upload','scantronformat',$dom,
12205: $confname,'scantron','','',$custom);
12206: if ($result eq 'ok') {
12207: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 12208: $changes{'scantronformat'} = 1;
1.46 raeburn 12209: } else {
12210: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
12211: }
12212: } else {
12213: $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);
12214: }
12215: }
12216: } else {
12217: $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);
12218: }
12219: if ($error) {
12220: &Apache::lonnet::logthis($error);
12221: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12222: }
12223: }
1.48 raeburn 12224: if (ref($domconfig{'scantron'}) eq 'HASH') {
12225: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
12226: if ($env{'form.scantronformat_del'}) {
12227: $confhash{'scantron'}{'scantronformat'} = '';
12228: $changes{'scantronformat'} = 1;
1.46 raeburn 12229: }
12230: }
12231: }
12232: if (keys(%confhash) > 0) {
12233: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
12234: $dom);
12235: if ($putresult eq 'ok') {
12236: if (keys(%changes) > 0) {
1.48 raeburn 12237: if (ref($confhash{'scantron'}) eq 'HASH') {
12238: $resulttext = &mt('Changes made:').'<ul>';
12239: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 12240: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 12241: } else {
1.130 raeburn 12242: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 12243: }
1.48 raeburn 12244: $resulttext .= '</ul>';
12245: } else {
1.130 raeburn 12246: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 12247: }
12248: $resulttext .= '</ul>';
12249: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12250: if (ref($lastactref) eq 'HASH') {
12251: $lastactref->{'domainconfig'} = 1;
12252: }
1.46 raeburn 12253: } else {
1.130 raeburn 12254: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12255: }
12256: } else {
12257: $resulttext = '<span class="LC_error">'.
12258: &mt('An error occurred: [_1]',$putresult).'</span>';
12259: }
12260: } else {
1.130 raeburn 12261: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 12262: }
12263: if ($errors) {
12264: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12265: $errors.'</ul>';
12266: }
12267: return $resulttext;
12268: }
12269:
1.48 raeburn 12270: sub modify_coursecategories {
1.239 raeburn 12271: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 12272: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
12273: $cathash);
1.48 raeburn 12274: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 12275: my @catitems = ('unauth','auth');
12276: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 12277: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 12278: $cathash = $domconfig{'coursecategories'}{'cats'};
12279: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
12280: $changes{'togglecats'} = 1;
12281: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
12282: }
12283: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
12284: $changes{'categorize'} = 1;
12285: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
12286: }
1.120 raeburn 12287: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
12288: $changes{'togglecatscomm'} = 1;
12289: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
12290: }
12291: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
12292: $changes{'categorizecomm'} = 1;
12293: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 12294:
12295: }
12296: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
12297: $changes{'togglecatsplace'} = 1;
12298: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
12299: }
12300: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
12301: $changes{'categorizeplace'} = 1;
12302: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 12303: }
1.238 raeburn 12304: foreach my $item (@catitems) {
12305: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12306: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
12307: $changes{$item} = 1;
12308: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12309: }
12310: }
12311: }
1.57 raeburn 12312: } else {
12313: $changes{'togglecats'} = 1;
12314: $changes{'categorize'} = 1;
1.124 raeburn 12315: $changes{'togglecatscomm'} = 1;
12316: $changes{'categorizecomm'} = 1;
1.272 raeburn 12317: $changes{'togglecatsplace'} = 1;
12318: $changes{'categorizeplace'} = 1;
1.87 raeburn 12319: $domconfig{'coursecategories'} = {
12320: togglecats => $env{'form.togglecats'},
12321: categorize => $env{'form.categorize'},
1.124 raeburn 12322: togglecatscomm => $env{'form.togglecatscomm'},
12323: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 12324: togglecatsplace => $env{'form.togglecatsplace'},
12325: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 12326: };
1.238 raeburn 12327: foreach my $item (@catitems) {
12328: if ($env{'form.coursecat_'.$item} ne 'std') {
12329: $changes{$item} = 1;
12330: }
12331: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
12332: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
12333: }
12334: }
1.57 raeburn 12335: }
12336: if (ref($cathash) eq 'HASH') {
12337: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 12338: push (@deletecategory,'instcode::0');
12339: }
1.120 raeburn 12340: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
12341: push(@deletecategory,'communities::0');
12342: }
1.272 raeburn 12343: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
12344: push(@deletecategory,'placement::0');
12345: }
1.48 raeburn 12346: }
1.57 raeburn 12347: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
12348: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12349: if (@deletecategory > 0) {
12350: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 12351: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 12352: foreach my $item (@deletecategory) {
1.57 raeburn 12353: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
12354: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 12355: $deletions{$item} = 1;
1.57 raeburn 12356: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 12357: }
12358: }
12359: }
1.57 raeburn 12360: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 12361: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 12362: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 12363: $reorderings{$item} = 1;
1.57 raeburn 12364: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 12365: }
12366: if ($env{'form.addcategory_name_'.$item} ne '') {
12367: my $newcat = $env{'form.addcategory_name_'.$item};
12368: my $newdepth = $depth+1;
12369: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12370: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 12371: $adds{$newitem} = 1;
12372: }
12373: if ($env{'form.subcat_'.$item} ne '') {
12374: my $newcat = $env{'form.subcat_'.$item};
12375: my $newdepth = $depth+1;
12376: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 12377: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 12378: $adds{$newitem} = 1;
12379: }
12380: }
12381: }
12382: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 12383: if (ref($cathash) eq 'HASH') {
1.48 raeburn 12384: my $newitem = 'instcode::0';
1.57 raeburn 12385: if ($cathash->{$newitem} eq '') {
12386: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12387: $adds{$newitem} = 1;
12388: }
12389: } else {
12390: my $newitem = 'instcode::0';
1.57 raeburn 12391: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 12392: $adds{$newitem} = 1;
12393: }
12394: }
1.120 raeburn 12395: if ($env{'form.communities'} eq '1') {
12396: if (ref($cathash) eq 'HASH') {
12397: my $newitem = 'communities::0';
12398: if ($cathash->{$newitem} eq '') {
12399: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12400: $adds{$newitem} = 1;
12401: }
12402: } else {
12403: my $newitem = 'communities::0';
12404: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
12405: $adds{$newitem} = 1;
12406: }
12407: }
1.272 raeburn 12408: if ($env{'form.placement'} eq '1') {
12409: if (ref($cathash) eq 'HASH') {
12410: my $newitem = 'placement::0';
12411: if ($cathash->{$newitem} eq '') {
12412: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12413: $adds{$newitem} = 1;
12414: }
12415: } else {
12416: my $newitem = 'placement::0';
12417: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
12418: $adds{$newitem} = 1;
12419: }
12420: }
1.48 raeburn 12421: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 12422: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 12423: ($env{'form.addcategory_name'} ne 'communities') &&
12424: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 12425: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
12426: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
12427: $adds{$newitem} = 1;
12428: }
1.48 raeburn 12429: }
1.57 raeburn 12430: my $putresult;
1.48 raeburn 12431: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12432: if (keys(%deletions) > 0) {
12433: foreach my $key (keys(%deletions)) {
12434: if ($predelallitems{$key} ne '') {
12435: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
12436: }
12437: }
12438: }
12439: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 12440: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 12441: if (ref($chkcats[0]) eq 'ARRAY') {
12442: my $depth = 0;
12443: my $chg = 0;
12444: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
12445: my $name = $chkcats[0][$i];
12446: my $item;
12447: if ($name eq '') {
12448: $chg ++;
12449: } else {
12450: $item = &escape($name).'::0';
12451: if ($chg) {
1.57 raeburn 12452: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12453: }
12454: $depth ++;
1.57 raeburn 12455: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12456: $depth --;
12457: }
12458: }
12459: }
1.57 raeburn 12460: }
12461: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12462: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12463: if ($putresult eq 'ok') {
1.57 raeburn 12464: my %title = (
1.120 raeburn 12465: togglecats => 'Show/Hide a course in catalog',
12466: categorize => 'Assign a category to a course',
12467: togglecatscomm => 'Show/Hide a community in catalog',
12468: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12469: );
12470: my %level = (
1.120 raeburn 12471: dom => 'set in Domain ("Modify Course/Community")',
12472: crs => 'set in Course ("Course Configuration")',
12473: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 12474: none => 'No catalog',
12475: std => 'Standard catalog',
12476: domonly => 'Domain-only catalog',
12477: codesrch => 'Code search form',
1.57 raeburn 12478: );
1.48 raeburn 12479: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12480: if ($changes{'togglecats'}) {
12481: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12482: }
12483: if ($changes{'categorize'}) {
12484: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12485: }
1.120 raeburn 12486: if ($changes{'togglecatscomm'}) {
12487: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12488: }
12489: if ($changes{'categorizecomm'}) {
12490: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12491: }
1.238 raeburn 12492: if ($changes{'unauth'}) {
12493: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12494: }
12495: if ($changes{'auth'}) {
12496: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12497: }
1.57 raeburn 12498: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12499: my $cathash;
12500: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12501: $cathash = $domconfig{'coursecategories'}{'cats'};
12502: } else {
12503: $cathash = {};
12504: }
12505: my (@cats,@trails,%allitems);
12506: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12507: if (keys(%deletions) > 0) {
12508: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12509: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12510: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12511: }
12512: $resulttext .= '</ul></li>';
12513: }
12514: if (keys(%reorderings) > 0) {
12515: my %sort_by_trail;
12516: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12517: foreach my $key (keys(%reorderings)) {
12518: if ($allitems{$key} ne '') {
12519: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12520: }
1.48 raeburn 12521: }
1.57 raeburn 12522: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12523: $resulttext .= '<li>'.$trails[$trail].'</li>';
12524: }
12525: $resulttext .= '</ul></li>';
1.48 raeburn 12526: }
1.57 raeburn 12527: if (keys(%adds) > 0) {
12528: my %sort_by_trail;
12529: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12530: foreach my $key (keys(%adds)) {
12531: if ($allitems{$key} ne '') {
12532: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12533: }
12534: }
12535: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12536: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12537: }
1.57 raeburn 12538: $resulttext .= '</ul></li>';
1.48 raeburn 12539: }
12540: }
12541: $resulttext .= '</ul>';
1.239 raeburn 12542: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 12543: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12544: if ($changes{'auth'}) {
12545: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12546: }
12547: if ($changes{'unauth'}) {
12548: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12549: }
12550: my $cachetime = 24*60*60;
12551: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 12552: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 12553: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 12554: }
12555: }
1.48 raeburn 12556: } else {
12557: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12558: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12559: }
12560: } else {
1.120 raeburn 12561: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12562: }
12563: return $resulttext;
12564: }
12565:
1.69 raeburn 12566: sub modify_serverstatuses {
12567: my ($dom,%domconfig) = @_;
12568: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12569: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12570: %currserverstatus = %{$domconfig{'serverstatuses'}};
12571: }
12572: my @pages = &serverstatus_pages();
12573: foreach my $type (@pages) {
12574: $newserverstatus{$type}{'namedusers'} = '';
12575: $newserverstatus{$type}{'machines'} = '';
12576: if (defined($env{'form.'.$type.'_namedusers'})) {
12577: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12578: my @okusers;
12579: foreach my $user (@users) {
12580: my ($uname,$udom) = split(/:/,$user);
12581: if (($udom =~ /^$match_domain$/) &&
12582: (&Apache::lonnet::domain($udom)) &&
12583: ($uname =~ /^$match_username$/)) {
12584: if (!grep(/^\Q$user\E/,@okusers)) {
12585: push(@okusers,$user);
12586: }
12587: }
12588: }
12589: if (@okusers > 0) {
12590: @okusers = sort(@okusers);
12591: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12592: }
12593: }
12594: if (defined($env{'form.'.$type.'_machines'})) {
12595: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12596: my @okmachines;
12597: foreach my $ip (@machines) {
12598: my @parts = split(/\./,$ip);
12599: next if (@parts < 4);
12600: my $badip = 0;
12601: for (my $i=0; $i<4; $i++) {
12602: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12603: $badip = 1;
12604: last;
12605: }
12606: }
12607: if (!$badip) {
12608: push(@okmachines,$ip);
12609: }
12610: }
12611: @okmachines = sort(@okmachines);
12612: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12613: }
12614: }
12615: my %serverstatushash = (
12616: serverstatuses => \%newserverstatus,
12617: );
12618: foreach my $type (@pages) {
1.83 raeburn 12619: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12620: my (@current,@new);
1.83 raeburn 12621: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12622: if ($currserverstatus{$type}{$setting} ne '') {
12623: @current = split(/,/,$currserverstatus{$type}{$setting});
12624: }
12625: }
12626: if ($newserverstatus{$type}{$setting} ne '') {
12627: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12628: }
12629: if (@current > 0) {
12630: if (@new > 0) {
12631: foreach my $item (@current) {
12632: if (!grep(/^\Q$item\E$/,@new)) {
12633: $changes{$type}{$setting} = 1;
1.82 raeburn 12634: last;
12635: }
12636: }
1.84 raeburn 12637: foreach my $item (@new) {
12638: if (!grep(/^\Q$item\E$/,@current)) {
12639: $changes{$type}{$setting} = 1;
12640: last;
1.82 raeburn 12641: }
12642: }
12643: } else {
1.83 raeburn 12644: $changes{$type}{$setting} = 1;
1.69 raeburn 12645: }
1.83 raeburn 12646: } elsif (@new > 0) {
12647: $changes{$type}{$setting} = 1;
1.69 raeburn 12648: }
12649: }
12650: }
12651: if (keys(%changes) > 0) {
1.81 raeburn 12652: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12653: my $putresult = &Apache::lonnet::put_dom('configuration',
12654: \%serverstatushash,$dom);
12655: if ($putresult eq 'ok') {
12656: $resulttext .= &mt('Changes made:').'<ul>';
12657: foreach my $type (@pages) {
1.84 raeburn 12658: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12659: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12660: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12661: if ($newserverstatus{$type}{'namedusers'} eq '') {
12662: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12663: } else {
12664: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12665: }
1.84 raeburn 12666: }
12667: if ($changes{$type}{'machines'}) {
1.69 raeburn 12668: if ($newserverstatus{$type}{'machines'} eq '') {
12669: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12670: } else {
12671: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12672: }
12673:
12674: }
12675: $resulttext .= '</ul></li>';
12676: }
12677: }
12678: $resulttext .= '</ul>';
12679: } else {
12680: $resulttext = '<span class="LC_error">'.
12681: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12682:
12683: }
12684: } else {
12685: $resulttext = &mt('No changes made to access to server status pages');
12686: }
12687: return $resulttext;
12688: }
12689:
1.118 jms 12690: sub modify_helpsettings {
1.285 raeburn 12691: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 12692: my ($resulttext,$errors,%changes,%helphash);
12693: my %defaultchecked = ('submitbugs' => 'on');
12694: my @offon = ('off','on');
1.118 jms 12695: my @toggles = ('submitbugs');
1.285 raeburn 12696: my %current = ('submitbugs' => '',
12697: 'adhoc' => {},
12698: );
1.118 jms 12699: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 12700: %current = %{$domconfig{'helpsettings'}};
12701: }
1.285 raeburn 12702: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 12703: foreach my $item (@toggles) {
12704: if ($defaultchecked{$item} eq 'on') {
12705: if ($current{$item} eq '') {
12706: if ($env{'form.'.$item} eq '0') {
12707: $changes{$item} = 1;
12708: }
12709: } elsif ($current{$item} ne $env{'form.'.$item}) {
12710: $changes{$item} = 1;
12711: }
12712: } elsif ($defaultchecked{$item} eq 'off') {
12713: if ($current{$item} eq '') {
12714: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 12715: $changes{$item} = 1;
12716: }
1.282 raeburn 12717: } elsif ($current{$item} ne $env{'form.'.$item}) {
12718: $changes{$item} = 1;
12719: }
12720: }
12721: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
12722: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
12723: }
12724: }
1.285 raeburn 12725: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 12726: my $confname = $dom.'-domainconfig';
12727: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 12728: my (@allpos,%newsettings,%changedprivs,$newrole);
12729: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 12730: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 12731: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 12732: my %lt = &Apache::lonlocal::texthash(
12733: s => 'system',
12734: d => 'domain',
12735: order => 'Display order',
12736: access => 'Role usage',
1.291 raeburn 12737: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 12738: dh => 'All with domain helpdesk role',
12739: da => 'All with domain helpdesk assistant role',
1.285 raeburn 12740: none => 'None',
12741: status => 'Determined based on institutional status',
12742: inc => 'Include all, but exclude specific personnel',
12743: exc => 'Exclude all, but include specific personnel',
12744: );
12745: for (my $num=0; $num<=$maxnum; $num++) {
12746: my ($prefix,$identifier,$rolename,%curr);
12747: if ($num == $maxnum) {
12748: next unless ($env{'form.newcusthelp'} == $maxnum);
12749: $identifier = 'custhelp'.$num;
12750: $prefix = 'helproles_'.$num;
12751: $rolename = $env{'form.custhelpname'.$num};
12752: $rolename=~s/[^A-Za-z0-9]//gs;
12753: next if ($rolename eq '');
12754: next if (exists($existing{'rolesdef_'.$rolename}));
12755: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12756: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12757: $newprivs{'c'},$confname,$dom);
12758: if ($result ne 'ok') {
12759: $errors .= '<li><span class="LC_error">'.
12760: &mt('An error occurred storing the new custom role: [_1]',
12761: $result).'</span></li>';
12762: next;
12763: } else {
12764: $changedprivs{$rolename} = \%newprivs;
12765: $newrole = $rolename;
12766: }
12767: } else {
12768: $prefix = 'helproles_'.$num;
12769: $rolename = $env{'form.'.$prefix};
12770: next if ($rolename eq '');
12771: next unless (exists($existing{'rolesdef_'.$rolename}));
12772: $identifier = 'custhelp'.$num;
12773: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12774: my %currprivs;
1.289 raeburn 12775: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 12776: split(/\_/,$existing{'rolesdef_'.$rolename});
12777: foreach my $level ('c','d','s') {
12778: if ($newprivs{$level} ne $currprivs{$level}) {
12779: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12780: $newprivs{'c'},$confname,$dom);
12781: if ($result ne 'ok') {
12782: $errors .= '<li><span class="LC_error">'.
12783: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12784: $rolename,$result).'</span></li>';
12785: } else {
12786: $changedprivs{$rolename} = \%newprivs;
12787: }
12788: last;
12789: }
12790: }
12791: if (ref($current{'adhoc'}) eq 'HASH') {
12792: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12793: %curr = %{$current{'adhoc'}{$rolename}};
12794: }
12795: }
12796: }
12797: my $newpos = $env{'form.'.$prefix.'_pos'};
12798: $newpos =~ s/\D+//g;
12799: $allpos[$newpos] = $rolename;
12800: my $newdesc = $env{'form.'.$prefix.'_desc'};
12801: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12802: if ($curr{'desc'}) {
12803: if ($curr{'desc'} ne $newdesc) {
12804: $changes{'customrole'}{$rolename}{'desc'} = 1;
12805: $newsettings{$rolename}{'desc'} = $newdesc;
12806: }
12807: } elsif ($newdesc ne '') {
12808: $changes{'customrole'}{$rolename}{'desc'} = 1;
12809: $newsettings{$rolename}{'desc'} = $newdesc;
12810: }
12811: my $access = $env{'form.'.$prefix.'_access'};
12812: if (grep(/^\Q$access\E$/,@accesstypes)) {
12813: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12814: if ($access eq 'status') {
12815: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12816: if (scalar(@statuses) == 0) {
1.289 raeburn 12817: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 12818: } else {
12819: my (@shownstatus,$numtypes);
12820: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12821: if (ref($types) eq 'ARRAY') {
12822: $numtypes = scalar(@{$types});
12823: foreach my $type (sort(@statuses)) {
12824: if ($type eq 'default') {
12825: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12826: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12827: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12828: push(@shownstatus,$usertypes->{$type});
12829: }
12830: }
12831: }
12832: if (grep(/^default$/,@statuses)) {
12833: push(@shownstatus,$othertitle);
12834: }
12835: if (scalar(@shownstatus) == 1+$numtypes) {
12836: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12837: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12838: } else {
12839: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12840: if (ref($curr{'status'}) eq 'ARRAY') {
12841: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12842: if (@diffs) {
12843: $changes{'customrole'}{$rolename}{$access} = 1;
12844: }
12845: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12846: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 12847: }
1.166 raeburn 12848: }
12849: }
1.285 raeburn 12850: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12851: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12852: my @newspecstaff;
12853: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12854: foreach my $person (sort(@personnel)) {
12855: if ($domhelpdesk{$person}) {
12856: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12857: }
12858: }
12859: if (ref($curr{$access}) eq 'ARRAY') {
12860: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12861: if (@diffs) {
12862: $changes{'customrole'}{$rolename}{$access} = 1;
12863: }
12864: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12865: $changes{'customrole'}{$rolename}{$access} = 1;
12866: }
12867: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12868: my ($uname,$udom) = split(/:/,$person);
12869: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12870: }
12871: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 12872: }
1.285 raeburn 12873: } else {
12874: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12875: }
12876: unless ($curr{'access'} eq $access) {
12877: $changes{'customrole'}{$rolename}{'access'} = 1;
12878: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 12879: }
12880: }
1.285 raeburn 12881: if (@allpos > 0) {
12882: my $idx = 0;
12883: foreach my $rolename (@allpos) {
12884: if ($rolename ne '') {
12885: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12886: if (ref($current{'adhoc'}) eq 'HASH') {
12887: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12888: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12889: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 12890: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 12891: }
12892: }
1.282 raeburn 12893: }
1.285 raeburn 12894: $idx ++;
1.166 raeburn 12895: }
12896: }
1.118 jms 12897: }
1.123 jms 12898: my $putresult;
12899: if (keys(%changes) > 0) {
1.166 raeburn 12900: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 12901: if ($putresult eq 'ok') {
1.285 raeburn 12902: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12903: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12904: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12905: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12906: }
12907: }
12908: my $cachetime = 24*60*60;
12909: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12910: if (ref($lastactref) eq 'HASH') {
12911: $lastactref->{'domdefaults'} = 1;
12912: }
12913: } else {
12914: $errors .= '<li><span class="LC_error">'.
12915: &mt('An error occurred storing the settings: [_1]',
12916: $putresult).'</span></li>';
12917: }
12918: }
12919: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12920: $resulttext = &mt('Changes made:').'<ul>';
12921: my (%shownprivs,@levelorder);
12922: @levelorder = ('c','d','s');
12923: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 12924: foreach my $item (sort(keys(%changes))) {
12925: if ($item eq 'submitbugs') {
12926: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12927: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12928: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 12929: } elsif ($item eq 'customrole') {
12930: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 12931: my @keyorder = ('order','desc','access','status','exc','inc');
12932: my %keytext = &Apache::lonlocal::texthash(
12933: order => 'Order',
12934: desc => 'Role description',
12935: access => 'Role usage',
12936: status => 'Allowed instituional types',
12937: exc => 'Allowed personnel',
12938: inc => 'Disallowed personnel',
12939: );
1.282 raeburn 12940: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 12941: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12942: if ($role eq $newrole) {
12943: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12944: $role).'<ul>';
12945: } else {
12946: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12947: $role).'<ul>';
12948: }
12949: foreach my $key (@keyorder) {
12950: if ($changes{'customrole'}{$role}{$key}) {
12951: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12952: $keytext{$key},$newsettings{$role}{$key}).
12953: '</li>';
12954: }
12955: }
12956: if (ref($changedprivs{$role}) eq 'HASH') {
12957: $shownprivs{$role} = 1;
12958: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
12959: foreach my $level (@levelorder) {
12960: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12961: next if ($item eq '');
12962: my ($priv) = split(/\&/,$item,2);
12963: if (&Apache::lonnet::plaintext($priv)) {
12964: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12965: unless ($level eq 'c') {
12966: $resulttext .= ' ('.$lt{$level}.')';
12967: }
12968: $resulttext .= '</li>';
12969: }
12970: }
12971: }
12972: $resulttext .= '</ul>';
12973: }
12974: $resulttext .= '</ul></li>';
12975: }
12976: }
12977: }
12978: }
12979: }
12980: }
12981: if (keys(%changedprivs)) {
12982: foreach my $role (sort(keys(%changedprivs))) {
12983: unless ($shownprivs{$role}) {
12984: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12985: $role).'<ul>'.
12986: '<li>'.&mt('Privileges set to :').'<ul>';
12987: foreach my $level (@levelorder) {
12988: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12989: next if ($item eq '');
12990: my ($priv) = split(/\&/,$item,2);
12991: if (&Apache::lonnet::plaintext($priv)) {
12992: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12993: unless ($level eq 'c') {
12994: $resulttext .= ' ('.$lt{$level}.')';
12995: }
12996: $resulttext .= '</li>';
12997: }
1.282 raeburn 12998: }
12999: }
1.285 raeburn 13000: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 13001: }
13002: }
13003: }
1.285 raeburn 13004: $resulttext .= '</ul>';
13005: } else {
13006: $resulttext = &mt('No changes made to help settings');
1.118 jms 13007: }
13008: if ($errors) {
1.168 raeburn 13009: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 13010: $errors.'</ul>';
1.118 jms 13011: }
13012: return $resulttext;
13013: }
13014:
1.121 raeburn 13015: sub modify_coursedefaults {
1.212 raeburn 13016: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 13017: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 13018: my %defaultchecked = (
13019: 'canuse_pdfforms' => 'off',
13020: 'uselcmath' => 'on',
13021: 'usejsme' => 'on'
13022: );
13023: my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198 raeburn 13024: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 13025: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
13026: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
13027: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 13028: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 13029: my %staticdefaults = (
13030: anonsurvey_threshold => 10,
13031: uploadquota => 500,
1.257 raeburn 13032: postsubmit => 60,
1.276 raeburn 13033: mysqltables => 172800,
1.198 raeburn 13034: );
1.121 raeburn 13035:
13036: $defaultshash{'coursedefaults'} = {};
13037:
13038: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
13039: if ($domconfig{'coursedefaults'} eq '') {
13040: $domconfig{'coursedefaults'} = {};
13041: }
13042: }
13043:
13044: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
13045: foreach my $item (@toggles) {
13046: if ($defaultchecked{$item} eq 'on') {
13047: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13048: ($env{'form.'.$item} eq '0')) {
13049: $changes{$item} = 1;
1.192 raeburn 13050: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 13051: $changes{$item} = 1;
13052: }
13053: } elsif ($defaultchecked{$item} eq 'off') {
13054: if (($domconfig{'coursedefaults'}{$item} eq '') &&
13055: ($env{'form.'.$item} eq '1')) {
13056: $changes{$item} = 1;
13057: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
13058: $changes{$item} = 1;
13059: }
13060: }
13061: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
13062: }
1.198 raeburn 13063: foreach my $item (@numbers) {
13064: my ($currdef,$newdef);
1.208 raeburn 13065: $newdef = $env{'form.'.$item};
1.198 raeburn 13066: if ($item eq 'anonsurvey_threshold') {
13067: $currdef = $domconfig{'coursedefaults'}{$item};
13068: $newdef =~ s/\D//g;
13069: if ($newdef eq '' || $newdef < 1) {
13070: $newdef = 1;
13071: }
13072: $defaultshash{'coursedefaults'}{$item} = $newdef;
13073: } else {
1.276 raeburn 13074: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
13075: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
13076: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 13077: }
13078: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 13079: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 13080: }
13081: if ($currdef ne $newdef) {
13082: my $staticdef;
13083: if ($item eq 'anonsurvey_threshold') {
13084: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
13085: $changes{$item} = 1;
13086: }
1.276 raeburn 13087: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 13088: my $setting = $1;
1.276 raeburn 13089: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
13090: $changes{$setting} = 1;
1.198 raeburn 13091: }
13092: }
1.139 raeburn 13093: }
13094: }
1.264 raeburn 13095: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
13096: my @currclonecode;
13097: if (ref($currclone) eq 'HASH') {
13098: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
13099: @currclonecode = @{$currclone->{'instcode'}};
13100: }
13101: }
13102: my $newclone;
1.289 raeburn 13103: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 13104: $newclone = $env{'form.canclone'};
13105: }
13106: if ($newclone eq 'instcode') {
13107: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
13108: my (%codedefaults,@code_order,@clonecode);
13109: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
13110: \@code_order);
13111: foreach my $item (@code_order) {
13112: if (grep(/^\Q$item\E$/,@newcodes)) {
13113: push(@clonecode,$item);
13114: }
13115: }
13116: if (@clonecode) {
13117: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
13118: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
13119: if (@diffs) {
13120: $changes{'canclone'} = 1;
13121: }
13122: } else {
13123: $newclone eq '';
13124: }
13125: } elsif ($newclone ne '') {
1.289 raeburn 13126: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
13127: }
1.264 raeburn 13128: if ($newclone ne $currclone) {
13129: $changes{'canclone'} = 1;
13130: }
1.257 raeburn 13131: my %credits;
13132: foreach my $type (@types) {
13133: unless ($type eq 'community') {
13134: $credits{$type} = $env{'form.'.$type.'_credits'};
13135: $credits{$type} =~ s/[^\d.]+//g;
13136: }
13137: }
13138: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
13139: ($env{'form.coursecredits'} eq '1')) {
13140: $changes{'coursecredits'} = 1;
13141: foreach my $type (keys(%credits)) {
13142: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13143: }
13144: } else {
1.289 raeburn 13145: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 13146: foreach my $type (@types) {
13147: unless ($type eq 'community') {
1.289 raeburn 13148: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 13149: $changes{'coursecredits'} = 1;
13150: }
13151: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
13152: }
13153: }
13154: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13155: foreach my $type (@types) {
13156: unless ($type eq 'community') {
13157: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
13158: $changes{'coursecredits'} = 1;
13159: last;
13160: }
13161: }
13162: }
13163: }
13164: }
13165: if ($env{'form.postsubmit'} eq '1') {
13166: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
13167: my %currtimeout;
13168: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13169: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
13170: $changes{'postsubmit'} = 1;
13171: }
13172: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13173: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
13174: }
13175: } else {
13176: $changes{'postsubmit'} = 1;
13177: }
13178: foreach my $type (@types) {
13179: my $timeout = $env{'form.'.$type.'_timeout'};
13180: $timeout =~ s/\D//g;
13181: if ($timeout == $staticdefaults{'postsubmit'}) {
13182: $timeout = '';
13183: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
13184: $timeout = '0';
13185: }
13186: unless ($timeout eq '') {
13187: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
13188: }
13189: if (exists($currtimeout{$type})) {
13190: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 13191: $changes{'postsubmit'} = 1;
1.257 raeburn 13192: }
13193: } elsif ($timeout ne '') {
13194: $changes{'postsubmit'} = 1;
13195: }
13196: }
13197: } else {
13198: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
13199: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13200: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
13201: $changes{'postsubmit'} = 1;
13202: }
13203: } else {
13204: $changes{'postsubmit'} = 1;
13205: }
1.192 raeburn 13206: }
1.121 raeburn 13207: }
13208: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13209: $dom);
13210: if ($putresult eq 'ok') {
13211: if (keys(%changes) > 0) {
1.213 raeburn 13212: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 13213: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 13214: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.276 raeburn 13215: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.257 raeburn 13216: foreach my $item ('canuse_pdfforms','uselcmath','usejsme') {
13217: if ($changes{$item}) {
13218: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
13219: }
1.289 raeburn 13220: }
1.192 raeburn 13221: if ($changes{'coursecredits'}) {
13222: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 13223: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
13224: $domdefaults{$type.'credits'} =
13225: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
13226: }
13227: }
13228: }
13229: if ($changes{'postsubmit'}) {
13230: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
13231: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
13232: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13233: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
13234: $domdefaults{$type.'postsubtimeout'} =
13235: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13236: }
13237: }
1.192 raeburn 13238: }
13239: }
1.198 raeburn 13240: if ($changes{'uploadquota'}) {
13241: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13242: foreach my $type (@types) {
13243: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
13244: }
13245: }
13246: }
1.264 raeburn 13247: if ($changes{'canclone'}) {
13248: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13249: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13250: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
13251: if (@clonecodes) {
13252: $domdefaults{'canclone'} = join('+',@clonecodes);
13253: }
13254: }
13255: } else {
13256: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
13257: }
13258: }
1.121 raeburn 13259: my $cachetime = 24*60*60;
13260: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 13261: if (ref($lastactref) eq 'HASH') {
13262: $lastactref->{'domdefaults'} = 1;
13263: }
1.121 raeburn 13264: }
13265: $resulttext = &mt('Changes made:').'<ul>';
13266: foreach my $item (sort(keys(%changes))) {
13267: if ($item eq 'canuse_pdfforms') {
13268: if ($env{'form.'.$item} eq '1') {
13269: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
13270: } else {
13271: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
13272: }
1.257 raeburn 13273: } elsif ($item eq 'uselcmath') {
13274: if ($env{'form.'.$item} eq '1') {
13275: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
13276: } else {
13277: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
13278: }
13279: } elsif ($item eq 'usejsme') {
13280: if ($env{'form.'.$item} eq '1') {
13281: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
13282: } else {
1.289 raeburn 13283: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 13284: }
1.139 raeburn 13285: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 13286: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 13287: } elsif ($item eq 'uploadquota') {
13288: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
13289: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
13290: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
13291: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 13292: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 13293: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 13294: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
13295: '</ul>'.
13296: '</li>';
13297: } else {
13298: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
13299: }
1.276 raeburn 13300: } elsif ($item eq 'mysqltables') {
13301: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
13302: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
13303: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
13304: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
13305: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
13306: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
13307: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
13308: '</ul>'.
13309: '</li>';
13310: } else {
13311: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
13312: }
1.257 raeburn 13313: } elsif ($item eq 'postsubmit') {
13314: if ($domdefaults{'postsubmit'} eq 'off') {
13315: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
13316: } else {
13317: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 13318: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 13319: $resulttext .= &mt('durations:').'<ul>';
13320: foreach my $type (@types) {
13321: $resulttext .= '<li>';
13322: my $timeout;
13323: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
13324: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
13325: }
13326: my $display;
13327: if ($timeout eq '0') {
13328: $display = &mt('unlimited');
13329: } elsif ($timeout eq '') {
13330: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
13331: } else {
13332: $display = &mt('[quant,_1,second]',$timeout);
13333: }
13334: if ($type eq 'community') {
13335: $resulttext .= &mt('Communities');
13336: } elsif ($type eq 'official') {
13337: $resulttext .= &mt('Official courses');
13338: } elsif ($type eq 'unofficial') {
13339: $resulttext .= &mt('Unofficial courses');
13340: } elsif ($type eq 'textbook') {
13341: $resulttext .= &mt('Textbook courses');
1.271 raeburn 13342: } elsif ($type eq 'placement') {
13343: $resulttext .= &mt('Placement tests');
1.257 raeburn 13344: }
13345: $resulttext .= ' -- '.$display.'</li>';
13346: }
13347: $resulttext .= '</ul>';
13348: }
1.289 raeburn 13349: $resulttext .= '</li>';
1.257 raeburn 13350: }
1.192 raeburn 13351: } elsif ($item eq 'coursecredits') {
13352: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
13353: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 13354: ($domdefaults{'unofficialcredits'} eq '') &&
13355: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 13356: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13357: } else {
13358: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
13359: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
13360: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 13361: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 13362: '</ul>'.
13363: '</li>';
13364: }
13365: } else {
13366: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
13367: }
1.264 raeburn 13368: } elsif ($item eq 'canclone') {
13369: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
13370: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
13371: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
13372: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
13373: }
13374: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
13375: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
13376: } else {
1.289 raeburn 13377: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 13378: }
1.140 raeburn 13379: }
1.121 raeburn 13380: }
13381: $resulttext .= '</ul>';
13382: } else {
13383: $resulttext = &mt('No changes made to course defaults');
13384: }
13385: } else {
13386: $resulttext = '<span class="LC_error">'.
13387: &mt('An error occurred: [_1]',$putresult).'</span>';
13388: }
13389: return $resulttext;
13390: }
13391:
1.231 raeburn 13392: sub modify_selfenrollment {
13393: my ($dom,$lastactref,%domconfig) = @_;
13394: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 13395: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 13396: my %titles = &tool_titles();
1.232 raeburn 13397: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
13398: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 13399: $ordered{'default'} = ['types','registered','approval','limit'];
13400:
13401: my (%roles,%shown,%toplevel);
13402: $roles{'0'} = &Apache::lonnet::plaintext('dc');
13403:
13404: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
13405: if ($domconfig{'selfenrollment'} eq '') {
13406: $domconfig{'selfenrollment'} = {};
13407: }
13408: }
13409: %toplevel = (
13410: admin => 'Configuration Rights',
13411: default => 'Default settings',
13412: validation => 'Validation of self-enrollment requests',
13413: );
1.233 raeburn 13414: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 13415:
13416: if (ref($ordered{'admin'}) eq 'ARRAY') {
13417: foreach my $item (@{$ordered{'admin'}}) {
13418: foreach my $type (@types) {
13419: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
13420: $selfenrollhash{'admin'}{$type}{$item} = 1;
13421: } else {
13422: $selfenrollhash{'admin'}{$type}{$item} = 0;
13423: }
13424: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
13425: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
13426: if ($selfenrollhash{'admin'}{$type}{$item} ne
13427: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
13428: push(@{$changes{'admin'}{$type}},$item);
13429: }
13430: } else {
13431: if (!$selfenrollhash{'admin'}{$type}{$item}) {
13432: push(@{$changes{'admin'}{$type}},$item);
13433: }
13434: }
13435: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13436: push(@{$changes{'admin'}{$type}},$item);
13437: }
13438: }
13439: }
13440: }
13441:
13442: foreach my $item (@{$ordered{'default'}}) {
13443: foreach my $type (@types) {
13444: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13445: if ($item eq 'types') {
13446: unless (($value eq 'all') || ($value eq 'dom')) {
13447: $value = '';
13448: }
13449: } elsif ($item eq 'registered') {
13450: unless ($value eq '1') {
13451: $value = 0;
13452: }
13453: } elsif ($item eq 'approval') {
13454: unless ($value =~ /^[012]$/) {
13455: $value = 0;
13456: }
13457: } else {
13458: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13459: $value = 'none';
13460: }
13461: }
13462: $selfenrollhash{'default'}{$type}{$item} = $value;
13463: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13464: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13465: if ($selfenrollhash{'default'}{$type}{$item} ne
13466: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13467: push(@{$changes{'default'}{$type}},$item);
13468: }
13469: } else {
13470: push(@{$changes{'default'}{$type}},$item);
13471: }
13472: } else {
13473: push(@{$changes{'default'}{$type}},$item);
13474: }
13475: if ($item eq 'limit') {
13476: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13477: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13478: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13479: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13480: }
13481: } else {
13482: $selfenrollhash{'default'}{$type}{'cap'} = '';
13483: }
13484: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13485: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13486: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13487: push(@{$changes{'default'}{$type}},'cap');
13488: }
13489: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13490: push(@{$changes{'default'}{$type}},'cap');
13491: }
13492: }
13493: }
13494: }
13495:
13496: foreach my $item (@{$itemsref}) {
13497: if ($item eq 'fields') {
13498: my @changed;
13499: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13500: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13501: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13502: }
13503: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13504: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13505: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13506: $domconfig{'selfenrollment'}{'validation'}{$item});
13507: } else {
13508: @changed = @{$selfenrollhash{'validation'}{$item}};
13509: }
13510: } else {
13511: @changed = @{$selfenrollhash{'validation'}{$item}};
13512: }
13513: if (@changed) {
13514: if ($selfenrollhash{'validation'}{$item}) {
13515: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13516: } else {
13517: $changes{'validation'}{$item} = &mt('None');
13518: }
13519: }
13520: } else {
13521: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13522: if ($item eq 'markup') {
13523: if ($env{'form.selfenroll_validation_'.$item}) {
13524: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13525: }
13526: }
13527: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13528: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13529: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13530: }
13531: }
13532: }
13533: }
13534:
13535: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13536: $dom);
13537: if ($putresult eq 'ok') {
13538: if (keys(%changes) > 0) {
13539: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13540: $resulttext = &mt('Changes made:').'<ul>';
13541: foreach my $key ('admin','default','validation') {
13542: if (ref($changes{$key}) eq 'HASH') {
13543: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13544: if ($key eq 'validation') {
13545: foreach my $item (@{$itemsref}) {
13546: if (exists($changes{$key}{$item})) {
13547: if ($item eq 'markup') {
13548: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13549: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13550: } else {
13551: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13552: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13553: }
13554: }
13555: }
13556: } else {
13557: foreach my $type (@types) {
13558: if ($type eq 'community') {
13559: $roles{'1'} = &mt('Community personnel');
13560: } else {
13561: $roles{'1'} = &mt('Course personnel');
13562: }
13563: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 13564: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13565: if ($key eq 'admin') {
13566: my @mgrdc = ();
13567: if (ref($ordered{$key}) eq 'ARRAY') {
13568: foreach my $item (@{$ordered{'admin'}}) {
13569: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13570: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13571: push(@mgrdc,$item);
13572: }
13573: }
13574: }
13575: if (@mgrdc) {
13576: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13577: } else {
13578: delete($domdefaults{$type.'selfenrolladmdc'});
13579: }
13580: }
13581: } else {
13582: if (ref($ordered{$key}) eq 'ARRAY') {
13583: foreach my $item (@{$ordered{$key}}) {
13584: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13585: $domdefaults{$type.'selfenroll'.$item} =
13586: $selfenrollhash{$key}{$type}{$item};
13587: }
13588: }
13589: }
13590: }
13591: }
1.231 raeburn 13592: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13593: foreach my $item (@{$ordered{$key}}) {
13594: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13595: $resulttext .= '<li>';
13596: if ($key eq 'admin') {
13597: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13598: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13599: } else {
13600: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13601: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13602: }
13603: $resulttext .= '</li>';
13604: }
13605: }
13606: $resulttext .= '</ul></li>';
13607: }
13608: }
13609: $resulttext .= '</ul></li>';
13610: }
13611: }
1.232 raeburn 13612: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13613: my $cachetime = 24*60*60;
13614: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13615: if (ref($lastactref) eq 'HASH') {
13616: $lastactref->{'domdefaults'} = 1;
13617: }
13618: }
1.231 raeburn 13619: }
13620: $resulttext .= '</ul>';
13621: } else {
13622: $resulttext = &mt('No changes made to self-enrollment settings');
13623: }
13624: } else {
13625: $resulttext = '<span class="LC_error">'.
13626: &mt('An error occurred: [_1]',$putresult).'</span>';
13627: }
13628: return $resulttext;
13629: }
13630:
1.137 raeburn 13631: sub modify_usersessions {
1.212 raeburn 13632: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13633: my @hostingtypes = ('version','excludedomain','includedomain');
13634: my @offloadtypes = ('primary','default');
13635: my %types = (
13636: remote => \@hostingtypes,
13637: hosted => \@hostingtypes,
13638: spares => \@offloadtypes,
13639: );
13640: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13641: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 13642: my (%by_ip,%by_location,@intdoms,@instdoms);
13643: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 13644: my @locations = sort(keys(%by_location));
1.137 raeburn 13645: my (%defaultshash,%changes);
13646: foreach my $prefix (@prefixes) {
13647: $defaultshash{'usersessions'}{$prefix} = {};
13648: }
1.212 raeburn 13649: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13650: my $resulttext;
1.138 raeburn 13651: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13652: foreach my $prefix (@prefixes) {
1.145 raeburn 13653: next if ($prefix eq 'spares');
13654: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13655: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13656: if ($type eq 'version') {
13657: my $value = $env{'form.'.$prefix.'_'.$type};
13658: my $okvalue;
13659: if ($value ne '') {
13660: if (grep(/^\Q$value\E$/,@lcversions)) {
13661: $okvalue = $value;
13662: }
13663: }
13664: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13665: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13666: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13667: if ($inuse == 0) {
13668: $changes{$prefix}{$type} = 1;
13669: } else {
13670: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13671: $changes{$prefix}{$type} = 1;
13672: }
13673: if ($okvalue ne '') {
13674: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13675: }
13676: }
13677: } else {
13678: if (($inuse == 1) && ($okvalue ne '')) {
13679: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13680: $changes{$prefix}{$type} = 1;
13681: }
13682: }
13683: } else {
13684: if (($inuse == 1) && ($okvalue ne '')) {
13685: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13686: $changes{$prefix}{$type} = 1;
13687: }
13688: }
13689: } else {
13690: if (($inuse == 1) && ($okvalue ne '')) {
13691: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13692: $changes{$prefix}{$type} = 1;
13693: }
13694: }
13695: } else {
13696: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13697: my @okvals;
13698: foreach my $val (@vals) {
1.138 raeburn 13699: if ($val =~ /:/) {
13700: my @items = split(/:/,$val);
13701: foreach my $item (@items) {
13702: if (ref($by_location{$item}) eq 'ARRAY') {
13703: push(@okvals,$item);
13704: }
13705: }
13706: } else {
13707: if (ref($by_location{$val}) eq 'ARRAY') {
13708: push(@okvals,$val);
13709: }
1.137 raeburn 13710: }
13711: }
13712: @okvals = sort(@okvals);
13713: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13714: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13715: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13716: if ($inuse == 0) {
13717: $changes{$prefix}{$type} = 1;
13718: } else {
13719: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13720: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13721: if (@changed > 0) {
13722: $changes{$prefix}{$type} = 1;
13723: }
13724: }
13725: } else {
13726: if ($inuse == 1) {
13727: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13728: $changes{$prefix}{$type} = 1;
13729: }
13730: }
13731: } else {
13732: if ($inuse == 1) {
13733: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13734: $changes{$prefix}{$type} = 1;
13735: }
13736: }
13737: } else {
13738: if ($inuse == 1) {
13739: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13740: $changes{$prefix}{$type} = 1;
13741: }
13742: }
13743: }
13744: }
13745: }
1.145 raeburn 13746:
13747: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 13748: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 13749: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13750: my $savespares;
13751:
13752: foreach my $lonhost (sort(keys(%servers))) {
13753: my $serverhomeID =
13754: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 13755: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 13756: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13757: my %spareschg;
13758: foreach my $type (@{$types{'spares'}}) {
13759: my @okspares;
13760: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13761: foreach my $server (@checked) {
1.152 raeburn 13762: if (&Apache::lonnet::hostname($server) ne '') {
13763: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13764: unless (grep(/^\Q$server\E$/,@okspares)) {
13765: push(@okspares,$server);
13766: }
1.145 raeburn 13767: }
13768: }
13769: }
13770: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13771: my $newspare;
1.152 raeburn 13772: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13773: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 13774: $newspare = $new;
13775: }
13776: }
1.152 raeburn 13777: my @spares;
13778: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13779: @spares = sort(@okspares,$newspare);
13780: } else {
13781: @spares = sort(@okspares);
13782: }
13783: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 13784: if (ref($spareid{$lonhost}) eq 'HASH') {
13785: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 13786: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 13787: if (@diffs > 0) {
13788: $spareschg{$type} = 1;
13789: }
13790: }
13791: }
13792: }
13793: if (keys(%spareschg) > 0) {
13794: $changes{'spares'}{$lonhost} = \%spareschg;
13795: }
13796: }
1.261 raeburn 13797: $defaultshash{'usersessions'}{'offloadnow'} = {};
13798: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13799: my @okoffload;
13800: if (@offloadnow) {
13801: foreach my $server (@offloadnow) {
13802: if (&Apache::lonnet::hostname($server) ne '') {
13803: unless (grep(/^\Q$server\E$/,@okoffload)) {
13804: push(@okoffload,$server);
13805: }
13806: }
13807: }
13808: if (@okoffload) {
13809: foreach my $lonhost (@okoffload) {
13810: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13811: }
13812: }
13813: }
1.145 raeburn 13814: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13815: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13816: if (ref($changes{'spares'}) eq 'HASH') {
13817: if (keys(%{$changes{'spares'}}) > 0) {
13818: $savespares = 1;
13819: }
13820: }
13821: } else {
13822: $savespares = 1;
13823: }
1.261 raeburn 13824: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13825: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13826: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13827: $changes{'offloadnow'} = 1;
13828: last;
13829: }
13830: }
13831: unless ($changes{'offloadnow'}) {
1.289 raeburn 13832: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261 raeburn 13833: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13834: $changes{'offloadnow'} = 1;
13835: last;
13836: }
13837: }
13838: }
13839: } elsif (@okoffload) {
13840: $changes{'offloadnow'} = 1;
13841: }
13842: } elsif (@okoffload) {
13843: $changes{'offloadnow'} = 1;
1.145 raeburn 13844: }
1.147 raeburn 13845: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13846: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13847: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13848: $dom);
13849: if ($putresult eq 'ok') {
13850: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13851: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13852: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13853: }
13854: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13855: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13856: }
1.261 raeburn 13857: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13858: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13859: }
1.137 raeburn 13860: }
13861: my $cachetime = 24*60*60;
13862: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 13863: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 13864: if (ref($lastactref) eq 'HASH') {
13865: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 13866: $lastactref->{'usersessions'} = 1;
1.212 raeburn 13867: }
1.147 raeburn 13868: if (keys(%changes) > 0) {
13869: my %lt = &usersession_titles();
13870: $resulttext = &mt('Changes made:').'<ul>';
13871: foreach my $prefix (@prefixes) {
13872: if (ref($changes{$prefix}) eq 'HASH') {
13873: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13874: if ($prefix eq 'spares') {
13875: if (ref($changes{$prefix}) eq 'HASH') {
13876: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13877: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13878: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 13879: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13880: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13881: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13882: foreach my $type (@{$types{$prefix}}) {
13883: if ($changes{$prefix}{$lonhost}{$type}) {
13884: my $offloadto = &mt('None');
13885: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13886: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13887: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13888: }
1.145 raeburn 13889: }
1.147 raeburn 13890: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13891: }
1.137 raeburn 13892: }
13893: }
1.147 raeburn 13894: $resulttext .= '</li>';
1.137 raeburn 13895: }
13896: }
1.147 raeburn 13897: } else {
13898: foreach my $type (@{$types{$prefix}}) {
13899: if (defined($changes{$prefix}{$type})) {
13900: my $newvalue;
13901: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13902: if (ref($defaultshash{'usersessions'}{$prefix})) {
13903: if ($type eq 'version') {
13904: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13905: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13906: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13907: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13908: }
1.145 raeburn 13909: }
13910: }
13911: }
1.147 raeburn 13912: if ($newvalue eq '') {
13913: if ($type eq 'version') {
13914: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13915: } else {
13916: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13917: }
1.145 raeburn 13918: } else {
1.147 raeburn 13919: if ($type eq 'version') {
13920: $newvalue .= ' '.&mt('(or later)');
13921: }
13922: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13923: }
1.137 raeburn 13924: }
13925: }
13926: }
1.147 raeburn 13927: $resulttext .= '</ul>';
1.137 raeburn 13928: }
13929: }
1.261 raeburn 13930: if ($changes{'offloadnow'}) {
13931: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13932: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13933: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13934: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13935: $resulttext .= '<li>'.$lonhost.'</li>';
13936: }
13937: $resulttext .= '</ul>';
13938: } else {
13939: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13940: }
13941: } else {
13942: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13943: }
13944: }
1.147 raeburn 13945: $resulttext .= '</ul>';
13946: } else {
13947: $resulttext = $nochgmsg;
1.137 raeburn 13948: }
13949: } else {
13950: $resulttext = '<span class="LC_error">'.
13951: &mt('An error occurred: [_1]',$putresult).'</span>';
13952: }
13953: } else {
1.147 raeburn 13954: $resulttext = $nochgmsg;
1.137 raeburn 13955: }
13956: return $resulttext;
13957: }
13958:
1.275 raeburn 13959: sub modify_ssl {
13960: my ($dom,$lastactref,%domconfig) = @_;
13961: my (%by_ip,%by_location,@intdoms,@instdoms);
13962: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
13963: my @locations = sort(keys(%by_location));
13964: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13965: my (%defaultshash,%changes);
13966: my $action = 'ssl';
1.293 raeburn 13967: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 13968: foreach my $prefix (@prefixes) {
13969: $defaultshash{$action}{$prefix} = {};
13970: }
13971: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13972: my $resulttext;
13973: my %iphost = &Apache::lonnet::get_iphost();
13974: my @reptypes = ('certreq','nocertreq');
13975: my @connecttypes = ('dom','intdom','other');
13976: my %types = (
1.293 raeburn 13977: connto => \@connecttypes,
13978: connfrom => \@connecttypes,
13979: replication => \@reptypes,
1.275 raeburn 13980: );
13981: foreach my $prefix (sort(keys(%types))) {
13982: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 13983: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 13984: my $value = 'yes';
13985: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
13986: $value = $env{'form.'.$prefix.'_'.$type};
13987: }
13988: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
13989: if ($domconfig{$action}{$prefix}{$type} ne '') {
13990: if ($value ne $domconfig{$action}{$prefix}{$type}) {
13991: $changes{$prefix}{$type} = 1;
13992: }
13993: $defaultshash{$action}{$prefix}{$type} = $value;
13994: } else {
13995: $defaultshash{$action}{$prefix}{$type} = $value;
13996: $changes{$prefix}{$type} = 1;
13997: }
13998: } else {
13999: $defaultshash{$action}{$prefix}{$type} = $value;
14000: $changes{$prefix}{$type} = 1;
14001: }
14002: if (($type eq 'dom') && (keys(%servers) == 1)) {
14003: delete($changes{$prefix}{$type});
14004: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
14005: delete($changes{$prefix}{$type});
14006: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
14007: delete($changes{$prefix}{$type});
14008: }
14009: } elsif ($prefix eq 'replication') {
14010: if (@locations > 0) {
14011: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14012: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14013: my @okvals;
14014: foreach my $val (@vals) {
14015: if ($val =~ /:/) {
14016: my @items = split(/:/,$val);
14017: foreach my $item (@items) {
14018: if (ref($by_location{$item}) eq 'ARRAY') {
14019: push(@okvals,$item);
14020: }
14021: }
14022: } else {
14023: if (ref($by_location{$val}) eq 'ARRAY') {
14024: push(@okvals,$val);
14025: }
14026: }
14027: }
14028: @okvals = sort(@okvals);
14029: if (ref($domconfig{$action}) eq 'HASH') {
14030: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
14031: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
14032: if ($inuse == 0) {
14033: $changes{$prefix}{$type} = 1;
14034: } else {
14035: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14036: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
14037: if (@changed > 0) {
14038: $changes{$prefix}{$type} = 1;
14039: }
14040: }
14041: } else {
14042: if ($inuse == 1) {
14043: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14044: $changes{$prefix}{$type} = 1;
14045: }
14046: }
14047: } else {
14048: if ($inuse == 1) {
14049: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14050: $changes{$prefix}{$type} = 1;
14051: }
14052: }
14053: } else {
14054: if ($inuse == 1) {
14055: $defaultshash{$action}{$prefix}{$type} = \@okvals;
14056: $changes{$prefix}{$type} = 1;
14057: }
14058: }
14059: }
14060: }
14061: }
14062: }
14063: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
14064: if (keys(%changes) > 0) {
14065: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14066: $dom);
14067: if ($putresult eq 'ok') {
14068: if (ref($defaultshash{$action}) eq 'HASH') {
14069: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
14070: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
14071: }
1.293 raeburn 14072: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
14073: $domdefaults{'connto'} = $domconfig{$action}{'connto'};
14074: }
14075: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
14076: $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};
1.275 raeburn 14077: }
14078: }
14079: my $cachetime = 24*60*60;
14080: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14081: if (ref($lastactref) eq 'HASH') {
14082: $lastactref->{'domdefaults'} = 1;
14083: }
14084: if (keys(%changes) > 0) {
14085: my %titles = &ssl_titles();
14086: $resulttext = &mt('Changes made:').'<ul>';
14087: foreach my $prefix (@prefixes) {
14088: if (ref($changes{$prefix}) eq 'HASH') {
14089: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
14090: foreach my $type (@{$types{$prefix}}) {
14091: if (defined($changes{$prefix}{$type})) {
14092: my $newvalue;
14093: if (ref($defaultshash{$action}) eq 'HASH') {
14094: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 14095: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 14096: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
14097: } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
14098: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
14099: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
14100: }
14101: }
14102: }
14103: if ($newvalue eq '') {
14104: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
14105: } else {
14106: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
14107: }
14108: }
14109: }
14110: }
14111: $resulttext .= '</ul>';
14112: }
14113: }
14114: } else {
14115: $resulttext = $nochgmsg;
14116: }
14117: } else {
14118: $resulttext = '<span class="LC_error">'.
14119: &mt('An error occurred: [_1]',$putresult).'</span>';
14120: }
14121: } else {
14122: $resulttext = $nochgmsg;
14123: }
14124: return $resulttext;
14125: }
14126:
1.279 raeburn 14127: sub modify_trust {
14128: my ($dom,$lastactref,%domconfig) = @_;
14129: my (%by_ip,%by_location,@intdoms,@instdoms);
14130: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
14131: my @locations = sort(keys(%by_location));
14132: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
14133: my @types = ('exc','inc');
14134: my (%defaultshash,%changes);
14135: foreach my $prefix (@prefixes) {
14136: $defaultshash{'trust'}{$prefix} = {};
14137: }
14138: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14139: my $resulttext;
14140: foreach my $prefix (@prefixes) {
14141: foreach my $type (@types) {
14142: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
14143: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
14144: my @okvals;
14145: foreach my $val (@vals) {
14146: if ($val =~ /:/) {
14147: my @items = split(/:/,$val);
14148: foreach my $item (@items) {
14149: if (ref($by_location{$item}) eq 'ARRAY') {
14150: push(@okvals,$item);
14151: }
14152: }
14153: } else {
14154: if (ref($by_location{$val}) eq 'ARRAY') {
14155: push(@okvals,$val);
14156: }
14157: }
14158: }
14159: @okvals = sort(@okvals);
14160: if (ref($domconfig{'trust'}) eq 'HASH') {
14161: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
14162: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14163: if ($inuse == 0) {
14164: $changes{$prefix}{$type} = 1;
14165: } else {
14166: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14167: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
14168: if (@changed > 0) {
14169: $changes{$prefix}{$type} = 1;
14170: }
14171: }
14172: } else {
14173: if ($inuse == 1) {
14174: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14175: $changes{$prefix}{$type} = 1;
14176: }
14177: }
14178: } else {
14179: if ($inuse == 1) {
14180: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14181: $changes{$prefix}{$type} = 1;
14182: }
14183: }
14184: } else {
14185: if ($inuse == 1) {
14186: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
14187: $changes{$prefix}{$type} = 1;
14188: }
14189: }
14190: }
14191: }
14192: my $nochgmsg = &mt('No changes made to trust settings.');
14193: if (keys(%changes) > 0) {
14194: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
14195: $dom);
14196: if ($putresult eq 'ok') {
14197: if (ref($defaultshash{'trust'}) eq 'HASH') {
14198: foreach my $prefix (@prefixes) {
14199: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
14200: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
14201: }
14202: }
14203: }
14204: my $cachetime = 24*60*60;
14205: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14206: if (ref($lastactref) eq 'HASH') {
14207: $lastactref->{'domdefaults'} = 1;
14208: }
14209: if (keys(%changes) > 0) {
14210: my %lt = &trust_titles();
14211: $resulttext = &mt('Changes made:').'<ul>';
14212: foreach my $prefix (@prefixes) {
14213: if (ref($changes{$prefix}) eq 'HASH') {
14214: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
14215: foreach my $type (@types) {
14216: if (defined($changes{$prefix}{$type})) {
14217: my $newvalue;
14218: if (ref($defaultshash{'trust'}) eq 'HASH') {
14219: if (ref($defaultshash{'trust'}{$prefix})) {
14220: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
14221: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
14222: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
14223: }
14224: }
14225: }
14226: }
14227: if ($newvalue eq '') {
14228: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
14229: } else {
14230: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
14231: }
14232: }
14233: }
14234: $resulttext .= '</ul>';
14235: }
14236: }
14237: $resulttext .= '</ul>';
14238: } else {
14239: $resulttext = $nochgmsg;
14240: }
14241: } else {
14242: $resulttext = '<span class="LC_error">'.
14243: &mt('An error occurred: [_1]',$putresult).'</span>';
14244: }
14245: } else {
14246: $resulttext = $nochgmsg;
14247: }
14248: return $resulttext;
14249: }
14250:
1.150 raeburn 14251: sub modify_loadbalancing {
14252: my ($dom,%domconfig) = @_;
14253: my $primary_id = &Apache::lonnet::domain($dom,'primary');
14254: my $intdom = &Apache::lonnet::internet_dom($primary_id);
14255: my ($othertitle,$usertypes,$types) =
14256: &Apache::loncommon::sorted_inst_types($dom);
14257: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 14258: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 14259: my @sparestypes = ('primary','default');
14260: my %typetitles = &sparestype_titles();
14261: my $resulttext;
1.171 raeburn 14262: my (%currbalancer,%currtargets,%currrules,%existing);
14263: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14264: %existing = %{$domconfig{'loadbalancing'}};
14265: }
14266: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
14267: \%currtargets,\%currrules);
14268: my ($saveloadbalancing,%defaultshash,%changes);
14269: my ($alltypes,$othertypes,$titles) =
14270: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
14271: my %ruletitles = &offloadtype_text();
14272: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
14273: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
14274: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
14275: if ($balancer eq '') {
14276: next;
14277: }
1.210 raeburn 14278: if (!exists($servers{$balancer})) {
1.171 raeburn 14279: if (exists($currbalancer{$balancer})) {
14280: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 14281: }
1.171 raeburn 14282: next;
14283: }
14284: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
14285: push(@{$changes{'delete'}},$balancer);
14286: next;
14287: }
14288: if (!exists($currbalancer{$balancer})) {
14289: push(@{$changes{'add'}},$balancer);
14290: }
14291: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
14292: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
14293: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
14294: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
14295: $saveloadbalancing = 1;
14296: }
14297: foreach my $sparetype (@sparestypes) {
14298: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
14299: my @offloadto;
14300: foreach my $target (@targets) {
14301: if (($servers{$target}) && ($target ne $balancer)) {
14302: if ($sparetype eq 'default') {
14303: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
14304: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 14305: }
14306: }
1.171 raeburn 14307: unless(grep(/^\Q$target\E$/,@offloadto)) {
14308: push(@offloadto,$target);
14309: }
1.150 raeburn 14310: }
14311: }
1.284 raeburn 14312: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
14313: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
14314: push(@offloadto,$balancer);
14315: }
14316: }
14317: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 14318: }
1.171 raeburn 14319: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 14320: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14321: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
14322: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 14323: if (@targetdiffs > 0) {
1.171 raeburn 14324: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14325: }
1.171 raeburn 14326: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14327: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14328: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 14329: }
14330: }
14331: }
14332: } else {
1.171 raeburn 14333: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 14334: foreach my $sparetype (@sparestypes) {
1.171 raeburn 14335: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14336: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14337: $changes{'curr'}{$balancer}{'targets'} = 1;
14338: }
1.150 raeburn 14339: }
14340: }
1.210 raeburn 14341: }
1.150 raeburn 14342: }
14343: my $ishomedom;
1.171 raeburn 14344: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
14345: $ishomedom = 1;
1.150 raeburn 14346: }
14347: if (ref($alltypes) eq 'ARRAY') {
14348: foreach my $type (@{$alltypes}) {
14349: my $rule;
1.210 raeburn 14350: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 14351: (!$ishomedom)) {
1.171 raeburn 14352: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
14353: }
14354: if ($rule eq 'specific') {
1.255 raeburn 14355: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 14356: if (exists($servers{$specifiedhost})) {
1.255 raeburn 14357: $rule = $specifiedhost;
14358: }
1.150 raeburn 14359: }
1.171 raeburn 14360: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
14361: if (ref($currrules{$balancer}) eq 'HASH') {
14362: if ($rule ne $currrules{$balancer}{$type}) {
14363: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14364: }
14365: } elsif ($rule ne '') {
1.171 raeburn 14366: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 14367: }
14368: }
14369: }
1.171 raeburn 14370: }
14371: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
14372: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
14373: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
14374: $defaultshash{'loadbalancing'} = {};
14375: }
14376: my $putresult = &Apache::lonnet::put_dom('configuration',
14377: \%defaultshash,$dom);
14378: if ($putresult eq 'ok') {
14379: if (keys(%changes) > 0) {
1.252 raeburn 14380: my %toupdate;
1.171 raeburn 14381: if (ref($changes{'delete'}) eq 'ARRAY') {
14382: foreach my $balancer (sort(@{$changes{'delete'}})) {
14383: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 14384: $toupdate{$balancer} = 1;
1.150 raeburn 14385: }
1.171 raeburn 14386: }
14387: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 14388: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 14389: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 14390: $toupdate{$balancer} = 1;
1.171 raeburn 14391: }
14392: }
14393: if (ref($changes{'curr'}) eq 'HASH') {
14394: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 14395: $toupdate{$balancer} = 1;
1.171 raeburn 14396: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
14397: if ($changes{'curr'}{$balancer}{'targets'}) {
14398: my %offloadstr;
14399: foreach my $sparetype (@sparestypes) {
14400: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14401: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
14402: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14403: }
14404: }
1.150 raeburn 14405: }
1.171 raeburn 14406: if (keys(%offloadstr) == 0) {
14407: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 14408: } else {
1.171 raeburn 14409: my $showoffload;
14410: foreach my $sparetype (@sparestypes) {
14411: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
14412: if (defined($offloadstr{$sparetype})) {
14413: $showoffload .= $offloadstr{$sparetype};
14414: } else {
14415: $showoffload .= &mt('None');
14416: }
14417: $showoffload .= (' 'x3);
14418: }
14419: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 14420: }
14421: }
14422: }
1.171 raeburn 14423: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
14424: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
14425: foreach my $type (@{$alltypes}) {
14426: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
14427: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14428: my $balancetext;
14429: if ($rule eq '') {
14430: $balancetext = $ruletitles{'default'};
1.209 raeburn 14431: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 14432: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 14433: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 14434: foreach my $sparetype (@sparestypes) {
14435: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
14436: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
14437: }
14438: }
1.253 raeburn 14439: foreach my $item (@{$alltypes}) {
14440: next if ($item =~ /^_LC_ipchange/);
14441: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
14442: if ($hasrule eq 'homeserver') {
14443: map { $toupdate{$_} = 1; } (keys(%libraryservers));
14444: } else {
14445: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
14446: if ($servers{$hasrule}) {
14447: $toupdate{$hasrule} = 1;
14448: }
14449: }
14450: }
14451: }
1.254 raeburn 14452: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
14453: $balancetext = $ruletitles{$rule};
14454: } else {
14455: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
14456: $balancetext = $ruletitles{'particular'}.' '.$receiver;
14457: if ($receiver) {
14458: $toupdate{$receiver};
14459: }
14460: }
14461: } else {
14462: $balancetext = $ruletitles{$rule};
1.252 raeburn 14463: }
1.171 raeburn 14464: } else {
14465: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
14466: }
1.210 raeburn 14467: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 14468: }
14469: }
14470: }
14471: }
1.252 raeburn 14472: if (keys(%toupdate)) {
14473: my %thismachine;
14474: my $updatedhere;
14475: my $cachetime = 60*60*24;
14476: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
14477: foreach my $lonhost (keys(%toupdate)) {
14478: if ($thismachine{$lonhost}) {
14479: unless ($updatedhere) {
14480: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
14481: $defaultshash{'loadbalancing'},
14482: $cachetime);
14483: $updatedhere = 1;
14484: }
14485: } else {
14486: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
14487: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
14488: }
14489: }
14490: }
1.150 raeburn 14491: }
1.171 raeburn 14492: }
14493: if ($resulttext ne '') {
14494: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 14495: } else {
14496: $resulttext = $nochgmsg;
14497: }
14498: } else {
1.171 raeburn 14499: $resulttext = $nochgmsg;
1.150 raeburn 14500: }
14501: } else {
1.171 raeburn 14502: $resulttext = '<span class="LC_error">'.
14503: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 14504: }
14505: } else {
1.171 raeburn 14506: $resulttext = $nochgmsg;
1.150 raeburn 14507: }
14508: return $resulttext;
14509: }
14510:
1.48 raeburn 14511: sub recurse_check {
14512: my ($chkcats,$categories,$depth,$name) = @_;
14513: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
14514: my $chg = 0;
14515: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
14516: my $category = $chkcats->[$depth]{$name}[$j];
14517: my $item;
14518: if ($category eq '') {
14519: $chg ++;
14520: } else {
14521: my $deeper = $depth + 1;
14522: $item = &escape($category).':'.&escape($name).':'.$depth;
14523: if ($chg) {
14524: $categories->{$item} -= $chg;
14525: }
14526: &recurse_check($chkcats,$categories,$deeper,$category);
14527: $deeper --;
14528: }
14529: }
14530: }
14531: return;
14532: }
14533:
14534: sub recurse_cat_deletes {
14535: my ($item,$coursecategories,$deletions) = @_;
14536: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14537: my $subdepth = $depth + 1;
14538: if (ref($coursecategories) eq 'HASH') {
14539: foreach my $subitem (keys(%{$coursecategories})) {
14540: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
14541: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
14542: delete($coursecategories->{$subitem});
14543: $deletions->{$subitem} = 1;
14544: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 14545: }
1.48 raeburn 14546: }
14547: }
14548: return;
14549: }
14550:
1.125 raeburn 14551: sub active_dc_picker {
1.191 raeburn 14552: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 14553: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 14554: my @domcoord = keys(%domcoords);
14555: if (keys(%currhash)) {
14556: foreach my $dc (keys(%currhash)) {
14557: unless (exists($domcoords{$dc})) {
14558: push(@domcoord,$dc);
14559: }
14560: }
14561: }
14562: @domcoord = sort(@domcoord);
1.210 raeburn 14563: my $numdcs = scalar(@domcoord);
1.191 raeburn 14564: my $rows = 0;
14565: my $table;
1.125 raeburn 14566: if ($numdcs > 1) {
1.191 raeburn 14567: $table = '<table>';
14568: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 14569: my $rem = $i%($numinrow);
14570: if ($rem == 0) {
14571: if ($i > 0) {
1.191 raeburn 14572: $table .= '</tr>';
1.125 raeburn 14573: }
1.191 raeburn 14574: $table .= '<tr>';
14575: $rows ++;
1.125 raeburn 14576: }
1.191 raeburn 14577: my $check = '';
14578: if ($inputtype eq 'radio') {
14579: if (keys(%currhash) == 0) {
14580: if (!$i) {
14581: $check = ' checked="checked"';
14582: }
14583: } elsif (exists($currhash{$domcoord[$i]})) {
14584: $check = ' checked="checked"';
14585: }
14586: } else {
14587: if (exists($currhash{$domcoord[$i]})) {
14588: $check = ' checked="checked"';
1.125 raeburn 14589: }
14590: }
1.191 raeburn 14591: if ($i == @domcoord - 1) {
1.125 raeburn 14592: my $colsleft = $numinrow - $rem;
14593: if ($colsleft > 1) {
1.191 raeburn 14594: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 14595: } else {
1.191 raeburn 14596: $table .= '<td class="LC_left_item">';
1.125 raeburn 14597: }
14598: } else {
1.191 raeburn 14599: $table .= '<td class="LC_left_item">';
14600: }
14601: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
14602: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
14603: $table .= '<span class="LC_nobreak"><label>'.
14604: '<input type="'.$inputtype.'" name="'.$name.'"'.
14605: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
14606: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 14607: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 14608: }
1.219 raeburn 14609: $table .= '</label></span></td>';
1.191 raeburn 14610: }
14611: $table .= '</tr></table>';
14612: } elsif ($numdcs == 1) {
1.219 raeburn 14613: my ($dcname,$dcdom) = split(':',$domcoord[0]);
14614: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 14615: if ($inputtype eq 'radio') {
1.247 raeburn 14616: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 14617: if ($user ne $dcname.':'.$dcdom) {
14618: $table .= ' ('.$dcname.':'.$dcdom.')';
14619: }
1.191 raeburn 14620: } else {
14621: my $check;
14622: if (exists($currhash{$domcoord[0]})) {
14623: $check = ' checked="checked"';
1.125 raeburn 14624: }
1.247 raeburn 14625: $table = '<span class="LC_nobreak"><label>'.
14626: '<input type="checkbox" name="'.$name.'" '.
14627: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 14628: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 14629: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 14630: }
1.220 raeburn 14631: $table .= '</label></span>';
1.191 raeburn 14632: $rows ++;
1.125 raeburn 14633: }
14634: }
1.191 raeburn 14635: return ($numdcs,$table,$rows);
1.125 raeburn 14636: }
14637:
1.137 raeburn 14638: sub usersession_titles {
14639: return &Apache::lonlocal::texthash(
14640: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
14641: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 14642: spares => 'Servers offloaded to, when busy',
1.137 raeburn 14643: version => 'LON-CAPA version requirement',
1.138 raeburn 14644: excludedomain => 'Allow all, but exclude specific domains',
14645: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 14646: primary => 'Primary (checked first)',
1.154 raeburn 14647: default => 'Default',
1.137 raeburn 14648: );
14649: }
14650:
1.152 raeburn 14651: sub id_for_thisdom {
14652: my (%servers) = @_;
14653: my %altids;
14654: foreach my $server (keys(%servers)) {
14655: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
14656: if ($serverhome ne $server) {
14657: $altids{$serverhome} = $server;
14658: }
14659: }
14660: return %altids;
14661: }
14662:
1.150 raeburn 14663: sub count_servers {
14664: my ($currbalancer,%servers) = @_;
14665: my (@spares,$numspares);
14666: foreach my $lonhost (sort(keys(%servers))) {
14667: next if ($currbalancer eq $lonhost);
14668: push(@spares,$lonhost);
14669: }
14670: if ($currbalancer) {
14671: $numspares = scalar(@spares);
14672: } else {
14673: $numspares = scalar(@spares) - 1;
14674: }
14675: return ($numspares,@spares);
14676: }
14677:
14678: sub lonbalance_targets_js {
1.171 raeburn 14679: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 14680: my $select = &mt('Select');
14681: my ($alltargets,$allishome,$allinsttypes,@alltypes);
14682: if (ref($servers) eq 'HASH') {
14683: $alltargets = join("','",sort(keys(%{$servers})));
14684: my @homedoms;
14685: foreach my $server (sort(keys(%{$servers}))) {
14686: if (&Apache::lonnet::host_domain($server) eq $dom) {
14687: push(@homedoms,'1');
14688: } else {
14689: push(@homedoms,'0');
14690: }
14691: }
14692: $allishome = join("','",@homedoms);
14693: }
14694: if (ref($types) eq 'ARRAY') {
14695: if (@{$types} > 0) {
14696: @alltypes = @{$types};
14697: }
14698: }
14699: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
14700: $allinsttypes = join("','",@alltypes);
1.171 raeburn 14701: my (%currbalancer,%currtargets,%currrules,%existing);
14702: if (ref($settings) eq 'HASH') {
14703: %existing = %{$settings};
14704: }
14705: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
14706: \%currtargets,\%currrules);
1.210 raeburn 14707: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 14708: return <<"END";
14709:
14710: <script type="text/javascript">
14711: // <![CDATA[
14712:
1.171 raeburn 14713: currBalancers = new Array('$balancers');
14714:
14715: function toggleTargets(balnum) {
14716: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14717: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14718: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14719: var prevbalancer = prevhostitem.value;
14720: var baltotal = document.getElementById('loadbalancing_total').value;
14721: prevhostitem.value = balancer;
14722: if (prevbalancer != '') {
14723: var prevIdx = currBalancers.indexOf(prevbalancer);
14724: if (prevIdx != -1) {
14725: currBalancers.splice(prevIdx,1);
14726: }
14727: }
1.150 raeburn 14728: if (balancer == '') {
1.171 raeburn 14729: hideSpares(balnum);
1.150 raeburn 14730: } else {
1.171 raeburn 14731: var currIdx = currBalancers.indexOf(balancer);
14732: if (currIdx == -1) {
14733: currBalancers.push(balancer);
14734: }
1.150 raeburn 14735: var homedoms = new Array('$allishome');
1.171 raeburn 14736: var ishomedom = homedoms[lonhostitem.selectedIndex];
14737: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14738: }
1.171 raeburn 14739: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14740: return;
14741: }
14742:
1.171 raeburn 14743: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14744: var alltargets = new Array('$alltargets');
14745: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14746: var offloadtypes = new Array('primary','default');
14747:
1.171 raeburn 14748: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14749: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14750:
1.151 raeburn 14751: for (var i=0; i<offloadtypes.length; i++) {
14752: var count = 0;
14753: for (var j=0; j<alltargets.length; j++) {
14754: if (alltargets[j] != balancer) {
1.171 raeburn 14755: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14756: item.value = alltargets[j];
14757: item.style.textAlign='left';
14758: item.style.textFace='normal';
14759: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14760: if (currBalancers.indexOf(alltargets[j]) == -1) {
14761: item.disabled = '';
14762: } else {
14763: item.disabled = 'disabled';
14764: item.checked = false;
14765: }
1.151 raeburn 14766: count ++;
14767: }
1.150 raeburn 14768: }
14769: }
1.151 raeburn 14770: for (var k=0; k<insttypes.length; k++) {
14771: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14772: if (ishomedom == 1) {
1.171 raeburn 14773: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14774: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14775: } else {
1.171 raeburn 14776: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14777: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14778: }
14779: } else {
1.171 raeburn 14780: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14781: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14782: }
1.151 raeburn 14783: if ((insttypes[k] != '_LC_external') &&
14784: ((insttypes[k] != '_LC_internetdom') ||
14785: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 14786: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14787: item.options.length = 0;
14788: item.options[0] = new Option("","",true,true);
1.210 raeburn 14789: var idx = 0;
1.151 raeburn 14790: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 14791: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14792: idx ++;
14793: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14794: }
14795: }
14796: }
14797: }
14798: return;
14799: }
14800:
1.171 raeburn 14801: function hideSpares(balnum) {
1.150 raeburn 14802: var alltargets = new Array('$alltargets');
14803: var insttypes = new Array('$allinsttypes');
14804: var offloadtypes = new Array('primary','default');
14805:
1.171 raeburn 14806: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14807: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14808:
14809: var total = alltargets.length - 1;
14810: for (var i=0; i<offloadtypes; i++) {
14811: for (var j=0; j<total; j++) {
1.171 raeburn 14812: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14813: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14814: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14815: }
1.150 raeburn 14816: }
14817: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 14818: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14819: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14820: if (insttypes[k] != '_LC_external') {
1.171 raeburn 14821: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14822: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14823: }
14824: }
14825: return;
14826: }
14827:
1.171 raeburn 14828: function checkOffloads(item,balnum,type) {
1.150 raeburn 14829: var alltargets = new Array('$alltargets');
14830: var offloadtypes = new Array('primary','default');
14831: if (item.checked) {
14832: var total = alltargets.length - 1;
14833: var other;
14834: if (type == offloadtypes[0]) {
1.151 raeburn 14835: other = offloadtypes[1];
1.150 raeburn 14836: } else {
1.151 raeburn 14837: other = offloadtypes[0];
1.150 raeburn 14838: }
14839: for (var i=0; i<total; i++) {
1.171 raeburn 14840: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14841: if (server == item.value) {
1.171 raeburn 14842: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14843: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14844: }
14845: }
14846: }
14847: }
14848: return;
14849: }
14850:
1.171 raeburn 14851: function singleServerToggle(balnum,type) {
14852: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 14853: if (offloadtoSelIdx == 0) {
1.171 raeburn 14854: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14855: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14856:
14857: } else {
1.171 raeburn 14858: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14859: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 14860: }
14861: return;
14862: }
14863:
1.171 raeburn 14864: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 14865: if (type == '_LC_external') {
1.171 raeburn 14866: return;
1.150 raeburn 14867: }
1.171 raeburn 14868: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 14869: for (var i=0; i<typesRules.length; i++) {
14870: if (formname.elements[typesRules[i]].checked) {
14871: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 14872: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14873: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14874: } else {
1.171 raeburn 14875: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14876: }
14877: }
14878: }
14879: return;
14880: }
14881:
14882: function balancerDeleteChange(balnum) {
14883: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14884: var baltotal = document.getElementById('loadbalancing_total').value;
14885: var addtarget;
14886: var removetarget;
14887: var action = 'delete';
14888: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14889: var lonhost = hostitem.value;
14890: var currIdx = currBalancers.indexOf(lonhost);
14891: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14892: if (currIdx != -1) {
14893: currBalancers.splice(currIdx,1);
14894: }
14895: addtarget = lonhost;
14896: } else {
14897: if (currIdx == -1) {
14898: currBalancers.push(lonhost);
14899: }
14900: removetarget = lonhost;
14901: action = 'undelete';
14902: }
14903: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14904: }
14905: return;
14906: }
14907:
14908: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14909: if (baltotal > 1) {
14910: var offloadtypes = new Array('primary','default');
14911: var alltargets = new Array('$alltargets');
14912: var insttypes = new Array('$allinsttypes');
14913: for (var i=0; i<baltotal; i++) {
14914: if (i != balnum) {
14915: for (var j=0; j<offloadtypes.length; j++) {
14916: var total = alltargets.length - 1;
14917: for (var k=0; k<total; k++) {
14918: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14919: var server = serveritem.value;
14920: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14921: if (server == addtarget) {
14922: serveritem.disabled = '';
14923: }
14924: }
14925: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14926: if (server == removetarget) {
14927: serveritem.disabled = 'disabled';
14928: serveritem.checked = false;
14929: }
14930: }
14931: }
14932: }
14933: for (var j=0; j<insttypes.length; j++) {
14934: if (insttypes[j] != '_LC_external') {
14935: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14936: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14937: var currSel = singleserver.selectedIndex;
14938: var currVal = singleserver.options[currSel].value;
14939: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14940: var numoptions = singleserver.options.length;
14941: var needsnew = 1;
14942: for (var k=0; k<numoptions; k++) {
14943: if (singleserver.options[k] == addtarget) {
14944: needsnew = 0;
14945: break;
14946: }
14947: }
14948: if (needsnew == 1) {
14949: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14950: }
14951: }
14952: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14953: singleserver.options.length = 0;
14954: if ((currVal) && (currVal != removetarget)) {
14955: singleserver.options[0] = new Option("","",false,false);
14956: } else {
14957: singleserver.options[0] = new Option("","",true,true);
14958: }
14959: var idx = 0;
14960: for (var m=0; m<alltargets.length; m++) {
14961: if (currBalancers.indexOf(alltargets[m]) == -1) {
14962: idx ++;
14963: if (currVal == alltargets[m]) {
14964: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
14965: } else {
14966: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
14967: }
14968: }
14969: }
14970: }
14971: }
14972: }
14973: }
1.150 raeburn 14974: }
14975: }
14976: }
14977: return;
14978: }
14979:
1.152 raeburn 14980: // ]]>
14981: </script>
14982:
14983: END
14984: }
14985:
14986: sub new_spares_js {
14987: my @sparestypes = ('primary','default');
14988: my $types = join("','",@sparestypes);
14989: my $select = &mt('Select');
14990: return <<"END";
14991:
14992: <script type="text/javascript">
14993: // <![CDATA[
14994:
14995: function updateNewSpares(formname,lonhost) {
14996: var types = new Array('$types');
14997: var include = new Array();
14998: var exclude = new Array();
14999: for (var i=0; i<types.length; i++) {
15000: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
15001: for (var j=0; j<spareboxes.length; j++) {
15002: if (formname.elements[spareboxes[j]].checked) {
15003: exclude.push(formname.elements[spareboxes[j]].value);
15004: } else {
15005: include.push(formname.elements[spareboxes[j]].value);
15006: }
15007: }
15008: }
15009: for (var i=0; i<types.length; i++) {
15010: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
15011: var selIdx = newSpare.selectedIndex;
15012: var currnew = newSpare.options[selIdx].value;
15013: var okSpares = new Array();
15014: for (var j=0; j<newSpare.options.length; j++) {
15015: var possible = newSpare.options[j].value;
15016: if (possible != '') {
15017: if (exclude.indexOf(possible) == -1) {
15018: okSpares.push(possible);
15019: } else {
15020: if (currnew == possible) {
15021: selIdx = 0;
15022: }
15023: }
15024: }
15025: }
15026: for (var k=0; k<include.length; k++) {
15027: if (okSpares.indexOf(include[k]) == -1) {
15028: okSpares.push(include[k]);
15029: }
15030: }
15031: okSpares.sort();
15032: newSpare.options.length = 0;
15033: if (selIdx == 0) {
15034: newSpare.options[0] = new Option("$select","",true,true);
15035: } else {
15036: newSpare.options[0] = new Option("$select","",false,false);
15037: }
15038: for (var m=0; m<okSpares.length; m++) {
15039: var idx = m+1;
15040: var selThis = 0;
15041: if (selIdx != 0) {
15042: if (okSpares[m] == currnew) {
15043: selThis = 1;
15044: }
15045: }
15046: if (selThis == 1) {
15047: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
15048: } else {
15049: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
15050: }
15051: }
15052: }
15053: return;
15054: }
15055:
15056: function checkNewSpares(lonhost,type) {
15057: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
15058: var chosen = newSpare.options[newSpare.selectedIndex].value;
15059: if (chosen != '') {
15060: var othertype;
15061: var othernewSpare;
15062: if (type == 'primary') {
15063: othernewSpare = document.getElementById('newspare_default_'+lonhost);
15064: }
15065: if (type == 'default') {
15066: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
15067: }
15068: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
15069: othernewSpare.selectedIndex = 0;
15070: }
15071: }
15072: return;
15073: }
15074:
15075: // ]]>
15076: </script>
15077:
15078: END
15079:
15080: }
15081:
15082: sub common_domprefs_js {
15083: return <<"END";
15084:
15085: <script type="text/javascript">
15086: // <![CDATA[
15087:
1.150 raeburn 15088: function getIndicesByName(formname,item) {
1.152 raeburn 15089: var group = new Array();
1.150 raeburn 15090: for (var i=0;i<formname.elements.length;i++) {
15091: if (formname.elements[i].name == item) {
1.152 raeburn 15092: group.push(formname.elements[i].id);
1.150 raeburn 15093: }
15094: }
1.152 raeburn 15095: return group;
1.150 raeburn 15096: }
15097:
15098: // ]]>
15099: </script>
15100:
15101: END
1.152 raeburn 15102:
1.150 raeburn 15103: }
15104:
1.165 raeburn 15105: sub recaptcha_js {
15106: my %lt = &captcha_phrases();
15107: return <<"END";
15108:
15109: <script type="text/javascript">
15110: // <![CDATA[
15111:
15112: function updateCaptcha(caller,context) {
15113: var privitem;
15114: var pubitem;
15115: var privtext;
15116: var pubtext;
1.269 raeburn 15117: var versionitem;
15118: var versiontext;
1.165 raeburn 15119: if (document.getElementById(context+'_recaptchapub')) {
15120: pubitem = document.getElementById(context+'_recaptchapub');
15121: } else {
15122: return;
15123: }
15124: if (document.getElementById(context+'_recaptchapriv')) {
15125: privitem = document.getElementById(context+'_recaptchapriv');
15126: } else {
15127: return;
15128: }
15129: if (document.getElementById(context+'_recaptchapubtxt')) {
15130: pubtext = document.getElementById(context+'_recaptchapubtxt');
15131: } else {
15132: return;
15133: }
15134: if (document.getElementById(context+'_recaptchaprivtxt')) {
15135: privtext = document.getElementById(context+'_recaptchaprivtxt');
15136: } else {
15137: return;
15138: }
1.269 raeburn 15139: if (document.getElementById(context+'_recaptchaversion')) {
15140: versionitem = document.getElementById(context+'_recaptchaversion');
15141: } else {
15142: return;
15143: }
15144: if (document.getElementById(context+'_recaptchavertxt')) {
15145: versiontext = document.getElementById(context+'_recaptchavertxt');
15146: } else {
15147: return;
15148: }
1.165 raeburn 15149: if (caller.checked) {
15150: if (caller.value == 'recaptcha') {
15151: pubitem.type = 'text';
15152: privitem.type = 'text';
15153: pubitem.size = '40';
15154: privitem.size = '40';
15155: pubtext.innerHTML = "$lt{'pub'}";
15156: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 15157: versionitem.type = 'text';
15158: versionitem.size = '3';
1.289 raeburn 15159: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 15160: } else {
15161: pubitem.type = 'hidden';
15162: privitem.type = 'hidden';
1.269 raeburn 15163: versionitem.type = 'hidden';
1.165 raeburn 15164: pubtext.innerHTML = '';
15165: privtext.innerHTML = '';
1.269 raeburn 15166: versiontext.innerHTML = '';
1.165 raeburn 15167: }
15168: }
15169: return;
15170: }
15171:
15172: // ]]>
15173: </script>
15174:
15175: END
15176:
15177: }
15178:
1.236 raeburn 15179: sub toggle_display_js {
1.192 raeburn 15180: return <<"END";
15181:
15182: <script type="text/javascript">
15183: // <![CDATA[
15184:
1.236 raeburn 15185: function toggleDisplay(domForm,caller) {
15186: if (document.getElementById(caller)) {
15187: var divitem = document.getElementById(caller);
15188: var optionsElement = domForm.coursecredits;
1.264 raeburn 15189: var checkval = 1;
15190: var dispval = 'block';
1.236 raeburn 15191: if (caller == 'emailoptions') {
15192: optionsElement = domForm.cancreate_email;
15193: }
1.257 raeburn 15194: if (caller == 'studentsubmission') {
15195: optionsElement = domForm.postsubmit;
15196: }
1.264 raeburn 15197: if (caller == 'cloneinstcode') {
15198: optionsElement = domForm.canclone;
15199: checkval = 'instcode';
15200: }
1.236 raeburn 15201: if (optionsElement.length) {
1.192 raeburn 15202: var currval;
1.236 raeburn 15203: for (var i=0; i<optionsElement.length; i++) {
15204: if (optionsElement[i].checked) {
15205: currval = optionsElement[i].value;
1.192 raeburn 15206: }
15207: }
1.264 raeburn 15208: if (currval == checkval) {
15209: divitem.style.display = dispval;
1.192 raeburn 15210: } else {
1.236 raeburn 15211: divitem.style.display = 'none';
1.192 raeburn 15212: }
15213: }
15214: }
15215: return;
15216: }
15217:
15218: // ]]>
15219: </script>
15220:
15221: END
15222:
15223: }
15224:
1.165 raeburn 15225: sub captcha_phrases {
15226: return &Apache::lonlocal::texthash (
15227: priv => 'Private key',
15228: pub => 'Public key',
15229: original => 'original (CAPTCHA)',
15230: recaptcha => 'successor (ReCAPTCHA)',
15231: notused => 'unused',
1.289 raeburn 15232: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 15233: );
15234: }
15235:
1.205 raeburn 15236: sub devalidate_remote_domconfs {
1.212 raeburn 15237: my ($dom,$cachekeys) = @_;
15238: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 15239: my %servers = &Apache::lonnet::internet_dom_servers($dom);
15240: my %thismachine;
15241: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.295 raeburn 15242: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.260 raeburn 15243: if (keys(%servers)) {
1.205 raeburn 15244: foreach my $server (keys(%servers)) {
15245: next if ($thismachine{$server});
1.212 raeburn 15246: my @cached;
15247: foreach my $name (@posscached) {
15248: if ($cachekeys->{$name}) {
15249: push(@cached,&escape($name).':'.&escape($dom));
15250: }
15251: }
15252: if (@cached) {
15253: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
15254: }
1.205 raeburn 15255: }
15256: }
15257: return;
15258: }
15259:
1.3 raeburn 15260: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>