Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.80
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.80! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.79 2017/01/30 19:18:33 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') {
623: $output = &modify_directorysrch($dom,%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: }
1281: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
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.30 raeburn 1441: $datatable .= '<td>'.&mt('Default in use:').' <span id="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.'" /> '.
1450: ' </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'}) {
1455: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
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.'" /> '.
1465: ' </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;
1524: system("convert -sample $size $input $output");
1.159 raeburn 1525: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1526: }
1527: }
1.6 raeburn 1528: }
1529: }
1.16 raeburn 1530: }
1.6 raeburn 1531: if ($showfile) {
1.40 raeburn 1532: if ($showfile =~ m{^/(adm|res)/}) {
1533: if ($showfile =~ m{^/res/}) {
1534: my $local_showfile =
1535: &Apache::lonnet::filelocation('',$showfile);
1536: &Apache::lonnet::repcopy($local_showfile);
1537: }
1538: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1539: }
1540: if ($imgfile) {
1541: if ($imgfile =~ m{^/(adm|res)/}) {
1542: if ($imgfile =~ m{^/res/}) {
1543: my $local_imgfile =
1544: &Apache::lonnet::filelocation('',$imgfile);
1545: &Apache::lonnet::repcopy($local_imgfile);
1546: }
1547: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1548: } else {
1549: $fullsize = $imgfile;
1550: }
1551: }
1.41 raeburn 1552: $datatable .= '<td>';
1553: if ($img eq 'login') {
1.135 bisitz 1554: $datatable .= $login_hdr_pick;
1555: }
1.41 raeburn 1556: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1557: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1558: } else {
1.160.6.22 raeburn 1559: $datatable .= '<td> </td><td class="LC_left_item">'.
1560: &mt('Upload:').'<br />';
1.6 raeburn 1561: }
1562: } else {
1.160.6.22 raeburn 1563: $datatable .= '<td> </td><td class="LC_left_item">'.
1564: &mt('Upload:').'<br />';
1.6 raeburn 1565: }
1.9 raeburn 1566: if ($switchserver) {
1567: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1568: } else {
1.135 bisitz 1569: if ($img ne 'login') { # suppress file selection for Log-in header
1570: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1571: }
1.9 raeburn 1572: }
1573: $datatable .= '</td></tr>';
1.6 raeburn 1574: }
1575: $itemcount ++;
1576: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1577: $datatable .= '<tr'.$css_class.'>'.
1578: '<td>'.$choices->{'bgs'}.'</td>';
1579: my $bgs_def;
1580: foreach my $item (@{$bgs}) {
1581: if (!$is_custom->{$item}) {
1.70 raeburn 1582: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1583: }
1584: }
1585: if ($bgs_def) {
1.8 raeburn 1586: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1587: } else {
1588: $datatable .= '<td> </td>';
1589: }
1590: $datatable .= '<td class="LC_right_item">'.
1591: '<table border="0"><tr>';
1.160.6.13 raeburn 1592:
1.6 raeburn 1593: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1594: $datatable .= '<td align="center">'.$choices->{$item};
1595: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1596: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1597: $datatable .= ' ';
1.6 raeburn 1598: }
1.160.6.9 raeburn 1599: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1600: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1601: }
1602: $datatable .= '</tr></table></td></tr>';
1603: $itemcount ++;
1604: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1605: $datatable .= '<tr'.$css_class.'>'.
1606: '<td>'.$choices->{'links'}.'</td>';
1607: my $links_def;
1608: foreach my $item (@{$links}) {
1609: if (!$is_custom->{$item}) {
1.30 raeburn 1610: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1611: }
1612: }
1613: if ($links_def) {
1.8 raeburn 1614: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1615: } else {
1616: $datatable .= '<td> </td>';
1617: }
1618: $datatable .= '<td class="LC_right_item">'.
1619: '<table border="0"><tr>';
1620: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1621: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1622: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1623: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1624: $datatable.=' ';
1.6 raeburn 1625: }
1.160.6.9 raeburn 1626: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1627: '" /></td>';
1628: }
1.30 raeburn 1629: $$rowtotal += $itemcount;
1.3 raeburn 1630: return $datatable;
1631: }
1632:
1.70 raeburn 1633: sub logo_display_options {
1634: my ($img,$defaults,$designs) = @_;
1635: my $checkedon;
1636: if (ref($defaults) eq 'HASH') {
1637: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1638: if ($defaults->{'showlogo'}{$img}) {
1639: $checkedon = 'checked="checked" ';
1640: }
1641: }
1642: }
1643: if (ref($designs) eq 'HASH') {
1644: if (ref($designs->{'showlogo'}) eq 'HASH') {
1645: if (defined($designs->{'showlogo'}{$img})) {
1646: if ($designs->{'showlogo'}{$img} == 0) {
1647: $checkedon = '';
1648: } elsif ($designs->{'showlogo'}{$img} == 1) {
1649: $checkedon = 'checked="checked" ';
1650: }
1651: }
1652: }
1653: }
1654: return '<br /><label> <input type="checkbox" name="'.
1655: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1656: &mt('show').'</label>'."\n";
1657: }
1658:
1.41 raeburn 1659: sub login_header_options {
1.135 bisitz 1660: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1661: my $output = '';
1.41 raeburn 1662: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1663: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1664: if (!$is_custom->{'textcol'}) {
1665: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1666: ' ';
1667: }
1668: if (!$is_custom->{'bgcol'}) {
1669: $output .= $choices->{'bgcol'}.': '.
1670: '<span id="css_'.$role.'_font" style="background-color: '.
1671: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1672: }
1673: $output .= '<br />';
1674: }
1675: $output .='<br />';
1676: return $output;
1677: }
1678:
1679: sub login_text_colors {
1.160.6.22 raeburn 1680: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1681: my $color_menu = '<table border="0"><tr>';
1682: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1683: $color_menu .= '<td align="center">'.$choices->{$item};
1684: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1685: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1686: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1687: }
1688: $color_menu .= '</tr></table><br />';
1689: return $color_menu;
1690: }
1691:
1692: sub image_changes {
1693: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1694: my $output;
1.135 bisitz 1695: if ($img eq 'login') {
1696: # suppress image for Log-in header
1697: } elsif (!$is_custom) {
1.70 raeburn 1698: if ($img ne 'domlogo') {
1.41 raeburn 1699: $output .= &mt('Default image:').'<br />';
1700: } else {
1701: $output .= &mt('Default in use:').'<br />';
1702: }
1703: }
1.135 bisitz 1704: if ($img eq 'login') { # suppress image for Log-in header
1705: $output .= '<td>'.$logincolors;
1.41 raeburn 1706: } else {
1.135 bisitz 1707: if ($img_import) {
1708: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1709: }
1710: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1711: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1712: if ($is_custom) {
1713: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1714: '<input type="checkbox" name="'.
1715: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1716: '</label> '.&mt('Replace:').'</span><br />';
1717: } else {
1.160.6.22 raeburn 1718: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1719: }
1.41 raeburn 1720: }
1721: return $output;
1722: }
1723:
1.3 raeburn 1724: sub print_quotas {
1.86 raeburn 1725: my ($dom,$settings,$rowtotal,$action) = @_;
1726: my $context;
1727: if ($action eq 'quotas') {
1728: $context = 'tools';
1729: } else {
1730: $context = $action;
1731: }
1.160.6.20 raeburn 1732: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1733: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1734: my $typecount = 0;
1.101 raeburn 1735: my ($css_class,%titles);
1.86 raeburn 1736: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1737: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1738: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1739: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1740: %titles = &courserequest_titles();
1.160.6.5 raeburn 1741: } elsif ($context eq 'requestauthor') {
1742: @usertools = ('author');
1743: @options = ('norequest','approval','automatic');
1744: %titles = &authorrequest_titles();
1.86 raeburn 1745: } else {
1.160.6.4 raeburn 1746: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1747: %titles = &tool_titles();
1.86 raeburn 1748: }
1.26 raeburn 1749: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1750: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1751: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1752: unless (($context eq 'requestcourses') ||
1753: ($context eq 'requestauthor')) {
1.86 raeburn 1754: if (ref($settings) eq 'HASH') {
1755: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1756: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1757: } else {
1758: $currdefquota = $settings->{$type};
1759: }
1.160.6.20 raeburn 1760: if (ref($settings->{authorquota}) eq 'HASH') {
1761: $currauthorquota = $settings->{authorquota}->{$type};
1762: }
1.78 raeburn 1763: }
1.72 raeburn 1764: }
1.3 raeburn 1765: if (defined($usertypes->{$type})) {
1766: $typecount ++;
1767: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1768: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1769: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1770: '<td class="LC_left_item">';
1.101 raeburn 1771: if ($context eq 'requestcourses') {
1772: $datatable .= '<table><tr>';
1773: }
1774: my %cell;
1.72 raeburn 1775: foreach my $item (@usertools) {
1.101 raeburn 1776: if ($context eq 'requestcourses') {
1777: my ($curroption,$currlimit);
1778: if (ref($settings) eq 'HASH') {
1779: if (ref($settings->{$item}) eq 'HASH') {
1780: $curroption = $settings->{$item}->{$type};
1781: if ($curroption =~ /^autolimit=(\d*)$/) {
1782: $currlimit = $1;
1783: }
1784: }
1785: }
1786: if (!$curroption) {
1787: $curroption = 'norequest';
1788: }
1789: $datatable .= '<th>'.$titles{$item}.'</th>';
1790: foreach my $option (@options) {
1791: my $val = $option;
1792: if ($option eq 'norequest') {
1793: $val = 0;
1794: }
1795: if ($option eq 'validate') {
1796: my $canvalidate = 0;
1797: if (ref($validations{$item}) eq 'HASH') {
1798: if ($validations{$item}{$type}) {
1799: $canvalidate = 1;
1800: }
1801: }
1802: next if (!$canvalidate);
1803: }
1804: my $checked = '';
1805: if ($option eq $curroption) {
1806: $checked = ' checked="checked"';
1807: } elsif ($option eq 'autolimit') {
1808: if ($curroption =~ /^autolimit/) {
1809: $checked = ' checked="checked"';
1810: }
1811: }
1812: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1813: '<input type="radio" name="crsreq_'.$item.
1814: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1815: $titles{$option}.'</label>';
1.101 raeburn 1816: if ($option eq 'autolimit') {
1.127 raeburn 1817: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1818: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1819: 'value="'.$currlimit.'" />';
1.101 raeburn 1820: }
1.127 raeburn 1821: $cell{$item} .= '</span> ';
1.103 raeburn 1822: if ($option eq 'autolimit') {
1.127 raeburn 1823: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1824: }
1.101 raeburn 1825: }
1.160.6.5 raeburn 1826: } elsif ($context eq 'requestauthor') {
1827: my $curroption;
1828: if (ref($settings) eq 'HASH') {
1829: $curroption = $settings->{$type};
1830: }
1831: if (!$curroption) {
1832: $curroption = 'norequest';
1833: }
1834: foreach my $option (@options) {
1835: my $val = $option;
1836: if ($option eq 'norequest') {
1837: $val = 0;
1838: }
1839: my $checked = '';
1840: if ($option eq $curroption) {
1841: $checked = ' checked="checked"';
1842: }
1843: $datatable .= '<span class="LC_nobreak"><label>'.
1844: '<input type="radio" name="authorreq_'.$type.
1845: '" value="'.$val.'"'.$checked.' />'.
1846: $titles{$option}.'</label></span> ';
1847: }
1.101 raeburn 1848: } else {
1849: my $checked = 'checked="checked" ';
1850: if (ref($settings) eq 'HASH') {
1851: if (ref($settings->{$item}) eq 'HASH') {
1852: if ($settings->{$item}->{$type} == 0) {
1853: $checked = '';
1854: } elsif ($settings->{$item}->{$type} == 1) {
1855: $checked = 'checked="checked" ';
1856: }
1.78 raeburn 1857: }
1.72 raeburn 1858: }
1.101 raeburn 1859: $datatable .= '<span class="LC_nobreak"><label>'.
1860: '<input type="checkbox" name="'.$context.'_'.$item.
1861: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1862: '</label></span> ';
1.72 raeburn 1863: }
1.101 raeburn 1864: }
1865: if ($context eq 'requestcourses') {
1866: $datatable .= '</tr><tr>';
1867: foreach my $item (@usertools) {
1.106 raeburn 1868: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1869: }
1870: $datatable .= '</tr></table>';
1.72 raeburn 1871: }
1.86 raeburn 1872: $datatable .= '</td>';
1.160.6.5 raeburn 1873: unless (($context eq 'requestcourses') ||
1874: ($context eq 'requestauthor')) {
1.86 raeburn 1875: $datatable .=
1.160.6.20 raeburn 1876: '<td class="LC_right_item">'.
1877: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1878: '<input type="text" name="quota_'.$type.
1.72 raeburn 1879: '" value="'.$currdefquota.
1.160.6.20 raeburn 1880: '" size="5" /></span>'.(' ' x 2).
1881: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1882: '<input type="text" name="authorquota_'.$type.
1883: '" value="'.$currauthorquota.
1884: '" size="5" /></span></td>';
1.86 raeburn 1885: }
1886: $datatable .= '</tr>';
1.3 raeburn 1887: }
1888: }
1889: }
1.160.6.5 raeburn 1890: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1891: $defaultquota = '20';
1.160.6.20 raeburn 1892: $authorquota = '500';
1.86 raeburn 1893: if (ref($settings) eq 'HASH') {
1894: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1895: $defaultquota = $settings->{'defaultquota'}->{'default'};
1896: } elsif (defined($settings->{'default'})) {
1897: $defaultquota = $settings->{'default'};
1898: }
1.160.6.20 raeburn 1899: if (ref($settings->{'authorquota'}) eq 'HASH') {
1900: $authorquota = $settings->{'authorquota'}->{'default'};
1901: }
1.3 raeburn 1902: }
1903: }
1904: $typecount ++;
1905: $css_class = $typecount%2?' class="LC_odd_row"':'';
1906: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1907: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1908: '<td class="LC_left_item">';
1.101 raeburn 1909: if ($context eq 'requestcourses') {
1910: $datatable .= '<table><tr>';
1911: }
1912: my %defcell;
1.72 raeburn 1913: foreach my $item (@usertools) {
1.101 raeburn 1914: if ($context eq 'requestcourses') {
1915: my ($curroption,$currlimit);
1916: if (ref($settings) eq 'HASH') {
1917: if (ref($settings->{$item}) eq 'HASH') {
1918: $curroption = $settings->{$item}->{'default'};
1919: if ($curroption =~ /^autolimit=(\d*)$/) {
1920: $currlimit = $1;
1921: }
1922: }
1923: }
1924: if (!$curroption) {
1925: $curroption = 'norequest';
1926: }
1927: $datatable .= '<th>'.$titles{$item}.'</th>';
1928: foreach my $option (@options) {
1929: my $val = $option;
1930: if ($option eq 'norequest') {
1931: $val = 0;
1932: }
1933: if ($option eq 'validate') {
1934: my $canvalidate = 0;
1935: if (ref($validations{$item}) eq 'HASH') {
1936: if ($validations{$item}{'default'}) {
1937: $canvalidate = 1;
1938: }
1939: }
1940: next if (!$canvalidate);
1941: }
1942: my $checked = '';
1943: if ($option eq $curroption) {
1944: $checked = ' checked="checked"';
1945: } elsif ($option eq 'autolimit') {
1946: if ($curroption =~ /^autolimit/) {
1947: $checked = ' checked="checked"';
1948: }
1949: }
1950: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1951: '<input type="radio" name="crsreq_'.$item.
1952: '_default" value="'.$val.'"'.$checked.' />'.
1953: $titles{$option}.'</label>';
1954: if ($option eq 'autolimit') {
1.127 raeburn 1955: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1956: $item.'_limit_default" size="1" '.
1957: 'value="'.$currlimit.'" />';
1958: }
1.127 raeburn 1959: $defcell{$item} .= '</span> ';
1.104 raeburn 1960: if ($option eq 'autolimit') {
1.127 raeburn 1961: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1962: }
1.101 raeburn 1963: }
1.160.6.5 raeburn 1964: } elsif ($context eq 'requestauthor') {
1965: my $curroption;
1966: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1967: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1968: }
1969: if (!$curroption) {
1970: $curroption = 'norequest';
1971: }
1972: foreach my $option (@options) {
1973: my $val = $option;
1974: if ($option eq 'norequest') {
1975: $val = 0;
1976: }
1977: my $checked = '';
1978: if ($option eq $curroption) {
1979: $checked = ' checked="checked"';
1980: }
1981: $datatable .= '<span class="LC_nobreak"><label>'.
1982: '<input type="radio" name="authorreq_default"'.
1983: ' value="'.$val.'"'.$checked.' />'.
1984: $titles{$option}.'</label></span> ';
1985: }
1.101 raeburn 1986: } else {
1987: my $checked = 'checked="checked" ';
1988: if (ref($settings) eq 'HASH') {
1989: if (ref($settings->{$item}) eq 'HASH') {
1990: if ($settings->{$item}->{'default'} == 0) {
1991: $checked = '';
1992: } elsif ($settings->{$item}->{'default'} == 1) {
1993: $checked = 'checked="checked" ';
1994: }
1.78 raeburn 1995: }
1.72 raeburn 1996: }
1.101 raeburn 1997: $datatable .= '<span class="LC_nobreak"><label>'.
1998: '<input type="checkbox" name="'.$context.'_'.$item.
1999: '" value="default" '.$checked.'/>'.$titles{$item}.
2000: '</label></span> ';
2001: }
2002: }
2003: if ($context eq 'requestcourses') {
2004: $datatable .= '</tr><tr>';
2005: foreach my $item (@usertools) {
1.106 raeburn 2006: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2007: }
1.101 raeburn 2008: $datatable .= '</tr></table>';
1.72 raeburn 2009: }
1.86 raeburn 2010: $datatable .= '</td>';
1.160.6.5 raeburn 2011: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2012: $datatable .= '<td class="LC_right_item">'.
2013: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2014: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2015: $defaultquota.'" size="5" /></span>'.(' ' x2).
2016: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2017: '<input type="text" name="authorquota" value="'.
2018: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2019: }
2020: $datatable .= '</tr>';
1.72 raeburn 2021: $typecount ++;
2022: $css_class = $typecount%2?' class="LC_odd_row"':'';
2023: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2024: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2025: if ($context eq 'requestcourses') {
1.109 raeburn 2026: $datatable .= &mt('(overrides affiliation, if set)').
2027: '</td>'.
2028: '<td class="LC_left_item">'.
2029: '<table><tr>';
1.101 raeburn 2030: } else {
1.109 raeburn 2031: $datatable .= &mt('(overrides affiliation, if checked)').
2032: '</td>'.
2033: '<td class="LC_left_item" colspan="2">'.
2034: '<br />';
1.101 raeburn 2035: }
2036: my %advcell;
1.72 raeburn 2037: foreach my $item (@usertools) {
1.101 raeburn 2038: if ($context eq 'requestcourses') {
2039: my ($curroption,$currlimit);
2040: if (ref($settings) eq 'HASH') {
2041: if (ref($settings->{$item}) eq 'HASH') {
2042: $curroption = $settings->{$item}->{'_LC_adv'};
2043: if ($curroption =~ /^autolimit=(\d*)$/) {
2044: $currlimit = $1;
2045: }
2046: }
2047: }
2048: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2049: my $checked = '';
2050: if ($curroption eq '') {
2051: $checked = ' checked="checked"';
2052: }
2053: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2054: '<input type="radio" name="crsreq_'.$item.
2055: '__LC_adv" value=""'.$checked.' />'.
2056: &mt('No override set').'</label></span> ';
1.101 raeburn 2057: foreach my $option (@options) {
2058: my $val = $option;
2059: if ($option eq 'norequest') {
2060: $val = 0;
2061: }
2062: if ($option eq 'validate') {
2063: my $canvalidate = 0;
2064: if (ref($validations{$item}) eq 'HASH') {
2065: if ($validations{$item}{'_LC_adv'}) {
2066: $canvalidate = 1;
2067: }
2068: }
2069: next if (!$canvalidate);
2070: }
2071: my $checked = '';
1.104 raeburn 2072: if ($val eq $curroption) {
1.101 raeburn 2073: $checked = ' checked="checked"';
2074: } elsif ($option eq 'autolimit') {
2075: if ($curroption =~ /^autolimit/) {
2076: $checked = ' checked="checked"';
2077: }
2078: }
2079: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2080: '<input type="radio" name="crsreq_'.$item.
2081: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2082: $titles{$option}.'</label>';
2083: if ($option eq 'autolimit') {
1.127 raeburn 2084: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2085: $item.'_limit__LC_adv" size="1" '.
2086: 'value="'.$currlimit.'" />';
2087: }
1.127 raeburn 2088: $advcell{$item} .= '</span> ';
1.104 raeburn 2089: if ($option eq 'autolimit') {
1.127 raeburn 2090: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2091: }
1.101 raeburn 2092: }
1.160.6.5 raeburn 2093: } elsif ($context eq 'requestauthor') {
2094: my $curroption;
2095: if (ref($settings) eq 'HASH') {
2096: $curroption = $settings->{'_LC_adv'};
2097: }
2098: my $checked = '';
2099: if ($curroption eq '') {
2100: $checked = ' checked="checked"';
2101: }
2102: $datatable .= '<span class="LC_nobreak"><label>'.
2103: '<input type="radio" name="authorreq__LC_adv"'.
2104: ' value=""'.$checked.' />'.
2105: &mt('No override set').'</label></span> ';
2106: foreach my $option (@options) {
2107: my $val = $option;
2108: if ($option eq 'norequest') {
2109: $val = 0;
2110: }
2111: my $checked = '';
2112: if ($val eq $curroption) {
2113: $checked = ' checked="checked"';
2114: }
2115: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2116: '<input type="radio" name="authorreq__LC_adv"'.
2117: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2118: $titles{$option}.'</label></span> ';
2119: }
1.101 raeburn 2120: } else {
2121: my $checked = 'checked="checked" ';
2122: if (ref($settings) eq 'HASH') {
2123: if (ref($settings->{$item}) eq 'HASH') {
2124: if ($settings->{$item}->{'_LC_adv'} == 0) {
2125: $checked = '';
2126: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2127: $checked = 'checked="checked" ';
2128: }
1.79 raeburn 2129: }
1.72 raeburn 2130: }
1.101 raeburn 2131: $datatable .= '<span class="LC_nobreak"><label>'.
2132: '<input type="checkbox" name="'.$context.'_'.$item.
2133: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2134: '</label></span> ';
2135: }
2136: }
2137: if ($context eq 'requestcourses') {
2138: $datatable .= '</tr><tr>';
2139: foreach my $item (@usertools) {
1.106 raeburn 2140: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2141: }
1.101 raeburn 2142: $datatable .= '</tr></table>';
1.72 raeburn 2143: }
1.98 raeburn 2144: $datatable .= '</td></tr>';
1.30 raeburn 2145: $$rowtotal += $typecount;
1.3 raeburn 2146: return $datatable;
2147: }
2148:
1.160.6.5 raeburn 2149: sub print_requestmail {
2150: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2151: my ($now,$datatable,%currapp);
1.102 raeburn 2152: $now = time;
2153: if (ref($settings) eq 'HASH') {
2154: if (ref($settings->{'notify'}) eq 'HASH') {
2155: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2156: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2157: }
2158: }
2159: }
1.160.6.16 raeburn 2160: my $numinrow = 2;
1.160.6.34 raeburn 2161: my $css_class;
2162: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2163: my $text;
2164: if ($action eq 'requestcourses') {
2165: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2166: } elsif ($action eq 'requestauthor') {
2167: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2168: } else {
1.160.6.34 raeburn 2169: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2170: }
1.160.6.34 raeburn 2171: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2172: ' <td>'.$text.'</td>'.
1.102 raeburn 2173: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2174: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2175: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2176: if ($numdc > 0) {
2177: $datatable .= $table;
1.102 raeburn 2178: } else {
2179: $datatable .= &mt('There are no active Domain Coordinators');
2180: }
2181: $datatable .='</td></tr>';
2182: return $datatable;
2183: }
2184:
1.160.6.30 raeburn 2185: sub print_studentcode {
2186: my ($settings,$rowtotal) = @_;
2187: my $rownum = 0;
2188: my ($output,%current);
2189: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2190: if (ref($settings) eq 'HASH') {
2191: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2192: foreach my $type (@crstypes) {
2193: $current{$type} = $settings->{'uniquecode'}{$type};
2194: }
1.160.6.30 raeburn 2195: }
2196: }
2197: $output .= '<tr>'.
2198: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2199: '<td class="LC_left_item">';
2200: foreach my $type (@crstypes) {
2201: my $check = ' ';
2202: if ($current{$type}) {
2203: $check = ' checked="checked" ';
2204: }
2205: $output .= '<span class="LC_nobreak"><label>'.
2206: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2207: &mt($type).'</label></span>'.(' 'x2).' ';
2208: }
2209: $output .= '</td></tr>';
2210: $$rowtotal ++;
2211: return $output;
2212: }
2213:
2214: sub print_textbookcourses {
1.160.6.46 raeburn 2215: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2216: my $rownum = 0;
2217: my $css_class;
2218: my $itemcount = 1;
2219: my $maxnum = 0;
2220: my $bookshash;
2221: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2222: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2223: }
2224: my %ordered;
2225: if (ref($bookshash) eq 'HASH') {
2226: foreach my $item (keys(%{$bookshash})) {
2227: if (ref($bookshash->{$item}) eq 'HASH') {
2228: my $num = $bookshash->{$item}{'order'};
2229: $ordered{$num} = $item;
2230: }
2231: }
2232: }
2233: my $confname = $dom.'-domainconfig';
2234: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2235: my $maxnum = scalar(keys(%ordered));
2236: my $datatable;
1.160.6.30 raeburn 2237: if (keys(%ordered)) {
2238: my @items = sort { $a <=> $b } keys(%ordered);
2239: for (my $i=0; $i<@items; $i++) {
2240: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2241: my $key = $ordered{$items[$i]};
2242: my %coursehash=&Apache::lonnet::coursedescription($key);
2243: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2244: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2245: if (ref($bookshash->{$key}) eq 'HASH') {
2246: $subject = $bookshash->{$key}->{'subject'};
2247: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2248: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2249: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2250: $author = $bookshash->{$key}->{'author'};
2251: $image = $bookshash->{$key}->{'image'};
2252: if ($image ne '') {
2253: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2254: my $imagethumb = "$path/tn-".$imagefile;
2255: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2256: }
1.160.6.30 raeburn 2257: }
2258: }
1.160.6.46 raeburn 2259: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2260: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2261: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2262: for (my $k=0; $k<=$maxnum; $k++) {
2263: my $vpos = $k+1;
2264: my $selstr;
2265: if ($k == $i) {
2266: $selstr = ' selected="selected" ';
2267: }
2268: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2269: }
2270: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2271: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2272: &mt('Delete?').'</label></span></td>'.
2273: '<td colspan="2">'.
1.160.6.46 raeburn 2274: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2275: (' 'x2).
1.160.6.46 raeburn 2276: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2277: if ($type eq 'textbooks') {
2278: $datatable .= (' 'x2).
1.160.6.47 raeburn 2279: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2280: (' 'x2).
1.160.6.46 raeburn 2281: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2282: (' 'x2).
2283: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2284: if ($image) {
2285: $datatable .= '<span class="LC_nobreak">'.
2286: $imgsrc.
2287: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2288: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2289: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2290: }
2291: if ($switchserver) {
2292: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2293: } else {
2294: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2295: }
1.160.6.30 raeburn 2296: }
1.160.6.46 raeburn 2297: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2298: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2299: $coursetitle.'</span></td></tr>'."\n";
2300: $itemcount ++;
2301: }
2302: }
2303: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2304: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2305: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2306: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2307: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2308: for (my $k=0; $k<$maxnum+1; $k++) {
2309: my $vpos = $k+1;
2310: my $selstr;
2311: if ($k == $maxnum) {
2312: $selstr = ' selected="selected" ';
2313: }
2314: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2315: }
2316: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2317: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2318: '<td colspan="2">'.
1.160.6.46 raeburn 2319: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2320: (' 'x2).
1.160.6.46 raeburn 2321: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2322: (' 'x2);
2323: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2324: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2325: (' 'x2).
2326: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2327: (' 'x2).
2328: '<span class="LC_nobreak">'.&mt('Image:').' ';
2329: if ($switchserver) {
2330: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2331: } else {
2332: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2333: }
1.160.6.30 raeburn 2334: }
2335: $datatable .= '</span>'."\n".
2336: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2337: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2338: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2339: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2340: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2341: '</span></td>'."\n".
2342: '</tr>'."\n";
2343: $itemcount ++;
2344: return $datatable;
2345: }
2346:
2347: sub textbookcourses_javascript {
1.160.6.46 raeburn 2348: my ($settings) = @_;
2349: return unless(ref($settings) eq 'HASH');
2350: my (%ordered,%total,%jstext);
2351: foreach my $type ('textbooks','templates') {
2352: $total{$type} = 0;
2353: if (ref($settings->{$type}) eq 'HASH') {
2354: foreach my $item (keys(%{$settings->{$type}})) {
2355: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2356: my $num = $settings->{$type}->{$item}{'order'};
2357: $ordered{$type}{$num} = $item;
2358: }
2359: }
2360: $total{$type} = scalar(keys(%{$settings->{$type}}));
2361: }
2362: my @jsarray = ();
2363: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2364: push(@jsarray,$ordered{$type}{$item});
2365: }
2366: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2367: }
2368: return <<"ENDSCRIPT";
2369: <script type="text/javascript">
2370: // <![CDATA[
1.160.6.46 raeburn 2371: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2372: var changedVal;
1.160.6.46 raeburn 2373: $jstext{'textbooks'};
2374: $jstext{'templates'};
2375: var newpos;
2376: var maxh;
2377: if (caller == 'textbooks') {
2378: newpos = 'textbooks_addbook_pos';
2379: maxh = 1 + $total{'textbooks'};
2380: } else {
2381: newpos = 'templates_addbook_pos';
2382: maxh = 1 + $total{'templates'};
2383: }
1.160.6.30 raeburn 2384: var current = new Array;
2385: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2386: if (item == newpos) {
2387: changedVal = newitemVal;
2388: } else {
2389: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2390: current[newitemVal] = newpos;
2391: }
1.160.6.46 raeburn 2392: if (caller == 'textbooks') {
2393: for (var i=0; i<textbooks.length; i++) {
2394: var elementName = 'textbooks_'+textbooks[i];
2395: if (elementName != item) {
2396: if (form.elements[elementName]) {
2397: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2398: current[currVal] = elementName;
2399: }
2400: }
2401: }
2402: }
2403: if (caller == 'templates') {
2404: for (var i=0; i<templates.length; i++) {
2405: var elementName = 'templates_'+templates[i];
2406: if (elementName != item) {
2407: if (form.elements[elementName]) {
2408: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2409: current[currVal] = elementName;
2410: }
1.160.6.30 raeburn 2411: }
2412: }
2413: }
2414: var oldVal;
2415: for (var j=0; j<maxh; j++) {
2416: if (current[j] == undefined) {
2417: oldVal = j;
2418: }
2419: }
2420: if (oldVal < changedVal) {
2421: for (var k=oldVal+1; k<=changedVal ; k++) {
2422: var elementName = current[k];
2423: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2424: }
2425: } else {
2426: for (var k=changedVal; k<oldVal; k++) {
2427: var elementName = current[k];
2428: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2429: }
2430: }
2431: return;
2432: }
2433:
2434: // ]]>
2435: </script>
2436:
2437: ENDSCRIPT
2438: }
2439:
1.3 raeburn 2440: sub print_autoenroll {
1.30 raeburn 2441: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2442: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2443: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2444: if (ref($settings) eq 'HASH') {
2445: if (exists($settings->{'run'})) {
2446: if ($settings->{'run'} eq '0') {
2447: $runoff = ' checked="checked" ';
2448: $runon = ' ';
2449: } else {
2450: $runon = ' checked="checked" ';
2451: $runoff = ' ';
2452: }
2453: } else {
2454: if ($autorun) {
2455: $runon = ' checked="checked" ';
2456: $runoff = ' ';
2457: } else {
2458: $runoff = ' checked="checked" ';
2459: $runon = ' ';
2460: }
2461: }
1.129 raeburn 2462: if (exists($settings->{'co-owners'})) {
2463: if ($settings->{'co-owners'} eq '0') {
2464: $coownersoff = ' checked="checked" ';
2465: $coownerson = ' ';
2466: } else {
2467: $coownerson = ' checked="checked" ';
2468: $coownersoff = ' ';
2469: }
2470: } else {
2471: $coownersoff = ' checked="checked" ';
2472: $coownerson = ' ';
2473: }
1.3 raeburn 2474: if (exists($settings->{'sender_domain'})) {
2475: $defdom = $settings->{'sender_domain'};
2476: }
1.160.6.68 raeburn 2477: if (exists($settings->{'autofailsafe'})) {
2478: $failsafe = $settings->{'autofailsafe'};
2479: }
1.14 raeburn 2480: } else {
2481: if ($autorun) {
2482: $runon = ' checked="checked" ';
2483: $runoff = ' ';
2484: } else {
2485: $runoff = ' checked="checked" ';
2486: $runon = ' ';
2487: }
1.3 raeburn 2488: }
2489: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2490: my $notif_sender;
2491: if (ref($settings) eq 'HASH') {
2492: $notif_sender = $settings->{'sender_uname'};
2493: }
1.3 raeburn 2494: my $datatable='<tr class="LC_odd_row">'.
2495: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2496: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2497: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2498: $runon.' value="1" />'.&mt('Yes').'</label> '.
2499: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2500: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2501: '</tr><tr>'.
2502: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2503: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2504: &mt('username').': '.
2505: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2506: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2507: ': '.$domform.'</span></td></tr>'.
2508: '<tr class="LC_odd_row">'.
2509: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2510: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2511: '<input type="radio" name="autoassign_coowners"'.
2512: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2513: '<label><input type="radio" name="autoassign_coowners"'.
2514: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2515: '</tr><tr>'.
2516: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2517: '<td class="LC_right_item"><span class="LC_nobreak">'.
2518: '<input type="text" name="autoenroll_failsafe"'.
2519: ' value="'.$failsafe.'" size="4" /></td></tr>';
2520: $$rowtotal += 4;
1.3 raeburn 2521: return $datatable;
2522: }
2523:
2524: sub print_autoupdate {
1.30 raeburn 2525: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2526: my $datatable;
2527: if ($position eq 'top') {
2528: my $updateon = ' ';
2529: my $updateoff = ' checked="checked" ';
2530: my $classlistson = ' ';
2531: my $classlistsoff = ' checked="checked" ';
2532: if (ref($settings) eq 'HASH') {
2533: if ($settings->{'run'} eq '1') {
2534: $updateon = $updateoff;
2535: $updateoff = ' ';
2536: }
2537: if ($settings->{'classlists'} eq '1') {
2538: $classlistson = $classlistsoff;
2539: $classlistsoff = ' ';
2540: }
2541: }
2542: my %title = (
2543: run => 'Auto-update active?',
2544: classlists => 'Update information in classlists?',
2545: );
2546: $datatable = '<tr class="LC_odd_row">'.
2547: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2548: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2549: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2550: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2551: '<label><input type="radio" name="autoupdate_run"'.
2552: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2553: '</tr><tr>'.
2554: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2555: '<td class="LC_right_item"><span class="LC_nobreak">'.
2556: '<label><input type="radio" name="classlists"'.
2557: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2558: '<label><input type="radio" name="classlists"'.
2559: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2560: '</tr>';
1.30 raeburn 2561: $$rowtotal += 2;
1.131 raeburn 2562: } elsif ($position eq 'middle') {
2563: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2564: my $numinrow = 3;
2565: my $locknamesettings;
2566: $datatable .= &insttypes_row($settings,$types,$usertypes,
2567: $dom,$numinrow,$othertitle,
2568: 'lockablenames');
2569: $$rowtotal ++;
1.3 raeburn 2570: } else {
1.44 raeburn 2571: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2572: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2573: 'permanentemail','id');
1.33 raeburn 2574: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2575: my $numrows = 0;
1.26 raeburn 2576: if (ref($types) eq 'ARRAY') {
2577: if (@{$types} > 0) {
2578: $datatable =
2579: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2580: \@fields,$types,\$numrows);
1.30 raeburn 2581: $$rowtotal += @{$types};
1.26 raeburn 2582: }
1.3 raeburn 2583: }
2584: $datatable .=
2585: &usertype_update_row($settings,{'default' => $othertitle},
2586: \%fieldtitles,\@fields,['default'],
2587: \$numrows);
1.30 raeburn 2588: $$rowtotal ++;
1.3 raeburn 2589: }
2590: return $datatable;
2591: }
2592:
1.125 raeburn 2593: sub print_autocreate {
2594: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2595: my (%createon,%createoff,%currhash);
1.125 raeburn 2596: my @types = ('xml','req');
2597: if (ref($settings) eq 'HASH') {
2598: foreach my $item (@types) {
2599: $createoff{$item} = ' checked="checked" ';
2600: $createon{$item} = ' ';
2601: if (exists($settings->{$item})) {
2602: if ($settings->{$item}) {
2603: $createon{$item} = ' checked="checked" ';
2604: $createoff{$item} = ' ';
2605: }
2606: }
2607: }
1.160.6.16 raeburn 2608: if ($settings->{'xmldc'} ne '') {
2609: $currhash{$settings->{'xmldc'}} = 1;
2610: }
1.125 raeburn 2611: } else {
2612: foreach my $item (@types) {
2613: $createoff{$item} = ' checked="checked" ';
2614: $createon{$item} = ' ';
2615: }
2616: }
2617: $$rowtotal += 2;
1.160.6.16 raeburn 2618: my $numinrow = 2;
1.125 raeburn 2619: my $datatable='<tr class="LC_odd_row">'.
2620: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2621: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2622: '<input type="radio" name="autocreate_xml"'.
2623: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2624: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2625: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2626: '</td></tr><tr>'.
2627: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2628: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2629: '<input type="radio" name="autocreate_req"'.
2630: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2631: '<label><input type="radio" name="autocreate_req"'.
2632: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2633: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2634: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2635: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2636: if ($numdc > 1) {
1.160.6.50 raeburn 2637: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2638: '</td><td class="LC_left_item">';
1.125 raeburn 2639: } else {
1.160.6.50 raeburn 2640: $datatable .= &mt('Course creation processed as:').
2641: '</td><td class="LC_right_item">';
1.125 raeburn 2642: }
1.160.6.50 raeburn 2643: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2644: $$rowtotal += $rows;
1.125 raeburn 2645: return $datatable;
2646: }
2647:
1.23 raeburn 2648: sub print_directorysrch {
1.160.6.72 raeburn 2649: my ($position,$dom,$settings,$rowtotal) = @_;
2650: my $datatable;
2651: if ($position eq 'top') {
2652: my $instsrchon = ' ';
2653: my $instsrchoff = ' checked="checked" ';
2654: my ($exacton,$containson,$beginson);
2655: my $instlocalon = ' ';
2656: my $instlocaloff = ' checked="checked" ';
2657: if (ref($settings) eq 'HASH') {
2658: if ($settings->{'available'} eq '1') {
2659: $instsrchon = $instsrchoff;
2660: $instsrchoff = ' ';
2661: }
2662: if ($settings->{'localonly'} eq '1') {
2663: $instlocalon = $instlocaloff;
2664: $instlocaloff = ' ';
2665: }
2666: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2667: foreach my $type (@{$settings->{'searchtypes'}}) {
2668: if ($type eq 'exact') {
2669: $exacton = ' checked="checked" ';
2670: } elsif ($type eq 'contains') {
2671: $containson = ' checked="checked" ';
2672: } elsif ($type eq 'begins') {
2673: $beginson = ' checked="checked" ';
2674: }
2675: }
2676: } else {
2677: if ($settings->{'searchtypes'} eq 'exact') {
2678: $exacton = ' checked="checked" ';
2679: } elsif ($settings->{'searchtypes'} eq 'contains') {
2680: $containson = ' checked="checked" ';
2681: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2682: $exacton = ' checked="checked" ';
2683: $containson = ' checked="checked" ';
2684: }
2685: }
1.23 raeburn 2686: }
1.160.6.72 raeburn 2687: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2688: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2689:
1.160.6.72 raeburn 2690: my $numinrow = 4;
2691: my $cansrchrow = 0;
2692: $datatable='<tr class="LC_odd_row">'.
2693: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2694: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2695: '<input type="radio" name="dirsrch_available"'.
2696: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2697: '<label><input type="radio" name="dirsrch_available"'.
2698: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2699: '</tr><tr>'.
2700: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2701: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2702: '<input type="radio" name="dirsrch_instlocalonly"'.
2703: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2704: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2705: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2706: '</tr>';
2707: $$rowtotal += 2;
2708: if (ref($usertypes) eq 'HASH') {
2709: if (keys(%{$usertypes}) > 0) {
2710: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2711: $numinrow,$othertitle,'cansearch');
2712: $cansrchrow = 1;
2713: }
1.26 raeburn 2714: }
1.160.6.72 raeburn 2715: if ($cansrchrow) {
2716: $$rowtotal ++;
2717: $datatable .= '<tr>';
2718: } else {
2719: $datatable .= '<tr class="LC_odd_row">';
2720: }
2721: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2722: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2723: foreach my $title (@{$titleorder}) {
2724: if (defined($searchtitles->{$title})) {
2725: my $check = ' ';
2726: if (ref($settings) eq 'HASH') {
2727: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2728: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2729: $check = ' checked="checked" ';
2730: }
1.39 raeburn 2731: }
1.25 raeburn 2732: }
1.160.6.72 raeburn 2733: $datatable .= '<td class="LC_left_item">'.
2734: '<span class="LC_nobreak"><label>'.
2735: '<input type="checkbox" name="searchby" '.
2736: 'value="'.$title.'"'.$check.'/>'.
2737: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2738: }
2739: }
1.160.6.72 raeburn 2740: $datatable .= '</tr></table></td></tr>';
2741: $$rowtotal ++;
2742: if ($cansrchrow) {
2743: $datatable .= '<tr class="LC_odd_row">';
2744: } else {
2745: $datatable .= '<tr>';
2746: }
2747: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2748: '<td class="LC_left_item" colspan="2">'.
2749: '<span class="LC_nobreak"><label>'.
2750: '<input type="checkbox" name="searchtypes" '.
2751: $exacton.' value="exact" />'.&mt('Exact match').
2752: '</label> '.
2753: '<label><input type="checkbox" name="searchtypes" '.
2754: $beginson.' value="begins" />'.&mt('Begins with').
2755: '</label> '.
2756: '<label><input type="checkbox" name="searchtypes" '.
2757: $containson.' value="contains" />'.&mt('Contains').
2758: '</label></span></td></tr>';
2759: $$rowtotal ++;
1.26 raeburn 2760: } else {
1.160.6.72 raeburn 2761: my $domsrchon = ' checked="checked" ';
2762: my $domsrchoff = ' ';
2763: my $domlocalon = ' ';
2764: my $domlocaloff = ' checked="checked" ';
2765: if (ref($settings) eq 'HASH') {
2766: if ($settings->{'lclocalonly'} eq '1') {
2767: $domlocalon = $domlocaloff;
2768: $domlocaloff = ' ';
2769: }
2770: if ($settings->{'lcavailable'} eq '0') {
2771: $domsrchoff = $domsrchon;
2772: $domsrchon = ' ';
2773: }
2774: }
2775: $datatable='<tr class="LC_odd_row">'.
2776: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2777: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2778: '<input type="radio" name="dirsrch_domavailable"'.
2779: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2780: '<label><input type="radio" name="dirsrch_domavailable"'.
2781: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2782: '</tr><tr>'.
2783: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2784: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2785: '<input type="radio" name="dirsrch_domlocalonly"'.
2786: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2787: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2788: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2789: '</tr>';
2790: $$rowtotal += 2;
1.26 raeburn 2791: }
1.25 raeburn 2792: return $datatable;
2793: }
2794:
1.28 raeburn 2795: sub print_contacts {
1.160.6.78 raeburn 2796: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2797: my $datatable;
2798: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 2799: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2800: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2801: if ($position eq 'top') {
2802: if (ref($settings) eq 'HASH') {
2803: foreach my $item (@contacts) {
2804: if (exists($settings->{$item})) {
2805: $to{$item} = $settings->{$item};
2806: }
1.28 raeburn 2807: }
2808: }
1.160.6.78 raeburn 2809: } elsif ($position eq 'middle') {
2810: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
2811: 'updatesmail','idconflictsmail');
1.28 raeburn 2812: foreach my $type (@mailings) {
1.160.6.78 raeburn 2813: $otheremails{$type} = '';
2814: }
2815: } else {
2816: @mailings = ('helpdeskmail','otherdomsmail');
2817: foreach my $type (@mailings) {
2818: $otheremails{$type} = '';
2819: }
2820: $bccemails{'helpdeskmail'} = '';
2821: $bccemails{'otherdomsmail'} = '';
2822: $includestr{'helpdeskmail'} = '';
2823: $includestr{'otherdomsmail'} = '';
2824: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2825: }
2826: if (ref($settings) eq 'HASH') {
2827: unless ($position eq 'top') {
2828: foreach my $type (@mailings) {
2829: if (exists($settings->{$type})) {
2830: if (ref($settings->{$type}) eq 'HASH') {
2831: foreach my $item (@contacts) {
2832: if ($settings->{$type}{$item}) {
2833: $checked{$type}{$item} = ' checked="checked" ';
2834: }
1.28 raeburn 2835: }
1.160.6.78 raeburn 2836: $otheremails{$type} = $settings->{$type}{'others'};
2837: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2838: $bccemails{$type} = $settings->{$type}{'bcc'};
2839: if ($settings->{$type}{'include'} ne '') {
2840: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2841: $includestr{$type} = &unescape($includestr{$type});
2842: }
2843: }
2844: }
2845: } elsif ($type eq 'lonstatusmail') {
2846: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2847: }
2848: }
2849: }
2850: if ($position eq 'bottom') {
2851: foreach my $type (@mailings) {
2852: $bccemails{$type} = $settings->{$type}{'bcc'};
2853: if ($settings->{$type}{'include'} ne '') {
2854: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2855: $includestr{$type} = &unescape($includestr{$type});
2856: }
2857: }
2858: if (ref($settings->{'helpform'}) eq 'HASH') {
2859: if (ref($fields) eq 'ARRAY') {
2860: foreach my $field (@{$fields}) {
2861: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 2862: }
1.160.6.78 raeburn 2863: }
2864: if (exists($settings->{'helpform'}{'maxsize'})) {
2865: $maxsize = $settings->{'helpform'}{'maxsize'};
2866: } else {
2867: $maxsize = '1.0';
2868: }
2869: } else {
2870: if (ref($fields) eq 'ARRAY') {
2871: foreach my $field (@{$fields}) {
2872: $currfield{$field} = 'yes';
1.134 raeburn 2873: }
1.28 raeburn 2874: }
1.160.6.78 raeburn 2875: $maxsize = '1.0';
1.28 raeburn 2876: }
2877: }
2878: } else {
1.160.6.78 raeburn 2879: if ($position eq 'top') {
2880: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2881: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2882: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2883: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2884: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2885: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2886: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2887: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
2888: } elsif ($position eq 'bottom') {
2889: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2890: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
2891: if (ref($fields) eq 'ARRAY') {
2892: foreach my $field (@{$fields}) {
2893: $currfield{$field} = 'yes';
2894: }
2895: }
2896: $maxsize = '1.0';
2897: }
1.28 raeburn 2898: }
2899: my ($titles,$short_titles) = &contact_titles();
2900: my $rownum = 0;
2901: my $css_class;
1.160.6.78 raeburn 2902: if ($position eq 'top') {
2903: foreach my $item (@contacts) {
2904: $css_class = $rownum%2?' class="LC_odd_row"':'';
2905: $datatable .= '<tr'.$css_class.'>'.
2906: '<td><span class="LC_nobreak">'.$titles->{$item}.
2907: '</span></td><td class="LC_right_item">'.
2908: '<input type="text" name="'.$item.'" value="'.
2909: $to{$item}.'" /></td></tr>';
2910: $rownum ++;
2911: }
2912: } else {
2913: foreach my $type (@mailings) {
2914: $css_class = $rownum%2?' class="LC_odd_row"':'';
2915: $datatable .= '<tr'.$css_class.'>'.
2916: '<td><span class="LC_nobreak">'.
2917: $titles->{$type}.': </span></td>'.
2918: '<td class="LC_left_item">';
2919: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2920: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
2921: }
2922: $datatable .= '<span class="LC_nobreak">';
2923: foreach my $item (@contacts) {
2924: $datatable .= '<label>'.
2925: '<input type="checkbox" name="'.$type.'"'.
2926: $checked{$type}{$item}.
2927: ' value="'.$item.'" />'.$short_titles->{$item}.
2928: '</label> ';
2929: }
2930: $datatable .= '</span><br />'.&mt('Others').': '.
2931: '<input type="text" name="'.$type.'_others" '.
2932: 'value="'.$otheremails{$type}.'" />';
2933: my %locchecked;
2934: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2935: foreach my $loc ('s','b') {
2936: if ($includeloc{$type} eq $loc) {
2937: $locchecked{$loc} = ' checked="checked"';
2938: last;
2939: }
2940: }
2941: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2942: '<input type="text" name="'.$type.'_bcc" '.
2943: 'value="'.$bccemails{$type}.'" /></fieldset>'.
2944: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
2945: &mt('Text automatically added to e-mail:').' '.
2946: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
2947: '<span class="LC_nobreak">'.&mt('Location:').' '.
2948: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
2949: (' 'x2).
2950: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
2951: '</span></fieldset>';
2952: }
2953: $datatable .= '</td></tr>'."\n";
2954: $rownum ++;
2955: }
1.28 raeburn 2956: }
1.160.6.78 raeburn 2957: if ($position eq 'middle') {
2958: my %choices;
2959: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2960: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2961: &mt('LON-CAPA core group - MSU'),600,500));
2962: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2963: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2964: &mt('LON-CAPA core group - MSU'),600,500));
2965: my @toggles = ('reporterrors','reportupdates');
2966: my %defaultchecked = ('reporterrors' => 'on',
2967: 'reportupdates' => 'on');
2968: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2969: \%choices,$rownum);
2970: $datatable .= $reports;
2971: } elsif ($position eq 'bottom') {
1.69 raeburn 2972: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2973: $datatable .= '<tr'.$css_class.'>'.
1.160.6.78 raeburn 2974: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
2975: &mt('(e-mail, subject, and description always shown)').
2976: '</td><td class="LC_left_item">';
2977: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
2978: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
2979: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
2980: foreach my $field (@{$fields}) {
2981: $datatable .= '<tr><td>'.$fieldtitles->{$field};
2982: if (($field eq 'screenshot') || ($field eq 'cc')) {
2983: $datatable .= ' '.&mt('(logged-in users)');
2984: }
2985: $datatable .='</td><td>';
2986: my $clickaction;
2987: if ($field eq 'screenshot') {
2988: $clickaction = ' onclick="screenshotSize(this);"';
2989: }
2990: if (ref($possoptions->{$field}) eq 'ARRAY') {
2991: foreach my $option (@{$possoptions->{$field}}) {
2992: my $checked;
2993: if ($currfield{$field} eq $option) {
2994: $checked = ' checked="checked"';
2995: }
2996: $datatable .= '<span class="LC_nobreak"><label>'.
2997: '<input type="radio" name="helpform_'.$field.'" '.
2998: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
2999: '</label></span>'.(' 'x2);
3000: }
3001: }
3002: if ($field eq 'screenshot') {
3003: my $display;
3004: if ($currfield{$field} eq 'no') {
3005: $display = ' style="display:none"';
3006: }
3007: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
3008: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3009: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3010: }
3011: $datatable .= '</td></tr>';
3012: }
3013: $datatable .= '</table>';
1.134 raeburn 3014: }
3015: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 3016: $rownum ++;
1.28 raeburn 3017: }
1.30 raeburn 3018: $$rowtotal += $rownum;
1.28 raeburn 3019: return $datatable;
3020: }
3021:
1.160.6.78 raeburn 3022: sub contacts_javascript {
3023: return <<"ENDSCRIPT";
3024:
3025: <script type="text/javascript">
3026: // <![CDATA[
3027:
3028: function screenshotSize(field) {
3029: if (document.getElementById('help_screenshotsize')) {
3030: if (field.value == 'no') {
3031: document.getElementById('help_screenshotsize').style.display="none";
3032: } else {
3033: document.getElementById('help_screenshotsize').style.display="";
3034: }
3035: }
3036: return;
3037: }
3038:
3039: // ]]>
3040: </script>
3041:
3042: ENDSCRIPT
3043: }
3044:
1.118 jms 3045: sub print_helpsettings {
1.160.6.73 raeburn 3046: my ($position,$dom,$settings,$rowtotal) = @_;
3047: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3048: my $formname = 'display';
1.160.6.5 raeburn 3049: my ($datatable,$itemcount);
1.160.6.73 raeburn 3050: if ($position eq 'top') {
3051: $itemcount = 1;
3052: my (%choices,%defaultchecked,@toggles);
3053: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3054: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3055: &mt('LON-CAPA bug tracker'),600,500));
3056: %defaultchecked = ('submitbugs' => 'on');
3057: @toggles = ('submitbugs');
3058: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3059: \%choices,$itemcount);
3060: $$rowtotal ++;
3061: } else {
3062: my $css_class;
3063: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3064: my (%customroles,%ordered,%current);
3065: if (ref($settings->{'adhoc'}) eq 'HASH') {
3066: %current = %{$settings->{'adhoc'}};
3067: }
3068: my $count = 0;
3069: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3070: if ($key=~/^rolesdef\_(\w+)$/) {
3071: my $rolename = $1;
1.160.6.77 raeburn 3072: my (%privs,$order);
1.160.6.73 raeburn 3073: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3074: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3075: if (ref($current{$rolename}) eq 'HASH') {
3076: $order = $current{$rolename}{'order'};
3077: }
3078: if ($order eq '') {
3079: $order = $count;
3080: }
3081: $ordered{$order} = $rolename;
3082: $count++;
1.160.6.73 raeburn 3083: }
3084: }
1.160.6.77 raeburn 3085: my $maxnum = scalar(keys(%ordered));
3086: my @roles_by_num = ();
3087: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3088: push(@roles_by_num,$item);
3089: }
3090: my $context = 'domprefs';
3091: my $crstype = 'Course';
3092: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3093: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3094: my ($numstatustypes,@jsarray);
3095: if (ref($types) eq 'ARRAY') {
3096: if (@{$types} > 0) {
3097: $numstatustypes = scalar(@{$types});
3098: push(@accesstypes,'status');
3099: @jsarray = ('bystatus');
3100: }
3101: }
1.160.6.79 raeburn 3102: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh'.'da']);
1.160.6.77 raeburn 3103: if (keys(%domhelpdesk)) {
3104: push(@accesstypes,('inc','exc'));
3105: push(@jsarray,('notinc','notexc'));
3106: }
3107: my $hiddenstr = join("','",@jsarray);
3108: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3109: my $context = 'domprefs';
3110: my $crstype = 'Course';
1.160.6.77 raeburn 3111: my $prefix = 'helproles_';
3112: my $add_class = 'LC_hidden';
3113: foreach my $num (@roles_by_num) {
3114: my $role = $ordered{$num};
3115: my ($desc,$access,@statuses);
3116: if (ref($current{$role}) eq 'HASH') {
3117: $desc = $current{$role}{'desc'};
3118: $access = $current{$role}{'access'};
3119: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3120: @statuses = @{$current{$role}{'insttypes'}};
3121: }
3122: }
3123: if ($desc eq '') {
3124: $desc = $role;
3125: }
3126: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3127: my %full=();
3128: my %levels= (
3129: course => {},
3130: domain => {},
3131: system => {},
3132: );
3133: my %levelscurrent=(
3134: course => {},
3135: domain => {},
3136: system => {},
3137: );
3138: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3139: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3140: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3141: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3142: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3143: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3144: for (my $k=0; $k<=$maxnum; $k++) {
3145: my $vpos = $k+1;
3146: my $selstr;
3147: if ($k == $num) {
3148: $selstr = ' selected="selected" ';
3149: }
3150: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3151: }
3152: $datatable .= '</select>'.(' 'x2).
3153: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3154: '</td>'.
3155: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3156: &mt('Name shown to users:').
3157: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3158: '</fieldset>'.
3159: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3160: $othertitle,$usertypes,$types,\%domhelpdesk).
3161: '<fieldset>'.
3162: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3163: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3164: \%levelscurrent,$identifier,
3165: 'LC_hidden',$prefix.$num.'_privs').
3166: '</fieldset></td>';
1.160.6.73 raeburn 3167: $itemcount ++;
3168: }
3169: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3170: my $newcust = 'custhelp'.$count;
3171: my (%privs,%levelscurrent);
3172: my %full=();
3173: my %levels= (
3174: course => {},
3175: domain => {},
3176: system => {},
3177: );
3178: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3179: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3180: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3181: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3182: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3183: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3184: for (my $k=0; $k<$maxnum+1; $k++) {
3185: my $vpos = $k+1;
3186: my $selstr;
3187: if ($k == $maxnum) {
3188: $selstr = ' selected="selected" ';
3189: }
3190: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3191: }
3192: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3193: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3194: '</label></span></td>'.
1.160.6.77 raeburn 3195: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3196: '<span class="LC_nobreak">'.
3197: &mt('Internal name:').
3198: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3199: '</span>'.(' 'x4).
3200: '<span class="LC_nobreak">'.
3201: &mt('Name shown to users:').
3202: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3203: '</span></fieldset>'.
3204: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3205: $usertypes,$types,\%domhelpdesk).
3206: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3207: &Apache::lonuserutils::custom_role_header($context,$crstype,
3208: \@templateroles,$newcust).
3209: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3210: \%levelscurrent,$newcust).
1.160.6.77 raeburn 3211: '</fieldset></td></tr>';
1.160.6.73 raeburn 3212: $count ++;
3213: $$rowtotal += $count;
3214: }
1.160.6.5 raeburn 3215: return $datatable;
1.121 raeburn 3216: }
3217:
1.160.6.77 raeburn 3218: sub adhocbutton {
3219: my ($prefix,$num,$field,$visibility) = @_;
3220: my %lt = &Apache::lonlocal::texthash(
3221: show => 'Show details',
3222: hide => 'Hide details',
3223: );
3224: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3225: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3226: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3227: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3228: }
3229:
3230: sub helpsettings_javascript {
3231: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3232: return unless(ref($roles_by_num) eq 'ARRAY');
3233: my %html_js_lt = &Apache::lonlocal::texthash(
3234: show => 'Show details',
3235: hide => 'Hide details',
3236: );
3237: &html_escape(\%html_js_lt);
3238: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3239: return <<"ENDSCRIPT";
3240: <script type="text/javascript">
3241: // <![CDATA[
3242:
3243: function reorderHelpRoles(form,item) {
3244: var changedVal;
3245: $jstext
3246: var newpos = 'helproles_${total}_pos';
3247: var maxh = 1 + $total;
3248: var current = new Array();
3249: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3250: if (item == newpos) {
3251: changedVal = newitemVal;
3252: } else {
3253: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3254: current[newitemVal] = newpos;
3255: }
3256: for (var i=0; i<helproles.length; i++) {
3257: var elementName = 'helproles_'+helproles[i]+'_pos';
3258: if (elementName != item) {
3259: if (form.elements[elementName]) {
3260: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3261: current[currVal] = elementName;
3262: }
3263: }
3264: }
3265: var oldVal;
3266: for (var j=0; j<maxh; j++) {
3267: if (current[j] == undefined) {
3268: oldVal = j;
3269: }
3270: }
3271: if (oldVal < changedVal) {
3272: for (var k=oldVal+1; k<=changedVal ; k++) {
3273: var elementName = current[k];
3274: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3275: }
3276: } else {
3277: for (var k=changedVal; k<oldVal; k++) {
3278: var elementName = current[k];
3279: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3280: }
3281: }
3282: return;
3283: }
3284:
3285: function helpdeskAccess(num) {
3286: var curraccess = null;
3287: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3288: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3289: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3290: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3291: }
3292: }
3293: }
3294: var shown = Array();
3295: var hidden = Array();
3296: if (curraccess == 'none') {
3297: hidden = Array('$hiddenstr');
3298: } else {
3299: if (curraccess == 'status') {
3300: shown = Array('bystatus');
3301: hidden = Array('notinc','notexc');
3302: } else {
3303: if (curraccess == 'exc') {
3304: shown = Array('notexc');
3305: hidden = Array('notinc','bystatus');
3306: }
3307: if (curraccess == 'inc') {
3308: shown = Array('notinc');
3309: hidden = Array('notexc','bystatus');
3310: }
1.160.6.79 raeburn 3311: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3312: hidden = Array('notinc','notexc','bystatus');
3313: }
3314: }
3315: }
3316: if (hidden.length > 0) {
3317: for (var i=0; i<hidden.length; i++) {
3318: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3319: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3320: }
3321: }
3322: }
3323: if (shown.length > 0) {
3324: for (var i=0; i<shown.length; i++) {
3325: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3326: if (shown[i] == 'privs') {
3327: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3328: } else {
3329: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3330: }
3331: }
3332: }
3333: }
3334: return;
3335: }
3336:
3337: function toggleHelpdeskItem(num,field) {
3338: if (document.getElementById('helproles_'+num+'_'+field)) {
3339: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3340: document.getElementById('helproles_'+num+'_'+field).className =
3341: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3342: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3343: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3344: }
3345: } else {
3346: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3347: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3348: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3349: }
3350: }
3351: }
3352: return;
3353: }
3354:
3355: // ]]>
3356: </script>
3357:
3358: ENDSCRIPT
3359: }
3360:
3361: sub helpdeskroles_access {
3362: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3363: $usertypes,$types,$domhelpdesk) = @_;
3364: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3365: my %lt = &Apache::lonlocal::texthash(
3366: 'rou' => 'Role usage',
3367: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3368: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3369: 'dh' => 'All with domain helpdesk role',
3370: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3371: 'none' => 'None',
3372: 'status' => 'Determined based on institutional status',
3373: 'inc' => 'Include all, but exclude specific personnel',
3374: 'exc' => 'Exclude all, but include specific personnel',
3375: );
3376: my %usecheck = (
3377: all => ' checked="checked"',
3378: );
3379: my %displaydiv = (
3380: status => 'none',
3381: inc => 'none',
3382: exc => 'none',
3383: priv => 'block',
3384: );
3385: my $output;
3386: if (ref($current) eq 'HASH') {
3387: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3388: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3389: $usecheck{$current->{access}} = $usecheck{'all'};
3390: delete($usecheck{'all'});
3391: if ($current->{access} =~ /^(status|inc|exc)$/) {
3392: my $access = $1;
3393: $displaydiv{$access} = 'inline';
3394: } elsif ($current->{access} eq 'none') {
3395: $displaydiv{'priv'} = 'none';
3396: }
3397: }
3398: }
3399: }
3400: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3401: '<p>'.$lt{'whi'}.'</p>';
3402: foreach my $access (@{$accesstypes}) {
3403: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3404: ' onclick="helpdeskAccess('."'$num'".');" />'.
3405: $lt{$access}.'</label>';
3406: if ($access eq 'status') {
3407: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3408: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3409: $othertitle,$usertypes,$types).
3410: '</div>';
3411: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3412: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3413: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3414: '</div>';
3415: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3416: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3417: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3418: '</div>';
3419: }
3420: $output .= '</p>';
3421: }
3422: $output .= '</fieldset>';
3423: return $output;
3424: }
3425:
1.121 raeburn 3426: sub radiobutton_prefs {
1.160.6.16 raeburn 3427: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3428: $additional,$align) = @_;
1.121 raeburn 3429: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3430: (ref($choices) eq 'HASH'));
3431:
3432: my (%checkedon,%checkedoff,$datatable,$css_class);
3433:
3434: foreach my $item (@{$toggles}) {
3435: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3436: $checkedon{$item} = ' checked="checked" ';
3437: $checkedoff{$item} = ' ';
1.121 raeburn 3438: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3439: $checkedoff{$item} = ' checked="checked" ';
3440: $checkedon{$item} = ' ';
3441: }
3442: }
3443: if (ref($settings) eq 'HASH') {
1.121 raeburn 3444: foreach my $item (@{$toggles}) {
1.118 jms 3445: if ($settings->{$item} eq '1') {
3446: $checkedon{$item} = ' checked="checked" ';
3447: $checkedoff{$item} = ' ';
3448: } elsif ($settings->{$item} eq '0') {
3449: $checkedoff{$item} = ' checked="checked" ';
3450: $checkedon{$item} = ' ';
3451: }
3452: }
1.121 raeburn 3453: }
1.160.6.16 raeburn 3454: if ($onclick) {
3455: $onclick = ' onclick="'.$onclick.'"';
3456: }
1.121 raeburn 3457: foreach my $item (@{$toggles}) {
1.118 jms 3458: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3459: $datatable .=
1.160.6.16 raeburn 3460: '<tr'.$css_class.'><td valign="top">'.
3461: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3462: '</span></td>';
3463: if ($align eq 'left') {
3464: $datatable .= '<td class="LC_left_item">';
3465: } else {
3466: $datatable .= '<td class="LC_right_item">';
3467: }
3468: $datatable .=
3469: '<span class="LC_nobreak">'.
1.118 jms 3470: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3471: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3472: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3473: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3474: '</span>'.$additional.
3475: '</td>'.
1.118 jms 3476: '</tr>';
3477: $itemcount ++;
1.121 raeburn 3478: }
3479: return ($datatable,$itemcount);
3480: }
3481:
3482: sub print_coursedefaults {
1.139 raeburn 3483: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3484: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3485: my $itemcount = 1;
1.160.6.16 raeburn 3486: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3487: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3488: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3489: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3490: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3491: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3492: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3493: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3494: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3495: );
1.160.6.21 raeburn 3496: my %staticdefaults = (
3497: anonsurvey_threshold => 10,
3498: uploadquota => 500,
1.160.6.57 raeburn 3499: postsubmit => 60,
1.160.6.70 raeburn 3500: mysqltables => 172800,
1.160.6.21 raeburn 3501: );
1.139 raeburn 3502: if ($position eq 'top') {
1.160.6.57 raeburn 3503: %defaultchecked = (
3504: 'uselcmath' => 'on',
3505: 'usejsme' => 'on',
1.160.6.64 raeburn 3506: 'canclone' => 'none',
1.160.6.57 raeburn 3507: );
3508: @toggles = ('uselcmath','usejsme');
1.139 raeburn 3509: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3510: \%choices,$itemcount);
1.160.6.64 raeburn 3511: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3512: $datatable .=
3513: '<tr'.$css_class.'><td valign="top">'.
3514: '<span class="LC_nobreak">'.$choices{'canclone'}.
3515: '</span></td><td class="LC_left_item">';
3516: my $currcanclone = 'none';
3517: my $onclick;
3518: my @cloneoptions = ('none','domain');
3519: my %clonetitles = (
3520: none => 'No additional course requesters',
3521: domain => "Any course requester in course's domain",
3522: instcode => 'Course requests for official courses ...',
3523: );
3524: my (%codedefaults,@code_order,@posscodes);
3525: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3526: \@code_order) eq 'ok') {
3527: if (@code_order > 0) {
3528: push(@cloneoptions,'instcode');
3529: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3530: }
3531: }
3532: if (ref($settings) eq 'HASH') {
3533: if ($settings->{'canclone'}) {
3534: if (ref($settings->{'canclone'}) eq 'HASH') {
3535: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3536: if (@code_order > 0) {
3537: $currcanclone = 'instcode';
3538: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3539: }
3540: }
3541: } elsif ($settings->{'canclone'} eq 'domain') {
3542: $currcanclone = $settings->{'canclone'};
3543: }
3544: }
3545: }
3546: foreach my $option (@cloneoptions) {
3547: my ($checked,$additional);
3548: if ($currcanclone eq $option) {
3549: $checked = ' checked="checked"';
3550: }
3551: if ($option eq 'instcode') {
3552: if (@code_order) {
3553: my $show = 'none';
3554: if ($checked) {
3555: $show = 'block';
3556: }
3557: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3558: &mt('Institutional codes for new and cloned course have identical:').
3559: '<br />';
3560: foreach my $item (@code_order) {
3561: my $codechk;
3562: if ($checked) {
3563: if (grep(/^\Q$item\E$/,@posscodes)) {
3564: $codechk = ' checked="checked"';
3565: }
3566: }
3567: $additional .= '<label>'.
3568: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3569: $item.'</label>';
3570: }
3571: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3572: }
3573: }
3574: $datatable .=
3575: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3576: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3577: '</label> '.$additional.'</span><br />';
3578: }
3579: $datatable .= '</td>'.
3580: '</tr>';
3581: $itemcount ++;
1.139 raeburn 3582: } else {
3583: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3584: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3585: my $currusecredits = 0;
1.160.6.57 raeburn 3586: my $postsubmitclient = 1;
1.160.6.30 raeburn 3587: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3588: if (ref($settings) eq 'HASH') {
3589: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3590: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3591: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3592: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3593: }
3594: }
1.160.6.16 raeburn 3595: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3596: foreach my $type (@types) {
3597: next if ($type eq 'community');
3598: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3599: if ($defcredits{$type} ne '') {
3600: $currusecredits = 1;
3601: }
3602: }
3603: }
3604: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3605: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3606: $postsubmitclient = 0;
3607: foreach my $type (@types) {
3608: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3609: }
3610: } else {
3611: foreach my $type (@types) {
3612: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3613: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3614: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3615: } else {
3616: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3617: }
3618: } else {
3619: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3620: }
3621: }
3622: }
3623: } else {
3624: foreach my $type (@types) {
3625: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3626: }
3627: }
1.160.6.70 raeburn 3628: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3629: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3630: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3631: }
3632: } else {
3633: foreach my $type (@types) {
3634: $currmysql{$type} = $staticdefaults{'mysqltables'};
3635: }
3636: }
1.160.6.58 raeburn 3637: } else {
3638: foreach my $type (@types) {
3639: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3640: }
1.139 raeburn 3641: }
3642: if (!$currdefresponder) {
1.160.6.21 raeburn 3643: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3644: } elsif ($currdefresponder < 1) {
3645: $currdefresponder = 1;
3646: }
1.160.6.21 raeburn 3647: foreach my $type (@types) {
3648: if ($curruploadquota{$type} eq '') {
3649: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3650: }
3651: }
1.139 raeburn 3652: $datatable .=
1.160.6.16 raeburn 3653: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3654: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3655: '</span></td>'.
3656: '<td class="LC_right_item"><span class="LC_nobreak">'.
3657: '<input type="text" name="anonsurvey_threshold"'.
3658: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3659: '</td></tr>'."\n";
3660: $itemcount ++;
3661: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3662: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3663: $choices{'uploadquota'}.
3664: '</span></td>'.
3665: '<td align="right" class="LC_right_item">'.
3666: '<table><tr>';
1.160.6.21 raeburn 3667: foreach my $type (@types) {
3668: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3669: '<input type="text" name="uploadquota_'.$type.'"'.
3670: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3671: }
3672: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3673: $itemcount ++;
1.160.6.40 raeburn 3674: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3675: my $display = 'none';
3676: if ($currusecredits) {
3677: $display = 'block';
3678: }
3679: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3680: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3681: foreach my $type (@types) {
3682: next if ($type eq 'community');
3683: $additional .= '<td align="center">'.&mt($type).'<br />'.
3684: '<input type="text" name="'.$type.'_credits"'.
3685: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3686: }
3687: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3688: %defaultchecked = ('coursecredits' => 'off');
3689: @toggles = ('coursecredits');
3690: my $current = {
3691: 'coursecredits' => $currusecredits,
3692: };
3693: (my $table,$itemcount) =
3694: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3695: \%choices,$itemcount,$onclick,$additional,'left');
3696: $datatable .= $table;
3697: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3698: my $display = 'none';
3699: if ($postsubmitclient) {
3700: $display = 'block';
3701: }
3702: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3703: &mt('Number of seconds submit is disabled').'<br />'.
3704: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3705: '<table><tr>';
1.160.6.57 raeburn 3706: foreach my $type (@types) {
3707: $additional .= '<td align="center">'.&mt($type).'<br />'.
3708: '<input type="text" name="'.$type.'_timeout" value="'.
3709: $deftimeout{$type}.'" size="5" /></td>';
3710: }
3711: $additional .= '</tr></table></div>'."\n";
3712: %defaultchecked = ('postsubmit' => 'on');
3713: @toggles = ('postsubmit');
1.160.6.70 raeburn 3714: $current = {
3715: 'postsubmit' => $postsubmitclient,
3716: };
1.160.6.57 raeburn 3717: ($table,$itemcount) =
3718: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3719: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3720: $datatable .= $table;
1.160.6.70 raeburn 3721: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3722: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3723: $choices{'mysqltables'}.
3724: '</span></td>'.
3725: '<td align="right" class="LC_right_item">'.
3726: '<table><tr>';
3727: foreach my $type (@types) {
3728: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3729: '<input type="text" name="mysqltables_'.$type.'"'.
3730: ' value="'.$currmysql{$type}.'" size="5" /></td>';
3731: }
3732: $datatable .= '</tr></table></td></tr>'."\n";
3733: $itemcount ++;
3734:
1.160.6.37 raeburn 3735: }
3736: $$rowtotal += $itemcount;
3737: return $datatable;
3738: }
3739:
3740: sub print_selfenrollment {
3741: my ($position,$dom,$settings,$rowtotal) = @_;
3742: my ($css_class,$datatable);
3743: my $itemcount = 1;
3744: my @types = ('official','unofficial','community','textbook');
3745: if (($position eq 'top') || ($position eq 'middle')) {
3746: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3747: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3748: my @rows;
3749: my $key;
3750: if ($position eq 'top') {
3751: $key = 'admin';
3752: if (ref($rowsref) eq 'ARRAY') {
3753: @rows = @{$rowsref};
3754: }
3755: } elsif ($position eq 'middle') {
3756: $key = 'default';
3757: @rows = ('types','registered','approval','limit');
3758: }
3759: foreach my $row (@rows) {
3760: if (defined($titlesref->{$row})) {
3761: $itemcount ++;
3762: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3763: $datatable .= '<tr'.$css_class.'>'.
3764: '<td>'.$titlesref->{$row}.'</td>'.
3765: '<td class="LC_left_item">'.
3766: '<table><tr>';
3767: my (%current,%currentcap);
3768: if (ref($settings) eq 'HASH') {
3769: if (ref($settings->{$key}) eq 'HASH') {
3770: foreach my $type (@types) {
3771: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3772: $current{$type} = $settings->{$key}->{$type}->{$row};
3773: }
3774: if (($row eq 'limit') && ($key eq 'default')) {
3775: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3776: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3777: }
3778: }
3779: }
3780: }
3781: }
3782: my %roles = (
3783: '0' => &Apache::lonnet::plaintext('dc'),
3784: );
3785:
3786: foreach my $type (@types) {
3787: unless (($row eq 'registered') && ($key eq 'default')) {
3788: $datatable .= '<th>'.&mt($type).'</th>';
3789: }
3790: }
3791: unless (($row eq 'registered') && ($key eq 'default')) {
3792: $datatable .= '</tr><tr>';
3793: }
3794: foreach my $type (@types) {
3795: if ($type eq 'community') {
3796: $roles{'1'} = &mt('Community personnel');
3797: } else {
3798: $roles{'1'} = &mt('Course personnel');
3799: }
3800: $datatable .= '<td style="vertical-align: top">';
3801: if ($position eq 'top') {
3802: my %checked;
3803: if ($current{$type} eq '0') {
3804: $checked{'0'} = ' checked="checked"';
3805: } else {
3806: $checked{'1'} = ' checked="checked"';
3807: }
3808: foreach my $role ('1','0') {
3809: $datatable .= '<span class="LC_nobreak"><label>'.
3810: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3811: 'value="'.$role.'"'.$checked{$role}.' />'.
3812: $roles{$role}.'</label></span> ';
3813: }
3814: } else {
3815: if ($row eq 'types') {
3816: my %checked;
3817: if ($current{$type} =~ /^(all|dom)$/) {
3818: $checked{$1} = ' checked="checked"';
3819: } else {
3820: $checked{''} = ' checked="checked"';
3821: }
3822: foreach my $val ('','dom','all') {
3823: $datatable .= '<span class="LC_nobreak"><label>'.
3824: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3825: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3826: }
3827: } elsif ($row eq 'registered') {
3828: my %checked;
3829: if ($current{$type} eq '1') {
3830: $checked{'1'} = ' checked="checked"';
3831: } else {
3832: $checked{'0'} = ' checked="checked"';
3833: }
3834: foreach my $val ('0','1') {
3835: $datatable .= '<span class="LC_nobreak"><label>'.
3836: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3837: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3838: }
3839: } elsif ($row eq 'approval') {
3840: my %checked;
3841: if ($current{$type} =~ /^([12])$/) {
3842: $checked{$1} = ' checked="checked"';
3843: } else {
3844: $checked{'0'} = ' checked="checked"';
3845: }
3846: for my $val (0..2) {
3847: $datatable .= '<span class="LC_nobreak"><label>'.
3848: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3849: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3850: }
3851: } elsif ($row eq 'limit') {
3852: my %checked;
3853: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3854: $checked{$1} = ' checked="checked"';
3855: } else {
3856: $checked{'none'} = ' checked="checked"';
3857: }
3858: my $cap;
3859: if ($currentcap{$type} =~ /^\d+$/) {
3860: $cap = $currentcap{$type};
3861: }
3862: foreach my $val ('none','allstudents','selfenrolled') {
3863: $datatable .= '<span class="LC_nobreak"><label>'.
3864: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3865: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3866: }
3867: $datatable .= '<br />'.
3868: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3869: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3870: '</span>';
3871: }
3872: }
3873: $datatable .= '</td>';
3874: }
3875: $datatable .= '</tr>';
3876: }
3877: $datatable .= '</table></td></tr>';
3878: }
3879: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3880: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3881: }
3882: $$rowtotal += $itemcount;
3883: return $datatable;
3884: }
3885:
3886: sub print_validation_rows {
3887: my ($caller,$dom,$settings,$rowtotal) = @_;
3888: my ($itemsref,$namesref,$fieldsref);
3889: if ($caller eq 'selfenroll') {
3890: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3891: } elsif ($caller eq 'requestcourses') {
3892: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3893: }
3894: my %currvalidation;
3895: if (ref($settings) eq 'HASH') {
3896: if (ref($settings->{'validation'}) eq 'HASH') {
3897: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3898: }
1.160.6.39 raeburn 3899: }
3900: my $datatable;
3901: my $itemcount = 0;
3902: foreach my $item (@{$itemsref}) {
3903: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3904: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3905: $namesref->{$item}.
3906: '</span></td>'.
3907: '<td class="LC_left_item">';
3908: if (($item eq 'url') || ($item eq 'button')) {
3909: $datatable .= '<span class="LC_nobreak">'.
3910: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3911: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3912: } elsif ($item eq 'fields') {
3913: my @currfields;
3914: if (ref($currvalidation{$item}) eq 'ARRAY') {
3915: @currfields = @{$currvalidation{$item}};
3916: }
3917: foreach my $field (@{$fieldsref}) {
3918: my $check = '';
3919: if (grep(/^\Q$field\E$/,@currfields)) {
3920: $check = ' checked="checked"';
3921: }
3922: $datatable .= '<span class="LC_nobreak"><label>'.
3923: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3924: ' value="'.$field.'"'.$check.' />'.$field.
3925: '</label></span> ';
3926: }
3927: } elsif ($item eq 'markup') {
3928: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3929: $currvalidation{$item}.
1.160.6.37 raeburn 3930: '</textarea>';
1.160.6.39 raeburn 3931: }
3932: $datatable .= '</td></tr>'."\n";
3933: if (ref($rowtotal)) {
1.160.6.37 raeburn 3934: $itemcount ++;
3935: }
1.139 raeburn 3936: }
1.160.6.39 raeburn 3937: if ($caller eq 'requestcourses') {
3938: my %currhash;
1.160.6.51 raeburn 3939: if (ref($settings) eq 'HASH') {
3940: if (ref($settings->{'validation'}) eq 'HASH') {
3941: if ($settings->{'validation'}{'dc'} ne '') {
3942: $currhash{$settings->{'validation'}{'dc'}} = 1;
3943: }
1.160.6.39 raeburn 3944: }
3945: }
3946: my $numinrow = 2;
3947: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3948: 'validationdc',%currhash);
1.160.6.50 raeburn 3949: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3950: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 3951: if ($numdc > 1) {
1.160.6.50 raeburn 3952: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3953: } else {
1.160.6.50 raeburn 3954: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3955: }
1.160.6.50 raeburn 3956: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3957: $itemcount ++;
3958: }
3959: if (ref($rowtotal)) {
3960: $$rowtotal += $itemcount;
3961: }
1.121 raeburn 3962: return $datatable;
1.118 jms 3963: }
3964:
1.137 raeburn 3965: sub print_usersessions {
3966: my ($position,$dom,$settings,$rowtotal) = @_;
3967: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3968: my (%by_ip,%by_location,@intdoms);
3969: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3970:
3971: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3972: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3973: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3974: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3975: my $itemcount = 1;
3976: if ($position eq 'top') {
1.152 raeburn 3977: if (keys(%serverhomes) > 1) {
1.145 raeburn 3978: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 3979: my $curroffloadnow;
3980: if (ref($settings) eq 'HASH') {
3981: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3982: $curroffloadnow = $settings->{'offloadnow'};
3983: }
3984: }
3985: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3986: } else {
1.140 raeburn 3987: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3988: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3989: }
1.137 raeburn 3990: } else {
1.145 raeburn 3991: if (keys(%by_location) == 0) {
3992: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3993: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3994: } else {
3995: my %lt = &usersession_titles();
3996: my $numinrow = 5;
3997: my $prefix;
3998: my @types;
3999: if ($position eq 'bottom') {
4000: $prefix = 'remote';
4001: @types = ('version','excludedomain','includedomain');
4002: } else {
4003: $prefix = 'hosted';
4004: @types = ('excludedomain','includedomain');
4005: }
4006: my (%current,%checkedon,%checkedoff);
4007: my @lcversions = &Apache::lonnet::all_loncaparevs();
4008: my @locations = sort(keys(%by_location));
4009: foreach my $type (@types) {
4010: $checkedon{$type} = '';
4011: $checkedoff{$type} = ' checked="checked"';
4012: }
4013: if (ref($settings) eq 'HASH') {
4014: if (ref($settings->{$prefix}) eq 'HASH') {
4015: foreach my $key (keys(%{$settings->{$prefix}})) {
4016: $current{$key} = $settings->{$prefix}{$key};
4017: if ($key eq 'version') {
4018: if ($current{$key} ne '') {
4019: $checkedon{$key} = ' checked="checked"';
4020: $checkedoff{$key} = '';
4021: }
4022: } elsif (ref($current{$key}) eq 'ARRAY') {
4023: $checkedon{$key} = ' checked="checked"';
4024: $checkedoff{$key} = '';
4025: }
1.137 raeburn 4026: }
4027: }
4028: }
1.145 raeburn 4029: foreach my $type (@types) {
4030: next if ($type ne 'version' && !@locations);
4031: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4032: $datatable .= '<tr'.$css_class.'>
4033: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4034: <span class="LC_nobreak">
4035: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4036: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4037: if ($type eq 'version') {
4038: my $selector = '<select name="'.$prefix.'_version">';
4039: foreach my $version (@lcversions) {
4040: my $selected = '';
4041: if ($current{'version'} eq $version) {
4042: $selected = ' selected="selected"';
4043: }
4044: $selector .= ' <option value="'.$version.'"'.
4045: $selected.'>'.$version.'</option>';
4046: }
4047: $selector .= '</select> ';
4048: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4049: } else {
4050: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4051: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4052: ' />'.(' 'x2).
4053: '<input type="button" value="'.&mt('uncheck all').'" '.
4054: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4055: "\n".
4056: '</div><div><table>';
4057: my $rem;
4058: for (my $i=0; $i<@locations; $i++) {
4059: my ($showloc,$value,$checkedtype);
4060: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4061: my $ip = $by_location{$locations[$i]}->[0];
4062: if (ref($by_ip{$ip}) eq 'ARRAY') {
4063: $value = join(':',@{$by_ip{$ip}});
4064: $showloc = join(', ',@{$by_ip{$ip}});
4065: if (ref($current{$type}) eq 'ARRAY') {
4066: foreach my $loc (@{$by_ip{$ip}}) {
4067: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4068: $checkedtype = ' checked="checked"';
4069: last;
4070: }
4071: }
1.138 raeburn 4072: }
4073: }
4074: }
1.145 raeburn 4075: $rem = $i%($numinrow);
4076: if ($rem == 0) {
4077: if ($i > 0) {
4078: $datatable .= '</tr>';
4079: }
4080: $datatable .= '<tr>';
4081: }
4082: $datatable .= '<td class="LC_left_item">'.
4083: '<span class="LC_nobreak"><label>'.
4084: '<input type="checkbox" name="'.$prefix.'_'.$type.
4085: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4086: '</label></span></td>';
1.137 raeburn 4087: }
1.145 raeburn 4088: $rem = @locations%($numinrow);
4089: my $colsleft = $numinrow - $rem;
4090: if ($colsleft > 1 ) {
4091: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4092: ' </td>';
4093: } elsif ($colsleft == 1) {
4094: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4095: }
1.145 raeburn 4096: $datatable .= '</tr></table>';
1.137 raeburn 4097: }
1.145 raeburn 4098: $datatable .= '</td></tr>';
4099: $itemcount ++;
1.137 raeburn 4100: }
4101: }
4102: }
4103: $$rowtotal += $itemcount;
4104: return $datatable;
4105: }
4106:
1.138 raeburn 4107: sub build_location_hashes {
4108: my ($intdoms,$by_ip,$by_location) = @_;
4109: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4110: (ref($by_location) eq 'HASH'));
4111: my %iphost = &Apache::lonnet::get_iphost();
4112: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4113: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4114: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4115: foreach my $id (@{$iphost{$primary_ip}}) {
4116: my $intdom = &Apache::lonnet::internet_dom($id);
4117: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4118: push(@{$intdoms},$intdom);
4119: }
4120: }
4121: }
4122: foreach my $ip (keys(%iphost)) {
4123: if (ref($iphost{$ip}) eq 'ARRAY') {
4124: foreach my $id (@{$iphost{$ip}}) {
4125: my $location = &Apache::lonnet::internet_dom($id);
4126: if ($location) {
4127: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4128: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4129: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4130: push(@{$by_ip->{$ip}},$location);
4131: }
4132: } else {
4133: $by_ip->{$ip} = [$location];
4134: }
4135: }
4136: }
4137: }
4138: }
4139: foreach my $ip (sort(keys(%{$by_ip}))) {
4140: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4141: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4142: my $first = $by_ip->{$ip}->[0];
4143: if (ref($by_location->{$first}) eq 'ARRAY') {
4144: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4145: push(@{$by_location->{$first}},$ip);
4146: }
4147: } else {
4148: $by_location->{$first} = [$ip];
4149: }
4150: }
4151: }
4152: return;
4153: }
4154:
1.145 raeburn 4155: sub current_offloads_to {
4156: my ($dom,$settings,$servers) = @_;
4157: my (%spareid,%otherdomconfigs);
1.152 raeburn 4158: if (ref($servers) eq 'HASH') {
1.145 raeburn 4159: foreach my $lonhost (sort(keys(%{$servers}))) {
4160: my $gotspares;
1.152 raeburn 4161: if (ref($settings) eq 'HASH') {
4162: if (ref($settings->{'spares'}) eq 'HASH') {
4163: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4164: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4165: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4166: $gotspares = 1;
4167: }
1.145 raeburn 4168: }
4169: }
4170: unless ($gotspares) {
4171: my $gotspares;
4172: my $serverhomeID =
4173: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4174: my $serverhomedom =
4175: &Apache::lonnet::host_domain($serverhomeID);
4176: if ($serverhomedom ne $dom) {
4177: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4178: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4179: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4180: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4181: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4182: $gotspares = 1;
4183: }
4184: }
4185: } else {
4186: $otherdomconfigs{$serverhomedom} =
4187: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4188: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4189: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4190: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4191: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4192: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4193: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4194: $gotspares = 1;
4195: }
4196: }
4197: }
4198: }
4199: }
4200: }
4201: }
4202: unless ($gotspares) {
4203: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4204: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4205: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4206: } else {
4207: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4208: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4209: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4210: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4211: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4212: } else {
1.150 raeburn 4213: my %what = (
4214: spareid => 1,
4215: );
4216: my ($result,$returnhash) =
4217: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4218: if ($result eq 'ok') {
4219: if (ref($returnhash) eq 'HASH') {
4220: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4221: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4222: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4223: }
4224: }
1.145 raeburn 4225: }
4226: }
4227: }
4228: }
4229: }
4230: }
4231: return %spareid;
4232: }
4233:
4234: sub spares_row {
1.160.6.61 raeburn 4235: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4236: my $css_class;
4237: my $numinrow = 4;
4238: my $itemcount = 1;
4239: my $datatable;
1.152 raeburn 4240: my %typetitles = &sparestype_titles();
4241: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4242: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4243: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4244: my ($othercontrol,$serverdom);
4245: if ($serverhome ne $server) {
4246: $serverdom = &Apache::lonnet::host_domain($serverhome);
4247: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4248: } else {
4249: $serverdom = &Apache::lonnet::host_domain($server);
4250: if ($serverdom ne $dom) {
4251: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4252: }
4253: }
4254: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4255: my $checkednow;
4256: if (ref($curroffloadnow) eq 'HASH') {
4257: if ($curroffloadnow->{$server}) {
4258: $checkednow = ' checked="checked"';
4259: }
4260: }
1.145 raeburn 4261: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4262: $datatable .= '<tr'.$css_class.'>
4263: <td rowspan="2">
1.160.6.13 raeburn 4264: <span class="LC_nobreak">'.
4265: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4266: ,'<b>'.$server.'</b>').'</span><br />'.
4267: '<span class="LC_nobreak">'."\n".
4268: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4269: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4270: "\n";
1.145 raeburn 4271: my (%current,%canselect);
1.152 raeburn 4272: my @choices =
4273: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4274: foreach my $type ('primary','default') {
4275: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4276: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4277: my @spares = @{$spareid->{$server}{$type}};
4278: if (@spares > 0) {
1.152 raeburn 4279: if ($othercontrol) {
4280: $current{$type} = join(', ',@spares);
4281: } else {
4282: $current{$type} .= '<table>';
4283: my $numspares = scalar(@spares);
4284: for (my $i=0; $i<@spares; $i++) {
4285: my $rem = $i%($numinrow);
4286: if ($rem == 0) {
4287: if ($i > 0) {
4288: $current{$type} .= '</tr>';
4289: }
4290: $current{$type} .= '<tr>';
1.145 raeburn 4291: }
1.152 raeburn 4292: $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'".');" /> '.
4293: $spareid->{$server}{$type}[$i].
4294: '</label></td>'."\n";
4295: }
4296: my $rem = @spares%($numinrow);
4297: my $colsleft = $numinrow - $rem;
4298: if ($colsleft > 1 ) {
4299: $current{$type} .= '<td colspan="'.$colsleft.
4300: '" class="LC_left_item">'.
4301: ' </td>';
4302: } elsif ($colsleft == 1) {
4303: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4304: }
1.152 raeburn 4305: $current{$type} .= '</tr></table>';
1.150 raeburn 4306: }
1.145 raeburn 4307: }
4308: }
4309: if ($current{$type} eq '') {
4310: $current{$type} = &mt('None specified');
4311: }
1.152 raeburn 4312: if ($othercontrol) {
4313: if ($type eq 'primary') {
4314: $canselect{$type} = $othercontrol;
4315: }
4316: } else {
4317: $canselect{$type} =
4318: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4319: '<select name="newspare_'.$type.'_'.$server.'" '.
4320: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4321: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4322: if (@choices > 0) {
4323: foreach my $lonhost (@choices) {
4324: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4325: }
4326: }
4327: $canselect{$type} .= '</select>'."\n";
4328: }
4329: } else {
4330: $current{$type} = &mt('Could not be determined');
4331: if ($type eq 'primary') {
4332: $canselect{$type} = $othercontrol;
4333: }
1.145 raeburn 4334: }
1.152 raeburn 4335: if ($type eq 'default') {
4336: $datatable .= '<tr'.$css_class.'>';
4337: }
4338: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4339: '<td>'.$current{$type}.'</td>'."\n".
4340: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4341: }
4342: $itemcount ++;
4343: }
4344: }
4345: $$rowtotal += $itemcount;
4346: return $datatable;
4347: }
4348:
1.152 raeburn 4349: sub possible_newspares {
4350: my ($server,$currspares,$serverhomes,$altids) = @_;
4351: my $serverhostname = &Apache::lonnet::hostname($server);
4352: my %excluded;
4353: if ($serverhostname ne '') {
4354: %excluded = (
4355: $serverhostname => 1,
4356: );
4357: }
4358: if (ref($currspares) eq 'HASH') {
4359: foreach my $type (keys(%{$currspares})) {
4360: if (ref($currspares->{$type}) eq 'ARRAY') {
4361: if (@{$currspares->{$type}} > 0) {
4362: foreach my $curr (@{$currspares->{$type}}) {
4363: my $hostname = &Apache::lonnet::hostname($curr);
4364: $excluded{$hostname} = 1;
4365: }
4366: }
4367: }
4368: }
4369: }
4370: my @choices;
4371: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4372: if (keys(%{$serverhomes}) > 1) {
4373: foreach my $name (sort(keys(%{$serverhomes}))) {
4374: unless ($excluded{$name}) {
4375: if (exists($altids->{$serverhomes->{$name}})) {
4376: push(@choices,$altids->{$serverhomes->{$name}});
4377: } else {
4378: push(@choices,$serverhomes->{$name});
1.145 raeburn 4379: }
4380: }
4381: }
4382: }
4383: }
1.152 raeburn 4384: return sort(@choices);
1.145 raeburn 4385: }
4386:
1.150 raeburn 4387: sub print_loadbalancing {
4388: my ($dom,$settings,$rowtotal) = @_;
4389: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4390: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4391: my $numinrow = 1;
4392: my $datatable;
4393: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 4394: my (%currbalancer,%currtargets,%currrules,%existing);
4395: if (ref($settings) eq 'HASH') {
4396: %existing = %{$settings};
4397: }
4398: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4399: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4400: \%currtargets,\%currrules);
1.150 raeburn 4401: } else {
4402: return;
4403: }
4404: my ($othertitle,$usertypes,$types) =
4405: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 4406: my $rownum = 8;
1.150 raeburn 4407: if (ref($types) eq 'ARRAY') {
4408: $rownum += scalar(@{$types});
4409: }
1.160.6.7 raeburn 4410: my @css_class = ('LC_odd_row','LC_even_row');
4411: my $balnum = 0;
4412: my $islast;
4413: my (@toshow,$disabledtext);
4414: if (keys(%currbalancer) > 0) {
4415: @toshow = sort(keys(%currbalancer));
4416: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4417: push(@toshow,'');
4418: }
4419: } else {
4420: @toshow = ('');
4421: $disabledtext = &mt('No existing load balancer');
4422: }
4423: foreach my $lonhost (@toshow) {
4424: if ($balnum == scalar(@toshow)-1) {
4425: $islast = 1;
4426: } else {
4427: $islast = 0;
4428: }
4429: my $cssidx = $balnum%2;
4430: my $targets_div_style = 'display: none';
4431: my $disabled_div_style = 'display: block';
4432: my $homedom_div_style = 'display: none';
4433: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4434: '<td rowspan="'.$rownum.'" valign="top">'.
4435: '<p>';
4436: if ($lonhost eq '') {
4437: $datatable .= '<span class="LC_nobreak">';
4438: if (keys(%currbalancer) > 0) {
4439: $datatable .= &mt('Add balancer:');
4440: } else {
4441: $datatable .= &mt('Enable balancer:');
4442: }
4443: $datatable .= ' '.
4444: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4445: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4446: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4447: '<option value="" selected="selected">'.&mt('None').
4448: '</option>'."\n";
4449: foreach my $server (sort(keys(%servers))) {
4450: next if ($currbalancer{$server});
4451: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4452: }
4453: $datatable .=
4454: '</select>'."\n".
4455: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4456: } else {
4457: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4458: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4459: &mt('Stop balancing').'</label>'.
4460: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4461: $targets_div_style = 'display: block';
4462: $disabled_div_style = 'display: none';
4463: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4464: $homedom_div_style = 'display: block';
4465: }
4466: }
4467: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4468: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4469: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4470: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4471: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4472: my @sparestypes = ('primary','default');
4473: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 4474: my %hostherechecked = (
4475: no => ' checked="checked"',
4476: );
1.160.6.7 raeburn 4477: foreach my $sparetype (@sparestypes) {
4478: my $targettable;
4479: for (my $i=0; $i<$numspares; $i++) {
4480: my $checked;
4481: if (ref($currtargets{$lonhost}) eq 'HASH') {
4482: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4483: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4484: $checked = ' checked="checked"';
4485: }
4486: }
4487: }
4488: my ($chkboxval,$disabled);
4489: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4490: $chkboxval = $spares[$i];
4491: }
4492: if (exists($currbalancer{$spares[$i]})) {
4493: $disabled = ' disabled="disabled"';
4494: }
4495: $targettable .=
1.160.6.55 raeburn 4496: '<td><span class="LC_nobreak"><label>'.
4497: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 4498: $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 4499: '</span></label></span></td>';
1.160.6.7 raeburn 4500: my $rem = $i%($numinrow);
4501: if ($rem == 0) {
4502: if (($i > 0) && ($i < $numspares-1)) {
4503: $targettable .= '</tr>';
4504: }
4505: if ($i < $numspares-1) {
4506: $targettable .= '<tr>';
1.150 raeburn 4507: }
4508: }
4509: }
1.160.6.7 raeburn 4510: if ($targettable ne '') {
4511: my $rem = $numspares%($numinrow);
4512: my $colsleft = $numinrow - $rem;
4513: if ($colsleft > 1 ) {
4514: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4515: ' </td>';
4516: } elsif ($colsleft == 1) {
4517: $targettable .= '<td class="LC_left_item"> </td>';
4518: }
4519: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4520: '<table><tr>'.$targettable.'</tr></table><br />';
4521: }
1.160.6.76 raeburn 4522: $hostherechecked{$sparetype} = '';
4523: if (ref($currtargets{$lonhost}) eq 'HASH') {
4524: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4525: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4526: $hostherechecked{$sparetype} = ' checked="checked"';
4527: $hostherechecked{'no'} = '';
4528: }
4529: }
4530: }
4531: }
4532: $datatable .= &mt('Hosting on balancer itself').'<br />'.
4533: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
4534: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
4535: foreach my $sparetype (@sparestypes) {
4536: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
4537: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
4538: '</i></label><br />';
1.160.6.7 raeburn 4539: }
4540: $datatable .= '</div></td></tr>'.
4541: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4542: $othertitle,$usertypes,$types,\%servers,
4543: \%currbalancer,$lonhost,
4544: $targets_div_style,$homedom_div_style,
4545: $css_class[$cssidx],$balnum,$islast);
4546: $$rowtotal += $rownum;
4547: $balnum ++;
4548: }
4549: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4550: return $datatable;
4551: }
4552:
4553: sub get_loadbalancers_config {
4554: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4555: return unless ((ref($servers) eq 'HASH') &&
4556: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4557: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4558: if (keys(%{$existing}) > 0) {
4559: my $oldlonhost;
4560: foreach my $key (sort(keys(%{$existing}))) {
4561: if ($key eq 'lonhost') {
4562: $oldlonhost = $existing->{'lonhost'};
4563: $currbalancer->{$oldlonhost} = 1;
4564: } elsif ($key eq 'targets') {
4565: if ($oldlonhost) {
4566: $currtargets->{$oldlonhost} = $existing->{'targets'};
4567: }
4568: } elsif ($key eq 'rules') {
4569: if ($oldlonhost) {
4570: $currrules->{$oldlonhost} = $existing->{'rules'};
4571: }
4572: } elsif (ref($existing->{$key}) eq 'HASH') {
4573: $currbalancer->{$key} = 1;
4574: $currtargets->{$key} = $existing->{$key}{'targets'};
4575: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4576: }
4577: }
1.160.6.7 raeburn 4578: } else {
4579: my ($balancerref,$targetsref) =
4580: &Apache::lonnet::get_lonbalancer_config($servers);
4581: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4582: foreach my $server (sort(keys(%{$balancerref}))) {
4583: $currbalancer->{$server} = 1;
4584: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4585: }
4586: }
4587: }
1.160.6.7 raeburn 4588: return;
1.150 raeburn 4589: }
4590:
4591: sub loadbalancing_rules {
4592: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 4593: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4594: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4595: my $output;
1.160.6.7 raeburn 4596: my $num = 0;
4597: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4598: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4599: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4600: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 4601: $num ++;
1.150 raeburn 4602: my $current;
4603: if (ref($currrules) eq 'HASH') {
4604: $current = $currrules->{$type};
4605: }
1.160.6.55 raeburn 4606: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 4607: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4608: $current = '';
4609: }
4610: }
4611: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 4612: $servers,$currbalancer,$lonhost,$dom,
4613: $targets_div_style,$homedom_div_style,
4614: $css_class,$balnum,$num,$islast);
1.150 raeburn 4615: }
4616: }
4617: return $output;
4618: }
4619:
4620: sub loadbalancing_titles {
4621: my ($dom,$intdom,$usertypes,$types) = @_;
4622: my %othertypes = (
4623: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4624: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4625: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4626: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 4627: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4628: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4629: );
1.160.6.26 raeburn 4630: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4631: if (ref($types) eq 'ARRAY') {
4632: unshift(@alltypes,@{$types},'default');
4633: }
4634: my %titles;
4635: foreach my $type (@alltypes) {
4636: if ($type =~ /^_LC_/) {
4637: $titles{$type} = $othertypes{$type};
4638: } elsif ($type eq 'default') {
4639: $titles{$type} = &mt('All users from [_1]',$dom);
4640: if (ref($types) eq 'ARRAY') {
4641: if (@{$types} > 0) {
4642: $titles{$type} = &mt('Other users from [_1]',$dom);
4643: }
4644: }
4645: } elsif (ref($usertypes) eq 'HASH') {
4646: $titles{$type} = $usertypes->{$type};
4647: }
4648: }
4649: return (\@alltypes,\%othertypes,\%titles);
4650: }
4651:
4652: sub loadbalance_rule_row {
1.160.6.7 raeburn 4653: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4654: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4655: my @rulenames;
1.150 raeburn 4656: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4657: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4658: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4659: } else {
1.160.6.26 raeburn 4660: @rulenames = ('default','homeserver');
4661: if ($type eq '_LC_external') {
4662: push(@rulenames,'externalbalancer');
4663: } else {
4664: push(@rulenames,'specific');
4665: }
4666: push(@rulenames,'none');
1.150 raeburn 4667: }
4668: my $style = $targets_div_style;
1.160.6.55 raeburn 4669: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4670: $style = $homedom_div_style;
4671: }
1.160.6.7 raeburn 4672: my $space;
4673: if ($islast && $num == 1) {
4674: $space = '<div display="inline-block"> </div>';
4675: }
4676: my $output =
4677: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4678: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4679: '<td valaign="top">'.$space.
4680: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4681: for (my $i=0; $i<@rulenames; $i++) {
4682: my $rule = $rulenames[$i];
4683: my ($checked,$extra);
4684: if ($rulenames[$i] eq 'default') {
4685: $rule = '';
4686: }
4687: if ($rulenames[$i] eq 'specific') {
4688: if (ref($servers) eq 'HASH') {
4689: my $default;
4690: if (($current ne '') && (exists($servers->{$current}))) {
4691: $checked = ' checked="checked"';
4692: }
4693: unless ($checked) {
4694: $default = ' selected="selected"';
4695: }
1.160.6.7 raeburn 4696: $extra =
4697: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4698: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4699: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4700: '<option value=""'.$default.'></option>'."\n";
4701: foreach my $server (sort(keys(%{$servers}))) {
4702: if (ref($currbalancer) eq 'HASH') {
4703: next if (exists($currbalancer->{$server}));
4704: }
1.150 raeburn 4705: my $selected;
1.160.6.7 raeburn 4706: if ($server eq $current) {
1.150 raeburn 4707: $selected = ' selected="selected"';
4708: }
1.160.6.7 raeburn 4709: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4710: }
4711: $extra .= '</select>';
4712: }
4713: } elsif ($rule eq $current) {
4714: $checked = ' checked="checked"';
4715: }
4716: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4717: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4718: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4719: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4720: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4721: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4722: $output .= $ruletitles{'particular'};
4723: } else {
4724: $output .= $ruletitles{$rulenames[$i]};
4725: }
4726: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4727: }
4728: $output .= '</div></td></tr>'."\n";
4729: return $output;
4730: }
4731:
4732: sub offloadtype_text {
4733: my %ruletitles = &Apache::lonlocal::texthash (
4734: 'default' => 'Offloads to default destinations',
4735: 'homeserver' => "Offloads to user's home server",
4736: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4737: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4738: 'none' => 'No offload',
1.160.6.26 raeburn 4739: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4740: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4741: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4742: );
4743: return %ruletitles;
4744: }
4745:
4746: sub sparestype_titles {
4747: my %typestitles = &Apache::lonlocal::texthash (
4748: 'primary' => 'primary',
4749: 'default' => 'default',
4750: );
4751: return %typestitles;
4752: }
4753:
1.28 raeburn 4754: sub contact_titles {
4755: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 4756: 'supportemail' => 'Support E-mail address',
4757: 'adminemail' => 'Default Server Admin E-mail address',
4758: 'errormail' => 'Error reports to be e-mailed to',
4759: 'packagesmail' => 'Package update alerts to be e-mailed to',
4760: 'helpdeskmail' => "Helpdesk requests for this domain's users",
4761: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
4762: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
4763: 'requestsmail' => 'E-mail from course requests requiring approval',
4764: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4765: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4766: );
4767: my %short_titles = &Apache::lonlocal::texthash (
4768: adminemail => 'Admin E-mail address',
4769: supportemail => 'Support E-mail',
4770: );
4771: return (\%titles,\%short_titles);
4772: }
4773:
1.160.6.78 raeburn 4774: sub helpform_fields {
4775: my %titles = &Apache::lonlocal::texthash (
4776: 'username' => 'Name',
4777: 'user' => 'Username/domain',
4778: 'phone' => 'Phone',
4779: 'cc' => 'Cc e-mail',
4780: 'course' => 'Course Details',
4781: 'section' => 'Sections',
4782: 'screenshot' => 'File upload',
4783: );
4784: my @fields = ('username','phone','user','course','section','cc','screenshot');
4785: my %possoptions = (
4786: username => ['yes','no','req'],
4787: phone => ['yes','no','req'],
4788: user => ['yes','no'],
4789: cc => ['yes','no'],
4790: course => ['yes','no'],
4791: section => ['yes','no'],
4792: screenshot => ['yes','no'],
4793: );
4794: my %fieldoptions = &Apache::lonlocal::texthash (
4795: 'yes' => 'Optional',
4796: 'req' => 'Required',
4797: 'no' => "Not shown",
4798: );
4799: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
4800: }
4801:
1.72 raeburn 4802: sub tool_titles {
4803: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4804: aboutme => 'Personal web page',
1.86 raeburn 4805: blog => 'Blog',
1.160.6.4 raeburn 4806: webdav => 'WebDAV',
1.86 raeburn 4807: portfolio => 'Portfolio',
1.88 bisitz 4808: official => 'Official courses (with institutional codes)',
4809: unofficial => 'Unofficial courses',
1.98 raeburn 4810: community => 'Communities',
1.160.6.30 raeburn 4811: textbook => 'Textbook courses',
1.86 raeburn 4812: );
1.72 raeburn 4813: return %titles;
4814: }
4815:
1.101 raeburn 4816: sub courserequest_titles {
4817: my %titles = &Apache::lonlocal::texthash (
4818: official => 'Official',
4819: unofficial => 'Unofficial',
4820: community => 'Communities',
1.160.6.30 raeburn 4821: textbook => 'Textbook',
1.101 raeburn 4822: norequest => 'Not allowed',
1.104 raeburn 4823: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4824: validate => 'With validation',
4825: autolimit => 'Numerical limit',
1.103 raeburn 4826: unlimited => '(blank for unlimited)',
1.101 raeburn 4827: );
4828: return %titles;
4829: }
4830:
1.160.6.5 raeburn 4831: sub authorrequest_titles {
4832: my %titles = &Apache::lonlocal::texthash (
4833: norequest => 'Not allowed',
4834: approval => 'Approval by Dom. Coord.',
4835: automatic => 'Automatic approval',
4836: );
4837: return %titles;
4838: }
4839:
1.101 raeburn 4840: sub courserequest_conditions {
4841: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4842: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4843: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4844: );
4845: return %conditions;
4846: }
4847:
4848:
1.27 raeburn 4849: sub print_usercreation {
1.30 raeburn 4850: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4851: my $numinrow = 4;
1.28 raeburn 4852: my $datatable;
4853: if ($position eq 'top') {
1.30 raeburn 4854: $$rowtotal ++;
1.34 raeburn 4855: my $rowcount = 0;
1.32 raeburn 4856: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4857: if (ref($rules) eq 'HASH') {
4858: if (keys(%{$rules}) > 0) {
1.32 raeburn 4859: $datatable .= &user_formats_row('username',$settings,$rules,
4860: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4861: $$rowtotal ++;
1.32 raeburn 4862: $rowcount ++;
4863: }
4864: }
4865: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4866: if (ref($idrules) eq 'HASH') {
4867: if (keys(%{$idrules}) > 0) {
4868: $datatable .= &user_formats_row('id',$settings,$idrules,
4869: $idruleorder,$numinrow,$rowcount);
4870: $$rowtotal ++;
4871: $rowcount ++;
1.28 raeburn 4872: }
4873: }
1.39 raeburn 4874: if ($rowcount == 0) {
4875: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4876: $$rowtotal ++;
4877: $rowcount ++;
4878: }
1.34 raeburn 4879: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4880: my @creators = ('author','course','requestcrs');
1.37 raeburn 4881: my ($rules,$ruleorder) =
4882: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4883: my %lt = &usercreation_types();
4884: my %checked;
4885: if (ref($settings) eq 'HASH') {
4886: if (ref($settings->{'cancreate'}) eq 'HASH') {
4887: foreach my $item (@creators) {
4888: $checked{$item} = $settings->{'cancreate'}{$item};
4889: }
4890: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4891: foreach my $item (@creators) {
4892: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4893: $checked{$item} = 'none';
4894: }
4895: }
4896: }
4897: }
4898: my $rownum = 0;
4899: foreach my $item (@creators) {
4900: $rownum ++;
1.160.6.34 raeburn 4901: if ($checked{$item} eq '') {
4902: $checked{$item} = 'any';
1.34 raeburn 4903: }
4904: my $css_class;
4905: if ($rownum%2) {
4906: $css_class = '';
4907: } else {
4908: $css_class = ' class="LC_odd_row" ';
4909: }
4910: $datatable .= '<tr'.$css_class.'>'.
4911: '<td><span class="LC_nobreak">'.$lt{$item}.
4912: '</span></td><td align="right">';
1.160.6.34 raeburn 4913: my @options = ('any');
4914: if (ref($rules) eq 'HASH') {
4915: if (keys(%{$rules}) > 0) {
4916: push(@options,('official','unofficial'));
1.37 raeburn 4917: }
4918: }
1.160.6.34 raeburn 4919: push(@options,'none');
1.37 raeburn 4920: foreach my $option (@options) {
1.50 raeburn 4921: my $type = 'radio';
1.34 raeburn 4922: my $check = ' ';
1.160.6.34 raeburn 4923: if ($checked{$item} eq $option) {
4924: $check = ' checked="checked" ';
1.34 raeburn 4925: }
4926: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4927: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4928: $item.'" value="'.$option.'"'.$check.'/> '.
4929: $lt{$option}.'</label> </span>';
4930: }
4931: $datatable .= '</td></tr>';
4932: }
1.28 raeburn 4933: } else {
4934: my @contexts = ('author','course','domain');
4935: my @authtypes = ('int','krb4','krb5','loc');
4936: my %checked;
4937: if (ref($settings) eq 'HASH') {
4938: if (ref($settings->{'authtypes'}) eq 'HASH') {
4939: foreach my $item (@contexts) {
4940: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4941: foreach my $auth (@authtypes) {
4942: if ($settings->{'authtypes'}{$item}{$auth}) {
4943: $checked{$item}{$auth} = ' checked="checked" ';
4944: }
4945: }
4946: }
4947: }
1.27 raeburn 4948: }
1.35 raeburn 4949: } else {
4950: foreach my $item (@contexts) {
1.36 raeburn 4951: foreach my $auth (@authtypes) {
1.35 raeburn 4952: $checked{$item}{$auth} = ' checked="checked" ';
4953: }
4954: }
1.27 raeburn 4955: }
1.28 raeburn 4956: my %title = &context_names();
4957: my %authname = &authtype_names();
4958: my $rownum = 0;
4959: my $css_class;
4960: foreach my $item (@contexts) {
4961: if ($rownum%2) {
4962: $css_class = '';
4963: } else {
4964: $css_class = ' class="LC_odd_row" ';
4965: }
1.30 raeburn 4966: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4967: '<td>'.$title{$item}.
4968: '</td><td class="LC_left_item">'.
4969: '<span class="LC_nobreak">';
4970: foreach my $auth (@authtypes) {
4971: $datatable .= '<label>'.
4972: '<input type="checkbox" name="'.$item.'_auth" '.
4973: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4974: $authname{$auth}.'</label> ';
4975: }
4976: $datatable .= '</span></td></tr>';
4977: $rownum ++;
1.27 raeburn 4978: }
1.30 raeburn 4979: $$rowtotal += $rownum;
1.27 raeburn 4980: }
4981: return $datatable;
4982: }
4983:
1.160.6.34 raeburn 4984: sub print_selfcreation {
4985: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4986: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4987: if (ref($settings) eq 'HASH') {
4988: if (ref($settings->{'cancreate'}) eq 'HASH') {
4989: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4990: if (ref($createsettings) eq 'HASH') {
4991: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4992: @selfcreate = @{$createsettings->{'selfcreate'}};
4993: } elsif ($createsettings->{'selfcreate'} ne '') {
4994: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4995: @selfcreate = ('email','login','sso');
4996: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4997: @selfcreate = ($createsettings->{'selfcreate'});
4998: }
4999: }
5000: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5001: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5002: }
5003: }
5004: }
5005: }
5006: my %radiohash;
5007: my $numinrow = 4;
5008: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5009: if ($position eq 'top') {
5010: my %choices = &Apache::lonlocal::texthash (
5011: cancreate_login => 'Institutional Login',
5012: cancreate_sso => 'Institutional Single Sign On',
5013: );
5014: my @toggles = sort(keys(%choices));
5015: my %defaultchecked = (
5016: 'cancreate_login' => 'off',
5017: 'cancreate_sso' => 'off',
5018: );
1.160.6.35 raeburn 5019: my ($onclick,$itemcount);
1.160.6.34 raeburn 5020: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5021: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5022: $$rowtotal += $itemcount;
1.160.6.39 raeburn 5023:
1.160.6.34 raeburn 5024: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5025:
5026: if (ref($usertypes) eq 'HASH') {
5027: if (keys(%{$usertypes}) > 0) {
5028: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5029: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 5030: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 5031: $$rowtotal ++;
5032: }
5033: }
1.160.6.44 raeburn 5034: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5035: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5036: $fieldtitles{'inststatus'} = &mt('Institutional status');
5037: my $rem;
5038: my $numperrow = 2;
5039: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5040: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5041: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5042: '<td class="LC_left_item">'."\n".
5043: '<table><tr><td>'."\n";
5044: for (my $i=0; $i<@fields; $i++) {
5045: $rem = $i%($numperrow);
5046: if ($rem == 0) {
5047: if ($i > 0) {
5048: $datatable .= '</tr>';
5049: }
5050: $datatable .= '<tr>';
5051: }
5052: my $currval;
1.160.6.51 raeburn 5053: if (ref($createsettings) eq 'HASH') {
5054: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5055: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5056: }
1.160.6.44 raeburn 5057: }
5058: $datatable .= '<td class="LC_left_item">'.
5059: '<span class="LC_nobreak">'.
5060: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5061: 'value="'.$currval.'" size="10" /> '.
5062: $fieldtitles{$fields[$i]}.'</span></td>';
5063: }
5064: my $colsleft = $numperrow - $rem;
5065: if ($colsleft > 1 ) {
5066: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5067: ' </td>';
5068: } elsif ($colsleft == 1) {
5069: $datatable .= '<td class="LC_left_item"> </td>';
5070: }
5071: $datatable .= '</tr></table></td></tr>';
5072: $$rowtotal ++;
1.160.6.34 raeburn 5073: } elsif ($position eq 'middle') {
5074: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5075: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5076: $usertypes->{'default'} = $othertitle;
5077: if (ref($types) eq 'ARRAY') {
5078: push(@{$types},'default');
5079: $usertypes->{'default'} = $othertitle;
5080: foreach my $status (@{$types}) {
5081: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 5082: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 5083: $$rowtotal ++;
1.160.6.34 raeburn 5084: }
5085: }
5086: } else {
1.160.6.40 raeburn 5087: my %choices = &Apache::lonlocal::texthash (
5088: cancreate_email => 'E-mail address as username',
5089: );
5090: my @toggles = sort(keys(%choices));
5091: my %defaultchecked = (
5092: 'cancreate_email' => 'off',
5093: );
5094: my $itemcount = 0;
5095: my $display = 'none';
5096: if (grep(/^\Qemail\E$/,@selfcreate)) {
5097: $display = 'block';
5098: }
5099: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5100: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5101: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5102: my $usertypes = {};
5103: my $order = [];
5104: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5105: $usertypes = $domdefaults{'inststatustypes'};
5106: $order = $domdefaults{'inststatusguest'};
5107: }
5108: if (ref($order) eq 'ARRAY') {
5109: push(@{$order},'default');
5110: if (@{$order} > 1) {
5111: $usertypes->{'default'} = &mt('Other users');
5112: $additional .= '<table><tr>';
5113: foreach my $status (@{$order}) {
5114: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5115: }
5116: $additional .= '</tr><tr>';
5117: foreach my $status (@{$order}) {
5118: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 5119: }
1.160.6.40 raeburn 5120: $additional .= '</tr></table>';
1.160.6.34 raeburn 5121: } else {
1.160.6.40 raeburn 5122: $usertypes->{'default'} = &mt('All users');
5123: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 5124: }
5125: }
1.160.6.40 raeburn 5126: $additional .= '</div>'."\n";
5127:
5128: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 5129: \%choices,$$rowtotal,$onclick,$additional);
5130: $$rowtotal ++;
1.160.6.40 raeburn 5131: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 5132: $$rowtotal ++;
1.160.6.35 raeburn 5133: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5134: $numinrow = 1;
1.160.6.40 raeburn 5135: if (ref($order) eq 'ARRAY') {
5136: foreach my $status (@{$order}) {
1.160.6.35 raeburn 5137: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5138: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5139: $$rowtotal ++;
5140: }
5141: }
1.160.6.34 raeburn 5142: my ($emailrules,$emailruleorder) =
5143: &Apache::lonnet::inst_userrules($dom,'email');
5144: if (ref($emailrules) eq 'HASH') {
5145: if (keys(%{$emailrules}) > 0) {
5146: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 5147: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 5148: $$rowtotal ++;
5149: }
5150: }
1.160.6.35 raeburn 5151: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 5152: }
5153: return $datatable;
5154: }
5155:
1.160.6.40 raeburn 5156: sub email_as_username {
5157: my ($rowtotal,$processing,$type) = @_;
5158: my %choices =
5159: &Apache::lonlocal::texthash (
5160: automatic => 'Automatic approval',
5161: approval => 'Queued for approval',
5162: );
5163: my $output;
5164: foreach my $option ('automatic','approval') {
5165: my $checked;
5166: if (ref($processing) eq 'HASH') {
5167: if ($type eq '') {
5168: if (!exists($processing->{'default'})) {
5169: if ($option eq 'automatic') {
5170: $checked = ' checked="checked"';
5171: }
5172: } else {
5173: if ($processing->{'default'} eq $option) {
5174: $checked = ' checked="checked"';
5175: }
5176: }
5177: } else {
5178: if (!exists($processing->{$type})) {
5179: if ($option eq 'automatic') {
5180: $checked = ' checked="checked"';
5181: }
5182: } else {
5183: if ($processing->{$type} eq $option) {
5184: $checked = ' checked="checked"';
5185: }
5186: }
5187: }
5188: } elsif ($option eq 'automatic') {
5189: $checked = ' checked="checked"';
5190: }
5191: my $name = 'cancreate_emailprocess';
5192: if (($type ne '') && ($type ne 'default')) {
5193: $name .= '_'.$type;
5194: }
5195: $output .= '<span class="LC_nobreak"><label>'.
5196: '<input type="radio" name="'.$name.'"'.
5197: $checked.' value="'.$option.'" />'.
5198: $choices{$option}.'</label></span>';
5199: if ($type eq '') {
5200: $output .= ' ';
5201: } else {
5202: $output .= '<br />';
5203: }
5204: }
5205: $$rowtotal ++;
5206: return $output;
5207: }
5208:
1.160.6.5 raeburn 5209: sub captcha_choice {
5210: my ($context,$settings,$itemcount) = @_;
1.160.6.69 raeburn 5211: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5212: $vertext,$currver);
1.160.6.5 raeburn 5213: my %lt = &captcha_phrases();
5214: $keyentry = 'hidden';
5215: if ($context eq 'cancreate') {
1.160.6.34 raeburn 5216: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 5217: } elsif ($context eq 'login') {
5218: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5219: }
5220: if (ref($settings) eq 'HASH') {
5221: if ($settings->{'captcha'}) {
5222: $checked{$settings->{'captcha'}} = ' checked="checked"';
5223: } else {
5224: $checked{'original'} = ' checked="checked"';
5225: }
5226: if ($settings->{'captcha'} eq 'recaptcha') {
5227: $pubtext = $lt{'pub'};
5228: $privtext = $lt{'priv'};
5229: $keyentry = 'text';
1.160.6.69 raeburn 5230: $vertext = $lt{'ver'};
5231: $currver = $settings->{'recaptchaversion'};
5232: if ($currver ne '2') {
5233: $currver = 1;
5234: }
1.160.6.5 raeburn 5235: }
5236: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5237: $currpub = $settings->{'recaptchakeys'}{'public'};
5238: $currpriv = $settings->{'recaptchakeys'}{'private'};
5239: }
5240: } else {
5241: $checked{'original'} = ' checked="checked"';
5242: }
5243: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5244: my $output = '<tr'.$css_class.'>'.
5245: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5246: '<table><tr><td>'."\n";
5247: foreach my $option ('original','recaptcha','notused') {
5248: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5249: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5250: $lt{$option}.'</label></span>';
5251: unless ($option eq 'notused') {
5252: $output .= (' 'x2)."\n";
5253: }
5254: }
5255: #
5256: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5257: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5258: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5259: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5260: #
5261: $output .= '</td></tr>'."\n".
5262: '<tr><td>'."\n".
5263: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5264: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5265: $currpub.'" size="40" /></span><br />'."\n".
5266: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5267: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 5268: $currpriv.'" size="40" /></span><br />'.
5269: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5270: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5271: $currver.'" size="3" /></span><br />'.
5272: '</td></tr></table>'."\n".
1.160.6.5 raeburn 5273: '</td></tr>';
5274: return $output;
5275: }
5276:
1.32 raeburn 5277: sub user_formats_row {
5278: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5279: my $output;
5280: my %text = (
5281: 'username' => 'new usernames',
5282: 'id' => 'IDs',
1.45 raeburn 5283: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5284: );
5285: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5286: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5287: '<td><span class="LC_nobreak">';
5288: if ($type eq 'email') {
5289: $output .= &mt("Formats disallowed for $text{$type}: ");
5290: } else {
5291: $output .= &mt("Format rules to check for $text{$type}: ");
5292: }
5293: $output .= '</span></td>'.
5294: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5295: my $rem;
5296: if (ref($ruleorder) eq 'ARRAY') {
5297: for (my $i=0; $i<@{$ruleorder}; $i++) {
5298: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5299: my $rem = $i%($numinrow);
5300: if ($rem == 0) {
5301: if ($i > 0) {
5302: $output .= '</tr>';
5303: }
5304: $output .= '<tr>';
5305: }
5306: my $check = ' ';
1.39 raeburn 5307: if (ref($settings) eq 'HASH') {
5308: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5309: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5310: $check = ' checked="checked" ';
5311: }
1.27 raeburn 5312: }
5313: }
5314: $output .= '<td class="LC_left_item">'.
5315: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5316: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5317: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5318: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5319: }
5320: }
5321: $rem = @{$ruleorder}%($numinrow);
5322: }
5323: my $colsleft = $numinrow - $rem;
5324: if ($colsleft > 1 ) {
5325: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5326: ' </td>';
5327: } elsif ($colsleft == 1) {
5328: $output .= '<td class="LC_left_item"> </td>';
5329: }
5330: $output .= '</tr></table></td></tr>';
5331: return $output;
5332: }
5333:
1.34 raeburn 5334: sub usercreation_types {
5335: my %lt = &Apache::lonlocal::texthash (
5336: author => 'When adding a co-author',
5337: course => 'When adding a user to a course',
1.100 raeburn 5338: requestcrs => 'When requesting a course',
1.34 raeburn 5339: any => 'Any',
5340: official => 'Institutional only ',
5341: unofficial => 'Non-institutional only',
5342: none => 'None',
5343: );
5344: return %lt;
1.48 raeburn 5345: }
1.34 raeburn 5346:
1.160.6.34 raeburn 5347: sub selfcreation_types {
5348: my %lt = &Apache::lonlocal::texthash (
5349: selfcreate => 'User creates own account',
5350: any => 'Any',
5351: official => 'Institutional only ',
5352: unofficial => 'Non-institutional only',
5353: email => 'E-mail address',
5354: login => 'Institutional Login',
5355: sso => 'SSO',
5356: );
5357: }
5358:
1.28 raeburn 5359: sub authtype_names {
5360: my %lt = &Apache::lonlocal::texthash(
5361: int => 'Internal',
5362: krb4 => 'Kerberos 4',
5363: krb5 => 'Kerberos 5',
5364: loc => 'Local',
5365: );
5366: return %lt;
5367: }
5368:
5369: sub context_names {
5370: my %context_title = &Apache::lonlocal::texthash(
5371: author => 'Creating users when an Author',
5372: course => 'Creating users when in a course',
5373: domain => 'Creating users when a Domain Coordinator',
5374: );
5375: return %context_title;
5376: }
5377:
1.33 raeburn 5378: sub print_usermodification {
5379: my ($position,$dom,$settings,$rowtotal) = @_;
5380: my $numinrow = 4;
5381: my ($context,$datatable,$rowcount);
5382: if ($position eq 'top') {
5383: $rowcount = 0;
5384: $context = 'author';
5385: foreach my $role ('ca','aa') {
5386: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5387: $numinrow,$rowcount);
5388: $$rowtotal ++;
5389: $rowcount ++;
5390: }
1.160.6.37 raeburn 5391: } elsif ($position eq 'bottom') {
1.33 raeburn 5392: $context = 'course';
5393: $rowcount = 0;
5394: foreach my $role ('st','ep','ta','in','cr') {
5395: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5396: $numinrow,$rowcount);
5397: $$rowtotal ++;
5398: $rowcount ++;
5399: }
5400: }
5401: return $datatable;
5402: }
5403:
1.43 raeburn 5404: sub print_defaults {
1.160.6.40 raeburn 5405: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5406: my $rownum = 0;
1.160.6.80! raeburn 5407: my ($datatable,$css_class,$titles);
! 5408: unless ($position eq 'bottom') {
! 5409: $titles = &defaults_titles($dom);
! 5410: }
1.160.6.40 raeburn 5411: if ($position eq 'top') {
5412: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5413: 'datelocale_def','portal_def');
5414: my %defaults;
5415: if (ref($settings) eq 'HASH') {
5416: %defaults = %{$settings};
1.43 raeburn 5417: } else {
1.160.6.40 raeburn 5418: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5419: foreach my $item (@items) {
5420: $defaults{$item} = $domdefaults{$item};
5421: }
1.43 raeburn 5422: }
1.160.6.40 raeburn 5423: foreach my $item (@items) {
5424: if ($rownum%2) {
5425: $css_class = '';
5426: } else {
5427: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 5428: }
1.160.6.40 raeburn 5429: $datatable .= '<tr'.$css_class.'>'.
5430: '<td><span class="LC_nobreak">'.$titles->{$item}.
5431: '</span></td><td class="LC_right_item" colspan="3">';
5432: if ($item eq 'auth_def') {
5433: my @authtypes = ('internal','krb4','krb5','localauth');
5434: my %shortauth = (
5435: internal => 'int',
5436: krb4 => 'krb4',
5437: krb5 => 'krb5',
5438: localauth => 'loc'
5439: );
5440: my %authnames = &authtype_names();
5441: foreach my $auth (@authtypes) {
5442: my $checked = ' ';
5443: if ($defaults{$item} eq $auth) {
5444: $checked = ' checked="checked" ';
5445: }
5446: $datatable .= '<label><input type="radio" name="'.$item.
5447: '" value="'.$auth.'"'.$checked.'/>'.
5448: $authnames{$shortauth{$auth}}.'</label> ';
5449: }
5450: } elsif ($item eq 'timezone_def') {
5451: my $includeempty = 1;
5452: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5453: } elsif ($item eq 'datelocale_def') {
5454: my $includeempty = 1;
5455: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5456: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 5457: my $includeempty = 1;
5458: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 5459: } else {
5460: my $size;
5461: if ($item eq 'portal_def') {
5462: $size = ' size="25"';
5463: }
5464: $datatable .= '<input type="text" name="'.$item.'" value="'.
5465: $defaults{$item}.'"'.$size.' />';
5466: }
5467: $datatable .= '</td></tr>';
5468: $rownum ++;
5469: }
1.160.6.80! raeburn 5470: } elsif ($position eq 'middle') {
! 5471: my @items = ('intauth_cost','intauth_check','intauth_switch');
! 5472: my %defaults;
! 5473: if (ref($settings) eq 'HASH') {
! 5474: %defaults = %{$settings};
! 5475: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
! 5476: $defaults{'intauth_cost'} = 10;
! 5477: }
! 5478: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
! 5479: $defaults{'intauth_check'} = 0;
! 5480: }
! 5481: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
! 5482: $defaults{'intauth_switch'} = 0;
! 5483: }
! 5484: } else {
! 5485: %defaults = (
! 5486: 'intauth_cost' => 10,
! 5487: 'intauth_check' => 0,
! 5488: 'intauth_switch' => 0,
! 5489: );
! 5490: }
! 5491: foreach my $item (@items) {
! 5492: if ($rownum%2) {
! 5493: $css_class = '';
! 5494: } else {
! 5495: $css_class = ' class="LC_odd_row" ';
! 5496: }
! 5497: $datatable .= '<tr'.$css_class.'>'.
! 5498: '<td><span class="LC_nobreak">'.$titles->{$item}.
! 5499: '</span></td><td class="LC_left_item" colspan="3">';
! 5500: if ($item eq 'intauth_switch') {
! 5501: my @options = (0,1,2);
! 5502: my %optiondesc = &Apache::lonlocal::texthash (
! 5503: 0 => 'No',
! 5504: 1 => 'Yes',
! 5505: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
! 5506: );
! 5507: $datatable .= '<table width="100%">';
! 5508: foreach my $option (@options) {
! 5509: my $checked = ' ';
! 5510: if ($defaults{$item} eq $option) {
! 5511: $checked = ' checked="checked"';
! 5512: }
! 5513: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
! 5514: '<label><input type="radio" name="'.$item.
! 5515: '" value="'.$option.'"'.$checked.' />'.
! 5516: $optiondesc{$option}.'</label></span></td></tr>';
! 5517: }
! 5518: $datatable .= '</table>';
! 5519: } elsif ($item eq 'intauth_check') {
! 5520: my @options = (0,1,2);
! 5521: my %optiondesc = &Apache::lonlocal::texthash (
! 5522: 0 => 'No',
! 5523: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
! 5524: 2 => 'Yes, disallow login if stored cost is less than domain default',
! 5525: );
! 5526: $datatable .= '<table wisth="100%">';
! 5527: foreach my $option (@options) {
! 5528: my $checked = ' ';
! 5529: my $onclick;
! 5530: if ($defaults{$item} eq $option) {
! 5531: $checked = ' checked="checked"';
! 5532: }
! 5533: if ($option == 2) {
! 5534: $onclick = ' onclick="javascript:warnIntAuth(this);"';
! 5535: }
! 5536: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
! 5537: '<label><input type="radio" name="'.$item.
! 5538: '" value="'.$option.'"'.$checked.$onclick.' />'.
! 5539: $optiondesc{$option}.'</label></span></td></tr>';
! 5540: }
! 5541: $datatable .= '</table>';
! 5542: } else {
! 5543: $datatable .= '<input type="text" name="'.$item.'" value="'.
! 5544: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
! 5545: }
! 5546: $datatable .= '</td></tr>';
! 5547: $rownum ++;
! 5548: }
1.160.6.40 raeburn 5549: } else {
1.160.6.80! raeburn 5550: my %defaults;
1.160.6.40 raeburn 5551: if (ref($settings) eq 'HASH') {
5552: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5553: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5554: my $maxnum = @{$settings->{'inststatusorder'}};
5555: for (my $i=0; $i<$maxnum; $i++) {
5556: $css_class = $rownum%2?' class="LC_odd_row"':'';
5557: my $item = $settings->{'inststatusorder'}->[$i];
5558: my $title = $settings->{'inststatustypes'}->{$item};
5559: my $guestok;
5560: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5561: $guestok = 1;
5562: }
5563: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5564: $datatable .= '<tr'.$css_class.'>'.
5565: '<td><span class="LC_nobreak">'.
5566: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5567: for (my $k=0; $k<=$maxnum; $k++) {
5568: my $vpos = $k+1;
5569: my $selstr;
5570: if ($k == $i) {
5571: $selstr = ' selected="selected" ';
5572: }
5573: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5574: }
5575: my ($checkedon,$checkedoff);
5576: $checkedoff = ' checked="checked"';
5577: if ($guestok) {
5578: $checkedon = $checkedoff;
5579: $checkedoff = '';
5580: }
5581: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5582: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5583: &mt('delete').'</span></td>'.
5584: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5585: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5586: '</span></td>'.
5587: '<td class="LC_right_item"><span class="LC_nobreak">'.
5588: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5589: &mt('Yes').'</label>'.(' 'x2).
5590: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5591: &mt('No').'</label></span></td></tr>';
5592: }
5593: $css_class = $rownum%2?' class="LC_odd_row"':'';
5594: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5595: $datatable .= '<tr '.$css_class.'>'.
5596: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5597: for (my $k=0; $k<=$maxnum; $k++) {
5598: my $vpos = $k+1;
5599: my $selstr;
5600: if ($k == $maxnum) {
5601: $selstr = ' selected="selected" ';
5602: }
5603: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5604: }
5605: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 5606: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 5607: ' '.&mt('(new)').
5608: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5609: &mt('Name displayed:').
5610: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5611: '<td class="LC_right_item"><span class="LC_nobreak">'.
5612: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5613: &mt('Yes').'</label>'.(' 'x2).
5614: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5615: &mt('No').'</label></span></td></tr>';
5616: '</tr>'."\n";
5617: $rownum ++;
1.141 raeburn 5618: }
1.43 raeburn 5619: }
5620: }
5621: $$rowtotal += $rownum;
5622: return $datatable;
5623: }
5624:
1.160.6.5 raeburn 5625: sub get_languages_hash {
5626: my %langchoices;
5627: foreach my $id (&Apache::loncommon::languageids()) {
5628: my $code = &Apache::loncommon::supportedlanguagecode($id);
5629: if ($code ne '') {
5630: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5631: }
5632: }
5633: return %langchoices;
5634: }
5635:
1.43 raeburn 5636: sub defaults_titles {
1.141 raeburn 5637: my ($dom) = @_;
1.43 raeburn 5638: my %titles = &Apache::lonlocal::texthash (
5639: 'auth_def' => 'Default authentication type',
5640: 'auth_arg_def' => 'Default authentication argument',
5641: 'lang_def' => 'Default language',
1.54 raeburn 5642: 'timezone_def' => 'Default timezone',
1.68 raeburn 5643: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5644: 'portal_def' => 'Portal/Default URL',
1.160.6.80! raeburn 5645: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
! 5646: 'intauth_check' => 'Check bcrypt cost if authenticated',
! 5647: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 5648: );
1.141 raeburn 5649: if ($dom) {
5650: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5651: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5652: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5653: $protocol = 'http' if ($protocol ne 'https');
5654: if ($uint_dom) {
5655: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5656: $uint_dom);
5657: }
5658: }
1.43 raeburn 5659: return (\%titles);
5660: }
5661:
1.46 raeburn 5662: sub print_scantronformat {
5663: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5664: my $itemcount = 1;
1.60 raeburn 5665: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5666: %confhash);
1.46 raeburn 5667: my $switchserver = &check_switchserver($dom,$confname);
5668: my %lt = &Apache::lonlocal::texthash (
1.95 www 5669: default => 'Default bubblesheet format file error',
5670: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5671: );
5672: my %scantronfiles = (
5673: default => 'default.tab',
5674: custom => 'custom.tab',
5675: );
5676: foreach my $key (keys(%scantronfiles)) {
5677: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5678: .$scantronfiles{$key};
5679: }
5680: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5681: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5682: if (!$switchserver) {
5683: my $servadm = $r->dir_config('lonAdmEMail');
5684: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5685: if ($configuserok eq 'ok') {
5686: if ($author_ok eq 'ok') {
5687: my %legacyfile = (
5688: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5689: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5690: );
5691: my %md5chk;
5692: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5693: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5694: chomp($md5chk{$type});
1.46 raeburn 5695: }
5696: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5697: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5698: ($scantronurls{$type},my $error) =
1.46 raeburn 5699: &legacy_scantronformat($r,$dom,$confname,
5700: $type,$legacyfile{$type},
5701: $scantronurls{$type},
5702: $scantronfiles{$type});
1.60 raeburn 5703: if ($error ne '') {
5704: $error{$type} = $error;
5705: }
5706: }
5707: if (keys(%error) == 0) {
5708: $is_custom = 1;
5709: $confhash{'scantron'}{'scantronformat'} =
5710: $scantronurls{'custom'};
5711: my $putresult =
5712: &Apache::lonnet::put_dom('configuration',
5713: \%confhash,$dom);
5714: if ($putresult ne 'ok') {
5715: $error{'custom'} =
5716: '<span class="LC_error">'.
5717: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5718: }
1.46 raeburn 5719: }
5720: } else {
1.60 raeburn 5721: ($scantronurls{'default'},my $error) =
1.46 raeburn 5722: &legacy_scantronformat($r,$dom,$confname,
5723: 'default',$legacyfile{'default'},
5724: $scantronurls{'default'},
5725: $scantronfiles{'default'});
1.60 raeburn 5726: if ($error eq '') {
5727: $confhash{'scantron'}{'scantronformat'} = '';
5728: my $putresult =
5729: &Apache::lonnet::put_dom('configuration',
5730: \%confhash,$dom);
5731: if ($putresult ne 'ok') {
5732: $error{'default'} =
5733: '<span class="LC_error">'.
5734: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5735: }
5736: } else {
5737: $error{'default'} = $error;
5738: }
1.46 raeburn 5739: }
5740: }
5741: }
5742: } else {
1.95 www 5743: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5744: }
5745: }
5746: if (ref($settings) eq 'HASH') {
5747: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5748: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5749: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5750: $scantronurl = '';
5751: } else {
5752: $scantronurl = $settings->{'scantronformat'};
5753: }
5754: $is_custom = 1;
5755: } else {
5756: $scantronurl = $scantronurls{'default'};
5757: }
5758: } else {
1.60 raeburn 5759: if ($is_custom) {
5760: $scantronurl = $scantronurls{'custom'};
5761: } else {
5762: $scantronurl = $scantronurls{'default'};
5763: }
1.46 raeburn 5764: }
5765: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5766: $datatable .= '<tr'.$css_class.'>';
5767: if (!$is_custom) {
1.65 raeburn 5768: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5769: '<span class="LC_nobreak">';
1.46 raeburn 5770: if ($scantronurl) {
1.160.6.21 raeburn 5771: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5772: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5773: } else {
5774: $datatable = &mt('File unavailable for display');
5775: }
1.65 raeburn 5776: $datatable .= '</span></td>';
1.60 raeburn 5777: if (keys(%error) == 0) {
5778: $datatable .= '<td valign="bottom">';
5779: if (!$switchserver) {
5780: $datatable .= &mt('Upload:').'<br />';
5781: }
5782: } else {
5783: my $errorstr;
5784: foreach my $key (sort(keys(%error))) {
5785: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5786: }
5787: $datatable .= '<td>'.$errorstr;
5788: }
1.46 raeburn 5789: } else {
5790: if (keys(%error) > 0) {
5791: my $errorstr;
5792: foreach my $key (sort(keys(%error))) {
5793: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5794: }
1.60 raeburn 5795: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5796: } elsif ($scantronurl) {
1.160.6.26 raeburn 5797: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 5798: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5799: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 5800: $link.
5801: '<label><input type="checkbox" name="scantronformat_del"'.
5802: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5803: '<td><span class="LC_nobreak"> '.
5804: &mt('Replace:').'</span><br />';
1.46 raeburn 5805: }
5806: }
5807: if (keys(%error) == 0) {
5808: if ($switchserver) {
5809: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5810: } else {
1.65 raeburn 5811: $datatable .='<span class="LC_nobreak"> '.
5812: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5813: }
5814: }
5815: $datatable .= '</td></tr>';
5816: $$rowtotal ++;
5817: return $datatable;
5818: }
5819:
5820: sub legacy_scantronformat {
5821: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5822: my ($url,$error);
5823: my @statinfo = &Apache::lonnet::stat_file($newurl);
5824: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5825: (my $result,$url) =
5826: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5827: '','',$newfile);
5828: if ($result ne 'ok') {
1.130 raeburn 5829: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5830: }
5831: }
5832: return ($url,$error);
5833: }
1.43 raeburn 5834:
1.49 raeburn 5835: sub print_coursecategories {
1.57 raeburn 5836: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5837: my $datatable;
5838: if ($position eq 'top') {
1.160.6.42 raeburn 5839: my (%checked);
5840: my @catitems = ('unauth','auth');
5841: my @cattypes = ('std','domonly','codesrch','none');
5842: $checked{'unauth'} = 'std';
5843: $checked{'auth'} = 'std';
5844: if (ref($settings) eq 'HASH') {
5845: foreach my $type (@cattypes) {
5846: if ($type eq $settings->{'unauth'}) {
5847: $checked{'unauth'} = $type;
5848: }
5849: if ($type eq $settings->{'auth'}) {
5850: $checked{'auth'} = $type;
5851: }
5852: }
5853: }
5854: my %lt = &Apache::lonlocal::texthash (
5855: unauth => 'Catalog type for unauthenticated users',
5856: auth => 'Catalog type for authenticated users',
5857: none => 'No catalog',
5858: std => 'Standard catalog',
5859: domonly => 'Domain-only catalog',
5860: codesrch => "Code search form",
5861: );
5862: my $itemcount = 0;
5863: foreach my $item (@catitems) {
5864: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5865: $datatable .= '<tr '.$css_class.'>'.
5866: '<td>'.$lt{$item}.'</td>'.
5867: '<td class="LC_right_item"><span class="LC_nobreak">';
5868: foreach my $type (@cattypes) {
5869: my $ischecked;
5870: if ($checked{$item} eq $type) {
5871: $ischecked=' checked="checked"';
5872: }
5873: $datatable .= '<label>'.
5874: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5875: ' />'.$lt{$type}.'</label> ';
5876: }
5877: $datatable .= '</td></tr>';
5878: $itemcount ++;
5879: }
5880: $$rowtotal += $itemcount;
5881: } elsif ($position eq 'middle') {
1.57 raeburn 5882: my $toggle_cats_crs = ' ';
5883: my $toggle_cats_dom = ' checked="checked" ';
5884: my $can_cat_crs = ' ';
5885: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5886: my $toggle_catscomm_comm = ' ';
5887: my $toggle_catscomm_dom = ' checked="checked" ';
5888: my $can_catcomm_comm = ' ';
5889: my $can_catcomm_dom = ' checked="checked" ';
5890:
1.57 raeburn 5891: if (ref($settings) eq 'HASH') {
5892: if ($settings->{'togglecats'} eq 'crs') {
5893: $toggle_cats_crs = $toggle_cats_dom;
5894: $toggle_cats_dom = ' ';
5895: }
5896: if ($settings->{'categorize'} eq 'crs') {
5897: $can_cat_crs = $can_cat_dom;
5898: $can_cat_dom = ' ';
5899: }
1.120 raeburn 5900: if ($settings->{'togglecatscomm'} eq 'comm') {
5901: $toggle_catscomm_comm = $toggle_catscomm_dom;
5902: $toggle_catscomm_dom = ' ';
5903: }
5904: if ($settings->{'categorizecomm'} eq 'comm') {
5905: $can_catcomm_comm = $can_catcomm_dom;
5906: $can_catcomm_dom = ' ';
5907: }
1.57 raeburn 5908: }
5909: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5910: togglecats => 'Show/Hide a course in catalog',
5911: togglecatscomm => 'Show/Hide a community in catalog',
5912: categorize => 'Assign a category to a course',
5913: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5914: );
5915: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5916: dom => 'Set in Domain',
5917: crs => 'Set in Course',
5918: comm => 'Set in Community',
1.57 raeburn 5919: );
5920: $datatable = '<tr class="LC_odd_row">'.
5921: '<td>'.$title{'togglecats'}.'</td>'.
5922: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5923: '<input type="radio" name="togglecats"'.
5924: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5925: '<label><input type="radio" name="togglecats"'.
5926: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5927: '</tr><tr>'.
5928: '<td>'.$title{'categorize'}.'</td>'.
5929: '<td class="LC_right_item"><span class="LC_nobreak">'.
5930: '<label><input type="radio" name="categorize"'.
5931: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5932: '<label><input type="radio" name="categorize"'.
5933: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5934: '</tr><tr class="LC_odd_row">'.
5935: '<td>'.$title{'togglecatscomm'}.'</td>'.
5936: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5937: '<input type="radio" name="togglecatscomm"'.
5938: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5939: '<label><input type="radio" name="togglecatscomm"'.
5940: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5941: '</tr><tr>'.
5942: '<td>'.$title{'categorizecomm'}.'</td>'.
5943: '<td class="LC_right_item"><span class="LC_nobreak">'.
5944: '<label><input type="radio" name="categorizecomm"'.
5945: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5946: '<label><input type="radio" name="categorizecomm"'.
5947: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5948: '</tr>';
1.120 raeburn 5949: $$rowtotal += 4;
1.57 raeburn 5950: } else {
5951: my $css_class;
5952: my $itemcount = 1;
5953: my $cathash;
5954: if (ref($settings) eq 'HASH') {
5955: $cathash = $settings->{'cats'};
5956: }
5957: if (ref($cathash) eq 'HASH') {
5958: my (@cats,@trails,%allitems,%idx,@jsarray);
5959: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5960: \%allitems,\%idx,\@jsarray);
5961: my $maxdepth = scalar(@cats);
5962: my $colattrib = '';
5963: if ($maxdepth > 2) {
5964: $colattrib = ' colspan="2" ';
5965: }
5966: my @path;
5967: if (@cats > 0) {
5968: if (ref($cats[0]) eq 'ARRAY') {
5969: my $numtop = @{$cats[0]};
5970: my $maxnum = $numtop;
1.120 raeburn 5971: my %default_names = (
5972: instcode => &mt('Official courses'),
5973: communities => &mt('Communities'),
5974: );
5975:
5976: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5977: ($cathash->{'instcode::0'} eq '') ||
5978: (!grep(/^communities$/,@{$cats[0]})) ||
5979: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5980: $maxnum ++;
5981: }
5982: my $lastidx;
5983: for (my $i=0; $i<$numtop; $i++) {
5984: my $parent = $cats[0][$i];
5985: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5986: my $item = &escape($parent).'::0';
5987: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5988: $lastidx = $idx{$item};
5989: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5990: .'<select name="'.$item.'"'.$chgstr.'>';
5991: for (my $k=0; $k<=$maxnum; $k++) {
5992: my $vpos = $k+1;
5993: my $selstr;
5994: if ($k == $i) {
5995: $selstr = ' selected="selected" ';
5996: }
5997: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5998: }
1.160.6.29 raeburn 5999: $datatable .= '</select></span></td><td>';
1.120 raeburn 6000: if ($parent eq 'instcode' || $parent eq 'communities') {
6001: $datatable .= '<span class="LC_nobreak">'
6002: .$default_names{$parent}.'</span>';
6003: if ($parent eq 'instcode') {
6004: $datatable .= '<br /><span class="LC_nobreak">('
6005: .&mt('with institutional codes')
6006: .')</span></td><td'.$colattrib.'>';
6007: } else {
6008: $datatable .= '<table><tr><td>';
6009: }
6010: $datatable .= '<span class="LC_nobreak">'
6011: .'<label><input type="radio" name="'
6012: .$parent.'" value="1" checked="checked" />'
6013: .&mt('Display').'</label>';
6014: if ($parent eq 'instcode') {
6015: $datatable .= ' ';
6016: } else {
6017: $datatable .= '</span></td></tr><tr><td>'
6018: .'<span class="LC_nobreak">';
6019: }
6020: $datatable .= '<label><input type="radio" name="'
6021: .$parent.'" value="0" />'
6022: .&mt('Do not display').'</label></span>';
6023: if ($parent eq 'communities') {
6024: $datatable .= '</td></tr></table>';
6025: }
6026: $datatable .= '</td>';
1.57 raeburn 6027: } else {
6028: $datatable .= $parent
1.160.6.29 raeburn 6029: .' <span class="LC_nobreak"><label>'
6030: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6031: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6032: }
6033: my $depth = 1;
6034: push(@path,$parent);
6035: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6036: pop(@path);
6037: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6038: $itemcount ++;
6039: }
1.48 raeburn 6040: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6041: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6042: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6043: for (my $k=0; $k<=$maxnum; $k++) {
6044: my $vpos = $k+1;
6045: my $selstr;
1.57 raeburn 6046: if ($k == $numtop) {
1.48 raeburn 6047: $selstr = ' selected="selected" ';
6048: }
6049: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6050: }
1.59 bisitz 6051: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6052: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6053: .'</tr>'."\n";
1.48 raeburn 6054: $itemcount ++;
1.120 raeburn 6055: foreach my $default ('instcode','communities') {
6056: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6057: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6058: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6059: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6060: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6061: for (my $k=0; $k<=$maxnum; $k++) {
6062: my $vpos = $k+1;
6063: my $selstr;
6064: if ($k == $maxnum) {
6065: $selstr = ' selected="selected" ';
6066: }
6067: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6068: }
1.120 raeburn 6069: $datatable .= '</select></span></td>'.
6070: '<td><span class="LC_nobreak">'.
6071: $default_names{$default}.'</span>';
6072: if ($default eq 'instcode') {
6073: $datatable .= '<br /><span class="LC_nobreak">('
6074: .&mt('with institutional codes').')</span>';
6075: }
6076: $datatable .= '</td>'
6077: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6078: .&mt('Display').'</label> '
6079: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6080: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6081: }
6082: }
6083: }
1.57 raeburn 6084: } else {
6085: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6086: }
6087: } else {
1.160.6.42 raeburn 6088: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6089: .&initialize_categories($itemcount);
1.48 raeburn 6090: }
1.57 raeburn 6091: $$rowtotal += $itemcount;
1.48 raeburn 6092: }
6093: return $datatable;
6094: }
6095:
1.69 raeburn 6096: sub print_serverstatuses {
6097: my ($dom,$settings,$rowtotal) = @_;
6098: my $datatable;
6099: my @pages = &serverstatus_pages();
6100: my (%namedaccess,%machineaccess);
6101: foreach my $type (@pages) {
6102: $namedaccess{$type} = '';
6103: $machineaccess{$type}= '';
6104: }
6105: if (ref($settings) eq 'HASH') {
6106: foreach my $type (@pages) {
6107: if (exists($settings->{$type})) {
6108: if (ref($settings->{$type}) eq 'HASH') {
6109: foreach my $key (keys(%{$settings->{$type}})) {
6110: if ($key eq 'namedusers') {
6111: $namedaccess{$type} = $settings->{$type}->{$key};
6112: } elsif ($key eq 'machines') {
6113: $machineaccess{$type} = $settings->{$type}->{$key};
6114: }
6115: }
6116: }
6117: }
6118: }
6119: }
1.81 raeburn 6120: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6121: my $rownum = 0;
6122: my $css_class;
6123: foreach my $type (@pages) {
6124: $rownum ++;
6125: $css_class = $rownum%2?' class="LC_odd_row"':'';
6126: $datatable .= '<tr'.$css_class.'>'.
6127: '<td><span class="LC_nobreak">'.
6128: $titles->{$type}.'</span></td>'.
6129: '<td class="LC_left_item">'.
6130: '<input type="text" name="'.$type.'_namedusers" '.
6131: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6132: '<td class="LC_right_item">'.
6133: '<span class="LC_nobreak">'.
6134: '<input type="text" name="'.$type.'_machines" '.
6135: 'value="'.$machineaccess{$type}.'" size="10" />'.
6136: '</td></tr>'."\n";
6137: }
6138: $$rowtotal += $rownum;
6139: return $datatable;
6140: }
6141:
6142: sub serverstatus_pages {
6143: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 6144: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 6145: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 6146: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6147: }
6148:
1.160.6.40 raeburn 6149: sub defaults_javascript {
6150: my ($settings) = @_;
1.160.6.80! raeburn 6151: 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.');
! 6152: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
! 6153: &js_escape(\$intauthcheck);
! 6154: &js_escape(\$intauthcost);
! 6155: my $intauthjs = <<"ENDSCRIPT";
! 6156:
! 6157: function warnIntAuth(field) {
! 6158: if (field.name == 'intauth_check') {
! 6159: if (field.value == '2') {
! 6160: alert('$intauthcheck');
! 6161: }
! 6162: }
! 6163: if (field.name == 'intauth_cost') {
! 6164: field.value.replace(/\s/g,'');
! 6165: if (field.value != '') {
! 6166: var regexdigit=/^\\d+\$/;
! 6167: if (!regexdigit.test(field.value)) {
! 6168: alert('$intauthcost');
! 6169: }
! 6170: }
! 6171: }
! 6172: return;
! 6173: }
! 6174:
! 6175: ENDSCRIPT
! 6176:
! 6177: if (ref($settings) ne 'HASH') {
! 6178: return &Apache::lonhtmlcommon::scripttag($intauthjs);
! 6179: }
1.160.6.40 raeburn 6180: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6181: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6182: if ($maxnum eq '') {
6183: $maxnum = 0;
6184: }
6185: $maxnum ++;
1.160.6.51 raeburn 6186: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 6187: return <<"ENDSCRIPT";
6188: <script type="text/javascript">
6189: // <![CDATA[
6190: function reorderTypes(form,caller) {
6191: var changedVal;
6192: $jstext
6193: var newpos = 'addinststatus_pos';
6194: var current = new Array;
6195: var maxh = $maxnum;
6196: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6197: var oldVal;
6198: if (caller == newpos) {
6199: changedVal = newitemVal;
6200: } else {
6201: var curritem = 'inststatus_pos_'+caller;
6202: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6203: current[newitemVal] = newpos;
6204: }
6205: for (var i=0; i<inststatuses.length; i++) {
6206: if (inststatuses[i] != caller) {
6207: var elementName = 'inststatus_pos_'+inststatuses[i];
6208: if (form.elements[elementName]) {
6209: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6210: current[currVal] = elementName;
6211: }
6212: }
6213: }
6214: for (var j=0; j<maxh; j++) {
6215: if (current[j] == undefined) {
6216: oldVal = j;
6217: }
6218: }
6219: if (oldVal < changedVal) {
6220: for (var k=oldVal+1; k<=changedVal ; k++) {
6221: var elementName = current[k];
6222: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6223: }
6224: } else {
6225: for (var k=changedVal; k<oldVal; k++) {
6226: var elementName = current[k];
6227: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6228: }
6229: }
6230: return;
6231: }
6232:
1.160.6.80! raeburn 6233: $intauthjs
! 6234:
1.160.6.40 raeburn 6235: // ]]>
6236: </script>
6237:
6238: ENDSCRIPT
1.160.6.80! raeburn 6239: } else {
! 6240: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40 raeburn 6241: }
6242: }
6243:
1.49 raeburn 6244: sub coursecategories_javascript {
6245: my ($settings) = @_;
1.57 raeburn 6246: my ($output,$jstext,$cathash);
1.49 raeburn 6247: if (ref($settings) eq 'HASH') {
1.57 raeburn 6248: $cathash = $settings->{'cats'};
6249: }
6250: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6251: my (@cats,@jsarray,%idx);
1.57 raeburn 6252: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6253: if (@jsarray > 0) {
6254: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6255: for (my $i=0; $i<@jsarray; $i++) {
6256: if (ref($jsarray[$i]) eq 'ARRAY') {
6257: my $catstr = join('","',@{$jsarray[$i]});
6258: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6259: }
6260: }
6261: }
6262: } else {
6263: $jstext = ' var categories = Array(1);'."\n".
6264: ' categories[0] = Array("instcode_pos");'."\n";
6265: }
1.160.6.42 raeburn 6266: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6267: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 6268: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6269: &js_escape(\$instcode_reserved);
6270: &js_escape(\$communities_reserved);
6271: &js_escape(\$choose_again);
1.49 raeburn 6272: $output = <<"ENDSCRIPT";
6273: <script type="text/javascript">
1.109 raeburn 6274: // <![CDATA[
1.49 raeburn 6275: function reorderCats(form,parent,item,idx) {
6276: var changedVal;
6277: $jstext
6278: var newpos = 'addcategory_pos';
6279: if (parent == '') {
6280: var has_instcode = 0;
6281: var maxtop = categories[idx].length;
6282: for (var j=0; j<maxtop; j++) {
6283: if (categories[idx][j] == 'instcode::0') {
6284: has_instcode == 1;
6285: }
6286: }
6287: if (has_instcode == 0) {
6288: categories[idx][maxtop] = 'instcode_pos';
6289: }
6290: } else {
6291: newpos += '_'+parent;
6292: }
6293: var maxh = 1 + categories[idx].length;
6294: var current = new Array;
6295: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6296: if (item == newpos) {
6297: changedVal = newitemVal;
6298: } else {
6299: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6300: current[newitemVal] = newpos;
6301: }
6302: for (var i=0; i<categories[idx].length; i++) {
6303: var elementName = categories[idx][i];
6304: if (elementName != item) {
6305: if (form.elements[elementName]) {
6306: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6307: current[currVal] = elementName;
6308: }
6309: }
6310: }
6311: var oldVal;
6312: for (var j=0; j<maxh; j++) {
6313: if (current[j] == undefined) {
6314: oldVal = j;
6315: }
6316: }
6317: if (oldVal < changedVal) {
6318: for (var k=oldVal+1; k<=changedVal ; k++) {
6319: var elementName = current[k];
6320: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6321: }
6322: } else {
6323: for (var k=changedVal; k<oldVal; k++) {
6324: var elementName = current[k];
6325: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6326: }
6327: }
6328: return;
6329: }
1.120 raeburn 6330:
6331: function categoryCheck(form) {
6332: if (form.elements['addcategory_name'].value == 'instcode') {
6333: alert('$instcode_reserved\\n$choose_again');
6334: return false;
6335: }
6336: if (form.elements['addcategory_name'].value == 'communities') {
6337: alert('$communities_reserved\\n$choose_again');
6338: return false;
6339: }
6340: return true;
6341: }
6342:
1.109 raeburn 6343: // ]]>
1.49 raeburn 6344: </script>
6345:
6346: ENDSCRIPT
6347: return $output;
6348: }
6349:
1.48 raeburn 6350: sub initialize_categories {
6351: my ($itemcount) = @_;
1.120 raeburn 6352: my ($datatable,$css_class,$chgstr);
6353: my %default_names = (
6354: instcode => 'Official courses (with institutional codes)',
6355: communities => 'Communities',
6356: );
6357: my $select0 = ' selected="selected"';
6358: my $select1 = '';
6359: foreach my $default ('instcode','communities') {
6360: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6361: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
6362: if ($default eq 'communities') {
6363: $select1 = $select0;
6364: $select0 = '';
6365: }
6366: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6367: .'<select name="'.$default.'_pos">'
6368: .'<option value="0"'.$select0.'>1</option>'
6369: .'<option value="1"'.$select1.'>2</option>'
6370: .'<option value="2">3</option></select> '
6371: .$default_names{$default}
6372: .'</span></td><td><span class="LC_nobreak">'
6373: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6374: .&mt('Display').'</label> <label>'
6375: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6376: .'</label></span></td></tr>';
1.120 raeburn 6377: $itemcount ++;
6378: }
1.48 raeburn 6379: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6380: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6381: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6382: .'<select name="addcategory_pos"'.$chgstr.'>'
6383: .'<option value="0">1</option>'
6384: .'<option value="1">2</option>'
6385: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6386: .&mt('Add category').'</td><td>'.&mt('Name:')
6387: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6388: return $datatable;
6389: }
6390:
6391: sub build_category_rows {
1.49 raeburn 6392: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6393: my ($text,$name,$item,$chgstr);
1.48 raeburn 6394: if (ref($cats) eq 'ARRAY') {
6395: my $maxdepth = scalar(@{$cats});
6396: if (ref($cats->[$depth]) eq 'HASH') {
6397: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6398: my $numchildren = @{$cats->[$depth]{$parent}};
6399: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 6400: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6401: my ($idxnum,$parent_name,$parent_item);
6402: my $higher = $depth - 1;
6403: if ($higher == 0) {
6404: $parent_name = &escape($parent).'::'.$higher;
6405: } else {
6406: if (ref($path) eq 'ARRAY') {
6407: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6408: }
6409: }
6410: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6411: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6412: if ($j < $numchildren) {
1.48 raeburn 6413: $name = $cats->[$depth]{$parent}[$j];
6414: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6415: $idxnum = $idx->{$item};
6416: } else {
6417: $name = $parent_name;
6418: $item = $parent_item;
1.48 raeburn 6419: }
1.49 raeburn 6420: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6421: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6422: for (my $i=0; $i<=$numchildren; $i++) {
6423: my $vpos = $i+1;
6424: my $selstr;
6425: if ($j == $i) {
6426: $selstr = ' selected="selected" ';
6427: }
6428: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6429: }
6430: $text .= '</select> ';
6431: if ($j < $numchildren) {
6432: my $deeper = $depth+1;
6433: $text .= $name.' '
6434: .'<label><input type="checkbox" name="deletecategory" value="'
6435: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6436: if(ref($path) eq 'ARRAY') {
6437: push(@{$path},$name);
1.49 raeburn 6438: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6439: pop(@{$path});
6440: }
6441: } else {
1.59 bisitz 6442: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 6443: if ($j == $numchildren) {
6444: $text .= $name;
6445: } else {
6446: $text .= $item;
6447: }
6448: $text .= '" value="" />';
6449: }
6450: $text .= '</td></tr>';
6451: }
6452: $text .= '</table></td>';
6453: } else {
6454: my $higher = $depth-1;
6455: if ($higher == 0) {
6456: $name = &escape($parent).'::'.$higher;
6457: } else {
6458: if (ref($path) eq 'ARRAY') {
6459: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6460: }
6461: }
6462: my $colspan;
6463: if ($parent ne 'instcode') {
6464: $colspan = $maxdepth - $depth - 1;
6465: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
6466: }
6467: }
6468: }
6469: }
6470: return $text;
6471: }
6472:
1.33 raeburn 6473: sub modifiable_userdata_row {
1.160.6.35 raeburn 6474: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6475: my ($role,$rolename,$statustype);
6476: $role = $item;
1.160.6.34 raeburn 6477: if ($context eq 'cancreate') {
1.160.6.35 raeburn 6478: if ($item =~ /^emailusername_(.+)$/) {
6479: $statustype = $1;
6480: $role = 'emailusername';
6481: if (ref($usertypes) eq 'HASH') {
6482: if ($usertypes->{$statustype}) {
6483: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6484: } else {
6485: $rolename = &mt('Data provided by user');
6486: }
6487: }
1.160.6.34 raeburn 6488: }
6489: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6490: if (ref($usertypes) eq 'HASH') {
6491: $rolename = $usertypes->{$role};
6492: } else {
6493: $rolename = $role;
6494: }
1.33 raeburn 6495: } else {
1.63 raeburn 6496: if ($role eq 'cr') {
6497: $rolename = &mt('Custom role');
6498: } else {
6499: $rolename = &Apache::lonnet::plaintext($role);
6500: }
1.33 raeburn 6501: }
1.160.6.34 raeburn 6502: my (@fields,%fieldtitles);
6503: if (ref($fieldsref) eq 'ARRAY') {
6504: @fields = @{$fieldsref};
6505: } else {
6506: @fields = ('lastname','firstname','middlename','generation',
6507: 'permanentemail','id');
6508: }
6509: if ((ref($titlesref) eq 'HASH')) {
6510: %fieldtitles = %{$titlesref};
6511: } else {
6512: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6513: }
1.33 raeburn 6514: my $output;
6515: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6516: $output = '<tr '.$css_class.'>'.
6517: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6518: '<td class="LC_left_item" colspan="2"><table>';
6519: my $rem;
6520: my %checks;
6521: if (ref($settings) eq 'HASH') {
6522: if (ref($settings->{$context}) eq 'HASH') {
6523: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 6524: my $hashref = $settings->{$context}->{$role};
6525: if ($role eq 'emailusername') {
6526: if ($statustype) {
6527: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6528: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 6529: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 6530: foreach my $field (@fields) {
6531: if ($hashref->{$field}) {
6532: $checks{$field} = $hashref->{$field};
6533: }
6534: }
6535: }
6536: }
6537: }
6538: } else {
6539: if (ref($hashref) eq 'HASH') {
6540: foreach my $field (@fields) {
6541: if ($hashref->{$field}) {
6542: $checks{$field} = ' checked="checked" ';
6543: }
6544: }
1.33 raeburn 6545: }
6546: }
6547: }
6548: }
6549: }
1.160.6.39 raeburn 6550:
1.33 raeburn 6551: for (my $i=0; $i<@fields; $i++) {
6552: my $rem = $i%($numinrow);
6553: if ($rem == 0) {
6554: if ($i > 0) {
6555: $output .= '</tr>';
6556: }
6557: $output .= '<tr>';
6558: }
6559: my $check = ' ';
1.160.6.35 raeburn 6560: unless ($role eq 'emailusername') {
6561: if (exists($checks{$fields[$i]})) {
6562: $check = $checks{$fields[$i]}
6563: } else {
6564: if ($role eq 'st') {
6565: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 6566: $check = ' checked="checked" ';
1.160.6.35 raeburn 6567: }
1.33 raeburn 6568: }
6569: }
6570: }
6571: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 6572: '<span class="LC_nobreak">';
6573: if ($role eq 'emailusername') {
6574: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6575: $checks{$fields[$i]} = 'omit';
6576: }
6577: foreach my $option ('required','optional','omit') {
6578: my $checked='';
6579: if ($checks{$fields[$i]} eq $option) {
6580: $checked='checked="checked" ';
6581: }
6582: $output .= '<label>'.
6583: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6584: &mt($option).'</label>'.(' ' x2);
6585: }
6586: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6587: } else {
6588: $output .= '<label>'.
6589: '<input type="checkbox" name="canmodify_'.$role.'" '.
6590: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6591: '</label>';
6592: }
6593: $output .= '</span></td>';
1.33 raeburn 6594: $rem = @fields%($numinrow);
6595: }
6596: my $colsleft = $numinrow - $rem;
6597: if ($colsleft > 1 ) {
6598: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6599: ' </td>';
6600: } elsif ($colsleft == 1) {
6601: $output .= '<td class="LC_left_item"> </td>';
6602: }
6603: $output .= '</tr></table></td></tr>';
6604: return $output;
6605: }
1.28 raeburn 6606:
1.93 raeburn 6607: sub insttypes_row {
1.160.6.34 raeburn 6608: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6609: my %lt = &Apache::lonlocal::texthash (
6610: cansearch => 'Users allowed to search',
6611: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6612: lockablenames => 'User preference to lock name',
1.93 raeburn 6613: );
6614: my $showdom;
6615: if ($context eq 'cansearch') {
6616: $showdom = ' ('.$dom.')';
6617: }
1.160.6.5 raeburn 6618: my $class = 'LC_left_item';
6619: if ($context eq 'statustocreate') {
6620: $class = 'LC_right_item';
6621: }
1.160.6.34 raeburn 6622: my $css_class = ' class="LC_odd_row"';
6623: if ($rownum ne '') {
6624: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6625: }
6626: my $output = '<tr'.$css_class.'>'.
6627: '<td>'.$lt{$context}.$showdom.
6628: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6629: my $rem;
6630: if (ref($types) eq 'ARRAY') {
6631: for (my $i=0; $i<@{$types}; $i++) {
6632: if (defined($usertypes->{$types->[$i]})) {
6633: my $rem = $i%($numinrow);
6634: if ($rem == 0) {
6635: if ($i > 0) {
6636: $output .= '</tr>';
6637: }
6638: $output .= '<tr>';
1.23 raeburn 6639: }
1.26 raeburn 6640: my $check = ' ';
1.99 raeburn 6641: if (ref($settings) eq 'HASH') {
6642: if (ref($settings->{$context}) eq 'ARRAY') {
6643: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6644: $check = ' checked="checked" ';
6645: }
6646: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6647: $check = ' checked="checked" ';
6648: }
1.23 raeburn 6649: }
1.26 raeburn 6650: $output .= '<td class="LC_left_item">'.
6651: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6652: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6653: 'value="'.$types->[$i].'"'.$check.'/>'.
6654: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6655: }
6656: }
1.26 raeburn 6657: $rem = @{$types}%($numinrow);
1.23 raeburn 6658: }
6659: my $colsleft = $numinrow - $rem;
1.131 raeburn 6660: if (($rem == 0) && (@{$types} > 0)) {
6661: $output .= '<tr>';
6662: }
1.23 raeburn 6663: if ($colsleft > 1) {
1.25 raeburn 6664: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6665: } else {
1.25 raeburn 6666: $output .= '<td class="LC_left_item">';
1.23 raeburn 6667: }
6668: my $defcheck = ' ';
1.99 raeburn 6669: if (ref($settings) eq 'HASH') {
6670: if (ref($settings->{$context}) eq 'ARRAY') {
6671: if (grep(/^default$/,@{$settings->{$context}})) {
6672: $defcheck = ' checked="checked" ';
6673: }
6674: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6675: $defcheck = ' checked="checked" ';
6676: }
1.23 raeburn 6677: }
1.25 raeburn 6678: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6679: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6680: 'value="default"'.$defcheck.'/>'.
6681: $othertitle.'</label></span></td>'.
6682: '</tr></table></td></tr>';
6683: return $output;
1.23 raeburn 6684: }
6685:
6686: sub sorted_searchtitles {
6687: my %searchtitles = &Apache::lonlocal::texthash(
6688: 'uname' => 'username',
6689: 'lastname' => 'last name',
6690: 'lastfirst' => 'last name, first name',
6691: );
6692: my @titleorder = ('uname','lastname','lastfirst');
6693: return (\%searchtitles,\@titleorder);
6694: }
6695:
1.25 raeburn 6696: sub sorted_searchtypes {
6697: my %srchtypes_desc = (
6698: exact => 'is exact match',
6699: contains => 'contains ..',
6700: begins => 'begins with ..',
6701: );
6702: my @srchtypeorder = ('exact','begins','contains');
6703: return (\%srchtypes_desc,\@srchtypeorder);
6704: }
6705:
1.3 raeburn 6706: sub usertype_update_row {
6707: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6708: my $datatable;
6709: my $numinrow = 4;
6710: foreach my $type (@{$types}) {
6711: if (defined($usertypes->{$type})) {
6712: $$rownums ++;
6713: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6714: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6715: '</td><td class="LC_left_item"><table>';
6716: for (my $i=0; $i<@{$fields}; $i++) {
6717: my $rem = $i%($numinrow);
6718: if ($rem == 0) {
6719: if ($i > 0) {
6720: $datatable .= '</tr>';
6721: }
6722: $datatable .= '<tr>';
6723: }
6724: my $check = ' ';
1.39 raeburn 6725: if (ref($settings) eq 'HASH') {
6726: if (ref($settings->{'fields'}) eq 'HASH') {
6727: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6728: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6729: $check = ' checked="checked" ';
6730: }
1.3 raeburn 6731: }
6732: }
6733: }
6734:
6735: if ($i == @{$fields}-1) {
6736: my $colsleft = $numinrow - $rem;
6737: if ($colsleft > 1) {
6738: $datatable .= '<td colspan="'.$colsleft.'">';
6739: } else {
6740: $datatable .= '<td>';
6741: }
6742: } else {
6743: $datatable .= '<td>';
6744: }
1.8 raeburn 6745: $datatable .= '<span class="LC_nobreak"><label>'.
6746: '<input type="checkbox" name="updateable_'.$type.
6747: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6748: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6749: }
6750: $datatable .= '</tr></table></td></tr>';
6751: }
6752: }
6753: return $datatable;
1.1 raeburn 6754: }
6755:
6756: sub modify_login {
1.160.6.24 raeburn 6757: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 6758: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6759: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6760: %title = ( coursecatalog => 'Display course catalog',
6761: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 6762: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 6763: newuser => 'Link for visitors to create a user account',
6764: loginheader => 'Log-in box header');
6765: @offon = ('off','on');
1.112 raeburn 6766: if (ref($domconfig{login}) eq 'HASH') {
6767: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6768: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6769: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6770: }
6771: }
6772: }
1.9 raeburn 6773: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6774: \%domconfig,\%loginhash);
1.160.6.14 raeburn 6775: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6776: foreach my $item (@toggles) {
6777: $loginhash{login}{$item} = $env{'form.'.$item};
6778: }
1.41 raeburn 6779: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6780: if (ref($colchanges{'login'}) eq 'HASH') {
6781: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6782: \%loginhash);
6783: }
1.110 raeburn 6784:
1.149 raeburn 6785: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 6786: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6787: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6788: if (keys(%servers) > 1) {
6789: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6790: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6791: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6792: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6793: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6794: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6795: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6796: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6797: $changes{'loginvia'}{$lonhost} = 1;
6798: } else {
6799: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6800: $changes{'loginvia'}{$lonhost} = 1;
6801: }
6802: } else {
6803: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6804: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6805: $changes{'loginvia'}{$lonhost} = 1;
6806: }
6807: }
6808: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6809: foreach my $item (@loginvia_attribs) {
6810: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6811: }
6812: } else {
6813: foreach my $item (@loginvia_attribs) {
6814: my $new = $env{'form.'.$lonhost.'_'.$item};
6815: if (($item eq 'serverpath') && ($new eq 'custom')) {
6816: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6817: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6818: $new = '/';
6819: }
6820: }
6821: if (($item eq 'custompath') &&
6822: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6823: $new = '';
6824: }
6825: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6826: $changes{'loginvia'}{$lonhost} = 1;
6827: }
6828: if ($item eq 'exempt') {
1.160.6.56 raeburn 6829: $new = &check_exempt_addresses($new);
1.128 raeburn 6830: }
6831: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6832: }
6833: }
1.112 raeburn 6834: } else {
1.128 raeburn 6835: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6836: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6837: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6838: foreach my $item (@loginvia_attribs) {
6839: my $new = $env{'form.'.$lonhost.'_'.$item};
6840: if (($item eq 'serverpath') && ($new eq 'custom')) {
6841: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6842: $new = '/';
6843: }
6844: }
6845: if (($item eq 'custompath') &&
6846: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6847: $new = '';
6848: }
6849: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6850: }
1.110 raeburn 6851: }
6852: }
6853: }
6854: }
1.119 raeburn 6855:
1.160.6.5 raeburn 6856: my $servadm = $r->dir_config('lonAdmEMail');
6857: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6858: if (ref($domconfig{'login'}) eq 'HASH') {
6859: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6860: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6861: if ($lang eq 'nolang') {
6862: push(@currlangs,$lang);
6863: } elsif (defined($langchoices{$lang})) {
6864: push(@currlangs,$lang);
6865: } else {
6866: next;
6867: }
6868: }
6869: }
6870: }
6871: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6872: if (@currlangs > 0) {
6873: foreach my $lang (@currlangs) {
6874: if (grep(/^\Q$lang\E$/,@delurls)) {
6875: $changes{'helpurl'}{$lang} = 1;
6876: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6877: $changes{'helpurl'}{$lang} = 1;
6878: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6879: push(@newlangs,$lang);
6880: } else {
6881: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6882: }
6883: }
6884: }
6885: unless (grep(/^nolang$/,@currlangs)) {
6886: if ($env{'form.loginhelpurl_nolang.filename'}) {
6887: $changes{'helpurl'}{'nolang'} = 1;
6888: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6889: push(@newlangs,'nolang');
6890: }
6891: }
6892: if ($env{'form.loginhelpurl_add_lang'}) {
6893: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6894: ($env{'form.loginhelpurl_add_file.filename'})) {
6895: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6896: $addedfile = $env{'form.loginhelpurl_add_lang'};
6897: }
6898: }
6899: if ((@newlangs > 0) || ($addedfile)) {
6900: my $error;
6901: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6902: if ($configuserok eq 'ok') {
6903: if ($switchserver) {
6904: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6905: } elsif ($author_ok eq 'ok') {
6906: my @allnew = @newlangs;
6907: if ($addedfile ne '') {
6908: push(@allnew,$addedfile);
6909: }
6910: foreach my $lang (@allnew) {
6911: my $formelem = 'loginhelpurl_'.$lang;
6912: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6913: $formelem = 'loginhelpurl_add_file';
6914: }
6915: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6916: "help/$lang",'','',$newfile{$lang});
6917: if ($result eq 'ok') {
6918: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6919: $changes{'helpurl'}{$lang} = 1;
6920: } else {
6921: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6922: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6923: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6924: (!grep(/^\Q$lang\E$/,@delurls))) {
6925: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6926: }
6927: }
6928: }
6929: } else {
6930: $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);
6931: }
6932: } else {
6933: $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);
6934: }
6935: if ($error) {
6936: &Apache::lonnet::logthis($error);
6937: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6938: }
6939: }
1.160.6.56 raeburn 6940:
6941: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6942: if (ref($domconfig{'login'}) eq 'HASH') {
6943: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6944: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6945: if ($domservers{$lonhost}) {
6946: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6947: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 6948: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 6949: }
6950: }
6951: }
6952: }
6953: }
6954: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6955: foreach my $lonhost (sort(keys(%domservers))) {
6956: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6957: $changes{'headtag'}{$lonhost} = 1;
6958: } else {
6959: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6960: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6961: }
6962: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6963: push(@newhosts,$lonhost);
6964: } elsif ($currheadtagurls{$lonhost}) {
6965: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6966: if ($currexempt{$lonhost}) {
6967: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6968: $changes{'headtag'}{$lonhost} = 1;
6969: }
6970: } elsif ($possexempt{$lonhost}) {
6971: $changes{'headtag'}{$lonhost} = 1;
6972: }
6973: if ($possexempt{$lonhost}) {
6974: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6975: }
6976: }
6977: }
6978: }
6979: if (@newhosts) {
6980: my $error;
6981: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6982: if ($configuserok eq 'ok') {
6983: if ($switchserver) {
6984: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6985: } elsif ($author_ok eq 'ok') {
6986: foreach my $lonhost (@newhosts) {
6987: my $formelem = 'loginheadtag_'.$lonhost;
6988: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6989: "login/headtag/$lonhost",'','',
6990: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6991: if ($result eq 'ok') {
6992: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6993: $changes{'headtag'}{$lonhost} = 1;
6994: if ($possexempt{$lonhost}) {
6995: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6996: }
6997: } else {
6998: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
6999: $newheadtagurls{$lonhost},$result);
7000: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7001: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7002: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7003: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7004: }
7005: }
7006: }
7007: } else {
7008: $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);
7009: }
7010: } else {
7011: $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);
7012: }
7013: if ($error) {
7014: &Apache::lonnet::logthis($error);
7015: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7016: }
7017: }
1.160.6.5 raeburn 7018: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7019:
7020: my $defaulthelpfile = '/adm/loginproblems.html';
7021: my $defaulttext = &mt('Default in use');
7022:
1.1 raeburn 7023: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7024: $dom);
7025: if ($putresult eq 'ok') {
1.160.6.14 raeburn 7026: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7027: my %defaultchecked = (
7028: 'coursecatalog' => 'on',
1.160.6.14 raeburn 7029: 'helpdesk' => 'on',
1.42 raeburn 7030: 'adminmail' => 'off',
1.43 raeburn 7031: 'newuser' => 'off',
1.42 raeburn 7032: );
1.55 raeburn 7033: if (ref($domconfig{'login'}) eq 'HASH') {
7034: foreach my $item (@toggles) {
7035: if ($defaultchecked{$item} eq 'on') {
7036: if (($domconfig{'login'}{$item} eq '0') &&
7037: ($env{'form.'.$item} eq '1')) {
7038: $changes{$item} = 1;
7039: } elsif (($domconfig{'login'}{$item} eq '' ||
7040: $domconfig{'login'}{$item} eq '1') &&
7041: ($env{'form.'.$item} eq '0')) {
7042: $changes{$item} = 1;
7043: }
7044: } elsif ($defaultchecked{$item} eq 'off') {
7045: if (($domconfig{'login'}{$item} eq '1') &&
7046: ($env{'form.'.$item} eq '0')) {
7047: $changes{$item} = 1;
7048: } elsif (($domconfig{'login'}{$item} eq '' ||
7049: $domconfig{'login'}{$item} eq '0') &&
7050: ($env{'form.'.$item} eq '1')) {
7051: $changes{$item} = 1;
7052: }
1.42 raeburn 7053: }
7054: }
1.41 raeburn 7055: }
1.6 raeburn 7056: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7057: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7058: if (ref($lastactref) eq 'HASH') {
7059: $lastactref->{'domainconfig'} = 1;
7060: }
1.1 raeburn 7061: $resulttext = &mt('Changes made:').'<ul>';
7062: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7063: if ($item eq 'loginvia') {
1.112 raeburn 7064: if (ref($changes{$item}) eq 'HASH') {
7065: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7066: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7067: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7068: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7069: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7070: $protocol = 'http' if ($protocol ne 'https');
7071: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7072:
7073: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7074: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7075: } else {
7076: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7077: }
7078: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7079: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7080: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7081: }
7082: $resulttext .= '</li>';
7083: } else {
7084: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7085: }
1.112 raeburn 7086: } else {
1.128 raeburn 7087: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7088: }
7089: }
1.128 raeburn 7090: $resulttext .= '</ul></li>';
1.112 raeburn 7091: }
1.160.6.5 raeburn 7092: } elsif ($item eq 'helpurl') {
7093: if (ref($changes{$item}) eq 'HASH') {
7094: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7095: if (grep(/^\Q$lang\E$/,@delurls)) {
7096: my ($chg,$link);
7097: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7098: if ($lang eq 'nolang') {
7099: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7100: } else {
7101: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7102: }
7103: $resulttext .= '<li>'.$chg.'</li>';
7104: } else {
7105: my $chg;
7106: if ($lang eq 'nolang') {
7107: $chg = &mt('custom log-in help file for no preferred language');
7108: } else {
7109: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7110: }
7111: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7112: $loginhash{'login'}{'helpurl'}{$lang}.
7113: '?inhibitmenu=yes',$chg,600,500).
7114: '</li>';
7115: }
7116: }
7117: }
1.160.6.56 raeburn 7118: } elsif ($item eq 'headtag') {
7119: if (ref($changes{$item}) eq 'HASH') {
7120: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7121: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7122: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7123: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7124: $resulttext .= '<li><a href="'.
7125: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7126: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7127: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7128: if ($possexempt{$lonhost}) {
7129: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7130: } else {
7131: $resulttext .= &mt('included for any client IP');
7132: }
7133: $resulttext .= '</li>';
7134: }
7135: }
7136: }
1.160.6.5 raeburn 7137: } elsif ($item eq 'captcha') {
7138: if (ref($loginhash{'login'}) eq 'HASH') {
7139: my $chgtxt;
7140: if ($loginhash{'login'}{$item} eq 'notused') {
7141: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7142: } else {
7143: my %captchas = &captcha_phrases();
7144: if ($captchas{$loginhash{'login'}{$item}}) {
7145: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7146: } else {
7147: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7148: }
7149: }
7150: $resulttext .= '<li>'.$chgtxt.'</li>';
7151: }
7152: } elsif ($item eq 'recaptchakeys') {
7153: if (ref($loginhash{'login'}) eq 'HASH') {
7154: my ($privkey,$pubkey);
7155: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7156: $pubkey = $loginhash{'login'}{$item}{'public'};
7157: $privkey = $loginhash{'login'}{$item}{'private'};
7158: }
7159: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7160: if (!$pubkey) {
7161: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7162: } else {
7163: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7164: }
7165: if (!$privkey) {
7166: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7167: } else {
1.160.6.53 raeburn 7168: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 7169: }
7170: $chgtxt .= '</ul>';
7171: $resulttext .= '<li>'.$chgtxt.'</li>';
7172: }
1.160.6.69 raeburn 7173: } elsif ($item eq 'recaptchaversion') {
7174: if (ref($loginhash{'login'}) eq 'HASH') {
7175: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
7176: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
7177: '</li>';
7178: }
7179: }
1.41 raeburn 7180: } else {
7181: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7182: }
1.1 raeburn 7183: }
1.6 raeburn 7184: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7185: } else {
7186: $resulttext = &mt('No changes made to log-in page settings');
7187: }
7188: } else {
1.11 albertel 7189: $resulttext = '<span class="LC_error">'.
7190: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7191: }
1.6 raeburn 7192: if ($errors) {
1.9 raeburn 7193: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7194: $errors.'</ul>';
7195: }
7196: return $resulttext;
7197: }
7198:
1.160.6.56 raeburn 7199: sub check_exempt_addresses {
7200: my ($iplist) = @_;
7201: $iplist =~ s/^\s+//;
7202: $iplist =~ s/\s+$//;
7203: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7204: my (@okips,$new);
7205: foreach my $ip (@poss_ips) {
7206: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7207: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7208: push(@okips,$ip);
7209: }
7210: }
7211: }
7212: if (@okips > 0) {
7213: $new = join(',',@okips);
7214: } else {
7215: $new = '';
7216: }
7217: return $new;
7218: }
7219:
1.6 raeburn 7220: sub color_font_choices {
7221: my %choices =
7222: &Apache::lonlocal::texthash (
7223: img => "Header",
7224: bgs => "Background colors",
7225: links => "Link colors",
1.55 raeburn 7226: images => "Images",
1.6 raeburn 7227: font => "Font color",
1.160.6.22 raeburn 7228: fontmenu => "Font menu",
1.76 raeburn 7229: pgbg => "Page",
1.6 raeburn 7230: tabbg => "Header",
7231: sidebg => "Border",
7232: link => "Link",
7233: alink => "Active link",
7234: vlink => "Visited link",
7235: );
7236: return %choices;
7237: }
7238:
7239: sub modify_rolecolors {
1.160.6.24 raeburn 7240: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7241: my ($resulttext,%rolehash);
7242: $rolehash{'rolecolors'} = {};
1.55 raeburn 7243: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7244: if ($domconfig{'rolecolors'} eq '') {
7245: $domconfig{'rolecolors'} = {};
7246: }
7247: }
1.9 raeburn 7248: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7249: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7250: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7251: $dom);
7252: if ($putresult eq 'ok') {
7253: if (keys(%changes) > 0) {
1.41 raeburn 7254: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7255: if (ref($lastactref) eq 'HASH') {
7256: $lastactref->{'domainconfig'} = 1;
7257: }
1.6 raeburn 7258: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7259: $rolehash{'rolecolors'});
7260: } else {
7261: $resulttext = &mt('No changes made to default color schemes');
7262: }
7263: } else {
1.11 albertel 7264: $resulttext = '<span class="LC_error">'.
7265: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7266: }
7267: if ($errors) {
7268: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7269: $errors.'</ul>';
7270: }
7271: return $resulttext;
7272: }
7273:
7274: sub modify_colors {
1.9 raeburn 7275: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7276: my (%changes,%choices);
1.51 raeburn 7277: my @bgs;
1.6 raeburn 7278: my @links = ('link','alink','vlink');
1.41 raeburn 7279: my @logintext;
1.6 raeburn 7280: my @images;
7281: my $servadm = $r->dir_config('lonAdmEMail');
7282: my $errors;
1.160.6.22 raeburn 7283: my %defaults;
1.6 raeburn 7284: foreach my $role (@{$roles}) {
7285: if ($role eq 'login') {
1.12 raeburn 7286: %choices = &login_choices();
1.41 raeburn 7287: @logintext = ('textcol','bgcol');
1.12 raeburn 7288: } else {
7289: %choices = &color_font_choices();
7290: }
7291: if ($role eq 'login') {
1.41 raeburn 7292: @images = ('img','logo','domlogo','login');
1.51 raeburn 7293: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7294: } else {
7295: @images = ('img');
1.160.6.22 raeburn 7296: @bgs = ('pgbg','tabbg','sidebg');
7297: }
7298: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7299: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7300: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7301: }
7302: if ($role eq 'login') {
7303: foreach my $item (@logintext) {
1.160.6.39 raeburn 7304: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7305: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7306: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7307: }
7308: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 7309: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7310: }
7311: }
7312: } else {
1.160.6.39 raeburn 7313: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7314: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7315: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7316: }
7317: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 7318: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7319: }
1.6 raeburn 7320: }
1.160.6.22 raeburn 7321: foreach my $item (@bgs) {
1.160.6.39 raeburn 7322: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7323: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7324: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7325: }
7326: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 7327: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7328: }
7329: }
7330: foreach my $item (@links) {
1.160.6.39 raeburn 7331: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7332: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7333: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7334: }
7335: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 7336: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7337: }
1.6 raeburn 7338: }
1.46 raeburn 7339: my ($configuserok,$author_ok,$switchserver) =
7340: &config_check($dom,$confname,$servadm);
1.9 raeburn 7341: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7342: if (ref($domconfig->{$role}) ne 'HASH') {
7343: $domconfig->{$role} = {};
7344: }
1.8 raeburn 7345: foreach my $img (@images) {
1.70 raeburn 7346: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7347: if (defined($env{'form.login_showlogo_'.$img})) {
7348: $confhash->{$role}{'showlogo'}{$img} = 1;
7349: } else {
7350: $confhash->{$role}{'showlogo'}{$img} = 0;
7351: }
7352: }
1.18 albertel 7353: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7354: && !defined($domconfig->{$role}{$img})
7355: && !$env{'form.'.$role.'_del_'.$img}
7356: && $env{'form.'.$role.'_import_'.$img}) {
7357: # import the old configured image from the .tab setting
7358: # if they haven't provided a new one
7359: $domconfig->{$role}{$img} =
7360: $env{'form.'.$role.'_import_'.$img};
7361: }
1.6 raeburn 7362: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7363: my $error;
1.6 raeburn 7364: if ($configuserok eq 'ok') {
1.9 raeburn 7365: if ($switchserver) {
1.12 raeburn 7366: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7367: } else {
7368: if ($author_ok eq 'ok') {
7369: my ($result,$logourl) =
7370: &publishlogo($r,'upload',$role.'_'.$img,
7371: $dom,$confname,$img,$width,$height);
7372: if ($result eq 'ok') {
7373: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7374: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7375: } else {
1.12 raeburn 7376: $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 7377: }
7378: } else {
1.46 raeburn 7379: $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 7380: }
7381: }
7382: } else {
1.46 raeburn 7383: $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 7384: }
7385: if ($error) {
1.8 raeburn 7386: &Apache::lonnet::logthis($error);
1.11 albertel 7387: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7388: }
7389: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7390: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7391: my $error;
7392: if ($configuserok eq 'ok') {
7393: # is confname an author?
7394: if ($switchserver eq '') {
7395: if ($author_ok eq 'ok') {
7396: my ($result,$logourl) =
7397: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7398: $dom,$confname,$img,$width,$height);
7399: if ($result eq 'ok') {
7400: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7401: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7402: }
7403: }
7404: }
7405: }
1.6 raeburn 7406: }
7407: }
7408: }
7409: if (ref($domconfig) eq 'HASH') {
7410: if (ref($domconfig->{$role}) eq 'HASH') {
7411: foreach my $img (@images) {
7412: if ($domconfig->{$role}{$img} ne '') {
7413: if ($env{'form.'.$role.'_del_'.$img}) {
7414: $confhash->{$role}{$img} = '';
1.12 raeburn 7415: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7416: } else {
1.9 raeburn 7417: if ($confhash->{$role}{$img} eq '') {
7418: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7419: }
1.6 raeburn 7420: }
7421: } else {
7422: if ($env{'form.'.$role.'_del_'.$img}) {
7423: $confhash->{$role}{$img} = '';
1.12 raeburn 7424: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7425: }
7426: }
1.70 raeburn 7427: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7428: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7429: if ($confhash->{$role}{'showlogo'}{$img} ne
7430: $domconfig->{$role}{'showlogo'}{$img}) {
7431: $changes{$role}{'showlogo'}{$img} = 1;
7432: }
7433: } else {
7434: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7435: $changes{$role}{'showlogo'}{$img} = 1;
7436: }
7437: }
7438: }
7439: }
1.6 raeburn 7440: if ($domconfig->{$role}{'font'} ne '') {
7441: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7442: $changes{$role}{'font'} = 1;
7443: }
7444: } else {
7445: if ($confhash->{$role}{'font'}) {
7446: $changes{$role}{'font'} = 1;
7447: }
7448: }
1.107 raeburn 7449: if ($role ne 'login') {
7450: if ($domconfig->{$role}{'fontmenu'} ne '') {
7451: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7452: $changes{$role}{'fontmenu'} = 1;
7453: }
7454: } else {
7455: if ($confhash->{$role}{'fontmenu'}) {
7456: $changes{$role}{'fontmenu'} = 1;
7457: }
1.97 tempelho 7458: }
7459: }
1.6 raeburn 7460: foreach my $item (@bgs) {
7461: if ($domconfig->{$role}{$item} ne '') {
7462: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7463: $changes{$role}{'bgs'}{$item} = 1;
7464: }
7465: } else {
7466: if ($confhash->{$role}{$item}) {
7467: $changes{$role}{'bgs'}{$item} = 1;
7468: }
7469: }
7470: }
7471: foreach my $item (@links) {
7472: if ($domconfig->{$role}{$item} ne '') {
7473: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7474: $changes{$role}{'links'}{$item} = 1;
7475: }
7476: } else {
7477: if ($confhash->{$role}{$item}) {
7478: $changes{$role}{'links'}{$item} = 1;
7479: }
7480: }
7481: }
1.41 raeburn 7482: foreach my $item (@logintext) {
7483: if ($domconfig->{$role}{$item} ne '') {
7484: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7485: $changes{$role}{'logintext'}{$item} = 1;
7486: }
7487: } else {
7488: if ($confhash->{$role}{$item}) {
7489: $changes{$role}{'logintext'}{$item} = 1;
7490: }
7491: }
7492: }
1.6 raeburn 7493: } else {
7494: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7495: \@logintext,$confhash,\%changes);
1.6 raeburn 7496: }
7497: } else {
7498: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7499: \@logintext,$confhash,\%changes);
1.6 raeburn 7500: }
7501: }
7502: return ($errors,%changes);
7503: }
7504:
1.46 raeburn 7505: sub config_check {
7506: my ($dom,$confname,$servadm) = @_;
7507: my ($configuserok,$author_ok,$switchserver,%currroles);
7508: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7509: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7510: $confname,$servadm);
7511: if ($configuserok eq 'ok') {
7512: $switchserver = &check_switchserver($dom,$confname);
7513: if ($switchserver eq '') {
7514: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7515: }
7516: }
7517: return ($configuserok,$author_ok,$switchserver);
7518: }
7519:
1.6 raeburn 7520: sub default_change_checker {
1.41 raeburn 7521: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7522: foreach my $item (@{$links}) {
7523: if ($confhash->{$role}{$item}) {
7524: $changes->{$role}{'links'}{$item} = 1;
7525: }
7526: }
7527: foreach my $item (@{$bgs}) {
7528: if ($confhash->{$role}{$item}) {
7529: $changes->{$role}{'bgs'}{$item} = 1;
7530: }
7531: }
1.41 raeburn 7532: foreach my $item (@{$logintext}) {
7533: if ($confhash->{$role}{$item}) {
7534: $changes->{$role}{'logintext'}{$item} = 1;
7535: }
7536: }
1.6 raeburn 7537: foreach my $img (@{$images}) {
7538: if ($env{'form.'.$role.'_del_'.$img}) {
7539: $confhash->{$role}{$img} = '';
1.12 raeburn 7540: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7541: }
1.70 raeburn 7542: if ($role eq 'login') {
7543: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7544: $changes->{$role}{'showlogo'}{$img} = 1;
7545: }
7546: }
1.6 raeburn 7547: }
7548: if ($confhash->{$role}{'font'}) {
7549: $changes->{$role}{'font'} = 1;
7550: }
1.48 raeburn 7551: }
1.6 raeburn 7552:
7553: sub display_colorchgs {
7554: my ($dom,$changes,$roles,$confhash) = @_;
7555: my (%choices,$resulttext);
7556: if (!grep(/^login$/,@{$roles})) {
7557: $resulttext = &mt('Changes made:').'<br />';
7558: }
7559: foreach my $role (@{$roles}) {
7560: if ($role eq 'login') {
7561: %choices = &login_choices();
7562: } else {
7563: %choices = &color_font_choices();
7564: }
7565: if (ref($changes->{$role}) eq 'HASH') {
7566: if ($role ne 'login') {
7567: $resulttext .= '<h4>'.&mt($role).'</h4>';
7568: }
7569: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7570: if ($role ne 'login') {
7571: $resulttext .= '<ul>';
7572: }
7573: if (ref($changes->{$role}{$key}) eq 'HASH') {
7574: if ($role ne 'login') {
7575: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7576: }
7577: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7578: if (($role eq 'login') && ($key eq 'showlogo')) {
7579: if ($confhash->{$role}{$key}{$item}) {
7580: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7581: } else {
7582: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7583: }
7584: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7585: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7586: } else {
1.12 raeburn 7587: my $newitem = $confhash->{$role}{$item};
7588: if ($key eq 'images') {
7589: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7590: }
7591: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7592: }
7593: }
7594: if ($role ne 'login') {
7595: $resulttext .= '</ul></li>';
7596: }
7597: } else {
7598: if ($confhash->{$role}{$key} eq '') {
7599: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7600: } else {
7601: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7602: }
7603: }
7604: if ($role ne 'login') {
7605: $resulttext .= '</ul>';
7606: }
7607: }
7608: }
7609: }
1.3 raeburn 7610: return $resulttext;
1.1 raeburn 7611: }
7612:
1.9 raeburn 7613: sub thumb_dimensions {
7614: return ('200','50');
7615: }
7616:
1.16 raeburn 7617: sub check_dimensions {
7618: my ($inputfile) = @_;
7619: my ($fullwidth,$fullheight);
7620: if ($inputfile =~ m|^[/\w.\-]+$|) {
7621: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7622: my $imageinfo = <PIPE>;
7623: if (!close(PIPE)) {
7624: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7625: }
7626: chomp($imageinfo);
7627: my ($fullsize) =
1.21 raeburn 7628: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7629: if ($fullsize) {
7630: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7631: }
7632: }
7633: }
7634: return ($fullwidth,$fullheight);
7635: }
7636:
1.9 raeburn 7637: sub check_configuser {
7638: my ($uhome,$dom,$confname,$servadm) = @_;
7639: my ($configuserok,%currroles);
7640: if ($uhome eq 'no_host') {
7641: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7642: my $configpass = &LONCAPA::Enrollment::create_password();
7643: $configuserok =
7644: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7645: $configpass,'','','','','',undef,$servadm);
7646: } else {
7647: $configuserok = 'ok';
7648: %currroles =
7649: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7650: }
7651: return ($configuserok,%currroles);
7652: }
7653:
7654: sub check_authorstatus {
7655: my ($dom,$confname,%currroles) = @_;
7656: my $author_ok;
1.40 raeburn 7657: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7658: my $start = time;
7659: my $end = 0;
7660: $author_ok =
7661: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7662: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7663: } else {
7664: $author_ok = 'ok';
7665: }
7666: return $author_ok;
7667: }
7668:
7669: sub publishlogo {
1.46 raeburn 7670: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 7671: my ($output,$fname,$logourl);
7672: if ($action eq 'upload') {
7673: $fname=$env{'form.'.$formname.'.filename'};
7674: chop($env{'form.'.$formname});
7675: } else {
7676: ($fname) = ($formname =~ /([^\/]+)$/);
7677: }
1.46 raeburn 7678: if ($savefileas ne '') {
7679: $fname = $savefileas;
7680: }
1.9 raeburn 7681: $fname=&Apache::lonnet::clean_filename($fname);
7682: # See if there is anything left
7683: unless ($fname) { return ('error: no uploaded file'); }
7684: $fname="$subdir/$fname";
1.160.6.5 raeburn 7685: my $docroot=$r->dir_config('lonDocRoot');
7686: my $filepath="$docroot/priv";
7687: my $relpath = "$dom/$confname";
1.9 raeburn 7688: my ($fnamepath,$file,$fetchthumb);
7689: $file=$fname;
7690: if ($fname=~m|/|) {
7691: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7692: }
1.160.6.26 raeburn 7693: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7694: my $count;
1.160.6.5 raeburn 7695: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7696: $filepath.="/$parts[$count]";
7697: if ((-e $filepath)!=1) {
7698: mkdir($filepath,02770);
7699: }
7700: }
7701: # Check for bad extension and disallow upload
7702: if ($file=~/\.(\w+)$/ &&
7703: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7704: $output =
1.160.6.25 raeburn 7705: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7706: } elsif ($file=~/\.(\w+)$/ &&
7707: !defined(&Apache::loncommon::fileembstyle($1))) {
7708: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7709: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 7710: $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 7711: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 7712: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7713: } else {
7714: my $source = $filepath.'/'.$file;
7715: my $logfile;
7716: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 7717: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7718: }
7719: print $logfile
7720: "\n================= Publish ".localtime()." ================\n".
7721: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7722: # Save the file
7723: if (!open(FH,'>'.$source)) {
7724: &Apache::lonnet::logthis('Failed to create '.$source);
7725: return (&mt('Failed to create file'));
7726: }
7727: if ($action eq 'upload') {
7728: if (!print FH ($env{'form.'.$formname})) {
7729: &Apache::lonnet::logthis('Failed to write to '.$source);
7730: return (&mt('Failed to write file'));
7731: }
7732: } else {
7733: my $original = &Apache::lonnet::filelocation('',$formname);
7734: if(!copy($original,$source)) {
7735: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7736: return (&mt('Failed to write file'));
7737: }
7738: }
7739: close(FH);
7740: chmod(0660, $source); # Permissions to rw-rw---.
7741:
7742: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7743: my $copyfile=$targetdir.'/'.$file;
7744:
7745: my @parts=split(/\//,$targetdir);
7746: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7747: for (my $count=5;$count<=$#parts;$count++) {
7748: $path.="/$parts[$count]";
7749: if (!-e $path) {
7750: print $logfile "\nCreating directory ".$path;
7751: mkdir($path,02770);
7752: }
7753: }
7754: my $versionresult;
7755: if (-e $copyfile) {
7756: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7757: } else {
7758: $versionresult = 'ok';
7759: }
7760: if ($versionresult eq 'ok') {
7761: if (copy($source,$copyfile)) {
7762: print $logfile "\nCopied original source to ".$copyfile."\n";
7763: $output = 'ok';
7764: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7765: push(@{$modified_urls},[$copyfile,$source]);
7766: my $metaoutput =
7767: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7768: unless ($registered_cleanup) {
7769: my $handlers = $r->get_handlers('PerlCleanupHandler');
7770: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7771: $registered_cleanup=1;
7772: }
1.9 raeburn 7773: } else {
7774: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7775: $output = &mt('Failed to copy file to RES space').", $!";
7776: }
7777: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7778: my $inputfile = $filepath.'/'.$file;
7779: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7780: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7781: if ($fullwidth ne '' && $fullheight ne '') {
7782: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7783: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7784: system("convert -sample $thumbsize $inputfile $outfile");
7785: chmod(0660, $filepath.'/tn-'.$file);
7786: if (-e $outfile) {
7787: my $copyfile=$targetdir.'/tn-'.$file;
7788: if (copy($outfile,$copyfile)) {
7789: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7790: my $thumb_metaoutput =
7791: &write_metadata($dom,$confname,$formname,
7792: $targetdir,'tn-'.$file,$logfile);
7793: push(@{$modified_urls},[$copyfile,$outfile]);
7794: unless ($registered_cleanup) {
7795: my $handlers = $r->get_handlers('PerlCleanupHandler');
7796: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7797: $registered_cleanup=1;
7798: }
1.16 raeburn 7799: } else {
7800: print $logfile "\nUnable to write ".$copyfile.
7801: ':'.$!."\n";
7802: }
7803: }
1.9 raeburn 7804: }
7805: }
7806: }
7807: } else {
7808: $output = $versionresult;
7809: }
7810: }
7811: return ($output,$logourl);
7812: }
7813:
7814: sub logo_versioning {
7815: my ($targetdir,$file,$logfile) = @_;
7816: my $target = $targetdir.'/'.$file;
7817: my ($maxversion,$fn,$extn,$output);
7818: $maxversion = 0;
7819: if ($file =~ /^(.+)\.(\w+)$/) {
7820: $fn=$1;
7821: $extn=$2;
7822: }
7823: opendir(DIR,$targetdir);
7824: while (my $filename=readdir(DIR)) {
7825: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7826: $maxversion=($1>$maxversion)?$1:$maxversion;
7827: }
7828: }
7829: $maxversion++;
7830: print $logfile "\nCreating old version ".$maxversion."\n";
7831: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7832: if (copy($target,$copyfile)) {
7833: print $logfile "Copied old target to ".$copyfile."\n";
7834: $copyfile=$copyfile.'.meta';
7835: if (copy($target.'.meta',$copyfile)) {
7836: print $logfile "Copied old target metadata to ".$copyfile."\n";
7837: $output = 'ok';
7838: } else {
7839: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7840: $output = &mt('Failed to copy old meta').", $!, ";
7841: }
7842: } else {
7843: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7844: $output = &mt('Failed to copy old target').", $!, ";
7845: }
7846: return $output;
7847: }
7848:
7849: sub write_metadata {
7850: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7851: my (%metadatafields,%metadatakeys,$output);
7852: $metadatafields{'title'}=$formname;
7853: $metadatafields{'creationdate'}=time;
7854: $metadatafields{'lastrevisiondate'}=time;
7855: $metadatafields{'copyright'}='public';
7856: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7857: $env{'user.domain'};
7858: $metadatafields{'authorspace'}=$confname.':'.$dom;
7859: $metadatafields{'domain'}=$dom;
7860: {
7861: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7862: my $mfh;
1.155 raeburn 7863: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 7864: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7865: unless ($_=~/\./) {
7866: my $unikey=$_;
7867: $unikey=~/^([A-Za-z]+)/;
7868: my $tag=$1;
7869: $tag=~tr/A-Z/a-z/;
7870: print $mfh "\n\<$tag";
7871: foreach (split(/\,/,$metadatakeys{$unikey})) {
7872: my $value=$metadatafields{$unikey.'.'.$_};
7873: $value=~s/\"/\'\'/g;
7874: print $mfh ' '.$_.'="'.$value.'"';
7875: }
7876: print $mfh '>'.
7877: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7878: .'</'.$tag.'>';
7879: }
7880: }
7881: $output = 'ok';
7882: print $logfile "\nWrote metadata";
7883: close($mfh);
7884: } else {
7885: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7886: $output = &mt('Could not write metadata');
7887: }
7888: }
1.155 raeburn 7889: return $output;
7890: }
7891:
7892: sub notifysubscribed {
7893: foreach my $targetsource (@{$modified_urls}){
7894: next unless (ref($targetsource) eq 'ARRAY');
7895: my ($target,$source)=@{$targetsource};
7896: if ($source ne '') {
7897: if (open(my $logfh,'>>'.$source.'.log')) {
7898: print $logfh "\nCleanup phase: Notifications\n";
7899: my @subscribed=&subscribed_hosts($target);
7900: foreach my $subhost (@subscribed) {
7901: print $logfh "\nNotifying host ".$subhost.':';
7902: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7903: print $logfh $reply;
7904: }
7905: my @subscribedmeta=&subscribed_hosts("$target.meta");
7906: foreach my $subhost (@subscribedmeta) {
7907: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7908: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7909: $subhost);
7910: print $logfh $reply;
7911: }
7912: print $logfh "\n============ Done ============\n";
1.160 raeburn 7913: close($logfh);
1.155 raeburn 7914: }
7915: }
7916: }
7917: return OK;
7918: }
7919:
7920: sub subscribed_hosts {
7921: my ($target) = @_;
7922: my @subscribed;
7923: if (open(my $fh,"<$target.subscription")) {
7924: while (my $subline=<$fh>) {
7925: if ($subline =~ /^($match_lonid):/) {
7926: my $host = $1;
7927: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7928: unless (grep(/^\Q$host\E$/,@subscribed)) {
7929: push(@subscribed,$host);
7930: }
7931: }
7932: }
7933: }
7934: }
7935: return @subscribed;
1.9 raeburn 7936: }
7937:
7938: sub check_switchserver {
7939: my ($dom,$confname) = @_;
7940: my ($allowed,$switchserver);
7941: my $home = &Apache::lonnet::homeserver($confname,$dom);
7942: if ($home eq 'no_host') {
7943: $home = &Apache::lonnet::domain($dom,'primary');
7944: }
7945: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7946: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7947: if (!$allowed) {
1.160.6.11 raeburn 7948: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7949: }
7950: return $switchserver;
7951: }
7952:
1.1 raeburn 7953: sub modify_quotas {
1.160.6.30 raeburn 7954: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7955: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7956: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7957: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7958: $validationfieldsref);
1.86 raeburn 7959: if ($action eq 'quotas') {
7960: $context = 'tools';
1.160.6.26 raeburn 7961: } else {
1.86 raeburn 7962: $context = $action;
7963: }
7964: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7965: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7966: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7967: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7968: %titles = &courserequest_titles();
7969: $toolregexp = join('|',@usertools);
7970: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7971: $confname = $dom.'-domainconfig';
7972: my $servadm = $r->dir_config('lonAdmEMail');
7973: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7974: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7975: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7976: } elsif ($context eq 'requestauthor') {
7977: @usertools = ('author');
7978: %titles = &authorrequest_titles();
1.86 raeburn 7979: } else {
1.160.6.4 raeburn 7980: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7981: %titles = &tool_titles();
1.86 raeburn 7982: }
1.160.6.27 raeburn 7983: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7984: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7985: foreach my $key (keys(%env)) {
1.101 raeburn 7986: if ($context eq 'requestcourses') {
7987: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7988: my $item = $1;
7989: my $type = $2;
7990: if ($type =~ /^limit_(.+)/) {
7991: $limithash{$item}{$1} = $env{$key};
7992: } else {
7993: $confhash{$item}{$type} = $env{$key};
7994: }
7995: }
1.160.6.5 raeburn 7996: } elsif ($context eq 'requestauthor') {
7997: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
7998: $confhash{$1} = $env{$key};
7999: }
1.101 raeburn 8000: } else {
1.86 raeburn 8001: if ($key =~ /^form\.quota_(.+)$/) {
8002: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 8003: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8004: $confhash{'authorquota'}{$1} = $env{$key};
8005: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8006: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8007: }
1.72 raeburn 8008: }
8009: }
1.160.6.5 raeburn 8010: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 8011: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8012: @approvalnotify = sort(@approvalnotify);
8013: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 8014: my @crstypes = ('official','unofficial','community','textbook');
8015: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8016: foreach my $type (@hasuniquecode) {
8017: if (grep(/^\Q$type\E$/,@crstypes)) {
8018: $confhash{'uniquecode'}{$type} = 1;
8019: }
8020: }
1.160.6.46 raeburn 8021: my (%newbook,%allpos);
1.160.6.30 raeburn 8022: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8023: foreach my $type ('textbooks','templates') {
8024: @{$allpos{$type}} = ();
8025: my $invalid;
8026: if ($type eq 'textbooks') {
8027: $invalid = &mt('Invalid LON-CAPA course for textbook');
8028: } else {
8029: $invalid = &mt('Invalid LON-CAPA course for template');
8030: }
8031: if ($env{'form.'.$type.'_addbook'}) {
8032: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8033: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8034: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8035: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8036: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8037: } else {
8038: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8039: my $position = $env{'form.'.$type.'_addbook_pos'};
8040: $position =~ s/\D+//g;
8041: if ($position ne '') {
8042: $allpos{$type}[$position] = $newbook{$type};
8043: }
1.160.6.30 raeburn 8044: }
1.160.6.46 raeburn 8045: } else {
8046: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 8047: }
8048: }
1.160.6.46 raeburn 8049: }
1.160.6.30 raeburn 8050: }
1.102 raeburn 8051: if (ref($domconfig{$action}) eq 'HASH') {
8052: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8053: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8054: $changes{'notify'}{'approval'} = 1;
8055: }
8056: } else {
1.144 raeburn 8057: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8058: $changes{'notify'}{'approval'} = 1;
8059: }
8060: }
1.160.6.30 raeburn 8061: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8062: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8063: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8064: unless ($confhash{'uniquecode'}{$crstype}) {
8065: $changes{'uniquecode'} = 1;
8066: }
8067: }
8068: unless ($changes{'uniquecode'}) {
8069: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8070: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8071: $changes{'uniquecode'} = 1;
8072: }
8073: }
8074: }
8075: } else {
8076: $changes{'uniquecode'} = 1;
8077: }
8078: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8079: $changes{'uniquecode'} = 1;
8080: }
8081: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8082: foreach my $type ('textbooks','templates') {
8083: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8084: my %deletions;
8085: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8086: if (@todelete) {
8087: map { $deletions{$_} = 1; } @todelete;
8088: }
8089: my %imgdeletions;
8090: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8091: if (@todeleteimages) {
8092: map { $imgdeletions{$_} = 1; } @todeleteimages;
8093: }
8094: my $maxnum = $env{'form.'.$type.'_maxnum'};
8095: for (my $i=0; $i<=$maxnum; $i++) {
8096: my $itemid = $env{'form.'.$type.'_id_'.$i};
8097: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8098: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8099: if ($deletions{$key}) {
8100: if ($domconfig{$action}{$type}{$key}{'image'}) {
8101: #FIXME need to obsolete item in RES space
8102: }
8103: next;
8104: } else {
8105: my $newpos = $env{'form.'.$itemid};
8106: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 8107: foreach my $item ('subject','title','publisher','author') {
8108: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8109: ($type eq 'templates'));
1.160.6.46 raeburn 8110: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8111: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8112: $changes{$type}{$key} = 1;
8113: }
8114: }
8115: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 8116: }
1.160.6.46 raeburn 8117: if ($imgdeletions{$key}) {
8118: $changes{$type}{$key} = 1;
8119: #FIXME need to obsolete item in RES space
8120: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8121: my ($cdom,$cnum) = split(/_/,$key);
8122: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8123: $cdom,$cnum,$type,$configuserok,
8124: $switchserver,$author_ok);
8125: if ($imgurl) {
8126: $confhash{$type}{$key}{'image'} = $imgurl;
8127: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 8128: }
1.160.6.46 raeburn 8129: if ($error) {
8130: &Apache::lonnet::logthis($error);
8131: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8132: }
8133: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8134: $confhash{$type}{$key}{'image'} =
8135: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 8136: }
8137: }
8138: }
8139: }
8140: }
8141: }
1.102 raeburn 8142: } else {
1.144 raeburn 8143: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8144: $changes{'notify'}{'approval'} = 1;
8145: }
1.160.6.30 raeburn 8146: if (ref($confhash{'uniquecode'} eq 'HASH')) {
8147: $changes{'uniquecode'} = 1;
8148: }
8149: }
8150: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8151: foreach my $type ('textbooks','templates') {
8152: if ($newbook{$type}) {
8153: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 8154: foreach my $item ('subject','title','publisher','author') {
8155: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8156: ($type eq 'template'));
1.160.6.46 raeburn 8157: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8158: if ($env{'form.'.$type.'_addbook_'.$item}) {
8159: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8160: }
8161: }
8162: if ($type eq 'textbooks') {
8163: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8164: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8165: my ($imageurl,$error) =
8166: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8167: $configuserok,$switchserver,$author_ok);
8168: if ($imageurl) {
8169: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8170: }
8171: if ($error) {
8172: &Apache::lonnet::logthis($error);
8173: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8174: }
8175: }
1.160.6.30 raeburn 8176: }
8177: }
1.160.6.46 raeburn 8178: if (@{$allpos{$type}} > 0) {
8179: my $idx = 0;
8180: foreach my $item (@{$allpos{$type}}) {
8181: if ($item ne '') {
8182: $confhash{$type}{$item}{'order'} = $idx;
8183: if (ref($domconfig{$action}) eq 'HASH') {
8184: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8185: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8186: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8187: $changes{$type}{$item} = 1;
8188: }
1.160.6.30 raeburn 8189: }
8190: }
8191: }
1.160.6.46 raeburn 8192: $idx ++;
1.160.6.30 raeburn 8193: }
8194: }
8195: }
8196: }
1.160.6.39 raeburn 8197: if (ref($validationitemsref) eq 'ARRAY') {
8198: foreach my $item (@{$validationitemsref}) {
8199: if ($item eq 'fields') {
8200: my @changed;
8201: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8202: if (@{$confhash{'validation'}{$item}} > 0) {
8203: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8204: }
1.160.6.65 raeburn 8205: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8206: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8207: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8208: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8209: $domconfig{'requestcourses'}{'validation'}{$item});
8210: } else {
8211: @changed = @{$confhash{'validation'}{$item}};
8212: }
1.160.6.39 raeburn 8213: } else {
8214: @changed = @{$confhash{'validation'}{$item}};
8215: }
8216: } else {
8217: @changed = @{$confhash{'validation'}{$item}};
8218: }
8219: if (@changed) {
8220: if ($confhash{'validation'}{$item}) {
8221: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8222: } else {
8223: $changes{'validation'}{$item} = &mt('None');
8224: }
8225: }
8226: } else {
8227: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8228: if ($item eq 'markup') {
8229: if ($env{'form.requestcourses_validation_'.$item}) {
8230: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8231: }
8232: }
1.160.6.65 raeburn 8233: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8234: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8235: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8236: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8237: }
8238: } else {
8239: if ($confhash{'validation'}{$item} ne '') {
8240: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8241: }
1.160.6.39 raeburn 8242: }
8243: } else {
8244: if ($confhash{'validation'}{$item} ne '') {
8245: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8246: }
8247: }
8248: }
8249: }
8250: }
8251: if ($env{'form.validationdc'}) {
8252: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 8253: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 8254: if (exists($domcoords{$newval})) {
8255: $confhash{'validation'}{'dc'} = $newval;
8256: }
8257: }
8258: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 8259: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8260: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8261: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8262: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8263: if ($confhash{'validation'}{'dc'} eq '') {
8264: $changes{'validation'}{'dc'} = &mt('None');
8265: } else {
8266: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8267: }
1.160.6.39 raeburn 8268: }
1.160.6.65 raeburn 8269: } elsif ($confhash{'validation'}{'dc'} ne '') {
8270: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 8271: }
8272: } elsif ($confhash{'validation'}{'dc'} ne '') {
8273: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8274: }
8275: } elsif ($confhash{'validation'}{'dc'} ne '') {
8276: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8277: }
1.160.6.65 raeburn 8278: } else {
8279: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8280: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8281: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8282: $changes{'validation'}{'dc'} = &mt('None');
8283: }
8284: }
1.160.6.39 raeburn 8285: }
8286: }
1.102 raeburn 8287: }
8288: } else {
1.86 raeburn 8289: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 8290: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8291: }
1.72 raeburn 8292: foreach my $item (@usertools) {
8293: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8294: my $unset;
1.101 raeburn 8295: if ($context eq 'requestcourses') {
1.104 raeburn 8296: $unset = '0';
8297: if ($type eq '_LC_adv') {
8298: $unset = '';
8299: }
1.101 raeburn 8300: if ($confhash{$item}{$type} eq 'autolimit') {
8301: $confhash{$item}{$type} .= '=';
8302: unless ($limithash{$item}{$type} =~ /\D/) {
8303: $confhash{$item}{$type} .= $limithash{$item}{$type};
8304: }
8305: }
1.160.6.5 raeburn 8306: } elsif ($context eq 'requestauthor') {
8307: $unset = '0';
8308: if ($type eq '_LC_adv') {
8309: $unset = '';
8310: }
1.72 raeburn 8311: } else {
1.101 raeburn 8312: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8313: $confhash{$item}{$type} = 1;
8314: } else {
8315: $confhash{$item}{$type} = 0;
8316: }
1.72 raeburn 8317: }
1.86 raeburn 8318: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 8319: if ($action eq 'requestauthor') {
8320: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8321: $changes{$type} = 1;
8322: }
8323: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8324: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8325: $changes{$item}{$type} = 1;
8326: }
8327: } else {
8328: if ($context eq 'requestcourses') {
1.104 raeburn 8329: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8330: $changes{$item}{$type} = 1;
8331: }
8332: } else {
8333: if (!$confhash{$item}{$type}) {
8334: $changes{$item}{$type} = 1;
8335: }
8336: }
8337: }
8338: } else {
8339: if ($context eq 'requestcourses') {
1.104 raeburn 8340: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8341: $changes{$item}{$type} = 1;
8342: }
1.160.6.5 raeburn 8343: } elsif ($context eq 'requestauthor') {
8344: if ($confhash{$type} ne $unset) {
8345: $changes{$type} = 1;
8346: }
1.72 raeburn 8347: } else {
8348: if (!$confhash{$item}{$type}) {
8349: $changes{$item}{$type} = 1;
8350: }
8351: }
8352: }
1.1 raeburn 8353: }
8354: }
1.160.6.5 raeburn 8355: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8356: if (ref($domconfig{'quotas'}) eq 'HASH') {
8357: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8358: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8359: if (exists($confhash{'defaultquota'}{$key})) {
8360: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8361: $changes{'defaultquota'}{$key} = 1;
8362: }
8363: } else {
8364: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8365: }
8366: }
1.86 raeburn 8367: } else {
8368: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8369: if (exists($confhash{'defaultquota'}{$key})) {
8370: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8371: $changes{'defaultquota'}{$key} = 1;
8372: }
8373: } else {
8374: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8375: }
1.1 raeburn 8376: }
8377: }
1.160.6.20 raeburn 8378: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8379: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8380: if (exists($confhash{'authorquota'}{$key})) {
8381: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8382: $changes{'authorquota'}{$key} = 1;
8383: }
8384: } else {
8385: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8386: }
8387: }
8388: }
1.1 raeburn 8389: }
1.86 raeburn 8390: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8391: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8392: if (ref($domconfig{'quotas'}) eq 'HASH') {
8393: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8394: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8395: $changes{'defaultquota'}{$key} = 1;
8396: }
8397: } else {
8398: if (!exists($domconfig{'quotas'}{$key})) {
8399: $changes{'defaultquota'}{$key} = 1;
8400: }
1.72 raeburn 8401: }
8402: } else {
1.86 raeburn 8403: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8404: }
1.1 raeburn 8405: }
8406: }
1.160.6.20 raeburn 8407: if (ref($confhash{'authorquota'}) eq 'HASH') {
8408: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8409: if (ref($domconfig{'quotas'}) eq 'HASH') {
8410: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8411: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8412: $changes{'authorquota'}{$key} = 1;
8413: }
8414: } else {
8415: $changes{'authorquota'}{$key} = 1;
8416: }
8417: } else {
8418: $changes{'authorquota'}{$key} = 1;
8419: }
8420: }
8421: }
1.1 raeburn 8422: }
1.72 raeburn 8423:
1.160.6.5 raeburn 8424: if ($context eq 'requestauthor') {
8425: $domdefaults{'requestauthor'} = \%confhash;
8426: } else {
8427: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 8428: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 8429: $domdefaults{$key} = $confhash{$key};
8430: }
1.160.6.5 raeburn 8431: }
1.72 raeburn 8432: }
1.160.6.5 raeburn 8433:
1.1 raeburn 8434: my %quotahash = (
1.86 raeburn 8435: $action => { %confhash }
1.1 raeburn 8436: );
8437: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8438: $dom);
8439: if ($putresult eq 'ok') {
8440: if (keys(%changes) > 0) {
1.72 raeburn 8441: my $cachetime = 24*60*60;
8442: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 8443: if (ref($lastactref) eq 'HASH') {
8444: $lastactref->{'domdefaults'} = 1;
8445: }
1.1 raeburn 8446: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 8447: unless (($context eq 'requestcourses') ||
8448: ($context eq 'requestauthor')) {
1.86 raeburn 8449: if (ref($changes{'defaultquota'}) eq 'HASH') {
8450: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8451: foreach my $type (@{$types},'default') {
8452: if (defined($changes{'defaultquota'}{$type})) {
8453: my $typetitle = $usertypes->{$type};
8454: if ($type eq 'default') {
8455: $typetitle = $othertitle;
8456: }
1.160.6.28 raeburn 8457: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8458: }
8459: }
1.86 raeburn 8460: $resulttext .= '</ul></li>';
1.72 raeburn 8461: }
1.160.6.20 raeburn 8462: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 8463: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 8464: foreach my $type (@{$types},'default') {
8465: if (defined($changes{'authorquota'}{$type})) {
8466: my $typetitle = $usertypes->{$type};
8467: if ($type eq 'default') {
8468: $typetitle = $othertitle;
8469: }
1.160.6.28 raeburn 8470: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 8471: }
8472: }
8473: $resulttext .= '</ul></li>';
8474: }
1.72 raeburn 8475: }
1.80 raeburn 8476: my %newenv;
1.72 raeburn 8477: foreach my $item (@usertools) {
1.160.6.5 raeburn 8478: my (%haschgs,%inconf);
8479: if ($context eq 'requestauthor') {
8480: %haschgs = %changes;
8481: %inconf = %confhash;
8482: } else {
8483: if (ref($changes{$item}) eq 'HASH') {
8484: %haschgs = %{$changes{$item}};
8485: }
8486: if (ref($confhash{$item}) eq 'HASH') {
8487: %inconf = %{$confhash{$item}};
8488: }
8489: }
8490: if (keys(%haschgs) > 0) {
1.80 raeburn 8491: my $newacc =
8492: &Apache::lonnet::usertools_access($env{'user.name'},
8493: $env{'user.domain'},
1.86 raeburn 8494: $item,'reload',$context);
1.160.6.5 raeburn 8495: if (($context eq 'requestcourses') ||
8496: ($context eq 'requestauthor')) {
1.108 raeburn 8497: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8498: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8499: }
8500: } else {
8501: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8502: $newenv{'environment.availabletools.'.$item} = $newacc;
8503: }
1.80 raeburn 8504: }
1.160.6.5 raeburn 8505: unless ($context eq 'requestauthor') {
8506: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8507: }
1.72 raeburn 8508: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 8509: if ($haschgs{$type}) {
1.72 raeburn 8510: my $typetitle = $usertypes->{$type};
8511: if ($type eq 'default') {
8512: $typetitle = $othertitle;
8513: } elsif ($type eq '_LC_adv') {
8514: $typetitle = 'LON-CAPA Advanced Users';
8515: }
1.160.6.5 raeburn 8516: if ($inconf{$type}) {
1.101 raeburn 8517: if ($context eq 'requestcourses') {
8518: my $cond;
1.160.6.5 raeburn 8519: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8520: if ($1 eq '') {
8521: $cond = &mt('(Automatic processing of any request).');
8522: } else {
8523: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8524: }
8525: } else {
1.160.6.5 raeburn 8526: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8527: }
8528: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 8529: } elsif ($context eq 'requestauthor') {
8530: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8531: $titles{$inconf{$type}},$typetitle);
8532:
1.101 raeburn 8533: } else {
8534: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8535: }
1.72 raeburn 8536: } else {
1.104 raeburn 8537: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 8538: if ($inconf{$type} eq '0') {
1.104 raeburn 8539: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8540: } else {
8541: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8542: }
8543: } else {
8544: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8545: }
1.72 raeburn 8546: }
8547: }
1.26 raeburn 8548: }
1.160.6.5 raeburn 8549: unless ($context eq 'requestauthor') {
8550: $resulttext .= '</ul></li>';
8551: }
1.26 raeburn 8552: }
1.1 raeburn 8553: }
1.160.6.5 raeburn 8554: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8555: if (ref($changes{'notify'}) eq 'HASH') {
8556: if ($changes{'notify'}{'approval'}) {
8557: if (ref($confhash{'notify'}) eq 'HASH') {
8558: if ($confhash{'notify'}{'approval'}) {
8559: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8560: } else {
1.160.6.5 raeburn 8561: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8562: }
8563: }
8564: }
8565: }
8566: }
1.160.6.30 raeburn 8567: if ($action eq 'requestcourses') {
8568: my @offon = ('off','on');
8569: if ($changes{'uniquecode'}) {
8570: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8571: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8572: $resulttext .= '<li>'.
8573: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8574: '</li>';
8575: } else {
8576: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8577: '</li>';
8578: }
8579: }
1.160.6.46 raeburn 8580: foreach my $type ('textbooks','templates') {
8581: if (ref($changes{$type}) eq 'HASH') {
8582: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8583: foreach my $key (sort(keys(%{$changes{$type}}))) {
8584: my %coursehash = &Apache::lonnet::coursedescription($key);
8585: my $coursetitle = $coursehash{'description'};
8586: my $position = $confhash{$type}{$key}{'order'} + 1;
8587: $resulttext .= '<li>';
1.160.6.47 raeburn 8588: foreach my $item ('subject','title','publisher','author') {
8589: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8590: ($type eq 'templates'));
1.160.6.46 raeburn 8591: my $name = $item.':';
8592: $name =~ s/^(\w)/\U$1/;
8593: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8594: }
8595: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8596: if ($type eq 'textbooks') {
8597: if ($confhash{$type}{$key}{'image'}) {
8598: $resulttext .= ' '.&mt('Image: [_1]',
8599: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8600: ' alt="Textbook cover" />').'<br />';
8601: }
8602: }
8603: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 8604: }
1.160.6.46 raeburn 8605: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 8606: }
8607: }
1.160.6.39 raeburn 8608: if (ref($changes{'validation'}) eq 'HASH') {
8609: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8610: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8611: foreach my $item (@{$validationitemsref}) {
8612: if (exists($changes{'validation'}{$item})) {
8613: if ($item eq 'markup') {
8614: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8615: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8616: } else {
8617: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8618: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8619: }
8620: }
8621: }
8622: if (exists($changes{'validation'}{'dc'})) {
8623: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8624: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8625: }
8626: }
8627: }
1.160.6.30 raeburn 8628: }
1.1 raeburn 8629: $resulttext .= '</ul>';
1.80 raeburn 8630: if (keys(%newenv)) {
8631: &Apache::lonnet::appenv(\%newenv);
8632: }
1.1 raeburn 8633: } else {
1.86 raeburn 8634: if ($context eq 'requestcourses') {
8635: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 8636: } elsif ($context eq 'requestauthor') {
8637: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8638: } else {
1.90 weissno 8639: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8640: }
1.1 raeburn 8641: }
8642: } else {
1.11 albertel 8643: $resulttext = '<span class="LC_error">'.
8644: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8645: }
1.160.6.30 raeburn 8646: if ($errors) {
8647: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8648: '<ul>'.$errors.'</ul></p>';
8649: }
1.3 raeburn 8650: return $resulttext;
1.1 raeburn 8651: }
8652:
1.160.6.30 raeburn 8653: sub process_textbook_image {
1.160.6.46 raeburn 8654: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 8655: my $filename = $env{'form.'.$caller.'.filename'};
8656: my ($error,$url);
8657: my ($width,$height) = (50,50);
8658: if ($configuserok eq 'ok') {
8659: if ($switchserver) {
8660: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8661: $switchserver);
8662: } elsif ($author_ok eq 'ok') {
8663: my ($result,$imageurl) =
8664: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 8665: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 8666: if ($result eq 'ok') {
8667: $url = $imageurl;
8668: } else {
8669: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8670: }
8671: } else {
8672: $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);
8673: }
8674: } else {
8675: $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);
8676: }
8677: return ($url,$error);
8678: }
8679:
1.3 raeburn 8680: sub modify_autoenroll {
1.160.6.24 raeburn 8681: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 8682: my ($resulttext,%changes);
8683: my %currautoenroll;
8684: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
8685: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
8686: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
8687: }
8688: }
8689: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
8690: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 8691: sender => 'Sender for notification messages',
1.160.6.68 raeburn 8692: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
8693: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 8694: my @offon = ('off','on');
1.17 raeburn 8695: my $sender_uname = $env{'form.sender_uname'};
8696: my $sender_domain = $env{'form.sender_domain'};
8697: if ($sender_domain eq '') {
8698: $sender_uname = '';
8699: } elsif ($sender_uname eq '') {
8700: $sender_domain = '';
8701: }
1.129 raeburn 8702: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 8703: my $failsafe = $env{'form.autoenroll_failsafe'};
8704: $failsafe =~ s{^\s+|\s+$}{}g;
8705: if ($failsafe =~ /\D/) {
8706: undef($failsafe);
8707: }
1.1 raeburn 8708: my %autoenrollhash = (
1.129 raeburn 8709: autoenroll => { 'run' => $env{'form.autoenroll_run'},
8710: 'sender_uname' => $sender_uname,
8711: 'sender_domain' => $sender_domain,
8712: 'co-owners' => $coowners,
1.160.6.68 raeburn 8713: 'autofailsafe' => $failsafe,
1.1 raeburn 8714: }
8715: );
1.4 raeburn 8716: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
8717: $dom);
1.1 raeburn 8718: if ($putresult eq 'ok') {
8719: if (exists($currautoenroll{'run'})) {
8720: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
8721: $changes{'run'} = 1;
8722: }
8723: } elsif ($autorun) {
8724: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 8725: $changes{'run'} = 1;
1.1 raeburn 8726: }
8727: }
1.17 raeburn 8728: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 8729: $changes{'sender'} = 1;
8730: }
1.17 raeburn 8731: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 8732: $changes{'sender'} = 1;
8733: }
1.129 raeburn 8734: if ($currautoenroll{'co-owners'} ne '') {
8735: if ($currautoenroll{'co-owners'} ne $coowners) {
8736: $changes{'coowners'} = 1;
8737: }
8738: } elsif ($coowners) {
8739: $changes{'coowners'} = 1;
1.160.6.68 raeburn 8740: }
8741: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
8742: $changes{'autofailsafe'} = 1;
8743: }
1.1 raeburn 8744: if (keys(%changes) > 0) {
8745: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 8746: if ($changes{'run'}) {
1.1 raeburn 8747: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
8748: }
8749: if ($changes{'sender'}) {
1.17 raeburn 8750: if ($sender_uname eq '' || $sender_domain eq '') {
8751: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
8752: } else {
8753: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
8754: }
1.1 raeburn 8755: }
1.129 raeburn 8756: if ($changes{'coowners'}) {
8757: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
8758: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8759: if (ref($lastactref) eq 'HASH') {
8760: $lastactref->{'domainconfig'} = 1;
8761: }
1.129 raeburn 8762: }
1.160.6.68 raeburn 8763: if ($changes{'autofailsafe'}) {
8764: if ($failsafe ne '') {
8765: $resulttext .= '<li>'.&mt("$title{'failsafe'} set to [_1]",$failsafe).'</li>';
8766: } else {
8767: $resulttext .= '<li>'.&mt("$title{'failsafe'} deleted");
8768: }
8769: &Apache::lonnet::get_domain_defaults($dom,1);
8770: if (ref($lastactref) eq 'HASH') {
8771: $lastactref->{'domdefaults'} = 1;
8772: }
8773: }
1.1 raeburn 8774: $resulttext .= '</ul>';
8775: } else {
8776: $resulttext = &mt('No changes made to auto-enrollment settings');
8777: }
8778: } else {
1.11 albertel 8779: $resulttext = '<span class="LC_error">'.
8780: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8781: }
1.3 raeburn 8782: return $resulttext;
1.1 raeburn 8783: }
8784:
8785: sub modify_autoupdate {
1.3 raeburn 8786: my ($dom,%domconfig) = @_;
1.1 raeburn 8787: my ($resulttext,%currautoupdate,%fields,%changes);
8788: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
8789: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
8790: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
8791: }
8792: }
8793: my @offon = ('off','on');
8794: my %title = &Apache::lonlocal::texthash (
8795: run => 'Auto-update:',
8796: classlists => 'Updates to user information in classlists?'
8797: );
1.44 raeburn 8798: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8799: my %fieldtitles = &Apache::lonlocal::texthash (
8800: id => 'Student/Employee ID',
1.20 raeburn 8801: permanentemail => 'E-mail address',
1.1 raeburn 8802: lastname => 'Last Name',
8803: firstname => 'First Name',
8804: middlename => 'Middle Name',
1.132 raeburn 8805: generation => 'Generation',
1.1 raeburn 8806: );
1.142 raeburn 8807: $othertitle = &mt('All users');
1.1 raeburn 8808: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8809: $othertitle = &mt('Other users');
1.1 raeburn 8810: }
8811: foreach my $key (keys(%env)) {
8812: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8813: my ($usertype,$item) = ($1,$2);
8814: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8815: if ($usertype eq 'default') {
8816: push(@{$fields{$1}},$2);
8817: } elsif (ref($types) eq 'ARRAY') {
8818: if (grep(/^\Q$usertype\E$/,@{$types})) {
8819: push(@{$fields{$1}},$2);
8820: }
8821: }
8822: }
1.1 raeburn 8823: }
8824: }
1.131 raeburn 8825: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8826: @lockablenames = sort(@lockablenames);
8827: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8828: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8829: if (@changed) {
8830: $changes{'lockablenames'} = 1;
8831: }
8832: } else {
8833: if (@lockablenames) {
8834: $changes{'lockablenames'} = 1;
8835: }
8836: }
1.1 raeburn 8837: my %updatehash = (
8838: autoupdate => { run => $env{'form.autoupdate_run'},
8839: classlists => $env{'form.classlists'},
8840: fields => {%fields},
1.131 raeburn 8841: lockablenames => \@lockablenames,
1.1 raeburn 8842: }
8843: );
8844: foreach my $key (keys(%currautoupdate)) {
8845: if (($key eq 'run') || ($key eq 'classlists')) {
8846: if (exists($updatehash{autoupdate}{$key})) {
8847: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8848: $changes{$key} = 1;
8849: }
8850: }
8851: } elsif ($key eq 'fields') {
8852: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8853: foreach my $item (@{$types},'default') {
1.1 raeburn 8854: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8855: my $change = 0;
8856: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8857: if (!exists($fields{$item})) {
8858: $change = 1;
1.132 raeburn 8859: last;
1.1 raeburn 8860: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8861: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8862: $change = 1;
1.132 raeburn 8863: last;
1.1 raeburn 8864: }
8865: }
8866: }
8867: if ($change) {
8868: push(@{$changes{$key}},$item);
8869: }
1.26 raeburn 8870: }
1.1 raeburn 8871: }
8872: }
1.131 raeburn 8873: } elsif ($key eq 'lockablenames') {
8874: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8875: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8876: if (@changed) {
8877: $changes{'lockablenames'} = 1;
8878: }
8879: } else {
8880: if (@lockablenames) {
8881: $changes{'lockablenames'} = 1;
8882: }
8883: }
8884: }
8885: }
8886: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8887: if (@lockablenames) {
8888: $changes{'lockablenames'} = 1;
1.1 raeburn 8889: }
8890: }
1.26 raeburn 8891: foreach my $item (@{$types},'default') {
8892: if (defined($fields{$item})) {
8893: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8894: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8895: my $change = 0;
8896: if (ref($fields{$item}) eq 'ARRAY') {
8897: foreach my $type (@{$fields{$item}}) {
8898: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
8899: $change = 1;
8900: last;
8901: }
8902: }
8903: }
8904: if ($change) {
8905: push(@{$changes{'fields'}},$item);
8906: }
8907: } else {
1.26 raeburn 8908: push(@{$changes{'fields'}},$item);
8909: }
8910: } else {
8911: push(@{$changes{'fields'}},$item);
1.1 raeburn 8912: }
8913: }
8914: }
8915: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8916: $dom);
8917: if ($putresult eq 'ok') {
8918: if (keys(%changes) > 0) {
8919: $resulttext = &mt('Changes made:').'<ul>';
8920: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 8921: if ($key eq 'lockablenames') {
8922: $resulttext .= '<li>';
8923: if (@lockablenames) {
8924: $usertypes->{'default'} = $othertitle;
8925: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8926: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8927: } else {
8928: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8929: }
8930: $resulttext .= '</li>';
8931: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8932: foreach my $item (@{$changes{$key}}) {
8933: my @newvalues;
8934: foreach my $type (@{$fields{$item}}) {
8935: push(@newvalues,$fieldtitles{$type});
8936: }
1.3 raeburn 8937: my $newvaluestr;
8938: if (@newvalues > 0) {
8939: $newvaluestr = join(', ',@newvalues);
8940: } else {
8941: $newvaluestr = &mt('none');
1.6 raeburn 8942: }
1.1 raeburn 8943: if ($item eq 'default') {
1.26 raeburn 8944: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8945: } else {
1.26 raeburn 8946: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8947: }
8948: }
8949: } else {
8950: my $newvalue;
8951: if ($key eq 'run') {
8952: $newvalue = $offon[$env{'form.autoupdate_run'}];
8953: } else {
8954: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8955: }
1.1 raeburn 8956: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8957: }
8958: }
8959: $resulttext .= '</ul>';
8960: } else {
1.3 raeburn 8961: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8962: }
8963: } else {
1.11 albertel 8964: $resulttext = '<span class="LC_error">'.
8965: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8966: }
1.3 raeburn 8967: return $resulttext;
1.1 raeburn 8968: }
8969:
1.125 raeburn 8970: sub modify_autocreate {
8971: my ($dom,%domconfig) = @_;
8972: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8973: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8974: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8975: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8976: }
8977: }
8978: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8979: req => 'Auto-creation of validated requests for official courses',
8980: xmldc => 'Identity of course creator of courses from XML files',
8981: );
8982: my @types = ('xml','req');
8983: foreach my $item (@types) {
8984: $newvals{$item} = $env{'form.autocreate_'.$item};
8985: $newvals{$item} =~ s/\D//g;
8986: $newvals{$item} = 0 if ($newvals{$item} eq '');
8987: }
8988: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 8989: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 8990: unless (exists($domcoords{$newvals{'xmldc'}})) {
8991: $newvals{'xmldc'} = '';
8992: }
8993: %autocreatehash = (
8994: autocreate => { xml => $newvals{'xml'},
8995: req => $newvals{'req'},
8996: }
8997: );
8998: if ($newvals{'xmldc'} ne '') {
8999: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9000: }
9001: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9002: $dom);
9003: if ($putresult eq 'ok') {
9004: my @items = @types;
9005: if ($newvals{'xml'}) {
9006: push(@items,'xmldc');
9007: }
9008: foreach my $item (@items) {
9009: if (exists($currautocreate{$item})) {
9010: if ($currautocreate{$item} ne $newvals{$item}) {
9011: $changes{$item} = 1;
9012: }
9013: } elsif ($newvals{$item}) {
9014: $changes{$item} = 1;
9015: }
9016: }
9017: if (keys(%changes) > 0) {
9018: my @offon = ('off','on');
9019: $resulttext = &mt('Changes made:').'<ul>';
9020: foreach my $item (@types) {
9021: if ($changes{$item}) {
9022: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 9023: $resulttext .= '<li>'.
9024: &mt("$title{$item} set to [_1]$newtxt [_2]",
9025: '<b>','</b>').
9026: '</li>';
1.125 raeburn 9027: }
9028: }
9029: if ($changes{'xmldc'}) {
9030: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9031: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 9032: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9033: }
9034: $resulttext .= '</ul>';
9035: } else {
9036: $resulttext = &mt('No changes made to auto-creation settings');
9037: }
9038: } else {
9039: $resulttext = '<span class="LC_error">'.
9040: &mt('An error occurred: [_1]',$putresult).'</span>';
9041: }
9042: return $resulttext;
9043: }
9044:
1.23 raeburn 9045: sub modify_directorysrch {
9046: my ($dom,%domconfig) = @_;
9047: my ($resulttext,%changes);
9048: my %currdirsrch;
9049: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9050: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9051: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9052: }
9053: }
1.160.6.72 raeburn 9054: my %title = ( available => 'Institutional directory search available',
9055: localonly => 'Other domains can search institution',
9056: lcavailable => 'LON-CAPA directory search available',
9057: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9058: searchby => 'Search types',
9059: searchtypes => 'Search latitude');
9060: my @offon = ('off','on');
1.24 raeburn 9061: my @otherdoms = ('Yes','No');
1.23 raeburn 9062:
1.25 raeburn 9063: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9064: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9065: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9066:
1.44 raeburn 9067: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9068: if (keys(%{$usertypes}) == 0) {
9069: @cansearch = ('default');
9070: } else {
9071: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9072: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9073: if (!grep(/^\Q$type\E$/,@cansearch)) {
9074: push(@{$changes{'cansearch'}},$type);
9075: }
1.23 raeburn 9076: }
1.26 raeburn 9077: foreach my $type (@cansearch) {
9078: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9079: push(@{$changes{'cansearch'}},$type);
9080: }
1.23 raeburn 9081: }
1.26 raeburn 9082: } else {
9083: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9084: }
9085: }
9086:
9087: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9088: foreach my $by (@{$currdirsrch{'searchby'}}) {
9089: if (!grep(/^\Q$by\E$/,@searchby)) {
9090: push(@{$changes{'searchby'}},$by);
9091: }
9092: }
9093: foreach my $by (@searchby) {
9094: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9095: push(@{$changes{'searchby'}},$by);
9096: }
9097: }
9098: } else {
9099: push(@{$changes{'searchby'}},@searchby);
9100: }
1.25 raeburn 9101:
9102: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9103: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9104: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9105: push(@{$changes{'searchtypes'}},$type);
9106: }
9107: }
9108: foreach my $type (@searchtypes) {
9109: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9110: push(@{$changes{'searchtypes'}},$type);
9111: }
9112: }
9113: } else {
9114: if (exists($currdirsrch{'searchtypes'})) {
9115: foreach my $type (@searchtypes) {
9116: if ($type ne $currdirsrch{'searchtypes'}) {
9117: push(@{$changes{'searchtypes'}},$type);
9118: }
9119: }
9120: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9121: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9122: }
9123: } else {
9124: push(@{$changes{'searchtypes'}},@searchtypes);
9125: }
9126: }
9127:
1.23 raeburn 9128: my %dirsrch_hash = (
9129: directorysrch => { available => $env{'form.dirsrch_available'},
9130: cansearch => \@cansearch,
1.160.6.72 raeburn 9131: localonly => $env{'form.dirsrch_instlocalonly'},
9132: lclocalonly => $env{'form.dirsrch_domlocalonly'},
9133: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9134: searchby => \@searchby,
1.25 raeburn 9135: searchtypes => \@searchtypes,
1.23 raeburn 9136: }
9137: );
9138: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9139: $dom);
9140: if ($putresult eq 'ok') {
9141: if (exists($currdirsrch{'available'})) {
9142: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9143: $changes{'available'} = 1;
9144: }
9145: } else {
9146: if ($env{'form.dirsrch_available'} eq '1') {
9147: $changes{'available'} = 1;
9148: }
9149: }
1.160.6.72 raeburn 9150: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 9151: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
9152: $changes{'lcavailable'} = 1;
9153: }
1.24 raeburn 9154: } else {
1.160.6.72 raeburn 9155: if ($env{'form.dirsrch_lcavailable'} eq '1') {
9156: $changes{'lcavailable'} = 1;
9157: }
9158: }
9159: if (exists($currdirsrch{'localonly'})) {
9160: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9161: $changes{'localonly'} = 1;
9162: }
1.160.6.72 raeburn 9163: } else {
9164: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
9165: $changes{'localonly'} = 1;
9166: }
9167: }
9168: if (exists($currdirsrch{'lclocalonly'})) {
9169: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
9170: $changes{'lclocalonly'} = 1;
9171: }
9172: } else {
9173: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
9174: $changes{'lclocalonly'} = 1;
9175: }
1.24 raeburn 9176: }
1.23 raeburn 9177: if (keys(%changes) > 0) {
9178: $resulttext = &mt('Changes made:').'<ul>';
9179: if ($changes{'available'}) {
9180: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9181: }
1.160.6.72 raeburn 9182: if ($changes{'lcavailable'}) {
9183: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
9184: }
1.24 raeburn 9185: if ($changes{'localonly'}) {
1.160.6.72 raeburn 9186: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
9187: }
9188: if ($changes{'lclocalonly'}) {
9189: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 9190: }
1.23 raeburn 9191: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9192: my $chgtext;
1.26 raeburn 9193: if (ref($usertypes) eq 'HASH') {
9194: if (keys(%{$usertypes}) > 0) {
9195: foreach my $type (@{$types}) {
9196: if (grep(/^\Q$type\E$/,@cansearch)) {
9197: $chgtext .= $usertypes->{$type}.'; ';
9198: }
9199: }
9200: if (grep(/^default$/,@cansearch)) {
9201: $chgtext .= $othertitle;
9202: } else {
9203: $chgtext =~ s/\; $//;
9204: }
1.160.6.13 raeburn 9205: $resulttext .=
9206: '<li>'.
9207: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9208: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9209: '</li>';
1.23 raeburn 9210: }
9211: }
9212: }
9213: if (ref($changes{'searchby'}) eq 'ARRAY') {
9214: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9215: my $chgtext;
9216: foreach my $type (@{$titleorder}) {
9217: if (grep(/^\Q$type\E$/,@searchby)) {
9218: if (defined($searchtitles->{$type})) {
9219: $chgtext .= $searchtitles->{$type}.'; ';
9220: }
9221: }
9222: }
9223: $chgtext =~ s/\; $//;
9224: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9225: }
1.25 raeburn 9226: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9227: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9228: my $chgtext;
9229: foreach my $type (@{$srchtypeorder}) {
9230: if (grep(/^\Q$type\E$/,@searchtypes)) {
9231: if (defined($srchtypes_desc->{$type})) {
9232: $chgtext .= $srchtypes_desc->{$type}.'; ';
9233: }
9234: }
9235: }
9236: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 9237: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9238: }
9239: $resulttext .= '</ul>';
9240: } else {
1.160.6.72 raeburn 9241: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9242: }
9243: } else {
9244: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9245: &mt('An error occurred: [_1]',$putresult).'</span>';
9246: }
9247: return $resulttext;
9248: }
9249:
1.28 raeburn 9250: sub modify_contacts {
1.160.6.24 raeburn 9251: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9252: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9253: if (ref($domconfig{'contacts'}) eq 'HASH') {
9254: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9255: $currsetting{$key} = $domconfig{'contacts'}{$key};
9256: }
9257: }
1.160.6.78 raeburn 9258: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 9259: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 9260: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
9261: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.160.6.23 raeburn 9262: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 9263: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 9264: foreach my $type (@mailings) {
9265: @{$newsetting{$type}} =
9266: &Apache::loncommon::get_env_multiple('form.'.$type);
9267: foreach my $item (@contacts) {
9268: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9269: $contacts_hash{contacts}{$type}{$item} = 1;
9270: } else {
9271: $contacts_hash{contacts}{$type}{$item} = 0;
9272: }
1.160.6.78 raeburn 9273: }
1.28 raeburn 9274: $others{$type} = $env{'form.'.$type.'_others'};
9275: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 9276: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9277: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9278: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 9279: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
9280: $includestr{$type} = $env{'form.'.$type.'_includestr'};
9281: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
9282: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
9283: }
1.134 raeburn 9284: }
1.28 raeburn 9285: }
9286: foreach my $item (@contacts) {
9287: $to{$item} = $env{'form.'.$item};
9288: $contacts_hash{'contacts'}{$item} = $to{$item};
9289: }
1.160.6.23 raeburn 9290: foreach my $item (@toggles) {
9291: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9292: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9293: }
9294: }
1.160.6.78 raeburn 9295: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
9296: foreach my $field (@{$fields}) {
9297: if (ref($possoptions->{$field}) eq 'ARRAY') {
9298: my $value = $env{'form.helpform_'.$field};
9299: $value =~ s/^\s+|\s+$//g;
9300: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
9301: $contacts_hash{contacts}{'helpform'}{$field} = $value;
9302: if ($field eq 'screenshot') {
9303: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
9304: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
9305: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
9306: }
9307: }
9308: }
9309: }
9310: }
9311: }
1.28 raeburn 9312: if (keys(%currsetting) > 0) {
9313: foreach my $item (@contacts) {
9314: if ($to{$item} ne $currsetting{$item}) {
9315: $changes{$item} = 1;
9316: }
9317: }
9318: foreach my $type (@mailings) {
9319: foreach my $item (@contacts) {
9320: if (ref($currsetting{$type}) eq 'HASH') {
9321: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9322: push(@{$changes{$type}},$item);
9323: }
9324: } else {
9325: push(@{$changes{$type}},@{$newsetting{$type}});
9326: }
9327: }
9328: if ($others{$type} ne $currsetting{$type}{'others'}) {
9329: push(@{$changes{$type}},'others');
9330: }
1.160.6.78 raeburn 9331: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9332: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9333: push(@{$changes{$type}},'bcc');
9334: }
1.160.6.78 raeburn 9335: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
9336: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
9337: push(@{$changes{$type}},'include');
9338: }
9339: }
9340: }
9341: if (ref($fields) eq 'ARRAY') {
9342: if (ref($currsetting{'helpform'}) eq 'HASH') {
9343: foreach my $field (@{$fields}) {
9344: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
9345: push(@{$changes{'helpform'}},$field);
9346: }
9347: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9348: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
9349: push(@{$changes{'helpform'}},'maxsize');
9350: }
9351: }
9352: }
9353: } else {
9354: foreach my $field (@{$fields}) {
9355: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9356: push(@{$changes{'helpform'}},$field);
9357: }
9358: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9359: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9360: push(@{$changes{'helpform'}},'maxsize');
9361: }
9362: }
9363: }
1.134 raeburn 9364: }
1.28 raeburn 9365: }
9366: } else {
9367: my %default;
9368: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9369: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9370: $default{'errormail'} = 'adminemail';
9371: $default{'packagesmail'} = 'adminemail';
9372: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 9373: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 9374: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9375: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 9376: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9377: foreach my $item (@contacts) {
9378: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 9379: $changes{$item} = 1;
1.160.6.23 raeburn 9380: }
1.28 raeburn 9381: }
9382: foreach my $type (@mailings) {
9383: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9384: push(@{$changes{$type}},@{$newsetting{$type}});
9385: }
9386: if ($others{$type} ne '') {
9387: push(@{$changes{$type}},'others');
1.134 raeburn 9388: }
1.160.6.78 raeburn 9389: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9390: if ($bcc{$type} ne '') {
9391: push(@{$changes{$type}},'bcc');
9392: }
1.160.6.78 raeburn 9393: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
9394: push(@{$changes{$type}},'include');
9395: }
9396: }
9397: }
9398: if (ref($fields) eq 'ARRAY') {
9399: foreach my $field (@{$fields}) {
9400: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9401: push(@{$changes{'helpform'}},$field);
9402: }
9403: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9404: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9405: push(@{$changes{'helpform'}},'maxsize');
9406: }
9407: }
1.134 raeburn 9408: }
1.28 raeburn 9409: }
9410: }
1.160.6.23 raeburn 9411: foreach my $item (@toggles) {
9412: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9413: $changes{$item} = 1;
9414: } elsif ((!$env{'form.'.$item}) &&
9415: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9416: $changes{$item} = 1;
9417: }
9418: }
1.28 raeburn 9419: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9420: $dom);
9421: if ($putresult eq 'ok') {
9422: if (keys(%changes) > 0) {
1.160.6.24 raeburn 9423: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9424: if (ref($lastactref) eq 'HASH') {
9425: $lastactref->{'domainconfig'} = 1;
9426: }
1.28 raeburn 9427: my ($titles,$short_titles) = &contact_titles();
9428: $resulttext = &mt('Changes made:').'<ul>';
9429: foreach my $item (@contacts) {
9430: if ($changes{$item}) {
9431: $resulttext .= '<li>'.$titles->{$item}.
9432: &mt(' set to: ').
9433: '<span class="LC_cusr_emph">'.
9434: $to{$item}.'</span></li>';
9435: }
9436: }
9437: foreach my $type (@mailings) {
9438: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 9439: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
9440: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
9441: } else {
9442: $resulttext .= '<li>'.$titles->{$type}.': ';
9443: }
1.28 raeburn 9444: my @text;
9445: foreach my $item (@{$newsetting{$type}}) {
9446: push(@text,$short_titles->{$item});
9447: }
9448: if ($others{$type} ne '') {
9449: push(@text,$others{$type});
9450: }
1.160.6.78 raeburn 9451: if (@text) {
9452: $resulttext .= '<span class="LC_cusr_emph">'.
9453: join(', ',@text).'</span>';
9454: }
9455: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9456: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 9457: my $bcctext;
9458: if (@text) {
9459: $bcctext = ' '.&mt('with Bcc to');
9460: } else {
9461: $bcctext = '(Bcc)';
9462: }
9463: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9464: } elsif (!@text) {
9465: $resulttext .= &mt('No one');
1.134 raeburn 9466: }
1.160.6.78 raeburn 9467: if ($includestr{$type} ne '') {
9468: if ($includeloc{$type} eq 'b') {
9469: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
9470: } elsif ($includeloc{$type} eq 's') {
9471: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
9472: }
9473: }
9474: } elsif (!@text) {
9475: $resulttext .= &mt('No recipients');
1.134 raeburn 9476: }
9477: $resulttext .= '</li>';
1.28 raeburn 9478: }
9479: }
1.160.6.23 raeburn 9480: my @offon = ('off','on');
9481: if ($changes{'reporterrors'}) {
9482: $resulttext .= '<li>'.
9483: &mt('E-mail error reports to [_1] set to "'.
9484: $offon[$env{'form.reporterrors'}].'".',
9485: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9486: &mt('LON-CAPA core group - MSU'),600,500)).
9487: '</li>';
9488: }
9489: if ($changes{'reportupdates'}) {
9490: $resulttext .= '<li>'.
9491: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9492: $offon[$env{'form.reportupdates'}].'".',
9493: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9494: &mt('LON-CAPA core group - MSU'),600,500)).
9495: '</li>';
9496: }
1.160.6.78 raeburn 9497: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
9498: my (@optional,@required,@unused,$maxsizechg);
9499: foreach my $field (@{$changes{'helpform'}}) {
9500: if ($field eq 'maxsize') {
9501: $maxsizechg = 1;
9502: next;
9503: }
9504: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
9505: push(@optional,$field);
9506: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
9507: push(@unused,$field);
9508: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
9509: push(@required,$field);
9510: }
9511: }
9512: if (@optional) {
9513: $resulttext .= '<li>'.
9514: &mt('Help form fields changed to "Optional": [_1].',
9515: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
9516: '</li>';
9517: }
9518: if (@required) {
9519: $resulttext .= '<li>'.
9520: &mt('Help form fields changed to "Required": [_1].',
9521: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
9522: '</li>';
9523: }
9524: if (@unused) {
9525: $resulttext .= '<li>'.
9526: &mt('Help form fields changed to "Not shown": [_1].',
9527: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
9528: '</li>';
9529: }
9530: if ($maxsizechg) {
9531: $resulttext .= '<li>'.
9532: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
9533: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
9534: '</li>';
9535:
9536: }
9537: }
1.28 raeburn 9538: $resulttext .= '</ul>';
9539: } else {
1.160.6.78 raeburn 9540: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 9541: }
9542: } else {
9543: $resulttext = '<span class="LC_error">'.
9544: &mt('An error occurred: [_1].',$putresult).'</span>';
9545: }
9546: return $resulttext;
9547: }
9548:
9549: sub modify_usercreation {
1.27 raeburn 9550: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9551: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9552: my $warningmsg;
1.27 raeburn 9553: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9554: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 9555: if ($key eq 'cancreate') {
9556: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9557: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9558: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 9559: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9560: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 9561: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9562: } else {
9563: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9564: }
1.50 raeburn 9565: }
1.43 raeburn 9566: }
1.160.6.34 raeburn 9567: } elsif ($key eq 'email_rule') {
9568: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9569: } else {
9570: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 9571: }
9572: }
1.34 raeburn 9573: }
1.160.6.34 raeburn 9574: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
9575: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
9576: my @contexts = ('author','course','requestcrs');
9577: foreach my $item(@contexts) {
9578: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9579: }
1.34 raeburn 9580: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9581: foreach my $item (@contexts) {
1.160.6.34 raeburn 9582: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9583: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9584: }
1.27 raeburn 9585: }
1.34 raeburn 9586: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9587: foreach my $item (@contexts) {
1.43 raeburn 9588: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9589: if ($cancreate{$item} ne 'any') {
9590: push(@{$changes{'cancreate'}},$item);
9591: }
9592: } else {
9593: if ($cancreate{$item} ne 'none') {
9594: push(@{$changes{'cancreate'}},$item);
9595: }
1.27 raeburn 9596: }
9597: }
9598: } else {
1.43 raeburn 9599: foreach my $item (@contexts) {
1.34 raeburn 9600: push(@{$changes{'cancreate'}},$item);
9601: }
1.27 raeburn 9602: }
1.34 raeburn 9603:
1.27 raeburn 9604: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9605: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9606: if (!grep(/^\Q$type\E$/,@username_rule)) {
9607: push(@{$changes{'username_rule'}},$type);
9608: }
9609: }
9610: foreach my $type (@username_rule) {
9611: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9612: push(@{$changes{'username_rule'}},$type);
9613: }
9614: }
9615: } else {
9616: push(@{$changes{'username_rule'}},@username_rule);
9617: }
9618:
1.32 raeburn 9619: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9620: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9621: if (!grep(/^\Q$type\E$/,@id_rule)) {
9622: push(@{$changes{'id_rule'}},$type);
9623: }
9624: }
9625: foreach my $type (@id_rule) {
9626: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9627: push(@{$changes{'id_rule'}},$type);
9628: }
9629: }
9630: } else {
9631: push(@{$changes{'id_rule'}},@id_rule);
9632: }
9633:
1.43 raeburn 9634: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9635: my @authtypes = ('int','krb4','krb5','loc');
9636: my %authhash;
1.43 raeburn 9637: foreach my $item (@authen_contexts) {
1.28 raeburn 9638: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9639: foreach my $auth (@authtypes) {
9640: if (grep(/^\Q$auth\E$/,@authallowed)) {
9641: $authhash{$item}{$auth} = 1;
9642: } else {
9643: $authhash{$item}{$auth} = 0;
9644: }
9645: }
9646: }
9647: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9648: foreach my $item (@authen_contexts) {
1.28 raeburn 9649: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
9650: foreach my $auth (@authtypes) {
9651: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
9652: push(@{$changes{'authtypes'}},$item);
9653: last;
9654: }
9655: }
9656: }
9657: }
9658: } else {
1.43 raeburn 9659: foreach my $item (@authen_contexts) {
1.28 raeburn 9660: push(@{$changes{'authtypes'}},$item);
9661: }
9662: }
9663:
1.160.6.34 raeburn 9664: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
9665: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
9666: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
9667: $save_usercreate{'id_rule'} = \@id_rule;
9668: $save_usercreate{'username_rule'} = \@username_rule,
9669: $save_usercreate{'authtypes'} = \%authhash;
9670:
1.27 raeburn 9671: my %usercreation_hash = (
1.160.6.34 raeburn 9672: usercreation => \%save_usercreate,
9673: );
1.27 raeburn 9674:
9675: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
9676: $dom);
1.50 raeburn 9677:
1.160.6.34 raeburn 9678: if ($putresult eq 'ok') {
9679: if (keys(%changes) > 0) {
9680: $resulttext = &mt('Changes made:').'<ul>';
9681: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9682: my %lt = &usercreation_types();
9683: foreach my $type (@{$changes{'cancreate'}}) {
9684: my $chgtext = $lt{$type}.', ';
9685: if ($cancreate{$type} eq 'none') {
9686: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
9687: } elsif ($cancreate{$type} eq 'any') {
9688: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
9689: } elsif ($cancreate{$type} eq 'official') {
9690: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
9691: } elsif ($cancreate{$type} eq 'unofficial') {
9692: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
9693: }
9694: $resulttext .= '<li>'.$chgtext.'</li>';
9695: }
9696: }
9697: if (ref($changes{'username_rule'}) eq 'ARRAY') {
9698: my ($rules,$ruleorder) =
9699: &Apache::lonnet::inst_userrules($dom,'username');
9700: my $chgtext = '<ul>';
9701: foreach my $type (@username_rule) {
9702: if (ref($rules->{$type}) eq 'HASH') {
9703: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
9704: }
9705: }
9706: $chgtext .= '</ul>';
9707: if (@username_rule > 0) {
9708: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9709: } else {
9710: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
9711: }
9712: }
9713: if (ref($changes{'id_rule'}) eq 'ARRAY') {
9714: my ($idrules,$idruleorder) =
9715: &Apache::lonnet::inst_userrules($dom,'id');
9716: my $chgtext = '<ul>';
9717: foreach my $type (@id_rule) {
9718: if (ref($idrules->{$type}) eq 'HASH') {
9719: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
9720: }
9721: }
9722: $chgtext .= '</ul>';
9723: if (@id_rule > 0) {
9724: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9725: } else {
9726: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
9727: }
9728: }
9729: my %authname = &authtype_names();
9730: my %context_title = &context_names();
9731: if (ref($changes{'authtypes'}) eq 'ARRAY') {
9732: my $chgtext = '<ul>';
9733: foreach my $type (@{$changes{'authtypes'}}) {
9734: my @allowed;
9735: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
9736: foreach my $auth (@authtypes) {
9737: if ($authhash{$type}{$auth}) {
9738: push(@allowed,$authname{$auth});
9739: }
9740: }
9741: if (@allowed > 0) {
9742: $chgtext .= join(', ',@allowed).'</li>';
9743: } else {
9744: $chgtext .= &mt('none').'</li>';
9745: }
9746: }
9747: $chgtext .= '</ul>';
9748: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
9749: $resulttext .= '</li>';
9750: }
9751: $resulttext .= '</ul>';
9752: } else {
9753: $resulttext = &mt('No changes made to user creation settings');
9754: }
9755: } else {
9756: $resulttext = '<span class="LC_error">'.
9757: &mt('An error occurred: [_1]',$putresult).'</span>';
9758: }
9759: if ($warningmsg ne '') {
9760: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9761: }
9762: return $resulttext;
9763: }
9764:
9765: sub modify_selfcreation {
9766: my ($dom,%domconfig) = @_;
9767: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
9768: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 9769: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9770: if (ref($types) eq 'ARRAY') {
9771: $usertypes->{'default'} = $othertitle;
9772: push(@{$types},'default');
9773: }
1.160.6.34 raeburn 9774: #
9775: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
9776: #
9777: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9778: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9779: if ($key eq 'cancreate') {
9780: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9781: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9782: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9783: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 9784: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 9785: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 9786: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 9787: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9788: } else {
9789: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9790: }
9791: }
9792: }
9793: } elsif ($key eq 'email_rule') {
9794: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9795: } else {
9796: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9797: }
9798: }
9799: }
9800: #
9801: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
9802: #
9803: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9804: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9805: if ($key eq 'selfcreate') {
9806: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
9807: } else {
9808: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
9809: }
9810: }
9811: }
9812:
9813: my @contexts = ('selfcreate');
9814: @{$cancreate{'selfcreate'}} = ();
9815: %{$cancreate{'emailusername'}} = ();
9816: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 9817: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 9818: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 9819: my %selfcreatetypes = (
9820: sso => 'users authenticated by institutional single sign on',
9821: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 9822: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 9823: );
1.160.6.34 raeburn 9824: #
9825: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
9826: # is permitted.
9827: #
1.160.6.40 raeburn 9828:
9829: my @statuses;
9830: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9831: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
9832: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
9833: }
9834: }
9835: push(@statuses,'default');
9836:
1.160.6.35 raeburn 9837: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 9838: if ($item eq 'email') {
1.160.6.40 raeburn 9839: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 9840: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 9841: push(@contexts,'selfcreateprocessing');
9842: foreach my $type (@statuses) {
9843: if ($type eq 'default') {
9844: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
9845: } else {
9846: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
9847: }
9848: }
1.160.6.34 raeburn 9849: }
9850: } else {
9851: if ($env{'form.cancreate_'.$item}) {
9852: push(@{$cancreate{'selfcreate'}},$item);
9853: }
9854: }
9855: }
9856: my (@email_rule,%userinfo,%savecaptcha);
9857: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9858: #
1.160.6.35 raeburn 9859: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9860: # 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 9861: #
1.160.6.40 raeburn 9862:
1.160.6.48 raeburn 9863: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 9864: push(@contexts,'emailusername');
1.160.6.35 raeburn 9865: if (ref($types) eq 'ARRAY') {
9866: foreach my $type (@{$types}) {
9867: if (ref($infofields) eq 'ARRAY') {
9868: foreach my $field (@{$infofields}) {
9869: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9870: $cancreate{'emailusername'}{$type}{$field} = $1;
9871: }
9872: }
1.160.6.34 raeburn 9873: }
9874: }
9875: }
9876: #
9877: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9878: # queued requests for self-creation of account using e-mail address as username
9879: #
9880:
9881: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9882: @approvalnotify = sort(@approvalnotify);
9883: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9884: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9885: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9886: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9887: push(@{$changes{'cancreate'}},'notify');
9888: }
9889: } else {
9890: if ($cancreate{'notify'}{'approval'}) {
9891: push(@{$changes{'cancreate'}},'notify');
9892: }
9893: }
9894: } elsif ($cancreate{'notify'}{'approval'}) {
9895: push(@{$changes{'cancreate'}},'notify');
9896: }
9897:
9898: #
9899: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9900: #
9901: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9902: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9903: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9904: if (@{$curr_usercreation{'email_rule'}} > 0) {
9905: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9906: if (!grep(/^\Q$type\E$/,@email_rule)) {
9907: push(@{$changes{'email_rule'}},$type);
9908: }
9909: }
9910: }
9911: if (@email_rule > 0) {
9912: foreach my $type (@email_rule) {
9913: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9914: push(@{$changes{'email_rule'}},$type);
9915: }
9916: }
9917: }
9918: } elsif (@email_rule > 0) {
9919: push(@{$changes{'email_rule'}},@email_rule);
9920: }
9921: }
9922: #
1.160.6.40 raeburn 9923: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 9924: # institutional log-in.
9925: #
9926: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9927: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9928: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
9929: ($domdefaults{'auth_def'} eq 'localauth'))) {
9930: $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.').' '.
9931: &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.');
9932: }
9933: }
9934: my @fields = ('lastname','firstname','middlename','generation',
9935: 'permanentemail','id');
1.160.6.44 raeburn 9936: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 9937: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9938: #
9939: # Where usernames may created for institutional log-in and/or institutional single sign on:
9940: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9941: # may self-create accounts
9942: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
9943: # which the user may supply, if institutional data is unavailable.
9944: #
9945: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
9946: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 9947: if (@{$types} > 1) {
1.160.6.34 raeburn 9948: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
9949: push(@contexts,'statustocreate');
9950: } else {
9951: undef($cancreate{'statustocreate'});
9952: }
9953: foreach my $type (@{$types}) {
9954: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
9955: foreach my $field (@fields) {
9956: if (grep(/^\Q$field\E$/,@modifiable)) {
9957: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9958: } else {
9959: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9960: }
9961: }
9962: }
9963: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9964: foreach my $type (@{$types}) {
9965: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9966: foreach my $field (@fields) {
9967: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9968: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9969: push(@{$changes{'selfcreate'}},$type);
9970: last;
9971: }
9972: }
9973: }
9974: }
9975: } else {
9976: foreach my $type (@{$types}) {
9977: push(@{$changes{'selfcreate'}},$type);
9978: }
9979: }
9980: }
1.160.6.44 raeburn 9981: foreach my $field (@shibfields) {
9982: if ($env{'form.shibenv_'.$field} ne '') {
9983: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
9984: }
9985: }
9986: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9987: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
9988: foreach my $field (@shibfields) {
9989: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
9990: push(@{$changes{'cancreate'}},'shibenv');
9991: }
9992: }
9993: } else {
9994: foreach my $field (@shibfields) {
9995: if ($env{'form.shibenv_'.$field}) {
9996: push(@{$changes{'cancreate'}},'shibenv');
9997: last;
9998: }
9999: }
10000: }
10001: }
1.160.6.34 raeburn 10002: }
10003: foreach my $item (@contexts) {
10004: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10005: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10006: if (ref($cancreate{$item}) eq 'ARRAY') {
10007: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10008: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10009: push(@{$changes{'cancreate'}},$item);
10010: }
10011: }
10012: }
10013: }
10014: if (ref($cancreate{$item}) eq 'ARRAY') {
10015: foreach my $type (@{$cancreate{$item}}) {
10016: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10017: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10018: push(@{$changes{'cancreate'}},$item);
10019: }
10020: }
10021: }
10022: }
10023: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10024: if (ref($cancreate{$item}) eq 'HASH') {
10025: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 10026: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10027: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10028: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10029: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10030: push(@{$changes{'cancreate'}},$item);
10031: }
10032: }
10033: }
1.160.6.40 raeburn 10034: } elsif ($item eq 'selfcreateprocessing') {
10035: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10036: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10037: push(@{$changes{'cancreate'}},$item);
10038: }
10039: }
1.160.6.35 raeburn 10040: } else {
10041: if (!$cancreate{$item}{$curr}) {
10042: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10043: push(@{$changes{'cancreate'}},$item);
10044: }
1.160.6.34 raeburn 10045: }
10046: }
10047: }
10048: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 10049: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10050: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10051: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10052: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10053: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10054: push(@{$changes{'cancreate'}},$item);
10055: }
10056: }
10057: } else {
10058: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10059: push(@{$changes{'cancreate'}},$item);
10060: }
10061: }
10062: }
1.160.6.40 raeburn 10063: } elsif ($item eq 'selfcreateprocessing') {
10064: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10065: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10066: push(@{$changes{'cancreate'}},$item);
10067: }
10068: }
1.160.6.35 raeburn 10069: } else {
10070: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10071: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10072: push(@{$changes{'cancreate'}},$item);
10073: }
1.160.6.34 raeburn 10074: }
10075: }
10076: }
10077: }
10078: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10079: if (ref($cancreate{$item}) eq 'ARRAY') {
10080: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10081: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10082: push(@{$changes{'cancreate'}},$item);
10083: }
10084: }
10085: } elsif (ref($cancreate{$item}) eq 'HASH') {
10086: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10087: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10088: push(@{$changes{'cancreate'}},$item);
10089: }
10090: }
10091: }
10092: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 10093: if (ref($cancreate{$item}) eq 'HASH') {
10094: foreach my $type (keys(%{$cancreate{$item}})) {
10095: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10096: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10097: if ($cancreate{$item}{$type}{$field}) {
10098: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10099: push(@{$changes{'cancreate'}},$item);
10100: }
10101: last;
10102: }
10103: }
10104: }
10105: }
1.160.6.34 raeburn 10106: }
10107: }
10108: }
10109: #
10110: # Populate %save_usercreate hash with updates to self-creation configuration.
10111: #
10112: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10113: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 10114: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 10115: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10116: if (ref($cancreate{'notify'}) eq 'HASH') {
10117: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10118: }
1.160.6.40 raeburn 10119: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10120: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10121: }
1.160.6.34 raeburn 10122: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10123: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10124: }
1.160.6.44 raeburn 10125: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10126: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10127: }
1.160.6.34 raeburn 10128: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
10129: $save_usercreate{'emailrule'} = \@email_rule;
10130:
10131: my %userconfig_hash = (
10132: usercreation => \%save_usercreate,
10133: usermodification => \%save_usermodify,
10134: );
10135: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10136: $dom);
10137: #
10138: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10139: #
1.27 raeburn 10140: if ($putresult eq 'ok') {
10141: if (keys(%changes) > 0) {
10142: $resulttext = &mt('Changes made:').'<ul>';
10143: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 10144: my %lt = &selfcreation_types();
1.34 raeburn 10145: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10146: my $chgtext;
1.45 raeburn 10147: if ($type eq 'selfcreate') {
1.50 raeburn 10148: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 10149: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10150: } else {
1.160.6.34 raeburn 10151: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10152: '<ul>';
1.50 raeburn 10153: foreach my $case (@{$cancreate{$type}}) {
10154: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10155: }
10156: $chgtext .= '</ul>';
1.100 raeburn 10157: if (ref($cancreate{$type}) eq 'ARRAY') {
10158: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10159: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10160: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 10161: $chgtext .= '<br />'.
10162: '<span class="LC_warning">'.
10163: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10164: '</span>';
1.100 raeburn 10165: }
10166: }
10167: }
10168: }
1.43 raeburn 10169: }
1.160.6.44 raeburn 10170: } elsif ($type eq 'shibenv') {
10171: if (keys(%{$cancreate{$type}}) == 0) {
10172: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10173: } else {
10174: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10175: '<ul>';
10176: foreach my $field (@shibfields) {
10177: next if ($cancreate{$type}{$field} eq '');
10178: if ($field eq 'inststatus') {
10179: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10180: } else {
10181: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10182: }
10183: }
10184: $chgtext .= '</ul>';
10185: }
1.93 raeburn 10186: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10187: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10188: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10189: if (@{$cancreate{'selfcreate'}} > 0) {
10190: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10191: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10192: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10193: $chgtext .= '<br />'.
10194: '<span class="LC_warning">'.
10195: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10196: '</span>';
10197: }
1.96 raeburn 10198: } elsif (ref($usertypes) eq 'HASH') {
10199: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10200: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10201: } else {
10202: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10203: }
10204: $chgtext .= '<ul>';
10205: foreach my $case (@{$cancreate{$type}}) {
10206: if ($case eq 'default') {
10207: $chgtext .= '<li>'.$othertitle.'</li>';
10208: } else {
10209: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10210: }
10211: }
1.100 raeburn 10212: $chgtext .= '</ul>';
10213: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10214: $chgtext .= '<br /><span class="LC_warning">'.
10215: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10216: '</span>';
1.100 raeburn 10217: }
10218: }
10219: } else {
10220: if (@{$cancreate{$type}} == 0) {
10221: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10222: } else {
10223: $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 10224: }
10225: }
10226: }
1.160.6.40 raeburn 10227: } elsif ($type eq 'selfcreateprocessing') {
10228: my %choices = &Apache::lonlocal::texthash (
10229: automatic => 'Automatic approval',
10230: approval => 'Queued for approval',
10231: );
10232: if (@statuses > 1) {
10233: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10234: '<ul>';
10235: foreach my $type (@statuses) {
10236: if ($type eq 'default') {
10237: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10238: } else {
10239: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10240: }
10241: }
10242: $chgtext .= '</ul>';
10243: } else {
10244: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10245: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10246: }
1.160.6.5 raeburn 10247: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 10248: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 10249: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10250: } else {
10251: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 10252: if ($captchas{$savecaptcha{$type}}) {
10253: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 10254: } else {
10255: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
10256: }
10257: }
10258: } elsif ($type eq 'recaptchakeys') {
10259: my ($privkey,$pubkey);
1.160.6.34 raeburn 10260: if (ref($savecaptcha{$type}) eq 'HASH') {
10261: $pubkey = $savecaptcha{$type}{'public'};
10262: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 10263: }
10264: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10265: if (!$pubkey) {
10266: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10267: } else {
10268: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10269: }
10270: if (!$privkey) {
10271: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10272: } else {
10273: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10274: }
10275: $chgtext .= '</ul>';
1.160.6.69 raeburn 10276: } elsif ($type eq 'recaptchaversion') {
10277: if ($savecaptcha{'captcha'} eq 'recaptcha') {
10278: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
10279: }
1.160.6.34 raeburn 10280: } elsif ($type eq 'emailusername') {
10281: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 10282: if (ref($types) eq 'ARRAY') {
10283: foreach my $type (@{$types}) {
10284: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10285: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 10286: $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 10287: '<ul>';
10288: foreach my $field (@{$infofields}) {
10289: if ($cancreate{'emailusername'}{$type}{$field}) {
10290: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10291: }
10292: }
1.160.6.50 raeburn 10293: $chgtext .= '</ul>';
10294: } else {
10295: $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 10296: }
10297: } else {
1.160.6.50 raeburn 10298: $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 10299: }
10300: }
10301: }
10302: }
10303: } elsif ($type eq 'notify') {
10304: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10305: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10306: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10307: if ($cancreate{'notify'}{'approval'}) {
10308: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10309: }
10310: }
1.43 raeburn 10311: }
1.34 raeburn 10312: }
1.160.6.34 raeburn 10313: if ($chgtext) {
10314: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10315: }
10316: }
10317: }
1.43 raeburn 10318: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10319: my ($emailrules,$emailruleorder) =
10320: &Apache::lonnet::inst_userrules($dom,'email');
10321: my $chgtext = '<ul>';
10322: foreach my $type (@email_rule) {
10323: if (ref($emailrules->{$type}) eq 'HASH') {
10324: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10325: }
10326: }
10327: $chgtext .= '</ul>';
10328: if (@email_rule > 0) {
1.160.6.34 raeburn 10329: $resulttext .= '<li>'.
10330: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10331: $chgtext.
10332: '</li>';
1.43 raeburn 10333: } else {
1.160.6.34 raeburn 10334: $resulttext .= '<li>'.
10335: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10336: '</li>';
1.43 raeburn 10337: }
10338: }
1.160.6.34 raeburn 10339: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10340: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10341: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10342: foreach my $type (@{$changes{'selfcreate'}}) {
10343: my $typename = $type;
10344: if (ref($usertypes) eq 'HASH') {
10345: if ($usertypes->{$type} ne '') {
10346: $typename = $usertypes->{$type};
1.28 raeburn 10347: }
10348: }
1.160.6.34 raeburn 10349: my @modifiable;
10350: $resulttext .= '<li>'.
10351: &mt('Self-creation of account by users with status: [_1]',
10352: '<span class="LC_cusr_emph">'.$typename.'</span>').
10353: ' - '.&mt('modifiable fields (if institutional data blank): ');
10354: foreach my $field (@fields) {
10355: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10356: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
10357: }
10358: }
10359: if (@modifiable > 0) {
10360: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10361: } else {
1.160.6.34 raeburn 10362: $resulttext .= &mt('none');
1.43 raeburn 10363: }
1.160.6.34 raeburn 10364: $resulttext .= '</li>';
1.28 raeburn 10365: }
1.160.6.34 raeburn 10366: $resulttext .= '</ul></li>';
1.28 raeburn 10367: }
1.27 raeburn 10368: $resulttext .= '</ul>';
10369: } else {
1.160.6.34 raeburn 10370: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10371: }
10372: } else {
10373: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10374: &mt('An error occurred: [_1]',$putresult).'</span>';
10375: }
1.43 raeburn 10376: if ($warningmsg ne '') {
10377: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10378: }
1.23 raeburn 10379: return $resulttext;
10380: }
10381:
1.160.6.5 raeburn 10382: sub process_captcha {
10383: my ($container,$changes,$newsettings,$current) = @_;
10384: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10385: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10386: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10387: $newsettings->{'captcha'} = 'original';
10388: }
10389: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
10390: if ($container eq 'cancreate') {
10391: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10392: push(@{$changes->{'cancreate'}},'captcha');
10393: } elsif (!defined($changes->{'cancreate'})) {
10394: $changes->{'cancreate'} = ['captcha'];
10395: }
10396: } else {
10397: $changes->{'captcha'} = 1;
10398: }
10399: }
1.160.6.69 raeburn 10400: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 10401: if ($newsettings->{'captcha'} eq 'recaptcha') {
10402: $newpub = $env{'form.'.$container.'_recaptchapub'};
10403: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 10404: $newpub =~ s/[^\w\-]//g;
10405: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 10406: $newsettings->{'recaptchakeys'} = {
10407: public => $newpub,
10408: private => $newpriv,
10409: };
1.160.6.69 raeburn 10410: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10411: $newversion =~ s/\D//g;
10412: if ($newversion ne '2') {
10413: $newversion = 1;
10414: }
10415: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 10416: }
10417: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10418: $currpub = $current->{'recaptchakeys'}{'public'};
10419: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 10420: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10421: $newsettings->{'recaptchakeys'} = {
10422: public => '',
10423: private => '',
10424: }
10425: }
1.160.6.5 raeburn 10426: }
1.160.6.69 raeburn 10427: if ($current->{'captcha'} eq 'recaptcha') {
10428: $currversion = $current->{'recaptchaversion'};
10429: if ($currversion ne '2') {
10430: $currversion = 1;
10431: }
10432: }
10433: if ($currversion ne $newversion) {
10434: if ($container eq 'cancreate') {
10435: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10436: push(@{$changes->{'cancreate'}},'recaptchaversion');
10437: } elsif (!defined($changes->{'cancreate'})) {
10438: $changes->{'cancreate'} = ['recaptchaversion'];
10439: }
10440: } else {
10441: $changes->{'recaptchaversion'} = 1;
10442: }
10443: }
1.160.6.5 raeburn 10444: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
10445: if ($container eq 'cancreate') {
10446: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10447: push(@{$changes->{'cancreate'}},'recaptchakeys');
10448: } elsif (!defined($changes->{'cancreate'})) {
10449: $changes->{'cancreate'} = ['recaptchakeys'];
10450: }
10451: } else {
10452: $changes->{'recaptchakeys'} = 1;
10453: }
10454: }
10455: return;
10456: }
10457:
1.33 raeburn 10458: sub modify_usermodification {
10459: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 10460: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10461: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10462: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 10463: if ($key eq 'selfcreate') {
10464: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10465: } else {
10466: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10467: }
1.33 raeburn 10468: }
10469: }
1.160.6.34 raeburn 10470: my @contexts = ('author','course');
1.33 raeburn 10471: my %context_title = (
10472: author => 'In author context',
10473: course => 'In course context',
10474: );
10475: my @fields = ('lastname','firstname','middlename','generation',
10476: 'permanentemail','id');
10477: my %roles = (
10478: author => ['ca','aa'],
10479: course => ['st','ep','ta','in','cr'],
10480: );
10481: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10482: foreach my $context (@contexts) {
10483: foreach my $role (@{$roles{$context}}) {
10484: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10485: foreach my $item (@fields) {
10486: if (grep(/^\Q$item\E$/,@modifiable)) {
10487: $modifyhash{$context}{$role}{$item} = 1;
10488: } else {
10489: $modifyhash{$context}{$role}{$item} = 0;
10490: }
10491: }
10492: }
10493: if (ref($curr_usermodification{$context}) eq 'HASH') {
10494: foreach my $role (@{$roles{$context}}) {
10495: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10496: foreach my $field (@fields) {
10497: if ($modifyhash{$context}{$role}{$field} ne
10498: $curr_usermodification{$context}{$role}{$field}) {
10499: push(@{$changes{$context}},$role);
10500: last;
10501: }
10502: }
10503: }
10504: }
10505: } else {
10506: foreach my $context (@contexts) {
10507: foreach my $role (@{$roles{$context}}) {
10508: push(@{$changes{$context}},$role);
10509: }
10510: }
10511: }
10512: }
10513: my %usermodification_hash = (
10514: usermodification => \%modifyhash,
10515: );
10516: my $putresult = &Apache::lonnet::put_dom('configuration',
10517: \%usermodification_hash,$dom);
10518: if ($putresult eq 'ok') {
10519: if (keys(%changes) > 0) {
10520: $resulttext = &mt('Changes made: ').'<ul>';
10521: foreach my $context (@contexts) {
10522: if (ref($changes{$context}) eq 'ARRAY') {
10523: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10524: if (ref($changes{$context}) eq 'ARRAY') {
10525: foreach my $role (@{$changes{$context}}) {
10526: my $rolename;
1.160.6.34 raeburn 10527: if ($role eq 'cr') {
10528: $rolename = &mt('Custom');
1.33 raeburn 10529: } else {
1.160.6.34 raeburn 10530: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10531: }
10532: my @modifiable;
1.160.6.34 raeburn 10533: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10534: foreach my $field (@fields) {
10535: if ($modifyhash{$context}{$role}{$field}) {
10536: push(@modifiable,$fieldtitles{$field});
10537: }
10538: }
10539: if (@modifiable > 0) {
10540: $resulttext .= join(', ',@modifiable);
10541: } else {
10542: $resulttext .= &mt('none');
10543: }
10544: $resulttext .= '</li>';
10545: }
10546: $resulttext .= '</ul></li>';
10547: }
10548: }
10549: }
10550: $resulttext .= '</ul>';
10551: } else {
10552: $resulttext = &mt('No changes made to user modification settings');
10553: }
10554: } else {
10555: $resulttext = '<span class="LC_error">'.
10556: &mt('An error occurred: [_1]',$putresult).'</span>';
10557: }
10558: return $resulttext;
10559: }
10560:
1.43 raeburn 10561: sub modify_defaults {
1.160.6.27 raeburn 10562: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10563: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 10564: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80! raeburn 10565: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
! 10566: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 10567: my @authtypes = ('internal','krb4','krb5','localauth');
10568: foreach my $item (@items) {
10569: $newvalues{$item} = $env{'form.'.$item};
10570: if ($item eq 'auth_def') {
10571: if ($newvalues{$item} ne '') {
10572: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10573: push(@errors,$item);
10574: }
10575: }
10576: } elsif ($item eq 'lang_def') {
10577: if ($newvalues{$item} ne '') {
10578: if ($newvalues{$item} =~ /^(\w+)/) {
10579: my $langcode = $1;
1.103 raeburn 10580: if ($langcode ne 'x_chef') {
10581: if (code2language($langcode) eq '') {
10582: push(@errors,$item);
10583: }
1.43 raeburn 10584: }
10585: } else {
10586: push(@errors,$item);
10587: }
10588: }
1.54 raeburn 10589: } elsif ($item eq 'timezone_def') {
10590: if ($newvalues{$item} ne '') {
1.62 raeburn 10591: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10592: push(@errors,$item);
10593: }
10594: }
1.68 raeburn 10595: } elsif ($item eq 'datelocale_def') {
10596: if ($newvalues{$item} ne '') {
10597: my @datelocale_ids = DateTime::Locale->ids();
10598: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10599: push(@errors,$item);
10600: }
10601: }
1.141 raeburn 10602: } elsif ($item eq 'portal_def') {
10603: if ($newvalues{$item} ne '') {
10604: 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])\/?$/) {
10605: push(@errors,$item);
10606: }
10607: }
1.160.6.80! raeburn 10608: } elsif ($item eq 'intauth_cost') {
! 10609: if ($newvalues{$item} ne '') {
! 10610: if ($newvalues{$item} =~ /\D/) {
! 10611: push(@errors,$item);
! 10612: }
! 10613: }
! 10614: } elsif ($item eq 'intauth_check') {
! 10615: if ($newvalues{$item} ne '') {
! 10616: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
! 10617: push(@errors,$item);
! 10618: }
! 10619: }
! 10620: } elsif ($item eq 'intauth_switch') {
! 10621: if ($newvalues{$item} ne '') {
! 10622: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
! 10623: push(@errors,$item);
! 10624: }
! 10625: }
1.43 raeburn 10626: }
10627: if (grep(/^\Q$item\E$/,@errors)) {
10628: $newvalues{$item} = $domdefaults{$item};
10629: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10630: $changes{$item} = 1;
10631: }
1.72 raeburn 10632: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10633: }
10634: my %defaults_hash = (
1.72 raeburn 10635: defaults => \%newvalues,
10636: );
1.43 raeburn 10637: my $title = &defaults_titles();
1.160.6.40 raeburn 10638:
10639: my $currinststatus;
10640: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10641: $currinststatus = $domconfig{'inststatus'};
10642: } else {
10643: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10644: $currinststatus = {
10645: inststatustypes => $usertypes,
10646: inststatusorder => $types,
10647: inststatusguest => [],
10648: };
10649: }
10650: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10651: my @allpos;
10652: my %guests;
10653: my %alltypes;
10654: my ($currtitles,$currguests,$currorder);
10655: if (ref($currinststatus) eq 'HASH') {
10656: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10657: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10658: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10659: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10660: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10661: }
10662: }
10663: unless (grep(/^\Q$type\E$/,@todelete)) {
10664: my $position = $env{'form.inststatus_pos_'.$type};
10665: $position =~ s/\D+//g;
10666: $allpos[$position] = $type;
10667: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
10668: $alltypes{$type} =~ s/`//g;
10669: if ($env{'form.inststatus_guest_'.$type}) {
10670: $guests{$type} = 1;
10671: }
10672: }
10673: }
10674: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
10675: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
10676: }
10677: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
10678: $currtitles =~ s/,$//;
10679: }
10680: }
10681: if ($env{'form.addinststatus'}) {
10682: my $newtype = $env{'form.addinststatus'};
10683: $newtype =~ s/\W//g;
10684: unless (exists($alltypes{$newtype})) {
10685: if ($env{'form.addinststatus_guest'}) {
10686: $guests{$newtype} = 1;
10687: }
10688: $alltypes{$newtype} = $env{'form.addinststatus_title'};
10689: $alltypes{$newtype} =~ s/`//g;
10690: my $position = $env{'form.addinststatus_pos'};
10691: $position =~ s/\D+//g;
10692: if ($position ne '') {
10693: $allpos[$position] = $newtype;
10694: }
10695: }
10696: }
10697: my (@orderedstatus,@orderedguests);
10698: foreach my $type (@allpos) {
10699: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
10700: push(@orderedstatus,$type);
10701: if ($guests{$type}) {
10702: push(@orderedguests,$type);
10703: }
10704: }
10705: }
10706: foreach my $type (keys(%alltypes)) {
10707: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
10708: delete($alltypes{$type});
10709: }
10710: }
10711: $defaults_hash{'inststatus'} = {
10712: inststatustypes => \%alltypes,
10713: inststatusorder => \@orderedstatus,
10714: inststatusguest => \@orderedguests,
10715: };
10716: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
10717: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
10718: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
10719: }
10720: }
10721: if ($currorder ne join(',',@orderedstatus)) {
10722: $changes{'inststatus'}{'inststatusorder'} = 1;
10723: }
10724: if ($currguests ne join(',',@orderedguests)) {
10725: $changes{'inststatus'}{'inststatusguest'} = 1;
10726: }
10727: my $newtitles;
10728: foreach my $item (@orderedstatus) {
10729: $newtitles .= $alltypes{$item}.',';
10730: }
10731: $newtitles =~ s/,$//;
10732: if ($currtitles ne $newtitles) {
10733: $changes{'inststatus'}{'inststatustypes'} = 1;
10734: }
1.43 raeburn 10735: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
10736: $dom);
10737: if ($putresult eq 'ok') {
10738: if (keys(%changes) > 0) {
10739: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 10740: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 10741: 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";
10742: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 10743: if ($item eq 'inststatus') {
10744: if (ref($changes{'inststatus'}) eq 'HASH') {
10745: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
10746: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
10747: foreach my $type (@orderedstatus) {
10748: $resulttext .= $alltypes{$type}.', ';
10749: }
10750: $resulttext =~ s/, $//;
10751: $resulttext .= '</li>';
10752: }
10753: if ($changes{'inststatus'}{'inststatusguest'}) {
10754: $resulttext .= '<li>';
10755: if (@orderedguests) {
10756: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
10757: foreach my $type (@orderedguests) {
10758: $resulttext .= $alltypes{$type}.', ';
10759: }
10760: $resulttext =~ s/, $//;
10761: } else {
10762: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
10763: }
10764: $resulttext .= '</li>';
10765: }
10766: }
10767: } else {
10768: my $value = $env{'form.'.$item};
10769: if ($value eq '') {
10770: $value = &mt('none');
10771: } elsif ($item eq 'auth_def') {
10772: my %authnames = &authtype_names();
10773: my %shortauth = (
10774: internal => 'int',
10775: krb4 => 'krb4',
10776: krb5 => 'krb5',
10777: localauth => 'loc',
10778: );
10779: $value = $authnames{$shortauth{$value}};
1.160.6.80! raeburn 10780: } elsif ($item eq 'intauth_switch') {
! 10781: my %optiondesc = &Apache::lonlocal::texthash (
! 10782: 0 => 'No',
! 10783: 1 => 'Yes',
! 10784: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
! 10785: );
! 10786: if ($value =~ /^(0|1|2)$/) {
! 10787: $value = $optiondesc{$value};
! 10788: } else {
! 10789: $value = &mt('none -- defaults to No');
! 10790: }
! 10791: } elsif ($item eq 'intauth_check') {
! 10792: my %optiondesc = &Apache::lonlocal::texthash (
! 10793: 0 => 'No',
! 10794: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
! 10795: 2 => 'Yes, disallow login if stored cost is less than domain default',
! 10796: );
! 10797: if ($value =~ /^(0|1|2)$/) {
! 10798: $value = $optiondesc{$value};
! 10799: } else {
! 10800: $value = &mt('none -- defaults to No');
! 10801: }
1.160.6.40 raeburn 10802: }
10803: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
10804: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 10805: }
10806: }
10807: $resulttext .= '</ul>';
10808: $mailmsgtext .= "\n";
10809: my $cachetime = 24*60*60;
1.72 raeburn 10810: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10811: if (ref($lastactref) eq 'HASH') {
10812: $lastactref->{'domdefaults'} = 1;
10813: }
1.68 raeburn 10814: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 10815: my $notify = 1;
10816: if (ref($domconfig{'contacts'}) eq 'HASH') {
10817: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
10818: $notify = 0;
10819: }
10820: }
10821: if ($notify) {
10822: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
10823: "LON-CAPA Domain Settings Change - $dom",
10824: $mailmsgtext);
10825: }
1.54 raeburn 10826: }
1.43 raeburn 10827: } else {
1.54 raeburn 10828: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 10829: }
10830: } else {
10831: $resulttext = '<span class="LC_error">'.
10832: &mt('An error occurred: [_1]',$putresult).'</span>';
10833: }
10834: if (@errors > 0) {
10835: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
10836: foreach my $item (@errors) {
10837: $resulttext .= ' "'.$title->{$item}.'",';
10838: }
10839: $resulttext =~ s/,$//;
10840: }
10841: return $resulttext;
10842: }
10843:
1.46 raeburn 10844: sub modify_scantron {
1.160.6.24 raeburn 10845: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 10846: my ($resulttext,%confhash,%changes,$errors);
10847: my $custom = 'custom.tab';
10848: my $default = 'default.tab';
10849: my $servadm = $r->dir_config('lonAdmEMail');
10850: my ($configuserok,$author_ok,$switchserver) =
10851: &config_check($dom,$confname,$servadm);
10852: if ($env{'form.scantronformat.filename'} ne '') {
10853: my $error;
10854: if ($configuserok eq 'ok') {
10855: if ($switchserver) {
1.130 raeburn 10856: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 10857: } else {
10858: if ($author_ok eq 'ok') {
10859: my ($result,$scantronurl) =
10860: &publishlogo($r,'upload','scantronformat',$dom,
10861: $confname,'scantron','','',$custom);
10862: if ($result eq 'ok') {
10863: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 10864: $changes{'scantronformat'} = 1;
1.46 raeburn 10865: } else {
10866: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
10867: }
10868: } else {
10869: $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);
10870: }
10871: }
10872: } else {
10873: $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);
10874: }
10875: if ($error) {
10876: &Apache::lonnet::logthis($error);
10877: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10878: }
10879: }
1.48 raeburn 10880: if (ref($domconfig{'scantron'}) eq 'HASH') {
10881: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
10882: if ($env{'form.scantronformat_del'}) {
10883: $confhash{'scantron'}{'scantronformat'} = '';
10884: $changes{'scantronformat'} = 1;
1.46 raeburn 10885: }
10886: }
10887: }
10888: if (keys(%confhash) > 0) {
10889: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10890: $dom);
10891: if ($putresult eq 'ok') {
10892: if (keys(%changes) > 0) {
1.48 raeburn 10893: if (ref($confhash{'scantron'}) eq 'HASH') {
10894: $resulttext = &mt('Changes made:').'<ul>';
10895: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 10896: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 10897: } else {
1.130 raeburn 10898: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 10899: }
1.48 raeburn 10900: $resulttext .= '</ul>';
10901: } else {
1.130 raeburn 10902: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 10903: }
10904: $resulttext .= '</ul>';
10905: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10906: if (ref($lastactref) eq 'HASH') {
10907: $lastactref->{'domainconfig'} = 1;
10908: }
1.46 raeburn 10909: } else {
1.130 raeburn 10910: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10911: }
10912: } else {
10913: $resulttext = '<span class="LC_error">'.
10914: &mt('An error occurred: [_1]',$putresult).'</span>';
10915: }
10916: } else {
1.130 raeburn 10917: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10918: }
10919: if ($errors) {
10920: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10921: $errors.'</ul>';
10922: }
10923: return $resulttext;
10924: }
10925:
1.48 raeburn 10926: sub modify_coursecategories {
1.160.6.43 raeburn 10927: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 10928: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10929: $cathash);
1.48 raeburn 10930: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 10931: my @catitems = ('unauth','auth');
10932: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 10933: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 10934: $cathash = $domconfig{'coursecategories'}{'cats'};
10935: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10936: $changes{'togglecats'} = 1;
10937: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10938: }
10939: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10940: $changes{'categorize'} = 1;
10941: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
10942: }
1.120 raeburn 10943: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
10944: $changes{'togglecatscomm'} = 1;
10945: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
10946: }
10947: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
10948: $changes{'categorizecomm'} = 1;
10949: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
10950: }
1.160.6.42 raeburn 10951: foreach my $item (@catitems) {
10952: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10953: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
10954: $changes{$item} = 1;
10955: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10956: }
10957: }
10958: }
1.57 raeburn 10959: } else {
10960: $changes{'togglecats'} = 1;
10961: $changes{'categorize'} = 1;
1.124 raeburn 10962: $changes{'togglecatscomm'} = 1;
10963: $changes{'categorizecomm'} = 1;
1.87 raeburn 10964: $domconfig{'coursecategories'} = {
10965: togglecats => $env{'form.togglecats'},
10966: categorize => $env{'form.categorize'},
1.124 raeburn 10967: togglecatscomm => $env{'form.togglecatscomm'},
10968: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 10969: };
1.160.6.42 raeburn 10970: foreach my $item (@catitems) {
10971: if ($env{'form.coursecat_'.$item} ne 'std') {
10972: $changes{$item} = 1;
10973: }
10974: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10975: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10976: }
10977: }
1.57 raeburn 10978: }
10979: if (ref($cathash) eq 'HASH') {
10980: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 10981: push (@deletecategory,'instcode::0');
10982: }
1.120 raeburn 10983: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
10984: push(@deletecategory,'communities::0');
10985: }
1.48 raeburn 10986: }
1.57 raeburn 10987: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
10988: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10989: if (@deletecategory > 0) {
10990: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 10991: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 10992: foreach my $item (@deletecategory) {
1.57 raeburn 10993: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
10994: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 10995: $deletions{$item} = 1;
1.57 raeburn 10996: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 10997: }
10998: }
10999: }
1.57 raeburn 11000: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11001: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11002: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11003: $reorderings{$item} = 1;
1.57 raeburn 11004: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11005: }
11006: if ($env{'form.addcategory_name_'.$item} ne '') {
11007: my $newcat = $env{'form.addcategory_name_'.$item};
11008: my $newdepth = $depth+1;
11009: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11010: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11011: $adds{$newitem} = 1;
11012: }
11013: if ($env{'form.subcat_'.$item} ne '') {
11014: my $newcat = $env{'form.subcat_'.$item};
11015: my $newdepth = $depth+1;
11016: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11017: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11018: $adds{$newitem} = 1;
11019: }
11020: }
11021: }
11022: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11023: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11024: my $newitem = 'instcode::0';
1.57 raeburn 11025: if ($cathash->{$newitem} eq '') {
11026: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11027: $adds{$newitem} = 1;
11028: }
11029: } else {
11030: my $newitem = 'instcode::0';
1.57 raeburn 11031: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11032: $adds{$newitem} = 1;
11033: }
11034: }
1.120 raeburn 11035: if ($env{'form.communities'} eq '1') {
11036: if (ref($cathash) eq 'HASH') {
11037: my $newitem = 'communities::0';
11038: if ($cathash->{$newitem} eq '') {
11039: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11040: $adds{$newitem} = 1;
11041: }
11042: } else {
11043: my $newitem = 'communities::0';
11044: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11045: $adds{$newitem} = 1;
11046: }
11047: }
1.48 raeburn 11048: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11049: if (($env{'form.addcategory_name'} ne 'instcode') &&
11050: ($env{'form.addcategory_name'} ne 'communities')) {
11051: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11052: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11053: $adds{$newitem} = 1;
11054: }
1.48 raeburn 11055: }
1.57 raeburn 11056: my $putresult;
1.48 raeburn 11057: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11058: if (keys(%deletions) > 0) {
11059: foreach my $key (keys(%deletions)) {
11060: if ($predelallitems{$key} ne '') {
11061: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11062: }
11063: }
11064: }
11065: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11066: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11067: if (ref($chkcats[0]) eq 'ARRAY') {
11068: my $depth = 0;
11069: my $chg = 0;
11070: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11071: my $name = $chkcats[0][$i];
11072: my $item;
11073: if ($name eq '') {
11074: $chg ++;
11075: } else {
11076: $item = &escape($name).'::0';
11077: if ($chg) {
1.57 raeburn 11078: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11079: }
11080: $depth ++;
1.57 raeburn 11081: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11082: $depth --;
11083: }
11084: }
11085: }
1.57 raeburn 11086: }
11087: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11088: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11089: if ($putresult eq 'ok') {
1.57 raeburn 11090: my %title = (
1.120 raeburn 11091: togglecats => 'Show/Hide a course in catalog',
11092: categorize => 'Assign a category to a course',
11093: togglecatscomm => 'Show/Hide a community in catalog',
11094: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11095: );
11096: my %level = (
1.120 raeburn 11097: dom => 'set in Domain ("Modify Course/Community")',
11098: crs => 'set in Course ("Course Configuration")',
11099: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 11100: none => 'No catalog',
11101: std => 'Standard catalog',
11102: domonly => 'Domain-only catalog',
11103: codesrch => 'Code search form',
1.57 raeburn 11104: );
1.48 raeburn 11105: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11106: if ($changes{'togglecats'}) {
11107: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11108: }
11109: if ($changes{'categorize'}) {
11110: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11111: }
1.120 raeburn 11112: if ($changes{'togglecatscomm'}) {
11113: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11114: }
11115: if ($changes{'categorizecomm'}) {
11116: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11117: }
1.160.6.42 raeburn 11118: if ($changes{'unauth'}) {
11119: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11120: }
11121: if ($changes{'auth'}) {
11122: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11123: }
1.57 raeburn 11124: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11125: my $cathash;
11126: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11127: $cathash = $domconfig{'coursecategories'}{'cats'};
11128: } else {
11129: $cathash = {};
11130: }
11131: my (@cats,@trails,%allitems);
11132: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11133: if (keys(%deletions) > 0) {
11134: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11135: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11136: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11137: }
11138: $resulttext .= '</ul></li>';
11139: }
11140: if (keys(%reorderings) > 0) {
11141: my %sort_by_trail;
11142: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11143: foreach my $key (keys(%reorderings)) {
11144: if ($allitems{$key} ne '') {
11145: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11146: }
1.48 raeburn 11147: }
1.57 raeburn 11148: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11149: $resulttext .= '<li>'.$trails[$trail].'</li>';
11150: }
11151: $resulttext .= '</ul></li>';
1.48 raeburn 11152: }
1.57 raeburn 11153: if (keys(%adds) > 0) {
11154: my %sort_by_trail;
11155: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11156: foreach my $key (keys(%adds)) {
11157: if ($allitems{$key} ne '') {
11158: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11159: }
11160: }
11161: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11162: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11163: }
1.57 raeburn 11164: $resulttext .= '</ul></li>';
1.48 raeburn 11165: }
11166: }
11167: $resulttext .= '</ul>';
1.160.6.43 raeburn 11168: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 11169: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11170: if ($changes{'auth'}) {
11171: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11172: }
11173: if ($changes{'unauth'}) {
11174: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11175: }
11176: my $cachetime = 24*60*60;
11177: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 11178: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 11179: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 11180: }
11181: }
1.48 raeburn 11182: } else {
11183: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11184: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11185: }
11186: } else {
1.120 raeburn 11187: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11188: }
11189: return $resulttext;
11190: }
11191:
1.69 raeburn 11192: sub modify_serverstatuses {
11193: my ($dom,%domconfig) = @_;
11194: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11195: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11196: %currserverstatus = %{$domconfig{'serverstatuses'}};
11197: }
11198: my @pages = &serverstatus_pages();
11199: foreach my $type (@pages) {
11200: $newserverstatus{$type}{'namedusers'} = '';
11201: $newserverstatus{$type}{'machines'} = '';
11202: if (defined($env{'form.'.$type.'_namedusers'})) {
11203: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11204: my @okusers;
11205: foreach my $user (@users) {
11206: my ($uname,$udom) = split(/:/,$user);
11207: if (($udom =~ /^$match_domain$/) &&
11208: (&Apache::lonnet::domain($udom)) &&
11209: ($uname =~ /^$match_username$/)) {
11210: if (!grep(/^\Q$user\E/,@okusers)) {
11211: push(@okusers,$user);
11212: }
11213: }
11214: }
11215: if (@okusers > 0) {
11216: @okusers = sort(@okusers);
11217: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11218: }
11219: }
11220: if (defined($env{'form.'.$type.'_machines'})) {
11221: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11222: my @okmachines;
11223: foreach my $ip (@machines) {
11224: my @parts = split(/\./,$ip);
11225: next if (@parts < 4);
11226: my $badip = 0;
11227: for (my $i=0; $i<4; $i++) {
11228: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11229: $badip = 1;
11230: last;
11231: }
11232: }
11233: if (!$badip) {
11234: push(@okmachines,$ip);
11235: }
11236: }
11237: @okmachines = sort(@okmachines);
11238: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11239: }
11240: }
11241: my %serverstatushash = (
11242: serverstatuses => \%newserverstatus,
11243: );
11244: foreach my $type (@pages) {
1.83 raeburn 11245: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11246: my (@current,@new);
1.83 raeburn 11247: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11248: if ($currserverstatus{$type}{$setting} ne '') {
11249: @current = split(/,/,$currserverstatus{$type}{$setting});
11250: }
11251: }
11252: if ($newserverstatus{$type}{$setting} ne '') {
11253: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11254: }
11255: if (@current > 0) {
11256: if (@new > 0) {
11257: foreach my $item (@current) {
11258: if (!grep(/^\Q$item\E$/,@new)) {
11259: $changes{$type}{$setting} = 1;
1.82 raeburn 11260: last;
11261: }
11262: }
1.84 raeburn 11263: foreach my $item (@new) {
11264: if (!grep(/^\Q$item\E$/,@current)) {
11265: $changes{$type}{$setting} = 1;
11266: last;
1.82 raeburn 11267: }
11268: }
11269: } else {
1.83 raeburn 11270: $changes{$type}{$setting} = 1;
1.69 raeburn 11271: }
1.83 raeburn 11272: } elsif (@new > 0) {
11273: $changes{$type}{$setting} = 1;
1.69 raeburn 11274: }
11275: }
11276: }
11277: if (keys(%changes) > 0) {
1.81 raeburn 11278: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11279: my $putresult = &Apache::lonnet::put_dom('configuration',
11280: \%serverstatushash,$dom);
11281: if ($putresult eq 'ok') {
11282: $resulttext .= &mt('Changes made:').'<ul>';
11283: foreach my $type (@pages) {
1.84 raeburn 11284: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11285: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11286: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11287: if ($newserverstatus{$type}{'namedusers'} eq '') {
11288: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11289: } else {
11290: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11291: }
1.84 raeburn 11292: }
11293: if ($changes{$type}{'machines'}) {
1.69 raeburn 11294: if ($newserverstatus{$type}{'machines'} eq '') {
11295: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11296: } else {
11297: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11298: }
11299:
11300: }
11301: $resulttext .= '</ul></li>';
11302: }
11303: }
11304: $resulttext .= '</ul>';
11305: } else {
11306: $resulttext = '<span class="LC_error">'.
11307: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11308:
11309: }
11310: } else {
11311: $resulttext = &mt('No changes made to access to server status pages');
11312: }
11313: return $resulttext;
11314: }
11315:
1.118 jms 11316: sub modify_helpsettings {
1.160.6.77 raeburn 11317: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 11318: my ($resulttext,$errors,%changes,%helphash);
11319: my %defaultchecked = ('submitbugs' => 'on');
11320: my @offon = ('off','on');
1.118 jms 11321: my @toggles = ('submitbugs');
1.160.6.77 raeburn 11322: my %current = ('submitbugs' => '',
11323: 'adhoc' => {},
11324: );
1.118 jms 11325: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 11326: %current = %{$domconfig{'helpsettings'}};
11327: }
1.160.6.77 raeburn 11328: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 11329: foreach my $item (@toggles) {
11330: if ($defaultchecked{$item} eq 'on') {
11331: if ($current{$item} eq '') {
11332: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 11333: $changes{$item} = 1;
11334: }
1.160.6.73 raeburn 11335: } elsif ($current{$item} ne $env{'form.'.$item}) {
11336: $changes{$item} = 1;
11337: }
11338: } elsif ($defaultchecked{$item} eq 'off') {
11339: if ($current{$item} eq '') {
11340: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 11341: $changes{$item} = 1;
11342: }
1.160.6.73 raeburn 11343: } elsif ($current{$item} ne $env{'form.'.$item}) {
11344: $changes{$item} = 1;
11345: }
11346: }
11347: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
11348: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11349: }
11350: }
1.160.6.77 raeburn 11351: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 11352: my $confname = $dom.'-domainconfig';
11353: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 11354: my (@allpos,%newsettings,%changedprivs,$newrole);
11355: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 11356: my @accesstypes = ('all','dh','da','none','status','inc','exc');
11357: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 11358: my %lt = &Apache::lonlocal::texthash(
11359: s => 'system',
11360: d => 'domain',
11361: order => 'Display order',
11362: access => 'Role usage',
1.160.6.79 raeburn 11363: all => 'All with domain helpdesk or helpdesk assistant role',
11364: dh => 'All with domain helpdesk role',
11365: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 11366: none => 'None',
11367: status => 'Determined based on institutional status',
11368: inc => 'Include all, but exclude specific personnel',
11369: exc => 'Exclude all, but include specific personnel',
11370: );
11371: for (my $num=0; $num<=$maxnum; $num++) {
11372: my ($prefix,$identifier,$rolename,%curr);
11373: if ($num == $maxnum) {
11374: next unless ($env{'form.newcusthelp'} == $maxnum);
11375: $identifier = 'custhelp'.$num;
11376: $prefix = 'helproles_'.$num;
11377: $rolename = $env{'form.custhelpname'.$num};
11378: $rolename=~s/[^A-Za-z0-9]//gs;
11379: next if ($rolename eq '');
11380: next if (exists($existing{'rolesdef_'.$rolename}));
11381: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11382: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11383: $newprivs{'c'},$confname,$dom);
11384: if ($result ne 'ok') {
11385: $errors .= '<li><span class="LC_error">'.
11386: &mt('An error occurred storing the new custom role: [_1]',
11387: $result).'</span></li>';
11388: next;
11389: } else {
11390: $changedprivs{$rolename} = \%newprivs;
11391: $newrole = $rolename;
11392: }
11393: } else {
11394: $prefix = 'helproles_'.$num;
11395: $rolename = $env{'form.'.$prefix};
11396: next if ($rolename eq '');
11397: next unless (exists($existing{'rolesdef_'.$rolename}));
11398: $identifier = 'custhelp'.$num;
11399: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11400: my %currprivs;
11401: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
11402: split(/\_/,$existing{'rolesdef_'.$rolename});
11403: foreach my $level ('c','d','s') {
11404: if ($newprivs{$level} ne $currprivs{$level}) {
11405: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11406: $newprivs{'c'},$confname,$dom);
11407: if ($result ne 'ok') {
11408: $errors .= '<li><span class="LC_error">'.
11409: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
11410: $rolename,$result).'</span></li>';
11411: } else {
11412: $changedprivs{$rolename} = \%newprivs;
11413: }
11414: last;
11415: }
11416: }
11417: if (ref($current{'adhoc'}) eq 'HASH') {
11418: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11419: %curr = %{$current{'adhoc'}{$rolename}};
11420: }
11421: }
11422: }
11423: my $newpos = $env{'form.'.$prefix.'_pos'};
11424: $newpos =~ s/\D+//g;
11425: $allpos[$newpos] = $rolename;
11426: my $newdesc = $env{'form.'.$prefix.'_desc'};
11427: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
11428: if ($curr{'desc'}) {
11429: if ($curr{'desc'} ne $newdesc) {
11430: $changes{'customrole'}{$rolename}{'desc'} = 1;
11431: $newsettings{$rolename}{'desc'} = $newdesc;
11432: }
11433: } elsif ($newdesc ne '') {
11434: $changes{'customrole'}{$rolename}{'desc'} = 1;
11435: $newsettings{$rolename}{'desc'} = $newdesc;
11436: }
11437: my $access = $env{'form.'.$prefix.'_access'};
11438: if (grep(/^\Q$access\E$/,@accesstypes)) {
11439: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
11440: if ($access eq 'status') {
11441: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
11442: if (scalar(@statuses) == 0) {
11443: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
11444: } else {
11445: my (@shownstatus,$numtypes);
11446: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11447: if (ref($types) eq 'ARRAY') {
11448: $numtypes = scalar(@{$types});
11449: foreach my $type (sort(@statuses)) {
11450: if ($type eq 'default') {
11451: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11452: } elsif (grep(/^\Q$type\E$/,@{$types})) {
11453: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11454: push(@shownstatus,$usertypes->{$type});
11455: }
1.160.6.73 raeburn 11456: }
11457: }
1.160.6.77 raeburn 11458: if (grep(/^default$/,@statuses)) {
11459: push(@shownstatus,$othertitle);
11460: }
11461: if (scalar(@shownstatus) == 1+$numtypes) {
11462: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
11463: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
11464: } else {
11465: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
11466: if (ref($curr{'status'}) eq 'ARRAY') {
11467: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11468: if (@diffs) {
11469: $changes{'customrole'}{$rolename}{$access} = 1;
11470: }
11471: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11472: $changes{'customrole'}{$rolename}{$access} = 1;
11473: }
11474: }
11475: }
11476: } elsif (($access eq 'inc') || ($access eq 'exc')) {
11477: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
11478: my @newspecstaff;
11479: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11480: foreach my $person (sort(@personnel)) {
11481: if ($domhelpdesk{$person}) {
11482: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
11483: }
11484: }
11485: if (ref($curr{$access}) eq 'ARRAY') {
11486: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11487: if (@diffs) {
11488: $changes{'customrole'}{$rolename}{$access} = 1;
11489: }
11490: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11491: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 11492: }
1.160.6.77 raeburn 11493: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11494: my ($uname,$udom) = split(/:/,$person);
11495: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
11496: }
11497: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 11498: }
1.160.6.77 raeburn 11499: } else {
11500: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
11501: }
11502: unless ($curr{'access'} eq $access) {
11503: $changes{'customrole'}{$rolename}{'access'} = 1;
11504: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 11505: }
11506: }
1.160.6.77 raeburn 11507: if (@allpos > 0) {
11508: my $idx = 0;
11509: foreach my $rolename (@allpos) {
11510: if ($rolename ne '') {
11511: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
11512: if (ref($current{'adhoc'}) eq 'HASH') {
11513: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11514: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
11515: $changes{'customrole'}{$rolename}{'order'} = 1;
11516: $newsettings{$rolename}{'order'} = $idx+1;
11517: }
11518: }
1.160.6.73 raeburn 11519: }
1.160.6.77 raeburn 11520: $idx ++;
1.122 jms 11521: }
11522: }
1.118 jms 11523: }
1.123 jms 11524: my $putresult;
11525: if (keys(%changes) > 0) {
1.160.6.5 raeburn 11526: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
11527: if ($putresult eq 'ok') {
1.160.6.77 raeburn 11528: if (ref($helphash{'helpsettings'}) eq 'HASH') {
11529: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
11530: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
11531: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
11532: }
11533: }
11534: my $cachetime = 24*60*60;
11535: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11536: if (ref($lastactref) eq 'HASH') {
11537: $lastactref->{'domdefaults'} = 1;
11538: }
11539: } else {
11540: $errors .= '<li><span class="LC_error">'.
11541: &mt('An error occurred storing the settings: [_1]',
11542: $putresult).'</span></li>';
11543: }
11544: }
11545: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
11546: $resulttext = &mt('Changes made:').'<ul>';
11547: my (%shownprivs,@levelorder);
11548: @levelorder = ('c','d','s');
11549: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 11550: foreach my $item (sort(keys(%changes))) {
11551: if ($item eq 'submitbugs') {
11552: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11553: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11554: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 11555: } elsif ($item eq 'customrole') {
11556: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 11557: my @keyorder = ('order','desc','access','status','exc','inc');
11558: my %keytext = &Apache::lonlocal::texthash(
11559: order => 'Order',
11560: desc => 'Role description',
11561: access => 'Role usage',
11562: status => 'Allowed instituional types',
11563: exc => 'Allowed personnel',
11564: inc => 'Disallowed personnel',
11565: );
1.160.6.73 raeburn 11566: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 11567: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
11568: if ($role eq $newrole) {
11569: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
11570: $role).'<ul>';
11571: } else {
11572: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11573: $role).'<ul>';
11574: }
11575: foreach my $key (@keyorder) {
11576: if ($changes{'customrole'}{$role}{$key}) {
11577: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
11578: $keytext{$key},$newsettings{$role}{$key}).
11579: '</li>';
11580: }
11581: }
11582: if (ref($changedprivs{$role}) eq 'HASH') {
11583: $shownprivs{$role} = 1;
11584: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
11585: foreach my $level (@levelorder) {
11586: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11587: next if ($item eq '');
11588: my ($priv) = split(/\&/,$item,2);
11589: if (&Apache::lonnet::plaintext($priv)) {
11590: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11591: unless ($level eq 'c') {
11592: $resulttext .= ' ('.$lt{$level}.')';
11593: }
11594: $resulttext .= '</li>';
11595: }
11596: }
11597: }
11598: $resulttext .= '</ul>';
11599: }
11600: $resulttext .= '</ul></li>';
11601: }
1.160.6.73 raeburn 11602: }
11603: }
1.160.6.5 raeburn 11604: }
11605: }
11606: }
1.160.6.77 raeburn 11607: if (keys(%changedprivs)) {
11608: foreach my $role (sort(keys(%changedprivs))) {
11609: unless ($shownprivs{$role}) {
11610: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11611: $role).'<ul>'.
11612: '<li>'.&mt('Privileges set to :').'<ul>';
11613: foreach my $level (@levelorder) {
11614: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11615: next if ($item eq '');
11616: my ($priv) = split(/\&/,$item,2);
11617: if (&Apache::lonnet::plaintext($priv)) {
11618: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11619: unless ($level eq 'c') {
11620: $resulttext .= ' ('.$lt{$level}.')';
11621: }
11622: $resulttext .= '</li>';
11623: }
11624: }
11625: }
11626: $resulttext .= '</ul></li></ul></li>';
11627: }
11628: }
11629: }
11630: $resulttext .= '</ul>';
11631: } else {
11632: $resulttext = &mt('No changes made to help settings');
1.118 jms 11633: }
11634: if ($errors) {
1.160.6.5 raeburn 11635: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 11636: $errors.'</ul>';
1.118 jms 11637: }
11638: return $resulttext;
11639: }
11640:
1.121 raeburn 11641: sub modify_coursedefaults {
1.160.6.27 raeburn 11642: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11643: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 11644: my %defaultchecked = (
11645: 'uselcmath' => 'on',
11646: 'usejsme' => 'on'
11647: );
11648: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 11649: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 11650: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
11651: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 11652: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 11653: my %staticdefaults = (
11654: anonsurvey_threshold => 10,
11655: uploadquota => 500,
1.160.6.57 raeburn 11656: postsubmit => 60,
1.160.6.70 raeburn 11657: mysqltables => 172800,
1.160.6.21 raeburn 11658: );
1.121 raeburn 11659:
11660: $defaultshash{'coursedefaults'} = {};
11661:
11662: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11663: if ($domconfig{'coursedefaults'} eq '') {
11664: $domconfig{'coursedefaults'} = {};
11665: }
11666: }
11667:
11668: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11669: foreach my $item (@toggles) {
11670: if ($defaultchecked{$item} eq 'on') {
11671: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11672: ($env{'form.'.$item} eq '0')) {
11673: $changes{$item} = 1;
1.160.6.16 raeburn 11674: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11675: $changes{$item} = 1;
11676: }
11677: } elsif ($defaultchecked{$item} eq 'off') {
11678: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11679: ($env{'form.'.$item} eq '1')) {
11680: $changes{$item} = 1;
11681: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11682: $changes{$item} = 1;
11683: }
11684: }
11685: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11686: }
1.160.6.21 raeburn 11687: foreach my $item (@numbers) {
11688: my ($currdef,$newdef);
1.160.6.26 raeburn 11689: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 11690: if ($item eq 'anonsurvey_threshold') {
11691: $currdef = $domconfig{'coursedefaults'}{$item};
11692: $newdef =~ s/\D//g;
11693: if ($newdef eq '' || $newdef < 1) {
11694: $newdef = 1;
11695: }
11696: $defaultshash{'coursedefaults'}{$item} = $newdef;
11697: } else {
1.160.6.70 raeburn 11698: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
11699: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
11700: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 11701: }
11702: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 11703: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 11704: }
11705: if ($currdef ne $newdef) {
11706: my $staticdef;
11707: if ($item eq 'anonsurvey_threshold') {
11708: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11709: $changes{$item} = 1;
11710: }
1.160.6.70 raeburn 11711: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
11712: my $setting = $1;
11713: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
11714: $changes{$setting} = 1;
1.160.6.21 raeburn 11715: }
11716: }
1.139 raeburn 11717: }
11718: }
1.160.6.64 raeburn 11719: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11720: my @currclonecode;
11721: if (ref($currclone) eq 'HASH') {
11722: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11723: @currclonecode = @{$currclone->{'instcode'}};
11724: }
11725: }
11726: my $newclone;
11727: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11728: $newclone = $env{'form.canclone'};
11729: }
11730: if ($newclone eq 'instcode') {
11731: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11732: my (%codedefaults,@code_order,@clonecode);
11733: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11734: \@code_order);
11735: foreach my $item (@code_order) {
11736: if (grep(/^\Q$item\E$/,@newcodes)) {
11737: push(@clonecode,$item);
11738: }
11739: }
11740: if (@clonecode) {
11741: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11742: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11743: if (@diffs) {
11744: $changes{'canclone'} = 1;
11745: }
11746: } else {
11747: $newclone eq '';
11748: }
11749: } elsif ($newclone ne '') {
11750: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11751: }
11752: if ($newclone ne $currclone) {
11753: $changes{'canclone'} = 1;
11754: }
1.160.6.57 raeburn 11755: my %credits;
11756: foreach my $type (@types) {
11757: unless ($type eq 'community') {
11758: $credits{$type} = $env{'form.'.$type.'_credits'};
11759: $credits{$type} =~ s/[^\d.]+//g;
11760: }
11761: }
11762: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11763: ($env{'form.coursecredits'} eq '1')) {
11764: $changes{'coursecredits'} = 1;
11765: foreach my $type (keys(%credits)) {
11766: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11767: }
11768: } else {
11769: if ($env{'form.coursecredits'} eq '1') {
11770: foreach my $type (@types) {
11771: unless ($type eq 'community') {
11772: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11773: $changes{'coursecredits'} = 1;
11774: }
11775: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11776: }
11777: }
11778: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11779: foreach my $type (@types) {
11780: unless ($type eq 'community') {
11781: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11782: $changes{'coursecredits'} = 1;
11783: last;
11784: }
11785: }
11786: }
11787: }
11788: }
11789: if ($env{'form.postsubmit'} eq '1') {
11790: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11791: my %currtimeout;
11792: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11793: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11794: $changes{'postsubmit'} = 1;
11795: }
11796: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11797: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11798: }
11799: } else {
11800: $changes{'postsubmit'} = 1;
11801: }
11802: foreach my $type (@types) {
11803: my $timeout = $env{'form.'.$type.'_timeout'};
11804: $timeout =~ s/\D//g;
11805: if ($timeout == $staticdefaults{'postsubmit'}) {
11806: $timeout = '';
11807: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11808: $timeout = '0';
11809: }
11810: unless ($timeout eq '') {
11811: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11812: }
11813: if (exists($currtimeout{$type})) {
11814: if ($timeout ne $currtimeout{$type}) {
11815: $changes{'postsubmit'} = 1;
11816: }
11817: } elsif ($timeout ne '') {
11818: $changes{'postsubmit'} = 1;
11819: }
11820: }
11821: } else {
11822: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11823: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11824: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11825: $changes{'postsubmit'} = 1;
11826: }
11827: } else {
11828: $changes{'postsubmit'} = 1;
11829: }
1.160.6.16 raeburn 11830: }
1.121 raeburn 11831: }
11832: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11833: $dom);
11834: if ($putresult eq 'ok') {
11835: if (keys(%changes) > 0) {
1.160.6.27 raeburn 11836: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 11837: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 11838: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 11839: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 11840: foreach my $item ('uselcmath','usejsme') {
11841: if ($changes{$item}) {
11842: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11843: }
1.160.6.16 raeburn 11844: }
11845: if ($changes{'coursecredits'}) {
11846: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 11847: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11848: $domdefaults{$type.'credits'} =
11849: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11850: }
11851: }
11852: }
11853: if ($changes{'postsubmit'}) {
11854: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11855: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11856: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11857: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11858: $domdefaults{$type.'postsubtimeout'} =
11859: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11860: }
11861: }
1.160.6.16 raeburn 11862: }
11863: }
1.160.6.21 raeburn 11864: if ($changes{'uploadquota'}) {
11865: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11866: foreach my $type (@types) {
11867: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11868: }
11869: }
11870: }
1.160.6.64 raeburn 11871: if ($changes{'canclone'}) {
11872: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11873: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11874: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11875: if (@clonecodes) {
11876: $domdefaults{'canclone'} = join('+',@clonecodes);
11877: }
11878: }
11879: } else {
11880: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11881: }
11882: }
1.121 raeburn 11883: my $cachetime = 24*60*60;
11884: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11885: if (ref($lastactref) eq 'HASH') {
11886: $lastactref->{'domdefaults'} = 1;
11887: }
1.121 raeburn 11888: }
11889: $resulttext = &mt('Changes made:').'<ul>';
11890: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 11891: if ($item eq 'uselcmath') {
1.121 raeburn 11892: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 11893: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 11894: } else {
1.160.6.57 raeburn 11895: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11896: }
11897: } elsif ($item eq 'usejsme') {
11898: if ($env{'form.'.$item} eq '1') {
11899: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11900: } else {
11901: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 11902: }
1.139 raeburn 11903: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 11904: $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 11905: } elsif ($item eq 'uploadquota') {
11906: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11907: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11908: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11909: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 11910: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
11911:
1.160.6.21 raeburn 11912: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11913: '</ul>'.
11914: '</li>';
11915: } else {
11916: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11917: }
1.160.6.70 raeburn 11918: } elsif ($item eq 'mysqltables') {
11919: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
11920: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
11921: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
11922: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
11923: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
11924: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
11925: '</ul>'.
11926: '</li>';
11927: } else {
11928: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
11929: }
1.160.6.57 raeburn 11930: } elsif ($item eq 'postsubmit') {
11931: if ($domdefaults{'postsubmit'} eq 'off') {
11932: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
11933: } else {
11934: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
11935: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11936: $resulttext .= &mt('durations:').'<ul>';
11937: foreach my $type (@types) {
11938: $resulttext .= '<li>';
11939: my $timeout;
11940: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11941: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11942: }
11943: my $display;
11944: if ($timeout eq '0') {
11945: $display = &mt('unlimited');
11946: } elsif ($timeout eq '') {
11947: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
11948: } else {
11949: $display = &mt('[quant,_1,second]',$timeout);
11950: }
11951: if ($type eq 'community') {
11952: $resulttext .= &mt('Communities');
11953: } elsif ($type eq 'official') {
11954: $resulttext .= &mt('Official courses');
11955: } elsif ($type eq 'unofficial') {
11956: $resulttext .= &mt('Unofficial courses');
11957: } elsif ($type eq 'textbook') {
11958: $resulttext .= &mt('Textbook courses');
11959: }
11960: $resulttext .= ' -- '.$display.'</li>';
11961: }
11962: $resulttext .= '</ul>';
11963: }
11964: $resulttext .= '</li>';
11965: }
1.160.6.16 raeburn 11966: } elsif ($item eq 'coursecredits') {
11967: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11968: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 11969: ($domdefaults{'unofficialcredits'} eq '') &&
11970: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 11971: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11972: } else {
11973: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
11974: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
11975: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 11976: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 11977: '</ul>'.
11978: '</li>';
11979: }
11980: } else {
11981: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11982: }
1.160.6.64 raeburn 11983: } elsif ($item eq 'canclone') {
11984: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11985: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11986: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
11987: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
11988: }
11989: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
11990: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
11991: } else {
11992: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
11993: }
1.140 raeburn 11994: }
1.121 raeburn 11995: }
11996: $resulttext .= '</ul>';
11997: } else {
11998: $resulttext = &mt('No changes made to course defaults');
11999: }
12000: } else {
12001: $resulttext = '<span class="LC_error">'.
12002: &mt('An error occurred: [_1]',$putresult).'</span>';
12003: }
12004: return $resulttext;
12005: }
12006:
1.160.6.37 raeburn 12007: sub modify_selfenrollment {
12008: my ($dom,$lastactref,%domconfig) = @_;
12009: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
12010: my @types = ('official','unofficial','community','textbook');
12011: my %titles = &tool_titles();
12012: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12013: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
12014: $ordered{'default'} = ['types','registered','approval','limit'];
12015:
12016: my (%roles,%shown,%toplevel);
12017: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12018:
12019: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12020: if ($domconfig{'selfenrollment'} eq '') {
12021: $domconfig{'selfenrollment'} = {};
12022: }
12023: }
12024: %toplevel = (
12025: admin => 'Configuration Rights',
12026: default => 'Default settings',
12027: validation => 'Validation of self-enrollment requests',
12028: );
12029: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
12030:
12031: if (ref($ordered{'admin'}) eq 'ARRAY') {
12032: foreach my $item (@{$ordered{'admin'}}) {
12033: foreach my $type (@types) {
12034: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12035: $selfenrollhash{'admin'}{$type}{$item} = 1;
12036: } else {
12037: $selfenrollhash{'admin'}{$type}{$item} = 0;
12038: }
12039: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12040: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12041: if ($selfenrollhash{'admin'}{$type}{$item} ne
12042: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12043: push(@{$changes{'admin'}{$type}},$item);
12044: }
12045: } else {
12046: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12047: push(@{$changes{'admin'}{$type}},$item);
12048: }
12049: }
12050: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12051: push(@{$changes{'admin'}{$type}},$item);
12052: }
12053: }
12054: }
12055: }
12056:
12057: foreach my $item (@{$ordered{'default'}}) {
12058: foreach my $type (@types) {
12059: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12060: if ($item eq 'types') {
12061: unless (($value eq 'all') || ($value eq 'dom')) {
12062: $value = '';
12063: }
12064: } elsif ($item eq 'registered') {
12065: unless ($value eq '1') {
12066: $value = 0;
12067: }
12068: } elsif ($item eq 'approval') {
12069: unless ($value =~ /^[012]$/) {
12070: $value = 0;
12071: }
12072: } else {
12073: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12074: $value = 'none';
12075: }
12076: }
12077: $selfenrollhash{'default'}{$type}{$item} = $value;
12078: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12079: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12080: if ($selfenrollhash{'default'}{$type}{$item} ne
12081: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12082: push(@{$changes{'default'}{$type}},$item);
12083: }
12084: } else {
12085: push(@{$changes{'default'}{$type}},$item);
12086: }
12087: } else {
12088: push(@{$changes{'default'}{$type}},$item);
12089: }
12090: if ($item eq 'limit') {
12091: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12092: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12093: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12094: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12095: }
12096: } else {
12097: $selfenrollhash{'default'}{$type}{'cap'} = '';
12098: }
12099: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12100: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12101: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12102: push(@{$changes{'default'}{$type}},'cap');
12103: }
12104: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12105: push(@{$changes{'default'}{$type}},'cap');
12106: }
12107: }
12108: }
12109: }
12110:
12111: foreach my $item (@{$itemsref}) {
12112: if ($item eq 'fields') {
12113: my @changed;
12114: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12115: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12116: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12117: }
12118: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12119: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12120: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12121: $domconfig{'selfenrollment'}{'validation'}{$item});
12122: } else {
12123: @changed = @{$selfenrollhash{'validation'}{$item}};
12124: }
12125: } else {
12126: @changed = @{$selfenrollhash{'validation'}{$item}};
12127: }
12128: if (@changed) {
12129: if ($selfenrollhash{'validation'}{$item}) {
12130: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12131: } else {
12132: $changes{'validation'}{$item} = &mt('None');
12133: }
12134: }
12135: } else {
12136: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12137: if ($item eq 'markup') {
12138: if ($env{'form.selfenroll_validation_'.$item}) {
12139: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12140: }
12141: }
12142: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12143: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12144: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12145: }
12146: }
12147: }
12148: }
12149:
12150: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12151: $dom);
12152: if ($putresult eq 'ok') {
12153: if (keys(%changes) > 0) {
12154: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12155: $resulttext = &mt('Changes made:').'<ul>';
12156: foreach my $key ('admin','default','validation') {
12157: if (ref($changes{$key}) eq 'HASH') {
12158: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12159: if ($key eq 'validation') {
12160: foreach my $item (@{$itemsref}) {
12161: if (exists($changes{$key}{$item})) {
12162: if ($item eq 'markup') {
12163: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12164: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12165: } else {
12166: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12167: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12168: }
12169: }
12170: }
12171: } else {
12172: foreach my $type (@types) {
12173: if ($type eq 'community') {
12174: $roles{'1'} = &mt('Community personnel');
12175: } else {
12176: $roles{'1'} = &mt('Course personnel');
12177: }
12178: if (ref($changes{$key}{$type}) eq 'ARRAY') {
12179: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12180: if ($key eq 'admin') {
12181: my @mgrdc = ();
12182: if (ref($ordered{$key}) eq 'ARRAY') {
12183: foreach my $item (@{$ordered{'admin'}}) {
12184: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12185: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12186: push(@mgrdc,$item);
12187: }
12188: }
12189: }
12190: if (@mgrdc) {
12191: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12192: } else {
12193: delete($domdefaults{$type.'selfenrolladmdc'});
12194: }
12195: }
12196: } else {
12197: if (ref($ordered{$key}) eq 'ARRAY') {
12198: foreach my $item (@{$ordered{$key}}) {
12199: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12200: $domdefaults{$type.'selfenroll'.$item} =
12201: $selfenrollhash{$key}{$type}{$item};
12202: }
12203: }
12204: }
12205: }
12206: }
12207: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12208: foreach my $item (@{$ordered{$key}}) {
12209: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12210: $resulttext .= '<li>';
12211: if ($key eq 'admin') {
12212: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12213: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12214: } else {
12215: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12216: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12217: }
12218: $resulttext .= '</li>';
12219: }
12220: }
12221: $resulttext .= '</ul></li>';
12222: }
12223: }
12224: $resulttext .= '</ul></li>';
12225: }
12226: }
12227: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12228: my $cachetime = 24*60*60;
12229: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12230: if (ref($lastactref) eq 'HASH') {
12231: $lastactref->{'domdefaults'} = 1;
12232: }
12233: }
12234: }
12235: $resulttext .= '</ul>';
12236: } else {
12237: $resulttext = &mt('No changes made to self-enrollment settings');
12238: }
12239: } else {
12240: $resulttext = '<span class="LC_error">'.
12241: &mt('An error occurred: [_1]',$putresult).'</span>';
12242: }
12243: return $resulttext;
12244: }
12245:
1.137 raeburn 12246: sub modify_usersessions {
1.160.6.27 raeburn 12247: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12248: my @hostingtypes = ('version','excludedomain','includedomain');
12249: my @offloadtypes = ('primary','default');
12250: my %types = (
12251: remote => \@hostingtypes,
12252: hosted => \@hostingtypes,
12253: spares => \@offloadtypes,
12254: );
12255: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12256: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 12257: my (%by_ip,%by_location,@intdoms);
12258: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
12259: my @locations = sort(keys(%by_location));
1.137 raeburn 12260: my (%defaultshash,%changes);
12261: foreach my $prefix (@prefixes) {
12262: $defaultshash{'usersessions'}{$prefix} = {};
12263: }
1.160.6.27 raeburn 12264: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12265: my $resulttext;
1.138 raeburn 12266: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12267: foreach my $prefix (@prefixes) {
1.145 raeburn 12268: next if ($prefix eq 'spares');
12269: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12270: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12271: if ($type eq 'version') {
12272: my $value = $env{'form.'.$prefix.'_'.$type};
12273: my $okvalue;
12274: if ($value ne '') {
12275: if (grep(/^\Q$value\E$/,@lcversions)) {
12276: $okvalue = $value;
12277: }
12278: }
12279: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12280: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12281: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12282: if ($inuse == 0) {
12283: $changes{$prefix}{$type} = 1;
12284: } else {
12285: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12286: $changes{$prefix}{$type} = 1;
12287: }
12288: if ($okvalue ne '') {
12289: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12290: }
12291: }
12292: } else {
12293: if (($inuse == 1) && ($okvalue ne '')) {
12294: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12295: $changes{$prefix}{$type} = 1;
12296: }
12297: }
12298: } else {
12299: if (($inuse == 1) && ($okvalue ne '')) {
12300: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12301: $changes{$prefix}{$type} = 1;
12302: }
12303: }
12304: } else {
12305: if (($inuse == 1) && ($okvalue ne '')) {
12306: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12307: $changes{$prefix}{$type} = 1;
12308: }
12309: }
12310: } else {
12311: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12312: my @okvals;
12313: foreach my $val (@vals) {
1.138 raeburn 12314: if ($val =~ /:/) {
12315: my @items = split(/:/,$val);
12316: foreach my $item (@items) {
12317: if (ref($by_location{$item}) eq 'ARRAY') {
12318: push(@okvals,$item);
12319: }
12320: }
12321: } else {
12322: if (ref($by_location{$val}) eq 'ARRAY') {
12323: push(@okvals,$val);
12324: }
1.137 raeburn 12325: }
12326: }
12327: @okvals = sort(@okvals);
12328: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12329: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12330: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12331: if ($inuse == 0) {
12332: $changes{$prefix}{$type} = 1;
12333: } else {
12334: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12335: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12336: if (@changed > 0) {
12337: $changes{$prefix}{$type} = 1;
12338: }
12339: }
12340: } else {
12341: if ($inuse == 1) {
12342: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12343: $changes{$prefix}{$type} = 1;
12344: }
12345: }
12346: } else {
12347: if ($inuse == 1) {
12348: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12349: $changes{$prefix}{$type} = 1;
12350: }
12351: }
12352: } else {
12353: if ($inuse == 1) {
12354: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12355: $changes{$prefix}{$type} = 1;
12356: }
12357: }
12358: }
12359: }
12360: }
1.145 raeburn 12361:
12362: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12363: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12364: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12365: my $savespares;
12366:
12367: foreach my $lonhost (sort(keys(%servers))) {
12368: my $serverhomeID =
12369: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12370: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12371: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12372: my %spareschg;
12373: foreach my $type (@{$types{'spares'}}) {
12374: my @okspares;
12375: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12376: foreach my $server (@checked) {
1.152 raeburn 12377: if (&Apache::lonnet::hostname($server) ne '') {
12378: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12379: unless (grep(/^\Q$server\E$/,@okspares)) {
12380: push(@okspares,$server);
12381: }
1.145 raeburn 12382: }
12383: }
12384: }
12385: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12386: my $newspare;
1.152 raeburn 12387: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12388: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12389: $newspare = $new;
12390: }
12391: }
1.152 raeburn 12392: my @spares;
12393: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12394: @spares = sort(@okspares,$newspare);
12395: } else {
12396: @spares = sort(@okspares);
12397: }
12398: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12399: if (ref($spareid{$lonhost}) eq 'HASH') {
12400: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12401: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12402: if (@diffs > 0) {
12403: $spareschg{$type} = 1;
12404: }
12405: }
12406: }
12407: }
12408: if (keys(%spareschg) > 0) {
12409: $changes{'spares'}{$lonhost} = \%spareschg;
12410: }
12411: }
1.160.6.61 raeburn 12412: $defaultshash{'usersessions'}{'offloadnow'} = {};
12413: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12414: my @okoffload;
12415: if (@offloadnow) {
12416: foreach my $server (@offloadnow) {
12417: if (&Apache::lonnet::hostname($server) ne '') {
12418: unless (grep(/^\Q$server\E$/,@okoffload)) {
12419: push(@okoffload,$server);
12420: }
12421: }
12422: }
12423: if (@okoffload) {
12424: foreach my $lonhost (@okoffload) {
12425: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12426: }
12427: }
12428: }
1.145 raeburn 12429: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12430: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12431: if (ref($changes{'spares'}) eq 'HASH') {
12432: if (keys(%{$changes{'spares'}}) > 0) {
12433: $savespares = 1;
12434: }
12435: }
12436: } else {
12437: $savespares = 1;
12438: }
1.160.6.61 raeburn 12439: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12440: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12441: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12442: $changes{'offloadnow'} = 1;
12443: last;
12444: }
12445: }
12446: unless ($changes{'offloadnow'}) {
12447: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12448: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12449: $changes{'offloadnow'} = 1;
12450: last;
12451: }
12452: }
12453: }
12454: } elsif (@okoffload) {
12455: $changes{'offloadnow'} = 1;
12456: }
12457: } elsif (@okoffload) {
12458: $changes{'offloadnow'} = 1;
1.145 raeburn 12459: }
1.147 raeburn 12460: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12461: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12462: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12463: $dom);
12464: if ($putresult eq 'ok') {
12465: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12466: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12467: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12468: }
12469: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12470: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12471: }
1.160.6.61 raeburn 12472: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12473: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12474: }
1.137 raeburn 12475: }
12476: my $cachetime = 24*60*60;
12477: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12478: if (ref($lastactref) eq 'HASH') {
12479: $lastactref->{'domdefaults'} = 1;
12480: }
1.147 raeburn 12481: if (keys(%changes) > 0) {
12482: my %lt = &usersession_titles();
12483: $resulttext = &mt('Changes made:').'<ul>';
12484: foreach my $prefix (@prefixes) {
12485: if (ref($changes{$prefix}) eq 'HASH') {
12486: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12487: if ($prefix eq 'spares') {
12488: if (ref($changes{$prefix}) eq 'HASH') {
12489: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12490: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12491: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 12492: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12493: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12494: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12495: foreach my $type (@{$types{$prefix}}) {
12496: if ($changes{$prefix}{$lonhost}{$type}) {
12497: my $offloadto = &mt('None');
12498: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12499: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12500: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12501: }
1.145 raeburn 12502: }
1.147 raeburn 12503: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12504: }
1.137 raeburn 12505: }
12506: }
1.147 raeburn 12507: $resulttext .= '</li>';
1.137 raeburn 12508: }
12509: }
1.147 raeburn 12510: } else {
12511: foreach my $type (@{$types{$prefix}}) {
12512: if (defined($changes{$prefix}{$type})) {
12513: my $newvalue;
12514: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12515: if (ref($defaultshash{'usersessions'}{$prefix})) {
12516: if ($type eq 'version') {
12517: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12518: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12519: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12520: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12521: }
1.145 raeburn 12522: }
12523: }
12524: }
1.147 raeburn 12525: if ($newvalue eq '') {
12526: if ($type eq 'version') {
12527: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12528: } else {
12529: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12530: }
1.145 raeburn 12531: } else {
1.147 raeburn 12532: if ($type eq 'version') {
12533: $newvalue .= ' '.&mt('(or later)');
12534: }
12535: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12536: }
1.137 raeburn 12537: }
12538: }
12539: }
1.147 raeburn 12540: $resulttext .= '</ul>';
1.137 raeburn 12541: }
12542: }
1.160.6.61 raeburn 12543: if ($changes{'offloadnow'}) {
12544: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12545: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12546: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12547: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12548: $resulttext .= '<li>'.$lonhost.'</li>';
12549: }
12550: $resulttext .= '</ul>';
12551: } else {
12552: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12553: }
12554: } else {
12555: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12556: }
12557: }
1.147 raeburn 12558: $resulttext .= '</ul>';
12559: } else {
12560: $resulttext = $nochgmsg;
1.137 raeburn 12561: }
12562: } else {
12563: $resulttext = '<span class="LC_error">'.
12564: &mt('An error occurred: [_1]',$putresult).'</span>';
12565: }
12566: } else {
1.147 raeburn 12567: $resulttext = $nochgmsg;
1.137 raeburn 12568: }
12569: return $resulttext;
12570: }
12571:
1.150 raeburn 12572: sub modify_loadbalancing {
12573: my ($dom,%domconfig) = @_;
12574: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12575: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12576: my ($othertitle,$usertypes,$types) =
12577: &Apache::loncommon::sorted_inst_types($dom);
12578: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 12579: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12580: my @sparestypes = ('primary','default');
12581: my %typetitles = &sparestype_titles();
12582: my $resulttext;
1.160.6.7 raeburn 12583: my (%currbalancer,%currtargets,%currrules,%existing);
12584: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12585: %existing = %{$domconfig{'loadbalancing'}};
12586: }
12587: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12588: \%currtargets,\%currrules);
12589: my ($saveloadbalancing,%defaultshash,%changes);
12590: my ($alltypes,$othertypes,$titles) =
12591: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12592: my %ruletitles = &offloadtype_text();
12593: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12594: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12595: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12596: if ($balancer eq '') {
12597: next;
12598: }
12599: if (!exists($servers{$balancer})) {
12600: if (exists($currbalancer{$balancer})) {
12601: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 12602: }
1.160.6.7 raeburn 12603: next;
12604: }
12605: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12606: push(@{$changes{'delete'}},$balancer);
12607: next;
12608: }
12609: if (!exists($currbalancer{$balancer})) {
12610: push(@{$changes{'add'}},$balancer);
12611: }
12612: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12613: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12614: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12615: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12616: $saveloadbalancing = 1;
12617: }
12618: foreach my $sparetype (@sparestypes) {
12619: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12620: my @offloadto;
12621: foreach my $target (@targets) {
12622: if (($servers{$target}) && ($target ne $balancer)) {
12623: if ($sparetype eq 'default') {
12624: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12625: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 12626: }
12627: }
1.160.6.7 raeburn 12628: unless(grep(/^\Q$target\E$/,@offloadto)) {
12629: push(@offloadto,$target);
12630: }
1.150 raeburn 12631: }
12632: }
1.160.6.76 raeburn 12633: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
12634: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
12635: push(@offloadto,$balancer);
12636: }
12637: }
12638: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 12639: }
1.160.6.7 raeburn 12640: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 12641: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 12642: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12643: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 12644: if (@targetdiffs > 0) {
1.160.6.7 raeburn 12645: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12646: }
1.160.6.7 raeburn 12647: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12648: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12649: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12650: }
12651: }
12652: }
12653: } else {
1.160.6.7 raeburn 12654: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
12655: foreach my $sparetype (@sparestypes) {
12656: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12657: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12658: $changes{'curr'}{$balancer}{'targets'} = 1;
12659: }
1.150 raeburn 12660: }
12661: }
1.160.6.7 raeburn 12662: }
1.150 raeburn 12663: }
12664: my $ishomedom;
1.160.6.7 raeburn 12665: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12666: $ishomedom = 1;
1.150 raeburn 12667: }
12668: if (ref($alltypes) eq 'ARRAY') {
12669: foreach my $type (@{$alltypes}) {
12670: my $rule;
1.160.6.7 raeburn 12671: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 12672: (!$ishomedom)) {
1.160.6.7 raeburn 12673: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12674: }
12675: if ($rule eq 'specific') {
1.160.6.55 raeburn 12676: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12677: if (exists($servers{$specifiedhost})) {
12678: $rule = $specifiedhost;
12679: }
1.150 raeburn 12680: }
1.160.6.7 raeburn 12681: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12682: if (ref($currrules{$balancer}) eq 'HASH') {
12683: if ($rule ne $currrules{$balancer}{$type}) {
12684: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12685: }
12686: } elsif ($rule ne '') {
1.160.6.7 raeburn 12687: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12688: }
12689: }
12690: }
1.160.6.7 raeburn 12691: }
12692: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12693: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12694: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12695: $defaultshash{'loadbalancing'} = {};
12696: }
12697: my $putresult = &Apache::lonnet::put_dom('configuration',
12698: \%defaultshash,$dom);
12699: if ($putresult eq 'ok') {
12700: if (keys(%changes) > 0) {
1.160.6.54 raeburn 12701: my %toupdate;
1.160.6.7 raeburn 12702: if (ref($changes{'delete'}) eq 'ARRAY') {
12703: foreach my $balancer (sort(@{$changes{'delete'}})) {
12704: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 12705: $toupdate{$balancer} = 1;
1.150 raeburn 12706: }
1.160.6.7 raeburn 12707: }
12708: if (ref($changes{'add'}) eq 'ARRAY') {
12709: foreach my $balancer (sort(@{$changes{'add'}})) {
12710: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 12711: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12712: }
12713: }
12714: if (ref($changes{'curr'}) eq 'HASH') {
12715: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 12716: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12717: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12718: if ($changes{'curr'}{$balancer}{'targets'}) {
12719: my %offloadstr;
12720: foreach my $sparetype (@sparestypes) {
12721: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12722: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12723: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12724: }
12725: }
1.150 raeburn 12726: }
1.160.6.7 raeburn 12727: if (keys(%offloadstr) == 0) {
12728: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 12729: } else {
1.160.6.7 raeburn 12730: my $showoffload;
12731: foreach my $sparetype (@sparestypes) {
12732: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12733: if (defined($offloadstr{$sparetype})) {
12734: $showoffload .= $offloadstr{$sparetype};
12735: } else {
12736: $showoffload .= &mt('None');
12737: }
12738: $showoffload .= (' 'x3);
12739: }
12740: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 12741: }
12742: }
12743: }
1.160.6.7 raeburn 12744: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12745: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12746: foreach my $type (@{$alltypes}) {
12747: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12748: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12749: my $balancetext;
12750: if ($rule eq '') {
12751: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 12752: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 12753: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12754: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 12755: foreach my $sparetype (@sparestypes) {
12756: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12757: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12758: }
12759: }
1.160.6.55 raeburn 12760: foreach my $item (@{$alltypes}) {
12761: next if ($item =~ /^_LC_ipchange/);
12762: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
12763: if ($hasrule eq 'homeserver') {
12764: map { $toupdate{$_} = 1; } (keys(%libraryservers));
12765: } else {
12766: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
12767: if ($servers{$hasrule}) {
12768: $toupdate{$hasrule} = 1;
12769: }
12770: }
12771: }
12772: }
12773: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
12774: $balancetext = $ruletitles{$rule};
12775: } else {
12776: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12777: $balancetext = $ruletitles{'particular'}.' '.$receiver;
12778: if ($receiver) {
12779: $toupdate{$receiver};
12780: }
12781: }
12782: } else {
12783: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 12784: }
1.160.6.7 raeburn 12785: } else {
12786: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
12787: }
1.160.6.26 raeburn 12788: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 12789: }
12790: }
12791: }
12792: }
1.160.6.54 raeburn 12793: if (keys(%toupdate)) {
12794: my %thismachine;
12795: my $updatedhere;
12796: my $cachetime = 60*60*24;
12797: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12798: foreach my $lonhost (keys(%toupdate)) {
12799: if ($thismachine{$lonhost}) {
12800: unless ($updatedhere) {
12801: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
12802: $defaultshash{'loadbalancing'},
12803: $cachetime);
12804: $updatedhere = 1;
12805: }
12806: } else {
12807: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
12808: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
12809: }
12810: }
12811: }
1.150 raeburn 12812: }
1.160.6.7 raeburn 12813: }
12814: if ($resulttext ne '') {
12815: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 12816: } else {
12817: $resulttext = $nochgmsg;
12818: }
12819: } else {
1.160.6.7 raeburn 12820: $resulttext = $nochgmsg;
1.150 raeburn 12821: }
12822: } else {
1.160.6.7 raeburn 12823: $resulttext = '<span class="LC_error">'.
12824: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 12825: }
12826: } else {
1.160.6.7 raeburn 12827: $resulttext = $nochgmsg;
1.150 raeburn 12828: }
12829: return $resulttext;
12830: }
12831:
1.48 raeburn 12832: sub recurse_check {
12833: my ($chkcats,$categories,$depth,$name) = @_;
12834: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
12835: my $chg = 0;
12836: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
12837: my $category = $chkcats->[$depth]{$name}[$j];
12838: my $item;
12839: if ($category eq '') {
12840: $chg ++;
12841: } else {
12842: my $deeper = $depth + 1;
12843: $item = &escape($category).':'.&escape($name).':'.$depth;
12844: if ($chg) {
12845: $categories->{$item} -= $chg;
12846: }
12847: &recurse_check($chkcats,$categories,$deeper,$category);
12848: $deeper --;
12849: }
12850: }
12851: }
12852: return;
12853: }
12854:
12855: sub recurse_cat_deletes {
12856: my ($item,$coursecategories,$deletions) = @_;
12857: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12858: my $subdepth = $depth + 1;
12859: if (ref($coursecategories) eq 'HASH') {
12860: foreach my $subitem (keys(%{$coursecategories})) {
12861: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
12862: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
12863: delete($coursecategories->{$subitem});
12864: $deletions->{$subitem} = 1;
12865: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 12866: }
1.48 raeburn 12867: }
12868: }
12869: return;
12870: }
12871:
1.125 raeburn 12872: sub active_dc_picker {
1.160.6.16 raeburn 12873: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 12874: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 12875: my @domcoord = keys(%domcoords);
12876: if (keys(%currhash)) {
12877: foreach my $dc (keys(%currhash)) {
12878: unless (exists($domcoords{$dc})) {
12879: push(@domcoord,$dc);
12880: }
12881: }
12882: }
12883: @domcoord = sort(@domcoord);
12884: my $numdcs = scalar(@domcoord);
12885: my $rows = 0;
12886: my $table;
1.125 raeburn 12887: if ($numdcs > 1) {
1.160.6.16 raeburn 12888: $table = '<table>';
12889: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 12890: my $rem = $i%($numinrow);
12891: if ($rem == 0) {
12892: if ($i > 0) {
1.160.6.16 raeburn 12893: $table .= '</tr>';
1.125 raeburn 12894: }
1.160.6.16 raeburn 12895: $table .= '<tr>';
12896: $rows ++;
1.125 raeburn 12897: }
1.160.6.16 raeburn 12898: my $check = '';
12899: if ($inputtype eq 'radio') {
12900: if (keys(%currhash) == 0) {
12901: if (!$i) {
12902: $check = ' checked="checked"';
12903: }
12904: } elsif (exists($currhash{$domcoord[$i]})) {
12905: $check = ' checked="checked"';
12906: }
12907: } else {
12908: if (exists($currhash{$domcoord[$i]})) {
12909: $check = ' checked="checked"';
1.125 raeburn 12910: }
12911: }
1.160.6.16 raeburn 12912: if ($i == @domcoord - 1) {
1.125 raeburn 12913: my $colsleft = $numinrow - $rem;
12914: if ($colsleft > 1) {
1.160.6.16 raeburn 12915: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 12916: } else {
1.160.6.16 raeburn 12917: $table .= '<td class="LC_left_item">';
1.125 raeburn 12918: }
12919: } else {
1.160.6.16 raeburn 12920: $table .= '<td class="LC_left_item">';
12921: }
12922: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
12923: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
12924: $table .= '<span class="LC_nobreak"><label>'.
12925: '<input type="'.$inputtype.'" name="'.$name.'"'.
12926: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
12927: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 12928: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 12929: }
1.160.6.33 raeburn 12930: $table .= '</label></span></td>';
1.125 raeburn 12931: }
1.160.6.16 raeburn 12932: $table .= '</tr></table>';
12933: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 12934: my ($dcname,$dcdom) = split(':',$domcoord[0]);
12935: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 12936: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 12937: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 12938: if ($user ne $dcname.':'.$dcdom) {
12939: $table .= ' ('.$dcname.':'.$dcdom.')';
12940: }
1.160.6.16 raeburn 12941: } else {
12942: my $check;
12943: if (exists($currhash{$domcoord[0]})) {
12944: $check = ' checked="checked"';
12945: }
1.160.6.50 raeburn 12946: $table = '<span class="LC_nobreak"><label>'.
12947: '<input type="checkbox" name="'.$name.'" '.
12948: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 12949: if ($user ne $dcname.':'.$dcdom) {
12950: $table .= ' ('.$dcname.':'.$dcdom.')';
12951: }
12952: $table .= '</label></span>';
1.160.6.16 raeburn 12953: $rows ++;
12954: }
1.125 raeburn 12955: }
1.160.6.16 raeburn 12956: return ($numdcs,$table,$rows);
1.125 raeburn 12957: }
12958:
1.137 raeburn 12959: sub usersession_titles {
12960: return &Apache::lonlocal::texthash(
12961: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
12962: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 12963: spares => 'Servers offloaded to, when busy',
1.137 raeburn 12964: version => 'LON-CAPA version requirement',
1.138 raeburn 12965: excludedomain => 'Allow all, but exclude specific domains',
12966: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 12967: primary => 'Primary (checked first)',
1.154 raeburn 12968: default => 'Default',
1.137 raeburn 12969: );
12970: }
12971:
1.152 raeburn 12972: sub id_for_thisdom {
12973: my (%servers) = @_;
12974: my %altids;
12975: foreach my $server (keys(%servers)) {
12976: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
12977: if ($serverhome ne $server) {
12978: $altids{$serverhome} = $server;
12979: }
12980: }
12981: return %altids;
12982: }
12983:
1.150 raeburn 12984: sub count_servers {
12985: my ($currbalancer,%servers) = @_;
12986: my (@spares,$numspares);
12987: foreach my $lonhost (sort(keys(%servers))) {
12988: next if ($currbalancer eq $lonhost);
12989: push(@spares,$lonhost);
12990: }
12991: if ($currbalancer) {
12992: $numspares = scalar(@spares);
12993: } else {
12994: $numspares = scalar(@spares) - 1;
12995: }
12996: return ($numspares,@spares);
12997: }
12998:
12999: sub lonbalance_targets_js {
1.160.6.7 raeburn 13000: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13001: my $select = &mt('Select');
13002: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13003: if (ref($servers) eq 'HASH') {
13004: $alltargets = join("','",sort(keys(%{$servers})));
13005: my @homedoms;
13006: foreach my $server (sort(keys(%{$servers}))) {
13007: if (&Apache::lonnet::host_domain($server) eq $dom) {
13008: push(@homedoms,'1');
13009: } else {
13010: push(@homedoms,'0');
13011: }
13012: }
13013: $allishome = join("','",@homedoms);
13014: }
13015: if (ref($types) eq 'ARRAY') {
13016: if (@{$types} > 0) {
13017: @alltypes = @{$types};
13018: }
13019: }
13020: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13021: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 13022: my (%currbalancer,%currtargets,%currrules,%existing);
13023: if (ref($settings) eq 'HASH') {
13024: %existing = %{$settings};
13025: }
13026: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13027: \%currtargets,\%currrules);
13028: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13029: return <<"END";
13030:
13031: <script type="text/javascript">
13032: // <![CDATA[
13033:
1.160.6.7 raeburn 13034: currBalancers = new Array('$balancers');
13035:
13036: function toggleTargets(balnum) {
13037: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13038: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13039: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13040: var prevbalancer = prevhostitem.value;
13041: var baltotal = document.getElementById('loadbalancing_total').value;
13042: prevhostitem.value = balancer;
13043: if (prevbalancer != '') {
13044: var prevIdx = currBalancers.indexOf(prevbalancer);
13045: if (prevIdx != -1) {
13046: currBalancers.splice(prevIdx,1);
13047: }
13048: }
1.150 raeburn 13049: if (balancer == '') {
1.160.6.7 raeburn 13050: hideSpares(balnum);
1.150 raeburn 13051: } else {
1.160.6.7 raeburn 13052: var currIdx = currBalancers.indexOf(balancer);
13053: if (currIdx == -1) {
13054: currBalancers.push(balancer);
13055: }
1.150 raeburn 13056: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 13057: var ishomedom = homedoms[lonhostitem.selectedIndex];
13058: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13059: }
1.160.6.7 raeburn 13060: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13061: return;
13062: }
13063:
1.160.6.7 raeburn 13064: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13065: var alltargets = new Array('$alltargets');
13066: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13067: var offloadtypes = new Array('primary','default');
13068:
1.160.6.7 raeburn 13069: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13070: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13071:
1.151 raeburn 13072: for (var i=0; i<offloadtypes.length; i++) {
13073: var count = 0;
13074: for (var j=0; j<alltargets.length; j++) {
13075: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 13076: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13077: item.value = alltargets[j];
13078: item.style.textAlign='left';
13079: item.style.textFace='normal';
13080: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13081: if (currBalancers.indexOf(alltargets[j]) == -1) {
13082: item.disabled = '';
13083: } else {
13084: item.disabled = 'disabled';
13085: item.checked = false;
13086: }
1.151 raeburn 13087: count ++;
13088: }
1.150 raeburn 13089: }
13090: }
1.151 raeburn 13091: for (var k=0; k<insttypes.length; k++) {
13092: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13093: if (ishomedom == 1) {
1.160.6.7 raeburn 13094: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13095: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13096: } else {
1.160.6.7 raeburn 13097: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13098: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13099: }
13100: } else {
1.160.6.7 raeburn 13101: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13102: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13103: }
1.151 raeburn 13104: if ((insttypes[k] != '_LC_external') &&
13105: ((insttypes[k] != '_LC_internetdom') ||
13106: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 13107: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13108: item.options.length = 0;
13109: item.options[0] = new Option("","",true,true);
13110: var idx = 0;
1.151 raeburn 13111: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 13112: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13113: idx ++;
13114: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13115: }
13116: }
13117: }
13118: }
13119: return;
13120: }
13121:
1.160.6.7 raeburn 13122: function hideSpares(balnum) {
1.150 raeburn 13123: var alltargets = new Array('$alltargets');
13124: var insttypes = new Array('$allinsttypes');
13125: var offloadtypes = new Array('primary','default');
13126:
1.160.6.7 raeburn 13127: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13128: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13129:
13130: var total = alltargets.length - 1;
13131: for (var i=0; i<offloadtypes; i++) {
13132: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 13133: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13134: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13135: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13136: }
1.150 raeburn 13137: }
13138: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 13139: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13140: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13141: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 13142: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13143: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13144: }
13145: }
13146: return;
13147: }
13148:
1.160.6.7 raeburn 13149: function checkOffloads(item,balnum,type) {
1.150 raeburn 13150: var alltargets = new Array('$alltargets');
13151: var offloadtypes = new Array('primary','default');
13152: if (item.checked) {
13153: var total = alltargets.length - 1;
13154: var other;
13155: if (type == offloadtypes[0]) {
1.151 raeburn 13156: other = offloadtypes[1];
1.150 raeburn 13157: } else {
1.151 raeburn 13158: other = offloadtypes[0];
1.150 raeburn 13159: }
13160: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 13161: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13162: if (server == item.value) {
1.160.6.7 raeburn 13163: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13164: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13165: }
13166: }
13167: }
13168: }
13169: return;
13170: }
13171:
1.160.6.7 raeburn 13172: function singleServerToggle(balnum,type) {
13173: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13174: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 13175: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13176: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13177:
13178: } else {
1.160.6.7 raeburn 13179: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13180: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13181: }
13182: return;
13183: }
13184:
1.160.6.7 raeburn 13185: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13186: if (type == '_LC_external') {
1.160.6.26 raeburn 13187: return;
1.150 raeburn 13188: }
1.160.6.7 raeburn 13189: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13190: for (var i=0; i<typesRules.length; i++) {
13191: if (formname.elements[typesRules[i]].checked) {
13192: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 13193: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13194: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13195: } else {
1.160.6.7 raeburn 13196: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13197: }
13198: }
13199: }
13200: return;
13201: }
13202:
13203: function balancerDeleteChange(balnum) {
13204: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13205: var baltotal = document.getElementById('loadbalancing_total').value;
13206: var addtarget;
13207: var removetarget;
13208: var action = 'delete';
13209: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13210: var lonhost = hostitem.value;
13211: var currIdx = currBalancers.indexOf(lonhost);
13212: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13213: if (currIdx != -1) {
13214: currBalancers.splice(currIdx,1);
13215: }
13216: addtarget = lonhost;
13217: } else {
13218: if (currIdx == -1) {
13219: currBalancers.push(lonhost);
13220: }
13221: removetarget = lonhost;
13222: action = 'undelete';
13223: }
13224: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13225: }
13226: return;
13227: }
13228:
13229: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13230: if (baltotal > 1) {
13231: var offloadtypes = new Array('primary','default');
13232: var alltargets = new Array('$alltargets');
13233: var insttypes = new Array('$allinsttypes');
13234: for (var i=0; i<baltotal; i++) {
13235: if (i != balnum) {
13236: for (var j=0; j<offloadtypes.length; j++) {
13237: var total = alltargets.length - 1;
13238: for (var k=0; k<total; k++) {
13239: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13240: var server = serveritem.value;
13241: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13242: if (server == addtarget) {
13243: serveritem.disabled = '';
13244: }
13245: }
13246: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13247: if (server == removetarget) {
13248: serveritem.disabled = 'disabled';
13249: serveritem.checked = false;
13250: }
13251: }
13252: }
13253: }
13254: for (var j=0; j<insttypes.length; j++) {
13255: if (insttypes[j] != '_LC_external') {
13256: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13257: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13258: var currSel = singleserver.selectedIndex;
13259: var currVal = singleserver.options[currSel].value;
13260: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13261: var numoptions = singleserver.options.length;
13262: var needsnew = 1;
13263: for (var k=0; k<numoptions; k++) {
13264: if (singleserver.options[k] == addtarget) {
13265: needsnew = 0;
13266: break;
13267: }
13268: }
13269: if (needsnew == 1) {
13270: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13271: }
13272: }
13273: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13274: singleserver.options.length = 0;
13275: if ((currVal) && (currVal != removetarget)) {
13276: singleserver.options[0] = new Option("","",false,false);
13277: } else {
13278: singleserver.options[0] = new Option("","",true,true);
13279: }
13280: var idx = 0;
13281: for (var m=0; m<alltargets.length; m++) {
13282: if (currBalancers.indexOf(alltargets[m]) == -1) {
13283: idx ++;
13284: if (currVal == alltargets[m]) {
13285: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13286: } else {
13287: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13288: }
13289: }
13290: }
13291: }
13292: }
13293: }
13294: }
1.150 raeburn 13295: }
13296: }
13297: }
13298: return;
13299: }
13300:
1.152 raeburn 13301: // ]]>
13302: </script>
13303:
13304: END
13305: }
13306:
13307: sub new_spares_js {
13308: my @sparestypes = ('primary','default');
13309: my $types = join("','",@sparestypes);
13310: my $select = &mt('Select');
13311: return <<"END";
13312:
13313: <script type="text/javascript">
13314: // <![CDATA[
13315:
13316: function updateNewSpares(formname,lonhost) {
13317: var types = new Array('$types');
13318: var include = new Array();
13319: var exclude = new Array();
13320: for (var i=0; i<types.length; i++) {
13321: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13322: for (var j=0; j<spareboxes.length; j++) {
13323: if (formname.elements[spareboxes[j]].checked) {
13324: exclude.push(formname.elements[spareboxes[j]].value);
13325: } else {
13326: include.push(formname.elements[spareboxes[j]].value);
13327: }
13328: }
13329: }
13330: for (var i=0; i<types.length; i++) {
13331: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13332: var selIdx = newSpare.selectedIndex;
13333: var currnew = newSpare.options[selIdx].value;
13334: var okSpares = new Array();
13335: for (var j=0; j<newSpare.options.length; j++) {
13336: var possible = newSpare.options[j].value;
13337: if (possible != '') {
13338: if (exclude.indexOf(possible) == -1) {
13339: okSpares.push(possible);
13340: } else {
13341: if (currnew == possible) {
13342: selIdx = 0;
13343: }
13344: }
13345: }
13346: }
13347: for (var k=0; k<include.length; k++) {
13348: if (okSpares.indexOf(include[k]) == -1) {
13349: okSpares.push(include[k]);
13350: }
13351: }
13352: okSpares.sort();
13353: newSpare.options.length = 0;
13354: if (selIdx == 0) {
13355: newSpare.options[0] = new Option("$select","",true,true);
13356: } else {
13357: newSpare.options[0] = new Option("$select","",false,false);
13358: }
13359: for (var m=0; m<okSpares.length; m++) {
13360: var idx = m+1;
13361: var selThis = 0;
13362: if (selIdx != 0) {
13363: if (okSpares[m] == currnew) {
13364: selThis = 1;
13365: }
13366: }
13367: if (selThis == 1) {
13368: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13369: } else {
13370: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13371: }
13372: }
13373: }
13374: return;
13375: }
13376:
13377: function checkNewSpares(lonhost,type) {
13378: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13379: var chosen = newSpare.options[newSpare.selectedIndex].value;
13380: if (chosen != '') {
13381: var othertype;
13382: var othernewSpare;
13383: if (type == 'primary') {
13384: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13385: }
13386: if (type == 'default') {
13387: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13388: }
13389: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13390: othernewSpare.selectedIndex = 0;
13391: }
13392: }
13393: return;
13394: }
13395:
13396: // ]]>
13397: </script>
13398:
13399: END
13400:
13401: }
13402:
13403: sub common_domprefs_js {
13404: return <<"END";
13405:
13406: <script type="text/javascript">
13407: // <![CDATA[
13408:
1.150 raeburn 13409: function getIndicesByName(formname,item) {
1.152 raeburn 13410: var group = new Array();
1.150 raeburn 13411: for (var i=0;i<formname.elements.length;i++) {
13412: if (formname.elements[i].name == item) {
1.152 raeburn 13413: group.push(formname.elements[i].id);
1.150 raeburn 13414: }
13415: }
1.152 raeburn 13416: return group;
1.150 raeburn 13417: }
13418:
13419: // ]]>
13420: </script>
13421:
13422: END
1.152 raeburn 13423:
1.150 raeburn 13424: }
13425:
1.160.6.5 raeburn 13426: sub recaptcha_js {
13427: my %lt = &captcha_phrases();
13428: return <<"END";
13429:
13430: <script type="text/javascript">
13431: // <![CDATA[
13432:
13433: function updateCaptcha(caller,context) {
13434: var privitem;
13435: var pubitem;
13436: var privtext;
13437: var pubtext;
1.160.6.69 raeburn 13438: var versionitem;
13439: var versiontext;
1.160.6.5 raeburn 13440: if (document.getElementById(context+'_recaptchapub')) {
13441: pubitem = document.getElementById(context+'_recaptchapub');
13442: } else {
13443: return;
13444: }
13445: if (document.getElementById(context+'_recaptchapriv')) {
13446: privitem = document.getElementById(context+'_recaptchapriv');
13447: } else {
13448: return;
13449: }
13450: if (document.getElementById(context+'_recaptchapubtxt')) {
13451: pubtext = document.getElementById(context+'_recaptchapubtxt');
13452: } else {
13453: return;
13454: }
13455: if (document.getElementById(context+'_recaptchaprivtxt')) {
13456: privtext = document.getElementById(context+'_recaptchaprivtxt');
13457: } else {
13458: return;
13459: }
1.160.6.69 raeburn 13460: if (document.getElementById(context+'_recaptchaversion')) {
13461: versionitem = document.getElementById(context+'_recaptchaversion');
13462: } else {
13463: return;
13464: }
13465: if (document.getElementById(context+'_recaptchavertxt')) {
13466: versiontext = document.getElementById(context+'_recaptchavertxt');
13467: } else {
13468: return;
13469: }
1.160.6.5 raeburn 13470: if (caller.checked) {
13471: if (caller.value == 'recaptcha') {
13472: pubitem.type = 'text';
13473: privitem.type = 'text';
13474: pubitem.size = '40';
13475: privitem.size = '40';
13476: pubtext.innerHTML = "$lt{'pub'}";
13477: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 13478: versionitem.type = 'text';
13479: versionitem.size = '3';
13480: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 13481: } else {
13482: pubitem.type = 'hidden';
13483: privitem.type = 'hidden';
1.160.6.69 raeburn 13484: versionitem.type = 'hidden';
1.160.6.5 raeburn 13485: pubtext.innerHTML = '';
13486: privtext.innerHTML = '';
1.160.6.69 raeburn 13487: versiontext.innerHTML = '';
1.160.6.5 raeburn 13488: }
13489: }
13490: return;
13491: }
13492:
13493: // ]]>
13494: </script>
13495:
13496: END
13497:
13498: }
13499:
1.160.6.40 raeburn 13500: sub toggle_display_js {
1.160.6.16 raeburn 13501: return <<"END";
13502:
13503: <script type="text/javascript">
13504: // <![CDATA[
13505:
1.160.6.40 raeburn 13506: function toggleDisplay(domForm,caller) {
13507: if (document.getElementById(caller)) {
13508: var divitem = document.getElementById(caller);
13509: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 13510: var checkval = 1;
13511: var dispval = 'block';
1.160.6.40 raeburn 13512: if (caller == 'emailoptions') {
13513: optionsElement = domForm.cancreate_email;
13514: }
1.160.6.57 raeburn 13515: if (caller == 'studentsubmission') {
13516: optionsElement = domForm.postsubmit;
13517: }
1.160.6.64 raeburn 13518: if (caller == 'cloneinstcode') {
13519: optionsElement = domForm.canclone;
13520: checkval = 'instcode';
13521: }
1.160.6.40 raeburn 13522: if (optionsElement.length) {
1.160.6.16 raeburn 13523: var currval;
1.160.6.40 raeburn 13524: for (var i=0; i<optionsElement.length; i++) {
13525: if (optionsElement[i].checked) {
13526: currval = optionsElement[i].value;
1.160.6.16 raeburn 13527: }
13528: }
1.160.6.64 raeburn 13529: if (currval == checkval) {
13530: divitem.style.display = dispval;
1.160.6.16 raeburn 13531: } else {
1.160.6.40 raeburn 13532: divitem.style.display = 'none';
1.160.6.16 raeburn 13533: }
13534: }
13535: }
13536: return;
13537: }
13538:
13539: // ]]>
13540: </script>
13541:
13542: END
13543:
13544: }
13545:
1.160.6.5 raeburn 13546: sub captcha_phrases {
13547: return &Apache::lonlocal::texthash (
13548: priv => 'Private key',
13549: pub => 'Public key',
13550: original => 'original (CAPTCHA)',
13551: recaptcha => 'successor (ReCAPTCHA)',
13552: notused => 'unused',
1.160.6.69 raeburn 13553: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 13554: );
13555: }
13556:
1.160.6.24 raeburn 13557: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 13558: my ($dom,$cachekeys) = @_;
13559: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 13560: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13561: my %thismachine;
13562: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.27 raeburn 13563: my @posscached = ('domainconfig','domdefaults');
1.160.6.61 raeburn 13564: if (keys(%servers)) {
1.160.6.24 raeburn 13565: foreach my $server (keys(%servers)) {
13566: next if ($thismachine{$server});
1.160.6.27 raeburn 13567: my @cached;
13568: foreach my $name (@posscached) {
13569: if ($cachekeys->{$name}) {
13570: push(@cached,&escape($name).':'.&escape($dom));
13571: }
13572: }
13573: if (@cached) {
13574: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13575: }
1.160.6.24 raeburn 13576: }
13577: }
13578: return;
13579: }
13580:
1.3 raeburn 13581: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>