Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.96
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.96! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.95 2019/08/02 02:10:50 raeburn Exp $
1.160.6.40 raeburn 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.160.6.78 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
30: ##############################################################
31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 107: (official, unofficial, community, and textbook). In each case the radio buttons
108: allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.1 raeburn 177:
1.155 raeburn 178: my $registered_cleanup;
179: my $modified_urls;
180:
1.1 raeburn 181: sub handler {
182: my $r=shift;
183: if ($r->header_only) {
184: &Apache::loncommon::content_type($r,'text/html');
185: $r->send_http_header;
186: return OK;
187: }
188:
1.91 raeburn 189: my $context = 'domain';
1.1 raeburn 190: my $dom = $env{'request.role.domain'};
1.5 albertel 191: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 192: if (&Apache::lonnet::allowed('mau',$dom)) {
193: &Apache::loncommon::content_type($r,'text/html');
194: $r->send_http_header;
195: } else {
196: $env{'user.error.msg'}=
197: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
198: return HTTP_NOT_ACCEPTABLE;
199: }
1.155 raeburn 200:
201: $registered_cleanup=0;
202: @{$modified_urls}=();
203:
1.1 raeburn 204: &Apache::lonhtmlcommon::clear_breadcrumbs();
205: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 206: ['phase','actions']);
1.30 raeburn 207: my $phase = 'pickactions';
1.3 raeburn 208: if ( exists($env{'form.phase'}) ) {
209: $phase = $env{'form.phase'};
210: }
1.150 raeburn 211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 212: my %domconfig =
1.6 raeburn 213: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 214: 'quotas','autoenroll','autoupdate','autocreate',
215: 'directorysrch','usercreation','usermodification',
216: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 217: 'serverstatuses','requestcourses','helpsettings',
218: 'coursedefaults','usersessions','loadbalancing',
219: 'requestauthor','selfenrollment','inststatus'],$dom);
1.43 raeburn 220: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 221: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 222: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 223: 'requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 224: 'serverstatuses','helpsettings','coursedefaults',
225: 'selfenrollment','usersessions');
1.160.6.7 raeburn 226: my %existing;
227: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
228: %existing = %{$domconfig{'loadbalancing'}};
229: }
230: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 231: push(@prefs_order,'loadbalancing');
232: }
1.30 raeburn 233: my %prefs = (
234: 'rolecolors' =>
235: { text => 'Default color schemes',
1.67 raeburn 236: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 237: header => [{col1 => 'Student Settings',
238: col2 => '',},
239: {col1 => 'Coordinator Settings',
240: col2 => '',},
241: {col1 => 'Author Settings',
242: col2 => '',},
243: {col1 => 'Administrator Settings',
244: col2 => '',}],
1.160.6.37 raeburn 245: print => \&print_rolecolors,
246: modify => \&modify_rolecolors,
1.30 raeburn 247: },
1.110 raeburn 248: 'login' =>
1.30 raeburn 249: { text => 'Log-in page options',
1.67 raeburn 250: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 251: header => [{col1 => 'Log-in Page Items',
252: col2 => '',},
253: {col1 => 'Log-in Help',
1.160.6.56 raeburn 254: col2 => 'Value'},
255: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 256: col2 => 'Value'}],
1.160.6.37 raeburn 257: print => \&print_login,
258: modify => \&modify_login,
1.30 raeburn 259: },
1.43 raeburn 260: 'defaults' =>
1.160.6.40 raeburn 261: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 262: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 263: header => [{col1 => 'Setting',
1.160.6.40 raeburn 264: col2 => 'Value'},
1.160.6.80 raeburn 265: {col1 => 'Internal Authentication',
266: col2 => 'Value'},
1.160.6.40 raeburn 267: {col1 => 'Institutional user types',
1.160.6.93 raeburn 268: col2 => 'Name displayed'}],
1.160.6.37 raeburn 269: print => \&print_defaults,
270: modify => \&modify_defaults,
1.43 raeburn 271: },
1.30 raeburn 272: 'quotas' =>
1.160.6.20 raeburn 273: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 274: help => 'Domain_Configuration_Quotas',
1.77 raeburn 275: header => [{col1 => 'User affiliation',
1.72 raeburn 276: col2 => 'Available tools',
1.160.6.28 raeburn 277: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 278: print => \&print_quotas,
279: modify => \&modify_quotas,
1.30 raeburn 280: },
281: 'autoenroll' =>
282: { text => 'Auto-enrollment settings',
1.67 raeburn 283: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 284: header => [{col1 => 'Configuration setting',
285: col2 => 'Value(s)'}],
1.160.6.37 raeburn 286: print => \&print_autoenroll,
287: modify => \&modify_autoenroll,
1.30 raeburn 288: },
289: 'autoupdate' =>
290: { text => 'Auto-update settings',
1.67 raeburn 291: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 292: header => [{col1 => 'Setting',
293: col2 => 'Value',},
1.131 raeburn 294: {col1 => 'Setting',
295: col2 => 'Affiliation'},
1.43 raeburn 296: {col1 => 'User population',
1.160.6.35 raeburn 297: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 298: print => \&print_autoupdate,
299: modify => \&modify_autoupdate,
1.30 raeburn 300: },
1.125 raeburn 301: 'autocreate' =>
302: { text => 'Auto-course creation settings',
303: help => 'Domain_Configuration_Auto_Creation',
304: header => [{col1 => 'Configuration Setting',
305: col2 => 'Value',}],
1.160.6.37 raeburn 306: print => \&print_autocreate,
307: modify => \&modify_autocreate,
1.125 raeburn 308: },
1.30 raeburn 309: 'directorysrch' =>
1.160.6.72 raeburn 310: { text => 'Directory searches',
1.67 raeburn 311: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 312: header => [{col1 => 'Institutional Directory Setting',
313: col2 => 'Value',},
314: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 315: col2 => 'Value',}],
1.160.6.37 raeburn 316: print => \&print_directorysrch,
317: modify => \&modify_directorysrch,
1.30 raeburn 318: },
319: 'contacts' =>
1.160.6.78 raeburn 320: { text => 'E-mail addresses and helpform',
1.67 raeburn 321: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 322: header => [{col1 => 'Default e-mail addresses',
323: col2 => 'Value',},
324: {col1 => 'Recipient(s) for notifications',
325: col2 => 'Value',},
326: {col1 => 'Ask helpdesk form settings',
327: col2 => 'Value',},],
1.160.6.37 raeburn 328: print => \&print_contacts,
329: modify => \&modify_contacts,
1.30 raeburn 330: },
331: 'usercreation' =>
332: { text => 'User creation',
1.67 raeburn 333: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 334: header => [{col1 => 'Format rule type',
335: col2 => 'Format rules in force'},
1.34 raeburn 336: {col1 => 'User account creation',
337: col2 => 'Usernames which may be created',},
1.30 raeburn 338: {col1 => 'Context',
1.43 raeburn 339: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 340: print => \&print_usercreation,
341: modify => \&modify_usercreation,
1.30 raeburn 342: },
1.160.6.34 raeburn 343: 'selfcreation' =>
344: { text => 'Users self-creating accounts',
345: help => 'Domain_Configuration_Self_Creation',
346: header => [{col1 => 'Self-creation with institutional username',
347: col2 => 'Enabled?'},
348: {col1 => 'Institutional user type (login/SSO self-creation)',
349: col2 => 'Information user can enter'},
1.160.6.93 raeburn 350: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 351: col2 => 'Settings'}],
1.160.6.37 raeburn 352: print => \&print_selfcreation,
353: modify => \&modify_selfcreation,
1.160.6.34 raeburn 354: },
1.69 raeburn 355: 'usermodification' =>
1.33 raeburn 356: { text => 'User modification',
1.67 raeburn 357: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 358: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 359: col2 => 'User information updatable in author context'},
1.33 raeburn 360: {col1 => 'Target user has role',
1.160.6.35 raeburn 361: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 362: print => \&print_usermodification,
363: modify => \&modify_usermodification,
1.33 raeburn 364: },
1.69 raeburn 365: 'scantron' =>
1.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.93 raeburn 531: if (grep(/^selfcreation$/,@actions)) {
532: $js .= &selfcreate_javascript();
533: }
1.160.6.78 raeburn 534: if (grep(/^contacts$/,@actions)) {
535: $js .= &contacts_javascript();
536: }
1.150 raeburn 537: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 538: } else {
1.160.6.11 raeburn 539: # check if domconfig user exists for the domain.
540: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 541: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 542: &config_check($dom,$confname,$servadm);
543: unless ($configuserok eq 'ok') {
544: &Apache::lonconfigsettings::print_header($r,$phase,$context);
545: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
546: $confname).
547: '<br />'
548: );
549: if ($switchserver) {
550: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
551: '<br />'.
552: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
553: '<br />'.
554: &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).
555: '<br />'.
556: &mt('To do that now, use the following link: [_1]',$switchserver)
557: );
558: } else {
559: $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.').
560: '<br />'.
561: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
562: );
563: }
564: $r->print(&Apache::loncommon::end_page());
565: return OK;
566: }
1.21 raeburn 567: if (keys(%domconfig) == 0) {
568: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 569: my @ids=&Apache::lonnet::current_machine_ids();
570: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 571: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 572: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 573: my $custom_img_count = 0;
574: foreach my $img (@loginimages) {
575: if ($designhash{$dom.'.login.'.$img} ne '') {
576: $custom_img_count ++;
577: }
578: }
579: foreach my $role (@roles) {
580: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
581: $custom_img_count ++;
582: }
583: }
584: if ($custom_img_count > 0) {
1.94 raeburn 585: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 586: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 587: $r->print(
588: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
589: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
590: &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 />'.
591: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
592: if ($switch_server) {
1.30 raeburn 593: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 594: }
1.91 raeburn 595: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 596: return OK;
597: }
598: }
599: }
1.91 raeburn 600: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 601: }
602: return OK;
603: }
604:
605: sub process_changes {
1.160.6.24 raeburn 606: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 607: my %domconfig;
608: if (ref($values) eq 'HASH') {
609: %domconfig = %{$values};
610: }
1.3 raeburn 611: my $output;
612: if ($action eq 'login') {
1.160.6.24 raeburn 613: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 614: } elsif ($action eq 'rolecolors') {
1.9 raeburn 615: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 616: $lastactref,%domconfig);
1.3 raeburn 617: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 618: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 619: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 620: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 621: } elsif ($action eq 'autoupdate') {
622: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 623: } elsif ($action eq 'autocreate') {
624: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 625: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 626: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 627: } elsif ($action eq 'usercreation') {
1.28 raeburn 628: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 629: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 630: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 631: } elsif ($action eq 'usermodification') {
632: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 633: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 634: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 635: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 636: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 637: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 638: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 639: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 640: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 641: } elsif ($action eq 'serverstatuses') {
642: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 643: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 644: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 645: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 646: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 647: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 648: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 649: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 650: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 651: } elsif ($action eq 'selfenrollment') {
652: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 653: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 654: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 655: } elsif ($action eq 'loadbalancing') {
656: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 657: }
658: return $output;
659: }
660:
661: sub print_config_box {
1.9 raeburn 662: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 663: my $rowtotal = 0;
1.49 raeburn 664: my $output;
665: if ($action eq 'coursecategories') {
666: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 667: } elsif ($action eq 'defaults') {
668: $output = &defaults_javascript($settings);
1.160.6.73 raeburn 669: } elsif ($action eq 'helpsettings') {
670: my (%privs,%levelscurrent);
671: my %full=();
672: my %levels=(
673: course => {},
674: domain => {},
675: system => {},
676: );
677: my $context = 'domain';
678: my $crstype = 'Course';
679: my $formname = 'display';
680: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
681: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
682: $output =
683: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
684: \@templateroles);
1.91 raeburn 685: }
1.160.6.40 raeburn 686: $output .=
1.30 raeburn 687: '<table class="LC_nested_outer">
1.3 raeburn 688: <tr>
1.66 raeburn 689: <th align="left" valign="middle"><span class="LC_nobreak">'.
690: &mt($item->{text}).' '.
691: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
692: '</tr>';
1.30 raeburn 693: $rowtotal ++;
1.110 raeburn 694: my $numheaders = 1;
695: if (ref($item->{'header'}) eq 'ARRAY') {
696: $numheaders = scalar(@{$item->{'header'}});
697: }
698: if ($numheaders > 1) {
1.64 raeburn 699: my $colspan = '';
1.145 raeburn 700: my $rightcolspan = '';
1.160.6.42 raeburn 701: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 702: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 703: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 704: $colspan = ' colspan="2"';
705: }
1.145 raeburn 706: if ($action eq 'usersessions') {
707: $rightcolspan = ' colspan="3"';
708: }
1.30 raeburn 709: $output .= '
1.3 raeburn 710: <tr>
711: <td>
712: <table class="LC_nested">
713: <tr class="LC_info_row">
1.59 bisitz 714: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 715: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 716: </tr>';
1.69 raeburn 717: $rowtotal ++;
1.160.6.37 raeburn 718: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 719: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 720: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78 raeburn 721: ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37 raeburn 722: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 723: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 724: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 725: } elsif ($action eq 'login') {
1.160.6.56 raeburn 726: if ($numheaders == 4) {
1.160.6.5 raeburn 727: $colspan = ' colspan="2"';
728: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
729: } else {
730: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
731: }
1.160.6.37 raeburn 732: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 733: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 734: } elsif ($action eq 'rolecolors') {
1.30 raeburn 735: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 736: }
1.30 raeburn 737: $output .= '
1.6 raeburn 738: </table>
739: </td>
740: </tr>
741: <tr>
742: <td>
743: <table class="LC_nested">
744: <tr class="LC_info_row">
1.160.6.37 raeburn 745: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 746: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 747: </tr>';
748: $rowtotal ++;
1.160.6.37 raeburn 749: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
750: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 751: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.80 raeburn 752: ($action eq 'contacts') || ($action eq 'defaults')) {
1.160.6.42 raeburn 753: if ($action eq 'coursecategories') {
754: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
755: $colspan = ' colspan="2"';
756: } else {
757: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
758: }
759: $output .= '
1.63 raeburn 760: </table>
761: </td>
762: </tr>
763: <tr>
764: <td>
765: <table class="LC_nested">
766: <tr class="LC_info_row">
767: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 768: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 769: </tr>'."\n";
770: if ($action eq 'coursecategories') {
771: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
772: } else {
773: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
774: }
1.63 raeburn 775: $rowtotal ++;
1.160.6.57 raeburn 776: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 777: ($action eq 'defaults') || ($action eq 'directorysrch') ||
778: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 779: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 780: } elsif ($action eq 'login') {
1.160.6.56 raeburn 781: if ($numheaders == 4) {
1.160.6.5 raeburn 782: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
783: </table>
784: </td>
785: </tr>
786: <tr>
787: <td>
788: <table class="LC_nested">
789: <tr class="LC_info_row">
790: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 791: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 792: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
793: $rowtotal ++;
794: } else {
795: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
796: }
1.160.6.56 raeburn 797: $output .= '
798: </table>
799: </td>
800: </tr>
801: <tr>
802: <td>
803: <table class="LC_nested">
804: <tr class="LC_info_row">';
805: if ($numheaders == 4) {
806: $output .= '
807: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
808: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
809: </tr>';
810: } else {
811: $output .= '
812: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
813: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
814: </tr>';
815: }
816: $rowtotal ++;
817: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 818: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 819: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
820: $rowtotal ++;
821: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 822: </table>
823: </td>
824: </tr>
825: <tr>
826: <td>
827: <table class="LC_nested">
828: <tr class="LC_info_row">
829: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
830: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 831: &textbookcourses_javascript($settings).
832: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
833: </table>
834: </td>
835: </tr>
836: <tr>
837: <td>
838: <table class="LC_nested">
839: <tr class="LC_info_row">
840: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
841: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
842: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 843: </table>
844: </td>
845: </tr>
846: <tr>
847: <td>
848: <table class="LC_nested">
849: <tr class="LC_info_row">
1.160.6.46 raeburn 850: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
851: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 852: </tr>'.
853: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 854: } elsif ($action eq 'requestauthor') {
855: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 856: $rowtotal ++;
1.122 jms 857: } elsif ($action eq 'rolecolors') {
1.30 raeburn 858: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 859: </table>
860: </td>
861: </tr>
862: <tr>
863: <td>
864: <table class="LC_nested">
865: <tr class="LC_info_row">
1.69 raeburn 866: <td class="LC_left_item"'.$colspan.' valign="top">'.
867: &mt($item->{'header'}->[2]->{'col1'}).'</td>
868: <td class="LC_right_item" valign="top">'.
869: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 870: </tr>'.
1.30 raeburn 871: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 872: </table>
873: </td>
874: </tr>
875: <tr>
876: <td>
877: <table class="LC_nested">
878: <tr class="LC_info_row">
1.59 bisitz 879: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
880: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 881: </tr>'.
1.30 raeburn 882: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
883: $rowtotal += 2;
1.6 raeburn 884: }
1.3 raeburn 885: } else {
1.30 raeburn 886: $output .= '
1.3 raeburn 887: <tr>
888: <td>
889: <table class="LC_nested">
1.30 raeburn 890: <tr class="LC_info_row">';
1.160.6.72 raeburn 891: if ($action eq 'login') {
1.30 raeburn 892: $output .= '
1.59 bisitz 893: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 894: } elsif ($action eq 'serverstatuses') {
895: $output .= '
896: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
897: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
898:
1.6 raeburn 899: } else {
1.30 raeburn 900: $output .= '
1.69 raeburn 901: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
902: }
1.72 raeburn 903: if (defined($item->{'header'}->[0]->{'col3'})) {
904: $output .= '<td class="LC_left_item" valign="top">'.
905: &mt($item->{'header'}->[0]->{'col2'});
906: if ($action eq 'serverstatuses') {
907: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
908: }
1.69 raeburn 909: } else {
910: $output .= '<td class="LC_right_item" valign="top">'.
911: &mt($item->{'header'}->[0]->{'col2'});
912: }
913: $output .= '</td>';
914: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 915: if (defined($item->{'header'}->[0]->{'col4'})) {
916: $output .= '<td class="LC_left_item" valign="top">'.
917: &mt($item->{'header'}->[0]->{'col3'});
918: } else {
919: $output .= '<td class="LC_right_item" valign="top">'.
920: &mt($item->{'header'}->[0]->{'col3'});
921: }
1.69 raeburn 922: if ($action eq 'serverstatuses') {
923: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
924: }
925: $output .= '</td>';
1.6 raeburn 926: }
1.150 raeburn 927: if ($item->{'header'}->[0]->{'col4'}) {
928: $output .= '<td class="LC_right_item" valign="top">'.
929: &mt($item->{'header'}->[0]->{'col4'});
930: }
1.69 raeburn 931: $output .= '</tr>';
1.48 raeburn 932: $rowtotal ++;
1.160.6.5 raeburn 933: if ($action eq 'quotas') {
1.86 raeburn 934: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 935: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.78 raeburn 936: ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 937: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 938: } elsif ($action eq 'scantron') {
939: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 940: }
1.3 raeburn 941: }
1.30 raeburn 942: $output .= '
1.3 raeburn 943: </table>
944: </td>
945: </tr>
1.30 raeburn 946: </table><br />';
947: return ($output,$rowtotal);
1.1 raeburn 948: }
949:
1.3 raeburn 950: sub print_login {
1.160.6.5 raeburn 951: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 952: my ($css_class,$datatable);
1.6 raeburn 953: my %choices = &login_choices();
1.110 raeburn 954:
1.160.6.5 raeburn 955: if ($caller eq 'service') {
1.149 raeburn 956: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 957: my $choice = $choices{'disallowlogin'};
958: $css_class = ' class="LC_odd_row"';
1.128 raeburn 959: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 960: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 961: '<th>'.$choices{'server'}.'</th>'.
962: '<th>'.$choices{'serverpath'}.'</th>'.
963: '<th>'.$choices{'custompath'}.'</th>'.
964: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 965: my %disallowed;
966: if (ref($settings) eq 'HASH') {
967: if (ref($settings->{'loginvia'}) eq 'HASH') {
968: %disallowed = %{$settings->{'loginvia'}};
969: }
970: }
971: foreach my $lonhost (sort(keys(%servers))) {
972: my $direct = 'selected="selected"';
1.128 raeburn 973: if (ref($disallowed{$lonhost}) eq 'HASH') {
974: if ($disallowed{$lonhost}{'server'} ne '') {
975: $direct = '';
976: }
1.110 raeburn 977: }
1.115 raeburn 978: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 979: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 980: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
981: '</option>';
1.160.6.13 raeburn 982: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 983: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 984: my $selected = '';
1.128 raeburn 985: if (ref($disallowed{$lonhost}) eq 'HASH') {
986: if ($hostid eq $disallowed{$lonhost}{'server'}) {
987: $selected = 'selected="selected"';
988: }
1.110 raeburn 989: }
990: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
991: $servers{$hostid}.'</option>';
992: }
1.128 raeburn 993: $datatable .= '</select></td>'.
994: '<td><select name="'.$lonhost.'_serverpath">';
995: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
996: my $pathname = $path;
997: if ($path eq 'custom') {
998: $pathname = &mt('Custom Path').' ->';
999: }
1000: my $selected = '';
1001: if (ref($disallowed{$lonhost}) eq 'HASH') {
1002: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1003: $selected = 'selected="selected"';
1004: }
1005: } elsif ($path eq '') {
1006: $selected = 'selected="selected"';
1007: }
1008: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1009: }
1010: $datatable .= '</select></td>';
1011: my ($custom,$exempt);
1012: if (ref($disallowed{$lonhost}) eq 'HASH') {
1013: $custom = $disallowed{$lonhost}{'custompath'};
1014: $exempt = $disallowed{$lonhost}{'exempt'};
1015: }
1016: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1017: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1018: '</tr>';
1.110 raeburn 1019: }
1020: $datatable .= '</table></td></tr>';
1021: return $datatable;
1.160.6.5 raeburn 1022: } elsif ($caller eq 'page') {
1023: my %defaultchecked = (
1024: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1025: 'helpdesk' => 'on',
1.160.6.5 raeburn 1026: 'adminmail' => 'off',
1027: 'newuser' => 'off',
1028: );
1.160.6.14 raeburn 1029: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1030: my (%checkedon,%checkedoff);
1.42 raeburn 1031: foreach my $item (@toggles) {
1.160.6.5 raeburn 1032: if ($defaultchecked{$item} eq 'on') {
1033: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1034: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1035: } elsif ($defaultchecked{$item} eq 'off') {
1036: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1037: $checkedon{$item} = ' ';
1038: }
1.1 raeburn 1039: }
1.160.6.5 raeburn 1040: my @images = ('img','logo','domlogo','login');
1041: my @logintext = ('textcol','bgcol');
1042: my @bgs = ('pgbg','mainbg','sidebg');
1043: my @links = ('link','alink','vlink');
1044: my %designhash = &Apache::loncommon::get_domainconf($dom);
1045: my %defaultdesign = %Apache::loncommon::defaultdesign;
1046: my (%is_custom,%designs);
1047: my %defaults = (
1048: font => $defaultdesign{'login.font'},
1049: );
1.6 raeburn 1050: foreach my $item (@images) {
1.160.6.5 raeburn 1051: $defaults{$item} = $defaultdesign{'login.'.$item};
1052: $defaults{'showlogo'}{$item} = 1;
1053: }
1054: foreach my $item (@bgs) {
1055: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1056: }
1.41 raeburn 1057: foreach my $item (@logintext) {
1.160.6.5 raeburn 1058: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1059: }
1.160.6.5 raeburn 1060: foreach my $item (@links) {
1061: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1062: }
1.160.6.5 raeburn 1063: if (ref($settings) eq 'HASH') {
1064: foreach my $item (@toggles) {
1065: if ($settings->{$item} eq '1') {
1066: $checkedon{$item} = ' checked="checked" ';
1067: $checkedoff{$item} = ' ';
1068: } elsif ($settings->{$item} eq '0') {
1069: $checkedoff{$item} = ' checked="checked" ';
1070: $checkedon{$item} = ' ';
1071: }
1.6 raeburn 1072: }
1.160.6.5 raeburn 1073: foreach my $item (@images) {
1074: if (defined($settings->{$item})) {
1075: $designs{$item} = $settings->{$item};
1076: $is_custom{$item} = 1;
1077: }
1078: if (defined($settings->{'showlogo'}{$item})) {
1079: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1080: }
1081: }
1082: foreach my $item (@logintext) {
1083: if ($settings->{$item} ne '') {
1084: $designs{'logintext'}{$item} = $settings->{$item};
1085: $is_custom{$item} = 1;
1086: }
1087: }
1088: if ($settings->{'font'} ne '') {
1089: $designs{'font'} = $settings->{'font'};
1090: $is_custom{'font'} = 1;
1091: }
1092: foreach my $item (@bgs) {
1093: if ($settings->{$item} ne '') {
1094: $designs{'bgs'}{$item} = $settings->{$item};
1095: $is_custom{$item} = 1;
1096: }
1097: }
1098: foreach my $item (@links) {
1099: if ($settings->{$item} ne '') {
1100: $designs{'links'}{$item} = $settings->{$item};
1101: $is_custom{$item} = 1;
1102: }
1103: }
1104: } else {
1105: if ($designhash{$dom.'.login.font'} ne '') {
1106: $designs{'font'} = $designhash{$dom.'.login.font'};
1107: $is_custom{'font'} = 1;
1108: }
1109: foreach my $item (@images) {
1110: if ($designhash{$dom.'.login.'.$item} ne '') {
1111: $designs{$item} = $designhash{$dom.'.login.'.$item};
1112: $is_custom{$item} = 1;
1113: }
1114: }
1115: foreach my $item (@bgs) {
1116: if ($designhash{$dom.'.login.'.$item} ne '') {
1117: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1118: $is_custom{$item} = 1;
1119: }
1120: }
1121: foreach my $item (@links) {
1122: if ($designhash{$dom.'.login.'.$item} ne '') {
1123: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1124: $is_custom{$item} = 1;
1125: }
1.6 raeburn 1126: }
1127: }
1.160.6.5 raeburn 1128: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1129: logo => 'Institution Logo',
1130: domlogo => 'Domain Logo',
1131: login => 'Login box');
1132: my $itemcount = 1;
1133: foreach my $item (@toggles) {
1134: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1135: $datatable .=
1136: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1137: '</td><td>'.
1138: '<span class="LC_nobreak"><label><input type="radio" name="'.
1139: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1140: '</label> <label><input type="radio" name="'.$item.'"'.
1141: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1142: '</tr>';
1143: $itemcount ++;
1.6 raeburn 1144: }
1.160.6.5 raeburn 1145: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1146: $datatable .= '</tr></table></td></tr>';
1147: } elsif ($caller eq 'help') {
1148: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1149: my $switchserver = &check_switchserver($dom,$confname);
1150: my $itemcount = 1;
1151: $defaulturl = '/adm/loginproblems.html';
1152: $defaulttype = 'default';
1153: %lt = &Apache::lonlocal::texthash (
1154: del => 'Delete?',
1155: rep => 'Replace:',
1156: upl => 'Upload:',
1157: default => 'Default',
1158: custom => 'Custom',
1159: );
1160: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1161: my @currlangs;
1162: if (ref($settings) eq 'HASH') {
1163: if (ref($settings->{'helpurl'}) eq 'HASH') {
1164: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1165: next if ($settings->{'helpurl'}{$key} eq '');
1166: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1167: $type{$key} = 'custom';
1168: unless ($key eq 'nolang') {
1169: push(@currlangs,$key);
1170: }
1171: }
1172: } elsif ($settings->{'helpurl'} ne '') {
1173: $type{'nolang'} = 'custom';
1174: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1175: }
1176: }
1.160.6.5 raeburn 1177: foreach my $lang ('nolang',sort(@currlangs)) {
1178: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1179: $datatable .= '<tr'.$css_class.'>';
1180: if ($url{$lang} eq '') {
1181: $url{$lang} = $defaulturl;
1182: }
1183: if ($type{$lang} eq '') {
1184: $type{$lang} = $defaulttype;
1185: }
1186: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1187: if ($lang eq 'nolang') {
1188: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1189: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1190: } else {
1191: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1192: $langchoices{$lang},
1193: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1194: }
1195: $datatable .= '</span></td>'."\n".
1196: '<td class="LC_left_item">';
1197: if ($type{$lang} eq 'custom') {
1198: $datatable .= '<span class="LC_nobreak"><label>'.
1199: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1200: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1201: } else {
1202: $datatable .= $lt{'upl'};
1203: }
1204: $datatable .='<br />';
1205: if ($switchserver) {
1206: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1207: } else {
1208: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1209: }
1.160.6.5 raeburn 1210: $datatable .= '</td></tr>';
1211: $itemcount ++;
1.6 raeburn 1212: }
1.160.6.5 raeburn 1213: my @addlangs;
1214: foreach my $lang (sort(keys(%langchoices))) {
1215: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1216: push(@addlangs,$lang);
1217: }
1218: if (@addlangs > 0) {
1219: my %toadd;
1220: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1221: $toadd{''} = &mt('Select');
1222: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1223: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1224: &mt('Add log-in help page for a specific language:').' '.
1225: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1226: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1227: if ($switchserver) {
1228: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1229: } else {
1230: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1231: }
1.160.6.5 raeburn 1232: $datatable .= '</td></tr>';
1233: $itemcount ++;
1.6 raeburn 1234: }
1.160.6.5 raeburn 1235: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1236: } elsif ($caller eq 'headtag') {
1237: my %domservers = &Apache::lonnet::get_servers($dom);
1238: my $choice = $choices{'headtag'};
1239: $css_class = ' class="LC_odd_row"';
1240: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1241: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1242: '<th>'.$choices{'current'}.'</th>'.
1243: '<th>'.$choices{'action'}.'</th>'.
1244: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1245: my (%currurls,%currexempt);
1246: if (ref($settings) eq 'HASH') {
1247: if (ref($settings->{'headtag'}) eq 'HASH') {
1248: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1249: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1250: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1251: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1252: }
1253: }
1254: }
1255: }
1256: my %lt = &Apache::lonlocal::texthash(
1257: del => 'Delete?',
1258: rep => 'Replace:',
1259: upl => 'Upload:',
1260: curr => 'View contents',
1261: none => 'None',
1262: );
1263: my $switchserver = &check_switchserver($dom,$confname);
1264: foreach my $lonhost (sort(keys(%domservers))) {
1265: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1266: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1267: if ($currurls{$lonhost}) {
1268: $datatable .= '<td class="LC_right_item"><a href="'.
1269: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1270: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1271: '">'.$lt{'curr'}.'</a></td>'.
1272: '<td><span class="LC_nobreak"><label>'.
1273: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1274: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1275: } else {
1276: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1277: }
1278: $datatable .='<br />';
1279: if ($switchserver) {
1280: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1281: } else {
1282: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1283: }
1.160.6.87 raeburn 1284: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1285: }
1286: $datatable .= '</table></td></tr>';
1.1 raeburn 1287: }
1.6 raeburn 1288: return $datatable;
1289: }
1290:
1291: sub login_choices {
1292: my %choices =
1293: &Apache::lonlocal::texthash (
1.116 bisitz 1294: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1295: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1296: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1297: disallowlogin => "Login page requests redirected",
1298: hostid => "Server",
1.128 raeburn 1299: server => "Redirect to:",
1300: serverpath => "Path",
1301: custompath => "Custom",
1302: exempt => "Exempt IP(s)",
1.110 raeburn 1303: directlogin => "No redirect",
1304: newuser => "Link to create a user account",
1305: img => "Header",
1306: logo => "Main Logo",
1307: domlogo => "Domain Logo",
1308: login => "Log-in Header",
1309: textcol => "Text color",
1310: bgcol => "Box color",
1311: bgs => "Background colors",
1312: links => "Link colors",
1313: font => "Font color",
1314: pgbg => "Header",
1315: mainbg => "Page",
1316: sidebg => "Login box",
1317: link => "Link",
1318: alink => "Active link",
1319: vlink => "Visited link",
1.160.6.56 raeburn 1320: headtag => "Custom markup",
1321: action => "Action",
1322: current => "Current",
1.6 raeburn 1323: );
1324: return %choices;
1325: }
1326:
1327: sub print_rolecolors {
1.30 raeburn 1328: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1329: my %choices = &color_font_choices();
1330: my @bgs = ('pgbg','tabbg','sidebg');
1331: my @links = ('link','alink','vlink');
1332: my @images = ('img');
1333: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1334: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1335: my %defaultdesign = %Apache::loncommon::defaultdesign;
1336: my (%is_custom,%designs);
1.160.6.22 raeburn 1337: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1338: if (ref($settings) eq 'HASH') {
1339: if (ref($settings->{$role}) eq 'HASH') {
1340: if ($settings->{$role}->{'img'} ne '') {
1341: $designs{'img'} = $settings->{$role}->{'img'};
1342: $is_custom{'img'} = 1;
1343: }
1344: if ($settings->{$role}->{'font'} ne '') {
1345: $designs{'font'} = $settings->{$role}->{'font'};
1346: $is_custom{'font'} = 1;
1347: }
1.97 tempelho 1348: if ($settings->{$role}->{'fontmenu'} ne '') {
1349: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1350: $is_custom{'fontmenu'} = 1;
1351: }
1.6 raeburn 1352: foreach my $item (@bgs) {
1353: if ($settings->{$role}->{$item} ne '') {
1354: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1355: $is_custom{$item} = 1;
1356: }
1357: }
1358: foreach my $item (@links) {
1359: if ($settings->{$role}->{$item} ne '') {
1360: $designs{'links'}{$item} = $settings->{$role}->{$item};
1361: $is_custom{$item} = 1;
1362: }
1363: }
1364: }
1365: } else {
1366: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1367: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1368: $is_custom{'img'} = 1;
1369: }
1.97 tempelho 1370: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1371: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1372: $is_custom{'fontmenu'} = 1;
1373: }
1.6 raeburn 1374: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1375: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1376: $is_custom{'font'} = 1;
1377: }
1378: foreach my $item (@bgs) {
1379: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1380: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1381: $is_custom{$item} = 1;
1382:
1383: }
1384: }
1385: foreach my $item (@links) {
1386: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1387: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1388: $is_custom{$item} = 1;
1389: }
1390: }
1391: }
1392: my $itemcount = 1;
1.30 raeburn 1393: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1394: $datatable .= '</tr></table></td></tr>';
1395: return $datatable;
1396: }
1397:
1.160.6.22 raeburn 1398: sub role_defaults {
1399: my ($role,$bgs,$links,$images,$logintext) = @_;
1400: my %defaults;
1401: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1402: return %defaults;
1403: }
1404: my %defaultdesign = %Apache::loncommon::defaultdesign;
1405: if ($role eq 'login') {
1406: %defaults = (
1407: font => $defaultdesign{$role.'.font'},
1408: );
1409: if (ref($logintext) eq 'ARRAY') {
1410: foreach my $item (@{$logintext}) {
1411: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1412: }
1413: }
1414: foreach my $item (@{$images}) {
1415: $defaults{'showlogo'}{$item} = 1;
1416: }
1417: } else {
1418: %defaults = (
1419: img => $defaultdesign{$role.'.img'},
1420: font => $defaultdesign{$role.'.font'},
1421: fontmenu => $defaultdesign{$role.'.fontmenu'},
1422: );
1423: }
1424: foreach my $item (@{$bgs}) {
1425: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1426: }
1427: foreach my $item (@{$links}) {
1428: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1429: }
1430: foreach my $item (@{$images}) {
1431: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1432: }
1433: return %defaults;
1434: }
1435:
1.6 raeburn 1436: sub display_color_options {
1.9 raeburn 1437: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1438: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1439: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1440: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1441: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1442: '<td>'.$choices->{'font'}.'</td>';
1443: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1444: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1445: } else {
1446: $datatable .= '<td> </td>';
1447: }
1.160.6.9 raeburn 1448: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1449:
1.8 raeburn 1450: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1451: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1452: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1453: ' </span></td></tr>';
1.107 raeburn 1454: unless ($role eq 'login') {
1455: $datatable .= '<tr'.$css_class.'>'.
1456: '<td>'.$choices->{'fontmenu'}.'</td>';
1457: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1458: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1459: } else {
1460: $datatable .= '<td> </td>';
1461: }
1.160.6.22 raeburn 1462: $current_color = $designs->{'fontmenu'} ?
1463: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1464: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1465: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1466: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1467: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1468: ' </span></td></tr>';
1.97 tempelho 1469: }
1.9 raeburn 1470: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1471: foreach my $img (@{$images}) {
1.18 albertel 1472: $itemcount ++;
1.6 raeburn 1473: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1474: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1475: '<td>'.$choices->{$img};
1.41 raeburn 1476: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1477: if ($role eq 'login') {
1478: if ($img eq 'login') {
1479: $login_hdr_pick =
1.135 bisitz 1480: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1481: $logincolors =
1482: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1483: $designs,$defaults);
1.70 raeburn 1484: } elsif ($img ne 'domlogo') {
1485: $datatable.= &logo_display_options($img,$defaults,$designs);
1486: }
1487: }
1488: $datatable .= '</td>';
1.6 raeburn 1489: if ($designs->{$img} ne '') {
1490: $imgfile = $designs->{$img};
1.18 albertel 1491: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1492: } else {
1493: $imgfile = $defaults->{$img};
1494: }
1495: if ($imgfile) {
1.9 raeburn 1496: my ($showfile,$fullsize);
1497: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1498: my $urldir = $1;
1499: my $filename = $2;
1500: my @info = &Apache::lonnet::stat_file($designs->{$img});
1501: if (@info) {
1502: my $thumbfile = 'tn-'.$filename;
1503: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1504: if (@thumb) {
1505: $showfile = $urldir.'/'.$thumbfile;
1506: } else {
1507: $showfile = $imgfile;
1508: }
1509: } else {
1510: $showfile = '';
1511: }
1512: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1513: $showfile = $imgfile;
1.6 raeburn 1514: my $imgdir = $1;
1515: my $filename = $2;
1.159 raeburn 1516: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1517: $showfile = "/$imgdir/tn-".$filename;
1518: } else {
1.159 raeburn 1519: my $input = $londocroot.$imgfile;
1520: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1521: if (!-e $output) {
1.9 raeburn 1522: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1523: my ($fullwidth,$fullheight) = &check_dimensions($input);
1524: if ($fullwidth ne '' && $fullheight ne '') {
1525: if ($fullwidth > $width && $fullheight > $height) {
1526: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1527: my @args = ('convert','-sample',$size,$input,$output);
1528: system({$args[0]} @args);
1.159 raeburn 1529: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1530: }
1531: }
1.6 raeburn 1532: }
1533: }
1.16 raeburn 1534: }
1.6 raeburn 1535: if ($showfile) {
1.40 raeburn 1536: if ($showfile =~ m{^/(adm|res)/}) {
1537: if ($showfile =~ m{^/res/}) {
1538: my $local_showfile =
1539: &Apache::lonnet::filelocation('',$showfile);
1540: &Apache::lonnet::repcopy($local_showfile);
1541: }
1542: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1543: }
1544: if ($imgfile) {
1545: if ($imgfile =~ m{^/(adm|res)/}) {
1546: if ($imgfile =~ m{^/res/}) {
1547: my $local_imgfile =
1548: &Apache::lonnet::filelocation('',$imgfile);
1549: &Apache::lonnet::repcopy($local_imgfile);
1550: }
1551: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1552: } else {
1553: $fullsize = $imgfile;
1554: }
1555: }
1.41 raeburn 1556: $datatable .= '<td>';
1557: if ($img eq 'login') {
1.135 bisitz 1558: $datatable .= $login_hdr_pick;
1559: }
1.41 raeburn 1560: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1561: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1562: } else {
1.160.6.22 raeburn 1563: $datatable .= '<td> </td><td class="LC_left_item">'.
1564: &mt('Upload:').'<br />';
1.6 raeburn 1565: }
1566: } else {
1.160.6.22 raeburn 1567: $datatable .= '<td> </td><td class="LC_left_item">'.
1568: &mt('Upload:').'<br />';
1.6 raeburn 1569: }
1.9 raeburn 1570: if ($switchserver) {
1571: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1572: } else {
1.135 bisitz 1573: if ($img ne 'login') { # suppress file selection for Log-in header
1574: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1575: }
1.9 raeburn 1576: }
1577: $datatable .= '</td></tr>';
1.6 raeburn 1578: }
1579: $itemcount ++;
1580: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1581: $datatable .= '<tr'.$css_class.'>'.
1582: '<td>'.$choices->{'bgs'}.'</td>';
1583: my $bgs_def;
1584: foreach my $item (@{$bgs}) {
1585: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1586: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1587: }
1588: }
1589: if ($bgs_def) {
1.8 raeburn 1590: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1591: } else {
1592: $datatable .= '<td> </td>';
1593: }
1594: $datatable .= '<td class="LC_right_item">'.
1595: '<table border="0"><tr>';
1.160.6.13 raeburn 1596:
1.6 raeburn 1597: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1598: $datatable .= '<td align="center">'.$choices->{$item};
1599: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1600: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1601: $datatable .= ' ';
1.6 raeburn 1602: }
1.160.6.9 raeburn 1603: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1604: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1605: }
1606: $datatable .= '</tr></table></td></tr>';
1607: $itemcount ++;
1608: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1609: $datatable .= '<tr'.$css_class.'>'.
1610: '<td>'.$choices->{'links'}.'</td>';
1611: my $links_def;
1612: foreach my $item (@{$links}) {
1613: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1614: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1615: }
1616: }
1617: if ($links_def) {
1.8 raeburn 1618: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1619: } else {
1620: $datatable .= '<td> </td>';
1621: }
1622: $datatable .= '<td class="LC_right_item">'.
1623: '<table border="0"><tr>';
1624: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1625: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1626: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1627: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1628: $datatable.=' ';
1.6 raeburn 1629: }
1.160.6.9 raeburn 1630: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1631: '" /></td>';
1632: }
1.30 raeburn 1633: $$rowtotal += $itemcount;
1.3 raeburn 1634: return $datatable;
1635: }
1636:
1.70 raeburn 1637: sub logo_display_options {
1638: my ($img,$defaults,$designs) = @_;
1639: my $checkedon;
1640: if (ref($defaults) eq 'HASH') {
1641: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1642: if ($defaults->{'showlogo'}{$img}) {
1643: $checkedon = 'checked="checked" ';
1644: }
1645: }
1646: }
1647: if (ref($designs) eq 'HASH') {
1648: if (ref($designs->{'showlogo'}) eq 'HASH') {
1649: if (defined($designs->{'showlogo'}{$img})) {
1650: if ($designs->{'showlogo'}{$img} == 0) {
1651: $checkedon = '';
1652: } elsif ($designs->{'showlogo'}{$img} == 1) {
1653: $checkedon = 'checked="checked" ';
1654: }
1655: }
1656: }
1657: }
1658: return '<br /><label> <input type="checkbox" name="'.
1659: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1660: &mt('show').'</label>'."\n";
1661: }
1662:
1.41 raeburn 1663: sub login_header_options {
1.135 bisitz 1664: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1665: my $output = '';
1.41 raeburn 1666: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1667: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1668: if (!$is_custom->{'textcol'}) {
1669: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1670: ' ';
1671: }
1672: if (!$is_custom->{'bgcol'}) {
1673: $output .= $choices->{'bgcol'}.': '.
1674: '<span id="css_'.$role.'_font" style="background-color: '.
1675: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1676: }
1677: $output .= '<br />';
1678: }
1679: $output .='<br />';
1680: return $output;
1681: }
1682:
1683: sub login_text_colors {
1.160.6.22 raeburn 1684: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1685: my $color_menu = '<table border="0"><tr>';
1686: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1687: $color_menu .= '<td align="center">'.$choices->{$item};
1688: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1689: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1690: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1691: }
1692: $color_menu .= '</tr></table><br />';
1693: return $color_menu;
1694: }
1695:
1696: sub image_changes {
1697: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1698: my $output;
1.135 bisitz 1699: if ($img eq 'login') {
1.160.6.87 raeburn 1700: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1701: } elsif (!$is_custom) {
1.70 raeburn 1702: if ($img ne 'domlogo') {
1.160.6.87 raeburn 1703: $output = &mt('Default image:').'<br />';
1.41 raeburn 1704: } else {
1.160.6.87 raeburn 1705: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1706: }
1707: }
1.160.6.87 raeburn 1708: if ($img ne 'login') {
1.135 bisitz 1709: if ($img_import) {
1710: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1711: }
1712: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1713: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1714: if ($is_custom) {
1715: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1716: '<input type="checkbox" name="'.
1717: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1718: '</label> '.&mt('Replace:').'</span><br />';
1719: } else {
1.160.6.22 raeburn 1720: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1721: }
1.41 raeburn 1722: }
1723: return $output;
1724: }
1725:
1.3 raeburn 1726: sub print_quotas {
1.86 raeburn 1727: my ($dom,$settings,$rowtotal,$action) = @_;
1728: my $context;
1729: if ($action eq 'quotas') {
1730: $context = 'tools';
1731: } else {
1732: $context = $action;
1733: }
1.160.6.20 raeburn 1734: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1735: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1736: my $typecount = 0;
1.101 raeburn 1737: my ($css_class,%titles);
1.86 raeburn 1738: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1739: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1740: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1741: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1742: %titles = &courserequest_titles();
1.160.6.5 raeburn 1743: } elsif ($context eq 'requestauthor') {
1744: @usertools = ('author');
1745: @options = ('norequest','approval','automatic');
1746: %titles = &authorrequest_titles();
1.86 raeburn 1747: } else {
1.160.6.4 raeburn 1748: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1749: %titles = &tool_titles();
1.86 raeburn 1750: }
1.26 raeburn 1751: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1752: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1753: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1754: unless (($context eq 'requestcourses') ||
1755: ($context eq 'requestauthor')) {
1.86 raeburn 1756: if (ref($settings) eq 'HASH') {
1757: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1758: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1759: } else {
1760: $currdefquota = $settings->{$type};
1761: }
1.160.6.20 raeburn 1762: if (ref($settings->{authorquota}) eq 'HASH') {
1763: $currauthorquota = $settings->{authorquota}->{$type};
1764: }
1.78 raeburn 1765: }
1.72 raeburn 1766: }
1.3 raeburn 1767: if (defined($usertypes->{$type})) {
1768: $typecount ++;
1769: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1770: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1771: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1772: '<td class="LC_left_item">';
1.101 raeburn 1773: if ($context eq 'requestcourses') {
1774: $datatable .= '<table><tr>';
1775: }
1776: my %cell;
1.72 raeburn 1777: foreach my $item (@usertools) {
1.101 raeburn 1778: if ($context eq 'requestcourses') {
1779: my ($curroption,$currlimit);
1780: if (ref($settings) eq 'HASH') {
1781: if (ref($settings->{$item}) eq 'HASH') {
1782: $curroption = $settings->{$item}->{$type};
1783: if ($curroption =~ /^autolimit=(\d*)$/) {
1784: $currlimit = $1;
1785: }
1786: }
1787: }
1788: if (!$curroption) {
1789: $curroption = 'norequest';
1790: }
1791: $datatable .= '<th>'.$titles{$item}.'</th>';
1792: foreach my $option (@options) {
1793: my $val = $option;
1794: if ($option eq 'norequest') {
1795: $val = 0;
1796: }
1797: if ($option eq 'validate') {
1798: my $canvalidate = 0;
1799: if (ref($validations{$item}) eq 'HASH') {
1800: if ($validations{$item}{$type}) {
1801: $canvalidate = 1;
1802: }
1803: }
1804: next if (!$canvalidate);
1805: }
1806: my $checked = '';
1807: if ($option eq $curroption) {
1808: $checked = ' checked="checked"';
1809: } elsif ($option eq 'autolimit') {
1810: if ($curroption =~ /^autolimit/) {
1811: $checked = ' checked="checked"';
1812: }
1813: }
1814: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1815: '<input type="radio" name="crsreq_'.$item.
1816: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1817: $titles{$option}.'</label>';
1.101 raeburn 1818: if ($option eq 'autolimit') {
1.127 raeburn 1819: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1820: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1821: 'value="'.$currlimit.'" />';
1.101 raeburn 1822: }
1.127 raeburn 1823: $cell{$item} .= '</span> ';
1.103 raeburn 1824: if ($option eq 'autolimit') {
1.127 raeburn 1825: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1826: }
1.101 raeburn 1827: }
1.160.6.5 raeburn 1828: } elsif ($context eq 'requestauthor') {
1829: my $curroption;
1830: if (ref($settings) eq 'HASH') {
1831: $curroption = $settings->{$type};
1832: }
1833: if (!$curroption) {
1834: $curroption = 'norequest';
1835: }
1836: foreach my $option (@options) {
1837: my $val = $option;
1838: if ($option eq 'norequest') {
1839: $val = 0;
1840: }
1841: my $checked = '';
1842: if ($option eq $curroption) {
1843: $checked = ' checked="checked"';
1844: }
1845: $datatable .= '<span class="LC_nobreak"><label>'.
1846: '<input type="radio" name="authorreq_'.$type.
1847: '" value="'.$val.'"'.$checked.' />'.
1848: $titles{$option}.'</label></span> ';
1849: }
1.101 raeburn 1850: } else {
1851: my $checked = 'checked="checked" ';
1852: if (ref($settings) eq 'HASH') {
1853: if (ref($settings->{$item}) eq 'HASH') {
1854: if ($settings->{$item}->{$type} == 0) {
1855: $checked = '';
1856: } elsif ($settings->{$item}->{$type} == 1) {
1857: $checked = 'checked="checked" ';
1858: }
1.78 raeburn 1859: }
1.72 raeburn 1860: }
1.101 raeburn 1861: $datatable .= '<span class="LC_nobreak"><label>'.
1862: '<input type="checkbox" name="'.$context.'_'.$item.
1863: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1864: '</label></span> ';
1.72 raeburn 1865: }
1.101 raeburn 1866: }
1867: if ($context eq 'requestcourses') {
1868: $datatable .= '</tr><tr>';
1869: foreach my $item (@usertools) {
1.106 raeburn 1870: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1871: }
1872: $datatable .= '</tr></table>';
1.72 raeburn 1873: }
1.86 raeburn 1874: $datatable .= '</td>';
1.160.6.5 raeburn 1875: unless (($context eq 'requestcourses') ||
1876: ($context eq 'requestauthor')) {
1.86 raeburn 1877: $datatable .=
1.160.6.20 raeburn 1878: '<td class="LC_right_item">'.
1879: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1880: '<input type="text" name="quota_'.$type.
1.72 raeburn 1881: '" value="'.$currdefquota.
1.160.6.20 raeburn 1882: '" size="5" /></span>'.(' ' x 2).
1883: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1884: '<input type="text" name="authorquota_'.$type.
1885: '" value="'.$currauthorquota.
1886: '" size="5" /></span></td>';
1.86 raeburn 1887: }
1888: $datatable .= '</tr>';
1.3 raeburn 1889: }
1890: }
1891: }
1.160.6.5 raeburn 1892: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1893: $defaultquota = '20';
1.160.6.20 raeburn 1894: $authorquota = '500';
1.86 raeburn 1895: if (ref($settings) eq 'HASH') {
1896: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1897: $defaultquota = $settings->{'defaultquota'}->{'default'};
1898: } elsif (defined($settings->{'default'})) {
1899: $defaultquota = $settings->{'default'};
1900: }
1.160.6.20 raeburn 1901: if (ref($settings->{'authorquota'}) eq 'HASH') {
1902: $authorquota = $settings->{'authorquota'}->{'default'};
1903: }
1.3 raeburn 1904: }
1905: }
1906: $typecount ++;
1907: $css_class = $typecount%2?' class="LC_odd_row"':'';
1908: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1909: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1910: '<td class="LC_left_item">';
1.101 raeburn 1911: if ($context eq 'requestcourses') {
1912: $datatable .= '<table><tr>';
1913: }
1914: my %defcell;
1.72 raeburn 1915: foreach my $item (@usertools) {
1.101 raeburn 1916: if ($context eq 'requestcourses') {
1917: my ($curroption,$currlimit);
1918: if (ref($settings) eq 'HASH') {
1919: if (ref($settings->{$item}) eq 'HASH') {
1920: $curroption = $settings->{$item}->{'default'};
1921: if ($curroption =~ /^autolimit=(\d*)$/) {
1922: $currlimit = $1;
1923: }
1924: }
1925: }
1926: if (!$curroption) {
1927: $curroption = 'norequest';
1928: }
1929: $datatable .= '<th>'.$titles{$item}.'</th>';
1930: foreach my $option (@options) {
1931: my $val = $option;
1932: if ($option eq 'norequest') {
1933: $val = 0;
1934: }
1935: if ($option eq 'validate') {
1936: my $canvalidate = 0;
1937: if (ref($validations{$item}) eq 'HASH') {
1938: if ($validations{$item}{'default'}) {
1939: $canvalidate = 1;
1940: }
1941: }
1942: next if (!$canvalidate);
1943: }
1944: my $checked = '';
1945: if ($option eq $curroption) {
1946: $checked = ' checked="checked"';
1947: } elsif ($option eq 'autolimit') {
1948: if ($curroption =~ /^autolimit/) {
1949: $checked = ' checked="checked"';
1950: }
1951: }
1952: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1953: '<input type="radio" name="crsreq_'.$item.
1954: '_default" value="'.$val.'"'.$checked.' />'.
1955: $titles{$option}.'</label>';
1956: if ($option eq 'autolimit') {
1.127 raeburn 1957: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1958: $item.'_limit_default" size="1" '.
1959: 'value="'.$currlimit.'" />';
1960: }
1.127 raeburn 1961: $defcell{$item} .= '</span> ';
1.104 raeburn 1962: if ($option eq 'autolimit') {
1.127 raeburn 1963: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1964: }
1.101 raeburn 1965: }
1.160.6.5 raeburn 1966: } elsif ($context eq 'requestauthor') {
1967: my $curroption;
1968: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1969: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1970: }
1971: if (!$curroption) {
1972: $curroption = 'norequest';
1973: }
1974: foreach my $option (@options) {
1975: my $val = $option;
1976: if ($option eq 'norequest') {
1977: $val = 0;
1978: }
1979: my $checked = '';
1980: if ($option eq $curroption) {
1981: $checked = ' checked="checked"';
1982: }
1983: $datatable .= '<span class="LC_nobreak"><label>'.
1984: '<input type="radio" name="authorreq_default"'.
1985: ' value="'.$val.'"'.$checked.' />'.
1986: $titles{$option}.'</label></span> ';
1987: }
1.101 raeburn 1988: } else {
1989: my $checked = 'checked="checked" ';
1990: if (ref($settings) eq 'HASH') {
1991: if (ref($settings->{$item}) eq 'HASH') {
1992: if ($settings->{$item}->{'default'} == 0) {
1993: $checked = '';
1994: } elsif ($settings->{$item}->{'default'} == 1) {
1995: $checked = 'checked="checked" ';
1996: }
1.78 raeburn 1997: }
1.72 raeburn 1998: }
1.101 raeburn 1999: $datatable .= '<span class="LC_nobreak"><label>'.
2000: '<input type="checkbox" name="'.$context.'_'.$item.
2001: '" value="default" '.$checked.'/>'.$titles{$item}.
2002: '</label></span> ';
2003: }
2004: }
2005: if ($context eq 'requestcourses') {
2006: $datatable .= '</tr><tr>';
2007: foreach my $item (@usertools) {
1.106 raeburn 2008: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2009: }
1.101 raeburn 2010: $datatable .= '</tr></table>';
1.72 raeburn 2011: }
1.86 raeburn 2012: $datatable .= '</td>';
1.160.6.5 raeburn 2013: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2014: $datatable .= '<td class="LC_right_item">'.
2015: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2016: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2017: $defaultquota.'" size="5" /></span>'.(' ' x2).
2018: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2019: '<input type="text" name="authorquota" value="'.
2020: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2021: }
2022: $datatable .= '</tr>';
1.72 raeburn 2023: $typecount ++;
2024: $css_class = $typecount%2?' class="LC_odd_row"':'';
2025: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2026: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2027: if ($context eq 'requestcourses') {
1.109 raeburn 2028: $datatable .= &mt('(overrides affiliation, if set)').
2029: '</td>'.
2030: '<td class="LC_left_item">'.
2031: '<table><tr>';
1.101 raeburn 2032: } else {
1.109 raeburn 2033: $datatable .= &mt('(overrides affiliation, if checked)').
2034: '</td>'.
2035: '<td class="LC_left_item" colspan="2">'.
2036: '<br />';
1.101 raeburn 2037: }
2038: my %advcell;
1.72 raeburn 2039: foreach my $item (@usertools) {
1.101 raeburn 2040: if ($context eq 'requestcourses') {
2041: my ($curroption,$currlimit);
2042: if (ref($settings) eq 'HASH') {
2043: if (ref($settings->{$item}) eq 'HASH') {
2044: $curroption = $settings->{$item}->{'_LC_adv'};
2045: if ($curroption =~ /^autolimit=(\d*)$/) {
2046: $currlimit = $1;
2047: }
2048: }
2049: }
2050: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2051: my $checked = '';
2052: if ($curroption eq '') {
2053: $checked = ' checked="checked"';
2054: }
2055: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2056: '<input type="radio" name="crsreq_'.$item.
2057: '__LC_adv" value=""'.$checked.' />'.
2058: &mt('No override set').'</label></span> ';
1.101 raeburn 2059: foreach my $option (@options) {
2060: my $val = $option;
2061: if ($option eq 'norequest') {
2062: $val = 0;
2063: }
2064: if ($option eq 'validate') {
2065: my $canvalidate = 0;
2066: if (ref($validations{$item}) eq 'HASH') {
2067: if ($validations{$item}{'_LC_adv'}) {
2068: $canvalidate = 1;
2069: }
2070: }
2071: next if (!$canvalidate);
2072: }
2073: my $checked = '';
1.104 raeburn 2074: if ($val eq $curroption) {
1.101 raeburn 2075: $checked = ' checked="checked"';
2076: } elsif ($option eq 'autolimit') {
2077: if ($curroption =~ /^autolimit/) {
2078: $checked = ' checked="checked"';
2079: }
2080: }
2081: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2082: '<input type="radio" name="crsreq_'.$item.
2083: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2084: $titles{$option}.'</label>';
2085: if ($option eq 'autolimit') {
1.127 raeburn 2086: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2087: $item.'_limit__LC_adv" size="1" '.
2088: 'value="'.$currlimit.'" />';
2089: }
1.127 raeburn 2090: $advcell{$item} .= '</span> ';
1.104 raeburn 2091: if ($option eq 'autolimit') {
1.127 raeburn 2092: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2093: }
1.101 raeburn 2094: }
1.160.6.5 raeburn 2095: } elsif ($context eq 'requestauthor') {
2096: my $curroption;
2097: if (ref($settings) eq 'HASH') {
2098: $curroption = $settings->{'_LC_adv'};
2099: }
2100: my $checked = '';
2101: if ($curroption eq '') {
2102: $checked = ' checked="checked"';
2103: }
2104: $datatable .= '<span class="LC_nobreak"><label>'.
2105: '<input type="radio" name="authorreq__LC_adv"'.
2106: ' value=""'.$checked.' />'.
2107: &mt('No override set').'</label></span> ';
2108: foreach my $option (@options) {
2109: my $val = $option;
2110: if ($option eq 'norequest') {
2111: $val = 0;
2112: }
2113: my $checked = '';
2114: if ($val eq $curroption) {
2115: $checked = ' checked="checked"';
2116: }
2117: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2118: '<input type="radio" name="authorreq__LC_adv"'.
2119: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2120: $titles{$option}.'</label></span> ';
2121: }
1.101 raeburn 2122: } else {
2123: my $checked = 'checked="checked" ';
2124: if (ref($settings) eq 'HASH') {
2125: if (ref($settings->{$item}) eq 'HASH') {
2126: if ($settings->{$item}->{'_LC_adv'} == 0) {
2127: $checked = '';
2128: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2129: $checked = 'checked="checked" ';
2130: }
1.79 raeburn 2131: }
1.72 raeburn 2132: }
1.101 raeburn 2133: $datatable .= '<span class="LC_nobreak"><label>'.
2134: '<input type="checkbox" name="'.$context.'_'.$item.
2135: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2136: '</label></span> ';
2137: }
2138: }
2139: if ($context eq 'requestcourses') {
2140: $datatable .= '</tr><tr>';
2141: foreach my $item (@usertools) {
1.106 raeburn 2142: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2143: }
1.101 raeburn 2144: $datatable .= '</tr></table>';
1.72 raeburn 2145: }
1.98 raeburn 2146: $datatable .= '</td></tr>';
1.30 raeburn 2147: $$rowtotal += $typecount;
1.3 raeburn 2148: return $datatable;
2149: }
2150:
1.160.6.5 raeburn 2151: sub print_requestmail {
1.160.6.93 raeburn 2152: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2153: my ($now,$datatable,%currapp);
1.102 raeburn 2154: $now = time;
2155: if (ref($settings) eq 'HASH') {
2156: if (ref($settings->{'notify'}) eq 'HASH') {
2157: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2158: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2159: }
2160: }
2161: }
1.160.6.16 raeburn 2162: my $numinrow = 2;
1.160.6.34 raeburn 2163: my $css_class;
1.160.6.93 raeburn 2164: if ($$rowtotal%2) {
2165: $css_class = 'LC_odd_row';
2166: }
2167: if ($customcss) {
2168: $css_class .= " $customcss";
2169: }
2170: $css_class =~ s/^\s+//;
2171: if ($css_class) {
2172: $css_class = ' class="'.$css_class.'"';
2173: }
2174: if ($rowstyle) {
2175: $css_class .= ' style="'.$rowstyle.'"';
2176: }
1.160.6.5 raeburn 2177: my $text;
2178: if ($action eq 'requestcourses') {
2179: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2180: } elsif ($action eq 'requestauthor') {
2181: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2182: } else {
1.160.6.34 raeburn 2183: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2184: }
1.160.6.34 raeburn 2185: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2186: ' <td>'.$text.'</td>'.
1.102 raeburn 2187: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2188: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2189: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2190: if ($numdc > 0) {
2191: $datatable .= $table;
1.102 raeburn 2192: } else {
2193: $datatable .= &mt('There are no active Domain Coordinators');
2194: }
2195: $datatable .='</td></tr>';
2196: return $datatable;
2197: }
2198:
1.160.6.30 raeburn 2199: sub print_studentcode {
2200: my ($settings,$rowtotal) = @_;
2201: my $rownum = 0;
2202: my ($output,%current);
2203: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2204: if (ref($settings) eq 'HASH') {
2205: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2206: foreach my $type (@crstypes) {
2207: $current{$type} = $settings->{'uniquecode'}{$type};
2208: }
1.160.6.30 raeburn 2209: }
2210: }
2211: $output .= '<tr>'.
2212: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2213: '<td class="LC_left_item">';
2214: foreach my $type (@crstypes) {
2215: my $check = ' ';
2216: if ($current{$type}) {
2217: $check = ' checked="checked" ';
2218: }
2219: $output .= '<span class="LC_nobreak"><label>'.
2220: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2221: &mt($type).'</label></span>'.(' 'x2).' ';
2222: }
2223: $output .= '</td></tr>';
2224: $$rowtotal ++;
2225: return $output;
2226: }
2227:
2228: sub print_textbookcourses {
1.160.6.46 raeburn 2229: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2230: my $rownum = 0;
2231: my $css_class;
2232: my $itemcount = 1;
2233: my $maxnum = 0;
2234: my $bookshash;
2235: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2236: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2237: }
2238: my %ordered;
2239: if (ref($bookshash) eq 'HASH') {
2240: foreach my $item (keys(%{$bookshash})) {
2241: if (ref($bookshash->{$item}) eq 'HASH') {
2242: my $num = $bookshash->{$item}{'order'};
2243: $ordered{$num} = $item;
2244: }
2245: }
2246: }
2247: my $confname = $dom.'-domainconfig';
2248: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2249: my $maxnum = scalar(keys(%ordered));
2250: my $datatable;
1.160.6.30 raeburn 2251: if (keys(%ordered)) {
2252: my @items = sort { $a <=> $b } keys(%ordered);
2253: for (my $i=0; $i<@items; $i++) {
2254: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2255: my $key = $ordered{$items[$i]};
2256: my %coursehash=&Apache::lonnet::coursedescription($key);
2257: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2258: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2259: if (ref($bookshash->{$key}) eq 'HASH') {
2260: $subject = $bookshash->{$key}->{'subject'};
2261: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2262: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2263: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2264: $author = $bookshash->{$key}->{'author'};
2265: $image = $bookshash->{$key}->{'image'};
2266: if ($image ne '') {
2267: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2268: my $imagethumb = "$path/tn-".$imagefile;
2269: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2270: }
1.160.6.30 raeburn 2271: }
2272: }
1.160.6.46 raeburn 2273: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2274: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2275: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2276: for (my $k=0; $k<=$maxnum; $k++) {
2277: my $vpos = $k+1;
2278: my $selstr;
2279: if ($k == $i) {
2280: $selstr = ' selected="selected" ';
2281: }
2282: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2283: }
2284: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2285: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2286: &mt('Delete?').'</label></span></td>'.
2287: '<td colspan="2">'.
1.160.6.46 raeburn 2288: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2289: (' 'x2).
1.160.6.46 raeburn 2290: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2291: if ($type eq 'textbooks') {
2292: $datatable .= (' 'x2).
1.160.6.47 raeburn 2293: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2294: (' 'x2).
1.160.6.46 raeburn 2295: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2296: (' 'x2).
2297: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2298: if ($image) {
2299: $datatable .= '<span class="LC_nobreak">'.
2300: $imgsrc.
2301: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2302: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2303: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2304: }
2305: if ($switchserver) {
2306: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2307: } else {
2308: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2309: }
1.160.6.30 raeburn 2310: }
1.160.6.46 raeburn 2311: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2312: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2313: $coursetitle.'</span></td></tr>'."\n";
2314: $itemcount ++;
2315: }
2316: }
2317: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2318: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2319: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2320: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2321: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2322: for (my $k=0; $k<$maxnum+1; $k++) {
2323: my $vpos = $k+1;
2324: my $selstr;
2325: if ($k == $maxnum) {
2326: $selstr = ' selected="selected" ';
2327: }
2328: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2329: }
2330: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2331: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2332: '<td colspan="2">'.
1.160.6.46 raeburn 2333: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2334: (' 'x2).
1.160.6.46 raeburn 2335: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2336: (' 'x2);
2337: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2338: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2339: (' 'x2).
2340: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2341: (' 'x2).
2342: '<span class="LC_nobreak">'.&mt('Image:').' ';
2343: if ($switchserver) {
2344: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2345: } else {
2346: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2347: }
1.160.6.87 raeburn 2348: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2349: }
1.160.6.87 raeburn 2350: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2351: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2352: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2353: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2354: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2355: '</span></td>'."\n".
2356: '</tr>'."\n";
2357: $itemcount ++;
2358: return $datatable;
2359: }
2360:
2361: sub textbookcourses_javascript {
1.160.6.46 raeburn 2362: my ($settings) = @_;
2363: return unless(ref($settings) eq 'HASH');
2364: my (%ordered,%total,%jstext);
2365: foreach my $type ('textbooks','templates') {
2366: $total{$type} = 0;
2367: if (ref($settings->{$type}) eq 'HASH') {
2368: foreach my $item (keys(%{$settings->{$type}})) {
2369: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2370: my $num = $settings->{$type}->{$item}{'order'};
2371: $ordered{$type}{$num} = $item;
2372: }
2373: }
2374: $total{$type} = scalar(keys(%{$settings->{$type}}));
2375: }
2376: my @jsarray = ();
2377: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2378: push(@jsarray,$ordered{$type}{$item});
2379: }
2380: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2381: }
2382: return <<"ENDSCRIPT";
2383: <script type="text/javascript">
2384: // <![CDATA[
1.160.6.46 raeburn 2385: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2386: var changedVal;
1.160.6.46 raeburn 2387: $jstext{'textbooks'};
2388: $jstext{'templates'};
2389: var newpos;
2390: var maxh;
2391: if (caller == 'textbooks') {
2392: newpos = 'textbooks_addbook_pos';
2393: maxh = 1 + $total{'textbooks'};
2394: } else {
2395: newpos = 'templates_addbook_pos';
2396: maxh = 1 + $total{'templates'};
2397: }
1.160.6.30 raeburn 2398: var current = new Array;
2399: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2400: if (item == newpos) {
2401: changedVal = newitemVal;
2402: } else {
2403: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2404: current[newitemVal] = newpos;
2405: }
1.160.6.46 raeburn 2406: if (caller == 'textbooks') {
2407: for (var i=0; i<textbooks.length; i++) {
2408: var elementName = 'textbooks_'+textbooks[i];
2409: if (elementName != item) {
2410: if (form.elements[elementName]) {
2411: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2412: current[currVal] = elementName;
2413: }
2414: }
2415: }
2416: }
2417: if (caller == 'templates') {
2418: for (var i=0; i<templates.length; i++) {
2419: var elementName = 'templates_'+templates[i];
2420: if (elementName != item) {
2421: if (form.elements[elementName]) {
2422: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2423: current[currVal] = elementName;
2424: }
1.160.6.30 raeburn 2425: }
2426: }
2427: }
2428: var oldVal;
2429: for (var j=0; j<maxh; j++) {
2430: if (current[j] == undefined) {
2431: oldVal = j;
2432: }
2433: }
2434: if (oldVal < changedVal) {
2435: for (var k=oldVal+1; k<=changedVal ; k++) {
2436: var elementName = current[k];
2437: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2438: }
2439: } else {
2440: for (var k=changedVal; k<oldVal; k++) {
2441: var elementName = current[k];
2442: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2443: }
2444: }
2445: return;
2446: }
2447:
2448: // ]]>
2449: </script>
2450:
2451: ENDSCRIPT
2452: }
2453:
1.3 raeburn 2454: sub print_autoenroll {
1.30 raeburn 2455: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2456: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2457: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2458: if (ref($settings) eq 'HASH') {
2459: if (exists($settings->{'run'})) {
2460: if ($settings->{'run'} eq '0') {
2461: $runoff = ' checked="checked" ';
2462: $runon = ' ';
2463: } else {
2464: $runon = ' checked="checked" ';
2465: $runoff = ' ';
2466: }
2467: } else {
2468: if ($autorun) {
2469: $runon = ' checked="checked" ';
2470: $runoff = ' ';
2471: } else {
2472: $runoff = ' checked="checked" ';
2473: $runon = ' ';
2474: }
2475: }
1.129 raeburn 2476: if (exists($settings->{'co-owners'})) {
2477: if ($settings->{'co-owners'} eq '0') {
2478: $coownersoff = ' checked="checked" ';
2479: $coownerson = ' ';
2480: } else {
2481: $coownerson = ' checked="checked" ';
2482: $coownersoff = ' ';
2483: }
2484: } else {
2485: $coownersoff = ' checked="checked" ';
2486: $coownerson = ' ';
2487: }
1.3 raeburn 2488: if (exists($settings->{'sender_domain'})) {
2489: $defdom = $settings->{'sender_domain'};
2490: }
1.160.6.68 raeburn 2491: if (exists($settings->{'autofailsafe'})) {
2492: $failsafe = $settings->{'autofailsafe'};
2493: }
1.14 raeburn 2494: } else {
2495: if ($autorun) {
2496: $runon = ' checked="checked" ';
2497: $runoff = ' ';
2498: } else {
2499: $runoff = ' checked="checked" ';
2500: $runon = ' ';
2501: }
1.3 raeburn 2502: }
2503: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2504: my $notif_sender;
2505: if (ref($settings) eq 'HASH') {
2506: $notif_sender = $settings->{'sender_uname'};
2507: }
1.3 raeburn 2508: my $datatable='<tr class="LC_odd_row">'.
2509: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2510: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2511: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2512: $runon.' value="1" />'.&mt('Yes').'</label> '.
2513: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2514: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2515: '</tr><tr>'.
2516: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2517: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2518: &mt('username').': '.
2519: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2520: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2521: ': '.$domform.'</span></td></tr>'.
2522: '<tr class="LC_odd_row">'.
2523: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2524: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2525: '<input type="radio" name="autoassign_coowners"'.
2526: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2527: '<label><input type="radio" name="autoassign_coowners"'.
2528: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2529: '</tr><tr>'.
2530: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2531: '<td class="LC_right_item"><span class="LC_nobreak">'.
2532: '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87 raeburn 2533: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68 raeburn 2534: $$rowtotal += 4;
1.3 raeburn 2535: return $datatable;
2536: }
2537:
2538: sub print_autoupdate {
1.30 raeburn 2539: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2540: my $datatable;
2541: if ($position eq 'top') {
2542: my $updateon = ' ';
2543: my $updateoff = ' checked="checked" ';
2544: my $classlistson = ' ';
2545: my $classlistsoff = ' checked="checked" ';
2546: if (ref($settings) eq 'HASH') {
2547: if ($settings->{'run'} eq '1') {
2548: $updateon = $updateoff;
2549: $updateoff = ' ';
2550: }
2551: if ($settings->{'classlists'} eq '1') {
2552: $classlistson = $classlistsoff;
2553: $classlistsoff = ' ';
2554: }
2555: }
2556: my %title = (
2557: run => 'Auto-update active?',
2558: classlists => 'Update information in classlists?',
2559: );
2560: $datatable = '<tr class="LC_odd_row">'.
2561: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2562: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2563: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2564: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2565: '<label><input type="radio" name="autoupdate_run"'.
2566: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2567: '</tr><tr>'.
2568: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2569: '<td class="LC_right_item"><span class="LC_nobreak">'.
2570: '<label><input type="radio" name="classlists"'.
2571: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2572: '<label><input type="radio" name="classlists"'.
2573: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2574: '</tr>';
1.30 raeburn 2575: $$rowtotal += 2;
1.131 raeburn 2576: } elsif ($position eq 'middle') {
2577: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2578: my $numinrow = 3;
2579: my $locknamesettings;
2580: $datatable .= &insttypes_row($settings,$types,$usertypes,
2581: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 2582: 'lockablenames',$rowtotal);
1.131 raeburn 2583: $$rowtotal ++;
1.3 raeburn 2584: } else {
1.44 raeburn 2585: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2586: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2587: 'permanentemail','id');
1.33 raeburn 2588: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2589: my $numrows = 0;
1.26 raeburn 2590: if (ref($types) eq 'ARRAY') {
2591: if (@{$types} > 0) {
2592: $datatable =
2593: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2594: \@fields,$types,\$numrows);
1.30 raeburn 2595: $$rowtotal += @{$types};
1.26 raeburn 2596: }
1.3 raeburn 2597: }
2598: $datatable .=
2599: &usertype_update_row($settings,{'default' => $othertitle},
2600: \%fieldtitles,\@fields,['default'],
2601: \$numrows);
1.30 raeburn 2602: $$rowtotal ++;
1.3 raeburn 2603: }
2604: return $datatable;
2605: }
2606:
1.125 raeburn 2607: sub print_autocreate {
2608: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2609: my (%createon,%createoff,%currhash);
1.125 raeburn 2610: my @types = ('xml','req');
2611: if (ref($settings) eq 'HASH') {
2612: foreach my $item (@types) {
2613: $createoff{$item} = ' checked="checked" ';
2614: $createon{$item} = ' ';
2615: if (exists($settings->{$item})) {
2616: if ($settings->{$item}) {
2617: $createon{$item} = ' checked="checked" ';
2618: $createoff{$item} = ' ';
2619: }
2620: }
2621: }
1.160.6.16 raeburn 2622: if ($settings->{'xmldc'} ne '') {
2623: $currhash{$settings->{'xmldc'}} = 1;
2624: }
1.125 raeburn 2625: } else {
2626: foreach my $item (@types) {
2627: $createoff{$item} = ' checked="checked" ';
2628: $createon{$item} = ' ';
2629: }
2630: }
2631: $$rowtotal += 2;
1.160.6.16 raeburn 2632: my $numinrow = 2;
1.125 raeburn 2633: my $datatable='<tr class="LC_odd_row">'.
2634: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2635: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2636: '<input type="radio" name="autocreate_xml"'.
2637: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2638: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2639: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2640: '</td></tr><tr>'.
2641: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2642: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2643: '<input type="radio" name="autocreate_req"'.
2644: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2645: '<label><input type="radio" name="autocreate_req"'.
2646: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2647: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2648: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2649: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2650: if ($numdc > 1) {
1.160.6.50 raeburn 2651: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2652: '</td><td class="LC_left_item">';
1.125 raeburn 2653: } else {
1.160.6.50 raeburn 2654: $datatable .= &mt('Course creation processed as:').
2655: '</td><td class="LC_right_item">';
1.125 raeburn 2656: }
1.160.6.50 raeburn 2657: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2658: $$rowtotal += $rows;
1.125 raeburn 2659: return $datatable;
2660: }
2661:
1.23 raeburn 2662: sub print_directorysrch {
1.160.6.72 raeburn 2663: my ($position,$dom,$settings,$rowtotal) = @_;
2664: my $datatable;
2665: if ($position eq 'top') {
2666: my $instsrchon = ' ';
2667: my $instsrchoff = ' checked="checked" ';
2668: my ($exacton,$containson,$beginson);
2669: my $instlocalon = ' ';
2670: my $instlocaloff = ' checked="checked" ';
2671: if (ref($settings) eq 'HASH') {
2672: if ($settings->{'available'} eq '1') {
2673: $instsrchon = $instsrchoff;
2674: $instsrchoff = ' ';
2675: }
2676: if ($settings->{'localonly'} eq '1') {
2677: $instlocalon = $instlocaloff;
2678: $instlocaloff = ' ';
2679: }
2680: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2681: foreach my $type (@{$settings->{'searchtypes'}}) {
2682: if ($type eq 'exact') {
2683: $exacton = ' checked="checked" ';
2684: } elsif ($type eq 'contains') {
2685: $containson = ' checked="checked" ';
2686: } elsif ($type eq 'begins') {
2687: $beginson = ' checked="checked" ';
2688: }
2689: }
2690: } else {
2691: if ($settings->{'searchtypes'} eq 'exact') {
2692: $exacton = ' checked="checked" ';
2693: } elsif ($settings->{'searchtypes'} eq 'contains') {
2694: $containson = ' checked="checked" ';
2695: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2696: $exacton = ' checked="checked" ';
2697: $containson = ' checked="checked" ';
2698: }
2699: }
1.23 raeburn 2700: }
1.160.6.72 raeburn 2701: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2702: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2703:
1.160.6.72 raeburn 2704: my $numinrow = 4;
2705: my $cansrchrow = 0;
2706: $datatable='<tr class="LC_odd_row">'.
2707: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2708: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2709: '<input type="radio" name="dirsrch_available"'.
2710: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2711: '<label><input type="radio" name="dirsrch_available"'.
2712: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2713: '</tr><tr>'.
2714: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2715: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2716: '<input type="radio" name="dirsrch_instlocalonly"'.
2717: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2718: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2719: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2720: '</tr>';
2721: $$rowtotal += 2;
2722: if (ref($usertypes) eq 'HASH') {
2723: if (keys(%{$usertypes}) > 0) {
2724: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 2725: $numinrow,$othertitle,'cansearch',
2726: $rowtotal);
1.160.6.72 raeburn 2727: $cansrchrow = 1;
2728: }
1.26 raeburn 2729: }
1.160.6.72 raeburn 2730: if ($cansrchrow) {
2731: $$rowtotal ++;
2732: $datatable .= '<tr>';
2733: } else {
2734: $datatable .= '<tr class="LC_odd_row">';
2735: }
2736: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2737: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2738: foreach my $title (@{$titleorder}) {
2739: if (defined($searchtitles->{$title})) {
2740: my $check = ' ';
2741: if (ref($settings) eq 'HASH') {
2742: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2743: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2744: $check = ' checked="checked" ';
2745: }
1.39 raeburn 2746: }
1.25 raeburn 2747: }
1.160.6.72 raeburn 2748: $datatable .= '<td class="LC_left_item">'.
2749: '<span class="LC_nobreak"><label>'.
2750: '<input type="checkbox" name="searchby" '.
2751: 'value="'.$title.'"'.$check.'/>'.
2752: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2753: }
2754: }
1.160.6.72 raeburn 2755: $datatable .= '</tr></table></td></tr>';
2756: $$rowtotal ++;
2757: if ($cansrchrow) {
2758: $datatable .= '<tr class="LC_odd_row">';
2759: } else {
2760: $datatable .= '<tr>';
2761: }
2762: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2763: '<td class="LC_left_item" colspan="2">'.
2764: '<span class="LC_nobreak"><label>'.
2765: '<input type="checkbox" name="searchtypes" '.
2766: $exacton.' value="exact" />'.&mt('Exact match').
2767: '</label> '.
2768: '<label><input type="checkbox" name="searchtypes" '.
2769: $beginson.' value="begins" />'.&mt('Begins with').
2770: '</label> '.
2771: '<label><input type="checkbox" name="searchtypes" '.
2772: $containson.' value="contains" />'.&mt('Contains').
2773: '</label></span></td></tr>';
2774: $$rowtotal ++;
1.26 raeburn 2775: } else {
1.160.6.72 raeburn 2776: my $domsrchon = ' checked="checked" ';
2777: my $domsrchoff = ' ';
2778: my $domlocalon = ' ';
2779: my $domlocaloff = ' checked="checked" ';
2780: if (ref($settings) eq 'HASH') {
2781: if ($settings->{'lclocalonly'} eq '1') {
2782: $domlocalon = $domlocaloff;
2783: $domlocaloff = ' ';
2784: }
2785: if ($settings->{'lcavailable'} eq '0') {
2786: $domsrchoff = $domsrchon;
2787: $domsrchon = ' ';
2788: }
2789: }
2790: $datatable='<tr class="LC_odd_row">'.
2791: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2792: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2793: '<input type="radio" name="dirsrch_domavailable"'.
2794: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2795: '<label><input type="radio" name="dirsrch_domavailable"'.
2796: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2797: '</tr><tr>'.
2798: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2799: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2800: '<input type="radio" name="dirsrch_domlocalonly"'.
2801: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2802: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2803: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2804: '</tr>';
2805: $$rowtotal += 2;
1.26 raeburn 2806: }
1.25 raeburn 2807: return $datatable;
2808: }
2809:
1.28 raeburn 2810: sub print_contacts {
1.160.6.78 raeburn 2811: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2812: my $datatable;
2813: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 2814: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2815: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2816: if ($position eq 'top') {
2817: if (ref($settings) eq 'HASH') {
2818: foreach my $item (@contacts) {
2819: if (exists($settings->{$item})) {
2820: $to{$item} = $settings->{$item};
2821: }
1.28 raeburn 2822: }
2823: }
1.160.6.78 raeburn 2824: } elsif ($position eq 'middle') {
2825: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 2826: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 2827: foreach my $type (@mailings) {
1.160.6.78 raeburn 2828: $otheremails{$type} = '';
2829: }
2830: } else {
2831: @mailings = ('helpdeskmail','otherdomsmail');
2832: foreach my $type (@mailings) {
2833: $otheremails{$type} = '';
2834: }
2835: $bccemails{'helpdeskmail'} = '';
2836: $bccemails{'otherdomsmail'} = '';
2837: $includestr{'helpdeskmail'} = '';
2838: $includestr{'otherdomsmail'} = '';
2839: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2840: }
2841: if (ref($settings) eq 'HASH') {
2842: unless ($position eq 'top') {
2843: foreach my $type (@mailings) {
2844: if (exists($settings->{$type})) {
2845: if (ref($settings->{$type}) eq 'HASH') {
2846: foreach my $item (@contacts) {
2847: if ($settings->{$type}{$item}) {
2848: $checked{$type}{$item} = ' checked="checked" ';
2849: }
1.28 raeburn 2850: }
1.160.6.78 raeburn 2851: $otheremails{$type} = $settings->{$type}{'others'};
2852: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2853: $bccemails{$type} = $settings->{$type}{'bcc'};
2854: if ($settings->{$type}{'include'} ne '') {
2855: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2856: $includestr{$type} = &unescape($includestr{$type});
2857: }
2858: }
2859: }
2860: } elsif ($type eq 'lonstatusmail') {
2861: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2862: }
2863: }
2864: }
2865: if ($position eq 'bottom') {
2866: foreach my $type (@mailings) {
2867: $bccemails{$type} = $settings->{$type}{'bcc'};
2868: if ($settings->{$type}{'include'} ne '') {
2869: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2870: $includestr{$type} = &unescape($includestr{$type});
2871: }
2872: }
2873: if (ref($settings->{'helpform'}) eq 'HASH') {
2874: if (ref($fields) eq 'ARRAY') {
2875: foreach my $field (@{$fields}) {
2876: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 2877: }
1.160.6.78 raeburn 2878: }
2879: if (exists($settings->{'helpform'}{'maxsize'})) {
2880: $maxsize = $settings->{'helpform'}{'maxsize'};
2881: } else {
2882: $maxsize = '1.0';
2883: }
2884: } else {
2885: if (ref($fields) eq 'ARRAY') {
2886: foreach my $field (@{$fields}) {
2887: $currfield{$field} = 'yes';
1.134 raeburn 2888: }
1.28 raeburn 2889: }
1.160.6.78 raeburn 2890: $maxsize = '1.0';
1.28 raeburn 2891: }
2892: }
2893: } else {
1.160.6.78 raeburn 2894: if ($position eq 'top') {
2895: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2896: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2897: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2898: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2899: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2900: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2901: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2902: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 2903: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 2904: } elsif ($position eq 'bottom') {
2905: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2906: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
2907: if (ref($fields) eq 'ARRAY') {
2908: foreach my $field (@{$fields}) {
2909: $currfield{$field} = 'yes';
2910: }
2911: }
2912: $maxsize = '1.0';
2913: }
1.28 raeburn 2914: }
2915: my ($titles,$short_titles) = &contact_titles();
2916: my $rownum = 0;
2917: my $css_class;
1.160.6.78 raeburn 2918: if ($position eq 'top') {
2919: foreach my $item (@contacts) {
2920: $css_class = $rownum%2?' class="LC_odd_row"':'';
2921: $datatable .= '<tr'.$css_class.'>'.
2922: '<td><span class="LC_nobreak">'.$titles->{$item}.
2923: '</span></td><td class="LC_right_item">'.
2924: '<input type="text" name="'.$item.'" value="'.
2925: $to{$item}.'" /></td></tr>';
2926: $rownum ++;
2927: }
2928: } else {
2929: foreach my $type (@mailings) {
2930: $css_class = $rownum%2?' class="LC_odd_row"':'';
2931: $datatable .= '<tr'.$css_class.'>'.
2932: '<td><span class="LC_nobreak">'.
2933: $titles->{$type}.': </span></td>'.
2934: '<td class="LC_left_item">';
2935: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2936: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
2937: }
2938: $datatable .= '<span class="LC_nobreak">';
2939: foreach my $item (@contacts) {
2940: $datatable .= '<label>'.
2941: '<input type="checkbox" name="'.$type.'"'.
2942: $checked{$type}{$item}.
2943: ' value="'.$item.'" />'.$short_titles->{$item}.
2944: '</label> ';
2945: }
2946: $datatable .= '</span><br />'.&mt('Others').': '.
2947: '<input type="text" name="'.$type.'_others" '.
2948: 'value="'.$otheremails{$type}.'" />';
2949: my %locchecked;
2950: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2951: foreach my $loc ('s','b') {
2952: if ($includeloc{$type} eq $loc) {
2953: $locchecked{$loc} = ' checked="checked"';
2954: last;
2955: }
2956: }
2957: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2958: '<input type="text" name="'.$type.'_bcc" '.
2959: 'value="'.$bccemails{$type}.'" /></fieldset>'.
2960: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
2961: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 2962: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 2963: '<span class="LC_nobreak">'.&mt('Location:').' '.
2964: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
2965: (' 'x2).
2966: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
2967: '</span></fieldset>';
2968: }
2969: $datatable .= '</td></tr>'."\n";
2970: $rownum ++;
2971: }
1.28 raeburn 2972: }
1.160.6.78 raeburn 2973: if ($position eq 'middle') {
2974: my %choices;
2975: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2976: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2977: &mt('LON-CAPA core group - MSU'),600,500));
2978: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2979: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2980: &mt('LON-CAPA core group - MSU'),600,500));
2981: my @toggles = ('reporterrors','reportupdates');
2982: my %defaultchecked = ('reporterrors' => 'on',
2983: 'reportupdates' => 'on');
2984: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2985: \%choices,$rownum);
2986: $datatable .= $reports;
2987: } elsif ($position eq 'bottom') {
1.69 raeburn 2988: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2989: $datatable .= '<tr'.$css_class.'>'.
1.160.6.78 raeburn 2990: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
2991: &mt('(e-mail, subject, and description always shown)').
2992: '</td><td class="LC_left_item">';
2993: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
2994: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
2995: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
2996: foreach my $field (@{$fields}) {
2997: $datatable .= '<tr><td>'.$fieldtitles->{$field};
2998: if (($field eq 'screenshot') || ($field eq 'cc')) {
2999: $datatable .= ' '.&mt('(logged-in users)');
3000: }
3001: $datatable .='</td><td>';
3002: my $clickaction;
3003: if ($field eq 'screenshot') {
3004: $clickaction = ' onclick="screenshotSize(this);"';
3005: }
3006: if (ref($possoptions->{$field}) eq 'ARRAY') {
3007: foreach my $option (@{$possoptions->{$field}}) {
3008: my $checked;
3009: if ($currfield{$field} eq $option) {
3010: $checked = ' checked="checked"';
3011: }
3012: $datatable .= '<span class="LC_nobreak"><label>'.
3013: '<input type="radio" name="helpform_'.$field.'" '.
3014: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
3015: '</label></span>'.(' 'x2);
3016: }
3017: }
3018: if ($field eq 'screenshot') {
3019: my $display;
3020: if ($currfield{$field} eq 'no') {
3021: $display = ' style="display:none"';
3022: }
1.160.6.87 raeburn 3023: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.160.6.78 raeburn 3024: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3025: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3026: }
3027: $datatable .= '</td></tr>';
3028: }
3029: $datatable .= '</table>';
1.134 raeburn 3030: }
3031: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 3032: $rownum ++;
1.28 raeburn 3033: }
1.30 raeburn 3034: $$rowtotal += $rownum;
1.28 raeburn 3035: return $datatable;
3036: }
3037:
1.160.6.78 raeburn 3038: sub contacts_javascript {
3039: return <<"ENDSCRIPT";
3040:
3041: <script type="text/javascript">
3042: // <![CDATA[
3043:
3044: function screenshotSize(field) {
3045: if (document.getElementById('help_screenshotsize')) {
3046: if (field.value == 'no') {
3047: document.getElementById('help_screenshotsize').style.display="none";
3048: } else {
3049: document.getElementById('help_screenshotsize').style.display="";
3050: }
3051: }
3052: return;
3053: }
3054:
3055: // ]]>
3056: </script>
3057:
3058: ENDSCRIPT
3059: }
3060:
1.118 jms 3061: sub print_helpsettings {
1.160.6.73 raeburn 3062: my ($position,$dom,$settings,$rowtotal) = @_;
3063: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3064: my $formname = 'display';
1.160.6.5 raeburn 3065: my ($datatable,$itemcount);
1.160.6.73 raeburn 3066: if ($position eq 'top') {
3067: $itemcount = 1;
3068: my (%choices,%defaultchecked,@toggles);
3069: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3070: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3071: &mt('LON-CAPA bug tracker'),600,500));
3072: %defaultchecked = ('submitbugs' => 'on');
3073: @toggles = ('submitbugs');
3074: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3075: \%choices,$itemcount);
3076: $$rowtotal ++;
3077: } else {
3078: my $css_class;
3079: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3080: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3081: if (ref($settings) eq 'HASH') {
3082: if (ref($settings->{'adhoc'}) eq 'HASH') {
3083: %current = %{$settings->{'adhoc'}};
3084: }
1.160.6.77 raeburn 3085: }
3086: my $count = 0;
3087: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3088: if ($key=~/^rolesdef\_(\w+)$/) {
3089: my $rolename = $1;
1.160.6.77 raeburn 3090: my (%privs,$order);
1.160.6.73 raeburn 3091: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3092: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3093: if (ref($current{$rolename}) eq 'HASH') {
3094: $order = $current{$rolename}{'order'};
3095: }
3096: if ($order eq '') {
3097: $order = $count;
3098: }
3099: $ordered{$order} = $rolename;
3100: $count++;
1.160.6.73 raeburn 3101: }
3102: }
1.160.6.77 raeburn 3103: my $maxnum = scalar(keys(%ordered));
3104: my @roles_by_num = ();
3105: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3106: push(@roles_by_num,$item);
3107: }
3108: my $context = 'domprefs';
3109: my $crstype = 'Course';
3110: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3111: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3112: my ($numstatustypes,@jsarray);
3113: if (ref($types) eq 'ARRAY') {
3114: if (@{$types} > 0) {
3115: $numstatustypes = scalar(@{$types});
3116: push(@accesstypes,'status');
3117: @jsarray = ('bystatus');
3118: }
3119: }
1.160.6.86 raeburn 3120: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3121: if (keys(%domhelpdesk)) {
3122: push(@accesstypes,('inc','exc'));
3123: push(@jsarray,('notinc','notexc'));
3124: }
3125: my $hiddenstr = join("','",@jsarray);
3126: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3127: my $context = 'domprefs';
3128: my $crstype = 'Course';
1.160.6.77 raeburn 3129: my $prefix = 'helproles_';
3130: my $add_class = 'LC_hidden';
3131: foreach my $num (@roles_by_num) {
3132: my $role = $ordered{$num};
3133: my ($desc,$access,@statuses);
3134: if (ref($current{$role}) eq 'HASH') {
3135: $desc = $current{$role}{'desc'};
3136: $access = $current{$role}{'access'};
3137: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3138: @statuses = @{$current{$role}{'insttypes'}};
3139: }
3140: }
3141: if ($desc eq '') {
3142: $desc = $role;
3143: }
3144: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3145: my %full=();
3146: my %levels= (
3147: course => {},
3148: domain => {},
3149: system => {},
3150: );
3151: my %levelscurrent=(
3152: course => {},
3153: domain => {},
3154: system => {},
3155: );
3156: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3157: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3158: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3159: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3160: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3161: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3162: for (my $k=0; $k<=$maxnum; $k++) {
3163: my $vpos = $k+1;
3164: my $selstr;
3165: if ($k == $num) {
3166: $selstr = ' selected="selected" ';
3167: }
3168: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3169: }
3170: $datatable .= '</select>'.(' 'x2).
3171: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3172: '</td>'.
3173: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3174: &mt('Name shown to users:').
3175: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3176: '</fieldset>'.
3177: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3178: $othertitle,$usertypes,$types,\%domhelpdesk).
3179: '<fieldset>'.
3180: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3181: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3182: \%levelscurrent,$identifier,
3183: 'LC_hidden',$prefix.$num.'_privs').
3184: '</fieldset></td>';
1.160.6.73 raeburn 3185: $itemcount ++;
3186: }
3187: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3188: my $newcust = 'custhelp'.$count;
3189: my (%privs,%levelscurrent);
3190: my %full=();
3191: my %levels= (
3192: course => {},
3193: domain => {},
3194: system => {},
3195: );
3196: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3197: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3198: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3199: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3200: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3201: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3202: for (my $k=0; $k<$maxnum+1; $k++) {
3203: my $vpos = $k+1;
3204: my $selstr;
3205: if ($k == $maxnum) {
3206: $selstr = ' selected="selected" ';
3207: }
3208: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3209: }
3210: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3211: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3212: '</label></span></td>'.
1.160.6.77 raeburn 3213: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3214: '<span class="LC_nobreak">'.
3215: &mt('Internal name:').
3216: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3217: '</span>'.(' 'x4).
3218: '<span class="LC_nobreak">'.
3219: &mt('Name shown to users:').
3220: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3221: '</span></fieldset>'.
3222: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3223: $usertypes,$types,\%domhelpdesk).
3224: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3225: &Apache::lonuserutils::custom_role_header($context,$crstype,
3226: \@templateroles,$newcust).
3227: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3228: \%levelscurrent,$newcust).
1.160.6.87 raeburn 3229: '</fieldset>'.
3230: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3231: '</td></tr>';
1.160.6.73 raeburn 3232: $count ++;
3233: $$rowtotal += $count;
3234: }
1.160.6.5 raeburn 3235: return $datatable;
1.121 raeburn 3236: }
3237:
1.160.6.77 raeburn 3238: sub adhocbutton {
3239: my ($prefix,$num,$field,$visibility) = @_;
3240: my %lt = &Apache::lonlocal::texthash(
3241: show => 'Show details',
3242: hide => 'Hide details',
3243: );
3244: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3245: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3246: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3247: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3248: }
3249:
3250: sub helpsettings_javascript {
3251: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3252: return unless(ref($roles_by_num) eq 'ARRAY');
3253: my %html_js_lt = &Apache::lonlocal::texthash(
3254: show => 'Show details',
3255: hide => 'Hide details',
3256: );
3257: &html_escape(\%html_js_lt);
3258: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3259: return <<"ENDSCRIPT";
3260: <script type="text/javascript">
3261: // <![CDATA[
3262:
3263: function reorderHelpRoles(form,item) {
3264: var changedVal;
3265: $jstext
3266: var newpos = 'helproles_${total}_pos';
3267: var maxh = 1 + $total;
3268: var current = new Array();
3269: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3270: if (item == newpos) {
3271: changedVal = newitemVal;
3272: } else {
3273: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3274: current[newitemVal] = newpos;
3275: }
3276: for (var i=0; i<helproles.length; i++) {
3277: var elementName = 'helproles_'+helproles[i]+'_pos';
3278: if (elementName != item) {
3279: if (form.elements[elementName]) {
3280: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3281: current[currVal] = elementName;
3282: }
3283: }
3284: }
3285: var oldVal;
3286: for (var j=0; j<maxh; j++) {
3287: if (current[j] == undefined) {
3288: oldVal = j;
3289: }
3290: }
3291: if (oldVal < changedVal) {
3292: for (var k=oldVal+1; k<=changedVal ; k++) {
3293: var elementName = current[k];
3294: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3295: }
3296: } else {
3297: for (var k=changedVal; k<oldVal; k++) {
3298: var elementName = current[k];
3299: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3300: }
3301: }
3302: return;
3303: }
3304:
3305: function helpdeskAccess(num) {
3306: var curraccess = null;
3307: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3308: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3309: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3310: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3311: }
3312: }
3313: }
3314: var shown = Array();
3315: var hidden = Array();
3316: if (curraccess == 'none') {
3317: hidden = Array('$hiddenstr');
3318: } else {
3319: if (curraccess == 'status') {
3320: shown = Array('bystatus');
3321: hidden = Array('notinc','notexc');
3322: } else {
3323: if (curraccess == 'exc') {
3324: shown = Array('notexc');
3325: hidden = Array('notinc','bystatus');
3326: }
3327: if (curraccess == 'inc') {
3328: shown = Array('notinc');
3329: hidden = Array('notexc','bystatus');
3330: }
1.160.6.79 raeburn 3331: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3332: hidden = Array('notinc','notexc','bystatus');
3333: }
3334: }
3335: }
3336: if (hidden.length > 0) {
3337: for (var i=0; i<hidden.length; i++) {
3338: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3339: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3340: }
3341: }
3342: }
3343: if (shown.length > 0) {
3344: for (var i=0; i<shown.length; i++) {
3345: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3346: if (shown[i] == 'privs') {
3347: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3348: } else {
3349: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3350: }
3351: }
3352: }
3353: }
3354: return;
3355: }
3356:
3357: function toggleHelpdeskItem(num,field) {
3358: if (document.getElementById('helproles_'+num+'_'+field)) {
3359: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3360: document.getElementById('helproles_'+num+'_'+field).className =
3361: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3362: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3363: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3364: }
3365: } else {
3366: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3367: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3368: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3369: }
3370: }
3371: }
3372: return;
3373: }
3374:
3375: // ]]>
3376: </script>
3377:
3378: ENDSCRIPT
3379: }
3380:
3381: sub helpdeskroles_access {
3382: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3383: $usertypes,$types,$domhelpdesk) = @_;
3384: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3385: my %lt = &Apache::lonlocal::texthash(
3386: 'rou' => 'Role usage',
3387: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3388: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3389: 'dh' => 'All with domain helpdesk role',
3390: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3391: 'none' => 'None',
3392: 'status' => 'Determined based on institutional status',
3393: 'inc' => 'Include all, but exclude specific personnel',
3394: 'exc' => 'Exclude all, but include specific personnel',
3395: );
3396: my %usecheck = (
3397: all => ' checked="checked"',
3398: );
3399: my %displaydiv = (
3400: status => 'none',
3401: inc => 'none',
3402: exc => 'none',
3403: priv => 'block',
3404: );
3405: my $output;
3406: if (ref($current) eq 'HASH') {
3407: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3408: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3409: $usecheck{$current->{access}} = $usecheck{'all'};
3410: delete($usecheck{'all'});
3411: if ($current->{access} =~ /^(status|inc|exc)$/) {
3412: my $access = $1;
3413: $displaydiv{$access} = 'inline';
3414: } elsif ($current->{access} eq 'none') {
3415: $displaydiv{'priv'} = 'none';
3416: }
3417: }
3418: }
3419: }
3420: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3421: '<p>'.$lt{'whi'}.'</p>';
3422: foreach my $access (@{$accesstypes}) {
3423: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3424: ' onclick="helpdeskAccess('."'$num'".');" />'.
3425: $lt{$access}.'</label>';
3426: if ($access eq 'status') {
3427: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3428: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3429: $othertitle,$usertypes,$types).
3430: '</div>';
3431: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3432: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3433: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3434: '</div>';
3435: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3436: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3437: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3438: '</div>';
3439: }
3440: $output .= '</p>';
3441: }
3442: $output .= '</fieldset>';
3443: return $output;
3444: }
3445:
1.121 raeburn 3446: sub radiobutton_prefs {
1.160.6.16 raeburn 3447: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3448: $additional,$align) = @_;
1.121 raeburn 3449: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3450: (ref($choices) eq 'HASH'));
3451:
3452: my (%checkedon,%checkedoff,$datatable,$css_class);
3453:
3454: foreach my $item (@{$toggles}) {
3455: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3456: $checkedon{$item} = ' checked="checked" ';
3457: $checkedoff{$item} = ' ';
1.121 raeburn 3458: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3459: $checkedoff{$item} = ' checked="checked" ';
3460: $checkedon{$item} = ' ';
3461: }
3462: }
3463: if (ref($settings) eq 'HASH') {
1.121 raeburn 3464: foreach my $item (@{$toggles}) {
1.118 jms 3465: if ($settings->{$item} eq '1') {
3466: $checkedon{$item} = ' checked="checked" ';
3467: $checkedoff{$item} = ' ';
3468: } elsif ($settings->{$item} eq '0') {
3469: $checkedoff{$item} = ' checked="checked" ';
3470: $checkedon{$item} = ' ';
3471: }
3472: }
1.121 raeburn 3473: }
1.160.6.16 raeburn 3474: if ($onclick) {
3475: $onclick = ' onclick="'.$onclick.'"';
3476: }
1.121 raeburn 3477: foreach my $item (@{$toggles}) {
1.118 jms 3478: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3479: $datatable .=
1.160.6.16 raeburn 3480: '<tr'.$css_class.'><td valign="top">'.
3481: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3482: '</span></td>';
3483: if ($align eq 'left') {
3484: $datatable .= '<td class="LC_left_item">';
3485: } else {
3486: $datatable .= '<td class="LC_right_item">';
3487: }
3488: $datatable .=
3489: '<span class="LC_nobreak">'.
1.118 jms 3490: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3491: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3492: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3493: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3494: '</span>'.$additional.
3495: '</td>'.
1.118 jms 3496: '</tr>';
3497: $itemcount ++;
1.121 raeburn 3498: }
3499: return ($datatable,$itemcount);
3500: }
3501:
3502: sub print_coursedefaults {
1.139 raeburn 3503: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3504: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3505: my $itemcount = 1;
1.160.6.16 raeburn 3506: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3507: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3508: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3509: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3510: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3511: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90 raeburn 3512: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 3513: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3514: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3515: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3516: );
1.160.6.21 raeburn 3517: my %staticdefaults = (
3518: anonsurvey_threshold => 10,
3519: uploadquota => 500,
1.160.6.57 raeburn 3520: postsubmit => 60,
1.160.6.70 raeburn 3521: mysqltables => 172800,
1.160.6.21 raeburn 3522: );
1.139 raeburn 3523: if ($position eq 'top') {
1.160.6.57 raeburn 3524: %defaultchecked = (
3525: 'uselcmath' => 'on',
3526: 'usejsme' => 'on',
1.160.6.64 raeburn 3527: 'canclone' => 'none',
1.160.6.57 raeburn 3528: );
3529: @toggles = ('uselcmath','usejsme');
1.160.6.90 raeburn 3530: my $deftex = $Apache::lonnet::deftex;
3531: if (ref($settings) eq 'HASH') {
3532: if ($settings->{'texengine'}) {
3533: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
3534: $deftex = $settings->{'texengine'};
3535: }
3536: }
3537: }
3538: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3539: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
3540: '<span class="LC_nobreak">'.$choices{'texengine'}.
3541: '</span></td><td class="LC_right_item">'.
3542: '<select name="texengine">'."\n";
3543: my %texoptions = (
3544: MathJax => 'MathJax',
3545: mimetex => &mt('Convert to Images'),
3546: tth => &mt('TeX to HTML'),
3547: );
3548: foreach my $renderer ('MathJax','mimetex','tth') {
3549: my $selected = '';
3550: if ($renderer eq $deftex) {
3551: $selected = ' selected="selected"';
3552: }
3553: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
3554: }
3555: $mathdisp .= '</select></td></tr>'."\n";
3556: $itemcount ++;
1.139 raeburn 3557: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3558: \%choices,$itemcount);
1.160.6.90 raeburn 3559: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 3560: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3561: $datatable .=
3562: '<tr'.$css_class.'><td valign="top">'.
3563: '<span class="LC_nobreak">'.$choices{'canclone'}.
3564: '</span></td><td class="LC_left_item">';
3565: my $currcanclone = 'none';
3566: my $onclick;
3567: my @cloneoptions = ('none','domain');
3568: my %clonetitles = (
3569: none => 'No additional course requesters',
3570: domain => "Any course requester in course's domain",
3571: instcode => 'Course requests for official courses ...',
3572: );
3573: my (%codedefaults,@code_order,@posscodes);
3574: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3575: \@code_order) eq 'ok') {
3576: if (@code_order > 0) {
3577: push(@cloneoptions,'instcode');
3578: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3579: }
3580: }
3581: if (ref($settings) eq 'HASH') {
3582: if ($settings->{'canclone'}) {
3583: if (ref($settings->{'canclone'}) eq 'HASH') {
3584: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3585: if (@code_order > 0) {
3586: $currcanclone = 'instcode';
3587: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3588: }
3589: }
3590: } elsif ($settings->{'canclone'} eq 'domain') {
3591: $currcanclone = $settings->{'canclone'};
3592: }
3593: }
3594: }
3595: foreach my $option (@cloneoptions) {
3596: my ($checked,$additional);
3597: if ($currcanclone eq $option) {
3598: $checked = ' checked="checked"';
3599: }
3600: if ($option eq 'instcode') {
3601: if (@code_order) {
3602: my $show = 'none';
3603: if ($checked) {
3604: $show = 'block';
3605: }
3606: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3607: &mt('Institutional codes for new and cloned course have identical:').
3608: '<br />';
3609: foreach my $item (@code_order) {
3610: my $codechk;
3611: if ($checked) {
3612: if (grep(/^\Q$item\E$/,@posscodes)) {
3613: $codechk = ' checked="checked"';
3614: }
3615: }
3616: $additional .= '<label>'.
3617: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3618: $item.'</label>';
3619: }
3620: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3621: }
3622: }
3623: $datatable .=
3624: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3625: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3626: '</label> '.$additional.'</span><br />';
3627: }
3628: $datatable .= '</td>'.
3629: '</tr>';
3630: $itemcount ++;
1.139 raeburn 3631: } else {
3632: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3633: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3634: my $currusecredits = 0;
1.160.6.57 raeburn 3635: my $postsubmitclient = 1;
1.160.6.30 raeburn 3636: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3637: if (ref($settings) eq 'HASH') {
3638: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3639: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3640: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3641: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3642: }
3643: }
1.160.6.16 raeburn 3644: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3645: foreach my $type (@types) {
3646: next if ($type eq 'community');
3647: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3648: if ($defcredits{$type} ne '') {
3649: $currusecredits = 1;
3650: }
3651: }
3652: }
3653: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3654: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3655: $postsubmitclient = 0;
3656: foreach my $type (@types) {
3657: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3658: }
3659: } else {
3660: foreach my $type (@types) {
3661: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3662: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3663: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3664: } else {
3665: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3666: }
3667: } else {
3668: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3669: }
3670: }
3671: }
3672: } else {
3673: foreach my $type (@types) {
3674: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3675: }
3676: }
1.160.6.70 raeburn 3677: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3678: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3679: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3680: }
3681: } else {
3682: foreach my $type (@types) {
3683: $currmysql{$type} = $staticdefaults{'mysqltables'};
3684: }
3685: }
1.160.6.58 raeburn 3686: } else {
3687: foreach my $type (@types) {
3688: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3689: }
1.139 raeburn 3690: }
3691: if (!$currdefresponder) {
1.160.6.21 raeburn 3692: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3693: } elsif ($currdefresponder < 1) {
3694: $currdefresponder = 1;
3695: }
1.160.6.21 raeburn 3696: foreach my $type (@types) {
3697: if ($curruploadquota{$type} eq '') {
3698: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3699: }
3700: }
1.139 raeburn 3701: $datatable .=
1.160.6.16 raeburn 3702: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3703: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3704: '</span></td>'.
3705: '<td class="LC_right_item"><span class="LC_nobreak">'.
3706: '<input type="text" name="anonsurvey_threshold"'.
3707: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3708: '</td></tr>'."\n";
3709: $itemcount ++;
3710: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3711: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3712: $choices{'uploadquota'}.
3713: '</span></td>'.
3714: '<td align="right" class="LC_right_item">'.
3715: '<table><tr>';
1.160.6.21 raeburn 3716: foreach my $type (@types) {
3717: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3718: '<input type="text" name="uploadquota_'.$type.'"'.
3719: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3720: }
3721: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3722: $itemcount ++;
1.160.6.40 raeburn 3723: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3724: my $display = 'none';
3725: if ($currusecredits) {
3726: $display = 'block';
3727: }
3728: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3729: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3730: foreach my $type (@types) {
3731: next if ($type eq 'community');
3732: $additional .= '<td align="center">'.&mt($type).'<br />'.
3733: '<input type="text" name="'.$type.'_credits"'.
3734: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3735: }
3736: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3737: %defaultchecked = ('coursecredits' => 'off');
3738: @toggles = ('coursecredits');
3739: my $current = {
3740: 'coursecredits' => $currusecredits,
3741: };
3742: (my $table,$itemcount) =
3743: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3744: \%choices,$itemcount,$onclick,$additional,'left');
3745: $datatable .= $table;
3746: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3747: my $display = 'none';
3748: if ($postsubmitclient) {
3749: $display = 'block';
3750: }
3751: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3752: &mt('Number of seconds submit is disabled').'<br />'.
3753: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3754: '<table><tr>';
1.160.6.57 raeburn 3755: foreach my $type (@types) {
3756: $additional .= '<td align="center">'.&mt($type).'<br />'.
3757: '<input type="text" name="'.$type.'_timeout" value="'.
3758: $deftimeout{$type}.'" size="5" /></td>';
3759: }
3760: $additional .= '</tr></table></div>'."\n";
3761: %defaultchecked = ('postsubmit' => 'on');
3762: @toggles = ('postsubmit');
1.160.6.70 raeburn 3763: $current = {
3764: 'postsubmit' => $postsubmitclient,
3765: };
1.160.6.57 raeburn 3766: ($table,$itemcount) =
3767: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3768: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3769: $datatable .= $table;
1.160.6.70 raeburn 3770: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3771: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3772: $choices{'mysqltables'}.
3773: '</span></td>'.
3774: '<td align="right" class="LC_right_item">'.
3775: '<table><tr>';
3776: foreach my $type (@types) {
3777: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3778: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 3779: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 3780: }
3781: $datatable .= '</tr></table></td></tr>'."\n";
3782: $itemcount ++;
3783:
1.160.6.37 raeburn 3784: }
3785: $$rowtotal += $itemcount;
3786: return $datatable;
3787: }
3788:
3789: sub print_selfenrollment {
3790: my ($position,$dom,$settings,$rowtotal) = @_;
3791: my ($css_class,$datatable);
3792: my $itemcount = 1;
3793: my @types = ('official','unofficial','community','textbook');
3794: if (($position eq 'top') || ($position eq 'middle')) {
3795: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3796: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3797: my @rows;
3798: my $key;
3799: if ($position eq 'top') {
3800: $key = 'admin';
3801: if (ref($rowsref) eq 'ARRAY') {
3802: @rows = @{$rowsref};
3803: }
3804: } elsif ($position eq 'middle') {
3805: $key = 'default';
3806: @rows = ('types','registered','approval','limit');
3807: }
3808: foreach my $row (@rows) {
3809: if (defined($titlesref->{$row})) {
3810: $itemcount ++;
3811: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3812: $datatable .= '<tr'.$css_class.'>'.
3813: '<td>'.$titlesref->{$row}.'</td>'.
3814: '<td class="LC_left_item">'.
3815: '<table><tr>';
3816: my (%current,%currentcap);
3817: if (ref($settings) eq 'HASH') {
3818: if (ref($settings->{$key}) eq 'HASH') {
3819: foreach my $type (@types) {
3820: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3821: $current{$type} = $settings->{$key}->{$type}->{$row};
3822: }
3823: if (($row eq 'limit') && ($key eq 'default')) {
3824: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3825: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3826: }
3827: }
3828: }
3829: }
3830: }
3831: my %roles = (
3832: '0' => &Apache::lonnet::plaintext('dc'),
3833: );
3834:
3835: foreach my $type (@types) {
3836: unless (($row eq 'registered') && ($key eq 'default')) {
3837: $datatable .= '<th>'.&mt($type).'</th>';
3838: }
3839: }
3840: unless (($row eq 'registered') && ($key eq 'default')) {
3841: $datatable .= '</tr><tr>';
3842: }
3843: foreach my $type (@types) {
3844: if ($type eq 'community') {
3845: $roles{'1'} = &mt('Community personnel');
3846: } else {
3847: $roles{'1'} = &mt('Course personnel');
3848: }
3849: $datatable .= '<td style="vertical-align: top">';
3850: if ($position eq 'top') {
3851: my %checked;
3852: if ($current{$type} eq '0') {
3853: $checked{'0'} = ' checked="checked"';
3854: } else {
3855: $checked{'1'} = ' checked="checked"';
3856: }
3857: foreach my $role ('1','0') {
3858: $datatable .= '<span class="LC_nobreak"><label>'.
3859: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3860: 'value="'.$role.'"'.$checked{$role}.' />'.
3861: $roles{$role}.'</label></span> ';
3862: }
3863: } else {
3864: if ($row eq 'types') {
3865: my %checked;
3866: if ($current{$type} =~ /^(all|dom)$/) {
3867: $checked{$1} = ' checked="checked"';
3868: } else {
3869: $checked{''} = ' checked="checked"';
3870: }
3871: foreach my $val ('','dom','all') {
3872: $datatable .= '<span class="LC_nobreak"><label>'.
3873: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3874: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3875: }
3876: } elsif ($row eq 'registered') {
3877: my %checked;
3878: if ($current{$type} eq '1') {
3879: $checked{'1'} = ' checked="checked"';
3880: } else {
3881: $checked{'0'} = ' checked="checked"';
3882: }
3883: foreach my $val ('0','1') {
3884: $datatable .= '<span class="LC_nobreak"><label>'.
3885: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3886: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3887: }
3888: } elsif ($row eq 'approval') {
3889: my %checked;
3890: if ($current{$type} =~ /^([12])$/) {
3891: $checked{$1} = ' checked="checked"';
3892: } else {
3893: $checked{'0'} = ' checked="checked"';
3894: }
3895: for my $val (0..2) {
3896: $datatable .= '<span class="LC_nobreak"><label>'.
3897: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3898: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3899: }
3900: } elsif ($row eq 'limit') {
3901: my %checked;
3902: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3903: $checked{$1} = ' checked="checked"';
3904: } else {
3905: $checked{'none'} = ' checked="checked"';
3906: }
3907: my $cap;
3908: if ($currentcap{$type} =~ /^\d+$/) {
3909: $cap = $currentcap{$type};
3910: }
3911: foreach my $val ('none','allstudents','selfenrolled') {
3912: $datatable .= '<span class="LC_nobreak"><label>'.
3913: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3914: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3915: }
3916: $datatable .= '<br />'.
3917: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3918: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3919: '</span>';
3920: }
3921: }
3922: $datatable .= '</td>';
3923: }
3924: $datatable .= '</tr>';
3925: }
3926: $datatable .= '</table></td></tr>';
3927: }
3928: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3929: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3930: }
3931: $$rowtotal += $itemcount;
3932: return $datatable;
3933: }
3934:
3935: sub print_validation_rows {
3936: my ($caller,$dom,$settings,$rowtotal) = @_;
3937: my ($itemsref,$namesref,$fieldsref);
3938: if ($caller eq 'selfenroll') {
3939: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3940: } elsif ($caller eq 'requestcourses') {
3941: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3942: }
3943: my %currvalidation;
3944: if (ref($settings) eq 'HASH') {
3945: if (ref($settings->{'validation'}) eq 'HASH') {
3946: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3947: }
1.160.6.39 raeburn 3948: }
3949: my $datatable;
3950: my $itemcount = 0;
3951: foreach my $item (@{$itemsref}) {
3952: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3953: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3954: $namesref->{$item}.
3955: '</span></td>'.
3956: '<td class="LC_left_item">';
3957: if (($item eq 'url') || ($item eq 'button')) {
3958: $datatable .= '<span class="LC_nobreak">'.
3959: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3960: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3961: } elsif ($item eq 'fields') {
3962: my @currfields;
3963: if (ref($currvalidation{$item}) eq 'ARRAY') {
3964: @currfields = @{$currvalidation{$item}};
3965: }
3966: foreach my $field (@{$fieldsref}) {
3967: my $check = '';
3968: if (grep(/^\Q$field\E$/,@currfields)) {
3969: $check = ' checked="checked"';
3970: }
3971: $datatable .= '<span class="LC_nobreak"><label>'.
3972: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3973: ' value="'.$field.'"'.$check.' />'.$field.
3974: '</label></span> ';
3975: }
3976: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 3977: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 3978: $currvalidation{$item}.
1.160.6.37 raeburn 3979: '</textarea>';
1.160.6.39 raeburn 3980: }
3981: $datatable .= '</td></tr>'."\n";
3982: if (ref($rowtotal)) {
1.160.6.37 raeburn 3983: $itemcount ++;
3984: }
1.139 raeburn 3985: }
1.160.6.39 raeburn 3986: if ($caller eq 'requestcourses') {
3987: my %currhash;
1.160.6.51 raeburn 3988: if (ref($settings) eq 'HASH') {
3989: if (ref($settings->{'validation'}) eq 'HASH') {
3990: if ($settings->{'validation'}{'dc'} ne '') {
3991: $currhash{$settings->{'validation'}{'dc'}} = 1;
3992: }
1.160.6.39 raeburn 3993: }
3994: }
3995: my $numinrow = 2;
3996: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3997: 'validationdc',%currhash);
1.160.6.50 raeburn 3998: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 3999: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 4000: if ($numdc > 1) {
1.160.6.50 raeburn 4001: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 4002: } else {
1.160.6.50 raeburn 4003: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 4004: }
1.160.6.50 raeburn 4005: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 4006: $itemcount ++;
4007: }
4008: if (ref($rowtotal)) {
4009: $$rowtotal += $itemcount;
4010: }
1.121 raeburn 4011: return $datatable;
1.118 jms 4012: }
4013:
1.137 raeburn 4014: sub print_usersessions {
4015: my ($position,$dom,$settings,$rowtotal) = @_;
4016: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 4017: my (%by_ip,%by_location,@intdoms);
4018: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 4019:
4020: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4021: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4022: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4023: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4024: my $itemcount = 1;
4025: if ($position eq 'top') {
1.152 raeburn 4026: if (keys(%serverhomes) > 1) {
1.145 raeburn 4027: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 4028: my $curroffloadnow;
4029: if (ref($settings) eq 'HASH') {
4030: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4031: $curroffloadnow = $settings->{'offloadnow'};
4032: }
4033: }
4034: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4035: } else {
1.140 raeburn 4036: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4037: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 4038: }
1.137 raeburn 4039: } else {
1.145 raeburn 4040: if (keys(%by_location) == 0) {
4041: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4042: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 4043: } else {
4044: my %lt = &usersession_titles();
4045: my $numinrow = 5;
4046: my $prefix;
4047: my @types;
4048: if ($position eq 'bottom') {
4049: $prefix = 'remote';
4050: @types = ('version','excludedomain','includedomain');
4051: } else {
4052: $prefix = 'hosted';
4053: @types = ('excludedomain','includedomain');
4054: }
4055: my (%current,%checkedon,%checkedoff);
4056: my @lcversions = &Apache::lonnet::all_loncaparevs();
4057: my @locations = sort(keys(%by_location));
4058: foreach my $type (@types) {
4059: $checkedon{$type} = '';
4060: $checkedoff{$type} = ' checked="checked"';
4061: }
4062: if (ref($settings) eq 'HASH') {
4063: if (ref($settings->{$prefix}) eq 'HASH') {
4064: foreach my $key (keys(%{$settings->{$prefix}})) {
4065: $current{$key} = $settings->{$prefix}{$key};
4066: if ($key eq 'version') {
4067: if ($current{$key} ne '') {
4068: $checkedon{$key} = ' checked="checked"';
4069: $checkedoff{$key} = '';
4070: }
4071: } elsif (ref($current{$key}) eq 'ARRAY') {
4072: $checkedon{$key} = ' checked="checked"';
4073: $checkedoff{$key} = '';
4074: }
1.137 raeburn 4075: }
4076: }
4077: }
1.145 raeburn 4078: foreach my $type (@types) {
4079: next if ($type ne 'version' && !@locations);
4080: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4081: $datatable .= '<tr'.$css_class.'>
4082: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4083: <span class="LC_nobreak">
4084: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4085: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4086: if ($type eq 'version') {
4087: my $selector = '<select name="'.$prefix.'_version">';
4088: foreach my $version (@lcversions) {
4089: my $selected = '';
4090: if ($current{'version'} eq $version) {
4091: $selected = ' selected="selected"';
4092: }
4093: $selector .= ' <option value="'.$version.'"'.
4094: $selected.'>'.$version.'</option>';
4095: }
4096: $selector .= '</select> ';
4097: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4098: } else {
4099: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4100: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4101: ' />'.(' 'x2).
4102: '<input type="button" value="'.&mt('uncheck all').'" '.
4103: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4104: "\n".
4105: '</div><div><table>';
4106: my $rem;
4107: for (my $i=0; $i<@locations; $i++) {
4108: my ($showloc,$value,$checkedtype);
4109: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4110: my $ip = $by_location{$locations[$i]}->[0];
4111: if (ref($by_ip{$ip}) eq 'ARRAY') {
4112: $value = join(':',@{$by_ip{$ip}});
4113: $showloc = join(', ',@{$by_ip{$ip}});
4114: if (ref($current{$type}) eq 'ARRAY') {
4115: foreach my $loc (@{$by_ip{$ip}}) {
4116: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4117: $checkedtype = ' checked="checked"';
4118: last;
4119: }
4120: }
1.138 raeburn 4121: }
4122: }
4123: }
1.145 raeburn 4124: $rem = $i%($numinrow);
4125: if ($rem == 0) {
4126: if ($i > 0) {
4127: $datatable .= '</tr>';
4128: }
4129: $datatable .= '<tr>';
4130: }
4131: $datatable .= '<td class="LC_left_item">'.
4132: '<span class="LC_nobreak"><label>'.
4133: '<input type="checkbox" name="'.$prefix.'_'.$type.
4134: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4135: '</label></span></td>';
1.137 raeburn 4136: }
1.145 raeburn 4137: $rem = @locations%($numinrow);
4138: my $colsleft = $numinrow - $rem;
4139: if ($colsleft > 1 ) {
4140: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4141: ' </td>';
4142: } elsif ($colsleft == 1) {
4143: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4144: }
1.145 raeburn 4145: $datatable .= '</tr></table>';
1.137 raeburn 4146: }
1.145 raeburn 4147: $datatable .= '</td></tr>';
4148: $itemcount ++;
1.137 raeburn 4149: }
4150: }
4151: }
4152: $$rowtotal += $itemcount;
4153: return $datatable;
4154: }
4155:
1.138 raeburn 4156: sub build_location_hashes {
4157: my ($intdoms,$by_ip,$by_location) = @_;
4158: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4159: (ref($by_location) eq 'HASH'));
4160: my %iphost = &Apache::lonnet::get_iphost();
4161: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4162: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4163: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4164: foreach my $id (@{$iphost{$primary_ip}}) {
4165: my $intdom = &Apache::lonnet::internet_dom($id);
4166: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4167: push(@{$intdoms},$intdom);
4168: }
4169: }
4170: }
4171: foreach my $ip (keys(%iphost)) {
4172: if (ref($iphost{$ip}) eq 'ARRAY') {
4173: foreach my $id (@{$iphost{$ip}}) {
4174: my $location = &Apache::lonnet::internet_dom($id);
4175: if ($location) {
4176: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4177: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4178: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4179: push(@{$by_ip->{$ip}},$location);
4180: }
4181: } else {
4182: $by_ip->{$ip} = [$location];
4183: }
4184: }
4185: }
4186: }
4187: }
4188: foreach my $ip (sort(keys(%{$by_ip}))) {
4189: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4190: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4191: my $first = $by_ip->{$ip}->[0];
4192: if (ref($by_location->{$first}) eq 'ARRAY') {
4193: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4194: push(@{$by_location->{$first}},$ip);
4195: }
4196: } else {
4197: $by_location->{$first} = [$ip];
4198: }
4199: }
4200: }
4201: return;
4202: }
4203:
1.145 raeburn 4204: sub current_offloads_to {
4205: my ($dom,$settings,$servers) = @_;
4206: my (%spareid,%otherdomconfigs);
1.152 raeburn 4207: if (ref($servers) eq 'HASH') {
1.145 raeburn 4208: foreach my $lonhost (sort(keys(%{$servers}))) {
4209: my $gotspares;
1.152 raeburn 4210: if (ref($settings) eq 'HASH') {
4211: if (ref($settings->{'spares'}) eq 'HASH') {
4212: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4213: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4214: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4215: $gotspares = 1;
4216: }
1.145 raeburn 4217: }
4218: }
4219: unless ($gotspares) {
4220: my $gotspares;
4221: my $serverhomeID =
4222: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4223: my $serverhomedom =
4224: &Apache::lonnet::host_domain($serverhomeID);
4225: if ($serverhomedom ne $dom) {
4226: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4227: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4228: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4229: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4230: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4231: $gotspares = 1;
4232: }
4233: }
4234: } else {
4235: $otherdomconfigs{$serverhomedom} =
4236: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4237: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4238: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4239: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4240: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4241: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4242: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4243: $gotspares = 1;
4244: }
4245: }
4246: }
4247: }
4248: }
4249: }
4250: }
4251: unless ($gotspares) {
4252: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4253: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4254: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4255: } else {
4256: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4257: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4258: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4259: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4260: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4261: } else {
1.150 raeburn 4262: my %what = (
4263: spareid => 1,
4264: );
4265: my ($result,$returnhash) =
4266: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4267: if ($result eq 'ok') {
4268: if (ref($returnhash) eq 'HASH') {
4269: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4270: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4271: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4272: }
4273: }
1.145 raeburn 4274: }
4275: }
4276: }
4277: }
4278: }
4279: }
4280: return %spareid;
4281: }
4282:
4283: sub spares_row {
1.160.6.61 raeburn 4284: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4285: my $css_class;
4286: my $numinrow = 4;
4287: my $itemcount = 1;
4288: my $datatable;
1.152 raeburn 4289: my %typetitles = &sparestype_titles();
4290: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4291: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4292: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4293: my ($othercontrol,$serverdom);
4294: if ($serverhome ne $server) {
4295: $serverdom = &Apache::lonnet::host_domain($serverhome);
4296: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4297: } else {
4298: $serverdom = &Apache::lonnet::host_domain($server);
4299: if ($serverdom ne $dom) {
4300: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4301: }
4302: }
4303: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4304: my $checkednow;
4305: if (ref($curroffloadnow) eq 'HASH') {
4306: if ($curroffloadnow->{$server}) {
4307: $checkednow = ' checked="checked"';
4308: }
4309: }
1.145 raeburn 4310: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4311: $datatable .= '<tr'.$css_class.'>
4312: <td rowspan="2">
1.160.6.13 raeburn 4313: <span class="LC_nobreak">'.
4314: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4315: ,'<b>'.$server.'</b>').'</span><br />'.
4316: '<span class="LC_nobreak">'."\n".
4317: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4318: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4319: "\n";
1.145 raeburn 4320: my (%current,%canselect);
1.152 raeburn 4321: my @choices =
4322: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4323: foreach my $type ('primary','default') {
4324: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4325: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4326: my @spares = @{$spareid->{$server}{$type}};
4327: if (@spares > 0) {
1.152 raeburn 4328: if ($othercontrol) {
4329: $current{$type} = join(', ',@spares);
4330: } else {
4331: $current{$type} .= '<table>';
4332: my $numspares = scalar(@spares);
4333: for (my $i=0; $i<@spares; $i++) {
4334: my $rem = $i%($numinrow);
4335: if ($rem == 0) {
4336: if ($i > 0) {
4337: $current{$type} .= '</tr>';
4338: }
4339: $current{$type} .= '<tr>';
1.145 raeburn 4340: }
1.152 raeburn 4341: $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'".');" /> '.
4342: $spareid->{$server}{$type}[$i].
4343: '</label></td>'."\n";
4344: }
4345: my $rem = @spares%($numinrow);
4346: my $colsleft = $numinrow - $rem;
4347: if ($colsleft > 1 ) {
4348: $current{$type} .= '<td colspan="'.$colsleft.
4349: '" class="LC_left_item">'.
4350: ' </td>';
4351: } elsif ($colsleft == 1) {
4352: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4353: }
1.152 raeburn 4354: $current{$type} .= '</tr></table>';
1.150 raeburn 4355: }
1.145 raeburn 4356: }
4357: }
4358: if ($current{$type} eq '') {
4359: $current{$type} = &mt('None specified');
4360: }
1.152 raeburn 4361: if ($othercontrol) {
4362: if ($type eq 'primary') {
4363: $canselect{$type} = $othercontrol;
4364: }
4365: } else {
4366: $canselect{$type} =
4367: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4368: '<select name="newspare_'.$type.'_'.$server.'" '.
4369: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4370: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4371: if (@choices > 0) {
4372: foreach my $lonhost (@choices) {
4373: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4374: }
4375: }
4376: $canselect{$type} .= '</select>'."\n";
4377: }
4378: } else {
4379: $current{$type} = &mt('Could not be determined');
4380: if ($type eq 'primary') {
4381: $canselect{$type} = $othercontrol;
4382: }
1.145 raeburn 4383: }
1.152 raeburn 4384: if ($type eq 'default') {
4385: $datatable .= '<tr'.$css_class.'>';
4386: }
4387: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4388: '<td>'.$current{$type}.'</td>'."\n".
4389: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4390: }
4391: $itemcount ++;
4392: }
4393: }
4394: $$rowtotal += $itemcount;
4395: return $datatable;
4396: }
4397:
1.152 raeburn 4398: sub possible_newspares {
4399: my ($server,$currspares,$serverhomes,$altids) = @_;
4400: my $serverhostname = &Apache::lonnet::hostname($server);
4401: my %excluded;
4402: if ($serverhostname ne '') {
4403: %excluded = (
4404: $serverhostname => 1,
4405: );
4406: }
4407: if (ref($currspares) eq 'HASH') {
4408: foreach my $type (keys(%{$currspares})) {
4409: if (ref($currspares->{$type}) eq 'ARRAY') {
4410: if (@{$currspares->{$type}} > 0) {
4411: foreach my $curr (@{$currspares->{$type}}) {
4412: my $hostname = &Apache::lonnet::hostname($curr);
4413: $excluded{$hostname} = 1;
4414: }
4415: }
4416: }
4417: }
4418: }
4419: my @choices;
4420: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4421: if (keys(%{$serverhomes}) > 1) {
4422: foreach my $name (sort(keys(%{$serverhomes}))) {
4423: unless ($excluded{$name}) {
4424: if (exists($altids->{$serverhomes->{$name}})) {
4425: push(@choices,$altids->{$serverhomes->{$name}});
4426: } else {
4427: push(@choices,$serverhomes->{$name});
1.145 raeburn 4428: }
4429: }
4430: }
4431: }
4432: }
1.152 raeburn 4433: return sort(@choices);
1.145 raeburn 4434: }
4435:
1.150 raeburn 4436: sub print_loadbalancing {
4437: my ($dom,$settings,$rowtotal) = @_;
4438: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4439: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4440: my $numinrow = 1;
4441: my $datatable;
4442: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 4443: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 4444: if (ref($settings) eq 'HASH') {
4445: %existing = %{$settings};
4446: }
4447: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4448: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 4449: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 4450: } else {
4451: return;
4452: }
4453: my ($othertitle,$usertypes,$types) =
4454: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 4455: my $rownum = 8;
1.150 raeburn 4456: if (ref($types) eq 'ARRAY') {
4457: $rownum += scalar(@{$types});
4458: }
1.160.6.7 raeburn 4459: my @css_class = ('LC_odd_row','LC_even_row');
4460: my $balnum = 0;
4461: my $islast;
4462: my (@toshow,$disabledtext);
4463: if (keys(%currbalancer) > 0) {
4464: @toshow = sort(keys(%currbalancer));
4465: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4466: push(@toshow,'');
4467: }
4468: } else {
4469: @toshow = ('');
4470: $disabledtext = &mt('No existing load balancer');
4471: }
4472: foreach my $lonhost (@toshow) {
4473: if ($balnum == scalar(@toshow)-1) {
4474: $islast = 1;
4475: } else {
4476: $islast = 0;
4477: }
4478: my $cssidx = $balnum%2;
4479: my $targets_div_style = 'display: none';
4480: my $disabled_div_style = 'display: block';
4481: my $homedom_div_style = 'display: none';
4482: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4483: '<td rowspan="'.$rownum.'" valign="top">'.
4484: '<p>';
4485: if ($lonhost eq '') {
4486: $datatable .= '<span class="LC_nobreak">';
4487: if (keys(%currbalancer) > 0) {
4488: $datatable .= &mt('Add balancer:');
4489: } else {
4490: $datatable .= &mt('Enable balancer:');
4491: }
4492: $datatable .= ' '.
4493: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4494: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4495: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4496: '<option value="" selected="selected">'.&mt('None').
4497: '</option>'."\n";
4498: foreach my $server (sort(keys(%servers))) {
4499: next if ($currbalancer{$server});
4500: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4501: }
4502: $datatable .=
4503: '</select>'."\n".
4504: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4505: } else {
4506: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4507: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4508: &mt('Stop balancing').'</label>'.
4509: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4510: $targets_div_style = 'display: block';
4511: $disabled_div_style = 'display: none';
4512: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4513: $homedom_div_style = 'display: block';
4514: }
4515: }
4516: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4517: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4518: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4519: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4520: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4521: my @sparestypes = ('primary','default');
4522: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 4523: my %hostherechecked = (
4524: no => ' checked="checked"',
4525: );
1.160.6.94 raeburn 4526: my %balcookiechecked = (
4527: no => ' checked="checked"',
4528: );
1.160.6.7 raeburn 4529: foreach my $sparetype (@sparestypes) {
4530: my $targettable;
4531: for (my $i=0; $i<$numspares; $i++) {
4532: my $checked;
4533: if (ref($currtargets{$lonhost}) eq 'HASH') {
4534: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4535: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4536: $checked = ' checked="checked"';
4537: }
4538: }
4539: }
4540: my ($chkboxval,$disabled);
4541: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4542: $chkboxval = $spares[$i];
4543: }
4544: if (exists($currbalancer{$spares[$i]})) {
4545: $disabled = ' disabled="disabled"';
4546: }
4547: $targettable .=
1.160.6.55 raeburn 4548: '<td><span class="LC_nobreak"><label>'.
4549: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 4550: $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 4551: '</span></label></span></td>';
1.160.6.7 raeburn 4552: my $rem = $i%($numinrow);
4553: if ($rem == 0) {
4554: if (($i > 0) && ($i < $numspares-1)) {
4555: $targettable .= '</tr>';
4556: }
4557: if ($i < $numspares-1) {
4558: $targettable .= '<tr>';
1.150 raeburn 4559: }
4560: }
4561: }
1.160.6.7 raeburn 4562: if ($targettable ne '') {
4563: my $rem = $numspares%($numinrow);
4564: my $colsleft = $numinrow - $rem;
4565: if ($colsleft > 1 ) {
4566: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4567: ' </td>';
4568: } elsif ($colsleft == 1) {
4569: $targettable .= '<td class="LC_left_item"> </td>';
4570: }
4571: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4572: '<table><tr>'.$targettable.'</tr></table><br />';
4573: }
1.160.6.76 raeburn 4574: $hostherechecked{$sparetype} = '';
4575: if (ref($currtargets{$lonhost}) eq 'HASH') {
4576: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4577: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4578: $hostherechecked{$sparetype} = ' checked="checked"';
4579: $hostherechecked{'no'} = '';
4580: }
4581: }
4582: }
4583: }
1.160.6.94 raeburn 4584: if ($currcookies{$lonhost}) {
4585: %balcookiechecked = (
4586: yes => ' checked="checked"',
4587: );
4588: }
1.160.6.76 raeburn 4589: $datatable .= &mt('Hosting on balancer itself').'<br />'.
4590: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
4591: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
4592: foreach my $sparetype (@sparestypes) {
4593: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
4594: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
4595: '</i></label><br />';
1.160.6.7 raeburn 4596: }
1.160.6.94 raeburn 4597: $datatable .= &mt('Use balancer cookie').'<br />'.
4598: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
4599: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
4600: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
4601: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
4602: '</div></td></tr>'.
1.160.6.7 raeburn 4603: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4604: $othertitle,$usertypes,$types,\%servers,
4605: \%currbalancer,$lonhost,
4606: $targets_div_style,$homedom_div_style,
4607: $css_class[$cssidx],$balnum,$islast);
4608: $$rowtotal += $rownum;
4609: $balnum ++;
4610: }
4611: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4612: return $datatable;
4613: }
4614:
4615: sub get_loadbalancers_config {
1.160.6.94 raeburn 4616: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 4617: return unless ((ref($servers) eq 'HASH') &&
4618: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 4619: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
4620: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 4621: if (keys(%{$existing}) > 0) {
4622: my $oldlonhost;
4623: foreach my $key (sort(keys(%{$existing}))) {
4624: if ($key eq 'lonhost') {
4625: $oldlonhost = $existing->{'lonhost'};
4626: $currbalancer->{$oldlonhost} = 1;
4627: } elsif ($key eq 'targets') {
4628: if ($oldlonhost) {
4629: $currtargets->{$oldlonhost} = $existing->{'targets'};
4630: }
4631: } elsif ($key eq 'rules') {
4632: if ($oldlonhost) {
4633: $currrules->{$oldlonhost} = $existing->{'rules'};
4634: }
4635: } elsif (ref($existing->{$key}) eq 'HASH') {
4636: $currbalancer->{$key} = 1;
4637: $currtargets->{$key} = $existing->{$key}{'targets'};
4638: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 4639: if ($existing->{$key}{'cookie'}) {
4640: $currcookies->{$key} = 1;
4641: }
1.150 raeburn 4642: }
4643: }
1.160.6.7 raeburn 4644: } else {
4645: my ($balancerref,$targetsref) =
4646: &Apache::lonnet::get_lonbalancer_config($servers);
4647: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4648: foreach my $server (sort(keys(%{$balancerref}))) {
4649: $currbalancer->{$server} = 1;
4650: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4651: }
4652: }
4653: }
1.160.6.7 raeburn 4654: return;
1.150 raeburn 4655: }
4656:
4657: sub loadbalancing_rules {
4658: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 4659: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4660: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4661: my $output;
1.160.6.7 raeburn 4662: my $num = 0;
4663: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4664: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4665: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4666: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 4667: $num ++;
1.150 raeburn 4668: my $current;
4669: if (ref($currrules) eq 'HASH') {
4670: $current = $currrules->{$type};
4671: }
1.160.6.55 raeburn 4672: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 4673: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4674: $current = '';
4675: }
4676: }
4677: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 4678: $servers,$currbalancer,$lonhost,$dom,
4679: $targets_div_style,$homedom_div_style,
4680: $css_class,$balnum,$num,$islast);
1.150 raeburn 4681: }
4682: }
4683: return $output;
4684: }
4685:
4686: sub loadbalancing_titles {
4687: my ($dom,$intdom,$usertypes,$types) = @_;
4688: my %othertypes = (
4689: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4690: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4691: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4692: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 4693: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4694: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4695: );
1.160.6.26 raeburn 4696: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 4697: my @available;
1.150 raeburn 4698: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 4699: @available = @{$types};
1.150 raeburn 4700: }
1.160.6.89 raeburn 4701: unless (grep(/^default$/,@available)) {
4702: push(@available,'default');
4703: }
4704: unshift(@alltypes,@available);
1.150 raeburn 4705: my %titles;
4706: foreach my $type (@alltypes) {
4707: if ($type =~ /^_LC_/) {
4708: $titles{$type} = $othertypes{$type};
4709: } elsif ($type eq 'default') {
4710: $titles{$type} = &mt('All users from [_1]',$dom);
4711: if (ref($types) eq 'ARRAY') {
4712: if (@{$types} > 0) {
4713: $titles{$type} = &mt('Other users from [_1]',$dom);
4714: }
4715: }
4716: } elsif (ref($usertypes) eq 'HASH') {
4717: $titles{$type} = $usertypes->{$type};
4718: }
4719: }
4720: return (\@alltypes,\%othertypes,\%titles);
4721: }
4722:
4723: sub loadbalance_rule_row {
1.160.6.7 raeburn 4724: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4725: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4726: my @rulenames;
1.150 raeburn 4727: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4728: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4729: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4730: } else {
1.160.6.26 raeburn 4731: @rulenames = ('default','homeserver');
4732: if ($type eq '_LC_external') {
4733: push(@rulenames,'externalbalancer');
4734: } else {
4735: push(@rulenames,'specific');
4736: }
4737: push(@rulenames,'none');
1.150 raeburn 4738: }
4739: my $style = $targets_div_style;
1.160.6.55 raeburn 4740: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4741: $style = $homedom_div_style;
4742: }
1.160.6.7 raeburn 4743: my $space;
4744: if ($islast && $num == 1) {
4745: $space = '<div display="inline-block"> </div>';
4746: }
4747: my $output =
4748: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4749: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4750: '<td valaign="top">'.$space.
4751: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4752: for (my $i=0; $i<@rulenames; $i++) {
4753: my $rule = $rulenames[$i];
4754: my ($checked,$extra);
4755: if ($rulenames[$i] eq 'default') {
4756: $rule = '';
4757: }
4758: if ($rulenames[$i] eq 'specific') {
4759: if (ref($servers) eq 'HASH') {
4760: my $default;
4761: if (($current ne '') && (exists($servers->{$current}))) {
4762: $checked = ' checked="checked"';
4763: }
4764: unless ($checked) {
4765: $default = ' selected="selected"';
4766: }
1.160.6.7 raeburn 4767: $extra =
4768: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4769: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4770: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4771: '<option value=""'.$default.'></option>'."\n";
4772: foreach my $server (sort(keys(%{$servers}))) {
4773: if (ref($currbalancer) eq 'HASH') {
4774: next if (exists($currbalancer->{$server}));
4775: }
1.150 raeburn 4776: my $selected;
1.160.6.7 raeburn 4777: if ($server eq $current) {
1.150 raeburn 4778: $selected = ' selected="selected"';
4779: }
1.160.6.7 raeburn 4780: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4781: }
4782: $extra .= '</select>';
4783: }
4784: } elsif ($rule eq $current) {
4785: $checked = ' checked="checked"';
4786: }
4787: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4788: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4789: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4790: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4791: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4792: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4793: $output .= $ruletitles{'particular'};
4794: } else {
4795: $output .= $ruletitles{$rulenames[$i]};
4796: }
4797: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4798: }
4799: $output .= '</div></td></tr>'."\n";
4800: return $output;
4801: }
4802:
4803: sub offloadtype_text {
4804: my %ruletitles = &Apache::lonlocal::texthash (
4805: 'default' => 'Offloads to default destinations',
4806: 'homeserver' => "Offloads to user's home server",
4807: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4808: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4809: 'none' => 'No offload',
1.160.6.26 raeburn 4810: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4811: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4812: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4813: );
4814: return %ruletitles;
4815: }
4816:
4817: sub sparestype_titles {
4818: my %typestitles = &Apache::lonlocal::texthash (
4819: 'primary' => 'primary',
4820: 'default' => 'default',
4821: );
4822: return %typestitles;
4823: }
4824:
1.28 raeburn 4825: sub contact_titles {
4826: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 4827: 'supportemail' => 'Support E-mail address',
4828: 'adminemail' => 'Default Server Admin E-mail address',
4829: 'errormail' => 'Error reports to be e-mailed to',
4830: 'packagesmail' => 'Package update alerts to be e-mailed to',
4831: 'helpdeskmail' => "Helpdesk requests for this domain's users",
4832: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
4833: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
4834: 'requestsmail' => 'E-mail from course requests requiring approval',
4835: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4836: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 4837: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.28 raeburn 4838: );
4839: my %short_titles = &Apache::lonlocal::texthash (
4840: adminemail => 'Admin E-mail address',
4841: supportemail => 'Support E-mail',
4842: );
4843: return (\%titles,\%short_titles);
4844: }
4845:
1.160.6.78 raeburn 4846: sub helpform_fields {
4847: my %titles = &Apache::lonlocal::texthash (
4848: 'username' => 'Name',
4849: 'user' => 'Username/domain',
4850: 'phone' => 'Phone',
4851: 'cc' => 'Cc e-mail',
4852: 'course' => 'Course Details',
4853: 'section' => 'Sections',
4854: 'screenshot' => 'File upload',
4855: );
4856: my @fields = ('username','phone','user','course','section','cc','screenshot');
4857: my %possoptions = (
4858: username => ['yes','no','req'],
4859: phone => ['yes','no','req'],
4860: user => ['yes','no'],
4861: cc => ['yes','no'],
4862: course => ['yes','no'],
4863: section => ['yes','no'],
4864: screenshot => ['yes','no'],
4865: );
4866: my %fieldoptions = &Apache::lonlocal::texthash (
4867: 'yes' => 'Optional',
4868: 'req' => 'Required',
4869: 'no' => "Not shown",
4870: );
4871: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
4872: }
4873:
1.72 raeburn 4874: sub tool_titles {
4875: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4876: aboutme => 'Personal web page',
1.86 raeburn 4877: blog => 'Blog',
1.160.6.4 raeburn 4878: webdav => 'WebDAV',
1.86 raeburn 4879: portfolio => 'Portfolio',
1.88 bisitz 4880: official => 'Official courses (with institutional codes)',
4881: unofficial => 'Unofficial courses',
1.98 raeburn 4882: community => 'Communities',
1.160.6.30 raeburn 4883: textbook => 'Textbook courses',
1.86 raeburn 4884: );
1.72 raeburn 4885: return %titles;
4886: }
4887:
1.101 raeburn 4888: sub courserequest_titles {
4889: my %titles = &Apache::lonlocal::texthash (
4890: official => 'Official',
4891: unofficial => 'Unofficial',
4892: community => 'Communities',
1.160.6.30 raeburn 4893: textbook => 'Textbook',
1.101 raeburn 4894: norequest => 'Not allowed',
1.104 raeburn 4895: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4896: validate => 'With validation',
4897: autolimit => 'Numerical limit',
1.103 raeburn 4898: unlimited => '(blank for unlimited)',
1.101 raeburn 4899: );
4900: return %titles;
4901: }
4902:
1.160.6.5 raeburn 4903: sub authorrequest_titles {
4904: my %titles = &Apache::lonlocal::texthash (
4905: norequest => 'Not allowed',
4906: approval => 'Approval by Dom. Coord.',
4907: automatic => 'Automatic approval',
4908: );
4909: return %titles;
4910: }
4911:
1.101 raeburn 4912: sub courserequest_conditions {
4913: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4914: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4915: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4916: );
4917: return %conditions;
4918: }
4919:
4920:
1.27 raeburn 4921: sub print_usercreation {
1.30 raeburn 4922: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4923: my $numinrow = 4;
1.28 raeburn 4924: my $datatable;
4925: if ($position eq 'top') {
1.30 raeburn 4926: $$rowtotal ++;
1.34 raeburn 4927: my $rowcount = 0;
1.32 raeburn 4928: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4929: if (ref($rules) eq 'HASH') {
4930: if (keys(%{$rules}) > 0) {
1.32 raeburn 4931: $datatable .= &user_formats_row('username',$settings,$rules,
4932: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4933: $$rowtotal ++;
1.32 raeburn 4934: $rowcount ++;
4935: }
4936: }
4937: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4938: if (ref($idrules) eq 'HASH') {
4939: if (keys(%{$idrules}) > 0) {
4940: $datatable .= &user_formats_row('id',$settings,$idrules,
4941: $idruleorder,$numinrow,$rowcount);
4942: $$rowtotal ++;
4943: $rowcount ++;
1.28 raeburn 4944: }
4945: }
1.39 raeburn 4946: if ($rowcount == 0) {
4947: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4948: $$rowtotal ++;
4949: $rowcount ++;
4950: }
1.34 raeburn 4951: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4952: my @creators = ('author','course','requestcrs');
1.37 raeburn 4953: my ($rules,$ruleorder) =
4954: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4955: my %lt = &usercreation_types();
4956: my %checked;
4957: if (ref($settings) eq 'HASH') {
4958: if (ref($settings->{'cancreate'}) eq 'HASH') {
4959: foreach my $item (@creators) {
4960: $checked{$item} = $settings->{'cancreate'}{$item};
4961: }
4962: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4963: foreach my $item (@creators) {
4964: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4965: $checked{$item} = 'none';
4966: }
4967: }
4968: }
4969: }
4970: my $rownum = 0;
4971: foreach my $item (@creators) {
4972: $rownum ++;
1.160.6.34 raeburn 4973: if ($checked{$item} eq '') {
4974: $checked{$item} = 'any';
1.34 raeburn 4975: }
4976: my $css_class;
4977: if ($rownum%2) {
4978: $css_class = '';
4979: } else {
4980: $css_class = ' class="LC_odd_row" ';
4981: }
4982: $datatable .= '<tr'.$css_class.'>'.
4983: '<td><span class="LC_nobreak">'.$lt{$item}.
4984: '</span></td><td align="right">';
1.160.6.34 raeburn 4985: my @options = ('any');
4986: if (ref($rules) eq 'HASH') {
4987: if (keys(%{$rules}) > 0) {
4988: push(@options,('official','unofficial'));
1.37 raeburn 4989: }
4990: }
1.160.6.34 raeburn 4991: push(@options,'none');
1.37 raeburn 4992: foreach my $option (@options) {
1.50 raeburn 4993: my $type = 'radio';
1.34 raeburn 4994: my $check = ' ';
1.160.6.34 raeburn 4995: if ($checked{$item} eq $option) {
4996: $check = ' checked="checked" ';
1.34 raeburn 4997: }
4998: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4999: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 5000: $item.'" value="'.$option.'"'.$check.'/> '.
5001: $lt{$option}.'</label> </span>';
5002: }
5003: $datatable .= '</td></tr>';
5004: }
1.28 raeburn 5005: } else {
5006: my @contexts = ('author','course','domain');
5007: my @authtypes = ('int','krb4','krb5','loc');
5008: my %checked;
5009: if (ref($settings) eq 'HASH') {
5010: if (ref($settings->{'authtypes'}) eq 'HASH') {
5011: foreach my $item (@contexts) {
5012: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
5013: foreach my $auth (@authtypes) {
5014: if ($settings->{'authtypes'}{$item}{$auth}) {
5015: $checked{$item}{$auth} = ' checked="checked" ';
5016: }
5017: }
5018: }
5019: }
1.27 raeburn 5020: }
1.35 raeburn 5021: } else {
5022: foreach my $item (@contexts) {
1.36 raeburn 5023: foreach my $auth (@authtypes) {
1.35 raeburn 5024: $checked{$item}{$auth} = ' checked="checked" ';
5025: }
5026: }
1.27 raeburn 5027: }
1.28 raeburn 5028: my %title = &context_names();
5029: my %authname = &authtype_names();
5030: my $rownum = 0;
5031: my $css_class;
5032: foreach my $item (@contexts) {
5033: if ($rownum%2) {
5034: $css_class = '';
5035: } else {
5036: $css_class = ' class="LC_odd_row" ';
5037: }
1.30 raeburn 5038: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5039: '<td>'.$title{$item}.
5040: '</td><td class="LC_left_item">'.
5041: '<span class="LC_nobreak">';
5042: foreach my $auth (@authtypes) {
5043: $datatable .= '<label>'.
5044: '<input type="checkbox" name="'.$item.'_auth" '.
5045: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5046: $authname{$auth}.'</label> ';
5047: }
5048: $datatable .= '</span></td></tr>';
5049: $rownum ++;
1.27 raeburn 5050: }
1.30 raeburn 5051: $$rowtotal += $rownum;
1.27 raeburn 5052: }
5053: return $datatable;
5054: }
5055:
1.160.6.34 raeburn 5056: sub print_selfcreation {
5057: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 5058: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
5059: $emaildomain,$datatable);
1.160.6.34 raeburn 5060: if (ref($settings) eq 'HASH') {
5061: if (ref($settings->{'cancreate'}) eq 'HASH') {
5062: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 5063: if (ref($createsettings) eq 'HASH') {
5064: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5065: @selfcreate = @{$createsettings->{'selfcreate'}};
5066: } elsif ($createsettings->{'selfcreate'} ne '') {
5067: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5068: @selfcreate = ('email','login','sso');
5069: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5070: @selfcreate = ($createsettings->{'selfcreate'});
5071: }
5072: }
5073: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5074: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5075: }
1.160.6.93 raeburn 5076: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
5077: $emailoptions = $createsettings->{'emailoptions'};
5078: }
5079: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
5080: $emailverified = $createsettings->{'emailverified'};
5081: }
5082: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
5083: $emaildomain = $createsettings->{'emaildomain'};
5084: }
1.160.6.34 raeburn 5085: }
5086: }
5087: }
5088: my %radiohash;
5089: my $numinrow = 4;
5090: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 5091: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 5092: if ($position eq 'top') {
5093: my %choices = &Apache::lonlocal::texthash (
5094: cancreate_login => 'Institutional Login',
5095: cancreate_sso => 'Institutional Single Sign On',
5096: );
5097: my @toggles = sort(keys(%choices));
5098: my %defaultchecked = (
5099: 'cancreate_login' => 'off',
5100: 'cancreate_sso' => 'off',
5101: );
1.160.6.35 raeburn 5102: my ($onclick,$itemcount);
1.160.6.34 raeburn 5103: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5104: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5105: $$rowtotal += $itemcount;
1.160.6.34 raeburn 5106:
5107: if (ref($usertypes) eq 'HASH') {
5108: if (keys(%{$usertypes}) > 0) {
5109: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5110: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 5111: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 5112: $$rowtotal ++;
5113: }
5114: }
1.160.6.44 raeburn 5115: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5116: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5117: $fieldtitles{'inststatus'} = &mt('Institutional status');
5118: my $rem;
5119: my $numperrow = 2;
5120: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5121: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5122: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5123: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 5124: '<table>'."\n";
1.160.6.44 raeburn 5125: for (my $i=0; $i<@fields; $i++) {
5126: $rem = $i%($numperrow);
5127: if ($rem == 0) {
5128: if ($i > 0) {
5129: $datatable .= '</tr>';
5130: }
5131: $datatable .= '<tr>';
5132: }
5133: my $currval;
1.160.6.51 raeburn 5134: if (ref($createsettings) eq 'HASH') {
5135: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5136: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5137: }
1.160.6.44 raeburn 5138: }
5139: $datatable .= '<td class="LC_left_item">'.
5140: '<span class="LC_nobreak">'.
5141: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5142: 'value="'.$currval.'" size="10" /> '.
5143: $fieldtitles{$fields[$i]}.'</span></td>';
5144: }
5145: my $colsleft = $numperrow - $rem;
5146: if ($colsleft > 1 ) {
5147: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5148: ' </td>';
5149: } elsif ($colsleft == 1) {
5150: $datatable .= '<td class="LC_left_item"> </td>';
5151: }
5152: $datatable .= '</tr></table></td></tr>';
5153: $$rowtotal ++;
1.160.6.34 raeburn 5154: } elsif ($position eq 'middle') {
5155: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 5156: my @posstypes;
1.160.6.34 raeburn 5157: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5158: @posstypes = @{$types};
5159: }
5160: unless (grep(/^default$/,@posstypes)) {
5161: push(@posstypes,'default');
5162: }
5163: my %usertypeshash;
5164: if (ref($usertypes) eq 'HASH') {
5165: %usertypeshash = %{$usertypes};
5166: }
5167: $usertypeshash{'default'} = $othertitle;
5168: foreach my $status (@posstypes) {
5169: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5170: $numinrow,$$rowtotal,\%usertypeshash);
5171: $$rowtotal ++;
1.160.6.34 raeburn 5172: }
5173: } else {
1.160.6.40 raeburn 5174: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 5175: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 5176: );
5177: my @toggles = sort(keys(%choices));
5178: my %defaultchecked = (
5179: 'cancreate_email' => 'off',
5180: );
1.160.6.93 raeburn 5181: my $customclass = 'LC_selfcreate_email';
5182: my $classprefix = 'LC_canmodify_emailusername_';
5183: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 5184: my $display = 'none';
1.160.6.93 raeburn 5185: my $rowstyle = 'display:none';
1.160.6.40 raeburn 5186: if (grep(/^\Qemail\E$/,@selfcreate)) {
5187: $display = 'block';
1.160.6.93 raeburn 5188: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 5189: }
1.160.6.93 raeburn 5190: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
5191: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5192: \%choices,$$rowtotal,$onclick);
5193: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
5194: $rowstyle);
5195: $$rowtotal ++;
5196: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
5197: $rowstyle);
5198: $$rowtotal ++;
5199: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 5200: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 5201: my ($emailrules,$emailruleorder) =
5202: &Apache::lonnet::inst_userrules($dom,'email');
5203: my $primary_id = &Apache::lonnet::domain($dom,'primary');
5204: my $intdom = &Apache::lonnet::internet_dom($primary_id);
5205: if (ref($types) eq 'ARRAY') {
5206: @posstypes = @{$types};
5207: }
5208: if (@posstypes) {
5209: unless (grep(/^default$/,@posstypes)) {
5210: push(@posstypes,'default');
1.160.6.89 raeburn 5211: }
5212: if (ref($usertypes) eq 'HASH') {
5213: %usertypeshash = %{$usertypes};
5214: }
1.160.6.93 raeburn 5215: my $currassign;
5216: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
5217: $currassign = {
5218: selfassign => $domdefaults{'inststatusguest'},
5219: };
5220: @ordered = @{$domdefaults{'inststatusguest'}};
5221: } else {
5222: $currassign = { selfassign => [] };
5223: }
5224: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
5225: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
5226: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
5227: $numinrow,$othertitle,'selfassign',
5228: $rowtotal,$onclicktypes,$customclass,
5229: $rowstyle);
5230: $$rowtotal ++;
1.160.6.89 raeburn 5231: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 5232: foreach my $status (@posstypes) {
5233: my $css_class;
5234: if ($$rowtotal%2) {
5235: $css_class = 'LC_odd_row ';
5236: }
5237: $css_class .= $customclass;
5238: my $rowid = $optionsprefix.$status;
5239: my $hidden = 1;
5240: my $currstyle = 'display:none';
5241: if (grep(/^\Q$status\E$/,@ordered)) {
5242: $currstyle = $rowstyle;
5243: $hidden = 0;
5244: }
5245: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5246: $emailrules,$emailruleorder,$settings,$status,$rowid,
5247: $usertypeshash{$status},$css_class,$currstyle,$intdom);
5248: unless ($hidden) {
5249: $$rowtotal ++;
5250: }
1.160.6.89 raeburn 5251: }
5252: } else {
1.160.6.93 raeburn 5253: my $css_class;
5254: if ($$rowtotal%2) {
5255: $css_class = 'LC_odd_row ';
5256: }
5257: $css_class .= $customclass;
1.160.6.89 raeburn 5258: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 5259: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5260: $emailrules,$emailruleorder,$settings,'default','',
5261: $othertitle,$css_class,$rowstyle,$intdom);
5262: $$rowtotal ++;
1.160.6.34 raeburn 5263: }
1.160.6.35 raeburn 5264: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5265: $numinrow = 1;
1.160.6.93 raeburn 5266: if (@posstypes) {
5267: foreach my $status (@posstypes) {
5268: my $rowid = $classprefix.$status;
5269: my $datarowstyle = 'display:none';
5270: if (grep(/^\Q$status\E$/,@ordered)) {
5271: $datarowstyle = $rowstyle;
5272: }
5273: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5274: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5275: $infotitles,$rowid,$customclass,$datarowstyle);
5276: unless ($datarowstyle eq 'display:none') {
5277: $$rowtotal ++;
5278: }
1.160.6.34 raeburn 5279: }
1.160.6.93 raeburn 5280: } else {
5281: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
5282: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5283: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 5284: }
5285: }
5286: return $datatable;
5287: }
5288:
1.160.6.93 raeburn 5289: sub selfcreate_javascript {
5290: return <<"ENDSCRIPT";
5291:
5292: <script type="text/javascript">
5293: // <![CDATA[
5294:
5295: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
5296: var x = document.getElementsByClassName(target);
5297: var insttypes = 0;
5298: var insttypeRegExp = new RegExp(prefix);
5299: if ((x.length != undefined) && (x.length > 0)) {
5300: if (form.elements[radio].length != undefined) {
5301: for (var i=0; i<form.elements[radio].length; i++) {
5302: if (form.elements[radio][i].checked) {
5303: if (form.elements[radio][i].value == 1) {
5304: for (var j=0; j<x.length; j++) {
5305: if (x[j].id == 'undefined') {
5306: x[j].style.display = 'table-row';
5307: } else if (insttypeRegExp.test(x[j].id)) {
5308: insttypes ++;
5309: } else {
5310: x[j].style.display = 'table-row';
5311: }
5312: }
5313: } else {
5314: for (var j=0; j<x.length; j++) {
5315: x[j].style.display = 'none';
5316: }
1.160.6.40 raeburn 5317: }
1.160.6.93 raeburn 5318: break;
5319: }
5320: }
5321: if (insttypes > 0) {
5322: toggleDataRow(form,checkbox,target,altprefix);
5323: toggleDataRow(form,checkbox,target,prefix,1);
5324: }
5325: }
5326: }
5327: return;
5328: }
5329:
5330: function toggleDataRow(form,checkbox,target,prefix,docount) {
5331: if (form.elements[checkbox].length != undefined) {
5332: var count = 0;
5333: if (docount) {
5334: for (var i=0; i<form.elements[checkbox].length; i++) {
5335: if (form.elements[checkbox][i].checked) {
5336: count ++;
5337: }
5338: }
5339: }
5340: for (var i=0; i<form.elements[checkbox].length; i++) {
5341: var type = form.elements[checkbox][i].value;
5342: if (document.getElementById(prefix+type)) {
5343: if (form.elements[checkbox][i].checked) {
5344: document.getElementById(prefix+type).style.display = 'table-row';
5345: if (count % 2 == 1) {
5346: document.getElementById(prefix+type).className = target+' LC_odd_row';
5347: } else {
5348: document.getElementById(prefix+type).className = target;
5349: }
5350: count ++;
1.160.6.40 raeburn 5351: } else {
1.160.6.93 raeburn 5352: document.getElementById(prefix+type).style.display = 'none';
5353: }
5354: }
5355: }
5356: }
5357: return;
5358: }
5359:
5360: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
5361: var caller = radio+'_'+status;
5362: if (form.elements[caller].length != undefined) {
5363: for (var i=0; i<form.elements[caller].length; i++) {
5364: if (form.elements[caller][i].checked) {
5365: if (document.getElementById(altprefix+'_inst_'+status)) {
5366: var curr = form.elements[caller][i].value;
5367: if (prefix) {
5368: document.getElementById(prefix+'_'+status).style.display = 'none';
5369: }
5370: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
5371: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
5372: if (curr == 'custom') {
5373: if (prefix) {
5374: document.getElementById(prefix+'_'+status).style.display = 'inline';
5375: }
5376: } else if (curr == 'inst') {
5377: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
5378: } else if (curr == 'noninst') {
5379: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 5380: }
1.160.6.93 raeburn 5381: break;
1.160.6.40 raeburn 5382: }
1.160.6.93 raeburn 5383: }
5384: }
5385: }
5386: }
5387:
5388: // ]]>
5389: </script>
5390:
5391: ENDSCRIPT
5392: }
5393:
5394: sub noninst_users {
5395: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
5396: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
5397: my $class = 'LC_left_item';
5398: if ($css_class) {
5399: $css_class = ' class="'.$css_class.'"';
5400: }
5401: if ($rowid) {
5402: $rowid = ' id="'.$rowid.'"';
5403: }
5404: if ($rowstyle) {
5405: $rowstyle = ' style="'.$rowstyle.'"';
5406: }
5407: my ($output,$description);
5408: if ($type eq 'default') {
5409: $description = &mt('Requests for: [_1]',$typetitle);
5410: } else {
5411: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
5412: }
5413: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
5414: "<td>$description</td>\n".
5415: '<td class="'.$class.'" colspan="2">'.
5416: '<table><tr>';
5417: my %headers = &Apache::lonlocal::texthash(
5418: approve => 'Processing',
5419: email => 'E-mail',
5420: username => 'Username',
5421: );
5422: foreach my $item ('approve','email','username') {
5423: $output .= '<th>'.$headers{$item}.'</th>';
5424: }
5425: $output .= '</tr><tr>';
5426: foreach my $item ('approve','email','username') {
5427: $output .= '<td valign="top">';
5428: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
5429: if ($item eq 'approve') {
5430: %choices = &Apache::lonlocal::texthash (
5431: automatic => 'Automatically approved',
5432: approval => 'Queued for approval',
5433: );
5434: @options = ('automatic','approval');
5435: $hashref = $processing;
5436: $defoption = 'automatic';
5437: $name = 'cancreate_emailprocess_'.$type;
5438: } elsif ($item eq 'email') {
5439: %choices = &Apache::lonlocal::texthash (
5440: any => 'Any e-mail',
5441: inst => 'Institutional only',
5442: noninst => 'Non-institutional only',
5443: custom => 'Custom restrictions',
5444: );
5445: @options = ('any','inst','noninst');
5446: my $showcustom;
5447: if (ref($emailrules) eq 'HASH') {
5448: if (keys(%{$emailrules}) > 0) {
5449: push(@options,'custom');
5450: $showcustom = 'cancreate_emailrule';
5451: if (ref($settings) eq 'HASH') {
5452: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
5453: foreach my $rule (@{$settings->{'email_rule'}}) {
5454: if (exists($emailrules->{$rule})) {
5455: $hascustom ++;
5456: }
5457: }
5458: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
5459: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
5460: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
5461: if (exists($emailrules->{$rule})) {
5462: $hascustom ++;
5463: }
5464: }
5465: }
5466: }
5467: }
5468: }
5469: }
5470: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
5471: "'cancreate_emaildomain','$type'".');"';
5472: $hashref = $emailoptions;
5473: $defoption = 'any';
5474: $name = 'cancreate_emailoptions_'.$type;
5475: } elsif ($item eq 'username') {
5476: %choices = &Apache::lonlocal::texthash (
5477: all => 'Same as e-mail',
5478: first => 'Omit @domain',
5479: free => 'Free to choose',
5480: );
5481: @options = ('all','first','free');
5482: $hashref = $emailverified;
5483: $defoption = 'all';
5484: $name = 'cancreate_usernameoptions_'.$type;
5485: }
5486: foreach my $option (@options) {
5487: my $checked;
5488: if (ref($hashref) eq 'HASH') {
5489: if ($type eq '') {
5490: if (!exists($hashref->{'default'})) {
5491: if ($option eq $defoption) {
5492: $checked = ' checked="checked"';
5493: }
5494: } else {
5495: if ($hashref->{'default'} eq $option) {
5496: $checked = ' checked="checked"';
5497: }
1.160.6.40 raeburn 5498: }
5499: } else {
1.160.6.93 raeburn 5500: if (!exists($hashref->{$type})) {
5501: if ($option eq $defoption) {
5502: $checked = ' checked="checked"';
5503: }
5504: } else {
5505: if ($hashref->{$type} eq $option) {
5506: $checked = ' checked="checked"';
5507: }
1.160.6.40 raeburn 5508: }
5509: }
1.160.6.93 raeburn 5510: } elsif (($item eq 'email') && ($hascustom)) {
5511: if ($option eq 'custom') {
5512: $checked = ' checked="checked"';
5513: }
5514: } elsif ($option eq $defoption) {
5515: $checked = ' checked="checked"';
5516: }
5517: $output .= '<span class="LC_nobreak"><label>'.
5518: '<input type="radio" name="'.$name.'"'.
5519: $checked.' value="'.$option.'"'.$onclick.' />'.
5520: $choices{$option}.'</label></span><br />';
5521: if ($item eq 'email') {
5522: if ($option eq 'custom') {
5523: my $id = 'cancreate_emailrule_'.$type;
5524: my $display = 'none';
5525: if ($checked) {
5526: $display = 'inline';
5527: }
5528: my $numinrow = 2;
5529: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
5530: '<legend>'.&mt('Disallow').'</legend><table>'.
5531: &user_formats_row('email',$settings,$emailrules,
5532: $emailruleorder,$numinrow,'',$type);
5533: '</table></fieldset>';
5534: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
5535: my %text = &Apache::lonlocal::texthash (
5536: inst => 'must end:',
5537: noninst => 'cannot end:',
5538: );
5539: my $value;
5540: if (ref($emaildomain) eq 'HASH') {
5541: if (ref($emaildomain->{$type}) eq 'HASH') {
5542: $value = $emaildomain->{$type}->{$option};
5543: }
5544: }
5545: if ($value eq '') {
5546: $value = '@'.$intdom;
5547: }
5548: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
5549: my $display = 'none';
5550: if ($checked) {
5551: $display = 'inline';
5552: }
5553: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
5554: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
5555: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
5556: '</div>';
5557: }
1.160.6.40 raeburn 5558: }
5559: }
1.160.6.93 raeburn 5560: $output .= '</td>'."\n";
1.160.6.40 raeburn 5561: }
1.160.6.93 raeburn 5562: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 5563: return $output;
5564: }
5565:
1.160.6.5 raeburn 5566: sub captcha_choice {
1.160.6.93 raeburn 5567: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 5568: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5569: $vertext,$currver);
1.160.6.5 raeburn 5570: my %lt = &captcha_phrases();
5571: $keyentry = 'hidden';
5572: if ($context eq 'cancreate') {
1.160.6.34 raeburn 5573: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 5574: } elsif ($context eq 'login') {
5575: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5576: }
5577: if (ref($settings) eq 'HASH') {
5578: if ($settings->{'captcha'}) {
5579: $checked{$settings->{'captcha'}} = ' checked="checked"';
5580: } else {
5581: $checked{'original'} = ' checked="checked"';
5582: }
5583: if ($settings->{'captcha'} eq 'recaptcha') {
5584: $pubtext = $lt{'pub'};
5585: $privtext = $lt{'priv'};
5586: $keyentry = 'text';
1.160.6.69 raeburn 5587: $vertext = $lt{'ver'};
5588: $currver = $settings->{'recaptchaversion'};
5589: if ($currver ne '2') {
5590: $currver = 1;
5591: }
1.160.6.5 raeburn 5592: }
5593: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5594: $currpub = $settings->{'recaptchakeys'}{'public'};
5595: $currpriv = $settings->{'recaptchakeys'}{'private'};
5596: }
5597: } else {
5598: $checked{'original'} = ' checked="checked"';
5599: }
1.160.6.93 raeburn 5600: my $css_class;
5601: if ($itemcount%2) {
5602: $css_class = 'LC_odd_row';
5603: }
5604: if ($customcss) {
5605: $css_class .= " $customcss";
5606: }
5607: $css_class =~ s/^\s+//;
5608: if ($css_class) {
5609: $css_class = ' class="'.$css_class.'"';
5610: }
5611: if ($rowstyle) {
5612: $css_class .= ' style="'.$rowstyle.'"';
5613: }
1.160.6.5 raeburn 5614: my $output = '<tr'.$css_class.'>'.
5615: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5616: '<table><tr><td>'."\n";
5617: foreach my $option ('original','recaptcha','notused') {
5618: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5619: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5620: $lt{$option}.'</label></span>';
5621: unless ($option eq 'notused') {
5622: $output .= (' 'x2)."\n";
5623: }
5624: }
5625: #
5626: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5627: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5628: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5629: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5630: #
5631: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 5632: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 5633: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5634: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5635: $currpub.'" size="40" /></span><br />'."\n".
5636: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5637: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 5638: $currpriv.'" size="40" /></span><br />'.
5639: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5640: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5641: $currver.'" size="3" /></span><br />'.
5642: '</td></tr></table>'."\n".
1.160.6.5 raeburn 5643: '</td></tr>';
5644: return $output;
5645: }
5646:
1.32 raeburn 5647: sub user_formats_row {
1.160.6.93 raeburn 5648: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 5649: my $output;
5650: my %text = (
5651: 'username' => 'new usernames',
5652: 'id' => 'IDs',
5653: );
1.160.6.93 raeburn 5654: unless ($type eq 'email') {
5655: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5656: $output = '<tr '.$css_class.'>'.
5657: '<td><span class="LC_nobreak">'.
5658: &mt("Format rules to check for $text{$type}: ").
5659: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 5660: }
1.27 raeburn 5661: my $rem;
5662: if (ref($ruleorder) eq 'ARRAY') {
5663: for (my $i=0; $i<@{$ruleorder}; $i++) {
5664: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5665: my $rem = $i%($numinrow);
5666: if ($rem == 0) {
5667: if ($i > 0) {
5668: $output .= '</tr>';
5669: }
5670: $output .= '<tr>';
5671: }
5672: my $check = ' ';
1.39 raeburn 5673: if (ref($settings) eq 'HASH') {
5674: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5675: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5676: $check = ' checked="checked" ';
5677: }
1.160.6.93 raeburn 5678: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
5679: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
5680: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
5681: $check = ' checked="checked" ';
5682: }
5683: }
1.27 raeburn 5684: }
5685: }
1.160.6.93 raeburn 5686: my $name = $type.'_rule';
5687: if ($type eq 'email') {
5688: $name .= '_'.$status;
5689: }
1.27 raeburn 5690: $output .= '<td class="LC_left_item">'.
5691: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 5692: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 5693: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5694: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5695: }
5696: }
5697: $rem = @{$ruleorder}%($numinrow);
5698: }
1.160.6.93 raeburn 5699: my $colsleft;
5700: if ($rem) {
5701: $colsleft = $numinrow - $rem;
5702: }
1.27 raeburn 5703: if ($colsleft > 1 ) {
5704: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5705: ' </td>';
5706: } elsif ($colsleft == 1) {
5707: $output .= '<td class="LC_left_item"> </td>';
5708: }
1.160.6.93 raeburn 5709: $output .= '</tr></table>';
5710: unless ($type eq 'email') {
5711: $output .= '</td></tr>';
5712: }
1.27 raeburn 5713: return $output;
5714: }
5715:
1.34 raeburn 5716: sub usercreation_types {
5717: my %lt = &Apache::lonlocal::texthash (
5718: author => 'When adding a co-author',
5719: course => 'When adding a user to a course',
1.100 raeburn 5720: requestcrs => 'When requesting a course',
1.34 raeburn 5721: any => 'Any',
5722: official => 'Institutional only ',
5723: unofficial => 'Non-institutional only',
5724: none => 'None',
5725: );
5726: return %lt;
1.48 raeburn 5727: }
1.34 raeburn 5728:
1.160.6.34 raeburn 5729: sub selfcreation_types {
5730: my %lt = &Apache::lonlocal::texthash (
5731: selfcreate => 'User creates own account',
5732: any => 'Any',
5733: official => 'Institutional only ',
5734: unofficial => 'Non-institutional only',
5735: email => 'E-mail address',
5736: login => 'Institutional Login',
5737: sso => 'SSO',
5738: );
5739: }
5740:
1.28 raeburn 5741: sub authtype_names {
5742: my %lt = &Apache::lonlocal::texthash(
5743: int => 'Internal',
5744: krb4 => 'Kerberos 4',
5745: krb5 => 'Kerberos 5',
5746: loc => 'Local',
5747: );
5748: return %lt;
5749: }
5750:
5751: sub context_names {
5752: my %context_title = &Apache::lonlocal::texthash(
5753: author => 'Creating users when an Author',
5754: course => 'Creating users when in a course',
5755: domain => 'Creating users when a Domain Coordinator',
5756: );
5757: return %context_title;
5758: }
5759:
1.33 raeburn 5760: sub print_usermodification {
5761: my ($position,$dom,$settings,$rowtotal) = @_;
5762: my $numinrow = 4;
5763: my ($context,$datatable,$rowcount);
5764: if ($position eq 'top') {
5765: $rowcount = 0;
5766: $context = 'author';
5767: foreach my $role ('ca','aa') {
5768: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5769: $numinrow,$rowcount);
5770: $$rowtotal ++;
5771: $rowcount ++;
5772: }
1.160.6.37 raeburn 5773: } elsif ($position eq 'bottom') {
1.33 raeburn 5774: $context = 'course';
5775: $rowcount = 0;
5776: foreach my $role ('st','ep','ta','in','cr') {
5777: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5778: $numinrow,$rowcount);
5779: $$rowtotal ++;
5780: $rowcount ++;
5781: }
5782: }
5783: return $datatable;
5784: }
5785:
1.43 raeburn 5786: sub print_defaults {
1.160.6.40 raeburn 5787: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5788: my $rownum = 0;
1.160.6.80 raeburn 5789: my ($datatable,$css_class,$titles);
5790: unless ($position eq 'bottom') {
5791: $titles = &defaults_titles($dom);
5792: }
1.160.6.40 raeburn 5793: if ($position eq 'top') {
5794: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5795: 'datelocale_def','portal_def');
5796: my %defaults;
5797: if (ref($settings) eq 'HASH') {
5798: %defaults = %{$settings};
1.43 raeburn 5799: } else {
1.160.6.40 raeburn 5800: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5801: foreach my $item (@items) {
5802: $defaults{$item} = $domdefaults{$item};
5803: }
1.43 raeburn 5804: }
1.160.6.40 raeburn 5805: foreach my $item (@items) {
5806: if ($rownum%2) {
5807: $css_class = '';
5808: } else {
5809: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 5810: }
1.160.6.40 raeburn 5811: $datatable .= '<tr'.$css_class.'>'.
5812: '<td><span class="LC_nobreak">'.$titles->{$item}.
5813: '</span></td><td class="LC_right_item" colspan="3">';
5814: if ($item eq 'auth_def') {
5815: my @authtypes = ('internal','krb4','krb5','localauth');
5816: my %shortauth = (
5817: internal => 'int',
5818: krb4 => 'krb4',
5819: krb5 => 'krb5',
5820: localauth => 'loc'
5821: );
5822: my %authnames = &authtype_names();
5823: foreach my $auth (@authtypes) {
5824: my $checked = ' ';
5825: if ($defaults{$item} eq $auth) {
5826: $checked = ' checked="checked" ';
5827: }
5828: $datatable .= '<label><input type="radio" name="'.$item.
5829: '" value="'.$auth.'"'.$checked.'/>'.
5830: $authnames{$shortauth{$auth}}.'</label> ';
5831: }
5832: } elsif ($item eq 'timezone_def') {
5833: my $includeempty = 1;
5834: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5835: } elsif ($item eq 'datelocale_def') {
5836: my $includeempty = 1;
5837: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5838: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 5839: my $includeempty = 1;
5840: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 5841: } else {
5842: my $size;
5843: if ($item eq 'portal_def') {
5844: $size = ' size="25"';
5845: }
5846: $datatable .= '<input type="text" name="'.$item.'" value="'.
5847: $defaults{$item}.'"'.$size.' />';
5848: }
5849: $datatable .= '</td></tr>';
5850: $rownum ++;
5851: }
1.160.6.80 raeburn 5852: } elsif ($position eq 'middle') {
5853: my @items = ('intauth_cost','intauth_check','intauth_switch');
5854: my %defaults;
5855: if (ref($settings) eq 'HASH') {
5856: %defaults = %{$settings};
5857: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5858: $defaults{'intauth_cost'} = 10;
5859: }
5860: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5861: $defaults{'intauth_check'} = 0;
5862: }
5863: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5864: $defaults{'intauth_switch'} = 0;
5865: }
5866: } else {
5867: %defaults = (
5868: 'intauth_cost' => 10,
5869: 'intauth_check' => 0,
5870: 'intauth_switch' => 0,
5871: );
5872: }
5873: foreach my $item (@items) {
5874: if ($rownum%2) {
5875: $css_class = '';
5876: } else {
5877: $css_class = ' class="LC_odd_row" ';
5878: }
5879: $datatable .= '<tr'.$css_class.'>'.
5880: '<td><span class="LC_nobreak">'.$titles->{$item}.
5881: '</span></td><td class="LC_left_item" colspan="3">';
5882: if ($item eq 'intauth_switch') {
5883: my @options = (0,1,2);
5884: my %optiondesc = &Apache::lonlocal::texthash (
5885: 0 => 'No',
5886: 1 => 'Yes',
5887: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5888: );
5889: $datatable .= '<table width="100%">';
5890: foreach my $option (@options) {
5891: my $checked = ' ';
5892: if ($defaults{$item} eq $option) {
5893: $checked = ' checked="checked"';
5894: }
5895: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5896: '<label><input type="radio" name="'.$item.
5897: '" value="'.$option.'"'.$checked.' />'.
5898: $optiondesc{$option}.'</label></span></td></tr>';
5899: }
5900: $datatable .= '</table>';
5901: } elsif ($item eq 'intauth_check') {
5902: my @options = (0,1,2);
5903: my %optiondesc = &Apache::lonlocal::texthash (
5904: 0 => 'No',
5905: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5906: 2 => 'Yes, disallow login if stored cost is less than domain default',
5907: );
1.160.6.87 raeburn 5908: $datatable .= '<table width="100%">';
1.160.6.80 raeburn 5909: foreach my $option (@options) {
5910: my $checked = ' ';
5911: my $onclick;
5912: if ($defaults{$item} eq $option) {
5913: $checked = ' checked="checked"';
5914: }
5915: if ($option == 2) {
5916: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5917: }
5918: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5919: '<label><input type="radio" name="'.$item.
5920: '" value="'.$option.'"'.$checked.$onclick.' />'.
5921: $optiondesc{$option}.'</label></span></td></tr>';
5922: }
5923: $datatable .= '</table>';
5924: } else {
5925: $datatable .= '<input type="text" name="'.$item.'" value="'.
5926: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5927: }
5928: $datatable .= '</td></tr>';
5929: $rownum ++;
5930: }
1.160.6.40 raeburn 5931: } else {
1.160.6.80 raeburn 5932: my %defaults;
1.160.6.40 raeburn 5933: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 5934: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 5935: my $maxnum = @{$settings->{'inststatusorder'}};
5936: for (my $i=0; $i<$maxnum; $i++) {
5937: $css_class = $rownum%2?' class="LC_odd_row"':'';
5938: my $item = $settings->{'inststatusorder'}->[$i];
5939: my $title = $settings->{'inststatustypes'}->{$item};
5940: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5941: $datatable .= '<tr'.$css_class.'>'.
5942: '<td><span class="LC_nobreak">'.
5943: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5944: for (my $k=0; $k<=$maxnum; $k++) {
5945: my $vpos = $k+1;
5946: my $selstr;
5947: if ($k == $i) {
5948: $selstr = ' selected="selected" ';
5949: }
5950: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5951: }
5952: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5953: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5954: &mt('delete').'</span></td>'.
5955: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5956: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 5957: '</span></td></tr>';
1.160.6.40 raeburn 5958: }
5959: $css_class = $rownum%2?' class="LC_odd_row"':'';
5960: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5961: $datatable .= '<tr '.$css_class.'>'.
5962: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5963: for (my $k=0; $k<=$maxnum; $k++) {
5964: my $vpos = $k+1;
5965: my $selstr;
5966: if ($k == $maxnum) {
5967: $selstr = ' selected="selected" ';
5968: }
5969: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5970: }
5971: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 5972: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 5973: ' '.&mt('(new)').
5974: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5975: &mt('Name displayed:').
5976: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5977: '</tr>'."\n";
5978: $rownum ++;
1.141 raeburn 5979: }
1.43 raeburn 5980: }
5981: }
5982: $$rowtotal += $rownum;
5983: return $datatable;
5984: }
5985:
1.160.6.5 raeburn 5986: sub get_languages_hash {
5987: my %langchoices;
5988: foreach my $id (&Apache::loncommon::languageids()) {
5989: my $code = &Apache::loncommon::supportedlanguagecode($id);
5990: if ($code ne '') {
5991: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5992: }
5993: }
5994: return %langchoices;
5995: }
5996:
1.43 raeburn 5997: sub defaults_titles {
1.141 raeburn 5998: my ($dom) = @_;
1.43 raeburn 5999: my %titles = &Apache::lonlocal::texthash (
6000: 'auth_def' => 'Default authentication type',
6001: 'auth_arg_def' => 'Default authentication argument',
6002: 'lang_def' => 'Default language',
1.54 raeburn 6003: 'timezone_def' => 'Default timezone',
1.68 raeburn 6004: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 6005: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 6006: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
6007: 'intauth_check' => 'Check bcrypt cost if authenticated',
6008: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 6009: );
1.141 raeburn 6010: if ($dom) {
6011: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
6012: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
6013: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
6014: $protocol = 'http' if ($protocol ne 'https');
6015: if ($uint_dom) {
6016: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
6017: $uint_dom);
6018: }
6019: }
1.43 raeburn 6020: return (\%titles);
6021: }
6022:
1.46 raeburn 6023: sub print_scantronformat {
6024: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
6025: my $itemcount = 1;
1.60 raeburn 6026: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
6027: %confhash);
1.46 raeburn 6028: my $switchserver = &check_switchserver($dom,$confname);
6029: my %lt = &Apache::lonlocal::texthash (
1.95 www 6030: default => 'Default bubblesheet format file error',
6031: custom => 'Custom bubblesheet format file error',
1.46 raeburn 6032: );
6033: my %scantronfiles = (
6034: default => 'default.tab',
6035: custom => 'custom.tab',
6036: );
6037: foreach my $key (keys(%scantronfiles)) {
6038: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
6039: .$scantronfiles{$key};
6040: }
6041: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
6042: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
6043: if (!$switchserver) {
6044: my $servadm = $r->dir_config('lonAdmEMail');
6045: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
6046: if ($configuserok eq 'ok') {
6047: if ($author_ok eq 'ok') {
6048: my %legacyfile = (
6049: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6050: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6051: );
6052: my %md5chk;
6053: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6054: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6055: chomp($md5chk{$type});
1.46 raeburn 6056: }
6057: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6058: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6059: ($scantronurls{$type},my $error) =
1.46 raeburn 6060: &legacy_scantronformat($r,$dom,$confname,
6061: $type,$legacyfile{$type},
6062: $scantronurls{$type},
6063: $scantronfiles{$type});
1.60 raeburn 6064: if ($error ne '') {
6065: $error{$type} = $error;
6066: }
6067: }
6068: if (keys(%error) == 0) {
6069: $is_custom = 1;
6070: $confhash{'scantron'}{'scantronformat'} =
6071: $scantronurls{'custom'};
6072: my $putresult =
6073: &Apache::lonnet::put_dom('configuration',
6074: \%confhash,$dom);
6075: if ($putresult ne 'ok') {
6076: $error{'custom'} =
6077: '<span class="LC_error">'.
6078: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6079: }
1.46 raeburn 6080: }
6081: } else {
1.60 raeburn 6082: ($scantronurls{'default'},my $error) =
1.46 raeburn 6083: &legacy_scantronformat($r,$dom,$confname,
6084: 'default',$legacyfile{'default'},
6085: $scantronurls{'default'},
6086: $scantronfiles{'default'});
1.60 raeburn 6087: if ($error eq '') {
6088: $confhash{'scantron'}{'scantronformat'} = '';
6089: my $putresult =
6090: &Apache::lonnet::put_dom('configuration',
6091: \%confhash,$dom);
6092: if ($putresult ne 'ok') {
6093: $error{'default'} =
6094: '<span class="LC_error">'.
6095: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6096: }
6097: } else {
6098: $error{'default'} = $error;
6099: }
1.46 raeburn 6100: }
6101: }
6102: }
6103: } else {
1.95 www 6104: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6105: }
6106: }
6107: if (ref($settings) eq 'HASH') {
6108: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6109: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6110: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6111: $scantronurl = '';
6112: } else {
6113: $scantronurl = $settings->{'scantronformat'};
6114: }
6115: $is_custom = 1;
6116: } else {
6117: $scantronurl = $scantronurls{'default'};
6118: }
6119: } else {
1.60 raeburn 6120: if ($is_custom) {
6121: $scantronurl = $scantronurls{'custom'};
6122: } else {
6123: $scantronurl = $scantronurls{'default'};
6124: }
1.46 raeburn 6125: }
6126: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6127: $datatable .= '<tr'.$css_class.'>';
6128: if (!$is_custom) {
1.65 raeburn 6129: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6130: '<span class="LC_nobreak">';
1.46 raeburn 6131: if ($scantronurl) {
1.160.6.21 raeburn 6132: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6133: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6134: } else {
6135: $datatable = &mt('File unavailable for display');
6136: }
1.65 raeburn 6137: $datatable .= '</span></td>';
1.60 raeburn 6138: if (keys(%error) == 0) {
6139: $datatable .= '<td valign="bottom">';
6140: if (!$switchserver) {
6141: $datatable .= &mt('Upload:').'<br />';
6142: }
6143: } else {
6144: my $errorstr;
6145: foreach my $key (sort(keys(%error))) {
6146: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6147: }
6148: $datatable .= '<td>'.$errorstr;
6149: }
1.46 raeburn 6150: } else {
6151: if (keys(%error) > 0) {
6152: my $errorstr;
6153: foreach my $key (sort(keys(%error))) {
6154: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6155: }
1.60 raeburn 6156: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6157: } elsif ($scantronurl) {
1.160.6.26 raeburn 6158: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 6159: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6160: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 6161: $link.
6162: '<label><input type="checkbox" name="scantronformat_del"'.
6163: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6164: '<td><span class="LC_nobreak"> '.
6165: &mt('Replace:').'</span><br />';
1.46 raeburn 6166: }
6167: }
6168: if (keys(%error) == 0) {
6169: if ($switchserver) {
6170: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6171: } else {
1.65 raeburn 6172: $datatable .='<span class="LC_nobreak"> '.
6173: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6174: }
6175: }
6176: $datatable .= '</td></tr>';
6177: $$rowtotal ++;
6178: return $datatable;
6179: }
6180:
6181: sub legacy_scantronformat {
6182: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6183: my ($url,$error);
6184: my @statinfo = &Apache::lonnet::stat_file($newurl);
6185: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6186: (my $result,$url) =
6187: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6188: '','',$newfile);
6189: if ($result ne 'ok') {
1.130 raeburn 6190: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6191: }
6192: }
6193: return ($url,$error);
6194: }
1.43 raeburn 6195:
1.49 raeburn 6196: sub print_coursecategories {
1.57 raeburn 6197: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6198: my $datatable;
6199: if ($position eq 'top') {
1.160.6.42 raeburn 6200: my (%checked);
6201: my @catitems = ('unauth','auth');
6202: my @cattypes = ('std','domonly','codesrch','none');
6203: $checked{'unauth'} = 'std';
6204: $checked{'auth'} = 'std';
6205: if (ref($settings) eq 'HASH') {
6206: foreach my $type (@cattypes) {
6207: if ($type eq $settings->{'unauth'}) {
6208: $checked{'unauth'} = $type;
6209: }
6210: if ($type eq $settings->{'auth'}) {
6211: $checked{'auth'} = $type;
6212: }
6213: }
6214: }
6215: my %lt = &Apache::lonlocal::texthash (
6216: unauth => 'Catalog type for unauthenticated users',
6217: auth => 'Catalog type for authenticated users',
6218: none => 'No catalog',
6219: std => 'Standard catalog',
6220: domonly => 'Domain-only catalog',
6221: codesrch => "Code search form",
6222: );
6223: my $itemcount = 0;
6224: foreach my $item (@catitems) {
6225: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6226: $datatable .= '<tr '.$css_class.'>'.
6227: '<td>'.$lt{$item}.'</td>'.
6228: '<td class="LC_right_item"><span class="LC_nobreak">';
6229: foreach my $type (@cattypes) {
6230: my $ischecked;
6231: if ($checked{$item} eq $type) {
6232: $ischecked=' checked="checked"';
6233: }
6234: $datatable .= '<label>'.
6235: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6236: ' />'.$lt{$type}.'</label> ';
6237: }
1.160.6.87 raeburn 6238: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 6239: $itemcount ++;
6240: }
6241: $$rowtotal += $itemcount;
6242: } elsif ($position eq 'middle') {
1.57 raeburn 6243: my $toggle_cats_crs = ' ';
6244: my $toggle_cats_dom = ' checked="checked" ';
6245: my $can_cat_crs = ' ';
6246: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6247: my $toggle_catscomm_comm = ' ';
6248: my $toggle_catscomm_dom = ' checked="checked" ';
6249: my $can_catcomm_comm = ' ';
6250: my $can_catcomm_dom = ' checked="checked" ';
6251:
1.57 raeburn 6252: if (ref($settings) eq 'HASH') {
6253: if ($settings->{'togglecats'} eq 'crs') {
6254: $toggle_cats_crs = $toggle_cats_dom;
6255: $toggle_cats_dom = ' ';
6256: }
6257: if ($settings->{'categorize'} eq 'crs') {
6258: $can_cat_crs = $can_cat_dom;
6259: $can_cat_dom = ' ';
6260: }
1.120 raeburn 6261: if ($settings->{'togglecatscomm'} eq 'comm') {
6262: $toggle_catscomm_comm = $toggle_catscomm_dom;
6263: $toggle_catscomm_dom = ' ';
6264: }
6265: if ($settings->{'categorizecomm'} eq 'comm') {
6266: $can_catcomm_comm = $can_catcomm_dom;
6267: $can_catcomm_dom = ' ';
6268: }
1.57 raeburn 6269: }
6270: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 6271: togglecats => 'Show/Hide a course in catalog',
6272: togglecatscomm => 'Show/Hide a community in catalog',
6273: categorize => 'Assign a category to a course',
6274: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6275: );
6276: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 6277: dom => 'Set in Domain',
6278: crs => 'Set in Course',
6279: comm => 'Set in Community',
1.57 raeburn 6280: );
6281: $datatable = '<tr class="LC_odd_row">'.
6282: '<td>'.$title{'togglecats'}.'</td>'.
6283: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6284: '<input type="radio" name="togglecats"'.
6285: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6286: '<label><input type="radio" name="togglecats"'.
6287: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6288: '</tr><tr>'.
6289: '<td>'.$title{'categorize'}.'</td>'.
6290: '<td class="LC_right_item"><span class="LC_nobreak">'.
6291: '<label><input type="radio" name="categorize"'.
6292: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6293: '<label><input type="radio" name="categorize"'.
6294: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6295: '</tr><tr class="LC_odd_row">'.
6296: '<td>'.$title{'togglecatscomm'}.'</td>'.
6297: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6298: '<input type="radio" name="togglecatscomm"'.
6299: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6300: '<label><input type="radio" name="togglecatscomm"'.
6301: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6302: '</tr><tr>'.
6303: '<td>'.$title{'categorizecomm'}.'</td>'.
6304: '<td class="LC_right_item"><span class="LC_nobreak">'.
6305: '<label><input type="radio" name="categorizecomm"'.
6306: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6307: '<label><input type="radio" name="categorizecomm"'.
6308: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 6309: '</tr>';
1.120 raeburn 6310: $$rowtotal += 4;
1.57 raeburn 6311: } else {
6312: my $css_class;
6313: my $itemcount = 1;
6314: my $cathash;
6315: if (ref($settings) eq 'HASH') {
6316: $cathash = $settings->{'cats'};
6317: }
6318: if (ref($cathash) eq 'HASH') {
6319: my (@cats,@trails,%allitems,%idx,@jsarray);
6320: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6321: \%allitems,\%idx,\@jsarray);
6322: my $maxdepth = scalar(@cats);
6323: my $colattrib = '';
6324: if ($maxdepth > 2) {
6325: $colattrib = ' colspan="2" ';
6326: }
6327: my @path;
6328: if (@cats > 0) {
6329: if (ref($cats[0]) eq 'ARRAY') {
6330: my $numtop = @{$cats[0]};
6331: my $maxnum = $numtop;
1.120 raeburn 6332: my %default_names = (
6333: instcode => &mt('Official courses'),
6334: communities => &mt('Communities'),
6335: );
6336:
6337: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6338: ($cathash->{'instcode::0'} eq '') ||
6339: (!grep(/^communities$/,@{$cats[0]})) ||
6340: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 6341: $maxnum ++;
6342: }
6343: my $lastidx;
6344: for (my $i=0; $i<$numtop; $i++) {
6345: my $parent = $cats[0][$i];
6346: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6347: my $item = &escape($parent).'::0';
6348: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6349: $lastidx = $idx{$item};
6350: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6351: .'<select name="'.$item.'"'.$chgstr.'>';
6352: for (my $k=0; $k<=$maxnum; $k++) {
6353: my $vpos = $k+1;
6354: my $selstr;
6355: if ($k == $i) {
6356: $selstr = ' selected="selected" ';
6357: }
6358: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6359: }
1.160.6.29 raeburn 6360: $datatable .= '</select></span></td><td>';
1.120 raeburn 6361: if ($parent eq 'instcode' || $parent eq 'communities') {
6362: $datatable .= '<span class="LC_nobreak">'
6363: .$default_names{$parent}.'</span>';
6364: if ($parent eq 'instcode') {
6365: $datatable .= '<br /><span class="LC_nobreak">('
6366: .&mt('with institutional codes')
6367: .')</span></td><td'.$colattrib.'>';
6368: } else {
6369: $datatable .= '<table><tr><td>';
6370: }
6371: $datatable .= '<span class="LC_nobreak">'
6372: .'<label><input type="radio" name="'
6373: .$parent.'" value="1" checked="checked" />'
6374: .&mt('Display').'</label>';
6375: if ($parent eq 'instcode') {
6376: $datatable .= ' ';
6377: } else {
6378: $datatable .= '</span></td></tr><tr><td>'
6379: .'<span class="LC_nobreak">';
6380: }
6381: $datatable .= '<label><input type="radio" name="'
6382: .$parent.'" value="0" />'
6383: .&mt('Do not display').'</label></span>';
6384: if ($parent eq 'communities') {
6385: $datatable .= '</td></tr></table>';
6386: }
6387: $datatable .= '</td>';
1.57 raeburn 6388: } else {
6389: $datatable .= $parent
1.160.6.29 raeburn 6390: .' <span class="LC_nobreak"><label>'
6391: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6392: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6393: }
6394: my $depth = 1;
6395: push(@path,$parent);
6396: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6397: pop(@path);
6398: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6399: $itemcount ++;
6400: }
1.48 raeburn 6401: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6402: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6403: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6404: for (my $k=0; $k<=$maxnum; $k++) {
6405: my $vpos = $k+1;
6406: my $selstr;
1.57 raeburn 6407: if ($k == $numtop) {
1.48 raeburn 6408: $selstr = ' selected="selected" ';
6409: }
6410: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6411: }
1.59 bisitz 6412: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6413: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6414: .'</tr>'."\n";
1.48 raeburn 6415: $itemcount ++;
1.120 raeburn 6416: foreach my $default ('instcode','communities') {
6417: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6418: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6419: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6420: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6421: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6422: for (my $k=0; $k<=$maxnum; $k++) {
6423: my $vpos = $k+1;
6424: my $selstr;
6425: if ($k == $maxnum) {
6426: $selstr = ' selected="selected" ';
6427: }
6428: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6429: }
1.120 raeburn 6430: $datatable .= '</select></span></td>'.
6431: '<td><span class="LC_nobreak">'.
6432: $default_names{$default}.'</span>';
6433: if ($default eq 'instcode') {
6434: $datatable .= '<br /><span class="LC_nobreak">('
6435: .&mt('with institutional codes').')</span>';
6436: }
6437: $datatable .= '</td>'
6438: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6439: .&mt('Display').'</label> '
6440: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6441: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6442: }
6443: }
6444: }
1.57 raeburn 6445: } else {
6446: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6447: }
6448: } else {
1.160.6.87 raeburn 6449: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 6450: .&initialize_categories($itemcount);
1.48 raeburn 6451: }
1.57 raeburn 6452: $$rowtotal += $itemcount;
1.48 raeburn 6453: }
6454: return $datatable;
6455: }
6456:
1.69 raeburn 6457: sub print_serverstatuses {
6458: my ($dom,$settings,$rowtotal) = @_;
6459: my $datatable;
6460: my @pages = &serverstatus_pages();
6461: my (%namedaccess,%machineaccess);
6462: foreach my $type (@pages) {
6463: $namedaccess{$type} = '';
6464: $machineaccess{$type}= '';
6465: }
6466: if (ref($settings) eq 'HASH') {
6467: foreach my $type (@pages) {
6468: if (exists($settings->{$type})) {
6469: if (ref($settings->{$type}) eq 'HASH') {
6470: foreach my $key (keys(%{$settings->{$type}})) {
6471: if ($key eq 'namedusers') {
6472: $namedaccess{$type} = $settings->{$type}->{$key};
6473: } elsif ($key eq 'machines') {
6474: $machineaccess{$type} = $settings->{$type}->{$key};
6475: }
6476: }
6477: }
6478: }
6479: }
6480: }
1.81 raeburn 6481: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6482: my $rownum = 0;
6483: my $css_class;
6484: foreach my $type (@pages) {
6485: $rownum ++;
6486: $css_class = $rownum%2?' class="LC_odd_row"':'';
6487: $datatable .= '<tr'.$css_class.'>'.
6488: '<td><span class="LC_nobreak">'.
6489: $titles->{$type}.'</span></td>'.
6490: '<td class="LC_left_item">'.
6491: '<input type="text" name="'.$type.'_namedusers" '.
6492: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6493: '<td class="LC_right_item">'.
6494: '<span class="LC_nobreak">'.
6495: '<input type="text" name="'.$type.'_machines" '.
6496: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 6497: '</span></td></tr>'."\n";
1.69 raeburn 6498: }
6499: $$rowtotal += $rownum;
6500: return $datatable;
6501: }
6502:
6503: sub serverstatus_pages {
6504: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 6505: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 6506: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 6507: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6508: }
6509:
1.160.6.40 raeburn 6510: sub defaults_javascript {
6511: my ($settings) = @_;
1.160.6.80 raeburn 6512: 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.');
6513: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6514: &js_escape(\$intauthcheck);
6515: &js_escape(\$intauthcost);
6516: my $intauthjs = <<"ENDSCRIPT";
6517:
6518: function warnIntAuth(field) {
6519: if (field.name == 'intauth_check') {
6520: if (field.value == '2') {
6521: alert('$intauthcheck');
6522: }
6523: }
6524: if (field.name == 'intauth_cost') {
6525: field.value.replace(/\s/g,'');
6526: if (field.value != '') {
6527: var regexdigit=/^\\d+\$/;
6528: if (!regexdigit.test(field.value)) {
6529: alert('$intauthcost');
6530: }
6531: }
6532: }
6533: return;
6534: }
6535:
6536: ENDSCRIPT
6537:
6538: if (ref($settings) ne 'HASH') {
6539: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6540: }
1.160.6.40 raeburn 6541: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6542: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6543: if ($maxnum eq '') {
6544: $maxnum = 0;
6545: }
6546: $maxnum ++;
1.160.6.51 raeburn 6547: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 6548: return <<"ENDSCRIPT";
6549: <script type="text/javascript">
6550: // <![CDATA[
6551: function reorderTypes(form,caller) {
6552: var changedVal;
6553: $jstext
6554: var newpos = 'addinststatus_pos';
6555: var current = new Array;
6556: var maxh = $maxnum;
6557: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6558: var oldVal;
6559: if (caller == newpos) {
6560: changedVal = newitemVal;
6561: } else {
6562: var curritem = 'inststatus_pos_'+caller;
6563: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6564: current[newitemVal] = newpos;
6565: }
6566: for (var i=0; i<inststatuses.length; i++) {
6567: if (inststatuses[i] != caller) {
6568: var elementName = 'inststatus_pos_'+inststatuses[i];
6569: if (form.elements[elementName]) {
6570: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6571: current[currVal] = elementName;
6572: }
6573: }
6574: }
6575: for (var j=0; j<maxh; j++) {
6576: if (current[j] == undefined) {
6577: oldVal = j;
6578: }
6579: }
6580: if (oldVal < changedVal) {
6581: for (var k=oldVal+1; k<=changedVal ; k++) {
6582: var elementName = current[k];
6583: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6584: }
6585: } else {
6586: for (var k=changedVal; k<oldVal; k++) {
6587: var elementName = current[k];
6588: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6589: }
6590: }
6591: return;
6592: }
6593:
1.160.6.80 raeburn 6594: $intauthjs
6595:
1.160.6.40 raeburn 6596: // ]]>
6597: </script>
6598:
6599: ENDSCRIPT
1.160.6.80 raeburn 6600: } else {
6601: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40 raeburn 6602: }
6603: }
6604:
1.49 raeburn 6605: sub coursecategories_javascript {
6606: my ($settings) = @_;
1.57 raeburn 6607: my ($output,$jstext,$cathash);
1.49 raeburn 6608: if (ref($settings) eq 'HASH') {
1.57 raeburn 6609: $cathash = $settings->{'cats'};
6610: }
6611: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6612: my (@cats,@jsarray,%idx);
1.57 raeburn 6613: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6614: if (@jsarray > 0) {
6615: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6616: for (my $i=0; $i<@jsarray; $i++) {
6617: if (ref($jsarray[$i]) eq 'ARRAY') {
6618: my $catstr = join('","',@{$jsarray[$i]});
6619: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6620: }
6621: }
6622: }
6623: } else {
6624: $jstext = ' var categories = Array(1);'."\n".
6625: ' categories[0] = Array("instcode_pos");'."\n";
6626: }
1.160.6.42 raeburn 6627: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6628: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 6629: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6630: &js_escape(\$instcode_reserved);
6631: &js_escape(\$communities_reserved);
6632: &js_escape(\$choose_again);
1.49 raeburn 6633: $output = <<"ENDSCRIPT";
6634: <script type="text/javascript">
1.109 raeburn 6635: // <![CDATA[
1.49 raeburn 6636: function reorderCats(form,parent,item,idx) {
6637: var changedVal;
6638: $jstext
6639: var newpos = 'addcategory_pos';
6640: if (parent == '') {
6641: var has_instcode = 0;
6642: var maxtop = categories[idx].length;
6643: for (var j=0; j<maxtop; j++) {
6644: if (categories[idx][j] == 'instcode::0') {
6645: has_instcode == 1;
6646: }
6647: }
6648: if (has_instcode == 0) {
6649: categories[idx][maxtop] = 'instcode_pos';
6650: }
6651: } else {
6652: newpos += '_'+parent;
6653: }
6654: var maxh = 1 + categories[idx].length;
6655: var current = new Array;
6656: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6657: if (item == newpos) {
6658: changedVal = newitemVal;
6659: } else {
6660: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6661: current[newitemVal] = newpos;
6662: }
6663: for (var i=0; i<categories[idx].length; i++) {
6664: var elementName = categories[idx][i];
6665: if (elementName != item) {
6666: if (form.elements[elementName]) {
6667: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6668: current[currVal] = elementName;
6669: }
6670: }
6671: }
6672: var oldVal;
6673: for (var j=0; j<maxh; j++) {
6674: if (current[j] == undefined) {
6675: oldVal = j;
6676: }
6677: }
6678: if (oldVal < changedVal) {
6679: for (var k=oldVal+1; k<=changedVal ; k++) {
6680: var elementName = current[k];
6681: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6682: }
6683: } else {
6684: for (var k=changedVal; k<oldVal; k++) {
6685: var elementName = current[k];
6686: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6687: }
6688: }
6689: return;
6690: }
1.120 raeburn 6691:
6692: function categoryCheck(form) {
6693: if (form.elements['addcategory_name'].value == 'instcode') {
6694: alert('$instcode_reserved\\n$choose_again');
6695: return false;
6696: }
6697: if (form.elements['addcategory_name'].value == 'communities') {
6698: alert('$communities_reserved\\n$choose_again');
6699: return false;
6700: }
6701: return true;
6702: }
6703:
1.109 raeburn 6704: // ]]>
1.49 raeburn 6705: </script>
6706:
6707: ENDSCRIPT
6708: return $output;
6709: }
6710:
1.48 raeburn 6711: sub initialize_categories {
6712: my ($itemcount) = @_;
1.120 raeburn 6713: my ($datatable,$css_class,$chgstr);
6714: my %default_names = (
6715: instcode => 'Official courses (with institutional codes)',
6716: communities => 'Communities',
6717: );
6718: my $select0 = ' selected="selected"';
6719: my $select1 = '';
6720: foreach my $default ('instcode','communities') {
6721: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 6722: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 6723: if ($default eq 'communities') {
6724: $select1 = $select0;
6725: $select0 = '';
6726: }
6727: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6728: .'<select name="'.$default.'_pos">'
6729: .'<option value="0"'.$select0.'>1</option>'
6730: .'<option value="1"'.$select1.'>2</option>'
6731: .'<option value="2">3</option></select> '
6732: .$default_names{$default}
6733: .'</span></td><td><span class="LC_nobreak">'
6734: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6735: .&mt('Display').'</label> <label>'
6736: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6737: .'</label></span></td></tr>';
1.120 raeburn 6738: $itemcount ++;
6739: }
1.48 raeburn 6740: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6741: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6742: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6743: .'<select name="addcategory_pos"'.$chgstr.'>'
6744: .'<option value="0">1</option>'
6745: .'<option value="1">2</option>'
6746: .'<option value="2" selected="selected">3</option></select> '
1.160.6.87 raeburn 6747: .&mt('Add category').'</span></td><tda<span class="LC_nobreak">>'.&mt('Name:')
6748: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
6749: .'</td></tr>';
1.48 raeburn 6750: return $datatable;
6751: }
6752:
6753: sub build_category_rows {
1.49 raeburn 6754: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6755: my ($text,$name,$item,$chgstr);
1.48 raeburn 6756: if (ref($cats) eq 'ARRAY') {
6757: my $maxdepth = scalar(@{$cats});
6758: if (ref($cats->[$depth]) eq 'HASH') {
6759: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6760: my $numchildren = @{$cats->[$depth]{$parent}};
6761: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 6762: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6763: my ($idxnum,$parent_name,$parent_item);
6764: my $higher = $depth - 1;
6765: if ($higher == 0) {
6766: $parent_name = &escape($parent).'::'.$higher;
6767: } else {
6768: if (ref($path) eq 'ARRAY') {
6769: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6770: }
6771: }
6772: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6773: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6774: if ($j < $numchildren) {
1.48 raeburn 6775: $name = $cats->[$depth]{$parent}[$j];
6776: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6777: $idxnum = $idx->{$item};
6778: } else {
6779: $name = $parent_name;
6780: $item = $parent_item;
1.48 raeburn 6781: }
1.49 raeburn 6782: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6783: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6784: for (my $i=0; $i<=$numchildren; $i++) {
6785: my $vpos = $i+1;
6786: my $selstr;
6787: if ($j == $i) {
6788: $selstr = ' selected="selected" ';
6789: }
6790: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6791: }
6792: $text .= '</select> ';
6793: if ($j < $numchildren) {
6794: my $deeper = $depth+1;
6795: $text .= $name.' '
6796: .'<label><input type="checkbox" name="deletecategory" value="'
6797: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6798: if(ref($path) eq 'ARRAY') {
6799: push(@{$path},$name);
1.49 raeburn 6800: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6801: pop(@{$path});
6802: }
6803: } else {
1.160.6.87 raeburn 6804: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 6805: if ($j == $numchildren) {
6806: $text .= $name;
6807: } else {
6808: $text .= $item;
6809: }
6810: $text .= '" value="" />';
6811: }
6812: $text .= '</td></tr>';
6813: }
6814: $text .= '</table></td>';
6815: } else {
6816: my $higher = $depth-1;
6817: if ($higher == 0) {
6818: $name = &escape($parent).'::'.$higher;
6819: } else {
6820: if (ref($path) eq 'ARRAY') {
6821: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6822: }
6823: }
6824: my $colspan;
6825: if ($parent ne 'instcode') {
6826: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 6827: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 6828: }
6829: }
6830: }
6831: }
6832: return $text;
6833: }
6834:
1.33 raeburn 6835: sub modifiable_userdata_row {
1.160.6.93 raeburn 6836: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
6837: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 6838: my ($role,$rolename,$statustype);
6839: $role = $item;
1.160.6.34 raeburn 6840: if ($context eq 'cancreate') {
1.160.6.93 raeburn 6841: if ($item =~ /^(emailusername)_(.+)$/) {
6842: $role = $1;
6843: $statustype = $2;
1.160.6.35 raeburn 6844: if (ref($usertypes) eq 'HASH') {
6845: if ($usertypes->{$statustype}) {
6846: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6847: } else {
6848: $rolename = &mt('Data provided by user');
6849: }
6850: }
1.160.6.34 raeburn 6851: }
6852: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6853: if (ref($usertypes) eq 'HASH') {
6854: $rolename = $usertypes->{$role};
6855: } else {
6856: $rolename = $role;
6857: }
1.33 raeburn 6858: } else {
1.63 raeburn 6859: if ($role eq 'cr') {
6860: $rolename = &mt('Custom role');
6861: } else {
6862: $rolename = &Apache::lonnet::plaintext($role);
6863: }
1.33 raeburn 6864: }
1.160.6.34 raeburn 6865: my (@fields,%fieldtitles);
6866: if (ref($fieldsref) eq 'ARRAY') {
6867: @fields = @{$fieldsref};
6868: } else {
6869: @fields = ('lastname','firstname','middlename','generation',
6870: 'permanentemail','id');
6871: }
6872: if ((ref($titlesref) eq 'HASH')) {
6873: %fieldtitles = %{$titlesref};
6874: } else {
6875: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6876: }
1.33 raeburn 6877: my $output;
1.160.6.93 raeburn 6878: my $css_class;
6879: if ($rowcount%2) {
6880: $css_class = 'LC_odd_row';
6881: }
6882: if ($customcss) {
6883: $css_class .= " $customcss";
6884: }
6885: $css_class =~ s/^\s+//;
6886: if ($css_class) {
6887: $css_class = ' class="'.$css_class.'"';
6888: }
6889: if ($rowstyle) {
6890: $css_class .= ' style="'.$rowstyle.'"';
6891: }
6892: if ($rowid) {
6893: $rowid = ' id="'.$rowid.'"';
6894: }
6895:
6896: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 6897: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6898: '<td class="LC_left_item" colspan="2"><table>';
6899: my $rem;
6900: my %checks;
6901: if (ref($settings) eq 'HASH') {
6902: if (ref($settings->{$context}) eq 'HASH') {
6903: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 6904: my $hashref = $settings->{$context}->{$role};
6905: if ($role eq 'emailusername') {
6906: if ($statustype) {
6907: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6908: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 6909: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 6910: foreach my $field (@fields) {
6911: if ($hashref->{$field}) {
6912: $checks{$field} = $hashref->{$field};
6913: }
6914: }
6915: }
6916: }
6917: }
6918: } else {
6919: if (ref($hashref) eq 'HASH') {
6920: foreach my $field (@fields) {
6921: if ($hashref->{$field}) {
6922: $checks{$field} = ' checked="checked" ';
6923: }
6924: }
1.33 raeburn 6925: }
6926: }
6927: }
6928: }
6929: }
1.160.6.93 raeburn 6930:
6931: my $total = scalar(@fields);
6932: for (my $i=0; $i<$total; $i++) {
6933: $rem = $i%($numinrow);
1.33 raeburn 6934: if ($rem == 0) {
6935: if ($i > 0) {
6936: $output .= '</tr>';
6937: }
6938: $output .= '<tr>';
6939: }
6940: my $check = ' ';
1.160.6.35 raeburn 6941: unless ($role eq 'emailusername') {
6942: if (exists($checks{$fields[$i]})) {
6943: $check = $checks{$fields[$i]}
6944: } else {
6945: if ($role eq 'st') {
6946: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 6947: $check = ' checked="checked" ';
1.160.6.35 raeburn 6948: }
1.33 raeburn 6949: }
6950: }
6951: }
6952: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 6953: '<span class="LC_nobreak">';
6954: if ($role eq 'emailusername') {
6955: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6956: $checks{$fields[$i]} = 'omit';
6957: }
6958: foreach my $option ('required','optional','omit') {
6959: my $checked='';
6960: if ($checks{$fields[$i]} eq $option) {
6961: $checked='checked="checked" ';
6962: }
6963: $output .= '<label>'.
6964: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6965: &mt($option).'</label>'.(' ' x2);
6966: }
6967: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6968: } else {
6969: $output .= '<label>'.
6970: '<input type="checkbox" name="canmodify_'.$role.'" '.
6971: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6972: '</label>';
6973: }
6974: $output .= '</span></td>';
1.33 raeburn 6975: }
1.160.6.93 raeburn 6976: $rem = $total%$numinrow;
6977: my $colsleft;
6978: if ($rem) {
6979: $colsleft = $numinrow - $rem;
6980: }
6981: if ($colsleft > 1) {
1.33 raeburn 6982: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6983: ' </td>';
6984: } elsif ($colsleft == 1) {
6985: $output .= '<td class="LC_left_item"> </td>';
6986: }
6987: $output .= '</tr></table></td></tr>';
6988: return $output;
6989: }
1.28 raeburn 6990:
1.93 raeburn 6991: sub insttypes_row {
1.160.6.93 raeburn 6992: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
6993: $customcss,$rowstyle) = @_;
1.93 raeburn 6994: my %lt = &Apache::lonlocal::texthash (
6995: cansearch => 'Users allowed to search',
6996: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6997: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 6998: selfassign => 'Self-reportable affiliations',
1.93 raeburn 6999: );
7000: my $showdom;
7001: if ($context eq 'cansearch') {
7002: $showdom = ' ('.$dom.')';
7003: }
1.160.6.5 raeburn 7004: my $class = 'LC_left_item';
7005: if ($context eq 'statustocreate') {
7006: $class = 'LC_right_item';
7007: }
1.160.6.93 raeburn 7008: my $css_class;
7009: if ($$rowtotal%2) {
7010: $css_class = 'LC_odd_row';
7011: }
7012: if ($customcss) {
7013: $css_class .= ' '.$customcss;
7014: }
7015: $css_class =~ s/^\s+//;
7016: if ($css_class) {
7017: $css_class = ' class="'.$css_class.'"';
7018: }
7019: if ($rowstyle) {
7020: $css_class .= ' style="'.$rowstyle.'"';
7021: }
7022: if ($onclick) {
7023: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 7024: }
7025: my $output = '<tr'.$css_class.'>'.
7026: '<td>'.$lt{$context}.$showdom.
7027: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 7028: my $rem;
7029: if (ref($types) eq 'ARRAY') {
7030: for (my $i=0; $i<@{$types}; $i++) {
7031: if (defined($usertypes->{$types->[$i]})) {
7032: my $rem = $i%($numinrow);
7033: if ($rem == 0) {
7034: if ($i > 0) {
7035: $output .= '</tr>';
7036: }
7037: $output .= '<tr>';
1.23 raeburn 7038: }
1.26 raeburn 7039: my $check = ' ';
1.99 raeburn 7040: if (ref($settings) eq 'HASH') {
7041: if (ref($settings->{$context}) eq 'ARRAY') {
7042: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
7043: $check = ' checked="checked" ';
7044: }
7045: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7046: $check = ' checked="checked" ';
7047: }
1.23 raeburn 7048: }
1.26 raeburn 7049: $output .= '<td class="LC_left_item">'.
7050: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7051: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 7052: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 7053: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7054: }
7055: }
1.26 raeburn 7056: $rem = @{$types}%($numinrow);
1.23 raeburn 7057: }
7058: my $colsleft = $numinrow - $rem;
1.160.6.87 raeburn 7059: if ($rem == 0) {
1.131 raeburn 7060: $output .= '<tr>';
7061: }
1.23 raeburn 7062: if ($colsleft > 1) {
1.25 raeburn 7063: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7064: } else {
1.25 raeburn 7065: $output .= '<td class="LC_left_item">';
1.23 raeburn 7066: }
7067: my $defcheck = ' ';
1.99 raeburn 7068: if (ref($settings) eq 'HASH') {
7069: if (ref($settings->{$context}) eq 'ARRAY') {
7070: if (grep(/^default$/,@{$settings->{$context}})) {
7071: $defcheck = ' checked="checked" ';
7072: }
7073: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7074: $defcheck = ' checked="checked" ';
7075: }
1.23 raeburn 7076: }
1.25 raeburn 7077: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7078: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 7079: 'value="default"'.$defcheck.$onclick.'/>'.
1.25 raeburn 7080: $othertitle.'</label></span></td>'.
7081: '</tr></table></td></tr>';
7082: return $output;
1.23 raeburn 7083: }
7084:
7085: sub sorted_searchtitles {
7086: my %searchtitles = &Apache::lonlocal::texthash(
7087: 'uname' => 'username',
7088: 'lastname' => 'last name',
7089: 'lastfirst' => 'last name, first name',
7090: );
7091: my @titleorder = ('uname','lastname','lastfirst');
7092: return (\%searchtitles,\@titleorder);
7093: }
7094:
1.25 raeburn 7095: sub sorted_searchtypes {
7096: my %srchtypes_desc = (
7097: exact => 'is exact match',
7098: contains => 'contains ..',
7099: begins => 'begins with ..',
7100: );
7101: my @srchtypeorder = ('exact','begins','contains');
7102: return (\%srchtypes_desc,\@srchtypeorder);
7103: }
7104:
1.3 raeburn 7105: sub usertype_update_row {
7106: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7107: my $datatable;
7108: my $numinrow = 4;
7109: foreach my $type (@{$types}) {
7110: if (defined($usertypes->{$type})) {
7111: $$rownums ++;
7112: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7113: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7114: '</td><td class="LC_left_item"><table>';
7115: for (my $i=0; $i<@{$fields}; $i++) {
7116: my $rem = $i%($numinrow);
7117: if ($rem == 0) {
7118: if ($i > 0) {
7119: $datatable .= '</tr>';
7120: }
7121: $datatable .= '<tr>';
7122: }
7123: my $check = ' ';
1.39 raeburn 7124: if (ref($settings) eq 'HASH') {
7125: if (ref($settings->{'fields'}) eq 'HASH') {
7126: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7127: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7128: $check = ' checked="checked" ';
7129: }
1.3 raeburn 7130: }
7131: }
7132: }
7133:
7134: if ($i == @{$fields}-1) {
7135: my $colsleft = $numinrow - $rem;
7136: if ($colsleft > 1) {
7137: $datatable .= '<td colspan="'.$colsleft.'">';
7138: } else {
7139: $datatable .= '<td>';
7140: }
7141: } else {
7142: $datatable .= '<td>';
7143: }
1.8 raeburn 7144: $datatable .= '<span class="LC_nobreak"><label>'.
7145: '<input type="checkbox" name="updateable_'.$type.
7146: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7147: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7148: }
7149: $datatable .= '</tr></table></td></tr>';
7150: }
7151: }
7152: return $datatable;
1.1 raeburn 7153: }
7154:
7155: sub modify_login {
1.160.6.24 raeburn 7156: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 7157: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7158: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7159: %title = ( coursecatalog => 'Display course catalog',
7160: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 7161: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 7162: newuser => 'Link for visitors to create a user account',
7163: loginheader => 'Log-in box header');
7164: @offon = ('off','on');
1.112 raeburn 7165: if (ref($domconfig{login}) eq 'HASH') {
7166: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7167: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7168: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7169: }
7170: }
7171: }
1.9 raeburn 7172: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7173: \%domconfig,\%loginhash);
1.160.6.14 raeburn 7174: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7175: foreach my $item (@toggles) {
7176: $loginhash{login}{$item} = $env{'form.'.$item};
7177: }
1.41 raeburn 7178: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7179: if (ref($colchanges{'login'}) eq 'HASH') {
7180: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7181: \%loginhash);
7182: }
1.110 raeburn 7183:
1.149 raeburn 7184: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 7185: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7186: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7187: if (keys(%servers) > 1) {
7188: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7189: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7190: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7191: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7192: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7193: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7194: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7195: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7196: $changes{'loginvia'}{$lonhost} = 1;
7197: } else {
7198: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7199: $changes{'loginvia'}{$lonhost} = 1;
7200: }
7201: } else {
7202: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7203: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7204: $changes{'loginvia'}{$lonhost} = 1;
7205: }
7206: }
7207: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7208: foreach my $item (@loginvia_attribs) {
7209: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7210: }
7211: } else {
7212: foreach my $item (@loginvia_attribs) {
7213: my $new = $env{'form.'.$lonhost.'_'.$item};
7214: if (($item eq 'serverpath') && ($new eq 'custom')) {
7215: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7216: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7217: $new = '/';
7218: }
7219: }
7220: if (($item eq 'custompath') &&
7221: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7222: $new = '';
7223: }
7224: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7225: $changes{'loginvia'}{$lonhost} = 1;
7226: }
7227: if ($item eq 'exempt') {
1.160.6.56 raeburn 7228: $new = &check_exempt_addresses($new);
1.128 raeburn 7229: }
7230: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7231: }
7232: }
1.112 raeburn 7233: } else {
1.128 raeburn 7234: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7235: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7236: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7237: foreach my $item (@loginvia_attribs) {
7238: my $new = $env{'form.'.$lonhost.'_'.$item};
7239: if (($item eq 'serverpath') && ($new eq 'custom')) {
7240: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7241: $new = '/';
7242: }
7243: }
7244: if (($item eq 'custompath') &&
7245: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7246: $new = '';
7247: }
7248: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7249: }
1.110 raeburn 7250: }
7251: }
7252: }
7253: }
1.119 raeburn 7254:
1.160.6.5 raeburn 7255: my $servadm = $r->dir_config('lonAdmEMail');
7256: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7257: if (ref($domconfig{'login'}) eq 'HASH') {
7258: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7259: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7260: if ($lang eq 'nolang') {
7261: push(@currlangs,$lang);
7262: } elsif (defined($langchoices{$lang})) {
7263: push(@currlangs,$lang);
7264: } else {
7265: next;
7266: }
7267: }
7268: }
7269: }
7270: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7271: if (@currlangs > 0) {
7272: foreach my $lang (@currlangs) {
7273: if (grep(/^\Q$lang\E$/,@delurls)) {
7274: $changes{'helpurl'}{$lang} = 1;
7275: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7276: $changes{'helpurl'}{$lang} = 1;
7277: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7278: push(@newlangs,$lang);
7279: } else {
7280: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7281: }
7282: }
7283: }
7284: unless (grep(/^nolang$/,@currlangs)) {
7285: if ($env{'form.loginhelpurl_nolang.filename'}) {
7286: $changes{'helpurl'}{'nolang'} = 1;
7287: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7288: push(@newlangs,'nolang');
7289: }
7290: }
7291: if ($env{'form.loginhelpurl_add_lang'}) {
7292: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7293: ($env{'form.loginhelpurl_add_file.filename'})) {
7294: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7295: $addedfile = $env{'form.loginhelpurl_add_lang'};
7296: }
7297: }
7298: if ((@newlangs > 0) || ($addedfile)) {
7299: my $error;
7300: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7301: if ($configuserok eq 'ok') {
7302: if ($switchserver) {
7303: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7304: } elsif ($author_ok eq 'ok') {
7305: my @allnew = @newlangs;
7306: if ($addedfile ne '') {
7307: push(@allnew,$addedfile);
7308: }
7309: foreach my $lang (@allnew) {
7310: my $formelem = 'loginhelpurl_'.$lang;
7311: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7312: $formelem = 'loginhelpurl_add_file';
7313: }
7314: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7315: "help/$lang",'','',$newfile{$lang});
7316: if ($result eq 'ok') {
7317: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7318: $changes{'helpurl'}{$lang} = 1;
7319: } else {
7320: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7321: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7322: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
7323: (!grep(/^\Q$lang\E$/,@delurls))) {
7324: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7325: }
7326: }
7327: }
7328: } else {
7329: $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);
7330: }
7331: } else {
7332: $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);
7333: }
7334: if ($error) {
7335: &Apache::lonnet::logthis($error);
7336: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7337: }
7338: }
1.160.6.56 raeburn 7339:
7340: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7341: if (ref($domconfig{'login'}) eq 'HASH') {
7342: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7343: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7344: if ($domservers{$lonhost}) {
7345: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7346: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 7347: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 7348: }
7349: }
7350: }
7351: }
7352: }
7353: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7354: foreach my $lonhost (sort(keys(%domservers))) {
7355: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7356: $changes{'headtag'}{$lonhost} = 1;
7357: } else {
7358: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7359: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7360: }
7361: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7362: push(@newhosts,$lonhost);
7363: } elsif ($currheadtagurls{$lonhost}) {
7364: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7365: if ($currexempt{$lonhost}) {
7366: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
7367: $changes{'headtag'}{$lonhost} = 1;
7368: }
7369: } elsif ($possexempt{$lonhost}) {
7370: $changes{'headtag'}{$lonhost} = 1;
7371: }
7372: if ($possexempt{$lonhost}) {
7373: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7374: }
7375: }
7376: }
7377: }
7378: if (@newhosts) {
7379: my $error;
7380: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7381: if ($configuserok eq 'ok') {
7382: if ($switchserver) {
7383: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7384: } elsif ($author_ok eq 'ok') {
7385: foreach my $lonhost (@newhosts) {
7386: my $formelem = 'loginheadtag_'.$lonhost;
7387: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7388: "login/headtag/$lonhost",'','',
7389: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7390: if ($result eq 'ok') {
7391: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7392: $changes{'headtag'}{$lonhost} = 1;
7393: if ($possexempt{$lonhost}) {
7394: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7395: }
7396: } else {
7397: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7398: $newheadtagurls{$lonhost},$result);
7399: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7400: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7401: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7402: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7403: }
7404: }
7405: }
7406: } else {
7407: $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);
7408: }
7409: } else {
7410: $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);
7411: }
7412: if ($error) {
7413: &Apache::lonnet::logthis($error);
7414: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7415: }
7416: }
1.160.6.5 raeburn 7417: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7418:
7419: my $defaulthelpfile = '/adm/loginproblems.html';
7420: my $defaulttext = &mt('Default in use');
7421:
1.1 raeburn 7422: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7423: $dom);
7424: if ($putresult eq 'ok') {
1.160.6.14 raeburn 7425: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7426: my %defaultchecked = (
7427: 'coursecatalog' => 'on',
1.160.6.14 raeburn 7428: 'helpdesk' => 'on',
1.42 raeburn 7429: 'adminmail' => 'off',
1.43 raeburn 7430: 'newuser' => 'off',
1.42 raeburn 7431: );
1.55 raeburn 7432: if (ref($domconfig{'login'}) eq 'HASH') {
7433: foreach my $item (@toggles) {
7434: if ($defaultchecked{$item} eq 'on') {
7435: if (($domconfig{'login'}{$item} eq '0') &&
7436: ($env{'form.'.$item} eq '1')) {
7437: $changes{$item} = 1;
7438: } elsif (($domconfig{'login'}{$item} eq '' ||
7439: $domconfig{'login'}{$item} eq '1') &&
7440: ($env{'form.'.$item} eq '0')) {
7441: $changes{$item} = 1;
7442: }
7443: } elsif ($defaultchecked{$item} eq 'off') {
7444: if (($domconfig{'login'}{$item} eq '1') &&
7445: ($env{'form.'.$item} eq '0')) {
7446: $changes{$item} = 1;
7447: } elsif (($domconfig{'login'}{$item} eq '' ||
7448: $domconfig{'login'}{$item} eq '0') &&
7449: ($env{'form.'.$item} eq '1')) {
7450: $changes{$item} = 1;
7451: }
1.42 raeburn 7452: }
7453: }
1.41 raeburn 7454: }
1.6 raeburn 7455: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7456: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7457: if (ref($lastactref) eq 'HASH') {
7458: $lastactref->{'domainconfig'} = 1;
7459: }
1.1 raeburn 7460: $resulttext = &mt('Changes made:').'<ul>';
7461: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7462: if ($item eq 'loginvia') {
1.112 raeburn 7463: if (ref($changes{$item}) eq 'HASH') {
7464: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7465: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7466: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7467: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7468: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7469: $protocol = 'http' if ($protocol ne 'https');
7470: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7471:
7472: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7473: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7474: } else {
7475: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7476: }
7477: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7478: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7479: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7480: }
7481: $resulttext .= '</li>';
7482: } else {
7483: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7484: }
1.112 raeburn 7485: } else {
1.128 raeburn 7486: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7487: }
7488: }
1.128 raeburn 7489: $resulttext .= '</ul></li>';
1.112 raeburn 7490: }
1.160.6.5 raeburn 7491: } elsif ($item eq 'helpurl') {
7492: if (ref($changes{$item}) eq 'HASH') {
7493: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7494: if (grep(/^\Q$lang\E$/,@delurls)) {
7495: my ($chg,$link);
7496: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7497: if ($lang eq 'nolang') {
7498: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7499: } else {
7500: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7501: }
7502: $resulttext .= '<li>'.$chg.'</li>';
7503: } else {
7504: my $chg;
7505: if ($lang eq 'nolang') {
7506: $chg = &mt('custom log-in help file for no preferred language');
7507: } else {
7508: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7509: }
7510: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7511: $loginhash{'login'}{'helpurl'}{$lang}.
7512: '?inhibitmenu=yes',$chg,600,500).
7513: '</li>';
7514: }
7515: }
7516: }
1.160.6.56 raeburn 7517: } elsif ($item eq 'headtag') {
7518: if (ref($changes{$item}) eq 'HASH') {
7519: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7520: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7521: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7522: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7523: $resulttext .= '<li><a href="'.
7524: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7525: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7526: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7527: if ($possexempt{$lonhost}) {
7528: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7529: } else {
7530: $resulttext .= &mt('included for any client IP');
7531: }
7532: $resulttext .= '</li>';
7533: }
7534: }
7535: }
1.160.6.5 raeburn 7536: } elsif ($item eq 'captcha') {
7537: if (ref($loginhash{'login'}) eq 'HASH') {
7538: my $chgtxt;
7539: if ($loginhash{'login'}{$item} eq 'notused') {
7540: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7541: } else {
7542: my %captchas = &captcha_phrases();
7543: if ($captchas{$loginhash{'login'}{$item}}) {
7544: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7545: } else {
7546: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7547: }
7548: }
7549: $resulttext .= '<li>'.$chgtxt.'</li>';
7550: }
7551: } elsif ($item eq 'recaptchakeys') {
7552: if (ref($loginhash{'login'}) eq 'HASH') {
7553: my ($privkey,$pubkey);
7554: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7555: $pubkey = $loginhash{'login'}{$item}{'public'};
7556: $privkey = $loginhash{'login'}{$item}{'private'};
7557: }
7558: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7559: if (!$pubkey) {
7560: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7561: } else {
7562: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7563: }
7564: if (!$privkey) {
7565: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7566: } else {
1.160.6.53 raeburn 7567: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 7568: }
7569: $chgtxt .= '</ul>';
7570: $resulttext .= '<li>'.$chgtxt.'</li>';
7571: }
1.160.6.69 raeburn 7572: } elsif ($item eq 'recaptchaversion') {
7573: if (ref($loginhash{'login'}) eq 'HASH') {
7574: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
7575: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
7576: '</li>';
7577: }
7578: }
1.41 raeburn 7579: } else {
7580: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7581: }
1.1 raeburn 7582: }
1.6 raeburn 7583: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7584: } else {
7585: $resulttext = &mt('No changes made to log-in page settings');
7586: }
7587: } else {
1.11 albertel 7588: $resulttext = '<span class="LC_error">'.
7589: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7590: }
1.6 raeburn 7591: if ($errors) {
1.9 raeburn 7592: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7593: $errors.'</ul>';
7594: }
7595: return $resulttext;
7596: }
7597:
1.160.6.56 raeburn 7598: sub check_exempt_addresses {
7599: my ($iplist) = @_;
7600: $iplist =~ s/^\s+//;
7601: $iplist =~ s/\s+$//;
7602: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7603: my (@okips,$new);
7604: foreach my $ip (@poss_ips) {
7605: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7606: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7607: push(@okips,$ip);
7608: }
7609: }
7610: }
7611: if (@okips > 0) {
7612: $new = join(',',@okips);
7613: } else {
7614: $new = '';
7615: }
7616: return $new;
7617: }
7618:
1.6 raeburn 7619: sub color_font_choices {
7620: my %choices =
7621: &Apache::lonlocal::texthash (
7622: img => "Header",
7623: bgs => "Background colors",
7624: links => "Link colors",
1.55 raeburn 7625: images => "Images",
1.6 raeburn 7626: font => "Font color",
1.160.6.22 raeburn 7627: fontmenu => "Font menu",
1.76 raeburn 7628: pgbg => "Page",
1.6 raeburn 7629: tabbg => "Header",
7630: sidebg => "Border",
7631: link => "Link",
7632: alink => "Active link",
7633: vlink => "Visited link",
7634: );
7635: return %choices;
7636: }
7637:
7638: sub modify_rolecolors {
1.160.6.24 raeburn 7639: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7640: my ($resulttext,%rolehash);
7641: $rolehash{'rolecolors'} = {};
1.55 raeburn 7642: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7643: if ($domconfig{'rolecolors'} eq '') {
7644: $domconfig{'rolecolors'} = {};
7645: }
7646: }
1.9 raeburn 7647: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7648: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7649: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7650: $dom);
7651: if ($putresult eq 'ok') {
7652: if (keys(%changes) > 0) {
1.41 raeburn 7653: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7654: if (ref($lastactref) eq 'HASH') {
7655: $lastactref->{'domainconfig'} = 1;
7656: }
1.6 raeburn 7657: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7658: $rolehash{'rolecolors'});
7659: } else {
7660: $resulttext = &mt('No changes made to default color schemes');
7661: }
7662: } else {
1.11 albertel 7663: $resulttext = '<span class="LC_error">'.
7664: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7665: }
7666: if ($errors) {
7667: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7668: $errors.'</ul>';
7669: }
7670: return $resulttext;
7671: }
7672:
7673: sub modify_colors {
1.9 raeburn 7674: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7675: my (%changes,%choices);
1.51 raeburn 7676: my @bgs;
1.6 raeburn 7677: my @links = ('link','alink','vlink');
1.41 raeburn 7678: my @logintext;
1.6 raeburn 7679: my @images;
7680: my $servadm = $r->dir_config('lonAdmEMail');
7681: my $errors;
1.160.6.22 raeburn 7682: my %defaults;
1.6 raeburn 7683: foreach my $role (@{$roles}) {
7684: if ($role eq 'login') {
1.12 raeburn 7685: %choices = &login_choices();
1.41 raeburn 7686: @logintext = ('textcol','bgcol');
1.12 raeburn 7687: } else {
7688: %choices = &color_font_choices();
7689: }
7690: if ($role eq 'login') {
1.41 raeburn 7691: @images = ('img','logo','domlogo','login');
1.51 raeburn 7692: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7693: } else {
7694: @images = ('img');
1.160.6.22 raeburn 7695: @bgs = ('pgbg','tabbg','sidebg');
7696: }
7697: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7698: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7699: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7700: }
7701: if ($role eq 'login') {
7702: foreach my $item (@logintext) {
1.160.6.39 raeburn 7703: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7704: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7705: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7706: }
7707: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 7708: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7709: }
7710: }
7711: } else {
1.160.6.39 raeburn 7712: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7713: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7714: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7715: }
7716: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 7717: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7718: }
1.6 raeburn 7719: }
1.160.6.22 raeburn 7720: foreach my $item (@bgs) {
1.160.6.39 raeburn 7721: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7722: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7723: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7724: }
7725: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 7726: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7727: }
7728: }
7729: foreach my $item (@links) {
1.160.6.39 raeburn 7730: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7731: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7732: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7733: }
7734: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 7735: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7736: }
1.6 raeburn 7737: }
1.46 raeburn 7738: my ($configuserok,$author_ok,$switchserver) =
7739: &config_check($dom,$confname,$servadm);
1.9 raeburn 7740: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7741: if (ref($domconfig->{$role}) ne 'HASH') {
7742: $domconfig->{$role} = {};
7743: }
1.8 raeburn 7744: foreach my $img (@images) {
1.70 raeburn 7745: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7746: if (defined($env{'form.login_showlogo_'.$img})) {
7747: $confhash->{$role}{'showlogo'}{$img} = 1;
7748: } else {
7749: $confhash->{$role}{'showlogo'}{$img} = 0;
7750: }
7751: }
1.18 albertel 7752: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7753: && !defined($domconfig->{$role}{$img})
7754: && !$env{'form.'.$role.'_del_'.$img}
7755: && $env{'form.'.$role.'_import_'.$img}) {
7756: # import the old configured image from the .tab setting
7757: # if they haven't provided a new one
7758: $domconfig->{$role}{$img} =
7759: $env{'form.'.$role.'_import_'.$img};
7760: }
1.6 raeburn 7761: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7762: my $error;
1.6 raeburn 7763: if ($configuserok eq 'ok') {
1.9 raeburn 7764: if ($switchserver) {
1.12 raeburn 7765: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7766: } else {
7767: if ($author_ok eq 'ok') {
7768: my ($result,$logourl) =
7769: &publishlogo($r,'upload',$role.'_'.$img,
7770: $dom,$confname,$img,$width,$height);
7771: if ($result eq 'ok') {
7772: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7773: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7774: } else {
1.12 raeburn 7775: $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 7776: }
7777: } else {
1.46 raeburn 7778: $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 7779: }
7780: }
7781: } else {
1.46 raeburn 7782: $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 7783: }
7784: if ($error) {
1.8 raeburn 7785: &Apache::lonnet::logthis($error);
1.11 albertel 7786: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7787: }
7788: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7789: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7790: my $error;
7791: if ($configuserok eq 'ok') {
7792: # is confname an author?
7793: if ($switchserver eq '') {
7794: if ($author_ok eq 'ok') {
7795: my ($result,$logourl) =
7796: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7797: $dom,$confname,$img,$width,$height);
7798: if ($result eq 'ok') {
7799: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7800: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7801: }
7802: }
7803: }
7804: }
1.6 raeburn 7805: }
7806: }
7807: }
7808: if (ref($domconfig) eq 'HASH') {
7809: if (ref($domconfig->{$role}) eq 'HASH') {
7810: foreach my $img (@images) {
7811: if ($domconfig->{$role}{$img} ne '') {
7812: if ($env{'form.'.$role.'_del_'.$img}) {
7813: $confhash->{$role}{$img} = '';
1.12 raeburn 7814: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7815: } else {
1.9 raeburn 7816: if ($confhash->{$role}{$img} eq '') {
7817: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7818: }
1.6 raeburn 7819: }
7820: } else {
7821: if ($env{'form.'.$role.'_del_'.$img}) {
7822: $confhash->{$role}{$img} = '';
1.12 raeburn 7823: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7824: }
7825: }
1.70 raeburn 7826: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7827: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7828: if ($confhash->{$role}{'showlogo'}{$img} ne
7829: $domconfig->{$role}{'showlogo'}{$img}) {
7830: $changes{$role}{'showlogo'}{$img} = 1;
7831: }
7832: } else {
7833: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7834: $changes{$role}{'showlogo'}{$img} = 1;
7835: }
7836: }
7837: }
7838: }
1.6 raeburn 7839: if ($domconfig->{$role}{'font'} ne '') {
7840: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7841: $changes{$role}{'font'} = 1;
7842: }
7843: } else {
7844: if ($confhash->{$role}{'font'}) {
7845: $changes{$role}{'font'} = 1;
7846: }
7847: }
1.107 raeburn 7848: if ($role ne 'login') {
7849: if ($domconfig->{$role}{'fontmenu'} ne '') {
7850: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7851: $changes{$role}{'fontmenu'} = 1;
7852: }
7853: } else {
7854: if ($confhash->{$role}{'fontmenu'}) {
7855: $changes{$role}{'fontmenu'} = 1;
7856: }
1.97 tempelho 7857: }
7858: }
1.6 raeburn 7859: foreach my $item (@bgs) {
7860: if ($domconfig->{$role}{$item} ne '') {
7861: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7862: $changes{$role}{'bgs'}{$item} = 1;
7863: }
7864: } else {
7865: if ($confhash->{$role}{$item}) {
7866: $changes{$role}{'bgs'}{$item} = 1;
7867: }
7868: }
7869: }
7870: foreach my $item (@links) {
7871: if ($domconfig->{$role}{$item} ne '') {
7872: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7873: $changes{$role}{'links'}{$item} = 1;
7874: }
7875: } else {
7876: if ($confhash->{$role}{$item}) {
7877: $changes{$role}{'links'}{$item} = 1;
7878: }
7879: }
7880: }
1.41 raeburn 7881: foreach my $item (@logintext) {
7882: if ($domconfig->{$role}{$item} ne '') {
7883: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7884: $changes{$role}{'logintext'}{$item} = 1;
7885: }
7886: } else {
7887: if ($confhash->{$role}{$item}) {
7888: $changes{$role}{'logintext'}{$item} = 1;
7889: }
7890: }
7891: }
1.6 raeburn 7892: } else {
7893: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7894: \@logintext,$confhash,\%changes);
1.6 raeburn 7895: }
7896: } else {
7897: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7898: \@logintext,$confhash,\%changes);
1.6 raeburn 7899: }
7900: }
7901: return ($errors,%changes);
7902: }
7903:
1.46 raeburn 7904: sub config_check {
7905: my ($dom,$confname,$servadm) = @_;
7906: my ($configuserok,$author_ok,$switchserver,%currroles);
7907: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7908: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7909: $confname,$servadm);
7910: if ($configuserok eq 'ok') {
7911: $switchserver = &check_switchserver($dom,$confname);
7912: if ($switchserver eq '') {
7913: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7914: }
7915: }
7916: return ($configuserok,$author_ok,$switchserver);
7917: }
7918:
1.6 raeburn 7919: sub default_change_checker {
1.41 raeburn 7920: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7921: foreach my $item (@{$links}) {
7922: if ($confhash->{$role}{$item}) {
7923: $changes->{$role}{'links'}{$item} = 1;
7924: }
7925: }
7926: foreach my $item (@{$bgs}) {
7927: if ($confhash->{$role}{$item}) {
7928: $changes->{$role}{'bgs'}{$item} = 1;
7929: }
7930: }
1.41 raeburn 7931: foreach my $item (@{$logintext}) {
7932: if ($confhash->{$role}{$item}) {
7933: $changes->{$role}{'logintext'}{$item} = 1;
7934: }
7935: }
1.6 raeburn 7936: foreach my $img (@{$images}) {
7937: if ($env{'form.'.$role.'_del_'.$img}) {
7938: $confhash->{$role}{$img} = '';
1.12 raeburn 7939: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7940: }
1.70 raeburn 7941: if ($role eq 'login') {
7942: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7943: $changes->{$role}{'showlogo'}{$img} = 1;
7944: }
7945: }
1.6 raeburn 7946: }
7947: if ($confhash->{$role}{'font'}) {
7948: $changes->{$role}{'font'} = 1;
7949: }
1.48 raeburn 7950: }
1.6 raeburn 7951:
7952: sub display_colorchgs {
7953: my ($dom,$changes,$roles,$confhash) = @_;
7954: my (%choices,$resulttext);
7955: if (!grep(/^login$/,@{$roles})) {
7956: $resulttext = &mt('Changes made:').'<br />';
7957: }
7958: foreach my $role (@{$roles}) {
7959: if ($role eq 'login') {
7960: %choices = &login_choices();
7961: } else {
7962: %choices = &color_font_choices();
7963: }
7964: if (ref($changes->{$role}) eq 'HASH') {
7965: if ($role ne 'login') {
7966: $resulttext .= '<h4>'.&mt($role).'</h4>';
7967: }
7968: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7969: if ($role ne 'login') {
7970: $resulttext .= '<ul>';
7971: }
7972: if (ref($changes->{$role}{$key}) eq 'HASH') {
7973: if ($role ne 'login') {
7974: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7975: }
7976: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7977: if (($role eq 'login') && ($key eq 'showlogo')) {
7978: if ($confhash->{$role}{$key}{$item}) {
7979: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7980: } else {
7981: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7982: }
7983: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7984: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7985: } else {
1.12 raeburn 7986: my $newitem = $confhash->{$role}{$item};
7987: if ($key eq 'images') {
7988: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7989: }
7990: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7991: }
7992: }
7993: if ($role ne 'login') {
7994: $resulttext .= '</ul></li>';
7995: }
7996: } else {
7997: if ($confhash->{$role}{$key} eq '') {
7998: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7999: } else {
8000: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
8001: }
8002: }
8003: if ($role ne 'login') {
8004: $resulttext .= '</ul>';
8005: }
8006: }
8007: }
8008: }
1.3 raeburn 8009: return $resulttext;
1.1 raeburn 8010: }
8011:
1.9 raeburn 8012: sub thumb_dimensions {
8013: return ('200','50');
8014: }
8015:
1.16 raeburn 8016: sub check_dimensions {
8017: my ($inputfile) = @_;
8018: my ($fullwidth,$fullheight);
8019: if ($inputfile =~ m|^[/\w.\-]+$|) {
8020: if (open(PIPE,"identify $inputfile 2>&1 |")) {
8021: my $imageinfo = <PIPE>;
8022: if (!close(PIPE)) {
8023: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
8024: }
8025: chomp($imageinfo);
8026: my ($fullsize) =
1.21 raeburn 8027: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 8028: if ($fullsize) {
8029: ($fullwidth,$fullheight) = split(/x/,$fullsize);
8030: }
8031: }
8032: }
8033: return ($fullwidth,$fullheight);
8034: }
8035:
1.9 raeburn 8036: sub check_configuser {
8037: my ($uhome,$dom,$confname,$servadm) = @_;
8038: my ($configuserok,%currroles);
8039: if ($uhome eq 'no_host') {
8040: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
8041: my $configpass = &LONCAPA::Enrollment::create_password();
8042: $configuserok =
8043: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
8044: $configpass,'','','','','',undef,$servadm);
8045: } else {
8046: $configuserok = 'ok';
8047: %currroles =
8048: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
8049: }
8050: return ($configuserok,%currroles);
8051: }
8052:
8053: sub check_authorstatus {
8054: my ($dom,$confname,%currroles) = @_;
8055: my $author_ok;
1.40 raeburn 8056: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8057: my $start = time;
8058: my $end = 0;
8059: $author_ok =
8060: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8061: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8062: } else {
8063: $author_ok = 'ok';
8064: }
8065: return $author_ok;
8066: }
8067:
8068: sub publishlogo {
1.46 raeburn 8069: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 8070: my ($output,$fname,$logourl);
8071: if ($action eq 'upload') {
8072: $fname=$env{'form.'.$formname.'.filename'};
8073: chop($env{'form.'.$formname});
8074: } else {
8075: ($fname) = ($formname =~ /([^\/]+)$/);
8076: }
1.46 raeburn 8077: if ($savefileas ne '') {
8078: $fname = $savefileas;
8079: }
1.9 raeburn 8080: $fname=&Apache::lonnet::clean_filename($fname);
8081: # See if there is anything left
8082: unless ($fname) { return ('error: no uploaded file'); }
8083: $fname="$subdir/$fname";
1.160.6.5 raeburn 8084: my $docroot=$r->dir_config('lonDocRoot');
8085: my $filepath="$docroot/priv";
8086: my $relpath = "$dom/$confname";
1.9 raeburn 8087: my ($fnamepath,$file,$fetchthumb);
8088: $file=$fname;
8089: if ($fname=~m|/|) {
8090: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8091: }
1.160.6.26 raeburn 8092: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8093: my $count;
1.160.6.5 raeburn 8094: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8095: $filepath.="/$parts[$count]";
8096: if ((-e $filepath)!=1) {
8097: mkdir($filepath,02770);
8098: }
8099: }
8100: # Check for bad extension and disallow upload
8101: if ($file=~/\.(\w+)$/ &&
8102: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8103: $output =
1.160.6.25 raeburn 8104: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8105: } elsif ($file=~/\.(\w+)$/ &&
8106: !defined(&Apache::loncommon::fileembstyle($1))) {
8107: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8108: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 8109: $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 8110: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 8111: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8112: } else {
8113: my $source = $filepath.'/'.$file;
8114: my $logfile;
1.160.6.88 raeburn 8115: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 8116: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8117: }
8118: print $logfile
8119: "\n================= Publish ".localtime()." ================\n".
8120: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8121: # Save the file
1.160.6.88 raeburn 8122: if (!open(FH,">",$source)) {
1.9 raeburn 8123: &Apache::lonnet::logthis('Failed to create '.$source);
8124: return (&mt('Failed to create file'));
8125: }
8126: if ($action eq 'upload') {
8127: if (!print FH ($env{'form.'.$formname})) {
8128: &Apache::lonnet::logthis('Failed to write to '.$source);
8129: return (&mt('Failed to write file'));
8130: }
8131: } else {
8132: my $original = &Apache::lonnet::filelocation('',$formname);
8133: if(!copy($original,$source)) {
8134: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8135: return (&mt('Failed to write file'));
8136: }
8137: }
8138: close(FH);
8139: chmod(0660, $source); # Permissions to rw-rw---.
8140:
8141: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8142: my $copyfile=$targetdir.'/'.$file;
8143:
8144: my @parts=split(/\//,$targetdir);
8145: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8146: for (my $count=5;$count<=$#parts;$count++) {
8147: $path.="/$parts[$count]";
8148: if (!-e $path) {
8149: print $logfile "\nCreating directory ".$path;
8150: mkdir($path,02770);
8151: }
8152: }
8153: my $versionresult;
8154: if (-e $copyfile) {
8155: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8156: } else {
8157: $versionresult = 'ok';
8158: }
8159: if ($versionresult eq 'ok') {
8160: if (copy($source,$copyfile)) {
8161: print $logfile "\nCopied original source to ".$copyfile."\n";
8162: $output = 'ok';
8163: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8164: push(@{$modified_urls},[$copyfile,$source]);
8165: my $metaoutput =
8166: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8167: unless ($registered_cleanup) {
8168: my $handlers = $r->get_handlers('PerlCleanupHandler');
8169: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8170: $registered_cleanup=1;
8171: }
1.9 raeburn 8172: } else {
8173: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8174: $output = &mt('Failed to copy file to RES space').", $!";
8175: }
8176: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8177: my $inputfile = $filepath.'/'.$file;
8178: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8179: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8180: if ($fullwidth ne '' && $fullheight ne '') {
8181: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8182: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 8183: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
8184: system({$args[0]} @args);
1.16 raeburn 8185: chmod(0660, $filepath.'/tn-'.$file);
8186: if (-e $outfile) {
8187: my $copyfile=$targetdir.'/tn-'.$file;
8188: if (copy($outfile,$copyfile)) {
8189: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8190: my $thumb_metaoutput =
8191: &write_metadata($dom,$confname,$formname,
8192: $targetdir,'tn-'.$file,$logfile);
8193: push(@{$modified_urls},[$copyfile,$outfile]);
8194: unless ($registered_cleanup) {
8195: my $handlers = $r->get_handlers('PerlCleanupHandler');
8196: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8197: $registered_cleanup=1;
8198: }
1.16 raeburn 8199: } else {
8200: print $logfile "\nUnable to write ".$copyfile.
8201: ':'.$!."\n";
8202: }
8203: }
1.9 raeburn 8204: }
8205: }
8206: }
8207: } else {
8208: $output = $versionresult;
8209: }
8210: }
8211: return ($output,$logourl);
8212: }
8213:
8214: sub logo_versioning {
8215: my ($targetdir,$file,$logfile) = @_;
8216: my $target = $targetdir.'/'.$file;
8217: my ($maxversion,$fn,$extn,$output);
8218: $maxversion = 0;
8219: if ($file =~ /^(.+)\.(\w+)$/) {
8220: $fn=$1;
8221: $extn=$2;
8222: }
8223: opendir(DIR,$targetdir);
8224: while (my $filename=readdir(DIR)) {
8225: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8226: $maxversion=($1>$maxversion)?$1:$maxversion;
8227: }
8228: }
8229: $maxversion++;
8230: print $logfile "\nCreating old version ".$maxversion."\n";
8231: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8232: if (copy($target,$copyfile)) {
8233: print $logfile "Copied old target to ".$copyfile."\n";
8234: $copyfile=$copyfile.'.meta';
8235: if (copy($target.'.meta',$copyfile)) {
8236: print $logfile "Copied old target metadata to ".$copyfile."\n";
8237: $output = 'ok';
8238: } else {
8239: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8240: $output = &mt('Failed to copy old meta').", $!, ";
8241: }
8242: } else {
8243: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8244: $output = &mt('Failed to copy old target').", $!, ";
8245: }
8246: return $output;
8247: }
8248:
8249: sub write_metadata {
8250: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8251: my (%metadatafields,%metadatakeys,$output);
8252: $metadatafields{'title'}=$formname;
8253: $metadatafields{'creationdate'}=time;
8254: $metadatafields{'lastrevisiondate'}=time;
8255: $metadatafields{'copyright'}='public';
8256: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8257: $env{'user.domain'};
8258: $metadatafields{'authorspace'}=$confname.':'.$dom;
8259: $metadatafields{'domain'}=$dom;
8260: {
8261: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8262: my $mfh;
1.160.6.88 raeburn 8263: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 8264: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8265: unless ($_=~/\./) {
8266: my $unikey=$_;
8267: $unikey=~/^([A-Za-z]+)/;
8268: my $tag=$1;
8269: $tag=~tr/A-Z/a-z/;
8270: print $mfh "\n\<$tag";
8271: foreach (split(/\,/,$metadatakeys{$unikey})) {
8272: my $value=$metadatafields{$unikey.'.'.$_};
8273: $value=~s/\"/\'\'/g;
8274: print $mfh ' '.$_.'="'.$value.'"';
8275: }
8276: print $mfh '>'.
8277: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8278: .'</'.$tag.'>';
8279: }
8280: }
8281: $output = 'ok';
8282: print $logfile "\nWrote metadata";
8283: close($mfh);
8284: } else {
8285: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8286: $output = &mt('Could not write metadata');
8287: }
8288: }
1.155 raeburn 8289: return $output;
8290: }
8291:
8292: sub notifysubscribed {
8293: foreach my $targetsource (@{$modified_urls}){
8294: next unless (ref($targetsource) eq 'ARRAY');
8295: my ($target,$source)=@{$targetsource};
8296: if ($source ne '') {
1.160.6.88 raeburn 8297: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 8298: print $logfh "\nCleanup phase: Notifications\n";
8299: my @subscribed=&subscribed_hosts($target);
8300: foreach my $subhost (@subscribed) {
8301: print $logfh "\nNotifying host ".$subhost.':';
8302: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8303: print $logfh $reply;
8304: }
8305: my @subscribedmeta=&subscribed_hosts("$target.meta");
8306: foreach my $subhost (@subscribedmeta) {
8307: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8308: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8309: $subhost);
8310: print $logfh $reply;
8311: }
8312: print $logfh "\n============ Done ============\n";
1.160 raeburn 8313: close($logfh);
1.155 raeburn 8314: }
8315: }
8316: }
8317: return OK;
8318: }
8319:
8320: sub subscribed_hosts {
8321: my ($target) = @_;
8322: my @subscribed;
1.160.6.88 raeburn 8323: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 8324: while (my $subline=<$fh>) {
8325: if ($subline =~ /^($match_lonid):/) {
8326: my $host = $1;
8327: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8328: unless (grep(/^\Q$host\E$/,@subscribed)) {
8329: push(@subscribed,$host);
8330: }
8331: }
8332: }
8333: }
8334: }
8335: return @subscribed;
1.9 raeburn 8336: }
8337:
8338: sub check_switchserver {
8339: my ($dom,$confname) = @_;
8340: my ($allowed,$switchserver);
8341: my $home = &Apache::lonnet::homeserver($confname,$dom);
8342: if ($home eq 'no_host') {
8343: $home = &Apache::lonnet::domain($dom,'primary');
8344: }
8345: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8346: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8347: if (!$allowed) {
1.160.6.11 raeburn 8348: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8349: }
8350: return $switchserver;
8351: }
8352:
1.1 raeburn 8353: sub modify_quotas {
1.160.6.30 raeburn 8354: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8355: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 8356: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 8357: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8358: $validationfieldsref);
1.86 raeburn 8359: if ($action eq 'quotas') {
8360: $context = 'tools';
1.160.6.26 raeburn 8361: } else {
1.86 raeburn 8362: $context = $action;
8363: }
8364: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 8365: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 8366: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8367: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8368: %titles = &courserequest_titles();
8369: $toolregexp = join('|',@usertools);
8370: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 8371: $confname = $dom.'-domainconfig';
8372: my $servadm = $r->dir_config('lonAdmEMail');
8373: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 8374: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8375: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 8376: } elsif ($context eq 'requestauthor') {
8377: @usertools = ('author');
8378: %titles = &authorrequest_titles();
1.86 raeburn 8379: } else {
1.160.6.4 raeburn 8380: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8381: %titles = &tool_titles();
1.86 raeburn 8382: }
1.160.6.27 raeburn 8383: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8384: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8385: foreach my $key (keys(%env)) {
1.101 raeburn 8386: if ($context eq 'requestcourses') {
8387: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8388: my $item = $1;
8389: my $type = $2;
8390: if ($type =~ /^limit_(.+)/) {
8391: $limithash{$item}{$1} = $env{$key};
8392: } else {
8393: $confhash{$item}{$type} = $env{$key};
8394: }
8395: }
1.160.6.5 raeburn 8396: } elsif ($context eq 'requestauthor') {
8397: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8398: $confhash{$1} = $env{$key};
8399: }
1.101 raeburn 8400: } else {
1.86 raeburn 8401: if ($key =~ /^form\.quota_(.+)$/) {
8402: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 8403: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8404: $confhash{'authorquota'}{$1} = $env{$key};
8405: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8406: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8407: }
1.72 raeburn 8408: }
8409: }
1.160.6.5 raeburn 8410: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 8411: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8412: @approvalnotify = sort(@approvalnotify);
8413: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 8414: my @crstypes = ('official','unofficial','community','textbook');
8415: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8416: foreach my $type (@hasuniquecode) {
8417: if (grep(/^\Q$type\E$/,@crstypes)) {
8418: $confhash{'uniquecode'}{$type} = 1;
8419: }
8420: }
1.160.6.46 raeburn 8421: my (%newbook,%allpos);
1.160.6.30 raeburn 8422: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8423: foreach my $type ('textbooks','templates') {
8424: @{$allpos{$type}} = ();
8425: my $invalid;
8426: if ($type eq 'textbooks') {
8427: $invalid = &mt('Invalid LON-CAPA course for textbook');
8428: } else {
8429: $invalid = &mt('Invalid LON-CAPA course for template');
8430: }
8431: if ($env{'form.'.$type.'_addbook'}) {
8432: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8433: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8434: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8435: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8436: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8437: } else {
8438: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8439: my $position = $env{'form.'.$type.'_addbook_pos'};
8440: $position =~ s/\D+//g;
8441: if ($position ne '') {
8442: $allpos{$type}[$position] = $newbook{$type};
8443: }
1.160.6.30 raeburn 8444: }
1.160.6.46 raeburn 8445: } else {
8446: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 8447: }
8448: }
1.160.6.46 raeburn 8449: }
1.160.6.30 raeburn 8450: }
1.102 raeburn 8451: if (ref($domconfig{$action}) eq 'HASH') {
8452: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8453: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8454: $changes{'notify'}{'approval'} = 1;
8455: }
8456: } else {
1.144 raeburn 8457: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8458: $changes{'notify'}{'approval'} = 1;
8459: }
8460: }
1.160.6.30 raeburn 8461: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8462: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8463: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8464: unless ($confhash{'uniquecode'}{$crstype}) {
8465: $changes{'uniquecode'} = 1;
8466: }
8467: }
8468: unless ($changes{'uniquecode'}) {
8469: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8470: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8471: $changes{'uniquecode'} = 1;
8472: }
8473: }
8474: }
8475: } else {
8476: $changes{'uniquecode'} = 1;
8477: }
8478: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8479: $changes{'uniquecode'} = 1;
8480: }
8481: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8482: foreach my $type ('textbooks','templates') {
8483: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8484: my %deletions;
8485: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8486: if (@todelete) {
8487: map { $deletions{$_} = 1; } @todelete;
8488: }
8489: my %imgdeletions;
8490: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8491: if (@todeleteimages) {
8492: map { $imgdeletions{$_} = 1; } @todeleteimages;
8493: }
8494: my $maxnum = $env{'form.'.$type.'_maxnum'};
8495: for (my $i=0; $i<=$maxnum; $i++) {
8496: my $itemid = $env{'form.'.$type.'_id_'.$i};
8497: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8498: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8499: if ($deletions{$key}) {
8500: if ($domconfig{$action}{$type}{$key}{'image'}) {
8501: #FIXME need to obsolete item in RES space
8502: }
8503: next;
8504: } else {
8505: my $newpos = $env{'form.'.$itemid};
8506: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 8507: foreach my $item ('subject','title','publisher','author') {
8508: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8509: ($type eq 'templates'));
1.160.6.46 raeburn 8510: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8511: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8512: $changes{$type}{$key} = 1;
8513: }
8514: }
8515: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 8516: }
1.160.6.46 raeburn 8517: if ($imgdeletions{$key}) {
8518: $changes{$type}{$key} = 1;
8519: #FIXME need to obsolete item in RES space
8520: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8521: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 8522: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
8523: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
8524: } else {
8525: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8526: $cdom,$cnum,$type,$configuserok,
8527: $switchserver,$author_ok);
8528: if ($imgurl) {
8529: $confhash{$type}{$key}{'image'} = $imgurl;
8530: $changes{$type}{$key} = 1;
8531: }
8532: if ($error) {
8533: &Apache::lonnet::logthis($error);
8534: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8535: }
1.160.6.46 raeburn 8536: }
8537: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8538: $confhash{$type}{$key}{'image'} =
8539: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 8540: }
8541: }
8542: }
8543: }
8544: }
8545: }
1.102 raeburn 8546: } else {
1.144 raeburn 8547: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8548: $changes{'notify'}{'approval'} = 1;
8549: }
1.160.6.30 raeburn 8550: if (ref($confhash{'uniquecode'} eq 'HASH')) {
8551: $changes{'uniquecode'} = 1;
8552: }
8553: }
8554: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8555: foreach my $type ('textbooks','templates') {
8556: if ($newbook{$type}) {
8557: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 8558: foreach my $item ('subject','title','publisher','author') {
8559: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8560: ($type eq 'template'));
1.160.6.46 raeburn 8561: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8562: if ($env{'form.'.$type.'_addbook_'.$item}) {
8563: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8564: }
8565: }
8566: if ($type eq 'textbooks') {
8567: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8568: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 8569: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
8570: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
8571: } else {
8572: my ($imageurl,$error) =
8573: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8574: $configuserok,$switchserver,$author_ok);
8575: if ($imageurl) {
8576: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8577: }
8578: if ($error) {
8579: &Apache::lonnet::logthis($error);
8580: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8581: }
1.160.6.46 raeburn 8582: }
8583: }
1.160.6.30 raeburn 8584: }
8585: }
1.160.6.46 raeburn 8586: if (@{$allpos{$type}} > 0) {
8587: my $idx = 0;
8588: foreach my $item (@{$allpos{$type}}) {
8589: if ($item ne '') {
8590: $confhash{$type}{$item}{'order'} = $idx;
8591: if (ref($domconfig{$action}) eq 'HASH') {
8592: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8593: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8594: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8595: $changes{$type}{$item} = 1;
8596: }
1.160.6.30 raeburn 8597: }
8598: }
8599: }
1.160.6.46 raeburn 8600: $idx ++;
1.160.6.30 raeburn 8601: }
8602: }
8603: }
8604: }
1.160.6.39 raeburn 8605: if (ref($validationitemsref) eq 'ARRAY') {
8606: foreach my $item (@{$validationitemsref}) {
8607: if ($item eq 'fields') {
8608: my @changed;
8609: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8610: if (@{$confhash{'validation'}{$item}} > 0) {
8611: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8612: }
1.160.6.65 raeburn 8613: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8614: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8615: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8616: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8617: $domconfig{'requestcourses'}{'validation'}{$item});
8618: } else {
8619: @changed = @{$confhash{'validation'}{$item}};
8620: }
1.160.6.39 raeburn 8621: } else {
8622: @changed = @{$confhash{'validation'}{$item}};
8623: }
8624: } else {
8625: @changed = @{$confhash{'validation'}{$item}};
8626: }
8627: if (@changed) {
8628: if ($confhash{'validation'}{$item}) {
8629: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8630: } else {
8631: $changes{'validation'}{$item} = &mt('None');
8632: }
8633: }
8634: } else {
8635: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8636: if ($item eq 'markup') {
8637: if ($env{'form.requestcourses_validation_'.$item}) {
8638: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8639: }
8640: }
1.160.6.65 raeburn 8641: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8642: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8643: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8644: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8645: }
8646: } else {
8647: if ($confhash{'validation'}{$item} ne '') {
8648: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8649: }
1.160.6.39 raeburn 8650: }
8651: } else {
8652: if ($confhash{'validation'}{$item} ne '') {
8653: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8654: }
8655: }
8656: }
8657: }
8658: }
8659: if ($env{'form.validationdc'}) {
8660: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 8661: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 8662: if (exists($domcoords{$newval})) {
8663: $confhash{'validation'}{'dc'} = $newval;
8664: }
8665: }
8666: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 8667: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8668: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8669: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8670: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8671: if ($confhash{'validation'}{'dc'} eq '') {
8672: $changes{'validation'}{'dc'} = &mt('None');
8673: } else {
8674: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8675: }
1.160.6.39 raeburn 8676: }
1.160.6.65 raeburn 8677: } elsif ($confhash{'validation'}{'dc'} ne '') {
8678: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 8679: }
8680: } elsif ($confhash{'validation'}{'dc'} ne '') {
8681: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8682: }
8683: } elsif ($confhash{'validation'}{'dc'} ne '') {
8684: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8685: }
1.160.6.65 raeburn 8686: } else {
8687: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8688: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8689: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8690: $changes{'validation'}{'dc'} = &mt('None');
8691: }
8692: }
1.160.6.39 raeburn 8693: }
8694: }
1.102 raeburn 8695: }
8696: } else {
1.86 raeburn 8697: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 8698: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8699: }
1.72 raeburn 8700: foreach my $item (@usertools) {
8701: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8702: my $unset;
1.101 raeburn 8703: if ($context eq 'requestcourses') {
1.104 raeburn 8704: $unset = '0';
8705: if ($type eq '_LC_adv') {
8706: $unset = '';
8707: }
1.101 raeburn 8708: if ($confhash{$item}{$type} eq 'autolimit') {
8709: $confhash{$item}{$type} .= '=';
8710: unless ($limithash{$item}{$type} =~ /\D/) {
8711: $confhash{$item}{$type} .= $limithash{$item}{$type};
8712: }
8713: }
1.160.6.5 raeburn 8714: } elsif ($context eq 'requestauthor') {
8715: $unset = '0';
8716: if ($type eq '_LC_adv') {
8717: $unset = '';
8718: }
1.72 raeburn 8719: } else {
1.101 raeburn 8720: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8721: $confhash{$item}{$type} = 1;
8722: } else {
8723: $confhash{$item}{$type} = 0;
8724: }
1.72 raeburn 8725: }
1.86 raeburn 8726: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 8727: if ($action eq 'requestauthor') {
8728: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8729: $changes{$type} = 1;
8730: }
8731: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8732: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8733: $changes{$item}{$type} = 1;
8734: }
8735: } else {
8736: if ($context eq 'requestcourses') {
1.104 raeburn 8737: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8738: $changes{$item}{$type} = 1;
8739: }
8740: } else {
8741: if (!$confhash{$item}{$type}) {
8742: $changes{$item}{$type} = 1;
8743: }
8744: }
8745: }
8746: } else {
8747: if ($context eq 'requestcourses') {
1.104 raeburn 8748: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8749: $changes{$item}{$type} = 1;
8750: }
1.160.6.5 raeburn 8751: } elsif ($context eq 'requestauthor') {
8752: if ($confhash{$type} ne $unset) {
8753: $changes{$type} = 1;
8754: }
1.72 raeburn 8755: } else {
8756: if (!$confhash{$item}{$type}) {
8757: $changes{$item}{$type} = 1;
8758: }
8759: }
8760: }
1.1 raeburn 8761: }
8762: }
1.160.6.5 raeburn 8763: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8764: if (ref($domconfig{'quotas'}) eq 'HASH') {
8765: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8766: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8767: if (exists($confhash{'defaultquota'}{$key})) {
8768: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8769: $changes{'defaultquota'}{$key} = 1;
8770: }
8771: } else {
8772: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8773: }
8774: }
1.86 raeburn 8775: } else {
8776: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8777: if (exists($confhash{'defaultquota'}{$key})) {
8778: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8779: $changes{'defaultquota'}{$key} = 1;
8780: }
8781: } else {
8782: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8783: }
1.1 raeburn 8784: }
8785: }
1.160.6.20 raeburn 8786: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8787: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8788: if (exists($confhash{'authorquota'}{$key})) {
8789: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8790: $changes{'authorquota'}{$key} = 1;
8791: }
8792: } else {
8793: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8794: }
8795: }
8796: }
1.1 raeburn 8797: }
1.86 raeburn 8798: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8799: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8800: if (ref($domconfig{'quotas'}) eq 'HASH') {
8801: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8802: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8803: $changes{'defaultquota'}{$key} = 1;
8804: }
8805: } else {
8806: if (!exists($domconfig{'quotas'}{$key})) {
8807: $changes{'defaultquota'}{$key} = 1;
8808: }
1.72 raeburn 8809: }
8810: } else {
1.86 raeburn 8811: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8812: }
1.1 raeburn 8813: }
8814: }
1.160.6.20 raeburn 8815: if (ref($confhash{'authorquota'}) eq 'HASH') {
8816: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8817: if (ref($domconfig{'quotas'}) eq 'HASH') {
8818: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8819: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8820: $changes{'authorquota'}{$key} = 1;
8821: }
8822: } else {
8823: $changes{'authorquota'}{$key} = 1;
8824: }
8825: } else {
8826: $changes{'authorquota'}{$key} = 1;
8827: }
8828: }
8829: }
1.1 raeburn 8830: }
1.72 raeburn 8831:
1.160.6.5 raeburn 8832: if ($context eq 'requestauthor') {
8833: $domdefaults{'requestauthor'} = \%confhash;
8834: } else {
8835: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 8836: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 8837: $domdefaults{$key} = $confhash{$key};
8838: }
1.160.6.5 raeburn 8839: }
1.72 raeburn 8840: }
1.160.6.5 raeburn 8841:
1.1 raeburn 8842: my %quotahash = (
1.86 raeburn 8843: $action => { %confhash }
1.1 raeburn 8844: );
8845: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8846: $dom);
8847: if ($putresult eq 'ok') {
8848: if (keys(%changes) > 0) {
1.72 raeburn 8849: my $cachetime = 24*60*60;
8850: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 8851: if (ref($lastactref) eq 'HASH') {
8852: $lastactref->{'domdefaults'} = 1;
8853: }
1.1 raeburn 8854: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 8855: unless (($context eq 'requestcourses') ||
8856: ($context eq 'requestauthor')) {
1.86 raeburn 8857: if (ref($changes{'defaultquota'}) eq 'HASH') {
8858: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8859: foreach my $type (@{$types},'default') {
8860: if (defined($changes{'defaultquota'}{$type})) {
8861: my $typetitle = $usertypes->{$type};
8862: if ($type eq 'default') {
8863: $typetitle = $othertitle;
8864: }
1.160.6.28 raeburn 8865: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8866: }
8867: }
1.86 raeburn 8868: $resulttext .= '</ul></li>';
1.72 raeburn 8869: }
1.160.6.20 raeburn 8870: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 8871: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 8872: foreach my $type (@{$types},'default') {
8873: if (defined($changes{'authorquota'}{$type})) {
8874: my $typetitle = $usertypes->{$type};
8875: if ($type eq 'default') {
8876: $typetitle = $othertitle;
8877: }
1.160.6.28 raeburn 8878: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 8879: }
8880: }
8881: $resulttext .= '</ul></li>';
8882: }
1.72 raeburn 8883: }
1.80 raeburn 8884: my %newenv;
1.72 raeburn 8885: foreach my $item (@usertools) {
1.160.6.5 raeburn 8886: my (%haschgs,%inconf);
8887: if ($context eq 'requestauthor') {
8888: %haschgs = %changes;
8889: %inconf = %confhash;
8890: } else {
8891: if (ref($changes{$item}) eq 'HASH') {
8892: %haschgs = %{$changes{$item}};
8893: }
8894: if (ref($confhash{$item}) eq 'HASH') {
8895: %inconf = %{$confhash{$item}};
8896: }
8897: }
8898: if (keys(%haschgs) > 0) {
1.80 raeburn 8899: my $newacc =
8900: &Apache::lonnet::usertools_access($env{'user.name'},
8901: $env{'user.domain'},
1.86 raeburn 8902: $item,'reload',$context);
1.160.6.5 raeburn 8903: if (($context eq 'requestcourses') ||
8904: ($context eq 'requestauthor')) {
1.108 raeburn 8905: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8906: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8907: }
8908: } else {
8909: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8910: $newenv{'environment.availabletools.'.$item} = $newacc;
8911: }
1.80 raeburn 8912: }
1.160.6.5 raeburn 8913: unless ($context eq 'requestauthor') {
8914: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8915: }
1.72 raeburn 8916: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 8917: if ($haschgs{$type}) {
1.72 raeburn 8918: my $typetitle = $usertypes->{$type};
8919: if ($type eq 'default') {
8920: $typetitle = $othertitle;
8921: } elsif ($type eq '_LC_adv') {
8922: $typetitle = 'LON-CAPA Advanced Users';
8923: }
1.160.6.5 raeburn 8924: if ($inconf{$type}) {
1.101 raeburn 8925: if ($context eq 'requestcourses') {
8926: my $cond;
1.160.6.5 raeburn 8927: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8928: if ($1 eq '') {
8929: $cond = &mt('(Automatic processing of any request).');
8930: } else {
8931: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8932: }
8933: } else {
1.160.6.5 raeburn 8934: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8935: }
8936: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 8937: } elsif ($context eq 'requestauthor') {
8938: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8939: $titles{$inconf{$type}},$typetitle);
8940:
1.101 raeburn 8941: } else {
8942: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8943: }
1.72 raeburn 8944: } else {
1.104 raeburn 8945: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 8946: if ($inconf{$type} eq '0') {
1.104 raeburn 8947: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8948: } else {
8949: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8950: }
8951: } else {
8952: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8953: }
1.72 raeburn 8954: }
8955: }
1.26 raeburn 8956: }
1.160.6.5 raeburn 8957: unless ($context eq 'requestauthor') {
8958: $resulttext .= '</ul></li>';
8959: }
1.26 raeburn 8960: }
1.1 raeburn 8961: }
1.160.6.5 raeburn 8962: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8963: if (ref($changes{'notify'}) eq 'HASH') {
8964: if ($changes{'notify'}{'approval'}) {
8965: if (ref($confhash{'notify'}) eq 'HASH') {
8966: if ($confhash{'notify'}{'approval'}) {
8967: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8968: } else {
1.160.6.5 raeburn 8969: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8970: }
8971: }
8972: }
8973: }
8974: }
1.160.6.30 raeburn 8975: if ($action eq 'requestcourses') {
8976: my @offon = ('off','on');
8977: if ($changes{'uniquecode'}) {
8978: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8979: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8980: $resulttext .= '<li>'.
8981: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8982: '</li>';
8983: } else {
8984: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8985: '</li>';
8986: }
8987: }
1.160.6.46 raeburn 8988: foreach my $type ('textbooks','templates') {
8989: if (ref($changes{$type}) eq 'HASH') {
8990: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8991: foreach my $key (sort(keys(%{$changes{$type}}))) {
8992: my %coursehash = &Apache::lonnet::coursedescription($key);
8993: my $coursetitle = $coursehash{'description'};
8994: my $position = $confhash{$type}{$key}{'order'} + 1;
8995: $resulttext .= '<li>';
1.160.6.47 raeburn 8996: foreach my $item ('subject','title','publisher','author') {
8997: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8998: ($type eq 'templates'));
1.160.6.46 raeburn 8999: my $name = $item.':';
9000: $name =~ s/^(\w)/\U$1/;
9001: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
9002: }
9003: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
9004: if ($type eq 'textbooks') {
9005: if ($confhash{$type}{$key}{'image'}) {
9006: $resulttext .= ' '.&mt('Image: [_1]',
9007: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
9008: ' alt="Textbook cover" />').'<br />';
9009: }
9010: }
9011: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 9012: }
1.160.6.46 raeburn 9013: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 9014: }
9015: }
1.160.6.39 raeburn 9016: if (ref($changes{'validation'}) eq 'HASH') {
9017: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
9018: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
9019: foreach my $item (@{$validationitemsref}) {
9020: if (exists($changes{'validation'}{$item})) {
9021: if ($item eq 'markup') {
9022: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9023: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
9024: } else {
9025: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
9026: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
9027: }
9028: }
9029: }
9030: if (exists($changes{'validation'}{'dc'})) {
9031: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
9032: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
9033: }
9034: }
9035: }
1.160.6.30 raeburn 9036: }
1.1 raeburn 9037: $resulttext .= '</ul>';
1.80 raeburn 9038: if (keys(%newenv)) {
9039: &Apache::lonnet::appenv(\%newenv);
9040: }
1.1 raeburn 9041: } else {
1.86 raeburn 9042: if ($context eq 'requestcourses') {
9043: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 9044: } elsif ($context eq 'requestauthor') {
9045: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 9046: } else {
1.90 weissno 9047: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 9048: }
1.1 raeburn 9049: }
9050: } else {
1.11 albertel 9051: $resulttext = '<span class="LC_error">'.
9052: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9053: }
1.160.6.30 raeburn 9054: if ($errors) {
9055: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
9056: '<ul>'.$errors.'</ul></p>';
9057: }
1.3 raeburn 9058: return $resulttext;
1.1 raeburn 9059: }
9060:
1.160.6.30 raeburn 9061: sub process_textbook_image {
1.160.6.46 raeburn 9062: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 9063: my $filename = $env{'form.'.$caller.'.filename'};
9064: my ($error,$url);
9065: my ($width,$height) = (50,50);
9066: if ($configuserok eq 'ok') {
9067: if ($switchserver) {
9068: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9069: $switchserver);
9070: } elsif ($author_ok eq 'ok') {
9071: my ($result,$imageurl) =
9072: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 9073: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 9074: if ($result eq 'ok') {
9075: $url = $imageurl;
9076: } else {
9077: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9078: }
9079: } else {
9080: $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);
9081: }
9082: } else {
9083: $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);
9084: }
9085: return ($url,$error);
9086: }
9087:
1.3 raeburn 9088: sub modify_autoenroll {
1.160.6.24 raeburn 9089: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9090: my ($resulttext,%changes);
9091: my %currautoenroll;
9092: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9093: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9094: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9095: }
9096: }
9097: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9098: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9099: sender => 'Sender for notification messages',
1.160.6.68 raeburn 9100: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9101: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9102: my @offon = ('off','on');
1.17 raeburn 9103: my $sender_uname = $env{'form.sender_uname'};
9104: my $sender_domain = $env{'form.sender_domain'};
9105: if ($sender_domain eq '') {
9106: $sender_uname = '';
9107: } elsif ($sender_uname eq '') {
9108: $sender_domain = '';
9109: }
1.129 raeburn 9110: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 9111: my $failsafe = $env{'form.autoenroll_failsafe'};
9112: $failsafe =~ s{^\s+|\s+$}{}g;
9113: if ($failsafe =~ /\D/) {
9114: undef($failsafe);
9115: }
1.1 raeburn 9116: my %autoenrollhash = (
1.129 raeburn 9117: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9118: 'sender_uname' => $sender_uname,
9119: 'sender_domain' => $sender_domain,
9120: 'co-owners' => $coowners,
1.160.6.68 raeburn 9121: 'autofailsafe' => $failsafe,
1.1 raeburn 9122: }
9123: );
1.4 raeburn 9124: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9125: $dom);
1.1 raeburn 9126: if ($putresult eq 'ok') {
9127: if (exists($currautoenroll{'run'})) {
9128: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9129: $changes{'run'} = 1;
9130: }
9131: } elsif ($autorun) {
9132: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9133: $changes{'run'} = 1;
1.1 raeburn 9134: }
9135: }
1.17 raeburn 9136: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9137: $changes{'sender'} = 1;
9138: }
1.17 raeburn 9139: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9140: $changes{'sender'} = 1;
9141: }
1.129 raeburn 9142: if ($currautoenroll{'co-owners'} ne '') {
9143: if ($currautoenroll{'co-owners'} ne $coowners) {
9144: $changes{'coowners'} = 1;
9145: }
9146: } elsif ($coowners) {
9147: $changes{'coowners'} = 1;
1.160.6.68 raeburn 9148: }
9149: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9150: $changes{'autofailsafe'} = 1;
9151: }
1.1 raeburn 9152: if (keys(%changes) > 0) {
9153: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9154: if ($changes{'run'}) {
1.1 raeburn 9155: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9156: }
9157: if ($changes{'sender'}) {
1.17 raeburn 9158: if ($sender_uname eq '' || $sender_domain eq '') {
9159: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9160: } else {
9161: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9162: }
1.1 raeburn 9163: }
1.129 raeburn 9164: if ($changes{'coowners'}) {
9165: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9166: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9167: if (ref($lastactref) eq 'HASH') {
9168: $lastactref->{'domainconfig'} = 1;
9169: }
1.129 raeburn 9170: }
1.160.6.68 raeburn 9171: if ($changes{'autofailsafe'}) {
9172: if ($failsafe ne '') {
1.160.6.82 raeburn 9173: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 9174: } else {
1.160.6.82 raeburn 9175: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 9176: }
9177: &Apache::lonnet::get_domain_defaults($dom,1);
9178: if (ref($lastactref) eq 'HASH') {
9179: $lastactref->{'domdefaults'} = 1;
9180: }
9181: }
1.1 raeburn 9182: $resulttext .= '</ul>';
9183: } else {
9184: $resulttext = &mt('No changes made to auto-enrollment settings');
9185: }
9186: } else {
1.11 albertel 9187: $resulttext = '<span class="LC_error">'.
9188: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9189: }
1.3 raeburn 9190: return $resulttext;
1.1 raeburn 9191: }
9192:
9193: sub modify_autoupdate {
1.3 raeburn 9194: my ($dom,%domconfig) = @_;
1.1 raeburn 9195: my ($resulttext,%currautoupdate,%fields,%changes);
9196: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9197: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9198: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9199: }
9200: }
9201: my @offon = ('off','on');
9202: my %title = &Apache::lonlocal::texthash (
9203: run => 'Auto-update:',
9204: classlists => 'Updates to user information in classlists?'
9205: );
1.44 raeburn 9206: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9207: my %fieldtitles = &Apache::lonlocal::texthash (
9208: id => 'Student/Employee ID',
1.20 raeburn 9209: permanentemail => 'E-mail address',
1.1 raeburn 9210: lastname => 'Last Name',
9211: firstname => 'First Name',
9212: middlename => 'Middle Name',
1.132 raeburn 9213: generation => 'Generation',
1.1 raeburn 9214: );
1.142 raeburn 9215: $othertitle = &mt('All users');
1.1 raeburn 9216: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9217: $othertitle = &mt('Other users');
1.1 raeburn 9218: }
9219: foreach my $key (keys(%env)) {
9220: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9221: my ($usertype,$item) = ($1,$2);
9222: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9223: if ($usertype eq 'default') {
9224: push(@{$fields{$1}},$2);
9225: } elsif (ref($types) eq 'ARRAY') {
9226: if (grep(/^\Q$usertype\E$/,@{$types})) {
9227: push(@{$fields{$1}},$2);
9228: }
9229: }
9230: }
1.1 raeburn 9231: }
9232: }
1.131 raeburn 9233: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9234: @lockablenames = sort(@lockablenames);
9235: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9236: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9237: if (@changed) {
9238: $changes{'lockablenames'} = 1;
9239: }
9240: } else {
9241: if (@lockablenames) {
9242: $changes{'lockablenames'} = 1;
9243: }
9244: }
1.1 raeburn 9245: my %updatehash = (
9246: autoupdate => { run => $env{'form.autoupdate_run'},
9247: classlists => $env{'form.classlists'},
9248: fields => {%fields},
1.131 raeburn 9249: lockablenames => \@lockablenames,
1.1 raeburn 9250: }
9251: );
9252: foreach my $key (keys(%currautoupdate)) {
9253: if (($key eq 'run') || ($key eq 'classlists')) {
9254: if (exists($updatehash{autoupdate}{$key})) {
9255: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9256: $changes{$key} = 1;
9257: }
9258: }
9259: } elsif ($key eq 'fields') {
9260: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9261: foreach my $item (@{$types},'default') {
1.1 raeburn 9262: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9263: my $change = 0;
9264: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9265: if (!exists($fields{$item})) {
9266: $change = 1;
1.132 raeburn 9267: last;
1.1 raeburn 9268: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9269: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9270: $change = 1;
1.132 raeburn 9271: last;
1.1 raeburn 9272: }
9273: }
9274: }
9275: if ($change) {
9276: push(@{$changes{$key}},$item);
9277: }
1.26 raeburn 9278: }
1.1 raeburn 9279: }
9280: }
1.131 raeburn 9281: } elsif ($key eq 'lockablenames') {
9282: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9283: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9284: if (@changed) {
9285: $changes{'lockablenames'} = 1;
9286: }
9287: } else {
9288: if (@lockablenames) {
9289: $changes{'lockablenames'} = 1;
9290: }
9291: }
9292: }
9293: }
9294: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
9295: if (@lockablenames) {
9296: $changes{'lockablenames'} = 1;
1.1 raeburn 9297: }
9298: }
1.26 raeburn 9299: foreach my $item (@{$types},'default') {
9300: if (defined($fields{$item})) {
9301: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 9302: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
9303: my $change = 0;
9304: if (ref($fields{$item}) eq 'ARRAY') {
9305: foreach my $type (@{$fields{$item}}) {
9306: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9307: $change = 1;
9308: last;
9309: }
9310: }
9311: }
9312: if ($change) {
9313: push(@{$changes{'fields'}},$item);
9314: }
9315: } else {
1.26 raeburn 9316: push(@{$changes{'fields'}},$item);
9317: }
9318: } else {
9319: push(@{$changes{'fields'}},$item);
1.1 raeburn 9320: }
9321: }
9322: }
9323: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9324: $dom);
9325: if ($putresult eq 'ok') {
9326: if (keys(%changes) > 0) {
9327: $resulttext = &mt('Changes made:').'<ul>';
9328: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9329: if ($key eq 'lockablenames') {
9330: $resulttext .= '<li>';
9331: if (@lockablenames) {
9332: $usertypes->{'default'} = $othertitle;
9333: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9334: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9335: } else {
9336: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9337: }
9338: $resulttext .= '</li>';
9339: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9340: foreach my $item (@{$changes{$key}}) {
9341: my @newvalues;
9342: foreach my $type (@{$fields{$item}}) {
9343: push(@newvalues,$fieldtitles{$type});
9344: }
1.3 raeburn 9345: my $newvaluestr;
9346: if (@newvalues > 0) {
9347: $newvaluestr = join(', ',@newvalues);
9348: } else {
9349: $newvaluestr = &mt('none');
1.6 raeburn 9350: }
1.1 raeburn 9351: if ($item eq 'default') {
1.26 raeburn 9352: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9353: } else {
1.26 raeburn 9354: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9355: }
9356: }
9357: } else {
9358: my $newvalue;
9359: if ($key eq 'run') {
9360: $newvalue = $offon[$env{'form.autoupdate_run'}];
9361: } else {
9362: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9363: }
1.1 raeburn 9364: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9365: }
9366: }
9367: $resulttext .= '</ul>';
9368: } else {
1.3 raeburn 9369: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9370: }
9371: } else {
1.11 albertel 9372: $resulttext = '<span class="LC_error">'.
9373: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9374: }
1.3 raeburn 9375: return $resulttext;
1.1 raeburn 9376: }
9377:
1.125 raeburn 9378: sub modify_autocreate {
9379: my ($dom,%domconfig) = @_;
9380: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9381: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9382: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9383: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9384: }
9385: }
9386: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9387: req => 'Auto-creation of validated requests for official courses',
9388: xmldc => 'Identity of course creator of courses from XML files',
9389: );
9390: my @types = ('xml','req');
9391: foreach my $item (@types) {
9392: $newvals{$item} = $env{'form.autocreate_'.$item};
9393: $newvals{$item} =~ s/\D//g;
9394: $newvals{$item} = 0 if ($newvals{$item} eq '');
9395: }
9396: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 9397: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 9398: unless (exists($domcoords{$newvals{'xmldc'}})) {
9399: $newvals{'xmldc'} = '';
9400: }
9401: %autocreatehash = (
9402: autocreate => { xml => $newvals{'xml'},
9403: req => $newvals{'req'},
9404: }
9405: );
9406: if ($newvals{'xmldc'} ne '') {
9407: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9408: }
9409: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9410: $dom);
9411: if ($putresult eq 'ok') {
9412: my @items = @types;
9413: if ($newvals{'xml'}) {
9414: push(@items,'xmldc');
9415: }
9416: foreach my $item (@items) {
9417: if (exists($currautocreate{$item})) {
9418: if ($currautocreate{$item} ne $newvals{$item}) {
9419: $changes{$item} = 1;
9420: }
9421: } elsif ($newvals{$item}) {
9422: $changes{$item} = 1;
9423: }
9424: }
9425: if (keys(%changes) > 0) {
9426: my @offon = ('off','on');
9427: $resulttext = &mt('Changes made:').'<ul>';
9428: foreach my $item (@types) {
9429: if ($changes{$item}) {
9430: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 9431: $resulttext .= '<li>'.
9432: &mt("$title{$item} set to [_1]$newtxt [_2]",
9433: '<b>','</b>').
9434: '</li>';
1.125 raeburn 9435: }
9436: }
9437: if ($changes{'xmldc'}) {
9438: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9439: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 9440: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9441: }
9442: $resulttext .= '</ul>';
9443: } else {
9444: $resulttext = &mt('No changes made to auto-creation settings');
9445: }
9446: } else {
9447: $resulttext = '<span class="LC_error">'.
9448: &mt('An error occurred: [_1]',$putresult).'</span>';
9449: }
9450: return $resulttext;
9451: }
9452:
1.23 raeburn 9453: sub modify_directorysrch {
1.160.6.81 raeburn 9454: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 9455: my ($resulttext,%changes);
9456: my %currdirsrch;
9457: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9458: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9459: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9460: }
9461: }
1.160.6.72 raeburn 9462: my %title = ( available => 'Institutional directory search available',
9463: localonly => 'Other domains can search institution',
9464: lcavailable => 'LON-CAPA directory search available',
9465: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9466: searchby => 'Search types',
9467: searchtypes => 'Search latitude');
9468: my @offon = ('off','on');
1.24 raeburn 9469: my @otherdoms = ('Yes','No');
1.23 raeburn 9470:
1.25 raeburn 9471: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9472: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9473: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9474:
1.44 raeburn 9475: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9476: if (keys(%{$usertypes}) == 0) {
9477: @cansearch = ('default');
9478: } else {
9479: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9480: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9481: if (!grep(/^\Q$type\E$/,@cansearch)) {
9482: push(@{$changes{'cansearch'}},$type);
9483: }
1.23 raeburn 9484: }
1.26 raeburn 9485: foreach my $type (@cansearch) {
9486: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9487: push(@{$changes{'cansearch'}},$type);
9488: }
1.23 raeburn 9489: }
1.26 raeburn 9490: } else {
9491: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9492: }
9493: }
9494:
9495: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9496: foreach my $by (@{$currdirsrch{'searchby'}}) {
9497: if (!grep(/^\Q$by\E$/,@searchby)) {
9498: push(@{$changes{'searchby'}},$by);
9499: }
9500: }
9501: foreach my $by (@searchby) {
9502: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9503: push(@{$changes{'searchby'}},$by);
9504: }
9505: }
9506: } else {
9507: push(@{$changes{'searchby'}},@searchby);
9508: }
1.25 raeburn 9509:
9510: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9511: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9512: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9513: push(@{$changes{'searchtypes'}},$type);
9514: }
9515: }
9516: foreach my $type (@searchtypes) {
9517: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9518: push(@{$changes{'searchtypes'}},$type);
9519: }
9520: }
9521: } else {
9522: if (exists($currdirsrch{'searchtypes'})) {
9523: foreach my $type (@searchtypes) {
9524: if ($type ne $currdirsrch{'searchtypes'}) {
9525: push(@{$changes{'searchtypes'}},$type);
9526: }
9527: }
9528: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9529: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9530: }
9531: } else {
9532: push(@{$changes{'searchtypes'}},@searchtypes);
9533: }
9534: }
9535:
1.23 raeburn 9536: my %dirsrch_hash = (
9537: directorysrch => { available => $env{'form.dirsrch_available'},
9538: cansearch => \@cansearch,
1.160.6.72 raeburn 9539: localonly => $env{'form.dirsrch_instlocalonly'},
9540: lclocalonly => $env{'form.dirsrch_domlocalonly'},
9541: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9542: searchby => \@searchby,
1.25 raeburn 9543: searchtypes => \@searchtypes,
1.23 raeburn 9544: }
9545: );
9546: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9547: $dom);
9548: if ($putresult eq 'ok') {
9549: if (exists($currdirsrch{'available'})) {
9550: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9551: $changes{'available'} = 1;
9552: }
9553: } else {
9554: if ($env{'form.dirsrch_available'} eq '1') {
9555: $changes{'available'} = 1;
9556: }
9557: }
1.160.6.72 raeburn 9558: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 9559: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
9560: $changes{'lcavailable'} = 1;
9561: }
1.24 raeburn 9562: } else {
1.160.6.72 raeburn 9563: if ($env{'form.dirsrch_lcavailable'} eq '1') {
9564: $changes{'lcavailable'} = 1;
9565: }
9566: }
9567: if (exists($currdirsrch{'localonly'})) {
9568: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9569: $changes{'localonly'} = 1;
9570: }
1.160.6.72 raeburn 9571: } else {
9572: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
9573: $changes{'localonly'} = 1;
9574: }
9575: }
9576: if (exists($currdirsrch{'lclocalonly'})) {
9577: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
9578: $changes{'lclocalonly'} = 1;
9579: }
9580: } else {
9581: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
9582: $changes{'lclocalonly'} = 1;
9583: }
1.24 raeburn 9584: }
1.23 raeburn 9585: if (keys(%changes) > 0) {
9586: $resulttext = &mt('Changes made:').'<ul>';
9587: if ($changes{'available'}) {
9588: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9589: }
1.160.6.72 raeburn 9590: if ($changes{'lcavailable'}) {
9591: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
9592: }
1.24 raeburn 9593: if ($changes{'localonly'}) {
1.160.6.72 raeburn 9594: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
9595: }
9596: if ($changes{'lclocalonly'}) {
9597: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 9598: }
1.23 raeburn 9599: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9600: my $chgtext;
1.26 raeburn 9601: if (ref($usertypes) eq 'HASH') {
9602: if (keys(%{$usertypes}) > 0) {
9603: foreach my $type (@{$types}) {
9604: if (grep(/^\Q$type\E$/,@cansearch)) {
9605: $chgtext .= $usertypes->{$type}.'; ';
9606: }
9607: }
9608: if (grep(/^default$/,@cansearch)) {
9609: $chgtext .= $othertitle;
9610: } else {
9611: $chgtext =~ s/\; $//;
9612: }
1.160.6.13 raeburn 9613: $resulttext .=
9614: '<li>'.
9615: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9616: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9617: '</li>';
1.23 raeburn 9618: }
9619: }
9620: }
9621: if (ref($changes{'searchby'}) eq 'ARRAY') {
9622: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9623: my $chgtext;
9624: foreach my $type (@{$titleorder}) {
9625: if (grep(/^\Q$type\E$/,@searchby)) {
9626: if (defined($searchtitles->{$type})) {
9627: $chgtext .= $searchtitles->{$type}.'; ';
9628: }
9629: }
9630: }
9631: $chgtext =~ s/\; $//;
9632: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9633: }
1.25 raeburn 9634: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9635: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9636: my $chgtext;
9637: foreach my $type (@{$srchtypeorder}) {
9638: if (grep(/^\Q$type\E$/,@searchtypes)) {
9639: if (defined($srchtypes_desc->{$type})) {
9640: $chgtext .= $srchtypes_desc->{$type}.'; ';
9641: }
9642: }
9643: }
9644: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 9645: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9646: }
9647: $resulttext .= '</ul>';
1.160.6.81 raeburn 9648: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
9649: if (ref($lastactref) eq 'HASH') {
9650: $lastactref->{'directorysrch'} = 1;
9651: }
1.23 raeburn 9652: } else {
1.160.6.72 raeburn 9653: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9654: }
9655: } else {
9656: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9657: &mt('An error occurred: [_1]',$putresult).'</span>';
9658: }
9659: return $resulttext;
9660: }
9661:
1.28 raeburn 9662: sub modify_contacts {
1.160.6.24 raeburn 9663: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9664: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9665: if (ref($domconfig{'contacts'}) eq 'HASH') {
9666: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9667: $currsetting{$key} = $domconfig{'contacts'}{$key};
9668: }
9669: }
1.160.6.78 raeburn 9670: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 9671: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 9672: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 9673: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.23 raeburn 9674: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 9675: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 9676: foreach my $type (@mailings) {
9677: @{$newsetting{$type}} =
9678: &Apache::loncommon::get_env_multiple('form.'.$type);
9679: foreach my $item (@contacts) {
9680: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9681: $contacts_hash{contacts}{$type}{$item} = 1;
9682: } else {
9683: $contacts_hash{contacts}{$type}{$item} = 0;
9684: }
1.160.6.78 raeburn 9685: }
1.28 raeburn 9686: $others{$type} = $env{'form.'.$type.'_others'};
9687: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 9688: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9689: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9690: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 9691: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
9692: $includestr{$type} = $env{'form.'.$type.'_includestr'};
9693: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
9694: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
9695: }
1.134 raeburn 9696: }
1.28 raeburn 9697: }
9698: foreach my $item (@contacts) {
9699: $to{$item} = $env{'form.'.$item};
9700: $contacts_hash{'contacts'}{$item} = $to{$item};
9701: }
1.160.6.23 raeburn 9702: foreach my $item (@toggles) {
9703: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9704: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9705: }
9706: }
1.160.6.78 raeburn 9707: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
9708: foreach my $field (@{$fields}) {
9709: if (ref($possoptions->{$field}) eq 'ARRAY') {
9710: my $value = $env{'form.helpform_'.$field};
9711: $value =~ s/^\s+|\s+$//g;
9712: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
9713: $contacts_hash{contacts}{'helpform'}{$field} = $value;
9714: if ($field eq 'screenshot') {
9715: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
9716: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
9717: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
9718: }
9719: }
9720: }
9721: }
9722: }
9723: }
1.28 raeburn 9724: if (keys(%currsetting) > 0) {
9725: foreach my $item (@contacts) {
9726: if ($to{$item} ne $currsetting{$item}) {
9727: $changes{$item} = 1;
9728: }
9729: }
9730: foreach my $type (@mailings) {
9731: foreach my $item (@contacts) {
9732: if (ref($currsetting{$type}) eq 'HASH') {
9733: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9734: push(@{$changes{$type}},$item);
9735: }
9736: } else {
9737: push(@{$changes{$type}},@{$newsetting{$type}});
9738: }
9739: }
9740: if ($others{$type} ne $currsetting{$type}{'others'}) {
9741: push(@{$changes{$type}},'others');
9742: }
1.160.6.78 raeburn 9743: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9744: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9745: push(@{$changes{$type}},'bcc');
9746: }
1.160.6.78 raeburn 9747: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
9748: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
9749: push(@{$changes{$type}},'include');
9750: }
9751: }
9752: }
9753: if (ref($fields) eq 'ARRAY') {
9754: if (ref($currsetting{'helpform'}) eq 'HASH') {
9755: foreach my $field (@{$fields}) {
9756: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
9757: push(@{$changes{'helpform'}},$field);
9758: }
9759: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9760: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
9761: push(@{$changes{'helpform'}},'maxsize');
9762: }
9763: }
9764: }
9765: } else {
9766: foreach my $field (@{$fields}) {
9767: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9768: push(@{$changes{'helpform'}},$field);
9769: }
9770: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9771: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9772: push(@{$changes{'helpform'}},'maxsize');
9773: }
9774: }
9775: }
1.134 raeburn 9776: }
1.28 raeburn 9777: }
9778: } else {
9779: my %default;
9780: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9781: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9782: $default{'errormail'} = 'adminemail';
9783: $default{'packagesmail'} = 'adminemail';
9784: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 9785: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 9786: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9787: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 9788: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 9789: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 9790: foreach my $item (@contacts) {
9791: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 9792: $changes{$item} = 1;
1.160.6.23 raeburn 9793: }
1.28 raeburn 9794: }
9795: foreach my $type (@mailings) {
9796: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9797: push(@{$changes{$type}},@{$newsetting{$type}});
9798: }
9799: if ($others{$type} ne '') {
9800: push(@{$changes{$type}},'others');
1.134 raeburn 9801: }
1.160.6.78 raeburn 9802: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9803: if ($bcc{$type} ne '') {
9804: push(@{$changes{$type}},'bcc');
9805: }
1.160.6.78 raeburn 9806: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
9807: push(@{$changes{$type}},'include');
9808: }
9809: }
9810: }
9811: if (ref($fields) eq 'ARRAY') {
9812: foreach my $field (@{$fields}) {
9813: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9814: push(@{$changes{'helpform'}},$field);
9815: }
9816: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9817: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9818: push(@{$changes{'helpform'}},'maxsize');
9819: }
9820: }
1.134 raeburn 9821: }
1.28 raeburn 9822: }
9823: }
1.160.6.23 raeburn 9824: foreach my $item (@toggles) {
9825: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9826: $changes{$item} = 1;
9827: } elsif ((!$env{'form.'.$item}) &&
9828: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9829: $changes{$item} = 1;
9830: }
9831: }
1.28 raeburn 9832: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9833: $dom);
9834: if ($putresult eq 'ok') {
9835: if (keys(%changes) > 0) {
1.160.6.24 raeburn 9836: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9837: if (ref($lastactref) eq 'HASH') {
9838: $lastactref->{'domainconfig'} = 1;
9839: }
1.28 raeburn 9840: my ($titles,$short_titles) = &contact_titles();
9841: $resulttext = &mt('Changes made:').'<ul>';
9842: foreach my $item (@contacts) {
9843: if ($changes{$item}) {
9844: $resulttext .= '<li>'.$titles->{$item}.
9845: &mt(' set to: ').
9846: '<span class="LC_cusr_emph">'.
9847: $to{$item}.'</span></li>';
9848: }
9849: }
9850: foreach my $type (@mailings) {
9851: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 9852: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
9853: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
9854: } else {
9855: $resulttext .= '<li>'.$titles->{$type}.': ';
9856: }
1.28 raeburn 9857: my @text;
9858: foreach my $item (@{$newsetting{$type}}) {
9859: push(@text,$short_titles->{$item});
9860: }
9861: if ($others{$type} ne '') {
9862: push(@text,$others{$type});
9863: }
1.160.6.78 raeburn 9864: if (@text) {
9865: $resulttext .= '<span class="LC_cusr_emph">'.
9866: join(', ',@text).'</span>';
9867: }
9868: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9869: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 9870: my $bcctext;
9871: if (@text) {
9872: $bcctext = ' '.&mt('with Bcc to');
9873: } else {
9874: $bcctext = '(Bcc)';
9875: }
9876: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9877: } elsif (!@text) {
9878: $resulttext .= &mt('No one');
1.134 raeburn 9879: }
1.160.6.78 raeburn 9880: if ($includestr{$type} ne '') {
9881: if ($includeloc{$type} eq 'b') {
9882: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
9883: } elsif ($includeloc{$type} eq 's') {
9884: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
9885: }
9886: }
9887: } elsif (!@text) {
9888: $resulttext .= &mt('No recipients');
1.134 raeburn 9889: }
9890: $resulttext .= '</li>';
1.28 raeburn 9891: }
9892: }
1.160.6.23 raeburn 9893: my @offon = ('off','on');
9894: if ($changes{'reporterrors'}) {
9895: $resulttext .= '<li>'.
9896: &mt('E-mail error reports to [_1] set to "'.
9897: $offon[$env{'form.reporterrors'}].'".',
9898: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9899: &mt('LON-CAPA core group - MSU'),600,500)).
9900: '</li>';
9901: }
9902: if ($changes{'reportupdates'}) {
9903: $resulttext .= '<li>'.
9904: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9905: $offon[$env{'form.reportupdates'}].'".',
9906: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9907: &mt('LON-CAPA core group - MSU'),600,500)).
9908: '</li>';
9909: }
1.160.6.78 raeburn 9910: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
9911: my (@optional,@required,@unused,$maxsizechg);
9912: foreach my $field (@{$changes{'helpform'}}) {
9913: if ($field eq 'maxsize') {
9914: $maxsizechg = 1;
9915: next;
9916: }
9917: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
9918: push(@optional,$field);
9919: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
9920: push(@unused,$field);
9921: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
9922: push(@required,$field);
9923: }
9924: }
9925: if (@optional) {
9926: $resulttext .= '<li>'.
9927: &mt('Help form fields changed to "Optional": [_1].',
9928: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
9929: '</li>';
9930: }
9931: if (@required) {
9932: $resulttext .= '<li>'.
9933: &mt('Help form fields changed to "Required": [_1].',
9934: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
9935: '</li>';
9936: }
9937: if (@unused) {
9938: $resulttext .= '<li>'.
9939: &mt('Help form fields changed to "Not shown": [_1].',
9940: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
9941: '</li>';
9942: }
9943: if ($maxsizechg) {
9944: $resulttext .= '<li>'.
9945: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
9946: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
9947: '</li>';
9948:
9949: }
9950: }
1.28 raeburn 9951: $resulttext .= '</ul>';
9952: } else {
1.160.6.78 raeburn 9953: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 9954: }
9955: } else {
9956: $resulttext = '<span class="LC_error">'.
9957: &mt('An error occurred: [_1].',$putresult).'</span>';
9958: }
9959: return $resulttext;
9960: }
9961:
9962: sub modify_usercreation {
1.27 raeburn 9963: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9964: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9965: my $warningmsg;
1.27 raeburn 9966: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9967: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 9968: if ($key eq 'cancreate') {
9969: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9970: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 9971: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 9972: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 9973: } else {
9974: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 9975: }
1.50 raeburn 9976: }
1.43 raeburn 9977: }
1.160.6.34 raeburn 9978: } elsif ($key eq 'email_rule') {
9979: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9980: } else {
9981: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 9982: }
9983: }
1.34 raeburn 9984: }
1.160.6.34 raeburn 9985: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
9986: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
9987: my @contexts = ('author','course','requestcrs');
9988: foreach my $item(@contexts) {
9989: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9990: }
1.34 raeburn 9991: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9992: foreach my $item (@contexts) {
1.160.6.34 raeburn 9993: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9994: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9995: }
1.27 raeburn 9996: }
1.34 raeburn 9997: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9998: foreach my $item (@contexts) {
1.43 raeburn 9999: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 10000: if ($cancreate{$item} ne 'any') {
10001: push(@{$changes{'cancreate'}},$item);
10002: }
10003: } else {
10004: if ($cancreate{$item} ne 'none') {
10005: push(@{$changes{'cancreate'}},$item);
10006: }
1.27 raeburn 10007: }
10008: }
10009: } else {
1.43 raeburn 10010: foreach my $item (@contexts) {
1.34 raeburn 10011: push(@{$changes{'cancreate'}},$item);
10012: }
1.27 raeburn 10013: }
1.34 raeburn 10014:
1.27 raeburn 10015: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
10016: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
10017: if (!grep(/^\Q$type\E$/,@username_rule)) {
10018: push(@{$changes{'username_rule'}},$type);
10019: }
10020: }
10021: foreach my $type (@username_rule) {
10022: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
10023: push(@{$changes{'username_rule'}},$type);
10024: }
10025: }
10026: } else {
10027: push(@{$changes{'username_rule'}},@username_rule);
10028: }
10029:
1.32 raeburn 10030: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
10031: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
10032: if (!grep(/^\Q$type\E$/,@id_rule)) {
10033: push(@{$changes{'id_rule'}},$type);
10034: }
10035: }
10036: foreach my $type (@id_rule) {
10037: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
10038: push(@{$changes{'id_rule'}},$type);
10039: }
10040: }
10041: } else {
10042: push(@{$changes{'id_rule'}},@id_rule);
10043: }
10044:
1.43 raeburn 10045: my @authen_contexts = ('author','course','domain');
1.28 raeburn 10046: my @authtypes = ('int','krb4','krb5','loc');
10047: my %authhash;
1.43 raeburn 10048: foreach my $item (@authen_contexts) {
1.28 raeburn 10049: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
10050: foreach my $auth (@authtypes) {
10051: if (grep(/^\Q$auth\E$/,@authallowed)) {
10052: $authhash{$item}{$auth} = 1;
10053: } else {
10054: $authhash{$item}{$auth} = 0;
10055: }
10056: }
10057: }
10058: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 10059: foreach my $item (@authen_contexts) {
1.28 raeburn 10060: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10061: foreach my $auth (@authtypes) {
10062: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10063: push(@{$changes{'authtypes'}},$item);
10064: last;
10065: }
10066: }
10067: }
10068: }
10069: } else {
1.43 raeburn 10070: foreach my $item (@authen_contexts) {
1.28 raeburn 10071: push(@{$changes{'authtypes'}},$item);
10072: }
10073: }
10074:
1.160.6.34 raeburn 10075: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10076: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10077: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10078: $save_usercreate{'id_rule'} = \@id_rule;
10079: $save_usercreate{'username_rule'} = \@username_rule,
10080: $save_usercreate{'authtypes'} = \%authhash;
10081:
1.27 raeburn 10082: my %usercreation_hash = (
1.160.6.34 raeburn 10083: usercreation => \%save_usercreate,
10084: );
1.27 raeburn 10085:
10086: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10087: $dom);
1.50 raeburn 10088:
1.160.6.34 raeburn 10089: if ($putresult eq 'ok') {
10090: if (keys(%changes) > 0) {
10091: $resulttext = &mt('Changes made:').'<ul>';
10092: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10093: my %lt = &usercreation_types();
10094: foreach my $type (@{$changes{'cancreate'}}) {
10095: my $chgtext = $lt{$type}.', ';
10096: if ($cancreate{$type} eq 'none') {
10097: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10098: } elsif ($cancreate{$type} eq 'any') {
10099: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10100: } elsif ($cancreate{$type} eq 'official') {
10101: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10102: } elsif ($cancreate{$type} eq 'unofficial') {
10103: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10104: }
10105: $resulttext .= '<li>'.$chgtext.'</li>';
10106: }
10107: }
10108: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10109: my ($rules,$ruleorder) =
10110: &Apache::lonnet::inst_userrules($dom,'username');
10111: my $chgtext = '<ul>';
10112: foreach my $type (@username_rule) {
10113: if (ref($rules->{$type}) eq 'HASH') {
10114: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10115: }
10116: }
10117: $chgtext .= '</ul>';
10118: if (@username_rule > 0) {
10119: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10120: } else {
10121: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
10122: }
10123: }
10124: if (ref($changes{'id_rule'}) eq 'ARRAY') {
10125: my ($idrules,$idruleorder) =
10126: &Apache::lonnet::inst_userrules($dom,'id');
10127: my $chgtext = '<ul>';
10128: foreach my $type (@id_rule) {
10129: if (ref($idrules->{$type}) eq 'HASH') {
10130: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
10131: }
10132: }
10133: $chgtext .= '</ul>';
10134: if (@id_rule > 0) {
10135: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10136: } else {
10137: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
10138: }
10139: }
10140: my %authname = &authtype_names();
10141: my %context_title = &context_names();
10142: if (ref($changes{'authtypes'}) eq 'ARRAY') {
10143: my $chgtext = '<ul>';
10144: foreach my $type (@{$changes{'authtypes'}}) {
10145: my @allowed;
10146: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
10147: foreach my $auth (@authtypes) {
10148: if ($authhash{$type}{$auth}) {
10149: push(@allowed,$authname{$auth});
10150: }
10151: }
10152: if (@allowed > 0) {
10153: $chgtext .= join(', ',@allowed).'</li>';
10154: } else {
10155: $chgtext .= &mt('none').'</li>';
10156: }
10157: }
10158: $chgtext .= '</ul>';
10159: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10160: $resulttext .= '</li>';
10161: }
10162: $resulttext .= '</ul>';
10163: } else {
10164: $resulttext = &mt('No changes made to user creation settings');
10165: }
10166: } else {
10167: $resulttext = '<span class="LC_error">'.
10168: &mt('An error occurred: [_1]',$putresult).'</span>';
10169: }
10170: if ($warningmsg ne '') {
10171: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10172: }
10173: return $resulttext;
10174: }
10175:
10176: sub modify_selfcreation {
1.160.6.93 raeburn 10177: my ($dom,$lastactref,%domconfig) = @_;
10178: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
10179: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
10180: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10181: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
10182: if (ref($typesref) eq 'ARRAY') {
10183: @types = @{$typesref};
10184: }
10185: if (ref($usertypesref) eq 'HASH') {
10186: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 10187: }
1.160.6.93 raeburn 10188: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 10189: #
10190: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10191: #
10192: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10193: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10194: if ($key eq 'cancreate') {
10195: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10196: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10197: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 10198: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10199: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
10200: ($item eq 'emailusername') || ($item eq 'shibenv') ||
10201: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
10202: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 10203: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10204: } else {
10205: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10206: }
10207: }
10208: }
10209: } elsif ($key eq 'email_rule') {
10210: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10211: } else {
10212: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10213: }
10214: }
10215: }
10216: #
10217: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10218: #
10219: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10220: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10221: if ($key eq 'selfcreate') {
10222: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10223: } else {
10224: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10225: }
10226: }
10227: }
1.160.6.93 raeburn 10228: #
10229: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
10230: #
10231: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10232: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
10233: if ($key eq 'inststatusguest') {
10234: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
10235: } else {
10236: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
10237: }
10238: }
10239: }
1.160.6.34 raeburn 10240:
10241: my @contexts = ('selfcreate');
10242: @{$cancreate{'selfcreate'}} = ();
10243: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 10244: if (@types) {
10245: @{$cancreate{'statustocreate'}} = ();
10246: }
1.160.6.40 raeburn 10247: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 10248: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 10249: %{$cancreate{'emailverified'}} = ();
10250: %{$cancreate{'emailoptions'}} = ();
10251: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 10252: my %selfcreatetypes = (
10253: sso => 'users authenticated by institutional single sign on',
10254: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 10255: email => 'users verified by e-mail',
1.50 raeburn 10256: );
1.160.6.34 raeburn 10257: #
10258: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10259: # is permitted.
10260: #
1.160.6.40 raeburn 10261:
1.160.6.93 raeburn 10262: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 10263:
1.160.6.93 raeburn 10264: my (@statuses,%email_rule);
1.160.6.35 raeburn 10265: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 10266: if ($item eq 'email') {
1.160.6.40 raeburn 10267: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 10268: if (@types) {
10269: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
10270: foreach my $status (@poss_statuses) {
10271: if (grep(/^\Q$status\E$/,(@types,'default'))) {
10272: push(@statuses,$status);
10273: }
10274: }
10275: $save_inststatus{'inststatusguest'} = \@statuses;
10276: } else {
10277: push(@statuses,'default');
10278: }
10279: if (@statuses) {
10280: my %curr_rule;
10281: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
10282: foreach my $type (@statuses) {
10283: $curr_rule{$type} = $curr_usercreation{'email_rule'};
10284: }
10285: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
10286: foreach my $type (@statuses) {
10287: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
10288: }
10289: }
10290: push(@{$cancreate{'selfcreate'}},'email');
10291: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
10292: my %curremaildom;
10293: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
10294: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
10295: }
10296: foreach my $type (@statuses) {
10297: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
10298: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10299: }
10300: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
10301: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
10302: }
10303: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
10304: #
10305: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
10306: #
10307: my $chosen = $1;
10308: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
10309: my $emaildom;
10310: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
10311: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
10312: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
10313: if (ref($curremaildom{$type}) eq 'HASH') {
10314: if (exists($curremaildom{$type}{$chosen})) {
10315: if ($curremaildom{$type}{$chosen} ne $emaildom) {
10316: push(@{$changes{'cancreate'}},'emaildomain');
10317: }
10318: } elsif ($emaildom ne '') {
10319: push(@{$changes{'cancreate'}},'emaildomain');
10320: }
10321: } elsif ($emaildom ne '') {
10322: push(@{$changes{'cancreate'}},'emaildomain');
10323: }
10324: }
10325: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
10326: } elsif ($chosen eq 'custom') {
10327: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
10328: $email_rule{$type} = [];
10329: if (ref($emailrules) eq 'HASH') {
10330: foreach my $rule (@possemail_rules) {
10331: if (exists($emailrules->{$rule})) {
10332: push(@{$email_rule{$type}},$rule);
10333: }
10334: }
10335: }
10336: if (@{$email_rule{$type}}) {
10337: $cancreate{'emailoptions'}{$type} = 'custom';
10338: if (ref($curr_rule{$type}) eq 'ARRAY') {
10339: if (@{$curr_rule{$type}} > 0) {
10340: foreach my $rule (@{$curr_rule{$type}}) {
10341: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
10342: push(@{$changes{'email_rule'}},$type);
10343: }
10344: }
10345: }
10346: foreach my $type (@{$email_rule{$type}}) {
10347: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
10348: push(@{$changes{'email_rule'}},$type);
10349: }
10350: }
10351: } else {
10352: push(@{$changes{'email_rule'}},$type);
10353: }
10354: }
10355: } else {
10356: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
10357: }
10358: }
10359: }
10360: if (@types) {
10361: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
10362: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
10363: if (@changed) {
10364: push(@{$changes{'inststatus'}},'inststatusguest');
10365: }
10366: } else {
10367: push(@{$changes{'inststatus'}},'inststatusguest');
10368: }
10369: }
10370: } else {
10371: delete($env{'form.cancreate_email'});
10372: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
10373: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
10374: push(@{$changes{'inststatus'}},'inststatusguest');
10375: }
10376: }
10377: }
10378: } else {
10379: $save_inststatus{'inststatusguest'} = [];
10380: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
10381: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
10382: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 10383: }
10384: }
1.160.6.34 raeburn 10385: }
10386: } else {
10387: if ($env{'form.cancreate_'.$item}) {
10388: push(@{$cancreate{'selfcreate'}},$item);
10389: }
10390: }
10391: }
1.160.6.93 raeburn 10392: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 10393: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
10394: #
1.160.6.35 raeburn 10395: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
10396: # 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 10397: #
1.160.6.40 raeburn 10398:
1.160.6.48 raeburn 10399: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 10400: push(@contexts,'emailusername');
1.160.6.93 raeburn 10401: if (@statuses) {
10402: foreach my $type (@statuses) {
1.160.6.35 raeburn 10403: if (ref($infofields) eq 'ARRAY') {
10404: foreach my $field (@{$infofields}) {
10405: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
10406: $cancreate{'emailusername'}{$type}{$field} = $1;
10407: }
10408: }
1.160.6.34 raeburn 10409: }
10410: }
10411: }
10412: #
10413: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 10414: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 10415: #
10416:
10417: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
10418: @approvalnotify = sort(@approvalnotify);
10419: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
10420: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10421: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
10422: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
10423: push(@{$changes{'cancreate'}},'notify');
10424: }
10425: } else {
10426: if ($cancreate{'notify'}{'approval'}) {
10427: push(@{$changes{'cancreate'}},'notify');
10428: }
10429: }
10430: } elsif ($cancreate{'notify'}{'approval'}) {
10431: push(@{$changes{'cancreate'}},'notify');
10432: }
10433:
10434: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
10435: }
10436: #
1.160.6.40 raeburn 10437: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 10438: # institutional log-in.
10439: #
10440: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
10441: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
10442: ($domdefaults{'auth_def'} eq 'localauth'))) {
10443: $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.').' '.
10444: &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.');
10445: }
10446: }
10447: my @fields = ('lastname','firstname','middlename','generation',
10448: 'permanentemail','id');
1.160.6.44 raeburn 10449: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 10450: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10451: #
10452: # Where usernames may created for institutional log-in and/or institutional single sign on:
10453: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
10454: # may self-create accounts
10455: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
10456: # which the user may supply, if institutional data is unavailable.
10457: #
10458: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 10459: if (@types) {
10460: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
10461: push(@contexts,'statustocreate');
10462: foreach my $type (@types) {
1.160.6.34 raeburn 10463: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
10464: foreach my $field (@fields) {
10465: if (grep(/^\Q$field\E$/,@modifiable)) {
10466: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
10467: } else {
10468: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
10469: }
10470: }
10471: }
10472: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 10473: foreach my $type (@types) {
1.160.6.34 raeburn 10474: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
10475: foreach my $field (@fields) {
10476: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
10477: $curr_usermodify{'selfcreate'}{$type}{$field}) {
10478: push(@{$changes{'selfcreate'}},$type);
10479: last;
10480: }
10481: }
10482: }
10483: }
10484: } else {
1.160.6.93 raeburn 10485: foreach my $type (@types) {
1.160.6.34 raeburn 10486: push(@{$changes{'selfcreate'}},$type);
10487: }
10488: }
10489: }
1.160.6.44 raeburn 10490: foreach my $field (@shibfields) {
10491: if ($env{'form.shibenv_'.$field} ne '') {
10492: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10493: }
10494: }
10495: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10496: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10497: foreach my $field (@shibfields) {
10498: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10499: push(@{$changes{'cancreate'}},'shibenv');
10500: }
10501: }
10502: } else {
10503: foreach my $field (@shibfields) {
10504: if ($env{'form.shibenv_'.$field}) {
10505: push(@{$changes{'cancreate'}},'shibenv');
10506: last;
10507: }
10508: }
10509: }
10510: }
1.160.6.34 raeburn 10511: }
10512: foreach my $item (@contexts) {
10513: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10514: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10515: if (ref($cancreate{$item}) eq 'ARRAY') {
10516: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10517: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10518: push(@{$changes{'cancreate'}},$item);
10519: }
10520: }
10521: }
10522: }
10523: if (ref($cancreate{$item}) eq 'ARRAY') {
10524: foreach my $type (@{$cancreate{$item}}) {
10525: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10526: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10527: push(@{$changes{'cancreate'}},$item);
10528: }
10529: }
10530: }
10531: }
10532: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10533: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 10534: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
10535: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
10536: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
10537: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 10538: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10539: push(@{$changes{'cancreate'}},$item);
10540: }
10541: }
10542: }
1.160.6.93 raeburn 10543: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
10544: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 10545: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10546: push(@{$changes{'cancreate'}},$item);
10547: }
1.160.6.34 raeburn 10548: }
10549: }
10550: }
1.160.6.93 raeburn 10551: foreach my $type (keys(%{$cancreate{$item}})) {
10552: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10553: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10554: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
10555: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 10556: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10557: push(@{$changes{'cancreate'}},$item);
10558: }
10559: }
10560: } else {
10561: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10562: push(@{$changes{'cancreate'}},$item);
10563: }
10564: }
10565: }
1.160.6.93 raeburn 10566: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
10567: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 10568: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10569: push(@{$changes{'cancreate'}},$item);
10570: }
1.160.6.34 raeburn 10571: }
10572: }
10573: }
10574: }
10575: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10576: if (ref($cancreate{$item}) eq 'ARRAY') {
10577: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10578: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10579: push(@{$changes{'cancreate'}},$item);
10580: }
10581: }
1.160.6.93 raeburn 10582: }
10583: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
10584: if (ref($cancreate{$item}) eq 'HASH') {
10585: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10586: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 10587: }
10588: }
10589: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 10590: if (ref($cancreate{$item}) eq 'HASH') {
10591: foreach my $type (keys(%{$cancreate{$item}})) {
10592: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10593: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10594: if ($cancreate{$item}{$type}{$field}) {
10595: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10596: push(@{$changes{'cancreate'}},$item);
10597: }
10598: last;
10599: }
10600: }
10601: }
10602: }
1.160.6.34 raeburn 10603: }
10604: }
10605: }
10606: #
10607: # Populate %save_usercreate hash with updates to self-creation configuration.
10608: #
10609: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10610: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 10611: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 10612: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10613: if (ref($cancreate{'notify'}) eq 'HASH') {
10614: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10615: }
1.160.6.40 raeburn 10616: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10617: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10618: }
1.160.6.93 raeburn 10619: if (ref($cancreate{'emailverified'}) eq 'HASH') {
10620: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
10621: }
10622: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
10623: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
10624: }
10625: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
10626: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
10627: }
1.160.6.34 raeburn 10628: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10629: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10630: }
1.160.6.44 raeburn 10631: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10632: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10633: }
1.160.6.34 raeburn 10634: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 10635: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 10636:
10637: my %userconfig_hash = (
10638: usercreation => \%save_usercreate,
10639: usermodification => \%save_usermodify,
1.160.6.93 raeburn 10640: inststatus => \%save_inststatus,
1.160.6.34 raeburn 10641: );
1.160.6.93 raeburn 10642:
1.160.6.34 raeburn 10643: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10644: $dom);
10645: #
1.160.6.93 raeburn 10646: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 10647: #
1.27 raeburn 10648: if ($putresult eq 'ok') {
10649: if (keys(%changes) > 0) {
10650: $resulttext = &mt('Changes made:').'<ul>';
10651: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 10652: my %lt = &selfcreation_types();
1.34 raeburn 10653: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 10654: my $chgtext = '';
1.45 raeburn 10655: if ($type eq 'selfcreate') {
1.50 raeburn 10656: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 10657: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10658: } else {
1.160.6.34 raeburn 10659: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10660: '<ul>';
1.50 raeburn 10661: foreach my $case (@{$cancreate{$type}}) {
10662: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10663: }
10664: $chgtext .= '</ul>';
1.100 raeburn 10665: if (ref($cancreate{$type}) eq 'ARRAY') {
10666: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10667: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10668: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 10669: $chgtext .= '<span class="LC_warning">'.
10670: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
10671: '</span><br />';
1.100 raeburn 10672: }
10673: }
10674: }
1.160.6.93 raeburn 10675: if (grep(/^email$/,@{$cancreate{$type}})) {
10676: if (!@statuses) {
10677: $chgtext .= '<span class="LC_warning">'.
10678: &mt("However, e-mail verification is currently set to 'unavailable' for all user types (including 'other'), so self-creation of accounts is not possible for non-institutional log-in.").
10679: '</span><br />';
10680:
10681: }
10682: }
1.100 raeburn 10683: }
1.43 raeburn 10684: }
1.160.6.44 raeburn 10685: } elsif ($type eq 'shibenv') {
10686: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 10687: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 10688: } else {
10689: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10690: '<ul>';
10691: foreach my $field (@shibfields) {
10692: next if ($cancreate{$type}{$field} eq '');
10693: if ($field eq 'inststatus') {
10694: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10695: } else {
10696: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10697: }
10698: }
10699: $chgtext .= '</ul>';
1.160.6.93 raeburn 10700: }
1.93 raeburn 10701: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10702: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10703: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10704: if (@{$cancreate{'selfcreate'}} > 0) {
10705: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10706: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10707: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10708: $chgtext .= '<br />'.
10709: '<span class="LC_warning">'.
10710: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10711: '</span>';
10712: }
1.160.6.93 raeburn 10713: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 10714: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10715: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10716: } else {
10717: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10718: }
10719: $chgtext .= '<ul>';
10720: foreach my $case (@{$cancreate{$type}}) {
10721: if ($case eq 'default') {
10722: $chgtext .= '<li>'.$othertitle.'</li>';
10723: } else {
1.160.6.93 raeburn 10724: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 10725: }
10726: }
1.100 raeburn 10727: $chgtext .= '</ul>';
10728: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 10729: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 10730: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10731: '</span>';
1.100 raeburn 10732: }
10733: }
10734: } else {
10735: if (@{$cancreate{$type}} == 0) {
10736: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10737: } else {
10738: $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 10739: }
10740: }
1.160.6.93 raeburn 10741: $chgtext .= '<br />';
1.93 raeburn 10742: }
1.160.6.40 raeburn 10743: } elsif ($type eq 'selfcreateprocessing') {
10744: my %choices = &Apache::lonlocal::texthash (
10745: automatic => 'Automatic approval',
10746: approval => 'Queued for approval',
10747: );
1.160.6.93 raeburn 10748: if (@types) {
10749: if (@statuses) {
10750: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
10751: '<ul>';
10752: foreach my $status (@statuses) {
10753: if ($status eq 'default') {
10754: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
10755: } else {
10756: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
10757: }
10758: }
10759: $chgtext .= '</ul>';
10760: }
10761: } else {
10762: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
10763: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10764: }
10765: } elsif ($type eq 'emailverified') {
10766: my %options = &Apache::lonlocal::texthash (
10767: all => 'Same as e-mail',
10768: first => 'Omit @domain',
10769: free => 'Free to choose',
10770: );
10771: if (@types) {
10772: if (@statuses) {
10773: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
10774: '<ul>';
10775: foreach my $status (@statuses) {
10776: if ($status eq 'default') {
10777: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
10778: } else {
10779: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
10780: }
10781: }
10782: $chgtext .= '</ul>';
10783: }
1.160.6.40 raeburn 10784: } else {
1.160.6.93 raeburn 10785: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
10786: $options{$cancreate{'emailverified'}{'default'}});
10787: }
10788: } elsif ($type eq 'emailoptions') {
10789: my %options = &Apache::lonlocal::texthash (
10790: any => 'Any e-mail',
10791: inst => 'Institutional only',
10792: noninst => 'Non-institutional only',
10793: custom => 'Custom restrictions',
10794: );
10795: if (@types) {
10796: if (@statuses) {
10797: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
10798: '<ul>';
10799: foreach my $status (@statuses) {
10800: if ($type eq 'default') {
10801: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
10802: } else {
10803: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
10804: }
10805: }
10806: $chgtext .= '</ul>';
10807: }
10808: } else {
10809: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
10810: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
10811: } else {
10812: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
10813: $options{$cancreate{'emailoptions'}{'default'}});
10814: }
10815: }
10816: } elsif ($type eq 'emaildomain') {
10817: my $output;
10818: if (@statuses) {
10819: foreach my $type (@statuses) {
10820: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
10821: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
10822: if ($type eq 'default') {
10823: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
10824: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
10825: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
10826: } else {
10827: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
10828: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
10829: }
10830: } else {
10831: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
10832: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
10833: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
10834: } else {
10835: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
10836: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
10837: }
10838: }
10839: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
10840: if ($type eq 'default') {
10841: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
10842: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
10843: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
10844: } else {
10845: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
10846: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
10847: }
10848: } else {
10849: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
10850: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
10851: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
10852: } else {
10853: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
10854: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
10855: }
10856: }
10857: }
10858: }
10859: }
10860: }
10861: if ($output ne '') {
10862: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
10863: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 10864: }
1.160.6.5 raeburn 10865: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 10866: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 10867: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10868: } else {
10869: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 10870: if ($captchas{$savecaptcha{$type}}) {
10871: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 10872: } else {
10873: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
10874: }
10875: }
10876: } elsif ($type eq 'recaptchakeys') {
10877: my ($privkey,$pubkey);
1.160.6.34 raeburn 10878: if (ref($savecaptcha{$type}) eq 'HASH') {
10879: $pubkey = $savecaptcha{$type}{'public'};
10880: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 10881: }
10882: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10883: if (!$pubkey) {
10884: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10885: } else {
10886: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10887: }
10888: if (!$privkey) {
10889: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10890: } else {
10891: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10892: }
10893: $chgtext .= '</ul>';
1.160.6.69 raeburn 10894: } elsif ($type eq 'recaptchaversion') {
10895: if ($savecaptcha{'captcha'} eq 'recaptcha') {
10896: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
10897: }
1.160.6.34 raeburn 10898: } elsif ($type eq 'emailusername') {
10899: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 10900: if (@statuses) {
10901: foreach my $type (@statuses) {
1.160.6.35 raeburn 10902: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10903: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 10904: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.160.6.35 raeburn 10905: '<ul>';
10906: foreach my $field (@{$infofields}) {
10907: if ($cancreate{'emailusername'}{$type}{$field}) {
10908: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10909: }
10910: }
1.160.6.50 raeburn 10911: $chgtext .= '</ul>';
10912: } else {
1.160.6.93 raeburn 10913: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.160.6.35 raeburn 10914: }
10915: } else {
1.160.6.93 raeburn 10916: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.160.6.34 raeburn 10917: }
10918: }
10919: }
10920: }
10921: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 10922: my $numapprove = 0;
1.160.6.34 raeburn 10923: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10924: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10925: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 10926: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10927: $numapprove ++;
1.160.6.34 raeburn 10928: }
10929: }
1.43 raeburn 10930: }
1.160.6.93 raeburn 10931: unless ($numapprove) {
10932: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10933: }
1.34 raeburn 10934: }
1.160.6.34 raeburn 10935: if ($chgtext) {
10936: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10937: }
10938: }
10939: }
1.160.6.93 raeburn 10940: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 10941: my ($emailrules,$emailruleorder) =
10942: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 10943: foreach my $type (@{$changes{'email_rule'}}) {
10944: if (ref($email_rule{$type}) eq 'ARRAY') {
10945: my $chgtext = '<ul>';
10946: foreach my $rule (@{$email_rule{$type}}) {
10947: if (ref($emailrules->{$rule}) eq 'HASH') {
10948: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
10949: }
10950: }
10951: $chgtext .= '</ul>';
10952: my $typename;
10953: if (@types) {
10954: if ($type eq 'default') {
10955: $typename = $othertitle;
10956: } else {
10957: $typename = $usertypes{$type};
10958: }
10959: $chgtext .= &mt('(Affiliation: [_1])',$typename);
10960: }
10961: if (@{$email_rule{$type}} > 0) {
10962: $resulttext .= '<li>'.
10963: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
10964: $usertypes{$type}).
10965: $chgtext.
10966: '</li>';
10967: } else {
10968: $resulttext .= '<li>'.
10969: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
10970: '</li>'.
10971: &mt('(Affiliation: [_1])',$typename);
10972: }
1.43 raeburn 10973: }
10974: }
1.160.6.93 raeburn 10975: }
10976: if (ref($changes{'inststatus'}) eq 'ARRAY') {
10977: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
10978: if (@{$save_inststatus{'inststatusguest'}} > 0) {
10979: my $chgtext = '<ul>';
10980: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
10981: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
10982: }
10983: $chgtext .= '</ul>';
10984: $resulttext .= '<li>'.
10985: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
10986: $chgtext.
10987: '</li>';
10988: } else {
10989: $resulttext .= '<li>'.
10990: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
10991: '</li>';
10992: }
1.43 raeburn 10993: }
10994: }
1.160.6.34 raeburn 10995: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10996: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10997: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10998: foreach my $type (@{$changes{'selfcreate'}}) {
10999: my $typename = $type;
1.160.6.93 raeburn 11000: if (keys(%usertypes) > 0) {
11001: if ($usertypes{$type} ne '') {
11002: $typename = $usertypes{$type};
1.28 raeburn 11003: }
11004: }
1.160.6.34 raeburn 11005: my @modifiable;
11006: $resulttext .= '<li>'.
11007: &mt('Self-creation of account by users with status: [_1]',
11008: '<span class="LC_cusr_emph">'.$typename.'</span>').
11009: ' - '.&mt('modifiable fields (if institutional data blank): ');
11010: foreach my $field (@fields) {
11011: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
11012: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
11013: }
11014: }
11015: if (@modifiable > 0) {
11016: $resulttext .= join(', ',@modifiable);
1.43 raeburn 11017: } else {
1.160.6.34 raeburn 11018: $resulttext .= &mt('none');
1.43 raeburn 11019: }
1.160.6.34 raeburn 11020: $resulttext .= '</li>';
1.28 raeburn 11021: }
1.160.6.34 raeburn 11022: $resulttext .= '</ul></li>';
1.28 raeburn 11023: }
1.27 raeburn 11024: $resulttext .= '</ul>';
1.160.6.93 raeburn 11025: my $cachetime = 24*60*60;
11026: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
11027: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11028: if (ref($lastactref) eq 'HASH') {
11029: $lastactref->{'domdefaults'} = 1;
11030: }
1.27 raeburn 11031: } else {
1.160.6.34 raeburn 11032: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 11033: }
11034: } else {
11035: $resulttext = '<span class="LC_error">'.
1.23 raeburn 11036: &mt('An error occurred: [_1]',$putresult).'</span>';
11037: }
1.43 raeburn 11038: if ($warningmsg ne '') {
11039: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
11040: }
1.23 raeburn 11041: return $resulttext;
11042: }
11043:
1.160.6.5 raeburn 11044: sub process_captcha {
11045: my ($container,$changes,$newsettings,$current) = @_;
11046: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
11047: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
11048: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
11049: $newsettings->{'captcha'} = 'original';
11050: }
11051: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
11052: if ($container eq 'cancreate') {
11053: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11054: push(@{$changes->{'cancreate'}},'captcha');
11055: } elsif (!defined($changes->{'cancreate'})) {
11056: $changes->{'cancreate'} = ['captcha'];
11057: }
11058: } else {
11059: $changes->{'captcha'} = 1;
11060: }
11061: }
1.160.6.69 raeburn 11062: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 11063: if ($newsettings->{'captcha'} eq 'recaptcha') {
11064: $newpub = $env{'form.'.$container.'_recaptchapub'};
11065: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 11066: $newpub =~ s/[^\w\-]//g;
11067: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 11068: $newsettings->{'recaptchakeys'} = {
11069: public => $newpub,
11070: private => $newpriv,
11071: };
1.160.6.69 raeburn 11072: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11073: $newversion =~ s/\D//g;
11074: if ($newversion ne '2') {
11075: $newversion = 1;
11076: }
11077: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 11078: }
11079: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11080: $currpub = $current->{'recaptchakeys'}{'public'};
11081: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 11082: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11083: $newsettings->{'recaptchakeys'} = {
11084: public => '',
11085: private => '',
11086: }
11087: }
1.160.6.5 raeburn 11088: }
1.160.6.69 raeburn 11089: if ($current->{'captcha'} eq 'recaptcha') {
11090: $currversion = $current->{'recaptchaversion'};
11091: if ($currversion ne '2') {
11092: $currversion = 1;
11093: }
11094: }
11095: if ($currversion ne $newversion) {
11096: if ($container eq 'cancreate') {
11097: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11098: push(@{$changes->{'cancreate'}},'recaptchaversion');
11099: } elsif (!defined($changes->{'cancreate'})) {
11100: $changes->{'cancreate'} = ['recaptchaversion'];
11101: }
11102: } else {
11103: $changes->{'recaptchaversion'} = 1;
11104: }
11105: }
1.160.6.5 raeburn 11106: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
11107: if ($container eq 'cancreate') {
11108: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11109: push(@{$changes->{'cancreate'}},'recaptchakeys');
11110: } elsif (!defined($changes->{'cancreate'})) {
11111: $changes->{'cancreate'} = ['recaptchakeys'];
11112: }
11113: } else {
11114: $changes->{'recaptchakeys'} = 1;
11115: }
11116: }
11117: return;
11118: }
11119:
1.33 raeburn 11120: sub modify_usermodification {
11121: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 11122: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11123: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11124: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 11125: if ($key eq 'selfcreate') {
11126: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11127: } else {
11128: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11129: }
1.33 raeburn 11130: }
11131: }
1.160.6.34 raeburn 11132: my @contexts = ('author','course');
1.33 raeburn 11133: my %context_title = (
11134: author => 'In author context',
11135: course => 'In course context',
11136: );
11137: my @fields = ('lastname','firstname','middlename','generation',
11138: 'permanentemail','id');
11139: my %roles = (
11140: author => ['ca','aa'],
11141: course => ['st','ep','ta','in','cr'],
11142: );
11143: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11144: foreach my $context (@contexts) {
11145: foreach my $role (@{$roles{$context}}) {
11146: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11147: foreach my $item (@fields) {
11148: if (grep(/^\Q$item\E$/,@modifiable)) {
11149: $modifyhash{$context}{$role}{$item} = 1;
11150: } else {
11151: $modifyhash{$context}{$role}{$item} = 0;
11152: }
11153: }
11154: }
11155: if (ref($curr_usermodification{$context}) eq 'HASH') {
11156: foreach my $role (@{$roles{$context}}) {
11157: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11158: foreach my $field (@fields) {
11159: if ($modifyhash{$context}{$role}{$field} ne
11160: $curr_usermodification{$context}{$role}{$field}) {
11161: push(@{$changes{$context}},$role);
11162: last;
11163: }
11164: }
11165: }
11166: }
11167: } else {
11168: foreach my $context (@contexts) {
11169: foreach my $role (@{$roles{$context}}) {
11170: push(@{$changes{$context}},$role);
11171: }
11172: }
11173: }
11174: }
11175: my %usermodification_hash = (
11176: usermodification => \%modifyhash,
11177: );
11178: my $putresult = &Apache::lonnet::put_dom('configuration',
11179: \%usermodification_hash,$dom);
11180: if ($putresult eq 'ok') {
11181: if (keys(%changes) > 0) {
11182: $resulttext = &mt('Changes made: ').'<ul>';
11183: foreach my $context (@contexts) {
11184: if (ref($changes{$context}) eq 'ARRAY') {
11185: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11186: if (ref($changes{$context}) eq 'ARRAY') {
11187: foreach my $role (@{$changes{$context}}) {
11188: my $rolename;
1.160.6.34 raeburn 11189: if ($role eq 'cr') {
11190: $rolename = &mt('Custom');
1.33 raeburn 11191: } else {
1.160.6.34 raeburn 11192: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11193: }
11194: my @modifiable;
1.160.6.34 raeburn 11195: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11196: foreach my $field (@fields) {
11197: if ($modifyhash{$context}{$role}{$field}) {
11198: push(@modifiable,$fieldtitles{$field});
11199: }
11200: }
11201: if (@modifiable > 0) {
11202: $resulttext .= join(', ',@modifiable);
11203: } else {
11204: $resulttext .= &mt('none');
11205: }
11206: $resulttext .= '</li>';
11207: }
11208: $resulttext .= '</ul></li>';
11209: }
11210: }
11211: }
11212: $resulttext .= '</ul>';
11213: } else {
11214: $resulttext = &mt('No changes made to user modification settings');
11215: }
11216: } else {
11217: $resulttext = '<span class="LC_error">'.
11218: &mt('An error occurred: [_1]',$putresult).'</span>';
11219: }
11220: return $resulttext;
11221: }
11222:
1.43 raeburn 11223: sub modify_defaults {
1.160.6.27 raeburn 11224: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11225: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 11226: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 11227: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
11228: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 11229: my @authtypes = ('internal','krb4','krb5','localauth');
11230: foreach my $item (@items) {
11231: $newvalues{$item} = $env{'form.'.$item};
11232: if ($item eq 'auth_def') {
11233: if ($newvalues{$item} ne '') {
11234: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11235: push(@errors,$item);
11236: }
11237: }
11238: } elsif ($item eq 'lang_def') {
11239: if ($newvalues{$item} ne '') {
11240: if ($newvalues{$item} =~ /^(\w+)/) {
11241: my $langcode = $1;
1.103 raeburn 11242: if ($langcode ne 'x_chef') {
11243: if (code2language($langcode) eq '') {
11244: push(@errors,$item);
11245: }
1.43 raeburn 11246: }
11247: } else {
11248: push(@errors,$item);
11249: }
11250: }
1.54 raeburn 11251: } elsif ($item eq 'timezone_def') {
11252: if ($newvalues{$item} ne '') {
1.62 raeburn 11253: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11254: push(@errors,$item);
11255: }
11256: }
1.68 raeburn 11257: } elsif ($item eq 'datelocale_def') {
11258: if ($newvalues{$item} ne '') {
11259: my @datelocale_ids = DateTime::Locale->ids();
11260: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11261: push(@errors,$item);
11262: }
11263: }
1.141 raeburn 11264: } elsif ($item eq 'portal_def') {
11265: if ($newvalues{$item} ne '') {
11266: 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])\/?$/) {
11267: push(@errors,$item);
11268: }
11269: }
1.160.6.80 raeburn 11270: } elsif ($item eq 'intauth_cost') {
11271: if ($newvalues{$item} ne '') {
11272: if ($newvalues{$item} =~ /\D/) {
11273: push(@errors,$item);
11274: }
11275: }
11276: } elsif ($item eq 'intauth_check') {
11277: if ($newvalues{$item} ne '') {
11278: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11279: push(@errors,$item);
11280: }
11281: }
11282: } elsif ($item eq 'intauth_switch') {
11283: if ($newvalues{$item} ne '') {
11284: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11285: push(@errors,$item);
11286: }
11287: }
1.43 raeburn 11288: }
11289: if (grep(/^\Q$item\E$/,@errors)) {
11290: $newvalues{$item} = $domdefaults{$item};
11291: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
11292: $changes{$item} = 1;
11293: }
1.72 raeburn 11294: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 11295: }
11296: my %defaults_hash = (
1.72 raeburn 11297: defaults => \%newvalues,
11298: );
1.43 raeburn 11299: my $title = &defaults_titles();
1.160.6.40 raeburn 11300:
11301: my $currinststatus;
11302: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11303: $currinststatus = $domconfig{'inststatus'};
11304: } else {
11305: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11306: $currinststatus = {
11307: inststatustypes => $usertypes,
11308: inststatusorder => $types,
11309: inststatusguest => [],
11310: };
11311: }
11312: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
11313: my @allpos;
11314: my %alltypes;
1.160.6.93 raeburn 11315: my @inststatusguest;
11316: if (ref($currinststatus) eq 'HASH') {
11317: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11318: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
11319: unless (grep(/^\Q$type\E$/,@todelete)) {
11320: push(@inststatusguest,$type);
11321: }
11322: }
11323: }
11324: }
11325: my ($currtitles,$currorder);
1.160.6.40 raeburn 11326: if (ref($currinststatus) eq 'HASH') {
11327: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
11328: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
11329: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
11330: if ($currinststatus->{inststatustypes}->{$type} ne '') {
11331: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
11332: }
11333: }
11334: unless (grep(/^\Q$type\E$/,@todelete)) {
11335: my $position = $env{'form.inststatus_pos_'.$type};
11336: $position =~ s/\D+//g;
11337: $allpos[$position] = $type;
11338: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
11339: $alltypes{$type} =~ s/`//g;
11340: }
11341: }
11342: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11343: $currtitles =~ s/,$//;
11344: }
11345: }
11346: if ($env{'form.addinststatus'}) {
11347: my $newtype = $env{'form.addinststatus'};
11348: $newtype =~ s/\W//g;
11349: unless (exists($alltypes{$newtype})) {
11350: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11351: $alltypes{$newtype} =~ s/`//g;
11352: my $position = $env{'form.addinststatus_pos'};
11353: $position =~ s/\D+//g;
11354: if ($position ne '') {
11355: $allpos[$position] = $newtype;
11356: }
11357: }
11358: }
1.160.6.93 raeburn 11359: my @orderedstatus;
1.160.6.40 raeburn 11360: foreach my $type (@allpos) {
11361: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11362: push(@orderedstatus,$type);
11363: }
11364: }
11365: foreach my $type (keys(%alltypes)) {
11366: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
11367: delete($alltypes{$type});
11368: }
11369: }
11370: $defaults_hash{'inststatus'} = {
11371: inststatustypes => \%alltypes,
11372: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 11373: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 11374: };
11375: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
11376: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
11377: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
11378: }
11379: }
11380: if ($currorder ne join(',',@orderedstatus)) {
11381: $changes{'inststatus'}{'inststatusorder'} = 1;
11382: }
11383: my $newtitles;
11384: foreach my $item (@orderedstatus) {
11385: $newtitles .= $alltypes{$item}.',';
11386: }
11387: $newtitles =~ s/,$//;
11388: if ($currtitles ne $newtitles) {
11389: $changes{'inststatus'}{'inststatustypes'} = 1;
11390: }
1.43 raeburn 11391: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
11392: $dom);
11393: if ($putresult eq 'ok') {
11394: if (keys(%changes) > 0) {
11395: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 11396: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 11397: 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";
11398: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 11399: if ($item eq 'inststatus') {
11400: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 11401: if (@orderedstatus) {
1.160.6.40 raeburn 11402: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
11403: foreach my $type (@orderedstatus) {
11404: $resulttext .= $alltypes{$type}.', ';
11405: }
11406: $resulttext =~ s/, $//;
11407: $resulttext .= '</li>';
1.160.6.93 raeburn 11408: } else {
11409: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 11410: }
11411: }
11412: } else {
11413: my $value = $env{'form.'.$item};
11414: if ($value eq '') {
11415: $value = &mt('none');
11416: } elsif ($item eq 'auth_def') {
11417: my %authnames = &authtype_names();
11418: my %shortauth = (
11419: internal => 'int',
11420: krb4 => 'krb4',
11421: krb5 => 'krb5',
11422: localauth => 'loc',
11423: );
11424: $value = $authnames{$shortauth{$value}};
1.160.6.80 raeburn 11425: } elsif ($item eq 'intauth_switch') {
11426: my %optiondesc = &Apache::lonlocal::texthash (
11427: 0 => 'No',
11428: 1 => 'Yes',
11429: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
11430: );
11431: if ($value =~ /^(0|1|2)$/) {
11432: $value = $optiondesc{$value};
11433: } else {
11434: $value = &mt('none -- defaults to No');
11435: }
11436: } elsif ($item eq 'intauth_check') {
11437: my %optiondesc = &Apache::lonlocal::texthash (
11438: 0 => 'No',
11439: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
11440: 2 => 'Yes, disallow login if stored cost is less than domain default',
11441: );
11442: if ($value =~ /^(0|1|2)$/) {
11443: $value = $optiondesc{$value};
11444: } else {
11445: $value = &mt('none -- defaults to No');
11446: }
1.160.6.40 raeburn 11447: }
11448: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11449: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11450: }
11451: }
11452: $resulttext .= '</ul>';
11453: $mailmsgtext .= "\n";
11454: my $cachetime = 24*60*60;
1.72 raeburn 11455: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11456: if (ref($lastactref) eq 'HASH') {
11457: $lastactref->{'domdefaults'} = 1;
11458: }
1.68 raeburn 11459: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 11460: my $notify = 1;
11461: if (ref($domconfig{'contacts'}) eq 'HASH') {
11462: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11463: $notify = 0;
11464: }
11465: }
11466: if ($notify) {
11467: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11468: "LON-CAPA Domain Settings Change - $dom",
11469: $mailmsgtext);
11470: }
1.54 raeburn 11471: }
1.43 raeburn 11472: } else {
1.54 raeburn 11473: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11474: }
11475: } else {
11476: $resulttext = '<span class="LC_error">'.
11477: &mt('An error occurred: [_1]',$putresult).'</span>';
11478: }
11479: if (@errors > 0) {
11480: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11481: foreach my $item (@errors) {
11482: $resulttext .= ' "'.$title->{$item}.'",';
11483: }
11484: $resulttext =~ s/,$//;
11485: }
11486: return $resulttext;
11487: }
11488:
1.46 raeburn 11489: sub modify_scantron {
1.160.6.24 raeburn 11490: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11491: my ($resulttext,%confhash,%changes,$errors);
11492: my $custom = 'custom.tab';
11493: my $default = 'default.tab';
11494: my $servadm = $r->dir_config('lonAdmEMail');
11495: my ($configuserok,$author_ok,$switchserver) =
11496: &config_check($dom,$confname,$servadm);
11497: if ($env{'form.scantronformat.filename'} ne '') {
11498: my $error;
11499: if ($configuserok eq 'ok') {
11500: if ($switchserver) {
1.130 raeburn 11501: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 11502: } else {
11503: if ($author_ok eq 'ok') {
11504: my ($result,$scantronurl) =
11505: &publishlogo($r,'upload','scantronformat',$dom,
11506: $confname,'scantron','','',$custom);
11507: if ($result eq 'ok') {
11508: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 11509: $changes{'scantronformat'} = 1;
1.46 raeburn 11510: } else {
11511: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
11512: }
11513: } else {
11514: $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);
11515: }
11516: }
11517: } else {
11518: $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);
11519: }
11520: if ($error) {
11521: &Apache::lonnet::logthis($error);
11522: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11523: }
11524: }
1.48 raeburn 11525: if (ref($domconfig{'scantron'}) eq 'HASH') {
11526: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
11527: if ($env{'form.scantronformat_del'}) {
11528: $confhash{'scantron'}{'scantronformat'} = '';
11529: $changes{'scantronformat'} = 1;
1.46 raeburn 11530: }
11531: }
11532: }
11533: if (keys(%confhash) > 0) {
11534: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
11535: $dom);
11536: if ($putresult eq 'ok') {
11537: if (keys(%changes) > 0) {
1.48 raeburn 11538: if (ref($confhash{'scantron'}) eq 'HASH') {
11539: $resulttext = &mt('Changes made:').'<ul>';
11540: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 11541: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 11542: } else {
1.130 raeburn 11543: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 11544: }
1.48 raeburn 11545: $resulttext .= '</ul>';
11546: } else {
1.130 raeburn 11547: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 11548: }
11549: $resulttext .= '</ul>';
11550: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11551: if (ref($lastactref) eq 'HASH') {
11552: $lastactref->{'domainconfig'} = 1;
11553: }
1.46 raeburn 11554: } else {
1.130 raeburn 11555: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11556: }
11557: } else {
11558: $resulttext = '<span class="LC_error">'.
11559: &mt('An error occurred: [_1]',$putresult).'</span>';
11560: }
11561: } else {
1.130 raeburn 11562: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11563: }
11564: if ($errors) {
11565: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11566: $errors.'</ul>';
11567: }
11568: return $resulttext;
11569: }
11570:
1.48 raeburn 11571: sub modify_coursecategories {
1.160.6.43 raeburn 11572: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 11573: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
11574: $cathash);
1.48 raeburn 11575: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 11576: my @catitems = ('unauth','auth');
11577: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 11578: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 11579: $cathash = $domconfig{'coursecategories'}{'cats'};
11580: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
11581: $changes{'togglecats'} = 1;
11582: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
11583: }
11584: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
11585: $changes{'categorize'} = 1;
11586: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
11587: }
1.120 raeburn 11588: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
11589: $changes{'togglecatscomm'} = 1;
11590: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
11591: }
11592: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
11593: $changes{'categorizecomm'} = 1;
11594: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
11595: }
1.160.6.42 raeburn 11596: foreach my $item (@catitems) {
11597: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11598: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
11599: $changes{$item} = 1;
11600: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11601: }
11602: }
11603: }
1.57 raeburn 11604: } else {
11605: $changes{'togglecats'} = 1;
11606: $changes{'categorize'} = 1;
1.124 raeburn 11607: $changes{'togglecatscomm'} = 1;
11608: $changes{'categorizecomm'} = 1;
1.87 raeburn 11609: $domconfig{'coursecategories'} = {
11610: togglecats => $env{'form.togglecats'},
11611: categorize => $env{'form.categorize'},
1.124 raeburn 11612: togglecatscomm => $env{'form.togglecatscomm'},
11613: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 11614: };
1.160.6.42 raeburn 11615: foreach my $item (@catitems) {
11616: if ($env{'form.coursecat_'.$item} ne 'std') {
11617: $changes{$item} = 1;
11618: }
11619: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11620: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11621: }
11622: }
1.57 raeburn 11623: }
11624: if (ref($cathash) eq 'HASH') {
11625: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 11626: push (@deletecategory,'instcode::0');
11627: }
1.120 raeburn 11628: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11629: push(@deletecategory,'communities::0');
11630: }
1.48 raeburn 11631: }
1.57 raeburn 11632: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11633: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11634: if (@deletecategory > 0) {
11635: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 11636: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 11637: foreach my $item (@deletecategory) {
1.57 raeburn 11638: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11639: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11640: $deletions{$item} = 1;
1.57 raeburn 11641: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11642: }
11643: }
11644: }
1.57 raeburn 11645: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11646: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11647: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11648: $reorderings{$item} = 1;
1.57 raeburn 11649: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11650: }
11651: if ($env{'form.addcategory_name_'.$item} ne '') {
11652: my $newcat = $env{'form.addcategory_name_'.$item};
11653: my $newdepth = $depth+1;
11654: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11655: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11656: $adds{$newitem} = 1;
11657: }
11658: if ($env{'form.subcat_'.$item} ne '') {
11659: my $newcat = $env{'form.subcat_'.$item};
11660: my $newdepth = $depth+1;
11661: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11662: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11663: $adds{$newitem} = 1;
11664: }
11665: }
11666: }
11667: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11668: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11669: my $newitem = 'instcode::0';
1.57 raeburn 11670: if ($cathash->{$newitem} eq '') {
11671: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11672: $adds{$newitem} = 1;
11673: }
11674: } else {
11675: my $newitem = 'instcode::0';
1.57 raeburn 11676: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11677: $adds{$newitem} = 1;
11678: }
11679: }
1.120 raeburn 11680: if ($env{'form.communities'} eq '1') {
11681: if (ref($cathash) eq 'HASH') {
11682: my $newitem = 'communities::0';
11683: if ($cathash->{$newitem} eq '') {
11684: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11685: $adds{$newitem} = 1;
11686: }
11687: } else {
11688: my $newitem = 'communities::0';
11689: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11690: $adds{$newitem} = 1;
11691: }
11692: }
1.48 raeburn 11693: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11694: if (($env{'form.addcategory_name'} ne 'instcode') &&
11695: ($env{'form.addcategory_name'} ne 'communities')) {
11696: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11697: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11698: $adds{$newitem} = 1;
11699: }
1.48 raeburn 11700: }
1.57 raeburn 11701: my $putresult;
1.48 raeburn 11702: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11703: if (keys(%deletions) > 0) {
11704: foreach my $key (keys(%deletions)) {
11705: if ($predelallitems{$key} ne '') {
11706: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11707: }
11708: }
11709: }
11710: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11711: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11712: if (ref($chkcats[0]) eq 'ARRAY') {
11713: my $depth = 0;
11714: my $chg = 0;
11715: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11716: my $name = $chkcats[0][$i];
11717: my $item;
11718: if ($name eq '') {
11719: $chg ++;
11720: } else {
11721: $item = &escape($name).'::0';
11722: if ($chg) {
1.57 raeburn 11723: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11724: }
11725: $depth ++;
1.57 raeburn 11726: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11727: $depth --;
11728: }
11729: }
11730: }
1.57 raeburn 11731: }
11732: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11733: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11734: if ($putresult eq 'ok') {
1.57 raeburn 11735: my %title = (
1.120 raeburn 11736: togglecats => 'Show/Hide a course in catalog',
11737: categorize => 'Assign a category to a course',
11738: togglecatscomm => 'Show/Hide a community in catalog',
11739: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11740: );
11741: my %level = (
1.120 raeburn 11742: dom => 'set in Domain ("Modify Course/Community")',
11743: crs => 'set in Course ("Course Configuration")',
11744: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 11745: none => 'No catalog',
11746: std => 'Standard catalog',
11747: domonly => 'Domain-only catalog',
11748: codesrch => 'Code search form',
1.57 raeburn 11749: );
1.48 raeburn 11750: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11751: if ($changes{'togglecats'}) {
11752: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11753: }
11754: if ($changes{'categorize'}) {
11755: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11756: }
1.120 raeburn 11757: if ($changes{'togglecatscomm'}) {
11758: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11759: }
11760: if ($changes{'categorizecomm'}) {
11761: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11762: }
1.160.6.42 raeburn 11763: if ($changes{'unauth'}) {
11764: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11765: }
11766: if ($changes{'auth'}) {
11767: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11768: }
1.57 raeburn 11769: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11770: my $cathash;
11771: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11772: $cathash = $domconfig{'coursecategories'}{'cats'};
11773: } else {
11774: $cathash = {};
11775: }
11776: my (@cats,@trails,%allitems);
11777: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11778: if (keys(%deletions) > 0) {
11779: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11780: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11781: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11782: }
11783: $resulttext .= '</ul></li>';
11784: }
11785: if (keys(%reorderings) > 0) {
11786: my %sort_by_trail;
11787: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11788: foreach my $key (keys(%reorderings)) {
11789: if ($allitems{$key} ne '') {
11790: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11791: }
1.48 raeburn 11792: }
1.57 raeburn 11793: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11794: $resulttext .= '<li>'.$trails[$trail].'</li>';
11795: }
11796: $resulttext .= '</ul></li>';
1.48 raeburn 11797: }
1.57 raeburn 11798: if (keys(%adds) > 0) {
11799: my %sort_by_trail;
11800: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11801: foreach my $key (keys(%adds)) {
11802: if ($allitems{$key} ne '') {
11803: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11804: }
11805: }
11806: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11807: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11808: }
1.57 raeburn 11809: $resulttext .= '</ul></li>';
1.48 raeburn 11810: }
1.160.6.92 raeburn 11811: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
11812: if (ref($lastactref) eq 'HASH') {
11813: $lastactref->{'cats'} = 1;
11814: }
1.48 raeburn 11815: }
11816: $resulttext .= '</ul>';
1.160.6.43 raeburn 11817: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 11818: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11819: if ($changes{'auth'}) {
11820: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11821: }
11822: if ($changes{'unauth'}) {
11823: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11824: }
11825: my $cachetime = 24*60*60;
11826: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 11827: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 11828: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 11829: }
11830: }
1.48 raeburn 11831: } else {
11832: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11833: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11834: }
11835: } else {
1.120 raeburn 11836: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11837: }
11838: return $resulttext;
11839: }
11840:
1.69 raeburn 11841: sub modify_serverstatuses {
11842: my ($dom,%domconfig) = @_;
11843: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11844: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11845: %currserverstatus = %{$domconfig{'serverstatuses'}};
11846: }
11847: my @pages = &serverstatus_pages();
11848: foreach my $type (@pages) {
11849: $newserverstatus{$type}{'namedusers'} = '';
11850: $newserverstatus{$type}{'machines'} = '';
11851: if (defined($env{'form.'.$type.'_namedusers'})) {
11852: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11853: my @okusers;
11854: foreach my $user (@users) {
11855: my ($uname,$udom) = split(/:/,$user);
11856: if (($udom =~ /^$match_domain$/) &&
11857: (&Apache::lonnet::domain($udom)) &&
11858: ($uname =~ /^$match_username$/)) {
11859: if (!grep(/^\Q$user\E/,@okusers)) {
11860: push(@okusers,$user);
11861: }
11862: }
11863: }
11864: if (@okusers > 0) {
11865: @okusers = sort(@okusers);
11866: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11867: }
11868: }
11869: if (defined($env{'form.'.$type.'_machines'})) {
11870: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11871: my @okmachines;
11872: foreach my $ip (@machines) {
11873: my @parts = split(/\./,$ip);
11874: next if (@parts < 4);
11875: my $badip = 0;
11876: for (my $i=0; $i<4; $i++) {
11877: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11878: $badip = 1;
11879: last;
11880: }
11881: }
11882: if (!$badip) {
11883: push(@okmachines,$ip);
11884: }
11885: }
11886: @okmachines = sort(@okmachines);
11887: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11888: }
11889: }
11890: my %serverstatushash = (
11891: serverstatuses => \%newserverstatus,
11892: );
11893: foreach my $type (@pages) {
1.83 raeburn 11894: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11895: my (@current,@new);
1.83 raeburn 11896: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11897: if ($currserverstatus{$type}{$setting} ne '') {
11898: @current = split(/,/,$currserverstatus{$type}{$setting});
11899: }
11900: }
11901: if ($newserverstatus{$type}{$setting} ne '') {
11902: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11903: }
11904: if (@current > 0) {
11905: if (@new > 0) {
11906: foreach my $item (@current) {
11907: if (!grep(/^\Q$item\E$/,@new)) {
11908: $changes{$type}{$setting} = 1;
1.82 raeburn 11909: last;
11910: }
11911: }
1.84 raeburn 11912: foreach my $item (@new) {
11913: if (!grep(/^\Q$item\E$/,@current)) {
11914: $changes{$type}{$setting} = 1;
11915: last;
1.82 raeburn 11916: }
11917: }
11918: } else {
1.83 raeburn 11919: $changes{$type}{$setting} = 1;
1.69 raeburn 11920: }
1.83 raeburn 11921: } elsif (@new > 0) {
11922: $changes{$type}{$setting} = 1;
1.69 raeburn 11923: }
11924: }
11925: }
11926: if (keys(%changes) > 0) {
1.81 raeburn 11927: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11928: my $putresult = &Apache::lonnet::put_dom('configuration',
11929: \%serverstatushash,$dom);
11930: if ($putresult eq 'ok') {
11931: $resulttext .= &mt('Changes made:').'<ul>';
11932: foreach my $type (@pages) {
1.84 raeburn 11933: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11934: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11935: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11936: if ($newserverstatus{$type}{'namedusers'} eq '') {
11937: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11938: } else {
11939: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11940: }
1.84 raeburn 11941: }
11942: if ($changes{$type}{'machines'}) {
1.69 raeburn 11943: if ($newserverstatus{$type}{'machines'} eq '') {
11944: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11945: } else {
11946: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11947: }
11948:
11949: }
11950: $resulttext .= '</ul></li>';
11951: }
11952: }
11953: $resulttext .= '</ul>';
11954: } else {
11955: $resulttext = '<span class="LC_error">'.
11956: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11957:
11958: }
11959: } else {
11960: $resulttext = &mt('No changes made to access to server status pages');
11961: }
11962: return $resulttext;
11963: }
11964:
1.118 jms 11965: sub modify_helpsettings {
1.160.6.77 raeburn 11966: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 11967: my ($resulttext,$errors,%changes,%helphash);
11968: my %defaultchecked = ('submitbugs' => 'on');
11969: my @offon = ('off','on');
1.118 jms 11970: my @toggles = ('submitbugs');
1.160.6.77 raeburn 11971: my %current = ('submitbugs' => '',
11972: 'adhoc' => {},
11973: );
1.118 jms 11974: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 11975: %current = %{$domconfig{'helpsettings'}};
11976: }
1.160.6.77 raeburn 11977: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 11978: foreach my $item (@toggles) {
11979: if ($defaultchecked{$item} eq 'on') {
11980: if ($current{$item} eq '') {
11981: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 11982: $changes{$item} = 1;
11983: }
1.160.6.73 raeburn 11984: } elsif ($current{$item} ne $env{'form.'.$item}) {
11985: $changes{$item} = 1;
11986: }
11987: } elsif ($defaultchecked{$item} eq 'off') {
11988: if ($current{$item} eq '') {
11989: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 11990: $changes{$item} = 1;
11991: }
1.160.6.73 raeburn 11992: } elsif ($current{$item} ne $env{'form.'.$item}) {
11993: $changes{$item} = 1;
11994: }
11995: }
11996: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
11997: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11998: }
11999: }
1.160.6.77 raeburn 12000: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 12001: my $confname = $dom.'-domainconfig';
12002: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 12003: my (@allpos,%newsettings,%changedprivs,$newrole);
12004: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 12005: my @accesstypes = ('all','dh','da','none','status','inc','exc');
12006: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 12007: my %lt = &Apache::lonlocal::texthash(
12008: s => 'system',
12009: d => 'domain',
12010: order => 'Display order',
12011: access => 'Role usage',
1.160.6.79 raeburn 12012: all => 'All with domain helpdesk or helpdesk assistant role',
12013: dh => 'All with domain helpdesk role',
12014: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 12015: none => 'None',
12016: status => 'Determined based on institutional status',
12017: inc => 'Include all, but exclude specific personnel',
12018: exc => 'Exclude all, but include specific personnel',
12019: );
12020: for (my $num=0; $num<=$maxnum; $num++) {
12021: my ($prefix,$identifier,$rolename,%curr);
12022: if ($num == $maxnum) {
12023: next unless ($env{'form.newcusthelp'} == $maxnum);
12024: $identifier = 'custhelp'.$num;
12025: $prefix = 'helproles_'.$num;
12026: $rolename = $env{'form.custhelpname'.$num};
12027: $rolename=~s/[^A-Za-z0-9]//gs;
12028: next if ($rolename eq '');
12029: next if (exists($existing{'rolesdef_'.$rolename}));
12030: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12031: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12032: $newprivs{'c'},$confname,$dom);
12033: if ($result ne 'ok') {
12034: $errors .= '<li><span class="LC_error">'.
12035: &mt('An error occurred storing the new custom role: [_1]',
12036: $result).'</span></li>';
12037: next;
12038: } else {
12039: $changedprivs{$rolename} = \%newprivs;
12040: $newrole = $rolename;
12041: }
12042: } else {
12043: $prefix = 'helproles_'.$num;
12044: $rolename = $env{'form.'.$prefix};
12045: next if ($rolename eq '');
12046: next unless (exists($existing{'rolesdef_'.$rolename}));
12047: $identifier = 'custhelp'.$num;
12048: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
12049: my %currprivs;
12050: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
12051: split(/\_/,$existing{'rolesdef_'.$rolename});
12052: foreach my $level ('c','d','s') {
12053: if ($newprivs{$level} ne $currprivs{$level}) {
12054: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
12055: $newprivs{'c'},$confname,$dom);
12056: if ($result ne 'ok') {
12057: $errors .= '<li><span class="LC_error">'.
12058: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
12059: $rolename,$result).'</span></li>';
12060: } else {
12061: $changedprivs{$rolename} = \%newprivs;
12062: }
12063: last;
12064: }
12065: }
12066: if (ref($current{'adhoc'}) eq 'HASH') {
12067: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12068: %curr = %{$current{'adhoc'}{$rolename}};
12069: }
12070: }
12071: }
12072: my $newpos = $env{'form.'.$prefix.'_pos'};
12073: $newpos =~ s/\D+//g;
12074: $allpos[$newpos] = $rolename;
12075: my $newdesc = $env{'form.'.$prefix.'_desc'};
12076: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12077: if ($curr{'desc'}) {
12078: if ($curr{'desc'} ne $newdesc) {
12079: $changes{'customrole'}{$rolename}{'desc'} = 1;
12080: $newsettings{$rolename}{'desc'} = $newdesc;
12081: }
12082: } elsif ($newdesc ne '') {
12083: $changes{'customrole'}{$rolename}{'desc'} = 1;
12084: $newsettings{$rolename}{'desc'} = $newdesc;
12085: }
12086: my $access = $env{'form.'.$prefix.'_access'};
12087: if (grep(/^\Q$access\E$/,@accesstypes)) {
12088: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12089: if ($access eq 'status') {
12090: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12091: if (scalar(@statuses) == 0) {
12092: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
12093: } else {
12094: my (@shownstatus,$numtypes);
12095: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12096: if (ref($types) eq 'ARRAY') {
12097: $numtypes = scalar(@{$types});
12098: foreach my $type (sort(@statuses)) {
12099: if ($type eq 'default') {
12100: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12101: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12102: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12103: push(@shownstatus,$usertypes->{$type});
12104: }
1.160.6.73 raeburn 12105: }
12106: }
1.160.6.77 raeburn 12107: if (grep(/^default$/,@statuses)) {
12108: push(@shownstatus,$othertitle);
12109: }
12110: if (scalar(@shownstatus) == 1+$numtypes) {
12111: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12112: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12113: } else {
12114: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12115: if (ref($curr{'status'}) eq 'ARRAY') {
12116: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12117: if (@diffs) {
12118: $changes{'customrole'}{$rolename}{$access} = 1;
12119: }
12120: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12121: $changes{'customrole'}{$rolename}{$access} = 1;
12122: }
12123: }
12124: }
12125: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12126: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12127: my @newspecstaff;
12128: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12129: foreach my $person (sort(@personnel)) {
12130: if ($domhelpdesk{$person}) {
12131: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12132: }
12133: }
12134: if (ref($curr{$access}) eq 'ARRAY') {
12135: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12136: if (@diffs) {
12137: $changes{'customrole'}{$rolename}{$access} = 1;
12138: }
12139: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12140: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 12141: }
1.160.6.77 raeburn 12142: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12143: my ($uname,$udom) = split(/:/,$person);
12144: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12145: }
12146: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 12147: }
1.160.6.77 raeburn 12148: } else {
12149: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12150: }
12151: unless ($curr{'access'} eq $access) {
12152: $changes{'customrole'}{$rolename}{'access'} = 1;
12153: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 12154: }
12155: }
1.160.6.77 raeburn 12156: if (@allpos > 0) {
12157: my $idx = 0;
12158: foreach my $rolename (@allpos) {
12159: if ($rolename ne '') {
12160: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12161: if (ref($current{'adhoc'}) eq 'HASH') {
12162: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12163: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12164: $changes{'customrole'}{$rolename}{'order'} = 1;
12165: $newsettings{$rolename}{'order'} = $idx+1;
12166: }
12167: }
1.160.6.73 raeburn 12168: }
1.160.6.77 raeburn 12169: $idx ++;
1.122 jms 12170: }
12171: }
1.118 jms 12172: }
1.123 jms 12173: my $putresult;
12174: if (keys(%changes) > 0) {
1.160.6.5 raeburn 12175: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
12176: if ($putresult eq 'ok') {
1.160.6.77 raeburn 12177: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12178: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12179: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12180: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12181: }
12182: }
12183: my $cachetime = 24*60*60;
12184: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12185: if (ref($lastactref) eq 'HASH') {
12186: $lastactref->{'domdefaults'} = 1;
12187: }
12188: } else {
12189: $errors .= '<li><span class="LC_error">'.
12190: &mt('An error occurred storing the settings: [_1]',
12191: $putresult).'</span></li>';
12192: }
12193: }
12194: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12195: $resulttext = &mt('Changes made:').'<ul>';
12196: my (%shownprivs,@levelorder);
12197: @levelorder = ('c','d','s');
12198: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 12199: foreach my $item (sort(keys(%changes))) {
12200: if ($item eq 'submitbugs') {
12201: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12202: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12203: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 12204: } elsif ($item eq 'customrole') {
12205: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 12206: my @keyorder = ('order','desc','access','status','exc','inc');
12207: my %keytext = &Apache::lonlocal::texthash(
12208: order => 'Order',
12209: desc => 'Role description',
12210: access => 'Role usage',
1.160.6.83 raeburn 12211: status => 'Allowed institutional types',
1.160.6.77 raeburn 12212: exc => 'Allowed personnel',
12213: inc => 'Disallowed personnel',
12214: );
1.160.6.73 raeburn 12215: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 12216: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12217: if ($role eq $newrole) {
12218: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12219: $role).'<ul>';
12220: } else {
12221: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12222: $role).'<ul>';
12223: }
12224: foreach my $key (@keyorder) {
12225: if ($changes{'customrole'}{$role}{$key}) {
12226: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12227: $keytext{$key},$newsettings{$role}{$key}).
12228: '</li>';
12229: }
12230: }
12231: if (ref($changedprivs{$role}) eq 'HASH') {
12232: $shownprivs{$role} = 1;
12233: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
12234: foreach my $level (@levelorder) {
12235: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12236: next if ($item eq '');
12237: my ($priv) = split(/\&/,$item,2);
12238: if (&Apache::lonnet::plaintext($priv)) {
12239: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12240: unless ($level eq 'c') {
12241: $resulttext .= ' ('.$lt{$level}.')';
12242: }
12243: $resulttext .= '</li>';
12244: }
12245: }
12246: }
12247: $resulttext .= '</ul>';
12248: }
12249: $resulttext .= '</ul></li>';
12250: }
1.160.6.73 raeburn 12251: }
12252: }
1.160.6.5 raeburn 12253: }
12254: }
12255: }
1.160.6.77 raeburn 12256: if (keys(%changedprivs)) {
12257: foreach my $role (sort(keys(%changedprivs))) {
12258: unless ($shownprivs{$role}) {
12259: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12260: $role).'<ul>'.
12261: '<li>'.&mt('Privileges set to :').'<ul>';
12262: foreach my $level (@levelorder) {
12263: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12264: next if ($item eq '');
12265: my ($priv) = split(/\&/,$item,2);
12266: if (&Apache::lonnet::plaintext($priv)) {
12267: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12268: unless ($level eq 'c') {
12269: $resulttext .= ' ('.$lt{$level}.')';
12270: }
12271: $resulttext .= '</li>';
12272: }
12273: }
12274: }
12275: $resulttext .= '</ul></li></ul></li>';
12276: }
12277: }
12278: }
12279: $resulttext .= '</ul>';
12280: } else {
12281: $resulttext = &mt('No changes made to help settings');
1.118 jms 12282: }
12283: if ($errors) {
1.160.6.5 raeburn 12284: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 12285: $errors.'</ul>';
1.118 jms 12286: }
12287: return $resulttext;
12288: }
12289:
1.121 raeburn 12290: sub modify_coursedefaults {
1.160.6.27 raeburn 12291: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 12292: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 12293: my %defaultchecked = (
12294: 'uselcmath' => 'on',
12295: 'usejsme' => 'on'
12296: );
12297: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 12298: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 12299: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
12300: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 12301: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 12302: my %staticdefaults = (
12303: anonsurvey_threshold => 10,
12304: uploadquota => 500,
1.160.6.57 raeburn 12305: postsubmit => 60,
1.160.6.70 raeburn 12306: mysqltables => 172800,
1.160.6.21 raeburn 12307: );
1.160.6.90 raeburn 12308: my %texoptions = (
12309: MathJax => 'MathJax',
12310: mimetex => &mt('Convert to Images'),
12311: tth => &mt('TeX to HTML'),
12312: );
1.121 raeburn 12313: $defaultshash{'coursedefaults'} = {};
12314:
12315: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
12316: if ($domconfig{'coursedefaults'} eq '') {
12317: $domconfig{'coursedefaults'} = {};
12318: }
12319: }
12320:
12321: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
12322: foreach my $item (@toggles) {
12323: if ($defaultchecked{$item} eq 'on') {
12324: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12325: ($env{'form.'.$item} eq '0')) {
12326: $changes{$item} = 1;
1.160.6.16 raeburn 12327: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 12328: $changes{$item} = 1;
12329: }
12330: } elsif ($defaultchecked{$item} eq 'off') {
12331: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12332: ($env{'form.'.$item} eq '1')) {
12333: $changes{$item} = 1;
12334: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
12335: $changes{$item} = 1;
12336: }
12337: }
12338: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
12339: }
1.160.6.21 raeburn 12340: foreach my $item (@numbers) {
12341: my ($currdef,$newdef);
1.160.6.26 raeburn 12342: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 12343: if ($item eq 'anonsurvey_threshold') {
12344: $currdef = $domconfig{'coursedefaults'}{$item};
12345: $newdef =~ s/\D//g;
12346: if ($newdef eq '' || $newdef < 1) {
12347: $newdef = 1;
12348: }
12349: $defaultshash{'coursedefaults'}{$item} = $newdef;
12350: } else {
1.160.6.70 raeburn 12351: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
12352: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
12353: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 12354: }
12355: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 12356: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 12357: }
12358: if ($currdef ne $newdef) {
12359: if ($item eq 'anonsurvey_threshold') {
12360: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
12361: $changes{$item} = 1;
12362: }
1.160.6.70 raeburn 12363: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
12364: my $setting = $1;
12365: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
12366: $changes{$setting} = 1;
1.160.6.21 raeburn 12367: }
12368: }
1.139 raeburn 12369: }
12370: }
1.160.6.90 raeburn 12371: my $texengine;
12372: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
12373: $texengine = $env{'form.texengine'};
12374: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
12375: if ($currdef eq '') {
12376: unless ($texengine eq $Apache::lonnet::deftex) {
12377: $changes{'texengine'} = 1;
12378: }
12379: } elsif ($currdef ne $texengine) {
12380: $changes{'texengine'} = 1;
12381: }
12382: }
12383: if ($texengine ne '') {
12384: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
12385: }
1.160.6.64 raeburn 12386: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
12387: my @currclonecode;
12388: if (ref($currclone) eq 'HASH') {
12389: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
12390: @currclonecode = @{$currclone->{'instcode'}};
12391: }
12392: }
12393: my $newclone;
12394: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
12395: $newclone = $env{'form.canclone'};
12396: }
12397: if ($newclone eq 'instcode') {
12398: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
12399: my (%codedefaults,@code_order,@clonecode);
12400: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
12401: \@code_order);
12402: foreach my $item (@code_order) {
12403: if (grep(/^\Q$item\E$/,@newcodes)) {
12404: push(@clonecode,$item);
12405: }
12406: }
12407: if (@clonecode) {
12408: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
12409: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
12410: if (@diffs) {
12411: $changes{'canclone'} = 1;
12412: }
12413: } else {
12414: $newclone eq '';
12415: }
12416: } elsif ($newclone ne '') {
12417: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
12418: }
12419: if ($newclone ne $currclone) {
12420: $changes{'canclone'} = 1;
12421: }
1.160.6.57 raeburn 12422: my %credits;
12423: foreach my $type (@types) {
12424: unless ($type eq 'community') {
12425: $credits{$type} = $env{'form.'.$type.'_credits'};
12426: $credits{$type} =~ s/[^\d.]+//g;
12427: }
12428: }
12429: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
12430: ($env{'form.coursecredits'} eq '1')) {
12431: $changes{'coursecredits'} = 1;
12432: foreach my $type (keys(%credits)) {
12433: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12434: }
12435: } else {
12436: if ($env{'form.coursecredits'} eq '1') {
12437: foreach my $type (@types) {
12438: unless ($type eq 'community') {
12439: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
12440: $changes{'coursecredits'} = 1;
12441: }
12442: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12443: }
12444: }
12445: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12446: foreach my $type (@types) {
12447: unless ($type eq 'community') {
12448: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
12449: $changes{'coursecredits'} = 1;
12450: last;
12451: }
12452: }
12453: }
12454: }
12455: }
12456: if ($env{'form.postsubmit'} eq '1') {
12457: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
12458: my %currtimeout;
12459: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12460: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
12461: $changes{'postsubmit'} = 1;
12462: }
12463: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12464: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
12465: }
12466: } else {
12467: $changes{'postsubmit'} = 1;
12468: }
12469: foreach my $type (@types) {
12470: my $timeout = $env{'form.'.$type.'_timeout'};
12471: $timeout =~ s/\D//g;
12472: if ($timeout == $staticdefaults{'postsubmit'}) {
12473: $timeout = '';
12474: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
12475: $timeout = '0';
12476: }
12477: unless ($timeout eq '') {
12478: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
12479: }
12480: if (exists($currtimeout{$type})) {
12481: if ($timeout ne $currtimeout{$type}) {
12482: $changes{'postsubmit'} = 1;
12483: }
12484: } elsif ($timeout ne '') {
12485: $changes{'postsubmit'} = 1;
12486: }
12487: }
12488: } else {
12489: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
12490: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12491: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
12492: $changes{'postsubmit'} = 1;
12493: }
12494: } else {
12495: $changes{'postsubmit'} = 1;
12496: }
1.160.6.16 raeburn 12497: }
1.121 raeburn 12498: }
12499: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12500: $dom);
12501: if ($putresult eq 'ok') {
12502: if (keys(%changes) > 0) {
1.160.6.27 raeburn 12503: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 12504: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 12505: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90 raeburn 12506: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
12507: foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57 raeburn 12508: if ($changes{$item}) {
12509: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
12510: }
1.160.6.16 raeburn 12511: }
12512: if ($changes{'coursecredits'}) {
12513: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 12514: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
12515: $domdefaults{$type.'credits'} =
12516: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
12517: }
12518: }
12519: }
12520: if ($changes{'postsubmit'}) {
12521: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12522: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
12523: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12524: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
12525: $domdefaults{$type.'postsubtimeout'} =
12526: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12527: }
12528: }
1.160.6.16 raeburn 12529: }
12530: }
1.160.6.21 raeburn 12531: if ($changes{'uploadquota'}) {
12532: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
12533: foreach my $type (@types) {
12534: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
12535: }
12536: }
12537: }
1.160.6.64 raeburn 12538: if ($changes{'canclone'}) {
12539: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12540: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12541: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
12542: if (@clonecodes) {
12543: $domdefaults{'canclone'} = join('+',@clonecodes);
12544: }
12545: }
12546: } else {
12547: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
12548: }
12549: }
1.121 raeburn 12550: my $cachetime = 24*60*60;
12551: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12552: if (ref($lastactref) eq 'HASH') {
12553: $lastactref->{'domdefaults'} = 1;
12554: }
1.121 raeburn 12555: }
12556: $resulttext = &mt('Changes made:').'<ul>';
12557: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 12558: if ($item eq 'uselcmath') {
1.121 raeburn 12559: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 12560: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 12561: } else {
1.160.6.57 raeburn 12562: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
12563: }
12564: } elsif ($item eq 'usejsme') {
12565: if ($env{'form.'.$item} eq '1') {
12566: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
12567: } else {
12568: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 12569: }
1.160.6.90 raeburn 12570: } elsif ($item eq 'texengine') {
12571: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
12572: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
12573: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
12574: }
1.139 raeburn 12575: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 12576: $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 12577: } elsif ($item eq 'uploadquota') {
12578: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
12579: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
12580: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
12581: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 12582: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
12583:
1.160.6.21 raeburn 12584: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
12585: '</ul>'.
12586: '</li>';
12587: } else {
12588: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
12589: }
1.160.6.70 raeburn 12590: } elsif ($item eq 'mysqltables') {
12591: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
12592: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
12593: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
12594: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
12595: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
12596: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
12597: '</ul>'.
12598: '</li>';
12599: } else {
12600: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
12601: }
1.160.6.57 raeburn 12602: } elsif ($item eq 'postsubmit') {
12603: if ($domdefaults{'postsubmit'} eq 'off') {
12604: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
12605: } else {
12606: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
12607: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12608: $resulttext .= &mt('durations:').'<ul>';
12609: foreach my $type (@types) {
12610: $resulttext .= '<li>';
12611: my $timeout;
12612: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12613: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12614: }
12615: my $display;
12616: if ($timeout eq '0') {
12617: $display = &mt('unlimited');
12618: } elsif ($timeout eq '') {
12619: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
12620: } else {
12621: $display = &mt('[quant,_1,second]',$timeout);
12622: }
12623: if ($type eq 'community') {
12624: $resulttext .= &mt('Communities');
12625: } elsif ($type eq 'official') {
12626: $resulttext .= &mt('Official courses');
12627: } elsif ($type eq 'unofficial') {
12628: $resulttext .= &mt('Unofficial courses');
12629: } elsif ($type eq 'textbook') {
12630: $resulttext .= &mt('Textbook courses');
12631: }
12632: $resulttext .= ' -- '.$display.'</li>';
12633: }
12634: $resulttext .= '</ul>';
12635: }
12636: $resulttext .= '</li>';
12637: }
1.160.6.16 raeburn 12638: } elsif ($item eq 'coursecredits') {
12639: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12640: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 12641: ($domdefaults{'unofficialcredits'} eq '') &&
12642: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 12643: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12644: } else {
12645: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
12646: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
12647: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 12648: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 12649: '</ul>'.
12650: '</li>';
12651: }
12652: } else {
12653: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12654: }
1.160.6.64 raeburn 12655: } elsif ($item eq 'canclone') {
12656: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12657: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12658: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
12659: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
12660: }
12661: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
12662: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
12663: } else {
12664: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
12665: }
1.140 raeburn 12666: }
1.121 raeburn 12667: }
12668: $resulttext .= '</ul>';
12669: } else {
12670: $resulttext = &mt('No changes made to course defaults');
12671: }
12672: } else {
12673: $resulttext = '<span class="LC_error">'.
12674: &mt('An error occurred: [_1]',$putresult).'</span>';
12675: }
12676: return $resulttext;
12677: }
12678:
1.160.6.37 raeburn 12679: sub modify_selfenrollment {
12680: my ($dom,$lastactref,%domconfig) = @_;
12681: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
12682: my @types = ('official','unofficial','community','textbook');
12683: my %titles = &tool_titles();
12684: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12685: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
12686: $ordered{'default'} = ['types','registered','approval','limit'];
12687:
12688: my (%roles,%shown,%toplevel);
12689: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12690:
12691: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12692: if ($domconfig{'selfenrollment'} eq '') {
12693: $domconfig{'selfenrollment'} = {};
12694: }
12695: }
12696: %toplevel = (
12697: admin => 'Configuration Rights',
12698: default => 'Default settings',
12699: validation => 'Validation of self-enrollment requests',
12700: );
12701: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
12702:
12703: if (ref($ordered{'admin'}) eq 'ARRAY') {
12704: foreach my $item (@{$ordered{'admin'}}) {
12705: foreach my $type (@types) {
12706: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12707: $selfenrollhash{'admin'}{$type}{$item} = 1;
12708: } else {
12709: $selfenrollhash{'admin'}{$type}{$item} = 0;
12710: }
12711: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12712: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12713: if ($selfenrollhash{'admin'}{$type}{$item} ne
12714: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12715: push(@{$changes{'admin'}{$type}},$item);
12716: }
12717: } else {
12718: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12719: push(@{$changes{'admin'}{$type}},$item);
12720: }
12721: }
12722: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12723: push(@{$changes{'admin'}{$type}},$item);
12724: }
12725: }
12726: }
12727: }
12728:
12729: foreach my $item (@{$ordered{'default'}}) {
12730: foreach my $type (@types) {
12731: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12732: if ($item eq 'types') {
12733: unless (($value eq 'all') || ($value eq 'dom')) {
12734: $value = '';
12735: }
12736: } elsif ($item eq 'registered') {
12737: unless ($value eq '1') {
12738: $value = 0;
12739: }
12740: } elsif ($item eq 'approval') {
12741: unless ($value =~ /^[012]$/) {
12742: $value = 0;
12743: }
12744: } else {
12745: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12746: $value = 'none';
12747: }
12748: }
12749: $selfenrollhash{'default'}{$type}{$item} = $value;
12750: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12751: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12752: if ($selfenrollhash{'default'}{$type}{$item} ne
12753: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12754: push(@{$changes{'default'}{$type}},$item);
12755: }
12756: } else {
12757: push(@{$changes{'default'}{$type}},$item);
12758: }
12759: } else {
12760: push(@{$changes{'default'}{$type}},$item);
12761: }
12762: if ($item eq 'limit') {
12763: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12764: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12765: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12766: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12767: }
12768: } else {
12769: $selfenrollhash{'default'}{$type}{'cap'} = '';
12770: }
12771: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12772: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12773: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12774: push(@{$changes{'default'}{$type}},'cap');
12775: }
12776: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12777: push(@{$changes{'default'}{$type}},'cap');
12778: }
12779: }
12780: }
12781: }
12782:
12783: foreach my $item (@{$itemsref}) {
12784: if ($item eq 'fields') {
12785: my @changed;
12786: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12787: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12788: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12789: }
12790: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12791: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12792: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12793: $domconfig{'selfenrollment'}{'validation'}{$item});
12794: } else {
12795: @changed = @{$selfenrollhash{'validation'}{$item}};
12796: }
12797: } else {
12798: @changed = @{$selfenrollhash{'validation'}{$item}};
12799: }
12800: if (@changed) {
12801: if ($selfenrollhash{'validation'}{$item}) {
12802: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12803: } else {
12804: $changes{'validation'}{$item} = &mt('None');
12805: }
12806: }
12807: } else {
12808: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12809: if ($item eq 'markup') {
12810: if ($env{'form.selfenroll_validation_'.$item}) {
12811: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12812: }
12813: }
12814: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12815: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12816: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12817: }
12818: }
12819: }
12820: }
12821:
12822: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12823: $dom);
12824: if ($putresult eq 'ok') {
12825: if (keys(%changes) > 0) {
12826: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12827: $resulttext = &mt('Changes made:').'<ul>';
12828: foreach my $key ('admin','default','validation') {
12829: if (ref($changes{$key}) eq 'HASH') {
12830: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12831: if ($key eq 'validation') {
12832: foreach my $item (@{$itemsref}) {
12833: if (exists($changes{$key}{$item})) {
12834: if ($item eq 'markup') {
12835: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12836: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12837: } else {
12838: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12839: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12840: }
12841: }
12842: }
12843: } else {
12844: foreach my $type (@types) {
12845: if ($type eq 'community') {
12846: $roles{'1'} = &mt('Community personnel');
12847: } else {
12848: $roles{'1'} = &mt('Course personnel');
12849: }
12850: if (ref($changes{$key}{$type}) eq 'ARRAY') {
12851: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12852: if ($key eq 'admin') {
12853: my @mgrdc = ();
12854: if (ref($ordered{$key}) eq 'ARRAY') {
12855: foreach my $item (@{$ordered{'admin'}}) {
12856: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12857: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12858: push(@mgrdc,$item);
12859: }
12860: }
12861: }
12862: if (@mgrdc) {
12863: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12864: } else {
12865: delete($domdefaults{$type.'selfenrolladmdc'});
12866: }
12867: }
12868: } else {
12869: if (ref($ordered{$key}) eq 'ARRAY') {
12870: foreach my $item (@{$ordered{$key}}) {
12871: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12872: $domdefaults{$type.'selfenroll'.$item} =
12873: $selfenrollhash{$key}{$type}{$item};
12874: }
12875: }
12876: }
12877: }
12878: }
12879: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12880: foreach my $item (@{$ordered{$key}}) {
12881: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12882: $resulttext .= '<li>';
12883: if ($key eq 'admin') {
12884: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12885: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12886: } else {
12887: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12888: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12889: }
12890: $resulttext .= '</li>';
12891: }
12892: }
12893: $resulttext .= '</ul></li>';
12894: }
12895: }
12896: $resulttext .= '</ul></li>';
12897: }
12898: }
1.160.6.93 raeburn 12899: }
12900: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12901: my $cachetime = 24*60*60;
12902: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12903: if (ref($lastactref) eq 'HASH') {
12904: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 12905: }
12906: }
12907: $resulttext .= '</ul>';
12908: } else {
12909: $resulttext = &mt('No changes made to self-enrollment settings');
12910: }
12911: } else {
12912: $resulttext = '<span class="LC_error">'.
12913: &mt('An error occurred: [_1]',$putresult).'</span>';
12914: }
12915: return $resulttext;
12916: }
12917:
1.137 raeburn 12918: sub modify_usersessions {
1.160.6.27 raeburn 12919: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12920: my @hostingtypes = ('version','excludedomain','includedomain');
12921: my @offloadtypes = ('primary','default');
12922: my %types = (
12923: remote => \@hostingtypes,
12924: hosted => \@hostingtypes,
12925: spares => \@offloadtypes,
12926: );
12927: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12928: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 12929: my (%by_ip,%by_location,@intdoms);
12930: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
12931: my @locations = sort(keys(%by_location));
1.137 raeburn 12932: my (%defaultshash,%changes);
12933: foreach my $prefix (@prefixes) {
12934: $defaultshash{'usersessions'}{$prefix} = {};
12935: }
1.160.6.27 raeburn 12936: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12937: my $resulttext;
1.138 raeburn 12938: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12939: foreach my $prefix (@prefixes) {
1.145 raeburn 12940: next if ($prefix eq 'spares');
12941: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12942: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12943: if ($type eq 'version') {
12944: my $value = $env{'form.'.$prefix.'_'.$type};
12945: my $okvalue;
12946: if ($value ne '') {
12947: if (grep(/^\Q$value\E$/,@lcversions)) {
12948: $okvalue = $value;
12949: }
12950: }
12951: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12952: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12953: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12954: if ($inuse == 0) {
12955: $changes{$prefix}{$type} = 1;
12956: } else {
12957: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12958: $changes{$prefix}{$type} = 1;
12959: }
12960: if ($okvalue ne '') {
12961: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12962: }
12963: }
12964: } else {
12965: if (($inuse == 1) && ($okvalue ne '')) {
12966: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12967: $changes{$prefix}{$type} = 1;
12968: }
12969: }
12970: } else {
12971: if (($inuse == 1) && ($okvalue ne '')) {
12972: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12973: $changes{$prefix}{$type} = 1;
12974: }
12975: }
12976: } else {
12977: if (($inuse == 1) && ($okvalue ne '')) {
12978: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12979: $changes{$prefix}{$type} = 1;
12980: }
12981: }
12982: } else {
12983: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12984: my @okvals;
12985: foreach my $val (@vals) {
1.138 raeburn 12986: if ($val =~ /:/) {
12987: my @items = split(/:/,$val);
12988: foreach my $item (@items) {
12989: if (ref($by_location{$item}) eq 'ARRAY') {
12990: push(@okvals,$item);
12991: }
12992: }
12993: } else {
12994: if (ref($by_location{$val}) eq 'ARRAY') {
12995: push(@okvals,$val);
12996: }
1.137 raeburn 12997: }
12998: }
12999: @okvals = sort(@okvals);
13000: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13001: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
13002: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13003: if ($inuse == 0) {
13004: $changes{$prefix}{$type} = 1;
13005: } else {
13006: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13007: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
13008: if (@changed > 0) {
13009: $changes{$prefix}{$type} = 1;
13010: }
13011: }
13012: } else {
13013: if ($inuse == 1) {
13014: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13015: $changes{$prefix}{$type} = 1;
13016: }
13017: }
13018: } else {
13019: if ($inuse == 1) {
13020: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13021: $changes{$prefix}{$type} = 1;
13022: }
13023: }
13024: } else {
13025: if ($inuse == 1) {
13026: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
13027: $changes{$prefix}{$type} = 1;
13028: }
13029: }
13030: }
13031: }
13032: }
1.145 raeburn 13033:
13034: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 13035: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 13036: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
13037: my $savespares;
13038:
13039: foreach my $lonhost (sort(keys(%servers))) {
13040: my $serverhomeID =
13041: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 13042: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 13043: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
13044: my %spareschg;
13045: foreach my $type (@{$types{'spares'}}) {
13046: my @okspares;
13047: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
13048: foreach my $server (@checked) {
1.152 raeburn 13049: if (&Apache::lonnet::hostname($server) ne '') {
13050: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
13051: unless (grep(/^\Q$server\E$/,@okspares)) {
13052: push(@okspares,$server);
13053: }
1.145 raeburn 13054: }
13055: }
13056: }
13057: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
13058: my $newspare;
1.152 raeburn 13059: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
13060: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 13061: $newspare = $new;
13062: }
13063: }
1.152 raeburn 13064: my @spares;
13065: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
13066: @spares = sort(@okspares,$newspare);
13067: } else {
13068: @spares = sort(@okspares);
13069: }
13070: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 13071: if (ref($spareid{$lonhost}) eq 'HASH') {
13072: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 13073: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 13074: if (@diffs > 0) {
13075: $spareschg{$type} = 1;
13076: }
13077: }
13078: }
13079: }
13080: if (keys(%spareschg) > 0) {
13081: $changes{'spares'}{$lonhost} = \%spareschg;
13082: }
13083: }
1.160.6.61 raeburn 13084: $defaultshash{'usersessions'}{'offloadnow'} = {};
13085: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
13086: my @okoffload;
13087: if (@offloadnow) {
13088: foreach my $server (@offloadnow) {
13089: if (&Apache::lonnet::hostname($server) ne '') {
13090: unless (grep(/^\Q$server\E$/,@okoffload)) {
13091: push(@okoffload,$server);
13092: }
13093: }
13094: }
13095: if (@okoffload) {
13096: foreach my $lonhost (@okoffload) {
13097: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13098: }
13099: }
13100: }
1.145 raeburn 13101: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13102: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13103: if (ref($changes{'spares'}) eq 'HASH') {
13104: if (keys(%{$changes{'spares'}}) > 0) {
13105: $savespares = 1;
13106: }
13107: }
13108: } else {
13109: $savespares = 1;
13110: }
1.160.6.61 raeburn 13111: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13112: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13113: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13114: $changes{'offloadnow'} = 1;
13115: last;
13116: }
13117: }
13118: unless ($changes{'offloadnow'}) {
13119: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
13120: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13121: $changes{'offloadnow'} = 1;
13122: last;
13123: }
13124: }
13125: }
13126: } elsif (@okoffload) {
13127: $changes{'offloadnow'} = 1;
13128: }
13129: } elsif (@okoffload) {
13130: $changes{'offloadnow'} = 1;
1.145 raeburn 13131: }
1.147 raeburn 13132: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13133: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13134: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13135: $dom);
13136: if ($putresult eq 'ok') {
13137: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13138: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13139: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13140: }
13141: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13142: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13143: }
1.160.6.61 raeburn 13144: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13145: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13146: }
1.137 raeburn 13147: }
13148: my $cachetime = 24*60*60;
13149: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 13150: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 13151: if (ref($lastactref) eq 'HASH') {
13152: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 13153: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 13154: }
1.147 raeburn 13155: if (keys(%changes) > 0) {
13156: my %lt = &usersession_titles();
13157: $resulttext = &mt('Changes made:').'<ul>';
13158: foreach my $prefix (@prefixes) {
13159: if (ref($changes{$prefix}) eq 'HASH') {
13160: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13161: if ($prefix eq 'spares') {
13162: if (ref($changes{$prefix}) eq 'HASH') {
13163: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13164: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13165: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 13166: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13167: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13168: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13169: foreach my $type (@{$types{$prefix}}) {
13170: if ($changes{$prefix}{$lonhost}{$type}) {
13171: my $offloadto = &mt('None');
13172: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13173: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13174: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13175: }
1.145 raeburn 13176: }
1.147 raeburn 13177: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13178: }
1.137 raeburn 13179: }
13180: }
1.147 raeburn 13181: $resulttext .= '</li>';
1.137 raeburn 13182: }
13183: }
1.147 raeburn 13184: } else {
13185: foreach my $type (@{$types{$prefix}}) {
13186: if (defined($changes{$prefix}{$type})) {
13187: my $newvalue;
13188: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13189: if (ref($defaultshash{'usersessions'}{$prefix})) {
13190: if ($type eq 'version') {
13191: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13192: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13193: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13194: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13195: }
1.145 raeburn 13196: }
13197: }
13198: }
1.147 raeburn 13199: if ($newvalue eq '') {
13200: if ($type eq 'version') {
13201: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13202: } else {
13203: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13204: }
1.145 raeburn 13205: } else {
1.147 raeburn 13206: if ($type eq 'version') {
13207: $newvalue .= ' '.&mt('(or later)');
13208: }
13209: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13210: }
1.137 raeburn 13211: }
13212: }
13213: }
1.147 raeburn 13214: $resulttext .= '</ul>';
1.137 raeburn 13215: }
13216: }
1.160.6.61 raeburn 13217: if ($changes{'offloadnow'}) {
13218: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13219: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13220: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13221: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13222: $resulttext .= '<li>'.$lonhost.'</li>';
13223: }
13224: $resulttext .= '</ul>';
13225: } else {
13226: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13227: }
13228: } else {
13229: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13230: }
13231: }
1.147 raeburn 13232: $resulttext .= '</ul>';
13233: } else {
13234: $resulttext = $nochgmsg;
1.137 raeburn 13235: }
13236: } else {
13237: $resulttext = '<span class="LC_error">'.
13238: &mt('An error occurred: [_1]',$putresult).'</span>';
13239: }
13240: } else {
1.147 raeburn 13241: $resulttext = $nochgmsg;
1.137 raeburn 13242: }
13243: return $resulttext;
13244: }
13245:
1.150 raeburn 13246: sub modify_loadbalancing {
13247: my ($dom,%domconfig) = @_;
13248: my $primary_id = &Apache::lonnet::domain($dom,'primary');
13249: my $intdom = &Apache::lonnet::internet_dom($primary_id);
13250: my ($othertitle,$usertypes,$types) =
13251: &Apache::loncommon::sorted_inst_types($dom);
13252: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 13253: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 13254: my @sparestypes = ('primary','default');
13255: my %typetitles = &sparestype_titles();
13256: my $resulttext;
1.160.6.94 raeburn 13257: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 13258: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13259: %existing = %{$domconfig{'loadbalancing'}};
13260: }
13261: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 13262: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 13263: my ($saveloadbalancing,%defaultshash,%changes);
13264: my ($alltypes,$othertypes,$titles) =
13265: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
13266: my %ruletitles = &offloadtype_text();
13267: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
13268: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
13269: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
13270: if ($balancer eq '') {
13271: next;
13272: }
13273: if (!exists($servers{$balancer})) {
13274: if (exists($currbalancer{$balancer})) {
13275: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 13276: }
1.160.6.7 raeburn 13277: next;
13278: }
13279: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
13280: push(@{$changes{'delete'}},$balancer);
13281: next;
13282: }
13283: if (!exists($currbalancer{$balancer})) {
13284: push(@{$changes{'add'}},$balancer);
13285: }
13286: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
13287: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
13288: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
13289: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13290: $saveloadbalancing = 1;
13291: }
13292: foreach my $sparetype (@sparestypes) {
13293: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
13294: my @offloadto;
13295: foreach my $target (@targets) {
13296: if (($servers{$target}) && ($target ne $balancer)) {
13297: if ($sparetype eq 'default') {
13298: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
13299: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 13300: }
13301: }
1.160.6.7 raeburn 13302: unless(grep(/^\Q$target\E$/,@offloadto)) {
13303: push(@offloadto,$target);
13304: }
1.150 raeburn 13305: }
13306: }
1.160.6.76 raeburn 13307: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
13308: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
13309: push(@offloadto,$balancer);
13310: }
13311: }
13312: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 13313: }
1.160.6.94 raeburn 13314: if ($env{'form.loadbalancing_cookie_'.$i}) {
13315: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
13316: if (exists($currbalancer{$balancer})) {
13317: unless ($currcookies{$balancer}) {
13318: $changes{'curr'}{$balancer}{'cookie'} = 1;
13319: }
13320: }
13321: } elsif (exists($currbalancer{$balancer})) {
13322: if ($currcookies{$balancer}) {
13323: $changes{'curr'}{$balancer}{'cookie'} = 1;
13324: }
13325: }
1.160.6.7 raeburn 13326: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 13327: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 13328: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
13329: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 13330: if (@targetdiffs > 0) {
1.160.6.7 raeburn 13331: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13332: }
1.160.6.7 raeburn 13333: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13334: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13335: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13336: }
13337: }
13338: }
13339: } else {
1.160.6.7 raeburn 13340: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
13341: foreach my $sparetype (@sparestypes) {
13342: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13343: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13344: $changes{'curr'}{$balancer}{'targets'} = 1;
13345: }
1.150 raeburn 13346: }
13347: }
1.160.6.7 raeburn 13348: }
1.150 raeburn 13349: }
13350: my $ishomedom;
1.160.6.7 raeburn 13351: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
13352: $ishomedom = 1;
1.150 raeburn 13353: }
13354: if (ref($alltypes) eq 'ARRAY') {
13355: foreach my $type (@{$alltypes}) {
13356: my $rule;
1.160.6.7 raeburn 13357: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 13358: (!$ishomedom)) {
1.160.6.7 raeburn 13359: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
13360: }
13361: if ($rule eq 'specific') {
1.160.6.55 raeburn 13362: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
13363: if (exists($servers{$specifiedhost})) {
13364: $rule = $specifiedhost;
13365: }
1.150 raeburn 13366: }
1.160.6.7 raeburn 13367: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
13368: if (ref($currrules{$balancer}) eq 'HASH') {
13369: if ($rule ne $currrules{$balancer}{$type}) {
13370: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13371: }
13372: } elsif ($rule ne '') {
1.160.6.7 raeburn 13373: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13374: }
13375: }
13376: }
1.160.6.7 raeburn 13377: }
13378: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
13379: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
13380: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
13381: $defaultshash{'loadbalancing'} = {};
13382: }
13383: my $putresult = &Apache::lonnet::put_dom('configuration',
13384: \%defaultshash,$dom);
13385: if ($putresult eq 'ok') {
13386: if (keys(%changes) > 0) {
1.160.6.54 raeburn 13387: my %toupdate;
1.160.6.7 raeburn 13388: if (ref($changes{'delete'}) eq 'ARRAY') {
13389: foreach my $balancer (sort(@{$changes{'delete'}})) {
13390: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 13391: $toupdate{$balancer} = 1;
1.150 raeburn 13392: }
1.160.6.7 raeburn 13393: }
13394: if (ref($changes{'add'}) eq 'ARRAY') {
13395: foreach my $balancer (sort(@{$changes{'add'}})) {
13396: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 13397: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 13398: }
13399: }
13400: if (ref($changes{'curr'}) eq 'HASH') {
13401: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 13402: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 13403: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
13404: if ($changes{'curr'}{$balancer}{'targets'}) {
13405: my %offloadstr;
13406: foreach my $sparetype (@sparestypes) {
13407: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13408: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13409: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13410: }
13411: }
1.150 raeburn 13412: }
1.160.6.7 raeburn 13413: if (keys(%offloadstr) == 0) {
13414: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 13415: } else {
1.160.6.7 raeburn 13416: my $showoffload;
13417: foreach my $sparetype (@sparestypes) {
13418: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
13419: if (defined($offloadstr{$sparetype})) {
13420: $showoffload .= $offloadstr{$sparetype};
13421: } else {
13422: $showoffload .= &mt('None');
13423: }
13424: $showoffload .= (' 'x3);
13425: }
13426: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 13427: }
13428: }
13429: }
1.160.6.7 raeburn 13430: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
13431: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
13432: foreach my $type (@{$alltypes}) {
13433: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
13434: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13435: my $balancetext;
13436: if ($rule eq '') {
13437: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 13438: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 13439: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
13440: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 13441: foreach my $sparetype (@sparestypes) {
13442: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13443: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13444: }
13445: }
1.160.6.55 raeburn 13446: foreach my $item (@{$alltypes}) {
13447: next if ($item =~ /^_LC_ipchange/);
13448: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
13449: if ($hasrule eq 'homeserver') {
13450: map { $toupdate{$_} = 1; } (keys(%libraryservers));
13451: } else {
13452: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
13453: if ($servers{$hasrule}) {
13454: $toupdate{$hasrule} = 1;
13455: }
13456: }
13457: }
13458: }
13459: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
13460: $balancetext = $ruletitles{$rule};
13461: } else {
13462: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13463: $balancetext = $ruletitles{'particular'}.' '.$receiver;
13464: if ($receiver) {
13465: $toupdate{$receiver};
13466: }
13467: }
13468: } else {
13469: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 13470: }
1.160.6.7 raeburn 13471: } else {
13472: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
13473: }
1.160.6.26 raeburn 13474: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 13475: }
13476: }
13477: }
13478: }
1.160.6.94 raeburn 13479: if ($changes{'curr'}{$balancer}{'cookie'}) {
13480: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
13481: $balancer).'</li>';
13482: }
1.160.6.54 raeburn 13483: if (keys(%toupdate)) {
13484: my %thismachine;
13485: my $updatedhere;
13486: my $cachetime = 60*60*24;
13487: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
13488: foreach my $lonhost (keys(%toupdate)) {
13489: if ($thismachine{$lonhost}) {
13490: unless ($updatedhere) {
13491: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
13492: $defaultshash{'loadbalancing'},
13493: $cachetime);
13494: $updatedhere = 1;
13495: }
13496: } else {
13497: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
13498: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
13499: }
13500: }
13501: }
1.150 raeburn 13502: }
1.160.6.7 raeburn 13503: }
13504: if ($resulttext ne '') {
13505: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 13506: } else {
13507: $resulttext = $nochgmsg;
13508: }
13509: } else {
1.160.6.7 raeburn 13510: $resulttext = $nochgmsg;
1.150 raeburn 13511: }
13512: } else {
1.160.6.7 raeburn 13513: $resulttext = '<span class="LC_error">'.
13514: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 13515: }
13516: } else {
1.160.6.7 raeburn 13517: $resulttext = $nochgmsg;
1.150 raeburn 13518: }
13519: return $resulttext;
13520: }
13521:
1.48 raeburn 13522: sub recurse_check {
13523: my ($chkcats,$categories,$depth,$name) = @_;
13524: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
13525: my $chg = 0;
13526: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
13527: my $category = $chkcats->[$depth]{$name}[$j];
13528: my $item;
13529: if ($category eq '') {
13530: $chg ++;
13531: } else {
13532: my $deeper = $depth + 1;
13533: $item = &escape($category).':'.&escape($name).':'.$depth;
13534: if ($chg) {
13535: $categories->{$item} -= $chg;
13536: }
13537: &recurse_check($chkcats,$categories,$deeper,$category);
13538: $deeper --;
13539: }
13540: }
13541: }
13542: return;
13543: }
13544:
13545: sub recurse_cat_deletes {
13546: my ($item,$coursecategories,$deletions) = @_;
13547: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13548: my $subdepth = $depth + 1;
13549: if (ref($coursecategories) eq 'HASH') {
13550: foreach my $subitem (keys(%{$coursecategories})) {
13551: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
13552: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
13553: delete($coursecategories->{$subitem});
13554: $deletions->{$subitem} = 1;
13555: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 13556: }
1.48 raeburn 13557: }
13558: }
13559: return;
13560: }
13561:
1.125 raeburn 13562: sub active_dc_picker {
1.160.6.16 raeburn 13563: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 13564: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 13565: my @domcoord = keys(%domcoords);
13566: if (keys(%currhash)) {
13567: foreach my $dc (keys(%currhash)) {
13568: unless (exists($domcoords{$dc})) {
13569: push(@domcoord,$dc);
13570: }
13571: }
13572: }
13573: @domcoord = sort(@domcoord);
13574: my $numdcs = scalar(@domcoord);
13575: my $rows = 0;
13576: my $table;
1.125 raeburn 13577: if ($numdcs > 1) {
1.160.6.16 raeburn 13578: $table = '<table>';
13579: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 13580: my $rem = $i%($numinrow);
13581: if ($rem == 0) {
13582: if ($i > 0) {
1.160.6.16 raeburn 13583: $table .= '</tr>';
1.125 raeburn 13584: }
1.160.6.16 raeburn 13585: $table .= '<tr>';
13586: $rows ++;
1.125 raeburn 13587: }
1.160.6.16 raeburn 13588: my $check = '';
13589: if ($inputtype eq 'radio') {
13590: if (keys(%currhash) == 0) {
13591: if (!$i) {
13592: $check = ' checked="checked"';
13593: }
13594: } elsif (exists($currhash{$domcoord[$i]})) {
13595: $check = ' checked="checked"';
13596: }
13597: } else {
13598: if (exists($currhash{$domcoord[$i]})) {
13599: $check = ' checked="checked"';
1.125 raeburn 13600: }
13601: }
1.160.6.16 raeburn 13602: if ($i == @domcoord - 1) {
1.125 raeburn 13603: my $colsleft = $numinrow - $rem;
13604: if ($colsleft > 1) {
1.160.6.16 raeburn 13605: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 13606: } else {
1.160.6.16 raeburn 13607: $table .= '<td class="LC_left_item">';
1.125 raeburn 13608: }
13609: } else {
1.160.6.16 raeburn 13610: $table .= '<td class="LC_left_item">';
13611: }
13612: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
13613: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
13614: $table .= '<span class="LC_nobreak"><label>'.
13615: '<input type="'.$inputtype.'" name="'.$name.'"'.
13616: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
13617: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 13618: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 13619: }
1.160.6.33 raeburn 13620: $table .= '</label></span></td>';
1.125 raeburn 13621: }
1.160.6.16 raeburn 13622: $table .= '</tr></table>';
13623: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 13624: my ($dcname,$dcdom) = split(':',$domcoord[0]);
13625: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 13626: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 13627: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 13628: if ($user ne $dcname.':'.$dcdom) {
13629: $table .= ' ('.$dcname.':'.$dcdom.')';
13630: }
1.160.6.16 raeburn 13631: } else {
13632: my $check;
13633: if (exists($currhash{$domcoord[0]})) {
13634: $check = ' checked="checked"';
13635: }
1.160.6.50 raeburn 13636: $table = '<span class="LC_nobreak"><label>'.
13637: '<input type="checkbox" name="'.$name.'" '.
13638: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 13639: if ($user ne $dcname.':'.$dcdom) {
13640: $table .= ' ('.$dcname.':'.$dcdom.')';
13641: }
13642: $table .= '</label></span>';
1.160.6.16 raeburn 13643: $rows ++;
13644: }
1.125 raeburn 13645: }
1.160.6.16 raeburn 13646: return ($numdcs,$table,$rows);
1.125 raeburn 13647: }
13648:
1.137 raeburn 13649: sub usersession_titles {
13650: return &Apache::lonlocal::texthash(
13651: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
13652: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 13653: spares => 'Servers offloaded to, when busy',
1.137 raeburn 13654: version => 'LON-CAPA version requirement',
1.138 raeburn 13655: excludedomain => 'Allow all, but exclude specific domains',
13656: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 13657: primary => 'Primary (checked first)',
1.154 raeburn 13658: default => 'Default',
1.137 raeburn 13659: );
13660: }
13661:
1.152 raeburn 13662: sub id_for_thisdom {
13663: my (%servers) = @_;
13664: my %altids;
13665: foreach my $server (keys(%servers)) {
13666: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
13667: if ($serverhome ne $server) {
13668: $altids{$serverhome} = $server;
13669: }
13670: }
13671: return %altids;
13672: }
13673:
1.150 raeburn 13674: sub count_servers {
13675: my ($currbalancer,%servers) = @_;
13676: my (@spares,$numspares);
13677: foreach my $lonhost (sort(keys(%servers))) {
13678: next if ($currbalancer eq $lonhost);
13679: push(@spares,$lonhost);
13680: }
13681: if ($currbalancer) {
13682: $numspares = scalar(@spares);
13683: } else {
13684: $numspares = scalar(@spares) - 1;
13685: }
13686: return ($numspares,@spares);
13687: }
13688:
13689: sub lonbalance_targets_js {
1.160.6.7 raeburn 13690: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13691: my $select = &mt('Select');
13692: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13693: if (ref($servers) eq 'HASH') {
13694: $alltargets = join("','",sort(keys(%{$servers})));
13695: my @homedoms;
13696: foreach my $server (sort(keys(%{$servers}))) {
13697: if (&Apache::lonnet::host_domain($server) eq $dom) {
13698: push(@homedoms,'1');
13699: } else {
13700: push(@homedoms,'0');
13701: }
13702: }
13703: $allishome = join("','",@homedoms);
13704: }
13705: if (ref($types) eq 'ARRAY') {
13706: if (@{$types} > 0) {
13707: @alltypes = @{$types};
13708: }
13709: }
13710: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13711: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 13712: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 13713: if (ref($settings) eq 'HASH') {
13714: %existing = %{$settings};
13715: }
13716: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 13717: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 13718: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13719: return <<"END";
13720:
13721: <script type="text/javascript">
13722: // <![CDATA[
13723:
1.160.6.7 raeburn 13724: currBalancers = new Array('$balancers');
13725:
13726: function toggleTargets(balnum) {
13727: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13728: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13729: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13730: var prevbalancer = prevhostitem.value;
13731: var baltotal = document.getElementById('loadbalancing_total').value;
13732: prevhostitem.value = balancer;
13733: if (prevbalancer != '') {
13734: var prevIdx = currBalancers.indexOf(prevbalancer);
13735: if (prevIdx != -1) {
13736: currBalancers.splice(prevIdx,1);
13737: }
13738: }
1.150 raeburn 13739: if (balancer == '') {
1.160.6.7 raeburn 13740: hideSpares(balnum);
1.150 raeburn 13741: } else {
1.160.6.7 raeburn 13742: var currIdx = currBalancers.indexOf(balancer);
13743: if (currIdx == -1) {
13744: currBalancers.push(balancer);
13745: }
1.150 raeburn 13746: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 13747: var ishomedom = homedoms[lonhostitem.selectedIndex];
13748: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13749: }
1.160.6.7 raeburn 13750: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13751: return;
13752: }
13753:
1.160.6.7 raeburn 13754: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13755: var alltargets = new Array('$alltargets');
13756: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13757: var offloadtypes = new Array('primary','default');
13758:
1.160.6.7 raeburn 13759: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13760: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13761:
1.151 raeburn 13762: for (var i=0; i<offloadtypes.length; i++) {
13763: var count = 0;
13764: for (var j=0; j<alltargets.length; j++) {
13765: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 13766: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13767: item.value = alltargets[j];
13768: item.style.textAlign='left';
13769: item.style.textFace='normal';
13770: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13771: if (currBalancers.indexOf(alltargets[j]) == -1) {
13772: item.disabled = '';
13773: } else {
13774: item.disabled = 'disabled';
13775: item.checked = false;
13776: }
1.151 raeburn 13777: count ++;
13778: }
1.150 raeburn 13779: }
13780: }
1.151 raeburn 13781: for (var k=0; k<insttypes.length; k++) {
13782: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13783: if (ishomedom == 1) {
1.160.6.7 raeburn 13784: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13785: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13786: } else {
1.160.6.7 raeburn 13787: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13788: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13789: }
13790: } else {
1.160.6.7 raeburn 13791: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13792: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13793: }
1.151 raeburn 13794: if ((insttypes[k] != '_LC_external') &&
13795: ((insttypes[k] != '_LC_internetdom') ||
13796: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 13797: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13798: item.options.length = 0;
13799: item.options[0] = new Option("","",true,true);
13800: var idx = 0;
1.151 raeburn 13801: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 13802: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13803: idx ++;
13804: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13805: }
13806: }
13807: }
13808: }
13809: return;
13810: }
13811:
1.160.6.7 raeburn 13812: function hideSpares(balnum) {
1.150 raeburn 13813: var alltargets = new Array('$alltargets');
13814: var insttypes = new Array('$allinsttypes');
13815: var offloadtypes = new Array('primary','default');
13816:
1.160.6.7 raeburn 13817: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13818: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13819:
13820: var total = alltargets.length - 1;
13821: for (var i=0; i<offloadtypes; i++) {
13822: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 13823: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13824: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13825: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13826: }
1.150 raeburn 13827: }
13828: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 13829: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13830: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13831: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 13832: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13833: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13834: }
13835: }
13836: return;
13837: }
13838:
1.160.6.7 raeburn 13839: function checkOffloads(item,balnum,type) {
1.150 raeburn 13840: var alltargets = new Array('$alltargets');
13841: var offloadtypes = new Array('primary','default');
13842: if (item.checked) {
13843: var total = alltargets.length - 1;
13844: var other;
13845: if (type == offloadtypes[0]) {
1.151 raeburn 13846: other = offloadtypes[1];
1.150 raeburn 13847: } else {
1.151 raeburn 13848: other = offloadtypes[0];
1.150 raeburn 13849: }
13850: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 13851: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13852: if (server == item.value) {
1.160.6.7 raeburn 13853: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13854: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13855: }
13856: }
13857: }
13858: }
13859: return;
13860: }
13861:
1.160.6.7 raeburn 13862: function singleServerToggle(balnum,type) {
13863: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13864: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 13865: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13866: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13867:
13868: } else {
1.160.6.7 raeburn 13869: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13870: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13871: }
13872: return;
13873: }
13874:
1.160.6.7 raeburn 13875: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13876: if (type == '_LC_external') {
1.160.6.26 raeburn 13877: return;
1.150 raeburn 13878: }
1.160.6.7 raeburn 13879: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13880: for (var i=0; i<typesRules.length; i++) {
13881: if (formname.elements[typesRules[i]].checked) {
13882: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 13883: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13884: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13885: } else {
1.160.6.7 raeburn 13886: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13887: }
13888: }
13889: }
13890: return;
13891: }
13892:
13893: function balancerDeleteChange(balnum) {
13894: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13895: var baltotal = document.getElementById('loadbalancing_total').value;
13896: var addtarget;
13897: var removetarget;
13898: var action = 'delete';
13899: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13900: var lonhost = hostitem.value;
13901: var currIdx = currBalancers.indexOf(lonhost);
13902: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13903: if (currIdx != -1) {
13904: currBalancers.splice(currIdx,1);
13905: }
13906: addtarget = lonhost;
13907: } else {
13908: if (currIdx == -1) {
13909: currBalancers.push(lonhost);
13910: }
13911: removetarget = lonhost;
13912: action = 'undelete';
13913: }
13914: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13915: }
13916: return;
13917: }
13918:
13919: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13920: if (baltotal > 1) {
13921: var offloadtypes = new Array('primary','default');
13922: var alltargets = new Array('$alltargets');
13923: var insttypes = new Array('$allinsttypes');
13924: for (var i=0; i<baltotal; i++) {
13925: if (i != balnum) {
13926: for (var j=0; j<offloadtypes.length; j++) {
13927: var total = alltargets.length - 1;
13928: for (var k=0; k<total; k++) {
13929: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13930: var server = serveritem.value;
13931: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13932: if (server == addtarget) {
13933: serveritem.disabled = '';
13934: }
13935: }
13936: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13937: if (server == removetarget) {
13938: serveritem.disabled = 'disabled';
13939: serveritem.checked = false;
13940: }
13941: }
13942: }
13943: }
13944: for (var j=0; j<insttypes.length; j++) {
13945: if (insttypes[j] != '_LC_external') {
13946: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13947: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13948: var currSel = singleserver.selectedIndex;
13949: var currVal = singleserver.options[currSel].value;
13950: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13951: var numoptions = singleserver.options.length;
13952: var needsnew = 1;
13953: for (var k=0; k<numoptions; k++) {
13954: if (singleserver.options[k] == addtarget) {
13955: needsnew = 0;
13956: break;
13957: }
13958: }
13959: if (needsnew == 1) {
13960: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13961: }
13962: }
13963: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13964: singleserver.options.length = 0;
13965: if ((currVal) && (currVal != removetarget)) {
13966: singleserver.options[0] = new Option("","",false,false);
13967: } else {
13968: singleserver.options[0] = new Option("","",true,true);
13969: }
13970: var idx = 0;
13971: for (var m=0; m<alltargets.length; m++) {
13972: if (currBalancers.indexOf(alltargets[m]) == -1) {
13973: idx ++;
13974: if (currVal == alltargets[m]) {
13975: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13976: } else {
13977: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13978: }
13979: }
13980: }
13981: }
13982: }
13983: }
13984: }
1.150 raeburn 13985: }
13986: }
13987: }
13988: return;
13989: }
13990:
1.152 raeburn 13991: // ]]>
13992: </script>
13993:
13994: END
13995: }
13996:
13997: sub new_spares_js {
13998: my @sparestypes = ('primary','default');
13999: my $types = join("','",@sparestypes);
14000: my $select = &mt('Select');
14001: return <<"END";
14002:
14003: <script type="text/javascript">
14004: // <![CDATA[
14005:
14006: function updateNewSpares(formname,lonhost) {
14007: var types = new Array('$types');
14008: var include = new Array();
14009: var exclude = new Array();
14010: for (var i=0; i<types.length; i++) {
14011: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
14012: for (var j=0; j<spareboxes.length; j++) {
14013: if (formname.elements[spareboxes[j]].checked) {
14014: exclude.push(formname.elements[spareboxes[j]].value);
14015: } else {
14016: include.push(formname.elements[spareboxes[j]].value);
14017: }
14018: }
14019: }
14020: for (var i=0; i<types.length; i++) {
14021: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
14022: var selIdx = newSpare.selectedIndex;
14023: var currnew = newSpare.options[selIdx].value;
14024: var okSpares = new Array();
14025: for (var j=0; j<newSpare.options.length; j++) {
14026: var possible = newSpare.options[j].value;
14027: if (possible != '') {
14028: if (exclude.indexOf(possible) == -1) {
14029: okSpares.push(possible);
14030: } else {
14031: if (currnew == possible) {
14032: selIdx = 0;
14033: }
14034: }
14035: }
14036: }
14037: for (var k=0; k<include.length; k++) {
14038: if (okSpares.indexOf(include[k]) == -1) {
14039: okSpares.push(include[k]);
14040: }
14041: }
14042: okSpares.sort();
14043: newSpare.options.length = 0;
14044: if (selIdx == 0) {
14045: newSpare.options[0] = new Option("$select","",true,true);
14046: } else {
14047: newSpare.options[0] = new Option("$select","",false,false);
14048: }
14049: for (var m=0; m<okSpares.length; m++) {
14050: var idx = m+1;
14051: var selThis = 0;
14052: if (selIdx != 0) {
14053: if (okSpares[m] == currnew) {
14054: selThis = 1;
14055: }
14056: }
14057: if (selThis == 1) {
14058: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
14059: } else {
14060: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
14061: }
14062: }
14063: }
14064: return;
14065: }
14066:
14067: function checkNewSpares(lonhost,type) {
14068: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
14069: var chosen = newSpare.options[newSpare.selectedIndex].value;
14070: if (chosen != '') {
14071: var othertype;
14072: var othernewSpare;
14073: if (type == 'primary') {
14074: othernewSpare = document.getElementById('newspare_default_'+lonhost);
14075: }
14076: if (type == 'default') {
14077: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
14078: }
14079: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
14080: othernewSpare.selectedIndex = 0;
14081: }
14082: }
14083: return;
14084: }
14085:
14086: // ]]>
14087: </script>
14088:
14089: END
14090:
14091: }
14092:
14093: sub common_domprefs_js {
14094: return <<"END";
14095:
14096: <script type="text/javascript">
14097: // <![CDATA[
14098:
1.150 raeburn 14099: function getIndicesByName(formname,item) {
1.152 raeburn 14100: var group = new Array();
1.150 raeburn 14101: for (var i=0;i<formname.elements.length;i++) {
14102: if (formname.elements[i].name == item) {
1.152 raeburn 14103: group.push(formname.elements[i].id);
1.150 raeburn 14104: }
14105: }
1.152 raeburn 14106: return group;
1.150 raeburn 14107: }
14108:
14109: // ]]>
14110: </script>
14111:
14112: END
1.152 raeburn 14113:
1.150 raeburn 14114: }
14115:
1.160.6.5 raeburn 14116: sub recaptcha_js {
14117: my %lt = &captcha_phrases();
14118: return <<"END";
14119:
14120: <script type="text/javascript">
14121: // <![CDATA[
14122:
14123: function updateCaptcha(caller,context) {
14124: var privitem;
14125: var pubitem;
14126: var privtext;
14127: var pubtext;
1.160.6.69 raeburn 14128: var versionitem;
14129: var versiontext;
1.160.6.5 raeburn 14130: if (document.getElementById(context+'_recaptchapub')) {
14131: pubitem = document.getElementById(context+'_recaptchapub');
14132: } else {
14133: return;
14134: }
14135: if (document.getElementById(context+'_recaptchapriv')) {
14136: privitem = document.getElementById(context+'_recaptchapriv');
14137: } else {
14138: return;
14139: }
14140: if (document.getElementById(context+'_recaptchapubtxt')) {
14141: pubtext = document.getElementById(context+'_recaptchapubtxt');
14142: } else {
14143: return;
14144: }
14145: if (document.getElementById(context+'_recaptchaprivtxt')) {
14146: privtext = document.getElementById(context+'_recaptchaprivtxt');
14147: } else {
14148: return;
14149: }
1.160.6.69 raeburn 14150: if (document.getElementById(context+'_recaptchaversion')) {
14151: versionitem = document.getElementById(context+'_recaptchaversion');
14152: } else {
14153: return;
14154: }
14155: if (document.getElementById(context+'_recaptchavertxt')) {
14156: versiontext = document.getElementById(context+'_recaptchavertxt');
14157: } else {
14158: return;
14159: }
1.160.6.5 raeburn 14160: if (caller.checked) {
14161: if (caller.value == 'recaptcha') {
14162: pubitem.type = 'text';
14163: privitem.type = 'text';
14164: pubitem.size = '40';
14165: privitem.size = '40';
14166: pubtext.innerHTML = "$lt{'pub'}";
14167: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 14168: versionitem.type = 'text';
14169: versionitem.size = '3';
14170: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 14171: } else {
14172: pubitem.type = 'hidden';
14173: privitem.type = 'hidden';
1.160.6.69 raeburn 14174: versionitem.type = 'hidden';
1.160.6.5 raeburn 14175: pubtext.innerHTML = '';
14176: privtext.innerHTML = '';
1.160.6.69 raeburn 14177: versiontext.innerHTML = '';
1.160.6.5 raeburn 14178: }
14179: }
14180: return;
14181: }
14182:
14183: // ]]>
14184: </script>
14185:
14186: END
14187:
14188: }
14189:
1.160.6.40 raeburn 14190: sub toggle_display_js {
1.160.6.16 raeburn 14191: return <<"END";
14192:
14193: <script type="text/javascript">
14194: // <![CDATA[
14195:
1.160.6.40 raeburn 14196: function toggleDisplay(domForm,caller) {
14197: if (document.getElementById(caller)) {
14198: var divitem = document.getElementById(caller);
14199: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 14200: var checkval = 1;
14201: var dispval = 'block';
1.160.6.93 raeburn 14202: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 14203: if (caller == 'emailoptions') {
14204: optionsElement = domForm.cancreate_email;
14205: }
1.160.6.57 raeburn 14206: if (caller == 'studentsubmission') {
14207: optionsElement = domForm.postsubmit;
14208: }
1.160.6.64 raeburn 14209: if (caller == 'cloneinstcode') {
14210: optionsElement = domForm.canclone;
14211: checkval = 'instcode';
14212: }
1.160.6.93 raeburn 14213: if (selfcreateRegExp.test(caller)) {
14214: optionsElement = domForm.elements[caller];
14215: checkval = 'other';
14216: dispval = 'inline'
14217: }
1.160.6.40 raeburn 14218: if (optionsElement.length) {
1.160.6.16 raeburn 14219: var currval;
1.160.6.40 raeburn 14220: for (var i=0; i<optionsElement.length; i++) {
14221: if (optionsElement[i].checked) {
14222: currval = optionsElement[i].value;
1.160.6.16 raeburn 14223: }
14224: }
1.160.6.64 raeburn 14225: if (currval == checkval) {
14226: divitem.style.display = dispval;
1.160.6.16 raeburn 14227: } else {
1.160.6.40 raeburn 14228: divitem.style.display = 'none';
1.160.6.16 raeburn 14229: }
14230: }
14231: }
14232: return;
14233: }
14234:
14235: // ]]>
14236: </script>
14237:
14238: END
14239:
14240: }
14241:
1.160.6.5 raeburn 14242: sub captcha_phrases {
14243: return &Apache::lonlocal::texthash (
14244: priv => 'Private key',
14245: pub => 'Public key',
14246: original => 'original (CAPTCHA)',
14247: recaptcha => 'successor (ReCAPTCHA)',
14248: notused => 'unused',
1.160.6.69 raeburn 14249: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 14250: );
14251: }
14252:
1.160.6.24 raeburn 14253: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 14254: my ($dom,$cachekeys) = @_;
14255: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 14256: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14257: my %thismachine;
14258: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.92 raeburn 14259: my @posscached = ('domainconfig','domdefaults','usersessions','directorysrch','cats');
1.160.6.61 raeburn 14260: if (keys(%servers)) {
1.160.6.24 raeburn 14261: foreach my $server (keys(%servers)) {
14262: next if ($thismachine{$server});
1.160.6.27 raeburn 14263: my @cached;
14264: foreach my $name (@posscached) {
14265: if ($cachekeys->{$name}) {
14266: push(@cached,&escape($name).':'.&escape($dom));
14267: }
14268: }
14269: if (@cached) {
14270: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
14271: }
1.160.6.24 raeburn 14272: }
14273: }
14274: return;
14275: }
14276:
1.3 raeburn 14277: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>