Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.86
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.86! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.85 2017/10/15 17:15: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);
1.160.6.84 raeburn 3065: if (ref($settings) eq 'HASH') {
3066: if (ref($settings->{'adhoc'}) eq 'HASH') {
3067: %current = %{$settings->{'adhoc'}};
3068: }
1.160.6.77 raeburn 3069: }
3070: my $count = 0;
3071: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3072: if ($key=~/^rolesdef\_(\w+)$/) {
3073: my $rolename = $1;
1.160.6.77 raeburn 3074: my (%privs,$order);
1.160.6.73 raeburn 3075: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3076: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3077: if (ref($current{$rolename}) eq 'HASH') {
3078: $order = $current{$rolename}{'order'};
3079: }
3080: if ($order eq '') {
3081: $order = $count;
3082: }
3083: $ordered{$order} = $rolename;
3084: $count++;
1.160.6.73 raeburn 3085: }
3086: }
1.160.6.77 raeburn 3087: my $maxnum = scalar(keys(%ordered));
3088: my @roles_by_num = ();
3089: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3090: push(@roles_by_num,$item);
3091: }
3092: my $context = 'domprefs';
3093: my $crstype = 'Course';
3094: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3095: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3096: my ($numstatustypes,@jsarray);
3097: if (ref($types) eq 'ARRAY') {
3098: if (@{$types} > 0) {
3099: $numstatustypes = scalar(@{$types});
3100: push(@accesstypes,'status');
3101: @jsarray = ('bystatus');
3102: }
3103: }
1.160.6.86! raeburn 3104: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3105: if (keys(%domhelpdesk)) {
3106: push(@accesstypes,('inc','exc'));
3107: push(@jsarray,('notinc','notexc'));
3108: }
3109: my $hiddenstr = join("','",@jsarray);
3110: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3111: my $context = 'domprefs';
3112: my $crstype = 'Course';
1.160.6.77 raeburn 3113: my $prefix = 'helproles_';
3114: my $add_class = 'LC_hidden';
3115: foreach my $num (@roles_by_num) {
3116: my $role = $ordered{$num};
3117: my ($desc,$access,@statuses);
3118: if (ref($current{$role}) eq 'HASH') {
3119: $desc = $current{$role}{'desc'};
3120: $access = $current{$role}{'access'};
3121: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3122: @statuses = @{$current{$role}{'insttypes'}};
3123: }
3124: }
3125: if ($desc eq '') {
3126: $desc = $role;
3127: }
3128: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3129: my %full=();
3130: my %levels= (
3131: course => {},
3132: domain => {},
3133: system => {},
3134: );
3135: my %levelscurrent=(
3136: course => {},
3137: domain => {},
3138: system => {},
3139: );
3140: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3141: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3142: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3143: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3144: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3145: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3146: for (my $k=0; $k<=$maxnum; $k++) {
3147: my $vpos = $k+1;
3148: my $selstr;
3149: if ($k == $num) {
3150: $selstr = ' selected="selected" ';
3151: }
3152: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3153: }
3154: $datatable .= '</select>'.(' 'x2).
3155: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3156: '</td>'.
3157: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3158: &mt('Name shown to users:').
3159: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3160: '</fieldset>'.
3161: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3162: $othertitle,$usertypes,$types,\%domhelpdesk).
3163: '<fieldset>'.
3164: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3165: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3166: \%levelscurrent,$identifier,
3167: 'LC_hidden',$prefix.$num.'_privs').
3168: '</fieldset></td>';
1.160.6.73 raeburn 3169: $itemcount ++;
3170: }
3171: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3172: my $newcust = 'custhelp'.$count;
3173: my (%privs,%levelscurrent);
3174: my %full=();
3175: my %levels= (
3176: course => {},
3177: domain => {},
3178: system => {},
3179: );
3180: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3181: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3182: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3183: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3184: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3185: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3186: for (my $k=0; $k<$maxnum+1; $k++) {
3187: my $vpos = $k+1;
3188: my $selstr;
3189: if ($k == $maxnum) {
3190: $selstr = ' selected="selected" ';
3191: }
3192: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3193: }
3194: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3195: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3196: '</label></span></td>'.
1.160.6.77 raeburn 3197: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3198: '<span class="LC_nobreak">'.
3199: &mt('Internal name:').
3200: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3201: '</span>'.(' 'x4).
3202: '<span class="LC_nobreak">'.
3203: &mt('Name shown to users:').
3204: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3205: '</span></fieldset>'.
3206: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3207: $usertypes,$types,\%domhelpdesk).
3208: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3209: &Apache::lonuserutils::custom_role_header($context,$crstype,
3210: \@templateroles,$newcust).
3211: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3212: \%levelscurrent,$newcust).
1.160.6.77 raeburn 3213: '</fieldset></td></tr>';
1.160.6.73 raeburn 3214: $count ++;
3215: $$rowtotal += $count;
3216: }
1.160.6.5 raeburn 3217: return $datatable;
1.121 raeburn 3218: }
3219:
1.160.6.77 raeburn 3220: sub adhocbutton {
3221: my ($prefix,$num,$field,$visibility) = @_;
3222: my %lt = &Apache::lonlocal::texthash(
3223: show => 'Show details',
3224: hide => 'Hide details',
3225: );
3226: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3227: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3228: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3229: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3230: }
3231:
3232: sub helpsettings_javascript {
3233: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3234: return unless(ref($roles_by_num) eq 'ARRAY');
3235: my %html_js_lt = &Apache::lonlocal::texthash(
3236: show => 'Show details',
3237: hide => 'Hide details',
3238: );
3239: &html_escape(\%html_js_lt);
3240: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3241: return <<"ENDSCRIPT";
3242: <script type="text/javascript">
3243: // <![CDATA[
3244:
3245: function reorderHelpRoles(form,item) {
3246: var changedVal;
3247: $jstext
3248: var newpos = 'helproles_${total}_pos';
3249: var maxh = 1 + $total;
3250: var current = new Array();
3251: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3252: if (item == newpos) {
3253: changedVal = newitemVal;
3254: } else {
3255: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3256: current[newitemVal] = newpos;
3257: }
3258: for (var i=0; i<helproles.length; i++) {
3259: var elementName = 'helproles_'+helproles[i]+'_pos';
3260: if (elementName != item) {
3261: if (form.elements[elementName]) {
3262: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3263: current[currVal] = elementName;
3264: }
3265: }
3266: }
3267: var oldVal;
3268: for (var j=0; j<maxh; j++) {
3269: if (current[j] == undefined) {
3270: oldVal = j;
3271: }
3272: }
3273: if (oldVal < changedVal) {
3274: for (var k=oldVal+1; k<=changedVal ; k++) {
3275: var elementName = current[k];
3276: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3277: }
3278: } else {
3279: for (var k=changedVal; k<oldVal; k++) {
3280: var elementName = current[k];
3281: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3282: }
3283: }
3284: return;
3285: }
3286:
3287: function helpdeskAccess(num) {
3288: var curraccess = null;
3289: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3290: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3291: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3292: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3293: }
3294: }
3295: }
3296: var shown = Array();
3297: var hidden = Array();
3298: if (curraccess == 'none') {
3299: hidden = Array('$hiddenstr');
3300: } else {
3301: if (curraccess == 'status') {
3302: shown = Array('bystatus');
3303: hidden = Array('notinc','notexc');
3304: } else {
3305: if (curraccess == 'exc') {
3306: shown = Array('notexc');
3307: hidden = Array('notinc','bystatus');
3308: }
3309: if (curraccess == 'inc') {
3310: shown = Array('notinc');
3311: hidden = Array('notexc','bystatus');
3312: }
1.160.6.79 raeburn 3313: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3314: hidden = Array('notinc','notexc','bystatus');
3315: }
3316: }
3317: }
3318: if (hidden.length > 0) {
3319: for (var i=0; i<hidden.length; i++) {
3320: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3321: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3322: }
3323: }
3324: }
3325: if (shown.length > 0) {
3326: for (var i=0; i<shown.length; i++) {
3327: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3328: if (shown[i] == 'privs') {
3329: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3330: } else {
3331: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3332: }
3333: }
3334: }
3335: }
3336: return;
3337: }
3338:
3339: function toggleHelpdeskItem(num,field) {
3340: if (document.getElementById('helproles_'+num+'_'+field)) {
3341: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3342: document.getElementById('helproles_'+num+'_'+field).className =
3343: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3344: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3345: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3346: }
3347: } else {
3348: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3349: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3350: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3351: }
3352: }
3353: }
3354: return;
3355: }
3356:
3357: // ]]>
3358: </script>
3359:
3360: ENDSCRIPT
3361: }
3362:
3363: sub helpdeskroles_access {
3364: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3365: $usertypes,$types,$domhelpdesk) = @_;
3366: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3367: my %lt = &Apache::lonlocal::texthash(
3368: 'rou' => 'Role usage',
3369: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3370: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3371: 'dh' => 'All with domain helpdesk role',
3372: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3373: 'none' => 'None',
3374: 'status' => 'Determined based on institutional status',
3375: 'inc' => 'Include all, but exclude specific personnel',
3376: 'exc' => 'Exclude all, but include specific personnel',
3377: );
3378: my %usecheck = (
3379: all => ' checked="checked"',
3380: );
3381: my %displaydiv = (
3382: status => 'none',
3383: inc => 'none',
3384: exc => 'none',
3385: priv => 'block',
3386: );
3387: my $output;
3388: if (ref($current) eq 'HASH') {
3389: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3390: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3391: $usecheck{$current->{access}} = $usecheck{'all'};
3392: delete($usecheck{'all'});
3393: if ($current->{access} =~ /^(status|inc|exc)$/) {
3394: my $access = $1;
3395: $displaydiv{$access} = 'inline';
3396: } elsif ($current->{access} eq 'none') {
3397: $displaydiv{'priv'} = 'none';
3398: }
3399: }
3400: }
3401: }
3402: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3403: '<p>'.$lt{'whi'}.'</p>';
3404: foreach my $access (@{$accesstypes}) {
3405: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3406: ' onclick="helpdeskAccess('."'$num'".');" />'.
3407: $lt{$access}.'</label>';
3408: if ($access eq 'status') {
3409: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3410: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3411: $othertitle,$usertypes,$types).
3412: '</div>';
3413: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3414: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3415: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3416: '</div>';
3417: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3418: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3419: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3420: '</div>';
3421: }
3422: $output .= '</p>';
3423: }
3424: $output .= '</fieldset>';
3425: return $output;
3426: }
3427:
1.121 raeburn 3428: sub radiobutton_prefs {
1.160.6.16 raeburn 3429: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3430: $additional,$align) = @_;
1.121 raeburn 3431: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3432: (ref($choices) eq 'HASH'));
3433:
3434: my (%checkedon,%checkedoff,$datatable,$css_class);
3435:
3436: foreach my $item (@{$toggles}) {
3437: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3438: $checkedon{$item} = ' checked="checked" ';
3439: $checkedoff{$item} = ' ';
1.121 raeburn 3440: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3441: $checkedoff{$item} = ' checked="checked" ';
3442: $checkedon{$item} = ' ';
3443: }
3444: }
3445: if (ref($settings) eq 'HASH') {
1.121 raeburn 3446: foreach my $item (@{$toggles}) {
1.118 jms 3447: if ($settings->{$item} eq '1') {
3448: $checkedon{$item} = ' checked="checked" ';
3449: $checkedoff{$item} = ' ';
3450: } elsif ($settings->{$item} eq '0') {
3451: $checkedoff{$item} = ' checked="checked" ';
3452: $checkedon{$item} = ' ';
3453: }
3454: }
1.121 raeburn 3455: }
1.160.6.16 raeburn 3456: if ($onclick) {
3457: $onclick = ' onclick="'.$onclick.'"';
3458: }
1.121 raeburn 3459: foreach my $item (@{$toggles}) {
1.118 jms 3460: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3461: $datatable .=
1.160.6.16 raeburn 3462: '<tr'.$css_class.'><td valign="top">'.
3463: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3464: '</span></td>';
3465: if ($align eq 'left') {
3466: $datatable .= '<td class="LC_left_item">';
3467: } else {
3468: $datatable .= '<td class="LC_right_item">';
3469: }
3470: $datatable .=
3471: '<span class="LC_nobreak">'.
1.118 jms 3472: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3473: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3474: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3475: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3476: '</span>'.$additional.
3477: '</td>'.
1.118 jms 3478: '</tr>';
3479: $itemcount ++;
1.121 raeburn 3480: }
3481: return ($datatable,$itemcount);
3482: }
3483:
3484: sub print_coursedefaults {
1.139 raeburn 3485: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3486: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3487: my $itemcount = 1;
1.160.6.16 raeburn 3488: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3489: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3490: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3491: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3492: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3493: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3494: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3495: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3496: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3497: );
1.160.6.21 raeburn 3498: my %staticdefaults = (
3499: anonsurvey_threshold => 10,
3500: uploadquota => 500,
1.160.6.57 raeburn 3501: postsubmit => 60,
1.160.6.70 raeburn 3502: mysqltables => 172800,
1.160.6.21 raeburn 3503: );
1.139 raeburn 3504: if ($position eq 'top') {
1.160.6.57 raeburn 3505: %defaultchecked = (
3506: 'uselcmath' => 'on',
3507: 'usejsme' => 'on',
1.160.6.64 raeburn 3508: 'canclone' => 'none',
1.160.6.57 raeburn 3509: );
3510: @toggles = ('uselcmath','usejsme');
1.139 raeburn 3511: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3512: \%choices,$itemcount);
1.160.6.64 raeburn 3513: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3514: $datatable .=
3515: '<tr'.$css_class.'><td valign="top">'.
3516: '<span class="LC_nobreak">'.$choices{'canclone'}.
3517: '</span></td><td class="LC_left_item">';
3518: my $currcanclone = 'none';
3519: my $onclick;
3520: my @cloneoptions = ('none','domain');
3521: my %clonetitles = (
3522: none => 'No additional course requesters',
3523: domain => "Any course requester in course's domain",
3524: instcode => 'Course requests for official courses ...',
3525: );
3526: my (%codedefaults,@code_order,@posscodes);
3527: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3528: \@code_order) eq 'ok') {
3529: if (@code_order > 0) {
3530: push(@cloneoptions,'instcode');
3531: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3532: }
3533: }
3534: if (ref($settings) eq 'HASH') {
3535: if ($settings->{'canclone'}) {
3536: if (ref($settings->{'canclone'}) eq 'HASH') {
3537: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3538: if (@code_order > 0) {
3539: $currcanclone = 'instcode';
3540: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3541: }
3542: }
3543: } elsif ($settings->{'canclone'} eq 'domain') {
3544: $currcanclone = $settings->{'canclone'};
3545: }
3546: }
3547: }
3548: foreach my $option (@cloneoptions) {
3549: my ($checked,$additional);
3550: if ($currcanclone eq $option) {
3551: $checked = ' checked="checked"';
3552: }
3553: if ($option eq 'instcode') {
3554: if (@code_order) {
3555: my $show = 'none';
3556: if ($checked) {
3557: $show = 'block';
3558: }
3559: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3560: &mt('Institutional codes for new and cloned course have identical:').
3561: '<br />';
3562: foreach my $item (@code_order) {
3563: my $codechk;
3564: if ($checked) {
3565: if (grep(/^\Q$item\E$/,@posscodes)) {
3566: $codechk = ' checked="checked"';
3567: }
3568: }
3569: $additional .= '<label>'.
3570: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3571: $item.'</label>';
3572: }
3573: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3574: }
3575: }
3576: $datatable .=
3577: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3578: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3579: '</label> '.$additional.'</span><br />';
3580: }
3581: $datatable .= '</td>'.
3582: '</tr>';
3583: $itemcount ++;
1.139 raeburn 3584: } else {
3585: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3586: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3587: my $currusecredits = 0;
1.160.6.57 raeburn 3588: my $postsubmitclient = 1;
1.160.6.30 raeburn 3589: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3590: if (ref($settings) eq 'HASH') {
3591: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3592: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3593: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3594: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3595: }
3596: }
1.160.6.16 raeburn 3597: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3598: foreach my $type (@types) {
3599: next if ($type eq 'community');
3600: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3601: if ($defcredits{$type} ne '') {
3602: $currusecredits = 1;
3603: }
3604: }
3605: }
3606: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3607: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3608: $postsubmitclient = 0;
3609: foreach my $type (@types) {
3610: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3611: }
3612: } else {
3613: foreach my $type (@types) {
3614: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3615: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3616: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3617: } else {
3618: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3619: }
3620: } else {
3621: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3622: }
3623: }
3624: }
3625: } else {
3626: foreach my $type (@types) {
3627: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3628: }
3629: }
1.160.6.70 raeburn 3630: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3631: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3632: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3633: }
3634: } else {
3635: foreach my $type (@types) {
3636: $currmysql{$type} = $staticdefaults{'mysqltables'};
3637: }
3638: }
1.160.6.58 raeburn 3639: } else {
3640: foreach my $type (@types) {
3641: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3642: }
1.139 raeburn 3643: }
3644: if (!$currdefresponder) {
1.160.6.21 raeburn 3645: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3646: } elsif ($currdefresponder < 1) {
3647: $currdefresponder = 1;
3648: }
1.160.6.21 raeburn 3649: foreach my $type (@types) {
3650: if ($curruploadquota{$type} eq '') {
3651: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3652: }
3653: }
1.139 raeburn 3654: $datatable .=
1.160.6.16 raeburn 3655: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3656: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3657: '</span></td>'.
3658: '<td class="LC_right_item"><span class="LC_nobreak">'.
3659: '<input type="text" name="anonsurvey_threshold"'.
3660: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3661: '</td></tr>'."\n";
3662: $itemcount ++;
3663: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3664: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3665: $choices{'uploadquota'}.
3666: '</span></td>'.
3667: '<td align="right" class="LC_right_item">'.
3668: '<table><tr>';
1.160.6.21 raeburn 3669: foreach my $type (@types) {
3670: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3671: '<input type="text" name="uploadquota_'.$type.'"'.
3672: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3673: }
3674: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3675: $itemcount ++;
1.160.6.40 raeburn 3676: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3677: my $display = 'none';
3678: if ($currusecredits) {
3679: $display = 'block';
3680: }
3681: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3682: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3683: foreach my $type (@types) {
3684: next if ($type eq 'community');
3685: $additional .= '<td align="center">'.&mt($type).'<br />'.
3686: '<input type="text" name="'.$type.'_credits"'.
3687: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3688: }
3689: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3690: %defaultchecked = ('coursecredits' => 'off');
3691: @toggles = ('coursecredits');
3692: my $current = {
3693: 'coursecredits' => $currusecredits,
3694: };
3695: (my $table,$itemcount) =
3696: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3697: \%choices,$itemcount,$onclick,$additional,'left');
3698: $datatable .= $table;
3699: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3700: my $display = 'none';
3701: if ($postsubmitclient) {
3702: $display = 'block';
3703: }
3704: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3705: &mt('Number of seconds submit is disabled').'<br />'.
3706: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3707: '<table><tr>';
1.160.6.57 raeburn 3708: foreach my $type (@types) {
3709: $additional .= '<td align="center">'.&mt($type).'<br />'.
3710: '<input type="text" name="'.$type.'_timeout" value="'.
3711: $deftimeout{$type}.'" size="5" /></td>';
3712: }
3713: $additional .= '</tr></table></div>'."\n";
3714: %defaultchecked = ('postsubmit' => 'on');
3715: @toggles = ('postsubmit');
1.160.6.70 raeburn 3716: $current = {
3717: 'postsubmit' => $postsubmitclient,
3718: };
1.160.6.57 raeburn 3719: ($table,$itemcount) =
3720: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3721: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3722: $datatable .= $table;
1.160.6.70 raeburn 3723: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3724: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3725: $choices{'mysqltables'}.
3726: '</span></td>'.
3727: '<td align="right" class="LC_right_item">'.
3728: '<table><tr>';
3729: foreach my $type (@types) {
3730: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3731: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 3732: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 3733: }
3734: $datatable .= '</tr></table></td></tr>'."\n";
3735: $itemcount ++;
3736:
1.160.6.37 raeburn 3737: }
3738: $$rowtotal += $itemcount;
3739: return $datatable;
3740: }
3741:
3742: sub print_selfenrollment {
3743: my ($position,$dom,$settings,$rowtotal) = @_;
3744: my ($css_class,$datatable);
3745: my $itemcount = 1;
3746: my @types = ('official','unofficial','community','textbook');
3747: if (($position eq 'top') || ($position eq 'middle')) {
3748: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3749: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3750: my @rows;
3751: my $key;
3752: if ($position eq 'top') {
3753: $key = 'admin';
3754: if (ref($rowsref) eq 'ARRAY') {
3755: @rows = @{$rowsref};
3756: }
3757: } elsif ($position eq 'middle') {
3758: $key = 'default';
3759: @rows = ('types','registered','approval','limit');
3760: }
3761: foreach my $row (@rows) {
3762: if (defined($titlesref->{$row})) {
3763: $itemcount ++;
3764: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3765: $datatable .= '<tr'.$css_class.'>'.
3766: '<td>'.$titlesref->{$row}.'</td>'.
3767: '<td class="LC_left_item">'.
3768: '<table><tr>';
3769: my (%current,%currentcap);
3770: if (ref($settings) eq 'HASH') {
3771: if (ref($settings->{$key}) eq 'HASH') {
3772: foreach my $type (@types) {
3773: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3774: $current{$type} = $settings->{$key}->{$type}->{$row};
3775: }
3776: if (($row eq 'limit') && ($key eq 'default')) {
3777: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3778: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3779: }
3780: }
3781: }
3782: }
3783: }
3784: my %roles = (
3785: '0' => &Apache::lonnet::plaintext('dc'),
3786: );
3787:
3788: foreach my $type (@types) {
3789: unless (($row eq 'registered') && ($key eq 'default')) {
3790: $datatable .= '<th>'.&mt($type).'</th>';
3791: }
3792: }
3793: unless (($row eq 'registered') && ($key eq 'default')) {
3794: $datatable .= '</tr><tr>';
3795: }
3796: foreach my $type (@types) {
3797: if ($type eq 'community') {
3798: $roles{'1'} = &mt('Community personnel');
3799: } else {
3800: $roles{'1'} = &mt('Course personnel');
3801: }
3802: $datatable .= '<td style="vertical-align: top">';
3803: if ($position eq 'top') {
3804: my %checked;
3805: if ($current{$type} eq '0') {
3806: $checked{'0'} = ' checked="checked"';
3807: } else {
3808: $checked{'1'} = ' checked="checked"';
3809: }
3810: foreach my $role ('1','0') {
3811: $datatable .= '<span class="LC_nobreak"><label>'.
3812: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3813: 'value="'.$role.'"'.$checked{$role}.' />'.
3814: $roles{$role}.'</label></span> ';
3815: }
3816: } else {
3817: if ($row eq 'types') {
3818: my %checked;
3819: if ($current{$type} =~ /^(all|dom)$/) {
3820: $checked{$1} = ' checked="checked"';
3821: } else {
3822: $checked{''} = ' checked="checked"';
3823: }
3824: foreach my $val ('','dom','all') {
3825: $datatable .= '<span class="LC_nobreak"><label>'.
3826: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3827: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3828: }
3829: } elsif ($row eq 'registered') {
3830: my %checked;
3831: if ($current{$type} eq '1') {
3832: $checked{'1'} = ' checked="checked"';
3833: } else {
3834: $checked{'0'} = ' checked="checked"';
3835: }
3836: foreach my $val ('0','1') {
3837: $datatable .= '<span class="LC_nobreak"><label>'.
3838: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3839: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3840: }
3841: } elsif ($row eq 'approval') {
3842: my %checked;
3843: if ($current{$type} =~ /^([12])$/) {
3844: $checked{$1} = ' checked="checked"';
3845: } else {
3846: $checked{'0'} = ' checked="checked"';
3847: }
3848: for my $val (0..2) {
3849: $datatable .= '<span class="LC_nobreak"><label>'.
3850: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3851: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3852: }
3853: } elsif ($row eq 'limit') {
3854: my %checked;
3855: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3856: $checked{$1} = ' checked="checked"';
3857: } else {
3858: $checked{'none'} = ' checked="checked"';
3859: }
3860: my $cap;
3861: if ($currentcap{$type} =~ /^\d+$/) {
3862: $cap = $currentcap{$type};
3863: }
3864: foreach my $val ('none','allstudents','selfenrolled') {
3865: $datatable .= '<span class="LC_nobreak"><label>'.
3866: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3867: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3868: }
3869: $datatable .= '<br />'.
3870: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3871: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3872: '</span>';
3873: }
3874: }
3875: $datatable .= '</td>';
3876: }
3877: $datatable .= '</tr>';
3878: }
3879: $datatable .= '</table></td></tr>';
3880: }
3881: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3882: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3883: }
3884: $$rowtotal += $itemcount;
3885: return $datatable;
3886: }
3887:
3888: sub print_validation_rows {
3889: my ($caller,$dom,$settings,$rowtotal) = @_;
3890: my ($itemsref,$namesref,$fieldsref);
3891: if ($caller eq 'selfenroll') {
3892: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3893: } elsif ($caller eq 'requestcourses') {
3894: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3895: }
3896: my %currvalidation;
3897: if (ref($settings) eq 'HASH') {
3898: if (ref($settings->{'validation'}) eq 'HASH') {
3899: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3900: }
1.160.6.39 raeburn 3901: }
3902: my $datatable;
3903: my $itemcount = 0;
3904: foreach my $item (@{$itemsref}) {
3905: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3906: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3907: $namesref->{$item}.
3908: '</span></td>'.
3909: '<td class="LC_left_item">';
3910: if (($item eq 'url') || ($item eq 'button')) {
3911: $datatable .= '<span class="LC_nobreak">'.
3912: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3913: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3914: } elsif ($item eq 'fields') {
3915: my @currfields;
3916: if (ref($currvalidation{$item}) eq 'ARRAY') {
3917: @currfields = @{$currvalidation{$item}};
3918: }
3919: foreach my $field (@{$fieldsref}) {
3920: my $check = '';
3921: if (grep(/^\Q$field\E$/,@currfields)) {
3922: $check = ' checked="checked"';
3923: }
3924: $datatable .= '<span class="LC_nobreak"><label>'.
3925: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3926: ' value="'.$field.'"'.$check.' />'.$field.
3927: '</label></span> ';
3928: }
3929: } elsif ($item eq 'markup') {
3930: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3931: $currvalidation{$item}.
1.160.6.37 raeburn 3932: '</textarea>';
1.160.6.39 raeburn 3933: }
3934: $datatable .= '</td></tr>'."\n";
3935: if (ref($rowtotal)) {
1.160.6.37 raeburn 3936: $itemcount ++;
3937: }
1.139 raeburn 3938: }
1.160.6.39 raeburn 3939: if ($caller eq 'requestcourses') {
3940: my %currhash;
1.160.6.51 raeburn 3941: if (ref($settings) eq 'HASH') {
3942: if (ref($settings->{'validation'}) eq 'HASH') {
3943: if ($settings->{'validation'}{'dc'} ne '') {
3944: $currhash{$settings->{'validation'}{'dc'}} = 1;
3945: }
1.160.6.39 raeburn 3946: }
3947: }
3948: my $numinrow = 2;
3949: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3950: 'validationdc',%currhash);
1.160.6.50 raeburn 3951: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3952: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 3953: if ($numdc > 1) {
1.160.6.50 raeburn 3954: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3955: } else {
1.160.6.50 raeburn 3956: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3957: }
1.160.6.50 raeburn 3958: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3959: $itemcount ++;
3960: }
3961: if (ref($rowtotal)) {
3962: $$rowtotal += $itemcount;
3963: }
1.121 raeburn 3964: return $datatable;
1.118 jms 3965: }
3966:
1.137 raeburn 3967: sub print_usersessions {
3968: my ($position,$dom,$settings,$rowtotal) = @_;
3969: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3970: my (%by_ip,%by_location,@intdoms);
3971: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3972:
3973: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3974: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3975: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3976: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3977: my $itemcount = 1;
3978: if ($position eq 'top') {
1.152 raeburn 3979: if (keys(%serverhomes) > 1) {
1.145 raeburn 3980: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 3981: my $curroffloadnow;
3982: if (ref($settings) eq 'HASH') {
3983: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3984: $curroffloadnow = $settings->{'offloadnow'};
3985: }
3986: }
3987: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3988: } else {
1.140 raeburn 3989: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3990: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3991: }
1.137 raeburn 3992: } else {
1.145 raeburn 3993: if (keys(%by_location) == 0) {
3994: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3995: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3996: } else {
3997: my %lt = &usersession_titles();
3998: my $numinrow = 5;
3999: my $prefix;
4000: my @types;
4001: if ($position eq 'bottom') {
4002: $prefix = 'remote';
4003: @types = ('version','excludedomain','includedomain');
4004: } else {
4005: $prefix = 'hosted';
4006: @types = ('excludedomain','includedomain');
4007: }
4008: my (%current,%checkedon,%checkedoff);
4009: my @lcversions = &Apache::lonnet::all_loncaparevs();
4010: my @locations = sort(keys(%by_location));
4011: foreach my $type (@types) {
4012: $checkedon{$type} = '';
4013: $checkedoff{$type} = ' checked="checked"';
4014: }
4015: if (ref($settings) eq 'HASH') {
4016: if (ref($settings->{$prefix}) eq 'HASH') {
4017: foreach my $key (keys(%{$settings->{$prefix}})) {
4018: $current{$key} = $settings->{$prefix}{$key};
4019: if ($key eq 'version') {
4020: if ($current{$key} ne '') {
4021: $checkedon{$key} = ' checked="checked"';
4022: $checkedoff{$key} = '';
4023: }
4024: } elsif (ref($current{$key}) eq 'ARRAY') {
4025: $checkedon{$key} = ' checked="checked"';
4026: $checkedoff{$key} = '';
4027: }
1.137 raeburn 4028: }
4029: }
4030: }
1.145 raeburn 4031: foreach my $type (@types) {
4032: next if ($type ne 'version' && !@locations);
4033: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4034: $datatable .= '<tr'.$css_class.'>
4035: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4036: <span class="LC_nobreak">
4037: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4038: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4039: if ($type eq 'version') {
4040: my $selector = '<select name="'.$prefix.'_version">';
4041: foreach my $version (@lcversions) {
4042: my $selected = '';
4043: if ($current{'version'} eq $version) {
4044: $selected = ' selected="selected"';
4045: }
4046: $selector .= ' <option value="'.$version.'"'.
4047: $selected.'>'.$version.'</option>';
4048: }
4049: $selector .= '</select> ';
4050: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4051: } else {
4052: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4053: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4054: ' />'.(' 'x2).
4055: '<input type="button" value="'.&mt('uncheck all').'" '.
4056: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4057: "\n".
4058: '</div><div><table>';
4059: my $rem;
4060: for (my $i=0; $i<@locations; $i++) {
4061: my ($showloc,$value,$checkedtype);
4062: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4063: my $ip = $by_location{$locations[$i]}->[0];
4064: if (ref($by_ip{$ip}) eq 'ARRAY') {
4065: $value = join(':',@{$by_ip{$ip}});
4066: $showloc = join(', ',@{$by_ip{$ip}});
4067: if (ref($current{$type}) eq 'ARRAY') {
4068: foreach my $loc (@{$by_ip{$ip}}) {
4069: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4070: $checkedtype = ' checked="checked"';
4071: last;
4072: }
4073: }
1.138 raeburn 4074: }
4075: }
4076: }
1.145 raeburn 4077: $rem = $i%($numinrow);
4078: if ($rem == 0) {
4079: if ($i > 0) {
4080: $datatable .= '</tr>';
4081: }
4082: $datatable .= '<tr>';
4083: }
4084: $datatable .= '<td class="LC_left_item">'.
4085: '<span class="LC_nobreak"><label>'.
4086: '<input type="checkbox" name="'.$prefix.'_'.$type.
4087: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4088: '</label></span></td>';
1.137 raeburn 4089: }
1.145 raeburn 4090: $rem = @locations%($numinrow);
4091: my $colsleft = $numinrow - $rem;
4092: if ($colsleft > 1 ) {
4093: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4094: ' </td>';
4095: } elsif ($colsleft == 1) {
4096: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4097: }
1.145 raeburn 4098: $datatable .= '</tr></table>';
1.137 raeburn 4099: }
1.145 raeburn 4100: $datatable .= '</td></tr>';
4101: $itemcount ++;
1.137 raeburn 4102: }
4103: }
4104: }
4105: $$rowtotal += $itemcount;
4106: return $datatable;
4107: }
4108:
1.138 raeburn 4109: sub build_location_hashes {
4110: my ($intdoms,$by_ip,$by_location) = @_;
4111: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4112: (ref($by_location) eq 'HASH'));
4113: my %iphost = &Apache::lonnet::get_iphost();
4114: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4115: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4116: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4117: foreach my $id (@{$iphost{$primary_ip}}) {
4118: my $intdom = &Apache::lonnet::internet_dom($id);
4119: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4120: push(@{$intdoms},$intdom);
4121: }
4122: }
4123: }
4124: foreach my $ip (keys(%iphost)) {
4125: if (ref($iphost{$ip}) eq 'ARRAY') {
4126: foreach my $id (@{$iphost{$ip}}) {
4127: my $location = &Apache::lonnet::internet_dom($id);
4128: if ($location) {
4129: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4130: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4131: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4132: push(@{$by_ip->{$ip}},$location);
4133: }
4134: } else {
4135: $by_ip->{$ip} = [$location];
4136: }
4137: }
4138: }
4139: }
4140: }
4141: foreach my $ip (sort(keys(%{$by_ip}))) {
4142: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4143: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4144: my $first = $by_ip->{$ip}->[0];
4145: if (ref($by_location->{$first}) eq 'ARRAY') {
4146: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4147: push(@{$by_location->{$first}},$ip);
4148: }
4149: } else {
4150: $by_location->{$first} = [$ip];
4151: }
4152: }
4153: }
4154: return;
4155: }
4156:
1.145 raeburn 4157: sub current_offloads_to {
4158: my ($dom,$settings,$servers) = @_;
4159: my (%spareid,%otherdomconfigs);
1.152 raeburn 4160: if (ref($servers) eq 'HASH') {
1.145 raeburn 4161: foreach my $lonhost (sort(keys(%{$servers}))) {
4162: my $gotspares;
1.152 raeburn 4163: if (ref($settings) eq 'HASH') {
4164: if (ref($settings->{'spares'}) eq 'HASH') {
4165: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4166: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4167: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4168: $gotspares = 1;
4169: }
1.145 raeburn 4170: }
4171: }
4172: unless ($gotspares) {
4173: my $gotspares;
4174: my $serverhomeID =
4175: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4176: my $serverhomedom =
4177: &Apache::lonnet::host_domain($serverhomeID);
4178: if ($serverhomedom ne $dom) {
4179: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4180: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4181: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4182: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4183: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4184: $gotspares = 1;
4185: }
4186: }
4187: } else {
4188: $otherdomconfigs{$serverhomedom} =
4189: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4190: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4191: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4192: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4193: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4194: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4195: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4196: $gotspares = 1;
4197: }
4198: }
4199: }
4200: }
4201: }
4202: }
4203: }
4204: unless ($gotspares) {
4205: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4206: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4207: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4208: } else {
4209: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4210: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4211: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4212: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4213: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4214: } else {
1.150 raeburn 4215: my %what = (
4216: spareid => 1,
4217: );
4218: my ($result,$returnhash) =
4219: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4220: if ($result eq 'ok') {
4221: if (ref($returnhash) eq 'HASH') {
4222: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4223: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4224: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4225: }
4226: }
1.145 raeburn 4227: }
4228: }
4229: }
4230: }
4231: }
4232: }
4233: return %spareid;
4234: }
4235:
4236: sub spares_row {
1.160.6.61 raeburn 4237: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4238: my $css_class;
4239: my $numinrow = 4;
4240: my $itemcount = 1;
4241: my $datatable;
1.152 raeburn 4242: my %typetitles = &sparestype_titles();
4243: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4244: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4245: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4246: my ($othercontrol,$serverdom);
4247: if ($serverhome ne $server) {
4248: $serverdom = &Apache::lonnet::host_domain($serverhome);
4249: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4250: } else {
4251: $serverdom = &Apache::lonnet::host_domain($server);
4252: if ($serverdom ne $dom) {
4253: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4254: }
4255: }
4256: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4257: my $checkednow;
4258: if (ref($curroffloadnow) eq 'HASH') {
4259: if ($curroffloadnow->{$server}) {
4260: $checkednow = ' checked="checked"';
4261: }
4262: }
1.145 raeburn 4263: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4264: $datatable .= '<tr'.$css_class.'>
4265: <td rowspan="2">
1.160.6.13 raeburn 4266: <span class="LC_nobreak">'.
4267: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4268: ,'<b>'.$server.'</b>').'</span><br />'.
4269: '<span class="LC_nobreak">'."\n".
4270: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4271: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4272: "\n";
1.145 raeburn 4273: my (%current,%canselect);
1.152 raeburn 4274: my @choices =
4275: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4276: foreach my $type ('primary','default') {
4277: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4278: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4279: my @spares = @{$spareid->{$server}{$type}};
4280: if (@spares > 0) {
1.152 raeburn 4281: if ($othercontrol) {
4282: $current{$type} = join(', ',@spares);
4283: } else {
4284: $current{$type} .= '<table>';
4285: my $numspares = scalar(@spares);
4286: for (my $i=0; $i<@spares; $i++) {
4287: my $rem = $i%($numinrow);
4288: if ($rem == 0) {
4289: if ($i > 0) {
4290: $current{$type} .= '</tr>';
4291: }
4292: $current{$type} .= '<tr>';
1.145 raeburn 4293: }
1.152 raeburn 4294: $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'".');" /> '.
4295: $spareid->{$server}{$type}[$i].
4296: '</label></td>'."\n";
4297: }
4298: my $rem = @spares%($numinrow);
4299: my $colsleft = $numinrow - $rem;
4300: if ($colsleft > 1 ) {
4301: $current{$type} .= '<td colspan="'.$colsleft.
4302: '" class="LC_left_item">'.
4303: ' </td>';
4304: } elsif ($colsleft == 1) {
4305: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4306: }
1.152 raeburn 4307: $current{$type} .= '</tr></table>';
1.150 raeburn 4308: }
1.145 raeburn 4309: }
4310: }
4311: if ($current{$type} eq '') {
4312: $current{$type} = &mt('None specified');
4313: }
1.152 raeburn 4314: if ($othercontrol) {
4315: if ($type eq 'primary') {
4316: $canselect{$type} = $othercontrol;
4317: }
4318: } else {
4319: $canselect{$type} =
4320: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4321: '<select name="newspare_'.$type.'_'.$server.'" '.
4322: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4323: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4324: if (@choices > 0) {
4325: foreach my $lonhost (@choices) {
4326: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4327: }
4328: }
4329: $canselect{$type} .= '</select>'."\n";
4330: }
4331: } else {
4332: $current{$type} = &mt('Could not be determined');
4333: if ($type eq 'primary') {
4334: $canselect{$type} = $othercontrol;
4335: }
1.145 raeburn 4336: }
1.152 raeburn 4337: if ($type eq 'default') {
4338: $datatable .= '<tr'.$css_class.'>';
4339: }
4340: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4341: '<td>'.$current{$type}.'</td>'."\n".
4342: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4343: }
4344: $itemcount ++;
4345: }
4346: }
4347: $$rowtotal += $itemcount;
4348: return $datatable;
4349: }
4350:
1.152 raeburn 4351: sub possible_newspares {
4352: my ($server,$currspares,$serverhomes,$altids) = @_;
4353: my $serverhostname = &Apache::lonnet::hostname($server);
4354: my %excluded;
4355: if ($serverhostname ne '') {
4356: %excluded = (
4357: $serverhostname => 1,
4358: );
4359: }
4360: if (ref($currspares) eq 'HASH') {
4361: foreach my $type (keys(%{$currspares})) {
4362: if (ref($currspares->{$type}) eq 'ARRAY') {
4363: if (@{$currspares->{$type}} > 0) {
4364: foreach my $curr (@{$currspares->{$type}}) {
4365: my $hostname = &Apache::lonnet::hostname($curr);
4366: $excluded{$hostname} = 1;
4367: }
4368: }
4369: }
4370: }
4371: }
4372: my @choices;
4373: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4374: if (keys(%{$serverhomes}) > 1) {
4375: foreach my $name (sort(keys(%{$serverhomes}))) {
4376: unless ($excluded{$name}) {
4377: if (exists($altids->{$serverhomes->{$name}})) {
4378: push(@choices,$altids->{$serverhomes->{$name}});
4379: } else {
4380: push(@choices,$serverhomes->{$name});
1.145 raeburn 4381: }
4382: }
4383: }
4384: }
4385: }
1.152 raeburn 4386: return sort(@choices);
1.145 raeburn 4387: }
4388:
1.150 raeburn 4389: sub print_loadbalancing {
4390: my ($dom,$settings,$rowtotal) = @_;
4391: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4392: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4393: my $numinrow = 1;
4394: my $datatable;
4395: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 4396: my (%currbalancer,%currtargets,%currrules,%existing);
4397: if (ref($settings) eq 'HASH') {
4398: %existing = %{$settings};
4399: }
4400: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4401: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4402: \%currtargets,\%currrules);
1.150 raeburn 4403: } else {
4404: return;
4405: }
4406: my ($othertitle,$usertypes,$types) =
4407: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 4408: my $rownum = 8;
1.150 raeburn 4409: if (ref($types) eq 'ARRAY') {
4410: $rownum += scalar(@{$types});
4411: }
1.160.6.7 raeburn 4412: my @css_class = ('LC_odd_row','LC_even_row');
4413: my $balnum = 0;
4414: my $islast;
4415: my (@toshow,$disabledtext);
4416: if (keys(%currbalancer) > 0) {
4417: @toshow = sort(keys(%currbalancer));
4418: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4419: push(@toshow,'');
4420: }
4421: } else {
4422: @toshow = ('');
4423: $disabledtext = &mt('No existing load balancer');
4424: }
4425: foreach my $lonhost (@toshow) {
4426: if ($balnum == scalar(@toshow)-1) {
4427: $islast = 1;
4428: } else {
4429: $islast = 0;
4430: }
4431: my $cssidx = $balnum%2;
4432: my $targets_div_style = 'display: none';
4433: my $disabled_div_style = 'display: block';
4434: my $homedom_div_style = 'display: none';
4435: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4436: '<td rowspan="'.$rownum.'" valign="top">'.
4437: '<p>';
4438: if ($lonhost eq '') {
4439: $datatable .= '<span class="LC_nobreak">';
4440: if (keys(%currbalancer) > 0) {
4441: $datatable .= &mt('Add balancer:');
4442: } else {
4443: $datatable .= &mt('Enable balancer:');
4444: }
4445: $datatable .= ' '.
4446: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4447: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4448: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4449: '<option value="" selected="selected">'.&mt('None').
4450: '</option>'."\n";
4451: foreach my $server (sort(keys(%servers))) {
4452: next if ($currbalancer{$server});
4453: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4454: }
4455: $datatable .=
4456: '</select>'."\n".
4457: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4458: } else {
4459: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4460: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4461: &mt('Stop balancing').'</label>'.
4462: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4463: $targets_div_style = 'display: block';
4464: $disabled_div_style = 'display: none';
4465: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4466: $homedom_div_style = 'display: block';
4467: }
4468: }
4469: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4470: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4471: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4472: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4473: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4474: my @sparestypes = ('primary','default');
4475: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 4476: my %hostherechecked = (
4477: no => ' checked="checked"',
4478: );
1.160.6.7 raeburn 4479: foreach my $sparetype (@sparestypes) {
4480: my $targettable;
4481: for (my $i=0; $i<$numspares; $i++) {
4482: my $checked;
4483: if (ref($currtargets{$lonhost}) eq 'HASH') {
4484: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4485: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4486: $checked = ' checked="checked"';
4487: }
4488: }
4489: }
4490: my ($chkboxval,$disabled);
4491: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4492: $chkboxval = $spares[$i];
4493: }
4494: if (exists($currbalancer{$spares[$i]})) {
4495: $disabled = ' disabled="disabled"';
4496: }
4497: $targettable .=
1.160.6.55 raeburn 4498: '<td><span class="LC_nobreak"><label>'.
4499: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 4500: $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 4501: '</span></label></span></td>';
1.160.6.7 raeburn 4502: my $rem = $i%($numinrow);
4503: if ($rem == 0) {
4504: if (($i > 0) && ($i < $numspares-1)) {
4505: $targettable .= '</tr>';
4506: }
4507: if ($i < $numspares-1) {
4508: $targettable .= '<tr>';
1.150 raeburn 4509: }
4510: }
4511: }
1.160.6.7 raeburn 4512: if ($targettable ne '') {
4513: my $rem = $numspares%($numinrow);
4514: my $colsleft = $numinrow - $rem;
4515: if ($colsleft > 1 ) {
4516: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4517: ' </td>';
4518: } elsif ($colsleft == 1) {
4519: $targettable .= '<td class="LC_left_item"> </td>';
4520: }
4521: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4522: '<table><tr>'.$targettable.'</tr></table><br />';
4523: }
1.160.6.76 raeburn 4524: $hostherechecked{$sparetype} = '';
4525: if (ref($currtargets{$lonhost}) eq 'HASH') {
4526: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4527: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4528: $hostherechecked{$sparetype} = ' checked="checked"';
4529: $hostherechecked{'no'} = '';
4530: }
4531: }
4532: }
4533: }
4534: $datatable .= &mt('Hosting on balancer itself').'<br />'.
4535: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
4536: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
4537: foreach my $sparetype (@sparestypes) {
4538: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
4539: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
4540: '</i></label><br />';
1.160.6.7 raeburn 4541: }
4542: $datatable .= '</div></td></tr>'.
4543: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4544: $othertitle,$usertypes,$types,\%servers,
4545: \%currbalancer,$lonhost,
4546: $targets_div_style,$homedom_div_style,
4547: $css_class[$cssidx],$balnum,$islast);
4548: $$rowtotal += $rownum;
4549: $balnum ++;
4550: }
4551: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4552: return $datatable;
4553: }
4554:
4555: sub get_loadbalancers_config {
4556: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4557: return unless ((ref($servers) eq 'HASH') &&
4558: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4559: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4560: if (keys(%{$existing}) > 0) {
4561: my $oldlonhost;
4562: foreach my $key (sort(keys(%{$existing}))) {
4563: if ($key eq 'lonhost') {
4564: $oldlonhost = $existing->{'lonhost'};
4565: $currbalancer->{$oldlonhost} = 1;
4566: } elsif ($key eq 'targets') {
4567: if ($oldlonhost) {
4568: $currtargets->{$oldlonhost} = $existing->{'targets'};
4569: }
4570: } elsif ($key eq 'rules') {
4571: if ($oldlonhost) {
4572: $currrules->{$oldlonhost} = $existing->{'rules'};
4573: }
4574: } elsif (ref($existing->{$key}) eq 'HASH') {
4575: $currbalancer->{$key} = 1;
4576: $currtargets->{$key} = $existing->{$key}{'targets'};
4577: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4578: }
4579: }
1.160.6.7 raeburn 4580: } else {
4581: my ($balancerref,$targetsref) =
4582: &Apache::lonnet::get_lonbalancer_config($servers);
4583: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4584: foreach my $server (sort(keys(%{$balancerref}))) {
4585: $currbalancer->{$server} = 1;
4586: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4587: }
4588: }
4589: }
1.160.6.7 raeburn 4590: return;
1.150 raeburn 4591: }
4592:
4593: sub loadbalancing_rules {
4594: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 4595: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4596: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4597: my $output;
1.160.6.7 raeburn 4598: my $num = 0;
4599: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4600: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4601: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4602: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 4603: $num ++;
1.150 raeburn 4604: my $current;
4605: if (ref($currrules) eq 'HASH') {
4606: $current = $currrules->{$type};
4607: }
1.160.6.55 raeburn 4608: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 4609: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4610: $current = '';
4611: }
4612: }
4613: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 4614: $servers,$currbalancer,$lonhost,$dom,
4615: $targets_div_style,$homedom_div_style,
4616: $css_class,$balnum,$num,$islast);
1.150 raeburn 4617: }
4618: }
4619: return $output;
4620: }
4621:
4622: sub loadbalancing_titles {
4623: my ($dom,$intdom,$usertypes,$types) = @_;
4624: my %othertypes = (
4625: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4626: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4627: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4628: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 4629: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4630: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4631: );
1.160.6.26 raeburn 4632: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4633: if (ref($types) eq 'ARRAY') {
4634: unshift(@alltypes,@{$types},'default');
4635: }
4636: my %titles;
4637: foreach my $type (@alltypes) {
4638: if ($type =~ /^_LC_/) {
4639: $titles{$type} = $othertypes{$type};
4640: } elsif ($type eq 'default') {
4641: $titles{$type} = &mt('All users from [_1]',$dom);
4642: if (ref($types) eq 'ARRAY') {
4643: if (@{$types} > 0) {
4644: $titles{$type} = &mt('Other users from [_1]',$dom);
4645: }
4646: }
4647: } elsif (ref($usertypes) eq 'HASH') {
4648: $titles{$type} = $usertypes->{$type};
4649: }
4650: }
4651: return (\@alltypes,\%othertypes,\%titles);
4652: }
4653:
4654: sub loadbalance_rule_row {
1.160.6.7 raeburn 4655: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4656: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4657: my @rulenames;
1.150 raeburn 4658: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4659: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4660: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4661: } else {
1.160.6.26 raeburn 4662: @rulenames = ('default','homeserver');
4663: if ($type eq '_LC_external') {
4664: push(@rulenames,'externalbalancer');
4665: } else {
4666: push(@rulenames,'specific');
4667: }
4668: push(@rulenames,'none');
1.150 raeburn 4669: }
4670: my $style = $targets_div_style;
1.160.6.55 raeburn 4671: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4672: $style = $homedom_div_style;
4673: }
1.160.6.7 raeburn 4674: my $space;
4675: if ($islast && $num == 1) {
4676: $space = '<div display="inline-block"> </div>';
4677: }
4678: my $output =
4679: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4680: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4681: '<td valaign="top">'.$space.
4682: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4683: for (my $i=0; $i<@rulenames; $i++) {
4684: my $rule = $rulenames[$i];
4685: my ($checked,$extra);
4686: if ($rulenames[$i] eq 'default') {
4687: $rule = '';
4688: }
4689: if ($rulenames[$i] eq 'specific') {
4690: if (ref($servers) eq 'HASH') {
4691: my $default;
4692: if (($current ne '') && (exists($servers->{$current}))) {
4693: $checked = ' checked="checked"';
4694: }
4695: unless ($checked) {
4696: $default = ' selected="selected"';
4697: }
1.160.6.7 raeburn 4698: $extra =
4699: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4700: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4701: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4702: '<option value=""'.$default.'></option>'."\n";
4703: foreach my $server (sort(keys(%{$servers}))) {
4704: if (ref($currbalancer) eq 'HASH') {
4705: next if (exists($currbalancer->{$server}));
4706: }
1.150 raeburn 4707: my $selected;
1.160.6.7 raeburn 4708: if ($server eq $current) {
1.150 raeburn 4709: $selected = ' selected="selected"';
4710: }
1.160.6.7 raeburn 4711: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4712: }
4713: $extra .= '</select>';
4714: }
4715: } elsif ($rule eq $current) {
4716: $checked = ' checked="checked"';
4717: }
4718: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4719: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4720: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4721: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4722: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4723: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4724: $output .= $ruletitles{'particular'};
4725: } else {
4726: $output .= $ruletitles{$rulenames[$i]};
4727: }
4728: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4729: }
4730: $output .= '</div></td></tr>'."\n";
4731: return $output;
4732: }
4733:
4734: sub offloadtype_text {
4735: my %ruletitles = &Apache::lonlocal::texthash (
4736: 'default' => 'Offloads to default destinations',
4737: 'homeserver' => "Offloads to user's home server",
4738: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4739: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4740: 'none' => 'No offload',
1.160.6.26 raeburn 4741: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4742: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4743: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4744: );
4745: return %ruletitles;
4746: }
4747:
4748: sub sparestype_titles {
4749: my %typestitles = &Apache::lonlocal::texthash (
4750: 'primary' => 'primary',
4751: 'default' => 'default',
4752: );
4753: return %typestitles;
4754: }
4755:
1.28 raeburn 4756: sub contact_titles {
4757: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 4758: 'supportemail' => 'Support E-mail address',
4759: 'adminemail' => 'Default Server Admin E-mail address',
4760: 'errormail' => 'Error reports to be e-mailed to',
4761: 'packagesmail' => 'Package update alerts to be e-mailed to',
4762: 'helpdeskmail' => "Helpdesk requests for this domain's users",
4763: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
4764: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
4765: 'requestsmail' => 'E-mail from course requests requiring approval',
4766: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4767: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4768: );
4769: my %short_titles = &Apache::lonlocal::texthash (
4770: adminemail => 'Admin E-mail address',
4771: supportemail => 'Support E-mail',
4772: );
4773: return (\%titles,\%short_titles);
4774: }
4775:
1.160.6.78 raeburn 4776: sub helpform_fields {
4777: my %titles = &Apache::lonlocal::texthash (
4778: 'username' => 'Name',
4779: 'user' => 'Username/domain',
4780: 'phone' => 'Phone',
4781: 'cc' => 'Cc e-mail',
4782: 'course' => 'Course Details',
4783: 'section' => 'Sections',
4784: 'screenshot' => 'File upload',
4785: );
4786: my @fields = ('username','phone','user','course','section','cc','screenshot');
4787: my %possoptions = (
4788: username => ['yes','no','req'],
4789: phone => ['yes','no','req'],
4790: user => ['yes','no'],
4791: cc => ['yes','no'],
4792: course => ['yes','no'],
4793: section => ['yes','no'],
4794: screenshot => ['yes','no'],
4795: );
4796: my %fieldoptions = &Apache::lonlocal::texthash (
4797: 'yes' => 'Optional',
4798: 'req' => 'Required',
4799: 'no' => "Not shown",
4800: );
4801: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
4802: }
4803:
1.72 raeburn 4804: sub tool_titles {
4805: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4806: aboutme => 'Personal web page',
1.86 raeburn 4807: blog => 'Blog',
1.160.6.4 raeburn 4808: webdav => 'WebDAV',
1.86 raeburn 4809: portfolio => 'Portfolio',
1.88 bisitz 4810: official => 'Official courses (with institutional codes)',
4811: unofficial => 'Unofficial courses',
1.98 raeburn 4812: community => 'Communities',
1.160.6.30 raeburn 4813: textbook => 'Textbook courses',
1.86 raeburn 4814: );
1.72 raeburn 4815: return %titles;
4816: }
4817:
1.101 raeburn 4818: sub courserequest_titles {
4819: my %titles = &Apache::lonlocal::texthash (
4820: official => 'Official',
4821: unofficial => 'Unofficial',
4822: community => 'Communities',
1.160.6.30 raeburn 4823: textbook => 'Textbook',
1.101 raeburn 4824: norequest => 'Not allowed',
1.104 raeburn 4825: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4826: validate => 'With validation',
4827: autolimit => 'Numerical limit',
1.103 raeburn 4828: unlimited => '(blank for unlimited)',
1.101 raeburn 4829: );
4830: return %titles;
4831: }
4832:
1.160.6.5 raeburn 4833: sub authorrequest_titles {
4834: my %titles = &Apache::lonlocal::texthash (
4835: norequest => 'Not allowed',
4836: approval => 'Approval by Dom. Coord.',
4837: automatic => 'Automatic approval',
4838: );
4839: return %titles;
4840: }
4841:
1.101 raeburn 4842: sub courserequest_conditions {
4843: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4844: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4845: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4846: );
4847: return %conditions;
4848: }
4849:
4850:
1.27 raeburn 4851: sub print_usercreation {
1.30 raeburn 4852: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4853: my $numinrow = 4;
1.28 raeburn 4854: my $datatable;
4855: if ($position eq 'top') {
1.30 raeburn 4856: $$rowtotal ++;
1.34 raeburn 4857: my $rowcount = 0;
1.32 raeburn 4858: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4859: if (ref($rules) eq 'HASH') {
4860: if (keys(%{$rules}) > 0) {
1.32 raeburn 4861: $datatable .= &user_formats_row('username',$settings,$rules,
4862: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4863: $$rowtotal ++;
1.32 raeburn 4864: $rowcount ++;
4865: }
4866: }
4867: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4868: if (ref($idrules) eq 'HASH') {
4869: if (keys(%{$idrules}) > 0) {
4870: $datatable .= &user_formats_row('id',$settings,$idrules,
4871: $idruleorder,$numinrow,$rowcount);
4872: $$rowtotal ++;
4873: $rowcount ++;
1.28 raeburn 4874: }
4875: }
1.39 raeburn 4876: if ($rowcount == 0) {
4877: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4878: $$rowtotal ++;
4879: $rowcount ++;
4880: }
1.34 raeburn 4881: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4882: my @creators = ('author','course','requestcrs');
1.37 raeburn 4883: my ($rules,$ruleorder) =
4884: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4885: my %lt = &usercreation_types();
4886: my %checked;
4887: if (ref($settings) eq 'HASH') {
4888: if (ref($settings->{'cancreate'}) eq 'HASH') {
4889: foreach my $item (@creators) {
4890: $checked{$item} = $settings->{'cancreate'}{$item};
4891: }
4892: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4893: foreach my $item (@creators) {
4894: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4895: $checked{$item} = 'none';
4896: }
4897: }
4898: }
4899: }
4900: my $rownum = 0;
4901: foreach my $item (@creators) {
4902: $rownum ++;
1.160.6.34 raeburn 4903: if ($checked{$item} eq '') {
4904: $checked{$item} = 'any';
1.34 raeburn 4905: }
4906: my $css_class;
4907: if ($rownum%2) {
4908: $css_class = '';
4909: } else {
4910: $css_class = ' class="LC_odd_row" ';
4911: }
4912: $datatable .= '<tr'.$css_class.'>'.
4913: '<td><span class="LC_nobreak">'.$lt{$item}.
4914: '</span></td><td align="right">';
1.160.6.34 raeburn 4915: my @options = ('any');
4916: if (ref($rules) eq 'HASH') {
4917: if (keys(%{$rules}) > 0) {
4918: push(@options,('official','unofficial'));
1.37 raeburn 4919: }
4920: }
1.160.6.34 raeburn 4921: push(@options,'none');
1.37 raeburn 4922: foreach my $option (@options) {
1.50 raeburn 4923: my $type = 'radio';
1.34 raeburn 4924: my $check = ' ';
1.160.6.34 raeburn 4925: if ($checked{$item} eq $option) {
4926: $check = ' checked="checked" ';
1.34 raeburn 4927: }
4928: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4929: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4930: $item.'" value="'.$option.'"'.$check.'/> '.
4931: $lt{$option}.'</label> </span>';
4932: }
4933: $datatable .= '</td></tr>';
4934: }
1.28 raeburn 4935: } else {
4936: my @contexts = ('author','course','domain');
4937: my @authtypes = ('int','krb4','krb5','loc');
4938: my %checked;
4939: if (ref($settings) eq 'HASH') {
4940: if (ref($settings->{'authtypes'}) eq 'HASH') {
4941: foreach my $item (@contexts) {
4942: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4943: foreach my $auth (@authtypes) {
4944: if ($settings->{'authtypes'}{$item}{$auth}) {
4945: $checked{$item}{$auth} = ' checked="checked" ';
4946: }
4947: }
4948: }
4949: }
1.27 raeburn 4950: }
1.35 raeburn 4951: } else {
4952: foreach my $item (@contexts) {
1.36 raeburn 4953: foreach my $auth (@authtypes) {
1.35 raeburn 4954: $checked{$item}{$auth} = ' checked="checked" ';
4955: }
4956: }
1.27 raeburn 4957: }
1.28 raeburn 4958: my %title = &context_names();
4959: my %authname = &authtype_names();
4960: my $rownum = 0;
4961: my $css_class;
4962: foreach my $item (@contexts) {
4963: if ($rownum%2) {
4964: $css_class = '';
4965: } else {
4966: $css_class = ' class="LC_odd_row" ';
4967: }
1.30 raeburn 4968: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4969: '<td>'.$title{$item}.
4970: '</td><td class="LC_left_item">'.
4971: '<span class="LC_nobreak">';
4972: foreach my $auth (@authtypes) {
4973: $datatable .= '<label>'.
4974: '<input type="checkbox" name="'.$item.'_auth" '.
4975: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4976: $authname{$auth}.'</label> ';
4977: }
4978: $datatable .= '</span></td></tr>';
4979: $rownum ++;
1.27 raeburn 4980: }
1.30 raeburn 4981: $$rowtotal += $rownum;
1.27 raeburn 4982: }
4983: return $datatable;
4984: }
4985:
1.160.6.34 raeburn 4986: sub print_selfcreation {
4987: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4988: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4989: if (ref($settings) eq 'HASH') {
4990: if (ref($settings->{'cancreate'}) eq 'HASH') {
4991: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4992: if (ref($createsettings) eq 'HASH') {
4993: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4994: @selfcreate = @{$createsettings->{'selfcreate'}};
4995: } elsif ($createsettings->{'selfcreate'} ne '') {
4996: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4997: @selfcreate = ('email','login','sso');
4998: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4999: @selfcreate = ($createsettings->{'selfcreate'});
5000: }
5001: }
5002: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5003: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5004: }
5005: }
5006: }
5007: }
5008: my %radiohash;
5009: my $numinrow = 4;
5010: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5011: if ($position eq 'top') {
5012: my %choices = &Apache::lonlocal::texthash (
5013: cancreate_login => 'Institutional Login',
5014: cancreate_sso => 'Institutional Single Sign On',
5015: );
5016: my @toggles = sort(keys(%choices));
5017: my %defaultchecked = (
5018: 'cancreate_login' => 'off',
5019: 'cancreate_sso' => 'off',
5020: );
1.160.6.35 raeburn 5021: my ($onclick,$itemcount);
1.160.6.34 raeburn 5022: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5023: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5024: $$rowtotal += $itemcount;
1.160.6.39 raeburn 5025:
1.160.6.34 raeburn 5026: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5027:
5028: if (ref($usertypes) eq 'HASH') {
5029: if (keys(%{$usertypes}) > 0) {
5030: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5031: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 5032: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 5033: $$rowtotal ++;
5034: }
5035: }
1.160.6.44 raeburn 5036: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5037: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5038: $fieldtitles{'inststatus'} = &mt('Institutional status');
5039: my $rem;
5040: my $numperrow = 2;
5041: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5042: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5043: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5044: '<td class="LC_left_item">'."\n".
5045: '<table><tr><td>'."\n";
5046: for (my $i=0; $i<@fields; $i++) {
5047: $rem = $i%($numperrow);
5048: if ($rem == 0) {
5049: if ($i > 0) {
5050: $datatable .= '</tr>';
5051: }
5052: $datatable .= '<tr>';
5053: }
5054: my $currval;
1.160.6.51 raeburn 5055: if (ref($createsettings) eq 'HASH') {
5056: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5057: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5058: }
1.160.6.44 raeburn 5059: }
5060: $datatable .= '<td class="LC_left_item">'.
5061: '<span class="LC_nobreak">'.
5062: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5063: 'value="'.$currval.'" size="10" /> '.
5064: $fieldtitles{$fields[$i]}.'</span></td>';
5065: }
5066: my $colsleft = $numperrow - $rem;
5067: if ($colsleft > 1 ) {
5068: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5069: ' </td>';
5070: } elsif ($colsleft == 1) {
5071: $datatable .= '<td class="LC_left_item"> </td>';
5072: }
5073: $datatable .= '</tr></table></td></tr>';
5074: $$rowtotal ++;
1.160.6.34 raeburn 5075: } elsif ($position eq 'middle') {
5076: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5077: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5078: $usertypes->{'default'} = $othertitle;
5079: if (ref($types) eq 'ARRAY') {
5080: push(@{$types},'default');
5081: $usertypes->{'default'} = $othertitle;
5082: foreach my $status (@{$types}) {
5083: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 5084: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 5085: $$rowtotal ++;
1.160.6.34 raeburn 5086: }
5087: }
5088: } else {
1.160.6.40 raeburn 5089: my %choices = &Apache::lonlocal::texthash (
5090: cancreate_email => 'E-mail address as username',
5091: );
5092: my @toggles = sort(keys(%choices));
5093: my %defaultchecked = (
5094: 'cancreate_email' => 'off',
5095: );
5096: my $itemcount = 0;
5097: my $display = 'none';
5098: if (grep(/^\Qemail\E$/,@selfcreate)) {
5099: $display = 'block';
5100: }
5101: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5102: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5103: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5104: my $usertypes = {};
5105: my $order = [];
5106: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5107: $usertypes = $domdefaults{'inststatustypes'};
5108: $order = $domdefaults{'inststatusguest'};
5109: }
5110: if (ref($order) eq 'ARRAY') {
5111: push(@{$order},'default');
5112: if (@{$order} > 1) {
5113: $usertypes->{'default'} = &mt('Other users');
5114: $additional .= '<table><tr>';
5115: foreach my $status (@{$order}) {
5116: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5117: }
5118: $additional .= '</tr><tr>';
5119: foreach my $status (@{$order}) {
5120: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 5121: }
1.160.6.40 raeburn 5122: $additional .= '</tr></table>';
1.160.6.34 raeburn 5123: } else {
1.160.6.40 raeburn 5124: $usertypes->{'default'} = &mt('All users');
5125: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 5126: }
5127: }
1.160.6.40 raeburn 5128: $additional .= '</div>'."\n";
5129:
5130: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 5131: \%choices,$$rowtotal,$onclick,$additional);
5132: $$rowtotal ++;
1.160.6.40 raeburn 5133: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 5134: $$rowtotal ++;
1.160.6.35 raeburn 5135: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5136: $numinrow = 1;
1.160.6.40 raeburn 5137: if (ref($order) eq 'ARRAY') {
5138: foreach my $status (@{$order}) {
1.160.6.35 raeburn 5139: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5140: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5141: $$rowtotal ++;
5142: }
5143: }
1.160.6.34 raeburn 5144: my ($emailrules,$emailruleorder) =
5145: &Apache::lonnet::inst_userrules($dom,'email');
5146: if (ref($emailrules) eq 'HASH') {
5147: if (keys(%{$emailrules}) > 0) {
5148: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 5149: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 5150: $$rowtotal ++;
5151: }
5152: }
1.160.6.35 raeburn 5153: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 5154: }
5155: return $datatable;
5156: }
5157:
1.160.6.40 raeburn 5158: sub email_as_username {
5159: my ($rowtotal,$processing,$type) = @_;
5160: my %choices =
5161: &Apache::lonlocal::texthash (
5162: automatic => 'Automatic approval',
5163: approval => 'Queued for approval',
5164: );
5165: my $output;
5166: foreach my $option ('automatic','approval') {
5167: my $checked;
5168: if (ref($processing) eq 'HASH') {
5169: if ($type eq '') {
5170: if (!exists($processing->{'default'})) {
5171: if ($option eq 'automatic') {
5172: $checked = ' checked="checked"';
5173: }
5174: } else {
5175: if ($processing->{'default'} eq $option) {
5176: $checked = ' checked="checked"';
5177: }
5178: }
5179: } else {
5180: if (!exists($processing->{$type})) {
5181: if ($option eq 'automatic') {
5182: $checked = ' checked="checked"';
5183: }
5184: } else {
5185: if ($processing->{$type} eq $option) {
5186: $checked = ' checked="checked"';
5187: }
5188: }
5189: }
5190: } elsif ($option eq 'automatic') {
5191: $checked = ' checked="checked"';
5192: }
5193: my $name = 'cancreate_emailprocess';
5194: if (($type ne '') && ($type ne 'default')) {
5195: $name .= '_'.$type;
5196: }
5197: $output .= '<span class="LC_nobreak"><label>'.
5198: '<input type="radio" name="'.$name.'"'.
5199: $checked.' value="'.$option.'" />'.
5200: $choices{$option}.'</label></span>';
5201: if ($type eq '') {
5202: $output .= ' ';
5203: } else {
5204: $output .= '<br />';
5205: }
5206: }
5207: $$rowtotal ++;
5208: return $output;
5209: }
5210:
1.160.6.5 raeburn 5211: sub captcha_choice {
5212: my ($context,$settings,$itemcount) = @_;
1.160.6.69 raeburn 5213: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5214: $vertext,$currver);
1.160.6.5 raeburn 5215: my %lt = &captcha_phrases();
5216: $keyentry = 'hidden';
5217: if ($context eq 'cancreate') {
1.160.6.34 raeburn 5218: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 5219: } elsif ($context eq 'login') {
5220: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5221: }
5222: if (ref($settings) eq 'HASH') {
5223: if ($settings->{'captcha'}) {
5224: $checked{$settings->{'captcha'}} = ' checked="checked"';
5225: } else {
5226: $checked{'original'} = ' checked="checked"';
5227: }
5228: if ($settings->{'captcha'} eq 'recaptcha') {
5229: $pubtext = $lt{'pub'};
5230: $privtext = $lt{'priv'};
5231: $keyentry = 'text';
1.160.6.69 raeburn 5232: $vertext = $lt{'ver'};
5233: $currver = $settings->{'recaptchaversion'};
5234: if ($currver ne '2') {
5235: $currver = 1;
5236: }
1.160.6.5 raeburn 5237: }
5238: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5239: $currpub = $settings->{'recaptchakeys'}{'public'};
5240: $currpriv = $settings->{'recaptchakeys'}{'private'};
5241: }
5242: } else {
5243: $checked{'original'} = ' checked="checked"';
5244: }
5245: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5246: my $output = '<tr'.$css_class.'>'.
5247: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5248: '<table><tr><td>'."\n";
5249: foreach my $option ('original','recaptcha','notused') {
5250: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5251: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5252: $lt{$option}.'</label></span>';
5253: unless ($option eq 'notused') {
5254: $output .= (' 'x2)."\n";
5255: }
5256: }
5257: #
5258: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5259: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5260: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5261: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5262: #
5263: $output .= '</td></tr>'."\n".
5264: '<tr><td>'."\n".
5265: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5266: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5267: $currpub.'" size="40" /></span><br />'."\n".
5268: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5269: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 5270: $currpriv.'" size="40" /></span><br />'.
5271: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5272: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5273: $currver.'" size="3" /></span><br />'.
5274: '</td></tr></table>'."\n".
1.160.6.5 raeburn 5275: '</td></tr>';
5276: return $output;
5277: }
5278:
1.32 raeburn 5279: sub user_formats_row {
5280: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5281: my $output;
5282: my %text = (
5283: 'username' => 'new usernames',
5284: 'id' => 'IDs',
1.45 raeburn 5285: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5286: );
5287: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5288: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5289: '<td><span class="LC_nobreak">';
5290: if ($type eq 'email') {
5291: $output .= &mt("Formats disallowed for $text{$type}: ");
5292: } else {
5293: $output .= &mt("Format rules to check for $text{$type}: ");
5294: }
5295: $output .= '</span></td>'.
5296: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5297: my $rem;
5298: if (ref($ruleorder) eq 'ARRAY') {
5299: for (my $i=0; $i<@{$ruleorder}; $i++) {
5300: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5301: my $rem = $i%($numinrow);
5302: if ($rem == 0) {
5303: if ($i > 0) {
5304: $output .= '</tr>';
5305: }
5306: $output .= '<tr>';
5307: }
5308: my $check = ' ';
1.39 raeburn 5309: if (ref($settings) eq 'HASH') {
5310: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5311: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5312: $check = ' checked="checked" ';
5313: }
1.27 raeburn 5314: }
5315: }
5316: $output .= '<td class="LC_left_item">'.
5317: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5318: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5319: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5320: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5321: }
5322: }
5323: $rem = @{$ruleorder}%($numinrow);
5324: }
5325: my $colsleft = $numinrow - $rem;
5326: if ($colsleft > 1 ) {
5327: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5328: ' </td>';
5329: } elsif ($colsleft == 1) {
5330: $output .= '<td class="LC_left_item"> </td>';
5331: }
5332: $output .= '</tr></table></td></tr>';
5333: return $output;
5334: }
5335:
1.34 raeburn 5336: sub usercreation_types {
5337: my %lt = &Apache::lonlocal::texthash (
5338: author => 'When adding a co-author',
5339: course => 'When adding a user to a course',
1.100 raeburn 5340: requestcrs => 'When requesting a course',
1.34 raeburn 5341: any => 'Any',
5342: official => 'Institutional only ',
5343: unofficial => 'Non-institutional only',
5344: none => 'None',
5345: );
5346: return %lt;
1.48 raeburn 5347: }
1.34 raeburn 5348:
1.160.6.34 raeburn 5349: sub selfcreation_types {
5350: my %lt = &Apache::lonlocal::texthash (
5351: selfcreate => 'User creates own account',
5352: any => 'Any',
5353: official => 'Institutional only ',
5354: unofficial => 'Non-institutional only',
5355: email => 'E-mail address',
5356: login => 'Institutional Login',
5357: sso => 'SSO',
5358: );
5359: }
5360:
1.28 raeburn 5361: sub authtype_names {
5362: my %lt = &Apache::lonlocal::texthash(
5363: int => 'Internal',
5364: krb4 => 'Kerberos 4',
5365: krb5 => 'Kerberos 5',
5366: loc => 'Local',
5367: );
5368: return %lt;
5369: }
5370:
5371: sub context_names {
5372: my %context_title = &Apache::lonlocal::texthash(
5373: author => 'Creating users when an Author',
5374: course => 'Creating users when in a course',
5375: domain => 'Creating users when a Domain Coordinator',
5376: );
5377: return %context_title;
5378: }
5379:
1.33 raeburn 5380: sub print_usermodification {
5381: my ($position,$dom,$settings,$rowtotal) = @_;
5382: my $numinrow = 4;
5383: my ($context,$datatable,$rowcount);
5384: if ($position eq 'top') {
5385: $rowcount = 0;
5386: $context = 'author';
5387: foreach my $role ('ca','aa') {
5388: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5389: $numinrow,$rowcount);
5390: $$rowtotal ++;
5391: $rowcount ++;
5392: }
1.160.6.37 raeburn 5393: } elsif ($position eq 'bottom') {
1.33 raeburn 5394: $context = 'course';
5395: $rowcount = 0;
5396: foreach my $role ('st','ep','ta','in','cr') {
5397: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5398: $numinrow,$rowcount);
5399: $$rowtotal ++;
5400: $rowcount ++;
5401: }
5402: }
5403: return $datatable;
5404: }
5405:
1.43 raeburn 5406: sub print_defaults {
1.160.6.40 raeburn 5407: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5408: my $rownum = 0;
1.160.6.80 raeburn 5409: my ($datatable,$css_class,$titles);
5410: unless ($position eq 'bottom') {
5411: $titles = &defaults_titles($dom);
5412: }
1.160.6.40 raeburn 5413: if ($position eq 'top') {
5414: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5415: 'datelocale_def','portal_def');
5416: my %defaults;
5417: if (ref($settings) eq 'HASH') {
5418: %defaults = %{$settings};
1.43 raeburn 5419: } else {
1.160.6.40 raeburn 5420: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5421: foreach my $item (@items) {
5422: $defaults{$item} = $domdefaults{$item};
5423: }
1.43 raeburn 5424: }
1.160.6.40 raeburn 5425: foreach my $item (@items) {
5426: if ($rownum%2) {
5427: $css_class = '';
5428: } else {
5429: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 5430: }
1.160.6.40 raeburn 5431: $datatable .= '<tr'.$css_class.'>'.
5432: '<td><span class="LC_nobreak">'.$titles->{$item}.
5433: '</span></td><td class="LC_right_item" colspan="3">';
5434: if ($item eq 'auth_def') {
5435: my @authtypes = ('internal','krb4','krb5','localauth');
5436: my %shortauth = (
5437: internal => 'int',
5438: krb4 => 'krb4',
5439: krb5 => 'krb5',
5440: localauth => 'loc'
5441: );
5442: my %authnames = &authtype_names();
5443: foreach my $auth (@authtypes) {
5444: my $checked = ' ';
5445: if ($defaults{$item} eq $auth) {
5446: $checked = ' checked="checked" ';
5447: }
5448: $datatable .= '<label><input type="radio" name="'.$item.
5449: '" value="'.$auth.'"'.$checked.'/>'.
5450: $authnames{$shortauth{$auth}}.'</label> ';
5451: }
5452: } elsif ($item eq 'timezone_def') {
5453: my $includeempty = 1;
5454: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5455: } elsif ($item eq 'datelocale_def') {
5456: my $includeempty = 1;
5457: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5458: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 5459: my $includeempty = 1;
5460: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 5461: } else {
5462: my $size;
5463: if ($item eq 'portal_def') {
5464: $size = ' size="25"';
5465: }
5466: $datatable .= '<input type="text" name="'.$item.'" value="'.
5467: $defaults{$item}.'"'.$size.' />';
5468: }
5469: $datatable .= '</td></tr>';
5470: $rownum ++;
5471: }
1.160.6.80 raeburn 5472: } elsif ($position eq 'middle') {
5473: my @items = ('intauth_cost','intauth_check','intauth_switch');
5474: my %defaults;
5475: if (ref($settings) eq 'HASH') {
5476: %defaults = %{$settings};
5477: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5478: $defaults{'intauth_cost'} = 10;
5479: }
5480: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5481: $defaults{'intauth_check'} = 0;
5482: }
5483: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5484: $defaults{'intauth_switch'} = 0;
5485: }
5486: } else {
5487: %defaults = (
5488: 'intauth_cost' => 10,
5489: 'intauth_check' => 0,
5490: 'intauth_switch' => 0,
5491: );
5492: }
5493: foreach my $item (@items) {
5494: if ($rownum%2) {
5495: $css_class = '';
5496: } else {
5497: $css_class = ' class="LC_odd_row" ';
5498: }
5499: $datatable .= '<tr'.$css_class.'>'.
5500: '<td><span class="LC_nobreak">'.$titles->{$item}.
5501: '</span></td><td class="LC_left_item" colspan="3">';
5502: if ($item eq 'intauth_switch') {
5503: my @options = (0,1,2);
5504: my %optiondesc = &Apache::lonlocal::texthash (
5505: 0 => 'No',
5506: 1 => 'Yes',
5507: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5508: );
5509: $datatable .= '<table width="100%">';
5510: foreach my $option (@options) {
5511: my $checked = ' ';
5512: if ($defaults{$item} eq $option) {
5513: $checked = ' checked="checked"';
5514: }
5515: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5516: '<label><input type="radio" name="'.$item.
5517: '" value="'.$option.'"'.$checked.' />'.
5518: $optiondesc{$option}.'</label></span></td></tr>';
5519: }
5520: $datatable .= '</table>';
5521: } elsif ($item eq 'intauth_check') {
5522: my @options = (0,1,2);
5523: my %optiondesc = &Apache::lonlocal::texthash (
5524: 0 => 'No',
5525: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5526: 2 => 'Yes, disallow login if stored cost is less than domain default',
5527: );
5528: $datatable .= '<table wisth="100%">';
5529: foreach my $option (@options) {
5530: my $checked = ' ';
5531: my $onclick;
5532: if ($defaults{$item} eq $option) {
5533: $checked = ' checked="checked"';
5534: }
5535: if ($option == 2) {
5536: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5537: }
5538: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5539: '<label><input type="radio" name="'.$item.
5540: '" value="'.$option.'"'.$checked.$onclick.' />'.
5541: $optiondesc{$option}.'</label></span></td></tr>';
5542: }
5543: $datatable .= '</table>';
5544: } else {
5545: $datatable .= '<input type="text" name="'.$item.'" value="'.
5546: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5547: }
5548: $datatable .= '</td></tr>';
5549: $rownum ++;
5550: }
1.160.6.40 raeburn 5551: } else {
1.160.6.80 raeburn 5552: my %defaults;
1.160.6.40 raeburn 5553: if (ref($settings) eq 'HASH') {
5554: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5555: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5556: my $maxnum = @{$settings->{'inststatusorder'}};
5557: for (my $i=0; $i<$maxnum; $i++) {
5558: $css_class = $rownum%2?' class="LC_odd_row"':'';
5559: my $item = $settings->{'inststatusorder'}->[$i];
5560: my $title = $settings->{'inststatustypes'}->{$item};
5561: my $guestok;
5562: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5563: $guestok = 1;
5564: }
5565: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5566: $datatable .= '<tr'.$css_class.'>'.
5567: '<td><span class="LC_nobreak">'.
5568: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5569: for (my $k=0; $k<=$maxnum; $k++) {
5570: my $vpos = $k+1;
5571: my $selstr;
5572: if ($k == $i) {
5573: $selstr = ' selected="selected" ';
5574: }
5575: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5576: }
5577: my ($checkedon,$checkedoff);
5578: $checkedoff = ' checked="checked"';
5579: if ($guestok) {
5580: $checkedon = $checkedoff;
5581: $checkedoff = '';
5582: }
5583: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5584: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5585: &mt('delete').'</span></td>'.
5586: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5587: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5588: '</span></td>'.
5589: '<td class="LC_right_item"><span class="LC_nobreak">'.
5590: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5591: &mt('Yes').'</label>'.(' 'x2).
5592: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5593: &mt('No').'</label></span></td></tr>';
5594: }
5595: $css_class = $rownum%2?' class="LC_odd_row"':'';
5596: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5597: $datatable .= '<tr '.$css_class.'>'.
5598: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5599: for (my $k=0; $k<=$maxnum; $k++) {
5600: my $vpos = $k+1;
5601: my $selstr;
5602: if ($k == $maxnum) {
5603: $selstr = ' selected="selected" ';
5604: }
5605: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5606: }
5607: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 5608: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 5609: ' '.&mt('(new)').
5610: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5611: &mt('Name displayed:').
5612: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5613: '<td class="LC_right_item"><span class="LC_nobreak">'.
5614: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5615: &mt('Yes').'</label>'.(' 'x2).
5616: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5617: &mt('No').'</label></span></td></tr>';
5618: '</tr>'."\n";
5619: $rownum ++;
1.141 raeburn 5620: }
1.43 raeburn 5621: }
5622: }
5623: $$rowtotal += $rownum;
5624: return $datatable;
5625: }
5626:
1.160.6.5 raeburn 5627: sub get_languages_hash {
5628: my %langchoices;
5629: foreach my $id (&Apache::loncommon::languageids()) {
5630: my $code = &Apache::loncommon::supportedlanguagecode($id);
5631: if ($code ne '') {
5632: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5633: }
5634: }
5635: return %langchoices;
5636: }
5637:
1.43 raeburn 5638: sub defaults_titles {
1.141 raeburn 5639: my ($dom) = @_;
1.43 raeburn 5640: my %titles = &Apache::lonlocal::texthash (
5641: 'auth_def' => 'Default authentication type',
5642: 'auth_arg_def' => 'Default authentication argument',
5643: 'lang_def' => 'Default language',
1.54 raeburn 5644: 'timezone_def' => 'Default timezone',
1.68 raeburn 5645: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5646: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 5647: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
5648: 'intauth_check' => 'Check bcrypt cost if authenticated',
5649: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 5650: );
1.141 raeburn 5651: if ($dom) {
5652: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5653: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5654: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5655: $protocol = 'http' if ($protocol ne 'https');
5656: if ($uint_dom) {
5657: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5658: $uint_dom);
5659: }
5660: }
1.43 raeburn 5661: return (\%titles);
5662: }
5663:
1.46 raeburn 5664: sub print_scantronformat {
5665: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5666: my $itemcount = 1;
1.60 raeburn 5667: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5668: %confhash);
1.46 raeburn 5669: my $switchserver = &check_switchserver($dom,$confname);
5670: my %lt = &Apache::lonlocal::texthash (
1.95 www 5671: default => 'Default bubblesheet format file error',
5672: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5673: );
5674: my %scantronfiles = (
5675: default => 'default.tab',
5676: custom => 'custom.tab',
5677: );
5678: foreach my $key (keys(%scantronfiles)) {
5679: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5680: .$scantronfiles{$key};
5681: }
5682: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5683: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5684: if (!$switchserver) {
5685: my $servadm = $r->dir_config('lonAdmEMail');
5686: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5687: if ($configuserok eq 'ok') {
5688: if ($author_ok eq 'ok') {
5689: my %legacyfile = (
5690: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5691: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5692: );
5693: my %md5chk;
5694: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5695: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5696: chomp($md5chk{$type});
1.46 raeburn 5697: }
5698: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5699: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5700: ($scantronurls{$type},my $error) =
1.46 raeburn 5701: &legacy_scantronformat($r,$dom,$confname,
5702: $type,$legacyfile{$type},
5703: $scantronurls{$type},
5704: $scantronfiles{$type});
1.60 raeburn 5705: if ($error ne '') {
5706: $error{$type} = $error;
5707: }
5708: }
5709: if (keys(%error) == 0) {
5710: $is_custom = 1;
5711: $confhash{'scantron'}{'scantronformat'} =
5712: $scantronurls{'custom'};
5713: my $putresult =
5714: &Apache::lonnet::put_dom('configuration',
5715: \%confhash,$dom);
5716: if ($putresult ne 'ok') {
5717: $error{'custom'} =
5718: '<span class="LC_error">'.
5719: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5720: }
1.46 raeburn 5721: }
5722: } else {
1.60 raeburn 5723: ($scantronurls{'default'},my $error) =
1.46 raeburn 5724: &legacy_scantronformat($r,$dom,$confname,
5725: 'default',$legacyfile{'default'},
5726: $scantronurls{'default'},
5727: $scantronfiles{'default'});
1.60 raeburn 5728: if ($error eq '') {
5729: $confhash{'scantron'}{'scantronformat'} = '';
5730: my $putresult =
5731: &Apache::lonnet::put_dom('configuration',
5732: \%confhash,$dom);
5733: if ($putresult ne 'ok') {
5734: $error{'default'} =
5735: '<span class="LC_error">'.
5736: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5737: }
5738: } else {
5739: $error{'default'} = $error;
5740: }
1.46 raeburn 5741: }
5742: }
5743: }
5744: } else {
1.95 www 5745: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5746: }
5747: }
5748: if (ref($settings) eq 'HASH') {
5749: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5750: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5751: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5752: $scantronurl = '';
5753: } else {
5754: $scantronurl = $settings->{'scantronformat'};
5755: }
5756: $is_custom = 1;
5757: } else {
5758: $scantronurl = $scantronurls{'default'};
5759: }
5760: } else {
1.60 raeburn 5761: if ($is_custom) {
5762: $scantronurl = $scantronurls{'custom'};
5763: } else {
5764: $scantronurl = $scantronurls{'default'};
5765: }
1.46 raeburn 5766: }
5767: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5768: $datatable .= '<tr'.$css_class.'>';
5769: if (!$is_custom) {
1.65 raeburn 5770: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5771: '<span class="LC_nobreak">';
1.46 raeburn 5772: if ($scantronurl) {
1.160.6.21 raeburn 5773: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5774: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5775: } else {
5776: $datatable = &mt('File unavailable for display');
5777: }
1.65 raeburn 5778: $datatable .= '</span></td>';
1.60 raeburn 5779: if (keys(%error) == 0) {
5780: $datatable .= '<td valign="bottom">';
5781: if (!$switchserver) {
5782: $datatable .= &mt('Upload:').'<br />';
5783: }
5784: } else {
5785: my $errorstr;
5786: foreach my $key (sort(keys(%error))) {
5787: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5788: }
5789: $datatable .= '<td>'.$errorstr;
5790: }
1.46 raeburn 5791: } else {
5792: if (keys(%error) > 0) {
5793: my $errorstr;
5794: foreach my $key (sort(keys(%error))) {
5795: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5796: }
1.60 raeburn 5797: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5798: } elsif ($scantronurl) {
1.160.6.26 raeburn 5799: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 5800: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5801: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 5802: $link.
5803: '<label><input type="checkbox" name="scantronformat_del"'.
5804: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5805: '<td><span class="LC_nobreak"> '.
5806: &mt('Replace:').'</span><br />';
1.46 raeburn 5807: }
5808: }
5809: if (keys(%error) == 0) {
5810: if ($switchserver) {
5811: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5812: } else {
1.65 raeburn 5813: $datatable .='<span class="LC_nobreak"> '.
5814: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5815: }
5816: }
5817: $datatable .= '</td></tr>';
5818: $$rowtotal ++;
5819: return $datatable;
5820: }
5821:
5822: sub legacy_scantronformat {
5823: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5824: my ($url,$error);
5825: my @statinfo = &Apache::lonnet::stat_file($newurl);
5826: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5827: (my $result,$url) =
5828: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5829: '','',$newfile);
5830: if ($result ne 'ok') {
1.130 raeburn 5831: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5832: }
5833: }
5834: return ($url,$error);
5835: }
1.43 raeburn 5836:
1.49 raeburn 5837: sub print_coursecategories {
1.57 raeburn 5838: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5839: my $datatable;
5840: if ($position eq 'top') {
1.160.6.42 raeburn 5841: my (%checked);
5842: my @catitems = ('unauth','auth');
5843: my @cattypes = ('std','domonly','codesrch','none');
5844: $checked{'unauth'} = 'std';
5845: $checked{'auth'} = 'std';
5846: if (ref($settings) eq 'HASH') {
5847: foreach my $type (@cattypes) {
5848: if ($type eq $settings->{'unauth'}) {
5849: $checked{'unauth'} = $type;
5850: }
5851: if ($type eq $settings->{'auth'}) {
5852: $checked{'auth'} = $type;
5853: }
5854: }
5855: }
5856: my %lt = &Apache::lonlocal::texthash (
5857: unauth => 'Catalog type for unauthenticated users',
5858: auth => 'Catalog type for authenticated users',
5859: none => 'No catalog',
5860: std => 'Standard catalog',
5861: domonly => 'Domain-only catalog',
5862: codesrch => "Code search form",
5863: );
5864: my $itemcount = 0;
5865: foreach my $item (@catitems) {
5866: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5867: $datatable .= '<tr '.$css_class.'>'.
5868: '<td>'.$lt{$item}.'</td>'.
5869: '<td class="LC_right_item"><span class="LC_nobreak">';
5870: foreach my $type (@cattypes) {
5871: my $ischecked;
5872: if ($checked{$item} eq $type) {
5873: $ischecked=' checked="checked"';
5874: }
5875: $datatable .= '<label>'.
5876: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5877: ' />'.$lt{$type}.'</label> ';
5878: }
5879: $datatable .= '</td></tr>';
5880: $itemcount ++;
5881: }
5882: $$rowtotal += $itemcount;
5883: } elsif ($position eq 'middle') {
1.57 raeburn 5884: my $toggle_cats_crs = ' ';
5885: my $toggle_cats_dom = ' checked="checked" ';
5886: my $can_cat_crs = ' ';
5887: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5888: my $toggle_catscomm_comm = ' ';
5889: my $toggle_catscomm_dom = ' checked="checked" ';
5890: my $can_catcomm_comm = ' ';
5891: my $can_catcomm_dom = ' checked="checked" ';
5892:
1.57 raeburn 5893: if (ref($settings) eq 'HASH') {
5894: if ($settings->{'togglecats'} eq 'crs') {
5895: $toggle_cats_crs = $toggle_cats_dom;
5896: $toggle_cats_dom = ' ';
5897: }
5898: if ($settings->{'categorize'} eq 'crs') {
5899: $can_cat_crs = $can_cat_dom;
5900: $can_cat_dom = ' ';
5901: }
1.120 raeburn 5902: if ($settings->{'togglecatscomm'} eq 'comm') {
5903: $toggle_catscomm_comm = $toggle_catscomm_dom;
5904: $toggle_catscomm_dom = ' ';
5905: }
5906: if ($settings->{'categorizecomm'} eq 'comm') {
5907: $can_catcomm_comm = $can_catcomm_dom;
5908: $can_catcomm_dom = ' ';
5909: }
1.57 raeburn 5910: }
5911: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5912: togglecats => 'Show/Hide a course in catalog',
5913: togglecatscomm => 'Show/Hide a community in catalog',
5914: categorize => 'Assign a category to a course',
5915: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5916: );
5917: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5918: dom => 'Set in Domain',
5919: crs => 'Set in Course',
5920: comm => 'Set in Community',
1.57 raeburn 5921: );
5922: $datatable = '<tr class="LC_odd_row">'.
5923: '<td>'.$title{'togglecats'}.'</td>'.
5924: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5925: '<input type="radio" name="togglecats"'.
5926: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5927: '<label><input type="radio" name="togglecats"'.
5928: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5929: '</tr><tr>'.
5930: '<td>'.$title{'categorize'}.'</td>'.
5931: '<td class="LC_right_item"><span class="LC_nobreak">'.
5932: '<label><input type="radio" name="categorize"'.
5933: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5934: '<label><input type="radio" name="categorize"'.
5935: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5936: '</tr><tr class="LC_odd_row">'.
5937: '<td>'.$title{'togglecatscomm'}.'</td>'.
5938: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5939: '<input type="radio" name="togglecatscomm"'.
5940: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5941: '<label><input type="radio" name="togglecatscomm"'.
5942: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5943: '</tr><tr>'.
5944: '<td>'.$title{'categorizecomm'}.'</td>'.
5945: '<td class="LC_right_item"><span class="LC_nobreak">'.
5946: '<label><input type="radio" name="categorizecomm"'.
5947: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5948: '<label><input type="radio" name="categorizecomm"'.
5949: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5950: '</tr>';
1.120 raeburn 5951: $$rowtotal += 4;
1.57 raeburn 5952: } else {
5953: my $css_class;
5954: my $itemcount = 1;
5955: my $cathash;
5956: if (ref($settings) eq 'HASH') {
5957: $cathash = $settings->{'cats'};
5958: }
5959: if (ref($cathash) eq 'HASH') {
5960: my (@cats,@trails,%allitems,%idx,@jsarray);
5961: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5962: \%allitems,\%idx,\@jsarray);
5963: my $maxdepth = scalar(@cats);
5964: my $colattrib = '';
5965: if ($maxdepth > 2) {
5966: $colattrib = ' colspan="2" ';
5967: }
5968: my @path;
5969: if (@cats > 0) {
5970: if (ref($cats[0]) eq 'ARRAY') {
5971: my $numtop = @{$cats[0]};
5972: my $maxnum = $numtop;
1.120 raeburn 5973: my %default_names = (
5974: instcode => &mt('Official courses'),
5975: communities => &mt('Communities'),
5976: );
5977:
5978: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5979: ($cathash->{'instcode::0'} eq '') ||
5980: (!grep(/^communities$/,@{$cats[0]})) ||
5981: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5982: $maxnum ++;
5983: }
5984: my $lastidx;
5985: for (my $i=0; $i<$numtop; $i++) {
5986: my $parent = $cats[0][$i];
5987: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5988: my $item = &escape($parent).'::0';
5989: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5990: $lastidx = $idx{$item};
5991: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5992: .'<select name="'.$item.'"'.$chgstr.'>';
5993: for (my $k=0; $k<=$maxnum; $k++) {
5994: my $vpos = $k+1;
5995: my $selstr;
5996: if ($k == $i) {
5997: $selstr = ' selected="selected" ';
5998: }
5999: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6000: }
1.160.6.29 raeburn 6001: $datatable .= '</select></span></td><td>';
1.120 raeburn 6002: if ($parent eq 'instcode' || $parent eq 'communities') {
6003: $datatable .= '<span class="LC_nobreak">'
6004: .$default_names{$parent}.'</span>';
6005: if ($parent eq 'instcode') {
6006: $datatable .= '<br /><span class="LC_nobreak">('
6007: .&mt('with institutional codes')
6008: .')</span></td><td'.$colattrib.'>';
6009: } else {
6010: $datatable .= '<table><tr><td>';
6011: }
6012: $datatable .= '<span class="LC_nobreak">'
6013: .'<label><input type="radio" name="'
6014: .$parent.'" value="1" checked="checked" />'
6015: .&mt('Display').'</label>';
6016: if ($parent eq 'instcode') {
6017: $datatable .= ' ';
6018: } else {
6019: $datatable .= '</span></td></tr><tr><td>'
6020: .'<span class="LC_nobreak">';
6021: }
6022: $datatable .= '<label><input type="radio" name="'
6023: .$parent.'" value="0" />'
6024: .&mt('Do not display').'</label></span>';
6025: if ($parent eq 'communities') {
6026: $datatable .= '</td></tr></table>';
6027: }
6028: $datatable .= '</td>';
1.57 raeburn 6029: } else {
6030: $datatable .= $parent
1.160.6.29 raeburn 6031: .' <span class="LC_nobreak"><label>'
6032: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6033: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6034: }
6035: my $depth = 1;
6036: push(@path,$parent);
6037: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6038: pop(@path);
6039: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6040: $itemcount ++;
6041: }
1.48 raeburn 6042: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6043: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6044: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6045: for (my $k=0; $k<=$maxnum; $k++) {
6046: my $vpos = $k+1;
6047: my $selstr;
1.57 raeburn 6048: if ($k == $numtop) {
1.48 raeburn 6049: $selstr = ' selected="selected" ';
6050: }
6051: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6052: }
1.59 bisitz 6053: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6054: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6055: .'</tr>'."\n";
1.48 raeburn 6056: $itemcount ++;
1.120 raeburn 6057: foreach my $default ('instcode','communities') {
6058: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6059: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6060: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6061: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6062: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6063: for (my $k=0; $k<=$maxnum; $k++) {
6064: my $vpos = $k+1;
6065: my $selstr;
6066: if ($k == $maxnum) {
6067: $selstr = ' selected="selected" ';
6068: }
6069: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6070: }
1.120 raeburn 6071: $datatable .= '</select></span></td>'.
6072: '<td><span class="LC_nobreak">'.
6073: $default_names{$default}.'</span>';
6074: if ($default eq 'instcode') {
6075: $datatable .= '<br /><span class="LC_nobreak">('
6076: .&mt('with institutional codes').')</span>';
6077: }
6078: $datatable .= '</td>'
6079: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6080: .&mt('Display').'</label> '
6081: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6082: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6083: }
6084: }
6085: }
1.57 raeburn 6086: } else {
6087: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6088: }
6089: } else {
1.160.6.42 raeburn 6090: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6091: .&initialize_categories($itemcount);
1.48 raeburn 6092: }
1.57 raeburn 6093: $$rowtotal += $itemcount;
1.48 raeburn 6094: }
6095: return $datatable;
6096: }
6097:
1.69 raeburn 6098: sub print_serverstatuses {
6099: my ($dom,$settings,$rowtotal) = @_;
6100: my $datatable;
6101: my @pages = &serverstatus_pages();
6102: my (%namedaccess,%machineaccess);
6103: foreach my $type (@pages) {
6104: $namedaccess{$type} = '';
6105: $machineaccess{$type}= '';
6106: }
6107: if (ref($settings) eq 'HASH') {
6108: foreach my $type (@pages) {
6109: if (exists($settings->{$type})) {
6110: if (ref($settings->{$type}) eq 'HASH') {
6111: foreach my $key (keys(%{$settings->{$type}})) {
6112: if ($key eq 'namedusers') {
6113: $namedaccess{$type} = $settings->{$type}->{$key};
6114: } elsif ($key eq 'machines') {
6115: $machineaccess{$type} = $settings->{$type}->{$key};
6116: }
6117: }
6118: }
6119: }
6120: }
6121: }
1.81 raeburn 6122: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6123: my $rownum = 0;
6124: my $css_class;
6125: foreach my $type (@pages) {
6126: $rownum ++;
6127: $css_class = $rownum%2?' class="LC_odd_row"':'';
6128: $datatable .= '<tr'.$css_class.'>'.
6129: '<td><span class="LC_nobreak">'.
6130: $titles->{$type}.'</span></td>'.
6131: '<td class="LC_left_item">'.
6132: '<input type="text" name="'.$type.'_namedusers" '.
6133: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6134: '<td class="LC_right_item">'.
6135: '<span class="LC_nobreak">'.
6136: '<input type="text" name="'.$type.'_machines" '.
6137: 'value="'.$machineaccess{$type}.'" size="10" />'.
6138: '</td></tr>'."\n";
6139: }
6140: $$rowtotal += $rownum;
6141: return $datatable;
6142: }
6143:
6144: sub serverstatus_pages {
6145: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 6146: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 6147: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 6148: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6149: }
6150:
1.160.6.40 raeburn 6151: sub defaults_javascript {
6152: my ($settings) = @_;
1.160.6.80 raeburn 6153: 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.');
6154: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6155: &js_escape(\$intauthcheck);
6156: &js_escape(\$intauthcost);
6157: my $intauthjs = <<"ENDSCRIPT";
6158:
6159: function warnIntAuth(field) {
6160: if (field.name == 'intauth_check') {
6161: if (field.value == '2') {
6162: alert('$intauthcheck');
6163: }
6164: }
6165: if (field.name == 'intauth_cost') {
6166: field.value.replace(/\s/g,'');
6167: if (field.value != '') {
6168: var regexdigit=/^\\d+\$/;
6169: if (!regexdigit.test(field.value)) {
6170: alert('$intauthcost');
6171: }
6172: }
6173: }
6174: return;
6175: }
6176:
6177: ENDSCRIPT
6178:
6179: if (ref($settings) ne 'HASH') {
6180: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6181: }
1.160.6.40 raeburn 6182: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6183: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6184: if ($maxnum eq '') {
6185: $maxnum = 0;
6186: }
6187: $maxnum ++;
1.160.6.51 raeburn 6188: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 6189: return <<"ENDSCRIPT";
6190: <script type="text/javascript">
6191: // <![CDATA[
6192: function reorderTypes(form,caller) {
6193: var changedVal;
6194: $jstext
6195: var newpos = 'addinststatus_pos';
6196: var current = new Array;
6197: var maxh = $maxnum;
6198: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6199: var oldVal;
6200: if (caller == newpos) {
6201: changedVal = newitemVal;
6202: } else {
6203: var curritem = 'inststatus_pos_'+caller;
6204: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6205: current[newitemVal] = newpos;
6206: }
6207: for (var i=0; i<inststatuses.length; i++) {
6208: if (inststatuses[i] != caller) {
6209: var elementName = 'inststatus_pos_'+inststatuses[i];
6210: if (form.elements[elementName]) {
6211: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6212: current[currVal] = elementName;
6213: }
6214: }
6215: }
6216: for (var j=0; j<maxh; j++) {
6217: if (current[j] == undefined) {
6218: oldVal = j;
6219: }
6220: }
6221: if (oldVal < changedVal) {
6222: for (var k=oldVal+1; k<=changedVal ; k++) {
6223: var elementName = current[k];
6224: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6225: }
6226: } else {
6227: for (var k=changedVal; k<oldVal; k++) {
6228: var elementName = current[k];
6229: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6230: }
6231: }
6232: return;
6233: }
6234:
1.160.6.80 raeburn 6235: $intauthjs
6236:
1.160.6.40 raeburn 6237: // ]]>
6238: </script>
6239:
6240: ENDSCRIPT
1.160.6.80 raeburn 6241: } else {
6242: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40 raeburn 6243: }
6244: }
6245:
1.49 raeburn 6246: sub coursecategories_javascript {
6247: my ($settings) = @_;
1.57 raeburn 6248: my ($output,$jstext,$cathash);
1.49 raeburn 6249: if (ref($settings) eq 'HASH') {
1.57 raeburn 6250: $cathash = $settings->{'cats'};
6251: }
6252: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6253: my (@cats,@jsarray,%idx);
1.57 raeburn 6254: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6255: if (@jsarray > 0) {
6256: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6257: for (my $i=0; $i<@jsarray; $i++) {
6258: if (ref($jsarray[$i]) eq 'ARRAY') {
6259: my $catstr = join('","',@{$jsarray[$i]});
6260: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6261: }
6262: }
6263: }
6264: } else {
6265: $jstext = ' var categories = Array(1);'."\n".
6266: ' categories[0] = Array("instcode_pos");'."\n";
6267: }
1.160.6.42 raeburn 6268: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6269: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 6270: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6271: &js_escape(\$instcode_reserved);
6272: &js_escape(\$communities_reserved);
6273: &js_escape(\$choose_again);
1.49 raeburn 6274: $output = <<"ENDSCRIPT";
6275: <script type="text/javascript">
1.109 raeburn 6276: // <![CDATA[
1.49 raeburn 6277: function reorderCats(form,parent,item,idx) {
6278: var changedVal;
6279: $jstext
6280: var newpos = 'addcategory_pos';
6281: if (parent == '') {
6282: var has_instcode = 0;
6283: var maxtop = categories[idx].length;
6284: for (var j=0; j<maxtop; j++) {
6285: if (categories[idx][j] == 'instcode::0') {
6286: has_instcode == 1;
6287: }
6288: }
6289: if (has_instcode == 0) {
6290: categories[idx][maxtop] = 'instcode_pos';
6291: }
6292: } else {
6293: newpos += '_'+parent;
6294: }
6295: var maxh = 1 + categories[idx].length;
6296: var current = new Array;
6297: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6298: if (item == newpos) {
6299: changedVal = newitemVal;
6300: } else {
6301: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6302: current[newitemVal] = newpos;
6303: }
6304: for (var i=0; i<categories[idx].length; i++) {
6305: var elementName = categories[idx][i];
6306: if (elementName != item) {
6307: if (form.elements[elementName]) {
6308: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6309: current[currVal] = elementName;
6310: }
6311: }
6312: }
6313: var oldVal;
6314: for (var j=0; j<maxh; j++) {
6315: if (current[j] == undefined) {
6316: oldVal = j;
6317: }
6318: }
6319: if (oldVal < changedVal) {
6320: for (var k=oldVal+1; k<=changedVal ; k++) {
6321: var elementName = current[k];
6322: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6323: }
6324: } else {
6325: for (var k=changedVal; k<oldVal; k++) {
6326: var elementName = current[k];
6327: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6328: }
6329: }
6330: return;
6331: }
1.120 raeburn 6332:
6333: function categoryCheck(form) {
6334: if (form.elements['addcategory_name'].value == 'instcode') {
6335: alert('$instcode_reserved\\n$choose_again');
6336: return false;
6337: }
6338: if (form.elements['addcategory_name'].value == 'communities') {
6339: alert('$communities_reserved\\n$choose_again');
6340: return false;
6341: }
6342: return true;
6343: }
6344:
1.109 raeburn 6345: // ]]>
1.49 raeburn 6346: </script>
6347:
6348: ENDSCRIPT
6349: return $output;
6350: }
6351:
1.48 raeburn 6352: sub initialize_categories {
6353: my ($itemcount) = @_;
1.120 raeburn 6354: my ($datatable,$css_class,$chgstr);
6355: my %default_names = (
6356: instcode => 'Official courses (with institutional codes)',
6357: communities => 'Communities',
6358: );
6359: my $select0 = ' selected="selected"';
6360: my $select1 = '';
6361: foreach my $default ('instcode','communities') {
6362: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6363: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
6364: if ($default eq 'communities') {
6365: $select1 = $select0;
6366: $select0 = '';
6367: }
6368: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6369: .'<select name="'.$default.'_pos">'
6370: .'<option value="0"'.$select0.'>1</option>'
6371: .'<option value="1"'.$select1.'>2</option>'
6372: .'<option value="2">3</option></select> '
6373: .$default_names{$default}
6374: .'</span></td><td><span class="LC_nobreak">'
6375: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6376: .&mt('Display').'</label> <label>'
6377: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6378: .'</label></span></td></tr>';
1.120 raeburn 6379: $itemcount ++;
6380: }
1.48 raeburn 6381: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6382: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6383: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6384: .'<select name="addcategory_pos"'.$chgstr.'>'
6385: .'<option value="0">1</option>'
6386: .'<option value="1">2</option>'
6387: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6388: .&mt('Add category').'</td><td>'.&mt('Name:')
6389: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6390: return $datatable;
6391: }
6392:
6393: sub build_category_rows {
1.49 raeburn 6394: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6395: my ($text,$name,$item,$chgstr);
1.48 raeburn 6396: if (ref($cats) eq 'ARRAY') {
6397: my $maxdepth = scalar(@{$cats});
6398: if (ref($cats->[$depth]) eq 'HASH') {
6399: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6400: my $numchildren = @{$cats->[$depth]{$parent}};
6401: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 6402: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6403: my ($idxnum,$parent_name,$parent_item);
6404: my $higher = $depth - 1;
6405: if ($higher == 0) {
6406: $parent_name = &escape($parent).'::'.$higher;
6407: } else {
6408: if (ref($path) eq 'ARRAY') {
6409: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6410: }
6411: }
6412: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6413: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6414: if ($j < $numchildren) {
1.48 raeburn 6415: $name = $cats->[$depth]{$parent}[$j];
6416: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6417: $idxnum = $idx->{$item};
6418: } else {
6419: $name = $parent_name;
6420: $item = $parent_item;
1.48 raeburn 6421: }
1.49 raeburn 6422: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6423: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6424: for (my $i=0; $i<=$numchildren; $i++) {
6425: my $vpos = $i+1;
6426: my $selstr;
6427: if ($j == $i) {
6428: $selstr = ' selected="selected" ';
6429: }
6430: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6431: }
6432: $text .= '</select> ';
6433: if ($j < $numchildren) {
6434: my $deeper = $depth+1;
6435: $text .= $name.' '
6436: .'<label><input type="checkbox" name="deletecategory" value="'
6437: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6438: if(ref($path) eq 'ARRAY') {
6439: push(@{$path},$name);
1.49 raeburn 6440: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6441: pop(@{$path});
6442: }
6443: } else {
1.59 bisitz 6444: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 6445: if ($j == $numchildren) {
6446: $text .= $name;
6447: } else {
6448: $text .= $item;
6449: }
6450: $text .= '" value="" />';
6451: }
6452: $text .= '</td></tr>';
6453: }
6454: $text .= '</table></td>';
6455: } else {
6456: my $higher = $depth-1;
6457: if ($higher == 0) {
6458: $name = &escape($parent).'::'.$higher;
6459: } else {
6460: if (ref($path) eq 'ARRAY') {
6461: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6462: }
6463: }
6464: my $colspan;
6465: if ($parent ne 'instcode') {
6466: $colspan = $maxdepth - $depth - 1;
6467: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
6468: }
6469: }
6470: }
6471: }
6472: return $text;
6473: }
6474:
1.33 raeburn 6475: sub modifiable_userdata_row {
1.160.6.35 raeburn 6476: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6477: my ($role,$rolename,$statustype);
6478: $role = $item;
1.160.6.34 raeburn 6479: if ($context eq 'cancreate') {
1.160.6.35 raeburn 6480: if ($item =~ /^emailusername_(.+)$/) {
6481: $statustype = $1;
6482: $role = 'emailusername';
6483: if (ref($usertypes) eq 'HASH') {
6484: if ($usertypes->{$statustype}) {
6485: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6486: } else {
6487: $rolename = &mt('Data provided by user');
6488: }
6489: }
1.160.6.34 raeburn 6490: }
6491: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6492: if (ref($usertypes) eq 'HASH') {
6493: $rolename = $usertypes->{$role};
6494: } else {
6495: $rolename = $role;
6496: }
1.33 raeburn 6497: } else {
1.63 raeburn 6498: if ($role eq 'cr') {
6499: $rolename = &mt('Custom role');
6500: } else {
6501: $rolename = &Apache::lonnet::plaintext($role);
6502: }
1.33 raeburn 6503: }
1.160.6.34 raeburn 6504: my (@fields,%fieldtitles);
6505: if (ref($fieldsref) eq 'ARRAY') {
6506: @fields = @{$fieldsref};
6507: } else {
6508: @fields = ('lastname','firstname','middlename','generation',
6509: 'permanentemail','id');
6510: }
6511: if ((ref($titlesref) eq 'HASH')) {
6512: %fieldtitles = %{$titlesref};
6513: } else {
6514: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6515: }
1.33 raeburn 6516: my $output;
6517: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6518: $output = '<tr '.$css_class.'>'.
6519: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6520: '<td class="LC_left_item" colspan="2"><table>';
6521: my $rem;
6522: my %checks;
6523: if (ref($settings) eq 'HASH') {
6524: if (ref($settings->{$context}) eq 'HASH') {
6525: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 6526: my $hashref = $settings->{$context}->{$role};
6527: if ($role eq 'emailusername') {
6528: if ($statustype) {
6529: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6530: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 6531: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 6532: foreach my $field (@fields) {
6533: if ($hashref->{$field}) {
6534: $checks{$field} = $hashref->{$field};
6535: }
6536: }
6537: }
6538: }
6539: }
6540: } else {
6541: if (ref($hashref) eq 'HASH') {
6542: foreach my $field (@fields) {
6543: if ($hashref->{$field}) {
6544: $checks{$field} = ' checked="checked" ';
6545: }
6546: }
1.33 raeburn 6547: }
6548: }
6549: }
6550: }
6551: }
1.160.6.39 raeburn 6552:
1.33 raeburn 6553: for (my $i=0; $i<@fields; $i++) {
6554: my $rem = $i%($numinrow);
6555: if ($rem == 0) {
6556: if ($i > 0) {
6557: $output .= '</tr>';
6558: }
6559: $output .= '<tr>';
6560: }
6561: my $check = ' ';
1.160.6.35 raeburn 6562: unless ($role eq 'emailusername') {
6563: if (exists($checks{$fields[$i]})) {
6564: $check = $checks{$fields[$i]}
6565: } else {
6566: if ($role eq 'st') {
6567: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 6568: $check = ' checked="checked" ';
1.160.6.35 raeburn 6569: }
1.33 raeburn 6570: }
6571: }
6572: }
6573: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 6574: '<span class="LC_nobreak">';
6575: if ($role eq 'emailusername') {
6576: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6577: $checks{$fields[$i]} = 'omit';
6578: }
6579: foreach my $option ('required','optional','omit') {
6580: my $checked='';
6581: if ($checks{$fields[$i]} eq $option) {
6582: $checked='checked="checked" ';
6583: }
6584: $output .= '<label>'.
6585: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6586: &mt($option).'</label>'.(' ' x2);
6587: }
6588: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6589: } else {
6590: $output .= '<label>'.
6591: '<input type="checkbox" name="canmodify_'.$role.'" '.
6592: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6593: '</label>';
6594: }
6595: $output .= '</span></td>';
1.33 raeburn 6596: $rem = @fields%($numinrow);
6597: }
6598: my $colsleft = $numinrow - $rem;
6599: if ($colsleft > 1 ) {
6600: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6601: ' </td>';
6602: } elsif ($colsleft == 1) {
6603: $output .= '<td class="LC_left_item"> </td>';
6604: }
6605: $output .= '</tr></table></td></tr>';
6606: return $output;
6607: }
1.28 raeburn 6608:
1.93 raeburn 6609: sub insttypes_row {
1.160.6.34 raeburn 6610: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6611: my %lt = &Apache::lonlocal::texthash (
6612: cansearch => 'Users allowed to search',
6613: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6614: lockablenames => 'User preference to lock name',
1.93 raeburn 6615: );
6616: my $showdom;
6617: if ($context eq 'cansearch') {
6618: $showdom = ' ('.$dom.')';
6619: }
1.160.6.5 raeburn 6620: my $class = 'LC_left_item';
6621: if ($context eq 'statustocreate') {
6622: $class = 'LC_right_item';
6623: }
1.160.6.34 raeburn 6624: my $css_class = ' class="LC_odd_row"';
6625: if ($rownum ne '') {
6626: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6627: }
6628: my $output = '<tr'.$css_class.'>'.
6629: '<td>'.$lt{$context}.$showdom.
6630: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6631: my $rem;
6632: if (ref($types) eq 'ARRAY') {
6633: for (my $i=0; $i<@{$types}; $i++) {
6634: if (defined($usertypes->{$types->[$i]})) {
6635: my $rem = $i%($numinrow);
6636: if ($rem == 0) {
6637: if ($i > 0) {
6638: $output .= '</tr>';
6639: }
6640: $output .= '<tr>';
1.23 raeburn 6641: }
1.26 raeburn 6642: my $check = ' ';
1.99 raeburn 6643: if (ref($settings) eq 'HASH') {
6644: if (ref($settings->{$context}) eq 'ARRAY') {
6645: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6646: $check = ' checked="checked" ';
6647: }
6648: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6649: $check = ' checked="checked" ';
6650: }
1.23 raeburn 6651: }
1.26 raeburn 6652: $output .= '<td class="LC_left_item">'.
6653: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6654: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6655: 'value="'.$types->[$i].'"'.$check.'/>'.
6656: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6657: }
6658: }
1.26 raeburn 6659: $rem = @{$types}%($numinrow);
1.23 raeburn 6660: }
6661: my $colsleft = $numinrow - $rem;
1.131 raeburn 6662: if (($rem == 0) && (@{$types} > 0)) {
6663: $output .= '<tr>';
6664: }
1.23 raeburn 6665: if ($colsleft > 1) {
1.25 raeburn 6666: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6667: } else {
1.25 raeburn 6668: $output .= '<td class="LC_left_item">';
1.23 raeburn 6669: }
6670: my $defcheck = ' ';
1.99 raeburn 6671: if (ref($settings) eq 'HASH') {
6672: if (ref($settings->{$context}) eq 'ARRAY') {
6673: if (grep(/^default$/,@{$settings->{$context}})) {
6674: $defcheck = ' checked="checked" ';
6675: }
6676: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6677: $defcheck = ' checked="checked" ';
6678: }
1.23 raeburn 6679: }
1.25 raeburn 6680: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6681: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6682: 'value="default"'.$defcheck.'/>'.
6683: $othertitle.'</label></span></td>'.
6684: '</tr></table></td></tr>';
6685: return $output;
1.23 raeburn 6686: }
6687:
6688: sub sorted_searchtitles {
6689: my %searchtitles = &Apache::lonlocal::texthash(
6690: 'uname' => 'username',
6691: 'lastname' => 'last name',
6692: 'lastfirst' => 'last name, first name',
6693: );
6694: my @titleorder = ('uname','lastname','lastfirst');
6695: return (\%searchtitles,\@titleorder);
6696: }
6697:
1.25 raeburn 6698: sub sorted_searchtypes {
6699: my %srchtypes_desc = (
6700: exact => 'is exact match',
6701: contains => 'contains ..',
6702: begins => 'begins with ..',
6703: );
6704: my @srchtypeorder = ('exact','begins','contains');
6705: return (\%srchtypes_desc,\@srchtypeorder);
6706: }
6707:
1.3 raeburn 6708: sub usertype_update_row {
6709: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6710: my $datatable;
6711: my $numinrow = 4;
6712: foreach my $type (@{$types}) {
6713: if (defined($usertypes->{$type})) {
6714: $$rownums ++;
6715: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6716: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6717: '</td><td class="LC_left_item"><table>';
6718: for (my $i=0; $i<@{$fields}; $i++) {
6719: my $rem = $i%($numinrow);
6720: if ($rem == 0) {
6721: if ($i > 0) {
6722: $datatable .= '</tr>';
6723: }
6724: $datatable .= '<tr>';
6725: }
6726: my $check = ' ';
1.39 raeburn 6727: if (ref($settings) eq 'HASH') {
6728: if (ref($settings->{'fields'}) eq 'HASH') {
6729: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6730: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6731: $check = ' checked="checked" ';
6732: }
1.3 raeburn 6733: }
6734: }
6735: }
6736:
6737: if ($i == @{$fields}-1) {
6738: my $colsleft = $numinrow - $rem;
6739: if ($colsleft > 1) {
6740: $datatable .= '<td colspan="'.$colsleft.'">';
6741: } else {
6742: $datatable .= '<td>';
6743: }
6744: } else {
6745: $datatable .= '<td>';
6746: }
1.8 raeburn 6747: $datatable .= '<span class="LC_nobreak"><label>'.
6748: '<input type="checkbox" name="updateable_'.$type.
6749: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6750: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6751: }
6752: $datatable .= '</tr></table></td></tr>';
6753: }
6754: }
6755: return $datatable;
1.1 raeburn 6756: }
6757:
6758: sub modify_login {
1.160.6.24 raeburn 6759: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 6760: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6761: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6762: %title = ( coursecatalog => 'Display course catalog',
6763: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 6764: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 6765: newuser => 'Link for visitors to create a user account',
6766: loginheader => 'Log-in box header');
6767: @offon = ('off','on');
1.112 raeburn 6768: if (ref($domconfig{login}) eq 'HASH') {
6769: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6770: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6771: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6772: }
6773: }
6774: }
1.9 raeburn 6775: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6776: \%domconfig,\%loginhash);
1.160.6.14 raeburn 6777: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6778: foreach my $item (@toggles) {
6779: $loginhash{login}{$item} = $env{'form.'.$item};
6780: }
1.41 raeburn 6781: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6782: if (ref($colchanges{'login'}) eq 'HASH') {
6783: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6784: \%loginhash);
6785: }
1.110 raeburn 6786:
1.149 raeburn 6787: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 6788: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6789: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6790: if (keys(%servers) > 1) {
6791: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6792: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6793: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6794: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6795: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6796: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6797: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6798: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6799: $changes{'loginvia'}{$lonhost} = 1;
6800: } else {
6801: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6802: $changes{'loginvia'}{$lonhost} = 1;
6803: }
6804: } else {
6805: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6806: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6807: $changes{'loginvia'}{$lonhost} = 1;
6808: }
6809: }
6810: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6811: foreach my $item (@loginvia_attribs) {
6812: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6813: }
6814: } else {
6815: foreach my $item (@loginvia_attribs) {
6816: my $new = $env{'form.'.$lonhost.'_'.$item};
6817: if (($item eq 'serverpath') && ($new eq 'custom')) {
6818: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6819: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6820: $new = '/';
6821: }
6822: }
6823: if (($item eq 'custompath') &&
6824: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6825: $new = '';
6826: }
6827: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6828: $changes{'loginvia'}{$lonhost} = 1;
6829: }
6830: if ($item eq 'exempt') {
1.160.6.56 raeburn 6831: $new = &check_exempt_addresses($new);
1.128 raeburn 6832: }
6833: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6834: }
6835: }
1.112 raeburn 6836: } else {
1.128 raeburn 6837: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6838: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6839: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6840: foreach my $item (@loginvia_attribs) {
6841: my $new = $env{'form.'.$lonhost.'_'.$item};
6842: if (($item eq 'serverpath') && ($new eq 'custom')) {
6843: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6844: $new = '/';
6845: }
6846: }
6847: if (($item eq 'custompath') &&
6848: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6849: $new = '';
6850: }
6851: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6852: }
1.110 raeburn 6853: }
6854: }
6855: }
6856: }
1.119 raeburn 6857:
1.160.6.5 raeburn 6858: my $servadm = $r->dir_config('lonAdmEMail');
6859: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6860: if (ref($domconfig{'login'}) eq 'HASH') {
6861: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6862: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6863: if ($lang eq 'nolang') {
6864: push(@currlangs,$lang);
6865: } elsif (defined($langchoices{$lang})) {
6866: push(@currlangs,$lang);
6867: } else {
6868: next;
6869: }
6870: }
6871: }
6872: }
6873: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6874: if (@currlangs > 0) {
6875: foreach my $lang (@currlangs) {
6876: if (grep(/^\Q$lang\E$/,@delurls)) {
6877: $changes{'helpurl'}{$lang} = 1;
6878: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6879: $changes{'helpurl'}{$lang} = 1;
6880: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6881: push(@newlangs,$lang);
6882: } else {
6883: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6884: }
6885: }
6886: }
6887: unless (grep(/^nolang$/,@currlangs)) {
6888: if ($env{'form.loginhelpurl_nolang.filename'}) {
6889: $changes{'helpurl'}{'nolang'} = 1;
6890: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6891: push(@newlangs,'nolang');
6892: }
6893: }
6894: if ($env{'form.loginhelpurl_add_lang'}) {
6895: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6896: ($env{'form.loginhelpurl_add_file.filename'})) {
6897: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6898: $addedfile = $env{'form.loginhelpurl_add_lang'};
6899: }
6900: }
6901: if ((@newlangs > 0) || ($addedfile)) {
6902: my $error;
6903: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6904: if ($configuserok eq 'ok') {
6905: if ($switchserver) {
6906: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6907: } elsif ($author_ok eq 'ok') {
6908: my @allnew = @newlangs;
6909: if ($addedfile ne '') {
6910: push(@allnew,$addedfile);
6911: }
6912: foreach my $lang (@allnew) {
6913: my $formelem = 'loginhelpurl_'.$lang;
6914: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6915: $formelem = 'loginhelpurl_add_file';
6916: }
6917: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6918: "help/$lang",'','',$newfile{$lang});
6919: if ($result eq 'ok') {
6920: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6921: $changes{'helpurl'}{$lang} = 1;
6922: } else {
6923: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6924: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6925: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6926: (!grep(/^\Q$lang\E$/,@delurls))) {
6927: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6928: }
6929: }
6930: }
6931: } else {
6932: $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);
6933: }
6934: } else {
6935: $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);
6936: }
6937: if ($error) {
6938: &Apache::lonnet::logthis($error);
6939: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6940: }
6941: }
1.160.6.56 raeburn 6942:
6943: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6944: if (ref($domconfig{'login'}) eq 'HASH') {
6945: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6946: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6947: if ($domservers{$lonhost}) {
6948: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6949: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 6950: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 6951: }
6952: }
6953: }
6954: }
6955: }
6956: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6957: foreach my $lonhost (sort(keys(%domservers))) {
6958: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6959: $changes{'headtag'}{$lonhost} = 1;
6960: } else {
6961: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6962: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6963: }
6964: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6965: push(@newhosts,$lonhost);
6966: } elsif ($currheadtagurls{$lonhost}) {
6967: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6968: if ($currexempt{$lonhost}) {
6969: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6970: $changes{'headtag'}{$lonhost} = 1;
6971: }
6972: } elsif ($possexempt{$lonhost}) {
6973: $changes{'headtag'}{$lonhost} = 1;
6974: }
6975: if ($possexempt{$lonhost}) {
6976: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6977: }
6978: }
6979: }
6980: }
6981: if (@newhosts) {
6982: my $error;
6983: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6984: if ($configuserok eq 'ok') {
6985: if ($switchserver) {
6986: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6987: } elsif ($author_ok eq 'ok') {
6988: foreach my $lonhost (@newhosts) {
6989: my $formelem = 'loginheadtag_'.$lonhost;
6990: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6991: "login/headtag/$lonhost",'','',
6992: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6993: if ($result eq 'ok') {
6994: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6995: $changes{'headtag'}{$lonhost} = 1;
6996: if ($possexempt{$lonhost}) {
6997: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6998: }
6999: } else {
7000: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7001: $newheadtagurls{$lonhost},$result);
7002: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7003: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7004: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7005: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7006: }
7007: }
7008: }
7009: } else {
7010: $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);
7011: }
7012: } else {
7013: $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);
7014: }
7015: if ($error) {
7016: &Apache::lonnet::logthis($error);
7017: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7018: }
7019: }
1.160.6.5 raeburn 7020: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7021:
7022: my $defaulthelpfile = '/adm/loginproblems.html';
7023: my $defaulttext = &mt('Default in use');
7024:
1.1 raeburn 7025: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7026: $dom);
7027: if ($putresult eq 'ok') {
1.160.6.14 raeburn 7028: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7029: my %defaultchecked = (
7030: 'coursecatalog' => 'on',
1.160.6.14 raeburn 7031: 'helpdesk' => 'on',
1.42 raeburn 7032: 'adminmail' => 'off',
1.43 raeburn 7033: 'newuser' => 'off',
1.42 raeburn 7034: );
1.55 raeburn 7035: if (ref($domconfig{'login'}) eq 'HASH') {
7036: foreach my $item (@toggles) {
7037: if ($defaultchecked{$item} eq 'on') {
7038: if (($domconfig{'login'}{$item} eq '0') &&
7039: ($env{'form.'.$item} eq '1')) {
7040: $changes{$item} = 1;
7041: } elsif (($domconfig{'login'}{$item} eq '' ||
7042: $domconfig{'login'}{$item} eq '1') &&
7043: ($env{'form.'.$item} eq '0')) {
7044: $changes{$item} = 1;
7045: }
7046: } elsif ($defaultchecked{$item} eq 'off') {
7047: if (($domconfig{'login'}{$item} eq '1') &&
7048: ($env{'form.'.$item} eq '0')) {
7049: $changes{$item} = 1;
7050: } elsif (($domconfig{'login'}{$item} eq '' ||
7051: $domconfig{'login'}{$item} eq '0') &&
7052: ($env{'form.'.$item} eq '1')) {
7053: $changes{$item} = 1;
7054: }
1.42 raeburn 7055: }
7056: }
1.41 raeburn 7057: }
1.6 raeburn 7058: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7059: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7060: if (ref($lastactref) eq 'HASH') {
7061: $lastactref->{'domainconfig'} = 1;
7062: }
1.1 raeburn 7063: $resulttext = &mt('Changes made:').'<ul>';
7064: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7065: if ($item eq 'loginvia') {
1.112 raeburn 7066: if (ref($changes{$item}) eq 'HASH') {
7067: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7068: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7069: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7070: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7071: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7072: $protocol = 'http' if ($protocol ne 'https');
7073: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7074:
7075: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7076: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7077: } else {
7078: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7079: }
7080: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7081: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7082: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7083: }
7084: $resulttext .= '</li>';
7085: } else {
7086: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7087: }
1.112 raeburn 7088: } else {
1.128 raeburn 7089: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7090: }
7091: }
1.128 raeburn 7092: $resulttext .= '</ul></li>';
1.112 raeburn 7093: }
1.160.6.5 raeburn 7094: } elsif ($item eq 'helpurl') {
7095: if (ref($changes{$item}) eq 'HASH') {
7096: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7097: if (grep(/^\Q$lang\E$/,@delurls)) {
7098: my ($chg,$link);
7099: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7100: if ($lang eq 'nolang') {
7101: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7102: } else {
7103: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7104: }
7105: $resulttext .= '<li>'.$chg.'</li>';
7106: } else {
7107: my $chg;
7108: if ($lang eq 'nolang') {
7109: $chg = &mt('custom log-in help file for no preferred language');
7110: } else {
7111: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7112: }
7113: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7114: $loginhash{'login'}{'helpurl'}{$lang}.
7115: '?inhibitmenu=yes',$chg,600,500).
7116: '</li>';
7117: }
7118: }
7119: }
1.160.6.56 raeburn 7120: } elsif ($item eq 'headtag') {
7121: if (ref($changes{$item}) eq 'HASH') {
7122: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7123: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7124: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7125: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7126: $resulttext .= '<li><a href="'.
7127: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7128: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7129: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7130: if ($possexempt{$lonhost}) {
7131: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7132: } else {
7133: $resulttext .= &mt('included for any client IP');
7134: }
7135: $resulttext .= '</li>';
7136: }
7137: }
7138: }
1.160.6.5 raeburn 7139: } elsif ($item eq 'captcha') {
7140: if (ref($loginhash{'login'}) eq 'HASH') {
7141: my $chgtxt;
7142: if ($loginhash{'login'}{$item} eq 'notused') {
7143: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7144: } else {
7145: my %captchas = &captcha_phrases();
7146: if ($captchas{$loginhash{'login'}{$item}}) {
7147: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7148: } else {
7149: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7150: }
7151: }
7152: $resulttext .= '<li>'.$chgtxt.'</li>';
7153: }
7154: } elsif ($item eq 'recaptchakeys') {
7155: if (ref($loginhash{'login'}) eq 'HASH') {
7156: my ($privkey,$pubkey);
7157: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7158: $pubkey = $loginhash{'login'}{$item}{'public'};
7159: $privkey = $loginhash{'login'}{$item}{'private'};
7160: }
7161: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7162: if (!$pubkey) {
7163: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7164: } else {
7165: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7166: }
7167: if (!$privkey) {
7168: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7169: } else {
1.160.6.53 raeburn 7170: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 7171: }
7172: $chgtxt .= '</ul>';
7173: $resulttext .= '<li>'.$chgtxt.'</li>';
7174: }
1.160.6.69 raeburn 7175: } elsif ($item eq 'recaptchaversion') {
7176: if (ref($loginhash{'login'}) eq 'HASH') {
7177: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
7178: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
7179: '</li>';
7180: }
7181: }
1.41 raeburn 7182: } else {
7183: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7184: }
1.1 raeburn 7185: }
1.6 raeburn 7186: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7187: } else {
7188: $resulttext = &mt('No changes made to log-in page settings');
7189: }
7190: } else {
1.11 albertel 7191: $resulttext = '<span class="LC_error">'.
7192: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7193: }
1.6 raeburn 7194: if ($errors) {
1.9 raeburn 7195: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7196: $errors.'</ul>';
7197: }
7198: return $resulttext;
7199: }
7200:
1.160.6.56 raeburn 7201: sub check_exempt_addresses {
7202: my ($iplist) = @_;
7203: $iplist =~ s/^\s+//;
7204: $iplist =~ s/\s+$//;
7205: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7206: my (@okips,$new);
7207: foreach my $ip (@poss_ips) {
7208: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7209: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7210: push(@okips,$ip);
7211: }
7212: }
7213: }
7214: if (@okips > 0) {
7215: $new = join(',',@okips);
7216: } else {
7217: $new = '';
7218: }
7219: return $new;
7220: }
7221:
1.6 raeburn 7222: sub color_font_choices {
7223: my %choices =
7224: &Apache::lonlocal::texthash (
7225: img => "Header",
7226: bgs => "Background colors",
7227: links => "Link colors",
1.55 raeburn 7228: images => "Images",
1.6 raeburn 7229: font => "Font color",
1.160.6.22 raeburn 7230: fontmenu => "Font menu",
1.76 raeburn 7231: pgbg => "Page",
1.6 raeburn 7232: tabbg => "Header",
7233: sidebg => "Border",
7234: link => "Link",
7235: alink => "Active link",
7236: vlink => "Visited link",
7237: );
7238: return %choices;
7239: }
7240:
7241: sub modify_rolecolors {
1.160.6.24 raeburn 7242: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7243: my ($resulttext,%rolehash);
7244: $rolehash{'rolecolors'} = {};
1.55 raeburn 7245: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7246: if ($domconfig{'rolecolors'} eq '') {
7247: $domconfig{'rolecolors'} = {};
7248: }
7249: }
1.9 raeburn 7250: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7251: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7252: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7253: $dom);
7254: if ($putresult eq 'ok') {
7255: if (keys(%changes) > 0) {
1.41 raeburn 7256: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7257: if (ref($lastactref) eq 'HASH') {
7258: $lastactref->{'domainconfig'} = 1;
7259: }
1.6 raeburn 7260: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7261: $rolehash{'rolecolors'});
7262: } else {
7263: $resulttext = &mt('No changes made to default color schemes');
7264: }
7265: } else {
1.11 albertel 7266: $resulttext = '<span class="LC_error">'.
7267: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7268: }
7269: if ($errors) {
7270: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7271: $errors.'</ul>';
7272: }
7273: return $resulttext;
7274: }
7275:
7276: sub modify_colors {
1.9 raeburn 7277: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7278: my (%changes,%choices);
1.51 raeburn 7279: my @bgs;
1.6 raeburn 7280: my @links = ('link','alink','vlink');
1.41 raeburn 7281: my @logintext;
1.6 raeburn 7282: my @images;
7283: my $servadm = $r->dir_config('lonAdmEMail');
7284: my $errors;
1.160.6.22 raeburn 7285: my %defaults;
1.6 raeburn 7286: foreach my $role (@{$roles}) {
7287: if ($role eq 'login') {
1.12 raeburn 7288: %choices = &login_choices();
1.41 raeburn 7289: @logintext = ('textcol','bgcol');
1.12 raeburn 7290: } else {
7291: %choices = &color_font_choices();
7292: }
7293: if ($role eq 'login') {
1.41 raeburn 7294: @images = ('img','logo','domlogo','login');
1.51 raeburn 7295: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7296: } else {
7297: @images = ('img');
1.160.6.22 raeburn 7298: @bgs = ('pgbg','tabbg','sidebg');
7299: }
7300: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7301: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7302: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7303: }
7304: if ($role eq 'login') {
7305: foreach my $item (@logintext) {
1.160.6.39 raeburn 7306: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7307: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7308: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7309: }
7310: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 7311: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7312: }
7313: }
7314: } else {
1.160.6.39 raeburn 7315: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7316: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7317: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7318: }
7319: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 7320: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7321: }
1.6 raeburn 7322: }
1.160.6.22 raeburn 7323: foreach my $item (@bgs) {
1.160.6.39 raeburn 7324: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7325: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7326: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7327: }
7328: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 7329: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7330: }
7331: }
7332: foreach my $item (@links) {
1.160.6.39 raeburn 7333: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7334: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7335: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7336: }
7337: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 7338: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7339: }
1.6 raeburn 7340: }
1.46 raeburn 7341: my ($configuserok,$author_ok,$switchserver) =
7342: &config_check($dom,$confname,$servadm);
1.9 raeburn 7343: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7344: if (ref($domconfig->{$role}) ne 'HASH') {
7345: $domconfig->{$role} = {};
7346: }
1.8 raeburn 7347: foreach my $img (@images) {
1.70 raeburn 7348: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7349: if (defined($env{'form.login_showlogo_'.$img})) {
7350: $confhash->{$role}{'showlogo'}{$img} = 1;
7351: } else {
7352: $confhash->{$role}{'showlogo'}{$img} = 0;
7353: }
7354: }
1.18 albertel 7355: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7356: && !defined($domconfig->{$role}{$img})
7357: && !$env{'form.'.$role.'_del_'.$img}
7358: && $env{'form.'.$role.'_import_'.$img}) {
7359: # import the old configured image from the .tab setting
7360: # if they haven't provided a new one
7361: $domconfig->{$role}{$img} =
7362: $env{'form.'.$role.'_import_'.$img};
7363: }
1.6 raeburn 7364: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7365: my $error;
1.6 raeburn 7366: if ($configuserok eq 'ok') {
1.9 raeburn 7367: if ($switchserver) {
1.12 raeburn 7368: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7369: } else {
7370: if ($author_ok eq 'ok') {
7371: my ($result,$logourl) =
7372: &publishlogo($r,'upload',$role.'_'.$img,
7373: $dom,$confname,$img,$width,$height);
7374: if ($result eq 'ok') {
7375: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7376: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7377: } else {
1.12 raeburn 7378: $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 7379: }
7380: } else {
1.46 raeburn 7381: $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 7382: }
7383: }
7384: } else {
1.46 raeburn 7385: $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 7386: }
7387: if ($error) {
1.8 raeburn 7388: &Apache::lonnet::logthis($error);
1.11 albertel 7389: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7390: }
7391: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7392: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7393: my $error;
7394: if ($configuserok eq 'ok') {
7395: # is confname an author?
7396: if ($switchserver eq '') {
7397: if ($author_ok eq 'ok') {
7398: my ($result,$logourl) =
7399: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7400: $dom,$confname,$img,$width,$height);
7401: if ($result eq 'ok') {
7402: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7403: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7404: }
7405: }
7406: }
7407: }
1.6 raeburn 7408: }
7409: }
7410: }
7411: if (ref($domconfig) eq 'HASH') {
7412: if (ref($domconfig->{$role}) eq 'HASH') {
7413: foreach my $img (@images) {
7414: if ($domconfig->{$role}{$img} ne '') {
7415: if ($env{'form.'.$role.'_del_'.$img}) {
7416: $confhash->{$role}{$img} = '';
1.12 raeburn 7417: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7418: } else {
1.9 raeburn 7419: if ($confhash->{$role}{$img} eq '') {
7420: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7421: }
1.6 raeburn 7422: }
7423: } else {
7424: if ($env{'form.'.$role.'_del_'.$img}) {
7425: $confhash->{$role}{$img} = '';
1.12 raeburn 7426: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7427: }
7428: }
1.70 raeburn 7429: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7430: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7431: if ($confhash->{$role}{'showlogo'}{$img} ne
7432: $domconfig->{$role}{'showlogo'}{$img}) {
7433: $changes{$role}{'showlogo'}{$img} = 1;
7434: }
7435: } else {
7436: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7437: $changes{$role}{'showlogo'}{$img} = 1;
7438: }
7439: }
7440: }
7441: }
1.6 raeburn 7442: if ($domconfig->{$role}{'font'} ne '') {
7443: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7444: $changes{$role}{'font'} = 1;
7445: }
7446: } else {
7447: if ($confhash->{$role}{'font'}) {
7448: $changes{$role}{'font'} = 1;
7449: }
7450: }
1.107 raeburn 7451: if ($role ne 'login') {
7452: if ($domconfig->{$role}{'fontmenu'} ne '') {
7453: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7454: $changes{$role}{'fontmenu'} = 1;
7455: }
7456: } else {
7457: if ($confhash->{$role}{'fontmenu'}) {
7458: $changes{$role}{'fontmenu'} = 1;
7459: }
1.97 tempelho 7460: }
7461: }
1.6 raeburn 7462: foreach my $item (@bgs) {
7463: if ($domconfig->{$role}{$item} ne '') {
7464: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7465: $changes{$role}{'bgs'}{$item} = 1;
7466: }
7467: } else {
7468: if ($confhash->{$role}{$item}) {
7469: $changes{$role}{'bgs'}{$item} = 1;
7470: }
7471: }
7472: }
7473: foreach my $item (@links) {
7474: if ($domconfig->{$role}{$item} ne '') {
7475: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7476: $changes{$role}{'links'}{$item} = 1;
7477: }
7478: } else {
7479: if ($confhash->{$role}{$item}) {
7480: $changes{$role}{'links'}{$item} = 1;
7481: }
7482: }
7483: }
1.41 raeburn 7484: foreach my $item (@logintext) {
7485: if ($domconfig->{$role}{$item} ne '') {
7486: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7487: $changes{$role}{'logintext'}{$item} = 1;
7488: }
7489: } else {
7490: if ($confhash->{$role}{$item}) {
7491: $changes{$role}{'logintext'}{$item} = 1;
7492: }
7493: }
7494: }
1.6 raeburn 7495: } else {
7496: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7497: \@logintext,$confhash,\%changes);
1.6 raeburn 7498: }
7499: } else {
7500: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7501: \@logintext,$confhash,\%changes);
1.6 raeburn 7502: }
7503: }
7504: return ($errors,%changes);
7505: }
7506:
1.46 raeburn 7507: sub config_check {
7508: my ($dom,$confname,$servadm) = @_;
7509: my ($configuserok,$author_ok,$switchserver,%currroles);
7510: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7511: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7512: $confname,$servadm);
7513: if ($configuserok eq 'ok') {
7514: $switchserver = &check_switchserver($dom,$confname);
7515: if ($switchserver eq '') {
7516: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7517: }
7518: }
7519: return ($configuserok,$author_ok,$switchserver);
7520: }
7521:
1.6 raeburn 7522: sub default_change_checker {
1.41 raeburn 7523: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7524: foreach my $item (@{$links}) {
7525: if ($confhash->{$role}{$item}) {
7526: $changes->{$role}{'links'}{$item} = 1;
7527: }
7528: }
7529: foreach my $item (@{$bgs}) {
7530: if ($confhash->{$role}{$item}) {
7531: $changes->{$role}{'bgs'}{$item} = 1;
7532: }
7533: }
1.41 raeburn 7534: foreach my $item (@{$logintext}) {
7535: if ($confhash->{$role}{$item}) {
7536: $changes->{$role}{'logintext'}{$item} = 1;
7537: }
7538: }
1.6 raeburn 7539: foreach my $img (@{$images}) {
7540: if ($env{'form.'.$role.'_del_'.$img}) {
7541: $confhash->{$role}{$img} = '';
1.12 raeburn 7542: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7543: }
1.70 raeburn 7544: if ($role eq 'login') {
7545: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7546: $changes->{$role}{'showlogo'}{$img} = 1;
7547: }
7548: }
1.6 raeburn 7549: }
7550: if ($confhash->{$role}{'font'}) {
7551: $changes->{$role}{'font'} = 1;
7552: }
1.48 raeburn 7553: }
1.6 raeburn 7554:
7555: sub display_colorchgs {
7556: my ($dom,$changes,$roles,$confhash) = @_;
7557: my (%choices,$resulttext);
7558: if (!grep(/^login$/,@{$roles})) {
7559: $resulttext = &mt('Changes made:').'<br />';
7560: }
7561: foreach my $role (@{$roles}) {
7562: if ($role eq 'login') {
7563: %choices = &login_choices();
7564: } else {
7565: %choices = &color_font_choices();
7566: }
7567: if (ref($changes->{$role}) eq 'HASH') {
7568: if ($role ne 'login') {
7569: $resulttext .= '<h4>'.&mt($role).'</h4>';
7570: }
7571: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7572: if ($role ne 'login') {
7573: $resulttext .= '<ul>';
7574: }
7575: if (ref($changes->{$role}{$key}) eq 'HASH') {
7576: if ($role ne 'login') {
7577: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7578: }
7579: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7580: if (($role eq 'login') && ($key eq 'showlogo')) {
7581: if ($confhash->{$role}{$key}{$item}) {
7582: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7583: } else {
7584: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7585: }
7586: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7587: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7588: } else {
1.12 raeburn 7589: my $newitem = $confhash->{$role}{$item};
7590: if ($key eq 'images') {
7591: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7592: }
7593: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7594: }
7595: }
7596: if ($role ne 'login') {
7597: $resulttext .= '</ul></li>';
7598: }
7599: } else {
7600: if ($confhash->{$role}{$key} eq '') {
7601: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7602: } else {
7603: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7604: }
7605: }
7606: if ($role ne 'login') {
7607: $resulttext .= '</ul>';
7608: }
7609: }
7610: }
7611: }
1.3 raeburn 7612: return $resulttext;
1.1 raeburn 7613: }
7614:
1.9 raeburn 7615: sub thumb_dimensions {
7616: return ('200','50');
7617: }
7618:
1.16 raeburn 7619: sub check_dimensions {
7620: my ($inputfile) = @_;
7621: my ($fullwidth,$fullheight);
7622: if ($inputfile =~ m|^[/\w.\-]+$|) {
7623: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7624: my $imageinfo = <PIPE>;
7625: if (!close(PIPE)) {
7626: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7627: }
7628: chomp($imageinfo);
7629: my ($fullsize) =
1.21 raeburn 7630: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7631: if ($fullsize) {
7632: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7633: }
7634: }
7635: }
7636: return ($fullwidth,$fullheight);
7637: }
7638:
1.9 raeburn 7639: sub check_configuser {
7640: my ($uhome,$dom,$confname,$servadm) = @_;
7641: my ($configuserok,%currroles);
7642: if ($uhome eq 'no_host') {
7643: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7644: my $configpass = &LONCAPA::Enrollment::create_password();
7645: $configuserok =
7646: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7647: $configpass,'','','','','',undef,$servadm);
7648: } else {
7649: $configuserok = 'ok';
7650: %currroles =
7651: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7652: }
7653: return ($configuserok,%currroles);
7654: }
7655:
7656: sub check_authorstatus {
7657: my ($dom,$confname,%currroles) = @_;
7658: my $author_ok;
1.40 raeburn 7659: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7660: my $start = time;
7661: my $end = 0;
7662: $author_ok =
7663: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7664: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7665: } else {
7666: $author_ok = 'ok';
7667: }
7668: return $author_ok;
7669: }
7670:
7671: sub publishlogo {
1.46 raeburn 7672: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 7673: my ($output,$fname,$logourl);
7674: if ($action eq 'upload') {
7675: $fname=$env{'form.'.$formname.'.filename'};
7676: chop($env{'form.'.$formname});
7677: } else {
7678: ($fname) = ($formname =~ /([^\/]+)$/);
7679: }
1.46 raeburn 7680: if ($savefileas ne '') {
7681: $fname = $savefileas;
7682: }
1.9 raeburn 7683: $fname=&Apache::lonnet::clean_filename($fname);
7684: # See if there is anything left
7685: unless ($fname) { return ('error: no uploaded file'); }
7686: $fname="$subdir/$fname";
1.160.6.5 raeburn 7687: my $docroot=$r->dir_config('lonDocRoot');
7688: my $filepath="$docroot/priv";
7689: my $relpath = "$dom/$confname";
1.9 raeburn 7690: my ($fnamepath,$file,$fetchthumb);
7691: $file=$fname;
7692: if ($fname=~m|/|) {
7693: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7694: }
1.160.6.26 raeburn 7695: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7696: my $count;
1.160.6.5 raeburn 7697: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7698: $filepath.="/$parts[$count]";
7699: if ((-e $filepath)!=1) {
7700: mkdir($filepath,02770);
7701: }
7702: }
7703: # Check for bad extension and disallow upload
7704: if ($file=~/\.(\w+)$/ &&
7705: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7706: $output =
1.160.6.25 raeburn 7707: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7708: } elsif ($file=~/\.(\w+)$/ &&
7709: !defined(&Apache::loncommon::fileembstyle($1))) {
7710: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7711: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 7712: $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 7713: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 7714: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7715: } else {
7716: my $source = $filepath.'/'.$file;
7717: my $logfile;
7718: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 7719: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7720: }
7721: print $logfile
7722: "\n================= Publish ".localtime()." ================\n".
7723: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7724: # Save the file
7725: if (!open(FH,'>'.$source)) {
7726: &Apache::lonnet::logthis('Failed to create '.$source);
7727: return (&mt('Failed to create file'));
7728: }
7729: if ($action eq 'upload') {
7730: if (!print FH ($env{'form.'.$formname})) {
7731: &Apache::lonnet::logthis('Failed to write to '.$source);
7732: return (&mt('Failed to write file'));
7733: }
7734: } else {
7735: my $original = &Apache::lonnet::filelocation('',$formname);
7736: if(!copy($original,$source)) {
7737: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7738: return (&mt('Failed to write file'));
7739: }
7740: }
7741: close(FH);
7742: chmod(0660, $source); # Permissions to rw-rw---.
7743:
7744: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7745: my $copyfile=$targetdir.'/'.$file;
7746:
7747: my @parts=split(/\//,$targetdir);
7748: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7749: for (my $count=5;$count<=$#parts;$count++) {
7750: $path.="/$parts[$count]";
7751: if (!-e $path) {
7752: print $logfile "\nCreating directory ".$path;
7753: mkdir($path,02770);
7754: }
7755: }
7756: my $versionresult;
7757: if (-e $copyfile) {
7758: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7759: } else {
7760: $versionresult = 'ok';
7761: }
7762: if ($versionresult eq 'ok') {
7763: if (copy($source,$copyfile)) {
7764: print $logfile "\nCopied original source to ".$copyfile."\n";
7765: $output = 'ok';
7766: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7767: push(@{$modified_urls},[$copyfile,$source]);
7768: my $metaoutput =
7769: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7770: unless ($registered_cleanup) {
7771: my $handlers = $r->get_handlers('PerlCleanupHandler');
7772: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7773: $registered_cleanup=1;
7774: }
1.9 raeburn 7775: } else {
7776: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7777: $output = &mt('Failed to copy file to RES space').", $!";
7778: }
7779: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7780: my $inputfile = $filepath.'/'.$file;
7781: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7782: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7783: if ($fullwidth ne '' && $fullheight ne '') {
7784: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7785: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7786: system("convert -sample $thumbsize $inputfile $outfile");
7787: chmod(0660, $filepath.'/tn-'.$file);
7788: if (-e $outfile) {
7789: my $copyfile=$targetdir.'/tn-'.$file;
7790: if (copy($outfile,$copyfile)) {
7791: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7792: my $thumb_metaoutput =
7793: &write_metadata($dom,$confname,$formname,
7794: $targetdir,'tn-'.$file,$logfile);
7795: push(@{$modified_urls},[$copyfile,$outfile]);
7796: unless ($registered_cleanup) {
7797: my $handlers = $r->get_handlers('PerlCleanupHandler');
7798: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7799: $registered_cleanup=1;
7800: }
1.16 raeburn 7801: } else {
7802: print $logfile "\nUnable to write ".$copyfile.
7803: ':'.$!."\n";
7804: }
7805: }
1.9 raeburn 7806: }
7807: }
7808: }
7809: } else {
7810: $output = $versionresult;
7811: }
7812: }
7813: return ($output,$logourl);
7814: }
7815:
7816: sub logo_versioning {
7817: my ($targetdir,$file,$logfile) = @_;
7818: my $target = $targetdir.'/'.$file;
7819: my ($maxversion,$fn,$extn,$output);
7820: $maxversion = 0;
7821: if ($file =~ /^(.+)\.(\w+)$/) {
7822: $fn=$1;
7823: $extn=$2;
7824: }
7825: opendir(DIR,$targetdir);
7826: while (my $filename=readdir(DIR)) {
7827: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7828: $maxversion=($1>$maxversion)?$1:$maxversion;
7829: }
7830: }
7831: $maxversion++;
7832: print $logfile "\nCreating old version ".$maxversion."\n";
7833: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7834: if (copy($target,$copyfile)) {
7835: print $logfile "Copied old target to ".$copyfile."\n";
7836: $copyfile=$copyfile.'.meta';
7837: if (copy($target.'.meta',$copyfile)) {
7838: print $logfile "Copied old target metadata to ".$copyfile."\n";
7839: $output = 'ok';
7840: } else {
7841: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7842: $output = &mt('Failed to copy old meta').", $!, ";
7843: }
7844: } else {
7845: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7846: $output = &mt('Failed to copy old target').", $!, ";
7847: }
7848: return $output;
7849: }
7850:
7851: sub write_metadata {
7852: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7853: my (%metadatafields,%metadatakeys,$output);
7854: $metadatafields{'title'}=$formname;
7855: $metadatafields{'creationdate'}=time;
7856: $metadatafields{'lastrevisiondate'}=time;
7857: $metadatafields{'copyright'}='public';
7858: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7859: $env{'user.domain'};
7860: $metadatafields{'authorspace'}=$confname.':'.$dom;
7861: $metadatafields{'domain'}=$dom;
7862: {
7863: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7864: my $mfh;
1.155 raeburn 7865: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 7866: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7867: unless ($_=~/\./) {
7868: my $unikey=$_;
7869: $unikey=~/^([A-Za-z]+)/;
7870: my $tag=$1;
7871: $tag=~tr/A-Z/a-z/;
7872: print $mfh "\n\<$tag";
7873: foreach (split(/\,/,$metadatakeys{$unikey})) {
7874: my $value=$metadatafields{$unikey.'.'.$_};
7875: $value=~s/\"/\'\'/g;
7876: print $mfh ' '.$_.'="'.$value.'"';
7877: }
7878: print $mfh '>'.
7879: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7880: .'</'.$tag.'>';
7881: }
7882: }
7883: $output = 'ok';
7884: print $logfile "\nWrote metadata";
7885: close($mfh);
7886: } else {
7887: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7888: $output = &mt('Could not write metadata');
7889: }
7890: }
1.155 raeburn 7891: return $output;
7892: }
7893:
7894: sub notifysubscribed {
7895: foreach my $targetsource (@{$modified_urls}){
7896: next unless (ref($targetsource) eq 'ARRAY');
7897: my ($target,$source)=@{$targetsource};
7898: if ($source ne '') {
7899: if (open(my $logfh,'>>'.$source.'.log')) {
7900: print $logfh "\nCleanup phase: Notifications\n";
7901: my @subscribed=&subscribed_hosts($target);
7902: foreach my $subhost (@subscribed) {
7903: print $logfh "\nNotifying host ".$subhost.':';
7904: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7905: print $logfh $reply;
7906: }
7907: my @subscribedmeta=&subscribed_hosts("$target.meta");
7908: foreach my $subhost (@subscribedmeta) {
7909: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7910: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7911: $subhost);
7912: print $logfh $reply;
7913: }
7914: print $logfh "\n============ Done ============\n";
1.160 raeburn 7915: close($logfh);
1.155 raeburn 7916: }
7917: }
7918: }
7919: return OK;
7920: }
7921:
7922: sub subscribed_hosts {
7923: my ($target) = @_;
7924: my @subscribed;
7925: if (open(my $fh,"<$target.subscription")) {
7926: while (my $subline=<$fh>) {
7927: if ($subline =~ /^($match_lonid):/) {
7928: my $host = $1;
7929: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7930: unless (grep(/^\Q$host\E$/,@subscribed)) {
7931: push(@subscribed,$host);
7932: }
7933: }
7934: }
7935: }
7936: }
7937: return @subscribed;
1.9 raeburn 7938: }
7939:
7940: sub check_switchserver {
7941: my ($dom,$confname) = @_;
7942: my ($allowed,$switchserver);
7943: my $home = &Apache::lonnet::homeserver($confname,$dom);
7944: if ($home eq 'no_host') {
7945: $home = &Apache::lonnet::domain($dom,'primary');
7946: }
7947: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7948: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7949: if (!$allowed) {
1.160.6.11 raeburn 7950: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7951: }
7952: return $switchserver;
7953: }
7954:
1.1 raeburn 7955: sub modify_quotas {
1.160.6.30 raeburn 7956: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7957: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7958: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7959: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7960: $validationfieldsref);
1.86 raeburn 7961: if ($action eq 'quotas') {
7962: $context = 'tools';
1.160.6.26 raeburn 7963: } else {
1.86 raeburn 7964: $context = $action;
7965: }
7966: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7967: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7968: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7969: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7970: %titles = &courserequest_titles();
7971: $toolregexp = join('|',@usertools);
7972: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7973: $confname = $dom.'-domainconfig';
7974: my $servadm = $r->dir_config('lonAdmEMail');
7975: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7976: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7977: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7978: } elsif ($context eq 'requestauthor') {
7979: @usertools = ('author');
7980: %titles = &authorrequest_titles();
1.86 raeburn 7981: } else {
1.160.6.4 raeburn 7982: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7983: %titles = &tool_titles();
1.86 raeburn 7984: }
1.160.6.27 raeburn 7985: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7986: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7987: foreach my $key (keys(%env)) {
1.101 raeburn 7988: if ($context eq 'requestcourses') {
7989: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7990: my $item = $1;
7991: my $type = $2;
7992: if ($type =~ /^limit_(.+)/) {
7993: $limithash{$item}{$1} = $env{$key};
7994: } else {
7995: $confhash{$item}{$type} = $env{$key};
7996: }
7997: }
1.160.6.5 raeburn 7998: } elsif ($context eq 'requestauthor') {
7999: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8000: $confhash{$1} = $env{$key};
8001: }
1.101 raeburn 8002: } else {
1.86 raeburn 8003: if ($key =~ /^form\.quota_(.+)$/) {
8004: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 8005: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8006: $confhash{'authorquota'}{$1} = $env{$key};
8007: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8008: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8009: }
1.72 raeburn 8010: }
8011: }
1.160.6.5 raeburn 8012: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 8013: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8014: @approvalnotify = sort(@approvalnotify);
8015: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 8016: my @crstypes = ('official','unofficial','community','textbook');
8017: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8018: foreach my $type (@hasuniquecode) {
8019: if (grep(/^\Q$type\E$/,@crstypes)) {
8020: $confhash{'uniquecode'}{$type} = 1;
8021: }
8022: }
1.160.6.46 raeburn 8023: my (%newbook,%allpos);
1.160.6.30 raeburn 8024: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8025: foreach my $type ('textbooks','templates') {
8026: @{$allpos{$type}} = ();
8027: my $invalid;
8028: if ($type eq 'textbooks') {
8029: $invalid = &mt('Invalid LON-CAPA course for textbook');
8030: } else {
8031: $invalid = &mt('Invalid LON-CAPA course for template');
8032: }
8033: if ($env{'form.'.$type.'_addbook'}) {
8034: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8035: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8036: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8037: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8038: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8039: } else {
8040: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8041: my $position = $env{'form.'.$type.'_addbook_pos'};
8042: $position =~ s/\D+//g;
8043: if ($position ne '') {
8044: $allpos{$type}[$position] = $newbook{$type};
8045: }
1.160.6.30 raeburn 8046: }
1.160.6.46 raeburn 8047: } else {
8048: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 8049: }
8050: }
1.160.6.46 raeburn 8051: }
1.160.6.30 raeburn 8052: }
1.102 raeburn 8053: if (ref($domconfig{$action}) eq 'HASH') {
8054: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8055: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8056: $changes{'notify'}{'approval'} = 1;
8057: }
8058: } else {
1.144 raeburn 8059: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8060: $changes{'notify'}{'approval'} = 1;
8061: }
8062: }
1.160.6.30 raeburn 8063: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8064: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8065: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8066: unless ($confhash{'uniquecode'}{$crstype}) {
8067: $changes{'uniquecode'} = 1;
8068: }
8069: }
8070: unless ($changes{'uniquecode'}) {
8071: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8072: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8073: $changes{'uniquecode'} = 1;
8074: }
8075: }
8076: }
8077: } else {
8078: $changes{'uniquecode'} = 1;
8079: }
8080: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8081: $changes{'uniquecode'} = 1;
8082: }
8083: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8084: foreach my $type ('textbooks','templates') {
8085: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8086: my %deletions;
8087: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8088: if (@todelete) {
8089: map { $deletions{$_} = 1; } @todelete;
8090: }
8091: my %imgdeletions;
8092: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8093: if (@todeleteimages) {
8094: map { $imgdeletions{$_} = 1; } @todeleteimages;
8095: }
8096: my $maxnum = $env{'form.'.$type.'_maxnum'};
8097: for (my $i=0; $i<=$maxnum; $i++) {
8098: my $itemid = $env{'form.'.$type.'_id_'.$i};
8099: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8100: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8101: if ($deletions{$key}) {
8102: if ($domconfig{$action}{$type}{$key}{'image'}) {
8103: #FIXME need to obsolete item in RES space
8104: }
8105: next;
8106: } else {
8107: my $newpos = $env{'form.'.$itemid};
8108: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 8109: foreach my $item ('subject','title','publisher','author') {
8110: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8111: ($type eq 'templates'));
1.160.6.46 raeburn 8112: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8113: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8114: $changes{$type}{$key} = 1;
8115: }
8116: }
8117: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 8118: }
1.160.6.46 raeburn 8119: if ($imgdeletions{$key}) {
8120: $changes{$type}{$key} = 1;
8121: #FIXME need to obsolete item in RES space
8122: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8123: my ($cdom,$cnum) = split(/_/,$key);
8124: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8125: $cdom,$cnum,$type,$configuserok,
8126: $switchserver,$author_ok);
8127: if ($imgurl) {
8128: $confhash{$type}{$key}{'image'} = $imgurl;
8129: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 8130: }
1.160.6.46 raeburn 8131: if ($error) {
8132: &Apache::lonnet::logthis($error);
8133: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8134: }
8135: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8136: $confhash{$type}{$key}{'image'} =
8137: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 8138: }
8139: }
8140: }
8141: }
8142: }
8143: }
1.102 raeburn 8144: } else {
1.144 raeburn 8145: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8146: $changes{'notify'}{'approval'} = 1;
8147: }
1.160.6.30 raeburn 8148: if (ref($confhash{'uniquecode'} eq 'HASH')) {
8149: $changes{'uniquecode'} = 1;
8150: }
8151: }
8152: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8153: foreach my $type ('textbooks','templates') {
8154: if ($newbook{$type}) {
8155: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 8156: foreach my $item ('subject','title','publisher','author') {
8157: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8158: ($type eq 'template'));
1.160.6.46 raeburn 8159: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8160: if ($env{'form.'.$type.'_addbook_'.$item}) {
8161: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8162: }
8163: }
8164: if ($type eq 'textbooks') {
8165: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8166: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8167: my ($imageurl,$error) =
8168: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8169: $configuserok,$switchserver,$author_ok);
8170: if ($imageurl) {
8171: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8172: }
8173: if ($error) {
8174: &Apache::lonnet::logthis($error);
8175: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8176: }
8177: }
1.160.6.30 raeburn 8178: }
8179: }
1.160.6.46 raeburn 8180: if (@{$allpos{$type}} > 0) {
8181: my $idx = 0;
8182: foreach my $item (@{$allpos{$type}}) {
8183: if ($item ne '') {
8184: $confhash{$type}{$item}{'order'} = $idx;
8185: if (ref($domconfig{$action}) eq 'HASH') {
8186: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8187: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8188: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8189: $changes{$type}{$item} = 1;
8190: }
1.160.6.30 raeburn 8191: }
8192: }
8193: }
1.160.6.46 raeburn 8194: $idx ++;
1.160.6.30 raeburn 8195: }
8196: }
8197: }
8198: }
1.160.6.39 raeburn 8199: if (ref($validationitemsref) eq 'ARRAY') {
8200: foreach my $item (@{$validationitemsref}) {
8201: if ($item eq 'fields') {
8202: my @changed;
8203: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8204: if (@{$confhash{'validation'}{$item}} > 0) {
8205: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8206: }
1.160.6.65 raeburn 8207: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8208: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8209: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8210: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8211: $domconfig{'requestcourses'}{'validation'}{$item});
8212: } else {
8213: @changed = @{$confhash{'validation'}{$item}};
8214: }
1.160.6.39 raeburn 8215: } else {
8216: @changed = @{$confhash{'validation'}{$item}};
8217: }
8218: } else {
8219: @changed = @{$confhash{'validation'}{$item}};
8220: }
8221: if (@changed) {
8222: if ($confhash{'validation'}{$item}) {
8223: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8224: } else {
8225: $changes{'validation'}{$item} = &mt('None');
8226: }
8227: }
8228: } else {
8229: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8230: if ($item eq 'markup') {
8231: if ($env{'form.requestcourses_validation_'.$item}) {
8232: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8233: }
8234: }
1.160.6.65 raeburn 8235: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8236: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8237: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8238: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8239: }
8240: } else {
8241: if ($confhash{'validation'}{$item} ne '') {
8242: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8243: }
1.160.6.39 raeburn 8244: }
8245: } else {
8246: if ($confhash{'validation'}{$item} ne '') {
8247: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8248: }
8249: }
8250: }
8251: }
8252: }
8253: if ($env{'form.validationdc'}) {
8254: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 8255: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 8256: if (exists($domcoords{$newval})) {
8257: $confhash{'validation'}{'dc'} = $newval;
8258: }
8259: }
8260: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 8261: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8262: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8263: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8264: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8265: if ($confhash{'validation'}{'dc'} eq '') {
8266: $changes{'validation'}{'dc'} = &mt('None');
8267: } else {
8268: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8269: }
1.160.6.39 raeburn 8270: }
1.160.6.65 raeburn 8271: } elsif ($confhash{'validation'}{'dc'} ne '') {
8272: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 8273: }
8274: } elsif ($confhash{'validation'}{'dc'} ne '') {
8275: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8276: }
8277: } elsif ($confhash{'validation'}{'dc'} ne '') {
8278: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8279: }
1.160.6.65 raeburn 8280: } else {
8281: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8282: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8283: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8284: $changes{'validation'}{'dc'} = &mt('None');
8285: }
8286: }
1.160.6.39 raeburn 8287: }
8288: }
1.102 raeburn 8289: }
8290: } else {
1.86 raeburn 8291: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 8292: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8293: }
1.72 raeburn 8294: foreach my $item (@usertools) {
8295: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8296: my $unset;
1.101 raeburn 8297: if ($context eq 'requestcourses') {
1.104 raeburn 8298: $unset = '0';
8299: if ($type eq '_LC_adv') {
8300: $unset = '';
8301: }
1.101 raeburn 8302: if ($confhash{$item}{$type} eq 'autolimit') {
8303: $confhash{$item}{$type} .= '=';
8304: unless ($limithash{$item}{$type} =~ /\D/) {
8305: $confhash{$item}{$type} .= $limithash{$item}{$type};
8306: }
8307: }
1.160.6.5 raeburn 8308: } elsif ($context eq 'requestauthor') {
8309: $unset = '0';
8310: if ($type eq '_LC_adv') {
8311: $unset = '';
8312: }
1.72 raeburn 8313: } else {
1.101 raeburn 8314: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8315: $confhash{$item}{$type} = 1;
8316: } else {
8317: $confhash{$item}{$type} = 0;
8318: }
1.72 raeburn 8319: }
1.86 raeburn 8320: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 8321: if ($action eq 'requestauthor') {
8322: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8323: $changes{$type} = 1;
8324: }
8325: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8326: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8327: $changes{$item}{$type} = 1;
8328: }
8329: } else {
8330: if ($context eq 'requestcourses') {
1.104 raeburn 8331: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8332: $changes{$item}{$type} = 1;
8333: }
8334: } else {
8335: if (!$confhash{$item}{$type}) {
8336: $changes{$item}{$type} = 1;
8337: }
8338: }
8339: }
8340: } else {
8341: if ($context eq 'requestcourses') {
1.104 raeburn 8342: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8343: $changes{$item}{$type} = 1;
8344: }
1.160.6.5 raeburn 8345: } elsif ($context eq 'requestauthor') {
8346: if ($confhash{$type} ne $unset) {
8347: $changes{$type} = 1;
8348: }
1.72 raeburn 8349: } else {
8350: if (!$confhash{$item}{$type}) {
8351: $changes{$item}{$type} = 1;
8352: }
8353: }
8354: }
1.1 raeburn 8355: }
8356: }
1.160.6.5 raeburn 8357: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8358: if (ref($domconfig{'quotas'}) eq 'HASH') {
8359: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8360: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8361: if (exists($confhash{'defaultquota'}{$key})) {
8362: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8363: $changes{'defaultquota'}{$key} = 1;
8364: }
8365: } else {
8366: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8367: }
8368: }
1.86 raeburn 8369: } else {
8370: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8371: if (exists($confhash{'defaultquota'}{$key})) {
8372: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8373: $changes{'defaultquota'}{$key} = 1;
8374: }
8375: } else {
8376: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8377: }
1.1 raeburn 8378: }
8379: }
1.160.6.20 raeburn 8380: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8381: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8382: if (exists($confhash{'authorquota'}{$key})) {
8383: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8384: $changes{'authorquota'}{$key} = 1;
8385: }
8386: } else {
8387: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8388: }
8389: }
8390: }
1.1 raeburn 8391: }
1.86 raeburn 8392: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8393: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8394: if (ref($domconfig{'quotas'}) eq 'HASH') {
8395: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8396: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8397: $changes{'defaultquota'}{$key} = 1;
8398: }
8399: } else {
8400: if (!exists($domconfig{'quotas'}{$key})) {
8401: $changes{'defaultquota'}{$key} = 1;
8402: }
1.72 raeburn 8403: }
8404: } else {
1.86 raeburn 8405: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8406: }
1.1 raeburn 8407: }
8408: }
1.160.6.20 raeburn 8409: if (ref($confhash{'authorquota'}) eq 'HASH') {
8410: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8411: if (ref($domconfig{'quotas'}) eq 'HASH') {
8412: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8413: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8414: $changes{'authorquota'}{$key} = 1;
8415: }
8416: } else {
8417: $changes{'authorquota'}{$key} = 1;
8418: }
8419: } else {
8420: $changes{'authorquota'}{$key} = 1;
8421: }
8422: }
8423: }
1.1 raeburn 8424: }
1.72 raeburn 8425:
1.160.6.5 raeburn 8426: if ($context eq 'requestauthor') {
8427: $domdefaults{'requestauthor'} = \%confhash;
8428: } else {
8429: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 8430: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 8431: $domdefaults{$key} = $confhash{$key};
8432: }
1.160.6.5 raeburn 8433: }
1.72 raeburn 8434: }
1.160.6.5 raeburn 8435:
1.1 raeburn 8436: my %quotahash = (
1.86 raeburn 8437: $action => { %confhash }
1.1 raeburn 8438: );
8439: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8440: $dom);
8441: if ($putresult eq 'ok') {
8442: if (keys(%changes) > 0) {
1.72 raeburn 8443: my $cachetime = 24*60*60;
8444: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 8445: if (ref($lastactref) eq 'HASH') {
8446: $lastactref->{'domdefaults'} = 1;
8447: }
1.1 raeburn 8448: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 8449: unless (($context eq 'requestcourses') ||
8450: ($context eq 'requestauthor')) {
1.86 raeburn 8451: if (ref($changes{'defaultquota'}) eq 'HASH') {
8452: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8453: foreach my $type (@{$types},'default') {
8454: if (defined($changes{'defaultquota'}{$type})) {
8455: my $typetitle = $usertypes->{$type};
8456: if ($type eq 'default') {
8457: $typetitle = $othertitle;
8458: }
1.160.6.28 raeburn 8459: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8460: }
8461: }
1.86 raeburn 8462: $resulttext .= '</ul></li>';
1.72 raeburn 8463: }
1.160.6.20 raeburn 8464: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 8465: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 8466: foreach my $type (@{$types},'default') {
8467: if (defined($changes{'authorquota'}{$type})) {
8468: my $typetitle = $usertypes->{$type};
8469: if ($type eq 'default') {
8470: $typetitle = $othertitle;
8471: }
1.160.6.28 raeburn 8472: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 8473: }
8474: }
8475: $resulttext .= '</ul></li>';
8476: }
1.72 raeburn 8477: }
1.80 raeburn 8478: my %newenv;
1.72 raeburn 8479: foreach my $item (@usertools) {
1.160.6.5 raeburn 8480: my (%haschgs,%inconf);
8481: if ($context eq 'requestauthor') {
8482: %haschgs = %changes;
8483: %inconf = %confhash;
8484: } else {
8485: if (ref($changes{$item}) eq 'HASH') {
8486: %haschgs = %{$changes{$item}};
8487: }
8488: if (ref($confhash{$item}) eq 'HASH') {
8489: %inconf = %{$confhash{$item}};
8490: }
8491: }
8492: if (keys(%haschgs) > 0) {
1.80 raeburn 8493: my $newacc =
8494: &Apache::lonnet::usertools_access($env{'user.name'},
8495: $env{'user.domain'},
1.86 raeburn 8496: $item,'reload',$context);
1.160.6.5 raeburn 8497: if (($context eq 'requestcourses') ||
8498: ($context eq 'requestauthor')) {
1.108 raeburn 8499: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8500: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8501: }
8502: } else {
8503: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8504: $newenv{'environment.availabletools.'.$item} = $newacc;
8505: }
1.80 raeburn 8506: }
1.160.6.5 raeburn 8507: unless ($context eq 'requestauthor') {
8508: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8509: }
1.72 raeburn 8510: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 8511: if ($haschgs{$type}) {
1.72 raeburn 8512: my $typetitle = $usertypes->{$type};
8513: if ($type eq 'default') {
8514: $typetitle = $othertitle;
8515: } elsif ($type eq '_LC_adv') {
8516: $typetitle = 'LON-CAPA Advanced Users';
8517: }
1.160.6.5 raeburn 8518: if ($inconf{$type}) {
1.101 raeburn 8519: if ($context eq 'requestcourses') {
8520: my $cond;
1.160.6.5 raeburn 8521: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8522: if ($1 eq '') {
8523: $cond = &mt('(Automatic processing of any request).');
8524: } else {
8525: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8526: }
8527: } else {
1.160.6.5 raeburn 8528: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8529: }
8530: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 8531: } elsif ($context eq 'requestauthor') {
8532: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8533: $titles{$inconf{$type}},$typetitle);
8534:
1.101 raeburn 8535: } else {
8536: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8537: }
1.72 raeburn 8538: } else {
1.104 raeburn 8539: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 8540: if ($inconf{$type} eq '0') {
1.104 raeburn 8541: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8542: } else {
8543: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8544: }
8545: } else {
8546: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8547: }
1.72 raeburn 8548: }
8549: }
1.26 raeburn 8550: }
1.160.6.5 raeburn 8551: unless ($context eq 'requestauthor') {
8552: $resulttext .= '</ul></li>';
8553: }
1.26 raeburn 8554: }
1.1 raeburn 8555: }
1.160.6.5 raeburn 8556: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8557: if (ref($changes{'notify'}) eq 'HASH') {
8558: if ($changes{'notify'}{'approval'}) {
8559: if (ref($confhash{'notify'}) eq 'HASH') {
8560: if ($confhash{'notify'}{'approval'}) {
8561: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8562: } else {
1.160.6.5 raeburn 8563: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8564: }
8565: }
8566: }
8567: }
8568: }
1.160.6.30 raeburn 8569: if ($action eq 'requestcourses') {
8570: my @offon = ('off','on');
8571: if ($changes{'uniquecode'}) {
8572: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8573: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8574: $resulttext .= '<li>'.
8575: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8576: '</li>';
8577: } else {
8578: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8579: '</li>';
8580: }
8581: }
1.160.6.46 raeburn 8582: foreach my $type ('textbooks','templates') {
8583: if (ref($changes{$type}) eq 'HASH') {
8584: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8585: foreach my $key (sort(keys(%{$changes{$type}}))) {
8586: my %coursehash = &Apache::lonnet::coursedescription($key);
8587: my $coursetitle = $coursehash{'description'};
8588: my $position = $confhash{$type}{$key}{'order'} + 1;
8589: $resulttext .= '<li>';
1.160.6.47 raeburn 8590: foreach my $item ('subject','title','publisher','author') {
8591: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8592: ($type eq 'templates'));
1.160.6.46 raeburn 8593: my $name = $item.':';
8594: $name =~ s/^(\w)/\U$1/;
8595: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8596: }
8597: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8598: if ($type eq 'textbooks') {
8599: if ($confhash{$type}{$key}{'image'}) {
8600: $resulttext .= ' '.&mt('Image: [_1]',
8601: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8602: ' alt="Textbook cover" />').'<br />';
8603: }
8604: }
8605: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 8606: }
1.160.6.46 raeburn 8607: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 8608: }
8609: }
1.160.6.39 raeburn 8610: if (ref($changes{'validation'}) eq 'HASH') {
8611: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8612: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8613: foreach my $item (@{$validationitemsref}) {
8614: if (exists($changes{'validation'}{$item})) {
8615: if ($item eq 'markup') {
8616: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8617: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8618: } else {
8619: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8620: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8621: }
8622: }
8623: }
8624: if (exists($changes{'validation'}{'dc'})) {
8625: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8626: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8627: }
8628: }
8629: }
1.160.6.30 raeburn 8630: }
1.1 raeburn 8631: $resulttext .= '</ul>';
1.80 raeburn 8632: if (keys(%newenv)) {
8633: &Apache::lonnet::appenv(\%newenv);
8634: }
1.1 raeburn 8635: } else {
1.86 raeburn 8636: if ($context eq 'requestcourses') {
8637: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 8638: } elsif ($context eq 'requestauthor') {
8639: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8640: } else {
1.90 weissno 8641: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8642: }
1.1 raeburn 8643: }
8644: } else {
1.11 albertel 8645: $resulttext = '<span class="LC_error">'.
8646: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8647: }
1.160.6.30 raeburn 8648: if ($errors) {
8649: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8650: '<ul>'.$errors.'</ul></p>';
8651: }
1.3 raeburn 8652: return $resulttext;
1.1 raeburn 8653: }
8654:
1.160.6.30 raeburn 8655: sub process_textbook_image {
1.160.6.46 raeburn 8656: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 8657: my $filename = $env{'form.'.$caller.'.filename'};
8658: my ($error,$url);
8659: my ($width,$height) = (50,50);
8660: if ($configuserok eq 'ok') {
8661: if ($switchserver) {
8662: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8663: $switchserver);
8664: } elsif ($author_ok eq 'ok') {
8665: my ($result,$imageurl) =
8666: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 8667: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 8668: if ($result eq 'ok') {
8669: $url = $imageurl;
8670: } else {
8671: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8672: }
8673: } else {
8674: $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);
8675: }
8676: } else {
8677: $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);
8678: }
8679: return ($url,$error);
8680: }
8681:
1.3 raeburn 8682: sub modify_autoenroll {
1.160.6.24 raeburn 8683: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 8684: my ($resulttext,%changes);
8685: my %currautoenroll;
8686: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
8687: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
8688: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
8689: }
8690: }
8691: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
8692: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 8693: sender => 'Sender for notification messages',
1.160.6.68 raeburn 8694: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
8695: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 8696: my @offon = ('off','on');
1.17 raeburn 8697: my $sender_uname = $env{'form.sender_uname'};
8698: my $sender_domain = $env{'form.sender_domain'};
8699: if ($sender_domain eq '') {
8700: $sender_uname = '';
8701: } elsif ($sender_uname eq '') {
8702: $sender_domain = '';
8703: }
1.129 raeburn 8704: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 8705: my $failsafe = $env{'form.autoenroll_failsafe'};
8706: $failsafe =~ s{^\s+|\s+$}{}g;
8707: if ($failsafe =~ /\D/) {
8708: undef($failsafe);
8709: }
1.1 raeburn 8710: my %autoenrollhash = (
1.129 raeburn 8711: autoenroll => { 'run' => $env{'form.autoenroll_run'},
8712: 'sender_uname' => $sender_uname,
8713: 'sender_domain' => $sender_domain,
8714: 'co-owners' => $coowners,
1.160.6.68 raeburn 8715: 'autofailsafe' => $failsafe,
1.1 raeburn 8716: }
8717: );
1.4 raeburn 8718: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
8719: $dom);
1.1 raeburn 8720: if ($putresult eq 'ok') {
8721: if (exists($currautoenroll{'run'})) {
8722: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
8723: $changes{'run'} = 1;
8724: }
8725: } elsif ($autorun) {
8726: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 8727: $changes{'run'} = 1;
1.1 raeburn 8728: }
8729: }
1.17 raeburn 8730: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 8731: $changes{'sender'} = 1;
8732: }
1.17 raeburn 8733: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 8734: $changes{'sender'} = 1;
8735: }
1.129 raeburn 8736: if ($currautoenroll{'co-owners'} ne '') {
8737: if ($currautoenroll{'co-owners'} ne $coowners) {
8738: $changes{'coowners'} = 1;
8739: }
8740: } elsif ($coowners) {
8741: $changes{'coowners'} = 1;
1.160.6.68 raeburn 8742: }
8743: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
8744: $changes{'autofailsafe'} = 1;
8745: }
1.1 raeburn 8746: if (keys(%changes) > 0) {
8747: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 8748: if ($changes{'run'}) {
1.1 raeburn 8749: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
8750: }
8751: if ($changes{'sender'}) {
1.17 raeburn 8752: if ($sender_uname eq '' || $sender_domain eq '') {
8753: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
8754: } else {
8755: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
8756: }
1.1 raeburn 8757: }
1.129 raeburn 8758: if ($changes{'coowners'}) {
8759: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
8760: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8761: if (ref($lastactref) eq 'HASH') {
8762: $lastactref->{'domainconfig'} = 1;
8763: }
1.129 raeburn 8764: }
1.160.6.68 raeburn 8765: if ($changes{'autofailsafe'}) {
8766: if ($failsafe ne '') {
1.160.6.82 raeburn 8767: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 8768: } else {
1.160.6.82 raeburn 8769: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 8770: }
8771: &Apache::lonnet::get_domain_defaults($dom,1);
8772: if (ref($lastactref) eq 'HASH') {
8773: $lastactref->{'domdefaults'} = 1;
8774: }
8775: }
1.1 raeburn 8776: $resulttext .= '</ul>';
8777: } else {
8778: $resulttext = &mt('No changes made to auto-enrollment settings');
8779: }
8780: } else {
1.11 albertel 8781: $resulttext = '<span class="LC_error">'.
8782: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8783: }
1.3 raeburn 8784: return $resulttext;
1.1 raeburn 8785: }
8786:
8787: sub modify_autoupdate {
1.3 raeburn 8788: my ($dom,%domconfig) = @_;
1.1 raeburn 8789: my ($resulttext,%currautoupdate,%fields,%changes);
8790: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
8791: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
8792: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
8793: }
8794: }
8795: my @offon = ('off','on');
8796: my %title = &Apache::lonlocal::texthash (
8797: run => 'Auto-update:',
8798: classlists => 'Updates to user information in classlists?'
8799: );
1.44 raeburn 8800: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8801: my %fieldtitles = &Apache::lonlocal::texthash (
8802: id => 'Student/Employee ID',
1.20 raeburn 8803: permanentemail => 'E-mail address',
1.1 raeburn 8804: lastname => 'Last Name',
8805: firstname => 'First Name',
8806: middlename => 'Middle Name',
1.132 raeburn 8807: generation => 'Generation',
1.1 raeburn 8808: );
1.142 raeburn 8809: $othertitle = &mt('All users');
1.1 raeburn 8810: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8811: $othertitle = &mt('Other users');
1.1 raeburn 8812: }
8813: foreach my $key (keys(%env)) {
8814: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8815: my ($usertype,$item) = ($1,$2);
8816: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8817: if ($usertype eq 'default') {
8818: push(@{$fields{$1}},$2);
8819: } elsif (ref($types) eq 'ARRAY') {
8820: if (grep(/^\Q$usertype\E$/,@{$types})) {
8821: push(@{$fields{$1}},$2);
8822: }
8823: }
8824: }
1.1 raeburn 8825: }
8826: }
1.131 raeburn 8827: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8828: @lockablenames = sort(@lockablenames);
8829: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8830: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8831: if (@changed) {
8832: $changes{'lockablenames'} = 1;
8833: }
8834: } else {
8835: if (@lockablenames) {
8836: $changes{'lockablenames'} = 1;
8837: }
8838: }
1.1 raeburn 8839: my %updatehash = (
8840: autoupdate => { run => $env{'form.autoupdate_run'},
8841: classlists => $env{'form.classlists'},
8842: fields => {%fields},
1.131 raeburn 8843: lockablenames => \@lockablenames,
1.1 raeburn 8844: }
8845: );
8846: foreach my $key (keys(%currautoupdate)) {
8847: if (($key eq 'run') || ($key eq 'classlists')) {
8848: if (exists($updatehash{autoupdate}{$key})) {
8849: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8850: $changes{$key} = 1;
8851: }
8852: }
8853: } elsif ($key eq 'fields') {
8854: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8855: foreach my $item (@{$types},'default') {
1.1 raeburn 8856: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8857: my $change = 0;
8858: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8859: if (!exists($fields{$item})) {
8860: $change = 1;
1.132 raeburn 8861: last;
1.1 raeburn 8862: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8863: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8864: $change = 1;
1.132 raeburn 8865: last;
1.1 raeburn 8866: }
8867: }
8868: }
8869: if ($change) {
8870: push(@{$changes{$key}},$item);
8871: }
1.26 raeburn 8872: }
1.1 raeburn 8873: }
8874: }
1.131 raeburn 8875: } elsif ($key eq 'lockablenames') {
8876: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8877: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8878: if (@changed) {
8879: $changes{'lockablenames'} = 1;
8880: }
8881: } else {
8882: if (@lockablenames) {
8883: $changes{'lockablenames'} = 1;
8884: }
8885: }
8886: }
8887: }
8888: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8889: if (@lockablenames) {
8890: $changes{'lockablenames'} = 1;
1.1 raeburn 8891: }
8892: }
1.26 raeburn 8893: foreach my $item (@{$types},'default') {
8894: if (defined($fields{$item})) {
8895: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8896: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8897: my $change = 0;
8898: if (ref($fields{$item}) eq 'ARRAY') {
8899: foreach my $type (@{$fields{$item}}) {
8900: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
8901: $change = 1;
8902: last;
8903: }
8904: }
8905: }
8906: if ($change) {
8907: push(@{$changes{'fields'}},$item);
8908: }
8909: } else {
1.26 raeburn 8910: push(@{$changes{'fields'}},$item);
8911: }
8912: } else {
8913: push(@{$changes{'fields'}},$item);
1.1 raeburn 8914: }
8915: }
8916: }
8917: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8918: $dom);
8919: if ($putresult eq 'ok') {
8920: if (keys(%changes) > 0) {
8921: $resulttext = &mt('Changes made:').'<ul>';
8922: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 8923: if ($key eq 'lockablenames') {
8924: $resulttext .= '<li>';
8925: if (@lockablenames) {
8926: $usertypes->{'default'} = $othertitle;
8927: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8928: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8929: } else {
8930: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8931: }
8932: $resulttext .= '</li>';
8933: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8934: foreach my $item (@{$changes{$key}}) {
8935: my @newvalues;
8936: foreach my $type (@{$fields{$item}}) {
8937: push(@newvalues,$fieldtitles{$type});
8938: }
1.3 raeburn 8939: my $newvaluestr;
8940: if (@newvalues > 0) {
8941: $newvaluestr = join(', ',@newvalues);
8942: } else {
8943: $newvaluestr = &mt('none');
1.6 raeburn 8944: }
1.1 raeburn 8945: if ($item eq 'default') {
1.26 raeburn 8946: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8947: } else {
1.26 raeburn 8948: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8949: }
8950: }
8951: } else {
8952: my $newvalue;
8953: if ($key eq 'run') {
8954: $newvalue = $offon[$env{'form.autoupdate_run'}];
8955: } else {
8956: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8957: }
1.1 raeburn 8958: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8959: }
8960: }
8961: $resulttext .= '</ul>';
8962: } else {
1.3 raeburn 8963: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8964: }
8965: } else {
1.11 albertel 8966: $resulttext = '<span class="LC_error">'.
8967: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8968: }
1.3 raeburn 8969: return $resulttext;
1.1 raeburn 8970: }
8971:
1.125 raeburn 8972: sub modify_autocreate {
8973: my ($dom,%domconfig) = @_;
8974: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8975: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8976: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8977: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8978: }
8979: }
8980: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8981: req => 'Auto-creation of validated requests for official courses',
8982: xmldc => 'Identity of course creator of courses from XML files',
8983: );
8984: my @types = ('xml','req');
8985: foreach my $item (@types) {
8986: $newvals{$item} = $env{'form.autocreate_'.$item};
8987: $newvals{$item} =~ s/\D//g;
8988: $newvals{$item} = 0 if ($newvals{$item} eq '');
8989: }
8990: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 8991: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 8992: unless (exists($domcoords{$newvals{'xmldc'}})) {
8993: $newvals{'xmldc'} = '';
8994: }
8995: %autocreatehash = (
8996: autocreate => { xml => $newvals{'xml'},
8997: req => $newvals{'req'},
8998: }
8999: );
9000: if ($newvals{'xmldc'} ne '') {
9001: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9002: }
9003: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9004: $dom);
9005: if ($putresult eq 'ok') {
9006: my @items = @types;
9007: if ($newvals{'xml'}) {
9008: push(@items,'xmldc');
9009: }
9010: foreach my $item (@items) {
9011: if (exists($currautocreate{$item})) {
9012: if ($currautocreate{$item} ne $newvals{$item}) {
9013: $changes{$item} = 1;
9014: }
9015: } elsif ($newvals{$item}) {
9016: $changes{$item} = 1;
9017: }
9018: }
9019: if (keys(%changes) > 0) {
9020: my @offon = ('off','on');
9021: $resulttext = &mt('Changes made:').'<ul>';
9022: foreach my $item (@types) {
9023: if ($changes{$item}) {
9024: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 9025: $resulttext .= '<li>'.
9026: &mt("$title{$item} set to [_1]$newtxt [_2]",
9027: '<b>','</b>').
9028: '</li>';
1.125 raeburn 9029: }
9030: }
9031: if ($changes{'xmldc'}) {
9032: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9033: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 9034: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9035: }
9036: $resulttext .= '</ul>';
9037: } else {
9038: $resulttext = &mt('No changes made to auto-creation settings');
9039: }
9040: } else {
9041: $resulttext = '<span class="LC_error">'.
9042: &mt('An error occurred: [_1]',$putresult).'</span>';
9043: }
9044: return $resulttext;
9045: }
9046:
1.23 raeburn 9047: sub modify_directorysrch {
1.160.6.81 raeburn 9048: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 9049: my ($resulttext,%changes);
9050: my %currdirsrch;
9051: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9052: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9053: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9054: }
9055: }
1.160.6.72 raeburn 9056: my %title = ( available => 'Institutional directory search available',
9057: localonly => 'Other domains can search institution',
9058: lcavailable => 'LON-CAPA directory search available',
9059: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9060: searchby => 'Search types',
9061: searchtypes => 'Search latitude');
9062: my @offon = ('off','on');
1.24 raeburn 9063: my @otherdoms = ('Yes','No');
1.23 raeburn 9064:
1.25 raeburn 9065: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9066: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9067: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9068:
1.44 raeburn 9069: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9070: if (keys(%{$usertypes}) == 0) {
9071: @cansearch = ('default');
9072: } else {
9073: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9074: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9075: if (!grep(/^\Q$type\E$/,@cansearch)) {
9076: push(@{$changes{'cansearch'}},$type);
9077: }
1.23 raeburn 9078: }
1.26 raeburn 9079: foreach my $type (@cansearch) {
9080: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9081: push(@{$changes{'cansearch'}},$type);
9082: }
1.23 raeburn 9083: }
1.26 raeburn 9084: } else {
9085: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9086: }
9087: }
9088:
9089: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9090: foreach my $by (@{$currdirsrch{'searchby'}}) {
9091: if (!grep(/^\Q$by\E$/,@searchby)) {
9092: push(@{$changes{'searchby'}},$by);
9093: }
9094: }
9095: foreach my $by (@searchby) {
9096: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9097: push(@{$changes{'searchby'}},$by);
9098: }
9099: }
9100: } else {
9101: push(@{$changes{'searchby'}},@searchby);
9102: }
1.25 raeburn 9103:
9104: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9105: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9106: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9107: push(@{$changes{'searchtypes'}},$type);
9108: }
9109: }
9110: foreach my $type (@searchtypes) {
9111: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9112: push(@{$changes{'searchtypes'}},$type);
9113: }
9114: }
9115: } else {
9116: if (exists($currdirsrch{'searchtypes'})) {
9117: foreach my $type (@searchtypes) {
9118: if ($type ne $currdirsrch{'searchtypes'}) {
9119: push(@{$changes{'searchtypes'}},$type);
9120: }
9121: }
9122: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9123: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9124: }
9125: } else {
9126: push(@{$changes{'searchtypes'}},@searchtypes);
9127: }
9128: }
9129:
1.23 raeburn 9130: my %dirsrch_hash = (
9131: directorysrch => { available => $env{'form.dirsrch_available'},
9132: cansearch => \@cansearch,
1.160.6.72 raeburn 9133: localonly => $env{'form.dirsrch_instlocalonly'},
9134: lclocalonly => $env{'form.dirsrch_domlocalonly'},
9135: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9136: searchby => \@searchby,
1.25 raeburn 9137: searchtypes => \@searchtypes,
1.23 raeburn 9138: }
9139: );
9140: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9141: $dom);
9142: if ($putresult eq 'ok') {
9143: if (exists($currdirsrch{'available'})) {
9144: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9145: $changes{'available'} = 1;
9146: }
9147: } else {
9148: if ($env{'form.dirsrch_available'} eq '1') {
9149: $changes{'available'} = 1;
9150: }
9151: }
1.160.6.72 raeburn 9152: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 9153: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
9154: $changes{'lcavailable'} = 1;
9155: }
1.24 raeburn 9156: } else {
1.160.6.72 raeburn 9157: if ($env{'form.dirsrch_lcavailable'} eq '1') {
9158: $changes{'lcavailable'} = 1;
9159: }
9160: }
9161: if (exists($currdirsrch{'localonly'})) {
9162: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9163: $changes{'localonly'} = 1;
9164: }
1.160.6.72 raeburn 9165: } else {
9166: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
9167: $changes{'localonly'} = 1;
9168: }
9169: }
9170: if (exists($currdirsrch{'lclocalonly'})) {
9171: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
9172: $changes{'lclocalonly'} = 1;
9173: }
9174: } else {
9175: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
9176: $changes{'lclocalonly'} = 1;
9177: }
1.24 raeburn 9178: }
1.23 raeburn 9179: if (keys(%changes) > 0) {
9180: $resulttext = &mt('Changes made:').'<ul>';
9181: if ($changes{'available'}) {
9182: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9183: }
1.160.6.72 raeburn 9184: if ($changes{'lcavailable'}) {
9185: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
9186: }
1.24 raeburn 9187: if ($changes{'localonly'}) {
1.160.6.72 raeburn 9188: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
9189: }
9190: if ($changes{'lclocalonly'}) {
9191: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 9192: }
1.23 raeburn 9193: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9194: my $chgtext;
1.26 raeburn 9195: if (ref($usertypes) eq 'HASH') {
9196: if (keys(%{$usertypes}) > 0) {
9197: foreach my $type (@{$types}) {
9198: if (grep(/^\Q$type\E$/,@cansearch)) {
9199: $chgtext .= $usertypes->{$type}.'; ';
9200: }
9201: }
9202: if (grep(/^default$/,@cansearch)) {
9203: $chgtext .= $othertitle;
9204: } else {
9205: $chgtext =~ s/\; $//;
9206: }
1.160.6.13 raeburn 9207: $resulttext .=
9208: '<li>'.
9209: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9210: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9211: '</li>';
1.23 raeburn 9212: }
9213: }
9214: }
9215: if (ref($changes{'searchby'}) eq 'ARRAY') {
9216: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9217: my $chgtext;
9218: foreach my $type (@{$titleorder}) {
9219: if (grep(/^\Q$type\E$/,@searchby)) {
9220: if (defined($searchtitles->{$type})) {
9221: $chgtext .= $searchtitles->{$type}.'; ';
9222: }
9223: }
9224: }
9225: $chgtext =~ s/\; $//;
9226: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9227: }
1.25 raeburn 9228: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9229: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9230: my $chgtext;
9231: foreach my $type (@{$srchtypeorder}) {
9232: if (grep(/^\Q$type\E$/,@searchtypes)) {
9233: if (defined($srchtypes_desc->{$type})) {
9234: $chgtext .= $srchtypes_desc->{$type}.'; ';
9235: }
9236: }
9237: }
9238: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 9239: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9240: }
9241: $resulttext .= '</ul>';
1.160.6.81 raeburn 9242: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
9243: if (ref($lastactref) eq 'HASH') {
9244: $lastactref->{'directorysrch'} = 1;
9245: }
1.23 raeburn 9246: } else {
1.160.6.72 raeburn 9247: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9248: }
9249: } else {
9250: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9251: &mt('An error occurred: [_1]',$putresult).'</span>';
9252: }
9253: return $resulttext;
9254: }
9255:
1.28 raeburn 9256: sub modify_contacts {
1.160.6.24 raeburn 9257: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9258: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9259: if (ref($domconfig{'contacts'}) eq 'HASH') {
9260: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9261: $currsetting{$key} = $domconfig{'contacts'}{$key};
9262: }
9263: }
1.160.6.78 raeburn 9264: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 9265: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 9266: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
9267: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.160.6.23 raeburn 9268: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 9269: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 9270: foreach my $type (@mailings) {
9271: @{$newsetting{$type}} =
9272: &Apache::loncommon::get_env_multiple('form.'.$type);
9273: foreach my $item (@contacts) {
9274: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9275: $contacts_hash{contacts}{$type}{$item} = 1;
9276: } else {
9277: $contacts_hash{contacts}{$type}{$item} = 0;
9278: }
1.160.6.78 raeburn 9279: }
1.28 raeburn 9280: $others{$type} = $env{'form.'.$type.'_others'};
9281: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 9282: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9283: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9284: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 9285: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
9286: $includestr{$type} = $env{'form.'.$type.'_includestr'};
9287: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
9288: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
9289: }
1.134 raeburn 9290: }
1.28 raeburn 9291: }
9292: foreach my $item (@contacts) {
9293: $to{$item} = $env{'form.'.$item};
9294: $contacts_hash{'contacts'}{$item} = $to{$item};
9295: }
1.160.6.23 raeburn 9296: foreach my $item (@toggles) {
9297: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9298: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9299: }
9300: }
1.160.6.78 raeburn 9301: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
9302: foreach my $field (@{$fields}) {
9303: if (ref($possoptions->{$field}) eq 'ARRAY') {
9304: my $value = $env{'form.helpform_'.$field};
9305: $value =~ s/^\s+|\s+$//g;
9306: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
9307: $contacts_hash{contacts}{'helpform'}{$field} = $value;
9308: if ($field eq 'screenshot') {
9309: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
9310: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
9311: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
9312: }
9313: }
9314: }
9315: }
9316: }
9317: }
1.28 raeburn 9318: if (keys(%currsetting) > 0) {
9319: foreach my $item (@contacts) {
9320: if ($to{$item} ne $currsetting{$item}) {
9321: $changes{$item} = 1;
9322: }
9323: }
9324: foreach my $type (@mailings) {
9325: foreach my $item (@contacts) {
9326: if (ref($currsetting{$type}) eq 'HASH') {
9327: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9328: push(@{$changes{$type}},$item);
9329: }
9330: } else {
9331: push(@{$changes{$type}},@{$newsetting{$type}});
9332: }
9333: }
9334: if ($others{$type} ne $currsetting{$type}{'others'}) {
9335: push(@{$changes{$type}},'others');
9336: }
1.160.6.78 raeburn 9337: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9338: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9339: push(@{$changes{$type}},'bcc');
9340: }
1.160.6.78 raeburn 9341: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
9342: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
9343: push(@{$changes{$type}},'include');
9344: }
9345: }
9346: }
9347: if (ref($fields) eq 'ARRAY') {
9348: if (ref($currsetting{'helpform'}) eq 'HASH') {
9349: foreach my $field (@{$fields}) {
9350: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
9351: push(@{$changes{'helpform'}},$field);
9352: }
9353: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9354: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
9355: push(@{$changes{'helpform'}},'maxsize');
9356: }
9357: }
9358: }
9359: } else {
9360: foreach my $field (@{$fields}) {
9361: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9362: push(@{$changes{'helpform'}},$field);
9363: }
9364: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9365: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9366: push(@{$changes{'helpform'}},'maxsize');
9367: }
9368: }
9369: }
1.134 raeburn 9370: }
1.28 raeburn 9371: }
9372: } else {
9373: my %default;
9374: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9375: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9376: $default{'errormail'} = 'adminemail';
9377: $default{'packagesmail'} = 'adminemail';
9378: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 9379: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 9380: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9381: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 9382: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9383: foreach my $item (@contacts) {
9384: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 9385: $changes{$item} = 1;
1.160.6.23 raeburn 9386: }
1.28 raeburn 9387: }
9388: foreach my $type (@mailings) {
9389: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9390: push(@{$changes{$type}},@{$newsetting{$type}});
9391: }
9392: if ($others{$type} ne '') {
9393: push(@{$changes{$type}},'others');
1.134 raeburn 9394: }
1.160.6.78 raeburn 9395: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9396: if ($bcc{$type} ne '') {
9397: push(@{$changes{$type}},'bcc');
9398: }
1.160.6.78 raeburn 9399: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
9400: push(@{$changes{$type}},'include');
9401: }
9402: }
9403: }
9404: if (ref($fields) eq 'ARRAY') {
9405: foreach my $field (@{$fields}) {
9406: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9407: push(@{$changes{'helpform'}},$field);
9408: }
9409: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9410: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9411: push(@{$changes{'helpform'}},'maxsize');
9412: }
9413: }
1.134 raeburn 9414: }
1.28 raeburn 9415: }
9416: }
1.160.6.23 raeburn 9417: foreach my $item (@toggles) {
9418: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9419: $changes{$item} = 1;
9420: } elsif ((!$env{'form.'.$item}) &&
9421: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9422: $changes{$item} = 1;
9423: }
9424: }
1.28 raeburn 9425: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9426: $dom);
9427: if ($putresult eq 'ok') {
9428: if (keys(%changes) > 0) {
1.160.6.24 raeburn 9429: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9430: if (ref($lastactref) eq 'HASH') {
9431: $lastactref->{'domainconfig'} = 1;
9432: }
1.28 raeburn 9433: my ($titles,$short_titles) = &contact_titles();
9434: $resulttext = &mt('Changes made:').'<ul>';
9435: foreach my $item (@contacts) {
9436: if ($changes{$item}) {
9437: $resulttext .= '<li>'.$titles->{$item}.
9438: &mt(' set to: ').
9439: '<span class="LC_cusr_emph">'.
9440: $to{$item}.'</span></li>';
9441: }
9442: }
9443: foreach my $type (@mailings) {
9444: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 9445: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
9446: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
9447: } else {
9448: $resulttext .= '<li>'.$titles->{$type}.': ';
9449: }
1.28 raeburn 9450: my @text;
9451: foreach my $item (@{$newsetting{$type}}) {
9452: push(@text,$short_titles->{$item});
9453: }
9454: if ($others{$type} ne '') {
9455: push(@text,$others{$type});
9456: }
1.160.6.78 raeburn 9457: if (@text) {
9458: $resulttext .= '<span class="LC_cusr_emph">'.
9459: join(', ',@text).'</span>';
9460: }
9461: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9462: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 9463: my $bcctext;
9464: if (@text) {
9465: $bcctext = ' '.&mt('with Bcc to');
9466: } else {
9467: $bcctext = '(Bcc)';
9468: }
9469: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9470: } elsif (!@text) {
9471: $resulttext .= &mt('No one');
1.134 raeburn 9472: }
1.160.6.78 raeburn 9473: if ($includestr{$type} ne '') {
9474: if ($includeloc{$type} eq 'b') {
9475: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
9476: } elsif ($includeloc{$type} eq 's') {
9477: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
9478: }
9479: }
9480: } elsif (!@text) {
9481: $resulttext .= &mt('No recipients');
1.134 raeburn 9482: }
9483: $resulttext .= '</li>';
1.28 raeburn 9484: }
9485: }
1.160.6.23 raeburn 9486: my @offon = ('off','on');
9487: if ($changes{'reporterrors'}) {
9488: $resulttext .= '<li>'.
9489: &mt('E-mail error reports to [_1] set to "'.
9490: $offon[$env{'form.reporterrors'}].'".',
9491: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9492: &mt('LON-CAPA core group - MSU'),600,500)).
9493: '</li>';
9494: }
9495: if ($changes{'reportupdates'}) {
9496: $resulttext .= '<li>'.
9497: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9498: $offon[$env{'form.reportupdates'}].'".',
9499: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9500: &mt('LON-CAPA core group - MSU'),600,500)).
9501: '</li>';
9502: }
1.160.6.78 raeburn 9503: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
9504: my (@optional,@required,@unused,$maxsizechg);
9505: foreach my $field (@{$changes{'helpform'}}) {
9506: if ($field eq 'maxsize') {
9507: $maxsizechg = 1;
9508: next;
9509: }
9510: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
9511: push(@optional,$field);
9512: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
9513: push(@unused,$field);
9514: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
9515: push(@required,$field);
9516: }
9517: }
9518: if (@optional) {
9519: $resulttext .= '<li>'.
9520: &mt('Help form fields changed to "Optional": [_1].',
9521: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
9522: '</li>';
9523: }
9524: if (@required) {
9525: $resulttext .= '<li>'.
9526: &mt('Help form fields changed to "Required": [_1].',
9527: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
9528: '</li>';
9529: }
9530: if (@unused) {
9531: $resulttext .= '<li>'.
9532: &mt('Help form fields changed to "Not shown": [_1].',
9533: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
9534: '</li>';
9535: }
9536: if ($maxsizechg) {
9537: $resulttext .= '<li>'.
9538: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
9539: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
9540: '</li>';
9541:
9542: }
9543: }
1.28 raeburn 9544: $resulttext .= '</ul>';
9545: } else {
1.160.6.78 raeburn 9546: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 9547: }
9548: } else {
9549: $resulttext = '<span class="LC_error">'.
9550: &mt('An error occurred: [_1].',$putresult).'</span>';
9551: }
9552: return $resulttext;
9553: }
9554:
9555: sub modify_usercreation {
1.27 raeburn 9556: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9557: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9558: my $warningmsg;
1.27 raeburn 9559: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9560: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 9561: if ($key eq 'cancreate') {
9562: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9563: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9564: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 9565: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9566: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 9567: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9568: } else {
9569: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9570: }
1.50 raeburn 9571: }
1.43 raeburn 9572: }
1.160.6.34 raeburn 9573: } elsif ($key eq 'email_rule') {
9574: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9575: } else {
9576: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 9577: }
9578: }
1.34 raeburn 9579: }
1.160.6.34 raeburn 9580: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
9581: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
9582: my @contexts = ('author','course','requestcrs');
9583: foreach my $item(@contexts) {
9584: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9585: }
1.34 raeburn 9586: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9587: foreach my $item (@contexts) {
1.160.6.34 raeburn 9588: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9589: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9590: }
1.27 raeburn 9591: }
1.34 raeburn 9592: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9593: foreach my $item (@contexts) {
1.43 raeburn 9594: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9595: if ($cancreate{$item} ne 'any') {
9596: push(@{$changes{'cancreate'}},$item);
9597: }
9598: } else {
9599: if ($cancreate{$item} ne 'none') {
9600: push(@{$changes{'cancreate'}},$item);
9601: }
1.27 raeburn 9602: }
9603: }
9604: } else {
1.43 raeburn 9605: foreach my $item (@contexts) {
1.34 raeburn 9606: push(@{$changes{'cancreate'}},$item);
9607: }
1.27 raeburn 9608: }
1.34 raeburn 9609:
1.27 raeburn 9610: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9611: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9612: if (!grep(/^\Q$type\E$/,@username_rule)) {
9613: push(@{$changes{'username_rule'}},$type);
9614: }
9615: }
9616: foreach my $type (@username_rule) {
9617: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9618: push(@{$changes{'username_rule'}},$type);
9619: }
9620: }
9621: } else {
9622: push(@{$changes{'username_rule'}},@username_rule);
9623: }
9624:
1.32 raeburn 9625: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9626: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9627: if (!grep(/^\Q$type\E$/,@id_rule)) {
9628: push(@{$changes{'id_rule'}},$type);
9629: }
9630: }
9631: foreach my $type (@id_rule) {
9632: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9633: push(@{$changes{'id_rule'}},$type);
9634: }
9635: }
9636: } else {
9637: push(@{$changes{'id_rule'}},@id_rule);
9638: }
9639:
1.43 raeburn 9640: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9641: my @authtypes = ('int','krb4','krb5','loc');
9642: my %authhash;
1.43 raeburn 9643: foreach my $item (@authen_contexts) {
1.28 raeburn 9644: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9645: foreach my $auth (@authtypes) {
9646: if (grep(/^\Q$auth\E$/,@authallowed)) {
9647: $authhash{$item}{$auth} = 1;
9648: } else {
9649: $authhash{$item}{$auth} = 0;
9650: }
9651: }
9652: }
9653: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9654: foreach my $item (@authen_contexts) {
1.28 raeburn 9655: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
9656: foreach my $auth (@authtypes) {
9657: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
9658: push(@{$changes{'authtypes'}},$item);
9659: last;
9660: }
9661: }
9662: }
9663: }
9664: } else {
1.43 raeburn 9665: foreach my $item (@authen_contexts) {
1.28 raeburn 9666: push(@{$changes{'authtypes'}},$item);
9667: }
9668: }
9669:
1.160.6.34 raeburn 9670: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
9671: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
9672: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
9673: $save_usercreate{'id_rule'} = \@id_rule;
9674: $save_usercreate{'username_rule'} = \@username_rule,
9675: $save_usercreate{'authtypes'} = \%authhash;
9676:
1.27 raeburn 9677: my %usercreation_hash = (
1.160.6.34 raeburn 9678: usercreation => \%save_usercreate,
9679: );
1.27 raeburn 9680:
9681: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
9682: $dom);
1.50 raeburn 9683:
1.160.6.34 raeburn 9684: if ($putresult eq 'ok') {
9685: if (keys(%changes) > 0) {
9686: $resulttext = &mt('Changes made:').'<ul>';
9687: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9688: my %lt = &usercreation_types();
9689: foreach my $type (@{$changes{'cancreate'}}) {
9690: my $chgtext = $lt{$type}.', ';
9691: if ($cancreate{$type} eq 'none') {
9692: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
9693: } elsif ($cancreate{$type} eq 'any') {
9694: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
9695: } elsif ($cancreate{$type} eq 'official') {
9696: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
9697: } elsif ($cancreate{$type} eq 'unofficial') {
9698: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
9699: }
9700: $resulttext .= '<li>'.$chgtext.'</li>';
9701: }
9702: }
9703: if (ref($changes{'username_rule'}) eq 'ARRAY') {
9704: my ($rules,$ruleorder) =
9705: &Apache::lonnet::inst_userrules($dom,'username');
9706: my $chgtext = '<ul>';
9707: foreach my $type (@username_rule) {
9708: if (ref($rules->{$type}) eq 'HASH') {
9709: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
9710: }
9711: }
9712: $chgtext .= '</ul>';
9713: if (@username_rule > 0) {
9714: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9715: } else {
9716: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
9717: }
9718: }
9719: if (ref($changes{'id_rule'}) eq 'ARRAY') {
9720: my ($idrules,$idruleorder) =
9721: &Apache::lonnet::inst_userrules($dom,'id');
9722: my $chgtext = '<ul>';
9723: foreach my $type (@id_rule) {
9724: if (ref($idrules->{$type}) eq 'HASH') {
9725: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
9726: }
9727: }
9728: $chgtext .= '</ul>';
9729: if (@id_rule > 0) {
9730: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9731: } else {
9732: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
9733: }
9734: }
9735: my %authname = &authtype_names();
9736: my %context_title = &context_names();
9737: if (ref($changes{'authtypes'}) eq 'ARRAY') {
9738: my $chgtext = '<ul>';
9739: foreach my $type (@{$changes{'authtypes'}}) {
9740: my @allowed;
9741: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
9742: foreach my $auth (@authtypes) {
9743: if ($authhash{$type}{$auth}) {
9744: push(@allowed,$authname{$auth});
9745: }
9746: }
9747: if (@allowed > 0) {
9748: $chgtext .= join(', ',@allowed).'</li>';
9749: } else {
9750: $chgtext .= &mt('none').'</li>';
9751: }
9752: }
9753: $chgtext .= '</ul>';
9754: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
9755: $resulttext .= '</li>';
9756: }
9757: $resulttext .= '</ul>';
9758: } else {
9759: $resulttext = &mt('No changes made to user creation settings');
9760: }
9761: } else {
9762: $resulttext = '<span class="LC_error">'.
9763: &mt('An error occurred: [_1]',$putresult).'</span>';
9764: }
9765: if ($warningmsg ne '') {
9766: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9767: }
9768: return $resulttext;
9769: }
9770:
9771: sub modify_selfcreation {
9772: my ($dom,%domconfig) = @_;
9773: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
9774: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 9775: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9776: if (ref($types) eq 'ARRAY') {
9777: $usertypes->{'default'} = $othertitle;
9778: push(@{$types},'default');
9779: }
1.160.6.34 raeburn 9780: #
9781: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
9782: #
9783: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9784: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9785: if ($key eq 'cancreate') {
9786: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9787: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9788: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9789: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 9790: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 9791: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 9792: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 9793: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9794: } else {
9795: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9796: }
9797: }
9798: }
9799: } elsif ($key eq 'email_rule') {
9800: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9801: } else {
9802: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9803: }
9804: }
9805: }
9806: #
9807: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
9808: #
9809: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9810: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9811: if ($key eq 'selfcreate') {
9812: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
9813: } else {
9814: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
9815: }
9816: }
9817: }
9818:
9819: my @contexts = ('selfcreate');
9820: @{$cancreate{'selfcreate'}} = ();
9821: %{$cancreate{'emailusername'}} = ();
9822: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 9823: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 9824: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 9825: my %selfcreatetypes = (
9826: sso => 'users authenticated by institutional single sign on',
9827: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 9828: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 9829: );
1.160.6.34 raeburn 9830: #
9831: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
9832: # is permitted.
9833: #
1.160.6.40 raeburn 9834:
9835: my @statuses;
9836: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9837: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
9838: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
9839: }
9840: }
9841: push(@statuses,'default');
9842:
1.160.6.35 raeburn 9843: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 9844: if ($item eq 'email') {
1.160.6.40 raeburn 9845: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 9846: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 9847: push(@contexts,'selfcreateprocessing');
9848: foreach my $type (@statuses) {
9849: if ($type eq 'default') {
9850: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
9851: } else {
9852: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
9853: }
9854: }
1.160.6.34 raeburn 9855: }
9856: } else {
9857: if ($env{'form.cancreate_'.$item}) {
9858: push(@{$cancreate{'selfcreate'}},$item);
9859: }
9860: }
9861: }
9862: my (@email_rule,%userinfo,%savecaptcha);
9863: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9864: #
1.160.6.35 raeburn 9865: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9866: # 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 9867: #
1.160.6.40 raeburn 9868:
1.160.6.48 raeburn 9869: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 9870: push(@contexts,'emailusername');
1.160.6.35 raeburn 9871: if (ref($types) eq 'ARRAY') {
9872: foreach my $type (@{$types}) {
9873: if (ref($infofields) eq 'ARRAY') {
9874: foreach my $field (@{$infofields}) {
9875: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9876: $cancreate{'emailusername'}{$type}{$field} = $1;
9877: }
9878: }
1.160.6.34 raeburn 9879: }
9880: }
9881: }
9882: #
9883: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9884: # queued requests for self-creation of account using e-mail address as username
9885: #
9886:
9887: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9888: @approvalnotify = sort(@approvalnotify);
9889: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9890: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9891: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9892: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9893: push(@{$changes{'cancreate'}},'notify');
9894: }
9895: } else {
9896: if ($cancreate{'notify'}{'approval'}) {
9897: push(@{$changes{'cancreate'}},'notify');
9898: }
9899: }
9900: } elsif ($cancreate{'notify'}{'approval'}) {
9901: push(@{$changes{'cancreate'}},'notify');
9902: }
9903:
9904: #
9905: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9906: #
9907: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9908: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9909: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9910: if (@{$curr_usercreation{'email_rule'}} > 0) {
9911: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9912: if (!grep(/^\Q$type\E$/,@email_rule)) {
9913: push(@{$changes{'email_rule'}},$type);
9914: }
9915: }
9916: }
9917: if (@email_rule > 0) {
9918: foreach my $type (@email_rule) {
9919: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9920: push(@{$changes{'email_rule'}},$type);
9921: }
9922: }
9923: }
9924: } elsif (@email_rule > 0) {
9925: push(@{$changes{'email_rule'}},@email_rule);
9926: }
9927: }
9928: #
1.160.6.40 raeburn 9929: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 9930: # institutional log-in.
9931: #
9932: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9933: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9934: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
9935: ($domdefaults{'auth_def'} eq 'localauth'))) {
9936: $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.').' '.
9937: &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.');
9938: }
9939: }
9940: my @fields = ('lastname','firstname','middlename','generation',
9941: 'permanentemail','id');
1.160.6.44 raeburn 9942: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 9943: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9944: #
9945: # Where usernames may created for institutional log-in and/or institutional single sign on:
9946: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9947: # may self-create accounts
9948: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
9949: # which the user may supply, if institutional data is unavailable.
9950: #
9951: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
9952: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 9953: if (@{$types} > 1) {
1.160.6.34 raeburn 9954: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
9955: push(@contexts,'statustocreate');
9956: } else {
9957: undef($cancreate{'statustocreate'});
9958: }
9959: foreach my $type (@{$types}) {
9960: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
9961: foreach my $field (@fields) {
9962: if (grep(/^\Q$field\E$/,@modifiable)) {
9963: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9964: } else {
9965: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9966: }
9967: }
9968: }
9969: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9970: foreach my $type (@{$types}) {
9971: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9972: foreach my $field (@fields) {
9973: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9974: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9975: push(@{$changes{'selfcreate'}},$type);
9976: last;
9977: }
9978: }
9979: }
9980: }
9981: } else {
9982: foreach my $type (@{$types}) {
9983: push(@{$changes{'selfcreate'}},$type);
9984: }
9985: }
9986: }
1.160.6.44 raeburn 9987: foreach my $field (@shibfields) {
9988: if ($env{'form.shibenv_'.$field} ne '') {
9989: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
9990: }
9991: }
9992: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9993: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
9994: foreach my $field (@shibfields) {
9995: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
9996: push(@{$changes{'cancreate'}},'shibenv');
9997: }
9998: }
9999: } else {
10000: foreach my $field (@shibfields) {
10001: if ($env{'form.shibenv_'.$field}) {
10002: push(@{$changes{'cancreate'}},'shibenv');
10003: last;
10004: }
10005: }
10006: }
10007: }
1.160.6.34 raeburn 10008: }
10009: foreach my $item (@contexts) {
10010: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10011: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10012: if (ref($cancreate{$item}) eq 'ARRAY') {
10013: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10014: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10015: push(@{$changes{'cancreate'}},$item);
10016: }
10017: }
10018: }
10019: }
10020: if (ref($cancreate{$item}) eq 'ARRAY') {
10021: foreach my $type (@{$cancreate{$item}}) {
10022: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10023: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10024: push(@{$changes{'cancreate'}},$item);
10025: }
10026: }
10027: }
10028: }
10029: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10030: if (ref($cancreate{$item}) eq 'HASH') {
10031: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 10032: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10033: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10034: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10035: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10036: push(@{$changes{'cancreate'}},$item);
10037: }
10038: }
10039: }
1.160.6.40 raeburn 10040: } elsif ($item eq 'selfcreateprocessing') {
10041: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10042: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10043: push(@{$changes{'cancreate'}},$item);
10044: }
10045: }
1.160.6.35 raeburn 10046: } else {
10047: if (!$cancreate{$item}{$curr}) {
10048: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10049: push(@{$changes{'cancreate'}},$item);
10050: }
1.160.6.34 raeburn 10051: }
10052: }
10053: }
10054: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 10055: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10056: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10057: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10058: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10059: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10060: push(@{$changes{'cancreate'}},$item);
10061: }
10062: }
10063: } else {
10064: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10065: push(@{$changes{'cancreate'}},$item);
10066: }
10067: }
10068: }
1.160.6.40 raeburn 10069: } elsif ($item eq 'selfcreateprocessing') {
10070: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10071: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10072: push(@{$changes{'cancreate'}},$item);
10073: }
10074: }
1.160.6.35 raeburn 10075: } else {
10076: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10077: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10078: push(@{$changes{'cancreate'}},$item);
10079: }
1.160.6.34 raeburn 10080: }
10081: }
10082: }
10083: }
10084: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10085: if (ref($cancreate{$item}) eq 'ARRAY') {
10086: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10087: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10088: push(@{$changes{'cancreate'}},$item);
10089: }
10090: }
10091: } elsif (ref($cancreate{$item}) eq 'HASH') {
10092: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10093: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10094: push(@{$changes{'cancreate'}},$item);
10095: }
10096: }
10097: }
10098: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 10099: if (ref($cancreate{$item}) eq 'HASH') {
10100: foreach my $type (keys(%{$cancreate{$item}})) {
10101: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10102: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10103: if ($cancreate{$item}{$type}{$field}) {
10104: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10105: push(@{$changes{'cancreate'}},$item);
10106: }
10107: last;
10108: }
10109: }
10110: }
10111: }
1.160.6.34 raeburn 10112: }
10113: }
10114: }
10115: #
10116: # Populate %save_usercreate hash with updates to self-creation configuration.
10117: #
10118: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10119: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 10120: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 10121: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10122: if (ref($cancreate{'notify'}) eq 'HASH') {
10123: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10124: }
1.160.6.40 raeburn 10125: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10126: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10127: }
1.160.6.34 raeburn 10128: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10129: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10130: }
1.160.6.44 raeburn 10131: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10132: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10133: }
1.160.6.34 raeburn 10134: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.85 raeburn 10135: $save_usercreate{'email_rule'} = \@email_rule;
1.160.6.34 raeburn 10136:
10137: my %userconfig_hash = (
10138: usercreation => \%save_usercreate,
10139: usermodification => \%save_usermodify,
10140: );
10141: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10142: $dom);
10143: #
10144: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10145: #
1.27 raeburn 10146: if ($putresult eq 'ok') {
10147: if (keys(%changes) > 0) {
10148: $resulttext = &mt('Changes made:').'<ul>';
10149: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 10150: my %lt = &selfcreation_types();
1.34 raeburn 10151: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10152: my $chgtext;
1.45 raeburn 10153: if ($type eq 'selfcreate') {
1.50 raeburn 10154: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 10155: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10156: } else {
1.160.6.34 raeburn 10157: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10158: '<ul>';
1.50 raeburn 10159: foreach my $case (@{$cancreate{$type}}) {
10160: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10161: }
10162: $chgtext .= '</ul>';
1.100 raeburn 10163: if (ref($cancreate{$type}) eq 'ARRAY') {
10164: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10165: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10166: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 10167: $chgtext .= '<br />'.
10168: '<span class="LC_warning">'.
10169: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10170: '</span>';
1.100 raeburn 10171: }
10172: }
10173: }
10174: }
1.43 raeburn 10175: }
1.160.6.44 raeburn 10176: } elsif ($type eq 'shibenv') {
10177: if (keys(%{$cancreate{$type}}) == 0) {
10178: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10179: } else {
10180: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10181: '<ul>';
10182: foreach my $field (@shibfields) {
10183: next if ($cancreate{$type}{$field} eq '');
10184: if ($field eq 'inststatus') {
10185: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10186: } else {
10187: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10188: }
10189: }
10190: $chgtext .= '</ul>';
10191: }
1.93 raeburn 10192: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10193: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10194: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10195: if (@{$cancreate{'selfcreate'}} > 0) {
10196: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10197: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10198: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10199: $chgtext .= '<br />'.
10200: '<span class="LC_warning">'.
10201: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10202: '</span>';
10203: }
1.96 raeburn 10204: } elsif (ref($usertypes) eq 'HASH') {
10205: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10206: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10207: } else {
10208: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10209: }
10210: $chgtext .= '<ul>';
10211: foreach my $case (@{$cancreate{$type}}) {
10212: if ($case eq 'default') {
10213: $chgtext .= '<li>'.$othertitle.'</li>';
10214: } else {
10215: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10216: }
10217: }
1.100 raeburn 10218: $chgtext .= '</ul>';
10219: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10220: $chgtext .= '<br /><span class="LC_warning">'.
10221: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10222: '</span>';
1.100 raeburn 10223: }
10224: }
10225: } else {
10226: if (@{$cancreate{$type}} == 0) {
10227: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10228: } else {
10229: $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 10230: }
10231: }
10232: }
1.160.6.40 raeburn 10233: } elsif ($type eq 'selfcreateprocessing') {
10234: my %choices = &Apache::lonlocal::texthash (
10235: automatic => 'Automatic approval',
10236: approval => 'Queued for approval',
10237: );
10238: if (@statuses > 1) {
10239: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10240: '<ul>';
10241: foreach my $type (@statuses) {
10242: if ($type eq 'default') {
10243: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10244: } else {
10245: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10246: }
10247: }
10248: $chgtext .= '</ul>';
10249: } else {
10250: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10251: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10252: }
1.160.6.5 raeburn 10253: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 10254: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 10255: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10256: } else {
10257: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 10258: if ($captchas{$savecaptcha{$type}}) {
10259: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 10260: } else {
10261: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
10262: }
10263: }
10264: } elsif ($type eq 'recaptchakeys') {
10265: my ($privkey,$pubkey);
1.160.6.34 raeburn 10266: if (ref($savecaptcha{$type}) eq 'HASH') {
10267: $pubkey = $savecaptcha{$type}{'public'};
10268: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 10269: }
10270: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10271: if (!$pubkey) {
10272: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10273: } else {
10274: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10275: }
10276: if (!$privkey) {
10277: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10278: } else {
10279: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10280: }
10281: $chgtext .= '</ul>';
1.160.6.69 raeburn 10282: } elsif ($type eq 'recaptchaversion') {
10283: if ($savecaptcha{'captcha'} eq 'recaptcha') {
10284: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
10285: }
1.160.6.34 raeburn 10286: } elsif ($type eq 'emailusername') {
10287: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 10288: if (ref($types) eq 'ARRAY') {
10289: foreach my $type (@{$types}) {
10290: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10291: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 10292: $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 10293: '<ul>';
10294: foreach my $field (@{$infofields}) {
10295: if ($cancreate{'emailusername'}{$type}{$field}) {
10296: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10297: }
10298: }
1.160.6.50 raeburn 10299: $chgtext .= '</ul>';
10300: } else {
10301: $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 10302: }
10303: } else {
1.160.6.50 raeburn 10304: $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 10305: }
10306: }
10307: }
10308: }
10309: } elsif ($type eq 'notify') {
10310: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10311: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10312: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10313: if ($cancreate{'notify'}{'approval'}) {
10314: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10315: }
10316: }
1.43 raeburn 10317: }
1.34 raeburn 10318: }
1.160.6.34 raeburn 10319: if ($chgtext) {
10320: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10321: }
10322: }
10323: }
1.43 raeburn 10324: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10325: my ($emailrules,$emailruleorder) =
10326: &Apache::lonnet::inst_userrules($dom,'email');
10327: my $chgtext = '<ul>';
10328: foreach my $type (@email_rule) {
10329: if (ref($emailrules->{$type}) eq 'HASH') {
10330: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10331: }
10332: }
10333: $chgtext .= '</ul>';
10334: if (@email_rule > 0) {
1.160.6.34 raeburn 10335: $resulttext .= '<li>'.
10336: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10337: $chgtext.
10338: '</li>';
1.43 raeburn 10339: } else {
1.160.6.34 raeburn 10340: $resulttext .= '<li>'.
10341: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10342: '</li>';
1.43 raeburn 10343: }
10344: }
1.160.6.34 raeburn 10345: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10346: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10347: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10348: foreach my $type (@{$changes{'selfcreate'}}) {
10349: my $typename = $type;
10350: if (ref($usertypes) eq 'HASH') {
10351: if ($usertypes->{$type} ne '') {
10352: $typename = $usertypes->{$type};
1.28 raeburn 10353: }
10354: }
1.160.6.34 raeburn 10355: my @modifiable;
10356: $resulttext .= '<li>'.
10357: &mt('Self-creation of account by users with status: [_1]',
10358: '<span class="LC_cusr_emph">'.$typename.'</span>').
10359: ' - '.&mt('modifiable fields (if institutional data blank): ');
10360: foreach my $field (@fields) {
10361: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10362: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
10363: }
10364: }
10365: if (@modifiable > 0) {
10366: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10367: } else {
1.160.6.34 raeburn 10368: $resulttext .= &mt('none');
1.43 raeburn 10369: }
1.160.6.34 raeburn 10370: $resulttext .= '</li>';
1.28 raeburn 10371: }
1.160.6.34 raeburn 10372: $resulttext .= '</ul></li>';
1.28 raeburn 10373: }
1.27 raeburn 10374: $resulttext .= '</ul>';
10375: } else {
1.160.6.34 raeburn 10376: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10377: }
10378: } else {
10379: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10380: &mt('An error occurred: [_1]',$putresult).'</span>';
10381: }
1.43 raeburn 10382: if ($warningmsg ne '') {
10383: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10384: }
1.23 raeburn 10385: return $resulttext;
10386: }
10387:
1.160.6.5 raeburn 10388: sub process_captcha {
10389: my ($container,$changes,$newsettings,$current) = @_;
10390: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10391: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10392: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10393: $newsettings->{'captcha'} = 'original';
10394: }
10395: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
10396: if ($container eq 'cancreate') {
10397: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10398: push(@{$changes->{'cancreate'}},'captcha');
10399: } elsif (!defined($changes->{'cancreate'})) {
10400: $changes->{'cancreate'} = ['captcha'];
10401: }
10402: } else {
10403: $changes->{'captcha'} = 1;
10404: }
10405: }
1.160.6.69 raeburn 10406: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 10407: if ($newsettings->{'captcha'} eq 'recaptcha') {
10408: $newpub = $env{'form.'.$container.'_recaptchapub'};
10409: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 10410: $newpub =~ s/[^\w\-]//g;
10411: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 10412: $newsettings->{'recaptchakeys'} = {
10413: public => $newpub,
10414: private => $newpriv,
10415: };
1.160.6.69 raeburn 10416: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10417: $newversion =~ s/\D//g;
10418: if ($newversion ne '2') {
10419: $newversion = 1;
10420: }
10421: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 10422: }
10423: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10424: $currpub = $current->{'recaptchakeys'}{'public'};
10425: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 10426: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10427: $newsettings->{'recaptchakeys'} = {
10428: public => '',
10429: private => '',
10430: }
10431: }
1.160.6.5 raeburn 10432: }
1.160.6.69 raeburn 10433: if ($current->{'captcha'} eq 'recaptcha') {
10434: $currversion = $current->{'recaptchaversion'};
10435: if ($currversion ne '2') {
10436: $currversion = 1;
10437: }
10438: }
10439: if ($currversion ne $newversion) {
10440: if ($container eq 'cancreate') {
10441: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10442: push(@{$changes->{'cancreate'}},'recaptchaversion');
10443: } elsif (!defined($changes->{'cancreate'})) {
10444: $changes->{'cancreate'} = ['recaptchaversion'];
10445: }
10446: } else {
10447: $changes->{'recaptchaversion'} = 1;
10448: }
10449: }
1.160.6.5 raeburn 10450: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
10451: if ($container eq 'cancreate') {
10452: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10453: push(@{$changes->{'cancreate'}},'recaptchakeys');
10454: } elsif (!defined($changes->{'cancreate'})) {
10455: $changes->{'cancreate'} = ['recaptchakeys'];
10456: }
10457: } else {
10458: $changes->{'recaptchakeys'} = 1;
10459: }
10460: }
10461: return;
10462: }
10463:
1.33 raeburn 10464: sub modify_usermodification {
10465: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 10466: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10467: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10468: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 10469: if ($key eq 'selfcreate') {
10470: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10471: } else {
10472: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10473: }
1.33 raeburn 10474: }
10475: }
1.160.6.34 raeburn 10476: my @contexts = ('author','course');
1.33 raeburn 10477: my %context_title = (
10478: author => 'In author context',
10479: course => 'In course context',
10480: );
10481: my @fields = ('lastname','firstname','middlename','generation',
10482: 'permanentemail','id');
10483: my %roles = (
10484: author => ['ca','aa'],
10485: course => ['st','ep','ta','in','cr'],
10486: );
10487: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10488: foreach my $context (@contexts) {
10489: foreach my $role (@{$roles{$context}}) {
10490: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10491: foreach my $item (@fields) {
10492: if (grep(/^\Q$item\E$/,@modifiable)) {
10493: $modifyhash{$context}{$role}{$item} = 1;
10494: } else {
10495: $modifyhash{$context}{$role}{$item} = 0;
10496: }
10497: }
10498: }
10499: if (ref($curr_usermodification{$context}) eq 'HASH') {
10500: foreach my $role (@{$roles{$context}}) {
10501: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10502: foreach my $field (@fields) {
10503: if ($modifyhash{$context}{$role}{$field} ne
10504: $curr_usermodification{$context}{$role}{$field}) {
10505: push(@{$changes{$context}},$role);
10506: last;
10507: }
10508: }
10509: }
10510: }
10511: } else {
10512: foreach my $context (@contexts) {
10513: foreach my $role (@{$roles{$context}}) {
10514: push(@{$changes{$context}},$role);
10515: }
10516: }
10517: }
10518: }
10519: my %usermodification_hash = (
10520: usermodification => \%modifyhash,
10521: );
10522: my $putresult = &Apache::lonnet::put_dom('configuration',
10523: \%usermodification_hash,$dom);
10524: if ($putresult eq 'ok') {
10525: if (keys(%changes) > 0) {
10526: $resulttext = &mt('Changes made: ').'<ul>';
10527: foreach my $context (@contexts) {
10528: if (ref($changes{$context}) eq 'ARRAY') {
10529: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10530: if (ref($changes{$context}) eq 'ARRAY') {
10531: foreach my $role (@{$changes{$context}}) {
10532: my $rolename;
1.160.6.34 raeburn 10533: if ($role eq 'cr') {
10534: $rolename = &mt('Custom');
1.33 raeburn 10535: } else {
1.160.6.34 raeburn 10536: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10537: }
10538: my @modifiable;
1.160.6.34 raeburn 10539: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10540: foreach my $field (@fields) {
10541: if ($modifyhash{$context}{$role}{$field}) {
10542: push(@modifiable,$fieldtitles{$field});
10543: }
10544: }
10545: if (@modifiable > 0) {
10546: $resulttext .= join(', ',@modifiable);
10547: } else {
10548: $resulttext .= &mt('none');
10549: }
10550: $resulttext .= '</li>';
10551: }
10552: $resulttext .= '</ul></li>';
10553: }
10554: }
10555: }
10556: $resulttext .= '</ul>';
10557: } else {
10558: $resulttext = &mt('No changes made to user modification settings');
10559: }
10560: } else {
10561: $resulttext = '<span class="LC_error">'.
10562: &mt('An error occurred: [_1]',$putresult).'</span>';
10563: }
10564: return $resulttext;
10565: }
10566:
1.43 raeburn 10567: sub modify_defaults {
1.160.6.27 raeburn 10568: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10569: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 10570: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 10571: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
10572: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 10573: my @authtypes = ('internal','krb4','krb5','localauth');
10574: foreach my $item (@items) {
10575: $newvalues{$item} = $env{'form.'.$item};
10576: if ($item eq 'auth_def') {
10577: if ($newvalues{$item} ne '') {
10578: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10579: push(@errors,$item);
10580: }
10581: }
10582: } elsif ($item eq 'lang_def') {
10583: if ($newvalues{$item} ne '') {
10584: if ($newvalues{$item} =~ /^(\w+)/) {
10585: my $langcode = $1;
1.103 raeburn 10586: if ($langcode ne 'x_chef') {
10587: if (code2language($langcode) eq '') {
10588: push(@errors,$item);
10589: }
1.43 raeburn 10590: }
10591: } else {
10592: push(@errors,$item);
10593: }
10594: }
1.54 raeburn 10595: } elsif ($item eq 'timezone_def') {
10596: if ($newvalues{$item} ne '') {
1.62 raeburn 10597: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10598: push(@errors,$item);
10599: }
10600: }
1.68 raeburn 10601: } elsif ($item eq 'datelocale_def') {
10602: if ($newvalues{$item} ne '') {
10603: my @datelocale_ids = DateTime::Locale->ids();
10604: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10605: push(@errors,$item);
10606: }
10607: }
1.141 raeburn 10608: } elsif ($item eq 'portal_def') {
10609: if ($newvalues{$item} ne '') {
10610: 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])\/?$/) {
10611: push(@errors,$item);
10612: }
10613: }
1.160.6.80 raeburn 10614: } elsif ($item eq 'intauth_cost') {
10615: if ($newvalues{$item} ne '') {
10616: if ($newvalues{$item} =~ /\D/) {
10617: push(@errors,$item);
10618: }
10619: }
10620: } elsif ($item eq 'intauth_check') {
10621: if ($newvalues{$item} ne '') {
10622: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
10623: push(@errors,$item);
10624: }
10625: }
10626: } elsif ($item eq 'intauth_switch') {
10627: if ($newvalues{$item} ne '') {
10628: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
10629: push(@errors,$item);
10630: }
10631: }
1.43 raeburn 10632: }
10633: if (grep(/^\Q$item\E$/,@errors)) {
10634: $newvalues{$item} = $domdefaults{$item};
10635: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10636: $changes{$item} = 1;
10637: }
1.72 raeburn 10638: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10639: }
10640: my %defaults_hash = (
1.72 raeburn 10641: defaults => \%newvalues,
10642: );
1.43 raeburn 10643: my $title = &defaults_titles();
1.160.6.40 raeburn 10644:
10645: my $currinststatus;
10646: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10647: $currinststatus = $domconfig{'inststatus'};
10648: } else {
10649: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10650: $currinststatus = {
10651: inststatustypes => $usertypes,
10652: inststatusorder => $types,
10653: inststatusguest => [],
10654: };
10655: }
10656: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10657: my @allpos;
10658: my %guests;
10659: my %alltypes;
10660: my ($currtitles,$currguests,$currorder);
10661: if (ref($currinststatus) eq 'HASH') {
10662: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10663: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10664: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10665: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10666: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10667: }
10668: }
10669: unless (grep(/^\Q$type\E$/,@todelete)) {
10670: my $position = $env{'form.inststatus_pos_'.$type};
10671: $position =~ s/\D+//g;
10672: $allpos[$position] = $type;
10673: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
10674: $alltypes{$type} =~ s/`//g;
10675: if ($env{'form.inststatus_guest_'.$type}) {
10676: $guests{$type} = 1;
10677: }
10678: }
10679: }
10680: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
10681: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
10682: }
10683: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
10684: $currtitles =~ s/,$//;
10685: }
10686: }
10687: if ($env{'form.addinststatus'}) {
10688: my $newtype = $env{'form.addinststatus'};
10689: $newtype =~ s/\W//g;
10690: unless (exists($alltypes{$newtype})) {
10691: if ($env{'form.addinststatus_guest'}) {
10692: $guests{$newtype} = 1;
10693: }
10694: $alltypes{$newtype} = $env{'form.addinststatus_title'};
10695: $alltypes{$newtype} =~ s/`//g;
10696: my $position = $env{'form.addinststatus_pos'};
10697: $position =~ s/\D+//g;
10698: if ($position ne '') {
10699: $allpos[$position] = $newtype;
10700: }
10701: }
10702: }
10703: my (@orderedstatus,@orderedguests);
10704: foreach my $type (@allpos) {
10705: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
10706: push(@orderedstatus,$type);
10707: if ($guests{$type}) {
10708: push(@orderedguests,$type);
10709: }
10710: }
10711: }
10712: foreach my $type (keys(%alltypes)) {
10713: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
10714: delete($alltypes{$type});
10715: }
10716: }
10717: $defaults_hash{'inststatus'} = {
10718: inststatustypes => \%alltypes,
10719: inststatusorder => \@orderedstatus,
10720: inststatusguest => \@orderedguests,
10721: };
10722: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
10723: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
10724: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
10725: }
10726: }
10727: if ($currorder ne join(',',@orderedstatus)) {
10728: $changes{'inststatus'}{'inststatusorder'} = 1;
10729: }
10730: if ($currguests ne join(',',@orderedguests)) {
10731: $changes{'inststatus'}{'inststatusguest'} = 1;
10732: }
10733: my $newtitles;
10734: foreach my $item (@orderedstatus) {
10735: $newtitles .= $alltypes{$item}.',';
10736: }
10737: $newtitles =~ s/,$//;
10738: if ($currtitles ne $newtitles) {
10739: $changes{'inststatus'}{'inststatustypes'} = 1;
10740: }
1.43 raeburn 10741: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
10742: $dom);
10743: if ($putresult eq 'ok') {
10744: if (keys(%changes) > 0) {
10745: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 10746: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 10747: 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";
10748: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 10749: if ($item eq 'inststatus') {
10750: if (ref($changes{'inststatus'}) eq 'HASH') {
10751: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
10752: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
10753: foreach my $type (@orderedstatus) {
10754: $resulttext .= $alltypes{$type}.', ';
10755: }
10756: $resulttext =~ s/, $//;
10757: $resulttext .= '</li>';
10758: }
10759: if ($changes{'inststatus'}{'inststatusguest'}) {
10760: $resulttext .= '<li>';
10761: if (@orderedguests) {
10762: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
10763: foreach my $type (@orderedguests) {
10764: $resulttext .= $alltypes{$type}.', ';
10765: }
10766: $resulttext =~ s/, $//;
10767: } else {
10768: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
10769: }
10770: $resulttext .= '</li>';
10771: }
10772: }
10773: } else {
10774: my $value = $env{'form.'.$item};
10775: if ($value eq '') {
10776: $value = &mt('none');
10777: } elsif ($item eq 'auth_def') {
10778: my %authnames = &authtype_names();
10779: my %shortauth = (
10780: internal => 'int',
10781: krb4 => 'krb4',
10782: krb5 => 'krb5',
10783: localauth => 'loc',
10784: );
10785: $value = $authnames{$shortauth{$value}};
1.160.6.80 raeburn 10786: } elsif ($item eq 'intauth_switch') {
10787: my %optiondesc = &Apache::lonlocal::texthash (
10788: 0 => 'No',
10789: 1 => 'Yes',
10790: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
10791: );
10792: if ($value =~ /^(0|1|2)$/) {
10793: $value = $optiondesc{$value};
10794: } else {
10795: $value = &mt('none -- defaults to No');
10796: }
10797: } elsif ($item eq 'intauth_check') {
10798: my %optiondesc = &Apache::lonlocal::texthash (
10799: 0 => 'No',
10800: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
10801: 2 => 'Yes, disallow login if stored cost is less than domain default',
10802: );
10803: if ($value =~ /^(0|1|2)$/) {
10804: $value = $optiondesc{$value};
10805: } else {
10806: $value = &mt('none -- defaults to No');
10807: }
1.160.6.40 raeburn 10808: }
10809: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
10810: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 10811: }
10812: }
10813: $resulttext .= '</ul>';
10814: $mailmsgtext .= "\n";
10815: my $cachetime = 24*60*60;
1.72 raeburn 10816: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10817: if (ref($lastactref) eq 'HASH') {
10818: $lastactref->{'domdefaults'} = 1;
10819: }
1.68 raeburn 10820: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 10821: my $notify = 1;
10822: if (ref($domconfig{'contacts'}) eq 'HASH') {
10823: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
10824: $notify = 0;
10825: }
10826: }
10827: if ($notify) {
10828: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
10829: "LON-CAPA Domain Settings Change - $dom",
10830: $mailmsgtext);
10831: }
1.54 raeburn 10832: }
1.43 raeburn 10833: } else {
1.54 raeburn 10834: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 10835: }
10836: } else {
10837: $resulttext = '<span class="LC_error">'.
10838: &mt('An error occurred: [_1]',$putresult).'</span>';
10839: }
10840: if (@errors > 0) {
10841: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
10842: foreach my $item (@errors) {
10843: $resulttext .= ' "'.$title->{$item}.'",';
10844: }
10845: $resulttext =~ s/,$//;
10846: }
10847: return $resulttext;
10848: }
10849:
1.46 raeburn 10850: sub modify_scantron {
1.160.6.24 raeburn 10851: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 10852: my ($resulttext,%confhash,%changes,$errors);
10853: my $custom = 'custom.tab';
10854: my $default = 'default.tab';
10855: my $servadm = $r->dir_config('lonAdmEMail');
10856: my ($configuserok,$author_ok,$switchserver) =
10857: &config_check($dom,$confname,$servadm);
10858: if ($env{'form.scantronformat.filename'} ne '') {
10859: my $error;
10860: if ($configuserok eq 'ok') {
10861: if ($switchserver) {
1.130 raeburn 10862: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 10863: } else {
10864: if ($author_ok eq 'ok') {
10865: my ($result,$scantronurl) =
10866: &publishlogo($r,'upload','scantronformat',$dom,
10867: $confname,'scantron','','',$custom);
10868: if ($result eq 'ok') {
10869: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 10870: $changes{'scantronformat'} = 1;
1.46 raeburn 10871: } else {
10872: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
10873: }
10874: } else {
10875: $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);
10876: }
10877: }
10878: } else {
10879: $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);
10880: }
10881: if ($error) {
10882: &Apache::lonnet::logthis($error);
10883: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10884: }
10885: }
1.48 raeburn 10886: if (ref($domconfig{'scantron'}) eq 'HASH') {
10887: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
10888: if ($env{'form.scantronformat_del'}) {
10889: $confhash{'scantron'}{'scantronformat'} = '';
10890: $changes{'scantronformat'} = 1;
1.46 raeburn 10891: }
10892: }
10893: }
10894: if (keys(%confhash) > 0) {
10895: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10896: $dom);
10897: if ($putresult eq 'ok') {
10898: if (keys(%changes) > 0) {
1.48 raeburn 10899: if (ref($confhash{'scantron'}) eq 'HASH') {
10900: $resulttext = &mt('Changes made:').'<ul>';
10901: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 10902: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 10903: } else {
1.130 raeburn 10904: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 10905: }
1.48 raeburn 10906: $resulttext .= '</ul>';
10907: } else {
1.130 raeburn 10908: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 10909: }
10910: $resulttext .= '</ul>';
10911: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10912: if (ref($lastactref) eq 'HASH') {
10913: $lastactref->{'domainconfig'} = 1;
10914: }
1.46 raeburn 10915: } else {
1.130 raeburn 10916: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10917: }
10918: } else {
10919: $resulttext = '<span class="LC_error">'.
10920: &mt('An error occurred: [_1]',$putresult).'</span>';
10921: }
10922: } else {
1.130 raeburn 10923: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10924: }
10925: if ($errors) {
10926: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10927: $errors.'</ul>';
10928: }
10929: return $resulttext;
10930: }
10931:
1.48 raeburn 10932: sub modify_coursecategories {
1.160.6.43 raeburn 10933: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 10934: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10935: $cathash);
1.48 raeburn 10936: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 10937: my @catitems = ('unauth','auth');
10938: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 10939: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 10940: $cathash = $domconfig{'coursecategories'}{'cats'};
10941: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10942: $changes{'togglecats'} = 1;
10943: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10944: }
10945: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10946: $changes{'categorize'} = 1;
10947: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
10948: }
1.120 raeburn 10949: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
10950: $changes{'togglecatscomm'} = 1;
10951: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
10952: }
10953: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
10954: $changes{'categorizecomm'} = 1;
10955: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
10956: }
1.160.6.42 raeburn 10957: foreach my $item (@catitems) {
10958: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10959: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
10960: $changes{$item} = 1;
10961: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10962: }
10963: }
10964: }
1.57 raeburn 10965: } else {
10966: $changes{'togglecats'} = 1;
10967: $changes{'categorize'} = 1;
1.124 raeburn 10968: $changes{'togglecatscomm'} = 1;
10969: $changes{'categorizecomm'} = 1;
1.87 raeburn 10970: $domconfig{'coursecategories'} = {
10971: togglecats => $env{'form.togglecats'},
10972: categorize => $env{'form.categorize'},
1.124 raeburn 10973: togglecatscomm => $env{'form.togglecatscomm'},
10974: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 10975: };
1.160.6.42 raeburn 10976: foreach my $item (@catitems) {
10977: if ($env{'form.coursecat_'.$item} ne 'std') {
10978: $changes{$item} = 1;
10979: }
10980: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10981: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10982: }
10983: }
1.57 raeburn 10984: }
10985: if (ref($cathash) eq 'HASH') {
10986: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 10987: push (@deletecategory,'instcode::0');
10988: }
1.120 raeburn 10989: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
10990: push(@deletecategory,'communities::0');
10991: }
1.48 raeburn 10992: }
1.57 raeburn 10993: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
10994: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10995: if (@deletecategory > 0) {
10996: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 10997: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 10998: foreach my $item (@deletecategory) {
1.57 raeburn 10999: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11000: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11001: $deletions{$item} = 1;
1.57 raeburn 11002: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11003: }
11004: }
11005: }
1.57 raeburn 11006: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11007: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11008: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11009: $reorderings{$item} = 1;
1.57 raeburn 11010: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11011: }
11012: if ($env{'form.addcategory_name_'.$item} ne '') {
11013: my $newcat = $env{'form.addcategory_name_'.$item};
11014: my $newdepth = $depth+1;
11015: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11016: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11017: $adds{$newitem} = 1;
11018: }
11019: if ($env{'form.subcat_'.$item} ne '') {
11020: my $newcat = $env{'form.subcat_'.$item};
11021: my $newdepth = $depth+1;
11022: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11023: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11024: $adds{$newitem} = 1;
11025: }
11026: }
11027: }
11028: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11029: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11030: my $newitem = 'instcode::0';
1.57 raeburn 11031: if ($cathash->{$newitem} eq '') {
11032: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11033: $adds{$newitem} = 1;
11034: }
11035: } else {
11036: my $newitem = 'instcode::0';
1.57 raeburn 11037: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11038: $adds{$newitem} = 1;
11039: }
11040: }
1.120 raeburn 11041: if ($env{'form.communities'} eq '1') {
11042: if (ref($cathash) eq 'HASH') {
11043: my $newitem = 'communities::0';
11044: if ($cathash->{$newitem} eq '') {
11045: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11046: $adds{$newitem} = 1;
11047: }
11048: } else {
11049: my $newitem = 'communities::0';
11050: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11051: $adds{$newitem} = 1;
11052: }
11053: }
1.48 raeburn 11054: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11055: if (($env{'form.addcategory_name'} ne 'instcode') &&
11056: ($env{'form.addcategory_name'} ne 'communities')) {
11057: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11058: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11059: $adds{$newitem} = 1;
11060: }
1.48 raeburn 11061: }
1.57 raeburn 11062: my $putresult;
1.48 raeburn 11063: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11064: if (keys(%deletions) > 0) {
11065: foreach my $key (keys(%deletions)) {
11066: if ($predelallitems{$key} ne '') {
11067: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11068: }
11069: }
11070: }
11071: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11072: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11073: if (ref($chkcats[0]) eq 'ARRAY') {
11074: my $depth = 0;
11075: my $chg = 0;
11076: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11077: my $name = $chkcats[0][$i];
11078: my $item;
11079: if ($name eq '') {
11080: $chg ++;
11081: } else {
11082: $item = &escape($name).'::0';
11083: if ($chg) {
1.57 raeburn 11084: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11085: }
11086: $depth ++;
1.57 raeburn 11087: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11088: $depth --;
11089: }
11090: }
11091: }
1.57 raeburn 11092: }
11093: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11094: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11095: if ($putresult eq 'ok') {
1.57 raeburn 11096: my %title = (
1.120 raeburn 11097: togglecats => 'Show/Hide a course in catalog',
11098: categorize => 'Assign a category to a course',
11099: togglecatscomm => 'Show/Hide a community in catalog',
11100: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11101: );
11102: my %level = (
1.120 raeburn 11103: dom => 'set in Domain ("Modify Course/Community")',
11104: crs => 'set in Course ("Course Configuration")',
11105: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 11106: none => 'No catalog',
11107: std => 'Standard catalog',
11108: domonly => 'Domain-only catalog',
11109: codesrch => 'Code search form',
1.57 raeburn 11110: );
1.48 raeburn 11111: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11112: if ($changes{'togglecats'}) {
11113: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11114: }
11115: if ($changes{'categorize'}) {
11116: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11117: }
1.120 raeburn 11118: if ($changes{'togglecatscomm'}) {
11119: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11120: }
11121: if ($changes{'categorizecomm'}) {
11122: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11123: }
1.160.6.42 raeburn 11124: if ($changes{'unauth'}) {
11125: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11126: }
11127: if ($changes{'auth'}) {
11128: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11129: }
1.57 raeburn 11130: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11131: my $cathash;
11132: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11133: $cathash = $domconfig{'coursecategories'}{'cats'};
11134: } else {
11135: $cathash = {};
11136: }
11137: my (@cats,@trails,%allitems);
11138: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11139: if (keys(%deletions) > 0) {
11140: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11141: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11142: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11143: }
11144: $resulttext .= '</ul></li>';
11145: }
11146: if (keys(%reorderings) > 0) {
11147: my %sort_by_trail;
11148: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11149: foreach my $key (keys(%reorderings)) {
11150: if ($allitems{$key} ne '') {
11151: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11152: }
1.48 raeburn 11153: }
1.57 raeburn 11154: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11155: $resulttext .= '<li>'.$trails[$trail].'</li>';
11156: }
11157: $resulttext .= '</ul></li>';
1.48 raeburn 11158: }
1.57 raeburn 11159: if (keys(%adds) > 0) {
11160: my %sort_by_trail;
11161: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11162: foreach my $key (keys(%adds)) {
11163: if ($allitems{$key} ne '') {
11164: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11165: }
11166: }
11167: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11168: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11169: }
1.57 raeburn 11170: $resulttext .= '</ul></li>';
1.48 raeburn 11171: }
11172: }
11173: $resulttext .= '</ul>';
1.160.6.43 raeburn 11174: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 11175: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11176: if ($changes{'auth'}) {
11177: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11178: }
11179: if ($changes{'unauth'}) {
11180: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11181: }
11182: my $cachetime = 24*60*60;
11183: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 11184: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 11185: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 11186: }
11187: }
1.48 raeburn 11188: } else {
11189: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11190: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11191: }
11192: } else {
1.120 raeburn 11193: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11194: }
11195: return $resulttext;
11196: }
11197:
1.69 raeburn 11198: sub modify_serverstatuses {
11199: my ($dom,%domconfig) = @_;
11200: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11201: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11202: %currserverstatus = %{$domconfig{'serverstatuses'}};
11203: }
11204: my @pages = &serverstatus_pages();
11205: foreach my $type (@pages) {
11206: $newserverstatus{$type}{'namedusers'} = '';
11207: $newserverstatus{$type}{'machines'} = '';
11208: if (defined($env{'form.'.$type.'_namedusers'})) {
11209: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11210: my @okusers;
11211: foreach my $user (@users) {
11212: my ($uname,$udom) = split(/:/,$user);
11213: if (($udom =~ /^$match_domain$/) &&
11214: (&Apache::lonnet::domain($udom)) &&
11215: ($uname =~ /^$match_username$/)) {
11216: if (!grep(/^\Q$user\E/,@okusers)) {
11217: push(@okusers,$user);
11218: }
11219: }
11220: }
11221: if (@okusers > 0) {
11222: @okusers = sort(@okusers);
11223: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11224: }
11225: }
11226: if (defined($env{'form.'.$type.'_machines'})) {
11227: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11228: my @okmachines;
11229: foreach my $ip (@machines) {
11230: my @parts = split(/\./,$ip);
11231: next if (@parts < 4);
11232: my $badip = 0;
11233: for (my $i=0; $i<4; $i++) {
11234: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11235: $badip = 1;
11236: last;
11237: }
11238: }
11239: if (!$badip) {
11240: push(@okmachines,$ip);
11241: }
11242: }
11243: @okmachines = sort(@okmachines);
11244: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11245: }
11246: }
11247: my %serverstatushash = (
11248: serverstatuses => \%newserverstatus,
11249: );
11250: foreach my $type (@pages) {
1.83 raeburn 11251: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11252: my (@current,@new);
1.83 raeburn 11253: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11254: if ($currserverstatus{$type}{$setting} ne '') {
11255: @current = split(/,/,$currserverstatus{$type}{$setting});
11256: }
11257: }
11258: if ($newserverstatus{$type}{$setting} ne '') {
11259: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11260: }
11261: if (@current > 0) {
11262: if (@new > 0) {
11263: foreach my $item (@current) {
11264: if (!grep(/^\Q$item\E$/,@new)) {
11265: $changes{$type}{$setting} = 1;
1.82 raeburn 11266: last;
11267: }
11268: }
1.84 raeburn 11269: foreach my $item (@new) {
11270: if (!grep(/^\Q$item\E$/,@current)) {
11271: $changes{$type}{$setting} = 1;
11272: last;
1.82 raeburn 11273: }
11274: }
11275: } else {
1.83 raeburn 11276: $changes{$type}{$setting} = 1;
1.69 raeburn 11277: }
1.83 raeburn 11278: } elsif (@new > 0) {
11279: $changes{$type}{$setting} = 1;
1.69 raeburn 11280: }
11281: }
11282: }
11283: if (keys(%changes) > 0) {
1.81 raeburn 11284: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11285: my $putresult = &Apache::lonnet::put_dom('configuration',
11286: \%serverstatushash,$dom);
11287: if ($putresult eq 'ok') {
11288: $resulttext .= &mt('Changes made:').'<ul>';
11289: foreach my $type (@pages) {
1.84 raeburn 11290: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11291: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11292: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11293: if ($newserverstatus{$type}{'namedusers'} eq '') {
11294: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11295: } else {
11296: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11297: }
1.84 raeburn 11298: }
11299: if ($changes{$type}{'machines'}) {
1.69 raeburn 11300: if ($newserverstatus{$type}{'machines'} eq '') {
11301: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11302: } else {
11303: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11304: }
11305:
11306: }
11307: $resulttext .= '</ul></li>';
11308: }
11309: }
11310: $resulttext .= '</ul>';
11311: } else {
11312: $resulttext = '<span class="LC_error">'.
11313: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11314:
11315: }
11316: } else {
11317: $resulttext = &mt('No changes made to access to server status pages');
11318: }
11319: return $resulttext;
11320: }
11321:
1.118 jms 11322: sub modify_helpsettings {
1.160.6.77 raeburn 11323: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 11324: my ($resulttext,$errors,%changes,%helphash);
11325: my %defaultchecked = ('submitbugs' => 'on');
11326: my @offon = ('off','on');
1.118 jms 11327: my @toggles = ('submitbugs');
1.160.6.77 raeburn 11328: my %current = ('submitbugs' => '',
11329: 'adhoc' => {},
11330: );
1.118 jms 11331: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 11332: %current = %{$domconfig{'helpsettings'}};
11333: }
1.160.6.77 raeburn 11334: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 11335: foreach my $item (@toggles) {
11336: if ($defaultchecked{$item} eq 'on') {
11337: if ($current{$item} eq '') {
11338: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 11339: $changes{$item} = 1;
11340: }
1.160.6.73 raeburn 11341: } elsif ($current{$item} ne $env{'form.'.$item}) {
11342: $changes{$item} = 1;
11343: }
11344: } elsif ($defaultchecked{$item} eq 'off') {
11345: if ($current{$item} eq '') {
11346: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 11347: $changes{$item} = 1;
11348: }
1.160.6.73 raeburn 11349: } elsif ($current{$item} ne $env{'form.'.$item}) {
11350: $changes{$item} = 1;
11351: }
11352: }
11353: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
11354: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11355: }
11356: }
1.160.6.77 raeburn 11357: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 11358: my $confname = $dom.'-domainconfig';
11359: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 11360: my (@allpos,%newsettings,%changedprivs,$newrole);
11361: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 11362: my @accesstypes = ('all','dh','da','none','status','inc','exc');
11363: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 11364: my %lt = &Apache::lonlocal::texthash(
11365: s => 'system',
11366: d => 'domain',
11367: order => 'Display order',
11368: access => 'Role usage',
1.160.6.79 raeburn 11369: all => 'All with domain helpdesk or helpdesk assistant role',
11370: dh => 'All with domain helpdesk role',
11371: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 11372: none => 'None',
11373: status => 'Determined based on institutional status',
11374: inc => 'Include all, but exclude specific personnel',
11375: exc => 'Exclude all, but include specific personnel',
11376: );
11377: for (my $num=0; $num<=$maxnum; $num++) {
11378: my ($prefix,$identifier,$rolename,%curr);
11379: if ($num == $maxnum) {
11380: next unless ($env{'form.newcusthelp'} == $maxnum);
11381: $identifier = 'custhelp'.$num;
11382: $prefix = 'helproles_'.$num;
11383: $rolename = $env{'form.custhelpname'.$num};
11384: $rolename=~s/[^A-Za-z0-9]//gs;
11385: next if ($rolename eq '');
11386: next if (exists($existing{'rolesdef_'.$rolename}));
11387: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11388: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11389: $newprivs{'c'},$confname,$dom);
11390: if ($result ne 'ok') {
11391: $errors .= '<li><span class="LC_error">'.
11392: &mt('An error occurred storing the new custom role: [_1]',
11393: $result).'</span></li>';
11394: next;
11395: } else {
11396: $changedprivs{$rolename} = \%newprivs;
11397: $newrole = $rolename;
11398: }
11399: } else {
11400: $prefix = 'helproles_'.$num;
11401: $rolename = $env{'form.'.$prefix};
11402: next if ($rolename eq '');
11403: next unless (exists($existing{'rolesdef_'.$rolename}));
11404: $identifier = 'custhelp'.$num;
11405: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11406: my %currprivs;
11407: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
11408: split(/\_/,$existing{'rolesdef_'.$rolename});
11409: foreach my $level ('c','d','s') {
11410: if ($newprivs{$level} ne $currprivs{$level}) {
11411: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11412: $newprivs{'c'},$confname,$dom);
11413: if ($result ne 'ok') {
11414: $errors .= '<li><span class="LC_error">'.
11415: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
11416: $rolename,$result).'</span></li>';
11417: } else {
11418: $changedprivs{$rolename} = \%newprivs;
11419: }
11420: last;
11421: }
11422: }
11423: if (ref($current{'adhoc'}) eq 'HASH') {
11424: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11425: %curr = %{$current{'adhoc'}{$rolename}};
11426: }
11427: }
11428: }
11429: my $newpos = $env{'form.'.$prefix.'_pos'};
11430: $newpos =~ s/\D+//g;
11431: $allpos[$newpos] = $rolename;
11432: my $newdesc = $env{'form.'.$prefix.'_desc'};
11433: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
11434: if ($curr{'desc'}) {
11435: if ($curr{'desc'} ne $newdesc) {
11436: $changes{'customrole'}{$rolename}{'desc'} = 1;
11437: $newsettings{$rolename}{'desc'} = $newdesc;
11438: }
11439: } elsif ($newdesc ne '') {
11440: $changes{'customrole'}{$rolename}{'desc'} = 1;
11441: $newsettings{$rolename}{'desc'} = $newdesc;
11442: }
11443: my $access = $env{'form.'.$prefix.'_access'};
11444: if (grep(/^\Q$access\E$/,@accesstypes)) {
11445: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
11446: if ($access eq 'status') {
11447: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
11448: if (scalar(@statuses) == 0) {
11449: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
11450: } else {
11451: my (@shownstatus,$numtypes);
11452: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11453: if (ref($types) eq 'ARRAY') {
11454: $numtypes = scalar(@{$types});
11455: foreach my $type (sort(@statuses)) {
11456: if ($type eq 'default') {
11457: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11458: } elsif (grep(/^\Q$type\E$/,@{$types})) {
11459: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11460: push(@shownstatus,$usertypes->{$type});
11461: }
1.160.6.73 raeburn 11462: }
11463: }
1.160.6.77 raeburn 11464: if (grep(/^default$/,@statuses)) {
11465: push(@shownstatus,$othertitle);
11466: }
11467: if (scalar(@shownstatus) == 1+$numtypes) {
11468: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
11469: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
11470: } else {
11471: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
11472: if (ref($curr{'status'}) eq 'ARRAY') {
11473: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11474: if (@diffs) {
11475: $changes{'customrole'}{$rolename}{$access} = 1;
11476: }
11477: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11478: $changes{'customrole'}{$rolename}{$access} = 1;
11479: }
11480: }
11481: }
11482: } elsif (($access eq 'inc') || ($access eq 'exc')) {
11483: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
11484: my @newspecstaff;
11485: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11486: foreach my $person (sort(@personnel)) {
11487: if ($domhelpdesk{$person}) {
11488: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
11489: }
11490: }
11491: if (ref($curr{$access}) eq 'ARRAY') {
11492: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11493: if (@diffs) {
11494: $changes{'customrole'}{$rolename}{$access} = 1;
11495: }
11496: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11497: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 11498: }
1.160.6.77 raeburn 11499: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11500: my ($uname,$udom) = split(/:/,$person);
11501: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
11502: }
11503: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 11504: }
1.160.6.77 raeburn 11505: } else {
11506: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
11507: }
11508: unless ($curr{'access'} eq $access) {
11509: $changes{'customrole'}{$rolename}{'access'} = 1;
11510: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 11511: }
11512: }
1.160.6.77 raeburn 11513: if (@allpos > 0) {
11514: my $idx = 0;
11515: foreach my $rolename (@allpos) {
11516: if ($rolename ne '') {
11517: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
11518: if (ref($current{'adhoc'}) eq 'HASH') {
11519: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11520: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
11521: $changes{'customrole'}{$rolename}{'order'} = 1;
11522: $newsettings{$rolename}{'order'} = $idx+1;
11523: }
11524: }
1.160.6.73 raeburn 11525: }
1.160.6.77 raeburn 11526: $idx ++;
1.122 jms 11527: }
11528: }
1.118 jms 11529: }
1.123 jms 11530: my $putresult;
11531: if (keys(%changes) > 0) {
1.160.6.5 raeburn 11532: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
11533: if ($putresult eq 'ok') {
1.160.6.77 raeburn 11534: if (ref($helphash{'helpsettings'}) eq 'HASH') {
11535: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
11536: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
11537: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
11538: }
11539: }
11540: my $cachetime = 24*60*60;
11541: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11542: if (ref($lastactref) eq 'HASH') {
11543: $lastactref->{'domdefaults'} = 1;
11544: }
11545: } else {
11546: $errors .= '<li><span class="LC_error">'.
11547: &mt('An error occurred storing the settings: [_1]',
11548: $putresult).'</span></li>';
11549: }
11550: }
11551: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
11552: $resulttext = &mt('Changes made:').'<ul>';
11553: my (%shownprivs,@levelorder);
11554: @levelorder = ('c','d','s');
11555: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 11556: foreach my $item (sort(keys(%changes))) {
11557: if ($item eq 'submitbugs') {
11558: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11559: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11560: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 11561: } elsif ($item eq 'customrole') {
11562: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 11563: my @keyorder = ('order','desc','access','status','exc','inc');
11564: my %keytext = &Apache::lonlocal::texthash(
11565: order => 'Order',
11566: desc => 'Role description',
11567: access => 'Role usage',
1.160.6.83 raeburn 11568: status => 'Allowed institutional types',
1.160.6.77 raeburn 11569: exc => 'Allowed personnel',
11570: inc => 'Disallowed personnel',
11571: );
1.160.6.73 raeburn 11572: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 11573: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
11574: if ($role eq $newrole) {
11575: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
11576: $role).'<ul>';
11577: } else {
11578: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11579: $role).'<ul>';
11580: }
11581: foreach my $key (@keyorder) {
11582: if ($changes{'customrole'}{$role}{$key}) {
11583: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
11584: $keytext{$key},$newsettings{$role}{$key}).
11585: '</li>';
11586: }
11587: }
11588: if (ref($changedprivs{$role}) eq 'HASH') {
11589: $shownprivs{$role} = 1;
11590: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
11591: foreach my $level (@levelorder) {
11592: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11593: next if ($item eq '');
11594: my ($priv) = split(/\&/,$item,2);
11595: if (&Apache::lonnet::plaintext($priv)) {
11596: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11597: unless ($level eq 'c') {
11598: $resulttext .= ' ('.$lt{$level}.')';
11599: }
11600: $resulttext .= '</li>';
11601: }
11602: }
11603: }
11604: $resulttext .= '</ul>';
11605: }
11606: $resulttext .= '</ul></li>';
11607: }
1.160.6.73 raeburn 11608: }
11609: }
1.160.6.5 raeburn 11610: }
11611: }
11612: }
1.160.6.77 raeburn 11613: if (keys(%changedprivs)) {
11614: foreach my $role (sort(keys(%changedprivs))) {
11615: unless ($shownprivs{$role}) {
11616: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11617: $role).'<ul>'.
11618: '<li>'.&mt('Privileges set to :').'<ul>';
11619: foreach my $level (@levelorder) {
11620: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11621: next if ($item eq '');
11622: my ($priv) = split(/\&/,$item,2);
11623: if (&Apache::lonnet::plaintext($priv)) {
11624: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11625: unless ($level eq 'c') {
11626: $resulttext .= ' ('.$lt{$level}.')';
11627: }
11628: $resulttext .= '</li>';
11629: }
11630: }
11631: }
11632: $resulttext .= '</ul></li></ul></li>';
11633: }
11634: }
11635: }
11636: $resulttext .= '</ul>';
11637: } else {
11638: $resulttext = &mt('No changes made to help settings');
1.118 jms 11639: }
11640: if ($errors) {
1.160.6.5 raeburn 11641: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 11642: $errors.'</ul>';
1.118 jms 11643: }
11644: return $resulttext;
11645: }
11646:
1.121 raeburn 11647: sub modify_coursedefaults {
1.160.6.27 raeburn 11648: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11649: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 11650: my %defaultchecked = (
11651: 'uselcmath' => 'on',
11652: 'usejsme' => 'on'
11653: );
11654: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 11655: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 11656: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
11657: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 11658: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 11659: my %staticdefaults = (
11660: anonsurvey_threshold => 10,
11661: uploadquota => 500,
1.160.6.57 raeburn 11662: postsubmit => 60,
1.160.6.70 raeburn 11663: mysqltables => 172800,
1.160.6.21 raeburn 11664: );
1.121 raeburn 11665:
11666: $defaultshash{'coursedefaults'} = {};
11667:
11668: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11669: if ($domconfig{'coursedefaults'} eq '') {
11670: $domconfig{'coursedefaults'} = {};
11671: }
11672: }
11673:
11674: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11675: foreach my $item (@toggles) {
11676: if ($defaultchecked{$item} eq 'on') {
11677: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11678: ($env{'form.'.$item} eq '0')) {
11679: $changes{$item} = 1;
1.160.6.16 raeburn 11680: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11681: $changes{$item} = 1;
11682: }
11683: } elsif ($defaultchecked{$item} eq 'off') {
11684: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11685: ($env{'form.'.$item} eq '1')) {
11686: $changes{$item} = 1;
11687: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11688: $changes{$item} = 1;
11689: }
11690: }
11691: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11692: }
1.160.6.21 raeburn 11693: foreach my $item (@numbers) {
11694: my ($currdef,$newdef);
1.160.6.26 raeburn 11695: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 11696: if ($item eq 'anonsurvey_threshold') {
11697: $currdef = $domconfig{'coursedefaults'}{$item};
11698: $newdef =~ s/\D//g;
11699: if ($newdef eq '' || $newdef < 1) {
11700: $newdef = 1;
11701: }
11702: $defaultshash{'coursedefaults'}{$item} = $newdef;
11703: } else {
1.160.6.70 raeburn 11704: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
11705: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
11706: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 11707: }
11708: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 11709: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 11710: }
11711: if ($currdef ne $newdef) {
11712: my $staticdef;
11713: if ($item eq 'anonsurvey_threshold') {
11714: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11715: $changes{$item} = 1;
11716: }
1.160.6.70 raeburn 11717: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
11718: my $setting = $1;
11719: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
11720: $changes{$setting} = 1;
1.160.6.21 raeburn 11721: }
11722: }
1.139 raeburn 11723: }
11724: }
1.160.6.64 raeburn 11725: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11726: my @currclonecode;
11727: if (ref($currclone) eq 'HASH') {
11728: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11729: @currclonecode = @{$currclone->{'instcode'}};
11730: }
11731: }
11732: my $newclone;
11733: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11734: $newclone = $env{'form.canclone'};
11735: }
11736: if ($newclone eq 'instcode') {
11737: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11738: my (%codedefaults,@code_order,@clonecode);
11739: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11740: \@code_order);
11741: foreach my $item (@code_order) {
11742: if (grep(/^\Q$item\E$/,@newcodes)) {
11743: push(@clonecode,$item);
11744: }
11745: }
11746: if (@clonecode) {
11747: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11748: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11749: if (@diffs) {
11750: $changes{'canclone'} = 1;
11751: }
11752: } else {
11753: $newclone eq '';
11754: }
11755: } elsif ($newclone ne '') {
11756: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11757: }
11758: if ($newclone ne $currclone) {
11759: $changes{'canclone'} = 1;
11760: }
1.160.6.57 raeburn 11761: my %credits;
11762: foreach my $type (@types) {
11763: unless ($type eq 'community') {
11764: $credits{$type} = $env{'form.'.$type.'_credits'};
11765: $credits{$type} =~ s/[^\d.]+//g;
11766: }
11767: }
11768: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11769: ($env{'form.coursecredits'} eq '1')) {
11770: $changes{'coursecredits'} = 1;
11771: foreach my $type (keys(%credits)) {
11772: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11773: }
11774: } else {
11775: if ($env{'form.coursecredits'} eq '1') {
11776: foreach my $type (@types) {
11777: unless ($type eq 'community') {
11778: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11779: $changes{'coursecredits'} = 1;
11780: }
11781: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11782: }
11783: }
11784: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11785: foreach my $type (@types) {
11786: unless ($type eq 'community') {
11787: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11788: $changes{'coursecredits'} = 1;
11789: last;
11790: }
11791: }
11792: }
11793: }
11794: }
11795: if ($env{'form.postsubmit'} eq '1') {
11796: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11797: my %currtimeout;
11798: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11799: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11800: $changes{'postsubmit'} = 1;
11801: }
11802: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11803: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11804: }
11805: } else {
11806: $changes{'postsubmit'} = 1;
11807: }
11808: foreach my $type (@types) {
11809: my $timeout = $env{'form.'.$type.'_timeout'};
11810: $timeout =~ s/\D//g;
11811: if ($timeout == $staticdefaults{'postsubmit'}) {
11812: $timeout = '';
11813: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11814: $timeout = '0';
11815: }
11816: unless ($timeout eq '') {
11817: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11818: }
11819: if (exists($currtimeout{$type})) {
11820: if ($timeout ne $currtimeout{$type}) {
11821: $changes{'postsubmit'} = 1;
11822: }
11823: } elsif ($timeout ne '') {
11824: $changes{'postsubmit'} = 1;
11825: }
11826: }
11827: } else {
11828: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11829: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11830: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11831: $changes{'postsubmit'} = 1;
11832: }
11833: } else {
11834: $changes{'postsubmit'} = 1;
11835: }
1.160.6.16 raeburn 11836: }
1.121 raeburn 11837: }
11838: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11839: $dom);
11840: if ($putresult eq 'ok') {
11841: if (keys(%changes) > 0) {
1.160.6.27 raeburn 11842: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 11843: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 11844: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 11845: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 11846: foreach my $item ('uselcmath','usejsme') {
11847: if ($changes{$item}) {
11848: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11849: }
1.160.6.16 raeburn 11850: }
11851: if ($changes{'coursecredits'}) {
11852: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 11853: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11854: $domdefaults{$type.'credits'} =
11855: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11856: }
11857: }
11858: }
11859: if ($changes{'postsubmit'}) {
11860: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11861: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11862: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11863: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11864: $domdefaults{$type.'postsubtimeout'} =
11865: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11866: }
11867: }
1.160.6.16 raeburn 11868: }
11869: }
1.160.6.21 raeburn 11870: if ($changes{'uploadquota'}) {
11871: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11872: foreach my $type (@types) {
11873: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11874: }
11875: }
11876: }
1.160.6.64 raeburn 11877: if ($changes{'canclone'}) {
11878: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11879: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11880: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11881: if (@clonecodes) {
11882: $domdefaults{'canclone'} = join('+',@clonecodes);
11883: }
11884: }
11885: } else {
11886: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11887: }
11888: }
1.121 raeburn 11889: my $cachetime = 24*60*60;
11890: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11891: if (ref($lastactref) eq 'HASH') {
11892: $lastactref->{'domdefaults'} = 1;
11893: }
1.121 raeburn 11894: }
11895: $resulttext = &mt('Changes made:').'<ul>';
11896: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 11897: if ($item eq 'uselcmath') {
1.121 raeburn 11898: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 11899: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 11900: } else {
1.160.6.57 raeburn 11901: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11902: }
11903: } elsif ($item eq 'usejsme') {
11904: if ($env{'form.'.$item} eq '1') {
11905: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11906: } else {
11907: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 11908: }
1.139 raeburn 11909: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 11910: $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 11911: } elsif ($item eq 'uploadquota') {
11912: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11913: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11914: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11915: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 11916: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
11917:
1.160.6.21 raeburn 11918: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11919: '</ul>'.
11920: '</li>';
11921: } else {
11922: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11923: }
1.160.6.70 raeburn 11924: } elsif ($item eq 'mysqltables') {
11925: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
11926: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
11927: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
11928: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
11929: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
11930: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
11931: '</ul>'.
11932: '</li>';
11933: } else {
11934: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
11935: }
1.160.6.57 raeburn 11936: } elsif ($item eq 'postsubmit') {
11937: if ($domdefaults{'postsubmit'} eq 'off') {
11938: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
11939: } else {
11940: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
11941: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11942: $resulttext .= &mt('durations:').'<ul>';
11943: foreach my $type (@types) {
11944: $resulttext .= '<li>';
11945: my $timeout;
11946: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11947: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11948: }
11949: my $display;
11950: if ($timeout eq '0') {
11951: $display = &mt('unlimited');
11952: } elsif ($timeout eq '') {
11953: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
11954: } else {
11955: $display = &mt('[quant,_1,second]',$timeout);
11956: }
11957: if ($type eq 'community') {
11958: $resulttext .= &mt('Communities');
11959: } elsif ($type eq 'official') {
11960: $resulttext .= &mt('Official courses');
11961: } elsif ($type eq 'unofficial') {
11962: $resulttext .= &mt('Unofficial courses');
11963: } elsif ($type eq 'textbook') {
11964: $resulttext .= &mt('Textbook courses');
11965: }
11966: $resulttext .= ' -- '.$display.'</li>';
11967: }
11968: $resulttext .= '</ul>';
11969: }
11970: $resulttext .= '</li>';
11971: }
1.160.6.16 raeburn 11972: } elsif ($item eq 'coursecredits') {
11973: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11974: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 11975: ($domdefaults{'unofficialcredits'} eq '') &&
11976: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 11977: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11978: } else {
11979: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
11980: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
11981: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 11982: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 11983: '</ul>'.
11984: '</li>';
11985: }
11986: } else {
11987: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11988: }
1.160.6.64 raeburn 11989: } elsif ($item eq 'canclone') {
11990: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11991: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11992: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
11993: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
11994: }
11995: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
11996: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
11997: } else {
11998: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
11999: }
1.140 raeburn 12000: }
1.121 raeburn 12001: }
12002: $resulttext .= '</ul>';
12003: } else {
12004: $resulttext = &mt('No changes made to course defaults');
12005: }
12006: } else {
12007: $resulttext = '<span class="LC_error">'.
12008: &mt('An error occurred: [_1]',$putresult).'</span>';
12009: }
12010: return $resulttext;
12011: }
12012:
1.160.6.37 raeburn 12013: sub modify_selfenrollment {
12014: my ($dom,$lastactref,%domconfig) = @_;
12015: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
12016: my @types = ('official','unofficial','community','textbook');
12017: my %titles = &tool_titles();
12018: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12019: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
12020: $ordered{'default'} = ['types','registered','approval','limit'];
12021:
12022: my (%roles,%shown,%toplevel);
12023: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12024:
12025: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12026: if ($domconfig{'selfenrollment'} eq '') {
12027: $domconfig{'selfenrollment'} = {};
12028: }
12029: }
12030: %toplevel = (
12031: admin => 'Configuration Rights',
12032: default => 'Default settings',
12033: validation => 'Validation of self-enrollment requests',
12034: );
12035: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
12036:
12037: if (ref($ordered{'admin'}) eq 'ARRAY') {
12038: foreach my $item (@{$ordered{'admin'}}) {
12039: foreach my $type (@types) {
12040: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12041: $selfenrollhash{'admin'}{$type}{$item} = 1;
12042: } else {
12043: $selfenrollhash{'admin'}{$type}{$item} = 0;
12044: }
12045: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12046: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12047: if ($selfenrollhash{'admin'}{$type}{$item} ne
12048: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12049: push(@{$changes{'admin'}{$type}},$item);
12050: }
12051: } else {
12052: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12053: push(@{$changes{'admin'}{$type}},$item);
12054: }
12055: }
12056: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12057: push(@{$changes{'admin'}{$type}},$item);
12058: }
12059: }
12060: }
12061: }
12062:
12063: foreach my $item (@{$ordered{'default'}}) {
12064: foreach my $type (@types) {
12065: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12066: if ($item eq 'types') {
12067: unless (($value eq 'all') || ($value eq 'dom')) {
12068: $value = '';
12069: }
12070: } elsif ($item eq 'registered') {
12071: unless ($value eq '1') {
12072: $value = 0;
12073: }
12074: } elsif ($item eq 'approval') {
12075: unless ($value =~ /^[012]$/) {
12076: $value = 0;
12077: }
12078: } else {
12079: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12080: $value = 'none';
12081: }
12082: }
12083: $selfenrollhash{'default'}{$type}{$item} = $value;
12084: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12085: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12086: if ($selfenrollhash{'default'}{$type}{$item} ne
12087: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12088: push(@{$changes{'default'}{$type}},$item);
12089: }
12090: } else {
12091: push(@{$changes{'default'}{$type}},$item);
12092: }
12093: } else {
12094: push(@{$changes{'default'}{$type}},$item);
12095: }
12096: if ($item eq 'limit') {
12097: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12098: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12099: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12100: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12101: }
12102: } else {
12103: $selfenrollhash{'default'}{$type}{'cap'} = '';
12104: }
12105: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12106: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12107: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12108: push(@{$changes{'default'}{$type}},'cap');
12109: }
12110: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12111: push(@{$changes{'default'}{$type}},'cap');
12112: }
12113: }
12114: }
12115: }
12116:
12117: foreach my $item (@{$itemsref}) {
12118: if ($item eq 'fields') {
12119: my @changed;
12120: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12121: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12122: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12123: }
12124: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12125: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12126: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12127: $domconfig{'selfenrollment'}{'validation'}{$item});
12128: } else {
12129: @changed = @{$selfenrollhash{'validation'}{$item}};
12130: }
12131: } else {
12132: @changed = @{$selfenrollhash{'validation'}{$item}};
12133: }
12134: if (@changed) {
12135: if ($selfenrollhash{'validation'}{$item}) {
12136: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12137: } else {
12138: $changes{'validation'}{$item} = &mt('None');
12139: }
12140: }
12141: } else {
12142: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12143: if ($item eq 'markup') {
12144: if ($env{'form.selfenroll_validation_'.$item}) {
12145: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12146: }
12147: }
12148: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12149: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12150: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12151: }
12152: }
12153: }
12154: }
12155:
12156: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12157: $dom);
12158: if ($putresult eq 'ok') {
12159: if (keys(%changes) > 0) {
12160: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12161: $resulttext = &mt('Changes made:').'<ul>';
12162: foreach my $key ('admin','default','validation') {
12163: if (ref($changes{$key}) eq 'HASH') {
12164: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12165: if ($key eq 'validation') {
12166: foreach my $item (@{$itemsref}) {
12167: if (exists($changes{$key}{$item})) {
12168: if ($item eq 'markup') {
12169: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12170: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12171: } else {
12172: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12173: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12174: }
12175: }
12176: }
12177: } else {
12178: foreach my $type (@types) {
12179: if ($type eq 'community') {
12180: $roles{'1'} = &mt('Community personnel');
12181: } else {
12182: $roles{'1'} = &mt('Course personnel');
12183: }
12184: if (ref($changes{$key}{$type}) eq 'ARRAY') {
12185: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12186: if ($key eq 'admin') {
12187: my @mgrdc = ();
12188: if (ref($ordered{$key}) eq 'ARRAY') {
12189: foreach my $item (@{$ordered{'admin'}}) {
12190: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12191: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12192: push(@mgrdc,$item);
12193: }
12194: }
12195: }
12196: if (@mgrdc) {
12197: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12198: } else {
12199: delete($domdefaults{$type.'selfenrolladmdc'});
12200: }
12201: }
12202: } else {
12203: if (ref($ordered{$key}) eq 'ARRAY') {
12204: foreach my $item (@{$ordered{$key}}) {
12205: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12206: $domdefaults{$type.'selfenroll'.$item} =
12207: $selfenrollhash{$key}{$type}{$item};
12208: }
12209: }
12210: }
12211: }
12212: }
12213: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12214: foreach my $item (@{$ordered{$key}}) {
12215: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12216: $resulttext .= '<li>';
12217: if ($key eq 'admin') {
12218: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12219: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12220: } else {
12221: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12222: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12223: }
12224: $resulttext .= '</li>';
12225: }
12226: }
12227: $resulttext .= '</ul></li>';
12228: }
12229: }
12230: $resulttext .= '</ul></li>';
12231: }
12232: }
12233: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12234: my $cachetime = 24*60*60;
12235: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12236: if (ref($lastactref) eq 'HASH') {
12237: $lastactref->{'domdefaults'} = 1;
12238: }
12239: }
12240: }
12241: $resulttext .= '</ul>';
12242: } else {
12243: $resulttext = &mt('No changes made to self-enrollment settings');
12244: }
12245: } else {
12246: $resulttext = '<span class="LC_error">'.
12247: &mt('An error occurred: [_1]',$putresult).'</span>';
12248: }
12249: return $resulttext;
12250: }
12251:
1.137 raeburn 12252: sub modify_usersessions {
1.160.6.27 raeburn 12253: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12254: my @hostingtypes = ('version','excludedomain','includedomain');
12255: my @offloadtypes = ('primary','default');
12256: my %types = (
12257: remote => \@hostingtypes,
12258: hosted => \@hostingtypes,
12259: spares => \@offloadtypes,
12260: );
12261: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12262: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 12263: my (%by_ip,%by_location,@intdoms);
12264: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
12265: my @locations = sort(keys(%by_location));
1.137 raeburn 12266: my (%defaultshash,%changes);
12267: foreach my $prefix (@prefixes) {
12268: $defaultshash{'usersessions'}{$prefix} = {};
12269: }
1.160.6.27 raeburn 12270: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12271: my $resulttext;
1.138 raeburn 12272: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12273: foreach my $prefix (@prefixes) {
1.145 raeburn 12274: next if ($prefix eq 'spares');
12275: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12276: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12277: if ($type eq 'version') {
12278: my $value = $env{'form.'.$prefix.'_'.$type};
12279: my $okvalue;
12280: if ($value ne '') {
12281: if (grep(/^\Q$value\E$/,@lcversions)) {
12282: $okvalue = $value;
12283: }
12284: }
12285: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12286: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12287: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12288: if ($inuse == 0) {
12289: $changes{$prefix}{$type} = 1;
12290: } else {
12291: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12292: $changes{$prefix}{$type} = 1;
12293: }
12294: if ($okvalue ne '') {
12295: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12296: }
12297: }
12298: } else {
12299: if (($inuse == 1) && ($okvalue ne '')) {
12300: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12301: $changes{$prefix}{$type} = 1;
12302: }
12303: }
12304: } else {
12305: if (($inuse == 1) && ($okvalue ne '')) {
12306: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12307: $changes{$prefix}{$type} = 1;
12308: }
12309: }
12310: } else {
12311: if (($inuse == 1) && ($okvalue ne '')) {
12312: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12313: $changes{$prefix}{$type} = 1;
12314: }
12315: }
12316: } else {
12317: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12318: my @okvals;
12319: foreach my $val (@vals) {
1.138 raeburn 12320: if ($val =~ /:/) {
12321: my @items = split(/:/,$val);
12322: foreach my $item (@items) {
12323: if (ref($by_location{$item}) eq 'ARRAY') {
12324: push(@okvals,$item);
12325: }
12326: }
12327: } else {
12328: if (ref($by_location{$val}) eq 'ARRAY') {
12329: push(@okvals,$val);
12330: }
1.137 raeburn 12331: }
12332: }
12333: @okvals = sort(@okvals);
12334: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12335: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12336: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12337: if ($inuse == 0) {
12338: $changes{$prefix}{$type} = 1;
12339: } else {
12340: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12341: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12342: if (@changed > 0) {
12343: $changes{$prefix}{$type} = 1;
12344: }
12345: }
12346: } else {
12347: if ($inuse == 1) {
12348: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12349: $changes{$prefix}{$type} = 1;
12350: }
12351: }
12352: } else {
12353: if ($inuse == 1) {
12354: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12355: $changes{$prefix}{$type} = 1;
12356: }
12357: }
12358: } else {
12359: if ($inuse == 1) {
12360: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12361: $changes{$prefix}{$type} = 1;
12362: }
12363: }
12364: }
12365: }
12366: }
1.145 raeburn 12367:
12368: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12369: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12370: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12371: my $savespares;
12372:
12373: foreach my $lonhost (sort(keys(%servers))) {
12374: my $serverhomeID =
12375: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12376: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12377: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12378: my %spareschg;
12379: foreach my $type (@{$types{'spares'}}) {
12380: my @okspares;
12381: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12382: foreach my $server (@checked) {
1.152 raeburn 12383: if (&Apache::lonnet::hostname($server) ne '') {
12384: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12385: unless (grep(/^\Q$server\E$/,@okspares)) {
12386: push(@okspares,$server);
12387: }
1.145 raeburn 12388: }
12389: }
12390: }
12391: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12392: my $newspare;
1.152 raeburn 12393: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12394: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12395: $newspare = $new;
12396: }
12397: }
1.152 raeburn 12398: my @spares;
12399: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12400: @spares = sort(@okspares,$newspare);
12401: } else {
12402: @spares = sort(@okspares);
12403: }
12404: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12405: if (ref($spareid{$lonhost}) eq 'HASH') {
12406: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12407: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12408: if (@diffs > 0) {
12409: $spareschg{$type} = 1;
12410: }
12411: }
12412: }
12413: }
12414: if (keys(%spareschg) > 0) {
12415: $changes{'spares'}{$lonhost} = \%spareschg;
12416: }
12417: }
1.160.6.61 raeburn 12418: $defaultshash{'usersessions'}{'offloadnow'} = {};
12419: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12420: my @okoffload;
12421: if (@offloadnow) {
12422: foreach my $server (@offloadnow) {
12423: if (&Apache::lonnet::hostname($server) ne '') {
12424: unless (grep(/^\Q$server\E$/,@okoffload)) {
12425: push(@okoffload,$server);
12426: }
12427: }
12428: }
12429: if (@okoffload) {
12430: foreach my $lonhost (@okoffload) {
12431: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12432: }
12433: }
12434: }
1.145 raeburn 12435: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12436: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12437: if (ref($changes{'spares'}) eq 'HASH') {
12438: if (keys(%{$changes{'spares'}}) > 0) {
12439: $savespares = 1;
12440: }
12441: }
12442: } else {
12443: $savespares = 1;
12444: }
1.160.6.61 raeburn 12445: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12446: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12447: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12448: $changes{'offloadnow'} = 1;
12449: last;
12450: }
12451: }
12452: unless ($changes{'offloadnow'}) {
12453: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12454: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12455: $changes{'offloadnow'} = 1;
12456: last;
12457: }
12458: }
12459: }
12460: } elsif (@okoffload) {
12461: $changes{'offloadnow'} = 1;
12462: }
12463: } elsif (@okoffload) {
12464: $changes{'offloadnow'} = 1;
1.145 raeburn 12465: }
1.147 raeburn 12466: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12467: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12468: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12469: $dom);
12470: if ($putresult eq 'ok') {
12471: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12472: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12473: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12474: }
12475: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12476: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12477: }
1.160.6.61 raeburn 12478: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12479: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12480: }
1.137 raeburn 12481: }
12482: my $cachetime = 24*60*60;
12483: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 12484: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 12485: if (ref($lastactref) eq 'HASH') {
12486: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 12487: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 12488: }
1.147 raeburn 12489: if (keys(%changes) > 0) {
12490: my %lt = &usersession_titles();
12491: $resulttext = &mt('Changes made:').'<ul>';
12492: foreach my $prefix (@prefixes) {
12493: if (ref($changes{$prefix}) eq 'HASH') {
12494: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12495: if ($prefix eq 'spares') {
12496: if (ref($changes{$prefix}) eq 'HASH') {
12497: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12498: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12499: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 12500: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12501: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12502: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12503: foreach my $type (@{$types{$prefix}}) {
12504: if ($changes{$prefix}{$lonhost}{$type}) {
12505: my $offloadto = &mt('None');
12506: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12507: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12508: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12509: }
1.145 raeburn 12510: }
1.147 raeburn 12511: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12512: }
1.137 raeburn 12513: }
12514: }
1.147 raeburn 12515: $resulttext .= '</li>';
1.137 raeburn 12516: }
12517: }
1.147 raeburn 12518: } else {
12519: foreach my $type (@{$types{$prefix}}) {
12520: if (defined($changes{$prefix}{$type})) {
12521: my $newvalue;
12522: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12523: if (ref($defaultshash{'usersessions'}{$prefix})) {
12524: if ($type eq 'version') {
12525: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12526: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12527: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12528: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12529: }
1.145 raeburn 12530: }
12531: }
12532: }
1.147 raeburn 12533: if ($newvalue eq '') {
12534: if ($type eq 'version') {
12535: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12536: } else {
12537: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12538: }
1.145 raeburn 12539: } else {
1.147 raeburn 12540: if ($type eq 'version') {
12541: $newvalue .= ' '.&mt('(or later)');
12542: }
12543: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12544: }
1.137 raeburn 12545: }
12546: }
12547: }
1.147 raeburn 12548: $resulttext .= '</ul>';
1.137 raeburn 12549: }
12550: }
1.160.6.61 raeburn 12551: if ($changes{'offloadnow'}) {
12552: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12553: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12554: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12555: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12556: $resulttext .= '<li>'.$lonhost.'</li>';
12557: }
12558: $resulttext .= '</ul>';
12559: } else {
12560: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12561: }
12562: } else {
12563: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12564: }
12565: }
1.147 raeburn 12566: $resulttext .= '</ul>';
12567: } else {
12568: $resulttext = $nochgmsg;
1.137 raeburn 12569: }
12570: } else {
12571: $resulttext = '<span class="LC_error">'.
12572: &mt('An error occurred: [_1]',$putresult).'</span>';
12573: }
12574: } else {
1.147 raeburn 12575: $resulttext = $nochgmsg;
1.137 raeburn 12576: }
12577: return $resulttext;
12578: }
12579:
1.150 raeburn 12580: sub modify_loadbalancing {
12581: my ($dom,%domconfig) = @_;
12582: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12583: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12584: my ($othertitle,$usertypes,$types) =
12585: &Apache::loncommon::sorted_inst_types($dom);
12586: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 12587: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12588: my @sparestypes = ('primary','default');
12589: my %typetitles = &sparestype_titles();
12590: my $resulttext;
1.160.6.7 raeburn 12591: my (%currbalancer,%currtargets,%currrules,%existing);
12592: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12593: %existing = %{$domconfig{'loadbalancing'}};
12594: }
12595: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12596: \%currtargets,\%currrules);
12597: my ($saveloadbalancing,%defaultshash,%changes);
12598: my ($alltypes,$othertypes,$titles) =
12599: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12600: my %ruletitles = &offloadtype_text();
12601: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12602: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12603: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12604: if ($balancer eq '') {
12605: next;
12606: }
12607: if (!exists($servers{$balancer})) {
12608: if (exists($currbalancer{$balancer})) {
12609: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 12610: }
1.160.6.7 raeburn 12611: next;
12612: }
12613: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12614: push(@{$changes{'delete'}},$balancer);
12615: next;
12616: }
12617: if (!exists($currbalancer{$balancer})) {
12618: push(@{$changes{'add'}},$balancer);
12619: }
12620: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12621: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12622: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12623: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12624: $saveloadbalancing = 1;
12625: }
12626: foreach my $sparetype (@sparestypes) {
12627: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12628: my @offloadto;
12629: foreach my $target (@targets) {
12630: if (($servers{$target}) && ($target ne $balancer)) {
12631: if ($sparetype eq 'default') {
12632: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12633: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 12634: }
12635: }
1.160.6.7 raeburn 12636: unless(grep(/^\Q$target\E$/,@offloadto)) {
12637: push(@offloadto,$target);
12638: }
1.150 raeburn 12639: }
12640: }
1.160.6.76 raeburn 12641: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
12642: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
12643: push(@offloadto,$balancer);
12644: }
12645: }
12646: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 12647: }
1.160.6.7 raeburn 12648: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 12649: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 12650: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12651: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 12652: if (@targetdiffs > 0) {
1.160.6.7 raeburn 12653: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12654: }
1.160.6.7 raeburn 12655: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12656: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12657: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12658: }
12659: }
12660: }
12661: } else {
1.160.6.7 raeburn 12662: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
12663: foreach my $sparetype (@sparestypes) {
12664: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12665: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12666: $changes{'curr'}{$balancer}{'targets'} = 1;
12667: }
1.150 raeburn 12668: }
12669: }
1.160.6.7 raeburn 12670: }
1.150 raeburn 12671: }
12672: my $ishomedom;
1.160.6.7 raeburn 12673: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12674: $ishomedom = 1;
1.150 raeburn 12675: }
12676: if (ref($alltypes) eq 'ARRAY') {
12677: foreach my $type (@{$alltypes}) {
12678: my $rule;
1.160.6.7 raeburn 12679: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 12680: (!$ishomedom)) {
1.160.6.7 raeburn 12681: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12682: }
12683: if ($rule eq 'specific') {
1.160.6.55 raeburn 12684: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12685: if (exists($servers{$specifiedhost})) {
12686: $rule = $specifiedhost;
12687: }
1.150 raeburn 12688: }
1.160.6.7 raeburn 12689: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12690: if (ref($currrules{$balancer}) eq 'HASH') {
12691: if ($rule ne $currrules{$balancer}{$type}) {
12692: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12693: }
12694: } elsif ($rule ne '') {
1.160.6.7 raeburn 12695: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12696: }
12697: }
12698: }
1.160.6.7 raeburn 12699: }
12700: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12701: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12702: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12703: $defaultshash{'loadbalancing'} = {};
12704: }
12705: my $putresult = &Apache::lonnet::put_dom('configuration',
12706: \%defaultshash,$dom);
12707: if ($putresult eq 'ok') {
12708: if (keys(%changes) > 0) {
1.160.6.54 raeburn 12709: my %toupdate;
1.160.6.7 raeburn 12710: if (ref($changes{'delete'}) eq 'ARRAY') {
12711: foreach my $balancer (sort(@{$changes{'delete'}})) {
12712: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 12713: $toupdate{$balancer} = 1;
1.150 raeburn 12714: }
1.160.6.7 raeburn 12715: }
12716: if (ref($changes{'add'}) eq 'ARRAY') {
12717: foreach my $balancer (sort(@{$changes{'add'}})) {
12718: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 12719: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12720: }
12721: }
12722: if (ref($changes{'curr'}) eq 'HASH') {
12723: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 12724: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12725: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12726: if ($changes{'curr'}{$balancer}{'targets'}) {
12727: my %offloadstr;
12728: foreach my $sparetype (@sparestypes) {
12729: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12730: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12731: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12732: }
12733: }
1.150 raeburn 12734: }
1.160.6.7 raeburn 12735: if (keys(%offloadstr) == 0) {
12736: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 12737: } else {
1.160.6.7 raeburn 12738: my $showoffload;
12739: foreach my $sparetype (@sparestypes) {
12740: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12741: if (defined($offloadstr{$sparetype})) {
12742: $showoffload .= $offloadstr{$sparetype};
12743: } else {
12744: $showoffload .= &mt('None');
12745: }
12746: $showoffload .= (' 'x3);
12747: }
12748: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 12749: }
12750: }
12751: }
1.160.6.7 raeburn 12752: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12753: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12754: foreach my $type (@{$alltypes}) {
12755: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12756: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12757: my $balancetext;
12758: if ($rule eq '') {
12759: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 12760: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 12761: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12762: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 12763: foreach my $sparetype (@sparestypes) {
12764: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12765: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12766: }
12767: }
1.160.6.55 raeburn 12768: foreach my $item (@{$alltypes}) {
12769: next if ($item =~ /^_LC_ipchange/);
12770: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
12771: if ($hasrule eq 'homeserver') {
12772: map { $toupdate{$_} = 1; } (keys(%libraryservers));
12773: } else {
12774: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
12775: if ($servers{$hasrule}) {
12776: $toupdate{$hasrule} = 1;
12777: }
12778: }
12779: }
12780: }
12781: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
12782: $balancetext = $ruletitles{$rule};
12783: } else {
12784: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12785: $balancetext = $ruletitles{'particular'}.' '.$receiver;
12786: if ($receiver) {
12787: $toupdate{$receiver};
12788: }
12789: }
12790: } else {
12791: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 12792: }
1.160.6.7 raeburn 12793: } else {
12794: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
12795: }
1.160.6.26 raeburn 12796: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 12797: }
12798: }
12799: }
12800: }
1.160.6.54 raeburn 12801: if (keys(%toupdate)) {
12802: my %thismachine;
12803: my $updatedhere;
12804: my $cachetime = 60*60*24;
12805: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12806: foreach my $lonhost (keys(%toupdate)) {
12807: if ($thismachine{$lonhost}) {
12808: unless ($updatedhere) {
12809: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
12810: $defaultshash{'loadbalancing'},
12811: $cachetime);
12812: $updatedhere = 1;
12813: }
12814: } else {
12815: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
12816: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
12817: }
12818: }
12819: }
1.150 raeburn 12820: }
1.160.6.7 raeburn 12821: }
12822: if ($resulttext ne '') {
12823: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 12824: } else {
12825: $resulttext = $nochgmsg;
12826: }
12827: } else {
1.160.6.7 raeburn 12828: $resulttext = $nochgmsg;
1.150 raeburn 12829: }
12830: } else {
1.160.6.7 raeburn 12831: $resulttext = '<span class="LC_error">'.
12832: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 12833: }
12834: } else {
1.160.6.7 raeburn 12835: $resulttext = $nochgmsg;
1.150 raeburn 12836: }
12837: return $resulttext;
12838: }
12839:
1.48 raeburn 12840: sub recurse_check {
12841: my ($chkcats,$categories,$depth,$name) = @_;
12842: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
12843: my $chg = 0;
12844: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
12845: my $category = $chkcats->[$depth]{$name}[$j];
12846: my $item;
12847: if ($category eq '') {
12848: $chg ++;
12849: } else {
12850: my $deeper = $depth + 1;
12851: $item = &escape($category).':'.&escape($name).':'.$depth;
12852: if ($chg) {
12853: $categories->{$item} -= $chg;
12854: }
12855: &recurse_check($chkcats,$categories,$deeper,$category);
12856: $deeper --;
12857: }
12858: }
12859: }
12860: return;
12861: }
12862:
12863: sub recurse_cat_deletes {
12864: my ($item,$coursecategories,$deletions) = @_;
12865: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12866: my $subdepth = $depth + 1;
12867: if (ref($coursecategories) eq 'HASH') {
12868: foreach my $subitem (keys(%{$coursecategories})) {
12869: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
12870: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
12871: delete($coursecategories->{$subitem});
12872: $deletions->{$subitem} = 1;
12873: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 12874: }
1.48 raeburn 12875: }
12876: }
12877: return;
12878: }
12879:
1.125 raeburn 12880: sub active_dc_picker {
1.160.6.16 raeburn 12881: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 12882: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 12883: my @domcoord = keys(%domcoords);
12884: if (keys(%currhash)) {
12885: foreach my $dc (keys(%currhash)) {
12886: unless (exists($domcoords{$dc})) {
12887: push(@domcoord,$dc);
12888: }
12889: }
12890: }
12891: @domcoord = sort(@domcoord);
12892: my $numdcs = scalar(@domcoord);
12893: my $rows = 0;
12894: my $table;
1.125 raeburn 12895: if ($numdcs > 1) {
1.160.6.16 raeburn 12896: $table = '<table>';
12897: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 12898: my $rem = $i%($numinrow);
12899: if ($rem == 0) {
12900: if ($i > 0) {
1.160.6.16 raeburn 12901: $table .= '</tr>';
1.125 raeburn 12902: }
1.160.6.16 raeburn 12903: $table .= '<tr>';
12904: $rows ++;
1.125 raeburn 12905: }
1.160.6.16 raeburn 12906: my $check = '';
12907: if ($inputtype eq 'radio') {
12908: if (keys(%currhash) == 0) {
12909: if (!$i) {
12910: $check = ' checked="checked"';
12911: }
12912: } elsif (exists($currhash{$domcoord[$i]})) {
12913: $check = ' checked="checked"';
12914: }
12915: } else {
12916: if (exists($currhash{$domcoord[$i]})) {
12917: $check = ' checked="checked"';
1.125 raeburn 12918: }
12919: }
1.160.6.16 raeburn 12920: if ($i == @domcoord - 1) {
1.125 raeburn 12921: my $colsleft = $numinrow - $rem;
12922: if ($colsleft > 1) {
1.160.6.16 raeburn 12923: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 12924: } else {
1.160.6.16 raeburn 12925: $table .= '<td class="LC_left_item">';
1.125 raeburn 12926: }
12927: } else {
1.160.6.16 raeburn 12928: $table .= '<td class="LC_left_item">';
12929: }
12930: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
12931: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
12932: $table .= '<span class="LC_nobreak"><label>'.
12933: '<input type="'.$inputtype.'" name="'.$name.'"'.
12934: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
12935: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 12936: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 12937: }
1.160.6.33 raeburn 12938: $table .= '</label></span></td>';
1.125 raeburn 12939: }
1.160.6.16 raeburn 12940: $table .= '</tr></table>';
12941: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 12942: my ($dcname,$dcdom) = split(':',$domcoord[0]);
12943: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 12944: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 12945: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 12946: if ($user ne $dcname.':'.$dcdom) {
12947: $table .= ' ('.$dcname.':'.$dcdom.')';
12948: }
1.160.6.16 raeburn 12949: } else {
12950: my $check;
12951: if (exists($currhash{$domcoord[0]})) {
12952: $check = ' checked="checked"';
12953: }
1.160.6.50 raeburn 12954: $table = '<span class="LC_nobreak"><label>'.
12955: '<input type="checkbox" name="'.$name.'" '.
12956: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 12957: if ($user ne $dcname.':'.$dcdom) {
12958: $table .= ' ('.$dcname.':'.$dcdom.')';
12959: }
12960: $table .= '</label></span>';
1.160.6.16 raeburn 12961: $rows ++;
12962: }
1.125 raeburn 12963: }
1.160.6.16 raeburn 12964: return ($numdcs,$table,$rows);
1.125 raeburn 12965: }
12966:
1.137 raeburn 12967: sub usersession_titles {
12968: return &Apache::lonlocal::texthash(
12969: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
12970: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 12971: spares => 'Servers offloaded to, when busy',
1.137 raeburn 12972: version => 'LON-CAPA version requirement',
1.138 raeburn 12973: excludedomain => 'Allow all, but exclude specific domains',
12974: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 12975: primary => 'Primary (checked first)',
1.154 raeburn 12976: default => 'Default',
1.137 raeburn 12977: );
12978: }
12979:
1.152 raeburn 12980: sub id_for_thisdom {
12981: my (%servers) = @_;
12982: my %altids;
12983: foreach my $server (keys(%servers)) {
12984: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
12985: if ($serverhome ne $server) {
12986: $altids{$serverhome} = $server;
12987: }
12988: }
12989: return %altids;
12990: }
12991:
1.150 raeburn 12992: sub count_servers {
12993: my ($currbalancer,%servers) = @_;
12994: my (@spares,$numspares);
12995: foreach my $lonhost (sort(keys(%servers))) {
12996: next if ($currbalancer eq $lonhost);
12997: push(@spares,$lonhost);
12998: }
12999: if ($currbalancer) {
13000: $numspares = scalar(@spares);
13001: } else {
13002: $numspares = scalar(@spares) - 1;
13003: }
13004: return ($numspares,@spares);
13005: }
13006:
13007: sub lonbalance_targets_js {
1.160.6.7 raeburn 13008: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13009: my $select = &mt('Select');
13010: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13011: if (ref($servers) eq 'HASH') {
13012: $alltargets = join("','",sort(keys(%{$servers})));
13013: my @homedoms;
13014: foreach my $server (sort(keys(%{$servers}))) {
13015: if (&Apache::lonnet::host_domain($server) eq $dom) {
13016: push(@homedoms,'1');
13017: } else {
13018: push(@homedoms,'0');
13019: }
13020: }
13021: $allishome = join("','",@homedoms);
13022: }
13023: if (ref($types) eq 'ARRAY') {
13024: if (@{$types} > 0) {
13025: @alltypes = @{$types};
13026: }
13027: }
13028: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13029: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 13030: my (%currbalancer,%currtargets,%currrules,%existing);
13031: if (ref($settings) eq 'HASH') {
13032: %existing = %{$settings};
13033: }
13034: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13035: \%currtargets,\%currrules);
13036: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13037: return <<"END";
13038:
13039: <script type="text/javascript">
13040: // <![CDATA[
13041:
1.160.6.7 raeburn 13042: currBalancers = new Array('$balancers');
13043:
13044: function toggleTargets(balnum) {
13045: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13046: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13047: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13048: var prevbalancer = prevhostitem.value;
13049: var baltotal = document.getElementById('loadbalancing_total').value;
13050: prevhostitem.value = balancer;
13051: if (prevbalancer != '') {
13052: var prevIdx = currBalancers.indexOf(prevbalancer);
13053: if (prevIdx != -1) {
13054: currBalancers.splice(prevIdx,1);
13055: }
13056: }
1.150 raeburn 13057: if (balancer == '') {
1.160.6.7 raeburn 13058: hideSpares(balnum);
1.150 raeburn 13059: } else {
1.160.6.7 raeburn 13060: var currIdx = currBalancers.indexOf(balancer);
13061: if (currIdx == -1) {
13062: currBalancers.push(balancer);
13063: }
1.150 raeburn 13064: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 13065: var ishomedom = homedoms[lonhostitem.selectedIndex];
13066: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13067: }
1.160.6.7 raeburn 13068: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13069: return;
13070: }
13071:
1.160.6.7 raeburn 13072: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13073: var alltargets = new Array('$alltargets');
13074: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13075: var offloadtypes = new Array('primary','default');
13076:
1.160.6.7 raeburn 13077: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13078: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13079:
1.151 raeburn 13080: for (var i=0; i<offloadtypes.length; i++) {
13081: var count = 0;
13082: for (var j=0; j<alltargets.length; j++) {
13083: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 13084: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13085: item.value = alltargets[j];
13086: item.style.textAlign='left';
13087: item.style.textFace='normal';
13088: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13089: if (currBalancers.indexOf(alltargets[j]) == -1) {
13090: item.disabled = '';
13091: } else {
13092: item.disabled = 'disabled';
13093: item.checked = false;
13094: }
1.151 raeburn 13095: count ++;
13096: }
1.150 raeburn 13097: }
13098: }
1.151 raeburn 13099: for (var k=0; k<insttypes.length; k++) {
13100: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13101: if (ishomedom == 1) {
1.160.6.7 raeburn 13102: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13103: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13104: } else {
1.160.6.7 raeburn 13105: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13106: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13107: }
13108: } else {
1.160.6.7 raeburn 13109: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13110: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13111: }
1.151 raeburn 13112: if ((insttypes[k] != '_LC_external') &&
13113: ((insttypes[k] != '_LC_internetdom') ||
13114: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 13115: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13116: item.options.length = 0;
13117: item.options[0] = new Option("","",true,true);
13118: var idx = 0;
1.151 raeburn 13119: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 13120: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13121: idx ++;
13122: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13123: }
13124: }
13125: }
13126: }
13127: return;
13128: }
13129:
1.160.6.7 raeburn 13130: function hideSpares(balnum) {
1.150 raeburn 13131: var alltargets = new Array('$alltargets');
13132: var insttypes = new Array('$allinsttypes');
13133: var offloadtypes = new Array('primary','default');
13134:
1.160.6.7 raeburn 13135: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13136: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13137:
13138: var total = alltargets.length - 1;
13139: for (var i=0; i<offloadtypes; i++) {
13140: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 13141: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13142: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13143: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13144: }
1.150 raeburn 13145: }
13146: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 13147: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13148: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13149: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 13150: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13151: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13152: }
13153: }
13154: return;
13155: }
13156:
1.160.6.7 raeburn 13157: function checkOffloads(item,balnum,type) {
1.150 raeburn 13158: var alltargets = new Array('$alltargets');
13159: var offloadtypes = new Array('primary','default');
13160: if (item.checked) {
13161: var total = alltargets.length - 1;
13162: var other;
13163: if (type == offloadtypes[0]) {
1.151 raeburn 13164: other = offloadtypes[1];
1.150 raeburn 13165: } else {
1.151 raeburn 13166: other = offloadtypes[0];
1.150 raeburn 13167: }
13168: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 13169: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13170: if (server == item.value) {
1.160.6.7 raeburn 13171: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13172: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13173: }
13174: }
13175: }
13176: }
13177: return;
13178: }
13179:
1.160.6.7 raeburn 13180: function singleServerToggle(balnum,type) {
13181: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13182: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 13183: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13184: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13185:
13186: } else {
1.160.6.7 raeburn 13187: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13188: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13189: }
13190: return;
13191: }
13192:
1.160.6.7 raeburn 13193: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13194: if (type == '_LC_external') {
1.160.6.26 raeburn 13195: return;
1.150 raeburn 13196: }
1.160.6.7 raeburn 13197: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13198: for (var i=0; i<typesRules.length; i++) {
13199: if (formname.elements[typesRules[i]].checked) {
13200: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 13201: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13202: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13203: } else {
1.160.6.7 raeburn 13204: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13205: }
13206: }
13207: }
13208: return;
13209: }
13210:
13211: function balancerDeleteChange(balnum) {
13212: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13213: var baltotal = document.getElementById('loadbalancing_total').value;
13214: var addtarget;
13215: var removetarget;
13216: var action = 'delete';
13217: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13218: var lonhost = hostitem.value;
13219: var currIdx = currBalancers.indexOf(lonhost);
13220: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13221: if (currIdx != -1) {
13222: currBalancers.splice(currIdx,1);
13223: }
13224: addtarget = lonhost;
13225: } else {
13226: if (currIdx == -1) {
13227: currBalancers.push(lonhost);
13228: }
13229: removetarget = lonhost;
13230: action = 'undelete';
13231: }
13232: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13233: }
13234: return;
13235: }
13236:
13237: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13238: if (baltotal > 1) {
13239: var offloadtypes = new Array('primary','default');
13240: var alltargets = new Array('$alltargets');
13241: var insttypes = new Array('$allinsttypes');
13242: for (var i=0; i<baltotal; i++) {
13243: if (i != balnum) {
13244: for (var j=0; j<offloadtypes.length; j++) {
13245: var total = alltargets.length - 1;
13246: for (var k=0; k<total; k++) {
13247: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13248: var server = serveritem.value;
13249: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13250: if (server == addtarget) {
13251: serveritem.disabled = '';
13252: }
13253: }
13254: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13255: if (server == removetarget) {
13256: serveritem.disabled = 'disabled';
13257: serveritem.checked = false;
13258: }
13259: }
13260: }
13261: }
13262: for (var j=0; j<insttypes.length; j++) {
13263: if (insttypes[j] != '_LC_external') {
13264: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13265: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13266: var currSel = singleserver.selectedIndex;
13267: var currVal = singleserver.options[currSel].value;
13268: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13269: var numoptions = singleserver.options.length;
13270: var needsnew = 1;
13271: for (var k=0; k<numoptions; k++) {
13272: if (singleserver.options[k] == addtarget) {
13273: needsnew = 0;
13274: break;
13275: }
13276: }
13277: if (needsnew == 1) {
13278: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13279: }
13280: }
13281: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13282: singleserver.options.length = 0;
13283: if ((currVal) && (currVal != removetarget)) {
13284: singleserver.options[0] = new Option("","",false,false);
13285: } else {
13286: singleserver.options[0] = new Option("","",true,true);
13287: }
13288: var idx = 0;
13289: for (var m=0; m<alltargets.length; m++) {
13290: if (currBalancers.indexOf(alltargets[m]) == -1) {
13291: idx ++;
13292: if (currVal == alltargets[m]) {
13293: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13294: } else {
13295: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13296: }
13297: }
13298: }
13299: }
13300: }
13301: }
13302: }
1.150 raeburn 13303: }
13304: }
13305: }
13306: return;
13307: }
13308:
1.152 raeburn 13309: // ]]>
13310: </script>
13311:
13312: END
13313: }
13314:
13315: sub new_spares_js {
13316: my @sparestypes = ('primary','default');
13317: my $types = join("','",@sparestypes);
13318: my $select = &mt('Select');
13319: return <<"END";
13320:
13321: <script type="text/javascript">
13322: // <![CDATA[
13323:
13324: function updateNewSpares(formname,lonhost) {
13325: var types = new Array('$types');
13326: var include = new Array();
13327: var exclude = new Array();
13328: for (var i=0; i<types.length; i++) {
13329: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13330: for (var j=0; j<spareboxes.length; j++) {
13331: if (formname.elements[spareboxes[j]].checked) {
13332: exclude.push(formname.elements[spareboxes[j]].value);
13333: } else {
13334: include.push(formname.elements[spareboxes[j]].value);
13335: }
13336: }
13337: }
13338: for (var i=0; i<types.length; i++) {
13339: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13340: var selIdx = newSpare.selectedIndex;
13341: var currnew = newSpare.options[selIdx].value;
13342: var okSpares = new Array();
13343: for (var j=0; j<newSpare.options.length; j++) {
13344: var possible = newSpare.options[j].value;
13345: if (possible != '') {
13346: if (exclude.indexOf(possible) == -1) {
13347: okSpares.push(possible);
13348: } else {
13349: if (currnew == possible) {
13350: selIdx = 0;
13351: }
13352: }
13353: }
13354: }
13355: for (var k=0; k<include.length; k++) {
13356: if (okSpares.indexOf(include[k]) == -1) {
13357: okSpares.push(include[k]);
13358: }
13359: }
13360: okSpares.sort();
13361: newSpare.options.length = 0;
13362: if (selIdx == 0) {
13363: newSpare.options[0] = new Option("$select","",true,true);
13364: } else {
13365: newSpare.options[0] = new Option("$select","",false,false);
13366: }
13367: for (var m=0; m<okSpares.length; m++) {
13368: var idx = m+1;
13369: var selThis = 0;
13370: if (selIdx != 0) {
13371: if (okSpares[m] == currnew) {
13372: selThis = 1;
13373: }
13374: }
13375: if (selThis == 1) {
13376: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13377: } else {
13378: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13379: }
13380: }
13381: }
13382: return;
13383: }
13384:
13385: function checkNewSpares(lonhost,type) {
13386: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13387: var chosen = newSpare.options[newSpare.selectedIndex].value;
13388: if (chosen != '') {
13389: var othertype;
13390: var othernewSpare;
13391: if (type == 'primary') {
13392: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13393: }
13394: if (type == 'default') {
13395: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13396: }
13397: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13398: othernewSpare.selectedIndex = 0;
13399: }
13400: }
13401: return;
13402: }
13403:
13404: // ]]>
13405: </script>
13406:
13407: END
13408:
13409: }
13410:
13411: sub common_domprefs_js {
13412: return <<"END";
13413:
13414: <script type="text/javascript">
13415: // <![CDATA[
13416:
1.150 raeburn 13417: function getIndicesByName(formname,item) {
1.152 raeburn 13418: var group = new Array();
1.150 raeburn 13419: for (var i=0;i<formname.elements.length;i++) {
13420: if (formname.elements[i].name == item) {
1.152 raeburn 13421: group.push(formname.elements[i].id);
1.150 raeburn 13422: }
13423: }
1.152 raeburn 13424: return group;
1.150 raeburn 13425: }
13426:
13427: // ]]>
13428: </script>
13429:
13430: END
1.152 raeburn 13431:
1.150 raeburn 13432: }
13433:
1.160.6.5 raeburn 13434: sub recaptcha_js {
13435: my %lt = &captcha_phrases();
13436: return <<"END";
13437:
13438: <script type="text/javascript">
13439: // <![CDATA[
13440:
13441: function updateCaptcha(caller,context) {
13442: var privitem;
13443: var pubitem;
13444: var privtext;
13445: var pubtext;
1.160.6.69 raeburn 13446: var versionitem;
13447: var versiontext;
1.160.6.5 raeburn 13448: if (document.getElementById(context+'_recaptchapub')) {
13449: pubitem = document.getElementById(context+'_recaptchapub');
13450: } else {
13451: return;
13452: }
13453: if (document.getElementById(context+'_recaptchapriv')) {
13454: privitem = document.getElementById(context+'_recaptchapriv');
13455: } else {
13456: return;
13457: }
13458: if (document.getElementById(context+'_recaptchapubtxt')) {
13459: pubtext = document.getElementById(context+'_recaptchapubtxt');
13460: } else {
13461: return;
13462: }
13463: if (document.getElementById(context+'_recaptchaprivtxt')) {
13464: privtext = document.getElementById(context+'_recaptchaprivtxt');
13465: } else {
13466: return;
13467: }
1.160.6.69 raeburn 13468: if (document.getElementById(context+'_recaptchaversion')) {
13469: versionitem = document.getElementById(context+'_recaptchaversion');
13470: } else {
13471: return;
13472: }
13473: if (document.getElementById(context+'_recaptchavertxt')) {
13474: versiontext = document.getElementById(context+'_recaptchavertxt');
13475: } else {
13476: return;
13477: }
1.160.6.5 raeburn 13478: if (caller.checked) {
13479: if (caller.value == 'recaptcha') {
13480: pubitem.type = 'text';
13481: privitem.type = 'text';
13482: pubitem.size = '40';
13483: privitem.size = '40';
13484: pubtext.innerHTML = "$lt{'pub'}";
13485: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 13486: versionitem.type = 'text';
13487: versionitem.size = '3';
13488: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 13489: } else {
13490: pubitem.type = 'hidden';
13491: privitem.type = 'hidden';
1.160.6.69 raeburn 13492: versionitem.type = 'hidden';
1.160.6.5 raeburn 13493: pubtext.innerHTML = '';
13494: privtext.innerHTML = '';
1.160.6.69 raeburn 13495: versiontext.innerHTML = '';
1.160.6.5 raeburn 13496: }
13497: }
13498: return;
13499: }
13500:
13501: // ]]>
13502: </script>
13503:
13504: END
13505:
13506: }
13507:
1.160.6.40 raeburn 13508: sub toggle_display_js {
1.160.6.16 raeburn 13509: return <<"END";
13510:
13511: <script type="text/javascript">
13512: // <![CDATA[
13513:
1.160.6.40 raeburn 13514: function toggleDisplay(domForm,caller) {
13515: if (document.getElementById(caller)) {
13516: var divitem = document.getElementById(caller);
13517: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 13518: var checkval = 1;
13519: var dispval = 'block';
1.160.6.40 raeburn 13520: if (caller == 'emailoptions') {
13521: optionsElement = domForm.cancreate_email;
13522: }
1.160.6.57 raeburn 13523: if (caller == 'studentsubmission') {
13524: optionsElement = domForm.postsubmit;
13525: }
1.160.6.64 raeburn 13526: if (caller == 'cloneinstcode') {
13527: optionsElement = domForm.canclone;
13528: checkval = 'instcode';
13529: }
1.160.6.40 raeburn 13530: if (optionsElement.length) {
1.160.6.16 raeburn 13531: var currval;
1.160.6.40 raeburn 13532: for (var i=0; i<optionsElement.length; i++) {
13533: if (optionsElement[i].checked) {
13534: currval = optionsElement[i].value;
1.160.6.16 raeburn 13535: }
13536: }
1.160.6.64 raeburn 13537: if (currval == checkval) {
13538: divitem.style.display = dispval;
1.160.6.16 raeburn 13539: } else {
1.160.6.40 raeburn 13540: divitem.style.display = 'none';
1.160.6.16 raeburn 13541: }
13542: }
13543: }
13544: return;
13545: }
13546:
13547: // ]]>
13548: </script>
13549:
13550: END
13551:
13552: }
13553:
1.160.6.5 raeburn 13554: sub captcha_phrases {
13555: return &Apache::lonlocal::texthash (
13556: priv => 'Private key',
13557: pub => 'Public key',
13558: original => 'original (CAPTCHA)',
13559: recaptcha => 'successor (ReCAPTCHA)',
13560: notused => 'unused',
1.160.6.69 raeburn 13561: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 13562: );
13563: }
13564:
1.160.6.24 raeburn 13565: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 13566: my ($dom,$cachekeys) = @_;
13567: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 13568: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13569: my %thismachine;
13570: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.81 raeburn 13571: my @posscached = ('domainconfig','domdefaults','usersessions','directorysrch');
1.160.6.61 raeburn 13572: if (keys(%servers)) {
1.160.6.24 raeburn 13573: foreach my $server (keys(%servers)) {
13574: next if ($thismachine{$server});
1.160.6.27 raeburn 13575: my @cached;
13576: foreach my $name (@posscached) {
13577: if ($cachekeys->{$name}) {
13578: push(@cached,&escape($name).':'.&escape($dom));
13579: }
13580: }
13581: if (@cached) {
13582: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13583: }
1.160.6.24 raeburn 13584: }
13585: }
13586: return;
13587: }
13588:
1.3 raeburn 13589: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>