Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.89
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.89! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.88 2018/09/14 22:43:14 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',
268: col2 => 'Assignable to e-mail usernames'}],
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'},
350: {col1 => 'Self-creation with e-mail as username',
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.95 www 366: { text => 'Bubblesheet format file',
1.67 raeburn 367: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 368: header => [ {col1 => 'Item',
369: col2 => '',
370: }],
1.160.6.37 raeburn 371: print => \&print_scantron,
372: modify => \&modify_scantron,
1.46 raeburn 373: },
1.86 raeburn 374: 'requestcourses' =>
375: {text => 'Request creation of courses',
376: help => 'Domain_Configuration_Request_Courses',
377: header => [{col1 => 'User affiliation',
1.102 raeburn 378: col2 => 'Availability/Processing of requests',},
379: {col1 => 'Setting',
1.160.6.30 raeburn 380: col2 => 'Value'},
381: {col1 => 'Available textbooks',
1.160.6.39 raeburn 382: col2 => ''},
1.160.6.46 raeburn 383: {col1 => 'Available templates',
384: col2 => ''},
1.160.6.39 raeburn 385: {col1 => 'Validation (not official courses)',
386: col2 => 'Value'},],
1.160.6.37 raeburn 387: print => \&print_quotas,
388: modify => \&modify_quotas,
1.86 raeburn 389: },
1.160.6.5 raeburn 390: 'requestauthor' =>
1.160.6.34 raeburn 391: {text => 'Request Authoring Space',
1.160.6.5 raeburn 392: help => 'Domain_Configuration_Request_Author',
393: header => [{col1 => 'User affiliation',
394: col2 => 'Availability/Processing of requests',},
395: {col1 => 'Setting',
396: col2 => 'Value'}],
1.160.6.37 raeburn 397: print => \&print_quotas,
398: modify => \&modify_quotas,
1.160.6.5 raeburn 399: },
1.69 raeburn 400: 'coursecategories' =>
1.120 raeburn 401: { text => 'Cataloging of courses/communities',
1.67 raeburn 402: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 403: header => [{col1 => 'Catalog type/availability',
404: col2 => '',},
405: {col1 => 'Category settings for standard catalog',
1.57 raeburn 406: col2 => '',},
407: {col1 => 'Categories',
408: col2 => '',
409: }],
1.160.6.37 raeburn 410: print => \&print_coursecategories,
411: modify => \&modify_coursecategories,
1.69 raeburn 412: },
413: 'serverstatuses' =>
1.77 raeburn 414: {text => 'Access to server status pages',
1.69 raeburn 415: help => 'Domain_Configuration_Server_Status',
416: header => [{col1 => 'Status Page',
417: col2 => 'Other named users',
418: col3 => 'Specific IPs',
419: }],
1.160.6.37 raeburn 420: print => \&print_serverstatuses,
421: modify => \&modify_serverstatuses,
1.69 raeburn 422: },
1.160.6.73 raeburn 423: 'helpsettings' =>
424: {text => 'Support settings',
425: help => 'Domain_Configuration_Help_Settings',
426: header => [{col1 => 'Help Page Settings (logged-in users)',
427: col2 => 'Value'},
428: {col1 => 'Helpdesk Roles',
429: col2 => 'Settings'},],
430: print => \&print_helpsettings,
431: modify => \&modify_helpsettings,
432: },
1.160.6.39 raeburn 433: 'coursedefaults' =>
1.160.6.16 raeburn 434: {text => 'Course/Community defaults',
435: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 436: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
437: col2 => 'Value',},
438: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 439: col2 => 'Value',},],
1.160.6.37 raeburn 440: print => \&print_coursedefaults,
441: modify => \&modify_coursedefaults,
442: },
1.160.6.39 raeburn 443: 'selfenrollment' =>
1.160.6.37 raeburn 444: {text => 'Self-enrollment in Course/Community',
445: help => 'Domain_Configuration_Selfenrollment',
446: header => [{col1 => 'Configuration Rights',
447: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
448: {col1 => 'Defaults',
449: col2 => 'Value'},
450: {col1 => 'Self-enrollment validation (optional)',
451: col2 => 'Value'},],
452: print => \&print_selfenrollment,
453: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 454: },
1.141 raeburn 455: 'usersessions' =>
1.145 raeburn 456: {text => 'User session hosting/offloading',
1.137 raeburn 457: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 458: header => [{col1 => 'Domain server',
459: col2 => 'Servers to offload sessions to when busy'},
460: {col1 => 'Hosting of users from other domains',
1.137 raeburn 461: col2 => 'Rules'},
462: {col1 => "Hosting domain's own users elsewhere",
463: col2 => 'Rules'}],
1.160.6.37 raeburn 464: print => \&print_usersessions,
465: modify => \&modify_usersessions,
1.137 raeburn 466: },
1.160.6.78 raeburn 467: 'loadbalancing' =>
1.160.6.7 raeburn 468: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 469: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 470: header => [{col1 => 'Balancers',
1.150 raeburn 471: col2 => 'Default destinations',
1.160.6.13 raeburn 472: col3 => 'User affiliation',
1.150 raeburn 473: col4 => 'Overrides'},
474: ],
1.160.6.37 raeburn 475: print => \&print_loadbalancing,
476: modify => \&modify_loadbalancing,
1.150 raeburn 477: },
1.3 raeburn 478: );
1.110 raeburn 479: if (keys(%servers) > 1) {
480: $prefs{'login'} = { text => 'Log-in page options',
481: help => 'Domain_Configuration_Login_Page',
482: header => [{col1 => 'Log-in Service',
483: col2 => 'Server Setting',},
484: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 485: col2 => ''},
486: {col1 => 'Log-in Help',
1.160.6.56 raeburn 487: col2 => 'Value'},
488: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 489: col2 => 'Value'}],
1.160.6.37 raeburn 490: print => \&print_login,
491: modify => \&modify_login,
1.110 raeburn 492: };
493: }
1.160.6.13 raeburn 494:
1.6 raeburn 495: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 496: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 497: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 498: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 499: text=>"Settings to display/modify"});
1.9 raeburn 500: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 501:
1.3 raeburn 502: if ($phase eq 'process') {
1.160.6.27 raeburn 503: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
504: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 505: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 506: $r->rflush();
1.160.6.27 raeburn 507: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 508: }
1.30 raeburn 509: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 510: my $js = &recaptcha_js().
1.160.6.40 raeburn 511: &toggle_display_js();
1.160.6.7 raeburn 512: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 513: my ($othertitle,$usertypes,$types) =
514: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 515: $js .= &lonbalance_targets_js($dom,$types,\%servers,
516: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 517: &new_spares_js().
518: &common_domprefs_js().
519: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 520: }
1.160.6.30 raeburn 521: if (grep(/^requestcourses$/,@actions)) {
522: my $javascript_validations;
523: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
524: $js .= <<END;
525: <script type="text/javascript">
526: $javascript_validations
527: </script>
528: $coursebrowserjs
529: END
530: }
1.160.6.78 raeburn 531: if (grep(/^contacts$/,@actions)) {
532: $js .= &contacts_javascript();
533: }
1.150 raeburn 534: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 535: } else {
1.160.6.11 raeburn 536: # check if domconfig user exists for the domain.
537: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 538: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 539: &config_check($dom,$confname,$servadm);
540: unless ($configuserok eq 'ok') {
541: &Apache::lonconfigsettings::print_header($r,$phase,$context);
542: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
543: $confname).
544: '<br />'
545: );
546: if ($switchserver) {
547: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
548: '<br />'.
549: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
550: '<br />'.
551: &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).
552: '<br />'.
553: &mt('To do that now, use the following link: [_1]',$switchserver)
554: );
555: } else {
556: $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.').
557: '<br />'.
558: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
559: );
560: }
561: $r->print(&Apache::loncommon::end_page());
562: return OK;
563: }
1.21 raeburn 564: if (keys(%domconfig) == 0) {
565: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 566: my @ids=&Apache::lonnet::current_machine_ids();
567: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 568: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 569: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 570: my $custom_img_count = 0;
571: foreach my $img (@loginimages) {
572: if ($designhash{$dom.'.login.'.$img} ne '') {
573: $custom_img_count ++;
574: }
575: }
576: foreach my $role (@roles) {
577: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
578: $custom_img_count ++;
579: }
580: }
581: if ($custom_img_count > 0) {
1.94 raeburn 582: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 583: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 584: $r->print(
585: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
586: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
587: &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 />'.
588: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
589: if ($switch_server) {
1.30 raeburn 590: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 591: }
1.91 raeburn 592: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 593: return OK;
594: }
595: }
596: }
1.91 raeburn 597: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 598: }
599: return OK;
600: }
601:
602: sub process_changes {
1.160.6.24 raeburn 603: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 604: my %domconfig;
605: if (ref($values) eq 'HASH') {
606: %domconfig = %{$values};
607: }
1.3 raeburn 608: my $output;
609: if ($action eq 'login') {
1.160.6.24 raeburn 610: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 611: } elsif ($action eq 'rolecolors') {
1.9 raeburn 612: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 613: $lastactref,%domconfig);
1.3 raeburn 614: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 615: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 616: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 617: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 618: } elsif ($action eq 'autoupdate') {
619: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 620: } elsif ($action eq 'autocreate') {
621: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 622: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 623: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 624: } elsif ($action eq 'usercreation') {
1.28 raeburn 625: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 626: } elsif ($action eq 'selfcreation') {
627: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 628: } elsif ($action eq 'usermodification') {
629: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 630: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 631: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 632: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 633: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 634: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 635: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 636: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 637: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 638: } elsif ($action eq 'serverstatuses') {
639: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 640: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 641: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 642: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 643: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 644: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 645: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 646: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 647: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 648: } elsif ($action eq 'selfenrollment') {
649: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 650: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 651: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 652: } elsif ($action eq 'loadbalancing') {
653: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 654: }
655: return $output;
656: }
657:
658: sub print_config_box {
1.9 raeburn 659: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 660: my $rowtotal = 0;
1.49 raeburn 661: my $output;
662: if ($action eq 'coursecategories') {
663: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 664: } elsif ($action eq 'defaults') {
665: $output = &defaults_javascript($settings);
1.160.6.73 raeburn 666: } elsif ($action eq 'helpsettings') {
667: my (%privs,%levelscurrent);
668: my %full=();
669: my %levels=(
670: course => {},
671: domain => {},
672: system => {},
673: );
674: my $context = 'domain';
675: my $crstype = 'Course';
676: my $formname = 'display';
677: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
678: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
679: $output =
680: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
681: \@templateroles);
1.91 raeburn 682: }
1.160.6.40 raeburn 683: $output .=
1.30 raeburn 684: '<table class="LC_nested_outer">
1.3 raeburn 685: <tr>
1.66 raeburn 686: <th align="left" valign="middle"><span class="LC_nobreak">'.
687: &mt($item->{text}).' '.
688: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
689: '</tr>';
1.30 raeburn 690: $rowtotal ++;
1.110 raeburn 691: my $numheaders = 1;
692: if (ref($item->{'header'}) eq 'ARRAY') {
693: $numheaders = scalar(@{$item->{'header'}});
694: }
695: if ($numheaders > 1) {
1.64 raeburn 696: my $colspan = '';
1.145 raeburn 697: my $rightcolspan = '';
1.160.6.42 raeburn 698: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 699: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 700: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 701: $colspan = ' colspan="2"';
702: }
1.145 raeburn 703: if ($action eq 'usersessions') {
704: $rightcolspan = ' colspan="3"';
705: }
1.30 raeburn 706: $output .= '
1.3 raeburn 707: <tr>
708: <td>
709: <table class="LC_nested">
710: <tr class="LC_info_row">
1.59 bisitz 711: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 712: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 713: </tr>';
1.69 raeburn 714: $rowtotal ++;
1.160.6.37 raeburn 715: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 716: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 717: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78 raeburn 718: ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37 raeburn 719: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 720: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 721: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 722: } elsif ($action eq 'login') {
1.160.6.56 raeburn 723: if ($numheaders == 4) {
1.160.6.5 raeburn 724: $colspan = ' colspan="2"';
725: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
726: } else {
727: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
728: }
1.160.6.37 raeburn 729: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 730: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 731: } elsif ($action eq 'rolecolors') {
1.30 raeburn 732: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 733: }
1.30 raeburn 734: $output .= '
1.6 raeburn 735: </table>
736: </td>
737: </tr>
738: <tr>
739: <td>
740: <table class="LC_nested">
741: <tr class="LC_info_row">
1.160.6.37 raeburn 742: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 743: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 744: </tr>';
745: $rowtotal ++;
1.160.6.37 raeburn 746: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
747: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 748: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.80 raeburn 749: ($action eq 'contacts') || ($action eq 'defaults')) {
1.160.6.42 raeburn 750: if ($action eq 'coursecategories') {
751: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
752: $colspan = ' colspan="2"';
753: } else {
754: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
755: }
756: $output .= '
1.63 raeburn 757: </table>
758: </td>
759: </tr>
760: <tr>
761: <td>
762: <table class="LC_nested">
763: <tr class="LC_info_row">
764: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 765: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 766: </tr>'."\n";
767: if ($action eq 'coursecategories') {
768: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
769: } else {
770: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
771: }
1.63 raeburn 772: $rowtotal ++;
1.160.6.57 raeburn 773: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 774: ($action eq 'defaults') || ($action eq 'directorysrch') ||
775: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 776: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 777: } elsif ($action eq 'login') {
1.160.6.56 raeburn 778: if ($numheaders == 4) {
1.160.6.5 raeburn 779: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
780: </table>
781: </td>
782: </tr>
783: <tr>
784: <td>
785: <table class="LC_nested">
786: <tr class="LC_info_row">
787: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 788: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 789: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
790: $rowtotal ++;
791: } else {
792: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
793: }
1.160.6.56 raeburn 794: $output .= '
795: </table>
796: </td>
797: </tr>
798: <tr>
799: <td>
800: <table class="LC_nested">
801: <tr class="LC_info_row">';
802: if ($numheaders == 4) {
803: $output .= '
804: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
805: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
806: </tr>';
807: } else {
808: $output .= '
809: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
810: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
811: </tr>';
812: }
813: $rowtotal ++;
814: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 815: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 816: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
817: $rowtotal ++;
818: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 819: </table>
820: </td>
821: </tr>
822: <tr>
823: <td>
824: <table class="LC_nested">
825: <tr class="LC_info_row">
826: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
827: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 828: &textbookcourses_javascript($settings).
829: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
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'}->[3]->{'col1'}).'</td>
838: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
839: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 840: </table>
841: </td>
842: </tr>
843: <tr>
844: <td>
845: <table class="LC_nested">
846: <tr class="LC_info_row">
1.160.6.46 raeburn 847: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
848: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 849: </tr>'.
850: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 851: } elsif ($action eq 'requestauthor') {
852: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 853: $rowtotal ++;
1.122 jms 854: } elsif ($action eq 'rolecolors') {
1.30 raeburn 855: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 856: </table>
857: </td>
858: </tr>
859: <tr>
860: <td>
861: <table class="LC_nested">
862: <tr class="LC_info_row">
1.69 raeburn 863: <td class="LC_left_item"'.$colspan.' valign="top">'.
864: &mt($item->{'header'}->[2]->{'col1'}).'</td>
865: <td class="LC_right_item" valign="top">'.
866: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 867: </tr>'.
1.30 raeburn 868: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 869: </table>
870: </td>
871: </tr>
872: <tr>
873: <td>
874: <table class="LC_nested">
875: <tr class="LC_info_row">
1.59 bisitz 876: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
877: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 878: </tr>'.
1.30 raeburn 879: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
880: $rowtotal += 2;
1.6 raeburn 881: }
1.3 raeburn 882: } else {
1.30 raeburn 883: $output .= '
1.3 raeburn 884: <tr>
885: <td>
886: <table class="LC_nested">
1.30 raeburn 887: <tr class="LC_info_row">';
1.160.6.72 raeburn 888: if ($action eq 'login') {
1.30 raeburn 889: $output .= '
1.59 bisitz 890: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 891: } elsif ($action eq 'serverstatuses') {
892: $output .= '
893: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
894: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
895:
1.6 raeburn 896: } else {
1.30 raeburn 897: $output .= '
1.69 raeburn 898: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
899: }
1.72 raeburn 900: if (defined($item->{'header'}->[0]->{'col3'})) {
901: $output .= '<td class="LC_left_item" valign="top">'.
902: &mt($item->{'header'}->[0]->{'col2'});
903: if ($action eq 'serverstatuses') {
904: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
905: }
1.69 raeburn 906: } else {
907: $output .= '<td class="LC_right_item" valign="top">'.
908: &mt($item->{'header'}->[0]->{'col2'});
909: }
910: $output .= '</td>';
911: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 912: if (defined($item->{'header'}->[0]->{'col4'})) {
913: $output .= '<td class="LC_left_item" valign="top">'.
914: &mt($item->{'header'}->[0]->{'col3'});
915: } else {
916: $output .= '<td class="LC_right_item" valign="top">'.
917: &mt($item->{'header'}->[0]->{'col3'});
918: }
1.69 raeburn 919: if ($action eq 'serverstatuses') {
920: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
921: }
922: $output .= '</td>';
1.6 raeburn 923: }
1.150 raeburn 924: if ($item->{'header'}->[0]->{'col4'}) {
925: $output .= '<td class="LC_right_item" valign="top">'.
926: &mt($item->{'header'}->[0]->{'col4'});
927: }
1.69 raeburn 928: $output .= '</tr>';
1.48 raeburn 929: $rowtotal ++;
1.160.6.5 raeburn 930: if ($action eq 'quotas') {
1.86 raeburn 931: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 932: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.78 raeburn 933: ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 934: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 935: } elsif ($action eq 'scantron') {
936: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 937: }
1.3 raeburn 938: }
1.30 raeburn 939: $output .= '
1.3 raeburn 940: </table>
941: </td>
942: </tr>
1.30 raeburn 943: </table><br />';
944: return ($output,$rowtotal);
1.1 raeburn 945: }
946:
1.3 raeburn 947: sub print_login {
1.160.6.5 raeburn 948: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 949: my ($css_class,$datatable);
1.6 raeburn 950: my %choices = &login_choices();
1.110 raeburn 951:
1.160.6.5 raeburn 952: if ($caller eq 'service') {
1.149 raeburn 953: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 954: my $choice = $choices{'disallowlogin'};
955: $css_class = ' class="LC_odd_row"';
1.128 raeburn 956: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 957: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 958: '<th>'.$choices{'server'}.'</th>'.
959: '<th>'.$choices{'serverpath'}.'</th>'.
960: '<th>'.$choices{'custompath'}.'</th>'.
961: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 962: my %disallowed;
963: if (ref($settings) eq 'HASH') {
964: if (ref($settings->{'loginvia'}) eq 'HASH') {
965: %disallowed = %{$settings->{'loginvia'}};
966: }
967: }
968: foreach my $lonhost (sort(keys(%servers))) {
969: my $direct = 'selected="selected"';
1.128 raeburn 970: if (ref($disallowed{$lonhost}) eq 'HASH') {
971: if ($disallowed{$lonhost}{'server'} ne '') {
972: $direct = '';
973: }
1.110 raeburn 974: }
1.115 raeburn 975: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 976: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 977: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
978: '</option>';
1.160.6.13 raeburn 979: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 980: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 981: my $selected = '';
1.128 raeburn 982: if (ref($disallowed{$lonhost}) eq 'HASH') {
983: if ($hostid eq $disallowed{$lonhost}{'server'}) {
984: $selected = 'selected="selected"';
985: }
1.110 raeburn 986: }
987: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
988: $servers{$hostid}.'</option>';
989: }
1.128 raeburn 990: $datatable .= '</select></td>'.
991: '<td><select name="'.$lonhost.'_serverpath">';
992: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
993: my $pathname = $path;
994: if ($path eq 'custom') {
995: $pathname = &mt('Custom Path').' ->';
996: }
997: my $selected = '';
998: if (ref($disallowed{$lonhost}) eq 'HASH') {
999: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1000: $selected = 'selected="selected"';
1001: }
1002: } elsif ($path eq '') {
1003: $selected = 'selected="selected"';
1004: }
1005: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1006: }
1007: $datatable .= '</select></td>';
1008: my ($custom,$exempt);
1009: if (ref($disallowed{$lonhost}) eq 'HASH') {
1010: $custom = $disallowed{$lonhost}{'custompath'};
1011: $exempt = $disallowed{$lonhost}{'exempt'};
1012: }
1013: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1014: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1015: '</tr>';
1.110 raeburn 1016: }
1017: $datatable .= '</table></td></tr>';
1018: return $datatable;
1.160.6.5 raeburn 1019: } elsif ($caller eq 'page') {
1020: my %defaultchecked = (
1021: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1022: 'helpdesk' => 'on',
1.160.6.5 raeburn 1023: 'adminmail' => 'off',
1024: 'newuser' => 'off',
1025: );
1.160.6.14 raeburn 1026: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1027: my (%checkedon,%checkedoff);
1.42 raeburn 1028: foreach my $item (@toggles) {
1.160.6.5 raeburn 1029: if ($defaultchecked{$item} eq 'on') {
1030: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1031: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1032: } elsif ($defaultchecked{$item} eq 'off') {
1033: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1034: $checkedon{$item} = ' ';
1035: }
1.1 raeburn 1036: }
1.160.6.5 raeburn 1037: my @images = ('img','logo','domlogo','login');
1038: my @logintext = ('textcol','bgcol');
1039: my @bgs = ('pgbg','mainbg','sidebg');
1040: my @links = ('link','alink','vlink');
1041: my %designhash = &Apache::loncommon::get_domainconf($dom);
1042: my %defaultdesign = %Apache::loncommon::defaultdesign;
1043: my (%is_custom,%designs);
1044: my %defaults = (
1045: font => $defaultdesign{'login.font'},
1046: );
1.6 raeburn 1047: foreach my $item (@images) {
1.160.6.5 raeburn 1048: $defaults{$item} = $defaultdesign{'login.'.$item};
1049: $defaults{'showlogo'}{$item} = 1;
1050: }
1051: foreach my $item (@bgs) {
1052: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1053: }
1.41 raeburn 1054: foreach my $item (@logintext) {
1.160.6.5 raeburn 1055: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1056: }
1.160.6.5 raeburn 1057: foreach my $item (@links) {
1058: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1059: }
1.160.6.5 raeburn 1060: if (ref($settings) eq 'HASH') {
1061: foreach my $item (@toggles) {
1062: if ($settings->{$item} eq '1') {
1063: $checkedon{$item} = ' checked="checked" ';
1064: $checkedoff{$item} = ' ';
1065: } elsif ($settings->{$item} eq '0') {
1066: $checkedoff{$item} = ' checked="checked" ';
1067: $checkedon{$item} = ' ';
1068: }
1.6 raeburn 1069: }
1.160.6.5 raeburn 1070: foreach my $item (@images) {
1071: if (defined($settings->{$item})) {
1072: $designs{$item} = $settings->{$item};
1073: $is_custom{$item} = 1;
1074: }
1075: if (defined($settings->{'showlogo'}{$item})) {
1076: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1077: }
1078: }
1079: foreach my $item (@logintext) {
1080: if ($settings->{$item} ne '') {
1081: $designs{'logintext'}{$item} = $settings->{$item};
1082: $is_custom{$item} = 1;
1083: }
1084: }
1085: if ($settings->{'font'} ne '') {
1086: $designs{'font'} = $settings->{'font'};
1087: $is_custom{'font'} = 1;
1088: }
1089: foreach my $item (@bgs) {
1090: if ($settings->{$item} ne '') {
1091: $designs{'bgs'}{$item} = $settings->{$item};
1092: $is_custom{$item} = 1;
1093: }
1094: }
1095: foreach my $item (@links) {
1096: if ($settings->{$item} ne '') {
1097: $designs{'links'}{$item} = $settings->{$item};
1098: $is_custom{$item} = 1;
1099: }
1100: }
1101: } else {
1102: if ($designhash{$dom.'.login.font'} ne '') {
1103: $designs{'font'} = $designhash{$dom.'.login.font'};
1104: $is_custom{'font'} = 1;
1105: }
1106: foreach my $item (@images) {
1107: if ($designhash{$dom.'.login.'.$item} ne '') {
1108: $designs{$item} = $designhash{$dom.'.login.'.$item};
1109: $is_custom{$item} = 1;
1110: }
1111: }
1112: foreach my $item (@bgs) {
1113: if ($designhash{$dom.'.login.'.$item} ne '') {
1114: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1115: $is_custom{$item} = 1;
1116: }
1117: }
1118: foreach my $item (@links) {
1119: if ($designhash{$dom.'.login.'.$item} ne '') {
1120: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1121: $is_custom{$item} = 1;
1122: }
1.6 raeburn 1123: }
1124: }
1.160.6.5 raeburn 1125: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1126: logo => 'Institution Logo',
1127: domlogo => 'Domain Logo',
1128: login => 'Login box');
1129: my $itemcount = 1;
1130: foreach my $item (@toggles) {
1131: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1132: $datatable .=
1133: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1134: '</td><td>'.
1135: '<span class="LC_nobreak"><label><input type="radio" name="'.
1136: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1137: '</label> <label><input type="radio" name="'.$item.'"'.
1138: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1139: '</tr>';
1140: $itemcount ++;
1.6 raeburn 1141: }
1.160.6.5 raeburn 1142: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1143: $datatable .= '</tr></table></td></tr>';
1144: } elsif ($caller eq 'help') {
1145: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1146: my $switchserver = &check_switchserver($dom,$confname);
1147: my $itemcount = 1;
1148: $defaulturl = '/adm/loginproblems.html';
1149: $defaulttype = 'default';
1150: %lt = &Apache::lonlocal::texthash (
1151: del => 'Delete?',
1152: rep => 'Replace:',
1153: upl => 'Upload:',
1154: default => 'Default',
1155: custom => 'Custom',
1156: );
1157: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1158: my @currlangs;
1159: if (ref($settings) eq 'HASH') {
1160: if (ref($settings->{'helpurl'}) eq 'HASH') {
1161: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1162: next if ($settings->{'helpurl'}{$key} eq '');
1163: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1164: $type{$key} = 'custom';
1165: unless ($key eq 'nolang') {
1166: push(@currlangs,$key);
1167: }
1168: }
1169: } elsif ($settings->{'helpurl'} ne '') {
1170: $type{'nolang'} = 'custom';
1171: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1172: }
1173: }
1.160.6.5 raeburn 1174: foreach my $lang ('nolang',sort(@currlangs)) {
1175: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1176: $datatable .= '<tr'.$css_class.'>';
1177: if ($url{$lang} eq '') {
1178: $url{$lang} = $defaulturl;
1179: }
1180: if ($type{$lang} eq '') {
1181: $type{$lang} = $defaulttype;
1182: }
1183: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1184: if ($lang eq 'nolang') {
1185: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1186: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1187: } else {
1188: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1189: $langchoices{$lang},
1190: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1191: }
1192: $datatable .= '</span></td>'."\n".
1193: '<td class="LC_left_item">';
1194: if ($type{$lang} eq 'custom') {
1195: $datatable .= '<span class="LC_nobreak"><label>'.
1196: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1197: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1198: } else {
1199: $datatable .= $lt{'upl'};
1200: }
1201: $datatable .='<br />';
1202: if ($switchserver) {
1203: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1204: } else {
1205: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1206: }
1.160.6.5 raeburn 1207: $datatable .= '</td></tr>';
1208: $itemcount ++;
1.6 raeburn 1209: }
1.160.6.5 raeburn 1210: my @addlangs;
1211: foreach my $lang (sort(keys(%langchoices))) {
1212: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1213: push(@addlangs,$lang);
1214: }
1215: if (@addlangs > 0) {
1216: my %toadd;
1217: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1218: $toadd{''} = &mt('Select');
1219: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1220: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1221: &mt('Add log-in help page for a specific language:').' '.
1222: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1223: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1224: if ($switchserver) {
1225: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1226: } else {
1227: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1228: }
1.160.6.5 raeburn 1229: $datatable .= '</td></tr>';
1230: $itemcount ++;
1.6 raeburn 1231: }
1.160.6.5 raeburn 1232: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1233: } elsif ($caller eq 'headtag') {
1234: my %domservers = &Apache::lonnet::get_servers($dom);
1235: my $choice = $choices{'headtag'};
1236: $css_class = ' class="LC_odd_row"';
1237: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1238: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1239: '<th>'.$choices{'current'}.'</th>'.
1240: '<th>'.$choices{'action'}.'</th>'.
1241: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1242: my (%currurls,%currexempt);
1243: if (ref($settings) eq 'HASH') {
1244: if (ref($settings->{'headtag'}) eq 'HASH') {
1245: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1246: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1247: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1248: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1249: }
1250: }
1251: }
1252: }
1253: my %lt = &Apache::lonlocal::texthash(
1254: del => 'Delete?',
1255: rep => 'Replace:',
1256: upl => 'Upload:',
1257: curr => 'View contents',
1258: none => 'None',
1259: );
1260: my $switchserver = &check_switchserver($dom,$confname);
1261: foreach my $lonhost (sort(keys(%domservers))) {
1262: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1263: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1264: if ($currurls{$lonhost}) {
1265: $datatable .= '<td class="LC_right_item"><a href="'.
1266: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1267: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1268: '">'.$lt{'curr'}.'</a></td>'.
1269: '<td><span class="LC_nobreak"><label>'.
1270: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1271: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1272: } else {
1273: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1274: }
1275: $datatable .='<br />';
1276: if ($switchserver) {
1277: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1278: } else {
1279: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1280: }
1.160.6.87 raeburn 1281: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1282: }
1283: $datatable .= '</table></td></tr>';
1.1 raeburn 1284: }
1.6 raeburn 1285: return $datatable;
1286: }
1287:
1288: sub login_choices {
1289: my %choices =
1290: &Apache::lonlocal::texthash (
1.116 bisitz 1291: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1292: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1293: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1294: disallowlogin => "Login page requests redirected",
1295: hostid => "Server",
1.128 raeburn 1296: server => "Redirect to:",
1297: serverpath => "Path",
1298: custompath => "Custom",
1299: exempt => "Exempt IP(s)",
1.110 raeburn 1300: directlogin => "No redirect",
1301: newuser => "Link to create a user account",
1302: img => "Header",
1303: logo => "Main Logo",
1304: domlogo => "Domain Logo",
1305: login => "Log-in Header",
1306: textcol => "Text color",
1307: bgcol => "Box color",
1308: bgs => "Background colors",
1309: links => "Link colors",
1310: font => "Font color",
1311: pgbg => "Header",
1312: mainbg => "Page",
1313: sidebg => "Login box",
1314: link => "Link",
1315: alink => "Active link",
1316: vlink => "Visited link",
1.160.6.56 raeburn 1317: headtag => "Custom markup",
1318: action => "Action",
1319: current => "Current",
1.6 raeburn 1320: );
1321: return %choices;
1322: }
1323:
1324: sub print_rolecolors {
1.30 raeburn 1325: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1326: my %choices = &color_font_choices();
1327: my @bgs = ('pgbg','tabbg','sidebg');
1328: my @links = ('link','alink','vlink');
1329: my @images = ('img');
1330: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1331: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1332: my %defaultdesign = %Apache::loncommon::defaultdesign;
1333: my (%is_custom,%designs);
1.160.6.22 raeburn 1334: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1335: if (ref($settings) eq 'HASH') {
1336: if (ref($settings->{$role}) eq 'HASH') {
1337: if ($settings->{$role}->{'img'} ne '') {
1338: $designs{'img'} = $settings->{$role}->{'img'};
1339: $is_custom{'img'} = 1;
1340: }
1341: if ($settings->{$role}->{'font'} ne '') {
1342: $designs{'font'} = $settings->{$role}->{'font'};
1343: $is_custom{'font'} = 1;
1344: }
1.97 tempelho 1345: if ($settings->{$role}->{'fontmenu'} ne '') {
1346: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1347: $is_custom{'fontmenu'} = 1;
1348: }
1.6 raeburn 1349: foreach my $item (@bgs) {
1350: if ($settings->{$role}->{$item} ne '') {
1351: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1352: $is_custom{$item} = 1;
1353: }
1354: }
1355: foreach my $item (@links) {
1356: if ($settings->{$role}->{$item} ne '') {
1357: $designs{'links'}{$item} = $settings->{$role}->{$item};
1358: $is_custom{$item} = 1;
1359: }
1360: }
1361: }
1362: } else {
1363: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1364: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1365: $is_custom{'img'} = 1;
1366: }
1.97 tempelho 1367: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1368: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1369: $is_custom{'fontmenu'} = 1;
1370: }
1.6 raeburn 1371: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1372: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1373: $is_custom{'font'} = 1;
1374: }
1375: foreach my $item (@bgs) {
1376: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1377: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1378: $is_custom{$item} = 1;
1379:
1380: }
1381: }
1382: foreach my $item (@links) {
1383: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1384: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1385: $is_custom{$item} = 1;
1386: }
1387: }
1388: }
1389: my $itemcount = 1;
1.30 raeburn 1390: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1391: $datatable .= '</tr></table></td></tr>';
1392: return $datatable;
1393: }
1394:
1.160.6.22 raeburn 1395: sub role_defaults {
1396: my ($role,$bgs,$links,$images,$logintext) = @_;
1397: my %defaults;
1398: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1399: return %defaults;
1400: }
1401: my %defaultdesign = %Apache::loncommon::defaultdesign;
1402: if ($role eq 'login') {
1403: %defaults = (
1404: font => $defaultdesign{$role.'.font'},
1405: );
1406: if (ref($logintext) eq 'ARRAY') {
1407: foreach my $item (@{$logintext}) {
1408: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1409: }
1410: }
1411: foreach my $item (@{$images}) {
1412: $defaults{'showlogo'}{$item} = 1;
1413: }
1414: } else {
1415: %defaults = (
1416: img => $defaultdesign{$role.'.img'},
1417: font => $defaultdesign{$role.'.font'},
1418: fontmenu => $defaultdesign{$role.'.fontmenu'},
1419: );
1420: }
1421: foreach my $item (@{$bgs}) {
1422: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1423: }
1424: foreach my $item (@{$links}) {
1425: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1426: }
1427: foreach my $item (@{$images}) {
1428: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1429: }
1430: return %defaults;
1431: }
1432:
1.6 raeburn 1433: sub display_color_options {
1.9 raeburn 1434: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1435: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1436: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1437: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1438: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1439: '<td>'.$choices->{'font'}.'</td>';
1440: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1441: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1442: } else {
1443: $datatable .= '<td> </td>';
1444: }
1.160.6.9 raeburn 1445: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1446:
1.8 raeburn 1447: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1448: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1449: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1450: ' </span></td></tr>';
1.107 raeburn 1451: unless ($role eq 'login') {
1452: $datatable .= '<tr'.$css_class.'>'.
1453: '<td>'.$choices->{'fontmenu'}.'</td>';
1454: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1455: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1456: } else {
1457: $datatable .= '<td> </td>';
1458: }
1.160.6.22 raeburn 1459: $current_color = $designs->{'fontmenu'} ?
1460: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1461: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1462: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1463: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1464: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1465: ' </span></td></tr>';
1.97 tempelho 1466: }
1.9 raeburn 1467: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1468: foreach my $img (@{$images}) {
1.18 albertel 1469: $itemcount ++;
1.6 raeburn 1470: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1471: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1472: '<td>'.$choices->{$img};
1.41 raeburn 1473: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1474: if ($role eq 'login') {
1475: if ($img eq 'login') {
1476: $login_hdr_pick =
1.135 bisitz 1477: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1478: $logincolors =
1479: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1480: $designs,$defaults);
1.70 raeburn 1481: } elsif ($img ne 'domlogo') {
1482: $datatable.= &logo_display_options($img,$defaults,$designs);
1483: }
1484: }
1485: $datatable .= '</td>';
1.6 raeburn 1486: if ($designs->{$img} ne '') {
1487: $imgfile = $designs->{$img};
1.18 albertel 1488: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1489: } else {
1490: $imgfile = $defaults->{$img};
1491: }
1492: if ($imgfile) {
1.9 raeburn 1493: my ($showfile,$fullsize);
1494: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1495: my $urldir = $1;
1496: my $filename = $2;
1497: my @info = &Apache::lonnet::stat_file($designs->{$img});
1498: if (@info) {
1499: my $thumbfile = 'tn-'.$filename;
1500: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1501: if (@thumb) {
1502: $showfile = $urldir.'/'.$thumbfile;
1503: } else {
1504: $showfile = $imgfile;
1505: }
1506: } else {
1507: $showfile = '';
1508: }
1509: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1510: $showfile = $imgfile;
1.6 raeburn 1511: my $imgdir = $1;
1512: my $filename = $2;
1.159 raeburn 1513: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1514: $showfile = "/$imgdir/tn-".$filename;
1515: } else {
1.159 raeburn 1516: my $input = $londocroot.$imgfile;
1517: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1518: if (!-e $output) {
1.9 raeburn 1519: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1520: my ($fullwidth,$fullheight) = &check_dimensions($input);
1521: if ($fullwidth ne '' && $fullheight ne '') {
1522: if ($fullwidth > $width && $fullheight > $height) {
1523: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1524: my @args = ('convert','-sample',$size,$input,$output);
1525: system({$args[0]} @args);
1.159 raeburn 1526: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1527: }
1528: }
1.6 raeburn 1529: }
1530: }
1.16 raeburn 1531: }
1.6 raeburn 1532: if ($showfile) {
1.40 raeburn 1533: if ($showfile =~ m{^/(adm|res)/}) {
1534: if ($showfile =~ m{^/res/}) {
1535: my $local_showfile =
1536: &Apache::lonnet::filelocation('',$showfile);
1537: &Apache::lonnet::repcopy($local_showfile);
1538: }
1539: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1540: }
1541: if ($imgfile) {
1542: if ($imgfile =~ m{^/(adm|res)/}) {
1543: if ($imgfile =~ m{^/res/}) {
1544: my $local_imgfile =
1545: &Apache::lonnet::filelocation('',$imgfile);
1546: &Apache::lonnet::repcopy($local_imgfile);
1547: }
1548: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1549: } else {
1550: $fullsize = $imgfile;
1551: }
1552: }
1.41 raeburn 1553: $datatable .= '<td>';
1554: if ($img eq 'login') {
1.135 bisitz 1555: $datatable .= $login_hdr_pick;
1556: }
1.41 raeburn 1557: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1558: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1559: } else {
1.160.6.22 raeburn 1560: $datatable .= '<td> </td><td class="LC_left_item">'.
1561: &mt('Upload:').'<br />';
1.6 raeburn 1562: }
1563: } else {
1.160.6.22 raeburn 1564: $datatable .= '<td> </td><td class="LC_left_item">'.
1565: &mt('Upload:').'<br />';
1.6 raeburn 1566: }
1.9 raeburn 1567: if ($switchserver) {
1568: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1569: } else {
1.135 bisitz 1570: if ($img ne 'login') { # suppress file selection for Log-in header
1571: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1572: }
1.9 raeburn 1573: }
1574: $datatable .= '</td></tr>';
1.6 raeburn 1575: }
1576: $itemcount ++;
1577: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1578: $datatable .= '<tr'.$css_class.'>'.
1579: '<td>'.$choices->{'bgs'}.'</td>';
1580: my $bgs_def;
1581: foreach my $item (@{$bgs}) {
1582: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1583: $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 1584: }
1585: }
1586: if ($bgs_def) {
1.8 raeburn 1587: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1588: } else {
1589: $datatable .= '<td> </td>';
1590: }
1591: $datatable .= '<td class="LC_right_item">'.
1592: '<table border="0"><tr>';
1.160.6.13 raeburn 1593:
1.6 raeburn 1594: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1595: $datatable .= '<td align="center">'.$choices->{$item};
1596: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1597: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1598: $datatable .= ' ';
1.6 raeburn 1599: }
1.160.6.9 raeburn 1600: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1601: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1602: }
1603: $datatable .= '</tr></table></td></tr>';
1604: $itemcount ++;
1605: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1606: $datatable .= '<tr'.$css_class.'>'.
1607: '<td>'.$choices->{'links'}.'</td>';
1608: my $links_def;
1609: foreach my $item (@{$links}) {
1610: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1611: $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 1612: }
1613: }
1614: if ($links_def) {
1.8 raeburn 1615: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1616: } else {
1617: $datatable .= '<td> </td>';
1618: }
1619: $datatable .= '<td class="LC_right_item">'.
1620: '<table border="0"><tr>';
1621: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1622: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1623: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1624: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1625: $datatable.=' ';
1.6 raeburn 1626: }
1.160.6.9 raeburn 1627: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1628: '" /></td>';
1629: }
1.30 raeburn 1630: $$rowtotal += $itemcount;
1.3 raeburn 1631: return $datatable;
1632: }
1633:
1.70 raeburn 1634: sub logo_display_options {
1635: my ($img,$defaults,$designs) = @_;
1636: my $checkedon;
1637: if (ref($defaults) eq 'HASH') {
1638: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1639: if ($defaults->{'showlogo'}{$img}) {
1640: $checkedon = 'checked="checked" ';
1641: }
1642: }
1643: }
1644: if (ref($designs) eq 'HASH') {
1645: if (ref($designs->{'showlogo'}) eq 'HASH') {
1646: if (defined($designs->{'showlogo'}{$img})) {
1647: if ($designs->{'showlogo'}{$img} == 0) {
1648: $checkedon = '';
1649: } elsif ($designs->{'showlogo'}{$img} == 1) {
1650: $checkedon = 'checked="checked" ';
1651: }
1652: }
1653: }
1654: }
1655: return '<br /><label> <input type="checkbox" name="'.
1656: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1657: &mt('show').'</label>'."\n";
1658: }
1659:
1.41 raeburn 1660: sub login_header_options {
1.135 bisitz 1661: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1662: my $output = '';
1.41 raeburn 1663: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1664: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1665: if (!$is_custom->{'textcol'}) {
1666: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1667: ' ';
1668: }
1669: if (!$is_custom->{'bgcol'}) {
1670: $output .= $choices->{'bgcol'}.': '.
1671: '<span id="css_'.$role.'_font" style="background-color: '.
1672: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1673: }
1674: $output .= '<br />';
1675: }
1676: $output .='<br />';
1677: return $output;
1678: }
1679:
1680: sub login_text_colors {
1.160.6.22 raeburn 1681: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1682: my $color_menu = '<table border="0"><tr>';
1683: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1684: $color_menu .= '<td align="center">'.$choices->{$item};
1685: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1686: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1687: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1688: }
1689: $color_menu .= '</tr></table><br />';
1690: return $color_menu;
1691: }
1692:
1693: sub image_changes {
1694: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1695: my $output;
1.135 bisitz 1696: if ($img eq 'login') {
1.160.6.87 raeburn 1697: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1698: } elsif (!$is_custom) {
1.70 raeburn 1699: if ($img ne 'domlogo') {
1.160.6.87 raeburn 1700: $output = &mt('Default image:').'<br />';
1.41 raeburn 1701: } else {
1.160.6.87 raeburn 1702: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1703: }
1704: }
1.160.6.87 raeburn 1705: if ($img ne 'login') {
1.135 bisitz 1706: if ($img_import) {
1707: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1708: }
1709: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1710: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1711: if ($is_custom) {
1712: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1713: '<input type="checkbox" name="'.
1714: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1715: '</label> '.&mt('Replace:').'</span><br />';
1716: } else {
1.160.6.22 raeburn 1717: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1718: }
1.41 raeburn 1719: }
1720: return $output;
1721: }
1722:
1.3 raeburn 1723: sub print_quotas {
1.86 raeburn 1724: my ($dom,$settings,$rowtotal,$action) = @_;
1725: my $context;
1726: if ($action eq 'quotas') {
1727: $context = 'tools';
1728: } else {
1729: $context = $action;
1730: }
1.160.6.20 raeburn 1731: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1732: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1733: my $typecount = 0;
1.101 raeburn 1734: my ($css_class,%titles);
1.86 raeburn 1735: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1736: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1737: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1738: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1739: %titles = &courserequest_titles();
1.160.6.5 raeburn 1740: } elsif ($context eq 'requestauthor') {
1741: @usertools = ('author');
1742: @options = ('norequest','approval','automatic');
1743: %titles = &authorrequest_titles();
1.86 raeburn 1744: } else {
1.160.6.4 raeburn 1745: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1746: %titles = &tool_titles();
1.86 raeburn 1747: }
1.26 raeburn 1748: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1749: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1750: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1751: unless (($context eq 'requestcourses') ||
1752: ($context eq 'requestauthor')) {
1.86 raeburn 1753: if (ref($settings) eq 'HASH') {
1754: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1755: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1756: } else {
1757: $currdefquota = $settings->{$type};
1758: }
1.160.6.20 raeburn 1759: if (ref($settings->{authorquota}) eq 'HASH') {
1760: $currauthorquota = $settings->{authorquota}->{$type};
1761: }
1.78 raeburn 1762: }
1.72 raeburn 1763: }
1.3 raeburn 1764: if (defined($usertypes->{$type})) {
1765: $typecount ++;
1766: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1767: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1768: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1769: '<td class="LC_left_item">';
1.101 raeburn 1770: if ($context eq 'requestcourses') {
1771: $datatable .= '<table><tr>';
1772: }
1773: my %cell;
1.72 raeburn 1774: foreach my $item (@usertools) {
1.101 raeburn 1775: if ($context eq 'requestcourses') {
1776: my ($curroption,$currlimit);
1777: if (ref($settings) eq 'HASH') {
1778: if (ref($settings->{$item}) eq 'HASH') {
1779: $curroption = $settings->{$item}->{$type};
1780: if ($curroption =~ /^autolimit=(\d*)$/) {
1781: $currlimit = $1;
1782: }
1783: }
1784: }
1785: if (!$curroption) {
1786: $curroption = 'norequest';
1787: }
1788: $datatable .= '<th>'.$titles{$item}.'</th>';
1789: foreach my $option (@options) {
1790: my $val = $option;
1791: if ($option eq 'norequest') {
1792: $val = 0;
1793: }
1794: if ($option eq 'validate') {
1795: my $canvalidate = 0;
1796: if (ref($validations{$item}) eq 'HASH') {
1797: if ($validations{$item}{$type}) {
1798: $canvalidate = 1;
1799: }
1800: }
1801: next if (!$canvalidate);
1802: }
1803: my $checked = '';
1804: if ($option eq $curroption) {
1805: $checked = ' checked="checked"';
1806: } elsif ($option eq 'autolimit') {
1807: if ($curroption =~ /^autolimit/) {
1808: $checked = ' checked="checked"';
1809: }
1810: }
1811: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1812: '<input type="radio" name="crsreq_'.$item.
1813: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1814: $titles{$option}.'</label>';
1.101 raeburn 1815: if ($option eq 'autolimit') {
1.127 raeburn 1816: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1817: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1818: 'value="'.$currlimit.'" />';
1.101 raeburn 1819: }
1.127 raeburn 1820: $cell{$item} .= '</span> ';
1.103 raeburn 1821: if ($option eq 'autolimit') {
1.127 raeburn 1822: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1823: }
1.101 raeburn 1824: }
1.160.6.5 raeburn 1825: } elsif ($context eq 'requestauthor') {
1826: my $curroption;
1827: if (ref($settings) eq 'HASH') {
1828: $curroption = $settings->{$type};
1829: }
1830: if (!$curroption) {
1831: $curroption = 'norequest';
1832: }
1833: foreach my $option (@options) {
1834: my $val = $option;
1835: if ($option eq 'norequest') {
1836: $val = 0;
1837: }
1838: my $checked = '';
1839: if ($option eq $curroption) {
1840: $checked = ' checked="checked"';
1841: }
1842: $datatable .= '<span class="LC_nobreak"><label>'.
1843: '<input type="radio" name="authorreq_'.$type.
1844: '" value="'.$val.'"'.$checked.' />'.
1845: $titles{$option}.'</label></span> ';
1846: }
1.101 raeburn 1847: } else {
1848: my $checked = 'checked="checked" ';
1849: if (ref($settings) eq 'HASH') {
1850: if (ref($settings->{$item}) eq 'HASH') {
1851: if ($settings->{$item}->{$type} == 0) {
1852: $checked = '';
1853: } elsif ($settings->{$item}->{$type} == 1) {
1854: $checked = 'checked="checked" ';
1855: }
1.78 raeburn 1856: }
1.72 raeburn 1857: }
1.101 raeburn 1858: $datatable .= '<span class="LC_nobreak"><label>'.
1859: '<input type="checkbox" name="'.$context.'_'.$item.
1860: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1861: '</label></span> ';
1.72 raeburn 1862: }
1.101 raeburn 1863: }
1864: if ($context eq 'requestcourses') {
1865: $datatable .= '</tr><tr>';
1866: foreach my $item (@usertools) {
1.106 raeburn 1867: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1868: }
1869: $datatable .= '</tr></table>';
1.72 raeburn 1870: }
1.86 raeburn 1871: $datatable .= '</td>';
1.160.6.5 raeburn 1872: unless (($context eq 'requestcourses') ||
1873: ($context eq 'requestauthor')) {
1.86 raeburn 1874: $datatable .=
1.160.6.20 raeburn 1875: '<td class="LC_right_item">'.
1876: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1877: '<input type="text" name="quota_'.$type.
1.72 raeburn 1878: '" value="'.$currdefquota.
1.160.6.20 raeburn 1879: '" size="5" /></span>'.(' ' x 2).
1880: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1881: '<input type="text" name="authorquota_'.$type.
1882: '" value="'.$currauthorquota.
1883: '" size="5" /></span></td>';
1.86 raeburn 1884: }
1885: $datatable .= '</tr>';
1.3 raeburn 1886: }
1887: }
1888: }
1.160.6.5 raeburn 1889: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1890: $defaultquota = '20';
1.160.6.20 raeburn 1891: $authorquota = '500';
1.86 raeburn 1892: if (ref($settings) eq 'HASH') {
1893: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1894: $defaultquota = $settings->{'defaultquota'}->{'default'};
1895: } elsif (defined($settings->{'default'})) {
1896: $defaultquota = $settings->{'default'};
1897: }
1.160.6.20 raeburn 1898: if (ref($settings->{'authorquota'}) eq 'HASH') {
1899: $authorquota = $settings->{'authorquota'}->{'default'};
1900: }
1.3 raeburn 1901: }
1902: }
1903: $typecount ++;
1904: $css_class = $typecount%2?' class="LC_odd_row"':'';
1905: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1906: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1907: '<td class="LC_left_item">';
1.101 raeburn 1908: if ($context eq 'requestcourses') {
1909: $datatable .= '<table><tr>';
1910: }
1911: my %defcell;
1.72 raeburn 1912: foreach my $item (@usertools) {
1.101 raeburn 1913: if ($context eq 'requestcourses') {
1914: my ($curroption,$currlimit);
1915: if (ref($settings) eq 'HASH') {
1916: if (ref($settings->{$item}) eq 'HASH') {
1917: $curroption = $settings->{$item}->{'default'};
1918: if ($curroption =~ /^autolimit=(\d*)$/) {
1919: $currlimit = $1;
1920: }
1921: }
1922: }
1923: if (!$curroption) {
1924: $curroption = 'norequest';
1925: }
1926: $datatable .= '<th>'.$titles{$item}.'</th>';
1927: foreach my $option (@options) {
1928: my $val = $option;
1929: if ($option eq 'norequest') {
1930: $val = 0;
1931: }
1932: if ($option eq 'validate') {
1933: my $canvalidate = 0;
1934: if (ref($validations{$item}) eq 'HASH') {
1935: if ($validations{$item}{'default'}) {
1936: $canvalidate = 1;
1937: }
1938: }
1939: next if (!$canvalidate);
1940: }
1941: my $checked = '';
1942: if ($option eq $curroption) {
1943: $checked = ' checked="checked"';
1944: } elsif ($option eq 'autolimit') {
1945: if ($curroption =~ /^autolimit/) {
1946: $checked = ' checked="checked"';
1947: }
1948: }
1949: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1950: '<input type="radio" name="crsreq_'.$item.
1951: '_default" value="'.$val.'"'.$checked.' />'.
1952: $titles{$option}.'</label>';
1953: if ($option eq 'autolimit') {
1.127 raeburn 1954: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1955: $item.'_limit_default" size="1" '.
1956: 'value="'.$currlimit.'" />';
1957: }
1.127 raeburn 1958: $defcell{$item} .= '</span> ';
1.104 raeburn 1959: if ($option eq 'autolimit') {
1.127 raeburn 1960: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1961: }
1.101 raeburn 1962: }
1.160.6.5 raeburn 1963: } elsif ($context eq 'requestauthor') {
1964: my $curroption;
1965: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1966: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1967: }
1968: if (!$curroption) {
1969: $curroption = 'norequest';
1970: }
1971: foreach my $option (@options) {
1972: my $val = $option;
1973: if ($option eq 'norequest') {
1974: $val = 0;
1975: }
1976: my $checked = '';
1977: if ($option eq $curroption) {
1978: $checked = ' checked="checked"';
1979: }
1980: $datatable .= '<span class="LC_nobreak"><label>'.
1981: '<input type="radio" name="authorreq_default"'.
1982: ' value="'.$val.'"'.$checked.' />'.
1983: $titles{$option}.'</label></span> ';
1984: }
1.101 raeburn 1985: } else {
1986: my $checked = 'checked="checked" ';
1987: if (ref($settings) eq 'HASH') {
1988: if (ref($settings->{$item}) eq 'HASH') {
1989: if ($settings->{$item}->{'default'} == 0) {
1990: $checked = '';
1991: } elsif ($settings->{$item}->{'default'} == 1) {
1992: $checked = 'checked="checked" ';
1993: }
1.78 raeburn 1994: }
1.72 raeburn 1995: }
1.101 raeburn 1996: $datatable .= '<span class="LC_nobreak"><label>'.
1997: '<input type="checkbox" name="'.$context.'_'.$item.
1998: '" value="default" '.$checked.'/>'.$titles{$item}.
1999: '</label></span> ';
2000: }
2001: }
2002: if ($context eq 'requestcourses') {
2003: $datatable .= '</tr><tr>';
2004: foreach my $item (@usertools) {
1.106 raeburn 2005: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2006: }
1.101 raeburn 2007: $datatable .= '</tr></table>';
1.72 raeburn 2008: }
1.86 raeburn 2009: $datatable .= '</td>';
1.160.6.5 raeburn 2010: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2011: $datatable .= '<td class="LC_right_item">'.
2012: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2013: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2014: $defaultquota.'" size="5" /></span>'.(' ' x2).
2015: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2016: '<input type="text" name="authorquota" value="'.
2017: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2018: }
2019: $datatable .= '</tr>';
1.72 raeburn 2020: $typecount ++;
2021: $css_class = $typecount%2?' class="LC_odd_row"':'';
2022: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2023: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2024: if ($context eq 'requestcourses') {
1.109 raeburn 2025: $datatable .= &mt('(overrides affiliation, if set)').
2026: '</td>'.
2027: '<td class="LC_left_item">'.
2028: '<table><tr>';
1.101 raeburn 2029: } else {
1.109 raeburn 2030: $datatable .= &mt('(overrides affiliation, if checked)').
2031: '</td>'.
2032: '<td class="LC_left_item" colspan="2">'.
2033: '<br />';
1.101 raeburn 2034: }
2035: my %advcell;
1.72 raeburn 2036: foreach my $item (@usertools) {
1.101 raeburn 2037: if ($context eq 'requestcourses') {
2038: my ($curroption,$currlimit);
2039: if (ref($settings) eq 'HASH') {
2040: if (ref($settings->{$item}) eq 'HASH') {
2041: $curroption = $settings->{$item}->{'_LC_adv'};
2042: if ($curroption =~ /^autolimit=(\d*)$/) {
2043: $currlimit = $1;
2044: }
2045: }
2046: }
2047: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2048: my $checked = '';
2049: if ($curroption eq '') {
2050: $checked = ' checked="checked"';
2051: }
2052: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2053: '<input type="radio" name="crsreq_'.$item.
2054: '__LC_adv" value=""'.$checked.' />'.
2055: &mt('No override set').'</label></span> ';
1.101 raeburn 2056: foreach my $option (@options) {
2057: my $val = $option;
2058: if ($option eq 'norequest') {
2059: $val = 0;
2060: }
2061: if ($option eq 'validate') {
2062: my $canvalidate = 0;
2063: if (ref($validations{$item}) eq 'HASH') {
2064: if ($validations{$item}{'_LC_adv'}) {
2065: $canvalidate = 1;
2066: }
2067: }
2068: next if (!$canvalidate);
2069: }
2070: my $checked = '';
1.104 raeburn 2071: if ($val eq $curroption) {
1.101 raeburn 2072: $checked = ' checked="checked"';
2073: } elsif ($option eq 'autolimit') {
2074: if ($curroption =~ /^autolimit/) {
2075: $checked = ' checked="checked"';
2076: }
2077: }
2078: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2079: '<input type="radio" name="crsreq_'.$item.
2080: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2081: $titles{$option}.'</label>';
2082: if ($option eq 'autolimit') {
1.127 raeburn 2083: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2084: $item.'_limit__LC_adv" size="1" '.
2085: 'value="'.$currlimit.'" />';
2086: }
1.127 raeburn 2087: $advcell{$item} .= '</span> ';
1.104 raeburn 2088: if ($option eq 'autolimit') {
1.127 raeburn 2089: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2090: }
1.101 raeburn 2091: }
1.160.6.5 raeburn 2092: } elsif ($context eq 'requestauthor') {
2093: my $curroption;
2094: if (ref($settings) eq 'HASH') {
2095: $curroption = $settings->{'_LC_adv'};
2096: }
2097: my $checked = '';
2098: if ($curroption eq '') {
2099: $checked = ' checked="checked"';
2100: }
2101: $datatable .= '<span class="LC_nobreak"><label>'.
2102: '<input type="radio" name="authorreq__LC_adv"'.
2103: ' value=""'.$checked.' />'.
2104: &mt('No override set').'</label></span> ';
2105: foreach my $option (@options) {
2106: my $val = $option;
2107: if ($option eq 'norequest') {
2108: $val = 0;
2109: }
2110: my $checked = '';
2111: if ($val eq $curroption) {
2112: $checked = ' checked="checked"';
2113: }
2114: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2115: '<input type="radio" name="authorreq__LC_adv"'.
2116: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2117: $titles{$option}.'</label></span> ';
2118: }
1.101 raeburn 2119: } else {
2120: my $checked = 'checked="checked" ';
2121: if (ref($settings) eq 'HASH') {
2122: if (ref($settings->{$item}) eq 'HASH') {
2123: if ($settings->{$item}->{'_LC_adv'} == 0) {
2124: $checked = '';
2125: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2126: $checked = 'checked="checked" ';
2127: }
1.79 raeburn 2128: }
1.72 raeburn 2129: }
1.101 raeburn 2130: $datatable .= '<span class="LC_nobreak"><label>'.
2131: '<input type="checkbox" name="'.$context.'_'.$item.
2132: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2133: '</label></span> ';
2134: }
2135: }
2136: if ($context eq 'requestcourses') {
2137: $datatable .= '</tr><tr>';
2138: foreach my $item (@usertools) {
1.106 raeburn 2139: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2140: }
1.101 raeburn 2141: $datatable .= '</tr></table>';
1.72 raeburn 2142: }
1.98 raeburn 2143: $datatable .= '</td></tr>';
1.30 raeburn 2144: $$rowtotal += $typecount;
1.3 raeburn 2145: return $datatable;
2146: }
2147:
1.160.6.5 raeburn 2148: sub print_requestmail {
2149: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2150: my ($now,$datatable,%currapp);
1.102 raeburn 2151: $now = time;
2152: if (ref($settings) eq 'HASH') {
2153: if (ref($settings->{'notify'}) eq 'HASH') {
2154: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2155: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2156: }
2157: }
2158: }
1.160.6.16 raeburn 2159: my $numinrow = 2;
1.160.6.34 raeburn 2160: my $css_class;
2161: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2162: my $text;
2163: if ($action eq 'requestcourses') {
2164: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2165: } elsif ($action eq 'requestauthor') {
2166: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2167: } else {
1.160.6.34 raeburn 2168: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2169: }
1.160.6.34 raeburn 2170: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2171: ' <td>'.$text.'</td>'.
1.102 raeburn 2172: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2173: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2174: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2175: if ($numdc > 0) {
2176: $datatable .= $table;
1.102 raeburn 2177: } else {
2178: $datatable .= &mt('There are no active Domain Coordinators');
2179: }
2180: $datatable .='</td></tr>';
2181: return $datatable;
2182: }
2183:
1.160.6.30 raeburn 2184: sub print_studentcode {
2185: my ($settings,$rowtotal) = @_;
2186: my $rownum = 0;
2187: my ($output,%current);
2188: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2189: if (ref($settings) eq 'HASH') {
2190: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2191: foreach my $type (@crstypes) {
2192: $current{$type} = $settings->{'uniquecode'}{$type};
2193: }
1.160.6.30 raeburn 2194: }
2195: }
2196: $output .= '<tr>'.
2197: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2198: '<td class="LC_left_item">';
2199: foreach my $type (@crstypes) {
2200: my $check = ' ';
2201: if ($current{$type}) {
2202: $check = ' checked="checked" ';
2203: }
2204: $output .= '<span class="LC_nobreak"><label>'.
2205: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2206: &mt($type).'</label></span>'.(' 'x2).' ';
2207: }
2208: $output .= '</td></tr>';
2209: $$rowtotal ++;
2210: return $output;
2211: }
2212:
2213: sub print_textbookcourses {
1.160.6.46 raeburn 2214: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2215: my $rownum = 0;
2216: my $css_class;
2217: my $itemcount = 1;
2218: my $maxnum = 0;
2219: my $bookshash;
2220: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2221: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2222: }
2223: my %ordered;
2224: if (ref($bookshash) eq 'HASH') {
2225: foreach my $item (keys(%{$bookshash})) {
2226: if (ref($bookshash->{$item}) eq 'HASH') {
2227: my $num = $bookshash->{$item}{'order'};
2228: $ordered{$num} = $item;
2229: }
2230: }
2231: }
2232: my $confname = $dom.'-domainconfig';
2233: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2234: my $maxnum = scalar(keys(%ordered));
2235: my $datatable;
1.160.6.30 raeburn 2236: if (keys(%ordered)) {
2237: my @items = sort { $a <=> $b } keys(%ordered);
2238: for (my $i=0; $i<@items; $i++) {
2239: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2240: my $key = $ordered{$items[$i]};
2241: my %coursehash=&Apache::lonnet::coursedescription($key);
2242: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2243: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2244: if (ref($bookshash->{$key}) eq 'HASH') {
2245: $subject = $bookshash->{$key}->{'subject'};
2246: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2247: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2248: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2249: $author = $bookshash->{$key}->{'author'};
2250: $image = $bookshash->{$key}->{'image'};
2251: if ($image ne '') {
2252: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2253: my $imagethumb = "$path/tn-".$imagefile;
2254: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2255: }
1.160.6.30 raeburn 2256: }
2257: }
1.160.6.46 raeburn 2258: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2259: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2260: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2261: for (my $k=0; $k<=$maxnum; $k++) {
2262: my $vpos = $k+1;
2263: my $selstr;
2264: if ($k == $i) {
2265: $selstr = ' selected="selected" ';
2266: }
2267: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2268: }
2269: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2270: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2271: &mt('Delete?').'</label></span></td>'.
2272: '<td colspan="2">'.
1.160.6.46 raeburn 2273: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2274: (' 'x2).
1.160.6.46 raeburn 2275: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2276: if ($type eq 'textbooks') {
2277: $datatable .= (' 'x2).
1.160.6.47 raeburn 2278: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2279: (' 'x2).
1.160.6.46 raeburn 2280: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2281: (' 'x2).
2282: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2283: if ($image) {
2284: $datatable .= '<span class="LC_nobreak">'.
2285: $imgsrc.
2286: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2287: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2288: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2289: }
2290: if ($switchserver) {
2291: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2292: } else {
2293: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2294: }
1.160.6.30 raeburn 2295: }
1.160.6.46 raeburn 2296: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2297: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2298: $coursetitle.'</span></td></tr>'."\n";
2299: $itemcount ++;
2300: }
2301: }
2302: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2303: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2304: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2305: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2306: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2307: for (my $k=0; $k<$maxnum+1; $k++) {
2308: my $vpos = $k+1;
2309: my $selstr;
2310: if ($k == $maxnum) {
2311: $selstr = ' selected="selected" ';
2312: }
2313: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2314: }
2315: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2316: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2317: '<td colspan="2">'.
1.160.6.46 raeburn 2318: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2319: (' 'x2).
1.160.6.46 raeburn 2320: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2321: (' 'x2);
2322: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2323: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2324: (' 'x2).
2325: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2326: (' 'x2).
2327: '<span class="LC_nobreak">'.&mt('Image:').' ';
2328: if ($switchserver) {
2329: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2330: } else {
2331: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2332: }
1.160.6.87 raeburn 2333: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2334: }
1.160.6.87 raeburn 2335: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2336: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2337: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2338: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2339: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2340: '</span></td>'."\n".
2341: '</tr>'."\n";
2342: $itemcount ++;
2343: return $datatable;
2344: }
2345:
2346: sub textbookcourses_javascript {
1.160.6.46 raeburn 2347: my ($settings) = @_;
2348: return unless(ref($settings) eq 'HASH');
2349: my (%ordered,%total,%jstext);
2350: foreach my $type ('textbooks','templates') {
2351: $total{$type} = 0;
2352: if (ref($settings->{$type}) eq 'HASH') {
2353: foreach my $item (keys(%{$settings->{$type}})) {
2354: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2355: my $num = $settings->{$type}->{$item}{'order'};
2356: $ordered{$type}{$num} = $item;
2357: }
2358: }
2359: $total{$type} = scalar(keys(%{$settings->{$type}}));
2360: }
2361: my @jsarray = ();
2362: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2363: push(@jsarray,$ordered{$type}{$item});
2364: }
2365: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2366: }
2367: return <<"ENDSCRIPT";
2368: <script type="text/javascript">
2369: // <![CDATA[
1.160.6.46 raeburn 2370: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2371: var changedVal;
1.160.6.46 raeburn 2372: $jstext{'textbooks'};
2373: $jstext{'templates'};
2374: var newpos;
2375: var maxh;
2376: if (caller == 'textbooks') {
2377: newpos = 'textbooks_addbook_pos';
2378: maxh = 1 + $total{'textbooks'};
2379: } else {
2380: newpos = 'templates_addbook_pos';
2381: maxh = 1 + $total{'templates'};
2382: }
1.160.6.30 raeburn 2383: var current = new Array;
2384: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2385: if (item == newpos) {
2386: changedVal = newitemVal;
2387: } else {
2388: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2389: current[newitemVal] = newpos;
2390: }
1.160.6.46 raeburn 2391: if (caller == 'textbooks') {
2392: for (var i=0; i<textbooks.length; i++) {
2393: var elementName = 'textbooks_'+textbooks[i];
2394: if (elementName != item) {
2395: if (form.elements[elementName]) {
2396: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2397: current[currVal] = elementName;
2398: }
2399: }
2400: }
2401: }
2402: if (caller == 'templates') {
2403: for (var i=0; i<templates.length; i++) {
2404: var elementName = 'templates_'+templates[i];
2405: if (elementName != item) {
2406: if (form.elements[elementName]) {
2407: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2408: current[currVal] = elementName;
2409: }
1.160.6.30 raeburn 2410: }
2411: }
2412: }
2413: var oldVal;
2414: for (var j=0; j<maxh; j++) {
2415: if (current[j] == undefined) {
2416: oldVal = j;
2417: }
2418: }
2419: if (oldVal < changedVal) {
2420: for (var k=oldVal+1; k<=changedVal ; k++) {
2421: var elementName = current[k];
2422: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2423: }
2424: } else {
2425: for (var k=changedVal; k<oldVal; k++) {
2426: var elementName = current[k];
2427: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2428: }
2429: }
2430: return;
2431: }
2432:
2433: // ]]>
2434: </script>
2435:
2436: ENDSCRIPT
2437: }
2438:
1.3 raeburn 2439: sub print_autoenroll {
1.30 raeburn 2440: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2441: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2442: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2443: if (ref($settings) eq 'HASH') {
2444: if (exists($settings->{'run'})) {
2445: if ($settings->{'run'} eq '0') {
2446: $runoff = ' checked="checked" ';
2447: $runon = ' ';
2448: } else {
2449: $runon = ' checked="checked" ';
2450: $runoff = ' ';
2451: }
2452: } else {
2453: if ($autorun) {
2454: $runon = ' checked="checked" ';
2455: $runoff = ' ';
2456: } else {
2457: $runoff = ' checked="checked" ';
2458: $runon = ' ';
2459: }
2460: }
1.129 raeburn 2461: if (exists($settings->{'co-owners'})) {
2462: if ($settings->{'co-owners'} eq '0') {
2463: $coownersoff = ' checked="checked" ';
2464: $coownerson = ' ';
2465: } else {
2466: $coownerson = ' checked="checked" ';
2467: $coownersoff = ' ';
2468: }
2469: } else {
2470: $coownersoff = ' checked="checked" ';
2471: $coownerson = ' ';
2472: }
1.3 raeburn 2473: if (exists($settings->{'sender_domain'})) {
2474: $defdom = $settings->{'sender_domain'};
2475: }
1.160.6.68 raeburn 2476: if (exists($settings->{'autofailsafe'})) {
2477: $failsafe = $settings->{'autofailsafe'};
2478: }
1.14 raeburn 2479: } else {
2480: if ($autorun) {
2481: $runon = ' checked="checked" ';
2482: $runoff = ' ';
2483: } else {
2484: $runoff = ' checked="checked" ';
2485: $runon = ' ';
2486: }
1.3 raeburn 2487: }
2488: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2489: my $notif_sender;
2490: if (ref($settings) eq 'HASH') {
2491: $notif_sender = $settings->{'sender_uname'};
2492: }
1.3 raeburn 2493: my $datatable='<tr class="LC_odd_row">'.
2494: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2495: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2496: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2497: $runon.' value="1" />'.&mt('Yes').'</label> '.
2498: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2499: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2500: '</tr><tr>'.
2501: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2502: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2503: &mt('username').': '.
2504: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2505: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2506: ': '.$domform.'</span></td></tr>'.
2507: '<tr class="LC_odd_row">'.
2508: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2509: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2510: '<input type="radio" name="autoassign_coowners"'.
2511: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2512: '<label><input type="radio" name="autoassign_coowners"'.
2513: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2514: '</tr><tr>'.
2515: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2516: '<td class="LC_right_item"><span class="LC_nobreak">'.
2517: '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87 raeburn 2518: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68 raeburn 2519: $$rowtotal += 4;
1.3 raeburn 2520: return $datatable;
2521: }
2522:
2523: sub print_autoupdate {
1.30 raeburn 2524: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2525: my $datatable;
2526: if ($position eq 'top') {
2527: my $updateon = ' ';
2528: my $updateoff = ' checked="checked" ';
2529: my $classlistson = ' ';
2530: my $classlistsoff = ' checked="checked" ';
2531: if (ref($settings) eq 'HASH') {
2532: if ($settings->{'run'} eq '1') {
2533: $updateon = $updateoff;
2534: $updateoff = ' ';
2535: }
2536: if ($settings->{'classlists'} eq '1') {
2537: $classlistson = $classlistsoff;
2538: $classlistsoff = ' ';
2539: }
2540: }
2541: my %title = (
2542: run => 'Auto-update active?',
2543: classlists => 'Update information in classlists?',
2544: );
2545: $datatable = '<tr class="LC_odd_row">'.
2546: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2547: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2548: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2549: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2550: '<label><input type="radio" name="autoupdate_run"'.
2551: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2552: '</tr><tr>'.
2553: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2554: '<td class="LC_right_item"><span class="LC_nobreak">'.
2555: '<label><input type="radio" name="classlists"'.
2556: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2557: '<label><input type="radio" name="classlists"'.
2558: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2559: '</tr>';
1.30 raeburn 2560: $$rowtotal += 2;
1.131 raeburn 2561: } elsif ($position eq 'middle') {
2562: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2563: my $numinrow = 3;
2564: my $locknamesettings;
2565: $datatable .= &insttypes_row($settings,$types,$usertypes,
2566: $dom,$numinrow,$othertitle,
2567: 'lockablenames');
2568: $$rowtotal ++;
1.3 raeburn 2569: } else {
1.44 raeburn 2570: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2571: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2572: 'permanentemail','id');
1.33 raeburn 2573: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2574: my $numrows = 0;
1.26 raeburn 2575: if (ref($types) eq 'ARRAY') {
2576: if (@{$types} > 0) {
2577: $datatable =
2578: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2579: \@fields,$types,\$numrows);
1.30 raeburn 2580: $$rowtotal += @{$types};
1.26 raeburn 2581: }
1.3 raeburn 2582: }
2583: $datatable .=
2584: &usertype_update_row($settings,{'default' => $othertitle},
2585: \%fieldtitles,\@fields,['default'],
2586: \$numrows);
1.30 raeburn 2587: $$rowtotal ++;
1.3 raeburn 2588: }
2589: return $datatable;
2590: }
2591:
1.125 raeburn 2592: sub print_autocreate {
2593: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2594: my (%createon,%createoff,%currhash);
1.125 raeburn 2595: my @types = ('xml','req');
2596: if (ref($settings) eq 'HASH') {
2597: foreach my $item (@types) {
2598: $createoff{$item} = ' checked="checked" ';
2599: $createon{$item} = ' ';
2600: if (exists($settings->{$item})) {
2601: if ($settings->{$item}) {
2602: $createon{$item} = ' checked="checked" ';
2603: $createoff{$item} = ' ';
2604: }
2605: }
2606: }
1.160.6.16 raeburn 2607: if ($settings->{'xmldc'} ne '') {
2608: $currhash{$settings->{'xmldc'}} = 1;
2609: }
1.125 raeburn 2610: } else {
2611: foreach my $item (@types) {
2612: $createoff{$item} = ' checked="checked" ';
2613: $createon{$item} = ' ';
2614: }
2615: }
2616: $$rowtotal += 2;
1.160.6.16 raeburn 2617: my $numinrow = 2;
1.125 raeburn 2618: my $datatable='<tr class="LC_odd_row">'.
2619: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2620: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2621: '<input type="radio" name="autocreate_xml"'.
2622: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2623: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2624: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2625: '</td></tr><tr>'.
2626: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2627: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2628: '<input type="radio" name="autocreate_req"'.
2629: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2630: '<label><input type="radio" name="autocreate_req"'.
2631: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2632: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2633: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2634: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2635: if ($numdc > 1) {
1.160.6.50 raeburn 2636: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2637: '</td><td class="LC_left_item">';
1.125 raeburn 2638: } else {
1.160.6.50 raeburn 2639: $datatable .= &mt('Course creation processed as:').
2640: '</td><td class="LC_right_item">';
1.125 raeburn 2641: }
1.160.6.50 raeburn 2642: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2643: $$rowtotal += $rows;
1.125 raeburn 2644: return $datatable;
2645: }
2646:
1.23 raeburn 2647: sub print_directorysrch {
1.160.6.72 raeburn 2648: my ($position,$dom,$settings,$rowtotal) = @_;
2649: my $datatable;
2650: if ($position eq 'top') {
2651: my $instsrchon = ' ';
2652: my $instsrchoff = ' checked="checked" ';
2653: my ($exacton,$containson,$beginson);
2654: my $instlocalon = ' ';
2655: my $instlocaloff = ' checked="checked" ';
2656: if (ref($settings) eq 'HASH') {
2657: if ($settings->{'available'} eq '1') {
2658: $instsrchon = $instsrchoff;
2659: $instsrchoff = ' ';
2660: }
2661: if ($settings->{'localonly'} eq '1') {
2662: $instlocalon = $instlocaloff;
2663: $instlocaloff = ' ';
2664: }
2665: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2666: foreach my $type (@{$settings->{'searchtypes'}}) {
2667: if ($type eq 'exact') {
2668: $exacton = ' checked="checked" ';
2669: } elsif ($type eq 'contains') {
2670: $containson = ' checked="checked" ';
2671: } elsif ($type eq 'begins') {
2672: $beginson = ' checked="checked" ';
2673: }
2674: }
2675: } else {
2676: if ($settings->{'searchtypes'} eq 'exact') {
2677: $exacton = ' checked="checked" ';
2678: } elsif ($settings->{'searchtypes'} eq 'contains') {
2679: $containson = ' checked="checked" ';
2680: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2681: $exacton = ' checked="checked" ';
2682: $containson = ' checked="checked" ';
2683: }
2684: }
1.23 raeburn 2685: }
1.160.6.72 raeburn 2686: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2687: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2688:
1.160.6.72 raeburn 2689: my $numinrow = 4;
2690: my $cansrchrow = 0;
2691: $datatable='<tr class="LC_odd_row">'.
2692: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2693: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2694: '<input type="radio" name="dirsrch_available"'.
2695: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2696: '<label><input type="radio" name="dirsrch_available"'.
2697: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2698: '</tr><tr>'.
2699: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2700: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2701: '<input type="radio" name="dirsrch_instlocalonly"'.
2702: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2703: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2704: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2705: '</tr>';
2706: $$rowtotal += 2;
2707: if (ref($usertypes) eq 'HASH') {
2708: if (keys(%{$usertypes}) > 0) {
2709: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2710: $numinrow,$othertitle,'cansearch');
2711: $cansrchrow = 1;
2712: }
1.26 raeburn 2713: }
1.160.6.72 raeburn 2714: if ($cansrchrow) {
2715: $$rowtotal ++;
2716: $datatable .= '<tr>';
2717: } else {
2718: $datatable .= '<tr class="LC_odd_row">';
2719: }
2720: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2721: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2722: foreach my $title (@{$titleorder}) {
2723: if (defined($searchtitles->{$title})) {
2724: my $check = ' ';
2725: if (ref($settings) eq 'HASH') {
2726: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2727: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2728: $check = ' checked="checked" ';
2729: }
1.39 raeburn 2730: }
1.25 raeburn 2731: }
1.160.6.72 raeburn 2732: $datatable .= '<td class="LC_left_item">'.
2733: '<span class="LC_nobreak"><label>'.
2734: '<input type="checkbox" name="searchby" '.
2735: 'value="'.$title.'"'.$check.'/>'.
2736: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2737: }
2738: }
1.160.6.72 raeburn 2739: $datatable .= '</tr></table></td></tr>';
2740: $$rowtotal ++;
2741: if ($cansrchrow) {
2742: $datatable .= '<tr class="LC_odd_row">';
2743: } else {
2744: $datatable .= '<tr>';
2745: }
2746: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2747: '<td class="LC_left_item" colspan="2">'.
2748: '<span class="LC_nobreak"><label>'.
2749: '<input type="checkbox" name="searchtypes" '.
2750: $exacton.' value="exact" />'.&mt('Exact match').
2751: '</label> '.
2752: '<label><input type="checkbox" name="searchtypes" '.
2753: $beginson.' value="begins" />'.&mt('Begins with').
2754: '</label> '.
2755: '<label><input type="checkbox" name="searchtypes" '.
2756: $containson.' value="contains" />'.&mt('Contains').
2757: '</label></span></td></tr>';
2758: $$rowtotal ++;
1.26 raeburn 2759: } else {
1.160.6.72 raeburn 2760: my $domsrchon = ' checked="checked" ';
2761: my $domsrchoff = ' ';
2762: my $domlocalon = ' ';
2763: my $domlocaloff = ' checked="checked" ';
2764: if (ref($settings) eq 'HASH') {
2765: if ($settings->{'lclocalonly'} eq '1') {
2766: $domlocalon = $domlocaloff;
2767: $domlocaloff = ' ';
2768: }
2769: if ($settings->{'lcavailable'} eq '0') {
2770: $domsrchoff = $domsrchon;
2771: $domsrchon = ' ';
2772: }
2773: }
2774: $datatable='<tr class="LC_odd_row">'.
2775: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2776: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2777: '<input type="radio" name="dirsrch_domavailable"'.
2778: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2779: '<label><input type="radio" name="dirsrch_domavailable"'.
2780: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2781: '</tr><tr>'.
2782: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2783: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2784: '<input type="radio" name="dirsrch_domlocalonly"'.
2785: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2786: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2787: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2788: '</tr>';
2789: $$rowtotal += 2;
1.26 raeburn 2790: }
1.25 raeburn 2791: return $datatable;
2792: }
2793:
1.28 raeburn 2794: sub print_contacts {
1.160.6.78 raeburn 2795: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2796: my $datatable;
2797: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 2798: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2799: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2800: if ($position eq 'top') {
2801: if (ref($settings) eq 'HASH') {
2802: foreach my $item (@contacts) {
2803: if (exists($settings->{$item})) {
2804: $to{$item} = $settings->{$item};
2805: }
1.28 raeburn 2806: }
2807: }
1.160.6.78 raeburn 2808: } elsif ($position eq 'middle') {
2809: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
2810: 'updatesmail','idconflictsmail');
1.28 raeburn 2811: foreach my $type (@mailings) {
1.160.6.78 raeburn 2812: $otheremails{$type} = '';
2813: }
2814: } else {
2815: @mailings = ('helpdeskmail','otherdomsmail');
2816: foreach my $type (@mailings) {
2817: $otheremails{$type} = '';
2818: }
2819: $bccemails{'helpdeskmail'} = '';
2820: $bccemails{'otherdomsmail'} = '';
2821: $includestr{'helpdeskmail'} = '';
2822: $includestr{'otherdomsmail'} = '';
2823: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2824: }
2825: if (ref($settings) eq 'HASH') {
2826: unless ($position eq 'top') {
2827: foreach my $type (@mailings) {
2828: if (exists($settings->{$type})) {
2829: if (ref($settings->{$type}) eq 'HASH') {
2830: foreach my $item (@contacts) {
2831: if ($settings->{$type}{$item}) {
2832: $checked{$type}{$item} = ' checked="checked" ';
2833: }
1.28 raeburn 2834: }
1.160.6.78 raeburn 2835: $otheremails{$type} = $settings->{$type}{'others'};
2836: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2837: $bccemails{$type} = $settings->{$type}{'bcc'};
2838: if ($settings->{$type}{'include'} ne '') {
2839: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2840: $includestr{$type} = &unescape($includestr{$type});
2841: }
2842: }
2843: }
2844: } elsif ($type eq 'lonstatusmail') {
2845: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2846: }
2847: }
2848: }
2849: if ($position eq 'bottom') {
2850: foreach my $type (@mailings) {
2851: $bccemails{$type} = $settings->{$type}{'bcc'};
2852: if ($settings->{$type}{'include'} ne '') {
2853: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2854: $includestr{$type} = &unescape($includestr{$type});
2855: }
2856: }
2857: if (ref($settings->{'helpform'}) eq 'HASH') {
2858: if (ref($fields) eq 'ARRAY') {
2859: foreach my $field (@{$fields}) {
2860: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 2861: }
1.160.6.78 raeburn 2862: }
2863: if (exists($settings->{'helpform'}{'maxsize'})) {
2864: $maxsize = $settings->{'helpform'}{'maxsize'};
2865: } else {
2866: $maxsize = '1.0';
2867: }
2868: } else {
2869: if (ref($fields) eq 'ARRAY') {
2870: foreach my $field (@{$fields}) {
2871: $currfield{$field} = 'yes';
1.134 raeburn 2872: }
1.28 raeburn 2873: }
1.160.6.78 raeburn 2874: $maxsize = '1.0';
1.28 raeburn 2875: }
2876: }
2877: } else {
1.160.6.78 raeburn 2878: if ($position eq 'top') {
2879: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2880: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2881: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2882: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2883: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2884: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2885: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2886: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
2887: } elsif ($position eq 'bottom') {
2888: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2889: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
2890: if (ref($fields) eq 'ARRAY') {
2891: foreach my $field (@{$fields}) {
2892: $currfield{$field} = 'yes';
2893: }
2894: }
2895: $maxsize = '1.0';
2896: }
1.28 raeburn 2897: }
2898: my ($titles,$short_titles) = &contact_titles();
2899: my $rownum = 0;
2900: my $css_class;
1.160.6.78 raeburn 2901: if ($position eq 'top') {
2902: foreach my $item (@contacts) {
2903: $css_class = $rownum%2?' class="LC_odd_row"':'';
2904: $datatable .= '<tr'.$css_class.'>'.
2905: '<td><span class="LC_nobreak">'.$titles->{$item}.
2906: '</span></td><td class="LC_right_item">'.
2907: '<input type="text" name="'.$item.'" value="'.
2908: $to{$item}.'" /></td></tr>';
2909: $rownum ++;
2910: }
2911: } else {
2912: foreach my $type (@mailings) {
2913: $css_class = $rownum%2?' class="LC_odd_row"':'';
2914: $datatable .= '<tr'.$css_class.'>'.
2915: '<td><span class="LC_nobreak">'.
2916: $titles->{$type}.': </span></td>'.
2917: '<td class="LC_left_item">';
2918: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2919: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
2920: }
2921: $datatable .= '<span class="LC_nobreak">';
2922: foreach my $item (@contacts) {
2923: $datatable .= '<label>'.
2924: '<input type="checkbox" name="'.$type.'"'.
2925: $checked{$type}{$item}.
2926: ' value="'.$item.'" />'.$short_titles->{$item}.
2927: '</label> ';
2928: }
2929: $datatable .= '</span><br />'.&mt('Others').': '.
2930: '<input type="text" name="'.$type.'_others" '.
2931: 'value="'.$otheremails{$type}.'" />';
2932: my %locchecked;
2933: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2934: foreach my $loc ('s','b') {
2935: if ($includeloc{$type} eq $loc) {
2936: $locchecked{$loc} = ' checked="checked"';
2937: last;
2938: }
2939: }
2940: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2941: '<input type="text" name="'.$type.'_bcc" '.
2942: 'value="'.$bccemails{$type}.'" /></fieldset>'.
2943: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
2944: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 2945: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 2946: '<span class="LC_nobreak">'.&mt('Location:').' '.
2947: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
2948: (' 'x2).
2949: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
2950: '</span></fieldset>';
2951: }
2952: $datatable .= '</td></tr>'."\n";
2953: $rownum ++;
2954: }
1.28 raeburn 2955: }
1.160.6.78 raeburn 2956: if ($position eq 'middle') {
2957: my %choices;
2958: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2959: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2960: &mt('LON-CAPA core group - MSU'),600,500));
2961: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2962: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2963: &mt('LON-CAPA core group - MSU'),600,500));
2964: my @toggles = ('reporterrors','reportupdates');
2965: my %defaultchecked = ('reporterrors' => 'on',
2966: 'reportupdates' => 'on');
2967: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2968: \%choices,$rownum);
2969: $datatable .= $reports;
2970: } elsif ($position eq 'bottom') {
1.69 raeburn 2971: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2972: $datatable .= '<tr'.$css_class.'>'.
1.160.6.78 raeburn 2973: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
2974: &mt('(e-mail, subject, and description always shown)').
2975: '</td><td class="LC_left_item">';
2976: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
2977: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
2978: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
2979: foreach my $field (@{$fields}) {
2980: $datatable .= '<tr><td>'.$fieldtitles->{$field};
2981: if (($field eq 'screenshot') || ($field eq 'cc')) {
2982: $datatable .= ' '.&mt('(logged-in users)');
2983: }
2984: $datatable .='</td><td>';
2985: my $clickaction;
2986: if ($field eq 'screenshot') {
2987: $clickaction = ' onclick="screenshotSize(this);"';
2988: }
2989: if (ref($possoptions->{$field}) eq 'ARRAY') {
2990: foreach my $option (@{$possoptions->{$field}}) {
2991: my $checked;
2992: if ($currfield{$field} eq $option) {
2993: $checked = ' checked="checked"';
2994: }
2995: $datatable .= '<span class="LC_nobreak"><label>'.
2996: '<input type="radio" name="helpform_'.$field.'" '.
2997: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
2998: '</label></span>'.(' 'x2);
2999: }
3000: }
3001: if ($field eq 'screenshot') {
3002: my $display;
3003: if ($currfield{$field} eq 'no') {
3004: $display = ' style="display:none"';
3005: }
1.160.6.87 raeburn 3006: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.160.6.78 raeburn 3007: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3008: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3009: }
3010: $datatable .= '</td></tr>';
3011: }
3012: $datatable .= '</table>';
1.134 raeburn 3013: }
3014: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 3015: $rownum ++;
1.28 raeburn 3016: }
1.30 raeburn 3017: $$rowtotal += $rownum;
1.28 raeburn 3018: return $datatable;
3019: }
3020:
1.160.6.78 raeburn 3021: sub contacts_javascript {
3022: return <<"ENDSCRIPT";
3023:
3024: <script type="text/javascript">
3025: // <![CDATA[
3026:
3027: function screenshotSize(field) {
3028: if (document.getElementById('help_screenshotsize')) {
3029: if (field.value == 'no') {
3030: document.getElementById('help_screenshotsize').style.display="none";
3031: } else {
3032: document.getElementById('help_screenshotsize').style.display="";
3033: }
3034: }
3035: return;
3036: }
3037:
3038: // ]]>
3039: </script>
3040:
3041: ENDSCRIPT
3042: }
3043:
1.118 jms 3044: sub print_helpsettings {
1.160.6.73 raeburn 3045: my ($position,$dom,$settings,$rowtotal) = @_;
3046: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3047: my $formname = 'display';
1.160.6.5 raeburn 3048: my ($datatable,$itemcount);
1.160.6.73 raeburn 3049: if ($position eq 'top') {
3050: $itemcount = 1;
3051: my (%choices,%defaultchecked,@toggles);
3052: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3053: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3054: &mt('LON-CAPA bug tracker'),600,500));
3055: %defaultchecked = ('submitbugs' => 'on');
3056: @toggles = ('submitbugs');
3057: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3058: \%choices,$itemcount);
3059: $$rowtotal ++;
3060: } else {
3061: my $css_class;
3062: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3063: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3064: if (ref($settings) eq 'HASH') {
3065: if (ref($settings->{'adhoc'}) eq 'HASH') {
3066: %current = %{$settings->{'adhoc'}};
3067: }
1.160.6.77 raeburn 3068: }
3069: my $count = 0;
3070: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3071: if ($key=~/^rolesdef\_(\w+)$/) {
3072: my $rolename = $1;
1.160.6.77 raeburn 3073: my (%privs,$order);
1.160.6.73 raeburn 3074: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3075: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3076: if (ref($current{$rolename}) eq 'HASH') {
3077: $order = $current{$rolename}{'order'};
3078: }
3079: if ($order eq '') {
3080: $order = $count;
3081: }
3082: $ordered{$order} = $rolename;
3083: $count++;
1.160.6.73 raeburn 3084: }
3085: }
1.160.6.77 raeburn 3086: my $maxnum = scalar(keys(%ordered));
3087: my @roles_by_num = ();
3088: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3089: push(@roles_by_num,$item);
3090: }
3091: my $context = 'domprefs';
3092: my $crstype = 'Course';
3093: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3094: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3095: my ($numstatustypes,@jsarray);
3096: if (ref($types) eq 'ARRAY') {
3097: if (@{$types} > 0) {
3098: $numstatustypes = scalar(@{$types});
3099: push(@accesstypes,'status');
3100: @jsarray = ('bystatus');
3101: }
3102: }
1.160.6.86 raeburn 3103: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3104: if (keys(%domhelpdesk)) {
3105: push(@accesstypes,('inc','exc'));
3106: push(@jsarray,('notinc','notexc'));
3107: }
3108: my $hiddenstr = join("','",@jsarray);
3109: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3110: my $context = 'domprefs';
3111: my $crstype = 'Course';
1.160.6.77 raeburn 3112: my $prefix = 'helproles_';
3113: my $add_class = 'LC_hidden';
3114: foreach my $num (@roles_by_num) {
3115: my $role = $ordered{$num};
3116: my ($desc,$access,@statuses);
3117: if (ref($current{$role}) eq 'HASH') {
3118: $desc = $current{$role}{'desc'};
3119: $access = $current{$role}{'access'};
3120: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3121: @statuses = @{$current{$role}{'insttypes'}};
3122: }
3123: }
3124: if ($desc eq '') {
3125: $desc = $role;
3126: }
3127: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3128: my %full=();
3129: my %levels= (
3130: course => {},
3131: domain => {},
3132: system => {},
3133: );
3134: my %levelscurrent=(
3135: course => {},
3136: domain => {},
3137: system => {},
3138: );
3139: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3140: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3141: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3142: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3143: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3144: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3145: for (my $k=0; $k<=$maxnum; $k++) {
3146: my $vpos = $k+1;
3147: my $selstr;
3148: if ($k == $num) {
3149: $selstr = ' selected="selected" ';
3150: }
3151: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3152: }
3153: $datatable .= '</select>'.(' 'x2).
3154: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3155: '</td>'.
3156: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3157: &mt('Name shown to users:').
3158: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3159: '</fieldset>'.
3160: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3161: $othertitle,$usertypes,$types,\%domhelpdesk).
3162: '<fieldset>'.
3163: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3164: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3165: \%levelscurrent,$identifier,
3166: 'LC_hidden',$prefix.$num.'_privs').
3167: '</fieldset></td>';
1.160.6.73 raeburn 3168: $itemcount ++;
3169: }
3170: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3171: my $newcust = 'custhelp'.$count;
3172: my (%privs,%levelscurrent);
3173: my %full=();
3174: my %levels= (
3175: course => {},
3176: domain => {},
3177: system => {},
3178: );
3179: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3180: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3181: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3182: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3183: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3184: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3185: for (my $k=0; $k<$maxnum+1; $k++) {
3186: my $vpos = $k+1;
3187: my $selstr;
3188: if ($k == $maxnum) {
3189: $selstr = ' selected="selected" ';
3190: }
3191: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3192: }
3193: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3194: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3195: '</label></span></td>'.
1.160.6.77 raeburn 3196: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3197: '<span class="LC_nobreak">'.
3198: &mt('Internal name:').
3199: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3200: '</span>'.(' 'x4).
3201: '<span class="LC_nobreak">'.
3202: &mt('Name shown to users:').
3203: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3204: '</span></fieldset>'.
3205: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3206: $usertypes,$types,\%domhelpdesk).
3207: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3208: &Apache::lonuserutils::custom_role_header($context,$crstype,
3209: \@templateroles,$newcust).
3210: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3211: \%levelscurrent,$newcust).
1.160.6.87 raeburn 3212: '</fieldset>'.
3213: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3214: '</td></tr>';
1.160.6.73 raeburn 3215: $count ++;
3216: $$rowtotal += $count;
3217: }
1.160.6.5 raeburn 3218: return $datatable;
1.121 raeburn 3219: }
3220:
1.160.6.77 raeburn 3221: sub adhocbutton {
3222: my ($prefix,$num,$field,$visibility) = @_;
3223: my %lt = &Apache::lonlocal::texthash(
3224: show => 'Show details',
3225: hide => 'Hide details',
3226: );
3227: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3228: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3229: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3230: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3231: }
3232:
3233: sub helpsettings_javascript {
3234: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3235: return unless(ref($roles_by_num) eq 'ARRAY');
3236: my %html_js_lt = &Apache::lonlocal::texthash(
3237: show => 'Show details',
3238: hide => 'Hide details',
3239: );
3240: &html_escape(\%html_js_lt);
3241: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3242: return <<"ENDSCRIPT";
3243: <script type="text/javascript">
3244: // <![CDATA[
3245:
3246: function reorderHelpRoles(form,item) {
3247: var changedVal;
3248: $jstext
3249: var newpos = 'helproles_${total}_pos';
3250: var maxh = 1 + $total;
3251: var current = new Array();
3252: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3253: if (item == newpos) {
3254: changedVal = newitemVal;
3255: } else {
3256: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3257: current[newitemVal] = newpos;
3258: }
3259: for (var i=0; i<helproles.length; i++) {
3260: var elementName = 'helproles_'+helproles[i]+'_pos';
3261: if (elementName != item) {
3262: if (form.elements[elementName]) {
3263: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3264: current[currVal] = elementName;
3265: }
3266: }
3267: }
3268: var oldVal;
3269: for (var j=0; j<maxh; j++) {
3270: if (current[j] == undefined) {
3271: oldVal = j;
3272: }
3273: }
3274: if (oldVal < changedVal) {
3275: for (var k=oldVal+1; k<=changedVal ; k++) {
3276: var elementName = current[k];
3277: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3278: }
3279: } else {
3280: for (var k=changedVal; k<oldVal; k++) {
3281: var elementName = current[k];
3282: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3283: }
3284: }
3285: return;
3286: }
3287:
3288: function helpdeskAccess(num) {
3289: var curraccess = null;
3290: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3291: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3292: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3293: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3294: }
3295: }
3296: }
3297: var shown = Array();
3298: var hidden = Array();
3299: if (curraccess == 'none') {
3300: hidden = Array('$hiddenstr');
3301: } else {
3302: if (curraccess == 'status') {
3303: shown = Array('bystatus');
3304: hidden = Array('notinc','notexc');
3305: } else {
3306: if (curraccess == 'exc') {
3307: shown = Array('notexc');
3308: hidden = Array('notinc','bystatus');
3309: }
3310: if (curraccess == 'inc') {
3311: shown = Array('notinc');
3312: hidden = Array('notexc','bystatus');
3313: }
1.160.6.79 raeburn 3314: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3315: hidden = Array('notinc','notexc','bystatus');
3316: }
3317: }
3318: }
3319: if (hidden.length > 0) {
3320: for (var i=0; i<hidden.length; i++) {
3321: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3322: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3323: }
3324: }
3325: }
3326: if (shown.length > 0) {
3327: for (var i=0; i<shown.length; i++) {
3328: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3329: if (shown[i] == 'privs') {
3330: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3331: } else {
3332: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3333: }
3334: }
3335: }
3336: }
3337: return;
3338: }
3339:
3340: function toggleHelpdeskItem(num,field) {
3341: if (document.getElementById('helproles_'+num+'_'+field)) {
3342: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3343: document.getElementById('helproles_'+num+'_'+field).className =
3344: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3345: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3346: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3347: }
3348: } else {
3349: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3350: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3351: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3352: }
3353: }
3354: }
3355: return;
3356: }
3357:
3358: // ]]>
3359: </script>
3360:
3361: ENDSCRIPT
3362: }
3363:
3364: sub helpdeskroles_access {
3365: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3366: $usertypes,$types,$domhelpdesk) = @_;
3367: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3368: my %lt = &Apache::lonlocal::texthash(
3369: 'rou' => 'Role usage',
3370: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3371: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3372: 'dh' => 'All with domain helpdesk role',
3373: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3374: 'none' => 'None',
3375: 'status' => 'Determined based on institutional status',
3376: 'inc' => 'Include all, but exclude specific personnel',
3377: 'exc' => 'Exclude all, but include specific personnel',
3378: );
3379: my %usecheck = (
3380: all => ' checked="checked"',
3381: );
3382: my %displaydiv = (
3383: status => 'none',
3384: inc => 'none',
3385: exc => 'none',
3386: priv => 'block',
3387: );
3388: my $output;
3389: if (ref($current) eq 'HASH') {
3390: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3391: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3392: $usecheck{$current->{access}} = $usecheck{'all'};
3393: delete($usecheck{'all'});
3394: if ($current->{access} =~ /^(status|inc|exc)$/) {
3395: my $access = $1;
3396: $displaydiv{$access} = 'inline';
3397: } elsif ($current->{access} eq 'none') {
3398: $displaydiv{'priv'} = 'none';
3399: }
3400: }
3401: }
3402: }
3403: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3404: '<p>'.$lt{'whi'}.'</p>';
3405: foreach my $access (@{$accesstypes}) {
3406: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3407: ' onclick="helpdeskAccess('."'$num'".');" />'.
3408: $lt{$access}.'</label>';
3409: if ($access eq 'status') {
3410: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3411: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3412: $othertitle,$usertypes,$types).
3413: '</div>';
3414: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3415: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3416: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3417: '</div>';
3418: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3419: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3420: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3421: '</div>';
3422: }
3423: $output .= '</p>';
3424: }
3425: $output .= '</fieldset>';
3426: return $output;
3427: }
3428:
1.121 raeburn 3429: sub radiobutton_prefs {
1.160.6.16 raeburn 3430: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3431: $additional,$align) = @_;
1.121 raeburn 3432: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3433: (ref($choices) eq 'HASH'));
3434:
3435: my (%checkedon,%checkedoff,$datatable,$css_class);
3436:
3437: foreach my $item (@{$toggles}) {
3438: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3439: $checkedon{$item} = ' checked="checked" ';
3440: $checkedoff{$item} = ' ';
1.121 raeburn 3441: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3442: $checkedoff{$item} = ' checked="checked" ';
3443: $checkedon{$item} = ' ';
3444: }
3445: }
3446: if (ref($settings) eq 'HASH') {
1.121 raeburn 3447: foreach my $item (@{$toggles}) {
1.118 jms 3448: if ($settings->{$item} eq '1') {
3449: $checkedon{$item} = ' checked="checked" ';
3450: $checkedoff{$item} = ' ';
3451: } elsif ($settings->{$item} eq '0') {
3452: $checkedoff{$item} = ' checked="checked" ';
3453: $checkedon{$item} = ' ';
3454: }
3455: }
1.121 raeburn 3456: }
1.160.6.16 raeburn 3457: if ($onclick) {
3458: $onclick = ' onclick="'.$onclick.'"';
3459: }
1.121 raeburn 3460: foreach my $item (@{$toggles}) {
1.118 jms 3461: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3462: $datatable .=
1.160.6.16 raeburn 3463: '<tr'.$css_class.'><td valign="top">'.
3464: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3465: '</span></td>';
3466: if ($align eq 'left') {
3467: $datatable .= '<td class="LC_left_item">';
3468: } else {
3469: $datatable .= '<td class="LC_right_item">';
3470: }
3471: $datatable .=
3472: '<span class="LC_nobreak">'.
1.118 jms 3473: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3474: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3475: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3476: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3477: '</span>'.$additional.
3478: '</td>'.
1.118 jms 3479: '</tr>';
3480: $itemcount ++;
1.121 raeburn 3481: }
3482: return ($datatable,$itemcount);
3483: }
3484:
3485: sub print_coursedefaults {
1.139 raeburn 3486: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3487: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3488: my $itemcount = 1;
1.160.6.16 raeburn 3489: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3490: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3491: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3492: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3493: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3494: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3495: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3496: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3497: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3498: );
1.160.6.21 raeburn 3499: my %staticdefaults = (
3500: anonsurvey_threshold => 10,
3501: uploadquota => 500,
1.160.6.57 raeburn 3502: postsubmit => 60,
1.160.6.70 raeburn 3503: mysqltables => 172800,
1.160.6.21 raeburn 3504: );
1.139 raeburn 3505: if ($position eq 'top') {
1.160.6.57 raeburn 3506: %defaultchecked = (
3507: 'uselcmath' => 'on',
3508: 'usejsme' => 'on',
1.160.6.64 raeburn 3509: 'canclone' => 'none',
1.160.6.57 raeburn 3510: );
3511: @toggles = ('uselcmath','usejsme');
1.139 raeburn 3512: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3513: \%choices,$itemcount);
1.160.6.64 raeburn 3514: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3515: $datatable .=
3516: '<tr'.$css_class.'><td valign="top">'.
3517: '<span class="LC_nobreak">'.$choices{'canclone'}.
3518: '</span></td><td class="LC_left_item">';
3519: my $currcanclone = 'none';
3520: my $onclick;
3521: my @cloneoptions = ('none','domain');
3522: my %clonetitles = (
3523: none => 'No additional course requesters',
3524: domain => "Any course requester in course's domain",
3525: instcode => 'Course requests for official courses ...',
3526: );
3527: my (%codedefaults,@code_order,@posscodes);
3528: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3529: \@code_order) eq 'ok') {
3530: if (@code_order > 0) {
3531: push(@cloneoptions,'instcode');
3532: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3533: }
3534: }
3535: if (ref($settings) eq 'HASH') {
3536: if ($settings->{'canclone'}) {
3537: if (ref($settings->{'canclone'}) eq 'HASH') {
3538: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3539: if (@code_order > 0) {
3540: $currcanclone = 'instcode';
3541: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3542: }
3543: }
3544: } elsif ($settings->{'canclone'} eq 'domain') {
3545: $currcanclone = $settings->{'canclone'};
3546: }
3547: }
3548: }
3549: foreach my $option (@cloneoptions) {
3550: my ($checked,$additional);
3551: if ($currcanclone eq $option) {
3552: $checked = ' checked="checked"';
3553: }
3554: if ($option eq 'instcode') {
3555: if (@code_order) {
3556: my $show = 'none';
3557: if ($checked) {
3558: $show = 'block';
3559: }
3560: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3561: &mt('Institutional codes for new and cloned course have identical:').
3562: '<br />';
3563: foreach my $item (@code_order) {
3564: my $codechk;
3565: if ($checked) {
3566: if (grep(/^\Q$item\E$/,@posscodes)) {
3567: $codechk = ' checked="checked"';
3568: }
3569: }
3570: $additional .= '<label>'.
3571: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3572: $item.'</label>';
3573: }
3574: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3575: }
3576: }
3577: $datatable .=
3578: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3579: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3580: '</label> '.$additional.'</span><br />';
3581: }
3582: $datatable .= '</td>'.
3583: '</tr>';
3584: $itemcount ++;
1.139 raeburn 3585: } else {
3586: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3587: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3588: my $currusecredits = 0;
1.160.6.57 raeburn 3589: my $postsubmitclient = 1;
1.160.6.30 raeburn 3590: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3591: if (ref($settings) eq 'HASH') {
3592: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3593: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3594: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3595: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3596: }
3597: }
1.160.6.16 raeburn 3598: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3599: foreach my $type (@types) {
3600: next if ($type eq 'community');
3601: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3602: if ($defcredits{$type} ne '') {
3603: $currusecredits = 1;
3604: }
3605: }
3606: }
3607: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3608: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3609: $postsubmitclient = 0;
3610: foreach my $type (@types) {
3611: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3612: }
3613: } else {
3614: foreach my $type (@types) {
3615: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3616: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3617: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3618: } else {
3619: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3620: }
3621: } else {
3622: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3623: }
3624: }
3625: }
3626: } else {
3627: foreach my $type (@types) {
3628: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3629: }
3630: }
1.160.6.70 raeburn 3631: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3632: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3633: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3634: }
3635: } else {
3636: foreach my $type (@types) {
3637: $currmysql{$type} = $staticdefaults{'mysqltables'};
3638: }
3639: }
1.160.6.58 raeburn 3640: } else {
3641: foreach my $type (@types) {
3642: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3643: }
1.139 raeburn 3644: }
3645: if (!$currdefresponder) {
1.160.6.21 raeburn 3646: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3647: } elsif ($currdefresponder < 1) {
3648: $currdefresponder = 1;
3649: }
1.160.6.21 raeburn 3650: foreach my $type (@types) {
3651: if ($curruploadquota{$type} eq '') {
3652: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3653: }
3654: }
1.139 raeburn 3655: $datatable .=
1.160.6.16 raeburn 3656: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3657: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3658: '</span></td>'.
3659: '<td class="LC_right_item"><span class="LC_nobreak">'.
3660: '<input type="text" name="anonsurvey_threshold"'.
3661: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3662: '</td></tr>'."\n";
3663: $itemcount ++;
3664: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3665: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3666: $choices{'uploadquota'}.
3667: '</span></td>'.
3668: '<td align="right" class="LC_right_item">'.
3669: '<table><tr>';
1.160.6.21 raeburn 3670: foreach my $type (@types) {
3671: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3672: '<input type="text" name="uploadquota_'.$type.'"'.
3673: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3674: }
3675: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3676: $itemcount ++;
1.160.6.40 raeburn 3677: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3678: my $display = 'none';
3679: if ($currusecredits) {
3680: $display = 'block';
3681: }
3682: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3683: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3684: foreach my $type (@types) {
3685: next if ($type eq 'community');
3686: $additional .= '<td align="center">'.&mt($type).'<br />'.
3687: '<input type="text" name="'.$type.'_credits"'.
3688: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3689: }
3690: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3691: %defaultchecked = ('coursecredits' => 'off');
3692: @toggles = ('coursecredits');
3693: my $current = {
3694: 'coursecredits' => $currusecredits,
3695: };
3696: (my $table,$itemcount) =
3697: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3698: \%choices,$itemcount,$onclick,$additional,'left');
3699: $datatable .= $table;
3700: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3701: my $display = 'none';
3702: if ($postsubmitclient) {
3703: $display = 'block';
3704: }
3705: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3706: &mt('Number of seconds submit is disabled').'<br />'.
3707: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3708: '<table><tr>';
1.160.6.57 raeburn 3709: foreach my $type (@types) {
3710: $additional .= '<td align="center">'.&mt($type).'<br />'.
3711: '<input type="text" name="'.$type.'_timeout" value="'.
3712: $deftimeout{$type}.'" size="5" /></td>';
3713: }
3714: $additional .= '</tr></table></div>'."\n";
3715: %defaultchecked = ('postsubmit' => 'on');
3716: @toggles = ('postsubmit');
1.160.6.70 raeburn 3717: $current = {
3718: 'postsubmit' => $postsubmitclient,
3719: };
1.160.6.57 raeburn 3720: ($table,$itemcount) =
3721: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3722: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3723: $datatable .= $table;
1.160.6.70 raeburn 3724: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3725: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3726: $choices{'mysqltables'}.
3727: '</span></td>'.
3728: '<td align="right" class="LC_right_item">'.
3729: '<table><tr>';
3730: foreach my $type (@types) {
3731: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3732: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 3733: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 3734: }
3735: $datatable .= '</tr></table></td></tr>'."\n";
3736: $itemcount ++;
3737:
1.160.6.37 raeburn 3738: }
3739: $$rowtotal += $itemcount;
3740: return $datatable;
3741: }
3742:
3743: sub print_selfenrollment {
3744: my ($position,$dom,$settings,$rowtotal) = @_;
3745: my ($css_class,$datatable);
3746: my $itemcount = 1;
3747: my @types = ('official','unofficial','community','textbook');
3748: if (($position eq 'top') || ($position eq 'middle')) {
3749: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3750: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3751: my @rows;
3752: my $key;
3753: if ($position eq 'top') {
3754: $key = 'admin';
3755: if (ref($rowsref) eq 'ARRAY') {
3756: @rows = @{$rowsref};
3757: }
3758: } elsif ($position eq 'middle') {
3759: $key = 'default';
3760: @rows = ('types','registered','approval','limit');
3761: }
3762: foreach my $row (@rows) {
3763: if (defined($titlesref->{$row})) {
3764: $itemcount ++;
3765: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3766: $datatable .= '<tr'.$css_class.'>'.
3767: '<td>'.$titlesref->{$row}.'</td>'.
3768: '<td class="LC_left_item">'.
3769: '<table><tr>';
3770: my (%current,%currentcap);
3771: if (ref($settings) eq 'HASH') {
3772: if (ref($settings->{$key}) eq 'HASH') {
3773: foreach my $type (@types) {
3774: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3775: $current{$type} = $settings->{$key}->{$type}->{$row};
3776: }
3777: if (($row eq 'limit') && ($key eq 'default')) {
3778: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3779: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3780: }
3781: }
3782: }
3783: }
3784: }
3785: my %roles = (
3786: '0' => &Apache::lonnet::plaintext('dc'),
3787: );
3788:
3789: foreach my $type (@types) {
3790: unless (($row eq 'registered') && ($key eq 'default')) {
3791: $datatable .= '<th>'.&mt($type).'</th>';
3792: }
3793: }
3794: unless (($row eq 'registered') && ($key eq 'default')) {
3795: $datatable .= '</tr><tr>';
3796: }
3797: foreach my $type (@types) {
3798: if ($type eq 'community') {
3799: $roles{'1'} = &mt('Community personnel');
3800: } else {
3801: $roles{'1'} = &mt('Course personnel');
3802: }
3803: $datatable .= '<td style="vertical-align: top">';
3804: if ($position eq 'top') {
3805: my %checked;
3806: if ($current{$type} eq '0') {
3807: $checked{'0'} = ' checked="checked"';
3808: } else {
3809: $checked{'1'} = ' checked="checked"';
3810: }
3811: foreach my $role ('1','0') {
3812: $datatable .= '<span class="LC_nobreak"><label>'.
3813: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3814: 'value="'.$role.'"'.$checked{$role}.' />'.
3815: $roles{$role}.'</label></span> ';
3816: }
3817: } else {
3818: if ($row eq 'types') {
3819: my %checked;
3820: if ($current{$type} =~ /^(all|dom)$/) {
3821: $checked{$1} = ' checked="checked"';
3822: } else {
3823: $checked{''} = ' checked="checked"';
3824: }
3825: foreach my $val ('','dom','all') {
3826: $datatable .= '<span class="LC_nobreak"><label>'.
3827: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3828: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3829: }
3830: } elsif ($row eq 'registered') {
3831: my %checked;
3832: if ($current{$type} eq '1') {
3833: $checked{'1'} = ' checked="checked"';
3834: } else {
3835: $checked{'0'} = ' checked="checked"';
3836: }
3837: foreach my $val ('0','1') {
3838: $datatable .= '<span class="LC_nobreak"><label>'.
3839: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3840: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3841: }
3842: } elsif ($row eq 'approval') {
3843: my %checked;
3844: if ($current{$type} =~ /^([12])$/) {
3845: $checked{$1} = ' checked="checked"';
3846: } else {
3847: $checked{'0'} = ' checked="checked"';
3848: }
3849: for my $val (0..2) {
3850: $datatable .= '<span class="LC_nobreak"><label>'.
3851: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3852: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3853: }
3854: } elsif ($row eq 'limit') {
3855: my %checked;
3856: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3857: $checked{$1} = ' checked="checked"';
3858: } else {
3859: $checked{'none'} = ' checked="checked"';
3860: }
3861: my $cap;
3862: if ($currentcap{$type} =~ /^\d+$/) {
3863: $cap = $currentcap{$type};
3864: }
3865: foreach my $val ('none','allstudents','selfenrolled') {
3866: $datatable .= '<span class="LC_nobreak"><label>'.
3867: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3868: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3869: }
3870: $datatable .= '<br />'.
3871: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3872: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3873: '</span>';
3874: }
3875: }
3876: $datatable .= '</td>';
3877: }
3878: $datatable .= '</tr>';
3879: }
3880: $datatable .= '</table></td></tr>';
3881: }
3882: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3883: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3884: }
3885: $$rowtotal += $itemcount;
3886: return $datatable;
3887: }
3888:
3889: sub print_validation_rows {
3890: my ($caller,$dom,$settings,$rowtotal) = @_;
3891: my ($itemsref,$namesref,$fieldsref);
3892: if ($caller eq 'selfenroll') {
3893: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3894: } elsif ($caller eq 'requestcourses') {
3895: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3896: }
3897: my %currvalidation;
3898: if (ref($settings) eq 'HASH') {
3899: if (ref($settings->{'validation'}) eq 'HASH') {
3900: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3901: }
1.160.6.39 raeburn 3902: }
3903: my $datatable;
3904: my $itemcount = 0;
3905: foreach my $item (@{$itemsref}) {
3906: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3907: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3908: $namesref->{$item}.
3909: '</span></td>'.
3910: '<td class="LC_left_item">';
3911: if (($item eq 'url') || ($item eq 'button')) {
3912: $datatable .= '<span class="LC_nobreak">'.
3913: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3914: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3915: } elsif ($item eq 'fields') {
3916: my @currfields;
3917: if (ref($currvalidation{$item}) eq 'ARRAY') {
3918: @currfields = @{$currvalidation{$item}};
3919: }
3920: foreach my $field (@{$fieldsref}) {
3921: my $check = '';
3922: if (grep(/^\Q$field\E$/,@currfields)) {
3923: $check = ' checked="checked"';
3924: }
3925: $datatable .= '<span class="LC_nobreak"><label>'.
3926: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3927: ' value="'.$field.'"'.$check.' />'.$field.
3928: '</label></span> ';
3929: }
3930: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 3931: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 3932: $currvalidation{$item}.
1.160.6.37 raeburn 3933: '</textarea>';
1.160.6.39 raeburn 3934: }
3935: $datatable .= '</td></tr>'."\n";
3936: if (ref($rowtotal)) {
1.160.6.37 raeburn 3937: $itemcount ++;
3938: }
1.139 raeburn 3939: }
1.160.6.39 raeburn 3940: if ($caller eq 'requestcourses') {
3941: my %currhash;
1.160.6.51 raeburn 3942: if (ref($settings) eq 'HASH') {
3943: if (ref($settings->{'validation'}) eq 'HASH') {
3944: if ($settings->{'validation'}{'dc'} ne '') {
3945: $currhash{$settings->{'validation'}{'dc'}} = 1;
3946: }
1.160.6.39 raeburn 3947: }
3948: }
3949: my $numinrow = 2;
3950: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3951: 'validationdc',%currhash);
1.160.6.50 raeburn 3952: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 3953: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 3954: if ($numdc > 1) {
1.160.6.50 raeburn 3955: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3956: } else {
1.160.6.50 raeburn 3957: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3958: }
1.160.6.50 raeburn 3959: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3960: $itemcount ++;
3961: }
3962: if (ref($rowtotal)) {
3963: $$rowtotal += $itemcount;
3964: }
1.121 raeburn 3965: return $datatable;
1.118 jms 3966: }
3967:
1.137 raeburn 3968: sub print_usersessions {
3969: my ($position,$dom,$settings,$rowtotal) = @_;
3970: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3971: my (%by_ip,%by_location,@intdoms);
3972: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3973:
3974: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3975: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3976: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3977: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3978: my $itemcount = 1;
3979: if ($position eq 'top') {
1.152 raeburn 3980: if (keys(%serverhomes) > 1) {
1.145 raeburn 3981: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 3982: my $curroffloadnow;
3983: if (ref($settings) eq 'HASH') {
3984: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3985: $curroffloadnow = $settings->{'offloadnow'};
3986: }
3987: }
3988: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3989: } else {
1.140 raeburn 3990: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3991: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3992: }
1.137 raeburn 3993: } else {
1.145 raeburn 3994: if (keys(%by_location) == 0) {
3995: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3996: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3997: } else {
3998: my %lt = &usersession_titles();
3999: my $numinrow = 5;
4000: my $prefix;
4001: my @types;
4002: if ($position eq 'bottom') {
4003: $prefix = 'remote';
4004: @types = ('version','excludedomain','includedomain');
4005: } else {
4006: $prefix = 'hosted';
4007: @types = ('excludedomain','includedomain');
4008: }
4009: my (%current,%checkedon,%checkedoff);
4010: my @lcversions = &Apache::lonnet::all_loncaparevs();
4011: my @locations = sort(keys(%by_location));
4012: foreach my $type (@types) {
4013: $checkedon{$type} = '';
4014: $checkedoff{$type} = ' checked="checked"';
4015: }
4016: if (ref($settings) eq 'HASH') {
4017: if (ref($settings->{$prefix}) eq 'HASH') {
4018: foreach my $key (keys(%{$settings->{$prefix}})) {
4019: $current{$key} = $settings->{$prefix}{$key};
4020: if ($key eq 'version') {
4021: if ($current{$key} ne '') {
4022: $checkedon{$key} = ' checked="checked"';
4023: $checkedoff{$key} = '';
4024: }
4025: } elsif (ref($current{$key}) eq 'ARRAY') {
4026: $checkedon{$key} = ' checked="checked"';
4027: $checkedoff{$key} = '';
4028: }
1.137 raeburn 4029: }
4030: }
4031: }
1.145 raeburn 4032: foreach my $type (@types) {
4033: next if ($type ne 'version' && !@locations);
4034: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4035: $datatable .= '<tr'.$css_class.'>
4036: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4037: <span class="LC_nobreak">
4038: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4039: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4040: if ($type eq 'version') {
4041: my $selector = '<select name="'.$prefix.'_version">';
4042: foreach my $version (@lcversions) {
4043: my $selected = '';
4044: if ($current{'version'} eq $version) {
4045: $selected = ' selected="selected"';
4046: }
4047: $selector .= ' <option value="'.$version.'"'.
4048: $selected.'>'.$version.'</option>';
4049: }
4050: $selector .= '</select> ';
4051: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4052: } else {
4053: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4054: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4055: ' />'.(' 'x2).
4056: '<input type="button" value="'.&mt('uncheck all').'" '.
4057: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4058: "\n".
4059: '</div><div><table>';
4060: my $rem;
4061: for (my $i=0; $i<@locations; $i++) {
4062: my ($showloc,$value,$checkedtype);
4063: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4064: my $ip = $by_location{$locations[$i]}->[0];
4065: if (ref($by_ip{$ip}) eq 'ARRAY') {
4066: $value = join(':',@{$by_ip{$ip}});
4067: $showloc = join(', ',@{$by_ip{$ip}});
4068: if (ref($current{$type}) eq 'ARRAY') {
4069: foreach my $loc (@{$by_ip{$ip}}) {
4070: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4071: $checkedtype = ' checked="checked"';
4072: last;
4073: }
4074: }
1.138 raeburn 4075: }
4076: }
4077: }
1.145 raeburn 4078: $rem = $i%($numinrow);
4079: if ($rem == 0) {
4080: if ($i > 0) {
4081: $datatable .= '</tr>';
4082: }
4083: $datatable .= '<tr>';
4084: }
4085: $datatable .= '<td class="LC_left_item">'.
4086: '<span class="LC_nobreak"><label>'.
4087: '<input type="checkbox" name="'.$prefix.'_'.$type.
4088: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4089: '</label></span></td>';
1.137 raeburn 4090: }
1.145 raeburn 4091: $rem = @locations%($numinrow);
4092: my $colsleft = $numinrow - $rem;
4093: if ($colsleft > 1 ) {
4094: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4095: ' </td>';
4096: } elsif ($colsleft == 1) {
4097: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4098: }
1.145 raeburn 4099: $datatable .= '</tr></table>';
1.137 raeburn 4100: }
1.145 raeburn 4101: $datatable .= '</td></tr>';
4102: $itemcount ++;
1.137 raeburn 4103: }
4104: }
4105: }
4106: $$rowtotal += $itemcount;
4107: return $datatable;
4108: }
4109:
1.138 raeburn 4110: sub build_location_hashes {
4111: my ($intdoms,$by_ip,$by_location) = @_;
4112: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4113: (ref($by_location) eq 'HASH'));
4114: my %iphost = &Apache::lonnet::get_iphost();
4115: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4116: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4117: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4118: foreach my $id (@{$iphost{$primary_ip}}) {
4119: my $intdom = &Apache::lonnet::internet_dom($id);
4120: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4121: push(@{$intdoms},$intdom);
4122: }
4123: }
4124: }
4125: foreach my $ip (keys(%iphost)) {
4126: if (ref($iphost{$ip}) eq 'ARRAY') {
4127: foreach my $id (@{$iphost{$ip}}) {
4128: my $location = &Apache::lonnet::internet_dom($id);
4129: if ($location) {
4130: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4131: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4132: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4133: push(@{$by_ip->{$ip}},$location);
4134: }
4135: } else {
4136: $by_ip->{$ip} = [$location];
4137: }
4138: }
4139: }
4140: }
4141: }
4142: foreach my $ip (sort(keys(%{$by_ip}))) {
4143: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4144: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4145: my $first = $by_ip->{$ip}->[0];
4146: if (ref($by_location->{$first}) eq 'ARRAY') {
4147: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4148: push(@{$by_location->{$first}},$ip);
4149: }
4150: } else {
4151: $by_location->{$first} = [$ip];
4152: }
4153: }
4154: }
4155: return;
4156: }
4157:
1.145 raeburn 4158: sub current_offloads_to {
4159: my ($dom,$settings,$servers) = @_;
4160: my (%spareid,%otherdomconfigs);
1.152 raeburn 4161: if (ref($servers) eq 'HASH') {
1.145 raeburn 4162: foreach my $lonhost (sort(keys(%{$servers}))) {
4163: my $gotspares;
1.152 raeburn 4164: if (ref($settings) eq 'HASH') {
4165: if (ref($settings->{'spares'}) eq 'HASH') {
4166: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4167: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4168: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4169: $gotspares = 1;
4170: }
1.145 raeburn 4171: }
4172: }
4173: unless ($gotspares) {
4174: my $gotspares;
4175: my $serverhomeID =
4176: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4177: my $serverhomedom =
4178: &Apache::lonnet::host_domain($serverhomeID);
4179: if ($serverhomedom ne $dom) {
4180: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4181: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4182: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4183: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4184: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4185: $gotspares = 1;
4186: }
4187: }
4188: } else {
4189: $otherdomconfigs{$serverhomedom} =
4190: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4191: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4192: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4193: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4194: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4195: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4196: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4197: $gotspares = 1;
4198: }
4199: }
4200: }
4201: }
4202: }
4203: }
4204: }
4205: unless ($gotspares) {
4206: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4207: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4208: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4209: } else {
4210: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4211: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4212: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4213: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4214: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4215: } else {
1.150 raeburn 4216: my %what = (
4217: spareid => 1,
4218: );
4219: my ($result,$returnhash) =
4220: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4221: if ($result eq 'ok') {
4222: if (ref($returnhash) eq 'HASH') {
4223: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4224: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4225: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4226: }
4227: }
1.145 raeburn 4228: }
4229: }
4230: }
4231: }
4232: }
4233: }
4234: return %spareid;
4235: }
4236:
4237: sub spares_row {
1.160.6.61 raeburn 4238: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4239: my $css_class;
4240: my $numinrow = 4;
4241: my $itemcount = 1;
4242: my $datatable;
1.152 raeburn 4243: my %typetitles = &sparestype_titles();
4244: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4245: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4246: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4247: my ($othercontrol,$serverdom);
4248: if ($serverhome ne $server) {
4249: $serverdom = &Apache::lonnet::host_domain($serverhome);
4250: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4251: } else {
4252: $serverdom = &Apache::lonnet::host_domain($server);
4253: if ($serverdom ne $dom) {
4254: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4255: }
4256: }
4257: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4258: my $checkednow;
4259: if (ref($curroffloadnow) eq 'HASH') {
4260: if ($curroffloadnow->{$server}) {
4261: $checkednow = ' checked="checked"';
4262: }
4263: }
1.145 raeburn 4264: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4265: $datatable .= '<tr'.$css_class.'>
4266: <td rowspan="2">
1.160.6.13 raeburn 4267: <span class="LC_nobreak">'.
4268: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4269: ,'<b>'.$server.'</b>').'</span><br />'.
4270: '<span class="LC_nobreak">'."\n".
4271: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4272: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4273: "\n";
1.145 raeburn 4274: my (%current,%canselect);
1.152 raeburn 4275: my @choices =
4276: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4277: foreach my $type ('primary','default') {
4278: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4279: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4280: my @spares = @{$spareid->{$server}{$type}};
4281: if (@spares > 0) {
1.152 raeburn 4282: if ($othercontrol) {
4283: $current{$type} = join(', ',@spares);
4284: } else {
4285: $current{$type} .= '<table>';
4286: my $numspares = scalar(@spares);
4287: for (my $i=0; $i<@spares; $i++) {
4288: my $rem = $i%($numinrow);
4289: if ($rem == 0) {
4290: if ($i > 0) {
4291: $current{$type} .= '</tr>';
4292: }
4293: $current{$type} .= '<tr>';
1.145 raeburn 4294: }
1.152 raeburn 4295: $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'".');" /> '.
4296: $spareid->{$server}{$type}[$i].
4297: '</label></td>'."\n";
4298: }
4299: my $rem = @spares%($numinrow);
4300: my $colsleft = $numinrow - $rem;
4301: if ($colsleft > 1 ) {
4302: $current{$type} .= '<td colspan="'.$colsleft.
4303: '" class="LC_left_item">'.
4304: ' </td>';
4305: } elsif ($colsleft == 1) {
4306: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4307: }
1.152 raeburn 4308: $current{$type} .= '</tr></table>';
1.150 raeburn 4309: }
1.145 raeburn 4310: }
4311: }
4312: if ($current{$type} eq '') {
4313: $current{$type} = &mt('None specified');
4314: }
1.152 raeburn 4315: if ($othercontrol) {
4316: if ($type eq 'primary') {
4317: $canselect{$type} = $othercontrol;
4318: }
4319: } else {
4320: $canselect{$type} =
4321: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4322: '<select name="newspare_'.$type.'_'.$server.'" '.
4323: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4324: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4325: if (@choices > 0) {
4326: foreach my $lonhost (@choices) {
4327: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4328: }
4329: }
4330: $canselect{$type} .= '</select>'."\n";
4331: }
4332: } else {
4333: $current{$type} = &mt('Could not be determined');
4334: if ($type eq 'primary') {
4335: $canselect{$type} = $othercontrol;
4336: }
1.145 raeburn 4337: }
1.152 raeburn 4338: if ($type eq 'default') {
4339: $datatable .= '<tr'.$css_class.'>';
4340: }
4341: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4342: '<td>'.$current{$type}.'</td>'."\n".
4343: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4344: }
4345: $itemcount ++;
4346: }
4347: }
4348: $$rowtotal += $itemcount;
4349: return $datatable;
4350: }
4351:
1.152 raeburn 4352: sub possible_newspares {
4353: my ($server,$currspares,$serverhomes,$altids) = @_;
4354: my $serverhostname = &Apache::lonnet::hostname($server);
4355: my %excluded;
4356: if ($serverhostname ne '') {
4357: %excluded = (
4358: $serverhostname => 1,
4359: );
4360: }
4361: if (ref($currspares) eq 'HASH') {
4362: foreach my $type (keys(%{$currspares})) {
4363: if (ref($currspares->{$type}) eq 'ARRAY') {
4364: if (@{$currspares->{$type}} > 0) {
4365: foreach my $curr (@{$currspares->{$type}}) {
4366: my $hostname = &Apache::lonnet::hostname($curr);
4367: $excluded{$hostname} = 1;
4368: }
4369: }
4370: }
4371: }
4372: }
4373: my @choices;
4374: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4375: if (keys(%{$serverhomes}) > 1) {
4376: foreach my $name (sort(keys(%{$serverhomes}))) {
4377: unless ($excluded{$name}) {
4378: if (exists($altids->{$serverhomes->{$name}})) {
4379: push(@choices,$altids->{$serverhomes->{$name}});
4380: } else {
4381: push(@choices,$serverhomes->{$name});
1.145 raeburn 4382: }
4383: }
4384: }
4385: }
4386: }
1.152 raeburn 4387: return sort(@choices);
1.145 raeburn 4388: }
4389:
1.150 raeburn 4390: sub print_loadbalancing {
4391: my ($dom,$settings,$rowtotal) = @_;
4392: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4393: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4394: my $numinrow = 1;
4395: my $datatable;
4396: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 4397: my (%currbalancer,%currtargets,%currrules,%existing);
4398: if (ref($settings) eq 'HASH') {
4399: %existing = %{$settings};
4400: }
4401: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4402: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4403: \%currtargets,\%currrules);
1.150 raeburn 4404: } else {
4405: return;
4406: }
4407: my ($othertitle,$usertypes,$types) =
4408: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 4409: my $rownum = 8;
1.150 raeburn 4410: if (ref($types) eq 'ARRAY') {
4411: $rownum += scalar(@{$types});
4412: }
1.160.6.7 raeburn 4413: my @css_class = ('LC_odd_row','LC_even_row');
4414: my $balnum = 0;
4415: my $islast;
4416: my (@toshow,$disabledtext);
4417: if (keys(%currbalancer) > 0) {
4418: @toshow = sort(keys(%currbalancer));
4419: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4420: push(@toshow,'');
4421: }
4422: } else {
4423: @toshow = ('');
4424: $disabledtext = &mt('No existing load balancer');
4425: }
4426: foreach my $lonhost (@toshow) {
4427: if ($balnum == scalar(@toshow)-1) {
4428: $islast = 1;
4429: } else {
4430: $islast = 0;
4431: }
4432: my $cssidx = $balnum%2;
4433: my $targets_div_style = 'display: none';
4434: my $disabled_div_style = 'display: block';
4435: my $homedom_div_style = 'display: none';
4436: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4437: '<td rowspan="'.$rownum.'" valign="top">'.
4438: '<p>';
4439: if ($lonhost eq '') {
4440: $datatable .= '<span class="LC_nobreak">';
4441: if (keys(%currbalancer) > 0) {
4442: $datatable .= &mt('Add balancer:');
4443: } else {
4444: $datatable .= &mt('Enable balancer:');
4445: }
4446: $datatable .= ' '.
4447: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4448: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4449: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4450: '<option value="" selected="selected">'.&mt('None').
4451: '</option>'."\n";
4452: foreach my $server (sort(keys(%servers))) {
4453: next if ($currbalancer{$server});
4454: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4455: }
4456: $datatable .=
4457: '</select>'."\n".
4458: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4459: } else {
4460: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4461: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4462: &mt('Stop balancing').'</label>'.
4463: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4464: $targets_div_style = 'display: block';
4465: $disabled_div_style = 'display: none';
4466: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4467: $homedom_div_style = 'display: block';
4468: }
4469: }
4470: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4471: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4472: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4473: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4474: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4475: my @sparestypes = ('primary','default');
4476: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 4477: my %hostherechecked = (
4478: no => ' checked="checked"',
4479: );
1.160.6.7 raeburn 4480: foreach my $sparetype (@sparestypes) {
4481: my $targettable;
4482: for (my $i=0; $i<$numspares; $i++) {
4483: my $checked;
4484: if (ref($currtargets{$lonhost}) eq 'HASH') {
4485: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4486: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4487: $checked = ' checked="checked"';
4488: }
4489: }
4490: }
4491: my ($chkboxval,$disabled);
4492: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4493: $chkboxval = $spares[$i];
4494: }
4495: if (exists($currbalancer{$spares[$i]})) {
4496: $disabled = ' disabled="disabled"';
4497: }
4498: $targettable .=
1.160.6.55 raeburn 4499: '<td><span class="LC_nobreak"><label>'.
4500: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 4501: $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 4502: '</span></label></span></td>';
1.160.6.7 raeburn 4503: my $rem = $i%($numinrow);
4504: if ($rem == 0) {
4505: if (($i > 0) && ($i < $numspares-1)) {
4506: $targettable .= '</tr>';
4507: }
4508: if ($i < $numspares-1) {
4509: $targettable .= '<tr>';
1.150 raeburn 4510: }
4511: }
4512: }
1.160.6.7 raeburn 4513: if ($targettable ne '') {
4514: my $rem = $numspares%($numinrow);
4515: my $colsleft = $numinrow - $rem;
4516: if ($colsleft > 1 ) {
4517: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4518: ' </td>';
4519: } elsif ($colsleft == 1) {
4520: $targettable .= '<td class="LC_left_item"> </td>';
4521: }
4522: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4523: '<table><tr>'.$targettable.'</tr></table><br />';
4524: }
1.160.6.76 raeburn 4525: $hostherechecked{$sparetype} = '';
4526: if (ref($currtargets{$lonhost}) eq 'HASH') {
4527: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4528: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4529: $hostherechecked{$sparetype} = ' checked="checked"';
4530: $hostherechecked{'no'} = '';
4531: }
4532: }
4533: }
4534: }
4535: $datatable .= &mt('Hosting on balancer itself').'<br />'.
4536: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
4537: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
4538: foreach my $sparetype (@sparestypes) {
4539: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
4540: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
4541: '</i></label><br />';
1.160.6.7 raeburn 4542: }
4543: $datatable .= '</div></td></tr>'.
4544: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4545: $othertitle,$usertypes,$types,\%servers,
4546: \%currbalancer,$lonhost,
4547: $targets_div_style,$homedom_div_style,
4548: $css_class[$cssidx],$balnum,$islast);
4549: $$rowtotal += $rownum;
4550: $balnum ++;
4551: }
4552: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4553: return $datatable;
4554: }
4555:
4556: sub get_loadbalancers_config {
4557: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4558: return unless ((ref($servers) eq 'HASH') &&
4559: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4560: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4561: if (keys(%{$existing}) > 0) {
4562: my $oldlonhost;
4563: foreach my $key (sort(keys(%{$existing}))) {
4564: if ($key eq 'lonhost') {
4565: $oldlonhost = $existing->{'lonhost'};
4566: $currbalancer->{$oldlonhost} = 1;
4567: } elsif ($key eq 'targets') {
4568: if ($oldlonhost) {
4569: $currtargets->{$oldlonhost} = $existing->{'targets'};
4570: }
4571: } elsif ($key eq 'rules') {
4572: if ($oldlonhost) {
4573: $currrules->{$oldlonhost} = $existing->{'rules'};
4574: }
4575: } elsif (ref($existing->{$key}) eq 'HASH') {
4576: $currbalancer->{$key} = 1;
4577: $currtargets->{$key} = $existing->{$key}{'targets'};
4578: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4579: }
4580: }
1.160.6.7 raeburn 4581: } else {
4582: my ($balancerref,$targetsref) =
4583: &Apache::lonnet::get_lonbalancer_config($servers);
4584: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4585: foreach my $server (sort(keys(%{$balancerref}))) {
4586: $currbalancer->{$server} = 1;
4587: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4588: }
4589: }
4590: }
1.160.6.7 raeburn 4591: return;
1.150 raeburn 4592: }
4593:
4594: sub loadbalancing_rules {
4595: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 4596: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4597: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4598: my $output;
1.160.6.7 raeburn 4599: my $num = 0;
4600: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4601: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4602: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4603: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 4604: $num ++;
1.150 raeburn 4605: my $current;
4606: if (ref($currrules) eq 'HASH') {
4607: $current = $currrules->{$type};
4608: }
1.160.6.55 raeburn 4609: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 4610: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4611: $current = '';
4612: }
4613: }
4614: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 4615: $servers,$currbalancer,$lonhost,$dom,
4616: $targets_div_style,$homedom_div_style,
4617: $css_class,$balnum,$num,$islast);
1.150 raeburn 4618: }
4619: }
4620: return $output;
4621: }
4622:
4623: sub loadbalancing_titles {
4624: my ($dom,$intdom,$usertypes,$types) = @_;
4625: my %othertypes = (
4626: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4627: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4628: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4629: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 4630: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4631: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4632: );
1.160.6.26 raeburn 4633: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89! raeburn 4634: my @available;
1.150 raeburn 4635: if (ref($types) eq 'ARRAY') {
1.160.6.89! raeburn 4636: @available = @{$types};
1.150 raeburn 4637: }
1.160.6.89! raeburn 4638: unless (grep(/^default$/,@available)) {
! 4639: push(@available,'default');
! 4640: }
! 4641: unshift(@alltypes,@available);
1.150 raeburn 4642: my %titles;
4643: foreach my $type (@alltypes) {
4644: if ($type =~ /^_LC_/) {
4645: $titles{$type} = $othertypes{$type};
4646: } elsif ($type eq 'default') {
4647: $titles{$type} = &mt('All users from [_1]',$dom);
4648: if (ref($types) eq 'ARRAY') {
4649: if (@{$types} > 0) {
4650: $titles{$type} = &mt('Other users from [_1]',$dom);
4651: }
4652: }
4653: } elsif (ref($usertypes) eq 'HASH') {
4654: $titles{$type} = $usertypes->{$type};
4655: }
4656: }
4657: return (\@alltypes,\%othertypes,\%titles);
4658: }
4659:
4660: sub loadbalance_rule_row {
1.160.6.7 raeburn 4661: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4662: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4663: my @rulenames;
1.150 raeburn 4664: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4665: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4666: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4667: } else {
1.160.6.26 raeburn 4668: @rulenames = ('default','homeserver');
4669: if ($type eq '_LC_external') {
4670: push(@rulenames,'externalbalancer');
4671: } else {
4672: push(@rulenames,'specific');
4673: }
4674: push(@rulenames,'none');
1.150 raeburn 4675: }
4676: my $style = $targets_div_style;
1.160.6.55 raeburn 4677: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4678: $style = $homedom_div_style;
4679: }
1.160.6.7 raeburn 4680: my $space;
4681: if ($islast && $num == 1) {
4682: $space = '<div display="inline-block"> </div>';
4683: }
4684: my $output =
4685: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4686: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4687: '<td valaign="top">'.$space.
4688: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4689: for (my $i=0; $i<@rulenames; $i++) {
4690: my $rule = $rulenames[$i];
4691: my ($checked,$extra);
4692: if ($rulenames[$i] eq 'default') {
4693: $rule = '';
4694: }
4695: if ($rulenames[$i] eq 'specific') {
4696: if (ref($servers) eq 'HASH') {
4697: my $default;
4698: if (($current ne '') && (exists($servers->{$current}))) {
4699: $checked = ' checked="checked"';
4700: }
4701: unless ($checked) {
4702: $default = ' selected="selected"';
4703: }
1.160.6.7 raeburn 4704: $extra =
4705: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4706: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4707: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4708: '<option value=""'.$default.'></option>'."\n";
4709: foreach my $server (sort(keys(%{$servers}))) {
4710: if (ref($currbalancer) eq 'HASH') {
4711: next if (exists($currbalancer->{$server}));
4712: }
1.150 raeburn 4713: my $selected;
1.160.6.7 raeburn 4714: if ($server eq $current) {
1.150 raeburn 4715: $selected = ' selected="selected"';
4716: }
1.160.6.7 raeburn 4717: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4718: }
4719: $extra .= '</select>';
4720: }
4721: } elsif ($rule eq $current) {
4722: $checked = ' checked="checked"';
4723: }
4724: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4725: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4726: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4727: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4728: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4729: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4730: $output .= $ruletitles{'particular'};
4731: } else {
4732: $output .= $ruletitles{$rulenames[$i]};
4733: }
4734: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4735: }
4736: $output .= '</div></td></tr>'."\n";
4737: return $output;
4738: }
4739:
4740: sub offloadtype_text {
4741: my %ruletitles = &Apache::lonlocal::texthash (
4742: 'default' => 'Offloads to default destinations',
4743: 'homeserver' => "Offloads to user's home server",
4744: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4745: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4746: 'none' => 'No offload',
1.160.6.26 raeburn 4747: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4748: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4749: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4750: );
4751: return %ruletitles;
4752: }
4753:
4754: sub sparestype_titles {
4755: my %typestitles = &Apache::lonlocal::texthash (
4756: 'primary' => 'primary',
4757: 'default' => 'default',
4758: );
4759: return %typestitles;
4760: }
4761:
1.28 raeburn 4762: sub contact_titles {
4763: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 4764: 'supportemail' => 'Support E-mail address',
4765: 'adminemail' => 'Default Server Admin E-mail address',
4766: 'errormail' => 'Error reports to be e-mailed to',
4767: 'packagesmail' => 'Package update alerts to be e-mailed to',
4768: 'helpdeskmail' => "Helpdesk requests for this domain's users",
4769: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
4770: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
4771: 'requestsmail' => 'E-mail from course requests requiring approval',
4772: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4773: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4774: );
4775: my %short_titles = &Apache::lonlocal::texthash (
4776: adminemail => 'Admin E-mail address',
4777: supportemail => 'Support E-mail',
4778: );
4779: return (\%titles,\%short_titles);
4780: }
4781:
1.160.6.78 raeburn 4782: sub helpform_fields {
4783: my %titles = &Apache::lonlocal::texthash (
4784: 'username' => 'Name',
4785: 'user' => 'Username/domain',
4786: 'phone' => 'Phone',
4787: 'cc' => 'Cc e-mail',
4788: 'course' => 'Course Details',
4789: 'section' => 'Sections',
4790: 'screenshot' => 'File upload',
4791: );
4792: my @fields = ('username','phone','user','course','section','cc','screenshot');
4793: my %possoptions = (
4794: username => ['yes','no','req'],
4795: phone => ['yes','no','req'],
4796: user => ['yes','no'],
4797: cc => ['yes','no'],
4798: course => ['yes','no'],
4799: section => ['yes','no'],
4800: screenshot => ['yes','no'],
4801: );
4802: my %fieldoptions = &Apache::lonlocal::texthash (
4803: 'yes' => 'Optional',
4804: 'req' => 'Required',
4805: 'no' => "Not shown",
4806: );
4807: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
4808: }
4809:
1.72 raeburn 4810: sub tool_titles {
4811: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4812: aboutme => 'Personal web page',
1.86 raeburn 4813: blog => 'Blog',
1.160.6.4 raeburn 4814: webdav => 'WebDAV',
1.86 raeburn 4815: portfolio => 'Portfolio',
1.88 bisitz 4816: official => 'Official courses (with institutional codes)',
4817: unofficial => 'Unofficial courses',
1.98 raeburn 4818: community => 'Communities',
1.160.6.30 raeburn 4819: textbook => 'Textbook courses',
1.86 raeburn 4820: );
1.72 raeburn 4821: return %titles;
4822: }
4823:
1.101 raeburn 4824: sub courserequest_titles {
4825: my %titles = &Apache::lonlocal::texthash (
4826: official => 'Official',
4827: unofficial => 'Unofficial',
4828: community => 'Communities',
1.160.6.30 raeburn 4829: textbook => 'Textbook',
1.101 raeburn 4830: norequest => 'Not allowed',
1.104 raeburn 4831: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4832: validate => 'With validation',
4833: autolimit => 'Numerical limit',
1.103 raeburn 4834: unlimited => '(blank for unlimited)',
1.101 raeburn 4835: );
4836: return %titles;
4837: }
4838:
1.160.6.5 raeburn 4839: sub authorrequest_titles {
4840: my %titles = &Apache::lonlocal::texthash (
4841: norequest => 'Not allowed',
4842: approval => 'Approval by Dom. Coord.',
4843: automatic => 'Automatic approval',
4844: );
4845: return %titles;
4846: }
4847:
1.101 raeburn 4848: sub courserequest_conditions {
4849: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4850: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4851: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4852: );
4853: return %conditions;
4854: }
4855:
4856:
1.27 raeburn 4857: sub print_usercreation {
1.30 raeburn 4858: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4859: my $numinrow = 4;
1.28 raeburn 4860: my $datatable;
4861: if ($position eq 'top') {
1.30 raeburn 4862: $$rowtotal ++;
1.34 raeburn 4863: my $rowcount = 0;
1.32 raeburn 4864: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4865: if (ref($rules) eq 'HASH') {
4866: if (keys(%{$rules}) > 0) {
1.32 raeburn 4867: $datatable .= &user_formats_row('username',$settings,$rules,
4868: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4869: $$rowtotal ++;
1.32 raeburn 4870: $rowcount ++;
4871: }
4872: }
4873: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4874: if (ref($idrules) eq 'HASH') {
4875: if (keys(%{$idrules}) > 0) {
4876: $datatable .= &user_formats_row('id',$settings,$idrules,
4877: $idruleorder,$numinrow,$rowcount);
4878: $$rowtotal ++;
4879: $rowcount ++;
1.28 raeburn 4880: }
4881: }
1.39 raeburn 4882: if ($rowcount == 0) {
4883: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4884: $$rowtotal ++;
4885: $rowcount ++;
4886: }
1.34 raeburn 4887: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4888: my @creators = ('author','course','requestcrs');
1.37 raeburn 4889: my ($rules,$ruleorder) =
4890: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4891: my %lt = &usercreation_types();
4892: my %checked;
4893: if (ref($settings) eq 'HASH') {
4894: if (ref($settings->{'cancreate'}) eq 'HASH') {
4895: foreach my $item (@creators) {
4896: $checked{$item} = $settings->{'cancreate'}{$item};
4897: }
4898: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4899: foreach my $item (@creators) {
4900: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4901: $checked{$item} = 'none';
4902: }
4903: }
4904: }
4905: }
4906: my $rownum = 0;
4907: foreach my $item (@creators) {
4908: $rownum ++;
1.160.6.34 raeburn 4909: if ($checked{$item} eq '') {
4910: $checked{$item} = 'any';
1.34 raeburn 4911: }
4912: my $css_class;
4913: if ($rownum%2) {
4914: $css_class = '';
4915: } else {
4916: $css_class = ' class="LC_odd_row" ';
4917: }
4918: $datatable .= '<tr'.$css_class.'>'.
4919: '<td><span class="LC_nobreak">'.$lt{$item}.
4920: '</span></td><td align="right">';
1.160.6.34 raeburn 4921: my @options = ('any');
4922: if (ref($rules) eq 'HASH') {
4923: if (keys(%{$rules}) > 0) {
4924: push(@options,('official','unofficial'));
1.37 raeburn 4925: }
4926: }
1.160.6.34 raeburn 4927: push(@options,'none');
1.37 raeburn 4928: foreach my $option (@options) {
1.50 raeburn 4929: my $type = 'radio';
1.34 raeburn 4930: my $check = ' ';
1.160.6.34 raeburn 4931: if ($checked{$item} eq $option) {
4932: $check = ' checked="checked" ';
1.34 raeburn 4933: }
4934: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4935: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4936: $item.'" value="'.$option.'"'.$check.'/> '.
4937: $lt{$option}.'</label> </span>';
4938: }
4939: $datatable .= '</td></tr>';
4940: }
1.28 raeburn 4941: } else {
4942: my @contexts = ('author','course','domain');
4943: my @authtypes = ('int','krb4','krb5','loc');
4944: my %checked;
4945: if (ref($settings) eq 'HASH') {
4946: if (ref($settings->{'authtypes'}) eq 'HASH') {
4947: foreach my $item (@contexts) {
4948: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4949: foreach my $auth (@authtypes) {
4950: if ($settings->{'authtypes'}{$item}{$auth}) {
4951: $checked{$item}{$auth} = ' checked="checked" ';
4952: }
4953: }
4954: }
4955: }
1.27 raeburn 4956: }
1.35 raeburn 4957: } else {
4958: foreach my $item (@contexts) {
1.36 raeburn 4959: foreach my $auth (@authtypes) {
1.35 raeburn 4960: $checked{$item}{$auth} = ' checked="checked" ';
4961: }
4962: }
1.27 raeburn 4963: }
1.28 raeburn 4964: my %title = &context_names();
4965: my %authname = &authtype_names();
4966: my $rownum = 0;
4967: my $css_class;
4968: foreach my $item (@contexts) {
4969: if ($rownum%2) {
4970: $css_class = '';
4971: } else {
4972: $css_class = ' class="LC_odd_row" ';
4973: }
1.30 raeburn 4974: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4975: '<td>'.$title{$item}.
4976: '</td><td class="LC_left_item">'.
4977: '<span class="LC_nobreak">';
4978: foreach my $auth (@authtypes) {
4979: $datatable .= '<label>'.
4980: '<input type="checkbox" name="'.$item.'_auth" '.
4981: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4982: $authname{$auth}.'</label> ';
4983: }
4984: $datatable .= '</span></td></tr>';
4985: $rownum ++;
1.27 raeburn 4986: }
1.30 raeburn 4987: $$rowtotal += $rownum;
1.27 raeburn 4988: }
4989: return $datatable;
4990: }
4991:
1.160.6.34 raeburn 4992: sub print_selfcreation {
4993: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4994: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4995: if (ref($settings) eq 'HASH') {
4996: if (ref($settings->{'cancreate'}) eq 'HASH') {
4997: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4998: if (ref($createsettings) eq 'HASH') {
4999: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5000: @selfcreate = @{$createsettings->{'selfcreate'}};
5001: } elsif ($createsettings->{'selfcreate'} ne '') {
5002: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5003: @selfcreate = ('email','login','sso');
5004: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5005: @selfcreate = ($createsettings->{'selfcreate'});
5006: }
5007: }
5008: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5009: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5010: }
5011: }
5012: }
5013: }
5014: my %radiohash;
5015: my $numinrow = 4;
5016: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89! raeburn 5017: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 5018: if ($position eq 'top') {
5019: my %choices = &Apache::lonlocal::texthash (
5020: cancreate_login => 'Institutional Login',
5021: cancreate_sso => 'Institutional Single Sign On',
5022: );
5023: my @toggles = sort(keys(%choices));
5024: my %defaultchecked = (
5025: 'cancreate_login' => 'off',
5026: 'cancreate_sso' => 'off',
5027: );
1.160.6.35 raeburn 5028: my ($onclick,$itemcount);
1.160.6.34 raeburn 5029: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5030: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5031: $$rowtotal += $itemcount;
1.160.6.34 raeburn 5032:
5033: if (ref($usertypes) eq 'HASH') {
5034: if (keys(%{$usertypes}) > 0) {
5035: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5036: $dom,$numinrow,$othertitle,
1.160.6.89! raeburn 5037: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 5038: $$rowtotal ++;
5039: }
5040: }
1.160.6.44 raeburn 5041: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5042: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5043: $fieldtitles{'inststatus'} = &mt('Institutional status');
5044: my $rem;
5045: my $numperrow = 2;
5046: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5047: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5048: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5049: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 5050: '<table>'."\n";
1.160.6.44 raeburn 5051: for (my $i=0; $i<@fields; $i++) {
5052: $rem = $i%($numperrow);
5053: if ($rem == 0) {
5054: if ($i > 0) {
5055: $datatable .= '</tr>';
5056: }
5057: $datatable .= '<tr>';
5058: }
5059: my $currval;
1.160.6.51 raeburn 5060: if (ref($createsettings) eq 'HASH') {
5061: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5062: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5063: }
1.160.6.44 raeburn 5064: }
5065: $datatable .= '<td class="LC_left_item">'.
5066: '<span class="LC_nobreak">'.
5067: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5068: 'value="'.$currval.'" size="10" /> '.
5069: $fieldtitles{$fields[$i]}.'</span></td>';
5070: }
5071: my $colsleft = $numperrow - $rem;
5072: if ($colsleft > 1 ) {
5073: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5074: ' </td>';
5075: } elsif ($colsleft == 1) {
5076: $datatable .= '<td class="LC_left_item"> </td>';
5077: }
5078: $datatable .= '</tr></table></td></tr>';
5079: $$rowtotal ++;
1.160.6.34 raeburn 5080: } elsif ($position eq 'middle') {
5081: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89! raeburn 5082: my @posstypes;
1.160.6.34 raeburn 5083: if (ref($types) eq 'ARRAY') {
1.160.6.89! raeburn 5084: @posstypes = @{$types};
! 5085: }
! 5086: unless (grep(/^default$/,@posstypes)) {
! 5087: push(@posstypes,'default');
! 5088: }
! 5089: my %usertypeshash;
! 5090: if (ref($usertypes) eq 'HASH') {
! 5091: %usertypeshash = %{$usertypes};
! 5092: }
! 5093: $usertypeshash{'default'} = $othertitle;
! 5094: foreach my $status (@posstypes) {
! 5095: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
! 5096: $numinrow,$$rowtotal,\%usertypeshash);
! 5097: $$rowtotal ++;
1.160.6.34 raeburn 5098: }
5099: } else {
1.160.6.40 raeburn 5100: my %choices = &Apache::lonlocal::texthash (
5101: cancreate_email => 'E-mail address as username',
5102: );
5103: my @toggles = sort(keys(%choices));
5104: my %defaultchecked = (
5105: 'cancreate_email' => 'off',
5106: );
5107: my $itemcount = 0;
5108: my $display = 'none';
5109: if (grep(/^\Qemail\E$/,@selfcreate)) {
5110: $display = 'block';
5111: }
5112: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5113: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5114: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.89! raeburn 5115: my (@ordered,%usertypeshash);
! 5116: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
! 5117: @ordered = @{$domdefaults{'inststatusguest'}};
! 5118: }
! 5119: if (@ordered) {
! 5120: unless (grep(/^default$/,@ordered)) {
! 5121: push(@ordered,'default');
! 5122: }
! 5123: if (ref($usertypes) eq 'HASH') {
! 5124: %usertypeshash = %{$usertypes};
! 5125: }
! 5126: $usertypeshash{'default'} = $othertitle;
! 5127: $additional .= '<table><tr>';
! 5128: foreach my $status (@ordered) {
! 5129: $additional .= '<th>'.$usertypeshash{$status}.'</th>';
1.160.6.34 raeburn 5130: }
1.160.6.89! raeburn 5131: $additional .= '</tr><tr>';
! 5132: foreach my $status (@ordered) {
! 5133: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
! 5134: }
! 5135: $additional .= '</tr></table>';
! 5136: } else {
! 5137: $usertypeshash{'default'} = $othertitle;
! 5138: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 5139: }
1.160.6.40 raeburn 5140: $additional .= '</div>'."\n";
5141:
5142: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 5143: \%choices,$$rowtotal,$onclick,$additional);
5144: $$rowtotal ++;
1.160.6.40 raeburn 5145: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 5146: $$rowtotal ++;
1.160.6.35 raeburn 5147: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5148: $numinrow = 1;
1.160.6.89! raeburn 5149: foreach my $status (@ordered) {
! 5150: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
! 5151: $numinrow,$$rowtotal,\%usertypeshash,$infofields,$infotitles);
! 5152: $$rowtotal ++;
1.160.6.35 raeburn 5153: }
1.160.6.34 raeburn 5154: my ($emailrules,$emailruleorder) =
5155: &Apache::lonnet::inst_userrules($dom,'email');
5156: if (ref($emailrules) eq 'HASH') {
5157: if (keys(%{$emailrules}) > 0) {
5158: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 5159: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 5160: $$rowtotal ++;
5161: }
5162: }
1.160.6.35 raeburn 5163: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 5164: }
5165: return $datatable;
5166: }
5167:
1.160.6.40 raeburn 5168: sub email_as_username {
5169: my ($rowtotal,$processing,$type) = @_;
5170: my %choices =
5171: &Apache::lonlocal::texthash (
5172: automatic => 'Automatic approval',
5173: approval => 'Queued for approval',
5174: );
5175: my $output;
5176: foreach my $option ('automatic','approval') {
5177: my $checked;
5178: if (ref($processing) eq 'HASH') {
5179: if ($type eq '') {
5180: if (!exists($processing->{'default'})) {
5181: if ($option eq 'automatic') {
5182: $checked = ' checked="checked"';
5183: }
5184: } else {
5185: if ($processing->{'default'} eq $option) {
5186: $checked = ' checked="checked"';
5187: }
5188: }
5189: } else {
5190: if (!exists($processing->{$type})) {
5191: if ($option eq 'automatic') {
5192: $checked = ' checked="checked"';
5193: }
5194: } else {
5195: if ($processing->{$type} eq $option) {
5196: $checked = ' checked="checked"';
5197: }
5198: }
5199: }
5200: } elsif ($option eq 'automatic') {
5201: $checked = ' checked="checked"';
5202: }
5203: my $name = 'cancreate_emailprocess';
5204: if (($type ne '') && ($type ne 'default')) {
5205: $name .= '_'.$type;
5206: }
5207: $output .= '<span class="LC_nobreak"><label>'.
5208: '<input type="radio" name="'.$name.'"'.
5209: $checked.' value="'.$option.'" />'.
5210: $choices{$option}.'</label></span>';
5211: if ($type eq '') {
5212: $output .= ' ';
5213: } else {
5214: $output .= '<br />';
5215: }
5216: }
5217: $$rowtotal ++;
5218: return $output;
5219: }
5220:
1.160.6.5 raeburn 5221: sub captcha_choice {
5222: my ($context,$settings,$itemcount) = @_;
1.160.6.69 raeburn 5223: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5224: $vertext,$currver);
1.160.6.5 raeburn 5225: my %lt = &captcha_phrases();
5226: $keyentry = 'hidden';
5227: if ($context eq 'cancreate') {
1.160.6.34 raeburn 5228: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 5229: } elsif ($context eq 'login') {
5230: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5231: }
5232: if (ref($settings) eq 'HASH') {
5233: if ($settings->{'captcha'}) {
5234: $checked{$settings->{'captcha'}} = ' checked="checked"';
5235: } else {
5236: $checked{'original'} = ' checked="checked"';
5237: }
5238: if ($settings->{'captcha'} eq 'recaptcha') {
5239: $pubtext = $lt{'pub'};
5240: $privtext = $lt{'priv'};
5241: $keyentry = 'text';
1.160.6.69 raeburn 5242: $vertext = $lt{'ver'};
5243: $currver = $settings->{'recaptchaversion'};
5244: if ($currver ne '2') {
5245: $currver = 1;
5246: }
1.160.6.5 raeburn 5247: }
5248: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5249: $currpub = $settings->{'recaptchakeys'}{'public'};
5250: $currpriv = $settings->{'recaptchakeys'}{'private'};
5251: }
5252: } else {
5253: $checked{'original'} = ' checked="checked"';
5254: }
5255: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5256: my $output = '<tr'.$css_class.'>'.
5257: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5258: '<table><tr><td>'."\n";
5259: foreach my $option ('original','recaptcha','notused') {
5260: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5261: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5262: $lt{$option}.'</label></span>';
5263: unless ($option eq 'notused') {
5264: $output .= (' 'x2)."\n";
5265: }
5266: }
5267: #
5268: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5269: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5270: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5271: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5272: #
5273: $output .= '</td></tr>'."\n".
5274: '<tr><td>'."\n".
5275: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5276: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5277: $currpub.'" size="40" /></span><br />'."\n".
5278: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5279: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 5280: $currpriv.'" size="40" /></span><br />'.
5281: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5282: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5283: $currver.'" size="3" /></span><br />'.
5284: '</td></tr></table>'."\n".
1.160.6.5 raeburn 5285: '</td></tr>';
5286: return $output;
5287: }
5288:
1.32 raeburn 5289: sub user_formats_row {
5290: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5291: my $output;
5292: my %text = (
5293: 'username' => 'new usernames',
5294: 'id' => 'IDs',
1.45 raeburn 5295: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5296: );
5297: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5298: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5299: '<td><span class="LC_nobreak">';
5300: if ($type eq 'email') {
5301: $output .= &mt("Formats disallowed for $text{$type}: ");
5302: } else {
5303: $output .= &mt("Format rules to check for $text{$type}: ");
5304: }
5305: $output .= '</span></td>'.
5306: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5307: my $rem;
5308: if (ref($ruleorder) eq 'ARRAY') {
5309: for (my $i=0; $i<@{$ruleorder}; $i++) {
5310: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5311: my $rem = $i%($numinrow);
5312: if ($rem == 0) {
5313: if ($i > 0) {
5314: $output .= '</tr>';
5315: }
5316: $output .= '<tr>';
5317: }
5318: my $check = ' ';
1.39 raeburn 5319: if (ref($settings) eq 'HASH') {
5320: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5321: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5322: $check = ' checked="checked" ';
5323: }
1.27 raeburn 5324: }
5325: }
5326: $output .= '<td class="LC_left_item">'.
5327: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5328: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5329: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5330: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5331: }
5332: }
5333: $rem = @{$ruleorder}%($numinrow);
5334: }
5335: my $colsleft = $numinrow - $rem;
5336: if ($colsleft > 1 ) {
5337: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5338: ' </td>';
5339: } elsif ($colsleft == 1) {
5340: $output .= '<td class="LC_left_item"> </td>';
5341: }
5342: $output .= '</tr></table></td></tr>';
5343: return $output;
5344: }
5345:
1.34 raeburn 5346: sub usercreation_types {
5347: my %lt = &Apache::lonlocal::texthash (
5348: author => 'When adding a co-author',
5349: course => 'When adding a user to a course',
1.100 raeburn 5350: requestcrs => 'When requesting a course',
1.34 raeburn 5351: any => 'Any',
5352: official => 'Institutional only ',
5353: unofficial => 'Non-institutional only',
5354: none => 'None',
5355: );
5356: return %lt;
1.48 raeburn 5357: }
1.34 raeburn 5358:
1.160.6.34 raeburn 5359: sub selfcreation_types {
5360: my %lt = &Apache::lonlocal::texthash (
5361: selfcreate => 'User creates own account',
5362: any => 'Any',
5363: official => 'Institutional only ',
5364: unofficial => 'Non-institutional only',
5365: email => 'E-mail address',
5366: login => 'Institutional Login',
5367: sso => 'SSO',
5368: );
5369: }
5370:
1.28 raeburn 5371: sub authtype_names {
5372: my %lt = &Apache::lonlocal::texthash(
5373: int => 'Internal',
5374: krb4 => 'Kerberos 4',
5375: krb5 => 'Kerberos 5',
5376: loc => 'Local',
5377: );
5378: return %lt;
5379: }
5380:
5381: sub context_names {
5382: my %context_title = &Apache::lonlocal::texthash(
5383: author => 'Creating users when an Author',
5384: course => 'Creating users when in a course',
5385: domain => 'Creating users when a Domain Coordinator',
5386: );
5387: return %context_title;
5388: }
5389:
1.33 raeburn 5390: sub print_usermodification {
5391: my ($position,$dom,$settings,$rowtotal) = @_;
5392: my $numinrow = 4;
5393: my ($context,$datatable,$rowcount);
5394: if ($position eq 'top') {
5395: $rowcount = 0;
5396: $context = 'author';
5397: foreach my $role ('ca','aa') {
5398: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5399: $numinrow,$rowcount);
5400: $$rowtotal ++;
5401: $rowcount ++;
5402: }
1.160.6.37 raeburn 5403: } elsif ($position eq 'bottom') {
1.33 raeburn 5404: $context = 'course';
5405: $rowcount = 0;
5406: foreach my $role ('st','ep','ta','in','cr') {
5407: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5408: $numinrow,$rowcount);
5409: $$rowtotal ++;
5410: $rowcount ++;
5411: }
5412: }
5413: return $datatable;
5414: }
5415:
1.43 raeburn 5416: sub print_defaults {
1.160.6.40 raeburn 5417: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5418: my $rownum = 0;
1.160.6.80 raeburn 5419: my ($datatable,$css_class,$titles);
5420: unless ($position eq 'bottom') {
5421: $titles = &defaults_titles($dom);
5422: }
1.160.6.40 raeburn 5423: if ($position eq 'top') {
5424: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5425: 'datelocale_def','portal_def');
5426: my %defaults;
5427: if (ref($settings) eq 'HASH') {
5428: %defaults = %{$settings};
1.43 raeburn 5429: } else {
1.160.6.40 raeburn 5430: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5431: foreach my $item (@items) {
5432: $defaults{$item} = $domdefaults{$item};
5433: }
1.43 raeburn 5434: }
1.160.6.40 raeburn 5435: foreach my $item (@items) {
5436: if ($rownum%2) {
5437: $css_class = '';
5438: } else {
5439: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 5440: }
1.160.6.40 raeburn 5441: $datatable .= '<tr'.$css_class.'>'.
5442: '<td><span class="LC_nobreak">'.$titles->{$item}.
5443: '</span></td><td class="LC_right_item" colspan="3">';
5444: if ($item eq 'auth_def') {
5445: my @authtypes = ('internal','krb4','krb5','localauth');
5446: my %shortauth = (
5447: internal => 'int',
5448: krb4 => 'krb4',
5449: krb5 => 'krb5',
5450: localauth => 'loc'
5451: );
5452: my %authnames = &authtype_names();
5453: foreach my $auth (@authtypes) {
5454: my $checked = ' ';
5455: if ($defaults{$item} eq $auth) {
5456: $checked = ' checked="checked" ';
5457: }
5458: $datatable .= '<label><input type="radio" name="'.$item.
5459: '" value="'.$auth.'"'.$checked.'/>'.
5460: $authnames{$shortauth{$auth}}.'</label> ';
5461: }
5462: } elsif ($item eq 'timezone_def') {
5463: my $includeempty = 1;
5464: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5465: } elsif ($item eq 'datelocale_def') {
5466: my $includeempty = 1;
5467: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5468: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 5469: my $includeempty = 1;
5470: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 5471: } else {
5472: my $size;
5473: if ($item eq 'portal_def') {
5474: $size = ' size="25"';
5475: }
5476: $datatable .= '<input type="text" name="'.$item.'" value="'.
5477: $defaults{$item}.'"'.$size.' />';
5478: }
5479: $datatable .= '</td></tr>';
5480: $rownum ++;
5481: }
1.160.6.80 raeburn 5482: } elsif ($position eq 'middle') {
5483: my @items = ('intauth_cost','intauth_check','intauth_switch');
5484: my %defaults;
5485: if (ref($settings) eq 'HASH') {
5486: %defaults = %{$settings};
5487: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5488: $defaults{'intauth_cost'} = 10;
5489: }
5490: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5491: $defaults{'intauth_check'} = 0;
5492: }
5493: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5494: $defaults{'intauth_switch'} = 0;
5495: }
5496: } else {
5497: %defaults = (
5498: 'intauth_cost' => 10,
5499: 'intauth_check' => 0,
5500: 'intauth_switch' => 0,
5501: );
5502: }
5503: foreach my $item (@items) {
5504: if ($rownum%2) {
5505: $css_class = '';
5506: } else {
5507: $css_class = ' class="LC_odd_row" ';
5508: }
5509: $datatable .= '<tr'.$css_class.'>'.
5510: '<td><span class="LC_nobreak">'.$titles->{$item}.
5511: '</span></td><td class="LC_left_item" colspan="3">';
5512: if ($item eq 'intauth_switch') {
5513: my @options = (0,1,2);
5514: my %optiondesc = &Apache::lonlocal::texthash (
5515: 0 => 'No',
5516: 1 => 'Yes',
5517: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5518: );
5519: $datatable .= '<table width="100%">';
5520: foreach my $option (@options) {
5521: my $checked = ' ';
5522: if ($defaults{$item} eq $option) {
5523: $checked = ' checked="checked"';
5524: }
5525: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5526: '<label><input type="radio" name="'.$item.
5527: '" value="'.$option.'"'.$checked.' />'.
5528: $optiondesc{$option}.'</label></span></td></tr>';
5529: }
5530: $datatable .= '</table>';
5531: } elsif ($item eq 'intauth_check') {
5532: my @options = (0,1,2);
5533: my %optiondesc = &Apache::lonlocal::texthash (
5534: 0 => 'No',
5535: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5536: 2 => 'Yes, disallow login if stored cost is less than domain default',
5537: );
1.160.6.87 raeburn 5538: $datatable .= '<table width="100%">';
1.160.6.80 raeburn 5539: foreach my $option (@options) {
5540: my $checked = ' ';
5541: my $onclick;
5542: if ($defaults{$item} eq $option) {
5543: $checked = ' checked="checked"';
5544: }
5545: if ($option == 2) {
5546: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5547: }
5548: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5549: '<label><input type="radio" name="'.$item.
5550: '" value="'.$option.'"'.$checked.$onclick.' />'.
5551: $optiondesc{$option}.'</label></span></td></tr>';
5552: }
5553: $datatable .= '</table>';
5554: } else {
5555: $datatable .= '<input type="text" name="'.$item.'" value="'.
5556: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5557: }
5558: $datatable .= '</td></tr>';
5559: $rownum ++;
5560: }
1.160.6.40 raeburn 5561: } else {
1.160.6.80 raeburn 5562: my %defaults;
1.160.6.40 raeburn 5563: if (ref($settings) eq 'HASH') {
5564: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5565: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5566: my $maxnum = @{$settings->{'inststatusorder'}};
5567: for (my $i=0; $i<$maxnum; $i++) {
5568: $css_class = $rownum%2?' class="LC_odd_row"':'';
5569: my $item = $settings->{'inststatusorder'}->[$i];
5570: my $title = $settings->{'inststatustypes'}->{$item};
5571: my $guestok;
5572: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5573: $guestok = 1;
5574: }
5575: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5576: $datatable .= '<tr'.$css_class.'>'.
5577: '<td><span class="LC_nobreak">'.
5578: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5579: for (my $k=0; $k<=$maxnum; $k++) {
5580: my $vpos = $k+1;
5581: my $selstr;
5582: if ($k == $i) {
5583: $selstr = ' selected="selected" ';
5584: }
5585: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5586: }
5587: my ($checkedon,$checkedoff);
5588: $checkedoff = ' checked="checked"';
5589: if ($guestok) {
5590: $checkedon = $checkedoff;
5591: $checkedoff = '';
5592: }
5593: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5594: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5595: &mt('delete').'</span></td>'.
5596: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5597: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5598: '</span></td>'.
5599: '<td class="LC_right_item"><span class="LC_nobreak">'.
5600: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5601: &mt('Yes').'</label>'.(' 'x2).
5602: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5603: &mt('No').'</label></span></td></tr>';
5604: }
5605: $css_class = $rownum%2?' class="LC_odd_row"':'';
5606: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5607: $datatable .= '<tr '.$css_class.'>'.
5608: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5609: for (my $k=0; $k<=$maxnum; $k++) {
5610: my $vpos = $k+1;
5611: my $selstr;
5612: if ($k == $maxnum) {
5613: $selstr = ' selected="selected" ';
5614: }
5615: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5616: }
5617: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 5618: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 5619: ' '.&mt('(new)').
5620: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5621: &mt('Name displayed:').
5622: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5623: '<td class="LC_right_item"><span class="LC_nobreak">'.
5624: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5625: &mt('Yes').'</label>'.(' 'x2).
5626: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5627: &mt('No').'</label></span></td></tr>';
5628: '</tr>'."\n";
5629: $rownum ++;
1.141 raeburn 5630: }
1.43 raeburn 5631: }
5632: }
5633: $$rowtotal += $rownum;
5634: return $datatable;
5635: }
5636:
1.160.6.5 raeburn 5637: sub get_languages_hash {
5638: my %langchoices;
5639: foreach my $id (&Apache::loncommon::languageids()) {
5640: my $code = &Apache::loncommon::supportedlanguagecode($id);
5641: if ($code ne '') {
5642: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5643: }
5644: }
5645: return %langchoices;
5646: }
5647:
1.43 raeburn 5648: sub defaults_titles {
1.141 raeburn 5649: my ($dom) = @_;
1.43 raeburn 5650: my %titles = &Apache::lonlocal::texthash (
5651: 'auth_def' => 'Default authentication type',
5652: 'auth_arg_def' => 'Default authentication argument',
5653: 'lang_def' => 'Default language',
1.54 raeburn 5654: 'timezone_def' => 'Default timezone',
1.68 raeburn 5655: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5656: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 5657: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
5658: 'intauth_check' => 'Check bcrypt cost if authenticated',
5659: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 5660: );
1.141 raeburn 5661: if ($dom) {
5662: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5663: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5664: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5665: $protocol = 'http' if ($protocol ne 'https');
5666: if ($uint_dom) {
5667: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5668: $uint_dom);
5669: }
5670: }
1.43 raeburn 5671: return (\%titles);
5672: }
5673:
1.46 raeburn 5674: sub print_scantronformat {
5675: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5676: my $itemcount = 1;
1.60 raeburn 5677: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5678: %confhash);
1.46 raeburn 5679: my $switchserver = &check_switchserver($dom,$confname);
5680: my %lt = &Apache::lonlocal::texthash (
1.95 www 5681: default => 'Default bubblesheet format file error',
5682: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5683: );
5684: my %scantronfiles = (
5685: default => 'default.tab',
5686: custom => 'custom.tab',
5687: );
5688: foreach my $key (keys(%scantronfiles)) {
5689: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5690: .$scantronfiles{$key};
5691: }
5692: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5693: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5694: if (!$switchserver) {
5695: my $servadm = $r->dir_config('lonAdmEMail');
5696: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5697: if ($configuserok eq 'ok') {
5698: if ($author_ok eq 'ok') {
5699: my %legacyfile = (
5700: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5701: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5702: );
5703: my %md5chk;
5704: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5705: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5706: chomp($md5chk{$type});
1.46 raeburn 5707: }
5708: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5709: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5710: ($scantronurls{$type},my $error) =
1.46 raeburn 5711: &legacy_scantronformat($r,$dom,$confname,
5712: $type,$legacyfile{$type},
5713: $scantronurls{$type},
5714: $scantronfiles{$type});
1.60 raeburn 5715: if ($error ne '') {
5716: $error{$type} = $error;
5717: }
5718: }
5719: if (keys(%error) == 0) {
5720: $is_custom = 1;
5721: $confhash{'scantron'}{'scantronformat'} =
5722: $scantronurls{'custom'};
5723: my $putresult =
5724: &Apache::lonnet::put_dom('configuration',
5725: \%confhash,$dom);
5726: if ($putresult ne 'ok') {
5727: $error{'custom'} =
5728: '<span class="LC_error">'.
5729: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5730: }
1.46 raeburn 5731: }
5732: } else {
1.60 raeburn 5733: ($scantronurls{'default'},my $error) =
1.46 raeburn 5734: &legacy_scantronformat($r,$dom,$confname,
5735: 'default',$legacyfile{'default'},
5736: $scantronurls{'default'},
5737: $scantronfiles{'default'});
1.60 raeburn 5738: if ($error eq '') {
5739: $confhash{'scantron'}{'scantronformat'} = '';
5740: my $putresult =
5741: &Apache::lonnet::put_dom('configuration',
5742: \%confhash,$dom);
5743: if ($putresult ne 'ok') {
5744: $error{'default'} =
5745: '<span class="LC_error">'.
5746: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5747: }
5748: } else {
5749: $error{'default'} = $error;
5750: }
1.46 raeburn 5751: }
5752: }
5753: }
5754: } else {
1.95 www 5755: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5756: }
5757: }
5758: if (ref($settings) eq 'HASH') {
5759: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5760: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5761: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5762: $scantronurl = '';
5763: } else {
5764: $scantronurl = $settings->{'scantronformat'};
5765: }
5766: $is_custom = 1;
5767: } else {
5768: $scantronurl = $scantronurls{'default'};
5769: }
5770: } else {
1.60 raeburn 5771: if ($is_custom) {
5772: $scantronurl = $scantronurls{'custom'};
5773: } else {
5774: $scantronurl = $scantronurls{'default'};
5775: }
1.46 raeburn 5776: }
5777: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5778: $datatable .= '<tr'.$css_class.'>';
5779: if (!$is_custom) {
1.65 raeburn 5780: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5781: '<span class="LC_nobreak">';
1.46 raeburn 5782: if ($scantronurl) {
1.160.6.21 raeburn 5783: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5784: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5785: } else {
5786: $datatable = &mt('File unavailable for display');
5787: }
1.65 raeburn 5788: $datatable .= '</span></td>';
1.60 raeburn 5789: if (keys(%error) == 0) {
5790: $datatable .= '<td valign="bottom">';
5791: if (!$switchserver) {
5792: $datatable .= &mt('Upload:').'<br />';
5793: }
5794: } else {
5795: my $errorstr;
5796: foreach my $key (sort(keys(%error))) {
5797: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5798: }
5799: $datatable .= '<td>'.$errorstr;
5800: }
1.46 raeburn 5801: } else {
5802: if (keys(%error) > 0) {
5803: my $errorstr;
5804: foreach my $key (sort(keys(%error))) {
5805: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5806: }
1.60 raeburn 5807: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5808: } elsif ($scantronurl) {
1.160.6.26 raeburn 5809: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 5810: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5811: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 5812: $link.
5813: '<label><input type="checkbox" name="scantronformat_del"'.
5814: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5815: '<td><span class="LC_nobreak"> '.
5816: &mt('Replace:').'</span><br />';
1.46 raeburn 5817: }
5818: }
5819: if (keys(%error) == 0) {
5820: if ($switchserver) {
5821: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5822: } else {
1.65 raeburn 5823: $datatable .='<span class="LC_nobreak"> '.
5824: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5825: }
5826: }
5827: $datatable .= '</td></tr>';
5828: $$rowtotal ++;
5829: return $datatable;
5830: }
5831:
5832: sub legacy_scantronformat {
5833: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5834: my ($url,$error);
5835: my @statinfo = &Apache::lonnet::stat_file($newurl);
5836: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5837: (my $result,$url) =
5838: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5839: '','',$newfile);
5840: if ($result ne 'ok') {
1.130 raeburn 5841: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5842: }
5843: }
5844: return ($url,$error);
5845: }
1.43 raeburn 5846:
1.49 raeburn 5847: sub print_coursecategories {
1.57 raeburn 5848: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5849: my $datatable;
5850: if ($position eq 'top') {
1.160.6.42 raeburn 5851: my (%checked);
5852: my @catitems = ('unauth','auth');
5853: my @cattypes = ('std','domonly','codesrch','none');
5854: $checked{'unauth'} = 'std';
5855: $checked{'auth'} = 'std';
5856: if (ref($settings) eq 'HASH') {
5857: foreach my $type (@cattypes) {
5858: if ($type eq $settings->{'unauth'}) {
5859: $checked{'unauth'} = $type;
5860: }
5861: if ($type eq $settings->{'auth'}) {
5862: $checked{'auth'} = $type;
5863: }
5864: }
5865: }
5866: my %lt = &Apache::lonlocal::texthash (
5867: unauth => 'Catalog type for unauthenticated users',
5868: auth => 'Catalog type for authenticated users',
5869: none => 'No catalog',
5870: std => 'Standard catalog',
5871: domonly => 'Domain-only catalog',
5872: codesrch => "Code search form",
5873: );
5874: my $itemcount = 0;
5875: foreach my $item (@catitems) {
5876: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5877: $datatable .= '<tr '.$css_class.'>'.
5878: '<td>'.$lt{$item}.'</td>'.
5879: '<td class="LC_right_item"><span class="LC_nobreak">';
5880: foreach my $type (@cattypes) {
5881: my $ischecked;
5882: if ($checked{$item} eq $type) {
5883: $ischecked=' checked="checked"';
5884: }
5885: $datatable .= '<label>'.
5886: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5887: ' />'.$lt{$type}.'</label> ';
5888: }
1.160.6.87 raeburn 5889: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 5890: $itemcount ++;
5891: }
5892: $$rowtotal += $itemcount;
5893: } elsif ($position eq 'middle') {
1.57 raeburn 5894: my $toggle_cats_crs = ' ';
5895: my $toggle_cats_dom = ' checked="checked" ';
5896: my $can_cat_crs = ' ';
5897: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5898: my $toggle_catscomm_comm = ' ';
5899: my $toggle_catscomm_dom = ' checked="checked" ';
5900: my $can_catcomm_comm = ' ';
5901: my $can_catcomm_dom = ' checked="checked" ';
5902:
1.57 raeburn 5903: if (ref($settings) eq 'HASH') {
5904: if ($settings->{'togglecats'} eq 'crs') {
5905: $toggle_cats_crs = $toggle_cats_dom;
5906: $toggle_cats_dom = ' ';
5907: }
5908: if ($settings->{'categorize'} eq 'crs') {
5909: $can_cat_crs = $can_cat_dom;
5910: $can_cat_dom = ' ';
5911: }
1.120 raeburn 5912: if ($settings->{'togglecatscomm'} eq 'comm') {
5913: $toggle_catscomm_comm = $toggle_catscomm_dom;
5914: $toggle_catscomm_dom = ' ';
5915: }
5916: if ($settings->{'categorizecomm'} eq 'comm') {
5917: $can_catcomm_comm = $can_catcomm_dom;
5918: $can_catcomm_dom = ' ';
5919: }
1.57 raeburn 5920: }
5921: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5922: togglecats => 'Show/Hide a course in catalog',
5923: togglecatscomm => 'Show/Hide a community in catalog',
5924: categorize => 'Assign a category to a course',
5925: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5926: );
5927: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5928: dom => 'Set in Domain',
5929: crs => 'Set in Course',
5930: comm => 'Set in Community',
1.57 raeburn 5931: );
5932: $datatable = '<tr class="LC_odd_row">'.
5933: '<td>'.$title{'togglecats'}.'</td>'.
5934: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5935: '<input type="radio" name="togglecats"'.
5936: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5937: '<label><input type="radio" name="togglecats"'.
5938: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5939: '</tr><tr>'.
5940: '<td>'.$title{'categorize'}.'</td>'.
5941: '<td class="LC_right_item"><span class="LC_nobreak">'.
5942: '<label><input type="radio" name="categorize"'.
5943: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5944: '<label><input type="radio" name="categorize"'.
5945: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5946: '</tr><tr class="LC_odd_row">'.
5947: '<td>'.$title{'togglecatscomm'}.'</td>'.
5948: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5949: '<input type="radio" name="togglecatscomm"'.
5950: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5951: '<label><input type="radio" name="togglecatscomm"'.
5952: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5953: '</tr><tr>'.
5954: '<td>'.$title{'categorizecomm'}.'</td>'.
5955: '<td class="LC_right_item"><span class="LC_nobreak">'.
5956: '<label><input type="radio" name="categorizecomm"'.
5957: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5958: '<label><input type="radio" name="categorizecomm"'.
5959: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5960: '</tr>';
1.120 raeburn 5961: $$rowtotal += 4;
1.57 raeburn 5962: } else {
5963: my $css_class;
5964: my $itemcount = 1;
5965: my $cathash;
5966: if (ref($settings) eq 'HASH') {
5967: $cathash = $settings->{'cats'};
5968: }
5969: if (ref($cathash) eq 'HASH') {
5970: my (@cats,@trails,%allitems,%idx,@jsarray);
5971: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5972: \%allitems,\%idx,\@jsarray);
5973: my $maxdepth = scalar(@cats);
5974: my $colattrib = '';
5975: if ($maxdepth > 2) {
5976: $colattrib = ' colspan="2" ';
5977: }
5978: my @path;
5979: if (@cats > 0) {
5980: if (ref($cats[0]) eq 'ARRAY') {
5981: my $numtop = @{$cats[0]};
5982: my $maxnum = $numtop;
1.120 raeburn 5983: my %default_names = (
5984: instcode => &mt('Official courses'),
5985: communities => &mt('Communities'),
5986: );
5987:
5988: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5989: ($cathash->{'instcode::0'} eq '') ||
5990: (!grep(/^communities$/,@{$cats[0]})) ||
5991: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5992: $maxnum ++;
5993: }
5994: my $lastidx;
5995: for (my $i=0; $i<$numtop; $i++) {
5996: my $parent = $cats[0][$i];
5997: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5998: my $item = &escape($parent).'::0';
5999: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6000: $lastidx = $idx{$item};
6001: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6002: .'<select name="'.$item.'"'.$chgstr.'>';
6003: for (my $k=0; $k<=$maxnum; $k++) {
6004: my $vpos = $k+1;
6005: my $selstr;
6006: if ($k == $i) {
6007: $selstr = ' selected="selected" ';
6008: }
6009: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6010: }
1.160.6.29 raeburn 6011: $datatable .= '</select></span></td><td>';
1.120 raeburn 6012: if ($parent eq 'instcode' || $parent eq 'communities') {
6013: $datatable .= '<span class="LC_nobreak">'
6014: .$default_names{$parent}.'</span>';
6015: if ($parent eq 'instcode') {
6016: $datatable .= '<br /><span class="LC_nobreak">('
6017: .&mt('with institutional codes')
6018: .')</span></td><td'.$colattrib.'>';
6019: } else {
6020: $datatable .= '<table><tr><td>';
6021: }
6022: $datatable .= '<span class="LC_nobreak">'
6023: .'<label><input type="radio" name="'
6024: .$parent.'" value="1" checked="checked" />'
6025: .&mt('Display').'</label>';
6026: if ($parent eq 'instcode') {
6027: $datatable .= ' ';
6028: } else {
6029: $datatable .= '</span></td></tr><tr><td>'
6030: .'<span class="LC_nobreak">';
6031: }
6032: $datatable .= '<label><input type="radio" name="'
6033: .$parent.'" value="0" />'
6034: .&mt('Do not display').'</label></span>';
6035: if ($parent eq 'communities') {
6036: $datatable .= '</td></tr></table>';
6037: }
6038: $datatable .= '</td>';
1.57 raeburn 6039: } else {
6040: $datatable .= $parent
1.160.6.29 raeburn 6041: .' <span class="LC_nobreak"><label>'
6042: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6043: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6044: }
6045: my $depth = 1;
6046: push(@path,$parent);
6047: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6048: pop(@path);
6049: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6050: $itemcount ++;
6051: }
1.48 raeburn 6052: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6053: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6054: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6055: for (my $k=0; $k<=$maxnum; $k++) {
6056: my $vpos = $k+1;
6057: my $selstr;
1.57 raeburn 6058: if ($k == $numtop) {
1.48 raeburn 6059: $selstr = ' selected="selected" ';
6060: }
6061: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6062: }
1.59 bisitz 6063: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6064: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6065: .'</tr>'."\n";
1.48 raeburn 6066: $itemcount ++;
1.120 raeburn 6067: foreach my $default ('instcode','communities') {
6068: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6069: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6070: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6071: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6072: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6073: for (my $k=0; $k<=$maxnum; $k++) {
6074: my $vpos = $k+1;
6075: my $selstr;
6076: if ($k == $maxnum) {
6077: $selstr = ' selected="selected" ';
6078: }
6079: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6080: }
1.120 raeburn 6081: $datatable .= '</select></span></td>'.
6082: '<td><span class="LC_nobreak">'.
6083: $default_names{$default}.'</span>';
6084: if ($default eq 'instcode') {
6085: $datatable .= '<br /><span class="LC_nobreak">('
6086: .&mt('with institutional codes').')</span>';
6087: }
6088: $datatable .= '</td>'
6089: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6090: .&mt('Display').'</label> '
6091: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6092: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6093: }
6094: }
6095: }
1.57 raeburn 6096: } else {
6097: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6098: }
6099: } else {
1.160.6.87 raeburn 6100: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 6101: .&initialize_categories($itemcount);
1.48 raeburn 6102: }
1.57 raeburn 6103: $$rowtotal += $itemcount;
1.48 raeburn 6104: }
6105: return $datatable;
6106: }
6107:
1.69 raeburn 6108: sub print_serverstatuses {
6109: my ($dom,$settings,$rowtotal) = @_;
6110: my $datatable;
6111: my @pages = &serverstatus_pages();
6112: my (%namedaccess,%machineaccess);
6113: foreach my $type (@pages) {
6114: $namedaccess{$type} = '';
6115: $machineaccess{$type}= '';
6116: }
6117: if (ref($settings) eq 'HASH') {
6118: foreach my $type (@pages) {
6119: if (exists($settings->{$type})) {
6120: if (ref($settings->{$type}) eq 'HASH') {
6121: foreach my $key (keys(%{$settings->{$type}})) {
6122: if ($key eq 'namedusers') {
6123: $namedaccess{$type} = $settings->{$type}->{$key};
6124: } elsif ($key eq 'machines') {
6125: $machineaccess{$type} = $settings->{$type}->{$key};
6126: }
6127: }
6128: }
6129: }
6130: }
6131: }
1.81 raeburn 6132: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6133: my $rownum = 0;
6134: my $css_class;
6135: foreach my $type (@pages) {
6136: $rownum ++;
6137: $css_class = $rownum%2?' class="LC_odd_row"':'';
6138: $datatable .= '<tr'.$css_class.'>'.
6139: '<td><span class="LC_nobreak">'.
6140: $titles->{$type}.'</span></td>'.
6141: '<td class="LC_left_item">'.
6142: '<input type="text" name="'.$type.'_namedusers" '.
6143: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6144: '<td class="LC_right_item">'.
6145: '<span class="LC_nobreak">'.
6146: '<input type="text" name="'.$type.'_machines" '.
6147: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 6148: '</span></td></tr>'."\n";
1.69 raeburn 6149: }
6150: $$rowtotal += $rownum;
6151: return $datatable;
6152: }
6153:
6154: sub serverstatus_pages {
6155: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 6156: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 6157: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 6158: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6159: }
6160:
1.160.6.40 raeburn 6161: sub defaults_javascript {
6162: my ($settings) = @_;
1.160.6.80 raeburn 6163: 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.');
6164: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6165: &js_escape(\$intauthcheck);
6166: &js_escape(\$intauthcost);
6167: my $intauthjs = <<"ENDSCRIPT";
6168:
6169: function warnIntAuth(field) {
6170: if (field.name == 'intauth_check') {
6171: if (field.value == '2') {
6172: alert('$intauthcheck');
6173: }
6174: }
6175: if (field.name == 'intauth_cost') {
6176: field.value.replace(/\s/g,'');
6177: if (field.value != '') {
6178: var regexdigit=/^\\d+\$/;
6179: if (!regexdigit.test(field.value)) {
6180: alert('$intauthcost');
6181: }
6182: }
6183: }
6184: return;
6185: }
6186:
6187: ENDSCRIPT
6188:
6189: if (ref($settings) ne 'HASH') {
6190: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6191: }
1.160.6.40 raeburn 6192: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6193: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6194: if ($maxnum eq '') {
6195: $maxnum = 0;
6196: }
6197: $maxnum ++;
1.160.6.51 raeburn 6198: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 6199: return <<"ENDSCRIPT";
6200: <script type="text/javascript">
6201: // <![CDATA[
6202: function reorderTypes(form,caller) {
6203: var changedVal;
6204: $jstext
6205: var newpos = 'addinststatus_pos';
6206: var current = new Array;
6207: var maxh = $maxnum;
6208: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6209: var oldVal;
6210: if (caller == newpos) {
6211: changedVal = newitemVal;
6212: } else {
6213: var curritem = 'inststatus_pos_'+caller;
6214: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6215: current[newitemVal] = newpos;
6216: }
6217: for (var i=0; i<inststatuses.length; i++) {
6218: if (inststatuses[i] != caller) {
6219: var elementName = 'inststatus_pos_'+inststatuses[i];
6220: if (form.elements[elementName]) {
6221: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6222: current[currVal] = elementName;
6223: }
6224: }
6225: }
6226: for (var j=0; j<maxh; j++) {
6227: if (current[j] == undefined) {
6228: oldVal = j;
6229: }
6230: }
6231: if (oldVal < changedVal) {
6232: for (var k=oldVal+1; k<=changedVal ; k++) {
6233: var elementName = current[k];
6234: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6235: }
6236: } else {
6237: for (var k=changedVal; k<oldVal; k++) {
6238: var elementName = current[k];
6239: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6240: }
6241: }
6242: return;
6243: }
6244:
1.160.6.80 raeburn 6245: $intauthjs
6246:
1.160.6.40 raeburn 6247: // ]]>
6248: </script>
6249:
6250: ENDSCRIPT
1.160.6.80 raeburn 6251: } else {
6252: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40 raeburn 6253: }
6254: }
6255:
1.49 raeburn 6256: sub coursecategories_javascript {
6257: my ($settings) = @_;
1.57 raeburn 6258: my ($output,$jstext,$cathash);
1.49 raeburn 6259: if (ref($settings) eq 'HASH') {
1.57 raeburn 6260: $cathash = $settings->{'cats'};
6261: }
6262: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6263: my (@cats,@jsarray,%idx);
1.57 raeburn 6264: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6265: if (@jsarray > 0) {
6266: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6267: for (my $i=0; $i<@jsarray; $i++) {
6268: if (ref($jsarray[$i]) eq 'ARRAY') {
6269: my $catstr = join('","',@{$jsarray[$i]});
6270: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6271: }
6272: }
6273: }
6274: } else {
6275: $jstext = ' var categories = Array(1);'."\n".
6276: ' categories[0] = Array("instcode_pos");'."\n";
6277: }
1.160.6.42 raeburn 6278: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6279: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 6280: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6281: &js_escape(\$instcode_reserved);
6282: &js_escape(\$communities_reserved);
6283: &js_escape(\$choose_again);
1.49 raeburn 6284: $output = <<"ENDSCRIPT";
6285: <script type="text/javascript">
1.109 raeburn 6286: // <![CDATA[
1.49 raeburn 6287: function reorderCats(form,parent,item,idx) {
6288: var changedVal;
6289: $jstext
6290: var newpos = 'addcategory_pos';
6291: if (parent == '') {
6292: var has_instcode = 0;
6293: var maxtop = categories[idx].length;
6294: for (var j=0; j<maxtop; j++) {
6295: if (categories[idx][j] == 'instcode::0') {
6296: has_instcode == 1;
6297: }
6298: }
6299: if (has_instcode == 0) {
6300: categories[idx][maxtop] = 'instcode_pos';
6301: }
6302: } else {
6303: newpos += '_'+parent;
6304: }
6305: var maxh = 1 + categories[idx].length;
6306: var current = new Array;
6307: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6308: if (item == newpos) {
6309: changedVal = newitemVal;
6310: } else {
6311: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6312: current[newitemVal] = newpos;
6313: }
6314: for (var i=0; i<categories[idx].length; i++) {
6315: var elementName = categories[idx][i];
6316: if (elementName != item) {
6317: if (form.elements[elementName]) {
6318: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6319: current[currVal] = elementName;
6320: }
6321: }
6322: }
6323: var oldVal;
6324: for (var j=0; j<maxh; j++) {
6325: if (current[j] == undefined) {
6326: oldVal = j;
6327: }
6328: }
6329: if (oldVal < changedVal) {
6330: for (var k=oldVal+1; k<=changedVal ; k++) {
6331: var elementName = current[k];
6332: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6333: }
6334: } else {
6335: for (var k=changedVal; k<oldVal; k++) {
6336: var elementName = current[k];
6337: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6338: }
6339: }
6340: return;
6341: }
1.120 raeburn 6342:
6343: function categoryCheck(form) {
6344: if (form.elements['addcategory_name'].value == 'instcode') {
6345: alert('$instcode_reserved\\n$choose_again');
6346: return false;
6347: }
6348: if (form.elements['addcategory_name'].value == 'communities') {
6349: alert('$communities_reserved\\n$choose_again');
6350: return false;
6351: }
6352: return true;
6353: }
6354:
1.109 raeburn 6355: // ]]>
1.49 raeburn 6356: </script>
6357:
6358: ENDSCRIPT
6359: return $output;
6360: }
6361:
1.48 raeburn 6362: sub initialize_categories {
6363: my ($itemcount) = @_;
1.120 raeburn 6364: my ($datatable,$css_class,$chgstr);
6365: my %default_names = (
6366: instcode => 'Official courses (with institutional codes)',
6367: communities => 'Communities',
6368: );
6369: my $select0 = ' selected="selected"';
6370: my $select1 = '';
6371: foreach my $default ('instcode','communities') {
6372: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 6373: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 6374: if ($default eq 'communities') {
6375: $select1 = $select0;
6376: $select0 = '';
6377: }
6378: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6379: .'<select name="'.$default.'_pos">'
6380: .'<option value="0"'.$select0.'>1</option>'
6381: .'<option value="1"'.$select1.'>2</option>'
6382: .'<option value="2">3</option></select> '
6383: .$default_names{$default}
6384: .'</span></td><td><span class="LC_nobreak">'
6385: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6386: .&mt('Display').'</label> <label>'
6387: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6388: .'</label></span></td></tr>';
1.120 raeburn 6389: $itemcount ++;
6390: }
1.48 raeburn 6391: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6392: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6393: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6394: .'<select name="addcategory_pos"'.$chgstr.'>'
6395: .'<option value="0">1</option>'
6396: .'<option value="1">2</option>'
6397: .'<option value="2" selected="selected">3</option></select> '
1.160.6.87 raeburn 6398: .&mt('Add category').'</span></td><tda<span class="LC_nobreak">>'.&mt('Name:')
6399: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
6400: .'</td></tr>';
1.48 raeburn 6401: return $datatable;
6402: }
6403:
6404: sub build_category_rows {
1.49 raeburn 6405: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6406: my ($text,$name,$item,$chgstr);
1.48 raeburn 6407: if (ref($cats) eq 'ARRAY') {
6408: my $maxdepth = scalar(@{$cats});
6409: if (ref($cats->[$depth]) eq 'HASH') {
6410: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6411: my $numchildren = @{$cats->[$depth]{$parent}};
6412: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 6413: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6414: my ($idxnum,$parent_name,$parent_item);
6415: my $higher = $depth - 1;
6416: if ($higher == 0) {
6417: $parent_name = &escape($parent).'::'.$higher;
6418: } else {
6419: if (ref($path) eq 'ARRAY') {
6420: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6421: }
6422: }
6423: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6424: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6425: if ($j < $numchildren) {
1.48 raeburn 6426: $name = $cats->[$depth]{$parent}[$j];
6427: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6428: $idxnum = $idx->{$item};
6429: } else {
6430: $name = $parent_name;
6431: $item = $parent_item;
1.48 raeburn 6432: }
1.49 raeburn 6433: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6434: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6435: for (my $i=0; $i<=$numchildren; $i++) {
6436: my $vpos = $i+1;
6437: my $selstr;
6438: if ($j == $i) {
6439: $selstr = ' selected="selected" ';
6440: }
6441: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6442: }
6443: $text .= '</select> ';
6444: if ($j < $numchildren) {
6445: my $deeper = $depth+1;
6446: $text .= $name.' '
6447: .'<label><input type="checkbox" name="deletecategory" value="'
6448: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6449: if(ref($path) eq 'ARRAY') {
6450: push(@{$path},$name);
1.49 raeburn 6451: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6452: pop(@{$path});
6453: }
6454: } else {
1.160.6.87 raeburn 6455: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 6456: if ($j == $numchildren) {
6457: $text .= $name;
6458: } else {
6459: $text .= $item;
6460: }
6461: $text .= '" value="" />';
6462: }
6463: $text .= '</td></tr>';
6464: }
6465: $text .= '</table></td>';
6466: } else {
6467: my $higher = $depth-1;
6468: if ($higher == 0) {
6469: $name = &escape($parent).'::'.$higher;
6470: } else {
6471: if (ref($path) eq 'ARRAY') {
6472: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6473: }
6474: }
6475: my $colspan;
6476: if ($parent ne 'instcode') {
6477: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 6478: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 6479: }
6480: }
6481: }
6482: }
6483: return $text;
6484: }
6485:
1.33 raeburn 6486: sub modifiable_userdata_row {
1.160.6.35 raeburn 6487: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6488: my ($role,$rolename,$statustype);
6489: $role = $item;
1.160.6.34 raeburn 6490: if ($context eq 'cancreate') {
1.160.6.35 raeburn 6491: if ($item =~ /^emailusername_(.+)$/) {
6492: $statustype = $1;
6493: $role = 'emailusername';
6494: if (ref($usertypes) eq 'HASH') {
6495: if ($usertypes->{$statustype}) {
6496: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6497: } else {
6498: $rolename = &mt('Data provided by user');
6499: }
6500: }
1.160.6.34 raeburn 6501: }
6502: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6503: if (ref($usertypes) eq 'HASH') {
6504: $rolename = $usertypes->{$role};
6505: } else {
6506: $rolename = $role;
6507: }
1.33 raeburn 6508: } else {
1.63 raeburn 6509: if ($role eq 'cr') {
6510: $rolename = &mt('Custom role');
6511: } else {
6512: $rolename = &Apache::lonnet::plaintext($role);
6513: }
1.33 raeburn 6514: }
1.160.6.34 raeburn 6515: my (@fields,%fieldtitles);
6516: if (ref($fieldsref) eq 'ARRAY') {
6517: @fields = @{$fieldsref};
6518: } else {
6519: @fields = ('lastname','firstname','middlename','generation',
6520: 'permanentemail','id');
6521: }
6522: if ((ref($titlesref) eq 'HASH')) {
6523: %fieldtitles = %{$titlesref};
6524: } else {
6525: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6526: }
1.33 raeburn 6527: my $output;
6528: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6529: $output = '<tr '.$css_class.'>'.
6530: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6531: '<td class="LC_left_item" colspan="2"><table>';
6532: my $rem;
6533: my %checks;
6534: if (ref($settings) eq 'HASH') {
6535: if (ref($settings->{$context}) eq 'HASH') {
6536: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 6537: my $hashref = $settings->{$context}->{$role};
6538: if ($role eq 'emailusername') {
6539: if ($statustype) {
6540: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6541: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 6542: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 6543: foreach my $field (@fields) {
6544: if ($hashref->{$field}) {
6545: $checks{$field} = $hashref->{$field};
6546: }
6547: }
6548: }
6549: }
6550: }
6551: } else {
6552: if (ref($hashref) eq 'HASH') {
6553: foreach my $field (@fields) {
6554: if ($hashref->{$field}) {
6555: $checks{$field} = ' checked="checked" ';
6556: }
6557: }
1.33 raeburn 6558: }
6559: }
6560: }
6561: }
6562: }
1.160.6.39 raeburn 6563:
1.33 raeburn 6564: for (my $i=0; $i<@fields; $i++) {
6565: my $rem = $i%($numinrow);
6566: if ($rem == 0) {
6567: if ($i > 0) {
6568: $output .= '</tr>';
6569: }
6570: $output .= '<tr>';
6571: }
6572: my $check = ' ';
1.160.6.35 raeburn 6573: unless ($role eq 'emailusername') {
6574: if (exists($checks{$fields[$i]})) {
6575: $check = $checks{$fields[$i]}
6576: } else {
6577: if ($role eq 'st') {
6578: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 6579: $check = ' checked="checked" ';
1.160.6.35 raeburn 6580: }
1.33 raeburn 6581: }
6582: }
6583: }
6584: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 6585: '<span class="LC_nobreak">';
6586: if ($role eq 'emailusername') {
6587: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6588: $checks{$fields[$i]} = 'omit';
6589: }
6590: foreach my $option ('required','optional','omit') {
6591: my $checked='';
6592: if ($checks{$fields[$i]} eq $option) {
6593: $checked='checked="checked" ';
6594: }
6595: $output .= '<label>'.
6596: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6597: &mt($option).'</label>'.(' ' x2);
6598: }
6599: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6600: } else {
6601: $output .= '<label>'.
6602: '<input type="checkbox" name="canmodify_'.$role.'" '.
6603: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6604: '</label>';
6605: }
6606: $output .= '</span></td>';
1.33 raeburn 6607: $rem = @fields%($numinrow);
6608: }
6609: my $colsleft = $numinrow - $rem;
6610: if ($colsleft > 1 ) {
6611: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6612: ' </td>';
6613: } elsif ($colsleft == 1) {
6614: $output .= '<td class="LC_left_item"> </td>';
6615: }
6616: $output .= '</tr></table></td></tr>';
6617: return $output;
6618: }
1.28 raeburn 6619:
1.93 raeburn 6620: sub insttypes_row {
1.160.6.34 raeburn 6621: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6622: my %lt = &Apache::lonlocal::texthash (
6623: cansearch => 'Users allowed to search',
6624: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6625: lockablenames => 'User preference to lock name',
1.93 raeburn 6626: );
6627: my $showdom;
6628: if ($context eq 'cansearch') {
6629: $showdom = ' ('.$dom.')';
6630: }
1.160.6.5 raeburn 6631: my $class = 'LC_left_item';
6632: if ($context eq 'statustocreate') {
6633: $class = 'LC_right_item';
6634: }
1.160.6.34 raeburn 6635: my $css_class = ' class="LC_odd_row"';
6636: if ($rownum ne '') {
6637: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6638: }
6639: my $output = '<tr'.$css_class.'>'.
6640: '<td>'.$lt{$context}.$showdom.
6641: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6642: my $rem;
6643: if (ref($types) eq 'ARRAY') {
6644: for (my $i=0; $i<@{$types}; $i++) {
6645: if (defined($usertypes->{$types->[$i]})) {
6646: my $rem = $i%($numinrow);
6647: if ($rem == 0) {
6648: if ($i > 0) {
6649: $output .= '</tr>';
6650: }
6651: $output .= '<tr>';
1.23 raeburn 6652: }
1.26 raeburn 6653: my $check = ' ';
1.99 raeburn 6654: if (ref($settings) eq 'HASH') {
6655: if (ref($settings->{$context}) eq 'ARRAY') {
6656: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6657: $check = ' checked="checked" ';
6658: }
6659: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6660: $check = ' checked="checked" ';
6661: }
1.23 raeburn 6662: }
1.26 raeburn 6663: $output .= '<td class="LC_left_item">'.
6664: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6665: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6666: 'value="'.$types->[$i].'"'.$check.'/>'.
6667: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6668: }
6669: }
1.26 raeburn 6670: $rem = @{$types}%($numinrow);
1.23 raeburn 6671: }
6672: my $colsleft = $numinrow - $rem;
1.160.6.87 raeburn 6673: if ($rem == 0) {
1.131 raeburn 6674: $output .= '<tr>';
6675: }
1.23 raeburn 6676: if ($colsleft > 1) {
1.25 raeburn 6677: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6678: } else {
1.25 raeburn 6679: $output .= '<td class="LC_left_item">';
1.23 raeburn 6680: }
6681: my $defcheck = ' ';
1.99 raeburn 6682: if (ref($settings) eq 'HASH') {
6683: if (ref($settings->{$context}) eq 'ARRAY') {
6684: if (grep(/^default$/,@{$settings->{$context}})) {
6685: $defcheck = ' checked="checked" ';
6686: }
6687: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6688: $defcheck = ' checked="checked" ';
6689: }
1.23 raeburn 6690: }
1.25 raeburn 6691: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6692: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6693: 'value="default"'.$defcheck.'/>'.
6694: $othertitle.'</label></span></td>'.
6695: '</tr></table></td></tr>';
6696: return $output;
1.23 raeburn 6697: }
6698:
6699: sub sorted_searchtitles {
6700: my %searchtitles = &Apache::lonlocal::texthash(
6701: 'uname' => 'username',
6702: 'lastname' => 'last name',
6703: 'lastfirst' => 'last name, first name',
6704: );
6705: my @titleorder = ('uname','lastname','lastfirst');
6706: return (\%searchtitles,\@titleorder);
6707: }
6708:
1.25 raeburn 6709: sub sorted_searchtypes {
6710: my %srchtypes_desc = (
6711: exact => 'is exact match',
6712: contains => 'contains ..',
6713: begins => 'begins with ..',
6714: );
6715: my @srchtypeorder = ('exact','begins','contains');
6716: return (\%srchtypes_desc,\@srchtypeorder);
6717: }
6718:
1.3 raeburn 6719: sub usertype_update_row {
6720: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6721: my $datatable;
6722: my $numinrow = 4;
6723: foreach my $type (@{$types}) {
6724: if (defined($usertypes->{$type})) {
6725: $$rownums ++;
6726: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6727: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6728: '</td><td class="LC_left_item"><table>';
6729: for (my $i=0; $i<@{$fields}; $i++) {
6730: my $rem = $i%($numinrow);
6731: if ($rem == 0) {
6732: if ($i > 0) {
6733: $datatable .= '</tr>';
6734: }
6735: $datatable .= '<tr>';
6736: }
6737: my $check = ' ';
1.39 raeburn 6738: if (ref($settings) eq 'HASH') {
6739: if (ref($settings->{'fields'}) eq 'HASH') {
6740: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6741: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6742: $check = ' checked="checked" ';
6743: }
1.3 raeburn 6744: }
6745: }
6746: }
6747:
6748: if ($i == @{$fields}-1) {
6749: my $colsleft = $numinrow - $rem;
6750: if ($colsleft > 1) {
6751: $datatable .= '<td colspan="'.$colsleft.'">';
6752: } else {
6753: $datatable .= '<td>';
6754: }
6755: } else {
6756: $datatable .= '<td>';
6757: }
1.8 raeburn 6758: $datatable .= '<span class="LC_nobreak"><label>'.
6759: '<input type="checkbox" name="updateable_'.$type.
6760: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6761: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6762: }
6763: $datatable .= '</tr></table></td></tr>';
6764: }
6765: }
6766: return $datatable;
1.1 raeburn 6767: }
6768:
6769: sub modify_login {
1.160.6.24 raeburn 6770: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 6771: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6772: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6773: %title = ( coursecatalog => 'Display course catalog',
6774: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 6775: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 6776: newuser => 'Link for visitors to create a user account',
6777: loginheader => 'Log-in box header');
6778: @offon = ('off','on');
1.112 raeburn 6779: if (ref($domconfig{login}) eq 'HASH') {
6780: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6781: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6782: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6783: }
6784: }
6785: }
1.9 raeburn 6786: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6787: \%domconfig,\%loginhash);
1.160.6.14 raeburn 6788: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6789: foreach my $item (@toggles) {
6790: $loginhash{login}{$item} = $env{'form.'.$item};
6791: }
1.41 raeburn 6792: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6793: if (ref($colchanges{'login'}) eq 'HASH') {
6794: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6795: \%loginhash);
6796: }
1.110 raeburn 6797:
1.149 raeburn 6798: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 6799: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6800: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6801: if (keys(%servers) > 1) {
6802: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6803: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6804: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6805: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6806: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6807: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6808: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6809: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6810: $changes{'loginvia'}{$lonhost} = 1;
6811: } else {
6812: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6813: $changes{'loginvia'}{$lonhost} = 1;
6814: }
6815: } else {
6816: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6817: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6818: $changes{'loginvia'}{$lonhost} = 1;
6819: }
6820: }
6821: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6822: foreach my $item (@loginvia_attribs) {
6823: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6824: }
6825: } else {
6826: foreach my $item (@loginvia_attribs) {
6827: my $new = $env{'form.'.$lonhost.'_'.$item};
6828: if (($item eq 'serverpath') && ($new eq 'custom')) {
6829: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6830: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6831: $new = '/';
6832: }
6833: }
6834: if (($item eq 'custompath') &&
6835: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6836: $new = '';
6837: }
6838: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6839: $changes{'loginvia'}{$lonhost} = 1;
6840: }
6841: if ($item eq 'exempt') {
1.160.6.56 raeburn 6842: $new = &check_exempt_addresses($new);
1.128 raeburn 6843: }
6844: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6845: }
6846: }
1.112 raeburn 6847: } else {
1.128 raeburn 6848: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6849: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6850: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6851: foreach my $item (@loginvia_attribs) {
6852: my $new = $env{'form.'.$lonhost.'_'.$item};
6853: if (($item eq 'serverpath') && ($new eq 'custom')) {
6854: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6855: $new = '/';
6856: }
6857: }
6858: if (($item eq 'custompath') &&
6859: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6860: $new = '';
6861: }
6862: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6863: }
1.110 raeburn 6864: }
6865: }
6866: }
6867: }
1.119 raeburn 6868:
1.160.6.5 raeburn 6869: my $servadm = $r->dir_config('lonAdmEMail');
6870: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6871: if (ref($domconfig{'login'}) eq 'HASH') {
6872: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6873: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6874: if ($lang eq 'nolang') {
6875: push(@currlangs,$lang);
6876: } elsif (defined($langchoices{$lang})) {
6877: push(@currlangs,$lang);
6878: } else {
6879: next;
6880: }
6881: }
6882: }
6883: }
6884: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6885: if (@currlangs > 0) {
6886: foreach my $lang (@currlangs) {
6887: if (grep(/^\Q$lang\E$/,@delurls)) {
6888: $changes{'helpurl'}{$lang} = 1;
6889: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6890: $changes{'helpurl'}{$lang} = 1;
6891: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6892: push(@newlangs,$lang);
6893: } else {
6894: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6895: }
6896: }
6897: }
6898: unless (grep(/^nolang$/,@currlangs)) {
6899: if ($env{'form.loginhelpurl_nolang.filename'}) {
6900: $changes{'helpurl'}{'nolang'} = 1;
6901: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6902: push(@newlangs,'nolang');
6903: }
6904: }
6905: if ($env{'form.loginhelpurl_add_lang'}) {
6906: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6907: ($env{'form.loginhelpurl_add_file.filename'})) {
6908: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6909: $addedfile = $env{'form.loginhelpurl_add_lang'};
6910: }
6911: }
6912: if ((@newlangs > 0) || ($addedfile)) {
6913: my $error;
6914: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6915: if ($configuserok eq 'ok') {
6916: if ($switchserver) {
6917: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6918: } elsif ($author_ok eq 'ok') {
6919: my @allnew = @newlangs;
6920: if ($addedfile ne '') {
6921: push(@allnew,$addedfile);
6922: }
6923: foreach my $lang (@allnew) {
6924: my $formelem = 'loginhelpurl_'.$lang;
6925: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6926: $formelem = 'loginhelpurl_add_file';
6927: }
6928: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6929: "help/$lang",'','',$newfile{$lang});
6930: if ($result eq 'ok') {
6931: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6932: $changes{'helpurl'}{$lang} = 1;
6933: } else {
6934: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6935: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6936: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6937: (!grep(/^\Q$lang\E$/,@delurls))) {
6938: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6939: }
6940: }
6941: }
6942: } else {
6943: $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);
6944: }
6945: } else {
6946: $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);
6947: }
6948: if ($error) {
6949: &Apache::lonnet::logthis($error);
6950: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6951: }
6952: }
1.160.6.56 raeburn 6953:
6954: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6955: if (ref($domconfig{'login'}) eq 'HASH') {
6956: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6957: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6958: if ($domservers{$lonhost}) {
6959: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6960: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 6961: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 6962: }
6963: }
6964: }
6965: }
6966: }
6967: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6968: foreach my $lonhost (sort(keys(%domservers))) {
6969: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6970: $changes{'headtag'}{$lonhost} = 1;
6971: } else {
6972: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6973: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6974: }
6975: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6976: push(@newhosts,$lonhost);
6977: } elsif ($currheadtagurls{$lonhost}) {
6978: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6979: if ($currexempt{$lonhost}) {
6980: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6981: $changes{'headtag'}{$lonhost} = 1;
6982: }
6983: } elsif ($possexempt{$lonhost}) {
6984: $changes{'headtag'}{$lonhost} = 1;
6985: }
6986: if ($possexempt{$lonhost}) {
6987: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6988: }
6989: }
6990: }
6991: }
6992: if (@newhosts) {
6993: my $error;
6994: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6995: if ($configuserok eq 'ok') {
6996: if ($switchserver) {
6997: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6998: } elsif ($author_ok eq 'ok') {
6999: foreach my $lonhost (@newhosts) {
7000: my $formelem = 'loginheadtag_'.$lonhost;
7001: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7002: "login/headtag/$lonhost",'','',
7003: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7004: if ($result eq 'ok') {
7005: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7006: $changes{'headtag'}{$lonhost} = 1;
7007: if ($possexempt{$lonhost}) {
7008: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7009: }
7010: } else {
7011: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7012: $newheadtagurls{$lonhost},$result);
7013: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7014: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7015: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7016: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7017: }
7018: }
7019: }
7020: } else {
7021: $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);
7022: }
7023: } else {
7024: $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);
7025: }
7026: if ($error) {
7027: &Apache::lonnet::logthis($error);
7028: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7029: }
7030: }
1.160.6.5 raeburn 7031: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7032:
7033: my $defaulthelpfile = '/adm/loginproblems.html';
7034: my $defaulttext = &mt('Default in use');
7035:
1.1 raeburn 7036: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7037: $dom);
7038: if ($putresult eq 'ok') {
1.160.6.14 raeburn 7039: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7040: my %defaultchecked = (
7041: 'coursecatalog' => 'on',
1.160.6.14 raeburn 7042: 'helpdesk' => 'on',
1.42 raeburn 7043: 'adminmail' => 'off',
1.43 raeburn 7044: 'newuser' => 'off',
1.42 raeburn 7045: );
1.55 raeburn 7046: if (ref($domconfig{'login'}) eq 'HASH') {
7047: foreach my $item (@toggles) {
7048: if ($defaultchecked{$item} eq 'on') {
7049: if (($domconfig{'login'}{$item} eq '0') &&
7050: ($env{'form.'.$item} eq '1')) {
7051: $changes{$item} = 1;
7052: } elsif (($domconfig{'login'}{$item} eq '' ||
7053: $domconfig{'login'}{$item} eq '1') &&
7054: ($env{'form.'.$item} eq '0')) {
7055: $changes{$item} = 1;
7056: }
7057: } elsif ($defaultchecked{$item} eq 'off') {
7058: if (($domconfig{'login'}{$item} eq '1') &&
7059: ($env{'form.'.$item} eq '0')) {
7060: $changes{$item} = 1;
7061: } elsif (($domconfig{'login'}{$item} eq '' ||
7062: $domconfig{'login'}{$item} eq '0') &&
7063: ($env{'form.'.$item} eq '1')) {
7064: $changes{$item} = 1;
7065: }
1.42 raeburn 7066: }
7067: }
1.41 raeburn 7068: }
1.6 raeburn 7069: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7070: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7071: if (ref($lastactref) eq 'HASH') {
7072: $lastactref->{'domainconfig'} = 1;
7073: }
1.1 raeburn 7074: $resulttext = &mt('Changes made:').'<ul>';
7075: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7076: if ($item eq 'loginvia') {
1.112 raeburn 7077: if (ref($changes{$item}) eq 'HASH') {
7078: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7079: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7080: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7081: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7082: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7083: $protocol = 'http' if ($protocol ne 'https');
7084: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7085:
7086: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7087: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7088: } else {
7089: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7090: }
7091: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7092: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7093: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7094: }
7095: $resulttext .= '</li>';
7096: } else {
7097: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7098: }
1.112 raeburn 7099: } else {
1.128 raeburn 7100: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7101: }
7102: }
1.128 raeburn 7103: $resulttext .= '</ul></li>';
1.112 raeburn 7104: }
1.160.6.5 raeburn 7105: } elsif ($item eq 'helpurl') {
7106: if (ref($changes{$item}) eq 'HASH') {
7107: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7108: if (grep(/^\Q$lang\E$/,@delurls)) {
7109: my ($chg,$link);
7110: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7111: if ($lang eq 'nolang') {
7112: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7113: } else {
7114: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7115: }
7116: $resulttext .= '<li>'.$chg.'</li>';
7117: } else {
7118: my $chg;
7119: if ($lang eq 'nolang') {
7120: $chg = &mt('custom log-in help file for no preferred language');
7121: } else {
7122: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7123: }
7124: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7125: $loginhash{'login'}{'helpurl'}{$lang}.
7126: '?inhibitmenu=yes',$chg,600,500).
7127: '</li>';
7128: }
7129: }
7130: }
1.160.6.56 raeburn 7131: } elsif ($item eq 'headtag') {
7132: if (ref($changes{$item}) eq 'HASH') {
7133: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7134: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7135: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7136: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7137: $resulttext .= '<li><a href="'.
7138: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7139: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7140: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7141: if ($possexempt{$lonhost}) {
7142: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7143: } else {
7144: $resulttext .= &mt('included for any client IP');
7145: }
7146: $resulttext .= '</li>';
7147: }
7148: }
7149: }
1.160.6.5 raeburn 7150: } elsif ($item eq 'captcha') {
7151: if (ref($loginhash{'login'}) eq 'HASH') {
7152: my $chgtxt;
7153: if ($loginhash{'login'}{$item} eq 'notused') {
7154: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7155: } else {
7156: my %captchas = &captcha_phrases();
7157: if ($captchas{$loginhash{'login'}{$item}}) {
7158: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7159: } else {
7160: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7161: }
7162: }
7163: $resulttext .= '<li>'.$chgtxt.'</li>';
7164: }
7165: } elsif ($item eq 'recaptchakeys') {
7166: if (ref($loginhash{'login'}) eq 'HASH') {
7167: my ($privkey,$pubkey);
7168: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7169: $pubkey = $loginhash{'login'}{$item}{'public'};
7170: $privkey = $loginhash{'login'}{$item}{'private'};
7171: }
7172: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7173: if (!$pubkey) {
7174: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7175: } else {
7176: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7177: }
7178: if (!$privkey) {
7179: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7180: } else {
1.160.6.53 raeburn 7181: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 7182: }
7183: $chgtxt .= '</ul>';
7184: $resulttext .= '<li>'.$chgtxt.'</li>';
7185: }
1.160.6.69 raeburn 7186: } elsif ($item eq 'recaptchaversion') {
7187: if (ref($loginhash{'login'}) eq 'HASH') {
7188: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
7189: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
7190: '</li>';
7191: }
7192: }
1.41 raeburn 7193: } else {
7194: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7195: }
1.1 raeburn 7196: }
1.6 raeburn 7197: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7198: } else {
7199: $resulttext = &mt('No changes made to log-in page settings');
7200: }
7201: } else {
1.11 albertel 7202: $resulttext = '<span class="LC_error">'.
7203: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7204: }
1.6 raeburn 7205: if ($errors) {
1.9 raeburn 7206: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7207: $errors.'</ul>';
7208: }
7209: return $resulttext;
7210: }
7211:
1.160.6.56 raeburn 7212: sub check_exempt_addresses {
7213: my ($iplist) = @_;
7214: $iplist =~ s/^\s+//;
7215: $iplist =~ s/\s+$//;
7216: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7217: my (@okips,$new);
7218: foreach my $ip (@poss_ips) {
7219: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7220: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7221: push(@okips,$ip);
7222: }
7223: }
7224: }
7225: if (@okips > 0) {
7226: $new = join(',',@okips);
7227: } else {
7228: $new = '';
7229: }
7230: return $new;
7231: }
7232:
1.6 raeburn 7233: sub color_font_choices {
7234: my %choices =
7235: &Apache::lonlocal::texthash (
7236: img => "Header",
7237: bgs => "Background colors",
7238: links => "Link colors",
1.55 raeburn 7239: images => "Images",
1.6 raeburn 7240: font => "Font color",
1.160.6.22 raeburn 7241: fontmenu => "Font menu",
1.76 raeburn 7242: pgbg => "Page",
1.6 raeburn 7243: tabbg => "Header",
7244: sidebg => "Border",
7245: link => "Link",
7246: alink => "Active link",
7247: vlink => "Visited link",
7248: );
7249: return %choices;
7250: }
7251:
7252: sub modify_rolecolors {
1.160.6.24 raeburn 7253: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7254: my ($resulttext,%rolehash);
7255: $rolehash{'rolecolors'} = {};
1.55 raeburn 7256: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7257: if ($domconfig{'rolecolors'} eq '') {
7258: $domconfig{'rolecolors'} = {};
7259: }
7260: }
1.9 raeburn 7261: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7262: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7263: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7264: $dom);
7265: if ($putresult eq 'ok') {
7266: if (keys(%changes) > 0) {
1.41 raeburn 7267: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7268: if (ref($lastactref) eq 'HASH') {
7269: $lastactref->{'domainconfig'} = 1;
7270: }
1.6 raeburn 7271: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7272: $rolehash{'rolecolors'});
7273: } else {
7274: $resulttext = &mt('No changes made to default color schemes');
7275: }
7276: } else {
1.11 albertel 7277: $resulttext = '<span class="LC_error">'.
7278: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7279: }
7280: if ($errors) {
7281: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7282: $errors.'</ul>';
7283: }
7284: return $resulttext;
7285: }
7286:
7287: sub modify_colors {
1.9 raeburn 7288: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7289: my (%changes,%choices);
1.51 raeburn 7290: my @bgs;
1.6 raeburn 7291: my @links = ('link','alink','vlink');
1.41 raeburn 7292: my @logintext;
1.6 raeburn 7293: my @images;
7294: my $servadm = $r->dir_config('lonAdmEMail');
7295: my $errors;
1.160.6.22 raeburn 7296: my %defaults;
1.6 raeburn 7297: foreach my $role (@{$roles}) {
7298: if ($role eq 'login') {
1.12 raeburn 7299: %choices = &login_choices();
1.41 raeburn 7300: @logintext = ('textcol','bgcol');
1.12 raeburn 7301: } else {
7302: %choices = &color_font_choices();
7303: }
7304: if ($role eq 'login') {
1.41 raeburn 7305: @images = ('img','logo','domlogo','login');
1.51 raeburn 7306: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7307: } else {
7308: @images = ('img');
1.160.6.22 raeburn 7309: @bgs = ('pgbg','tabbg','sidebg');
7310: }
7311: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7312: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7313: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7314: }
7315: if ($role eq 'login') {
7316: foreach my $item (@logintext) {
1.160.6.39 raeburn 7317: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7318: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7319: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7320: }
7321: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 7322: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7323: }
7324: }
7325: } else {
1.160.6.39 raeburn 7326: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7327: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7328: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7329: }
7330: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 7331: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7332: }
1.6 raeburn 7333: }
1.160.6.22 raeburn 7334: foreach my $item (@bgs) {
1.160.6.39 raeburn 7335: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7336: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7337: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7338: }
7339: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 7340: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7341: }
7342: }
7343: foreach my $item (@links) {
1.160.6.39 raeburn 7344: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7345: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7346: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7347: }
7348: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 7349: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7350: }
1.6 raeburn 7351: }
1.46 raeburn 7352: my ($configuserok,$author_ok,$switchserver) =
7353: &config_check($dom,$confname,$servadm);
1.9 raeburn 7354: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7355: if (ref($domconfig->{$role}) ne 'HASH') {
7356: $domconfig->{$role} = {};
7357: }
1.8 raeburn 7358: foreach my $img (@images) {
1.70 raeburn 7359: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7360: if (defined($env{'form.login_showlogo_'.$img})) {
7361: $confhash->{$role}{'showlogo'}{$img} = 1;
7362: } else {
7363: $confhash->{$role}{'showlogo'}{$img} = 0;
7364: }
7365: }
1.18 albertel 7366: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7367: && !defined($domconfig->{$role}{$img})
7368: && !$env{'form.'.$role.'_del_'.$img}
7369: && $env{'form.'.$role.'_import_'.$img}) {
7370: # import the old configured image from the .tab setting
7371: # if they haven't provided a new one
7372: $domconfig->{$role}{$img} =
7373: $env{'form.'.$role.'_import_'.$img};
7374: }
1.6 raeburn 7375: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7376: my $error;
1.6 raeburn 7377: if ($configuserok eq 'ok') {
1.9 raeburn 7378: if ($switchserver) {
1.12 raeburn 7379: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7380: } else {
7381: if ($author_ok eq 'ok') {
7382: my ($result,$logourl) =
7383: &publishlogo($r,'upload',$role.'_'.$img,
7384: $dom,$confname,$img,$width,$height);
7385: if ($result eq 'ok') {
7386: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7387: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7388: } else {
1.12 raeburn 7389: $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 7390: }
7391: } else {
1.46 raeburn 7392: $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 7393: }
7394: }
7395: } else {
1.46 raeburn 7396: $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 7397: }
7398: if ($error) {
1.8 raeburn 7399: &Apache::lonnet::logthis($error);
1.11 albertel 7400: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7401: }
7402: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7403: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7404: my $error;
7405: if ($configuserok eq 'ok') {
7406: # is confname an author?
7407: if ($switchserver eq '') {
7408: if ($author_ok eq 'ok') {
7409: my ($result,$logourl) =
7410: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7411: $dom,$confname,$img,$width,$height);
7412: if ($result eq 'ok') {
7413: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7414: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7415: }
7416: }
7417: }
7418: }
1.6 raeburn 7419: }
7420: }
7421: }
7422: if (ref($domconfig) eq 'HASH') {
7423: if (ref($domconfig->{$role}) eq 'HASH') {
7424: foreach my $img (@images) {
7425: if ($domconfig->{$role}{$img} ne '') {
7426: if ($env{'form.'.$role.'_del_'.$img}) {
7427: $confhash->{$role}{$img} = '';
1.12 raeburn 7428: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7429: } else {
1.9 raeburn 7430: if ($confhash->{$role}{$img} eq '') {
7431: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7432: }
1.6 raeburn 7433: }
7434: } else {
7435: if ($env{'form.'.$role.'_del_'.$img}) {
7436: $confhash->{$role}{$img} = '';
1.12 raeburn 7437: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7438: }
7439: }
1.70 raeburn 7440: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7441: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7442: if ($confhash->{$role}{'showlogo'}{$img} ne
7443: $domconfig->{$role}{'showlogo'}{$img}) {
7444: $changes{$role}{'showlogo'}{$img} = 1;
7445: }
7446: } else {
7447: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7448: $changes{$role}{'showlogo'}{$img} = 1;
7449: }
7450: }
7451: }
7452: }
1.6 raeburn 7453: if ($domconfig->{$role}{'font'} ne '') {
7454: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7455: $changes{$role}{'font'} = 1;
7456: }
7457: } else {
7458: if ($confhash->{$role}{'font'}) {
7459: $changes{$role}{'font'} = 1;
7460: }
7461: }
1.107 raeburn 7462: if ($role ne 'login') {
7463: if ($domconfig->{$role}{'fontmenu'} ne '') {
7464: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7465: $changes{$role}{'fontmenu'} = 1;
7466: }
7467: } else {
7468: if ($confhash->{$role}{'fontmenu'}) {
7469: $changes{$role}{'fontmenu'} = 1;
7470: }
1.97 tempelho 7471: }
7472: }
1.6 raeburn 7473: foreach my $item (@bgs) {
7474: if ($domconfig->{$role}{$item} ne '') {
7475: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7476: $changes{$role}{'bgs'}{$item} = 1;
7477: }
7478: } else {
7479: if ($confhash->{$role}{$item}) {
7480: $changes{$role}{'bgs'}{$item} = 1;
7481: }
7482: }
7483: }
7484: foreach my $item (@links) {
7485: if ($domconfig->{$role}{$item} ne '') {
7486: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7487: $changes{$role}{'links'}{$item} = 1;
7488: }
7489: } else {
7490: if ($confhash->{$role}{$item}) {
7491: $changes{$role}{'links'}{$item} = 1;
7492: }
7493: }
7494: }
1.41 raeburn 7495: foreach my $item (@logintext) {
7496: if ($domconfig->{$role}{$item} ne '') {
7497: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7498: $changes{$role}{'logintext'}{$item} = 1;
7499: }
7500: } else {
7501: if ($confhash->{$role}{$item}) {
7502: $changes{$role}{'logintext'}{$item} = 1;
7503: }
7504: }
7505: }
1.6 raeburn 7506: } else {
7507: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7508: \@logintext,$confhash,\%changes);
1.6 raeburn 7509: }
7510: } else {
7511: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7512: \@logintext,$confhash,\%changes);
1.6 raeburn 7513: }
7514: }
7515: return ($errors,%changes);
7516: }
7517:
1.46 raeburn 7518: sub config_check {
7519: my ($dom,$confname,$servadm) = @_;
7520: my ($configuserok,$author_ok,$switchserver,%currroles);
7521: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7522: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7523: $confname,$servadm);
7524: if ($configuserok eq 'ok') {
7525: $switchserver = &check_switchserver($dom,$confname);
7526: if ($switchserver eq '') {
7527: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7528: }
7529: }
7530: return ($configuserok,$author_ok,$switchserver);
7531: }
7532:
1.6 raeburn 7533: sub default_change_checker {
1.41 raeburn 7534: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7535: foreach my $item (@{$links}) {
7536: if ($confhash->{$role}{$item}) {
7537: $changes->{$role}{'links'}{$item} = 1;
7538: }
7539: }
7540: foreach my $item (@{$bgs}) {
7541: if ($confhash->{$role}{$item}) {
7542: $changes->{$role}{'bgs'}{$item} = 1;
7543: }
7544: }
1.41 raeburn 7545: foreach my $item (@{$logintext}) {
7546: if ($confhash->{$role}{$item}) {
7547: $changes->{$role}{'logintext'}{$item} = 1;
7548: }
7549: }
1.6 raeburn 7550: foreach my $img (@{$images}) {
7551: if ($env{'form.'.$role.'_del_'.$img}) {
7552: $confhash->{$role}{$img} = '';
1.12 raeburn 7553: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7554: }
1.70 raeburn 7555: if ($role eq 'login') {
7556: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7557: $changes->{$role}{'showlogo'}{$img} = 1;
7558: }
7559: }
1.6 raeburn 7560: }
7561: if ($confhash->{$role}{'font'}) {
7562: $changes->{$role}{'font'} = 1;
7563: }
1.48 raeburn 7564: }
1.6 raeburn 7565:
7566: sub display_colorchgs {
7567: my ($dom,$changes,$roles,$confhash) = @_;
7568: my (%choices,$resulttext);
7569: if (!grep(/^login$/,@{$roles})) {
7570: $resulttext = &mt('Changes made:').'<br />';
7571: }
7572: foreach my $role (@{$roles}) {
7573: if ($role eq 'login') {
7574: %choices = &login_choices();
7575: } else {
7576: %choices = &color_font_choices();
7577: }
7578: if (ref($changes->{$role}) eq 'HASH') {
7579: if ($role ne 'login') {
7580: $resulttext .= '<h4>'.&mt($role).'</h4>';
7581: }
7582: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7583: if ($role ne 'login') {
7584: $resulttext .= '<ul>';
7585: }
7586: if (ref($changes->{$role}{$key}) eq 'HASH') {
7587: if ($role ne 'login') {
7588: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7589: }
7590: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7591: if (($role eq 'login') && ($key eq 'showlogo')) {
7592: if ($confhash->{$role}{$key}{$item}) {
7593: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7594: } else {
7595: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7596: }
7597: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7598: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7599: } else {
1.12 raeburn 7600: my $newitem = $confhash->{$role}{$item};
7601: if ($key eq 'images') {
7602: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7603: }
7604: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7605: }
7606: }
7607: if ($role ne 'login') {
7608: $resulttext .= '</ul></li>';
7609: }
7610: } else {
7611: if ($confhash->{$role}{$key} eq '') {
7612: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7613: } else {
7614: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7615: }
7616: }
7617: if ($role ne 'login') {
7618: $resulttext .= '</ul>';
7619: }
7620: }
7621: }
7622: }
1.3 raeburn 7623: return $resulttext;
1.1 raeburn 7624: }
7625:
1.9 raeburn 7626: sub thumb_dimensions {
7627: return ('200','50');
7628: }
7629:
1.16 raeburn 7630: sub check_dimensions {
7631: my ($inputfile) = @_;
7632: my ($fullwidth,$fullheight);
7633: if ($inputfile =~ m|^[/\w.\-]+$|) {
7634: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7635: my $imageinfo = <PIPE>;
7636: if (!close(PIPE)) {
7637: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7638: }
7639: chomp($imageinfo);
7640: my ($fullsize) =
1.21 raeburn 7641: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7642: if ($fullsize) {
7643: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7644: }
7645: }
7646: }
7647: return ($fullwidth,$fullheight);
7648: }
7649:
1.9 raeburn 7650: sub check_configuser {
7651: my ($uhome,$dom,$confname,$servadm) = @_;
7652: my ($configuserok,%currroles);
7653: if ($uhome eq 'no_host') {
7654: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7655: my $configpass = &LONCAPA::Enrollment::create_password();
7656: $configuserok =
7657: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7658: $configpass,'','','','','',undef,$servadm);
7659: } else {
7660: $configuserok = 'ok';
7661: %currroles =
7662: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7663: }
7664: return ($configuserok,%currroles);
7665: }
7666:
7667: sub check_authorstatus {
7668: my ($dom,$confname,%currroles) = @_;
7669: my $author_ok;
1.40 raeburn 7670: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7671: my $start = time;
7672: my $end = 0;
7673: $author_ok =
7674: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7675: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7676: } else {
7677: $author_ok = 'ok';
7678: }
7679: return $author_ok;
7680: }
7681:
7682: sub publishlogo {
1.46 raeburn 7683: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 7684: my ($output,$fname,$logourl);
7685: if ($action eq 'upload') {
7686: $fname=$env{'form.'.$formname.'.filename'};
7687: chop($env{'form.'.$formname});
7688: } else {
7689: ($fname) = ($formname =~ /([^\/]+)$/);
7690: }
1.46 raeburn 7691: if ($savefileas ne '') {
7692: $fname = $savefileas;
7693: }
1.9 raeburn 7694: $fname=&Apache::lonnet::clean_filename($fname);
7695: # See if there is anything left
7696: unless ($fname) { return ('error: no uploaded file'); }
7697: $fname="$subdir/$fname";
1.160.6.5 raeburn 7698: my $docroot=$r->dir_config('lonDocRoot');
7699: my $filepath="$docroot/priv";
7700: my $relpath = "$dom/$confname";
1.9 raeburn 7701: my ($fnamepath,$file,$fetchthumb);
7702: $file=$fname;
7703: if ($fname=~m|/|) {
7704: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7705: }
1.160.6.26 raeburn 7706: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7707: my $count;
1.160.6.5 raeburn 7708: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7709: $filepath.="/$parts[$count]";
7710: if ((-e $filepath)!=1) {
7711: mkdir($filepath,02770);
7712: }
7713: }
7714: # Check for bad extension and disallow upload
7715: if ($file=~/\.(\w+)$/ &&
7716: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7717: $output =
1.160.6.25 raeburn 7718: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7719: } elsif ($file=~/\.(\w+)$/ &&
7720: !defined(&Apache::loncommon::fileembstyle($1))) {
7721: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7722: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 7723: $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 7724: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 7725: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7726: } else {
7727: my $source = $filepath.'/'.$file;
7728: my $logfile;
1.160.6.88 raeburn 7729: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 7730: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7731: }
7732: print $logfile
7733: "\n================= Publish ".localtime()." ================\n".
7734: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7735: # Save the file
1.160.6.88 raeburn 7736: if (!open(FH,">",$source)) {
1.9 raeburn 7737: &Apache::lonnet::logthis('Failed to create '.$source);
7738: return (&mt('Failed to create file'));
7739: }
7740: if ($action eq 'upload') {
7741: if (!print FH ($env{'form.'.$formname})) {
7742: &Apache::lonnet::logthis('Failed to write to '.$source);
7743: return (&mt('Failed to write file'));
7744: }
7745: } else {
7746: my $original = &Apache::lonnet::filelocation('',$formname);
7747: if(!copy($original,$source)) {
7748: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7749: return (&mt('Failed to write file'));
7750: }
7751: }
7752: close(FH);
7753: chmod(0660, $source); # Permissions to rw-rw---.
7754:
7755: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7756: my $copyfile=$targetdir.'/'.$file;
7757:
7758: my @parts=split(/\//,$targetdir);
7759: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7760: for (my $count=5;$count<=$#parts;$count++) {
7761: $path.="/$parts[$count]";
7762: if (!-e $path) {
7763: print $logfile "\nCreating directory ".$path;
7764: mkdir($path,02770);
7765: }
7766: }
7767: my $versionresult;
7768: if (-e $copyfile) {
7769: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7770: } else {
7771: $versionresult = 'ok';
7772: }
7773: if ($versionresult eq 'ok') {
7774: if (copy($source,$copyfile)) {
7775: print $logfile "\nCopied original source to ".$copyfile."\n";
7776: $output = 'ok';
7777: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7778: push(@{$modified_urls},[$copyfile,$source]);
7779: my $metaoutput =
7780: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7781: unless ($registered_cleanup) {
7782: my $handlers = $r->get_handlers('PerlCleanupHandler');
7783: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7784: $registered_cleanup=1;
7785: }
1.9 raeburn 7786: } else {
7787: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7788: $output = &mt('Failed to copy file to RES space').", $!";
7789: }
7790: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7791: my $inputfile = $filepath.'/'.$file;
7792: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7793: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7794: if ($fullwidth ne '' && $fullheight ne '') {
7795: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7796: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 7797: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
7798: system({$args[0]} @args);
1.16 raeburn 7799: chmod(0660, $filepath.'/tn-'.$file);
7800: if (-e $outfile) {
7801: my $copyfile=$targetdir.'/tn-'.$file;
7802: if (copy($outfile,$copyfile)) {
7803: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7804: my $thumb_metaoutput =
7805: &write_metadata($dom,$confname,$formname,
7806: $targetdir,'tn-'.$file,$logfile);
7807: push(@{$modified_urls},[$copyfile,$outfile]);
7808: unless ($registered_cleanup) {
7809: my $handlers = $r->get_handlers('PerlCleanupHandler');
7810: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7811: $registered_cleanup=1;
7812: }
1.16 raeburn 7813: } else {
7814: print $logfile "\nUnable to write ".$copyfile.
7815: ':'.$!."\n";
7816: }
7817: }
1.9 raeburn 7818: }
7819: }
7820: }
7821: } else {
7822: $output = $versionresult;
7823: }
7824: }
7825: return ($output,$logourl);
7826: }
7827:
7828: sub logo_versioning {
7829: my ($targetdir,$file,$logfile) = @_;
7830: my $target = $targetdir.'/'.$file;
7831: my ($maxversion,$fn,$extn,$output);
7832: $maxversion = 0;
7833: if ($file =~ /^(.+)\.(\w+)$/) {
7834: $fn=$1;
7835: $extn=$2;
7836: }
7837: opendir(DIR,$targetdir);
7838: while (my $filename=readdir(DIR)) {
7839: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7840: $maxversion=($1>$maxversion)?$1:$maxversion;
7841: }
7842: }
7843: $maxversion++;
7844: print $logfile "\nCreating old version ".$maxversion."\n";
7845: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7846: if (copy($target,$copyfile)) {
7847: print $logfile "Copied old target to ".$copyfile."\n";
7848: $copyfile=$copyfile.'.meta';
7849: if (copy($target.'.meta',$copyfile)) {
7850: print $logfile "Copied old target metadata to ".$copyfile."\n";
7851: $output = 'ok';
7852: } else {
7853: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7854: $output = &mt('Failed to copy old meta').", $!, ";
7855: }
7856: } else {
7857: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7858: $output = &mt('Failed to copy old target').", $!, ";
7859: }
7860: return $output;
7861: }
7862:
7863: sub write_metadata {
7864: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7865: my (%metadatafields,%metadatakeys,$output);
7866: $metadatafields{'title'}=$formname;
7867: $metadatafields{'creationdate'}=time;
7868: $metadatafields{'lastrevisiondate'}=time;
7869: $metadatafields{'copyright'}='public';
7870: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7871: $env{'user.domain'};
7872: $metadatafields{'authorspace'}=$confname.':'.$dom;
7873: $metadatafields{'domain'}=$dom;
7874: {
7875: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7876: my $mfh;
1.160.6.88 raeburn 7877: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 7878: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7879: unless ($_=~/\./) {
7880: my $unikey=$_;
7881: $unikey=~/^([A-Za-z]+)/;
7882: my $tag=$1;
7883: $tag=~tr/A-Z/a-z/;
7884: print $mfh "\n\<$tag";
7885: foreach (split(/\,/,$metadatakeys{$unikey})) {
7886: my $value=$metadatafields{$unikey.'.'.$_};
7887: $value=~s/\"/\'\'/g;
7888: print $mfh ' '.$_.'="'.$value.'"';
7889: }
7890: print $mfh '>'.
7891: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7892: .'</'.$tag.'>';
7893: }
7894: }
7895: $output = 'ok';
7896: print $logfile "\nWrote metadata";
7897: close($mfh);
7898: } else {
7899: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7900: $output = &mt('Could not write metadata');
7901: }
7902: }
1.155 raeburn 7903: return $output;
7904: }
7905:
7906: sub notifysubscribed {
7907: foreach my $targetsource (@{$modified_urls}){
7908: next unless (ref($targetsource) eq 'ARRAY');
7909: my ($target,$source)=@{$targetsource};
7910: if ($source ne '') {
1.160.6.88 raeburn 7911: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 7912: print $logfh "\nCleanup phase: Notifications\n";
7913: my @subscribed=&subscribed_hosts($target);
7914: foreach my $subhost (@subscribed) {
7915: print $logfh "\nNotifying host ".$subhost.':';
7916: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7917: print $logfh $reply;
7918: }
7919: my @subscribedmeta=&subscribed_hosts("$target.meta");
7920: foreach my $subhost (@subscribedmeta) {
7921: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7922: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7923: $subhost);
7924: print $logfh $reply;
7925: }
7926: print $logfh "\n============ Done ============\n";
1.160 raeburn 7927: close($logfh);
1.155 raeburn 7928: }
7929: }
7930: }
7931: return OK;
7932: }
7933:
7934: sub subscribed_hosts {
7935: my ($target) = @_;
7936: my @subscribed;
1.160.6.88 raeburn 7937: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 7938: while (my $subline=<$fh>) {
7939: if ($subline =~ /^($match_lonid):/) {
7940: my $host = $1;
7941: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7942: unless (grep(/^\Q$host\E$/,@subscribed)) {
7943: push(@subscribed,$host);
7944: }
7945: }
7946: }
7947: }
7948: }
7949: return @subscribed;
1.9 raeburn 7950: }
7951:
7952: sub check_switchserver {
7953: my ($dom,$confname) = @_;
7954: my ($allowed,$switchserver);
7955: my $home = &Apache::lonnet::homeserver($confname,$dom);
7956: if ($home eq 'no_host') {
7957: $home = &Apache::lonnet::domain($dom,'primary');
7958: }
7959: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7960: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7961: if (!$allowed) {
1.160.6.11 raeburn 7962: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7963: }
7964: return $switchserver;
7965: }
7966:
1.1 raeburn 7967: sub modify_quotas {
1.160.6.30 raeburn 7968: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7969: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7970: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7971: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7972: $validationfieldsref);
1.86 raeburn 7973: if ($action eq 'quotas') {
7974: $context = 'tools';
1.160.6.26 raeburn 7975: } else {
1.86 raeburn 7976: $context = $action;
7977: }
7978: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7979: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7980: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7981: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7982: %titles = &courserequest_titles();
7983: $toolregexp = join('|',@usertools);
7984: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7985: $confname = $dom.'-domainconfig';
7986: my $servadm = $r->dir_config('lonAdmEMail');
7987: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7988: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7989: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7990: } elsif ($context eq 'requestauthor') {
7991: @usertools = ('author');
7992: %titles = &authorrequest_titles();
1.86 raeburn 7993: } else {
1.160.6.4 raeburn 7994: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7995: %titles = &tool_titles();
1.86 raeburn 7996: }
1.160.6.27 raeburn 7997: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7998: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7999: foreach my $key (keys(%env)) {
1.101 raeburn 8000: if ($context eq 'requestcourses') {
8001: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8002: my $item = $1;
8003: my $type = $2;
8004: if ($type =~ /^limit_(.+)/) {
8005: $limithash{$item}{$1} = $env{$key};
8006: } else {
8007: $confhash{$item}{$type} = $env{$key};
8008: }
8009: }
1.160.6.5 raeburn 8010: } elsif ($context eq 'requestauthor') {
8011: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8012: $confhash{$1} = $env{$key};
8013: }
1.101 raeburn 8014: } else {
1.86 raeburn 8015: if ($key =~ /^form\.quota_(.+)$/) {
8016: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 8017: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8018: $confhash{'authorquota'}{$1} = $env{$key};
8019: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8020: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8021: }
1.72 raeburn 8022: }
8023: }
1.160.6.5 raeburn 8024: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 8025: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8026: @approvalnotify = sort(@approvalnotify);
8027: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 8028: my @crstypes = ('official','unofficial','community','textbook');
8029: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8030: foreach my $type (@hasuniquecode) {
8031: if (grep(/^\Q$type\E$/,@crstypes)) {
8032: $confhash{'uniquecode'}{$type} = 1;
8033: }
8034: }
1.160.6.46 raeburn 8035: my (%newbook,%allpos);
1.160.6.30 raeburn 8036: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8037: foreach my $type ('textbooks','templates') {
8038: @{$allpos{$type}} = ();
8039: my $invalid;
8040: if ($type eq 'textbooks') {
8041: $invalid = &mt('Invalid LON-CAPA course for textbook');
8042: } else {
8043: $invalid = &mt('Invalid LON-CAPA course for template');
8044: }
8045: if ($env{'form.'.$type.'_addbook'}) {
8046: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8047: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8048: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8049: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8050: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8051: } else {
8052: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8053: my $position = $env{'form.'.$type.'_addbook_pos'};
8054: $position =~ s/\D+//g;
8055: if ($position ne '') {
8056: $allpos{$type}[$position] = $newbook{$type};
8057: }
1.160.6.30 raeburn 8058: }
1.160.6.46 raeburn 8059: } else {
8060: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 8061: }
8062: }
1.160.6.46 raeburn 8063: }
1.160.6.30 raeburn 8064: }
1.102 raeburn 8065: if (ref($domconfig{$action}) eq 'HASH') {
8066: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8067: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8068: $changes{'notify'}{'approval'} = 1;
8069: }
8070: } else {
1.144 raeburn 8071: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8072: $changes{'notify'}{'approval'} = 1;
8073: }
8074: }
1.160.6.30 raeburn 8075: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8076: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8077: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8078: unless ($confhash{'uniquecode'}{$crstype}) {
8079: $changes{'uniquecode'} = 1;
8080: }
8081: }
8082: unless ($changes{'uniquecode'}) {
8083: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8084: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8085: $changes{'uniquecode'} = 1;
8086: }
8087: }
8088: }
8089: } else {
8090: $changes{'uniquecode'} = 1;
8091: }
8092: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8093: $changes{'uniquecode'} = 1;
8094: }
8095: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8096: foreach my $type ('textbooks','templates') {
8097: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8098: my %deletions;
8099: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8100: if (@todelete) {
8101: map { $deletions{$_} = 1; } @todelete;
8102: }
8103: my %imgdeletions;
8104: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8105: if (@todeleteimages) {
8106: map { $imgdeletions{$_} = 1; } @todeleteimages;
8107: }
8108: my $maxnum = $env{'form.'.$type.'_maxnum'};
8109: for (my $i=0; $i<=$maxnum; $i++) {
8110: my $itemid = $env{'form.'.$type.'_id_'.$i};
8111: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8112: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8113: if ($deletions{$key}) {
8114: if ($domconfig{$action}{$type}{$key}{'image'}) {
8115: #FIXME need to obsolete item in RES space
8116: }
8117: next;
8118: } else {
8119: my $newpos = $env{'form.'.$itemid};
8120: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 8121: foreach my $item ('subject','title','publisher','author') {
8122: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8123: ($type eq 'templates'));
1.160.6.46 raeburn 8124: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8125: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8126: $changes{$type}{$key} = 1;
8127: }
8128: }
8129: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 8130: }
1.160.6.46 raeburn 8131: if ($imgdeletions{$key}) {
8132: $changes{$type}{$key} = 1;
8133: #FIXME need to obsolete item in RES space
8134: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8135: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 8136: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
8137: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
8138: } else {
8139: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8140: $cdom,$cnum,$type,$configuserok,
8141: $switchserver,$author_ok);
8142: if ($imgurl) {
8143: $confhash{$type}{$key}{'image'} = $imgurl;
8144: $changes{$type}{$key} = 1;
8145: }
8146: if ($error) {
8147: &Apache::lonnet::logthis($error);
8148: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8149: }
1.160.6.46 raeburn 8150: }
8151: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8152: $confhash{$type}{$key}{'image'} =
8153: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 8154: }
8155: }
8156: }
8157: }
8158: }
8159: }
1.102 raeburn 8160: } else {
1.144 raeburn 8161: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8162: $changes{'notify'}{'approval'} = 1;
8163: }
1.160.6.30 raeburn 8164: if (ref($confhash{'uniquecode'} eq 'HASH')) {
8165: $changes{'uniquecode'} = 1;
8166: }
8167: }
8168: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8169: foreach my $type ('textbooks','templates') {
8170: if ($newbook{$type}) {
8171: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 8172: foreach my $item ('subject','title','publisher','author') {
8173: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8174: ($type eq 'template'));
1.160.6.46 raeburn 8175: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8176: if ($env{'form.'.$type.'_addbook_'.$item}) {
8177: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8178: }
8179: }
8180: if ($type eq 'textbooks') {
8181: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8182: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 8183: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
8184: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
8185: } else {
8186: my ($imageurl,$error) =
8187: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8188: $configuserok,$switchserver,$author_ok);
8189: if ($imageurl) {
8190: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8191: }
8192: if ($error) {
8193: &Apache::lonnet::logthis($error);
8194: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8195: }
1.160.6.46 raeburn 8196: }
8197: }
1.160.6.30 raeburn 8198: }
8199: }
1.160.6.46 raeburn 8200: if (@{$allpos{$type}} > 0) {
8201: my $idx = 0;
8202: foreach my $item (@{$allpos{$type}}) {
8203: if ($item ne '') {
8204: $confhash{$type}{$item}{'order'} = $idx;
8205: if (ref($domconfig{$action}) eq 'HASH') {
8206: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8207: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8208: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8209: $changes{$type}{$item} = 1;
8210: }
1.160.6.30 raeburn 8211: }
8212: }
8213: }
1.160.6.46 raeburn 8214: $idx ++;
1.160.6.30 raeburn 8215: }
8216: }
8217: }
8218: }
1.160.6.39 raeburn 8219: if (ref($validationitemsref) eq 'ARRAY') {
8220: foreach my $item (@{$validationitemsref}) {
8221: if ($item eq 'fields') {
8222: my @changed;
8223: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8224: if (@{$confhash{'validation'}{$item}} > 0) {
8225: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8226: }
1.160.6.65 raeburn 8227: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8228: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8229: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8230: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8231: $domconfig{'requestcourses'}{'validation'}{$item});
8232: } else {
8233: @changed = @{$confhash{'validation'}{$item}};
8234: }
1.160.6.39 raeburn 8235: } else {
8236: @changed = @{$confhash{'validation'}{$item}};
8237: }
8238: } else {
8239: @changed = @{$confhash{'validation'}{$item}};
8240: }
8241: if (@changed) {
8242: if ($confhash{'validation'}{$item}) {
8243: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8244: } else {
8245: $changes{'validation'}{$item} = &mt('None');
8246: }
8247: }
8248: } else {
8249: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8250: if ($item eq 'markup') {
8251: if ($env{'form.requestcourses_validation_'.$item}) {
8252: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8253: }
8254: }
1.160.6.65 raeburn 8255: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8256: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8257: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8258: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8259: }
8260: } else {
8261: if ($confhash{'validation'}{$item} ne '') {
8262: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8263: }
1.160.6.39 raeburn 8264: }
8265: } else {
8266: if ($confhash{'validation'}{$item} ne '') {
8267: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8268: }
8269: }
8270: }
8271: }
8272: }
8273: if ($env{'form.validationdc'}) {
8274: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 8275: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 8276: if (exists($domcoords{$newval})) {
8277: $confhash{'validation'}{'dc'} = $newval;
8278: }
8279: }
8280: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 8281: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8282: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8283: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8284: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8285: if ($confhash{'validation'}{'dc'} eq '') {
8286: $changes{'validation'}{'dc'} = &mt('None');
8287: } else {
8288: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8289: }
1.160.6.39 raeburn 8290: }
1.160.6.65 raeburn 8291: } elsif ($confhash{'validation'}{'dc'} ne '') {
8292: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 8293: }
8294: } elsif ($confhash{'validation'}{'dc'} ne '') {
8295: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8296: }
8297: } elsif ($confhash{'validation'}{'dc'} ne '') {
8298: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8299: }
1.160.6.65 raeburn 8300: } else {
8301: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8302: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8303: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8304: $changes{'validation'}{'dc'} = &mt('None');
8305: }
8306: }
1.160.6.39 raeburn 8307: }
8308: }
1.102 raeburn 8309: }
8310: } else {
1.86 raeburn 8311: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 8312: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8313: }
1.72 raeburn 8314: foreach my $item (@usertools) {
8315: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8316: my $unset;
1.101 raeburn 8317: if ($context eq 'requestcourses') {
1.104 raeburn 8318: $unset = '0';
8319: if ($type eq '_LC_adv') {
8320: $unset = '';
8321: }
1.101 raeburn 8322: if ($confhash{$item}{$type} eq 'autolimit') {
8323: $confhash{$item}{$type} .= '=';
8324: unless ($limithash{$item}{$type} =~ /\D/) {
8325: $confhash{$item}{$type} .= $limithash{$item}{$type};
8326: }
8327: }
1.160.6.5 raeburn 8328: } elsif ($context eq 'requestauthor') {
8329: $unset = '0';
8330: if ($type eq '_LC_adv') {
8331: $unset = '';
8332: }
1.72 raeburn 8333: } else {
1.101 raeburn 8334: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8335: $confhash{$item}{$type} = 1;
8336: } else {
8337: $confhash{$item}{$type} = 0;
8338: }
1.72 raeburn 8339: }
1.86 raeburn 8340: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 8341: if ($action eq 'requestauthor') {
8342: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8343: $changes{$type} = 1;
8344: }
8345: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8346: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8347: $changes{$item}{$type} = 1;
8348: }
8349: } else {
8350: if ($context eq 'requestcourses') {
1.104 raeburn 8351: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8352: $changes{$item}{$type} = 1;
8353: }
8354: } else {
8355: if (!$confhash{$item}{$type}) {
8356: $changes{$item}{$type} = 1;
8357: }
8358: }
8359: }
8360: } else {
8361: if ($context eq 'requestcourses') {
1.104 raeburn 8362: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8363: $changes{$item}{$type} = 1;
8364: }
1.160.6.5 raeburn 8365: } elsif ($context eq 'requestauthor') {
8366: if ($confhash{$type} ne $unset) {
8367: $changes{$type} = 1;
8368: }
1.72 raeburn 8369: } else {
8370: if (!$confhash{$item}{$type}) {
8371: $changes{$item}{$type} = 1;
8372: }
8373: }
8374: }
1.1 raeburn 8375: }
8376: }
1.160.6.5 raeburn 8377: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8378: if (ref($domconfig{'quotas'}) eq 'HASH') {
8379: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8380: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8381: if (exists($confhash{'defaultquota'}{$key})) {
8382: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8383: $changes{'defaultquota'}{$key} = 1;
8384: }
8385: } else {
8386: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8387: }
8388: }
1.86 raeburn 8389: } else {
8390: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8391: if (exists($confhash{'defaultquota'}{$key})) {
8392: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8393: $changes{'defaultquota'}{$key} = 1;
8394: }
8395: } else {
8396: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8397: }
1.1 raeburn 8398: }
8399: }
1.160.6.20 raeburn 8400: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8401: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8402: if (exists($confhash{'authorquota'}{$key})) {
8403: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8404: $changes{'authorquota'}{$key} = 1;
8405: }
8406: } else {
8407: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8408: }
8409: }
8410: }
1.1 raeburn 8411: }
1.86 raeburn 8412: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8413: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8414: if (ref($domconfig{'quotas'}) eq 'HASH') {
8415: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8416: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8417: $changes{'defaultquota'}{$key} = 1;
8418: }
8419: } else {
8420: if (!exists($domconfig{'quotas'}{$key})) {
8421: $changes{'defaultquota'}{$key} = 1;
8422: }
1.72 raeburn 8423: }
8424: } else {
1.86 raeburn 8425: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8426: }
1.1 raeburn 8427: }
8428: }
1.160.6.20 raeburn 8429: if (ref($confhash{'authorquota'}) eq 'HASH') {
8430: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8431: if (ref($domconfig{'quotas'}) eq 'HASH') {
8432: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8433: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8434: $changes{'authorquota'}{$key} = 1;
8435: }
8436: } else {
8437: $changes{'authorquota'}{$key} = 1;
8438: }
8439: } else {
8440: $changes{'authorquota'}{$key} = 1;
8441: }
8442: }
8443: }
1.1 raeburn 8444: }
1.72 raeburn 8445:
1.160.6.5 raeburn 8446: if ($context eq 'requestauthor') {
8447: $domdefaults{'requestauthor'} = \%confhash;
8448: } else {
8449: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 8450: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 8451: $domdefaults{$key} = $confhash{$key};
8452: }
1.160.6.5 raeburn 8453: }
1.72 raeburn 8454: }
1.160.6.5 raeburn 8455:
1.1 raeburn 8456: my %quotahash = (
1.86 raeburn 8457: $action => { %confhash }
1.1 raeburn 8458: );
8459: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8460: $dom);
8461: if ($putresult eq 'ok') {
8462: if (keys(%changes) > 0) {
1.72 raeburn 8463: my $cachetime = 24*60*60;
8464: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 8465: if (ref($lastactref) eq 'HASH') {
8466: $lastactref->{'domdefaults'} = 1;
8467: }
1.1 raeburn 8468: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 8469: unless (($context eq 'requestcourses') ||
8470: ($context eq 'requestauthor')) {
1.86 raeburn 8471: if (ref($changes{'defaultquota'}) eq 'HASH') {
8472: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8473: foreach my $type (@{$types},'default') {
8474: if (defined($changes{'defaultquota'}{$type})) {
8475: my $typetitle = $usertypes->{$type};
8476: if ($type eq 'default') {
8477: $typetitle = $othertitle;
8478: }
1.160.6.28 raeburn 8479: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8480: }
8481: }
1.86 raeburn 8482: $resulttext .= '</ul></li>';
1.72 raeburn 8483: }
1.160.6.20 raeburn 8484: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 8485: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 8486: foreach my $type (@{$types},'default') {
8487: if (defined($changes{'authorquota'}{$type})) {
8488: my $typetitle = $usertypes->{$type};
8489: if ($type eq 'default') {
8490: $typetitle = $othertitle;
8491: }
1.160.6.28 raeburn 8492: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 8493: }
8494: }
8495: $resulttext .= '</ul></li>';
8496: }
1.72 raeburn 8497: }
1.80 raeburn 8498: my %newenv;
1.72 raeburn 8499: foreach my $item (@usertools) {
1.160.6.5 raeburn 8500: my (%haschgs,%inconf);
8501: if ($context eq 'requestauthor') {
8502: %haschgs = %changes;
8503: %inconf = %confhash;
8504: } else {
8505: if (ref($changes{$item}) eq 'HASH') {
8506: %haschgs = %{$changes{$item}};
8507: }
8508: if (ref($confhash{$item}) eq 'HASH') {
8509: %inconf = %{$confhash{$item}};
8510: }
8511: }
8512: if (keys(%haschgs) > 0) {
1.80 raeburn 8513: my $newacc =
8514: &Apache::lonnet::usertools_access($env{'user.name'},
8515: $env{'user.domain'},
1.86 raeburn 8516: $item,'reload',$context);
1.160.6.5 raeburn 8517: if (($context eq 'requestcourses') ||
8518: ($context eq 'requestauthor')) {
1.108 raeburn 8519: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8520: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8521: }
8522: } else {
8523: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8524: $newenv{'environment.availabletools.'.$item} = $newacc;
8525: }
1.80 raeburn 8526: }
1.160.6.5 raeburn 8527: unless ($context eq 'requestauthor') {
8528: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8529: }
1.72 raeburn 8530: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 8531: if ($haschgs{$type}) {
1.72 raeburn 8532: my $typetitle = $usertypes->{$type};
8533: if ($type eq 'default') {
8534: $typetitle = $othertitle;
8535: } elsif ($type eq '_LC_adv') {
8536: $typetitle = 'LON-CAPA Advanced Users';
8537: }
1.160.6.5 raeburn 8538: if ($inconf{$type}) {
1.101 raeburn 8539: if ($context eq 'requestcourses') {
8540: my $cond;
1.160.6.5 raeburn 8541: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8542: if ($1 eq '') {
8543: $cond = &mt('(Automatic processing of any request).');
8544: } else {
8545: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8546: }
8547: } else {
1.160.6.5 raeburn 8548: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8549: }
8550: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 8551: } elsif ($context eq 'requestauthor') {
8552: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8553: $titles{$inconf{$type}},$typetitle);
8554:
1.101 raeburn 8555: } else {
8556: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8557: }
1.72 raeburn 8558: } else {
1.104 raeburn 8559: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 8560: if ($inconf{$type} eq '0') {
1.104 raeburn 8561: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8562: } else {
8563: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8564: }
8565: } else {
8566: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8567: }
1.72 raeburn 8568: }
8569: }
1.26 raeburn 8570: }
1.160.6.5 raeburn 8571: unless ($context eq 'requestauthor') {
8572: $resulttext .= '</ul></li>';
8573: }
1.26 raeburn 8574: }
1.1 raeburn 8575: }
1.160.6.5 raeburn 8576: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8577: if (ref($changes{'notify'}) eq 'HASH') {
8578: if ($changes{'notify'}{'approval'}) {
8579: if (ref($confhash{'notify'}) eq 'HASH') {
8580: if ($confhash{'notify'}{'approval'}) {
8581: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8582: } else {
1.160.6.5 raeburn 8583: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8584: }
8585: }
8586: }
8587: }
8588: }
1.160.6.30 raeburn 8589: if ($action eq 'requestcourses') {
8590: my @offon = ('off','on');
8591: if ($changes{'uniquecode'}) {
8592: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8593: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8594: $resulttext .= '<li>'.
8595: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8596: '</li>';
8597: } else {
8598: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8599: '</li>';
8600: }
8601: }
1.160.6.46 raeburn 8602: foreach my $type ('textbooks','templates') {
8603: if (ref($changes{$type}) eq 'HASH') {
8604: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8605: foreach my $key (sort(keys(%{$changes{$type}}))) {
8606: my %coursehash = &Apache::lonnet::coursedescription($key);
8607: my $coursetitle = $coursehash{'description'};
8608: my $position = $confhash{$type}{$key}{'order'} + 1;
8609: $resulttext .= '<li>';
1.160.6.47 raeburn 8610: foreach my $item ('subject','title','publisher','author') {
8611: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8612: ($type eq 'templates'));
1.160.6.46 raeburn 8613: my $name = $item.':';
8614: $name =~ s/^(\w)/\U$1/;
8615: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8616: }
8617: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8618: if ($type eq 'textbooks') {
8619: if ($confhash{$type}{$key}{'image'}) {
8620: $resulttext .= ' '.&mt('Image: [_1]',
8621: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8622: ' alt="Textbook cover" />').'<br />';
8623: }
8624: }
8625: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 8626: }
1.160.6.46 raeburn 8627: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 8628: }
8629: }
1.160.6.39 raeburn 8630: if (ref($changes{'validation'}) eq 'HASH') {
8631: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8632: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8633: foreach my $item (@{$validationitemsref}) {
8634: if (exists($changes{'validation'}{$item})) {
8635: if ($item eq 'markup') {
8636: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8637: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8638: } else {
8639: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8640: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8641: }
8642: }
8643: }
8644: if (exists($changes{'validation'}{'dc'})) {
8645: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8646: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8647: }
8648: }
8649: }
1.160.6.30 raeburn 8650: }
1.1 raeburn 8651: $resulttext .= '</ul>';
1.80 raeburn 8652: if (keys(%newenv)) {
8653: &Apache::lonnet::appenv(\%newenv);
8654: }
1.1 raeburn 8655: } else {
1.86 raeburn 8656: if ($context eq 'requestcourses') {
8657: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 8658: } elsif ($context eq 'requestauthor') {
8659: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8660: } else {
1.90 weissno 8661: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8662: }
1.1 raeburn 8663: }
8664: } else {
1.11 albertel 8665: $resulttext = '<span class="LC_error">'.
8666: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8667: }
1.160.6.30 raeburn 8668: if ($errors) {
8669: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8670: '<ul>'.$errors.'</ul></p>';
8671: }
1.3 raeburn 8672: return $resulttext;
1.1 raeburn 8673: }
8674:
1.160.6.30 raeburn 8675: sub process_textbook_image {
1.160.6.46 raeburn 8676: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 8677: my $filename = $env{'form.'.$caller.'.filename'};
8678: my ($error,$url);
8679: my ($width,$height) = (50,50);
8680: if ($configuserok eq 'ok') {
8681: if ($switchserver) {
8682: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8683: $switchserver);
8684: } elsif ($author_ok eq 'ok') {
8685: my ($result,$imageurl) =
8686: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 8687: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 8688: if ($result eq 'ok') {
8689: $url = $imageurl;
8690: } else {
8691: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8692: }
8693: } else {
8694: $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);
8695: }
8696: } else {
8697: $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);
8698: }
8699: return ($url,$error);
8700: }
8701:
1.3 raeburn 8702: sub modify_autoenroll {
1.160.6.24 raeburn 8703: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 8704: my ($resulttext,%changes);
8705: my %currautoenroll;
8706: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
8707: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
8708: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
8709: }
8710: }
8711: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
8712: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 8713: sender => 'Sender for notification messages',
1.160.6.68 raeburn 8714: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
8715: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 8716: my @offon = ('off','on');
1.17 raeburn 8717: my $sender_uname = $env{'form.sender_uname'};
8718: my $sender_domain = $env{'form.sender_domain'};
8719: if ($sender_domain eq '') {
8720: $sender_uname = '';
8721: } elsif ($sender_uname eq '') {
8722: $sender_domain = '';
8723: }
1.129 raeburn 8724: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 8725: my $failsafe = $env{'form.autoenroll_failsafe'};
8726: $failsafe =~ s{^\s+|\s+$}{}g;
8727: if ($failsafe =~ /\D/) {
8728: undef($failsafe);
8729: }
1.1 raeburn 8730: my %autoenrollhash = (
1.129 raeburn 8731: autoenroll => { 'run' => $env{'form.autoenroll_run'},
8732: 'sender_uname' => $sender_uname,
8733: 'sender_domain' => $sender_domain,
8734: 'co-owners' => $coowners,
1.160.6.68 raeburn 8735: 'autofailsafe' => $failsafe,
1.1 raeburn 8736: }
8737: );
1.4 raeburn 8738: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
8739: $dom);
1.1 raeburn 8740: if ($putresult eq 'ok') {
8741: if (exists($currautoenroll{'run'})) {
8742: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
8743: $changes{'run'} = 1;
8744: }
8745: } elsif ($autorun) {
8746: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 8747: $changes{'run'} = 1;
1.1 raeburn 8748: }
8749: }
1.17 raeburn 8750: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 8751: $changes{'sender'} = 1;
8752: }
1.17 raeburn 8753: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 8754: $changes{'sender'} = 1;
8755: }
1.129 raeburn 8756: if ($currautoenroll{'co-owners'} ne '') {
8757: if ($currautoenroll{'co-owners'} ne $coowners) {
8758: $changes{'coowners'} = 1;
8759: }
8760: } elsif ($coowners) {
8761: $changes{'coowners'} = 1;
1.160.6.68 raeburn 8762: }
8763: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
8764: $changes{'autofailsafe'} = 1;
8765: }
1.1 raeburn 8766: if (keys(%changes) > 0) {
8767: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 8768: if ($changes{'run'}) {
1.1 raeburn 8769: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
8770: }
8771: if ($changes{'sender'}) {
1.17 raeburn 8772: if ($sender_uname eq '' || $sender_domain eq '') {
8773: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
8774: } else {
8775: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
8776: }
1.1 raeburn 8777: }
1.129 raeburn 8778: if ($changes{'coowners'}) {
8779: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
8780: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8781: if (ref($lastactref) eq 'HASH') {
8782: $lastactref->{'domainconfig'} = 1;
8783: }
1.129 raeburn 8784: }
1.160.6.68 raeburn 8785: if ($changes{'autofailsafe'}) {
8786: if ($failsafe ne '') {
1.160.6.82 raeburn 8787: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 8788: } else {
1.160.6.82 raeburn 8789: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 8790: }
8791: &Apache::lonnet::get_domain_defaults($dom,1);
8792: if (ref($lastactref) eq 'HASH') {
8793: $lastactref->{'domdefaults'} = 1;
8794: }
8795: }
1.1 raeburn 8796: $resulttext .= '</ul>';
8797: } else {
8798: $resulttext = &mt('No changes made to auto-enrollment settings');
8799: }
8800: } else {
1.11 albertel 8801: $resulttext = '<span class="LC_error">'.
8802: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8803: }
1.3 raeburn 8804: return $resulttext;
1.1 raeburn 8805: }
8806:
8807: sub modify_autoupdate {
1.3 raeburn 8808: my ($dom,%domconfig) = @_;
1.1 raeburn 8809: my ($resulttext,%currautoupdate,%fields,%changes);
8810: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
8811: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
8812: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
8813: }
8814: }
8815: my @offon = ('off','on');
8816: my %title = &Apache::lonlocal::texthash (
8817: run => 'Auto-update:',
8818: classlists => 'Updates to user information in classlists?'
8819: );
1.44 raeburn 8820: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8821: my %fieldtitles = &Apache::lonlocal::texthash (
8822: id => 'Student/Employee ID',
1.20 raeburn 8823: permanentemail => 'E-mail address',
1.1 raeburn 8824: lastname => 'Last Name',
8825: firstname => 'First Name',
8826: middlename => 'Middle Name',
1.132 raeburn 8827: generation => 'Generation',
1.1 raeburn 8828: );
1.142 raeburn 8829: $othertitle = &mt('All users');
1.1 raeburn 8830: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8831: $othertitle = &mt('Other users');
1.1 raeburn 8832: }
8833: foreach my $key (keys(%env)) {
8834: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8835: my ($usertype,$item) = ($1,$2);
8836: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8837: if ($usertype eq 'default') {
8838: push(@{$fields{$1}},$2);
8839: } elsif (ref($types) eq 'ARRAY') {
8840: if (grep(/^\Q$usertype\E$/,@{$types})) {
8841: push(@{$fields{$1}},$2);
8842: }
8843: }
8844: }
1.1 raeburn 8845: }
8846: }
1.131 raeburn 8847: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8848: @lockablenames = sort(@lockablenames);
8849: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8850: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8851: if (@changed) {
8852: $changes{'lockablenames'} = 1;
8853: }
8854: } else {
8855: if (@lockablenames) {
8856: $changes{'lockablenames'} = 1;
8857: }
8858: }
1.1 raeburn 8859: my %updatehash = (
8860: autoupdate => { run => $env{'form.autoupdate_run'},
8861: classlists => $env{'form.classlists'},
8862: fields => {%fields},
1.131 raeburn 8863: lockablenames => \@lockablenames,
1.1 raeburn 8864: }
8865: );
8866: foreach my $key (keys(%currautoupdate)) {
8867: if (($key eq 'run') || ($key eq 'classlists')) {
8868: if (exists($updatehash{autoupdate}{$key})) {
8869: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8870: $changes{$key} = 1;
8871: }
8872: }
8873: } elsif ($key eq 'fields') {
8874: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8875: foreach my $item (@{$types},'default') {
1.1 raeburn 8876: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8877: my $change = 0;
8878: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8879: if (!exists($fields{$item})) {
8880: $change = 1;
1.132 raeburn 8881: last;
1.1 raeburn 8882: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8883: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8884: $change = 1;
1.132 raeburn 8885: last;
1.1 raeburn 8886: }
8887: }
8888: }
8889: if ($change) {
8890: push(@{$changes{$key}},$item);
8891: }
1.26 raeburn 8892: }
1.1 raeburn 8893: }
8894: }
1.131 raeburn 8895: } elsif ($key eq 'lockablenames') {
8896: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8897: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8898: if (@changed) {
8899: $changes{'lockablenames'} = 1;
8900: }
8901: } else {
8902: if (@lockablenames) {
8903: $changes{'lockablenames'} = 1;
8904: }
8905: }
8906: }
8907: }
8908: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8909: if (@lockablenames) {
8910: $changes{'lockablenames'} = 1;
1.1 raeburn 8911: }
8912: }
1.26 raeburn 8913: foreach my $item (@{$types},'default') {
8914: if (defined($fields{$item})) {
8915: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8916: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8917: my $change = 0;
8918: if (ref($fields{$item}) eq 'ARRAY') {
8919: foreach my $type (@{$fields{$item}}) {
8920: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
8921: $change = 1;
8922: last;
8923: }
8924: }
8925: }
8926: if ($change) {
8927: push(@{$changes{'fields'}},$item);
8928: }
8929: } else {
1.26 raeburn 8930: push(@{$changes{'fields'}},$item);
8931: }
8932: } else {
8933: push(@{$changes{'fields'}},$item);
1.1 raeburn 8934: }
8935: }
8936: }
8937: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8938: $dom);
8939: if ($putresult eq 'ok') {
8940: if (keys(%changes) > 0) {
8941: $resulttext = &mt('Changes made:').'<ul>';
8942: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 8943: if ($key eq 'lockablenames') {
8944: $resulttext .= '<li>';
8945: if (@lockablenames) {
8946: $usertypes->{'default'} = $othertitle;
8947: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8948: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8949: } else {
8950: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8951: }
8952: $resulttext .= '</li>';
8953: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8954: foreach my $item (@{$changes{$key}}) {
8955: my @newvalues;
8956: foreach my $type (@{$fields{$item}}) {
8957: push(@newvalues,$fieldtitles{$type});
8958: }
1.3 raeburn 8959: my $newvaluestr;
8960: if (@newvalues > 0) {
8961: $newvaluestr = join(', ',@newvalues);
8962: } else {
8963: $newvaluestr = &mt('none');
1.6 raeburn 8964: }
1.1 raeburn 8965: if ($item eq 'default') {
1.26 raeburn 8966: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8967: } else {
1.26 raeburn 8968: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8969: }
8970: }
8971: } else {
8972: my $newvalue;
8973: if ($key eq 'run') {
8974: $newvalue = $offon[$env{'form.autoupdate_run'}];
8975: } else {
8976: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8977: }
1.1 raeburn 8978: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8979: }
8980: }
8981: $resulttext .= '</ul>';
8982: } else {
1.3 raeburn 8983: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8984: }
8985: } else {
1.11 albertel 8986: $resulttext = '<span class="LC_error">'.
8987: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8988: }
1.3 raeburn 8989: return $resulttext;
1.1 raeburn 8990: }
8991:
1.125 raeburn 8992: sub modify_autocreate {
8993: my ($dom,%domconfig) = @_;
8994: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8995: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8996: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8997: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8998: }
8999: }
9000: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9001: req => 'Auto-creation of validated requests for official courses',
9002: xmldc => 'Identity of course creator of courses from XML files',
9003: );
9004: my @types = ('xml','req');
9005: foreach my $item (@types) {
9006: $newvals{$item} = $env{'form.autocreate_'.$item};
9007: $newvals{$item} =~ s/\D//g;
9008: $newvals{$item} = 0 if ($newvals{$item} eq '');
9009: }
9010: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 9011: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 9012: unless (exists($domcoords{$newvals{'xmldc'}})) {
9013: $newvals{'xmldc'} = '';
9014: }
9015: %autocreatehash = (
9016: autocreate => { xml => $newvals{'xml'},
9017: req => $newvals{'req'},
9018: }
9019: );
9020: if ($newvals{'xmldc'} ne '') {
9021: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9022: }
9023: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9024: $dom);
9025: if ($putresult eq 'ok') {
9026: my @items = @types;
9027: if ($newvals{'xml'}) {
9028: push(@items,'xmldc');
9029: }
9030: foreach my $item (@items) {
9031: if (exists($currautocreate{$item})) {
9032: if ($currautocreate{$item} ne $newvals{$item}) {
9033: $changes{$item} = 1;
9034: }
9035: } elsif ($newvals{$item}) {
9036: $changes{$item} = 1;
9037: }
9038: }
9039: if (keys(%changes) > 0) {
9040: my @offon = ('off','on');
9041: $resulttext = &mt('Changes made:').'<ul>';
9042: foreach my $item (@types) {
9043: if ($changes{$item}) {
9044: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 9045: $resulttext .= '<li>'.
9046: &mt("$title{$item} set to [_1]$newtxt [_2]",
9047: '<b>','</b>').
9048: '</li>';
1.125 raeburn 9049: }
9050: }
9051: if ($changes{'xmldc'}) {
9052: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9053: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 9054: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9055: }
9056: $resulttext .= '</ul>';
9057: } else {
9058: $resulttext = &mt('No changes made to auto-creation settings');
9059: }
9060: } else {
9061: $resulttext = '<span class="LC_error">'.
9062: &mt('An error occurred: [_1]',$putresult).'</span>';
9063: }
9064: return $resulttext;
9065: }
9066:
1.23 raeburn 9067: sub modify_directorysrch {
1.160.6.81 raeburn 9068: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 9069: my ($resulttext,%changes);
9070: my %currdirsrch;
9071: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9072: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9073: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9074: }
9075: }
1.160.6.72 raeburn 9076: my %title = ( available => 'Institutional directory search available',
9077: localonly => 'Other domains can search institution',
9078: lcavailable => 'LON-CAPA directory search available',
9079: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9080: searchby => 'Search types',
9081: searchtypes => 'Search latitude');
9082: my @offon = ('off','on');
1.24 raeburn 9083: my @otherdoms = ('Yes','No');
1.23 raeburn 9084:
1.25 raeburn 9085: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9086: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9087: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9088:
1.44 raeburn 9089: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9090: if (keys(%{$usertypes}) == 0) {
9091: @cansearch = ('default');
9092: } else {
9093: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9094: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9095: if (!grep(/^\Q$type\E$/,@cansearch)) {
9096: push(@{$changes{'cansearch'}},$type);
9097: }
1.23 raeburn 9098: }
1.26 raeburn 9099: foreach my $type (@cansearch) {
9100: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9101: push(@{$changes{'cansearch'}},$type);
9102: }
1.23 raeburn 9103: }
1.26 raeburn 9104: } else {
9105: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9106: }
9107: }
9108:
9109: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9110: foreach my $by (@{$currdirsrch{'searchby'}}) {
9111: if (!grep(/^\Q$by\E$/,@searchby)) {
9112: push(@{$changes{'searchby'}},$by);
9113: }
9114: }
9115: foreach my $by (@searchby) {
9116: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9117: push(@{$changes{'searchby'}},$by);
9118: }
9119: }
9120: } else {
9121: push(@{$changes{'searchby'}},@searchby);
9122: }
1.25 raeburn 9123:
9124: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9125: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9126: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9127: push(@{$changes{'searchtypes'}},$type);
9128: }
9129: }
9130: foreach my $type (@searchtypes) {
9131: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9132: push(@{$changes{'searchtypes'}},$type);
9133: }
9134: }
9135: } else {
9136: if (exists($currdirsrch{'searchtypes'})) {
9137: foreach my $type (@searchtypes) {
9138: if ($type ne $currdirsrch{'searchtypes'}) {
9139: push(@{$changes{'searchtypes'}},$type);
9140: }
9141: }
9142: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9143: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9144: }
9145: } else {
9146: push(@{$changes{'searchtypes'}},@searchtypes);
9147: }
9148: }
9149:
1.23 raeburn 9150: my %dirsrch_hash = (
9151: directorysrch => { available => $env{'form.dirsrch_available'},
9152: cansearch => \@cansearch,
1.160.6.72 raeburn 9153: localonly => $env{'form.dirsrch_instlocalonly'},
9154: lclocalonly => $env{'form.dirsrch_domlocalonly'},
9155: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9156: searchby => \@searchby,
1.25 raeburn 9157: searchtypes => \@searchtypes,
1.23 raeburn 9158: }
9159: );
9160: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9161: $dom);
9162: if ($putresult eq 'ok') {
9163: if (exists($currdirsrch{'available'})) {
9164: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9165: $changes{'available'} = 1;
9166: }
9167: } else {
9168: if ($env{'form.dirsrch_available'} eq '1') {
9169: $changes{'available'} = 1;
9170: }
9171: }
1.160.6.72 raeburn 9172: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 9173: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
9174: $changes{'lcavailable'} = 1;
9175: }
1.24 raeburn 9176: } else {
1.160.6.72 raeburn 9177: if ($env{'form.dirsrch_lcavailable'} eq '1') {
9178: $changes{'lcavailable'} = 1;
9179: }
9180: }
9181: if (exists($currdirsrch{'localonly'})) {
9182: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9183: $changes{'localonly'} = 1;
9184: }
1.160.6.72 raeburn 9185: } else {
9186: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
9187: $changes{'localonly'} = 1;
9188: }
9189: }
9190: if (exists($currdirsrch{'lclocalonly'})) {
9191: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
9192: $changes{'lclocalonly'} = 1;
9193: }
9194: } else {
9195: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
9196: $changes{'lclocalonly'} = 1;
9197: }
1.24 raeburn 9198: }
1.23 raeburn 9199: if (keys(%changes) > 0) {
9200: $resulttext = &mt('Changes made:').'<ul>';
9201: if ($changes{'available'}) {
9202: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9203: }
1.160.6.72 raeburn 9204: if ($changes{'lcavailable'}) {
9205: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
9206: }
1.24 raeburn 9207: if ($changes{'localonly'}) {
1.160.6.72 raeburn 9208: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
9209: }
9210: if ($changes{'lclocalonly'}) {
9211: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 9212: }
1.23 raeburn 9213: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9214: my $chgtext;
1.26 raeburn 9215: if (ref($usertypes) eq 'HASH') {
9216: if (keys(%{$usertypes}) > 0) {
9217: foreach my $type (@{$types}) {
9218: if (grep(/^\Q$type\E$/,@cansearch)) {
9219: $chgtext .= $usertypes->{$type}.'; ';
9220: }
9221: }
9222: if (grep(/^default$/,@cansearch)) {
9223: $chgtext .= $othertitle;
9224: } else {
9225: $chgtext =~ s/\; $//;
9226: }
1.160.6.13 raeburn 9227: $resulttext .=
9228: '<li>'.
9229: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9230: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9231: '</li>';
1.23 raeburn 9232: }
9233: }
9234: }
9235: if (ref($changes{'searchby'}) eq 'ARRAY') {
9236: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9237: my $chgtext;
9238: foreach my $type (@{$titleorder}) {
9239: if (grep(/^\Q$type\E$/,@searchby)) {
9240: if (defined($searchtitles->{$type})) {
9241: $chgtext .= $searchtitles->{$type}.'; ';
9242: }
9243: }
9244: }
9245: $chgtext =~ s/\; $//;
9246: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9247: }
1.25 raeburn 9248: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9249: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9250: my $chgtext;
9251: foreach my $type (@{$srchtypeorder}) {
9252: if (grep(/^\Q$type\E$/,@searchtypes)) {
9253: if (defined($srchtypes_desc->{$type})) {
9254: $chgtext .= $srchtypes_desc->{$type}.'; ';
9255: }
9256: }
9257: }
9258: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 9259: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9260: }
9261: $resulttext .= '</ul>';
1.160.6.81 raeburn 9262: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
9263: if (ref($lastactref) eq 'HASH') {
9264: $lastactref->{'directorysrch'} = 1;
9265: }
1.23 raeburn 9266: } else {
1.160.6.72 raeburn 9267: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9268: }
9269: } else {
9270: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9271: &mt('An error occurred: [_1]',$putresult).'</span>';
9272: }
9273: return $resulttext;
9274: }
9275:
1.28 raeburn 9276: sub modify_contacts {
1.160.6.24 raeburn 9277: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9278: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9279: if (ref($domconfig{'contacts'}) eq 'HASH') {
9280: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9281: $currsetting{$key} = $domconfig{'contacts'}{$key};
9282: }
9283: }
1.160.6.78 raeburn 9284: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 9285: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 9286: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
9287: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.160.6.23 raeburn 9288: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 9289: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 9290: foreach my $type (@mailings) {
9291: @{$newsetting{$type}} =
9292: &Apache::loncommon::get_env_multiple('form.'.$type);
9293: foreach my $item (@contacts) {
9294: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9295: $contacts_hash{contacts}{$type}{$item} = 1;
9296: } else {
9297: $contacts_hash{contacts}{$type}{$item} = 0;
9298: }
1.160.6.78 raeburn 9299: }
1.28 raeburn 9300: $others{$type} = $env{'form.'.$type.'_others'};
9301: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 9302: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9303: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9304: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 9305: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
9306: $includestr{$type} = $env{'form.'.$type.'_includestr'};
9307: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
9308: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
9309: }
1.134 raeburn 9310: }
1.28 raeburn 9311: }
9312: foreach my $item (@contacts) {
9313: $to{$item} = $env{'form.'.$item};
9314: $contacts_hash{'contacts'}{$item} = $to{$item};
9315: }
1.160.6.23 raeburn 9316: foreach my $item (@toggles) {
9317: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9318: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9319: }
9320: }
1.160.6.78 raeburn 9321: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
9322: foreach my $field (@{$fields}) {
9323: if (ref($possoptions->{$field}) eq 'ARRAY') {
9324: my $value = $env{'form.helpform_'.$field};
9325: $value =~ s/^\s+|\s+$//g;
9326: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
9327: $contacts_hash{contacts}{'helpform'}{$field} = $value;
9328: if ($field eq 'screenshot') {
9329: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
9330: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
9331: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
9332: }
9333: }
9334: }
9335: }
9336: }
9337: }
1.28 raeburn 9338: if (keys(%currsetting) > 0) {
9339: foreach my $item (@contacts) {
9340: if ($to{$item} ne $currsetting{$item}) {
9341: $changes{$item} = 1;
9342: }
9343: }
9344: foreach my $type (@mailings) {
9345: foreach my $item (@contacts) {
9346: if (ref($currsetting{$type}) eq 'HASH') {
9347: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9348: push(@{$changes{$type}},$item);
9349: }
9350: } else {
9351: push(@{$changes{$type}},@{$newsetting{$type}});
9352: }
9353: }
9354: if ($others{$type} ne $currsetting{$type}{'others'}) {
9355: push(@{$changes{$type}},'others');
9356: }
1.160.6.78 raeburn 9357: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9358: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9359: push(@{$changes{$type}},'bcc');
9360: }
1.160.6.78 raeburn 9361: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
9362: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
9363: push(@{$changes{$type}},'include');
9364: }
9365: }
9366: }
9367: if (ref($fields) eq 'ARRAY') {
9368: if (ref($currsetting{'helpform'}) eq 'HASH') {
9369: foreach my $field (@{$fields}) {
9370: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
9371: push(@{$changes{'helpform'}},$field);
9372: }
9373: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9374: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
9375: push(@{$changes{'helpform'}},'maxsize');
9376: }
9377: }
9378: }
9379: } else {
9380: foreach my $field (@{$fields}) {
9381: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9382: push(@{$changes{'helpform'}},$field);
9383: }
9384: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9385: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9386: push(@{$changes{'helpform'}},'maxsize');
9387: }
9388: }
9389: }
1.134 raeburn 9390: }
1.28 raeburn 9391: }
9392: } else {
9393: my %default;
9394: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9395: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9396: $default{'errormail'} = 'adminemail';
9397: $default{'packagesmail'} = 'adminemail';
9398: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 9399: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 9400: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9401: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 9402: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9403: foreach my $item (@contacts) {
9404: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 9405: $changes{$item} = 1;
1.160.6.23 raeburn 9406: }
1.28 raeburn 9407: }
9408: foreach my $type (@mailings) {
9409: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9410: push(@{$changes{$type}},@{$newsetting{$type}});
9411: }
9412: if ($others{$type} ne '') {
9413: push(@{$changes{$type}},'others');
1.134 raeburn 9414: }
1.160.6.78 raeburn 9415: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9416: if ($bcc{$type} ne '') {
9417: push(@{$changes{$type}},'bcc');
9418: }
1.160.6.78 raeburn 9419: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
9420: push(@{$changes{$type}},'include');
9421: }
9422: }
9423: }
9424: if (ref($fields) eq 'ARRAY') {
9425: foreach my $field (@{$fields}) {
9426: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9427: push(@{$changes{'helpform'}},$field);
9428: }
9429: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9430: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9431: push(@{$changes{'helpform'}},'maxsize');
9432: }
9433: }
1.134 raeburn 9434: }
1.28 raeburn 9435: }
9436: }
1.160.6.23 raeburn 9437: foreach my $item (@toggles) {
9438: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9439: $changes{$item} = 1;
9440: } elsif ((!$env{'form.'.$item}) &&
9441: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9442: $changes{$item} = 1;
9443: }
9444: }
1.28 raeburn 9445: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9446: $dom);
9447: if ($putresult eq 'ok') {
9448: if (keys(%changes) > 0) {
1.160.6.24 raeburn 9449: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9450: if (ref($lastactref) eq 'HASH') {
9451: $lastactref->{'domainconfig'} = 1;
9452: }
1.28 raeburn 9453: my ($titles,$short_titles) = &contact_titles();
9454: $resulttext = &mt('Changes made:').'<ul>';
9455: foreach my $item (@contacts) {
9456: if ($changes{$item}) {
9457: $resulttext .= '<li>'.$titles->{$item}.
9458: &mt(' set to: ').
9459: '<span class="LC_cusr_emph">'.
9460: $to{$item}.'</span></li>';
9461: }
9462: }
9463: foreach my $type (@mailings) {
9464: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 9465: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
9466: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
9467: } else {
9468: $resulttext .= '<li>'.$titles->{$type}.': ';
9469: }
1.28 raeburn 9470: my @text;
9471: foreach my $item (@{$newsetting{$type}}) {
9472: push(@text,$short_titles->{$item});
9473: }
9474: if ($others{$type} ne '') {
9475: push(@text,$others{$type});
9476: }
1.160.6.78 raeburn 9477: if (@text) {
9478: $resulttext .= '<span class="LC_cusr_emph">'.
9479: join(', ',@text).'</span>';
9480: }
9481: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9482: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 9483: my $bcctext;
9484: if (@text) {
9485: $bcctext = ' '.&mt('with Bcc to');
9486: } else {
9487: $bcctext = '(Bcc)';
9488: }
9489: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9490: } elsif (!@text) {
9491: $resulttext .= &mt('No one');
1.134 raeburn 9492: }
1.160.6.78 raeburn 9493: if ($includestr{$type} ne '') {
9494: if ($includeloc{$type} eq 'b') {
9495: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
9496: } elsif ($includeloc{$type} eq 's') {
9497: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
9498: }
9499: }
9500: } elsif (!@text) {
9501: $resulttext .= &mt('No recipients');
1.134 raeburn 9502: }
9503: $resulttext .= '</li>';
1.28 raeburn 9504: }
9505: }
1.160.6.23 raeburn 9506: my @offon = ('off','on');
9507: if ($changes{'reporterrors'}) {
9508: $resulttext .= '<li>'.
9509: &mt('E-mail error reports to [_1] set to "'.
9510: $offon[$env{'form.reporterrors'}].'".',
9511: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9512: &mt('LON-CAPA core group - MSU'),600,500)).
9513: '</li>';
9514: }
9515: if ($changes{'reportupdates'}) {
9516: $resulttext .= '<li>'.
9517: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9518: $offon[$env{'form.reportupdates'}].'".',
9519: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9520: &mt('LON-CAPA core group - MSU'),600,500)).
9521: '</li>';
9522: }
1.160.6.78 raeburn 9523: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
9524: my (@optional,@required,@unused,$maxsizechg);
9525: foreach my $field (@{$changes{'helpform'}}) {
9526: if ($field eq 'maxsize') {
9527: $maxsizechg = 1;
9528: next;
9529: }
9530: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
9531: push(@optional,$field);
9532: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
9533: push(@unused,$field);
9534: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
9535: push(@required,$field);
9536: }
9537: }
9538: if (@optional) {
9539: $resulttext .= '<li>'.
9540: &mt('Help form fields changed to "Optional": [_1].',
9541: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
9542: '</li>';
9543: }
9544: if (@required) {
9545: $resulttext .= '<li>'.
9546: &mt('Help form fields changed to "Required": [_1].',
9547: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
9548: '</li>';
9549: }
9550: if (@unused) {
9551: $resulttext .= '<li>'.
9552: &mt('Help form fields changed to "Not shown": [_1].',
9553: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
9554: '</li>';
9555: }
9556: if ($maxsizechg) {
9557: $resulttext .= '<li>'.
9558: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
9559: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
9560: '</li>';
9561:
9562: }
9563: }
1.28 raeburn 9564: $resulttext .= '</ul>';
9565: } else {
1.160.6.78 raeburn 9566: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 9567: }
9568: } else {
9569: $resulttext = '<span class="LC_error">'.
9570: &mt('An error occurred: [_1].',$putresult).'</span>';
9571: }
9572: return $resulttext;
9573: }
9574:
9575: sub modify_usercreation {
1.27 raeburn 9576: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9577: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9578: my $warningmsg;
1.27 raeburn 9579: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9580: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 9581: if ($key eq 'cancreate') {
9582: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9583: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9584: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 9585: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9586: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 9587: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9588: } else {
9589: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9590: }
1.50 raeburn 9591: }
1.43 raeburn 9592: }
1.160.6.34 raeburn 9593: } elsif ($key eq 'email_rule') {
9594: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9595: } else {
9596: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 9597: }
9598: }
1.34 raeburn 9599: }
1.160.6.34 raeburn 9600: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
9601: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
9602: my @contexts = ('author','course','requestcrs');
9603: foreach my $item(@contexts) {
9604: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9605: }
1.34 raeburn 9606: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9607: foreach my $item (@contexts) {
1.160.6.34 raeburn 9608: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9609: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9610: }
1.27 raeburn 9611: }
1.34 raeburn 9612: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9613: foreach my $item (@contexts) {
1.43 raeburn 9614: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9615: if ($cancreate{$item} ne 'any') {
9616: push(@{$changes{'cancreate'}},$item);
9617: }
9618: } else {
9619: if ($cancreate{$item} ne 'none') {
9620: push(@{$changes{'cancreate'}},$item);
9621: }
1.27 raeburn 9622: }
9623: }
9624: } else {
1.43 raeburn 9625: foreach my $item (@contexts) {
1.34 raeburn 9626: push(@{$changes{'cancreate'}},$item);
9627: }
1.27 raeburn 9628: }
1.34 raeburn 9629:
1.27 raeburn 9630: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9631: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9632: if (!grep(/^\Q$type\E$/,@username_rule)) {
9633: push(@{$changes{'username_rule'}},$type);
9634: }
9635: }
9636: foreach my $type (@username_rule) {
9637: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9638: push(@{$changes{'username_rule'}},$type);
9639: }
9640: }
9641: } else {
9642: push(@{$changes{'username_rule'}},@username_rule);
9643: }
9644:
1.32 raeburn 9645: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9646: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9647: if (!grep(/^\Q$type\E$/,@id_rule)) {
9648: push(@{$changes{'id_rule'}},$type);
9649: }
9650: }
9651: foreach my $type (@id_rule) {
9652: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9653: push(@{$changes{'id_rule'}},$type);
9654: }
9655: }
9656: } else {
9657: push(@{$changes{'id_rule'}},@id_rule);
9658: }
9659:
1.43 raeburn 9660: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9661: my @authtypes = ('int','krb4','krb5','loc');
9662: my %authhash;
1.43 raeburn 9663: foreach my $item (@authen_contexts) {
1.28 raeburn 9664: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9665: foreach my $auth (@authtypes) {
9666: if (grep(/^\Q$auth\E$/,@authallowed)) {
9667: $authhash{$item}{$auth} = 1;
9668: } else {
9669: $authhash{$item}{$auth} = 0;
9670: }
9671: }
9672: }
9673: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9674: foreach my $item (@authen_contexts) {
1.28 raeburn 9675: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
9676: foreach my $auth (@authtypes) {
9677: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
9678: push(@{$changes{'authtypes'}},$item);
9679: last;
9680: }
9681: }
9682: }
9683: }
9684: } else {
1.43 raeburn 9685: foreach my $item (@authen_contexts) {
1.28 raeburn 9686: push(@{$changes{'authtypes'}},$item);
9687: }
9688: }
9689:
1.160.6.34 raeburn 9690: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
9691: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
9692: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
9693: $save_usercreate{'id_rule'} = \@id_rule;
9694: $save_usercreate{'username_rule'} = \@username_rule,
9695: $save_usercreate{'authtypes'} = \%authhash;
9696:
1.27 raeburn 9697: my %usercreation_hash = (
1.160.6.34 raeburn 9698: usercreation => \%save_usercreate,
9699: );
1.27 raeburn 9700:
9701: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
9702: $dom);
1.50 raeburn 9703:
1.160.6.34 raeburn 9704: if ($putresult eq 'ok') {
9705: if (keys(%changes) > 0) {
9706: $resulttext = &mt('Changes made:').'<ul>';
9707: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9708: my %lt = &usercreation_types();
9709: foreach my $type (@{$changes{'cancreate'}}) {
9710: my $chgtext = $lt{$type}.', ';
9711: if ($cancreate{$type} eq 'none') {
9712: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
9713: } elsif ($cancreate{$type} eq 'any') {
9714: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
9715: } elsif ($cancreate{$type} eq 'official') {
9716: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
9717: } elsif ($cancreate{$type} eq 'unofficial') {
9718: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
9719: }
9720: $resulttext .= '<li>'.$chgtext.'</li>';
9721: }
9722: }
9723: if (ref($changes{'username_rule'}) eq 'ARRAY') {
9724: my ($rules,$ruleorder) =
9725: &Apache::lonnet::inst_userrules($dom,'username');
9726: my $chgtext = '<ul>';
9727: foreach my $type (@username_rule) {
9728: if (ref($rules->{$type}) eq 'HASH') {
9729: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
9730: }
9731: }
9732: $chgtext .= '</ul>';
9733: if (@username_rule > 0) {
9734: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9735: } else {
9736: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
9737: }
9738: }
9739: if (ref($changes{'id_rule'}) eq 'ARRAY') {
9740: my ($idrules,$idruleorder) =
9741: &Apache::lonnet::inst_userrules($dom,'id');
9742: my $chgtext = '<ul>';
9743: foreach my $type (@id_rule) {
9744: if (ref($idrules->{$type}) eq 'HASH') {
9745: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
9746: }
9747: }
9748: $chgtext .= '</ul>';
9749: if (@id_rule > 0) {
9750: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9751: } else {
9752: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
9753: }
9754: }
9755: my %authname = &authtype_names();
9756: my %context_title = &context_names();
9757: if (ref($changes{'authtypes'}) eq 'ARRAY') {
9758: my $chgtext = '<ul>';
9759: foreach my $type (@{$changes{'authtypes'}}) {
9760: my @allowed;
9761: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
9762: foreach my $auth (@authtypes) {
9763: if ($authhash{$type}{$auth}) {
9764: push(@allowed,$authname{$auth});
9765: }
9766: }
9767: if (@allowed > 0) {
9768: $chgtext .= join(', ',@allowed).'</li>';
9769: } else {
9770: $chgtext .= &mt('none').'</li>';
9771: }
9772: }
9773: $chgtext .= '</ul>';
9774: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
9775: $resulttext .= '</li>';
9776: }
9777: $resulttext .= '</ul>';
9778: } else {
9779: $resulttext = &mt('No changes made to user creation settings');
9780: }
9781: } else {
9782: $resulttext = '<span class="LC_error">'.
9783: &mt('An error occurred: [_1]',$putresult).'</span>';
9784: }
9785: if ($warningmsg ne '') {
9786: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9787: }
9788: return $resulttext;
9789: }
9790:
9791: sub modify_selfcreation {
9792: my ($dom,%domconfig) = @_;
9793: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
9794: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 9795: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9796: if (ref($types) eq 'ARRAY') {
9797: $usertypes->{'default'} = $othertitle;
9798: push(@{$types},'default');
9799: }
1.160.6.34 raeburn 9800: #
9801: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
9802: #
9803: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9804: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9805: if ($key eq 'cancreate') {
9806: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9807: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9808: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9809: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 9810: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 9811: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 9812: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 9813: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9814: } else {
9815: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9816: }
9817: }
9818: }
9819: } elsif ($key eq 'email_rule') {
9820: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9821: } else {
9822: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9823: }
9824: }
9825: }
9826: #
9827: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
9828: #
9829: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9830: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9831: if ($key eq 'selfcreate') {
9832: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
9833: } else {
9834: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
9835: }
9836: }
9837: }
9838:
9839: my @contexts = ('selfcreate');
9840: @{$cancreate{'selfcreate'}} = ();
9841: %{$cancreate{'emailusername'}} = ();
9842: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 9843: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 9844: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 9845: my %selfcreatetypes = (
9846: sso => 'users authenticated by institutional single sign on',
9847: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 9848: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 9849: );
1.160.6.34 raeburn 9850: #
9851: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
9852: # is permitted.
9853: #
1.160.6.40 raeburn 9854:
9855: my @statuses;
9856: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9857: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
9858: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
9859: }
9860: }
9861: push(@statuses,'default');
9862:
1.160.6.35 raeburn 9863: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 9864: if ($item eq 'email') {
1.160.6.40 raeburn 9865: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 9866: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 9867: push(@contexts,'selfcreateprocessing');
9868: foreach my $type (@statuses) {
9869: if ($type eq 'default') {
9870: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
9871: } else {
9872: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
9873: }
9874: }
1.160.6.34 raeburn 9875: }
9876: } else {
9877: if ($env{'form.cancreate_'.$item}) {
9878: push(@{$cancreate{'selfcreate'}},$item);
9879: }
9880: }
9881: }
9882: my (@email_rule,%userinfo,%savecaptcha);
9883: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9884: #
1.160.6.35 raeburn 9885: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9886: # 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 9887: #
1.160.6.40 raeburn 9888:
1.160.6.48 raeburn 9889: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 9890: push(@contexts,'emailusername');
1.160.6.35 raeburn 9891: if (ref($types) eq 'ARRAY') {
9892: foreach my $type (@{$types}) {
9893: if (ref($infofields) eq 'ARRAY') {
9894: foreach my $field (@{$infofields}) {
9895: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9896: $cancreate{'emailusername'}{$type}{$field} = $1;
9897: }
9898: }
1.160.6.34 raeburn 9899: }
9900: }
9901: }
9902: #
9903: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9904: # queued requests for self-creation of account using e-mail address as username
9905: #
9906:
9907: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9908: @approvalnotify = sort(@approvalnotify);
9909: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9910: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9911: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9912: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9913: push(@{$changes{'cancreate'}},'notify');
9914: }
9915: } else {
9916: if ($cancreate{'notify'}{'approval'}) {
9917: push(@{$changes{'cancreate'}},'notify');
9918: }
9919: }
9920: } elsif ($cancreate{'notify'}{'approval'}) {
9921: push(@{$changes{'cancreate'}},'notify');
9922: }
9923:
9924: #
9925: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9926: #
9927: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9928: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9929: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9930: if (@{$curr_usercreation{'email_rule'}} > 0) {
9931: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9932: if (!grep(/^\Q$type\E$/,@email_rule)) {
9933: push(@{$changes{'email_rule'}},$type);
9934: }
9935: }
9936: }
9937: if (@email_rule > 0) {
9938: foreach my $type (@email_rule) {
9939: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9940: push(@{$changes{'email_rule'}},$type);
9941: }
9942: }
9943: }
9944: } elsif (@email_rule > 0) {
9945: push(@{$changes{'email_rule'}},@email_rule);
9946: }
9947: }
9948: #
1.160.6.40 raeburn 9949: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 9950: # institutional log-in.
9951: #
9952: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9953: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9954: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
9955: ($domdefaults{'auth_def'} eq 'localauth'))) {
9956: $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.').' '.
9957: &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.');
9958: }
9959: }
9960: my @fields = ('lastname','firstname','middlename','generation',
9961: 'permanentemail','id');
1.160.6.44 raeburn 9962: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 9963: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9964: #
9965: # Where usernames may created for institutional log-in and/or institutional single sign on:
9966: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9967: # may self-create accounts
9968: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
9969: # which the user may supply, if institutional data is unavailable.
9970: #
9971: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
9972: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 9973: if (@{$types} > 1) {
1.160.6.34 raeburn 9974: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
9975: push(@contexts,'statustocreate');
9976: } else {
9977: undef($cancreate{'statustocreate'});
9978: }
9979: foreach my $type (@{$types}) {
9980: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
9981: foreach my $field (@fields) {
9982: if (grep(/^\Q$field\E$/,@modifiable)) {
9983: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9984: } else {
9985: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9986: }
9987: }
9988: }
9989: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9990: foreach my $type (@{$types}) {
9991: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9992: foreach my $field (@fields) {
9993: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9994: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9995: push(@{$changes{'selfcreate'}},$type);
9996: last;
9997: }
9998: }
9999: }
10000: }
10001: } else {
10002: foreach my $type (@{$types}) {
10003: push(@{$changes{'selfcreate'}},$type);
10004: }
10005: }
10006: }
1.160.6.44 raeburn 10007: foreach my $field (@shibfields) {
10008: if ($env{'form.shibenv_'.$field} ne '') {
10009: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10010: }
10011: }
10012: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10013: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10014: foreach my $field (@shibfields) {
10015: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10016: push(@{$changes{'cancreate'}},'shibenv');
10017: }
10018: }
10019: } else {
10020: foreach my $field (@shibfields) {
10021: if ($env{'form.shibenv_'.$field}) {
10022: push(@{$changes{'cancreate'}},'shibenv');
10023: last;
10024: }
10025: }
10026: }
10027: }
1.160.6.34 raeburn 10028: }
10029: foreach my $item (@contexts) {
10030: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10031: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10032: if (ref($cancreate{$item}) eq 'ARRAY') {
10033: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10034: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10035: push(@{$changes{'cancreate'}},$item);
10036: }
10037: }
10038: }
10039: }
10040: if (ref($cancreate{$item}) eq 'ARRAY') {
10041: foreach my $type (@{$cancreate{$item}}) {
10042: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10043: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10044: push(@{$changes{'cancreate'}},$item);
10045: }
10046: }
10047: }
10048: }
10049: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10050: if (ref($cancreate{$item}) eq 'HASH') {
10051: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 10052: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10053: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10054: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10055: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10056: push(@{$changes{'cancreate'}},$item);
10057: }
10058: }
10059: }
1.160.6.40 raeburn 10060: } elsif ($item eq 'selfcreateprocessing') {
10061: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10062: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10063: push(@{$changes{'cancreate'}},$item);
10064: }
10065: }
1.160.6.35 raeburn 10066: } else {
10067: if (!$cancreate{$item}{$curr}) {
10068: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10069: push(@{$changes{'cancreate'}},$item);
10070: }
1.160.6.34 raeburn 10071: }
10072: }
10073: }
10074: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 10075: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10076: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10077: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10078: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10079: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10080: push(@{$changes{'cancreate'}},$item);
10081: }
10082: }
10083: } else {
10084: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10085: push(@{$changes{'cancreate'}},$item);
10086: }
10087: }
10088: }
1.160.6.40 raeburn 10089: } elsif ($item eq 'selfcreateprocessing') {
10090: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10091: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10092: push(@{$changes{'cancreate'}},$item);
10093: }
10094: }
1.160.6.35 raeburn 10095: } else {
10096: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10097: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10098: push(@{$changes{'cancreate'}},$item);
10099: }
1.160.6.34 raeburn 10100: }
10101: }
10102: }
10103: }
10104: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10105: if (ref($cancreate{$item}) eq 'ARRAY') {
10106: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10107: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10108: push(@{$changes{'cancreate'}},$item);
10109: }
10110: }
10111: } elsif (ref($cancreate{$item}) eq 'HASH') {
10112: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10113: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10114: push(@{$changes{'cancreate'}},$item);
10115: }
10116: }
10117: }
10118: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 10119: if (ref($cancreate{$item}) eq 'HASH') {
10120: foreach my $type (keys(%{$cancreate{$item}})) {
10121: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10122: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10123: if ($cancreate{$item}{$type}{$field}) {
10124: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10125: push(@{$changes{'cancreate'}},$item);
10126: }
10127: last;
10128: }
10129: }
10130: }
10131: }
1.160.6.34 raeburn 10132: }
10133: }
10134: }
10135: #
10136: # Populate %save_usercreate hash with updates to self-creation configuration.
10137: #
10138: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10139: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 10140: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 10141: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10142: if (ref($cancreate{'notify'}) eq 'HASH') {
10143: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10144: }
1.160.6.40 raeburn 10145: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10146: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10147: }
1.160.6.34 raeburn 10148: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10149: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10150: }
1.160.6.44 raeburn 10151: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10152: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10153: }
1.160.6.34 raeburn 10154: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.85 raeburn 10155: $save_usercreate{'email_rule'} = \@email_rule;
1.160.6.34 raeburn 10156:
10157: my %userconfig_hash = (
10158: usercreation => \%save_usercreate,
10159: usermodification => \%save_usermodify,
10160: );
10161: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10162: $dom);
10163: #
10164: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10165: #
1.27 raeburn 10166: if ($putresult eq 'ok') {
10167: if (keys(%changes) > 0) {
10168: $resulttext = &mt('Changes made:').'<ul>';
10169: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 10170: my %lt = &selfcreation_types();
1.34 raeburn 10171: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10172: my $chgtext;
1.45 raeburn 10173: if ($type eq 'selfcreate') {
1.50 raeburn 10174: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 10175: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10176: } else {
1.160.6.34 raeburn 10177: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10178: '<ul>';
1.50 raeburn 10179: foreach my $case (@{$cancreate{$type}}) {
10180: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10181: }
10182: $chgtext .= '</ul>';
1.100 raeburn 10183: if (ref($cancreate{$type}) eq 'ARRAY') {
10184: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10185: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10186: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 10187: $chgtext .= '<br />'.
10188: '<span class="LC_warning">'.
10189: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10190: '</span>';
1.100 raeburn 10191: }
10192: }
10193: }
10194: }
1.43 raeburn 10195: }
1.160.6.44 raeburn 10196: } elsif ($type eq 'shibenv') {
10197: if (keys(%{$cancreate{$type}}) == 0) {
10198: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10199: } else {
10200: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10201: '<ul>';
10202: foreach my $field (@shibfields) {
10203: next if ($cancreate{$type}{$field} eq '');
10204: if ($field eq 'inststatus') {
10205: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10206: } else {
10207: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10208: }
10209: }
10210: $chgtext .= '</ul>';
10211: }
1.93 raeburn 10212: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10213: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10214: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10215: if (@{$cancreate{'selfcreate'}} > 0) {
10216: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10217: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10218: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10219: $chgtext .= '<br />'.
10220: '<span class="LC_warning">'.
10221: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10222: '</span>';
10223: }
1.96 raeburn 10224: } elsif (ref($usertypes) eq 'HASH') {
10225: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10226: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10227: } else {
10228: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10229: }
10230: $chgtext .= '<ul>';
10231: foreach my $case (@{$cancreate{$type}}) {
10232: if ($case eq 'default') {
10233: $chgtext .= '<li>'.$othertitle.'</li>';
10234: } else {
10235: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10236: }
10237: }
1.100 raeburn 10238: $chgtext .= '</ul>';
10239: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10240: $chgtext .= '<br /><span class="LC_warning">'.
10241: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10242: '</span>';
1.100 raeburn 10243: }
10244: }
10245: } else {
10246: if (@{$cancreate{$type}} == 0) {
10247: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10248: } else {
10249: $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 10250: }
10251: }
10252: }
1.160.6.40 raeburn 10253: } elsif ($type eq 'selfcreateprocessing') {
10254: my %choices = &Apache::lonlocal::texthash (
10255: automatic => 'Automatic approval',
10256: approval => 'Queued for approval',
10257: );
10258: if (@statuses > 1) {
10259: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10260: '<ul>';
10261: foreach my $type (@statuses) {
10262: if ($type eq 'default') {
10263: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10264: } else {
10265: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10266: }
10267: }
10268: $chgtext .= '</ul>';
10269: } else {
10270: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10271: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10272: }
1.160.6.5 raeburn 10273: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 10274: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 10275: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10276: } else {
10277: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 10278: if ($captchas{$savecaptcha{$type}}) {
10279: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 10280: } else {
10281: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
10282: }
10283: }
10284: } elsif ($type eq 'recaptchakeys') {
10285: my ($privkey,$pubkey);
1.160.6.34 raeburn 10286: if (ref($savecaptcha{$type}) eq 'HASH') {
10287: $pubkey = $savecaptcha{$type}{'public'};
10288: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 10289: }
10290: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10291: if (!$pubkey) {
10292: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10293: } else {
10294: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10295: }
10296: if (!$privkey) {
10297: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10298: } else {
10299: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10300: }
10301: $chgtext .= '</ul>';
1.160.6.69 raeburn 10302: } elsif ($type eq 'recaptchaversion') {
10303: if ($savecaptcha{'captcha'} eq 'recaptcha') {
10304: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
10305: }
1.160.6.34 raeburn 10306: } elsif ($type eq 'emailusername') {
10307: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 10308: if (ref($types) eq 'ARRAY') {
10309: foreach my $type (@{$types}) {
10310: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10311: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 10312: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.160.6.35 raeburn 10313: '<ul>';
10314: foreach my $field (@{$infofields}) {
10315: if ($cancreate{'emailusername'}{$type}{$field}) {
10316: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10317: }
10318: }
1.160.6.50 raeburn 10319: $chgtext .= '</ul>';
10320: } else {
10321: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.160.6.35 raeburn 10322: }
10323: } else {
1.160.6.50 raeburn 10324: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.160.6.34 raeburn 10325: }
10326: }
10327: }
10328: }
10329: } elsif ($type eq 'notify') {
10330: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10331: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10332: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10333: if ($cancreate{'notify'}{'approval'}) {
10334: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10335: }
10336: }
1.43 raeburn 10337: }
1.34 raeburn 10338: }
1.160.6.34 raeburn 10339: if ($chgtext) {
10340: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10341: }
10342: }
10343: }
1.43 raeburn 10344: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10345: my ($emailrules,$emailruleorder) =
10346: &Apache::lonnet::inst_userrules($dom,'email');
10347: my $chgtext = '<ul>';
10348: foreach my $type (@email_rule) {
10349: if (ref($emailrules->{$type}) eq 'HASH') {
10350: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10351: }
10352: }
10353: $chgtext .= '</ul>';
10354: if (@email_rule > 0) {
1.160.6.34 raeburn 10355: $resulttext .= '<li>'.
10356: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10357: $chgtext.
10358: '</li>';
1.43 raeburn 10359: } else {
1.160.6.34 raeburn 10360: $resulttext .= '<li>'.
10361: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10362: '</li>';
1.43 raeburn 10363: }
10364: }
1.160.6.34 raeburn 10365: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10366: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10367: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10368: foreach my $type (@{$changes{'selfcreate'}}) {
10369: my $typename = $type;
10370: if (ref($usertypes) eq 'HASH') {
10371: if ($usertypes->{$type} ne '') {
10372: $typename = $usertypes->{$type};
1.28 raeburn 10373: }
10374: }
1.160.6.34 raeburn 10375: my @modifiable;
10376: $resulttext .= '<li>'.
10377: &mt('Self-creation of account by users with status: [_1]',
10378: '<span class="LC_cusr_emph">'.$typename.'</span>').
10379: ' - '.&mt('modifiable fields (if institutional data blank): ');
10380: foreach my $field (@fields) {
10381: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10382: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
10383: }
10384: }
10385: if (@modifiable > 0) {
10386: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10387: } else {
1.160.6.34 raeburn 10388: $resulttext .= &mt('none');
1.43 raeburn 10389: }
1.160.6.34 raeburn 10390: $resulttext .= '</li>';
1.28 raeburn 10391: }
1.160.6.34 raeburn 10392: $resulttext .= '</ul></li>';
1.28 raeburn 10393: }
1.27 raeburn 10394: $resulttext .= '</ul>';
10395: } else {
1.160.6.34 raeburn 10396: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10397: }
10398: } else {
10399: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10400: &mt('An error occurred: [_1]',$putresult).'</span>';
10401: }
1.43 raeburn 10402: if ($warningmsg ne '') {
10403: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10404: }
1.23 raeburn 10405: return $resulttext;
10406: }
10407:
1.160.6.5 raeburn 10408: sub process_captcha {
10409: my ($container,$changes,$newsettings,$current) = @_;
10410: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10411: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10412: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10413: $newsettings->{'captcha'} = 'original';
10414: }
10415: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
10416: if ($container eq 'cancreate') {
10417: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10418: push(@{$changes->{'cancreate'}},'captcha');
10419: } elsif (!defined($changes->{'cancreate'})) {
10420: $changes->{'cancreate'} = ['captcha'];
10421: }
10422: } else {
10423: $changes->{'captcha'} = 1;
10424: }
10425: }
1.160.6.69 raeburn 10426: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 10427: if ($newsettings->{'captcha'} eq 'recaptcha') {
10428: $newpub = $env{'form.'.$container.'_recaptchapub'};
10429: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 10430: $newpub =~ s/[^\w\-]//g;
10431: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 10432: $newsettings->{'recaptchakeys'} = {
10433: public => $newpub,
10434: private => $newpriv,
10435: };
1.160.6.69 raeburn 10436: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10437: $newversion =~ s/\D//g;
10438: if ($newversion ne '2') {
10439: $newversion = 1;
10440: }
10441: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 10442: }
10443: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10444: $currpub = $current->{'recaptchakeys'}{'public'};
10445: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 10446: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10447: $newsettings->{'recaptchakeys'} = {
10448: public => '',
10449: private => '',
10450: }
10451: }
1.160.6.5 raeburn 10452: }
1.160.6.69 raeburn 10453: if ($current->{'captcha'} eq 'recaptcha') {
10454: $currversion = $current->{'recaptchaversion'};
10455: if ($currversion ne '2') {
10456: $currversion = 1;
10457: }
10458: }
10459: if ($currversion ne $newversion) {
10460: if ($container eq 'cancreate') {
10461: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10462: push(@{$changes->{'cancreate'}},'recaptchaversion');
10463: } elsif (!defined($changes->{'cancreate'})) {
10464: $changes->{'cancreate'} = ['recaptchaversion'];
10465: }
10466: } else {
10467: $changes->{'recaptchaversion'} = 1;
10468: }
10469: }
1.160.6.5 raeburn 10470: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
10471: if ($container eq 'cancreate') {
10472: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10473: push(@{$changes->{'cancreate'}},'recaptchakeys');
10474: } elsif (!defined($changes->{'cancreate'})) {
10475: $changes->{'cancreate'} = ['recaptchakeys'];
10476: }
10477: } else {
10478: $changes->{'recaptchakeys'} = 1;
10479: }
10480: }
10481: return;
10482: }
10483:
1.33 raeburn 10484: sub modify_usermodification {
10485: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 10486: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10487: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10488: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 10489: if ($key eq 'selfcreate') {
10490: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10491: } else {
10492: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10493: }
1.33 raeburn 10494: }
10495: }
1.160.6.34 raeburn 10496: my @contexts = ('author','course');
1.33 raeburn 10497: my %context_title = (
10498: author => 'In author context',
10499: course => 'In course context',
10500: );
10501: my @fields = ('lastname','firstname','middlename','generation',
10502: 'permanentemail','id');
10503: my %roles = (
10504: author => ['ca','aa'],
10505: course => ['st','ep','ta','in','cr'],
10506: );
10507: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10508: foreach my $context (@contexts) {
10509: foreach my $role (@{$roles{$context}}) {
10510: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10511: foreach my $item (@fields) {
10512: if (grep(/^\Q$item\E$/,@modifiable)) {
10513: $modifyhash{$context}{$role}{$item} = 1;
10514: } else {
10515: $modifyhash{$context}{$role}{$item} = 0;
10516: }
10517: }
10518: }
10519: if (ref($curr_usermodification{$context}) eq 'HASH') {
10520: foreach my $role (@{$roles{$context}}) {
10521: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10522: foreach my $field (@fields) {
10523: if ($modifyhash{$context}{$role}{$field} ne
10524: $curr_usermodification{$context}{$role}{$field}) {
10525: push(@{$changes{$context}},$role);
10526: last;
10527: }
10528: }
10529: }
10530: }
10531: } else {
10532: foreach my $context (@contexts) {
10533: foreach my $role (@{$roles{$context}}) {
10534: push(@{$changes{$context}},$role);
10535: }
10536: }
10537: }
10538: }
10539: my %usermodification_hash = (
10540: usermodification => \%modifyhash,
10541: );
10542: my $putresult = &Apache::lonnet::put_dom('configuration',
10543: \%usermodification_hash,$dom);
10544: if ($putresult eq 'ok') {
10545: if (keys(%changes) > 0) {
10546: $resulttext = &mt('Changes made: ').'<ul>';
10547: foreach my $context (@contexts) {
10548: if (ref($changes{$context}) eq 'ARRAY') {
10549: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10550: if (ref($changes{$context}) eq 'ARRAY') {
10551: foreach my $role (@{$changes{$context}}) {
10552: my $rolename;
1.160.6.34 raeburn 10553: if ($role eq 'cr') {
10554: $rolename = &mt('Custom');
1.33 raeburn 10555: } else {
1.160.6.34 raeburn 10556: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10557: }
10558: my @modifiable;
1.160.6.34 raeburn 10559: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10560: foreach my $field (@fields) {
10561: if ($modifyhash{$context}{$role}{$field}) {
10562: push(@modifiable,$fieldtitles{$field});
10563: }
10564: }
10565: if (@modifiable > 0) {
10566: $resulttext .= join(', ',@modifiable);
10567: } else {
10568: $resulttext .= &mt('none');
10569: }
10570: $resulttext .= '</li>';
10571: }
10572: $resulttext .= '</ul></li>';
10573: }
10574: }
10575: }
10576: $resulttext .= '</ul>';
10577: } else {
10578: $resulttext = &mt('No changes made to user modification settings');
10579: }
10580: } else {
10581: $resulttext = '<span class="LC_error">'.
10582: &mt('An error occurred: [_1]',$putresult).'</span>';
10583: }
10584: return $resulttext;
10585: }
10586:
1.43 raeburn 10587: sub modify_defaults {
1.160.6.27 raeburn 10588: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10589: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 10590: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 10591: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
10592: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 10593: my @authtypes = ('internal','krb4','krb5','localauth');
10594: foreach my $item (@items) {
10595: $newvalues{$item} = $env{'form.'.$item};
10596: if ($item eq 'auth_def') {
10597: if ($newvalues{$item} ne '') {
10598: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10599: push(@errors,$item);
10600: }
10601: }
10602: } elsif ($item eq 'lang_def') {
10603: if ($newvalues{$item} ne '') {
10604: if ($newvalues{$item} =~ /^(\w+)/) {
10605: my $langcode = $1;
1.103 raeburn 10606: if ($langcode ne 'x_chef') {
10607: if (code2language($langcode) eq '') {
10608: push(@errors,$item);
10609: }
1.43 raeburn 10610: }
10611: } else {
10612: push(@errors,$item);
10613: }
10614: }
1.54 raeburn 10615: } elsif ($item eq 'timezone_def') {
10616: if ($newvalues{$item} ne '') {
1.62 raeburn 10617: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10618: push(@errors,$item);
10619: }
10620: }
1.68 raeburn 10621: } elsif ($item eq 'datelocale_def') {
10622: if ($newvalues{$item} ne '') {
10623: my @datelocale_ids = DateTime::Locale->ids();
10624: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10625: push(@errors,$item);
10626: }
10627: }
1.141 raeburn 10628: } elsif ($item eq 'portal_def') {
10629: if ($newvalues{$item} ne '') {
10630: 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])\/?$/) {
10631: push(@errors,$item);
10632: }
10633: }
1.160.6.80 raeburn 10634: } elsif ($item eq 'intauth_cost') {
10635: if ($newvalues{$item} ne '') {
10636: if ($newvalues{$item} =~ /\D/) {
10637: push(@errors,$item);
10638: }
10639: }
10640: } elsif ($item eq 'intauth_check') {
10641: if ($newvalues{$item} ne '') {
10642: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
10643: push(@errors,$item);
10644: }
10645: }
10646: } elsif ($item eq 'intauth_switch') {
10647: if ($newvalues{$item} ne '') {
10648: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
10649: push(@errors,$item);
10650: }
10651: }
1.43 raeburn 10652: }
10653: if (grep(/^\Q$item\E$/,@errors)) {
10654: $newvalues{$item} = $domdefaults{$item};
10655: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10656: $changes{$item} = 1;
10657: }
1.72 raeburn 10658: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10659: }
10660: my %defaults_hash = (
1.72 raeburn 10661: defaults => \%newvalues,
10662: );
1.43 raeburn 10663: my $title = &defaults_titles();
1.160.6.40 raeburn 10664:
10665: my $currinststatus;
10666: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10667: $currinststatus = $domconfig{'inststatus'};
10668: } else {
10669: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10670: $currinststatus = {
10671: inststatustypes => $usertypes,
10672: inststatusorder => $types,
10673: inststatusguest => [],
10674: };
10675: }
10676: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10677: my @allpos;
10678: my %guests;
10679: my %alltypes;
10680: my ($currtitles,$currguests,$currorder);
10681: if (ref($currinststatus) eq 'HASH') {
10682: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10683: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10684: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10685: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10686: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10687: }
10688: }
10689: unless (grep(/^\Q$type\E$/,@todelete)) {
10690: my $position = $env{'form.inststatus_pos_'.$type};
10691: $position =~ s/\D+//g;
10692: $allpos[$position] = $type;
10693: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
10694: $alltypes{$type} =~ s/`//g;
10695: if ($env{'form.inststatus_guest_'.$type}) {
10696: $guests{$type} = 1;
10697: }
10698: }
10699: }
10700: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
10701: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
10702: }
10703: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
10704: $currtitles =~ s/,$//;
10705: }
10706: }
10707: if ($env{'form.addinststatus'}) {
10708: my $newtype = $env{'form.addinststatus'};
10709: $newtype =~ s/\W//g;
10710: unless (exists($alltypes{$newtype})) {
10711: if ($env{'form.addinststatus_guest'}) {
10712: $guests{$newtype} = 1;
10713: }
10714: $alltypes{$newtype} = $env{'form.addinststatus_title'};
10715: $alltypes{$newtype} =~ s/`//g;
10716: my $position = $env{'form.addinststatus_pos'};
10717: $position =~ s/\D+//g;
10718: if ($position ne '') {
10719: $allpos[$position] = $newtype;
10720: }
10721: }
10722: }
10723: my (@orderedstatus,@orderedguests);
10724: foreach my $type (@allpos) {
10725: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
10726: push(@orderedstatus,$type);
10727: if ($guests{$type}) {
10728: push(@orderedguests,$type);
10729: }
10730: }
10731: }
10732: foreach my $type (keys(%alltypes)) {
10733: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
10734: delete($alltypes{$type});
10735: }
10736: }
10737: $defaults_hash{'inststatus'} = {
10738: inststatustypes => \%alltypes,
10739: inststatusorder => \@orderedstatus,
10740: inststatusguest => \@orderedguests,
10741: };
10742: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
10743: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
10744: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
10745: }
10746: }
10747: if ($currorder ne join(',',@orderedstatus)) {
10748: $changes{'inststatus'}{'inststatusorder'} = 1;
10749: }
10750: if ($currguests ne join(',',@orderedguests)) {
10751: $changes{'inststatus'}{'inststatusguest'} = 1;
10752: }
10753: my $newtitles;
10754: foreach my $item (@orderedstatus) {
10755: $newtitles .= $alltypes{$item}.',';
10756: }
10757: $newtitles =~ s/,$//;
10758: if ($currtitles ne $newtitles) {
10759: $changes{'inststatus'}{'inststatustypes'} = 1;
10760: }
1.43 raeburn 10761: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
10762: $dom);
10763: if ($putresult eq 'ok') {
10764: if (keys(%changes) > 0) {
10765: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 10766: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 10767: 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";
10768: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 10769: if ($item eq 'inststatus') {
10770: if (ref($changes{'inststatus'}) eq 'HASH') {
10771: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
10772: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
10773: foreach my $type (@orderedstatus) {
10774: $resulttext .= $alltypes{$type}.', ';
10775: }
10776: $resulttext =~ s/, $//;
10777: $resulttext .= '</li>';
10778: }
10779: if ($changes{'inststatus'}{'inststatusguest'}) {
10780: $resulttext .= '<li>';
10781: if (@orderedguests) {
10782: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
10783: foreach my $type (@orderedguests) {
10784: $resulttext .= $alltypes{$type}.', ';
10785: }
10786: $resulttext =~ s/, $//;
10787: } else {
10788: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
10789: }
10790: $resulttext .= '</li>';
10791: }
10792: }
10793: } else {
10794: my $value = $env{'form.'.$item};
10795: if ($value eq '') {
10796: $value = &mt('none');
10797: } elsif ($item eq 'auth_def') {
10798: my %authnames = &authtype_names();
10799: my %shortauth = (
10800: internal => 'int',
10801: krb4 => 'krb4',
10802: krb5 => 'krb5',
10803: localauth => 'loc',
10804: );
10805: $value = $authnames{$shortauth{$value}};
1.160.6.80 raeburn 10806: } elsif ($item eq 'intauth_switch') {
10807: my %optiondesc = &Apache::lonlocal::texthash (
10808: 0 => 'No',
10809: 1 => 'Yes',
10810: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
10811: );
10812: if ($value =~ /^(0|1|2)$/) {
10813: $value = $optiondesc{$value};
10814: } else {
10815: $value = &mt('none -- defaults to No');
10816: }
10817: } elsif ($item eq 'intauth_check') {
10818: my %optiondesc = &Apache::lonlocal::texthash (
10819: 0 => 'No',
10820: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
10821: 2 => 'Yes, disallow login if stored cost is less than domain default',
10822: );
10823: if ($value =~ /^(0|1|2)$/) {
10824: $value = $optiondesc{$value};
10825: } else {
10826: $value = &mt('none -- defaults to No');
10827: }
1.160.6.40 raeburn 10828: }
10829: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
10830: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 10831: }
10832: }
10833: $resulttext .= '</ul>';
10834: $mailmsgtext .= "\n";
10835: my $cachetime = 24*60*60;
1.72 raeburn 10836: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10837: if (ref($lastactref) eq 'HASH') {
10838: $lastactref->{'domdefaults'} = 1;
10839: }
1.68 raeburn 10840: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 10841: my $notify = 1;
10842: if (ref($domconfig{'contacts'}) eq 'HASH') {
10843: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
10844: $notify = 0;
10845: }
10846: }
10847: if ($notify) {
10848: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
10849: "LON-CAPA Domain Settings Change - $dom",
10850: $mailmsgtext);
10851: }
1.54 raeburn 10852: }
1.43 raeburn 10853: } else {
1.54 raeburn 10854: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 10855: }
10856: } else {
10857: $resulttext = '<span class="LC_error">'.
10858: &mt('An error occurred: [_1]',$putresult).'</span>';
10859: }
10860: if (@errors > 0) {
10861: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
10862: foreach my $item (@errors) {
10863: $resulttext .= ' "'.$title->{$item}.'",';
10864: }
10865: $resulttext =~ s/,$//;
10866: }
10867: return $resulttext;
10868: }
10869:
1.46 raeburn 10870: sub modify_scantron {
1.160.6.24 raeburn 10871: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 10872: my ($resulttext,%confhash,%changes,$errors);
10873: my $custom = 'custom.tab';
10874: my $default = 'default.tab';
10875: my $servadm = $r->dir_config('lonAdmEMail');
10876: my ($configuserok,$author_ok,$switchserver) =
10877: &config_check($dom,$confname,$servadm);
10878: if ($env{'form.scantronformat.filename'} ne '') {
10879: my $error;
10880: if ($configuserok eq 'ok') {
10881: if ($switchserver) {
1.130 raeburn 10882: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 10883: } else {
10884: if ($author_ok eq 'ok') {
10885: my ($result,$scantronurl) =
10886: &publishlogo($r,'upload','scantronformat',$dom,
10887: $confname,'scantron','','',$custom);
10888: if ($result eq 'ok') {
10889: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 10890: $changes{'scantronformat'} = 1;
1.46 raeburn 10891: } else {
10892: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
10893: }
10894: } else {
10895: $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);
10896: }
10897: }
10898: } else {
10899: $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);
10900: }
10901: if ($error) {
10902: &Apache::lonnet::logthis($error);
10903: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10904: }
10905: }
1.48 raeburn 10906: if (ref($domconfig{'scantron'}) eq 'HASH') {
10907: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
10908: if ($env{'form.scantronformat_del'}) {
10909: $confhash{'scantron'}{'scantronformat'} = '';
10910: $changes{'scantronformat'} = 1;
1.46 raeburn 10911: }
10912: }
10913: }
10914: if (keys(%confhash) > 0) {
10915: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10916: $dom);
10917: if ($putresult eq 'ok') {
10918: if (keys(%changes) > 0) {
1.48 raeburn 10919: if (ref($confhash{'scantron'}) eq 'HASH') {
10920: $resulttext = &mt('Changes made:').'<ul>';
10921: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 10922: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 10923: } else {
1.130 raeburn 10924: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 10925: }
1.48 raeburn 10926: $resulttext .= '</ul>';
10927: } else {
1.130 raeburn 10928: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 10929: }
10930: $resulttext .= '</ul>';
10931: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10932: if (ref($lastactref) eq 'HASH') {
10933: $lastactref->{'domainconfig'} = 1;
10934: }
1.46 raeburn 10935: } else {
1.130 raeburn 10936: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10937: }
10938: } else {
10939: $resulttext = '<span class="LC_error">'.
10940: &mt('An error occurred: [_1]',$putresult).'</span>';
10941: }
10942: } else {
1.130 raeburn 10943: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10944: }
10945: if ($errors) {
10946: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10947: $errors.'</ul>';
10948: }
10949: return $resulttext;
10950: }
10951:
1.48 raeburn 10952: sub modify_coursecategories {
1.160.6.43 raeburn 10953: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 10954: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10955: $cathash);
1.48 raeburn 10956: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 10957: my @catitems = ('unauth','auth');
10958: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 10959: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 10960: $cathash = $domconfig{'coursecategories'}{'cats'};
10961: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10962: $changes{'togglecats'} = 1;
10963: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10964: }
10965: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10966: $changes{'categorize'} = 1;
10967: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
10968: }
1.120 raeburn 10969: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
10970: $changes{'togglecatscomm'} = 1;
10971: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
10972: }
10973: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
10974: $changes{'categorizecomm'} = 1;
10975: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
10976: }
1.160.6.42 raeburn 10977: foreach my $item (@catitems) {
10978: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10979: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
10980: $changes{$item} = 1;
10981: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10982: }
10983: }
10984: }
1.57 raeburn 10985: } else {
10986: $changes{'togglecats'} = 1;
10987: $changes{'categorize'} = 1;
1.124 raeburn 10988: $changes{'togglecatscomm'} = 1;
10989: $changes{'categorizecomm'} = 1;
1.87 raeburn 10990: $domconfig{'coursecategories'} = {
10991: togglecats => $env{'form.togglecats'},
10992: categorize => $env{'form.categorize'},
1.124 raeburn 10993: togglecatscomm => $env{'form.togglecatscomm'},
10994: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 10995: };
1.160.6.42 raeburn 10996: foreach my $item (@catitems) {
10997: if ($env{'form.coursecat_'.$item} ne 'std') {
10998: $changes{$item} = 1;
10999: }
11000: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11001: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11002: }
11003: }
1.57 raeburn 11004: }
11005: if (ref($cathash) eq 'HASH') {
11006: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 11007: push (@deletecategory,'instcode::0');
11008: }
1.120 raeburn 11009: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11010: push(@deletecategory,'communities::0');
11011: }
1.48 raeburn 11012: }
1.57 raeburn 11013: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11014: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11015: if (@deletecategory > 0) {
11016: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 11017: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 11018: foreach my $item (@deletecategory) {
1.57 raeburn 11019: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11020: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11021: $deletions{$item} = 1;
1.57 raeburn 11022: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11023: }
11024: }
11025: }
1.57 raeburn 11026: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11027: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11028: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11029: $reorderings{$item} = 1;
1.57 raeburn 11030: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11031: }
11032: if ($env{'form.addcategory_name_'.$item} ne '') {
11033: my $newcat = $env{'form.addcategory_name_'.$item};
11034: my $newdepth = $depth+1;
11035: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11036: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11037: $adds{$newitem} = 1;
11038: }
11039: if ($env{'form.subcat_'.$item} ne '') {
11040: my $newcat = $env{'form.subcat_'.$item};
11041: my $newdepth = $depth+1;
11042: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11043: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11044: $adds{$newitem} = 1;
11045: }
11046: }
11047: }
11048: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11049: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11050: my $newitem = 'instcode::0';
1.57 raeburn 11051: if ($cathash->{$newitem} eq '') {
11052: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11053: $adds{$newitem} = 1;
11054: }
11055: } else {
11056: my $newitem = 'instcode::0';
1.57 raeburn 11057: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11058: $adds{$newitem} = 1;
11059: }
11060: }
1.120 raeburn 11061: if ($env{'form.communities'} eq '1') {
11062: if (ref($cathash) eq 'HASH') {
11063: my $newitem = 'communities::0';
11064: if ($cathash->{$newitem} eq '') {
11065: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11066: $adds{$newitem} = 1;
11067: }
11068: } else {
11069: my $newitem = 'communities::0';
11070: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11071: $adds{$newitem} = 1;
11072: }
11073: }
1.48 raeburn 11074: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11075: if (($env{'form.addcategory_name'} ne 'instcode') &&
11076: ($env{'form.addcategory_name'} ne 'communities')) {
11077: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11078: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11079: $adds{$newitem} = 1;
11080: }
1.48 raeburn 11081: }
1.57 raeburn 11082: my $putresult;
1.48 raeburn 11083: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11084: if (keys(%deletions) > 0) {
11085: foreach my $key (keys(%deletions)) {
11086: if ($predelallitems{$key} ne '') {
11087: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11088: }
11089: }
11090: }
11091: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11092: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11093: if (ref($chkcats[0]) eq 'ARRAY') {
11094: my $depth = 0;
11095: my $chg = 0;
11096: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11097: my $name = $chkcats[0][$i];
11098: my $item;
11099: if ($name eq '') {
11100: $chg ++;
11101: } else {
11102: $item = &escape($name).'::0';
11103: if ($chg) {
1.57 raeburn 11104: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11105: }
11106: $depth ++;
1.57 raeburn 11107: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11108: $depth --;
11109: }
11110: }
11111: }
1.57 raeburn 11112: }
11113: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11114: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11115: if ($putresult eq 'ok') {
1.57 raeburn 11116: my %title = (
1.120 raeburn 11117: togglecats => 'Show/Hide a course in catalog',
11118: categorize => 'Assign a category to a course',
11119: togglecatscomm => 'Show/Hide a community in catalog',
11120: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11121: );
11122: my %level = (
1.120 raeburn 11123: dom => 'set in Domain ("Modify Course/Community")',
11124: crs => 'set in Course ("Course Configuration")',
11125: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 11126: none => 'No catalog',
11127: std => 'Standard catalog',
11128: domonly => 'Domain-only catalog',
11129: codesrch => 'Code search form',
1.57 raeburn 11130: );
1.48 raeburn 11131: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11132: if ($changes{'togglecats'}) {
11133: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11134: }
11135: if ($changes{'categorize'}) {
11136: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11137: }
1.120 raeburn 11138: if ($changes{'togglecatscomm'}) {
11139: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11140: }
11141: if ($changes{'categorizecomm'}) {
11142: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11143: }
1.160.6.42 raeburn 11144: if ($changes{'unauth'}) {
11145: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11146: }
11147: if ($changes{'auth'}) {
11148: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11149: }
1.57 raeburn 11150: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11151: my $cathash;
11152: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11153: $cathash = $domconfig{'coursecategories'}{'cats'};
11154: } else {
11155: $cathash = {};
11156: }
11157: my (@cats,@trails,%allitems);
11158: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11159: if (keys(%deletions) > 0) {
11160: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11161: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11162: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11163: }
11164: $resulttext .= '</ul></li>';
11165: }
11166: if (keys(%reorderings) > 0) {
11167: my %sort_by_trail;
11168: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11169: foreach my $key (keys(%reorderings)) {
11170: if ($allitems{$key} ne '') {
11171: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11172: }
1.48 raeburn 11173: }
1.57 raeburn 11174: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11175: $resulttext .= '<li>'.$trails[$trail].'</li>';
11176: }
11177: $resulttext .= '</ul></li>';
1.48 raeburn 11178: }
1.57 raeburn 11179: if (keys(%adds) > 0) {
11180: my %sort_by_trail;
11181: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11182: foreach my $key (keys(%adds)) {
11183: if ($allitems{$key} ne '') {
11184: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11185: }
11186: }
11187: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11188: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11189: }
1.57 raeburn 11190: $resulttext .= '</ul></li>';
1.48 raeburn 11191: }
11192: }
11193: $resulttext .= '</ul>';
1.160.6.43 raeburn 11194: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 11195: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11196: if ($changes{'auth'}) {
11197: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11198: }
11199: if ($changes{'unauth'}) {
11200: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11201: }
11202: my $cachetime = 24*60*60;
11203: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 11204: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 11205: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 11206: }
11207: }
1.48 raeburn 11208: } else {
11209: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11210: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11211: }
11212: } else {
1.120 raeburn 11213: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11214: }
11215: return $resulttext;
11216: }
11217:
1.69 raeburn 11218: sub modify_serverstatuses {
11219: my ($dom,%domconfig) = @_;
11220: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11221: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11222: %currserverstatus = %{$domconfig{'serverstatuses'}};
11223: }
11224: my @pages = &serverstatus_pages();
11225: foreach my $type (@pages) {
11226: $newserverstatus{$type}{'namedusers'} = '';
11227: $newserverstatus{$type}{'machines'} = '';
11228: if (defined($env{'form.'.$type.'_namedusers'})) {
11229: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11230: my @okusers;
11231: foreach my $user (@users) {
11232: my ($uname,$udom) = split(/:/,$user);
11233: if (($udom =~ /^$match_domain$/) &&
11234: (&Apache::lonnet::domain($udom)) &&
11235: ($uname =~ /^$match_username$/)) {
11236: if (!grep(/^\Q$user\E/,@okusers)) {
11237: push(@okusers,$user);
11238: }
11239: }
11240: }
11241: if (@okusers > 0) {
11242: @okusers = sort(@okusers);
11243: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11244: }
11245: }
11246: if (defined($env{'form.'.$type.'_machines'})) {
11247: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11248: my @okmachines;
11249: foreach my $ip (@machines) {
11250: my @parts = split(/\./,$ip);
11251: next if (@parts < 4);
11252: my $badip = 0;
11253: for (my $i=0; $i<4; $i++) {
11254: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11255: $badip = 1;
11256: last;
11257: }
11258: }
11259: if (!$badip) {
11260: push(@okmachines,$ip);
11261: }
11262: }
11263: @okmachines = sort(@okmachines);
11264: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11265: }
11266: }
11267: my %serverstatushash = (
11268: serverstatuses => \%newserverstatus,
11269: );
11270: foreach my $type (@pages) {
1.83 raeburn 11271: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11272: my (@current,@new);
1.83 raeburn 11273: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11274: if ($currserverstatus{$type}{$setting} ne '') {
11275: @current = split(/,/,$currserverstatus{$type}{$setting});
11276: }
11277: }
11278: if ($newserverstatus{$type}{$setting} ne '') {
11279: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11280: }
11281: if (@current > 0) {
11282: if (@new > 0) {
11283: foreach my $item (@current) {
11284: if (!grep(/^\Q$item\E$/,@new)) {
11285: $changes{$type}{$setting} = 1;
1.82 raeburn 11286: last;
11287: }
11288: }
1.84 raeburn 11289: foreach my $item (@new) {
11290: if (!grep(/^\Q$item\E$/,@current)) {
11291: $changes{$type}{$setting} = 1;
11292: last;
1.82 raeburn 11293: }
11294: }
11295: } else {
1.83 raeburn 11296: $changes{$type}{$setting} = 1;
1.69 raeburn 11297: }
1.83 raeburn 11298: } elsif (@new > 0) {
11299: $changes{$type}{$setting} = 1;
1.69 raeburn 11300: }
11301: }
11302: }
11303: if (keys(%changes) > 0) {
1.81 raeburn 11304: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11305: my $putresult = &Apache::lonnet::put_dom('configuration',
11306: \%serverstatushash,$dom);
11307: if ($putresult eq 'ok') {
11308: $resulttext .= &mt('Changes made:').'<ul>';
11309: foreach my $type (@pages) {
1.84 raeburn 11310: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11311: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11312: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11313: if ($newserverstatus{$type}{'namedusers'} eq '') {
11314: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11315: } else {
11316: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11317: }
1.84 raeburn 11318: }
11319: if ($changes{$type}{'machines'}) {
1.69 raeburn 11320: if ($newserverstatus{$type}{'machines'} eq '') {
11321: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11322: } else {
11323: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11324: }
11325:
11326: }
11327: $resulttext .= '</ul></li>';
11328: }
11329: }
11330: $resulttext .= '</ul>';
11331: } else {
11332: $resulttext = '<span class="LC_error">'.
11333: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11334:
11335: }
11336: } else {
11337: $resulttext = &mt('No changes made to access to server status pages');
11338: }
11339: return $resulttext;
11340: }
11341:
1.118 jms 11342: sub modify_helpsettings {
1.160.6.77 raeburn 11343: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 11344: my ($resulttext,$errors,%changes,%helphash);
11345: my %defaultchecked = ('submitbugs' => 'on');
11346: my @offon = ('off','on');
1.118 jms 11347: my @toggles = ('submitbugs');
1.160.6.77 raeburn 11348: my %current = ('submitbugs' => '',
11349: 'adhoc' => {},
11350: );
1.118 jms 11351: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 11352: %current = %{$domconfig{'helpsettings'}};
11353: }
1.160.6.77 raeburn 11354: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 11355: foreach my $item (@toggles) {
11356: if ($defaultchecked{$item} eq 'on') {
11357: if ($current{$item} eq '') {
11358: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 11359: $changes{$item} = 1;
11360: }
1.160.6.73 raeburn 11361: } elsif ($current{$item} ne $env{'form.'.$item}) {
11362: $changes{$item} = 1;
11363: }
11364: } elsif ($defaultchecked{$item} eq 'off') {
11365: if ($current{$item} eq '') {
11366: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 11367: $changes{$item} = 1;
11368: }
1.160.6.73 raeburn 11369: } elsif ($current{$item} ne $env{'form.'.$item}) {
11370: $changes{$item} = 1;
11371: }
11372: }
11373: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
11374: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11375: }
11376: }
1.160.6.77 raeburn 11377: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 11378: my $confname = $dom.'-domainconfig';
11379: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 11380: my (@allpos,%newsettings,%changedprivs,$newrole);
11381: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 11382: my @accesstypes = ('all','dh','da','none','status','inc','exc');
11383: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 11384: my %lt = &Apache::lonlocal::texthash(
11385: s => 'system',
11386: d => 'domain',
11387: order => 'Display order',
11388: access => 'Role usage',
1.160.6.79 raeburn 11389: all => 'All with domain helpdesk or helpdesk assistant role',
11390: dh => 'All with domain helpdesk role',
11391: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 11392: none => 'None',
11393: status => 'Determined based on institutional status',
11394: inc => 'Include all, but exclude specific personnel',
11395: exc => 'Exclude all, but include specific personnel',
11396: );
11397: for (my $num=0; $num<=$maxnum; $num++) {
11398: my ($prefix,$identifier,$rolename,%curr);
11399: if ($num == $maxnum) {
11400: next unless ($env{'form.newcusthelp'} == $maxnum);
11401: $identifier = 'custhelp'.$num;
11402: $prefix = 'helproles_'.$num;
11403: $rolename = $env{'form.custhelpname'.$num};
11404: $rolename=~s/[^A-Za-z0-9]//gs;
11405: next if ($rolename eq '');
11406: next if (exists($existing{'rolesdef_'.$rolename}));
11407: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11408: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11409: $newprivs{'c'},$confname,$dom);
11410: if ($result ne 'ok') {
11411: $errors .= '<li><span class="LC_error">'.
11412: &mt('An error occurred storing the new custom role: [_1]',
11413: $result).'</span></li>';
11414: next;
11415: } else {
11416: $changedprivs{$rolename} = \%newprivs;
11417: $newrole = $rolename;
11418: }
11419: } else {
11420: $prefix = 'helproles_'.$num;
11421: $rolename = $env{'form.'.$prefix};
11422: next if ($rolename eq '');
11423: next unless (exists($existing{'rolesdef_'.$rolename}));
11424: $identifier = 'custhelp'.$num;
11425: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11426: my %currprivs;
11427: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
11428: split(/\_/,$existing{'rolesdef_'.$rolename});
11429: foreach my $level ('c','d','s') {
11430: if ($newprivs{$level} ne $currprivs{$level}) {
11431: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11432: $newprivs{'c'},$confname,$dom);
11433: if ($result ne 'ok') {
11434: $errors .= '<li><span class="LC_error">'.
11435: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
11436: $rolename,$result).'</span></li>';
11437: } else {
11438: $changedprivs{$rolename} = \%newprivs;
11439: }
11440: last;
11441: }
11442: }
11443: if (ref($current{'adhoc'}) eq 'HASH') {
11444: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11445: %curr = %{$current{'adhoc'}{$rolename}};
11446: }
11447: }
11448: }
11449: my $newpos = $env{'form.'.$prefix.'_pos'};
11450: $newpos =~ s/\D+//g;
11451: $allpos[$newpos] = $rolename;
11452: my $newdesc = $env{'form.'.$prefix.'_desc'};
11453: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
11454: if ($curr{'desc'}) {
11455: if ($curr{'desc'} ne $newdesc) {
11456: $changes{'customrole'}{$rolename}{'desc'} = 1;
11457: $newsettings{$rolename}{'desc'} = $newdesc;
11458: }
11459: } elsif ($newdesc ne '') {
11460: $changes{'customrole'}{$rolename}{'desc'} = 1;
11461: $newsettings{$rolename}{'desc'} = $newdesc;
11462: }
11463: my $access = $env{'form.'.$prefix.'_access'};
11464: if (grep(/^\Q$access\E$/,@accesstypes)) {
11465: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
11466: if ($access eq 'status') {
11467: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
11468: if (scalar(@statuses) == 0) {
11469: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
11470: } else {
11471: my (@shownstatus,$numtypes);
11472: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11473: if (ref($types) eq 'ARRAY') {
11474: $numtypes = scalar(@{$types});
11475: foreach my $type (sort(@statuses)) {
11476: if ($type eq 'default') {
11477: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11478: } elsif (grep(/^\Q$type\E$/,@{$types})) {
11479: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11480: push(@shownstatus,$usertypes->{$type});
11481: }
1.160.6.73 raeburn 11482: }
11483: }
1.160.6.77 raeburn 11484: if (grep(/^default$/,@statuses)) {
11485: push(@shownstatus,$othertitle);
11486: }
11487: if (scalar(@shownstatus) == 1+$numtypes) {
11488: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
11489: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
11490: } else {
11491: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
11492: if (ref($curr{'status'}) eq 'ARRAY') {
11493: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11494: if (@diffs) {
11495: $changes{'customrole'}{$rolename}{$access} = 1;
11496: }
11497: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11498: $changes{'customrole'}{$rolename}{$access} = 1;
11499: }
11500: }
11501: }
11502: } elsif (($access eq 'inc') || ($access eq 'exc')) {
11503: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
11504: my @newspecstaff;
11505: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11506: foreach my $person (sort(@personnel)) {
11507: if ($domhelpdesk{$person}) {
11508: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
11509: }
11510: }
11511: if (ref($curr{$access}) eq 'ARRAY') {
11512: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11513: if (@diffs) {
11514: $changes{'customrole'}{$rolename}{$access} = 1;
11515: }
11516: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11517: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 11518: }
1.160.6.77 raeburn 11519: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11520: my ($uname,$udom) = split(/:/,$person);
11521: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
11522: }
11523: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 11524: }
1.160.6.77 raeburn 11525: } else {
11526: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
11527: }
11528: unless ($curr{'access'} eq $access) {
11529: $changes{'customrole'}{$rolename}{'access'} = 1;
11530: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 11531: }
11532: }
1.160.6.77 raeburn 11533: if (@allpos > 0) {
11534: my $idx = 0;
11535: foreach my $rolename (@allpos) {
11536: if ($rolename ne '') {
11537: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
11538: if (ref($current{'adhoc'}) eq 'HASH') {
11539: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11540: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
11541: $changes{'customrole'}{$rolename}{'order'} = 1;
11542: $newsettings{$rolename}{'order'} = $idx+1;
11543: }
11544: }
1.160.6.73 raeburn 11545: }
1.160.6.77 raeburn 11546: $idx ++;
1.122 jms 11547: }
11548: }
1.118 jms 11549: }
1.123 jms 11550: my $putresult;
11551: if (keys(%changes) > 0) {
1.160.6.5 raeburn 11552: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
11553: if ($putresult eq 'ok') {
1.160.6.77 raeburn 11554: if (ref($helphash{'helpsettings'}) eq 'HASH') {
11555: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
11556: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
11557: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
11558: }
11559: }
11560: my $cachetime = 24*60*60;
11561: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11562: if (ref($lastactref) eq 'HASH') {
11563: $lastactref->{'domdefaults'} = 1;
11564: }
11565: } else {
11566: $errors .= '<li><span class="LC_error">'.
11567: &mt('An error occurred storing the settings: [_1]',
11568: $putresult).'</span></li>';
11569: }
11570: }
11571: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
11572: $resulttext = &mt('Changes made:').'<ul>';
11573: my (%shownprivs,@levelorder);
11574: @levelorder = ('c','d','s');
11575: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 11576: foreach my $item (sort(keys(%changes))) {
11577: if ($item eq 'submitbugs') {
11578: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11579: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11580: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 11581: } elsif ($item eq 'customrole') {
11582: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 11583: my @keyorder = ('order','desc','access','status','exc','inc');
11584: my %keytext = &Apache::lonlocal::texthash(
11585: order => 'Order',
11586: desc => 'Role description',
11587: access => 'Role usage',
1.160.6.83 raeburn 11588: status => 'Allowed institutional types',
1.160.6.77 raeburn 11589: exc => 'Allowed personnel',
11590: inc => 'Disallowed personnel',
11591: );
1.160.6.73 raeburn 11592: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 11593: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
11594: if ($role eq $newrole) {
11595: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
11596: $role).'<ul>';
11597: } else {
11598: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11599: $role).'<ul>';
11600: }
11601: foreach my $key (@keyorder) {
11602: if ($changes{'customrole'}{$role}{$key}) {
11603: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
11604: $keytext{$key},$newsettings{$role}{$key}).
11605: '</li>';
11606: }
11607: }
11608: if (ref($changedprivs{$role}) eq 'HASH') {
11609: $shownprivs{$role} = 1;
11610: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
11611: foreach my $level (@levelorder) {
11612: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11613: next if ($item eq '');
11614: my ($priv) = split(/\&/,$item,2);
11615: if (&Apache::lonnet::plaintext($priv)) {
11616: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11617: unless ($level eq 'c') {
11618: $resulttext .= ' ('.$lt{$level}.')';
11619: }
11620: $resulttext .= '</li>';
11621: }
11622: }
11623: }
11624: $resulttext .= '</ul>';
11625: }
11626: $resulttext .= '</ul></li>';
11627: }
1.160.6.73 raeburn 11628: }
11629: }
1.160.6.5 raeburn 11630: }
11631: }
11632: }
1.160.6.77 raeburn 11633: if (keys(%changedprivs)) {
11634: foreach my $role (sort(keys(%changedprivs))) {
11635: unless ($shownprivs{$role}) {
11636: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11637: $role).'<ul>'.
11638: '<li>'.&mt('Privileges set to :').'<ul>';
11639: foreach my $level (@levelorder) {
11640: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11641: next if ($item eq '');
11642: my ($priv) = split(/\&/,$item,2);
11643: if (&Apache::lonnet::plaintext($priv)) {
11644: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11645: unless ($level eq 'c') {
11646: $resulttext .= ' ('.$lt{$level}.')';
11647: }
11648: $resulttext .= '</li>';
11649: }
11650: }
11651: }
11652: $resulttext .= '</ul></li></ul></li>';
11653: }
11654: }
11655: }
11656: $resulttext .= '</ul>';
11657: } else {
11658: $resulttext = &mt('No changes made to help settings');
1.118 jms 11659: }
11660: if ($errors) {
1.160.6.5 raeburn 11661: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 11662: $errors.'</ul>';
1.118 jms 11663: }
11664: return $resulttext;
11665: }
11666:
1.121 raeburn 11667: sub modify_coursedefaults {
1.160.6.27 raeburn 11668: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11669: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 11670: my %defaultchecked = (
11671: 'uselcmath' => 'on',
11672: 'usejsme' => 'on'
11673: );
11674: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 11675: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 11676: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
11677: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 11678: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 11679: my %staticdefaults = (
11680: anonsurvey_threshold => 10,
11681: uploadquota => 500,
1.160.6.57 raeburn 11682: postsubmit => 60,
1.160.6.70 raeburn 11683: mysqltables => 172800,
1.160.6.21 raeburn 11684: );
1.121 raeburn 11685:
11686: $defaultshash{'coursedefaults'} = {};
11687:
11688: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11689: if ($domconfig{'coursedefaults'} eq '') {
11690: $domconfig{'coursedefaults'} = {};
11691: }
11692: }
11693:
11694: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11695: foreach my $item (@toggles) {
11696: if ($defaultchecked{$item} eq 'on') {
11697: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11698: ($env{'form.'.$item} eq '0')) {
11699: $changes{$item} = 1;
1.160.6.16 raeburn 11700: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11701: $changes{$item} = 1;
11702: }
11703: } elsif ($defaultchecked{$item} eq 'off') {
11704: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11705: ($env{'form.'.$item} eq '1')) {
11706: $changes{$item} = 1;
11707: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11708: $changes{$item} = 1;
11709: }
11710: }
11711: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11712: }
1.160.6.21 raeburn 11713: foreach my $item (@numbers) {
11714: my ($currdef,$newdef);
1.160.6.26 raeburn 11715: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 11716: if ($item eq 'anonsurvey_threshold') {
11717: $currdef = $domconfig{'coursedefaults'}{$item};
11718: $newdef =~ s/\D//g;
11719: if ($newdef eq '' || $newdef < 1) {
11720: $newdef = 1;
11721: }
11722: $defaultshash{'coursedefaults'}{$item} = $newdef;
11723: } else {
1.160.6.70 raeburn 11724: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
11725: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
11726: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 11727: }
11728: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 11729: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 11730: }
11731: if ($currdef ne $newdef) {
11732: my $staticdef;
11733: if ($item eq 'anonsurvey_threshold') {
11734: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11735: $changes{$item} = 1;
11736: }
1.160.6.70 raeburn 11737: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
11738: my $setting = $1;
11739: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
11740: $changes{$setting} = 1;
1.160.6.21 raeburn 11741: }
11742: }
1.139 raeburn 11743: }
11744: }
1.160.6.64 raeburn 11745: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11746: my @currclonecode;
11747: if (ref($currclone) eq 'HASH') {
11748: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11749: @currclonecode = @{$currclone->{'instcode'}};
11750: }
11751: }
11752: my $newclone;
11753: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11754: $newclone = $env{'form.canclone'};
11755: }
11756: if ($newclone eq 'instcode') {
11757: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11758: my (%codedefaults,@code_order,@clonecode);
11759: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11760: \@code_order);
11761: foreach my $item (@code_order) {
11762: if (grep(/^\Q$item\E$/,@newcodes)) {
11763: push(@clonecode,$item);
11764: }
11765: }
11766: if (@clonecode) {
11767: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11768: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11769: if (@diffs) {
11770: $changes{'canclone'} = 1;
11771: }
11772: } else {
11773: $newclone eq '';
11774: }
11775: } elsif ($newclone ne '') {
11776: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11777: }
11778: if ($newclone ne $currclone) {
11779: $changes{'canclone'} = 1;
11780: }
1.160.6.57 raeburn 11781: my %credits;
11782: foreach my $type (@types) {
11783: unless ($type eq 'community') {
11784: $credits{$type} = $env{'form.'.$type.'_credits'};
11785: $credits{$type} =~ s/[^\d.]+//g;
11786: }
11787: }
11788: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11789: ($env{'form.coursecredits'} eq '1')) {
11790: $changes{'coursecredits'} = 1;
11791: foreach my $type (keys(%credits)) {
11792: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11793: }
11794: } else {
11795: if ($env{'form.coursecredits'} eq '1') {
11796: foreach my $type (@types) {
11797: unless ($type eq 'community') {
11798: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11799: $changes{'coursecredits'} = 1;
11800: }
11801: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11802: }
11803: }
11804: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11805: foreach my $type (@types) {
11806: unless ($type eq 'community') {
11807: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11808: $changes{'coursecredits'} = 1;
11809: last;
11810: }
11811: }
11812: }
11813: }
11814: }
11815: if ($env{'form.postsubmit'} eq '1') {
11816: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11817: my %currtimeout;
11818: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11819: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11820: $changes{'postsubmit'} = 1;
11821: }
11822: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11823: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11824: }
11825: } else {
11826: $changes{'postsubmit'} = 1;
11827: }
11828: foreach my $type (@types) {
11829: my $timeout = $env{'form.'.$type.'_timeout'};
11830: $timeout =~ s/\D//g;
11831: if ($timeout == $staticdefaults{'postsubmit'}) {
11832: $timeout = '';
11833: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11834: $timeout = '0';
11835: }
11836: unless ($timeout eq '') {
11837: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11838: }
11839: if (exists($currtimeout{$type})) {
11840: if ($timeout ne $currtimeout{$type}) {
11841: $changes{'postsubmit'} = 1;
11842: }
11843: } elsif ($timeout ne '') {
11844: $changes{'postsubmit'} = 1;
11845: }
11846: }
11847: } else {
11848: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11849: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11850: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11851: $changes{'postsubmit'} = 1;
11852: }
11853: } else {
11854: $changes{'postsubmit'} = 1;
11855: }
1.160.6.16 raeburn 11856: }
1.121 raeburn 11857: }
11858: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11859: $dom);
11860: if ($putresult eq 'ok') {
11861: if (keys(%changes) > 0) {
1.160.6.27 raeburn 11862: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 11863: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 11864: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 11865: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 11866: foreach my $item ('uselcmath','usejsme') {
11867: if ($changes{$item}) {
11868: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11869: }
1.160.6.16 raeburn 11870: }
11871: if ($changes{'coursecredits'}) {
11872: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 11873: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11874: $domdefaults{$type.'credits'} =
11875: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11876: }
11877: }
11878: }
11879: if ($changes{'postsubmit'}) {
11880: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11881: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11882: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11883: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11884: $domdefaults{$type.'postsubtimeout'} =
11885: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11886: }
11887: }
1.160.6.16 raeburn 11888: }
11889: }
1.160.6.21 raeburn 11890: if ($changes{'uploadquota'}) {
11891: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11892: foreach my $type (@types) {
11893: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11894: }
11895: }
11896: }
1.160.6.64 raeburn 11897: if ($changes{'canclone'}) {
11898: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11899: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11900: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11901: if (@clonecodes) {
11902: $domdefaults{'canclone'} = join('+',@clonecodes);
11903: }
11904: }
11905: } else {
11906: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11907: }
11908: }
1.121 raeburn 11909: my $cachetime = 24*60*60;
11910: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11911: if (ref($lastactref) eq 'HASH') {
11912: $lastactref->{'domdefaults'} = 1;
11913: }
1.121 raeburn 11914: }
11915: $resulttext = &mt('Changes made:').'<ul>';
11916: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 11917: if ($item eq 'uselcmath') {
1.121 raeburn 11918: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 11919: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 11920: } else {
1.160.6.57 raeburn 11921: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11922: }
11923: } elsif ($item eq 'usejsme') {
11924: if ($env{'form.'.$item} eq '1') {
11925: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11926: } else {
11927: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 11928: }
1.139 raeburn 11929: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 11930: $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 11931: } elsif ($item eq 'uploadquota') {
11932: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11933: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11934: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11935: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 11936: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
11937:
1.160.6.21 raeburn 11938: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11939: '</ul>'.
11940: '</li>';
11941: } else {
11942: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11943: }
1.160.6.70 raeburn 11944: } elsif ($item eq 'mysqltables') {
11945: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
11946: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
11947: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
11948: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
11949: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
11950: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
11951: '</ul>'.
11952: '</li>';
11953: } else {
11954: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
11955: }
1.160.6.57 raeburn 11956: } elsif ($item eq 'postsubmit') {
11957: if ($domdefaults{'postsubmit'} eq 'off') {
11958: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
11959: } else {
11960: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
11961: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11962: $resulttext .= &mt('durations:').'<ul>';
11963: foreach my $type (@types) {
11964: $resulttext .= '<li>';
11965: my $timeout;
11966: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11967: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11968: }
11969: my $display;
11970: if ($timeout eq '0') {
11971: $display = &mt('unlimited');
11972: } elsif ($timeout eq '') {
11973: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
11974: } else {
11975: $display = &mt('[quant,_1,second]',$timeout);
11976: }
11977: if ($type eq 'community') {
11978: $resulttext .= &mt('Communities');
11979: } elsif ($type eq 'official') {
11980: $resulttext .= &mt('Official courses');
11981: } elsif ($type eq 'unofficial') {
11982: $resulttext .= &mt('Unofficial courses');
11983: } elsif ($type eq 'textbook') {
11984: $resulttext .= &mt('Textbook courses');
11985: }
11986: $resulttext .= ' -- '.$display.'</li>';
11987: }
11988: $resulttext .= '</ul>';
11989: }
11990: $resulttext .= '</li>';
11991: }
1.160.6.16 raeburn 11992: } elsif ($item eq 'coursecredits') {
11993: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11994: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 11995: ($domdefaults{'unofficialcredits'} eq '') &&
11996: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 11997: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11998: } else {
11999: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
12000: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
12001: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 12002: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 12003: '</ul>'.
12004: '</li>';
12005: }
12006: } else {
12007: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12008: }
1.160.6.64 raeburn 12009: } elsif ($item eq 'canclone') {
12010: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12011: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12012: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
12013: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
12014: }
12015: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
12016: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
12017: } else {
12018: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
12019: }
1.140 raeburn 12020: }
1.121 raeburn 12021: }
12022: $resulttext .= '</ul>';
12023: } else {
12024: $resulttext = &mt('No changes made to course defaults');
12025: }
12026: } else {
12027: $resulttext = '<span class="LC_error">'.
12028: &mt('An error occurred: [_1]',$putresult).'</span>';
12029: }
12030: return $resulttext;
12031: }
12032:
1.160.6.37 raeburn 12033: sub modify_selfenrollment {
12034: my ($dom,$lastactref,%domconfig) = @_;
12035: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
12036: my @types = ('official','unofficial','community','textbook');
12037: my %titles = &tool_titles();
12038: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12039: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
12040: $ordered{'default'} = ['types','registered','approval','limit'];
12041:
12042: my (%roles,%shown,%toplevel);
12043: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12044:
12045: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12046: if ($domconfig{'selfenrollment'} eq '') {
12047: $domconfig{'selfenrollment'} = {};
12048: }
12049: }
12050: %toplevel = (
12051: admin => 'Configuration Rights',
12052: default => 'Default settings',
12053: validation => 'Validation of self-enrollment requests',
12054: );
12055: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
12056:
12057: if (ref($ordered{'admin'}) eq 'ARRAY') {
12058: foreach my $item (@{$ordered{'admin'}}) {
12059: foreach my $type (@types) {
12060: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12061: $selfenrollhash{'admin'}{$type}{$item} = 1;
12062: } else {
12063: $selfenrollhash{'admin'}{$type}{$item} = 0;
12064: }
12065: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12066: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12067: if ($selfenrollhash{'admin'}{$type}{$item} ne
12068: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12069: push(@{$changes{'admin'}{$type}},$item);
12070: }
12071: } else {
12072: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12073: push(@{$changes{'admin'}{$type}},$item);
12074: }
12075: }
12076: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12077: push(@{$changes{'admin'}{$type}},$item);
12078: }
12079: }
12080: }
12081: }
12082:
12083: foreach my $item (@{$ordered{'default'}}) {
12084: foreach my $type (@types) {
12085: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12086: if ($item eq 'types') {
12087: unless (($value eq 'all') || ($value eq 'dom')) {
12088: $value = '';
12089: }
12090: } elsif ($item eq 'registered') {
12091: unless ($value eq '1') {
12092: $value = 0;
12093: }
12094: } elsif ($item eq 'approval') {
12095: unless ($value =~ /^[012]$/) {
12096: $value = 0;
12097: }
12098: } else {
12099: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12100: $value = 'none';
12101: }
12102: }
12103: $selfenrollhash{'default'}{$type}{$item} = $value;
12104: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12105: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12106: if ($selfenrollhash{'default'}{$type}{$item} ne
12107: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12108: push(@{$changes{'default'}{$type}},$item);
12109: }
12110: } else {
12111: push(@{$changes{'default'}{$type}},$item);
12112: }
12113: } else {
12114: push(@{$changes{'default'}{$type}},$item);
12115: }
12116: if ($item eq 'limit') {
12117: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12118: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12119: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12120: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12121: }
12122: } else {
12123: $selfenrollhash{'default'}{$type}{'cap'} = '';
12124: }
12125: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12126: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12127: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12128: push(@{$changes{'default'}{$type}},'cap');
12129: }
12130: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12131: push(@{$changes{'default'}{$type}},'cap');
12132: }
12133: }
12134: }
12135: }
12136:
12137: foreach my $item (@{$itemsref}) {
12138: if ($item eq 'fields') {
12139: my @changed;
12140: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12141: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12142: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12143: }
12144: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12145: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12146: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12147: $domconfig{'selfenrollment'}{'validation'}{$item});
12148: } else {
12149: @changed = @{$selfenrollhash{'validation'}{$item}};
12150: }
12151: } else {
12152: @changed = @{$selfenrollhash{'validation'}{$item}};
12153: }
12154: if (@changed) {
12155: if ($selfenrollhash{'validation'}{$item}) {
12156: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12157: } else {
12158: $changes{'validation'}{$item} = &mt('None');
12159: }
12160: }
12161: } else {
12162: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12163: if ($item eq 'markup') {
12164: if ($env{'form.selfenroll_validation_'.$item}) {
12165: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12166: }
12167: }
12168: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12169: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12170: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12171: }
12172: }
12173: }
12174: }
12175:
12176: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12177: $dom);
12178: if ($putresult eq 'ok') {
12179: if (keys(%changes) > 0) {
12180: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12181: $resulttext = &mt('Changes made:').'<ul>';
12182: foreach my $key ('admin','default','validation') {
12183: if (ref($changes{$key}) eq 'HASH') {
12184: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12185: if ($key eq 'validation') {
12186: foreach my $item (@{$itemsref}) {
12187: if (exists($changes{$key}{$item})) {
12188: if ($item eq 'markup') {
12189: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12190: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12191: } else {
12192: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12193: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12194: }
12195: }
12196: }
12197: } else {
12198: foreach my $type (@types) {
12199: if ($type eq 'community') {
12200: $roles{'1'} = &mt('Community personnel');
12201: } else {
12202: $roles{'1'} = &mt('Course personnel');
12203: }
12204: if (ref($changes{$key}{$type}) eq 'ARRAY') {
12205: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12206: if ($key eq 'admin') {
12207: my @mgrdc = ();
12208: if (ref($ordered{$key}) eq 'ARRAY') {
12209: foreach my $item (@{$ordered{'admin'}}) {
12210: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12211: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12212: push(@mgrdc,$item);
12213: }
12214: }
12215: }
12216: if (@mgrdc) {
12217: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12218: } else {
12219: delete($domdefaults{$type.'selfenrolladmdc'});
12220: }
12221: }
12222: } else {
12223: if (ref($ordered{$key}) eq 'ARRAY') {
12224: foreach my $item (@{$ordered{$key}}) {
12225: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12226: $domdefaults{$type.'selfenroll'.$item} =
12227: $selfenrollhash{$key}{$type}{$item};
12228: }
12229: }
12230: }
12231: }
12232: }
12233: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12234: foreach my $item (@{$ordered{$key}}) {
12235: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12236: $resulttext .= '<li>';
12237: if ($key eq 'admin') {
12238: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12239: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12240: } else {
12241: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12242: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12243: }
12244: $resulttext .= '</li>';
12245: }
12246: }
12247: $resulttext .= '</ul></li>';
12248: }
12249: }
12250: $resulttext .= '</ul></li>';
12251: }
12252: }
12253: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12254: my $cachetime = 24*60*60;
12255: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12256: if (ref($lastactref) eq 'HASH') {
12257: $lastactref->{'domdefaults'} = 1;
12258: }
12259: }
12260: }
12261: $resulttext .= '</ul>';
12262: } else {
12263: $resulttext = &mt('No changes made to self-enrollment settings');
12264: }
12265: } else {
12266: $resulttext = '<span class="LC_error">'.
12267: &mt('An error occurred: [_1]',$putresult).'</span>';
12268: }
12269: return $resulttext;
12270: }
12271:
1.137 raeburn 12272: sub modify_usersessions {
1.160.6.27 raeburn 12273: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12274: my @hostingtypes = ('version','excludedomain','includedomain');
12275: my @offloadtypes = ('primary','default');
12276: my %types = (
12277: remote => \@hostingtypes,
12278: hosted => \@hostingtypes,
12279: spares => \@offloadtypes,
12280: );
12281: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12282: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 12283: my (%by_ip,%by_location,@intdoms);
12284: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
12285: my @locations = sort(keys(%by_location));
1.137 raeburn 12286: my (%defaultshash,%changes);
12287: foreach my $prefix (@prefixes) {
12288: $defaultshash{'usersessions'}{$prefix} = {};
12289: }
1.160.6.27 raeburn 12290: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12291: my $resulttext;
1.138 raeburn 12292: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12293: foreach my $prefix (@prefixes) {
1.145 raeburn 12294: next if ($prefix eq 'spares');
12295: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12296: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12297: if ($type eq 'version') {
12298: my $value = $env{'form.'.$prefix.'_'.$type};
12299: my $okvalue;
12300: if ($value ne '') {
12301: if (grep(/^\Q$value\E$/,@lcversions)) {
12302: $okvalue = $value;
12303: }
12304: }
12305: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12306: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12307: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12308: if ($inuse == 0) {
12309: $changes{$prefix}{$type} = 1;
12310: } else {
12311: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12312: $changes{$prefix}{$type} = 1;
12313: }
12314: if ($okvalue ne '') {
12315: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12316: }
12317: }
12318: } else {
12319: if (($inuse == 1) && ($okvalue ne '')) {
12320: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12321: $changes{$prefix}{$type} = 1;
12322: }
12323: }
12324: } else {
12325: if (($inuse == 1) && ($okvalue ne '')) {
12326: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12327: $changes{$prefix}{$type} = 1;
12328: }
12329: }
12330: } else {
12331: if (($inuse == 1) && ($okvalue ne '')) {
12332: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12333: $changes{$prefix}{$type} = 1;
12334: }
12335: }
12336: } else {
12337: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12338: my @okvals;
12339: foreach my $val (@vals) {
1.138 raeburn 12340: if ($val =~ /:/) {
12341: my @items = split(/:/,$val);
12342: foreach my $item (@items) {
12343: if (ref($by_location{$item}) eq 'ARRAY') {
12344: push(@okvals,$item);
12345: }
12346: }
12347: } else {
12348: if (ref($by_location{$val}) eq 'ARRAY') {
12349: push(@okvals,$val);
12350: }
1.137 raeburn 12351: }
12352: }
12353: @okvals = sort(@okvals);
12354: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12355: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12356: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12357: if ($inuse == 0) {
12358: $changes{$prefix}{$type} = 1;
12359: } else {
12360: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12361: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12362: if (@changed > 0) {
12363: $changes{$prefix}{$type} = 1;
12364: }
12365: }
12366: } else {
12367: if ($inuse == 1) {
12368: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12369: $changes{$prefix}{$type} = 1;
12370: }
12371: }
12372: } else {
12373: if ($inuse == 1) {
12374: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12375: $changes{$prefix}{$type} = 1;
12376: }
12377: }
12378: } else {
12379: if ($inuse == 1) {
12380: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12381: $changes{$prefix}{$type} = 1;
12382: }
12383: }
12384: }
12385: }
12386: }
1.145 raeburn 12387:
12388: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12389: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12390: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12391: my $savespares;
12392:
12393: foreach my $lonhost (sort(keys(%servers))) {
12394: my $serverhomeID =
12395: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12396: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12397: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12398: my %spareschg;
12399: foreach my $type (@{$types{'spares'}}) {
12400: my @okspares;
12401: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12402: foreach my $server (@checked) {
1.152 raeburn 12403: if (&Apache::lonnet::hostname($server) ne '') {
12404: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12405: unless (grep(/^\Q$server\E$/,@okspares)) {
12406: push(@okspares,$server);
12407: }
1.145 raeburn 12408: }
12409: }
12410: }
12411: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12412: my $newspare;
1.152 raeburn 12413: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12414: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12415: $newspare = $new;
12416: }
12417: }
1.152 raeburn 12418: my @spares;
12419: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12420: @spares = sort(@okspares,$newspare);
12421: } else {
12422: @spares = sort(@okspares);
12423: }
12424: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12425: if (ref($spareid{$lonhost}) eq 'HASH') {
12426: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12427: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12428: if (@diffs > 0) {
12429: $spareschg{$type} = 1;
12430: }
12431: }
12432: }
12433: }
12434: if (keys(%spareschg) > 0) {
12435: $changes{'spares'}{$lonhost} = \%spareschg;
12436: }
12437: }
1.160.6.61 raeburn 12438: $defaultshash{'usersessions'}{'offloadnow'} = {};
12439: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12440: my @okoffload;
12441: if (@offloadnow) {
12442: foreach my $server (@offloadnow) {
12443: if (&Apache::lonnet::hostname($server) ne '') {
12444: unless (grep(/^\Q$server\E$/,@okoffload)) {
12445: push(@okoffload,$server);
12446: }
12447: }
12448: }
12449: if (@okoffload) {
12450: foreach my $lonhost (@okoffload) {
12451: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12452: }
12453: }
12454: }
1.145 raeburn 12455: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12456: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12457: if (ref($changes{'spares'}) eq 'HASH') {
12458: if (keys(%{$changes{'spares'}}) > 0) {
12459: $savespares = 1;
12460: }
12461: }
12462: } else {
12463: $savespares = 1;
12464: }
1.160.6.61 raeburn 12465: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12466: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12467: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12468: $changes{'offloadnow'} = 1;
12469: last;
12470: }
12471: }
12472: unless ($changes{'offloadnow'}) {
12473: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12474: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12475: $changes{'offloadnow'} = 1;
12476: last;
12477: }
12478: }
12479: }
12480: } elsif (@okoffload) {
12481: $changes{'offloadnow'} = 1;
12482: }
12483: } elsif (@okoffload) {
12484: $changes{'offloadnow'} = 1;
1.145 raeburn 12485: }
1.147 raeburn 12486: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12487: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12488: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12489: $dom);
12490: if ($putresult eq 'ok') {
12491: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12492: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12493: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12494: }
12495: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12496: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12497: }
1.160.6.61 raeburn 12498: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12499: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12500: }
1.137 raeburn 12501: }
12502: my $cachetime = 24*60*60;
12503: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 12504: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 12505: if (ref($lastactref) eq 'HASH') {
12506: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 12507: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 12508: }
1.147 raeburn 12509: if (keys(%changes) > 0) {
12510: my %lt = &usersession_titles();
12511: $resulttext = &mt('Changes made:').'<ul>';
12512: foreach my $prefix (@prefixes) {
12513: if (ref($changes{$prefix}) eq 'HASH') {
12514: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12515: if ($prefix eq 'spares') {
12516: if (ref($changes{$prefix}) eq 'HASH') {
12517: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12518: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12519: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 12520: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12521: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12522: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12523: foreach my $type (@{$types{$prefix}}) {
12524: if ($changes{$prefix}{$lonhost}{$type}) {
12525: my $offloadto = &mt('None');
12526: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12527: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12528: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12529: }
1.145 raeburn 12530: }
1.147 raeburn 12531: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12532: }
1.137 raeburn 12533: }
12534: }
1.147 raeburn 12535: $resulttext .= '</li>';
1.137 raeburn 12536: }
12537: }
1.147 raeburn 12538: } else {
12539: foreach my $type (@{$types{$prefix}}) {
12540: if (defined($changes{$prefix}{$type})) {
12541: my $newvalue;
12542: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12543: if (ref($defaultshash{'usersessions'}{$prefix})) {
12544: if ($type eq 'version') {
12545: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12546: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12547: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12548: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12549: }
1.145 raeburn 12550: }
12551: }
12552: }
1.147 raeburn 12553: if ($newvalue eq '') {
12554: if ($type eq 'version') {
12555: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12556: } else {
12557: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12558: }
1.145 raeburn 12559: } else {
1.147 raeburn 12560: if ($type eq 'version') {
12561: $newvalue .= ' '.&mt('(or later)');
12562: }
12563: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12564: }
1.137 raeburn 12565: }
12566: }
12567: }
1.147 raeburn 12568: $resulttext .= '</ul>';
1.137 raeburn 12569: }
12570: }
1.160.6.61 raeburn 12571: if ($changes{'offloadnow'}) {
12572: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12573: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12574: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12575: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12576: $resulttext .= '<li>'.$lonhost.'</li>';
12577: }
12578: $resulttext .= '</ul>';
12579: } else {
12580: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12581: }
12582: } else {
12583: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12584: }
12585: }
1.147 raeburn 12586: $resulttext .= '</ul>';
12587: } else {
12588: $resulttext = $nochgmsg;
1.137 raeburn 12589: }
12590: } else {
12591: $resulttext = '<span class="LC_error">'.
12592: &mt('An error occurred: [_1]',$putresult).'</span>';
12593: }
12594: } else {
1.147 raeburn 12595: $resulttext = $nochgmsg;
1.137 raeburn 12596: }
12597: return $resulttext;
12598: }
12599:
1.150 raeburn 12600: sub modify_loadbalancing {
12601: my ($dom,%domconfig) = @_;
12602: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12603: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12604: my ($othertitle,$usertypes,$types) =
12605: &Apache::loncommon::sorted_inst_types($dom);
12606: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 12607: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12608: my @sparestypes = ('primary','default');
12609: my %typetitles = &sparestype_titles();
12610: my $resulttext;
1.160.6.7 raeburn 12611: my (%currbalancer,%currtargets,%currrules,%existing);
12612: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12613: %existing = %{$domconfig{'loadbalancing'}};
12614: }
12615: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12616: \%currtargets,\%currrules);
12617: my ($saveloadbalancing,%defaultshash,%changes);
12618: my ($alltypes,$othertypes,$titles) =
12619: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12620: my %ruletitles = &offloadtype_text();
12621: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12622: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12623: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12624: if ($balancer eq '') {
12625: next;
12626: }
12627: if (!exists($servers{$balancer})) {
12628: if (exists($currbalancer{$balancer})) {
12629: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 12630: }
1.160.6.7 raeburn 12631: next;
12632: }
12633: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12634: push(@{$changes{'delete'}},$balancer);
12635: next;
12636: }
12637: if (!exists($currbalancer{$balancer})) {
12638: push(@{$changes{'add'}},$balancer);
12639: }
12640: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12641: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12642: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12643: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12644: $saveloadbalancing = 1;
12645: }
12646: foreach my $sparetype (@sparestypes) {
12647: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12648: my @offloadto;
12649: foreach my $target (@targets) {
12650: if (($servers{$target}) && ($target ne $balancer)) {
12651: if ($sparetype eq 'default') {
12652: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12653: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 12654: }
12655: }
1.160.6.7 raeburn 12656: unless(grep(/^\Q$target\E$/,@offloadto)) {
12657: push(@offloadto,$target);
12658: }
1.150 raeburn 12659: }
12660: }
1.160.6.76 raeburn 12661: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
12662: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
12663: push(@offloadto,$balancer);
12664: }
12665: }
12666: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 12667: }
1.160.6.7 raeburn 12668: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 12669: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 12670: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12671: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 12672: if (@targetdiffs > 0) {
1.160.6.7 raeburn 12673: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12674: }
1.160.6.7 raeburn 12675: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12676: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12677: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12678: }
12679: }
12680: }
12681: } else {
1.160.6.7 raeburn 12682: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
12683: foreach my $sparetype (@sparestypes) {
12684: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12685: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12686: $changes{'curr'}{$balancer}{'targets'} = 1;
12687: }
1.150 raeburn 12688: }
12689: }
1.160.6.7 raeburn 12690: }
1.150 raeburn 12691: }
12692: my $ishomedom;
1.160.6.7 raeburn 12693: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12694: $ishomedom = 1;
1.150 raeburn 12695: }
12696: if (ref($alltypes) eq 'ARRAY') {
12697: foreach my $type (@{$alltypes}) {
12698: my $rule;
1.160.6.7 raeburn 12699: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 12700: (!$ishomedom)) {
1.160.6.7 raeburn 12701: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12702: }
12703: if ($rule eq 'specific') {
1.160.6.55 raeburn 12704: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12705: if (exists($servers{$specifiedhost})) {
12706: $rule = $specifiedhost;
12707: }
1.150 raeburn 12708: }
1.160.6.7 raeburn 12709: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12710: if (ref($currrules{$balancer}) eq 'HASH') {
12711: if ($rule ne $currrules{$balancer}{$type}) {
12712: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12713: }
12714: } elsif ($rule ne '') {
1.160.6.7 raeburn 12715: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12716: }
12717: }
12718: }
1.160.6.7 raeburn 12719: }
12720: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12721: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12722: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12723: $defaultshash{'loadbalancing'} = {};
12724: }
12725: my $putresult = &Apache::lonnet::put_dom('configuration',
12726: \%defaultshash,$dom);
12727: if ($putresult eq 'ok') {
12728: if (keys(%changes) > 0) {
1.160.6.54 raeburn 12729: my %toupdate;
1.160.6.7 raeburn 12730: if (ref($changes{'delete'}) eq 'ARRAY') {
12731: foreach my $balancer (sort(@{$changes{'delete'}})) {
12732: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 12733: $toupdate{$balancer} = 1;
1.150 raeburn 12734: }
1.160.6.7 raeburn 12735: }
12736: if (ref($changes{'add'}) eq 'ARRAY') {
12737: foreach my $balancer (sort(@{$changes{'add'}})) {
12738: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 12739: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12740: }
12741: }
12742: if (ref($changes{'curr'}) eq 'HASH') {
12743: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 12744: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12745: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12746: if ($changes{'curr'}{$balancer}{'targets'}) {
12747: my %offloadstr;
12748: foreach my $sparetype (@sparestypes) {
12749: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12750: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12751: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12752: }
12753: }
1.150 raeburn 12754: }
1.160.6.7 raeburn 12755: if (keys(%offloadstr) == 0) {
12756: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 12757: } else {
1.160.6.7 raeburn 12758: my $showoffload;
12759: foreach my $sparetype (@sparestypes) {
12760: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12761: if (defined($offloadstr{$sparetype})) {
12762: $showoffload .= $offloadstr{$sparetype};
12763: } else {
12764: $showoffload .= &mt('None');
12765: }
12766: $showoffload .= (' 'x3);
12767: }
12768: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 12769: }
12770: }
12771: }
1.160.6.7 raeburn 12772: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12773: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12774: foreach my $type (@{$alltypes}) {
12775: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12776: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12777: my $balancetext;
12778: if ($rule eq '') {
12779: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 12780: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 12781: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12782: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 12783: foreach my $sparetype (@sparestypes) {
12784: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12785: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12786: }
12787: }
1.160.6.55 raeburn 12788: foreach my $item (@{$alltypes}) {
12789: next if ($item =~ /^_LC_ipchange/);
12790: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
12791: if ($hasrule eq 'homeserver') {
12792: map { $toupdate{$_} = 1; } (keys(%libraryservers));
12793: } else {
12794: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
12795: if ($servers{$hasrule}) {
12796: $toupdate{$hasrule} = 1;
12797: }
12798: }
12799: }
12800: }
12801: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
12802: $balancetext = $ruletitles{$rule};
12803: } else {
12804: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12805: $balancetext = $ruletitles{'particular'}.' '.$receiver;
12806: if ($receiver) {
12807: $toupdate{$receiver};
12808: }
12809: }
12810: } else {
12811: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 12812: }
1.160.6.7 raeburn 12813: } else {
12814: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
12815: }
1.160.6.26 raeburn 12816: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 12817: }
12818: }
12819: }
12820: }
1.160.6.54 raeburn 12821: if (keys(%toupdate)) {
12822: my %thismachine;
12823: my $updatedhere;
12824: my $cachetime = 60*60*24;
12825: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12826: foreach my $lonhost (keys(%toupdate)) {
12827: if ($thismachine{$lonhost}) {
12828: unless ($updatedhere) {
12829: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
12830: $defaultshash{'loadbalancing'},
12831: $cachetime);
12832: $updatedhere = 1;
12833: }
12834: } else {
12835: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
12836: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
12837: }
12838: }
12839: }
1.150 raeburn 12840: }
1.160.6.7 raeburn 12841: }
12842: if ($resulttext ne '') {
12843: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 12844: } else {
12845: $resulttext = $nochgmsg;
12846: }
12847: } else {
1.160.6.7 raeburn 12848: $resulttext = $nochgmsg;
1.150 raeburn 12849: }
12850: } else {
1.160.6.7 raeburn 12851: $resulttext = '<span class="LC_error">'.
12852: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 12853: }
12854: } else {
1.160.6.7 raeburn 12855: $resulttext = $nochgmsg;
1.150 raeburn 12856: }
12857: return $resulttext;
12858: }
12859:
1.48 raeburn 12860: sub recurse_check {
12861: my ($chkcats,$categories,$depth,$name) = @_;
12862: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
12863: my $chg = 0;
12864: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
12865: my $category = $chkcats->[$depth]{$name}[$j];
12866: my $item;
12867: if ($category eq '') {
12868: $chg ++;
12869: } else {
12870: my $deeper = $depth + 1;
12871: $item = &escape($category).':'.&escape($name).':'.$depth;
12872: if ($chg) {
12873: $categories->{$item} -= $chg;
12874: }
12875: &recurse_check($chkcats,$categories,$deeper,$category);
12876: $deeper --;
12877: }
12878: }
12879: }
12880: return;
12881: }
12882:
12883: sub recurse_cat_deletes {
12884: my ($item,$coursecategories,$deletions) = @_;
12885: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12886: my $subdepth = $depth + 1;
12887: if (ref($coursecategories) eq 'HASH') {
12888: foreach my $subitem (keys(%{$coursecategories})) {
12889: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
12890: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
12891: delete($coursecategories->{$subitem});
12892: $deletions->{$subitem} = 1;
12893: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 12894: }
1.48 raeburn 12895: }
12896: }
12897: return;
12898: }
12899:
1.125 raeburn 12900: sub active_dc_picker {
1.160.6.16 raeburn 12901: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 12902: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 12903: my @domcoord = keys(%domcoords);
12904: if (keys(%currhash)) {
12905: foreach my $dc (keys(%currhash)) {
12906: unless (exists($domcoords{$dc})) {
12907: push(@domcoord,$dc);
12908: }
12909: }
12910: }
12911: @domcoord = sort(@domcoord);
12912: my $numdcs = scalar(@domcoord);
12913: my $rows = 0;
12914: my $table;
1.125 raeburn 12915: if ($numdcs > 1) {
1.160.6.16 raeburn 12916: $table = '<table>';
12917: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 12918: my $rem = $i%($numinrow);
12919: if ($rem == 0) {
12920: if ($i > 0) {
1.160.6.16 raeburn 12921: $table .= '</tr>';
1.125 raeburn 12922: }
1.160.6.16 raeburn 12923: $table .= '<tr>';
12924: $rows ++;
1.125 raeburn 12925: }
1.160.6.16 raeburn 12926: my $check = '';
12927: if ($inputtype eq 'radio') {
12928: if (keys(%currhash) == 0) {
12929: if (!$i) {
12930: $check = ' checked="checked"';
12931: }
12932: } elsif (exists($currhash{$domcoord[$i]})) {
12933: $check = ' checked="checked"';
12934: }
12935: } else {
12936: if (exists($currhash{$domcoord[$i]})) {
12937: $check = ' checked="checked"';
1.125 raeburn 12938: }
12939: }
1.160.6.16 raeburn 12940: if ($i == @domcoord - 1) {
1.125 raeburn 12941: my $colsleft = $numinrow - $rem;
12942: if ($colsleft > 1) {
1.160.6.16 raeburn 12943: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 12944: } else {
1.160.6.16 raeburn 12945: $table .= '<td class="LC_left_item">';
1.125 raeburn 12946: }
12947: } else {
1.160.6.16 raeburn 12948: $table .= '<td class="LC_left_item">';
12949: }
12950: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
12951: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
12952: $table .= '<span class="LC_nobreak"><label>'.
12953: '<input type="'.$inputtype.'" name="'.$name.'"'.
12954: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
12955: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 12956: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 12957: }
1.160.6.33 raeburn 12958: $table .= '</label></span></td>';
1.125 raeburn 12959: }
1.160.6.16 raeburn 12960: $table .= '</tr></table>';
12961: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 12962: my ($dcname,$dcdom) = split(':',$domcoord[0]);
12963: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 12964: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 12965: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 12966: if ($user ne $dcname.':'.$dcdom) {
12967: $table .= ' ('.$dcname.':'.$dcdom.')';
12968: }
1.160.6.16 raeburn 12969: } else {
12970: my $check;
12971: if (exists($currhash{$domcoord[0]})) {
12972: $check = ' checked="checked"';
12973: }
1.160.6.50 raeburn 12974: $table = '<span class="LC_nobreak"><label>'.
12975: '<input type="checkbox" name="'.$name.'" '.
12976: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 12977: if ($user ne $dcname.':'.$dcdom) {
12978: $table .= ' ('.$dcname.':'.$dcdom.')';
12979: }
12980: $table .= '</label></span>';
1.160.6.16 raeburn 12981: $rows ++;
12982: }
1.125 raeburn 12983: }
1.160.6.16 raeburn 12984: return ($numdcs,$table,$rows);
1.125 raeburn 12985: }
12986:
1.137 raeburn 12987: sub usersession_titles {
12988: return &Apache::lonlocal::texthash(
12989: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
12990: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 12991: spares => 'Servers offloaded to, when busy',
1.137 raeburn 12992: version => 'LON-CAPA version requirement',
1.138 raeburn 12993: excludedomain => 'Allow all, but exclude specific domains',
12994: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 12995: primary => 'Primary (checked first)',
1.154 raeburn 12996: default => 'Default',
1.137 raeburn 12997: );
12998: }
12999:
1.152 raeburn 13000: sub id_for_thisdom {
13001: my (%servers) = @_;
13002: my %altids;
13003: foreach my $server (keys(%servers)) {
13004: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
13005: if ($serverhome ne $server) {
13006: $altids{$serverhome} = $server;
13007: }
13008: }
13009: return %altids;
13010: }
13011:
1.150 raeburn 13012: sub count_servers {
13013: my ($currbalancer,%servers) = @_;
13014: my (@spares,$numspares);
13015: foreach my $lonhost (sort(keys(%servers))) {
13016: next if ($currbalancer eq $lonhost);
13017: push(@spares,$lonhost);
13018: }
13019: if ($currbalancer) {
13020: $numspares = scalar(@spares);
13021: } else {
13022: $numspares = scalar(@spares) - 1;
13023: }
13024: return ($numspares,@spares);
13025: }
13026:
13027: sub lonbalance_targets_js {
1.160.6.7 raeburn 13028: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13029: my $select = &mt('Select');
13030: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13031: if (ref($servers) eq 'HASH') {
13032: $alltargets = join("','",sort(keys(%{$servers})));
13033: my @homedoms;
13034: foreach my $server (sort(keys(%{$servers}))) {
13035: if (&Apache::lonnet::host_domain($server) eq $dom) {
13036: push(@homedoms,'1');
13037: } else {
13038: push(@homedoms,'0');
13039: }
13040: }
13041: $allishome = join("','",@homedoms);
13042: }
13043: if (ref($types) eq 'ARRAY') {
13044: if (@{$types} > 0) {
13045: @alltypes = @{$types};
13046: }
13047: }
13048: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13049: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 13050: my (%currbalancer,%currtargets,%currrules,%existing);
13051: if (ref($settings) eq 'HASH') {
13052: %existing = %{$settings};
13053: }
13054: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13055: \%currtargets,\%currrules);
13056: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13057: return <<"END";
13058:
13059: <script type="text/javascript">
13060: // <![CDATA[
13061:
1.160.6.7 raeburn 13062: currBalancers = new Array('$balancers');
13063:
13064: function toggleTargets(balnum) {
13065: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13066: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13067: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13068: var prevbalancer = prevhostitem.value;
13069: var baltotal = document.getElementById('loadbalancing_total').value;
13070: prevhostitem.value = balancer;
13071: if (prevbalancer != '') {
13072: var prevIdx = currBalancers.indexOf(prevbalancer);
13073: if (prevIdx != -1) {
13074: currBalancers.splice(prevIdx,1);
13075: }
13076: }
1.150 raeburn 13077: if (balancer == '') {
1.160.6.7 raeburn 13078: hideSpares(balnum);
1.150 raeburn 13079: } else {
1.160.6.7 raeburn 13080: var currIdx = currBalancers.indexOf(balancer);
13081: if (currIdx == -1) {
13082: currBalancers.push(balancer);
13083: }
1.150 raeburn 13084: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 13085: var ishomedom = homedoms[lonhostitem.selectedIndex];
13086: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13087: }
1.160.6.7 raeburn 13088: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13089: return;
13090: }
13091:
1.160.6.7 raeburn 13092: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13093: var alltargets = new Array('$alltargets');
13094: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13095: var offloadtypes = new Array('primary','default');
13096:
1.160.6.7 raeburn 13097: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13098: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13099:
1.151 raeburn 13100: for (var i=0; i<offloadtypes.length; i++) {
13101: var count = 0;
13102: for (var j=0; j<alltargets.length; j++) {
13103: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 13104: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13105: item.value = alltargets[j];
13106: item.style.textAlign='left';
13107: item.style.textFace='normal';
13108: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13109: if (currBalancers.indexOf(alltargets[j]) == -1) {
13110: item.disabled = '';
13111: } else {
13112: item.disabled = 'disabled';
13113: item.checked = false;
13114: }
1.151 raeburn 13115: count ++;
13116: }
1.150 raeburn 13117: }
13118: }
1.151 raeburn 13119: for (var k=0; k<insttypes.length; k++) {
13120: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13121: if (ishomedom == 1) {
1.160.6.7 raeburn 13122: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13123: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13124: } else {
1.160.6.7 raeburn 13125: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13126: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13127: }
13128: } else {
1.160.6.7 raeburn 13129: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13130: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13131: }
1.151 raeburn 13132: if ((insttypes[k] != '_LC_external') &&
13133: ((insttypes[k] != '_LC_internetdom') ||
13134: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 13135: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13136: item.options.length = 0;
13137: item.options[0] = new Option("","",true,true);
13138: var idx = 0;
1.151 raeburn 13139: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 13140: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13141: idx ++;
13142: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13143: }
13144: }
13145: }
13146: }
13147: return;
13148: }
13149:
1.160.6.7 raeburn 13150: function hideSpares(balnum) {
1.150 raeburn 13151: var alltargets = new Array('$alltargets');
13152: var insttypes = new Array('$allinsttypes');
13153: var offloadtypes = new Array('primary','default');
13154:
1.160.6.7 raeburn 13155: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13156: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13157:
13158: var total = alltargets.length - 1;
13159: for (var i=0; i<offloadtypes; i++) {
13160: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 13161: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13162: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13163: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13164: }
1.150 raeburn 13165: }
13166: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 13167: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13168: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13169: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 13170: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13171: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13172: }
13173: }
13174: return;
13175: }
13176:
1.160.6.7 raeburn 13177: function checkOffloads(item,balnum,type) {
1.150 raeburn 13178: var alltargets = new Array('$alltargets');
13179: var offloadtypes = new Array('primary','default');
13180: if (item.checked) {
13181: var total = alltargets.length - 1;
13182: var other;
13183: if (type == offloadtypes[0]) {
1.151 raeburn 13184: other = offloadtypes[1];
1.150 raeburn 13185: } else {
1.151 raeburn 13186: other = offloadtypes[0];
1.150 raeburn 13187: }
13188: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 13189: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13190: if (server == item.value) {
1.160.6.7 raeburn 13191: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13192: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13193: }
13194: }
13195: }
13196: }
13197: return;
13198: }
13199:
1.160.6.7 raeburn 13200: function singleServerToggle(balnum,type) {
13201: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13202: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 13203: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13204: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13205:
13206: } else {
1.160.6.7 raeburn 13207: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13208: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13209: }
13210: return;
13211: }
13212:
1.160.6.7 raeburn 13213: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13214: if (type == '_LC_external') {
1.160.6.26 raeburn 13215: return;
1.150 raeburn 13216: }
1.160.6.7 raeburn 13217: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13218: for (var i=0; i<typesRules.length; i++) {
13219: if (formname.elements[typesRules[i]].checked) {
13220: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 13221: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13222: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13223: } else {
1.160.6.7 raeburn 13224: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13225: }
13226: }
13227: }
13228: return;
13229: }
13230:
13231: function balancerDeleteChange(balnum) {
13232: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13233: var baltotal = document.getElementById('loadbalancing_total').value;
13234: var addtarget;
13235: var removetarget;
13236: var action = 'delete';
13237: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13238: var lonhost = hostitem.value;
13239: var currIdx = currBalancers.indexOf(lonhost);
13240: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13241: if (currIdx != -1) {
13242: currBalancers.splice(currIdx,1);
13243: }
13244: addtarget = lonhost;
13245: } else {
13246: if (currIdx == -1) {
13247: currBalancers.push(lonhost);
13248: }
13249: removetarget = lonhost;
13250: action = 'undelete';
13251: }
13252: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13253: }
13254: return;
13255: }
13256:
13257: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13258: if (baltotal > 1) {
13259: var offloadtypes = new Array('primary','default');
13260: var alltargets = new Array('$alltargets');
13261: var insttypes = new Array('$allinsttypes');
13262: for (var i=0; i<baltotal; i++) {
13263: if (i != balnum) {
13264: for (var j=0; j<offloadtypes.length; j++) {
13265: var total = alltargets.length - 1;
13266: for (var k=0; k<total; k++) {
13267: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13268: var server = serveritem.value;
13269: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13270: if (server == addtarget) {
13271: serveritem.disabled = '';
13272: }
13273: }
13274: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13275: if (server == removetarget) {
13276: serveritem.disabled = 'disabled';
13277: serveritem.checked = false;
13278: }
13279: }
13280: }
13281: }
13282: for (var j=0; j<insttypes.length; j++) {
13283: if (insttypes[j] != '_LC_external') {
13284: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13285: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13286: var currSel = singleserver.selectedIndex;
13287: var currVal = singleserver.options[currSel].value;
13288: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13289: var numoptions = singleserver.options.length;
13290: var needsnew = 1;
13291: for (var k=0; k<numoptions; k++) {
13292: if (singleserver.options[k] == addtarget) {
13293: needsnew = 0;
13294: break;
13295: }
13296: }
13297: if (needsnew == 1) {
13298: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13299: }
13300: }
13301: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13302: singleserver.options.length = 0;
13303: if ((currVal) && (currVal != removetarget)) {
13304: singleserver.options[0] = new Option("","",false,false);
13305: } else {
13306: singleserver.options[0] = new Option("","",true,true);
13307: }
13308: var idx = 0;
13309: for (var m=0; m<alltargets.length; m++) {
13310: if (currBalancers.indexOf(alltargets[m]) == -1) {
13311: idx ++;
13312: if (currVal == alltargets[m]) {
13313: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13314: } else {
13315: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13316: }
13317: }
13318: }
13319: }
13320: }
13321: }
13322: }
1.150 raeburn 13323: }
13324: }
13325: }
13326: return;
13327: }
13328:
1.152 raeburn 13329: // ]]>
13330: </script>
13331:
13332: END
13333: }
13334:
13335: sub new_spares_js {
13336: my @sparestypes = ('primary','default');
13337: my $types = join("','",@sparestypes);
13338: my $select = &mt('Select');
13339: return <<"END";
13340:
13341: <script type="text/javascript">
13342: // <![CDATA[
13343:
13344: function updateNewSpares(formname,lonhost) {
13345: var types = new Array('$types');
13346: var include = new Array();
13347: var exclude = new Array();
13348: for (var i=0; i<types.length; i++) {
13349: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13350: for (var j=0; j<spareboxes.length; j++) {
13351: if (formname.elements[spareboxes[j]].checked) {
13352: exclude.push(formname.elements[spareboxes[j]].value);
13353: } else {
13354: include.push(formname.elements[spareboxes[j]].value);
13355: }
13356: }
13357: }
13358: for (var i=0; i<types.length; i++) {
13359: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13360: var selIdx = newSpare.selectedIndex;
13361: var currnew = newSpare.options[selIdx].value;
13362: var okSpares = new Array();
13363: for (var j=0; j<newSpare.options.length; j++) {
13364: var possible = newSpare.options[j].value;
13365: if (possible != '') {
13366: if (exclude.indexOf(possible) == -1) {
13367: okSpares.push(possible);
13368: } else {
13369: if (currnew == possible) {
13370: selIdx = 0;
13371: }
13372: }
13373: }
13374: }
13375: for (var k=0; k<include.length; k++) {
13376: if (okSpares.indexOf(include[k]) == -1) {
13377: okSpares.push(include[k]);
13378: }
13379: }
13380: okSpares.sort();
13381: newSpare.options.length = 0;
13382: if (selIdx == 0) {
13383: newSpare.options[0] = new Option("$select","",true,true);
13384: } else {
13385: newSpare.options[0] = new Option("$select","",false,false);
13386: }
13387: for (var m=0; m<okSpares.length; m++) {
13388: var idx = m+1;
13389: var selThis = 0;
13390: if (selIdx != 0) {
13391: if (okSpares[m] == currnew) {
13392: selThis = 1;
13393: }
13394: }
13395: if (selThis == 1) {
13396: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13397: } else {
13398: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13399: }
13400: }
13401: }
13402: return;
13403: }
13404:
13405: function checkNewSpares(lonhost,type) {
13406: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13407: var chosen = newSpare.options[newSpare.selectedIndex].value;
13408: if (chosen != '') {
13409: var othertype;
13410: var othernewSpare;
13411: if (type == 'primary') {
13412: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13413: }
13414: if (type == 'default') {
13415: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13416: }
13417: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13418: othernewSpare.selectedIndex = 0;
13419: }
13420: }
13421: return;
13422: }
13423:
13424: // ]]>
13425: </script>
13426:
13427: END
13428:
13429: }
13430:
13431: sub common_domprefs_js {
13432: return <<"END";
13433:
13434: <script type="text/javascript">
13435: // <![CDATA[
13436:
1.150 raeburn 13437: function getIndicesByName(formname,item) {
1.152 raeburn 13438: var group = new Array();
1.150 raeburn 13439: for (var i=0;i<formname.elements.length;i++) {
13440: if (formname.elements[i].name == item) {
1.152 raeburn 13441: group.push(formname.elements[i].id);
1.150 raeburn 13442: }
13443: }
1.152 raeburn 13444: return group;
1.150 raeburn 13445: }
13446:
13447: // ]]>
13448: </script>
13449:
13450: END
1.152 raeburn 13451:
1.150 raeburn 13452: }
13453:
1.160.6.5 raeburn 13454: sub recaptcha_js {
13455: my %lt = &captcha_phrases();
13456: return <<"END";
13457:
13458: <script type="text/javascript">
13459: // <![CDATA[
13460:
13461: function updateCaptcha(caller,context) {
13462: var privitem;
13463: var pubitem;
13464: var privtext;
13465: var pubtext;
1.160.6.69 raeburn 13466: var versionitem;
13467: var versiontext;
1.160.6.5 raeburn 13468: if (document.getElementById(context+'_recaptchapub')) {
13469: pubitem = document.getElementById(context+'_recaptchapub');
13470: } else {
13471: return;
13472: }
13473: if (document.getElementById(context+'_recaptchapriv')) {
13474: privitem = document.getElementById(context+'_recaptchapriv');
13475: } else {
13476: return;
13477: }
13478: if (document.getElementById(context+'_recaptchapubtxt')) {
13479: pubtext = document.getElementById(context+'_recaptchapubtxt');
13480: } else {
13481: return;
13482: }
13483: if (document.getElementById(context+'_recaptchaprivtxt')) {
13484: privtext = document.getElementById(context+'_recaptchaprivtxt');
13485: } else {
13486: return;
13487: }
1.160.6.69 raeburn 13488: if (document.getElementById(context+'_recaptchaversion')) {
13489: versionitem = document.getElementById(context+'_recaptchaversion');
13490: } else {
13491: return;
13492: }
13493: if (document.getElementById(context+'_recaptchavertxt')) {
13494: versiontext = document.getElementById(context+'_recaptchavertxt');
13495: } else {
13496: return;
13497: }
1.160.6.5 raeburn 13498: if (caller.checked) {
13499: if (caller.value == 'recaptcha') {
13500: pubitem.type = 'text';
13501: privitem.type = 'text';
13502: pubitem.size = '40';
13503: privitem.size = '40';
13504: pubtext.innerHTML = "$lt{'pub'}";
13505: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 13506: versionitem.type = 'text';
13507: versionitem.size = '3';
13508: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 13509: } else {
13510: pubitem.type = 'hidden';
13511: privitem.type = 'hidden';
1.160.6.69 raeburn 13512: versionitem.type = 'hidden';
1.160.6.5 raeburn 13513: pubtext.innerHTML = '';
13514: privtext.innerHTML = '';
1.160.6.69 raeburn 13515: versiontext.innerHTML = '';
1.160.6.5 raeburn 13516: }
13517: }
13518: return;
13519: }
13520:
13521: // ]]>
13522: </script>
13523:
13524: END
13525:
13526: }
13527:
1.160.6.40 raeburn 13528: sub toggle_display_js {
1.160.6.16 raeburn 13529: return <<"END";
13530:
13531: <script type="text/javascript">
13532: // <![CDATA[
13533:
1.160.6.40 raeburn 13534: function toggleDisplay(domForm,caller) {
13535: if (document.getElementById(caller)) {
13536: var divitem = document.getElementById(caller);
13537: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 13538: var checkval = 1;
13539: var dispval = 'block';
1.160.6.40 raeburn 13540: if (caller == 'emailoptions') {
13541: optionsElement = domForm.cancreate_email;
13542: }
1.160.6.57 raeburn 13543: if (caller == 'studentsubmission') {
13544: optionsElement = domForm.postsubmit;
13545: }
1.160.6.64 raeburn 13546: if (caller == 'cloneinstcode') {
13547: optionsElement = domForm.canclone;
13548: checkval = 'instcode';
13549: }
1.160.6.40 raeburn 13550: if (optionsElement.length) {
1.160.6.16 raeburn 13551: var currval;
1.160.6.40 raeburn 13552: for (var i=0; i<optionsElement.length; i++) {
13553: if (optionsElement[i].checked) {
13554: currval = optionsElement[i].value;
1.160.6.16 raeburn 13555: }
13556: }
1.160.6.64 raeburn 13557: if (currval == checkval) {
13558: divitem.style.display = dispval;
1.160.6.16 raeburn 13559: } else {
1.160.6.40 raeburn 13560: divitem.style.display = 'none';
1.160.6.16 raeburn 13561: }
13562: }
13563: }
13564: return;
13565: }
13566:
13567: // ]]>
13568: </script>
13569:
13570: END
13571:
13572: }
13573:
1.160.6.5 raeburn 13574: sub captcha_phrases {
13575: return &Apache::lonlocal::texthash (
13576: priv => 'Private key',
13577: pub => 'Public key',
13578: original => 'original (CAPTCHA)',
13579: recaptcha => 'successor (ReCAPTCHA)',
13580: notused => 'unused',
1.160.6.69 raeburn 13581: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 13582: );
13583: }
13584:
1.160.6.24 raeburn 13585: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 13586: my ($dom,$cachekeys) = @_;
13587: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 13588: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13589: my %thismachine;
13590: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.81 raeburn 13591: my @posscached = ('domainconfig','domdefaults','usersessions','directorysrch');
1.160.6.61 raeburn 13592: if (keys(%servers)) {
1.160.6.24 raeburn 13593: foreach my $server (keys(%servers)) {
13594: next if ($thismachine{$server});
1.160.6.27 raeburn 13595: my @cached;
13596: foreach my $name (@posscached) {
13597: if ($cachekeys->{$name}) {
13598: push(@cached,&escape($name).':'.&escape($dom));
13599: }
13600: }
13601: if (@cached) {
13602: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13603: }
1.160.6.24 raeburn 13604: }
13605: }
13606: return;
13607: }
13608:
1.3 raeburn 13609: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>