Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.84.4.2
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.84.4. (raeburn 4:): # $Id: domainprefs.pm,v 1.160.6.84.4.1 2017/08/15 23:40:33 raeburn Exp $
1.160.6.40 raeburn 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.160.6.78 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
30: ##############################################################
31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 107: (official, unofficial, community, and textbook). In each case the radio buttons
108: allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.1 raeburn 177:
1.155 raeburn 178: my $registered_cleanup;
179: my $modified_urls;
180:
1.1 raeburn 181: sub handler {
182: my $r=shift;
183: if ($r->header_only) {
184: &Apache::loncommon::content_type($r,'text/html');
185: $r->send_http_header;
186: return OK;
187: }
188:
1.91 raeburn 189: my $context = 'domain';
1.1 raeburn 190: my $dom = $env{'request.role.domain'};
1.5 albertel 191: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 192: if (&Apache::lonnet::allowed('mau',$dom)) {
193: &Apache::loncommon::content_type($r,'text/html');
194: $r->send_http_header;
195: } else {
196: $env{'user.error.msg'}=
197: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
198: return HTTP_NOT_ACCEPTABLE;
199: }
1.155 raeburn 200:
201: $registered_cleanup=0;
202: @{$modified_urls}=();
203:
1.1 raeburn 204: &Apache::lonhtmlcommon::clear_breadcrumbs();
205: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 206: ['phase','actions']);
1.30 raeburn 207: my $phase = 'pickactions';
1.3 raeburn 208: if ( exists($env{'form.phase'}) ) {
209: $phase = $env{'form.phase'};
210: }
1.150 raeburn 211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 212: my %domconfig =
1.6 raeburn 213: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 214: 'quotas','autoenroll','autoupdate','autocreate',
215: 'directorysrch','usercreation','usermodification',
216: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 217: 'serverstatuses','requestcourses','helpsettings',
218: 'coursedefaults','usersessions','loadbalancing',
219: 'requestauthor','selfenrollment','inststatus'],$dom);
1.43 raeburn 220: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 221: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 222: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 223: 'requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 224: 'serverstatuses','helpsettings','coursedefaults',
225: 'selfenrollment','usersessions');
1.160.6.7 raeburn 226: my %existing;
227: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
228: %existing = %{$domconfig{'loadbalancing'}};
229: }
230: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 231: push(@prefs_order,'loadbalancing');
232: }
1.30 raeburn 233: my %prefs = (
234: 'rolecolors' =>
235: { text => 'Default color schemes',
1.67 raeburn 236: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 237: header => [{col1 => 'Student Settings',
238: col2 => '',},
239: {col1 => 'Coordinator Settings',
240: col2 => '',},
241: {col1 => 'Author Settings',
242: col2 => '',},
243: {col1 => 'Administrator Settings',
244: col2 => '',}],
1.160.6.37 raeburn 245: print => \&print_rolecolors,
246: modify => \&modify_rolecolors,
1.30 raeburn 247: },
1.110 raeburn 248: 'login' =>
1.30 raeburn 249: { text => 'Log-in page options',
1.67 raeburn 250: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 251: header => [{col1 => 'Log-in Page Items',
252: col2 => '',},
253: {col1 => 'Log-in Help',
1.160.6.56 raeburn 254: col2 => 'Value'},
255: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 256: col2 => 'Value'}],
1.160.6.37 raeburn 257: print => \&print_login,
258: modify => \&modify_login,
1.30 raeburn 259: },
1.43 raeburn 260: 'defaults' =>
1.160.6.40 raeburn 261: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 262: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 263: header => [{col1 => 'Setting',
1.160.6.40 raeburn 264: col2 => 'Value'},
1.160.6.80 raeburn 265: {col1 => 'Internal Authentication',
266: col2 => 'Value'},
1.160.6.40 raeburn 267: {col1 => 'Institutional user types',
1.160.6.84.4. (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.84.4. (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.84.4. (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.84.4. (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: }
1284: $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
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.30 raeburn 1444: $datatable .= '<td>'.&mt('Default in use:').' <span id="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.'" /> '.
1453: ' </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'}) {
1458: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
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.'" /> '.
1468: ' </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;
1527: system("convert -sample $size $input $output");
1.159 raeburn 1528: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1529: }
1530: }
1.6 raeburn 1531: }
1532: }
1.16 raeburn 1533: }
1.6 raeburn 1534: if ($showfile) {
1.40 raeburn 1535: if ($showfile =~ m{^/(adm|res)/}) {
1536: if ($showfile =~ m{^/res/}) {
1537: my $local_showfile =
1538: &Apache::lonnet::filelocation('',$showfile);
1539: &Apache::lonnet::repcopy($local_showfile);
1540: }
1541: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1542: }
1543: if ($imgfile) {
1544: if ($imgfile =~ m{^/(adm|res)/}) {
1545: if ($imgfile =~ m{^/res/}) {
1546: my $local_imgfile =
1547: &Apache::lonnet::filelocation('',$imgfile);
1548: &Apache::lonnet::repcopy($local_imgfile);
1549: }
1550: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1551: } else {
1552: $fullsize = $imgfile;
1553: }
1554: }
1.41 raeburn 1555: $datatable .= '<td>';
1556: if ($img eq 'login') {
1.135 bisitz 1557: $datatable .= $login_hdr_pick;
1558: }
1.41 raeburn 1559: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1560: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1561: } else {
1.160.6.22 raeburn 1562: $datatable .= '<td> </td><td class="LC_left_item">'.
1563: &mt('Upload:').'<br />';
1.6 raeburn 1564: }
1565: } else {
1.160.6.22 raeburn 1566: $datatable .= '<td> </td><td class="LC_left_item">'.
1567: &mt('Upload:').'<br />';
1.6 raeburn 1568: }
1.9 raeburn 1569: if ($switchserver) {
1570: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1571: } else {
1.135 bisitz 1572: if ($img ne 'login') { # suppress file selection for Log-in header
1573: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1574: }
1.9 raeburn 1575: }
1576: $datatable .= '</td></tr>';
1.6 raeburn 1577: }
1578: $itemcount ++;
1579: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1580: $datatable .= '<tr'.$css_class.'>'.
1581: '<td>'.$choices->{'bgs'}.'</td>';
1582: my $bgs_def;
1583: foreach my $item (@{$bgs}) {
1584: if (!$is_custom->{$item}) {
1.70 raeburn 1585: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1586: }
1587: }
1588: if ($bgs_def) {
1.8 raeburn 1589: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1590: } else {
1591: $datatable .= '<td> </td>';
1592: }
1593: $datatable .= '<td class="LC_right_item">'.
1594: '<table border="0"><tr>';
1.160.6.13 raeburn 1595:
1.6 raeburn 1596: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1597: $datatable .= '<td align="center">'.$choices->{$item};
1598: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1599: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1600: $datatable .= ' ';
1.6 raeburn 1601: }
1.160.6.9 raeburn 1602: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1603: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1604: }
1605: $datatable .= '</tr></table></td></tr>';
1606: $itemcount ++;
1607: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1608: $datatable .= '<tr'.$css_class.'>'.
1609: '<td>'.$choices->{'links'}.'</td>';
1610: my $links_def;
1611: foreach my $item (@{$links}) {
1612: if (!$is_custom->{$item}) {
1.30 raeburn 1613: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1614: }
1615: }
1616: if ($links_def) {
1.8 raeburn 1617: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1618: } else {
1619: $datatable .= '<td> </td>';
1620: }
1621: $datatable .= '<td class="LC_right_item">'.
1622: '<table border="0"><tr>';
1623: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1624: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1625: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1626: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1627: $datatable.=' ';
1.6 raeburn 1628: }
1.160.6.9 raeburn 1629: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1630: '" /></td>';
1631: }
1.30 raeburn 1632: $$rowtotal += $itemcount;
1.3 raeburn 1633: return $datatable;
1634: }
1635:
1.70 raeburn 1636: sub logo_display_options {
1637: my ($img,$defaults,$designs) = @_;
1638: my $checkedon;
1639: if (ref($defaults) eq 'HASH') {
1640: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1641: if ($defaults->{'showlogo'}{$img}) {
1642: $checkedon = 'checked="checked" ';
1643: }
1644: }
1645: }
1646: if (ref($designs) eq 'HASH') {
1647: if (ref($designs->{'showlogo'}) eq 'HASH') {
1648: if (defined($designs->{'showlogo'}{$img})) {
1649: if ($designs->{'showlogo'}{$img} == 0) {
1650: $checkedon = '';
1651: } elsif ($designs->{'showlogo'}{$img} == 1) {
1652: $checkedon = 'checked="checked" ';
1653: }
1654: }
1655: }
1656: }
1657: return '<br /><label> <input type="checkbox" name="'.
1658: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1659: &mt('show').'</label>'."\n";
1660: }
1661:
1.41 raeburn 1662: sub login_header_options {
1.135 bisitz 1663: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1664: my $output = '';
1.41 raeburn 1665: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1666: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1667: if (!$is_custom->{'textcol'}) {
1668: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1669: ' ';
1670: }
1671: if (!$is_custom->{'bgcol'}) {
1672: $output .= $choices->{'bgcol'}.': '.
1673: '<span id="css_'.$role.'_font" style="background-color: '.
1674: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1675: }
1676: $output .= '<br />';
1677: }
1678: $output .='<br />';
1679: return $output;
1680: }
1681:
1682: sub login_text_colors {
1.160.6.22 raeburn 1683: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1684: my $color_menu = '<table border="0"><tr>';
1685: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1686: $color_menu .= '<td align="center">'.$choices->{$item};
1687: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1688: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1689: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1690: }
1691: $color_menu .= '</tr></table><br />';
1692: return $color_menu;
1693: }
1694:
1695: sub image_changes {
1696: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1697: my $output;
1.135 bisitz 1698: if ($img eq 'login') {
1699: # suppress image for Log-in header
1700: } elsif (!$is_custom) {
1.70 raeburn 1701: if ($img ne 'domlogo') {
1.41 raeburn 1702: $output .= &mt('Default image:').'<br />';
1703: } else {
1704: $output .= &mt('Default in use:').'<br />';
1705: }
1706: }
1.135 bisitz 1707: if ($img eq 'login') { # suppress image for Log-in header
1708: $output .= '<td>'.$logincolors;
1.41 raeburn 1709: } else {
1.135 bisitz 1710: if ($img_import) {
1711: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1712: }
1713: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1714: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1715: if ($is_custom) {
1716: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1717: '<input type="checkbox" name="'.
1718: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1719: '</label> '.&mt('Replace:').'</span><br />';
1720: } else {
1.160.6.22 raeburn 1721: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1722: }
1.41 raeburn 1723: }
1724: return $output;
1725: }
1726:
1.3 raeburn 1727: sub print_quotas {
1.86 raeburn 1728: my ($dom,$settings,$rowtotal,$action) = @_;
1729: my $context;
1730: if ($action eq 'quotas') {
1731: $context = 'tools';
1732: } else {
1733: $context = $action;
1734: }
1.160.6.20 raeburn 1735: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1736: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1737: my $typecount = 0;
1.101 raeburn 1738: my ($css_class,%titles);
1.86 raeburn 1739: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1740: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1741: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1742: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1743: %titles = &courserequest_titles();
1.160.6.5 raeburn 1744: } elsif ($context eq 'requestauthor') {
1745: @usertools = ('author');
1746: @options = ('norequest','approval','automatic');
1747: %titles = &authorrequest_titles();
1.86 raeburn 1748: } else {
1.160.6.4 raeburn 1749: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1750: %titles = &tool_titles();
1.86 raeburn 1751: }
1.26 raeburn 1752: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1753: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1754: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1755: unless (($context eq 'requestcourses') ||
1756: ($context eq 'requestauthor')) {
1.86 raeburn 1757: if (ref($settings) eq 'HASH') {
1758: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1759: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1760: } else {
1761: $currdefquota = $settings->{$type};
1762: }
1.160.6.20 raeburn 1763: if (ref($settings->{authorquota}) eq 'HASH') {
1764: $currauthorquota = $settings->{authorquota}->{$type};
1765: }
1.78 raeburn 1766: }
1.72 raeburn 1767: }
1.3 raeburn 1768: if (defined($usertypes->{$type})) {
1769: $typecount ++;
1770: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1771: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1772: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1773: '<td class="LC_left_item">';
1.101 raeburn 1774: if ($context eq 'requestcourses') {
1775: $datatable .= '<table><tr>';
1776: }
1777: my %cell;
1.72 raeburn 1778: foreach my $item (@usertools) {
1.101 raeburn 1779: if ($context eq 'requestcourses') {
1780: my ($curroption,$currlimit);
1781: if (ref($settings) eq 'HASH') {
1782: if (ref($settings->{$item}) eq 'HASH') {
1783: $curroption = $settings->{$item}->{$type};
1784: if ($curroption =~ /^autolimit=(\d*)$/) {
1785: $currlimit = $1;
1786: }
1787: }
1788: }
1789: if (!$curroption) {
1790: $curroption = 'norequest';
1791: }
1792: $datatable .= '<th>'.$titles{$item}.'</th>';
1793: foreach my $option (@options) {
1794: my $val = $option;
1795: if ($option eq 'norequest') {
1796: $val = 0;
1797: }
1798: if ($option eq 'validate') {
1799: my $canvalidate = 0;
1800: if (ref($validations{$item}) eq 'HASH') {
1801: if ($validations{$item}{$type}) {
1802: $canvalidate = 1;
1803: }
1804: }
1805: next if (!$canvalidate);
1806: }
1807: my $checked = '';
1808: if ($option eq $curroption) {
1809: $checked = ' checked="checked"';
1810: } elsif ($option eq 'autolimit') {
1811: if ($curroption =~ /^autolimit/) {
1812: $checked = ' checked="checked"';
1813: }
1814: }
1815: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1816: '<input type="radio" name="crsreq_'.$item.
1817: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1818: $titles{$option}.'</label>';
1.101 raeburn 1819: if ($option eq 'autolimit') {
1.127 raeburn 1820: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1821: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1822: 'value="'.$currlimit.'" />';
1.101 raeburn 1823: }
1.127 raeburn 1824: $cell{$item} .= '</span> ';
1.103 raeburn 1825: if ($option eq 'autolimit') {
1.127 raeburn 1826: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1827: }
1.101 raeburn 1828: }
1.160.6.5 raeburn 1829: } elsif ($context eq 'requestauthor') {
1830: my $curroption;
1831: if (ref($settings) eq 'HASH') {
1832: $curroption = $settings->{$type};
1833: }
1834: if (!$curroption) {
1835: $curroption = 'norequest';
1836: }
1837: foreach my $option (@options) {
1838: my $val = $option;
1839: if ($option eq 'norequest') {
1840: $val = 0;
1841: }
1842: my $checked = '';
1843: if ($option eq $curroption) {
1844: $checked = ' checked="checked"';
1845: }
1846: $datatable .= '<span class="LC_nobreak"><label>'.
1847: '<input type="radio" name="authorreq_'.$type.
1848: '" value="'.$val.'"'.$checked.' />'.
1849: $titles{$option}.'</label></span> ';
1850: }
1.101 raeburn 1851: } else {
1852: my $checked = 'checked="checked" ';
1853: if (ref($settings) eq 'HASH') {
1854: if (ref($settings->{$item}) eq 'HASH') {
1855: if ($settings->{$item}->{$type} == 0) {
1856: $checked = '';
1857: } elsif ($settings->{$item}->{$type} == 1) {
1858: $checked = 'checked="checked" ';
1859: }
1.78 raeburn 1860: }
1.72 raeburn 1861: }
1.101 raeburn 1862: $datatable .= '<span class="LC_nobreak"><label>'.
1863: '<input type="checkbox" name="'.$context.'_'.$item.
1864: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1865: '</label></span> ';
1.72 raeburn 1866: }
1.101 raeburn 1867: }
1868: if ($context eq 'requestcourses') {
1869: $datatable .= '</tr><tr>';
1870: foreach my $item (@usertools) {
1.106 raeburn 1871: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1872: }
1873: $datatable .= '</tr></table>';
1.72 raeburn 1874: }
1.86 raeburn 1875: $datatable .= '</td>';
1.160.6.5 raeburn 1876: unless (($context eq 'requestcourses') ||
1877: ($context eq 'requestauthor')) {
1.86 raeburn 1878: $datatable .=
1.160.6.20 raeburn 1879: '<td class="LC_right_item">'.
1880: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1881: '<input type="text" name="quota_'.$type.
1.72 raeburn 1882: '" value="'.$currdefquota.
1.160.6.20 raeburn 1883: '" size="5" /></span>'.(' ' x 2).
1884: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1885: '<input type="text" name="authorquota_'.$type.
1886: '" value="'.$currauthorquota.
1887: '" size="5" /></span></td>';
1.86 raeburn 1888: }
1889: $datatable .= '</tr>';
1.3 raeburn 1890: }
1891: }
1892: }
1.160.6.5 raeburn 1893: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1894: $defaultquota = '20';
1.160.6.20 raeburn 1895: $authorquota = '500';
1.86 raeburn 1896: if (ref($settings) eq 'HASH') {
1897: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1898: $defaultquota = $settings->{'defaultquota'}->{'default'};
1899: } elsif (defined($settings->{'default'})) {
1900: $defaultquota = $settings->{'default'};
1901: }
1.160.6.20 raeburn 1902: if (ref($settings->{'authorquota'}) eq 'HASH') {
1903: $authorquota = $settings->{'authorquota'}->{'default'};
1904: }
1.3 raeburn 1905: }
1906: }
1907: $typecount ++;
1908: $css_class = $typecount%2?' class="LC_odd_row"':'';
1909: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1910: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1911: '<td class="LC_left_item">';
1.101 raeburn 1912: if ($context eq 'requestcourses') {
1913: $datatable .= '<table><tr>';
1914: }
1915: my %defcell;
1.72 raeburn 1916: foreach my $item (@usertools) {
1.101 raeburn 1917: if ($context eq 'requestcourses') {
1918: my ($curroption,$currlimit);
1919: if (ref($settings) eq 'HASH') {
1920: if (ref($settings->{$item}) eq 'HASH') {
1921: $curroption = $settings->{$item}->{'default'};
1922: if ($curroption =~ /^autolimit=(\d*)$/) {
1923: $currlimit = $1;
1924: }
1925: }
1926: }
1927: if (!$curroption) {
1928: $curroption = 'norequest';
1929: }
1930: $datatable .= '<th>'.$titles{$item}.'</th>';
1931: foreach my $option (@options) {
1932: my $val = $option;
1933: if ($option eq 'norequest') {
1934: $val = 0;
1935: }
1936: if ($option eq 'validate') {
1937: my $canvalidate = 0;
1938: if (ref($validations{$item}) eq 'HASH') {
1939: if ($validations{$item}{'default'}) {
1940: $canvalidate = 1;
1941: }
1942: }
1943: next if (!$canvalidate);
1944: }
1945: my $checked = '';
1946: if ($option eq $curroption) {
1947: $checked = ' checked="checked"';
1948: } elsif ($option eq 'autolimit') {
1949: if ($curroption =~ /^autolimit/) {
1950: $checked = ' checked="checked"';
1951: }
1952: }
1953: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1954: '<input type="radio" name="crsreq_'.$item.
1955: '_default" value="'.$val.'"'.$checked.' />'.
1956: $titles{$option}.'</label>';
1957: if ($option eq 'autolimit') {
1.127 raeburn 1958: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1959: $item.'_limit_default" size="1" '.
1960: 'value="'.$currlimit.'" />';
1961: }
1.127 raeburn 1962: $defcell{$item} .= '</span> ';
1.104 raeburn 1963: if ($option eq 'autolimit') {
1.127 raeburn 1964: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1965: }
1.101 raeburn 1966: }
1.160.6.5 raeburn 1967: } elsif ($context eq 'requestauthor') {
1968: my $curroption;
1969: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1970: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1971: }
1972: if (!$curroption) {
1973: $curroption = 'norequest';
1974: }
1975: foreach my $option (@options) {
1976: my $val = $option;
1977: if ($option eq 'norequest') {
1978: $val = 0;
1979: }
1980: my $checked = '';
1981: if ($option eq $curroption) {
1982: $checked = ' checked="checked"';
1983: }
1984: $datatable .= '<span class="LC_nobreak"><label>'.
1985: '<input type="radio" name="authorreq_default"'.
1986: ' value="'.$val.'"'.$checked.' />'.
1987: $titles{$option}.'</label></span> ';
1988: }
1.101 raeburn 1989: } else {
1990: my $checked = 'checked="checked" ';
1991: if (ref($settings) eq 'HASH') {
1992: if (ref($settings->{$item}) eq 'HASH') {
1993: if ($settings->{$item}->{'default'} == 0) {
1994: $checked = '';
1995: } elsif ($settings->{$item}->{'default'} == 1) {
1996: $checked = 'checked="checked" ';
1997: }
1.78 raeburn 1998: }
1.72 raeburn 1999: }
1.101 raeburn 2000: $datatable .= '<span class="LC_nobreak"><label>'.
2001: '<input type="checkbox" name="'.$context.'_'.$item.
2002: '" value="default" '.$checked.'/>'.$titles{$item}.
2003: '</label></span> ';
2004: }
2005: }
2006: if ($context eq 'requestcourses') {
2007: $datatable .= '</tr><tr>';
2008: foreach my $item (@usertools) {
1.106 raeburn 2009: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2010: }
1.101 raeburn 2011: $datatable .= '</tr></table>';
1.72 raeburn 2012: }
1.86 raeburn 2013: $datatable .= '</td>';
1.160.6.5 raeburn 2014: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2015: $datatable .= '<td class="LC_right_item">'.
2016: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2017: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2018: $defaultquota.'" size="5" /></span>'.(' ' x2).
2019: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2020: '<input type="text" name="authorquota" value="'.
2021: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2022: }
2023: $datatable .= '</tr>';
1.72 raeburn 2024: $typecount ++;
2025: $css_class = $typecount%2?' class="LC_odd_row"':'';
2026: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2027: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2028: if ($context eq 'requestcourses') {
1.109 raeburn 2029: $datatable .= &mt('(overrides affiliation, if set)').
2030: '</td>'.
2031: '<td class="LC_left_item">'.
2032: '<table><tr>';
1.101 raeburn 2033: } else {
1.109 raeburn 2034: $datatable .= &mt('(overrides affiliation, if checked)').
2035: '</td>'.
2036: '<td class="LC_left_item" colspan="2">'.
2037: '<br />';
1.101 raeburn 2038: }
2039: my %advcell;
1.72 raeburn 2040: foreach my $item (@usertools) {
1.101 raeburn 2041: if ($context eq 'requestcourses') {
2042: my ($curroption,$currlimit);
2043: if (ref($settings) eq 'HASH') {
2044: if (ref($settings->{$item}) eq 'HASH') {
2045: $curroption = $settings->{$item}->{'_LC_adv'};
2046: if ($curroption =~ /^autolimit=(\d*)$/) {
2047: $currlimit = $1;
2048: }
2049: }
2050: }
2051: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2052: my $checked = '';
2053: if ($curroption eq '') {
2054: $checked = ' checked="checked"';
2055: }
2056: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2057: '<input type="radio" name="crsreq_'.$item.
2058: '__LC_adv" value=""'.$checked.' />'.
2059: &mt('No override set').'</label></span> ';
1.101 raeburn 2060: foreach my $option (@options) {
2061: my $val = $option;
2062: if ($option eq 'norequest') {
2063: $val = 0;
2064: }
2065: if ($option eq 'validate') {
2066: my $canvalidate = 0;
2067: if (ref($validations{$item}) eq 'HASH') {
2068: if ($validations{$item}{'_LC_adv'}) {
2069: $canvalidate = 1;
2070: }
2071: }
2072: next if (!$canvalidate);
2073: }
2074: my $checked = '';
1.104 raeburn 2075: if ($val eq $curroption) {
1.101 raeburn 2076: $checked = ' checked="checked"';
2077: } elsif ($option eq 'autolimit') {
2078: if ($curroption =~ /^autolimit/) {
2079: $checked = ' checked="checked"';
2080: }
2081: }
2082: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2083: '<input type="radio" name="crsreq_'.$item.
2084: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2085: $titles{$option}.'</label>';
2086: if ($option eq 'autolimit') {
1.127 raeburn 2087: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2088: $item.'_limit__LC_adv" size="1" '.
2089: 'value="'.$currlimit.'" />';
2090: }
1.127 raeburn 2091: $advcell{$item} .= '</span> ';
1.104 raeburn 2092: if ($option eq 'autolimit') {
1.127 raeburn 2093: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2094: }
1.101 raeburn 2095: }
1.160.6.5 raeburn 2096: } elsif ($context eq 'requestauthor') {
2097: my $curroption;
2098: if (ref($settings) eq 'HASH') {
2099: $curroption = $settings->{'_LC_adv'};
2100: }
2101: my $checked = '';
2102: if ($curroption eq '') {
2103: $checked = ' checked="checked"';
2104: }
2105: $datatable .= '<span class="LC_nobreak"><label>'.
2106: '<input type="radio" name="authorreq__LC_adv"'.
2107: ' value=""'.$checked.' />'.
2108: &mt('No override set').'</label></span> ';
2109: foreach my $option (@options) {
2110: my $val = $option;
2111: if ($option eq 'norequest') {
2112: $val = 0;
2113: }
2114: my $checked = '';
2115: if ($val eq $curroption) {
2116: $checked = ' checked="checked"';
2117: }
2118: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2119: '<input type="radio" name="authorreq__LC_adv"'.
2120: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2121: $titles{$option}.'</label></span> ';
2122: }
1.101 raeburn 2123: } else {
2124: my $checked = 'checked="checked" ';
2125: if (ref($settings) eq 'HASH') {
2126: if (ref($settings->{$item}) eq 'HASH') {
2127: if ($settings->{$item}->{'_LC_adv'} == 0) {
2128: $checked = '';
2129: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2130: $checked = 'checked="checked" ';
2131: }
1.79 raeburn 2132: }
1.72 raeburn 2133: }
1.101 raeburn 2134: $datatable .= '<span class="LC_nobreak"><label>'.
2135: '<input type="checkbox" name="'.$context.'_'.$item.
2136: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2137: '</label></span> ';
2138: }
2139: }
2140: if ($context eq 'requestcourses') {
2141: $datatable .= '</tr><tr>';
2142: foreach my $item (@usertools) {
1.106 raeburn 2143: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2144: }
1.101 raeburn 2145: $datatable .= '</tr></table>';
1.72 raeburn 2146: }
1.98 raeburn 2147: $datatable .= '</td></tr>';
1.30 raeburn 2148: $$rowtotal += $typecount;
1.3 raeburn 2149: return $datatable;
2150: }
2151:
1.160.6.5 raeburn 2152: sub print_requestmail {
1.160.6.84.4. (raeburn 2153:): my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2154: my ($now,$datatable,%currapp);
1.102 raeburn 2155: $now = time;
2156: if (ref($settings) eq 'HASH') {
2157: if (ref($settings->{'notify'}) eq 'HASH') {
2158: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2159: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2160: }
2161: }
2162: }
1.160.6.16 raeburn 2163: my $numinrow = 2;
1.160.6.34 raeburn 2164: my $css_class;
1.160.6.84.4. (raeburn 2165:): if ($$rowtotal%2) {
2166:): $css_class = 'LC_odd_row';
2167:): }
2168:): if ($customcss) {
2169:): $css_class .= " $customcss";
2170:): }
2171:): $css_class =~ s/^\s+//;
2172:): if ($css_class) {
2173:): $css_class = ' class="'.$css_class.'"';
2174:): }
2175:): if ($rowstyle) {
2176:): $css_class .= ' style="'.$rowstyle.'"';
2177:): }
1.160.6.5 raeburn 2178: my $text;
2179: if ($action eq 'requestcourses') {
2180: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2181: } elsif ($action eq 'requestauthor') {
2182: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2183: } else {
1.160.6.34 raeburn 2184: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2185: }
1.160.6.34 raeburn 2186: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2187: ' <td>'.$text.'</td>'.
1.102 raeburn 2188: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2189: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2190: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2191: if ($numdc > 0) {
2192: $datatable .= $table;
1.102 raeburn 2193: } else {
2194: $datatable .= &mt('There are no active Domain Coordinators');
2195: }
2196: $datatable .='</td></tr>';
2197: return $datatable;
2198: }
2199:
1.160.6.30 raeburn 2200: sub print_studentcode {
2201: my ($settings,$rowtotal) = @_;
2202: my $rownum = 0;
2203: my ($output,%current);
2204: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2205: if (ref($settings) eq 'HASH') {
2206: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2207: foreach my $type (@crstypes) {
2208: $current{$type} = $settings->{'uniquecode'}{$type};
2209: }
1.160.6.30 raeburn 2210: }
2211: }
2212: $output .= '<tr>'.
2213: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2214: '<td class="LC_left_item">';
2215: foreach my $type (@crstypes) {
2216: my $check = ' ';
2217: if ($current{$type}) {
2218: $check = ' checked="checked" ';
2219: }
2220: $output .= '<span class="LC_nobreak"><label>'.
2221: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2222: &mt($type).'</label></span>'.(' 'x2).' ';
2223: }
2224: $output .= '</td></tr>';
2225: $$rowtotal ++;
2226: return $output;
2227: }
2228:
2229: sub print_textbookcourses {
1.160.6.46 raeburn 2230: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2231: my $rownum = 0;
2232: my $css_class;
2233: my $itemcount = 1;
2234: my $maxnum = 0;
2235: my $bookshash;
2236: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2237: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2238: }
2239: my %ordered;
2240: if (ref($bookshash) eq 'HASH') {
2241: foreach my $item (keys(%{$bookshash})) {
2242: if (ref($bookshash->{$item}) eq 'HASH') {
2243: my $num = $bookshash->{$item}{'order'};
2244: $ordered{$num} = $item;
2245: }
2246: }
2247: }
2248: my $confname = $dom.'-domainconfig';
2249: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2250: my $maxnum = scalar(keys(%ordered));
2251: my $datatable;
1.160.6.30 raeburn 2252: if (keys(%ordered)) {
2253: my @items = sort { $a <=> $b } keys(%ordered);
2254: for (my $i=0; $i<@items; $i++) {
2255: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2256: my $key = $ordered{$items[$i]};
2257: my %coursehash=&Apache::lonnet::coursedescription($key);
2258: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2259: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2260: if (ref($bookshash->{$key}) eq 'HASH') {
2261: $subject = $bookshash->{$key}->{'subject'};
2262: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2263: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2264: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2265: $author = $bookshash->{$key}->{'author'};
2266: $image = $bookshash->{$key}->{'image'};
2267: if ($image ne '') {
2268: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2269: my $imagethumb = "$path/tn-".$imagefile;
2270: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2271: }
1.160.6.30 raeburn 2272: }
2273: }
1.160.6.46 raeburn 2274: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2275: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2276: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2277: for (my $k=0; $k<=$maxnum; $k++) {
2278: my $vpos = $k+1;
2279: my $selstr;
2280: if ($k == $i) {
2281: $selstr = ' selected="selected" ';
2282: }
2283: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2284: }
2285: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2286: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2287: &mt('Delete?').'</label></span></td>'.
2288: '<td colspan="2">'.
1.160.6.46 raeburn 2289: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2290: (' 'x2).
1.160.6.46 raeburn 2291: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2292: if ($type eq 'textbooks') {
2293: $datatable .= (' 'x2).
1.160.6.47 raeburn 2294: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2295: (' 'x2).
1.160.6.46 raeburn 2296: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2297: (' 'x2).
2298: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2299: if ($image) {
2300: $datatable .= '<span class="LC_nobreak">'.
2301: $imgsrc.
2302: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2303: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2304: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2305: }
2306: if ($switchserver) {
2307: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2308: } else {
2309: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2310: }
1.160.6.30 raeburn 2311: }
1.160.6.46 raeburn 2312: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2313: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2314: $coursetitle.'</span></td></tr>'."\n";
2315: $itemcount ++;
2316: }
2317: }
2318: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2319: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2320: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2321: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2322: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2323: for (my $k=0; $k<$maxnum+1; $k++) {
2324: my $vpos = $k+1;
2325: my $selstr;
2326: if ($k == $maxnum) {
2327: $selstr = ' selected="selected" ';
2328: }
2329: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2330: }
2331: $datatable .= '</select> '."\n".
1.160.6.46 raeburn 2332: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30 raeburn 2333: '<td colspan="2">'.
1.160.6.46 raeburn 2334: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2335: (' 'x2).
1.160.6.46 raeburn 2336: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2337: (' 'x2);
2338: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2339: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2340: (' 'x2).
2341: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2342: (' 'x2).
2343: '<span class="LC_nobreak">'.&mt('Image:').' ';
2344: if ($switchserver) {
2345: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2346: } else {
2347: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2348: }
1.160.6.30 raeburn 2349: }
2350: $datatable .= '</span>'."\n".
2351: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2352: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2353: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2354: &Apache::loncommon::selectcourse_link
1.160.6.46 raeburn 2355: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30 raeburn 2356: '</span></td>'."\n".
2357: '</tr>'."\n";
2358: $itemcount ++;
2359: return $datatable;
2360: }
2361:
2362: sub textbookcourses_javascript {
1.160.6.46 raeburn 2363: my ($settings) = @_;
2364: return unless(ref($settings) eq 'HASH');
2365: my (%ordered,%total,%jstext);
2366: foreach my $type ('textbooks','templates') {
2367: $total{$type} = 0;
2368: if (ref($settings->{$type}) eq 'HASH') {
2369: foreach my $item (keys(%{$settings->{$type}})) {
2370: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2371: my $num = $settings->{$type}->{$item}{'order'};
2372: $ordered{$type}{$num} = $item;
2373: }
2374: }
2375: $total{$type} = scalar(keys(%{$settings->{$type}}));
2376: }
2377: my @jsarray = ();
2378: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2379: push(@jsarray,$ordered{$type}{$item});
2380: }
2381: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2382: }
2383: return <<"ENDSCRIPT";
2384: <script type="text/javascript">
2385: // <![CDATA[
1.160.6.46 raeburn 2386: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2387: var changedVal;
1.160.6.46 raeburn 2388: $jstext{'textbooks'};
2389: $jstext{'templates'};
2390: var newpos;
2391: var maxh;
2392: if (caller == 'textbooks') {
2393: newpos = 'textbooks_addbook_pos';
2394: maxh = 1 + $total{'textbooks'};
2395: } else {
2396: newpos = 'templates_addbook_pos';
2397: maxh = 1 + $total{'templates'};
2398: }
1.160.6.30 raeburn 2399: var current = new Array;
2400: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2401: if (item == newpos) {
2402: changedVal = newitemVal;
2403: } else {
2404: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2405: current[newitemVal] = newpos;
2406: }
1.160.6.46 raeburn 2407: if (caller == 'textbooks') {
2408: for (var i=0; i<textbooks.length; i++) {
2409: var elementName = 'textbooks_'+textbooks[i];
2410: if (elementName != item) {
2411: if (form.elements[elementName]) {
2412: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2413: current[currVal] = elementName;
2414: }
2415: }
2416: }
2417: }
2418: if (caller == 'templates') {
2419: for (var i=0; i<templates.length; i++) {
2420: var elementName = 'templates_'+templates[i];
2421: if (elementName != item) {
2422: if (form.elements[elementName]) {
2423: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2424: current[currVal] = elementName;
2425: }
1.160.6.30 raeburn 2426: }
2427: }
2428: }
2429: var oldVal;
2430: for (var j=0; j<maxh; j++) {
2431: if (current[j] == undefined) {
2432: oldVal = j;
2433: }
2434: }
2435: if (oldVal < changedVal) {
2436: for (var k=oldVal+1; k<=changedVal ; k++) {
2437: var elementName = current[k];
2438: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2439: }
2440: } else {
2441: for (var k=changedVal; k<oldVal; k++) {
2442: var elementName = current[k];
2443: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2444: }
2445: }
2446: return;
2447: }
2448:
2449: // ]]>
2450: </script>
2451:
2452: ENDSCRIPT
2453: }
2454:
1.3 raeburn 2455: sub print_autoenroll {
1.30 raeburn 2456: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2457: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2458: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2459: if (ref($settings) eq 'HASH') {
2460: if (exists($settings->{'run'})) {
2461: if ($settings->{'run'} eq '0') {
2462: $runoff = ' checked="checked" ';
2463: $runon = ' ';
2464: } else {
2465: $runon = ' checked="checked" ';
2466: $runoff = ' ';
2467: }
2468: } else {
2469: if ($autorun) {
2470: $runon = ' checked="checked" ';
2471: $runoff = ' ';
2472: } else {
2473: $runoff = ' checked="checked" ';
2474: $runon = ' ';
2475: }
2476: }
1.129 raeburn 2477: if (exists($settings->{'co-owners'})) {
2478: if ($settings->{'co-owners'} eq '0') {
2479: $coownersoff = ' checked="checked" ';
2480: $coownerson = ' ';
2481: } else {
2482: $coownerson = ' checked="checked" ';
2483: $coownersoff = ' ';
2484: }
2485: } else {
2486: $coownersoff = ' checked="checked" ';
2487: $coownerson = ' ';
2488: }
1.3 raeburn 2489: if (exists($settings->{'sender_domain'})) {
2490: $defdom = $settings->{'sender_domain'};
2491: }
1.160.6.68 raeburn 2492: if (exists($settings->{'autofailsafe'})) {
2493: $failsafe = $settings->{'autofailsafe'};
2494: }
1.14 raeburn 2495: } else {
2496: if ($autorun) {
2497: $runon = ' checked="checked" ';
2498: $runoff = ' ';
2499: } else {
2500: $runoff = ' checked="checked" ';
2501: $runon = ' ';
2502: }
1.3 raeburn 2503: }
2504: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2505: my $notif_sender;
2506: if (ref($settings) eq 'HASH') {
2507: $notif_sender = $settings->{'sender_uname'};
2508: }
1.3 raeburn 2509: my $datatable='<tr class="LC_odd_row">'.
2510: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2511: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2512: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2513: $runon.' value="1" />'.&mt('Yes').'</label> '.
2514: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2515: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2516: '</tr><tr>'.
2517: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2518: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2519: &mt('username').': '.
2520: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2521: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2522: ': '.$domform.'</span></td></tr>'.
2523: '<tr class="LC_odd_row">'.
2524: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2525: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2526: '<input type="radio" name="autoassign_coowners"'.
2527: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2528: '<label><input type="radio" name="autoassign_coowners"'.
2529: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2530: '</tr><tr>'.
2531: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2532: '<td class="LC_right_item"><span class="LC_nobreak">'.
2533: '<input type="text" name="autoenroll_failsafe"'.
2534: ' value="'.$failsafe.'" size="4" /></td></tr>';
2535: $$rowtotal += 4;
1.3 raeburn 2536: return $datatable;
2537: }
2538:
2539: sub print_autoupdate {
1.30 raeburn 2540: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2541: my $datatable;
2542: if ($position eq 'top') {
2543: my $updateon = ' ';
2544: my $updateoff = ' checked="checked" ';
2545: my $classlistson = ' ';
2546: my $classlistsoff = ' checked="checked" ';
2547: if (ref($settings) eq 'HASH') {
2548: if ($settings->{'run'} eq '1') {
2549: $updateon = $updateoff;
2550: $updateoff = ' ';
2551: }
2552: if ($settings->{'classlists'} eq '1') {
2553: $classlistson = $classlistsoff;
2554: $classlistsoff = ' ';
2555: }
2556: }
2557: my %title = (
2558: run => 'Auto-update active?',
2559: classlists => 'Update information in classlists?',
2560: );
2561: $datatable = '<tr class="LC_odd_row">'.
2562: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2563: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2564: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2565: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2566: '<label><input type="radio" name="autoupdate_run"'.
2567: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2568: '</tr><tr>'.
2569: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2570: '<td class="LC_right_item"><span class="LC_nobreak">'.
2571: '<label><input type="radio" name="classlists"'.
2572: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2573: '<label><input type="radio" name="classlists"'.
2574: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2575: '</tr>';
1.30 raeburn 2576: $$rowtotal += 2;
1.131 raeburn 2577: } elsif ($position eq 'middle') {
2578: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2579: my $numinrow = 3;
2580: my $locknamesettings;
2581: $datatable .= &insttypes_row($settings,$types,$usertypes,
2582: $dom,$numinrow,$othertitle,
1.160.6.84.4. (raeburn 2583:): 'lockablenames',$rowtotal);
1.131 raeburn 2584: $$rowtotal ++;
1.3 raeburn 2585: } else {
1.44 raeburn 2586: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2587: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2588: 'permanentemail','id');
1.33 raeburn 2589: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2590: my $numrows = 0;
1.26 raeburn 2591: if (ref($types) eq 'ARRAY') {
2592: if (@{$types} > 0) {
2593: $datatable =
2594: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2595: \@fields,$types,\$numrows);
1.30 raeburn 2596: $$rowtotal += @{$types};
1.26 raeburn 2597: }
1.3 raeburn 2598: }
2599: $datatable .=
2600: &usertype_update_row($settings,{'default' => $othertitle},
2601: \%fieldtitles,\@fields,['default'],
2602: \$numrows);
1.30 raeburn 2603: $$rowtotal ++;
1.3 raeburn 2604: }
2605: return $datatable;
2606: }
2607:
1.125 raeburn 2608: sub print_autocreate {
2609: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2610: my (%createon,%createoff,%currhash);
1.125 raeburn 2611: my @types = ('xml','req');
2612: if (ref($settings) eq 'HASH') {
2613: foreach my $item (@types) {
2614: $createoff{$item} = ' checked="checked" ';
2615: $createon{$item} = ' ';
2616: if (exists($settings->{$item})) {
2617: if ($settings->{$item}) {
2618: $createon{$item} = ' checked="checked" ';
2619: $createoff{$item} = ' ';
2620: }
2621: }
2622: }
1.160.6.16 raeburn 2623: if ($settings->{'xmldc'} ne '') {
2624: $currhash{$settings->{'xmldc'}} = 1;
2625: }
1.125 raeburn 2626: } else {
2627: foreach my $item (@types) {
2628: $createoff{$item} = ' checked="checked" ';
2629: $createon{$item} = ' ';
2630: }
2631: }
2632: $$rowtotal += 2;
1.160.6.16 raeburn 2633: my $numinrow = 2;
1.125 raeburn 2634: my $datatable='<tr class="LC_odd_row">'.
2635: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2636: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2637: '<input type="radio" name="autocreate_xml"'.
2638: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2639: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2640: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2641: '</td></tr><tr>'.
2642: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2643: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2644: '<input type="radio" name="autocreate_req"'.
2645: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2646: '<label><input type="radio" name="autocreate_req"'.
2647: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2648: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2649: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2650: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2651: if ($numdc > 1) {
1.160.6.50 raeburn 2652: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2653: '</td><td class="LC_left_item">';
1.125 raeburn 2654: } else {
1.160.6.50 raeburn 2655: $datatable .= &mt('Course creation processed as:').
2656: '</td><td class="LC_right_item">';
1.125 raeburn 2657: }
1.160.6.50 raeburn 2658: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2659: $$rowtotal += $rows;
1.125 raeburn 2660: return $datatable;
2661: }
2662:
1.23 raeburn 2663: sub print_directorysrch {
1.160.6.72 raeburn 2664: my ($position,$dom,$settings,$rowtotal) = @_;
2665: my $datatable;
2666: if ($position eq 'top') {
2667: my $instsrchon = ' ';
2668: my $instsrchoff = ' checked="checked" ';
2669: my ($exacton,$containson,$beginson);
2670: my $instlocalon = ' ';
2671: my $instlocaloff = ' checked="checked" ';
2672: if (ref($settings) eq 'HASH') {
2673: if ($settings->{'available'} eq '1') {
2674: $instsrchon = $instsrchoff;
2675: $instsrchoff = ' ';
2676: }
2677: if ($settings->{'localonly'} eq '1') {
2678: $instlocalon = $instlocaloff;
2679: $instlocaloff = ' ';
2680: }
2681: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2682: foreach my $type (@{$settings->{'searchtypes'}}) {
2683: if ($type eq 'exact') {
2684: $exacton = ' checked="checked" ';
2685: } elsif ($type eq 'contains') {
2686: $containson = ' checked="checked" ';
2687: } elsif ($type eq 'begins') {
2688: $beginson = ' checked="checked" ';
2689: }
2690: }
2691: } else {
2692: if ($settings->{'searchtypes'} eq 'exact') {
2693: $exacton = ' checked="checked" ';
2694: } elsif ($settings->{'searchtypes'} eq 'contains') {
2695: $containson = ' checked="checked" ';
2696: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2697: $exacton = ' checked="checked" ';
2698: $containson = ' checked="checked" ';
2699: }
2700: }
1.23 raeburn 2701: }
1.160.6.72 raeburn 2702: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2703: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2704:
1.160.6.72 raeburn 2705: my $numinrow = 4;
2706: my $cansrchrow = 0;
2707: $datatable='<tr class="LC_odd_row">'.
2708: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2709: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2710: '<input type="radio" name="dirsrch_available"'.
2711: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2712: '<label><input type="radio" name="dirsrch_available"'.
2713: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2714: '</tr><tr>'.
2715: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2716: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2717: '<input type="radio" name="dirsrch_instlocalonly"'.
2718: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2719: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2720: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2721: '</tr>';
2722: $$rowtotal += 2;
2723: if (ref($usertypes) eq 'HASH') {
2724: if (keys(%{$usertypes}) > 0) {
2725: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.84.4. (raeburn 2726:): $numinrow,$othertitle,'cansearch',
2727:): $rowtotal);
1.160.6.72 raeburn 2728: $cansrchrow = 1;
2729: }
1.26 raeburn 2730: }
1.160.6.72 raeburn 2731: if ($cansrchrow) {
2732: $$rowtotal ++;
2733: $datatable .= '<tr>';
2734: } else {
2735: $datatable .= '<tr class="LC_odd_row">';
2736: }
2737: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2738: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2739: foreach my $title (@{$titleorder}) {
2740: if (defined($searchtitles->{$title})) {
2741: my $check = ' ';
2742: if (ref($settings) eq 'HASH') {
2743: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2744: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2745: $check = ' checked="checked" ';
2746: }
1.39 raeburn 2747: }
1.25 raeburn 2748: }
1.160.6.72 raeburn 2749: $datatable .= '<td class="LC_left_item">'.
2750: '<span class="LC_nobreak"><label>'.
2751: '<input type="checkbox" name="searchby" '.
2752: 'value="'.$title.'"'.$check.'/>'.
2753: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2754: }
2755: }
1.160.6.72 raeburn 2756: $datatable .= '</tr></table></td></tr>';
2757: $$rowtotal ++;
2758: if ($cansrchrow) {
2759: $datatable .= '<tr class="LC_odd_row">';
2760: } else {
2761: $datatable .= '<tr>';
2762: }
2763: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2764: '<td class="LC_left_item" colspan="2">'.
2765: '<span class="LC_nobreak"><label>'.
2766: '<input type="checkbox" name="searchtypes" '.
2767: $exacton.' value="exact" />'.&mt('Exact match').
2768: '</label> '.
2769: '<label><input type="checkbox" name="searchtypes" '.
2770: $beginson.' value="begins" />'.&mt('Begins with').
2771: '</label> '.
2772: '<label><input type="checkbox" name="searchtypes" '.
2773: $containson.' value="contains" />'.&mt('Contains').
2774: '</label></span></td></tr>';
2775: $$rowtotal ++;
1.26 raeburn 2776: } else {
1.160.6.72 raeburn 2777: my $domsrchon = ' checked="checked" ';
2778: my $domsrchoff = ' ';
2779: my $domlocalon = ' ';
2780: my $domlocaloff = ' checked="checked" ';
2781: if (ref($settings) eq 'HASH') {
2782: if ($settings->{'lclocalonly'} eq '1') {
2783: $domlocalon = $domlocaloff;
2784: $domlocaloff = ' ';
2785: }
2786: if ($settings->{'lcavailable'} eq '0') {
2787: $domsrchoff = $domsrchon;
2788: $domsrchon = ' ';
2789: }
2790: }
2791: $datatable='<tr class="LC_odd_row">'.
2792: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2793: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2794: '<input type="radio" name="dirsrch_domavailable"'.
2795: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2796: '<label><input type="radio" name="dirsrch_domavailable"'.
2797: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2798: '</tr><tr>'.
2799: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2800: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2801: '<input type="radio" name="dirsrch_domlocalonly"'.
2802: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2803: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2804: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2805: '</tr>';
2806: $$rowtotal += 2;
1.26 raeburn 2807: }
1.25 raeburn 2808: return $datatable;
2809: }
2810:
1.28 raeburn 2811: sub print_contacts {
1.160.6.78 raeburn 2812: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2813: my $datatable;
2814: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 2815: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2816: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2817: if ($position eq 'top') {
2818: if (ref($settings) eq 'HASH') {
2819: foreach my $item (@contacts) {
2820: if (exists($settings->{$item})) {
2821: $to{$item} = $settings->{$item};
2822: }
1.28 raeburn 2823: }
2824: }
1.160.6.78 raeburn 2825: } elsif ($position eq 'middle') {
2826: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
2827: 'updatesmail','idconflictsmail');
1.28 raeburn 2828: foreach my $type (@mailings) {
1.160.6.78 raeburn 2829: $otheremails{$type} = '';
2830: }
2831: } else {
2832: @mailings = ('helpdeskmail','otherdomsmail');
2833: foreach my $type (@mailings) {
2834: $otheremails{$type} = '';
2835: }
2836: $bccemails{'helpdeskmail'} = '';
2837: $bccemails{'otherdomsmail'} = '';
2838: $includestr{'helpdeskmail'} = '';
2839: $includestr{'otherdomsmail'} = '';
2840: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2841: }
2842: if (ref($settings) eq 'HASH') {
2843: unless ($position eq 'top') {
2844: foreach my $type (@mailings) {
2845: if (exists($settings->{$type})) {
2846: if (ref($settings->{$type}) eq 'HASH') {
2847: foreach my $item (@contacts) {
2848: if ($settings->{$type}{$item}) {
2849: $checked{$type}{$item} = ' checked="checked" ';
2850: }
1.28 raeburn 2851: }
1.160.6.78 raeburn 2852: $otheremails{$type} = $settings->{$type}{'others'};
2853: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2854: $bccemails{$type} = $settings->{$type}{'bcc'};
2855: if ($settings->{$type}{'include'} ne '') {
2856: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2857: $includestr{$type} = &unescape($includestr{$type});
2858: }
2859: }
2860: }
2861: } elsif ($type eq 'lonstatusmail') {
2862: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2863: }
2864: }
2865: }
2866: if ($position eq 'bottom') {
2867: foreach my $type (@mailings) {
2868: $bccemails{$type} = $settings->{$type}{'bcc'};
2869: if ($settings->{$type}{'include'} ne '') {
2870: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2871: $includestr{$type} = &unescape($includestr{$type});
2872: }
2873: }
2874: if (ref($settings->{'helpform'}) eq 'HASH') {
2875: if (ref($fields) eq 'ARRAY') {
2876: foreach my $field (@{$fields}) {
2877: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 2878: }
1.160.6.78 raeburn 2879: }
2880: if (exists($settings->{'helpform'}{'maxsize'})) {
2881: $maxsize = $settings->{'helpform'}{'maxsize'};
2882: } else {
2883: $maxsize = '1.0';
2884: }
2885: } else {
2886: if (ref($fields) eq 'ARRAY') {
2887: foreach my $field (@{$fields}) {
2888: $currfield{$field} = 'yes';
1.134 raeburn 2889: }
1.28 raeburn 2890: }
1.160.6.78 raeburn 2891: $maxsize = '1.0';
1.28 raeburn 2892: }
2893: }
2894: } else {
1.160.6.78 raeburn 2895: if ($position eq 'top') {
2896: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2897: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2898: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2899: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2900: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2901: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2902: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2903: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
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:').' '.
2962: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
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: }
3023: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
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.79 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.77 raeburn 3229: '</fieldset></td></tr>';
1.160.6.73 raeburn 3230: $count ++;
3231: $$rowtotal += $count;
3232: }
1.160.6.5 raeburn 3233: return $datatable;
1.121 raeburn 3234: }
3235:
1.160.6.77 raeburn 3236: sub adhocbutton {
3237: my ($prefix,$num,$field,$visibility) = @_;
3238: my %lt = &Apache::lonlocal::texthash(
3239: show => 'Show details',
3240: hide => 'Hide details',
3241: );
3242: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3243: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3244: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3245: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3246: }
3247:
3248: sub helpsettings_javascript {
3249: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3250: return unless(ref($roles_by_num) eq 'ARRAY');
3251: my %html_js_lt = &Apache::lonlocal::texthash(
3252: show => 'Show details',
3253: hide => 'Hide details',
3254: );
3255: &html_escape(\%html_js_lt);
3256: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3257: return <<"ENDSCRIPT";
3258: <script type="text/javascript">
3259: // <![CDATA[
3260:
3261: function reorderHelpRoles(form,item) {
3262: var changedVal;
3263: $jstext
3264: var newpos = 'helproles_${total}_pos';
3265: var maxh = 1 + $total;
3266: var current = new Array();
3267: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3268: if (item == newpos) {
3269: changedVal = newitemVal;
3270: } else {
3271: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3272: current[newitemVal] = newpos;
3273: }
3274: for (var i=0; i<helproles.length; i++) {
3275: var elementName = 'helproles_'+helproles[i]+'_pos';
3276: if (elementName != item) {
3277: if (form.elements[elementName]) {
3278: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3279: current[currVal] = elementName;
3280: }
3281: }
3282: }
3283: var oldVal;
3284: for (var j=0; j<maxh; j++) {
3285: if (current[j] == undefined) {
3286: oldVal = j;
3287: }
3288: }
3289: if (oldVal < changedVal) {
3290: for (var k=oldVal+1; k<=changedVal ; k++) {
3291: var elementName = current[k];
3292: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3293: }
3294: } else {
3295: for (var k=changedVal; k<oldVal; k++) {
3296: var elementName = current[k];
3297: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3298: }
3299: }
3300: return;
3301: }
3302:
3303: function helpdeskAccess(num) {
3304: var curraccess = null;
3305: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3306: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3307: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3308: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3309: }
3310: }
3311: }
3312: var shown = Array();
3313: var hidden = Array();
3314: if (curraccess == 'none') {
3315: hidden = Array('$hiddenstr');
3316: } else {
3317: if (curraccess == 'status') {
3318: shown = Array('bystatus');
3319: hidden = Array('notinc','notexc');
3320: } else {
3321: if (curraccess == 'exc') {
3322: shown = Array('notexc');
3323: hidden = Array('notinc','bystatus');
3324: }
3325: if (curraccess == 'inc') {
3326: shown = Array('notinc');
3327: hidden = Array('notexc','bystatus');
3328: }
1.160.6.79 raeburn 3329: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3330: hidden = Array('notinc','notexc','bystatus');
3331: }
3332: }
3333: }
3334: if (hidden.length > 0) {
3335: for (var i=0; i<hidden.length; i++) {
3336: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3337: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3338: }
3339: }
3340: }
3341: if (shown.length > 0) {
3342: for (var i=0; i<shown.length; i++) {
3343: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3344: if (shown[i] == 'privs') {
3345: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3346: } else {
3347: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3348: }
3349: }
3350: }
3351: }
3352: return;
3353: }
3354:
3355: function toggleHelpdeskItem(num,field) {
3356: if (document.getElementById('helproles_'+num+'_'+field)) {
3357: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3358: document.getElementById('helproles_'+num+'_'+field).className =
3359: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3360: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3361: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3362: }
3363: } else {
3364: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3365: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3366: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3367: }
3368: }
3369: }
3370: return;
3371: }
3372:
3373: // ]]>
3374: </script>
3375:
3376: ENDSCRIPT
3377: }
3378:
3379: sub helpdeskroles_access {
3380: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3381: $usertypes,$types,$domhelpdesk) = @_;
3382: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3383: my %lt = &Apache::lonlocal::texthash(
3384: 'rou' => 'Role usage',
3385: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3386: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3387: 'dh' => 'All with domain helpdesk role',
3388: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3389: 'none' => 'None',
3390: 'status' => 'Determined based on institutional status',
3391: 'inc' => 'Include all, but exclude specific personnel',
3392: 'exc' => 'Exclude all, but include specific personnel',
3393: );
3394: my %usecheck = (
3395: all => ' checked="checked"',
3396: );
3397: my %displaydiv = (
3398: status => 'none',
3399: inc => 'none',
3400: exc => 'none',
3401: priv => 'block',
3402: );
3403: my $output;
3404: if (ref($current) eq 'HASH') {
3405: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3406: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3407: $usecheck{$current->{access}} = $usecheck{'all'};
3408: delete($usecheck{'all'});
3409: if ($current->{access} =~ /^(status|inc|exc)$/) {
3410: my $access = $1;
3411: $displaydiv{$access} = 'inline';
3412: } elsif ($current->{access} eq 'none') {
3413: $displaydiv{'priv'} = 'none';
3414: }
3415: }
3416: }
3417: }
3418: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3419: '<p>'.$lt{'whi'}.'</p>';
3420: foreach my $access (@{$accesstypes}) {
3421: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3422: ' onclick="helpdeskAccess('."'$num'".');" />'.
3423: $lt{$access}.'</label>';
3424: if ($access eq 'status') {
3425: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3426: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3427: $othertitle,$usertypes,$types).
3428: '</div>';
3429: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3430: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3431: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3432: '</div>';
3433: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3434: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3435: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3436: '</div>';
3437: }
3438: $output .= '</p>';
3439: }
3440: $output .= '</fieldset>';
3441: return $output;
3442: }
3443:
1.121 raeburn 3444: sub radiobutton_prefs {
1.160.6.16 raeburn 3445: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3446: $additional,$align) = @_;
1.121 raeburn 3447: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3448: (ref($choices) eq 'HASH'));
3449:
3450: my (%checkedon,%checkedoff,$datatable,$css_class);
3451:
3452: foreach my $item (@{$toggles}) {
3453: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3454: $checkedon{$item} = ' checked="checked" ';
3455: $checkedoff{$item} = ' ';
1.121 raeburn 3456: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3457: $checkedoff{$item} = ' checked="checked" ';
3458: $checkedon{$item} = ' ';
3459: }
3460: }
3461: if (ref($settings) eq 'HASH') {
1.121 raeburn 3462: foreach my $item (@{$toggles}) {
1.118 jms 3463: if ($settings->{$item} eq '1') {
3464: $checkedon{$item} = ' checked="checked" ';
3465: $checkedoff{$item} = ' ';
3466: } elsif ($settings->{$item} eq '0') {
3467: $checkedoff{$item} = ' checked="checked" ';
3468: $checkedon{$item} = ' ';
3469: }
3470: }
1.121 raeburn 3471: }
1.160.6.16 raeburn 3472: if ($onclick) {
3473: $onclick = ' onclick="'.$onclick.'"';
3474: }
1.121 raeburn 3475: foreach my $item (@{$toggles}) {
1.118 jms 3476: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3477: $datatable .=
1.160.6.16 raeburn 3478: '<tr'.$css_class.'><td valign="top">'.
3479: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3480: '</span></td>';
3481: if ($align eq 'left') {
3482: $datatable .= '<td class="LC_left_item">';
3483: } else {
3484: $datatable .= '<td class="LC_right_item">';
3485: }
3486: $datatable .=
3487: '<span class="LC_nobreak">'.
1.118 jms 3488: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3489: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3490: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3491: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3492: '</span>'.$additional.
3493: '</td>'.
1.118 jms 3494: '</tr>';
3495: $itemcount ++;
1.121 raeburn 3496: }
3497: return ($datatable,$itemcount);
3498: }
3499:
3500: sub print_coursedefaults {
1.139 raeburn 3501: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3502: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3503: my $itemcount = 1;
1.160.6.16 raeburn 3504: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3505: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3506: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3507: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3508: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3509: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3510: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3511: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3512: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3513: );
1.160.6.21 raeburn 3514: my %staticdefaults = (
3515: anonsurvey_threshold => 10,
3516: uploadquota => 500,
1.160.6.57 raeburn 3517: postsubmit => 60,
1.160.6.70 raeburn 3518: mysqltables => 172800,
1.160.6.21 raeburn 3519: );
1.139 raeburn 3520: if ($position eq 'top') {
1.160.6.57 raeburn 3521: %defaultchecked = (
3522: 'uselcmath' => 'on',
3523: 'usejsme' => 'on',
1.160.6.64 raeburn 3524: 'canclone' => 'none',
1.160.6.57 raeburn 3525: );
3526: @toggles = ('uselcmath','usejsme');
1.139 raeburn 3527: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3528: \%choices,$itemcount);
1.160.6.64 raeburn 3529: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3530: $datatable .=
3531: '<tr'.$css_class.'><td valign="top">'.
3532: '<span class="LC_nobreak">'.$choices{'canclone'}.
3533: '</span></td><td class="LC_left_item">';
3534: my $currcanclone = 'none';
3535: my $onclick;
3536: my @cloneoptions = ('none','domain');
3537: my %clonetitles = (
3538: none => 'No additional course requesters',
3539: domain => "Any course requester in course's domain",
3540: instcode => 'Course requests for official courses ...',
3541: );
3542: my (%codedefaults,@code_order,@posscodes);
3543: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3544: \@code_order) eq 'ok') {
3545: if (@code_order > 0) {
3546: push(@cloneoptions,'instcode');
3547: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3548: }
3549: }
3550: if (ref($settings) eq 'HASH') {
3551: if ($settings->{'canclone'}) {
3552: if (ref($settings->{'canclone'}) eq 'HASH') {
3553: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3554: if (@code_order > 0) {
3555: $currcanclone = 'instcode';
3556: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3557: }
3558: }
3559: } elsif ($settings->{'canclone'} eq 'domain') {
3560: $currcanclone = $settings->{'canclone'};
3561: }
3562: }
3563: }
3564: foreach my $option (@cloneoptions) {
3565: my ($checked,$additional);
3566: if ($currcanclone eq $option) {
3567: $checked = ' checked="checked"';
3568: }
3569: if ($option eq 'instcode') {
3570: if (@code_order) {
3571: my $show = 'none';
3572: if ($checked) {
3573: $show = 'block';
3574: }
3575: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3576: &mt('Institutional codes for new and cloned course have identical:').
3577: '<br />';
3578: foreach my $item (@code_order) {
3579: my $codechk;
3580: if ($checked) {
3581: if (grep(/^\Q$item\E$/,@posscodes)) {
3582: $codechk = ' checked="checked"';
3583: }
3584: }
3585: $additional .= '<label>'.
3586: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3587: $item.'</label>';
3588: }
3589: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3590: }
3591: }
3592: $datatable .=
3593: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3594: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3595: '</label> '.$additional.'</span><br />';
3596: }
3597: $datatable .= '</td>'.
3598: '</tr>';
3599: $itemcount ++;
1.139 raeburn 3600: } else {
3601: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3602: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3603: my $currusecredits = 0;
1.160.6.57 raeburn 3604: my $postsubmitclient = 1;
1.160.6.30 raeburn 3605: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3606: if (ref($settings) eq 'HASH') {
3607: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3608: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3609: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3610: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3611: }
3612: }
1.160.6.16 raeburn 3613: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3614: foreach my $type (@types) {
3615: next if ($type eq 'community');
3616: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3617: if ($defcredits{$type} ne '') {
3618: $currusecredits = 1;
3619: }
3620: }
3621: }
3622: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3623: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3624: $postsubmitclient = 0;
3625: foreach my $type (@types) {
3626: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3627: }
3628: } else {
3629: foreach my $type (@types) {
3630: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3631: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3632: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3633: } else {
3634: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3635: }
3636: } else {
3637: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3638: }
3639: }
3640: }
3641: } else {
3642: foreach my $type (@types) {
3643: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3644: }
3645: }
1.160.6.70 raeburn 3646: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3647: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3648: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3649: }
3650: } else {
3651: foreach my $type (@types) {
3652: $currmysql{$type} = $staticdefaults{'mysqltables'};
3653: }
3654: }
1.160.6.58 raeburn 3655: } else {
3656: foreach my $type (@types) {
3657: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3658: }
1.139 raeburn 3659: }
3660: if (!$currdefresponder) {
1.160.6.21 raeburn 3661: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3662: } elsif ($currdefresponder < 1) {
3663: $currdefresponder = 1;
3664: }
1.160.6.21 raeburn 3665: foreach my $type (@types) {
3666: if ($curruploadquota{$type} eq '') {
3667: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3668: }
3669: }
1.139 raeburn 3670: $datatable .=
1.160.6.16 raeburn 3671: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3672: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3673: '</span></td>'.
3674: '<td class="LC_right_item"><span class="LC_nobreak">'.
3675: '<input type="text" name="anonsurvey_threshold"'.
3676: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3677: '</td></tr>'."\n";
3678: $itemcount ++;
3679: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3680: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3681: $choices{'uploadquota'}.
3682: '</span></td>'.
3683: '<td align="right" class="LC_right_item">'.
3684: '<table><tr>';
1.160.6.21 raeburn 3685: foreach my $type (@types) {
3686: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3687: '<input type="text" name="uploadquota_'.$type.'"'.
3688: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3689: }
3690: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3691: $itemcount ++;
1.160.6.40 raeburn 3692: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3693: my $display = 'none';
3694: if ($currusecredits) {
3695: $display = 'block';
3696: }
3697: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3698: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3699: foreach my $type (@types) {
3700: next if ($type eq 'community');
3701: $additional .= '<td align="center">'.&mt($type).'<br />'.
3702: '<input type="text" name="'.$type.'_credits"'.
3703: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3704: }
3705: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3706: %defaultchecked = ('coursecredits' => 'off');
3707: @toggles = ('coursecredits');
3708: my $current = {
3709: 'coursecredits' => $currusecredits,
3710: };
3711: (my $table,$itemcount) =
3712: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3713: \%choices,$itemcount,$onclick,$additional,'left');
3714: $datatable .= $table;
3715: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3716: my $display = 'none';
3717: if ($postsubmitclient) {
3718: $display = 'block';
3719: }
3720: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3721: &mt('Number of seconds submit is disabled').'<br />'.
3722: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3723: '<table><tr>';
1.160.6.57 raeburn 3724: foreach my $type (@types) {
3725: $additional .= '<td align="center">'.&mt($type).'<br />'.
3726: '<input type="text" name="'.$type.'_timeout" value="'.
3727: $deftimeout{$type}.'" size="5" /></td>';
3728: }
3729: $additional .= '</tr></table></div>'."\n";
3730: %defaultchecked = ('postsubmit' => 'on');
3731: @toggles = ('postsubmit');
1.160.6.70 raeburn 3732: $current = {
3733: 'postsubmit' => $postsubmitclient,
3734: };
1.160.6.57 raeburn 3735: ($table,$itemcount) =
3736: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3737: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3738: $datatable .= $table;
1.160.6.70 raeburn 3739: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3740: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3741: $choices{'mysqltables'}.
3742: '</span></td>'.
3743: '<td align="right" class="LC_right_item">'.
3744: '<table><tr>';
3745: foreach my $type (@types) {
3746: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3747: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 3748: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 3749: }
3750: $datatable .= '</tr></table></td></tr>'."\n";
3751: $itemcount ++;
3752:
1.160.6.37 raeburn 3753: }
3754: $$rowtotal += $itemcount;
3755: return $datatable;
3756: }
3757:
3758: sub print_selfenrollment {
3759: my ($position,$dom,$settings,$rowtotal) = @_;
3760: my ($css_class,$datatable);
3761: my $itemcount = 1;
3762: my @types = ('official','unofficial','community','textbook');
3763: if (($position eq 'top') || ($position eq 'middle')) {
3764: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3765: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3766: my @rows;
3767: my $key;
3768: if ($position eq 'top') {
3769: $key = 'admin';
3770: if (ref($rowsref) eq 'ARRAY') {
3771: @rows = @{$rowsref};
3772: }
3773: } elsif ($position eq 'middle') {
3774: $key = 'default';
3775: @rows = ('types','registered','approval','limit');
3776: }
3777: foreach my $row (@rows) {
3778: if (defined($titlesref->{$row})) {
3779: $itemcount ++;
3780: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3781: $datatable .= '<tr'.$css_class.'>'.
3782: '<td>'.$titlesref->{$row}.'</td>'.
3783: '<td class="LC_left_item">'.
3784: '<table><tr>';
3785: my (%current,%currentcap);
3786: if (ref($settings) eq 'HASH') {
3787: if (ref($settings->{$key}) eq 'HASH') {
3788: foreach my $type (@types) {
3789: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3790: $current{$type} = $settings->{$key}->{$type}->{$row};
3791: }
3792: if (($row eq 'limit') && ($key eq 'default')) {
3793: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3794: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3795: }
3796: }
3797: }
3798: }
3799: }
3800: my %roles = (
3801: '0' => &Apache::lonnet::plaintext('dc'),
3802: );
3803:
3804: foreach my $type (@types) {
3805: unless (($row eq 'registered') && ($key eq 'default')) {
3806: $datatable .= '<th>'.&mt($type).'</th>';
3807: }
3808: }
3809: unless (($row eq 'registered') && ($key eq 'default')) {
3810: $datatable .= '</tr><tr>';
3811: }
3812: foreach my $type (@types) {
3813: if ($type eq 'community') {
3814: $roles{'1'} = &mt('Community personnel');
3815: } else {
3816: $roles{'1'} = &mt('Course personnel');
3817: }
3818: $datatable .= '<td style="vertical-align: top">';
3819: if ($position eq 'top') {
3820: my %checked;
3821: if ($current{$type} eq '0') {
3822: $checked{'0'} = ' checked="checked"';
3823: } else {
3824: $checked{'1'} = ' checked="checked"';
3825: }
3826: foreach my $role ('1','0') {
3827: $datatable .= '<span class="LC_nobreak"><label>'.
3828: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3829: 'value="'.$role.'"'.$checked{$role}.' />'.
3830: $roles{$role}.'</label></span> ';
3831: }
3832: } else {
3833: if ($row eq 'types') {
3834: my %checked;
3835: if ($current{$type} =~ /^(all|dom)$/) {
3836: $checked{$1} = ' checked="checked"';
3837: } else {
3838: $checked{''} = ' checked="checked"';
3839: }
3840: foreach my $val ('','dom','all') {
3841: $datatable .= '<span class="LC_nobreak"><label>'.
3842: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3843: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3844: }
3845: } elsif ($row eq 'registered') {
3846: my %checked;
3847: if ($current{$type} eq '1') {
3848: $checked{'1'} = ' checked="checked"';
3849: } else {
3850: $checked{'0'} = ' checked="checked"';
3851: }
3852: foreach my $val ('0','1') {
3853: $datatable .= '<span class="LC_nobreak"><label>'.
3854: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3855: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3856: }
3857: } elsif ($row eq 'approval') {
3858: my %checked;
3859: if ($current{$type} =~ /^([12])$/) {
3860: $checked{$1} = ' checked="checked"';
3861: } else {
3862: $checked{'0'} = ' checked="checked"';
3863: }
3864: for my $val (0..2) {
3865: $datatable .= '<span class="LC_nobreak"><label>'.
3866: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3867: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3868: }
3869: } elsif ($row eq 'limit') {
3870: my %checked;
3871: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3872: $checked{$1} = ' checked="checked"';
3873: } else {
3874: $checked{'none'} = ' checked="checked"';
3875: }
3876: my $cap;
3877: if ($currentcap{$type} =~ /^\d+$/) {
3878: $cap = $currentcap{$type};
3879: }
3880: foreach my $val ('none','allstudents','selfenrolled') {
3881: $datatable .= '<span class="LC_nobreak"><label>'.
3882: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3883: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3884: }
3885: $datatable .= '<br />'.
3886: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3887: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3888: '</span>';
3889: }
3890: }
3891: $datatable .= '</td>';
3892: }
3893: $datatable .= '</tr>';
3894: }
3895: $datatable .= '</table></td></tr>';
3896: }
3897: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3898: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3899: }
3900: $$rowtotal += $itemcount;
3901: return $datatable;
3902: }
3903:
3904: sub print_validation_rows {
3905: my ($caller,$dom,$settings,$rowtotal) = @_;
3906: my ($itemsref,$namesref,$fieldsref);
3907: if ($caller eq 'selfenroll') {
3908: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3909: } elsif ($caller eq 'requestcourses') {
3910: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3911: }
3912: my %currvalidation;
3913: if (ref($settings) eq 'HASH') {
3914: if (ref($settings->{'validation'}) eq 'HASH') {
3915: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3916: }
1.160.6.39 raeburn 3917: }
3918: my $datatable;
3919: my $itemcount = 0;
3920: foreach my $item (@{$itemsref}) {
3921: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3922: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3923: $namesref->{$item}.
3924: '</span></td>'.
3925: '<td class="LC_left_item">';
3926: if (($item eq 'url') || ($item eq 'button')) {
3927: $datatable .= '<span class="LC_nobreak">'.
3928: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3929: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3930: } elsif ($item eq 'fields') {
3931: my @currfields;
3932: if (ref($currvalidation{$item}) eq 'ARRAY') {
3933: @currfields = @{$currvalidation{$item}};
3934: }
3935: foreach my $field (@{$fieldsref}) {
3936: my $check = '';
3937: if (grep(/^\Q$field\E$/,@currfields)) {
3938: $check = ' checked="checked"';
3939: }
3940: $datatable .= '<span class="LC_nobreak"><label>'.
3941: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3942: ' value="'.$field.'"'.$check.' />'.$field.
3943: '</label></span> ';
3944: }
3945: } elsif ($item eq 'markup') {
3946: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
3947: $currvalidation{$item}.
1.160.6.37 raeburn 3948: '</textarea>';
1.160.6.39 raeburn 3949: }
3950: $datatable .= '</td></tr>'."\n";
3951: if (ref($rowtotal)) {
1.160.6.37 raeburn 3952: $itemcount ++;
3953: }
1.139 raeburn 3954: }
1.160.6.39 raeburn 3955: if ($caller eq 'requestcourses') {
3956: my %currhash;
1.160.6.51 raeburn 3957: if (ref($settings) eq 'HASH') {
3958: if (ref($settings->{'validation'}) eq 'HASH') {
3959: if ($settings->{'validation'}{'dc'} ne '') {
3960: $currhash{$settings->{'validation'}{'dc'}} = 1;
3961: }
1.160.6.39 raeburn 3962: }
3963: }
3964: my $numinrow = 2;
3965: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3966: 'validationdc',%currhash);
1.160.6.50 raeburn 3967: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3968: $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39 raeburn 3969: if ($numdc > 1) {
1.160.6.50 raeburn 3970: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3971: } else {
1.160.6.50 raeburn 3972: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3973: }
1.160.6.50 raeburn 3974: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3975: $itemcount ++;
3976: }
3977: if (ref($rowtotal)) {
3978: $$rowtotal += $itemcount;
3979: }
1.121 raeburn 3980: return $datatable;
1.118 jms 3981: }
3982:
1.137 raeburn 3983: sub print_usersessions {
3984: my ($position,$dom,$settings,$rowtotal) = @_;
3985: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3986: my (%by_ip,%by_location,@intdoms);
3987: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3988:
3989: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3990: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3991: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3992: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3993: my $itemcount = 1;
3994: if ($position eq 'top') {
1.152 raeburn 3995: if (keys(%serverhomes) > 1) {
1.145 raeburn 3996: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 3997: my $curroffloadnow;
3998: if (ref($settings) eq 'HASH') {
3999: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4000: $curroffloadnow = $settings->{'offloadnow'};
4001: }
4002: }
4003: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4004: } else {
1.140 raeburn 4005: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4006: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 4007: }
1.137 raeburn 4008: } else {
1.145 raeburn 4009: if (keys(%by_location) == 0) {
4010: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4011: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 4012: } else {
4013: my %lt = &usersession_titles();
4014: my $numinrow = 5;
4015: my $prefix;
4016: my @types;
4017: if ($position eq 'bottom') {
4018: $prefix = 'remote';
4019: @types = ('version','excludedomain','includedomain');
4020: } else {
4021: $prefix = 'hosted';
4022: @types = ('excludedomain','includedomain');
4023: }
4024: my (%current,%checkedon,%checkedoff);
4025: my @lcversions = &Apache::lonnet::all_loncaparevs();
4026: my @locations = sort(keys(%by_location));
4027: foreach my $type (@types) {
4028: $checkedon{$type} = '';
4029: $checkedoff{$type} = ' checked="checked"';
4030: }
4031: if (ref($settings) eq 'HASH') {
4032: if (ref($settings->{$prefix}) eq 'HASH') {
4033: foreach my $key (keys(%{$settings->{$prefix}})) {
4034: $current{$key} = $settings->{$prefix}{$key};
4035: if ($key eq 'version') {
4036: if ($current{$key} ne '') {
4037: $checkedon{$key} = ' checked="checked"';
4038: $checkedoff{$key} = '';
4039: }
4040: } elsif (ref($current{$key}) eq 'ARRAY') {
4041: $checkedon{$key} = ' checked="checked"';
4042: $checkedoff{$key} = '';
4043: }
1.137 raeburn 4044: }
4045: }
4046: }
1.145 raeburn 4047: foreach my $type (@types) {
4048: next if ($type ne 'version' && !@locations);
4049: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4050: $datatable .= '<tr'.$css_class.'>
4051: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4052: <span class="LC_nobreak">
4053: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4054: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4055: if ($type eq 'version') {
4056: my $selector = '<select name="'.$prefix.'_version">';
4057: foreach my $version (@lcversions) {
4058: my $selected = '';
4059: if ($current{'version'} eq $version) {
4060: $selected = ' selected="selected"';
4061: }
4062: $selector .= ' <option value="'.$version.'"'.
4063: $selected.'>'.$version.'</option>';
4064: }
4065: $selector .= '</select> ';
4066: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4067: } else {
4068: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4069: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4070: ' />'.(' 'x2).
4071: '<input type="button" value="'.&mt('uncheck all').'" '.
4072: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4073: "\n".
4074: '</div><div><table>';
4075: my $rem;
4076: for (my $i=0; $i<@locations; $i++) {
4077: my ($showloc,$value,$checkedtype);
4078: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4079: my $ip = $by_location{$locations[$i]}->[0];
4080: if (ref($by_ip{$ip}) eq 'ARRAY') {
4081: $value = join(':',@{$by_ip{$ip}});
4082: $showloc = join(', ',@{$by_ip{$ip}});
4083: if (ref($current{$type}) eq 'ARRAY') {
4084: foreach my $loc (@{$by_ip{$ip}}) {
4085: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4086: $checkedtype = ' checked="checked"';
4087: last;
4088: }
4089: }
1.138 raeburn 4090: }
4091: }
4092: }
1.145 raeburn 4093: $rem = $i%($numinrow);
4094: if ($rem == 0) {
4095: if ($i > 0) {
4096: $datatable .= '</tr>';
4097: }
4098: $datatable .= '<tr>';
4099: }
4100: $datatable .= '<td class="LC_left_item">'.
4101: '<span class="LC_nobreak"><label>'.
4102: '<input type="checkbox" name="'.$prefix.'_'.$type.
4103: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4104: '</label></span></td>';
1.137 raeburn 4105: }
1.145 raeburn 4106: $rem = @locations%($numinrow);
4107: my $colsleft = $numinrow - $rem;
4108: if ($colsleft > 1 ) {
4109: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4110: ' </td>';
4111: } elsif ($colsleft == 1) {
4112: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4113: }
1.145 raeburn 4114: $datatable .= '</tr></table>';
1.137 raeburn 4115: }
1.145 raeburn 4116: $datatable .= '</td></tr>';
4117: $itemcount ++;
1.137 raeburn 4118: }
4119: }
4120: }
4121: $$rowtotal += $itemcount;
4122: return $datatable;
4123: }
4124:
1.138 raeburn 4125: sub build_location_hashes {
4126: my ($intdoms,$by_ip,$by_location) = @_;
4127: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4128: (ref($by_location) eq 'HASH'));
4129: my %iphost = &Apache::lonnet::get_iphost();
4130: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4131: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4132: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4133: foreach my $id (@{$iphost{$primary_ip}}) {
4134: my $intdom = &Apache::lonnet::internet_dom($id);
4135: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4136: push(@{$intdoms},$intdom);
4137: }
4138: }
4139: }
4140: foreach my $ip (keys(%iphost)) {
4141: if (ref($iphost{$ip}) eq 'ARRAY') {
4142: foreach my $id (@{$iphost{$ip}}) {
4143: my $location = &Apache::lonnet::internet_dom($id);
4144: if ($location) {
4145: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4146: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4147: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4148: push(@{$by_ip->{$ip}},$location);
4149: }
4150: } else {
4151: $by_ip->{$ip} = [$location];
4152: }
4153: }
4154: }
4155: }
4156: }
4157: foreach my $ip (sort(keys(%{$by_ip}))) {
4158: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4159: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4160: my $first = $by_ip->{$ip}->[0];
4161: if (ref($by_location->{$first}) eq 'ARRAY') {
4162: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4163: push(@{$by_location->{$first}},$ip);
4164: }
4165: } else {
4166: $by_location->{$first} = [$ip];
4167: }
4168: }
4169: }
4170: return;
4171: }
4172:
1.145 raeburn 4173: sub current_offloads_to {
4174: my ($dom,$settings,$servers) = @_;
4175: my (%spareid,%otherdomconfigs);
1.152 raeburn 4176: if (ref($servers) eq 'HASH') {
1.145 raeburn 4177: foreach my $lonhost (sort(keys(%{$servers}))) {
4178: my $gotspares;
1.152 raeburn 4179: if (ref($settings) eq 'HASH') {
4180: if (ref($settings->{'spares'}) eq 'HASH') {
4181: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4182: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4183: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4184: $gotspares = 1;
4185: }
1.145 raeburn 4186: }
4187: }
4188: unless ($gotspares) {
4189: my $gotspares;
4190: my $serverhomeID =
4191: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4192: my $serverhomedom =
4193: &Apache::lonnet::host_domain($serverhomeID);
4194: if ($serverhomedom ne $dom) {
4195: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4196: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4197: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4198: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4199: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4200: $gotspares = 1;
4201: }
4202: }
4203: } else {
4204: $otherdomconfigs{$serverhomedom} =
4205: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4206: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4207: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4208: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4209: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4210: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4211: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4212: $gotspares = 1;
4213: }
4214: }
4215: }
4216: }
4217: }
4218: }
4219: }
4220: unless ($gotspares) {
4221: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4222: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4223: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4224: } else {
4225: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4226: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4227: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4228: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4229: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4230: } else {
1.150 raeburn 4231: my %what = (
4232: spareid => 1,
4233: );
4234: my ($result,$returnhash) =
4235: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4236: if ($result eq 'ok') {
4237: if (ref($returnhash) eq 'HASH') {
4238: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4239: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4240: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4241: }
4242: }
1.145 raeburn 4243: }
4244: }
4245: }
4246: }
4247: }
4248: }
4249: return %spareid;
4250: }
4251:
4252: sub spares_row {
1.160.6.61 raeburn 4253: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4254: my $css_class;
4255: my $numinrow = 4;
4256: my $itemcount = 1;
4257: my $datatable;
1.152 raeburn 4258: my %typetitles = &sparestype_titles();
4259: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4260: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4261: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4262: my ($othercontrol,$serverdom);
4263: if ($serverhome ne $server) {
4264: $serverdom = &Apache::lonnet::host_domain($serverhome);
4265: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4266: } else {
4267: $serverdom = &Apache::lonnet::host_domain($server);
4268: if ($serverdom ne $dom) {
4269: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4270: }
4271: }
4272: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4273: my $checkednow;
4274: if (ref($curroffloadnow) eq 'HASH') {
4275: if ($curroffloadnow->{$server}) {
4276: $checkednow = ' checked="checked"';
4277: }
4278: }
1.145 raeburn 4279: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4280: $datatable .= '<tr'.$css_class.'>
4281: <td rowspan="2">
1.160.6.13 raeburn 4282: <span class="LC_nobreak">'.
4283: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4284: ,'<b>'.$server.'</b>').'</span><br />'.
4285: '<span class="LC_nobreak">'."\n".
4286: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4287: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4288: "\n";
1.145 raeburn 4289: my (%current,%canselect);
1.152 raeburn 4290: my @choices =
4291: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4292: foreach my $type ('primary','default') {
4293: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4294: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4295: my @spares = @{$spareid->{$server}{$type}};
4296: if (@spares > 0) {
1.152 raeburn 4297: if ($othercontrol) {
4298: $current{$type} = join(', ',@spares);
4299: } else {
4300: $current{$type} .= '<table>';
4301: my $numspares = scalar(@spares);
4302: for (my $i=0; $i<@spares; $i++) {
4303: my $rem = $i%($numinrow);
4304: if ($rem == 0) {
4305: if ($i > 0) {
4306: $current{$type} .= '</tr>';
4307: }
4308: $current{$type} .= '<tr>';
1.145 raeburn 4309: }
1.152 raeburn 4310: $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'".');" /> '.
4311: $spareid->{$server}{$type}[$i].
4312: '</label></td>'."\n";
4313: }
4314: my $rem = @spares%($numinrow);
4315: my $colsleft = $numinrow - $rem;
4316: if ($colsleft > 1 ) {
4317: $current{$type} .= '<td colspan="'.$colsleft.
4318: '" class="LC_left_item">'.
4319: ' </td>';
4320: } elsif ($colsleft == 1) {
4321: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4322: }
1.152 raeburn 4323: $current{$type} .= '</tr></table>';
1.150 raeburn 4324: }
1.145 raeburn 4325: }
4326: }
4327: if ($current{$type} eq '') {
4328: $current{$type} = &mt('None specified');
4329: }
1.152 raeburn 4330: if ($othercontrol) {
4331: if ($type eq 'primary') {
4332: $canselect{$type} = $othercontrol;
4333: }
4334: } else {
4335: $canselect{$type} =
4336: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4337: '<select name="newspare_'.$type.'_'.$server.'" '.
4338: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4339: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4340: if (@choices > 0) {
4341: foreach my $lonhost (@choices) {
4342: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4343: }
4344: }
4345: $canselect{$type} .= '</select>'."\n";
4346: }
4347: } else {
4348: $current{$type} = &mt('Could not be determined');
4349: if ($type eq 'primary') {
4350: $canselect{$type} = $othercontrol;
4351: }
1.145 raeburn 4352: }
1.152 raeburn 4353: if ($type eq 'default') {
4354: $datatable .= '<tr'.$css_class.'>';
4355: }
4356: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4357: '<td>'.$current{$type}.'</td>'."\n".
4358: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4359: }
4360: $itemcount ++;
4361: }
4362: }
4363: $$rowtotal += $itemcount;
4364: return $datatable;
4365: }
4366:
1.152 raeburn 4367: sub possible_newspares {
4368: my ($server,$currspares,$serverhomes,$altids) = @_;
4369: my $serverhostname = &Apache::lonnet::hostname($server);
4370: my %excluded;
4371: if ($serverhostname ne '') {
4372: %excluded = (
4373: $serverhostname => 1,
4374: );
4375: }
4376: if (ref($currspares) eq 'HASH') {
4377: foreach my $type (keys(%{$currspares})) {
4378: if (ref($currspares->{$type}) eq 'ARRAY') {
4379: if (@{$currspares->{$type}} > 0) {
4380: foreach my $curr (@{$currspares->{$type}}) {
4381: my $hostname = &Apache::lonnet::hostname($curr);
4382: $excluded{$hostname} = 1;
4383: }
4384: }
4385: }
4386: }
4387: }
4388: my @choices;
4389: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4390: if (keys(%{$serverhomes}) > 1) {
4391: foreach my $name (sort(keys(%{$serverhomes}))) {
4392: unless ($excluded{$name}) {
4393: if (exists($altids->{$serverhomes->{$name}})) {
4394: push(@choices,$altids->{$serverhomes->{$name}});
4395: } else {
4396: push(@choices,$serverhomes->{$name});
1.145 raeburn 4397: }
4398: }
4399: }
4400: }
4401: }
1.152 raeburn 4402: return sort(@choices);
1.145 raeburn 4403: }
4404:
1.150 raeburn 4405: sub print_loadbalancing {
4406: my ($dom,$settings,$rowtotal) = @_;
4407: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4408: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4409: my $numinrow = 1;
4410: my $datatable;
4411: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 4412: my (%currbalancer,%currtargets,%currrules,%existing);
4413: if (ref($settings) eq 'HASH') {
4414: %existing = %{$settings};
4415: }
4416: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4417: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4418: \%currtargets,\%currrules);
1.150 raeburn 4419: } else {
4420: return;
4421: }
4422: my ($othertitle,$usertypes,$types) =
4423: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 4424: my $rownum = 8;
1.150 raeburn 4425: if (ref($types) eq 'ARRAY') {
4426: $rownum += scalar(@{$types});
4427: }
1.160.6.7 raeburn 4428: my @css_class = ('LC_odd_row','LC_even_row');
4429: my $balnum = 0;
4430: my $islast;
4431: my (@toshow,$disabledtext);
4432: if (keys(%currbalancer) > 0) {
4433: @toshow = sort(keys(%currbalancer));
4434: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4435: push(@toshow,'');
4436: }
4437: } else {
4438: @toshow = ('');
4439: $disabledtext = &mt('No existing load balancer');
4440: }
4441: foreach my $lonhost (@toshow) {
4442: if ($balnum == scalar(@toshow)-1) {
4443: $islast = 1;
4444: } else {
4445: $islast = 0;
4446: }
4447: my $cssidx = $balnum%2;
4448: my $targets_div_style = 'display: none';
4449: my $disabled_div_style = 'display: block';
4450: my $homedom_div_style = 'display: none';
4451: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4452: '<td rowspan="'.$rownum.'" valign="top">'.
4453: '<p>';
4454: if ($lonhost eq '') {
4455: $datatable .= '<span class="LC_nobreak">';
4456: if (keys(%currbalancer) > 0) {
4457: $datatable .= &mt('Add balancer:');
4458: } else {
4459: $datatable .= &mt('Enable balancer:');
4460: }
4461: $datatable .= ' '.
4462: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4463: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4464: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4465: '<option value="" selected="selected">'.&mt('None').
4466: '</option>'."\n";
4467: foreach my $server (sort(keys(%servers))) {
4468: next if ($currbalancer{$server});
4469: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4470: }
4471: $datatable .=
4472: '</select>'."\n".
4473: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4474: } else {
4475: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4476: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4477: &mt('Stop balancing').'</label>'.
4478: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4479: $targets_div_style = 'display: block';
4480: $disabled_div_style = 'display: none';
4481: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4482: $homedom_div_style = 'display: block';
4483: }
4484: }
4485: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4486: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4487: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4488: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4489: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4490: my @sparestypes = ('primary','default');
4491: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 4492: my %hostherechecked = (
4493: no => ' checked="checked"',
4494: );
1.160.6.7 raeburn 4495: foreach my $sparetype (@sparestypes) {
4496: my $targettable;
4497: for (my $i=0; $i<$numspares; $i++) {
4498: my $checked;
4499: if (ref($currtargets{$lonhost}) eq 'HASH') {
4500: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4501: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4502: $checked = ' checked="checked"';
4503: }
4504: }
4505: }
4506: my ($chkboxval,$disabled);
4507: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4508: $chkboxval = $spares[$i];
4509: }
4510: if (exists($currbalancer{$spares[$i]})) {
4511: $disabled = ' disabled="disabled"';
4512: }
4513: $targettable .=
1.160.6.55 raeburn 4514: '<td><span class="LC_nobreak"><label>'.
4515: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 4516: $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 4517: '</span></label></span></td>';
1.160.6.7 raeburn 4518: my $rem = $i%($numinrow);
4519: if ($rem == 0) {
4520: if (($i > 0) && ($i < $numspares-1)) {
4521: $targettable .= '</tr>';
4522: }
4523: if ($i < $numspares-1) {
4524: $targettable .= '<tr>';
1.150 raeburn 4525: }
4526: }
4527: }
1.160.6.7 raeburn 4528: if ($targettable ne '') {
4529: my $rem = $numspares%($numinrow);
4530: my $colsleft = $numinrow - $rem;
4531: if ($colsleft > 1 ) {
4532: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4533: ' </td>';
4534: } elsif ($colsleft == 1) {
4535: $targettable .= '<td class="LC_left_item"> </td>';
4536: }
4537: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4538: '<table><tr>'.$targettable.'</tr></table><br />';
4539: }
1.160.6.76 raeburn 4540: $hostherechecked{$sparetype} = '';
4541: if (ref($currtargets{$lonhost}) eq 'HASH') {
4542: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4543: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4544: $hostherechecked{$sparetype} = ' checked="checked"';
4545: $hostherechecked{'no'} = '';
4546: }
4547: }
4548: }
4549: }
4550: $datatable .= &mt('Hosting on balancer itself').'<br />'.
4551: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
4552: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
4553: foreach my $sparetype (@sparestypes) {
4554: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
4555: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
4556: '</i></label><br />';
1.160.6.7 raeburn 4557: }
4558: $datatable .= '</div></td></tr>'.
4559: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4560: $othertitle,$usertypes,$types,\%servers,
4561: \%currbalancer,$lonhost,
4562: $targets_div_style,$homedom_div_style,
4563: $css_class[$cssidx],$balnum,$islast);
4564: $$rowtotal += $rownum;
4565: $balnum ++;
4566: }
4567: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4568: return $datatable;
4569: }
4570:
4571: sub get_loadbalancers_config {
4572: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4573: return unless ((ref($servers) eq 'HASH') &&
4574: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4575: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4576: if (keys(%{$existing}) > 0) {
4577: my $oldlonhost;
4578: foreach my $key (sort(keys(%{$existing}))) {
4579: if ($key eq 'lonhost') {
4580: $oldlonhost = $existing->{'lonhost'};
4581: $currbalancer->{$oldlonhost} = 1;
4582: } elsif ($key eq 'targets') {
4583: if ($oldlonhost) {
4584: $currtargets->{$oldlonhost} = $existing->{'targets'};
4585: }
4586: } elsif ($key eq 'rules') {
4587: if ($oldlonhost) {
4588: $currrules->{$oldlonhost} = $existing->{'rules'};
4589: }
4590: } elsif (ref($existing->{$key}) eq 'HASH') {
4591: $currbalancer->{$key} = 1;
4592: $currtargets->{$key} = $existing->{$key}{'targets'};
4593: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4594: }
4595: }
1.160.6.7 raeburn 4596: } else {
4597: my ($balancerref,$targetsref) =
4598: &Apache::lonnet::get_lonbalancer_config($servers);
4599: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4600: foreach my $server (sort(keys(%{$balancerref}))) {
4601: $currbalancer->{$server} = 1;
4602: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4603: }
4604: }
4605: }
1.160.6.7 raeburn 4606: return;
1.150 raeburn 4607: }
4608:
4609: sub loadbalancing_rules {
4610: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 4611: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4612: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4613: my $output;
1.160.6.7 raeburn 4614: my $num = 0;
4615: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4616: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4617: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4618: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 4619: $num ++;
1.150 raeburn 4620: my $current;
4621: if (ref($currrules) eq 'HASH') {
4622: $current = $currrules->{$type};
4623: }
1.160.6.55 raeburn 4624: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 4625: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4626: $current = '';
4627: }
4628: }
4629: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 4630: $servers,$currbalancer,$lonhost,$dom,
4631: $targets_div_style,$homedom_div_style,
4632: $css_class,$balnum,$num,$islast);
1.150 raeburn 4633: }
4634: }
4635: return $output;
4636: }
4637:
4638: sub loadbalancing_titles {
4639: my ($dom,$intdom,$usertypes,$types) = @_;
4640: my %othertypes = (
4641: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4642: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4643: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4644: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 4645: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4646: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4647: );
1.160.6.26 raeburn 4648: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.84.4. (raeburn 4649:): my @available;
1.150 raeburn 4650: if (ref($types) eq 'ARRAY') {
1.160.6.84.4. (raeburn 4651:): @available = @{$types};
4652:): }
4653:): unless (grep(/^default$/,@available)) {
4654:): push(@available,'default');
1.150 raeburn 4655: }
1.160.6.84.4. (raeburn 4656:): unshift(@alltypes,@available);
1.150 raeburn 4657: my %titles;
4658: foreach my $type (@alltypes) {
4659: if ($type =~ /^_LC_/) {
4660: $titles{$type} = $othertypes{$type};
4661: } elsif ($type eq 'default') {
4662: $titles{$type} = &mt('All users from [_1]',$dom);
4663: if (ref($types) eq 'ARRAY') {
4664: if (@{$types} > 0) {
4665: $titles{$type} = &mt('Other users from [_1]',$dom);
4666: }
4667: }
4668: } elsif (ref($usertypes) eq 'HASH') {
4669: $titles{$type} = $usertypes->{$type};
4670: }
4671: }
4672: return (\@alltypes,\%othertypes,\%titles);
4673: }
4674:
4675: sub loadbalance_rule_row {
1.160.6.7 raeburn 4676: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4677: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4678: my @rulenames;
1.150 raeburn 4679: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4680: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4681: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4682: } else {
1.160.6.26 raeburn 4683: @rulenames = ('default','homeserver');
4684: if ($type eq '_LC_external') {
4685: push(@rulenames,'externalbalancer');
4686: } else {
4687: push(@rulenames,'specific');
4688: }
4689: push(@rulenames,'none');
1.150 raeburn 4690: }
4691: my $style = $targets_div_style;
1.160.6.55 raeburn 4692: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4693: $style = $homedom_div_style;
4694: }
1.160.6.7 raeburn 4695: my $space;
4696: if ($islast && $num == 1) {
4697: $space = '<div display="inline-block"> </div>';
4698: }
4699: my $output =
4700: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4701: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4702: '<td valaign="top">'.$space.
4703: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4704: for (my $i=0; $i<@rulenames; $i++) {
4705: my $rule = $rulenames[$i];
4706: my ($checked,$extra);
4707: if ($rulenames[$i] eq 'default') {
4708: $rule = '';
4709: }
4710: if ($rulenames[$i] eq 'specific') {
4711: if (ref($servers) eq 'HASH') {
4712: my $default;
4713: if (($current ne '') && (exists($servers->{$current}))) {
4714: $checked = ' checked="checked"';
4715: }
4716: unless ($checked) {
4717: $default = ' selected="selected"';
4718: }
1.160.6.7 raeburn 4719: $extra =
4720: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4721: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4722: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4723: '<option value=""'.$default.'></option>'."\n";
4724: foreach my $server (sort(keys(%{$servers}))) {
4725: if (ref($currbalancer) eq 'HASH') {
4726: next if (exists($currbalancer->{$server}));
4727: }
1.150 raeburn 4728: my $selected;
1.160.6.7 raeburn 4729: if ($server eq $current) {
1.150 raeburn 4730: $selected = ' selected="selected"';
4731: }
1.160.6.7 raeburn 4732: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4733: }
4734: $extra .= '</select>';
4735: }
4736: } elsif ($rule eq $current) {
4737: $checked = ' checked="checked"';
4738: }
4739: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4740: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4741: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4742: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4743: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4744: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4745: $output .= $ruletitles{'particular'};
4746: } else {
4747: $output .= $ruletitles{$rulenames[$i]};
4748: }
4749: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4750: }
4751: $output .= '</div></td></tr>'."\n";
4752: return $output;
4753: }
4754:
4755: sub offloadtype_text {
4756: my %ruletitles = &Apache::lonlocal::texthash (
4757: 'default' => 'Offloads to default destinations',
4758: 'homeserver' => "Offloads to user's home server",
4759: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4760: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4761: 'none' => 'No offload',
1.160.6.26 raeburn 4762: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4763: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4764: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4765: );
4766: return %ruletitles;
4767: }
4768:
4769: sub sparestype_titles {
4770: my %typestitles = &Apache::lonlocal::texthash (
4771: 'primary' => 'primary',
4772: 'default' => 'default',
4773: );
4774: return %typestitles;
4775: }
4776:
1.28 raeburn 4777: sub contact_titles {
4778: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 4779: 'supportemail' => 'Support E-mail address',
4780: 'adminemail' => 'Default Server Admin E-mail address',
4781: 'errormail' => 'Error reports to be e-mailed to',
4782: 'packagesmail' => 'Package update alerts to be e-mailed to',
4783: 'helpdeskmail' => "Helpdesk requests for this domain's users",
4784: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
4785: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
4786: 'requestsmail' => 'E-mail from course requests requiring approval',
4787: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4788: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4789: );
4790: my %short_titles = &Apache::lonlocal::texthash (
4791: adminemail => 'Admin E-mail address',
4792: supportemail => 'Support E-mail',
4793: );
4794: return (\%titles,\%short_titles);
4795: }
4796:
1.160.6.78 raeburn 4797: sub helpform_fields {
4798: my %titles = &Apache::lonlocal::texthash (
4799: 'username' => 'Name',
4800: 'user' => 'Username/domain',
4801: 'phone' => 'Phone',
4802: 'cc' => 'Cc e-mail',
4803: 'course' => 'Course Details',
4804: 'section' => 'Sections',
4805: 'screenshot' => 'File upload',
4806: );
4807: my @fields = ('username','phone','user','course','section','cc','screenshot');
4808: my %possoptions = (
4809: username => ['yes','no','req'],
4810: phone => ['yes','no','req'],
4811: user => ['yes','no'],
4812: cc => ['yes','no'],
4813: course => ['yes','no'],
4814: section => ['yes','no'],
4815: screenshot => ['yes','no'],
4816: );
4817: my %fieldoptions = &Apache::lonlocal::texthash (
4818: 'yes' => 'Optional',
4819: 'req' => 'Required',
4820: 'no' => "Not shown",
4821: );
4822: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
4823: }
4824:
1.72 raeburn 4825: sub tool_titles {
4826: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4827: aboutme => 'Personal web page',
1.86 raeburn 4828: blog => 'Blog',
1.160.6.4 raeburn 4829: webdav => 'WebDAV',
1.86 raeburn 4830: portfolio => 'Portfolio',
1.88 bisitz 4831: official => 'Official courses (with institutional codes)',
4832: unofficial => 'Unofficial courses',
1.98 raeburn 4833: community => 'Communities',
1.160.6.30 raeburn 4834: textbook => 'Textbook courses',
1.86 raeburn 4835: );
1.72 raeburn 4836: return %titles;
4837: }
4838:
1.101 raeburn 4839: sub courserequest_titles {
4840: my %titles = &Apache::lonlocal::texthash (
4841: official => 'Official',
4842: unofficial => 'Unofficial',
4843: community => 'Communities',
1.160.6.30 raeburn 4844: textbook => 'Textbook',
1.101 raeburn 4845: norequest => 'Not allowed',
1.104 raeburn 4846: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4847: validate => 'With validation',
4848: autolimit => 'Numerical limit',
1.103 raeburn 4849: unlimited => '(blank for unlimited)',
1.101 raeburn 4850: );
4851: return %titles;
4852: }
4853:
1.160.6.5 raeburn 4854: sub authorrequest_titles {
4855: my %titles = &Apache::lonlocal::texthash (
4856: norequest => 'Not allowed',
4857: approval => 'Approval by Dom. Coord.',
4858: automatic => 'Automatic approval',
4859: );
4860: return %titles;
4861: }
4862:
1.101 raeburn 4863: sub courserequest_conditions {
4864: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4865: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4866: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4867: );
4868: return %conditions;
4869: }
4870:
4871:
1.27 raeburn 4872: sub print_usercreation {
1.30 raeburn 4873: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4874: my $numinrow = 4;
1.28 raeburn 4875: my $datatable;
4876: if ($position eq 'top') {
1.30 raeburn 4877: $$rowtotal ++;
1.34 raeburn 4878: my $rowcount = 0;
1.32 raeburn 4879: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4880: if (ref($rules) eq 'HASH') {
4881: if (keys(%{$rules}) > 0) {
1.32 raeburn 4882: $datatable .= &user_formats_row('username',$settings,$rules,
4883: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4884: $$rowtotal ++;
1.32 raeburn 4885: $rowcount ++;
4886: }
4887: }
4888: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4889: if (ref($idrules) eq 'HASH') {
4890: if (keys(%{$idrules}) > 0) {
4891: $datatable .= &user_formats_row('id',$settings,$idrules,
4892: $idruleorder,$numinrow,$rowcount);
4893: $$rowtotal ++;
4894: $rowcount ++;
1.28 raeburn 4895: }
4896: }
1.39 raeburn 4897: if ($rowcount == 0) {
4898: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4899: $$rowtotal ++;
4900: $rowcount ++;
4901: }
1.34 raeburn 4902: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4903: my @creators = ('author','course','requestcrs');
1.37 raeburn 4904: my ($rules,$ruleorder) =
4905: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4906: my %lt = &usercreation_types();
4907: my %checked;
4908: if (ref($settings) eq 'HASH') {
4909: if (ref($settings->{'cancreate'}) eq 'HASH') {
4910: foreach my $item (@creators) {
4911: $checked{$item} = $settings->{'cancreate'}{$item};
4912: }
4913: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4914: foreach my $item (@creators) {
4915: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4916: $checked{$item} = 'none';
4917: }
4918: }
4919: }
4920: }
4921: my $rownum = 0;
4922: foreach my $item (@creators) {
4923: $rownum ++;
1.160.6.34 raeburn 4924: if ($checked{$item} eq '') {
4925: $checked{$item} = 'any';
1.34 raeburn 4926: }
4927: my $css_class;
4928: if ($rownum%2) {
4929: $css_class = '';
4930: } else {
4931: $css_class = ' class="LC_odd_row" ';
4932: }
4933: $datatable .= '<tr'.$css_class.'>'.
4934: '<td><span class="LC_nobreak">'.$lt{$item}.
4935: '</span></td><td align="right">';
1.160.6.34 raeburn 4936: my @options = ('any');
4937: if (ref($rules) eq 'HASH') {
4938: if (keys(%{$rules}) > 0) {
4939: push(@options,('official','unofficial'));
1.37 raeburn 4940: }
4941: }
1.160.6.34 raeburn 4942: push(@options,'none');
1.37 raeburn 4943: foreach my $option (@options) {
1.50 raeburn 4944: my $type = 'radio';
1.34 raeburn 4945: my $check = ' ';
1.160.6.34 raeburn 4946: if ($checked{$item} eq $option) {
4947: $check = ' checked="checked" ';
1.34 raeburn 4948: }
4949: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4950: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4951: $item.'" value="'.$option.'"'.$check.'/> '.
4952: $lt{$option}.'</label> </span>';
4953: }
4954: $datatable .= '</td></tr>';
4955: }
1.28 raeburn 4956: } else {
4957: my @contexts = ('author','course','domain');
4958: my @authtypes = ('int','krb4','krb5','loc');
4959: my %checked;
4960: if (ref($settings) eq 'HASH') {
4961: if (ref($settings->{'authtypes'}) eq 'HASH') {
4962: foreach my $item (@contexts) {
4963: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4964: foreach my $auth (@authtypes) {
4965: if ($settings->{'authtypes'}{$item}{$auth}) {
4966: $checked{$item}{$auth} = ' checked="checked" ';
4967: }
4968: }
4969: }
4970: }
1.27 raeburn 4971: }
1.35 raeburn 4972: } else {
4973: foreach my $item (@contexts) {
1.36 raeburn 4974: foreach my $auth (@authtypes) {
1.35 raeburn 4975: $checked{$item}{$auth} = ' checked="checked" ';
4976: }
4977: }
1.27 raeburn 4978: }
1.28 raeburn 4979: my %title = &context_names();
4980: my %authname = &authtype_names();
4981: my $rownum = 0;
4982: my $css_class;
4983: foreach my $item (@contexts) {
4984: if ($rownum%2) {
4985: $css_class = '';
4986: } else {
4987: $css_class = ' class="LC_odd_row" ';
4988: }
1.30 raeburn 4989: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4990: '<td>'.$title{$item}.
4991: '</td><td class="LC_left_item">'.
4992: '<span class="LC_nobreak">';
4993: foreach my $auth (@authtypes) {
4994: $datatable .= '<label>'.
4995: '<input type="checkbox" name="'.$item.'_auth" '.
4996: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4997: $authname{$auth}.'</label> ';
4998: }
4999: $datatable .= '</span></td></tr>';
5000: $rownum ++;
1.27 raeburn 5001: }
1.30 raeburn 5002: $$rowtotal += $rownum;
1.27 raeburn 5003: }
5004: return $datatable;
5005: }
5006:
1.160.6.34 raeburn 5007: sub print_selfcreation {
5008: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.84.4. (raeburn 5009:): my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
5010:): $emaildomain,$datatable);
1.160.6.34 raeburn 5011: if (ref($settings) eq 'HASH') {
5012: if (ref($settings->{'cancreate'}) eq 'HASH') {
5013: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 5014: if (ref($createsettings) eq 'HASH') {
5015: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5016: @selfcreate = @{$createsettings->{'selfcreate'}};
5017: } elsif ($createsettings->{'selfcreate'} ne '') {
5018: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5019: @selfcreate = ('email','login','sso');
5020: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5021: @selfcreate = ($createsettings->{'selfcreate'});
5022: }
5023: }
5024: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5025: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5026: }
1.160.6.84.4. (raeburn 5027:): if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
5028:): $emailoptions = $createsettings->{'emailoptions'};
5029:): }
5030:): if (ref($createsettings->{'emailverified'}) eq 'HASH') {
5031:): $emailverified = $createsettings->{'emailverified'};
5032:): }
5033:): if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
5034:): $emaildomain = $createsettings->{'emaildomain'};
5035:): }
1.160.6.34 raeburn 5036: }
5037: }
5038: }
5039: my %radiohash;
5040: my $numinrow = 4;
5041: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.84.4. (raeburn 5042:): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 5043: if ($position eq 'top') {
5044: my %choices = &Apache::lonlocal::texthash (
5045: cancreate_login => 'Institutional Login',
5046: cancreate_sso => 'Institutional Single Sign On',
5047: );
5048: my @toggles = sort(keys(%choices));
5049: my %defaultchecked = (
5050: 'cancreate_login' => 'off',
5051: 'cancreate_sso' => 'off',
5052: );
1.160.6.35 raeburn 5053: my ($onclick,$itemcount);
1.160.6.34 raeburn 5054: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5055: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5056: $$rowtotal += $itemcount;
1.160.6.39 raeburn 5057:
1.160.6.34 raeburn 5058: if (ref($usertypes) eq 'HASH') {
5059: if (keys(%{$usertypes}) > 0) {
5060: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5061: $dom,$numinrow,$othertitle,
1.160.6.84.4. (raeburn 5062:): 'statustocreate',$rowtotal);
1.160.6.34 raeburn 5063: $$rowtotal ++;
5064: }
5065: }
1.160.6.44 raeburn 5066: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5067: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5068: $fieldtitles{'inststatus'} = &mt('Institutional status');
5069: my $rem;
5070: my $numperrow = 2;
5071: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5072: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5073: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5074: '<td class="LC_left_item">'."\n".
5075: '<table><tr><td>'."\n";
5076: for (my $i=0; $i<@fields; $i++) {
5077: $rem = $i%($numperrow);
5078: if ($rem == 0) {
5079: if ($i > 0) {
5080: $datatable .= '</tr>';
5081: }
5082: $datatable .= '<tr>';
5083: }
5084: my $currval;
1.160.6.51 raeburn 5085: if (ref($createsettings) eq 'HASH') {
5086: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5087: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5088: }
1.160.6.44 raeburn 5089: }
5090: $datatable .= '<td class="LC_left_item">'.
5091: '<span class="LC_nobreak">'.
5092: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5093: 'value="'.$currval.'" size="10" /> '.
5094: $fieldtitles{$fields[$i]}.'</span></td>';
5095: }
5096: my $colsleft = $numperrow - $rem;
5097: if ($colsleft > 1 ) {
5098: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5099: ' </td>';
5100: } elsif ($colsleft == 1) {
5101: $datatable .= '<td class="LC_left_item"> </td>';
5102: }
5103: $datatable .= '</tr></table></td></tr>';
5104: $$rowtotal ++;
1.160.6.34 raeburn 5105: } elsif ($position eq 'middle') {
5106: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.84.4. (raeburn 5107:): my @posstypes;
1.160.6.34 raeburn 5108: if (ref($types) eq 'ARRAY') {
1.160.6.84.4. (raeburn 5109:): @posstypes = @{$types};
5110:): }
5111:): unless (grep(/^default$/,@posstypes)) {
5112:): push(@posstypes,'default');
5113:): }
5114:): my %usertypeshash;
5115:): if (ref($usertypes) eq 'HASH') {
5116:): %usertypeshash = %{$usertypes};
5117:): }
5118:): $usertypeshash{'default'} = $othertitle;
5119:): foreach my $status (@posstypes) {
5120:): $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5121:): $numinrow,$$rowtotal,\%usertypeshash);
5122:): $$rowtotal ++;
1.160.6.34 raeburn 5123: }
5124: } else {
1.160.6.40 raeburn 5125: my %choices = &Apache::lonlocal::texthash (
1.160.6.84.4. (raeburn 5126:): 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 5127: );
5128: my @toggles = sort(keys(%choices));
5129: my %defaultchecked = (
5130: 'cancreate_email' => 'off',
5131: );
1.160.6.84.4. (raeburn 5132:): my $customclass = 'LC_selfcreate_email';
5133:): my $classprefix = 'LC_canmodify_emailusername_';
5134:): my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 5135: my $display = 'none';
1.160.6.84.4. (raeburn 5136:): my $rowstyle = 'display:none';
1.160.6.40 raeburn 5137: if (grep(/^\Qemail\E$/,@selfcreate)) {
5138: $display = 'block';
1.160.6.84.4. (raeburn 5139:): $rowstyle = 'display:table-row';
1.160.6.40 raeburn 5140: }
1.160.6.84.4. (raeburn 5141:): my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
5142:): ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5143:): \%choices,$$rowtotal,$onclick);
5144:): $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
5145:): $rowstyle);
5146:): $$rowtotal ++;
5147:): $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
5148:): $rowstyle);
5149:): $$rowtotal ++;
5150:): my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 5151: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.84.4. (raeburn 5152:): my ($emailrules,$emailruleorder) =
5153:): &Apache::lonnet::inst_userrules($dom,'email');
5154:): my $primary_id = &Apache::lonnet::domain($dom,'primary');
5155:): my $intdom = &Apache::lonnet::internet_dom($primary_id);
5156:): if (ref($types) eq 'ARRAY') {
5157:): @posstypes = @{$types};
5158:): }
5159:): if (@posstypes) {
5160:): unless (grep(/^default$/,@posstypes)) {
5161:): push(@posstypes,'default');
5162:): }
5163:): if (ref($usertypes) eq 'HASH') {
5164:): %usertypeshash = %{$usertypes};
5165:): }
5166:): my $currassign;
5167:): if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
5168:): $currassign = {
5169:): selfassign => $domdefaults{'inststatusguest'},
5170:): };
5171:): @ordered = @{$domdefaults{'inststatusguest'}};
5172:): } else {
5173:): $currassign = { selfassign => [] };
5174:): }
5175:): my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
5176:): "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
5177:): $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
5178:): $numinrow,$othertitle,'selfassign',
5179:): $rowtotal,$onclicktypes,$customclass,
5180:): $rowstyle);
5181:): $$rowtotal ++;
5182:): $usertypeshash{'default'} = $othertitle;
5183:): foreach my $status (@posstypes) {
5184:): my $css_class;
5185:): if ($$rowtotal%2) {
5186:): $css_class = 'LC_odd_row ';
5187:): }
5188:): $css_class .= $customclass;
5189:): my $rowid = $optionsprefix.$status;
5190:): my $hidden = 1;
5191:): my $currstyle = 'display:none';
5192:): if (grep(/^\Q$status\E$/,@ordered)) {
5193:): $currstyle = $rowstyle;
5194:): $hidden = 0;
5195:): }
5196:): $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5197:): $emailrules,$emailruleorder,$settings,$status,$rowid,
5198:): $usertypeshash{$status},$css_class,$currstyle,$intdom);
5199:): unless ($hidden) {
5200:): $$rowtotal ++;
1.160.6.34 raeburn 5201: }
5202: }
1.160.6.84.4. (raeburn 5203:): } else {
5204:): my $css_class;
5205:): if ($$rowtotal%2) {
5206:): $css_class = 'LC_odd_row ';
5207:): }
5208:): $css_class .= $customclass;
5209:): $usertypeshash{'default'} = $othertitle;
5210:): $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
5211:): $emailrules,$emailruleorder,$settings,'default','',
5212:): $othertitle,$css_class,$rowstyle,$intdom);
5213:): $$rowtotal ++;
1.160.6.34 raeburn 5214: }
1.160.6.35 raeburn 5215: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5216: $numinrow = 1;
1.160.6.84.4. (raeburn 5217:): if (@posstypes) {
5218:): foreach my $status (@posstypes) {
5219:): my $rowid = $classprefix.$status;
5220:): my $datarowstyle = 'display:none';
5221:): if (grep(/^\Q$status\E$/,@ordered)) {
5222:): $datarowstyle = $rowstyle;
5223:): }
1.160.6.35 raeburn 5224: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
1.160.6.84.4. (raeburn 5225:): $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5226:): $infotitles,$rowid,$customclass,$datarowstyle);
5227:): unless ($datarowstyle eq 'display:none') {
5228:): $$rowtotal ++;
5229:): }
1.160.6.35 raeburn 5230: }
1.160.6.84.4. (raeburn 5231:): } else {
5232:): $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
5233:): $numinrow,$$rowtotal,\%usertypeshash,$infofields,
5234:): $infotitles,'',$customclass,$rowstyle);
1.160.6.35 raeburn 5235: }
1.160.6.84.4. (raeburn 5236:): }
5237:): return $datatable;
5238:): }
5239:):
5240:): sub selfcreate_javascript {
5241:): return <<"ENDSCRIPT";
5242:):
5243:): <script type="text/javascript">
5244:): // <![CDATA[
5245:):
5246:): function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
5247:): var x = document.getElementsByClassName(target);
5248:): var insttypes = 0;
5249:): var insttypeRegExp = new RegExp(prefix);
5250:): if ((x.length != undefined) && (x.length > 0)) {
5251:): if (form.elements[radio].length != undefined) {
5252:): for (var i=0; i<form.elements[radio].length; i++) {
5253:): if (form.elements[radio][i].checked) {
5254:): if (form.elements[radio][i].value == 1) {
5255:): for (var j=0; j<x.length; j++) {
5256:): if (x[j].id == 'undefined') {
5257:): x[j].style.display = 'table-row';
5258:): } else if (insttypeRegExp.test(x[j].id)) {
5259:): insttypes ++;
5260:): } else {
5261:): x[j].style.display = 'table-row';
5262:): }
5263:): }
5264:): } else {
5265:): for (var j=0; j<x.length; j++) {
5266:): x[j].style.display = 'none';
5267:): }
5268:): }
5269:): break;
5270:): }
5271:): }
5272:): if (insttypes > 0) {
5273:): toggleDataRow(form,checkbox,target,altprefix);
5274:): toggleDataRow(form,checkbox,target,prefix,1);
1.160.6.34 raeburn 5275: }
5276: }
5277: }
1.160.6.84.4. (raeburn 5278:): return;
1.160.6.34 raeburn 5279: }
5280:
1.160.6.84.4. (raeburn 5281:): function toggleDataRow(form,checkbox,target,prefix,docount) {
5282:): if (form.elements[checkbox].length != undefined) {
5283:): var count = 0;
5284:): if (docount) {
5285:): for (var i=0; i<form.elements[checkbox].length; i++) {
5286:): if (form.elements[checkbox][i].checked) {
5287:): count ++;
5288:): }
5289:): }
5290:): }
5291:): for (var i=0; i<form.elements[checkbox].length; i++) {
5292:): var type = form.elements[checkbox][i].value;
5293:): if (document.getElementById(prefix+type)) {
5294:): if (form.elements[checkbox][i].checked) {
5295:): document.getElementById(prefix+type).style.display = 'table-row';
5296:): if (count % 2 == 1) {
5297:): document.getElementById(prefix+type).className = target+' LC_odd_row';
5298:): } else {
5299:): document.getElementById(prefix+type).className = target;
1.160.6.40 raeburn 5300: }
1.160.6.84.4. (raeburn 5301:): count ++;
1.160.6.40 raeburn 5302: } else {
1.160.6.84.4. (raeburn 5303:): document.getElementById(prefix+type).style.display = 'none';
5304:): }
5305:): }
5306:): }
5307:): }
5308:): return;
5309:): }
5310:):
5311:): function toggleEmailOptions(form,radio,prefix,altprefix,status) {
5312:): var caller = radio+'_'+status;
5313:): if (form.elements[caller].length != undefined) {
5314:): for (var i=0; i<form.elements[caller].length; i++) {
5315:): if (form.elements[caller][i].checked) {
5316:): if (document.getElementById(altprefix+'_inst_'+status)) {
5317:): var curr = form.elements[caller][i].value;
5318:): if (prefix) {
5319:): document.getElementById(prefix+'_'+status).style.display = 'none';
5320:): }
5321:): document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
5322:): document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
5323:): if (curr == 'custom') {
5324:): if (prefix) {
5325:): document.getElementById(prefix+'_'+status).style.display = 'inline';
5326:): }
5327:): } else if (curr == 'inst') {
5328:): document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
5329:): } else if (curr == 'noninst') {
5330:): document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 5331: }
1.160.6.84.4. (raeburn 5332:): break;
1.160.6.40 raeburn 5333: }
1.160.6.84.4. (raeburn 5334:): }
5335:): }
5336:): }
5337:): }
5338:):
5339:): // ]]>
5340:): </script>
5341:):
5342:): ENDSCRIPT
5343:): }
5344:):
5345:): sub noninst_users {
5346:): my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
5347:): $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
5348:): my $class = 'LC_left_item';
5349:): if ($css_class) {
5350:): $css_class = ' class="'.$css_class.'"';
5351:): }
5352:): if ($rowid) {
5353:): $rowid = ' id="'.$rowid.'"';
5354:): }
5355:): if ($rowstyle) {
5356:): $rowstyle = ' style="'.$rowstyle.'"';
5357:): }
5358:): my ($output,$description);
5359:): if ($type eq 'default') {
5360:): $description = &mt('Requests for: [_1]',$typetitle);
5361:): } else {
5362:): $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
5363:): }
5364:): $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
5365:): "<td>$description</td>\n".
5366:): '<td class="'.$class.'" colspan="2">'.
5367:): '<table><tr>';
5368:): my %headers = &Apache::lonlocal::texthash(
5369:): approve => 'Processing',
5370:): email => 'E-mail',
5371:): username => 'Username',
5372:): );
5373:): foreach my $item ('approve','email','username') {
5374:): $output .= '<th>'.$headers{$item}.'</th>';
5375:): }
5376:): $output .= '</tr><tr>';
5377:): foreach my $item ('approve','email','username') {
5378:): $output .= '<td valign="top">';
5379:): my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
5380:): if ($item eq 'approve') {
5381:): %choices = &Apache::lonlocal::texthash (
5382:): automatic => 'Automatically approved',
5383:): approval => 'Queued for approval',
5384:): );
5385:): @options = ('automatic','approval');
5386:): $hashref = $processing;
5387:): $defoption = 'automatic';
5388:): $name = 'cancreate_emailprocess_'.$type;
5389:): } elsif ($item eq 'email') {
5390:): %choices = &Apache::lonlocal::texthash (
5391:): any => 'Any e-mail',
5392:): inst => 'Institutional only',
5393:): noninst => 'Non-institutional only',
5394:): custom => 'Custom restrictions',
5395:): );
5396:): @options = ('any','inst','noninst');
5397:): my $showcustom;
5398:): if (ref($emailrules) eq 'HASH') {
5399:): if (keys(%{$emailrules}) > 0) {
5400:): push(@options,'custom');
5401:): $showcustom = 'cancreate_emailrule';
5402:): if (ref($settings) eq 'HASH') {
5403:): if (ref($settings->{'email_rule'}) eq 'ARRAY') {
5404:): foreach my $rule (@{$settings->{'email_rule'}}) {
5405:): if (exists($emailrules->{$rule})) {
5406:): $hascustom ++;
5407:): }
5408:): }
5409:): } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
5410:): if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
5411:): foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
5412:): if (exists($emailrules->{$rule})) {
5413:): $hascustom ++;
5414:): }
5415:): }
5416:): }
5417:): }
5418:): }
5419:): }
5420:): }
5421:): $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
5422:): "'cancreate_emaildomain','$type'".');"';
5423:): $hashref = $emailoptions;
5424:): $defoption = 'any';
5425:): $name = 'cancreate_emailoptions_'.$type;
5426:): } elsif ($item eq 'username') {
5427:): %choices = &Apache::lonlocal::texthash (
5428:): all => 'Same as e-mail',
5429:): first => 'Omit @domain',
5430:): free => 'Free to choose',
5431:): );
5432:): @options = ('all','first','free');
5433:): $hashref = $emailverified;
5434:): $defoption = 'all';
5435:): $name = 'cancreate_usernameoptions_'.$type;
5436:): }
5437:): foreach my $option (@options) {
5438:): my $checked;
5439:): if (ref($hashref) eq 'HASH') {
5440:): if ($type eq '') {
5441:): if (!exists($hashref->{'default'})) {
5442:): if ($option eq $defoption) {
5443:): $checked = ' checked="checked"';
5444:): }
5445:): } else {
5446:): if ($hashref->{'default'} eq $option) {
5447:): $checked = ' checked="checked"';
5448:): }
1.160.6.40 raeburn 5449: }
5450: } else {
1.160.6.84.4. (raeburn 5451:): if (!exists($hashref->{$type})) {
5452:): if ($option eq $defoption) {
5453:): $checked = ' checked="checked"';
5454:): }
5455:): } else {
5456:): if ($hashref->{$type} eq $option) {
5457:): $checked = ' checked="checked"';
5458:): }
1.160.6.40 raeburn 5459: }
5460: }
1.160.6.84.4. (raeburn 5461:): } elsif (($item eq 'email') && ($hascustom)) {
5462:): if ($option eq 'custom') {
5463:): $checked = ' checked="checked"';
5464:): }
5465:): } elsif ($option eq $defoption) {
5466:): $checked = ' checked="checked"';
5467:): }
5468:): $output .= '<span class="LC_nobreak"><label>'.
5469:): '<input type="radio" name="'.$name.'"'.
5470:): $checked.' value="'.$option.'"'.$onclick.' />'.
5471:): $choices{$option}.'</label></span><br />';
5472:): if ($item eq 'email') {
5473:): if ($option eq 'custom') {
5474:): my $id = 'cancreate_emailrule_'.$type;
5475:): my $display = 'none';
5476:): if ($checked) {
5477:): $display = 'inline';
5478:): }
5479:): my $numinrow = 2;
5480:): $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
5481:): '<legend>'.&mt('Disallow').'</legend><table>'.
5482:): &user_formats_row('email',$settings,$emailrules,
5483:): $emailruleorder,$numinrow,'',$type);
5484:): '</table></fieldset>';
5485:): } elsif (($option eq 'inst') || ($option eq 'noninst')) {
5486:): my %text = &Apache::lonlocal::texthash (
5487:): inst => 'must end:',
5488:): noninst => 'cannot end:',
5489:): );
5490:): my $value;
5491:): if (ref($emaildomain) eq 'HASH') {
5492:): if (ref($emaildomain->{$type}) eq 'HASH') {
5493:): $value = $emaildomain->{$type}->{$option};
5494:): }
5495:): }
5496:): if ($value eq '') {
5497:): $value = '@'.$intdom;
5498:): }
5499:): my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
5500:): my $display = 'none';
5501:): if ($checked) {
5502:): $display = 'inline';
5503:): }
5504:): $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
5505:): '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
5506:): '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
5507:): '</div>';
5508:): }
1.160.6.40 raeburn 5509: }
5510: }
1.160.6.84.4. (raeburn 5511:): $output .= '</td>'."\n";
1.160.6.40 raeburn 5512: }
1.160.6.84.4. (raeburn 5513:): $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 5514: return $output;
5515: }
5516:
1.160.6.5 raeburn 5517: sub captcha_choice {
1.160.6.84.4. (raeburn 5518:): my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 5519: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5520: $vertext,$currver);
1.160.6.5 raeburn 5521: my %lt = &captcha_phrases();
5522: $keyentry = 'hidden';
5523: if ($context eq 'cancreate') {
1.160.6.34 raeburn 5524: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 5525: } elsif ($context eq 'login') {
5526: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5527: }
5528: if (ref($settings) eq 'HASH') {
5529: if ($settings->{'captcha'}) {
5530: $checked{$settings->{'captcha'}} = ' checked="checked"';
5531: } else {
5532: $checked{'original'} = ' checked="checked"';
5533: }
5534: if ($settings->{'captcha'} eq 'recaptcha') {
5535: $pubtext = $lt{'pub'};
5536: $privtext = $lt{'priv'};
5537: $keyentry = 'text';
1.160.6.69 raeburn 5538: $vertext = $lt{'ver'};
5539: $currver = $settings->{'recaptchaversion'};
5540: if ($currver ne '2') {
5541: $currver = 1;
5542: }
1.160.6.5 raeburn 5543: }
5544: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5545: $currpub = $settings->{'recaptchakeys'}{'public'};
5546: $currpriv = $settings->{'recaptchakeys'}{'private'};
5547: }
5548: } else {
5549: $checked{'original'} = ' checked="checked"';
5550: }
1.160.6.84.4. (raeburn 5551:): my $css_class;
5552:): if ($itemcount%2) {
5553:): $css_class = 'LC_odd_row';
5554:): }
5555:): if ($customcss) {
5556:): $css_class .= " $customcss";
5557:): }
5558:): $css_class =~ s/^\s+//;
5559:): if ($css_class) {
5560:): $css_class = ' class="'.$css_class.'"';
5561:): }
5562:): if ($rowstyle) {
5563:): $css_class .= ' style="'.$rowstyle.'"';
5564:): }
1.160.6.5 raeburn 5565: my $output = '<tr'.$css_class.'>'.
5566: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5567: '<table><tr><td>'."\n";
5568: foreach my $option ('original','recaptcha','notused') {
5569: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5570: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5571: $lt{$option}.'</label></span>';
5572: unless ($option eq 'notused') {
5573: $output .= (' 'x2)."\n";
5574: }
5575: }
5576: #
5577: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5578: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5579: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5580: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5581: #
5582: $output .= '</td></tr>'."\n".
1.160.6.84.4. (raeburn 5583:): '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 5584: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5585: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5586: $currpub.'" size="40" /></span><br />'."\n".
5587: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5588: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 5589: $currpriv.'" size="40" /></span><br />'.
5590: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5591: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5592: $currver.'" size="3" /></span><br />'.
5593: '</td></tr></table>'."\n".
1.160.6.5 raeburn 5594: '</td></tr>';
5595: return $output;
5596: }
5597:
1.32 raeburn 5598: sub user_formats_row {
1.160.6.84.4. (raeburn 5599:): my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 5600: my $output;
5601: my %text = (
5602: 'username' => 'new usernames',
5603: 'id' => 'IDs',
5604: );
1.160.6.84.4. (raeburn 5605:): unless ($type eq 'email') {
5606:): my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5607:): $output = '<tr '.$css_class.'>'.
5608:): '<td><span class="LC_nobreak">'.
5609:): &mt("Format rules to check for $text{$type}: ").
5610:): '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 5611: }
1.27 raeburn 5612: my $rem;
5613: if (ref($ruleorder) eq 'ARRAY') {
5614: for (my $i=0; $i<@{$ruleorder}; $i++) {
5615: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5616: my $rem = $i%($numinrow);
5617: if ($rem == 0) {
5618: if ($i > 0) {
5619: $output .= '</tr>';
5620: }
5621: $output .= '<tr>';
5622: }
5623: my $check = ' ';
1.39 raeburn 5624: if (ref($settings) eq 'HASH') {
5625: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5626: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5627: $check = ' checked="checked" ';
5628: }
1.160.6.84.4. (raeburn 5629:): } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
5630:): if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
5631:): if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
5632:): $check = ' checked="checked" ';
5633:): }
5634:): }
1.27 raeburn 5635: }
5636: }
1.160.6.84.4. (raeburn 5637:): my $name = $type.'_rule';
5638:): if ($type eq 'email') {
5639:): $name .= '_'.$status;
5640:): }
1.27 raeburn 5641: $output .= '<td class="LC_left_item">'.
5642: '<span class="LC_nobreak"><label>'.
1.160.6.84.4. (raeburn 5643:): '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 5644: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5645: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5646: }
5647: }
5648: $rem = @{$ruleorder}%($numinrow);
5649: }
1.160.6.84.4. (raeburn 5650:): my $colsleft;
5651:): if ($rem) {
5652:): $colsleft = $numinrow - $rem;
5653:): }
1.27 raeburn 5654: if ($colsleft > 1 ) {
5655: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5656: ' </td>';
5657: } elsif ($colsleft == 1) {
5658: $output .= '<td class="LC_left_item"> </td>';
5659: }
1.160.6.84.4. (raeburn 5660:): $output .= '</tr></table>';
5661:): unless ($type eq 'email') {
5662:): $output .= '</td></tr>';
5663:): }
1.27 raeburn 5664: return $output;
5665: }
5666:
1.34 raeburn 5667: sub usercreation_types {
5668: my %lt = &Apache::lonlocal::texthash (
5669: author => 'When adding a co-author',
5670: course => 'When adding a user to a course',
1.100 raeburn 5671: requestcrs => 'When requesting a course',
1.34 raeburn 5672: any => 'Any',
5673: official => 'Institutional only ',
5674: unofficial => 'Non-institutional only',
5675: none => 'None',
5676: );
5677: return %lt;
1.48 raeburn 5678: }
1.34 raeburn 5679:
1.160.6.34 raeburn 5680: sub selfcreation_types {
5681: my %lt = &Apache::lonlocal::texthash (
5682: selfcreate => 'User creates own account',
5683: any => 'Any',
5684: official => 'Institutional only ',
5685: unofficial => 'Non-institutional only',
5686: email => 'E-mail address',
5687: login => 'Institutional Login',
5688: sso => 'SSO',
5689: );
5690: }
5691:
1.28 raeburn 5692: sub authtype_names {
5693: my %lt = &Apache::lonlocal::texthash(
5694: int => 'Internal',
5695: krb4 => 'Kerberos 4',
5696: krb5 => 'Kerberos 5',
5697: loc => 'Local',
5698: );
5699: return %lt;
5700: }
5701:
5702: sub context_names {
5703: my %context_title = &Apache::lonlocal::texthash(
5704: author => 'Creating users when an Author',
5705: course => 'Creating users when in a course',
5706: domain => 'Creating users when a Domain Coordinator',
5707: );
5708: return %context_title;
5709: }
5710:
1.33 raeburn 5711: sub print_usermodification {
5712: my ($position,$dom,$settings,$rowtotal) = @_;
5713: my $numinrow = 4;
5714: my ($context,$datatable,$rowcount);
5715: if ($position eq 'top') {
5716: $rowcount = 0;
5717: $context = 'author';
5718: foreach my $role ('ca','aa') {
5719: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5720: $numinrow,$rowcount);
5721: $$rowtotal ++;
5722: $rowcount ++;
5723: }
1.160.6.37 raeburn 5724: } elsif ($position eq 'bottom') {
1.33 raeburn 5725: $context = 'course';
5726: $rowcount = 0;
5727: foreach my $role ('st','ep','ta','in','cr') {
5728: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5729: $numinrow,$rowcount);
5730: $$rowtotal ++;
5731: $rowcount ++;
5732: }
5733: }
5734: return $datatable;
5735: }
5736:
1.43 raeburn 5737: sub print_defaults {
1.160.6.40 raeburn 5738: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5739: my $rownum = 0;
1.160.6.80 raeburn 5740: my ($datatable,$css_class,$titles);
5741: unless ($position eq 'bottom') {
5742: $titles = &defaults_titles($dom);
5743: }
1.160.6.40 raeburn 5744: if ($position eq 'top') {
5745: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5746: 'datelocale_def','portal_def');
5747: my %defaults;
5748: if (ref($settings) eq 'HASH') {
5749: %defaults = %{$settings};
1.43 raeburn 5750: } else {
1.160.6.40 raeburn 5751: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5752: foreach my $item (@items) {
5753: $defaults{$item} = $domdefaults{$item};
5754: }
1.43 raeburn 5755: }
1.160.6.40 raeburn 5756: foreach my $item (@items) {
5757: if ($rownum%2) {
5758: $css_class = '';
5759: } else {
5760: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 5761: }
1.160.6.40 raeburn 5762: $datatable .= '<tr'.$css_class.'>'.
5763: '<td><span class="LC_nobreak">'.$titles->{$item}.
5764: '</span></td><td class="LC_right_item" colspan="3">';
5765: if ($item eq 'auth_def') {
5766: my @authtypes = ('internal','krb4','krb5','localauth');
5767: my %shortauth = (
5768: internal => 'int',
5769: krb4 => 'krb4',
5770: krb5 => 'krb5',
5771: localauth => 'loc'
5772: );
5773: my %authnames = &authtype_names();
5774: foreach my $auth (@authtypes) {
5775: my $checked = ' ';
5776: if ($defaults{$item} eq $auth) {
5777: $checked = ' checked="checked" ';
5778: }
5779: $datatable .= '<label><input type="radio" name="'.$item.
5780: '" value="'.$auth.'"'.$checked.'/>'.
5781: $authnames{$shortauth{$auth}}.'</label> ';
5782: }
5783: } elsif ($item eq 'timezone_def') {
5784: my $includeempty = 1;
5785: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5786: } elsif ($item eq 'datelocale_def') {
5787: my $includeempty = 1;
5788: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5789: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 5790: my $includeempty = 1;
5791: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 5792: } else {
5793: my $size;
5794: if ($item eq 'portal_def') {
5795: $size = ' size="25"';
5796: }
5797: $datatable .= '<input type="text" name="'.$item.'" value="'.
5798: $defaults{$item}.'"'.$size.' />';
5799: }
5800: $datatable .= '</td></tr>';
5801: $rownum ++;
5802: }
1.160.6.80 raeburn 5803: } elsif ($position eq 'middle') {
5804: my @items = ('intauth_cost','intauth_check','intauth_switch');
5805: my %defaults;
5806: if (ref($settings) eq 'HASH') {
5807: %defaults = %{$settings};
5808: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5809: $defaults{'intauth_cost'} = 10;
5810: }
5811: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5812: $defaults{'intauth_check'} = 0;
5813: }
5814: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5815: $defaults{'intauth_switch'} = 0;
5816: }
5817: } else {
5818: %defaults = (
5819: 'intauth_cost' => 10,
5820: 'intauth_check' => 0,
5821: 'intauth_switch' => 0,
5822: );
5823: }
5824: foreach my $item (@items) {
5825: if ($rownum%2) {
5826: $css_class = '';
5827: } else {
5828: $css_class = ' class="LC_odd_row" ';
5829: }
5830: $datatable .= '<tr'.$css_class.'>'.
5831: '<td><span class="LC_nobreak">'.$titles->{$item}.
5832: '</span></td><td class="LC_left_item" colspan="3">';
5833: if ($item eq 'intauth_switch') {
5834: my @options = (0,1,2);
5835: my %optiondesc = &Apache::lonlocal::texthash (
5836: 0 => 'No',
5837: 1 => 'Yes',
5838: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5839: );
5840: $datatable .= '<table width="100%">';
5841: foreach my $option (@options) {
5842: my $checked = ' ';
5843: if ($defaults{$item} eq $option) {
5844: $checked = ' checked="checked"';
5845: }
5846: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5847: '<label><input type="radio" name="'.$item.
5848: '" value="'.$option.'"'.$checked.' />'.
5849: $optiondesc{$option}.'</label></span></td></tr>';
5850: }
5851: $datatable .= '</table>';
5852: } elsif ($item eq 'intauth_check') {
5853: my @options = (0,1,2);
5854: my %optiondesc = &Apache::lonlocal::texthash (
5855: 0 => 'No',
5856: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5857: 2 => 'Yes, disallow login if stored cost is less than domain default',
5858: );
5859: $datatable .= '<table wisth="100%">';
5860: foreach my $option (@options) {
5861: my $checked = ' ';
5862: my $onclick;
5863: if ($defaults{$item} eq $option) {
5864: $checked = ' checked="checked"';
5865: }
5866: if ($option == 2) {
5867: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5868: }
5869: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5870: '<label><input type="radio" name="'.$item.
5871: '" value="'.$option.'"'.$checked.$onclick.' />'.
5872: $optiondesc{$option}.'</label></span></td></tr>';
5873: }
5874: $datatable .= '</table>';
5875: } else {
5876: $datatable .= '<input type="text" name="'.$item.'" value="'.
5877: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5878: }
5879: $datatable .= '</td></tr>';
5880: $rownum ++;
5881: }
1.160.6.40 raeburn 5882: } else {
1.160.6.80 raeburn 5883: my %defaults;
1.160.6.40 raeburn 5884: if (ref($settings) eq 'HASH') {
1.160.6.84.4. (raeburn 5885:): if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 5886: my $maxnum = @{$settings->{'inststatusorder'}};
5887: for (my $i=0; $i<$maxnum; $i++) {
5888: $css_class = $rownum%2?' class="LC_odd_row"':'';
5889: my $item = $settings->{'inststatusorder'}->[$i];
5890: my $title = $settings->{'inststatustypes'}->{$item};
5891: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5892: $datatable .= '<tr'.$css_class.'>'.
5893: '<td><span class="LC_nobreak">'.
5894: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5895: for (my $k=0; $k<=$maxnum; $k++) {
5896: my $vpos = $k+1;
5897: my $selstr;
5898: if ($k == $i) {
5899: $selstr = ' selected="selected" ';
5900: }
5901: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5902: }
5903: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5904: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5905: &mt('delete').'</span></td>'.
1.160.6.84.4. (raeburn 5906:): '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
1.160.6.40 raeburn 5907: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.84.4. (raeburn 5908:): '</span></td></tr>';
1.160.6.40 raeburn 5909: }
5910: $css_class = $rownum%2?' class="LC_odd_row"':'';
5911: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5912: $datatable .= '<tr '.$css_class.'>'.
5913: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5914: for (my $k=0; $k<=$maxnum; $k++) {
5915: my $vpos = $k+1;
5916: my $selstr;
5917: if ($k == $maxnum) {
5918: $selstr = ' selected="selected" ';
5919: }
5920: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5921: }
5922: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 5923: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 5924: ' '.&mt('(new)').
1.160.6.84.4. (raeburn 5925:): '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.160.6.40 raeburn 5926: &mt('Name displayed:').
5927: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5928: '</tr>'."\n";
5929: $rownum ++;
1.141 raeburn 5930: }
1.43 raeburn 5931: }
5932: }
5933: $$rowtotal += $rownum;
5934: return $datatable;
5935: }
5936:
1.160.6.5 raeburn 5937: sub get_languages_hash {
5938: my %langchoices;
5939: foreach my $id (&Apache::loncommon::languageids()) {
5940: my $code = &Apache::loncommon::supportedlanguagecode($id);
5941: if ($code ne '') {
5942: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5943: }
5944: }
5945: return %langchoices;
5946: }
5947:
1.43 raeburn 5948: sub defaults_titles {
1.141 raeburn 5949: my ($dom) = @_;
1.43 raeburn 5950: my %titles = &Apache::lonlocal::texthash (
5951: 'auth_def' => 'Default authentication type',
5952: 'auth_arg_def' => 'Default authentication argument',
5953: 'lang_def' => 'Default language',
1.54 raeburn 5954: 'timezone_def' => 'Default timezone',
1.68 raeburn 5955: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5956: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 5957: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
5958: 'intauth_check' => 'Check bcrypt cost if authenticated',
5959: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 5960: );
1.141 raeburn 5961: if ($dom) {
5962: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5963: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5964: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5965: $protocol = 'http' if ($protocol ne 'https');
5966: if ($uint_dom) {
5967: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5968: $uint_dom);
5969: }
5970: }
1.43 raeburn 5971: return (\%titles);
5972: }
5973:
1.46 raeburn 5974: sub print_scantronformat {
5975: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5976: my $itemcount = 1;
1.60 raeburn 5977: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5978: %confhash);
1.46 raeburn 5979: my $switchserver = &check_switchserver($dom,$confname);
5980: my %lt = &Apache::lonlocal::texthash (
1.95 www 5981: default => 'Default bubblesheet format file error',
5982: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5983: );
5984: my %scantronfiles = (
5985: default => 'default.tab',
5986: custom => 'custom.tab',
5987: );
5988: foreach my $key (keys(%scantronfiles)) {
5989: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5990: .$scantronfiles{$key};
5991: }
5992: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5993: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5994: if (!$switchserver) {
5995: my $servadm = $r->dir_config('lonAdmEMail');
5996: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5997: if ($configuserok eq 'ok') {
5998: if ($author_ok eq 'ok') {
5999: my %legacyfile = (
6000: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
6001: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
6002: );
6003: my %md5chk;
6004: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6005: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
6006: chomp($md5chk{$type});
1.46 raeburn 6007: }
6008: if ($md5chk{'default'} ne $md5chk{'custom'}) {
6009: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 6010: ($scantronurls{$type},my $error) =
1.46 raeburn 6011: &legacy_scantronformat($r,$dom,$confname,
6012: $type,$legacyfile{$type},
6013: $scantronurls{$type},
6014: $scantronfiles{$type});
1.60 raeburn 6015: if ($error ne '') {
6016: $error{$type} = $error;
6017: }
6018: }
6019: if (keys(%error) == 0) {
6020: $is_custom = 1;
6021: $confhash{'scantron'}{'scantronformat'} =
6022: $scantronurls{'custom'};
6023: my $putresult =
6024: &Apache::lonnet::put_dom('configuration',
6025: \%confhash,$dom);
6026: if ($putresult ne 'ok') {
6027: $error{'custom'} =
6028: '<span class="LC_error">'.
6029: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6030: }
1.46 raeburn 6031: }
6032: } else {
1.60 raeburn 6033: ($scantronurls{'default'},my $error) =
1.46 raeburn 6034: &legacy_scantronformat($r,$dom,$confname,
6035: 'default',$legacyfile{'default'},
6036: $scantronurls{'default'},
6037: $scantronfiles{'default'});
1.60 raeburn 6038: if ($error eq '') {
6039: $confhash{'scantron'}{'scantronformat'} = '';
6040: my $putresult =
6041: &Apache::lonnet::put_dom('configuration',
6042: \%confhash,$dom);
6043: if ($putresult ne 'ok') {
6044: $error{'default'} =
6045: '<span class="LC_error">'.
6046: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
6047: }
6048: } else {
6049: $error{'default'} = $error;
6050: }
1.46 raeburn 6051: }
6052: }
6053: }
6054: } else {
1.95 www 6055: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 6056: }
6057: }
6058: if (ref($settings) eq 'HASH') {
6059: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
6060: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
6061: if ((!@info) || ($info[0] eq 'no_such_dir')) {
6062: $scantronurl = '';
6063: } else {
6064: $scantronurl = $settings->{'scantronformat'};
6065: }
6066: $is_custom = 1;
6067: } else {
6068: $scantronurl = $scantronurls{'default'};
6069: }
6070: } else {
1.60 raeburn 6071: if ($is_custom) {
6072: $scantronurl = $scantronurls{'custom'};
6073: } else {
6074: $scantronurl = $scantronurls{'default'};
6075: }
1.46 raeburn 6076: }
6077: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6078: $datatable .= '<tr'.$css_class.'>';
6079: if (!$is_custom) {
1.65 raeburn 6080: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
6081: '<span class="LC_nobreak">';
1.46 raeburn 6082: if ($scantronurl) {
1.160.6.21 raeburn 6083: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
6084: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 6085: } else {
6086: $datatable = &mt('File unavailable for display');
6087: }
1.65 raeburn 6088: $datatable .= '</span></td>';
1.60 raeburn 6089: if (keys(%error) == 0) {
6090: $datatable .= '<td valign="bottom">';
6091: if (!$switchserver) {
6092: $datatable .= &mt('Upload:').'<br />';
6093: }
6094: } else {
6095: my $errorstr;
6096: foreach my $key (sort(keys(%error))) {
6097: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6098: }
6099: $datatable .= '<td>'.$errorstr;
6100: }
1.46 raeburn 6101: } else {
6102: if (keys(%error) > 0) {
6103: my $errorstr;
6104: foreach my $key (sort(keys(%error))) {
6105: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
6106: }
1.60 raeburn 6107: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 6108: } elsif ($scantronurl) {
1.160.6.26 raeburn 6109: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 6110: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 6111: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 6112: $link.
6113: '<label><input type="checkbox" name="scantronformat_del"'.
6114: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 6115: '<td><span class="LC_nobreak"> '.
6116: &mt('Replace:').'</span><br />';
1.46 raeburn 6117: }
6118: }
6119: if (keys(%error) == 0) {
6120: if ($switchserver) {
6121: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
6122: } else {
1.65 raeburn 6123: $datatable .='<span class="LC_nobreak"> '.
6124: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 6125: }
6126: }
6127: $datatable .= '</td></tr>';
6128: $$rowtotal ++;
6129: return $datatable;
6130: }
6131:
6132: sub legacy_scantronformat {
6133: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
6134: my ($url,$error);
6135: my @statinfo = &Apache::lonnet::stat_file($newurl);
6136: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
6137: (my $result,$url) =
6138: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
6139: '','',$newfile);
6140: if ($result ne 'ok') {
1.130 raeburn 6141: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 6142: }
6143: }
6144: return ($url,$error);
6145: }
1.43 raeburn 6146:
1.49 raeburn 6147: sub print_coursecategories {
1.57 raeburn 6148: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
6149: my $datatable;
6150: if ($position eq 'top') {
1.160.6.42 raeburn 6151: my (%checked);
6152: my @catitems = ('unauth','auth');
6153: my @cattypes = ('std','domonly','codesrch','none');
6154: $checked{'unauth'} = 'std';
6155: $checked{'auth'} = 'std';
6156: if (ref($settings) eq 'HASH') {
6157: foreach my $type (@cattypes) {
6158: if ($type eq $settings->{'unauth'}) {
6159: $checked{'unauth'} = $type;
6160: }
6161: if ($type eq $settings->{'auth'}) {
6162: $checked{'auth'} = $type;
6163: }
6164: }
6165: }
6166: my %lt = &Apache::lonlocal::texthash (
6167: unauth => 'Catalog type for unauthenticated users',
6168: auth => 'Catalog type for authenticated users',
6169: none => 'No catalog',
6170: std => 'Standard catalog',
6171: domonly => 'Domain-only catalog',
6172: codesrch => "Code search form",
6173: );
6174: my $itemcount = 0;
6175: foreach my $item (@catitems) {
6176: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
6177: $datatable .= '<tr '.$css_class.'>'.
6178: '<td>'.$lt{$item}.'</td>'.
6179: '<td class="LC_right_item"><span class="LC_nobreak">';
6180: foreach my $type (@cattypes) {
6181: my $ischecked;
6182: if ($checked{$item} eq $type) {
6183: $ischecked=' checked="checked"';
6184: }
6185: $datatable .= '<label>'.
6186: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
6187: ' />'.$lt{$type}.'</label> ';
6188: }
6189: $datatable .= '</td></tr>';
6190: $itemcount ++;
6191: }
6192: $$rowtotal += $itemcount;
6193: } elsif ($position eq 'middle') {
1.57 raeburn 6194: my $toggle_cats_crs = ' ';
6195: my $toggle_cats_dom = ' checked="checked" ';
6196: my $can_cat_crs = ' ';
6197: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 6198: my $toggle_catscomm_comm = ' ';
6199: my $toggle_catscomm_dom = ' checked="checked" ';
6200: my $can_catcomm_comm = ' ';
6201: my $can_catcomm_dom = ' checked="checked" ';
6202:
1.57 raeburn 6203: if (ref($settings) eq 'HASH') {
6204: if ($settings->{'togglecats'} eq 'crs') {
6205: $toggle_cats_crs = $toggle_cats_dom;
6206: $toggle_cats_dom = ' ';
6207: }
6208: if ($settings->{'categorize'} eq 'crs') {
6209: $can_cat_crs = $can_cat_dom;
6210: $can_cat_dom = ' ';
6211: }
1.120 raeburn 6212: if ($settings->{'togglecatscomm'} eq 'comm') {
6213: $toggle_catscomm_comm = $toggle_catscomm_dom;
6214: $toggle_catscomm_dom = ' ';
6215: }
6216: if ($settings->{'categorizecomm'} eq 'comm') {
6217: $can_catcomm_comm = $can_catcomm_dom;
6218: $can_catcomm_dom = ' ';
6219: }
1.57 raeburn 6220: }
6221: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 6222: togglecats => 'Show/Hide a course in catalog',
6223: togglecatscomm => 'Show/Hide a community in catalog',
6224: categorize => 'Assign a category to a course',
6225: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6226: );
6227: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 6228: dom => 'Set in Domain',
6229: crs => 'Set in Course',
6230: comm => 'Set in Community',
1.57 raeburn 6231: );
6232: $datatable = '<tr class="LC_odd_row">'.
6233: '<td>'.$title{'togglecats'}.'</td>'.
6234: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6235: '<input type="radio" name="togglecats"'.
6236: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6237: '<label><input type="radio" name="togglecats"'.
6238: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
6239: '</tr><tr>'.
6240: '<td>'.$title{'categorize'}.'</td>'.
6241: '<td class="LC_right_item"><span class="LC_nobreak">'.
6242: '<label><input type="radio" name="categorize"'.
6243: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6244: '<label><input type="radio" name="categorize"'.
6245: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 6246: '</tr><tr class="LC_odd_row">'.
6247: '<td>'.$title{'togglecatscomm'}.'</td>'.
6248: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
6249: '<input type="radio" name="togglecatscomm"'.
6250: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6251: '<label><input type="radio" name="togglecatscomm"'.
6252: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
6253: '</tr><tr>'.
6254: '<td>'.$title{'categorizecomm'}.'</td>'.
6255: '<td class="LC_right_item"><span class="LC_nobreak">'.
6256: '<label><input type="radio" name="categorizecomm"'.
6257: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
6258: '<label><input type="radio" name="categorizecomm"'.
6259: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 6260: '</tr>';
1.120 raeburn 6261: $$rowtotal += 4;
1.57 raeburn 6262: } else {
6263: my $css_class;
6264: my $itemcount = 1;
6265: my $cathash;
6266: if (ref($settings) eq 'HASH') {
6267: $cathash = $settings->{'cats'};
6268: }
6269: if (ref($cathash) eq 'HASH') {
6270: my (@cats,@trails,%allitems,%idx,@jsarray);
6271: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6272: \%allitems,\%idx,\@jsarray);
6273: my $maxdepth = scalar(@cats);
6274: my $colattrib = '';
6275: if ($maxdepth > 2) {
6276: $colattrib = ' colspan="2" ';
6277: }
6278: my @path;
6279: if (@cats > 0) {
6280: if (ref($cats[0]) eq 'ARRAY') {
6281: my $numtop = @{$cats[0]};
6282: my $maxnum = $numtop;
1.120 raeburn 6283: my %default_names = (
6284: instcode => &mt('Official courses'),
6285: communities => &mt('Communities'),
6286: );
6287:
6288: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6289: ($cathash->{'instcode::0'} eq '') ||
6290: (!grep(/^communities$/,@{$cats[0]})) ||
6291: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 6292: $maxnum ++;
6293: }
6294: my $lastidx;
6295: for (my $i=0; $i<$numtop; $i++) {
6296: my $parent = $cats[0][$i];
6297: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6298: my $item = &escape($parent).'::0';
6299: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6300: $lastidx = $idx{$item};
6301: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6302: .'<select name="'.$item.'"'.$chgstr.'>';
6303: for (my $k=0; $k<=$maxnum; $k++) {
6304: my $vpos = $k+1;
6305: my $selstr;
6306: if ($k == $i) {
6307: $selstr = ' selected="selected" ';
6308: }
6309: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6310: }
1.160.6.29 raeburn 6311: $datatable .= '</select></span></td><td>';
1.120 raeburn 6312: if ($parent eq 'instcode' || $parent eq 'communities') {
6313: $datatable .= '<span class="LC_nobreak">'
6314: .$default_names{$parent}.'</span>';
6315: if ($parent eq 'instcode') {
6316: $datatable .= '<br /><span class="LC_nobreak">('
6317: .&mt('with institutional codes')
6318: .')</span></td><td'.$colattrib.'>';
6319: } else {
6320: $datatable .= '<table><tr><td>';
6321: }
6322: $datatable .= '<span class="LC_nobreak">'
6323: .'<label><input type="radio" name="'
6324: .$parent.'" value="1" checked="checked" />'
6325: .&mt('Display').'</label>';
6326: if ($parent eq 'instcode') {
6327: $datatable .= ' ';
6328: } else {
6329: $datatable .= '</span></td></tr><tr><td>'
6330: .'<span class="LC_nobreak">';
6331: }
6332: $datatable .= '<label><input type="radio" name="'
6333: .$parent.'" value="0" />'
6334: .&mt('Do not display').'</label></span>';
6335: if ($parent eq 'communities') {
6336: $datatable .= '</td></tr></table>';
6337: }
6338: $datatable .= '</td>';
1.57 raeburn 6339: } else {
6340: $datatable .= $parent
1.160.6.29 raeburn 6341: .' <span class="LC_nobreak"><label>'
6342: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6343: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6344: }
6345: my $depth = 1;
6346: push(@path,$parent);
6347: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6348: pop(@path);
6349: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6350: $itemcount ++;
6351: }
1.48 raeburn 6352: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6353: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6354: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6355: for (my $k=0; $k<=$maxnum; $k++) {
6356: my $vpos = $k+1;
6357: my $selstr;
1.57 raeburn 6358: if ($k == $numtop) {
1.48 raeburn 6359: $selstr = ' selected="selected" ';
6360: }
6361: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6362: }
1.59 bisitz 6363: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6364: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6365: .'</tr>'."\n";
1.48 raeburn 6366: $itemcount ++;
1.120 raeburn 6367: foreach my $default ('instcode','communities') {
6368: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6369: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6370: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6371: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6372: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6373: for (my $k=0; $k<=$maxnum; $k++) {
6374: my $vpos = $k+1;
6375: my $selstr;
6376: if ($k == $maxnum) {
6377: $selstr = ' selected="selected" ';
6378: }
6379: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6380: }
1.120 raeburn 6381: $datatable .= '</select></span></td>'.
6382: '<td><span class="LC_nobreak">'.
6383: $default_names{$default}.'</span>';
6384: if ($default eq 'instcode') {
6385: $datatable .= '<br /><span class="LC_nobreak">('
6386: .&mt('with institutional codes').')</span>';
6387: }
6388: $datatable .= '</td>'
6389: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6390: .&mt('Display').'</label> '
6391: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6392: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6393: }
6394: }
6395: }
1.57 raeburn 6396: } else {
6397: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6398: }
6399: } else {
1.160.6.42 raeburn 6400: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57 raeburn 6401: .&initialize_categories($itemcount);
1.48 raeburn 6402: }
1.57 raeburn 6403: $$rowtotal += $itemcount;
1.48 raeburn 6404: }
6405: return $datatable;
6406: }
6407:
1.69 raeburn 6408: sub print_serverstatuses {
6409: my ($dom,$settings,$rowtotal) = @_;
6410: my $datatable;
6411: my @pages = &serverstatus_pages();
6412: my (%namedaccess,%machineaccess);
6413: foreach my $type (@pages) {
6414: $namedaccess{$type} = '';
6415: $machineaccess{$type}= '';
6416: }
6417: if (ref($settings) eq 'HASH') {
6418: foreach my $type (@pages) {
6419: if (exists($settings->{$type})) {
6420: if (ref($settings->{$type}) eq 'HASH') {
6421: foreach my $key (keys(%{$settings->{$type}})) {
6422: if ($key eq 'namedusers') {
6423: $namedaccess{$type} = $settings->{$type}->{$key};
6424: } elsif ($key eq 'machines') {
6425: $machineaccess{$type} = $settings->{$type}->{$key};
6426: }
6427: }
6428: }
6429: }
6430: }
6431: }
1.81 raeburn 6432: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6433: my $rownum = 0;
6434: my $css_class;
6435: foreach my $type (@pages) {
6436: $rownum ++;
6437: $css_class = $rownum%2?' class="LC_odd_row"':'';
6438: $datatable .= '<tr'.$css_class.'>'.
6439: '<td><span class="LC_nobreak">'.
6440: $titles->{$type}.'</span></td>'.
6441: '<td class="LC_left_item">'.
6442: '<input type="text" name="'.$type.'_namedusers" '.
6443: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6444: '<td class="LC_right_item">'.
6445: '<span class="LC_nobreak">'.
6446: '<input type="text" name="'.$type.'_machines" '.
6447: 'value="'.$machineaccess{$type}.'" size="10" />'.
6448: '</td></tr>'."\n";
6449: }
6450: $$rowtotal += $rownum;
6451: return $datatable;
6452: }
6453:
6454: sub serverstatus_pages {
6455: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 6456: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 6457: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 6458: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6459: }
6460:
1.160.6.40 raeburn 6461: sub defaults_javascript {
6462: my ($settings) = @_;
1.160.6.80 raeburn 6463: 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.');
6464: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6465: &js_escape(\$intauthcheck);
6466: &js_escape(\$intauthcost);
6467: my $intauthjs = <<"ENDSCRIPT";
6468:
6469: function warnIntAuth(field) {
6470: if (field.name == 'intauth_check') {
6471: if (field.value == '2') {
6472: alert('$intauthcheck');
6473: }
6474: }
6475: if (field.name == 'intauth_cost') {
6476: field.value.replace(/\s/g,'');
6477: if (field.value != '') {
6478: var regexdigit=/^\\d+\$/;
6479: if (!regexdigit.test(field.value)) {
6480: alert('$intauthcost');
6481: }
6482: }
6483: }
6484: return;
6485: }
6486:
6487: ENDSCRIPT
6488:
6489: if (ref($settings) ne 'HASH') {
6490: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6491: }
1.160.6.40 raeburn 6492: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6493: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6494: if ($maxnum eq '') {
6495: $maxnum = 0;
6496: }
6497: $maxnum ++;
1.160.6.51 raeburn 6498: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 6499: return <<"ENDSCRIPT";
6500: <script type="text/javascript">
6501: // <![CDATA[
6502: function reorderTypes(form,caller) {
6503: var changedVal;
6504: $jstext
6505: var newpos = 'addinststatus_pos';
6506: var current = new Array;
6507: var maxh = $maxnum;
6508: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6509: var oldVal;
6510: if (caller == newpos) {
6511: changedVal = newitemVal;
6512: } else {
6513: var curritem = 'inststatus_pos_'+caller;
6514: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6515: current[newitemVal] = newpos;
6516: }
6517: for (var i=0; i<inststatuses.length; i++) {
6518: if (inststatuses[i] != caller) {
6519: var elementName = 'inststatus_pos_'+inststatuses[i];
6520: if (form.elements[elementName]) {
6521: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6522: current[currVal] = elementName;
6523: }
6524: }
6525: }
6526: for (var j=0; j<maxh; j++) {
6527: if (current[j] == undefined) {
6528: oldVal = j;
6529: }
6530: }
6531: if (oldVal < changedVal) {
6532: for (var k=oldVal+1; k<=changedVal ; k++) {
6533: var elementName = current[k];
6534: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6535: }
6536: } else {
6537: for (var k=changedVal; k<oldVal; k++) {
6538: var elementName = current[k];
6539: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6540: }
6541: }
6542: return;
6543: }
6544:
1.160.6.80 raeburn 6545: $intauthjs
6546:
1.160.6.40 raeburn 6547: // ]]>
6548: </script>
6549:
6550: ENDSCRIPT
1.160.6.80 raeburn 6551: } else {
6552: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40 raeburn 6553: }
6554: }
6555:
1.49 raeburn 6556: sub coursecategories_javascript {
6557: my ($settings) = @_;
1.57 raeburn 6558: my ($output,$jstext,$cathash);
1.49 raeburn 6559: if (ref($settings) eq 'HASH') {
1.57 raeburn 6560: $cathash = $settings->{'cats'};
6561: }
6562: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6563: my (@cats,@jsarray,%idx);
1.57 raeburn 6564: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6565: if (@jsarray > 0) {
6566: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6567: for (my $i=0; $i<@jsarray; $i++) {
6568: if (ref($jsarray[$i]) eq 'ARRAY') {
6569: my $catstr = join('","',@{$jsarray[$i]});
6570: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6571: }
6572: }
6573: }
6574: } else {
6575: $jstext = ' var categories = Array(1);'."\n".
6576: ' categories[0] = Array("instcode_pos");'."\n";
6577: }
1.160.6.42 raeburn 6578: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6579: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 6580: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6581: &js_escape(\$instcode_reserved);
6582: &js_escape(\$communities_reserved);
6583: &js_escape(\$choose_again);
1.49 raeburn 6584: $output = <<"ENDSCRIPT";
6585: <script type="text/javascript">
1.109 raeburn 6586: // <![CDATA[
1.49 raeburn 6587: function reorderCats(form,parent,item,idx) {
6588: var changedVal;
6589: $jstext
6590: var newpos = 'addcategory_pos';
6591: if (parent == '') {
6592: var has_instcode = 0;
6593: var maxtop = categories[idx].length;
6594: for (var j=0; j<maxtop; j++) {
6595: if (categories[idx][j] == 'instcode::0') {
6596: has_instcode == 1;
6597: }
6598: }
6599: if (has_instcode == 0) {
6600: categories[idx][maxtop] = 'instcode_pos';
6601: }
6602: } else {
6603: newpos += '_'+parent;
6604: }
6605: var maxh = 1 + categories[idx].length;
6606: var current = new Array;
6607: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6608: if (item == newpos) {
6609: changedVal = newitemVal;
6610: } else {
6611: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6612: current[newitemVal] = newpos;
6613: }
6614: for (var i=0; i<categories[idx].length; i++) {
6615: var elementName = categories[idx][i];
6616: if (elementName != item) {
6617: if (form.elements[elementName]) {
6618: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6619: current[currVal] = elementName;
6620: }
6621: }
6622: }
6623: var oldVal;
6624: for (var j=0; j<maxh; j++) {
6625: if (current[j] == undefined) {
6626: oldVal = j;
6627: }
6628: }
6629: if (oldVal < changedVal) {
6630: for (var k=oldVal+1; k<=changedVal ; k++) {
6631: var elementName = current[k];
6632: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6633: }
6634: } else {
6635: for (var k=changedVal; k<oldVal; k++) {
6636: var elementName = current[k];
6637: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6638: }
6639: }
6640: return;
6641: }
1.120 raeburn 6642:
6643: function categoryCheck(form) {
6644: if (form.elements['addcategory_name'].value == 'instcode') {
6645: alert('$instcode_reserved\\n$choose_again');
6646: return false;
6647: }
6648: if (form.elements['addcategory_name'].value == 'communities') {
6649: alert('$communities_reserved\\n$choose_again');
6650: return false;
6651: }
6652: return true;
6653: }
6654:
1.109 raeburn 6655: // ]]>
1.49 raeburn 6656: </script>
6657:
6658: ENDSCRIPT
6659: return $output;
6660: }
6661:
1.48 raeburn 6662: sub initialize_categories {
6663: my ($itemcount) = @_;
1.120 raeburn 6664: my ($datatable,$css_class,$chgstr);
6665: my %default_names = (
6666: instcode => 'Official courses (with institutional codes)',
6667: communities => 'Communities',
6668: );
6669: my $select0 = ' selected="selected"';
6670: my $select1 = '';
6671: foreach my $default ('instcode','communities') {
6672: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6673: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
6674: if ($default eq 'communities') {
6675: $select1 = $select0;
6676: $select0 = '';
6677: }
6678: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6679: .'<select name="'.$default.'_pos">'
6680: .'<option value="0"'.$select0.'>1</option>'
6681: .'<option value="1"'.$select1.'>2</option>'
6682: .'<option value="2">3</option></select> '
6683: .$default_names{$default}
6684: .'</span></td><td><span class="LC_nobreak">'
6685: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6686: .&mt('Display').'</label> <label>'
6687: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6688: .'</label></span></td></tr>';
1.120 raeburn 6689: $itemcount ++;
6690: }
1.48 raeburn 6691: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6692: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6693: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6694: .'<select name="addcategory_pos"'.$chgstr.'>'
6695: .'<option value="0">1</option>'
6696: .'<option value="1">2</option>'
6697: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 6698: .&mt('Add category').'</td><td>'.&mt('Name:')
6699: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
6700: return $datatable;
6701: }
6702:
6703: sub build_category_rows {
1.49 raeburn 6704: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6705: my ($text,$name,$item,$chgstr);
1.48 raeburn 6706: if (ref($cats) eq 'ARRAY') {
6707: my $maxdepth = scalar(@{$cats});
6708: if (ref($cats->[$depth]) eq 'HASH') {
6709: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6710: my $numchildren = @{$cats->[$depth]{$parent}};
6711: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 6712: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6713: my ($idxnum,$parent_name,$parent_item);
6714: my $higher = $depth - 1;
6715: if ($higher == 0) {
6716: $parent_name = &escape($parent).'::'.$higher;
6717: } else {
6718: if (ref($path) eq 'ARRAY') {
6719: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6720: }
6721: }
6722: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6723: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6724: if ($j < $numchildren) {
1.48 raeburn 6725: $name = $cats->[$depth]{$parent}[$j];
6726: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6727: $idxnum = $idx->{$item};
6728: } else {
6729: $name = $parent_name;
6730: $item = $parent_item;
1.48 raeburn 6731: }
1.49 raeburn 6732: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6733: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6734: for (my $i=0; $i<=$numchildren; $i++) {
6735: my $vpos = $i+1;
6736: my $selstr;
6737: if ($j == $i) {
6738: $selstr = ' selected="selected" ';
6739: }
6740: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6741: }
6742: $text .= '</select> ';
6743: if ($j < $numchildren) {
6744: my $deeper = $depth+1;
6745: $text .= $name.' '
6746: .'<label><input type="checkbox" name="deletecategory" value="'
6747: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6748: if(ref($path) eq 'ARRAY') {
6749: push(@{$path},$name);
1.49 raeburn 6750: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6751: pop(@{$path});
6752: }
6753: } else {
1.59 bisitz 6754: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 6755: if ($j == $numchildren) {
6756: $text .= $name;
6757: } else {
6758: $text .= $item;
6759: }
6760: $text .= '" value="" />';
6761: }
6762: $text .= '</td></tr>';
6763: }
6764: $text .= '</table></td>';
6765: } else {
6766: my $higher = $depth-1;
6767: if ($higher == 0) {
6768: $name = &escape($parent).'::'.$higher;
6769: } else {
6770: if (ref($path) eq 'ARRAY') {
6771: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6772: }
6773: }
6774: my $colspan;
6775: if ($parent ne 'instcode') {
6776: $colspan = $maxdepth - $depth - 1;
6777: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
6778: }
6779: }
6780: }
6781: }
6782: return $text;
6783: }
6784:
1.33 raeburn 6785: sub modifiable_userdata_row {
1.160.6.84.4. (raeburn 6786:): my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
6787:): $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 6788: my ($role,$rolename,$statustype);
6789: $role = $item;
1.160.6.34 raeburn 6790: if ($context eq 'cancreate') {
1.160.6.84.4. (raeburn 6791:): if ($item =~ /^(emailusername)_(.+)$/) {
6792:): $role = $1;
6793:): $statustype = $2;
1.160.6.35 raeburn 6794: if (ref($usertypes) eq 'HASH') {
6795: if ($usertypes->{$statustype}) {
6796: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6797: } else {
6798: $rolename = &mt('Data provided by user');
6799: }
6800: }
1.160.6.34 raeburn 6801: }
6802: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6803: if (ref($usertypes) eq 'HASH') {
6804: $rolename = $usertypes->{$role};
6805: } else {
6806: $rolename = $role;
6807: }
1.33 raeburn 6808: } else {
1.63 raeburn 6809: if ($role eq 'cr') {
6810: $rolename = &mt('Custom role');
6811: } else {
6812: $rolename = &Apache::lonnet::plaintext($role);
6813: }
1.33 raeburn 6814: }
1.160.6.34 raeburn 6815: my (@fields,%fieldtitles);
6816: if (ref($fieldsref) eq 'ARRAY') {
6817: @fields = @{$fieldsref};
6818: } else {
6819: @fields = ('lastname','firstname','middlename','generation',
6820: 'permanentemail','id');
6821: }
6822: if ((ref($titlesref) eq 'HASH')) {
6823: %fieldtitles = %{$titlesref};
6824: } else {
6825: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6826: }
1.33 raeburn 6827: my $output;
1.160.6.84.4. (raeburn 6828:): my $css_class;
6829:): if ($rowcount%2) {
6830:): $css_class = 'LC_odd_row';
6831:): }
6832:): if ($customcss) {
6833:): $css_class .= " $customcss";
6834:): }
6835:): $css_class =~ s/^\s+//;
6836:): if ($css_class) {
6837:): $css_class = ' class="'.$css_class.'"';
6838:): }
6839:): if ($rowstyle) {
6840:): $css_class .= ' style="'.$rowstyle.'"';
6841:): }
6842:): if ($rowid) {
6843:): $rowid = ' id="'.$rowid.'"';
6844:): }
6845:):
6846:): $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 6847: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6848: '<td class="LC_left_item" colspan="2"><table>';
6849: my $rem;
6850: my %checks;
6851: if (ref($settings) eq 'HASH') {
6852: if (ref($settings->{$context}) eq 'HASH') {
6853: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 6854: my $hashref = $settings->{$context}->{$role};
6855: if ($role eq 'emailusername') {
6856: if ($statustype) {
6857: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6858: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 6859: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 6860: foreach my $field (@fields) {
6861: if ($hashref->{$field}) {
6862: $checks{$field} = $hashref->{$field};
6863: }
6864: }
6865: }
6866: }
6867: }
6868: } else {
6869: if (ref($hashref) eq 'HASH') {
6870: foreach my $field (@fields) {
6871: if ($hashref->{$field}) {
6872: $checks{$field} = ' checked="checked" ';
6873: }
6874: }
1.33 raeburn 6875: }
6876: }
6877: }
6878: }
6879: }
1.160.6.84.4. (raeburn 6880:):
6881:): my $total = scalar(@fields);
6882:): for (my $i=0; $i<$total; $i++) {
6883:): $rem = $i%($numinrow);
1.33 raeburn 6884: if ($rem == 0) {
6885: if ($i > 0) {
6886: $output .= '</tr>';
6887: }
6888: $output .= '<tr>';
6889: }
6890: my $check = ' ';
1.160.6.35 raeburn 6891: unless ($role eq 'emailusername') {
6892: if (exists($checks{$fields[$i]})) {
6893: $check = $checks{$fields[$i]}
6894: } else {
6895: if ($role eq 'st') {
6896: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 6897: $check = ' checked="checked" ';
1.160.6.35 raeburn 6898: }
1.33 raeburn 6899: }
6900: }
6901: }
6902: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 6903: '<span class="LC_nobreak">';
6904: if ($role eq 'emailusername') {
6905: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6906: $checks{$fields[$i]} = 'omit';
6907: }
6908: foreach my $option ('required','optional','omit') {
6909: my $checked='';
6910: if ($checks{$fields[$i]} eq $option) {
6911: $checked='checked="checked" ';
6912: }
6913: $output .= '<label>'.
6914: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6915: &mt($option).'</label>'.(' ' x2);
6916: }
6917: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6918: } else {
6919: $output .= '<label>'.
6920: '<input type="checkbox" name="canmodify_'.$role.'" '.
6921: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6922: '</label>';
6923: }
6924: $output .= '</span></td>';
1.33 raeburn 6925: }
1.160.6.84.4. (raeburn 6926:): $rem = $total%$numinrow;
6927:): my $colsleft;
6928:): if ($rem) {
6929:): $colsleft = $numinrow - $rem;
6930:): }
6931:): if ($colsleft > 1) {
1.33 raeburn 6932: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6933: ' </td>';
6934: } elsif ($colsleft == 1) {
6935: $output .= '<td class="LC_left_item"> </td>';
6936: }
6937: $output .= '</tr></table></td></tr>';
6938: return $output;
6939: }
1.28 raeburn 6940:
1.93 raeburn 6941: sub insttypes_row {
1.160.6.84.4. (raeburn 6942:): my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
6943:): $customcss,$rowstyle) = @_;
1.93 raeburn 6944: my %lt = &Apache::lonlocal::texthash (
6945: cansearch => 'Users allowed to search',
6946: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6947: lockablenames => 'User preference to lock name',
1.160.6.84.4. (raeburn 6948:): selfassign => 'Self-reportable affiliations',
1.93 raeburn 6949: );
6950: my $showdom;
6951: if ($context eq 'cansearch') {
6952: $showdom = ' ('.$dom.')';
6953: }
1.160.6.5 raeburn 6954: my $class = 'LC_left_item';
6955: if ($context eq 'statustocreate') {
6956: $class = 'LC_right_item';
6957: }
1.160.6.84.4. (raeburn 6958:): my $css_class;
6959:): if ($$rowtotal%2) {
6960:): $css_class = 'LC_odd_row';
6961:): }
6962:): if ($customcss) {
6963:): $css_class .= ' '.$customcss;
6964:): }
6965:): $css_class =~ s/^\s+//;
6966:): if ($css_class) {
6967:): $css_class = ' class="'.$css_class.'"';
6968:): }
6969:): if ($rowstyle) {
6970:): $css_class .= ' style="'.$rowstyle.'"';
6971:): }
6972:): if ($onclick) {
6973:): $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 6974: }
6975: my $output = '<tr'.$css_class.'>'.
6976: '<td>'.$lt{$context}.$showdom.
6977: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6978: my $rem;
6979: if (ref($types) eq 'ARRAY') {
6980: for (my $i=0; $i<@{$types}; $i++) {
6981: if (defined($usertypes->{$types->[$i]})) {
6982: my $rem = $i%($numinrow);
6983: if ($rem == 0) {
6984: if ($i > 0) {
6985: $output .= '</tr>';
6986: }
6987: $output .= '<tr>';
1.23 raeburn 6988: }
1.26 raeburn 6989: my $check = ' ';
1.99 raeburn 6990: if (ref($settings) eq 'HASH') {
6991: if (ref($settings->{$context}) eq 'ARRAY') {
6992: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6993: $check = ' checked="checked" ';
6994: }
6995: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6996: $check = ' checked="checked" ';
6997: }
1.23 raeburn 6998: }
1.26 raeburn 6999: $output .= '<td class="LC_left_item">'.
7000: '<span class="LC_nobreak"><label>'.
1.93 raeburn 7001: '<input type="checkbox" name="'.$context.'" '.
1.160.6.84.4. (raeburn 7002:): 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 7003: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 7004: }
7005: }
1.26 raeburn 7006: $rem = @{$types}%($numinrow);
1.23 raeburn 7007: }
7008: my $colsleft = $numinrow - $rem;
1.131 raeburn 7009: if (($rem == 0) && (@{$types} > 0)) {
7010: $output .= '<tr>';
7011: }
1.23 raeburn 7012: if ($colsleft > 1) {
1.25 raeburn 7013: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 7014: } else {
1.25 raeburn 7015: $output .= '<td class="LC_left_item">';
1.23 raeburn 7016: }
7017: my $defcheck = ' ';
1.99 raeburn 7018: if (ref($settings) eq 'HASH') {
7019: if (ref($settings->{$context}) eq 'ARRAY') {
7020: if (grep(/^default$/,@{$settings->{$context}})) {
7021: $defcheck = ' checked="checked" ';
7022: }
7023: } elsif ($context eq 'statustocreate') {
1.26 raeburn 7024: $defcheck = ' checked="checked" ';
7025: }
1.23 raeburn 7026: }
1.25 raeburn 7027: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 7028: '<input type="checkbox" name="'.$context.'" '.
1.160.6.84.4. (raeburn 7029:): 'value="default"'.$defcheck.$onclick.' />'.
1.25 raeburn 7030: $othertitle.'</label></span></td>'.
7031: '</tr></table></td></tr>';
7032: return $output;
1.23 raeburn 7033: }
7034:
7035: sub sorted_searchtitles {
7036: my %searchtitles = &Apache::lonlocal::texthash(
7037: 'uname' => 'username',
7038: 'lastname' => 'last name',
7039: 'lastfirst' => 'last name, first name',
7040: );
7041: my @titleorder = ('uname','lastname','lastfirst');
7042: return (\%searchtitles,\@titleorder);
7043: }
7044:
1.25 raeburn 7045: sub sorted_searchtypes {
7046: my %srchtypes_desc = (
7047: exact => 'is exact match',
7048: contains => 'contains ..',
7049: begins => 'begins with ..',
7050: );
7051: my @srchtypeorder = ('exact','begins','contains');
7052: return (\%srchtypes_desc,\@srchtypeorder);
7053: }
7054:
1.3 raeburn 7055: sub usertype_update_row {
7056: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
7057: my $datatable;
7058: my $numinrow = 4;
7059: foreach my $type (@{$types}) {
7060: if (defined($usertypes->{$type})) {
7061: $$rownums ++;
7062: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
7063: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
7064: '</td><td class="LC_left_item"><table>';
7065: for (my $i=0; $i<@{$fields}; $i++) {
7066: my $rem = $i%($numinrow);
7067: if ($rem == 0) {
7068: if ($i > 0) {
7069: $datatable .= '</tr>';
7070: }
7071: $datatable .= '<tr>';
7072: }
7073: my $check = ' ';
1.39 raeburn 7074: if (ref($settings) eq 'HASH') {
7075: if (ref($settings->{'fields'}) eq 'HASH') {
7076: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
7077: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
7078: $check = ' checked="checked" ';
7079: }
1.3 raeburn 7080: }
7081: }
7082: }
7083:
7084: if ($i == @{$fields}-1) {
7085: my $colsleft = $numinrow - $rem;
7086: if ($colsleft > 1) {
7087: $datatable .= '<td colspan="'.$colsleft.'">';
7088: } else {
7089: $datatable .= '<td>';
7090: }
7091: } else {
7092: $datatable .= '<td>';
7093: }
1.8 raeburn 7094: $datatable .= '<span class="LC_nobreak"><label>'.
7095: '<input type="checkbox" name="updateable_'.$type.
7096: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
7097: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 7098: }
7099: $datatable .= '</tr></table></td></tr>';
7100: }
7101: }
7102: return $datatable;
1.1 raeburn 7103: }
7104:
7105: sub modify_login {
1.160.6.24 raeburn 7106: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 7107: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
7108: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
7109: %title = ( coursecatalog => 'Display course catalog',
7110: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 7111: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 7112: newuser => 'Link for visitors to create a user account',
7113: loginheader => 'Log-in box header');
7114: @offon = ('off','on');
1.112 raeburn 7115: if (ref($domconfig{login}) eq 'HASH') {
7116: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
7117: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
7118: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
7119: }
7120: }
7121: }
1.9 raeburn 7122: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
7123: \%domconfig,\%loginhash);
1.160.6.14 raeburn 7124: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7125: foreach my $item (@toggles) {
7126: $loginhash{login}{$item} = $env{'form.'.$item};
7127: }
1.41 raeburn 7128: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 7129: if (ref($colchanges{'login'}) eq 'HASH') {
7130: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
7131: \%loginhash);
7132: }
1.110 raeburn 7133:
1.149 raeburn 7134: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 7135: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 7136: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 7137: if (keys(%servers) > 1) {
7138: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 7139: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
7140: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
7141: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
7142: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
7143: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
7144: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7145: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7146: $changes{'loginvia'}{$lonhost} = 1;
7147: } else {
7148: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
7149: $changes{'loginvia'}{$lonhost} = 1;
7150: }
7151: } else {
7152: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7153: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
7154: $changes{'loginvia'}{$lonhost} = 1;
7155: }
7156: }
7157: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
7158: foreach my $item (@loginvia_attribs) {
7159: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
7160: }
7161: } else {
7162: foreach my $item (@loginvia_attribs) {
7163: my $new = $env{'form.'.$lonhost.'_'.$item};
7164: if (($item eq 'serverpath') && ($new eq 'custom')) {
7165: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
7166: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7167: $new = '/';
7168: }
7169: }
7170: if (($item eq 'custompath') &&
7171: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7172: $new = '';
7173: }
7174: if ($new ne $curr_loginvia{$lonhost}{$item}) {
7175: $changes{'loginvia'}{$lonhost} = 1;
7176: }
7177: if ($item eq 'exempt') {
1.160.6.56 raeburn 7178: $new = &check_exempt_addresses($new);
1.128 raeburn 7179: }
7180: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7181: }
7182: }
1.112 raeburn 7183: } else {
1.128 raeburn 7184: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
7185: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 7186: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 7187: foreach my $item (@loginvia_attribs) {
7188: my $new = $env{'form.'.$lonhost.'_'.$item};
7189: if (($item eq 'serverpath') && ($new eq 'custom')) {
7190: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
7191: $new = '/';
7192: }
7193: }
7194: if (($item eq 'custompath') &&
7195: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
7196: $new = '';
7197: }
7198: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
7199: }
1.110 raeburn 7200: }
7201: }
7202: }
7203: }
1.119 raeburn 7204:
1.160.6.5 raeburn 7205: my $servadm = $r->dir_config('lonAdmEMail');
7206: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
7207: if (ref($domconfig{'login'}) eq 'HASH') {
7208: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
7209: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
7210: if ($lang eq 'nolang') {
7211: push(@currlangs,$lang);
7212: } elsif (defined($langchoices{$lang})) {
7213: push(@currlangs,$lang);
7214: } else {
7215: next;
7216: }
7217: }
7218: }
7219: }
7220: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
7221: if (@currlangs > 0) {
7222: foreach my $lang (@currlangs) {
7223: if (grep(/^\Q$lang\E$/,@delurls)) {
7224: $changes{'helpurl'}{$lang} = 1;
7225: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
7226: $changes{'helpurl'}{$lang} = 1;
7227: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
7228: push(@newlangs,$lang);
7229: } else {
7230: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7231: }
7232: }
7233: }
7234: unless (grep(/^nolang$/,@currlangs)) {
7235: if ($env{'form.loginhelpurl_nolang.filename'}) {
7236: $changes{'helpurl'}{'nolang'} = 1;
7237: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
7238: push(@newlangs,'nolang');
7239: }
7240: }
7241: if ($env{'form.loginhelpurl_add_lang'}) {
7242: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
7243: ($env{'form.loginhelpurl_add_file.filename'})) {
7244: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
7245: $addedfile = $env{'form.loginhelpurl_add_lang'};
7246: }
7247: }
7248: if ((@newlangs > 0) || ($addedfile)) {
7249: my $error;
7250: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7251: if ($configuserok eq 'ok') {
7252: if ($switchserver) {
7253: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
7254: } elsif ($author_ok eq 'ok') {
7255: my @allnew = @newlangs;
7256: if ($addedfile ne '') {
7257: push(@allnew,$addedfile);
7258: }
7259: foreach my $lang (@allnew) {
7260: my $formelem = 'loginhelpurl_'.$lang;
7261: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
7262: $formelem = 'loginhelpurl_add_file';
7263: }
7264: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7265: "help/$lang",'','',$newfile{$lang});
7266: if ($result eq 'ok') {
7267: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
7268: $changes{'helpurl'}{$lang} = 1;
7269: } else {
7270: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
7271: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7272: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
7273: (!grep(/^\Q$lang\E$/,@delurls))) {
7274: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
7275: }
7276: }
7277: }
7278: } else {
7279: $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);
7280: }
7281: } else {
7282: $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);
7283: }
7284: if ($error) {
7285: &Apache::lonnet::logthis($error);
7286: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7287: }
7288: }
1.160.6.56 raeburn 7289:
7290: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
7291: if (ref($domconfig{'login'}) eq 'HASH') {
7292: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
7293: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
7294: if ($domservers{$lonhost}) {
7295: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7296: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 7297: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 7298: }
7299: }
7300: }
7301: }
7302: }
7303: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
7304: foreach my $lonhost (sort(keys(%domservers))) {
7305: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7306: $changes{'headtag'}{$lonhost} = 1;
7307: } else {
7308: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7309: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7310: }
7311: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7312: push(@newhosts,$lonhost);
7313: } elsif ($currheadtagurls{$lonhost}) {
7314: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7315: if ($currexempt{$lonhost}) {
7316: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
7317: $changes{'headtag'}{$lonhost} = 1;
7318: }
7319: } elsif ($possexempt{$lonhost}) {
7320: $changes{'headtag'}{$lonhost} = 1;
7321: }
7322: if ($possexempt{$lonhost}) {
7323: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7324: }
7325: }
7326: }
7327: }
7328: if (@newhosts) {
7329: my $error;
7330: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7331: if ($configuserok eq 'ok') {
7332: if ($switchserver) {
7333: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7334: } elsif ($author_ok eq 'ok') {
7335: foreach my $lonhost (@newhosts) {
7336: my $formelem = 'loginheadtag_'.$lonhost;
7337: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7338: "login/headtag/$lonhost",'','',
7339: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7340: if ($result eq 'ok') {
7341: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7342: $changes{'headtag'}{$lonhost} = 1;
7343: if ($possexempt{$lonhost}) {
7344: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7345: }
7346: } else {
7347: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7348: $newheadtagurls{$lonhost},$result);
7349: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7350: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7351: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7352: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7353: }
7354: }
7355: }
7356: } else {
7357: $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);
7358: }
7359: } else {
7360: $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);
7361: }
7362: if ($error) {
7363: &Apache::lonnet::logthis($error);
7364: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7365: }
7366: }
1.160.6.5 raeburn 7367: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7368:
7369: my $defaulthelpfile = '/adm/loginproblems.html';
7370: my $defaulttext = &mt('Default in use');
7371:
1.1 raeburn 7372: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7373: $dom);
7374: if ($putresult eq 'ok') {
1.160.6.14 raeburn 7375: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7376: my %defaultchecked = (
7377: 'coursecatalog' => 'on',
1.160.6.14 raeburn 7378: 'helpdesk' => 'on',
1.42 raeburn 7379: 'adminmail' => 'off',
1.43 raeburn 7380: 'newuser' => 'off',
1.42 raeburn 7381: );
1.55 raeburn 7382: if (ref($domconfig{'login'}) eq 'HASH') {
7383: foreach my $item (@toggles) {
7384: if ($defaultchecked{$item} eq 'on') {
7385: if (($domconfig{'login'}{$item} eq '0') &&
7386: ($env{'form.'.$item} eq '1')) {
7387: $changes{$item} = 1;
7388: } elsif (($domconfig{'login'}{$item} eq '' ||
7389: $domconfig{'login'}{$item} eq '1') &&
7390: ($env{'form.'.$item} eq '0')) {
7391: $changes{$item} = 1;
7392: }
7393: } elsif ($defaultchecked{$item} eq 'off') {
7394: if (($domconfig{'login'}{$item} eq '1') &&
7395: ($env{'form.'.$item} eq '0')) {
7396: $changes{$item} = 1;
7397: } elsif (($domconfig{'login'}{$item} eq '' ||
7398: $domconfig{'login'}{$item} eq '0') &&
7399: ($env{'form.'.$item} eq '1')) {
7400: $changes{$item} = 1;
7401: }
1.42 raeburn 7402: }
7403: }
1.41 raeburn 7404: }
1.6 raeburn 7405: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7406: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7407: if (ref($lastactref) eq 'HASH') {
7408: $lastactref->{'domainconfig'} = 1;
7409: }
1.1 raeburn 7410: $resulttext = &mt('Changes made:').'<ul>';
7411: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7412: if ($item eq 'loginvia') {
1.112 raeburn 7413: if (ref($changes{$item}) eq 'HASH') {
7414: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7415: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7416: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7417: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7418: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7419: $protocol = 'http' if ($protocol ne 'https');
7420: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7421:
7422: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7423: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7424: } else {
7425: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7426: }
7427: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7428: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7429: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7430: }
7431: $resulttext .= '</li>';
7432: } else {
7433: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7434: }
1.112 raeburn 7435: } else {
1.128 raeburn 7436: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7437: }
7438: }
1.128 raeburn 7439: $resulttext .= '</ul></li>';
1.112 raeburn 7440: }
1.160.6.5 raeburn 7441: } elsif ($item eq 'helpurl') {
7442: if (ref($changes{$item}) eq 'HASH') {
7443: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7444: if (grep(/^\Q$lang\E$/,@delurls)) {
7445: my ($chg,$link);
7446: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7447: if ($lang eq 'nolang') {
7448: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7449: } else {
7450: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7451: }
7452: $resulttext .= '<li>'.$chg.'</li>';
7453: } else {
7454: my $chg;
7455: if ($lang eq 'nolang') {
7456: $chg = &mt('custom log-in help file for no preferred language');
7457: } else {
7458: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7459: }
7460: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7461: $loginhash{'login'}{'helpurl'}{$lang}.
7462: '?inhibitmenu=yes',$chg,600,500).
7463: '</li>';
7464: }
7465: }
7466: }
1.160.6.56 raeburn 7467: } elsif ($item eq 'headtag') {
7468: if (ref($changes{$item}) eq 'HASH') {
7469: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7470: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7471: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7472: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7473: $resulttext .= '<li><a href="'.
7474: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7475: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7476: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7477: if ($possexempt{$lonhost}) {
7478: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7479: } else {
7480: $resulttext .= &mt('included for any client IP');
7481: }
7482: $resulttext .= '</li>';
7483: }
7484: }
7485: }
1.160.6.5 raeburn 7486: } elsif ($item eq 'captcha') {
7487: if (ref($loginhash{'login'}) eq 'HASH') {
7488: my $chgtxt;
7489: if ($loginhash{'login'}{$item} eq 'notused') {
7490: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7491: } else {
7492: my %captchas = &captcha_phrases();
7493: if ($captchas{$loginhash{'login'}{$item}}) {
7494: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7495: } else {
7496: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7497: }
7498: }
7499: $resulttext .= '<li>'.$chgtxt.'</li>';
7500: }
7501: } elsif ($item eq 'recaptchakeys') {
7502: if (ref($loginhash{'login'}) eq 'HASH') {
7503: my ($privkey,$pubkey);
7504: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7505: $pubkey = $loginhash{'login'}{$item}{'public'};
7506: $privkey = $loginhash{'login'}{$item}{'private'};
7507: }
7508: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7509: if (!$pubkey) {
7510: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7511: } else {
7512: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7513: }
7514: if (!$privkey) {
7515: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7516: } else {
1.160.6.53 raeburn 7517: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 7518: }
7519: $chgtxt .= '</ul>';
7520: $resulttext .= '<li>'.$chgtxt.'</li>';
7521: }
1.160.6.69 raeburn 7522: } elsif ($item eq 'recaptchaversion') {
7523: if (ref($loginhash{'login'}) eq 'HASH') {
7524: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
7525: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
7526: '</li>';
7527: }
7528: }
1.41 raeburn 7529: } else {
7530: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7531: }
1.1 raeburn 7532: }
1.6 raeburn 7533: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7534: } else {
7535: $resulttext = &mt('No changes made to log-in page settings');
7536: }
7537: } else {
1.11 albertel 7538: $resulttext = '<span class="LC_error">'.
7539: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7540: }
1.6 raeburn 7541: if ($errors) {
1.9 raeburn 7542: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7543: $errors.'</ul>';
7544: }
7545: return $resulttext;
7546: }
7547:
1.160.6.56 raeburn 7548: sub check_exempt_addresses {
7549: my ($iplist) = @_;
7550: $iplist =~ s/^\s+//;
7551: $iplist =~ s/\s+$//;
7552: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7553: my (@okips,$new);
7554: foreach my $ip (@poss_ips) {
7555: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7556: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7557: push(@okips,$ip);
7558: }
7559: }
7560: }
7561: if (@okips > 0) {
7562: $new = join(',',@okips);
7563: } else {
7564: $new = '';
7565: }
7566: return $new;
7567: }
7568:
1.6 raeburn 7569: sub color_font_choices {
7570: my %choices =
7571: &Apache::lonlocal::texthash (
7572: img => "Header",
7573: bgs => "Background colors",
7574: links => "Link colors",
1.55 raeburn 7575: images => "Images",
1.6 raeburn 7576: font => "Font color",
1.160.6.22 raeburn 7577: fontmenu => "Font menu",
1.76 raeburn 7578: pgbg => "Page",
1.6 raeburn 7579: tabbg => "Header",
7580: sidebg => "Border",
7581: link => "Link",
7582: alink => "Active link",
7583: vlink => "Visited link",
7584: );
7585: return %choices;
7586: }
7587:
7588: sub modify_rolecolors {
1.160.6.24 raeburn 7589: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7590: my ($resulttext,%rolehash);
7591: $rolehash{'rolecolors'} = {};
1.55 raeburn 7592: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7593: if ($domconfig{'rolecolors'} eq '') {
7594: $domconfig{'rolecolors'} = {};
7595: }
7596: }
1.9 raeburn 7597: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7598: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7599: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7600: $dom);
7601: if ($putresult eq 'ok') {
7602: if (keys(%changes) > 0) {
1.41 raeburn 7603: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7604: if (ref($lastactref) eq 'HASH') {
7605: $lastactref->{'domainconfig'} = 1;
7606: }
1.6 raeburn 7607: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7608: $rolehash{'rolecolors'});
7609: } else {
7610: $resulttext = &mt('No changes made to default color schemes');
7611: }
7612: } else {
1.11 albertel 7613: $resulttext = '<span class="LC_error">'.
7614: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7615: }
7616: if ($errors) {
7617: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7618: $errors.'</ul>';
7619: }
7620: return $resulttext;
7621: }
7622:
7623: sub modify_colors {
1.9 raeburn 7624: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7625: my (%changes,%choices);
1.51 raeburn 7626: my @bgs;
1.6 raeburn 7627: my @links = ('link','alink','vlink');
1.41 raeburn 7628: my @logintext;
1.6 raeburn 7629: my @images;
7630: my $servadm = $r->dir_config('lonAdmEMail');
7631: my $errors;
1.160.6.22 raeburn 7632: my %defaults;
1.6 raeburn 7633: foreach my $role (@{$roles}) {
7634: if ($role eq 'login') {
1.12 raeburn 7635: %choices = &login_choices();
1.41 raeburn 7636: @logintext = ('textcol','bgcol');
1.12 raeburn 7637: } else {
7638: %choices = &color_font_choices();
7639: }
7640: if ($role eq 'login') {
1.41 raeburn 7641: @images = ('img','logo','domlogo','login');
1.51 raeburn 7642: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7643: } else {
7644: @images = ('img');
1.160.6.22 raeburn 7645: @bgs = ('pgbg','tabbg','sidebg');
7646: }
7647: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7648: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7649: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7650: }
7651: if ($role eq 'login') {
7652: foreach my $item (@logintext) {
1.160.6.39 raeburn 7653: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7654: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7655: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7656: }
7657: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 7658: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7659: }
7660: }
7661: } else {
1.160.6.39 raeburn 7662: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7663: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7664: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7665: }
7666: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 7667: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7668: }
1.6 raeburn 7669: }
1.160.6.22 raeburn 7670: foreach my $item (@bgs) {
1.160.6.39 raeburn 7671: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7672: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7673: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7674: }
7675: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 7676: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7677: }
7678: }
7679: foreach my $item (@links) {
1.160.6.39 raeburn 7680: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7681: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7682: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7683: }
7684: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 7685: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7686: }
1.6 raeburn 7687: }
1.46 raeburn 7688: my ($configuserok,$author_ok,$switchserver) =
7689: &config_check($dom,$confname,$servadm);
1.9 raeburn 7690: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7691: if (ref($domconfig->{$role}) ne 'HASH') {
7692: $domconfig->{$role} = {};
7693: }
1.8 raeburn 7694: foreach my $img (@images) {
1.70 raeburn 7695: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7696: if (defined($env{'form.login_showlogo_'.$img})) {
7697: $confhash->{$role}{'showlogo'}{$img} = 1;
7698: } else {
7699: $confhash->{$role}{'showlogo'}{$img} = 0;
7700: }
7701: }
1.18 albertel 7702: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7703: && !defined($domconfig->{$role}{$img})
7704: && !$env{'form.'.$role.'_del_'.$img}
7705: && $env{'form.'.$role.'_import_'.$img}) {
7706: # import the old configured image from the .tab setting
7707: # if they haven't provided a new one
7708: $domconfig->{$role}{$img} =
7709: $env{'form.'.$role.'_import_'.$img};
7710: }
1.6 raeburn 7711: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7712: my $error;
1.6 raeburn 7713: if ($configuserok eq 'ok') {
1.9 raeburn 7714: if ($switchserver) {
1.12 raeburn 7715: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7716: } else {
7717: if ($author_ok eq 'ok') {
7718: my ($result,$logourl) =
7719: &publishlogo($r,'upload',$role.'_'.$img,
7720: $dom,$confname,$img,$width,$height);
7721: if ($result eq 'ok') {
7722: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7723: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7724: } else {
1.12 raeburn 7725: $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 7726: }
7727: } else {
1.46 raeburn 7728: $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 7729: }
7730: }
7731: } else {
1.46 raeburn 7732: $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 7733: }
7734: if ($error) {
1.8 raeburn 7735: &Apache::lonnet::logthis($error);
1.11 albertel 7736: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7737: }
7738: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7739: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7740: my $error;
7741: if ($configuserok eq 'ok') {
7742: # is confname an author?
7743: if ($switchserver eq '') {
7744: if ($author_ok eq 'ok') {
7745: my ($result,$logourl) =
7746: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7747: $dom,$confname,$img,$width,$height);
7748: if ($result eq 'ok') {
7749: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7750: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7751: }
7752: }
7753: }
7754: }
1.6 raeburn 7755: }
7756: }
7757: }
7758: if (ref($domconfig) eq 'HASH') {
7759: if (ref($domconfig->{$role}) eq 'HASH') {
7760: foreach my $img (@images) {
7761: if ($domconfig->{$role}{$img} ne '') {
7762: if ($env{'form.'.$role.'_del_'.$img}) {
7763: $confhash->{$role}{$img} = '';
1.12 raeburn 7764: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7765: } else {
1.9 raeburn 7766: if ($confhash->{$role}{$img} eq '') {
7767: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7768: }
1.6 raeburn 7769: }
7770: } else {
7771: if ($env{'form.'.$role.'_del_'.$img}) {
7772: $confhash->{$role}{$img} = '';
1.12 raeburn 7773: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7774: }
7775: }
1.70 raeburn 7776: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7777: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7778: if ($confhash->{$role}{'showlogo'}{$img} ne
7779: $domconfig->{$role}{'showlogo'}{$img}) {
7780: $changes{$role}{'showlogo'}{$img} = 1;
7781: }
7782: } else {
7783: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7784: $changes{$role}{'showlogo'}{$img} = 1;
7785: }
7786: }
7787: }
7788: }
1.6 raeburn 7789: if ($domconfig->{$role}{'font'} ne '') {
7790: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7791: $changes{$role}{'font'} = 1;
7792: }
7793: } else {
7794: if ($confhash->{$role}{'font'}) {
7795: $changes{$role}{'font'} = 1;
7796: }
7797: }
1.107 raeburn 7798: if ($role ne 'login') {
7799: if ($domconfig->{$role}{'fontmenu'} ne '') {
7800: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7801: $changes{$role}{'fontmenu'} = 1;
7802: }
7803: } else {
7804: if ($confhash->{$role}{'fontmenu'}) {
7805: $changes{$role}{'fontmenu'} = 1;
7806: }
1.97 tempelho 7807: }
7808: }
1.6 raeburn 7809: foreach my $item (@bgs) {
7810: if ($domconfig->{$role}{$item} ne '') {
7811: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7812: $changes{$role}{'bgs'}{$item} = 1;
7813: }
7814: } else {
7815: if ($confhash->{$role}{$item}) {
7816: $changes{$role}{'bgs'}{$item} = 1;
7817: }
7818: }
7819: }
7820: foreach my $item (@links) {
7821: if ($domconfig->{$role}{$item} ne '') {
7822: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7823: $changes{$role}{'links'}{$item} = 1;
7824: }
7825: } else {
7826: if ($confhash->{$role}{$item}) {
7827: $changes{$role}{'links'}{$item} = 1;
7828: }
7829: }
7830: }
1.41 raeburn 7831: foreach my $item (@logintext) {
7832: if ($domconfig->{$role}{$item} ne '') {
7833: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7834: $changes{$role}{'logintext'}{$item} = 1;
7835: }
7836: } else {
7837: if ($confhash->{$role}{$item}) {
7838: $changes{$role}{'logintext'}{$item} = 1;
7839: }
7840: }
7841: }
1.6 raeburn 7842: } else {
7843: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7844: \@logintext,$confhash,\%changes);
1.6 raeburn 7845: }
7846: } else {
7847: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7848: \@logintext,$confhash,\%changes);
1.6 raeburn 7849: }
7850: }
7851: return ($errors,%changes);
7852: }
7853:
1.46 raeburn 7854: sub config_check {
7855: my ($dom,$confname,$servadm) = @_;
7856: my ($configuserok,$author_ok,$switchserver,%currroles);
7857: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7858: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7859: $confname,$servadm);
7860: if ($configuserok eq 'ok') {
7861: $switchserver = &check_switchserver($dom,$confname);
7862: if ($switchserver eq '') {
7863: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7864: }
7865: }
7866: return ($configuserok,$author_ok,$switchserver);
7867: }
7868:
1.6 raeburn 7869: sub default_change_checker {
1.41 raeburn 7870: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7871: foreach my $item (@{$links}) {
7872: if ($confhash->{$role}{$item}) {
7873: $changes->{$role}{'links'}{$item} = 1;
7874: }
7875: }
7876: foreach my $item (@{$bgs}) {
7877: if ($confhash->{$role}{$item}) {
7878: $changes->{$role}{'bgs'}{$item} = 1;
7879: }
7880: }
1.41 raeburn 7881: foreach my $item (@{$logintext}) {
7882: if ($confhash->{$role}{$item}) {
7883: $changes->{$role}{'logintext'}{$item} = 1;
7884: }
7885: }
1.6 raeburn 7886: foreach my $img (@{$images}) {
7887: if ($env{'form.'.$role.'_del_'.$img}) {
7888: $confhash->{$role}{$img} = '';
1.12 raeburn 7889: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7890: }
1.70 raeburn 7891: if ($role eq 'login') {
7892: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7893: $changes->{$role}{'showlogo'}{$img} = 1;
7894: }
7895: }
1.6 raeburn 7896: }
7897: if ($confhash->{$role}{'font'}) {
7898: $changes->{$role}{'font'} = 1;
7899: }
1.48 raeburn 7900: }
1.6 raeburn 7901:
7902: sub display_colorchgs {
7903: my ($dom,$changes,$roles,$confhash) = @_;
7904: my (%choices,$resulttext);
7905: if (!grep(/^login$/,@{$roles})) {
7906: $resulttext = &mt('Changes made:').'<br />';
7907: }
7908: foreach my $role (@{$roles}) {
7909: if ($role eq 'login') {
7910: %choices = &login_choices();
7911: } else {
7912: %choices = &color_font_choices();
7913: }
7914: if (ref($changes->{$role}) eq 'HASH') {
7915: if ($role ne 'login') {
7916: $resulttext .= '<h4>'.&mt($role).'</h4>';
7917: }
7918: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7919: if ($role ne 'login') {
7920: $resulttext .= '<ul>';
7921: }
7922: if (ref($changes->{$role}{$key}) eq 'HASH') {
7923: if ($role ne 'login') {
7924: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7925: }
7926: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7927: if (($role eq 'login') && ($key eq 'showlogo')) {
7928: if ($confhash->{$role}{$key}{$item}) {
7929: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7930: } else {
7931: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7932: }
7933: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7934: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7935: } else {
1.12 raeburn 7936: my $newitem = $confhash->{$role}{$item};
7937: if ($key eq 'images') {
7938: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7939: }
7940: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7941: }
7942: }
7943: if ($role ne 'login') {
7944: $resulttext .= '</ul></li>';
7945: }
7946: } else {
7947: if ($confhash->{$role}{$key} eq '') {
7948: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7949: } else {
7950: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7951: }
7952: }
7953: if ($role ne 'login') {
7954: $resulttext .= '</ul>';
7955: }
7956: }
7957: }
7958: }
1.3 raeburn 7959: return $resulttext;
1.1 raeburn 7960: }
7961:
1.9 raeburn 7962: sub thumb_dimensions {
7963: return ('200','50');
7964: }
7965:
1.16 raeburn 7966: sub check_dimensions {
7967: my ($inputfile) = @_;
7968: my ($fullwidth,$fullheight);
7969: if ($inputfile =~ m|^[/\w.\-]+$|) {
7970: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7971: my $imageinfo = <PIPE>;
7972: if (!close(PIPE)) {
7973: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7974: }
7975: chomp($imageinfo);
7976: my ($fullsize) =
1.21 raeburn 7977: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7978: if ($fullsize) {
7979: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7980: }
7981: }
7982: }
7983: return ($fullwidth,$fullheight);
7984: }
7985:
1.9 raeburn 7986: sub check_configuser {
7987: my ($uhome,$dom,$confname,$servadm) = @_;
7988: my ($configuserok,%currroles);
7989: if ($uhome eq 'no_host') {
7990: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7991: my $configpass = &LONCAPA::Enrollment::create_password();
7992: $configuserok =
7993: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7994: $configpass,'','','','','',undef,$servadm);
7995: } else {
7996: $configuserok = 'ok';
7997: %currroles =
7998: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7999: }
8000: return ($configuserok,%currroles);
8001: }
8002:
8003: sub check_authorstatus {
8004: my ($dom,$confname,%currroles) = @_;
8005: my $author_ok;
1.40 raeburn 8006: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 8007: my $start = time;
8008: my $end = 0;
8009: $author_ok =
8010: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 8011: 'au',$end,$start,'','','domconfig');
1.9 raeburn 8012: } else {
8013: $author_ok = 'ok';
8014: }
8015: return $author_ok;
8016: }
8017:
8018: sub publishlogo {
1.46 raeburn 8019: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 8020: my ($output,$fname,$logourl);
8021: if ($action eq 'upload') {
8022: $fname=$env{'form.'.$formname.'.filename'};
8023: chop($env{'form.'.$formname});
8024: } else {
8025: ($fname) = ($formname =~ /([^\/]+)$/);
8026: }
1.46 raeburn 8027: if ($savefileas ne '') {
8028: $fname = $savefileas;
8029: }
1.9 raeburn 8030: $fname=&Apache::lonnet::clean_filename($fname);
8031: # See if there is anything left
8032: unless ($fname) { return ('error: no uploaded file'); }
8033: $fname="$subdir/$fname";
1.160.6.5 raeburn 8034: my $docroot=$r->dir_config('lonDocRoot');
8035: my $filepath="$docroot/priv";
8036: my $relpath = "$dom/$confname";
1.9 raeburn 8037: my ($fnamepath,$file,$fetchthumb);
8038: $file=$fname;
8039: if ($fname=~m|/|) {
8040: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
8041: }
1.160.6.26 raeburn 8042: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 8043: my $count;
1.160.6.5 raeburn 8044: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 8045: $filepath.="/$parts[$count]";
8046: if ((-e $filepath)!=1) {
8047: mkdir($filepath,02770);
8048: }
8049: }
8050: # Check for bad extension and disallow upload
8051: if ($file=~/\.(\w+)$/ &&
8052: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
8053: $output =
1.160.6.25 raeburn 8054: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 8055: } elsif ($file=~/\.(\w+)$/ &&
8056: !defined(&Apache::loncommon::fileembstyle($1))) {
8057: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
8058: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 8059: $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 8060: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 8061: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 8062: } else {
8063: my $source = $filepath.'/'.$file;
8064: my $logfile;
8065: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 8066: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 8067: }
8068: print $logfile
8069: "\n================= Publish ".localtime()." ================\n".
8070: $env{'user.name'}.':'.$env{'user.domain'}."\n";
8071: # Save the file
8072: if (!open(FH,'>'.$source)) {
8073: &Apache::lonnet::logthis('Failed to create '.$source);
8074: return (&mt('Failed to create file'));
8075: }
8076: if ($action eq 'upload') {
8077: if (!print FH ($env{'form.'.$formname})) {
8078: &Apache::lonnet::logthis('Failed to write to '.$source);
8079: return (&mt('Failed to write file'));
8080: }
8081: } else {
8082: my $original = &Apache::lonnet::filelocation('',$formname);
8083: if(!copy($original,$source)) {
8084: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
8085: return (&mt('Failed to write file'));
8086: }
8087: }
8088: close(FH);
8089: chmod(0660, $source); # Permissions to rw-rw---.
8090:
8091: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
8092: my $copyfile=$targetdir.'/'.$file;
8093:
8094: my @parts=split(/\//,$targetdir);
8095: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
8096: for (my $count=5;$count<=$#parts;$count++) {
8097: $path.="/$parts[$count]";
8098: if (!-e $path) {
8099: print $logfile "\nCreating directory ".$path;
8100: mkdir($path,02770);
8101: }
8102: }
8103: my $versionresult;
8104: if (-e $copyfile) {
8105: $versionresult = &logo_versioning($targetdir,$file,$logfile);
8106: } else {
8107: $versionresult = 'ok';
8108: }
8109: if ($versionresult eq 'ok') {
8110: if (copy($source,$copyfile)) {
8111: print $logfile "\nCopied original source to ".$copyfile."\n";
8112: $output = 'ok';
8113: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 8114: push(@{$modified_urls},[$copyfile,$source]);
8115: my $metaoutput =
8116: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
8117: unless ($registered_cleanup) {
8118: my $handlers = $r->get_handlers('PerlCleanupHandler');
8119: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8120: $registered_cleanup=1;
8121: }
1.9 raeburn 8122: } else {
8123: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
8124: $output = &mt('Failed to copy file to RES space').", $!";
8125: }
8126: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
8127: my $inputfile = $filepath.'/'.$file;
8128: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 8129: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
8130: if ($fullwidth ne '' && $fullheight ne '') {
8131: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
8132: my $thumbsize = $thumbwidth.'x'.$thumbheight;
8133: system("convert -sample $thumbsize $inputfile $outfile");
8134: chmod(0660, $filepath.'/tn-'.$file);
8135: if (-e $outfile) {
8136: my $copyfile=$targetdir.'/tn-'.$file;
8137: if (copy($outfile,$copyfile)) {
8138: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 8139: my $thumb_metaoutput =
8140: &write_metadata($dom,$confname,$formname,
8141: $targetdir,'tn-'.$file,$logfile);
8142: push(@{$modified_urls},[$copyfile,$outfile]);
8143: unless ($registered_cleanup) {
8144: my $handlers = $r->get_handlers('PerlCleanupHandler');
8145: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
8146: $registered_cleanup=1;
8147: }
1.16 raeburn 8148: } else {
8149: print $logfile "\nUnable to write ".$copyfile.
8150: ':'.$!."\n";
8151: }
8152: }
1.9 raeburn 8153: }
8154: }
8155: }
8156: } else {
8157: $output = $versionresult;
8158: }
8159: }
8160: return ($output,$logourl);
8161: }
8162:
8163: sub logo_versioning {
8164: my ($targetdir,$file,$logfile) = @_;
8165: my $target = $targetdir.'/'.$file;
8166: my ($maxversion,$fn,$extn,$output);
8167: $maxversion = 0;
8168: if ($file =~ /^(.+)\.(\w+)$/) {
8169: $fn=$1;
8170: $extn=$2;
8171: }
8172: opendir(DIR,$targetdir);
8173: while (my $filename=readdir(DIR)) {
8174: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
8175: $maxversion=($1>$maxversion)?$1:$maxversion;
8176: }
8177: }
8178: $maxversion++;
8179: print $logfile "\nCreating old version ".$maxversion."\n";
8180: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
8181: if (copy($target,$copyfile)) {
8182: print $logfile "Copied old target to ".$copyfile."\n";
8183: $copyfile=$copyfile.'.meta';
8184: if (copy($target.'.meta',$copyfile)) {
8185: print $logfile "Copied old target metadata to ".$copyfile."\n";
8186: $output = 'ok';
8187: } else {
8188: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
8189: $output = &mt('Failed to copy old meta').", $!, ";
8190: }
8191: } else {
8192: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
8193: $output = &mt('Failed to copy old target').", $!, ";
8194: }
8195: return $output;
8196: }
8197:
8198: sub write_metadata {
8199: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
8200: my (%metadatafields,%metadatakeys,$output);
8201: $metadatafields{'title'}=$formname;
8202: $metadatafields{'creationdate'}=time;
8203: $metadatafields{'lastrevisiondate'}=time;
8204: $metadatafields{'copyright'}='public';
8205: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
8206: $env{'user.domain'};
8207: $metadatafields{'authorspace'}=$confname.':'.$dom;
8208: $metadatafields{'domain'}=$dom;
8209: {
8210: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
8211: my $mfh;
1.155 raeburn 8212: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 8213: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 8214: unless ($_=~/\./) {
8215: my $unikey=$_;
8216: $unikey=~/^([A-Za-z]+)/;
8217: my $tag=$1;
8218: $tag=~tr/A-Z/a-z/;
8219: print $mfh "\n\<$tag";
8220: foreach (split(/\,/,$metadatakeys{$unikey})) {
8221: my $value=$metadatafields{$unikey.'.'.$_};
8222: $value=~s/\"/\'\'/g;
8223: print $mfh ' '.$_.'="'.$value.'"';
8224: }
8225: print $mfh '>'.
8226: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
8227: .'</'.$tag.'>';
8228: }
8229: }
8230: $output = 'ok';
8231: print $logfile "\nWrote metadata";
8232: close($mfh);
8233: } else {
8234: print $logfile "\nFailed to open metadata file";
1.9 raeburn 8235: $output = &mt('Could not write metadata');
8236: }
8237: }
1.155 raeburn 8238: return $output;
8239: }
8240:
8241: sub notifysubscribed {
8242: foreach my $targetsource (@{$modified_urls}){
8243: next unless (ref($targetsource) eq 'ARRAY');
8244: my ($target,$source)=@{$targetsource};
8245: if ($source ne '') {
8246: if (open(my $logfh,'>>'.$source.'.log')) {
8247: print $logfh "\nCleanup phase: Notifications\n";
8248: my @subscribed=&subscribed_hosts($target);
8249: foreach my $subhost (@subscribed) {
8250: print $logfh "\nNotifying host ".$subhost.':';
8251: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
8252: print $logfh $reply;
8253: }
8254: my @subscribedmeta=&subscribed_hosts("$target.meta");
8255: foreach my $subhost (@subscribedmeta) {
8256: print $logfh "\nNotifying host for metadata only ".$subhost.':';
8257: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
8258: $subhost);
8259: print $logfh $reply;
8260: }
8261: print $logfh "\n============ Done ============\n";
1.160 raeburn 8262: close($logfh);
1.155 raeburn 8263: }
8264: }
8265: }
8266: return OK;
8267: }
8268:
8269: sub subscribed_hosts {
8270: my ($target) = @_;
8271: my @subscribed;
8272: if (open(my $fh,"<$target.subscription")) {
8273: while (my $subline=<$fh>) {
8274: if ($subline =~ /^($match_lonid):/) {
8275: my $host = $1;
8276: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
8277: unless (grep(/^\Q$host\E$/,@subscribed)) {
8278: push(@subscribed,$host);
8279: }
8280: }
8281: }
8282: }
8283: }
8284: return @subscribed;
1.9 raeburn 8285: }
8286:
8287: sub check_switchserver {
8288: my ($dom,$confname) = @_;
8289: my ($allowed,$switchserver);
8290: my $home = &Apache::lonnet::homeserver($confname,$dom);
8291: if ($home eq 'no_host') {
8292: $home = &Apache::lonnet::domain($dom,'primary');
8293: }
8294: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 8295: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
8296: if (!$allowed) {
1.160.6.11 raeburn 8297: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 8298: }
8299: return $switchserver;
8300: }
8301:
1.1 raeburn 8302: sub modify_quotas {
1.160.6.30 raeburn 8303: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8304: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 8305: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 8306: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8307: $validationfieldsref);
1.86 raeburn 8308: if ($action eq 'quotas') {
8309: $context = 'tools';
1.160.6.26 raeburn 8310: } else {
1.86 raeburn 8311: $context = $action;
8312: }
8313: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 8314: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 8315: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8316: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8317: %titles = &courserequest_titles();
8318: $toolregexp = join('|',@usertools);
8319: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 8320: $confname = $dom.'-domainconfig';
8321: my $servadm = $r->dir_config('lonAdmEMail');
8322: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 8323: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8324: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 8325: } elsif ($context eq 'requestauthor') {
8326: @usertools = ('author');
8327: %titles = &authorrequest_titles();
1.86 raeburn 8328: } else {
1.160.6.4 raeburn 8329: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8330: %titles = &tool_titles();
1.86 raeburn 8331: }
1.160.6.27 raeburn 8332: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8333: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8334: foreach my $key (keys(%env)) {
1.101 raeburn 8335: if ($context eq 'requestcourses') {
8336: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8337: my $item = $1;
8338: my $type = $2;
8339: if ($type =~ /^limit_(.+)/) {
8340: $limithash{$item}{$1} = $env{$key};
8341: } else {
8342: $confhash{$item}{$type} = $env{$key};
8343: }
8344: }
1.160.6.5 raeburn 8345: } elsif ($context eq 'requestauthor') {
8346: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8347: $confhash{$1} = $env{$key};
8348: }
1.101 raeburn 8349: } else {
1.86 raeburn 8350: if ($key =~ /^form\.quota_(.+)$/) {
8351: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 8352: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8353: $confhash{'authorquota'}{$1} = $env{$key};
8354: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8355: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8356: }
1.72 raeburn 8357: }
8358: }
1.160.6.5 raeburn 8359: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 8360: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8361: @approvalnotify = sort(@approvalnotify);
8362: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 8363: my @crstypes = ('official','unofficial','community','textbook');
8364: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8365: foreach my $type (@hasuniquecode) {
8366: if (grep(/^\Q$type\E$/,@crstypes)) {
8367: $confhash{'uniquecode'}{$type} = 1;
8368: }
8369: }
1.160.6.46 raeburn 8370: my (%newbook,%allpos);
1.160.6.30 raeburn 8371: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8372: foreach my $type ('textbooks','templates') {
8373: @{$allpos{$type}} = ();
8374: my $invalid;
8375: if ($type eq 'textbooks') {
8376: $invalid = &mt('Invalid LON-CAPA course for textbook');
8377: } else {
8378: $invalid = &mt('Invalid LON-CAPA course for template');
8379: }
8380: if ($env{'form.'.$type.'_addbook'}) {
8381: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8382: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8383: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8384: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8385: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8386: } else {
8387: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8388: my $position = $env{'form.'.$type.'_addbook_pos'};
8389: $position =~ s/\D+//g;
8390: if ($position ne '') {
8391: $allpos{$type}[$position] = $newbook{$type};
8392: }
1.160.6.30 raeburn 8393: }
1.160.6.46 raeburn 8394: } else {
8395: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 8396: }
8397: }
1.160.6.46 raeburn 8398: }
1.160.6.30 raeburn 8399: }
1.102 raeburn 8400: if (ref($domconfig{$action}) eq 'HASH') {
8401: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8402: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8403: $changes{'notify'}{'approval'} = 1;
8404: }
8405: } else {
1.144 raeburn 8406: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8407: $changes{'notify'}{'approval'} = 1;
8408: }
8409: }
1.160.6.30 raeburn 8410: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8411: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8412: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8413: unless ($confhash{'uniquecode'}{$crstype}) {
8414: $changes{'uniquecode'} = 1;
8415: }
8416: }
8417: unless ($changes{'uniquecode'}) {
8418: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8419: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8420: $changes{'uniquecode'} = 1;
8421: }
8422: }
8423: }
8424: } else {
8425: $changes{'uniquecode'} = 1;
8426: }
8427: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8428: $changes{'uniquecode'} = 1;
8429: }
8430: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8431: foreach my $type ('textbooks','templates') {
8432: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8433: my %deletions;
8434: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8435: if (@todelete) {
8436: map { $deletions{$_} = 1; } @todelete;
8437: }
8438: my %imgdeletions;
8439: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8440: if (@todeleteimages) {
8441: map { $imgdeletions{$_} = 1; } @todeleteimages;
8442: }
8443: my $maxnum = $env{'form.'.$type.'_maxnum'};
8444: for (my $i=0; $i<=$maxnum; $i++) {
8445: my $itemid = $env{'form.'.$type.'_id_'.$i};
8446: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8447: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8448: if ($deletions{$key}) {
8449: if ($domconfig{$action}{$type}{$key}{'image'}) {
8450: #FIXME need to obsolete item in RES space
8451: }
8452: next;
8453: } else {
8454: my $newpos = $env{'form.'.$itemid};
8455: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 8456: foreach my $item ('subject','title','publisher','author') {
8457: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8458: ($type eq 'templates'));
1.160.6.46 raeburn 8459: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8460: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8461: $changes{$type}{$key} = 1;
8462: }
8463: }
8464: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 8465: }
1.160.6.46 raeburn 8466: if ($imgdeletions{$key}) {
8467: $changes{$type}{$key} = 1;
8468: #FIXME need to obsolete item in RES space
8469: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8470: my ($cdom,$cnum) = split(/_/,$key);
8471: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8472: $cdom,$cnum,$type,$configuserok,
8473: $switchserver,$author_ok);
8474: if ($imgurl) {
8475: $confhash{$type}{$key}{'image'} = $imgurl;
8476: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 8477: }
1.160.6.46 raeburn 8478: if ($error) {
8479: &Apache::lonnet::logthis($error);
8480: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8481: }
8482: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8483: $confhash{$type}{$key}{'image'} =
8484: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 8485: }
8486: }
8487: }
8488: }
8489: }
8490: }
1.102 raeburn 8491: } else {
1.144 raeburn 8492: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8493: $changes{'notify'}{'approval'} = 1;
8494: }
1.160.6.30 raeburn 8495: if (ref($confhash{'uniquecode'} eq 'HASH')) {
8496: $changes{'uniquecode'} = 1;
8497: }
8498: }
8499: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8500: foreach my $type ('textbooks','templates') {
8501: if ($newbook{$type}) {
8502: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 8503: foreach my $item ('subject','title','publisher','author') {
8504: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8505: ($type eq 'template'));
1.160.6.46 raeburn 8506: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8507: if ($env{'form.'.$type.'_addbook_'.$item}) {
8508: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8509: }
8510: }
8511: if ($type eq 'textbooks') {
8512: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8513: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8514: my ($imageurl,$error) =
8515: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8516: $configuserok,$switchserver,$author_ok);
8517: if ($imageurl) {
8518: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8519: }
8520: if ($error) {
8521: &Apache::lonnet::logthis($error);
8522: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8523: }
8524: }
1.160.6.30 raeburn 8525: }
8526: }
1.160.6.46 raeburn 8527: if (@{$allpos{$type}} > 0) {
8528: my $idx = 0;
8529: foreach my $item (@{$allpos{$type}}) {
8530: if ($item ne '') {
8531: $confhash{$type}{$item}{'order'} = $idx;
8532: if (ref($domconfig{$action}) eq 'HASH') {
8533: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8534: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8535: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8536: $changes{$type}{$item} = 1;
8537: }
1.160.6.30 raeburn 8538: }
8539: }
8540: }
1.160.6.46 raeburn 8541: $idx ++;
1.160.6.30 raeburn 8542: }
8543: }
8544: }
8545: }
1.160.6.39 raeburn 8546: if (ref($validationitemsref) eq 'ARRAY') {
8547: foreach my $item (@{$validationitemsref}) {
8548: if ($item eq 'fields') {
8549: my @changed;
8550: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8551: if (@{$confhash{'validation'}{$item}} > 0) {
8552: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8553: }
1.160.6.65 raeburn 8554: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8555: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8556: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8557: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8558: $domconfig{'requestcourses'}{'validation'}{$item});
8559: } else {
8560: @changed = @{$confhash{'validation'}{$item}};
8561: }
1.160.6.39 raeburn 8562: } else {
8563: @changed = @{$confhash{'validation'}{$item}};
8564: }
8565: } else {
8566: @changed = @{$confhash{'validation'}{$item}};
8567: }
8568: if (@changed) {
8569: if ($confhash{'validation'}{$item}) {
8570: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8571: } else {
8572: $changes{'validation'}{$item} = &mt('None');
8573: }
8574: }
8575: } else {
8576: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8577: if ($item eq 'markup') {
8578: if ($env{'form.requestcourses_validation_'.$item}) {
8579: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8580: }
8581: }
1.160.6.65 raeburn 8582: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8583: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8584: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8585: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8586: }
8587: } else {
8588: if ($confhash{'validation'}{$item} ne '') {
8589: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8590: }
1.160.6.39 raeburn 8591: }
8592: } else {
8593: if ($confhash{'validation'}{$item} ne '') {
8594: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8595: }
8596: }
8597: }
8598: }
8599: }
8600: if ($env{'form.validationdc'}) {
8601: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 8602: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 8603: if (exists($domcoords{$newval})) {
8604: $confhash{'validation'}{'dc'} = $newval;
8605: }
8606: }
8607: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 8608: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8609: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8610: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8611: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8612: if ($confhash{'validation'}{'dc'} eq '') {
8613: $changes{'validation'}{'dc'} = &mt('None');
8614: } else {
8615: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8616: }
1.160.6.39 raeburn 8617: }
1.160.6.65 raeburn 8618: } elsif ($confhash{'validation'}{'dc'} ne '') {
8619: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 8620: }
8621: } elsif ($confhash{'validation'}{'dc'} ne '') {
8622: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8623: }
8624: } elsif ($confhash{'validation'}{'dc'} ne '') {
8625: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8626: }
1.160.6.65 raeburn 8627: } else {
8628: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8629: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8630: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8631: $changes{'validation'}{'dc'} = &mt('None');
8632: }
8633: }
1.160.6.39 raeburn 8634: }
8635: }
1.102 raeburn 8636: }
8637: } else {
1.86 raeburn 8638: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 8639: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8640: }
1.72 raeburn 8641: foreach my $item (@usertools) {
8642: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8643: my $unset;
1.101 raeburn 8644: if ($context eq 'requestcourses') {
1.104 raeburn 8645: $unset = '0';
8646: if ($type eq '_LC_adv') {
8647: $unset = '';
8648: }
1.101 raeburn 8649: if ($confhash{$item}{$type} eq 'autolimit') {
8650: $confhash{$item}{$type} .= '=';
8651: unless ($limithash{$item}{$type} =~ /\D/) {
8652: $confhash{$item}{$type} .= $limithash{$item}{$type};
8653: }
8654: }
1.160.6.5 raeburn 8655: } elsif ($context eq 'requestauthor') {
8656: $unset = '0';
8657: if ($type eq '_LC_adv') {
8658: $unset = '';
8659: }
1.72 raeburn 8660: } else {
1.101 raeburn 8661: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8662: $confhash{$item}{$type} = 1;
8663: } else {
8664: $confhash{$item}{$type} = 0;
8665: }
1.72 raeburn 8666: }
1.86 raeburn 8667: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 8668: if ($action eq 'requestauthor') {
8669: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8670: $changes{$type} = 1;
8671: }
8672: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8673: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8674: $changes{$item}{$type} = 1;
8675: }
8676: } else {
8677: if ($context eq 'requestcourses') {
1.104 raeburn 8678: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8679: $changes{$item}{$type} = 1;
8680: }
8681: } else {
8682: if (!$confhash{$item}{$type}) {
8683: $changes{$item}{$type} = 1;
8684: }
8685: }
8686: }
8687: } else {
8688: if ($context eq 'requestcourses') {
1.104 raeburn 8689: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8690: $changes{$item}{$type} = 1;
8691: }
1.160.6.5 raeburn 8692: } elsif ($context eq 'requestauthor') {
8693: if ($confhash{$type} ne $unset) {
8694: $changes{$type} = 1;
8695: }
1.72 raeburn 8696: } else {
8697: if (!$confhash{$item}{$type}) {
8698: $changes{$item}{$type} = 1;
8699: }
8700: }
8701: }
1.1 raeburn 8702: }
8703: }
1.160.6.5 raeburn 8704: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8705: if (ref($domconfig{'quotas'}) eq 'HASH') {
8706: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8707: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8708: if (exists($confhash{'defaultquota'}{$key})) {
8709: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8710: $changes{'defaultquota'}{$key} = 1;
8711: }
8712: } else {
8713: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8714: }
8715: }
1.86 raeburn 8716: } else {
8717: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8718: if (exists($confhash{'defaultquota'}{$key})) {
8719: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8720: $changes{'defaultquota'}{$key} = 1;
8721: }
8722: } else {
8723: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8724: }
1.1 raeburn 8725: }
8726: }
1.160.6.20 raeburn 8727: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8728: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8729: if (exists($confhash{'authorquota'}{$key})) {
8730: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8731: $changes{'authorquota'}{$key} = 1;
8732: }
8733: } else {
8734: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8735: }
8736: }
8737: }
1.1 raeburn 8738: }
1.86 raeburn 8739: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8740: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8741: if (ref($domconfig{'quotas'}) eq 'HASH') {
8742: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8743: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8744: $changes{'defaultquota'}{$key} = 1;
8745: }
8746: } else {
8747: if (!exists($domconfig{'quotas'}{$key})) {
8748: $changes{'defaultquota'}{$key} = 1;
8749: }
1.72 raeburn 8750: }
8751: } else {
1.86 raeburn 8752: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8753: }
1.1 raeburn 8754: }
8755: }
1.160.6.20 raeburn 8756: if (ref($confhash{'authorquota'}) eq 'HASH') {
8757: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8758: if (ref($domconfig{'quotas'}) eq 'HASH') {
8759: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8760: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8761: $changes{'authorquota'}{$key} = 1;
8762: }
8763: } else {
8764: $changes{'authorquota'}{$key} = 1;
8765: }
8766: } else {
8767: $changes{'authorquota'}{$key} = 1;
8768: }
8769: }
8770: }
1.1 raeburn 8771: }
1.72 raeburn 8772:
1.160.6.5 raeburn 8773: if ($context eq 'requestauthor') {
8774: $domdefaults{'requestauthor'} = \%confhash;
8775: } else {
8776: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 8777: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 8778: $domdefaults{$key} = $confhash{$key};
8779: }
1.160.6.5 raeburn 8780: }
1.72 raeburn 8781: }
1.160.6.5 raeburn 8782:
1.1 raeburn 8783: my %quotahash = (
1.86 raeburn 8784: $action => { %confhash }
1.1 raeburn 8785: );
8786: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8787: $dom);
8788: if ($putresult eq 'ok') {
8789: if (keys(%changes) > 0) {
1.72 raeburn 8790: my $cachetime = 24*60*60;
8791: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 8792: if (ref($lastactref) eq 'HASH') {
8793: $lastactref->{'domdefaults'} = 1;
8794: }
1.1 raeburn 8795: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 8796: unless (($context eq 'requestcourses') ||
8797: ($context eq 'requestauthor')) {
1.86 raeburn 8798: if (ref($changes{'defaultquota'}) eq 'HASH') {
8799: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8800: foreach my $type (@{$types},'default') {
8801: if (defined($changes{'defaultquota'}{$type})) {
8802: my $typetitle = $usertypes->{$type};
8803: if ($type eq 'default') {
8804: $typetitle = $othertitle;
8805: }
1.160.6.28 raeburn 8806: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8807: }
8808: }
1.86 raeburn 8809: $resulttext .= '</ul></li>';
1.72 raeburn 8810: }
1.160.6.20 raeburn 8811: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 8812: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 8813: foreach my $type (@{$types},'default') {
8814: if (defined($changes{'authorquota'}{$type})) {
8815: my $typetitle = $usertypes->{$type};
8816: if ($type eq 'default') {
8817: $typetitle = $othertitle;
8818: }
1.160.6.28 raeburn 8819: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 8820: }
8821: }
8822: $resulttext .= '</ul></li>';
8823: }
1.72 raeburn 8824: }
1.80 raeburn 8825: my %newenv;
1.72 raeburn 8826: foreach my $item (@usertools) {
1.160.6.5 raeburn 8827: my (%haschgs,%inconf);
8828: if ($context eq 'requestauthor') {
8829: %haschgs = %changes;
8830: %inconf = %confhash;
8831: } else {
8832: if (ref($changes{$item}) eq 'HASH') {
8833: %haschgs = %{$changes{$item}};
8834: }
8835: if (ref($confhash{$item}) eq 'HASH') {
8836: %inconf = %{$confhash{$item}};
8837: }
8838: }
8839: if (keys(%haschgs) > 0) {
1.80 raeburn 8840: my $newacc =
8841: &Apache::lonnet::usertools_access($env{'user.name'},
8842: $env{'user.domain'},
1.86 raeburn 8843: $item,'reload',$context);
1.160.6.5 raeburn 8844: if (($context eq 'requestcourses') ||
8845: ($context eq 'requestauthor')) {
1.108 raeburn 8846: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8847: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8848: }
8849: } else {
8850: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8851: $newenv{'environment.availabletools.'.$item} = $newacc;
8852: }
1.80 raeburn 8853: }
1.160.6.5 raeburn 8854: unless ($context eq 'requestauthor') {
8855: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8856: }
1.72 raeburn 8857: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 8858: if ($haschgs{$type}) {
1.72 raeburn 8859: my $typetitle = $usertypes->{$type};
8860: if ($type eq 'default') {
8861: $typetitle = $othertitle;
8862: } elsif ($type eq '_LC_adv') {
8863: $typetitle = 'LON-CAPA Advanced Users';
8864: }
1.160.6.5 raeburn 8865: if ($inconf{$type}) {
1.101 raeburn 8866: if ($context eq 'requestcourses') {
8867: my $cond;
1.160.6.5 raeburn 8868: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8869: if ($1 eq '') {
8870: $cond = &mt('(Automatic processing of any request).');
8871: } else {
8872: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8873: }
8874: } else {
1.160.6.5 raeburn 8875: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8876: }
8877: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 8878: } elsif ($context eq 'requestauthor') {
8879: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8880: $titles{$inconf{$type}},$typetitle);
8881:
1.101 raeburn 8882: } else {
8883: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8884: }
1.72 raeburn 8885: } else {
1.104 raeburn 8886: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 8887: if ($inconf{$type} eq '0') {
1.104 raeburn 8888: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8889: } else {
8890: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8891: }
8892: } else {
8893: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8894: }
1.72 raeburn 8895: }
8896: }
1.26 raeburn 8897: }
1.160.6.5 raeburn 8898: unless ($context eq 'requestauthor') {
8899: $resulttext .= '</ul></li>';
8900: }
1.26 raeburn 8901: }
1.1 raeburn 8902: }
1.160.6.5 raeburn 8903: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8904: if (ref($changes{'notify'}) eq 'HASH') {
8905: if ($changes{'notify'}{'approval'}) {
8906: if (ref($confhash{'notify'}) eq 'HASH') {
8907: if ($confhash{'notify'}{'approval'}) {
8908: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8909: } else {
1.160.6.5 raeburn 8910: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8911: }
8912: }
8913: }
8914: }
8915: }
1.160.6.30 raeburn 8916: if ($action eq 'requestcourses') {
8917: my @offon = ('off','on');
8918: if ($changes{'uniquecode'}) {
8919: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8920: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8921: $resulttext .= '<li>'.
8922: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8923: '</li>';
8924: } else {
8925: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8926: '</li>';
8927: }
8928: }
1.160.6.46 raeburn 8929: foreach my $type ('textbooks','templates') {
8930: if (ref($changes{$type}) eq 'HASH') {
8931: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8932: foreach my $key (sort(keys(%{$changes{$type}}))) {
8933: my %coursehash = &Apache::lonnet::coursedescription($key);
8934: my $coursetitle = $coursehash{'description'};
8935: my $position = $confhash{$type}{$key}{'order'} + 1;
8936: $resulttext .= '<li>';
1.160.6.47 raeburn 8937: foreach my $item ('subject','title','publisher','author') {
8938: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8939: ($type eq 'templates'));
1.160.6.46 raeburn 8940: my $name = $item.':';
8941: $name =~ s/^(\w)/\U$1/;
8942: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8943: }
8944: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8945: if ($type eq 'textbooks') {
8946: if ($confhash{$type}{$key}{'image'}) {
8947: $resulttext .= ' '.&mt('Image: [_1]',
8948: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8949: ' alt="Textbook cover" />').'<br />';
8950: }
8951: }
8952: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 8953: }
1.160.6.46 raeburn 8954: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 8955: }
8956: }
1.160.6.39 raeburn 8957: if (ref($changes{'validation'}) eq 'HASH') {
8958: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8959: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8960: foreach my $item (@{$validationitemsref}) {
8961: if (exists($changes{'validation'}{$item})) {
8962: if ($item eq 'markup') {
8963: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8964: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8965: } else {
8966: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8967: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8968: }
8969: }
8970: }
8971: if (exists($changes{'validation'}{'dc'})) {
8972: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8973: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8974: }
8975: }
8976: }
1.160.6.30 raeburn 8977: }
1.1 raeburn 8978: $resulttext .= '</ul>';
1.80 raeburn 8979: if (keys(%newenv)) {
8980: &Apache::lonnet::appenv(\%newenv);
8981: }
1.1 raeburn 8982: } else {
1.86 raeburn 8983: if ($context eq 'requestcourses') {
8984: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 8985: } elsif ($context eq 'requestauthor') {
8986: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8987: } else {
1.90 weissno 8988: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8989: }
1.1 raeburn 8990: }
8991: } else {
1.11 albertel 8992: $resulttext = '<span class="LC_error">'.
8993: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8994: }
1.160.6.30 raeburn 8995: if ($errors) {
8996: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8997: '<ul>'.$errors.'</ul></p>';
8998: }
1.3 raeburn 8999: return $resulttext;
1.1 raeburn 9000: }
9001:
1.160.6.30 raeburn 9002: sub process_textbook_image {
1.160.6.46 raeburn 9003: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 9004: my $filename = $env{'form.'.$caller.'.filename'};
9005: my ($error,$url);
9006: my ($width,$height) = (50,50);
9007: if ($configuserok eq 'ok') {
9008: if ($switchserver) {
9009: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
9010: $switchserver);
9011: } elsif ($author_ok eq 'ok') {
9012: my ($result,$imageurl) =
9013: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 9014: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 9015: if ($result eq 'ok') {
9016: $url = $imageurl;
9017: } else {
9018: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
9019: }
9020: } else {
9021: $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);
9022: }
9023: } else {
9024: $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);
9025: }
9026: return ($url,$error);
9027: }
9028:
1.3 raeburn 9029: sub modify_autoenroll {
1.160.6.24 raeburn 9030: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 9031: my ($resulttext,%changes);
9032: my %currautoenroll;
9033: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
9034: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
9035: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
9036: }
9037: }
9038: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
9039: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 9040: sender => 'Sender for notification messages',
1.160.6.68 raeburn 9041: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
9042: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 9043: my @offon = ('off','on');
1.17 raeburn 9044: my $sender_uname = $env{'form.sender_uname'};
9045: my $sender_domain = $env{'form.sender_domain'};
9046: if ($sender_domain eq '') {
9047: $sender_uname = '';
9048: } elsif ($sender_uname eq '') {
9049: $sender_domain = '';
9050: }
1.129 raeburn 9051: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 9052: my $failsafe = $env{'form.autoenroll_failsafe'};
9053: $failsafe =~ s{^\s+|\s+$}{}g;
9054: if ($failsafe =~ /\D/) {
9055: undef($failsafe);
9056: }
1.1 raeburn 9057: my %autoenrollhash = (
1.129 raeburn 9058: autoenroll => { 'run' => $env{'form.autoenroll_run'},
9059: 'sender_uname' => $sender_uname,
9060: 'sender_domain' => $sender_domain,
9061: 'co-owners' => $coowners,
1.160.6.68 raeburn 9062: 'autofailsafe' => $failsafe,
1.1 raeburn 9063: }
9064: );
1.4 raeburn 9065: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
9066: $dom);
1.1 raeburn 9067: if ($putresult eq 'ok') {
9068: if (exists($currautoenroll{'run'})) {
9069: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
9070: $changes{'run'} = 1;
9071: }
9072: } elsif ($autorun) {
9073: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 9074: $changes{'run'} = 1;
1.1 raeburn 9075: }
9076: }
1.17 raeburn 9077: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 9078: $changes{'sender'} = 1;
9079: }
1.17 raeburn 9080: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 9081: $changes{'sender'} = 1;
9082: }
1.129 raeburn 9083: if ($currautoenroll{'co-owners'} ne '') {
9084: if ($currautoenroll{'co-owners'} ne $coowners) {
9085: $changes{'coowners'} = 1;
9086: }
9087: } elsif ($coowners) {
9088: $changes{'coowners'} = 1;
1.160.6.68 raeburn 9089: }
9090: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
9091: $changes{'autofailsafe'} = 1;
9092: }
1.1 raeburn 9093: if (keys(%changes) > 0) {
9094: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 9095: if ($changes{'run'}) {
1.1 raeburn 9096: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
9097: }
9098: if ($changes{'sender'}) {
1.17 raeburn 9099: if ($sender_uname eq '' || $sender_domain eq '') {
9100: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
9101: } else {
9102: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
9103: }
1.1 raeburn 9104: }
1.129 raeburn 9105: if ($changes{'coowners'}) {
9106: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
9107: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9108: if (ref($lastactref) eq 'HASH') {
9109: $lastactref->{'domainconfig'} = 1;
9110: }
1.129 raeburn 9111: }
1.160.6.68 raeburn 9112: if ($changes{'autofailsafe'}) {
9113: if ($failsafe ne '') {
1.160.6.82 raeburn 9114: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 9115: } else {
1.160.6.82 raeburn 9116: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 9117: }
9118: &Apache::lonnet::get_domain_defaults($dom,1);
9119: if (ref($lastactref) eq 'HASH') {
9120: $lastactref->{'domdefaults'} = 1;
9121: }
9122: }
1.1 raeburn 9123: $resulttext .= '</ul>';
9124: } else {
9125: $resulttext = &mt('No changes made to auto-enrollment settings');
9126: }
9127: } else {
1.11 albertel 9128: $resulttext = '<span class="LC_error">'.
9129: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9130: }
1.3 raeburn 9131: return $resulttext;
1.1 raeburn 9132: }
9133:
9134: sub modify_autoupdate {
1.3 raeburn 9135: my ($dom,%domconfig) = @_;
1.1 raeburn 9136: my ($resulttext,%currautoupdate,%fields,%changes);
9137: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
9138: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
9139: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
9140: }
9141: }
9142: my @offon = ('off','on');
9143: my %title = &Apache::lonlocal::texthash (
9144: run => 'Auto-update:',
9145: classlists => 'Updates to user information in classlists?'
9146: );
1.44 raeburn 9147: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 9148: my %fieldtitles = &Apache::lonlocal::texthash (
9149: id => 'Student/Employee ID',
1.20 raeburn 9150: permanentemail => 'E-mail address',
1.1 raeburn 9151: lastname => 'Last Name',
9152: firstname => 'First Name',
9153: middlename => 'Middle Name',
1.132 raeburn 9154: generation => 'Generation',
1.1 raeburn 9155: );
1.142 raeburn 9156: $othertitle = &mt('All users');
1.1 raeburn 9157: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 9158: $othertitle = &mt('Other users');
1.1 raeburn 9159: }
9160: foreach my $key (keys(%env)) {
9161: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 9162: my ($usertype,$item) = ($1,$2);
9163: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
9164: if ($usertype eq 'default') {
9165: push(@{$fields{$1}},$2);
9166: } elsif (ref($types) eq 'ARRAY') {
9167: if (grep(/^\Q$usertype\E$/,@{$types})) {
9168: push(@{$fields{$1}},$2);
9169: }
9170: }
9171: }
1.1 raeburn 9172: }
9173: }
1.131 raeburn 9174: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
9175: @lockablenames = sort(@lockablenames);
9176: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
9177: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9178: if (@changed) {
9179: $changes{'lockablenames'} = 1;
9180: }
9181: } else {
9182: if (@lockablenames) {
9183: $changes{'lockablenames'} = 1;
9184: }
9185: }
1.1 raeburn 9186: my %updatehash = (
9187: autoupdate => { run => $env{'form.autoupdate_run'},
9188: classlists => $env{'form.classlists'},
9189: fields => {%fields},
1.131 raeburn 9190: lockablenames => \@lockablenames,
1.1 raeburn 9191: }
9192: );
9193: foreach my $key (keys(%currautoupdate)) {
9194: if (($key eq 'run') || ($key eq 'classlists')) {
9195: if (exists($updatehash{autoupdate}{$key})) {
9196: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
9197: $changes{$key} = 1;
9198: }
9199: }
9200: } elsif ($key eq 'fields') {
9201: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 9202: foreach my $item (@{$types},'default') {
1.1 raeburn 9203: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
9204: my $change = 0;
9205: foreach my $type (@{$currautoupdate{$key}{$item}}) {
9206: if (!exists($fields{$item})) {
9207: $change = 1;
1.132 raeburn 9208: last;
1.1 raeburn 9209: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 9210: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 9211: $change = 1;
1.132 raeburn 9212: last;
1.1 raeburn 9213: }
9214: }
9215: }
9216: if ($change) {
9217: push(@{$changes{$key}},$item);
9218: }
1.26 raeburn 9219: }
1.1 raeburn 9220: }
9221: }
1.131 raeburn 9222: } elsif ($key eq 'lockablenames') {
9223: if (ref($currautoupdate{$key}) eq 'ARRAY') {
9224: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
9225: if (@changed) {
9226: $changes{'lockablenames'} = 1;
9227: }
9228: } else {
9229: if (@lockablenames) {
9230: $changes{'lockablenames'} = 1;
9231: }
9232: }
9233: }
9234: }
9235: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
9236: if (@lockablenames) {
9237: $changes{'lockablenames'} = 1;
1.1 raeburn 9238: }
9239: }
1.26 raeburn 9240: foreach my $item (@{$types},'default') {
9241: if (defined($fields{$item})) {
9242: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 9243: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
9244: my $change = 0;
9245: if (ref($fields{$item}) eq 'ARRAY') {
9246: foreach my $type (@{$fields{$item}}) {
9247: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
9248: $change = 1;
9249: last;
9250: }
9251: }
9252: }
9253: if ($change) {
9254: push(@{$changes{'fields'}},$item);
9255: }
9256: } else {
1.26 raeburn 9257: push(@{$changes{'fields'}},$item);
9258: }
9259: } else {
9260: push(@{$changes{'fields'}},$item);
1.1 raeburn 9261: }
9262: }
9263: }
9264: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
9265: $dom);
9266: if ($putresult eq 'ok') {
9267: if (keys(%changes) > 0) {
9268: $resulttext = &mt('Changes made:').'<ul>';
9269: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 9270: if ($key eq 'lockablenames') {
9271: $resulttext .= '<li>';
9272: if (@lockablenames) {
9273: $usertypes->{'default'} = $othertitle;
9274: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
9275: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
9276: } else {
9277: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
9278: }
9279: $resulttext .= '</li>';
9280: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 9281: foreach my $item (@{$changes{$key}}) {
9282: my @newvalues;
9283: foreach my $type (@{$fields{$item}}) {
9284: push(@newvalues,$fieldtitles{$type});
9285: }
1.3 raeburn 9286: my $newvaluestr;
9287: if (@newvalues > 0) {
9288: $newvaluestr = join(', ',@newvalues);
9289: } else {
9290: $newvaluestr = &mt('none');
1.6 raeburn 9291: }
1.1 raeburn 9292: if ($item eq 'default') {
1.26 raeburn 9293: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 9294: } else {
1.26 raeburn 9295: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9296: }
9297: }
9298: } else {
9299: my $newvalue;
9300: if ($key eq 'run') {
9301: $newvalue = $offon[$env{'form.autoupdate_run'}];
9302: } else {
9303: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9304: }
1.1 raeburn 9305: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9306: }
9307: }
9308: $resulttext .= '</ul>';
9309: } else {
1.3 raeburn 9310: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9311: }
9312: } else {
1.11 albertel 9313: $resulttext = '<span class="LC_error">'.
9314: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9315: }
1.3 raeburn 9316: return $resulttext;
1.1 raeburn 9317: }
9318:
1.125 raeburn 9319: sub modify_autocreate {
9320: my ($dom,%domconfig) = @_;
9321: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9322: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9323: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9324: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9325: }
9326: }
9327: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9328: req => 'Auto-creation of validated requests for official courses',
9329: xmldc => 'Identity of course creator of courses from XML files',
9330: );
9331: my @types = ('xml','req');
9332: foreach my $item (@types) {
9333: $newvals{$item} = $env{'form.autocreate_'.$item};
9334: $newvals{$item} =~ s/\D//g;
9335: $newvals{$item} = 0 if ($newvals{$item} eq '');
9336: }
9337: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 9338: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 9339: unless (exists($domcoords{$newvals{'xmldc'}})) {
9340: $newvals{'xmldc'} = '';
9341: }
9342: %autocreatehash = (
9343: autocreate => { xml => $newvals{'xml'},
9344: req => $newvals{'req'},
9345: }
9346: );
9347: if ($newvals{'xmldc'} ne '') {
9348: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9349: }
9350: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9351: $dom);
9352: if ($putresult eq 'ok') {
9353: my @items = @types;
9354: if ($newvals{'xml'}) {
9355: push(@items,'xmldc');
9356: }
9357: foreach my $item (@items) {
9358: if (exists($currautocreate{$item})) {
9359: if ($currautocreate{$item} ne $newvals{$item}) {
9360: $changes{$item} = 1;
9361: }
9362: } elsif ($newvals{$item}) {
9363: $changes{$item} = 1;
9364: }
9365: }
9366: if (keys(%changes) > 0) {
9367: my @offon = ('off','on');
9368: $resulttext = &mt('Changes made:').'<ul>';
9369: foreach my $item (@types) {
9370: if ($changes{$item}) {
9371: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 9372: $resulttext .= '<li>'.
9373: &mt("$title{$item} set to [_1]$newtxt [_2]",
9374: '<b>','</b>').
9375: '</li>';
1.125 raeburn 9376: }
9377: }
9378: if ($changes{'xmldc'}) {
9379: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9380: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 9381: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9382: }
9383: $resulttext .= '</ul>';
9384: } else {
9385: $resulttext = &mt('No changes made to auto-creation settings');
9386: }
9387: } else {
9388: $resulttext = '<span class="LC_error">'.
9389: &mt('An error occurred: [_1]',$putresult).'</span>';
9390: }
9391: return $resulttext;
9392: }
9393:
1.23 raeburn 9394: sub modify_directorysrch {
1.160.6.81 raeburn 9395: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 9396: my ($resulttext,%changes);
9397: my %currdirsrch;
9398: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9399: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9400: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9401: }
9402: }
1.160.6.72 raeburn 9403: my %title = ( available => 'Institutional directory search available',
9404: localonly => 'Other domains can search institution',
9405: lcavailable => 'LON-CAPA directory search available',
9406: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9407: searchby => 'Search types',
9408: searchtypes => 'Search latitude');
9409: my @offon = ('off','on');
1.24 raeburn 9410: my @otherdoms = ('Yes','No');
1.23 raeburn 9411:
1.25 raeburn 9412: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9413: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9414: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9415:
1.44 raeburn 9416: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9417: if (keys(%{$usertypes}) == 0) {
9418: @cansearch = ('default');
9419: } else {
9420: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9421: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9422: if (!grep(/^\Q$type\E$/,@cansearch)) {
9423: push(@{$changes{'cansearch'}},$type);
9424: }
1.23 raeburn 9425: }
1.26 raeburn 9426: foreach my $type (@cansearch) {
9427: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9428: push(@{$changes{'cansearch'}},$type);
9429: }
1.23 raeburn 9430: }
1.26 raeburn 9431: } else {
9432: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9433: }
9434: }
9435:
9436: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9437: foreach my $by (@{$currdirsrch{'searchby'}}) {
9438: if (!grep(/^\Q$by\E$/,@searchby)) {
9439: push(@{$changes{'searchby'}},$by);
9440: }
9441: }
9442: foreach my $by (@searchby) {
9443: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9444: push(@{$changes{'searchby'}},$by);
9445: }
9446: }
9447: } else {
9448: push(@{$changes{'searchby'}},@searchby);
9449: }
1.25 raeburn 9450:
9451: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9452: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9453: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9454: push(@{$changes{'searchtypes'}},$type);
9455: }
9456: }
9457: foreach my $type (@searchtypes) {
9458: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9459: push(@{$changes{'searchtypes'}},$type);
9460: }
9461: }
9462: } else {
9463: if (exists($currdirsrch{'searchtypes'})) {
9464: foreach my $type (@searchtypes) {
9465: if ($type ne $currdirsrch{'searchtypes'}) {
9466: push(@{$changes{'searchtypes'}},$type);
9467: }
9468: }
9469: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9470: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9471: }
9472: } else {
9473: push(@{$changes{'searchtypes'}},@searchtypes);
9474: }
9475: }
9476:
1.23 raeburn 9477: my %dirsrch_hash = (
9478: directorysrch => { available => $env{'form.dirsrch_available'},
9479: cansearch => \@cansearch,
1.160.6.72 raeburn 9480: localonly => $env{'form.dirsrch_instlocalonly'},
9481: lclocalonly => $env{'form.dirsrch_domlocalonly'},
9482: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9483: searchby => \@searchby,
1.25 raeburn 9484: searchtypes => \@searchtypes,
1.23 raeburn 9485: }
9486: );
9487: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9488: $dom);
9489: if ($putresult eq 'ok') {
9490: if (exists($currdirsrch{'available'})) {
9491: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9492: $changes{'available'} = 1;
9493: }
9494: } else {
9495: if ($env{'form.dirsrch_available'} eq '1') {
9496: $changes{'available'} = 1;
9497: }
9498: }
1.160.6.72 raeburn 9499: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 9500: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
9501: $changes{'lcavailable'} = 1;
9502: }
1.24 raeburn 9503: } else {
1.160.6.72 raeburn 9504: if ($env{'form.dirsrch_lcavailable'} eq '1') {
9505: $changes{'lcavailable'} = 1;
9506: }
9507: }
9508: if (exists($currdirsrch{'localonly'})) {
9509: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9510: $changes{'localonly'} = 1;
9511: }
1.160.6.72 raeburn 9512: } else {
9513: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
9514: $changes{'localonly'} = 1;
9515: }
9516: }
9517: if (exists($currdirsrch{'lclocalonly'})) {
9518: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
9519: $changes{'lclocalonly'} = 1;
9520: }
9521: } else {
9522: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
9523: $changes{'lclocalonly'} = 1;
9524: }
1.24 raeburn 9525: }
1.23 raeburn 9526: if (keys(%changes) > 0) {
9527: $resulttext = &mt('Changes made:').'<ul>';
9528: if ($changes{'available'}) {
9529: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9530: }
1.160.6.72 raeburn 9531: if ($changes{'lcavailable'}) {
9532: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
9533: }
1.24 raeburn 9534: if ($changes{'localonly'}) {
1.160.6.72 raeburn 9535: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
9536: }
9537: if ($changes{'lclocalonly'}) {
9538: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 9539: }
1.23 raeburn 9540: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9541: my $chgtext;
1.26 raeburn 9542: if (ref($usertypes) eq 'HASH') {
9543: if (keys(%{$usertypes}) > 0) {
9544: foreach my $type (@{$types}) {
9545: if (grep(/^\Q$type\E$/,@cansearch)) {
9546: $chgtext .= $usertypes->{$type}.'; ';
9547: }
9548: }
9549: if (grep(/^default$/,@cansearch)) {
9550: $chgtext .= $othertitle;
9551: } else {
9552: $chgtext =~ s/\; $//;
9553: }
1.160.6.13 raeburn 9554: $resulttext .=
9555: '<li>'.
9556: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9557: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9558: '</li>';
1.23 raeburn 9559: }
9560: }
9561: }
9562: if (ref($changes{'searchby'}) eq 'ARRAY') {
9563: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9564: my $chgtext;
9565: foreach my $type (@{$titleorder}) {
9566: if (grep(/^\Q$type\E$/,@searchby)) {
9567: if (defined($searchtitles->{$type})) {
9568: $chgtext .= $searchtitles->{$type}.'; ';
9569: }
9570: }
9571: }
9572: $chgtext =~ s/\; $//;
9573: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9574: }
1.25 raeburn 9575: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9576: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9577: my $chgtext;
9578: foreach my $type (@{$srchtypeorder}) {
9579: if (grep(/^\Q$type\E$/,@searchtypes)) {
9580: if (defined($srchtypes_desc->{$type})) {
9581: $chgtext .= $srchtypes_desc->{$type}.'; ';
9582: }
9583: }
9584: }
9585: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 9586: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9587: }
9588: $resulttext .= '</ul>';
1.160.6.81 raeburn 9589: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
9590: if (ref($lastactref) eq 'HASH') {
9591: $lastactref->{'directorysrch'} = 1;
9592: }
1.23 raeburn 9593: } else {
1.160.6.72 raeburn 9594: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9595: }
9596: } else {
9597: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9598: &mt('An error occurred: [_1]',$putresult).'</span>';
9599: }
9600: return $resulttext;
9601: }
9602:
1.28 raeburn 9603: sub modify_contacts {
1.160.6.24 raeburn 9604: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9605: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9606: if (ref($domconfig{'contacts'}) eq 'HASH') {
9607: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9608: $currsetting{$key} = $domconfig{'contacts'}{$key};
9609: }
9610: }
1.160.6.78 raeburn 9611: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 9612: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 9613: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
9614: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.160.6.23 raeburn 9615: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 9616: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 9617: foreach my $type (@mailings) {
9618: @{$newsetting{$type}} =
9619: &Apache::loncommon::get_env_multiple('form.'.$type);
9620: foreach my $item (@contacts) {
9621: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9622: $contacts_hash{contacts}{$type}{$item} = 1;
9623: } else {
9624: $contacts_hash{contacts}{$type}{$item} = 0;
9625: }
1.160.6.78 raeburn 9626: }
1.28 raeburn 9627: $others{$type} = $env{'form.'.$type.'_others'};
9628: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 9629: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9630: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9631: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 9632: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
9633: $includestr{$type} = $env{'form.'.$type.'_includestr'};
9634: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
9635: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
9636: }
1.134 raeburn 9637: }
1.28 raeburn 9638: }
9639: foreach my $item (@contacts) {
9640: $to{$item} = $env{'form.'.$item};
9641: $contacts_hash{'contacts'}{$item} = $to{$item};
9642: }
1.160.6.23 raeburn 9643: foreach my $item (@toggles) {
9644: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9645: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9646: }
9647: }
1.160.6.78 raeburn 9648: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
9649: foreach my $field (@{$fields}) {
9650: if (ref($possoptions->{$field}) eq 'ARRAY') {
9651: my $value = $env{'form.helpform_'.$field};
9652: $value =~ s/^\s+|\s+$//g;
9653: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
9654: $contacts_hash{contacts}{'helpform'}{$field} = $value;
9655: if ($field eq 'screenshot') {
9656: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
9657: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
9658: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
9659: }
9660: }
9661: }
9662: }
9663: }
9664: }
1.28 raeburn 9665: if (keys(%currsetting) > 0) {
9666: foreach my $item (@contacts) {
9667: if ($to{$item} ne $currsetting{$item}) {
9668: $changes{$item} = 1;
9669: }
9670: }
9671: foreach my $type (@mailings) {
9672: foreach my $item (@contacts) {
9673: if (ref($currsetting{$type}) eq 'HASH') {
9674: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9675: push(@{$changes{$type}},$item);
9676: }
9677: } else {
9678: push(@{$changes{$type}},@{$newsetting{$type}});
9679: }
9680: }
9681: if ($others{$type} ne $currsetting{$type}{'others'}) {
9682: push(@{$changes{$type}},'others');
9683: }
1.160.6.78 raeburn 9684: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9685: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9686: push(@{$changes{$type}},'bcc');
9687: }
1.160.6.78 raeburn 9688: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
9689: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
9690: push(@{$changes{$type}},'include');
9691: }
9692: }
9693: }
9694: if (ref($fields) eq 'ARRAY') {
9695: if (ref($currsetting{'helpform'}) eq 'HASH') {
9696: foreach my $field (@{$fields}) {
9697: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
9698: push(@{$changes{'helpform'}},$field);
9699: }
9700: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9701: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
9702: push(@{$changes{'helpform'}},'maxsize');
9703: }
9704: }
9705: }
9706: } else {
9707: foreach my $field (@{$fields}) {
9708: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9709: push(@{$changes{'helpform'}},$field);
9710: }
9711: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9712: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9713: push(@{$changes{'helpform'}},'maxsize');
9714: }
9715: }
9716: }
1.134 raeburn 9717: }
1.28 raeburn 9718: }
9719: } else {
9720: my %default;
9721: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9722: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9723: $default{'errormail'} = 'adminemail';
9724: $default{'packagesmail'} = 'adminemail';
9725: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 9726: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 9727: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9728: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 9729: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9730: foreach my $item (@contacts) {
9731: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 9732: $changes{$item} = 1;
1.160.6.23 raeburn 9733: }
1.28 raeburn 9734: }
9735: foreach my $type (@mailings) {
9736: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9737: push(@{$changes{$type}},@{$newsetting{$type}});
9738: }
9739: if ($others{$type} ne '') {
9740: push(@{$changes{$type}},'others');
1.134 raeburn 9741: }
1.160.6.78 raeburn 9742: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9743: if ($bcc{$type} ne '') {
9744: push(@{$changes{$type}},'bcc');
9745: }
1.160.6.78 raeburn 9746: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
9747: push(@{$changes{$type}},'include');
9748: }
9749: }
9750: }
9751: if (ref($fields) eq 'ARRAY') {
9752: foreach my $field (@{$fields}) {
9753: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9754: push(@{$changes{'helpform'}},$field);
9755: }
9756: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9757: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9758: push(@{$changes{'helpform'}},'maxsize');
9759: }
9760: }
1.134 raeburn 9761: }
1.28 raeburn 9762: }
9763: }
1.160.6.23 raeburn 9764: foreach my $item (@toggles) {
9765: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9766: $changes{$item} = 1;
9767: } elsif ((!$env{'form.'.$item}) &&
9768: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9769: $changes{$item} = 1;
9770: }
9771: }
1.28 raeburn 9772: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9773: $dom);
9774: if ($putresult eq 'ok') {
9775: if (keys(%changes) > 0) {
1.160.6.24 raeburn 9776: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9777: if (ref($lastactref) eq 'HASH') {
9778: $lastactref->{'domainconfig'} = 1;
9779: }
1.28 raeburn 9780: my ($titles,$short_titles) = &contact_titles();
9781: $resulttext = &mt('Changes made:').'<ul>';
9782: foreach my $item (@contacts) {
9783: if ($changes{$item}) {
9784: $resulttext .= '<li>'.$titles->{$item}.
9785: &mt(' set to: ').
9786: '<span class="LC_cusr_emph">'.
9787: $to{$item}.'</span></li>';
9788: }
9789: }
9790: foreach my $type (@mailings) {
9791: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 9792: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
9793: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
9794: } else {
9795: $resulttext .= '<li>'.$titles->{$type}.': ';
9796: }
1.28 raeburn 9797: my @text;
9798: foreach my $item (@{$newsetting{$type}}) {
9799: push(@text,$short_titles->{$item});
9800: }
9801: if ($others{$type} ne '') {
9802: push(@text,$others{$type});
9803: }
1.160.6.78 raeburn 9804: if (@text) {
9805: $resulttext .= '<span class="LC_cusr_emph">'.
9806: join(', ',@text).'</span>';
9807: }
9808: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9809: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 9810: my $bcctext;
9811: if (@text) {
9812: $bcctext = ' '.&mt('with Bcc to');
9813: } else {
9814: $bcctext = '(Bcc)';
9815: }
9816: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9817: } elsif (!@text) {
9818: $resulttext .= &mt('No one');
1.134 raeburn 9819: }
1.160.6.78 raeburn 9820: if ($includestr{$type} ne '') {
9821: if ($includeloc{$type} eq 'b') {
9822: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
9823: } elsif ($includeloc{$type} eq 's') {
9824: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
9825: }
9826: }
9827: } elsif (!@text) {
9828: $resulttext .= &mt('No recipients');
1.134 raeburn 9829: }
9830: $resulttext .= '</li>';
1.28 raeburn 9831: }
9832: }
1.160.6.23 raeburn 9833: my @offon = ('off','on');
9834: if ($changes{'reporterrors'}) {
9835: $resulttext .= '<li>'.
9836: &mt('E-mail error reports to [_1] set to "'.
9837: $offon[$env{'form.reporterrors'}].'".',
9838: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9839: &mt('LON-CAPA core group - MSU'),600,500)).
9840: '</li>';
9841: }
9842: if ($changes{'reportupdates'}) {
9843: $resulttext .= '<li>'.
9844: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9845: $offon[$env{'form.reportupdates'}].'".',
9846: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9847: &mt('LON-CAPA core group - MSU'),600,500)).
9848: '</li>';
9849: }
1.160.6.78 raeburn 9850: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
9851: my (@optional,@required,@unused,$maxsizechg);
9852: foreach my $field (@{$changes{'helpform'}}) {
9853: if ($field eq 'maxsize') {
9854: $maxsizechg = 1;
9855: next;
9856: }
9857: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
9858: push(@optional,$field);
9859: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
9860: push(@unused,$field);
9861: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
9862: push(@required,$field);
9863: }
9864: }
9865: if (@optional) {
9866: $resulttext .= '<li>'.
9867: &mt('Help form fields changed to "Optional": [_1].',
9868: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
9869: '</li>';
9870: }
9871: if (@required) {
9872: $resulttext .= '<li>'.
9873: &mt('Help form fields changed to "Required": [_1].',
9874: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
9875: '</li>';
9876: }
9877: if (@unused) {
9878: $resulttext .= '<li>'.
9879: &mt('Help form fields changed to "Not shown": [_1].',
9880: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
9881: '</li>';
9882: }
9883: if ($maxsizechg) {
9884: $resulttext .= '<li>'.
9885: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
9886: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
9887: '</li>';
9888:
9889: }
9890: }
1.28 raeburn 9891: $resulttext .= '</ul>';
9892: } else {
1.160.6.78 raeburn 9893: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 9894: }
9895: } else {
9896: $resulttext = '<span class="LC_error">'.
9897: &mt('An error occurred: [_1].',$putresult).'</span>';
9898: }
9899: return $resulttext;
9900: }
9901:
9902: sub modify_usercreation {
1.27 raeburn 9903: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9904: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9905: my $warningmsg;
1.27 raeburn 9906: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9907: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 9908: if ($key eq 'cancreate') {
9909: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9910: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.84.4. (raeburn 9911:): if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 9912: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.84.4. (raeburn 9913:): } else {
9914:): $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 9915: }
1.50 raeburn 9916: }
1.43 raeburn 9917: }
1.160.6.34 raeburn 9918: } elsif ($key eq 'email_rule') {
9919: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9920: } else {
9921: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 9922: }
9923: }
1.34 raeburn 9924: }
1.160.6.34 raeburn 9925: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
9926: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
9927: my @contexts = ('author','course','requestcrs');
9928: foreach my $item(@contexts) {
9929: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9930: }
1.34 raeburn 9931: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9932: foreach my $item (@contexts) {
1.160.6.34 raeburn 9933: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9934: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9935: }
1.27 raeburn 9936: }
1.34 raeburn 9937: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9938: foreach my $item (@contexts) {
1.43 raeburn 9939: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9940: if ($cancreate{$item} ne 'any') {
9941: push(@{$changes{'cancreate'}},$item);
9942: }
9943: } else {
9944: if ($cancreate{$item} ne 'none') {
9945: push(@{$changes{'cancreate'}},$item);
9946: }
1.27 raeburn 9947: }
9948: }
9949: } else {
1.43 raeburn 9950: foreach my $item (@contexts) {
1.34 raeburn 9951: push(@{$changes{'cancreate'}},$item);
9952: }
1.27 raeburn 9953: }
1.34 raeburn 9954:
1.27 raeburn 9955: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9956: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9957: if (!grep(/^\Q$type\E$/,@username_rule)) {
9958: push(@{$changes{'username_rule'}},$type);
9959: }
9960: }
9961: foreach my $type (@username_rule) {
9962: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9963: push(@{$changes{'username_rule'}},$type);
9964: }
9965: }
9966: } else {
9967: push(@{$changes{'username_rule'}},@username_rule);
9968: }
9969:
1.32 raeburn 9970: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9971: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9972: if (!grep(/^\Q$type\E$/,@id_rule)) {
9973: push(@{$changes{'id_rule'}},$type);
9974: }
9975: }
9976: foreach my $type (@id_rule) {
9977: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9978: push(@{$changes{'id_rule'}},$type);
9979: }
9980: }
9981: } else {
9982: push(@{$changes{'id_rule'}},@id_rule);
9983: }
9984:
1.43 raeburn 9985: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9986: my @authtypes = ('int','krb4','krb5','loc');
9987: my %authhash;
1.43 raeburn 9988: foreach my $item (@authen_contexts) {
1.28 raeburn 9989: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9990: foreach my $auth (@authtypes) {
9991: if (grep(/^\Q$auth\E$/,@authallowed)) {
9992: $authhash{$item}{$auth} = 1;
9993: } else {
9994: $authhash{$item}{$auth} = 0;
9995: }
9996: }
9997: }
9998: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9999: foreach my $item (@authen_contexts) {
1.28 raeburn 10000: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
10001: foreach my $auth (@authtypes) {
10002: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
10003: push(@{$changes{'authtypes'}},$item);
10004: last;
10005: }
10006: }
10007: }
10008: }
10009: } else {
1.43 raeburn 10010: foreach my $item (@authen_contexts) {
1.28 raeburn 10011: push(@{$changes{'authtypes'}},$item);
10012: }
10013: }
10014:
1.160.6.34 raeburn 10015: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
10016: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
10017: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
10018: $save_usercreate{'id_rule'} = \@id_rule;
10019: $save_usercreate{'username_rule'} = \@username_rule,
10020: $save_usercreate{'authtypes'} = \%authhash;
10021:
1.27 raeburn 10022: my %usercreation_hash = (
1.160.6.34 raeburn 10023: usercreation => \%save_usercreate,
10024: );
1.27 raeburn 10025:
10026: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
10027: $dom);
1.50 raeburn 10028:
1.160.6.34 raeburn 10029: if ($putresult eq 'ok') {
10030: if (keys(%changes) > 0) {
10031: $resulttext = &mt('Changes made:').'<ul>';
10032: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10033: my %lt = &usercreation_types();
10034: foreach my $type (@{$changes{'cancreate'}}) {
10035: my $chgtext = $lt{$type}.', ';
10036: if ($cancreate{$type} eq 'none') {
10037: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
10038: } elsif ($cancreate{$type} eq 'any') {
10039: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
10040: } elsif ($cancreate{$type} eq 'official') {
10041: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
10042: } elsif ($cancreate{$type} eq 'unofficial') {
10043: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
10044: }
10045: $resulttext .= '<li>'.$chgtext.'</li>';
10046: }
10047: }
10048: if (ref($changes{'username_rule'}) eq 'ARRAY') {
10049: my ($rules,$ruleorder) =
10050: &Apache::lonnet::inst_userrules($dom,'username');
10051: my $chgtext = '<ul>';
10052: foreach my $type (@username_rule) {
10053: if (ref($rules->{$type}) eq 'HASH') {
10054: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
10055: }
10056: }
10057: $chgtext .= '</ul>';
10058: if (@username_rule > 0) {
10059: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10060: } else {
10061: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
10062: }
10063: }
10064: if (ref($changes{'id_rule'}) eq 'ARRAY') {
10065: my ($idrules,$idruleorder) =
10066: &Apache::lonnet::inst_userrules($dom,'id');
10067: my $chgtext = '<ul>';
10068: foreach my $type (@id_rule) {
10069: if (ref($idrules->{$type}) eq 'HASH') {
10070: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
10071: }
10072: }
10073: $chgtext .= '</ul>';
10074: if (@id_rule > 0) {
10075: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
10076: } else {
10077: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
10078: }
10079: }
10080: my %authname = &authtype_names();
10081: my %context_title = &context_names();
10082: if (ref($changes{'authtypes'}) eq 'ARRAY') {
10083: my $chgtext = '<ul>';
10084: foreach my $type (@{$changes{'authtypes'}}) {
10085: my @allowed;
10086: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
10087: foreach my $auth (@authtypes) {
10088: if ($authhash{$type}{$auth}) {
10089: push(@allowed,$authname{$auth});
10090: }
10091: }
10092: if (@allowed > 0) {
10093: $chgtext .= join(', ',@allowed).'</li>';
10094: } else {
10095: $chgtext .= &mt('none').'</li>';
10096: }
10097: }
10098: $chgtext .= '</ul>';
10099: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
10100: $resulttext .= '</li>';
10101: }
10102: $resulttext .= '</ul>';
10103: } else {
10104: $resulttext = &mt('No changes made to user creation settings');
10105: }
10106: } else {
10107: $resulttext = '<span class="LC_error">'.
10108: &mt('An error occurred: [_1]',$putresult).'</span>';
10109: }
10110: if ($warningmsg ne '') {
10111: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10112: }
10113: return $resulttext;
10114: }
10115:
10116: sub modify_selfcreation {
1.160.6.84.4. (raeburn 10117:): my ($dom,$lastactref,%domconfig) = @_;
10118:): my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
10119:): my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
10120:): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10121:): my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
10122:): if (ref($typesref) eq 'ARRAY') {
10123:): @types = @{$typesref};
10124:): }
10125:): if (ref($usertypesref) eq 'HASH') {
10126:): %usertypes = %{$usertypesref};
1.160.6.35 raeburn 10127: }
1.160.6.84.4. (raeburn 10128:): $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 10129: #
10130: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
10131: #
10132: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10133: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
10134: if ($key eq 'cancreate') {
10135: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
10136: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
10137: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.84.4. (raeburn 10138:): ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
10139:): ($item eq 'recaptchaversion') || ($item eq 'notify') ||
10140:): ($item eq 'emailusername') || ($item eq 'shibenv') ||
10141:): ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
10142:): ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 10143: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10144: } else {
10145: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
10146: }
10147: }
10148: }
10149: } elsif ($key eq 'email_rule') {
10150: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
10151: } else {
10152: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
10153: }
10154: }
10155: }
10156: #
10157: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
10158: #
10159: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10160: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
10161: if ($key eq 'selfcreate') {
10162: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
10163: } else {
10164: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
10165: }
10166: }
10167: }
1.160.6.84.4. (raeburn 10168:): #
10169:): # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
10170:): #
10171:): if (ref($domconfig{'inststatus'}) eq 'HASH') {
10172:): foreach my $key (keys(%{$domconfig{'inststatus'}})) {
10173:): if ($key eq 'inststatusguest') {
10174:): $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
10175:): } else {
10176:): $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
10177:): }
10178:): }
10179:): }
1.160.6.34 raeburn 10180:
10181: my @contexts = ('selfcreate');
10182: @{$cancreate{'selfcreate'}} = ();
10183: %{$cancreate{'emailusername'}} = ();
1.160.6.84.4. (raeburn 10184:): if (@types) {
10185:): @{$cancreate{'statustocreate'}} = ();
10186:): }
1.160.6.40 raeburn 10187: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 10188: %{$cancreate{'shibenv'}} = ();
1.160.6.84.4. (raeburn 10189:): %{$cancreate{'emailverified'}} = ();
10190:): %{$cancreate{'emailoptions'}} = ();
10191:): %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 10192: my %selfcreatetypes = (
10193: sso => 'users authenticated by institutional single sign on',
10194: login => 'users authenticated by institutional log-in',
1.160.6.84.4. (raeburn 10195:): email => 'users verified by e-mail',
1.50 raeburn 10196: );
1.160.6.34 raeburn 10197: #
10198: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
10199: # is permitted.
10200: #
1.160.6.40 raeburn 10201:
1.160.6.84.4. (raeburn 10202:): my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 10203:
1.160.6.84.4. (raeburn 10204:): my (@statuses,%email_rule);
1.160.6.35 raeburn 10205: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 10206: if ($item eq 'email') {
1.160.6.40 raeburn 10207: if ($env{'form.cancreate_email'}) {
1.160.6.84.4. (raeburn 10208:): if (@types) {
10209:): my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
10210:): foreach my $status (@poss_statuses) {
10211:): if (grep(/^\Q$status\E$/,(@types,'default'))) {
10212:): push(@statuses,$status);
10213:): }
10214:): }
10215:): $save_inststatus{'inststatusguest'} = \@statuses;
10216:): } else {
10217:): push(@statuses,'default');
10218:): }
10219:): if (@statuses) {
10220:): my %curr_rule;
10221:): if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
10222:): foreach my $type (@statuses) {
10223:): $curr_rule{$type} = $curr_usercreation{'email_rule'};
10224:): }
10225:): } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
10226:): foreach my $type (@statuses) {
10227:): $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
10228:): }
10229:): }
10230:): push(@{$cancreate{'selfcreate'}},'email');
10231:): push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
10232:): my %curremaildom;
10233:): if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
10234:): %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
10235:): }
10236:): foreach my $type (@statuses) {
10237:): if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
10238:): $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
10239:): }
10240:): if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
10241:): $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
10242:): }
10243:): if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
10244:): #
10245:): # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
10246:): #
10247:): my $chosen = $1;
10248:): if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
10249:): my $emaildom;
10250:): if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
10251:): $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
10252:): $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
10253:): if (ref($curremaildom{$type}) eq 'HASH') {
10254:): if (exists($curremaildom{$type}{$chosen})) {
10255:): if ($curremaildom{$type}{$chosen} ne $emaildom) {
10256:): push(@{$changes{'cancreate'}},'emaildomain');
10257:): }
10258:): } elsif ($emaildom ne '') {
10259:): push(@{$changes{'cancreate'}},'emaildomain');
10260:): }
10261:): } elsif ($emaildom ne '') {
10262:): push(@{$changes{'cancreate'}},'emaildomain');
10263:): }
10264:): }
10265:): $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
10266:): } elsif ($chosen eq 'custom') {
10267:): my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
10268:): $email_rule{$type} = [];
10269:): if (ref($emailrules) eq 'HASH') {
10270:): foreach my $rule (@possemail_rules) {
10271:): if (exists($emailrules->{$rule})) {
10272:): push(@{$email_rule{$type}},$rule);
10273:): }
10274:): }
10275:): }
10276:): if (@{$email_rule{$type}}) {
10277:): $cancreate{'emailoptions'}{$type} = 'custom';
10278:): if (ref($curr_rule{$type}) eq 'ARRAY') {
10279:): if (@{$curr_rule{$type}} > 0) {
10280:): foreach my $rule (@{$curr_rule{$type}}) {
10281:): if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
10282:): push(@{$changes{'email_rule'}},$type);
10283:): }
10284:): }
10285:): }
10286:): foreach my $type (@{$email_rule{$type}}) {
10287:): if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
10288:): push(@{$changes{'email_rule'}},$type);
10289:): }
10290:): }
10291:): } else {
10292:): push(@{$changes{'email_rule'}},$type);
10293:): }
10294:): }
10295:): } else {
10296:): $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
10297:): }
10298:): }
10299:): }
10300:): if (@types) {
10301:): if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
10302:): my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
10303:): if (@changed) {
10304:): push(@{$changes{'inststatus'}},'inststatusguest');
10305:): }
10306:): } else {
10307:): push(@{$changes{'inststatus'}},'inststatusguest');
10308:): }
10309:): }
10310:): } else {
10311:): delete($env{'form.cancreate_email'});
10312:): if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
10313:): if (@{$curr_inststatus{'inststatusguest'}} > 0) {
10314:): push(@{$changes{'inststatus'}},'inststatusguest');
10315:): }
10316:): }
10317:): }
10318:): } else {
10319:): $save_inststatus{'inststatusguest'} = [];
10320:): if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
10321:): if (@{$curr_inststatus{'inststatusguest'}} > 0) {
10322:): push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 10323: }
10324: }
1.160.6.34 raeburn 10325: }
10326: } else {
10327: if ($env{'form.cancreate_'.$item}) {
10328: push(@{$cancreate{'selfcreate'}},$item);
10329: }
10330: }
10331: }
1.160.6.84.4. (raeburn 10332:): my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 10333: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
10334: #
1.160.6.35 raeburn 10335: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
10336: # 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 10337: #
1.160.6.40 raeburn 10338:
1.160.6.48 raeburn 10339: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 10340: push(@contexts,'emailusername');
1.160.6.84.4. (raeburn 10341:): if (@statuses) {
10342:): foreach my $type (@statuses) {
1.160.6.35 raeburn 10343: if (ref($infofields) eq 'ARRAY') {
10344: foreach my $field (@{$infofields}) {
10345: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
10346: $cancreate{'emailusername'}{$type}{$field} = $1;
10347: }
10348: }
1.160.6.34 raeburn 10349: }
10350: }
10351: }
10352: #
10353: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.84.4. (raeburn 10354:): # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 10355: #
10356:
10357: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
10358: @approvalnotify = sort(@approvalnotify);
10359: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
10360: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10361: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
10362: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
10363: push(@{$changes{'cancreate'}},'notify');
10364: }
10365: } else {
10366: if ($cancreate{'notify'}{'approval'}) {
10367: push(@{$changes{'cancreate'}},'notify');
10368: }
10369: }
10370: } elsif ($cancreate{'notify'}{'approval'}) {
10371: push(@{$changes{'cancreate'}},'notify');
10372: }
10373:
10374: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
10375: }
10376: #
1.160.6.40 raeburn 10377: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 10378: # institutional log-in.
10379: #
10380: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
10381: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
10382: ($domdefaults{'auth_def'} eq 'localauth'))) {
10383: $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.').' '.
10384: &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.');
10385: }
10386: }
10387: my @fields = ('lastname','firstname','middlename','generation',
10388: 'permanentemail','id');
1.160.6.44 raeburn 10389: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 10390: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10391: #
10392: # Where usernames may created for institutional log-in and/or institutional single sign on:
10393: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
10394: # may self-create accounts
10395: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
10396: # which the user may supply, if institutional data is unavailable.
10397: #
10398: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.84.4. (raeburn 10399:): if (@types) {
10400:): @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
10401:): push(@contexts,'statustocreate');
10402:): foreach my $type (@types) {
1.160.6.34 raeburn 10403: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
10404: foreach my $field (@fields) {
10405: if (grep(/^\Q$field\E$/,@modifiable)) {
10406: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
10407: } else {
10408: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
10409: }
10410: }
10411: }
10412: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.84.4. (raeburn 10413:): foreach my $type (@types) {
1.160.6.34 raeburn 10414: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
10415: foreach my $field (@fields) {
10416: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
10417: $curr_usermodify{'selfcreate'}{$type}{$field}) {
10418: push(@{$changes{'selfcreate'}},$type);
10419: last;
10420: }
10421: }
10422: }
10423: }
10424: } else {
1.160.6.84.4. (raeburn 10425:): foreach my $type (@types) {
1.160.6.34 raeburn 10426: push(@{$changes{'selfcreate'}},$type);
10427: }
10428: }
10429: }
1.160.6.44 raeburn 10430: foreach my $field (@shibfields) {
10431: if ($env{'form.shibenv_'.$field} ne '') {
10432: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10433: }
10434: }
10435: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10436: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10437: foreach my $field (@shibfields) {
10438: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10439: push(@{$changes{'cancreate'}},'shibenv');
10440: }
10441: }
10442: } else {
10443: foreach my $field (@shibfields) {
10444: if ($env{'form.shibenv_'.$field}) {
10445: push(@{$changes{'cancreate'}},'shibenv');
10446: last;
10447: }
10448: }
10449: }
10450: }
1.160.6.34 raeburn 10451: }
10452: foreach my $item (@contexts) {
10453: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10454: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10455: if (ref($cancreate{$item}) eq 'ARRAY') {
10456: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10457: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10458: push(@{$changes{'cancreate'}},$item);
10459: }
10460: }
10461: }
10462: }
10463: if (ref($cancreate{$item}) eq 'ARRAY') {
10464: foreach my $type (@{$cancreate{$item}}) {
10465: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10466: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10467: push(@{$changes{'cancreate'}},$item);
10468: }
10469: }
10470: }
10471: }
10472: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10473: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.84.4. (raeburn 10474:): foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
10475:): if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
10476:): foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
10477:): unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 10478: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10479: push(@{$changes{'cancreate'}},$item);
10480: }
10481: }
10482: }
1.160.6.84.4. (raeburn 10483:): } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
10484:): if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 10485: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10486: push(@{$changes{'cancreate'}},$item);
10487: }
1.160.6.34 raeburn 10488: }
10489: }
10490: }
1.160.6.84.4. (raeburn 10491:): foreach my $type (keys(%{$cancreate{$item}})) {
10492:): if (ref($cancreate{$item}{$type}) eq 'HASH') {
10493:): foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10494:): if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
10495:): unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 10496: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10497: push(@{$changes{'cancreate'}},$item);
10498: }
10499: }
10500: } else {
10501: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10502: push(@{$changes{'cancreate'}},$item);
10503: }
10504: }
10505: }
1.160.6.84.4. (raeburn 10506:): } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
10507:): if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 10508: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10509: push(@{$changes{'cancreate'}},$item);
10510: }
1.160.6.34 raeburn 10511: }
10512: }
10513: }
10514: }
10515: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10516: if (ref($cancreate{$item}) eq 'ARRAY') {
10517: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10518: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10519: push(@{$changes{'cancreate'}},$item);
10520: }
10521: }
1.160.6.84.4. (raeburn 10522:): }
10523:): } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
10524:): if (ref($cancreate{$item}) eq 'HASH') {
10525:): if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10526:): push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 10527: }
10528: }
10529: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 10530: if (ref($cancreate{$item}) eq 'HASH') {
10531: foreach my $type (keys(%{$cancreate{$item}})) {
10532: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10533: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10534: if ($cancreate{$item}{$type}{$field}) {
10535: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10536: push(@{$changes{'cancreate'}},$item);
10537: }
10538: last;
10539: }
10540: }
10541: }
10542: }
1.160.6.34 raeburn 10543: }
10544: }
10545: }
10546: #
10547: # Populate %save_usercreate hash with updates to self-creation configuration.
10548: #
10549: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10550: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 10551: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 10552: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10553: if (ref($cancreate{'notify'}) eq 'HASH') {
10554: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10555: }
1.160.6.40 raeburn 10556: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10557: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10558: }
1.160.6.84.4. (raeburn 10559:): if (ref($cancreate{'emailverified'}) eq 'HASH') {
10560:): $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
10561:): }
10562:): if (ref($cancreate{'emailoptions'}) eq 'HASH') {
10563:): $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
10564:): }
10565:): if (ref($cancreate{'emaildomain'}) eq 'HASH') {
10566:): $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
10567:): }
1.160.6.34 raeburn 10568: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10569: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10570: }
1.160.6.44 raeburn 10571: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10572: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10573: }
1.160.6.34 raeburn 10574: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.84.4. (raeburn 10575:): $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 10576:
10577: my %userconfig_hash = (
10578: usercreation => \%save_usercreate,
10579: usermodification => \%save_usermodify,
1.160.6.84.4. (raeburn 10580:): inststatus => \%save_inststatus,
1.160.6.34 raeburn 10581: );
1.160.6.84.4. (raeburn 10582:):
1.160.6.34 raeburn 10583: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10584: $dom);
10585: #
1.160.6.84.4. (raeburn 10586:): # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 10587: #
1.27 raeburn 10588: if ($putresult eq 'ok') {
10589: if (keys(%changes) > 0) {
10590: $resulttext = &mt('Changes made:').'<ul>';
10591: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 10592: my %lt = &selfcreation_types();
1.34 raeburn 10593: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.84.4. (raeburn 10594:): my $chgtext = '';
1.45 raeburn 10595: if ($type eq 'selfcreate') {
1.50 raeburn 10596: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 10597: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10598: } else {
1.160.6.34 raeburn 10599: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10600: '<ul>';
1.50 raeburn 10601: foreach my $case (@{$cancreate{$type}}) {
10602: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10603: }
10604: $chgtext .= '</ul>';
1.100 raeburn 10605: if (ref($cancreate{$type}) eq 'ARRAY') {
10606: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10607: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10608: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.84.4. (raeburn 10609:): $chgtext .= '<span class="LC_warning">'.
10610:): &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
10611:): '</span><br />';
1.100 raeburn 10612: }
10613: }
10614: }
1.160.6.84.4. (raeburn 10615:): if (grep(/^email$/,@{$cancreate{$type}})) {
10616:): if (!@statuses) {
10617:): $chgtext .= '<span class="LC_warning">'.
10618:): &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.").
10619:): '</span><br />';
10620:):
10621:): }
10622:): }
1.100 raeburn 10623: }
1.43 raeburn 10624: }
1.160.6.44 raeburn 10625: } elsif ($type eq 'shibenv') {
10626: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.84.4. (raeburn 10627:): $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 10628: } else {
10629: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10630: '<ul>';
10631: foreach my $field (@shibfields) {
10632: next if ($cancreate{$type}{$field} eq '');
10633: if ($field eq 'inststatus') {
10634: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10635: } else {
10636: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10637: }
10638: }
10639: $chgtext .= '</ul>';
1.160.6.84.4. (raeburn 10640:): }
1.93 raeburn 10641: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10642: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10643: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10644: if (@{$cancreate{'selfcreate'}} > 0) {
10645: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10646: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10647: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10648: $chgtext .= '<br />'.
10649: '<span class="LC_warning">'.
10650: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10651: '</span>';
10652: }
1.160.6.84.4. (raeburn 10653:): } elsif (keys(%usertypes) > 0) {
1.96 raeburn 10654: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10655: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10656: } else {
10657: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10658: }
10659: $chgtext .= '<ul>';
10660: foreach my $case (@{$cancreate{$type}}) {
10661: if ($case eq 'default') {
10662: $chgtext .= '<li>'.$othertitle.'</li>';
10663: } else {
1.160.6.84.4. (raeburn 10664:): $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 10665: }
10666: }
1.100 raeburn 10667: $chgtext .= '</ul>';
10668: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.84.4. (raeburn 10669:): $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 10670: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10671: '</span>';
1.100 raeburn 10672: }
10673: }
10674: } else {
10675: if (@{$cancreate{$type}} == 0) {
10676: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10677: } else {
10678: $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 10679: }
10680: }
1.160.6.84.4. (raeburn 10681:): $chgtext .= '<br />';
1.93 raeburn 10682: }
1.160.6.40 raeburn 10683: } elsif ($type eq 'selfcreateprocessing') {
10684: my %choices = &Apache::lonlocal::texthash (
10685: automatic => 'Automatic approval',
10686: approval => 'Queued for approval',
10687: );
1.160.6.84.4. (raeburn 10688:): if (@types) {
10689:): if (@statuses) {
10690:): $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
10691:): '<ul>';
10692:): foreach my $status (@statuses) {
10693:): if ($status eq 'default') {
10694:): $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
10695:): } else {
10696:): $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
10697:): }
10698:): }
10699:): $chgtext .= '</ul>';
10700:): }
10701:): } else {
10702:): $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
10703:): $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10704:): }
10705:): } elsif ($type eq 'emailverified') {
10706:): my %options = &Apache::lonlocal::texthash (
10707:): all => 'Same as e-mail',
10708:): first => 'Omit @domain',
10709:): free => 'Free to choose',
10710:): );
10711:): if (@types) {
10712:): if (@statuses) {
10713:): $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
10714:): '<ul>';
10715:): foreach my $status (@statuses) {
10716:): if ($type eq 'default') {
10717:): $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
10718:): } else {
10719:): $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
10720:): }
10721:): }
10722:): $chgtext .= '</ul>';
10723:): }
1.160.6.40 raeburn 10724: } else {
1.160.6.84.4. (raeburn 10725:): $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
10726:): $options{$cancreate{'emailverified'}{'default'}});
10727:): }
10728:): } elsif ($type eq 'emailoptions') {
10729:): my %options = &Apache::lonlocal::texthash (
10730:): any => 'Any e-mail',
10731:): inst => 'Institutional only',
10732:): noninst => 'Non-institutional only',
10733:): custom => 'Custom restrictions',
10734:): );
10735:): if (@types) {
10736:): if (@statuses) {
10737:): $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
10738:): '<ul>';
10739:): foreach my $status (@statuses) {
10740:): if ($type eq 'default') {
10741:): $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
10742:): } else {
10743:): $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
10744:): }
10745:): }
10746:): $chgtext .= '</ul>';
10747:): }
10748:): } else {
10749:): if ($cancreate{'emailoptions'}{'default'} eq 'any') {
10750:): $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
10751:): } else {
10752:): $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
10753:): $options{$cancreate{'emailoptions'}{'default'}});
10754:): }
10755:): }
10756:): } elsif ($type eq 'emaildomain') {
10757:): my $output;
10758:): if (@statuses) {
10759:): foreach my $type (@statuses) {
10760:): if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
10761:): if ($cancreate{'emailoptions'}{$type} eq 'inst') {
10762:): if ($type eq 'default') {
10763:): if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
10764:): ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
10765:): $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
10766:): } else {
10767:): $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
10768:): $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
10769:): }
10770:): } else {
10771:): if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
10772:): ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
10773:): $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
10774:): } else {
10775:): $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
10776:): $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
10777:): }
10778:): }
10779:): } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
10780:): if ($type eq 'default') {
10781:): if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
10782:): ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
10783:): $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
10784:): } else {
10785:): $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
10786:): $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
10787:): }
10788:): } else {
10789:): if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
10790:): ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
10791:): $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
10792:): } else {
10793:): $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
10794:): $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
10795:): }
10796:): }
10797:): }
10798:): }
10799:): }
10800:): }
10801:): if ($output ne '') {
10802:): $chgtext .= &mt('For self-created accounts verified by e-mail address:').
10803:): '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 10804: }
1.160.6.5 raeburn 10805: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 10806: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 10807: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10808: } else {
10809: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 10810: if ($captchas{$savecaptcha{$type}}) {
10811: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 10812: } else {
10813: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
10814: }
10815: }
10816: } elsif ($type eq 'recaptchakeys') {
10817: my ($privkey,$pubkey);
1.160.6.34 raeburn 10818: if (ref($savecaptcha{$type}) eq 'HASH') {
10819: $pubkey = $savecaptcha{$type}{'public'};
10820: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 10821: }
10822: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10823: if (!$pubkey) {
10824: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10825: } else {
10826: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10827: }
10828: if (!$privkey) {
10829: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10830: } else {
10831: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10832: }
10833: $chgtext .= '</ul>';
1.160.6.69 raeburn 10834: } elsif ($type eq 'recaptchaversion') {
10835: if ($savecaptcha{'captcha'} eq 'recaptcha') {
10836: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
10837: }
1.160.6.34 raeburn 10838: } elsif ($type eq 'emailusername') {
10839: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.84.4. (raeburn 10840:): if (@statuses) {
10841:): foreach my $type (@statuses) {
1.160.6.35 raeburn 10842: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10843: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.84.4. (raeburn 10844:): $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 10845: '<ul>';
10846: foreach my $field (@{$infofields}) {
10847: if ($cancreate{'emailusername'}{$type}{$field}) {
10848: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10849: }
10850: }
1.160.6.50 raeburn 10851: $chgtext .= '</ul>';
10852: } else {
1.160.6.84.4. (raeburn 10853:): $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 10854: }
10855: } else {
1.160.6.84.4. (raeburn 10856:): $chgtext .= &mt('When self creating account with e-mail verficiation, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.160.6.34 raeburn 10857: }
10858: }
10859: }
10860: }
10861: } elsif ($type eq 'notify') {
1.160.6.84.4. (raeburn 10862:): my $numapprove = 0;
1.160.6.34 raeburn 10863: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10864: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10865: if ($cancreate{'notify'}{'approval'}) {
1.160.6.84.4. (raeburn 10866:): $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10867:): $numapprove ++;
1.160.6.34 raeburn 10868: }
10869: }
1.43 raeburn 10870: }
1.160.6.84.4. (raeburn 10871:): unless ($numapprove) {
10872:): $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10873:): }
1.34 raeburn 10874: }
1.160.6.34 raeburn 10875: if ($chgtext) {
10876: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10877: }
10878: }
10879: }
1.160.6.84.4. (raeburn 10880:): if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 10881: my ($emailrules,$emailruleorder) =
10882: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.84.4. (raeburn 10883:): foreach my $type (@{$changes{'email_rule'}}) {
10884:): if (ref($email_rule{$type}) eq 'ARRAY') {
10885:): my $chgtext = '<ul>';
10886:): foreach my $rule (@{$email_rule{$type}}) {
10887:): if (ref($emailrules->{$rule}) eq 'HASH') {
10888:): $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
10889:): }
10890:): }
10891:): $chgtext .= '</ul>';
10892:): my $typename;
10893:): if (@types) {
10894:): if ($type eq 'default') {
10895:): $typename = $othertitle;
10896:): } else {
10897:): $typename = $usertypes{$type};
10898:): }
10899:): $chgtext .= &mt('(Affiliation: [_1])',$typename);
10900:): }
10901:): if (@{$email_rule{$type}} > 0) {
10902:): $resulttext .= '<li>'.
10903:): &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
10904:): $usertypes{$type}).
10905:): $chgtext.
10906:): '</li>';
10907:): } else {
10908:): $resulttext .= '<li>'.
10909:): &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
10910:): '</li>'.
10911:): &mt('(Affiliation: [_1])',$typename);
10912:): }
1.43 raeburn 10913: }
10914: }
1.160.6.84.4. (raeburn 10915:): }
10916:): if (ref($changes{'inststatus'}) eq 'ARRAY') {
10917:): if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
10918:): if (@{$save_inststatus{'inststatusguest'}} > 0) {
10919:): my $chgtext = '<ul>';
10920:): foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
10921:): $chgtext .= '<li>'.$usertypes{$type}.'</li>';
10922:): }
10923:): $chgtext .= '</ul>';
10924:): $resulttext .= '<li>'.
10925:): &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
10926:): $chgtext.
10927:): '</li>';
10928:): } else {
10929:): $resulttext .= '<li>'.
10930:): &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
10931:): '</li>';
10932:): }
1.43 raeburn 10933: }
10934: }
1.160.6.34 raeburn 10935: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10936: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10937: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10938: foreach my $type (@{$changes{'selfcreate'}}) {
10939: my $typename = $type;
1.160.6.84.4. (raeburn 10940:): if (keys(%usertypes) > 0) {
10941:): if ($usertypes{$type} ne '') {
10942:): $typename = $usertypes{$type};
1.28 raeburn 10943: }
10944: }
1.160.6.34 raeburn 10945: my @modifiable;
10946: $resulttext .= '<li>'.
10947: &mt('Self-creation of account by users with status: [_1]',
10948: '<span class="LC_cusr_emph">'.$typename.'</span>').
10949: ' - '.&mt('modifiable fields (if institutional data blank): ');
10950: foreach my $field (@fields) {
10951: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10952: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
10953: }
10954: }
10955: if (@modifiable > 0) {
10956: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10957: } else {
1.160.6.34 raeburn 10958: $resulttext .= &mt('none');
1.43 raeburn 10959: }
1.160.6.34 raeburn 10960: $resulttext .= '</li>';
1.28 raeburn 10961: }
1.160.6.34 raeburn 10962: $resulttext .= '</ul></li>';
1.28 raeburn 10963: }
1.27 raeburn 10964: $resulttext .= '</ul>';
1.160.6.84.4. (raeburn 10965:): my $cachetime = 24*60*60;
10966:): $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
10967:): &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
10968:): if (ref($lastactref) eq 'HASH') {
10969:): $lastactref->{'domdefaults'} = 1;
10970:): }
1.27 raeburn 10971: } else {
1.160.6.34 raeburn 10972: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10973: }
10974: } else {
10975: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10976: &mt('An error occurred: [_1]',$putresult).'</span>';
10977: }
1.43 raeburn 10978: if ($warningmsg ne '') {
10979: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10980: }
1.23 raeburn 10981: return $resulttext;
10982: }
10983:
1.160.6.5 raeburn 10984: sub process_captcha {
10985: my ($container,$changes,$newsettings,$current) = @_;
10986: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10987: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10988: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10989: $newsettings->{'captcha'} = 'original';
10990: }
10991: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
10992: if ($container eq 'cancreate') {
10993: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10994: push(@{$changes->{'cancreate'}},'captcha');
10995: } elsif (!defined($changes->{'cancreate'})) {
10996: $changes->{'cancreate'} = ['captcha'];
10997: }
10998: } else {
10999: $changes->{'captcha'} = 1;
11000: }
11001: }
1.160.6.69 raeburn 11002: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 11003: if ($newsettings->{'captcha'} eq 'recaptcha') {
11004: $newpub = $env{'form.'.$container.'_recaptchapub'};
11005: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 11006: $newpub =~ s/[^\w\-]//g;
11007: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 11008: $newsettings->{'recaptchakeys'} = {
11009: public => $newpub,
11010: private => $newpriv,
11011: };
1.160.6.69 raeburn 11012: $newversion = $env{'form.'.$container.'_recaptchaversion'};
11013: $newversion =~ s/\D//g;
11014: if ($newversion ne '2') {
11015: $newversion = 1;
11016: }
11017: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 11018: }
11019: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
11020: $currpub = $current->{'recaptchakeys'}{'public'};
11021: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 11022: unless ($newsettings->{'captcha'} eq 'recaptcha') {
11023: $newsettings->{'recaptchakeys'} = {
11024: public => '',
11025: private => '',
11026: }
11027: }
1.160.6.5 raeburn 11028: }
1.160.6.69 raeburn 11029: if ($current->{'captcha'} eq 'recaptcha') {
11030: $currversion = $current->{'recaptchaversion'};
11031: if ($currversion ne '2') {
11032: $currversion = 1;
11033: }
11034: }
11035: if ($currversion ne $newversion) {
11036: if ($container eq 'cancreate') {
11037: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11038: push(@{$changes->{'cancreate'}},'recaptchaversion');
11039: } elsif (!defined($changes->{'cancreate'})) {
11040: $changes->{'cancreate'} = ['recaptchaversion'];
11041: }
11042: } else {
11043: $changes->{'recaptchaversion'} = 1;
11044: }
11045: }
1.160.6.5 raeburn 11046: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
11047: if ($container eq 'cancreate') {
11048: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
11049: push(@{$changes->{'cancreate'}},'recaptchakeys');
11050: } elsif (!defined($changes->{'cancreate'})) {
11051: $changes->{'cancreate'} = ['recaptchakeys'];
11052: }
11053: } else {
11054: $changes->{'recaptchakeys'} = 1;
11055: }
11056: }
11057: return;
11058: }
11059:
1.33 raeburn 11060: sub modify_usermodification {
11061: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 11062: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 11063: if (ref($domconfig{'usermodification'}) eq 'HASH') {
11064: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 11065: if ($key eq 'selfcreate') {
11066: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
11067: } else {
11068: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
11069: }
1.33 raeburn 11070: }
11071: }
1.160.6.34 raeburn 11072: my @contexts = ('author','course');
1.33 raeburn 11073: my %context_title = (
11074: author => 'In author context',
11075: course => 'In course context',
11076: );
11077: my @fields = ('lastname','firstname','middlename','generation',
11078: 'permanentemail','id');
11079: my %roles = (
11080: author => ['ca','aa'],
11081: course => ['st','ep','ta','in','cr'],
11082: );
11083: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11084: foreach my $context (@contexts) {
11085: foreach my $role (@{$roles{$context}}) {
11086: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
11087: foreach my $item (@fields) {
11088: if (grep(/^\Q$item\E$/,@modifiable)) {
11089: $modifyhash{$context}{$role}{$item} = 1;
11090: } else {
11091: $modifyhash{$context}{$role}{$item} = 0;
11092: }
11093: }
11094: }
11095: if (ref($curr_usermodification{$context}) eq 'HASH') {
11096: foreach my $role (@{$roles{$context}}) {
11097: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
11098: foreach my $field (@fields) {
11099: if ($modifyhash{$context}{$role}{$field} ne
11100: $curr_usermodification{$context}{$role}{$field}) {
11101: push(@{$changes{$context}},$role);
11102: last;
11103: }
11104: }
11105: }
11106: }
11107: } else {
11108: foreach my $context (@contexts) {
11109: foreach my $role (@{$roles{$context}}) {
11110: push(@{$changes{$context}},$role);
11111: }
11112: }
11113: }
11114: }
11115: my %usermodification_hash = (
11116: usermodification => \%modifyhash,
11117: );
11118: my $putresult = &Apache::lonnet::put_dom('configuration',
11119: \%usermodification_hash,$dom);
11120: if ($putresult eq 'ok') {
11121: if (keys(%changes) > 0) {
11122: $resulttext = &mt('Changes made: ').'<ul>';
11123: foreach my $context (@contexts) {
11124: if (ref($changes{$context}) eq 'ARRAY') {
11125: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
11126: if (ref($changes{$context}) eq 'ARRAY') {
11127: foreach my $role (@{$changes{$context}}) {
11128: my $rolename;
1.160.6.34 raeburn 11129: if ($role eq 'cr') {
11130: $rolename = &mt('Custom');
1.33 raeburn 11131: } else {
1.160.6.34 raeburn 11132: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 11133: }
11134: my @modifiable;
1.160.6.34 raeburn 11135: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 11136: foreach my $field (@fields) {
11137: if ($modifyhash{$context}{$role}{$field}) {
11138: push(@modifiable,$fieldtitles{$field});
11139: }
11140: }
11141: if (@modifiable > 0) {
11142: $resulttext .= join(', ',@modifiable);
11143: } else {
11144: $resulttext .= &mt('none');
11145: }
11146: $resulttext .= '</li>';
11147: }
11148: $resulttext .= '</ul></li>';
11149: }
11150: }
11151: }
11152: $resulttext .= '</ul>';
11153: } else {
11154: $resulttext = &mt('No changes made to user modification settings');
11155: }
11156: } else {
11157: $resulttext = '<span class="LC_error">'.
11158: &mt('An error occurred: [_1]',$putresult).'</span>';
11159: }
11160: return $resulttext;
11161: }
11162:
1.43 raeburn 11163: sub modify_defaults {
1.160.6.27 raeburn 11164: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 11165: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 11166: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 11167: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
11168: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 11169: my @authtypes = ('internal','krb4','krb5','localauth');
11170: foreach my $item (@items) {
11171: $newvalues{$item} = $env{'form.'.$item};
11172: if ($item eq 'auth_def') {
11173: if ($newvalues{$item} ne '') {
11174: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
11175: push(@errors,$item);
11176: }
11177: }
11178: } elsif ($item eq 'lang_def') {
11179: if ($newvalues{$item} ne '') {
11180: if ($newvalues{$item} =~ /^(\w+)/) {
11181: my $langcode = $1;
1.103 raeburn 11182: if ($langcode ne 'x_chef') {
11183: if (code2language($langcode) eq '') {
11184: push(@errors,$item);
11185: }
1.43 raeburn 11186: }
11187: } else {
11188: push(@errors,$item);
11189: }
11190: }
1.54 raeburn 11191: } elsif ($item eq 'timezone_def') {
11192: if ($newvalues{$item} ne '') {
1.62 raeburn 11193: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 11194: push(@errors,$item);
11195: }
11196: }
1.68 raeburn 11197: } elsif ($item eq 'datelocale_def') {
11198: if ($newvalues{$item} ne '') {
11199: my @datelocale_ids = DateTime::Locale->ids();
11200: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
11201: push(@errors,$item);
11202: }
11203: }
1.141 raeburn 11204: } elsif ($item eq 'portal_def') {
11205: if ($newvalues{$item} ne '') {
11206: 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])\/?$/) {
11207: push(@errors,$item);
11208: }
11209: }
1.160.6.80 raeburn 11210: } elsif ($item eq 'intauth_cost') {
11211: if ($newvalues{$item} ne '') {
11212: if ($newvalues{$item} =~ /\D/) {
11213: push(@errors,$item);
11214: }
11215: }
11216: } elsif ($item eq 'intauth_check') {
11217: if ($newvalues{$item} ne '') {
11218: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11219: push(@errors,$item);
11220: }
11221: }
11222: } elsif ($item eq 'intauth_switch') {
11223: if ($newvalues{$item} ne '') {
11224: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
11225: push(@errors,$item);
11226: }
11227: }
1.43 raeburn 11228: }
11229: if (grep(/^\Q$item\E$/,@errors)) {
11230: $newvalues{$item} = $domdefaults{$item};
11231: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
11232: $changes{$item} = 1;
11233: }
1.72 raeburn 11234: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 11235: }
11236: my %defaults_hash = (
1.72 raeburn 11237: defaults => \%newvalues,
11238: );
1.43 raeburn 11239: my $title = &defaults_titles();
1.160.6.40 raeburn 11240:
11241: my $currinststatus;
11242: if (ref($domconfig{'inststatus'}) eq 'HASH') {
11243: $currinststatus = $domconfig{'inststatus'};
11244: } else {
11245: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
11246: $currinststatus = {
11247: inststatustypes => $usertypes,
11248: inststatusorder => $types,
11249: inststatusguest => [],
11250: };
11251: }
11252: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
11253: my @allpos;
11254: my %alltypes;
1.160.6.84.4. (raeburn 11255:): my @inststatusguest;
11256:): if (ref($currinststatus) eq 'HASH') {
11257:): if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
11258:): foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
11259:): unless (grep(/^\Q$type\E$/,@todelete)) {
11260:): push(@inststatusguest,$type);
11261:): }
11262:): }
11263:): }
11264:): }
11265:): my ($currtitles,$currorder);
1.160.6.40 raeburn 11266: if (ref($currinststatus) eq 'HASH') {
11267: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
11268: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
11269: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
11270: if ($currinststatus->{inststatustypes}->{$type} ne '') {
11271: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
11272: }
11273: }
11274: unless (grep(/^\Q$type\E$/,@todelete)) {
11275: my $position = $env{'form.inststatus_pos_'.$type};
11276: $position =~ s/\D+//g;
11277: $allpos[$position] = $type;
11278: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
11279: $alltypes{$type} =~ s/`//g;
11280: }
11281: }
11282: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
11283: $currtitles =~ s/,$//;
11284: }
11285: }
11286: if ($env{'form.addinststatus'}) {
11287: my $newtype = $env{'form.addinststatus'};
11288: $newtype =~ s/\W//g;
11289: unless (exists($alltypes{$newtype})) {
11290: $alltypes{$newtype} = $env{'form.addinststatus_title'};
11291: $alltypes{$newtype} =~ s/`//g;
11292: my $position = $env{'form.addinststatus_pos'};
11293: $position =~ s/\D+//g;
11294: if ($position ne '') {
11295: $allpos[$position] = $newtype;
11296: }
11297: }
11298: }
1.160.6.84.4. (raeburn 11299:): my @orderedstatus;
1.160.6.40 raeburn 11300: foreach my $type (@allpos) {
11301: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
11302: push(@orderedstatus,$type);
11303: }
11304: }
11305: foreach my $type (keys(%alltypes)) {
11306: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
11307: delete($alltypes{$type});
11308: }
11309: }
11310: $defaults_hash{'inststatus'} = {
11311: inststatustypes => \%alltypes,
11312: inststatusorder => \@orderedstatus,
1.160.6.84.4. (raeburn 11313:): inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 11314: };
11315: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
11316: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
11317: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
11318: }
11319: }
11320: if ($currorder ne join(',',@orderedstatus)) {
11321: $changes{'inststatus'}{'inststatusorder'} = 1;
11322: }
11323: my $newtitles;
11324: foreach my $item (@orderedstatus) {
11325: $newtitles .= $alltypes{$item}.',';
11326: }
11327: $newtitles =~ s/,$//;
11328: if ($currtitles ne $newtitles) {
11329: $changes{'inststatus'}{'inststatustypes'} = 1;
11330: }
1.43 raeburn 11331: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
11332: $dom);
11333: if ($putresult eq 'ok') {
11334: if (keys(%changes) > 0) {
11335: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 11336: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 11337: 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";
11338: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 11339: if ($item eq 'inststatus') {
11340: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.84.4. (raeburn 11341:): if (@orderedstatus) {
1.160.6.40 raeburn 11342: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
11343: foreach my $type (@orderedstatus) {
11344: $resulttext .= $alltypes{$type}.', ';
11345: }
11346: $resulttext =~ s/, $//;
11347: $resulttext .= '</li>';
1.160.6.84.4. (raeburn 11348:): } else {
11349:): $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 11350: }
11351: }
11352: } else {
11353: my $value = $env{'form.'.$item};
11354: if ($value eq '') {
11355: $value = &mt('none');
11356: } elsif ($item eq 'auth_def') {
11357: my %authnames = &authtype_names();
11358: my %shortauth = (
11359: internal => 'int',
11360: krb4 => 'krb4',
11361: krb5 => 'krb5',
11362: localauth => 'loc',
11363: );
11364: $value = $authnames{$shortauth{$value}};
1.160.6.80 raeburn 11365: } elsif ($item eq 'intauth_switch') {
11366: my %optiondesc = &Apache::lonlocal::texthash (
11367: 0 => 'No',
11368: 1 => 'Yes',
11369: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
11370: );
11371: if ($value =~ /^(0|1|2)$/) {
11372: $value = $optiondesc{$value};
11373: } else {
11374: $value = &mt('none -- defaults to No');
11375: }
11376: } elsif ($item eq 'intauth_check') {
11377: my %optiondesc = &Apache::lonlocal::texthash (
11378: 0 => 'No',
11379: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
11380: 2 => 'Yes, disallow login if stored cost is less than domain default',
11381: );
11382: if ($value =~ /^(0|1|2)$/) {
11383: $value = $optiondesc{$value};
11384: } else {
11385: $value = &mt('none -- defaults to No');
11386: }
1.160.6.40 raeburn 11387: }
11388: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
11389: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 11390: }
11391: }
11392: $resulttext .= '</ul>';
11393: $mailmsgtext .= "\n";
11394: my $cachetime = 24*60*60;
1.72 raeburn 11395: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11396: if (ref($lastactref) eq 'HASH') {
11397: $lastactref->{'domdefaults'} = 1;
11398: }
1.68 raeburn 11399: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 11400: my $notify = 1;
11401: if (ref($domconfig{'contacts'}) eq 'HASH') {
11402: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
11403: $notify = 0;
11404: }
11405: }
11406: if ($notify) {
11407: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
11408: "LON-CAPA Domain Settings Change - $dom",
11409: $mailmsgtext);
11410: }
1.54 raeburn 11411: }
1.43 raeburn 11412: } else {
1.54 raeburn 11413: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 11414: }
11415: } else {
11416: $resulttext = '<span class="LC_error">'.
11417: &mt('An error occurred: [_1]',$putresult).'</span>';
11418: }
11419: if (@errors > 0) {
11420: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
11421: foreach my $item (@errors) {
11422: $resulttext .= ' "'.$title->{$item}.'",';
11423: }
11424: $resulttext =~ s/,$//;
11425: }
11426: return $resulttext;
11427: }
11428:
1.46 raeburn 11429: sub modify_scantron {
1.160.6.24 raeburn 11430: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 11431: my ($resulttext,%confhash,%changes,$errors);
11432: my $custom = 'custom.tab';
11433: my $default = 'default.tab';
11434: my $servadm = $r->dir_config('lonAdmEMail');
11435: my ($configuserok,$author_ok,$switchserver) =
11436: &config_check($dom,$confname,$servadm);
11437: if ($env{'form.scantronformat.filename'} ne '') {
11438: my $error;
11439: if ($configuserok eq 'ok') {
11440: if ($switchserver) {
1.130 raeburn 11441: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 11442: } else {
11443: if ($author_ok eq 'ok') {
11444: my ($result,$scantronurl) =
11445: &publishlogo($r,'upload','scantronformat',$dom,
11446: $confname,'scantron','','',$custom);
11447: if ($result eq 'ok') {
11448: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 11449: $changes{'scantronformat'} = 1;
1.46 raeburn 11450: } else {
11451: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
11452: }
11453: } else {
11454: $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);
11455: }
11456: }
11457: } else {
11458: $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);
11459: }
11460: if ($error) {
11461: &Apache::lonnet::logthis($error);
11462: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11463: }
11464: }
1.48 raeburn 11465: if (ref($domconfig{'scantron'}) eq 'HASH') {
11466: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
11467: if ($env{'form.scantronformat_del'}) {
11468: $confhash{'scantron'}{'scantronformat'} = '';
11469: $changes{'scantronformat'} = 1;
1.46 raeburn 11470: }
11471: }
11472: }
11473: if (keys(%confhash) > 0) {
11474: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
11475: $dom);
11476: if ($putresult eq 'ok') {
11477: if (keys(%changes) > 0) {
1.48 raeburn 11478: if (ref($confhash{'scantron'}) eq 'HASH') {
11479: $resulttext = &mt('Changes made:').'<ul>';
11480: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 11481: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 11482: } else {
1.130 raeburn 11483: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 11484: }
1.48 raeburn 11485: $resulttext .= '</ul>';
11486: } else {
1.130 raeburn 11487: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 11488: }
11489: $resulttext .= '</ul>';
11490: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11491: if (ref($lastactref) eq 'HASH') {
11492: $lastactref->{'domainconfig'} = 1;
11493: }
1.46 raeburn 11494: } else {
1.130 raeburn 11495: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11496: }
11497: } else {
11498: $resulttext = '<span class="LC_error">'.
11499: &mt('An error occurred: [_1]',$putresult).'</span>';
11500: }
11501: } else {
1.130 raeburn 11502: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 11503: }
11504: if ($errors) {
11505: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11506: $errors.'</ul>';
11507: }
11508: return $resulttext;
11509: }
11510:
1.48 raeburn 11511: sub modify_coursecategories {
1.160.6.43 raeburn 11512: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 11513: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
11514: $cathash);
1.48 raeburn 11515: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 11516: my @catitems = ('unauth','auth');
11517: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 11518: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 11519: $cathash = $domconfig{'coursecategories'}{'cats'};
11520: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
11521: $changes{'togglecats'} = 1;
11522: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
11523: }
11524: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
11525: $changes{'categorize'} = 1;
11526: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
11527: }
1.120 raeburn 11528: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
11529: $changes{'togglecatscomm'} = 1;
11530: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
11531: }
11532: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
11533: $changes{'categorizecomm'} = 1;
11534: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
11535: }
1.160.6.42 raeburn 11536: foreach my $item (@catitems) {
11537: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11538: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
11539: $changes{$item} = 1;
11540: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11541: }
11542: }
11543: }
1.57 raeburn 11544: } else {
11545: $changes{'togglecats'} = 1;
11546: $changes{'categorize'} = 1;
1.124 raeburn 11547: $changes{'togglecatscomm'} = 1;
11548: $changes{'categorizecomm'} = 1;
1.87 raeburn 11549: $domconfig{'coursecategories'} = {
11550: togglecats => $env{'form.togglecats'},
11551: categorize => $env{'form.categorize'},
1.124 raeburn 11552: togglecatscomm => $env{'form.togglecatscomm'},
11553: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 11554: };
1.160.6.42 raeburn 11555: foreach my $item (@catitems) {
11556: if ($env{'form.coursecat_'.$item} ne 'std') {
11557: $changes{$item} = 1;
11558: }
11559: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11560: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11561: }
11562: }
1.57 raeburn 11563: }
11564: if (ref($cathash) eq 'HASH') {
11565: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 11566: push (@deletecategory,'instcode::0');
11567: }
1.120 raeburn 11568: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11569: push(@deletecategory,'communities::0');
11570: }
1.48 raeburn 11571: }
1.57 raeburn 11572: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11573: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11574: if (@deletecategory > 0) {
11575: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 11576: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 11577: foreach my $item (@deletecategory) {
1.57 raeburn 11578: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11579: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11580: $deletions{$item} = 1;
1.57 raeburn 11581: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11582: }
11583: }
11584: }
1.57 raeburn 11585: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11586: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11587: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11588: $reorderings{$item} = 1;
1.57 raeburn 11589: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11590: }
11591: if ($env{'form.addcategory_name_'.$item} ne '') {
11592: my $newcat = $env{'form.addcategory_name_'.$item};
11593: my $newdepth = $depth+1;
11594: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11595: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11596: $adds{$newitem} = 1;
11597: }
11598: if ($env{'form.subcat_'.$item} ne '') {
11599: my $newcat = $env{'form.subcat_'.$item};
11600: my $newdepth = $depth+1;
11601: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11602: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11603: $adds{$newitem} = 1;
11604: }
11605: }
11606: }
11607: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11608: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11609: my $newitem = 'instcode::0';
1.57 raeburn 11610: if ($cathash->{$newitem} eq '') {
11611: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11612: $adds{$newitem} = 1;
11613: }
11614: } else {
11615: my $newitem = 'instcode::0';
1.57 raeburn 11616: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11617: $adds{$newitem} = 1;
11618: }
11619: }
1.120 raeburn 11620: if ($env{'form.communities'} eq '1') {
11621: if (ref($cathash) eq 'HASH') {
11622: my $newitem = 'communities::0';
11623: if ($cathash->{$newitem} eq '') {
11624: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11625: $adds{$newitem} = 1;
11626: }
11627: } else {
11628: my $newitem = 'communities::0';
11629: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11630: $adds{$newitem} = 1;
11631: }
11632: }
1.48 raeburn 11633: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11634: if (($env{'form.addcategory_name'} ne 'instcode') &&
11635: ($env{'form.addcategory_name'} ne 'communities')) {
11636: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11637: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11638: $adds{$newitem} = 1;
11639: }
1.48 raeburn 11640: }
1.57 raeburn 11641: my $putresult;
1.48 raeburn 11642: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11643: if (keys(%deletions) > 0) {
11644: foreach my $key (keys(%deletions)) {
11645: if ($predelallitems{$key} ne '') {
11646: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11647: }
11648: }
11649: }
11650: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11651: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11652: if (ref($chkcats[0]) eq 'ARRAY') {
11653: my $depth = 0;
11654: my $chg = 0;
11655: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11656: my $name = $chkcats[0][$i];
11657: my $item;
11658: if ($name eq '') {
11659: $chg ++;
11660: } else {
11661: $item = &escape($name).'::0';
11662: if ($chg) {
1.57 raeburn 11663: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11664: }
11665: $depth ++;
1.57 raeburn 11666: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11667: $depth --;
11668: }
11669: }
11670: }
1.57 raeburn 11671: }
11672: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11673: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11674: if ($putresult eq 'ok') {
1.57 raeburn 11675: my %title = (
1.120 raeburn 11676: togglecats => 'Show/Hide a course in catalog',
11677: categorize => 'Assign a category to a course',
11678: togglecatscomm => 'Show/Hide a community in catalog',
11679: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11680: );
11681: my %level = (
1.120 raeburn 11682: dom => 'set in Domain ("Modify Course/Community")',
11683: crs => 'set in Course ("Course Configuration")',
11684: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 11685: none => 'No catalog',
11686: std => 'Standard catalog',
11687: domonly => 'Domain-only catalog',
11688: codesrch => 'Code search form',
1.57 raeburn 11689: );
1.48 raeburn 11690: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11691: if ($changes{'togglecats'}) {
11692: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11693: }
11694: if ($changes{'categorize'}) {
11695: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11696: }
1.120 raeburn 11697: if ($changes{'togglecatscomm'}) {
11698: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11699: }
11700: if ($changes{'categorizecomm'}) {
11701: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11702: }
1.160.6.42 raeburn 11703: if ($changes{'unauth'}) {
11704: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11705: }
11706: if ($changes{'auth'}) {
11707: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11708: }
1.57 raeburn 11709: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11710: my $cathash;
11711: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11712: $cathash = $domconfig{'coursecategories'}{'cats'};
11713: } else {
11714: $cathash = {};
11715: }
11716: my (@cats,@trails,%allitems);
11717: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11718: if (keys(%deletions) > 0) {
11719: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11720: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11721: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11722: }
11723: $resulttext .= '</ul></li>';
11724: }
11725: if (keys(%reorderings) > 0) {
11726: my %sort_by_trail;
11727: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11728: foreach my $key (keys(%reorderings)) {
11729: if ($allitems{$key} ne '') {
11730: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11731: }
1.48 raeburn 11732: }
1.57 raeburn 11733: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11734: $resulttext .= '<li>'.$trails[$trail].'</li>';
11735: }
11736: $resulttext .= '</ul></li>';
1.48 raeburn 11737: }
1.57 raeburn 11738: if (keys(%adds) > 0) {
11739: my %sort_by_trail;
11740: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11741: foreach my $key (keys(%adds)) {
11742: if ($allitems{$key} ne '') {
11743: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11744: }
11745: }
11746: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11747: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11748: }
1.57 raeburn 11749: $resulttext .= '</ul></li>';
1.48 raeburn 11750: }
11751: }
11752: $resulttext .= '</ul>';
1.160.6.43 raeburn 11753: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 11754: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11755: if ($changes{'auth'}) {
11756: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11757: }
11758: if ($changes{'unauth'}) {
11759: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11760: }
11761: my $cachetime = 24*60*60;
11762: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 11763: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 11764: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 11765: }
11766: }
1.48 raeburn 11767: } else {
11768: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11769: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11770: }
11771: } else {
1.120 raeburn 11772: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11773: }
11774: return $resulttext;
11775: }
11776:
1.69 raeburn 11777: sub modify_serverstatuses {
11778: my ($dom,%domconfig) = @_;
11779: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11780: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11781: %currserverstatus = %{$domconfig{'serverstatuses'}};
11782: }
11783: my @pages = &serverstatus_pages();
11784: foreach my $type (@pages) {
11785: $newserverstatus{$type}{'namedusers'} = '';
11786: $newserverstatus{$type}{'machines'} = '';
11787: if (defined($env{'form.'.$type.'_namedusers'})) {
11788: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11789: my @okusers;
11790: foreach my $user (@users) {
11791: my ($uname,$udom) = split(/:/,$user);
11792: if (($udom =~ /^$match_domain$/) &&
11793: (&Apache::lonnet::domain($udom)) &&
11794: ($uname =~ /^$match_username$/)) {
11795: if (!grep(/^\Q$user\E/,@okusers)) {
11796: push(@okusers,$user);
11797: }
11798: }
11799: }
11800: if (@okusers > 0) {
11801: @okusers = sort(@okusers);
11802: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11803: }
11804: }
11805: if (defined($env{'form.'.$type.'_machines'})) {
11806: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11807: my @okmachines;
11808: foreach my $ip (@machines) {
11809: my @parts = split(/\./,$ip);
11810: next if (@parts < 4);
11811: my $badip = 0;
11812: for (my $i=0; $i<4; $i++) {
11813: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11814: $badip = 1;
11815: last;
11816: }
11817: }
11818: if (!$badip) {
11819: push(@okmachines,$ip);
11820: }
11821: }
11822: @okmachines = sort(@okmachines);
11823: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11824: }
11825: }
11826: my %serverstatushash = (
11827: serverstatuses => \%newserverstatus,
11828: );
11829: foreach my $type (@pages) {
1.83 raeburn 11830: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11831: my (@current,@new);
1.83 raeburn 11832: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11833: if ($currserverstatus{$type}{$setting} ne '') {
11834: @current = split(/,/,$currserverstatus{$type}{$setting});
11835: }
11836: }
11837: if ($newserverstatus{$type}{$setting} ne '') {
11838: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11839: }
11840: if (@current > 0) {
11841: if (@new > 0) {
11842: foreach my $item (@current) {
11843: if (!grep(/^\Q$item\E$/,@new)) {
11844: $changes{$type}{$setting} = 1;
1.82 raeburn 11845: last;
11846: }
11847: }
1.84 raeburn 11848: foreach my $item (@new) {
11849: if (!grep(/^\Q$item\E$/,@current)) {
11850: $changes{$type}{$setting} = 1;
11851: last;
1.82 raeburn 11852: }
11853: }
11854: } else {
1.83 raeburn 11855: $changes{$type}{$setting} = 1;
1.69 raeburn 11856: }
1.83 raeburn 11857: } elsif (@new > 0) {
11858: $changes{$type}{$setting} = 1;
1.69 raeburn 11859: }
11860: }
11861: }
11862: if (keys(%changes) > 0) {
1.81 raeburn 11863: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11864: my $putresult = &Apache::lonnet::put_dom('configuration',
11865: \%serverstatushash,$dom);
11866: if ($putresult eq 'ok') {
11867: $resulttext .= &mt('Changes made:').'<ul>';
11868: foreach my $type (@pages) {
1.84 raeburn 11869: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11870: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11871: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11872: if ($newserverstatus{$type}{'namedusers'} eq '') {
11873: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11874: } else {
11875: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11876: }
1.84 raeburn 11877: }
11878: if ($changes{$type}{'machines'}) {
1.69 raeburn 11879: if ($newserverstatus{$type}{'machines'} eq '') {
11880: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11881: } else {
11882: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11883: }
11884:
11885: }
11886: $resulttext .= '</ul></li>';
11887: }
11888: }
11889: $resulttext .= '</ul>';
11890: } else {
11891: $resulttext = '<span class="LC_error">'.
11892: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11893:
11894: }
11895: } else {
11896: $resulttext = &mt('No changes made to access to server status pages');
11897: }
11898: return $resulttext;
11899: }
11900:
1.118 jms 11901: sub modify_helpsettings {
1.160.6.77 raeburn 11902: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 11903: my ($resulttext,$errors,%changes,%helphash);
11904: my %defaultchecked = ('submitbugs' => 'on');
11905: my @offon = ('off','on');
1.118 jms 11906: my @toggles = ('submitbugs');
1.160.6.77 raeburn 11907: my %current = ('submitbugs' => '',
11908: 'adhoc' => {},
11909: );
1.118 jms 11910: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 11911: %current = %{$domconfig{'helpsettings'}};
11912: }
1.160.6.77 raeburn 11913: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 11914: foreach my $item (@toggles) {
11915: if ($defaultchecked{$item} eq 'on') {
11916: if ($current{$item} eq '') {
11917: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 11918: $changes{$item} = 1;
11919: }
1.160.6.73 raeburn 11920: } elsif ($current{$item} ne $env{'form.'.$item}) {
11921: $changes{$item} = 1;
11922: }
11923: } elsif ($defaultchecked{$item} eq 'off') {
11924: if ($current{$item} eq '') {
11925: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 11926: $changes{$item} = 1;
11927: }
1.160.6.73 raeburn 11928: } elsif ($current{$item} ne $env{'form.'.$item}) {
11929: $changes{$item} = 1;
11930: }
11931: }
11932: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
11933: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11934: }
11935: }
1.160.6.77 raeburn 11936: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 11937: my $confname = $dom.'-domainconfig';
11938: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 11939: my (@allpos,%newsettings,%changedprivs,$newrole);
11940: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 11941: my @accesstypes = ('all','dh','da','none','status','inc','exc');
11942: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 11943: my %lt = &Apache::lonlocal::texthash(
11944: s => 'system',
11945: d => 'domain',
11946: order => 'Display order',
11947: access => 'Role usage',
1.160.6.79 raeburn 11948: all => 'All with domain helpdesk or helpdesk assistant role',
11949: dh => 'All with domain helpdesk role',
11950: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 11951: none => 'None',
11952: status => 'Determined based on institutional status',
11953: inc => 'Include all, but exclude specific personnel',
11954: exc => 'Exclude all, but include specific personnel',
11955: );
11956: for (my $num=0; $num<=$maxnum; $num++) {
11957: my ($prefix,$identifier,$rolename,%curr);
11958: if ($num == $maxnum) {
11959: next unless ($env{'form.newcusthelp'} == $maxnum);
11960: $identifier = 'custhelp'.$num;
11961: $prefix = 'helproles_'.$num;
11962: $rolename = $env{'form.custhelpname'.$num};
11963: $rolename=~s/[^A-Za-z0-9]//gs;
11964: next if ($rolename eq '');
11965: next if (exists($existing{'rolesdef_'.$rolename}));
11966: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11967: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11968: $newprivs{'c'},$confname,$dom);
11969: if ($result ne 'ok') {
11970: $errors .= '<li><span class="LC_error">'.
11971: &mt('An error occurred storing the new custom role: [_1]',
11972: $result).'</span></li>';
11973: next;
11974: } else {
11975: $changedprivs{$rolename} = \%newprivs;
11976: $newrole = $rolename;
11977: }
11978: } else {
11979: $prefix = 'helproles_'.$num;
11980: $rolename = $env{'form.'.$prefix};
11981: next if ($rolename eq '');
11982: next unless (exists($existing{'rolesdef_'.$rolename}));
11983: $identifier = 'custhelp'.$num;
11984: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11985: my %currprivs;
11986: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
11987: split(/\_/,$existing{'rolesdef_'.$rolename});
11988: foreach my $level ('c','d','s') {
11989: if ($newprivs{$level} ne $currprivs{$level}) {
11990: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11991: $newprivs{'c'},$confname,$dom);
11992: if ($result ne 'ok') {
11993: $errors .= '<li><span class="LC_error">'.
11994: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
11995: $rolename,$result).'</span></li>';
11996: } else {
11997: $changedprivs{$rolename} = \%newprivs;
11998: }
11999: last;
12000: }
12001: }
12002: if (ref($current{'adhoc'}) eq 'HASH') {
12003: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12004: %curr = %{$current{'adhoc'}{$rolename}};
12005: }
12006: }
12007: }
12008: my $newpos = $env{'form.'.$prefix.'_pos'};
12009: $newpos =~ s/\D+//g;
12010: $allpos[$newpos] = $rolename;
12011: my $newdesc = $env{'form.'.$prefix.'_desc'};
12012: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
12013: if ($curr{'desc'}) {
12014: if ($curr{'desc'} ne $newdesc) {
12015: $changes{'customrole'}{$rolename}{'desc'} = 1;
12016: $newsettings{$rolename}{'desc'} = $newdesc;
12017: }
12018: } elsif ($newdesc ne '') {
12019: $changes{'customrole'}{$rolename}{'desc'} = 1;
12020: $newsettings{$rolename}{'desc'} = $newdesc;
12021: }
12022: my $access = $env{'form.'.$prefix.'_access'};
12023: if (grep(/^\Q$access\E$/,@accesstypes)) {
12024: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
12025: if ($access eq 'status') {
12026: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
12027: if (scalar(@statuses) == 0) {
12028: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
12029: } else {
12030: my (@shownstatus,$numtypes);
12031: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12032: if (ref($types) eq 'ARRAY') {
12033: $numtypes = scalar(@{$types});
12034: foreach my $type (sort(@statuses)) {
12035: if ($type eq 'default') {
12036: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12037: } elsif (grep(/^\Q$type\E$/,@{$types})) {
12038: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
12039: push(@shownstatus,$usertypes->{$type});
12040: }
1.160.6.73 raeburn 12041: }
12042: }
1.160.6.77 raeburn 12043: if (grep(/^default$/,@statuses)) {
12044: push(@shownstatus,$othertitle);
12045: }
12046: if (scalar(@shownstatus) == 1+$numtypes) {
12047: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
12048: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
12049: } else {
12050: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
12051: if (ref($curr{'status'}) eq 'ARRAY') {
12052: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12053: if (@diffs) {
12054: $changes{'customrole'}{$rolename}{$access} = 1;
12055: }
12056: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12057: $changes{'customrole'}{$rolename}{$access} = 1;
12058: }
12059: }
12060: }
12061: } elsif (($access eq 'inc') || ($access eq 'exc')) {
12062: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
12063: my @newspecstaff;
12064: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
12065: foreach my $person (sort(@personnel)) {
12066: if ($domhelpdesk{$person}) {
12067: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
12068: }
12069: }
12070: if (ref($curr{$access}) eq 'ARRAY') {
12071: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
12072: if (@diffs) {
12073: $changes{'customrole'}{$rolename}{$access} = 1;
12074: }
12075: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12076: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 12077: }
1.160.6.77 raeburn 12078: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
12079: my ($uname,$udom) = split(/:/,$person);
12080: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
12081: }
12082: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 12083: }
1.160.6.77 raeburn 12084: } else {
12085: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
12086: }
12087: unless ($curr{'access'} eq $access) {
12088: $changes{'customrole'}{$rolename}{'access'} = 1;
12089: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 12090: }
12091: }
1.160.6.77 raeburn 12092: if (@allpos > 0) {
12093: my $idx = 0;
12094: foreach my $rolename (@allpos) {
12095: if ($rolename ne '') {
12096: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
12097: if (ref($current{'adhoc'}) eq 'HASH') {
12098: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
12099: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
12100: $changes{'customrole'}{$rolename}{'order'} = 1;
12101: $newsettings{$rolename}{'order'} = $idx+1;
12102: }
12103: }
1.160.6.73 raeburn 12104: }
1.160.6.77 raeburn 12105: $idx ++;
1.122 jms 12106: }
12107: }
1.118 jms 12108: }
1.123 jms 12109: my $putresult;
12110: if (keys(%changes) > 0) {
1.160.6.5 raeburn 12111: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
12112: if ($putresult eq 'ok') {
1.160.6.77 raeburn 12113: if (ref($helphash{'helpsettings'}) eq 'HASH') {
12114: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
12115: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
12116: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
12117: }
12118: }
12119: my $cachetime = 24*60*60;
12120: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12121: if (ref($lastactref) eq 'HASH') {
12122: $lastactref->{'domdefaults'} = 1;
12123: }
12124: } else {
12125: $errors .= '<li><span class="LC_error">'.
12126: &mt('An error occurred storing the settings: [_1]',
12127: $putresult).'</span></li>';
12128: }
12129: }
12130: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
12131: $resulttext = &mt('Changes made:').'<ul>';
12132: my (%shownprivs,@levelorder);
12133: @levelorder = ('c','d','s');
12134: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 12135: foreach my $item (sort(keys(%changes))) {
12136: if ($item eq 'submitbugs') {
12137: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
12138: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
12139: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 12140: } elsif ($item eq 'customrole') {
12141: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 12142: my @keyorder = ('order','desc','access','status','exc','inc');
12143: my %keytext = &Apache::lonlocal::texthash(
12144: order => 'Order',
12145: desc => 'Role description',
12146: access => 'Role usage',
1.160.6.83 raeburn 12147: status => 'Allowed institutional types',
1.160.6.77 raeburn 12148: exc => 'Allowed personnel',
12149: inc => 'Disallowed personnel',
12150: );
1.160.6.73 raeburn 12151: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 12152: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
12153: if ($role eq $newrole) {
12154: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
12155: $role).'<ul>';
12156: } else {
12157: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12158: $role).'<ul>';
12159: }
12160: foreach my $key (@keyorder) {
12161: if ($changes{'customrole'}{$role}{$key}) {
12162: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
12163: $keytext{$key},$newsettings{$role}{$key}).
12164: '</li>';
12165: }
12166: }
12167: if (ref($changedprivs{$role}) eq 'HASH') {
12168: $shownprivs{$role} = 1;
12169: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
12170: foreach my $level (@levelorder) {
12171: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12172: next if ($item eq '');
12173: my ($priv) = split(/\&/,$item,2);
12174: if (&Apache::lonnet::plaintext($priv)) {
12175: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12176: unless ($level eq 'c') {
12177: $resulttext .= ' ('.$lt{$level}.')';
12178: }
12179: $resulttext .= '</li>';
12180: }
12181: }
12182: }
12183: $resulttext .= '</ul>';
12184: }
12185: $resulttext .= '</ul></li>';
12186: }
1.160.6.73 raeburn 12187: }
12188: }
1.160.6.5 raeburn 12189: }
12190: }
12191: }
1.160.6.77 raeburn 12192: if (keys(%changedprivs)) {
12193: foreach my $role (sort(keys(%changedprivs))) {
12194: unless ($shownprivs{$role}) {
12195: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
12196: $role).'<ul>'.
12197: '<li>'.&mt('Privileges set to :').'<ul>';
12198: foreach my $level (@levelorder) {
12199: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
12200: next if ($item eq '');
12201: my ($priv) = split(/\&/,$item,2);
12202: if (&Apache::lonnet::plaintext($priv)) {
12203: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
12204: unless ($level eq 'c') {
12205: $resulttext .= ' ('.$lt{$level}.')';
12206: }
12207: $resulttext .= '</li>';
12208: }
12209: }
12210: }
12211: $resulttext .= '</ul></li></ul></li>';
12212: }
12213: }
12214: }
12215: $resulttext .= '</ul>';
12216: } else {
12217: $resulttext = &mt('No changes made to help settings');
1.118 jms 12218: }
12219: if ($errors) {
1.160.6.5 raeburn 12220: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 12221: $errors.'</ul>';
1.118 jms 12222: }
12223: return $resulttext;
12224: }
12225:
1.121 raeburn 12226: sub modify_coursedefaults {
1.160.6.27 raeburn 12227: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 12228: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 12229: my %defaultchecked = (
12230: 'uselcmath' => 'on',
12231: 'usejsme' => 'on'
12232: );
12233: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 12234: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 12235: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
12236: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 12237: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 12238: my %staticdefaults = (
12239: anonsurvey_threshold => 10,
12240: uploadquota => 500,
1.160.6.57 raeburn 12241: postsubmit => 60,
1.160.6.70 raeburn 12242: mysqltables => 172800,
1.160.6.21 raeburn 12243: );
1.121 raeburn 12244:
12245: $defaultshash{'coursedefaults'} = {};
12246:
12247: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
12248: if ($domconfig{'coursedefaults'} eq '') {
12249: $domconfig{'coursedefaults'} = {};
12250: }
12251: }
12252:
12253: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
12254: foreach my $item (@toggles) {
12255: if ($defaultchecked{$item} eq 'on') {
12256: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12257: ($env{'form.'.$item} eq '0')) {
12258: $changes{$item} = 1;
1.160.6.16 raeburn 12259: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 12260: $changes{$item} = 1;
12261: }
12262: } elsif ($defaultchecked{$item} eq 'off') {
12263: if (($domconfig{'coursedefaults'}{$item} eq '') &&
12264: ($env{'form.'.$item} eq '1')) {
12265: $changes{$item} = 1;
12266: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
12267: $changes{$item} = 1;
12268: }
12269: }
12270: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
12271: }
1.160.6.21 raeburn 12272: foreach my $item (@numbers) {
12273: my ($currdef,$newdef);
1.160.6.26 raeburn 12274: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 12275: if ($item eq 'anonsurvey_threshold') {
12276: $currdef = $domconfig{'coursedefaults'}{$item};
12277: $newdef =~ s/\D//g;
12278: if ($newdef eq '' || $newdef < 1) {
12279: $newdef = 1;
12280: }
12281: $defaultshash{'coursedefaults'}{$item} = $newdef;
12282: } else {
1.160.6.70 raeburn 12283: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
12284: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
12285: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 12286: }
12287: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 12288: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 12289: }
12290: if ($currdef ne $newdef) {
12291: my $staticdef;
12292: if ($item eq 'anonsurvey_threshold') {
12293: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
12294: $changes{$item} = 1;
12295: }
1.160.6.70 raeburn 12296: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
12297: my $setting = $1;
12298: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
12299: $changes{$setting} = 1;
1.160.6.21 raeburn 12300: }
12301: }
1.139 raeburn 12302: }
12303: }
1.160.6.64 raeburn 12304: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
12305: my @currclonecode;
12306: if (ref($currclone) eq 'HASH') {
12307: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
12308: @currclonecode = @{$currclone->{'instcode'}};
12309: }
12310: }
12311: my $newclone;
12312: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
12313: $newclone = $env{'form.canclone'};
12314: }
12315: if ($newclone eq 'instcode') {
12316: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
12317: my (%codedefaults,@code_order,@clonecode);
12318: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
12319: \@code_order);
12320: foreach my $item (@code_order) {
12321: if (grep(/^\Q$item\E$/,@newcodes)) {
12322: push(@clonecode,$item);
12323: }
12324: }
12325: if (@clonecode) {
12326: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
12327: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
12328: if (@diffs) {
12329: $changes{'canclone'} = 1;
12330: }
12331: } else {
12332: $newclone eq '';
12333: }
12334: } elsif ($newclone ne '') {
12335: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
12336: }
12337: if ($newclone ne $currclone) {
12338: $changes{'canclone'} = 1;
12339: }
1.160.6.57 raeburn 12340: my %credits;
12341: foreach my $type (@types) {
12342: unless ($type eq 'community') {
12343: $credits{$type} = $env{'form.'.$type.'_credits'};
12344: $credits{$type} =~ s/[^\d.]+//g;
12345: }
12346: }
12347: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
12348: ($env{'form.coursecredits'} eq '1')) {
12349: $changes{'coursecredits'} = 1;
12350: foreach my $type (keys(%credits)) {
12351: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12352: }
12353: } else {
12354: if ($env{'form.coursecredits'} eq '1') {
12355: foreach my $type (@types) {
12356: unless ($type eq 'community') {
12357: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
12358: $changes{'coursecredits'} = 1;
12359: }
12360: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
12361: }
12362: }
12363: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12364: foreach my $type (@types) {
12365: unless ($type eq 'community') {
12366: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
12367: $changes{'coursecredits'} = 1;
12368: last;
12369: }
12370: }
12371: }
12372: }
12373: }
12374: if ($env{'form.postsubmit'} eq '1') {
12375: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
12376: my %currtimeout;
12377: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12378: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
12379: $changes{'postsubmit'} = 1;
12380: }
12381: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12382: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
12383: }
12384: } else {
12385: $changes{'postsubmit'} = 1;
12386: }
12387: foreach my $type (@types) {
12388: my $timeout = $env{'form.'.$type.'_timeout'};
12389: $timeout =~ s/\D//g;
12390: if ($timeout == $staticdefaults{'postsubmit'}) {
12391: $timeout = '';
12392: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
12393: $timeout = '0';
12394: }
12395: unless ($timeout eq '') {
12396: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
12397: }
12398: if (exists($currtimeout{$type})) {
12399: if ($timeout ne $currtimeout{$type}) {
12400: $changes{'postsubmit'} = 1;
12401: }
12402: } elsif ($timeout ne '') {
12403: $changes{'postsubmit'} = 1;
12404: }
12405: }
12406: } else {
12407: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
12408: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12409: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
12410: $changes{'postsubmit'} = 1;
12411: }
12412: } else {
12413: $changes{'postsubmit'} = 1;
12414: }
1.160.6.16 raeburn 12415: }
1.121 raeburn 12416: }
12417: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12418: $dom);
12419: if ($putresult eq 'ok') {
12420: if (keys(%changes) > 0) {
1.160.6.27 raeburn 12421: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 12422: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 12423: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 12424: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 12425: foreach my $item ('uselcmath','usejsme') {
12426: if ($changes{$item}) {
12427: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
12428: }
1.160.6.16 raeburn 12429: }
12430: if ($changes{'coursecredits'}) {
12431: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 12432: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
12433: $domdefaults{$type.'credits'} =
12434: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
12435: }
12436: }
12437: }
12438: if ($changes{'postsubmit'}) {
12439: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12440: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
12441: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12442: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
12443: $domdefaults{$type.'postsubtimeout'} =
12444: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12445: }
12446: }
1.160.6.16 raeburn 12447: }
12448: }
1.160.6.21 raeburn 12449: if ($changes{'uploadquota'}) {
12450: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
12451: foreach my $type (@types) {
12452: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
12453: }
12454: }
12455: }
1.160.6.64 raeburn 12456: if ($changes{'canclone'}) {
12457: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12458: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12459: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
12460: if (@clonecodes) {
12461: $domdefaults{'canclone'} = join('+',@clonecodes);
12462: }
12463: }
12464: } else {
12465: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
12466: }
12467: }
1.121 raeburn 12468: my $cachetime = 24*60*60;
12469: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12470: if (ref($lastactref) eq 'HASH') {
12471: $lastactref->{'domdefaults'} = 1;
12472: }
1.121 raeburn 12473: }
12474: $resulttext = &mt('Changes made:').'<ul>';
12475: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 12476: if ($item eq 'uselcmath') {
1.121 raeburn 12477: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 12478: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 12479: } else {
1.160.6.57 raeburn 12480: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
12481: }
12482: } elsif ($item eq 'usejsme') {
12483: if ($env{'form.'.$item} eq '1') {
12484: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
12485: } else {
12486: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 12487: }
1.139 raeburn 12488: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 12489: $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 12490: } elsif ($item eq 'uploadquota') {
12491: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
12492: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
12493: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
12494: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 12495: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
12496:
1.160.6.21 raeburn 12497: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
12498: '</ul>'.
12499: '</li>';
12500: } else {
12501: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
12502: }
1.160.6.70 raeburn 12503: } elsif ($item eq 'mysqltables') {
12504: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
12505: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
12506: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
12507: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
12508: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
12509: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
12510: '</ul>'.
12511: '</li>';
12512: } else {
12513: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
12514: }
1.160.6.57 raeburn 12515: } elsif ($item eq 'postsubmit') {
12516: if ($domdefaults{'postsubmit'} eq 'off') {
12517: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
12518: } else {
12519: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
12520: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12521: $resulttext .= &mt('durations:').'<ul>';
12522: foreach my $type (@types) {
12523: $resulttext .= '<li>';
12524: my $timeout;
12525: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12526: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12527: }
12528: my $display;
12529: if ($timeout eq '0') {
12530: $display = &mt('unlimited');
12531: } elsif ($timeout eq '') {
12532: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
12533: } else {
12534: $display = &mt('[quant,_1,second]',$timeout);
12535: }
12536: if ($type eq 'community') {
12537: $resulttext .= &mt('Communities');
12538: } elsif ($type eq 'official') {
12539: $resulttext .= &mt('Official courses');
12540: } elsif ($type eq 'unofficial') {
12541: $resulttext .= &mt('Unofficial courses');
12542: } elsif ($type eq 'textbook') {
12543: $resulttext .= &mt('Textbook courses');
12544: }
12545: $resulttext .= ' -- '.$display.'</li>';
12546: }
12547: $resulttext .= '</ul>';
12548: }
12549: $resulttext .= '</li>';
12550: }
1.160.6.16 raeburn 12551: } elsif ($item eq 'coursecredits') {
12552: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12553: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 12554: ($domdefaults{'unofficialcredits'} eq '') &&
12555: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 12556: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12557: } else {
12558: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
12559: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
12560: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 12561: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 12562: '</ul>'.
12563: '</li>';
12564: }
12565: } else {
12566: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12567: }
1.160.6.64 raeburn 12568: } elsif ($item eq 'canclone') {
12569: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12570: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12571: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
12572: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
12573: }
12574: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
12575: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
12576: } else {
12577: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
12578: }
1.140 raeburn 12579: }
1.121 raeburn 12580: }
12581: $resulttext .= '</ul>';
12582: } else {
12583: $resulttext = &mt('No changes made to course defaults');
12584: }
12585: } else {
12586: $resulttext = '<span class="LC_error">'.
12587: &mt('An error occurred: [_1]',$putresult).'</span>';
12588: }
12589: return $resulttext;
12590: }
12591:
1.160.6.37 raeburn 12592: sub modify_selfenrollment {
12593: my ($dom,$lastactref,%domconfig) = @_;
12594: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
12595: my @types = ('official','unofficial','community','textbook');
12596: my %titles = &tool_titles();
12597: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12598: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
12599: $ordered{'default'} = ['types','registered','approval','limit'];
12600:
12601: my (%roles,%shown,%toplevel);
12602: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12603:
12604: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12605: if ($domconfig{'selfenrollment'} eq '') {
12606: $domconfig{'selfenrollment'} = {};
12607: }
12608: }
12609: %toplevel = (
12610: admin => 'Configuration Rights',
12611: default => 'Default settings',
12612: validation => 'Validation of self-enrollment requests',
12613: );
12614: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
12615:
12616: if (ref($ordered{'admin'}) eq 'ARRAY') {
12617: foreach my $item (@{$ordered{'admin'}}) {
12618: foreach my $type (@types) {
12619: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12620: $selfenrollhash{'admin'}{$type}{$item} = 1;
12621: } else {
12622: $selfenrollhash{'admin'}{$type}{$item} = 0;
12623: }
12624: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12625: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12626: if ($selfenrollhash{'admin'}{$type}{$item} ne
12627: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12628: push(@{$changes{'admin'}{$type}},$item);
12629: }
12630: } else {
12631: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12632: push(@{$changes{'admin'}{$type}},$item);
12633: }
12634: }
12635: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12636: push(@{$changes{'admin'}{$type}},$item);
12637: }
12638: }
12639: }
12640: }
12641:
12642: foreach my $item (@{$ordered{'default'}}) {
12643: foreach my $type (@types) {
12644: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12645: if ($item eq 'types') {
12646: unless (($value eq 'all') || ($value eq 'dom')) {
12647: $value = '';
12648: }
12649: } elsif ($item eq 'registered') {
12650: unless ($value eq '1') {
12651: $value = 0;
12652: }
12653: } elsif ($item eq 'approval') {
12654: unless ($value =~ /^[012]$/) {
12655: $value = 0;
12656: }
12657: } else {
12658: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12659: $value = 'none';
12660: }
12661: }
12662: $selfenrollhash{'default'}{$type}{$item} = $value;
12663: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12664: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12665: if ($selfenrollhash{'default'}{$type}{$item} ne
12666: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12667: push(@{$changes{'default'}{$type}},$item);
12668: }
12669: } else {
12670: push(@{$changes{'default'}{$type}},$item);
12671: }
12672: } else {
12673: push(@{$changes{'default'}{$type}},$item);
12674: }
12675: if ($item eq 'limit') {
12676: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12677: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12678: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12679: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12680: }
12681: } else {
12682: $selfenrollhash{'default'}{$type}{'cap'} = '';
12683: }
12684: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12685: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12686: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12687: push(@{$changes{'default'}{$type}},'cap');
12688: }
12689: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12690: push(@{$changes{'default'}{$type}},'cap');
12691: }
12692: }
12693: }
12694: }
12695:
12696: foreach my $item (@{$itemsref}) {
12697: if ($item eq 'fields') {
12698: my @changed;
12699: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12700: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12701: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12702: }
12703: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12704: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12705: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12706: $domconfig{'selfenrollment'}{'validation'}{$item});
12707: } else {
12708: @changed = @{$selfenrollhash{'validation'}{$item}};
12709: }
12710: } else {
12711: @changed = @{$selfenrollhash{'validation'}{$item}};
12712: }
12713: if (@changed) {
12714: if ($selfenrollhash{'validation'}{$item}) {
12715: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12716: } else {
12717: $changes{'validation'}{$item} = &mt('None');
12718: }
12719: }
12720: } else {
12721: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12722: if ($item eq 'markup') {
12723: if ($env{'form.selfenroll_validation_'.$item}) {
12724: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12725: }
12726: }
12727: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12728: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12729: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12730: }
12731: }
12732: }
12733: }
12734:
12735: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12736: $dom);
12737: if ($putresult eq 'ok') {
12738: if (keys(%changes) > 0) {
12739: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12740: $resulttext = &mt('Changes made:').'<ul>';
12741: foreach my $key ('admin','default','validation') {
12742: if (ref($changes{$key}) eq 'HASH') {
12743: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12744: if ($key eq 'validation') {
12745: foreach my $item (@{$itemsref}) {
12746: if (exists($changes{$key}{$item})) {
12747: if ($item eq 'markup') {
12748: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12749: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12750: } else {
12751: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12752: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12753: }
12754: }
12755: }
12756: } else {
12757: foreach my $type (@types) {
12758: if ($type eq 'community') {
12759: $roles{'1'} = &mt('Community personnel');
12760: } else {
12761: $roles{'1'} = &mt('Course personnel');
12762: }
12763: if (ref($changes{$key}{$type}) eq 'ARRAY') {
12764: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12765: if ($key eq 'admin') {
12766: my @mgrdc = ();
12767: if (ref($ordered{$key}) eq 'ARRAY') {
12768: foreach my $item (@{$ordered{'admin'}}) {
12769: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12770: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12771: push(@mgrdc,$item);
12772: }
12773: }
12774: }
12775: if (@mgrdc) {
12776: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12777: } else {
12778: delete($domdefaults{$type.'selfenrolladmdc'});
12779: }
12780: }
12781: } else {
12782: if (ref($ordered{$key}) eq 'ARRAY') {
12783: foreach my $item (@{$ordered{$key}}) {
12784: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12785: $domdefaults{$type.'selfenroll'.$item} =
12786: $selfenrollhash{$key}{$type}{$item};
12787: }
12788: }
12789: }
12790: }
12791: }
12792: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12793: foreach my $item (@{$ordered{$key}}) {
12794: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12795: $resulttext .= '<li>';
12796: if ($key eq 'admin') {
12797: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12798: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12799: } else {
12800: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12801: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12802: }
12803: $resulttext .= '</li>';
12804: }
12805: }
12806: $resulttext .= '</ul></li>';
12807: }
12808: }
12809: $resulttext .= '</ul></li>';
12810: }
12811: }
1.160.6.84.4. (raeburn 12812:): }
12813:): if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12814:): my $cachetime = 24*60*60;
12815:): &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12816:): if (ref($lastactref) eq 'HASH') {
12817:): $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 12818: }
12819: }
12820: $resulttext .= '</ul>';
12821: } else {
12822: $resulttext = &mt('No changes made to self-enrollment settings');
12823: }
12824: } else {
12825: $resulttext = '<span class="LC_error">'.
12826: &mt('An error occurred: [_1]',$putresult).'</span>';
12827: }
12828: return $resulttext;
12829: }
12830:
1.137 raeburn 12831: sub modify_usersessions {
1.160.6.27 raeburn 12832: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12833: my @hostingtypes = ('version','excludedomain','includedomain');
12834: my @offloadtypes = ('primary','default');
12835: my %types = (
12836: remote => \@hostingtypes,
12837: hosted => \@hostingtypes,
12838: spares => \@offloadtypes,
12839: );
12840: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12841: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 12842: my (%by_ip,%by_location,@intdoms);
12843: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
12844: my @locations = sort(keys(%by_location));
1.137 raeburn 12845: my (%defaultshash,%changes);
12846: foreach my $prefix (@prefixes) {
12847: $defaultshash{'usersessions'}{$prefix} = {};
12848: }
1.160.6.27 raeburn 12849: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12850: my $resulttext;
1.138 raeburn 12851: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12852: foreach my $prefix (@prefixes) {
1.145 raeburn 12853: next if ($prefix eq 'spares');
12854: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12855: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12856: if ($type eq 'version') {
12857: my $value = $env{'form.'.$prefix.'_'.$type};
12858: my $okvalue;
12859: if ($value ne '') {
12860: if (grep(/^\Q$value\E$/,@lcversions)) {
12861: $okvalue = $value;
12862: }
12863: }
12864: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12865: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12866: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12867: if ($inuse == 0) {
12868: $changes{$prefix}{$type} = 1;
12869: } else {
12870: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12871: $changes{$prefix}{$type} = 1;
12872: }
12873: if ($okvalue ne '') {
12874: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12875: }
12876: }
12877: } else {
12878: if (($inuse == 1) && ($okvalue ne '')) {
12879: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12880: $changes{$prefix}{$type} = 1;
12881: }
12882: }
12883: } else {
12884: if (($inuse == 1) && ($okvalue ne '')) {
12885: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12886: $changes{$prefix}{$type} = 1;
12887: }
12888: }
12889: } else {
12890: if (($inuse == 1) && ($okvalue ne '')) {
12891: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12892: $changes{$prefix}{$type} = 1;
12893: }
12894: }
12895: } else {
12896: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12897: my @okvals;
12898: foreach my $val (@vals) {
1.138 raeburn 12899: if ($val =~ /:/) {
12900: my @items = split(/:/,$val);
12901: foreach my $item (@items) {
12902: if (ref($by_location{$item}) eq 'ARRAY') {
12903: push(@okvals,$item);
12904: }
12905: }
12906: } else {
12907: if (ref($by_location{$val}) eq 'ARRAY') {
12908: push(@okvals,$val);
12909: }
1.137 raeburn 12910: }
12911: }
12912: @okvals = sort(@okvals);
12913: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12914: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12915: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12916: if ($inuse == 0) {
12917: $changes{$prefix}{$type} = 1;
12918: } else {
12919: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12920: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12921: if (@changed > 0) {
12922: $changes{$prefix}{$type} = 1;
12923: }
12924: }
12925: } else {
12926: if ($inuse == 1) {
12927: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12928: $changes{$prefix}{$type} = 1;
12929: }
12930: }
12931: } else {
12932: if ($inuse == 1) {
12933: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12934: $changes{$prefix}{$type} = 1;
12935: }
12936: }
12937: } else {
12938: if ($inuse == 1) {
12939: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12940: $changes{$prefix}{$type} = 1;
12941: }
12942: }
12943: }
12944: }
12945: }
1.145 raeburn 12946:
12947: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12948: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12949: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12950: my $savespares;
12951:
12952: foreach my $lonhost (sort(keys(%servers))) {
12953: my $serverhomeID =
12954: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12955: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12956: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12957: my %spareschg;
12958: foreach my $type (@{$types{'spares'}}) {
12959: my @okspares;
12960: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12961: foreach my $server (@checked) {
1.152 raeburn 12962: if (&Apache::lonnet::hostname($server) ne '') {
12963: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12964: unless (grep(/^\Q$server\E$/,@okspares)) {
12965: push(@okspares,$server);
12966: }
1.145 raeburn 12967: }
12968: }
12969: }
12970: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12971: my $newspare;
1.152 raeburn 12972: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12973: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12974: $newspare = $new;
12975: }
12976: }
1.152 raeburn 12977: my @spares;
12978: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12979: @spares = sort(@okspares,$newspare);
12980: } else {
12981: @spares = sort(@okspares);
12982: }
12983: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12984: if (ref($spareid{$lonhost}) eq 'HASH') {
12985: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12986: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12987: if (@diffs > 0) {
12988: $spareschg{$type} = 1;
12989: }
12990: }
12991: }
12992: }
12993: if (keys(%spareschg) > 0) {
12994: $changes{'spares'}{$lonhost} = \%spareschg;
12995: }
12996: }
1.160.6.61 raeburn 12997: $defaultshash{'usersessions'}{'offloadnow'} = {};
12998: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12999: my @okoffload;
13000: if (@offloadnow) {
13001: foreach my $server (@offloadnow) {
13002: if (&Apache::lonnet::hostname($server) ne '') {
13003: unless (grep(/^\Q$server\E$/,@okoffload)) {
13004: push(@okoffload,$server);
13005: }
13006: }
13007: }
13008: if (@okoffload) {
13009: foreach my $lonhost (@okoffload) {
13010: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
13011: }
13012: }
13013: }
1.145 raeburn 13014: if (ref($domconfig{'usersessions'}) eq 'HASH') {
13015: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
13016: if (ref($changes{'spares'}) eq 'HASH') {
13017: if (keys(%{$changes{'spares'}}) > 0) {
13018: $savespares = 1;
13019: }
13020: }
13021: } else {
13022: $savespares = 1;
13023: }
1.160.6.61 raeburn 13024: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
13025: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
13026: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
13027: $changes{'offloadnow'} = 1;
13028: last;
13029: }
13030: }
13031: unless ($changes{'offloadnow'}) {
13032: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
13033: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
13034: $changes{'offloadnow'} = 1;
13035: last;
13036: }
13037: }
13038: }
13039: } elsif (@okoffload) {
13040: $changes{'offloadnow'} = 1;
13041: }
13042: } elsif (@okoffload) {
13043: $changes{'offloadnow'} = 1;
1.145 raeburn 13044: }
1.147 raeburn 13045: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
13046: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 13047: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13048: $dom);
13049: if ($putresult eq 'ok') {
13050: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13051: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
13052: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
13053: }
13054: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
13055: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
13056: }
1.160.6.61 raeburn 13057: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13058: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
13059: }
1.137 raeburn 13060: }
13061: my $cachetime = 24*60*60;
13062: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 13063: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 13064: if (ref($lastactref) eq 'HASH') {
13065: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 13066: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 13067: }
1.147 raeburn 13068: if (keys(%changes) > 0) {
13069: my %lt = &usersession_titles();
13070: $resulttext = &mt('Changes made:').'<ul>';
13071: foreach my $prefix (@prefixes) {
13072: if (ref($changes{$prefix}) eq 'HASH') {
13073: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
13074: if ($prefix eq 'spares') {
13075: if (ref($changes{$prefix}) eq 'HASH') {
13076: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
13077: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 13078: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 13079: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
13080: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 13081: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
13082: foreach my $type (@{$types{$prefix}}) {
13083: if ($changes{$prefix}{$lonhost}{$type}) {
13084: my $offloadto = &mt('None');
13085: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
13086: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
13087: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
13088: }
1.145 raeburn 13089: }
1.147 raeburn 13090: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 13091: }
1.137 raeburn 13092: }
13093: }
1.147 raeburn 13094: $resulttext .= '</li>';
1.137 raeburn 13095: }
13096: }
1.147 raeburn 13097: } else {
13098: foreach my $type (@{$types{$prefix}}) {
13099: if (defined($changes{$prefix}{$type})) {
13100: my $newvalue;
13101: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
13102: if (ref($defaultshash{'usersessions'}{$prefix})) {
13103: if ($type eq 'version') {
13104: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
13105: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
13106: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
13107: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
13108: }
1.145 raeburn 13109: }
13110: }
13111: }
1.147 raeburn 13112: if ($newvalue eq '') {
13113: if ($type eq 'version') {
13114: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
13115: } else {
13116: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
13117: }
1.145 raeburn 13118: } else {
1.147 raeburn 13119: if ($type eq 'version') {
13120: $newvalue .= ' '.&mt('(or later)');
13121: }
13122: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 13123: }
1.137 raeburn 13124: }
13125: }
13126: }
1.147 raeburn 13127: $resulttext .= '</ul>';
1.137 raeburn 13128: }
13129: }
1.160.6.61 raeburn 13130: if ($changes{'offloadnow'}) {
13131: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
13132: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
13133: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
13134: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
13135: $resulttext .= '<li>'.$lonhost.'</li>';
13136: }
13137: $resulttext .= '</ul>';
13138: } else {
13139: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
13140: }
13141: } else {
13142: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
13143: }
13144: }
1.147 raeburn 13145: $resulttext .= '</ul>';
13146: } else {
13147: $resulttext = $nochgmsg;
1.137 raeburn 13148: }
13149: } else {
13150: $resulttext = '<span class="LC_error">'.
13151: &mt('An error occurred: [_1]',$putresult).'</span>';
13152: }
13153: } else {
1.147 raeburn 13154: $resulttext = $nochgmsg;
1.137 raeburn 13155: }
13156: return $resulttext;
13157: }
13158:
1.150 raeburn 13159: sub modify_loadbalancing {
13160: my ($dom,%domconfig) = @_;
13161: my $primary_id = &Apache::lonnet::domain($dom,'primary');
13162: my $intdom = &Apache::lonnet::internet_dom($primary_id);
13163: my ($othertitle,$usertypes,$types) =
13164: &Apache::loncommon::sorted_inst_types($dom);
13165: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 13166: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 13167: my @sparestypes = ('primary','default');
13168: my %typetitles = &sparestype_titles();
13169: my $resulttext;
1.160.6.7 raeburn 13170: my (%currbalancer,%currtargets,%currrules,%existing);
13171: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13172: %existing = %{$domconfig{'loadbalancing'}};
13173: }
13174: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
13175: \%currtargets,\%currrules);
13176: my ($saveloadbalancing,%defaultshash,%changes);
13177: my ($alltypes,$othertypes,$titles) =
13178: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
13179: my %ruletitles = &offloadtype_text();
13180: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
13181: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
13182: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
13183: if ($balancer eq '') {
13184: next;
13185: }
13186: if (!exists($servers{$balancer})) {
13187: if (exists($currbalancer{$balancer})) {
13188: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 13189: }
1.160.6.7 raeburn 13190: next;
13191: }
13192: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
13193: push(@{$changes{'delete'}},$balancer);
13194: next;
13195: }
13196: if (!exists($currbalancer{$balancer})) {
13197: push(@{$changes{'add'}},$balancer);
13198: }
13199: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
13200: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
13201: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
13202: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
13203: $saveloadbalancing = 1;
13204: }
13205: foreach my $sparetype (@sparestypes) {
13206: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
13207: my @offloadto;
13208: foreach my $target (@targets) {
13209: if (($servers{$target}) && ($target ne $balancer)) {
13210: if ($sparetype eq 'default') {
13211: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
13212: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 13213: }
13214: }
1.160.6.7 raeburn 13215: unless(grep(/^\Q$target\E$/,@offloadto)) {
13216: push(@offloadto,$target);
13217: }
1.150 raeburn 13218: }
13219: }
1.160.6.76 raeburn 13220: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
13221: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
13222: push(@offloadto,$balancer);
13223: }
13224: }
13225: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 13226: }
1.160.6.7 raeburn 13227: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 13228: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 13229: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
13230: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 13231: if (@targetdiffs > 0) {
1.160.6.7 raeburn 13232: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13233: }
1.160.6.7 raeburn 13234: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13235: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13236: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 13237: }
13238: }
13239: }
13240: } else {
1.160.6.7 raeburn 13241: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
13242: foreach my $sparetype (@sparestypes) {
13243: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13244: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13245: $changes{'curr'}{$balancer}{'targets'} = 1;
13246: }
1.150 raeburn 13247: }
13248: }
1.160.6.7 raeburn 13249: }
1.150 raeburn 13250: }
13251: my $ishomedom;
1.160.6.7 raeburn 13252: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
13253: $ishomedom = 1;
1.150 raeburn 13254: }
13255: if (ref($alltypes) eq 'ARRAY') {
13256: foreach my $type (@{$alltypes}) {
13257: my $rule;
1.160.6.7 raeburn 13258: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 13259: (!$ishomedom)) {
1.160.6.7 raeburn 13260: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
13261: }
13262: if ($rule eq 'specific') {
1.160.6.55 raeburn 13263: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
13264: if (exists($servers{$specifiedhost})) {
13265: $rule = $specifiedhost;
13266: }
1.150 raeburn 13267: }
1.160.6.7 raeburn 13268: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
13269: if (ref($currrules{$balancer}) eq 'HASH') {
13270: if ($rule ne $currrules{$balancer}{$type}) {
13271: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13272: }
13273: } elsif ($rule ne '') {
1.160.6.7 raeburn 13274: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 13275: }
13276: }
13277: }
1.160.6.7 raeburn 13278: }
13279: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
13280: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
13281: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
13282: $defaultshash{'loadbalancing'} = {};
13283: }
13284: my $putresult = &Apache::lonnet::put_dom('configuration',
13285: \%defaultshash,$dom);
13286: if ($putresult eq 'ok') {
13287: if (keys(%changes) > 0) {
1.160.6.54 raeburn 13288: my %toupdate;
1.160.6.7 raeburn 13289: if (ref($changes{'delete'}) eq 'ARRAY') {
13290: foreach my $balancer (sort(@{$changes{'delete'}})) {
13291: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 13292: $toupdate{$balancer} = 1;
1.150 raeburn 13293: }
1.160.6.7 raeburn 13294: }
13295: if (ref($changes{'add'}) eq 'ARRAY') {
13296: foreach my $balancer (sort(@{$changes{'add'}})) {
13297: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 13298: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 13299: }
13300: }
13301: if (ref($changes{'curr'}) eq 'HASH') {
13302: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 13303: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 13304: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
13305: if ($changes{'curr'}{$balancer}{'targets'}) {
13306: my %offloadstr;
13307: foreach my $sparetype (@sparestypes) {
13308: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13309: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
13310: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13311: }
13312: }
1.150 raeburn 13313: }
1.160.6.7 raeburn 13314: if (keys(%offloadstr) == 0) {
13315: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 13316: } else {
1.160.6.7 raeburn 13317: my $showoffload;
13318: foreach my $sparetype (@sparestypes) {
13319: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
13320: if (defined($offloadstr{$sparetype})) {
13321: $showoffload .= $offloadstr{$sparetype};
13322: } else {
13323: $showoffload .= &mt('None');
13324: }
13325: $showoffload .= (' 'x3);
13326: }
13327: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 13328: }
13329: }
13330: }
1.160.6.7 raeburn 13331: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
13332: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
13333: foreach my $type (@{$alltypes}) {
13334: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
13335: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13336: my $balancetext;
13337: if ($rule eq '') {
13338: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 13339: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 13340: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
13341: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 13342: foreach my $sparetype (@sparestypes) {
13343: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
13344: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
13345: }
13346: }
1.160.6.55 raeburn 13347: foreach my $item (@{$alltypes}) {
13348: next if ($item =~ /^_LC_ipchange/);
13349: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
13350: if ($hasrule eq 'homeserver') {
13351: map { $toupdate{$_} = 1; } (keys(%libraryservers));
13352: } else {
13353: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
13354: if ($servers{$hasrule}) {
13355: $toupdate{$hasrule} = 1;
13356: }
13357: }
13358: }
13359: }
13360: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
13361: $balancetext = $ruletitles{$rule};
13362: } else {
13363: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
13364: $balancetext = $ruletitles{'particular'}.' '.$receiver;
13365: if ($receiver) {
13366: $toupdate{$receiver};
13367: }
13368: }
13369: } else {
13370: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 13371: }
1.160.6.7 raeburn 13372: } else {
13373: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
13374: }
1.160.6.26 raeburn 13375: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 13376: }
13377: }
13378: }
13379: }
1.160.6.54 raeburn 13380: if (keys(%toupdate)) {
13381: my %thismachine;
13382: my $updatedhere;
13383: my $cachetime = 60*60*24;
13384: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
13385: foreach my $lonhost (keys(%toupdate)) {
13386: if ($thismachine{$lonhost}) {
13387: unless ($updatedhere) {
13388: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
13389: $defaultshash{'loadbalancing'},
13390: $cachetime);
13391: $updatedhere = 1;
13392: }
13393: } else {
13394: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
13395: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
13396: }
13397: }
13398: }
1.150 raeburn 13399: }
1.160.6.7 raeburn 13400: }
13401: if ($resulttext ne '') {
13402: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 13403: } else {
13404: $resulttext = $nochgmsg;
13405: }
13406: } else {
1.160.6.7 raeburn 13407: $resulttext = $nochgmsg;
1.150 raeburn 13408: }
13409: } else {
1.160.6.7 raeburn 13410: $resulttext = '<span class="LC_error">'.
13411: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 13412: }
13413: } else {
1.160.6.7 raeburn 13414: $resulttext = $nochgmsg;
1.150 raeburn 13415: }
13416: return $resulttext;
13417: }
13418:
1.48 raeburn 13419: sub recurse_check {
13420: my ($chkcats,$categories,$depth,$name) = @_;
13421: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
13422: my $chg = 0;
13423: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
13424: my $category = $chkcats->[$depth]{$name}[$j];
13425: my $item;
13426: if ($category eq '') {
13427: $chg ++;
13428: } else {
13429: my $deeper = $depth + 1;
13430: $item = &escape($category).':'.&escape($name).':'.$depth;
13431: if ($chg) {
13432: $categories->{$item} -= $chg;
13433: }
13434: &recurse_check($chkcats,$categories,$deeper,$category);
13435: $deeper --;
13436: }
13437: }
13438: }
13439: return;
13440: }
13441:
13442: sub recurse_cat_deletes {
13443: my ($item,$coursecategories,$deletions) = @_;
13444: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13445: my $subdepth = $depth + 1;
13446: if (ref($coursecategories) eq 'HASH') {
13447: foreach my $subitem (keys(%{$coursecategories})) {
13448: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
13449: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
13450: delete($coursecategories->{$subitem});
13451: $deletions->{$subitem} = 1;
13452: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 13453: }
1.48 raeburn 13454: }
13455: }
13456: return;
13457: }
13458:
1.125 raeburn 13459: sub active_dc_picker {
1.160.6.16 raeburn 13460: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 13461: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 13462: my @domcoord = keys(%domcoords);
13463: if (keys(%currhash)) {
13464: foreach my $dc (keys(%currhash)) {
13465: unless (exists($domcoords{$dc})) {
13466: push(@domcoord,$dc);
13467: }
13468: }
13469: }
13470: @domcoord = sort(@domcoord);
13471: my $numdcs = scalar(@domcoord);
13472: my $rows = 0;
13473: my $table;
1.125 raeburn 13474: if ($numdcs > 1) {
1.160.6.16 raeburn 13475: $table = '<table>';
13476: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 13477: my $rem = $i%($numinrow);
13478: if ($rem == 0) {
13479: if ($i > 0) {
1.160.6.16 raeburn 13480: $table .= '</tr>';
1.125 raeburn 13481: }
1.160.6.16 raeburn 13482: $table .= '<tr>';
13483: $rows ++;
1.125 raeburn 13484: }
1.160.6.16 raeburn 13485: my $check = '';
13486: if ($inputtype eq 'radio') {
13487: if (keys(%currhash) == 0) {
13488: if (!$i) {
13489: $check = ' checked="checked"';
13490: }
13491: } elsif (exists($currhash{$domcoord[$i]})) {
13492: $check = ' checked="checked"';
13493: }
13494: } else {
13495: if (exists($currhash{$domcoord[$i]})) {
13496: $check = ' checked="checked"';
1.125 raeburn 13497: }
13498: }
1.160.6.16 raeburn 13499: if ($i == @domcoord - 1) {
1.125 raeburn 13500: my $colsleft = $numinrow - $rem;
13501: if ($colsleft > 1) {
1.160.6.16 raeburn 13502: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 13503: } else {
1.160.6.16 raeburn 13504: $table .= '<td class="LC_left_item">';
1.125 raeburn 13505: }
13506: } else {
1.160.6.16 raeburn 13507: $table .= '<td class="LC_left_item">';
13508: }
13509: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
13510: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
13511: $table .= '<span class="LC_nobreak"><label>'.
13512: '<input type="'.$inputtype.'" name="'.$name.'"'.
13513: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
13514: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 13515: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 13516: }
1.160.6.33 raeburn 13517: $table .= '</label></span></td>';
1.125 raeburn 13518: }
1.160.6.16 raeburn 13519: $table .= '</tr></table>';
13520: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 13521: my ($dcname,$dcdom) = split(':',$domcoord[0]);
13522: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 13523: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 13524: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 13525: if ($user ne $dcname.':'.$dcdom) {
13526: $table .= ' ('.$dcname.':'.$dcdom.')';
13527: }
1.160.6.16 raeburn 13528: } else {
13529: my $check;
13530: if (exists($currhash{$domcoord[0]})) {
13531: $check = ' checked="checked"';
13532: }
1.160.6.50 raeburn 13533: $table = '<span class="LC_nobreak"><label>'.
13534: '<input type="checkbox" name="'.$name.'" '.
13535: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 13536: if ($user ne $dcname.':'.$dcdom) {
13537: $table .= ' ('.$dcname.':'.$dcdom.')';
13538: }
13539: $table .= '</label></span>';
1.160.6.16 raeburn 13540: $rows ++;
13541: }
1.125 raeburn 13542: }
1.160.6.16 raeburn 13543: return ($numdcs,$table,$rows);
1.125 raeburn 13544: }
13545:
1.137 raeburn 13546: sub usersession_titles {
13547: return &Apache::lonlocal::texthash(
13548: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
13549: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 13550: spares => 'Servers offloaded to, when busy',
1.137 raeburn 13551: version => 'LON-CAPA version requirement',
1.138 raeburn 13552: excludedomain => 'Allow all, but exclude specific domains',
13553: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 13554: primary => 'Primary (checked first)',
1.154 raeburn 13555: default => 'Default',
1.137 raeburn 13556: );
13557: }
13558:
1.152 raeburn 13559: sub id_for_thisdom {
13560: my (%servers) = @_;
13561: my %altids;
13562: foreach my $server (keys(%servers)) {
13563: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
13564: if ($serverhome ne $server) {
13565: $altids{$serverhome} = $server;
13566: }
13567: }
13568: return %altids;
13569: }
13570:
1.150 raeburn 13571: sub count_servers {
13572: my ($currbalancer,%servers) = @_;
13573: my (@spares,$numspares);
13574: foreach my $lonhost (sort(keys(%servers))) {
13575: next if ($currbalancer eq $lonhost);
13576: push(@spares,$lonhost);
13577: }
13578: if ($currbalancer) {
13579: $numspares = scalar(@spares);
13580: } else {
13581: $numspares = scalar(@spares) - 1;
13582: }
13583: return ($numspares,@spares);
13584: }
13585:
13586: sub lonbalance_targets_js {
1.160.6.7 raeburn 13587: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13588: my $select = &mt('Select');
13589: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13590: if (ref($servers) eq 'HASH') {
13591: $alltargets = join("','",sort(keys(%{$servers})));
13592: my @homedoms;
13593: foreach my $server (sort(keys(%{$servers}))) {
13594: if (&Apache::lonnet::host_domain($server) eq $dom) {
13595: push(@homedoms,'1');
13596: } else {
13597: push(@homedoms,'0');
13598: }
13599: }
13600: $allishome = join("','",@homedoms);
13601: }
13602: if (ref($types) eq 'ARRAY') {
13603: if (@{$types} > 0) {
13604: @alltypes = @{$types};
13605: }
13606: }
13607: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13608: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 13609: my (%currbalancer,%currtargets,%currrules,%existing);
13610: if (ref($settings) eq 'HASH') {
13611: %existing = %{$settings};
13612: }
13613: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13614: \%currtargets,\%currrules);
13615: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13616: return <<"END";
13617:
13618: <script type="text/javascript">
13619: // <![CDATA[
13620:
1.160.6.7 raeburn 13621: currBalancers = new Array('$balancers');
13622:
13623: function toggleTargets(balnum) {
13624: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13625: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13626: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13627: var prevbalancer = prevhostitem.value;
13628: var baltotal = document.getElementById('loadbalancing_total').value;
13629: prevhostitem.value = balancer;
13630: if (prevbalancer != '') {
13631: var prevIdx = currBalancers.indexOf(prevbalancer);
13632: if (prevIdx != -1) {
13633: currBalancers.splice(prevIdx,1);
13634: }
13635: }
1.150 raeburn 13636: if (balancer == '') {
1.160.6.7 raeburn 13637: hideSpares(balnum);
1.150 raeburn 13638: } else {
1.160.6.7 raeburn 13639: var currIdx = currBalancers.indexOf(balancer);
13640: if (currIdx == -1) {
13641: currBalancers.push(balancer);
13642: }
1.150 raeburn 13643: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 13644: var ishomedom = homedoms[lonhostitem.selectedIndex];
13645: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13646: }
1.160.6.7 raeburn 13647: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13648: return;
13649: }
13650:
1.160.6.7 raeburn 13651: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13652: var alltargets = new Array('$alltargets');
13653: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13654: var offloadtypes = new Array('primary','default');
13655:
1.160.6.7 raeburn 13656: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13657: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13658:
1.151 raeburn 13659: for (var i=0; i<offloadtypes.length; i++) {
13660: var count = 0;
13661: for (var j=0; j<alltargets.length; j++) {
13662: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 13663: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13664: item.value = alltargets[j];
13665: item.style.textAlign='left';
13666: item.style.textFace='normal';
13667: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13668: if (currBalancers.indexOf(alltargets[j]) == -1) {
13669: item.disabled = '';
13670: } else {
13671: item.disabled = 'disabled';
13672: item.checked = false;
13673: }
1.151 raeburn 13674: count ++;
13675: }
1.150 raeburn 13676: }
13677: }
1.151 raeburn 13678: for (var k=0; k<insttypes.length; k++) {
13679: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13680: if (ishomedom == 1) {
1.160.6.7 raeburn 13681: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13682: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13683: } else {
1.160.6.7 raeburn 13684: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13685: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13686: }
13687: } else {
1.160.6.7 raeburn 13688: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13689: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13690: }
1.151 raeburn 13691: if ((insttypes[k] != '_LC_external') &&
13692: ((insttypes[k] != '_LC_internetdom') ||
13693: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 13694: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13695: item.options.length = 0;
13696: item.options[0] = new Option("","",true,true);
13697: var idx = 0;
1.151 raeburn 13698: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 13699: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13700: idx ++;
13701: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13702: }
13703: }
13704: }
13705: }
13706: return;
13707: }
13708:
1.160.6.7 raeburn 13709: function hideSpares(balnum) {
1.150 raeburn 13710: var alltargets = new Array('$alltargets');
13711: var insttypes = new Array('$allinsttypes');
13712: var offloadtypes = new Array('primary','default');
13713:
1.160.6.7 raeburn 13714: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13715: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13716:
13717: var total = alltargets.length - 1;
13718: for (var i=0; i<offloadtypes; i++) {
13719: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 13720: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13721: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13722: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13723: }
1.150 raeburn 13724: }
13725: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 13726: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13727: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13728: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 13729: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13730: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13731: }
13732: }
13733: return;
13734: }
13735:
1.160.6.7 raeburn 13736: function checkOffloads(item,balnum,type) {
1.150 raeburn 13737: var alltargets = new Array('$alltargets');
13738: var offloadtypes = new Array('primary','default');
13739: if (item.checked) {
13740: var total = alltargets.length - 1;
13741: var other;
13742: if (type == offloadtypes[0]) {
1.151 raeburn 13743: other = offloadtypes[1];
1.150 raeburn 13744: } else {
1.151 raeburn 13745: other = offloadtypes[0];
1.150 raeburn 13746: }
13747: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 13748: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13749: if (server == item.value) {
1.160.6.7 raeburn 13750: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13751: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13752: }
13753: }
13754: }
13755: }
13756: return;
13757: }
13758:
1.160.6.7 raeburn 13759: function singleServerToggle(balnum,type) {
13760: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13761: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 13762: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13763: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13764:
13765: } else {
1.160.6.7 raeburn 13766: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13767: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13768: }
13769: return;
13770: }
13771:
1.160.6.7 raeburn 13772: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13773: if (type == '_LC_external') {
1.160.6.26 raeburn 13774: return;
1.150 raeburn 13775: }
1.160.6.7 raeburn 13776: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13777: for (var i=0; i<typesRules.length; i++) {
13778: if (formname.elements[typesRules[i]].checked) {
13779: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 13780: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13781: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13782: } else {
1.160.6.7 raeburn 13783: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13784: }
13785: }
13786: }
13787: return;
13788: }
13789:
13790: function balancerDeleteChange(balnum) {
13791: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13792: var baltotal = document.getElementById('loadbalancing_total').value;
13793: var addtarget;
13794: var removetarget;
13795: var action = 'delete';
13796: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13797: var lonhost = hostitem.value;
13798: var currIdx = currBalancers.indexOf(lonhost);
13799: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13800: if (currIdx != -1) {
13801: currBalancers.splice(currIdx,1);
13802: }
13803: addtarget = lonhost;
13804: } else {
13805: if (currIdx == -1) {
13806: currBalancers.push(lonhost);
13807: }
13808: removetarget = lonhost;
13809: action = 'undelete';
13810: }
13811: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13812: }
13813: return;
13814: }
13815:
13816: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13817: if (baltotal > 1) {
13818: var offloadtypes = new Array('primary','default');
13819: var alltargets = new Array('$alltargets');
13820: var insttypes = new Array('$allinsttypes');
13821: for (var i=0; i<baltotal; i++) {
13822: if (i != balnum) {
13823: for (var j=0; j<offloadtypes.length; j++) {
13824: var total = alltargets.length - 1;
13825: for (var k=0; k<total; k++) {
13826: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13827: var server = serveritem.value;
13828: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13829: if (server == addtarget) {
13830: serveritem.disabled = '';
13831: }
13832: }
13833: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13834: if (server == removetarget) {
13835: serveritem.disabled = 'disabled';
13836: serveritem.checked = false;
13837: }
13838: }
13839: }
13840: }
13841: for (var j=0; j<insttypes.length; j++) {
13842: if (insttypes[j] != '_LC_external') {
13843: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13844: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13845: var currSel = singleserver.selectedIndex;
13846: var currVal = singleserver.options[currSel].value;
13847: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13848: var numoptions = singleserver.options.length;
13849: var needsnew = 1;
13850: for (var k=0; k<numoptions; k++) {
13851: if (singleserver.options[k] == addtarget) {
13852: needsnew = 0;
13853: break;
13854: }
13855: }
13856: if (needsnew == 1) {
13857: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13858: }
13859: }
13860: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13861: singleserver.options.length = 0;
13862: if ((currVal) && (currVal != removetarget)) {
13863: singleserver.options[0] = new Option("","",false,false);
13864: } else {
13865: singleserver.options[0] = new Option("","",true,true);
13866: }
13867: var idx = 0;
13868: for (var m=0; m<alltargets.length; m++) {
13869: if (currBalancers.indexOf(alltargets[m]) == -1) {
13870: idx ++;
13871: if (currVal == alltargets[m]) {
13872: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13873: } else {
13874: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13875: }
13876: }
13877: }
13878: }
13879: }
13880: }
13881: }
1.150 raeburn 13882: }
13883: }
13884: }
13885: return;
13886: }
13887:
1.152 raeburn 13888: // ]]>
13889: </script>
13890:
13891: END
13892: }
13893:
13894: sub new_spares_js {
13895: my @sparestypes = ('primary','default');
13896: my $types = join("','",@sparestypes);
13897: my $select = &mt('Select');
13898: return <<"END";
13899:
13900: <script type="text/javascript">
13901: // <![CDATA[
13902:
13903: function updateNewSpares(formname,lonhost) {
13904: var types = new Array('$types');
13905: var include = new Array();
13906: var exclude = new Array();
13907: for (var i=0; i<types.length; i++) {
13908: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13909: for (var j=0; j<spareboxes.length; j++) {
13910: if (formname.elements[spareboxes[j]].checked) {
13911: exclude.push(formname.elements[spareboxes[j]].value);
13912: } else {
13913: include.push(formname.elements[spareboxes[j]].value);
13914: }
13915: }
13916: }
13917: for (var i=0; i<types.length; i++) {
13918: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13919: var selIdx = newSpare.selectedIndex;
13920: var currnew = newSpare.options[selIdx].value;
13921: var okSpares = new Array();
13922: for (var j=0; j<newSpare.options.length; j++) {
13923: var possible = newSpare.options[j].value;
13924: if (possible != '') {
13925: if (exclude.indexOf(possible) == -1) {
13926: okSpares.push(possible);
13927: } else {
13928: if (currnew == possible) {
13929: selIdx = 0;
13930: }
13931: }
13932: }
13933: }
13934: for (var k=0; k<include.length; k++) {
13935: if (okSpares.indexOf(include[k]) == -1) {
13936: okSpares.push(include[k]);
13937: }
13938: }
13939: okSpares.sort();
13940: newSpare.options.length = 0;
13941: if (selIdx == 0) {
13942: newSpare.options[0] = new Option("$select","",true,true);
13943: } else {
13944: newSpare.options[0] = new Option("$select","",false,false);
13945: }
13946: for (var m=0; m<okSpares.length; m++) {
13947: var idx = m+1;
13948: var selThis = 0;
13949: if (selIdx != 0) {
13950: if (okSpares[m] == currnew) {
13951: selThis = 1;
13952: }
13953: }
13954: if (selThis == 1) {
13955: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13956: } else {
13957: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13958: }
13959: }
13960: }
13961: return;
13962: }
13963:
13964: function checkNewSpares(lonhost,type) {
13965: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13966: var chosen = newSpare.options[newSpare.selectedIndex].value;
13967: if (chosen != '') {
13968: var othertype;
13969: var othernewSpare;
13970: if (type == 'primary') {
13971: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13972: }
13973: if (type == 'default') {
13974: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13975: }
13976: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13977: othernewSpare.selectedIndex = 0;
13978: }
13979: }
13980: return;
13981: }
13982:
13983: // ]]>
13984: </script>
13985:
13986: END
13987:
13988: }
13989:
13990: sub common_domprefs_js {
13991: return <<"END";
13992:
13993: <script type="text/javascript">
13994: // <![CDATA[
13995:
1.150 raeburn 13996: function getIndicesByName(formname,item) {
1.152 raeburn 13997: var group = new Array();
1.150 raeburn 13998: for (var i=0;i<formname.elements.length;i++) {
13999: if (formname.elements[i].name == item) {
1.152 raeburn 14000: group.push(formname.elements[i].id);
1.150 raeburn 14001: }
14002: }
1.152 raeburn 14003: return group;
1.150 raeburn 14004: }
14005:
14006: // ]]>
14007: </script>
14008:
14009: END
1.152 raeburn 14010:
1.150 raeburn 14011: }
14012:
1.160.6.5 raeburn 14013: sub recaptcha_js {
14014: my %lt = &captcha_phrases();
14015: return <<"END";
14016:
14017: <script type="text/javascript">
14018: // <![CDATA[
14019:
14020: function updateCaptcha(caller,context) {
14021: var privitem;
14022: var pubitem;
14023: var privtext;
14024: var pubtext;
1.160.6.69 raeburn 14025: var versionitem;
14026: var versiontext;
1.160.6.5 raeburn 14027: if (document.getElementById(context+'_recaptchapub')) {
14028: pubitem = document.getElementById(context+'_recaptchapub');
14029: } else {
14030: return;
14031: }
14032: if (document.getElementById(context+'_recaptchapriv')) {
14033: privitem = document.getElementById(context+'_recaptchapriv');
14034: } else {
14035: return;
14036: }
14037: if (document.getElementById(context+'_recaptchapubtxt')) {
14038: pubtext = document.getElementById(context+'_recaptchapubtxt');
14039: } else {
14040: return;
14041: }
14042: if (document.getElementById(context+'_recaptchaprivtxt')) {
14043: privtext = document.getElementById(context+'_recaptchaprivtxt');
14044: } else {
14045: return;
14046: }
1.160.6.69 raeburn 14047: if (document.getElementById(context+'_recaptchaversion')) {
14048: versionitem = document.getElementById(context+'_recaptchaversion');
14049: } else {
14050: return;
14051: }
14052: if (document.getElementById(context+'_recaptchavertxt')) {
14053: versiontext = document.getElementById(context+'_recaptchavertxt');
14054: } else {
14055: return;
14056: }
1.160.6.5 raeburn 14057: if (caller.checked) {
14058: if (caller.value == 'recaptcha') {
14059: pubitem.type = 'text';
14060: privitem.type = 'text';
14061: pubitem.size = '40';
14062: privitem.size = '40';
14063: pubtext.innerHTML = "$lt{'pub'}";
14064: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 14065: versionitem.type = 'text';
14066: versionitem.size = '3';
14067: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 14068: } else {
14069: pubitem.type = 'hidden';
14070: privitem.type = 'hidden';
1.160.6.69 raeburn 14071: versionitem.type = 'hidden';
1.160.6.5 raeburn 14072: pubtext.innerHTML = '';
14073: privtext.innerHTML = '';
1.160.6.69 raeburn 14074: versiontext.innerHTML = '';
1.160.6.5 raeburn 14075: }
14076: }
14077: return;
14078: }
14079:
14080: // ]]>
14081: </script>
14082:
14083: END
14084:
14085: }
14086:
1.160.6.40 raeburn 14087: sub toggle_display_js {
1.160.6.16 raeburn 14088: return <<"END";
14089:
14090: <script type="text/javascript">
14091: // <![CDATA[
14092:
1.160.6.40 raeburn 14093: function toggleDisplay(domForm,caller) {
14094: if (document.getElementById(caller)) {
14095: var divitem = document.getElementById(caller);
14096: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 14097: var checkval = 1;
14098: var dispval = 'block';
1.160.6.84.4. (raeburn 14099:): var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 14100: if (caller == 'emailoptions') {
14101: optionsElement = domForm.cancreate_email;
14102: }
1.160.6.57 raeburn 14103: if (caller == 'studentsubmission') {
14104: optionsElement = domForm.postsubmit;
14105: }
1.160.6.64 raeburn 14106: if (caller == 'cloneinstcode') {
14107: optionsElement = domForm.canclone;
14108: checkval = 'instcode';
14109: }
1.160.6.84.4. (raeburn 14110:): if (selfcreateRegExp.test(caller)) {
14111:): optionsElement = domForm.elements[caller];
14112:): checkval = 'other';
14113:): dispval = 'inline'
14114:): }
1.160.6.40 raeburn 14115: if (optionsElement.length) {
1.160.6.16 raeburn 14116: var currval;
1.160.6.40 raeburn 14117: for (var i=0; i<optionsElement.length; i++) {
14118: if (optionsElement[i].checked) {
14119: currval = optionsElement[i].value;
1.160.6.16 raeburn 14120: }
14121: }
1.160.6.64 raeburn 14122: if (currval == checkval) {
14123: divitem.style.display = dispval;
1.160.6.16 raeburn 14124: } else {
1.160.6.40 raeburn 14125: divitem.style.display = 'none';
1.160.6.16 raeburn 14126: }
14127: }
14128: }
14129: return;
14130: }
14131:
14132: // ]]>
14133: </script>
14134:
14135: END
14136:
14137: }
14138:
1.160.6.5 raeburn 14139: sub captcha_phrases {
14140: return &Apache::lonlocal::texthash (
14141: priv => 'Private key',
14142: pub => 'Public key',
14143: original => 'original (CAPTCHA)',
14144: recaptcha => 'successor (ReCAPTCHA)',
14145: notused => 'unused',
1.160.6.69 raeburn 14146: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 14147: );
14148: }
14149:
1.160.6.24 raeburn 14150: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 14151: my ($dom,$cachekeys) = @_;
14152: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 14153: my %servers = &Apache::lonnet::internet_dom_servers($dom);
14154: my %thismachine;
14155: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.81 raeburn 14156: my @posscached = ('domainconfig','domdefaults','usersessions','directorysrch');
1.160.6.61 raeburn 14157: if (keys(%servers)) {
1.160.6.24 raeburn 14158: foreach my $server (keys(%servers)) {
14159: next if ($thismachine{$server});
1.160.6.27 raeburn 14160: my @cached;
14161: foreach my $name (@posscached) {
14162: if ($cachekeys->{$name}) {
14163: push(@cached,&escape($name).':'.&escape($dom));
14164: }
14165: }
14166: if (@cached) {
14167: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
14168: }
1.160.6.24 raeburn 14169: }
14170: }
14171: return;
14172: }
14173:
1.3 raeburn 14174: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>