Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.97
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.97! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.96 2019/08/03 16:17:39 raeburn Exp $
1.160.6.40 raeburn 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.160.6.78 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.160.6.13 raeburn 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.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 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.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 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.160.6.30 raeburn 107: (official, unofficial, community, and textbook). In each case the radio buttons
108: 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.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 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.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.1 raeburn 177:
1.155 raeburn 178: my $registered_cleanup;
179: my $modified_urls;
180:
1.1 raeburn 181: sub handler {
182: my $r=shift;
183: if ($r->header_only) {
184: &Apache::loncommon::content_type($r,'text/html');
185: $r->send_http_header;
186: return OK;
187: }
188:
1.91 raeburn 189: my $context = 'domain';
1.1 raeburn 190: my $dom = $env{'request.role.domain'};
1.5 albertel 191: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 192: if (&Apache::lonnet::allowed('mau',$dom)) {
193: &Apache::loncommon::content_type($r,'text/html');
194: $r->send_http_header;
195: } else {
196: $env{'user.error.msg'}=
197: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
198: return HTTP_NOT_ACCEPTABLE;
199: }
1.155 raeburn 200:
201: $registered_cleanup=0;
202: @{$modified_urls}=();
203:
1.1 raeburn 204: &Apache::lonhtmlcommon::clear_breadcrumbs();
205: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 206: ['phase','actions']);
1.30 raeburn 207: my $phase = 'pickactions';
1.3 raeburn 208: if ( exists($env{'form.phase'}) ) {
209: $phase = $env{'form.phase'};
210: }
1.150 raeburn 211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 212: my %domconfig =
1.6 raeburn 213: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 214: 'quotas','autoenroll','autoupdate','autocreate',
215: 'directorysrch','usercreation','usermodification',
216: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 217: 'serverstatuses','requestcourses','helpsettings',
218: 'coursedefaults','usersessions','loadbalancing',
219: 'requestauthor','selfenrollment','inststatus'],$dom);
1.43 raeburn 220: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 221: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 222: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 223: 'requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 224: 'serverstatuses','helpsettings','coursedefaults',
225: 'selfenrollment','usersessions');
1.160.6.7 raeburn 226: my %existing;
227: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
228: %existing = %{$domconfig{'loadbalancing'}};
229: }
230: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 231: push(@prefs_order,'loadbalancing');
232: }
1.30 raeburn 233: my %prefs = (
234: 'rolecolors' =>
235: { text => 'Default color schemes',
1.67 raeburn 236: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 237: header => [{col1 => 'Student Settings',
238: col2 => '',},
239: {col1 => 'Coordinator Settings',
240: col2 => '',},
241: {col1 => 'Author Settings',
242: col2 => '',},
243: {col1 => 'Administrator Settings',
244: col2 => '',}],
1.160.6.37 raeburn 245: print => \&print_rolecolors,
246: modify => \&modify_rolecolors,
1.30 raeburn 247: },
1.110 raeburn 248: 'login' =>
1.30 raeburn 249: { text => 'Log-in page options',
1.67 raeburn 250: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 251: header => [{col1 => 'Log-in Page Items',
252: col2 => '',},
253: {col1 => 'Log-in Help',
1.160.6.56 raeburn 254: col2 => 'Value'},
255: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 256: col2 => 'Value'}],
1.160.6.37 raeburn 257: print => \&print_login,
258: modify => \&modify_login,
1.30 raeburn 259: },
1.43 raeburn 260: 'defaults' =>
1.160.6.40 raeburn 261: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 262: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 263: header => [{col1 => 'Setting',
1.160.6.40 raeburn 264: col2 => 'Value'},
1.160.6.80 raeburn 265: {col1 => 'Internal Authentication',
266: col2 => 'Value'},
1.160.6.40 raeburn 267: {col1 => 'Institutional user types',
1.160.6.93 raeburn 268: col2 => 'Name displayed'}],
1.160.6.37 raeburn 269: print => \&print_defaults,
270: modify => \&modify_defaults,
1.43 raeburn 271: },
1.30 raeburn 272: 'quotas' =>
1.160.6.20 raeburn 273: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 274: help => 'Domain_Configuration_Quotas',
1.77 raeburn 275: header => [{col1 => 'User affiliation',
1.72 raeburn 276: col2 => 'Available tools',
1.160.6.28 raeburn 277: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 278: print => \&print_quotas,
279: modify => \&modify_quotas,
1.30 raeburn 280: },
281: 'autoenroll' =>
282: { text => 'Auto-enrollment settings',
1.67 raeburn 283: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 284: header => [{col1 => 'Configuration setting',
285: col2 => 'Value(s)'}],
1.160.6.37 raeburn 286: print => \&print_autoenroll,
287: modify => \&modify_autoenroll,
1.30 raeburn 288: },
289: 'autoupdate' =>
290: { text => 'Auto-update settings',
1.67 raeburn 291: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 292: header => [{col1 => 'Setting',
293: col2 => 'Value',},
1.131 raeburn 294: {col1 => 'Setting',
295: col2 => 'Affiliation'},
1.43 raeburn 296: {col1 => 'User population',
1.160.6.35 raeburn 297: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 298: print => \&print_autoupdate,
299: modify => \&modify_autoupdate,
1.30 raeburn 300: },
1.125 raeburn 301: 'autocreate' =>
302: { text => 'Auto-course creation settings',
303: help => 'Domain_Configuration_Auto_Creation',
304: header => [{col1 => 'Configuration Setting',
305: col2 => 'Value',}],
1.160.6.37 raeburn 306: print => \&print_autocreate,
307: modify => \&modify_autocreate,
1.125 raeburn 308: },
1.30 raeburn 309: 'directorysrch' =>
1.160.6.72 raeburn 310: { text => 'Directory searches',
1.67 raeburn 311: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 312: header => [{col1 => 'Institutional Directory Setting',
313: col2 => 'Value',},
314: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 315: col2 => 'Value',}],
1.160.6.37 raeburn 316: print => \&print_directorysrch,
317: modify => \&modify_directorysrch,
1.30 raeburn 318: },
319: 'contacts' =>
1.160.6.78 raeburn 320: { text => 'E-mail addresses and helpform',
1.67 raeburn 321: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 322: header => [{col1 => 'Default e-mail addresses',
323: col2 => 'Value',},
324: {col1 => 'Recipient(s) for notifications',
325: col2 => 'Value',},
326: {col1 => 'Ask helpdesk form settings',
327: col2 => 'Value',},],
1.160.6.37 raeburn 328: print => \&print_contacts,
329: modify => \&modify_contacts,
1.30 raeburn 330: },
331: 'usercreation' =>
332: { text => 'User creation',
1.67 raeburn 333: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 334: header => [{col1 => 'Format rule type',
335: col2 => 'Format rules in force'},
1.34 raeburn 336: {col1 => 'User account creation',
337: col2 => 'Usernames which may be created',},
1.30 raeburn 338: {col1 => 'Context',
1.43 raeburn 339: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 340: print => \&print_usercreation,
341: modify => \&modify_usercreation,
1.30 raeburn 342: },
1.160.6.34 raeburn 343: 'selfcreation' =>
344: { text => 'Users self-creating accounts',
345: help => 'Domain_Configuration_Self_Creation',
346: header => [{col1 => 'Self-creation with institutional username',
347: col2 => 'Enabled?'},
348: {col1 => 'Institutional user type (login/SSO self-creation)',
349: col2 => 'Information user can enter'},
1.160.6.93 raeburn 350: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 351: col2 => 'Settings'}],
1.160.6.37 raeburn 352: print => \&print_selfcreation,
353: modify => \&modify_selfcreation,
1.160.6.34 raeburn 354: },
1.69 raeburn 355: 'usermodification' =>
1.33 raeburn 356: { text => 'User modification',
1.67 raeburn 357: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 358: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 359: col2 => 'User information updatable in author context'},
1.33 raeburn 360: {col1 => 'Target user has role',
1.160.6.35 raeburn 361: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 362: print => \&print_usermodification,
363: modify => \&modify_usermodification,
1.33 raeburn 364: },
1.69 raeburn 365: 'scantron' =>
1.160.6.97! raeburn 366: { text => 'Bubblesheet format',
1.67 raeburn 367: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97! raeburn 368: header => [ {col1 => 'Bubblesheet format file',
! 369: col2 => ''},
! 370: {col1 => 'Bubblesheet data upload formats',
! 371: col2 => 'Settings'}],
1.160.6.37 raeburn 372: print => \&print_scantron,
373: modify => \&modify_scantron,
1.46 raeburn 374: },
1.86 raeburn 375: 'requestcourses' =>
376: {text => 'Request creation of courses',
377: help => 'Domain_Configuration_Request_Courses',
378: header => [{col1 => 'User affiliation',
1.102 raeburn 379: col2 => 'Availability/Processing of requests',},
380: {col1 => 'Setting',
1.160.6.30 raeburn 381: col2 => 'Value'},
382: {col1 => 'Available textbooks',
1.160.6.39 raeburn 383: col2 => ''},
1.160.6.46 raeburn 384: {col1 => 'Available templates',
385: col2 => ''},
1.160.6.39 raeburn 386: {col1 => 'Validation (not official courses)',
387: col2 => 'Value'},],
1.160.6.37 raeburn 388: print => \&print_quotas,
389: modify => \&modify_quotas,
1.86 raeburn 390: },
1.160.6.5 raeburn 391: 'requestauthor' =>
1.160.6.34 raeburn 392: {text => 'Request Authoring Space',
1.160.6.5 raeburn 393: help => 'Domain_Configuration_Request_Author',
394: header => [{col1 => 'User affiliation',
395: col2 => 'Availability/Processing of requests',},
396: {col1 => 'Setting',
397: col2 => 'Value'}],
1.160.6.37 raeburn 398: print => \&print_quotas,
399: modify => \&modify_quotas,
1.160.6.5 raeburn 400: },
1.69 raeburn 401: 'coursecategories' =>
1.120 raeburn 402: { text => 'Cataloging of courses/communities',
1.67 raeburn 403: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 404: header => [{col1 => 'Catalog type/availability',
405: col2 => '',},
406: {col1 => 'Category settings for standard catalog',
1.57 raeburn 407: col2 => '',},
408: {col1 => 'Categories',
409: col2 => '',
410: }],
1.160.6.37 raeburn 411: print => \&print_coursecategories,
412: modify => \&modify_coursecategories,
1.69 raeburn 413: },
414: 'serverstatuses' =>
1.77 raeburn 415: {text => 'Access to server status pages',
1.69 raeburn 416: help => 'Domain_Configuration_Server_Status',
417: header => [{col1 => 'Status Page',
418: col2 => 'Other named users',
419: col3 => 'Specific IPs',
420: }],
1.160.6.37 raeburn 421: print => \&print_serverstatuses,
422: modify => \&modify_serverstatuses,
1.69 raeburn 423: },
1.160.6.73 raeburn 424: 'helpsettings' =>
425: {text => 'Support settings',
426: help => 'Domain_Configuration_Help_Settings',
427: header => [{col1 => 'Help Page Settings (logged-in users)',
428: col2 => 'Value'},
429: {col1 => 'Helpdesk Roles',
430: col2 => 'Settings'},],
431: print => \&print_helpsettings,
432: modify => \&modify_helpsettings,
433: },
1.160.6.39 raeburn 434: 'coursedefaults' =>
1.160.6.16 raeburn 435: {text => 'Course/Community defaults',
436: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 437: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
438: col2 => 'Value',},
439: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 440: col2 => 'Value',},],
1.160.6.37 raeburn 441: print => \&print_coursedefaults,
442: modify => \&modify_coursedefaults,
443: },
1.160.6.39 raeburn 444: 'selfenrollment' =>
1.160.6.37 raeburn 445: {text => 'Self-enrollment in Course/Community',
446: help => 'Domain_Configuration_Selfenrollment',
447: header => [{col1 => 'Configuration Rights',
448: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
449: {col1 => 'Defaults',
450: col2 => 'Value'},
451: {col1 => 'Self-enrollment validation (optional)',
452: col2 => 'Value'},],
453: print => \&print_selfenrollment,
454: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 455: },
1.141 raeburn 456: 'usersessions' =>
1.145 raeburn 457: {text => 'User session hosting/offloading',
1.137 raeburn 458: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 459: header => [{col1 => 'Domain server',
460: col2 => 'Servers to offload sessions to when busy'},
461: {col1 => 'Hosting of users from other domains',
1.137 raeburn 462: col2 => 'Rules'},
463: {col1 => "Hosting domain's own users elsewhere",
464: col2 => 'Rules'}],
1.160.6.37 raeburn 465: print => \&print_usersessions,
466: modify => \&modify_usersessions,
1.137 raeburn 467: },
1.160.6.78 raeburn 468: 'loadbalancing' =>
1.160.6.7 raeburn 469: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 470: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 471: header => [{col1 => 'Balancers',
1.150 raeburn 472: col2 => 'Default destinations',
1.160.6.13 raeburn 473: col3 => 'User affiliation',
1.150 raeburn 474: col4 => 'Overrides'},
475: ],
1.160.6.37 raeburn 476: print => \&print_loadbalancing,
477: modify => \&modify_loadbalancing,
1.150 raeburn 478: },
1.3 raeburn 479: );
1.110 raeburn 480: if (keys(%servers) > 1) {
481: $prefs{'login'} = { text => 'Log-in page options',
482: help => 'Domain_Configuration_Login_Page',
483: header => [{col1 => 'Log-in Service',
484: col2 => 'Server Setting',},
485: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 486: col2 => ''},
487: {col1 => 'Log-in Help',
1.160.6.56 raeburn 488: col2 => 'Value'},
489: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 490: col2 => 'Value'}],
1.160.6.37 raeburn 491: print => \&print_login,
492: modify => \&modify_login,
1.110 raeburn 493: };
494: }
1.160.6.13 raeburn 495:
1.6 raeburn 496: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 497: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 498: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 499: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 500: text=>"Settings to display/modify"});
1.9 raeburn 501: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 502:
1.3 raeburn 503: if ($phase eq 'process') {
1.160.6.27 raeburn 504: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
505: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 506: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 507: $r->rflush();
1.160.6.27 raeburn 508: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 509: }
1.30 raeburn 510: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 511: my $js = &recaptcha_js().
1.160.6.40 raeburn 512: &toggle_display_js();
1.160.6.7 raeburn 513: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 514: my ($othertitle,$usertypes,$types) =
515: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 516: $js .= &lonbalance_targets_js($dom,$types,\%servers,
517: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 518: &new_spares_js().
519: &common_domprefs_js().
520: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 521: }
1.160.6.30 raeburn 522: if (grep(/^requestcourses$/,@actions)) {
523: my $javascript_validations;
524: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
525: $js .= <<END;
526: <script type="text/javascript">
527: $javascript_validations
528: </script>
529: $coursebrowserjs
530: END
531: }
1.160.6.93 raeburn 532: if (grep(/^selfcreation$/,@actions)) {
533: $js .= &selfcreate_javascript();
534: }
1.160.6.78 raeburn 535: if (grep(/^contacts$/,@actions)) {
536: $js .= &contacts_javascript();
537: }
1.160.6.97! raeburn 538: if (grep(/^scantron$/,@actions)) {
! 539: $js .= &scantron_javascript();
! 540: }
1.150 raeburn 541: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 542: } else {
1.160.6.11 raeburn 543: # check if domconfig user exists for the domain.
544: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 545: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 546: &config_check($dom,$confname,$servadm);
547: unless ($configuserok eq 'ok') {
548: &Apache::lonconfigsettings::print_header($r,$phase,$context);
549: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
550: $confname).
551: '<br />'
552: );
553: if ($switchserver) {
554: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
555: '<br />'.
556: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
557: '<br />'.
558: &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).
559: '<br />'.
560: &mt('To do that now, use the following link: [_1]',$switchserver)
561: );
562: } else {
563: $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.').
564: '<br />'.
565: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
566: );
567: }
568: $r->print(&Apache::loncommon::end_page());
569: return OK;
570: }
1.21 raeburn 571: if (keys(%domconfig) == 0) {
572: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 573: my @ids=&Apache::lonnet::current_machine_ids();
574: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 575: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 576: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 577: my $custom_img_count = 0;
578: foreach my $img (@loginimages) {
579: if ($designhash{$dom.'.login.'.$img} ne '') {
580: $custom_img_count ++;
581: }
582: }
583: foreach my $role (@roles) {
584: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
585: $custom_img_count ++;
586: }
587: }
588: if ($custom_img_count > 0) {
1.94 raeburn 589: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 590: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 591: $r->print(
592: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
593: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
594: &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 />'.
595: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
596: if ($switch_server) {
1.30 raeburn 597: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 598: }
1.91 raeburn 599: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 600: return OK;
601: }
602: }
603: }
1.91 raeburn 604: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 605: }
606: return OK;
607: }
608:
609: sub process_changes {
1.160.6.24 raeburn 610: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 611: my %domconfig;
612: if (ref($values) eq 'HASH') {
613: %domconfig = %{$values};
614: }
1.3 raeburn 615: my $output;
616: if ($action eq 'login') {
1.160.6.24 raeburn 617: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 618: } elsif ($action eq 'rolecolors') {
1.9 raeburn 619: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 620: $lastactref,%domconfig);
1.3 raeburn 621: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 622: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 623: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 624: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 625: } elsif ($action eq 'autoupdate') {
626: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 627: } elsif ($action eq 'autocreate') {
628: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 629: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 630: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 631: } elsif ($action eq 'usercreation') {
1.28 raeburn 632: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 633: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 634: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 635: } elsif ($action eq 'usermodification') {
636: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 637: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 638: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 639: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 640: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 641: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 642: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 643: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 644: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 645: } elsif ($action eq 'serverstatuses') {
646: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 647: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 648: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 649: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 650: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 651: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 652: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 653: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 654: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 655: } elsif ($action eq 'selfenrollment') {
656: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 657: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 658: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 659: } elsif ($action eq 'loadbalancing') {
660: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 661: }
662: return $output;
663: }
664:
665: sub print_config_box {
1.9 raeburn 666: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 667: my $rowtotal = 0;
1.49 raeburn 668: my $output;
669: if ($action eq 'coursecategories') {
670: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 671: } elsif ($action eq 'defaults') {
672: $output = &defaults_javascript($settings);
1.160.6.73 raeburn 673: } elsif ($action eq 'helpsettings') {
674: my (%privs,%levelscurrent);
675: my %full=();
676: my %levels=(
677: course => {},
678: domain => {},
679: system => {},
680: );
681: my $context = 'domain';
682: my $crstype = 'Course';
683: my $formname = 'display';
684: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
685: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
686: $output =
687: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
688: \@templateroles);
1.91 raeburn 689: }
1.160.6.40 raeburn 690: $output .=
1.30 raeburn 691: '<table class="LC_nested_outer">
1.3 raeburn 692: <tr>
1.66 raeburn 693: <th align="left" valign="middle"><span class="LC_nobreak">'.
694: &mt($item->{text}).' '.
695: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
696: '</tr>';
1.30 raeburn 697: $rowtotal ++;
1.110 raeburn 698: my $numheaders = 1;
699: if (ref($item->{'header'}) eq 'ARRAY') {
700: $numheaders = scalar(@{$item->{'header'}});
701: }
702: if ($numheaders > 1) {
1.64 raeburn 703: my $colspan = '';
1.145 raeburn 704: my $rightcolspan = '';
1.160.6.42 raeburn 705: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 706: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 707: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 708: $colspan = ' colspan="2"';
709: }
1.145 raeburn 710: if ($action eq 'usersessions') {
711: $rightcolspan = ' colspan="3"';
712: }
1.30 raeburn 713: $output .= '
1.3 raeburn 714: <tr>
715: <td>
716: <table class="LC_nested">
717: <tr class="LC_info_row">
1.59 bisitz 718: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 719: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 720: </tr>';
1.69 raeburn 721: $rowtotal ++;
1.160.6.37 raeburn 722: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 723: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 724: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78 raeburn 725: ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37 raeburn 726: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 727: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 728: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97! raeburn 729: } elsif ($action eq 'scantron') {
! 730: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 731: } elsif ($action eq 'login') {
1.160.6.56 raeburn 732: if ($numheaders == 4) {
1.160.6.5 raeburn 733: $colspan = ' colspan="2"';
734: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
735: } else {
736: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
737: }
1.160.6.37 raeburn 738: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 739: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 740: } elsif ($action eq 'rolecolors') {
1.30 raeburn 741: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 742: }
1.30 raeburn 743: $output .= '
1.6 raeburn 744: </table>
745: </td>
746: </tr>
747: <tr>
748: <td>
749: <table class="LC_nested">
750: <tr class="LC_info_row">
1.160.6.37 raeburn 751: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 752: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 753: </tr>';
754: $rowtotal ++;
1.160.6.37 raeburn 755: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
756: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 757: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.80 raeburn 758: ($action eq 'contacts') || ($action eq 'defaults')) {
1.160.6.42 raeburn 759: if ($action eq 'coursecategories') {
760: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
761: $colspan = ' colspan="2"';
762: } else {
763: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
764: }
765: $output .= '
1.63 raeburn 766: </table>
767: </td>
768: </tr>
769: <tr>
770: <td>
771: <table class="LC_nested">
772: <tr class="LC_info_row">
773: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 774: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 775: </tr>'."\n";
776: if ($action eq 'coursecategories') {
777: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
778: } else {
779: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
780: }
1.63 raeburn 781: $rowtotal ++;
1.160.6.57 raeburn 782: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 783: ($action eq 'defaults') || ($action eq 'directorysrch') ||
784: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 785: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97! raeburn 786: } elsif ($action eq 'scantron') {
! 787: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 788: } elsif ($action eq 'login') {
1.160.6.56 raeburn 789: if ($numheaders == 4) {
1.160.6.5 raeburn 790: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
791: </table>
792: </td>
793: </tr>
794: <tr>
795: <td>
796: <table class="LC_nested">
797: <tr class="LC_info_row">
798: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 799: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 800: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
801: $rowtotal ++;
802: } else {
803: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
804: }
1.160.6.56 raeburn 805: $output .= '
806: </table>
807: </td>
808: </tr>
809: <tr>
810: <td>
811: <table class="LC_nested">
812: <tr class="LC_info_row">';
813: if ($numheaders == 4) {
814: $output .= '
815: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
816: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
817: </tr>';
818: } else {
819: $output .= '
820: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
821: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
822: </tr>';
823: }
824: $rowtotal ++;
825: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 826: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 827: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
828: $rowtotal ++;
829: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 830: </table>
831: </td>
832: </tr>
833: <tr>
834: <td>
835: <table class="LC_nested">
836: <tr class="LC_info_row">
837: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
838: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 839: &textbookcourses_javascript($settings).
840: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
841: </table>
842: </td>
843: </tr>
844: <tr>
845: <td>
846: <table class="LC_nested">
847: <tr class="LC_info_row">
848: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
849: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
850: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 851: </table>
852: </td>
853: </tr>
854: <tr>
855: <td>
856: <table class="LC_nested">
857: <tr class="LC_info_row">
1.160.6.46 raeburn 858: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
859: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 860: </tr>'.
861: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 862: } elsif ($action eq 'requestauthor') {
863: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 864: $rowtotal ++;
1.122 jms 865: } elsif ($action eq 'rolecolors') {
1.30 raeburn 866: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 867: </table>
868: </td>
869: </tr>
870: <tr>
871: <td>
872: <table class="LC_nested">
873: <tr class="LC_info_row">
1.69 raeburn 874: <td class="LC_left_item"'.$colspan.' valign="top">'.
875: &mt($item->{'header'}->[2]->{'col1'}).'</td>
876: <td class="LC_right_item" valign="top">'.
877: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 878: </tr>'.
1.30 raeburn 879: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 880: </table>
881: </td>
882: </tr>
883: <tr>
884: <td>
885: <table class="LC_nested">
886: <tr class="LC_info_row">
1.59 bisitz 887: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
888: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 889: </tr>'.
1.30 raeburn 890: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
891: $rowtotal += 2;
1.6 raeburn 892: }
1.3 raeburn 893: } else {
1.30 raeburn 894: $output .= '
1.3 raeburn 895: <tr>
896: <td>
897: <table class="LC_nested">
1.30 raeburn 898: <tr class="LC_info_row">';
1.160.6.72 raeburn 899: if ($action eq 'login') {
1.30 raeburn 900: $output .= '
1.59 bisitz 901: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 902: } elsif ($action eq 'serverstatuses') {
903: $output .= '
904: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
905: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
906:
1.6 raeburn 907: } else {
1.30 raeburn 908: $output .= '
1.69 raeburn 909: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
910: }
1.72 raeburn 911: if (defined($item->{'header'}->[0]->{'col3'})) {
912: $output .= '<td class="LC_left_item" valign="top">'.
913: &mt($item->{'header'}->[0]->{'col2'});
914: if ($action eq 'serverstatuses') {
915: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
916: }
1.69 raeburn 917: } else {
918: $output .= '<td class="LC_right_item" valign="top">'.
919: &mt($item->{'header'}->[0]->{'col2'});
920: }
921: $output .= '</td>';
922: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 923: if (defined($item->{'header'}->[0]->{'col4'})) {
924: $output .= '<td class="LC_left_item" valign="top">'.
925: &mt($item->{'header'}->[0]->{'col3'});
926: } else {
927: $output .= '<td class="LC_right_item" valign="top">'.
928: &mt($item->{'header'}->[0]->{'col3'});
929: }
1.69 raeburn 930: if ($action eq 'serverstatuses') {
931: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
932: }
933: $output .= '</td>';
1.6 raeburn 934: }
1.150 raeburn 935: if ($item->{'header'}->[0]->{'col4'}) {
936: $output .= '<td class="LC_right_item" valign="top">'.
937: &mt($item->{'header'}->[0]->{'col4'});
938: }
1.69 raeburn 939: $output .= '</tr>';
1.48 raeburn 940: $rowtotal ++;
1.160.6.5 raeburn 941: if ($action eq 'quotas') {
1.86 raeburn 942: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 943: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.78 raeburn 944: ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 945: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 946: }
1.3 raeburn 947: }
1.30 raeburn 948: $output .= '
1.3 raeburn 949: </table>
950: </td>
951: </tr>
1.30 raeburn 952: </table><br />';
953: return ($output,$rowtotal);
1.1 raeburn 954: }
955:
1.3 raeburn 956: sub print_login {
1.160.6.5 raeburn 957: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 958: my ($css_class,$datatable);
1.6 raeburn 959: my %choices = &login_choices();
1.110 raeburn 960:
1.160.6.5 raeburn 961: if ($caller eq 'service') {
1.149 raeburn 962: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 963: my $choice = $choices{'disallowlogin'};
964: $css_class = ' class="LC_odd_row"';
1.128 raeburn 965: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 966: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 967: '<th>'.$choices{'server'}.'</th>'.
968: '<th>'.$choices{'serverpath'}.'</th>'.
969: '<th>'.$choices{'custompath'}.'</th>'.
970: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 971: my %disallowed;
972: if (ref($settings) eq 'HASH') {
973: if (ref($settings->{'loginvia'}) eq 'HASH') {
974: %disallowed = %{$settings->{'loginvia'}};
975: }
976: }
977: foreach my $lonhost (sort(keys(%servers))) {
978: my $direct = 'selected="selected"';
1.128 raeburn 979: if (ref($disallowed{$lonhost}) eq 'HASH') {
980: if ($disallowed{$lonhost}{'server'} ne '') {
981: $direct = '';
982: }
1.110 raeburn 983: }
1.115 raeburn 984: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 985: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 986: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
987: '</option>';
1.160.6.13 raeburn 988: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 989: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 990: my $selected = '';
1.128 raeburn 991: if (ref($disallowed{$lonhost}) eq 'HASH') {
992: if ($hostid eq $disallowed{$lonhost}{'server'}) {
993: $selected = 'selected="selected"';
994: }
1.110 raeburn 995: }
996: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
997: $servers{$hostid}.'</option>';
998: }
1.128 raeburn 999: $datatable .= '</select></td>'.
1000: '<td><select name="'.$lonhost.'_serverpath">';
1001: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1002: my $pathname = $path;
1003: if ($path eq 'custom') {
1004: $pathname = &mt('Custom Path').' ->';
1005: }
1006: my $selected = '';
1007: if (ref($disallowed{$lonhost}) eq 'HASH') {
1008: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1009: $selected = 'selected="selected"';
1010: }
1011: } elsif ($path eq '') {
1012: $selected = 'selected="selected"';
1013: }
1014: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1015: }
1016: $datatable .= '</select></td>';
1017: my ($custom,$exempt);
1018: if (ref($disallowed{$lonhost}) eq 'HASH') {
1019: $custom = $disallowed{$lonhost}{'custompath'};
1020: $exempt = $disallowed{$lonhost}{'exempt'};
1021: }
1022: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1023: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1024: '</tr>';
1.110 raeburn 1025: }
1026: $datatable .= '</table></td></tr>';
1027: return $datatable;
1.160.6.5 raeburn 1028: } elsif ($caller eq 'page') {
1029: my %defaultchecked = (
1030: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1031: 'helpdesk' => 'on',
1.160.6.5 raeburn 1032: 'adminmail' => 'off',
1033: 'newuser' => 'off',
1034: );
1.160.6.14 raeburn 1035: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1036: my (%checkedon,%checkedoff);
1.42 raeburn 1037: foreach my $item (@toggles) {
1.160.6.5 raeburn 1038: if ($defaultchecked{$item} eq 'on') {
1039: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1040: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1041: } elsif ($defaultchecked{$item} eq 'off') {
1042: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1043: $checkedon{$item} = ' ';
1044: }
1.1 raeburn 1045: }
1.160.6.5 raeburn 1046: my @images = ('img','logo','domlogo','login');
1047: my @logintext = ('textcol','bgcol');
1048: my @bgs = ('pgbg','mainbg','sidebg');
1049: my @links = ('link','alink','vlink');
1050: my %designhash = &Apache::loncommon::get_domainconf($dom);
1051: my %defaultdesign = %Apache::loncommon::defaultdesign;
1052: my (%is_custom,%designs);
1053: my %defaults = (
1054: font => $defaultdesign{'login.font'},
1055: );
1.6 raeburn 1056: foreach my $item (@images) {
1.160.6.5 raeburn 1057: $defaults{$item} = $defaultdesign{'login.'.$item};
1058: $defaults{'showlogo'}{$item} = 1;
1059: }
1060: foreach my $item (@bgs) {
1061: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1062: }
1.41 raeburn 1063: foreach my $item (@logintext) {
1.160.6.5 raeburn 1064: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1065: }
1.160.6.5 raeburn 1066: foreach my $item (@links) {
1067: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1068: }
1.160.6.5 raeburn 1069: if (ref($settings) eq 'HASH') {
1070: foreach my $item (@toggles) {
1071: if ($settings->{$item} eq '1') {
1072: $checkedon{$item} = ' checked="checked" ';
1073: $checkedoff{$item} = ' ';
1074: } elsif ($settings->{$item} eq '0') {
1075: $checkedoff{$item} = ' checked="checked" ';
1076: $checkedon{$item} = ' ';
1077: }
1.6 raeburn 1078: }
1.160.6.5 raeburn 1079: foreach my $item (@images) {
1080: if (defined($settings->{$item})) {
1081: $designs{$item} = $settings->{$item};
1082: $is_custom{$item} = 1;
1083: }
1084: if (defined($settings->{'showlogo'}{$item})) {
1085: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1086: }
1087: }
1088: foreach my $item (@logintext) {
1089: if ($settings->{$item} ne '') {
1090: $designs{'logintext'}{$item} = $settings->{$item};
1091: $is_custom{$item} = 1;
1092: }
1093: }
1094: if ($settings->{'font'} ne '') {
1095: $designs{'font'} = $settings->{'font'};
1096: $is_custom{'font'} = 1;
1097: }
1098: foreach my $item (@bgs) {
1099: if ($settings->{$item} ne '') {
1100: $designs{'bgs'}{$item} = $settings->{$item};
1101: $is_custom{$item} = 1;
1102: }
1103: }
1104: foreach my $item (@links) {
1105: if ($settings->{$item} ne '') {
1106: $designs{'links'}{$item} = $settings->{$item};
1107: $is_custom{$item} = 1;
1108: }
1109: }
1110: } else {
1111: if ($designhash{$dom.'.login.font'} ne '') {
1112: $designs{'font'} = $designhash{$dom.'.login.font'};
1113: $is_custom{'font'} = 1;
1114: }
1115: foreach my $item (@images) {
1116: if ($designhash{$dom.'.login.'.$item} ne '') {
1117: $designs{$item} = $designhash{$dom.'.login.'.$item};
1118: $is_custom{$item} = 1;
1119: }
1120: }
1121: foreach my $item (@bgs) {
1122: if ($designhash{$dom.'.login.'.$item} ne '') {
1123: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1124: $is_custom{$item} = 1;
1125: }
1126: }
1127: foreach my $item (@links) {
1128: if ($designhash{$dom.'.login.'.$item} ne '') {
1129: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1130: $is_custom{$item} = 1;
1131: }
1.6 raeburn 1132: }
1133: }
1.160.6.5 raeburn 1134: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1135: logo => 'Institution Logo',
1136: domlogo => 'Domain Logo',
1137: login => 'Login box');
1138: my $itemcount = 1;
1139: foreach my $item (@toggles) {
1140: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1141: $datatable .=
1142: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1143: '</td><td>'.
1144: '<span class="LC_nobreak"><label><input type="radio" name="'.
1145: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1146: '</label> <label><input type="radio" name="'.$item.'"'.
1147: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1148: '</tr>';
1149: $itemcount ++;
1.6 raeburn 1150: }
1.160.6.5 raeburn 1151: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1152: $datatable .= '</tr></table></td></tr>';
1153: } elsif ($caller eq 'help') {
1154: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1155: my $switchserver = &check_switchserver($dom,$confname);
1156: my $itemcount = 1;
1157: $defaulturl = '/adm/loginproblems.html';
1158: $defaulttype = 'default';
1159: %lt = &Apache::lonlocal::texthash (
1160: del => 'Delete?',
1161: rep => 'Replace:',
1162: upl => 'Upload:',
1163: default => 'Default',
1164: custom => 'Custom',
1165: );
1166: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1167: my @currlangs;
1168: if (ref($settings) eq 'HASH') {
1169: if (ref($settings->{'helpurl'}) eq 'HASH') {
1170: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1171: next if ($settings->{'helpurl'}{$key} eq '');
1172: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1173: $type{$key} = 'custom';
1174: unless ($key eq 'nolang') {
1175: push(@currlangs,$key);
1176: }
1177: }
1178: } elsif ($settings->{'helpurl'} ne '') {
1179: $type{'nolang'} = 'custom';
1180: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1181: }
1182: }
1.160.6.5 raeburn 1183: foreach my $lang ('nolang',sort(@currlangs)) {
1184: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1185: $datatable .= '<tr'.$css_class.'>';
1186: if ($url{$lang} eq '') {
1187: $url{$lang} = $defaulturl;
1188: }
1189: if ($type{$lang} eq '') {
1190: $type{$lang} = $defaulttype;
1191: }
1192: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1193: if ($lang eq 'nolang') {
1194: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1195: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1196: } else {
1197: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1198: $langchoices{$lang},
1199: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1200: }
1201: $datatable .= '</span></td>'."\n".
1202: '<td class="LC_left_item">';
1203: if ($type{$lang} eq 'custom') {
1204: $datatable .= '<span class="LC_nobreak"><label>'.
1205: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1206: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1207: } else {
1208: $datatable .= $lt{'upl'};
1209: }
1210: $datatable .='<br />';
1211: if ($switchserver) {
1212: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1213: } else {
1214: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1215: }
1.160.6.5 raeburn 1216: $datatable .= '</td></tr>';
1217: $itemcount ++;
1.6 raeburn 1218: }
1.160.6.5 raeburn 1219: my @addlangs;
1220: foreach my $lang (sort(keys(%langchoices))) {
1221: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1222: push(@addlangs,$lang);
1223: }
1224: if (@addlangs > 0) {
1225: my %toadd;
1226: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1227: $toadd{''} = &mt('Select');
1228: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1229: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1230: &mt('Add log-in help page for a specific language:').' '.
1231: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1232: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1233: if ($switchserver) {
1234: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1235: } else {
1236: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1237: }
1.160.6.5 raeburn 1238: $datatable .= '</td></tr>';
1239: $itemcount ++;
1.6 raeburn 1240: }
1.160.6.5 raeburn 1241: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1242: } elsif ($caller eq 'headtag') {
1243: my %domservers = &Apache::lonnet::get_servers($dom);
1244: my $choice = $choices{'headtag'};
1245: $css_class = ' class="LC_odd_row"';
1246: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1247: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1248: '<th>'.$choices{'current'}.'</th>'.
1249: '<th>'.$choices{'action'}.'</th>'.
1250: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1251: my (%currurls,%currexempt);
1252: if (ref($settings) eq 'HASH') {
1253: if (ref($settings->{'headtag'}) eq 'HASH') {
1254: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1255: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1256: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1257: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1258: }
1259: }
1260: }
1261: }
1262: my %lt = &Apache::lonlocal::texthash(
1263: del => 'Delete?',
1264: rep => 'Replace:',
1265: upl => 'Upload:',
1266: curr => 'View contents',
1267: none => 'None',
1268: );
1269: my $switchserver = &check_switchserver($dom,$confname);
1270: foreach my $lonhost (sort(keys(%domservers))) {
1271: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1272: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1273: if ($currurls{$lonhost}) {
1274: $datatable .= '<td class="LC_right_item"><a href="'.
1275: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1276: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1277: '">'.$lt{'curr'}.'</a></td>'.
1278: '<td><span class="LC_nobreak"><label>'.
1279: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1280: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1281: } else {
1282: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1283: }
1284: $datatable .='<br />';
1285: if ($switchserver) {
1286: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1287: } else {
1288: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1289: }
1.160.6.87 raeburn 1290: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1291: }
1292: $datatable .= '</table></td></tr>';
1.1 raeburn 1293: }
1.6 raeburn 1294: return $datatable;
1295: }
1296:
1297: sub login_choices {
1298: my %choices =
1299: &Apache::lonlocal::texthash (
1.116 bisitz 1300: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1301: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1302: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1303: disallowlogin => "Login page requests redirected",
1304: hostid => "Server",
1.128 raeburn 1305: server => "Redirect to:",
1306: serverpath => "Path",
1307: custompath => "Custom",
1308: exempt => "Exempt IP(s)",
1.110 raeburn 1309: directlogin => "No redirect",
1310: newuser => "Link to create a user account",
1311: img => "Header",
1312: logo => "Main Logo",
1313: domlogo => "Domain Logo",
1314: login => "Log-in Header",
1315: textcol => "Text color",
1316: bgcol => "Box color",
1317: bgs => "Background colors",
1318: links => "Link colors",
1319: font => "Font color",
1320: pgbg => "Header",
1321: mainbg => "Page",
1322: sidebg => "Login box",
1323: link => "Link",
1324: alink => "Active link",
1325: vlink => "Visited link",
1.160.6.56 raeburn 1326: headtag => "Custom markup",
1327: action => "Action",
1328: current => "Current",
1.6 raeburn 1329: );
1330: return %choices;
1331: }
1332:
1333: sub print_rolecolors {
1.30 raeburn 1334: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1335: my %choices = &color_font_choices();
1336: my @bgs = ('pgbg','tabbg','sidebg');
1337: my @links = ('link','alink','vlink');
1338: my @images = ('img');
1339: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1340: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1341: my %defaultdesign = %Apache::loncommon::defaultdesign;
1342: my (%is_custom,%designs);
1.160.6.22 raeburn 1343: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1344: if (ref($settings) eq 'HASH') {
1345: if (ref($settings->{$role}) eq 'HASH') {
1346: if ($settings->{$role}->{'img'} ne '') {
1347: $designs{'img'} = $settings->{$role}->{'img'};
1348: $is_custom{'img'} = 1;
1349: }
1350: if ($settings->{$role}->{'font'} ne '') {
1351: $designs{'font'} = $settings->{$role}->{'font'};
1352: $is_custom{'font'} = 1;
1353: }
1.97 tempelho 1354: if ($settings->{$role}->{'fontmenu'} ne '') {
1355: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1356: $is_custom{'fontmenu'} = 1;
1357: }
1.6 raeburn 1358: foreach my $item (@bgs) {
1359: if ($settings->{$role}->{$item} ne '') {
1360: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1361: $is_custom{$item} = 1;
1362: }
1363: }
1364: foreach my $item (@links) {
1365: if ($settings->{$role}->{$item} ne '') {
1366: $designs{'links'}{$item} = $settings->{$role}->{$item};
1367: $is_custom{$item} = 1;
1368: }
1369: }
1370: }
1371: } else {
1372: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1373: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1374: $is_custom{'img'} = 1;
1375: }
1.97 tempelho 1376: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1377: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1378: $is_custom{'fontmenu'} = 1;
1379: }
1.6 raeburn 1380: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1381: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1382: $is_custom{'font'} = 1;
1383: }
1384: foreach my $item (@bgs) {
1385: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1386: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1387: $is_custom{$item} = 1;
1388:
1389: }
1390: }
1391: foreach my $item (@links) {
1392: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1393: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1394: $is_custom{$item} = 1;
1395: }
1396: }
1397: }
1398: my $itemcount = 1;
1.30 raeburn 1399: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1400: $datatable .= '</tr></table></td></tr>';
1401: return $datatable;
1402: }
1403:
1.160.6.22 raeburn 1404: sub role_defaults {
1405: my ($role,$bgs,$links,$images,$logintext) = @_;
1406: my %defaults;
1407: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1408: return %defaults;
1409: }
1410: my %defaultdesign = %Apache::loncommon::defaultdesign;
1411: if ($role eq 'login') {
1412: %defaults = (
1413: font => $defaultdesign{$role.'.font'},
1414: );
1415: if (ref($logintext) eq 'ARRAY') {
1416: foreach my $item (@{$logintext}) {
1417: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1418: }
1419: }
1420: foreach my $item (@{$images}) {
1421: $defaults{'showlogo'}{$item} = 1;
1422: }
1423: } else {
1424: %defaults = (
1425: img => $defaultdesign{$role.'.img'},
1426: font => $defaultdesign{$role.'.font'},
1427: fontmenu => $defaultdesign{$role.'.fontmenu'},
1428: );
1429: }
1430: foreach my $item (@{$bgs}) {
1431: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1432: }
1433: foreach my $item (@{$links}) {
1434: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1435: }
1436: foreach my $item (@{$images}) {
1437: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1438: }
1439: return %defaults;
1440: }
1441:
1.6 raeburn 1442: sub display_color_options {
1.9 raeburn 1443: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1444: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1445: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1446: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1447: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1448: '<td>'.$choices->{'font'}.'</td>';
1449: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1450: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1451: } else {
1452: $datatable .= '<td> </td>';
1453: }
1.160.6.9 raeburn 1454: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1455:
1.8 raeburn 1456: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1457: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1458: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1459: ' </span></td></tr>';
1.107 raeburn 1460: unless ($role eq 'login') {
1461: $datatable .= '<tr'.$css_class.'>'.
1462: '<td>'.$choices->{'fontmenu'}.'</td>';
1463: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1464: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1465: } else {
1466: $datatable .= '<td> </td>';
1467: }
1.160.6.22 raeburn 1468: $current_color = $designs->{'fontmenu'} ?
1469: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1470: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1471: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1472: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1473: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1474: ' </span></td></tr>';
1.97 tempelho 1475: }
1.9 raeburn 1476: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1477: foreach my $img (@{$images}) {
1.18 albertel 1478: $itemcount ++;
1.6 raeburn 1479: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1480: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1481: '<td>'.$choices->{$img};
1.41 raeburn 1482: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1483: if ($role eq 'login') {
1484: if ($img eq 'login') {
1485: $login_hdr_pick =
1.135 bisitz 1486: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1487: $logincolors =
1488: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1489: $designs,$defaults);
1.70 raeburn 1490: } elsif ($img ne 'domlogo') {
1491: $datatable.= &logo_display_options($img,$defaults,$designs);
1492: }
1493: }
1494: $datatable .= '</td>';
1.6 raeburn 1495: if ($designs->{$img} ne '') {
1496: $imgfile = $designs->{$img};
1.18 albertel 1497: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1498: } else {
1499: $imgfile = $defaults->{$img};
1500: }
1501: if ($imgfile) {
1.9 raeburn 1502: my ($showfile,$fullsize);
1503: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1504: my $urldir = $1;
1505: my $filename = $2;
1506: my @info = &Apache::lonnet::stat_file($designs->{$img});
1507: if (@info) {
1508: my $thumbfile = 'tn-'.$filename;
1509: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1510: if (@thumb) {
1511: $showfile = $urldir.'/'.$thumbfile;
1512: } else {
1513: $showfile = $imgfile;
1514: }
1515: } else {
1516: $showfile = '';
1517: }
1518: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1519: $showfile = $imgfile;
1.6 raeburn 1520: my $imgdir = $1;
1521: my $filename = $2;
1.159 raeburn 1522: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1523: $showfile = "/$imgdir/tn-".$filename;
1524: } else {
1.159 raeburn 1525: my $input = $londocroot.$imgfile;
1526: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1527: if (!-e $output) {
1.9 raeburn 1528: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1529: my ($fullwidth,$fullheight) = &check_dimensions($input);
1530: if ($fullwidth ne '' && $fullheight ne '') {
1531: if ($fullwidth > $width && $fullheight > $height) {
1532: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1533: my @args = ('convert','-sample',$size,$input,$output);
1534: system({$args[0]} @args);
1.159 raeburn 1535: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1536: }
1537: }
1.6 raeburn 1538: }
1539: }
1.16 raeburn 1540: }
1.6 raeburn 1541: if ($showfile) {
1.40 raeburn 1542: if ($showfile =~ m{^/(adm|res)/}) {
1543: if ($showfile =~ m{^/res/}) {
1544: my $local_showfile =
1545: &Apache::lonnet::filelocation('',$showfile);
1546: &Apache::lonnet::repcopy($local_showfile);
1547: }
1548: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1549: }
1550: if ($imgfile) {
1551: if ($imgfile =~ m{^/(adm|res)/}) {
1552: if ($imgfile =~ m{^/res/}) {
1553: my $local_imgfile =
1554: &Apache::lonnet::filelocation('',$imgfile);
1555: &Apache::lonnet::repcopy($local_imgfile);
1556: }
1557: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1558: } else {
1559: $fullsize = $imgfile;
1560: }
1561: }
1.41 raeburn 1562: $datatable .= '<td>';
1563: if ($img eq 'login') {
1.135 bisitz 1564: $datatable .= $login_hdr_pick;
1565: }
1.41 raeburn 1566: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1567: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1568: } else {
1.160.6.22 raeburn 1569: $datatable .= '<td> </td><td class="LC_left_item">'.
1570: &mt('Upload:').'<br />';
1.6 raeburn 1571: }
1572: } else {
1.160.6.22 raeburn 1573: $datatable .= '<td> </td><td class="LC_left_item">'.
1574: &mt('Upload:').'<br />';
1.6 raeburn 1575: }
1.9 raeburn 1576: if ($switchserver) {
1577: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1578: } else {
1.135 bisitz 1579: if ($img ne 'login') { # suppress file selection for Log-in header
1580: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1581: }
1.9 raeburn 1582: }
1583: $datatable .= '</td></tr>';
1.6 raeburn 1584: }
1585: $itemcount ++;
1586: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1587: $datatable .= '<tr'.$css_class.'>'.
1588: '<td>'.$choices->{'bgs'}.'</td>';
1589: my $bgs_def;
1590: foreach my $item (@{$bgs}) {
1591: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1592: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1593: }
1594: }
1595: if ($bgs_def) {
1.8 raeburn 1596: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1597: } else {
1598: $datatable .= '<td> </td>';
1599: }
1600: $datatable .= '<td class="LC_right_item">'.
1601: '<table border="0"><tr>';
1.160.6.13 raeburn 1602:
1.6 raeburn 1603: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1604: $datatable .= '<td align="center">'.$choices->{$item};
1605: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1606: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1607: $datatable .= ' ';
1.6 raeburn 1608: }
1.160.6.9 raeburn 1609: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1610: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1611: }
1612: $datatable .= '</tr></table></td></tr>';
1613: $itemcount ++;
1614: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1615: $datatable .= '<tr'.$css_class.'>'.
1616: '<td>'.$choices->{'links'}.'</td>';
1617: my $links_def;
1618: foreach my $item (@{$links}) {
1619: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1620: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1621: }
1622: }
1623: if ($links_def) {
1.8 raeburn 1624: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1625: } else {
1626: $datatable .= '<td> </td>';
1627: }
1628: $datatable .= '<td class="LC_right_item">'.
1629: '<table border="0"><tr>';
1630: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1631: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1632: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1633: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1634: $datatable.=' ';
1.6 raeburn 1635: }
1.160.6.9 raeburn 1636: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1637: '" /></td>';
1638: }
1.30 raeburn 1639: $$rowtotal += $itemcount;
1.3 raeburn 1640: return $datatable;
1641: }
1642:
1.70 raeburn 1643: sub logo_display_options {
1644: my ($img,$defaults,$designs) = @_;
1645: my $checkedon;
1646: if (ref($defaults) eq 'HASH') {
1647: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1648: if ($defaults->{'showlogo'}{$img}) {
1649: $checkedon = 'checked="checked" ';
1650: }
1651: }
1652: }
1653: if (ref($designs) eq 'HASH') {
1654: if (ref($designs->{'showlogo'}) eq 'HASH') {
1655: if (defined($designs->{'showlogo'}{$img})) {
1656: if ($designs->{'showlogo'}{$img} == 0) {
1657: $checkedon = '';
1658: } elsif ($designs->{'showlogo'}{$img} == 1) {
1659: $checkedon = 'checked="checked" ';
1660: }
1661: }
1662: }
1663: }
1664: return '<br /><label> <input type="checkbox" name="'.
1665: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1666: &mt('show').'</label>'."\n";
1667: }
1668:
1.41 raeburn 1669: sub login_header_options {
1.135 bisitz 1670: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1671: my $output = '';
1.41 raeburn 1672: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1673: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1674: if (!$is_custom->{'textcol'}) {
1675: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1676: ' ';
1677: }
1678: if (!$is_custom->{'bgcol'}) {
1679: $output .= $choices->{'bgcol'}.': '.
1680: '<span id="css_'.$role.'_font" style="background-color: '.
1681: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1682: }
1683: $output .= '<br />';
1684: }
1685: $output .='<br />';
1686: return $output;
1687: }
1688:
1689: sub login_text_colors {
1.160.6.22 raeburn 1690: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1691: my $color_menu = '<table border="0"><tr>';
1692: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1693: $color_menu .= '<td align="center">'.$choices->{$item};
1694: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1695: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1696: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1697: }
1698: $color_menu .= '</tr></table><br />';
1699: return $color_menu;
1700: }
1701:
1702: sub image_changes {
1703: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1704: my $output;
1.135 bisitz 1705: if ($img eq 'login') {
1.160.6.87 raeburn 1706: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1707: } elsif (!$is_custom) {
1.70 raeburn 1708: if ($img ne 'domlogo') {
1.160.6.87 raeburn 1709: $output = &mt('Default image:').'<br />';
1.41 raeburn 1710: } else {
1.160.6.87 raeburn 1711: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1712: }
1713: }
1.160.6.87 raeburn 1714: if ($img ne 'login') {
1.135 bisitz 1715: if ($img_import) {
1716: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1717: }
1718: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1719: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1720: if ($is_custom) {
1721: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1722: '<input type="checkbox" name="'.
1723: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1724: '</label> '.&mt('Replace:').'</span><br />';
1725: } else {
1.160.6.22 raeburn 1726: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1727: }
1.41 raeburn 1728: }
1729: return $output;
1730: }
1731:
1.3 raeburn 1732: sub print_quotas {
1.86 raeburn 1733: my ($dom,$settings,$rowtotal,$action) = @_;
1734: my $context;
1735: if ($action eq 'quotas') {
1736: $context = 'tools';
1737: } else {
1738: $context = $action;
1739: }
1.160.6.20 raeburn 1740: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1741: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1742: my $typecount = 0;
1.101 raeburn 1743: my ($css_class,%titles);
1.86 raeburn 1744: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1745: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1746: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1747: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1748: %titles = &courserequest_titles();
1.160.6.5 raeburn 1749: } elsif ($context eq 'requestauthor') {
1750: @usertools = ('author');
1751: @options = ('norequest','approval','automatic');
1752: %titles = &authorrequest_titles();
1.86 raeburn 1753: } else {
1.160.6.4 raeburn 1754: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1755: %titles = &tool_titles();
1.86 raeburn 1756: }
1.26 raeburn 1757: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1758: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1759: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1760: unless (($context eq 'requestcourses') ||
1761: ($context eq 'requestauthor')) {
1.86 raeburn 1762: if (ref($settings) eq 'HASH') {
1763: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1764: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1765: } else {
1766: $currdefquota = $settings->{$type};
1767: }
1.160.6.20 raeburn 1768: if (ref($settings->{authorquota}) eq 'HASH') {
1769: $currauthorquota = $settings->{authorquota}->{$type};
1770: }
1.78 raeburn 1771: }
1.72 raeburn 1772: }
1.3 raeburn 1773: if (defined($usertypes->{$type})) {
1774: $typecount ++;
1775: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1776: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1777: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1778: '<td class="LC_left_item">';
1.101 raeburn 1779: if ($context eq 'requestcourses') {
1780: $datatable .= '<table><tr>';
1781: }
1782: my %cell;
1.72 raeburn 1783: foreach my $item (@usertools) {
1.101 raeburn 1784: if ($context eq 'requestcourses') {
1785: my ($curroption,$currlimit);
1786: if (ref($settings) eq 'HASH') {
1787: if (ref($settings->{$item}) eq 'HASH') {
1788: $curroption = $settings->{$item}->{$type};
1789: if ($curroption =~ /^autolimit=(\d*)$/) {
1790: $currlimit = $1;
1791: }
1792: }
1793: }
1794: if (!$curroption) {
1795: $curroption = 'norequest';
1796: }
1797: $datatable .= '<th>'.$titles{$item}.'</th>';
1798: foreach my $option (@options) {
1799: my $val = $option;
1800: if ($option eq 'norequest') {
1801: $val = 0;
1802: }
1803: if ($option eq 'validate') {
1804: my $canvalidate = 0;
1805: if (ref($validations{$item}) eq 'HASH') {
1806: if ($validations{$item}{$type}) {
1807: $canvalidate = 1;
1808: }
1809: }
1810: next if (!$canvalidate);
1811: }
1812: my $checked = '';
1813: if ($option eq $curroption) {
1814: $checked = ' checked="checked"';
1815: } elsif ($option eq 'autolimit') {
1816: if ($curroption =~ /^autolimit/) {
1817: $checked = ' checked="checked"';
1818: }
1819: }
1820: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1821: '<input type="radio" name="crsreq_'.$item.
1822: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1823: $titles{$option}.'</label>';
1.101 raeburn 1824: if ($option eq 'autolimit') {
1.127 raeburn 1825: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1826: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1827: 'value="'.$currlimit.'" />';
1.101 raeburn 1828: }
1.127 raeburn 1829: $cell{$item} .= '</span> ';
1.103 raeburn 1830: if ($option eq 'autolimit') {
1.127 raeburn 1831: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1832: }
1.101 raeburn 1833: }
1.160.6.5 raeburn 1834: } elsif ($context eq 'requestauthor') {
1835: my $curroption;
1836: if (ref($settings) eq 'HASH') {
1837: $curroption = $settings->{$type};
1838: }
1839: if (!$curroption) {
1840: $curroption = 'norequest';
1841: }
1842: foreach my $option (@options) {
1843: my $val = $option;
1844: if ($option eq 'norequest') {
1845: $val = 0;
1846: }
1847: my $checked = '';
1848: if ($option eq $curroption) {
1849: $checked = ' checked="checked"';
1850: }
1851: $datatable .= '<span class="LC_nobreak"><label>'.
1852: '<input type="radio" name="authorreq_'.$type.
1853: '" value="'.$val.'"'.$checked.' />'.
1854: $titles{$option}.'</label></span> ';
1855: }
1.101 raeburn 1856: } else {
1857: my $checked = 'checked="checked" ';
1858: if (ref($settings) eq 'HASH') {
1859: if (ref($settings->{$item}) eq 'HASH') {
1860: if ($settings->{$item}->{$type} == 0) {
1861: $checked = '';
1862: } elsif ($settings->{$item}->{$type} == 1) {
1863: $checked = 'checked="checked" ';
1864: }
1.78 raeburn 1865: }
1.72 raeburn 1866: }
1.101 raeburn 1867: $datatable .= '<span class="LC_nobreak"><label>'.
1868: '<input type="checkbox" name="'.$context.'_'.$item.
1869: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1870: '</label></span> ';
1.72 raeburn 1871: }
1.101 raeburn 1872: }
1873: if ($context eq 'requestcourses') {
1874: $datatable .= '</tr><tr>';
1875: foreach my $item (@usertools) {
1.106 raeburn 1876: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1877: }
1878: $datatable .= '</tr></table>';
1.72 raeburn 1879: }
1.86 raeburn 1880: $datatable .= '</td>';
1.160.6.5 raeburn 1881: unless (($context eq 'requestcourses') ||
1882: ($context eq 'requestauthor')) {
1.86 raeburn 1883: $datatable .=
1.160.6.20 raeburn 1884: '<td class="LC_right_item">'.
1885: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1886: '<input type="text" name="quota_'.$type.
1.72 raeburn 1887: '" value="'.$currdefquota.
1.160.6.20 raeburn 1888: '" size="5" /></span>'.(' ' x 2).
1889: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1890: '<input type="text" name="authorquota_'.$type.
1891: '" value="'.$currauthorquota.
1892: '" size="5" /></span></td>';
1.86 raeburn 1893: }
1894: $datatable .= '</tr>';
1.3 raeburn 1895: }
1896: }
1897: }
1.160.6.5 raeburn 1898: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1899: $defaultquota = '20';
1.160.6.20 raeburn 1900: $authorquota = '500';
1.86 raeburn 1901: if (ref($settings) eq 'HASH') {
1902: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1903: $defaultquota = $settings->{'defaultquota'}->{'default'};
1904: } elsif (defined($settings->{'default'})) {
1905: $defaultquota = $settings->{'default'};
1906: }
1.160.6.20 raeburn 1907: if (ref($settings->{'authorquota'}) eq 'HASH') {
1908: $authorquota = $settings->{'authorquota'}->{'default'};
1909: }
1.3 raeburn 1910: }
1911: }
1912: $typecount ++;
1913: $css_class = $typecount%2?' class="LC_odd_row"':'';
1914: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1915: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1916: '<td class="LC_left_item">';
1.101 raeburn 1917: if ($context eq 'requestcourses') {
1918: $datatable .= '<table><tr>';
1919: }
1920: my %defcell;
1.72 raeburn 1921: foreach my $item (@usertools) {
1.101 raeburn 1922: if ($context eq 'requestcourses') {
1923: my ($curroption,$currlimit);
1924: if (ref($settings) eq 'HASH') {
1925: if (ref($settings->{$item}) eq 'HASH') {
1926: $curroption = $settings->{$item}->{'default'};
1927: if ($curroption =~ /^autolimit=(\d*)$/) {
1928: $currlimit = $1;
1929: }
1930: }
1931: }
1932: if (!$curroption) {
1933: $curroption = 'norequest';
1934: }
1935: $datatable .= '<th>'.$titles{$item}.'</th>';
1936: foreach my $option (@options) {
1937: my $val = $option;
1938: if ($option eq 'norequest') {
1939: $val = 0;
1940: }
1941: if ($option eq 'validate') {
1942: my $canvalidate = 0;
1943: if (ref($validations{$item}) eq 'HASH') {
1944: if ($validations{$item}{'default'}) {
1945: $canvalidate = 1;
1946: }
1947: }
1948: next if (!$canvalidate);
1949: }
1950: my $checked = '';
1951: if ($option eq $curroption) {
1952: $checked = ' checked="checked"';
1953: } elsif ($option eq 'autolimit') {
1954: if ($curroption =~ /^autolimit/) {
1955: $checked = ' checked="checked"';
1956: }
1957: }
1958: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1959: '<input type="radio" name="crsreq_'.$item.
1960: '_default" value="'.$val.'"'.$checked.' />'.
1961: $titles{$option}.'</label>';
1962: if ($option eq 'autolimit') {
1.127 raeburn 1963: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1964: $item.'_limit_default" size="1" '.
1965: 'value="'.$currlimit.'" />';
1966: }
1.127 raeburn 1967: $defcell{$item} .= '</span> ';
1.104 raeburn 1968: if ($option eq 'autolimit') {
1.127 raeburn 1969: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1970: }
1.101 raeburn 1971: }
1.160.6.5 raeburn 1972: } elsif ($context eq 'requestauthor') {
1973: my $curroption;
1974: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1975: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1976: }
1977: if (!$curroption) {
1978: $curroption = 'norequest';
1979: }
1980: foreach my $option (@options) {
1981: my $val = $option;
1982: if ($option eq 'norequest') {
1983: $val = 0;
1984: }
1985: my $checked = '';
1986: if ($option eq $curroption) {
1987: $checked = ' checked="checked"';
1988: }
1989: $datatable .= '<span class="LC_nobreak"><label>'.
1990: '<input type="radio" name="authorreq_default"'.
1991: ' value="'.$val.'"'.$checked.' />'.
1992: $titles{$option}.'</label></span> ';
1993: }
1.101 raeburn 1994: } else {
1995: my $checked = 'checked="checked" ';
1996: if (ref($settings) eq 'HASH') {
1997: if (ref($settings->{$item}) eq 'HASH') {
1998: if ($settings->{$item}->{'default'} == 0) {
1999: $checked = '';
2000: } elsif ($settings->{$item}->{'default'} == 1) {
2001: $checked = 'checked="checked" ';
2002: }
1.78 raeburn 2003: }
1.72 raeburn 2004: }
1.101 raeburn 2005: $datatable .= '<span class="LC_nobreak"><label>'.
2006: '<input type="checkbox" name="'.$context.'_'.$item.
2007: '" value="default" '.$checked.'/>'.$titles{$item}.
2008: '</label></span> ';
2009: }
2010: }
2011: if ($context eq 'requestcourses') {
2012: $datatable .= '</tr><tr>';
2013: foreach my $item (@usertools) {
1.106 raeburn 2014: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2015: }
1.101 raeburn 2016: $datatable .= '</tr></table>';
1.72 raeburn 2017: }
1.86 raeburn 2018: $datatable .= '</td>';
1.160.6.5 raeburn 2019: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2020: $datatable .= '<td class="LC_right_item">'.
2021: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2022: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2023: $defaultquota.'" size="5" /></span>'.(' ' x2).
2024: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2025: '<input type="text" name="authorquota" value="'.
2026: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2027: }
2028: $datatable .= '</tr>';
1.72 raeburn 2029: $typecount ++;
2030: $css_class = $typecount%2?' class="LC_odd_row"':'';
2031: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2032: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2033: if ($context eq 'requestcourses') {
1.109 raeburn 2034: $datatable .= &mt('(overrides affiliation, if set)').
2035: '</td>'.
2036: '<td class="LC_left_item">'.
2037: '<table><tr>';
1.101 raeburn 2038: } else {
1.109 raeburn 2039: $datatable .= &mt('(overrides affiliation, if checked)').
2040: '</td>'.
2041: '<td class="LC_left_item" colspan="2">'.
2042: '<br />';
1.101 raeburn 2043: }
2044: my %advcell;
1.72 raeburn 2045: foreach my $item (@usertools) {
1.101 raeburn 2046: if ($context eq 'requestcourses') {
2047: my ($curroption,$currlimit);
2048: if (ref($settings) eq 'HASH') {
2049: if (ref($settings->{$item}) eq 'HASH') {
2050: $curroption = $settings->{$item}->{'_LC_adv'};
2051: if ($curroption =~ /^autolimit=(\d*)$/) {
2052: $currlimit = $1;
2053: }
2054: }
2055: }
2056: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2057: my $checked = '';
2058: if ($curroption eq '') {
2059: $checked = ' checked="checked"';
2060: }
2061: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2062: '<input type="radio" name="crsreq_'.$item.
2063: '__LC_adv" value=""'.$checked.' />'.
2064: &mt('No override set').'</label></span> ';
1.101 raeburn 2065: foreach my $option (@options) {
2066: my $val = $option;
2067: if ($option eq 'norequest') {
2068: $val = 0;
2069: }
2070: if ($option eq 'validate') {
2071: my $canvalidate = 0;
2072: if (ref($validations{$item}) eq 'HASH') {
2073: if ($validations{$item}{'_LC_adv'}) {
2074: $canvalidate = 1;
2075: }
2076: }
2077: next if (!$canvalidate);
2078: }
2079: my $checked = '';
1.104 raeburn 2080: if ($val eq $curroption) {
1.101 raeburn 2081: $checked = ' checked="checked"';
2082: } elsif ($option eq 'autolimit') {
2083: if ($curroption =~ /^autolimit/) {
2084: $checked = ' checked="checked"';
2085: }
2086: }
2087: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2088: '<input type="radio" name="crsreq_'.$item.
2089: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2090: $titles{$option}.'</label>';
2091: if ($option eq 'autolimit') {
1.127 raeburn 2092: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2093: $item.'_limit__LC_adv" size="1" '.
2094: 'value="'.$currlimit.'" />';
2095: }
1.127 raeburn 2096: $advcell{$item} .= '</span> ';
1.104 raeburn 2097: if ($option eq 'autolimit') {
1.127 raeburn 2098: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2099: }
1.101 raeburn 2100: }
1.160.6.5 raeburn 2101: } elsif ($context eq 'requestauthor') {
2102: my $curroption;
2103: if (ref($settings) eq 'HASH') {
2104: $curroption = $settings->{'_LC_adv'};
2105: }
2106: my $checked = '';
2107: if ($curroption eq '') {
2108: $checked = ' checked="checked"';
2109: }
2110: $datatable .= '<span class="LC_nobreak"><label>'.
2111: '<input type="radio" name="authorreq__LC_adv"'.
2112: ' value=""'.$checked.' />'.
2113: &mt('No override set').'</label></span> ';
2114: foreach my $option (@options) {
2115: my $val = $option;
2116: if ($option eq 'norequest') {
2117: $val = 0;
2118: }
2119: my $checked = '';
2120: if ($val eq $curroption) {
2121: $checked = ' checked="checked"';
2122: }
2123: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2124: '<input type="radio" name="authorreq__LC_adv"'.
2125: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2126: $titles{$option}.'</label></span> ';
2127: }
1.101 raeburn 2128: } else {
2129: my $checked = 'checked="checked" ';
2130: if (ref($settings) eq 'HASH') {
2131: if (ref($settings->{$item}) eq 'HASH') {
2132: if ($settings->{$item}->{'_LC_adv'} == 0) {
2133: $checked = '';
2134: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2135: $checked = 'checked="checked" ';
2136: }
1.79 raeburn 2137: }
1.72 raeburn 2138: }
1.101 raeburn 2139: $datatable .= '<span class="LC_nobreak"><label>'.
2140: '<input type="checkbox" name="'.$context.'_'.$item.
2141: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2142: '</label></span> ';
2143: }
2144: }
2145: if ($context eq 'requestcourses') {
2146: $datatable .= '</tr><tr>';
2147: foreach my $item (@usertools) {
1.106 raeburn 2148: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2149: }
1.101 raeburn 2150: $datatable .= '</tr></table>';
1.72 raeburn 2151: }
1.98 raeburn 2152: $datatable .= '</td></tr>';
1.30 raeburn 2153: $$rowtotal += $typecount;
1.3 raeburn 2154: return $datatable;
2155: }
2156:
1.160.6.5 raeburn 2157: sub print_requestmail {
1.160.6.93 raeburn 2158: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2159: my ($now,$datatable,%currapp);
1.102 raeburn 2160: $now = time;
2161: if (ref($settings) eq 'HASH') {
2162: if (ref($settings->{'notify'}) eq 'HASH') {
2163: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2164: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2165: }
2166: }
2167: }
1.160.6.16 raeburn 2168: my $numinrow = 2;
1.160.6.34 raeburn 2169: my $css_class;
1.160.6.93 raeburn 2170: if ($$rowtotal%2) {
2171: $css_class = 'LC_odd_row';
2172: }
2173: if ($customcss) {
2174: $css_class .= " $customcss";
2175: }
2176: $css_class =~ s/^\s+//;
2177: if ($css_class) {
2178: $css_class = ' class="'.$css_class.'"';
2179: }
2180: if ($rowstyle) {
2181: $css_class .= ' style="'.$rowstyle.'"';
2182: }
1.160.6.5 raeburn 2183: my $text;
2184: if ($action eq 'requestcourses') {
2185: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2186: } elsif ($action eq 'requestauthor') {
2187: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2188: } else {
1.160.6.34 raeburn 2189: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2190: }
1.160.6.34 raeburn 2191: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2192: ' <td>'.$text.'</td>'.
1.102 raeburn 2193: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2194: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2195: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2196: if ($numdc > 0) {
2197: $datatable .= $table;
1.102 raeburn 2198: } else {
2199: $datatable .= &mt('There are no active Domain Coordinators');
2200: }
2201: $datatable .='</td></tr>';
2202: return $datatable;
2203: }
2204:
1.160.6.30 raeburn 2205: sub print_studentcode {
2206: my ($settings,$rowtotal) = @_;
2207: my $rownum = 0;
2208: my ($output,%current);
2209: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2210: if (ref($settings) eq 'HASH') {
2211: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2212: foreach my $type (@crstypes) {
2213: $current{$type} = $settings->{'uniquecode'}{$type};
2214: }
1.160.6.30 raeburn 2215: }
2216: }
2217: $output .= '<tr>'.
2218: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2219: '<td class="LC_left_item">';
2220: foreach my $type (@crstypes) {
2221: my $check = ' ';
2222: if ($current{$type}) {
2223: $check = ' checked="checked" ';
2224: }
2225: $output .= '<span class="LC_nobreak"><label>'.
2226: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2227: &mt($type).'</label></span>'.(' 'x2).' ';
2228: }
2229: $output .= '</td></tr>';
2230: $$rowtotal ++;
2231: return $output;
2232: }
2233:
2234: sub print_textbookcourses {
1.160.6.46 raeburn 2235: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2236: my $rownum = 0;
2237: my $css_class;
2238: my $itemcount = 1;
2239: my $maxnum = 0;
2240: my $bookshash;
2241: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2242: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2243: }
2244: my %ordered;
2245: if (ref($bookshash) eq 'HASH') {
2246: foreach my $item (keys(%{$bookshash})) {
2247: if (ref($bookshash->{$item}) eq 'HASH') {
2248: my $num = $bookshash->{$item}{'order'};
2249: $ordered{$num} = $item;
2250: }
2251: }
2252: }
2253: my $confname = $dom.'-domainconfig';
2254: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2255: my $maxnum = scalar(keys(%ordered));
2256: my $datatable;
1.160.6.30 raeburn 2257: if (keys(%ordered)) {
2258: my @items = sort { $a <=> $b } keys(%ordered);
2259: for (my $i=0; $i<@items; $i++) {
2260: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2261: my $key = $ordered{$items[$i]};
2262: my %coursehash=&Apache::lonnet::coursedescription($key);
2263: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2264: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2265: if (ref($bookshash->{$key}) eq 'HASH') {
2266: $subject = $bookshash->{$key}->{'subject'};
2267: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2268: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2269: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2270: $author = $bookshash->{$key}->{'author'};
2271: $image = $bookshash->{$key}->{'image'};
2272: if ($image ne '') {
2273: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2274: my $imagethumb = "$path/tn-".$imagefile;
2275: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2276: }
1.160.6.30 raeburn 2277: }
2278: }
1.160.6.46 raeburn 2279: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2280: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2281: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2282: for (my $k=0; $k<=$maxnum; $k++) {
2283: my $vpos = $k+1;
2284: my $selstr;
2285: if ($k == $i) {
2286: $selstr = ' selected="selected" ';
2287: }
2288: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2289: }
2290: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2291: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2292: &mt('Delete?').'</label></span></td>'.
2293: '<td colspan="2">'.
1.160.6.46 raeburn 2294: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2295: (' 'x2).
1.160.6.46 raeburn 2296: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2297: if ($type eq 'textbooks') {
2298: $datatable .= (' 'x2).
1.160.6.47 raeburn 2299: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2300: (' 'x2).
1.160.6.46 raeburn 2301: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2302: (' 'x2).
2303: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2304: if ($image) {
2305: $datatable .= '<span class="LC_nobreak">'.
2306: $imgsrc.
2307: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2308: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2309: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2310: }
2311: if ($switchserver) {
2312: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2313: } else {
2314: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2315: }
1.160.6.30 raeburn 2316: }
1.160.6.46 raeburn 2317: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2318: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2319: $coursetitle.'</span></td></tr>'."\n";
2320: $itemcount ++;
2321: }
2322: }
2323: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2324: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2325: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2326: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2327: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2328: for (my $k=0; $k<$maxnum+1; $k++) {
2329: my $vpos = $k+1;
2330: my $selstr;
2331: if ($k == $maxnum) {
2332: $selstr = ' selected="selected" ';
2333: }
2334: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2335: }
2336: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2337: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2338: '<td colspan="2">'.
1.160.6.46 raeburn 2339: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2340: (' 'x2).
1.160.6.46 raeburn 2341: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2342: (' 'x2);
2343: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2344: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2345: (' 'x2).
2346: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2347: (' 'x2).
2348: '<span class="LC_nobreak">'.&mt('Image:').' ';
2349: if ($switchserver) {
2350: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2351: } else {
2352: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2353: }
1.160.6.87 raeburn 2354: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2355: }
1.160.6.87 raeburn 2356: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2357: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2358: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2359: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2360: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2361: '</span></td>'."\n".
2362: '</tr>'."\n";
2363: $itemcount ++;
2364: return $datatable;
2365: }
2366:
2367: sub textbookcourses_javascript {
1.160.6.46 raeburn 2368: my ($settings) = @_;
2369: return unless(ref($settings) eq 'HASH');
2370: my (%ordered,%total,%jstext);
2371: foreach my $type ('textbooks','templates') {
2372: $total{$type} = 0;
2373: if (ref($settings->{$type}) eq 'HASH') {
2374: foreach my $item (keys(%{$settings->{$type}})) {
2375: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2376: my $num = $settings->{$type}->{$item}{'order'};
2377: $ordered{$type}{$num} = $item;
2378: }
2379: }
2380: $total{$type} = scalar(keys(%{$settings->{$type}}));
2381: }
2382: my @jsarray = ();
2383: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2384: push(@jsarray,$ordered{$type}{$item});
2385: }
2386: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2387: }
2388: return <<"ENDSCRIPT";
2389: <script type="text/javascript">
2390: // <![CDATA[
1.160.6.46 raeburn 2391: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2392: var changedVal;
1.160.6.46 raeburn 2393: $jstext{'textbooks'};
2394: $jstext{'templates'};
2395: var newpos;
2396: var maxh;
2397: if (caller == 'textbooks') {
2398: newpos = 'textbooks_addbook_pos';
2399: maxh = 1 + $total{'textbooks'};
2400: } else {
2401: newpos = 'templates_addbook_pos';
2402: maxh = 1 + $total{'templates'};
2403: }
1.160.6.30 raeburn 2404: var current = new Array;
2405: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2406: if (item == newpos) {
2407: changedVal = newitemVal;
2408: } else {
2409: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2410: current[newitemVal] = newpos;
2411: }
1.160.6.46 raeburn 2412: if (caller == 'textbooks') {
2413: for (var i=0; i<textbooks.length; i++) {
2414: var elementName = 'textbooks_'+textbooks[i];
2415: if (elementName != item) {
2416: if (form.elements[elementName]) {
2417: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2418: current[currVal] = elementName;
2419: }
2420: }
2421: }
2422: }
2423: if (caller == 'templates') {
2424: for (var i=0; i<templates.length; i++) {
2425: var elementName = 'templates_'+templates[i];
2426: if (elementName != item) {
2427: if (form.elements[elementName]) {
2428: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2429: current[currVal] = elementName;
2430: }
1.160.6.30 raeburn 2431: }
2432: }
2433: }
2434: var oldVal;
2435: for (var j=0; j<maxh; j++) {
2436: if (current[j] == undefined) {
2437: oldVal = j;
2438: }
2439: }
2440: if (oldVal < changedVal) {
2441: for (var k=oldVal+1; k<=changedVal ; k++) {
2442: var elementName = current[k];
2443: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2444: }
2445: } else {
2446: for (var k=changedVal; k<oldVal; k++) {
2447: var elementName = current[k];
2448: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2449: }
2450: }
2451: return;
2452: }
2453:
2454: // ]]>
2455: </script>
2456:
2457: ENDSCRIPT
2458: }
2459:
1.3 raeburn 2460: sub print_autoenroll {
1.30 raeburn 2461: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2462: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2463: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2464: if (ref($settings) eq 'HASH') {
2465: if (exists($settings->{'run'})) {
2466: if ($settings->{'run'} eq '0') {
2467: $runoff = ' checked="checked" ';
2468: $runon = ' ';
2469: } else {
2470: $runon = ' checked="checked" ';
2471: $runoff = ' ';
2472: }
2473: } else {
2474: if ($autorun) {
2475: $runon = ' checked="checked" ';
2476: $runoff = ' ';
2477: } else {
2478: $runoff = ' checked="checked" ';
2479: $runon = ' ';
2480: }
2481: }
1.129 raeburn 2482: if (exists($settings->{'co-owners'})) {
2483: if ($settings->{'co-owners'} eq '0') {
2484: $coownersoff = ' checked="checked" ';
2485: $coownerson = ' ';
2486: } else {
2487: $coownerson = ' checked="checked" ';
2488: $coownersoff = ' ';
2489: }
2490: } else {
2491: $coownersoff = ' checked="checked" ';
2492: $coownerson = ' ';
2493: }
1.3 raeburn 2494: if (exists($settings->{'sender_domain'})) {
2495: $defdom = $settings->{'sender_domain'};
2496: }
1.160.6.68 raeburn 2497: if (exists($settings->{'autofailsafe'})) {
2498: $failsafe = $settings->{'autofailsafe'};
2499: }
1.14 raeburn 2500: } else {
2501: if ($autorun) {
2502: $runon = ' checked="checked" ';
2503: $runoff = ' ';
2504: } else {
2505: $runoff = ' checked="checked" ';
2506: $runon = ' ';
2507: }
1.3 raeburn 2508: }
2509: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2510: my $notif_sender;
2511: if (ref($settings) eq 'HASH') {
2512: $notif_sender = $settings->{'sender_uname'};
2513: }
1.3 raeburn 2514: my $datatable='<tr class="LC_odd_row">'.
2515: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2516: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2517: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2518: $runon.' value="1" />'.&mt('Yes').'</label> '.
2519: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2520: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2521: '</tr><tr>'.
2522: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2523: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2524: &mt('username').': '.
2525: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2526: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2527: ': '.$domform.'</span></td></tr>'.
2528: '<tr class="LC_odd_row">'.
2529: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2530: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2531: '<input type="radio" name="autoassign_coowners"'.
2532: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2533: '<label><input type="radio" name="autoassign_coowners"'.
2534: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2535: '</tr><tr>'.
2536: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2537: '<td class="LC_right_item"><span class="LC_nobreak">'.
2538: '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87 raeburn 2539: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68 raeburn 2540: $$rowtotal += 4;
1.3 raeburn 2541: return $datatable;
2542: }
2543:
2544: sub print_autoupdate {
1.30 raeburn 2545: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2546: my $datatable;
2547: if ($position eq 'top') {
2548: my $updateon = ' ';
2549: my $updateoff = ' checked="checked" ';
2550: my $classlistson = ' ';
2551: my $classlistsoff = ' checked="checked" ';
2552: if (ref($settings) eq 'HASH') {
2553: if ($settings->{'run'} eq '1') {
2554: $updateon = $updateoff;
2555: $updateoff = ' ';
2556: }
2557: if ($settings->{'classlists'} eq '1') {
2558: $classlistson = $classlistsoff;
2559: $classlistsoff = ' ';
2560: }
2561: }
2562: my %title = (
2563: run => 'Auto-update active?',
2564: classlists => 'Update information in classlists?',
2565: );
2566: $datatable = '<tr class="LC_odd_row">'.
2567: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2568: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2569: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2570: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2571: '<label><input type="radio" name="autoupdate_run"'.
2572: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2573: '</tr><tr>'.
2574: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2575: '<td class="LC_right_item"><span class="LC_nobreak">'.
2576: '<label><input type="radio" name="classlists"'.
2577: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2578: '<label><input type="radio" name="classlists"'.
2579: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2580: '</tr>';
1.30 raeburn 2581: $$rowtotal += 2;
1.131 raeburn 2582: } elsif ($position eq 'middle') {
2583: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2584: my $numinrow = 3;
2585: my $locknamesettings;
2586: $datatable .= &insttypes_row($settings,$types,$usertypes,
2587: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 2588: 'lockablenames',$rowtotal);
1.131 raeburn 2589: $$rowtotal ++;
1.3 raeburn 2590: } else {
1.44 raeburn 2591: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2592: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2593: 'permanentemail','id');
1.33 raeburn 2594: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2595: my $numrows = 0;
1.26 raeburn 2596: if (ref($types) eq 'ARRAY') {
2597: if (@{$types} > 0) {
2598: $datatable =
2599: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2600: \@fields,$types,\$numrows);
1.30 raeburn 2601: $$rowtotal += @{$types};
1.26 raeburn 2602: }
1.3 raeburn 2603: }
2604: $datatable .=
2605: &usertype_update_row($settings,{'default' => $othertitle},
2606: \%fieldtitles,\@fields,['default'],
2607: \$numrows);
1.30 raeburn 2608: $$rowtotal ++;
1.3 raeburn 2609: }
2610: return $datatable;
2611: }
2612:
1.125 raeburn 2613: sub print_autocreate {
2614: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2615: my (%createon,%createoff,%currhash);
1.125 raeburn 2616: my @types = ('xml','req');
2617: if (ref($settings) eq 'HASH') {
2618: foreach my $item (@types) {
2619: $createoff{$item} = ' checked="checked" ';
2620: $createon{$item} = ' ';
2621: if (exists($settings->{$item})) {
2622: if ($settings->{$item}) {
2623: $createon{$item} = ' checked="checked" ';
2624: $createoff{$item} = ' ';
2625: }
2626: }
2627: }
1.160.6.16 raeburn 2628: if ($settings->{'xmldc'} ne '') {
2629: $currhash{$settings->{'xmldc'}} = 1;
2630: }
1.125 raeburn 2631: } else {
2632: foreach my $item (@types) {
2633: $createoff{$item} = ' checked="checked" ';
2634: $createon{$item} = ' ';
2635: }
2636: }
2637: $$rowtotal += 2;
1.160.6.16 raeburn 2638: my $numinrow = 2;
1.125 raeburn 2639: my $datatable='<tr class="LC_odd_row">'.
2640: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2641: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2642: '<input type="radio" name="autocreate_xml"'.
2643: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2644: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2645: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2646: '</td></tr><tr>'.
2647: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2648: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2649: '<input type="radio" name="autocreate_req"'.
2650: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2651: '<label><input type="radio" name="autocreate_req"'.
2652: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2653: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2654: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2655: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2656: if ($numdc > 1) {
1.160.6.50 raeburn 2657: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2658: '</td><td class="LC_left_item">';
1.125 raeburn 2659: } else {
1.160.6.50 raeburn 2660: $datatable .= &mt('Course creation processed as:').
2661: '</td><td class="LC_right_item">';
1.125 raeburn 2662: }
1.160.6.50 raeburn 2663: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2664: $$rowtotal += $rows;
1.125 raeburn 2665: return $datatable;
2666: }
2667:
1.23 raeburn 2668: sub print_directorysrch {
1.160.6.72 raeburn 2669: my ($position,$dom,$settings,$rowtotal) = @_;
2670: my $datatable;
2671: if ($position eq 'top') {
2672: my $instsrchon = ' ';
2673: my $instsrchoff = ' checked="checked" ';
2674: my ($exacton,$containson,$beginson);
2675: my $instlocalon = ' ';
2676: my $instlocaloff = ' checked="checked" ';
2677: if (ref($settings) eq 'HASH') {
2678: if ($settings->{'available'} eq '1') {
2679: $instsrchon = $instsrchoff;
2680: $instsrchoff = ' ';
2681: }
2682: if ($settings->{'localonly'} eq '1') {
2683: $instlocalon = $instlocaloff;
2684: $instlocaloff = ' ';
2685: }
2686: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2687: foreach my $type (@{$settings->{'searchtypes'}}) {
2688: if ($type eq 'exact') {
2689: $exacton = ' checked="checked" ';
2690: } elsif ($type eq 'contains') {
2691: $containson = ' checked="checked" ';
2692: } elsif ($type eq 'begins') {
2693: $beginson = ' checked="checked" ';
2694: }
2695: }
2696: } else {
2697: if ($settings->{'searchtypes'} eq 'exact') {
2698: $exacton = ' checked="checked" ';
2699: } elsif ($settings->{'searchtypes'} eq 'contains') {
2700: $containson = ' checked="checked" ';
2701: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2702: $exacton = ' checked="checked" ';
2703: $containson = ' checked="checked" ';
2704: }
2705: }
1.23 raeburn 2706: }
1.160.6.72 raeburn 2707: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2708: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2709:
1.160.6.72 raeburn 2710: my $numinrow = 4;
2711: my $cansrchrow = 0;
2712: $datatable='<tr class="LC_odd_row">'.
2713: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2714: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2715: '<input type="radio" name="dirsrch_available"'.
2716: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2717: '<label><input type="radio" name="dirsrch_available"'.
2718: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2719: '</tr><tr>'.
2720: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2721: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2722: '<input type="radio" name="dirsrch_instlocalonly"'.
2723: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2724: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2725: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2726: '</tr>';
2727: $$rowtotal += 2;
2728: if (ref($usertypes) eq 'HASH') {
2729: if (keys(%{$usertypes}) > 0) {
2730: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 2731: $numinrow,$othertitle,'cansearch',
2732: $rowtotal);
1.160.6.72 raeburn 2733: $cansrchrow = 1;
2734: }
1.26 raeburn 2735: }
1.160.6.72 raeburn 2736: if ($cansrchrow) {
2737: $$rowtotal ++;
2738: $datatable .= '<tr>';
2739: } else {
2740: $datatable .= '<tr class="LC_odd_row">';
2741: }
2742: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2743: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2744: foreach my $title (@{$titleorder}) {
2745: if (defined($searchtitles->{$title})) {
2746: my $check = ' ';
2747: if (ref($settings) eq 'HASH') {
2748: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2749: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2750: $check = ' checked="checked" ';
2751: }
1.39 raeburn 2752: }
1.25 raeburn 2753: }
1.160.6.72 raeburn 2754: $datatable .= '<td class="LC_left_item">'.
2755: '<span class="LC_nobreak"><label>'.
2756: '<input type="checkbox" name="searchby" '.
2757: 'value="'.$title.'"'.$check.'/>'.
2758: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2759: }
2760: }
1.160.6.72 raeburn 2761: $datatable .= '</tr></table></td></tr>';
2762: $$rowtotal ++;
2763: if ($cansrchrow) {
2764: $datatable .= '<tr class="LC_odd_row">';
2765: } else {
2766: $datatable .= '<tr>';
2767: }
2768: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2769: '<td class="LC_left_item" colspan="2">'.
2770: '<span class="LC_nobreak"><label>'.
2771: '<input type="checkbox" name="searchtypes" '.
2772: $exacton.' value="exact" />'.&mt('Exact match').
2773: '</label> '.
2774: '<label><input type="checkbox" name="searchtypes" '.
2775: $beginson.' value="begins" />'.&mt('Begins with').
2776: '</label> '.
2777: '<label><input type="checkbox" name="searchtypes" '.
2778: $containson.' value="contains" />'.&mt('Contains').
2779: '</label></span></td></tr>';
2780: $$rowtotal ++;
1.26 raeburn 2781: } else {
1.160.6.72 raeburn 2782: my $domsrchon = ' checked="checked" ';
2783: my $domsrchoff = ' ';
2784: my $domlocalon = ' ';
2785: my $domlocaloff = ' checked="checked" ';
2786: if (ref($settings) eq 'HASH') {
2787: if ($settings->{'lclocalonly'} eq '1') {
2788: $domlocalon = $domlocaloff;
2789: $domlocaloff = ' ';
2790: }
2791: if ($settings->{'lcavailable'} eq '0') {
2792: $domsrchoff = $domsrchon;
2793: $domsrchon = ' ';
2794: }
2795: }
2796: $datatable='<tr class="LC_odd_row">'.
2797: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2798: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2799: '<input type="radio" name="dirsrch_domavailable"'.
2800: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2801: '<label><input type="radio" name="dirsrch_domavailable"'.
2802: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2803: '</tr><tr>'.
2804: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2805: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2806: '<input type="radio" name="dirsrch_domlocalonly"'.
2807: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2808: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2809: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2810: '</tr>';
2811: $$rowtotal += 2;
1.26 raeburn 2812: }
1.25 raeburn 2813: return $datatable;
2814: }
2815:
1.28 raeburn 2816: sub print_contacts {
1.160.6.78 raeburn 2817: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2818: my $datatable;
2819: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 2820: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2821: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2822: if ($position eq 'top') {
2823: if (ref($settings) eq 'HASH') {
2824: foreach my $item (@contacts) {
2825: if (exists($settings->{$item})) {
2826: $to{$item} = $settings->{$item};
2827: }
1.28 raeburn 2828: }
2829: }
1.160.6.78 raeburn 2830: } elsif ($position eq 'middle') {
2831: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 2832: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 2833: foreach my $type (@mailings) {
1.160.6.78 raeburn 2834: $otheremails{$type} = '';
2835: }
2836: } else {
2837: @mailings = ('helpdeskmail','otherdomsmail');
2838: foreach my $type (@mailings) {
2839: $otheremails{$type} = '';
2840: }
2841: $bccemails{'helpdeskmail'} = '';
2842: $bccemails{'otherdomsmail'} = '';
2843: $includestr{'helpdeskmail'} = '';
2844: $includestr{'otherdomsmail'} = '';
2845: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2846: }
2847: if (ref($settings) eq 'HASH') {
2848: unless ($position eq 'top') {
2849: foreach my $type (@mailings) {
2850: if (exists($settings->{$type})) {
2851: if (ref($settings->{$type}) eq 'HASH') {
2852: foreach my $item (@contacts) {
2853: if ($settings->{$type}{$item}) {
2854: $checked{$type}{$item} = ' checked="checked" ';
2855: }
1.28 raeburn 2856: }
1.160.6.78 raeburn 2857: $otheremails{$type} = $settings->{$type}{'others'};
2858: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2859: $bccemails{$type} = $settings->{$type}{'bcc'};
2860: if ($settings->{$type}{'include'} ne '') {
2861: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2862: $includestr{$type} = &unescape($includestr{$type});
2863: }
2864: }
2865: }
2866: } elsif ($type eq 'lonstatusmail') {
2867: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2868: }
2869: }
2870: }
2871: if ($position eq 'bottom') {
2872: foreach my $type (@mailings) {
2873: $bccemails{$type} = $settings->{$type}{'bcc'};
2874: if ($settings->{$type}{'include'} ne '') {
2875: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2876: $includestr{$type} = &unescape($includestr{$type});
2877: }
2878: }
2879: if (ref($settings->{'helpform'}) eq 'HASH') {
2880: if (ref($fields) eq 'ARRAY') {
2881: foreach my $field (@{$fields}) {
2882: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 2883: }
1.160.6.78 raeburn 2884: }
2885: if (exists($settings->{'helpform'}{'maxsize'})) {
2886: $maxsize = $settings->{'helpform'}{'maxsize'};
2887: } else {
2888: $maxsize = '1.0';
2889: }
2890: } else {
2891: if (ref($fields) eq 'ARRAY') {
2892: foreach my $field (@{$fields}) {
2893: $currfield{$field} = 'yes';
1.134 raeburn 2894: }
1.28 raeburn 2895: }
1.160.6.78 raeburn 2896: $maxsize = '1.0';
1.28 raeburn 2897: }
2898: }
2899: } else {
1.160.6.78 raeburn 2900: if ($position eq 'top') {
2901: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2902: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2903: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2904: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2905: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2906: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2907: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2908: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 2909: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 2910: } elsif ($position eq 'bottom') {
2911: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2912: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
2913: if (ref($fields) eq 'ARRAY') {
2914: foreach my $field (@{$fields}) {
2915: $currfield{$field} = 'yes';
2916: }
2917: }
2918: $maxsize = '1.0';
2919: }
1.28 raeburn 2920: }
2921: my ($titles,$short_titles) = &contact_titles();
2922: my $rownum = 0;
2923: my $css_class;
1.160.6.78 raeburn 2924: if ($position eq 'top') {
2925: foreach my $item (@contacts) {
2926: $css_class = $rownum%2?' class="LC_odd_row"':'';
2927: $datatable .= '<tr'.$css_class.'>'.
2928: '<td><span class="LC_nobreak">'.$titles->{$item}.
2929: '</span></td><td class="LC_right_item">'.
2930: '<input type="text" name="'.$item.'" value="'.
2931: $to{$item}.'" /></td></tr>';
2932: $rownum ++;
2933: }
2934: } else {
2935: foreach my $type (@mailings) {
2936: $css_class = $rownum%2?' class="LC_odd_row"':'';
2937: $datatable .= '<tr'.$css_class.'>'.
2938: '<td><span class="LC_nobreak">'.
2939: $titles->{$type}.': </span></td>'.
2940: '<td class="LC_left_item">';
2941: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2942: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
2943: }
2944: $datatable .= '<span class="LC_nobreak">';
2945: foreach my $item (@contacts) {
2946: $datatable .= '<label>'.
2947: '<input type="checkbox" name="'.$type.'"'.
2948: $checked{$type}{$item}.
2949: ' value="'.$item.'" />'.$short_titles->{$item}.
2950: '</label> ';
2951: }
2952: $datatable .= '</span><br />'.&mt('Others').': '.
2953: '<input type="text" name="'.$type.'_others" '.
2954: 'value="'.$otheremails{$type}.'" />';
2955: my %locchecked;
2956: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2957: foreach my $loc ('s','b') {
2958: if ($includeloc{$type} eq $loc) {
2959: $locchecked{$loc} = ' checked="checked"';
2960: last;
2961: }
2962: }
2963: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2964: '<input type="text" name="'.$type.'_bcc" '.
2965: 'value="'.$bccemails{$type}.'" /></fieldset>'.
2966: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
2967: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 2968: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 2969: '<span class="LC_nobreak">'.&mt('Location:').' '.
2970: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
2971: (' 'x2).
2972: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
2973: '</span></fieldset>';
2974: }
2975: $datatable .= '</td></tr>'."\n";
2976: $rownum ++;
2977: }
1.28 raeburn 2978: }
1.160.6.78 raeburn 2979: if ($position eq 'middle') {
2980: my %choices;
2981: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2982: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2983: &mt('LON-CAPA core group - MSU'),600,500));
2984: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2985: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2986: &mt('LON-CAPA core group - MSU'),600,500));
2987: my @toggles = ('reporterrors','reportupdates');
2988: my %defaultchecked = ('reporterrors' => 'on',
2989: 'reportupdates' => 'on');
2990: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2991: \%choices,$rownum);
2992: $datatable .= $reports;
2993: } elsif ($position eq 'bottom') {
1.69 raeburn 2994: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2995: $datatable .= '<tr'.$css_class.'>'.
1.160.6.78 raeburn 2996: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
2997: &mt('(e-mail, subject, and description always shown)').
2998: '</td><td class="LC_left_item">';
2999: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3000: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3001: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3002: foreach my $field (@{$fields}) {
3003: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3004: if (($field eq 'screenshot') || ($field eq 'cc')) {
3005: $datatable .= ' '.&mt('(logged-in users)');
3006: }
3007: $datatable .='</td><td>';
3008: my $clickaction;
3009: if ($field eq 'screenshot') {
3010: $clickaction = ' onclick="screenshotSize(this);"';
3011: }
3012: if (ref($possoptions->{$field}) eq 'ARRAY') {
3013: foreach my $option (@{$possoptions->{$field}}) {
3014: my $checked;
3015: if ($currfield{$field} eq $option) {
3016: $checked = ' checked="checked"';
3017: }
3018: $datatable .= '<span class="LC_nobreak"><label>'.
3019: '<input type="radio" name="helpform_'.$field.'" '.
3020: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3021: '</label></span>'.(' 'x2);
3022: }
3023: }
3024: if ($field eq 'screenshot') {
3025: my $display;
3026: if ($currfield{$field} eq 'no') {
3027: $display = ' style="display:none"';
3028: }
1.160.6.87 raeburn 3029: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.160.6.78 raeburn 3030: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3031: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3032: }
3033: $datatable .= '</td></tr>';
3034: }
3035: $datatable .= '</table>';
1.134 raeburn 3036: }
3037: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 3038: $rownum ++;
1.28 raeburn 3039: }
1.30 raeburn 3040: $$rowtotal += $rownum;
1.28 raeburn 3041: return $datatable;
3042: }
3043:
1.160.6.78 raeburn 3044: sub contacts_javascript {
3045: return <<"ENDSCRIPT";
3046:
3047: <script type="text/javascript">
3048: // <![CDATA[
3049:
3050: function screenshotSize(field) {
3051: if (document.getElementById('help_screenshotsize')) {
3052: if (field.value == 'no') {
3053: document.getElementById('help_screenshotsize').style.display="none";
3054: } else {
3055: document.getElementById('help_screenshotsize').style.display="";
3056: }
3057: }
3058: return;
3059: }
3060:
3061: // ]]>
3062: </script>
3063:
3064: ENDSCRIPT
3065: }
3066:
1.118 jms 3067: sub print_helpsettings {
1.160.6.73 raeburn 3068: my ($position,$dom,$settings,$rowtotal) = @_;
3069: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3070: my $formname = 'display';
1.160.6.5 raeburn 3071: my ($datatable,$itemcount);
1.160.6.73 raeburn 3072: if ($position eq 'top') {
3073: $itemcount = 1;
3074: my (%choices,%defaultchecked,@toggles);
3075: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3076: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3077: &mt('LON-CAPA bug tracker'),600,500));
3078: %defaultchecked = ('submitbugs' => 'on');
3079: @toggles = ('submitbugs');
3080: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3081: \%choices,$itemcount);
3082: $$rowtotal ++;
3083: } else {
3084: my $css_class;
3085: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3086: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3087: if (ref($settings) eq 'HASH') {
3088: if (ref($settings->{'adhoc'}) eq 'HASH') {
3089: %current = %{$settings->{'adhoc'}};
3090: }
1.160.6.77 raeburn 3091: }
3092: my $count = 0;
3093: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3094: if ($key=~/^rolesdef\_(\w+)$/) {
3095: my $rolename = $1;
1.160.6.77 raeburn 3096: my (%privs,$order);
1.160.6.73 raeburn 3097: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3098: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3099: if (ref($current{$rolename}) eq 'HASH') {
3100: $order = $current{$rolename}{'order'};
3101: }
3102: if ($order eq '') {
3103: $order = $count;
3104: }
3105: $ordered{$order} = $rolename;
3106: $count++;
1.160.6.73 raeburn 3107: }
3108: }
1.160.6.77 raeburn 3109: my $maxnum = scalar(keys(%ordered));
3110: my @roles_by_num = ();
3111: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3112: push(@roles_by_num,$item);
3113: }
3114: my $context = 'domprefs';
3115: my $crstype = 'Course';
3116: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3117: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3118: my ($numstatustypes,@jsarray);
3119: if (ref($types) eq 'ARRAY') {
3120: if (@{$types} > 0) {
3121: $numstatustypes = scalar(@{$types});
3122: push(@accesstypes,'status');
3123: @jsarray = ('bystatus');
3124: }
3125: }
1.160.6.86 raeburn 3126: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3127: if (keys(%domhelpdesk)) {
3128: push(@accesstypes,('inc','exc'));
3129: push(@jsarray,('notinc','notexc'));
3130: }
3131: my $hiddenstr = join("','",@jsarray);
3132: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3133: my $context = 'domprefs';
3134: my $crstype = 'Course';
1.160.6.77 raeburn 3135: my $prefix = 'helproles_';
3136: my $add_class = 'LC_hidden';
3137: foreach my $num (@roles_by_num) {
3138: my $role = $ordered{$num};
3139: my ($desc,$access,@statuses);
3140: if (ref($current{$role}) eq 'HASH') {
3141: $desc = $current{$role}{'desc'};
3142: $access = $current{$role}{'access'};
3143: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3144: @statuses = @{$current{$role}{'insttypes'}};
3145: }
3146: }
3147: if ($desc eq '') {
3148: $desc = $role;
3149: }
3150: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3151: my %full=();
3152: my %levels= (
3153: course => {},
3154: domain => {},
3155: system => {},
3156: );
3157: my %levelscurrent=(
3158: course => {},
3159: domain => {},
3160: system => {},
3161: );
3162: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3163: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3164: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3165: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3166: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3167: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3168: for (my $k=0; $k<=$maxnum; $k++) {
3169: my $vpos = $k+1;
3170: my $selstr;
3171: if ($k == $num) {
3172: $selstr = ' selected="selected" ';
3173: }
3174: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3175: }
3176: $datatable .= '</select>'.(' 'x2).
3177: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3178: '</td>'.
3179: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3180: &mt('Name shown to users:').
3181: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3182: '</fieldset>'.
3183: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3184: $othertitle,$usertypes,$types,\%domhelpdesk).
3185: '<fieldset>'.
3186: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3187: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3188: \%levelscurrent,$identifier,
3189: 'LC_hidden',$prefix.$num.'_privs').
3190: '</fieldset></td>';
1.160.6.73 raeburn 3191: $itemcount ++;
3192: }
3193: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3194: my $newcust = 'custhelp'.$count;
3195: my (%privs,%levelscurrent);
3196: my %full=();
3197: my %levels= (
3198: course => {},
3199: domain => {},
3200: system => {},
3201: );
3202: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3203: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3204: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3205: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3206: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3207: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3208: for (my $k=0; $k<$maxnum+1; $k++) {
3209: my $vpos = $k+1;
3210: my $selstr;
3211: if ($k == $maxnum) {
3212: $selstr = ' selected="selected" ';
3213: }
3214: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3215: }
3216: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3217: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3218: '</label></span></td>'.
1.160.6.77 raeburn 3219: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3220: '<span class="LC_nobreak">'.
3221: &mt('Internal name:').
3222: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3223: '</span>'.(' 'x4).
3224: '<span class="LC_nobreak">'.
3225: &mt('Name shown to users:').
3226: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3227: '</span></fieldset>'.
3228: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3229: $usertypes,$types,\%domhelpdesk).
3230: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3231: &Apache::lonuserutils::custom_role_header($context,$crstype,
3232: \@templateroles,$newcust).
3233: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3234: \%levelscurrent,$newcust).
1.160.6.87 raeburn 3235: '</fieldset>'.
3236: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3237: '</td></tr>';
1.160.6.73 raeburn 3238: $count ++;
3239: $$rowtotal += $count;
3240: }
1.160.6.5 raeburn 3241: return $datatable;
1.121 raeburn 3242: }
3243:
1.160.6.77 raeburn 3244: sub adhocbutton {
3245: my ($prefix,$num,$field,$visibility) = @_;
3246: my %lt = &Apache::lonlocal::texthash(
3247: show => 'Show details',
3248: hide => 'Hide details',
3249: );
3250: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3251: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3252: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3253: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3254: }
3255:
3256: sub helpsettings_javascript {
3257: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3258: return unless(ref($roles_by_num) eq 'ARRAY');
3259: my %html_js_lt = &Apache::lonlocal::texthash(
3260: show => 'Show details',
3261: hide => 'Hide details',
3262: );
3263: &html_escape(\%html_js_lt);
3264: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3265: return <<"ENDSCRIPT";
3266: <script type="text/javascript">
3267: // <![CDATA[
3268:
3269: function reorderHelpRoles(form,item) {
3270: var changedVal;
3271: $jstext
3272: var newpos = 'helproles_${total}_pos';
3273: var maxh = 1 + $total;
3274: var current = new Array();
3275: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3276: if (item == newpos) {
3277: changedVal = newitemVal;
3278: } else {
3279: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3280: current[newitemVal] = newpos;
3281: }
3282: for (var i=0; i<helproles.length; i++) {
3283: var elementName = 'helproles_'+helproles[i]+'_pos';
3284: if (elementName != item) {
3285: if (form.elements[elementName]) {
3286: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3287: current[currVal] = elementName;
3288: }
3289: }
3290: }
3291: var oldVal;
3292: for (var j=0; j<maxh; j++) {
3293: if (current[j] == undefined) {
3294: oldVal = j;
3295: }
3296: }
3297: if (oldVal < changedVal) {
3298: for (var k=oldVal+1; k<=changedVal ; k++) {
3299: var elementName = current[k];
3300: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3301: }
3302: } else {
3303: for (var k=changedVal; k<oldVal; k++) {
3304: var elementName = current[k];
3305: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3306: }
3307: }
3308: return;
3309: }
3310:
3311: function helpdeskAccess(num) {
3312: var curraccess = null;
3313: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3314: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3315: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3316: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3317: }
3318: }
3319: }
3320: var shown = Array();
3321: var hidden = Array();
3322: if (curraccess == 'none') {
3323: hidden = Array('$hiddenstr');
3324: } else {
3325: if (curraccess == 'status') {
3326: shown = Array('bystatus');
3327: hidden = Array('notinc','notexc');
3328: } else {
3329: if (curraccess == 'exc') {
3330: shown = Array('notexc');
3331: hidden = Array('notinc','bystatus');
3332: }
3333: if (curraccess == 'inc') {
3334: shown = Array('notinc');
3335: hidden = Array('notexc','bystatus');
3336: }
1.160.6.79 raeburn 3337: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3338: hidden = Array('notinc','notexc','bystatus');
3339: }
3340: }
3341: }
3342: if (hidden.length > 0) {
3343: for (var i=0; i<hidden.length; i++) {
3344: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3345: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3346: }
3347: }
3348: }
3349: if (shown.length > 0) {
3350: for (var i=0; i<shown.length; i++) {
3351: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3352: if (shown[i] == 'privs') {
3353: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3354: } else {
3355: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3356: }
3357: }
3358: }
3359: }
3360: return;
3361: }
3362:
3363: function toggleHelpdeskItem(num,field) {
3364: if (document.getElementById('helproles_'+num+'_'+field)) {
3365: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3366: document.getElementById('helproles_'+num+'_'+field).className =
3367: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3368: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3369: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3370: }
3371: } else {
3372: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3373: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3374: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3375: }
3376: }
3377: }
3378: return;
3379: }
3380:
3381: // ]]>
3382: </script>
3383:
3384: ENDSCRIPT
3385: }
3386:
3387: sub helpdeskroles_access {
3388: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3389: $usertypes,$types,$domhelpdesk) = @_;
3390: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3391: my %lt = &Apache::lonlocal::texthash(
3392: 'rou' => 'Role usage',
3393: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3394: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3395: 'dh' => 'All with domain helpdesk role',
3396: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3397: 'none' => 'None',
3398: 'status' => 'Determined based on institutional status',
3399: 'inc' => 'Include all, but exclude specific personnel',
3400: 'exc' => 'Exclude all, but include specific personnel',
3401: );
3402: my %usecheck = (
3403: all => ' checked="checked"',
3404: );
3405: my %displaydiv = (
3406: status => 'none',
3407: inc => 'none',
3408: exc => 'none',
3409: priv => 'block',
3410: );
3411: my $output;
3412: if (ref($current) eq 'HASH') {
3413: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3414: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3415: $usecheck{$current->{access}} = $usecheck{'all'};
3416: delete($usecheck{'all'});
3417: if ($current->{access} =~ /^(status|inc|exc)$/) {
3418: my $access = $1;
3419: $displaydiv{$access} = 'inline';
3420: } elsif ($current->{access} eq 'none') {
3421: $displaydiv{'priv'} = 'none';
3422: }
3423: }
3424: }
3425: }
3426: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3427: '<p>'.$lt{'whi'}.'</p>';
3428: foreach my $access (@{$accesstypes}) {
3429: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3430: ' onclick="helpdeskAccess('."'$num'".');" />'.
3431: $lt{$access}.'</label>';
3432: if ($access eq 'status') {
3433: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3434: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3435: $othertitle,$usertypes,$types).
3436: '</div>';
3437: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3438: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3439: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3440: '</div>';
3441: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3442: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3443: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3444: '</div>';
3445: }
3446: $output .= '</p>';
3447: }
3448: $output .= '</fieldset>';
3449: return $output;
3450: }
3451:
1.121 raeburn 3452: sub radiobutton_prefs {
1.160.6.16 raeburn 3453: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3454: $additional,$align) = @_;
1.121 raeburn 3455: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3456: (ref($choices) eq 'HASH'));
3457:
3458: my (%checkedon,%checkedoff,$datatable,$css_class);
3459:
3460: foreach my $item (@{$toggles}) {
3461: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3462: $checkedon{$item} = ' checked="checked" ';
3463: $checkedoff{$item} = ' ';
1.121 raeburn 3464: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3465: $checkedoff{$item} = ' checked="checked" ';
3466: $checkedon{$item} = ' ';
3467: }
3468: }
3469: if (ref($settings) eq 'HASH') {
1.121 raeburn 3470: foreach my $item (@{$toggles}) {
1.118 jms 3471: if ($settings->{$item} eq '1') {
3472: $checkedon{$item} = ' checked="checked" ';
3473: $checkedoff{$item} = ' ';
3474: } elsif ($settings->{$item} eq '0') {
3475: $checkedoff{$item} = ' checked="checked" ';
3476: $checkedon{$item} = ' ';
3477: }
3478: }
1.121 raeburn 3479: }
1.160.6.16 raeburn 3480: if ($onclick) {
3481: $onclick = ' onclick="'.$onclick.'"';
3482: }
1.121 raeburn 3483: foreach my $item (@{$toggles}) {
1.118 jms 3484: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3485: $datatable .=
1.160.6.16 raeburn 3486: '<tr'.$css_class.'><td valign="top">'.
3487: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3488: '</span></td>';
3489: if ($align eq 'left') {
3490: $datatable .= '<td class="LC_left_item">';
3491: } else {
3492: $datatable .= '<td class="LC_right_item">';
3493: }
3494: $datatable .=
3495: '<span class="LC_nobreak">'.
1.118 jms 3496: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3497: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3498: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3499: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3500: '</span>'.$additional.
3501: '</td>'.
1.118 jms 3502: '</tr>';
3503: $itemcount ++;
1.121 raeburn 3504: }
3505: return ($datatable,$itemcount);
3506: }
3507:
3508: sub print_coursedefaults {
1.139 raeburn 3509: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3510: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3511: my $itemcount = 1;
1.160.6.16 raeburn 3512: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3513: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3514: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3515: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3516: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3517: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90 raeburn 3518: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 3519: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3520: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3521: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3522: );
1.160.6.21 raeburn 3523: my %staticdefaults = (
3524: anonsurvey_threshold => 10,
3525: uploadquota => 500,
1.160.6.57 raeburn 3526: postsubmit => 60,
1.160.6.70 raeburn 3527: mysqltables => 172800,
1.160.6.21 raeburn 3528: );
1.139 raeburn 3529: if ($position eq 'top') {
1.160.6.57 raeburn 3530: %defaultchecked = (
3531: 'uselcmath' => 'on',
3532: 'usejsme' => 'on',
1.160.6.64 raeburn 3533: 'canclone' => 'none',
1.160.6.57 raeburn 3534: );
3535: @toggles = ('uselcmath','usejsme');
1.160.6.90 raeburn 3536: my $deftex = $Apache::lonnet::deftex;
3537: if (ref($settings) eq 'HASH') {
3538: if ($settings->{'texengine'}) {
3539: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
3540: $deftex = $settings->{'texengine'};
3541: }
3542: }
3543: }
3544: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3545: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
3546: '<span class="LC_nobreak">'.$choices{'texengine'}.
3547: '</span></td><td class="LC_right_item">'.
3548: '<select name="texengine">'."\n";
3549: my %texoptions = (
3550: MathJax => 'MathJax',
3551: mimetex => &mt('Convert to Images'),
3552: tth => &mt('TeX to HTML'),
3553: );
3554: foreach my $renderer ('MathJax','mimetex','tth') {
3555: my $selected = '';
3556: if ($renderer eq $deftex) {
3557: $selected = ' selected="selected"';
3558: }
3559: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
3560: }
3561: $mathdisp .= '</select></td></tr>'."\n";
3562: $itemcount ++;
1.139 raeburn 3563: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3564: \%choices,$itemcount);
1.160.6.90 raeburn 3565: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 3566: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3567: $datatable .=
3568: '<tr'.$css_class.'><td valign="top">'.
3569: '<span class="LC_nobreak">'.$choices{'canclone'}.
3570: '</span></td><td class="LC_left_item">';
3571: my $currcanclone = 'none';
3572: my $onclick;
3573: my @cloneoptions = ('none','domain');
3574: my %clonetitles = (
3575: none => 'No additional course requesters',
3576: domain => "Any course requester in course's domain",
3577: instcode => 'Course requests for official courses ...',
3578: );
3579: my (%codedefaults,@code_order,@posscodes);
3580: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3581: \@code_order) eq 'ok') {
3582: if (@code_order > 0) {
3583: push(@cloneoptions,'instcode');
3584: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3585: }
3586: }
3587: if (ref($settings) eq 'HASH') {
3588: if ($settings->{'canclone'}) {
3589: if (ref($settings->{'canclone'}) eq 'HASH') {
3590: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3591: if (@code_order > 0) {
3592: $currcanclone = 'instcode';
3593: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3594: }
3595: }
3596: } elsif ($settings->{'canclone'} eq 'domain') {
3597: $currcanclone = $settings->{'canclone'};
3598: }
3599: }
3600: }
3601: foreach my $option (@cloneoptions) {
3602: my ($checked,$additional);
3603: if ($currcanclone eq $option) {
3604: $checked = ' checked="checked"';
3605: }
3606: if ($option eq 'instcode') {
3607: if (@code_order) {
3608: my $show = 'none';
3609: if ($checked) {
3610: $show = 'block';
3611: }
3612: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3613: &mt('Institutional codes for new and cloned course have identical:').
3614: '<br />';
3615: foreach my $item (@code_order) {
3616: my $codechk;
3617: if ($checked) {
3618: if (grep(/^\Q$item\E$/,@posscodes)) {
3619: $codechk = ' checked="checked"';
3620: }
3621: }
3622: $additional .= '<label>'.
3623: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3624: $item.'</label>';
3625: }
3626: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3627: }
3628: }
3629: $datatable .=
3630: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3631: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3632: '</label> '.$additional.'</span><br />';
3633: }
3634: $datatable .= '</td>'.
3635: '</tr>';
3636: $itemcount ++;
1.139 raeburn 3637: } else {
3638: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3639: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3640: my $currusecredits = 0;
1.160.6.57 raeburn 3641: my $postsubmitclient = 1;
1.160.6.30 raeburn 3642: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3643: if (ref($settings) eq 'HASH') {
3644: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3645: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3646: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3647: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3648: }
3649: }
1.160.6.16 raeburn 3650: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3651: foreach my $type (@types) {
3652: next if ($type eq 'community');
3653: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3654: if ($defcredits{$type} ne '') {
3655: $currusecredits = 1;
3656: }
3657: }
3658: }
3659: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3660: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3661: $postsubmitclient = 0;
3662: foreach my $type (@types) {
3663: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3664: }
3665: } else {
3666: foreach my $type (@types) {
3667: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3668: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3669: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3670: } else {
3671: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3672: }
3673: } else {
3674: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3675: }
3676: }
3677: }
3678: } else {
3679: foreach my $type (@types) {
3680: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3681: }
3682: }
1.160.6.70 raeburn 3683: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3684: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3685: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3686: }
3687: } else {
3688: foreach my $type (@types) {
3689: $currmysql{$type} = $staticdefaults{'mysqltables'};
3690: }
3691: }
1.160.6.58 raeburn 3692: } else {
3693: foreach my $type (@types) {
3694: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3695: }
1.139 raeburn 3696: }
3697: if (!$currdefresponder) {
1.160.6.21 raeburn 3698: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3699: } elsif ($currdefresponder < 1) {
3700: $currdefresponder = 1;
3701: }
1.160.6.21 raeburn 3702: foreach my $type (@types) {
3703: if ($curruploadquota{$type} eq '') {
3704: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3705: }
3706: }
1.139 raeburn 3707: $datatable .=
1.160.6.16 raeburn 3708: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3709: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3710: '</span></td>'.
3711: '<td class="LC_right_item"><span class="LC_nobreak">'.
3712: '<input type="text" name="anonsurvey_threshold"'.
3713: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3714: '</td></tr>'."\n";
3715: $itemcount ++;
3716: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3717: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3718: $choices{'uploadquota'}.
3719: '</span></td>'.
3720: '<td align="right" class="LC_right_item">'.
3721: '<table><tr>';
1.160.6.21 raeburn 3722: foreach my $type (@types) {
3723: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3724: '<input type="text" name="uploadquota_'.$type.'"'.
3725: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3726: }
3727: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3728: $itemcount ++;
1.160.6.40 raeburn 3729: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3730: my $display = 'none';
3731: if ($currusecredits) {
3732: $display = 'block';
3733: }
3734: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3735: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3736: foreach my $type (@types) {
3737: next if ($type eq 'community');
3738: $additional .= '<td align="center">'.&mt($type).'<br />'.
3739: '<input type="text" name="'.$type.'_credits"'.
3740: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3741: }
3742: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3743: %defaultchecked = ('coursecredits' => 'off');
3744: @toggles = ('coursecredits');
3745: my $current = {
3746: 'coursecredits' => $currusecredits,
3747: };
3748: (my $table,$itemcount) =
3749: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3750: \%choices,$itemcount,$onclick,$additional,'left');
3751: $datatable .= $table;
3752: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3753: my $display = 'none';
3754: if ($postsubmitclient) {
3755: $display = 'block';
3756: }
3757: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3758: &mt('Number of seconds submit is disabled').'<br />'.
3759: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3760: '<table><tr>';
1.160.6.57 raeburn 3761: foreach my $type (@types) {
3762: $additional .= '<td align="center">'.&mt($type).'<br />'.
3763: '<input type="text" name="'.$type.'_timeout" value="'.
3764: $deftimeout{$type}.'" size="5" /></td>';
3765: }
3766: $additional .= '</tr></table></div>'."\n";
3767: %defaultchecked = ('postsubmit' => 'on');
3768: @toggles = ('postsubmit');
1.160.6.70 raeburn 3769: $current = {
3770: 'postsubmit' => $postsubmitclient,
3771: };
1.160.6.57 raeburn 3772: ($table,$itemcount) =
3773: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3774: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3775: $datatable .= $table;
1.160.6.70 raeburn 3776: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3777: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3778: $choices{'mysqltables'}.
3779: '</span></td>'.
3780: '<td align="right" class="LC_right_item">'.
3781: '<table><tr>';
3782: foreach my $type (@types) {
3783: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3784: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 3785: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 3786: }
3787: $datatable .= '</tr></table></td></tr>'."\n";
3788: $itemcount ++;
3789:
1.160.6.37 raeburn 3790: }
3791: $$rowtotal += $itemcount;
3792: return $datatable;
3793: }
3794:
3795: sub print_selfenrollment {
3796: my ($position,$dom,$settings,$rowtotal) = @_;
3797: my ($css_class,$datatable);
3798: my $itemcount = 1;
3799: my @types = ('official','unofficial','community','textbook');
3800: if (($position eq 'top') || ($position eq 'middle')) {
3801: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3802: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3803: my @rows;
3804: my $key;
3805: if ($position eq 'top') {
3806: $key = 'admin';
3807: if (ref($rowsref) eq 'ARRAY') {
3808: @rows = @{$rowsref};
3809: }
3810: } elsif ($position eq 'middle') {
3811: $key = 'default';
3812: @rows = ('types','registered','approval','limit');
3813: }
3814: foreach my $row (@rows) {
3815: if (defined($titlesref->{$row})) {
3816: $itemcount ++;
3817: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3818: $datatable .= '<tr'.$css_class.'>'.
3819: '<td>'.$titlesref->{$row}.'</td>'.
3820: '<td class="LC_left_item">'.
3821: '<table><tr>';
3822: my (%current,%currentcap);
3823: if (ref($settings) eq 'HASH') {
3824: if (ref($settings->{$key}) eq 'HASH') {
3825: foreach my $type (@types) {
3826: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3827: $current{$type} = $settings->{$key}->{$type}->{$row};
3828: }
3829: if (($row eq 'limit') && ($key eq 'default')) {
3830: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3831: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3832: }
3833: }
3834: }
3835: }
3836: }
3837: my %roles = (
3838: '0' => &Apache::lonnet::plaintext('dc'),
3839: );
3840:
3841: foreach my $type (@types) {
3842: unless (($row eq 'registered') && ($key eq 'default')) {
3843: $datatable .= '<th>'.&mt($type).'</th>';
3844: }
3845: }
3846: unless (($row eq 'registered') && ($key eq 'default')) {
3847: $datatable .= '</tr><tr>';
3848: }
3849: foreach my $type (@types) {
3850: if ($type eq 'community') {
3851: $roles{'1'} = &mt('Community personnel');
3852: } else {
3853: $roles{'1'} = &mt('Course personnel');
3854: }
3855: $datatable .= '<td style="vertical-align: top">';
3856: if ($position eq 'top') {
3857: my %checked;
3858: if ($current{$type} eq '0') {
3859: $checked{'0'} = ' checked="checked"';
3860: } else {
3861: $checked{'1'} = ' checked="checked"';
3862: }
3863: foreach my $role ('1','0') {
3864: $datatable .= '<span class="LC_nobreak"><label>'.
3865: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3866: 'value="'.$role.'"'.$checked{$role}.' />'.
3867: $roles{$role}.'</label></span> ';
3868: }
3869: } else {
3870: if ($row eq 'types') {
3871: my %checked;
3872: if ($current{$type} =~ /^(all|dom)$/) {
3873: $checked{$1} = ' checked="checked"';
3874: } else {
3875: $checked{''} = ' checked="checked"';
3876: }
3877: foreach my $val ('','dom','all') {
3878: $datatable .= '<span class="LC_nobreak"><label>'.
3879: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3880: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3881: }
3882: } elsif ($row eq 'registered') {
3883: my %checked;
3884: if ($current{$type} eq '1') {
3885: $checked{'1'} = ' checked="checked"';
3886: } else {
3887: $checked{'0'} = ' checked="checked"';
3888: }
3889: foreach my $val ('0','1') {
3890: $datatable .= '<span class="LC_nobreak"><label>'.
3891: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3892: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3893: }
3894: } elsif ($row eq 'approval') {
3895: my %checked;
3896: if ($current{$type} =~ /^([12])$/) {
3897: $checked{$1} = ' checked="checked"';
3898: } else {
3899: $checked{'0'} = ' checked="checked"';
3900: }
3901: for my $val (0..2) {
3902: $datatable .= '<span class="LC_nobreak"><label>'.
3903: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3904: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3905: }
3906: } elsif ($row eq 'limit') {
3907: my %checked;
3908: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3909: $checked{$1} = ' checked="checked"';
3910: } else {
3911: $checked{'none'} = ' checked="checked"';
3912: }
3913: my $cap;
3914: if ($currentcap{$type} =~ /^\d+$/) {
3915: $cap = $currentcap{$type};
3916: }
3917: foreach my $val ('none','allstudents','selfenrolled') {
3918: $datatable .= '<span class="LC_nobreak"><label>'.
3919: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3920: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3921: }
3922: $datatable .= '<br />'.
3923: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3924: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3925: '</span>';
3926: }
3927: }
3928: $datatable .= '</td>';
3929: }
3930: $datatable .= '</tr>';
3931: }
3932: $datatable .= '</table></td></tr>';
3933: }
3934: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3935: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3936: }
3937: $$rowtotal += $itemcount;
3938: return $datatable;
3939: }
3940:
3941: sub print_validation_rows {
3942: my ($caller,$dom,$settings,$rowtotal) = @_;
3943: my ($itemsref,$namesref,$fieldsref);
3944: if ($caller eq 'selfenroll') {
3945: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3946: } elsif ($caller eq 'requestcourses') {
3947: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3948: }
3949: my %currvalidation;
3950: if (ref($settings) eq 'HASH') {
3951: if (ref($settings->{'validation'}) eq 'HASH') {
3952: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3953: }
1.160.6.39 raeburn 3954: }
3955: my $datatable;
3956: my $itemcount = 0;
3957: foreach my $item (@{$itemsref}) {
3958: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3959: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3960: $namesref->{$item}.
3961: '</span></td>'.
3962: '<td class="LC_left_item">';
3963: if (($item eq 'url') || ($item eq 'button')) {
3964: $datatable .= '<span class="LC_nobreak">'.
3965: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3966: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3967: } elsif ($item eq 'fields') {
3968: my @currfields;
3969: if (ref($currvalidation{$item}) eq 'ARRAY') {
3970: @currfields = @{$currvalidation{$item}};
3971: }
3972: foreach my $field (@{$fieldsref}) {
3973: my $check = '';
3974: if (grep(/^\Q$field\E$/,@currfields)) {
3975: $check = ' checked="checked"';
3976: }
3977: $datatable .= '<span class="LC_nobreak"><label>'.
3978: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3979: ' value="'.$field.'"'.$check.' />'.$field.
3980: '</label></span> ';
3981: }
3982: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 3983: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 3984: $currvalidation{$item}.
1.160.6.37 raeburn 3985: '</textarea>';
1.160.6.39 raeburn 3986: }
3987: $datatable .= '</td></tr>'."\n";
3988: if (ref($rowtotal)) {
1.160.6.37 raeburn 3989: $itemcount ++;
3990: }
1.139 raeburn 3991: }
1.160.6.39 raeburn 3992: if ($caller eq 'requestcourses') {
3993: my %currhash;
1.160.6.51 raeburn 3994: if (ref($settings) eq 'HASH') {
3995: if (ref($settings->{'validation'}) eq 'HASH') {
3996: if ($settings->{'validation'}{'dc'} ne '') {
3997: $currhash{$settings->{'validation'}{'dc'}} = 1;
3998: }
1.160.6.39 raeburn 3999: }
4000: }
4001: my $numinrow = 2;
4002: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4003: 'validationdc',%currhash);
1.160.6.50 raeburn 4004: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 4005: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 4006: if ($numdc > 1) {
1.160.6.50 raeburn 4007: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4008: } else {
1.160.6.50 raeburn 4009: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4010: }
1.160.6.50 raeburn 4011: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4012: $itemcount ++;
4013: }
4014: if (ref($rowtotal)) {
4015: $$rowtotal += $itemcount;
4016: }
1.121 raeburn 4017: return $datatable;
1.118 jms 4018: }
4019:
1.137 raeburn 4020: sub print_usersessions {
4021: my ($position,$dom,$settings,$rowtotal) = @_;
4022: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 4023: my (%by_ip,%by_location,@intdoms);
4024: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 4025:
4026: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4027: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4028: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4029: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4030: my $itemcount = 1;
4031: if ($position eq 'top') {
1.152 raeburn 4032: if (keys(%serverhomes) > 1) {
1.145 raeburn 4033: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 4034: my $curroffloadnow;
4035: if (ref($settings) eq 'HASH') {
4036: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4037: $curroffloadnow = $settings->{'offloadnow'};
4038: }
4039: }
4040: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4041: } else {
1.140 raeburn 4042: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4043: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 4044: }
1.137 raeburn 4045: } else {
1.145 raeburn 4046: if (keys(%by_location) == 0) {
4047: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4048: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 4049: } else {
4050: my %lt = &usersession_titles();
4051: my $numinrow = 5;
4052: my $prefix;
4053: my @types;
4054: if ($position eq 'bottom') {
4055: $prefix = 'remote';
4056: @types = ('version','excludedomain','includedomain');
4057: } else {
4058: $prefix = 'hosted';
4059: @types = ('excludedomain','includedomain');
4060: }
4061: my (%current,%checkedon,%checkedoff);
4062: my @lcversions = &Apache::lonnet::all_loncaparevs();
4063: my @locations = sort(keys(%by_location));
4064: foreach my $type (@types) {
4065: $checkedon{$type} = '';
4066: $checkedoff{$type} = ' checked="checked"';
4067: }
4068: if (ref($settings) eq 'HASH') {
4069: if (ref($settings->{$prefix}) eq 'HASH') {
4070: foreach my $key (keys(%{$settings->{$prefix}})) {
4071: $current{$key} = $settings->{$prefix}{$key};
4072: if ($key eq 'version') {
4073: if ($current{$key} ne '') {
4074: $checkedon{$key} = ' checked="checked"';
4075: $checkedoff{$key} = '';
4076: }
4077: } elsif (ref($current{$key}) eq 'ARRAY') {
4078: $checkedon{$key} = ' checked="checked"';
4079: $checkedoff{$key} = '';
4080: }
1.137 raeburn 4081: }
4082: }
4083: }
1.145 raeburn 4084: foreach my $type (@types) {
4085: next if ($type ne 'version' && !@locations);
4086: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4087: $datatable .= '<tr'.$css_class.'>
4088: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4089: <span class="LC_nobreak">
4090: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4091: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4092: if ($type eq 'version') {
4093: my $selector = '<select name="'.$prefix.'_version">';
4094: foreach my $version (@lcversions) {
4095: my $selected = '';
4096: if ($current{'version'} eq $version) {
4097: $selected = ' selected="selected"';
4098: }
4099: $selector .= ' <option value="'.$version.'"'.
4100: $selected.'>'.$version.'</option>';
4101: }
4102: $selector .= '</select> ';
4103: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4104: } else {
4105: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4106: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4107: ' />'.(' 'x2).
4108: '<input type="button" value="'.&mt('uncheck all').'" '.
4109: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4110: "\n".
4111: '</div><div><table>';
4112: my $rem;
4113: for (my $i=0; $i<@locations; $i++) {
4114: my ($showloc,$value,$checkedtype);
4115: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4116: my $ip = $by_location{$locations[$i]}->[0];
4117: if (ref($by_ip{$ip}) eq 'ARRAY') {
4118: $value = join(':',@{$by_ip{$ip}});
4119: $showloc = join(', ',@{$by_ip{$ip}});
4120: if (ref($current{$type}) eq 'ARRAY') {
4121: foreach my $loc (@{$by_ip{$ip}}) {
4122: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4123: $checkedtype = ' checked="checked"';
4124: last;
4125: }
4126: }
1.138 raeburn 4127: }
4128: }
4129: }
1.145 raeburn 4130: $rem = $i%($numinrow);
4131: if ($rem == 0) {
4132: if ($i > 0) {
4133: $datatable .= '</tr>';
4134: }
4135: $datatable .= '<tr>';
4136: }
4137: $datatable .= '<td class="LC_left_item">'.
4138: '<span class="LC_nobreak"><label>'.
4139: '<input type="checkbox" name="'.$prefix.'_'.$type.
4140: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4141: '</label></span></td>';
1.137 raeburn 4142: }
1.145 raeburn 4143: $rem = @locations%($numinrow);
4144: my $colsleft = $numinrow - $rem;
4145: if ($colsleft > 1 ) {
4146: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4147: ' </td>';
4148: } elsif ($colsleft == 1) {
4149: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4150: }
1.145 raeburn 4151: $datatable .= '</tr></table>';
1.137 raeburn 4152: }
1.145 raeburn 4153: $datatable .= '</td></tr>';
4154: $itemcount ++;
1.137 raeburn 4155: }
4156: }
4157: }
4158: $$rowtotal += $itemcount;
4159: return $datatable;
4160: }
4161:
1.138 raeburn 4162: sub build_location_hashes {
4163: my ($intdoms,$by_ip,$by_location) = @_;
4164: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4165: (ref($by_location) eq 'HASH'));
4166: my %iphost = &Apache::lonnet::get_iphost();
4167: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4168: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4169: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4170: foreach my $id (@{$iphost{$primary_ip}}) {
4171: my $intdom = &Apache::lonnet::internet_dom($id);
4172: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4173: push(@{$intdoms},$intdom);
4174: }
4175: }
4176: }
4177: foreach my $ip (keys(%iphost)) {
4178: if (ref($iphost{$ip}) eq 'ARRAY') {
4179: foreach my $id (@{$iphost{$ip}}) {
4180: my $location = &Apache::lonnet::internet_dom($id);
4181: if ($location) {
4182: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4183: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4184: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4185: push(@{$by_ip->{$ip}},$location);
4186: }
4187: } else {
4188: $by_ip->{$ip} = [$location];
4189: }
4190: }
4191: }
4192: }
4193: }
4194: foreach my $ip (sort(keys(%{$by_ip}))) {
4195: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4196: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4197: my $first = $by_ip->{$ip}->[0];
4198: if (ref($by_location->{$first}) eq 'ARRAY') {
4199: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4200: push(@{$by_location->{$first}},$ip);
4201: }
4202: } else {
4203: $by_location->{$first} = [$ip];
4204: }
4205: }
4206: }
4207: return;
4208: }
4209:
1.145 raeburn 4210: sub current_offloads_to {
4211: my ($dom,$settings,$servers) = @_;
4212: my (%spareid,%otherdomconfigs);
1.152 raeburn 4213: if (ref($servers) eq 'HASH') {
1.145 raeburn 4214: foreach my $lonhost (sort(keys(%{$servers}))) {
4215: my $gotspares;
1.152 raeburn 4216: if (ref($settings) eq 'HASH') {
4217: if (ref($settings->{'spares'}) eq 'HASH') {
4218: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4219: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4220: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4221: $gotspares = 1;
4222: }
1.145 raeburn 4223: }
4224: }
4225: unless ($gotspares) {
4226: my $gotspares;
4227: my $serverhomeID =
4228: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4229: my $serverhomedom =
4230: &Apache::lonnet::host_domain($serverhomeID);
4231: if ($serverhomedom ne $dom) {
4232: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4233: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4234: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4235: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4236: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4237: $gotspares = 1;
4238: }
4239: }
4240: } else {
4241: $otherdomconfigs{$serverhomedom} =
4242: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4243: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4244: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4245: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4246: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4247: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4248: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4249: $gotspares = 1;
4250: }
4251: }
4252: }
4253: }
4254: }
4255: }
4256: }
4257: unless ($gotspares) {
4258: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4259: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4260: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4261: } else {
4262: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4263: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4264: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4265: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4266: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4267: } else {
1.150 raeburn 4268: my %what = (
4269: spareid => 1,
4270: );
4271: my ($result,$returnhash) =
4272: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4273: if ($result eq 'ok') {
4274: if (ref($returnhash) eq 'HASH') {
4275: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4276: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4277: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4278: }
4279: }
1.145 raeburn 4280: }
4281: }
4282: }
4283: }
4284: }
4285: }
4286: return %spareid;
4287: }
4288:
4289: sub spares_row {
1.160.6.61 raeburn 4290: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4291: my $css_class;
4292: my $numinrow = 4;
4293: my $itemcount = 1;
4294: my $datatable;
1.152 raeburn 4295: my %typetitles = &sparestype_titles();
4296: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4297: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4298: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4299: my ($othercontrol,$serverdom);
4300: if ($serverhome ne $server) {
4301: $serverdom = &Apache::lonnet::host_domain($serverhome);
4302: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4303: } else {
4304: $serverdom = &Apache::lonnet::host_domain($server);
4305: if ($serverdom ne $dom) {
4306: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4307: }
4308: }
4309: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4310: my $checkednow;
4311: if (ref($curroffloadnow) eq 'HASH') {
4312: if ($curroffloadnow->{$server}) {
4313: $checkednow = ' checked="checked"';
4314: }
4315: }
1.145 raeburn 4316: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4317: $datatable .= '<tr'.$css_class.'>
4318: <td rowspan="2">
1.160.6.13 raeburn 4319: <span class="LC_nobreak">'.
4320: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4321: ,'<b>'.$server.'</b>').'</span><br />'.
4322: '<span class="LC_nobreak">'."\n".
4323: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4324: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4325: "\n";
1.145 raeburn 4326: my (%current,%canselect);
1.152 raeburn 4327: my @choices =
4328: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4329: foreach my $type ('primary','default') {
4330: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4331: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4332: my @spares = @{$spareid->{$server}{$type}};
4333: if (@spares > 0) {
1.152 raeburn 4334: if ($othercontrol) {
4335: $current{$type} = join(', ',@spares);
4336: } else {
4337: $current{$type} .= '<table>';
4338: my $numspares = scalar(@spares);
4339: for (my $i=0; $i<@spares; $i++) {
4340: my $rem = $i%($numinrow);
4341: if ($rem == 0) {
4342: if ($i > 0) {
4343: $current{$type} .= '</tr>';
4344: }
4345: $current{$type} .= '<tr>';
1.145 raeburn 4346: }
1.152 raeburn 4347: $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'".');" /> '.
4348: $spareid->{$server}{$type}[$i].
4349: '</label></td>'."\n";
4350: }
4351: my $rem = @spares%($numinrow);
4352: my $colsleft = $numinrow - $rem;
4353: if ($colsleft > 1 ) {
4354: $current{$type} .= '<td colspan="'.$colsleft.
4355: '" class="LC_left_item">'.
4356: ' </td>';
4357: } elsif ($colsleft == 1) {
4358: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4359: }
1.152 raeburn 4360: $current{$type} .= '</tr></table>';
1.150 raeburn 4361: }
1.145 raeburn 4362: }
4363: }
4364: if ($current{$type} eq '') {
4365: $current{$type} = &mt('None specified');
4366: }
1.152 raeburn 4367: if ($othercontrol) {
4368: if ($type eq 'primary') {
4369: $canselect{$type} = $othercontrol;
4370: }
4371: } else {
4372: $canselect{$type} =
4373: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4374: '<select name="newspare_'.$type.'_'.$server.'" '.
4375: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4376: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4377: if (@choices > 0) {
4378: foreach my $lonhost (@choices) {
4379: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4380: }
4381: }
4382: $canselect{$type} .= '</select>'."\n";
4383: }
4384: } else {
4385: $current{$type} = &mt('Could not be determined');
4386: if ($type eq 'primary') {
4387: $canselect{$type} = $othercontrol;
4388: }
1.145 raeburn 4389: }
1.152 raeburn 4390: if ($type eq 'default') {
4391: $datatable .= '<tr'.$css_class.'>';
4392: }
4393: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4394: '<td>'.$current{$type}.'</td>'."\n".
4395: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4396: }
4397: $itemcount ++;
4398: }
4399: }
4400: $$rowtotal += $itemcount;
4401: return $datatable;
4402: }
4403:
1.152 raeburn 4404: sub possible_newspares {
4405: my ($server,$currspares,$serverhomes,$altids) = @_;
4406: my $serverhostname = &Apache::lonnet::hostname($server);
4407: my %excluded;
4408: if ($serverhostname ne '') {
4409: %excluded = (
4410: $serverhostname => 1,
4411: );
4412: }
4413: if (ref($currspares) eq 'HASH') {
4414: foreach my $type (keys(%{$currspares})) {
4415: if (ref($currspares->{$type}) eq 'ARRAY') {
4416: if (@{$currspares->{$type}} > 0) {
4417: foreach my $curr (@{$currspares->{$type}}) {
4418: my $hostname = &Apache::lonnet::hostname($curr);
4419: $excluded{$hostname} = 1;
4420: }
4421: }
4422: }
4423: }
4424: }
4425: my @choices;
4426: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4427: if (keys(%{$serverhomes}) > 1) {
4428: foreach my $name (sort(keys(%{$serverhomes}))) {
4429: unless ($excluded{$name}) {
4430: if (exists($altids->{$serverhomes->{$name}})) {
4431: push(@choices,$altids->{$serverhomes->{$name}});
4432: } else {
4433: push(@choices,$serverhomes->{$name});
1.145 raeburn 4434: }
4435: }
4436: }
4437: }
4438: }
1.152 raeburn 4439: return sort(@choices);
1.145 raeburn 4440: }
4441:
1.150 raeburn 4442: sub print_loadbalancing {
4443: my ($dom,$settings,$rowtotal) = @_;
4444: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4445: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4446: my $numinrow = 1;
4447: my $datatable;
4448: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 4449: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 4450: if (ref($settings) eq 'HASH') {
4451: %existing = %{$settings};
4452: }
4453: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4454: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 4455: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 4456: } else {
4457: return;
4458: }
4459: my ($othertitle,$usertypes,$types) =
4460: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 4461: my $rownum = 8;
1.150 raeburn 4462: if (ref($types) eq 'ARRAY') {
4463: $rownum += scalar(@{$types});
4464: }
1.160.6.7 raeburn 4465: my @css_class = ('LC_odd_row','LC_even_row');
4466: my $balnum = 0;
4467: my $islast;
4468: my (@toshow,$disabledtext);
4469: if (keys(%currbalancer) > 0) {
4470: @toshow = sort(keys(%currbalancer));
4471: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4472: push(@toshow,'');
4473: }
4474: } else {
4475: @toshow = ('');
4476: $disabledtext = &mt('No existing load balancer');
4477: }
4478: foreach my $lonhost (@toshow) {
4479: if ($balnum == scalar(@toshow)-1) {
4480: $islast = 1;
4481: } else {
4482: $islast = 0;
4483: }
4484: my $cssidx = $balnum%2;
4485: my $targets_div_style = 'display: none';
4486: my $disabled_div_style = 'display: block';
4487: my $homedom_div_style = 'display: none';
4488: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4489: '<td rowspan="'.$rownum.'" valign="top">'.
4490: '<p>';
4491: if ($lonhost eq '') {
4492: $datatable .= '<span class="LC_nobreak">';
4493: if (keys(%currbalancer) > 0) {
4494: $datatable .= &mt('Add balancer:');
4495: } else {
4496: $datatable .= &mt('Enable balancer:');
4497: }
4498: $datatable .= ' '.
4499: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4500: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4501: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4502: '<option value="" selected="selected">'.&mt('None').
4503: '</option>'."\n";
4504: foreach my $server (sort(keys(%servers))) {
4505: next if ($currbalancer{$server});
4506: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4507: }
4508: $datatable .=
4509: '</select>'."\n".
4510: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4511: } else {
4512: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4513: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4514: &mt('Stop balancing').'</label>'.
4515: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4516: $targets_div_style = 'display: block';
4517: $disabled_div_style = 'display: none';
4518: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4519: $homedom_div_style = 'display: block';
4520: }
4521: }
4522: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4523: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4524: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4525: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4526: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4527: my @sparestypes = ('primary','default');
4528: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 4529: my %hostherechecked = (
4530: no => ' checked="checked"',
4531: );
1.160.6.94 raeburn 4532: my %balcookiechecked = (
4533: no => ' checked="checked"',
4534: );
1.160.6.7 raeburn 4535: foreach my $sparetype (@sparestypes) {
4536: my $targettable;
4537: for (my $i=0; $i<$numspares; $i++) {
4538: my $checked;
4539: if (ref($currtargets{$lonhost}) eq 'HASH') {
4540: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4541: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4542: $checked = ' checked="checked"';
4543: }
4544: }
4545: }
4546: my ($chkboxval,$disabled);
4547: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4548: $chkboxval = $spares[$i];
4549: }
4550: if (exists($currbalancer{$spares[$i]})) {
4551: $disabled = ' disabled="disabled"';
4552: }
4553: $targettable .=
1.160.6.55 raeburn 4554: '<td><span class="LC_nobreak"><label>'.
4555: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 4556: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.160.6.55 raeburn 4557: '</span></label></span></td>';
1.160.6.7 raeburn 4558: my $rem = $i%($numinrow);
4559: if ($rem == 0) {
4560: if (($i > 0) && ($i < $numspares-1)) {
4561: $targettable .= '</tr>';
4562: }
4563: if ($i < $numspares-1) {
4564: $targettable .= '<tr>';
1.150 raeburn 4565: }
4566: }
4567: }
1.160.6.7 raeburn 4568: if ($targettable ne '') {
4569: my $rem = $numspares%($numinrow);
4570: my $colsleft = $numinrow - $rem;
4571: if ($colsleft > 1 ) {
4572: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4573: ' </td>';
4574: } elsif ($colsleft == 1) {
4575: $targettable .= '<td class="LC_left_item"> </td>';
4576: }
4577: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4578: '<table><tr>'.$targettable.'</tr></table><br />';
4579: }
1.160.6.76 raeburn 4580: $hostherechecked{$sparetype} = '';
4581: if (ref($currtargets{$lonhost}) eq 'HASH') {
4582: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4583: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4584: $hostherechecked{$sparetype} = ' checked="checked"';
4585: $hostherechecked{'no'} = '';
4586: }
4587: }
4588: }
4589: }
1.160.6.94 raeburn 4590: if ($currcookies{$lonhost}) {
4591: %balcookiechecked = (
4592: yes => ' checked="checked"',
4593: );
4594: }
1.160.6.76 raeburn 4595: $datatable .= &mt('Hosting on balancer itself').'<br />'.
4596: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
4597: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
4598: foreach my $sparetype (@sparestypes) {
4599: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
4600: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
4601: '</i></label><br />';
1.160.6.7 raeburn 4602: }
1.160.6.94 raeburn 4603: $datatable .= &mt('Use balancer cookie').'<br />'.
4604: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
4605: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
4606: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
4607: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
4608: '</div></td></tr>'.
1.160.6.7 raeburn 4609: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4610: $othertitle,$usertypes,$types,\%servers,
4611: \%currbalancer,$lonhost,
4612: $targets_div_style,$homedom_div_style,
4613: $css_class[$cssidx],$balnum,$islast);
4614: $$rowtotal += $rownum;
4615: $balnum ++;
4616: }
4617: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4618: return $datatable;
4619: }
4620:
4621: sub get_loadbalancers_config {
1.160.6.94 raeburn 4622: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 4623: return unless ((ref($servers) eq 'HASH') &&
4624: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 4625: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
4626: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 4627: if (keys(%{$existing}) > 0) {
4628: my $oldlonhost;
4629: foreach my $key (sort(keys(%{$existing}))) {
4630: if ($key eq 'lonhost') {
4631: $oldlonhost = $existing->{'lonhost'};
4632: $currbalancer->{$oldlonhost} = 1;
4633: } elsif ($key eq 'targets') {
4634: if ($oldlonhost) {
4635: $currtargets->{$oldlonhost} = $existing->{'targets'};
4636: }
4637: } elsif ($key eq 'rules') {
4638: if ($oldlonhost) {
4639: $currrules->{$oldlonhost} = $existing->{'rules'};
4640: }
4641: } elsif (ref($existing->{$key}) eq 'HASH') {
4642: $currbalancer->{$key} = 1;
4643: $currtargets->{$key} = $existing->{$key}{'targets'};
4644: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 4645: if ($existing->{$key}{'cookie'}) {
4646: $currcookies->{$key} = 1;
4647: }
1.150 raeburn 4648: }
4649: }
1.160.6.7 raeburn 4650: } else {
4651: my ($balancerref,$targetsref) =
4652: &Apache::lonnet::get_lonbalancer_config($servers);
4653: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4654: foreach my $server (sort(keys(%{$balancerref}))) {
4655: $currbalancer->{$server} = 1;
4656: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4657: }
4658: }
4659: }
1.160.6.7 raeburn 4660: return;
1.150 raeburn 4661: }
4662:
4663: sub loadbalancing_rules {
4664: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 4665: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4666: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4667: my $output;
1.160.6.7 raeburn 4668: my $num = 0;
4669: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4670: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4671: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4672: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 4673: $num ++;
1.150 raeburn 4674: my $current;
4675: if (ref($currrules) eq 'HASH') {
4676: $current = $currrules->{$type};
4677: }
1.160.6.55 raeburn 4678: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 4679: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4680: $current = '';
4681: }
4682: }
4683: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 4684: $servers,$currbalancer,$lonhost,$dom,
4685: $targets_div_style,$homedom_div_style,
4686: $css_class,$balnum,$num,$islast);
1.150 raeburn 4687: }
4688: }
4689: return $output;
4690: }
4691:
4692: sub loadbalancing_titles {
4693: my ($dom,$intdom,$usertypes,$types) = @_;
4694: my %othertypes = (
4695: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4696: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4697: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4698: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 4699: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4700: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4701: );
1.160.6.26 raeburn 4702: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 4703: my @available;
1.150 raeburn 4704: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 4705: @available = @{$types};
1.150 raeburn 4706: }
1.160.6.89 raeburn 4707: unless (grep(/^default$/,@available)) {
4708: push(@available,'default');
4709: }
4710: unshift(@alltypes,@available);
1.150 raeburn 4711: my %titles;
4712: foreach my $type (@alltypes) {
4713: if ($type =~ /^_LC_/) {
4714: $titles{$type} = $othertypes{$type};
4715: } elsif ($type eq 'default') {
4716: $titles{$type} = &mt('All users from [_1]',$dom);
4717: if (ref($types) eq 'ARRAY') {
4718: if (@{$types} > 0) {
4719: $titles{$type} = &mt('Other users from [_1]',$dom);
4720: }
4721: }
4722: } elsif (ref($usertypes) eq 'HASH') {
4723: $titles{$type} = $usertypes->{$type};
4724: }
4725: }
4726: return (\@alltypes,\%othertypes,\%titles);
4727: }
4728:
4729: sub loadbalance_rule_row {
1.160.6.7 raeburn 4730: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4731: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4732: my @rulenames;
1.150 raeburn 4733: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4734: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4735: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4736: } else {
1.160.6.26 raeburn 4737: @rulenames = ('default','homeserver');
4738: if ($type eq '_LC_external') {
4739: push(@rulenames,'externalbalancer');
4740: } else {
4741: push(@rulenames,'specific');
4742: }
4743: push(@rulenames,'none');
1.150 raeburn 4744: }
4745: my $style = $targets_div_style;
1.160.6.55 raeburn 4746: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4747: $style = $homedom_div_style;
4748: }
1.160.6.7 raeburn 4749: my $space;
4750: if ($islast && $num == 1) {
4751: $space = '<div display="inline-block"> </div>';
4752: }
4753: my $output =
4754: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4755: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4756: '<td valaign="top">'.$space.
4757: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4758: for (my $i=0; $i<@rulenames; $i++) {
4759: my $rule = $rulenames[$i];
4760: my ($checked,$extra);
4761: if ($rulenames[$i] eq 'default') {
4762: $rule = '';
4763: }
4764: if ($rulenames[$i] eq 'specific') {
4765: if (ref($servers) eq 'HASH') {
4766: my $default;
4767: if (($current ne '') && (exists($servers->{$current}))) {
4768: $checked = ' checked="checked"';
4769: }
4770: unless ($checked) {
4771: $default = ' selected="selected"';
4772: }
1.160.6.7 raeburn 4773: $extra =
4774: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4775: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4776: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4777: '<option value=""'.$default.'></option>'."\n";
4778: foreach my $server (sort(keys(%{$servers}))) {
4779: if (ref($currbalancer) eq 'HASH') {
4780: next if (exists($currbalancer->{$server}));
4781: }
1.150 raeburn 4782: my $selected;
1.160.6.7 raeburn 4783: if ($server eq $current) {
1.150 raeburn 4784: $selected = ' selected="selected"';
4785: }
1.160.6.7 raeburn 4786: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4787: }
4788: $extra .= '</select>';
4789: }
4790: } elsif ($rule eq $current) {
4791: $checked = ' checked="checked"';
4792: }
4793: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4794: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4795: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4796: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4797: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4798: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4799: $output .= $ruletitles{'particular'};
4800: } else {
4801: $output .= $ruletitles{$rulenames[$i]};
4802: }
4803: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4804: }
4805: $output .= '</div></td></tr>'."\n";
4806: return $output;
4807: }
4808:
4809: sub offloadtype_text {
4810: my %ruletitles = &Apache::lonlocal::texthash (
4811: 'default' => 'Offloads to default destinations',
4812: 'homeserver' => "Offloads to user's home server",
4813: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4814: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4815: 'none' => 'No offload',
1.160.6.26 raeburn 4816: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4817: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4818: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4819: );
4820: return %ruletitles;
4821: }
4822:
4823: sub sparestype_titles {
4824: my %typestitles = &Apache::lonlocal::texthash (
4825: 'primary' => 'primary',
4826: 'default' => 'default',
4827: );
4828: return %typestitles;
4829: }
4830:
1.28 raeburn 4831: sub contact_titles {
4832: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 4833: 'supportemail' => 'Support E-mail address',
4834: 'adminemail' => 'Default Server Admin E-mail address',
4835: 'errormail' => 'Error reports to be e-mailed to',
4836: 'packagesmail' => 'Package update alerts to be e-mailed to',
4837: 'helpdeskmail' => "Helpdesk requests for this domain's users",
4838: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
4839: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
4840: 'requestsmail' => 'E-mail from course requests requiring approval',
4841: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4842: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 4843: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.28 raeburn 4844: );
4845: my %short_titles = &Apache::lonlocal::texthash (
4846: adminemail => 'Admin E-mail address',
4847: supportemail => 'Support E-mail',
4848: );
4849: return (\%titles,\%short_titles);
4850: }
4851:
1.160.6.78 raeburn 4852: sub helpform_fields {
4853: my %titles = &Apache::lonlocal::texthash (
4854: 'username' => 'Name',
4855: 'user' => 'Username/domain',
4856: 'phone' => 'Phone',
4857: 'cc' => 'Cc e-mail',
4858: 'course' => 'Course Details',
4859: 'section' => 'Sections',
4860: 'screenshot' => 'File upload',
4861: );
4862: my @fields = ('username','phone','user','course','section','cc','screenshot');
4863: my %possoptions = (
4864: username => ['yes','no','req'],
4865: phone => ['yes','no','req'],
4866: user => ['yes','no'],
4867: cc => ['yes','no'],
4868: course => ['yes','no'],
4869: section => ['yes','no'],
4870: screenshot => ['yes','no'],
4871: );
4872: my %fieldoptions = &Apache::lonlocal::texthash (
4873: 'yes' => 'Optional',
4874: 'req' => 'Required',
4875: 'no' => "Not shown",
4876: );
4877: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
4878: }
4879:
1.72 raeburn 4880: sub tool_titles {
4881: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4882: aboutme => 'Personal web page',
1.86 raeburn 4883: blog => 'Blog',
1.160.6.4 raeburn 4884: webdav => 'WebDAV',
1.86 raeburn 4885: portfolio => 'Portfolio',
1.88 bisitz 4886: official => 'Official courses (with institutional codes)',
4887: unofficial => 'Unofficial courses',
1.98 raeburn 4888: community => 'Communities',
1.160.6.30 raeburn 4889: textbook => 'Textbook courses',
1.86 raeburn 4890: );
1.72 raeburn 4891: return %titles;
4892: }
4893:
1.101 raeburn 4894: sub courserequest_titles {
4895: my %titles = &Apache::lonlocal::texthash (
4896: official => 'Official',
4897: unofficial => 'Unofficial',
4898: community => 'Communities',
1.160.6.30 raeburn 4899: textbook => 'Textbook',
1.101 raeburn 4900: norequest => 'Not allowed',
1.104 raeburn 4901: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4902: validate => 'With validation',
4903: autolimit => 'Numerical limit',
1.103 raeburn 4904: unlimited => '(blank for unlimited)',
1.101 raeburn 4905: );
4906: return %titles;
4907: }
4908:
1.160.6.5 raeburn 4909: sub authorrequest_titles {
4910: my %titles = &Apache::lonlocal::texthash (
4911: norequest => 'Not allowed',
4912: approval => 'Approval by Dom. Coord.',
4913: automatic => 'Automatic approval',
4914: );
4915: return %titles;
4916: }
4917:
1.101 raeburn 4918: sub courserequest_conditions {
4919: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4920: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4921: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4922: );
4923: return %conditions;
4924: }
4925:
4926:
1.27 raeburn 4927: sub print_usercreation {
1.30 raeburn 4928: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4929: my $numinrow = 4;
1.28 raeburn 4930: my $datatable;
4931: if ($position eq 'top') {
1.30 raeburn 4932: $$rowtotal ++;
1.34 raeburn 4933: my $rowcount = 0;
1.32 raeburn 4934: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4935: if (ref($rules) eq 'HASH') {
4936: if (keys(%{$rules}) > 0) {
1.32 raeburn 4937: $datatable .= &user_formats_row('username',$settings,$rules,
4938: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4939: $$rowtotal ++;
1.32 raeburn 4940: $rowcount ++;
4941: }
4942: }
4943: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4944: if (ref($idrules) eq 'HASH') {
4945: if (keys(%{$idrules}) > 0) {
4946: $datatable .= &user_formats_row('id',$settings,$idrules,
4947: $idruleorder,$numinrow,$rowcount);
4948: $$rowtotal ++;
4949: $rowcount ++;
1.28 raeburn 4950: }
4951: }
1.39 raeburn 4952: if ($rowcount == 0) {
4953: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4954: $$rowtotal ++;
4955: $rowcount ++;
4956: }
1.34 raeburn 4957: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4958: my @creators = ('author','course','requestcrs');
1.37 raeburn 4959: my ($rules,$ruleorder) =
4960: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4961: my %lt = &usercreation_types();
4962: my %checked;
4963: if (ref($settings) eq 'HASH') {
4964: if (ref($settings->{'cancreate'}) eq 'HASH') {
4965: foreach my $item (@creators) {
4966: $checked{$item} = $settings->{'cancreate'}{$item};
4967: }
4968: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4969: foreach my $item (@creators) {
4970: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4971: $checked{$item} = 'none';
4972: }
4973: }
4974: }
4975: }
4976: my $rownum = 0;
4977: foreach my $item (@creators) {
4978: $rownum ++;
1.160.6.34 raeburn 4979: if ($checked{$item} eq '') {
4980: $checked{$item} = 'any';
1.34 raeburn 4981: }
4982: my $css_class;
4983: if ($rownum%2) {
4984: $css_class = '';
4985: } else {
4986: $css_class = ' class="LC_odd_row" ';
4987: }
4988: $datatable .= '<tr'.$css_class.'>'.
4989: '<td><span class="LC_nobreak">'.$lt{$item}.
4990: '</span></td><td align="right">';
1.160.6.34 raeburn 4991: my @options = ('any');
4992: if (ref($rules) eq 'HASH') {
4993: if (keys(%{$rules}) > 0) {
4994: push(@options,('official','unofficial'));
1.37 raeburn 4995: }
4996: }
1.160.6.34 raeburn 4997: push(@options,'none');
1.37 raeburn 4998: foreach my $option (@options) {
1.50 raeburn 4999: my $type = 'radio';
1.34 raeburn 5000: my $check = ' ';
1.160.6.34 raeburn 5001: if ($checked{$item} eq $option) {
5002: $check = ' checked="checked" ';
1.34 raeburn 5003: }
5004: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 5005: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5006: $item.'" value="'.$option.'"'.$check.'/> '.
5007: $lt{$option}.'</label> </span>';
5008: }
5009: $datatable .= '</td></tr>';
5010: }
1.28 raeburn 5011: } else {
5012: my @contexts = ('author','course','domain');
5013: my @authtypes = ('int','krb4','krb5','loc');
5014: my %checked;
5015: if (ref($settings) eq 'HASH') {
5016: if (ref($settings->{'authtypes'}) eq 'HASH') {
5017: foreach my $item (@contexts) {
5018: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5019: foreach my $auth (@authtypes) {
5020: if ($settings->{'authtypes'}{$item}{$auth}) {
5021: $checked{$item}{$auth} = ' checked="checked" ';
5022: }
5023: }
5024: }
5025: }
1.27 raeburn 5026: }
1.35 raeburn 5027: } else {
5028: foreach my $item (@contexts) {
1.36 raeburn 5029: foreach my $auth (@authtypes) {
1.35 raeburn 5030: $checked{$item}{$auth} = ' checked="checked" ';
5031: }
5032: }
1.27 raeburn 5033: }
1.28 raeburn 5034: my %title = &context_names();
5035: my %authname = &authtype_names();
5036: my $rownum = 0;
5037: my $css_class;
5038: foreach my $item (@contexts) {
5039: if ($rownum%2) {
5040: $css_class = '';
5041: } else {
5042: $css_class = ' class="LC_odd_row" ';
5043: }
1.30 raeburn 5044: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5045: '<td>'.$title{$item}.
5046: '</td><td class="LC_left_item">'.
5047: '<span class="LC_nobreak">';
5048: foreach my $auth (@authtypes) {
5049: $datatable .= '<label>'.
5050: '<input type="checkbox" name="'.$item.'_auth" '.
5051: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5052: $authname{$auth}.'</label> ';
5053: }
5054: $datatable .= '</span></td></tr>';
5055: $rownum ++;
1.27 raeburn 5056: }
1.30 raeburn 5057: $$rowtotal += $rownum;
1.27 raeburn 5058: }
5059: return $datatable;
5060: }
5061:
1.160.6.34 raeburn 5062: sub print_selfcreation {
5063: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 5064: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
5065: $emaildomain,$datatable);
1.160.6.34 raeburn 5066: if (ref($settings) eq 'HASH') {
5067: if (ref($settings->{'cancreate'}) eq 'HASH') {
5068: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 5069: if (ref($createsettings) eq 'HASH') {
5070: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5071: @selfcreate = @{$createsettings->{'selfcreate'}};
5072: } elsif ($createsettings->{'selfcreate'} ne '') {
5073: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5074: @selfcreate = ('email','login','sso');
5075: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5076: @selfcreate = ($createsettings->{'selfcreate'});
5077: }
5078: }
5079: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5080: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5081: }
1.160.6.93 raeburn 5082: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
5083: $emailoptions = $createsettings->{'emailoptions'};
5084: }
5085: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
5086: $emailverified = $createsettings->{'emailverified'};
5087: }
5088: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
5089: $emaildomain = $createsettings->{'emaildomain'};
5090: }
1.160.6.34 raeburn 5091: }
5092: }
5093: }
5094: my %radiohash;
5095: my $numinrow = 4;
5096: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 5097: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 5098: if ($position eq 'top') {
5099: my %choices = &Apache::lonlocal::texthash (
5100: cancreate_login => 'Institutional Login',
5101: cancreate_sso => 'Institutional Single Sign On',
5102: );
5103: my @toggles = sort(keys(%choices));
5104: my %defaultchecked = (
5105: 'cancreate_login' => 'off',
5106: 'cancreate_sso' => 'off',
5107: );
1.160.6.35 raeburn 5108: my ($onclick,$itemcount);
1.160.6.34 raeburn 5109: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5110: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5111: $$rowtotal += $itemcount;
1.160.6.34 raeburn 5112:
5113: if (ref($usertypes) eq 'HASH') {
5114: if (keys(%{$usertypes}) > 0) {
5115: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5116: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 5117: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 5118: $$rowtotal ++;
5119: }
5120: }
1.160.6.44 raeburn 5121: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5122: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5123: $fieldtitles{'inststatus'} = &mt('Institutional status');
5124: my $rem;
5125: my $numperrow = 2;
5126: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5127: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5128: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5129: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 5130: '<table>'."\n";
1.160.6.44 raeburn 5131: for (my $i=0; $i<@fields; $i++) {
5132: $rem = $i%($numperrow);
5133: if ($rem == 0) {
5134: if ($i > 0) {
5135: $datatable .= '</tr>';
5136: }
5137: $datatable .= '<tr>';
5138: }
5139: my $currval;
1.160.6.51 raeburn 5140: if (ref($createsettings) eq 'HASH') {
5141: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5142: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5143: }
1.160.6.44 raeburn 5144: }
5145: $datatable .= '<td class="LC_left_item">'.
5146: '<span class="LC_nobreak">'.
5147: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5148: 'value="'.$currval.'" size="10" /> '.
5149: $fieldtitles{$fields[$i]}.'</span></td>';
5150: }
5151: my $colsleft = $numperrow - $rem;
5152: if ($colsleft > 1 ) {
5153: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5154: ' </td>';
5155: } elsif ($colsleft == 1) {
5156: $datatable .= '<td class="LC_left_item"> </td>';
5157: }
5158: $datatable .= '</tr></table></td></tr>';
5159: $$rowtotal ++;
1.160.6.34 raeburn 5160: } elsif ($position eq 'middle') {
5161: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 5162: my @posstypes;
1.160.6.34 raeburn 5163: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5164: @posstypes = @{$types};
5165: }
5166: unless (grep(/^default$/,@posstypes)) {
5167: push(@posstypes,'default');
5168: }
5169: my %usertypeshash;
5170: if (ref($usertypes) eq 'HASH') {
5171: %usertypeshash = %{$usertypes};
5172: }
5173: $usertypeshash{'default'} = $othertitle;
5174: foreach my $status (@posstypes) {
5175: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5176: $numinrow,$$rowtotal,\%usertypeshash);
5177: $$rowtotal ++;
1.160.6.34 raeburn 5178: }
5179: } else {
1.160.6.40 raeburn 5180: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 5181: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 5182: );
5183: my @toggles = sort(keys(%choices));
5184: my %defaultchecked = (
5185: 'cancreate_email' => 'off',
5186: );
1.160.6.93 raeburn 5187: my $customclass = 'LC_selfcreate_email';
5188: my $classprefix = 'LC_canmodify_emailusername_';
5189: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 5190: my $display = 'none';
1.160.6.93 raeburn 5191: my $rowstyle = 'display:none';
1.160.6.40 raeburn 5192: if (grep(/^\Qemail\E$/,@selfcreate)) {
5193: $display = 'block';
1.160.6.93 raeburn 5194: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 5195: }
1.160.6.93 raeburn 5196: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
5197: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5198: \%choices,$$rowtotal,$onclick);
5199: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
5200: $rowstyle);
5201: $$rowtotal ++;
5202: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
5203: $rowstyle);
5204: $$rowtotal ++;
5205: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 5206: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 5207: my ($emailrules,$emailruleorder) =
5208: &Apache::lonnet::inst_userrules($dom,'email');
5209: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5210: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5211: if (ref($types) eq 'ARRAY') {
5212: @posstypes = @{$types};
5213: }
5214: if (@posstypes) {
5215: unless (grep(/^default$/,@posstypes)) {
5216: push(@posstypes,'default');
1.160.6.89 raeburn 5217: }
5218: if (ref($usertypes) eq 'HASH') {
5219: %usertypeshash = %{$usertypes};
5220: }
1.160.6.93 raeburn 5221: my $currassign;
5222: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
5223: $currassign = {
5224: selfassign => $domdefaults{'inststatusguest'},
5225: };
5226: @ordered = @{$domdefaults{'inststatusguest'}};
5227: } else {
5228: $currassign = { selfassign => [] };
5229: }
5230: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
5231: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
5232: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
5233: $numinrow,$othertitle,'selfassign',
5234: $rowtotal,$onclicktypes,$customclass,
5235: $rowstyle);
5236: $$rowtotal ++;
1.160.6.89 raeburn 5237: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 5238: foreach my $status (@posstypes) {
5239: my $css_class;
5240: if ($$rowtotal%2) {
5241: $css_class = 'LC_odd_row ';
5242: }
5243: $css_class .= $customclass;
5244: my $rowid = $optionsprefix.$status;
5245: my $hidden = 1;
5246: my $currstyle = 'display:none';
5247: if (grep(/^\Q$status\E$/,@ordered)) {
5248: $currstyle = $rowstyle;
5249: $hidden = 0;
5250: }
5251: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5252: $emailrules,$emailruleorder,$settings,$status,$rowid,
5253: $usertypeshash{$status},$css_class,$currstyle,$intdom);
5254: unless ($hidden) {
5255: $$rowtotal ++;
5256: }
1.160.6.89 raeburn 5257: }
5258: } else {
1.160.6.93 raeburn 5259: my $css_class;
5260: if ($$rowtotal%2) {
5261: $css_class = 'LC_odd_row ';
5262: }
5263: $css_class .= $customclass;
1.160.6.89 raeburn 5264: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 5265: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5266: $emailrules,$emailruleorder,$settings,'default','',
5267: $othertitle,$css_class,$rowstyle,$intdom);
5268: $$rowtotal ++;
1.160.6.34 raeburn 5269: }
1.160.6.35 raeburn 5270: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5271: $numinrow = 1;
1.160.6.93 raeburn 5272: if (@posstypes) {
5273: foreach my $status (@posstypes) {
5274: my $rowid = $classprefix.$status;
5275: my $datarowstyle = 'display:none';
5276: if (grep(/^\Q$status\E$/,@ordered)) {
5277: $datarowstyle = $rowstyle;
5278: }
5279: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5280: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5281: $infotitles,$rowid,$customclass,$datarowstyle);
5282: unless ($datarowstyle eq 'display:none') {
5283: $$rowtotal ++;
5284: }
1.160.6.34 raeburn 5285: }
1.160.6.93 raeburn 5286: } else {
5287: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
5288: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5289: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 5290: }
5291: }
5292: return $datatable;
5293: }
5294:
1.160.6.93 raeburn 5295: sub selfcreate_javascript {
5296: return <<"ENDSCRIPT";
5297:
5298: <script type="text/javascript">
5299: // <![CDATA[
5300:
5301: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
5302: var x = document.getElementsByClassName(target);
5303: var insttypes = 0;
5304: var insttypeRegExp = new RegExp(prefix);
5305: if ((x.length != undefined) && (x.length > 0)) {
5306: if (form.elements[radio].length != undefined) {
5307: for (var i=0; i<form.elements[radio].length; i++) {
5308: if (form.elements[radio][i].checked) {
5309: if (form.elements[radio][i].value == 1) {
5310: for (var j=0; j<x.length; j++) {
5311: if (x[j].id == 'undefined') {
5312: x[j].style.display = 'table-row';
5313: } else if (insttypeRegExp.test(x[j].id)) {
5314: insttypes ++;
5315: } else {
5316: x[j].style.display = 'table-row';
5317: }
5318: }
5319: } else {
5320: for (var j=0; j<x.length; j++) {
5321: x[j].style.display = 'none';
5322: }
1.160.6.40 raeburn 5323: }
1.160.6.93 raeburn 5324: break;
5325: }
5326: }
5327: if (insttypes > 0) {
5328: toggleDataRow(form,checkbox,target,altprefix);
5329: toggleDataRow(form,checkbox,target,prefix,1);
5330: }
5331: }
5332: }
5333: return;
5334: }
5335:
5336: function toggleDataRow(form,checkbox,target,prefix,docount) {
5337: if (form.elements[checkbox].length != undefined) {
5338: var count = 0;
5339: if (docount) {
5340: for (var i=0; i<form.elements[checkbox].length; i++) {
5341: if (form.elements[checkbox][i].checked) {
5342: count ++;
5343: }
5344: }
5345: }
5346: for (var i=0; i<form.elements[checkbox].length; i++) {
5347: var type = form.elements[checkbox][i].value;
5348: if (document.getElementById(prefix+type)) {
5349: if (form.elements[checkbox][i].checked) {
5350: document.getElementById(prefix+type).style.display = 'table-row';
5351: if (count % 2 == 1) {
5352: document.getElementById(prefix+type).className = target+' LC_odd_row';
5353: } else {
5354: document.getElementById(prefix+type).className = target;
5355: }
5356: count ++;
1.160.6.40 raeburn 5357: } else {
1.160.6.93 raeburn 5358: document.getElementById(prefix+type).style.display = 'none';
5359: }
5360: }
5361: }
5362: }
5363: return;
5364: }
5365:
5366: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
5367: var caller = radio+'_'+status;
5368: if (form.elements[caller].length != undefined) {
5369: for (var i=0; i<form.elements[caller].length; i++) {
5370: if (form.elements[caller][i].checked) {
5371: if (document.getElementById(altprefix+'_inst_'+status)) {
5372: var curr = form.elements[caller][i].value;
5373: if (prefix) {
5374: document.getElementById(prefix+'_'+status).style.display = 'none';
5375: }
5376: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
5377: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
5378: if (curr == 'custom') {
5379: if (prefix) {
5380: document.getElementById(prefix+'_'+status).style.display = 'inline';
5381: }
5382: } else if (curr == 'inst') {
5383: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
5384: } else if (curr == 'noninst') {
5385: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 5386: }
1.160.6.93 raeburn 5387: break;
1.160.6.40 raeburn 5388: }
1.160.6.93 raeburn 5389: }
5390: }
5391: }
5392: }
5393:
5394: // ]]>
5395: </script>
5396:
5397: ENDSCRIPT
5398: }
5399:
5400: sub noninst_users {
5401: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
5402: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
5403: my $class = 'LC_left_item';
5404: if ($css_class) {
5405: $css_class = ' class="'.$css_class.'"';
5406: }
5407: if ($rowid) {
5408: $rowid = ' id="'.$rowid.'"';
5409: }
5410: if ($rowstyle) {
5411: $rowstyle = ' style="'.$rowstyle.'"';
5412: }
5413: my ($output,$description);
5414: if ($type eq 'default') {
5415: $description = &mt('Requests for: [_1]',$typetitle);
5416: } else {
5417: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
5418: }
5419: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
5420: "<td>$description</td>\n".
5421: '<td class="'.$class.'" colspan="2">'.
5422: '<table><tr>';
5423: my %headers = &Apache::lonlocal::texthash(
5424: approve => 'Processing',
5425: email => 'E-mail',
5426: username => 'Username',
5427: );
5428: foreach my $item ('approve','email','username') {
5429: $output .= '<th>'.$headers{$item}.'</th>';
5430: }
5431: $output .= '</tr><tr>';
5432: foreach my $item ('approve','email','username') {
5433: $output .= '<td valign="top">';
5434: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
5435: if ($item eq 'approve') {
5436: %choices = &Apache::lonlocal::texthash (
5437: automatic => 'Automatically approved',
5438: approval => 'Queued for approval',
5439: );
5440: @options = ('automatic','approval');
5441: $hashref = $processing;
5442: $defoption = 'automatic';
5443: $name = 'cancreate_emailprocess_'.$type;
5444: } elsif ($item eq 'email') {
5445: %choices = &Apache::lonlocal::texthash (
5446: any => 'Any e-mail',
5447: inst => 'Institutional only',
5448: noninst => 'Non-institutional only',
5449: custom => 'Custom restrictions',
5450: );
5451: @options = ('any','inst','noninst');
5452: my $showcustom;
5453: if (ref($emailrules) eq 'HASH') {
5454: if (keys(%{$emailrules}) > 0) {
5455: push(@options,'custom');
5456: $showcustom = 'cancreate_emailrule';
5457: if (ref($settings) eq 'HASH') {
5458: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
5459: foreach my $rule (@{$settings->{'email_rule'}}) {
5460: if (exists($emailrules->{$rule})) {
5461: $hascustom ++;
5462: }
5463: }
5464: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
5465: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
5466: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
5467: if (exists($emailrules->{$rule})) {
5468: $hascustom ++;
5469: }
5470: }
5471: }
5472: }
5473: }
5474: }
5475: }
5476: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
5477: "'cancreate_emaildomain','$type'".');"';
5478: $hashref = $emailoptions;
5479: $defoption = 'any';
5480: $name = 'cancreate_emailoptions_'.$type;
5481: } elsif ($item eq 'username') {
5482: %choices = &Apache::lonlocal::texthash (
5483: all => 'Same as e-mail',
5484: first => 'Omit @domain',
5485: free => 'Free to choose',
5486: );
5487: @options = ('all','first','free');
5488: $hashref = $emailverified;
5489: $defoption = 'all';
5490: $name = 'cancreate_usernameoptions_'.$type;
5491: }
5492: foreach my $option (@options) {
5493: my $checked;
5494: if (ref($hashref) eq 'HASH') {
5495: if ($type eq '') {
5496: if (!exists($hashref->{'default'})) {
5497: if ($option eq $defoption) {
5498: $checked = ' checked="checked"';
5499: }
5500: } else {
5501: if ($hashref->{'default'} eq $option) {
5502: $checked = ' checked="checked"';
5503: }
1.160.6.40 raeburn 5504: }
5505: } else {
1.160.6.93 raeburn 5506: if (!exists($hashref->{$type})) {
5507: if ($option eq $defoption) {
5508: $checked = ' checked="checked"';
5509: }
5510: } else {
5511: if ($hashref->{$type} eq $option) {
5512: $checked = ' checked="checked"';
5513: }
1.160.6.40 raeburn 5514: }
5515: }
1.160.6.93 raeburn 5516: } elsif (($item eq 'email') && ($hascustom)) {
5517: if ($option eq 'custom') {
5518: $checked = ' checked="checked"';
5519: }
5520: } elsif ($option eq $defoption) {
5521: $checked = ' checked="checked"';
5522: }
5523: $output .= '<span class="LC_nobreak"><label>'.
5524: '<input type="radio" name="'.$name.'"'.
5525: $checked.' value="'.$option.'"'.$onclick.' />'.
5526: $choices{$option}.'</label></span><br />';
5527: if ($item eq 'email') {
5528: if ($option eq 'custom') {
5529: my $id = 'cancreate_emailrule_'.$type;
5530: my $display = 'none';
5531: if ($checked) {
5532: $display = 'inline';
5533: }
5534: my $numinrow = 2;
5535: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
5536: '<legend>'.&mt('Disallow').'</legend><table>'.
5537: &user_formats_row('email',$settings,$emailrules,
5538: $emailruleorder,$numinrow,'',$type);
5539: '</table></fieldset>';
5540: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
5541: my %text = &Apache::lonlocal::texthash (
5542: inst => 'must end:',
5543: noninst => 'cannot end:',
5544: );
5545: my $value;
5546: if (ref($emaildomain) eq 'HASH') {
5547: if (ref($emaildomain->{$type}) eq 'HASH') {
5548: $value = $emaildomain->{$type}->{$option};
5549: }
5550: }
5551: if ($value eq '') {
5552: $value = '@'.$intdom;
5553: }
5554: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
5555: my $display = 'none';
5556: if ($checked) {
5557: $display = 'inline';
5558: }
5559: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
5560: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
5561: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
5562: '</div>';
5563: }
1.160.6.40 raeburn 5564: }
5565: }
1.160.6.93 raeburn 5566: $output .= '</td>'."\n";
1.160.6.40 raeburn 5567: }
1.160.6.93 raeburn 5568: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 5569: return $output;
5570: }
5571:
1.160.6.5 raeburn 5572: sub captcha_choice {
1.160.6.93 raeburn 5573: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 5574: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5575: $vertext,$currver);
1.160.6.5 raeburn 5576: my %lt = &captcha_phrases();
5577: $keyentry = 'hidden';
5578: if ($context eq 'cancreate') {
1.160.6.34 raeburn 5579: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 5580: } elsif ($context eq 'login') {
5581: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5582: }
5583: if (ref($settings) eq 'HASH') {
5584: if ($settings->{'captcha'}) {
5585: $checked{$settings->{'captcha'}} = ' checked="checked"';
5586: } else {
5587: $checked{'original'} = ' checked="checked"';
5588: }
5589: if ($settings->{'captcha'} eq 'recaptcha') {
5590: $pubtext = $lt{'pub'};
5591: $privtext = $lt{'priv'};
5592: $keyentry = 'text';
1.160.6.69 raeburn 5593: $vertext = $lt{'ver'};
5594: $currver = $settings->{'recaptchaversion'};
5595: if ($currver ne '2') {
5596: $currver = 1;
5597: }
1.160.6.5 raeburn 5598: }
5599: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5600: $currpub = $settings->{'recaptchakeys'}{'public'};
5601: $currpriv = $settings->{'recaptchakeys'}{'private'};
5602: }
5603: } else {
5604: $checked{'original'} = ' checked="checked"';
5605: }
1.160.6.93 raeburn 5606: my $css_class;
5607: if ($itemcount%2) {
5608: $css_class = 'LC_odd_row';
5609: }
5610: if ($customcss) {
5611: $css_class .= " $customcss";
5612: }
5613: $css_class =~ s/^\s+//;
5614: if ($css_class) {
5615: $css_class = ' class="'.$css_class.'"';
5616: }
5617: if ($rowstyle) {
5618: $css_class .= ' style="'.$rowstyle.'"';
5619: }
1.160.6.5 raeburn 5620: my $output = '<tr'.$css_class.'>'.
5621: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5622: '<table><tr><td>'."\n";
5623: foreach my $option ('original','recaptcha','notused') {
5624: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5625: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5626: $lt{$option}.'</label></span>';
5627: unless ($option eq 'notused') {
5628: $output .= (' 'x2)."\n";
5629: }
5630: }
5631: #
5632: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5633: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5634: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5635: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5636: #
5637: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 5638: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 5639: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5640: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5641: $currpub.'" size="40" /></span><br />'."\n".
5642: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5643: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 5644: $currpriv.'" size="40" /></span><br />'.
5645: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5646: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5647: $currver.'" size="3" /></span><br />'.
5648: '</td></tr></table>'."\n".
1.160.6.5 raeburn 5649: '</td></tr>';
5650: return $output;
5651: }
5652:
1.32 raeburn 5653: sub user_formats_row {
1.160.6.93 raeburn 5654: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 5655: my $output;
5656: my %text = (
5657: 'username' => 'new usernames',
5658: 'id' => 'IDs',
5659: );
1.160.6.93 raeburn 5660: unless ($type eq 'email') {
5661: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5662: $output = '<tr '.$css_class.'>'.
5663: '<td><span class="LC_nobreak">'.
5664: &mt("Format rules to check for $text{$type}: ").
5665: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 5666: }
1.27 raeburn 5667: my $rem;
5668: if (ref($ruleorder) eq 'ARRAY') {
5669: for (my $i=0; $i<@{$ruleorder}; $i++) {
5670: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5671: my $rem = $i%($numinrow);
5672: if ($rem == 0) {
5673: if ($i > 0) {
5674: $output .= '</tr>';
5675: }
5676: $output .= '<tr>';
5677: }
5678: my $check = ' ';
1.39 raeburn 5679: if (ref($settings) eq 'HASH') {
5680: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5681: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5682: $check = ' checked="checked" ';
5683: }
1.160.6.93 raeburn 5684: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
5685: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
5686: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
5687: $check = ' checked="checked" ';
5688: }
5689: }
1.27 raeburn 5690: }
5691: }
1.160.6.93 raeburn 5692: my $name = $type.'_rule';
5693: if ($type eq 'email') {
5694: $name .= '_'.$status;
5695: }
1.27 raeburn 5696: $output .= '<td class="LC_left_item">'.
5697: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 5698: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 5699: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5700: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5701: }
5702: }
5703: $rem = @{$ruleorder}%($numinrow);
5704: }
1.160.6.93 raeburn 5705: my $colsleft;
5706: if ($rem) {
5707: $colsleft = $numinrow - $rem;
5708: }
1.27 raeburn 5709: if ($colsleft > 1 ) {
5710: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5711: ' </td>';
5712: } elsif ($colsleft == 1) {
5713: $output .= '<td class="LC_left_item"> </td>';
5714: }
1.160.6.93 raeburn 5715: $output .= '</tr></table>';
5716: unless ($type eq 'email') {
5717: $output .= '</td></tr>';
5718: }
1.27 raeburn 5719: return $output;
5720: }
5721:
1.34 raeburn 5722: sub usercreation_types {
5723: my %lt = &Apache::lonlocal::texthash (
5724: author => 'When adding a co-author',
5725: course => 'When adding a user to a course',
1.100 raeburn 5726: requestcrs => 'When requesting a course',
1.34 raeburn 5727: any => 'Any',
5728: official => 'Institutional only ',
5729: unofficial => 'Non-institutional only',
5730: none => 'None',
5731: );
5732: return %lt;
1.48 raeburn 5733: }
1.34 raeburn 5734:
1.160.6.34 raeburn 5735: sub selfcreation_types {
5736: my %lt = &Apache::lonlocal::texthash (
5737: selfcreate => 'User creates own account',
5738: any => 'Any',
5739: official => 'Institutional only ',
5740: unofficial => 'Non-institutional only',
5741: email => 'E-mail address',
5742: login => 'Institutional Login',
5743: sso => 'SSO',
5744: );
5745: }
5746:
1.28 raeburn 5747: sub authtype_names {
5748: my %lt = &Apache::lonlocal::texthash(
5749: int => 'Internal',
5750: krb4 => 'Kerberos 4',
5751: krb5 => 'Kerberos 5',
5752: loc => 'Local',
5753: );
5754: return %lt;
5755: }
5756:
5757: sub context_names {
5758: my %context_title = &Apache::lonlocal::texthash(
5759: author => 'Creating users when an Author',
5760: course => 'Creating users when in a course',
5761: domain => 'Creating users when a Domain Coordinator',
5762: );
5763: return %context_title;
5764: }
5765:
1.33 raeburn 5766: sub print_usermodification {
5767: my ($position,$dom,$settings,$rowtotal) = @_;
5768: my $numinrow = 4;
5769: my ($context,$datatable,$rowcount);
5770: if ($position eq 'top') {
5771: $rowcount = 0;
5772: $context = 'author';
5773: foreach my $role ('ca','aa') {
5774: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5775: $numinrow,$rowcount);
5776: $$rowtotal ++;
5777: $rowcount ++;
5778: }
1.160.6.37 raeburn 5779: } elsif ($position eq 'bottom') {
1.33 raeburn 5780: $context = 'course';
5781: $rowcount = 0;
5782: foreach my $role ('st','ep','ta','in','cr') {
5783: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5784: $numinrow,$rowcount);
5785: $$rowtotal ++;
5786: $rowcount ++;
5787: }
5788: }
5789: return $datatable;
5790: }
5791:
1.43 raeburn 5792: sub print_defaults {
1.160.6.40 raeburn 5793: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5794: my $rownum = 0;
1.160.6.80 raeburn 5795: my ($datatable,$css_class,$titles);
5796: unless ($position eq 'bottom') {
5797: $titles = &defaults_titles($dom);
5798: }
1.160.6.40 raeburn 5799: if ($position eq 'top') {
5800: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5801: 'datelocale_def','portal_def');
5802: my %defaults;
5803: if (ref($settings) eq 'HASH') {
5804: %defaults = %{$settings};
1.43 raeburn 5805: } else {
1.160.6.40 raeburn 5806: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5807: foreach my $item (@items) {
5808: $defaults{$item} = $domdefaults{$item};
5809: }
1.43 raeburn 5810: }
1.160.6.40 raeburn 5811: foreach my $item (@items) {
5812: if ($rownum%2) {
5813: $css_class = '';
5814: } else {
5815: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 5816: }
1.160.6.40 raeburn 5817: $datatable .= '<tr'.$css_class.'>'.
5818: '<td><span class="LC_nobreak">'.$titles->{$item}.
5819: '</span></td><td class="LC_right_item" colspan="3">';
5820: if ($item eq 'auth_def') {
5821: my @authtypes = ('internal','krb4','krb5','localauth');
5822: my %shortauth = (
5823: internal => 'int',
5824: krb4 => 'krb4',
5825: krb5 => 'krb5',
5826: localauth => 'loc'
5827: );
5828: my %authnames = &authtype_names();
5829: foreach my $auth (@authtypes) {
5830: my $checked = ' ';
5831: if ($defaults{$item} eq $auth) {
5832: $checked = ' checked="checked" ';
5833: }
5834: $datatable .= '<label><input type="radio" name="'.$item.
5835: '" value="'.$auth.'"'.$checked.'/>'.
5836: $authnames{$shortauth{$auth}}.'</label> ';
5837: }
5838: } elsif ($item eq 'timezone_def') {
5839: my $includeempty = 1;
5840: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5841: } elsif ($item eq 'datelocale_def') {
5842: my $includeempty = 1;
5843: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5844: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 5845: my $includeempty = 1;
5846: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 5847: } else {
5848: my $size;
5849: if ($item eq 'portal_def') {
5850: $size = ' size="25"';
5851: }
5852: $datatable .= '<input type="text" name="'.$item.'" value="'.
5853: $defaults{$item}.'"'.$size.' />';
5854: }
5855: $datatable .= '</td></tr>';
5856: $rownum ++;
5857: }
1.160.6.80 raeburn 5858: } elsif ($position eq 'middle') {
5859: my @items = ('intauth_cost','intauth_check','intauth_switch');
5860: my %defaults;
5861: if (ref($settings) eq 'HASH') {
5862: %defaults = %{$settings};
5863: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5864: $defaults{'intauth_cost'} = 10;
5865: }
5866: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5867: $defaults{'intauth_check'} = 0;
5868: }
5869: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5870: $defaults{'intauth_switch'} = 0;
5871: }
5872: } else {
5873: %defaults = (
5874: 'intauth_cost' => 10,
5875: 'intauth_check' => 0,
5876: 'intauth_switch' => 0,
5877: );
5878: }
5879: foreach my $item (@items) {
5880: if ($rownum%2) {
5881: $css_class = '';
5882: } else {
5883: $css_class = ' class="LC_odd_row" ';
5884: }
5885: $datatable .= '<tr'.$css_class.'>'.
5886: '<td><span class="LC_nobreak">'.$titles->{$item}.
5887: '</span></td><td class="LC_left_item" colspan="3">';
5888: if ($item eq 'intauth_switch') {
5889: my @options = (0,1,2);
5890: my %optiondesc = &Apache::lonlocal::texthash (
5891: 0 => 'No',
5892: 1 => 'Yes',
5893: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5894: );
5895: $datatable .= '<table width="100%">';
5896: foreach my $option (@options) {
5897: my $checked = ' ';
5898: if ($defaults{$item} eq $option) {
5899: $checked = ' checked="checked"';
5900: }
5901: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5902: '<label><input type="radio" name="'.$item.
5903: '" value="'.$option.'"'.$checked.' />'.
5904: $optiondesc{$option}.'</label></span></td></tr>';
5905: }
5906: $datatable .= '</table>';
5907: } elsif ($item eq 'intauth_check') {
5908: my @options = (0,1,2);
5909: my %optiondesc = &Apache::lonlocal::texthash (
5910: 0 => 'No',
5911: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5912: 2 => 'Yes, disallow login if stored cost is less than domain default',
5913: );
1.160.6.87 raeburn 5914: $datatable .= '<table width="100%">';
1.160.6.80 raeburn 5915: foreach my $option (@options) {
5916: my $checked = ' ';
5917: my $onclick;
5918: if ($defaults{$item} eq $option) {
5919: $checked = ' checked="checked"';
5920: }
5921: if ($option == 2) {
5922: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5923: }
5924: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5925: '<label><input type="radio" name="'.$item.
5926: '" value="'.$option.'"'.$checked.$onclick.' />'.
5927: $optiondesc{$option}.'</label></span></td></tr>';
5928: }
5929: $datatable .= '</table>';
5930: } else {
5931: $datatable .= '<input type="text" name="'.$item.'" value="'.
5932: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5933: }
5934: $datatable .= '</td></tr>';
5935: $rownum ++;
5936: }
1.160.6.40 raeburn 5937: } else {
1.160.6.80 raeburn 5938: my %defaults;
1.160.6.40 raeburn 5939: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 5940: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 5941: my $maxnum = @{$settings->{'inststatusorder'}};
5942: for (my $i=0; $i<$maxnum; $i++) {
5943: $css_class = $rownum%2?' class="LC_odd_row"':'';
5944: my $item = $settings->{'inststatusorder'}->[$i];
5945: my $title = $settings->{'inststatustypes'}->{$item};
5946: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5947: $datatable .= '<tr'.$css_class.'>'.
5948: '<td><span class="LC_nobreak">'.
5949: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5950: for (my $k=0; $k<=$maxnum; $k++) {
5951: my $vpos = $k+1;
5952: my $selstr;
5953: if ($k == $i) {
5954: $selstr = ' selected="selected" ';
5955: }
5956: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5957: }
5958: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5959: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5960: &mt('delete').'</span></td>'.
5961: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5962: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 5963: '</span></td></tr>';
1.160.6.40 raeburn 5964: }
5965: $css_class = $rownum%2?' class="LC_odd_row"':'';
5966: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5967: $datatable .= '<tr '.$css_class.'>'.
5968: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5969: for (my $k=0; $k<=$maxnum; $k++) {
5970: my $vpos = $k+1;
5971: my $selstr;
5972: if ($k == $maxnum) {
5973: $selstr = ' selected="selected" ';
5974: }
5975: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5976: }
5977: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 5978: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 5979: ' '.&mt('(new)').
5980: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5981: &mt('Name displayed:').
5982: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5983: '</tr>'."\n";
5984: $rownum ++;
1.141 raeburn 5985: }
1.43 raeburn 5986: }
5987: }
5988: $$rowtotal += $rownum;
5989: return $datatable;
5990: }
5991:
1.160.6.5 raeburn 5992: sub get_languages_hash {
5993: my %langchoices;
5994: foreach my $id (&Apache::loncommon::languageids()) {
5995: my $code = &Apache::loncommon::supportedlanguagecode($id);
5996: if ($code ne '') {
5997: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5998: }
5999: }
6000: return %langchoices;
6001: }
6002:
1.43 raeburn 6003: sub defaults_titles {
1.141 raeburn 6004: my ($dom) = @_;
1.43 raeburn 6005: my %titles = &Apache::lonlocal::texthash (
6006: 'auth_def' => 'Default authentication type',
6007: 'auth_arg_def' => 'Default authentication argument',
6008: 'lang_def' => 'Default language',
1.54 raeburn 6009: 'timezone_def' => 'Default timezone',
1.68 raeburn 6010: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6011: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 6012: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6013: 'intauth_check' => 'Check bcrypt cost if authenticated',
6014: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6015: );
1.141 raeburn 6016: if ($dom) {
6017: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6018: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6019: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6020: $protocol = 'http' if ($protocol ne 'https');
6021: if ($uint_dom) {
6022: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6023: $uint_dom);
6024: }
6025: }
1.43 raeburn 6026: return (\%titles);
6027: }
6028:
1.160.6.97! raeburn 6029: sub print_scantron {
! 6030: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
! 6031: if ($position eq 'top') {
! 6032: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
! 6033: } else {
! 6034: return &print_scantronconfig($dom,$settings,\$rowtotal);
! 6035: }
! 6036: }
! 6037:
! 6038: sub scantron_javascript {
! 6039: return <<"ENDSCRIPT";
! 6040:
! 6041: <script type="text/javascript">
! 6042: // <![CDATA[
! 6043:
! 6044: function toggleScantron(form) {
! 6045: var csvfieldset = new Array();
! 6046: if (document.getElementById('scantroncsv_cols')) {
! 6047: csvfieldset.push(document.getElementById('scantroncsv_cols'));
! 6048: }
! 6049: if (document.getElementById('scantroncsv_options')) {
! 6050: csvfieldset.push(document.getElementById('scantroncsv_options'));
! 6051: }
! 6052: if (csvfieldset.length) {
! 6053: if (document.getElementById('scantronconfcsv')) {
! 6054: var scantroncsv = document.getElementById('scantronconfcsv');
! 6055: if (scantroncsv.checked) {
! 6056: for (var i=0; i<csvfieldset.length; i++) {
! 6057: csvfieldset[i].style.display = 'block';
! 6058: }
! 6059: } else {
! 6060: for (var i=0; i<csvfieldset.length; i++) {
! 6061: csvfieldset[i].style.display = 'none';
! 6062: }
! 6063: var csvselects = document.getElementsByClassName('scantronconfig_csv');
! 6064: if (csvselects.length) {
! 6065: for (var j=0; j<csvselects.length; j++) {
! 6066: csvselects[j].selectedIndex = 0;
! 6067: }
! 6068: }
! 6069: }
! 6070: }
! 6071: }
! 6072: return;
! 6073: }
! 6074: // ]]>
! 6075: </script>
! 6076:
! 6077: ENDSCRIPT
! 6078:
! 6079: }
! 6080:
1.46 raeburn 6081: sub print_scantronformat {
6082: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6083: my $itemcount = 1;
1.60 raeburn 6084: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6085: %confhash);
1.46 raeburn 6086: my $switchserver = &check_switchserver($dom,$confname);
6087: my %lt = &Apache::lonlocal::texthash (
1.95 www 6088: default => 'Default bubblesheet format file error',
6089: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6090: );
6091: my %scantronfiles = (
6092: default => 'default.tab',
6093: custom => 'custom.tab',
6094: );
6095: foreach my $key (keys(%scantronfiles)) {
6096: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6097: .$scantronfiles{$key};
6098: }
6099: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6100: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6101: if (!$switchserver) {
6102: my $servadm = $r->dir_config('lonAdmEMail');
6103: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6104: if ($configuserok eq 'ok') {
6105: if ($author_ok eq 'ok') {
6106: my %legacyfile = (
1.160.6.97! raeburn 6107: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
! 6108: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 6109: );
6110: my %md5chk;
6111: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6112: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6113: chomp($md5chk{$type});
1.46 raeburn 6114: }
6115: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6116: foreach my $type (keys(%legacyfile)) {
1.160.6.97! raeburn 6117: ($scantronurls{$type},my $error) =
1.46 raeburn 6118: &legacy_scantronformat($r,$dom,$confname,
6119: $type,$legacyfile{$type},
6120: $scantronurls{$type},
6121: $scantronfiles{$type});
1.60 raeburn 6122: if ($error ne '') {
6123: $error{$type} = $error;
6124: }
6125: }
6126: if (keys(%error) == 0) {
6127: $is_custom = 1;
1.160.6.97! raeburn 6128: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 6129: $scantronurls{'custom'};
1.160.6.97! raeburn 6130: my $putresult =
1.60 raeburn 6131: &Apache::lonnet::put_dom('configuration',
6132: \%confhash,$dom);
6133: if ($putresult ne 'ok') {
1.160.6.97! raeburn 6134: $error{'custom'} =
1.60 raeburn 6135: '<span class="LC_error">'.
6136: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6137: }
1.46 raeburn 6138: }
6139: } else {
1.60 raeburn 6140: ($scantronurls{'default'},my $error) =
1.46 raeburn 6141: &legacy_scantronformat($r,$dom,$confname,
6142: 'default',$legacyfile{'default'},
6143: $scantronurls{'default'},
6144: $scantronfiles{'default'});
1.60 raeburn 6145: if ($error eq '') {
6146: $confhash{'scantron'}{'scantronformat'} = '';
6147: my $putresult =
6148: &Apache::lonnet::put_dom('configuration',
6149: \%confhash,$dom);
6150: if ($putresult ne 'ok') {
6151: $error{'default'} =
6152: '<span class="LC_error">'.
6153: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6154: }
6155: } else {
6156: $error{'default'} = $error;
6157: }
1.46 raeburn 6158: }
6159: }
6160: }
6161: } else {
1.95 www 6162: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6163: }
6164: }
6165: if (ref($settings) eq 'HASH') {
6166: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6167: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6168: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6169: $scantronurl = '';
6170: } else {
6171: $scantronurl = $settings->{'scantronformat'};
6172: }
6173: $is_custom = 1;
6174: } else {
6175: $scantronurl = $scantronurls{'default'};
6176: }
6177: } else {
1.60 raeburn 6178: if ($is_custom) {
6179: $scantronurl = $scantronurls{'custom'};
6180: } else {
6181: $scantronurl = $scantronurls{'default'};
6182: }
1.46 raeburn 6183: }
6184: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6185: $datatable .= '<tr'.$css_class.'>';
6186: if (!$is_custom) {
1.65 raeburn 6187: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6188: '<span class="LC_nobreak">';
1.46 raeburn 6189: if ($scantronurl) {
1.160.6.21 raeburn 6190: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6191: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6192: } else {
6193: $datatable = &mt('File unavailable for display');
6194: }
1.65 raeburn 6195: $datatable .= '</span></td>';
1.60 raeburn 6196: if (keys(%error) == 0) {
6197: $datatable .= '<td valign="bottom">';
6198: if (!$switchserver) {
6199: $datatable .= &mt('Upload:').'<br />';
6200: }
6201: } else {
6202: my $errorstr;
6203: foreach my $key (sort(keys(%error))) {
6204: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6205: }
6206: $datatable .= '<td>'.$errorstr;
6207: }
1.46 raeburn 6208: } else {
6209: if (keys(%error) > 0) {
6210: my $errorstr;
6211: foreach my $key (sort(keys(%error))) {
6212: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6213: }
1.60 raeburn 6214: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6215: } elsif ($scantronurl) {
1.160.6.26 raeburn 6216: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 6217: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6218: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 6219: $link.
6220: '<label><input type="checkbox" name="scantronformat_del"'.
6221: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6222: '<td><span class="LC_nobreak"> '.
6223: &mt('Replace:').'</span><br />';
1.46 raeburn 6224: }
6225: }
6226: if (keys(%error) == 0) {
6227: if ($switchserver) {
6228: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6229: } else {
1.65 raeburn 6230: $datatable .='<span class="LC_nobreak"> '.
6231: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6232: }
6233: }
6234: $datatable .= '</td></tr>';
6235: $$rowtotal ++;
6236: return $datatable;
6237: }
6238:
6239: sub legacy_scantronformat {
6240: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6241: my ($url,$error);
6242: my @statinfo = &Apache::lonnet::stat_file($newurl);
6243: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6244: (my $result,$url) =
6245: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6246: '','',$newfile);
6247: if ($result ne 'ok') {
1.130 raeburn 6248: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6249: }
6250: }
6251: return ($url,$error);
6252: }
1.43 raeburn 6253:
1.160.6.97! raeburn 6254: sub print_scantronconfig {
! 6255: my ($dom,$settings,$rowtotal) = @_;
! 6256: my $itemcount = 2;
! 6257: my $is_checked = ' checked="checked"';
! 6258: my %optionson = (
! 6259: hdr => ' checked="checked"',
! 6260: pad => ' checked="checked"',
! 6261: rem => ' checked="checked"',
! 6262: );
! 6263: my %optionsoff = (
! 6264: hdr => '',
! 6265: pad => '',
! 6266: rem => '',
! 6267: );
! 6268: my $currcsvsty = 'none';
! 6269: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
! 6270: my @fields = &scantroncsv_fields();
! 6271: my %titles = &scantronconfig_titles();
! 6272: if (ref($settings) eq 'HASH') {
! 6273: if (ref($settings->{config}) eq 'HASH') {
! 6274: if ($settings->{config}->{dat}) {
! 6275: $checked{'dat'} = $is_checked;
! 6276: }
! 6277: if (ref($settings->{config}->{csv}) eq 'HASH') {
! 6278: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
! 6279: %csvfields = %{$settings->{config}->{csv}->{fields}};
! 6280: if (keys(%csvfields) > 0) {
! 6281: $checked{'csv'} = $is_checked;
! 6282: $currcsvsty = 'block';
! 6283: }
! 6284: }
! 6285: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
! 6286: %csvoptions = %{$settings->{config}->{csv}->{options}};
! 6287: foreach my $option (keys(%optionson)) {
! 6288: unless ($csvoptions{$option}) {
! 6289: $optionsoff{$option} = $optionson{$option};
! 6290: $optionson{$option} = '';
! 6291: }
! 6292: }
! 6293: }
! 6294: }
! 6295: } else {
! 6296: $checked{'dat'} = $is_checked;
! 6297: }
! 6298: } else {
! 6299: $checked{'dat'} = $is_checked;
! 6300: }
! 6301: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
! 6302: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
! 6303: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
! 6304: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
! 6305: foreach my $item ('dat','csv') {
! 6306: my $id;
! 6307: if ($item eq 'csv') {
! 6308: $id = 'id="scantronconfcsv" ';
! 6309: }
! 6310: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
! 6311: $titles{$item}.'</label>'.(' 'x3);
! 6312: if ($item eq 'csv') {
! 6313: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
! 6314: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
! 6315: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
! 6316: foreach my $col (@fields) {
! 6317: my $selnone;
! 6318: if ($csvfields{$col} eq '') {
! 6319: $selnone = ' selected="selected"';
! 6320: }
! 6321: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
! 6322: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
! 6323: '<option value=""'.$selnone.'></option>';
! 6324: for (my $i=0; $i<20; $i++) {
! 6325: my $shown = $i+1;
! 6326: my $sel;
! 6327: unless ($selnone) {
! 6328: if (exists($csvfields{$col})) {
! 6329: if ($csvfields{$col} == $i) {
! 6330: $sel = ' selected="selected"';
! 6331: }
! 6332: }
! 6333: }
! 6334: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
! 6335: }
! 6336: $datatable .= '</select></td></tr>';
! 6337: }
! 6338: $datatable .= '</table></fieldset>'.
! 6339: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
! 6340: '<legend>'.&mt('CSV Options').'</legend>';
! 6341: foreach my $option ('hdr','pad','rem') {
! 6342: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
! 6343: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
! 6344: &mt('Yes').'</label>'.(' 'x2)."\n".
! 6345: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
! 6346: }
! 6347: $datatable .= '</fieldset>';
! 6348: $itemcount ++;
! 6349: }
! 6350: }
! 6351: $datatable .= '</td></tr>';
! 6352: $$rowtotal ++;
! 6353: return $datatable;
! 6354: }
! 6355:
! 6356: sub scantronconfig_titles {
! 6357: return &Apache::lonlocal::texthash(
! 6358: dat => 'Standard format (.dat)',
! 6359: csv => 'Comma separated values (.csv)',
! 6360: hdr => 'Remove first line in file (contains column titles)',
! 6361: pad => 'Prepend 0s to PaperID',
! 6362: rem => 'Remove leading spaces (except Question Response columns)',
! 6363: CODE => 'CODE',
! 6364: ID => 'Student ID',
! 6365: PaperID => 'Paper ID',
! 6366: FirstName => 'First Name',
! 6367: LastName => 'Last Name',
! 6368: FirstQuestion => 'First Question Response',
! 6369: Section => 'Section',
! 6370: );
! 6371: }
! 6372:
! 6373: sub scantroncsv_fields {
! 6374: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
! 6375: }
! 6376:
1.49 raeburn 6377: sub print_coursecategories {
1.57 raeburn 6378: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6379: my $datatable;
6380: if ($position eq 'top') {
1.160.6.42 raeburn 6381: my (%checked);
6382: my @catitems = ('unauth','auth');
6383: my @cattypes = ('std','domonly','codesrch','none');
6384: $checked{'unauth'} = 'std';
6385: $checked{'auth'} = 'std';
6386: if (ref($settings) eq 'HASH') {
6387: foreach my $type (@cattypes) {
6388: if ($type eq $settings->{'unauth'}) {
6389: $checked{'unauth'} = $type;
6390: }
6391: if ($type eq $settings->{'auth'}) {
6392: $checked{'auth'} = $type;
6393: }
6394: }
6395: }
6396: my %lt = &Apache::lonlocal::texthash (
6397: unauth => 'Catalog type for unauthenticated users',
6398: auth => 'Catalog type for authenticated users',
6399: none => 'No catalog',
6400: std => 'Standard catalog',
6401: domonly => 'Domain-only catalog',
6402: codesrch => "Code search form",
6403: );
6404: my $itemcount = 0;
6405: foreach my $item (@catitems) {
6406: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6407: $datatable .= '<tr '.$css_class.'>'.
6408: '<td>'.$lt{$item}.'</td>'.
6409: '<td class="LC_right_item"><span class="LC_nobreak">';
6410: foreach my $type (@cattypes) {
6411: my $ischecked;
6412: if ($checked{$item} eq $type) {
6413: $ischecked=' checked="checked"';
6414: }
6415: $datatable .= '<label>'.
6416: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6417: ' />'.$lt{$type}.'</label> ';
6418: }
1.160.6.87 raeburn 6419: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 6420: $itemcount ++;
6421: }
6422: $$rowtotal += $itemcount;
6423: } elsif ($position eq 'middle') {
1.57 raeburn 6424: my $toggle_cats_crs = ' ';
6425: my $toggle_cats_dom = ' checked="checked" ';
6426: my $can_cat_crs = ' ';
6427: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6428: my $toggle_catscomm_comm = ' ';
6429: my $toggle_catscomm_dom = ' checked="checked" ';
6430: my $can_catcomm_comm = ' ';
6431: my $can_catcomm_dom = ' checked="checked" ';
6432:
1.57 raeburn 6433: if (ref($settings) eq 'HASH') {
6434: if ($settings->{'togglecats'} eq 'crs') {
6435: $toggle_cats_crs = $toggle_cats_dom;
6436: $toggle_cats_dom = ' ';
6437: }
6438: if ($settings->{'categorize'} eq 'crs') {
6439: $can_cat_crs = $can_cat_dom;
6440: $can_cat_dom = ' ';
6441: }
1.120 raeburn 6442: if ($settings->{'togglecatscomm'} eq 'comm') {
6443: $toggle_catscomm_comm = $toggle_catscomm_dom;
6444: $toggle_catscomm_dom = ' ';
6445: }
6446: if ($settings->{'categorizecomm'} eq 'comm') {
6447: $can_catcomm_comm = $can_catcomm_dom;
6448: $can_catcomm_dom = ' ';
6449: }
1.57 raeburn 6450: }
6451: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 6452: togglecats => 'Show/Hide a course in catalog',
6453: togglecatscomm => 'Show/Hide a community in catalog',
6454: categorize => 'Assign a category to a course',
6455: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6456: );
6457: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 6458: dom => 'Set in Domain',
6459: crs => 'Set in Course',
6460: comm => 'Set in Community',
1.57 raeburn 6461: );
6462: $datatable = '<tr class="LC_odd_row">'.
6463: '<td>'.$title{'togglecats'}.'</td>'.
6464: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6465: '<input type="radio" name="togglecats"'.
6466: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6467: '<label><input type="radio" name="togglecats"'.
6468: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6469: '</tr><tr>'.
6470: '<td>'.$title{'categorize'}.'</td>'.
6471: '<td class="LC_right_item"><span class="LC_nobreak">'.
6472: '<label><input type="radio" name="categorize"'.
6473: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6474: '<label><input type="radio" name="categorize"'.
6475: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6476: '</tr><tr class="LC_odd_row">'.
6477: '<td>'.$title{'togglecatscomm'}.'</td>'.
6478: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6479: '<input type="radio" name="togglecatscomm"'.
6480: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6481: '<label><input type="radio" name="togglecatscomm"'.
6482: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6483: '</tr><tr>'.
6484: '<td>'.$title{'categorizecomm'}.'</td>'.
6485: '<td class="LC_right_item"><span class="LC_nobreak">'.
6486: '<label><input type="radio" name="categorizecomm"'.
6487: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6488: '<label><input type="radio" name="categorizecomm"'.
6489: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 6490: '</tr>';
1.120 raeburn 6491: $$rowtotal += 4;
1.57 raeburn 6492: } else {
6493: my $css_class;
6494: my $itemcount = 1;
6495: my $cathash;
6496: if (ref($settings) eq 'HASH') {
6497: $cathash = $settings->{'cats'};
6498: }
6499: if (ref($cathash) eq 'HASH') {
6500: my (@cats,@trails,%allitems,%idx,@jsarray);
6501: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6502: \%allitems,\%idx,\@jsarray);
6503: my $maxdepth = scalar(@cats);
6504: my $colattrib = '';
6505: if ($maxdepth > 2) {
6506: $colattrib = ' colspan="2" ';
6507: }
6508: my @path;
6509: if (@cats > 0) {
6510: if (ref($cats[0]) eq 'ARRAY') {
6511: my $numtop = @{$cats[0]};
6512: my $maxnum = $numtop;
1.120 raeburn 6513: my %default_names = (
6514: instcode => &mt('Official courses'),
6515: communities => &mt('Communities'),
6516: );
6517:
6518: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6519: ($cathash->{'instcode::0'} eq '') ||
6520: (!grep(/^communities$/,@{$cats[0]})) ||
6521: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 6522: $maxnum ++;
6523: }
6524: my $lastidx;
6525: for (my $i=0; $i<$numtop; $i++) {
6526: my $parent = $cats[0][$i];
6527: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6528: my $item = &escape($parent).'::0';
6529: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6530: $lastidx = $idx{$item};
6531: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6532: .'<select name="'.$item.'"'.$chgstr.'>';
6533: for (my $k=0; $k<=$maxnum; $k++) {
6534: my $vpos = $k+1;
6535: my $selstr;
6536: if ($k == $i) {
6537: $selstr = ' selected="selected" ';
6538: }
6539: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6540: }
1.160.6.29 raeburn 6541: $datatable .= '</select></span></td><td>';
1.120 raeburn 6542: if ($parent eq 'instcode' || $parent eq 'communities') {
6543: $datatable .= '<span class="LC_nobreak">'
6544: .$default_names{$parent}.'</span>';
6545: if ($parent eq 'instcode') {
6546: $datatable .= '<br /><span class="LC_nobreak">('
6547: .&mt('with institutional codes')
6548: .')</span></td><td'.$colattrib.'>';
6549: } else {
6550: $datatable .= '<table><tr><td>';
6551: }
6552: $datatable .= '<span class="LC_nobreak">'
6553: .'<label><input type="radio" name="'
6554: .$parent.'" value="1" checked="checked" />'
6555: .&mt('Display').'</label>';
6556: if ($parent eq 'instcode') {
6557: $datatable .= ' ';
6558: } else {
6559: $datatable .= '</span></td></tr><tr><td>'
6560: .'<span class="LC_nobreak">';
6561: }
6562: $datatable .= '<label><input type="radio" name="'
6563: .$parent.'" value="0" />'
6564: .&mt('Do not display').'</label></span>';
6565: if ($parent eq 'communities') {
6566: $datatable .= '</td></tr></table>';
6567: }
6568: $datatable .= '</td>';
1.57 raeburn 6569: } else {
6570: $datatable .= $parent
1.160.6.29 raeburn 6571: .' <span class="LC_nobreak"><label>'
6572: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6573: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6574: }
6575: my $depth = 1;
6576: push(@path,$parent);
6577: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6578: pop(@path);
6579: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6580: $itemcount ++;
6581: }
1.48 raeburn 6582: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6583: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6584: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6585: for (my $k=0; $k<=$maxnum; $k++) {
6586: my $vpos = $k+1;
6587: my $selstr;
1.57 raeburn 6588: if ($k == $numtop) {
1.48 raeburn 6589: $selstr = ' selected="selected" ';
6590: }
6591: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6592: }
1.59 bisitz 6593: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6594: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6595: .'</tr>'."\n";
1.48 raeburn 6596: $itemcount ++;
1.120 raeburn 6597: foreach my $default ('instcode','communities') {
6598: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6599: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6600: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6601: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6602: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6603: for (my $k=0; $k<=$maxnum; $k++) {
6604: my $vpos = $k+1;
6605: my $selstr;
6606: if ($k == $maxnum) {
6607: $selstr = ' selected="selected" ';
6608: }
6609: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6610: }
1.120 raeburn 6611: $datatable .= '</select></span></td>'.
6612: '<td><span class="LC_nobreak">'.
6613: $default_names{$default}.'</span>';
6614: if ($default eq 'instcode') {
6615: $datatable .= '<br /><span class="LC_nobreak">('
6616: .&mt('with institutional codes').')</span>';
6617: }
6618: $datatable .= '</td>'
6619: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6620: .&mt('Display').'</label> '
6621: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6622: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6623: }
6624: }
6625: }
1.57 raeburn 6626: } else {
6627: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6628: }
6629: } else {
1.160.6.87 raeburn 6630: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 6631: .&initialize_categories($itemcount);
1.48 raeburn 6632: }
1.57 raeburn 6633: $$rowtotal += $itemcount;
1.48 raeburn 6634: }
6635: return $datatable;
6636: }
6637:
1.69 raeburn 6638: sub print_serverstatuses {
6639: my ($dom,$settings,$rowtotal) = @_;
6640: my $datatable;
6641: my @pages = &serverstatus_pages();
6642: my (%namedaccess,%machineaccess);
6643: foreach my $type (@pages) {
6644: $namedaccess{$type} = '';
6645: $machineaccess{$type}= '';
6646: }
6647: if (ref($settings) eq 'HASH') {
6648: foreach my $type (@pages) {
6649: if (exists($settings->{$type})) {
6650: if (ref($settings->{$type}) eq 'HASH') {
6651: foreach my $key (keys(%{$settings->{$type}})) {
6652: if ($key eq 'namedusers') {
6653: $namedaccess{$type} = $settings->{$type}->{$key};
6654: } elsif ($key eq 'machines') {
6655: $machineaccess{$type} = $settings->{$type}->{$key};
6656: }
6657: }
6658: }
6659: }
6660: }
6661: }
1.81 raeburn 6662: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6663: my $rownum = 0;
6664: my $css_class;
6665: foreach my $type (@pages) {
6666: $rownum ++;
6667: $css_class = $rownum%2?' class="LC_odd_row"':'';
6668: $datatable .= '<tr'.$css_class.'>'.
6669: '<td><span class="LC_nobreak">'.
6670: $titles->{$type}.'</span></td>'.
6671: '<td class="LC_left_item">'.
6672: '<input type="text" name="'.$type.'_namedusers" '.
6673: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6674: '<td class="LC_right_item">'.
6675: '<span class="LC_nobreak">'.
6676: '<input type="text" name="'.$type.'_machines" '.
6677: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 6678: '</span></td></tr>'."\n";
1.69 raeburn 6679: }
6680: $$rowtotal += $rownum;
6681: return $datatable;
6682: }
6683:
6684: sub serverstatus_pages {
6685: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 6686: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 6687: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 6688: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6689: }
6690:
1.160.6.40 raeburn 6691: sub defaults_javascript {
6692: my ($settings) = @_;
1.160.6.80 raeburn 6693: 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.');
6694: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6695: &js_escape(\$intauthcheck);
6696: &js_escape(\$intauthcost);
6697: my $intauthjs = <<"ENDSCRIPT";
6698:
6699: function warnIntAuth(field) {
6700: if (field.name == 'intauth_check') {
6701: if (field.value == '2') {
6702: alert('$intauthcheck');
6703: }
6704: }
6705: if (field.name == 'intauth_cost') {
6706: field.value.replace(/\s/g,'');
6707: if (field.value != '') {
6708: var regexdigit=/^\\d+\$/;
6709: if (!regexdigit.test(field.value)) {
6710: alert('$intauthcost');
6711: }
6712: }
6713: }
6714: return;
6715: }
6716:
6717: ENDSCRIPT
6718:
6719: if (ref($settings) ne 'HASH') {
6720: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6721: }
1.160.6.40 raeburn 6722: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6723: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6724: if ($maxnum eq '') {
6725: $maxnum = 0;
6726: }
6727: $maxnum ++;
1.160.6.51 raeburn 6728: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 6729: return <<"ENDSCRIPT";
6730: <script type="text/javascript">
6731: // <![CDATA[
6732: function reorderTypes(form,caller) {
6733: var changedVal;
6734: $jstext
6735: var newpos = 'addinststatus_pos';
6736: var current = new Array;
6737: var maxh = $maxnum;
6738: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6739: var oldVal;
6740: if (caller == newpos) {
6741: changedVal = newitemVal;
6742: } else {
6743: var curritem = 'inststatus_pos_'+caller;
6744: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6745: current[newitemVal] = newpos;
6746: }
6747: for (var i=0; i<inststatuses.length; i++) {
6748: if (inststatuses[i] != caller) {
6749: var elementName = 'inststatus_pos_'+inststatuses[i];
6750: if (form.elements[elementName]) {
6751: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6752: current[currVal] = elementName;
6753: }
6754: }
6755: }
6756: for (var j=0; j<maxh; j++) {
6757: if (current[j] == undefined) {
6758: oldVal = j;
6759: }
6760: }
6761: if (oldVal < changedVal) {
6762: for (var k=oldVal+1; k<=changedVal ; k++) {
6763: var elementName = current[k];
6764: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6765: }
6766: } else {
6767: for (var k=changedVal; k<oldVal; k++) {
6768: var elementName = current[k];
6769: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6770: }
6771: }
6772: return;
6773: }
6774:
1.160.6.80 raeburn 6775: $intauthjs
6776:
1.160.6.40 raeburn 6777: // ]]>
6778: </script>
6779:
6780: ENDSCRIPT
1.160.6.80 raeburn 6781: } else {
6782: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40 raeburn 6783: }
6784: }
6785:
1.49 raeburn 6786: sub coursecategories_javascript {
6787: my ($settings) = @_;
1.57 raeburn 6788: my ($output,$jstext,$cathash);
1.49 raeburn 6789: if (ref($settings) eq 'HASH') {
1.57 raeburn 6790: $cathash = $settings->{'cats'};
6791: }
6792: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6793: my (@cats,@jsarray,%idx);
1.57 raeburn 6794: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6795: if (@jsarray > 0) {
6796: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6797: for (my $i=0; $i<@jsarray; $i++) {
6798: if (ref($jsarray[$i]) eq 'ARRAY') {
6799: my $catstr = join('","',@{$jsarray[$i]});
6800: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6801: }
6802: }
6803: }
6804: } else {
6805: $jstext = ' var categories = Array(1);'."\n".
6806: ' categories[0] = Array("instcode_pos");'."\n";
6807: }
1.160.6.42 raeburn 6808: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6809: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 6810: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6811: &js_escape(\$instcode_reserved);
6812: &js_escape(\$communities_reserved);
6813: &js_escape(\$choose_again);
1.49 raeburn 6814: $output = <<"ENDSCRIPT";
6815: <script type="text/javascript">
1.109 raeburn 6816: // <![CDATA[
1.49 raeburn 6817: function reorderCats(form,parent,item,idx) {
6818: var changedVal;
6819: $jstext
6820: var newpos = 'addcategory_pos';
6821: if (parent == '') {
6822: var has_instcode = 0;
6823: var maxtop = categories[idx].length;
6824: for (var j=0; j<maxtop; j++) {
6825: if (categories[idx][j] == 'instcode::0') {
6826: has_instcode == 1;
6827: }
6828: }
6829: if (has_instcode == 0) {
6830: categories[idx][maxtop] = 'instcode_pos';
6831: }
6832: } else {
6833: newpos += '_'+parent;
6834: }
6835: var maxh = 1 + categories[idx].length;
6836: var current = new Array;
6837: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6838: if (item == newpos) {
6839: changedVal = newitemVal;
6840: } else {
6841: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6842: current[newitemVal] = newpos;
6843: }
6844: for (var i=0; i<categories[idx].length; i++) {
6845: var elementName = categories[idx][i];
6846: if (elementName != item) {
6847: if (form.elements[elementName]) {
6848: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6849: current[currVal] = elementName;
6850: }
6851: }
6852: }
6853: var oldVal;
6854: for (var j=0; j<maxh; j++) {
6855: if (current[j] == undefined) {
6856: oldVal = j;
6857: }
6858: }
6859: if (oldVal < changedVal) {
6860: for (var k=oldVal+1; k<=changedVal ; k++) {
6861: var elementName = current[k];
6862: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6863: }
6864: } else {
6865: for (var k=changedVal; k<oldVal; k++) {
6866: var elementName = current[k];
6867: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6868: }
6869: }
6870: return;
6871: }
1.120 raeburn 6872:
6873: function categoryCheck(form) {
6874: if (form.elements['addcategory_name'].value == 'instcode') {
6875: alert('$instcode_reserved\\n$choose_again');
6876: return false;
6877: }
6878: if (form.elements['addcategory_name'].value == 'communities') {
6879: alert('$communities_reserved\\n$choose_again');
6880: return false;
6881: }
6882: return true;
6883: }
6884:
1.109 raeburn 6885: // ]]>
1.49 raeburn 6886: </script>
6887:
6888: ENDSCRIPT
6889: return $output;
6890: }
6891:
1.48 raeburn 6892: sub initialize_categories {
6893: my ($itemcount) = @_;
1.120 raeburn 6894: my ($datatable,$css_class,$chgstr);
6895: my %default_names = (
6896: instcode => 'Official courses (with institutional codes)',
6897: communities => 'Communities',
6898: );
6899: my $select0 = ' selected="selected"';
6900: my $select1 = '';
6901: foreach my $default ('instcode','communities') {
6902: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 6903: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 6904: if ($default eq 'communities') {
6905: $select1 = $select0;
6906: $select0 = '';
6907: }
6908: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6909: .'<select name="'.$default.'_pos">'
6910: .'<option value="0"'.$select0.'>1</option>'
6911: .'<option value="1"'.$select1.'>2</option>'
6912: .'<option value="2">3</option></select> '
6913: .$default_names{$default}
6914: .'</span></td><td><span class="LC_nobreak">'
6915: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6916: .&mt('Display').'</label> <label>'
6917: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6918: .'</label></span></td></tr>';
1.120 raeburn 6919: $itemcount ++;
6920: }
1.48 raeburn 6921: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6922: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6923: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6924: .'<select name="addcategory_pos"'.$chgstr.'>'
6925: .'<option value="0">1</option>'
6926: .'<option value="1">2</option>'
6927: .'<option value="2" selected="selected">3</option></select> '
1.160.6.87 raeburn 6928: .&mt('Add category').'</span></td><tda<span class="LC_nobreak">>'.&mt('Name:')
6929: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
6930: .'</td></tr>';
1.48 raeburn 6931: return $datatable;
6932: }
6933:
6934: sub build_category_rows {
1.49 raeburn 6935: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6936: my ($text,$name,$item,$chgstr);
1.48 raeburn 6937: if (ref($cats) eq 'ARRAY') {
6938: my $maxdepth = scalar(@{$cats});
6939: if (ref($cats->[$depth]) eq 'HASH') {
6940: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6941: my $numchildren = @{$cats->[$depth]{$parent}};
6942: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 6943: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6944: my ($idxnum,$parent_name,$parent_item);
6945: my $higher = $depth - 1;
6946: if ($higher == 0) {
6947: $parent_name = &escape($parent).'::'.$higher;
6948: } else {
6949: if (ref($path) eq 'ARRAY') {
6950: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6951: }
6952: }
6953: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6954: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6955: if ($j < $numchildren) {
1.48 raeburn 6956: $name = $cats->[$depth]{$parent}[$j];
6957: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6958: $idxnum = $idx->{$item};
6959: } else {
6960: $name = $parent_name;
6961: $item = $parent_item;
1.48 raeburn 6962: }
1.49 raeburn 6963: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6964: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6965: for (my $i=0; $i<=$numchildren; $i++) {
6966: my $vpos = $i+1;
6967: my $selstr;
6968: if ($j == $i) {
6969: $selstr = ' selected="selected" ';
6970: }
6971: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6972: }
6973: $text .= '</select> ';
6974: if ($j < $numchildren) {
6975: my $deeper = $depth+1;
6976: $text .= $name.' '
6977: .'<label><input type="checkbox" name="deletecategory" value="'
6978: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6979: if(ref($path) eq 'ARRAY') {
6980: push(@{$path},$name);
1.49 raeburn 6981: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6982: pop(@{$path});
6983: }
6984: } else {
1.160.6.87 raeburn 6985: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 6986: if ($j == $numchildren) {
6987: $text .= $name;
6988: } else {
6989: $text .= $item;
6990: }
6991: $text .= '" value="" />';
6992: }
6993: $text .= '</td></tr>';
6994: }
6995: $text .= '</table></td>';
6996: } else {
6997: my $higher = $depth-1;
6998: if ($higher == 0) {
6999: $name = &escape($parent).'::'.$higher;
7000: } else {
7001: if (ref($path) eq 'ARRAY') {
7002: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
7003: }
7004: }
7005: my $colspan;
7006: if ($parent ne 'instcode') {
7007: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 7008: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 7009: }
7010: }
7011: }
7012: }
7013: return $text;
7014: }
7015:
1.33 raeburn 7016: sub modifiable_userdata_row {
1.160.6.93 raeburn 7017: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
7018: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 7019: my ($role,$rolename,$statustype);
7020: $role = $item;
1.160.6.34 raeburn 7021: if ($context eq 'cancreate') {
1.160.6.93 raeburn 7022: if ($item =~ /^(emailusername)_(.+)$/) {
7023: $role = $1;
7024: $statustype = $2;
1.160.6.35 raeburn 7025: if (ref($usertypes) eq 'HASH') {
7026: if ($usertypes->{$statustype}) {
7027: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
7028: } else {
7029: $rolename = &mt('Data provided by user');
7030: }
7031: }
1.160.6.34 raeburn 7032: }
7033: } elsif ($context eq 'selfcreate') {
1.63 raeburn 7034: if (ref($usertypes) eq 'HASH') {
7035: $rolename = $usertypes->{$role};
7036: } else {
7037: $rolename = $role;
7038: }
1.33 raeburn 7039: } else {
1.63 raeburn 7040: if ($role eq 'cr') {
7041: $rolename = &mt('Custom role');
7042: } else {
7043: $rolename = &Apache::lonnet::plaintext($role);
7044: }
1.33 raeburn 7045: }
1.160.6.34 raeburn 7046: my (@fields,%fieldtitles);
7047: if (ref($fieldsref) eq 'ARRAY') {
7048: @fields = @{$fieldsref};
7049: } else {
7050: @fields = ('lastname','firstname','middlename','generation',
7051: 'permanentemail','id');
7052: }
7053: if ((ref($titlesref) eq 'HASH')) {
7054: %fieldtitles = %{$titlesref};
7055: } else {
7056: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7057: }
1.33 raeburn 7058: my $output;
1.160.6.93 raeburn 7059: my $css_class;
7060: if ($rowcount%2) {
7061: $css_class = 'LC_odd_row';
7062: }
7063: if ($customcss) {
7064: $css_class .= " $customcss";
7065: }
7066: $css_class =~ s/^\s+//;
7067: if ($css_class) {
7068: $css_class = ' class="'.$css_class.'"';
7069: }
7070: if ($rowstyle) {
7071: $css_class .= ' style="'.$rowstyle.'"';
7072: }
7073: if ($rowid) {
7074: $rowid = ' id="'.$rowid.'"';
7075: }
7076:
7077: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 7078: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
7079: '<td class="LC_left_item" colspan="2"><table>';
7080: my $rem;
7081: my %checks;
7082: if (ref($settings) eq 'HASH') {
7083: if (ref($settings->{$context}) eq 'HASH') {
7084: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 7085: my $hashref = $settings->{$context}->{$role};
7086: if ($role eq 'emailusername') {
7087: if ($statustype) {
7088: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
7089: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 7090: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 7091: foreach my $field (@fields) {
7092: if ($hashref->{$field}) {
7093: $checks{$field} = $hashref->{$field};
7094: }
7095: }
7096: }
7097: }
7098: }
7099: } else {
7100: if (ref($hashref) eq 'HASH') {
7101: foreach my $field (@fields) {
7102: if ($hashref->{$field}) {
7103: $checks{$field} = ' checked="checked" ';
7104: }
7105: }
1.33 raeburn 7106: }
7107: }
7108: }
7109: }
7110: }
1.160.6.93 raeburn 7111:
7112: my $total = scalar(@fields);
7113: for (my $i=0; $i<$total; $i++) {
7114: $rem = $i%($numinrow);
1.33 raeburn 7115: if ($rem == 0) {
7116: if ($i > 0) {
7117: $output .= '</tr>';
7118: }
7119: $output .= '<tr>';
7120: }
7121: my $check = ' ';
1.160.6.35 raeburn 7122: unless ($role eq 'emailusername') {
7123: if (exists($checks{$fields[$i]})) {
7124: $check = $checks{$fields[$i]}
7125: } else {
7126: if ($role eq 'st') {
7127: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 7128: $check = ' checked="checked" ';
1.160.6.35 raeburn 7129: }
1.33 raeburn 7130: }
7131: }
7132: }
7133: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 7134: '<span class="LC_nobreak">';
7135: if ($role eq 'emailusername') {
7136: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
7137: $checks{$fields[$i]} = 'omit';
7138: }
7139: foreach my $option ('required','optional','omit') {
7140: my $checked='';
7141: if ($checks{$fields[$i]} eq $option) {
7142: $checked='checked="checked" ';
7143: }
7144: $output .= '<label>'.
7145: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
7146: &mt($option).'</label>'.(' ' x2);
7147: }
7148: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
7149: } else {
7150: $output .= '<label>'.
7151: '<input type="checkbox" name="canmodify_'.$role.'" '.
7152: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
7153: '</label>';
7154: }
7155: $output .= '</span></td>';
1.33 raeburn 7156: }
1.160.6.93 raeburn 7157: $rem = $total%$numinrow;
7158: my $colsleft;
7159: if ($rem) {
7160: $colsleft = $numinrow - $rem;
7161: }
7162: if ($colsleft > 1) {
1.33 raeburn 7163: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7164: ' </td>';
7165: } elsif ($colsleft == 1) {
7166: $output .= '<td class="LC_left_item"> </td>';
7167: }
7168: $output .= '</tr></table></td></tr>';
7169: return $output;
7170: }
1.28 raeburn 7171:
1.93 raeburn 7172: sub insttypes_row {
1.160.6.93 raeburn 7173: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
7174: $customcss,$rowstyle) = @_;
1.93 raeburn 7175: my %lt = &Apache::lonlocal::texthash (
7176: cansearch => 'Users allowed to search',
7177: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 7178: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 7179: selfassign => 'Self-reportable affiliations',
1.93 raeburn 7180: );
7181: my $showdom;
7182: if ($context eq 'cansearch') {
7183: $showdom = ' ('.$dom.')';
7184: }
1.160.6.5 raeburn 7185: my $class = 'LC_left_item';
7186: if ($context eq 'statustocreate') {
7187: $class = 'LC_right_item';
7188: }
1.160.6.93 raeburn 7189: my $css_class;
7190: if ($$rowtotal%2) {
7191: $css_class = 'LC_odd_row';
7192: }
7193: if ($customcss) {
7194: $css_class .= ' '.$customcss;
7195: }
7196: $css_class =~ s/^\s+//;
7197: if ($css_class) {
7198: $css_class = ' class="'.$css_class.'"';
7199: }
7200: if ($rowstyle) {
7201: $css_class .= ' style="'.$rowstyle.'"';
7202: }
7203: if ($onclick) {
7204: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 7205: }
7206: my $output = '<tr'.$css_class.'>'.
7207: '<td>'.$lt{$context}.$showdom.
7208: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7209: my $rem;
7210: if (ref($types) eq 'ARRAY') {
7211: for (my $i=0; $i<@{$types}; $i++) {
7212: if (defined($usertypes->{$types->[$i]})) {
7213: my $rem = $i%($numinrow);
7214: if ($rem == 0) {
7215: if ($i > 0) {
7216: $output .= '</tr>';
7217: }
7218: $output .= '<tr>';
1.23 raeburn 7219: }
1.26 raeburn 7220: my $check = ' ';
1.99 raeburn 7221: if (ref($settings) eq 'HASH') {
7222: if (ref($settings->{$context}) eq 'ARRAY') {
7223: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7224: $check = ' checked="checked" ';
7225: }
7226: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7227: $check = ' checked="checked" ';
7228: }
1.23 raeburn 7229: }
1.26 raeburn 7230: $output .= '<td class="LC_left_item">'.
7231: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7232: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 7233: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 7234: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7235: }
7236: }
1.26 raeburn 7237: $rem = @{$types}%($numinrow);
1.23 raeburn 7238: }
7239: my $colsleft = $numinrow - $rem;
1.160.6.87 raeburn 7240: if ($rem == 0) {
1.131 raeburn 7241: $output .= '<tr>';
7242: }
1.23 raeburn 7243: if ($colsleft > 1) {
1.25 raeburn 7244: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7245: } else {
1.25 raeburn 7246: $output .= '<td class="LC_left_item">';
1.23 raeburn 7247: }
7248: my $defcheck = ' ';
1.99 raeburn 7249: if (ref($settings) eq 'HASH') {
7250: if (ref($settings->{$context}) eq 'ARRAY') {
7251: if (grep(/^default$/,@{$settings->{$context}})) {
7252: $defcheck = ' checked="checked" ';
7253: }
7254: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7255: $defcheck = ' checked="checked" ';
7256: }
1.23 raeburn 7257: }
1.25 raeburn 7258: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7259: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 7260: 'value="default"'.$defcheck.$onclick.'/>'.
1.25 raeburn 7261: $othertitle.'</label></span></td>'.
7262: '</tr></table></td></tr>';
7263: return $output;
1.23 raeburn 7264: }
7265:
7266: sub sorted_searchtitles {
7267: my %searchtitles = &Apache::lonlocal::texthash(
7268: 'uname' => 'username',
7269: 'lastname' => 'last name',
7270: 'lastfirst' => 'last name, first name',
7271: );
7272: my @titleorder = ('uname','lastname','lastfirst');
7273: return (\%searchtitles,\@titleorder);
7274: }
7275:
1.25 raeburn 7276: sub sorted_searchtypes {
7277: my %srchtypes_desc = (
7278: exact => 'is exact match',
7279: contains => 'contains ..',
7280: begins => 'begins with ..',
7281: );
7282: my @srchtypeorder = ('exact','begins','contains');
7283: return (\%srchtypes_desc,\@srchtypeorder);
7284: }
7285:
1.3 raeburn 7286: sub usertype_update_row {
7287: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7288: my $datatable;
7289: my $numinrow = 4;
7290: foreach my $type (@{$types}) {
7291: if (defined($usertypes->{$type})) {
7292: $$rownums ++;
7293: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7294: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7295: '</td><td class="LC_left_item"><table>';
7296: for (my $i=0; $i<@{$fields}; $i++) {
7297: my $rem = $i%($numinrow);
7298: if ($rem == 0) {
7299: if ($i > 0) {
7300: $datatable .= '</tr>';
7301: }
7302: $datatable .= '<tr>';
7303: }
7304: my $check = ' ';
1.39 raeburn 7305: if (ref($settings) eq 'HASH') {
7306: if (ref($settings->{'fields'}) eq 'HASH') {
7307: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7308: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7309: $check = ' checked="checked" ';
7310: }
1.3 raeburn 7311: }
7312: }
7313: }
7314:
7315: if ($i == @{$fields}-1) {
7316: my $colsleft = $numinrow - $rem;
7317: if ($colsleft > 1) {
7318: $datatable .= '<td colspan="'.$colsleft.'">';
7319: } else {
7320: $datatable .= '<td>';
7321: }
7322: } else {
7323: $datatable .= '<td>';
7324: }
1.8 raeburn 7325: $datatable .= '<span class="LC_nobreak"><label>'.
7326: '<input type="checkbox" name="updateable_'.$type.
7327: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7328: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7329: }
7330: $datatable .= '</tr></table></td></tr>';
7331: }
7332: }
7333: return $datatable;
1.1 raeburn 7334: }
7335:
7336: sub modify_login {
1.160.6.24 raeburn 7337: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 7338: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7339: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7340: %title = ( coursecatalog => 'Display course catalog',
7341: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 7342: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 7343: newuser => 'Link for visitors to create a user account',
7344: loginheader => 'Log-in box header');
7345: @offon = ('off','on');
1.112 raeburn 7346: if (ref($domconfig{login}) eq 'HASH') {
7347: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7348: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7349: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7350: }
7351: }
7352: }
1.9 raeburn 7353: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7354: \%domconfig,\%loginhash);
1.160.6.14 raeburn 7355: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7356: foreach my $item (@toggles) {
7357: $loginhash{login}{$item} = $env{'form.'.$item};
7358: }
1.41 raeburn 7359: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7360: if (ref($colchanges{'login'}) eq 'HASH') {
7361: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7362: \%loginhash);
7363: }
1.110 raeburn 7364:
1.149 raeburn 7365: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 7366: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7367: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7368: if (keys(%servers) > 1) {
7369: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7370: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7371: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7372: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7373: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7374: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7375: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7376: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7377: $changes{'loginvia'}{$lonhost} = 1;
7378: } else {
7379: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7380: $changes{'loginvia'}{$lonhost} = 1;
7381: }
7382: } else {
7383: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7384: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7385: $changes{'loginvia'}{$lonhost} = 1;
7386: }
7387: }
7388: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7389: foreach my $item (@loginvia_attribs) {
7390: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7391: }
7392: } else {
7393: foreach my $item (@loginvia_attribs) {
7394: my $new = $env{'form.'.$lonhost.'_'.$item};
7395: if (($item eq 'serverpath') && ($new eq 'custom')) {
7396: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7397: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7398: $new = '/';
7399: }
7400: }
7401: if (($item eq 'custompath') &&
7402: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7403: $new = '';
7404: }
7405: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7406: $changes{'loginvia'}{$lonhost} = 1;
7407: }
7408: if ($item eq 'exempt') {
1.160.6.56 raeburn 7409: $new = &check_exempt_addresses($new);
1.128 raeburn 7410: }
7411: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7412: }
7413: }
1.112 raeburn 7414: } else {
1.128 raeburn 7415: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7416: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7417: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7418: foreach my $item (@loginvia_attribs) {
7419: my $new = $env{'form.'.$lonhost.'_'.$item};
7420: if (($item eq 'serverpath') && ($new eq 'custom')) {
7421: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7422: $new = '/';
7423: }
7424: }
7425: if (($item eq 'custompath') &&
7426: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7427: $new = '';
7428: }
7429: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7430: }
1.110 raeburn 7431: }
7432: }
7433: }
7434: }
1.119 raeburn 7435:
1.160.6.5 raeburn 7436: my $servadm = $r->dir_config('lonAdmEMail');
7437: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7438: if (ref($domconfig{'login'}) eq 'HASH') {
7439: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7440: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7441: if ($lang eq 'nolang') {
7442: push(@currlangs,$lang);
7443: } elsif (defined($langchoices{$lang})) {
7444: push(@currlangs,$lang);
7445: } else {
7446: next;
7447: }
7448: }
7449: }
7450: }
7451: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7452: if (@currlangs > 0) {
7453: foreach my $lang (@currlangs) {
7454: if (grep(/^\Q$lang\E$/,@delurls)) {
7455: $changes{'helpurl'}{$lang} = 1;
7456: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7457: $changes{'helpurl'}{$lang} = 1;
7458: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7459: push(@newlangs,$lang);
7460: } else {
7461: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7462: }
7463: }
7464: }
7465: unless (grep(/^nolang$/,@currlangs)) {
7466: if ($env{'form.loginhelpurl_nolang.filename'}) {
7467: $changes{'helpurl'}{'nolang'} = 1;
7468: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7469: push(@newlangs,'nolang');
7470: }
7471: }
7472: if ($env{'form.loginhelpurl_add_lang'}) {
7473: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7474: ($env{'form.loginhelpurl_add_file.filename'})) {
7475: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7476: $addedfile = $env{'form.loginhelpurl_add_lang'};
7477: }
7478: }
7479: if ((@newlangs > 0) || ($addedfile)) {
7480: my $error;
7481: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7482: if ($configuserok eq 'ok') {
7483: if ($switchserver) {
7484: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7485: } elsif ($author_ok eq 'ok') {
7486: my @allnew = @newlangs;
7487: if ($addedfile ne '') {
7488: push(@allnew,$addedfile);
7489: }
7490: foreach my $lang (@allnew) {
7491: my $formelem = 'loginhelpurl_'.$lang;
7492: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7493: $formelem = 'loginhelpurl_add_file';
7494: }
7495: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7496: "help/$lang",'','',$newfile{$lang});
7497: if ($result eq 'ok') {
7498: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7499: $changes{'helpurl'}{$lang} = 1;
7500: } else {
7501: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7502: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7503: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
7504: (!grep(/^\Q$lang\E$/,@delurls))) {
7505: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7506: }
7507: }
7508: }
7509: } else {
7510: $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);
7511: }
7512: } else {
7513: $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);
7514: }
7515: if ($error) {
7516: &Apache::lonnet::logthis($error);
7517: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7518: }
7519: }
1.160.6.56 raeburn 7520:
7521: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7522: if (ref($domconfig{'login'}) eq 'HASH') {
7523: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7524: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7525: if ($domservers{$lonhost}) {
7526: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7527: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 7528: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 7529: }
7530: }
7531: }
7532: }
7533: }
7534: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7535: foreach my $lonhost (sort(keys(%domservers))) {
7536: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7537: $changes{'headtag'}{$lonhost} = 1;
7538: } else {
7539: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7540: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7541: }
7542: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7543: push(@newhosts,$lonhost);
7544: } elsif ($currheadtagurls{$lonhost}) {
7545: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7546: if ($currexempt{$lonhost}) {
7547: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
7548: $changes{'headtag'}{$lonhost} = 1;
7549: }
7550: } elsif ($possexempt{$lonhost}) {
7551: $changes{'headtag'}{$lonhost} = 1;
7552: }
7553: if ($possexempt{$lonhost}) {
7554: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7555: }
7556: }
7557: }
7558: }
7559: if (@newhosts) {
7560: my $error;
7561: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7562: if ($configuserok eq 'ok') {
7563: if ($switchserver) {
7564: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7565: } elsif ($author_ok eq 'ok') {
7566: foreach my $lonhost (@newhosts) {
7567: my $formelem = 'loginheadtag_'.$lonhost;
7568: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7569: "login/headtag/$lonhost",'','',
7570: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7571: if ($result eq 'ok') {
7572: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7573: $changes{'headtag'}{$lonhost} = 1;
7574: if ($possexempt{$lonhost}) {
7575: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7576: }
7577: } else {
7578: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7579: $newheadtagurls{$lonhost},$result);
7580: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7581: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7582: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7583: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7584: }
7585: }
7586: }
7587: } else {
7588: $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);
7589: }
7590: } else {
7591: $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);
7592: }
7593: if ($error) {
7594: &Apache::lonnet::logthis($error);
7595: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7596: }
7597: }
1.160.6.5 raeburn 7598: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7599:
7600: my $defaulthelpfile = '/adm/loginproblems.html';
7601: my $defaulttext = &mt('Default in use');
7602:
1.1 raeburn 7603: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7604: $dom);
7605: if ($putresult eq 'ok') {
1.160.6.14 raeburn 7606: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7607: my %defaultchecked = (
7608: 'coursecatalog' => 'on',
1.160.6.14 raeburn 7609: 'helpdesk' => 'on',
1.42 raeburn 7610: 'adminmail' => 'off',
1.43 raeburn 7611: 'newuser' => 'off',
1.42 raeburn 7612: );
1.55 raeburn 7613: if (ref($domconfig{'login'}) eq 'HASH') {
7614: foreach my $item (@toggles) {
7615: if ($defaultchecked{$item} eq 'on') {
7616: if (($domconfig{'login'}{$item} eq '0') &&
7617: ($env{'form.'.$item} eq '1')) {
7618: $changes{$item} = 1;
7619: } elsif (($domconfig{'login'}{$item} eq '' ||
7620: $domconfig{'login'}{$item} eq '1') &&
7621: ($env{'form.'.$item} eq '0')) {
7622: $changes{$item} = 1;
7623: }
7624: } elsif ($defaultchecked{$item} eq 'off') {
7625: if (($domconfig{'login'}{$item} eq '1') &&
7626: ($env{'form.'.$item} eq '0')) {
7627: $changes{$item} = 1;
7628: } elsif (($domconfig{'login'}{$item} eq '' ||
7629: $domconfig{'login'}{$item} eq '0') &&
7630: ($env{'form.'.$item} eq '1')) {
7631: $changes{$item} = 1;
7632: }
1.42 raeburn 7633: }
7634: }
1.41 raeburn 7635: }
1.6 raeburn 7636: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7637: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7638: if (ref($lastactref) eq 'HASH') {
7639: $lastactref->{'domainconfig'} = 1;
7640: }
1.1 raeburn 7641: $resulttext = &mt('Changes made:').'<ul>';
7642: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7643: if ($item eq 'loginvia') {
1.112 raeburn 7644: if (ref($changes{$item}) eq 'HASH') {
7645: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7646: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7647: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7648: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7649: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7650: $protocol = 'http' if ($protocol ne 'https');
7651: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7652:
7653: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7654: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7655: } else {
7656: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7657: }
7658: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7659: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7660: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7661: }
7662: $resulttext .= '</li>';
7663: } else {
7664: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7665: }
1.112 raeburn 7666: } else {
1.128 raeburn 7667: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7668: }
7669: }
1.128 raeburn 7670: $resulttext .= '</ul></li>';
1.112 raeburn 7671: }
1.160.6.5 raeburn 7672: } elsif ($item eq 'helpurl') {
7673: if (ref($changes{$item}) eq 'HASH') {
7674: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7675: if (grep(/^\Q$lang\E$/,@delurls)) {
7676: my ($chg,$link);
7677: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7678: if ($lang eq 'nolang') {
7679: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7680: } else {
7681: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7682: }
7683: $resulttext .= '<li>'.$chg.'</li>';
7684: } else {
7685: my $chg;
7686: if ($lang eq 'nolang') {
7687: $chg = &mt('custom log-in help file for no preferred language');
7688: } else {
7689: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7690: }
7691: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7692: $loginhash{'login'}{'helpurl'}{$lang}.
7693: '?inhibitmenu=yes',$chg,600,500).
7694: '</li>';
7695: }
7696: }
7697: }
1.160.6.56 raeburn 7698: } elsif ($item eq 'headtag') {
7699: if (ref($changes{$item}) eq 'HASH') {
7700: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7701: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7702: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7703: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7704: $resulttext .= '<li><a href="'.
7705: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7706: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7707: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7708: if ($possexempt{$lonhost}) {
7709: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7710: } else {
7711: $resulttext .= &mt('included for any client IP');
7712: }
7713: $resulttext .= '</li>';
7714: }
7715: }
7716: }
1.160.6.5 raeburn 7717: } elsif ($item eq 'captcha') {
7718: if (ref($loginhash{'login'}) eq 'HASH') {
7719: my $chgtxt;
7720: if ($loginhash{'login'}{$item} eq 'notused') {
7721: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7722: } else {
7723: my %captchas = &captcha_phrases();
7724: if ($captchas{$loginhash{'login'}{$item}}) {
7725: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7726: } else {
7727: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7728: }
7729: }
7730: $resulttext .= '<li>'.$chgtxt.'</li>';
7731: }
7732: } elsif ($item eq 'recaptchakeys') {
7733: if (ref($loginhash{'login'}) eq 'HASH') {
7734: my ($privkey,$pubkey);
7735: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7736: $pubkey = $loginhash{'login'}{$item}{'public'};
7737: $privkey = $loginhash{'login'}{$item}{'private'};
7738: }
7739: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7740: if (!$pubkey) {
7741: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7742: } else {
7743: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7744: }
7745: if (!$privkey) {
7746: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7747: } else {
1.160.6.53 raeburn 7748: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 7749: }
7750: $chgtxt .= '</ul>';
7751: $resulttext .= '<li>'.$chgtxt.'</li>';
7752: }
1.160.6.69 raeburn 7753: } elsif ($item eq 'recaptchaversion') {
7754: if (ref($loginhash{'login'}) eq 'HASH') {
7755: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
7756: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
7757: '</li>';
7758: }
7759: }
1.41 raeburn 7760: } else {
7761: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7762: }
1.1 raeburn 7763: }
1.6 raeburn 7764: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7765: } else {
7766: $resulttext = &mt('No changes made to log-in page settings');
7767: }
7768: } else {
1.11 albertel 7769: $resulttext = '<span class="LC_error">'.
7770: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7771: }
1.6 raeburn 7772: if ($errors) {
1.9 raeburn 7773: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7774: $errors.'</ul>';
7775: }
7776: return $resulttext;
7777: }
7778:
1.160.6.56 raeburn 7779: sub check_exempt_addresses {
7780: my ($iplist) = @_;
7781: $iplist =~ s/^\s+//;
7782: $iplist =~ s/\s+$//;
7783: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7784: my (@okips,$new);
7785: foreach my $ip (@poss_ips) {
7786: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7787: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7788: push(@okips,$ip);
7789: }
7790: }
7791: }
7792: if (@okips > 0) {
7793: $new = join(',',@okips);
7794: } else {
7795: $new = '';
7796: }
7797: return $new;
7798: }
7799:
1.6 raeburn 7800: sub color_font_choices {
7801: my %choices =
7802: &Apache::lonlocal::texthash (
7803: img => "Header",
7804: bgs => "Background colors",
7805: links => "Link colors",
1.55 raeburn 7806: images => "Images",
1.6 raeburn 7807: font => "Font color",
1.160.6.22 raeburn 7808: fontmenu => "Font menu",
1.76 raeburn 7809: pgbg => "Page",
1.6 raeburn 7810: tabbg => "Header",
7811: sidebg => "Border",
7812: link => "Link",
7813: alink => "Active link",
7814: vlink => "Visited link",
7815: );
7816: return %choices;
7817: }
7818:
7819: sub modify_rolecolors {
1.160.6.24 raeburn 7820: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7821: my ($resulttext,%rolehash);
7822: $rolehash{'rolecolors'} = {};
1.55 raeburn 7823: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7824: if ($domconfig{'rolecolors'} eq '') {
7825: $domconfig{'rolecolors'} = {};
7826: }
7827: }
1.9 raeburn 7828: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7829: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7830: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7831: $dom);
7832: if ($putresult eq 'ok') {
7833: if (keys(%changes) > 0) {
1.41 raeburn 7834: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7835: if (ref($lastactref) eq 'HASH') {
7836: $lastactref->{'domainconfig'} = 1;
7837: }
1.6 raeburn 7838: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7839: $rolehash{'rolecolors'});
7840: } else {
7841: $resulttext = &mt('No changes made to default color schemes');
7842: }
7843: } else {
1.11 albertel 7844: $resulttext = '<span class="LC_error">'.
7845: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7846: }
7847: if ($errors) {
7848: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7849: $errors.'</ul>';
7850: }
7851: return $resulttext;
7852: }
7853:
7854: sub modify_colors {
1.9 raeburn 7855: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7856: my (%changes,%choices);
1.51 raeburn 7857: my @bgs;
1.6 raeburn 7858: my @links = ('link','alink','vlink');
1.41 raeburn 7859: my @logintext;
1.6 raeburn 7860: my @images;
7861: my $servadm = $r->dir_config('lonAdmEMail');
7862: my $errors;
1.160.6.22 raeburn 7863: my %defaults;
1.6 raeburn 7864: foreach my $role (@{$roles}) {
7865: if ($role eq 'login') {
1.12 raeburn 7866: %choices = &login_choices();
1.41 raeburn 7867: @logintext = ('textcol','bgcol');
1.12 raeburn 7868: } else {
7869: %choices = &color_font_choices();
7870: }
7871: if ($role eq 'login') {
1.41 raeburn 7872: @images = ('img','logo','domlogo','login');
1.51 raeburn 7873: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7874: } else {
7875: @images = ('img');
1.160.6.22 raeburn 7876: @bgs = ('pgbg','tabbg','sidebg');
7877: }
7878: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7879: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7880: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7881: }
7882: if ($role eq 'login') {
7883: foreach my $item (@logintext) {
1.160.6.39 raeburn 7884: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7885: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7886: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7887: }
7888: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 7889: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7890: }
7891: }
7892: } else {
1.160.6.39 raeburn 7893: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7894: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7895: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7896: }
7897: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 7898: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7899: }
1.6 raeburn 7900: }
1.160.6.22 raeburn 7901: foreach my $item (@bgs) {
1.160.6.39 raeburn 7902: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7903: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7904: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7905: }
7906: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 7907: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7908: }
7909: }
7910: foreach my $item (@links) {
1.160.6.39 raeburn 7911: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7912: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7913: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7914: }
7915: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 7916: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7917: }
1.6 raeburn 7918: }
1.46 raeburn 7919: my ($configuserok,$author_ok,$switchserver) =
7920: &config_check($dom,$confname,$servadm);
1.9 raeburn 7921: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7922: if (ref($domconfig->{$role}) ne 'HASH') {
7923: $domconfig->{$role} = {};
7924: }
1.8 raeburn 7925: foreach my $img (@images) {
1.70 raeburn 7926: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7927: if (defined($env{'form.login_showlogo_'.$img})) {
7928: $confhash->{$role}{'showlogo'}{$img} = 1;
7929: } else {
7930: $confhash->{$role}{'showlogo'}{$img} = 0;
7931: }
7932: }
1.18 albertel 7933: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7934: && !defined($domconfig->{$role}{$img})
7935: && !$env{'form.'.$role.'_del_'.$img}
7936: && $env{'form.'.$role.'_import_'.$img}) {
7937: # import the old configured image from the .tab setting
7938: # if they haven't provided a new one
7939: $domconfig->{$role}{$img} =
7940: $env{'form.'.$role.'_import_'.$img};
7941: }
1.6 raeburn 7942: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7943: my $error;
1.6 raeburn 7944: if ($configuserok eq 'ok') {
1.9 raeburn 7945: if ($switchserver) {
1.12 raeburn 7946: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7947: } else {
7948: if ($author_ok eq 'ok') {
7949: my ($result,$logourl) =
7950: &publishlogo($r,'upload',$role.'_'.$img,
7951: $dom,$confname,$img,$width,$height);
7952: if ($result eq 'ok') {
7953: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7954: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7955: } else {
1.12 raeburn 7956: $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 7957: }
7958: } else {
1.46 raeburn 7959: $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 7960: }
7961: }
7962: } else {
1.46 raeburn 7963: $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 7964: }
7965: if ($error) {
1.8 raeburn 7966: &Apache::lonnet::logthis($error);
1.11 albertel 7967: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7968: }
7969: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7970: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7971: my $error;
7972: if ($configuserok eq 'ok') {
7973: # is confname an author?
7974: if ($switchserver eq '') {
7975: if ($author_ok eq 'ok') {
7976: my ($result,$logourl) =
7977: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7978: $dom,$confname,$img,$width,$height);
7979: if ($result eq 'ok') {
7980: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7981: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7982: }
7983: }
7984: }
7985: }
1.6 raeburn 7986: }
7987: }
7988: }
7989: if (ref($domconfig) eq 'HASH') {
7990: if (ref($domconfig->{$role}) eq 'HASH') {
7991: foreach my $img (@images) {
7992: if ($domconfig->{$role}{$img} ne '') {
7993: if ($env{'form.'.$role.'_del_'.$img}) {
7994: $confhash->{$role}{$img} = '';
1.12 raeburn 7995: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7996: } else {
1.9 raeburn 7997: if ($confhash->{$role}{$img} eq '') {
7998: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7999: }
1.6 raeburn 8000: }
8001: } else {
8002: if ($env{'form.'.$role.'_del_'.$img}) {
8003: $confhash->{$role}{$img} = '';
1.12 raeburn 8004: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 8005: }
8006: }
1.70 raeburn 8007: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
8008: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
8009: if ($confhash->{$role}{'showlogo'}{$img} ne
8010: $domconfig->{$role}{'showlogo'}{$img}) {
8011: $changes{$role}{'showlogo'}{$img} = 1;
8012: }
8013: } else {
8014: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8015: $changes{$role}{'showlogo'}{$img} = 1;
8016: }
8017: }
8018: }
8019: }
1.6 raeburn 8020: if ($domconfig->{$role}{'font'} ne '') {
8021: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
8022: $changes{$role}{'font'} = 1;
8023: }
8024: } else {
8025: if ($confhash->{$role}{'font'}) {
8026: $changes{$role}{'font'} = 1;
8027: }
8028: }
1.107 raeburn 8029: if ($role ne 'login') {
8030: if ($domconfig->{$role}{'fontmenu'} ne '') {
8031: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
8032: $changes{$role}{'fontmenu'} = 1;
8033: }
8034: } else {
8035: if ($confhash->{$role}{'fontmenu'}) {
8036: $changes{$role}{'fontmenu'} = 1;
8037: }
1.97 tempelho 8038: }
8039: }
1.6 raeburn 8040: foreach my $item (@bgs) {
8041: if ($domconfig->{$role}{$item} ne '') {
8042: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8043: $changes{$role}{'bgs'}{$item} = 1;
8044: }
8045: } else {
8046: if ($confhash->{$role}{$item}) {
8047: $changes{$role}{'bgs'}{$item} = 1;
8048: }
8049: }
8050: }
8051: foreach my $item (@links) {
8052: if ($domconfig->{$role}{$item} ne '') {
8053: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8054: $changes{$role}{'links'}{$item} = 1;
8055: }
8056: } else {
8057: if ($confhash->{$role}{$item}) {
8058: $changes{$role}{'links'}{$item} = 1;
8059: }
8060: }
8061: }
1.41 raeburn 8062: foreach my $item (@logintext) {
8063: if ($domconfig->{$role}{$item} ne '') {
8064: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
8065: $changes{$role}{'logintext'}{$item} = 1;
8066: }
8067: } else {
8068: if ($confhash->{$role}{$item}) {
8069: $changes{$role}{'logintext'}{$item} = 1;
8070: }
8071: }
8072: }
1.6 raeburn 8073: } else {
8074: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8075: \@logintext,$confhash,\%changes);
1.6 raeburn 8076: }
8077: } else {
8078: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 8079: \@logintext,$confhash,\%changes);
1.6 raeburn 8080: }
8081: }
8082: return ($errors,%changes);
8083: }
8084:
1.46 raeburn 8085: sub config_check {
8086: my ($dom,$confname,$servadm) = @_;
8087: my ($configuserok,$author_ok,$switchserver,%currroles);
8088: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
8089: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
8090: $confname,$servadm);
8091: if ($configuserok eq 'ok') {
8092: $switchserver = &check_switchserver($dom,$confname);
8093: if ($switchserver eq '') {
8094: $author_ok = &check_authorstatus($dom,$confname,%currroles);
8095: }
8096: }
8097: return ($configuserok,$author_ok,$switchserver);
8098: }
8099:
1.6 raeburn 8100: sub default_change_checker {
1.41 raeburn 8101: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 8102: foreach my $item (@{$links}) {
8103: if ($confhash->{$role}{$item}) {
8104: $changes->{$role}{'links'}{$item} = 1;
8105: }
8106: }
8107: foreach my $item (@{$bgs}) {
8108: if ($confhash->{$role}{$item}) {
8109: $changes->{$role}{'bgs'}{$item} = 1;
8110: }
8111: }
1.41 raeburn 8112: foreach my $item (@{$logintext}) {
8113: if ($confhash->{$role}{$item}) {
8114: $changes->{$role}{'logintext'}{$item} = 1;
8115: }
8116: }
1.6 raeburn 8117: foreach my $img (@{$images}) {
8118: if ($env{'form.'.$role.'_del_'.$img}) {
8119: $confhash->{$role}{$img} = '';
1.12 raeburn 8120: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 8121: }
1.70 raeburn 8122: if ($role eq 'login') {
8123: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
8124: $changes->{$role}{'showlogo'}{$img} = 1;
8125: }
8126: }
1.6 raeburn 8127: }
8128: if ($confhash->{$role}{'font'}) {
8129: $changes->{$role}{'font'} = 1;
8130: }
1.48 raeburn 8131: }
1.6 raeburn 8132:
8133: sub display_colorchgs {
8134: my ($dom,$changes,$roles,$confhash) = @_;
8135: my (%choices,$resulttext);
8136: if (!grep(/^login$/,@{$roles})) {
8137: $resulttext = &mt('Changes made:').'<br />';
8138: }
8139: foreach my $role (@{$roles}) {
8140: if ($role eq 'login') {
8141: %choices = &login_choices();
8142: } else {
8143: %choices = &color_font_choices();
8144: }
8145: if (ref($changes->{$role}) eq 'HASH') {
8146: if ($role ne 'login') {
8147: $resulttext .= '<h4>'.&mt($role).'</h4>';
8148: }
8149: foreach my $key (sort(keys(%{$changes->{$role}}))) {
8150: if ($role ne 'login') {
8151: $resulttext .= '<ul>';
8152: }
8153: if (ref($changes->{$role}{$key}) eq 'HASH') {
8154: if ($role ne 'login') {
8155: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
8156: }
8157: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 8158: if (($role eq 'login') && ($key eq 'showlogo')) {
8159: if ($confhash->{$role}{$key}{$item}) {
8160: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
8161: } else {
8162: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
8163: }
8164: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 8165: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
8166: } else {
1.12 raeburn 8167: my $newitem = $confhash->{$role}{$item};
8168: if ($key eq 'images') {
8169: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
8170: }
8171: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 8172: }
8173: }
8174: if ($role ne 'login') {
8175: $resulttext .= '</ul></li>';
8176: }
8177: } else {
8178: if ($confhash->{$role}{$key} eq '') {
8179: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
8180: } else {
8181: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8182: }
8183: }
8184: if ($role ne 'login') {
8185: $resulttext .= '</ul>';
8186: }
8187: }
8188: }
8189: }
1.3 raeburn 8190: return $resulttext;
1.1 raeburn 8191: }
8192:
1.9 raeburn 8193: sub thumb_dimensions {
8194: return ('200','50');
8195: }
8196:
1.16 raeburn 8197: sub check_dimensions {
8198: my ($inputfile) = @_;
8199: my ($fullwidth,$fullheight);
8200: if ($inputfile =~ m|^[/\w.\-]+$|) {
8201: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8202: my $imageinfo = <PIPE>;
8203: if (!close(PIPE)) {
8204: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8205: }
8206: chomp($imageinfo);
8207: my ($fullsize) =
1.21 raeburn 8208: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8209: if ($fullsize) {
8210: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8211: }
8212: }
8213: }
8214: return ($fullwidth,$fullheight);
8215: }
8216:
1.9 raeburn 8217: sub check_configuser {
8218: my ($uhome,$dom,$confname,$servadm) = @_;
8219: my ($configuserok,%currroles);
8220: if ($uhome eq 'no_host') {
8221: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8222: my $configpass = &LONCAPA::Enrollment::create_password();
8223: $configuserok =
8224: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8225: $configpass,'','','','','',undef,$servadm);
8226: } else {
8227: $configuserok = 'ok';
8228: %currroles =
8229: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8230: }
8231: return ($configuserok,%currroles);
8232: }
8233:
8234: sub check_authorstatus {
8235: my ($dom,$confname,%currroles) = @_;
8236: my $author_ok;
1.40 raeburn 8237: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8238: my $start = time;
8239: my $end = 0;
8240: $author_ok =
8241: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8242: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8243: } else {
8244: $author_ok = 'ok';
8245: }
8246: return $author_ok;
8247: }
8248:
8249: sub publishlogo {
1.46 raeburn 8250: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 8251: my ($output,$fname,$logourl);
8252: if ($action eq 'upload') {
8253: $fname=$env{'form.'.$formname.'.filename'};
8254: chop($env{'form.'.$formname});
8255: } else {
8256: ($fname) = ($formname =~ /([^\/]+)$/);
8257: }
1.46 raeburn 8258: if ($savefileas ne '') {
8259: $fname = $savefileas;
8260: }
1.9 raeburn 8261: $fname=&Apache::lonnet::clean_filename($fname);
8262: # See if there is anything left
8263: unless ($fname) { return ('error: no uploaded file'); }
8264: $fname="$subdir/$fname";
1.160.6.5 raeburn 8265: my $docroot=$r->dir_config('lonDocRoot');
8266: my $filepath="$docroot/priv";
8267: my $relpath = "$dom/$confname";
1.9 raeburn 8268: my ($fnamepath,$file,$fetchthumb);
8269: $file=$fname;
8270: if ($fname=~m|/|) {
8271: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8272: }
1.160.6.26 raeburn 8273: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8274: my $count;
1.160.6.5 raeburn 8275: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8276: $filepath.="/$parts[$count]";
8277: if ((-e $filepath)!=1) {
8278: mkdir($filepath,02770);
8279: }
8280: }
8281: # Check for bad extension and disallow upload
8282: if ($file=~/\.(\w+)$/ &&
8283: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8284: $output =
1.160.6.25 raeburn 8285: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8286: } elsif ($file=~/\.(\w+)$/ &&
8287: !defined(&Apache::loncommon::fileembstyle($1))) {
8288: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8289: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 8290: $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 8291: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 8292: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8293: } else {
8294: my $source = $filepath.'/'.$file;
8295: my $logfile;
1.160.6.88 raeburn 8296: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 8297: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8298: }
8299: print $logfile
8300: "\n================= Publish ".localtime()." ================\n".
8301: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8302: # Save the file
1.160.6.88 raeburn 8303: if (!open(FH,">",$source)) {
1.9 raeburn 8304: &Apache::lonnet::logthis('Failed to create '.$source);
8305: return (&mt('Failed to create file'));
8306: }
8307: if ($action eq 'upload') {
8308: if (!print FH ($env{'form.'.$formname})) {
8309: &Apache::lonnet::logthis('Failed to write to '.$source);
8310: return (&mt('Failed to write file'));
8311: }
8312: } else {
8313: my $original = &Apache::lonnet::filelocation('',$formname);
8314: if(!copy($original,$source)) {
8315: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8316: return (&mt('Failed to write file'));
8317: }
8318: }
8319: close(FH);
8320: chmod(0660, $source); # Permissions to rw-rw---.
8321:
8322: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8323: my $copyfile=$targetdir.'/'.$file;
8324:
8325: my @parts=split(/\//,$targetdir);
8326: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8327: for (my $count=5;$count<=$#parts;$count++) {
8328: $path.="/$parts[$count]";
8329: if (!-e $path) {
8330: print $logfile "\nCreating directory ".$path;
8331: mkdir($path,02770);
8332: }
8333: }
8334: my $versionresult;
8335: if (-e $copyfile) {
8336: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8337: } else {
8338: $versionresult = 'ok';
8339: }
8340: if ($versionresult eq 'ok') {
8341: if (copy($source,$copyfile)) {
8342: print $logfile "\nCopied original source to ".$copyfile."\n";
8343: $output = 'ok';
8344: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8345: push(@{$modified_urls},[$copyfile,$source]);
8346: my $metaoutput =
8347: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8348: unless ($registered_cleanup) {
8349: my $handlers = $r->get_handlers('PerlCleanupHandler');
8350: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8351: $registered_cleanup=1;
8352: }
1.9 raeburn 8353: } else {
8354: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8355: $output = &mt('Failed to copy file to RES space').", $!";
8356: }
8357: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8358: my $inputfile = $filepath.'/'.$file;
8359: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8360: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8361: if ($fullwidth ne '' && $fullheight ne '') {
8362: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8363: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 8364: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
8365: system({$args[0]} @args);
1.16 raeburn 8366: chmod(0660, $filepath.'/tn-'.$file);
8367: if (-e $outfile) {
8368: my $copyfile=$targetdir.'/tn-'.$file;
8369: if (copy($outfile,$copyfile)) {
8370: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8371: my $thumb_metaoutput =
8372: &write_metadata($dom,$confname,$formname,
8373: $targetdir,'tn-'.$file,$logfile);
8374: push(@{$modified_urls},[$copyfile,$outfile]);
8375: unless ($registered_cleanup) {
8376: my $handlers = $r->get_handlers('PerlCleanupHandler');
8377: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8378: $registered_cleanup=1;
8379: }
1.16 raeburn 8380: } else {
8381: print $logfile "\nUnable to write ".$copyfile.
8382: ':'.$!."\n";
8383: }
8384: }
1.9 raeburn 8385: }
8386: }
8387: }
8388: } else {
8389: $output = $versionresult;
8390: }
8391: }
8392: return ($output,$logourl);
8393: }
8394:
8395: sub logo_versioning {
8396: my ($targetdir,$file,$logfile) = @_;
8397: my $target = $targetdir.'/'.$file;
8398: my ($maxversion,$fn,$extn,$output);
8399: $maxversion = 0;
8400: if ($file =~ /^(.+)\.(\w+)$/) {
8401: $fn=$1;
8402: $extn=$2;
8403: }
8404: opendir(DIR,$targetdir);
8405: while (my $filename=readdir(DIR)) {
8406: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8407: $maxversion=($1>$maxversion)?$1:$maxversion;
8408: }
8409: }
8410: $maxversion++;
8411: print $logfile "\nCreating old version ".$maxversion."\n";
8412: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8413: if (copy($target,$copyfile)) {
8414: print $logfile "Copied old target to ".$copyfile."\n";
8415: $copyfile=$copyfile.'.meta';
8416: if (copy($target.'.meta',$copyfile)) {
8417: print $logfile "Copied old target metadata to ".$copyfile."\n";
8418: $output = 'ok';
8419: } else {
8420: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8421: $output = &mt('Failed to copy old meta').", $!, ";
8422: }
8423: } else {
8424: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8425: $output = &mt('Failed to copy old target').", $!, ";
8426: }
8427: return $output;
8428: }
8429:
8430: sub write_metadata {
8431: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8432: my (%metadatafields,%metadatakeys,$output);
8433: $metadatafields{'title'}=$formname;
8434: $metadatafields{'creationdate'}=time;
8435: $metadatafields{'lastrevisiondate'}=time;
8436: $metadatafields{'copyright'}='public';
8437: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8438: $env{'user.domain'};
8439: $metadatafields{'authorspace'}=$confname.':'.$dom;
8440: $metadatafields{'domain'}=$dom;
8441: {
8442: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8443: my $mfh;
1.160.6.88 raeburn 8444: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 8445: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8446: unless ($_=~/\./) {
8447: my $unikey=$_;
8448: $unikey=~/^([A-Za-z]+)/;
8449: my $tag=$1;
8450: $tag=~tr/A-Z/a-z/;
8451: print $mfh "\n\<$tag";
8452: foreach (split(/\,/,$metadatakeys{$unikey})) {
8453: my $value=$metadatafields{$unikey.'.'.$_};
8454: $value=~s/\"/\'\'/g;
8455: print $mfh ' '.$_.'="'.$value.'"';
8456: }
8457: print $mfh '>'.
8458: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8459: .'</'.$tag.'>';
8460: }
8461: }
8462: $output = 'ok';
8463: print $logfile "\nWrote metadata";
8464: close($mfh);
8465: } else {
8466: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8467: $output = &mt('Could not write metadata');
8468: }
8469: }
1.155 raeburn 8470: return $output;
8471: }
8472:
8473: sub notifysubscribed {
8474: foreach my $targetsource (@{$modified_urls}){
8475: next unless (ref($targetsource) eq 'ARRAY');
8476: my ($target,$source)=@{$targetsource};
8477: if ($source ne '') {
1.160.6.88 raeburn 8478: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 8479: print $logfh "\nCleanup phase: Notifications\n";
8480: my @subscribed=&subscribed_hosts($target);
8481: foreach my $subhost (@subscribed) {
8482: print $logfh "\nNotifying host ".$subhost.':';
8483: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8484: print $logfh $reply;
8485: }
8486: my @subscribedmeta=&subscribed_hosts("$target.meta");
8487: foreach my $subhost (@subscribedmeta) {
8488: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8489: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8490: $subhost);
8491: print $logfh $reply;
8492: }
8493: print $logfh "\n============ Done ============\n";
1.160 raeburn 8494: close($logfh);
1.155 raeburn 8495: }
8496: }
8497: }
8498: return OK;
8499: }
8500:
8501: sub subscribed_hosts {
8502: my ($target) = @_;
8503: my @subscribed;
1.160.6.88 raeburn 8504: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 8505: while (my $subline=<$fh>) {
8506: if ($subline =~ /^($match_lonid):/) {
8507: my $host = $1;
8508: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8509: unless (grep(/^\Q$host\E$/,@subscribed)) {
8510: push(@subscribed,$host);
8511: }
8512: }
8513: }
8514: }
8515: }
8516: return @subscribed;
1.9 raeburn 8517: }
8518:
8519: sub check_switchserver {
8520: my ($dom,$confname) = @_;
8521: my ($allowed,$switchserver);
8522: my $home = &Apache::lonnet::homeserver($confname,$dom);
8523: if ($home eq 'no_host') {
8524: $home = &Apache::lonnet::domain($dom,'primary');
8525: }
8526: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8527: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8528: if (!$allowed) {
1.160.6.11 raeburn 8529: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8530: }
8531: return $switchserver;
8532: }
8533:
1.1 raeburn 8534: sub modify_quotas {
1.160.6.30 raeburn 8535: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8536: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 8537: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 8538: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8539: $validationfieldsref);
1.86 raeburn 8540: if ($action eq 'quotas') {
8541: $context = 'tools';
1.160.6.26 raeburn 8542: } else {
1.86 raeburn 8543: $context = $action;
8544: }
8545: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 8546: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 8547: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8548: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8549: %titles = &courserequest_titles();
8550: $toolregexp = join('|',@usertools);
8551: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 8552: $confname = $dom.'-domainconfig';
8553: my $servadm = $r->dir_config('lonAdmEMail');
8554: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 8555: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8556: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 8557: } elsif ($context eq 'requestauthor') {
8558: @usertools = ('author');
8559: %titles = &authorrequest_titles();
1.86 raeburn 8560: } else {
1.160.6.4 raeburn 8561: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8562: %titles = &tool_titles();
1.86 raeburn 8563: }
1.160.6.27 raeburn 8564: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8565: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8566: foreach my $key (keys(%env)) {
1.101 raeburn 8567: if ($context eq 'requestcourses') {
8568: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8569: my $item = $1;
8570: my $type = $2;
8571: if ($type =~ /^limit_(.+)/) {
8572: $limithash{$item}{$1} = $env{$key};
8573: } else {
8574: $confhash{$item}{$type} = $env{$key};
8575: }
8576: }
1.160.6.5 raeburn 8577: } elsif ($context eq 'requestauthor') {
8578: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8579: $confhash{$1} = $env{$key};
8580: }
1.101 raeburn 8581: } else {
1.86 raeburn 8582: if ($key =~ /^form\.quota_(.+)$/) {
8583: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 8584: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8585: $confhash{'authorquota'}{$1} = $env{$key};
8586: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8587: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8588: }
1.72 raeburn 8589: }
8590: }
1.160.6.5 raeburn 8591: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 8592: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8593: @approvalnotify = sort(@approvalnotify);
8594: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 8595: my @crstypes = ('official','unofficial','community','textbook');
8596: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8597: foreach my $type (@hasuniquecode) {
8598: if (grep(/^\Q$type\E$/,@crstypes)) {
8599: $confhash{'uniquecode'}{$type} = 1;
8600: }
8601: }
1.160.6.46 raeburn 8602: my (%newbook,%allpos);
1.160.6.30 raeburn 8603: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8604: foreach my $type ('textbooks','templates') {
8605: @{$allpos{$type}} = ();
8606: my $invalid;
8607: if ($type eq 'textbooks') {
8608: $invalid = &mt('Invalid LON-CAPA course for textbook');
8609: } else {
8610: $invalid = &mt('Invalid LON-CAPA course for template');
8611: }
8612: if ($env{'form.'.$type.'_addbook'}) {
8613: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8614: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8615: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8616: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8617: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8618: } else {
8619: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8620: my $position = $env{'form.'.$type.'_addbook_pos'};
8621: $position =~ s/\D+//g;
8622: if ($position ne '') {
8623: $allpos{$type}[$position] = $newbook{$type};
8624: }
1.160.6.30 raeburn 8625: }
1.160.6.46 raeburn 8626: } else {
8627: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 8628: }
8629: }
1.160.6.46 raeburn 8630: }
1.160.6.30 raeburn 8631: }
1.102 raeburn 8632: if (ref($domconfig{$action}) eq 'HASH') {
8633: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8634: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8635: $changes{'notify'}{'approval'} = 1;
8636: }
8637: } else {
1.144 raeburn 8638: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8639: $changes{'notify'}{'approval'} = 1;
8640: }
8641: }
1.160.6.30 raeburn 8642: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8643: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8644: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8645: unless ($confhash{'uniquecode'}{$crstype}) {
8646: $changes{'uniquecode'} = 1;
8647: }
8648: }
8649: unless ($changes{'uniquecode'}) {
8650: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8651: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8652: $changes{'uniquecode'} = 1;
8653: }
8654: }
8655: }
8656: } else {
8657: $changes{'uniquecode'} = 1;
8658: }
8659: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8660: $changes{'uniquecode'} = 1;
8661: }
8662: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8663: foreach my $type ('textbooks','templates') {
8664: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8665: my %deletions;
8666: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8667: if (@todelete) {
8668: map { $deletions{$_} = 1; } @todelete;
8669: }
8670: my %imgdeletions;
8671: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8672: if (@todeleteimages) {
8673: map { $imgdeletions{$_} = 1; } @todeleteimages;
8674: }
8675: my $maxnum = $env{'form.'.$type.'_maxnum'};
8676: for (my $i=0; $i<=$maxnum; $i++) {
8677: my $itemid = $env{'form.'.$type.'_id_'.$i};
8678: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8679: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8680: if ($deletions{$key}) {
8681: if ($domconfig{$action}{$type}{$key}{'image'}) {
8682: #FIXME need to obsolete item in RES space
8683: }
8684: next;
8685: } else {
8686: my $newpos = $env{'form.'.$itemid};
8687: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 8688: foreach my $item ('subject','title','publisher','author') {
8689: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8690: ($type eq 'templates'));
1.160.6.46 raeburn 8691: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8692: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8693: $changes{$type}{$key} = 1;
8694: }
8695: }
8696: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 8697: }
1.160.6.46 raeburn 8698: if ($imgdeletions{$key}) {
8699: $changes{$type}{$key} = 1;
8700: #FIXME need to obsolete item in RES space
8701: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8702: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 8703: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
8704: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
8705: } else {
8706: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8707: $cdom,$cnum,$type,$configuserok,
8708: $switchserver,$author_ok);
8709: if ($imgurl) {
8710: $confhash{$type}{$key}{'image'} = $imgurl;
8711: $changes{$type}{$key} = 1;
8712: }
8713: if ($error) {
8714: &Apache::lonnet::logthis($error);
8715: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8716: }
1.160.6.46 raeburn 8717: }
8718: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8719: $confhash{$type}{$key}{'image'} =
8720: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 8721: }
8722: }
8723: }
8724: }
8725: }
8726: }
1.102 raeburn 8727: } else {
1.144 raeburn 8728: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8729: $changes{'notify'}{'approval'} = 1;
8730: }
1.160.6.30 raeburn 8731: if (ref($confhash{'uniquecode'} eq 'HASH')) {
8732: $changes{'uniquecode'} = 1;
8733: }
8734: }
8735: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8736: foreach my $type ('textbooks','templates') {
8737: if ($newbook{$type}) {
8738: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 8739: foreach my $item ('subject','title','publisher','author') {
8740: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8741: ($type eq 'template'));
1.160.6.46 raeburn 8742: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8743: if ($env{'form.'.$type.'_addbook_'.$item}) {
8744: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8745: }
8746: }
8747: if ($type eq 'textbooks') {
8748: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8749: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 8750: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
8751: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
8752: } else {
8753: my ($imageurl,$error) =
8754: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8755: $configuserok,$switchserver,$author_ok);
8756: if ($imageurl) {
8757: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8758: }
8759: if ($error) {
8760: &Apache::lonnet::logthis($error);
8761: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8762: }
1.160.6.46 raeburn 8763: }
8764: }
1.160.6.30 raeburn 8765: }
8766: }
1.160.6.46 raeburn 8767: if (@{$allpos{$type}} > 0) {
8768: my $idx = 0;
8769: foreach my $item (@{$allpos{$type}}) {
8770: if ($item ne '') {
8771: $confhash{$type}{$item}{'order'} = $idx;
8772: if (ref($domconfig{$action}) eq 'HASH') {
8773: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8774: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8775: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8776: $changes{$type}{$item} = 1;
8777: }
1.160.6.30 raeburn 8778: }
8779: }
8780: }
1.160.6.46 raeburn 8781: $idx ++;
1.160.6.30 raeburn 8782: }
8783: }
8784: }
8785: }
1.160.6.39 raeburn 8786: if (ref($validationitemsref) eq 'ARRAY') {
8787: foreach my $item (@{$validationitemsref}) {
8788: if ($item eq 'fields') {
8789: my @changed;
8790: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8791: if (@{$confhash{'validation'}{$item}} > 0) {
8792: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8793: }
1.160.6.65 raeburn 8794: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8795: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8796: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8797: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8798: $domconfig{'requestcourses'}{'validation'}{$item});
8799: } else {
8800: @changed = @{$confhash{'validation'}{$item}};
8801: }
1.160.6.39 raeburn 8802: } else {
8803: @changed = @{$confhash{'validation'}{$item}};
8804: }
8805: } else {
8806: @changed = @{$confhash{'validation'}{$item}};
8807: }
8808: if (@changed) {
8809: if ($confhash{'validation'}{$item}) {
8810: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8811: } else {
8812: $changes{'validation'}{$item} = &mt('None');
8813: }
8814: }
8815: } else {
8816: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8817: if ($item eq 'markup') {
8818: if ($env{'form.requestcourses_validation_'.$item}) {
8819: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8820: }
8821: }
1.160.6.65 raeburn 8822: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8823: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8824: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8825: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8826: }
8827: } else {
8828: if ($confhash{'validation'}{$item} ne '') {
8829: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8830: }
1.160.6.39 raeburn 8831: }
8832: } else {
8833: if ($confhash{'validation'}{$item} ne '') {
8834: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8835: }
8836: }
8837: }
8838: }
8839: }
8840: if ($env{'form.validationdc'}) {
8841: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 8842: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 8843: if (exists($domcoords{$newval})) {
8844: $confhash{'validation'}{'dc'} = $newval;
8845: }
8846: }
8847: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 8848: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8849: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8850: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8851: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8852: if ($confhash{'validation'}{'dc'} eq '') {
8853: $changes{'validation'}{'dc'} = &mt('None');
8854: } else {
8855: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8856: }
1.160.6.39 raeburn 8857: }
1.160.6.65 raeburn 8858: } elsif ($confhash{'validation'}{'dc'} ne '') {
8859: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 8860: }
8861: } elsif ($confhash{'validation'}{'dc'} ne '') {
8862: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8863: }
8864: } elsif ($confhash{'validation'}{'dc'} ne '') {
8865: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8866: }
1.160.6.65 raeburn 8867: } else {
8868: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8869: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8870: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8871: $changes{'validation'}{'dc'} = &mt('None');
8872: }
8873: }
1.160.6.39 raeburn 8874: }
8875: }
1.102 raeburn 8876: }
8877: } else {
1.86 raeburn 8878: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 8879: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8880: }
1.72 raeburn 8881: foreach my $item (@usertools) {
8882: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8883: my $unset;
1.101 raeburn 8884: if ($context eq 'requestcourses') {
1.104 raeburn 8885: $unset = '0';
8886: if ($type eq '_LC_adv') {
8887: $unset = '';
8888: }
1.101 raeburn 8889: if ($confhash{$item}{$type} eq 'autolimit') {
8890: $confhash{$item}{$type} .= '=';
8891: unless ($limithash{$item}{$type} =~ /\D/) {
8892: $confhash{$item}{$type} .= $limithash{$item}{$type};
8893: }
8894: }
1.160.6.5 raeburn 8895: } elsif ($context eq 'requestauthor') {
8896: $unset = '0';
8897: if ($type eq '_LC_adv') {
8898: $unset = '';
8899: }
1.72 raeburn 8900: } else {
1.101 raeburn 8901: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8902: $confhash{$item}{$type} = 1;
8903: } else {
8904: $confhash{$item}{$type} = 0;
8905: }
1.72 raeburn 8906: }
1.86 raeburn 8907: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 8908: if ($action eq 'requestauthor') {
8909: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8910: $changes{$type} = 1;
8911: }
8912: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8913: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8914: $changes{$item}{$type} = 1;
8915: }
8916: } else {
8917: if ($context eq 'requestcourses') {
1.104 raeburn 8918: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8919: $changes{$item}{$type} = 1;
8920: }
8921: } else {
8922: if (!$confhash{$item}{$type}) {
8923: $changes{$item}{$type} = 1;
8924: }
8925: }
8926: }
8927: } else {
8928: if ($context eq 'requestcourses') {
1.104 raeburn 8929: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8930: $changes{$item}{$type} = 1;
8931: }
1.160.6.5 raeburn 8932: } elsif ($context eq 'requestauthor') {
8933: if ($confhash{$type} ne $unset) {
8934: $changes{$type} = 1;
8935: }
1.72 raeburn 8936: } else {
8937: if (!$confhash{$item}{$type}) {
8938: $changes{$item}{$type} = 1;
8939: }
8940: }
8941: }
1.1 raeburn 8942: }
8943: }
1.160.6.5 raeburn 8944: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8945: if (ref($domconfig{'quotas'}) eq 'HASH') {
8946: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8947: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8948: if (exists($confhash{'defaultquota'}{$key})) {
8949: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8950: $changes{'defaultquota'}{$key} = 1;
8951: }
8952: } else {
8953: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8954: }
8955: }
1.86 raeburn 8956: } else {
8957: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8958: if (exists($confhash{'defaultquota'}{$key})) {
8959: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8960: $changes{'defaultquota'}{$key} = 1;
8961: }
8962: } else {
8963: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8964: }
1.1 raeburn 8965: }
8966: }
1.160.6.20 raeburn 8967: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8968: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8969: if (exists($confhash{'authorquota'}{$key})) {
8970: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8971: $changes{'authorquota'}{$key} = 1;
8972: }
8973: } else {
8974: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8975: }
8976: }
8977: }
1.1 raeburn 8978: }
1.86 raeburn 8979: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8980: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8981: if (ref($domconfig{'quotas'}) eq 'HASH') {
8982: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8983: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8984: $changes{'defaultquota'}{$key} = 1;
8985: }
8986: } else {
8987: if (!exists($domconfig{'quotas'}{$key})) {
8988: $changes{'defaultquota'}{$key} = 1;
8989: }
1.72 raeburn 8990: }
8991: } else {
1.86 raeburn 8992: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8993: }
1.1 raeburn 8994: }
8995: }
1.160.6.20 raeburn 8996: if (ref($confhash{'authorquota'}) eq 'HASH') {
8997: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8998: if (ref($domconfig{'quotas'}) eq 'HASH') {
8999: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
9000: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
9001: $changes{'authorquota'}{$key} = 1;
9002: }
9003: } else {
9004: $changes{'authorquota'}{$key} = 1;
9005: }
9006: } else {
9007: $changes{'authorquota'}{$key} = 1;
9008: }
9009: }
9010: }
1.1 raeburn 9011: }
1.72 raeburn 9012:
1.160.6.5 raeburn 9013: if ($context eq 'requestauthor') {
9014: $domdefaults{'requestauthor'} = \%confhash;
9015: } else {
9016: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 9017: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 9018: $domdefaults{$key} = $confhash{$key};
9019: }
1.160.6.5 raeburn 9020: }
1.72 raeburn 9021: }
1.160.6.5 raeburn 9022:
1.1 raeburn 9023: my %quotahash = (
1.86 raeburn 9024: $action => { %confhash }
1.1 raeburn 9025: );
9026: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
9027: $dom);
9028: if ($putresult eq 'ok') {
9029: if (keys(%changes) > 0) {
1.72 raeburn 9030: my $cachetime = 24*60*60;
9031: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 9032: if (ref($lastactref) eq 'HASH') {
9033: $lastactref->{'domdefaults'} = 1;
9034: }
1.1 raeburn 9035: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 9036: unless (($context eq 'requestcourses') ||
9037: ($context eq 'requestauthor')) {
1.86 raeburn 9038: if (ref($changes{'defaultquota'}) eq 'HASH') {
9039: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
9040: foreach my $type (@{$types},'default') {
9041: if (defined($changes{'defaultquota'}{$type})) {
9042: my $typetitle = $usertypes->{$type};
9043: if ($type eq 'default') {
9044: $typetitle = $othertitle;
9045: }
1.160.6.28 raeburn 9046: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 9047: }
9048: }
1.86 raeburn 9049: $resulttext .= '</ul></li>';
1.72 raeburn 9050: }
1.160.6.20 raeburn 9051: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 9052: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 9053: foreach my $type (@{$types},'default') {
9054: if (defined($changes{'authorquota'}{$type})) {
9055: my $typetitle = $usertypes->{$type};
9056: if ($type eq 'default') {
9057: $typetitle = $othertitle;
9058: }
1.160.6.28 raeburn 9059: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 9060: }
9061: }
9062: $resulttext .= '</ul></li>';
9063: }
1.72 raeburn 9064: }
1.80 raeburn 9065: my %newenv;
1.72 raeburn 9066: foreach my $item (@usertools) {
1.160.6.5 raeburn 9067: my (%haschgs,%inconf);
9068: if ($context eq 'requestauthor') {
9069: %haschgs = %changes;
9070: %inconf = %confhash;
9071: } else {
9072: if (ref($changes{$item}) eq 'HASH') {
9073: %haschgs = %{$changes{$item}};
9074: }
9075: if (ref($confhash{$item}) eq 'HASH') {
9076: %inconf = %{$confhash{$item}};
9077: }
9078: }
9079: if (keys(%haschgs) > 0) {
1.80 raeburn 9080: my $newacc =
9081: &Apache::lonnet::usertools_access($env{'user.name'},
9082: $env{'user.domain'},
1.86 raeburn 9083: $item,'reload',$context);
1.160.6.5 raeburn 9084: if (($context eq 'requestcourses') ||
9085: ($context eq 'requestauthor')) {
1.108 raeburn 9086: if ($env{'environment.canrequest.'.$item} ne $newacc) {
9087: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 9088: }
9089: } else {
9090: if ($env{'environment.availabletools.'.$item} ne $newacc) {
9091: $newenv{'environment.availabletools.'.$item} = $newacc;
9092: }
1.80 raeburn 9093: }
1.160.6.5 raeburn 9094: unless ($context eq 'requestauthor') {
9095: $resulttext .= '<li>'.$titles{$item}.'<ul>';
9096: }
1.72 raeburn 9097: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 9098: if ($haschgs{$type}) {
1.72 raeburn 9099: my $typetitle = $usertypes->{$type};
9100: if ($type eq 'default') {
9101: $typetitle = $othertitle;
9102: } elsif ($type eq '_LC_adv') {
9103: $typetitle = 'LON-CAPA Advanced Users';
9104: }
1.160.6.5 raeburn 9105: if ($inconf{$type}) {
1.101 raeburn 9106: if ($context eq 'requestcourses') {
9107: my $cond;
1.160.6.5 raeburn 9108: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 9109: if ($1 eq '') {
9110: $cond = &mt('(Automatic processing of any request).');
9111: } else {
9112: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
9113: }
9114: } else {
1.160.6.5 raeburn 9115: $cond = $conditions{$inconf{$type}};
1.101 raeburn 9116: }
9117: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 9118: } elsif ($context eq 'requestauthor') {
9119: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
9120: $titles{$inconf{$type}},$typetitle);
9121:
1.101 raeburn 9122: } else {
9123: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
9124: }
1.72 raeburn 9125: } else {
1.104 raeburn 9126: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 9127: if ($inconf{$type} eq '0') {
1.104 raeburn 9128: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9129: } else {
9130: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
9131: }
9132: } else {
9133: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
9134: }
1.72 raeburn 9135: }
9136: }
1.26 raeburn 9137: }
1.160.6.5 raeburn 9138: unless ($context eq 'requestauthor') {
9139: $resulttext .= '</ul></li>';
9140: }
1.26 raeburn 9141: }
1.1 raeburn 9142: }
1.160.6.5 raeburn 9143: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 9144: if (ref($changes{'notify'}) eq 'HASH') {
9145: if ($changes{'notify'}{'approval'}) {
9146: if (ref($confhash{'notify'}) eq 'HASH') {
9147: if ($confhash{'notify'}{'approval'}) {
9148: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
9149: } else {
1.160.6.5 raeburn 9150: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 9151: }
9152: }
9153: }
9154: }
9155: }
1.160.6.30 raeburn 9156: if ($action eq 'requestcourses') {
9157: my @offon = ('off','on');
9158: if ($changes{'uniquecode'}) {
9159: if (ref($confhash{'uniquecode'}) eq 'HASH') {
9160: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
9161: $resulttext .= '<li>'.
9162: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
9163: '</li>';
9164: } else {
9165: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
9166: '</li>';
9167: }
9168: }
1.160.6.46 raeburn 9169: foreach my $type ('textbooks','templates') {
9170: if (ref($changes{$type}) eq 'HASH') {
9171: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
9172: foreach my $key (sort(keys(%{$changes{$type}}))) {
9173: my %coursehash = &Apache::lonnet::coursedescription($key);
9174: my $coursetitle = $coursehash{'description'};
9175: my $position = $confhash{$type}{$key}{'order'} + 1;
9176: $resulttext .= '<li>';
1.160.6.47 raeburn 9177: foreach my $item ('subject','title','publisher','author') {
9178: next if ((($item eq 'author') || ($item eq 'publisher')) &&
9179: ($type eq 'templates'));
1.160.6.46 raeburn 9180: my $name = $item.':';
9181: $name =~ s/^(\w)/\U$1/;
9182: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9183: }
9184: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9185: if ($type eq 'textbooks') {
9186: if ($confhash{$type}{$key}{'image'}) {
9187: $resulttext .= ' '.&mt('Image: [_1]',
9188: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9189: ' alt="Textbook cover" />').'<br />';
9190: }
9191: }
9192: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 9193: }
1.160.6.46 raeburn 9194: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 9195: }
9196: }
1.160.6.39 raeburn 9197: if (ref($changes{'validation'}) eq 'HASH') {
9198: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9199: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9200: foreach my $item (@{$validationitemsref}) {
9201: if (exists($changes{'validation'}{$item})) {
9202: if ($item eq 'markup') {
9203: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9204: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9205: } else {
9206: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9207: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9208: }
9209: }
9210: }
9211: if (exists($changes{'validation'}{'dc'})) {
9212: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9213: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9214: }
9215: }
9216: }
1.160.6.30 raeburn 9217: }
1.1 raeburn 9218: $resulttext .= '</ul>';
1.80 raeburn 9219: if (keys(%newenv)) {
9220: &Apache::lonnet::appenv(\%newenv);
9221: }
1.1 raeburn 9222: } else {
1.86 raeburn 9223: if ($context eq 'requestcourses') {
9224: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 9225: } elsif ($context eq 'requestauthor') {
9226: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9227: } else {
1.90 weissno 9228: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9229: }
1.1 raeburn 9230: }
9231: } else {
1.11 albertel 9232: $resulttext = '<span class="LC_error">'.
9233: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9234: }
1.160.6.30 raeburn 9235: if ($errors) {
9236: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9237: '<ul>'.$errors.'</ul></p>';
9238: }
1.3 raeburn 9239: return $resulttext;
1.1 raeburn 9240: }
9241:
1.160.6.30 raeburn 9242: sub process_textbook_image {
1.160.6.46 raeburn 9243: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 9244: my $filename = $env{'form.'.$caller.'.filename'};
9245: my ($error,$url);
9246: my ($width,$height) = (50,50);
9247: if ($configuserok eq 'ok') {
9248: if ($switchserver) {
9249: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9250: $switchserver);
9251: } elsif ($author_ok eq 'ok') {
9252: my ($result,$imageurl) =
9253: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 9254: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 9255: if ($result eq 'ok') {
9256: $url = $imageurl;
9257: } else {
9258: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9259: }
9260: } else {
9261: $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);
9262: }
9263: } else {
9264: $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);
9265: }
9266: return ($url,$error);
9267: }
9268:
1.3 raeburn 9269: sub modify_autoenroll {
1.160.6.24 raeburn 9270: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9271: my ($resulttext,%changes);
9272: my %currautoenroll;
9273: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9274: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9275: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9276: }
9277: }
9278: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9279: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9280: sender => 'Sender for notification messages',
1.160.6.68 raeburn 9281: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9282: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9283: my @offon = ('off','on');
1.17 raeburn 9284: my $sender_uname = $env{'form.sender_uname'};
9285: my $sender_domain = $env{'form.sender_domain'};
9286: if ($sender_domain eq '') {
9287: $sender_uname = '';
9288: } elsif ($sender_uname eq '') {
9289: $sender_domain = '';
9290: }
1.129 raeburn 9291: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 9292: my $failsafe = $env{'form.autoenroll_failsafe'};
9293: $failsafe =~ s{^\s+|\s+$}{}g;
9294: if ($failsafe =~ /\D/) {
9295: undef($failsafe);
9296: }
1.1 raeburn 9297: my %autoenrollhash = (
1.129 raeburn 9298: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9299: 'sender_uname' => $sender_uname,
9300: 'sender_domain' => $sender_domain,
9301: 'co-owners' => $coowners,
1.160.6.68 raeburn 9302: 'autofailsafe' => $failsafe,
1.1 raeburn 9303: }
9304: );
1.4 raeburn 9305: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9306: $dom);
1.1 raeburn 9307: if ($putresult eq 'ok') {
9308: if (exists($currautoenroll{'run'})) {
9309: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9310: $changes{'run'} = 1;
9311: }
9312: } elsif ($autorun) {
9313: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9314: $changes{'run'} = 1;
1.1 raeburn 9315: }
9316: }
1.17 raeburn 9317: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9318: $changes{'sender'} = 1;
9319: }
1.17 raeburn 9320: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9321: $changes{'sender'} = 1;
9322: }
1.129 raeburn 9323: if ($currautoenroll{'co-owners'} ne '') {
9324: if ($currautoenroll{'co-owners'} ne $coowners) {
9325: $changes{'coowners'} = 1;
9326: }
9327: } elsif ($coowners) {
9328: $changes{'coowners'} = 1;
1.160.6.68 raeburn 9329: }
9330: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9331: $changes{'autofailsafe'} = 1;
9332: }
1.1 raeburn 9333: if (keys(%changes) > 0) {
9334: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9335: if ($changes{'run'}) {
1.1 raeburn 9336: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9337: }
9338: if ($changes{'sender'}) {
1.17 raeburn 9339: if ($sender_uname eq '' || $sender_domain eq '') {
9340: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9341: } else {
9342: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9343: }
1.1 raeburn 9344: }
1.129 raeburn 9345: if ($changes{'coowners'}) {
9346: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9347: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9348: if (ref($lastactref) eq 'HASH') {
9349: $lastactref->{'domainconfig'} = 1;
9350: }
1.129 raeburn 9351: }
1.160.6.68 raeburn 9352: if ($changes{'autofailsafe'}) {
9353: if ($failsafe ne '') {
1.160.6.82 raeburn 9354: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 9355: } else {
1.160.6.82 raeburn 9356: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 9357: }
9358: &Apache::lonnet::get_domain_defaults($dom,1);
9359: if (ref($lastactref) eq 'HASH') {
9360: $lastactref->{'domdefaults'} = 1;
9361: }
9362: }
1.1 raeburn 9363: $resulttext .= '</ul>';
9364: } else {
9365: $resulttext = &mt('No changes made to auto-enrollment settings');
9366: }
9367: } else {
1.11 albertel 9368: $resulttext = '<span class="LC_error">'.
9369: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9370: }
1.3 raeburn 9371: return $resulttext;
1.1 raeburn 9372: }
9373:
9374: sub modify_autoupdate {
1.3 raeburn 9375: my ($dom,%domconfig) = @_;
1.1 raeburn 9376: my ($resulttext,%currautoupdate,%fields,%changes);
9377: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9378: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9379: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9380: }
9381: }
9382: my @offon = ('off','on');
9383: my %title = &Apache::lonlocal::texthash (
9384: run => 'Auto-update:',
9385: classlists => 'Updates to user information in classlists?'
9386: );
1.44 raeburn 9387: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9388: my %fieldtitles = &Apache::lonlocal::texthash (
9389: id => 'Student/Employee ID',
1.20 raeburn 9390: permanentemail => 'E-mail address',
1.1 raeburn 9391: lastname => 'Last Name',
9392: firstname => 'First Name',
9393: middlename => 'Middle Name',
1.132 raeburn 9394: generation => 'Generation',
1.1 raeburn 9395: );
1.142 raeburn 9396: $othertitle = &mt('All users');
1.1 raeburn 9397: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9398: $othertitle = &mt('Other users');
1.1 raeburn 9399: }
9400: foreach my $key (keys(%env)) {
9401: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9402: my ($usertype,$item) = ($1,$2);
9403: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9404: if ($usertype eq 'default') {
9405: push(@{$fields{$1}},$2);
9406: } elsif (ref($types) eq 'ARRAY') {
9407: if (grep(/^\Q$usertype\E$/,@{$types})) {
9408: push(@{$fields{$1}},$2);
9409: }
9410: }
9411: }
1.1 raeburn 9412: }
9413: }
1.131 raeburn 9414: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9415: @lockablenames = sort(@lockablenames);
9416: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9417: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9418: if (@changed) {
9419: $changes{'lockablenames'} = 1;
9420: }
9421: } else {
9422: if (@lockablenames) {
9423: $changes{'lockablenames'} = 1;
9424: }
9425: }
1.1 raeburn 9426: my %updatehash = (
9427: autoupdate => { run => $env{'form.autoupdate_run'},
9428: classlists => $env{'form.classlists'},
9429: fields => {%fields},
1.131 raeburn 9430: lockablenames => \@lockablenames,
1.1 raeburn 9431: }
9432: );
9433: foreach my $key (keys(%currautoupdate)) {
9434: if (($key eq 'run') || ($key eq 'classlists')) {
9435: if (exists($updatehash{autoupdate}{$key})) {
9436: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9437: $changes{$key} = 1;
9438: }
9439: }
9440: } elsif ($key eq 'fields') {
9441: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9442: foreach my $item (@{$types},'default') {
1.1 raeburn 9443: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9444: my $change = 0;
9445: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9446: if (!exists($fields{$item})) {
9447: $change = 1;
1.132 raeburn 9448: last;
1.1 raeburn 9449: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9450: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9451: $change = 1;
1.132 raeburn 9452: last;
1.1 raeburn 9453: }
9454: }
9455: }
9456: if ($change) {
9457: push(@{$changes{$key}},$item);
9458: }
1.26 raeburn 9459: }
1.1 raeburn 9460: }
9461: }
1.131 raeburn 9462: } elsif ($key eq 'lockablenames') {
9463: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9464: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9465: if (@changed) {
9466: $changes{'lockablenames'} = 1;
9467: }
9468: } else {
9469: if (@lockablenames) {
9470: $changes{'lockablenames'} = 1;
9471: }
9472: }
9473: }
9474: }
9475: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
9476: if (@lockablenames) {
9477: $changes{'lockablenames'} = 1;
1.1 raeburn 9478: }
9479: }
1.26 raeburn 9480: foreach my $item (@{$types},'default') {
9481: if (defined($fields{$item})) {
9482: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 9483: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
9484: my $change = 0;
9485: if (ref($fields{$item}) eq 'ARRAY') {
9486: foreach my $type (@{$fields{$item}}) {
9487: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9488: $change = 1;
9489: last;
9490: }
9491: }
9492: }
9493: if ($change) {
9494: push(@{$changes{'fields'}},$item);
9495: }
9496: } else {
1.26 raeburn 9497: push(@{$changes{'fields'}},$item);
9498: }
9499: } else {
9500: push(@{$changes{'fields'}},$item);
1.1 raeburn 9501: }
9502: }
9503: }
9504: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9505: $dom);
9506: if ($putresult eq 'ok') {
9507: if (keys(%changes) > 0) {
9508: $resulttext = &mt('Changes made:').'<ul>';
9509: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9510: if ($key eq 'lockablenames') {
9511: $resulttext .= '<li>';
9512: if (@lockablenames) {
9513: $usertypes->{'default'} = $othertitle;
9514: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9515: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9516: } else {
9517: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9518: }
9519: $resulttext .= '</li>';
9520: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9521: foreach my $item (@{$changes{$key}}) {
9522: my @newvalues;
9523: foreach my $type (@{$fields{$item}}) {
9524: push(@newvalues,$fieldtitles{$type});
9525: }
1.3 raeburn 9526: my $newvaluestr;
9527: if (@newvalues > 0) {
9528: $newvaluestr = join(', ',@newvalues);
9529: } else {
9530: $newvaluestr = &mt('none');
1.6 raeburn 9531: }
1.1 raeburn 9532: if ($item eq 'default') {
1.26 raeburn 9533: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9534: } else {
1.26 raeburn 9535: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9536: }
9537: }
9538: } else {
9539: my $newvalue;
9540: if ($key eq 'run') {
9541: $newvalue = $offon[$env{'form.autoupdate_run'}];
9542: } else {
9543: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9544: }
1.1 raeburn 9545: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9546: }
9547: }
9548: $resulttext .= '</ul>';
9549: } else {
1.3 raeburn 9550: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9551: }
9552: } else {
1.11 albertel 9553: $resulttext = '<span class="LC_error">'.
9554: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9555: }
1.3 raeburn 9556: return $resulttext;
1.1 raeburn 9557: }
9558:
1.125 raeburn 9559: sub modify_autocreate {
9560: my ($dom,%domconfig) = @_;
9561: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9562: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9563: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9564: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9565: }
9566: }
9567: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9568: req => 'Auto-creation of validated requests for official courses',
9569: xmldc => 'Identity of course creator of courses from XML files',
9570: );
9571: my @types = ('xml','req');
9572: foreach my $item (@types) {
9573: $newvals{$item} = $env{'form.autocreate_'.$item};
9574: $newvals{$item} =~ s/\D//g;
9575: $newvals{$item} = 0 if ($newvals{$item} eq '');
9576: }
9577: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 9578: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 9579: unless (exists($domcoords{$newvals{'xmldc'}})) {
9580: $newvals{'xmldc'} = '';
9581: }
9582: %autocreatehash = (
9583: autocreate => { xml => $newvals{'xml'},
9584: req => $newvals{'req'},
9585: }
9586: );
9587: if ($newvals{'xmldc'} ne '') {
9588: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9589: }
9590: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9591: $dom);
9592: if ($putresult eq 'ok') {
9593: my @items = @types;
9594: if ($newvals{'xml'}) {
9595: push(@items,'xmldc');
9596: }
9597: foreach my $item (@items) {
9598: if (exists($currautocreate{$item})) {
9599: if ($currautocreate{$item} ne $newvals{$item}) {
9600: $changes{$item} = 1;
9601: }
9602: } elsif ($newvals{$item}) {
9603: $changes{$item} = 1;
9604: }
9605: }
9606: if (keys(%changes) > 0) {
9607: my @offon = ('off','on');
9608: $resulttext = &mt('Changes made:').'<ul>';
9609: foreach my $item (@types) {
9610: if ($changes{$item}) {
9611: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 9612: $resulttext .= '<li>'.
9613: &mt("$title{$item} set to [_1]$newtxt [_2]",
9614: '<b>','</b>').
9615: '</li>';
1.125 raeburn 9616: }
9617: }
9618: if ($changes{'xmldc'}) {
9619: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9620: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 9621: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9622: }
9623: $resulttext .= '</ul>';
9624: } else {
9625: $resulttext = &mt('No changes made to auto-creation settings');
9626: }
9627: } else {
9628: $resulttext = '<span class="LC_error">'.
9629: &mt('An error occurred: [_1]',$putresult).'</span>';
9630: }
9631: return $resulttext;
9632: }
9633:
1.23 raeburn 9634: sub modify_directorysrch {
1.160.6.81 raeburn 9635: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 9636: my ($resulttext,%changes);
9637: my %currdirsrch;
9638: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9639: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9640: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9641: }
9642: }
1.160.6.72 raeburn 9643: my %title = ( available => 'Institutional directory search available',
9644: localonly => 'Other domains can search institution',
9645: lcavailable => 'LON-CAPA directory search available',
9646: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9647: searchby => 'Search types',
9648: searchtypes => 'Search latitude');
9649: my @offon = ('off','on');
1.24 raeburn 9650: my @otherdoms = ('Yes','No');
1.23 raeburn 9651:
1.25 raeburn 9652: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9653: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9654: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9655:
1.44 raeburn 9656: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9657: if (keys(%{$usertypes}) == 0) {
9658: @cansearch = ('default');
9659: } else {
9660: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9661: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9662: if (!grep(/^\Q$type\E$/,@cansearch)) {
9663: push(@{$changes{'cansearch'}},$type);
9664: }
1.23 raeburn 9665: }
1.26 raeburn 9666: foreach my $type (@cansearch) {
9667: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9668: push(@{$changes{'cansearch'}},$type);
9669: }
1.23 raeburn 9670: }
1.26 raeburn 9671: } else {
9672: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9673: }
9674: }
9675:
9676: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9677: foreach my $by (@{$currdirsrch{'searchby'}}) {
9678: if (!grep(/^\Q$by\E$/,@searchby)) {
9679: push(@{$changes{'searchby'}},$by);
9680: }
9681: }
9682: foreach my $by (@searchby) {
9683: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9684: push(@{$changes{'searchby'}},$by);
9685: }
9686: }
9687: } else {
9688: push(@{$changes{'searchby'}},@searchby);
9689: }
1.25 raeburn 9690:
9691: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9692: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9693: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9694: push(@{$changes{'searchtypes'}},$type);
9695: }
9696: }
9697: foreach my $type (@searchtypes) {
9698: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9699: push(@{$changes{'searchtypes'}},$type);
9700: }
9701: }
9702: } else {
9703: if (exists($currdirsrch{'searchtypes'})) {
9704: foreach my $type (@searchtypes) {
9705: if ($type ne $currdirsrch{'searchtypes'}) {
9706: push(@{$changes{'searchtypes'}},$type);
9707: }
9708: }
9709: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9710: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9711: }
9712: } else {
9713: push(@{$changes{'searchtypes'}},@searchtypes);
9714: }
9715: }
9716:
1.23 raeburn 9717: my %dirsrch_hash = (
9718: directorysrch => { available => $env{'form.dirsrch_available'},
9719: cansearch => \@cansearch,
1.160.6.72 raeburn 9720: localonly => $env{'form.dirsrch_instlocalonly'},
9721: lclocalonly => $env{'form.dirsrch_domlocalonly'},
9722: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9723: searchby => \@searchby,
1.25 raeburn 9724: searchtypes => \@searchtypes,
1.23 raeburn 9725: }
9726: );
9727: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9728: $dom);
9729: if ($putresult eq 'ok') {
9730: if (exists($currdirsrch{'available'})) {
9731: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9732: $changes{'available'} = 1;
9733: }
9734: } else {
9735: if ($env{'form.dirsrch_available'} eq '1') {
9736: $changes{'available'} = 1;
9737: }
9738: }
1.160.6.72 raeburn 9739: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 9740: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
9741: $changes{'lcavailable'} = 1;
9742: }
1.24 raeburn 9743: } else {
1.160.6.72 raeburn 9744: if ($env{'form.dirsrch_lcavailable'} eq '1') {
9745: $changes{'lcavailable'} = 1;
9746: }
9747: }
9748: if (exists($currdirsrch{'localonly'})) {
9749: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9750: $changes{'localonly'} = 1;
9751: }
1.160.6.72 raeburn 9752: } else {
9753: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
9754: $changes{'localonly'} = 1;
9755: }
9756: }
9757: if (exists($currdirsrch{'lclocalonly'})) {
9758: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
9759: $changes{'lclocalonly'} = 1;
9760: }
9761: } else {
9762: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
9763: $changes{'lclocalonly'} = 1;
9764: }
1.24 raeburn 9765: }
1.23 raeburn 9766: if (keys(%changes) > 0) {
9767: $resulttext = &mt('Changes made:').'<ul>';
9768: if ($changes{'available'}) {
9769: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9770: }
1.160.6.72 raeburn 9771: if ($changes{'lcavailable'}) {
9772: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
9773: }
1.24 raeburn 9774: if ($changes{'localonly'}) {
1.160.6.72 raeburn 9775: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
9776: }
9777: if ($changes{'lclocalonly'}) {
9778: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 9779: }
1.23 raeburn 9780: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9781: my $chgtext;
1.26 raeburn 9782: if (ref($usertypes) eq 'HASH') {
9783: if (keys(%{$usertypes}) > 0) {
9784: foreach my $type (@{$types}) {
9785: if (grep(/^\Q$type\E$/,@cansearch)) {
9786: $chgtext .= $usertypes->{$type}.'; ';
9787: }
9788: }
9789: if (grep(/^default$/,@cansearch)) {
9790: $chgtext .= $othertitle;
9791: } else {
9792: $chgtext =~ s/\; $//;
9793: }
1.160.6.13 raeburn 9794: $resulttext .=
9795: '<li>'.
9796: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9797: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9798: '</li>';
1.23 raeburn 9799: }
9800: }
9801: }
9802: if (ref($changes{'searchby'}) eq 'ARRAY') {
9803: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9804: my $chgtext;
9805: foreach my $type (@{$titleorder}) {
9806: if (grep(/^\Q$type\E$/,@searchby)) {
9807: if (defined($searchtitles->{$type})) {
9808: $chgtext .= $searchtitles->{$type}.'; ';
9809: }
9810: }
9811: }
9812: $chgtext =~ s/\; $//;
9813: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9814: }
1.25 raeburn 9815: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9816: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9817: my $chgtext;
9818: foreach my $type (@{$srchtypeorder}) {
9819: if (grep(/^\Q$type\E$/,@searchtypes)) {
9820: if (defined($srchtypes_desc->{$type})) {
9821: $chgtext .= $srchtypes_desc->{$type}.'; ';
9822: }
9823: }
9824: }
9825: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 9826: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9827: }
9828: $resulttext .= '</ul>';
1.160.6.81 raeburn 9829: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
9830: if (ref($lastactref) eq 'HASH') {
9831: $lastactref->{'directorysrch'} = 1;
9832: }
1.23 raeburn 9833: } else {
1.160.6.72 raeburn 9834: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9835: }
9836: } else {
9837: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9838: &mt('An error occurred: [_1]',$putresult).'</span>';
9839: }
9840: return $resulttext;
9841: }
9842:
1.28 raeburn 9843: sub modify_contacts {
1.160.6.24 raeburn 9844: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9845: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9846: if (ref($domconfig{'contacts'}) eq 'HASH') {
9847: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9848: $currsetting{$key} = $domconfig{'contacts'}{$key};
9849: }
9850: }
1.160.6.78 raeburn 9851: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 9852: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 9853: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 9854: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.23 raeburn 9855: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 9856: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 9857: foreach my $type (@mailings) {
9858: @{$newsetting{$type}} =
9859: &Apache::loncommon::get_env_multiple('form.'.$type);
9860: foreach my $item (@contacts) {
9861: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9862: $contacts_hash{contacts}{$type}{$item} = 1;
9863: } else {
9864: $contacts_hash{contacts}{$type}{$item} = 0;
9865: }
1.160.6.78 raeburn 9866: }
1.28 raeburn 9867: $others{$type} = $env{'form.'.$type.'_others'};
9868: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 9869: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9870: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9871: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 9872: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
9873: $includestr{$type} = $env{'form.'.$type.'_includestr'};
9874: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
9875: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
9876: }
1.134 raeburn 9877: }
1.28 raeburn 9878: }
9879: foreach my $item (@contacts) {
9880: $to{$item} = $env{'form.'.$item};
9881: $contacts_hash{'contacts'}{$item} = $to{$item};
9882: }
1.160.6.23 raeburn 9883: foreach my $item (@toggles) {
9884: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9885: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9886: }
9887: }
1.160.6.78 raeburn 9888: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
9889: foreach my $field (@{$fields}) {
9890: if (ref($possoptions->{$field}) eq 'ARRAY') {
9891: my $value = $env{'form.helpform_'.$field};
9892: $value =~ s/^\s+|\s+$//g;
9893: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
9894: $contacts_hash{contacts}{'helpform'}{$field} = $value;
9895: if ($field eq 'screenshot') {
9896: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
9897: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
9898: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
9899: }
9900: }
9901: }
9902: }
9903: }
9904: }
1.28 raeburn 9905: if (keys(%currsetting) > 0) {
9906: foreach my $item (@contacts) {
9907: if ($to{$item} ne $currsetting{$item}) {
9908: $changes{$item} = 1;
9909: }
9910: }
9911: foreach my $type (@mailings) {
9912: foreach my $item (@contacts) {
9913: if (ref($currsetting{$type}) eq 'HASH') {
9914: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9915: push(@{$changes{$type}},$item);
9916: }
9917: } else {
9918: push(@{$changes{$type}},@{$newsetting{$type}});
9919: }
9920: }
9921: if ($others{$type} ne $currsetting{$type}{'others'}) {
9922: push(@{$changes{$type}},'others');
9923: }
1.160.6.78 raeburn 9924: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9925: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9926: push(@{$changes{$type}},'bcc');
9927: }
1.160.6.78 raeburn 9928: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
9929: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
9930: push(@{$changes{$type}},'include');
9931: }
9932: }
9933: }
9934: if (ref($fields) eq 'ARRAY') {
9935: if (ref($currsetting{'helpform'}) eq 'HASH') {
9936: foreach my $field (@{$fields}) {
9937: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
9938: push(@{$changes{'helpform'}},$field);
9939: }
9940: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9941: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
9942: push(@{$changes{'helpform'}},'maxsize');
9943: }
9944: }
9945: }
9946: } else {
9947: foreach my $field (@{$fields}) {
9948: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9949: push(@{$changes{'helpform'}},$field);
9950: }
9951: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9952: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9953: push(@{$changes{'helpform'}},'maxsize');
9954: }
9955: }
9956: }
1.134 raeburn 9957: }
1.28 raeburn 9958: }
9959: } else {
9960: my %default;
9961: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9962: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9963: $default{'errormail'} = 'adminemail';
9964: $default{'packagesmail'} = 'adminemail';
9965: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 9966: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 9967: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9968: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 9969: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 9970: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 9971: foreach my $item (@contacts) {
9972: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 9973: $changes{$item} = 1;
1.160.6.23 raeburn 9974: }
1.28 raeburn 9975: }
9976: foreach my $type (@mailings) {
9977: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9978: push(@{$changes{$type}},@{$newsetting{$type}});
9979: }
9980: if ($others{$type} ne '') {
9981: push(@{$changes{$type}},'others');
1.134 raeburn 9982: }
1.160.6.78 raeburn 9983: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9984: if ($bcc{$type} ne '') {
9985: push(@{$changes{$type}},'bcc');
9986: }
1.160.6.78 raeburn 9987: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
9988: push(@{$changes{$type}},'include');
9989: }
9990: }
9991: }
9992: if (ref($fields) eq 'ARRAY') {
9993: foreach my $field (@{$fields}) {
9994: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9995: push(@{$changes{'helpform'}},$field);
9996: }
9997: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9998: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9999: push(@{$changes{'helpform'}},'maxsize');
10000: }
10001: }
1.134 raeburn 10002: }
1.28 raeburn 10003: }
10004: }
1.160.6.23 raeburn 10005: foreach my $item (@toggles) {
10006: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
10007: $changes{$item} = 1;
10008: } elsif ((!$env{'form.'.$item}) &&
10009: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
10010: $changes{$item} = 1;
10011: }
10012: }
1.28 raeburn 10013: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
10014: $dom);
10015: if ($putresult eq 'ok') {
10016: if (keys(%changes) > 0) {
1.160.6.24 raeburn 10017: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10018: if (ref($lastactref) eq 'HASH') {
10019: $lastactref->{'domainconfig'} = 1;
10020: }
1.28 raeburn 10021: my ($titles,$short_titles) = &contact_titles();
10022: $resulttext = &mt('Changes made:').'<ul>';
10023: foreach my $item (@contacts) {
10024: if ($changes{$item}) {
10025: $resulttext .= '<li>'.$titles->{$item}.
10026: &mt(' set to: ').
10027: '<span class="LC_cusr_emph">'.
10028: $to{$item}.'</span></li>';
10029: }
10030: }
10031: foreach my $type (@mailings) {
10032: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 10033: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
10034: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
10035: } else {
10036: $resulttext .= '<li>'.$titles->{$type}.': ';
10037: }
1.28 raeburn 10038: my @text;
10039: foreach my $item (@{$newsetting{$type}}) {
10040: push(@text,$short_titles->{$item});
10041: }
10042: if ($others{$type} ne '') {
10043: push(@text,$others{$type});
10044: }
1.160.6.78 raeburn 10045: if (@text) {
10046: $resulttext .= '<span class="LC_cusr_emph">'.
10047: join(', ',@text).'</span>';
10048: }
10049: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 10050: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 10051: my $bcctext;
10052: if (@text) {
10053: $bcctext = ' '.&mt('with Bcc to');
10054: } else {
10055: $bcctext = '(Bcc)';
10056: }
10057: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
10058: } elsif (!@text) {
10059: $resulttext .= &mt('No one');
1.134 raeburn 10060: }
1.160.6.78 raeburn 10061: if ($includestr{$type} ne '') {
10062: if ($includeloc{$type} eq 'b') {
10063: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
10064: } elsif ($includeloc{$type} eq 's') {
10065: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
10066: }
10067: }
10068: } elsif (!@text) {
10069: $resulttext .= &mt('No recipients');
1.134 raeburn 10070: }
10071: $resulttext .= '</li>';
1.28 raeburn 10072: }
10073: }
1.160.6.23 raeburn 10074: my @offon = ('off','on');
10075: if ($changes{'reporterrors'}) {
10076: $resulttext .= '<li>'.
10077: &mt('E-mail error reports to [_1] set to "'.
10078: $offon[$env{'form.reporterrors'}].'".',
10079: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10080: &mt('LON-CAPA core group - MSU'),600,500)).
10081: '</li>';
10082: }
10083: if ($changes{'reportupdates'}) {
10084: $resulttext .= '<li>'.
10085: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
10086: $offon[$env{'form.reportupdates'}].'".',
10087: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
10088: &mt('LON-CAPA core group - MSU'),600,500)).
10089: '</li>';
10090: }
1.160.6.78 raeburn 10091: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
10092: my (@optional,@required,@unused,$maxsizechg);
10093: foreach my $field (@{$changes{'helpform'}}) {
10094: if ($field eq 'maxsize') {
10095: $maxsizechg = 1;
10096: next;
10097: }
10098: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
10099: push(@optional,$field);
10100: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
10101: push(@unused,$field);
10102: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
10103: push(@required,$field);
10104: }
10105: }
10106: if (@optional) {
10107: $resulttext .= '<li>'.
10108: &mt('Help form fields changed to "Optional": [_1].',
10109: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
10110: '</li>';
10111: }
10112: if (@required) {
10113: $resulttext .= '<li>'.
10114: &mt('Help form fields changed to "Required": [_1].',
10115: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
10116: '</li>';
10117: }
10118: if (@unused) {
10119: $resulttext .= '<li>'.
10120: &mt('Help form fields changed to "Not shown": [_1].',
10121: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
10122: '</li>';
10123: }
10124: if ($maxsizechg) {
10125: $resulttext .= '<li>'.
10126: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
10127: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
10128: '</li>';
10129:
10130: }
10131: }
1.28 raeburn 10132: $resulttext .= '</ul>';
10133: } else {
1.160.6.78 raeburn 10134: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 10135: }
10136: } else {
10137: $resulttext = '<span class="LC_error">'.
10138: &mt('An error occurred: [_1].',$putresult).'</span>';
10139: }
10140: return $resulttext;
10141: }
10142:
10143: sub modify_usercreation {
1.27 raeburn 10144: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 10145: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 10146: my $warningmsg;
1.27 raeburn 10147: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10148: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 10149: if ($key eq 'cancreate') {
10150: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10151: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 10152: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 10153: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 10154: } else {
10155: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 10156: }
1.50 raeburn 10157: }
1.43 raeburn 10158: }
1.160.6.34 raeburn 10159: } elsif ($key eq 'email_rule') {
10160: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10161: } else {
10162: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 10163: }
10164: }
1.34 raeburn 10165: }
1.160.6.34 raeburn 10166: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
10167: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
10168: my @contexts = ('author','course','requestcrs');
10169: foreach my $item(@contexts) {
10170: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 10171: }
1.34 raeburn 10172: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10173: foreach my $item (@contexts) {
1.160.6.34 raeburn 10174: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
10175: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 10176: }
1.27 raeburn 10177: }
1.34 raeburn 10178: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
10179: foreach my $item (@contexts) {
1.43 raeburn 10180: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10181: if ($cancreate{$item} ne 'any') {
10182: push(@{$changes{'cancreate'}},$item);
10183: }
10184: } else {
10185: if ($cancreate{$item} ne 'none') {
10186: push(@{$changes{'cancreate'}},$item);
10187: }
1.27 raeburn 10188: }
10189: }
10190: } else {
1.43 raeburn 10191: foreach my $item (@contexts) {
1.34 raeburn 10192: push(@{$changes{'cancreate'}},$item);
10193: }
1.27 raeburn 10194: }
1.34 raeburn 10195:
1.27 raeburn 10196: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10197: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10198: if (!grep(/^\Q$type\E$/,@username_rule)) {
10199: push(@{$changes{'username_rule'}},$type);
10200: }
10201: }
10202: foreach my $type (@username_rule) {
10203: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10204: push(@{$changes{'username_rule'}},$type);
10205: }
10206: }
10207: } else {
10208: push(@{$changes{'username_rule'}},@username_rule);
10209: }
10210:
1.32 raeburn 10211: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10212: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10213: if (!grep(/^\Q$type\E$/,@id_rule)) {
10214: push(@{$changes{'id_rule'}},$type);
10215: }
10216: }
10217: foreach my $type (@id_rule) {
10218: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10219: push(@{$changes{'id_rule'}},$type);
10220: }
10221: }
10222: } else {
10223: push(@{$changes{'id_rule'}},@id_rule);
10224: }
10225:
1.43 raeburn 10226: my @authen_contexts = ('author','course','domain');
1.28 raeburn 10227: my @authtypes = ('int','krb4','krb5','loc');
10228: my %authhash;
1.43 raeburn 10229: foreach my $item (@authen_contexts) {
1.28 raeburn 10230: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
10231: foreach my $auth (@authtypes) {
10232: if (grep(/^\Q$auth\E$/,@authallowed)) {
10233: $authhash{$item}{$auth} = 1;
10234: } else {
10235: $authhash{$item}{$auth} = 0;
10236: }
10237: }
10238: }
10239: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 10240: foreach my $item (@authen_contexts) {
1.28 raeburn 10241: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10242: foreach my $auth (@authtypes) {
10243: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10244: push(@{$changes{'authtypes'}},$item);
10245: last;
10246: }
10247: }
10248: }
10249: }
10250: } else {
1.43 raeburn 10251: foreach my $item (@authen_contexts) {
1.28 raeburn 10252: push(@{$changes{'authtypes'}},$item);
10253: }
10254: }
10255:
1.160.6.34 raeburn 10256: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10257: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10258: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10259: $save_usercreate{'id_rule'} = \@id_rule;
10260: $save_usercreate{'username_rule'} = \@username_rule,
10261: $save_usercreate{'authtypes'} = \%authhash;
10262:
1.27 raeburn 10263: my %usercreation_hash = (
1.160.6.34 raeburn 10264: usercreation => \%save_usercreate,
10265: );
1.27 raeburn 10266:
10267: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10268: $dom);
1.50 raeburn 10269:
1.160.6.34 raeburn 10270: if ($putresult eq 'ok') {
10271: if (keys(%changes) > 0) {
10272: $resulttext = &mt('Changes made:').'<ul>';
10273: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10274: my %lt = &usercreation_types();
10275: foreach my $type (@{$changes{'cancreate'}}) {
10276: my $chgtext = $lt{$type}.', ';
10277: if ($cancreate{$type} eq 'none') {
10278: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10279: } elsif ($cancreate{$type} eq 'any') {
10280: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10281: } elsif ($cancreate{$type} eq 'official') {
10282: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10283: } elsif ($cancreate{$type} eq 'unofficial') {
10284: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10285: }
10286: $resulttext .= '<li>'.$chgtext.'</li>';
10287: }
10288: }
10289: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10290: my ($rules,$ruleorder) =
10291: &Apache::lonnet::inst_userrules($dom,'username');
10292: my $chgtext = '<ul>';
10293: foreach my $type (@username_rule) {
10294: if (ref($rules->{$type}) eq 'HASH') {
10295: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10296: }
10297: }
10298: $chgtext .= '</ul>';
10299: if (@username_rule > 0) {
10300: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10301: } else {
10302: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
10303: }
10304: }
10305: if (ref($changes{'id_rule'}) eq 'ARRAY') {
10306: my ($idrules,$idruleorder) =
10307: &Apache::lonnet::inst_userrules($dom,'id');
10308: my $chgtext = '<ul>';
10309: foreach my $type (@id_rule) {
10310: if (ref($idrules->{$type}) eq 'HASH') {
10311: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
10312: }
10313: }
10314: $chgtext .= '</ul>';
10315: if (@id_rule > 0) {
10316: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10317: } else {
10318: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
10319: }
10320: }
10321: my %authname = &authtype_names();
10322: my %context_title = &context_names();
10323: if (ref($changes{'authtypes'}) eq 'ARRAY') {
10324: my $chgtext = '<ul>';
10325: foreach my $type (@{$changes{'authtypes'}}) {
10326: my @allowed;
10327: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
10328: foreach my $auth (@authtypes) {
10329: if ($authhash{$type}{$auth}) {
10330: push(@allowed,$authname{$auth});
10331: }
10332: }
10333: if (@allowed > 0) {
10334: $chgtext .= join(', ',@allowed).'</li>';
10335: } else {
10336: $chgtext .= &mt('none').'</li>';
10337: }
10338: }
10339: $chgtext .= '</ul>';
10340: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10341: $resulttext .= '</li>';
10342: }
10343: $resulttext .= '</ul>';
10344: } else {
10345: $resulttext = &mt('No changes made to user creation settings');
10346: }
10347: } else {
10348: $resulttext = '<span class="LC_error">'.
10349: &mt('An error occurred: [_1]',$putresult).'</span>';
10350: }
10351: if ($warningmsg ne '') {
10352: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10353: }
10354: return $resulttext;
10355: }
10356:
10357: sub modify_selfcreation {
1.160.6.93 raeburn 10358: my ($dom,$lastactref,%domconfig) = @_;
10359: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
10360: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
10361: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10362: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
10363: if (ref($typesref) eq 'ARRAY') {
10364: @types = @{$typesref};
10365: }
10366: if (ref($usertypesref) eq 'HASH') {
10367: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 10368: }
1.160.6.93 raeburn 10369: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 10370: #
10371: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10372: #
10373: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10374: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10375: if ($key eq 'cancreate') {
10376: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10377: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10378: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 10379: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10380: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
10381: ($item eq 'emailusername') || ($item eq 'shibenv') ||
10382: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
10383: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 10384: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10385: } else {
10386: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10387: }
10388: }
10389: }
10390: } elsif ($key eq 'email_rule') {
10391: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10392: } else {
10393: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10394: }
10395: }
10396: }
10397: #
10398: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10399: #
10400: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10401: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10402: if ($key eq 'selfcreate') {
10403: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10404: } else {
10405: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10406: }
10407: }
10408: }
1.160.6.93 raeburn 10409: #
10410: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
10411: #
10412: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10413: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
10414: if ($key eq 'inststatusguest') {
10415: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
10416: } else {
10417: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
10418: }
10419: }
10420: }
1.160.6.34 raeburn 10421:
10422: my @contexts = ('selfcreate');
10423: @{$cancreate{'selfcreate'}} = ();
10424: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 10425: if (@types) {
10426: @{$cancreate{'statustocreate'}} = ();
10427: }
1.160.6.40 raeburn 10428: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 10429: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 10430: %{$cancreate{'emailverified'}} = ();
10431: %{$cancreate{'emailoptions'}} = ();
10432: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 10433: my %selfcreatetypes = (
10434: sso => 'users authenticated by institutional single sign on',
10435: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 10436: email => 'users verified by e-mail',
1.50 raeburn 10437: );
1.160.6.34 raeburn 10438: #
10439: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10440: # is permitted.
10441: #
1.160.6.40 raeburn 10442:
1.160.6.93 raeburn 10443: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 10444:
1.160.6.93 raeburn 10445: my (@statuses,%email_rule);
1.160.6.35 raeburn 10446: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 10447: if ($item eq 'email') {
1.160.6.40 raeburn 10448: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 10449: if (@types) {
10450: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
10451: foreach my $status (@poss_statuses) {
10452: if (grep(/^\Q$status\E$/,(@types,'default'))) {
10453: push(@statuses,$status);
10454: }
10455: }
10456: $save_inststatus{'inststatusguest'} = \@statuses;
10457: } else {
10458: push(@statuses,'default');
10459: }
10460: if (@statuses) {
10461: my %curr_rule;
10462: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
10463: foreach my $type (@statuses) {
10464: $curr_rule{$type} = $curr_usercreation{'email_rule'};
10465: }
10466: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
10467: foreach my $type (@statuses) {
10468: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
10469: }
10470: }
10471: push(@{$cancreate{'selfcreate'}},'email');
10472: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
10473: my %curremaildom;
10474: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
10475: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
10476: }
10477: foreach my $type (@statuses) {
10478: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
10479: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10480: }
10481: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
10482: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
10483: }
10484: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
10485: #
10486: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
10487: #
10488: my $chosen = $1;
10489: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
10490: my $emaildom;
10491: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
10492: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
10493: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
10494: if (ref($curremaildom{$type}) eq 'HASH') {
10495: if (exists($curremaildom{$type}{$chosen})) {
10496: if ($curremaildom{$type}{$chosen} ne $emaildom) {
10497: push(@{$changes{'cancreate'}},'emaildomain');
10498: }
10499: } elsif ($emaildom ne '') {
10500: push(@{$changes{'cancreate'}},'emaildomain');
10501: }
10502: } elsif ($emaildom ne '') {
10503: push(@{$changes{'cancreate'}},'emaildomain');
10504: }
10505: }
10506: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
10507: } elsif ($chosen eq 'custom') {
10508: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
10509: $email_rule{$type} = [];
10510: if (ref($emailrules) eq 'HASH') {
10511: foreach my $rule (@possemail_rules) {
10512: if (exists($emailrules->{$rule})) {
10513: push(@{$email_rule{$type}},$rule);
10514: }
10515: }
10516: }
10517: if (@{$email_rule{$type}}) {
10518: $cancreate{'emailoptions'}{$type} = 'custom';
10519: if (ref($curr_rule{$type}) eq 'ARRAY') {
10520: if (@{$curr_rule{$type}} > 0) {
10521: foreach my $rule (@{$curr_rule{$type}}) {
10522: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
10523: push(@{$changes{'email_rule'}},$type);
10524: }
10525: }
10526: }
10527: foreach my $type (@{$email_rule{$type}}) {
10528: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
10529: push(@{$changes{'email_rule'}},$type);
10530: }
10531: }
10532: } else {
10533: push(@{$changes{'email_rule'}},$type);
10534: }
10535: }
10536: } else {
10537: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
10538: }
10539: }
10540: }
10541: if (@types) {
10542: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
10543: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
10544: if (@changed) {
10545: push(@{$changes{'inststatus'}},'inststatusguest');
10546: }
10547: } else {
10548: push(@{$changes{'inststatus'}},'inststatusguest');
10549: }
10550: }
10551: } else {
10552: delete($env{'form.cancreate_email'});
10553: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
10554: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
10555: push(@{$changes{'inststatus'}},'inststatusguest');
10556: }
10557: }
10558: }
10559: } else {
10560: $save_inststatus{'inststatusguest'} = [];
10561: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
10562: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
10563: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 10564: }
10565: }
1.160.6.34 raeburn 10566: }
10567: } else {
10568: if ($env{'form.cancreate_'.$item}) {
10569: push(@{$cancreate{'selfcreate'}},$item);
10570: }
10571: }
10572: }
1.160.6.93 raeburn 10573: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 10574: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
10575: #
1.160.6.35 raeburn 10576: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
10577: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.160.6.34 raeburn 10578: #
1.160.6.40 raeburn 10579:
1.160.6.48 raeburn 10580: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 10581: push(@contexts,'emailusername');
1.160.6.93 raeburn 10582: if (@statuses) {
10583: foreach my $type (@statuses) {
1.160.6.35 raeburn 10584: if (ref($infofields) eq 'ARRAY') {
10585: foreach my $field (@{$infofields}) {
10586: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
10587: $cancreate{'emailusername'}{$type}{$field} = $1;
10588: }
10589: }
1.160.6.34 raeburn 10590: }
10591: }
10592: }
10593: #
10594: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 10595: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 10596: #
10597:
10598: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
10599: @approvalnotify = sort(@approvalnotify);
10600: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
10601: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10602: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
10603: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
10604: push(@{$changes{'cancreate'}},'notify');
10605: }
10606: } else {
10607: if ($cancreate{'notify'}{'approval'}) {
10608: push(@{$changes{'cancreate'}},'notify');
10609: }
10610: }
10611: } elsif ($cancreate{'notify'}{'approval'}) {
10612: push(@{$changes{'cancreate'}},'notify');
10613: }
10614:
10615: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
10616: }
10617: #
1.160.6.40 raeburn 10618: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 10619: # institutional log-in.
10620: #
10621: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
10622: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
10623: ($domdefaults{'auth_def'} eq 'localauth'))) {
10624: $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.').' '.
10625: &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.');
10626: }
10627: }
10628: my @fields = ('lastname','firstname','middlename','generation',
10629: 'permanentemail','id');
1.160.6.44 raeburn 10630: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 10631: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10632: #
10633: # Where usernames may created for institutional log-in and/or institutional single sign on:
10634: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
10635: # may self-create accounts
10636: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
10637: # which the user may supply, if institutional data is unavailable.
10638: #
10639: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 10640: if (@types) {
10641: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
10642: push(@contexts,'statustocreate');
10643: foreach my $type (@types) {
1.160.6.34 raeburn 10644: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
10645: foreach my $field (@fields) {
10646: if (grep(/^\Q$field\E$/,@modifiable)) {
10647: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
10648: } else {
10649: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
10650: }
10651: }
10652: }
10653: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 10654: foreach my $type (@types) {
1.160.6.34 raeburn 10655: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
10656: foreach my $field (@fields) {
10657: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
10658: $curr_usermodify{'selfcreate'}{$type}{$field}) {
10659: push(@{$changes{'selfcreate'}},$type);
10660: last;
10661: }
10662: }
10663: }
10664: }
10665: } else {
1.160.6.93 raeburn 10666: foreach my $type (@types) {
1.160.6.34 raeburn 10667: push(@{$changes{'selfcreate'}},$type);
10668: }
10669: }
10670: }
1.160.6.44 raeburn 10671: foreach my $field (@shibfields) {
10672: if ($env{'form.shibenv_'.$field} ne '') {
10673: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10674: }
10675: }
10676: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10677: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10678: foreach my $field (@shibfields) {
10679: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10680: push(@{$changes{'cancreate'}},'shibenv');
10681: }
10682: }
10683: } else {
10684: foreach my $field (@shibfields) {
10685: if ($env{'form.shibenv_'.$field}) {
10686: push(@{$changes{'cancreate'}},'shibenv');
10687: last;
10688: }
10689: }
10690: }
10691: }
1.160.6.34 raeburn 10692: }
10693: foreach my $item (@contexts) {
10694: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10695: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10696: if (ref($cancreate{$item}) eq 'ARRAY') {
10697: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10698: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10699: push(@{$changes{'cancreate'}},$item);
10700: }
10701: }
10702: }
10703: }
10704: if (ref($cancreate{$item}) eq 'ARRAY') {
10705: foreach my $type (@{$cancreate{$item}}) {
10706: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10707: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10708: push(@{$changes{'cancreate'}},$item);
10709: }
10710: }
10711: }
10712: }
10713: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10714: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 10715: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
10716: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
10717: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
10718: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 10719: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10720: push(@{$changes{'cancreate'}},$item);
10721: }
10722: }
10723: }
1.160.6.93 raeburn 10724: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
10725: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 10726: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10727: push(@{$changes{'cancreate'}},$item);
10728: }
1.160.6.34 raeburn 10729: }
10730: }
10731: }
1.160.6.93 raeburn 10732: foreach my $type (keys(%{$cancreate{$item}})) {
10733: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10734: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10735: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
10736: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 10737: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10738: push(@{$changes{'cancreate'}},$item);
10739: }
10740: }
10741: } else {
10742: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10743: push(@{$changes{'cancreate'}},$item);
10744: }
10745: }
10746: }
1.160.6.93 raeburn 10747: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
10748: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 10749: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10750: push(@{$changes{'cancreate'}},$item);
10751: }
1.160.6.34 raeburn 10752: }
10753: }
10754: }
10755: }
10756: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10757: if (ref($cancreate{$item}) eq 'ARRAY') {
10758: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10759: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10760: push(@{$changes{'cancreate'}},$item);
10761: }
10762: }
1.160.6.93 raeburn 10763: }
10764: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
10765: if (ref($cancreate{$item}) eq 'HASH') {
10766: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10767: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 10768: }
10769: }
10770: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 10771: if (ref($cancreate{$item}) eq 'HASH') {
10772: foreach my $type (keys(%{$cancreate{$item}})) {
10773: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10774: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10775: if ($cancreate{$item}{$type}{$field}) {
10776: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10777: push(@{$changes{'cancreate'}},$item);
10778: }
10779: last;
10780: }
10781: }
10782: }
10783: }
1.160.6.34 raeburn 10784: }
10785: }
10786: }
10787: #
10788: # Populate %save_usercreate hash with updates to self-creation configuration.
10789: #
10790: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10791: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 10792: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 10793: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10794: if (ref($cancreate{'notify'}) eq 'HASH') {
10795: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10796: }
1.160.6.40 raeburn 10797: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10798: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10799: }
1.160.6.93 raeburn 10800: if (ref($cancreate{'emailverified'}) eq 'HASH') {
10801: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
10802: }
10803: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
10804: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
10805: }
10806: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
10807: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
10808: }
1.160.6.34 raeburn 10809: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10810: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10811: }
1.160.6.44 raeburn 10812: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10813: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10814: }
1.160.6.34 raeburn 10815: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 10816: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 10817:
10818: my %userconfig_hash = (
10819: usercreation => \%save_usercreate,
10820: usermodification => \%save_usermodify,
1.160.6.93 raeburn 10821: inststatus => \%save_inststatus,
1.160.6.34 raeburn 10822: );
1.160.6.93 raeburn 10823:
1.160.6.34 raeburn 10824: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10825: $dom);
10826: #
1.160.6.93 raeburn 10827: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 10828: #
1.27 raeburn 10829: if ($putresult eq 'ok') {
10830: if (keys(%changes) > 0) {
10831: $resulttext = &mt('Changes made:').'<ul>';
10832: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 10833: my %lt = &selfcreation_types();
1.34 raeburn 10834: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 10835: my $chgtext = '';
1.45 raeburn 10836: if ($type eq 'selfcreate') {
1.50 raeburn 10837: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 10838: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10839: } else {
1.160.6.34 raeburn 10840: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10841: '<ul>';
1.50 raeburn 10842: foreach my $case (@{$cancreate{$type}}) {
10843: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10844: }
10845: $chgtext .= '</ul>';
1.100 raeburn 10846: if (ref($cancreate{$type}) eq 'ARRAY') {
10847: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10848: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10849: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 10850: $chgtext .= '<span class="LC_warning">'.
10851: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
10852: '</span><br />';
1.100 raeburn 10853: }
10854: }
10855: }
1.160.6.93 raeburn 10856: if (grep(/^email$/,@{$cancreate{$type}})) {
10857: if (!@statuses) {
10858: $chgtext .= '<span class="LC_warning">'.
10859: &mt("However, e-mail verification is currently set to 'unavailable' for all user types (including 'other'), so self-creation of accounts is not possible for non-institutional log-in.").
10860: '</span><br />';
10861:
10862: }
10863: }
1.100 raeburn 10864: }
1.43 raeburn 10865: }
1.160.6.44 raeburn 10866: } elsif ($type eq 'shibenv') {
10867: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 10868: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 10869: } else {
10870: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10871: '<ul>';
10872: foreach my $field (@shibfields) {
10873: next if ($cancreate{$type}{$field} eq '');
10874: if ($field eq 'inststatus') {
10875: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10876: } else {
10877: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10878: }
10879: }
10880: $chgtext .= '</ul>';
1.160.6.93 raeburn 10881: }
1.93 raeburn 10882: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10883: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10884: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10885: if (@{$cancreate{'selfcreate'}} > 0) {
10886: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10887: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10888: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10889: $chgtext .= '<br />'.
10890: '<span class="LC_warning">'.
10891: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10892: '</span>';
10893: }
1.160.6.93 raeburn 10894: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 10895: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10896: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10897: } else {
10898: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10899: }
10900: $chgtext .= '<ul>';
10901: foreach my $case (@{$cancreate{$type}}) {
10902: if ($case eq 'default') {
10903: $chgtext .= '<li>'.$othertitle.'</li>';
10904: } else {
1.160.6.93 raeburn 10905: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 10906: }
10907: }
1.100 raeburn 10908: $chgtext .= '</ul>';
10909: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 10910: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 10911: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10912: '</span>';
1.100 raeburn 10913: }
10914: }
10915: } else {
10916: if (@{$cancreate{$type}} == 0) {
10917: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10918: } else {
10919: $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 10920: }
10921: }
1.160.6.93 raeburn 10922: $chgtext .= '<br />';
1.93 raeburn 10923: }
1.160.6.40 raeburn 10924: } elsif ($type eq 'selfcreateprocessing') {
10925: my %choices = &Apache::lonlocal::texthash (
10926: automatic => 'Automatic approval',
10927: approval => 'Queued for approval',
10928: );
1.160.6.93 raeburn 10929: if (@types) {
10930: if (@statuses) {
10931: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
10932: '<ul>';
10933: foreach my $status (@statuses) {
10934: if ($status eq 'default') {
10935: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
10936: } else {
10937: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
10938: }
10939: }
10940: $chgtext .= '</ul>';
10941: }
10942: } else {
10943: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
10944: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10945: }
10946: } elsif ($type eq 'emailverified') {
10947: my %options = &Apache::lonlocal::texthash (
10948: all => 'Same as e-mail',
10949: first => 'Omit @domain',
10950: free => 'Free to choose',
10951: );
10952: if (@types) {
10953: if (@statuses) {
10954: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
10955: '<ul>';
10956: foreach my $status (@statuses) {
10957: if ($status eq 'default') {
10958: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
10959: } else {
10960: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
10961: }
10962: }
10963: $chgtext .= '</ul>';
10964: }
1.160.6.40 raeburn 10965: } else {
1.160.6.93 raeburn 10966: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
10967: $options{$cancreate{'emailverified'}{'default'}});
10968: }
10969: } elsif ($type eq 'emailoptions') {
10970: my %options = &Apache::lonlocal::texthash (
10971: any => 'Any e-mail',
10972: inst => 'Institutional only',
10973: noninst => 'Non-institutional only',
10974: custom => 'Custom restrictions',
10975: );
10976: if (@types) {
10977: if (@statuses) {
10978: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
10979: '<ul>';
10980: foreach my $status (@statuses) {
10981: if ($type eq 'default') {
10982: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
10983: } else {
10984: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
10985: }
10986: }
10987: $chgtext .= '</ul>';
10988: }
10989: } else {
10990: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
10991: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
10992: } else {
10993: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
10994: $options{$cancreate{'emailoptions'}{'default'}});
10995: }
10996: }
10997: } elsif ($type eq 'emaildomain') {
10998: my $output;
10999: if (@statuses) {
11000: foreach my $type (@statuses) {
11001: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
11002: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
11003: if ($type eq 'default') {
11004: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
11005: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
11006: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
11007: } else {
11008: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
11009: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
11010: }
11011: } else {
11012: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
11013: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
11014: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
11015: } else {
11016: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
11017: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
11018: }
11019: }
11020: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
11021: if ($type eq 'default') {
11022: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
11023: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
11024: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
11025: } else {
11026: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
11027: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
11028: }
11029: } else {
11030: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
11031: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
11032: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
11033: } else {
11034: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
11035: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
11036: }
11037: }
11038: }
11039: }
11040: }
11041: }
11042: if ($output ne '') {
11043: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
11044: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 11045: }
1.160.6.5 raeburn 11046: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 11047: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 11048: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
11049: } else {
11050: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 11051: if ($captchas{$savecaptcha{$type}}) {
11052: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 11053: } else {
11054: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
11055: }
11056: }
11057: } elsif ($type eq 'recaptchakeys') {
11058: my ($privkey,$pubkey);
1.160.6.34 raeburn 11059: if (ref($savecaptcha{$type}) eq 'HASH') {
11060: $pubkey = $savecaptcha{$type}{'public'};
11061: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 11062: }
11063: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
11064: if (!$pubkey) {
11065: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
11066: } else {
11067: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11068: }
11069: if (!$privkey) {
11070: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
11071: } else {
11072: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
11073: }
11074: $chgtext .= '</ul>';
1.160.6.69 raeburn 11075: } elsif ($type eq 'recaptchaversion') {
11076: if ($savecaptcha{'captcha'} eq 'recaptcha') {
11077: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
11078: }
1.160.6.34 raeburn 11079: } elsif ($type eq 'emailusername') {
11080: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 11081: if (@statuses) {
11082: foreach my $type (@statuses) {
1.160.6.35 raeburn 11083: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
11084: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 11085: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.160.6.35 raeburn 11086: '<ul>';
11087: foreach my $field (@{$infofields}) {
11088: if ($cancreate{'emailusername'}{$type}{$field}) {
11089: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
11090: }
11091: }
1.160.6.50 raeburn 11092: $chgtext .= '</ul>';
11093: } else {
1.160.6.93 raeburn 11094: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.160.6.35 raeburn 11095: }
11096: } else {
1.160.6.93 raeburn 11097: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.160.6.34 raeburn 11098: }
11099: }
11100: }
11101: }
11102: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 11103: my $numapprove = 0;
1.160.6.34 raeburn 11104: if (ref($changes{'cancreate'}) eq 'ARRAY') {
11105: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
11106: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 11107: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
11108: $numapprove ++;
1.160.6.34 raeburn 11109: }
11110: }
1.43 raeburn 11111: }
1.160.6.93 raeburn 11112: unless ($numapprove) {
11113: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
11114: }
1.34 raeburn 11115: }
1.160.6.34 raeburn 11116: if ($chgtext) {
11117: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 11118: }
11119: }
11120: }
1.160.6.93 raeburn 11121: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 11122: my ($emailrules,$emailruleorder) =
11123: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 11124: foreach my $type (@{$changes{'email_rule'}}) {
11125: if (ref($email_rule{$type}) eq 'ARRAY') {
11126: my $chgtext = '<ul>';
11127: foreach my $rule (@{$email_rule{$type}}) {
11128: if (ref($emailrules->{$rule}) eq 'HASH') {
11129: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
11130: }
11131: }
11132: $chgtext .= '</ul>';
11133: my $typename;
11134: if (@types) {
11135: if ($type eq 'default') {
11136: $typename = $othertitle;
11137: } else {
11138: $typename = $usertypes{$type};
11139: }
11140: $chgtext .= &mt('(Affiliation: [_1])',$typename);
11141: }
11142: if (@{$email_rule{$type}} > 0) {
11143: $resulttext .= '<li>'.
11144: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
11145: $usertypes{$type}).
11146: $chgtext.
11147: '</li>';
11148: } else {
11149: $resulttext .= '<li>'.
11150: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
11151: '</li>'.
11152: &mt('(Affiliation: [_1])',$typename);
11153: }
1.43 raeburn 11154: }
11155: }
1.160.6.93 raeburn 11156: }
11157: if (ref($changes{'inststatus'}) eq 'ARRAY') {
11158: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
11159: if (@{$save_inststatus{'inststatusguest'}} > 0) {
11160: my $chgtext = '<ul>';
11161: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
11162: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
11163: }
11164: $chgtext .= '</ul>';
11165: $resulttext .= '<li>'.
11166: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
11167: $chgtext.
11168: '</li>';
11169: } else {
11170: $resulttext .= '<li>'.
11171: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
11172: '</li>';
11173: }
1.43 raeburn 11174: }
11175: }
1.160.6.34 raeburn 11176: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
11177: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
11178: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11179: foreach my $type (@{$changes{'selfcreate'}}) {
11180: my $typename = $type;
1.160.6.93 raeburn 11181: if (keys(%usertypes) > 0) {
11182: if ($usertypes{$type} ne '') {
11183: $typename = $usertypes{$type};
1.28 raeburn 11184: }
11185: }
1.160.6.34 raeburn 11186: my @modifiable;
11187: $resulttext .= '<li>'.
11188: &mt('Self-creation of account by users with status: [_1]',
11189: '<span class="LC_cusr_emph">'.$typename.'</span>').
11190: ' - '.&mt('modifiable fields (if institutional data blank): ');
11191: foreach my $field (@fields) {
11192: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11193: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
11194: }
11195: }
11196: if (@modifiable > 0) {
11197: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11198: } else {
1.160.6.34 raeburn 11199: $resulttext .= &mt('none');
1.43 raeburn 11200: }
1.160.6.34 raeburn 11201: $resulttext .= '</li>';
1.28 raeburn 11202: }
1.160.6.34 raeburn 11203: $resulttext .= '</ul></li>';
1.28 raeburn 11204: }
1.27 raeburn 11205: $resulttext .= '</ul>';
1.160.6.93 raeburn 11206: my $cachetime = 24*60*60;
11207: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
11208: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11209: if (ref($lastactref) eq 'HASH') {
11210: $lastactref->{'domdefaults'} = 1;
11211: }
1.27 raeburn 11212: } else {
1.160.6.34 raeburn 11213: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11214: }
11215: } else {
11216: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11217: &mt('An error occurred: [_1]',$putresult).'</span>';
11218: }
1.43 raeburn 11219: if ($warningmsg ne '') {
11220: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11221: }
1.23 raeburn 11222: return $resulttext;
11223: }
11224:
1.160.6.5 raeburn 11225: sub process_captcha {
11226: my ($container,$changes,$newsettings,$current) = @_;
11227: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11228: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11229: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11230: $newsettings->{'captcha'} = 'original';
11231: }
11232: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
11233: if ($container eq 'cancreate') {
11234: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11235: push(@{$changes->{'cancreate'}},'captcha');
11236: } elsif (!defined($changes->{'cancreate'})) {
11237: $changes->{'cancreate'} = ['captcha'];
11238: }
11239: } else {
11240: $changes->{'captcha'} = 1;
11241: }
11242: }
1.160.6.69 raeburn 11243: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 11244: if ($newsettings->{'captcha'} eq 'recaptcha') {
11245: $newpub = $env{'form.'.$container.'_recaptchapub'};
11246: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 11247: $newpub =~ s/[^\w\-]//g;
11248: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 11249: $newsettings->{'recaptchakeys'} = {
11250: public => $newpub,
11251: private => $newpriv,
11252: };
1.160.6.69 raeburn 11253: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11254: $newversion =~ s/\D//g;
11255: if ($newversion ne '2') {
11256: $newversion = 1;
11257: }
11258: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 11259: }
11260: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11261: $currpub = $current->{'recaptchakeys'}{'public'};
11262: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 11263: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11264: $newsettings->{'recaptchakeys'} = {
11265: public => '',
11266: private => '',
11267: }
11268: }
1.160.6.5 raeburn 11269: }
1.160.6.69 raeburn 11270: if ($current->{'captcha'} eq 'recaptcha') {
11271: $currversion = $current->{'recaptchaversion'};
11272: if ($currversion ne '2') {
11273: $currversion = 1;
11274: }
11275: }
11276: if ($currversion ne $newversion) {
11277: if ($container eq 'cancreate') {
11278: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11279: push(@{$changes->{'cancreate'}},'recaptchaversion');
11280: } elsif (!defined($changes->{'cancreate'})) {
11281: $changes->{'cancreate'} = ['recaptchaversion'];
11282: }
11283: } else {
11284: $changes->{'recaptchaversion'} = 1;
11285: }
11286: }
1.160.6.5 raeburn 11287: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
11288: if ($container eq 'cancreate') {
11289: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11290: push(@{$changes->{'cancreate'}},'recaptchakeys');
11291: } elsif (!defined($changes->{'cancreate'})) {
11292: $changes->{'cancreate'} = ['recaptchakeys'];
11293: }
11294: } else {
11295: $changes->{'recaptchakeys'} = 1;
11296: }
11297: }
11298: return;
11299: }
11300:
1.33 raeburn 11301: sub modify_usermodification {
11302: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 11303: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11304: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11305: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 11306: if ($key eq 'selfcreate') {
11307: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11308: } else {
11309: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11310: }
1.33 raeburn 11311: }
11312: }
1.160.6.34 raeburn 11313: my @contexts = ('author','course');
1.33 raeburn 11314: my %context_title = (
11315: author => 'In author context',
11316: course => 'In course context',
11317: );
11318: my @fields = ('lastname','firstname','middlename','generation',
11319: 'permanentemail','id');
11320: my %roles = (
11321: author => ['ca','aa'],
11322: course => ['st','ep','ta','in','cr'],
11323: );
11324: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11325: foreach my $context (@contexts) {
11326: foreach my $role (@{$roles{$context}}) {
11327: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11328: foreach my $item (@fields) {
11329: if (grep(/^\Q$item\E$/,@modifiable)) {
11330: $modifyhash{$context}{$role}{$item} = 1;
11331: } else {
11332: $modifyhash{$context}{$role}{$item} = 0;
11333: }
11334: }
11335: }
11336: if (ref($curr_usermodification{$context}) eq 'HASH') {
11337: foreach my $role (@{$roles{$context}}) {
11338: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11339: foreach my $field (@fields) {
11340: if ($modifyhash{$context}{$role}{$field} ne
11341: $curr_usermodification{$context}{$role}{$field}) {
11342: push(@{$changes{$context}},$role);
11343: last;
11344: }
11345: }
11346: }
11347: }
11348: } else {
11349: foreach my $context (@contexts) {
11350: foreach my $role (@{$roles{$context}}) {
11351: push(@{$changes{$context}},$role);
11352: }
11353: }
11354: }
11355: }
11356: my %usermodification_hash = (
11357: usermodification => \%modifyhash,
11358: );
11359: my $putresult = &Apache::lonnet::put_dom('configuration',
11360: \%usermodification_hash,$dom);
11361: if ($putresult eq 'ok') {
11362: if (keys(%changes) > 0) {
11363: $resulttext = &mt('Changes made: ').'<ul>';
11364: foreach my $context (@contexts) {
11365: if (ref($changes{$context}) eq 'ARRAY') {
11366: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11367: if (ref($changes{$context}) eq 'ARRAY') {
11368: foreach my $role (@{$changes{$context}}) {
11369: my $rolename;
1.160.6.34 raeburn 11370: if ($role eq 'cr') {
11371: $rolename = &mt('Custom');
1.33 raeburn 11372: } else {
1.160.6.34 raeburn 11373: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11374: }
11375: my @modifiable;
1.160.6.34 raeburn 11376: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11377: foreach my $field (@fields) {
11378: if ($modifyhash{$context}{$role}{$field}) {
11379: push(@modifiable,$fieldtitles{$field});
11380: }
11381: }
11382: if (@modifiable > 0) {
11383: $resulttext .= join(', ',@modifiable);
11384: } else {
11385: $resulttext .= &mt('none');
11386: }
11387: $resulttext .= '</li>';
11388: }
11389: $resulttext .= '</ul></li>';
11390: }
11391: }
11392: }
11393: $resulttext .= '</ul>';
11394: } else {
11395: $resulttext = &mt('No changes made to user modification settings');
11396: }
11397: } else {
11398: $resulttext = '<span class="LC_error">'.
11399: &mt('An error occurred: [_1]',$putresult).'</span>';
11400: }
11401: return $resulttext;
11402: }
11403:
1.43 raeburn 11404: sub modify_defaults {
1.160.6.27 raeburn 11405: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11406: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 11407: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 11408: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
11409: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 11410: my @authtypes = ('internal','krb4','krb5','localauth');
11411: foreach my $item (@items) {
11412: $newvalues{$item} = $env{'form.'.$item};
11413: if ($item eq 'auth_def') {
11414: if ($newvalues{$item} ne '') {
11415: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11416: push(@errors,$item);
11417: }
11418: }
11419: } elsif ($item eq 'lang_def') {
11420: if ($newvalues{$item} ne '') {
11421: if ($newvalues{$item} =~ /^(\w+)/) {
11422: my $langcode = $1;
1.103 raeburn 11423: if ($langcode ne 'x_chef') {
11424: if (code2language($langcode) eq '') {
11425: push(@errors,$item);
11426: }
1.43 raeburn 11427: }
11428: } else {
11429: push(@errors,$item);
11430: }
11431: }
1.54 raeburn 11432: } elsif ($item eq 'timezone_def') {
11433: if ($newvalues{$item} ne '') {
1.62 raeburn 11434: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11435: push(@errors,$item);
11436: }
11437: }
1.68 raeburn 11438: } elsif ($item eq 'datelocale_def') {
11439: if ($newvalues{$item} ne '') {
11440: my @datelocale_ids = DateTime::Locale->ids();
11441: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11442: push(@errors,$item);
11443: }
11444: }
1.141 raeburn 11445: } elsif ($item eq 'portal_def') {
11446: if ($newvalues{$item} ne '') {
11447: 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])\/?$/) {
11448: push(@errors,$item);
11449: }
11450: }
1.160.6.80 raeburn 11451: } elsif ($item eq 'intauth_cost') {
11452: if ($newvalues{$item} ne '') {
11453: if ($newvalues{$item} =~ /\D/) {
11454: push(@errors,$item);
11455: }
11456: }
11457: } elsif ($item eq 'intauth_check') {
11458: if ($newvalues{$item} ne '') {
11459: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11460: push(@errors,$item);
11461: }
11462: }
11463: } elsif ($item eq 'intauth_switch') {
11464: if ($newvalues{$item} ne '') {
11465: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11466: push(@errors,$item);
11467: }
11468: }
1.43 raeburn 11469: }
11470: if (grep(/^\Q$item\E$/,@errors)) {
11471: $newvalues{$item} = $domdefaults{$item};
11472: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
11473: $changes{$item} = 1;
11474: }
1.72 raeburn 11475: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 11476: }
11477: my %defaults_hash = (
1.72 raeburn 11478: defaults => \%newvalues,
11479: );
1.43 raeburn 11480: my $title = &defaults_titles();
1.160.6.40 raeburn 11481:
11482: my $currinststatus;
11483: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11484: $currinststatus = $domconfig{'inststatus'};
11485: } else {
11486: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11487: $currinststatus = {
11488: inststatustypes => $usertypes,
11489: inststatusorder => $types,
11490: inststatusguest => [],
11491: };
11492: }
11493: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
11494: my @allpos;
11495: my %alltypes;
1.160.6.93 raeburn 11496: my @inststatusguest;
11497: if (ref($currinststatus) eq 'HASH') {
11498: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11499: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
11500: unless (grep(/^\Q$type\E$/,@todelete)) {
11501: push(@inststatusguest,$type);
11502: }
11503: }
11504: }
11505: }
11506: my ($currtitles,$currorder);
1.160.6.40 raeburn 11507: if (ref($currinststatus) eq 'HASH') {
11508: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
11509: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
11510: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
11511: if ($currinststatus->{inststatustypes}->{$type} ne '') {
11512: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
11513: }
11514: }
11515: unless (grep(/^\Q$type\E$/,@todelete)) {
11516: my $position = $env{'form.inststatus_pos_'.$type};
11517: $position =~ s/\D+//g;
11518: $allpos[$position] = $type;
11519: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
11520: $alltypes{$type} =~ s/`//g;
11521: }
11522: }
11523: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11524: $currtitles =~ s/,$//;
11525: }
11526: }
11527: if ($env{'form.addinststatus'}) {
11528: my $newtype = $env{'form.addinststatus'};
11529: $newtype =~ s/\W//g;
11530: unless (exists($alltypes{$newtype})) {
11531: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11532: $alltypes{$newtype} =~ s/`//g;
11533: my $position = $env{'form.addinststatus_pos'};
11534: $position =~ s/\D+//g;
11535: if ($position ne '') {
11536: $allpos[$position] = $newtype;
11537: }
11538: }
11539: }
1.160.6.93 raeburn 11540: my @orderedstatus;
1.160.6.40 raeburn 11541: foreach my $type (@allpos) {
11542: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11543: push(@orderedstatus,$type);
11544: }
11545: }
11546: foreach my $type (keys(%alltypes)) {
11547: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
11548: delete($alltypes{$type});
11549: }
11550: }
11551: $defaults_hash{'inststatus'} = {
11552: inststatustypes => \%alltypes,
11553: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 11554: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 11555: };
11556: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
11557: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
11558: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
11559: }
11560: }
11561: if ($currorder ne join(',',@orderedstatus)) {
11562: $changes{'inststatus'}{'inststatusorder'} = 1;
11563: }
11564: my $newtitles;
11565: foreach my $item (@orderedstatus) {
11566: $newtitles .= $alltypes{$item}.',';
11567: }
11568: $newtitles =~ s/,$//;
11569: if ($currtitles ne $newtitles) {
11570: $changes{'inststatus'}{'inststatustypes'} = 1;
11571: }
1.43 raeburn 11572: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
11573: $dom);
11574: if ($putresult eq 'ok') {
11575: if (keys(%changes) > 0) {
11576: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 11577: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 11578: 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";
11579: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 11580: if ($item eq 'inststatus') {
11581: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 11582: if (@orderedstatus) {
1.160.6.40 raeburn 11583: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
11584: foreach my $type (@orderedstatus) {
11585: $resulttext .= $alltypes{$type}.', ';
11586: }
11587: $resulttext =~ s/, $//;
11588: $resulttext .= '</li>';
1.160.6.93 raeburn 11589: } else {
11590: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 11591: }
11592: }
11593: } else {
11594: my $value = $env{'form.'.$item};
11595: if ($value eq '') {
11596: $value = &mt('none');
11597: } elsif ($item eq 'auth_def') {
11598: my %authnames = &authtype_names();
11599: my %shortauth = (
11600: internal => 'int',
11601: krb4 => 'krb4',
11602: krb5 => 'krb5',
11603: localauth => 'loc',
11604: );
11605: $value = $authnames{$shortauth{$value}};
1.160.6.80 raeburn 11606: } elsif ($item eq 'intauth_switch') {
11607: my %optiondesc = &Apache::lonlocal::texthash (
11608: 0 => 'No',
11609: 1 => 'Yes',
11610: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
11611: );
11612: if ($value =~ /^(0|1|2)$/) {
11613: $value = $optiondesc{$value};
11614: } else {
11615: $value = &mt('none -- defaults to No');
11616: }
11617: } elsif ($item eq 'intauth_check') {
11618: my %optiondesc = &Apache::lonlocal::texthash (
11619: 0 => 'No',
11620: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
11621: 2 => 'Yes, disallow login if stored cost is less than domain default',
11622: );
11623: if ($value =~ /^(0|1|2)$/) {
11624: $value = $optiondesc{$value};
11625: } else {
11626: $value = &mt('none -- defaults to No');
11627: }
1.160.6.40 raeburn 11628: }
11629: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11630: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11631: }
11632: }
11633: $resulttext .= '</ul>';
11634: $mailmsgtext .= "\n";
11635: my $cachetime = 24*60*60;
1.72 raeburn 11636: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11637: if (ref($lastactref) eq 'HASH') {
11638: $lastactref->{'domdefaults'} = 1;
11639: }
1.68 raeburn 11640: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 11641: my $notify = 1;
11642: if (ref($domconfig{'contacts'}) eq 'HASH') {
11643: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11644: $notify = 0;
11645: }
11646: }
11647: if ($notify) {
11648: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11649: "LON-CAPA Domain Settings Change - $dom",
11650: $mailmsgtext);
11651: }
1.54 raeburn 11652: }
1.43 raeburn 11653: } else {
1.54 raeburn 11654: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11655: }
11656: } else {
11657: $resulttext = '<span class="LC_error">'.
11658: &mt('An error occurred: [_1]',$putresult).'</span>';
11659: }
11660: if (@errors > 0) {
11661: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11662: foreach my $item (@errors) {
11663: $resulttext .= ' "'.$title->{$item}.'",';
11664: }
11665: $resulttext =~ s/,$//;
11666: }
11667: return $resulttext;
11668: }
11669:
1.46 raeburn 11670: sub modify_scantron {
1.160.6.24 raeburn 11671: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11672: my ($resulttext,%confhash,%changes,$errors);
11673: my $custom = 'custom.tab';
11674: my $default = 'default.tab';
11675: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97! raeburn 11676: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 11677: &config_check($dom,$confname,$servadm);
11678: if ($env{'form.scantronformat.filename'} ne '') {
11679: my $error;
11680: if ($configuserok eq 'ok') {
11681: if ($switchserver) {
1.130 raeburn 11682: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 11683: } else {
11684: if ($author_ok eq 'ok') {
11685: my ($result,$scantronurl) =
11686: &publishlogo($r,'upload','scantronformat',$dom,
11687: $confname,'scantron','','',$custom);
11688: if ($result eq 'ok') {
11689: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 11690: $changes{'scantronformat'} = 1;
1.46 raeburn 11691: } else {
11692: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
11693: }
11694: } else {
11695: $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);
11696: }
11697: }
11698: } else {
11699: $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);
11700: }
11701: if ($error) {
11702: &Apache::lonnet::logthis($error);
11703: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11704: }
11705: }
1.48 raeburn 11706: if (ref($domconfig{'scantron'}) eq 'HASH') {
11707: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
11708: if ($env{'form.scantronformat_del'}) {
11709: $confhash{'scantron'}{'scantronformat'} = '';
11710: $changes{'scantronformat'} = 1;
1.160.6.97! raeburn 11711: } else {
! 11712: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
! 11713: }
! 11714: }
! 11715: }
! 11716: my @options = ('hdr','pad','rem');
! 11717: my @fields = &scantroncsv_fields();
! 11718: my %titles = &scantronconfig_titles();
! 11719: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
! 11720: my ($newdat,$currdat,%newcol,%currcol);
! 11721: if (grep(/^dat$/,@formats)) {
! 11722: $confhash{'scantron'}{config}{dat} = 1;
! 11723: $newdat = 1;
! 11724: } else {
! 11725: $newdat = 0;
! 11726: }
! 11727: if (grep(/^csv$/,@formats)) {
! 11728: my %bynum;
! 11729: foreach my $field (@fields) {
! 11730: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
! 11731: my $posscol = $1;
! 11732: if (($posscol < 20) && (!$bynum{$posscol})) {
! 11733: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
! 11734: $bynum{$posscol} = $field;
! 11735: $newcol{$field} = $posscol;
! 11736: }
! 11737: }
! 11738: }
! 11739: if (keys(%newcol)) {
! 11740: foreach my $option (@options) {
! 11741: if ($env{'form.scantroncsv_'.$option}) {
! 11742: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
! 11743: }
! 11744: }
! 11745: }
! 11746: }
! 11747: $currdat = 1;
! 11748: if (ref($domconfig{'scantron'}) eq 'HASH') {
! 11749: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
! 11750: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
! 11751: $currdat = 0;
! 11752: }
! 11753: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
! 11754: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
! 11755: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
! 11756: }
! 11757: }
! 11758: }
! 11759: }
! 11760: if ($currdat != $newdat) {
! 11761: $changes{'config'} = 1;
! 11762: } else {
! 11763: foreach my $field (@fields) {
! 11764: if ($currcol{$field} ne '') {
! 11765: if ($currcol{$field} ne $newcol{$field}) {
! 11766: $changes{'config'} = 1;
! 11767: last;
! 11768: }
! 11769: } elsif ($newcol{$field} ne '') {
! 11770: $changes{'config'} = 1;
! 11771: last;
1.46 raeburn 11772: }
11773: }
11774: }
11775: if (keys(%confhash) > 0) {
11776: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
11777: $dom);
11778: if ($putresult eq 'ok') {
11779: if (keys(%changes) > 0) {
1.48 raeburn 11780: if (ref($confhash{'scantron'}) eq 'HASH') {
11781: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97! raeburn 11782: if ($changes{'scantronformat'}) {
! 11783: if ($confhash{'scantron'}{'scantronformat'} eq '') {
! 11784: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
! 11785: } else {
! 11786: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
! 11787: }
! 11788: }
! 11789: if ($changes{'config'}) {
! 11790: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
! 11791: if ($confhash{'scantron'}{'config'}{'dat'}) {
! 11792: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
! 11793: }
! 11794: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
! 11795: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
! 11796: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
! 11797: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
! 11798: foreach my $field (@fields) {
! 11799: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
! 11800: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
! 11801: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
! 11802: }
! 11803: }
! 11804: $resulttext .= '</ul></li>';
! 11805: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
! 11806: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
! 11807: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
! 11808: foreach my $option (@options) {
! 11809: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
! 11810: $resulttext .= '<li>'.$titles{$option}.'</li>';
! 11811: }
! 11812: }
! 11813: $resulttext .= '</ul></li>';
! 11814: }
! 11815: }
! 11816: }
! 11817: }
! 11818: }
! 11819: } else {
! 11820: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
! 11821: }
1.46 raeburn 11822: }
1.48 raeburn 11823: $resulttext .= '</ul>';
11824: } else {
1.130 raeburn 11825: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 11826: }
11827: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11828: if (ref($lastactref) eq 'HASH') {
11829: $lastactref->{'domainconfig'} = 1;
11830: }
1.46 raeburn 11831: } else {
1.160.6.97! raeburn 11832: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 11833: }
11834: } else {
11835: $resulttext = '<span class="LC_error">'.
11836: &mt('An error occurred: [_1]',$putresult).'</span>';
11837: }
11838: } else {
1.160.6.97! raeburn 11839: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 11840: }
11841: if ($errors) {
11842: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11843: $errors.'</ul>';
11844: }
11845: return $resulttext;
11846: }
11847:
1.48 raeburn 11848: sub modify_coursecategories {
1.160.6.43 raeburn 11849: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 11850: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
11851: $cathash);
1.48 raeburn 11852: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 11853: my @catitems = ('unauth','auth');
11854: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 11855: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 11856: $cathash = $domconfig{'coursecategories'}{'cats'};
11857: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
11858: $changes{'togglecats'} = 1;
11859: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
11860: }
11861: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
11862: $changes{'categorize'} = 1;
11863: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
11864: }
1.120 raeburn 11865: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
11866: $changes{'togglecatscomm'} = 1;
11867: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
11868: }
11869: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
11870: $changes{'categorizecomm'} = 1;
11871: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
11872: }
1.160.6.42 raeburn 11873: foreach my $item (@catitems) {
11874: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11875: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
11876: $changes{$item} = 1;
11877: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11878: }
11879: }
11880: }
1.57 raeburn 11881: } else {
11882: $changes{'togglecats'} = 1;
11883: $changes{'categorize'} = 1;
1.124 raeburn 11884: $changes{'togglecatscomm'} = 1;
11885: $changes{'categorizecomm'} = 1;
1.87 raeburn 11886: $domconfig{'coursecategories'} = {
11887: togglecats => $env{'form.togglecats'},
11888: categorize => $env{'form.categorize'},
1.124 raeburn 11889: togglecatscomm => $env{'form.togglecatscomm'},
11890: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 11891: };
1.160.6.42 raeburn 11892: foreach my $item (@catitems) {
11893: if ($env{'form.coursecat_'.$item} ne 'std') {
11894: $changes{$item} = 1;
11895: }
11896: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11897: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11898: }
11899: }
1.57 raeburn 11900: }
11901: if (ref($cathash) eq 'HASH') {
11902: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 11903: push (@deletecategory,'instcode::0');
11904: }
1.120 raeburn 11905: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11906: push(@deletecategory,'communities::0');
11907: }
1.48 raeburn 11908: }
1.57 raeburn 11909: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11910: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11911: if (@deletecategory > 0) {
11912: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 11913: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 11914: foreach my $item (@deletecategory) {
1.57 raeburn 11915: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11916: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11917: $deletions{$item} = 1;
1.57 raeburn 11918: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11919: }
11920: }
11921: }
1.57 raeburn 11922: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11923: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11924: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11925: $reorderings{$item} = 1;
1.57 raeburn 11926: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11927: }
11928: if ($env{'form.addcategory_name_'.$item} ne '') {
11929: my $newcat = $env{'form.addcategory_name_'.$item};
11930: my $newdepth = $depth+1;
11931: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11932: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11933: $adds{$newitem} = 1;
11934: }
11935: if ($env{'form.subcat_'.$item} ne '') {
11936: my $newcat = $env{'form.subcat_'.$item};
11937: my $newdepth = $depth+1;
11938: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11939: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11940: $adds{$newitem} = 1;
11941: }
11942: }
11943: }
11944: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11945: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11946: my $newitem = 'instcode::0';
1.57 raeburn 11947: if ($cathash->{$newitem} eq '') {
11948: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11949: $adds{$newitem} = 1;
11950: }
11951: } else {
11952: my $newitem = 'instcode::0';
1.57 raeburn 11953: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11954: $adds{$newitem} = 1;
11955: }
11956: }
1.120 raeburn 11957: if ($env{'form.communities'} eq '1') {
11958: if (ref($cathash) eq 'HASH') {
11959: my $newitem = 'communities::0';
11960: if ($cathash->{$newitem} eq '') {
11961: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11962: $adds{$newitem} = 1;
11963: }
11964: } else {
11965: my $newitem = 'communities::0';
11966: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11967: $adds{$newitem} = 1;
11968: }
11969: }
1.48 raeburn 11970: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11971: if (($env{'form.addcategory_name'} ne 'instcode') &&
11972: ($env{'form.addcategory_name'} ne 'communities')) {
11973: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11974: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11975: $adds{$newitem} = 1;
11976: }
1.48 raeburn 11977: }
1.57 raeburn 11978: my $putresult;
1.48 raeburn 11979: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11980: if (keys(%deletions) > 0) {
11981: foreach my $key (keys(%deletions)) {
11982: if ($predelallitems{$key} ne '') {
11983: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11984: }
11985: }
11986: }
11987: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11988: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11989: if (ref($chkcats[0]) eq 'ARRAY') {
11990: my $depth = 0;
11991: my $chg = 0;
11992: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11993: my $name = $chkcats[0][$i];
11994: my $item;
11995: if ($name eq '') {
11996: $chg ++;
11997: } else {
11998: $item = &escape($name).'::0';
11999: if ($chg) {
1.57 raeburn 12000: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 12001: }
12002: $depth ++;
1.57 raeburn 12003: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 12004: $depth --;
12005: }
12006: }
12007: }
1.57 raeburn 12008: }
12009: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12010: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 12011: if ($putresult eq 'ok') {
1.57 raeburn 12012: my %title = (
1.120 raeburn 12013: togglecats => 'Show/Hide a course in catalog',
12014: categorize => 'Assign a category to a course',
12015: togglecatscomm => 'Show/Hide a community in catalog',
12016: categorizecomm => 'Assign a category to a community',
1.57 raeburn 12017: );
12018: my %level = (
1.120 raeburn 12019: dom => 'set in Domain ("Modify Course/Community")',
12020: crs => 'set in Course ("Course Configuration")',
12021: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 12022: none => 'No catalog',
12023: std => 'Standard catalog',
12024: domonly => 'Domain-only catalog',
12025: codesrch => 'Code search form',
1.57 raeburn 12026: );
1.48 raeburn 12027: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 12028: if ($changes{'togglecats'}) {
12029: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
12030: }
12031: if ($changes{'categorize'}) {
12032: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 12033: }
1.120 raeburn 12034: if ($changes{'togglecatscomm'}) {
12035: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
12036: }
12037: if ($changes{'categorizecomm'}) {
12038: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
12039: }
1.160.6.42 raeburn 12040: if ($changes{'unauth'}) {
12041: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
12042: }
12043: if ($changes{'auth'}) {
12044: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
12045: }
1.57 raeburn 12046: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
12047: my $cathash;
12048: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
12049: $cathash = $domconfig{'coursecategories'}{'cats'};
12050: } else {
12051: $cathash = {};
12052: }
12053: my (@cats,@trails,%allitems);
12054: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
12055: if (keys(%deletions) > 0) {
12056: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
12057: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
12058: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
12059: }
12060: $resulttext .= '</ul></li>';
12061: }
12062: if (keys(%reorderings) > 0) {
12063: my %sort_by_trail;
12064: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
12065: foreach my $key (keys(%reorderings)) {
12066: if ($allitems{$key} ne '') {
12067: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12068: }
1.48 raeburn 12069: }
1.57 raeburn 12070: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12071: $resulttext .= '<li>'.$trails[$trail].'</li>';
12072: }
12073: $resulttext .= '</ul></li>';
1.48 raeburn 12074: }
1.57 raeburn 12075: if (keys(%adds) > 0) {
12076: my %sort_by_trail;
12077: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
12078: foreach my $key (keys(%adds)) {
12079: if ($allitems{$key} ne '') {
12080: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
12081: }
12082: }
12083: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
12084: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 12085: }
1.57 raeburn 12086: $resulttext .= '</ul></li>';
1.48 raeburn 12087: }
1.160.6.92 raeburn 12088: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
12089: if (ref($lastactref) eq 'HASH') {
12090: $lastactref->{'cats'} = 1;
12091: }
1.48 raeburn 12092: }
12093: $resulttext .= '</ul>';
1.160.6.43 raeburn 12094: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 12095: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12096: if ($changes{'auth'}) {
12097: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
12098: }
12099: if ($changes{'unauth'}) {
12100: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
12101: }
12102: my $cachetime = 24*60*60;
12103: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 12104: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 12105: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 12106: }
12107: }
1.48 raeburn 12108: } else {
12109: $resulttext = '<span class="LC_error">'.
1.57 raeburn 12110: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 12111: }
12112: } else {
1.120 raeburn 12113: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 12114: }
12115: return $resulttext;
12116: }
12117:
1.69 raeburn 12118: sub modify_serverstatuses {
12119: my ($dom,%domconfig) = @_;
12120: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
12121: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
12122: %currserverstatus = %{$domconfig{'serverstatuses'}};
12123: }
12124: my @pages = &serverstatus_pages();
12125: foreach my $type (@pages) {
12126: $newserverstatus{$type}{'namedusers'} = '';
12127: $newserverstatus{$type}{'machines'} = '';
12128: if (defined($env{'form.'.$type.'_namedusers'})) {
12129: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
12130: my @okusers;
12131: foreach my $user (@users) {
12132: my ($uname,$udom) = split(/:/,$user);
12133: if (($udom =~ /^$match_domain$/) &&
12134: (&Apache::lonnet::domain($udom)) &&
12135: ($uname =~ /^$match_username$/)) {
12136: if (!grep(/^\Q$user\E/,@okusers)) {
12137: push(@okusers,$user);
12138: }
12139: }
12140: }
12141: if (@okusers > 0) {
12142: @okusers = sort(@okusers);
12143: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
12144: }
12145: }
12146: if (defined($env{'form.'.$type.'_machines'})) {
12147: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
12148: my @okmachines;
12149: foreach my $ip (@machines) {
12150: my @parts = split(/\./,$ip);
12151: next if (@parts < 4);
12152: my $badip = 0;
12153: for (my $i=0; $i<4; $i++) {
12154: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
12155: $badip = 1;
12156: last;
12157: }
12158: }
12159: if (!$badip) {
12160: push(@okmachines,$ip);
12161: }
12162: }
12163: @okmachines = sort(@okmachines);
12164: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
12165: }
12166: }
12167: my %serverstatushash = (
12168: serverstatuses => \%newserverstatus,
12169: );
12170: foreach my $type (@pages) {
1.83 raeburn 12171: foreach my $setting ('namedusers','machines') {
1.84 raeburn 12172: my (@current,@new);
1.83 raeburn 12173: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 12174: if ($currserverstatus{$type}{$setting} ne '') {
12175: @current = split(/,/,$currserverstatus{$type}{$setting});
12176: }
12177: }
12178: if ($newserverstatus{$type}{$setting} ne '') {
12179: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 12180: }
12181: if (@current > 0) {
12182: if (@new > 0) {
12183: foreach my $item (@current) {
12184: if (!grep(/^\Q$item\E$/,@new)) {
12185: $changes{$type}{$setting} = 1;
1.82 raeburn 12186: last;
12187: }
12188: }
1.84 raeburn 12189: foreach my $item (@new) {
12190: if (!grep(/^\Q$item\E$/,@current)) {
12191: $changes{$type}{$setting} = 1;
12192: last;
1.82 raeburn 12193: }
12194: }
12195: } else {
1.83 raeburn 12196: $changes{$type}{$setting} = 1;
1.69 raeburn 12197: }
1.83 raeburn 12198: } elsif (@new > 0) {
12199: $changes{$type}{$setting} = 1;
1.69 raeburn 12200: }
12201: }
12202: }
12203: if (keys(%changes) > 0) {
1.81 raeburn 12204: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 12205: my $putresult = &Apache::lonnet::put_dom('configuration',
12206: \%serverstatushash,$dom);
12207: if ($putresult eq 'ok') {
12208: $resulttext .= &mt('Changes made:').'<ul>';
12209: foreach my $type (@pages) {
1.84 raeburn 12210: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 12211: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 12212: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 12213: if ($newserverstatus{$type}{'namedusers'} eq '') {
12214: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
12215: } else {
12216: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
12217: }
1.84 raeburn 12218: }
12219: if ($changes{$type}{'machines'}) {
1.69 raeburn 12220: if ($newserverstatus{$type}{'machines'} eq '') {
12221: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
12222: } else {
12223: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
12224: }
12225:
12226: }
12227: $resulttext .= '</ul></li>';
12228: }
12229: }
12230: $resulttext .= '</ul>';
12231: } else {
12232: $resulttext = '<span class="LC_error">'.
12233: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
12234:
12235: }
12236: } else {
12237: $resulttext = &mt('No changes made to access to server status pages');
12238: }
12239: return $resulttext;
12240: }
12241:
1.118 jms 12242: sub modify_helpsettings {
1.160.6.77 raeburn 12243: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 12244: my ($resulttext,$errors,%changes,%helphash);
12245: my %defaultchecked = ('submitbugs' => 'on');
12246: my @offon = ('off','on');
1.118 jms 12247: my @toggles = ('submitbugs');
1.160.6.77 raeburn 12248: my %current = ('submitbugs' => '',
12249: 'adhoc' => {},
12250: );
1.118 jms 12251: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 12252: %current = %{$domconfig{'helpsettings'}};
12253: }
1.160.6.77 raeburn 12254: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 12255: foreach my $item (@toggles) {
12256: if ($defaultchecked{$item} eq 'on') {
12257: if ($current{$item} eq '') {
12258: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 12259: $changes{$item} = 1;
12260: }
1.160.6.73 raeburn 12261: } elsif ($current{$item} ne $env{'form.'.$item}) {
12262: $changes{$item} = 1;
12263: }
12264: } elsif ($defaultchecked{$item} eq 'off') {
12265: if ($current{$item} eq '') {
12266: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 12267: $changes{$item} = 1;
12268: }
1.160.6.73 raeburn 12269: } elsif ($current{$item} ne $env{'form.'.$item}) {
12270: $changes{$item} = 1;
12271: }
12272: }
12273: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
12274: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
12275: }
12276: }
1.160.6.77 raeburn 12277: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 12278: my $confname = $dom.'-domainconfig';
12279: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 12280: my (@allpos,%newsettings,%changedprivs,$newrole);
12281: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 12282: my @accesstypes = ('all','dh','da','none','status','inc','exc');
12283: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 12284: my %lt = &Apache::lonlocal::texthash(
12285: s => 'system',
12286: d => 'domain',
12287: order => 'Display order',
12288: access => 'Role usage',
1.160.6.79 raeburn 12289: all => 'All with domain helpdesk or helpdesk assistant role',
12290: dh => 'All with domain helpdesk role',
12291: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 12292: none => 'None',
12293: status => 'Determined based on institutional status',
12294: inc => 'Include all, but exclude specific personnel',
12295: exc => 'Exclude all, but include specific personnel',
12296: );
12297: for (my $num=0; $num<=$maxnum; $num++) {
12298: my ($prefix,$identifier,$rolename,%curr);
12299: if ($num == $maxnum) {
12300: next unless ($env{'form.newcusthelp'} == $maxnum);
12301: $identifier = 'custhelp'.$num;
12302: $prefix = 'helproles_'.$num;
12303: $rolename = $env{'form.custhelpname'.$num};
12304: $rolename=~s/[^A-Za-z0-9]//gs;
12305: next if ($rolename eq '');
12306: next if (exists($existing{'rolesdef_'.$rolename}));
12307: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12308: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12309: $newprivs{'c'},$confname,$dom);
12310: if ($result ne 'ok') {
12311: $errors .= '<li><span class="LC_error">'.
12312: &mt('An error occurred storing the new custom role: [_1]',
12313: $result).'</span></li>';
12314: next;
12315: } else {
12316: $changedprivs{$rolename} = \%newprivs;
12317: $newrole = $rolename;
12318: }
12319: } else {
12320: $prefix = 'helproles_'.$num;
12321: $rolename = $env{'form.'.$prefix};
12322: next if ($rolename eq '');
12323: next unless (exists($existing{'rolesdef_'.$rolename}));
12324: $identifier = 'custhelp'.$num;
12325: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12326: my %currprivs;
12327: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
12328: split(/\_/,$existing{'rolesdef_'.$rolename});
12329: foreach my $level ('c','d','s') {
12330: if ($newprivs{$level} ne $currprivs{$level}) {
12331: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12332: $newprivs{'c'},$confname,$dom);
12333: if ($result ne 'ok') {
12334: $errors .= '<li><span class="LC_error">'.
12335: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12336: $rolename,$result).'</span></li>';
12337: } else {
12338: $changedprivs{$rolename} = \%newprivs;
12339: }
12340: last;
12341: }
12342: }
12343: if (ref($current{'adhoc'}) eq 'HASH') {
12344: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12345: %curr = %{$current{'adhoc'}{$rolename}};
12346: }
12347: }
12348: }
12349: my $newpos = $env{'form.'.$prefix.'_pos'};
12350: $newpos =~ s/\D+//g;
12351: $allpos[$newpos] = $rolename;
12352: my $newdesc = $env{'form.'.$prefix.'_desc'};
12353: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12354: if ($curr{'desc'}) {
12355: if ($curr{'desc'} ne $newdesc) {
12356: $changes{'customrole'}{$rolename}{'desc'} = 1;
12357: $newsettings{$rolename}{'desc'} = $newdesc;
12358: }
12359: } elsif ($newdesc ne '') {
12360: $changes{'customrole'}{$rolename}{'desc'} = 1;
12361: $newsettings{$rolename}{'desc'} = $newdesc;
12362: }
12363: my $access = $env{'form.'.$prefix.'_access'};
12364: if (grep(/^\Q$access\E$/,@accesstypes)) {
12365: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12366: if ($access eq 'status') {
12367: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12368: if (scalar(@statuses) == 0) {
12369: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
12370: } else {
12371: my (@shownstatus,$numtypes);
12372: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12373: if (ref($types) eq 'ARRAY') {
12374: $numtypes = scalar(@{$types});
12375: foreach my $type (sort(@statuses)) {
12376: if ($type eq 'default') {
12377: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12378: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12379: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12380: push(@shownstatus,$usertypes->{$type});
12381: }
1.160.6.73 raeburn 12382: }
12383: }
1.160.6.77 raeburn 12384: if (grep(/^default$/,@statuses)) {
12385: push(@shownstatus,$othertitle);
12386: }
12387: if (scalar(@shownstatus) == 1+$numtypes) {
12388: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12389: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12390: } else {
12391: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12392: if (ref($curr{'status'}) eq 'ARRAY') {
12393: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12394: if (@diffs) {
12395: $changes{'customrole'}{$rolename}{$access} = 1;
12396: }
12397: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12398: $changes{'customrole'}{$rolename}{$access} = 1;
12399: }
12400: }
12401: }
12402: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12403: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12404: my @newspecstaff;
12405: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12406: foreach my $person (sort(@personnel)) {
12407: if ($domhelpdesk{$person}) {
12408: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12409: }
12410: }
12411: if (ref($curr{$access}) eq 'ARRAY') {
12412: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12413: if (@diffs) {
12414: $changes{'customrole'}{$rolename}{$access} = 1;
12415: }
12416: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12417: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 12418: }
1.160.6.77 raeburn 12419: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12420: my ($uname,$udom) = split(/:/,$person);
12421: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12422: }
12423: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 12424: }
1.160.6.77 raeburn 12425: } else {
12426: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12427: }
12428: unless ($curr{'access'} eq $access) {
12429: $changes{'customrole'}{$rolename}{'access'} = 1;
12430: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 12431: }
12432: }
1.160.6.77 raeburn 12433: if (@allpos > 0) {
12434: my $idx = 0;
12435: foreach my $rolename (@allpos) {
12436: if ($rolename ne '') {
12437: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12438: if (ref($current{'adhoc'}) eq 'HASH') {
12439: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12440: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12441: $changes{'customrole'}{$rolename}{'order'} = 1;
12442: $newsettings{$rolename}{'order'} = $idx+1;
12443: }
12444: }
1.160.6.73 raeburn 12445: }
1.160.6.77 raeburn 12446: $idx ++;
1.122 jms 12447: }
12448: }
1.118 jms 12449: }
1.123 jms 12450: my $putresult;
12451: if (keys(%changes) > 0) {
1.160.6.5 raeburn 12452: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
12453: if ($putresult eq 'ok') {
1.160.6.77 raeburn 12454: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12455: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12456: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12457: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12458: }
12459: }
12460: my $cachetime = 24*60*60;
12461: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12462: if (ref($lastactref) eq 'HASH') {
12463: $lastactref->{'domdefaults'} = 1;
12464: }
12465: } else {
12466: $errors .= '<li><span class="LC_error">'.
12467: &mt('An error occurred storing the settings: [_1]',
12468: $putresult).'</span></li>';
12469: }
12470: }
12471: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12472: $resulttext = &mt('Changes made:').'<ul>';
12473: my (%shownprivs,@levelorder);
12474: @levelorder = ('c','d','s');
12475: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 12476: foreach my $item (sort(keys(%changes))) {
12477: if ($item eq 'submitbugs') {
12478: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12479: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12480: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 12481: } elsif ($item eq 'customrole') {
12482: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 12483: my @keyorder = ('order','desc','access','status','exc','inc');
12484: my %keytext = &Apache::lonlocal::texthash(
12485: order => 'Order',
12486: desc => 'Role description',
12487: access => 'Role usage',
1.160.6.83 raeburn 12488: status => 'Allowed institutional types',
1.160.6.77 raeburn 12489: exc => 'Allowed personnel',
12490: inc => 'Disallowed personnel',
12491: );
1.160.6.73 raeburn 12492: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 12493: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12494: if ($role eq $newrole) {
12495: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12496: $role).'<ul>';
12497: } else {
12498: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12499: $role).'<ul>';
12500: }
12501: foreach my $key (@keyorder) {
12502: if ($changes{'customrole'}{$role}{$key}) {
12503: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12504: $keytext{$key},$newsettings{$role}{$key}).
12505: '</li>';
12506: }
12507: }
12508: if (ref($changedprivs{$role}) eq 'HASH') {
12509: $shownprivs{$role} = 1;
12510: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
12511: foreach my $level (@levelorder) {
12512: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12513: next if ($item eq '');
12514: my ($priv) = split(/\&/,$item,2);
12515: if (&Apache::lonnet::plaintext($priv)) {
12516: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12517: unless ($level eq 'c') {
12518: $resulttext .= ' ('.$lt{$level}.')';
12519: }
12520: $resulttext .= '</li>';
12521: }
12522: }
12523: }
12524: $resulttext .= '</ul>';
12525: }
12526: $resulttext .= '</ul></li>';
12527: }
1.160.6.73 raeburn 12528: }
12529: }
1.160.6.5 raeburn 12530: }
12531: }
12532: }
1.160.6.77 raeburn 12533: if (keys(%changedprivs)) {
12534: foreach my $role (sort(keys(%changedprivs))) {
12535: unless ($shownprivs{$role}) {
12536: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12537: $role).'<ul>'.
12538: '<li>'.&mt('Privileges set to :').'<ul>';
12539: foreach my $level (@levelorder) {
12540: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12541: next if ($item eq '');
12542: my ($priv) = split(/\&/,$item,2);
12543: if (&Apache::lonnet::plaintext($priv)) {
12544: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12545: unless ($level eq 'c') {
12546: $resulttext .= ' ('.$lt{$level}.')';
12547: }
12548: $resulttext .= '</li>';
12549: }
12550: }
12551: }
12552: $resulttext .= '</ul></li></ul></li>';
12553: }
12554: }
12555: }
12556: $resulttext .= '</ul>';
12557: } else {
12558: $resulttext = &mt('No changes made to help settings');
1.118 jms 12559: }
12560: if ($errors) {
1.160.6.5 raeburn 12561: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 12562: $errors.'</ul>';
1.118 jms 12563: }
12564: return $resulttext;
12565: }
12566:
1.121 raeburn 12567: sub modify_coursedefaults {
1.160.6.27 raeburn 12568: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 12569: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 12570: my %defaultchecked = (
12571: 'uselcmath' => 'on',
12572: 'usejsme' => 'on'
12573: );
12574: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 12575: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 12576: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
12577: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 12578: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 12579: my %staticdefaults = (
12580: anonsurvey_threshold => 10,
12581: uploadquota => 500,
1.160.6.57 raeburn 12582: postsubmit => 60,
1.160.6.70 raeburn 12583: mysqltables => 172800,
1.160.6.21 raeburn 12584: );
1.160.6.90 raeburn 12585: my %texoptions = (
12586: MathJax => 'MathJax',
12587: mimetex => &mt('Convert to Images'),
12588: tth => &mt('TeX to HTML'),
12589: );
1.121 raeburn 12590: $defaultshash{'coursedefaults'} = {};
12591:
12592: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
12593: if ($domconfig{'coursedefaults'} eq '') {
12594: $domconfig{'coursedefaults'} = {};
12595: }
12596: }
12597:
12598: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
12599: foreach my $item (@toggles) {
12600: if ($defaultchecked{$item} eq 'on') {
12601: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12602: ($env{'form.'.$item} eq '0')) {
12603: $changes{$item} = 1;
1.160.6.16 raeburn 12604: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 12605: $changes{$item} = 1;
12606: }
12607: } elsif ($defaultchecked{$item} eq 'off') {
12608: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12609: ($env{'form.'.$item} eq '1')) {
12610: $changes{$item} = 1;
12611: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
12612: $changes{$item} = 1;
12613: }
12614: }
12615: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
12616: }
1.160.6.21 raeburn 12617: foreach my $item (@numbers) {
12618: my ($currdef,$newdef);
1.160.6.26 raeburn 12619: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 12620: if ($item eq 'anonsurvey_threshold') {
12621: $currdef = $domconfig{'coursedefaults'}{$item};
12622: $newdef =~ s/\D//g;
12623: if ($newdef eq '' || $newdef < 1) {
12624: $newdef = 1;
12625: }
12626: $defaultshash{'coursedefaults'}{$item} = $newdef;
12627: } else {
1.160.6.70 raeburn 12628: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
12629: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
12630: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 12631: }
12632: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 12633: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 12634: }
12635: if ($currdef ne $newdef) {
12636: if ($item eq 'anonsurvey_threshold') {
12637: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
12638: $changes{$item} = 1;
12639: }
1.160.6.70 raeburn 12640: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
12641: my $setting = $1;
12642: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
12643: $changes{$setting} = 1;
1.160.6.21 raeburn 12644: }
12645: }
1.139 raeburn 12646: }
12647: }
1.160.6.90 raeburn 12648: my $texengine;
12649: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
12650: $texengine = $env{'form.texengine'};
12651: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
12652: if ($currdef eq '') {
12653: unless ($texengine eq $Apache::lonnet::deftex) {
12654: $changes{'texengine'} = 1;
12655: }
12656: } elsif ($currdef ne $texengine) {
12657: $changes{'texengine'} = 1;
12658: }
12659: }
12660: if ($texengine ne '') {
12661: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
12662: }
1.160.6.64 raeburn 12663: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
12664: my @currclonecode;
12665: if (ref($currclone) eq 'HASH') {
12666: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
12667: @currclonecode = @{$currclone->{'instcode'}};
12668: }
12669: }
12670: my $newclone;
12671: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
12672: $newclone = $env{'form.canclone'};
12673: }
12674: if ($newclone eq 'instcode') {
12675: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
12676: my (%codedefaults,@code_order,@clonecode);
12677: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
12678: \@code_order);
12679: foreach my $item (@code_order) {
12680: if (grep(/^\Q$item\E$/,@newcodes)) {
12681: push(@clonecode,$item);
12682: }
12683: }
12684: if (@clonecode) {
12685: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
12686: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
12687: if (@diffs) {
12688: $changes{'canclone'} = 1;
12689: }
12690: } else {
12691: $newclone eq '';
12692: }
12693: } elsif ($newclone ne '') {
12694: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
12695: }
12696: if ($newclone ne $currclone) {
12697: $changes{'canclone'} = 1;
12698: }
1.160.6.57 raeburn 12699: my %credits;
12700: foreach my $type (@types) {
12701: unless ($type eq 'community') {
12702: $credits{$type} = $env{'form.'.$type.'_credits'};
12703: $credits{$type} =~ s/[^\d.]+//g;
12704: }
12705: }
12706: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
12707: ($env{'form.coursecredits'} eq '1')) {
12708: $changes{'coursecredits'} = 1;
12709: foreach my $type (keys(%credits)) {
12710: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12711: }
12712: } else {
12713: if ($env{'form.coursecredits'} eq '1') {
12714: foreach my $type (@types) {
12715: unless ($type eq 'community') {
12716: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
12717: $changes{'coursecredits'} = 1;
12718: }
12719: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12720: }
12721: }
12722: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12723: foreach my $type (@types) {
12724: unless ($type eq 'community') {
12725: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
12726: $changes{'coursecredits'} = 1;
12727: last;
12728: }
12729: }
12730: }
12731: }
12732: }
12733: if ($env{'form.postsubmit'} eq '1') {
12734: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
12735: my %currtimeout;
12736: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12737: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
12738: $changes{'postsubmit'} = 1;
12739: }
12740: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12741: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
12742: }
12743: } else {
12744: $changes{'postsubmit'} = 1;
12745: }
12746: foreach my $type (@types) {
12747: my $timeout = $env{'form.'.$type.'_timeout'};
12748: $timeout =~ s/\D//g;
12749: if ($timeout == $staticdefaults{'postsubmit'}) {
12750: $timeout = '';
12751: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
12752: $timeout = '0';
12753: }
12754: unless ($timeout eq '') {
12755: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
12756: }
12757: if (exists($currtimeout{$type})) {
12758: if ($timeout ne $currtimeout{$type}) {
12759: $changes{'postsubmit'} = 1;
12760: }
12761: } elsif ($timeout ne '') {
12762: $changes{'postsubmit'} = 1;
12763: }
12764: }
12765: } else {
12766: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
12767: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12768: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
12769: $changes{'postsubmit'} = 1;
12770: }
12771: } else {
12772: $changes{'postsubmit'} = 1;
12773: }
1.160.6.16 raeburn 12774: }
1.121 raeburn 12775: }
12776: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12777: $dom);
12778: if ($putresult eq 'ok') {
12779: if (keys(%changes) > 0) {
1.160.6.27 raeburn 12780: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 12781: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 12782: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90 raeburn 12783: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
12784: foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57 raeburn 12785: if ($changes{$item}) {
12786: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
12787: }
1.160.6.16 raeburn 12788: }
12789: if ($changes{'coursecredits'}) {
12790: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 12791: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
12792: $domdefaults{$type.'credits'} =
12793: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
12794: }
12795: }
12796: }
12797: if ($changes{'postsubmit'}) {
12798: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12799: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
12800: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12801: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
12802: $domdefaults{$type.'postsubtimeout'} =
12803: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12804: }
12805: }
1.160.6.16 raeburn 12806: }
12807: }
1.160.6.21 raeburn 12808: if ($changes{'uploadquota'}) {
12809: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
12810: foreach my $type (@types) {
12811: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
12812: }
12813: }
12814: }
1.160.6.64 raeburn 12815: if ($changes{'canclone'}) {
12816: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12817: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12818: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
12819: if (@clonecodes) {
12820: $domdefaults{'canclone'} = join('+',@clonecodes);
12821: }
12822: }
12823: } else {
12824: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
12825: }
12826: }
1.121 raeburn 12827: my $cachetime = 24*60*60;
12828: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12829: if (ref($lastactref) eq 'HASH') {
12830: $lastactref->{'domdefaults'} = 1;
12831: }
1.121 raeburn 12832: }
12833: $resulttext = &mt('Changes made:').'<ul>';
12834: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 12835: if ($item eq 'uselcmath') {
1.121 raeburn 12836: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 12837: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 12838: } else {
1.160.6.57 raeburn 12839: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
12840: }
12841: } elsif ($item eq 'usejsme') {
12842: if ($env{'form.'.$item} eq '1') {
12843: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
12844: } else {
12845: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 12846: }
1.160.6.90 raeburn 12847: } elsif ($item eq 'texengine') {
12848: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
12849: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
12850: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
12851: }
1.139 raeburn 12852: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 12853: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.160.6.21 raeburn 12854: } elsif ($item eq 'uploadquota') {
12855: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
12856: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
12857: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
12858: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 12859: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
12860:
1.160.6.21 raeburn 12861: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
12862: '</ul>'.
12863: '</li>';
12864: } else {
12865: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
12866: }
1.160.6.70 raeburn 12867: } elsif ($item eq 'mysqltables') {
12868: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
12869: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
12870: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
12871: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
12872: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
12873: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
12874: '</ul>'.
12875: '</li>';
12876: } else {
12877: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
12878: }
1.160.6.57 raeburn 12879: } elsif ($item eq 'postsubmit') {
12880: if ($domdefaults{'postsubmit'} eq 'off') {
12881: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
12882: } else {
12883: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
12884: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12885: $resulttext .= &mt('durations:').'<ul>';
12886: foreach my $type (@types) {
12887: $resulttext .= '<li>';
12888: my $timeout;
12889: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12890: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12891: }
12892: my $display;
12893: if ($timeout eq '0') {
12894: $display = &mt('unlimited');
12895: } elsif ($timeout eq '') {
12896: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
12897: } else {
12898: $display = &mt('[quant,_1,second]',$timeout);
12899: }
12900: if ($type eq 'community') {
12901: $resulttext .= &mt('Communities');
12902: } elsif ($type eq 'official') {
12903: $resulttext .= &mt('Official courses');
12904: } elsif ($type eq 'unofficial') {
12905: $resulttext .= &mt('Unofficial courses');
12906: } elsif ($type eq 'textbook') {
12907: $resulttext .= &mt('Textbook courses');
12908: }
12909: $resulttext .= ' -- '.$display.'</li>';
12910: }
12911: $resulttext .= '</ul>';
12912: }
12913: $resulttext .= '</li>';
12914: }
1.160.6.16 raeburn 12915: } elsif ($item eq 'coursecredits') {
12916: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12917: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 12918: ($domdefaults{'unofficialcredits'} eq '') &&
12919: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 12920: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12921: } else {
12922: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
12923: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
12924: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 12925: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 12926: '</ul>'.
12927: '</li>';
12928: }
12929: } else {
12930: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12931: }
1.160.6.64 raeburn 12932: } elsif ($item eq 'canclone') {
12933: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12934: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12935: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
12936: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
12937: }
12938: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
12939: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
12940: } else {
12941: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
12942: }
1.140 raeburn 12943: }
1.121 raeburn 12944: }
12945: $resulttext .= '</ul>';
12946: } else {
12947: $resulttext = &mt('No changes made to course defaults');
12948: }
12949: } else {
12950: $resulttext = '<span class="LC_error">'.
12951: &mt('An error occurred: [_1]',$putresult).'</span>';
12952: }
12953: return $resulttext;
12954: }
12955:
1.160.6.37 raeburn 12956: sub modify_selfenrollment {
12957: my ($dom,$lastactref,%domconfig) = @_;
12958: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
12959: my @types = ('official','unofficial','community','textbook');
12960: my %titles = &tool_titles();
12961: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12962: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
12963: $ordered{'default'} = ['types','registered','approval','limit'];
12964:
12965: my (%roles,%shown,%toplevel);
12966: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12967:
12968: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12969: if ($domconfig{'selfenrollment'} eq '') {
12970: $domconfig{'selfenrollment'} = {};
12971: }
12972: }
12973: %toplevel = (
12974: admin => 'Configuration Rights',
12975: default => 'Default settings',
12976: validation => 'Validation of self-enrollment requests',
12977: );
12978: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
12979:
12980: if (ref($ordered{'admin'}) eq 'ARRAY') {
12981: foreach my $item (@{$ordered{'admin'}}) {
12982: foreach my $type (@types) {
12983: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12984: $selfenrollhash{'admin'}{$type}{$item} = 1;
12985: } else {
12986: $selfenrollhash{'admin'}{$type}{$item} = 0;
12987: }
12988: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12989: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12990: if ($selfenrollhash{'admin'}{$type}{$item} ne
12991: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12992: push(@{$changes{'admin'}{$type}},$item);
12993: }
12994: } else {
12995: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12996: push(@{$changes{'admin'}{$type}},$item);
12997: }
12998: }
12999: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
13000: push(@{$changes{'admin'}{$type}},$item);
13001: }
13002: }
13003: }
13004: }
13005:
13006: foreach my $item (@{$ordered{'default'}}) {
13007: foreach my $type (@types) {
13008: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
13009: if ($item eq 'types') {
13010: unless (($value eq 'all') || ($value eq 'dom')) {
13011: $value = '';
13012: }
13013: } elsif ($item eq 'registered') {
13014: unless ($value eq '1') {
13015: $value = 0;
13016: }
13017: } elsif ($item eq 'approval') {
13018: unless ($value =~ /^[012]$/) {
13019: $value = 0;
13020: }
13021: } else {
13022: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13023: $value = 'none';
13024: }
13025: }
13026: $selfenrollhash{'default'}{$type}{$item} = $value;
13027: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
13028: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13029: if ($selfenrollhash{'default'}{$type}{$item} ne
13030: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
13031: push(@{$changes{'default'}{$type}},$item);
13032: }
13033: } else {
13034: push(@{$changes{'default'}{$type}},$item);
13035: }
13036: } else {
13037: push(@{$changes{'default'}{$type}},$item);
13038: }
13039: if ($item eq 'limit') {
13040: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
13041: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
13042: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
13043: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
13044: }
13045: } else {
13046: $selfenrollhash{'default'}{$type}{'cap'} = '';
13047: }
13048: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
13049: if ($selfenrollhash{'default'}{$type}{'cap'} ne
13050: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
13051: push(@{$changes{'default'}{$type}},'cap');
13052: }
13053: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
13054: push(@{$changes{'default'}{$type}},'cap');
13055: }
13056: }
13057: }
13058: }
13059:
13060: foreach my $item (@{$itemsref}) {
13061: if ($item eq 'fields') {
13062: my @changed;
13063: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
13064: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
13065: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
13066: }
13067: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13068: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
13069: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
13070: $domconfig{'selfenrollment'}{'validation'}{$item});
13071: } else {
13072: @changed = @{$selfenrollhash{'validation'}{$item}};
13073: }
13074: } else {
13075: @changed = @{$selfenrollhash{'validation'}{$item}};
13076: }
13077: if (@changed) {
13078: if ($selfenrollhash{'validation'}{$item}) {
13079: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
13080: } else {
13081: $changes{'validation'}{$item} = &mt('None');
13082: }
13083: }
13084: } else {
13085: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
13086: if ($item eq 'markup') {
13087: if ($env{'form.selfenroll_validation_'.$item}) {
13088: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13089: }
13090: }
13091: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
13092: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
13093: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
13094: }
13095: }
13096: }
13097: }
13098:
13099: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
13100: $dom);
13101: if ($putresult eq 'ok') {
13102: if (keys(%changes) > 0) {
13103: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13104: $resulttext = &mt('Changes made:').'<ul>';
13105: foreach my $key ('admin','default','validation') {
13106: if (ref($changes{$key}) eq 'HASH') {
13107: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
13108: if ($key eq 'validation') {
13109: foreach my $item (@{$itemsref}) {
13110: if (exists($changes{$key}{$item})) {
13111: if ($item eq 'markup') {
13112: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13113: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
13114: } else {
13115: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
13116: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
13117: }
13118: }
13119: }
13120: } else {
13121: foreach my $type (@types) {
13122: if ($type eq 'community') {
13123: $roles{'1'} = &mt('Community personnel');
13124: } else {
13125: $roles{'1'} = &mt('Course personnel');
13126: }
13127: if (ref($changes{$key}{$type}) eq 'ARRAY') {
13128: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13129: if ($key eq 'admin') {
13130: my @mgrdc = ();
13131: if (ref($ordered{$key}) eq 'ARRAY') {
13132: foreach my $item (@{$ordered{'admin'}}) {
13133: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
13134: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
13135: push(@mgrdc,$item);
13136: }
13137: }
13138: }
13139: if (@mgrdc) {
13140: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
13141: } else {
13142: delete($domdefaults{$type.'selfenrolladmdc'});
13143: }
13144: }
13145: } else {
13146: if (ref($ordered{$key}) eq 'ARRAY') {
13147: foreach my $item (@{$ordered{$key}}) {
13148: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13149: $domdefaults{$type.'selfenroll'.$item} =
13150: $selfenrollhash{$key}{$type}{$item};
13151: }
13152: }
13153: }
13154: }
13155: }
13156: $resulttext .= '<li>'.$titles{$type}.'<ul>';
13157: foreach my $item (@{$ordered{$key}}) {
13158: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
13159: $resulttext .= '<li>';
13160: if ($key eq 'admin') {
13161: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
13162: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
13163: } else {
13164: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
13165: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
13166: }
13167: $resulttext .= '</li>';
13168: }
13169: }
13170: $resulttext .= '</ul></li>';
13171: }
13172: }
13173: $resulttext .= '</ul></li>';
13174: }
13175: }
1.160.6.93 raeburn 13176: }
13177: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
13178: my $cachetime = 24*60*60;
13179: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13180: if (ref($lastactref) eq 'HASH') {
13181: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 13182: }
13183: }
13184: $resulttext .= '</ul>';
13185: } else {
13186: $resulttext = &mt('No changes made to self-enrollment settings');
13187: }
13188: } else {
13189: $resulttext = '<span class="LC_error">'.
13190: &mt('An error occurred: [_1]',$putresult).'</span>';
13191: }
13192: return $resulttext;
13193: }
13194:
1.137 raeburn 13195: sub modify_usersessions {
1.160.6.27 raeburn 13196: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 13197: my @hostingtypes = ('version','excludedomain','includedomain');
13198: my @offloadtypes = ('primary','default');
13199: my %types = (
13200: remote => \@hostingtypes,
13201: hosted => \@hostingtypes,
13202: spares => \@offloadtypes,
13203: );
13204: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 13205: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 13206: my (%by_ip,%by_location,@intdoms);
13207: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
13208: my @locations = sort(keys(%by_location));
1.137 raeburn 13209: my (%defaultshash,%changes);
13210: foreach my $prefix (@prefixes) {
13211: $defaultshash{'usersessions'}{$prefix} = {};
13212: }
1.160.6.27 raeburn 13213: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 13214: my $resulttext;
1.138 raeburn 13215: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 13216: foreach my $prefix (@prefixes) {
1.145 raeburn 13217: next if ($prefix eq 'spares');
13218: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 13219: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
13220: if ($type eq 'version') {
13221: my $value = $env{'form.'.$prefix.'_'.$type};
13222: my $okvalue;
13223: if ($value ne '') {
13224: if (grep(/^\Q$value\E$/,@lcversions)) {
13225: $okvalue = $value;
13226: }
13227: }
13228: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13229: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13230: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
13231: if ($inuse == 0) {
13232: $changes{$prefix}{$type} = 1;
13233: } else {
13234: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
13235: $changes{$prefix}{$type} = 1;
13236: }
13237: if ($okvalue ne '') {
13238: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13239: }
13240: }
13241: } else {
13242: if (($inuse == 1) && ($okvalue ne '')) {
13243: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13244: $changes{$prefix}{$type} = 1;
13245: }
13246: }
13247: } else {
13248: if (($inuse == 1) && ($okvalue ne '')) {
13249: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13250: $changes{$prefix}{$type} = 1;
13251: }
13252: }
13253: } else {
13254: if (($inuse == 1) && ($okvalue ne '')) {
13255: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
13256: $changes{$prefix}{$type} = 1;
13257: }
13258: }
13259: } else {
13260: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
13261: my @okvals;
13262: foreach my $val (@vals) {
1.138 raeburn 13263: if ($val =~ /:/) {
13264: my @items = split(/:/,$val);
13265: foreach my $item (@items) {
13266: if (ref($by_location{$item}) eq 'ARRAY') {
13267: push(@okvals,$item);
13268: }
13269: }
13270: } else {
13271: if (ref($by_location{$val}) eq 'ARRAY') {
13272: push(@okvals,$val);
13273: }
1.137 raeburn 13274: }
13275: }
13276: @okvals = sort(@okvals);
13277: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13278: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13279: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13280: if ($inuse == 0) {
13281: $changes{$prefix}{$type} = 1;
13282: } else {
13283: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13284: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13285: if (@changed > 0) {
13286: $changes{$prefix}{$type} = 1;
13287: }
13288: }
13289: } else {
13290: if ($inuse == 1) {
13291: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13292: $changes{$prefix}{$type} = 1;
13293: }
13294: }
13295: } else {
13296: if ($inuse == 1) {
13297: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13298: $changes{$prefix}{$type} = 1;
13299: }
13300: }
13301: } else {
13302: if ($inuse == 1) {
13303: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13304: $changes{$prefix}{$type} = 1;
13305: }
13306: }
13307: }
13308: }
13309: }
1.145 raeburn 13310:
13311: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 13312: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 13313: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13314: my $savespares;
13315:
13316: foreach my $lonhost (sort(keys(%servers))) {
13317: my $serverhomeID =
13318: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 13319: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 13320: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13321: my %spareschg;
13322: foreach my $type (@{$types{'spares'}}) {
13323: my @okspares;
13324: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13325: foreach my $server (@checked) {
1.152 raeburn 13326: if (&Apache::lonnet::hostname($server) ne '') {
13327: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13328: unless (grep(/^\Q$server\E$/,@okspares)) {
13329: push(@okspares,$server);
13330: }
1.145 raeburn 13331: }
13332: }
13333: }
13334: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13335: my $newspare;
1.152 raeburn 13336: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13337: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 13338: $newspare = $new;
13339: }
13340: }
1.152 raeburn 13341: my @spares;
13342: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13343: @spares = sort(@okspares,$newspare);
13344: } else {
13345: @spares = sort(@okspares);
13346: }
13347: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 13348: if (ref($spareid{$lonhost}) eq 'HASH') {
13349: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 13350: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 13351: if (@diffs > 0) {
13352: $spareschg{$type} = 1;
13353: }
13354: }
13355: }
13356: }
13357: if (keys(%spareschg) > 0) {
13358: $changes{'spares'}{$lonhost} = \%spareschg;
13359: }
13360: }
1.160.6.61 raeburn 13361: $defaultshash{'usersessions'}{'offloadnow'} = {};
13362: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13363: my @okoffload;
13364: if (@offloadnow) {
13365: foreach my $server (@offloadnow) {
13366: if (&Apache::lonnet::hostname($server) ne '') {
13367: unless (grep(/^\Q$server\E$/,@okoffload)) {
13368: push(@okoffload,$server);
13369: }
13370: }
13371: }
13372: if (@okoffload) {
13373: foreach my $lonhost (@okoffload) {
13374: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13375: }
13376: }
13377: }
1.145 raeburn 13378: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13379: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13380: if (ref($changes{'spares'}) eq 'HASH') {
13381: if (keys(%{$changes{'spares'}}) > 0) {
13382: $savespares = 1;
13383: }
13384: }
13385: } else {
13386: $savespares = 1;
13387: }
1.160.6.61 raeburn 13388: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13389: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13390: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13391: $changes{'offloadnow'} = 1;
13392: last;
13393: }
13394: }
13395: unless ($changes{'offloadnow'}) {
13396: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
13397: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13398: $changes{'offloadnow'} = 1;
13399: last;
13400: }
13401: }
13402: }
13403: } elsif (@okoffload) {
13404: $changes{'offloadnow'} = 1;
13405: }
13406: } elsif (@okoffload) {
13407: $changes{'offloadnow'} = 1;
1.145 raeburn 13408: }
1.147 raeburn 13409: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13410: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13411: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13412: $dom);
13413: if ($putresult eq 'ok') {
13414: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13415: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13416: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13417: }
13418: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13419: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13420: }
1.160.6.61 raeburn 13421: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13422: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13423: }
1.137 raeburn 13424: }
13425: my $cachetime = 24*60*60;
13426: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 13427: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 13428: if (ref($lastactref) eq 'HASH') {
13429: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 13430: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 13431: }
1.147 raeburn 13432: if (keys(%changes) > 0) {
13433: my %lt = &usersession_titles();
13434: $resulttext = &mt('Changes made:').'<ul>';
13435: foreach my $prefix (@prefixes) {
13436: if (ref($changes{$prefix}) eq 'HASH') {
13437: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13438: if ($prefix eq 'spares') {
13439: if (ref($changes{$prefix}) eq 'HASH') {
13440: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13441: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13442: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 13443: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13444: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13445: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13446: foreach my $type (@{$types{$prefix}}) {
13447: if ($changes{$prefix}{$lonhost}{$type}) {
13448: my $offloadto = &mt('None');
13449: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13450: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13451: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13452: }
1.145 raeburn 13453: }
1.147 raeburn 13454: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13455: }
1.137 raeburn 13456: }
13457: }
1.147 raeburn 13458: $resulttext .= '</li>';
1.137 raeburn 13459: }
13460: }
1.147 raeburn 13461: } else {
13462: foreach my $type (@{$types{$prefix}}) {
13463: if (defined($changes{$prefix}{$type})) {
13464: my $newvalue;
13465: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13466: if (ref($defaultshash{'usersessions'}{$prefix})) {
13467: if ($type eq 'version') {
13468: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13469: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13470: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13471: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13472: }
1.145 raeburn 13473: }
13474: }
13475: }
1.147 raeburn 13476: if ($newvalue eq '') {
13477: if ($type eq 'version') {
13478: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13479: } else {
13480: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13481: }
1.145 raeburn 13482: } else {
1.147 raeburn 13483: if ($type eq 'version') {
13484: $newvalue .= ' '.&mt('(or later)');
13485: }
13486: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13487: }
1.137 raeburn 13488: }
13489: }
13490: }
1.147 raeburn 13491: $resulttext .= '</ul>';
1.137 raeburn 13492: }
13493: }
1.160.6.61 raeburn 13494: if ($changes{'offloadnow'}) {
13495: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13496: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13497: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13498: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13499: $resulttext .= '<li>'.$lonhost.'</li>';
13500: }
13501: $resulttext .= '</ul>';
13502: } else {
13503: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13504: }
13505: } else {
13506: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13507: }
13508: }
1.147 raeburn 13509: $resulttext .= '</ul>';
13510: } else {
13511: $resulttext = $nochgmsg;
1.137 raeburn 13512: }
13513: } else {
13514: $resulttext = '<span class="LC_error">'.
13515: &mt('An error occurred: [_1]',$putresult).'</span>';
13516: }
13517: } else {
1.147 raeburn 13518: $resulttext = $nochgmsg;
1.137 raeburn 13519: }
13520: return $resulttext;
13521: }
13522:
1.150 raeburn 13523: sub modify_loadbalancing {
13524: my ($dom,%domconfig) = @_;
13525: my $primary_id = &Apache::lonnet::domain($dom,'primary');
13526: my $intdom = &Apache::lonnet::internet_dom($primary_id);
13527: my ($othertitle,$usertypes,$types) =
13528: &Apache::loncommon::sorted_inst_types($dom);
13529: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 13530: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 13531: my @sparestypes = ('primary','default');
13532: my %typetitles = &sparestype_titles();
13533: my $resulttext;
1.160.6.94 raeburn 13534: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 13535: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13536: %existing = %{$domconfig{'loadbalancing'}};
13537: }
13538: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 13539: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 13540: my ($saveloadbalancing,%defaultshash,%changes);
13541: my ($alltypes,$othertypes,$titles) =
13542: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
13543: my %ruletitles = &offloadtype_text();
13544: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
13545: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
13546: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
13547: if ($balancer eq '') {
13548: next;
13549: }
13550: if (!exists($servers{$balancer})) {
13551: if (exists($currbalancer{$balancer})) {
13552: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 13553: }
1.160.6.7 raeburn 13554: next;
13555: }
13556: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
13557: push(@{$changes{'delete'}},$balancer);
13558: next;
13559: }
13560: if (!exists($currbalancer{$balancer})) {
13561: push(@{$changes{'add'}},$balancer);
13562: }
13563: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
13564: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
13565: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
13566: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13567: $saveloadbalancing = 1;
13568: }
13569: foreach my $sparetype (@sparestypes) {
13570: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
13571: my @offloadto;
13572: foreach my $target (@targets) {
13573: if (($servers{$target}) && ($target ne $balancer)) {
13574: if ($sparetype eq 'default') {
13575: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
13576: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 13577: }
13578: }
1.160.6.7 raeburn 13579: unless(grep(/^\Q$target\E$/,@offloadto)) {
13580: push(@offloadto,$target);
13581: }
1.150 raeburn 13582: }
13583: }
1.160.6.76 raeburn 13584: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
13585: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
13586: push(@offloadto,$balancer);
13587: }
13588: }
13589: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 13590: }
1.160.6.94 raeburn 13591: if ($env{'form.loadbalancing_cookie_'.$i}) {
13592: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
13593: if (exists($currbalancer{$balancer})) {
13594: unless ($currcookies{$balancer}) {
13595: $changes{'curr'}{$balancer}{'cookie'} = 1;
13596: }
13597: }
13598: } elsif (exists($currbalancer{$balancer})) {
13599: if ($currcookies{$balancer}) {
13600: $changes{'curr'}{$balancer}{'cookie'} = 1;
13601: }
13602: }
1.160.6.7 raeburn 13603: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 13604: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 13605: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
13606: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 13607: if (@targetdiffs > 0) {
1.160.6.7 raeburn 13608: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13609: }
1.160.6.7 raeburn 13610: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13611: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13612: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13613: }
13614: }
13615: }
13616: } else {
1.160.6.7 raeburn 13617: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
13618: foreach my $sparetype (@sparestypes) {
13619: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13620: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13621: $changes{'curr'}{$balancer}{'targets'} = 1;
13622: }
1.150 raeburn 13623: }
13624: }
1.160.6.7 raeburn 13625: }
1.150 raeburn 13626: }
13627: my $ishomedom;
1.160.6.7 raeburn 13628: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
13629: $ishomedom = 1;
1.150 raeburn 13630: }
13631: if (ref($alltypes) eq 'ARRAY') {
13632: foreach my $type (@{$alltypes}) {
13633: my $rule;
1.160.6.7 raeburn 13634: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 13635: (!$ishomedom)) {
1.160.6.7 raeburn 13636: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
13637: }
13638: if ($rule eq 'specific') {
1.160.6.55 raeburn 13639: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
13640: if (exists($servers{$specifiedhost})) {
13641: $rule = $specifiedhost;
13642: }
1.150 raeburn 13643: }
1.160.6.7 raeburn 13644: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
13645: if (ref($currrules{$balancer}) eq 'HASH') {
13646: if ($rule ne $currrules{$balancer}{$type}) {
13647: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13648: }
13649: } elsif ($rule ne '') {
1.160.6.7 raeburn 13650: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13651: }
13652: }
13653: }
1.160.6.7 raeburn 13654: }
13655: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
13656: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
13657: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
13658: $defaultshash{'loadbalancing'} = {};
13659: }
13660: my $putresult = &Apache::lonnet::put_dom('configuration',
13661: \%defaultshash,$dom);
13662: if ($putresult eq 'ok') {
13663: if (keys(%changes) > 0) {
1.160.6.54 raeburn 13664: my %toupdate;
1.160.6.7 raeburn 13665: if (ref($changes{'delete'}) eq 'ARRAY') {
13666: foreach my $balancer (sort(@{$changes{'delete'}})) {
13667: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 13668: $toupdate{$balancer} = 1;
1.150 raeburn 13669: }
1.160.6.7 raeburn 13670: }
13671: if (ref($changes{'add'}) eq 'ARRAY') {
13672: foreach my $balancer (sort(@{$changes{'add'}})) {
13673: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 13674: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 13675: }
13676: }
13677: if (ref($changes{'curr'}) eq 'HASH') {
13678: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 13679: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 13680: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
13681: if ($changes{'curr'}{$balancer}{'targets'}) {
13682: my %offloadstr;
13683: foreach my $sparetype (@sparestypes) {
13684: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13685: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13686: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13687: }
13688: }
1.150 raeburn 13689: }
1.160.6.7 raeburn 13690: if (keys(%offloadstr) == 0) {
13691: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 13692: } else {
1.160.6.7 raeburn 13693: my $showoffload;
13694: foreach my $sparetype (@sparestypes) {
13695: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
13696: if (defined($offloadstr{$sparetype})) {
13697: $showoffload .= $offloadstr{$sparetype};
13698: } else {
13699: $showoffload .= &mt('None');
13700: }
13701: $showoffload .= (' 'x3);
13702: }
13703: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 13704: }
13705: }
13706: }
1.160.6.7 raeburn 13707: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
13708: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
13709: foreach my $type (@{$alltypes}) {
13710: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
13711: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13712: my $balancetext;
13713: if ($rule eq '') {
13714: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 13715: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 13716: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
13717: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 13718: foreach my $sparetype (@sparestypes) {
13719: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13720: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13721: }
13722: }
1.160.6.55 raeburn 13723: foreach my $item (@{$alltypes}) {
13724: next if ($item =~ /^_LC_ipchange/);
13725: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
13726: if ($hasrule eq 'homeserver') {
13727: map { $toupdate{$_} = 1; } (keys(%libraryservers));
13728: } else {
13729: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
13730: if ($servers{$hasrule}) {
13731: $toupdate{$hasrule} = 1;
13732: }
13733: }
13734: }
13735: }
13736: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
13737: $balancetext = $ruletitles{$rule};
13738: } else {
13739: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13740: $balancetext = $ruletitles{'particular'}.' '.$receiver;
13741: if ($receiver) {
13742: $toupdate{$receiver};
13743: }
13744: }
13745: } else {
13746: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 13747: }
1.160.6.7 raeburn 13748: } else {
13749: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
13750: }
1.160.6.26 raeburn 13751: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 13752: }
13753: }
13754: }
13755: }
1.160.6.94 raeburn 13756: if ($changes{'curr'}{$balancer}{'cookie'}) {
13757: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
13758: $balancer).'</li>';
13759: }
1.160.6.54 raeburn 13760: if (keys(%toupdate)) {
13761: my %thismachine;
13762: my $updatedhere;
13763: my $cachetime = 60*60*24;
13764: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
13765: foreach my $lonhost (keys(%toupdate)) {
13766: if ($thismachine{$lonhost}) {
13767: unless ($updatedhere) {
13768: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
13769: $defaultshash{'loadbalancing'},
13770: $cachetime);
13771: $updatedhere = 1;
13772: }
13773: } else {
13774: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
13775: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
13776: }
13777: }
13778: }
1.150 raeburn 13779: }
1.160.6.7 raeburn 13780: }
13781: if ($resulttext ne '') {
13782: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 13783: } else {
13784: $resulttext = $nochgmsg;
13785: }
13786: } else {
1.160.6.7 raeburn 13787: $resulttext = $nochgmsg;
1.150 raeburn 13788: }
13789: } else {
1.160.6.7 raeburn 13790: $resulttext = '<span class="LC_error">'.
13791: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 13792: }
13793: } else {
1.160.6.7 raeburn 13794: $resulttext = $nochgmsg;
1.150 raeburn 13795: }
13796: return $resulttext;
13797: }
13798:
1.48 raeburn 13799: sub recurse_check {
13800: my ($chkcats,$categories,$depth,$name) = @_;
13801: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
13802: my $chg = 0;
13803: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
13804: my $category = $chkcats->[$depth]{$name}[$j];
13805: my $item;
13806: if ($category eq '') {
13807: $chg ++;
13808: } else {
13809: my $deeper = $depth + 1;
13810: $item = &escape($category).':'.&escape($name).':'.$depth;
13811: if ($chg) {
13812: $categories->{$item} -= $chg;
13813: }
13814: &recurse_check($chkcats,$categories,$deeper,$category);
13815: $deeper --;
13816: }
13817: }
13818: }
13819: return;
13820: }
13821:
13822: sub recurse_cat_deletes {
13823: my ($item,$coursecategories,$deletions) = @_;
13824: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13825: my $subdepth = $depth + 1;
13826: if (ref($coursecategories) eq 'HASH') {
13827: foreach my $subitem (keys(%{$coursecategories})) {
13828: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
13829: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
13830: delete($coursecategories->{$subitem});
13831: $deletions->{$subitem} = 1;
13832: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 13833: }
1.48 raeburn 13834: }
13835: }
13836: return;
13837: }
13838:
1.125 raeburn 13839: sub active_dc_picker {
1.160.6.16 raeburn 13840: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 13841: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 13842: my @domcoord = keys(%domcoords);
13843: if (keys(%currhash)) {
13844: foreach my $dc (keys(%currhash)) {
13845: unless (exists($domcoords{$dc})) {
13846: push(@domcoord,$dc);
13847: }
13848: }
13849: }
13850: @domcoord = sort(@domcoord);
13851: my $numdcs = scalar(@domcoord);
13852: my $rows = 0;
13853: my $table;
1.125 raeburn 13854: if ($numdcs > 1) {
1.160.6.16 raeburn 13855: $table = '<table>';
13856: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 13857: my $rem = $i%($numinrow);
13858: if ($rem == 0) {
13859: if ($i > 0) {
1.160.6.16 raeburn 13860: $table .= '</tr>';
1.125 raeburn 13861: }
1.160.6.16 raeburn 13862: $table .= '<tr>';
13863: $rows ++;
1.125 raeburn 13864: }
1.160.6.16 raeburn 13865: my $check = '';
13866: if ($inputtype eq 'radio') {
13867: if (keys(%currhash) == 0) {
13868: if (!$i) {
13869: $check = ' checked="checked"';
13870: }
13871: } elsif (exists($currhash{$domcoord[$i]})) {
13872: $check = ' checked="checked"';
13873: }
13874: } else {
13875: if (exists($currhash{$domcoord[$i]})) {
13876: $check = ' checked="checked"';
1.125 raeburn 13877: }
13878: }
1.160.6.16 raeburn 13879: if ($i == @domcoord - 1) {
1.125 raeburn 13880: my $colsleft = $numinrow - $rem;
13881: if ($colsleft > 1) {
1.160.6.16 raeburn 13882: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 13883: } else {
1.160.6.16 raeburn 13884: $table .= '<td class="LC_left_item">';
1.125 raeburn 13885: }
13886: } else {
1.160.6.16 raeburn 13887: $table .= '<td class="LC_left_item">';
13888: }
13889: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
13890: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
13891: $table .= '<span class="LC_nobreak"><label>'.
13892: '<input type="'.$inputtype.'" name="'.$name.'"'.
13893: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
13894: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 13895: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 13896: }
1.160.6.33 raeburn 13897: $table .= '</label></span></td>';
1.125 raeburn 13898: }
1.160.6.16 raeburn 13899: $table .= '</tr></table>';
13900: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 13901: my ($dcname,$dcdom) = split(':',$domcoord[0]);
13902: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 13903: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 13904: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 13905: if ($user ne $dcname.':'.$dcdom) {
13906: $table .= ' ('.$dcname.':'.$dcdom.')';
13907: }
1.160.6.16 raeburn 13908: } else {
13909: my $check;
13910: if (exists($currhash{$domcoord[0]})) {
13911: $check = ' checked="checked"';
13912: }
1.160.6.50 raeburn 13913: $table = '<span class="LC_nobreak"><label>'.
13914: '<input type="checkbox" name="'.$name.'" '.
13915: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 13916: if ($user ne $dcname.':'.$dcdom) {
13917: $table .= ' ('.$dcname.':'.$dcdom.')';
13918: }
13919: $table .= '</label></span>';
1.160.6.16 raeburn 13920: $rows ++;
13921: }
1.125 raeburn 13922: }
1.160.6.16 raeburn 13923: return ($numdcs,$table,$rows);
1.125 raeburn 13924: }
13925:
1.137 raeburn 13926: sub usersession_titles {
13927: return &Apache::lonlocal::texthash(
13928: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
13929: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 13930: spares => 'Servers offloaded to, when busy',
1.137 raeburn 13931: version => 'LON-CAPA version requirement',
1.138 raeburn 13932: excludedomain => 'Allow all, but exclude specific domains',
13933: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 13934: primary => 'Primary (checked first)',
1.154 raeburn 13935: default => 'Default',
1.137 raeburn 13936: );
13937: }
13938:
1.152 raeburn 13939: sub id_for_thisdom {
13940: my (%servers) = @_;
13941: my %altids;
13942: foreach my $server (keys(%servers)) {
13943: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
13944: if ($serverhome ne $server) {
13945: $altids{$serverhome} = $server;
13946: }
13947: }
13948: return %altids;
13949: }
13950:
1.150 raeburn 13951: sub count_servers {
13952: my ($currbalancer,%servers) = @_;
13953: my (@spares,$numspares);
13954: foreach my $lonhost (sort(keys(%servers))) {
13955: next if ($currbalancer eq $lonhost);
13956: push(@spares,$lonhost);
13957: }
13958: if ($currbalancer) {
13959: $numspares = scalar(@spares);
13960: } else {
13961: $numspares = scalar(@spares) - 1;
13962: }
13963: return ($numspares,@spares);
13964: }
13965:
13966: sub lonbalance_targets_js {
1.160.6.7 raeburn 13967: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13968: my $select = &mt('Select');
13969: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13970: if (ref($servers) eq 'HASH') {
13971: $alltargets = join("','",sort(keys(%{$servers})));
13972: my @homedoms;
13973: foreach my $server (sort(keys(%{$servers}))) {
13974: if (&Apache::lonnet::host_domain($server) eq $dom) {
13975: push(@homedoms,'1');
13976: } else {
13977: push(@homedoms,'0');
13978: }
13979: }
13980: $allishome = join("','",@homedoms);
13981: }
13982: if (ref($types) eq 'ARRAY') {
13983: if (@{$types} > 0) {
13984: @alltypes = @{$types};
13985: }
13986: }
13987: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13988: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 13989: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 13990: if (ref($settings) eq 'HASH') {
13991: %existing = %{$settings};
13992: }
13993: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 13994: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 13995: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13996: return <<"END";
13997:
13998: <script type="text/javascript">
13999: // <![CDATA[
14000:
1.160.6.7 raeburn 14001: currBalancers = new Array('$balancers');
14002:
14003: function toggleTargets(balnum) {
14004: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14005: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
14006: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
14007: var prevbalancer = prevhostitem.value;
14008: var baltotal = document.getElementById('loadbalancing_total').value;
14009: prevhostitem.value = balancer;
14010: if (prevbalancer != '') {
14011: var prevIdx = currBalancers.indexOf(prevbalancer);
14012: if (prevIdx != -1) {
14013: currBalancers.splice(prevIdx,1);
14014: }
14015: }
1.150 raeburn 14016: if (balancer == '') {
1.160.6.7 raeburn 14017: hideSpares(balnum);
1.150 raeburn 14018: } else {
1.160.6.7 raeburn 14019: var currIdx = currBalancers.indexOf(balancer);
14020: if (currIdx == -1) {
14021: currBalancers.push(balancer);
14022: }
1.150 raeburn 14023: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 14024: var ishomedom = homedoms[lonhostitem.selectedIndex];
14025: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 14026: }
1.160.6.7 raeburn 14027: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 14028: return;
14029: }
14030:
1.160.6.7 raeburn 14031: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 14032: var alltargets = new Array('$alltargets');
14033: var insttypes = new Array('$allinsttypes');
1.151 raeburn 14034: var offloadtypes = new Array('primary','default');
14035:
1.160.6.7 raeburn 14036: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
14037: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 14038:
1.151 raeburn 14039: for (var i=0; i<offloadtypes.length; i++) {
14040: var count = 0;
14041: for (var j=0; j<alltargets.length; j++) {
14042: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 14043: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
14044: item.value = alltargets[j];
14045: item.style.textAlign='left';
14046: item.style.textFace='normal';
14047: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
14048: if (currBalancers.indexOf(alltargets[j]) == -1) {
14049: item.disabled = '';
14050: } else {
14051: item.disabled = 'disabled';
14052: item.checked = false;
14053: }
1.151 raeburn 14054: count ++;
14055: }
1.150 raeburn 14056: }
14057: }
1.151 raeburn 14058: for (var k=0; k<insttypes.length; k++) {
14059: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 14060: if (ishomedom == 1) {
1.160.6.7 raeburn 14061: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14062: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14063: } else {
1.160.6.7 raeburn 14064: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14065: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 14066: }
14067: } else {
1.160.6.7 raeburn 14068: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
14069: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 14070: }
1.151 raeburn 14071: if ((insttypes[k] != '_LC_external') &&
14072: ((insttypes[k] != '_LC_internetdom') ||
14073: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 14074: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
14075: item.options.length = 0;
14076: item.options[0] = new Option("","",true,true);
14077: var idx = 0;
1.151 raeburn 14078: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 14079: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
14080: idx ++;
14081: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 14082: }
14083: }
14084: }
14085: }
14086: return;
14087: }
14088:
1.160.6.7 raeburn 14089: function hideSpares(balnum) {
1.150 raeburn 14090: var alltargets = new Array('$alltargets');
14091: var insttypes = new Array('$allinsttypes');
14092: var offloadtypes = new Array('primary','default');
14093:
1.160.6.7 raeburn 14094: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
14095: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 14096:
14097: var total = alltargets.length - 1;
14098: for (var i=0; i<offloadtypes; i++) {
14099: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 14100: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
14101: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
14102: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 14103: }
1.150 raeburn 14104: }
14105: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 14106: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
14107: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 14108: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 14109: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
14110: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 14111: }
14112: }
14113: return;
14114: }
14115:
1.160.6.7 raeburn 14116: function checkOffloads(item,balnum,type) {
1.150 raeburn 14117: var alltargets = new Array('$alltargets');
14118: var offloadtypes = new Array('primary','default');
14119: if (item.checked) {
14120: var total = alltargets.length - 1;
14121: var other;
14122: if (type == offloadtypes[0]) {
1.151 raeburn 14123: other = offloadtypes[1];
1.150 raeburn 14124: } else {
1.151 raeburn 14125: other = offloadtypes[0];
1.150 raeburn 14126: }
14127: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 14128: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 14129: if (server == item.value) {
1.160.6.7 raeburn 14130: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
14131: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 14132: }
14133: }
14134: }
14135: }
14136: return;
14137: }
14138:
1.160.6.7 raeburn 14139: function singleServerToggle(balnum,type) {
14140: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 14141: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 14142: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
14143: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14144:
14145: } else {
1.160.6.7 raeburn 14146: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
14147: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 14148: }
14149: return;
14150: }
14151:
1.160.6.7 raeburn 14152: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 14153: if (type == '_LC_external') {
1.160.6.26 raeburn 14154: return;
1.150 raeburn 14155: }
1.160.6.7 raeburn 14156: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 14157: for (var i=0; i<typesRules.length; i++) {
14158: if (formname.elements[typesRules[i]].checked) {
14159: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 14160: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
14161: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 14162: } else {
1.160.6.7 raeburn 14163: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
14164: }
14165: }
14166: }
14167: return;
14168: }
14169:
14170: function balancerDeleteChange(balnum) {
14171: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
14172: var baltotal = document.getElementById('loadbalancing_total').value;
14173: var addtarget;
14174: var removetarget;
14175: var action = 'delete';
14176: if (document.getElementById('loadbalancing_delete_'+balnum)) {
14177: var lonhost = hostitem.value;
14178: var currIdx = currBalancers.indexOf(lonhost);
14179: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
14180: if (currIdx != -1) {
14181: currBalancers.splice(currIdx,1);
14182: }
14183: addtarget = lonhost;
14184: } else {
14185: if (currIdx == -1) {
14186: currBalancers.push(lonhost);
14187: }
14188: removetarget = lonhost;
14189: action = 'undelete';
14190: }
14191: balancerChange(balnum,baltotal,action,addtarget,removetarget);
14192: }
14193: return;
14194: }
14195:
14196: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
14197: if (baltotal > 1) {
14198: var offloadtypes = new Array('primary','default');
14199: var alltargets = new Array('$alltargets');
14200: var insttypes = new Array('$allinsttypes');
14201: for (var i=0; i<baltotal; i++) {
14202: if (i != balnum) {
14203: for (var j=0; j<offloadtypes.length; j++) {
14204: var total = alltargets.length - 1;
14205: for (var k=0; k<total; k++) {
14206: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
14207: var server = serveritem.value;
14208: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14209: if (server == addtarget) {
14210: serveritem.disabled = '';
14211: }
14212: }
14213: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14214: if (server == removetarget) {
14215: serveritem.disabled = 'disabled';
14216: serveritem.checked = false;
14217: }
14218: }
14219: }
14220: }
14221: for (var j=0; j<insttypes.length; j++) {
14222: if (insttypes[j] != '_LC_external') {
14223: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
14224: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
14225: var currSel = singleserver.selectedIndex;
14226: var currVal = singleserver.options[currSel].value;
14227: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
14228: var numoptions = singleserver.options.length;
14229: var needsnew = 1;
14230: for (var k=0; k<numoptions; k++) {
14231: if (singleserver.options[k] == addtarget) {
14232: needsnew = 0;
14233: break;
14234: }
14235: }
14236: if (needsnew == 1) {
14237: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
14238: }
14239: }
14240: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
14241: singleserver.options.length = 0;
14242: if ((currVal) && (currVal != removetarget)) {
14243: singleserver.options[0] = new Option("","",false,false);
14244: } else {
14245: singleserver.options[0] = new Option("","",true,true);
14246: }
14247: var idx = 0;
14248: for (var m=0; m<alltargets.length; m++) {
14249: if (currBalancers.indexOf(alltargets[m]) == -1) {
14250: idx ++;
14251: if (currVal == alltargets[m]) {
14252: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
14253: } else {
14254: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
14255: }
14256: }
14257: }
14258: }
14259: }
14260: }
14261: }
1.150 raeburn 14262: }
14263: }
14264: }
14265: return;
14266: }
14267:
1.152 raeburn 14268: // ]]>
14269: </script>
14270:
14271: END
14272: }
14273:
14274: sub new_spares_js {
14275: my @sparestypes = ('primary','default');
14276: my $types = join("','",@sparestypes);
14277: my $select = &mt('Select');
14278: return <<"END";
14279:
14280: <script type="text/javascript">
14281: // <![CDATA[
14282:
14283: function updateNewSpares(formname,lonhost) {
14284: var types = new Array('$types');
14285: var include = new Array();
14286: var exclude = new Array();
14287: for (var i=0; i<types.length; i++) {
14288: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
14289: for (var j=0; j<spareboxes.length; j++) {
14290: if (formname.elements[spareboxes[j]].checked) {
14291: exclude.push(formname.elements[spareboxes[j]].value);
14292: } else {
14293: include.push(formname.elements[spareboxes[j]].value);
14294: }
14295: }
14296: }
14297: for (var i=0; i<types.length; i++) {
14298: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
14299: var selIdx = newSpare.selectedIndex;
14300: var currnew = newSpare.options[selIdx].value;
14301: var okSpares = new Array();
14302: for (var j=0; j<newSpare.options.length; j++) {
14303: var possible = newSpare.options[j].value;
14304: if (possible != '') {
14305: if (exclude.indexOf(possible) == -1) {
14306: okSpares.push(possible);
14307: } else {
14308: if (currnew == possible) {
14309: selIdx = 0;
14310: }
14311: }
14312: }
14313: }
14314: for (var k=0; k<include.length; k++) {
14315: if (okSpares.indexOf(include[k]) == -1) {
14316: okSpares.push(include[k]);
14317: }
14318: }
14319: okSpares.sort();
14320: newSpare.options.length = 0;
14321: if (selIdx == 0) {
14322: newSpare.options[0] = new Option("$select","",true,true);
14323: } else {
14324: newSpare.options[0] = new Option("$select","",false,false);
14325: }
14326: for (var m=0; m<okSpares.length; m++) {
14327: var idx = m+1;
14328: var selThis = 0;
14329: if (selIdx != 0) {
14330: if (okSpares[m] == currnew) {
14331: selThis = 1;
14332: }
14333: }
14334: if (selThis == 1) {
14335: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
14336: } else {
14337: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
14338: }
14339: }
14340: }
14341: return;
14342: }
14343:
14344: function checkNewSpares(lonhost,type) {
14345: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
14346: var chosen = newSpare.options[newSpare.selectedIndex].value;
14347: if (chosen != '') {
14348: var othertype;
14349: var othernewSpare;
14350: if (type == 'primary') {
14351: othernewSpare = document.getElementById('newspare_default_'+lonhost);
14352: }
14353: if (type == 'default') {
14354: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
14355: }
14356: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
14357: othernewSpare.selectedIndex = 0;
14358: }
14359: }
14360: return;
14361: }
14362:
14363: // ]]>
14364: </script>
14365:
14366: END
14367:
14368: }
14369:
14370: sub common_domprefs_js {
14371: return <<"END";
14372:
14373: <script type="text/javascript">
14374: // <![CDATA[
14375:
1.150 raeburn 14376: function getIndicesByName(formname,item) {
1.152 raeburn 14377: var group = new Array();
1.150 raeburn 14378: for (var i=0;i<formname.elements.length;i++) {
14379: if (formname.elements[i].name == item) {
1.152 raeburn 14380: group.push(formname.elements[i].id);
1.150 raeburn 14381: }
14382: }
1.152 raeburn 14383: return group;
1.150 raeburn 14384: }
14385:
14386: // ]]>
14387: </script>
14388:
14389: END
1.152 raeburn 14390:
1.150 raeburn 14391: }
14392:
1.160.6.5 raeburn 14393: sub recaptcha_js {
14394: my %lt = &captcha_phrases();
14395: return <<"END";
14396:
14397: <script type="text/javascript">
14398: // <![CDATA[
14399:
14400: function updateCaptcha(caller,context) {
14401: var privitem;
14402: var pubitem;
14403: var privtext;
14404: var pubtext;
1.160.6.69 raeburn 14405: var versionitem;
14406: var versiontext;
1.160.6.5 raeburn 14407: if (document.getElementById(context+'_recaptchapub')) {
14408: pubitem = document.getElementById(context+'_recaptchapub');
14409: } else {
14410: return;
14411: }
14412: if (document.getElementById(context+'_recaptchapriv')) {
14413: privitem = document.getElementById(context+'_recaptchapriv');
14414: } else {
14415: return;
14416: }
14417: if (document.getElementById(context+'_recaptchapubtxt')) {
14418: pubtext = document.getElementById(context+'_recaptchapubtxt');
14419: } else {
14420: return;
14421: }
14422: if (document.getElementById(context+'_recaptchaprivtxt')) {
14423: privtext = document.getElementById(context+'_recaptchaprivtxt');
14424: } else {
14425: return;
14426: }
1.160.6.69 raeburn 14427: if (document.getElementById(context+'_recaptchaversion')) {
14428: versionitem = document.getElementById(context+'_recaptchaversion');
14429: } else {
14430: return;
14431: }
14432: if (document.getElementById(context+'_recaptchavertxt')) {
14433: versiontext = document.getElementById(context+'_recaptchavertxt');
14434: } else {
14435: return;
14436: }
1.160.6.5 raeburn 14437: if (caller.checked) {
14438: if (caller.value == 'recaptcha') {
14439: pubitem.type = 'text';
14440: privitem.type = 'text';
14441: pubitem.size = '40';
14442: privitem.size = '40';
14443: pubtext.innerHTML = "$lt{'pub'}";
14444: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 14445: versionitem.type = 'text';
14446: versionitem.size = '3';
14447: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 14448: } else {
14449: pubitem.type = 'hidden';
14450: privitem.type = 'hidden';
1.160.6.69 raeburn 14451: versionitem.type = 'hidden';
1.160.6.5 raeburn 14452: pubtext.innerHTML = '';
14453: privtext.innerHTML = '';
1.160.6.69 raeburn 14454: versiontext.innerHTML = '';
1.160.6.5 raeburn 14455: }
14456: }
14457: return;
14458: }
14459:
14460: // ]]>
14461: </script>
14462:
14463: END
14464:
14465: }
14466:
1.160.6.40 raeburn 14467: sub toggle_display_js {
1.160.6.16 raeburn 14468: return <<"END";
14469:
14470: <script type="text/javascript">
14471: // <![CDATA[
14472:
1.160.6.40 raeburn 14473: function toggleDisplay(domForm,caller) {
14474: if (document.getElementById(caller)) {
14475: var divitem = document.getElementById(caller);
14476: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 14477: var checkval = 1;
14478: var dispval = 'block';
1.160.6.93 raeburn 14479: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 14480: if (caller == 'emailoptions') {
14481: optionsElement = domForm.cancreate_email;
14482: }
1.160.6.57 raeburn 14483: if (caller == 'studentsubmission') {
14484: optionsElement = domForm.postsubmit;
14485: }
1.160.6.64 raeburn 14486: if (caller == 'cloneinstcode') {
14487: optionsElement = domForm.canclone;
14488: checkval = 'instcode';
14489: }
1.160.6.93 raeburn 14490: if (selfcreateRegExp.test(caller)) {
14491: optionsElement = domForm.elements[caller];
14492: checkval = 'other';
14493: dispval = 'inline'
14494: }
1.160.6.40 raeburn 14495: if (optionsElement.length) {
1.160.6.16 raeburn 14496: var currval;
1.160.6.40 raeburn 14497: for (var i=0; i<optionsElement.length; i++) {
14498: if (optionsElement[i].checked) {
14499: currval = optionsElement[i].value;
1.160.6.16 raeburn 14500: }
14501: }
1.160.6.64 raeburn 14502: if (currval == checkval) {
14503: divitem.style.display = dispval;
1.160.6.16 raeburn 14504: } else {
1.160.6.40 raeburn 14505: divitem.style.display = 'none';
1.160.6.16 raeburn 14506: }
14507: }
14508: }
14509: return;
14510: }
14511:
14512: // ]]>
14513: </script>
14514:
14515: END
14516:
14517: }
14518:
1.160.6.5 raeburn 14519: sub captcha_phrases {
14520: return &Apache::lonlocal::texthash (
14521: priv => 'Private key',
14522: pub => 'Public key',
14523: original => 'original (CAPTCHA)',
14524: recaptcha => 'successor (ReCAPTCHA)',
14525: notused => 'unused',
1.160.6.69 raeburn 14526: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 14527: );
14528: }
14529:
1.160.6.24 raeburn 14530: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 14531: my ($dom,$cachekeys) = @_;
14532: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 14533: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14534: my %thismachine;
14535: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.92 raeburn 14536: my @posscached = ('domainconfig','domdefaults','usersessions','directorysrch','cats');
1.160.6.61 raeburn 14537: if (keys(%servers)) {
1.160.6.24 raeburn 14538: foreach my $server (keys(%servers)) {
14539: next if ($thismachine{$server});
1.160.6.27 raeburn 14540: my @cached;
14541: foreach my $name (@posscached) {
14542: if ($cachekeys->{$name}) {
14543: push(@cached,&escape($name).':'.&escape($dom));
14544: }
14545: }
14546: if (@cached) {
14547: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
14548: }
1.160.6.24 raeburn 14549: }
14550: }
14551: return;
14552: }
14553:
1.3 raeburn 14554: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>