Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.87
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.87! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.86 2017/10/17 14:07:23 raeburn Exp $
1.160.6.40 raeburn 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
1.160.6.78 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
30: ##############################################################
31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 107: (official, unofficial, community, and textbook). In each case the radio buttons
108: allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 raeburn 169: use Apache::loncoursequeueadmin();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.1 raeburn 177:
1.155 raeburn 178: my $registered_cleanup;
179: my $modified_urls;
180:
1.1 raeburn 181: sub handler {
182: my $r=shift;
183: if ($r->header_only) {
184: &Apache::loncommon::content_type($r,'text/html');
185: $r->send_http_header;
186: return OK;
187: }
188:
1.91 raeburn 189: my $context = 'domain';
1.1 raeburn 190: my $dom = $env{'request.role.domain'};
1.5 albertel 191: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 192: if (&Apache::lonnet::allowed('mau',$dom)) {
193: &Apache::loncommon::content_type($r,'text/html');
194: $r->send_http_header;
195: } else {
196: $env{'user.error.msg'}=
197: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
198: return HTTP_NOT_ACCEPTABLE;
199: }
1.155 raeburn 200:
201: $registered_cleanup=0;
202: @{$modified_urls}=();
203:
1.1 raeburn 204: &Apache::lonhtmlcommon::clear_breadcrumbs();
205: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 206: ['phase','actions']);
1.30 raeburn 207: my $phase = 'pickactions';
1.3 raeburn 208: if ( exists($env{'form.phase'}) ) {
209: $phase = $env{'form.phase'};
210: }
1.150 raeburn 211: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 212: my %domconfig =
1.6 raeburn 213: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 214: 'quotas','autoenroll','autoupdate','autocreate',
215: 'directorysrch','usercreation','usermodification',
216: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 217: 'serverstatuses','requestcourses','helpsettings',
218: 'coursedefaults','usersessions','loadbalancing',
219: 'requestauthor','selfenrollment','inststatus'],$dom);
1.43 raeburn 220: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 221: 'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34 raeburn 222: 'usercreation','selfcreation','usermodification','scantron',
1.160.6.5 raeburn 223: 'requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 224: 'serverstatuses','helpsettings','coursedefaults',
225: 'selfenrollment','usersessions');
1.160.6.7 raeburn 226: my %existing;
227: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
228: %existing = %{$domconfig{'loadbalancing'}};
229: }
230: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 231: push(@prefs_order,'loadbalancing');
232: }
1.30 raeburn 233: my %prefs = (
234: 'rolecolors' =>
235: { text => 'Default color schemes',
1.67 raeburn 236: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 237: header => [{col1 => 'Student Settings',
238: col2 => '',},
239: {col1 => 'Coordinator Settings',
240: col2 => '',},
241: {col1 => 'Author Settings',
242: col2 => '',},
243: {col1 => 'Administrator Settings',
244: col2 => '',}],
1.160.6.37 raeburn 245: print => \&print_rolecolors,
246: modify => \&modify_rolecolors,
1.30 raeburn 247: },
1.110 raeburn 248: 'login' =>
1.30 raeburn 249: { text => 'Log-in page options',
1.67 raeburn 250: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 251: header => [{col1 => 'Log-in Page Items',
252: col2 => '',},
253: {col1 => 'Log-in Help',
1.160.6.56 raeburn 254: col2 => 'Value'},
255: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 256: col2 => 'Value'}],
1.160.6.37 raeburn 257: print => \&print_login,
258: modify => \&modify_login,
1.30 raeburn 259: },
1.43 raeburn 260: 'defaults' =>
1.160.6.40 raeburn 261: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 262: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 263: header => [{col1 => 'Setting',
1.160.6.40 raeburn 264: col2 => 'Value'},
1.160.6.80 raeburn 265: {col1 => 'Internal Authentication',
266: col2 => 'Value'},
1.160.6.40 raeburn 267: {col1 => 'Institutional user types',
268: col2 => 'Assignable to e-mail usernames'}],
1.160.6.37 raeburn 269: print => \&print_defaults,
270: modify => \&modify_defaults,
1.43 raeburn 271: },
1.30 raeburn 272: 'quotas' =>
1.160.6.20 raeburn 273: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 274: help => 'Domain_Configuration_Quotas',
1.77 raeburn 275: header => [{col1 => 'User affiliation',
1.72 raeburn 276: col2 => 'Available tools',
1.160.6.28 raeburn 277: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 278: print => \&print_quotas,
279: modify => \&modify_quotas,
1.30 raeburn 280: },
281: 'autoenroll' =>
282: { text => 'Auto-enrollment settings',
1.67 raeburn 283: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 284: header => [{col1 => 'Configuration setting',
285: col2 => 'Value(s)'}],
1.160.6.37 raeburn 286: print => \&print_autoenroll,
287: modify => \&modify_autoenroll,
1.30 raeburn 288: },
289: 'autoupdate' =>
290: { text => 'Auto-update settings',
1.67 raeburn 291: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 292: header => [{col1 => 'Setting',
293: col2 => 'Value',},
1.131 raeburn 294: {col1 => 'Setting',
295: col2 => 'Affiliation'},
1.43 raeburn 296: {col1 => 'User population',
1.160.6.35 raeburn 297: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 298: print => \&print_autoupdate,
299: modify => \&modify_autoupdate,
1.30 raeburn 300: },
1.125 raeburn 301: 'autocreate' =>
302: { text => 'Auto-course creation settings',
303: help => 'Domain_Configuration_Auto_Creation',
304: header => [{col1 => 'Configuration Setting',
305: col2 => 'Value',}],
1.160.6.37 raeburn 306: print => \&print_autocreate,
307: modify => \&modify_autocreate,
1.125 raeburn 308: },
1.30 raeburn 309: 'directorysrch' =>
1.160.6.72 raeburn 310: { text => 'Directory searches',
1.67 raeburn 311: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 312: header => [{col1 => 'Institutional Directory Setting',
313: col2 => 'Value',},
314: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 315: col2 => 'Value',}],
1.160.6.37 raeburn 316: print => \&print_directorysrch,
317: modify => \&modify_directorysrch,
1.30 raeburn 318: },
319: 'contacts' =>
1.160.6.78 raeburn 320: { text => 'E-mail addresses and helpform',
1.67 raeburn 321: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 322: header => [{col1 => 'Default e-mail addresses',
323: col2 => 'Value',},
324: {col1 => 'Recipient(s) for notifications',
325: col2 => 'Value',},
326: {col1 => 'Ask helpdesk form settings',
327: col2 => 'Value',},],
1.160.6.37 raeburn 328: print => \&print_contacts,
329: modify => \&modify_contacts,
1.30 raeburn 330: },
331: 'usercreation' =>
332: { text => 'User creation',
1.67 raeburn 333: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 334: header => [{col1 => 'Format rule type',
335: col2 => 'Format rules in force'},
1.34 raeburn 336: {col1 => 'User account creation',
337: col2 => 'Usernames which may be created',},
1.30 raeburn 338: {col1 => 'Context',
1.43 raeburn 339: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 340: print => \&print_usercreation,
341: modify => \&modify_usercreation,
1.30 raeburn 342: },
1.160.6.34 raeburn 343: 'selfcreation' =>
344: { text => 'Users self-creating accounts',
345: help => 'Domain_Configuration_Self_Creation',
346: header => [{col1 => 'Self-creation with institutional username',
347: col2 => 'Enabled?'},
348: {col1 => 'Institutional user type (login/SSO self-creation)',
349: col2 => 'Information user can enter'},
350: {col1 => 'Self-creation with e-mail as username',
351: col2 => 'Settings'}],
1.160.6.37 raeburn 352: print => \&print_selfcreation,
353: modify => \&modify_selfcreation,
1.160.6.34 raeburn 354: },
1.69 raeburn 355: 'usermodification' =>
1.33 raeburn 356: { text => 'User modification',
1.67 raeburn 357: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 358: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 359: col2 => 'User information updatable in author context'},
1.33 raeburn 360: {col1 => 'Target user has role',
1.160.6.35 raeburn 361: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 362: print => \&print_usermodification,
363: modify => \&modify_usermodification,
1.33 raeburn 364: },
1.69 raeburn 365: 'scantron' =>
1.95 www 366: { text => 'Bubblesheet format file',
1.67 raeburn 367: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 368: header => [ {col1 => 'Item',
369: col2 => '',
370: }],
1.160.6.37 raeburn 371: print => \&print_scantron,
372: modify => \&modify_scantron,
1.46 raeburn 373: },
1.86 raeburn 374: 'requestcourses' =>
375: {text => 'Request creation of courses',
376: help => 'Domain_Configuration_Request_Courses',
377: header => [{col1 => 'User affiliation',
1.102 raeburn 378: col2 => 'Availability/Processing of requests',},
379: {col1 => 'Setting',
1.160.6.30 raeburn 380: col2 => 'Value'},
381: {col1 => 'Available textbooks',
1.160.6.39 raeburn 382: col2 => ''},
1.160.6.46 raeburn 383: {col1 => 'Available templates',
384: col2 => ''},
1.160.6.39 raeburn 385: {col1 => 'Validation (not official courses)',
386: col2 => 'Value'},],
1.160.6.37 raeburn 387: print => \&print_quotas,
388: modify => \&modify_quotas,
1.86 raeburn 389: },
1.160.6.5 raeburn 390: 'requestauthor' =>
1.160.6.34 raeburn 391: {text => 'Request Authoring Space',
1.160.6.5 raeburn 392: help => 'Domain_Configuration_Request_Author',
393: header => [{col1 => 'User affiliation',
394: col2 => 'Availability/Processing of requests',},
395: {col1 => 'Setting',
396: col2 => 'Value'}],
1.160.6.37 raeburn 397: print => \&print_quotas,
398: modify => \&modify_quotas,
1.160.6.5 raeburn 399: },
1.69 raeburn 400: 'coursecategories' =>
1.120 raeburn 401: { text => 'Cataloging of courses/communities',
1.67 raeburn 402: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 403: header => [{col1 => 'Catalog type/availability',
404: col2 => '',},
405: {col1 => 'Category settings for standard catalog',
1.57 raeburn 406: col2 => '',},
407: {col1 => 'Categories',
408: col2 => '',
409: }],
1.160.6.37 raeburn 410: print => \&print_coursecategories,
411: modify => \&modify_coursecategories,
1.69 raeburn 412: },
413: 'serverstatuses' =>
1.77 raeburn 414: {text => 'Access to server status pages',
1.69 raeburn 415: help => 'Domain_Configuration_Server_Status',
416: header => [{col1 => 'Status Page',
417: col2 => 'Other named users',
418: col3 => 'Specific IPs',
419: }],
1.160.6.37 raeburn 420: print => \&print_serverstatuses,
421: modify => \&modify_serverstatuses,
1.69 raeburn 422: },
1.160.6.73 raeburn 423: 'helpsettings' =>
424: {text => 'Support settings',
425: help => 'Domain_Configuration_Help_Settings',
426: header => [{col1 => 'Help Page Settings (logged-in users)',
427: col2 => 'Value'},
428: {col1 => 'Helpdesk Roles',
429: col2 => 'Settings'},],
430: print => \&print_helpsettings,
431: modify => \&modify_helpsettings,
432: },
1.160.6.39 raeburn 433: 'coursedefaults' =>
1.160.6.16 raeburn 434: {text => 'Course/Community defaults',
435: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 436: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
437: col2 => 'Value',},
438: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 439: col2 => 'Value',},],
1.160.6.37 raeburn 440: print => \&print_coursedefaults,
441: modify => \&modify_coursedefaults,
442: },
1.160.6.39 raeburn 443: 'selfenrollment' =>
1.160.6.37 raeburn 444: {text => 'Self-enrollment in Course/Community',
445: help => 'Domain_Configuration_Selfenrollment',
446: header => [{col1 => 'Configuration Rights',
447: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
448: {col1 => 'Defaults',
449: col2 => 'Value'},
450: {col1 => 'Self-enrollment validation (optional)',
451: col2 => 'Value'},],
452: print => \&print_selfenrollment,
453: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 454: },
1.141 raeburn 455: 'usersessions' =>
1.145 raeburn 456: {text => 'User session hosting/offloading',
1.137 raeburn 457: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 458: header => [{col1 => 'Domain server',
459: col2 => 'Servers to offload sessions to when busy'},
460: {col1 => 'Hosting of users from other domains',
1.137 raeburn 461: col2 => 'Rules'},
462: {col1 => "Hosting domain's own users elsewhere",
463: col2 => 'Rules'}],
1.160.6.37 raeburn 464: print => \&print_usersessions,
465: modify => \&modify_usersessions,
1.137 raeburn 466: },
1.160.6.78 raeburn 467: 'loadbalancing' =>
1.160.6.7 raeburn 468: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 469: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 470: header => [{col1 => 'Balancers',
1.150 raeburn 471: col2 => 'Default destinations',
1.160.6.13 raeburn 472: col3 => 'User affiliation',
1.150 raeburn 473: col4 => 'Overrides'},
474: ],
1.160.6.37 raeburn 475: print => \&print_loadbalancing,
476: modify => \&modify_loadbalancing,
1.150 raeburn 477: },
1.3 raeburn 478: );
1.110 raeburn 479: if (keys(%servers) > 1) {
480: $prefs{'login'} = { text => 'Log-in page options',
481: help => 'Domain_Configuration_Login_Page',
482: header => [{col1 => 'Log-in Service',
483: col2 => 'Server Setting',},
484: {col1 => 'Log-in Page Items',
1.160.6.5 raeburn 485: col2 => ''},
486: {col1 => 'Log-in Help',
1.160.6.56 raeburn 487: col2 => 'Value'},
488: {col1 => 'Custom HTML in document head',
1.160.6.5 raeburn 489: col2 => 'Value'}],
1.160.6.37 raeburn 490: print => \&print_login,
491: modify => \&modify_login,
1.110 raeburn 492: };
493: }
1.160.6.13 raeburn 494:
1.6 raeburn 495: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 496: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 497: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 498: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 499: text=>"Settings to display/modify"});
1.9 raeburn 500: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 501:
1.3 raeburn 502: if ($phase eq 'process') {
1.160.6.27 raeburn 503: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
504: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 505: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 506: $r->rflush();
1.160.6.27 raeburn 507: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 508: }
1.30 raeburn 509: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 510: my $js = &recaptcha_js().
1.160.6.40 raeburn 511: &toggle_display_js();
1.160.6.7 raeburn 512: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 513: my ($othertitle,$usertypes,$types) =
514: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 515: $js .= &lonbalance_targets_js($dom,$types,\%servers,
516: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 517: &new_spares_js().
518: &common_domprefs_js().
519: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 520: }
1.160.6.30 raeburn 521: if (grep(/^requestcourses$/,@actions)) {
522: my $javascript_validations;
523: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
524: $js .= <<END;
525: <script type="text/javascript">
526: $javascript_validations
527: </script>
528: $coursebrowserjs
529: END
530: }
1.160.6.78 raeburn 531: if (grep(/^contacts$/,@actions)) {
532: $js .= &contacts_javascript();
533: }
1.150 raeburn 534: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 535: } else {
1.160.6.11 raeburn 536: # check if domconfig user exists for the domain.
537: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 538: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 539: &config_check($dom,$confname,$servadm);
540: unless ($configuserok eq 'ok') {
541: &Apache::lonconfigsettings::print_header($r,$phase,$context);
542: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
543: $confname).
544: '<br />'
545: );
546: if ($switchserver) {
547: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
548: '<br />'.
549: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
550: '<br />'.
551: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
552: '<br />'.
553: &mt('To do that now, use the following link: [_1]',$switchserver)
554: );
555: } else {
556: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
557: '<br />'.
558: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
559: );
560: }
561: $r->print(&Apache::loncommon::end_page());
562: return OK;
563: }
1.21 raeburn 564: if (keys(%domconfig) == 0) {
565: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 566: my @ids=&Apache::lonnet::current_machine_ids();
567: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 568: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 569: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 570: my $custom_img_count = 0;
571: foreach my $img (@loginimages) {
572: if ($designhash{$dom.'.login.'.$img} ne '') {
573: $custom_img_count ++;
574: }
575: }
576: foreach my $role (@roles) {
577: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
578: $custom_img_count ++;
579: }
580: }
581: if ($custom_img_count > 0) {
1.94 raeburn 582: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 583: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 584: $r->print(
585: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
586: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
587: &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
588: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
589: if ($switch_server) {
1.30 raeburn 590: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 591: }
1.91 raeburn 592: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 593: return OK;
594: }
595: }
596: }
1.91 raeburn 597: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 598: }
599: return OK;
600: }
601:
602: sub process_changes {
1.160.6.24 raeburn 603: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 604: my %domconfig;
605: if (ref($values) eq 'HASH') {
606: %domconfig = %{$values};
607: }
1.3 raeburn 608: my $output;
609: if ($action eq 'login') {
1.160.6.24 raeburn 610: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 611: } elsif ($action eq 'rolecolors') {
1.9 raeburn 612: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 613: $lastactref,%domconfig);
1.3 raeburn 614: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 615: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 616: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 617: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 618: } elsif ($action eq 'autoupdate') {
619: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 620: } elsif ($action eq 'autocreate') {
621: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 622: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 623: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 624: } elsif ($action eq 'usercreation') {
1.28 raeburn 625: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 626: } elsif ($action eq 'selfcreation') {
627: $output = &modify_selfcreation($dom,%domconfig);
1.33 raeburn 628: } elsif ($action eq 'usermodification') {
629: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 630: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 631: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 632: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 633: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 634: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 635: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 636: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 637: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 638: } elsif ($action eq 'serverstatuses') {
639: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 640: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 641: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 642: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 643: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 644: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 645: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 646: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 647: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 648: } elsif ($action eq 'selfenrollment') {
649: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 650: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 651: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 652: } elsif ($action eq 'loadbalancing') {
653: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 654: }
655: return $output;
656: }
657:
658: sub print_config_box {
1.9 raeburn 659: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 660: my $rowtotal = 0;
1.49 raeburn 661: my $output;
662: if ($action eq 'coursecategories') {
663: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 664: } elsif ($action eq 'defaults') {
665: $output = &defaults_javascript($settings);
1.160.6.73 raeburn 666: } elsif ($action eq 'helpsettings') {
667: my (%privs,%levelscurrent);
668: my %full=();
669: my %levels=(
670: course => {},
671: domain => {},
672: system => {},
673: );
674: my $context = 'domain';
675: my $crstype = 'Course';
676: my $formname = 'display';
677: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
678: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
679: $output =
680: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
681: \@templateroles);
1.91 raeburn 682: }
1.160.6.40 raeburn 683: $output .=
1.30 raeburn 684: '<table class="LC_nested_outer">
1.3 raeburn 685: <tr>
1.66 raeburn 686: <th align="left" valign="middle"><span class="LC_nobreak">'.
687: &mt($item->{text}).' '.
688: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
689: '</tr>';
1.30 raeburn 690: $rowtotal ++;
1.110 raeburn 691: my $numheaders = 1;
692: if (ref($item->{'header'}) eq 'ARRAY') {
693: $numheaders = scalar(@{$item->{'header'}});
694: }
695: if ($numheaders > 1) {
1.64 raeburn 696: my $colspan = '';
1.145 raeburn 697: my $rightcolspan = '';
1.160.6.42 raeburn 698: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 699: ($action eq 'directorysrch') ||
1.160.6.56 raeburn 700: (($action eq 'login') && ($numheaders < 4))) {
1.64 raeburn 701: $colspan = ' colspan="2"';
702: }
1.145 raeburn 703: if ($action eq 'usersessions') {
704: $rightcolspan = ' colspan="3"';
705: }
1.30 raeburn 706: $output .= '
1.3 raeburn 707: <tr>
708: <td>
709: <table class="LC_nested">
710: <tr class="LC_info_row">
1.59 bisitz 711: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 712: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 713: </tr>';
1.69 raeburn 714: $rowtotal ++;
1.160.6.37 raeburn 715: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 716: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 717: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78 raeburn 718: ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37 raeburn 719: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57 raeburn 720: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 721: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 722: } elsif ($action eq 'login') {
1.160.6.56 raeburn 723: if ($numheaders == 4) {
1.160.6.5 raeburn 724: $colspan = ' colspan="2"';
725: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
726: } else {
727: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
728: }
1.160.6.37 raeburn 729: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 730: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 731: } elsif ($action eq 'rolecolors') {
1.30 raeburn 732: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 733: }
1.30 raeburn 734: $output .= '
1.6 raeburn 735: </table>
736: </td>
737: </tr>
738: <tr>
739: <td>
740: <table class="LC_nested">
741: <tr class="LC_info_row">
1.160.6.37 raeburn 742: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 743: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 744: </tr>';
745: $rowtotal ++;
1.160.6.37 raeburn 746: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
747: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 748: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.80 raeburn 749: ($action eq 'contacts') || ($action eq 'defaults')) {
1.160.6.42 raeburn 750: if ($action eq 'coursecategories') {
751: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
752: $colspan = ' colspan="2"';
753: } else {
754: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
755: }
756: $output .= '
1.63 raeburn 757: </table>
758: </td>
759: </tr>
760: <tr>
761: <td>
762: <table class="LC_nested">
763: <tr class="LC_info_row">
764: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 765: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 766: </tr>'."\n";
767: if ($action eq 'coursecategories') {
768: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
769: } else {
770: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
771: }
1.63 raeburn 772: $rowtotal ++;
1.160.6.57 raeburn 773: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 774: ($action eq 'defaults') || ($action eq 'directorysrch') ||
775: ($action eq 'helpsettings')) {
1.160.6.37 raeburn 776: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 777: } elsif ($action eq 'login') {
1.160.6.56 raeburn 778: if ($numheaders == 4) {
1.160.6.5 raeburn 779: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
780: </table>
781: </td>
782: </tr>
783: <tr>
784: <td>
785: <table class="LC_nested">
786: <tr class="LC_info_row">
787: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 788: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 789: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
790: $rowtotal ++;
791: } else {
792: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
793: }
1.160.6.56 raeburn 794: $output .= '
795: </table>
796: </td>
797: </tr>
798: <tr>
799: <td>
800: <table class="LC_nested">
801: <tr class="LC_info_row">';
802: if ($numheaders == 4) {
803: $output .= '
804: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
805: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
806: </tr>';
807: } else {
808: $output .= '
809: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
810: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
811: </tr>';
812: }
813: $rowtotal ++;
814: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 815: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 816: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
817: $rowtotal ++;
818: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 819: </table>
820: </td>
821: </tr>
822: <tr>
823: <td>
824: <table class="LC_nested">
825: <tr class="LC_info_row">
826: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
827: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 828: &textbookcourses_javascript($settings).
829: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
830: </table>
831: </td>
832: </tr>
833: <tr>
834: <td>
835: <table class="LC_nested">
836: <tr class="LC_info_row">
837: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
838: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
839: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 840: </table>
841: </td>
842: </tr>
843: <tr>
844: <td>
845: <table class="LC_nested">
846: <tr class="LC_info_row">
1.160.6.46 raeburn 847: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
848: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 849: </tr>'.
850: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 851: } elsif ($action eq 'requestauthor') {
852: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 853: $rowtotal ++;
1.122 jms 854: } elsif ($action eq 'rolecolors') {
1.30 raeburn 855: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 856: </table>
857: </td>
858: </tr>
859: <tr>
860: <td>
861: <table class="LC_nested">
862: <tr class="LC_info_row">
1.69 raeburn 863: <td class="LC_left_item"'.$colspan.' valign="top">'.
864: &mt($item->{'header'}->[2]->{'col1'}).'</td>
865: <td class="LC_right_item" valign="top">'.
866: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 867: </tr>'.
1.30 raeburn 868: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 869: </table>
870: </td>
871: </tr>
872: <tr>
873: <td>
874: <table class="LC_nested">
875: <tr class="LC_info_row">
1.59 bisitz 876: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
877: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 878: </tr>'.
1.30 raeburn 879: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
880: $rowtotal += 2;
1.6 raeburn 881: }
1.3 raeburn 882: } else {
1.30 raeburn 883: $output .= '
1.3 raeburn 884: <tr>
885: <td>
886: <table class="LC_nested">
1.30 raeburn 887: <tr class="LC_info_row">';
1.160.6.72 raeburn 888: if ($action eq 'login') {
1.30 raeburn 889: $output .= '
1.59 bisitz 890: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 891: } elsif ($action eq 'serverstatuses') {
892: $output .= '
893: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
894: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
895:
1.6 raeburn 896: } else {
1.30 raeburn 897: $output .= '
1.69 raeburn 898: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
899: }
1.72 raeburn 900: if (defined($item->{'header'}->[0]->{'col3'})) {
901: $output .= '<td class="LC_left_item" valign="top">'.
902: &mt($item->{'header'}->[0]->{'col2'});
903: if ($action eq 'serverstatuses') {
904: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
905: }
1.69 raeburn 906: } else {
907: $output .= '<td class="LC_right_item" valign="top">'.
908: &mt($item->{'header'}->[0]->{'col2'});
909: }
910: $output .= '</td>';
911: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 912: if (defined($item->{'header'}->[0]->{'col4'})) {
913: $output .= '<td class="LC_left_item" valign="top">'.
914: &mt($item->{'header'}->[0]->{'col3'});
915: } else {
916: $output .= '<td class="LC_right_item" valign="top">'.
917: &mt($item->{'header'}->[0]->{'col3'});
918: }
1.69 raeburn 919: if ($action eq 'serverstatuses') {
920: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
921: }
922: $output .= '</td>';
1.6 raeburn 923: }
1.150 raeburn 924: if ($item->{'header'}->[0]->{'col4'}) {
925: $output .= '<td class="LC_right_item" valign="top">'.
926: &mt($item->{'header'}->[0]->{'col4'});
927: }
1.69 raeburn 928: $output .= '</tr>';
1.48 raeburn 929: $rowtotal ++;
1.160.6.5 raeburn 930: if ($action eq 'quotas') {
1.86 raeburn 931: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 932: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.78 raeburn 933: ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37 raeburn 934: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46 raeburn 935: } elsif ($action eq 'scantron') {
936: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121 raeburn 937: }
1.3 raeburn 938: }
1.30 raeburn 939: $output .= '
1.3 raeburn 940: </table>
941: </td>
942: </tr>
1.30 raeburn 943: </table><br />';
944: return ($output,$rowtotal);
1.1 raeburn 945: }
946:
1.3 raeburn 947: sub print_login {
1.160.6.5 raeburn 948: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 949: my ($css_class,$datatable);
1.6 raeburn 950: my %choices = &login_choices();
1.110 raeburn 951:
1.160.6.5 raeburn 952: if ($caller eq 'service') {
1.149 raeburn 953: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 954: my $choice = $choices{'disallowlogin'};
955: $css_class = ' class="LC_odd_row"';
1.128 raeburn 956: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 957: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 958: '<th>'.$choices{'server'}.'</th>'.
959: '<th>'.$choices{'serverpath'}.'</th>'.
960: '<th>'.$choices{'custompath'}.'</th>'.
961: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 962: my %disallowed;
963: if (ref($settings) eq 'HASH') {
964: if (ref($settings->{'loginvia'}) eq 'HASH') {
965: %disallowed = %{$settings->{'loginvia'}};
966: }
967: }
968: foreach my $lonhost (sort(keys(%servers))) {
969: my $direct = 'selected="selected"';
1.128 raeburn 970: if (ref($disallowed{$lonhost}) eq 'HASH') {
971: if ($disallowed{$lonhost}{'server'} ne '') {
972: $direct = '';
973: }
1.110 raeburn 974: }
1.115 raeburn 975: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 976: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 977: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
978: '</option>';
1.160.6.13 raeburn 979: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 980: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 981: my $selected = '';
1.128 raeburn 982: if (ref($disallowed{$lonhost}) eq 'HASH') {
983: if ($hostid eq $disallowed{$lonhost}{'server'}) {
984: $selected = 'selected="selected"';
985: }
1.110 raeburn 986: }
987: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
988: $servers{$hostid}.'</option>';
989: }
1.128 raeburn 990: $datatable .= '</select></td>'.
991: '<td><select name="'.$lonhost.'_serverpath">';
992: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
993: my $pathname = $path;
994: if ($path eq 'custom') {
995: $pathname = &mt('Custom Path').' ->';
996: }
997: my $selected = '';
998: if (ref($disallowed{$lonhost}) eq 'HASH') {
999: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1000: $selected = 'selected="selected"';
1001: }
1002: } elsif ($path eq '') {
1003: $selected = 'selected="selected"';
1004: }
1005: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1006: }
1007: $datatable .= '</select></td>';
1008: my ($custom,$exempt);
1009: if (ref($disallowed{$lonhost}) eq 'HASH') {
1010: $custom = $disallowed{$lonhost}{'custompath'};
1011: $exempt = $disallowed{$lonhost}{'exempt'};
1012: }
1013: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1014: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1015: '</tr>';
1.110 raeburn 1016: }
1017: $datatable .= '</table></td></tr>';
1018: return $datatable;
1.160.6.5 raeburn 1019: } elsif ($caller eq 'page') {
1020: my %defaultchecked = (
1021: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1022: 'helpdesk' => 'on',
1.160.6.5 raeburn 1023: 'adminmail' => 'off',
1024: 'newuser' => 'off',
1025: );
1.160.6.14 raeburn 1026: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1027: my (%checkedon,%checkedoff);
1.42 raeburn 1028: foreach my $item (@toggles) {
1.160.6.5 raeburn 1029: if ($defaultchecked{$item} eq 'on') {
1030: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1031: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1032: } elsif ($defaultchecked{$item} eq 'off') {
1033: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1034: $checkedon{$item} = ' ';
1035: }
1.1 raeburn 1036: }
1.160.6.5 raeburn 1037: my @images = ('img','logo','domlogo','login');
1038: my @logintext = ('textcol','bgcol');
1039: my @bgs = ('pgbg','mainbg','sidebg');
1040: my @links = ('link','alink','vlink');
1041: my %designhash = &Apache::loncommon::get_domainconf($dom);
1042: my %defaultdesign = %Apache::loncommon::defaultdesign;
1043: my (%is_custom,%designs);
1044: my %defaults = (
1045: font => $defaultdesign{'login.font'},
1046: );
1.6 raeburn 1047: foreach my $item (@images) {
1.160.6.5 raeburn 1048: $defaults{$item} = $defaultdesign{'login.'.$item};
1049: $defaults{'showlogo'}{$item} = 1;
1050: }
1051: foreach my $item (@bgs) {
1052: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1053: }
1.41 raeburn 1054: foreach my $item (@logintext) {
1.160.6.5 raeburn 1055: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1056: }
1.160.6.5 raeburn 1057: foreach my $item (@links) {
1058: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1059: }
1.160.6.5 raeburn 1060: if (ref($settings) eq 'HASH') {
1061: foreach my $item (@toggles) {
1062: if ($settings->{$item} eq '1') {
1063: $checkedon{$item} = ' checked="checked" ';
1064: $checkedoff{$item} = ' ';
1065: } elsif ($settings->{$item} eq '0') {
1066: $checkedoff{$item} = ' checked="checked" ';
1067: $checkedon{$item} = ' ';
1068: }
1.6 raeburn 1069: }
1.160.6.5 raeburn 1070: foreach my $item (@images) {
1071: if (defined($settings->{$item})) {
1072: $designs{$item} = $settings->{$item};
1073: $is_custom{$item} = 1;
1074: }
1075: if (defined($settings->{'showlogo'}{$item})) {
1076: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1077: }
1078: }
1079: foreach my $item (@logintext) {
1080: if ($settings->{$item} ne '') {
1081: $designs{'logintext'}{$item} = $settings->{$item};
1082: $is_custom{$item} = 1;
1083: }
1084: }
1085: if ($settings->{'font'} ne '') {
1086: $designs{'font'} = $settings->{'font'};
1087: $is_custom{'font'} = 1;
1088: }
1089: foreach my $item (@bgs) {
1090: if ($settings->{$item} ne '') {
1091: $designs{'bgs'}{$item} = $settings->{$item};
1092: $is_custom{$item} = 1;
1093: }
1094: }
1095: foreach my $item (@links) {
1096: if ($settings->{$item} ne '') {
1097: $designs{'links'}{$item} = $settings->{$item};
1098: $is_custom{$item} = 1;
1099: }
1100: }
1101: } else {
1102: if ($designhash{$dom.'.login.font'} ne '') {
1103: $designs{'font'} = $designhash{$dom.'.login.font'};
1104: $is_custom{'font'} = 1;
1105: }
1106: foreach my $item (@images) {
1107: if ($designhash{$dom.'.login.'.$item} ne '') {
1108: $designs{$item} = $designhash{$dom.'.login.'.$item};
1109: $is_custom{$item} = 1;
1110: }
1111: }
1112: foreach my $item (@bgs) {
1113: if ($designhash{$dom.'.login.'.$item} ne '') {
1114: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1115: $is_custom{$item} = 1;
1116: }
1117: }
1118: foreach my $item (@links) {
1119: if ($designhash{$dom.'.login.'.$item} ne '') {
1120: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1121: $is_custom{$item} = 1;
1122: }
1.6 raeburn 1123: }
1124: }
1.160.6.5 raeburn 1125: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1126: logo => 'Institution Logo',
1127: domlogo => 'Domain Logo',
1128: login => 'Login box');
1129: my $itemcount = 1;
1130: foreach my $item (@toggles) {
1131: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1132: $datatable .=
1133: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1134: '</td><td>'.
1135: '<span class="LC_nobreak"><label><input type="radio" name="'.
1136: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1137: '</label> <label><input type="radio" name="'.$item.'"'.
1138: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1139: '</tr>';
1140: $itemcount ++;
1.6 raeburn 1141: }
1.160.6.5 raeburn 1142: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1143: $datatable .= '</tr></table></td></tr>';
1144: } elsif ($caller eq 'help') {
1145: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1146: my $switchserver = &check_switchserver($dom,$confname);
1147: my $itemcount = 1;
1148: $defaulturl = '/adm/loginproblems.html';
1149: $defaulttype = 'default';
1150: %lt = &Apache::lonlocal::texthash (
1151: del => 'Delete?',
1152: rep => 'Replace:',
1153: upl => 'Upload:',
1154: default => 'Default',
1155: custom => 'Custom',
1156: );
1157: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1158: my @currlangs;
1159: if (ref($settings) eq 'HASH') {
1160: if (ref($settings->{'helpurl'}) eq 'HASH') {
1161: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1162: next if ($settings->{'helpurl'}{$key} eq '');
1163: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1164: $type{$key} = 'custom';
1165: unless ($key eq 'nolang') {
1166: push(@currlangs,$key);
1167: }
1168: }
1169: } elsif ($settings->{'helpurl'} ne '') {
1170: $type{'nolang'} = 'custom';
1171: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1172: }
1173: }
1.160.6.5 raeburn 1174: foreach my $lang ('nolang',sort(@currlangs)) {
1175: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1176: $datatable .= '<tr'.$css_class.'>';
1177: if ($url{$lang} eq '') {
1178: $url{$lang} = $defaulturl;
1179: }
1180: if ($type{$lang} eq '') {
1181: $type{$lang} = $defaulttype;
1182: }
1183: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1184: if ($lang eq 'nolang') {
1185: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1186: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1187: } else {
1188: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1189: $langchoices{$lang},
1190: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1191: }
1192: $datatable .= '</span></td>'."\n".
1193: '<td class="LC_left_item">';
1194: if ($type{$lang} eq 'custom') {
1195: $datatable .= '<span class="LC_nobreak"><label>'.
1196: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1197: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1198: } else {
1199: $datatable .= $lt{'upl'};
1200: }
1201: $datatable .='<br />';
1202: if ($switchserver) {
1203: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1204: } else {
1205: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1206: }
1.160.6.5 raeburn 1207: $datatable .= '</td></tr>';
1208: $itemcount ++;
1.6 raeburn 1209: }
1.160.6.5 raeburn 1210: my @addlangs;
1211: foreach my $lang (sort(keys(%langchoices))) {
1212: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1213: push(@addlangs,$lang);
1214: }
1215: if (@addlangs > 0) {
1216: my %toadd;
1217: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1218: $toadd{''} = &mt('Select');
1219: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1220: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1221: &mt('Add log-in help page for a specific language:').' '.
1222: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1223: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1224: if ($switchserver) {
1225: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1226: } else {
1227: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1228: }
1.160.6.5 raeburn 1229: $datatable .= '</td></tr>';
1230: $itemcount ++;
1.6 raeburn 1231: }
1.160.6.5 raeburn 1232: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1233: } elsif ($caller eq 'headtag') {
1234: my %domservers = &Apache::lonnet::get_servers($dom);
1235: my $choice = $choices{'headtag'};
1236: $css_class = ' class="LC_odd_row"';
1237: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1238: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1239: '<th>'.$choices{'current'}.'</th>'.
1240: '<th>'.$choices{'action'}.'</th>'.
1241: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1242: my (%currurls,%currexempt);
1243: if (ref($settings) eq 'HASH') {
1244: if (ref($settings->{'headtag'}) eq 'HASH') {
1245: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1246: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1247: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1248: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1249: }
1250: }
1251: }
1252: }
1253: my %lt = &Apache::lonlocal::texthash(
1254: del => 'Delete?',
1255: rep => 'Replace:',
1256: upl => 'Upload:',
1257: curr => 'View contents',
1258: none => 'None',
1259: );
1260: my $switchserver = &check_switchserver($dom,$confname);
1261: foreach my $lonhost (sort(keys(%domservers))) {
1262: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1263: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1264: if ($currurls{$lonhost}) {
1265: $datatable .= '<td class="LC_right_item"><a href="'.
1266: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1267: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1268: '">'.$lt{'curr'}.'</a></td>'.
1269: '<td><span class="LC_nobreak"><label>'.
1270: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1271: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1272: } else {
1273: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1274: }
1275: $datatable .='<br />';
1276: if ($switchserver) {
1277: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1278: } else {
1279: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1280: }
1.160.6.87! raeburn 1281: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1282: }
1283: $datatable .= '</table></td></tr>';
1.1 raeburn 1284: }
1.6 raeburn 1285: return $datatable;
1286: }
1287:
1288: sub login_choices {
1289: my %choices =
1290: &Apache::lonlocal::texthash (
1.116 bisitz 1291: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1292: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1293: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1294: disallowlogin => "Login page requests redirected",
1295: hostid => "Server",
1.128 raeburn 1296: server => "Redirect to:",
1297: serverpath => "Path",
1298: custompath => "Custom",
1299: exempt => "Exempt IP(s)",
1.110 raeburn 1300: directlogin => "No redirect",
1301: newuser => "Link to create a user account",
1302: img => "Header",
1303: logo => "Main Logo",
1304: domlogo => "Domain Logo",
1305: login => "Log-in Header",
1306: textcol => "Text color",
1307: bgcol => "Box color",
1308: bgs => "Background colors",
1309: links => "Link colors",
1310: font => "Font color",
1311: pgbg => "Header",
1312: mainbg => "Page",
1313: sidebg => "Login box",
1314: link => "Link",
1315: alink => "Active link",
1316: vlink => "Visited link",
1.160.6.56 raeburn 1317: headtag => "Custom markup",
1318: action => "Action",
1319: current => "Current",
1.6 raeburn 1320: );
1321: return %choices;
1322: }
1323:
1324: sub print_rolecolors {
1.30 raeburn 1325: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1326: my %choices = &color_font_choices();
1327: my @bgs = ('pgbg','tabbg','sidebg');
1328: my @links = ('link','alink','vlink');
1329: my @images = ('img');
1330: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1331: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1332: my %defaultdesign = %Apache::loncommon::defaultdesign;
1333: my (%is_custom,%designs);
1.160.6.22 raeburn 1334: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1335: if (ref($settings) eq 'HASH') {
1336: if (ref($settings->{$role}) eq 'HASH') {
1337: if ($settings->{$role}->{'img'} ne '') {
1338: $designs{'img'} = $settings->{$role}->{'img'};
1339: $is_custom{'img'} = 1;
1340: }
1341: if ($settings->{$role}->{'font'} ne '') {
1342: $designs{'font'} = $settings->{$role}->{'font'};
1343: $is_custom{'font'} = 1;
1344: }
1.97 tempelho 1345: if ($settings->{$role}->{'fontmenu'} ne '') {
1346: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1347: $is_custom{'fontmenu'} = 1;
1348: }
1.6 raeburn 1349: foreach my $item (@bgs) {
1350: if ($settings->{$role}->{$item} ne '') {
1351: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1352: $is_custom{$item} = 1;
1353: }
1354: }
1355: foreach my $item (@links) {
1356: if ($settings->{$role}->{$item} ne '') {
1357: $designs{'links'}{$item} = $settings->{$role}->{$item};
1358: $is_custom{$item} = 1;
1359: }
1360: }
1361: }
1362: } else {
1363: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1364: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1365: $is_custom{'img'} = 1;
1366: }
1.97 tempelho 1367: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1368: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1369: $is_custom{'fontmenu'} = 1;
1370: }
1.6 raeburn 1371: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1372: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1373: $is_custom{'font'} = 1;
1374: }
1375: foreach my $item (@bgs) {
1376: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1377: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1378: $is_custom{$item} = 1;
1379:
1380: }
1381: }
1382: foreach my $item (@links) {
1383: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1384: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1385: $is_custom{$item} = 1;
1386: }
1387: }
1388: }
1389: my $itemcount = 1;
1.30 raeburn 1390: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1391: $datatable .= '</tr></table></td></tr>';
1392: return $datatable;
1393: }
1394:
1.160.6.22 raeburn 1395: sub role_defaults {
1396: my ($role,$bgs,$links,$images,$logintext) = @_;
1397: my %defaults;
1398: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1399: return %defaults;
1400: }
1401: my %defaultdesign = %Apache::loncommon::defaultdesign;
1402: if ($role eq 'login') {
1403: %defaults = (
1404: font => $defaultdesign{$role.'.font'},
1405: );
1406: if (ref($logintext) eq 'ARRAY') {
1407: foreach my $item (@{$logintext}) {
1408: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1409: }
1410: }
1411: foreach my $item (@{$images}) {
1412: $defaults{'showlogo'}{$item} = 1;
1413: }
1414: } else {
1415: %defaults = (
1416: img => $defaultdesign{$role.'.img'},
1417: font => $defaultdesign{$role.'.font'},
1418: fontmenu => $defaultdesign{$role.'.fontmenu'},
1419: );
1420: }
1421: foreach my $item (@{$bgs}) {
1422: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1423: }
1424: foreach my $item (@{$links}) {
1425: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1426: }
1427: foreach my $item (@{$images}) {
1428: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1429: }
1430: return %defaults;
1431: }
1432:
1.6 raeburn 1433: sub display_color_options {
1.9 raeburn 1434: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1435: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1436: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1437: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1438: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1439: '<td>'.$choices->{'font'}.'</td>';
1440: if (!$is_custom->{'font'}) {
1.160.6.87! raeburn 1441: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1442: } else {
1443: $datatable .= '<td> </td>';
1444: }
1.160.6.9 raeburn 1445: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1446:
1.8 raeburn 1447: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1448: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1449: ' value="'.$current_color.'" /> '.
1.160.6.87! raeburn 1450: ' </span></td></tr>';
1.107 raeburn 1451: unless ($role eq 'login') {
1452: $datatable .= '<tr'.$css_class.'>'.
1453: '<td>'.$choices->{'fontmenu'}.'</td>';
1454: if (!$is_custom->{'fontmenu'}) {
1.160.6.87! raeburn 1455: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1456: } else {
1457: $datatable .= '<td> </td>';
1458: }
1.160.6.22 raeburn 1459: $current_color = $designs->{'fontmenu'} ?
1460: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1461: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1462: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1463: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1464: ' value="'.$current_color.'" /> '.
1.160.6.87! raeburn 1465: ' </span></td></tr>';
1.97 tempelho 1466: }
1.9 raeburn 1467: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1468: foreach my $img (@{$images}) {
1.18 albertel 1469: $itemcount ++;
1.6 raeburn 1470: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1471: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1472: '<td>'.$choices->{$img};
1.41 raeburn 1473: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1474: if ($role eq 'login') {
1475: if ($img eq 'login') {
1476: $login_hdr_pick =
1.135 bisitz 1477: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1478: $logincolors =
1479: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1480: $designs,$defaults);
1.70 raeburn 1481: } elsif ($img ne 'domlogo') {
1482: $datatable.= &logo_display_options($img,$defaults,$designs);
1483: }
1484: }
1485: $datatable .= '</td>';
1.6 raeburn 1486: if ($designs->{$img} ne '') {
1487: $imgfile = $designs->{$img};
1.18 albertel 1488: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1489: } else {
1490: $imgfile = $defaults->{$img};
1491: }
1492: if ($imgfile) {
1.9 raeburn 1493: my ($showfile,$fullsize);
1494: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1495: my $urldir = $1;
1496: my $filename = $2;
1497: my @info = &Apache::lonnet::stat_file($designs->{$img});
1498: if (@info) {
1499: my $thumbfile = 'tn-'.$filename;
1500: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1501: if (@thumb) {
1502: $showfile = $urldir.'/'.$thumbfile;
1503: } else {
1504: $showfile = $imgfile;
1505: }
1506: } else {
1507: $showfile = '';
1508: }
1509: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1510: $showfile = $imgfile;
1.6 raeburn 1511: my $imgdir = $1;
1512: my $filename = $2;
1.159 raeburn 1513: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1514: $showfile = "/$imgdir/tn-".$filename;
1515: } else {
1.159 raeburn 1516: my $input = $londocroot.$imgfile;
1517: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1518: if (!-e $output) {
1.9 raeburn 1519: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1520: my ($fullwidth,$fullheight) = &check_dimensions($input);
1521: if ($fullwidth ne '' && $fullheight ne '') {
1522: if ($fullwidth > $width && $fullheight > $height) {
1523: my $size = $width.'x'.$height;
1524: system("convert -sample $size $input $output");
1.159 raeburn 1525: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1526: }
1527: }
1.6 raeburn 1528: }
1529: }
1.16 raeburn 1530: }
1.6 raeburn 1531: if ($showfile) {
1.40 raeburn 1532: if ($showfile =~ m{^/(adm|res)/}) {
1533: if ($showfile =~ m{^/res/}) {
1534: my $local_showfile =
1535: &Apache::lonnet::filelocation('',$showfile);
1536: &Apache::lonnet::repcopy($local_showfile);
1537: }
1538: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1539: }
1540: if ($imgfile) {
1541: if ($imgfile =~ m{^/(adm|res)/}) {
1542: if ($imgfile =~ m{^/res/}) {
1543: my $local_imgfile =
1544: &Apache::lonnet::filelocation('',$imgfile);
1545: &Apache::lonnet::repcopy($local_imgfile);
1546: }
1547: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1548: } else {
1549: $fullsize = $imgfile;
1550: }
1551: }
1.41 raeburn 1552: $datatable .= '<td>';
1553: if ($img eq 'login') {
1.135 bisitz 1554: $datatable .= $login_hdr_pick;
1555: }
1.41 raeburn 1556: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1557: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1558: } else {
1.160.6.22 raeburn 1559: $datatable .= '<td> </td><td class="LC_left_item">'.
1560: &mt('Upload:').'<br />';
1.6 raeburn 1561: }
1562: } else {
1.160.6.22 raeburn 1563: $datatable .= '<td> </td><td class="LC_left_item">'.
1564: &mt('Upload:').'<br />';
1.6 raeburn 1565: }
1.9 raeburn 1566: if ($switchserver) {
1567: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1568: } else {
1.135 bisitz 1569: if ($img ne 'login') { # suppress file selection for Log-in header
1570: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1571: }
1.9 raeburn 1572: }
1573: $datatable .= '</td></tr>';
1.6 raeburn 1574: }
1575: $itemcount ++;
1576: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1577: $datatable .= '<tr'.$css_class.'>'.
1578: '<td>'.$choices->{'bgs'}.'</td>';
1579: my $bgs_def;
1580: foreach my $item (@{$bgs}) {
1581: if (!$is_custom->{$item}) {
1.160.6.87! raeburn 1582: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1583: }
1584: }
1585: if ($bgs_def) {
1.8 raeburn 1586: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1587: } else {
1588: $datatable .= '<td> </td>';
1589: }
1590: $datatable .= '<td class="LC_right_item">'.
1591: '<table border="0"><tr>';
1.160.6.13 raeburn 1592:
1.6 raeburn 1593: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1594: $datatable .= '<td align="center">'.$choices->{$item};
1595: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1596: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1597: $datatable .= ' ';
1.6 raeburn 1598: }
1.160.6.9 raeburn 1599: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1600: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1601: }
1602: $datatable .= '</tr></table></td></tr>';
1603: $itemcount ++;
1604: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1605: $datatable .= '<tr'.$css_class.'>'.
1606: '<td>'.$choices->{'links'}.'</td>';
1607: my $links_def;
1608: foreach my $item (@{$links}) {
1609: if (!$is_custom->{$item}) {
1.160.6.87! raeburn 1610: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1611: }
1612: }
1613: if ($links_def) {
1.8 raeburn 1614: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1615: } else {
1616: $datatable .= '<td> </td>';
1617: }
1618: $datatable .= '<td class="LC_right_item">'.
1619: '<table border="0"><tr>';
1620: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1621: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1622: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1623: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1624: $datatable.=' ';
1.6 raeburn 1625: }
1.160.6.9 raeburn 1626: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1627: '" /></td>';
1628: }
1.30 raeburn 1629: $$rowtotal += $itemcount;
1.3 raeburn 1630: return $datatable;
1631: }
1632:
1.70 raeburn 1633: sub logo_display_options {
1634: my ($img,$defaults,$designs) = @_;
1635: my $checkedon;
1636: if (ref($defaults) eq 'HASH') {
1637: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1638: if ($defaults->{'showlogo'}{$img}) {
1639: $checkedon = 'checked="checked" ';
1640: }
1641: }
1642: }
1643: if (ref($designs) eq 'HASH') {
1644: if (ref($designs->{'showlogo'}) eq 'HASH') {
1645: if (defined($designs->{'showlogo'}{$img})) {
1646: if ($designs->{'showlogo'}{$img} == 0) {
1647: $checkedon = '';
1648: } elsif ($designs->{'showlogo'}{$img} == 1) {
1649: $checkedon = 'checked="checked" ';
1650: }
1651: }
1652: }
1653: }
1654: return '<br /><label> <input type="checkbox" name="'.
1655: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1656: &mt('show').'</label>'."\n";
1657: }
1658:
1.41 raeburn 1659: sub login_header_options {
1.135 bisitz 1660: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1661: my $output = '';
1.41 raeburn 1662: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1663: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1664: if (!$is_custom->{'textcol'}) {
1665: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1666: ' ';
1667: }
1668: if (!$is_custom->{'bgcol'}) {
1669: $output .= $choices->{'bgcol'}.': '.
1670: '<span id="css_'.$role.'_font" style="background-color: '.
1671: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1672: }
1673: $output .= '<br />';
1674: }
1675: $output .='<br />';
1676: return $output;
1677: }
1678:
1679: sub login_text_colors {
1.160.6.22 raeburn 1680: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1681: my $color_menu = '<table border="0"><tr>';
1682: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1683: $color_menu .= '<td align="center">'.$choices->{$item};
1684: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1685: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1686: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1687: }
1688: $color_menu .= '</tr></table><br />';
1689: return $color_menu;
1690: }
1691:
1692: sub image_changes {
1693: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1694: my $output;
1.135 bisitz 1695: if ($img eq 'login') {
1.160.6.87! raeburn 1696: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1697: } elsif (!$is_custom) {
1.70 raeburn 1698: if ($img ne 'domlogo') {
1.160.6.87! raeburn 1699: $output = &mt('Default image:').'<br />';
1.41 raeburn 1700: } else {
1.160.6.87! raeburn 1701: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1702: }
1703: }
1.160.6.87! raeburn 1704: if ($img ne 'login') {
1.135 bisitz 1705: if ($img_import) {
1706: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1707: }
1708: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1709: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1710: if ($is_custom) {
1711: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1712: '<input type="checkbox" name="'.
1713: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1714: '</label> '.&mt('Replace:').'</span><br />';
1715: } else {
1.160.6.22 raeburn 1716: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1717: }
1.41 raeburn 1718: }
1719: return $output;
1720: }
1721:
1.3 raeburn 1722: sub print_quotas {
1.86 raeburn 1723: my ($dom,$settings,$rowtotal,$action) = @_;
1724: my $context;
1725: if ($action eq 'quotas') {
1726: $context = 'tools';
1727: } else {
1728: $context = $action;
1729: }
1.160.6.20 raeburn 1730: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1731: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1732: my $typecount = 0;
1.101 raeburn 1733: my ($css_class,%titles);
1.86 raeburn 1734: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1735: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1736: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1737: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1738: %titles = &courserequest_titles();
1.160.6.5 raeburn 1739: } elsif ($context eq 'requestauthor') {
1740: @usertools = ('author');
1741: @options = ('norequest','approval','automatic');
1742: %titles = &authorrequest_titles();
1.86 raeburn 1743: } else {
1.160.6.4 raeburn 1744: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1745: %titles = &tool_titles();
1.86 raeburn 1746: }
1.26 raeburn 1747: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1748: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1749: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1750: unless (($context eq 'requestcourses') ||
1751: ($context eq 'requestauthor')) {
1.86 raeburn 1752: if (ref($settings) eq 'HASH') {
1753: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1754: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1755: } else {
1756: $currdefquota = $settings->{$type};
1757: }
1.160.6.20 raeburn 1758: if (ref($settings->{authorquota}) eq 'HASH') {
1759: $currauthorquota = $settings->{authorquota}->{$type};
1760: }
1.78 raeburn 1761: }
1.72 raeburn 1762: }
1.3 raeburn 1763: if (defined($usertypes->{$type})) {
1764: $typecount ++;
1765: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1766: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1767: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1768: '<td class="LC_left_item">';
1.101 raeburn 1769: if ($context eq 'requestcourses') {
1770: $datatable .= '<table><tr>';
1771: }
1772: my %cell;
1.72 raeburn 1773: foreach my $item (@usertools) {
1.101 raeburn 1774: if ($context eq 'requestcourses') {
1775: my ($curroption,$currlimit);
1776: if (ref($settings) eq 'HASH') {
1777: if (ref($settings->{$item}) eq 'HASH') {
1778: $curroption = $settings->{$item}->{$type};
1779: if ($curroption =~ /^autolimit=(\d*)$/) {
1780: $currlimit = $1;
1781: }
1782: }
1783: }
1784: if (!$curroption) {
1785: $curroption = 'norequest';
1786: }
1787: $datatable .= '<th>'.$titles{$item}.'</th>';
1788: foreach my $option (@options) {
1789: my $val = $option;
1790: if ($option eq 'norequest') {
1791: $val = 0;
1792: }
1793: if ($option eq 'validate') {
1794: my $canvalidate = 0;
1795: if (ref($validations{$item}) eq 'HASH') {
1796: if ($validations{$item}{$type}) {
1797: $canvalidate = 1;
1798: }
1799: }
1800: next if (!$canvalidate);
1801: }
1802: my $checked = '';
1803: if ($option eq $curroption) {
1804: $checked = ' checked="checked"';
1805: } elsif ($option eq 'autolimit') {
1806: if ($curroption =~ /^autolimit/) {
1807: $checked = ' checked="checked"';
1808: }
1809: }
1810: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1811: '<input type="radio" name="crsreq_'.$item.
1812: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1813: $titles{$option}.'</label>';
1.101 raeburn 1814: if ($option eq 'autolimit') {
1.127 raeburn 1815: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1816: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1817: 'value="'.$currlimit.'" />';
1.101 raeburn 1818: }
1.127 raeburn 1819: $cell{$item} .= '</span> ';
1.103 raeburn 1820: if ($option eq 'autolimit') {
1.127 raeburn 1821: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1822: }
1.101 raeburn 1823: }
1.160.6.5 raeburn 1824: } elsif ($context eq 'requestauthor') {
1825: my $curroption;
1826: if (ref($settings) eq 'HASH') {
1827: $curroption = $settings->{$type};
1828: }
1829: if (!$curroption) {
1830: $curroption = 'norequest';
1831: }
1832: foreach my $option (@options) {
1833: my $val = $option;
1834: if ($option eq 'norequest') {
1835: $val = 0;
1836: }
1837: my $checked = '';
1838: if ($option eq $curroption) {
1839: $checked = ' checked="checked"';
1840: }
1841: $datatable .= '<span class="LC_nobreak"><label>'.
1842: '<input type="radio" name="authorreq_'.$type.
1843: '" value="'.$val.'"'.$checked.' />'.
1844: $titles{$option}.'</label></span> ';
1845: }
1.101 raeburn 1846: } else {
1847: my $checked = 'checked="checked" ';
1848: if (ref($settings) eq 'HASH') {
1849: if (ref($settings->{$item}) eq 'HASH') {
1850: if ($settings->{$item}->{$type} == 0) {
1851: $checked = '';
1852: } elsif ($settings->{$item}->{$type} == 1) {
1853: $checked = 'checked="checked" ';
1854: }
1.78 raeburn 1855: }
1.72 raeburn 1856: }
1.101 raeburn 1857: $datatable .= '<span class="LC_nobreak"><label>'.
1858: '<input type="checkbox" name="'.$context.'_'.$item.
1859: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1860: '</label></span> ';
1.72 raeburn 1861: }
1.101 raeburn 1862: }
1863: if ($context eq 'requestcourses') {
1864: $datatable .= '</tr><tr>';
1865: foreach my $item (@usertools) {
1.106 raeburn 1866: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1867: }
1868: $datatable .= '</tr></table>';
1.72 raeburn 1869: }
1.86 raeburn 1870: $datatable .= '</td>';
1.160.6.5 raeburn 1871: unless (($context eq 'requestcourses') ||
1872: ($context eq 'requestauthor')) {
1.86 raeburn 1873: $datatable .=
1.160.6.20 raeburn 1874: '<td class="LC_right_item">'.
1875: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1876: '<input type="text" name="quota_'.$type.
1.72 raeburn 1877: '" value="'.$currdefquota.
1.160.6.20 raeburn 1878: '" size="5" /></span>'.(' ' x 2).
1879: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1880: '<input type="text" name="authorquota_'.$type.
1881: '" value="'.$currauthorquota.
1882: '" size="5" /></span></td>';
1.86 raeburn 1883: }
1884: $datatable .= '</tr>';
1.3 raeburn 1885: }
1886: }
1887: }
1.160.6.5 raeburn 1888: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1889: $defaultquota = '20';
1.160.6.20 raeburn 1890: $authorquota = '500';
1.86 raeburn 1891: if (ref($settings) eq 'HASH') {
1892: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1893: $defaultquota = $settings->{'defaultquota'}->{'default'};
1894: } elsif (defined($settings->{'default'})) {
1895: $defaultquota = $settings->{'default'};
1896: }
1.160.6.20 raeburn 1897: if (ref($settings->{'authorquota'}) eq 'HASH') {
1898: $authorquota = $settings->{'authorquota'}->{'default'};
1899: }
1.3 raeburn 1900: }
1901: }
1902: $typecount ++;
1903: $css_class = $typecount%2?' class="LC_odd_row"':'';
1904: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1905: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1906: '<td class="LC_left_item">';
1.101 raeburn 1907: if ($context eq 'requestcourses') {
1908: $datatable .= '<table><tr>';
1909: }
1910: my %defcell;
1.72 raeburn 1911: foreach my $item (@usertools) {
1.101 raeburn 1912: if ($context eq 'requestcourses') {
1913: my ($curroption,$currlimit);
1914: if (ref($settings) eq 'HASH') {
1915: if (ref($settings->{$item}) eq 'HASH') {
1916: $curroption = $settings->{$item}->{'default'};
1917: if ($curroption =~ /^autolimit=(\d*)$/) {
1918: $currlimit = $1;
1919: }
1920: }
1921: }
1922: if (!$curroption) {
1923: $curroption = 'norequest';
1924: }
1925: $datatable .= '<th>'.$titles{$item}.'</th>';
1926: foreach my $option (@options) {
1927: my $val = $option;
1928: if ($option eq 'norequest') {
1929: $val = 0;
1930: }
1931: if ($option eq 'validate') {
1932: my $canvalidate = 0;
1933: if (ref($validations{$item}) eq 'HASH') {
1934: if ($validations{$item}{'default'}) {
1935: $canvalidate = 1;
1936: }
1937: }
1938: next if (!$canvalidate);
1939: }
1940: my $checked = '';
1941: if ($option eq $curroption) {
1942: $checked = ' checked="checked"';
1943: } elsif ($option eq 'autolimit') {
1944: if ($curroption =~ /^autolimit/) {
1945: $checked = ' checked="checked"';
1946: }
1947: }
1948: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1949: '<input type="radio" name="crsreq_'.$item.
1950: '_default" value="'.$val.'"'.$checked.' />'.
1951: $titles{$option}.'</label>';
1952: if ($option eq 'autolimit') {
1.127 raeburn 1953: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1954: $item.'_limit_default" size="1" '.
1955: 'value="'.$currlimit.'" />';
1956: }
1.127 raeburn 1957: $defcell{$item} .= '</span> ';
1.104 raeburn 1958: if ($option eq 'autolimit') {
1.127 raeburn 1959: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1960: }
1.101 raeburn 1961: }
1.160.6.5 raeburn 1962: } elsif ($context eq 'requestauthor') {
1963: my $curroption;
1964: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1965: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1966: }
1967: if (!$curroption) {
1968: $curroption = 'norequest';
1969: }
1970: foreach my $option (@options) {
1971: my $val = $option;
1972: if ($option eq 'norequest') {
1973: $val = 0;
1974: }
1975: my $checked = '';
1976: if ($option eq $curroption) {
1977: $checked = ' checked="checked"';
1978: }
1979: $datatable .= '<span class="LC_nobreak"><label>'.
1980: '<input type="radio" name="authorreq_default"'.
1981: ' value="'.$val.'"'.$checked.' />'.
1982: $titles{$option}.'</label></span> ';
1983: }
1.101 raeburn 1984: } else {
1985: my $checked = 'checked="checked" ';
1986: if (ref($settings) eq 'HASH') {
1987: if (ref($settings->{$item}) eq 'HASH') {
1988: if ($settings->{$item}->{'default'} == 0) {
1989: $checked = '';
1990: } elsif ($settings->{$item}->{'default'} == 1) {
1991: $checked = 'checked="checked" ';
1992: }
1.78 raeburn 1993: }
1.72 raeburn 1994: }
1.101 raeburn 1995: $datatable .= '<span class="LC_nobreak"><label>'.
1996: '<input type="checkbox" name="'.$context.'_'.$item.
1997: '" value="default" '.$checked.'/>'.$titles{$item}.
1998: '</label></span> ';
1999: }
2000: }
2001: if ($context eq 'requestcourses') {
2002: $datatable .= '</tr><tr>';
2003: foreach my $item (@usertools) {
1.106 raeburn 2004: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2005: }
1.101 raeburn 2006: $datatable .= '</tr></table>';
1.72 raeburn 2007: }
1.86 raeburn 2008: $datatable .= '</td>';
1.160.6.5 raeburn 2009: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2010: $datatable .= '<td class="LC_right_item">'.
2011: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2012: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2013: $defaultquota.'" size="5" /></span>'.(' ' x2).
2014: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2015: '<input type="text" name="authorquota" value="'.
2016: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2017: }
2018: $datatable .= '</tr>';
1.72 raeburn 2019: $typecount ++;
2020: $css_class = $typecount%2?' class="LC_odd_row"':'';
2021: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2022: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2023: if ($context eq 'requestcourses') {
1.109 raeburn 2024: $datatable .= &mt('(overrides affiliation, if set)').
2025: '</td>'.
2026: '<td class="LC_left_item">'.
2027: '<table><tr>';
1.101 raeburn 2028: } else {
1.109 raeburn 2029: $datatable .= &mt('(overrides affiliation, if checked)').
2030: '</td>'.
2031: '<td class="LC_left_item" colspan="2">'.
2032: '<br />';
1.101 raeburn 2033: }
2034: my %advcell;
1.72 raeburn 2035: foreach my $item (@usertools) {
1.101 raeburn 2036: if ($context eq 'requestcourses') {
2037: my ($curroption,$currlimit);
2038: if (ref($settings) eq 'HASH') {
2039: if (ref($settings->{$item}) eq 'HASH') {
2040: $curroption = $settings->{$item}->{'_LC_adv'};
2041: if ($curroption =~ /^autolimit=(\d*)$/) {
2042: $currlimit = $1;
2043: }
2044: }
2045: }
2046: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2047: my $checked = '';
2048: if ($curroption eq '') {
2049: $checked = ' checked="checked"';
2050: }
2051: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2052: '<input type="radio" name="crsreq_'.$item.
2053: '__LC_adv" value=""'.$checked.' />'.
2054: &mt('No override set').'</label></span> ';
1.101 raeburn 2055: foreach my $option (@options) {
2056: my $val = $option;
2057: if ($option eq 'norequest') {
2058: $val = 0;
2059: }
2060: if ($option eq 'validate') {
2061: my $canvalidate = 0;
2062: if (ref($validations{$item}) eq 'HASH') {
2063: if ($validations{$item}{'_LC_adv'}) {
2064: $canvalidate = 1;
2065: }
2066: }
2067: next if (!$canvalidate);
2068: }
2069: my $checked = '';
1.104 raeburn 2070: if ($val eq $curroption) {
1.101 raeburn 2071: $checked = ' checked="checked"';
2072: } elsif ($option eq 'autolimit') {
2073: if ($curroption =~ /^autolimit/) {
2074: $checked = ' checked="checked"';
2075: }
2076: }
2077: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2078: '<input type="radio" name="crsreq_'.$item.
2079: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2080: $titles{$option}.'</label>';
2081: if ($option eq 'autolimit') {
1.127 raeburn 2082: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2083: $item.'_limit__LC_adv" size="1" '.
2084: 'value="'.$currlimit.'" />';
2085: }
1.127 raeburn 2086: $advcell{$item} .= '</span> ';
1.104 raeburn 2087: if ($option eq 'autolimit') {
1.127 raeburn 2088: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2089: }
1.101 raeburn 2090: }
1.160.6.5 raeburn 2091: } elsif ($context eq 'requestauthor') {
2092: my $curroption;
2093: if (ref($settings) eq 'HASH') {
2094: $curroption = $settings->{'_LC_adv'};
2095: }
2096: my $checked = '';
2097: if ($curroption eq '') {
2098: $checked = ' checked="checked"';
2099: }
2100: $datatable .= '<span class="LC_nobreak"><label>'.
2101: '<input type="radio" name="authorreq__LC_adv"'.
2102: ' value=""'.$checked.' />'.
2103: &mt('No override set').'</label></span> ';
2104: foreach my $option (@options) {
2105: my $val = $option;
2106: if ($option eq 'norequest') {
2107: $val = 0;
2108: }
2109: my $checked = '';
2110: if ($val eq $curroption) {
2111: $checked = ' checked="checked"';
2112: }
2113: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2114: '<input type="radio" name="authorreq__LC_adv"'.
2115: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2116: $titles{$option}.'</label></span> ';
2117: }
1.101 raeburn 2118: } else {
2119: my $checked = 'checked="checked" ';
2120: if (ref($settings) eq 'HASH') {
2121: if (ref($settings->{$item}) eq 'HASH') {
2122: if ($settings->{$item}->{'_LC_adv'} == 0) {
2123: $checked = '';
2124: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2125: $checked = 'checked="checked" ';
2126: }
1.79 raeburn 2127: }
1.72 raeburn 2128: }
1.101 raeburn 2129: $datatable .= '<span class="LC_nobreak"><label>'.
2130: '<input type="checkbox" name="'.$context.'_'.$item.
2131: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2132: '</label></span> ';
2133: }
2134: }
2135: if ($context eq 'requestcourses') {
2136: $datatable .= '</tr><tr>';
2137: foreach my $item (@usertools) {
1.106 raeburn 2138: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2139: }
1.101 raeburn 2140: $datatable .= '</tr></table>';
1.72 raeburn 2141: }
1.98 raeburn 2142: $datatable .= '</td></tr>';
1.30 raeburn 2143: $$rowtotal += $typecount;
1.3 raeburn 2144: return $datatable;
2145: }
2146:
1.160.6.5 raeburn 2147: sub print_requestmail {
2148: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2149: my ($now,$datatable,%currapp);
1.102 raeburn 2150: $now = time;
2151: if (ref($settings) eq 'HASH') {
2152: if (ref($settings->{'notify'}) eq 'HASH') {
2153: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2154: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2155: }
2156: }
2157: }
1.160.6.16 raeburn 2158: my $numinrow = 2;
1.160.6.34 raeburn 2159: my $css_class;
2160: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2161: my $text;
2162: if ($action eq 'requestcourses') {
2163: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2164: } elsif ($action eq 'requestauthor') {
2165: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2166: } else {
1.160.6.34 raeburn 2167: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2168: }
1.160.6.34 raeburn 2169: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2170: ' <td>'.$text.'</td>'.
1.102 raeburn 2171: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2172: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2173: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2174: if ($numdc > 0) {
2175: $datatable .= $table;
1.102 raeburn 2176: } else {
2177: $datatable .= &mt('There are no active Domain Coordinators');
2178: }
2179: $datatable .='</td></tr>';
2180: return $datatable;
2181: }
2182:
1.160.6.30 raeburn 2183: sub print_studentcode {
2184: my ($settings,$rowtotal) = @_;
2185: my $rownum = 0;
2186: my ($output,%current);
2187: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2188: if (ref($settings) eq 'HASH') {
2189: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2190: foreach my $type (@crstypes) {
2191: $current{$type} = $settings->{'uniquecode'}{$type};
2192: }
1.160.6.30 raeburn 2193: }
2194: }
2195: $output .= '<tr>'.
2196: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2197: '<td class="LC_left_item">';
2198: foreach my $type (@crstypes) {
2199: my $check = ' ';
2200: if ($current{$type}) {
2201: $check = ' checked="checked" ';
2202: }
2203: $output .= '<span class="LC_nobreak"><label>'.
2204: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2205: &mt($type).'</label></span>'.(' 'x2).' ';
2206: }
2207: $output .= '</td></tr>';
2208: $$rowtotal ++;
2209: return $output;
2210: }
2211:
2212: sub print_textbookcourses {
1.160.6.46 raeburn 2213: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2214: my $rownum = 0;
2215: my $css_class;
2216: my $itemcount = 1;
2217: my $maxnum = 0;
2218: my $bookshash;
2219: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2220: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2221: }
2222: my %ordered;
2223: if (ref($bookshash) eq 'HASH') {
2224: foreach my $item (keys(%{$bookshash})) {
2225: if (ref($bookshash->{$item}) eq 'HASH') {
2226: my $num = $bookshash->{$item}{'order'};
2227: $ordered{$num} = $item;
2228: }
2229: }
2230: }
2231: my $confname = $dom.'-domainconfig';
2232: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2233: my $maxnum = scalar(keys(%ordered));
2234: my $datatable;
1.160.6.30 raeburn 2235: if (keys(%ordered)) {
2236: my @items = sort { $a <=> $b } keys(%ordered);
2237: for (my $i=0; $i<@items; $i++) {
2238: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2239: my $key = $ordered{$items[$i]};
2240: my %coursehash=&Apache::lonnet::coursedescription($key);
2241: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2242: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2243: if (ref($bookshash->{$key}) eq 'HASH') {
2244: $subject = $bookshash->{$key}->{'subject'};
2245: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2246: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2247: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2248: $author = $bookshash->{$key}->{'author'};
2249: $image = $bookshash->{$key}->{'image'};
2250: if ($image ne '') {
2251: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2252: my $imagethumb = "$path/tn-".$imagefile;
2253: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2254: }
1.160.6.30 raeburn 2255: }
2256: }
1.160.6.46 raeburn 2257: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2258: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2259: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2260: for (my $k=0; $k<=$maxnum; $k++) {
2261: my $vpos = $k+1;
2262: my $selstr;
2263: if ($k == $i) {
2264: $selstr = ' selected="selected" ';
2265: }
2266: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2267: }
2268: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2269: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2270: &mt('Delete?').'</label></span></td>'.
2271: '<td colspan="2">'.
1.160.6.46 raeburn 2272: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2273: (' 'x2).
1.160.6.46 raeburn 2274: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2275: if ($type eq 'textbooks') {
2276: $datatable .= (' 'x2).
1.160.6.47 raeburn 2277: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2278: (' 'x2).
1.160.6.46 raeburn 2279: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2280: (' 'x2).
2281: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2282: if ($image) {
2283: $datatable .= '<span class="LC_nobreak">'.
2284: $imgsrc.
2285: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2286: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2287: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2288: }
2289: if ($switchserver) {
2290: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2291: } else {
2292: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2293: }
1.160.6.30 raeburn 2294: }
1.160.6.46 raeburn 2295: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2296: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2297: $coursetitle.'</span></td></tr>'."\n";
2298: $itemcount ++;
2299: }
2300: }
2301: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2302: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2303: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2304: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2305: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2306: for (my $k=0; $k<$maxnum+1; $k++) {
2307: my $vpos = $k+1;
2308: my $selstr;
2309: if ($k == $maxnum) {
2310: $selstr = ' selected="selected" ';
2311: }
2312: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2313: }
2314: $datatable .= '</select> '."\n".
1.160.6.87! raeburn 2315: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2316: '<td colspan="2">'.
1.160.6.46 raeburn 2317: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2318: (' 'x2).
1.160.6.46 raeburn 2319: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2320: (' 'x2);
2321: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2322: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2323: (' 'x2).
2324: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2325: (' 'x2).
2326: '<span class="LC_nobreak">'.&mt('Image:').' ';
2327: if ($switchserver) {
2328: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2329: } else {
2330: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2331: }
1.160.6.87! raeburn 2332: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2333: }
1.160.6.87! raeburn 2334: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2335: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2336: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2337: &Apache::loncommon::selectcourse_link
1.160.6.87! raeburn 2338: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2339: '</span></td>'."\n".
2340: '</tr>'."\n";
2341: $itemcount ++;
2342: return $datatable;
2343: }
2344:
2345: sub textbookcourses_javascript {
1.160.6.46 raeburn 2346: my ($settings) = @_;
2347: return unless(ref($settings) eq 'HASH');
2348: my (%ordered,%total,%jstext);
2349: foreach my $type ('textbooks','templates') {
2350: $total{$type} = 0;
2351: if (ref($settings->{$type}) eq 'HASH') {
2352: foreach my $item (keys(%{$settings->{$type}})) {
2353: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2354: my $num = $settings->{$type}->{$item}{'order'};
2355: $ordered{$type}{$num} = $item;
2356: }
2357: }
2358: $total{$type} = scalar(keys(%{$settings->{$type}}));
2359: }
2360: my @jsarray = ();
2361: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2362: push(@jsarray,$ordered{$type}{$item});
2363: }
2364: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2365: }
2366: return <<"ENDSCRIPT";
2367: <script type="text/javascript">
2368: // <![CDATA[
1.160.6.46 raeburn 2369: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2370: var changedVal;
1.160.6.46 raeburn 2371: $jstext{'textbooks'};
2372: $jstext{'templates'};
2373: var newpos;
2374: var maxh;
2375: if (caller == 'textbooks') {
2376: newpos = 'textbooks_addbook_pos';
2377: maxh = 1 + $total{'textbooks'};
2378: } else {
2379: newpos = 'templates_addbook_pos';
2380: maxh = 1 + $total{'templates'};
2381: }
1.160.6.30 raeburn 2382: var current = new Array;
2383: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2384: if (item == newpos) {
2385: changedVal = newitemVal;
2386: } else {
2387: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2388: current[newitemVal] = newpos;
2389: }
1.160.6.46 raeburn 2390: if (caller == 'textbooks') {
2391: for (var i=0; i<textbooks.length; i++) {
2392: var elementName = 'textbooks_'+textbooks[i];
2393: if (elementName != item) {
2394: if (form.elements[elementName]) {
2395: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2396: current[currVal] = elementName;
2397: }
2398: }
2399: }
2400: }
2401: if (caller == 'templates') {
2402: for (var i=0; i<templates.length; i++) {
2403: var elementName = 'templates_'+templates[i];
2404: if (elementName != item) {
2405: if (form.elements[elementName]) {
2406: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2407: current[currVal] = elementName;
2408: }
1.160.6.30 raeburn 2409: }
2410: }
2411: }
2412: var oldVal;
2413: for (var j=0; j<maxh; j++) {
2414: if (current[j] == undefined) {
2415: oldVal = j;
2416: }
2417: }
2418: if (oldVal < changedVal) {
2419: for (var k=oldVal+1; k<=changedVal ; k++) {
2420: var elementName = current[k];
2421: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2422: }
2423: } else {
2424: for (var k=changedVal; k<oldVal; k++) {
2425: var elementName = current[k];
2426: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2427: }
2428: }
2429: return;
2430: }
2431:
2432: // ]]>
2433: </script>
2434:
2435: ENDSCRIPT
2436: }
2437:
1.3 raeburn 2438: sub print_autoenroll {
1.30 raeburn 2439: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2440: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2441: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2442: if (ref($settings) eq 'HASH') {
2443: if (exists($settings->{'run'})) {
2444: if ($settings->{'run'} eq '0') {
2445: $runoff = ' checked="checked" ';
2446: $runon = ' ';
2447: } else {
2448: $runon = ' checked="checked" ';
2449: $runoff = ' ';
2450: }
2451: } else {
2452: if ($autorun) {
2453: $runon = ' checked="checked" ';
2454: $runoff = ' ';
2455: } else {
2456: $runoff = ' checked="checked" ';
2457: $runon = ' ';
2458: }
2459: }
1.129 raeburn 2460: if (exists($settings->{'co-owners'})) {
2461: if ($settings->{'co-owners'} eq '0') {
2462: $coownersoff = ' checked="checked" ';
2463: $coownerson = ' ';
2464: } else {
2465: $coownerson = ' checked="checked" ';
2466: $coownersoff = ' ';
2467: }
2468: } else {
2469: $coownersoff = ' checked="checked" ';
2470: $coownerson = ' ';
2471: }
1.3 raeburn 2472: if (exists($settings->{'sender_domain'})) {
2473: $defdom = $settings->{'sender_domain'};
2474: }
1.160.6.68 raeburn 2475: if (exists($settings->{'autofailsafe'})) {
2476: $failsafe = $settings->{'autofailsafe'};
2477: }
1.14 raeburn 2478: } else {
2479: if ($autorun) {
2480: $runon = ' checked="checked" ';
2481: $runoff = ' ';
2482: } else {
2483: $runoff = ' checked="checked" ';
2484: $runon = ' ';
2485: }
1.3 raeburn 2486: }
2487: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2488: my $notif_sender;
2489: if (ref($settings) eq 'HASH') {
2490: $notif_sender = $settings->{'sender_uname'};
2491: }
1.3 raeburn 2492: my $datatable='<tr class="LC_odd_row">'.
2493: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2494: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2495: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2496: $runon.' value="1" />'.&mt('Yes').'</label> '.
2497: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2498: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2499: '</tr><tr>'.
2500: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2501: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2502: &mt('username').': '.
2503: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2504: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2505: ': '.$domform.'</span></td></tr>'.
2506: '<tr class="LC_odd_row">'.
2507: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2508: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2509: '<input type="radio" name="autoassign_coowners"'.
2510: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2511: '<label><input type="radio" name="autoassign_coowners"'.
2512: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2513: '</tr><tr>'.
2514: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2515: '<td class="LC_right_item"><span class="LC_nobreak">'.
2516: '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87! raeburn 2517: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68 raeburn 2518: $$rowtotal += 4;
1.3 raeburn 2519: return $datatable;
2520: }
2521:
2522: sub print_autoupdate {
1.30 raeburn 2523: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2524: my $datatable;
2525: if ($position eq 'top') {
2526: my $updateon = ' ';
2527: my $updateoff = ' checked="checked" ';
2528: my $classlistson = ' ';
2529: my $classlistsoff = ' checked="checked" ';
2530: if (ref($settings) eq 'HASH') {
2531: if ($settings->{'run'} eq '1') {
2532: $updateon = $updateoff;
2533: $updateoff = ' ';
2534: }
2535: if ($settings->{'classlists'} eq '1') {
2536: $classlistson = $classlistsoff;
2537: $classlistsoff = ' ';
2538: }
2539: }
2540: my %title = (
2541: run => 'Auto-update active?',
2542: classlists => 'Update information in classlists?',
2543: );
2544: $datatable = '<tr class="LC_odd_row">'.
2545: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2546: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2547: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2548: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2549: '<label><input type="radio" name="autoupdate_run"'.
2550: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2551: '</tr><tr>'.
2552: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2553: '<td class="LC_right_item"><span class="LC_nobreak">'.
2554: '<label><input type="radio" name="classlists"'.
2555: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2556: '<label><input type="radio" name="classlists"'.
2557: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2558: '</tr>';
1.30 raeburn 2559: $$rowtotal += 2;
1.131 raeburn 2560: } elsif ($position eq 'middle') {
2561: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2562: my $numinrow = 3;
2563: my $locknamesettings;
2564: $datatable .= &insttypes_row($settings,$types,$usertypes,
2565: $dom,$numinrow,$othertitle,
2566: 'lockablenames');
2567: $$rowtotal ++;
1.3 raeburn 2568: } else {
1.44 raeburn 2569: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2570: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2571: 'permanentemail','id');
1.33 raeburn 2572: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2573: my $numrows = 0;
1.26 raeburn 2574: if (ref($types) eq 'ARRAY') {
2575: if (@{$types} > 0) {
2576: $datatable =
2577: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2578: \@fields,$types,\$numrows);
1.30 raeburn 2579: $$rowtotal += @{$types};
1.26 raeburn 2580: }
1.3 raeburn 2581: }
2582: $datatable .=
2583: &usertype_update_row($settings,{'default' => $othertitle},
2584: \%fieldtitles,\@fields,['default'],
2585: \$numrows);
1.30 raeburn 2586: $$rowtotal ++;
1.3 raeburn 2587: }
2588: return $datatable;
2589: }
2590:
1.125 raeburn 2591: sub print_autocreate {
2592: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2593: my (%createon,%createoff,%currhash);
1.125 raeburn 2594: my @types = ('xml','req');
2595: if (ref($settings) eq 'HASH') {
2596: foreach my $item (@types) {
2597: $createoff{$item} = ' checked="checked" ';
2598: $createon{$item} = ' ';
2599: if (exists($settings->{$item})) {
2600: if ($settings->{$item}) {
2601: $createon{$item} = ' checked="checked" ';
2602: $createoff{$item} = ' ';
2603: }
2604: }
2605: }
1.160.6.16 raeburn 2606: if ($settings->{'xmldc'} ne '') {
2607: $currhash{$settings->{'xmldc'}} = 1;
2608: }
1.125 raeburn 2609: } else {
2610: foreach my $item (@types) {
2611: $createoff{$item} = ' checked="checked" ';
2612: $createon{$item} = ' ';
2613: }
2614: }
2615: $$rowtotal += 2;
1.160.6.16 raeburn 2616: my $numinrow = 2;
1.125 raeburn 2617: my $datatable='<tr class="LC_odd_row">'.
2618: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2619: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2620: '<input type="radio" name="autocreate_xml"'.
2621: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2622: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2623: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2624: '</td></tr><tr>'.
2625: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2626: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2627: '<input type="radio" name="autocreate_req"'.
2628: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2629: '<label><input type="radio" name="autocreate_req"'.
2630: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2631: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2632: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2633: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2634: if ($numdc > 1) {
1.160.6.50 raeburn 2635: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2636: '</td><td class="LC_left_item">';
1.125 raeburn 2637: } else {
1.160.6.50 raeburn 2638: $datatable .= &mt('Course creation processed as:').
2639: '</td><td class="LC_right_item">';
1.125 raeburn 2640: }
1.160.6.50 raeburn 2641: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2642: $$rowtotal += $rows;
1.125 raeburn 2643: return $datatable;
2644: }
2645:
1.23 raeburn 2646: sub print_directorysrch {
1.160.6.72 raeburn 2647: my ($position,$dom,$settings,$rowtotal) = @_;
2648: my $datatable;
2649: if ($position eq 'top') {
2650: my $instsrchon = ' ';
2651: my $instsrchoff = ' checked="checked" ';
2652: my ($exacton,$containson,$beginson);
2653: my $instlocalon = ' ';
2654: my $instlocaloff = ' checked="checked" ';
2655: if (ref($settings) eq 'HASH') {
2656: if ($settings->{'available'} eq '1') {
2657: $instsrchon = $instsrchoff;
2658: $instsrchoff = ' ';
2659: }
2660: if ($settings->{'localonly'} eq '1') {
2661: $instlocalon = $instlocaloff;
2662: $instlocaloff = ' ';
2663: }
2664: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2665: foreach my $type (@{$settings->{'searchtypes'}}) {
2666: if ($type eq 'exact') {
2667: $exacton = ' checked="checked" ';
2668: } elsif ($type eq 'contains') {
2669: $containson = ' checked="checked" ';
2670: } elsif ($type eq 'begins') {
2671: $beginson = ' checked="checked" ';
2672: }
2673: }
2674: } else {
2675: if ($settings->{'searchtypes'} eq 'exact') {
2676: $exacton = ' checked="checked" ';
2677: } elsif ($settings->{'searchtypes'} eq 'contains') {
2678: $containson = ' checked="checked" ';
2679: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2680: $exacton = ' checked="checked" ';
2681: $containson = ' checked="checked" ';
2682: }
2683: }
1.23 raeburn 2684: }
1.160.6.72 raeburn 2685: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2686: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2687:
1.160.6.72 raeburn 2688: my $numinrow = 4;
2689: my $cansrchrow = 0;
2690: $datatable='<tr class="LC_odd_row">'.
2691: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2692: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2693: '<input type="radio" name="dirsrch_available"'.
2694: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2695: '<label><input type="radio" name="dirsrch_available"'.
2696: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2697: '</tr><tr>'.
2698: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2699: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2700: '<input type="radio" name="dirsrch_instlocalonly"'.
2701: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2702: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2703: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2704: '</tr>';
2705: $$rowtotal += 2;
2706: if (ref($usertypes) eq 'HASH') {
2707: if (keys(%{$usertypes}) > 0) {
2708: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2709: $numinrow,$othertitle,'cansearch');
2710: $cansrchrow = 1;
2711: }
1.26 raeburn 2712: }
1.160.6.72 raeburn 2713: if ($cansrchrow) {
2714: $$rowtotal ++;
2715: $datatable .= '<tr>';
2716: } else {
2717: $datatable .= '<tr class="LC_odd_row">';
2718: }
2719: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2720: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2721: foreach my $title (@{$titleorder}) {
2722: if (defined($searchtitles->{$title})) {
2723: my $check = ' ';
2724: if (ref($settings) eq 'HASH') {
2725: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2726: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2727: $check = ' checked="checked" ';
2728: }
1.39 raeburn 2729: }
1.25 raeburn 2730: }
1.160.6.72 raeburn 2731: $datatable .= '<td class="LC_left_item">'.
2732: '<span class="LC_nobreak"><label>'.
2733: '<input type="checkbox" name="searchby" '.
2734: 'value="'.$title.'"'.$check.'/>'.
2735: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2736: }
2737: }
1.160.6.72 raeburn 2738: $datatable .= '</tr></table></td></tr>';
2739: $$rowtotal ++;
2740: if ($cansrchrow) {
2741: $datatable .= '<tr class="LC_odd_row">';
2742: } else {
2743: $datatable .= '<tr>';
2744: }
2745: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2746: '<td class="LC_left_item" colspan="2">'.
2747: '<span class="LC_nobreak"><label>'.
2748: '<input type="checkbox" name="searchtypes" '.
2749: $exacton.' value="exact" />'.&mt('Exact match').
2750: '</label> '.
2751: '<label><input type="checkbox" name="searchtypes" '.
2752: $beginson.' value="begins" />'.&mt('Begins with').
2753: '</label> '.
2754: '<label><input type="checkbox" name="searchtypes" '.
2755: $containson.' value="contains" />'.&mt('Contains').
2756: '</label></span></td></tr>';
2757: $$rowtotal ++;
1.26 raeburn 2758: } else {
1.160.6.72 raeburn 2759: my $domsrchon = ' checked="checked" ';
2760: my $domsrchoff = ' ';
2761: my $domlocalon = ' ';
2762: my $domlocaloff = ' checked="checked" ';
2763: if (ref($settings) eq 'HASH') {
2764: if ($settings->{'lclocalonly'} eq '1') {
2765: $domlocalon = $domlocaloff;
2766: $domlocaloff = ' ';
2767: }
2768: if ($settings->{'lcavailable'} eq '0') {
2769: $domsrchoff = $domsrchon;
2770: $domsrchon = ' ';
2771: }
2772: }
2773: $datatable='<tr class="LC_odd_row">'.
2774: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2775: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2776: '<input type="radio" name="dirsrch_domavailable"'.
2777: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2778: '<label><input type="radio" name="dirsrch_domavailable"'.
2779: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2780: '</tr><tr>'.
2781: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2782: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2783: '<input type="radio" name="dirsrch_domlocalonly"'.
2784: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2785: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2786: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2787: '</tr>';
2788: $$rowtotal += 2;
1.26 raeburn 2789: }
1.25 raeburn 2790: return $datatable;
2791: }
2792:
1.28 raeburn 2793: sub print_contacts {
1.160.6.78 raeburn 2794: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2795: my $datatable;
2796: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 2797: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2798: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2799: if ($position eq 'top') {
2800: if (ref($settings) eq 'HASH') {
2801: foreach my $item (@contacts) {
2802: if (exists($settings->{$item})) {
2803: $to{$item} = $settings->{$item};
2804: }
1.28 raeburn 2805: }
2806: }
1.160.6.78 raeburn 2807: } elsif ($position eq 'middle') {
2808: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
2809: 'updatesmail','idconflictsmail');
1.28 raeburn 2810: foreach my $type (@mailings) {
1.160.6.78 raeburn 2811: $otheremails{$type} = '';
2812: }
2813: } else {
2814: @mailings = ('helpdeskmail','otherdomsmail');
2815: foreach my $type (@mailings) {
2816: $otheremails{$type} = '';
2817: }
2818: $bccemails{'helpdeskmail'} = '';
2819: $bccemails{'otherdomsmail'} = '';
2820: $includestr{'helpdeskmail'} = '';
2821: $includestr{'otherdomsmail'} = '';
2822: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2823: }
2824: if (ref($settings) eq 'HASH') {
2825: unless ($position eq 'top') {
2826: foreach my $type (@mailings) {
2827: if (exists($settings->{$type})) {
2828: if (ref($settings->{$type}) eq 'HASH') {
2829: foreach my $item (@contacts) {
2830: if ($settings->{$type}{$item}) {
2831: $checked{$type}{$item} = ' checked="checked" ';
2832: }
1.28 raeburn 2833: }
1.160.6.78 raeburn 2834: $otheremails{$type} = $settings->{$type}{'others'};
2835: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2836: $bccemails{$type} = $settings->{$type}{'bcc'};
2837: if ($settings->{$type}{'include'} ne '') {
2838: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2839: $includestr{$type} = &unescape($includestr{$type});
2840: }
2841: }
2842: }
2843: } elsif ($type eq 'lonstatusmail') {
2844: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2845: }
2846: }
2847: }
2848: if ($position eq 'bottom') {
2849: foreach my $type (@mailings) {
2850: $bccemails{$type} = $settings->{$type}{'bcc'};
2851: if ($settings->{$type}{'include'} ne '') {
2852: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2853: $includestr{$type} = &unescape($includestr{$type});
2854: }
2855: }
2856: if (ref($settings->{'helpform'}) eq 'HASH') {
2857: if (ref($fields) eq 'ARRAY') {
2858: foreach my $field (@{$fields}) {
2859: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 2860: }
1.160.6.78 raeburn 2861: }
2862: if (exists($settings->{'helpform'}{'maxsize'})) {
2863: $maxsize = $settings->{'helpform'}{'maxsize'};
2864: } else {
2865: $maxsize = '1.0';
2866: }
2867: } else {
2868: if (ref($fields) eq 'ARRAY') {
2869: foreach my $field (@{$fields}) {
2870: $currfield{$field} = 'yes';
1.134 raeburn 2871: }
1.28 raeburn 2872: }
1.160.6.78 raeburn 2873: $maxsize = '1.0';
1.28 raeburn 2874: }
2875: }
2876: } else {
1.160.6.78 raeburn 2877: if ($position eq 'top') {
2878: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2879: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2880: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2881: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2882: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2883: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2884: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2885: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
2886: } elsif ($position eq 'bottom') {
2887: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2888: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
2889: if (ref($fields) eq 'ARRAY') {
2890: foreach my $field (@{$fields}) {
2891: $currfield{$field} = 'yes';
2892: }
2893: }
2894: $maxsize = '1.0';
2895: }
1.28 raeburn 2896: }
2897: my ($titles,$short_titles) = &contact_titles();
2898: my $rownum = 0;
2899: my $css_class;
1.160.6.78 raeburn 2900: if ($position eq 'top') {
2901: foreach my $item (@contacts) {
2902: $css_class = $rownum%2?' class="LC_odd_row"':'';
2903: $datatable .= '<tr'.$css_class.'>'.
2904: '<td><span class="LC_nobreak">'.$titles->{$item}.
2905: '</span></td><td class="LC_right_item">'.
2906: '<input type="text" name="'.$item.'" value="'.
2907: $to{$item}.'" /></td></tr>';
2908: $rownum ++;
2909: }
2910: } else {
2911: foreach my $type (@mailings) {
2912: $css_class = $rownum%2?' class="LC_odd_row"':'';
2913: $datatable .= '<tr'.$css_class.'>'.
2914: '<td><span class="LC_nobreak">'.
2915: $titles->{$type}.': </span></td>'.
2916: '<td class="LC_left_item">';
2917: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2918: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
2919: }
2920: $datatable .= '<span class="LC_nobreak">';
2921: foreach my $item (@contacts) {
2922: $datatable .= '<label>'.
2923: '<input type="checkbox" name="'.$type.'"'.
2924: $checked{$type}{$item}.
2925: ' value="'.$item.'" />'.$short_titles->{$item}.
2926: '</label> ';
2927: }
2928: $datatable .= '</span><br />'.&mt('Others').': '.
2929: '<input type="text" name="'.$type.'_others" '.
2930: 'value="'.$otheremails{$type}.'" />';
2931: my %locchecked;
2932: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2933: foreach my $loc ('s','b') {
2934: if ($includeloc{$type} eq $loc) {
2935: $locchecked{$loc} = ' checked="checked"';
2936: last;
2937: }
2938: }
2939: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2940: '<input type="text" name="'.$type.'_bcc" '.
2941: 'value="'.$bccemails{$type}.'" /></fieldset>'.
2942: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
2943: &mt('Text automatically added to e-mail:').' '.
1.160.6.87! raeburn 2944: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 2945: '<span class="LC_nobreak">'.&mt('Location:').' '.
2946: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
2947: (' 'x2).
2948: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
2949: '</span></fieldset>';
2950: }
2951: $datatable .= '</td></tr>'."\n";
2952: $rownum ++;
2953: }
1.28 raeburn 2954: }
1.160.6.78 raeburn 2955: if ($position eq 'middle') {
2956: my %choices;
2957: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2958: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2959: &mt('LON-CAPA core group - MSU'),600,500));
2960: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2961: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2962: &mt('LON-CAPA core group - MSU'),600,500));
2963: my @toggles = ('reporterrors','reportupdates');
2964: my %defaultchecked = ('reporterrors' => 'on',
2965: 'reportupdates' => 'on');
2966: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2967: \%choices,$rownum);
2968: $datatable .= $reports;
2969: } elsif ($position eq 'bottom') {
1.69 raeburn 2970: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2971: $datatable .= '<tr'.$css_class.'>'.
1.160.6.78 raeburn 2972: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
2973: &mt('(e-mail, subject, and description always shown)').
2974: '</td><td class="LC_left_item">';
2975: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
2976: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
2977: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
2978: foreach my $field (@{$fields}) {
2979: $datatable .= '<tr><td>'.$fieldtitles->{$field};
2980: if (($field eq 'screenshot') || ($field eq 'cc')) {
2981: $datatable .= ' '.&mt('(logged-in users)');
2982: }
2983: $datatable .='</td><td>';
2984: my $clickaction;
2985: if ($field eq 'screenshot') {
2986: $clickaction = ' onclick="screenshotSize(this);"';
2987: }
2988: if (ref($possoptions->{$field}) eq 'ARRAY') {
2989: foreach my $option (@{$possoptions->{$field}}) {
2990: my $checked;
2991: if ($currfield{$field} eq $option) {
2992: $checked = ' checked="checked"';
2993: }
2994: $datatable .= '<span class="LC_nobreak"><label>'.
2995: '<input type="radio" name="helpform_'.$field.'" '.
2996: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
2997: '</label></span>'.(' 'x2);
2998: }
2999: }
3000: if ($field eq 'screenshot') {
3001: my $display;
3002: if ($currfield{$field} eq 'no') {
3003: $display = ' style="display:none"';
3004: }
1.160.6.87! raeburn 3005: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.160.6.78 raeburn 3006: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3007: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3008: }
3009: $datatable .= '</td></tr>';
3010: }
3011: $datatable .= '</table>';
1.134 raeburn 3012: }
3013: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 3014: $rownum ++;
1.28 raeburn 3015: }
1.30 raeburn 3016: $$rowtotal += $rownum;
1.28 raeburn 3017: return $datatable;
3018: }
3019:
1.160.6.78 raeburn 3020: sub contacts_javascript {
3021: return <<"ENDSCRIPT";
3022:
3023: <script type="text/javascript">
3024: // <![CDATA[
3025:
3026: function screenshotSize(field) {
3027: if (document.getElementById('help_screenshotsize')) {
3028: if (field.value == 'no') {
3029: document.getElementById('help_screenshotsize').style.display="none";
3030: } else {
3031: document.getElementById('help_screenshotsize').style.display="";
3032: }
3033: }
3034: return;
3035: }
3036:
3037: // ]]>
3038: </script>
3039:
3040: ENDSCRIPT
3041: }
3042:
1.118 jms 3043: sub print_helpsettings {
1.160.6.73 raeburn 3044: my ($position,$dom,$settings,$rowtotal) = @_;
3045: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3046: my $formname = 'display';
1.160.6.5 raeburn 3047: my ($datatable,$itemcount);
1.160.6.73 raeburn 3048: if ($position eq 'top') {
3049: $itemcount = 1;
3050: my (%choices,%defaultchecked,@toggles);
3051: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3052: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3053: &mt('LON-CAPA bug tracker'),600,500));
3054: %defaultchecked = ('submitbugs' => 'on');
3055: @toggles = ('submitbugs');
3056: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3057: \%choices,$itemcount);
3058: $$rowtotal ++;
3059: } else {
3060: my $css_class;
3061: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3062: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3063: if (ref($settings) eq 'HASH') {
3064: if (ref($settings->{'adhoc'}) eq 'HASH') {
3065: %current = %{$settings->{'adhoc'}};
3066: }
1.160.6.77 raeburn 3067: }
3068: my $count = 0;
3069: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3070: if ($key=~/^rolesdef\_(\w+)$/) {
3071: my $rolename = $1;
1.160.6.77 raeburn 3072: my (%privs,$order);
1.160.6.73 raeburn 3073: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3074: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3075: if (ref($current{$rolename}) eq 'HASH') {
3076: $order = $current{$rolename}{'order'};
3077: }
3078: if ($order eq '') {
3079: $order = $count;
3080: }
3081: $ordered{$order} = $rolename;
3082: $count++;
1.160.6.73 raeburn 3083: }
3084: }
1.160.6.77 raeburn 3085: my $maxnum = scalar(keys(%ordered));
3086: my @roles_by_num = ();
3087: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3088: push(@roles_by_num,$item);
3089: }
3090: my $context = 'domprefs';
3091: my $crstype = 'Course';
3092: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3093: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3094: my ($numstatustypes,@jsarray);
3095: if (ref($types) eq 'ARRAY') {
3096: if (@{$types} > 0) {
3097: $numstatustypes = scalar(@{$types});
3098: push(@accesstypes,'status');
3099: @jsarray = ('bystatus');
3100: }
3101: }
1.160.6.86 raeburn 3102: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3103: if (keys(%domhelpdesk)) {
3104: push(@accesstypes,('inc','exc'));
3105: push(@jsarray,('notinc','notexc'));
3106: }
3107: my $hiddenstr = join("','",@jsarray);
3108: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3109: my $context = 'domprefs';
3110: my $crstype = 'Course';
1.160.6.77 raeburn 3111: my $prefix = 'helproles_';
3112: my $add_class = 'LC_hidden';
3113: foreach my $num (@roles_by_num) {
3114: my $role = $ordered{$num};
3115: my ($desc,$access,@statuses);
3116: if (ref($current{$role}) eq 'HASH') {
3117: $desc = $current{$role}{'desc'};
3118: $access = $current{$role}{'access'};
3119: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3120: @statuses = @{$current{$role}{'insttypes'}};
3121: }
3122: }
3123: if ($desc eq '') {
3124: $desc = $role;
3125: }
3126: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3127: my %full=();
3128: my %levels= (
3129: course => {},
3130: domain => {},
3131: system => {},
3132: );
3133: my %levelscurrent=(
3134: course => {},
3135: domain => {},
3136: system => {},
3137: );
3138: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3139: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3140: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3141: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3142: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3143: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3144: for (my $k=0; $k<=$maxnum; $k++) {
3145: my $vpos = $k+1;
3146: my $selstr;
3147: if ($k == $num) {
3148: $selstr = ' selected="selected" ';
3149: }
3150: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3151: }
3152: $datatable .= '</select>'.(' 'x2).
3153: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3154: '</td>'.
3155: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3156: &mt('Name shown to users:').
3157: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3158: '</fieldset>'.
3159: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3160: $othertitle,$usertypes,$types,\%domhelpdesk).
3161: '<fieldset>'.
3162: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3163: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3164: \%levelscurrent,$identifier,
3165: 'LC_hidden',$prefix.$num.'_privs').
3166: '</fieldset></td>';
1.160.6.73 raeburn 3167: $itemcount ++;
3168: }
3169: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3170: my $newcust = 'custhelp'.$count;
3171: my (%privs,%levelscurrent);
3172: my %full=();
3173: my %levels= (
3174: course => {},
3175: domain => {},
3176: system => {},
3177: );
3178: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3179: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3180: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3181: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3182: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3183: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3184: for (my $k=0; $k<$maxnum+1; $k++) {
3185: my $vpos = $k+1;
3186: my $selstr;
3187: if ($k == $maxnum) {
3188: $selstr = ' selected="selected" ';
3189: }
3190: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3191: }
3192: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3193: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3194: '</label></span></td>'.
1.160.6.77 raeburn 3195: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3196: '<span class="LC_nobreak">'.
3197: &mt('Internal name:').
3198: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3199: '</span>'.(' 'x4).
3200: '<span class="LC_nobreak">'.
3201: &mt('Name shown to users:').
3202: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3203: '</span></fieldset>'.
3204: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3205: $usertypes,$types,\%domhelpdesk).
3206: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3207: &Apache::lonuserutils::custom_role_header($context,$crstype,
3208: \@templateroles,$newcust).
3209: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3210: \%levelscurrent,$newcust).
1.160.6.87! raeburn 3211: '</fieldset>'.
! 3212: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
! 3213: '</td></tr>';
1.160.6.73 raeburn 3214: $count ++;
3215: $$rowtotal += $count;
3216: }
1.160.6.5 raeburn 3217: return $datatable;
1.121 raeburn 3218: }
3219:
1.160.6.77 raeburn 3220: sub adhocbutton {
3221: my ($prefix,$num,$field,$visibility) = @_;
3222: my %lt = &Apache::lonlocal::texthash(
3223: show => 'Show details',
3224: hide => 'Hide details',
3225: );
3226: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3227: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3228: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3229: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3230: }
3231:
3232: sub helpsettings_javascript {
3233: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3234: return unless(ref($roles_by_num) eq 'ARRAY');
3235: my %html_js_lt = &Apache::lonlocal::texthash(
3236: show => 'Show details',
3237: hide => 'Hide details',
3238: );
3239: &html_escape(\%html_js_lt);
3240: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3241: return <<"ENDSCRIPT";
3242: <script type="text/javascript">
3243: // <![CDATA[
3244:
3245: function reorderHelpRoles(form,item) {
3246: var changedVal;
3247: $jstext
3248: var newpos = 'helproles_${total}_pos';
3249: var maxh = 1 + $total;
3250: var current = new Array();
3251: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3252: if (item == newpos) {
3253: changedVal = newitemVal;
3254: } else {
3255: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3256: current[newitemVal] = newpos;
3257: }
3258: for (var i=0; i<helproles.length; i++) {
3259: var elementName = 'helproles_'+helproles[i]+'_pos';
3260: if (elementName != item) {
3261: if (form.elements[elementName]) {
3262: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3263: current[currVal] = elementName;
3264: }
3265: }
3266: }
3267: var oldVal;
3268: for (var j=0; j<maxh; j++) {
3269: if (current[j] == undefined) {
3270: oldVal = j;
3271: }
3272: }
3273: if (oldVal < changedVal) {
3274: for (var k=oldVal+1; k<=changedVal ; k++) {
3275: var elementName = current[k];
3276: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3277: }
3278: } else {
3279: for (var k=changedVal; k<oldVal; k++) {
3280: var elementName = current[k];
3281: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3282: }
3283: }
3284: return;
3285: }
3286:
3287: function helpdeskAccess(num) {
3288: var curraccess = null;
3289: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3290: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3291: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3292: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3293: }
3294: }
3295: }
3296: var shown = Array();
3297: var hidden = Array();
3298: if (curraccess == 'none') {
3299: hidden = Array('$hiddenstr');
3300: } else {
3301: if (curraccess == 'status') {
3302: shown = Array('bystatus');
3303: hidden = Array('notinc','notexc');
3304: } else {
3305: if (curraccess == 'exc') {
3306: shown = Array('notexc');
3307: hidden = Array('notinc','bystatus');
3308: }
3309: if (curraccess == 'inc') {
3310: shown = Array('notinc');
3311: hidden = Array('notexc','bystatus');
3312: }
1.160.6.79 raeburn 3313: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3314: hidden = Array('notinc','notexc','bystatus');
3315: }
3316: }
3317: }
3318: if (hidden.length > 0) {
3319: for (var i=0; i<hidden.length; i++) {
3320: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3321: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3322: }
3323: }
3324: }
3325: if (shown.length > 0) {
3326: for (var i=0; i<shown.length; i++) {
3327: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3328: if (shown[i] == 'privs') {
3329: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3330: } else {
3331: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3332: }
3333: }
3334: }
3335: }
3336: return;
3337: }
3338:
3339: function toggleHelpdeskItem(num,field) {
3340: if (document.getElementById('helproles_'+num+'_'+field)) {
3341: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3342: document.getElementById('helproles_'+num+'_'+field).className =
3343: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3344: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3345: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3346: }
3347: } else {
3348: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3349: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3350: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3351: }
3352: }
3353: }
3354: return;
3355: }
3356:
3357: // ]]>
3358: </script>
3359:
3360: ENDSCRIPT
3361: }
3362:
3363: sub helpdeskroles_access {
3364: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3365: $usertypes,$types,$domhelpdesk) = @_;
3366: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3367: my %lt = &Apache::lonlocal::texthash(
3368: 'rou' => 'Role usage',
3369: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3370: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3371: 'dh' => 'All with domain helpdesk role',
3372: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3373: 'none' => 'None',
3374: 'status' => 'Determined based on institutional status',
3375: 'inc' => 'Include all, but exclude specific personnel',
3376: 'exc' => 'Exclude all, but include specific personnel',
3377: );
3378: my %usecheck = (
3379: all => ' checked="checked"',
3380: );
3381: my %displaydiv = (
3382: status => 'none',
3383: inc => 'none',
3384: exc => 'none',
3385: priv => 'block',
3386: );
3387: my $output;
3388: if (ref($current) eq 'HASH') {
3389: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3390: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3391: $usecheck{$current->{access}} = $usecheck{'all'};
3392: delete($usecheck{'all'});
3393: if ($current->{access} =~ /^(status|inc|exc)$/) {
3394: my $access = $1;
3395: $displaydiv{$access} = 'inline';
3396: } elsif ($current->{access} eq 'none') {
3397: $displaydiv{'priv'} = 'none';
3398: }
3399: }
3400: }
3401: }
3402: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3403: '<p>'.$lt{'whi'}.'</p>';
3404: foreach my $access (@{$accesstypes}) {
3405: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3406: ' onclick="helpdeskAccess('."'$num'".');" />'.
3407: $lt{$access}.'</label>';
3408: if ($access eq 'status') {
3409: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3410: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3411: $othertitle,$usertypes,$types).
3412: '</div>';
3413: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3414: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3415: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3416: '</div>';
3417: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3418: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3419: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3420: '</div>';
3421: }
3422: $output .= '</p>';
3423: }
3424: $output .= '</fieldset>';
3425: return $output;
3426: }
3427:
1.121 raeburn 3428: sub radiobutton_prefs {
1.160.6.16 raeburn 3429: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3430: $additional,$align) = @_;
1.121 raeburn 3431: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3432: (ref($choices) eq 'HASH'));
3433:
3434: my (%checkedon,%checkedoff,$datatable,$css_class);
3435:
3436: foreach my $item (@{$toggles}) {
3437: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3438: $checkedon{$item} = ' checked="checked" ';
3439: $checkedoff{$item} = ' ';
1.121 raeburn 3440: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3441: $checkedoff{$item} = ' checked="checked" ';
3442: $checkedon{$item} = ' ';
3443: }
3444: }
3445: if (ref($settings) eq 'HASH') {
1.121 raeburn 3446: foreach my $item (@{$toggles}) {
1.118 jms 3447: if ($settings->{$item} eq '1') {
3448: $checkedon{$item} = ' checked="checked" ';
3449: $checkedoff{$item} = ' ';
3450: } elsif ($settings->{$item} eq '0') {
3451: $checkedoff{$item} = ' checked="checked" ';
3452: $checkedon{$item} = ' ';
3453: }
3454: }
1.121 raeburn 3455: }
1.160.6.16 raeburn 3456: if ($onclick) {
3457: $onclick = ' onclick="'.$onclick.'"';
3458: }
1.121 raeburn 3459: foreach my $item (@{$toggles}) {
1.118 jms 3460: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3461: $datatable .=
1.160.6.16 raeburn 3462: '<tr'.$css_class.'><td valign="top">'.
3463: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3464: '</span></td>';
3465: if ($align eq 'left') {
3466: $datatable .= '<td class="LC_left_item">';
3467: } else {
3468: $datatable .= '<td class="LC_right_item">';
3469: }
3470: $datatable .=
3471: '<span class="LC_nobreak">'.
1.118 jms 3472: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3473: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3474: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3475: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3476: '</span>'.$additional.
3477: '</td>'.
1.118 jms 3478: '</tr>';
3479: $itemcount ++;
1.121 raeburn 3480: }
3481: return ($datatable,$itemcount);
3482: }
3483:
3484: sub print_coursedefaults {
1.139 raeburn 3485: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3486: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3487: my $itemcount = 1;
1.160.6.16 raeburn 3488: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3489: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3490: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3491: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3492: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3493: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3494: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3495: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3496: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3497: );
1.160.6.21 raeburn 3498: my %staticdefaults = (
3499: anonsurvey_threshold => 10,
3500: uploadquota => 500,
1.160.6.57 raeburn 3501: postsubmit => 60,
1.160.6.70 raeburn 3502: mysqltables => 172800,
1.160.6.21 raeburn 3503: );
1.139 raeburn 3504: if ($position eq 'top') {
1.160.6.57 raeburn 3505: %defaultchecked = (
3506: 'uselcmath' => 'on',
3507: 'usejsme' => 'on',
1.160.6.64 raeburn 3508: 'canclone' => 'none',
1.160.6.57 raeburn 3509: );
3510: @toggles = ('uselcmath','usejsme');
1.139 raeburn 3511: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3512: \%choices,$itemcount);
1.160.6.64 raeburn 3513: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3514: $datatable .=
3515: '<tr'.$css_class.'><td valign="top">'.
3516: '<span class="LC_nobreak">'.$choices{'canclone'}.
3517: '</span></td><td class="LC_left_item">';
3518: my $currcanclone = 'none';
3519: my $onclick;
3520: my @cloneoptions = ('none','domain');
3521: my %clonetitles = (
3522: none => 'No additional course requesters',
3523: domain => "Any course requester in course's domain",
3524: instcode => 'Course requests for official courses ...',
3525: );
3526: my (%codedefaults,@code_order,@posscodes);
3527: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3528: \@code_order) eq 'ok') {
3529: if (@code_order > 0) {
3530: push(@cloneoptions,'instcode');
3531: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3532: }
3533: }
3534: if (ref($settings) eq 'HASH') {
3535: if ($settings->{'canclone'}) {
3536: if (ref($settings->{'canclone'}) eq 'HASH') {
3537: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3538: if (@code_order > 0) {
3539: $currcanclone = 'instcode';
3540: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3541: }
3542: }
3543: } elsif ($settings->{'canclone'} eq 'domain') {
3544: $currcanclone = $settings->{'canclone'};
3545: }
3546: }
3547: }
3548: foreach my $option (@cloneoptions) {
3549: my ($checked,$additional);
3550: if ($currcanclone eq $option) {
3551: $checked = ' checked="checked"';
3552: }
3553: if ($option eq 'instcode') {
3554: if (@code_order) {
3555: my $show = 'none';
3556: if ($checked) {
3557: $show = 'block';
3558: }
3559: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3560: &mt('Institutional codes for new and cloned course have identical:').
3561: '<br />';
3562: foreach my $item (@code_order) {
3563: my $codechk;
3564: if ($checked) {
3565: if (grep(/^\Q$item\E$/,@posscodes)) {
3566: $codechk = ' checked="checked"';
3567: }
3568: }
3569: $additional .= '<label>'.
3570: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3571: $item.'</label>';
3572: }
3573: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3574: }
3575: }
3576: $datatable .=
3577: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3578: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3579: '</label> '.$additional.'</span><br />';
3580: }
3581: $datatable .= '</td>'.
3582: '</tr>';
3583: $itemcount ++;
1.139 raeburn 3584: } else {
3585: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3586: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3587: my $currusecredits = 0;
1.160.6.57 raeburn 3588: my $postsubmitclient = 1;
1.160.6.30 raeburn 3589: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3590: if (ref($settings) eq 'HASH') {
3591: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3592: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3593: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3594: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3595: }
3596: }
1.160.6.16 raeburn 3597: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3598: foreach my $type (@types) {
3599: next if ($type eq 'community');
3600: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3601: if ($defcredits{$type} ne '') {
3602: $currusecredits = 1;
3603: }
3604: }
3605: }
3606: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3607: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3608: $postsubmitclient = 0;
3609: foreach my $type (@types) {
3610: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3611: }
3612: } else {
3613: foreach my $type (@types) {
3614: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3615: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3616: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3617: } else {
3618: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3619: }
3620: } else {
3621: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3622: }
3623: }
3624: }
3625: } else {
3626: foreach my $type (@types) {
3627: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3628: }
3629: }
1.160.6.70 raeburn 3630: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3631: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3632: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3633: }
3634: } else {
3635: foreach my $type (@types) {
3636: $currmysql{$type} = $staticdefaults{'mysqltables'};
3637: }
3638: }
1.160.6.58 raeburn 3639: } else {
3640: foreach my $type (@types) {
3641: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3642: }
1.139 raeburn 3643: }
3644: if (!$currdefresponder) {
1.160.6.21 raeburn 3645: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3646: } elsif ($currdefresponder < 1) {
3647: $currdefresponder = 1;
3648: }
1.160.6.21 raeburn 3649: foreach my $type (@types) {
3650: if ($curruploadquota{$type} eq '') {
3651: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3652: }
3653: }
1.139 raeburn 3654: $datatable .=
1.160.6.16 raeburn 3655: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3656: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3657: '</span></td>'.
3658: '<td class="LC_right_item"><span class="LC_nobreak">'.
3659: '<input type="text" name="anonsurvey_threshold"'.
3660: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3661: '</td></tr>'."\n";
3662: $itemcount ++;
3663: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3664: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3665: $choices{'uploadquota'}.
3666: '</span></td>'.
3667: '<td align="right" class="LC_right_item">'.
3668: '<table><tr>';
1.160.6.21 raeburn 3669: foreach my $type (@types) {
3670: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3671: '<input type="text" name="uploadquota_'.$type.'"'.
3672: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3673: }
3674: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3675: $itemcount ++;
1.160.6.40 raeburn 3676: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3677: my $display = 'none';
3678: if ($currusecredits) {
3679: $display = 'block';
3680: }
3681: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3682: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3683: foreach my $type (@types) {
3684: next if ($type eq 'community');
3685: $additional .= '<td align="center">'.&mt($type).'<br />'.
3686: '<input type="text" name="'.$type.'_credits"'.
3687: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3688: }
3689: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3690: %defaultchecked = ('coursecredits' => 'off');
3691: @toggles = ('coursecredits');
3692: my $current = {
3693: 'coursecredits' => $currusecredits,
3694: };
3695: (my $table,$itemcount) =
3696: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3697: \%choices,$itemcount,$onclick,$additional,'left');
3698: $datatable .= $table;
3699: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3700: my $display = 'none';
3701: if ($postsubmitclient) {
3702: $display = 'block';
3703: }
3704: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3705: &mt('Number of seconds submit is disabled').'<br />'.
3706: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3707: '<table><tr>';
1.160.6.57 raeburn 3708: foreach my $type (@types) {
3709: $additional .= '<td align="center">'.&mt($type).'<br />'.
3710: '<input type="text" name="'.$type.'_timeout" value="'.
3711: $deftimeout{$type}.'" size="5" /></td>';
3712: }
3713: $additional .= '</tr></table></div>'."\n";
3714: %defaultchecked = ('postsubmit' => 'on');
3715: @toggles = ('postsubmit');
1.160.6.70 raeburn 3716: $current = {
3717: 'postsubmit' => $postsubmitclient,
3718: };
1.160.6.57 raeburn 3719: ($table,$itemcount) =
3720: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3721: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3722: $datatable .= $table;
1.160.6.70 raeburn 3723: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3724: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3725: $choices{'mysqltables'}.
3726: '</span></td>'.
3727: '<td align="right" class="LC_right_item">'.
3728: '<table><tr>';
3729: foreach my $type (@types) {
3730: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3731: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 3732: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 3733: }
3734: $datatable .= '</tr></table></td></tr>'."\n";
3735: $itemcount ++;
3736:
1.160.6.37 raeburn 3737: }
3738: $$rowtotal += $itemcount;
3739: return $datatable;
3740: }
3741:
3742: sub print_selfenrollment {
3743: my ($position,$dom,$settings,$rowtotal) = @_;
3744: my ($css_class,$datatable);
3745: my $itemcount = 1;
3746: my @types = ('official','unofficial','community','textbook');
3747: if (($position eq 'top') || ($position eq 'middle')) {
3748: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3749: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3750: my @rows;
3751: my $key;
3752: if ($position eq 'top') {
3753: $key = 'admin';
3754: if (ref($rowsref) eq 'ARRAY') {
3755: @rows = @{$rowsref};
3756: }
3757: } elsif ($position eq 'middle') {
3758: $key = 'default';
3759: @rows = ('types','registered','approval','limit');
3760: }
3761: foreach my $row (@rows) {
3762: if (defined($titlesref->{$row})) {
3763: $itemcount ++;
3764: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3765: $datatable .= '<tr'.$css_class.'>'.
3766: '<td>'.$titlesref->{$row}.'</td>'.
3767: '<td class="LC_left_item">'.
3768: '<table><tr>';
3769: my (%current,%currentcap);
3770: if (ref($settings) eq 'HASH') {
3771: if (ref($settings->{$key}) eq 'HASH') {
3772: foreach my $type (@types) {
3773: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3774: $current{$type} = $settings->{$key}->{$type}->{$row};
3775: }
3776: if (($row eq 'limit') && ($key eq 'default')) {
3777: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3778: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3779: }
3780: }
3781: }
3782: }
3783: }
3784: my %roles = (
3785: '0' => &Apache::lonnet::plaintext('dc'),
3786: );
3787:
3788: foreach my $type (@types) {
3789: unless (($row eq 'registered') && ($key eq 'default')) {
3790: $datatable .= '<th>'.&mt($type).'</th>';
3791: }
3792: }
3793: unless (($row eq 'registered') && ($key eq 'default')) {
3794: $datatable .= '</tr><tr>';
3795: }
3796: foreach my $type (@types) {
3797: if ($type eq 'community') {
3798: $roles{'1'} = &mt('Community personnel');
3799: } else {
3800: $roles{'1'} = &mt('Course personnel');
3801: }
3802: $datatable .= '<td style="vertical-align: top">';
3803: if ($position eq 'top') {
3804: my %checked;
3805: if ($current{$type} eq '0') {
3806: $checked{'0'} = ' checked="checked"';
3807: } else {
3808: $checked{'1'} = ' checked="checked"';
3809: }
3810: foreach my $role ('1','0') {
3811: $datatable .= '<span class="LC_nobreak"><label>'.
3812: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3813: 'value="'.$role.'"'.$checked{$role}.' />'.
3814: $roles{$role}.'</label></span> ';
3815: }
3816: } else {
3817: if ($row eq 'types') {
3818: my %checked;
3819: if ($current{$type} =~ /^(all|dom)$/) {
3820: $checked{$1} = ' checked="checked"';
3821: } else {
3822: $checked{''} = ' checked="checked"';
3823: }
3824: foreach my $val ('','dom','all') {
3825: $datatable .= '<span class="LC_nobreak"><label>'.
3826: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3827: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3828: }
3829: } elsif ($row eq 'registered') {
3830: my %checked;
3831: if ($current{$type} eq '1') {
3832: $checked{'1'} = ' checked="checked"';
3833: } else {
3834: $checked{'0'} = ' checked="checked"';
3835: }
3836: foreach my $val ('0','1') {
3837: $datatable .= '<span class="LC_nobreak"><label>'.
3838: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3839: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3840: }
3841: } elsif ($row eq 'approval') {
3842: my %checked;
3843: if ($current{$type} =~ /^([12])$/) {
3844: $checked{$1} = ' checked="checked"';
3845: } else {
3846: $checked{'0'} = ' checked="checked"';
3847: }
3848: for my $val (0..2) {
3849: $datatable .= '<span class="LC_nobreak"><label>'.
3850: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3851: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3852: }
3853: } elsif ($row eq 'limit') {
3854: my %checked;
3855: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3856: $checked{$1} = ' checked="checked"';
3857: } else {
3858: $checked{'none'} = ' checked="checked"';
3859: }
3860: my $cap;
3861: if ($currentcap{$type} =~ /^\d+$/) {
3862: $cap = $currentcap{$type};
3863: }
3864: foreach my $val ('none','allstudents','selfenrolled') {
3865: $datatable .= '<span class="LC_nobreak"><label>'.
3866: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3867: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3868: }
3869: $datatable .= '<br />'.
3870: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3871: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3872: '</span>';
3873: }
3874: }
3875: $datatable .= '</td>';
3876: }
3877: $datatable .= '</tr>';
3878: }
3879: $datatable .= '</table></td></tr>';
3880: }
3881: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3882: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3883: }
3884: $$rowtotal += $itemcount;
3885: return $datatable;
3886: }
3887:
3888: sub print_validation_rows {
3889: my ($caller,$dom,$settings,$rowtotal) = @_;
3890: my ($itemsref,$namesref,$fieldsref);
3891: if ($caller eq 'selfenroll') {
3892: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3893: } elsif ($caller eq 'requestcourses') {
3894: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3895: }
3896: my %currvalidation;
3897: if (ref($settings) eq 'HASH') {
3898: if (ref($settings->{'validation'}) eq 'HASH') {
3899: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3900: }
1.160.6.39 raeburn 3901: }
3902: my $datatable;
3903: my $itemcount = 0;
3904: foreach my $item (@{$itemsref}) {
3905: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3906: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3907: $namesref->{$item}.
3908: '</span></td>'.
3909: '<td class="LC_left_item">';
3910: if (($item eq 'url') || ($item eq 'button')) {
3911: $datatable .= '<span class="LC_nobreak">'.
3912: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3913: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3914: } elsif ($item eq 'fields') {
3915: my @currfields;
3916: if (ref($currvalidation{$item}) eq 'ARRAY') {
3917: @currfields = @{$currvalidation{$item}};
3918: }
3919: foreach my $field (@{$fieldsref}) {
3920: my $check = '';
3921: if (grep(/^\Q$field\E$/,@currfields)) {
3922: $check = ' checked="checked"';
3923: }
3924: $datatable .= '<span class="LC_nobreak"><label>'.
3925: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3926: ' value="'.$field.'"'.$check.' />'.$field.
3927: '</label></span> ';
3928: }
3929: } elsif ($item eq 'markup') {
1.160.6.87! raeburn 3930: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 3931: $currvalidation{$item}.
1.160.6.37 raeburn 3932: '</textarea>';
1.160.6.39 raeburn 3933: }
3934: $datatable .= '</td></tr>'."\n";
3935: if (ref($rowtotal)) {
1.160.6.37 raeburn 3936: $itemcount ++;
3937: }
1.139 raeburn 3938: }
1.160.6.39 raeburn 3939: if ($caller eq 'requestcourses') {
3940: my %currhash;
1.160.6.51 raeburn 3941: if (ref($settings) eq 'HASH') {
3942: if (ref($settings->{'validation'}) eq 'HASH') {
3943: if ($settings->{'validation'}{'dc'} ne '') {
3944: $currhash{$settings->{'validation'}{'dc'}} = 1;
3945: }
1.160.6.39 raeburn 3946: }
3947: }
3948: my $numinrow = 2;
3949: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3950: 'validationdc',%currhash);
1.160.6.50 raeburn 3951: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87! raeburn 3952: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 3953: if ($numdc > 1) {
1.160.6.50 raeburn 3954: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3955: } else {
1.160.6.50 raeburn 3956: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3957: }
1.160.6.50 raeburn 3958: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3959: $itemcount ++;
3960: }
3961: if (ref($rowtotal)) {
3962: $$rowtotal += $itemcount;
3963: }
1.121 raeburn 3964: return $datatable;
1.118 jms 3965: }
3966:
1.137 raeburn 3967: sub print_usersessions {
3968: my ($position,$dom,$settings,$rowtotal) = @_;
3969: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3970: my (%by_ip,%by_location,@intdoms);
3971: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3972:
3973: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3974: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3975: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3976: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3977: my $itemcount = 1;
3978: if ($position eq 'top') {
1.152 raeburn 3979: if (keys(%serverhomes) > 1) {
1.145 raeburn 3980: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 3981: my $curroffloadnow;
3982: if (ref($settings) eq 'HASH') {
3983: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3984: $curroffloadnow = $settings->{'offloadnow'};
3985: }
3986: }
3987: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3988: } else {
1.140 raeburn 3989: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3990: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3991: }
1.137 raeburn 3992: } else {
1.145 raeburn 3993: if (keys(%by_location) == 0) {
3994: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3995: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3996: } else {
3997: my %lt = &usersession_titles();
3998: my $numinrow = 5;
3999: my $prefix;
4000: my @types;
4001: if ($position eq 'bottom') {
4002: $prefix = 'remote';
4003: @types = ('version','excludedomain','includedomain');
4004: } else {
4005: $prefix = 'hosted';
4006: @types = ('excludedomain','includedomain');
4007: }
4008: my (%current,%checkedon,%checkedoff);
4009: my @lcversions = &Apache::lonnet::all_loncaparevs();
4010: my @locations = sort(keys(%by_location));
4011: foreach my $type (@types) {
4012: $checkedon{$type} = '';
4013: $checkedoff{$type} = ' checked="checked"';
4014: }
4015: if (ref($settings) eq 'HASH') {
4016: if (ref($settings->{$prefix}) eq 'HASH') {
4017: foreach my $key (keys(%{$settings->{$prefix}})) {
4018: $current{$key} = $settings->{$prefix}{$key};
4019: if ($key eq 'version') {
4020: if ($current{$key} ne '') {
4021: $checkedon{$key} = ' checked="checked"';
4022: $checkedoff{$key} = '';
4023: }
4024: } elsif (ref($current{$key}) eq 'ARRAY') {
4025: $checkedon{$key} = ' checked="checked"';
4026: $checkedoff{$key} = '';
4027: }
1.137 raeburn 4028: }
4029: }
4030: }
1.145 raeburn 4031: foreach my $type (@types) {
4032: next if ($type ne 'version' && !@locations);
4033: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4034: $datatable .= '<tr'.$css_class.'>
4035: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4036: <span class="LC_nobreak">
4037: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4038: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4039: if ($type eq 'version') {
4040: my $selector = '<select name="'.$prefix.'_version">';
4041: foreach my $version (@lcversions) {
4042: my $selected = '';
4043: if ($current{'version'} eq $version) {
4044: $selected = ' selected="selected"';
4045: }
4046: $selector .= ' <option value="'.$version.'"'.
4047: $selected.'>'.$version.'</option>';
4048: }
4049: $selector .= '</select> ';
4050: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4051: } else {
4052: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4053: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4054: ' />'.(' 'x2).
4055: '<input type="button" value="'.&mt('uncheck all').'" '.
4056: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4057: "\n".
4058: '</div><div><table>';
4059: my $rem;
4060: for (my $i=0; $i<@locations; $i++) {
4061: my ($showloc,$value,$checkedtype);
4062: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4063: my $ip = $by_location{$locations[$i]}->[0];
4064: if (ref($by_ip{$ip}) eq 'ARRAY') {
4065: $value = join(':',@{$by_ip{$ip}});
4066: $showloc = join(', ',@{$by_ip{$ip}});
4067: if (ref($current{$type}) eq 'ARRAY') {
4068: foreach my $loc (@{$by_ip{$ip}}) {
4069: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4070: $checkedtype = ' checked="checked"';
4071: last;
4072: }
4073: }
1.138 raeburn 4074: }
4075: }
4076: }
1.145 raeburn 4077: $rem = $i%($numinrow);
4078: if ($rem == 0) {
4079: if ($i > 0) {
4080: $datatable .= '</tr>';
4081: }
4082: $datatable .= '<tr>';
4083: }
4084: $datatable .= '<td class="LC_left_item">'.
4085: '<span class="LC_nobreak"><label>'.
4086: '<input type="checkbox" name="'.$prefix.'_'.$type.
4087: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4088: '</label></span></td>';
1.137 raeburn 4089: }
1.145 raeburn 4090: $rem = @locations%($numinrow);
4091: my $colsleft = $numinrow - $rem;
4092: if ($colsleft > 1 ) {
4093: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4094: ' </td>';
4095: } elsif ($colsleft == 1) {
4096: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4097: }
1.145 raeburn 4098: $datatable .= '</tr></table>';
1.137 raeburn 4099: }
1.145 raeburn 4100: $datatable .= '</td></tr>';
4101: $itemcount ++;
1.137 raeburn 4102: }
4103: }
4104: }
4105: $$rowtotal += $itemcount;
4106: return $datatable;
4107: }
4108:
1.138 raeburn 4109: sub build_location_hashes {
4110: my ($intdoms,$by_ip,$by_location) = @_;
4111: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4112: (ref($by_location) eq 'HASH'));
4113: my %iphost = &Apache::lonnet::get_iphost();
4114: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4115: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4116: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4117: foreach my $id (@{$iphost{$primary_ip}}) {
4118: my $intdom = &Apache::lonnet::internet_dom($id);
4119: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4120: push(@{$intdoms},$intdom);
4121: }
4122: }
4123: }
4124: foreach my $ip (keys(%iphost)) {
4125: if (ref($iphost{$ip}) eq 'ARRAY') {
4126: foreach my $id (@{$iphost{$ip}}) {
4127: my $location = &Apache::lonnet::internet_dom($id);
4128: if ($location) {
4129: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4130: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4131: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4132: push(@{$by_ip->{$ip}},$location);
4133: }
4134: } else {
4135: $by_ip->{$ip} = [$location];
4136: }
4137: }
4138: }
4139: }
4140: }
4141: foreach my $ip (sort(keys(%{$by_ip}))) {
4142: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4143: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4144: my $first = $by_ip->{$ip}->[0];
4145: if (ref($by_location->{$first}) eq 'ARRAY') {
4146: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4147: push(@{$by_location->{$first}},$ip);
4148: }
4149: } else {
4150: $by_location->{$first} = [$ip];
4151: }
4152: }
4153: }
4154: return;
4155: }
4156:
1.145 raeburn 4157: sub current_offloads_to {
4158: my ($dom,$settings,$servers) = @_;
4159: my (%spareid,%otherdomconfigs);
1.152 raeburn 4160: if (ref($servers) eq 'HASH') {
1.145 raeburn 4161: foreach my $lonhost (sort(keys(%{$servers}))) {
4162: my $gotspares;
1.152 raeburn 4163: if (ref($settings) eq 'HASH') {
4164: if (ref($settings->{'spares'}) eq 'HASH') {
4165: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4166: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4167: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4168: $gotspares = 1;
4169: }
1.145 raeburn 4170: }
4171: }
4172: unless ($gotspares) {
4173: my $gotspares;
4174: my $serverhomeID =
4175: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4176: my $serverhomedom =
4177: &Apache::lonnet::host_domain($serverhomeID);
4178: if ($serverhomedom ne $dom) {
4179: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4180: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4181: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4182: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4183: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4184: $gotspares = 1;
4185: }
4186: }
4187: } else {
4188: $otherdomconfigs{$serverhomedom} =
4189: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4190: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4191: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4192: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4193: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4194: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4195: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4196: $gotspares = 1;
4197: }
4198: }
4199: }
4200: }
4201: }
4202: }
4203: }
4204: unless ($gotspares) {
4205: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4206: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4207: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4208: } else {
4209: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4210: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4211: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4212: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4213: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4214: } else {
1.150 raeburn 4215: my %what = (
4216: spareid => 1,
4217: );
4218: my ($result,$returnhash) =
4219: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4220: if ($result eq 'ok') {
4221: if (ref($returnhash) eq 'HASH') {
4222: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4223: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4224: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4225: }
4226: }
1.145 raeburn 4227: }
4228: }
4229: }
4230: }
4231: }
4232: }
4233: return %spareid;
4234: }
4235:
4236: sub spares_row {
1.160.6.61 raeburn 4237: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4238: my $css_class;
4239: my $numinrow = 4;
4240: my $itemcount = 1;
4241: my $datatable;
1.152 raeburn 4242: my %typetitles = &sparestype_titles();
4243: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4244: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4245: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4246: my ($othercontrol,$serverdom);
4247: if ($serverhome ne $server) {
4248: $serverdom = &Apache::lonnet::host_domain($serverhome);
4249: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4250: } else {
4251: $serverdom = &Apache::lonnet::host_domain($server);
4252: if ($serverdom ne $dom) {
4253: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4254: }
4255: }
4256: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4257: my $checkednow;
4258: if (ref($curroffloadnow) eq 'HASH') {
4259: if ($curroffloadnow->{$server}) {
4260: $checkednow = ' checked="checked"';
4261: }
4262: }
1.145 raeburn 4263: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4264: $datatable .= '<tr'.$css_class.'>
4265: <td rowspan="2">
1.160.6.13 raeburn 4266: <span class="LC_nobreak">'.
4267: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4268: ,'<b>'.$server.'</b>').'</span><br />'.
4269: '<span class="LC_nobreak">'."\n".
4270: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4271: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4272: "\n";
1.145 raeburn 4273: my (%current,%canselect);
1.152 raeburn 4274: my @choices =
4275: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4276: foreach my $type ('primary','default') {
4277: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4278: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4279: my @spares = @{$spareid->{$server}{$type}};
4280: if (@spares > 0) {
1.152 raeburn 4281: if ($othercontrol) {
4282: $current{$type} = join(', ',@spares);
4283: } else {
4284: $current{$type} .= '<table>';
4285: my $numspares = scalar(@spares);
4286: for (my $i=0; $i<@spares; $i++) {
4287: my $rem = $i%($numinrow);
4288: if ($rem == 0) {
4289: if ($i > 0) {
4290: $current{$type} .= '</tr>';
4291: }
4292: $current{$type} .= '<tr>';
1.145 raeburn 4293: }
1.152 raeburn 4294: $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" id="spare_'.$type.'_'.$server.'_'.$i.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" onclick="updateNewSpares(this.form,'."'$server'".');" /> '.
4295: $spareid->{$server}{$type}[$i].
4296: '</label></td>'."\n";
4297: }
4298: my $rem = @spares%($numinrow);
4299: my $colsleft = $numinrow - $rem;
4300: if ($colsleft > 1 ) {
4301: $current{$type} .= '<td colspan="'.$colsleft.
4302: '" class="LC_left_item">'.
4303: ' </td>';
4304: } elsif ($colsleft == 1) {
4305: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4306: }
1.152 raeburn 4307: $current{$type} .= '</tr></table>';
1.150 raeburn 4308: }
1.145 raeburn 4309: }
4310: }
4311: if ($current{$type} eq '') {
4312: $current{$type} = &mt('None specified');
4313: }
1.152 raeburn 4314: if ($othercontrol) {
4315: if ($type eq 'primary') {
4316: $canselect{$type} = $othercontrol;
4317: }
4318: } else {
4319: $canselect{$type} =
4320: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4321: '<select name="newspare_'.$type.'_'.$server.'" '.
4322: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4323: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4324: if (@choices > 0) {
4325: foreach my $lonhost (@choices) {
4326: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4327: }
4328: }
4329: $canselect{$type} .= '</select>'."\n";
4330: }
4331: } else {
4332: $current{$type} = &mt('Could not be determined');
4333: if ($type eq 'primary') {
4334: $canselect{$type} = $othercontrol;
4335: }
1.145 raeburn 4336: }
1.152 raeburn 4337: if ($type eq 'default') {
4338: $datatable .= '<tr'.$css_class.'>';
4339: }
4340: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4341: '<td>'.$current{$type}.'</td>'."\n".
4342: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4343: }
4344: $itemcount ++;
4345: }
4346: }
4347: $$rowtotal += $itemcount;
4348: return $datatable;
4349: }
4350:
1.152 raeburn 4351: sub possible_newspares {
4352: my ($server,$currspares,$serverhomes,$altids) = @_;
4353: my $serverhostname = &Apache::lonnet::hostname($server);
4354: my %excluded;
4355: if ($serverhostname ne '') {
4356: %excluded = (
4357: $serverhostname => 1,
4358: );
4359: }
4360: if (ref($currspares) eq 'HASH') {
4361: foreach my $type (keys(%{$currspares})) {
4362: if (ref($currspares->{$type}) eq 'ARRAY') {
4363: if (@{$currspares->{$type}} > 0) {
4364: foreach my $curr (@{$currspares->{$type}}) {
4365: my $hostname = &Apache::lonnet::hostname($curr);
4366: $excluded{$hostname} = 1;
4367: }
4368: }
4369: }
4370: }
4371: }
4372: my @choices;
4373: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4374: if (keys(%{$serverhomes}) > 1) {
4375: foreach my $name (sort(keys(%{$serverhomes}))) {
4376: unless ($excluded{$name}) {
4377: if (exists($altids->{$serverhomes->{$name}})) {
4378: push(@choices,$altids->{$serverhomes->{$name}});
4379: } else {
4380: push(@choices,$serverhomes->{$name});
1.145 raeburn 4381: }
4382: }
4383: }
4384: }
4385: }
1.152 raeburn 4386: return sort(@choices);
1.145 raeburn 4387: }
4388:
1.150 raeburn 4389: sub print_loadbalancing {
4390: my ($dom,$settings,$rowtotal) = @_;
4391: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4392: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4393: my $numinrow = 1;
4394: my $datatable;
4395: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 4396: my (%currbalancer,%currtargets,%currrules,%existing);
4397: if (ref($settings) eq 'HASH') {
4398: %existing = %{$settings};
4399: }
4400: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4401: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4402: \%currtargets,\%currrules);
1.150 raeburn 4403: } else {
4404: return;
4405: }
4406: my ($othertitle,$usertypes,$types) =
4407: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 4408: my $rownum = 8;
1.150 raeburn 4409: if (ref($types) eq 'ARRAY') {
4410: $rownum += scalar(@{$types});
4411: }
1.160.6.7 raeburn 4412: my @css_class = ('LC_odd_row','LC_even_row');
4413: my $balnum = 0;
4414: my $islast;
4415: my (@toshow,$disabledtext);
4416: if (keys(%currbalancer) > 0) {
4417: @toshow = sort(keys(%currbalancer));
4418: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4419: push(@toshow,'');
4420: }
4421: } else {
4422: @toshow = ('');
4423: $disabledtext = &mt('No existing load balancer');
4424: }
4425: foreach my $lonhost (@toshow) {
4426: if ($balnum == scalar(@toshow)-1) {
4427: $islast = 1;
4428: } else {
4429: $islast = 0;
4430: }
4431: my $cssidx = $balnum%2;
4432: my $targets_div_style = 'display: none';
4433: my $disabled_div_style = 'display: block';
4434: my $homedom_div_style = 'display: none';
4435: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4436: '<td rowspan="'.$rownum.'" valign="top">'.
4437: '<p>';
4438: if ($lonhost eq '') {
4439: $datatable .= '<span class="LC_nobreak">';
4440: if (keys(%currbalancer) > 0) {
4441: $datatable .= &mt('Add balancer:');
4442: } else {
4443: $datatable .= &mt('Enable balancer:');
4444: }
4445: $datatable .= ' '.
4446: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4447: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4448: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4449: '<option value="" selected="selected">'.&mt('None').
4450: '</option>'."\n";
4451: foreach my $server (sort(keys(%servers))) {
4452: next if ($currbalancer{$server});
4453: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4454: }
4455: $datatable .=
4456: '</select>'."\n".
4457: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4458: } else {
4459: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4460: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4461: &mt('Stop balancing').'</label>'.
4462: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4463: $targets_div_style = 'display: block';
4464: $disabled_div_style = 'display: none';
4465: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4466: $homedom_div_style = 'display: block';
4467: }
4468: }
4469: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4470: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4471: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4472: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4473: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4474: my @sparestypes = ('primary','default');
4475: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 4476: my %hostherechecked = (
4477: no => ' checked="checked"',
4478: );
1.160.6.7 raeburn 4479: foreach my $sparetype (@sparestypes) {
4480: my $targettable;
4481: for (my $i=0; $i<$numspares; $i++) {
4482: my $checked;
4483: if (ref($currtargets{$lonhost}) eq 'HASH') {
4484: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4485: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4486: $checked = ' checked="checked"';
4487: }
4488: }
4489: }
4490: my ($chkboxval,$disabled);
4491: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4492: $chkboxval = $spares[$i];
4493: }
4494: if (exists($currbalancer{$spares[$i]})) {
4495: $disabled = ' disabled="disabled"';
4496: }
4497: $targettable .=
1.160.6.55 raeburn 4498: '<td><span class="LC_nobreak"><label>'.
4499: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 4500: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.160.6.55 raeburn 4501: '</span></label></span></td>';
1.160.6.7 raeburn 4502: my $rem = $i%($numinrow);
4503: if ($rem == 0) {
4504: if (($i > 0) && ($i < $numspares-1)) {
4505: $targettable .= '</tr>';
4506: }
4507: if ($i < $numspares-1) {
4508: $targettable .= '<tr>';
1.150 raeburn 4509: }
4510: }
4511: }
1.160.6.7 raeburn 4512: if ($targettable ne '') {
4513: my $rem = $numspares%($numinrow);
4514: my $colsleft = $numinrow - $rem;
4515: if ($colsleft > 1 ) {
4516: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4517: ' </td>';
4518: } elsif ($colsleft == 1) {
4519: $targettable .= '<td class="LC_left_item"> </td>';
4520: }
4521: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4522: '<table><tr>'.$targettable.'</tr></table><br />';
4523: }
1.160.6.76 raeburn 4524: $hostherechecked{$sparetype} = '';
4525: if (ref($currtargets{$lonhost}) eq 'HASH') {
4526: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4527: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4528: $hostherechecked{$sparetype} = ' checked="checked"';
4529: $hostherechecked{'no'} = '';
4530: }
4531: }
4532: }
4533: }
4534: $datatable .= &mt('Hosting on balancer itself').'<br />'.
4535: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
4536: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
4537: foreach my $sparetype (@sparestypes) {
4538: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
4539: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
4540: '</i></label><br />';
1.160.6.7 raeburn 4541: }
4542: $datatable .= '</div></td></tr>'.
4543: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4544: $othertitle,$usertypes,$types,\%servers,
4545: \%currbalancer,$lonhost,
4546: $targets_div_style,$homedom_div_style,
4547: $css_class[$cssidx],$balnum,$islast);
4548: $$rowtotal += $rownum;
4549: $balnum ++;
4550: }
4551: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4552: return $datatable;
4553: }
4554:
4555: sub get_loadbalancers_config {
4556: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4557: return unless ((ref($servers) eq 'HASH') &&
4558: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4559: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4560: if (keys(%{$existing}) > 0) {
4561: my $oldlonhost;
4562: foreach my $key (sort(keys(%{$existing}))) {
4563: if ($key eq 'lonhost') {
4564: $oldlonhost = $existing->{'lonhost'};
4565: $currbalancer->{$oldlonhost} = 1;
4566: } elsif ($key eq 'targets') {
4567: if ($oldlonhost) {
4568: $currtargets->{$oldlonhost} = $existing->{'targets'};
4569: }
4570: } elsif ($key eq 'rules') {
4571: if ($oldlonhost) {
4572: $currrules->{$oldlonhost} = $existing->{'rules'};
4573: }
4574: } elsif (ref($existing->{$key}) eq 'HASH') {
4575: $currbalancer->{$key} = 1;
4576: $currtargets->{$key} = $existing->{$key}{'targets'};
4577: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4578: }
4579: }
1.160.6.7 raeburn 4580: } else {
4581: my ($balancerref,$targetsref) =
4582: &Apache::lonnet::get_lonbalancer_config($servers);
4583: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4584: foreach my $server (sort(keys(%{$balancerref}))) {
4585: $currbalancer->{$server} = 1;
4586: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4587: }
4588: }
4589: }
1.160.6.7 raeburn 4590: return;
1.150 raeburn 4591: }
4592:
4593: sub loadbalancing_rules {
4594: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 4595: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4596: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4597: my $output;
1.160.6.7 raeburn 4598: my $num = 0;
4599: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4600: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4601: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4602: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 4603: $num ++;
1.150 raeburn 4604: my $current;
4605: if (ref($currrules) eq 'HASH') {
4606: $current = $currrules->{$type};
4607: }
1.160.6.55 raeburn 4608: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 4609: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4610: $current = '';
4611: }
4612: }
4613: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 4614: $servers,$currbalancer,$lonhost,$dom,
4615: $targets_div_style,$homedom_div_style,
4616: $css_class,$balnum,$num,$islast);
1.150 raeburn 4617: }
4618: }
4619: return $output;
4620: }
4621:
4622: sub loadbalancing_titles {
4623: my ($dom,$intdom,$usertypes,$types) = @_;
4624: my %othertypes = (
4625: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4626: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4627: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4628: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 4629: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4630: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4631: );
1.160.6.26 raeburn 4632: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4633: if (ref($types) eq 'ARRAY') {
4634: unshift(@alltypes,@{$types},'default');
4635: }
4636: my %titles;
4637: foreach my $type (@alltypes) {
4638: if ($type =~ /^_LC_/) {
4639: $titles{$type} = $othertypes{$type};
4640: } elsif ($type eq 'default') {
4641: $titles{$type} = &mt('All users from [_1]',$dom);
4642: if (ref($types) eq 'ARRAY') {
4643: if (@{$types} > 0) {
4644: $titles{$type} = &mt('Other users from [_1]',$dom);
4645: }
4646: }
4647: } elsif (ref($usertypes) eq 'HASH') {
4648: $titles{$type} = $usertypes->{$type};
4649: }
4650: }
4651: return (\@alltypes,\%othertypes,\%titles);
4652: }
4653:
4654: sub loadbalance_rule_row {
1.160.6.7 raeburn 4655: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4656: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4657: my @rulenames;
1.150 raeburn 4658: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4659: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4660: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4661: } else {
1.160.6.26 raeburn 4662: @rulenames = ('default','homeserver');
4663: if ($type eq '_LC_external') {
4664: push(@rulenames,'externalbalancer');
4665: } else {
4666: push(@rulenames,'specific');
4667: }
4668: push(@rulenames,'none');
1.150 raeburn 4669: }
4670: my $style = $targets_div_style;
1.160.6.55 raeburn 4671: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4672: $style = $homedom_div_style;
4673: }
1.160.6.7 raeburn 4674: my $space;
4675: if ($islast && $num == 1) {
4676: $space = '<div display="inline-block"> </div>';
4677: }
4678: my $output =
4679: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4680: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4681: '<td valaign="top">'.$space.
4682: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4683: for (my $i=0; $i<@rulenames; $i++) {
4684: my $rule = $rulenames[$i];
4685: my ($checked,$extra);
4686: if ($rulenames[$i] eq 'default') {
4687: $rule = '';
4688: }
4689: if ($rulenames[$i] eq 'specific') {
4690: if (ref($servers) eq 'HASH') {
4691: my $default;
4692: if (($current ne '') && (exists($servers->{$current}))) {
4693: $checked = ' checked="checked"';
4694: }
4695: unless ($checked) {
4696: $default = ' selected="selected"';
4697: }
1.160.6.7 raeburn 4698: $extra =
4699: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4700: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4701: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4702: '<option value=""'.$default.'></option>'."\n";
4703: foreach my $server (sort(keys(%{$servers}))) {
4704: if (ref($currbalancer) eq 'HASH') {
4705: next if (exists($currbalancer->{$server}));
4706: }
1.150 raeburn 4707: my $selected;
1.160.6.7 raeburn 4708: if ($server eq $current) {
1.150 raeburn 4709: $selected = ' selected="selected"';
4710: }
1.160.6.7 raeburn 4711: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4712: }
4713: $extra .= '</select>';
4714: }
4715: } elsif ($rule eq $current) {
4716: $checked = ' checked="checked"';
4717: }
4718: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4719: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4720: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4721: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4722: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4723: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4724: $output .= $ruletitles{'particular'};
4725: } else {
4726: $output .= $ruletitles{$rulenames[$i]};
4727: }
4728: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4729: }
4730: $output .= '</div></td></tr>'."\n";
4731: return $output;
4732: }
4733:
4734: sub offloadtype_text {
4735: my %ruletitles = &Apache::lonlocal::texthash (
4736: 'default' => 'Offloads to default destinations',
4737: 'homeserver' => "Offloads to user's home server",
4738: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4739: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4740: 'none' => 'No offload',
1.160.6.26 raeburn 4741: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4742: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4743: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4744: );
4745: return %ruletitles;
4746: }
4747:
4748: sub sparestype_titles {
4749: my %typestitles = &Apache::lonlocal::texthash (
4750: 'primary' => 'primary',
4751: 'default' => 'default',
4752: );
4753: return %typestitles;
4754: }
4755:
1.28 raeburn 4756: sub contact_titles {
4757: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 4758: 'supportemail' => 'Support E-mail address',
4759: 'adminemail' => 'Default Server Admin E-mail address',
4760: 'errormail' => 'Error reports to be e-mailed to',
4761: 'packagesmail' => 'Package update alerts to be e-mailed to',
4762: 'helpdeskmail' => "Helpdesk requests for this domain's users",
4763: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
4764: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
4765: 'requestsmail' => 'E-mail from course requests requiring approval',
4766: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4767: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4768: );
4769: my %short_titles = &Apache::lonlocal::texthash (
4770: adminemail => 'Admin E-mail address',
4771: supportemail => 'Support E-mail',
4772: );
4773: return (\%titles,\%short_titles);
4774: }
4775:
1.160.6.78 raeburn 4776: sub helpform_fields {
4777: my %titles = &Apache::lonlocal::texthash (
4778: 'username' => 'Name',
4779: 'user' => 'Username/domain',
4780: 'phone' => 'Phone',
4781: 'cc' => 'Cc e-mail',
4782: 'course' => 'Course Details',
4783: 'section' => 'Sections',
4784: 'screenshot' => 'File upload',
4785: );
4786: my @fields = ('username','phone','user','course','section','cc','screenshot');
4787: my %possoptions = (
4788: username => ['yes','no','req'],
4789: phone => ['yes','no','req'],
4790: user => ['yes','no'],
4791: cc => ['yes','no'],
4792: course => ['yes','no'],
4793: section => ['yes','no'],
4794: screenshot => ['yes','no'],
4795: );
4796: my %fieldoptions = &Apache::lonlocal::texthash (
4797: 'yes' => 'Optional',
4798: 'req' => 'Required',
4799: 'no' => "Not shown",
4800: );
4801: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
4802: }
4803:
1.72 raeburn 4804: sub tool_titles {
4805: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4806: aboutme => 'Personal web page',
1.86 raeburn 4807: blog => 'Blog',
1.160.6.4 raeburn 4808: webdav => 'WebDAV',
1.86 raeburn 4809: portfolio => 'Portfolio',
1.88 bisitz 4810: official => 'Official courses (with institutional codes)',
4811: unofficial => 'Unofficial courses',
1.98 raeburn 4812: community => 'Communities',
1.160.6.30 raeburn 4813: textbook => 'Textbook courses',
1.86 raeburn 4814: );
1.72 raeburn 4815: return %titles;
4816: }
4817:
1.101 raeburn 4818: sub courserequest_titles {
4819: my %titles = &Apache::lonlocal::texthash (
4820: official => 'Official',
4821: unofficial => 'Unofficial',
4822: community => 'Communities',
1.160.6.30 raeburn 4823: textbook => 'Textbook',
1.101 raeburn 4824: norequest => 'Not allowed',
1.104 raeburn 4825: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4826: validate => 'With validation',
4827: autolimit => 'Numerical limit',
1.103 raeburn 4828: unlimited => '(blank for unlimited)',
1.101 raeburn 4829: );
4830: return %titles;
4831: }
4832:
1.160.6.5 raeburn 4833: sub authorrequest_titles {
4834: my %titles = &Apache::lonlocal::texthash (
4835: norequest => 'Not allowed',
4836: approval => 'Approval by Dom. Coord.',
4837: automatic => 'Automatic approval',
4838: );
4839: return %titles;
4840: }
4841:
1.101 raeburn 4842: sub courserequest_conditions {
4843: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4844: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4845: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4846: );
4847: return %conditions;
4848: }
4849:
4850:
1.27 raeburn 4851: sub print_usercreation {
1.30 raeburn 4852: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4853: my $numinrow = 4;
1.28 raeburn 4854: my $datatable;
4855: if ($position eq 'top') {
1.30 raeburn 4856: $$rowtotal ++;
1.34 raeburn 4857: my $rowcount = 0;
1.32 raeburn 4858: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4859: if (ref($rules) eq 'HASH') {
4860: if (keys(%{$rules}) > 0) {
1.32 raeburn 4861: $datatable .= &user_formats_row('username',$settings,$rules,
4862: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4863: $$rowtotal ++;
1.32 raeburn 4864: $rowcount ++;
4865: }
4866: }
4867: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4868: if (ref($idrules) eq 'HASH') {
4869: if (keys(%{$idrules}) > 0) {
4870: $datatable .= &user_formats_row('id',$settings,$idrules,
4871: $idruleorder,$numinrow,$rowcount);
4872: $$rowtotal ++;
4873: $rowcount ++;
1.28 raeburn 4874: }
4875: }
1.39 raeburn 4876: if ($rowcount == 0) {
4877: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4878: $$rowtotal ++;
4879: $rowcount ++;
4880: }
1.34 raeburn 4881: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4882: my @creators = ('author','course','requestcrs');
1.37 raeburn 4883: my ($rules,$ruleorder) =
4884: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4885: my %lt = &usercreation_types();
4886: my %checked;
4887: if (ref($settings) eq 'HASH') {
4888: if (ref($settings->{'cancreate'}) eq 'HASH') {
4889: foreach my $item (@creators) {
4890: $checked{$item} = $settings->{'cancreate'}{$item};
4891: }
4892: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4893: foreach my $item (@creators) {
4894: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4895: $checked{$item} = 'none';
4896: }
4897: }
4898: }
4899: }
4900: my $rownum = 0;
4901: foreach my $item (@creators) {
4902: $rownum ++;
1.160.6.34 raeburn 4903: if ($checked{$item} eq '') {
4904: $checked{$item} = 'any';
1.34 raeburn 4905: }
4906: my $css_class;
4907: if ($rownum%2) {
4908: $css_class = '';
4909: } else {
4910: $css_class = ' class="LC_odd_row" ';
4911: }
4912: $datatable .= '<tr'.$css_class.'>'.
4913: '<td><span class="LC_nobreak">'.$lt{$item}.
4914: '</span></td><td align="right">';
1.160.6.34 raeburn 4915: my @options = ('any');
4916: if (ref($rules) eq 'HASH') {
4917: if (keys(%{$rules}) > 0) {
4918: push(@options,('official','unofficial'));
1.37 raeburn 4919: }
4920: }
1.160.6.34 raeburn 4921: push(@options,'none');
1.37 raeburn 4922: foreach my $option (@options) {
1.50 raeburn 4923: my $type = 'radio';
1.34 raeburn 4924: my $check = ' ';
1.160.6.34 raeburn 4925: if ($checked{$item} eq $option) {
4926: $check = ' checked="checked" ';
1.34 raeburn 4927: }
4928: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4929: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4930: $item.'" value="'.$option.'"'.$check.'/> '.
4931: $lt{$option}.'</label> </span>';
4932: }
4933: $datatable .= '</td></tr>';
4934: }
1.28 raeburn 4935: } else {
4936: my @contexts = ('author','course','domain');
4937: my @authtypes = ('int','krb4','krb5','loc');
4938: my %checked;
4939: if (ref($settings) eq 'HASH') {
4940: if (ref($settings->{'authtypes'}) eq 'HASH') {
4941: foreach my $item (@contexts) {
4942: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4943: foreach my $auth (@authtypes) {
4944: if ($settings->{'authtypes'}{$item}{$auth}) {
4945: $checked{$item}{$auth} = ' checked="checked" ';
4946: }
4947: }
4948: }
4949: }
1.27 raeburn 4950: }
1.35 raeburn 4951: } else {
4952: foreach my $item (@contexts) {
1.36 raeburn 4953: foreach my $auth (@authtypes) {
1.35 raeburn 4954: $checked{$item}{$auth} = ' checked="checked" ';
4955: }
4956: }
1.27 raeburn 4957: }
1.28 raeburn 4958: my %title = &context_names();
4959: my %authname = &authtype_names();
4960: my $rownum = 0;
4961: my $css_class;
4962: foreach my $item (@contexts) {
4963: if ($rownum%2) {
4964: $css_class = '';
4965: } else {
4966: $css_class = ' class="LC_odd_row" ';
4967: }
1.30 raeburn 4968: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4969: '<td>'.$title{$item}.
4970: '</td><td class="LC_left_item">'.
4971: '<span class="LC_nobreak">';
4972: foreach my $auth (@authtypes) {
4973: $datatable .= '<label>'.
4974: '<input type="checkbox" name="'.$item.'_auth" '.
4975: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4976: $authname{$auth}.'</label> ';
4977: }
4978: $datatable .= '</span></td></tr>';
4979: $rownum ++;
1.27 raeburn 4980: }
1.30 raeburn 4981: $$rowtotal += $rownum;
1.27 raeburn 4982: }
4983: return $datatable;
4984: }
4985:
1.160.6.34 raeburn 4986: sub print_selfcreation {
4987: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4988: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4989: if (ref($settings) eq 'HASH') {
4990: if (ref($settings->{'cancreate'}) eq 'HASH') {
4991: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4992: if (ref($createsettings) eq 'HASH') {
4993: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4994: @selfcreate = @{$createsettings->{'selfcreate'}};
4995: } elsif ($createsettings->{'selfcreate'} ne '') {
4996: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4997: @selfcreate = ('email','login','sso');
4998: } elsif ($createsettings->{'selfcreate'} ne 'none') {
4999: @selfcreate = ($createsettings->{'selfcreate'});
5000: }
5001: }
5002: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5003: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5004: }
5005: }
5006: }
5007: }
5008: my %radiohash;
5009: my $numinrow = 4;
5010: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5011: if ($position eq 'top') {
5012: my %choices = &Apache::lonlocal::texthash (
5013: cancreate_login => 'Institutional Login',
5014: cancreate_sso => 'Institutional Single Sign On',
5015: );
5016: my @toggles = sort(keys(%choices));
5017: my %defaultchecked = (
5018: 'cancreate_login' => 'off',
5019: 'cancreate_sso' => 'off',
5020: );
1.160.6.35 raeburn 5021: my ($onclick,$itemcount);
1.160.6.34 raeburn 5022: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5023: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5024: $$rowtotal += $itemcount;
1.160.6.39 raeburn 5025:
1.160.6.34 raeburn 5026: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5027:
5028: if (ref($usertypes) eq 'HASH') {
5029: if (keys(%{$usertypes}) > 0) {
5030: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5031: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 5032: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 5033: $$rowtotal ++;
5034: }
5035: }
1.160.6.44 raeburn 5036: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5037: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5038: $fieldtitles{'inststatus'} = &mt('Institutional status');
5039: my $rem;
5040: my $numperrow = 2;
5041: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5042: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5043: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5044: '<td class="LC_left_item">'."\n".
1.160.6.87! raeburn 5045: '<table>'."\n";
1.160.6.44 raeburn 5046: for (my $i=0; $i<@fields; $i++) {
5047: $rem = $i%($numperrow);
5048: if ($rem == 0) {
5049: if ($i > 0) {
5050: $datatable .= '</tr>';
5051: }
5052: $datatable .= '<tr>';
5053: }
5054: my $currval;
1.160.6.51 raeburn 5055: if (ref($createsettings) eq 'HASH') {
5056: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5057: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5058: }
1.160.6.44 raeburn 5059: }
5060: $datatable .= '<td class="LC_left_item">'.
5061: '<span class="LC_nobreak">'.
5062: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5063: 'value="'.$currval.'" size="10" /> '.
5064: $fieldtitles{$fields[$i]}.'</span></td>';
5065: }
5066: my $colsleft = $numperrow - $rem;
5067: if ($colsleft > 1 ) {
5068: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5069: ' </td>';
5070: } elsif ($colsleft == 1) {
5071: $datatable .= '<td class="LC_left_item"> </td>';
5072: }
5073: $datatable .= '</tr></table></td></tr>';
5074: $$rowtotal ++;
1.160.6.34 raeburn 5075: } elsif ($position eq 'middle') {
5076: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5077: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5078: $usertypes->{'default'} = $othertitle;
5079: if (ref($types) eq 'ARRAY') {
5080: push(@{$types},'default');
5081: $usertypes->{'default'} = $othertitle;
5082: foreach my $status (@{$types}) {
5083: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 5084: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 5085: $$rowtotal ++;
1.160.6.34 raeburn 5086: }
5087: }
5088: } else {
1.160.6.40 raeburn 5089: my %choices = &Apache::lonlocal::texthash (
5090: cancreate_email => 'E-mail address as username',
5091: );
5092: my @toggles = sort(keys(%choices));
5093: my %defaultchecked = (
5094: 'cancreate_email' => 'off',
5095: );
5096: my $itemcount = 0;
5097: my $display = 'none';
5098: if (grep(/^\Qemail\E$/,@selfcreate)) {
5099: $display = 'block';
5100: }
5101: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5102: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5103: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5104: my $usertypes = {};
5105: my $order = [];
5106: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5107: $usertypes = $domdefaults{'inststatustypes'};
5108: $order = $domdefaults{'inststatusguest'};
5109: }
5110: if (ref($order) eq 'ARRAY') {
5111: push(@{$order},'default');
5112: if (@{$order} > 1) {
5113: $usertypes->{'default'} = &mt('Other users');
5114: $additional .= '<table><tr>';
5115: foreach my $status (@{$order}) {
5116: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5117: }
5118: $additional .= '</tr><tr>';
5119: foreach my $status (@{$order}) {
5120: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 5121: }
1.160.6.40 raeburn 5122: $additional .= '</tr></table>';
1.160.6.34 raeburn 5123: } else {
1.160.6.40 raeburn 5124: $usertypes->{'default'} = &mt('All users');
5125: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 5126: }
5127: }
1.160.6.40 raeburn 5128: $additional .= '</div>'."\n";
5129:
5130: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 5131: \%choices,$$rowtotal,$onclick,$additional);
5132: $$rowtotal ++;
1.160.6.40 raeburn 5133: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 5134: $$rowtotal ++;
1.160.6.35 raeburn 5135: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5136: $numinrow = 1;
1.160.6.40 raeburn 5137: if (ref($order) eq 'ARRAY') {
5138: foreach my $status (@{$order}) {
1.160.6.35 raeburn 5139: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5140: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5141: $$rowtotal ++;
5142: }
5143: }
1.160.6.34 raeburn 5144: my ($emailrules,$emailruleorder) =
5145: &Apache::lonnet::inst_userrules($dom,'email');
5146: if (ref($emailrules) eq 'HASH') {
5147: if (keys(%{$emailrules}) > 0) {
5148: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 5149: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 5150: $$rowtotal ++;
5151: }
5152: }
1.160.6.35 raeburn 5153: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 5154: }
5155: return $datatable;
5156: }
5157:
1.160.6.40 raeburn 5158: sub email_as_username {
5159: my ($rowtotal,$processing,$type) = @_;
5160: my %choices =
5161: &Apache::lonlocal::texthash (
5162: automatic => 'Automatic approval',
5163: approval => 'Queued for approval',
5164: );
5165: my $output;
5166: foreach my $option ('automatic','approval') {
5167: my $checked;
5168: if (ref($processing) eq 'HASH') {
5169: if ($type eq '') {
5170: if (!exists($processing->{'default'})) {
5171: if ($option eq 'automatic') {
5172: $checked = ' checked="checked"';
5173: }
5174: } else {
5175: if ($processing->{'default'} eq $option) {
5176: $checked = ' checked="checked"';
5177: }
5178: }
5179: } else {
5180: if (!exists($processing->{$type})) {
5181: if ($option eq 'automatic') {
5182: $checked = ' checked="checked"';
5183: }
5184: } else {
5185: if ($processing->{$type} eq $option) {
5186: $checked = ' checked="checked"';
5187: }
5188: }
5189: }
5190: } elsif ($option eq 'automatic') {
5191: $checked = ' checked="checked"';
5192: }
5193: my $name = 'cancreate_emailprocess';
5194: if (($type ne '') && ($type ne 'default')) {
5195: $name .= '_'.$type;
5196: }
5197: $output .= '<span class="LC_nobreak"><label>'.
5198: '<input type="radio" name="'.$name.'"'.
5199: $checked.' value="'.$option.'" />'.
5200: $choices{$option}.'</label></span>';
5201: if ($type eq '') {
5202: $output .= ' ';
5203: } else {
5204: $output .= '<br />';
5205: }
5206: }
5207: $$rowtotal ++;
5208: return $output;
5209: }
5210:
1.160.6.5 raeburn 5211: sub captcha_choice {
5212: my ($context,$settings,$itemcount) = @_;
1.160.6.69 raeburn 5213: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5214: $vertext,$currver);
1.160.6.5 raeburn 5215: my %lt = &captcha_phrases();
5216: $keyentry = 'hidden';
5217: if ($context eq 'cancreate') {
1.160.6.34 raeburn 5218: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 5219: } elsif ($context eq 'login') {
5220: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5221: }
5222: if (ref($settings) eq 'HASH') {
5223: if ($settings->{'captcha'}) {
5224: $checked{$settings->{'captcha'}} = ' checked="checked"';
5225: } else {
5226: $checked{'original'} = ' checked="checked"';
5227: }
5228: if ($settings->{'captcha'} eq 'recaptcha') {
5229: $pubtext = $lt{'pub'};
5230: $privtext = $lt{'priv'};
5231: $keyentry = 'text';
1.160.6.69 raeburn 5232: $vertext = $lt{'ver'};
5233: $currver = $settings->{'recaptchaversion'};
5234: if ($currver ne '2') {
5235: $currver = 1;
5236: }
1.160.6.5 raeburn 5237: }
5238: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5239: $currpub = $settings->{'recaptchakeys'}{'public'};
5240: $currpriv = $settings->{'recaptchakeys'}{'private'};
5241: }
5242: } else {
5243: $checked{'original'} = ' checked="checked"';
5244: }
5245: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5246: my $output = '<tr'.$css_class.'>'.
5247: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5248: '<table><tr><td>'."\n";
5249: foreach my $option ('original','recaptcha','notused') {
5250: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5251: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5252: $lt{$option}.'</label></span>';
5253: unless ($option eq 'notused') {
5254: $output .= (' 'x2)."\n";
5255: }
5256: }
5257: #
5258: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5259: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5260: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5261: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5262: #
5263: $output .= '</td></tr>'."\n".
5264: '<tr><td>'."\n".
5265: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5266: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5267: $currpub.'" size="40" /></span><br />'."\n".
5268: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5269: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 5270: $currpriv.'" size="40" /></span><br />'.
5271: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5272: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5273: $currver.'" size="3" /></span><br />'.
5274: '</td></tr></table>'."\n".
1.160.6.5 raeburn 5275: '</td></tr>';
5276: return $output;
5277: }
5278:
1.32 raeburn 5279: sub user_formats_row {
5280: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5281: my $output;
5282: my %text = (
5283: 'username' => 'new usernames',
5284: 'id' => 'IDs',
1.45 raeburn 5285: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5286: );
5287: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5288: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5289: '<td><span class="LC_nobreak">';
5290: if ($type eq 'email') {
5291: $output .= &mt("Formats disallowed for $text{$type}: ");
5292: } else {
5293: $output .= &mt("Format rules to check for $text{$type}: ");
5294: }
5295: $output .= '</span></td>'.
5296: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5297: my $rem;
5298: if (ref($ruleorder) eq 'ARRAY') {
5299: for (my $i=0; $i<@{$ruleorder}; $i++) {
5300: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5301: my $rem = $i%($numinrow);
5302: if ($rem == 0) {
5303: if ($i > 0) {
5304: $output .= '</tr>';
5305: }
5306: $output .= '<tr>';
5307: }
5308: my $check = ' ';
1.39 raeburn 5309: if (ref($settings) eq 'HASH') {
5310: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5311: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5312: $check = ' checked="checked" ';
5313: }
1.27 raeburn 5314: }
5315: }
5316: $output .= '<td class="LC_left_item">'.
5317: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5318: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5319: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5320: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5321: }
5322: }
5323: $rem = @{$ruleorder}%($numinrow);
5324: }
5325: my $colsleft = $numinrow - $rem;
5326: if ($colsleft > 1 ) {
5327: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5328: ' </td>';
5329: } elsif ($colsleft == 1) {
5330: $output .= '<td class="LC_left_item"> </td>';
5331: }
5332: $output .= '</tr></table></td></tr>';
5333: return $output;
5334: }
5335:
1.34 raeburn 5336: sub usercreation_types {
5337: my %lt = &Apache::lonlocal::texthash (
5338: author => 'When adding a co-author',
5339: course => 'When adding a user to a course',
1.100 raeburn 5340: requestcrs => 'When requesting a course',
1.34 raeburn 5341: any => 'Any',
5342: official => 'Institutional only ',
5343: unofficial => 'Non-institutional only',
5344: none => 'None',
5345: );
5346: return %lt;
1.48 raeburn 5347: }
1.34 raeburn 5348:
1.160.6.34 raeburn 5349: sub selfcreation_types {
5350: my %lt = &Apache::lonlocal::texthash (
5351: selfcreate => 'User creates own account',
5352: any => 'Any',
5353: official => 'Institutional only ',
5354: unofficial => 'Non-institutional only',
5355: email => 'E-mail address',
5356: login => 'Institutional Login',
5357: sso => 'SSO',
5358: );
5359: }
5360:
1.28 raeburn 5361: sub authtype_names {
5362: my %lt = &Apache::lonlocal::texthash(
5363: int => 'Internal',
5364: krb4 => 'Kerberos 4',
5365: krb5 => 'Kerberos 5',
5366: loc => 'Local',
5367: );
5368: return %lt;
5369: }
5370:
5371: sub context_names {
5372: my %context_title = &Apache::lonlocal::texthash(
5373: author => 'Creating users when an Author',
5374: course => 'Creating users when in a course',
5375: domain => 'Creating users when a Domain Coordinator',
5376: );
5377: return %context_title;
5378: }
5379:
1.33 raeburn 5380: sub print_usermodification {
5381: my ($position,$dom,$settings,$rowtotal) = @_;
5382: my $numinrow = 4;
5383: my ($context,$datatable,$rowcount);
5384: if ($position eq 'top') {
5385: $rowcount = 0;
5386: $context = 'author';
5387: foreach my $role ('ca','aa') {
5388: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5389: $numinrow,$rowcount);
5390: $$rowtotal ++;
5391: $rowcount ++;
5392: }
1.160.6.37 raeburn 5393: } elsif ($position eq 'bottom') {
1.33 raeburn 5394: $context = 'course';
5395: $rowcount = 0;
5396: foreach my $role ('st','ep','ta','in','cr') {
5397: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5398: $numinrow,$rowcount);
5399: $$rowtotal ++;
5400: $rowcount ++;
5401: }
5402: }
5403: return $datatable;
5404: }
5405:
1.43 raeburn 5406: sub print_defaults {
1.160.6.40 raeburn 5407: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5408: my $rownum = 0;
1.160.6.80 raeburn 5409: my ($datatable,$css_class,$titles);
5410: unless ($position eq 'bottom') {
5411: $titles = &defaults_titles($dom);
5412: }
1.160.6.40 raeburn 5413: if ($position eq 'top') {
5414: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5415: 'datelocale_def','portal_def');
5416: my %defaults;
5417: if (ref($settings) eq 'HASH') {
5418: %defaults = %{$settings};
1.43 raeburn 5419: } else {
1.160.6.40 raeburn 5420: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5421: foreach my $item (@items) {
5422: $defaults{$item} = $domdefaults{$item};
5423: }
1.43 raeburn 5424: }
1.160.6.40 raeburn 5425: foreach my $item (@items) {
5426: if ($rownum%2) {
5427: $css_class = '';
5428: } else {
5429: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 5430: }
1.160.6.40 raeburn 5431: $datatable .= '<tr'.$css_class.'>'.
5432: '<td><span class="LC_nobreak">'.$titles->{$item}.
5433: '</span></td><td class="LC_right_item" colspan="3">';
5434: if ($item eq 'auth_def') {
5435: my @authtypes = ('internal','krb4','krb5','localauth');
5436: my %shortauth = (
5437: internal => 'int',
5438: krb4 => 'krb4',
5439: krb5 => 'krb5',
5440: localauth => 'loc'
5441: );
5442: my %authnames = &authtype_names();
5443: foreach my $auth (@authtypes) {
5444: my $checked = ' ';
5445: if ($defaults{$item} eq $auth) {
5446: $checked = ' checked="checked" ';
5447: }
5448: $datatable .= '<label><input type="radio" name="'.$item.
5449: '" value="'.$auth.'"'.$checked.'/>'.
5450: $authnames{$shortauth{$auth}}.'</label> ';
5451: }
5452: } elsif ($item eq 'timezone_def') {
5453: my $includeempty = 1;
5454: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5455: } elsif ($item eq 'datelocale_def') {
5456: my $includeempty = 1;
5457: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5458: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 5459: my $includeempty = 1;
5460: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 5461: } else {
5462: my $size;
5463: if ($item eq 'portal_def') {
5464: $size = ' size="25"';
5465: }
5466: $datatable .= '<input type="text" name="'.$item.'" value="'.
5467: $defaults{$item}.'"'.$size.' />';
5468: }
5469: $datatable .= '</td></tr>';
5470: $rownum ++;
5471: }
1.160.6.80 raeburn 5472: } elsif ($position eq 'middle') {
5473: my @items = ('intauth_cost','intauth_check','intauth_switch');
5474: my %defaults;
5475: if (ref($settings) eq 'HASH') {
5476: %defaults = %{$settings};
5477: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5478: $defaults{'intauth_cost'} = 10;
5479: }
5480: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5481: $defaults{'intauth_check'} = 0;
5482: }
5483: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5484: $defaults{'intauth_switch'} = 0;
5485: }
5486: } else {
5487: %defaults = (
5488: 'intauth_cost' => 10,
5489: 'intauth_check' => 0,
5490: 'intauth_switch' => 0,
5491: );
5492: }
5493: foreach my $item (@items) {
5494: if ($rownum%2) {
5495: $css_class = '';
5496: } else {
5497: $css_class = ' class="LC_odd_row" ';
5498: }
5499: $datatable .= '<tr'.$css_class.'>'.
5500: '<td><span class="LC_nobreak">'.$titles->{$item}.
5501: '</span></td><td class="LC_left_item" colspan="3">';
5502: if ($item eq 'intauth_switch') {
5503: my @options = (0,1,2);
5504: my %optiondesc = &Apache::lonlocal::texthash (
5505: 0 => 'No',
5506: 1 => 'Yes',
5507: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5508: );
5509: $datatable .= '<table width="100%">';
5510: foreach my $option (@options) {
5511: my $checked = ' ';
5512: if ($defaults{$item} eq $option) {
5513: $checked = ' checked="checked"';
5514: }
5515: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5516: '<label><input type="radio" name="'.$item.
5517: '" value="'.$option.'"'.$checked.' />'.
5518: $optiondesc{$option}.'</label></span></td></tr>';
5519: }
5520: $datatable .= '</table>';
5521: } elsif ($item eq 'intauth_check') {
5522: my @options = (0,1,2);
5523: my %optiondesc = &Apache::lonlocal::texthash (
5524: 0 => 'No',
5525: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5526: 2 => 'Yes, disallow login if stored cost is less than domain default',
5527: );
1.160.6.87! raeburn 5528: $datatable .= '<table width="100%">';
1.160.6.80 raeburn 5529: foreach my $option (@options) {
5530: my $checked = ' ';
5531: my $onclick;
5532: if ($defaults{$item} eq $option) {
5533: $checked = ' checked="checked"';
5534: }
5535: if ($option == 2) {
5536: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5537: }
5538: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5539: '<label><input type="radio" name="'.$item.
5540: '" value="'.$option.'"'.$checked.$onclick.' />'.
5541: $optiondesc{$option}.'</label></span></td></tr>';
5542: }
5543: $datatable .= '</table>';
5544: } else {
5545: $datatable .= '<input type="text" name="'.$item.'" value="'.
5546: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5547: }
5548: $datatable .= '</td></tr>';
5549: $rownum ++;
5550: }
1.160.6.40 raeburn 5551: } else {
1.160.6.80 raeburn 5552: my %defaults;
1.160.6.40 raeburn 5553: if (ref($settings) eq 'HASH') {
5554: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5555: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5556: my $maxnum = @{$settings->{'inststatusorder'}};
5557: for (my $i=0; $i<$maxnum; $i++) {
5558: $css_class = $rownum%2?' class="LC_odd_row"':'';
5559: my $item = $settings->{'inststatusorder'}->[$i];
5560: my $title = $settings->{'inststatustypes'}->{$item};
5561: my $guestok;
5562: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5563: $guestok = 1;
5564: }
5565: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5566: $datatable .= '<tr'.$css_class.'>'.
5567: '<td><span class="LC_nobreak">'.
5568: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5569: for (my $k=0; $k<=$maxnum; $k++) {
5570: my $vpos = $k+1;
5571: my $selstr;
5572: if ($k == $i) {
5573: $selstr = ' selected="selected" ';
5574: }
5575: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5576: }
5577: my ($checkedon,$checkedoff);
5578: $checkedoff = ' checked="checked"';
5579: if ($guestok) {
5580: $checkedon = $checkedoff;
5581: $checkedoff = '';
5582: }
5583: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5584: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5585: &mt('delete').'</span></td>'.
5586: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5587: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5588: '</span></td>'.
5589: '<td class="LC_right_item"><span class="LC_nobreak">'.
5590: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5591: &mt('Yes').'</label>'.(' 'x2).
5592: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5593: &mt('No').'</label></span></td></tr>';
5594: }
5595: $css_class = $rownum%2?' class="LC_odd_row"':'';
5596: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5597: $datatable .= '<tr '.$css_class.'>'.
5598: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5599: for (my $k=0; $k<=$maxnum; $k++) {
5600: my $vpos = $k+1;
5601: my $selstr;
5602: if ($k == $maxnum) {
5603: $selstr = ' selected="selected" ';
5604: }
5605: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5606: }
5607: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 5608: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 5609: ' '.&mt('(new)').
5610: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5611: &mt('Name displayed:').
5612: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5613: '<td class="LC_right_item"><span class="LC_nobreak">'.
5614: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5615: &mt('Yes').'</label>'.(' 'x2).
5616: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5617: &mt('No').'</label></span></td></tr>';
5618: '</tr>'."\n";
5619: $rownum ++;
1.141 raeburn 5620: }
1.43 raeburn 5621: }
5622: }
5623: $$rowtotal += $rownum;
5624: return $datatable;
5625: }
5626:
1.160.6.5 raeburn 5627: sub get_languages_hash {
5628: my %langchoices;
5629: foreach my $id (&Apache::loncommon::languageids()) {
5630: my $code = &Apache::loncommon::supportedlanguagecode($id);
5631: if ($code ne '') {
5632: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5633: }
5634: }
5635: return %langchoices;
5636: }
5637:
1.43 raeburn 5638: sub defaults_titles {
1.141 raeburn 5639: my ($dom) = @_;
1.43 raeburn 5640: my %titles = &Apache::lonlocal::texthash (
5641: 'auth_def' => 'Default authentication type',
5642: 'auth_arg_def' => 'Default authentication argument',
5643: 'lang_def' => 'Default language',
1.54 raeburn 5644: 'timezone_def' => 'Default timezone',
1.68 raeburn 5645: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5646: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 5647: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
5648: 'intauth_check' => 'Check bcrypt cost if authenticated',
5649: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 5650: );
1.141 raeburn 5651: if ($dom) {
5652: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5653: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5654: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5655: $protocol = 'http' if ($protocol ne 'https');
5656: if ($uint_dom) {
5657: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5658: $uint_dom);
5659: }
5660: }
1.43 raeburn 5661: return (\%titles);
5662: }
5663:
1.46 raeburn 5664: sub print_scantronformat {
5665: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5666: my $itemcount = 1;
1.60 raeburn 5667: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5668: %confhash);
1.46 raeburn 5669: my $switchserver = &check_switchserver($dom,$confname);
5670: my %lt = &Apache::lonlocal::texthash (
1.95 www 5671: default => 'Default bubblesheet format file error',
5672: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5673: );
5674: my %scantronfiles = (
5675: default => 'default.tab',
5676: custom => 'custom.tab',
5677: );
5678: foreach my $key (keys(%scantronfiles)) {
5679: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5680: .$scantronfiles{$key};
5681: }
5682: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5683: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5684: if (!$switchserver) {
5685: my $servadm = $r->dir_config('lonAdmEMail');
5686: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5687: if ($configuserok eq 'ok') {
5688: if ($author_ok eq 'ok') {
5689: my %legacyfile = (
5690: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5691: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5692: );
5693: my %md5chk;
5694: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5695: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5696: chomp($md5chk{$type});
1.46 raeburn 5697: }
5698: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5699: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5700: ($scantronurls{$type},my $error) =
1.46 raeburn 5701: &legacy_scantronformat($r,$dom,$confname,
5702: $type,$legacyfile{$type},
5703: $scantronurls{$type},
5704: $scantronfiles{$type});
1.60 raeburn 5705: if ($error ne '') {
5706: $error{$type} = $error;
5707: }
5708: }
5709: if (keys(%error) == 0) {
5710: $is_custom = 1;
5711: $confhash{'scantron'}{'scantronformat'} =
5712: $scantronurls{'custom'};
5713: my $putresult =
5714: &Apache::lonnet::put_dom('configuration',
5715: \%confhash,$dom);
5716: if ($putresult ne 'ok') {
5717: $error{'custom'} =
5718: '<span class="LC_error">'.
5719: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5720: }
1.46 raeburn 5721: }
5722: } else {
1.60 raeburn 5723: ($scantronurls{'default'},my $error) =
1.46 raeburn 5724: &legacy_scantronformat($r,$dom,$confname,
5725: 'default',$legacyfile{'default'},
5726: $scantronurls{'default'},
5727: $scantronfiles{'default'});
1.60 raeburn 5728: if ($error eq '') {
5729: $confhash{'scantron'}{'scantronformat'} = '';
5730: my $putresult =
5731: &Apache::lonnet::put_dom('configuration',
5732: \%confhash,$dom);
5733: if ($putresult ne 'ok') {
5734: $error{'default'} =
5735: '<span class="LC_error">'.
5736: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5737: }
5738: } else {
5739: $error{'default'} = $error;
5740: }
1.46 raeburn 5741: }
5742: }
5743: }
5744: } else {
1.95 www 5745: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5746: }
5747: }
5748: if (ref($settings) eq 'HASH') {
5749: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5750: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5751: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5752: $scantronurl = '';
5753: } else {
5754: $scantronurl = $settings->{'scantronformat'};
5755: }
5756: $is_custom = 1;
5757: } else {
5758: $scantronurl = $scantronurls{'default'};
5759: }
5760: } else {
1.60 raeburn 5761: if ($is_custom) {
5762: $scantronurl = $scantronurls{'custom'};
5763: } else {
5764: $scantronurl = $scantronurls{'default'};
5765: }
1.46 raeburn 5766: }
5767: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5768: $datatable .= '<tr'.$css_class.'>';
5769: if (!$is_custom) {
1.65 raeburn 5770: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5771: '<span class="LC_nobreak">';
1.46 raeburn 5772: if ($scantronurl) {
1.160.6.21 raeburn 5773: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5774: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5775: } else {
5776: $datatable = &mt('File unavailable for display');
5777: }
1.65 raeburn 5778: $datatable .= '</span></td>';
1.60 raeburn 5779: if (keys(%error) == 0) {
5780: $datatable .= '<td valign="bottom">';
5781: if (!$switchserver) {
5782: $datatable .= &mt('Upload:').'<br />';
5783: }
5784: } else {
5785: my $errorstr;
5786: foreach my $key (sort(keys(%error))) {
5787: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5788: }
5789: $datatable .= '<td>'.$errorstr;
5790: }
1.46 raeburn 5791: } else {
5792: if (keys(%error) > 0) {
5793: my $errorstr;
5794: foreach my $key (sort(keys(%error))) {
5795: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5796: }
1.60 raeburn 5797: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5798: } elsif ($scantronurl) {
1.160.6.26 raeburn 5799: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 5800: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5801: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 5802: $link.
5803: '<label><input type="checkbox" name="scantronformat_del"'.
5804: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5805: '<td><span class="LC_nobreak"> '.
5806: &mt('Replace:').'</span><br />';
1.46 raeburn 5807: }
5808: }
5809: if (keys(%error) == 0) {
5810: if ($switchserver) {
5811: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5812: } else {
1.65 raeburn 5813: $datatable .='<span class="LC_nobreak"> '.
5814: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5815: }
5816: }
5817: $datatable .= '</td></tr>';
5818: $$rowtotal ++;
5819: return $datatable;
5820: }
5821:
5822: sub legacy_scantronformat {
5823: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5824: my ($url,$error);
5825: my @statinfo = &Apache::lonnet::stat_file($newurl);
5826: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5827: (my $result,$url) =
5828: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5829: '','',$newfile);
5830: if ($result ne 'ok') {
1.130 raeburn 5831: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5832: }
5833: }
5834: return ($url,$error);
5835: }
1.43 raeburn 5836:
1.49 raeburn 5837: sub print_coursecategories {
1.57 raeburn 5838: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5839: my $datatable;
5840: if ($position eq 'top') {
1.160.6.42 raeburn 5841: my (%checked);
5842: my @catitems = ('unauth','auth');
5843: my @cattypes = ('std','domonly','codesrch','none');
5844: $checked{'unauth'} = 'std';
5845: $checked{'auth'} = 'std';
5846: if (ref($settings) eq 'HASH') {
5847: foreach my $type (@cattypes) {
5848: if ($type eq $settings->{'unauth'}) {
5849: $checked{'unauth'} = $type;
5850: }
5851: if ($type eq $settings->{'auth'}) {
5852: $checked{'auth'} = $type;
5853: }
5854: }
5855: }
5856: my %lt = &Apache::lonlocal::texthash (
5857: unauth => 'Catalog type for unauthenticated users',
5858: auth => 'Catalog type for authenticated users',
5859: none => 'No catalog',
5860: std => 'Standard catalog',
5861: domonly => 'Domain-only catalog',
5862: codesrch => "Code search form",
5863: );
5864: my $itemcount = 0;
5865: foreach my $item (@catitems) {
5866: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5867: $datatable .= '<tr '.$css_class.'>'.
5868: '<td>'.$lt{$item}.'</td>'.
5869: '<td class="LC_right_item"><span class="LC_nobreak">';
5870: foreach my $type (@cattypes) {
5871: my $ischecked;
5872: if ($checked{$item} eq $type) {
5873: $ischecked=' checked="checked"';
5874: }
5875: $datatable .= '<label>'.
5876: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5877: ' />'.$lt{$type}.'</label> ';
5878: }
1.160.6.87! raeburn 5879: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 5880: $itemcount ++;
5881: }
5882: $$rowtotal += $itemcount;
5883: } elsif ($position eq 'middle') {
1.57 raeburn 5884: my $toggle_cats_crs = ' ';
5885: my $toggle_cats_dom = ' checked="checked" ';
5886: my $can_cat_crs = ' ';
5887: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5888: my $toggle_catscomm_comm = ' ';
5889: my $toggle_catscomm_dom = ' checked="checked" ';
5890: my $can_catcomm_comm = ' ';
5891: my $can_catcomm_dom = ' checked="checked" ';
5892:
1.57 raeburn 5893: if (ref($settings) eq 'HASH') {
5894: if ($settings->{'togglecats'} eq 'crs') {
5895: $toggle_cats_crs = $toggle_cats_dom;
5896: $toggle_cats_dom = ' ';
5897: }
5898: if ($settings->{'categorize'} eq 'crs') {
5899: $can_cat_crs = $can_cat_dom;
5900: $can_cat_dom = ' ';
5901: }
1.120 raeburn 5902: if ($settings->{'togglecatscomm'} eq 'comm') {
5903: $toggle_catscomm_comm = $toggle_catscomm_dom;
5904: $toggle_catscomm_dom = ' ';
5905: }
5906: if ($settings->{'categorizecomm'} eq 'comm') {
5907: $can_catcomm_comm = $can_catcomm_dom;
5908: $can_catcomm_dom = ' ';
5909: }
1.57 raeburn 5910: }
5911: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5912: togglecats => 'Show/Hide a course in catalog',
5913: togglecatscomm => 'Show/Hide a community in catalog',
5914: categorize => 'Assign a category to a course',
5915: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5916: );
5917: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5918: dom => 'Set in Domain',
5919: crs => 'Set in Course',
5920: comm => 'Set in Community',
1.57 raeburn 5921: );
5922: $datatable = '<tr class="LC_odd_row">'.
5923: '<td>'.$title{'togglecats'}.'</td>'.
5924: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5925: '<input type="radio" name="togglecats"'.
5926: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5927: '<label><input type="radio" name="togglecats"'.
5928: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5929: '</tr><tr>'.
5930: '<td>'.$title{'categorize'}.'</td>'.
5931: '<td class="LC_right_item"><span class="LC_nobreak">'.
5932: '<label><input type="radio" name="categorize"'.
5933: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5934: '<label><input type="radio" name="categorize"'.
5935: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5936: '</tr><tr class="LC_odd_row">'.
5937: '<td>'.$title{'togglecatscomm'}.'</td>'.
5938: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5939: '<input type="radio" name="togglecatscomm"'.
5940: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5941: '<label><input type="radio" name="togglecatscomm"'.
5942: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5943: '</tr><tr>'.
5944: '<td>'.$title{'categorizecomm'}.'</td>'.
5945: '<td class="LC_right_item"><span class="LC_nobreak">'.
5946: '<label><input type="radio" name="categorizecomm"'.
5947: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5948: '<label><input type="radio" name="categorizecomm"'.
5949: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5950: '</tr>';
1.120 raeburn 5951: $$rowtotal += 4;
1.57 raeburn 5952: } else {
5953: my $css_class;
5954: my $itemcount = 1;
5955: my $cathash;
5956: if (ref($settings) eq 'HASH') {
5957: $cathash = $settings->{'cats'};
5958: }
5959: if (ref($cathash) eq 'HASH') {
5960: my (@cats,@trails,%allitems,%idx,@jsarray);
5961: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5962: \%allitems,\%idx,\@jsarray);
5963: my $maxdepth = scalar(@cats);
5964: my $colattrib = '';
5965: if ($maxdepth > 2) {
5966: $colattrib = ' colspan="2" ';
5967: }
5968: my @path;
5969: if (@cats > 0) {
5970: if (ref($cats[0]) eq 'ARRAY') {
5971: my $numtop = @{$cats[0]};
5972: my $maxnum = $numtop;
1.120 raeburn 5973: my %default_names = (
5974: instcode => &mt('Official courses'),
5975: communities => &mt('Communities'),
5976: );
5977:
5978: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5979: ($cathash->{'instcode::0'} eq '') ||
5980: (!grep(/^communities$/,@{$cats[0]})) ||
5981: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5982: $maxnum ++;
5983: }
5984: my $lastidx;
5985: for (my $i=0; $i<$numtop; $i++) {
5986: my $parent = $cats[0][$i];
5987: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5988: my $item = &escape($parent).'::0';
5989: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5990: $lastidx = $idx{$item};
5991: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5992: .'<select name="'.$item.'"'.$chgstr.'>';
5993: for (my $k=0; $k<=$maxnum; $k++) {
5994: my $vpos = $k+1;
5995: my $selstr;
5996: if ($k == $i) {
5997: $selstr = ' selected="selected" ';
5998: }
5999: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6000: }
1.160.6.29 raeburn 6001: $datatable .= '</select></span></td><td>';
1.120 raeburn 6002: if ($parent eq 'instcode' || $parent eq 'communities') {
6003: $datatable .= '<span class="LC_nobreak">'
6004: .$default_names{$parent}.'</span>';
6005: if ($parent eq 'instcode') {
6006: $datatable .= '<br /><span class="LC_nobreak">('
6007: .&mt('with institutional codes')
6008: .')</span></td><td'.$colattrib.'>';
6009: } else {
6010: $datatable .= '<table><tr><td>';
6011: }
6012: $datatable .= '<span class="LC_nobreak">'
6013: .'<label><input type="radio" name="'
6014: .$parent.'" value="1" checked="checked" />'
6015: .&mt('Display').'</label>';
6016: if ($parent eq 'instcode') {
6017: $datatable .= ' ';
6018: } else {
6019: $datatable .= '</span></td></tr><tr><td>'
6020: .'<span class="LC_nobreak">';
6021: }
6022: $datatable .= '<label><input type="radio" name="'
6023: .$parent.'" value="0" />'
6024: .&mt('Do not display').'</label></span>';
6025: if ($parent eq 'communities') {
6026: $datatable .= '</td></tr></table>';
6027: }
6028: $datatable .= '</td>';
1.57 raeburn 6029: } else {
6030: $datatable .= $parent
1.160.6.29 raeburn 6031: .' <span class="LC_nobreak"><label>'
6032: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6033: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6034: }
6035: my $depth = 1;
6036: push(@path,$parent);
6037: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6038: pop(@path);
6039: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6040: $itemcount ++;
6041: }
1.48 raeburn 6042: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6043: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6044: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6045: for (my $k=0; $k<=$maxnum; $k++) {
6046: my $vpos = $k+1;
6047: my $selstr;
1.57 raeburn 6048: if ($k == $numtop) {
1.48 raeburn 6049: $selstr = ' selected="selected" ';
6050: }
6051: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6052: }
1.59 bisitz 6053: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6054: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6055: .'</tr>'."\n";
1.48 raeburn 6056: $itemcount ++;
1.120 raeburn 6057: foreach my $default ('instcode','communities') {
6058: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6059: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6060: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6061: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6062: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6063: for (my $k=0; $k<=$maxnum; $k++) {
6064: my $vpos = $k+1;
6065: my $selstr;
6066: if ($k == $maxnum) {
6067: $selstr = ' selected="selected" ';
6068: }
6069: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6070: }
1.120 raeburn 6071: $datatable .= '</select></span></td>'.
6072: '<td><span class="LC_nobreak">'.
6073: $default_names{$default}.'</span>';
6074: if ($default eq 'instcode') {
6075: $datatable .= '<br /><span class="LC_nobreak">('
6076: .&mt('with institutional codes').')</span>';
6077: }
6078: $datatable .= '</td>'
6079: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6080: .&mt('Display').'</label> '
6081: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6082: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6083: }
6084: }
6085: }
1.57 raeburn 6086: } else {
6087: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6088: }
6089: } else {
1.160.6.87! raeburn 6090: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 6091: .&initialize_categories($itemcount);
1.48 raeburn 6092: }
1.57 raeburn 6093: $$rowtotal += $itemcount;
1.48 raeburn 6094: }
6095: return $datatable;
6096: }
6097:
1.69 raeburn 6098: sub print_serverstatuses {
6099: my ($dom,$settings,$rowtotal) = @_;
6100: my $datatable;
6101: my @pages = &serverstatus_pages();
6102: my (%namedaccess,%machineaccess);
6103: foreach my $type (@pages) {
6104: $namedaccess{$type} = '';
6105: $machineaccess{$type}= '';
6106: }
6107: if (ref($settings) eq 'HASH') {
6108: foreach my $type (@pages) {
6109: if (exists($settings->{$type})) {
6110: if (ref($settings->{$type}) eq 'HASH') {
6111: foreach my $key (keys(%{$settings->{$type}})) {
6112: if ($key eq 'namedusers') {
6113: $namedaccess{$type} = $settings->{$type}->{$key};
6114: } elsif ($key eq 'machines') {
6115: $machineaccess{$type} = $settings->{$type}->{$key};
6116: }
6117: }
6118: }
6119: }
6120: }
6121: }
1.81 raeburn 6122: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6123: my $rownum = 0;
6124: my $css_class;
6125: foreach my $type (@pages) {
6126: $rownum ++;
6127: $css_class = $rownum%2?' class="LC_odd_row"':'';
6128: $datatable .= '<tr'.$css_class.'>'.
6129: '<td><span class="LC_nobreak">'.
6130: $titles->{$type}.'</span></td>'.
6131: '<td class="LC_left_item">'.
6132: '<input type="text" name="'.$type.'_namedusers" '.
6133: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6134: '<td class="LC_right_item">'.
6135: '<span class="LC_nobreak">'.
6136: '<input type="text" name="'.$type.'_machines" '.
6137: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87! raeburn 6138: '</span></td></tr>'."\n";
1.69 raeburn 6139: }
6140: $$rowtotal += $rownum;
6141: return $datatable;
6142: }
6143:
6144: sub serverstatus_pages {
6145: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 6146: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 6147: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 6148: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6149: }
6150:
1.160.6.40 raeburn 6151: sub defaults_javascript {
6152: my ($settings) = @_;
1.160.6.80 raeburn 6153: my $intauthcheck = &mt('Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.');
6154: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6155: &js_escape(\$intauthcheck);
6156: &js_escape(\$intauthcost);
6157: my $intauthjs = <<"ENDSCRIPT";
6158:
6159: function warnIntAuth(field) {
6160: if (field.name == 'intauth_check') {
6161: if (field.value == '2') {
6162: alert('$intauthcheck');
6163: }
6164: }
6165: if (field.name == 'intauth_cost') {
6166: field.value.replace(/\s/g,'');
6167: if (field.value != '') {
6168: var regexdigit=/^\\d+\$/;
6169: if (!regexdigit.test(field.value)) {
6170: alert('$intauthcost');
6171: }
6172: }
6173: }
6174: return;
6175: }
6176:
6177: ENDSCRIPT
6178:
6179: if (ref($settings) ne 'HASH') {
6180: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6181: }
1.160.6.40 raeburn 6182: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6183: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6184: if ($maxnum eq '') {
6185: $maxnum = 0;
6186: }
6187: $maxnum ++;
1.160.6.51 raeburn 6188: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 6189: return <<"ENDSCRIPT";
6190: <script type="text/javascript">
6191: // <![CDATA[
6192: function reorderTypes(form,caller) {
6193: var changedVal;
6194: $jstext
6195: var newpos = 'addinststatus_pos';
6196: var current = new Array;
6197: var maxh = $maxnum;
6198: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6199: var oldVal;
6200: if (caller == newpos) {
6201: changedVal = newitemVal;
6202: } else {
6203: var curritem = 'inststatus_pos_'+caller;
6204: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6205: current[newitemVal] = newpos;
6206: }
6207: for (var i=0; i<inststatuses.length; i++) {
6208: if (inststatuses[i] != caller) {
6209: var elementName = 'inststatus_pos_'+inststatuses[i];
6210: if (form.elements[elementName]) {
6211: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6212: current[currVal] = elementName;
6213: }
6214: }
6215: }
6216: for (var j=0; j<maxh; j++) {
6217: if (current[j] == undefined) {
6218: oldVal = j;
6219: }
6220: }
6221: if (oldVal < changedVal) {
6222: for (var k=oldVal+1; k<=changedVal ; k++) {
6223: var elementName = current[k];
6224: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6225: }
6226: } else {
6227: for (var k=changedVal; k<oldVal; k++) {
6228: var elementName = current[k];
6229: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6230: }
6231: }
6232: return;
6233: }
6234:
1.160.6.80 raeburn 6235: $intauthjs
6236:
1.160.6.40 raeburn 6237: // ]]>
6238: </script>
6239:
6240: ENDSCRIPT
1.160.6.80 raeburn 6241: } else {
6242: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40 raeburn 6243: }
6244: }
6245:
1.49 raeburn 6246: sub coursecategories_javascript {
6247: my ($settings) = @_;
1.57 raeburn 6248: my ($output,$jstext,$cathash);
1.49 raeburn 6249: if (ref($settings) eq 'HASH') {
1.57 raeburn 6250: $cathash = $settings->{'cats'};
6251: }
6252: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6253: my (@cats,@jsarray,%idx);
1.57 raeburn 6254: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6255: if (@jsarray > 0) {
6256: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6257: for (my $i=0; $i<@jsarray; $i++) {
6258: if (ref($jsarray[$i]) eq 'ARRAY') {
6259: my $catstr = join('","',@{$jsarray[$i]});
6260: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6261: }
6262: }
6263: }
6264: } else {
6265: $jstext = ' var categories = Array(1);'."\n".
6266: ' categories[0] = Array("instcode_pos");'."\n";
6267: }
1.160.6.42 raeburn 6268: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6269: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 6270: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6271: &js_escape(\$instcode_reserved);
6272: &js_escape(\$communities_reserved);
6273: &js_escape(\$choose_again);
1.49 raeburn 6274: $output = <<"ENDSCRIPT";
6275: <script type="text/javascript">
1.109 raeburn 6276: // <![CDATA[
1.49 raeburn 6277: function reorderCats(form,parent,item,idx) {
6278: var changedVal;
6279: $jstext
6280: var newpos = 'addcategory_pos';
6281: if (parent == '') {
6282: var has_instcode = 0;
6283: var maxtop = categories[idx].length;
6284: for (var j=0; j<maxtop; j++) {
6285: if (categories[idx][j] == 'instcode::0') {
6286: has_instcode == 1;
6287: }
6288: }
6289: if (has_instcode == 0) {
6290: categories[idx][maxtop] = 'instcode_pos';
6291: }
6292: } else {
6293: newpos += '_'+parent;
6294: }
6295: var maxh = 1 + categories[idx].length;
6296: var current = new Array;
6297: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6298: if (item == newpos) {
6299: changedVal = newitemVal;
6300: } else {
6301: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6302: current[newitemVal] = newpos;
6303: }
6304: for (var i=0; i<categories[idx].length; i++) {
6305: var elementName = categories[idx][i];
6306: if (elementName != item) {
6307: if (form.elements[elementName]) {
6308: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6309: current[currVal] = elementName;
6310: }
6311: }
6312: }
6313: var oldVal;
6314: for (var j=0; j<maxh; j++) {
6315: if (current[j] == undefined) {
6316: oldVal = j;
6317: }
6318: }
6319: if (oldVal < changedVal) {
6320: for (var k=oldVal+1; k<=changedVal ; k++) {
6321: var elementName = current[k];
6322: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6323: }
6324: } else {
6325: for (var k=changedVal; k<oldVal; k++) {
6326: var elementName = current[k];
6327: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6328: }
6329: }
6330: return;
6331: }
1.120 raeburn 6332:
6333: function categoryCheck(form) {
6334: if (form.elements['addcategory_name'].value == 'instcode') {
6335: alert('$instcode_reserved\\n$choose_again');
6336: return false;
6337: }
6338: if (form.elements['addcategory_name'].value == 'communities') {
6339: alert('$communities_reserved\\n$choose_again');
6340: return false;
6341: }
6342: return true;
6343: }
6344:
1.109 raeburn 6345: // ]]>
1.49 raeburn 6346: </script>
6347:
6348: ENDSCRIPT
6349: return $output;
6350: }
6351:
1.48 raeburn 6352: sub initialize_categories {
6353: my ($itemcount) = @_;
1.120 raeburn 6354: my ($datatable,$css_class,$chgstr);
6355: my %default_names = (
6356: instcode => 'Official courses (with institutional codes)',
6357: communities => 'Communities',
6358: );
6359: my $select0 = ' selected="selected"';
6360: my $select1 = '';
6361: foreach my $default ('instcode','communities') {
6362: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87! raeburn 6363: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 6364: if ($default eq 'communities') {
6365: $select1 = $select0;
6366: $select0 = '';
6367: }
6368: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6369: .'<select name="'.$default.'_pos">'
6370: .'<option value="0"'.$select0.'>1</option>'
6371: .'<option value="1"'.$select1.'>2</option>'
6372: .'<option value="2">3</option></select> '
6373: .$default_names{$default}
6374: .'</span></td><td><span class="LC_nobreak">'
6375: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6376: .&mt('Display').'</label> <label>'
6377: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6378: .'</label></span></td></tr>';
1.120 raeburn 6379: $itemcount ++;
6380: }
1.48 raeburn 6381: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6382: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6383: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6384: .'<select name="addcategory_pos"'.$chgstr.'>'
6385: .'<option value="0">1</option>'
6386: .'<option value="1">2</option>'
6387: .'<option value="2" selected="selected">3</option></select> '
1.160.6.87! raeburn 6388: .&mt('Add category').'</span></td><tda<span class="LC_nobreak">>'.&mt('Name:')
! 6389: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
! 6390: .'</td></tr>';
1.48 raeburn 6391: return $datatable;
6392: }
6393:
6394: sub build_category_rows {
1.49 raeburn 6395: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6396: my ($text,$name,$item,$chgstr);
1.48 raeburn 6397: if (ref($cats) eq 'ARRAY') {
6398: my $maxdepth = scalar(@{$cats});
6399: if (ref($cats->[$depth]) eq 'HASH') {
6400: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6401: my $numchildren = @{$cats->[$depth]{$parent}};
6402: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 6403: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6404: my ($idxnum,$parent_name,$parent_item);
6405: my $higher = $depth - 1;
6406: if ($higher == 0) {
6407: $parent_name = &escape($parent).'::'.$higher;
6408: } else {
6409: if (ref($path) eq 'ARRAY') {
6410: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6411: }
6412: }
6413: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6414: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6415: if ($j < $numchildren) {
1.48 raeburn 6416: $name = $cats->[$depth]{$parent}[$j];
6417: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6418: $idxnum = $idx->{$item};
6419: } else {
6420: $name = $parent_name;
6421: $item = $parent_item;
1.48 raeburn 6422: }
1.49 raeburn 6423: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6424: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6425: for (my $i=0; $i<=$numchildren; $i++) {
6426: my $vpos = $i+1;
6427: my $selstr;
6428: if ($j == $i) {
6429: $selstr = ' selected="selected" ';
6430: }
6431: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6432: }
6433: $text .= '</select> ';
6434: if ($j < $numchildren) {
6435: my $deeper = $depth+1;
6436: $text .= $name.' '
6437: .'<label><input type="checkbox" name="deletecategory" value="'
6438: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6439: if(ref($path) eq 'ARRAY') {
6440: push(@{$path},$name);
1.49 raeburn 6441: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6442: pop(@{$path});
6443: }
6444: } else {
1.160.6.87! raeburn 6445: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 6446: if ($j == $numchildren) {
6447: $text .= $name;
6448: } else {
6449: $text .= $item;
6450: }
6451: $text .= '" value="" />';
6452: }
6453: $text .= '</td></tr>';
6454: }
6455: $text .= '</table></td>';
6456: } else {
6457: my $higher = $depth-1;
6458: if ($higher == 0) {
6459: $name = &escape($parent).'::'.$higher;
6460: } else {
6461: if (ref($path) eq 'ARRAY') {
6462: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6463: }
6464: }
6465: my $colspan;
6466: if ($parent ne 'instcode') {
6467: $colspan = $maxdepth - $depth - 1;
1.160.6.87! raeburn 6468: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 6469: }
6470: }
6471: }
6472: }
6473: return $text;
6474: }
6475:
1.33 raeburn 6476: sub modifiable_userdata_row {
1.160.6.35 raeburn 6477: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6478: my ($role,$rolename,$statustype);
6479: $role = $item;
1.160.6.34 raeburn 6480: if ($context eq 'cancreate') {
1.160.6.35 raeburn 6481: if ($item =~ /^emailusername_(.+)$/) {
6482: $statustype = $1;
6483: $role = 'emailusername';
6484: if (ref($usertypes) eq 'HASH') {
6485: if ($usertypes->{$statustype}) {
6486: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6487: } else {
6488: $rolename = &mt('Data provided by user');
6489: }
6490: }
1.160.6.34 raeburn 6491: }
6492: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6493: if (ref($usertypes) eq 'HASH') {
6494: $rolename = $usertypes->{$role};
6495: } else {
6496: $rolename = $role;
6497: }
1.33 raeburn 6498: } else {
1.63 raeburn 6499: if ($role eq 'cr') {
6500: $rolename = &mt('Custom role');
6501: } else {
6502: $rolename = &Apache::lonnet::plaintext($role);
6503: }
1.33 raeburn 6504: }
1.160.6.34 raeburn 6505: my (@fields,%fieldtitles);
6506: if (ref($fieldsref) eq 'ARRAY') {
6507: @fields = @{$fieldsref};
6508: } else {
6509: @fields = ('lastname','firstname','middlename','generation',
6510: 'permanentemail','id');
6511: }
6512: if ((ref($titlesref) eq 'HASH')) {
6513: %fieldtitles = %{$titlesref};
6514: } else {
6515: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6516: }
1.33 raeburn 6517: my $output;
6518: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6519: $output = '<tr '.$css_class.'>'.
6520: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6521: '<td class="LC_left_item" colspan="2"><table>';
6522: my $rem;
6523: my %checks;
6524: if (ref($settings) eq 'HASH') {
6525: if (ref($settings->{$context}) eq 'HASH') {
6526: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 6527: my $hashref = $settings->{$context}->{$role};
6528: if ($role eq 'emailusername') {
6529: if ($statustype) {
6530: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6531: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 6532: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 6533: foreach my $field (@fields) {
6534: if ($hashref->{$field}) {
6535: $checks{$field} = $hashref->{$field};
6536: }
6537: }
6538: }
6539: }
6540: }
6541: } else {
6542: if (ref($hashref) eq 'HASH') {
6543: foreach my $field (@fields) {
6544: if ($hashref->{$field}) {
6545: $checks{$field} = ' checked="checked" ';
6546: }
6547: }
1.33 raeburn 6548: }
6549: }
6550: }
6551: }
6552: }
1.160.6.39 raeburn 6553:
1.33 raeburn 6554: for (my $i=0; $i<@fields; $i++) {
6555: my $rem = $i%($numinrow);
6556: if ($rem == 0) {
6557: if ($i > 0) {
6558: $output .= '</tr>';
6559: }
6560: $output .= '<tr>';
6561: }
6562: my $check = ' ';
1.160.6.35 raeburn 6563: unless ($role eq 'emailusername') {
6564: if (exists($checks{$fields[$i]})) {
6565: $check = $checks{$fields[$i]}
6566: } else {
6567: if ($role eq 'st') {
6568: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 6569: $check = ' checked="checked" ';
1.160.6.35 raeburn 6570: }
1.33 raeburn 6571: }
6572: }
6573: }
6574: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 6575: '<span class="LC_nobreak">';
6576: if ($role eq 'emailusername') {
6577: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6578: $checks{$fields[$i]} = 'omit';
6579: }
6580: foreach my $option ('required','optional','omit') {
6581: my $checked='';
6582: if ($checks{$fields[$i]} eq $option) {
6583: $checked='checked="checked" ';
6584: }
6585: $output .= '<label>'.
6586: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6587: &mt($option).'</label>'.(' ' x2);
6588: }
6589: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6590: } else {
6591: $output .= '<label>'.
6592: '<input type="checkbox" name="canmodify_'.$role.'" '.
6593: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6594: '</label>';
6595: }
6596: $output .= '</span></td>';
1.33 raeburn 6597: $rem = @fields%($numinrow);
6598: }
6599: my $colsleft = $numinrow - $rem;
6600: if ($colsleft > 1 ) {
6601: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6602: ' </td>';
6603: } elsif ($colsleft == 1) {
6604: $output .= '<td class="LC_left_item"> </td>';
6605: }
6606: $output .= '</tr></table></td></tr>';
6607: return $output;
6608: }
1.28 raeburn 6609:
1.93 raeburn 6610: sub insttypes_row {
1.160.6.34 raeburn 6611: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6612: my %lt = &Apache::lonlocal::texthash (
6613: cansearch => 'Users allowed to search',
6614: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6615: lockablenames => 'User preference to lock name',
1.93 raeburn 6616: );
6617: my $showdom;
6618: if ($context eq 'cansearch') {
6619: $showdom = ' ('.$dom.')';
6620: }
1.160.6.5 raeburn 6621: my $class = 'LC_left_item';
6622: if ($context eq 'statustocreate') {
6623: $class = 'LC_right_item';
6624: }
1.160.6.34 raeburn 6625: my $css_class = ' class="LC_odd_row"';
6626: if ($rownum ne '') {
6627: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6628: }
6629: my $output = '<tr'.$css_class.'>'.
6630: '<td>'.$lt{$context}.$showdom.
6631: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6632: my $rem;
6633: if (ref($types) eq 'ARRAY') {
6634: for (my $i=0; $i<@{$types}; $i++) {
6635: if (defined($usertypes->{$types->[$i]})) {
6636: my $rem = $i%($numinrow);
6637: if ($rem == 0) {
6638: if ($i > 0) {
6639: $output .= '</tr>';
6640: }
6641: $output .= '<tr>';
1.23 raeburn 6642: }
1.26 raeburn 6643: my $check = ' ';
1.99 raeburn 6644: if (ref($settings) eq 'HASH') {
6645: if (ref($settings->{$context}) eq 'ARRAY') {
6646: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6647: $check = ' checked="checked" ';
6648: }
6649: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6650: $check = ' checked="checked" ';
6651: }
1.23 raeburn 6652: }
1.26 raeburn 6653: $output .= '<td class="LC_left_item">'.
6654: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6655: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6656: 'value="'.$types->[$i].'"'.$check.'/>'.
6657: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6658: }
6659: }
1.26 raeburn 6660: $rem = @{$types}%($numinrow);
1.23 raeburn 6661: }
6662: my $colsleft = $numinrow - $rem;
1.160.6.87! raeburn 6663: if ($rem == 0) {
1.131 raeburn 6664: $output .= '<tr>';
6665: }
1.23 raeburn 6666: if ($colsleft > 1) {
1.25 raeburn 6667: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6668: } else {
1.25 raeburn 6669: $output .= '<td class="LC_left_item">';
1.23 raeburn 6670: }
6671: my $defcheck = ' ';
1.99 raeburn 6672: if (ref($settings) eq 'HASH') {
6673: if (ref($settings->{$context}) eq 'ARRAY') {
6674: if (grep(/^default$/,@{$settings->{$context}})) {
6675: $defcheck = ' checked="checked" ';
6676: }
6677: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6678: $defcheck = ' checked="checked" ';
6679: }
1.23 raeburn 6680: }
1.25 raeburn 6681: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6682: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6683: 'value="default"'.$defcheck.'/>'.
6684: $othertitle.'</label></span></td>'.
6685: '</tr></table></td></tr>';
6686: return $output;
1.23 raeburn 6687: }
6688:
6689: sub sorted_searchtitles {
6690: my %searchtitles = &Apache::lonlocal::texthash(
6691: 'uname' => 'username',
6692: 'lastname' => 'last name',
6693: 'lastfirst' => 'last name, first name',
6694: );
6695: my @titleorder = ('uname','lastname','lastfirst');
6696: return (\%searchtitles,\@titleorder);
6697: }
6698:
1.25 raeburn 6699: sub sorted_searchtypes {
6700: my %srchtypes_desc = (
6701: exact => 'is exact match',
6702: contains => 'contains ..',
6703: begins => 'begins with ..',
6704: );
6705: my @srchtypeorder = ('exact','begins','contains');
6706: return (\%srchtypes_desc,\@srchtypeorder);
6707: }
6708:
1.3 raeburn 6709: sub usertype_update_row {
6710: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6711: my $datatable;
6712: my $numinrow = 4;
6713: foreach my $type (@{$types}) {
6714: if (defined($usertypes->{$type})) {
6715: $$rownums ++;
6716: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6717: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6718: '</td><td class="LC_left_item"><table>';
6719: for (my $i=0; $i<@{$fields}; $i++) {
6720: my $rem = $i%($numinrow);
6721: if ($rem == 0) {
6722: if ($i > 0) {
6723: $datatable .= '</tr>';
6724: }
6725: $datatable .= '<tr>';
6726: }
6727: my $check = ' ';
1.39 raeburn 6728: if (ref($settings) eq 'HASH') {
6729: if (ref($settings->{'fields'}) eq 'HASH') {
6730: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6731: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6732: $check = ' checked="checked" ';
6733: }
1.3 raeburn 6734: }
6735: }
6736: }
6737:
6738: if ($i == @{$fields}-1) {
6739: my $colsleft = $numinrow - $rem;
6740: if ($colsleft > 1) {
6741: $datatable .= '<td colspan="'.$colsleft.'">';
6742: } else {
6743: $datatable .= '<td>';
6744: }
6745: } else {
6746: $datatable .= '<td>';
6747: }
1.8 raeburn 6748: $datatable .= '<span class="LC_nobreak"><label>'.
6749: '<input type="checkbox" name="updateable_'.$type.
6750: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6751: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6752: }
6753: $datatable .= '</tr></table></td></tr>';
6754: }
6755: }
6756: return $datatable;
1.1 raeburn 6757: }
6758:
6759: sub modify_login {
1.160.6.24 raeburn 6760: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 6761: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6762: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6763: %title = ( coursecatalog => 'Display course catalog',
6764: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 6765: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 6766: newuser => 'Link for visitors to create a user account',
6767: loginheader => 'Log-in box header');
6768: @offon = ('off','on');
1.112 raeburn 6769: if (ref($domconfig{login}) eq 'HASH') {
6770: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6771: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6772: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6773: }
6774: }
6775: }
1.9 raeburn 6776: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6777: \%domconfig,\%loginhash);
1.160.6.14 raeburn 6778: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6779: foreach my $item (@toggles) {
6780: $loginhash{login}{$item} = $env{'form.'.$item};
6781: }
1.41 raeburn 6782: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6783: if (ref($colchanges{'login'}) eq 'HASH') {
6784: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6785: \%loginhash);
6786: }
1.110 raeburn 6787:
1.149 raeburn 6788: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 6789: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6790: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6791: if (keys(%servers) > 1) {
6792: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6793: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6794: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6795: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6796: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6797: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6798: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6799: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6800: $changes{'loginvia'}{$lonhost} = 1;
6801: } else {
6802: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6803: $changes{'loginvia'}{$lonhost} = 1;
6804: }
6805: } else {
6806: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6807: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6808: $changes{'loginvia'}{$lonhost} = 1;
6809: }
6810: }
6811: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6812: foreach my $item (@loginvia_attribs) {
6813: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6814: }
6815: } else {
6816: foreach my $item (@loginvia_attribs) {
6817: my $new = $env{'form.'.$lonhost.'_'.$item};
6818: if (($item eq 'serverpath') && ($new eq 'custom')) {
6819: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6820: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6821: $new = '/';
6822: }
6823: }
6824: if (($item eq 'custompath') &&
6825: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6826: $new = '';
6827: }
6828: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6829: $changes{'loginvia'}{$lonhost} = 1;
6830: }
6831: if ($item eq 'exempt') {
1.160.6.56 raeburn 6832: $new = &check_exempt_addresses($new);
1.128 raeburn 6833: }
6834: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6835: }
6836: }
1.112 raeburn 6837: } else {
1.128 raeburn 6838: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6839: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6840: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6841: foreach my $item (@loginvia_attribs) {
6842: my $new = $env{'form.'.$lonhost.'_'.$item};
6843: if (($item eq 'serverpath') && ($new eq 'custom')) {
6844: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6845: $new = '/';
6846: }
6847: }
6848: if (($item eq 'custompath') &&
6849: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6850: $new = '';
6851: }
6852: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6853: }
1.110 raeburn 6854: }
6855: }
6856: }
6857: }
1.119 raeburn 6858:
1.160.6.5 raeburn 6859: my $servadm = $r->dir_config('lonAdmEMail');
6860: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6861: if (ref($domconfig{'login'}) eq 'HASH') {
6862: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6863: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6864: if ($lang eq 'nolang') {
6865: push(@currlangs,$lang);
6866: } elsif (defined($langchoices{$lang})) {
6867: push(@currlangs,$lang);
6868: } else {
6869: next;
6870: }
6871: }
6872: }
6873: }
6874: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6875: if (@currlangs > 0) {
6876: foreach my $lang (@currlangs) {
6877: if (grep(/^\Q$lang\E$/,@delurls)) {
6878: $changes{'helpurl'}{$lang} = 1;
6879: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6880: $changes{'helpurl'}{$lang} = 1;
6881: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6882: push(@newlangs,$lang);
6883: } else {
6884: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6885: }
6886: }
6887: }
6888: unless (grep(/^nolang$/,@currlangs)) {
6889: if ($env{'form.loginhelpurl_nolang.filename'}) {
6890: $changes{'helpurl'}{'nolang'} = 1;
6891: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6892: push(@newlangs,'nolang');
6893: }
6894: }
6895: if ($env{'form.loginhelpurl_add_lang'}) {
6896: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6897: ($env{'form.loginhelpurl_add_file.filename'})) {
6898: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6899: $addedfile = $env{'form.loginhelpurl_add_lang'};
6900: }
6901: }
6902: if ((@newlangs > 0) || ($addedfile)) {
6903: my $error;
6904: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6905: if ($configuserok eq 'ok') {
6906: if ($switchserver) {
6907: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6908: } elsif ($author_ok eq 'ok') {
6909: my @allnew = @newlangs;
6910: if ($addedfile ne '') {
6911: push(@allnew,$addedfile);
6912: }
6913: foreach my $lang (@allnew) {
6914: my $formelem = 'loginhelpurl_'.$lang;
6915: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6916: $formelem = 'loginhelpurl_add_file';
6917: }
6918: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6919: "help/$lang",'','',$newfile{$lang});
6920: if ($result eq 'ok') {
6921: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6922: $changes{'helpurl'}{$lang} = 1;
6923: } else {
6924: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6925: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6926: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6927: (!grep(/^\Q$lang\E$/,@delurls))) {
6928: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6929: }
6930: }
6931: }
6932: } else {
6933: $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);
6934: }
6935: } else {
6936: $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);
6937: }
6938: if ($error) {
6939: &Apache::lonnet::logthis($error);
6940: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6941: }
6942: }
1.160.6.56 raeburn 6943:
6944: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6945: if (ref($domconfig{'login'}) eq 'HASH') {
6946: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6947: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6948: if ($domservers{$lonhost}) {
6949: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6950: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 6951: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 6952: }
6953: }
6954: }
6955: }
6956: }
6957: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6958: foreach my $lonhost (sort(keys(%domservers))) {
6959: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6960: $changes{'headtag'}{$lonhost} = 1;
6961: } else {
6962: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6963: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6964: }
6965: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6966: push(@newhosts,$lonhost);
6967: } elsif ($currheadtagurls{$lonhost}) {
6968: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6969: if ($currexempt{$lonhost}) {
6970: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6971: $changes{'headtag'}{$lonhost} = 1;
6972: }
6973: } elsif ($possexempt{$lonhost}) {
6974: $changes{'headtag'}{$lonhost} = 1;
6975: }
6976: if ($possexempt{$lonhost}) {
6977: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6978: }
6979: }
6980: }
6981: }
6982: if (@newhosts) {
6983: my $error;
6984: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6985: if ($configuserok eq 'ok') {
6986: if ($switchserver) {
6987: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6988: } elsif ($author_ok eq 'ok') {
6989: foreach my $lonhost (@newhosts) {
6990: my $formelem = 'loginheadtag_'.$lonhost;
6991: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6992: "login/headtag/$lonhost",'','',
6993: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6994: if ($result eq 'ok') {
6995: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6996: $changes{'headtag'}{$lonhost} = 1;
6997: if ($possexempt{$lonhost}) {
6998: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6999: }
7000: } else {
7001: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7002: $newheadtagurls{$lonhost},$result);
7003: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7004: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7005: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7006: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7007: }
7008: }
7009: }
7010: } else {
7011: $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);
7012: }
7013: } else {
7014: $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);
7015: }
7016: if ($error) {
7017: &Apache::lonnet::logthis($error);
7018: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7019: }
7020: }
1.160.6.5 raeburn 7021: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7022:
7023: my $defaulthelpfile = '/adm/loginproblems.html';
7024: my $defaulttext = &mt('Default in use');
7025:
1.1 raeburn 7026: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7027: $dom);
7028: if ($putresult eq 'ok') {
1.160.6.14 raeburn 7029: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7030: my %defaultchecked = (
7031: 'coursecatalog' => 'on',
1.160.6.14 raeburn 7032: 'helpdesk' => 'on',
1.42 raeburn 7033: 'adminmail' => 'off',
1.43 raeburn 7034: 'newuser' => 'off',
1.42 raeburn 7035: );
1.55 raeburn 7036: if (ref($domconfig{'login'}) eq 'HASH') {
7037: foreach my $item (@toggles) {
7038: if ($defaultchecked{$item} eq 'on') {
7039: if (($domconfig{'login'}{$item} eq '0') &&
7040: ($env{'form.'.$item} eq '1')) {
7041: $changes{$item} = 1;
7042: } elsif (($domconfig{'login'}{$item} eq '' ||
7043: $domconfig{'login'}{$item} eq '1') &&
7044: ($env{'form.'.$item} eq '0')) {
7045: $changes{$item} = 1;
7046: }
7047: } elsif ($defaultchecked{$item} eq 'off') {
7048: if (($domconfig{'login'}{$item} eq '1') &&
7049: ($env{'form.'.$item} eq '0')) {
7050: $changes{$item} = 1;
7051: } elsif (($domconfig{'login'}{$item} eq '' ||
7052: $domconfig{'login'}{$item} eq '0') &&
7053: ($env{'form.'.$item} eq '1')) {
7054: $changes{$item} = 1;
7055: }
1.42 raeburn 7056: }
7057: }
1.41 raeburn 7058: }
1.6 raeburn 7059: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7060: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7061: if (ref($lastactref) eq 'HASH') {
7062: $lastactref->{'domainconfig'} = 1;
7063: }
1.1 raeburn 7064: $resulttext = &mt('Changes made:').'<ul>';
7065: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7066: if ($item eq 'loginvia') {
1.112 raeburn 7067: if (ref($changes{$item}) eq 'HASH') {
7068: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7069: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7070: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7071: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7072: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7073: $protocol = 'http' if ($protocol ne 'https');
7074: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7075:
7076: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7077: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7078: } else {
7079: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7080: }
7081: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7082: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7083: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7084: }
7085: $resulttext .= '</li>';
7086: } else {
7087: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7088: }
1.112 raeburn 7089: } else {
1.128 raeburn 7090: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7091: }
7092: }
1.128 raeburn 7093: $resulttext .= '</ul></li>';
1.112 raeburn 7094: }
1.160.6.5 raeburn 7095: } elsif ($item eq 'helpurl') {
7096: if (ref($changes{$item}) eq 'HASH') {
7097: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7098: if (grep(/^\Q$lang\E$/,@delurls)) {
7099: my ($chg,$link);
7100: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7101: if ($lang eq 'nolang') {
7102: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7103: } else {
7104: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7105: }
7106: $resulttext .= '<li>'.$chg.'</li>';
7107: } else {
7108: my $chg;
7109: if ($lang eq 'nolang') {
7110: $chg = &mt('custom log-in help file for no preferred language');
7111: } else {
7112: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7113: }
7114: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7115: $loginhash{'login'}{'helpurl'}{$lang}.
7116: '?inhibitmenu=yes',$chg,600,500).
7117: '</li>';
7118: }
7119: }
7120: }
1.160.6.56 raeburn 7121: } elsif ($item eq 'headtag') {
7122: if (ref($changes{$item}) eq 'HASH') {
7123: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7124: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7125: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7126: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7127: $resulttext .= '<li><a href="'.
7128: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7129: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7130: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7131: if ($possexempt{$lonhost}) {
7132: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7133: } else {
7134: $resulttext .= &mt('included for any client IP');
7135: }
7136: $resulttext .= '</li>';
7137: }
7138: }
7139: }
1.160.6.5 raeburn 7140: } elsif ($item eq 'captcha') {
7141: if (ref($loginhash{'login'}) eq 'HASH') {
7142: my $chgtxt;
7143: if ($loginhash{'login'}{$item} eq 'notused') {
7144: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7145: } else {
7146: my %captchas = &captcha_phrases();
7147: if ($captchas{$loginhash{'login'}{$item}}) {
7148: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7149: } else {
7150: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7151: }
7152: }
7153: $resulttext .= '<li>'.$chgtxt.'</li>';
7154: }
7155: } elsif ($item eq 'recaptchakeys') {
7156: if (ref($loginhash{'login'}) eq 'HASH') {
7157: my ($privkey,$pubkey);
7158: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7159: $pubkey = $loginhash{'login'}{$item}{'public'};
7160: $privkey = $loginhash{'login'}{$item}{'private'};
7161: }
7162: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7163: if (!$pubkey) {
7164: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7165: } else {
7166: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7167: }
7168: if (!$privkey) {
7169: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7170: } else {
1.160.6.53 raeburn 7171: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 7172: }
7173: $chgtxt .= '</ul>';
7174: $resulttext .= '<li>'.$chgtxt.'</li>';
7175: }
1.160.6.69 raeburn 7176: } elsif ($item eq 'recaptchaversion') {
7177: if (ref($loginhash{'login'}) eq 'HASH') {
7178: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
7179: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
7180: '</li>';
7181: }
7182: }
1.41 raeburn 7183: } else {
7184: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7185: }
1.1 raeburn 7186: }
1.6 raeburn 7187: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7188: } else {
7189: $resulttext = &mt('No changes made to log-in page settings');
7190: }
7191: } else {
1.11 albertel 7192: $resulttext = '<span class="LC_error">'.
7193: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7194: }
1.6 raeburn 7195: if ($errors) {
1.9 raeburn 7196: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7197: $errors.'</ul>';
7198: }
7199: return $resulttext;
7200: }
7201:
1.160.6.56 raeburn 7202: sub check_exempt_addresses {
7203: my ($iplist) = @_;
7204: $iplist =~ s/^\s+//;
7205: $iplist =~ s/\s+$//;
7206: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7207: my (@okips,$new);
7208: foreach my $ip (@poss_ips) {
7209: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7210: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7211: push(@okips,$ip);
7212: }
7213: }
7214: }
7215: if (@okips > 0) {
7216: $new = join(',',@okips);
7217: } else {
7218: $new = '';
7219: }
7220: return $new;
7221: }
7222:
1.6 raeburn 7223: sub color_font_choices {
7224: my %choices =
7225: &Apache::lonlocal::texthash (
7226: img => "Header",
7227: bgs => "Background colors",
7228: links => "Link colors",
1.55 raeburn 7229: images => "Images",
1.6 raeburn 7230: font => "Font color",
1.160.6.22 raeburn 7231: fontmenu => "Font menu",
1.76 raeburn 7232: pgbg => "Page",
1.6 raeburn 7233: tabbg => "Header",
7234: sidebg => "Border",
7235: link => "Link",
7236: alink => "Active link",
7237: vlink => "Visited link",
7238: );
7239: return %choices;
7240: }
7241:
7242: sub modify_rolecolors {
1.160.6.24 raeburn 7243: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7244: my ($resulttext,%rolehash);
7245: $rolehash{'rolecolors'} = {};
1.55 raeburn 7246: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7247: if ($domconfig{'rolecolors'} eq '') {
7248: $domconfig{'rolecolors'} = {};
7249: }
7250: }
1.9 raeburn 7251: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7252: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7253: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7254: $dom);
7255: if ($putresult eq 'ok') {
7256: if (keys(%changes) > 0) {
1.41 raeburn 7257: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7258: if (ref($lastactref) eq 'HASH') {
7259: $lastactref->{'domainconfig'} = 1;
7260: }
1.6 raeburn 7261: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7262: $rolehash{'rolecolors'});
7263: } else {
7264: $resulttext = &mt('No changes made to default color schemes');
7265: }
7266: } else {
1.11 albertel 7267: $resulttext = '<span class="LC_error">'.
7268: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7269: }
7270: if ($errors) {
7271: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7272: $errors.'</ul>';
7273: }
7274: return $resulttext;
7275: }
7276:
7277: sub modify_colors {
1.9 raeburn 7278: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7279: my (%changes,%choices);
1.51 raeburn 7280: my @bgs;
1.6 raeburn 7281: my @links = ('link','alink','vlink');
1.41 raeburn 7282: my @logintext;
1.6 raeburn 7283: my @images;
7284: my $servadm = $r->dir_config('lonAdmEMail');
7285: my $errors;
1.160.6.22 raeburn 7286: my %defaults;
1.6 raeburn 7287: foreach my $role (@{$roles}) {
7288: if ($role eq 'login') {
1.12 raeburn 7289: %choices = &login_choices();
1.41 raeburn 7290: @logintext = ('textcol','bgcol');
1.12 raeburn 7291: } else {
7292: %choices = &color_font_choices();
7293: }
7294: if ($role eq 'login') {
1.41 raeburn 7295: @images = ('img','logo','domlogo','login');
1.51 raeburn 7296: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7297: } else {
7298: @images = ('img');
1.160.6.22 raeburn 7299: @bgs = ('pgbg','tabbg','sidebg');
7300: }
7301: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7302: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7303: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7304: }
7305: if ($role eq 'login') {
7306: foreach my $item (@logintext) {
1.160.6.39 raeburn 7307: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7308: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7309: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7310: }
7311: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 7312: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7313: }
7314: }
7315: } else {
1.160.6.39 raeburn 7316: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7317: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7318: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7319: }
7320: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 7321: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7322: }
1.6 raeburn 7323: }
1.160.6.22 raeburn 7324: foreach my $item (@bgs) {
1.160.6.39 raeburn 7325: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7326: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7327: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7328: }
7329: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 7330: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7331: }
7332: }
7333: foreach my $item (@links) {
1.160.6.39 raeburn 7334: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7335: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7336: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7337: }
7338: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 7339: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7340: }
1.6 raeburn 7341: }
1.46 raeburn 7342: my ($configuserok,$author_ok,$switchserver) =
7343: &config_check($dom,$confname,$servadm);
1.9 raeburn 7344: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7345: if (ref($domconfig->{$role}) ne 'HASH') {
7346: $domconfig->{$role} = {};
7347: }
1.8 raeburn 7348: foreach my $img (@images) {
1.70 raeburn 7349: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7350: if (defined($env{'form.login_showlogo_'.$img})) {
7351: $confhash->{$role}{'showlogo'}{$img} = 1;
7352: } else {
7353: $confhash->{$role}{'showlogo'}{$img} = 0;
7354: }
7355: }
1.18 albertel 7356: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7357: && !defined($domconfig->{$role}{$img})
7358: && !$env{'form.'.$role.'_del_'.$img}
7359: && $env{'form.'.$role.'_import_'.$img}) {
7360: # import the old configured image from the .tab setting
7361: # if they haven't provided a new one
7362: $domconfig->{$role}{$img} =
7363: $env{'form.'.$role.'_import_'.$img};
7364: }
1.6 raeburn 7365: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7366: my $error;
1.6 raeburn 7367: if ($configuserok eq 'ok') {
1.9 raeburn 7368: if ($switchserver) {
1.12 raeburn 7369: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7370: } else {
7371: if ($author_ok eq 'ok') {
7372: my ($result,$logourl) =
7373: &publishlogo($r,'upload',$role.'_'.$img,
7374: $dom,$confname,$img,$width,$height);
7375: if ($result eq 'ok') {
7376: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7377: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7378: } else {
1.12 raeburn 7379: $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 7380: }
7381: } else {
1.46 raeburn 7382: $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 7383: }
7384: }
7385: } else {
1.46 raeburn 7386: $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 7387: }
7388: if ($error) {
1.8 raeburn 7389: &Apache::lonnet::logthis($error);
1.11 albertel 7390: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7391: }
7392: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7393: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7394: my $error;
7395: if ($configuserok eq 'ok') {
7396: # is confname an author?
7397: if ($switchserver eq '') {
7398: if ($author_ok eq 'ok') {
7399: my ($result,$logourl) =
7400: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7401: $dom,$confname,$img,$width,$height);
7402: if ($result eq 'ok') {
7403: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7404: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7405: }
7406: }
7407: }
7408: }
1.6 raeburn 7409: }
7410: }
7411: }
7412: if (ref($domconfig) eq 'HASH') {
7413: if (ref($domconfig->{$role}) eq 'HASH') {
7414: foreach my $img (@images) {
7415: if ($domconfig->{$role}{$img} ne '') {
7416: if ($env{'form.'.$role.'_del_'.$img}) {
7417: $confhash->{$role}{$img} = '';
1.12 raeburn 7418: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7419: } else {
1.9 raeburn 7420: if ($confhash->{$role}{$img} eq '') {
7421: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7422: }
1.6 raeburn 7423: }
7424: } else {
7425: if ($env{'form.'.$role.'_del_'.$img}) {
7426: $confhash->{$role}{$img} = '';
1.12 raeburn 7427: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7428: }
7429: }
1.70 raeburn 7430: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7431: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7432: if ($confhash->{$role}{'showlogo'}{$img} ne
7433: $domconfig->{$role}{'showlogo'}{$img}) {
7434: $changes{$role}{'showlogo'}{$img} = 1;
7435: }
7436: } else {
7437: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7438: $changes{$role}{'showlogo'}{$img} = 1;
7439: }
7440: }
7441: }
7442: }
1.6 raeburn 7443: if ($domconfig->{$role}{'font'} ne '') {
7444: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7445: $changes{$role}{'font'} = 1;
7446: }
7447: } else {
7448: if ($confhash->{$role}{'font'}) {
7449: $changes{$role}{'font'} = 1;
7450: }
7451: }
1.107 raeburn 7452: if ($role ne 'login') {
7453: if ($domconfig->{$role}{'fontmenu'} ne '') {
7454: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7455: $changes{$role}{'fontmenu'} = 1;
7456: }
7457: } else {
7458: if ($confhash->{$role}{'fontmenu'}) {
7459: $changes{$role}{'fontmenu'} = 1;
7460: }
1.97 tempelho 7461: }
7462: }
1.6 raeburn 7463: foreach my $item (@bgs) {
7464: if ($domconfig->{$role}{$item} ne '') {
7465: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7466: $changes{$role}{'bgs'}{$item} = 1;
7467: }
7468: } else {
7469: if ($confhash->{$role}{$item}) {
7470: $changes{$role}{'bgs'}{$item} = 1;
7471: }
7472: }
7473: }
7474: foreach my $item (@links) {
7475: if ($domconfig->{$role}{$item} ne '') {
7476: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7477: $changes{$role}{'links'}{$item} = 1;
7478: }
7479: } else {
7480: if ($confhash->{$role}{$item}) {
7481: $changes{$role}{'links'}{$item} = 1;
7482: }
7483: }
7484: }
1.41 raeburn 7485: foreach my $item (@logintext) {
7486: if ($domconfig->{$role}{$item} ne '') {
7487: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7488: $changes{$role}{'logintext'}{$item} = 1;
7489: }
7490: } else {
7491: if ($confhash->{$role}{$item}) {
7492: $changes{$role}{'logintext'}{$item} = 1;
7493: }
7494: }
7495: }
1.6 raeburn 7496: } else {
7497: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7498: \@logintext,$confhash,\%changes);
1.6 raeburn 7499: }
7500: } else {
7501: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7502: \@logintext,$confhash,\%changes);
1.6 raeburn 7503: }
7504: }
7505: return ($errors,%changes);
7506: }
7507:
1.46 raeburn 7508: sub config_check {
7509: my ($dom,$confname,$servadm) = @_;
7510: my ($configuserok,$author_ok,$switchserver,%currroles);
7511: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7512: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7513: $confname,$servadm);
7514: if ($configuserok eq 'ok') {
7515: $switchserver = &check_switchserver($dom,$confname);
7516: if ($switchserver eq '') {
7517: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7518: }
7519: }
7520: return ($configuserok,$author_ok,$switchserver);
7521: }
7522:
1.6 raeburn 7523: sub default_change_checker {
1.41 raeburn 7524: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7525: foreach my $item (@{$links}) {
7526: if ($confhash->{$role}{$item}) {
7527: $changes->{$role}{'links'}{$item} = 1;
7528: }
7529: }
7530: foreach my $item (@{$bgs}) {
7531: if ($confhash->{$role}{$item}) {
7532: $changes->{$role}{'bgs'}{$item} = 1;
7533: }
7534: }
1.41 raeburn 7535: foreach my $item (@{$logintext}) {
7536: if ($confhash->{$role}{$item}) {
7537: $changes->{$role}{'logintext'}{$item} = 1;
7538: }
7539: }
1.6 raeburn 7540: foreach my $img (@{$images}) {
7541: if ($env{'form.'.$role.'_del_'.$img}) {
7542: $confhash->{$role}{$img} = '';
1.12 raeburn 7543: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7544: }
1.70 raeburn 7545: if ($role eq 'login') {
7546: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7547: $changes->{$role}{'showlogo'}{$img} = 1;
7548: }
7549: }
1.6 raeburn 7550: }
7551: if ($confhash->{$role}{'font'}) {
7552: $changes->{$role}{'font'} = 1;
7553: }
1.48 raeburn 7554: }
1.6 raeburn 7555:
7556: sub display_colorchgs {
7557: my ($dom,$changes,$roles,$confhash) = @_;
7558: my (%choices,$resulttext);
7559: if (!grep(/^login$/,@{$roles})) {
7560: $resulttext = &mt('Changes made:').'<br />';
7561: }
7562: foreach my $role (@{$roles}) {
7563: if ($role eq 'login') {
7564: %choices = &login_choices();
7565: } else {
7566: %choices = &color_font_choices();
7567: }
7568: if (ref($changes->{$role}) eq 'HASH') {
7569: if ($role ne 'login') {
7570: $resulttext .= '<h4>'.&mt($role).'</h4>';
7571: }
7572: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7573: if ($role ne 'login') {
7574: $resulttext .= '<ul>';
7575: }
7576: if (ref($changes->{$role}{$key}) eq 'HASH') {
7577: if ($role ne 'login') {
7578: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7579: }
7580: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7581: if (($role eq 'login') && ($key eq 'showlogo')) {
7582: if ($confhash->{$role}{$key}{$item}) {
7583: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7584: } else {
7585: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7586: }
7587: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7588: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7589: } else {
1.12 raeburn 7590: my $newitem = $confhash->{$role}{$item};
7591: if ($key eq 'images') {
7592: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7593: }
7594: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7595: }
7596: }
7597: if ($role ne 'login') {
7598: $resulttext .= '</ul></li>';
7599: }
7600: } else {
7601: if ($confhash->{$role}{$key} eq '') {
7602: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7603: } else {
7604: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7605: }
7606: }
7607: if ($role ne 'login') {
7608: $resulttext .= '</ul>';
7609: }
7610: }
7611: }
7612: }
1.3 raeburn 7613: return $resulttext;
1.1 raeburn 7614: }
7615:
1.9 raeburn 7616: sub thumb_dimensions {
7617: return ('200','50');
7618: }
7619:
1.16 raeburn 7620: sub check_dimensions {
7621: my ($inputfile) = @_;
7622: my ($fullwidth,$fullheight);
7623: if ($inputfile =~ m|^[/\w.\-]+$|) {
7624: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7625: my $imageinfo = <PIPE>;
7626: if (!close(PIPE)) {
7627: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7628: }
7629: chomp($imageinfo);
7630: my ($fullsize) =
1.21 raeburn 7631: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7632: if ($fullsize) {
7633: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7634: }
7635: }
7636: }
7637: return ($fullwidth,$fullheight);
7638: }
7639:
1.9 raeburn 7640: sub check_configuser {
7641: my ($uhome,$dom,$confname,$servadm) = @_;
7642: my ($configuserok,%currroles);
7643: if ($uhome eq 'no_host') {
7644: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7645: my $configpass = &LONCAPA::Enrollment::create_password();
7646: $configuserok =
7647: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7648: $configpass,'','','','','',undef,$servadm);
7649: } else {
7650: $configuserok = 'ok';
7651: %currroles =
7652: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7653: }
7654: return ($configuserok,%currroles);
7655: }
7656:
7657: sub check_authorstatus {
7658: my ($dom,$confname,%currroles) = @_;
7659: my $author_ok;
1.40 raeburn 7660: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7661: my $start = time;
7662: my $end = 0;
7663: $author_ok =
7664: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7665: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7666: } else {
7667: $author_ok = 'ok';
7668: }
7669: return $author_ok;
7670: }
7671:
7672: sub publishlogo {
1.46 raeburn 7673: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 7674: my ($output,$fname,$logourl);
7675: if ($action eq 'upload') {
7676: $fname=$env{'form.'.$formname.'.filename'};
7677: chop($env{'form.'.$formname});
7678: } else {
7679: ($fname) = ($formname =~ /([^\/]+)$/);
7680: }
1.46 raeburn 7681: if ($savefileas ne '') {
7682: $fname = $savefileas;
7683: }
1.9 raeburn 7684: $fname=&Apache::lonnet::clean_filename($fname);
7685: # See if there is anything left
7686: unless ($fname) { return ('error: no uploaded file'); }
7687: $fname="$subdir/$fname";
1.160.6.5 raeburn 7688: my $docroot=$r->dir_config('lonDocRoot');
7689: my $filepath="$docroot/priv";
7690: my $relpath = "$dom/$confname";
1.9 raeburn 7691: my ($fnamepath,$file,$fetchthumb);
7692: $file=$fname;
7693: if ($fname=~m|/|) {
7694: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7695: }
1.160.6.26 raeburn 7696: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7697: my $count;
1.160.6.5 raeburn 7698: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7699: $filepath.="/$parts[$count]";
7700: if ((-e $filepath)!=1) {
7701: mkdir($filepath,02770);
7702: }
7703: }
7704: # Check for bad extension and disallow upload
7705: if ($file=~/\.(\w+)$/ &&
7706: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7707: $output =
1.160.6.25 raeburn 7708: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7709: } elsif ($file=~/\.(\w+)$/ &&
7710: !defined(&Apache::loncommon::fileembstyle($1))) {
7711: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7712: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 7713: $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 7714: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 7715: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7716: } else {
7717: my $source = $filepath.'/'.$file;
7718: my $logfile;
7719: if (!open($logfile,">>$source".'.log')) {
1.160.6.19 raeburn 7720: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7721: }
7722: print $logfile
7723: "\n================= Publish ".localtime()." ================\n".
7724: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7725: # Save the file
7726: if (!open(FH,'>'.$source)) {
7727: &Apache::lonnet::logthis('Failed to create '.$source);
7728: return (&mt('Failed to create file'));
7729: }
7730: if ($action eq 'upload') {
7731: if (!print FH ($env{'form.'.$formname})) {
7732: &Apache::lonnet::logthis('Failed to write to '.$source);
7733: return (&mt('Failed to write file'));
7734: }
7735: } else {
7736: my $original = &Apache::lonnet::filelocation('',$formname);
7737: if(!copy($original,$source)) {
7738: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7739: return (&mt('Failed to write file'));
7740: }
7741: }
7742: close(FH);
7743: chmod(0660, $source); # Permissions to rw-rw---.
7744:
7745: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7746: my $copyfile=$targetdir.'/'.$file;
7747:
7748: my @parts=split(/\//,$targetdir);
7749: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7750: for (my $count=5;$count<=$#parts;$count++) {
7751: $path.="/$parts[$count]";
7752: if (!-e $path) {
7753: print $logfile "\nCreating directory ".$path;
7754: mkdir($path,02770);
7755: }
7756: }
7757: my $versionresult;
7758: if (-e $copyfile) {
7759: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7760: } else {
7761: $versionresult = 'ok';
7762: }
7763: if ($versionresult eq 'ok') {
7764: if (copy($source,$copyfile)) {
7765: print $logfile "\nCopied original source to ".$copyfile."\n";
7766: $output = 'ok';
7767: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7768: push(@{$modified_urls},[$copyfile,$source]);
7769: my $metaoutput =
7770: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7771: unless ($registered_cleanup) {
7772: my $handlers = $r->get_handlers('PerlCleanupHandler');
7773: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7774: $registered_cleanup=1;
7775: }
1.9 raeburn 7776: } else {
7777: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7778: $output = &mt('Failed to copy file to RES space').", $!";
7779: }
7780: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7781: my $inputfile = $filepath.'/'.$file;
7782: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7783: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7784: if ($fullwidth ne '' && $fullheight ne '') {
7785: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7786: my $thumbsize = $thumbwidth.'x'.$thumbheight;
7787: system("convert -sample $thumbsize $inputfile $outfile");
7788: chmod(0660, $filepath.'/tn-'.$file);
7789: if (-e $outfile) {
7790: my $copyfile=$targetdir.'/tn-'.$file;
7791: if (copy($outfile,$copyfile)) {
7792: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7793: my $thumb_metaoutput =
7794: &write_metadata($dom,$confname,$formname,
7795: $targetdir,'tn-'.$file,$logfile);
7796: push(@{$modified_urls},[$copyfile,$outfile]);
7797: unless ($registered_cleanup) {
7798: my $handlers = $r->get_handlers('PerlCleanupHandler');
7799: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7800: $registered_cleanup=1;
7801: }
1.16 raeburn 7802: } else {
7803: print $logfile "\nUnable to write ".$copyfile.
7804: ':'.$!."\n";
7805: }
7806: }
1.9 raeburn 7807: }
7808: }
7809: }
7810: } else {
7811: $output = $versionresult;
7812: }
7813: }
7814: return ($output,$logourl);
7815: }
7816:
7817: sub logo_versioning {
7818: my ($targetdir,$file,$logfile) = @_;
7819: my $target = $targetdir.'/'.$file;
7820: my ($maxversion,$fn,$extn,$output);
7821: $maxversion = 0;
7822: if ($file =~ /^(.+)\.(\w+)$/) {
7823: $fn=$1;
7824: $extn=$2;
7825: }
7826: opendir(DIR,$targetdir);
7827: while (my $filename=readdir(DIR)) {
7828: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7829: $maxversion=($1>$maxversion)?$1:$maxversion;
7830: }
7831: }
7832: $maxversion++;
7833: print $logfile "\nCreating old version ".$maxversion."\n";
7834: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7835: if (copy($target,$copyfile)) {
7836: print $logfile "Copied old target to ".$copyfile."\n";
7837: $copyfile=$copyfile.'.meta';
7838: if (copy($target.'.meta',$copyfile)) {
7839: print $logfile "Copied old target metadata to ".$copyfile."\n";
7840: $output = 'ok';
7841: } else {
7842: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7843: $output = &mt('Failed to copy old meta').", $!, ";
7844: }
7845: } else {
7846: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7847: $output = &mt('Failed to copy old target').", $!, ";
7848: }
7849: return $output;
7850: }
7851:
7852: sub write_metadata {
7853: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7854: my (%metadatafields,%metadatakeys,$output);
7855: $metadatafields{'title'}=$formname;
7856: $metadatafields{'creationdate'}=time;
7857: $metadatafields{'lastrevisiondate'}=time;
7858: $metadatafields{'copyright'}='public';
7859: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7860: $env{'user.domain'};
7861: $metadatafields{'authorspace'}=$confname.':'.$dom;
7862: $metadatafields{'domain'}=$dom;
7863: {
7864: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7865: my $mfh;
1.155 raeburn 7866: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 7867: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7868: unless ($_=~/\./) {
7869: my $unikey=$_;
7870: $unikey=~/^([A-Za-z]+)/;
7871: my $tag=$1;
7872: $tag=~tr/A-Z/a-z/;
7873: print $mfh "\n\<$tag";
7874: foreach (split(/\,/,$metadatakeys{$unikey})) {
7875: my $value=$metadatafields{$unikey.'.'.$_};
7876: $value=~s/\"/\'\'/g;
7877: print $mfh ' '.$_.'="'.$value.'"';
7878: }
7879: print $mfh '>'.
7880: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7881: .'</'.$tag.'>';
7882: }
7883: }
7884: $output = 'ok';
7885: print $logfile "\nWrote metadata";
7886: close($mfh);
7887: } else {
7888: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7889: $output = &mt('Could not write metadata');
7890: }
7891: }
1.155 raeburn 7892: return $output;
7893: }
7894:
7895: sub notifysubscribed {
7896: foreach my $targetsource (@{$modified_urls}){
7897: next unless (ref($targetsource) eq 'ARRAY');
7898: my ($target,$source)=@{$targetsource};
7899: if ($source ne '') {
7900: if (open(my $logfh,'>>'.$source.'.log')) {
7901: print $logfh "\nCleanup phase: Notifications\n";
7902: my @subscribed=&subscribed_hosts($target);
7903: foreach my $subhost (@subscribed) {
7904: print $logfh "\nNotifying host ".$subhost.':';
7905: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7906: print $logfh $reply;
7907: }
7908: my @subscribedmeta=&subscribed_hosts("$target.meta");
7909: foreach my $subhost (@subscribedmeta) {
7910: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7911: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7912: $subhost);
7913: print $logfh $reply;
7914: }
7915: print $logfh "\n============ Done ============\n";
1.160 raeburn 7916: close($logfh);
1.155 raeburn 7917: }
7918: }
7919: }
7920: return OK;
7921: }
7922:
7923: sub subscribed_hosts {
7924: my ($target) = @_;
7925: my @subscribed;
7926: if (open(my $fh,"<$target.subscription")) {
7927: while (my $subline=<$fh>) {
7928: if ($subline =~ /^($match_lonid):/) {
7929: my $host = $1;
7930: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7931: unless (grep(/^\Q$host\E$/,@subscribed)) {
7932: push(@subscribed,$host);
7933: }
7934: }
7935: }
7936: }
7937: }
7938: return @subscribed;
1.9 raeburn 7939: }
7940:
7941: sub check_switchserver {
7942: my ($dom,$confname) = @_;
7943: my ($allowed,$switchserver);
7944: my $home = &Apache::lonnet::homeserver($confname,$dom);
7945: if ($home eq 'no_host') {
7946: $home = &Apache::lonnet::domain($dom,'primary');
7947: }
7948: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7949: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7950: if (!$allowed) {
1.160.6.11 raeburn 7951: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7952: }
7953: return $switchserver;
7954: }
7955:
1.1 raeburn 7956: sub modify_quotas {
1.160.6.30 raeburn 7957: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7958: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7959: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7960: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7961: $validationfieldsref);
1.86 raeburn 7962: if ($action eq 'quotas') {
7963: $context = 'tools';
1.160.6.26 raeburn 7964: } else {
1.86 raeburn 7965: $context = $action;
7966: }
7967: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7968: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7969: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7970: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7971: %titles = &courserequest_titles();
7972: $toolregexp = join('|',@usertools);
7973: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7974: $confname = $dom.'-domainconfig';
7975: my $servadm = $r->dir_config('lonAdmEMail');
7976: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7977: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7978: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7979: } elsif ($context eq 'requestauthor') {
7980: @usertools = ('author');
7981: %titles = &authorrequest_titles();
1.86 raeburn 7982: } else {
1.160.6.4 raeburn 7983: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7984: %titles = &tool_titles();
1.86 raeburn 7985: }
1.160.6.27 raeburn 7986: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7987: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7988: foreach my $key (keys(%env)) {
1.101 raeburn 7989: if ($context eq 'requestcourses') {
7990: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7991: my $item = $1;
7992: my $type = $2;
7993: if ($type =~ /^limit_(.+)/) {
7994: $limithash{$item}{$1} = $env{$key};
7995: } else {
7996: $confhash{$item}{$type} = $env{$key};
7997: }
7998: }
1.160.6.5 raeburn 7999: } elsif ($context eq 'requestauthor') {
8000: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8001: $confhash{$1} = $env{$key};
8002: }
1.101 raeburn 8003: } else {
1.86 raeburn 8004: if ($key =~ /^form\.quota_(.+)$/) {
8005: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 8006: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8007: $confhash{'authorquota'}{$1} = $env{$key};
8008: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8009: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8010: }
1.72 raeburn 8011: }
8012: }
1.160.6.5 raeburn 8013: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 8014: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8015: @approvalnotify = sort(@approvalnotify);
8016: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 8017: my @crstypes = ('official','unofficial','community','textbook');
8018: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8019: foreach my $type (@hasuniquecode) {
8020: if (grep(/^\Q$type\E$/,@crstypes)) {
8021: $confhash{'uniquecode'}{$type} = 1;
8022: }
8023: }
1.160.6.46 raeburn 8024: my (%newbook,%allpos);
1.160.6.30 raeburn 8025: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8026: foreach my $type ('textbooks','templates') {
8027: @{$allpos{$type}} = ();
8028: my $invalid;
8029: if ($type eq 'textbooks') {
8030: $invalid = &mt('Invalid LON-CAPA course for textbook');
8031: } else {
8032: $invalid = &mt('Invalid LON-CAPA course for template');
8033: }
8034: if ($env{'form.'.$type.'_addbook'}) {
8035: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8036: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8037: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8038: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8039: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8040: } else {
8041: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8042: my $position = $env{'form.'.$type.'_addbook_pos'};
8043: $position =~ s/\D+//g;
8044: if ($position ne '') {
8045: $allpos{$type}[$position] = $newbook{$type};
8046: }
1.160.6.30 raeburn 8047: }
1.160.6.46 raeburn 8048: } else {
8049: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 8050: }
8051: }
1.160.6.46 raeburn 8052: }
1.160.6.30 raeburn 8053: }
1.102 raeburn 8054: if (ref($domconfig{$action}) eq 'HASH') {
8055: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8056: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8057: $changes{'notify'}{'approval'} = 1;
8058: }
8059: } else {
1.144 raeburn 8060: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8061: $changes{'notify'}{'approval'} = 1;
8062: }
8063: }
1.160.6.30 raeburn 8064: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8065: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8066: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8067: unless ($confhash{'uniquecode'}{$crstype}) {
8068: $changes{'uniquecode'} = 1;
8069: }
8070: }
8071: unless ($changes{'uniquecode'}) {
8072: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8073: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8074: $changes{'uniquecode'} = 1;
8075: }
8076: }
8077: }
8078: } else {
8079: $changes{'uniquecode'} = 1;
8080: }
8081: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8082: $changes{'uniquecode'} = 1;
8083: }
8084: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8085: foreach my $type ('textbooks','templates') {
8086: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8087: my %deletions;
8088: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8089: if (@todelete) {
8090: map { $deletions{$_} = 1; } @todelete;
8091: }
8092: my %imgdeletions;
8093: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8094: if (@todeleteimages) {
8095: map { $imgdeletions{$_} = 1; } @todeleteimages;
8096: }
8097: my $maxnum = $env{'form.'.$type.'_maxnum'};
8098: for (my $i=0; $i<=$maxnum; $i++) {
8099: my $itemid = $env{'form.'.$type.'_id_'.$i};
8100: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8101: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8102: if ($deletions{$key}) {
8103: if ($domconfig{$action}{$type}{$key}{'image'}) {
8104: #FIXME need to obsolete item in RES space
8105: }
8106: next;
8107: } else {
8108: my $newpos = $env{'form.'.$itemid};
8109: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 8110: foreach my $item ('subject','title','publisher','author') {
8111: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8112: ($type eq 'templates'));
1.160.6.46 raeburn 8113: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8114: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8115: $changes{$type}{$key} = 1;
8116: }
8117: }
8118: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 8119: }
1.160.6.46 raeburn 8120: if ($imgdeletions{$key}) {
8121: $changes{$type}{$key} = 1;
8122: #FIXME need to obsolete item in RES space
8123: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8124: my ($cdom,$cnum) = split(/_/,$key);
8125: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8126: $cdom,$cnum,$type,$configuserok,
8127: $switchserver,$author_ok);
8128: if ($imgurl) {
8129: $confhash{$type}{$key}{'image'} = $imgurl;
8130: $changes{$type}{$key} = 1;
1.160.6.30 raeburn 8131: }
1.160.6.46 raeburn 8132: if ($error) {
8133: &Apache::lonnet::logthis($error);
8134: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8135: }
8136: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8137: $confhash{$type}{$key}{'image'} =
8138: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 8139: }
8140: }
8141: }
8142: }
8143: }
8144: }
1.102 raeburn 8145: } else {
1.144 raeburn 8146: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8147: $changes{'notify'}{'approval'} = 1;
8148: }
1.160.6.30 raeburn 8149: if (ref($confhash{'uniquecode'} eq 'HASH')) {
8150: $changes{'uniquecode'} = 1;
8151: }
8152: }
8153: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8154: foreach my $type ('textbooks','templates') {
8155: if ($newbook{$type}) {
8156: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 8157: foreach my $item ('subject','title','publisher','author') {
8158: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8159: ($type eq 'template'));
1.160.6.46 raeburn 8160: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8161: if ($env{'form.'.$type.'_addbook_'.$item}) {
8162: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8163: }
8164: }
8165: if ($type eq 'textbooks') {
8166: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8167: my ($cdom,$cnum) = split(/_/,$newbook{$type});
8168: my ($imageurl,$error) =
8169: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8170: $configuserok,$switchserver,$author_ok);
8171: if ($imageurl) {
8172: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8173: }
8174: if ($error) {
8175: &Apache::lonnet::logthis($error);
8176: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8177: }
8178: }
1.160.6.30 raeburn 8179: }
8180: }
1.160.6.46 raeburn 8181: if (@{$allpos{$type}} > 0) {
8182: my $idx = 0;
8183: foreach my $item (@{$allpos{$type}}) {
8184: if ($item ne '') {
8185: $confhash{$type}{$item}{'order'} = $idx;
8186: if (ref($domconfig{$action}) eq 'HASH') {
8187: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8188: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8189: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8190: $changes{$type}{$item} = 1;
8191: }
1.160.6.30 raeburn 8192: }
8193: }
8194: }
1.160.6.46 raeburn 8195: $idx ++;
1.160.6.30 raeburn 8196: }
8197: }
8198: }
8199: }
1.160.6.39 raeburn 8200: if (ref($validationitemsref) eq 'ARRAY') {
8201: foreach my $item (@{$validationitemsref}) {
8202: if ($item eq 'fields') {
8203: my @changed;
8204: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8205: if (@{$confhash{'validation'}{$item}} > 0) {
8206: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8207: }
1.160.6.65 raeburn 8208: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8209: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8210: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8211: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8212: $domconfig{'requestcourses'}{'validation'}{$item});
8213: } else {
8214: @changed = @{$confhash{'validation'}{$item}};
8215: }
1.160.6.39 raeburn 8216: } else {
8217: @changed = @{$confhash{'validation'}{$item}};
8218: }
8219: } else {
8220: @changed = @{$confhash{'validation'}{$item}};
8221: }
8222: if (@changed) {
8223: if ($confhash{'validation'}{$item}) {
8224: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8225: } else {
8226: $changes{'validation'}{$item} = &mt('None');
8227: }
8228: }
8229: } else {
8230: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8231: if ($item eq 'markup') {
8232: if ($env{'form.requestcourses_validation_'.$item}) {
8233: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8234: }
8235: }
1.160.6.65 raeburn 8236: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8237: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8238: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8239: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8240: }
8241: } else {
8242: if ($confhash{'validation'}{$item} ne '') {
8243: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8244: }
1.160.6.39 raeburn 8245: }
8246: } else {
8247: if ($confhash{'validation'}{$item} ne '') {
8248: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8249: }
8250: }
8251: }
8252: }
8253: }
8254: if ($env{'form.validationdc'}) {
8255: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 8256: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 8257: if (exists($domcoords{$newval})) {
8258: $confhash{'validation'}{'dc'} = $newval;
8259: }
8260: }
8261: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 8262: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8263: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8264: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8265: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8266: if ($confhash{'validation'}{'dc'} eq '') {
8267: $changes{'validation'}{'dc'} = &mt('None');
8268: } else {
8269: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8270: }
1.160.6.39 raeburn 8271: }
1.160.6.65 raeburn 8272: } elsif ($confhash{'validation'}{'dc'} ne '') {
8273: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 8274: }
8275: } elsif ($confhash{'validation'}{'dc'} ne '') {
8276: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8277: }
8278: } elsif ($confhash{'validation'}{'dc'} ne '') {
8279: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8280: }
1.160.6.65 raeburn 8281: } else {
8282: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8283: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8284: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8285: $changes{'validation'}{'dc'} = &mt('None');
8286: }
8287: }
1.160.6.39 raeburn 8288: }
8289: }
1.102 raeburn 8290: }
8291: } else {
1.86 raeburn 8292: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 8293: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8294: }
1.72 raeburn 8295: foreach my $item (@usertools) {
8296: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8297: my $unset;
1.101 raeburn 8298: if ($context eq 'requestcourses') {
1.104 raeburn 8299: $unset = '0';
8300: if ($type eq '_LC_adv') {
8301: $unset = '';
8302: }
1.101 raeburn 8303: if ($confhash{$item}{$type} eq 'autolimit') {
8304: $confhash{$item}{$type} .= '=';
8305: unless ($limithash{$item}{$type} =~ /\D/) {
8306: $confhash{$item}{$type} .= $limithash{$item}{$type};
8307: }
8308: }
1.160.6.5 raeburn 8309: } elsif ($context eq 'requestauthor') {
8310: $unset = '0';
8311: if ($type eq '_LC_adv') {
8312: $unset = '';
8313: }
1.72 raeburn 8314: } else {
1.101 raeburn 8315: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8316: $confhash{$item}{$type} = 1;
8317: } else {
8318: $confhash{$item}{$type} = 0;
8319: }
1.72 raeburn 8320: }
1.86 raeburn 8321: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 8322: if ($action eq 'requestauthor') {
8323: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8324: $changes{$type} = 1;
8325: }
8326: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8327: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8328: $changes{$item}{$type} = 1;
8329: }
8330: } else {
8331: if ($context eq 'requestcourses') {
1.104 raeburn 8332: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8333: $changes{$item}{$type} = 1;
8334: }
8335: } else {
8336: if (!$confhash{$item}{$type}) {
8337: $changes{$item}{$type} = 1;
8338: }
8339: }
8340: }
8341: } else {
8342: if ($context eq 'requestcourses') {
1.104 raeburn 8343: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8344: $changes{$item}{$type} = 1;
8345: }
1.160.6.5 raeburn 8346: } elsif ($context eq 'requestauthor') {
8347: if ($confhash{$type} ne $unset) {
8348: $changes{$type} = 1;
8349: }
1.72 raeburn 8350: } else {
8351: if (!$confhash{$item}{$type}) {
8352: $changes{$item}{$type} = 1;
8353: }
8354: }
8355: }
1.1 raeburn 8356: }
8357: }
1.160.6.5 raeburn 8358: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8359: if (ref($domconfig{'quotas'}) eq 'HASH') {
8360: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8361: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8362: if (exists($confhash{'defaultquota'}{$key})) {
8363: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8364: $changes{'defaultquota'}{$key} = 1;
8365: }
8366: } else {
8367: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8368: }
8369: }
1.86 raeburn 8370: } else {
8371: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8372: if (exists($confhash{'defaultquota'}{$key})) {
8373: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8374: $changes{'defaultquota'}{$key} = 1;
8375: }
8376: } else {
8377: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8378: }
1.1 raeburn 8379: }
8380: }
1.160.6.20 raeburn 8381: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8382: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8383: if (exists($confhash{'authorquota'}{$key})) {
8384: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8385: $changes{'authorquota'}{$key} = 1;
8386: }
8387: } else {
8388: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8389: }
8390: }
8391: }
1.1 raeburn 8392: }
1.86 raeburn 8393: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8394: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8395: if (ref($domconfig{'quotas'}) eq 'HASH') {
8396: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8397: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8398: $changes{'defaultquota'}{$key} = 1;
8399: }
8400: } else {
8401: if (!exists($domconfig{'quotas'}{$key})) {
8402: $changes{'defaultquota'}{$key} = 1;
8403: }
1.72 raeburn 8404: }
8405: } else {
1.86 raeburn 8406: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8407: }
1.1 raeburn 8408: }
8409: }
1.160.6.20 raeburn 8410: if (ref($confhash{'authorquota'}) eq 'HASH') {
8411: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8412: if (ref($domconfig{'quotas'}) eq 'HASH') {
8413: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8414: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8415: $changes{'authorquota'}{$key} = 1;
8416: }
8417: } else {
8418: $changes{'authorquota'}{$key} = 1;
8419: }
8420: } else {
8421: $changes{'authorquota'}{$key} = 1;
8422: }
8423: }
8424: }
1.1 raeburn 8425: }
1.72 raeburn 8426:
1.160.6.5 raeburn 8427: if ($context eq 'requestauthor') {
8428: $domdefaults{'requestauthor'} = \%confhash;
8429: } else {
8430: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 8431: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 8432: $domdefaults{$key} = $confhash{$key};
8433: }
1.160.6.5 raeburn 8434: }
1.72 raeburn 8435: }
1.160.6.5 raeburn 8436:
1.1 raeburn 8437: my %quotahash = (
1.86 raeburn 8438: $action => { %confhash }
1.1 raeburn 8439: );
8440: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8441: $dom);
8442: if ($putresult eq 'ok') {
8443: if (keys(%changes) > 0) {
1.72 raeburn 8444: my $cachetime = 24*60*60;
8445: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 8446: if (ref($lastactref) eq 'HASH') {
8447: $lastactref->{'domdefaults'} = 1;
8448: }
1.1 raeburn 8449: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 8450: unless (($context eq 'requestcourses') ||
8451: ($context eq 'requestauthor')) {
1.86 raeburn 8452: if (ref($changes{'defaultquota'}) eq 'HASH') {
8453: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8454: foreach my $type (@{$types},'default') {
8455: if (defined($changes{'defaultquota'}{$type})) {
8456: my $typetitle = $usertypes->{$type};
8457: if ($type eq 'default') {
8458: $typetitle = $othertitle;
8459: }
1.160.6.28 raeburn 8460: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8461: }
8462: }
1.86 raeburn 8463: $resulttext .= '</ul></li>';
1.72 raeburn 8464: }
1.160.6.20 raeburn 8465: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 8466: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 8467: foreach my $type (@{$types},'default') {
8468: if (defined($changes{'authorquota'}{$type})) {
8469: my $typetitle = $usertypes->{$type};
8470: if ($type eq 'default') {
8471: $typetitle = $othertitle;
8472: }
1.160.6.28 raeburn 8473: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 8474: }
8475: }
8476: $resulttext .= '</ul></li>';
8477: }
1.72 raeburn 8478: }
1.80 raeburn 8479: my %newenv;
1.72 raeburn 8480: foreach my $item (@usertools) {
1.160.6.5 raeburn 8481: my (%haschgs,%inconf);
8482: if ($context eq 'requestauthor') {
8483: %haschgs = %changes;
8484: %inconf = %confhash;
8485: } else {
8486: if (ref($changes{$item}) eq 'HASH') {
8487: %haschgs = %{$changes{$item}};
8488: }
8489: if (ref($confhash{$item}) eq 'HASH') {
8490: %inconf = %{$confhash{$item}};
8491: }
8492: }
8493: if (keys(%haschgs) > 0) {
1.80 raeburn 8494: my $newacc =
8495: &Apache::lonnet::usertools_access($env{'user.name'},
8496: $env{'user.domain'},
1.86 raeburn 8497: $item,'reload',$context);
1.160.6.5 raeburn 8498: if (($context eq 'requestcourses') ||
8499: ($context eq 'requestauthor')) {
1.108 raeburn 8500: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8501: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8502: }
8503: } else {
8504: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8505: $newenv{'environment.availabletools.'.$item} = $newacc;
8506: }
1.80 raeburn 8507: }
1.160.6.5 raeburn 8508: unless ($context eq 'requestauthor') {
8509: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8510: }
1.72 raeburn 8511: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 8512: if ($haschgs{$type}) {
1.72 raeburn 8513: my $typetitle = $usertypes->{$type};
8514: if ($type eq 'default') {
8515: $typetitle = $othertitle;
8516: } elsif ($type eq '_LC_adv') {
8517: $typetitle = 'LON-CAPA Advanced Users';
8518: }
1.160.6.5 raeburn 8519: if ($inconf{$type}) {
1.101 raeburn 8520: if ($context eq 'requestcourses') {
8521: my $cond;
1.160.6.5 raeburn 8522: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8523: if ($1 eq '') {
8524: $cond = &mt('(Automatic processing of any request).');
8525: } else {
8526: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8527: }
8528: } else {
1.160.6.5 raeburn 8529: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8530: }
8531: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 8532: } elsif ($context eq 'requestauthor') {
8533: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8534: $titles{$inconf{$type}},$typetitle);
8535:
1.101 raeburn 8536: } else {
8537: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8538: }
1.72 raeburn 8539: } else {
1.104 raeburn 8540: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 8541: if ($inconf{$type} eq '0') {
1.104 raeburn 8542: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8543: } else {
8544: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8545: }
8546: } else {
8547: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8548: }
1.72 raeburn 8549: }
8550: }
1.26 raeburn 8551: }
1.160.6.5 raeburn 8552: unless ($context eq 'requestauthor') {
8553: $resulttext .= '</ul></li>';
8554: }
1.26 raeburn 8555: }
1.1 raeburn 8556: }
1.160.6.5 raeburn 8557: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8558: if (ref($changes{'notify'}) eq 'HASH') {
8559: if ($changes{'notify'}{'approval'}) {
8560: if (ref($confhash{'notify'}) eq 'HASH') {
8561: if ($confhash{'notify'}{'approval'}) {
8562: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8563: } else {
1.160.6.5 raeburn 8564: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8565: }
8566: }
8567: }
8568: }
8569: }
1.160.6.30 raeburn 8570: if ($action eq 'requestcourses') {
8571: my @offon = ('off','on');
8572: if ($changes{'uniquecode'}) {
8573: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8574: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8575: $resulttext .= '<li>'.
8576: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8577: '</li>';
8578: } else {
8579: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8580: '</li>';
8581: }
8582: }
1.160.6.46 raeburn 8583: foreach my $type ('textbooks','templates') {
8584: if (ref($changes{$type}) eq 'HASH') {
8585: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8586: foreach my $key (sort(keys(%{$changes{$type}}))) {
8587: my %coursehash = &Apache::lonnet::coursedescription($key);
8588: my $coursetitle = $coursehash{'description'};
8589: my $position = $confhash{$type}{$key}{'order'} + 1;
8590: $resulttext .= '<li>';
1.160.6.47 raeburn 8591: foreach my $item ('subject','title','publisher','author') {
8592: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8593: ($type eq 'templates'));
1.160.6.46 raeburn 8594: my $name = $item.':';
8595: $name =~ s/^(\w)/\U$1/;
8596: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8597: }
8598: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8599: if ($type eq 'textbooks') {
8600: if ($confhash{$type}{$key}{'image'}) {
8601: $resulttext .= ' '.&mt('Image: [_1]',
8602: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8603: ' alt="Textbook cover" />').'<br />';
8604: }
8605: }
8606: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 8607: }
1.160.6.46 raeburn 8608: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 8609: }
8610: }
1.160.6.39 raeburn 8611: if (ref($changes{'validation'}) eq 'HASH') {
8612: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8613: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8614: foreach my $item (@{$validationitemsref}) {
8615: if (exists($changes{'validation'}{$item})) {
8616: if ($item eq 'markup') {
8617: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8618: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8619: } else {
8620: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8621: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8622: }
8623: }
8624: }
8625: if (exists($changes{'validation'}{'dc'})) {
8626: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8627: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8628: }
8629: }
8630: }
1.160.6.30 raeburn 8631: }
1.1 raeburn 8632: $resulttext .= '</ul>';
1.80 raeburn 8633: if (keys(%newenv)) {
8634: &Apache::lonnet::appenv(\%newenv);
8635: }
1.1 raeburn 8636: } else {
1.86 raeburn 8637: if ($context eq 'requestcourses') {
8638: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 8639: } elsif ($context eq 'requestauthor') {
8640: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8641: } else {
1.90 weissno 8642: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8643: }
1.1 raeburn 8644: }
8645: } else {
1.11 albertel 8646: $resulttext = '<span class="LC_error">'.
8647: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8648: }
1.160.6.30 raeburn 8649: if ($errors) {
8650: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8651: '<ul>'.$errors.'</ul></p>';
8652: }
1.3 raeburn 8653: return $resulttext;
1.1 raeburn 8654: }
8655:
1.160.6.30 raeburn 8656: sub process_textbook_image {
1.160.6.46 raeburn 8657: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 8658: my $filename = $env{'form.'.$caller.'.filename'};
8659: my ($error,$url);
8660: my ($width,$height) = (50,50);
8661: if ($configuserok eq 'ok') {
8662: if ($switchserver) {
8663: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8664: $switchserver);
8665: } elsif ($author_ok eq 'ok') {
8666: my ($result,$imageurl) =
8667: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46 raeburn 8668: "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 8669: if ($result eq 'ok') {
8670: $url = $imageurl;
8671: } else {
8672: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8673: }
8674: } else {
8675: $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);
8676: }
8677: } else {
8678: $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);
8679: }
8680: return ($url,$error);
8681: }
8682:
1.3 raeburn 8683: sub modify_autoenroll {
1.160.6.24 raeburn 8684: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 8685: my ($resulttext,%changes);
8686: my %currautoenroll;
8687: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
8688: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
8689: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
8690: }
8691: }
8692: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
8693: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 8694: sender => 'Sender for notification messages',
1.160.6.68 raeburn 8695: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
8696: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 8697: my @offon = ('off','on');
1.17 raeburn 8698: my $sender_uname = $env{'form.sender_uname'};
8699: my $sender_domain = $env{'form.sender_domain'};
8700: if ($sender_domain eq '') {
8701: $sender_uname = '';
8702: } elsif ($sender_uname eq '') {
8703: $sender_domain = '';
8704: }
1.129 raeburn 8705: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 8706: my $failsafe = $env{'form.autoenroll_failsafe'};
8707: $failsafe =~ s{^\s+|\s+$}{}g;
8708: if ($failsafe =~ /\D/) {
8709: undef($failsafe);
8710: }
1.1 raeburn 8711: my %autoenrollhash = (
1.129 raeburn 8712: autoenroll => { 'run' => $env{'form.autoenroll_run'},
8713: 'sender_uname' => $sender_uname,
8714: 'sender_domain' => $sender_domain,
8715: 'co-owners' => $coowners,
1.160.6.68 raeburn 8716: 'autofailsafe' => $failsafe,
1.1 raeburn 8717: }
8718: );
1.4 raeburn 8719: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
8720: $dom);
1.1 raeburn 8721: if ($putresult eq 'ok') {
8722: if (exists($currautoenroll{'run'})) {
8723: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
8724: $changes{'run'} = 1;
8725: }
8726: } elsif ($autorun) {
8727: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 8728: $changes{'run'} = 1;
1.1 raeburn 8729: }
8730: }
1.17 raeburn 8731: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 8732: $changes{'sender'} = 1;
8733: }
1.17 raeburn 8734: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 8735: $changes{'sender'} = 1;
8736: }
1.129 raeburn 8737: if ($currautoenroll{'co-owners'} ne '') {
8738: if ($currautoenroll{'co-owners'} ne $coowners) {
8739: $changes{'coowners'} = 1;
8740: }
8741: } elsif ($coowners) {
8742: $changes{'coowners'} = 1;
1.160.6.68 raeburn 8743: }
8744: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
8745: $changes{'autofailsafe'} = 1;
8746: }
1.1 raeburn 8747: if (keys(%changes) > 0) {
8748: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 8749: if ($changes{'run'}) {
1.1 raeburn 8750: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
8751: }
8752: if ($changes{'sender'}) {
1.17 raeburn 8753: if ($sender_uname eq '' || $sender_domain eq '') {
8754: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
8755: } else {
8756: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
8757: }
1.1 raeburn 8758: }
1.129 raeburn 8759: if ($changes{'coowners'}) {
8760: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
8761: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8762: if (ref($lastactref) eq 'HASH') {
8763: $lastactref->{'domainconfig'} = 1;
8764: }
1.129 raeburn 8765: }
1.160.6.68 raeburn 8766: if ($changes{'autofailsafe'}) {
8767: if ($failsafe ne '') {
1.160.6.82 raeburn 8768: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 8769: } else {
1.160.6.82 raeburn 8770: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 8771: }
8772: &Apache::lonnet::get_domain_defaults($dom,1);
8773: if (ref($lastactref) eq 'HASH') {
8774: $lastactref->{'domdefaults'} = 1;
8775: }
8776: }
1.1 raeburn 8777: $resulttext .= '</ul>';
8778: } else {
8779: $resulttext = &mt('No changes made to auto-enrollment settings');
8780: }
8781: } else {
1.11 albertel 8782: $resulttext = '<span class="LC_error">'.
8783: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8784: }
1.3 raeburn 8785: return $resulttext;
1.1 raeburn 8786: }
8787:
8788: sub modify_autoupdate {
1.3 raeburn 8789: my ($dom,%domconfig) = @_;
1.1 raeburn 8790: my ($resulttext,%currautoupdate,%fields,%changes);
8791: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
8792: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
8793: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
8794: }
8795: }
8796: my @offon = ('off','on');
8797: my %title = &Apache::lonlocal::texthash (
8798: run => 'Auto-update:',
8799: classlists => 'Updates to user information in classlists?'
8800: );
1.44 raeburn 8801: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8802: my %fieldtitles = &Apache::lonlocal::texthash (
8803: id => 'Student/Employee ID',
1.20 raeburn 8804: permanentemail => 'E-mail address',
1.1 raeburn 8805: lastname => 'Last Name',
8806: firstname => 'First Name',
8807: middlename => 'Middle Name',
1.132 raeburn 8808: generation => 'Generation',
1.1 raeburn 8809: );
1.142 raeburn 8810: $othertitle = &mt('All users');
1.1 raeburn 8811: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8812: $othertitle = &mt('Other users');
1.1 raeburn 8813: }
8814: foreach my $key (keys(%env)) {
8815: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8816: my ($usertype,$item) = ($1,$2);
8817: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8818: if ($usertype eq 'default') {
8819: push(@{$fields{$1}},$2);
8820: } elsif (ref($types) eq 'ARRAY') {
8821: if (grep(/^\Q$usertype\E$/,@{$types})) {
8822: push(@{$fields{$1}},$2);
8823: }
8824: }
8825: }
1.1 raeburn 8826: }
8827: }
1.131 raeburn 8828: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8829: @lockablenames = sort(@lockablenames);
8830: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8831: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8832: if (@changed) {
8833: $changes{'lockablenames'} = 1;
8834: }
8835: } else {
8836: if (@lockablenames) {
8837: $changes{'lockablenames'} = 1;
8838: }
8839: }
1.1 raeburn 8840: my %updatehash = (
8841: autoupdate => { run => $env{'form.autoupdate_run'},
8842: classlists => $env{'form.classlists'},
8843: fields => {%fields},
1.131 raeburn 8844: lockablenames => \@lockablenames,
1.1 raeburn 8845: }
8846: );
8847: foreach my $key (keys(%currautoupdate)) {
8848: if (($key eq 'run') || ($key eq 'classlists')) {
8849: if (exists($updatehash{autoupdate}{$key})) {
8850: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8851: $changes{$key} = 1;
8852: }
8853: }
8854: } elsif ($key eq 'fields') {
8855: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8856: foreach my $item (@{$types},'default') {
1.1 raeburn 8857: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8858: my $change = 0;
8859: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8860: if (!exists($fields{$item})) {
8861: $change = 1;
1.132 raeburn 8862: last;
1.1 raeburn 8863: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8864: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8865: $change = 1;
1.132 raeburn 8866: last;
1.1 raeburn 8867: }
8868: }
8869: }
8870: if ($change) {
8871: push(@{$changes{$key}},$item);
8872: }
1.26 raeburn 8873: }
1.1 raeburn 8874: }
8875: }
1.131 raeburn 8876: } elsif ($key eq 'lockablenames') {
8877: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8878: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8879: if (@changed) {
8880: $changes{'lockablenames'} = 1;
8881: }
8882: } else {
8883: if (@lockablenames) {
8884: $changes{'lockablenames'} = 1;
8885: }
8886: }
8887: }
8888: }
8889: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8890: if (@lockablenames) {
8891: $changes{'lockablenames'} = 1;
1.1 raeburn 8892: }
8893: }
1.26 raeburn 8894: foreach my $item (@{$types},'default') {
8895: if (defined($fields{$item})) {
8896: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8897: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8898: my $change = 0;
8899: if (ref($fields{$item}) eq 'ARRAY') {
8900: foreach my $type (@{$fields{$item}}) {
8901: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
8902: $change = 1;
8903: last;
8904: }
8905: }
8906: }
8907: if ($change) {
8908: push(@{$changes{'fields'}},$item);
8909: }
8910: } else {
1.26 raeburn 8911: push(@{$changes{'fields'}},$item);
8912: }
8913: } else {
8914: push(@{$changes{'fields'}},$item);
1.1 raeburn 8915: }
8916: }
8917: }
8918: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8919: $dom);
8920: if ($putresult eq 'ok') {
8921: if (keys(%changes) > 0) {
8922: $resulttext = &mt('Changes made:').'<ul>';
8923: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 8924: if ($key eq 'lockablenames') {
8925: $resulttext .= '<li>';
8926: if (@lockablenames) {
8927: $usertypes->{'default'} = $othertitle;
8928: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8929: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8930: } else {
8931: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8932: }
8933: $resulttext .= '</li>';
8934: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8935: foreach my $item (@{$changes{$key}}) {
8936: my @newvalues;
8937: foreach my $type (@{$fields{$item}}) {
8938: push(@newvalues,$fieldtitles{$type});
8939: }
1.3 raeburn 8940: my $newvaluestr;
8941: if (@newvalues > 0) {
8942: $newvaluestr = join(', ',@newvalues);
8943: } else {
8944: $newvaluestr = &mt('none');
1.6 raeburn 8945: }
1.1 raeburn 8946: if ($item eq 'default') {
1.26 raeburn 8947: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8948: } else {
1.26 raeburn 8949: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8950: }
8951: }
8952: } else {
8953: my $newvalue;
8954: if ($key eq 'run') {
8955: $newvalue = $offon[$env{'form.autoupdate_run'}];
8956: } else {
8957: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8958: }
1.1 raeburn 8959: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8960: }
8961: }
8962: $resulttext .= '</ul>';
8963: } else {
1.3 raeburn 8964: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8965: }
8966: } else {
1.11 albertel 8967: $resulttext = '<span class="LC_error">'.
8968: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8969: }
1.3 raeburn 8970: return $resulttext;
1.1 raeburn 8971: }
8972:
1.125 raeburn 8973: sub modify_autocreate {
8974: my ($dom,%domconfig) = @_;
8975: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8976: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8977: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8978: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8979: }
8980: }
8981: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8982: req => 'Auto-creation of validated requests for official courses',
8983: xmldc => 'Identity of course creator of courses from XML files',
8984: );
8985: my @types = ('xml','req');
8986: foreach my $item (@types) {
8987: $newvals{$item} = $env{'form.autocreate_'.$item};
8988: $newvals{$item} =~ s/\D//g;
8989: $newvals{$item} = 0 if ($newvals{$item} eq '');
8990: }
8991: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 8992: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 8993: unless (exists($domcoords{$newvals{'xmldc'}})) {
8994: $newvals{'xmldc'} = '';
8995: }
8996: %autocreatehash = (
8997: autocreate => { xml => $newvals{'xml'},
8998: req => $newvals{'req'},
8999: }
9000: );
9001: if ($newvals{'xmldc'} ne '') {
9002: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9003: }
9004: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9005: $dom);
9006: if ($putresult eq 'ok') {
9007: my @items = @types;
9008: if ($newvals{'xml'}) {
9009: push(@items,'xmldc');
9010: }
9011: foreach my $item (@items) {
9012: if (exists($currautocreate{$item})) {
9013: if ($currautocreate{$item} ne $newvals{$item}) {
9014: $changes{$item} = 1;
9015: }
9016: } elsif ($newvals{$item}) {
9017: $changes{$item} = 1;
9018: }
9019: }
9020: if (keys(%changes) > 0) {
9021: my @offon = ('off','on');
9022: $resulttext = &mt('Changes made:').'<ul>';
9023: foreach my $item (@types) {
9024: if ($changes{$item}) {
9025: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 9026: $resulttext .= '<li>'.
9027: &mt("$title{$item} set to [_1]$newtxt [_2]",
9028: '<b>','</b>').
9029: '</li>';
1.125 raeburn 9030: }
9031: }
9032: if ($changes{'xmldc'}) {
9033: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9034: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 9035: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9036: }
9037: $resulttext .= '</ul>';
9038: } else {
9039: $resulttext = &mt('No changes made to auto-creation settings');
9040: }
9041: } else {
9042: $resulttext = '<span class="LC_error">'.
9043: &mt('An error occurred: [_1]',$putresult).'</span>';
9044: }
9045: return $resulttext;
9046: }
9047:
1.23 raeburn 9048: sub modify_directorysrch {
1.160.6.81 raeburn 9049: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 9050: my ($resulttext,%changes);
9051: my %currdirsrch;
9052: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9053: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9054: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9055: }
9056: }
1.160.6.72 raeburn 9057: my %title = ( available => 'Institutional directory search available',
9058: localonly => 'Other domains can search institution',
9059: lcavailable => 'LON-CAPA directory search available',
9060: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9061: searchby => 'Search types',
9062: searchtypes => 'Search latitude');
9063: my @offon = ('off','on');
1.24 raeburn 9064: my @otherdoms = ('Yes','No');
1.23 raeburn 9065:
1.25 raeburn 9066: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9067: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9068: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9069:
1.44 raeburn 9070: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9071: if (keys(%{$usertypes}) == 0) {
9072: @cansearch = ('default');
9073: } else {
9074: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9075: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9076: if (!grep(/^\Q$type\E$/,@cansearch)) {
9077: push(@{$changes{'cansearch'}},$type);
9078: }
1.23 raeburn 9079: }
1.26 raeburn 9080: foreach my $type (@cansearch) {
9081: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9082: push(@{$changes{'cansearch'}},$type);
9083: }
1.23 raeburn 9084: }
1.26 raeburn 9085: } else {
9086: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9087: }
9088: }
9089:
9090: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9091: foreach my $by (@{$currdirsrch{'searchby'}}) {
9092: if (!grep(/^\Q$by\E$/,@searchby)) {
9093: push(@{$changes{'searchby'}},$by);
9094: }
9095: }
9096: foreach my $by (@searchby) {
9097: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9098: push(@{$changes{'searchby'}},$by);
9099: }
9100: }
9101: } else {
9102: push(@{$changes{'searchby'}},@searchby);
9103: }
1.25 raeburn 9104:
9105: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9106: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9107: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9108: push(@{$changes{'searchtypes'}},$type);
9109: }
9110: }
9111: foreach my $type (@searchtypes) {
9112: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9113: push(@{$changes{'searchtypes'}},$type);
9114: }
9115: }
9116: } else {
9117: if (exists($currdirsrch{'searchtypes'})) {
9118: foreach my $type (@searchtypes) {
9119: if ($type ne $currdirsrch{'searchtypes'}) {
9120: push(@{$changes{'searchtypes'}},$type);
9121: }
9122: }
9123: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9124: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9125: }
9126: } else {
9127: push(@{$changes{'searchtypes'}},@searchtypes);
9128: }
9129: }
9130:
1.23 raeburn 9131: my %dirsrch_hash = (
9132: directorysrch => { available => $env{'form.dirsrch_available'},
9133: cansearch => \@cansearch,
1.160.6.72 raeburn 9134: localonly => $env{'form.dirsrch_instlocalonly'},
9135: lclocalonly => $env{'form.dirsrch_domlocalonly'},
9136: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9137: searchby => \@searchby,
1.25 raeburn 9138: searchtypes => \@searchtypes,
1.23 raeburn 9139: }
9140: );
9141: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9142: $dom);
9143: if ($putresult eq 'ok') {
9144: if (exists($currdirsrch{'available'})) {
9145: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9146: $changes{'available'} = 1;
9147: }
9148: } else {
9149: if ($env{'form.dirsrch_available'} eq '1') {
9150: $changes{'available'} = 1;
9151: }
9152: }
1.160.6.72 raeburn 9153: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 9154: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
9155: $changes{'lcavailable'} = 1;
9156: }
1.24 raeburn 9157: } else {
1.160.6.72 raeburn 9158: if ($env{'form.dirsrch_lcavailable'} eq '1') {
9159: $changes{'lcavailable'} = 1;
9160: }
9161: }
9162: if (exists($currdirsrch{'localonly'})) {
9163: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9164: $changes{'localonly'} = 1;
9165: }
1.160.6.72 raeburn 9166: } else {
9167: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
9168: $changes{'localonly'} = 1;
9169: }
9170: }
9171: if (exists($currdirsrch{'lclocalonly'})) {
9172: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
9173: $changes{'lclocalonly'} = 1;
9174: }
9175: } else {
9176: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
9177: $changes{'lclocalonly'} = 1;
9178: }
1.24 raeburn 9179: }
1.23 raeburn 9180: if (keys(%changes) > 0) {
9181: $resulttext = &mt('Changes made:').'<ul>';
9182: if ($changes{'available'}) {
9183: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9184: }
1.160.6.72 raeburn 9185: if ($changes{'lcavailable'}) {
9186: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
9187: }
1.24 raeburn 9188: if ($changes{'localonly'}) {
1.160.6.72 raeburn 9189: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
9190: }
9191: if ($changes{'lclocalonly'}) {
9192: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 9193: }
1.23 raeburn 9194: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9195: my $chgtext;
1.26 raeburn 9196: if (ref($usertypes) eq 'HASH') {
9197: if (keys(%{$usertypes}) > 0) {
9198: foreach my $type (@{$types}) {
9199: if (grep(/^\Q$type\E$/,@cansearch)) {
9200: $chgtext .= $usertypes->{$type}.'; ';
9201: }
9202: }
9203: if (grep(/^default$/,@cansearch)) {
9204: $chgtext .= $othertitle;
9205: } else {
9206: $chgtext =~ s/\; $//;
9207: }
1.160.6.13 raeburn 9208: $resulttext .=
9209: '<li>'.
9210: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9211: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9212: '</li>';
1.23 raeburn 9213: }
9214: }
9215: }
9216: if (ref($changes{'searchby'}) eq 'ARRAY') {
9217: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9218: my $chgtext;
9219: foreach my $type (@{$titleorder}) {
9220: if (grep(/^\Q$type\E$/,@searchby)) {
9221: if (defined($searchtitles->{$type})) {
9222: $chgtext .= $searchtitles->{$type}.'; ';
9223: }
9224: }
9225: }
9226: $chgtext =~ s/\; $//;
9227: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9228: }
1.25 raeburn 9229: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9230: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9231: my $chgtext;
9232: foreach my $type (@{$srchtypeorder}) {
9233: if (grep(/^\Q$type\E$/,@searchtypes)) {
9234: if (defined($srchtypes_desc->{$type})) {
9235: $chgtext .= $srchtypes_desc->{$type}.'; ';
9236: }
9237: }
9238: }
9239: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 9240: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9241: }
9242: $resulttext .= '</ul>';
1.160.6.81 raeburn 9243: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
9244: if (ref($lastactref) eq 'HASH') {
9245: $lastactref->{'directorysrch'} = 1;
9246: }
1.23 raeburn 9247: } else {
1.160.6.72 raeburn 9248: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9249: }
9250: } else {
9251: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9252: &mt('An error occurred: [_1]',$putresult).'</span>';
9253: }
9254: return $resulttext;
9255: }
9256:
1.28 raeburn 9257: sub modify_contacts {
1.160.6.24 raeburn 9258: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9259: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9260: if (ref($domconfig{'contacts'}) eq 'HASH') {
9261: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9262: $currsetting{$key} = $domconfig{'contacts'}{$key};
9263: }
9264: }
1.160.6.78 raeburn 9265: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 9266: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 9267: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
9268: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.160.6.23 raeburn 9269: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 9270: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 9271: foreach my $type (@mailings) {
9272: @{$newsetting{$type}} =
9273: &Apache::loncommon::get_env_multiple('form.'.$type);
9274: foreach my $item (@contacts) {
9275: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9276: $contacts_hash{contacts}{$type}{$item} = 1;
9277: } else {
9278: $contacts_hash{contacts}{$type}{$item} = 0;
9279: }
1.160.6.78 raeburn 9280: }
1.28 raeburn 9281: $others{$type} = $env{'form.'.$type.'_others'};
9282: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 9283: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9284: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9285: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 9286: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
9287: $includestr{$type} = $env{'form.'.$type.'_includestr'};
9288: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
9289: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
9290: }
1.134 raeburn 9291: }
1.28 raeburn 9292: }
9293: foreach my $item (@contacts) {
9294: $to{$item} = $env{'form.'.$item};
9295: $contacts_hash{'contacts'}{$item} = $to{$item};
9296: }
1.160.6.23 raeburn 9297: foreach my $item (@toggles) {
9298: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9299: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9300: }
9301: }
1.160.6.78 raeburn 9302: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
9303: foreach my $field (@{$fields}) {
9304: if (ref($possoptions->{$field}) eq 'ARRAY') {
9305: my $value = $env{'form.helpform_'.$field};
9306: $value =~ s/^\s+|\s+$//g;
9307: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
9308: $contacts_hash{contacts}{'helpform'}{$field} = $value;
9309: if ($field eq 'screenshot') {
9310: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
9311: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
9312: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
9313: }
9314: }
9315: }
9316: }
9317: }
9318: }
1.28 raeburn 9319: if (keys(%currsetting) > 0) {
9320: foreach my $item (@contacts) {
9321: if ($to{$item} ne $currsetting{$item}) {
9322: $changes{$item} = 1;
9323: }
9324: }
9325: foreach my $type (@mailings) {
9326: foreach my $item (@contacts) {
9327: if (ref($currsetting{$type}) eq 'HASH') {
9328: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9329: push(@{$changes{$type}},$item);
9330: }
9331: } else {
9332: push(@{$changes{$type}},@{$newsetting{$type}});
9333: }
9334: }
9335: if ($others{$type} ne $currsetting{$type}{'others'}) {
9336: push(@{$changes{$type}},'others');
9337: }
1.160.6.78 raeburn 9338: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9339: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9340: push(@{$changes{$type}},'bcc');
9341: }
1.160.6.78 raeburn 9342: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
9343: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
9344: push(@{$changes{$type}},'include');
9345: }
9346: }
9347: }
9348: if (ref($fields) eq 'ARRAY') {
9349: if (ref($currsetting{'helpform'}) eq 'HASH') {
9350: foreach my $field (@{$fields}) {
9351: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
9352: push(@{$changes{'helpform'}},$field);
9353: }
9354: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9355: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
9356: push(@{$changes{'helpform'}},'maxsize');
9357: }
9358: }
9359: }
9360: } else {
9361: foreach my $field (@{$fields}) {
9362: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9363: push(@{$changes{'helpform'}},$field);
9364: }
9365: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9366: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9367: push(@{$changes{'helpform'}},'maxsize');
9368: }
9369: }
9370: }
1.134 raeburn 9371: }
1.28 raeburn 9372: }
9373: } else {
9374: my %default;
9375: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9376: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9377: $default{'errormail'} = 'adminemail';
9378: $default{'packagesmail'} = 'adminemail';
9379: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 9380: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 9381: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9382: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 9383: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9384: foreach my $item (@contacts) {
9385: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 9386: $changes{$item} = 1;
1.160.6.23 raeburn 9387: }
1.28 raeburn 9388: }
9389: foreach my $type (@mailings) {
9390: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9391: push(@{$changes{$type}},@{$newsetting{$type}});
9392: }
9393: if ($others{$type} ne '') {
9394: push(@{$changes{$type}},'others');
1.134 raeburn 9395: }
1.160.6.78 raeburn 9396: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9397: if ($bcc{$type} ne '') {
9398: push(@{$changes{$type}},'bcc');
9399: }
1.160.6.78 raeburn 9400: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
9401: push(@{$changes{$type}},'include');
9402: }
9403: }
9404: }
9405: if (ref($fields) eq 'ARRAY') {
9406: foreach my $field (@{$fields}) {
9407: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9408: push(@{$changes{'helpform'}},$field);
9409: }
9410: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9411: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9412: push(@{$changes{'helpform'}},'maxsize');
9413: }
9414: }
1.134 raeburn 9415: }
1.28 raeburn 9416: }
9417: }
1.160.6.23 raeburn 9418: foreach my $item (@toggles) {
9419: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9420: $changes{$item} = 1;
9421: } elsif ((!$env{'form.'.$item}) &&
9422: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9423: $changes{$item} = 1;
9424: }
9425: }
1.28 raeburn 9426: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9427: $dom);
9428: if ($putresult eq 'ok') {
9429: if (keys(%changes) > 0) {
1.160.6.24 raeburn 9430: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9431: if (ref($lastactref) eq 'HASH') {
9432: $lastactref->{'domainconfig'} = 1;
9433: }
1.28 raeburn 9434: my ($titles,$short_titles) = &contact_titles();
9435: $resulttext = &mt('Changes made:').'<ul>';
9436: foreach my $item (@contacts) {
9437: if ($changes{$item}) {
9438: $resulttext .= '<li>'.$titles->{$item}.
9439: &mt(' set to: ').
9440: '<span class="LC_cusr_emph">'.
9441: $to{$item}.'</span></li>';
9442: }
9443: }
9444: foreach my $type (@mailings) {
9445: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 9446: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
9447: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
9448: } else {
9449: $resulttext .= '<li>'.$titles->{$type}.': ';
9450: }
1.28 raeburn 9451: my @text;
9452: foreach my $item (@{$newsetting{$type}}) {
9453: push(@text,$short_titles->{$item});
9454: }
9455: if ($others{$type} ne '') {
9456: push(@text,$others{$type});
9457: }
1.160.6.78 raeburn 9458: if (@text) {
9459: $resulttext .= '<span class="LC_cusr_emph">'.
9460: join(', ',@text).'</span>';
9461: }
9462: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9463: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 9464: my $bcctext;
9465: if (@text) {
9466: $bcctext = ' '.&mt('with Bcc to');
9467: } else {
9468: $bcctext = '(Bcc)';
9469: }
9470: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9471: } elsif (!@text) {
9472: $resulttext .= &mt('No one');
1.134 raeburn 9473: }
1.160.6.78 raeburn 9474: if ($includestr{$type} ne '') {
9475: if ($includeloc{$type} eq 'b') {
9476: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
9477: } elsif ($includeloc{$type} eq 's') {
9478: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
9479: }
9480: }
9481: } elsif (!@text) {
9482: $resulttext .= &mt('No recipients');
1.134 raeburn 9483: }
9484: $resulttext .= '</li>';
1.28 raeburn 9485: }
9486: }
1.160.6.23 raeburn 9487: my @offon = ('off','on');
9488: if ($changes{'reporterrors'}) {
9489: $resulttext .= '<li>'.
9490: &mt('E-mail error reports to [_1] set to "'.
9491: $offon[$env{'form.reporterrors'}].'".',
9492: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9493: &mt('LON-CAPA core group - MSU'),600,500)).
9494: '</li>';
9495: }
9496: if ($changes{'reportupdates'}) {
9497: $resulttext .= '<li>'.
9498: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9499: $offon[$env{'form.reportupdates'}].'".',
9500: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9501: &mt('LON-CAPA core group - MSU'),600,500)).
9502: '</li>';
9503: }
1.160.6.78 raeburn 9504: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
9505: my (@optional,@required,@unused,$maxsizechg);
9506: foreach my $field (@{$changes{'helpform'}}) {
9507: if ($field eq 'maxsize') {
9508: $maxsizechg = 1;
9509: next;
9510: }
9511: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
9512: push(@optional,$field);
9513: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
9514: push(@unused,$field);
9515: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
9516: push(@required,$field);
9517: }
9518: }
9519: if (@optional) {
9520: $resulttext .= '<li>'.
9521: &mt('Help form fields changed to "Optional": [_1].',
9522: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
9523: '</li>';
9524: }
9525: if (@required) {
9526: $resulttext .= '<li>'.
9527: &mt('Help form fields changed to "Required": [_1].',
9528: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
9529: '</li>';
9530: }
9531: if (@unused) {
9532: $resulttext .= '<li>'.
9533: &mt('Help form fields changed to "Not shown": [_1].',
9534: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
9535: '</li>';
9536: }
9537: if ($maxsizechg) {
9538: $resulttext .= '<li>'.
9539: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
9540: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
9541: '</li>';
9542:
9543: }
9544: }
1.28 raeburn 9545: $resulttext .= '</ul>';
9546: } else {
1.160.6.78 raeburn 9547: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 9548: }
9549: } else {
9550: $resulttext = '<span class="LC_error">'.
9551: &mt('An error occurred: [_1].',$putresult).'</span>';
9552: }
9553: return $resulttext;
9554: }
9555:
9556: sub modify_usercreation {
1.27 raeburn 9557: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9558: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9559: my $warningmsg;
1.27 raeburn 9560: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9561: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 9562: if ($key eq 'cancreate') {
9563: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9564: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9565: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 9566: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9567: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 9568: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9569: } else {
9570: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9571: }
1.50 raeburn 9572: }
1.43 raeburn 9573: }
1.160.6.34 raeburn 9574: } elsif ($key eq 'email_rule') {
9575: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9576: } else {
9577: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 9578: }
9579: }
1.34 raeburn 9580: }
1.160.6.34 raeburn 9581: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
9582: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
9583: my @contexts = ('author','course','requestcrs');
9584: foreach my $item(@contexts) {
9585: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9586: }
1.34 raeburn 9587: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9588: foreach my $item (@contexts) {
1.160.6.34 raeburn 9589: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9590: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9591: }
1.27 raeburn 9592: }
1.34 raeburn 9593: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9594: foreach my $item (@contexts) {
1.43 raeburn 9595: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9596: if ($cancreate{$item} ne 'any') {
9597: push(@{$changes{'cancreate'}},$item);
9598: }
9599: } else {
9600: if ($cancreate{$item} ne 'none') {
9601: push(@{$changes{'cancreate'}},$item);
9602: }
1.27 raeburn 9603: }
9604: }
9605: } else {
1.43 raeburn 9606: foreach my $item (@contexts) {
1.34 raeburn 9607: push(@{$changes{'cancreate'}},$item);
9608: }
1.27 raeburn 9609: }
1.34 raeburn 9610:
1.27 raeburn 9611: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9612: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9613: if (!grep(/^\Q$type\E$/,@username_rule)) {
9614: push(@{$changes{'username_rule'}},$type);
9615: }
9616: }
9617: foreach my $type (@username_rule) {
9618: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9619: push(@{$changes{'username_rule'}},$type);
9620: }
9621: }
9622: } else {
9623: push(@{$changes{'username_rule'}},@username_rule);
9624: }
9625:
1.32 raeburn 9626: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9627: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9628: if (!grep(/^\Q$type\E$/,@id_rule)) {
9629: push(@{$changes{'id_rule'}},$type);
9630: }
9631: }
9632: foreach my $type (@id_rule) {
9633: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9634: push(@{$changes{'id_rule'}},$type);
9635: }
9636: }
9637: } else {
9638: push(@{$changes{'id_rule'}},@id_rule);
9639: }
9640:
1.43 raeburn 9641: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9642: my @authtypes = ('int','krb4','krb5','loc');
9643: my %authhash;
1.43 raeburn 9644: foreach my $item (@authen_contexts) {
1.28 raeburn 9645: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9646: foreach my $auth (@authtypes) {
9647: if (grep(/^\Q$auth\E$/,@authallowed)) {
9648: $authhash{$item}{$auth} = 1;
9649: } else {
9650: $authhash{$item}{$auth} = 0;
9651: }
9652: }
9653: }
9654: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9655: foreach my $item (@authen_contexts) {
1.28 raeburn 9656: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
9657: foreach my $auth (@authtypes) {
9658: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
9659: push(@{$changes{'authtypes'}},$item);
9660: last;
9661: }
9662: }
9663: }
9664: }
9665: } else {
1.43 raeburn 9666: foreach my $item (@authen_contexts) {
1.28 raeburn 9667: push(@{$changes{'authtypes'}},$item);
9668: }
9669: }
9670:
1.160.6.34 raeburn 9671: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
9672: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
9673: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
9674: $save_usercreate{'id_rule'} = \@id_rule;
9675: $save_usercreate{'username_rule'} = \@username_rule,
9676: $save_usercreate{'authtypes'} = \%authhash;
9677:
1.27 raeburn 9678: my %usercreation_hash = (
1.160.6.34 raeburn 9679: usercreation => \%save_usercreate,
9680: );
1.27 raeburn 9681:
9682: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
9683: $dom);
1.50 raeburn 9684:
1.160.6.34 raeburn 9685: if ($putresult eq 'ok') {
9686: if (keys(%changes) > 0) {
9687: $resulttext = &mt('Changes made:').'<ul>';
9688: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9689: my %lt = &usercreation_types();
9690: foreach my $type (@{$changes{'cancreate'}}) {
9691: my $chgtext = $lt{$type}.', ';
9692: if ($cancreate{$type} eq 'none') {
9693: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
9694: } elsif ($cancreate{$type} eq 'any') {
9695: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
9696: } elsif ($cancreate{$type} eq 'official') {
9697: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
9698: } elsif ($cancreate{$type} eq 'unofficial') {
9699: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
9700: }
9701: $resulttext .= '<li>'.$chgtext.'</li>';
9702: }
9703: }
9704: if (ref($changes{'username_rule'}) eq 'ARRAY') {
9705: my ($rules,$ruleorder) =
9706: &Apache::lonnet::inst_userrules($dom,'username');
9707: my $chgtext = '<ul>';
9708: foreach my $type (@username_rule) {
9709: if (ref($rules->{$type}) eq 'HASH') {
9710: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
9711: }
9712: }
9713: $chgtext .= '</ul>';
9714: if (@username_rule > 0) {
9715: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9716: } else {
9717: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
9718: }
9719: }
9720: if (ref($changes{'id_rule'}) eq 'ARRAY') {
9721: my ($idrules,$idruleorder) =
9722: &Apache::lonnet::inst_userrules($dom,'id');
9723: my $chgtext = '<ul>';
9724: foreach my $type (@id_rule) {
9725: if (ref($idrules->{$type}) eq 'HASH') {
9726: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
9727: }
9728: }
9729: $chgtext .= '</ul>';
9730: if (@id_rule > 0) {
9731: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9732: } else {
9733: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
9734: }
9735: }
9736: my %authname = &authtype_names();
9737: my %context_title = &context_names();
9738: if (ref($changes{'authtypes'}) eq 'ARRAY') {
9739: my $chgtext = '<ul>';
9740: foreach my $type (@{$changes{'authtypes'}}) {
9741: my @allowed;
9742: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
9743: foreach my $auth (@authtypes) {
9744: if ($authhash{$type}{$auth}) {
9745: push(@allowed,$authname{$auth});
9746: }
9747: }
9748: if (@allowed > 0) {
9749: $chgtext .= join(', ',@allowed).'</li>';
9750: } else {
9751: $chgtext .= &mt('none').'</li>';
9752: }
9753: }
9754: $chgtext .= '</ul>';
9755: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
9756: $resulttext .= '</li>';
9757: }
9758: $resulttext .= '</ul>';
9759: } else {
9760: $resulttext = &mt('No changes made to user creation settings');
9761: }
9762: } else {
9763: $resulttext = '<span class="LC_error">'.
9764: &mt('An error occurred: [_1]',$putresult).'</span>';
9765: }
9766: if ($warningmsg ne '') {
9767: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9768: }
9769: return $resulttext;
9770: }
9771:
9772: sub modify_selfcreation {
9773: my ($dom,%domconfig) = @_;
9774: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
9775: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 9776: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9777: if (ref($types) eq 'ARRAY') {
9778: $usertypes->{'default'} = $othertitle;
9779: push(@{$types},'default');
9780: }
1.160.6.34 raeburn 9781: #
9782: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
9783: #
9784: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9785: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9786: if ($key eq 'cancreate') {
9787: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9788: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9789: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9790: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 9791: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 9792: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 9793: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 9794: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9795: } else {
9796: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9797: }
9798: }
9799: }
9800: } elsif ($key eq 'email_rule') {
9801: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9802: } else {
9803: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9804: }
9805: }
9806: }
9807: #
9808: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
9809: #
9810: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9811: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9812: if ($key eq 'selfcreate') {
9813: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
9814: } else {
9815: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
9816: }
9817: }
9818: }
9819:
9820: my @contexts = ('selfcreate');
9821: @{$cancreate{'selfcreate'}} = ();
9822: %{$cancreate{'emailusername'}} = ();
9823: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 9824: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 9825: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 9826: my %selfcreatetypes = (
9827: sso => 'users authenticated by institutional single sign on',
9828: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 9829: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 9830: );
1.160.6.34 raeburn 9831: #
9832: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
9833: # is permitted.
9834: #
1.160.6.40 raeburn 9835:
9836: my @statuses;
9837: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9838: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
9839: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
9840: }
9841: }
9842: push(@statuses,'default');
9843:
1.160.6.35 raeburn 9844: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 9845: if ($item eq 'email') {
1.160.6.40 raeburn 9846: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 9847: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 9848: push(@contexts,'selfcreateprocessing');
9849: foreach my $type (@statuses) {
9850: if ($type eq 'default') {
9851: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
9852: } else {
9853: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
9854: }
9855: }
1.160.6.34 raeburn 9856: }
9857: } else {
9858: if ($env{'form.cancreate_'.$item}) {
9859: push(@{$cancreate{'selfcreate'}},$item);
9860: }
9861: }
9862: }
9863: my (@email_rule,%userinfo,%savecaptcha);
9864: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9865: #
1.160.6.35 raeburn 9866: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9867: # 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 9868: #
1.160.6.40 raeburn 9869:
1.160.6.48 raeburn 9870: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 9871: push(@contexts,'emailusername');
1.160.6.35 raeburn 9872: if (ref($types) eq 'ARRAY') {
9873: foreach my $type (@{$types}) {
9874: if (ref($infofields) eq 'ARRAY') {
9875: foreach my $field (@{$infofields}) {
9876: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9877: $cancreate{'emailusername'}{$type}{$field} = $1;
9878: }
9879: }
1.160.6.34 raeburn 9880: }
9881: }
9882: }
9883: #
9884: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9885: # queued requests for self-creation of account using e-mail address as username
9886: #
9887:
9888: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9889: @approvalnotify = sort(@approvalnotify);
9890: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9891: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9892: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9893: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9894: push(@{$changes{'cancreate'}},'notify');
9895: }
9896: } else {
9897: if ($cancreate{'notify'}{'approval'}) {
9898: push(@{$changes{'cancreate'}},'notify');
9899: }
9900: }
9901: } elsif ($cancreate{'notify'}{'approval'}) {
9902: push(@{$changes{'cancreate'}},'notify');
9903: }
9904:
9905: #
9906: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9907: #
9908: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9909: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9910: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9911: if (@{$curr_usercreation{'email_rule'}} > 0) {
9912: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9913: if (!grep(/^\Q$type\E$/,@email_rule)) {
9914: push(@{$changes{'email_rule'}},$type);
9915: }
9916: }
9917: }
9918: if (@email_rule > 0) {
9919: foreach my $type (@email_rule) {
9920: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9921: push(@{$changes{'email_rule'}},$type);
9922: }
9923: }
9924: }
9925: } elsif (@email_rule > 0) {
9926: push(@{$changes{'email_rule'}},@email_rule);
9927: }
9928: }
9929: #
1.160.6.40 raeburn 9930: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 9931: # institutional log-in.
9932: #
9933: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9934: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9935: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
9936: ($domdefaults{'auth_def'} eq 'localauth'))) {
9937: $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.').' '.
9938: &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.');
9939: }
9940: }
9941: my @fields = ('lastname','firstname','middlename','generation',
9942: 'permanentemail','id');
1.160.6.44 raeburn 9943: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 9944: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9945: #
9946: # Where usernames may created for institutional log-in and/or institutional single sign on:
9947: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9948: # may self-create accounts
9949: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
9950: # which the user may supply, if institutional data is unavailable.
9951: #
9952: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
9953: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 9954: if (@{$types} > 1) {
1.160.6.34 raeburn 9955: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
9956: push(@contexts,'statustocreate');
9957: } else {
9958: undef($cancreate{'statustocreate'});
9959: }
9960: foreach my $type (@{$types}) {
9961: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
9962: foreach my $field (@fields) {
9963: if (grep(/^\Q$field\E$/,@modifiable)) {
9964: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9965: } else {
9966: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9967: }
9968: }
9969: }
9970: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9971: foreach my $type (@{$types}) {
9972: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9973: foreach my $field (@fields) {
9974: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9975: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9976: push(@{$changes{'selfcreate'}},$type);
9977: last;
9978: }
9979: }
9980: }
9981: }
9982: } else {
9983: foreach my $type (@{$types}) {
9984: push(@{$changes{'selfcreate'}},$type);
9985: }
9986: }
9987: }
1.160.6.44 raeburn 9988: foreach my $field (@shibfields) {
9989: if ($env{'form.shibenv_'.$field} ne '') {
9990: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
9991: }
9992: }
9993: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9994: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
9995: foreach my $field (@shibfields) {
9996: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
9997: push(@{$changes{'cancreate'}},'shibenv');
9998: }
9999: }
10000: } else {
10001: foreach my $field (@shibfields) {
10002: if ($env{'form.shibenv_'.$field}) {
10003: push(@{$changes{'cancreate'}},'shibenv');
10004: last;
10005: }
10006: }
10007: }
10008: }
1.160.6.34 raeburn 10009: }
10010: foreach my $item (@contexts) {
10011: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10012: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10013: if (ref($cancreate{$item}) eq 'ARRAY') {
10014: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10015: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10016: push(@{$changes{'cancreate'}},$item);
10017: }
10018: }
10019: }
10020: }
10021: if (ref($cancreate{$item}) eq 'ARRAY') {
10022: foreach my $type (@{$cancreate{$item}}) {
10023: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10024: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10025: push(@{$changes{'cancreate'}},$item);
10026: }
10027: }
10028: }
10029: }
10030: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10031: if (ref($cancreate{$item}) eq 'HASH') {
10032: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 10033: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10034: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10035: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10036: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10037: push(@{$changes{'cancreate'}},$item);
10038: }
10039: }
10040: }
1.160.6.40 raeburn 10041: } elsif ($item eq 'selfcreateprocessing') {
10042: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10043: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10044: push(@{$changes{'cancreate'}},$item);
10045: }
10046: }
1.160.6.35 raeburn 10047: } else {
10048: if (!$cancreate{$item}{$curr}) {
10049: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10050: push(@{$changes{'cancreate'}},$item);
10051: }
1.160.6.34 raeburn 10052: }
10053: }
10054: }
10055: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 10056: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10057: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10058: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10059: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10060: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10061: push(@{$changes{'cancreate'}},$item);
10062: }
10063: }
10064: } else {
10065: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10066: push(@{$changes{'cancreate'}},$item);
10067: }
10068: }
10069: }
1.160.6.40 raeburn 10070: } elsif ($item eq 'selfcreateprocessing') {
10071: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10072: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10073: push(@{$changes{'cancreate'}},$item);
10074: }
10075: }
1.160.6.35 raeburn 10076: } else {
10077: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10078: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10079: push(@{$changes{'cancreate'}},$item);
10080: }
1.160.6.34 raeburn 10081: }
10082: }
10083: }
10084: }
10085: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10086: if (ref($cancreate{$item}) eq 'ARRAY') {
10087: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10088: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10089: push(@{$changes{'cancreate'}},$item);
10090: }
10091: }
10092: } elsif (ref($cancreate{$item}) eq 'HASH') {
10093: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10094: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10095: push(@{$changes{'cancreate'}},$item);
10096: }
10097: }
10098: }
10099: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 10100: if (ref($cancreate{$item}) eq 'HASH') {
10101: foreach my $type (keys(%{$cancreate{$item}})) {
10102: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10103: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10104: if ($cancreate{$item}{$type}{$field}) {
10105: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10106: push(@{$changes{'cancreate'}},$item);
10107: }
10108: last;
10109: }
10110: }
10111: }
10112: }
1.160.6.34 raeburn 10113: }
10114: }
10115: }
10116: #
10117: # Populate %save_usercreate hash with updates to self-creation configuration.
10118: #
10119: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10120: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 10121: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 10122: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10123: if (ref($cancreate{'notify'}) eq 'HASH') {
10124: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10125: }
1.160.6.40 raeburn 10126: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10127: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10128: }
1.160.6.34 raeburn 10129: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10130: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10131: }
1.160.6.44 raeburn 10132: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10133: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10134: }
1.160.6.34 raeburn 10135: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.85 raeburn 10136: $save_usercreate{'email_rule'} = \@email_rule;
1.160.6.34 raeburn 10137:
10138: my %userconfig_hash = (
10139: usercreation => \%save_usercreate,
10140: usermodification => \%save_usermodify,
10141: );
10142: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10143: $dom);
10144: #
10145: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10146: #
1.27 raeburn 10147: if ($putresult eq 'ok') {
10148: if (keys(%changes) > 0) {
10149: $resulttext = &mt('Changes made:').'<ul>';
10150: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 10151: my %lt = &selfcreation_types();
1.34 raeburn 10152: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10153: my $chgtext;
1.45 raeburn 10154: if ($type eq 'selfcreate') {
1.50 raeburn 10155: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 10156: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10157: } else {
1.160.6.34 raeburn 10158: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10159: '<ul>';
1.50 raeburn 10160: foreach my $case (@{$cancreate{$type}}) {
10161: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10162: }
10163: $chgtext .= '</ul>';
1.100 raeburn 10164: if (ref($cancreate{$type}) eq 'ARRAY') {
10165: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10166: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10167: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 10168: $chgtext .= '<br />'.
10169: '<span class="LC_warning">'.
10170: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10171: '</span>';
1.100 raeburn 10172: }
10173: }
10174: }
10175: }
1.43 raeburn 10176: }
1.160.6.44 raeburn 10177: } elsif ($type eq 'shibenv') {
10178: if (keys(%{$cancreate{$type}}) == 0) {
10179: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10180: } else {
10181: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10182: '<ul>';
10183: foreach my $field (@shibfields) {
10184: next if ($cancreate{$type}{$field} eq '');
10185: if ($field eq 'inststatus') {
10186: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10187: } else {
10188: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10189: }
10190: }
10191: $chgtext .= '</ul>';
10192: }
1.93 raeburn 10193: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10194: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10195: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10196: if (@{$cancreate{'selfcreate'}} > 0) {
10197: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10198: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10199: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10200: $chgtext .= '<br />'.
10201: '<span class="LC_warning">'.
10202: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10203: '</span>';
10204: }
1.96 raeburn 10205: } elsif (ref($usertypes) eq 'HASH') {
10206: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10207: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10208: } else {
10209: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10210: }
10211: $chgtext .= '<ul>';
10212: foreach my $case (@{$cancreate{$type}}) {
10213: if ($case eq 'default') {
10214: $chgtext .= '<li>'.$othertitle.'</li>';
10215: } else {
10216: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10217: }
10218: }
1.100 raeburn 10219: $chgtext .= '</ul>';
10220: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10221: $chgtext .= '<br /><span class="LC_warning">'.
10222: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10223: '</span>';
1.100 raeburn 10224: }
10225: }
10226: } else {
10227: if (@{$cancreate{$type}} == 0) {
10228: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10229: } else {
10230: $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 10231: }
10232: }
10233: }
1.160.6.40 raeburn 10234: } elsif ($type eq 'selfcreateprocessing') {
10235: my %choices = &Apache::lonlocal::texthash (
10236: automatic => 'Automatic approval',
10237: approval => 'Queued for approval',
10238: );
10239: if (@statuses > 1) {
10240: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10241: '<ul>';
10242: foreach my $type (@statuses) {
10243: if ($type eq 'default') {
10244: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10245: } else {
10246: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10247: }
10248: }
10249: $chgtext .= '</ul>';
10250: } else {
10251: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10252: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10253: }
1.160.6.5 raeburn 10254: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 10255: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 10256: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10257: } else {
10258: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 10259: if ($captchas{$savecaptcha{$type}}) {
10260: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 10261: } else {
10262: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
10263: }
10264: }
10265: } elsif ($type eq 'recaptchakeys') {
10266: my ($privkey,$pubkey);
1.160.6.34 raeburn 10267: if (ref($savecaptcha{$type}) eq 'HASH') {
10268: $pubkey = $savecaptcha{$type}{'public'};
10269: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 10270: }
10271: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10272: if (!$pubkey) {
10273: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10274: } else {
10275: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10276: }
10277: if (!$privkey) {
10278: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10279: } else {
10280: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10281: }
10282: $chgtext .= '</ul>';
1.160.6.69 raeburn 10283: } elsif ($type eq 'recaptchaversion') {
10284: if ($savecaptcha{'captcha'} eq 'recaptcha') {
10285: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
10286: }
1.160.6.34 raeburn 10287: } elsif ($type eq 'emailusername') {
10288: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 10289: if (ref($types) eq 'ARRAY') {
10290: foreach my $type (@{$types}) {
10291: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10292: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 10293: $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.160.6.35 raeburn 10294: '<ul>';
10295: foreach my $field (@{$infofields}) {
10296: if ($cancreate{'emailusername'}{$type}{$field}) {
10297: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10298: }
10299: }
1.160.6.50 raeburn 10300: $chgtext .= '</ul>';
10301: } else {
10302: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.160.6.35 raeburn 10303: }
10304: } else {
1.160.6.50 raeburn 10305: $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.160.6.34 raeburn 10306: }
10307: }
10308: }
10309: }
10310: } elsif ($type eq 'notify') {
10311: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10312: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10313: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10314: if ($cancreate{'notify'}{'approval'}) {
10315: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10316: }
10317: }
1.43 raeburn 10318: }
1.34 raeburn 10319: }
1.160.6.34 raeburn 10320: if ($chgtext) {
10321: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10322: }
10323: }
10324: }
1.43 raeburn 10325: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10326: my ($emailrules,$emailruleorder) =
10327: &Apache::lonnet::inst_userrules($dom,'email');
10328: my $chgtext = '<ul>';
10329: foreach my $type (@email_rule) {
10330: if (ref($emailrules->{$type}) eq 'HASH') {
10331: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10332: }
10333: }
10334: $chgtext .= '</ul>';
10335: if (@email_rule > 0) {
1.160.6.34 raeburn 10336: $resulttext .= '<li>'.
10337: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10338: $chgtext.
10339: '</li>';
1.43 raeburn 10340: } else {
1.160.6.34 raeburn 10341: $resulttext .= '<li>'.
10342: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10343: '</li>';
1.43 raeburn 10344: }
10345: }
1.160.6.34 raeburn 10346: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10347: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10348: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10349: foreach my $type (@{$changes{'selfcreate'}}) {
10350: my $typename = $type;
10351: if (ref($usertypes) eq 'HASH') {
10352: if ($usertypes->{$type} ne '') {
10353: $typename = $usertypes->{$type};
1.28 raeburn 10354: }
10355: }
1.160.6.34 raeburn 10356: my @modifiable;
10357: $resulttext .= '<li>'.
10358: &mt('Self-creation of account by users with status: [_1]',
10359: '<span class="LC_cusr_emph">'.$typename.'</span>').
10360: ' - '.&mt('modifiable fields (if institutional data blank): ');
10361: foreach my $field (@fields) {
10362: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10363: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
10364: }
10365: }
10366: if (@modifiable > 0) {
10367: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10368: } else {
1.160.6.34 raeburn 10369: $resulttext .= &mt('none');
1.43 raeburn 10370: }
1.160.6.34 raeburn 10371: $resulttext .= '</li>';
1.28 raeburn 10372: }
1.160.6.34 raeburn 10373: $resulttext .= '</ul></li>';
1.28 raeburn 10374: }
1.27 raeburn 10375: $resulttext .= '</ul>';
10376: } else {
1.160.6.34 raeburn 10377: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10378: }
10379: } else {
10380: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10381: &mt('An error occurred: [_1]',$putresult).'</span>';
10382: }
1.43 raeburn 10383: if ($warningmsg ne '') {
10384: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10385: }
1.23 raeburn 10386: return $resulttext;
10387: }
10388:
1.160.6.5 raeburn 10389: sub process_captcha {
10390: my ($container,$changes,$newsettings,$current) = @_;
10391: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10392: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10393: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10394: $newsettings->{'captcha'} = 'original';
10395: }
10396: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
10397: if ($container eq 'cancreate') {
10398: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10399: push(@{$changes->{'cancreate'}},'captcha');
10400: } elsif (!defined($changes->{'cancreate'})) {
10401: $changes->{'cancreate'} = ['captcha'];
10402: }
10403: } else {
10404: $changes->{'captcha'} = 1;
10405: }
10406: }
1.160.6.69 raeburn 10407: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 10408: if ($newsettings->{'captcha'} eq 'recaptcha') {
10409: $newpub = $env{'form.'.$container.'_recaptchapub'};
10410: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 10411: $newpub =~ s/[^\w\-]//g;
10412: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 10413: $newsettings->{'recaptchakeys'} = {
10414: public => $newpub,
10415: private => $newpriv,
10416: };
1.160.6.69 raeburn 10417: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10418: $newversion =~ s/\D//g;
10419: if ($newversion ne '2') {
10420: $newversion = 1;
10421: }
10422: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 10423: }
10424: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10425: $currpub = $current->{'recaptchakeys'}{'public'};
10426: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 10427: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10428: $newsettings->{'recaptchakeys'} = {
10429: public => '',
10430: private => '',
10431: }
10432: }
1.160.6.5 raeburn 10433: }
1.160.6.69 raeburn 10434: if ($current->{'captcha'} eq 'recaptcha') {
10435: $currversion = $current->{'recaptchaversion'};
10436: if ($currversion ne '2') {
10437: $currversion = 1;
10438: }
10439: }
10440: if ($currversion ne $newversion) {
10441: if ($container eq 'cancreate') {
10442: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10443: push(@{$changes->{'cancreate'}},'recaptchaversion');
10444: } elsif (!defined($changes->{'cancreate'})) {
10445: $changes->{'cancreate'} = ['recaptchaversion'];
10446: }
10447: } else {
10448: $changes->{'recaptchaversion'} = 1;
10449: }
10450: }
1.160.6.5 raeburn 10451: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
10452: if ($container eq 'cancreate') {
10453: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10454: push(@{$changes->{'cancreate'}},'recaptchakeys');
10455: } elsif (!defined($changes->{'cancreate'})) {
10456: $changes->{'cancreate'} = ['recaptchakeys'];
10457: }
10458: } else {
10459: $changes->{'recaptchakeys'} = 1;
10460: }
10461: }
10462: return;
10463: }
10464:
1.33 raeburn 10465: sub modify_usermodification {
10466: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 10467: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10468: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10469: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 10470: if ($key eq 'selfcreate') {
10471: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10472: } else {
10473: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10474: }
1.33 raeburn 10475: }
10476: }
1.160.6.34 raeburn 10477: my @contexts = ('author','course');
1.33 raeburn 10478: my %context_title = (
10479: author => 'In author context',
10480: course => 'In course context',
10481: );
10482: my @fields = ('lastname','firstname','middlename','generation',
10483: 'permanentemail','id');
10484: my %roles = (
10485: author => ['ca','aa'],
10486: course => ['st','ep','ta','in','cr'],
10487: );
10488: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10489: foreach my $context (@contexts) {
10490: foreach my $role (@{$roles{$context}}) {
10491: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10492: foreach my $item (@fields) {
10493: if (grep(/^\Q$item\E$/,@modifiable)) {
10494: $modifyhash{$context}{$role}{$item} = 1;
10495: } else {
10496: $modifyhash{$context}{$role}{$item} = 0;
10497: }
10498: }
10499: }
10500: if (ref($curr_usermodification{$context}) eq 'HASH') {
10501: foreach my $role (@{$roles{$context}}) {
10502: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10503: foreach my $field (@fields) {
10504: if ($modifyhash{$context}{$role}{$field} ne
10505: $curr_usermodification{$context}{$role}{$field}) {
10506: push(@{$changes{$context}},$role);
10507: last;
10508: }
10509: }
10510: }
10511: }
10512: } else {
10513: foreach my $context (@contexts) {
10514: foreach my $role (@{$roles{$context}}) {
10515: push(@{$changes{$context}},$role);
10516: }
10517: }
10518: }
10519: }
10520: my %usermodification_hash = (
10521: usermodification => \%modifyhash,
10522: );
10523: my $putresult = &Apache::lonnet::put_dom('configuration',
10524: \%usermodification_hash,$dom);
10525: if ($putresult eq 'ok') {
10526: if (keys(%changes) > 0) {
10527: $resulttext = &mt('Changes made: ').'<ul>';
10528: foreach my $context (@contexts) {
10529: if (ref($changes{$context}) eq 'ARRAY') {
10530: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10531: if (ref($changes{$context}) eq 'ARRAY') {
10532: foreach my $role (@{$changes{$context}}) {
10533: my $rolename;
1.160.6.34 raeburn 10534: if ($role eq 'cr') {
10535: $rolename = &mt('Custom');
1.33 raeburn 10536: } else {
1.160.6.34 raeburn 10537: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10538: }
10539: my @modifiable;
1.160.6.34 raeburn 10540: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10541: foreach my $field (@fields) {
10542: if ($modifyhash{$context}{$role}{$field}) {
10543: push(@modifiable,$fieldtitles{$field});
10544: }
10545: }
10546: if (@modifiable > 0) {
10547: $resulttext .= join(', ',@modifiable);
10548: } else {
10549: $resulttext .= &mt('none');
10550: }
10551: $resulttext .= '</li>';
10552: }
10553: $resulttext .= '</ul></li>';
10554: }
10555: }
10556: }
10557: $resulttext .= '</ul>';
10558: } else {
10559: $resulttext = &mt('No changes made to user modification settings');
10560: }
10561: } else {
10562: $resulttext = '<span class="LC_error">'.
10563: &mt('An error occurred: [_1]',$putresult).'</span>';
10564: }
10565: return $resulttext;
10566: }
10567:
1.43 raeburn 10568: sub modify_defaults {
1.160.6.27 raeburn 10569: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10570: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 10571: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 10572: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
10573: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 10574: my @authtypes = ('internal','krb4','krb5','localauth');
10575: foreach my $item (@items) {
10576: $newvalues{$item} = $env{'form.'.$item};
10577: if ($item eq 'auth_def') {
10578: if ($newvalues{$item} ne '') {
10579: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10580: push(@errors,$item);
10581: }
10582: }
10583: } elsif ($item eq 'lang_def') {
10584: if ($newvalues{$item} ne '') {
10585: if ($newvalues{$item} =~ /^(\w+)/) {
10586: my $langcode = $1;
1.103 raeburn 10587: if ($langcode ne 'x_chef') {
10588: if (code2language($langcode) eq '') {
10589: push(@errors,$item);
10590: }
1.43 raeburn 10591: }
10592: } else {
10593: push(@errors,$item);
10594: }
10595: }
1.54 raeburn 10596: } elsif ($item eq 'timezone_def') {
10597: if ($newvalues{$item} ne '') {
1.62 raeburn 10598: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10599: push(@errors,$item);
10600: }
10601: }
1.68 raeburn 10602: } elsif ($item eq 'datelocale_def') {
10603: if ($newvalues{$item} ne '') {
10604: my @datelocale_ids = DateTime::Locale->ids();
10605: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10606: push(@errors,$item);
10607: }
10608: }
1.141 raeburn 10609: } elsif ($item eq 'portal_def') {
10610: if ($newvalues{$item} ne '') {
10611: 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])\/?$/) {
10612: push(@errors,$item);
10613: }
10614: }
1.160.6.80 raeburn 10615: } elsif ($item eq 'intauth_cost') {
10616: if ($newvalues{$item} ne '') {
10617: if ($newvalues{$item} =~ /\D/) {
10618: push(@errors,$item);
10619: }
10620: }
10621: } elsif ($item eq 'intauth_check') {
10622: if ($newvalues{$item} ne '') {
10623: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
10624: push(@errors,$item);
10625: }
10626: }
10627: } elsif ($item eq 'intauth_switch') {
10628: if ($newvalues{$item} ne '') {
10629: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
10630: push(@errors,$item);
10631: }
10632: }
1.43 raeburn 10633: }
10634: if (grep(/^\Q$item\E$/,@errors)) {
10635: $newvalues{$item} = $domdefaults{$item};
10636: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10637: $changes{$item} = 1;
10638: }
1.72 raeburn 10639: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10640: }
10641: my %defaults_hash = (
1.72 raeburn 10642: defaults => \%newvalues,
10643: );
1.43 raeburn 10644: my $title = &defaults_titles();
1.160.6.40 raeburn 10645:
10646: my $currinststatus;
10647: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10648: $currinststatus = $domconfig{'inststatus'};
10649: } else {
10650: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10651: $currinststatus = {
10652: inststatustypes => $usertypes,
10653: inststatusorder => $types,
10654: inststatusguest => [],
10655: };
10656: }
10657: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10658: my @allpos;
10659: my %guests;
10660: my %alltypes;
10661: my ($currtitles,$currguests,$currorder);
10662: if (ref($currinststatus) eq 'HASH') {
10663: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10664: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10665: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10666: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10667: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10668: }
10669: }
10670: unless (grep(/^\Q$type\E$/,@todelete)) {
10671: my $position = $env{'form.inststatus_pos_'.$type};
10672: $position =~ s/\D+//g;
10673: $allpos[$position] = $type;
10674: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
10675: $alltypes{$type} =~ s/`//g;
10676: if ($env{'form.inststatus_guest_'.$type}) {
10677: $guests{$type} = 1;
10678: }
10679: }
10680: }
10681: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
10682: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
10683: }
10684: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
10685: $currtitles =~ s/,$//;
10686: }
10687: }
10688: if ($env{'form.addinststatus'}) {
10689: my $newtype = $env{'form.addinststatus'};
10690: $newtype =~ s/\W//g;
10691: unless (exists($alltypes{$newtype})) {
10692: if ($env{'form.addinststatus_guest'}) {
10693: $guests{$newtype} = 1;
10694: }
10695: $alltypes{$newtype} = $env{'form.addinststatus_title'};
10696: $alltypes{$newtype} =~ s/`//g;
10697: my $position = $env{'form.addinststatus_pos'};
10698: $position =~ s/\D+//g;
10699: if ($position ne '') {
10700: $allpos[$position] = $newtype;
10701: }
10702: }
10703: }
10704: my (@orderedstatus,@orderedguests);
10705: foreach my $type (@allpos) {
10706: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
10707: push(@orderedstatus,$type);
10708: if ($guests{$type}) {
10709: push(@orderedguests,$type);
10710: }
10711: }
10712: }
10713: foreach my $type (keys(%alltypes)) {
10714: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
10715: delete($alltypes{$type});
10716: }
10717: }
10718: $defaults_hash{'inststatus'} = {
10719: inststatustypes => \%alltypes,
10720: inststatusorder => \@orderedstatus,
10721: inststatusguest => \@orderedguests,
10722: };
10723: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
10724: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
10725: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
10726: }
10727: }
10728: if ($currorder ne join(',',@orderedstatus)) {
10729: $changes{'inststatus'}{'inststatusorder'} = 1;
10730: }
10731: if ($currguests ne join(',',@orderedguests)) {
10732: $changes{'inststatus'}{'inststatusguest'} = 1;
10733: }
10734: my $newtitles;
10735: foreach my $item (@orderedstatus) {
10736: $newtitles .= $alltypes{$item}.',';
10737: }
10738: $newtitles =~ s/,$//;
10739: if ($currtitles ne $newtitles) {
10740: $changes{'inststatus'}{'inststatustypes'} = 1;
10741: }
1.43 raeburn 10742: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
10743: $dom);
10744: if ($putresult eq 'ok') {
10745: if (keys(%changes) > 0) {
10746: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 10747: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 10748: 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";
10749: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 10750: if ($item eq 'inststatus') {
10751: if (ref($changes{'inststatus'}) eq 'HASH') {
10752: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
10753: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
10754: foreach my $type (@orderedstatus) {
10755: $resulttext .= $alltypes{$type}.', ';
10756: }
10757: $resulttext =~ s/, $//;
10758: $resulttext .= '</li>';
10759: }
10760: if ($changes{'inststatus'}{'inststatusguest'}) {
10761: $resulttext .= '<li>';
10762: if (@orderedguests) {
10763: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
10764: foreach my $type (@orderedguests) {
10765: $resulttext .= $alltypes{$type}.', ';
10766: }
10767: $resulttext =~ s/, $//;
10768: } else {
10769: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
10770: }
10771: $resulttext .= '</li>';
10772: }
10773: }
10774: } else {
10775: my $value = $env{'form.'.$item};
10776: if ($value eq '') {
10777: $value = &mt('none');
10778: } elsif ($item eq 'auth_def') {
10779: my %authnames = &authtype_names();
10780: my %shortauth = (
10781: internal => 'int',
10782: krb4 => 'krb4',
10783: krb5 => 'krb5',
10784: localauth => 'loc',
10785: );
10786: $value = $authnames{$shortauth{$value}};
1.160.6.80 raeburn 10787: } elsif ($item eq 'intauth_switch') {
10788: my %optiondesc = &Apache::lonlocal::texthash (
10789: 0 => 'No',
10790: 1 => 'Yes',
10791: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
10792: );
10793: if ($value =~ /^(0|1|2)$/) {
10794: $value = $optiondesc{$value};
10795: } else {
10796: $value = &mt('none -- defaults to No');
10797: }
10798: } elsif ($item eq 'intauth_check') {
10799: my %optiondesc = &Apache::lonlocal::texthash (
10800: 0 => 'No',
10801: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
10802: 2 => 'Yes, disallow login if stored cost is less than domain default',
10803: );
10804: if ($value =~ /^(0|1|2)$/) {
10805: $value = $optiondesc{$value};
10806: } else {
10807: $value = &mt('none -- defaults to No');
10808: }
1.160.6.40 raeburn 10809: }
10810: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
10811: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 10812: }
10813: }
10814: $resulttext .= '</ul>';
10815: $mailmsgtext .= "\n";
10816: my $cachetime = 24*60*60;
1.72 raeburn 10817: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10818: if (ref($lastactref) eq 'HASH') {
10819: $lastactref->{'domdefaults'} = 1;
10820: }
1.68 raeburn 10821: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 10822: my $notify = 1;
10823: if (ref($domconfig{'contacts'}) eq 'HASH') {
10824: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
10825: $notify = 0;
10826: }
10827: }
10828: if ($notify) {
10829: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
10830: "LON-CAPA Domain Settings Change - $dom",
10831: $mailmsgtext);
10832: }
1.54 raeburn 10833: }
1.43 raeburn 10834: } else {
1.54 raeburn 10835: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 10836: }
10837: } else {
10838: $resulttext = '<span class="LC_error">'.
10839: &mt('An error occurred: [_1]',$putresult).'</span>';
10840: }
10841: if (@errors > 0) {
10842: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
10843: foreach my $item (@errors) {
10844: $resulttext .= ' "'.$title->{$item}.'",';
10845: }
10846: $resulttext =~ s/,$//;
10847: }
10848: return $resulttext;
10849: }
10850:
1.46 raeburn 10851: sub modify_scantron {
1.160.6.24 raeburn 10852: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 10853: my ($resulttext,%confhash,%changes,$errors);
10854: my $custom = 'custom.tab';
10855: my $default = 'default.tab';
10856: my $servadm = $r->dir_config('lonAdmEMail');
10857: my ($configuserok,$author_ok,$switchserver) =
10858: &config_check($dom,$confname,$servadm);
10859: if ($env{'form.scantronformat.filename'} ne '') {
10860: my $error;
10861: if ($configuserok eq 'ok') {
10862: if ($switchserver) {
1.130 raeburn 10863: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 10864: } else {
10865: if ($author_ok eq 'ok') {
10866: my ($result,$scantronurl) =
10867: &publishlogo($r,'upload','scantronformat',$dom,
10868: $confname,'scantron','','',$custom);
10869: if ($result eq 'ok') {
10870: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 10871: $changes{'scantronformat'} = 1;
1.46 raeburn 10872: } else {
10873: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
10874: }
10875: } else {
10876: $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);
10877: }
10878: }
10879: } else {
10880: $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);
10881: }
10882: if ($error) {
10883: &Apache::lonnet::logthis($error);
10884: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10885: }
10886: }
1.48 raeburn 10887: if (ref($domconfig{'scantron'}) eq 'HASH') {
10888: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
10889: if ($env{'form.scantronformat_del'}) {
10890: $confhash{'scantron'}{'scantronformat'} = '';
10891: $changes{'scantronformat'} = 1;
1.46 raeburn 10892: }
10893: }
10894: }
10895: if (keys(%confhash) > 0) {
10896: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10897: $dom);
10898: if ($putresult eq 'ok') {
10899: if (keys(%changes) > 0) {
1.48 raeburn 10900: if (ref($confhash{'scantron'}) eq 'HASH') {
10901: $resulttext = &mt('Changes made:').'<ul>';
10902: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 10903: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 10904: } else {
1.130 raeburn 10905: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 10906: }
1.48 raeburn 10907: $resulttext .= '</ul>';
10908: } else {
1.130 raeburn 10909: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 10910: }
10911: $resulttext .= '</ul>';
10912: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10913: if (ref($lastactref) eq 'HASH') {
10914: $lastactref->{'domainconfig'} = 1;
10915: }
1.46 raeburn 10916: } else {
1.130 raeburn 10917: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10918: }
10919: } else {
10920: $resulttext = '<span class="LC_error">'.
10921: &mt('An error occurred: [_1]',$putresult).'</span>';
10922: }
10923: } else {
1.130 raeburn 10924: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10925: }
10926: if ($errors) {
10927: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10928: $errors.'</ul>';
10929: }
10930: return $resulttext;
10931: }
10932:
1.48 raeburn 10933: sub modify_coursecategories {
1.160.6.43 raeburn 10934: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 10935: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10936: $cathash);
1.48 raeburn 10937: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 10938: my @catitems = ('unauth','auth');
10939: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 10940: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 10941: $cathash = $domconfig{'coursecategories'}{'cats'};
10942: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10943: $changes{'togglecats'} = 1;
10944: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10945: }
10946: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10947: $changes{'categorize'} = 1;
10948: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
10949: }
1.120 raeburn 10950: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
10951: $changes{'togglecatscomm'} = 1;
10952: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
10953: }
10954: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
10955: $changes{'categorizecomm'} = 1;
10956: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
10957: }
1.160.6.42 raeburn 10958: foreach my $item (@catitems) {
10959: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10960: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
10961: $changes{$item} = 1;
10962: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10963: }
10964: }
10965: }
1.57 raeburn 10966: } else {
10967: $changes{'togglecats'} = 1;
10968: $changes{'categorize'} = 1;
1.124 raeburn 10969: $changes{'togglecatscomm'} = 1;
10970: $changes{'categorizecomm'} = 1;
1.87 raeburn 10971: $domconfig{'coursecategories'} = {
10972: togglecats => $env{'form.togglecats'},
10973: categorize => $env{'form.categorize'},
1.124 raeburn 10974: togglecatscomm => $env{'form.togglecatscomm'},
10975: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 10976: };
1.160.6.42 raeburn 10977: foreach my $item (@catitems) {
10978: if ($env{'form.coursecat_'.$item} ne 'std') {
10979: $changes{$item} = 1;
10980: }
10981: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10982: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10983: }
10984: }
1.57 raeburn 10985: }
10986: if (ref($cathash) eq 'HASH') {
10987: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 10988: push (@deletecategory,'instcode::0');
10989: }
1.120 raeburn 10990: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
10991: push(@deletecategory,'communities::0');
10992: }
1.48 raeburn 10993: }
1.57 raeburn 10994: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
10995: if (ref($cathash) eq 'HASH') {
1.48 raeburn 10996: if (@deletecategory > 0) {
10997: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 10998: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 10999: foreach my $item (@deletecategory) {
1.57 raeburn 11000: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11001: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11002: $deletions{$item} = 1;
1.57 raeburn 11003: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11004: }
11005: }
11006: }
1.57 raeburn 11007: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11008: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11009: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11010: $reorderings{$item} = 1;
1.57 raeburn 11011: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11012: }
11013: if ($env{'form.addcategory_name_'.$item} ne '') {
11014: my $newcat = $env{'form.addcategory_name_'.$item};
11015: my $newdepth = $depth+1;
11016: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11017: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11018: $adds{$newitem} = 1;
11019: }
11020: if ($env{'form.subcat_'.$item} ne '') {
11021: my $newcat = $env{'form.subcat_'.$item};
11022: my $newdepth = $depth+1;
11023: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11024: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11025: $adds{$newitem} = 1;
11026: }
11027: }
11028: }
11029: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11030: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11031: my $newitem = 'instcode::0';
1.57 raeburn 11032: if ($cathash->{$newitem} eq '') {
11033: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11034: $adds{$newitem} = 1;
11035: }
11036: } else {
11037: my $newitem = 'instcode::0';
1.57 raeburn 11038: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11039: $adds{$newitem} = 1;
11040: }
11041: }
1.120 raeburn 11042: if ($env{'form.communities'} eq '1') {
11043: if (ref($cathash) eq 'HASH') {
11044: my $newitem = 'communities::0';
11045: if ($cathash->{$newitem} eq '') {
11046: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11047: $adds{$newitem} = 1;
11048: }
11049: } else {
11050: my $newitem = 'communities::0';
11051: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11052: $adds{$newitem} = 1;
11053: }
11054: }
1.48 raeburn 11055: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11056: if (($env{'form.addcategory_name'} ne 'instcode') &&
11057: ($env{'form.addcategory_name'} ne 'communities')) {
11058: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11059: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11060: $adds{$newitem} = 1;
11061: }
1.48 raeburn 11062: }
1.57 raeburn 11063: my $putresult;
1.48 raeburn 11064: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11065: if (keys(%deletions) > 0) {
11066: foreach my $key (keys(%deletions)) {
11067: if ($predelallitems{$key} ne '') {
11068: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11069: }
11070: }
11071: }
11072: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11073: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11074: if (ref($chkcats[0]) eq 'ARRAY') {
11075: my $depth = 0;
11076: my $chg = 0;
11077: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11078: my $name = $chkcats[0][$i];
11079: my $item;
11080: if ($name eq '') {
11081: $chg ++;
11082: } else {
11083: $item = &escape($name).'::0';
11084: if ($chg) {
1.57 raeburn 11085: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11086: }
11087: $depth ++;
1.57 raeburn 11088: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11089: $depth --;
11090: }
11091: }
11092: }
1.57 raeburn 11093: }
11094: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11095: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11096: if ($putresult eq 'ok') {
1.57 raeburn 11097: my %title = (
1.120 raeburn 11098: togglecats => 'Show/Hide a course in catalog',
11099: categorize => 'Assign a category to a course',
11100: togglecatscomm => 'Show/Hide a community in catalog',
11101: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11102: );
11103: my %level = (
1.120 raeburn 11104: dom => 'set in Domain ("Modify Course/Community")',
11105: crs => 'set in Course ("Course Configuration")',
11106: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 11107: none => 'No catalog',
11108: std => 'Standard catalog',
11109: domonly => 'Domain-only catalog',
11110: codesrch => 'Code search form',
1.57 raeburn 11111: );
1.48 raeburn 11112: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11113: if ($changes{'togglecats'}) {
11114: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11115: }
11116: if ($changes{'categorize'}) {
11117: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11118: }
1.120 raeburn 11119: if ($changes{'togglecatscomm'}) {
11120: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11121: }
11122: if ($changes{'categorizecomm'}) {
11123: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11124: }
1.160.6.42 raeburn 11125: if ($changes{'unauth'}) {
11126: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11127: }
11128: if ($changes{'auth'}) {
11129: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11130: }
1.57 raeburn 11131: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11132: my $cathash;
11133: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11134: $cathash = $domconfig{'coursecategories'}{'cats'};
11135: } else {
11136: $cathash = {};
11137: }
11138: my (@cats,@trails,%allitems);
11139: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11140: if (keys(%deletions) > 0) {
11141: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11142: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11143: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11144: }
11145: $resulttext .= '</ul></li>';
11146: }
11147: if (keys(%reorderings) > 0) {
11148: my %sort_by_trail;
11149: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11150: foreach my $key (keys(%reorderings)) {
11151: if ($allitems{$key} ne '') {
11152: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11153: }
1.48 raeburn 11154: }
1.57 raeburn 11155: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11156: $resulttext .= '<li>'.$trails[$trail].'</li>';
11157: }
11158: $resulttext .= '</ul></li>';
1.48 raeburn 11159: }
1.57 raeburn 11160: if (keys(%adds) > 0) {
11161: my %sort_by_trail;
11162: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11163: foreach my $key (keys(%adds)) {
11164: if ($allitems{$key} ne '') {
11165: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11166: }
11167: }
11168: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11169: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11170: }
1.57 raeburn 11171: $resulttext .= '</ul></li>';
1.48 raeburn 11172: }
11173: }
11174: $resulttext .= '</ul>';
1.160.6.43 raeburn 11175: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 11176: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11177: if ($changes{'auth'}) {
11178: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11179: }
11180: if ($changes{'unauth'}) {
11181: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11182: }
11183: my $cachetime = 24*60*60;
11184: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 11185: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 11186: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 11187: }
11188: }
1.48 raeburn 11189: } else {
11190: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11191: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11192: }
11193: } else {
1.120 raeburn 11194: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11195: }
11196: return $resulttext;
11197: }
11198:
1.69 raeburn 11199: sub modify_serverstatuses {
11200: my ($dom,%domconfig) = @_;
11201: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11202: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11203: %currserverstatus = %{$domconfig{'serverstatuses'}};
11204: }
11205: my @pages = &serverstatus_pages();
11206: foreach my $type (@pages) {
11207: $newserverstatus{$type}{'namedusers'} = '';
11208: $newserverstatus{$type}{'machines'} = '';
11209: if (defined($env{'form.'.$type.'_namedusers'})) {
11210: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11211: my @okusers;
11212: foreach my $user (@users) {
11213: my ($uname,$udom) = split(/:/,$user);
11214: if (($udom =~ /^$match_domain$/) &&
11215: (&Apache::lonnet::domain($udom)) &&
11216: ($uname =~ /^$match_username$/)) {
11217: if (!grep(/^\Q$user\E/,@okusers)) {
11218: push(@okusers,$user);
11219: }
11220: }
11221: }
11222: if (@okusers > 0) {
11223: @okusers = sort(@okusers);
11224: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11225: }
11226: }
11227: if (defined($env{'form.'.$type.'_machines'})) {
11228: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11229: my @okmachines;
11230: foreach my $ip (@machines) {
11231: my @parts = split(/\./,$ip);
11232: next if (@parts < 4);
11233: my $badip = 0;
11234: for (my $i=0; $i<4; $i++) {
11235: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11236: $badip = 1;
11237: last;
11238: }
11239: }
11240: if (!$badip) {
11241: push(@okmachines,$ip);
11242: }
11243: }
11244: @okmachines = sort(@okmachines);
11245: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11246: }
11247: }
11248: my %serverstatushash = (
11249: serverstatuses => \%newserverstatus,
11250: );
11251: foreach my $type (@pages) {
1.83 raeburn 11252: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11253: my (@current,@new);
1.83 raeburn 11254: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11255: if ($currserverstatus{$type}{$setting} ne '') {
11256: @current = split(/,/,$currserverstatus{$type}{$setting});
11257: }
11258: }
11259: if ($newserverstatus{$type}{$setting} ne '') {
11260: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11261: }
11262: if (@current > 0) {
11263: if (@new > 0) {
11264: foreach my $item (@current) {
11265: if (!grep(/^\Q$item\E$/,@new)) {
11266: $changes{$type}{$setting} = 1;
1.82 raeburn 11267: last;
11268: }
11269: }
1.84 raeburn 11270: foreach my $item (@new) {
11271: if (!grep(/^\Q$item\E$/,@current)) {
11272: $changes{$type}{$setting} = 1;
11273: last;
1.82 raeburn 11274: }
11275: }
11276: } else {
1.83 raeburn 11277: $changes{$type}{$setting} = 1;
1.69 raeburn 11278: }
1.83 raeburn 11279: } elsif (@new > 0) {
11280: $changes{$type}{$setting} = 1;
1.69 raeburn 11281: }
11282: }
11283: }
11284: if (keys(%changes) > 0) {
1.81 raeburn 11285: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11286: my $putresult = &Apache::lonnet::put_dom('configuration',
11287: \%serverstatushash,$dom);
11288: if ($putresult eq 'ok') {
11289: $resulttext .= &mt('Changes made:').'<ul>';
11290: foreach my $type (@pages) {
1.84 raeburn 11291: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11292: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11293: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11294: if ($newserverstatus{$type}{'namedusers'} eq '') {
11295: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11296: } else {
11297: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11298: }
1.84 raeburn 11299: }
11300: if ($changes{$type}{'machines'}) {
1.69 raeburn 11301: if ($newserverstatus{$type}{'machines'} eq '') {
11302: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11303: } else {
11304: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11305: }
11306:
11307: }
11308: $resulttext .= '</ul></li>';
11309: }
11310: }
11311: $resulttext .= '</ul>';
11312: } else {
11313: $resulttext = '<span class="LC_error">'.
11314: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11315:
11316: }
11317: } else {
11318: $resulttext = &mt('No changes made to access to server status pages');
11319: }
11320: return $resulttext;
11321: }
11322:
1.118 jms 11323: sub modify_helpsettings {
1.160.6.77 raeburn 11324: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 11325: my ($resulttext,$errors,%changes,%helphash);
11326: my %defaultchecked = ('submitbugs' => 'on');
11327: my @offon = ('off','on');
1.118 jms 11328: my @toggles = ('submitbugs');
1.160.6.77 raeburn 11329: my %current = ('submitbugs' => '',
11330: 'adhoc' => {},
11331: );
1.118 jms 11332: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 11333: %current = %{$domconfig{'helpsettings'}};
11334: }
1.160.6.77 raeburn 11335: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 11336: foreach my $item (@toggles) {
11337: if ($defaultchecked{$item} eq 'on') {
11338: if ($current{$item} eq '') {
11339: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 11340: $changes{$item} = 1;
11341: }
1.160.6.73 raeburn 11342: } elsif ($current{$item} ne $env{'form.'.$item}) {
11343: $changes{$item} = 1;
11344: }
11345: } elsif ($defaultchecked{$item} eq 'off') {
11346: if ($current{$item} eq '') {
11347: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 11348: $changes{$item} = 1;
11349: }
1.160.6.73 raeburn 11350: } elsif ($current{$item} ne $env{'form.'.$item}) {
11351: $changes{$item} = 1;
11352: }
11353: }
11354: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
11355: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11356: }
11357: }
1.160.6.77 raeburn 11358: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 11359: my $confname = $dom.'-domainconfig';
11360: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 11361: my (@allpos,%newsettings,%changedprivs,$newrole);
11362: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 11363: my @accesstypes = ('all','dh','da','none','status','inc','exc');
11364: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 11365: my %lt = &Apache::lonlocal::texthash(
11366: s => 'system',
11367: d => 'domain',
11368: order => 'Display order',
11369: access => 'Role usage',
1.160.6.79 raeburn 11370: all => 'All with domain helpdesk or helpdesk assistant role',
11371: dh => 'All with domain helpdesk role',
11372: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 11373: none => 'None',
11374: status => 'Determined based on institutional status',
11375: inc => 'Include all, but exclude specific personnel',
11376: exc => 'Exclude all, but include specific personnel',
11377: );
11378: for (my $num=0; $num<=$maxnum; $num++) {
11379: my ($prefix,$identifier,$rolename,%curr);
11380: if ($num == $maxnum) {
11381: next unless ($env{'form.newcusthelp'} == $maxnum);
11382: $identifier = 'custhelp'.$num;
11383: $prefix = 'helproles_'.$num;
11384: $rolename = $env{'form.custhelpname'.$num};
11385: $rolename=~s/[^A-Za-z0-9]//gs;
11386: next if ($rolename eq '');
11387: next if (exists($existing{'rolesdef_'.$rolename}));
11388: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11389: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11390: $newprivs{'c'},$confname,$dom);
11391: if ($result ne 'ok') {
11392: $errors .= '<li><span class="LC_error">'.
11393: &mt('An error occurred storing the new custom role: [_1]',
11394: $result).'</span></li>';
11395: next;
11396: } else {
11397: $changedprivs{$rolename} = \%newprivs;
11398: $newrole = $rolename;
11399: }
11400: } else {
11401: $prefix = 'helproles_'.$num;
11402: $rolename = $env{'form.'.$prefix};
11403: next if ($rolename eq '');
11404: next unless (exists($existing{'rolesdef_'.$rolename}));
11405: $identifier = 'custhelp'.$num;
11406: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11407: my %currprivs;
11408: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
11409: split(/\_/,$existing{'rolesdef_'.$rolename});
11410: foreach my $level ('c','d','s') {
11411: if ($newprivs{$level} ne $currprivs{$level}) {
11412: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11413: $newprivs{'c'},$confname,$dom);
11414: if ($result ne 'ok') {
11415: $errors .= '<li><span class="LC_error">'.
11416: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
11417: $rolename,$result).'</span></li>';
11418: } else {
11419: $changedprivs{$rolename} = \%newprivs;
11420: }
11421: last;
11422: }
11423: }
11424: if (ref($current{'adhoc'}) eq 'HASH') {
11425: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11426: %curr = %{$current{'adhoc'}{$rolename}};
11427: }
11428: }
11429: }
11430: my $newpos = $env{'form.'.$prefix.'_pos'};
11431: $newpos =~ s/\D+//g;
11432: $allpos[$newpos] = $rolename;
11433: my $newdesc = $env{'form.'.$prefix.'_desc'};
11434: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
11435: if ($curr{'desc'}) {
11436: if ($curr{'desc'} ne $newdesc) {
11437: $changes{'customrole'}{$rolename}{'desc'} = 1;
11438: $newsettings{$rolename}{'desc'} = $newdesc;
11439: }
11440: } elsif ($newdesc ne '') {
11441: $changes{'customrole'}{$rolename}{'desc'} = 1;
11442: $newsettings{$rolename}{'desc'} = $newdesc;
11443: }
11444: my $access = $env{'form.'.$prefix.'_access'};
11445: if (grep(/^\Q$access\E$/,@accesstypes)) {
11446: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
11447: if ($access eq 'status') {
11448: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
11449: if (scalar(@statuses) == 0) {
11450: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
11451: } else {
11452: my (@shownstatus,$numtypes);
11453: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11454: if (ref($types) eq 'ARRAY') {
11455: $numtypes = scalar(@{$types});
11456: foreach my $type (sort(@statuses)) {
11457: if ($type eq 'default') {
11458: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11459: } elsif (grep(/^\Q$type\E$/,@{$types})) {
11460: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11461: push(@shownstatus,$usertypes->{$type});
11462: }
1.160.6.73 raeburn 11463: }
11464: }
1.160.6.77 raeburn 11465: if (grep(/^default$/,@statuses)) {
11466: push(@shownstatus,$othertitle);
11467: }
11468: if (scalar(@shownstatus) == 1+$numtypes) {
11469: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
11470: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
11471: } else {
11472: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
11473: if (ref($curr{'status'}) eq 'ARRAY') {
11474: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11475: if (@diffs) {
11476: $changes{'customrole'}{$rolename}{$access} = 1;
11477: }
11478: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11479: $changes{'customrole'}{$rolename}{$access} = 1;
11480: }
11481: }
11482: }
11483: } elsif (($access eq 'inc') || ($access eq 'exc')) {
11484: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
11485: my @newspecstaff;
11486: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11487: foreach my $person (sort(@personnel)) {
11488: if ($domhelpdesk{$person}) {
11489: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
11490: }
11491: }
11492: if (ref($curr{$access}) eq 'ARRAY') {
11493: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11494: if (@diffs) {
11495: $changes{'customrole'}{$rolename}{$access} = 1;
11496: }
11497: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11498: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 11499: }
1.160.6.77 raeburn 11500: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11501: my ($uname,$udom) = split(/:/,$person);
11502: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
11503: }
11504: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 11505: }
1.160.6.77 raeburn 11506: } else {
11507: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
11508: }
11509: unless ($curr{'access'} eq $access) {
11510: $changes{'customrole'}{$rolename}{'access'} = 1;
11511: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 11512: }
11513: }
1.160.6.77 raeburn 11514: if (@allpos > 0) {
11515: my $idx = 0;
11516: foreach my $rolename (@allpos) {
11517: if ($rolename ne '') {
11518: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
11519: if (ref($current{'adhoc'}) eq 'HASH') {
11520: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11521: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
11522: $changes{'customrole'}{$rolename}{'order'} = 1;
11523: $newsettings{$rolename}{'order'} = $idx+1;
11524: }
11525: }
1.160.6.73 raeburn 11526: }
1.160.6.77 raeburn 11527: $idx ++;
1.122 jms 11528: }
11529: }
1.118 jms 11530: }
1.123 jms 11531: my $putresult;
11532: if (keys(%changes) > 0) {
1.160.6.5 raeburn 11533: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
11534: if ($putresult eq 'ok') {
1.160.6.77 raeburn 11535: if (ref($helphash{'helpsettings'}) eq 'HASH') {
11536: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
11537: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
11538: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
11539: }
11540: }
11541: my $cachetime = 24*60*60;
11542: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11543: if (ref($lastactref) eq 'HASH') {
11544: $lastactref->{'domdefaults'} = 1;
11545: }
11546: } else {
11547: $errors .= '<li><span class="LC_error">'.
11548: &mt('An error occurred storing the settings: [_1]',
11549: $putresult).'</span></li>';
11550: }
11551: }
11552: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
11553: $resulttext = &mt('Changes made:').'<ul>';
11554: my (%shownprivs,@levelorder);
11555: @levelorder = ('c','d','s');
11556: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 11557: foreach my $item (sort(keys(%changes))) {
11558: if ($item eq 'submitbugs') {
11559: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11560: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11561: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 11562: } elsif ($item eq 'customrole') {
11563: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 11564: my @keyorder = ('order','desc','access','status','exc','inc');
11565: my %keytext = &Apache::lonlocal::texthash(
11566: order => 'Order',
11567: desc => 'Role description',
11568: access => 'Role usage',
1.160.6.83 raeburn 11569: status => 'Allowed institutional types',
1.160.6.77 raeburn 11570: exc => 'Allowed personnel',
11571: inc => 'Disallowed personnel',
11572: );
1.160.6.73 raeburn 11573: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 11574: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
11575: if ($role eq $newrole) {
11576: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
11577: $role).'<ul>';
11578: } else {
11579: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11580: $role).'<ul>';
11581: }
11582: foreach my $key (@keyorder) {
11583: if ($changes{'customrole'}{$role}{$key}) {
11584: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
11585: $keytext{$key},$newsettings{$role}{$key}).
11586: '</li>';
11587: }
11588: }
11589: if (ref($changedprivs{$role}) eq 'HASH') {
11590: $shownprivs{$role} = 1;
11591: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
11592: foreach my $level (@levelorder) {
11593: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11594: next if ($item eq '');
11595: my ($priv) = split(/\&/,$item,2);
11596: if (&Apache::lonnet::plaintext($priv)) {
11597: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11598: unless ($level eq 'c') {
11599: $resulttext .= ' ('.$lt{$level}.')';
11600: }
11601: $resulttext .= '</li>';
11602: }
11603: }
11604: }
11605: $resulttext .= '</ul>';
11606: }
11607: $resulttext .= '</ul></li>';
11608: }
1.160.6.73 raeburn 11609: }
11610: }
1.160.6.5 raeburn 11611: }
11612: }
11613: }
1.160.6.77 raeburn 11614: if (keys(%changedprivs)) {
11615: foreach my $role (sort(keys(%changedprivs))) {
11616: unless ($shownprivs{$role}) {
11617: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11618: $role).'<ul>'.
11619: '<li>'.&mt('Privileges set to :').'<ul>';
11620: foreach my $level (@levelorder) {
11621: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11622: next if ($item eq '');
11623: my ($priv) = split(/\&/,$item,2);
11624: if (&Apache::lonnet::plaintext($priv)) {
11625: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11626: unless ($level eq 'c') {
11627: $resulttext .= ' ('.$lt{$level}.')';
11628: }
11629: $resulttext .= '</li>';
11630: }
11631: }
11632: }
11633: $resulttext .= '</ul></li></ul></li>';
11634: }
11635: }
11636: }
11637: $resulttext .= '</ul>';
11638: } else {
11639: $resulttext = &mt('No changes made to help settings');
1.118 jms 11640: }
11641: if ($errors) {
1.160.6.5 raeburn 11642: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 11643: $errors.'</ul>';
1.118 jms 11644: }
11645: return $resulttext;
11646: }
11647:
1.121 raeburn 11648: sub modify_coursedefaults {
1.160.6.27 raeburn 11649: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11650: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 11651: my %defaultchecked = (
11652: 'uselcmath' => 'on',
11653: 'usejsme' => 'on'
11654: );
11655: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 11656: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 11657: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
11658: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 11659: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 11660: my %staticdefaults = (
11661: anonsurvey_threshold => 10,
11662: uploadquota => 500,
1.160.6.57 raeburn 11663: postsubmit => 60,
1.160.6.70 raeburn 11664: mysqltables => 172800,
1.160.6.21 raeburn 11665: );
1.121 raeburn 11666:
11667: $defaultshash{'coursedefaults'} = {};
11668:
11669: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11670: if ($domconfig{'coursedefaults'} eq '') {
11671: $domconfig{'coursedefaults'} = {};
11672: }
11673: }
11674:
11675: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11676: foreach my $item (@toggles) {
11677: if ($defaultchecked{$item} eq 'on') {
11678: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11679: ($env{'form.'.$item} eq '0')) {
11680: $changes{$item} = 1;
1.160.6.16 raeburn 11681: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11682: $changes{$item} = 1;
11683: }
11684: } elsif ($defaultchecked{$item} eq 'off') {
11685: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11686: ($env{'form.'.$item} eq '1')) {
11687: $changes{$item} = 1;
11688: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11689: $changes{$item} = 1;
11690: }
11691: }
11692: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11693: }
1.160.6.21 raeburn 11694: foreach my $item (@numbers) {
11695: my ($currdef,$newdef);
1.160.6.26 raeburn 11696: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 11697: if ($item eq 'anonsurvey_threshold') {
11698: $currdef = $domconfig{'coursedefaults'}{$item};
11699: $newdef =~ s/\D//g;
11700: if ($newdef eq '' || $newdef < 1) {
11701: $newdef = 1;
11702: }
11703: $defaultshash{'coursedefaults'}{$item} = $newdef;
11704: } else {
1.160.6.70 raeburn 11705: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
11706: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
11707: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 11708: }
11709: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 11710: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 11711: }
11712: if ($currdef ne $newdef) {
11713: my $staticdef;
11714: if ($item eq 'anonsurvey_threshold') {
11715: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11716: $changes{$item} = 1;
11717: }
1.160.6.70 raeburn 11718: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
11719: my $setting = $1;
11720: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
11721: $changes{$setting} = 1;
1.160.6.21 raeburn 11722: }
11723: }
1.139 raeburn 11724: }
11725: }
1.160.6.64 raeburn 11726: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11727: my @currclonecode;
11728: if (ref($currclone) eq 'HASH') {
11729: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11730: @currclonecode = @{$currclone->{'instcode'}};
11731: }
11732: }
11733: my $newclone;
11734: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11735: $newclone = $env{'form.canclone'};
11736: }
11737: if ($newclone eq 'instcode') {
11738: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11739: my (%codedefaults,@code_order,@clonecode);
11740: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11741: \@code_order);
11742: foreach my $item (@code_order) {
11743: if (grep(/^\Q$item\E$/,@newcodes)) {
11744: push(@clonecode,$item);
11745: }
11746: }
11747: if (@clonecode) {
11748: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11749: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11750: if (@diffs) {
11751: $changes{'canclone'} = 1;
11752: }
11753: } else {
11754: $newclone eq '';
11755: }
11756: } elsif ($newclone ne '') {
11757: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11758: }
11759: if ($newclone ne $currclone) {
11760: $changes{'canclone'} = 1;
11761: }
1.160.6.57 raeburn 11762: my %credits;
11763: foreach my $type (@types) {
11764: unless ($type eq 'community') {
11765: $credits{$type} = $env{'form.'.$type.'_credits'};
11766: $credits{$type} =~ s/[^\d.]+//g;
11767: }
11768: }
11769: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11770: ($env{'form.coursecredits'} eq '1')) {
11771: $changes{'coursecredits'} = 1;
11772: foreach my $type (keys(%credits)) {
11773: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11774: }
11775: } else {
11776: if ($env{'form.coursecredits'} eq '1') {
11777: foreach my $type (@types) {
11778: unless ($type eq 'community') {
11779: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11780: $changes{'coursecredits'} = 1;
11781: }
11782: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11783: }
11784: }
11785: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11786: foreach my $type (@types) {
11787: unless ($type eq 'community') {
11788: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11789: $changes{'coursecredits'} = 1;
11790: last;
11791: }
11792: }
11793: }
11794: }
11795: }
11796: if ($env{'form.postsubmit'} eq '1') {
11797: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11798: my %currtimeout;
11799: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11800: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11801: $changes{'postsubmit'} = 1;
11802: }
11803: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11804: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11805: }
11806: } else {
11807: $changes{'postsubmit'} = 1;
11808: }
11809: foreach my $type (@types) {
11810: my $timeout = $env{'form.'.$type.'_timeout'};
11811: $timeout =~ s/\D//g;
11812: if ($timeout == $staticdefaults{'postsubmit'}) {
11813: $timeout = '';
11814: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11815: $timeout = '0';
11816: }
11817: unless ($timeout eq '') {
11818: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11819: }
11820: if (exists($currtimeout{$type})) {
11821: if ($timeout ne $currtimeout{$type}) {
11822: $changes{'postsubmit'} = 1;
11823: }
11824: } elsif ($timeout ne '') {
11825: $changes{'postsubmit'} = 1;
11826: }
11827: }
11828: } else {
11829: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11830: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11831: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11832: $changes{'postsubmit'} = 1;
11833: }
11834: } else {
11835: $changes{'postsubmit'} = 1;
11836: }
1.160.6.16 raeburn 11837: }
1.121 raeburn 11838: }
11839: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11840: $dom);
11841: if ($putresult eq 'ok') {
11842: if (keys(%changes) > 0) {
1.160.6.27 raeburn 11843: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 11844: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 11845: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 11846: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 11847: foreach my $item ('uselcmath','usejsme') {
11848: if ($changes{$item}) {
11849: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11850: }
1.160.6.16 raeburn 11851: }
11852: if ($changes{'coursecredits'}) {
11853: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 11854: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11855: $domdefaults{$type.'credits'} =
11856: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11857: }
11858: }
11859: }
11860: if ($changes{'postsubmit'}) {
11861: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11862: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11863: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11864: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11865: $domdefaults{$type.'postsubtimeout'} =
11866: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11867: }
11868: }
1.160.6.16 raeburn 11869: }
11870: }
1.160.6.21 raeburn 11871: if ($changes{'uploadquota'}) {
11872: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11873: foreach my $type (@types) {
11874: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11875: }
11876: }
11877: }
1.160.6.64 raeburn 11878: if ($changes{'canclone'}) {
11879: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11880: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11881: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11882: if (@clonecodes) {
11883: $domdefaults{'canclone'} = join('+',@clonecodes);
11884: }
11885: }
11886: } else {
11887: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11888: }
11889: }
1.121 raeburn 11890: my $cachetime = 24*60*60;
11891: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11892: if (ref($lastactref) eq 'HASH') {
11893: $lastactref->{'domdefaults'} = 1;
11894: }
1.121 raeburn 11895: }
11896: $resulttext = &mt('Changes made:').'<ul>';
11897: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 11898: if ($item eq 'uselcmath') {
1.121 raeburn 11899: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 11900: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 11901: } else {
1.160.6.57 raeburn 11902: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11903: }
11904: } elsif ($item eq 'usejsme') {
11905: if ($env{'form.'.$item} eq '1') {
11906: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11907: } else {
11908: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 11909: }
1.139 raeburn 11910: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 11911: $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 11912: } elsif ($item eq 'uploadquota') {
11913: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11914: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11915: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11916: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 11917: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
11918:
1.160.6.21 raeburn 11919: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11920: '</ul>'.
11921: '</li>';
11922: } else {
11923: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11924: }
1.160.6.70 raeburn 11925: } elsif ($item eq 'mysqltables') {
11926: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
11927: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
11928: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
11929: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
11930: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
11931: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
11932: '</ul>'.
11933: '</li>';
11934: } else {
11935: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
11936: }
1.160.6.57 raeburn 11937: } elsif ($item eq 'postsubmit') {
11938: if ($domdefaults{'postsubmit'} eq 'off') {
11939: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
11940: } else {
11941: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
11942: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11943: $resulttext .= &mt('durations:').'<ul>';
11944: foreach my $type (@types) {
11945: $resulttext .= '<li>';
11946: my $timeout;
11947: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11948: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11949: }
11950: my $display;
11951: if ($timeout eq '0') {
11952: $display = &mt('unlimited');
11953: } elsif ($timeout eq '') {
11954: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
11955: } else {
11956: $display = &mt('[quant,_1,second]',$timeout);
11957: }
11958: if ($type eq 'community') {
11959: $resulttext .= &mt('Communities');
11960: } elsif ($type eq 'official') {
11961: $resulttext .= &mt('Official courses');
11962: } elsif ($type eq 'unofficial') {
11963: $resulttext .= &mt('Unofficial courses');
11964: } elsif ($type eq 'textbook') {
11965: $resulttext .= &mt('Textbook courses');
11966: }
11967: $resulttext .= ' -- '.$display.'</li>';
11968: }
11969: $resulttext .= '</ul>';
11970: }
11971: $resulttext .= '</li>';
11972: }
1.160.6.16 raeburn 11973: } elsif ($item eq 'coursecredits') {
11974: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11975: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 11976: ($domdefaults{'unofficialcredits'} eq '') &&
11977: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 11978: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11979: } else {
11980: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
11981: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
11982: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 11983: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 11984: '</ul>'.
11985: '</li>';
11986: }
11987: } else {
11988: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11989: }
1.160.6.64 raeburn 11990: } elsif ($item eq 'canclone') {
11991: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11992: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11993: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
11994: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
11995: }
11996: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
11997: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
11998: } else {
11999: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
12000: }
1.140 raeburn 12001: }
1.121 raeburn 12002: }
12003: $resulttext .= '</ul>';
12004: } else {
12005: $resulttext = &mt('No changes made to course defaults');
12006: }
12007: } else {
12008: $resulttext = '<span class="LC_error">'.
12009: &mt('An error occurred: [_1]',$putresult).'</span>';
12010: }
12011: return $resulttext;
12012: }
12013:
1.160.6.37 raeburn 12014: sub modify_selfenrollment {
12015: my ($dom,$lastactref,%domconfig) = @_;
12016: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
12017: my @types = ('official','unofficial','community','textbook');
12018: my %titles = &tool_titles();
12019: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12020: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
12021: $ordered{'default'} = ['types','registered','approval','limit'];
12022:
12023: my (%roles,%shown,%toplevel);
12024: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12025:
12026: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12027: if ($domconfig{'selfenrollment'} eq '') {
12028: $domconfig{'selfenrollment'} = {};
12029: }
12030: }
12031: %toplevel = (
12032: admin => 'Configuration Rights',
12033: default => 'Default settings',
12034: validation => 'Validation of self-enrollment requests',
12035: );
12036: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
12037:
12038: if (ref($ordered{'admin'}) eq 'ARRAY') {
12039: foreach my $item (@{$ordered{'admin'}}) {
12040: foreach my $type (@types) {
12041: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12042: $selfenrollhash{'admin'}{$type}{$item} = 1;
12043: } else {
12044: $selfenrollhash{'admin'}{$type}{$item} = 0;
12045: }
12046: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12047: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12048: if ($selfenrollhash{'admin'}{$type}{$item} ne
12049: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12050: push(@{$changes{'admin'}{$type}},$item);
12051: }
12052: } else {
12053: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12054: push(@{$changes{'admin'}{$type}},$item);
12055: }
12056: }
12057: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12058: push(@{$changes{'admin'}{$type}},$item);
12059: }
12060: }
12061: }
12062: }
12063:
12064: foreach my $item (@{$ordered{'default'}}) {
12065: foreach my $type (@types) {
12066: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12067: if ($item eq 'types') {
12068: unless (($value eq 'all') || ($value eq 'dom')) {
12069: $value = '';
12070: }
12071: } elsif ($item eq 'registered') {
12072: unless ($value eq '1') {
12073: $value = 0;
12074: }
12075: } elsif ($item eq 'approval') {
12076: unless ($value =~ /^[012]$/) {
12077: $value = 0;
12078: }
12079: } else {
12080: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12081: $value = 'none';
12082: }
12083: }
12084: $selfenrollhash{'default'}{$type}{$item} = $value;
12085: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12086: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12087: if ($selfenrollhash{'default'}{$type}{$item} ne
12088: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12089: push(@{$changes{'default'}{$type}},$item);
12090: }
12091: } else {
12092: push(@{$changes{'default'}{$type}},$item);
12093: }
12094: } else {
12095: push(@{$changes{'default'}{$type}},$item);
12096: }
12097: if ($item eq 'limit') {
12098: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12099: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12100: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12101: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12102: }
12103: } else {
12104: $selfenrollhash{'default'}{$type}{'cap'} = '';
12105: }
12106: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12107: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12108: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12109: push(@{$changes{'default'}{$type}},'cap');
12110: }
12111: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12112: push(@{$changes{'default'}{$type}},'cap');
12113: }
12114: }
12115: }
12116: }
12117:
12118: foreach my $item (@{$itemsref}) {
12119: if ($item eq 'fields') {
12120: my @changed;
12121: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12122: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12123: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12124: }
12125: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12126: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12127: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12128: $domconfig{'selfenrollment'}{'validation'}{$item});
12129: } else {
12130: @changed = @{$selfenrollhash{'validation'}{$item}};
12131: }
12132: } else {
12133: @changed = @{$selfenrollhash{'validation'}{$item}};
12134: }
12135: if (@changed) {
12136: if ($selfenrollhash{'validation'}{$item}) {
12137: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12138: } else {
12139: $changes{'validation'}{$item} = &mt('None');
12140: }
12141: }
12142: } else {
12143: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12144: if ($item eq 'markup') {
12145: if ($env{'form.selfenroll_validation_'.$item}) {
12146: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12147: }
12148: }
12149: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12150: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12151: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12152: }
12153: }
12154: }
12155: }
12156:
12157: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12158: $dom);
12159: if ($putresult eq 'ok') {
12160: if (keys(%changes) > 0) {
12161: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12162: $resulttext = &mt('Changes made:').'<ul>';
12163: foreach my $key ('admin','default','validation') {
12164: if (ref($changes{$key}) eq 'HASH') {
12165: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12166: if ($key eq 'validation') {
12167: foreach my $item (@{$itemsref}) {
12168: if (exists($changes{$key}{$item})) {
12169: if ($item eq 'markup') {
12170: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12171: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12172: } else {
12173: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12174: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12175: }
12176: }
12177: }
12178: } else {
12179: foreach my $type (@types) {
12180: if ($type eq 'community') {
12181: $roles{'1'} = &mt('Community personnel');
12182: } else {
12183: $roles{'1'} = &mt('Course personnel');
12184: }
12185: if (ref($changes{$key}{$type}) eq 'ARRAY') {
12186: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12187: if ($key eq 'admin') {
12188: my @mgrdc = ();
12189: if (ref($ordered{$key}) eq 'ARRAY') {
12190: foreach my $item (@{$ordered{'admin'}}) {
12191: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12192: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12193: push(@mgrdc,$item);
12194: }
12195: }
12196: }
12197: if (@mgrdc) {
12198: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12199: } else {
12200: delete($domdefaults{$type.'selfenrolladmdc'});
12201: }
12202: }
12203: } else {
12204: if (ref($ordered{$key}) eq 'ARRAY') {
12205: foreach my $item (@{$ordered{$key}}) {
12206: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12207: $domdefaults{$type.'selfenroll'.$item} =
12208: $selfenrollhash{$key}{$type}{$item};
12209: }
12210: }
12211: }
12212: }
12213: }
12214: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12215: foreach my $item (@{$ordered{$key}}) {
12216: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12217: $resulttext .= '<li>';
12218: if ($key eq 'admin') {
12219: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12220: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12221: } else {
12222: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12223: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12224: }
12225: $resulttext .= '</li>';
12226: }
12227: }
12228: $resulttext .= '</ul></li>';
12229: }
12230: }
12231: $resulttext .= '</ul></li>';
12232: }
12233: }
12234: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12235: my $cachetime = 24*60*60;
12236: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12237: if (ref($lastactref) eq 'HASH') {
12238: $lastactref->{'domdefaults'} = 1;
12239: }
12240: }
12241: }
12242: $resulttext .= '</ul>';
12243: } else {
12244: $resulttext = &mt('No changes made to self-enrollment settings');
12245: }
12246: } else {
12247: $resulttext = '<span class="LC_error">'.
12248: &mt('An error occurred: [_1]',$putresult).'</span>';
12249: }
12250: return $resulttext;
12251: }
12252:
1.137 raeburn 12253: sub modify_usersessions {
1.160.6.27 raeburn 12254: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12255: my @hostingtypes = ('version','excludedomain','includedomain');
12256: my @offloadtypes = ('primary','default');
12257: my %types = (
12258: remote => \@hostingtypes,
12259: hosted => \@hostingtypes,
12260: spares => \@offloadtypes,
12261: );
12262: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12263: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 12264: my (%by_ip,%by_location,@intdoms);
12265: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
12266: my @locations = sort(keys(%by_location));
1.137 raeburn 12267: my (%defaultshash,%changes);
12268: foreach my $prefix (@prefixes) {
12269: $defaultshash{'usersessions'}{$prefix} = {};
12270: }
1.160.6.27 raeburn 12271: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12272: my $resulttext;
1.138 raeburn 12273: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12274: foreach my $prefix (@prefixes) {
1.145 raeburn 12275: next if ($prefix eq 'spares');
12276: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12277: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12278: if ($type eq 'version') {
12279: my $value = $env{'form.'.$prefix.'_'.$type};
12280: my $okvalue;
12281: if ($value ne '') {
12282: if (grep(/^\Q$value\E$/,@lcversions)) {
12283: $okvalue = $value;
12284: }
12285: }
12286: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12287: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12288: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12289: if ($inuse == 0) {
12290: $changes{$prefix}{$type} = 1;
12291: } else {
12292: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12293: $changes{$prefix}{$type} = 1;
12294: }
12295: if ($okvalue ne '') {
12296: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12297: }
12298: }
12299: } else {
12300: if (($inuse == 1) && ($okvalue ne '')) {
12301: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12302: $changes{$prefix}{$type} = 1;
12303: }
12304: }
12305: } else {
12306: if (($inuse == 1) && ($okvalue ne '')) {
12307: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12308: $changes{$prefix}{$type} = 1;
12309: }
12310: }
12311: } else {
12312: if (($inuse == 1) && ($okvalue ne '')) {
12313: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12314: $changes{$prefix}{$type} = 1;
12315: }
12316: }
12317: } else {
12318: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12319: my @okvals;
12320: foreach my $val (@vals) {
1.138 raeburn 12321: if ($val =~ /:/) {
12322: my @items = split(/:/,$val);
12323: foreach my $item (@items) {
12324: if (ref($by_location{$item}) eq 'ARRAY') {
12325: push(@okvals,$item);
12326: }
12327: }
12328: } else {
12329: if (ref($by_location{$val}) eq 'ARRAY') {
12330: push(@okvals,$val);
12331: }
1.137 raeburn 12332: }
12333: }
12334: @okvals = sort(@okvals);
12335: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12336: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12337: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12338: if ($inuse == 0) {
12339: $changes{$prefix}{$type} = 1;
12340: } else {
12341: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12342: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12343: if (@changed > 0) {
12344: $changes{$prefix}{$type} = 1;
12345: }
12346: }
12347: } else {
12348: if ($inuse == 1) {
12349: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12350: $changes{$prefix}{$type} = 1;
12351: }
12352: }
12353: } else {
12354: if ($inuse == 1) {
12355: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12356: $changes{$prefix}{$type} = 1;
12357: }
12358: }
12359: } else {
12360: if ($inuse == 1) {
12361: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12362: $changes{$prefix}{$type} = 1;
12363: }
12364: }
12365: }
12366: }
12367: }
1.145 raeburn 12368:
12369: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12370: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12371: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12372: my $savespares;
12373:
12374: foreach my $lonhost (sort(keys(%servers))) {
12375: my $serverhomeID =
12376: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12377: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12378: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12379: my %spareschg;
12380: foreach my $type (@{$types{'spares'}}) {
12381: my @okspares;
12382: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12383: foreach my $server (@checked) {
1.152 raeburn 12384: if (&Apache::lonnet::hostname($server) ne '') {
12385: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12386: unless (grep(/^\Q$server\E$/,@okspares)) {
12387: push(@okspares,$server);
12388: }
1.145 raeburn 12389: }
12390: }
12391: }
12392: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12393: my $newspare;
1.152 raeburn 12394: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12395: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12396: $newspare = $new;
12397: }
12398: }
1.152 raeburn 12399: my @spares;
12400: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12401: @spares = sort(@okspares,$newspare);
12402: } else {
12403: @spares = sort(@okspares);
12404: }
12405: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12406: if (ref($spareid{$lonhost}) eq 'HASH') {
12407: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12408: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12409: if (@diffs > 0) {
12410: $spareschg{$type} = 1;
12411: }
12412: }
12413: }
12414: }
12415: if (keys(%spareschg) > 0) {
12416: $changes{'spares'}{$lonhost} = \%spareschg;
12417: }
12418: }
1.160.6.61 raeburn 12419: $defaultshash{'usersessions'}{'offloadnow'} = {};
12420: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12421: my @okoffload;
12422: if (@offloadnow) {
12423: foreach my $server (@offloadnow) {
12424: if (&Apache::lonnet::hostname($server) ne '') {
12425: unless (grep(/^\Q$server\E$/,@okoffload)) {
12426: push(@okoffload,$server);
12427: }
12428: }
12429: }
12430: if (@okoffload) {
12431: foreach my $lonhost (@okoffload) {
12432: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12433: }
12434: }
12435: }
1.145 raeburn 12436: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12437: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12438: if (ref($changes{'spares'}) eq 'HASH') {
12439: if (keys(%{$changes{'spares'}}) > 0) {
12440: $savespares = 1;
12441: }
12442: }
12443: } else {
12444: $savespares = 1;
12445: }
1.160.6.61 raeburn 12446: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12447: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12448: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12449: $changes{'offloadnow'} = 1;
12450: last;
12451: }
12452: }
12453: unless ($changes{'offloadnow'}) {
12454: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12455: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12456: $changes{'offloadnow'} = 1;
12457: last;
12458: }
12459: }
12460: }
12461: } elsif (@okoffload) {
12462: $changes{'offloadnow'} = 1;
12463: }
12464: } elsif (@okoffload) {
12465: $changes{'offloadnow'} = 1;
1.145 raeburn 12466: }
1.147 raeburn 12467: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12468: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12469: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12470: $dom);
12471: if ($putresult eq 'ok') {
12472: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12473: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12474: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12475: }
12476: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12477: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12478: }
1.160.6.61 raeburn 12479: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12480: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12481: }
1.137 raeburn 12482: }
12483: my $cachetime = 24*60*60;
12484: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 12485: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 12486: if (ref($lastactref) eq 'HASH') {
12487: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 12488: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 12489: }
1.147 raeburn 12490: if (keys(%changes) > 0) {
12491: my %lt = &usersession_titles();
12492: $resulttext = &mt('Changes made:').'<ul>';
12493: foreach my $prefix (@prefixes) {
12494: if (ref($changes{$prefix}) eq 'HASH') {
12495: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12496: if ($prefix eq 'spares') {
12497: if (ref($changes{$prefix}) eq 'HASH') {
12498: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12499: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12500: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 12501: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12502: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12503: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12504: foreach my $type (@{$types{$prefix}}) {
12505: if ($changes{$prefix}{$lonhost}{$type}) {
12506: my $offloadto = &mt('None');
12507: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12508: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12509: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12510: }
1.145 raeburn 12511: }
1.147 raeburn 12512: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12513: }
1.137 raeburn 12514: }
12515: }
1.147 raeburn 12516: $resulttext .= '</li>';
1.137 raeburn 12517: }
12518: }
1.147 raeburn 12519: } else {
12520: foreach my $type (@{$types{$prefix}}) {
12521: if (defined($changes{$prefix}{$type})) {
12522: my $newvalue;
12523: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12524: if (ref($defaultshash{'usersessions'}{$prefix})) {
12525: if ($type eq 'version') {
12526: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12527: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12528: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12529: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12530: }
1.145 raeburn 12531: }
12532: }
12533: }
1.147 raeburn 12534: if ($newvalue eq '') {
12535: if ($type eq 'version') {
12536: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12537: } else {
12538: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12539: }
1.145 raeburn 12540: } else {
1.147 raeburn 12541: if ($type eq 'version') {
12542: $newvalue .= ' '.&mt('(or later)');
12543: }
12544: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12545: }
1.137 raeburn 12546: }
12547: }
12548: }
1.147 raeburn 12549: $resulttext .= '</ul>';
1.137 raeburn 12550: }
12551: }
1.160.6.61 raeburn 12552: if ($changes{'offloadnow'}) {
12553: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12554: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12555: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12556: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12557: $resulttext .= '<li>'.$lonhost.'</li>';
12558: }
12559: $resulttext .= '</ul>';
12560: } else {
12561: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12562: }
12563: } else {
12564: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12565: }
12566: }
1.147 raeburn 12567: $resulttext .= '</ul>';
12568: } else {
12569: $resulttext = $nochgmsg;
1.137 raeburn 12570: }
12571: } else {
12572: $resulttext = '<span class="LC_error">'.
12573: &mt('An error occurred: [_1]',$putresult).'</span>';
12574: }
12575: } else {
1.147 raeburn 12576: $resulttext = $nochgmsg;
1.137 raeburn 12577: }
12578: return $resulttext;
12579: }
12580:
1.150 raeburn 12581: sub modify_loadbalancing {
12582: my ($dom,%domconfig) = @_;
12583: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12584: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12585: my ($othertitle,$usertypes,$types) =
12586: &Apache::loncommon::sorted_inst_types($dom);
12587: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 12588: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12589: my @sparestypes = ('primary','default');
12590: my %typetitles = &sparestype_titles();
12591: my $resulttext;
1.160.6.7 raeburn 12592: my (%currbalancer,%currtargets,%currrules,%existing);
12593: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12594: %existing = %{$domconfig{'loadbalancing'}};
12595: }
12596: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12597: \%currtargets,\%currrules);
12598: my ($saveloadbalancing,%defaultshash,%changes);
12599: my ($alltypes,$othertypes,$titles) =
12600: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12601: my %ruletitles = &offloadtype_text();
12602: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12603: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12604: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12605: if ($balancer eq '') {
12606: next;
12607: }
12608: if (!exists($servers{$balancer})) {
12609: if (exists($currbalancer{$balancer})) {
12610: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 12611: }
1.160.6.7 raeburn 12612: next;
12613: }
12614: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12615: push(@{$changes{'delete'}},$balancer);
12616: next;
12617: }
12618: if (!exists($currbalancer{$balancer})) {
12619: push(@{$changes{'add'}},$balancer);
12620: }
12621: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12622: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12623: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12624: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12625: $saveloadbalancing = 1;
12626: }
12627: foreach my $sparetype (@sparestypes) {
12628: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12629: my @offloadto;
12630: foreach my $target (@targets) {
12631: if (($servers{$target}) && ($target ne $balancer)) {
12632: if ($sparetype eq 'default') {
12633: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12634: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 12635: }
12636: }
1.160.6.7 raeburn 12637: unless(grep(/^\Q$target\E$/,@offloadto)) {
12638: push(@offloadto,$target);
12639: }
1.150 raeburn 12640: }
12641: }
1.160.6.76 raeburn 12642: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
12643: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
12644: push(@offloadto,$balancer);
12645: }
12646: }
12647: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 12648: }
1.160.6.7 raeburn 12649: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 12650: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 12651: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12652: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 12653: if (@targetdiffs > 0) {
1.160.6.7 raeburn 12654: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12655: }
1.160.6.7 raeburn 12656: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12657: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12658: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12659: }
12660: }
12661: }
12662: } else {
1.160.6.7 raeburn 12663: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
12664: foreach my $sparetype (@sparestypes) {
12665: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12666: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12667: $changes{'curr'}{$balancer}{'targets'} = 1;
12668: }
1.150 raeburn 12669: }
12670: }
1.160.6.7 raeburn 12671: }
1.150 raeburn 12672: }
12673: my $ishomedom;
1.160.6.7 raeburn 12674: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12675: $ishomedom = 1;
1.150 raeburn 12676: }
12677: if (ref($alltypes) eq 'ARRAY') {
12678: foreach my $type (@{$alltypes}) {
12679: my $rule;
1.160.6.7 raeburn 12680: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 12681: (!$ishomedom)) {
1.160.6.7 raeburn 12682: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12683: }
12684: if ($rule eq 'specific') {
1.160.6.55 raeburn 12685: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12686: if (exists($servers{$specifiedhost})) {
12687: $rule = $specifiedhost;
12688: }
1.150 raeburn 12689: }
1.160.6.7 raeburn 12690: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12691: if (ref($currrules{$balancer}) eq 'HASH') {
12692: if ($rule ne $currrules{$balancer}{$type}) {
12693: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12694: }
12695: } elsif ($rule ne '') {
1.160.6.7 raeburn 12696: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12697: }
12698: }
12699: }
1.160.6.7 raeburn 12700: }
12701: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12702: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12703: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12704: $defaultshash{'loadbalancing'} = {};
12705: }
12706: my $putresult = &Apache::lonnet::put_dom('configuration',
12707: \%defaultshash,$dom);
12708: if ($putresult eq 'ok') {
12709: if (keys(%changes) > 0) {
1.160.6.54 raeburn 12710: my %toupdate;
1.160.6.7 raeburn 12711: if (ref($changes{'delete'}) eq 'ARRAY') {
12712: foreach my $balancer (sort(@{$changes{'delete'}})) {
12713: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 12714: $toupdate{$balancer} = 1;
1.150 raeburn 12715: }
1.160.6.7 raeburn 12716: }
12717: if (ref($changes{'add'}) eq 'ARRAY') {
12718: foreach my $balancer (sort(@{$changes{'add'}})) {
12719: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 12720: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12721: }
12722: }
12723: if (ref($changes{'curr'}) eq 'HASH') {
12724: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 12725: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12726: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12727: if ($changes{'curr'}{$balancer}{'targets'}) {
12728: my %offloadstr;
12729: foreach my $sparetype (@sparestypes) {
12730: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12731: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12732: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12733: }
12734: }
1.150 raeburn 12735: }
1.160.6.7 raeburn 12736: if (keys(%offloadstr) == 0) {
12737: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 12738: } else {
1.160.6.7 raeburn 12739: my $showoffload;
12740: foreach my $sparetype (@sparestypes) {
12741: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12742: if (defined($offloadstr{$sparetype})) {
12743: $showoffload .= $offloadstr{$sparetype};
12744: } else {
12745: $showoffload .= &mt('None');
12746: }
12747: $showoffload .= (' 'x3);
12748: }
12749: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 12750: }
12751: }
12752: }
1.160.6.7 raeburn 12753: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12754: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12755: foreach my $type (@{$alltypes}) {
12756: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12757: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12758: my $balancetext;
12759: if ($rule eq '') {
12760: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 12761: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 12762: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12763: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 12764: foreach my $sparetype (@sparestypes) {
12765: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12766: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12767: }
12768: }
1.160.6.55 raeburn 12769: foreach my $item (@{$alltypes}) {
12770: next if ($item =~ /^_LC_ipchange/);
12771: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
12772: if ($hasrule eq 'homeserver') {
12773: map { $toupdate{$_} = 1; } (keys(%libraryservers));
12774: } else {
12775: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
12776: if ($servers{$hasrule}) {
12777: $toupdate{$hasrule} = 1;
12778: }
12779: }
12780: }
12781: }
12782: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
12783: $balancetext = $ruletitles{$rule};
12784: } else {
12785: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12786: $balancetext = $ruletitles{'particular'}.' '.$receiver;
12787: if ($receiver) {
12788: $toupdate{$receiver};
12789: }
12790: }
12791: } else {
12792: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 12793: }
1.160.6.7 raeburn 12794: } else {
12795: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
12796: }
1.160.6.26 raeburn 12797: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 12798: }
12799: }
12800: }
12801: }
1.160.6.54 raeburn 12802: if (keys(%toupdate)) {
12803: my %thismachine;
12804: my $updatedhere;
12805: my $cachetime = 60*60*24;
12806: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12807: foreach my $lonhost (keys(%toupdate)) {
12808: if ($thismachine{$lonhost}) {
12809: unless ($updatedhere) {
12810: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
12811: $defaultshash{'loadbalancing'},
12812: $cachetime);
12813: $updatedhere = 1;
12814: }
12815: } else {
12816: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
12817: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
12818: }
12819: }
12820: }
1.150 raeburn 12821: }
1.160.6.7 raeburn 12822: }
12823: if ($resulttext ne '') {
12824: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 12825: } else {
12826: $resulttext = $nochgmsg;
12827: }
12828: } else {
1.160.6.7 raeburn 12829: $resulttext = $nochgmsg;
1.150 raeburn 12830: }
12831: } else {
1.160.6.7 raeburn 12832: $resulttext = '<span class="LC_error">'.
12833: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 12834: }
12835: } else {
1.160.6.7 raeburn 12836: $resulttext = $nochgmsg;
1.150 raeburn 12837: }
12838: return $resulttext;
12839: }
12840:
1.48 raeburn 12841: sub recurse_check {
12842: my ($chkcats,$categories,$depth,$name) = @_;
12843: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
12844: my $chg = 0;
12845: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
12846: my $category = $chkcats->[$depth]{$name}[$j];
12847: my $item;
12848: if ($category eq '') {
12849: $chg ++;
12850: } else {
12851: my $deeper = $depth + 1;
12852: $item = &escape($category).':'.&escape($name).':'.$depth;
12853: if ($chg) {
12854: $categories->{$item} -= $chg;
12855: }
12856: &recurse_check($chkcats,$categories,$deeper,$category);
12857: $deeper --;
12858: }
12859: }
12860: }
12861: return;
12862: }
12863:
12864: sub recurse_cat_deletes {
12865: my ($item,$coursecategories,$deletions) = @_;
12866: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12867: my $subdepth = $depth + 1;
12868: if (ref($coursecategories) eq 'HASH') {
12869: foreach my $subitem (keys(%{$coursecategories})) {
12870: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
12871: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
12872: delete($coursecategories->{$subitem});
12873: $deletions->{$subitem} = 1;
12874: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 12875: }
1.48 raeburn 12876: }
12877: }
12878: return;
12879: }
12880:
1.125 raeburn 12881: sub active_dc_picker {
1.160.6.16 raeburn 12882: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 12883: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 12884: my @domcoord = keys(%domcoords);
12885: if (keys(%currhash)) {
12886: foreach my $dc (keys(%currhash)) {
12887: unless (exists($domcoords{$dc})) {
12888: push(@domcoord,$dc);
12889: }
12890: }
12891: }
12892: @domcoord = sort(@domcoord);
12893: my $numdcs = scalar(@domcoord);
12894: my $rows = 0;
12895: my $table;
1.125 raeburn 12896: if ($numdcs > 1) {
1.160.6.16 raeburn 12897: $table = '<table>';
12898: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 12899: my $rem = $i%($numinrow);
12900: if ($rem == 0) {
12901: if ($i > 0) {
1.160.6.16 raeburn 12902: $table .= '</tr>';
1.125 raeburn 12903: }
1.160.6.16 raeburn 12904: $table .= '<tr>';
12905: $rows ++;
1.125 raeburn 12906: }
1.160.6.16 raeburn 12907: my $check = '';
12908: if ($inputtype eq 'radio') {
12909: if (keys(%currhash) == 0) {
12910: if (!$i) {
12911: $check = ' checked="checked"';
12912: }
12913: } elsif (exists($currhash{$domcoord[$i]})) {
12914: $check = ' checked="checked"';
12915: }
12916: } else {
12917: if (exists($currhash{$domcoord[$i]})) {
12918: $check = ' checked="checked"';
1.125 raeburn 12919: }
12920: }
1.160.6.16 raeburn 12921: if ($i == @domcoord - 1) {
1.125 raeburn 12922: my $colsleft = $numinrow - $rem;
12923: if ($colsleft > 1) {
1.160.6.16 raeburn 12924: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 12925: } else {
1.160.6.16 raeburn 12926: $table .= '<td class="LC_left_item">';
1.125 raeburn 12927: }
12928: } else {
1.160.6.16 raeburn 12929: $table .= '<td class="LC_left_item">';
12930: }
12931: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
12932: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
12933: $table .= '<span class="LC_nobreak"><label>'.
12934: '<input type="'.$inputtype.'" name="'.$name.'"'.
12935: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
12936: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 12937: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 12938: }
1.160.6.33 raeburn 12939: $table .= '</label></span></td>';
1.125 raeburn 12940: }
1.160.6.16 raeburn 12941: $table .= '</tr></table>';
12942: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 12943: my ($dcname,$dcdom) = split(':',$domcoord[0]);
12944: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 12945: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 12946: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 12947: if ($user ne $dcname.':'.$dcdom) {
12948: $table .= ' ('.$dcname.':'.$dcdom.')';
12949: }
1.160.6.16 raeburn 12950: } else {
12951: my $check;
12952: if (exists($currhash{$domcoord[0]})) {
12953: $check = ' checked="checked"';
12954: }
1.160.6.50 raeburn 12955: $table = '<span class="LC_nobreak"><label>'.
12956: '<input type="checkbox" name="'.$name.'" '.
12957: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 12958: if ($user ne $dcname.':'.$dcdom) {
12959: $table .= ' ('.$dcname.':'.$dcdom.')';
12960: }
12961: $table .= '</label></span>';
1.160.6.16 raeburn 12962: $rows ++;
12963: }
1.125 raeburn 12964: }
1.160.6.16 raeburn 12965: return ($numdcs,$table,$rows);
1.125 raeburn 12966: }
12967:
1.137 raeburn 12968: sub usersession_titles {
12969: return &Apache::lonlocal::texthash(
12970: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
12971: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 12972: spares => 'Servers offloaded to, when busy',
1.137 raeburn 12973: version => 'LON-CAPA version requirement',
1.138 raeburn 12974: excludedomain => 'Allow all, but exclude specific domains',
12975: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 12976: primary => 'Primary (checked first)',
1.154 raeburn 12977: default => 'Default',
1.137 raeburn 12978: );
12979: }
12980:
1.152 raeburn 12981: sub id_for_thisdom {
12982: my (%servers) = @_;
12983: my %altids;
12984: foreach my $server (keys(%servers)) {
12985: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
12986: if ($serverhome ne $server) {
12987: $altids{$serverhome} = $server;
12988: }
12989: }
12990: return %altids;
12991: }
12992:
1.150 raeburn 12993: sub count_servers {
12994: my ($currbalancer,%servers) = @_;
12995: my (@spares,$numspares);
12996: foreach my $lonhost (sort(keys(%servers))) {
12997: next if ($currbalancer eq $lonhost);
12998: push(@spares,$lonhost);
12999: }
13000: if ($currbalancer) {
13001: $numspares = scalar(@spares);
13002: } else {
13003: $numspares = scalar(@spares) - 1;
13004: }
13005: return ($numspares,@spares);
13006: }
13007:
13008: sub lonbalance_targets_js {
1.160.6.7 raeburn 13009: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13010: my $select = &mt('Select');
13011: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13012: if (ref($servers) eq 'HASH') {
13013: $alltargets = join("','",sort(keys(%{$servers})));
13014: my @homedoms;
13015: foreach my $server (sort(keys(%{$servers}))) {
13016: if (&Apache::lonnet::host_domain($server) eq $dom) {
13017: push(@homedoms,'1');
13018: } else {
13019: push(@homedoms,'0');
13020: }
13021: }
13022: $allishome = join("','",@homedoms);
13023: }
13024: if (ref($types) eq 'ARRAY') {
13025: if (@{$types} > 0) {
13026: @alltypes = @{$types};
13027: }
13028: }
13029: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13030: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 13031: my (%currbalancer,%currtargets,%currrules,%existing);
13032: if (ref($settings) eq 'HASH') {
13033: %existing = %{$settings};
13034: }
13035: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13036: \%currtargets,\%currrules);
13037: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13038: return <<"END";
13039:
13040: <script type="text/javascript">
13041: // <![CDATA[
13042:
1.160.6.7 raeburn 13043: currBalancers = new Array('$balancers');
13044:
13045: function toggleTargets(balnum) {
13046: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13047: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13048: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13049: var prevbalancer = prevhostitem.value;
13050: var baltotal = document.getElementById('loadbalancing_total').value;
13051: prevhostitem.value = balancer;
13052: if (prevbalancer != '') {
13053: var prevIdx = currBalancers.indexOf(prevbalancer);
13054: if (prevIdx != -1) {
13055: currBalancers.splice(prevIdx,1);
13056: }
13057: }
1.150 raeburn 13058: if (balancer == '') {
1.160.6.7 raeburn 13059: hideSpares(balnum);
1.150 raeburn 13060: } else {
1.160.6.7 raeburn 13061: var currIdx = currBalancers.indexOf(balancer);
13062: if (currIdx == -1) {
13063: currBalancers.push(balancer);
13064: }
1.150 raeburn 13065: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 13066: var ishomedom = homedoms[lonhostitem.selectedIndex];
13067: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13068: }
1.160.6.7 raeburn 13069: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13070: return;
13071: }
13072:
1.160.6.7 raeburn 13073: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13074: var alltargets = new Array('$alltargets');
13075: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13076: var offloadtypes = new Array('primary','default');
13077:
1.160.6.7 raeburn 13078: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13079: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13080:
1.151 raeburn 13081: for (var i=0; i<offloadtypes.length; i++) {
13082: var count = 0;
13083: for (var j=0; j<alltargets.length; j++) {
13084: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 13085: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13086: item.value = alltargets[j];
13087: item.style.textAlign='left';
13088: item.style.textFace='normal';
13089: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13090: if (currBalancers.indexOf(alltargets[j]) == -1) {
13091: item.disabled = '';
13092: } else {
13093: item.disabled = 'disabled';
13094: item.checked = false;
13095: }
1.151 raeburn 13096: count ++;
13097: }
1.150 raeburn 13098: }
13099: }
1.151 raeburn 13100: for (var k=0; k<insttypes.length; k++) {
13101: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13102: if (ishomedom == 1) {
1.160.6.7 raeburn 13103: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13104: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13105: } else {
1.160.6.7 raeburn 13106: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13107: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13108: }
13109: } else {
1.160.6.7 raeburn 13110: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13111: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13112: }
1.151 raeburn 13113: if ((insttypes[k] != '_LC_external') &&
13114: ((insttypes[k] != '_LC_internetdom') ||
13115: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 13116: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13117: item.options.length = 0;
13118: item.options[0] = new Option("","",true,true);
13119: var idx = 0;
1.151 raeburn 13120: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 13121: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13122: idx ++;
13123: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13124: }
13125: }
13126: }
13127: }
13128: return;
13129: }
13130:
1.160.6.7 raeburn 13131: function hideSpares(balnum) {
1.150 raeburn 13132: var alltargets = new Array('$alltargets');
13133: var insttypes = new Array('$allinsttypes');
13134: var offloadtypes = new Array('primary','default');
13135:
1.160.6.7 raeburn 13136: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13137: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13138:
13139: var total = alltargets.length - 1;
13140: for (var i=0; i<offloadtypes; i++) {
13141: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 13142: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13143: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13144: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13145: }
1.150 raeburn 13146: }
13147: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 13148: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13149: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13150: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 13151: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13152: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13153: }
13154: }
13155: return;
13156: }
13157:
1.160.6.7 raeburn 13158: function checkOffloads(item,balnum,type) {
1.150 raeburn 13159: var alltargets = new Array('$alltargets');
13160: var offloadtypes = new Array('primary','default');
13161: if (item.checked) {
13162: var total = alltargets.length - 1;
13163: var other;
13164: if (type == offloadtypes[0]) {
1.151 raeburn 13165: other = offloadtypes[1];
1.150 raeburn 13166: } else {
1.151 raeburn 13167: other = offloadtypes[0];
1.150 raeburn 13168: }
13169: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 13170: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13171: if (server == item.value) {
1.160.6.7 raeburn 13172: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13173: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13174: }
13175: }
13176: }
13177: }
13178: return;
13179: }
13180:
1.160.6.7 raeburn 13181: function singleServerToggle(balnum,type) {
13182: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13183: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 13184: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13185: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13186:
13187: } else {
1.160.6.7 raeburn 13188: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13189: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13190: }
13191: return;
13192: }
13193:
1.160.6.7 raeburn 13194: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13195: if (type == '_LC_external') {
1.160.6.26 raeburn 13196: return;
1.150 raeburn 13197: }
1.160.6.7 raeburn 13198: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13199: for (var i=0; i<typesRules.length; i++) {
13200: if (formname.elements[typesRules[i]].checked) {
13201: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 13202: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13203: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13204: } else {
1.160.6.7 raeburn 13205: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13206: }
13207: }
13208: }
13209: return;
13210: }
13211:
13212: function balancerDeleteChange(balnum) {
13213: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13214: var baltotal = document.getElementById('loadbalancing_total').value;
13215: var addtarget;
13216: var removetarget;
13217: var action = 'delete';
13218: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13219: var lonhost = hostitem.value;
13220: var currIdx = currBalancers.indexOf(lonhost);
13221: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13222: if (currIdx != -1) {
13223: currBalancers.splice(currIdx,1);
13224: }
13225: addtarget = lonhost;
13226: } else {
13227: if (currIdx == -1) {
13228: currBalancers.push(lonhost);
13229: }
13230: removetarget = lonhost;
13231: action = 'undelete';
13232: }
13233: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13234: }
13235: return;
13236: }
13237:
13238: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13239: if (baltotal > 1) {
13240: var offloadtypes = new Array('primary','default');
13241: var alltargets = new Array('$alltargets');
13242: var insttypes = new Array('$allinsttypes');
13243: for (var i=0; i<baltotal; i++) {
13244: if (i != balnum) {
13245: for (var j=0; j<offloadtypes.length; j++) {
13246: var total = alltargets.length - 1;
13247: for (var k=0; k<total; k++) {
13248: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13249: var server = serveritem.value;
13250: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13251: if (server == addtarget) {
13252: serveritem.disabled = '';
13253: }
13254: }
13255: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13256: if (server == removetarget) {
13257: serveritem.disabled = 'disabled';
13258: serveritem.checked = false;
13259: }
13260: }
13261: }
13262: }
13263: for (var j=0; j<insttypes.length; j++) {
13264: if (insttypes[j] != '_LC_external') {
13265: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13266: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13267: var currSel = singleserver.selectedIndex;
13268: var currVal = singleserver.options[currSel].value;
13269: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13270: var numoptions = singleserver.options.length;
13271: var needsnew = 1;
13272: for (var k=0; k<numoptions; k++) {
13273: if (singleserver.options[k] == addtarget) {
13274: needsnew = 0;
13275: break;
13276: }
13277: }
13278: if (needsnew == 1) {
13279: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13280: }
13281: }
13282: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13283: singleserver.options.length = 0;
13284: if ((currVal) && (currVal != removetarget)) {
13285: singleserver.options[0] = new Option("","",false,false);
13286: } else {
13287: singleserver.options[0] = new Option("","",true,true);
13288: }
13289: var idx = 0;
13290: for (var m=0; m<alltargets.length; m++) {
13291: if (currBalancers.indexOf(alltargets[m]) == -1) {
13292: idx ++;
13293: if (currVal == alltargets[m]) {
13294: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13295: } else {
13296: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13297: }
13298: }
13299: }
13300: }
13301: }
13302: }
13303: }
1.150 raeburn 13304: }
13305: }
13306: }
13307: return;
13308: }
13309:
1.152 raeburn 13310: // ]]>
13311: </script>
13312:
13313: END
13314: }
13315:
13316: sub new_spares_js {
13317: my @sparestypes = ('primary','default');
13318: my $types = join("','",@sparestypes);
13319: my $select = &mt('Select');
13320: return <<"END";
13321:
13322: <script type="text/javascript">
13323: // <![CDATA[
13324:
13325: function updateNewSpares(formname,lonhost) {
13326: var types = new Array('$types');
13327: var include = new Array();
13328: var exclude = new Array();
13329: for (var i=0; i<types.length; i++) {
13330: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13331: for (var j=0; j<spareboxes.length; j++) {
13332: if (formname.elements[spareboxes[j]].checked) {
13333: exclude.push(formname.elements[spareboxes[j]].value);
13334: } else {
13335: include.push(formname.elements[spareboxes[j]].value);
13336: }
13337: }
13338: }
13339: for (var i=0; i<types.length; i++) {
13340: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13341: var selIdx = newSpare.selectedIndex;
13342: var currnew = newSpare.options[selIdx].value;
13343: var okSpares = new Array();
13344: for (var j=0; j<newSpare.options.length; j++) {
13345: var possible = newSpare.options[j].value;
13346: if (possible != '') {
13347: if (exclude.indexOf(possible) == -1) {
13348: okSpares.push(possible);
13349: } else {
13350: if (currnew == possible) {
13351: selIdx = 0;
13352: }
13353: }
13354: }
13355: }
13356: for (var k=0; k<include.length; k++) {
13357: if (okSpares.indexOf(include[k]) == -1) {
13358: okSpares.push(include[k]);
13359: }
13360: }
13361: okSpares.sort();
13362: newSpare.options.length = 0;
13363: if (selIdx == 0) {
13364: newSpare.options[0] = new Option("$select","",true,true);
13365: } else {
13366: newSpare.options[0] = new Option("$select","",false,false);
13367: }
13368: for (var m=0; m<okSpares.length; m++) {
13369: var idx = m+1;
13370: var selThis = 0;
13371: if (selIdx != 0) {
13372: if (okSpares[m] == currnew) {
13373: selThis = 1;
13374: }
13375: }
13376: if (selThis == 1) {
13377: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13378: } else {
13379: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13380: }
13381: }
13382: }
13383: return;
13384: }
13385:
13386: function checkNewSpares(lonhost,type) {
13387: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13388: var chosen = newSpare.options[newSpare.selectedIndex].value;
13389: if (chosen != '') {
13390: var othertype;
13391: var othernewSpare;
13392: if (type == 'primary') {
13393: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13394: }
13395: if (type == 'default') {
13396: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13397: }
13398: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13399: othernewSpare.selectedIndex = 0;
13400: }
13401: }
13402: return;
13403: }
13404:
13405: // ]]>
13406: </script>
13407:
13408: END
13409:
13410: }
13411:
13412: sub common_domprefs_js {
13413: return <<"END";
13414:
13415: <script type="text/javascript">
13416: // <![CDATA[
13417:
1.150 raeburn 13418: function getIndicesByName(formname,item) {
1.152 raeburn 13419: var group = new Array();
1.150 raeburn 13420: for (var i=0;i<formname.elements.length;i++) {
13421: if (formname.elements[i].name == item) {
1.152 raeburn 13422: group.push(formname.elements[i].id);
1.150 raeburn 13423: }
13424: }
1.152 raeburn 13425: return group;
1.150 raeburn 13426: }
13427:
13428: // ]]>
13429: </script>
13430:
13431: END
1.152 raeburn 13432:
1.150 raeburn 13433: }
13434:
1.160.6.5 raeburn 13435: sub recaptcha_js {
13436: my %lt = &captcha_phrases();
13437: return <<"END";
13438:
13439: <script type="text/javascript">
13440: // <![CDATA[
13441:
13442: function updateCaptcha(caller,context) {
13443: var privitem;
13444: var pubitem;
13445: var privtext;
13446: var pubtext;
1.160.6.69 raeburn 13447: var versionitem;
13448: var versiontext;
1.160.6.5 raeburn 13449: if (document.getElementById(context+'_recaptchapub')) {
13450: pubitem = document.getElementById(context+'_recaptchapub');
13451: } else {
13452: return;
13453: }
13454: if (document.getElementById(context+'_recaptchapriv')) {
13455: privitem = document.getElementById(context+'_recaptchapriv');
13456: } else {
13457: return;
13458: }
13459: if (document.getElementById(context+'_recaptchapubtxt')) {
13460: pubtext = document.getElementById(context+'_recaptchapubtxt');
13461: } else {
13462: return;
13463: }
13464: if (document.getElementById(context+'_recaptchaprivtxt')) {
13465: privtext = document.getElementById(context+'_recaptchaprivtxt');
13466: } else {
13467: return;
13468: }
1.160.6.69 raeburn 13469: if (document.getElementById(context+'_recaptchaversion')) {
13470: versionitem = document.getElementById(context+'_recaptchaversion');
13471: } else {
13472: return;
13473: }
13474: if (document.getElementById(context+'_recaptchavertxt')) {
13475: versiontext = document.getElementById(context+'_recaptchavertxt');
13476: } else {
13477: return;
13478: }
1.160.6.5 raeburn 13479: if (caller.checked) {
13480: if (caller.value == 'recaptcha') {
13481: pubitem.type = 'text';
13482: privitem.type = 'text';
13483: pubitem.size = '40';
13484: privitem.size = '40';
13485: pubtext.innerHTML = "$lt{'pub'}";
13486: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 13487: versionitem.type = 'text';
13488: versionitem.size = '3';
13489: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 13490: } else {
13491: pubitem.type = 'hidden';
13492: privitem.type = 'hidden';
1.160.6.69 raeburn 13493: versionitem.type = 'hidden';
1.160.6.5 raeburn 13494: pubtext.innerHTML = '';
13495: privtext.innerHTML = '';
1.160.6.69 raeburn 13496: versiontext.innerHTML = '';
1.160.6.5 raeburn 13497: }
13498: }
13499: return;
13500: }
13501:
13502: // ]]>
13503: </script>
13504:
13505: END
13506:
13507: }
13508:
1.160.6.40 raeburn 13509: sub toggle_display_js {
1.160.6.16 raeburn 13510: return <<"END";
13511:
13512: <script type="text/javascript">
13513: // <![CDATA[
13514:
1.160.6.40 raeburn 13515: function toggleDisplay(domForm,caller) {
13516: if (document.getElementById(caller)) {
13517: var divitem = document.getElementById(caller);
13518: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 13519: var checkval = 1;
13520: var dispval = 'block';
1.160.6.40 raeburn 13521: if (caller == 'emailoptions') {
13522: optionsElement = domForm.cancreate_email;
13523: }
1.160.6.57 raeburn 13524: if (caller == 'studentsubmission') {
13525: optionsElement = domForm.postsubmit;
13526: }
1.160.6.64 raeburn 13527: if (caller == 'cloneinstcode') {
13528: optionsElement = domForm.canclone;
13529: checkval = 'instcode';
13530: }
1.160.6.40 raeburn 13531: if (optionsElement.length) {
1.160.6.16 raeburn 13532: var currval;
1.160.6.40 raeburn 13533: for (var i=0; i<optionsElement.length; i++) {
13534: if (optionsElement[i].checked) {
13535: currval = optionsElement[i].value;
1.160.6.16 raeburn 13536: }
13537: }
1.160.6.64 raeburn 13538: if (currval == checkval) {
13539: divitem.style.display = dispval;
1.160.6.16 raeburn 13540: } else {
1.160.6.40 raeburn 13541: divitem.style.display = 'none';
1.160.6.16 raeburn 13542: }
13543: }
13544: }
13545: return;
13546: }
13547:
13548: // ]]>
13549: </script>
13550:
13551: END
13552:
13553: }
13554:
1.160.6.5 raeburn 13555: sub captcha_phrases {
13556: return &Apache::lonlocal::texthash (
13557: priv => 'Private key',
13558: pub => 'Public key',
13559: original => 'original (CAPTCHA)',
13560: recaptcha => 'successor (ReCAPTCHA)',
13561: notused => 'unused',
1.160.6.69 raeburn 13562: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 13563: );
13564: }
13565:
1.160.6.24 raeburn 13566: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 13567: my ($dom,$cachekeys) = @_;
13568: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 13569: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13570: my %thismachine;
13571: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.81 raeburn 13572: my @posscached = ('domainconfig','domdefaults','usersessions','directorysrch');
1.160.6.61 raeburn 13573: if (keys(%servers)) {
1.160.6.24 raeburn 13574: foreach my $server (keys(%servers)) {
13575: next if ($thismachine{$server});
1.160.6.27 raeburn 13576: my @cached;
13577: foreach my $name (@posscached) {
13578: if ($cachekeys->{$name}) {
13579: push(@cached,&escape($name).':'.&escape($dom));
13580: }
13581: }
13582: if (@cached) {
13583: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13584: }
1.160.6.24 raeburn 13585: }
13586: }
13587: return;
13588: }
13589:
1.3 raeburn 13590: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>