Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.81
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.81! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.80 2017/03/13 21:20:18 raeburn Exp $
1.160.6.40 raeburn 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.160.6.78 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
30: ##############################################################
31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 107: (official, unofficial, community, and textbook). In each case the radio buttons
108: allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.1 raeburn 177:
1.155 raeburn 178: my $registered_cleanup;
179: my $modified_urls;
180:
1.1 raeburn 181: sub handler {
182: my $r=shift;
183: if ($r->header_only) {
184: &Apache::loncommon::content_type($r,'text/html');
185: $r->send_http_header;
186: return OK;
187: }
188:
1.91 raeburn 189: my $context = 'domain';
1.1 raeburn 190: my $dom = $env{'request.role.domain'};
1.5 albertel 191: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 192: if (&Apache::lonnet::allowed('mau',$dom)) {
193: &Apache::loncommon::content_type($r,'text/html');
194: $r->send_http_header;
195: } else {
196: $env{'user.error.msg'}=
197: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
198: return HTTP_NOT_ACCEPTABLE;
199: }
1.155 raeburn 200:
201: $registered_cleanup=0;
202: @{$modified_urls}=();
203:
1.1 raeburn 204: &Apache::lonhtmlcommon::clear_breadcrumbs();
205: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 206: ['phase','actions']);
1.30 raeburn 207: my $phase = 'pickactions';
1.3 raeburn 208: if ( exists($env{'form.phase'}) ) {
209: $phase = $env{'form.phase'};
210: }
1.150 raeburn 211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 212: my %domconfig =
1.6 raeburn 213: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 214: 'quotas','autoenroll','autoupdate','autocreate',
215: 'directorysrch','usercreation','usermodification',
216: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 217: 'serverstatuses','requestcourses','helpsettings',
218: 'coursedefaults','usersessions','loadbalancing',
219: 'requestauthor','selfenrollment','inststatus'],$dom);
1.43 raeburn 220: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 221: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 222: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 223: 'requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 224: 'serverstatuses','helpsettings','coursedefaults',
225: 'selfenrollment','usersessions');
1.160.6.7 raeburn 226: my %existing;
227: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
228: %existing = %{$domconfig{'loadbalancing'}};
229: }
230: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 231: push(@prefs_order,'loadbalancing');
232: }
1.30 raeburn 233: my %prefs = (
234: 'rolecolors' =>
235: { text => 'Default color schemes',
1.67 raeburn 236: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 237: header => [{col1 => 'Student Settings',
238: col2 => '',},
239: {col1 => 'Coordinator Settings',
240: col2 => '',},
241: {col1 => 'Author Settings',
242: col2 => '',},
243: {col1 => 'Administrator Settings',
244: col2 => '',}],
1.160.6.37 raeburn 245: print => \&print_rolecolors,
246: modify => \&modify_rolecolors,
1.30 raeburn 247: },
1.110 raeburn 248: 'login' =>
1.30 raeburn 249: { text => 'Log-in page options',
1.67 raeburn 250: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 251: header => [{col1 => 'Log-in Page Items',
252: col2 => '',},
253: {col1 => 'Log-in Help',
1.160.6.56 raeburn 254: col2 => 'Value'},
255: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 256: col2 => 'Value'}],
1.160.6.37 raeburn 257: print => \&print_login,
258: modify => \&modify_login,
1.30 raeburn 259: },
1.43 raeburn 260: 'defaults' =>
1.160.6.40 raeburn 261: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 262: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 263: header => [{col1 => 'Setting',
1.160.6.40 raeburn 264: col2 => 'Value'},
1.160.6.80 raeburn 265: {col1 => 'Internal Authentication',
266: col2 => 'Value'},
1.160.6.40 raeburn 267: {col1 => 'Institutional user types',
268: col2 => 'Assignable to e-mail usernames'}],
1.160.6.37 raeburn 269: print => \&print_defaults,
270: modify => \&modify_defaults,
1.43 raeburn 271: },
1.30 raeburn 272: 'quotas' =>
1.160.6.20 raeburn 273: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 274: help => 'Domain_Configuration_Quotas',
1.77 raeburn 275: header => [{col1 => 'User affiliation',
1.72 raeburn 276: col2 => 'Available tools',
1.160.6.28 raeburn 277: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 278: print => \&print_quotas,
279: modify => \&modify_quotas,
1.30 raeburn 280: },
281: 'autoenroll' =>
282: { text => 'Auto-enrollment settings',
1.67 raeburn 283: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 284: header => [{col1 => 'Configuration setting',
285: col2 => 'Value(s)'}],
1.160.6.37 raeburn 286: print => \&print_autoenroll,
287: modify => \&modify_autoenroll,
1.30 raeburn 288: },
289: 'autoupdate' =>
290: { text => 'Auto-update settings',
1.67 raeburn 291: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 292: header => [{col1 => 'Setting',
293: col2 => 'Value',},
1.131 raeburn 294: {col1 => 'Setting',
295: col2 => 'Affiliation'},
1.43 raeburn 296: {col1 => 'User population',
1.160.6.35 raeburn 297: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 298: print => \&print_autoupdate,
299: modify => \&modify_autoupdate,
1.30 raeburn 300: },
1.125 raeburn 301: 'autocreate' =>
302: { text => 'Auto-course creation settings',
303: help => 'Domain_Configuration_Auto_Creation',
304: header => [{col1 => 'Configuration Setting',
305: col2 => 'Value',}],
1.160.6.37 raeburn 306: print => \&print_autocreate,
307: modify => \&modify_autocreate,
1.125 raeburn 308: },
1.30 raeburn 309: 'directorysrch' =>
1.160.6.72 raeburn 310: { text => 'Directory searches',
1.67 raeburn 311: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 312: header => [{col1 => 'Institutional Directory Setting',
313: col2 => 'Value',},
314: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 315: col2 => 'Value',}],
1.160.6.37 raeburn 316: print => \&print_directorysrch,
317: modify => \&modify_directorysrch,
1.30 raeburn 318: },
319: 'contacts' =>
1.160.6.78 raeburn 320: { text => 'E-mail addresses and helpform',
1.67 raeburn 321: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 322: header => [{col1 => 'Default e-mail addresses',
323: col2 => 'Value',},
324: {col1 => 'Recipient(s) for notifications',
325: col2 => 'Value',},
326: {col1 => 'Ask helpdesk form settings',
327: col2 => 'Value',},],
1.160.6.37 raeburn 328: print => \&print_contacts,
329: modify => \&modify_contacts,
1.30 raeburn 330: },
331: 'usercreation' =>
332: { text => 'User creation',
1.67 raeburn 333: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 334: header => [{col1 => 'Format rule type',
335: col2 => 'Format rules in force'},
1.34 raeburn 336: {col1 => 'User account creation',
337: col2 => 'Usernames which may be created',},
1.30 raeburn 338: {col1 => 'Context',
1.43 raeburn 339: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 340: print => \&print_usercreation,
341: modify => \&modify_usercreation,
1.30 raeburn 342: },
1.160.6.34 raeburn 343: 'selfcreation' =>
344: { text => 'Users self-creating accounts',
345: help => 'Domain_Configuration_Self_Creation',
346: header => [{col1 => 'Self-creation with institutional username',
347: col2 => 'Enabled?'},
348: {col1 => 'Institutional user type (login/SSO self-creation)',
349: col2 => 'Information user can enter'},
350: {col1 => 'Self-creation with e-mail as username',
351: col2 => 'Settings'}],
1.160.6.37 raeburn 352: print => \&print_selfcreation,
353: modify => \&modify_selfcreation,
1.160.6.34 raeburn 354: },
1.69 raeburn 355: 'usermodification' =>
1.33 raeburn 356: { text => 'User modification',
1.67 raeburn 357: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 358: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 359: col2 => 'User information updatable in author context'},
1.33 raeburn 360: {col1 => 'Target user has role',
1.160.6.35 raeburn 361: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 362: print => \&print_usermodification,
363: modify => \&modify_usermodification,
1.33 raeburn 364: },
1.69 raeburn 365: 'scantron' =>
1.95 www 366: { text => 'Bubblesheet format file',
1.67 raeburn 367: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 368: header => [ {col1 => 'Item',
369: col2 => '',
370: }],
1.160.6.37 raeburn 371: print => \&print_scantron,
372: modify => \&modify_scantron,
1.46 raeburn 373: },
1.86 raeburn 374: 'requestcourses' =>
375: {text => 'Request creation of courses',
376: help => 'Domain_Configuration_Request_Courses',
377: header => [{col1 => 'User affiliation',
1.102 raeburn 378: col2 => 'Availability/Processing of requests',},
379: {col1 => 'Setting',
1.160.6.30 raeburn 380: col2 => 'Value'},
381: {col1 => 'Available textbooks',
1.160.6.39 raeburn 382: col2 => ''},
1.160.6.46 raeburn 383: {col1 => 'Available templates',
384: col2 => ''},
1.160.6.39 raeburn 385: {col1 => 'Validation (not official courses)',
386: col2 => 'Value'},],
1.160.6.37 raeburn 387: print => \&print_quotas,
388: modify => \&modify_quotas,
1.86 raeburn 389: },
1.160.6.5 raeburn 390: 'requestauthor' =>
1.160.6.34 raeburn 391: {text => 'Request Authoring Space',
1.160.6.5 raeburn 392: help => 'Domain_Configuration_Request_Author',
393: header => [{col1 => 'User affiliation',
394: col2 => 'Availability/Processing of requests',},
395: {col1 => 'Setting',
396: col2 => 'Value'}],
1.160.6.37 raeburn 397: print => \&print_quotas,
398: modify => \&modify_quotas,
1.160.6.5 raeburn 399: },
1.69 raeburn 400: 'coursecategories' =>
1.120 raeburn 401: { text => 'Cataloging of courses/communities',
1.67 raeburn 402: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 403: header => [{col1 => 'Catalog type/availability',
404: col2 => '',},
405: {col1 => 'Category settings for standard catalog',
1.57 raeburn 406: col2 => '',},
407: {col1 => 'Categories',
408: col2 => '',
409: }],
1.160.6.37 raeburn 410: print => \&print_coursecategories,
411: modify => \&modify_coursecategories,
1.69 raeburn 412: },
413: 'serverstatuses' =>
1.77 raeburn 414: {text => 'Access to server status pages',
1.69 raeburn 415: help => 'Domain_Configuration_Server_Status',
416: header => [{col1 => 'Status Page',
417: col2 => 'Other named users',
418: col3 => 'Specific IPs',
419: }],
1.160.6.37 raeburn 420: print => \&print_serverstatuses,
421: modify => \&modify_serverstatuses,
1.69 raeburn 422: },
1.160.6.73 raeburn 423: 'helpsettings' =>
424: {text => 'Support settings',
425: help => 'Domain_Configuration_Help_Settings',
426: header => [{col1 => 'Help Page Settings (logged-in users)',
427: col2 => 'Value'},
428: {col1 => 'Helpdesk Roles',
429: col2 => 'Settings'},],
430: print => \&print_helpsettings,
431: modify => \&modify_helpsettings,
432: },
1.160.6.39 raeburn 433: 'coursedefaults' =>
1.160.6.16 raeburn 434: {text => 'Course/Community defaults',
435: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 436: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
437: col2 => 'Value',},
438: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 439: col2 => 'Value',},],
1.160.6.37 raeburn 440: print => \&print_coursedefaults,
441: modify => \&modify_coursedefaults,
442: },
1.160.6.39 raeburn 443: 'selfenrollment' =>
1.160.6.37 raeburn 444: {text => 'Self-enrollment in Course/Community',
445: help => 'Domain_Configuration_Selfenrollment',
446: header => [{col1 => 'Configuration Rights',
447: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
448: {col1 => 'Defaults',
449: col2 => 'Value'},
450: {col1 => 'Self-enrollment validation (optional)',
451: col2 => 'Value'},],
452: print => \&print_selfenrollment,
453: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 454: },
1.141 raeburn 455: 'usersessions' =>
1.145 raeburn 456: {text => 'User session hosting/offloading',
1.137 raeburn 457: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 458: header => [{col1 => 'Domain server',
459: col2 => 'Servers to offload sessions to when busy'},
460: {col1 => 'Hosting of users from other domains',
1.137 raeburn 461: col2 => 'Rules'},
462: {col1 => "Hosting domain's own users elsewhere",
463: col2 => 'Rules'}],
1.160.6.37 raeburn 464: print => \&print_usersessions,
465: modify => \&modify_usersessions,
1.137 raeburn 466: },
1.160.6.78 raeburn 467: 'loadbalancing' =>
1.160.6.7 raeburn 468: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 469: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 470: header => [{col1 => 'Balancers',
1.150 raeburn 471: col2 => 'Default destinations',
1.160.6.13 raeburn 472: col3 => 'User affiliation',
1.150 raeburn 473: col4 => 'Overrides'},
474: ],
1.160.6.37 raeburn 475: print => \&print_loadbalancing,
476: modify => \&modify_loadbalancing,
1.150 raeburn 477: },
1.3 raeburn 478: );
1.110 raeburn 479: if (keys(%servers) > 1) {
480: $prefs{'login'} = { text => 'Log-in page options',
481: help => 'Domain_Configuration_Login_Page',
482: header => [{col1 => 'Log-in Service',
483: col2 => 'Server Setting',},
484: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 485: col2 => ''},
486: {col1 => 'Log-in Help',
1.160.6.56 raeburn 487: col2 => 'Value'},
488: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 489: col2 => 'Value'}],
1.160.6.37 raeburn 490: print => \&print_login,
491: modify => \&modify_login,
1.110 raeburn 492: };
493: }
1.160.6.13 raeburn 494:
1.6 raeburn 495: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 496: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 497: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 498: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 499: text=>"Settings to display/modify"});
1.9 raeburn 500: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 501:
1.3 raeburn 502: if ($phase eq 'process') {
1.160.6.27 raeburn 503: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
504: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 505: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 506: $r->rflush();
1.160.6.27 raeburn 507: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 508: }
1.30 raeburn 509: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 510: my $js = &recaptcha_js().
1.160.6.40 raeburn 511: &toggle_display_js();
1.160.6.7 raeburn 512: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 513: my ($othertitle,$usertypes,$types) =
514: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 515: $js .= &lonbalance_targets_js($dom,$types,\%servers,
516: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 517: &new_spares_js().
518: &common_domprefs_js().
519: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 520: }
1.160.6.30 raeburn 521: if (grep(/^requestcourses$/,@actions)) {
522: my $javascript_validations;
523: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
524: $js .= <<END;
525: <script type="text/javascript">
526: $javascript_validations
527: </script>
528: $coursebrowserjs
529: END
530: }
1.160.6.78 raeburn 531: if (grep(/^contacts$/,@actions)) {
532: $js .= &contacts_javascript();
533: }
1.150 raeburn 534: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 535: } else {
1.160.6.11 raeburn 536: # check if domconfig user exists for the domain.
537: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 538: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 539: &config_check($dom,$confname,$servadm);
540: unless ($configuserok eq 'ok') {
541: &Apache::lonconfigsettings::print_header($r,$phase,$context);
542: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
543: $confname).
544: '<br />'
545: );
546: if ($switchserver) {
547: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
548: '<br />'.
549: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
550: '<br />'.
551: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
552: '<br />'.
553: &mt('To do that now, use the following link: [_1]',$switchserver)
554: );
555: } else {
556: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
557: '<br />'.
558: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
559: );
560: }
561: $r->print(&Apache::loncommon::end_page());
562: return OK;
563: }
1.21 raeburn 564: if (keys(%domconfig) == 0) {
565: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 566: my @ids=&Apache::lonnet::current_machine_ids();
567: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 568: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 569: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 570: my $custom_img_count = 0;
571: foreach my $img (@loginimages) {
572: if ($designhash{$dom.'.login.'.$img} ne '') {
573: $custom_img_count ++;
574: }
575: }
576: foreach my $role (@roles) {
577: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
578: $custom_img_count ++;
579: }
580: }
581: if ($custom_img_count > 0) {
1.94 raeburn 582: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 583: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 584: $r->print(
585: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
586: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
587: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
588: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
589: if ($switch_server) {
1.30 raeburn 590: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 591: }
1.91 raeburn 592: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 593: return OK;
594: }
595: }
596: }
1.91 raeburn 597: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 598: }
599: return OK;
600: }
601:
602: sub process_changes {
1.160.6.24 raeburn 603: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 604: my %domconfig;
605: if (ref($values) eq 'HASH') {
606: %domconfig = %{$values};
607: }
1.3 raeburn 608: my $output;
609: if ($action eq 'login') {
1.160.6.24 raeburn 610: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 611: } elsif ($action eq 'rolecolors') {
1.9 raeburn 612: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 613: $lastactref,%domconfig);
1.3 raeburn 614: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 615: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 616: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 617: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 618: } elsif ($action eq 'autoupdate') {
619: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 620: } elsif ($action eq 'autocreate') {
621: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 622: } elsif ($action eq 'directorysrch') {
1.160.6.81! raeburn 623: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 624: } elsif ($action eq 'usercreation') {
1.28 raeburn 625: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 626: } elsif ($action eq 'selfcreation') {
627: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 628: } elsif ($action eq 'usermodification') {
629: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 630: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 631: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 632: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 633: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 634: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 635: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 636: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 637: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 638: } elsif ($action eq 'serverstatuses') {
639: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 640: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 641: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 642: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 643: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 644: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 645: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 646: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 647: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 648: } elsif ($action eq 'selfenrollment') {
649: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 650: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 651: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 652: } elsif ($action eq 'loadbalancing') {
653: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 654: }
655: return $output;
656: }
657:
658: sub print_config_box {
1.9 raeburn 659: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 660: my $rowtotal = 0;
1.49 raeburn 661: my $output;
662: if ($action eq 'coursecategories') {
663: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 664: } elsif ($action eq 'defaults') {
665: $output = &defaults_javascript($settings);
1.160.6.73 raeburn 666: } elsif ($action eq 'helpsettings') {
667: my (%privs,%levelscurrent);
668: my %full=();
669: my %levels=(
670: course => {},
671: domain => {},
672: system => {},
673: );
674: my $context = 'domain';
675: my $crstype = 'Course';
676: my $formname = 'display';
677: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
678: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
679: $output =
680: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
681: \@templateroles);
1.91 raeburn 682: }
1.160.6.40 raeburn 683: $output .=
1.30 raeburn 684: '<table class="LC_nested_outer">
1.3 raeburn 685: <tr>
1.66 raeburn 686: <th align="left" valign="middle"><span class="LC_nobreak">'.
687: &mt($item->{text}).' '.
688: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
689: '</tr>';
1.30 raeburn 690: $rowtotal ++;
1.110 raeburn 691: my $numheaders = 1;
692: if (ref($item->{'header'}) eq 'ARRAY') {
693: $numheaders = scalar(@{$item->{'header'}});
694: }
695: if ($numheaders > 1) {
1.64 raeburn 696: my $colspan = '';
1.145 raeburn 697: my $rightcolspan = '';
1.160.6.42 raeburn 698: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 699: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 700: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 701: $colspan = ' colspan="2"';
702: }
1.145 raeburn 703: if ($action eq 'usersessions') {
704: $rightcolspan = ' colspan="3"';
705: }
1.30 raeburn 706: $output .= '
1.3 raeburn 707: <tr>
708: <td>
709: <table class="LC_nested">
710: <tr class="LC_info_row">
1.59 bisitz 711: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 712: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 713: </tr>';
1.69 raeburn 714: $rowtotal ++;
1.160.6.37 raeburn 715: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 716: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 717: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78 raeburn 718: ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37 raeburn 719: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 720: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 721: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 722: } elsif ($action eq 'login') {
1.160.6.56 raeburn 723: if ($numheaders == 4) {
1.160.6.5 raeburn 724: $colspan = ' colspan="2"';
725: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
726: } else {
727: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
728: }
1.160.6.37 raeburn 729: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 730: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 731: } elsif ($action eq 'rolecolors') {
1.30 raeburn 732: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 733: }
1.30 raeburn 734: $output .= '
1.6 raeburn 735: </table>
736: </td>
737: </tr>
738: <tr>
739: <td>
740: <table class="LC_nested">
741: <tr class="LC_info_row">
1.160.6.37 raeburn 742: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 743: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 744: </tr>';
745: $rowtotal ++;
1.160.6.37 raeburn 746: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
747: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 748: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.80 raeburn 749: ($action eq 'contacts') || ($action eq 'defaults')) {
1.160.6.42 raeburn 750: if ($action eq 'coursecategories') {
751: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
752: $colspan = ' colspan="2"';
753: } else {
754: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
755: }
756: $output .= '
1.63 raeburn 757: </table>
758: </td>
759: </tr>
760: <tr>
761: <td>
762: <table class="LC_nested">
763: <tr class="LC_info_row">
764: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 765: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 766: </tr>'."\n";
767: if ($action eq 'coursecategories') {
768: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
769: } else {
770: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
771: }
1.63 raeburn 772: $rowtotal ++;
1.160.6.57 raeburn 773: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 774: ($action eq 'defaults') || ($action eq 'directorysrch') ||
775: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 776: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 777: } elsif ($action eq 'login') {
1.160.6.56 raeburn 778: if ($numheaders == 4) {
1.160.6.5 raeburn 779: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
780: </table>
781: </td>
782: </tr>
783: <tr>
784: <td>
785: <table class="LC_nested">
786: <tr class="LC_info_row">
787: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 788: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 789: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
790: $rowtotal ++;
791: } else {
792: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
793: }
1.160.6.56 raeburn 794: $output .= '
795: </table>
796: </td>
797: </tr>
798: <tr>
799: <td>
800: <table class="LC_nested">
801: <tr class="LC_info_row">';
802: if ($numheaders == 4) {
803: $output .= '
804: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
805: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
806: </tr>';
807: } else {
808: $output .= '
809: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
810: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
811: </tr>';
812: }
813: $rowtotal ++;
814: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 815: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 816: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
817: $rowtotal ++;
818: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 819: </table>
820: </td>
821: </tr>
822: <tr>
823: <td>
824: <table class="LC_nested">
825: <tr class="LC_info_row">
826: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
827: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 828: &textbookcourses_javascript($settings).
829: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
830: </table>
831: </td>
832: </tr>
833: <tr>
834: <td>
835: <table class="LC_nested">
836: <tr class="LC_info_row">
837: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
838: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
839: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 840: </table>
841: </td>
842: </tr>
843: <tr>
844: <td>
845: <table class="LC_nested">
846: <tr class="LC_info_row">
1.160.6.46 raeburn 847: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
848: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 849: </tr>'.
850: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 851: } elsif ($action eq 'requestauthor') {
852: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 853: $rowtotal ++;
1.122 jms 854: } elsif ($action eq 'rolecolors') {
1.30 raeburn 855: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 856: </table>
857: </td>
858: </tr>
859: <tr>
860: <td>
861: <table class="LC_nested">
862: <tr class="LC_info_row">
1.69 raeburn 863: <td class="LC_left_item"'.$colspan.' valign="top">'.
864: &mt($item->{'header'}->[2]->{'col1'}).'</td>
865: <td class="LC_right_item" valign="top">'.
866: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 867: </tr>'.
1.30 raeburn 868: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 869: </table>
870: </td>
871: </tr>
872: <tr>
873: <td>
874: <table class="LC_nested">
875: <tr class="LC_info_row">
1.59 bisitz 876: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
877: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 878: </tr>'.
1.30 raeburn 879: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
880: $rowtotal += 2;
1.6 raeburn 881: }
1.3 raeburn 882: } else {
1.30 raeburn 883: $output .= '
1.3 raeburn 884: <tr>
885: <td>
886: <table class="LC_nested">
1.30 raeburn 887: <tr class="LC_info_row">';
1.160.6.72 raeburn 888: if ($action eq 'login') {
1.30 raeburn 889: $output .= '
1.59 bisitz 890: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 891: } elsif ($action eq 'serverstatuses') {
892: $output .= '
893: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
894: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
895:
1.6 raeburn 896: } else {
1.30 raeburn 897: $output .= '
1.69 raeburn 898: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
899: }
1.72 raeburn 900: if (defined($item->{'header'}->[0]->{'col3'})) {
901: $output .= '<td class="LC_left_item" valign="top">'.
902: &mt($item->{'header'}->[0]->{'col2'});
903: if ($action eq 'serverstatuses') {
904: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
905: }
1.69 raeburn 906: } else {
907: $output .= '<td class="LC_right_item" valign="top">'.
908: &mt($item->{'header'}->[0]->{'col2'});
909: }
910: $output .= '</td>';
911: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 912: if (defined($item->{'header'}->[0]->{'col4'})) {
913: $output .= '<td class="LC_left_item" valign="top">'.
914: &mt($item->{'header'}->[0]->{'col3'});
915: } else {
916: $output .= '<td class="LC_right_item" valign="top">'.
917: &mt($item->{'header'}->[0]->{'col3'});
918: }
1.69 raeburn 919: if ($action eq 'serverstatuses') {
920: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
921: }
922: $output .= '</td>';
1.6 raeburn 923: }
1.150 raeburn 924: if ($item->{'header'}->[0]->{'col4'}) {
925: $output .= '<td class="LC_right_item" valign="top">'.
926: &mt($item->{'header'}->[0]->{'col4'});
927: }
1.69 raeburn 928: $output .= '</tr>';
1.48 raeburn 929: $rowtotal ++;
1.160.6.5 raeburn 930: if ($action eq 'quotas') {
1.86 raeburn 931: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 932: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.78 raeburn 933: ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 934: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 935: } elsif ($action eq 'scantron') {
936: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 937: }
1.3 raeburn 938: }
1.30 raeburn 939: $output .= '
1.3 raeburn 940: </table>
941: </td>
942: </tr>
1.30 raeburn 943: </table><br />';
944: return ($output,$rowtotal);
1.1 raeburn 945: }
946:
1.3 raeburn 947: sub print_login {
1.160.6.5 raeburn 948: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 949: my ($css_class,$datatable);
1.6 raeburn 950: my %choices = &login_choices();
1.110 raeburn 951:
1.160.6.5 raeburn 952: if ($caller eq 'service') {
1.149 raeburn 953: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 954: my $choice = $choices{'disallowlogin'};
955: $css_class = ' class="LC_odd_row"';
1.128 raeburn 956: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 957: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 958: '<th>'.$choices{'server'}.'</th>'.
959: '<th>'.$choices{'serverpath'}.'</th>'.
960: '<th>'.$choices{'custompath'}.'</th>'.
961: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 962: my %disallowed;
963: if (ref($settings) eq 'HASH') {
964: if (ref($settings->{'loginvia'}) eq 'HASH') {
965: %disallowed = %{$settings->{'loginvia'}};
966: }
967: }
968: foreach my $lonhost (sort(keys(%servers))) {
969: my $direct = 'selected="selected"';
1.128 raeburn 970: if (ref($disallowed{$lonhost}) eq 'HASH') {
971: if ($disallowed{$lonhost}{'server'} ne '') {
972: $direct = '';
973: }
1.110 raeburn 974: }
1.115 raeburn 975: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 976: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 977: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
978: '</option>';
1.160.6.13 raeburn 979: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 980: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 981: my $selected = '';
1.128 raeburn 982: if (ref($disallowed{$lonhost}) eq 'HASH') {
983: if ($hostid eq $disallowed{$lonhost}{'server'}) {
984: $selected = 'selected="selected"';
985: }
1.110 raeburn 986: }
987: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
988: $servers{$hostid}.'</option>';
989: }
1.128 raeburn 990: $datatable .= '</select></td>'.
991: '<td><select name="'.$lonhost.'_serverpath">';
992: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
993: my $pathname = $path;
994: if ($path eq 'custom') {
995: $pathname = &mt('Custom Path').' ->';
996: }
997: my $selected = '';
998: if (ref($disallowed{$lonhost}) eq 'HASH') {
999: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1000: $selected = 'selected="selected"';
1001: }
1002: } elsif ($path eq '') {
1003: $selected = 'selected="selected"';
1004: }
1005: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1006: }
1007: $datatable .= '</select></td>';
1008: my ($custom,$exempt);
1009: if (ref($disallowed{$lonhost}) eq 'HASH') {
1010: $custom = $disallowed{$lonhost}{'custompath'};
1011: $exempt = $disallowed{$lonhost}{'exempt'};
1012: }
1013: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1014: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1015: '</tr>';
1.110 raeburn 1016: }
1017: $datatable .= '</table></td></tr>';
1018: return $datatable;
1.160.6.5 raeburn 1019: } elsif ($caller eq 'page') {
1020: my %defaultchecked = (
1021: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1022: 'helpdesk' => 'on',
1.160.6.5 raeburn 1023: 'adminmail' => 'off',
1024: 'newuser' => 'off',
1025: );
1.160.6.14 raeburn 1026: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1027: my (%checkedon,%checkedoff);
1.42 raeburn 1028: foreach my $item (@toggles) {
1.160.6.5 raeburn 1029: if ($defaultchecked{$item} eq 'on') {
1030: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1031: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1032: } elsif ($defaultchecked{$item} eq 'off') {
1033: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1034: $checkedon{$item} = ' ';
1035: }
1.1 raeburn 1036: }
1.160.6.5 raeburn 1037: my @images = ('img','logo','domlogo','login');
1038: my @logintext = ('textcol','bgcol');
1039: my @bgs = ('pgbg','mainbg','sidebg');
1040: my @links = ('link','alink','vlink');
1041: my %designhash = &Apache::loncommon::get_domainconf($dom);
1042: my %defaultdesign = %Apache::loncommon::defaultdesign;
1043: my (%is_custom,%designs);
1044: my %defaults = (
1045: font => $defaultdesign{'login.font'},
1046: );
1.6 raeburn 1047: foreach my $item (@images) {
1.160.6.5 raeburn 1048: $defaults{$item} = $defaultdesign{'login.'.$item};
1049: $defaults{'showlogo'}{$item} = 1;
1050: }
1051: foreach my $item (@bgs) {
1052: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1053: }
1.41 raeburn 1054: foreach my $item (@logintext) {
1.160.6.5 raeburn 1055: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1056: }
1.160.6.5 raeburn 1057: foreach my $item (@links) {
1058: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1059: }
1.160.6.5 raeburn 1060: if (ref($settings) eq 'HASH') {
1061: foreach my $item (@toggles) {
1062: if ($settings->{$item} eq '1') {
1063: $checkedon{$item} = ' checked="checked" ';
1064: $checkedoff{$item} = ' ';
1065: } elsif ($settings->{$item} eq '0') {
1066: $checkedoff{$item} = ' checked="checked" ';
1067: $checkedon{$item} = ' ';
1068: }
1.6 raeburn 1069: }
1.160.6.5 raeburn 1070: foreach my $item (@images) {
1071: if (defined($settings->{$item})) {
1072: $designs{$item} = $settings->{$item};
1073: $is_custom{$item} = 1;
1074: }
1075: if (defined($settings->{'showlogo'}{$item})) {
1076: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1077: }
1078: }
1079: foreach my $item (@logintext) {
1080: if ($settings->{$item} ne '') {
1081: $designs{'logintext'}{$item} = $settings->{$item};
1082: $is_custom{$item} = 1;
1083: }
1084: }
1085: if ($settings->{'font'} ne '') {
1086: $designs{'font'} = $settings->{'font'};
1087: $is_custom{'font'} = 1;
1088: }
1089: foreach my $item (@bgs) {
1090: if ($settings->{$item} ne '') {
1091: $designs{'bgs'}{$item} = $settings->{$item};
1092: $is_custom{$item} = 1;
1093: }
1094: }
1095: foreach my $item (@links) {
1096: if ($settings->{$item} ne '') {
1097: $designs{'links'}{$item} = $settings->{$item};
1098: $is_custom{$item} = 1;
1099: }
1100: }
1101: } else {
1102: if ($designhash{$dom.'.login.font'} ne '') {
1103: $designs{'font'} = $designhash{$dom.'.login.font'};
1104: $is_custom{'font'} = 1;
1105: }
1106: foreach my $item (@images) {
1107: if ($designhash{$dom.'.login.'.$item} ne '') {
1108: $designs{$item} = $designhash{$dom.'.login.'.$item};
1109: $is_custom{$item} = 1;
1110: }
1111: }
1112: foreach my $item (@bgs) {
1113: if ($designhash{$dom.'.login.'.$item} ne '') {
1114: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1115: $is_custom{$item} = 1;
1116: }
1117: }
1118: foreach my $item (@links) {
1119: if ($designhash{$dom.'.login.'.$item} ne '') {
1120: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1121: $is_custom{$item} = 1;
1122: }
1.6 raeburn 1123: }
1124: }
1.160.6.5 raeburn 1125: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1126: logo => 'Institution Logo',
1127: domlogo => 'Domain Logo',
1128: login => 'Login box');
1129: my $itemcount = 1;
1130: foreach my $item (@toggles) {
1131: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1132: $datatable .=
1133: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1134: '</td><td>'.
1135: '<span class="LC_nobreak"><label><input type="radio" name="'.
1136: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1137: '</label> <label><input type="radio" name="'.$item.'"'.
1138: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1139: '</tr>';
1140: $itemcount ++;
1.6 raeburn 1141: }
1.160.6.5 raeburn 1142: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1143: $datatable .= '</tr></table></td></tr>';
1144: } elsif ($caller eq 'help') {
1145: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1146: my $switchserver = &check_switchserver($dom,$confname);
1147: my $itemcount = 1;
1148: $defaulturl = '/adm/loginproblems.html';
1149: $defaulttype = 'default';
1150: %lt = &Apache::lonlocal::texthash (
1151: del => 'Delete?',
1152: rep => 'Replace:',
1153: upl => 'Upload:',
1154: default => 'Default',
1155: custom => 'Custom',
1156: );
1157: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1158: my @currlangs;
1159: if (ref($settings) eq 'HASH') {
1160: if (ref($settings->{'helpurl'}) eq 'HASH') {
1161: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1162: next if ($settings->{'helpurl'}{$key} eq '');
1163: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1164: $type{$key} = 'custom';
1165: unless ($key eq 'nolang') {
1166: push(@currlangs,$key);
1167: }
1168: }
1169: } elsif ($settings->{'helpurl'} ne '') {
1170: $type{'nolang'} = 'custom';
1171: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1172: }
1173: }
1.160.6.5 raeburn 1174: foreach my $lang ('nolang',sort(@currlangs)) {
1175: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1176: $datatable .= '<tr'.$css_class.'>';
1177: if ($url{$lang} eq '') {
1178: $url{$lang} = $defaulturl;
1179: }
1180: if ($type{$lang} eq '') {
1181: $type{$lang} = $defaulttype;
1182: }
1183: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1184: if ($lang eq 'nolang') {
1185: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1186: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1187: } else {
1188: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1189: $langchoices{$lang},
1190: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1191: }
1192: $datatable .= '</span></td>'."\n".
1193: '<td class="LC_left_item">';
1194: if ($type{$lang} eq 'custom') {
1195: $datatable .= '<span class="LC_nobreak"><label>'.
1196: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1197: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1198: } else {
1199: $datatable .= $lt{'upl'};
1200: }
1201: $datatable .='<br />';
1202: if ($switchserver) {
1203: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1204: } else {
1205: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1206: }
1.160.6.5 raeburn 1207: $datatable .= '</td></tr>';
1208: $itemcount ++;
1.6 raeburn 1209: }
1.160.6.5 raeburn 1210: my @addlangs;
1211: foreach my $lang (sort(keys(%langchoices))) {
1212: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1213: push(@addlangs,$lang);
1214: }
1215: if (@addlangs > 0) {
1216: my %toadd;
1217: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1218: $toadd{''} = &mt('Select');
1219: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1220: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1221: &mt('Add log-in help page for a specific language:').' '.
1222: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1223: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1224: if ($switchserver) {
1225: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1226: } else {
1227: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1228: }
1.160.6.5 raeburn 1229: $datatable .= '</td></tr>';
1230: $itemcount ++;
1.6 raeburn 1231: }
1.160.6.5 raeburn 1232: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1233: } elsif ($caller eq 'headtag') {
1234: my %domservers = &Apache::lonnet::get_servers($dom);
1235: my $choice = $choices{'headtag'};
1236: $css_class = ' class="LC_odd_row"';
1237: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1238: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1239: '<th>'.$choices{'current'}.'</th>'.
1240: '<th>'.$choices{'action'}.'</th>'.
1241: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1242: my (%currurls,%currexempt);
1243: if (ref($settings) eq 'HASH') {
1244: if (ref($settings->{'headtag'}) eq 'HASH') {
1245: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1246: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1247: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1248: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1249: }
1250: }
1251: }
1252: }
1253: my %lt = &Apache::lonlocal::texthash(
1254: del => 'Delete?',
1255: rep => 'Replace:',
1256: upl => 'Upload:',
1257: curr => 'View contents',
1258: none => 'None',
1259: );
1260: my $switchserver = &check_switchserver($dom,$confname);
1261: foreach my $lonhost (sort(keys(%domservers))) {
1262: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1263: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1264: if ($currurls{$lonhost}) {
1265: $datatable .= '<td class="LC_right_item"><a href="'.
1266: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1267: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1268: '">'.$lt{'curr'}.'</a></td>'.
1269: '<td><span class="LC_nobreak"><label>'.
1270: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1271: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1272: } else {
1273: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1274: }
1275: $datatable .='<br />';
1276: if ($switchserver) {
1277: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1278: } else {
1279: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1280: }
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.'"'.
1.160.6.81! raeburn 3730: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 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 {
1.160.6.81! raeburn 9046: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 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>';
1.160.6.81! raeburn 9240: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
! 9241: if (ref($lastactref) eq 'HASH') {
! 9242: $lastactref->{'directorysrch'} = 1;
! 9243: }
1.23 raeburn 9244: } else {
1.160.6.72 raeburn 9245: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9246: }
9247: } else {
9248: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9249: &mt('An error occurred: [_1]',$putresult).'</span>';
9250: }
9251: return $resulttext;
9252: }
9253:
1.28 raeburn 9254: sub modify_contacts {
1.160.6.24 raeburn 9255: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9256: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9257: if (ref($domconfig{'contacts'}) eq 'HASH') {
9258: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9259: $currsetting{$key} = $domconfig{'contacts'}{$key};
9260: }
9261: }
1.160.6.78 raeburn 9262: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 9263: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 9264: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
9265: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.160.6.23 raeburn 9266: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 9267: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 9268: foreach my $type (@mailings) {
9269: @{$newsetting{$type}} =
9270: &Apache::loncommon::get_env_multiple('form.'.$type);
9271: foreach my $item (@contacts) {
9272: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9273: $contacts_hash{contacts}{$type}{$item} = 1;
9274: } else {
9275: $contacts_hash{contacts}{$type}{$item} = 0;
9276: }
1.160.6.78 raeburn 9277: }
1.28 raeburn 9278: $others{$type} = $env{'form.'.$type.'_others'};
9279: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 9280: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9281: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9282: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 9283: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
9284: $includestr{$type} = $env{'form.'.$type.'_includestr'};
9285: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
9286: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
9287: }
1.134 raeburn 9288: }
1.28 raeburn 9289: }
9290: foreach my $item (@contacts) {
9291: $to{$item} = $env{'form.'.$item};
9292: $contacts_hash{'contacts'}{$item} = $to{$item};
9293: }
1.160.6.23 raeburn 9294: foreach my $item (@toggles) {
9295: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9296: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9297: }
9298: }
1.160.6.78 raeburn 9299: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
9300: foreach my $field (@{$fields}) {
9301: if (ref($possoptions->{$field}) eq 'ARRAY') {
9302: my $value = $env{'form.helpform_'.$field};
9303: $value =~ s/^\s+|\s+$//g;
9304: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
9305: $contacts_hash{contacts}{'helpform'}{$field} = $value;
9306: if ($field eq 'screenshot') {
9307: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
9308: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
9309: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
9310: }
9311: }
9312: }
9313: }
9314: }
9315: }
1.28 raeburn 9316: if (keys(%currsetting) > 0) {
9317: foreach my $item (@contacts) {
9318: if ($to{$item} ne $currsetting{$item}) {
9319: $changes{$item} = 1;
9320: }
9321: }
9322: foreach my $type (@mailings) {
9323: foreach my $item (@contacts) {
9324: if (ref($currsetting{$type}) eq 'HASH') {
9325: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9326: push(@{$changes{$type}},$item);
9327: }
9328: } else {
9329: push(@{$changes{$type}},@{$newsetting{$type}});
9330: }
9331: }
9332: if ($others{$type} ne $currsetting{$type}{'others'}) {
9333: push(@{$changes{$type}},'others');
9334: }
1.160.6.78 raeburn 9335: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9336: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9337: push(@{$changes{$type}},'bcc');
9338: }
1.160.6.78 raeburn 9339: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
9340: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
9341: push(@{$changes{$type}},'include');
9342: }
9343: }
9344: }
9345: if (ref($fields) eq 'ARRAY') {
9346: if (ref($currsetting{'helpform'}) eq 'HASH') {
9347: foreach my $field (@{$fields}) {
9348: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
9349: push(@{$changes{'helpform'}},$field);
9350: }
9351: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9352: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
9353: push(@{$changes{'helpform'}},'maxsize');
9354: }
9355: }
9356: }
9357: } else {
9358: foreach my $field (@{$fields}) {
9359: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9360: push(@{$changes{'helpform'}},$field);
9361: }
9362: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9363: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9364: push(@{$changes{'helpform'}},'maxsize');
9365: }
9366: }
9367: }
1.134 raeburn 9368: }
1.28 raeburn 9369: }
9370: } else {
9371: my %default;
9372: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9373: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9374: $default{'errormail'} = 'adminemail';
9375: $default{'packagesmail'} = 'adminemail';
9376: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 9377: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 9378: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9379: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 9380: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9381: foreach my $item (@contacts) {
9382: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 9383: $changes{$item} = 1;
1.160.6.23 raeburn 9384: }
1.28 raeburn 9385: }
9386: foreach my $type (@mailings) {
9387: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9388: push(@{$changes{$type}},@{$newsetting{$type}});
9389: }
9390: if ($others{$type} ne '') {
9391: push(@{$changes{$type}},'others');
1.134 raeburn 9392: }
1.160.6.78 raeburn 9393: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9394: if ($bcc{$type} ne '') {
9395: push(@{$changes{$type}},'bcc');
9396: }
1.160.6.78 raeburn 9397: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
9398: push(@{$changes{$type}},'include');
9399: }
9400: }
9401: }
9402: if (ref($fields) eq 'ARRAY') {
9403: foreach my $field (@{$fields}) {
9404: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9405: push(@{$changes{'helpform'}},$field);
9406: }
9407: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9408: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9409: push(@{$changes{'helpform'}},'maxsize');
9410: }
9411: }
1.134 raeburn 9412: }
1.28 raeburn 9413: }
9414: }
1.160.6.23 raeburn 9415: foreach my $item (@toggles) {
9416: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9417: $changes{$item} = 1;
9418: } elsif ((!$env{'form.'.$item}) &&
9419: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9420: $changes{$item} = 1;
9421: }
9422: }
1.28 raeburn 9423: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9424: $dom);
9425: if ($putresult eq 'ok') {
9426: if (keys(%changes) > 0) {
1.160.6.24 raeburn 9427: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9428: if (ref($lastactref) eq 'HASH') {
9429: $lastactref->{'domainconfig'} = 1;
9430: }
1.28 raeburn 9431: my ($titles,$short_titles) = &contact_titles();
9432: $resulttext = &mt('Changes made:').'<ul>';
9433: foreach my $item (@contacts) {
9434: if ($changes{$item}) {
9435: $resulttext .= '<li>'.$titles->{$item}.
9436: &mt(' set to: ').
9437: '<span class="LC_cusr_emph">'.
9438: $to{$item}.'</span></li>';
9439: }
9440: }
9441: foreach my $type (@mailings) {
9442: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 9443: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
9444: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
9445: } else {
9446: $resulttext .= '<li>'.$titles->{$type}.': ';
9447: }
1.28 raeburn 9448: my @text;
9449: foreach my $item (@{$newsetting{$type}}) {
9450: push(@text,$short_titles->{$item});
9451: }
9452: if ($others{$type} ne '') {
9453: push(@text,$others{$type});
9454: }
1.160.6.78 raeburn 9455: if (@text) {
9456: $resulttext .= '<span class="LC_cusr_emph">'.
9457: join(', ',@text).'</span>';
9458: }
9459: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9460: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 9461: my $bcctext;
9462: if (@text) {
9463: $bcctext = ' '.&mt('with Bcc to');
9464: } else {
9465: $bcctext = '(Bcc)';
9466: }
9467: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9468: } elsif (!@text) {
9469: $resulttext .= &mt('No one');
1.134 raeburn 9470: }
1.160.6.78 raeburn 9471: if ($includestr{$type} ne '') {
9472: if ($includeloc{$type} eq 'b') {
9473: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
9474: } elsif ($includeloc{$type} eq 's') {
9475: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
9476: }
9477: }
9478: } elsif (!@text) {
9479: $resulttext .= &mt('No recipients');
1.134 raeburn 9480: }
9481: $resulttext .= '</li>';
1.28 raeburn 9482: }
9483: }
1.160.6.23 raeburn 9484: my @offon = ('off','on');
9485: if ($changes{'reporterrors'}) {
9486: $resulttext .= '<li>'.
9487: &mt('E-mail error reports to [_1] set to "'.
9488: $offon[$env{'form.reporterrors'}].'".',
9489: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9490: &mt('LON-CAPA core group - MSU'),600,500)).
9491: '</li>';
9492: }
9493: if ($changes{'reportupdates'}) {
9494: $resulttext .= '<li>'.
9495: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9496: $offon[$env{'form.reportupdates'}].'".',
9497: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9498: &mt('LON-CAPA core group - MSU'),600,500)).
9499: '</li>';
9500: }
1.160.6.78 raeburn 9501: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
9502: my (@optional,@required,@unused,$maxsizechg);
9503: foreach my $field (@{$changes{'helpform'}}) {
9504: if ($field eq 'maxsize') {
9505: $maxsizechg = 1;
9506: next;
9507: }
9508: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
9509: push(@optional,$field);
9510: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
9511: push(@unused,$field);
9512: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
9513: push(@required,$field);
9514: }
9515: }
9516: if (@optional) {
9517: $resulttext .= '<li>'.
9518: &mt('Help form fields changed to "Optional": [_1].',
9519: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
9520: '</li>';
9521: }
9522: if (@required) {
9523: $resulttext .= '<li>'.
9524: &mt('Help form fields changed to "Required": [_1].',
9525: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
9526: '</li>';
9527: }
9528: if (@unused) {
9529: $resulttext .= '<li>'.
9530: &mt('Help form fields changed to "Not shown": [_1].',
9531: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
9532: '</li>';
9533: }
9534: if ($maxsizechg) {
9535: $resulttext .= '<li>'.
9536: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
9537: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
9538: '</li>';
9539:
9540: }
9541: }
1.28 raeburn 9542: $resulttext .= '</ul>';
9543: } else {
1.160.6.78 raeburn 9544: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 9545: }
9546: } else {
9547: $resulttext = '<span class="LC_error">'.
9548: &mt('An error occurred: [_1].',$putresult).'</span>';
9549: }
9550: return $resulttext;
9551: }
9552:
9553: sub modify_usercreation {
1.27 raeburn 9554: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9555: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9556: my $warningmsg;
1.27 raeburn 9557: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9558: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 9559: if ($key eq 'cancreate') {
9560: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9561: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9562: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 9563: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9564: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 9565: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9566: } else {
9567: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9568: }
1.50 raeburn 9569: }
1.43 raeburn 9570: }
1.160.6.34 raeburn 9571: } elsif ($key eq 'email_rule') {
9572: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9573: } else {
9574: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 9575: }
9576: }
1.34 raeburn 9577: }
1.160.6.34 raeburn 9578: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
9579: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
9580: my @contexts = ('author','course','requestcrs');
9581: foreach my $item(@contexts) {
9582: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9583: }
1.34 raeburn 9584: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9585: foreach my $item (@contexts) {
1.160.6.34 raeburn 9586: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9587: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9588: }
1.27 raeburn 9589: }
1.34 raeburn 9590: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9591: foreach my $item (@contexts) {
1.43 raeburn 9592: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9593: if ($cancreate{$item} ne 'any') {
9594: push(@{$changes{'cancreate'}},$item);
9595: }
9596: } else {
9597: if ($cancreate{$item} ne 'none') {
9598: push(@{$changes{'cancreate'}},$item);
9599: }
1.27 raeburn 9600: }
9601: }
9602: } else {
1.43 raeburn 9603: foreach my $item (@contexts) {
1.34 raeburn 9604: push(@{$changes{'cancreate'}},$item);
9605: }
1.27 raeburn 9606: }
1.34 raeburn 9607:
1.27 raeburn 9608: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9609: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9610: if (!grep(/^\Q$type\E$/,@username_rule)) {
9611: push(@{$changes{'username_rule'}},$type);
9612: }
9613: }
9614: foreach my $type (@username_rule) {
9615: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9616: push(@{$changes{'username_rule'}},$type);
9617: }
9618: }
9619: } else {
9620: push(@{$changes{'username_rule'}},@username_rule);
9621: }
9622:
1.32 raeburn 9623: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9624: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9625: if (!grep(/^\Q$type\E$/,@id_rule)) {
9626: push(@{$changes{'id_rule'}},$type);
9627: }
9628: }
9629: foreach my $type (@id_rule) {
9630: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9631: push(@{$changes{'id_rule'}},$type);
9632: }
9633: }
9634: } else {
9635: push(@{$changes{'id_rule'}},@id_rule);
9636: }
9637:
1.43 raeburn 9638: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9639: my @authtypes = ('int','krb4','krb5','loc');
9640: my %authhash;
1.43 raeburn 9641: foreach my $item (@authen_contexts) {
1.28 raeburn 9642: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9643: foreach my $auth (@authtypes) {
9644: if (grep(/^\Q$auth\E$/,@authallowed)) {
9645: $authhash{$item}{$auth} = 1;
9646: } else {
9647: $authhash{$item}{$auth} = 0;
9648: }
9649: }
9650: }
9651: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9652: foreach my $item (@authen_contexts) {
1.28 raeburn 9653: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
9654: foreach my $auth (@authtypes) {
9655: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
9656: push(@{$changes{'authtypes'}},$item);
9657: last;
9658: }
9659: }
9660: }
9661: }
9662: } else {
1.43 raeburn 9663: foreach my $item (@authen_contexts) {
1.28 raeburn 9664: push(@{$changes{'authtypes'}},$item);
9665: }
9666: }
9667:
1.160.6.34 raeburn 9668: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
9669: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
9670: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
9671: $save_usercreate{'id_rule'} = \@id_rule;
9672: $save_usercreate{'username_rule'} = \@username_rule,
9673: $save_usercreate{'authtypes'} = \%authhash;
9674:
1.27 raeburn 9675: my %usercreation_hash = (
1.160.6.34 raeburn 9676: usercreation => \%save_usercreate,
9677: );
1.27 raeburn 9678:
9679: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
9680: $dom);
1.50 raeburn 9681:
1.160.6.34 raeburn 9682: if ($putresult eq 'ok') {
9683: if (keys(%changes) > 0) {
9684: $resulttext = &mt('Changes made:').'<ul>';
9685: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9686: my %lt = &usercreation_types();
9687: foreach my $type (@{$changes{'cancreate'}}) {
9688: my $chgtext = $lt{$type}.', ';
9689: if ($cancreate{$type} eq 'none') {
9690: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
9691: } elsif ($cancreate{$type} eq 'any') {
9692: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
9693: } elsif ($cancreate{$type} eq 'official') {
9694: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
9695: } elsif ($cancreate{$type} eq 'unofficial') {
9696: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
9697: }
9698: $resulttext .= '<li>'.$chgtext.'</li>';
9699: }
9700: }
9701: if (ref($changes{'username_rule'}) eq 'ARRAY') {
9702: my ($rules,$ruleorder) =
9703: &Apache::lonnet::inst_userrules($dom,'username');
9704: my $chgtext = '<ul>';
9705: foreach my $type (@username_rule) {
9706: if (ref($rules->{$type}) eq 'HASH') {
9707: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
9708: }
9709: }
9710: $chgtext .= '</ul>';
9711: if (@username_rule > 0) {
9712: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9713: } else {
9714: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
9715: }
9716: }
9717: if (ref($changes{'id_rule'}) eq 'ARRAY') {
9718: my ($idrules,$idruleorder) =
9719: &Apache::lonnet::inst_userrules($dom,'id');
9720: my $chgtext = '<ul>';
9721: foreach my $type (@id_rule) {
9722: if (ref($idrules->{$type}) eq 'HASH') {
9723: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
9724: }
9725: }
9726: $chgtext .= '</ul>';
9727: if (@id_rule > 0) {
9728: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9729: } else {
9730: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
9731: }
9732: }
9733: my %authname = &authtype_names();
9734: my %context_title = &context_names();
9735: if (ref($changes{'authtypes'}) eq 'ARRAY') {
9736: my $chgtext = '<ul>';
9737: foreach my $type (@{$changes{'authtypes'}}) {
9738: my @allowed;
9739: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
9740: foreach my $auth (@authtypes) {
9741: if ($authhash{$type}{$auth}) {
9742: push(@allowed,$authname{$auth});
9743: }
9744: }
9745: if (@allowed > 0) {
9746: $chgtext .= join(', ',@allowed).'</li>';
9747: } else {
9748: $chgtext .= &mt('none').'</li>';
9749: }
9750: }
9751: $chgtext .= '</ul>';
9752: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
9753: $resulttext .= '</li>';
9754: }
9755: $resulttext .= '</ul>';
9756: } else {
9757: $resulttext = &mt('No changes made to user creation settings');
9758: }
9759: } else {
9760: $resulttext = '<span class="LC_error">'.
9761: &mt('An error occurred: [_1]',$putresult).'</span>';
9762: }
9763: if ($warningmsg ne '') {
9764: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9765: }
9766: return $resulttext;
9767: }
9768:
9769: sub modify_selfcreation {
9770: my ($dom,%domconfig) = @_;
9771: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
9772: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 9773: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9774: if (ref($types) eq 'ARRAY') {
9775: $usertypes->{'default'} = $othertitle;
9776: push(@{$types},'default');
9777: }
1.160.6.34 raeburn 9778: #
9779: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
9780: #
9781: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9782: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9783: if ($key eq 'cancreate') {
9784: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9785: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9786: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9787: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 9788: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 9789: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 9790: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 9791: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9792: } else {
9793: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9794: }
9795: }
9796: }
9797: } elsif ($key eq 'email_rule') {
9798: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9799: } else {
9800: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9801: }
9802: }
9803: }
9804: #
9805: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
9806: #
9807: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9808: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9809: if ($key eq 'selfcreate') {
9810: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
9811: } else {
9812: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
9813: }
9814: }
9815: }
9816:
9817: my @contexts = ('selfcreate');
9818: @{$cancreate{'selfcreate'}} = ();
9819: %{$cancreate{'emailusername'}} = ();
9820: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 9821: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 9822: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 9823: my %selfcreatetypes = (
9824: sso => 'users authenticated by institutional single sign on',
9825: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 9826: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 9827: );
1.160.6.34 raeburn 9828: #
9829: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
9830: # is permitted.
9831: #
1.160.6.40 raeburn 9832:
9833: my @statuses;
9834: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9835: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
9836: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
9837: }
9838: }
9839: push(@statuses,'default');
9840:
1.160.6.35 raeburn 9841: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 9842: if ($item eq 'email') {
1.160.6.40 raeburn 9843: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 9844: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 9845: push(@contexts,'selfcreateprocessing');
9846: foreach my $type (@statuses) {
9847: if ($type eq 'default') {
9848: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
9849: } else {
9850: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
9851: }
9852: }
1.160.6.34 raeburn 9853: }
9854: } else {
9855: if ($env{'form.cancreate_'.$item}) {
9856: push(@{$cancreate{'selfcreate'}},$item);
9857: }
9858: }
9859: }
9860: my (@email_rule,%userinfo,%savecaptcha);
9861: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9862: #
1.160.6.35 raeburn 9863: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9864: # 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 9865: #
1.160.6.40 raeburn 9866:
1.160.6.48 raeburn 9867: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 9868: push(@contexts,'emailusername');
1.160.6.35 raeburn 9869: if (ref($types) eq 'ARRAY') {
9870: foreach my $type (@{$types}) {
9871: if (ref($infofields) eq 'ARRAY') {
9872: foreach my $field (@{$infofields}) {
9873: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9874: $cancreate{'emailusername'}{$type}{$field} = $1;
9875: }
9876: }
1.160.6.34 raeburn 9877: }
9878: }
9879: }
9880: #
9881: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9882: # queued requests for self-creation of account using e-mail address as username
9883: #
9884:
9885: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9886: @approvalnotify = sort(@approvalnotify);
9887: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9888: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9889: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9890: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9891: push(@{$changes{'cancreate'}},'notify');
9892: }
9893: } else {
9894: if ($cancreate{'notify'}{'approval'}) {
9895: push(@{$changes{'cancreate'}},'notify');
9896: }
9897: }
9898: } elsif ($cancreate{'notify'}{'approval'}) {
9899: push(@{$changes{'cancreate'}},'notify');
9900: }
9901:
9902: #
9903: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9904: #
9905: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9906: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9907: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9908: if (@{$curr_usercreation{'email_rule'}} > 0) {
9909: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9910: if (!grep(/^\Q$type\E$/,@email_rule)) {
9911: push(@{$changes{'email_rule'}},$type);
9912: }
9913: }
9914: }
9915: if (@email_rule > 0) {
9916: foreach my $type (@email_rule) {
9917: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9918: push(@{$changes{'email_rule'}},$type);
9919: }
9920: }
9921: }
9922: } elsif (@email_rule > 0) {
9923: push(@{$changes{'email_rule'}},@email_rule);
9924: }
9925: }
9926: #
1.160.6.40 raeburn 9927: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 9928: # institutional log-in.
9929: #
9930: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9931: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9932: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
9933: ($domdefaults{'auth_def'} eq 'localauth'))) {
9934: $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.').' '.
9935: &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.');
9936: }
9937: }
9938: my @fields = ('lastname','firstname','middlename','generation',
9939: 'permanentemail','id');
1.160.6.44 raeburn 9940: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 9941: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9942: #
9943: # Where usernames may created for institutional log-in and/or institutional single sign on:
9944: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9945: # may self-create accounts
9946: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
9947: # which the user may supply, if institutional data is unavailable.
9948: #
9949: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
9950: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 9951: if (@{$types} > 1) {
1.160.6.34 raeburn 9952: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
9953: push(@contexts,'statustocreate');
9954: } else {
9955: undef($cancreate{'statustocreate'});
9956: }
9957: foreach my $type (@{$types}) {
9958: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
9959: foreach my $field (@fields) {
9960: if (grep(/^\Q$field\E$/,@modifiable)) {
9961: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9962: } else {
9963: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9964: }
9965: }
9966: }
9967: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9968: foreach my $type (@{$types}) {
9969: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9970: foreach my $field (@fields) {
9971: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9972: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9973: push(@{$changes{'selfcreate'}},$type);
9974: last;
9975: }
9976: }
9977: }
9978: }
9979: } else {
9980: foreach my $type (@{$types}) {
9981: push(@{$changes{'selfcreate'}},$type);
9982: }
9983: }
9984: }
1.160.6.44 raeburn 9985: foreach my $field (@shibfields) {
9986: if ($env{'form.shibenv_'.$field} ne '') {
9987: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
9988: }
9989: }
9990: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9991: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
9992: foreach my $field (@shibfields) {
9993: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
9994: push(@{$changes{'cancreate'}},'shibenv');
9995: }
9996: }
9997: } else {
9998: foreach my $field (@shibfields) {
9999: if ($env{'form.shibenv_'.$field}) {
10000: push(@{$changes{'cancreate'}},'shibenv');
10001: last;
10002: }
10003: }
10004: }
10005: }
1.160.6.34 raeburn 10006: }
10007: foreach my $item (@contexts) {
10008: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10009: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10010: if (ref($cancreate{$item}) eq 'ARRAY') {
10011: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10012: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10013: push(@{$changes{'cancreate'}},$item);
10014: }
10015: }
10016: }
10017: }
10018: if (ref($cancreate{$item}) eq 'ARRAY') {
10019: foreach my $type (@{$cancreate{$item}}) {
10020: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10021: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10022: push(@{$changes{'cancreate'}},$item);
10023: }
10024: }
10025: }
10026: }
10027: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10028: if (ref($cancreate{$item}) eq 'HASH') {
10029: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 10030: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10031: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10032: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10033: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10034: push(@{$changes{'cancreate'}},$item);
10035: }
10036: }
10037: }
1.160.6.40 raeburn 10038: } elsif ($item eq 'selfcreateprocessing') {
10039: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10040: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10041: push(@{$changes{'cancreate'}},$item);
10042: }
10043: }
1.160.6.35 raeburn 10044: } else {
10045: if (!$cancreate{$item}{$curr}) {
10046: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10047: push(@{$changes{'cancreate'}},$item);
10048: }
1.160.6.34 raeburn 10049: }
10050: }
10051: }
10052: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 10053: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10054: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10055: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10056: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10057: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10058: push(@{$changes{'cancreate'}},$item);
10059: }
10060: }
10061: } else {
10062: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10063: push(@{$changes{'cancreate'}},$item);
10064: }
10065: }
10066: }
1.160.6.40 raeburn 10067: } elsif ($item eq 'selfcreateprocessing') {
10068: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10069: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10070: push(@{$changes{'cancreate'}},$item);
10071: }
10072: }
1.160.6.35 raeburn 10073: } else {
10074: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10075: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10076: push(@{$changes{'cancreate'}},$item);
10077: }
1.160.6.34 raeburn 10078: }
10079: }
10080: }
10081: }
10082: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10083: if (ref($cancreate{$item}) eq 'ARRAY') {
10084: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10085: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10086: push(@{$changes{'cancreate'}},$item);
10087: }
10088: }
10089: } elsif (ref($cancreate{$item}) eq 'HASH') {
10090: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10091: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10092: push(@{$changes{'cancreate'}},$item);
10093: }
10094: }
10095: }
10096: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 10097: if (ref($cancreate{$item}) eq 'HASH') {
10098: foreach my $type (keys(%{$cancreate{$item}})) {
10099: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10100: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10101: if ($cancreate{$item}{$type}{$field}) {
10102: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10103: push(@{$changes{'cancreate'}},$item);
10104: }
10105: last;
10106: }
10107: }
10108: }
10109: }
1.160.6.34 raeburn 10110: }
10111: }
10112: }
10113: #
10114: # Populate %save_usercreate hash with updates to self-creation configuration.
10115: #
10116: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10117: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 10118: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 10119: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10120: if (ref($cancreate{'notify'}) eq 'HASH') {
10121: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10122: }
1.160.6.40 raeburn 10123: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10124: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10125: }
1.160.6.34 raeburn 10126: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10127: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10128: }
1.160.6.44 raeburn 10129: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10130: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10131: }
1.160.6.34 raeburn 10132: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
10133: $save_usercreate{'emailrule'} = \@email_rule;
10134:
10135: my %userconfig_hash = (
10136: usercreation => \%save_usercreate,
10137: usermodification => \%save_usermodify,
10138: );
10139: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10140: $dom);
10141: #
10142: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10143: #
1.27 raeburn 10144: if ($putresult eq 'ok') {
10145: if (keys(%changes) > 0) {
10146: $resulttext = &mt('Changes made:').'<ul>';
10147: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 10148: my %lt = &selfcreation_types();
1.34 raeburn 10149: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10150: my $chgtext;
1.45 raeburn 10151: if ($type eq 'selfcreate') {
1.50 raeburn 10152: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 10153: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10154: } else {
1.160.6.34 raeburn 10155: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10156: '<ul>';
1.50 raeburn 10157: foreach my $case (@{$cancreate{$type}}) {
10158: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10159: }
10160: $chgtext .= '</ul>';
1.100 raeburn 10161: if (ref($cancreate{$type}) eq 'ARRAY') {
10162: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10163: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10164: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 10165: $chgtext .= '<br />'.
10166: '<span class="LC_warning">'.
10167: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10168: '</span>';
1.100 raeburn 10169: }
10170: }
10171: }
10172: }
1.43 raeburn 10173: }
1.160.6.44 raeburn 10174: } elsif ($type eq 'shibenv') {
10175: if (keys(%{$cancreate{$type}}) == 0) {
10176: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10177: } else {
10178: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10179: '<ul>';
10180: foreach my $field (@shibfields) {
10181: next if ($cancreate{$type}{$field} eq '');
10182: if ($field eq 'inststatus') {
10183: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10184: } else {
10185: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10186: }
10187: }
10188: $chgtext .= '</ul>';
10189: }
1.93 raeburn 10190: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10191: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10192: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10193: if (@{$cancreate{'selfcreate'}} > 0) {
10194: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10195: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10196: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10197: $chgtext .= '<br />'.
10198: '<span class="LC_warning">'.
10199: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10200: '</span>';
10201: }
1.96 raeburn 10202: } elsif (ref($usertypes) eq 'HASH') {
10203: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10204: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10205: } else {
10206: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10207: }
10208: $chgtext .= '<ul>';
10209: foreach my $case (@{$cancreate{$type}}) {
10210: if ($case eq 'default') {
10211: $chgtext .= '<li>'.$othertitle.'</li>';
10212: } else {
10213: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10214: }
10215: }
1.100 raeburn 10216: $chgtext .= '</ul>';
10217: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10218: $chgtext .= '<br /><span class="LC_warning">'.
10219: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10220: '</span>';
1.100 raeburn 10221: }
10222: }
10223: } else {
10224: if (@{$cancreate{$type}} == 0) {
10225: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10226: } else {
10227: $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 10228: }
10229: }
10230: }
1.160.6.40 raeburn 10231: } elsif ($type eq 'selfcreateprocessing') {
10232: my %choices = &Apache::lonlocal::texthash (
10233: automatic => 'Automatic approval',
10234: approval => 'Queued for approval',
10235: );
10236: if (@statuses > 1) {
10237: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10238: '<ul>';
10239: foreach my $type (@statuses) {
10240: if ($type eq 'default') {
10241: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10242: } else {
10243: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10244: }
10245: }
10246: $chgtext .= '</ul>';
10247: } else {
10248: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10249: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10250: }
1.160.6.5 raeburn 10251: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 10252: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 10253: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10254: } else {
10255: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 10256: if ($captchas{$savecaptcha{$type}}) {
10257: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 10258: } else {
10259: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
10260: }
10261: }
10262: } elsif ($type eq 'recaptchakeys') {
10263: my ($privkey,$pubkey);
1.160.6.34 raeburn 10264: if (ref($savecaptcha{$type}) eq 'HASH') {
10265: $pubkey = $savecaptcha{$type}{'public'};
10266: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 10267: }
10268: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10269: if (!$pubkey) {
10270: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10271: } else {
10272: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10273: }
10274: if (!$privkey) {
10275: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10276: } else {
10277: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10278: }
10279: $chgtext .= '</ul>';
1.160.6.69 raeburn 10280: } elsif ($type eq 'recaptchaversion') {
10281: if ($savecaptcha{'captcha'} eq 'recaptcha') {
10282: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
10283: }
1.160.6.34 raeburn 10284: } elsif ($type eq 'emailusername') {
10285: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 10286: if (ref($types) eq 'ARRAY') {
10287: foreach my $type (@{$types}) {
10288: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10289: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 10290: $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 10291: '<ul>';
10292: foreach my $field (@{$infofields}) {
10293: if ($cancreate{'emailusername'}{$type}{$field}) {
10294: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10295: }
10296: }
1.160.6.50 raeburn 10297: $chgtext .= '</ul>';
10298: } else {
10299: $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 10300: }
10301: } else {
1.160.6.50 raeburn 10302: $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 10303: }
10304: }
10305: }
10306: }
10307: } elsif ($type eq 'notify') {
10308: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10309: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10310: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10311: if ($cancreate{'notify'}{'approval'}) {
10312: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10313: }
10314: }
1.43 raeburn 10315: }
1.34 raeburn 10316: }
1.160.6.34 raeburn 10317: if ($chgtext) {
10318: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10319: }
10320: }
10321: }
1.43 raeburn 10322: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10323: my ($emailrules,$emailruleorder) =
10324: &Apache::lonnet::inst_userrules($dom,'email');
10325: my $chgtext = '<ul>';
10326: foreach my $type (@email_rule) {
10327: if (ref($emailrules->{$type}) eq 'HASH') {
10328: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10329: }
10330: }
10331: $chgtext .= '</ul>';
10332: if (@email_rule > 0) {
1.160.6.34 raeburn 10333: $resulttext .= '<li>'.
10334: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10335: $chgtext.
10336: '</li>';
1.43 raeburn 10337: } else {
1.160.6.34 raeburn 10338: $resulttext .= '<li>'.
10339: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10340: '</li>';
1.43 raeburn 10341: }
10342: }
1.160.6.34 raeburn 10343: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10344: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10345: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10346: foreach my $type (@{$changes{'selfcreate'}}) {
10347: my $typename = $type;
10348: if (ref($usertypes) eq 'HASH') {
10349: if ($usertypes->{$type} ne '') {
10350: $typename = $usertypes->{$type};
1.28 raeburn 10351: }
10352: }
1.160.6.34 raeburn 10353: my @modifiable;
10354: $resulttext .= '<li>'.
10355: &mt('Self-creation of account by users with status: [_1]',
10356: '<span class="LC_cusr_emph">'.$typename.'</span>').
10357: ' - '.&mt('modifiable fields (if institutional data blank): ');
10358: foreach my $field (@fields) {
10359: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10360: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
10361: }
10362: }
10363: if (@modifiable > 0) {
10364: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10365: } else {
1.160.6.34 raeburn 10366: $resulttext .= &mt('none');
1.43 raeburn 10367: }
1.160.6.34 raeburn 10368: $resulttext .= '</li>';
1.28 raeburn 10369: }
1.160.6.34 raeburn 10370: $resulttext .= '</ul></li>';
1.28 raeburn 10371: }
1.27 raeburn 10372: $resulttext .= '</ul>';
10373: } else {
1.160.6.34 raeburn 10374: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10375: }
10376: } else {
10377: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10378: &mt('An error occurred: [_1]',$putresult).'</span>';
10379: }
1.43 raeburn 10380: if ($warningmsg ne '') {
10381: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10382: }
1.23 raeburn 10383: return $resulttext;
10384: }
10385:
1.160.6.5 raeburn 10386: sub process_captcha {
10387: my ($container,$changes,$newsettings,$current) = @_;
10388: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10389: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10390: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10391: $newsettings->{'captcha'} = 'original';
10392: }
10393: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
10394: if ($container eq 'cancreate') {
10395: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10396: push(@{$changes->{'cancreate'}},'captcha');
10397: } elsif (!defined($changes->{'cancreate'})) {
10398: $changes->{'cancreate'} = ['captcha'];
10399: }
10400: } else {
10401: $changes->{'captcha'} = 1;
10402: }
10403: }
1.160.6.69 raeburn 10404: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 10405: if ($newsettings->{'captcha'} eq 'recaptcha') {
10406: $newpub = $env{'form.'.$container.'_recaptchapub'};
10407: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 10408: $newpub =~ s/[^\w\-]//g;
10409: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 10410: $newsettings->{'recaptchakeys'} = {
10411: public => $newpub,
10412: private => $newpriv,
10413: };
1.160.6.69 raeburn 10414: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10415: $newversion =~ s/\D//g;
10416: if ($newversion ne '2') {
10417: $newversion = 1;
10418: }
10419: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 10420: }
10421: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10422: $currpub = $current->{'recaptchakeys'}{'public'};
10423: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 10424: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10425: $newsettings->{'recaptchakeys'} = {
10426: public => '',
10427: private => '',
10428: }
10429: }
1.160.6.5 raeburn 10430: }
1.160.6.69 raeburn 10431: if ($current->{'captcha'} eq 'recaptcha') {
10432: $currversion = $current->{'recaptchaversion'};
10433: if ($currversion ne '2') {
10434: $currversion = 1;
10435: }
10436: }
10437: if ($currversion ne $newversion) {
10438: if ($container eq 'cancreate') {
10439: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10440: push(@{$changes->{'cancreate'}},'recaptchaversion');
10441: } elsif (!defined($changes->{'cancreate'})) {
10442: $changes->{'cancreate'} = ['recaptchaversion'];
10443: }
10444: } else {
10445: $changes->{'recaptchaversion'} = 1;
10446: }
10447: }
1.160.6.5 raeburn 10448: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
10449: if ($container eq 'cancreate') {
10450: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10451: push(@{$changes->{'cancreate'}},'recaptchakeys');
10452: } elsif (!defined($changes->{'cancreate'})) {
10453: $changes->{'cancreate'} = ['recaptchakeys'];
10454: }
10455: } else {
10456: $changes->{'recaptchakeys'} = 1;
10457: }
10458: }
10459: return;
10460: }
10461:
1.33 raeburn 10462: sub modify_usermodification {
10463: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 10464: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10465: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10466: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 10467: if ($key eq 'selfcreate') {
10468: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10469: } else {
10470: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10471: }
1.33 raeburn 10472: }
10473: }
1.160.6.34 raeburn 10474: my @contexts = ('author','course');
1.33 raeburn 10475: my %context_title = (
10476: author => 'In author context',
10477: course => 'In course context',
10478: );
10479: my @fields = ('lastname','firstname','middlename','generation',
10480: 'permanentemail','id');
10481: my %roles = (
10482: author => ['ca','aa'],
10483: course => ['st','ep','ta','in','cr'],
10484: );
10485: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10486: foreach my $context (@contexts) {
10487: foreach my $role (@{$roles{$context}}) {
10488: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10489: foreach my $item (@fields) {
10490: if (grep(/^\Q$item\E$/,@modifiable)) {
10491: $modifyhash{$context}{$role}{$item} = 1;
10492: } else {
10493: $modifyhash{$context}{$role}{$item} = 0;
10494: }
10495: }
10496: }
10497: if (ref($curr_usermodification{$context}) eq 'HASH') {
10498: foreach my $role (@{$roles{$context}}) {
10499: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10500: foreach my $field (@fields) {
10501: if ($modifyhash{$context}{$role}{$field} ne
10502: $curr_usermodification{$context}{$role}{$field}) {
10503: push(@{$changes{$context}},$role);
10504: last;
10505: }
10506: }
10507: }
10508: }
10509: } else {
10510: foreach my $context (@contexts) {
10511: foreach my $role (@{$roles{$context}}) {
10512: push(@{$changes{$context}},$role);
10513: }
10514: }
10515: }
10516: }
10517: my %usermodification_hash = (
10518: usermodification => \%modifyhash,
10519: );
10520: my $putresult = &Apache::lonnet::put_dom('configuration',
10521: \%usermodification_hash,$dom);
10522: if ($putresult eq 'ok') {
10523: if (keys(%changes) > 0) {
10524: $resulttext = &mt('Changes made: ').'<ul>';
10525: foreach my $context (@contexts) {
10526: if (ref($changes{$context}) eq 'ARRAY') {
10527: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10528: if (ref($changes{$context}) eq 'ARRAY') {
10529: foreach my $role (@{$changes{$context}}) {
10530: my $rolename;
1.160.6.34 raeburn 10531: if ($role eq 'cr') {
10532: $rolename = &mt('Custom');
1.33 raeburn 10533: } else {
1.160.6.34 raeburn 10534: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10535: }
10536: my @modifiable;
1.160.6.34 raeburn 10537: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10538: foreach my $field (@fields) {
10539: if ($modifyhash{$context}{$role}{$field}) {
10540: push(@modifiable,$fieldtitles{$field});
10541: }
10542: }
10543: if (@modifiable > 0) {
10544: $resulttext .= join(', ',@modifiable);
10545: } else {
10546: $resulttext .= &mt('none');
10547: }
10548: $resulttext .= '</li>';
10549: }
10550: $resulttext .= '</ul></li>';
10551: }
10552: }
10553: }
10554: $resulttext .= '</ul>';
10555: } else {
10556: $resulttext = &mt('No changes made to user modification settings');
10557: }
10558: } else {
10559: $resulttext = '<span class="LC_error">'.
10560: &mt('An error occurred: [_1]',$putresult).'</span>';
10561: }
10562: return $resulttext;
10563: }
10564:
1.43 raeburn 10565: sub modify_defaults {
1.160.6.27 raeburn 10566: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10567: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 10568: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 10569: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
10570: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 10571: my @authtypes = ('internal','krb4','krb5','localauth');
10572: foreach my $item (@items) {
10573: $newvalues{$item} = $env{'form.'.$item};
10574: if ($item eq 'auth_def') {
10575: if ($newvalues{$item} ne '') {
10576: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10577: push(@errors,$item);
10578: }
10579: }
10580: } elsif ($item eq 'lang_def') {
10581: if ($newvalues{$item} ne '') {
10582: if ($newvalues{$item} =~ /^(\w+)/) {
10583: my $langcode = $1;
1.103 raeburn 10584: if ($langcode ne 'x_chef') {
10585: if (code2language($langcode) eq '') {
10586: push(@errors,$item);
10587: }
1.43 raeburn 10588: }
10589: } else {
10590: push(@errors,$item);
10591: }
10592: }
1.54 raeburn 10593: } elsif ($item eq 'timezone_def') {
10594: if ($newvalues{$item} ne '') {
1.62 raeburn 10595: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10596: push(@errors,$item);
10597: }
10598: }
1.68 raeburn 10599: } elsif ($item eq 'datelocale_def') {
10600: if ($newvalues{$item} ne '') {
10601: my @datelocale_ids = DateTime::Locale->ids();
10602: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10603: push(@errors,$item);
10604: }
10605: }
1.141 raeburn 10606: } elsif ($item eq 'portal_def') {
10607: if ($newvalues{$item} ne '') {
10608: 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])\/?$/) {
10609: push(@errors,$item);
10610: }
10611: }
1.160.6.80 raeburn 10612: } elsif ($item eq 'intauth_cost') {
10613: if ($newvalues{$item} ne '') {
10614: if ($newvalues{$item} =~ /\D/) {
10615: push(@errors,$item);
10616: }
10617: }
10618: } elsif ($item eq 'intauth_check') {
10619: if ($newvalues{$item} ne '') {
10620: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
10621: push(@errors,$item);
10622: }
10623: }
10624: } elsif ($item eq 'intauth_switch') {
10625: if ($newvalues{$item} ne '') {
10626: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
10627: push(@errors,$item);
10628: }
10629: }
1.43 raeburn 10630: }
10631: if (grep(/^\Q$item\E$/,@errors)) {
10632: $newvalues{$item} = $domdefaults{$item};
10633: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10634: $changes{$item} = 1;
10635: }
1.72 raeburn 10636: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10637: }
10638: my %defaults_hash = (
1.72 raeburn 10639: defaults => \%newvalues,
10640: );
1.43 raeburn 10641: my $title = &defaults_titles();
1.160.6.40 raeburn 10642:
10643: my $currinststatus;
10644: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10645: $currinststatus = $domconfig{'inststatus'};
10646: } else {
10647: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10648: $currinststatus = {
10649: inststatustypes => $usertypes,
10650: inststatusorder => $types,
10651: inststatusguest => [],
10652: };
10653: }
10654: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10655: my @allpos;
10656: my %guests;
10657: my %alltypes;
10658: my ($currtitles,$currguests,$currorder);
10659: if (ref($currinststatus) eq 'HASH') {
10660: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10661: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10662: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10663: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10664: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10665: }
10666: }
10667: unless (grep(/^\Q$type\E$/,@todelete)) {
10668: my $position = $env{'form.inststatus_pos_'.$type};
10669: $position =~ s/\D+//g;
10670: $allpos[$position] = $type;
10671: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
10672: $alltypes{$type} =~ s/`//g;
10673: if ($env{'form.inststatus_guest_'.$type}) {
10674: $guests{$type} = 1;
10675: }
10676: }
10677: }
10678: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
10679: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
10680: }
10681: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
10682: $currtitles =~ s/,$//;
10683: }
10684: }
10685: if ($env{'form.addinststatus'}) {
10686: my $newtype = $env{'form.addinststatus'};
10687: $newtype =~ s/\W//g;
10688: unless (exists($alltypes{$newtype})) {
10689: if ($env{'form.addinststatus_guest'}) {
10690: $guests{$newtype} = 1;
10691: }
10692: $alltypes{$newtype} = $env{'form.addinststatus_title'};
10693: $alltypes{$newtype} =~ s/`//g;
10694: my $position = $env{'form.addinststatus_pos'};
10695: $position =~ s/\D+//g;
10696: if ($position ne '') {
10697: $allpos[$position] = $newtype;
10698: }
10699: }
10700: }
10701: my (@orderedstatus,@orderedguests);
10702: foreach my $type (@allpos) {
10703: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
10704: push(@orderedstatus,$type);
10705: if ($guests{$type}) {
10706: push(@orderedguests,$type);
10707: }
10708: }
10709: }
10710: foreach my $type (keys(%alltypes)) {
10711: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
10712: delete($alltypes{$type});
10713: }
10714: }
10715: $defaults_hash{'inststatus'} = {
10716: inststatustypes => \%alltypes,
10717: inststatusorder => \@orderedstatus,
10718: inststatusguest => \@orderedguests,
10719: };
10720: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
10721: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
10722: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
10723: }
10724: }
10725: if ($currorder ne join(',',@orderedstatus)) {
10726: $changes{'inststatus'}{'inststatusorder'} = 1;
10727: }
10728: if ($currguests ne join(',',@orderedguests)) {
10729: $changes{'inststatus'}{'inststatusguest'} = 1;
10730: }
10731: my $newtitles;
10732: foreach my $item (@orderedstatus) {
10733: $newtitles .= $alltypes{$item}.',';
10734: }
10735: $newtitles =~ s/,$//;
10736: if ($currtitles ne $newtitles) {
10737: $changes{'inststatus'}{'inststatustypes'} = 1;
10738: }
1.43 raeburn 10739: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
10740: $dom);
10741: if ($putresult eq 'ok') {
10742: if (keys(%changes) > 0) {
10743: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 10744: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 10745: 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";
10746: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 10747: if ($item eq 'inststatus') {
10748: if (ref($changes{'inststatus'}) eq 'HASH') {
10749: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
10750: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
10751: foreach my $type (@orderedstatus) {
10752: $resulttext .= $alltypes{$type}.', ';
10753: }
10754: $resulttext =~ s/, $//;
10755: $resulttext .= '</li>';
10756: }
10757: if ($changes{'inststatus'}{'inststatusguest'}) {
10758: $resulttext .= '<li>';
10759: if (@orderedguests) {
10760: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
10761: foreach my $type (@orderedguests) {
10762: $resulttext .= $alltypes{$type}.', ';
10763: }
10764: $resulttext =~ s/, $//;
10765: } else {
10766: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
10767: }
10768: $resulttext .= '</li>';
10769: }
10770: }
10771: } else {
10772: my $value = $env{'form.'.$item};
10773: if ($value eq '') {
10774: $value = &mt('none');
10775: } elsif ($item eq 'auth_def') {
10776: my %authnames = &authtype_names();
10777: my %shortauth = (
10778: internal => 'int',
10779: krb4 => 'krb4',
10780: krb5 => 'krb5',
10781: localauth => 'loc',
10782: );
10783: $value = $authnames{$shortauth{$value}};
1.160.6.80 raeburn 10784: } elsif ($item eq 'intauth_switch') {
10785: my %optiondesc = &Apache::lonlocal::texthash (
10786: 0 => 'No',
10787: 1 => 'Yes',
10788: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
10789: );
10790: if ($value =~ /^(0|1|2)$/) {
10791: $value = $optiondesc{$value};
10792: } else {
10793: $value = &mt('none -- defaults to No');
10794: }
10795: } elsif ($item eq 'intauth_check') {
10796: my %optiondesc = &Apache::lonlocal::texthash (
10797: 0 => 'No',
10798: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
10799: 2 => 'Yes, disallow login if stored cost is less than domain default',
10800: );
10801: if ($value =~ /^(0|1|2)$/) {
10802: $value = $optiondesc{$value};
10803: } else {
10804: $value = &mt('none -- defaults to No');
10805: }
1.160.6.40 raeburn 10806: }
10807: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
10808: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 10809: }
10810: }
10811: $resulttext .= '</ul>';
10812: $mailmsgtext .= "\n";
10813: my $cachetime = 24*60*60;
1.72 raeburn 10814: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10815: if (ref($lastactref) eq 'HASH') {
10816: $lastactref->{'domdefaults'} = 1;
10817: }
1.68 raeburn 10818: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 10819: my $notify = 1;
10820: if (ref($domconfig{'contacts'}) eq 'HASH') {
10821: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
10822: $notify = 0;
10823: }
10824: }
10825: if ($notify) {
10826: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
10827: "LON-CAPA Domain Settings Change - $dom",
10828: $mailmsgtext);
10829: }
1.54 raeburn 10830: }
1.43 raeburn 10831: } else {
1.54 raeburn 10832: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 10833: }
10834: } else {
10835: $resulttext = '<span class="LC_error">'.
10836: &mt('An error occurred: [_1]',$putresult).'</span>';
10837: }
10838: if (@errors > 0) {
10839: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
10840: foreach my $item (@errors) {
10841: $resulttext .= ' "'.$title->{$item}.'",';
10842: }
10843: $resulttext =~ s/,$//;
10844: }
10845: return $resulttext;
10846: }
10847:
1.46 raeburn 10848: sub modify_scantron {
1.160.6.24 raeburn 10849: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 10850: my ($resulttext,%confhash,%changes,$errors);
10851: my $custom = 'custom.tab';
10852: my $default = 'default.tab';
10853: my $servadm = $r->dir_config('lonAdmEMail');
10854: my ($configuserok,$author_ok,$switchserver) =
10855: &config_check($dom,$confname,$servadm);
10856: if ($env{'form.scantronformat.filename'} ne '') {
10857: my $error;
10858: if ($configuserok eq 'ok') {
10859: if ($switchserver) {
1.130 raeburn 10860: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 10861: } else {
10862: if ($author_ok eq 'ok') {
10863: my ($result,$scantronurl) =
10864: &publishlogo($r,'upload','scantronformat',$dom,
10865: $confname,'scantron','','',$custom);
10866: if ($result eq 'ok') {
10867: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 10868: $changes{'scantronformat'} = 1;
1.46 raeburn 10869: } else {
10870: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
10871: }
10872: } else {
10873: $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);
10874: }
10875: }
10876: } else {
10877: $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);
10878: }
10879: if ($error) {
10880: &Apache::lonnet::logthis($error);
10881: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10882: }
10883: }
1.48 raeburn 10884: if (ref($domconfig{'scantron'}) eq 'HASH') {
10885: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
10886: if ($env{'form.scantronformat_del'}) {
10887: $confhash{'scantron'}{'scantronformat'} = '';
10888: $changes{'scantronformat'} = 1;
1.46 raeburn 10889: }
10890: }
10891: }
10892: if (keys(%confhash) > 0) {
10893: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10894: $dom);
10895: if ($putresult eq 'ok') {
10896: if (keys(%changes) > 0) {
1.48 raeburn 10897: if (ref($confhash{'scantron'}) eq 'HASH') {
10898: $resulttext = &mt('Changes made:').'<ul>';
10899: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 10900: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 10901: } else {
1.130 raeburn 10902: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 10903: }
1.48 raeburn 10904: $resulttext .= '</ul>';
10905: } else {
1.130 raeburn 10906: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 10907: }
10908: $resulttext .= '</ul>';
10909: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10910: if (ref($lastactref) eq 'HASH') {
10911: $lastactref->{'domainconfig'} = 1;
10912: }
1.46 raeburn 10913: } else {
1.130 raeburn 10914: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10915: }
10916: } else {
10917: $resulttext = '<span class="LC_error">'.
10918: &mt('An error occurred: [_1]',$putresult).'</span>';
10919: }
10920: } else {
1.130 raeburn 10921: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10922: }
10923: if ($errors) {
10924: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10925: $errors.'</ul>';
10926: }
10927: return $resulttext;
10928: }
10929:
1.48 raeburn 10930: sub modify_coursecategories {
1.160.6.43 raeburn 10931: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 10932: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10933: $cathash);
1.48 raeburn 10934: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 10935: my @catitems = ('unauth','auth');
10936: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 10937: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 10938: $cathash = $domconfig{'coursecategories'}{'cats'};
10939: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10940: $changes{'togglecats'} = 1;
10941: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10942: }
10943: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10944: $changes{'categorize'} = 1;
10945: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
10946: }
1.120 raeburn 10947: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
10948: $changes{'togglecatscomm'} = 1;
10949: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
10950: }
10951: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
10952: $changes{'categorizecomm'} = 1;
10953: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
10954: }
1.160.6.42 raeburn 10955: foreach my $item (@catitems) {
10956: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10957: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
10958: $changes{$item} = 1;
10959: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10960: }
10961: }
10962: }
1.57 raeburn 10963: } else {
10964: $changes{'togglecats'} = 1;
10965: $changes{'categorize'} = 1;
1.124 raeburn 10966: $changes{'togglecatscomm'} = 1;
10967: $changes{'categorizecomm'} = 1;
1.87 raeburn 10968: $domconfig{'coursecategories'} = {
10969: togglecats => $env{'form.togglecats'},
10970: categorize => $env{'form.categorize'},
1.124 raeburn 10971: togglecatscomm => $env{'form.togglecatscomm'},
10972: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 10973: };
1.160.6.42 raeburn 10974: foreach my $item (@catitems) {
10975: if ($env{'form.coursecat_'.$item} ne 'std') {
10976: $changes{$item} = 1;
10977: }
10978: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10979: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10980: }
10981: }
1.57 raeburn 10982: }
10983: if (ref($cathash) eq 'HASH') {
10984: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 10985: push (@deletecategory,'instcode::0');
10986: }
1.120 raeburn 10987: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
10988: push(@deletecategory,'communities::0');
10989: }
1.48 raeburn 10990: }
1.57 raeburn 10991: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
10992: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10993: if (@deletecategory > 0) {
10994: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 10995: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 10996: foreach my $item (@deletecategory) {
1.57 raeburn 10997: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
10998: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 10999: $deletions{$item} = 1;
1.57 raeburn 11000: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11001: }
11002: }
11003: }
1.57 raeburn 11004: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11005: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11006: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11007: $reorderings{$item} = 1;
1.57 raeburn 11008: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11009: }
11010: if ($env{'form.addcategory_name_'.$item} ne '') {
11011: my $newcat = $env{'form.addcategory_name_'.$item};
11012: my $newdepth = $depth+1;
11013: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11014: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11015: $adds{$newitem} = 1;
11016: }
11017: if ($env{'form.subcat_'.$item} ne '') {
11018: my $newcat = $env{'form.subcat_'.$item};
11019: my $newdepth = $depth+1;
11020: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11021: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11022: $adds{$newitem} = 1;
11023: }
11024: }
11025: }
11026: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11027: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11028: my $newitem = 'instcode::0';
1.57 raeburn 11029: if ($cathash->{$newitem} eq '') {
11030: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11031: $adds{$newitem} = 1;
11032: }
11033: } else {
11034: my $newitem = 'instcode::0';
1.57 raeburn 11035: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11036: $adds{$newitem} = 1;
11037: }
11038: }
1.120 raeburn 11039: if ($env{'form.communities'} eq '1') {
11040: if (ref($cathash) eq 'HASH') {
11041: my $newitem = 'communities::0';
11042: if ($cathash->{$newitem} eq '') {
11043: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11044: $adds{$newitem} = 1;
11045: }
11046: } else {
11047: my $newitem = 'communities::0';
11048: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11049: $adds{$newitem} = 1;
11050: }
11051: }
1.48 raeburn 11052: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11053: if (($env{'form.addcategory_name'} ne 'instcode') &&
11054: ($env{'form.addcategory_name'} ne 'communities')) {
11055: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11056: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11057: $adds{$newitem} = 1;
11058: }
1.48 raeburn 11059: }
1.57 raeburn 11060: my $putresult;
1.48 raeburn 11061: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11062: if (keys(%deletions) > 0) {
11063: foreach my $key (keys(%deletions)) {
11064: if ($predelallitems{$key} ne '') {
11065: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11066: }
11067: }
11068: }
11069: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11070: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11071: if (ref($chkcats[0]) eq 'ARRAY') {
11072: my $depth = 0;
11073: my $chg = 0;
11074: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11075: my $name = $chkcats[0][$i];
11076: my $item;
11077: if ($name eq '') {
11078: $chg ++;
11079: } else {
11080: $item = &escape($name).'::0';
11081: if ($chg) {
1.57 raeburn 11082: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11083: }
11084: $depth ++;
1.57 raeburn 11085: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11086: $depth --;
11087: }
11088: }
11089: }
1.57 raeburn 11090: }
11091: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11092: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11093: if ($putresult eq 'ok') {
1.57 raeburn 11094: my %title = (
1.120 raeburn 11095: togglecats => 'Show/Hide a course in catalog',
11096: categorize => 'Assign a category to a course',
11097: togglecatscomm => 'Show/Hide a community in catalog',
11098: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11099: );
11100: my %level = (
1.120 raeburn 11101: dom => 'set in Domain ("Modify Course/Community")',
11102: crs => 'set in Course ("Course Configuration")',
11103: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 11104: none => 'No catalog',
11105: std => 'Standard catalog',
11106: domonly => 'Domain-only catalog',
11107: codesrch => 'Code search form',
1.57 raeburn 11108: );
1.48 raeburn 11109: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11110: if ($changes{'togglecats'}) {
11111: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11112: }
11113: if ($changes{'categorize'}) {
11114: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11115: }
1.120 raeburn 11116: if ($changes{'togglecatscomm'}) {
11117: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11118: }
11119: if ($changes{'categorizecomm'}) {
11120: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11121: }
1.160.6.42 raeburn 11122: if ($changes{'unauth'}) {
11123: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11124: }
11125: if ($changes{'auth'}) {
11126: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11127: }
1.57 raeburn 11128: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11129: my $cathash;
11130: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11131: $cathash = $domconfig{'coursecategories'}{'cats'};
11132: } else {
11133: $cathash = {};
11134: }
11135: my (@cats,@trails,%allitems);
11136: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11137: if (keys(%deletions) > 0) {
11138: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11139: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11140: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11141: }
11142: $resulttext .= '</ul></li>';
11143: }
11144: if (keys(%reorderings) > 0) {
11145: my %sort_by_trail;
11146: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11147: foreach my $key (keys(%reorderings)) {
11148: if ($allitems{$key} ne '') {
11149: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11150: }
1.48 raeburn 11151: }
1.57 raeburn 11152: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11153: $resulttext .= '<li>'.$trails[$trail].'</li>';
11154: }
11155: $resulttext .= '</ul></li>';
1.48 raeburn 11156: }
1.57 raeburn 11157: if (keys(%adds) > 0) {
11158: my %sort_by_trail;
11159: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11160: foreach my $key (keys(%adds)) {
11161: if ($allitems{$key} ne '') {
11162: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11163: }
11164: }
11165: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11166: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11167: }
1.57 raeburn 11168: $resulttext .= '</ul></li>';
1.48 raeburn 11169: }
11170: }
11171: $resulttext .= '</ul>';
1.160.6.43 raeburn 11172: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 11173: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11174: if ($changes{'auth'}) {
11175: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11176: }
11177: if ($changes{'unauth'}) {
11178: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11179: }
11180: my $cachetime = 24*60*60;
11181: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 11182: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 11183: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 11184: }
11185: }
1.48 raeburn 11186: } else {
11187: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11188: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11189: }
11190: } else {
1.120 raeburn 11191: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11192: }
11193: return $resulttext;
11194: }
11195:
1.69 raeburn 11196: sub modify_serverstatuses {
11197: my ($dom,%domconfig) = @_;
11198: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11199: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11200: %currserverstatus = %{$domconfig{'serverstatuses'}};
11201: }
11202: my @pages = &serverstatus_pages();
11203: foreach my $type (@pages) {
11204: $newserverstatus{$type}{'namedusers'} = '';
11205: $newserverstatus{$type}{'machines'} = '';
11206: if (defined($env{'form.'.$type.'_namedusers'})) {
11207: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11208: my @okusers;
11209: foreach my $user (@users) {
11210: my ($uname,$udom) = split(/:/,$user);
11211: if (($udom =~ /^$match_domain$/) &&
11212: (&Apache::lonnet::domain($udom)) &&
11213: ($uname =~ /^$match_username$/)) {
11214: if (!grep(/^\Q$user\E/,@okusers)) {
11215: push(@okusers,$user);
11216: }
11217: }
11218: }
11219: if (@okusers > 0) {
11220: @okusers = sort(@okusers);
11221: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11222: }
11223: }
11224: if (defined($env{'form.'.$type.'_machines'})) {
11225: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11226: my @okmachines;
11227: foreach my $ip (@machines) {
11228: my @parts = split(/\./,$ip);
11229: next if (@parts < 4);
11230: my $badip = 0;
11231: for (my $i=0; $i<4; $i++) {
11232: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11233: $badip = 1;
11234: last;
11235: }
11236: }
11237: if (!$badip) {
11238: push(@okmachines,$ip);
11239: }
11240: }
11241: @okmachines = sort(@okmachines);
11242: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11243: }
11244: }
11245: my %serverstatushash = (
11246: serverstatuses => \%newserverstatus,
11247: );
11248: foreach my $type (@pages) {
1.83 raeburn 11249: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11250: my (@current,@new);
1.83 raeburn 11251: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11252: if ($currserverstatus{$type}{$setting} ne '') {
11253: @current = split(/,/,$currserverstatus{$type}{$setting});
11254: }
11255: }
11256: if ($newserverstatus{$type}{$setting} ne '') {
11257: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11258: }
11259: if (@current > 0) {
11260: if (@new > 0) {
11261: foreach my $item (@current) {
11262: if (!grep(/^\Q$item\E$/,@new)) {
11263: $changes{$type}{$setting} = 1;
1.82 raeburn 11264: last;
11265: }
11266: }
1.84 raeburn 11267: foreach my $item (@new) {
11268: if (!grep(/^\Q$item\E$/,@current)) {
11269: $changes{$type}{$setting} = 1;
11270: last;
1.82 raeburn 11271: }
11272: }
11273: } else {
1.83 raeburn 11274: $changes{$type}{$setting} = 1;
1.69 raeburn 11275: }
1.83 raeburn 11276: } elsif (@new > 0) {
11277: $changes{$type}{$setting} = 1;
1.69 raeburn 11278: }
11279: }
11280: }
11281: if (keys(%changes) > 0) {
1.81 raeburn 11282: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11283: my $putresult = &Apache::lonnet::put_dom('configuration',
11284: \%serverstatushash,$dom);
11285: if ($putresult eq 'ok') {
11286: $resulttext .= &mt('Changes made:').'<ul>';
11287: foreach my $type (@pages) {
1.84 raeburn 11288: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11289: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11290: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11291: if ($newserverstatus{$type}{'namedusers'} eq '') {
11292: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11293: } else {
11294: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11295: }
1.84 raeburn 11296: }
11297: if ($changes{$type}{'machines'}) {
1.69 raeburn 11298: if ($newserverstatus{$type}{'machines'} eq '') {
11299: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11300: } else {
11301: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11302: }
11303:
11304: }
11305: $resulttext .= '</ul></li>';
11306: }
11307: }
11308: $resulttext .= '</ul>';
11309: } else {
11310: $resulttext = '<span class="LC_error">'.
11311: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11312:
11313: }
11314: } else {
11315: $resulttext = &mt('No changes made to access to server status pages');
11316: }
11317: return $resulttext;
11318: }
11319:
1.118 jms 11320: sub modify_helpsettings {
1.160.6.77 raeburn 11321: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 11322: my ($resulttext,$errors,%changes,%helphash);
11323: my %defaultchecked = ('submitbugs' => 'on');
11324: my @offon = ('off','on');
1.118 jms 11325: my @toggles = ('submitbugs');
1.160.6.77 raeburn 11326: my %current = ('submitbugs' => '',
11327: 'adhoc' => {},
11328: );
1.118 jms 11329: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 11330: %current = %{$domconfig{'helpsettings'}};
11331: }
1.160.6.77 raeburn 11332: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 11333: foreach my $item (@toggles) {
11334: if ($defaultchecked{$item} eq 'on') {
11335: if ($current{$item} eq '') {
11336: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 11337: $changes{$item} = 1;
11338: }
1.160.6.73 raeburn 11339: } elsif ($current{$item} ne $env{'form.'.$item}) {
11340: $changes{$item} = 1;
11341: }
11342: } elsif ($defaultchecked{$item} eq 'off') {
11343: if ($current{$item} eq '') {
11344: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 11345: $changes{$item} = 1;
11346: }
1.160.6.73 raeburn 11347: } elsif ($current{$item} ne $env{'form.'.$item}) {
11348: $changes{$item} = 1;
11349: }
11350: }
11351: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
11352: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11353: }
11354: }
1.160.6.77 raeburn 11355: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 11356: my $confname = $dom.'-domainconfig';
11357: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 11358: my (@allpos,%newsettings,%changedprivs,$newrole);
11359: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 11360: my @accesstypes = ('all','dh','da','none','status','inc','exc');
11361: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 11362: my %lt = &Apache::lonlocal::texthash(
11363: s => 'system',
11364: d => 'domain',
11365: order => 'Display order',
11366: access => 'Role usage',
1.160.6.79 raeburn 11367: all => 'All with domain helpdesk or helpdesk assistant role',
11368: dh => 'All with domain helpdesk role',
11369: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 11370: none => 'None',
11371: status => 'Determined based on institutional status',
11372: inc => 'Include all, but exclude specific personnel',
11373: exc => 'Exclude all, but include specific personnel',
11374: );
11375: for (my $num=0; $num<=$maxnum; $num++) {
11376: my ($prefix,$identifier,$rolename,%curr);
11377: if ($num == $maxnum) {
11378: next unless ($env{'form.newcusthelp'} == $maxnum);
11379: $identifier = 'custhelp'.$num;
11380: $prefix = 'helproles_'.$num;
11381: $rolename = $env{'form.custhelpname'.$num};
11382: $rolename=~s/[^A-Za-z0-9]//gs;
11383: next if ($rolename eq '');
11384: next if (exists($existing{'rolesdef_'.$rolename}));
11385: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11386: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11387: $newprivs{'c'},$confname,$dom);
11388: if ($result ne 'ok') {
11389: $errors .= '<li><span class="LC_error">'.
11390: &mt('An error occurred storing the new custom role: [_1]',
11391: $result).'</span></li>';
11392: next;
11393: } else {
11394: $changedprivs{$rolename} = \%newprivs;
11395: $newrole = $rolename;
11396: }
11397: } else {
11398: $prefix = 'helproles_'.$num;
11399: $rolename = $env{'form.'.$prefix};
11400: next if ($rolename eq '');
11401: next unless (exists($existing{'rolesdef_'.$rolename}));
11402: $identifier = 'custhelp'.$num;
11403: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11404: my %currprivs;
11405: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
11406: split(/\_/,$existing{'rolesdef_'.$rolename});
11407: foreach my $level ('c','d','s') {
11408: if ($newprivs{$level} ne $currprivs{$level}) {
11409: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11410: $newprivs{'c'},$confname,$dom);
11411: if ($result ne 'ok') {
11412: $errors .= '<li><span class="LC_error">'.
11413: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
11414: $rolename,$result).'</span></li>';
11415: } else {
11416: $changedprivs{$rolename} = \%newprivs;
11417: }
11418: last;
11419: }
11420: }
11421: if (ref($current{'adhoc'}) eq 'HASH') {
11422: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11423: %curr = %{$current{'adhoc'}{$rolename}};
11424: }
11425: }
11426: }
11427: my $newpos = $env{'form.'.$prefix.'_pos'};
11428: $newpos =~ s/\D+//g;
11429: $allpos[$newpos] = $rolename;
11430: my $newdesc = $env{'form.'.$prefix.'_desc'};
11431: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
11432: if ($curr{'desc'}) {
11433: if ($curr{'desc'} ne $newdesc) {
11434: $changes{'customrole'}{$rolename}{'desc'} = 1;
11435: $newsettings{$rolename}{'desc'} = $newdesc;
11436: }
11437: } elsif ($newdesc ne '') {
11438: $changes{'customrole'}{$rolename}{'desc'} = 1;
11439: $newsettings{$rolename}{'desc'} = $newdesc;
11440: }
11441: my $access = $env{'form.'.$prefix.'_access'};
11442: if (grep(/^\Q$access\E$/,@accesstypes)) {
11443: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
11444: if ($access eq 'status') {
11445: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
11446: if (scalar(@statuses) == 0) {
11447: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
11448: } else {
11449: my (@shownstatus,$numtypes);
11450: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11451: if (ref($types) eq 'ARRAY') {
11452: $numtypes = scalar(@{$types});
11453: foreach my $type (sort(@statuses)) {
11454: if ($type eq 'default') {
11455: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11456: } elsif (grep(/^\Q$type\E$/,@{$types})) {
11457: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11458: push(@shownstatus,$usertypes->{$type});
11459: }
1.160.6.73 raeburn 11460: }
11461: }
1.160.6.77 raeburn 11462: if (grep(/^default$/,@statuses)) {
11463: push(@shownstatus,$othertitle);
11464: }
11465: if (scalar(@shownstatus) == 1+$numtypes) {
11466: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
11467: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
11468: } else {
11469: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
11470: if (ref($curr{'status'}) eq 'ARRAY') {
11471: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11472: if (@diffs) {
11473: $changes{'customrole'}{$rolename}{$access} = 1;
11474: }
11475: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11476: $changes{'customrole'}{$rolename}{$access} = 1;
11477: }
11478: }
11479: }
11480: } elsif (($access eq 'inc') || ($access eq 'exc')) {
11481: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
11482: my @newspecstaff;
11483: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11484: foreach my $person (sort(@personnel)) {
11485: if ($domhelpdesk{$person}) {
11486: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
11487: }
11488: }
11489: if (ref($curr{$access}) eq 'ARRAY') {
11490: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11491: if (@diffs) {
11492: $changes{'customrole'}{$rolename}{$access} = 1;
11493: }
11494: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11495: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 11496: }
1.160.6.77 raeburn 11497: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11498: my ($uname,$udom) = split(/:/,$person);
11499: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
11500: }
11501: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 11502: }
1.160.6.77 raeburn 11503: } else {
11504: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
11505: }
11506: unless ($curr{'access'} eq $access) {
11507: $changes{'customrole'}{$rolename}{'access'} = 1;
11508: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 11509: }
11510: }
1.160.6.77 raeburn 11511: if (@allpos > 0) {
11512: my $idx = 0;
11513: foreach my $rolename (@allpos) {
11514: if ($rolename ne '') {
11515: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
11516: if (ref($current{'adhoc'}) eq 'HASH') {
11517: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11518: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
11519: $changes{'customrole'}{$rolename}{'order'} = 1;
11520: $newsettings{$rolename}{'order'} = $idx+1;
11521: }
11522: }
1.160.6.73 raeburn 11523: }
1.160.6.77 raeburn 11524: $idx ++;
1.122 jms 11525: }
11526: }
1.118 jms 11527: }
1.123 jms 11528: my $putresult;
11529: if (keys(%changes) > 0) {
1.160.6.5 raeburn 11530: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
11531: if ($putresult eq 'ok') {
1.160.6.77 raeburn 11532: if (ref($helphash{'helpsettings'}) eq 'HASH') {
11533: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
11534: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
11535: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
11536: }
11537: }
11538: my $cachetime = 24*60*60;
11539: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11540: if (ref($lastactref) eq 'HASH') {
11541: $lastactref->{'domdefaults'} = 1;
11542: }
11543: } else {
11544: $errors .= '<li><span class="LC_error">'.
11545: &mt('An error occurred storing the settings: [_1]',
11546: $putresult).'</span></li>';
11547: }
11548: }
11549: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
11550: $resulttext = &mt('Changes made:').'<ul>';
11551: my (%shownprivs,@levelorder);
11552: @levelorder = ('c','d','s');
11553: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 11554: foreach my $item (sort(keys(%changes))) {
11555: if ($item eq 'submitbugs') {
11556: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11557: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11558: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 11559: } elsif ($item eq 'customrole') {
11560: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 11561: my @keyorder = ('order','desc','access','status','exc','inc');
11562: my %keytext = &Apache::lonlocal::texthash(
11563: order => 'Order',
11564: desc => 'Role description',
11565: access => 'Role usage',
11566: status => 'Allowed instituional types',
11567: exc => 'Allowed personnel',
11568: inc => 'Disallowed personnel',
11569: );
1.160.6.73 raeburn 11570: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 11571: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
11572: if ($role eq $newrole) {
11573: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
11574: $role).'<ul>';
11575: } else {
11576: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11577: $role).'<ul>';
11578: }
11579: foreach my $key (@keyorder) {
11580: if ($changes{'customrole'}{$role}{$key}) {
11581: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
11582: $keytext{$key},$newsettings{$role}{$key}).
11583: '</li>';
11584: }
11585: }
11586: if (ref($changedprivs{$role}) eq 'HASH') {
11587: $shownprivs{$role} = 1;
11588: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
11589: foreach my $level (@levelorder) {
11590: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11591: next if ($item eq '');
11592: my ($priv) = split(/\&/,$item,2);
11593: if (&Apache::lonnet::plaintext($priv)) {
11594: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11595: unless ($level eq 'c') {
11596: $resulttext .= ' ('.$lt{$level}.')';
11597: }
11598: $resulttext .= '</li>';
11599: }
11600: }
11601: }
11602: $resulttext .= '</ul>';
11603: }
11604: $resulttext .= '</ul></li>';
11605: }
1.160.6.73 raeburn 11606: }
11607: }
1.160.6.5 raeburn 11608: }
11609: }
11610: }
1.160.6.77 raeburn 11611: if (keys(%changedprivs)) {
11612: foreach my $role (sort(keys(%changedprivs))) {
11613: unless ($shownprivs{$role}) {
11614: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11615: $role).'<ul>'.
11616: '<li>'.&mt('Privileges set to :').'<ul>';
11617: foreach my $level (@levelorder) {
11618: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11619: next if ($item eq '');
11620: my ($priv) = split(/\&/,$item,2);
11621: if (&Apache::lonnet::plaintext($priv)) {
11622: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11623: unless ($level eq 'c') {
11624: $resulttext .= ' ('.$lt{$level}.')';
11625: }
11626: $resulttext .= '</li>';
11627: }
11628: }
11629: }
11630: $resulttext .= '</ul></li></ul></li>';
11631: }
11632: }
11633: }
11634: $resulttext .= '</ul>';
11635: } else {
11636: $resulttext = &mt('No changes made to help settings');
1.118 jms 11637: }
11638: if ($errors) {
1.160.6.5 raeburn 11639: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 11640: $errors.'</ul>';
1.118 jms 11641: }
11642: return $resulttext;
11643: }
11644:
1.121 raeburn 11645: sub modify_coursedefaults {
1.160.6.27 raeburn 11646: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11647: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 11648: my %defaultchecked = (
11649: 'uselcmath' => 'on',
11650: 'usejsme' => 'on'
11651: );
11652: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 11653: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 11654: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
11655: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 11656: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 11657: my %staticdefaults = (
11658: anonsurvey_threshold => 10,
11659: uploadquota => 500,
1.160.6.57 raeburn 11660: postsubmit => 60,
1.160.6.70 raeburn 11661: mysqltables => 172800,
1.160.6.21 raeburn 11662: );
1.121 raeburn 11663:
11664: $defaultshash{'coursedefaults'} = {};
11665:
11666: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11667: if ($domconfig{'coursedefaults'} eq '') {
11668: $domconfig{'coursedefaults'} = {};
11669: }
11670: }
11671:
11672: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11673: foreach my $item (@toggles) {
11674: if ($defaultchecked{$item} eq 'on') {
11675: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11676: ($env{'form.'.$item} eq '0')) {
11677: $changes{$item} = 1;
1.160.6.16 raeburn 11678: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11679: $changes{$item} = 1;
11680: }
11681: } elsif ($defaultchecked{$item} eq 'off') {
11682: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11683: ($env{'form.'.$item} eq '1')) {
11684: $changes{$item} = 1;
11685: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11686: $changes{$item} = 1;
11687: }
11688: }
11689: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11690: }
1.160.6.21 raeburn 11691: foreach my $item (@numbers) {
11692: my ($currdef,$newdef);
1.160.6.26 raeburn 11693: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 11694: if ($item eq 'anonsurvey_threshold') {
11695: $currdef = $domconfig{'coursedefaults'}{$item};
11696: $newdef =~ s/\D//g;
11697: if ($newdef eq '' || $newdef < 1) {
11698: $newdef = 1;
11699: }
11700: $defaultshash{'coursedefaults'}{$item} = $newdef;
11701: } else {
1.160.6.70 raeburn 11702: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
11703: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
11704: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 11705: }
11706: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 11707: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 11708: }
11709: if ($currdef ne $newdef) {
11710: my $staticdef;
11711: if ($item eq 'anonsurvey_threshold') {
11712: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11713: $changes{$item} = 1;
11714: }
1.160.6.70 raeburn 11715: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
11716: my $setting = $1;
11717: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
11718: $changes{$setting} = 1;
1.160.6.21 raeburn 11719: }
11720: }
1.139 raeburn 11721: }
11722: }
1.160.6.64 raeburn 11723: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11724: my @currclonecode;
11725: if (ref($currclone) eq 'HASH') {
11726: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11727: @currclonecode = @{$currclone->{'instcode'}};
11728: }
11729: }
11730: my $newclone;
11731: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11732: $newclone = $env{'form.canclone'};
11733: }
11734: if ($newclone eq 'instcode') {
11735: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11736: my (%codedefaults,@code_order,@clonecode);
11737: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11738: \@code_order);
11739: foreach my $item (@code_order) {
11740: if (grep(/^\Q$item\E$/,@newcodes)) {
11741: push(@clonecode,$item);
11742: }
11743: }
11744: if (@clonecode) {
11745: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11746: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11747: if (@diffs) {
11748: $changes{'canclone'} = 1;
11749: }
11750: } else {
11751: $newclone eq '';
11752: }
11753: } elsif ($newclone ne '') {
11754: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11755: }
11756: if ($newclone ne $currclone) {
11757: $changes{'canclone'} = 1;
11758: }
1.160.6.57 raeburn 11759: my %credits;
11760: foreach my $type (@types) {
11761: unless ($type eq 'community') {
11762: $credits{$type} = $env{'form.'.$type.'_credits'};
11763: $credits{$type} =~ s/[^\d.]+//g;
11764: }
11765: }
11766: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11767: ($env{'form.coursecredits'} eq '1')) {
11768: $changes{'coursecredits'} = 1;
11769: foreach my $type (keys(%credits)) {
11770: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11771: }
11772: } else {
11773: if ($env{'form.coursecredits'} eq '1') {
11774: foreach my $type (@types) {
11775: unless ($type eq 'community') {
11776: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11777: $changes{'coursecredits'} = 1;
11778: }
11779: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11780: }
11781: }
11782: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11783: foreach my $type (@types) {
11784: unless ($type eq 'community') {
11785: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11786: $changes{'coursecredits'} = 1;
11787: last;
11788: }
11789: }
11790: }
11791: }
11792: }
11793: if ($env{'form.postsubmit'} eq '1') {
11794: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11795: my %currtimeout;
11796: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11797: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11798: $changes{'postsubmit'} = 1;
11799: }
11800: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11801: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11802: }
11803: } else {
11804: $changes{'postsubmit'} = 1;
11805: }
11806: foreach my $type (@types) {
11807: my $timeout = $env{'form.'.$type.'_timeout'};
11808: $timeout =~ s/\D//g;
11809: if ($timeout == $staticdefaults{'postsubmit'}) {
11810: $timeout = '';
11811: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11812: $timeout = '0';
11813: }
11814: unless ($timeout eq '') {
11815: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11816: }
11817: if (exists($currtimeout{$type})) {
11818: if ($timeout ne $currtimeout{$type}) {
11819: $changes{'postsubmit'} = 1;
11820: }
11821: } elsif ($timeout ne '') {
11822: $changes{'postsubmit'} = 1;
11823: }
11824: }
11825: } else {
11826: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11827: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11828: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11829: $changes{'postsubmit'} = 1;
11830: }
11831: } else {
11832: $changes{'postsubmit'} = 1;
11833: }
1.160.6.16 raeburn 11834: }
1.121 raeburn 11835: }
11836: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11837: $dom);
11838: if ($putresult eq 'ok') {
11839: if (keys(%changes) > 0) {
1.160.6.27 raeburn 11840: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 11841: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 11842: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 11843: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 11844: foreach my $item ('uselcmath','usejsme') {
11845: if ($changes{$item}) {
11846: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11847: }
1.160.6.16 raeburn 11848: }
11849: if ($changes{'coursecredits'}) {
11850: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 11851: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11852: $domdefaults{$type.'credits'} =
11853: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11854: }
11855: }
11856: }
11857: if ($changes{'postsubmit'}) {
11858: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11859: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11860: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11861: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11862: $domdefaults{$type.'postsubtimeout'} =
11863: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11864: }
11865: }
1.160.6.16 raeburn 11866: }
11867: }
1.160.6.21 raeburn 11868: if ($changes{'uploadquota'}) {
11869: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11870: foreach my $type (@types) {
11871: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11872: }
11873: }
11874: }
1.160.6.64 raeburn 11875: if ($changes{'canclone'}) {
11876: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11877: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11878: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11879: if (@clonecodes) {
11880: $domdefaults{'canclone'} = join('+',@clonecodes);
11881: }
11882: }
11883: } else {
11884: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11885: }
11886: }
1.121 raeburn 11887: my $cachetime = 24*60*60;
11888: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11889: if (ref($lastactref) eq 'HASH') {
11890: $lastactref->{'domdefaults'} = 1;
11891: }
1.121 raeburn 11892: }
11893: $resulttext = &mt('Changes made:').'<ul>';
11894: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 11895: if ($item eq 'uselcmath') {
1.121 raeburn 11896: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 11897: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 11898: } else {
1.160.6.57 raeburn 11899: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11900: }
11901: } elsif ($item eq 'usejsme') {
11902: if ($env{'form.'.$item} eq '1') {
11903: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11904: } else {
11905: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 11906: }
1.139 raeburn 11907: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 11908: $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 11909: } elsif ($item eq 'uploadquota') {
11910: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11911: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11912: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11913: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 11914: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
11915:
1.160.6.21 raeburn 11916: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11917: '</ul>'.
11918: '</li>';
11919: } else {
11920: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11921: }
1.160.6.70 raeburn 11922: } elsif ($item eq 'mysqltables') {
11923: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
11924: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
11925: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
11926: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
11927: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
11928: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
11929: '</ul>'.
11930: '</li>';
11931: } else {
11932: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
11933: }
1.160.6.57 raeburn 11934: } elsif ($item eq 'postsubmit') {
11935: if ($domdefaults{'postsubmit'} eq 'off') {
11936: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
11937: } else {
11938: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
11939: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11940: $resulttext .= &mt('durations:').'<ul>';
11941: foreach my $type (@types) {
11942: $resulttext .= '<li>';
11943: my $timeout;
11944: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11945: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11946: }
11947: my $display;
11948: if ($timeout eq '0') {
11949: $display = &mt('unlimited');
11950: } elsif ($timeout eq '') {
11951: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
11952: } else {
11953: $display = &mt('[quant,_1,second]',$timeout);
11954: }
11955: if ($type eq 'community') {
11956: $resulttext .= &mt('Communities');
11957: } elsif ($type eq 'official') {
11958: $resulttext .= &mt('Official courses');
11959: } elsif ($type eq 'unofficial') {
11960: $resulttext .= &mt('Unofficial courses');
11961: } elsif ($type eq 'textbook') {
11962: $resulttext .= &mt('Textbook courses');
11963: }
11964: $resulttext .= ' -- '.$display.'</li>';
11965: }
11966: $resulttext .= '</ul>';
11967: }
11968: $resulttext .= '</li>';
11969: }
1.160.6.16 raeburn 11970: } elsif ($item eq 'coursecredits') {
11971: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11972: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 11973: ($domdefaults{'unofficialcredits'} eq '') &&
11974: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 11975: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11976: } else {
11977: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
11978: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
11979: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 11980: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 11981: '</ul>'.
11982: '</li>';
11983: }
11984: } else {
11985: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11986: }
1.160.6.64 raeburn 11987: } elsif ($item eq 'canclone') {
11988: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11989: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11990: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
11991: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
11992: }
11993: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
11994: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
11995: } else {
11996: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
11997: }
1.140 raeburn 11998: }
1.121 raeburn 11999: }
12000: $resulttext .= '</ul>';
12001: } else {
12002: $resulttext = &mt('No changes made to course defaults');
12003: }
12004: } else {
12005: $resulttext = '<span class="LC_error">'.
12006: &mt('An error occurred: [_1]',$putresult).'</span>';
12007: }
12008: return $resulttext;
12009: }
12010:
1.160.6.37 raeburn 12011: sub modify_selfenrollment {
12012: my ($dom,$lastactref,%domconfig) = @_;
12013: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
12014: my @types = ('official','unofficial','community','textbook');
12015: my %titles = &tool_titles();
12016: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12017: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
12018: $ordered{'default'} = ['types','registered','approval','limit'];
12019:
12020: my (%roles,%shown,%toplevel);
12021: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12022:
12023: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12024: if ($domconfig{'selfenrollment'} eq '') {
12025: $domconfig{'selfenrollment'} = {};
12026: }
12027: }
12028: %toplevel = (
12029: admin => 'Configuration Rights',
12030: default => 'Default settings',
12031: validation => 'Validation of self-enrollment requests',
12032: );
12033: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
12034:
12035: if (ref($ordered{'admin'}) eq 'ARRAY') {
12036: foreach my $item (@{$ordered{'admin'}}) {
12037: foreach my $type (@types) {
12038: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12039: $selfenrollhash{'admin'}{$type}{$item} = 1;
12040: } else {
12041: $selfenrollhash{'admin'}{$type}{$item} = 0;
12042: }
12043: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12044: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12045: if ($selfenrollhash{'admin'}{$type}{$item} ne
12046: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12047: push(@{$changes{'admin'}{$type}},$item);
12048: }
12049: } else {
12050: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12051: push(@{$changes{'admin'}{$type}},$item);
12052: }
12053: }
12054: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12055: push(@{$changes{'admin'}{$type}},$item);
12056: }
12057: }
12058: }
12059: }
12060:
12061: foreach my $item (@{$ordered{'default'}}) {
12062: foreach my $type (@types) {
12063: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12064: if ($item eq 'types') {
12065: unless (($value eq 'all') || ($value eq 'dom')) {
12066: $value = '';
12067: }
12068: } elsif ($item eq 'registered') {
12069: unless ($value eq '1') {
12070: $value = 0;
12071: }
12072: } elsif ($item eq 'approval') {
12073: unless ($value =~ /^[012]$/) {
12074: $value = 0;
12075: }
12076: } else {
12077: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12078: $value = 'none';
12079: }
12080: }
12081: $selfenrollhash{'default'}{$type}{$item} = $value;
12082: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12083: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12084: if ($selfenrollhash{'default'}{$type}{$item} ne
12085: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12086: push(@{$changes{'default'}{$type}},$item);
12087: }
12088: } else {
12089: push(@{$changes{'default'}{$type}},$item);
12090: }
12091: } else {
12092: push(@{$changes{'default'}{$type}},$item);
12093: }
12094: if ($item eq 'limit') {
12095: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12096: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12097: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12098: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12099: }
12100: } else {
12101: $selfenrollhash{'default'}{$type}{'cap'} = '';
12102: }
12103: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12104: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12105: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12106: push(@{$changes{'default'}{$type}},'cap');
12107: }
12108: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12109: push(@{$changes{'default'}{$type}},'cap');
12110: }
12111: }
12112: }
12113: }
12114:
12115: foreach my $item (@{$itemsref}) {
12116: if ($item eq 'fields') {
12117: my @changed;
12118: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12119: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12120: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12121: }
12122: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12123: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12124: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12125: $domconfig{'selfenrollment'}{'validation'}{$item});
12126: } else {
12127: @changed = @{$selfenrollhash{'validation'}{$item}};
12128: }
12129: } else {
12130: @changed = @{$selfenrollhash{'validation'}{$item}};
12131: }
12132: if (@changed) {
12133: if ($selfenrollhash{'validation'}{$item}) {
12134: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12135: } else {
12136: $changes{'validation'}{$item} = &mt('None');
12137: }
12138: }
12139: } else {
12140: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12141: if ($item eq 'markup') {
12142: if ($env{'form.selfenroll_validation_'.$item}) {
12143: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12144: }
12145: }
12146: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12147: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12148: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12149: }
12150: }
12151: }
12152: }
12153:
12154: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12155: $dom);
12156: if ($putresult eq 'ok') {
12157: if (keys(%changes) > 0) {
12158: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12159: $resulttext = &mt('Changes made:').'<ul>';
12160: foreach my $key ('admin','default','validation') {
12161: if (ref($changes{$key}) eq 'HASH') {
12162: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12163: if ($key eq 'validation') {
12164: foreach my $item (@{$itemsref}) {
12165: if (exists($changes{$key}{$item})) {
12166: if ($item eq 'markup') {
12167: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12168: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12169: } else {
12170: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12171: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12172: }
12173: }
12174: }
12175: } else {
12176: foreach my $type (@types) {
12177: if ($type eq 'community') {
12178: $roles{'1'} = &mt('Community personnel');
12179: } else {
12180: $roles{'1'} = &mt('Course personnel');
12181: }
12182: if (ref($changes{$key}{$type}) eq 'ARRAY') {
12183: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12184: if ($key eq 'admin') {
12185: my @mgrdc = ();
12186: if (ref($ordered{$key}) eq 'ARRAY') {
12187: foreach my $item (@{$ordered{'admin'}}) {
12188: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12189: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12190: push(@mgrdc,$item);
12191: }
12192: }
12193: }
12194: if (@mgrdc) {
12195: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12196: } else {
12197: delete($domdefaults{$type.'selfenrolladmdc'});
12198: }
12199: }
12200: } else {
12201: if (ref($ordered{$key}) eq 'ARRAY') {
12202: foreach my $item (@{$ordered{$key}}) {
12203: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12204: $domdefaults{$type.'selfenroll'.$item} =
12205: $selfenrollhash{$key}{$type}{$item};
12206: }
12207: }
12208: }
12209: }
12210: }
12211: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12212: foreach my $item (@{$ordered{$key}}) {
12213: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12214: $resulttext .= '<li>';
12215: if ($key eq 'admin') {
12216: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12217: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12218: } else {
12219: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12220: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12221: }
12222: $resulttext .= '</li>';
12223: }
12224: }
12225: $resulttext .= '</ul></li>';
12226: }
12227: }
12228: $resulttext .= '</ul></li>';
12229: }
12230: }
12231: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12232: my $cachetime = 24*60*60;
12233: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12234: if (ref($lastactref) eq 'HASH') {
12235: $lastactref->{'domdefaults'} = 1;
12236: }
12237: }
12238: }
12239: $resulttext .= '</ul>';
12240: } else {
12241: $resulttext = &mt('No changes made to self-enrollment settings');
12242: }
12243: } else {
12244: $resulttext = '<span class="LC_error">'.
12245: &mt('An error occurred: [_1]',$putresult).'</span>';
12246: }
12247: return $resulttext;
12248: }
12249:
1.137 raeburn 12250: sub modify_usersessions {
1.160.6.27 raeburn 12251: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12252: my @hostingtypes = ('version','excludedomain','includedomain');
12253: my @offloadtypes = ('primary','default');
12254: my %types = (
12255: remote => \@hostingtypes,
12256: hosted => \@hostingtypes,
12257: spares => \@offloadtypes,
12258: );
12259: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12260: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 12261: my (%by_ip,%by_location,@intdoms);
12262: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
12263: my @locations = sort(keys(%by_location));
1.137 raeburn 12264: my (%defaultshash,%changes);
12265: foreach my $prefix (@prefixes) {
12266: $defaultshash{'usersessions'}{$prefix} = {};
12267: }
1.160.6.27 raeburn 12268: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12269: my $resulttext;
1.138 raeburn 12270: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12271: foreach my $prefix (@prefixes) {
1.145 raeburn 12272: next if ($prefix eq 'spares');
12273: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12274: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12275: if ($type eq 'version') {
12276: my $value = $env{'form.'.$prefix.'_'.$type};
12277: my $okvalue;
12278: if ($value ne '') {
12279: if (grep(/^\Q$value\E$/,@lcversions)) {
12280: $okvalue = $value;
12281: }
12282: }
12283: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12284: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12285: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12286: if ($inuse == 0) {
12287: $changes{$prefix}{$type} = 1;
12288: } else {
12289: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12290: $changes{$prefix}{$type} = 1;
12291: }
12292: if ($okvalue ne '') {
12293: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12294: }
12295: }
12296: } else {
12297: if (($inuse == 1) && ($okvalue ne '')) {
12298: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12299: $changes{$prefix}{$type} = 1;
12300: }
12301: }
12302: } else {
12303: if (($inuse == 1) && ($okvalue ne '')) {
12304: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12305: $changes{$prefix}{$type} = 1;
12306: }
12307: }
12308: } else {
12309: if (($inuse == 1) && ($okvalue ne '')) {
12310: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12311: $changes{$prefix}{$type} = 1;
12312: }
12313: }
12314: } else {
12315: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12316: my @okvals;
12317: foreach my $val (@vals) {
1.138 raeburn 12318: if ($val =~ /:/) {
12319: my @items = split(/:/,$val);
12320: foreach my $item (@items) {
12321: if (ref($by_location{$item}) eq 'ARRAY') {
12322: push(@okvals,$item);
12323: }
12324: }
12325: } else {
12326: if (ref($by_location{$val}) eq 'ARRAY') {
12327: push(@okvals,$val);
12328: }
1.137 raeburn 12329: }
12330: }
12331: @okvals = sort(@okvals);
12332: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12333: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12334: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12335: if ($inuse == 0) {
12336: $changes{$prefix}{$type} = 1;
12337: } else {
12338: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12339: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12340: if (@changed > 0) {
12341: $changes{$prefix}{$type} = 1;
12342: }
12343: }
12344: } else {
12345: if ($inuse == 1) {
12346: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12347: $changes{$prefix}{$type} = 1;
12348: }
12349: }
12350: } else {
12351: if ($inuse == 1) {
12352: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12353: $changes{$prefix}{$type} = 1;
12354: }
12355: }
12356: } else {
12357: if ($inuse == 1) {
12358: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12359: $changes{$prefix}{$type} = 1;
12360: }
12361: }
12362: }
12363: }
12364: }
1.145 raeburn 12365:
12366: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12367: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12368: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12369: my $savespares;
12370:
12371: foreach my $lonhost (sort(keys(%servers))) {
12372: my $serverhomeID =
12373: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12374: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12375: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12376: my %spareschg;
12377: foreach my $type (@{$types{'spares'}}) {
12378: my @okspares;
12379: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12380: foreach my $server (@checked) {
1.152 raeburn 12381: if (&Apache::lonnet::hostname($server) ne '') {
12382: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12383: unless (grep(/^\Q$server\E$/,@okspares)) {
12384: push(@okspares,$server);
12385: }
1.145 raeburn 12386: }
12387: }
12388: }
12389: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12390: my $newspare;
1.152 raeburn 12391: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12392: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12393: $newspare = $new;
12394: }
12395: }
1.152 raeburn 12396: my @spares;
12397: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12398: @spares = sort(@okspares,$newspare);
12399: } else {
12400: @spares = sort(@okspares);
12401: }
12402: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12403: if (ref($spareid{$lonhost}) eq 'HASH') {
12404: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12405: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12406: if (@diffs > 0) {
12407: $spareschg{$type} = 1;
12408: }
12409: }
12410: }
12411: }
12412: if (keys(%spareschg) > 0) {
12413: $changes{'spares'}{$lonhost} = \%spareschg;
12414: }
12415: }
1.160.6.61 raeburn 12416: $defaultshash{'usersessions'}{'offloadnow'} = {};
12417: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12418: my @okoffload;
12419: if (@offloadnow) {
12420: foreach my $server (@offloadnow) {
12421: if (&Apache::lonnet::hostname($server) ne '') {
12422: unless (grep(/^\Q$server\E$/,@okoffload)) {
12423: push(@okoffload,$server);
12424: }
12425: }
12426: }
12427: if (@okoffload) {
12428: foreach my $lonhost (@okoffload) {
12429: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12430: }
12431: }
12432: }
1.145 raeburn 12433: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12434: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12435: if (ref($changes{'spares'}) eq 'HASH') {
12436: if (keys(%{$changes{'spares'}}) > 0) {
12437: $savespares = 1;
12438: }
12439: }
12440: } else {
12441: $savespares = 1;
12442: }
1.160.6.61 raeburn 12443: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12444: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12445: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12446: $changes{'offloadnow'} = 1;
12447: last;
12448: }
12449: }
12450: unless ($changes{'offloadnow'}) {
12451: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12452: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12453: $changes{'offloadnow'} = 1;
12454: last;
12455: }
12456: }
12457: }
12458: } elsif (@okoffload) {
12459: $changes{'offloadnow'} = 1;
12460: }
12461: } elsif (@okoffload) {
12462: $changes{'offloadnow'} = 1;
1.145 raeburn 12463: }
1.147 raeburn 12464: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12465: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12466: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12467: $dom);
12468: if ($putresult eq 'ok') {
12469: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12470: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12471: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12472: }
12473: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12474: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12475: }
1.160.6.61 raeburn 12476: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12477: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12478: }
1.137 raeburn 12479: }
12480: my $cachetime = 24*60*60;
12481: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81! raeburn 12482: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 12483: if (ref($lastactref) eq 'HASH') {
12484: $lastactref->{'domdefaults'} = 1;
1.160.6.81! raeburn 12485: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 12486: }
1.147 raeburn 12487: if (keys(%changes) > 0) {
12488: my %lt = &usersession_titles();
12489: $resulttext = &mt('Changes made:').'<ul>';
12490: foreach my $prefix (@prefixes) {
12491: if (ref($changes{$prefix}) eq 'HASH') {
12492: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12493: if ($prefix eq 'spares') {
12494: if (ref($changes{$prefix}) eq 'HASH') {
12495: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12496: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12497: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 12498: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12499: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12500: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12501: foreach my $type (@{$types{$prefix}}) {
12502: if ($changes{$prefix}{$lonhost}{$type}) {
12503: my $offloadto = &mt('None');
12504: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12505: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12506: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12507: }
1.145 raeburn 12508: }
1.147 raeburn 12509: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12510: }
1.137 raeburn 12511: }
12512: }
1.147 raeburn 12513: $resulttext .= '</li>';
1.137 raeburn 12514: }
12515: }
1.147 raeburn 12516: } else {
12517: foreach my $type (@{$types{$prefix}}) {
12518: if (defined($changes{$prefix}{$type})) {
12519: my $newvalue;
12520: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12521: if (ref($defaultshash{'usersessions'}{$prefix})) {
12522: if ($type eq 'version') {
12523: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12524: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12525: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12526: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12527: }
1.145 raeburn 12528: }
12529: }
12530: }
1.147 raeburn 12531: if ($newvalue eq '') {
12532: if ($type eq 'version') {
12533: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12534: } else {
12535: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12536: }
1.145 raeburn 12537: } else {
1.147 raeburn 12538: if ($type eq 'version') {
12539: $newvalue .= ' '.&mt('(or later)');
12540: }
12541: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12542: }
1.137 raeburn 12543: }
12544: }
12545: }
1.147 raeburn 12546: $resulttext .= '</ul>';
1.137 raeburn 12547: }
12548: }
1.160.6.61 raeburn 12549: if ($changes{'offloadnow'}) {
12550: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12551: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12552: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12553: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12554: $resulttext .= '<li>'.$lonhost.'</li>';
12555: }
12556: $resulttext .= '</ul>';
12557: } else {
12558: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12559: }
12560: } else {
12561: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12562: }
12563: }
1.147 raeburn 12564: $resulttext .= '</ul>';
12565: } else {
12566: $resulttext = $nochgmsg;
1.137 raeburn 12567: }
12568: } else {
12569: $resulttext = '<span class="LC_error">'.
12570: &mt('An error occurred: [_1]',$putresult).'</span>';
12571: }
12572: } else {
1.147 raeburn 12573: $resulttext = $nochgmsg;
1.137 raeburn 12574: }
12575: return $resulttext;
12576: }
12577:
1.150 raeburn 12578: sub modify_loadbalancing {
12579: my ($dom,%domconfig) = @_;
12580: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12581: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12582: my ($othertitle,$usertypes,$types) =
12583: &Apache::loncommon::sorted_inst_types($dom);
12584: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 12585: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12586: my @sparestypes = ('primary','default');
12587: my %typetitles = &sparestype_titles();
12588: my $resulttext;
1.160.6.7 raeburn 12589: my (%currbalancer,%currtargets,%currrules,%existing);
12590: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12591: %existing = %{$domconfig{'loadbalancing'}};
12592: }
12593: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12594: \%currtargets,\%currrules);
12595: my ($saveloadbalancing,%defaultshash,%changes);
12596: my ($alltypes,$othertypes,$titles) =
12597: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12598: my %ruletitles = &offloadtype_text();
12599: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12600: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12601: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12602: if ($balancer eq '') {
12603: next;
12604: }
12605: if (!exists($servers{$balancer})) {
12606: if (exists($currbalancer{$balancer})) {
12607: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 12608: }
1.160.6.7 raeburn 12609: next;
12610: }
12611: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12612: push(@{$changes{'delete'}},$balancer);
12613: next;
12614: }
12615: if (!exists($currbalancer{$balancer})) {
12616: push(@{$changes{'add'}},$balancer);
12617: }
12618: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12619: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12620: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12621: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12622: $saveloadbalancing = 1;
12623: }
12624: foreach my $sparetype (@sparestypes) {
12625: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12626: my @offloadto;
12627: foreach my $target (@targets) {
12628: if (($servers{$target}) && ($target ne $balancer)) {
12629: if ($sparetype eq 'default') {
12630: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12631: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 12632: }
12633: }
1.160.6.7 raeburn 12634: unless(grep(/^\Q$target\E$/,@offloadto)) {
12635: push(@offloadto,$target);
12636: }
1.150 raeburn 12637: }
12638: }
1.160.6.76 raeburn 12639: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
12640: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
12641: push(@offloadto,$balancer);
12642: }
12643: }
12644: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 12645: }
1.160.6.7 raeburn 12646: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 12647: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 12648: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12649: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 12650: if (@targetdiffs > 0) {
1.160.6.7 raeburn 12651: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12652: }
1.160.6.7 raeburn 12653: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12654: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12655: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12656: }
12657: }
12658: }
12659: } else {
1.160.6.7 raeburn 12660: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
12661: foreach my $sparetype (@sparestypes) {
12662: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12663: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12664: $changes{'curr'}{$balancer}{'targets'} = 1;
12665: }
1.150 raeburn 12666: }
12667: }
1.160.6.7 raeburn 12668: }
1.150 raeburn 12669: }
12670: my $ishomedom;
1.160.6.7 raeburn 12671: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12672: $ishomedom = 1;
1.150 raeburn 12673: }
12674: if (ref($alltypes) eq 'ARRAY') {
12675: foreach my $type (@{$alltypes}) {
12676: my $rule;
1.160.6.7 raeburn 12677: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 12678: (!$ishomedom)) {
1.160.6.7 raeburn 12679: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12680: }
12681: if ($rule eq 'specific') {
1.160.6.55 raeburn 12682: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12683: if (exists($servers{$specifiedhost})) {
12684: $rule = $specifiedhost;
12685: }
1.150 raeburn 12686: }
1.160.6.7 raeburn 12687: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12688: if (ref($currrules{$balancer}) eq 'HASH') {
12689: if ($rule ne $currrules{$balancer}{$type}) {
12690: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12691: }
12692: } elsif ($rule ne '') {
1.160.6.7 raeburn 12693: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12694: }
12695: }
12696: }
1.160.6.7 raeburn 12697: }
12698: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12699: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12700: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12701: $defaultshash{'loadbalancing'} = {};
12702: }
12703: my $putresult = &Apache::lonnet::put_dom('configuration',
12704: \%defaultshash,$dom);
12705: if ($putresult eq 'ok') {
12706: if (keys(%changes) > 0) {
1.160.6.54 raeburn 12707: my %toupdate;
1.160.6.7 raeburn 12708: if (ref($changes{'delete'}) eq 'ARRAY') {
12709: foreach my $balancer (sort(@{$changes{'delete'}})) {
12710: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 12711: $toupdate{$balancer} = 1;
1.150 raeburn 12712: }
1.160.6.7 raeburn 12713: }
12714: if (ref($changes{'add'}) eq 'ARRAY') {
12715: foreach my $balancer (sort(@{$changes{'add'}})) {
12716: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 12717: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12718: }
12719: }
12720: if (ref($changes{'curr'}) eq 'HASH') {
12721: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 12722: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12723: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12724: if ($changes{'curr'}{$balancer}{'targets'}) {
12725: my %offloadstr;
12726: foreach my $sparetype (@sparestypes) {
12727: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12728: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12729: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12730: }
12731: }
1.150 raeburn 12732: }
1.160.6.7 raeburn 12733: if (keys(%offloadstr) == 0) {
12734: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 12735: } else {
1.160.6.7 raeburn 12736: my $showoffload;
12737: foreach my $sparetype (@sparestypes) {
12738: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12739: if (defined($offloadstr{$sparetype})) {
12740: $showoffload .= $offloadstr{$sparetype};
12741: } else {
12742: $showoffload .= &mt('None');
12743: }
12744: $showoffload .= (' 'x3);
12745: }
12746: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 12747: }
12748: }
12749: }
1.160.6.7 raeburn 12750: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12751: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12752: foreach my $type (@{$alltypes}) {
12753: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12754: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12755: my $balancetext;
12756: if ($rule eq '') {
12757: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 12758: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 12759: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12760: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 12761: foreach my $sparetype (@sparestypes) {
12762: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12763: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12764: }
12765: }
1.160.6.55 raeburn 12766: foreach my $item (@{$alltypes}) {
12767: next if ($item =~ /^_LC_ipchange/);
12768: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
12769: if ($hasrule eq 'homeserver') {
12770: map { $toupdate{$_} = 1; } (keys(%libraryservers));
12771: } else {
12772: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
12773: if ($servers{$hasrule}) {
12774: $toupdate{$hasrule} = 1;
12775: }
12776: }
12777: }
12778: }
12779: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
12780: $balancetext = $ruletitles{$rule};
12781: } else {
12782: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12783: $balancetext = $ruletitles{'particular'}.' '.$receiver;
12784: if ($receiver) {
12785: $toupdate{$receiver};
12786: }
12787: }
12788: } else {
12789: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 12790: }
1.160.6.7 raeburn 12791: } else {
12792: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
12793: }
1.160.6.26 raeburn 12794: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 12795: }
12796: }
12797: }
12798: }
1.160.6.54 raeburn 12799: if (keys(%toupdate)) {
12800: my %thismachine;
12801: my $updatedhere;
12802: my $cachetime = 60*60*24;
12803: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12804: foreach my $lonhost (keys(%toupdate)) {
12805: if ($thismachine{$lonhost}) {
12806: unless ($updatedhere) {
12807: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
12808: $defaultshash{'loadbalancing'},
12809: $cachetime);
12810: $updatedhere = 1;
12811: }
12812: } else {
12813: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
12814: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
12815: }
12816: }
12817: }
1.150 raeburn 12818: }
1.160.6.7 raeburn 12819: }
12820: if ($resulttext ne '') {
12821: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 12822: } else {
12823: $resulttext = $nochgmsg;
12824: }
12825: } else {
1.160.6.7 raeburn 12826: $resulttext = $nochgmsg;
1.150 raeburn 12827: }
12828: } else {
1.160.6.7 raeburn 12829: $resulttext = '<span class="LC_error">'.
12830: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 12831: }
12832: } else {
1.160.6.7 raeburn 12833: $resulttext = $nochgmsg;
1.150 raeburn 12834: }
12835: return $resulttext;
12836: }
12837:
1.48 raeburn 12838: sub recurse_check {
12839: my ($chkcats,$categories,$depth,$name) = @_;
12840: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
12841: my $chg = 0;
12842: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
12843: my $category = $chkcats->[$depth]{$name}[$j];
12844: my $item;
12845: if ($category eq '') {
12846: $chg ++;
12847: } else {
12848: my $deeper = $depth + 1;
12849: $item = &escape($category).':'.&escape($name).':'.$depth;
12850: if ($chg) {
12851: $categories->{$item} -= $chg;
12852: }
12853: &recurse_check($chkcats,$categories,$deeper,$category);
12854: $deeper --;
12855: }
12856: }
12857: }
12858: return;
12859: }
12860:
12861: sub recurse_cat_deletes {
12862: my ($item,$coursecategories,$deletions) = @_;
12863: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12864: my $subdepth = $depth + 1;
12865: if (ref($coursecategories) eq 'HASH') {
12866: foreach my $subitem (keys(%{$coursecategories})) {
12867: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
12868: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
12869: delete($coursecategories->{$subitem});
12870: $deletions->{$subitem} = 1;
12871: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 12872: }
1.48 raeburn 12873: }
12874: }
12875: return;
12876: }
12877:
1.125 raeburn 12878: sub active_dc_picker {
1.160.6.16 raeburn 12879: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 12880: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 12881: my @domcoord = keys(%domcoords);
12882: if (keys(%currhash)) {
12883: foreach my $dc (keys(%currhash)) {
12884: unless (exists($domcoords{$dc})) {
12885: push(@domcoord,$dc);
12886: }
12887: }
12888: }
12889: @domcoord = sort(@domcoord);
12890: my $numdcs = scalar(@domcoord);
12891: my $rows = 0;
12892: my $table;
1.125 raeburn 12893: if ($numdcs > 1) {
1.160.6.16 raeburn 12894: $table = '<table>';
12895: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 12896: my $rem = $i%($numinrow);
12897: if ($rem == 0) {
12898: if ($i > 0) {
1.160.6.16 raeburn 12899: $table .= '</tr>';
1.125 raeburn 12900: }
1.160.6.16 raeburn 12901: $table .= '<tr>';
12902: $rows ++;
1.125 raeburn 12903: }
1.160.6.16 raeburn 12904: my $check = '';
12905: if ($inputtype eq 'radio') {
12906: if (keys(%currhash) == 0) {
12907: if (!$i) {
12908: $check = ' checked="checked"';
12909: }
12910: } elsif (exists($currhash{$domcoord[$i]})) {
12911: $check = ' checked="checked"';
12912: }
12913: } else {
12914: if (exists($currhash{$domcoord[$i]})) {
12915: $check = ' checked="checked"';
1.125 raeburn 12916: }
12917: }
1.160.6.16 raeburn 12918: if ($i == @domcoord - 1) {
1.125 raeburn 12919: my $colsleft = $numinrow - $rem;
12920: if ($colsleft > 1) {
1.160.6.16 raeburn 12921: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 12922: } else {
1.160.6.16 raeburn 12923: $table .= '<td class="LC_left_item">';
1.125 raeburn 12924: }
12925: } else {
1.160.6.16 raeburn 12926: $table .= '<td class="LC_left_item">';
12927: }
12928: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
12929: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
12930: $table .= '<span class="LC_nobreak"><label>'.
12931: '<input type="'.$inputtype.'" name="'.$name.'"'.
12932: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
12933: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 12934: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 12935: }
1.160.6.33 raeburn 12936: $table .= '</label></span></td>';
1.125 raeburn 12937: }
1.160.6.16 raeburn 12938: $table .= '</tr></table>';
12939: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 12940: my ($dcname,$dcdom) = split(':',$domcoord[0]);
12941: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 12942: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 12943: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 12944: if ($user ne $dcname.':'.$dcdom) {
12945: $table .= ' ('.$dcname.':'.$dcdom.')';
12946: }
1.160.6.16 raeburn 12947: } else {
12948: my $check;
12949: if (exists($currhash{$domcoord[0]})) {
12950: $check = ' checked="checked"';
12951: }
1.160.6.50 raeburn 12952: $table = '<span class="LC_nobreak"><label>'.
12953: '<input type="checkbox" name="'.$name.'" '.
12954: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 12955: if ($user ne $dcname.':'.$dcdom) {
12956: $table .= ' ('.$dcname.':'.$dcdom.')';
12957: }
12958: $table .= '</label></span>';
1.160.6.16 raeburn 12959: $rows ++;
12960: }
1.125 raeburn 12961: }
1.160.6.16 raeburn 12962: return ($numdcs,$table,$rows);
1.125 raeburn 12963: }
12964:
1.137 raeburn 12965: sub usersession_titles {
12966: return &Apache::lonlocal::texthash(
12967: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
12968: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 12969: spares => 'Servers offloaded to, when busy',
1.137 raeburn 12970: version => 'LON-CAPA version requirement',
1.138 raeburn 12971: excludedomain => 'Allow all, but exclude specific domains',
12972: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 12973: primary => 'Primary (checked first)',
1.154 raeburn 12974: default => 'Default',
1.137 raeburn 12975: );
12976: }
12977:
1.152 raeburn 12978: sub id_for_thisdom {
12979: my (%servers) = @_;
12980: my %altids;
12981: foreach my $server (keys(%servers)) {
12982: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
12983: if ($serverhome ne $server) {
12984: $altids{$serverhome} = $server;
12985: }
12986: }
12987: return %altids;
12988: }
12989:
1.150 raeburn 12990: sub count_servers {
12991: my ($currbalancer,%servers) = @_;
12992: my (@spares,$numspares);
12993: foreach my $lonhost (sort(keys(%servers))) {
12994: next if ($currbalancer eq $lonhost);
12995: push(@spares,$lonhost);
12996: }
12997: if ($currbalancer) {
12998: $numspares = scalar(@spares);
12999: } else {
13000: $numspares = scalar(@spares) - 1;
13001: }
13002: return ($numspares,@spares);
13003: }
13004:
13005: sub lonbalance_targets_js {
1.160.6.7 raeburn 13006: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13007: my $select = &mt('Select');
13008: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13009: if (ref($servers) eq 'HASH') {
13010: $alltargets = join("','",sort(keys(%{$servers})));
13011: my @homedoms;
13012: foreach my $server (sort(keys(%{$servers}))) {
13013: if (&Apache::lonnet::host_domain($server) eq $dom) {
13014: push(@homedoms,'1');
13015: } else {
13016: push(@homedoms,'0');
13017: }
13018: }
13019: $allishome = join("','",@homedoms);
13020: }
13021: if (ref($types) eq 'ARRAY') {
13022: if (@{$types} > 0) {
13023: @alltypes = @{$types};
13024: }
13025: }
13026: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13027: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 13028: my (%currbalancer,%currtargets,%currrules,%existing);
13029: if (ref($settings) eq 'HASH') {
13030: %existing = %{$settings};
13031: }
13032: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13033: \%currtargets,\%currrules);
13034: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13035: return <<"END";
13036:
13037: <script type="text/javascript">
13038: // <![CDATA[
13039:
1.160.6.7 raeburn 13040: currBalancers = new Array('$balancers');
13041:
13042: function toggleTargets(balnum) {
13043: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13044: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13045: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13046: var prevbalancer = prevhostitem.value;
13047: var baltotal = document.getElementById('loadbalancing_total').value;
13048: prevhostitem.value = balancer;
13049: if (prevbalancer != '') {
13050: var prevIdx = currBalancers.indexOf(prevbalancer);
13051: if (prevIdx != -1) {
13052: currBalancers.splice(prevIdx,1);
13053: }
13054: }
1.150 raeburn 13055: if (balancer == '') {
1.160.6.7 raeburn 13056: hideSpares(balnum);
1.150 raeburn 13057: } else {
1.160.6.7 raeburn 13058: var currIdx = currBalancers.indexOf(balancer);
13059: if (currIdx == -1) {
13060: currBalancers.push(balancer);
13061: }
1.150 raeburn 13062: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 13063: var ishomedom = homedoms[lonhostitem.selectedIndex];
13064: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13065: }
1.160.6.7 raeburn 13066: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13067: return;
13068: }
13069:
1.160.6.7 raeburn 13070: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13071: var alltargets = new Array('$alltargets');
13072: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13073: var offloadtypes = new Array('primary','default');
13074:
1.160.6.7 raeburn 13075: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13076: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13077:
1.151 raeburn 13078: for (var i=0; i<offloadtypes.length; i++) {
13079: var count = 0;
13080: for (var j=0; j<alltargets.length; j++) {
13081: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 13082: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13083: item.value = alltargets[j];
13084: item.style.textAlign='left';
13085: item.style.textFace='normal';
13086: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13087: if (currBalancers.indexOf(alltargets[j]) == -1) {
13088: item.disabled = '';
13089: } else {
13090: item.disabled = 'disabled';
13091: item.checked = false;
13092: }
1.151 raeburn 13093: count ++;
13094: }
1.150 raeburn 13095: }
13096: }
1.151 raeburn 13097: for (var k=0; k<insttypes.length; k++) {
13098: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13099: if (ishomedom == 1) {
1.160.6.7 raeburn 13100: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13101: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13102: } else {
1.160.6.7 raeburn 13103: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13104: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13105: }
13106: } else {
1.160.6.7 raeburn 13107: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13108: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13109: }
1.151 raeburn 13110: if ((insttypes[k] != '_LC_external') &&
13111: ((insttypes[k] != '_LC_internetdom') ||
13112: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 13113: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13114: item.options.length = 0;
13115: item.options[0] = new Option("","",true,true);
13116: var idx = 0;
1.151 raeburn 13117: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 13118: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13119: idx ++;
13120: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13121: }
13122: }
13123: }
13124: }
13125: return;
13126: }
13127:
1.160.6.7 raeburn 13128: function hideSpares(balnum) {
1.150 raeburn 13129: var alltargets = new Array('$alltargets');
13130: var insttypes = new Array('$allinsttypes');
13131: var offloadtypes = new Array('primary','default');
13132:
1.160.6.7 raeburn 13133: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13134: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13135:
13136: var total = alltargets.length - 1;
13137: for (var i=0; i<offloadtypes; i++) {
13138: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 13139: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13140: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13141: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13142: }
1.150 raeburn 13143: }
13144: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 13145: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13146: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13147: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 13148: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13149: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13150: }
13151: }
13152: return;
13153: }
13154:
1.160.6.7 raeburn 13155: function checkOffloads(item,balnum,type) {
1.150 raeburn 13156: var alltargets = new Array('$alltargets');
13157: var offloadtypes = new Array('primary','default');
13158: if (item.checked) {
13159: var total = alltargets.length - 1;
13160: var other;
13161: if (type == offloadtypes[0]) {
1.151 raeburn 13162: other = offloadtypes[1];
1.150 raeburn 13163: } else {
1.151 raeburn 13164: other = offloadtypes[0];
1.150 raeburn 13165: }
13166: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 13167: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13168: if (server == item.value) {
1.160.6.7 raeburn 13169: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13170: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13171: }
13172: }
13173: }
13174: }
13175: return;
13176: }
13177:
1.160.6.7 raeburn 13178: function singleServerToggle(balnum,type) {
13179: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13180: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 13181: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13182: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13183:
13184: } else {
1.160.6.7 raeburn 13185: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13186: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13187: }
13188: return;
13189: }
13190:
1.160.6.7 raeburn 13191: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13192: if (type == '_LC_external') {
1.160.6.26 raeburn 13193: return;
1.150 raeburn 13194: }
1.160.6.7 raeburn 13195: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13196: for (var i=0; i<typesRules.length; i++) {
13197: if (formname.elements[typesRules[i]].checked) {
13198: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 13199: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13200: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13201: } else {
1.160.6.7 raeburn 13202: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13203: }
13204: }
13205: }
13206: return;
13207: }
13208:
13209: function balancerDeleteChange(balnum) {
13210: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13211: var baltotal = document.getElementById('loadbalancing_total').value;
13212: var addtarget;
13213: var removetarget;
13214: var action = 'delete';
13215: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13216: var lonhost = hostitem.value;
13217: var currIdx = currBalancers.indexOf(lonhost);
13218: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13219: if (currIdx != -1) {
13220: currBalancers.splice(currIdx,1);
13221: }
13222: addtarget = lonhost;
13223: } else {
13224: if (currIdx == -1) {
13225: currBalancers.push(lonhost);
13226: }
13227: removetarget = lonhost;
13228: action = 'undelete';
13229: }
13230: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13231: }
13232: return;
13233: }
13234:
13235: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13236: if (baltotal > 1) {
13237: var offloadtypes = new Array('primary','default');
13238: var alltargets = new Array('$alltargets');
13239: var insttypes = new Array('$allinsttypes');
13240: for (var i=0; i<baltotal; i++) {
13241: if (i != balnum) {
13242: for (var j=0; j<offloadtypes.length; j++) {
13243: var total = alltargets.length - 1;
13244: for (var k=0; k<total; k++) {
13245: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13246: var server = serveritem.value;
13247: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13248: if (server == addtarget) {
13249: serveritem.disabled = '';
13250: }
13251: }
13252: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13253: if (server == removetarget) {
13254: serveritem.disabled = 'disabled';
13255: serveritem.checked = false;
13256: }
13257: }
13258: }
13259: }
13260: for (var j=0; j<insttypes.length; j++) {
13261: if (insttypes[j] != '_LC_external') {
13262: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13263: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13264: var currSel = singleserver.selectedIndex;
13265: var currVal = singleserver.options[currSel].value;
13266: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13267: var numoptions = singleserver.options.length;
13268: var needsnew = 1;
13269: for (var k=0; k<numoptions; k++) {
13270: if (singleserver.options[k] == addtarget) {
13271: needsnew = 0;
13272: break;
13273: }
13274: }
13275: if (needsnew == 1) {
13276: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13277: }
13278: }
13279: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13280: singleserver.options.length = 0;
13281: if ((currVal) && (currVal != removetarget)) {
13282: singleserver.options[0] = new Option("","",false,false);
13283: } else {
13284: singleserver.options[0] = new Option("","",true,true);
13285: }
13286: var idx = 0;
13287: for (var m=0; m<alltargets.length; m++) {
13288: if (currBalancers.indexOf(alltargets[m]) == -1) {
13289: idx ++;
13290: if (currVal == alltargets[m]) {
13291: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13292: } else {
13293: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13294: }
13295: }
13296: }
13297: }
13298: }
13299: }
13300: }
1.150 raeburn 13301: }
13302: }
13303: }
13304: return;
13305: }
13306:
1.152 raeburn 13307: // ]]>
13308: </script>
13309:
13310: END
13311: }
13312:
13313: sub new_spares_js {
13314: my @sparestypes = ('primary','default');
13315: my $types = join("','",@sparestypes);
13316: my $select = &mt('Select');
13317: return <<"END";
13318:
13319: <script type="text/javascript">
13320: // <![CDATA[
13321:
13322: function updateNewSpares(formname,lonhost) {
13323: var types = new Array('$types');
13324: var include = new Array();
13325: var exclude = new Array();
13326: for (var i=0; i<types.length; i++) {
13327: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13328: for (var j=0; j<spareboxes.length; j++) {
13329: if (formname.elements[spareboxes[j]].checked) {
13330: exclude.push(formname.elements[spareboxes[j]].value);
13331: } else {
13332: include.push(formname.elements[spareboxes[j]].value);
13333: }
13334: }
13335: }
13336: for (var i=0; i<types.length; i++) {
13337: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13338: var selIdx = newSpare.selectedIndex;
13339: var currnew = newSpare.options[selIdx].value;
13340: var okSpares = new Array();
13341: for (var j=0; j<newSpare.options.length; j++) {
13342: var possible = newSpare.options[j].value;
13343: if (possible != '') {
13344: if (exclude.indexOf(possible) == -1) {
13345: okSpares.push(possible);
13346: } else {
13347: if (currnew == possible) {
13348: selIdx = 0;
13349: }
13350: }
13351: }
13352: }
13353: for (var k=0; k<include.length; k++) {
13354: if (okSpares.indexOf(include[k]) == -1) {
13355: okSpares.push(include[k]);
13356: }
13357: }
13358: okSpares.sort();
13359: newSpare.options.length = 0;
13360: if (selIdx == 0) {
13361: newSpare.options[0] = new Option("$select","",true,true);
13362: } else {
13363: newSpare.options[0] = new Option("$select","",false,false);
13364: }
13365: for (var m=0; m<okSpares.length; m++) {
13366: var idx = m+1;
13367: var selThis = 0;
13368: if (selIdx != 0) {
13369: if (okSpares[m] == currnew) {
13370: selThis = 1;
13371: }
13372: }
13373: if (selThis == 1) {
13374: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13375: } else {
13376: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13377: }
13378: }
13379: }
13380: return;
13381: }
13382:
13383: function checkNewSpares(lonhost,type) {
13384: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13385: var chosen = newSpare.options[newSpare.selectedIndex].value;
13386: if (chosen != '') {
13387: var othertype;
13388: var othernewSpare;
13389: if (type == 'primary') {
13390: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13391: }
13392: if (type == 'default') {
13393: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13394: }
13395: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13396: othernewSpare.selectedIndex = 0;
13397: }
13398: }
13399: return;
13400: }
13401:
13402: // ]]>
13403: </script>
13404:
13405: END
13406:
13407: }
13408:
13409: sub common_domprefs_js {
13410: return <<"END";
13411:
13412: <script type="text/javascript">
13413: // <![CDATA[
13414:
1.150 raeburn 13415: function getIndicesByName(formname,item) {
1.152 raeburn 13416: var group = new Array();
1.150 raeburn 13417: for (var i=0;i<formname.elements.length;i++) {
13418: if (formname.elements[i].name == item) {
1.152 raeburn 13419: group.push(formname.elements[i].id);
1.150 raeburn 13420: }
13421: }
1.152 raeburn 13422: return group;
1.150 raeburn 13423: }
13424:
13425: // ]]>
13426: </script>
13427:
13428: END
1.152 raeburn 13429:
1.150 raeburn 13430: }
13431:
1.160.6.5 raeburn 13432: sub recaptcha_js {
13433: my %lt = &captcha_phrases();
13434: return <<"END";
13435:
13436: <script type="text/javascript">
13437: // <![CDATA[
13438:
13439: function updateCaptcha(caller,context) {
13440: var privitem;
13441: var pubitem;
13442: var privtext;
13443: var pubtext;
1.160.6.69 raeburn 13444: var versionitem;
13445: var versiontext;
1.160.6.5 raeburn 13446: if (document.getElementById(context+'_recaptchapub')) {
13447: pubitem = document.getElementById(context+'_recaptchapub');
13448: } else {
13449: return;
13450: }
13451: if (document.getElementById(context+'_recaptchapriv')) {
13452: privitem = document.getElementById(context+'_recaptchapriv');
13453: } else {
13454: return;
13455: }
13456: if (document.getElementById(context+'_recaptchapubtxt')) {
13457: pubtext = document.getElementById(context+'_recaptchapubtxt');
13458: } else {
13459: return;
13460: }
13461: if (document.getElementById(context+'_recaptchaprivtxt')) {
13462: privtext = document.getElementById(context+'_recaptchaprivtxt');
13463: } else {
13464: return;
13465: }
1.160.6.69 raeburn 13466: if (document.getElementById(context+'_recaptchaversion')) {
13467: versionitem = document.getElementById(context+'_recaptchaversion');
13468: } else {
13469: return;
13470: }
13471: if (document.getElementById(context+'_recaptchavertxt')) {
13472: versiontext = document.getElementById(context+'_recaptchavertxt');
13473: } else {
13474: return;
13475: }
1.160.6.5 raeburn 13476: if (caller.checked) {
13477: if (caller.value == 'recaptcha') {
13478: pubitem.type = 'text';
13479: privitem.type = 'text';
13480: pubitem.size = '40';
13481: privitem.size = '40';
13482: pubtext.innerHTML = "$lt{'pub'}";
13483: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 13484: versionitem.type = 'text';
13485: versionitem.size = '3';
13486: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 13487: } else {
13488: pubitem.type = 'hidden';
13489: privitem.type = 'hidden';
1.160.6.69 raeburn 13490: versionitem.type = 'hidden';
1.160.6.5 raeburn 13491: pubtext.innerHTML = '';
13492: privtext.innerHTML = '';
1.160.6.69 raeburn 13493: versiontext.innerHTML = '';
1.160.6.5 raeburn 13494: }
13495: }
13496: return;
13497: }
13498:
13499: // ]]>
13500: </script>
13501:
13502: END
13503:
13504: }
13505:
1.160.6.40 raeburn 13506: sub toggle_display_js {
1.160.6.16 raeburn 13507: return <<"END";
13508:
13509: <script type="text/javascript">
13510: // <![CDATA[
13511:
1.160.6.40 raeburn 13512: function toggleDisplay(domForm,caller) {
13513: if (document.getElementById(caller)) {
13514: var divitem = document.getElementById(caller);
13515: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 13516: var checkval = 1;
13517: var dispval = 'block';
1.160.6.40 raeburn 13518: if (caller == 'emailoptions') {
13519: optionsElement = domForm.cancreate_email;
13520: }
1.160.6.57 raeburn 13521: if (caller == 'studentsubmission') {
13522: optionsElement = domForm.postsubmit;
13523: }
1.160.6.64 raeburn 13524: if (caller == 'cloneinstcode') {
13525: optionsElement = domForm.canclone;
13526: checkval = 'instcode';
13527: }
1.160.6.40 raeburn 13528: if (optionsElement.length) {
1.160.6.16 raeburn 13529: var currval;
1.160.6.40 raeburn 13530: for (var i=0; i<optionsElement.length; i++) {
13531: if (optionsElement[i].checked) {
13532: currval = optionsElement[i].value;
1.160.6.16 raeburn 13533: }
13534: }
1.160.6.64 raeburn 13535: if (currval == checkval) {
13536: divitem.style.display = dispval;
1.160.6.16 raeburn 13537: } else {
1.160.6.40 raeburn 13538: divitem.style.display = 'none';
1.160.6.16 raeburn 13539: }
13540: }
13541: }
13542: return;
13543: }
13544:
13545: // ]]>
13546: </script>
13547:
13548: END
13549:
13550: }
13551:
1.160.6.5 raeburn 13552: sub captcha_phrases {
13553: return &Apache::lonlocal::texthash (
13554: priv => 'Private key',
13555: pub => 'Public key',
13556: original => 'original (CAPTCHA)',
13557: recaptcha => 'successor (ReCAPTCHA)',
13558: notused => 'unused',
1.160.6.69 raeburn 13559: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 13560: );
13561: }
13562:
1.160.6.24 raeburn 13563: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 13564: my ($dom,$cachekeys) = @_;
13565: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 13566: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13567: my %thismachine;
13568: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.81! raeburn 13569: my @posscached = ('domainconfig','domdefaults','usersessions','directorysrch');
1.160.6.61 raeburn 13570: if (keys(%servers)) {
1.160.6.24 raeburn 13571: foreach my $server (keys(%servers)) {
13572: next if ($thismachine{$server});
1.160.6.27 raeburn 13573: my @cached;
13574: foreach my $name (@posscached) {
13575: if ($cachekeys->{$name}) {
13576: push(@cached,&escape($name).':'.&escape($dom));
13577: }
13578: }
13579: if (@cached) {
13580: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13581: }
1.160.6.24 raeburn 13582: }
13583: }
13584: return;
13585: }
13586:
1.3 raeburn 13587: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>