Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.91
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.91! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.90 2019/02/15 21:18:32 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;
1.160.6.88 raeburn 1524: my @args = ('convert','-sample',$size,$input,$output);
1525: system({$args[0]} @args);
1.159 raeburn 1526: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1527: }
1528: }
1.6 raeburn 1529: }
1530: }
1.16 raeburn 1531: }
1.6 raeburn 1532: if ($showfile) {
1.40 raeburn 1533: if ($showfile =~ m{^/(adm|res)/}) {
1534: if ($showfile =~ m{^/res/}) {
1535: my $local_showfile =
1536: &Apache::lonnet::filelocation('',$showfile);
1537: &Apache::lonnet::repcopy($local_showfile);
1538: }
1539: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1540: }
1541: if ($imgfile) {
1542: if ($imgfile =~ m{^/(adm|res)/}) {
1543: if ($imgfile =~ m{^/res/}) {
1544: my $local_imgfile =
1545: &Apache::lonnet::filelocation('',$imgfile);
1546: &Apache::lonnet::repcopy($local_imgfile);
1547: }
1548: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1549: } else {
1550: $fullsize = $imgfile;
1551: }
1552: }
1.41 raeburn 1553: $datatable .= '<td>';
1554: if ($img eq 'login') {
1.135 bisitz 1555: $datatable .= $login_hdr_pick;
1556: }
1.41 raeburn 1557: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1558: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1559: } else {
1.160.6.22 raeburn 1560: $datatable .= '<td> </td><td class="LC_left_item">'.
1561: &mt('Upload:').'<br />';
1.6 raeburn 1562: }
1563: } else {
1.160.6.22 raeburn 1564: $datatable .= '<td> </td><td class="LC_left_item">'.
1565: &mt('Upload:').'<br />';
1.6 raeburn 1566: }
1.9 raeburn 1567: if ($switchserver) {
1568: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1569: } else {
1.135 bisitz 1570: if ($img ne 'login') { # suppress file selection for Log-in header
1571: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1572: }
1.9 raeburn 1573: }
1574: $datatable .= '</td></tr>';
1.6 raeburn 1575: }
1576: $itemcount ++;
1577: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1578: $datatable .= '<tr'.$css_class.'>'.
1579: '<td>'.$choices->{'bgs'}.'</td>';
1580: my $bgs_def;
1581: foreach my $item (@{$bgs}) {
1582: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1583: $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 1584: }
1585: }
1586: if ($bgs_def) {
1.8 raeburn 1587: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1588: } else {
1589: $datatable .= '<td> </td>';
1590: }
1591: $datatable .= '<td class="LC_right_item">'.
1592: '<table border="0"><tr>';
1.160.6.13 raeburn 1593:
1.6 raeburn 1594: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 1595: $datatable .= '<td align="center">'.$choices->{$item};
1596: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1597: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 1598: $datatable .= ' ';
1.6 raeburn 1599: }
1.160.6.9 raeburn 1600: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1601: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1602: }
1603: $datatable .= '</tr></table></td></tr>';
1604: $itemcount ++;
1605: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1606: $datatable .= '<tr'.$css_class.'>'.
1607: '<td>'.$choices->{'links'}.'</td>';
1608: my $links_def;
1609: foreach my $item (@{$links}) {
1610: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 1611: $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 1612: }
1613: }
1614: if ($links_def) {
1.8 raeburn 1615: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1616: } else {
1617: $datatable .= '<td> </td>';
1618: }
1619: $datatable .= '<td class="LC_right_item">'.
1620: '<table border="0"><tr>';
1621: foreach my $item (@{$links}) {
1.160.6.39 raeburn 1622: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 1623: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1624: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 1625: $datatable.=' ';
1.6 raeburn 1626: }
1.160.6.9 raeburn 1627: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1628: '" /></td>';
1629: }
1.30 raeburn 1630: $$rowtotal += $itemcount;
1.3 raeburn 1631: return $datatable;
1632: }
1633:
1.70 raeburn 1634: sub logo_display_options {
1635: my ($img,$defaults,$designs) = @_;
1636: my $checkedon;
1637: if (ref($defaults) eq 'HASH') {
1638: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1639: if ($defaults->{'showlogo'}{$img}) {
1640: $checkedon = 'checked="checked" ';
1641: }
1642: }
1643: }
1644: if (ref($designs) eq 'HASH') {
1645: if (ref($designs->{'showlogo'}) eq 'HASH') {
1646: if (defined($designs->{'showlogo'}{$img})) {
1647: if ($designs->{'showlogo'}{$img} == 0) {
1648: $checkedon = '';
1649: } elsif ($designs->{'showlogo'}{$img} == 1) {
1650: $checkedon = 'checked="checked" ';
1651: }
1652: }
1653: }
1654: }
1655: return '<br /><label> <input type="checkbox" name="'.
1656: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1657: &mt('show').'</label>'."\n";
1658: }
1659:
1.41 raeburn 1660: sub login_header_options {
1.135 bisitz 1661: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1662: my $output = '';
1.41 raeburn 1663: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1664: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1665: if (!$is_custom->{'textcol'}) {
1666: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1667: ' ';
1668: }
1669: if (!$is_custom->{'bgcol'}) {
1670: $output .= $choices->{'bgcol'}.': '.
1671: '<span id="css_'.$role.'_font" style="background-color: '.
1672: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1673: }
1674: $output .= '<br />';
1675: }
1676: $output .='<br />';
1677: return $output;
1678: }
1679:
1680: sub login_text_colors {
1.160.6.22 raeburn 1681: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1682: my $color_menu = '<table border="0"><tr>';
1683: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 1684: $color_menu .= '<td align="center">'.$choices->{$item};
1685: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1686: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1687: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1688: }
1689: $color_menu .= '</tr></table><br />';
1690: return $color_menu;
1691: }
1692:
1693: sub image_changes {
1694: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1695: my $output;
1.135 bisitz 1696: if ($img eq 'login') {
1.160.6.87 raeburn 1697: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 1698: } elsif (!$is_custom) {
1.70 raeburn 1699: if ($img ne 'domlogo') {
1.160.6.87 raeburn 1700: $output = &mt('Default image:').'<br />';
1.41 raeburn 1701: } else {
1.160.6.87 raeburn 1702: $output = &mt('Default in use:').'<br />';
1.41 raeburn 1703: }
1704: }
1.160.6.87 raeburn 1705: if ($img ne 'login') {
1.135 bisitz 1706: if ($img_import) {
1707: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1708: }
1709: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1710: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1711: if ($is_custom) {
1712: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1713: '<input type="checkbox" name="'.
1714: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1715: '</label> '.&mt('Replace:').'</span><br />';
1716: } else {
1.160.6.22 raeburn 1717: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1718: }
1.41 raeburn 1719: }
1720: return $output;
1721: }
1722:
1.3 raeburn 1723: sub print_quotas {
1.86 raeburn 1724: my ($dom,$settings,$rowtotal,$action) = @_;
1725: my $context;
1726: if ($action eq 'quotas') {
1727: $context = 'tools';
1728: } else {
1729: $context = $action;
1730: }
1.160.6.20 raeburn 1731: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1732: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1733: my $typecount = 0;
1.101 raeburn 1734: my ($css_class,%titles);
1.86 raeburn 1735: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 1736: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 1737: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1738: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1739: %titles = &courserequest_titles();
1.160.6.5 raeburn 1740: } elsif ($context eq 'requestauthor') {
1741: @usertools = ('author');
1742: @options = ('norequest','approval','automatic');
1743: %titles = &authorrequest_titles();
1.86 raeburn 1744: } else {
1.160.6.4 raeburn 1745: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1746: %titles = &tool_titles();
1.86 raeburn 1747: }
1.26 raeburn 1748: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1749: foreach my $type (@{$types}) {
1.160.6.20 raeburn 1750: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 1751: unless (($context eq 'requestcourses') ||
1752: ($context eq 'requestauthor')) {
1.86 raeburn 1753: if (ref($settings) eq 'HASH') {
1754: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 1755: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1756: } else {
1757: $currdefquota = $settings->{$type};
1758: }
1.160.6.20 raeburn 1759: if (ref($settings->{authorquota}) eq 'HASH') {
1760: $currauthorquota = $settings->{authorquota}->{$type};
1761: }
1.78 raeburn 1762: }
1.72 raeburn 1763: }
1.3 raeburn 1764: if (defined($usertypes->{$type})) {
1765: $typecount ++;
1766: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1767: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1768: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1769: '<td class="LC_left_item">';
1.101 raeburn 1770: if ($context eq 'requestcourses') {
1771: $datatable .= '<table><tr>';
1772: }
1773: my %cell;
1.72 raeburn 1774: foreach my $item (@usertools) {
1.101 raeburn 1775: if ($context eq 'requestcourses') {
1776: my ($curroption,$currlimit);
1777: if (ref($settings) eq 'HASH') {
1778: if (ref($settings->{$item}) eq 'HASH') {
1779: $curroption = $settings->{$item}->{$type};
1780: if ($curroption =~ /^autolimit=(\d*)$/) {
1781: $currlimit = $1;
1782: }
1783: }
1784: }
1785: if (!$curroption) {
1786: $curroption = 'norequest';
1787: }
1788: $datatable .= '<th>'.$titles{$item}.'</th>';
1789: foreach my $option (@options) {
1790: my $val = $option;
1791: if ($option eq 'norequest') {
1792: $val = 0;
1793: }
1794: if ($option eq 'validate') {
1795: my $canvalidate = 0;
1796: if (ref($validations{$item}) eq 'HASH') {
1797: if ($validations{$item}{$type}) {
1798: $canvalidate = 1;
1799: }
1800: }
1801: next if (!$canvalidate);
1802: }
1803: my $checked = '';
1804: if ($option eq $curroption) {
1805: $checked = ' checked="checked"';
1806: } elsif ($option eq 'autolimit') {
1807: if ($curroption =~ /^autolimit/) {
1808: $checked = ' checked="checked"';
1809: }
1810: }
1811: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1812: '<input type="radio" name="crsreq_'.$item.
1813: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1814: $titles{$option}.'</label>';
1.101 raeburn 1815: if ($option eq 'autolimit') {
1.127 raeburn 1816: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1817: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1818: 'value="'.$currlimit.'" />';
1.101 raeburn 1819: }
1.127 raeburn 1820: $cell{$item} .= '</span> ';
1.103 raeburn 1821: if ($option eq 'autolimit') {
1.127 raeburn 1822: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1823: }
1.101 raeburn 1824: }
1.160.6.5 raeburn 1825: } elsif ($context eq 'requestauthor') {
1826: my $curroption;
1827: if (ref($settings) eq 'HASH') {
1828: $curroption = $settings->{$type};
1829: }
1830: if (!$curroption) {
1831: $curroption = 'norequest';
1832: }
1833: foreach my $option (@options) {
1834: my $val = $option;
1835: if ($option eq 'norequest') {
1836: $val = 0;
1837: }
1838: my $checked = '';
1839: if ($option eq $curroption) {
1840: $checked = ' checked="checked"';
1841: }
1842: $datatable .= '<span class="LC_nobreak"><label>'.
1843: '<input type="radio" name="authorreq_'.$type.
1844: '" value="'.$val.'"'.$checked.' />'.
1845: $titles{$option}.'</label></span> ';
1846: }
1.101 raeburn 1847: } else {
1848: my $checked = 'checked="checked" ';
1849: if (ref($settings) eq 'HASH') {
1850: if (ref($settings->{$item}) eq 'HASH') {
1851: if ($settings->{$item}->{$type} == 0) {
1852: $checked = '';
1853: } elsif ($settings->{$item}->{$type} == 1) {
1854: $checked = 'checked="checked" ';
1855: }
1.78 raeburn 1856: }
1.72 raeburn 1857: }
1.101 raeburn 1858: $datatable .= '<span class="LC_nobreak"><label>'.
1859: '<input type="checkbox" name="'.$context.'_'.$item.
1860: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1861: '</label></span> ';
1.72 raeburn 1862: }
1.101 raeburn 1863: }
1864: if ($context eq 'requestcourses') {
1865: $datatable .= '</tr><tr>';
1866: foreach my $item (@usertools) {
1.106 raeburn 1867: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1868: }
1869: $datatable .= '</tr></table>';
1.72 raeburn 1870: }
1.86 raeburn 1871: $datatable .= '</td>';
1.160.6.5 raeburn 1872: unless (($context eq 'requestcourses') ||
1873: ($context eq 'requestauthor')) {
1.86 raeburn 1874: $datatable .=
1.160.6.20 raeburn 1875: '<td class="LC_right_item">'.
1876: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1877: '<input type="text" name="quota_'.$type.
1.72 raeburn 1878: '" value="'.$currdefquota.
1.160.6.20 raeburn 1879: '" size="5" /></span>'.(' ' x 2).
1880: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1881: '<input type="text" name="authorquota_'.$type.
1882: '" value="'.$currauthorquota.
1883: '" size="5" /></span></td>';
1.86 raeburn 1884: }
1885: $datatable .= '</tr>';
1.3 raeburn 1886: }
1887: }
1888: }
1.160.6.5 raeburn 1889: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1890: $defaultquota = '20';
1.160.6.20 raeburn 1891: $authorquota = '500';
1.86 raeburn 1892: if (ref($settings) eq 'HASH') {
1893: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1894: $defaultquota = $settings->{'defaultquota'}->{'default'};
1895: } elsif (defined($settings->{'default'})) {
1896: $defaultquota = $settings->{'default'};
1897: }
1.160.6.20 raeburn 1898: if (ref($settings->{'authorquota'}) eq 'HASH') {
1899: $authorquota = $settings->{'authorquota'}->{'default'};
1900: }
1.3 raeburn 1901: }
1902: }
1903: $typecount ++;
1904: $css_class = $typecount%2?' class="LC_odd_row"':'';
1905: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1906: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1907: '<td class="LC_left_item">';
1.101 raeburn 1908: if ($context eq 'requestcourses') {
1909: $datatable .= '<table><tr>';
1910: }
1911: my %defcell;
1.72 raeburn 1912: foreach my $item (@usertools) {
1.101 raeburn 1913: if ($context eq 'requestcourses') {
1914: my ($curroption,$currlimit);
1915: if (ref($settings) eq 'HASH') {
1916: if (ref($settings->{$item}) eq 'HASH') {
1917: $curroption = $settings->{$item}->{'default'};
1918: if ($curroption =~ /^autolimit=(\d*)$/) {
1919: $currlimit = $1;
1920: }
1921: }
1922: }
1923: if (!$curroption) {
1924: $curroption = 'norequest';
1925: }
1926: $datatable .= '<th>'.$titles{$item}.'</th>';
1927: foreach my $option (@options) {
1928: my $val = $option;
1929: if ($option eq 'norequest') {
1930: $val = 0;
1931: }
1932: if ($option eq 'validate') {
1933: my $canvalidate = 0;
1934: if (ref($validations{$item}) eq 'HASH') {
1935: if ($validations{$item}{'default'}) {
1936: $canvalidate = 1;
1937: }
1938: }
1939: next if (!$canvalidate);
1940: }
1941: my $checked = '';
1942: if ($option eq $curroption) {
1943: $checked = ' checked="checked"';
1944: } elsif ($option eq 'autolimit') {
1945: if ($curroption =~ /^autolimit/) {
1946: $checked = ' checked="checked"';
1947: }
1948: }
1949: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1950: '<input type="radio" name="crsreq_'.$item.
1951: '_default" value="'.$val.'"'.$checked.' />'.
1952: $titles{$option}.'</label>';
1953: if ($option eq 'autolimit') {
1.127 raeburn 1954: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1955: $item.'_limit_default" size="1" '.
1956: 'value="'.$currlimit.'" />';
1957: }
1.127 raeburn 1958: $defcell{$item} .= '</span> ';
1.104 raeburn 1959: if ($option eq 'autolimit') {
1.127 raeburn 1960: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1961: }
1.101 raeburn 1962: }
1.160.6.5 raeburn 1963: } elsif ($context eq 'requestauthor') {
1964: my $curroption;
1965: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 1966: $curroption = $settings->{'default'};
1.160.6.5 raeburn 1967: }
1968: if (!$curroption) {
1969: $curroption = 'norequest';
1970: }
1971: foreach my $option (@options) {
1972: my $val = $option;
1973: if ($option eq 'norequest') {
1974: $val = 0;
1975: }
1976: my $checked = '';
1977: if ($option eq $curroption) {
1978: $checked = ' checked="checked"';
1979: }
1980: $datatable .= '<span class="LC_nobreak"><label>'.
1981: '<input type="radio" name="authorreq_default"'.
1982: ' value="'.$val.'"'.$checked.' />'.
1983: $titles{$option}.'</label></span> ';
1984: }
1.101 raeburn 1985: } else {
1986: my $checked = 'checked="checked" ';
1987: if (ref($settings) eq 'HASH') {
1988: if (ref($settings->{$item}) eq 'HASH') {
1989: if ($settings->{$item}->{'default'} == 0) {
1990: $checked = '';
1991: } elsif ($settings->{$item}->{'default'} == 1) {
1992: $checked = 'checked="checked" ';
1993: }
1.78 raeburn 1994: }
1.72 raeburn 1995: }
1.101 raeburn 1996: $datatable .= '<span class="LC_nobreak"><label>'.
1997: '<input type="checkbox" name="'.$context.'_'.$item.
1998: '" value="default" '.$checked.'/>'.$titles{$item}.
1999: '</label></span> ';
2000: }
2001: }
2002: if ($context eq 'requestcourses') {
2003: $datatable .= '</tr><tr>';
2004: foreach my $item (@usertools) {
1.106 raeburn 2005: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2006: }
1.101 raeburn 2007: $datatable .= '</tr></table>';
1.72 raeburn 2008: }
1.86 raeburn 2009: $datatable .= '</td>';
1.160.6.5 raeburn 2010: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2011: $datatable .= '<td class="LC_right_item">'.
2012: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2013: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2014: $defaultquota.'" size="5" /></span>'.(' ' x2).
2015: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2016: '<input type="text" name="authorquota" value="'.
2017: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2018: }
2019: $datatable .= '</tr>';
1.72 raeburn 2020: $typecount ++;
2021: $css_class = $typecount%2?' class="LC_odd_row"':'';
2022: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2023: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2024: if ($context eq 'requestcourses') {
1.109 raeburn 2025: $datatable .= &mt('(overrides affiliation, if set)').
2026: '</td>'.
2027: '<td class="LC_left_item">'.
2028: '<table><tr>';
1.101 raeburn 2029: } else {
1.109 raeburn 2030: $datatable .= &mt('(overrides affiliation, if checked)').
2031: '</td>'.
2032: '<td class="LC_left_item" colspan="2">'.
2033: '<br />';
1.101 raeburn 2034: }
2035: my %advcell;
1.72 raeburn 2036: foreach my $item (@usertools) {
1.101 raeburn 2037: if ($context eq 'requestcourses') {
2038: my ($curroption,$currlimit);
2039: if (ref($settings) eq 'HASH') {
2040: if (ref($settings->{$item}) eq 'HASH') {
2041: $curroption = $settings->{$item}->{'_LC_adv'};
2042: if ($curroption =~ /^autolimit=(\d*)$/) {
2043: $currlimit = $1;
2044: }
2045: }
2046: }
2047: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2048: my $checked = '';
2049: if ($curroption eq '') {
2050: $checked = ' checked="checked"';
2051: }
2052: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2053: '<input type="radio" name="crsreq_'.$item.
2054: '__LC_adv" value=""'.$checked.' />'.
2055: &mt('No override set').'</label></span> ';
1.101 raeburn 2056: foreach my $option (@options) {
2057: my $val = $option;
2058: if ($option eq 'norequest') {
2059: $val = 0;
2060: }
2061: if ($option eq 'validate') {
2062: my $canvalidate = 0;
2063: if (ref($validations{$item}) eq 'HASH') {
2064: if ($validations{$item}{'_LC_adv'}) {
2065: $canvalidate = 1;
2066: }
2067: }
2068: next if (!$canvalidate);
2069: }
2070: my $checked = '';
1.104 raeburn 2071: if ($val eq $curroption) {
1.101 raeburn 2072: $checked = ' checked="checked"';
2073: } elsif ($option eq 'autolimit') {
2074: if ($curroption =~ /^autolimit/) {
2075: $checked = ' checked="checked"';
2076: }
2077: }
2078: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2079: '<input type="radio" name="crsreq_'.$item.
2080: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2081: $titles{$option}.'</label>';
2082: if ($option eq 'autolimit') {
1.127 raeburn 2083: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2084: $item.'_limit__LC_adv" size="1" '.
2085: 'value="'.$currlimit.'" />';
2086: }
1.127 raeburn 2087: $advcell{$item} .= '</span> ';
1.104 raeburn 2088: if ($option eq 'autolimit') {
1.127 raeburn 2089: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2090: }
1.101 raeburn 2091: }
1.160.6.5 raeburn 2092: } elsif ($context eq 'requestauthor') {
2093: my $curroption;
2094: if (ref($settings) eq 'HASH') {
2095: $curroption = $settings->{'_LC_adv'};
2096: }
2097: my $checked = '';
2098: if ($curroption eq '') {
2099: $checked = ' checked="checked"';
2100: }
2101: $datatable .= '<span class="LC_nobreak"><label>'.
2102: '<input type="radio" name="authorreq__LC_adv"'.
2103: ' value=""'.$checked.' />'.
2104: &mt('No override set').'</label></span> ';
2105: foreach my $option (@options) {
2106: my $val = $option;
2107: if ($option eq 'norequest') {
2108: $val = 0;
2109: }
2110: my $checked = '';
2111: if ($val eq $curroption) {
2112: $checked = ' checked="checked"';
2113: }
2114: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2115: '<input type="radio" name="authorreq__LC_adv"'.
2116: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2117: $titles{$option}.'</label></span> ';
2118: }
1.101 raeburn 2119: } else {
2120: my $checked = 'checked="checked" ';
2121: if (ref($settings) eq 'HASH') {
2122: if (ref($settings->{$item}) eq 'HASH') {
2123: if ($settings->{$item}->{'_LC_adv'} == 0) {
2124: $checked = '';
2125: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2126: $checked = 'checked="checked" ';
2127: }
1.79 raeburn 2128: }
1.72 raeburn 2129: }
1.101 raeburn 2130: $datatable .= '<span class="LC_nobreak"><label>'.
2131: '<input type="checkbox" name="'.$context.'_'.$item.
2132: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2133: '</label></span> ';
2134: }
2135: }
2136: if ($context eq 'requestcourses') {
2137: $datatable .= '</tr><tr>';
2138: foreach my $item (@usertools) {
1.106 raeburn 2139: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2140: }
1.101 raeburn 2141: $datatable .= '</tr></table>';
1.72 raeburn 2142: }
1.98 raeburn 2143: $datatable .= '</td></tr>';
1.30 raeburn 2144: $$rowtotal += $typecount;
1.3 raeburn 2145: return $datatable;
2146: }
2147:
1.160.6.5 raeburn 2148: sub print_requestmail {
2149: my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25 raeburn 2150: my ($now,$datatable,%currapp);
1.102 raeburn 2151: $now = time;
2152: if (ref($settings) eq 'HASH') {
2153: if (ref($settings->{'notify'}) eq 'HASH') {
2154: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2155: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2156: }
2157: }
2158: }
1.160.6.16 raeburn 2159: my $numinrow = 2;
1.160.6.34 raeburn 2160: my $css_class;
2161: $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5 raeburn 2162: my $text;
2163: if ($action eq 'requestcourses') {
2164: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2165: } elsif ($action eq 'requestauthor') {
2166: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2167: } else {
1.160.6.34 raeburn 2168: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2169: }
1.160.6.34 raeburn 2170: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2171: ' <td>'.$text.'</td>'.
1.102 raeburn 2172: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2173: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2174: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2175: if ($numdc > 0) {
2176: $datatable .= $table;
1.102 raeburn 2177: } else {
2178: $datatable .= &mt('There are no active Domain Coordinators');
2179: }
2180: $datatable .='</td></tr>';
2181: return $datatable;
2182: }
2183:
1.160.6.30 raeburn 2184: sub print_studentcode {
2185: my ($settings,$rowtotal) = @_;
2186: my $rownum = 0;
2187: my ($output,%current);
2188: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2189: if (ref($settings) eq 'HASH') {
2190: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2191: foreach my $type (@crstypes) {
2192: $current{$type} = $settings->{'uniquecode'}{$type};
2193: }
1.160.6.30 raeburn 2194: }
2195: }
2196: $output .= '<tr>'.
2197: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2198: '<td class="LC_left_item">';
2199: foreach my $type (@crstypes) {
2200: my $check = ' ';
2201: if ($current{$type}) {
2202: $check = ' checked="checked" ';
2203: }
2204: $output .= '<span class="LC_nobreak"><label>'.
2205: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2206: &mt($type).'</label></span>'.(' 'x2).' ';
2207: }
2208: $output .= '</td></tr>';
2209: $$rowtotal ++;
2210: return $output;
2211: }
2212:
2213: sub print_textbookcourses {
1.160.6.46 raeburn 2214: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2215: my $rownum = 0;
2216: my $css_class;
2217: my $itemcount = 1;
2218: my $maxnum = 0;
2219: my $bookshash;
2220: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2221: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2222: }
2223: my %ordered;
2224: if (ref($bookshash) eq 'HASH') {
2225: foreach my $item (keys(%{$bookshash})) {
2226: if (ref($bookshash->{$item}) eq 'HASH') {
2227: my $num = $bookshash->{$item}{'order'};
2228: $ordered{$num} = $item;
2229: }
2230: }
2231: }
2232: my $confname = $dom.'-domainconfig';
2233: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2234: my $maxnum = scalar(keys(%ordered));
2235: my $datatable;
1.160.6.30 raeburn 2236: if (keys(%ordered)) {
2237: my @items = sort { $a <=> $b } keys(%ordered);
2238: for (my $i=0; $i<@items; $i++) {
2239: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2240: my $key = $ordered{$items[$i]};
2241: my %coursehash=&Apache::lonnet::coursedescription($key);
2242: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2243: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2244: if (ref($bookshash->{$key}) eq 'HASH') {
2245: $subject = $bookshash->{$key}->{'subject'};
2246: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2247: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2248: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2249: $author = $bookshash->{$key}->{'author'};
2250: $image = $bookshash->{$key}->{'image'};
2251: if ($image ne '') {
2252: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2253: my $imagethumb = "$path/tn-".$imagefile;
2254: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2255: }
1.160.6.30 raeburn 2256: }
2257: }
1.160.6.46 raeburn 2258: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2259: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2260: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2261: for (my $k=0; $k<=$maxnum; $k++) {
2262: my $vpos = $k+1;
2263: my $selstr;
2264: if ($k == $i) {
2265: $selstr = ' selected="selected" ';
2266: }
2267: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2268: }
2269: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2270: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2271: &mt('Delete?').'</label></span></td>'.
2272: '<td colspan="2">'.
1.160.6.46 raeburn 2273: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2274: (' 'x2).
1.160.6.46 raeburn 2275: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2276: if ($type eq 'textbooks') {
2277: $datatable .= (' 'x2).
1.160.6.47 raeburn 2278: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2279: (' 'x2).
1.160.6.46 raeburn 2280: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2281: (' 'x2).
2282: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2283: if ($image) {
2284: $datatable .= '<span class="LC_nobreak">'.
2285: $imgsrc.
2286: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2287: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2288: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2289: }
2290: if ($switchserver) {
2291: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2292: } else {
2293: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2294: }
1.160.6.30 raeburn 2295: }
1.160.6.46 raeburn 2296: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2297: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2298: $coursetitle.'</span></td></tr>'."\n";
2299: $itemcount ++;
2300: }
2301: }
2302: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2303: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2304: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2305: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2306: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2307: for (my $k=0; $k<$maxnum+1; $k++) {
2308: my $vpos = $k+1;
2309: my $selstr;
2310: if ($k == $maxnum) {
2311: $selstr = ' selected="selected" ';
2312: }
2313: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2314: }
2315: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2316: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2317: '<td colspan="2">'.
1.160.6.46 raeburn 2318: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2319: (' 'x2).
1.160.6.46 raeburn 2320: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2321: (' 'x2);
2322: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2323: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2324: (' 'x2).
2325: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2326: (' 'x2).
2327: '<span class="LC_nobreak">'.&mt('Image:').' ';
2328: if ($switchserver) {
2329: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2330: } else {
2331: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2332: }
1.160.6.87 raeburn 2333: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2334: }
1.160.6.87 raeburn 2335: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2336: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2337: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2338: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2339: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2340: '</span></td>'."\n".
2341: '</tr>'."\n";
2342: $itemcount ++;
2343: return $datatable;
2344: }
2345:
2346: sub textbookcourses_javascript {
1.160.6.46 raeburn 2347: my ($settings) = @_;
2348: return unless(ref($settings) eq 'HASH');
2349: my (%ordered,%total,%jstext);
2350: foreach my $type ('textbooks','templates') {
2351: $total{$type} = 0;
2352: if (ref($settings->{$type}) eq 'HASH') {
2353: foreach my $item (keys(%{$settings->{$type}})) {
2354: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2355: my $num = $settings->{$type}->{$item}{'order'};
2356: $ordered{$type}{$num} = $item;
2357: }
2358: }
2359: $total{$type} = scalar(keys(%{$settings->{$type}}));
2360: }
2361: my @jsarray = ();
2362: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2363: push(@jsarray,$ordered{$type}{$item});
2364: }
2365: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2366: }
2367: return <<"ENDSCRIPT";
2368: <script type="text/javascript">
2369: // <![CDATA[
1.160.6.46 raeburn 2370: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2371: var changedVal;
1.160.6.46 raeburn 2372: $jstext{'textbooks'};
2373: $jstext{'templates'};
2374: var newpos;
2375: var maxh;
2376: if (caller == 'textbooks') {
2377: newpos = 'textbooks_addbook_pos';
2378: maxh = 1 + $total{'textbooks'};
2379: } else {
2380: newpos = 'templates_addbook_pos';
2381: maxh = 1 + $total{'templates'};
2382: }
1.160.6.30 raeburn 2383: var current = new Array;
2384: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2385: if (item == newpos) {
2386: changedVal = newitemVal;
2387: } else {
2388: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2389: current[newitemVal] = newpos;
2390: }
1.160.6.46 raeburn 2391: if (caller == 'textbooks') {
2392: for (var i=0; i<textbooks.length; i++) {
2393: var elementName = 'textbooks_'+textbooks[i];
2394: if (elementName != item) {
2395: if (form.elements[elementName]) {
2396: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2397: current[currVal] = elementName;
2398: }
2399: }
2400: }
2401: }
2402: if (caller == 'templates') {
2403: for (var i=0; i<templates.length; i++) {
2404: var elementName = 'templates_'+templates[i];
2405: if (elementName != item) {
2406: if (form.elements[elementName]) {
2407: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2408: current[currVal] = elementName;
2409: }
1.160.6.30 raeburn 2410: }
2411: }
2412: }
2413: var oldVal;
2414: for (var j=0; j<maxh; j++) {
2415: if (current[j] == undefined) {
2416: oldVal = j;
2417: }
2418: }
2419: if (oldVal < changedVal) {
2420: for (var k=oldVal+1; k<=changedVal ; k++) {
2421: var elementName = current[k];
2422: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2423: }
2424: } else {
2425: for (var k=changedVal; k<oldVal; k++) {
2426: var elementName = current[k];
2427: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2428: }
2429: }
2430: return;
2431: }
2432:
2433: // ]]>
2434: </script>
2435:
2436: ENDSCRIPT
2437: }
2438:
1.3 raeburn 2439: sub print_autoenroll {
1.30 raeburn 2440: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2441: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68 raeburn 2442: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3 raeburn 2443: if (ref($settings) eq 'HASH') {
2444: if (exists($settings->{'run'})) {
2445: if ($settings->{'run'} eq '0') {
2446: $runoff = ' checked="checked" ';
2447: $runon = ' ';
2448: } else {
2449: $runon = ' checked="checked" ';
2450: $runoff = ' ';
2451: }
2452: } else {
2453: if ($autorun) {
2454: $runon = ' checked="checked" ';
2455: $runoff = ' ';
2456: } else {
2457: $runoff = ' checked="checked" ';
2458: $runon = ' ';
2459: }
2460: }
1.129 raeburn 2461: if (exists($settings->{'co-owners'})) {
2462: if ($settings->{'co-owners'} eq '0') {
2463: $coownersoff = ' checked="checked" ';
2464: $coownerson = ' ';
2465: } else {
2466: $coownerson = ' checked="checked" ';
2467: $coownersoff = ' ';
2468: }
2469: } else {
2470: $coownersoff = ' checked="checked" ';
2471: $coownerson = ' ';
2472: }
1.3 raeburn 2473: if (exists($settings->{'sender_domain'})) {
2474: $defdom = $settings->{'sender_domain'};
2475: }
1.160.6.68 raeburn 2476: if (exists($settings->{'autofailsafe'})) {
2477: $failsafe = $settings->{'autofailsafe'};
2478: }
1.14 raeburn 2479: } else {
2480: if ($autorun) {
2481: $runon = ' checked="checked" ';
2482: $runoff = ' ';
2483: } else {
2484: $runoff = ' checked="checked" ';
2485: $runon = ' ';
2486: }
1.3 raeburn 2487: }
2488: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2489: my $notif_sender;
2490: if (ref($settings) eq 'HASH') {
2491: $notif_sender = $settings->{'sender_uname'};
2492: }
1.3 raeburn 2493: my $datatable='<tr class="LC_odd_row">'.
2494: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2495: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2496: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2497: $runon.' value="1" />'.&mt('Yes').'</label> '.
2498: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2499: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2500: '</tr><tr>'.
2501: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2502: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2503: &mt('username').': '.
2504: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2505: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2506: ': '.$domform.'</span></td></tr>'.
2507: '<tr class="LC_odd_row">'.
2508: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2509: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2510: '<input type="radio" name="autoassign_coowners"'.
2511: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2512: '<label><input type="radio" name="autoassign_coowners"'.
2513: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 2514: '</tr><tr>'.
2515: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
2516: '<td class="LC_right_item"><span class="LC_nobreak">'.
2517: '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87 raeburn 2518: ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68 raeburn 2519: $$rowtotal += 4;
1.3 raeburn 2520: return $datatable;
2521: }
2522:
2523: sub print_autoupdate {
1.30 raeburn 2524: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2525: my $datatable;
2526: if ($position eq 'top') {
2527: my $updateon = ' ';
2528: my $updateoff = ' checked="checked" ';
2529: my $classlistson = ' ';
2530: my $classlistsoff = ' checked="checked" ';
2531: if (ref($settings) eq 'HASH') {
2532: if ($settings->{'run'} eq '1') {
2533: $updateon = $updateoff;
2534: $updateoff = ' ';
2535: }
2536: if ($settings->{'classlists'} eq '1') {
2537: $classlistson = $classlistsoff;
2538: $classlistsoff = ' ';
2539: }
2540: }
2541: my %title = (
2542: run => 'Auto-update active?',
2543: classlists => 'Update information in classlists?',
2544: );
2545: $datatable = '<tr class="LC_odd_row">'.
2546: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2547: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2548: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2549: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2550: '<label><input type="radio" name="autoupdate_run"'.
2551: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2552: '</tr><tr>'.
2553: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2554: '<td class="LC_right_item"><span class="LC_nobreak">'.
2555: '<label><input type="radio" name="classlists"'.
2556: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2557: '<label><input type="radio" name="classlists"'.
2558: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2559: '</tr>';
1.30 raeburn 2560: $$rowtotal += 2;
1.131 raeburn 2561: } elsif ($position eq 'middle') {
2562: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2563: my $numinrow = 3;
2564: my $locknamesettings;
2565: $datatable .= &insttypes_row($settings,$types,$usertypes,
2566: $dom,$numinrow,$othertitle,
2567: 'lockablenames');
2568: $$rowtotal ++;
1.3 raeburn 2569: } else {
1.44 raeburn 2570: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2571: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2572: 'permanentemail','id');
1.33 raeburn 2573: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2574: my $numrows = 0;
1.26 raeburn 2575: if (ref($types) eq 'ARRAY') {
2576: if (@{$types} > 0) {
2577: $datatable =
2578: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2579: \@fields,$types,\$numrows);
1.30 raeburn 2580: $$rowtotal += @{$types};
1.26 raeburn 2581: }
1.3 raeburn 2582: }
2583: $datatable .=
2584: &usertype_update_row($settings,{'default' => $othertitle},
2585: \%fieldtitles,\@fields,['default'],
2586: \$numrows);
1.30 raeburn 2587: $$rowtotal ++;
1.3 raeburn 2588: }
2589: return $datatable;
2590: }
2591:
1.125 raeburn 2592: sub print_autocreate {
2593: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 2594: my (%createon,%createoff,%currhash);
1.125 raeburn 2595: my @types = ('xml','req');
2596: if (ref($settings) eq 'HASH') {
2597: foreach my $item (@types) {
2598: $createoff{$item} = ' checked="checked" ';
2599: $createon{$item} = ' ';
2600: if (exists($settings->{$item})) {
2601: if ($settings->{$item}) {
2602: $createon{$item} = ' checked="checked" ';
2603: $createoff{$item} = ' ';
2604: }
2605: }
2606: }
1.160.6.16 raeburn 2607: if ($settings->{'xmldc'} ne '') {
2608: $currhash{$settings->{'xmldc'}} = 1;
2609: }
1.125 raeburn 2610: } else {
2611: foreach my $item (@types) {
2612: $createoff{$item} = ' checked="checked" ';
2613: $createon{$item} = ' ';
2614: }
2615: }
2616: $$rowtotal += 2;
1.160.6.16 raeburn 2617: my $numinrow = 2;
1.125 raeburn 2618: my $datatable='<tr class="LC_odd_row">'.
2619: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2620: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2621: '<input type="radio" name="autocreate_xml"'.
2622: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2623: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2624: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2625: '</td></tr><tr>'.
2626: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2627: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2628: '<input type="radio" name="autocreate_req"'.
2629: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2630: '<label><input type="radio" name="autocreate_req"'.
2631: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 2632: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2633: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 2634: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 2635: if ($numdc > 1) {
1.160.6.50 raeburn 2636: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
2637: '</td><td class="LC_left_item">';
1.125 raeburn 2638: } else {
1.160.6.50 raeburn 2639: $datatable .= &mt('Course creation processed as:').
2640: '</td><td class="LC_right_item">';
1.125 raeburn 2641: }
1.160.6.50 raeburn 2642: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 2643: $$rowtotal += $rows;
1.125 raeburn 2644: return $datatable;
2645: }
2646:
1.23 raeburn 2647: sub print_directorysrch {
1.160.6.72 raeburn 2648: my ($position,$dom,$settings,$rowtotal) = @_;
2649: my $datatable;
2650: if ($position eq 'top') {
2651: my $instsrchon = ' ';
2652: my $instsrchoff = ' checked="checked" ';
2653: my ($exacton,$containson,$beginson);
2654: my $instlocalon = ' ';
2655: my $instlocaloff = ' checked="checked" ';
2656: if (ref($settings) eq 'HASH') {
2657: if ($settings->{'available'} eq '1') {
2658: $instsrchon = $instsrchoff;
2659: $instsrchoff = ' ';
2660: }
2661: if ($settings->{'localonly'} eq '1') {
2662: $instlocalon = $instlocaloff;
2663: $instlocaloff = ' ';
2664: }
2665: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2666: foreach my $type (@{$settings->{'searchtypes'}}) {
2667: if ($type eq 'exact') {
2668: $exacton = ' checked="checked" ';
2669: } elsif ($type eq 'contains') {
2670: $containson = ' checked="checked" ';
2671: } elsif ($type eq 'begins') {
2672: $beginson = ' checked="checked" ';
2673: }
2674: }
2675: } else {
2676: if ($settings->{'searchtypes'} eq 'exact') {
2677: $exacton = ' checked="checked" ';
2678: } elsif ($settings->{'searchtypes'} eq 'contains') {
2679: $containson = ' checked="checked" ';
2680: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 2681: $exacton = ' checked="checked" ';
2682: $containson = ' checked="checked" ';
2683: }
2684: }
1.23 raeburn 2685: }
1.160.6.72 raeburn 2686: my ($searchtitles,$titleorder) = &sorted_searchtitles();
2687: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2688:
1.160.6.72 raeburn 2689: my $numinrow = 4;
2690: my $cansrchrow = 0;
2691: $datatable='<tr class="LC_odd_row">'.
2692: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
2693: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2694: '<input type="radio" name="dirsrch_available"'.
2695: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
2696: '<label><input type="radio" name="dirsrch_available"'.
2697: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2698: '</tr><tr>'.
2699: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
2700: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2701: '<input type="radio" name="dirsrch_instlocalonly"'.
2702: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2703: '<label><input type="radio" name="dirsrch_instlocalonly"'.
2704: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2705: '</tr>';
2706: $$rowtotal += 2;
2707: if (ref($usertypes) eq 'HASH') {
2708: if (keys(%{$usertypes}) > 0) {
2709: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2710: $numinrow,$othertitle,'cansearch');
2711: $cansrchrow = 1;
2712: }
1.26 raeburn 2713: }
1.160.6.72 raeburn 2714: if ($cansrchrow) {
2715: $$rowtotal ++;
2716: $datatable .= '<tr>';
2717: } else {
2718: $datatable .= '<tr class="LC_odd_row">';
2719: }
2720: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2721: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
2722: foreach my $title (@{$titleorder}) {
2723: if (defined($searchtitles->{$title})) {
2724: my $check = ' ';
2725: if (ref($settings) eq 'HASH') {
2726: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2727: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2728: $check = ' checked="checked" ';
2729: }
1.39 raeburn 2730: }
1.25 raeburn 2731: }
1.160.6.72 raeburn 2732: $datatable .= '<td class="LC_left_item">'.
2733: '<span class="LC_nobreak"><label>'.
2734: '<input type="checkbox" name="searchby" '.
2735: 'value="'.$title.'"'.$check.'/>'.
2736: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 2737: }
2738: }
1.160.6.72 raeburn 2739: $datatable .= '</tr></table></td></tr>';
2740: $$rowtotal ++;
2741: if ($cansrchrow) {
2742: $datatable .= '<tr class="LC_odd_row">';
2743: } else {
2744: $datatable .= '<tr>';
2745: }
2746: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
2747: '<td class="LC_left_item" colspan="2">'.
2748: '<span class="LC_nobreak"><label>'.
2749: '<input type="checkbox" name="searchtypes" '.
2750: $exacton.' value="exact" />'.&mt('Exact match').
2751: '</label> '.
2752: '<label><input type="checkbox" name="searchtypes" '.
2753: $beginson.' value="begins" />'.&mt('Begins with').
2754: '</label> '.
2755: '<label><input type="checkbox" name="searchtypes" '.
2756: $containson.' value="contains" />'.&mt('Contains').
2757: '</label></span></td></tr>';
2758: $$rowtotal ++;
1.26 raeburn 2759: } else {
1.160.6.72 raeburn 2760: my $domsrchon = ' checked="checked" ';
2761: my $domsrchoff = ' ';
2762: my $domlocalon = ' ';
2763: my $domlocaloff = ' checked="checked" ';
2764: if (ref($settings) eq 'HASH') {
2765: if ($settings->{'lclocalonly'} eq '1') {
2766: $domlocalon = $domlocaloff;
2767: $domlocaloff = ' ';
2768: }
2769: if ($settings->{'lcavailable'} eq '0') {
2770: $domsrchoff = $domsrchon;
2771: $domsrchon = ' ';
2772: }
2773: }
2774: $datatable='<tr class="LC_odd_row">'.
2775: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
2776: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2777: '<input type="radio" name="dirsrch_domavailable"'.
2778: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
2779: '<label><input type="radio" name="dirsrch_domavailable"'.
2780: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2781: '</tr><tr>'.
2782: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
2783: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2784: '<input type="radio" name="dirsrch_domlocalonly"'.
2785: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
2786: '<label><input type="radio" name="dirsrch_domlocalonly"'.
2787: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
2788: '</tr>';
2789: $$rowtotal += 2;
1.26 raeburn 2790: }
1.25 raeburn 2791: return $datatable;
2792: }
2793:
1.28 raeburn 2794: sub print_contacts {
1.160.6.78 raeburn 2795: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 2796: my $datatable;
2797: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 2798: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
2799: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
2800: if ($position eq 'top') {
2801: if (ref($settings) eq 'HASH') {
2802: foreach my $item (@contacts) {
2803: if (exists($settings->{$item})) {
2804: $to{$item} = $settings->{$item};
2805: }
1.28 raeburn 2806: }
2807: }
1.160.6.78 raeburn 2808: } elsif ($position eq 'middle') {
2809: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91! raeburn 2810: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 2811: foreach my $type (@mailings) {
1.160.6.78 raeburn 2812: $otheremails{$type} = '';
2813: }
2814: } else {
2815: @mailings = ('helpdeskmail','otherdomsmail');
2816: foreach my $type (@mailings) {
2817: $otheremails{$type} = '';
2818: }
2819: $bccemails{'helpdeskmail'} = '';
2820: $bccemails{'otherdomsmail'} = '';
2821: $includestr{'helpdeskmail'} = '';
2822: $includestr{'otherdomsmail'} = '';
2823: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
2824: }
2825: if (ref($settings) eq 'HASH') {
2826: unless ($position eq 'top') {
2827: foreach my $type (@mailings) {
2828: if (exists($settings->{$type})) {
2829: if (ref($settings->{$type}) eq 'HASH') {
2830: foreach my $item (@contacts) {
2831: if ($settings->{$type}{$item}) {
2832: $checked{$type}{$item} = ' checked="checked" ';
2833: }
1.28 raeburn 2834: }
1.160.6.78 raeburn 2835: $otheremails{$type} = $settings->{$type}{'others'};
2836: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2837: $bccemails{$type} = $settings->{$type}{'bcc'};
2838: if ($settings->{$type}{'include'} ne '') {
2839: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2840: $includestr{$type} = &unescape($includestr{$type});
2841: }
2842: }
2843: }
2844: } elsif ($type eq 'lonstatusmail') {
2845: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2846: }
2847: }
2848: }
2849: if ($position eq 'bottom') {
2850: foreach my $type (@mailings) {
2851: $bccemails{$type} = $settings->{$type}{'bcc'};
2852: if ($settings->{$type}{'include'} ne '') {
2853: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
2854: $includestr{$type} = &unescape($includestr{$type});
2855: }
2856: }
2857: if (ref($settings->{'helpform'}) eq 'HASH') {
2858: if (ref($fields) eq 'ARRAY') {
2859: foreach my $field (@{$fields}) {
2860: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 2861: }
1.160.6.78 raeburn 2862: }
2863: if (exists($settings->{'helpform'}{'maxsize'})) {
2864: $maxsize = $settings->{'helpform'}{'maxsize'};
2865: } else {
2866: $maxsize = '1.0';
2867: }
2868: } else {
2869: if (ref($fields) eq 'ARRAY') {
2870: foreach my $field (@{$fields}) {
2871: $currfield{$field} = 'yes';
1.134 raeburn 2872: }
1.28 raeburn 2873: }
1.160.6.78 raeburn 2874: $maxsize = '1.0';
1.28 raeburn 2875: }
2876: }
2877: } else {
1.160.6.78 raeburn 2878: if ($position eq 'top') {
2879: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2880: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2881: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2882: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
2883: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
2884: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
2885: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
2886: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91! raeburn 2887: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 2888: } elsif ($position eq 'bottom') {
2889: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2890: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
2891: if (ref($fields) eq 'ARRAY') {
2892: foreach my $field (@{$fields}) {
2893: $currfield{$field} = 'yes';
2894: }
2895: }
2896: $maxsize = '1.0';
2897: }
1.28 raeburn 2898: }
2899: my ($titles,$short_titles) = &contact_titles();
2900: my $rownum = 0;
2901: my $css_class;
1.160.6.78 raeburn 2902: if ($position eq 'top') {
2903: foreach my $item (@contacts) {
2904: $css_class = $rownum%2?' class="LC_odd_row"':'';
2905: $datatable .= '<tr'.$css_class.'>'.
2906: '<td><span class="LC_nobreak">'.$titles->{$item}.
2907: '</span></td><td class="LC_right_item">'.
2908: '<input type="text" name="'.$item.'" value="'.
2909: $to{$item}.'" /></td></tr>';
2910: $rownum ++;
2911: }
2912: } else {
2913: foreach my $type (@mailings) {
2914: $css_class = $rownum%2?' class="LC_odd_row"':'';
2915: $datatable .= '<tr'.$css_class.'>'.
2916: '<td><span class="LC_nobreak">'.
2917: $titles->{$type}.': </span></td>'.
2918: '<td class="LC_left_item">';
2919: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2920: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
2921: }
2922: $datatable .= '<span class="LC_nobreak">';
2923: foreach my $item (@contacts) {
2924: $datatable .= '<label>'.
2925: '<input type="checkbox" name="'.$type.'"'.
2926: $checked{$type}{$item}.
2927: ' value="'.$item.'" />'.$short_titles->{$item}.
2928: '</label> ';
2929: }
2930: $datatable .= '</span><br />'.&mt('Others').': '.
2931: '<input type="text" name="'.$type.'_others" '.
2932: 'value="'.$otheremails{$type}.'" />';
2933: my %locchecked;
2934: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2935: foreach my $loc ('s','b') {
2936: if ($includeloc{$type} eq $loc) {
2937: $locchecked{$loc} = ' checked="checked"';
2938: last;
2939: }
2940: }
2941: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2942: '<input type="text" name="'.$type.'_bcc" '.
2943: 'value="'.$bccemails{$type}.'" /></fieldset>'.
2944: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
2945: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 2946: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 2947: '<span class="LC_nobreak">'.&mt('Location:').' '.
2948: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
2949: (' 'x2).
2950: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
2951: '</span></fieldset>';
2952: }
2953: $datatable .= '</td></tr>'."\n";
2954: $rownum ++;
2955: }
1.28 raeburn 2956: }
1.160.6.78 raeburn 2957: if ($position eq 'middle') {
2958: my %choices;
2959: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2960: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2961: &mt('LON-CAPA core group - MSU'),600,500));
2962: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2963: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2964: &mt('LON-CAPA core group - MSU'),600,500));
2965: my @toggles = ('reporterrors','reportupdates');
2966: my %defaultchecked = ('reporterrors' => 'on',
2967: 'reportupdates' => 'on');
2968: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2969: \%choices,$rownum);
2970: $datatable .= $reports;
2971: } elsif ($position eq 'bottom') {
1.69 raeburn 2972: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2973: $datatable .= '<tr'.$css_class.'>'.
1.160.6.78 raeburn 2974: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
2975: &mt('(e-mail, subject, and description always shown)').
2976: '</td><td class="LC_left_item">';
2977: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
2978: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
2979: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
2980: foreach my $field (@{$fields}) {
2981: $datatable .= '<tr><td>'.$fieldtitles->{$field};
2982: if (($field eq 'screenshot') || ($field eq 'cc')) {
2983: $datatable .= ' '.&mt('(logged-in users)');
2984: }
2985: $datatable .='</td><td>';
2986: my $clickaction;
2987: if ($field eq 'screenshot') {
2988: $clickaction = ' onclick="screenshotSize(this);"';
2989: }
2990: if (ref($possoptions->{$field}) eq 'ARRAY') {
2991: foreach my $option (@{$possoptions->{$field}}) {
2992: my $checked;
2993: if ($currfield{$field} eq $option) {
2994: $checked = ' checked="checked"';
2995: }
2996: $datatable .= '<span class="LC_nobreak"><label>'.
2997: '<input type="radio" name="helpform_'.$field.'" '.
2998: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
2999: '</label></span>'.(' 'x2);
3000: }
3001: }
3002: if ($field eq 'screenshot') {
3003: my $display;
3004: if ($currfield{$field} eq 'no') {
3005: $display = ' style="display:none"';
3006: }
1.160.6.87 raeburn 3007: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.160.6.78 raeburn 3008: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3009: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3010: }
3011: $datatable .= '</td></tr>';
3012: }
3013: $datatable .= '</table>';
1.134 raeburn 3014: }
3015: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 3016: $rownum ++;
1.28 raeburn 3017: }
1.30 raeburn 3018: $$rowtotal += $rownum;
1.28 raeburn 3019: return $datatable;
3020: }
3021:
1.160.6.78 raeburn 3022: sub contacts_javascript {
3023: return <<"ENDSCRIPT";
3024:
3025: <script type="text/javascript">
3026: // <![CDATA[
3027:
3028: function screenshotSize(field) {
3029: if (document.getElementById('help_screenshotsize')) {
3030: if (field.value == 'no') {
3031: document.getElementById('help_screenshotsize').style.display="none";
3032: } else {
3033: document.getElementById('help_screenshotsize').style.display="";
3034: }
3035: }
3036: return;
3037: }
3038:
3039: // ]]>
3040: </script>
3041:
3042: ENDSCRIPT
3043: }
3044:
1.118 jms 3045: sub print_helpsettings {
1.160.6.73 raeburn 3046: my ($position,$dom,$settings,$rowtotal) = @_;
3047: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3048: my $formname = 'display';
1.160.6.5 raeburn 3049: my ($datatable,$itemcount);
1.160.6.73 raeburn 3050: if ($position eq 'top') {
3051: $itemcount = 1;
3052: my (%choices,%defaultchecked,@toggles);
3053: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3054: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3055: &mt('LON-CAPA bug tracker'),600,500));
3056: %defaultchecked = ('submitbugs' => 'on');
3057: @toggles = ('submitbugs');
3058: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3059: \%choices,$itemcount);
3060: $$rowtotal ++;
3061: } else {
3062: my $css_class;
3063: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3064: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3065: if (ref($settings) eq 'HASH') {
3066: if (ref($settings->{'adhoc'}) eq 'HASH') {
3067: %current = %{$settings->{'adhoc'}};
3068: }
1.160.6.77 raeburn 3069: }
3070: my $count = 0;
3071: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3072: if ($key=~/^rolesdef\_(\w+)$/) {
3073: my $rolename = $1;
1.160.6.77 raeburn 3074: my (%privs,$order);
1.160.6.73 raeburn 3075: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3076: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3077: if (ref($current{$rolename}) eq 'HASH') {
3078: $order = $current{$rolename}{'order'};
3079: }
3080: if ($order eq '') {
3081: $order = $count;
3082: }
3083: $ordered{$order} = $rolename;
3084: $count++;
1.160.6.73 raeburn 3085: }
3086: }
1.160.6.77 raeburn 3087: my $maxnum = scalar(keys(%ordered));
3088: my @roles_by_num = ();
3089: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3090: push(@roles_by_num,$item);
3091: }
3092: my $context = 'domprefs';
3093: my $crstype = 'Course';
3094: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3095: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3096: my ($numstatustypes,@jsarray);
3097: if (ref($types) eq 'ARRAY') {
3098: if (@{$types} > 0) {
3099: $numstatustypes = scalar(@{$types});
3100: push(@accesstypes,'status');
3101: @jsarray = ('bystatus');
3102: }
3103: }
1.160.6.86 raeburn 3104: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3105: if (keys(%domhelpdesk)) {
3106: push(@accesstypes,('inc','exc'));
3107: push(@jsarray,('notinc','notexc'));
3108: }
3109: my $hiddenstr = join("','",@jsarray);
3110: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3111: my $context = 'domprefs';
3112: my $crstype = 'Course';
1.160.6.77 raeburn 3113: my $prefix = 'helproles_';
3114: my $add_class = 'LC_hidden';
3115: foreach my $num (@roles_by_num) {
3116: my $role = $ordered{$num};
3117: my ($desc,$access,@statuses);
3118: if (ref($current{$role}) eq 'HASH') {
3119: $desc = $current{$role}{'desc'};
3120: $access = $current{$role}{'access'};
3121: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3122: @statuses = @{$current{$role}{'insttypes'}};
3123: }
3124: }
3125: if ($desc eq '') {
3126: $desc = $role;
3127: }
3128: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3129: my %full=();
3130: my %levels= (
3131: course => {},
3132: domain => {},
3133: system => {},
3134: );
3135: my %levelscurrent=(
3136: course => {},
3137: domain => {},
3138: system => {},
3139: );
3140: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3141: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3142: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3143: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3144: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3145: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3146: for (my $k=0; $k<=$maxnum; $k++) {
3147: my $vpos = $k+1;
3148: my $selstr;
3149: if ($k == $num) {
3150: $selstr = ' selected="selected" ';
3151: }
3152: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3153: }
3154: $datatable .= '</select>'.(' 'x2).
3155: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3156: '</td>'.
3157: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3158: &mt('Name shown to users:').
3159: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3160: '</fieldset>'.
3161: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3162: $othertitle,$usertypes,$types,\%domhelpdesk).
3163: '<fieldset>'.
3164: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3165: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3166: \%levelscurrent,$identifier,
3167: 'LC_hidden',$prefix.$num.'_privs').
3168: '</fieldset></td>';
1.160.6.73 raeburn 3169: $itemcount ++;
3170: }
3171: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3172: my $newcust = 'custhelp'.$count;
3173: my (%privs,%levelscurrent);
3174: my %full=();
3175: my %levels= (
3176: course => {},
3177: domain => {},
3178: system => {},
3179: );
3180: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3181: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3182: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3183: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3184: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3185: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3186: for (my $k=0; $k<$maxnum+1; $k++) {
3187: my $vpos = $k+1;
3188: my $selstr;
3189: if ($k == $maxnum) {
3190: $selstr = ' selected="selected" ';
3191: }
3192: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3193: }
3194: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3195: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3196: '</label></span></td>'.
1.160.6.77 raeburn 3197: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3198: '<span class="LC_nobreak">'.
3199: &mt('Internal name:').
3200: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3201: '</span>'.(' 'x4).
3202: '<span class="LC_nobreak">'.
3203: &mt('Name shown to users:').
3204: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3205: '</span></fieldset>'.
3206: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3207: $usertypes,$types,\%domhelpdesk).
3208: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3209: &Apache::lonuserutils::custom_role_header($context,$crstype,
3210: \@templateroles,$newcust).
3211: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3212: \%levelscurrent,$newcust).
1.160.6.87 raeburn 3213: '</fieldset>'.
3214: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3215: '</td></tr>';
1.160.6.73 raeburn 3216: $count ++;
3217: $$rowtotal += $count;
3218: }
1.160.6.5 raeburn 3219: return $datatable;
1.121 raeburn 3220: }
3221:
1.160.6.77 raeburn 3222: sub adhocbutton {
3223: my ($prefix,$num,$field,$visibility) = @_;
3224: my %lt = &Apache::lonlocal::texthash(
3225: show => 'Show details',
3226: hide => 'Hide details',
3227: );
3228: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3229: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3230: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3231: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3232: }
3233:
3234: sub helpsettings_javascript {
3235: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3236: return unless(ref($roles_by_num) eq 'ARRAY');
3237: my %html_js_lt = &Apache::lonlocal::texthash(
3238: show => 'Show details',
3239: hide => 'Hide details',
3240: );
3241: &html_escape(\%html_js_lt);
3242: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3243: return <<"ENDSCRIPT";
3244: <script type="text/javascript">
3245: // <![CDATA[
3246:
3247: function reorderHelpRoles(form,item) {
3248: var changedVal;
3249: $jstext
3250: var newpos = 'helproles_${total}_pos';
3251: var maxh = 1 + $total;
3252: var current = new Array();
3253: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3254: if (item == newpos) {
3255: changedVal = newitemVal;
3256: } else {
3257: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3258: current[newitemVal] = newpos;
3259: }
3260: for (var i=0; i<helproles.length; i++) {
3261: var elementName = 'helproles_'+helproles[i]+'_pos';
3262: if (elementName != item) {
3263: if (form.elements[elementName]) {
3264: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3265: current[currVal] = elementName;
3266: }
3267: }
3268: }
3269: var oldVal;
3270: for (var j=0; j<maxh; j++) {
3271: if (current[j] == undefined) {
3272: oldVal = j;
3273: }
3274: }
3275: if (oldVal < changedVal) {
3276: for (var k=oldVal+1; k<=changedVal ; k++) {
3277: var elementName = current[k];
3278: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3279: }
3280: } else {
3281: for (var k=changedVal; k<oldVal; k++) {
3282: var elementName = current[k];
3283: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3284: }
3285: }
3286: return;
3287: }
3288:
3289: function helpdeskAccess(num) {
3290: var curraccess = null;
3291: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3292: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3293: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3294: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3295: }
3296: }
3297: }
3298: var shown = Array();
3299: var hidden = Array();
3300: if (curraccess == 'none') {
3301: hidden = Array('$hiddenstr');
3302: } else {
3303: if (curraccess == 'status') {
3304: shown = Array('bystatus');
3305: hidden = Array('notinc','notexc');
3306: } else {
3307: if (curraccess == 'exc') {
3308: shown = Array('notexc');
3309: hidden = Array('notinc','bystatus');
3310: }
3311: if (curraccess == 'inc') {
3312: shown = Array('notinc');
3313: hidden = Array('notexc','bystatus');
3314: }
1.160.6.79 raeburn 3315: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3316: hidden = Array('notinc','notexc','bystatus');
3317: }
3318: }
3319: }
3320: if (hidden.length > 0) {
3321: for (var i=0; i<hidden.length; i++) {
3322: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3323: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3324: }
3325: }
3326: }
3327: if (shown.length > 0) {
3328: for (var i=0; i<shown.length; i++) {
3329: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3330: if (shown[i] == 'privs') {
3331: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3332: } else {
3333: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3334: }
3335: }
3336: }
3337: }
3338: return;
3339: }
3340:
3341: function toggleHelpdeskItem(num,field) {
3342: if (document.getElementById('helproles_'+num+'_'+field)) {
3343: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3344: document.getElementById('helproles_'+num+'_'+field).className =
3345: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3346: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3347: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3348: }
3349: } else {
3350: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3351: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3352: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3353: }
3354: }
3355: }
3356: return;
3357: }
3358:
3359: // ]]>
3360: </script>
3361:
3362: ENDSCRIPT
3363: }
3364:
3365: sub helpdeskroles_access {
3366: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3367: $usertypes,$types,$domhelpdesk) = @_;
3368: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3369: my %lt = &Apache::lonlocal::texthash(
3370: 'rou' => 'Role usage',
3371: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3372: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3373: 'dh' => 'All with domain helpdesk role',
3374: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3375: 'none' => 'None',
3376: 'status' => 'Determined based on institutional status',
3377: 'inc' => 'Include all, but exclude specific personnel',
3378: 'exc' => 'Exclude all, but include specific personnel',
3379: );
3380: my %usecheck = (
3381: all => ' checked="checked"',
3382: );
3383: my %displaydiv = (
3384: status => 'none',
3385: inc => 'none',
3386: exc => 'none',
3387: priv => 'block',
3388: );
3389: my $output;
3390: if (ref($current) eq 'HASH') {
3391: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3392: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3393: $usecheck{$current->{access}} = $usecheck{'all'};
3394: delete($usecheck{'all'});
3395: if ($current->{access} =~ /^(status|inc|exc)$/) {
3396: my $access = $1;
3397: $displaydiv{$access} = 'inline';
3398: } elsif ($current->{access} eq 'none') {
3399: $displaydiv{'priv'} = 'none';
3400: }
3401: }
3402: }
3403: }
3404: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3405: '<p>'.$lt{'whi'}.'</p>';
3406: foreach my $access (@{$accesstypes}) {
3407: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3408: ' onclick="helpdeskAccess('."'$num'".');" />'.
3409: $lt{$access}.'</label>';
3410: if ($access eq 'status') {
3411: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3412: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3413: $othertitle,$usertypes,$types).
3414: '</div>';
3415: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3416: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3417: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3418: '</div>';
3419: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3420: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3421: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3422: '</div>';
3423: }
3424: $output .= '</p>';
3425: }
3426: $output .= '</fieldset>';
3427: return $output;
3428: }
3429:
1.121 raeburn 3430: sub radiobutton_prefs {
1.160.6.16 raeburn 3431: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3432: $additional,$align) = @_;
1.121 raeburn 3433: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3434: (ref($choices) eq 'HASH'));
3435:
3436: my (%checkedon,%checkedoff,$datatable,$css_class);
3437:
3438: foreach my $item (@{$toggles}) {
3439: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3440: $checkedon{$item} = ' checked="checked" ';
3441: $checkedoff{$item} = ' ';
1.121 raeburn 3442: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3443: $checkedoff{$item} = ' checked="checked" ';
3444: $checkedon{$item} = ' ';
3445: }
3446: }
3447: if (ref($settings) eq 'HASH') {
1.121 raeburn 3448: foreach my $item (@{$toggles}) {
1.118 jms 3449: if ($settings->{$item} eq '1') {
3450: $checkedon{$item} = ' checked="checked" ';
3451: $checkedoff{$item} = ' ';
3452: } elsif ($settings->{$item} eq '0') {
3453: $checkedoff{$item} = ' checked="checked" ';
3454: $checkedon{$item} = ' ';
3455: }
3456: }
1.121 raeburn 3457: }
1.160.6.16 raeburn 3458: if ($onclick) {
3459: $onclick = ' onclick="'.$onclick.'"';
3460: }
1.121 raeburn 3461: foreach my $item (@{$toggles}) {
1.118 jms 3462: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3463: $datatable .=
1.160.6.16 raeburn 3464: '<tr'.$css_class.'><td valign="top">'.
3465: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3466: '</span></td>';
3467: if ($align eq 'left') {
3468: $datatable .= '<td class="LC_left_item">';
3469: } else {
3470: $datatable .= '<td class="LC_right_item">';
3471: }
3472: $datatable .=
3473: '<span class="LC_nobreak">'.
1.118 jms 3474: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3475: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3476: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3477: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3478: '</span>'.$additional.
3479: '</td>'.
1.118 jms 3480: '</tr>';
3481: $itemcount ++;
1.121 raeburn 3482: }
3483: return ($datatable,$itemcount);
3484: }
3485:
3486: sub print_coursedefaults {
1.139 raeburn 3487: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3488: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3489: my $itemcount = 1;
1.160.6.16 raeburn 3490: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3491: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3492: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3493: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3494: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3495: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90 raeburn 3496: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 3497: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3498: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3499: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3500: );
1.160.6.21 raeburn 3501: my %staticdefaults = (
3502: anonsurvey_threshold => 10,
3503: uploadquota => 500,
1.160.6.57 raeburn 3504: postsubmit => 60,
1.160.6.70 raeburn 3505: mysqltables => 172800,
1.160.6.21 raeburn 3506: );
1.139 raeburn 3507: if ($position eq 'top') {
1.160.6.57 raeburn 3508: %defaultchecked = (
3509: 'uselcmath' => 'on',
3510: 'usejsme' => 'on',
1.160.6.64 raeburn 3511: 'canclone' => 'none',
1.160.6.57 raeburn 3512: );
3513: @toggles = ('uselcmath','usejsme');
1.160.6.90 raeburn 3514: my $deftex = $Apache::lonnet::deftex;
3515: if (ref($settings) eq 'HASH') {
3516: if ($settings->{'texengine'}) {
3517: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
3518: $deftex = $settings->{'texengine'};
3519: }
3520: }
3521: }
3522: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3523: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
3524: '<span class="LC_nobreak">'.$choices{'texengine'}.
3525: '</span></td><td class="LC_right_item">'.
3526: '<select name="texengine">'."\n";
3527: my %texoptions = (
3528: MathJax => 'MathJax',
3529: mimetex => &mt('Convert to Images'),
3530: tth => &mt('TeX to HTML'),
3531: );
3532: foreach my $renderer ('MathJax','mimetex','tth') {
3533: my $selected = '';
3534: if ($renderer eq $deftex) {
3535: $selected = ' selected="selected"';
3536: }
3537: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
3538: }
3539: $mathdisp .= '</select></td></tr>'."\n";
3540: $itemcount ++;
1.139 raeburn 3541: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3542: \%choices,$itemcount);
1.160.6.90 raeburn 3543: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 3544: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3545: $datatable .=
3546: '<tr'.$css_class.'><td valign="top">'.
3547: '<span class="LC_nobreak">'.$choices{'canclone'}.
3548: '</span></td><td class="LC_left_item">';
3549: my $currcanclone = 'none';
3550: my $onclick;
3551: my @cloneoptions = ('none','domain');
3552: my %clonetitles = (
3553: none => 'No additional course requesters',
3554: domain => "Any course requester in course's domain",
3555: instcode => 'Course requests for official courses ...',
3556: );
3557: my (%codedefaults,@code_order,@posscodes);
3558: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3559: \@code_order) eq 'ok') {
3560: if (@code_order > 0) {
3561: push(@cloneoptions,'instcode');
3562: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3563: }
3564: }
3565: if (ref($settings) eq 'HASH') {
3566: if ($settings->{'canclone'}) {
3567: if (ref($settings->{'canclone'}) eq 'HASH') {
3568: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3569: if (@code_order > 0) {
3570: $currcanclone = 'instcode';
3571: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3572: }
3573: }
3574: } elsif ($settings->{'canclone'} eq 'domain') {
3575: $currcanclone = $settings->{'canclone'};
3576: }
3577: }
3578: }
3579: foreach my $option (@cloneoptions) {
3580: my ($checked,$additional);
3581: if ($currcanclone eq $option) {
3582: $checked = ' checked="checked"';
3583: }
3584: if ($option eq 'instcode') {
3585: if (@code_order) {
3586: my $show = 'none';
3587: if ($checked) {
3588: $show = 'block';
3589: }
3590: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3591: &mt('Institutional codes for new and cloned course have identical:').
3592: '<br />';
3593: foreach my $item (@code_order) {
3594: my $codechk;
3595: if ($checked) {
3596: if (grep(/^\Q$item\E$/,@posscodes)) {
3597: $codechk = ' checked="checked"';
3598: }
3599: }
3600: $additional .= '<label>'.
3601: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3602: $item.'</label>';
3603: }
3604: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3605: }
3606: }
3607: $datatable .=
3608: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3609: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3610: '</label> '.$additional.'</span><br />';
3611: }
3612: $datatable .= '</td>'.
3613: '</tr>';
3614: $itemcount ++;
1.139 raeburn 3615: } else {
3616: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3617: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3618: my $currusecredits = 0;
1.160.6.57 raeburn 3619: my $postsubmitclient = 1;
1.160.6.30 raeburn 3620: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3621: if (ref($settings) eq 'HASH') {
3622: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3623: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3624: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3625: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3626: }
3627: }
1.160.6.16 raeburn 3628: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3629: foreach my $type (@types) {
3630: next if ($type eq 'community');
3631: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3632: if ($defcredits{$type} ne '') {
3633: $currusecredits = 1;
3634: }
3635: }
3636: }
3637: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3638: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3639: $postsubmitclient = 0;
3640: foreach my $type (@types) {
3641: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3642: }
3643: } else {
3644: foreach my $type (@types) {
3645: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3646: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3647: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3648: } else {
3649: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3650: }
3651: } else {
3652: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3653: }
3654: }
3655: }
3656: } else {
3657: foreach my $type (@types) {
3658: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3659: }
3660: }
1.160.6.70 raeburn 3661: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3662: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3663: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3664: }
3665: } else {
3666: foreach my $type (@types) {
3667: $currmysql{$type} = $staticdefaults{'mysqltables'};
3668: }
3669: }
1.160.6.58 raeburn 3670: } else {
3671: foreach my $type (@types) {
3672: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3673: }
1.139 raeburn 3674: }
3675: if (!$currdefresponder) {
1.160.6.21 raeburn 3676: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3677: } elsif ($currdefresponder < 1) {
3678: $currdefresponder = 1;
3679: }
1.160.6.21 raeburn 3680: foreach my $type (@types) {
3681: if ($curruploadquota{$type} eq '') {
3682: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3683: }
3684: }
1.139 raeburn 3685: $datatable .=
1.160.6.16 raeburn 3686: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3687: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3688: '</span></td>'.
3689: '<td class="LC_right_item"><span class="LC_nobreak">'.
3690: '<input type="text" name="anonsurvey_threshold"'.
3691: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3692: '</td></tr>'."\n";
3693: $itemcount ++;
3694: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3695: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3696: $choices{'uploadquota'}.
3697: '</span></td>'.
3698: '<td align="right" class="LC_right_item">'.
3699: '<table><tr>';
1.160.6.21 raeburn 3700: foreach my $type (@types) {
3701: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3702: '<input type="text" name="uploadquota_'.$type.'"'.
3703: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3704: }
3705: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3706: $itemcount ++;
1.160.6.40 raeburn 3707: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3708: my $display = 'none';
3709: if ($currusecredits) {
3710: $display = 'block';
3711: }
3712: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3713: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3714: foreach my $type (@types) {
3715: next if ($type eq 'community');
3716: $additional .= '<td align="center">'.&mt($type).'<br />'.
3717: '<input type="text" name="'.$type.'_credits"'.
3718: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3719: }
3720: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3721: %defaultchecked = ('coursecredits' => 'off');
3722: @toggles = ('coursecredits');
3723: my $current = {
3724: 'coursecredits' => $currusecredits,
3725: };
3726: (my $table,$itemcount) =
3727: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3728: \%choices,$itemcount,$onclick,$additional,'left');
3729: $datatable .= $table;
3730: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3731: my $display = 'none';
3732: if ($postsubmitclient) {
3733: $display = 'block';
3734: }
3735: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3736: &mt('Number of seconds submit is disabled').'<br />'.
3737: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3738: '<table><tr>';
1.160.6.57 raeburn 3739: foreach my $type (@types) {
3740: $additional .= '<td align="center">'.&mt($type).'<br />'.
3741: '<input type="text" name="'.$type.'_timeout" value="'.
3742: $deftimeout{$type}.'" size="5" /></td>';
3743: }
3744: $additional .= '</tr></table></div>'."\n";
3745: %defaultchecked = ('postsubmit' => 'on');
3746: @toggles = ('postsubmit');
1.160.6.70 raeburn 3747: $current = {
3748: 'postsubmit' => $postsubmitclient,
3749: };
1.160.6.57 raeburn 3750: ($table,$itemcount) =
3751: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3752: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3753: $datatable .= $table;
1.160.6.70 raeburn 3754: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3755: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3756: $choices{'mysqltables'}.
3757: '</span></td>'.
3758: '<td align="right" class="LC_right_item">'.
3759: '<table><tr>';
3760: foreach my $type (@types) {
3761: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3762: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 3763: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 3764: }
3765: $datatable .= '</tr></table></td></tr>'."\n";
3766: $itemcount ++;
3767:
1.160.6.37 raeburn 3768: }
3769: $$rowtotal += $itemcount;
3770: return $datatable;
3771: }
3772:
3773: sub print_selfenrollment {
3774: my ($position,$dom,$settings,$rowtotal) = @_;
3775: my ($css_class,$datatable);
3776: my $itemcount = 1;
3777: my @types = ('official','unofficial','community','textbook');
3778: if (($position eq 'top') || ($position eq 'middle')) {
3779: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3780: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3781: my @rows;
3782: my $key;
3783: if ($position eq 'top') {
3784: $key = 'admin';
3785: if (ref($rowsref) eq 'ARRAY') {
3786: @rows = @{$rowsref};
3787: }
3788: } elsif ($position eq 'middle') {
3789: $key = 'default';
3790: @rows = ('types','registered','approval','limit');
3791: }
3792: foreach my $row (@rows) {
3793: if (defined($titlesref->{$row})) {
3794: $itemcount ++;
3795: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3796: $datatable .= '<tr'.$css_class.'>'.
3797: '<td>'.$titlesref->{$row}.'</td>'.
3798: '<td class="LC_left_item">'.
3799: '<table><tr>';
3800: my (%current,%currentcap);
3801: if (ref($settings) eq 'HASH') {
3802: if (ref($settings->{$key}) eq 'HASH') {
3803: foreach my $type (@types) {
3804: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3805: $current{$type} = $settings->{$key}->{$type}->{$row};
3806: }
3807: if (($row eq 'limit') && ($key eq 'default')) {
3808: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3809: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3810: }
3811: }
3812: }
3813: }
3814: }
3815: my %roles = (
3816: '0' => &Apache::lonnet::plaintext('dc'),
3817: );
3818:
3819: foreach my $type (@types) {
3820: unless (($row eq 'registered') && ($key eq 'default')) {
3821: $datatable .= '<th>'.&mt($type).'</th>';
3822: }
3823: }
3824: unless (($row eq 'registered') && ($key eq 'default')) {
3825: $datatable .= '</tr><tr>';
3826: }
3827: foreach my $type (@types) {
3828: if ($type eq 'community') {
3829: $roles{'1'} = &mt('Community personnel');
3830: } else {
3831: $roles{'1'} = &mt('Course personnel');
3832: }
3833: $datatable .= '<td style="vertical-align: top">';
3834: if ($position eq 'top') {
3835: my %checked;
3836: if ($current{$type} eq '0') {
3837: $checked{'0'} = ' checked="checked"';
3838: } else {
3839: $checked{'1'} = ' checked="checked"';
3840: }
3841: foreach my $role ('1','0') {
3842: $datatable .= '<span class="LC_nobreak"><label>'.
3843: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3844: 'value="'.$role.'"'.$checked{$role}.' />'.
3845: $roles{$role}.'</label></span> ';
3846: }
3847: } else {
3848: if ($row eq 'types') {
3849: my %checked;
3850: if ($current{$type} =~ /^(all|dom)$/) {
3851: $checked{$1} = ' checked="checked"';
3852: } else {
3853: $checked{''} = ' checked="checked"';
3854: }
3855: foreach my $val ('','dom','all') {
3856: $datatable .= '<span class="LC_nobreak"><label>'.
3857: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3858: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3859: }
3860: } elsif ($row eq 'registered') {
3861: my %checked;
3862: if ($current{$type} eq '1') {
3863: $checked{'1'} = ' checked="checked"';
3864: } else {
3865: $checked{'0'} = ' checked="checked"';
3866: }
3867: foreach my $val ('0','1') {
3868: $datatable .= '<span class="LC_nobreak"><label>'.
3869: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3870: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3871: }
3872: } elsif ($row eq 'approval') {
3873: my %checked;
3874: if ($current{$type} =~ /^([12])$/) {
3875: $checked{$1} = ' checked="checked"';
3876: } else {
3877: $checked{'0'} = ' checked="checked"';
3878: }
3879: for my $val (0..2) {
3880: $datatable .= '<span class="LC_nobreak"><label>'.
3881: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3882: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3883: }
3884: } elsif ($row eq 'limit') {
3885: my %checked;
3886: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3887: $checked{$1} = ' checked="checked"';
3888: } else {
3889: $checked{'none'} = ' checked="checked"';
3890: }
3891: my $cap;
3892: if ($currentcap{$type} =~ /^\d+$/) {
3893: $cap = $currentcap{$type};
3894: }
3895: foreach my $val ('none','allstudents','selfenrolled') {
3896: $datatable .= '<span class="LC_nobreak"><label>'.
3897: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3898: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3899: }
3900: $datatable .= '<br />'.
3901: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3902: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3903: '</span>';
3904: }
3905: }
3906: $datatable .= '</td>';
3907: }
3908: $datatable .= '</tr>';
3909: }
3910: $datatable .= '</table></td></tr>';
3911: }
3912: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3913: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3914: }
3915: $$rowtotal += $itemcount;
3916: return $datatable;
3917: }
3918:
3919: sub print_validation_rows {
3920: my ($caller,$dom,$settings,$rowtotal) = @_;
3921: my ($itemsref,$namesref,$fieldsref);
3922: if ($caller eq 'selfenroll') {
3923: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3924: } elsif ($caller eq 'requestcourses') {
3925: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3926: }
3927: my %currvalidation;
3928: if (ref($settings) eq 'HASH') {
3929: if (ref($settings->{'validation'}) eq 'HASH') {
3930: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3931: }
1.160.6.39 raeburn 3932: }
3933: my $datatable;
3934: my $itemcount = 0;
3935: foreach my $item (@{$itemsref}) {
3936: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3937: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3938: $namesref->{$item}.
3939: '</span></td>'.
3940: '<td class="LC_left_item">';
3941: if (($item eq 'url') || ($item eq 'button')) {
3942: $datatable .= '<span class="LC_nobreak">'.
3943: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3944: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3945: } elsif ($item eq 'fields') {
3946: my @currfields;
3947: if (ref($currvalidation{$item}) eq 'ARRAY') {
3948: @currfields = @{$currvalidation{$item}};
3949: }
3950: foreach my $field (@{$fieldsref}) {
3951: my $check = '';
3952: if (grep(/^\Q$field\E$/,@currfields)) {
3953: $check = ' checked="checked"';
3954: }
3955: $datatable .= '<span class="LC_nobreak"><label>'.
3956: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3957: ' value="'.$field.'"'.$check.' />'.$field.
3958: '</label></span> ';
3959: }
3960: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 3961: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 3962: $currvalidation{$item}.
1.160.6.37 raeburn 3963: '</textarea>';
1.160.6.39 raeburn 3964: }
3965: $datatable .= '</td></tr>'."\n";
3966: if (ref($rowtotal)) {
1.160.6.37 raeburn 3967: $itemcount ++;
3968: }
1.139 raeburn 3969: }
1.160.6.39 raeburn 3970: if ($caller eq 'requestcourses') {
3971: my %currhash;
1.160.6.51 raeburn 3972: if (ref($settings) eq 'HASH') {
3973: if (ref($settings->{'validation'}) eq 'HASH') {
3974: if ($settings->{'validation'}{'dc'} ne '') {
3975: $currhash{$settings->{'validation'}{'dc'}} = 1;
3976: }
1.160.6.39 raeburn 3977: }
3978: }
3979: my $numinrow = 2;
3980: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3981: 'validationdc',%currhash);
1.160.6.50 raeburn 3982: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 3983: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 3984: if ($numdc > 1) {
1.160.6.50 raeburn 3985: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3986: } else {
1.160.6.50 raeburn 3987: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3988: }
1.160.6.50 raeburn 3989: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3990: $itemcount ++;
3991: }
3992: if (ref($rowtotal)) {
3993: $$rowtotal += $itemcount;
3994: }
1.121 raeburn 3995: return $datatable;
1.118 jms 3996: }
3997:
1.137 raeburn 3998: sub print_usersessions {
3999: my ($position,$dom,$settings,$rowtotal) = @_;
4000: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 4001: my (%by_ip,%by_location,@intdoms);
4002: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 4003:
4004: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 4005: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 4006: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 4007: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 4008: my $itemcount = 1;
4009: if ($position eq 'top') {
1.152 raeburn 4010: if (keys(%serverhomes) > 1) {
1.145 raeburn 4011: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 4012: my $curroffloadnow;
4013: if (ref($settings) eq 'HASH') {
4014: if (ref($settings->{'offloadnow'}) eq 'HASH') {
4015: $curroffloadnow = $settings->{'offloadnow'};
4016: }
4017: }
4018: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 4019: } else {
1.140 raeburn 4020: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4021: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 4022: }
1.137 raeburn 4023: } else {
1.145 raeburn 4024: if (keys(%by_location) == 0) {
4025: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 4026: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 4027: } else {
4028: my %lt = &usersession_titles();
4029: my $numinrow = 5;
4030: my $prefix;
4031: my @types;
4032: if ($position eq 'bottom') {
4033: $prefix = 'remote';
4034: @types = ('version','excludedomain','includedomain');
4035: } else {
4036: $prefix = 'hosted';
4037: @types = ('excludedomain','includedomain');
4038: }
4039: my (%current,%checkedon,%checkedoff);
4040: my @lcversions = &Apache::lonnet::all_loncaparevs();
4041: my @locations = sort(keys(%by_location));
4042: foreach my $type (@types) {
4043: $checkedon{$type} = '';
4044: $checkedoff{$type} = ' checked="checked"';
4045: }
4046: if (ref($settings) eq 'HASH') {
4047: if (ref($settings->{$prefix}) eq 'HASH') {
4048: foreach my $key (keys(%{$settings->{$prefix}})) {
4049: $current{$key} = $settings->{$prefix}{$key};
4050: if ($key eq 'version') {
4051: if ($current{$key} ne '') {
4052: $checkedon{$key} = ' checked="checked"';
4053: $checkedoff{$key} = '';
4054: }
4055: } elsif (ref($current{$key}) eq 'ARRAY') {
4056: $checkedon{$key} = ' checked="checked"';
4057: $checkedoff{$key} = '';
4058: }
1.137 raeburn 4059: }
4060: }
4061: }
1.145 raeburn 4062: foreach my $type (@types) {
4063: next if ($type ne 'version' && !@locations);
4064: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4065: $datatable .= '<tr'.$css_class.'>
4066: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4067: <span class="LC_nobreak">
4068: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4069: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4070: if ($type eq 'version') {
4071: my $selector = '<select name="'.$prefix.'_version">';
4072: foreach my $version (@lcversions) {
4073: my $selected = '';
4074: if ($current{'version'} eq $version) {
4075: $selected = ' selected="selected"';
4076: }
4077: $selector .= ' <option value="'.$version.'"'.
4078: $selected.'>'.$version.'</option>';
4079: }
4080: $selector .= '</select> ';
4081: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4082: } else {
4083: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4084: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4085: ' />'.(' 'x2).
4086: '<input type="button" value="'.&mt('uncheck all').'" '.
4087: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4088: "\n".
4089: '</div><div><table>';
4090: my $rem;
4091: for (my $i=0; $i<@locations; $i++) {
4092: my ($showloc,$value,$checkedtype);
4093: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4094: my $ip = $by_location{$locations[$i]}->[0];
4095: if (ref($by_ip{$ip}) eq 'ARRAY') {
4096: $value = join(':',@{$by_ip{$ip}});
4097: $showloc = join(', ',@{$by_ip{$ip}});
4098: if (ref($current{$type}) eq 'ARRAY') {
4099: foreach my $loc (@{$by_ip{$ip}}) {
4100: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4101: $checkedtype = ' checked="checked"';
4102: last;
4103: }
4104: }
1.138 raeburn 4105: }
4106: }
4107: }
1.145 raeburn 4108: $rem = $i%($numinrow);
4109: if ($rem == 0) {
4110: if ($i > 0) {
4111: $datatable .= '</tr>';
4112: }
4113: $datatable .= '<tr>';
4114: }
4115: $datatable .= '<td class="LC_left_item">'.
4116: '<span class="LC_nobreak"><label>'.
4117: '<input type="checkbox" name="'.$prefix.'_'.$type.
4118: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4119: '</label></span></td>';
1.137 raeburn 4120: }
1.145 raeburn 4121: $rem = @locations%($numinrow);
4122: my $colsleft = $numinrow - $rem;
4123: if ($colsleft > 1 ) {
4124: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4125: ' </td>';
4126: } elsif ($colsleft == 1) {
4127: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4128: }
1.145 raeburn 4129: $datatable .= '</tr></table>';
1.137 raeburn 4130: }
1.145 raeburn 4131: $datatable .= '</td></tr>';
4132: $itemcount ++;
1.137 raeburn 4133: }
4134: }
4135: }
4136: $$rowtotal += $itemcount;
4137: return $datatable;
4138: }
4139:
1.138 raeburn 4140: sub build_location_hashes {
4141: my ($intdoms,$by_ip,$by_location) = @_;
4142: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4143: (ref($by_location) eq 'HASH'));
4144: my %iphost = &Apache::lonnet::get_iphost();
4145: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4146: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4147: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4148: foreach my $id (@{$iphost{$primary_ip}}) {
4149: my $intdom = &Apache::lonnet::internet_dom($id);
4150: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4151: push(@{$intdoms},$intdom);
4152: }
4153: }
4154: }
4155: foreach my $ip (keys(%iphost)) {
4156: if (ref($iphost{$ip}) eq 'ARRAY') {
4157: foreach my $id (@{$iphost{$ip}}) {
4158: my $location = &Apache::lonnet::internet_dom($id);
4159: if ($location) {
4160: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4161: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4162: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4163: push(@{$by_ip->{$ip}},$location);
4164: }
4165: } else {
4166: $by_ip->{$ip} = [$location];
4167: }
4168: }
4169: }
4170: }
4171: }
4172: foreach my $ip (sort(keys(%{$by_ip}))) {
4173: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4174: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4175: my $first = $by_ip->{$ip}->[0];
4176: if (ref($by_location->{$first}) eq 'ARRAY') {
4177: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4178: push(@{$by_location->{$first}},$ip);
4179: }
4180: } else {
4181: $by_location->{$first} = [$ip];
4182: }
4183: }
4184: }
4185: return;
4186: }
4187:
1.145 raeburn 4188: sub current_offloads_to {
4189: my ($dom,$settings,$servers) = @_;
4190: my (%spareid,%otherdomconfigs);
1.152 raeburn 4191: if (ref($servers) eq 'HASH') {
1.145 raeburn 4192: foreach my $lonhost (sort(keys(%{$servers}))) {
4193: my $gotspares;
1.152 raeburn 4194: if (ref($settings) eq 'HASH') {
4195: if (ref($settings->{'spares'}) eq 'HASH') {
4196: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4197: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4198: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4199: $gotspares = 1;
4200: }
1.145 raeburn 4201: }
4202: }
4203: unless ($gotspares) {
4204: my $gotspares;
4205: my $serverhomeID =
4206: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4207: my $serverhomedom =
4208: &Apache::lonnet::host_domain($serverhomeID);
4209: if ($serverhomedom ne $dom) {
4210: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4211: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4212: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4213: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4214: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4215: $gotspares = 1;
4216: }
4217: }
4218: } else {
4219: $otherdomconfigs{$serverhomedom} =
4220: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4221: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4222: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4223: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4224: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4225: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4226: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4227: $gotspares = 1;
4228: }
4229: }
4230: }
4231: }
4232: }
4233: }
4234: }
4235: unless ($gotspares) {
4236: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4237: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4238: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4239: } else {
4240: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4241: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4242: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4243: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4244: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4245: } else {
1.150 raeburn 4246: my %what = (
4247: spareid => 1,
4248: );
4249: my ($result,$returnhash) =
4250: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4251: if ($result eq 'ok') {
4252: if (ref($returnhash) eq 'HASH') {
4253: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4254: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4255: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4256: }
4257: }
1.145 raeburn 4258: }
4259: }
4260: }
4261: }
4262: }
4263: }
4264: return %spareid;
4265: }
4266:
4267: sub spares_row {
1.160.6.61 raeburn 4268: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4269: my $css_class;
4270: my $numinrow = 4;
4271: my $itemcount = 1;
4272: my $datatable;
1.152 raeburn 4273: my %typetitles = &sparestype_titles();
4274: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4275: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4276: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4277: my ($othercontrol,$serverdom);
4278: if ($serverhome ne $server) {
4279: $serverdom = &Apache::lonnet::host_domain($serverhome);
4280: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4281: } else {
4282: $serverdom = &Apache::lonnet::host_domain($server);
4283: if ($serverdom ne $dom) {
4284: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4285: }
4286: }
4287: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4288: my $checkednow;
4289: if (ref($curroffloadnow) eq 'HASH') {
4290: if ($curroffloadnow->{$server}) {
4291: $checkednow = ' checked="checked"';
4292: }
4293: }
1.145 raeburn 4294: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4295: $datatable .= '<tr'.$css_class.'>
4296: <td rowspan="2">
1.160.6.13 raeburn 4297: <span class="LC_nobreak">'.
4298: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4299: ,'<b>'.$server.'</b>').'</span><br />'.
4300: '<span class="LC_nobreak">'."\n".
4301: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4302: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4303: "\n";
1.145 raeburn 4304: my (%current,%canselect);
1.152 raeburn 4305: my @choices =
4306: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4307: foreach my $type ('primary','default') {
4308: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4309: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4310: my @spares = @{$spareid->{$server}{$type}};
4311: if (@spares > 0) {
1.152 raeburn 4312: if ($othercontrol) {
4313: $current{$type} = join(', ',@spares);
4314: } else {
4315: $current{$type} .= '<table>';
4316: my $numspares = scalar(@spares);
4317: for (my $i=0; $i<@spares; $i++) {
4318: my $rem = $i%($numinrow);
4319: if ($rem == 0) {
4320: if ($i > 0) {
4321: $current{$type} .= '</tr>';
4322: }
4323: $current{$type} .= '<tr>';
1.145 raeburn 4324: }
1.152 raeburn 4325: $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'".');" /> '.
4326: $spareid->{$server}{$type}[$i].
4327: '</label></td>'."\n";
4328: }
4329: my $rem = @spares%($numinrow);
4330: my $colsleft = $numinrow - $rem;
4331: if ($colsleft > 1 ) {
4332: $current{$type} .= '<td colspan="'.$colsleft.
4333: '" class="LC_left_item">'.
4334: ' </td>';
4335: } elsif ($colsleft == 1) {
4336: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4337: }
1.152 raeburn 4338: $current{$type} .= '</tr></table>';
1.150 raeburn 4339: }
1.145 raeburn 4340: }
4341: }
4342: if ($current{$type} eq '') {
4343: $current{$type} = &mt('None specified');
4344: }
1.152 raeburn 4345: if ($othercontrol) {
4346: if ($type eq 'primary') {
4347: $canselect{$type} = $othercontrol;
4348: }
4349: } else {
4350: $canselect{$type} =
4351: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4352: '<select name="newspare_'.$type.'_'.$server.'" '.
4353: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4354: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4355: if (@choices > 0) {
4356: foreach my $lonhost (@choices) {
4357: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4358: }
4359: }
4360: $canselect{$type} .= '</select>'."\n";
4361: }
4362: } else {
4363: $current{$type} = &mt('Could not be determined');
4364: if ($type eq 'primary') {
4365: $canselect{$type} = $othercontrol;
4366: }
1.145 raeburn 4367: }
1.152 raeburn 4368: if ($type eq 'default') {
4369: $datatable .= '<tr'.$css_class.'>';
4370: }
4371: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4372: '<td>'.$current{$type}.'</td>'."\n".
4373: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4374: }
4375: $itemcount ++;
4376: }
4377: }
4378: $$rowtotal += $itemcount;
4379: return $datatable;
4380: }
4381:
1.152 raeburn 4382: sub possible_newspares {
4383: my ($server,$currspares,$serverhomes,$altids) = @_;
4384: my $serverhostname = &Apache::lonnet::hostname($server);
4385: my %excluded;
4386: if ($serverhostname ne '') {
4387: %excluded = (
4388: $serverhostname => 1,
4389: );
4390: }
4391: if (ref($currspares) eq 'HASH') {
4392: foreach my $type (keys(%{$currspares})) {
4393: if (ref($currspares->{$type}) eq 'ARRAY') {
4394: if (@{$currspares->{$type}} > 0) {
4395: foreach my $curr (@{$currspares->{$type}}) {
4396: my $hostname = &Apache::lonnet::hostname($curr);
4397: $excluded{$hostname} = 1;
4398: }
4399: }
4400: }
4401: }
4402: }
4403: my @choices;
4404: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4405: if (keys(%{$serverhomes}) > 1) {
4406: foreach my $name (sort(keys(%{$serverhomes}))) {
4407: unless ($excluded{$name}) {
4408: if (exists($altids->{$serverhomes->{$name}})) {
4409: push(@choices,$altids->{$serverhomes->{$name}});
4410: } else {
4411: push(@choices,$serverhomes->{$name});
1.145 raeburn 4412: }
4413: }
4414: }
4415: }
4416: }
1.152 raeburn 4417: return sort(@choices);
1.145 raeburn 4418: }
4419:
1.150 raeburn 4420: sub print_loadbalancing {
4421: my ($dom,$settings,$rowtotal) = @_;
4422: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4423: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4424: my $numinrow = 1;
4425: my $datatable;
4426: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 4427: my (%currbalancer,%currtargets,%currrules,%existing);
4428: if (ref($settings) eq 'HASH') {
4429: %existing = %{$settings};
4430: }
4431: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4432: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4433: \%currtargets,\%currrules);
1.150 raeburn 4434: } else {
4435: return;
4436: }
4437: my ($othertitle,$usertypes,$types) =
4438: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 4439: my $rownum = 8;
1.150 raeburn 4440: if (ref($types) eq 'ARRAY') {
4441: $rownum += scalar(@{$types});
4442: }
1.160.6.7 raeburn 4443: my @css_class = ('LC_odd_row','LC_even_row');
4444: my $balnum = 0;
4445: my $islast;
4446: my (@toshow,$disabledtext);
4447: if (keys(%currbalancer) > 0) {
4448: @toshow = sort(keys(%currbalancer));
4449: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4450: push(@toshow,'');
4451: }
4452: } else {
4453: @toshow = ('');
4454: $disabledtext = &mt('No existing load balancer');
4455: }
4456: foreach my $lonhost (@toshow) {
4457: if ($balnum == scalar(@toshow)-1) {
4458: $islast = 1;
4459: } else {
4460: $islast = 0;
4461: }
4462: my $cssidx = $balnum%2;
4463: my $targets_div_style = 'display: none';
4464: my $disabled_div_style = 'display: block';
4465: my $homedom_div_style = 'display: none';
4466: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4467: '<td rowspan="'.$rownum.'" valign="top">'.
4468: '<p>';
4469: if ($lonhost eq '') {
4470: $datatable .= '<span class="LC_nobreak">';
4471: if (keys(%currbalancer) > 0) {
4472: $datatable .= &mt('Add balancer:');
4473: } else {
4474: $datatable .= &mt('Enable balancer:');
4475: }
4476: $datatable .= ' '.
4477: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4478: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4479: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4480: '<option value="" selected="selected">'.&mt('None').
4481: '</option>'."\n";
4482: foreach my $server (sort(keys(%servers))) {
4483: next if ($currbalancer{$server});
4484: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4485: }
4486: $datatable .=
4487: '</select>'."\n".
4488: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4489: } else {
4490: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4491: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4492: &mt('Stop balancing').'</label>'.
4493: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4494: $targets_div_style = 'display: block';
4495: $disabled_div_style = 'display: none';
4496: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4497: $homedom_div_style = 'display: block';
4498: }
4499: }
4500: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4501: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4502: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4503: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4504: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4505: my @sparestypes = ('primary','default');
4506: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 4507: my %hostherechecked = (
4508: no => ' checked="checked"',
4509: );
1.160.6.7 raeburn 4510: foreach my $sparetype (@sparestypes) {
4511: my $targettable;
4512: for (my $i=0; $i<$numspares; $i++) {
4513: my $checked;
4514: if (ref($currtargets{$lonhost}) eq 'HASH') {
4515: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4516: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4517: $checked = ' checked="checked"';
4518: }
4519: }
4520: }
4521: my ($chkboxval,$disabled);
4522: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4523: $chkboxval = $spares[$i];
4524: }
4525: if (exists($currbalancer{$spares[$i]})) {
4526: $disabled = ' disabled="disabled"';
4527: }
4528: $targettable .=
1.160.6.55 raeburn 4529: '<td><span class="LC_nobreak"><label>'.
4530: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 4531: $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 4532: '</span></label></span></td>';
1.160.6.7 raeburn 4533: my $rem = $i%($numinrow);
4534: if ($rem == 0) {
4535: if (($i > 0) && ($i < $numspares-1)) {
4536: $targettable .= '</tr>';
4537: }
4538: if ($i < $numspares-1) {
4539: $targettable .= '<tr>';
1.150 raeburn 4540: }
4541: }
4542: }
1.160.6.7 raeburn 4543: if ($targettable ne '') {
4544: my $rem = $numspares%($numinrow);
4545: my $colsleft = $numinrow - $rem;
4546: if ($colsleft > 1 ) {
4547: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4548: ' </td>';
4549: } elsif ($colsleft == 1) {
4550: $targettable .= '<td class="LC_left_item"> </td>';
4551: }
4552: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4553: '<table><tr>'.$targettable.'</tr></table><br />';
4554: }
1.160.6.76 raeburn 4555: $hostherechecked{$sparetype} = '';
4556: if (ref($currtargets{$lonhost}) eq 'HASH') {
4557: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4558: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4559: $hostherechecked{$sparetype} = ' checked="checked"';
4560: $hostherechecked{'no'} = '';
4561: }
4562: }
4563: }
4564: }
4565: $datatable .= &mt('Hosting on balancer itself').'<br />'.
4566: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
4567: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
4568: foreach my $sparetype (@sparestypes) {
4569: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
4570: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
4571: '</i></label><br />';
1.160.6.7 raeburn 4572: }
4573: $datatable .= '</div></td></tr>'.
4574: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4575: $othertitle,$usertypes,$types,\%servers,
4576: \%currbalancer,$lonhost,
4577: $targets_div_style,$homedom_div_style,
4578: $css_class[$cssidx],$balnum,$islast);
4579: $$rowtotal += $rownum;
4580: $balnum ++;
4581: }
4582: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4583: return $datatable;
4584: }
4585:
4586: sub get_loadbalancers_config {
4587: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4588: return unless ((ref($servers) eq 'HASH') &&
4589: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4590: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4591: if (keys(%{$existing}) > 0) {
4592: my $oldlonhost;
4593: foreach my $key (sort(keys(%{$existing}))) {
4594: if ($key eq 'lonhost') {
4595: $oldlonhost = $existing->{'lonhost'};
4596: $currbalancer->{$oldlonhost} = 1;
4597: } elsif ($key eq 'targets') {
4598: if ($oldlonhost) {
4599: $currtargets->{$oldlonhost} = $existing->{'targets'};
4600: }
4601: } elsif ($key eq 'rules') {
4602: if ($oldlonhost) {
4603: $currrules->{$oldlonhost} = $existing->{'rules'};
4604: }
4605: } elsif (ref($existing->{$key}) eq 'HASH') {
4606: $currbalancer->{$key} = 1;
4607: $currtargets->{$key} = $existing->{$key}{'targets'};
4608: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4609: }
4610: }
1.160.6.7 raeburn 4611: } else {
4612: my ($balancerref,$targetsref) =
4613: &Apache::lonnet::get_lonbalancer_config($servers);
4614: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4615: foreach my $server (sort(keys(%{$balancerref}))) {
4616: $currbalancer->{$server} = 1;
4617: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4618: }
4619: }
4620: }
1.160.6.7 raeburn 4621: return;
1.150 raeburn 4622: }
4623:
4624: sub loadbalancing_rules {
4625: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 4626: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4627: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4628: my $output;
1.160.6.7 raeburn 4629: my $num = 0;
4630: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4631: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4632: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4633: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 4634: $num ++;
1.150 raeburn 4635: my $current;
4636: if (ref($currrules) eq 'HASH') {
4637: $current = $currrules->{$type};
4638: }
1.160.6.55 raeburn 4639: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 4640: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4641: $current = '';
4642: }
4643: }
4644: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 4645: $servers,$currbalancer,$lonhost,$dom,
4646: $targets_div_style,$homedom_div_style,
4647: $css_class,$balnum,$num,$islast);
1.150 raeburn 4648: }
4649: }
4650: return $output;
4651: }
4652:
4653: sub loadbalancing_titles {
4654: my ($dom,$intdom,$usertypes,$types) = @_;
4655: my %othertypes = (
4656: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4657: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4658: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4659: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 4660: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4661: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4662: );
1.160.6.26 raeburn 4663: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 4664: my @available;
1.150 raeburn 4665: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 4666: @available = @{$types};
1.150 raeburn 4667: }
1.160.6.89 raeburn 4668: unless (grep(/^default$/,@available)) {
4669: push(@available,'default');
4670: }
4671: unshift(@alltypes,@available);
1.150 raeburn 4672: my %titles;
4673: foreach my $type (@alltypes) {
4674: if ($type =~ /^_LC_/) {
4675: $titles{$type} = $othertypes{$type};
4676: } elsif ($type eq 'default') {
4677: $titles{$type} = &mt('All users from [_1]',$dom);
4678: if (ref($types) eq 'ARRAY') {
4679: if (@{$types} > 0) {
4680: $titles{$type} = &mt('Other users from [_1]',$dom);
4681: }
4682: }
4683: } elsif (ref($usertypes) eq 'HASH') {
4684: $titles{$type} = $usertypes->{$type};
4685: }
4686: }
4687: return (\@alltypes,\%othertypes,\%titles);
4688: }
4689:
4690: sub loadbalance_rule_row {
1.160.6.7 raeburn 4691: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4692: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4693: my @rulenames;
1.150 raeburn 4694: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4695: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4696: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4697: } else {
1.160.6.26 raeburn 4698: @rulenames = ('default','homeserver');
4699: if ($type eq '_LC_external') {
4700: push(@rulenames,'externalbalancer');
4701: } else {
4702: push(@rulenames,'specific');
4703: }
4704: push(@rulenames,'none');
1.150 raeburn 4705: }
4706: my $style = $targets_div_style;
1.160.6.55 raeburn 4707: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4708: $style = $homedom_div_style;
4709: }
1.160.6.7 raeburn 4710: my $space;
4711: if ($islast && $num == 1) {
4712: $space = '<div display="inline-block"> </div>';
4713: }
4714: my $output =
4715: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4716: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4717: '<td valaign="top">'.$space.
4718: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4719: for (my $i=0; $i<@rulenames; $i++) {
4720: my $rule = $rulenames[$i];
4721: my ($checked,$extra);
4722: if ($rulenames[$i] eq 'default') {
4723: $rule = '';
4724: }
4725: if ($rulenames[$i] eq 'specific') {
4726: if (ref($servers) eq 'HASH') {
4727: my $default;
4728: if (($current ne '') && (exists($servers->{$current}))) {
4729: $checked = ' checked="checked"';
4730: }
4731: unless ($checked) {
4732: $default = ' selected="selected"';
4733: }
1.160.6.7 raeburn 4734: $extra =
4735: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4736: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4737: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4738: '<option value=""'.$default.'></option>'."\n";
4739: foreach my $server (sort(keys(%{$servers}))) {
4740: if (ref($currbalancer) eq 'HASH') {
4741: next if (exists($currbalancer->{$server}));
4742: }
1.150 raeburn 4743: my $selected;
1.160.6.7 raeburn 4744: if ($server eq $current) {
1.150 raeburn 4745: $selected = ' selected="selected"';
4746: }
1.160.6.7 raeburn 4747: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4748: }
4749: $extra .= '</select>';
4750: }
4751: } elsif ($rule eq $current) {
4752: $checked = ' checked="checked"';
4753: }
4754: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4755: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4756: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4757: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4758: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4759: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4760: $output .= $ruletitles{'particular'};
4761: } else {
4762: $output .= $ruletitles{$rulenames[$i]};
4763: }
4764: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4765: }
4766: $output .= '</div></td></tr>'."\n";
4767: return $output;
4768: }
4769:
4770: sub offloadtype_text {
4771: my %ruletitles = &Apache::lonlocal::texthash (
4772: 'default' => 'Offloads to default destinations',
4773: 'homeserver' => "Offloads to user's home server",
4774: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4775: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4776: 'none' => 'No offload',
1.160.6.26 raeburn 4777: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4778: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4779: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4780: );
4781: return %ruletitles;
4782: }
4783:
4784: sub sparestype_titles {
4785: my %typestitles = &Apache::lonlocal::texthash (
4786: 'primary' => 'primary',
4787: 'default' => 'default',
4788: );
4789: return %typestitles;
4790: }
4791:
1.28 raeburn 4792: sub contact_titles {
4793: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 4794: 'supportemail' => 'Support E-mail address',
4795: 'adminemail' => 'Default Server Admin E-mail address',
4796: 'errormail' => 'Error reports to be e-mailed to',
4797: 'packagesmail' => 'Package update alerts to be e-mailed to',
4798: 'helpdeskmail' => "Helpdesk requests for this domain's users",
4799: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
4800: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
4801: 'requestsmail' => 'E-mail from course requests requiring approval',
4802: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4803: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91! raeburn 4804: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.28 raeburn 4805: );
4806: my %short_titles = &Apache::lonlocal::texthash (
4807: adminemail => 'Admin E-mail address',
4808: supportemail => 'Support E-mail',
4809: );
4810: return (\%titles,\%short_titles);
4811: }
4812:
1.160.6.78 raeburn 4813: sub helpform_fields {
4814: my %titles = &Apache::lonlocal::texthash (
4815: 'username' => 'Name',
4816: 'user' => 'Username/domain',
4817: 'phone' => 'Phone',
4818: 'cc' => 'Cc e-mail',
4819: 'course' => 'Course Details',
4820: 'section' => 'Sections',
4821: 'screenshot' => 'File upload',
4822: );
4823: my @fields = ('username','phone','user','course','section','cc','screenshot');
4824: my %possoptions = (
4825: username => ['yes','no','req'],
4826: phone => ['yes','no','req'],
4827: user => ['yes','no'],
4828: cc => ['yes','no'],
4829: course => ['yes','no'],
4830: section => ['yes','no'],
4831: screenshot => ['yes','no'],
4832: );
4833: my %fieldoptions = &Apache::lonlocal::texthash (
4834: 'yes' => 'Optional',
4835: 'req' => 'Required',
4836: 'no' => "Not shown",
4837: );
4838: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
4839: }
4840:
1.72 raeburn 4841: sub tool_titles {
4842: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4843: aboutme => 'Personal web page',
1.86 raeburn 4844: blog => 'Blog',
1.160.6.4 raeburn 4845: webdav => 'WebDAV',
1.86 raeburn 4846: portfolio => 'Portfolio',
1.88 bisitz 4847: official => 'Official courses (with institutional codes)',
4848: unofficial => 'Unofficial courses',
1.98 raeburn 4849: community => 'Communities',
1.160.6.30 raeburn 4850: textbook => 'Textbook courses',
1.86 raeburn 4851: );
1.72 raeburn 4852: return %titles;
4853: }
4854:
1.101 raeburn 4855: sub courserequest_titles {
4856: my %titles = &Apache::lonlocal::texthash (
4857: official => 'Official',
4858: unofficial => 'Unofficial',
4859: community => 'Communities',
1.160.6.30 raeburn 4860: textbook => 'Textbook',
1.101 raeburn 4861: norequest => 'Not allowed',
1.104 raeburn 4862: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4863: validate => 'With validation',
4864: autolimit => 'Numerical limit',
1.103 raeburn 4865: unlimited => '(blank for unlimited)',
1.101 raeburn 4866: );
4867: return %titles;
4868: }
4869:
1.160.6.5 raeburn 4870: sub authorrequest_titles {
4871: my %titles = &Apache::lonlocal::texthash (
4872: norequest => 'Not allowed',
4873: approval => 'Approval by Dom. Coord.',
4874: automatic => 'Automatic approval',
4875: );
4876: return %titles;
4877: }
4878:
1.101 raeburn 4879: sub courserequest_conditions {
4880: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4881: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4882: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4883: );
4884: return %conditions;
4885: }
4886:
4887:
1.27 raeburn 4888: sub print_usercreation {
1.30 raeburn 4889: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4890: my $numinrow = 4;
1.28 raeburn 4891: my $datatable;
4892: if ($position eq 'top') {
1.30 raeburn 4893: $$rowtotal ++;
1.34 raeburn 4894: my $rowcount = 0;
1.32 raeburn 4895: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4896: if (ref($rules) eq 'HASH') {
4897: if (keys(%{$rules}) > 0) {
1.32 raeburn 4898: $datatable .= &user_formats_row('username',$settings,$rules,
4899: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4900: $$rowtotal ++;
1.32 raeburn 4901: $rowcount ++;
4902: }
4903: }
4904: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4905: if (ref($idrules) eq 'HASH') {
4906: if (keys(%{$idrules}) > 0) {
4907: $datatable .= &user_formats_row('id',$settings,$idrules,
4908: $idruleorder,$numinrow,$rowcount);
4909: $$rowtotal ++;
4910: $rowcount ++;
1.28 raeburn 4911: }
4912: }
1.39 raeburn 4913: if ($rowcount == 0) {
4914: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4915: $$rowtotal ++;
4916: $rowcount ++;
4917: }
1.34 raeburn 4918: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4919: my @creators = ('author','course','requestcrs');
1.37 raeburn 4920: my ($rules,$ruleorder) =
4921: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4922: my %lt = &usercreation_types();
4923: my %checked;
4924: if (ref($settings) eq 'HASH') {
4925: if (ref($settings->{'cancreate'}) eq 'HASH') {
4926: foreach my $item (@creators) {
4927: $checked{$item} = $settings->{'cancreate'}{$item};
4928: }
4929: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4930: foreach my $item (@creators) {
4931: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4932: $checked{$item} = 'none';
4933: }
4934: }
4935: }
4936: }
4937: my $rownum = 0;
4938: foreach my $item (@creators) {
4939: $rownum ++;
1.160.6.34 raeburn 4940: if ($checked{$item} eq '') {
4941: $checked{$item} = 'any';
1.34 raeburn 4942: }
4943: my $css_class;
4944: if ($rownum%2) {
4945: $css_class = '';
4946: } else {
4947: $css_class = ' class="LC_odd_row" ';
4948: }
4949: $datatable .= '<tr'.$css_class.'>'.
4950: '<td><span class="LC_nobreak">'.$lt{$item}.
4951: '</span></td><td align="right">';
1.160.6.34 raeburn 4952: my @options = ('any');
4953: if (ref($rules) eq 'HASH') {
4954: if (keys(%{$rules}) > 0) {
4955: push(@options,('official','unofficial'));
1.37 raeburn 4956: }
4957: }
1.160.6.34 raeburn 4958: push(@options,'none');
1.37 raeburn 4959: foreach my $option (@options) {
1.50 raeburn 4960: my $type = 'radio';
1.34 raeburn 4961: my $check = ' ';
1.160.6.34 raeburn 4962: if ($checked{$item} eq $option) {
4963: $check = ' checked="checked" ';
1.34 raeburn 4964: }
4965: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4966: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4967: $item.'" value="'.$option.'"'.$check.'/> '.
4968: $lt{$option}.'</label> </span>';
4969: }
4970: $datatable .= '</td></tr>';
4971: }
1.28 raeburn 4972: } else {
4973: my @contexts = ('author','course','domain');
4974: my @authtypes = ('int','krb4','krb5','loc');
4975: my %checked;
4976: if (ref($settings) eq 'HASH') {
4977: if (ref($settings->{'authtypes'}) eq 'HASH') {
4978: foreach my $item (@contexts) {
4979: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4980: foreach my $auth (@authtypes) {
4981: if ($settings->{'authtypes'}{$item}{$auth}) {
4982: $checked{$item}{$auth} = ' checked="checked" ';
4983: }
4984: }
4985: }
4986: }
1.27 raeburn 4987: }
1.35 raeburn 4988: } else {
4989: foreach my $item (@contexts) {
1.36 raeburn 4990: foreach my $auth (@authtypes) {
1.35 raeburn 4991: $checked{$item}{$auth} = ' checked="checked" ';
4992: }
4993: }
1.27 raeburn 4994: }
1.28 raeburn 4995: my %title = &context_names();
4996: my %authname = &authtype_names();
4997: my $rownum = 0;
4998: my $css_class;
4999: foreach my $item (@contexts) {
5000: if ($rownum%2) {
5001: $css_class = '';
5002: } else {
5003: $css_class = ' class="LC_odd_row" ';
5004: }
1.30 raeburn 5005: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 5006: '<td>'.$title{$item}.
5007: '</td><td class="LC_left_item">'.
5008: '<span class="LC_nobreak">';
5009: foreach my $auth (@authtypes) {
5010: $datatable .= '<label>'.
5011: '<input type="checkbox" name="'.$item.'_auth" '.
5012: $checked{$item}{$auth}.' value="'.$auth.'" />'.
5013: $authname{$auth}.'</label> ';
5014: }
5015: $datatable .= '</span></td></tr>';
5016: $rownum ++;
1.27 raeburn 5017: }
1.30 raeburn 5018: $$rowtotal += $rownum;
1.27 raeburn 5019: }
5020: return $datatable;
5021: }
5022:
1.160.6.34 raeburn 5023: sub print_selfcreation {
5024: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 5025: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 5026: if (ref($settings) eq 'HASH') {
5027: if (ref($settings->{'cancreate'}) eq 'HASH') {
5028: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 5029: if (ref($createsettings) eq 'HASH') {
5030: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
5031: @selfcreate = @{$createsettings->{'selfcreate'}};
5032: } elsif ($createsettings->{'selfcreate'} ne '') {
5033: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
5034: @selfcreate = ('email','login','sso');
5035: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5036: @selfcreate = ($createsettings->{'selfcreate'});
5037: }
5038: }
5039: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5040: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5041: }
5042: }
5043: }
5044: }
5045: my %radiohash;
5046: my $numinrow = 4;
5047: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 5048: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 5049: if ($position eq 'top') {
5050: my %choices = &Apache::lonlocal::texthash (
5051: cancreate_login => 'Institutional Login',
5052: cancreate_sso => 'Institutional Single Sign On',
5053: );
5054: my @toggles = sort(keys(%choices));
5055: my %defaultchecked = (
5056: 'cancreate_login' => 'off',
5057: 'cancreate_sso' => 'off',
5058: );
1.160.6.35 raeburn 5059: my ($onclick,$itemcount);
1.160.6.34 raeburn 5060: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5061: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5062: $$rowtotal += $itemcount;
1.160.6.34 raeburn 5063:
5064: if (ref($usertypes) eq 'HASH') {
5065: if (keys(%{$usertypes}) > 0) {
5066: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5067: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 5068: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 5069: $$rowtotal ++;
5070: }
5071: }
1.160.6.44 raeburn 5072: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5073: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5074: $fieldtitles{'inststatus'} = &mt('Institutional status');
5075: my $rem;
5076: my $numperrow = 2;
5077: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5078: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5079: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5080: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 5081: '<table>'."\n";
1.160.6.44 raeburn 5082: for (my $i=0; $i<@fields; $i++) {
5083: $rem = $i%($numperrow);
5084: if ($rem == 0) {
5085: if ($i > 0) {
5086: $datatable .= '</tr>';
5087: }
5088: $datatable .= '<tr>';
5089: }
5090: my $currval;
1.160.6.51 raeburn 5091: if (ref($createsettings) eq 'HASH') {
5092: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5093: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5094: }
1.160.6.44 raeburn 5095: }
5096: $datatable .= '<td class="LC_left_item">'.
5097: '<span class="LC_nobreak">'.
5098: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5099: 'value="'.$currval.'" size="10" /> '.
5100: $fieldtitles{$fields[$i]}.'</span></td>';
5101: }
5102: my $colsleft = $numperrow - $rem;
5103: if ($colsleft > 1 ) {
5104: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5105: ' </td>';
5106: } elsif ($colsleft == 1) {
5107: $datatable .= '<td class="LC_left_item"> </td>';
5108: }
5109: $datatable .= '</tr></table></td></tr>';
5110: $$rowtotal ++;
1.160.6.34 raeburn 5111: } elsif ($position eq 'middle') {
5112: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 5113: my @posstypes;
1.160.6.34 raeburn 5114: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 5115: @posstypes = @{$types};
5116: }
5117: unless (grep(/^default$/,@posstypes)) {
5118: push(@posstypes,'default');
5119: }
5120: my %usertypeshash;
5121: if (ref($usertypes) eq 'HASH') {
5122: %usertypeshash = %{$usertypes};
5123: }
5124: $usertypeshash{'default'} = $othertitle;
5125: foreach my $status (@posstypes) {
5126: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
5127: $numinrow,$$rowtotal,\%usertypeshash);
5128: $$rowtotal ++;
1.160.6.34 raeburn 5129: }
5130: } else {
1.160.6.40 raeburn 5131: my %choices = &Apache::lonlocal::texthash (
5132: cancreate_email => 'E-mail address as username',
5133: );
5134: my @toggles = sort(keys(%choices));
5135: my %defaultchecked = (
5136: 'cancreate_email' => 'off',
5137: );
5138: my $itemcount = 0;
5139: my $display = 'none';
5140: if (grep(/^\Qemail\E$/,@selfcreate)) {
5141: $display = 'block';
5142: }
5143: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5144: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5145: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.89 raeburn 5146: my (@ordered,%usertypeshash);
5147: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
5148: @ordered = @{$domdefaults{'inststatusguest'}};
5149: }
5150: if (@ordered) {
5151: unless (grep(/^default$/,@ordered)) {
5152: push(@ordered,'default');
5153: }
5154: if (ref($usertypes) eq 'HASH') {
5155: %usertypeshash = %{$usertypes};
5156: }
5157: $usertypeshash{'default'} = $othertitle;
5158: $additional .= '<table><tr>';
5159: foreach my $status (@ordered) {
5160: $additional .= '<th>'.$usertypeshash{$status}.'</th>';
1.160.6.34 raeburn 5161: }
1.160.6.89 raeburn 5162: $additional .= '</tr><tr>';
5163: foreach my $status (@ordered) {
5164: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
5165: }
5166: $additional .= '</tr></table>';
5167: } else {
5168: $usertypeshash{'default'} = $othertitle;
5169: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 5170: }
1.160.6.40 raeburn 5171: $additional .= '</div>'."\n";
5172:
5173: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 5174: \%choices,$$rowtotal,$onclick,$additional);
5175: $$rowtotal ++;
1.160.6.40 raeburn 5176: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 5177: $$rowtotal ++;
1.160.6.35 raeburn 5178: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5179: $numinrow = 1;
1.160.6.89 raeburn 5180: foreach my $status (@ordered) {
5181: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5182: $numinrow,$$rowtotal,\%usertypeshash,$infofields,$infotitles);
5183: $$rowtotal ++;
1.160.6.35 raeburn 5184: }
1.160.6.34 raeburn 5185: my ($emailrules,$emailruleorder) =
5186: &Apache::lonnet::inst_userrules($dom,'email');
5187: if (ref($emailrules) eq 'HASH') {
5188: if (keys(%{$emailrules}) > 0) {
5189: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 5190: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 5191: $$rowtotal ++;
5192: }
5193: }
1.160.6.35 raeburn 5194: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 5195: }
5196: return $datatable;
5197: }
5198:
1.160.6.40 raeburn 5199: sub email_as_username {
5200: my ($rowtotal,$processing,$type) = @_;
5201: my %choices =
5202: &Apache::lonlocal::texthash (
5203: automatic => 'Automatic approval',
5204: approval => 'Queued for approval',
5205: );
5206: my $output;
5207: foreach my $option ('automatic','approval') {
5208: my $checked;
5209: if (ref($processing) eq 'HASH') {
5210: if ($type eq '') {
5211: if (!exists($processing->{'default'})) {
5212: if ($option eq 'automatic') {
5213: $checked = ' checked="checked"';
5214: }
5215: } else {
5216: if ($processing->{'default'} eq $option) {
5217: $checked = ' checked="checked"';
5218: }
5219: }
5220: } else {
5221: if (!exists($processing->{$type})) {
5222: if ($option eq 'automatic') {
5223: $checked = ' checked="checked"';
5224: }
5225: } else {
5226: if ($processing->{$type} eq $option) {
5227: $checked = ' checked="checked"';
5228: }
5229: }
5230: }
5231: } elsif ($option eq 'automatic') {
5232: $checked = ' checked="checked"';
5233: }
5234: my $name = 'cancreate_emailprocess';
5235: if (($type ne '') && ($type ne 'default')) {
5236: $name .= '_'.$type;
5237: }
5238: $output .= '<span class="LC_nobreak"><label>'.
5239: '<input type="radio" name="'.$name.'"'.
5240: $checked.' value="'.$option.'" />'.
5241: $choices{$option}.'</label></span>';
5242: if ($type eq '') {
5243: $output .= ' ';
5244: } else {
5245: $output .= '<br />';
5246: }
5247: }
5248: $$rowtotal ++;
5249: return $output;
5250: }
5251:
1.160.6.5 raeburn 5252: sub captcha_choice {
5253: my ($context,$settings,$itemcount) = @_;
1.160.6.69 raeburn 5254: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5255: $vertext,$currver);
1.160.6.5 raeburn 5256: my %lt = &captcha_phrases();
5257: $keyentry = 'hidden';
5258: if ($context eq 'cancreate') {
1.160.6.34 raeburn 5259: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 5260: } elsif ($context eq 'login') {
5261: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5262: }
5263: if (ref($settings) eq 'HASH') {
5264: if ($settings->{'captcha'}) {
5265: $checked{$settings->{'captcha'}} = ' checked="checked"';
5266: } else {
5267: $checked{'original'} = ' checked="checked"';
5268: }
5269: if ($settings->{'captcha'} eq 'recaptcha') {
5270: $pubtext = $lt{'pub'};
5271: $privtext = $lt{'priv'};
5272: $keyentry = 'text';
1.160.6.69 raeburn 5273: $vertext = $lt{'ver'};
5274: $currver = $settings->{'recaptchaversion'};
5275: if ($currver ne '2') {
5276: $currver = 1;
5277: }
1.160.6.5 raeburn 5278: }
5279: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5280: $currpub = $settings->{'recaptchakeys'}{'public'};
5281: $currpriv = $settings->{'recaptchakeys'}{'private'};
5282: }
5283: } else {
5284: $checked{'original'} = ' checked="checked"';
5285: }
5286: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5287: my $output = '<tr'.$css_class.'>'.
5288: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5289: '<table><tr><td>'."\n";
5290: foreach my $option ('original','recaptcha','notused') {
5291: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5292: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5293: $lt{$option}.'</label></span>';
5294: unless ($option eq 'notused') {
5295: $output .= (' 'x2)."\n";
5296: }
5297: }
5298: #
5299: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5300: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5301: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5302: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5303: #
5304: $output .= '</td></tr>'."\n".
5305: '<tr><td>'."\n".
5306: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5307: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5308: $currpub.'" size="40" /></span><br />'."\n".
5309: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5310: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 5311: $currpriv.'" size="40" /></span><br />'.
5312: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5313: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5314: $currver.'" size="3" /></span><br />'.
5315: '</td></tr></table>'."\n".
1.160.6.5 raeburn 5316: '</td></tr>';
5317: return $output;
5318: }
5319:
1.32 raeburn 5320: sub user_formats_row {
5321: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5322: my $output;
5323: my %text = (
5324: 'username' => 'new usernames',
5325: 'id' => 'IDs',
1.45 raeburn 5326: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5327: );
5328: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5329: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5330: '<td><span class="LC_nobreak">';
5331: if ($type eq 'email') {
5332: $output .= &mt("Formats disallowed for $text{$type}: ");
5333: } else {
5334: $output .= &mt("Format rules to check for $text{$type}: ");
5335: }
5336: $output .= '</span></td>'.
5337: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5338: my $rem;
5339: if (ref($ruleorder) eq 'ARRAY') {
5340: for (my $i=0; $i<@{$ruleorder}; $i++) {
5341: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5342: my $rem = $i%($numinrow);
5343: if ($rem == 0) {
5344: if ($i > 0) {
5345: $output .= '</tr>';
5346: }
5347: $output .= '<tr>';
5348: }
5349: my $check = ' ';
1.39 raeburn 5350: if (ref($settings) eq 'HASH') {
5351: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5352: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5353: $check = ' checked="checked" ';
5354: }
1.27 raeburn 5355: }
5356: }
5357: $output .= '<td class="LC_left_item">'.
5358: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5359: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5360: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5361: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5362: }
5363: }
5364: $rem = @{$ruleorder}%($numinrow);
5365: }
5366: my $colsleft = $numinrow - $rem;
5367: if ($colsleft > 1 ) {
5368: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5369: ' </td>';
5370: } elsif ($colsleft == 1) {
5371: $output .= '<td class="LC_left_item"> </td>';
5372: }
5373: $output .= '</tr></table></td></tr>';
5374: return $output;
5375: }
5376:
1.34 raeburn 5377: sub usercreation_types {
5378: my %lt = &Apache::lonlocal::texthash (
5379: author => 'When adding a co-author',
5380: course => 'When adding a user to a course',
1.100 raeburn 5381: requestcrs => 'When requesting a course',
1.34 raeburn 5382: any => 'Any',
5383: official => 'Institutional only ',
5384: unofficial => 'Non-institutional only',
5385: none => 'None',
5386: );
5387: return %lt;
1.48 raeburn 5388: }
1.34 raeburn 5389:
1.160.6.34 raeburn 5390: sub selfcreation_types {
5391: my %lt = &Apache::lonlocal::texthash (
5392: selfcreate => 'User creates own account',
5393: any => 'Any',
5394: official => 'Institutional only ',
5395: unofficial => 'Non-institutional only',
5396: email => 'E-mail address',
5397: login => 'Institutional Login',
5398: sso => 'SSO',
5399: );
5400: }
5401:
1.28 raeburn 5402: sub authtype_names {
5403: my %lt = &Apache::lonlocal::texthash(
5404: int => 'Internal',
5405: krb4 => 'Kerberos 4',
5406: krb5 => 'Kerberos 5',
5407: loc => 'Local',
5408: );
5409: return %lt;
5410: }
5411:
5412: sub context_names {
5413: my %context_title = &Apache::lonlocal::texthash(
5414: author => 'Creating users when an Author',
5415: course => 'Creating users when in a course',
5416: domain => 'Creating users when a Domain Coordinator',
5417: );
5418: return %context_title;
5419: }
5420:
1.33 raeburn 5421: sub print_usermodification {
5422: my ($position,$dom,$settings,$rowtotal) = @_;
5423: my $numinrow = 4;
5424: my ($context,$datatable,$rowcount);
5425: if ($position eq 'top') {
5426: $rowcount = 0;
5427: $context = 'author';
5428: foreach my $role ('ca','aa') {
5429: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5430: $numinrow,$rowcount);
5431: $$rowtotal ++;
5432: $rowcount ++;
5433: }
1.160.6.37 raeburn 5434: } elsif ($position eq 'bottom') {
1.33 raeburn 5435: $context = 'course';
5436: $rowcount = 0;
5437: foreach my $role ('st','ep','ta','in','cr') {
5438: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5439: $numinrow,$rowcount);
5440: $$rowtotal ++;
5441: $rowcount ++;
5442: }
5443: }
5444: return $datatable;
5445: }
5446:
1.43 raeburn 5447: sub print_defaults {
1.160.6.40 raeburn 5448: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5449: my $rownum = 0;
1.160.6.80 raeburn 5450: my ($datatable,$css_class,$titles);
5451: unless ($position eq 'bottom') {
5452: $titles = &defaults_titles($dom);
5453: }
1.160.6.40 raeburn 5454: if ($position eq 'top') {
5455: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5456: 'datelocale_def','portal_def');
5457: my %defaults;
5458: if (ref($settings) eq 'HASH') {
5459: %defaults = %{$settings};
1.43 raeburn 5460: } else {
1.160.6.40 raeburn 5461: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5462: foreach my $item (@items) {
5463: $defaults{$item} = $domdefaults{$item};
5464: }
1.43 raeburn 5465: }
1.160.6.40 raeburn 5466: foreach my $item (@items) {
5467: if ($rownum%2) {
5468: $css_class = '';
5469: } else {
5470: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 5471: }
1.160.6.40 raeburn 5472: $datatable .= '<tr'.$css_class.'>'.
5473: '<td><span class="LC_nobreak">'.$titles->{$item}.
5474: '</span></td><td class="LC_right_item" colspan="3">';
5475: if ($item eq 'auth_def') {
5476: my @authtypes = ('internal','krb4','krb5','localauth');
5477: my %shortauth = (
5478: internal => 'int',
5479: krb4 => 'krb4',
5480: krb5 => 'krb5',
5481: localauth => 'loc'
5482: );
5483: my %authnames = &authtype_names();
5484: foreach my $auth (@authtypes) {
5485: my $checked = ' ';
5486: if ($defaults{$item} eq $auth) {
5487: $checked = ' checked="checked" ';
5488: }
5489: $datatable .= '<label><input type="radio" name="'.$item.
5490: '" value="'.$auth.'"'.$checked.'/>'.
5491: $authnames{$shortauth{$auth}}.'</label> ';
5492: }
5493: } elsif ($item eq 'timezone_def') {
5494: my $includeempty = 1;
5495: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5496: } elsif ($item eq 'datelocale_def') {
5497: my $includeempty = 1;
5498: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5499: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 5500: my $includeempty = 1;
5501: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 5502: } else {
5503: my $size;
5504: if ($item eq 'portal_def') {
5505: $size = ' size="25"';
5506: }
5507: $datatable .= '<input type="text" name="'.$item.'" value="'.
5508: $defaults{$item}.'"'.$size.' />';
5509: }
5510: $datatable .= '</td></tr>';
5511: $rownum ++;
5512: }
1.160.6.80 raeburn 5513: } elsif ($position eq 'middle') {
5514: my @items = ('intauth_cost','intauth_check','intauth_switch');
5515: my %defaults;
5516: if (ref($settings) eq 'HASH') {
5517: %defaults = %{$settings};
5518: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5519: $defaults{'intauth_cost'} = 10;
5520: }
5521: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5522: $defaults{'intauth_check'} = 0;
5523: }
5524: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5525: $defaults{'intauth_switch'} = 0;
5526: }
5527: } else {
5528: %defaults = (
5529: 'intauth_cost' => 10,
5530: 'intauth_check' => 0,
5531: 'intauth_switch' => 0,
5532: );
5533: }
5534: foreach my $item (@items) {
5535: if ($rownum%2) {
5536: $css_class = '';
5537: } else {
5538: $css_class = ' class="LC_odd_row" ';
5539: }
5540: $datatable .= '<tr'.$css_class.'>'.
5541: '<td><span class="LC_nobreak">'.$titles->{$item}.
5542: '</span></td><td class="LC_left_item" colspan="3">';
5543: if ($item eq 'intauth_switch') {
5544: my @options = (0,1,2);
5545: my %optiondesc = &Apache::lonlocal::texthash (
5546: 0 => 'No',
5547: 1 => 'Yes',
5548: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5549: );
5550: $datatable .= '<table width="100%">';
5551: foreach my $option (@options) {
5552: my $checked = ' ';
5553: if ($defaults{$item} eq $option) {
5554: $checked = ' checked="checked"';
5555: }
5556: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5557: '<label><input type="radio" name="'.$item.
5558: '" value="'.$option.'"'.$checked.' />'.
5559: $optiondesc{$option}.'</label></span></td></tr>';
5560: }
5561: $datatable .= '</table>';
5562: } elsif ($item eq 'intauth_check') {
5563: my @options = (0,1,2);
5564: my %optiondesc = &Apache::lonlocal::texthash (
5565: 0 => 'No',
5566: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5567: 2 => 'Yes, disallow login if stored cost is less than domain default',
5568: );
1.160.6.87 raeburn 5569: $datatable .= '<table width="100%">';
1.160.6.80 raeburn 5570: foreach my $option (@options) {
5571: my $checked = ' ';
5572: my $onclick;
5573: if ($defaults{$item} eq $option) {
5574: $checked = ' checked="checked"';
5575: }
5576: if ($option == 2) {
5577: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5578: }
5579: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5580: '<label><input type="radio" name="'.$item.
5581: '" value="'.$option.'"'.$checked.$onclick.' />'.
5582: $optiondesc{$option}.'</label></span></td></tr>';
5583: }
5584: $datatable .= '</table>';
5585: } else {
5586: $datatable .= '<input type="text" name="'.$item.'" value="'.
5587: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5588: }
5589: $datatable .= '</td></tr>';
5590: $rownum ++;
5591: }
1.160.6.40 raeburn 5592: } else {
1.160.6.80 raeburn 5593: my %defaults;
1.160.6.40 raeburn 5594: if (ref($settings) eq 'HASH') {
5595: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5596: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5597: my $maxnum = @{$settings->{'inststatusorder'}};
5598: for (my $i=0; $i<$maxnum; $i++) {
5599: $css_class = $rownum%2?' class="LC_odd_row"':'';
5600: my $item = $settings->{'inststatusorder'}->[$i];
5601: my $title = $settings->{'inststatustypes'}->{$item};
5602: my $guestok;
5603: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5604: $guestok = 1;
5605: }
5606: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5607: $datatable .= '<tr'.$css_class.'>'.
5608: '<td><span class="LC_nobreak">'.
5609: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5610: for (my $k=0; $k<=$maxnum; $k++) {
5611: my $vpos = $k+1;
5612: my $selstr;
5613: if ($k == $i) {
5614: $selstr = ' selected="selected" ';
5615: }
5616: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5617: }
5618: my ($checkedon,$checkedoff);
5619: $checkedoff = ' checked="checked"';
5620: if ($guestok) {
5621: $checkedon = $checkedoff;
5622: $checkedoff = '';
5623: }
5624: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5625: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5626: &mt('delete').'</span></td>'.
5627: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5628: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5629: '</span></td>'.
5630: '<td class="LC_right_item"><span class="LC_nobreak">'.
5631: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5632: &mt('Yes').'</label>'.(' 'x2).
5633: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5634: &mt('No').'</label></span></td></tr>';
5635: }
5636: $css_class = $rownum%2?' class="LC_odd_row"':'';
5637: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5638: $datatable .= '<tr '.$css_class.'>'.
5639: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5640: for (my $k=0; $k<=$maxnum; $k++) {
5641: my $vpos = $k+1;
5642: my $selstr;
5643: if ($k == $maxnum) {
5644: $selstr = ' selected="selected" ';
5645: }
5646: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5647: }
5648: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 5649: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 5650: ' '.&mt('(new)').
5651: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5652: &mt('Name displayed:').
5653: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5654: '<td class="LC_right_item"><span class="LC_nobreak">'.
5655: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5656: &mt('Yes').'</label>'.(' 'x2).
5657: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5658: &mt('No').'</label></span></td></tr>';
5659: '</tr>'."\n";
5660: $rownum ++;
1.141 raeburn 5661: }
1.43 raeburn 5662: }
5663: }
5664: $$rowtotal += $rownum;
5665: return $datatable;
5666: }
5667:
1.160.6.5 raeburn 5668: sub get_languages_hash {
5669: my %langchoices;
5670: foreach my $id (&Apache::loncommon::languageids()) {
5671: my $code = &Apache::loncommon::supportedlanguagecode($id);
5672: if ($code ne '') {
5673: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5674: }
5675: }
5676: return %langchoices;
5677: }
5678:
1.43 raeburn 5679: sub defaults_titles {
1.141 raeburn 5680: my ($dom) = @_;
1.43 raeburn 5681: my %titles = &Apache::lonlocal::texthash (
5682: 'auth_def' => 'Default authentication type',
5683: 'auth_arg_def' => 'Default authentication argument',
5684: 'lang_def' => 'Default language',
1.54 raeburn 5685: 'timezone_def' => 'Default timezone',
1.68 raeburn 5686: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5687: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 5688: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
5689: 'intauth_check' => 'Check bcrypt cost if authenticated',
5690: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 5691: );
1.141 raeburn 5692: if ($dom) {
5693: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5694: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5695: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5696: $protocol = 'http' if ($protocol ne 'https');
5697: if ($uint_dom) {
5698: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5699: $uint_dom);
5700: }
5701: }
1.43 raeburn 5702: return (\%titles);
5703: }
5704:
1.46 raeburn 5705: sub print_scantronformat {
5706: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5707: my $itemcount = 1;
1.60 raeburn 5708: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5709: %confhash);
1.46 raeburn 5710: my $switchserver = &check_switchserver($dom,$confname);
5711: my %lt = &Apache::lonlocal::texthash (
1.95 www 5712: default => 'Default bubblesheet format file error',
5713: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5714: );
5715: my %scantronfiles = (
5716: default => 'default.tab',
5717: custom => 'custom.tab',
5718: );
5719: foreach my $key (keys(%scantronfiles)) {
5720: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5721: .$scantronfiles{$key};
5722: }
5723: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5724: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5725: if (!$switchserver) {
5726: my $servadm = $r->dir_config('lonAdmEMail');
5727: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5728: if ($configuserok eq 'ok') {
5729: if ($author_ok eq 'ok') {
5730: my %legacyfile = (
5731: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5732: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5733: );
5734: my %md5chk;
5735: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5736: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5737: chomp($md5chk{$type});
1.46 raeburn 5738: }
5739: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5740: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5741: ($scantronurls{$type},my $error) =
1.46 raeburn 5742: &legacy_scantronformat($r,$dom,$confname,
5743: $type,$legacyfile{$type},
5744: $scantronurls{$type},
5745: $scantronfiles{$type});
1.60 raeburn 5746: if ($error ne '') {
5747: $error{$type} = $error;
5748: }
5749: }
5750: if (keys(%error) == 0) {
5751: $is_custom = 1;
5752: $confhash{'scantron'}{'scantronformat'} =
5753: $scantronurls{'custom'};
5754: my $putresult =
5755: &Apache::lonnet::put_dom('configuration',
5756: \%confhash,$dom);
5757: if ($putresult ne 'ok') {
5758: $error{'custom'} =
5759: '<span class="LC_error">'.
5760: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5761: }
1.46 raeburn 5762: }
5763: } else {
1.60 raeburn 5764: ($scantronurls{'default'},my $error) =
1.46 raeburn 5765: &legacy_scantronformat($r,$dom,$confname,
5766: 'default',$legacyfile{'default'},
5767: $scantronurls{'default'},
5768: $scantronfiles{'default'});
1.60 raeburn 5769: if ($error eq '') {
5770: $confhash{'scantron'}{'scantronformat'} = '';
5771: my $putresult =
5772: &Apache::lonnet::put_dom('configuration',
5773: \%confhash,$dom);
5774: if ($putresult ne 'ok') {
5775: $error{'default'} =
5776: '<span class="LC_error">'.
5777: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5778: }
5779: } else {
5780: $error{'default'} = $error;
5781: }
1.46 raeburn 5782: }
5783: }
5784: }
5785: } else {
1.95 www 5786: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5787: }
5788: }
5789: if (ref($settings) eq 'HASH') {
5790: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5791: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5792: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5793: $scantronurl = '';
5794: } else {
5795: $scantronurl = $settings->{'scantronformat'};
5796: }
5797: $is_custom = 1;
5798: } else {
5799: $scantronurl = $scantronurls{'default'};
5800: }
5801: } else {
1.60 raeburn 5802: if ($is_custom) {
5803: $scantronurl = $scantronurls{'custom'};
5804: } else {
5805: $scantronurl = $scantronurls{'default'};
5806: }
1.46 raeburn 5807: }
5808: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5809: $datatable .= '<tr'.$css_class.'>';
5810: if (!$is_custom) {
1.65 raeburn 5811: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5812: '<span class="LC_nobreak">';
1.46 raeburn 5813: if ($scantronurl) {
1.160.6.21 raeburn 5814: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5815: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5816: } else {
5817: $datatable = &mt('File unavailable for display');
5818: }
1.65 raeburn 5819: $datatable .= '</span></td>';
1.60 raeburn 5820: if (keys(%error) == 0) {
5821: $datatable .= '<td valign="bottom">';
5822: if (!$switchserver) {
5823: $datatable .= &mt('Upload:').'<br />';
5824: }
5825: } else {
5826: my $errorstr;
5827: foreach my $key (sort(keys(%error))) {
5828: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5829: }
5830: $datatable .= '<td>'.$errorstr;
5831: }
1.46 raeburn 5832: } else {
5833: if (keys(%error) > 0) {
5834: my $errorstr;
5835: foreach my $key (sort(keys(%error))) {
5836: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5837: }
1.60 raeburn 5838: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5839: } elsif ($scantronurl) {
1.160.6.26 raeburn 5840: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 5841: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5842: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 5843: $link.
5844: '<label><input type="checkbox" name="scantronformat_del"'.
5845: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5846: '<td><span class="LC_nobreak"> '.
5847: &mt('Replace:').'</span><br />';
1.46 raeburn 5848: }
5849: }
5850: if (keys(%error) == 0) {
5851: if ($switchserver) {
5852: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5853: } else {
1.65 raeburn 5854: $datatable .='<span class="LC_nobreak"> '.
5855: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5856: }
5857: }
5858: $datatable .= '</td></tr>';
5859: $$rowtotal ++;
5860: return $datatable;
5861: }
5862:
5863: sub legacy_scantronformat {
5864: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5865: my ($url,$error);
5866: my @statinfo = &Apache::lonnet::stat_file($newurl);
5867: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5868: (my $result,$url) =
5869: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5870: '','',$newfile);
5871: if ($result ne 'ok') {
1.130 raeburn 5872: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5873: }
5874: }
5875: return ($url,$error);
5876: }
1.43 raeburn 5877:
1.49 raeburn 5878: sub print_coursecategories {
1.57 raeburn 5879: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5880: my $datatable;
5881: if ($position eq 'top') {
1.160.6.42 raeburn 5882: my (%checked);
5883: my @catitems = ('unauth','auth');
5884: my @cattypes = ('std','domonly','codesrch','none');
5885: $checked{'unauth'} = 'std';
5886: $checked{'auth'} = 'std';
5887: if (ref($settings) eq 'HASH') {
5888: foreach my $type (@cattypes) {
5889: if ($type eq $settings->{'unauth'}) {
5890: $checked{'unauth'} = $type;
5891: }
5892: if ($type eq $settings->{'auth'}) {
5893: $checked{'auth'} = $type;
5894: }
5895: }
5896: }
5897: my %lt = &Apache::lonlocal::texthash (
5898: unauth => 'Catalog type for unauthenticated users',
5899: auth => 'Catalog type for authenticated users',
5900: none => 'No catalog',
5901: std => 'Standard catalog',
5902: domonly => 'Domain-only catalog',
5903: codesrch => "Code search form",
5904: );
5905: my $itemcount = 0;
5906: foreach my $item (@catitems) {
5907: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5908: $datatable .= '<tr '.$css_class.'>'.
5909: '<td>'.$lt{$item}.'</td>'.
5910: '<td class="LC_right_item"><span class="LC_nobreak">';
5911: foreach my $type (@cattypes) {
5912: my $ischecked;
5913: if ($checked{$item} eq $type) {
5914: $ischecked=' checked="checked"';
5915: }
5916: $datatable .= '<label>'.
5917: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5918: ' />'.$lt{$type}.'</label> ';
5919: }
1.160.6.87 raeburn 5920: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 5921: $itemcount ++;
5922: }
5923: $$rowtotal += $itemcount;
5924: } elsif ($position eq 'middle') {
1.57 raeburn 5925: my $toggle_cats_crs = ' ';
5926: my $toggle_cats_dom = ' checked="checked" ';
5927: my $can_cat_crs = ' ';
5928: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5929: my $toggle_catscomm_comm = ' ';
5930: my $toggle_catscomm_dom = ' checked="checked" ';
5931: my $can_catcomm_comm = ' ';
5932: my $can_catcomm_dom = ' checked="checked" ';
5933:
1.57 raeburn 5934: if (ref($settings) eq 'HASH') {
5935: if ($settings->{'togglecats'} eq 'crs') {
5936: $toggle_cats_crs = $toggle_cats_dom;
5937: $toggle_cats_dom = ' ';
5938: }
5939: if ($settings->{'categorize'} eq 'crs') {
5940: $can_cat_crs = $can_cat_dom;
5941: $can_cat_dom = ' ';
5942: }
1.120 raeburn 5943: if ($settings->{'togglecatscomm'} eq 'comm') {
5944: $toggle_catscomm_comm = $toggle_catscomm_dom;
5945: $toggle_catscomm_dom = ' ';
5946: }
5947: if ($settings->{'categorizecomm'} eq 'comm') {
5948: $can_catcomm_comm = $can_catcomm_dom;
5949: $can_catcomm_dom = ' ';
5950: }
1.57 raeburn 5951: }
5952: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5953: togglecats => 'Show/Hide a course in catalog',
5954: togglecatscomm => 'Show/Hide a community in catalog',
5955: categorize => 'Assign a category to a course',
5956: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5957: );
5958: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5959: dom => 'Set in Domain',
5960: crs => 'Set in Course',
5961: comm => 'Set in Community',
1.57 raeburn 5962: );
5963: $datatable = '<tr class="LC_odd_row">'.
5964: '<td>'.$title{'togglecats'}.'</td>'.
5965: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5966: '<input type="radio" name="togglecats"'.
5967: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5968: '<label><input type="radio" name="togglecats"'.
5969: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5970: '</tr><tr>'.
5971: '<td>'.$title{'categorize'}.'</td>'.
5972: '<td class="LC_right_item"><span class="LC_nobreak">'.
5973: '<label><input type="radio" name="categorize"'.
5974: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5975: '<label><input type="radio" name="categorize"'.
5976: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5977: '</tr><tr class="LC_odd_row">'.
5978: '<td>'.$title{'togglecatscomm'}.'</td>'.
5979: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5980: '<input type="radio" name="togglecatscomm"'.
5981: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5982: '<label><input type="radio" name="togglecatscomm"'.
5983: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5984: '</tr><tr>'.
5985: '<td>'.$title{'categorizecomm'}.'</td>'.
5986: '<td class="LC_right_item"><span class="LC_nobreak">'.
5987: '<label><input type="radio" name="categorizecomm"'.
5988: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5989: '<label><input type="radio" name="categorizecomm"'.
5990: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5991: '</tr>';
1.120 raeburn 5992: $$rowtotal += 4;
1.57 raeburn 5993: } else {
5994: my $css_class;
5995: my $itemcount = 1;
5996: my $cathash;
5997: if (ref($settings) eq 'HASH') {
5998: $cathash = $settings->{'cats'};
5999: }
6000: if (ref($cathash) eq 'HASH') {
6001: my (@cats,@trails,%allitems,%idx,@jsarray);
6002: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
6003: \%allitems,\%idx,\@jsarray);
6004: my $maxdepth = scalar(@cats);
6005: my $colattrib = '';
6006: if ($maxdepth > 2) {
6007: $colattrib = ' colspan="2" ';
6008: }
6009: my @path;
6010: if (@cats > 0) {
6011: if (ref($cats[0]) eq 'ARRAY') {
6012: my $numtop = @{$cats[0]};
6013: my $maxnum = $numtop;
1.120 raeburn 6014: my %default_names = (
6015: instcode => &mt('Official courses'),
6016: communities => &mt('Communities'),
6017: );
6018:
6019: if ((!grep(/^instcode$/,@{$cats[0]})) ||
6020: ($cathash->{'instcode::0'} eq '') ||
6021: (!grep(/^communities$/,@{$cats[0]})) ||
6022: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 6023: $maxnum ++;
6024: }
6025: my $lastidx;
6026: for (my $i=0; $i<$numtop; $i++) {
6027: my $parent = $cats[0][$i];
6028: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6029: my $item = &escape($parent).'::0';
6030: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
6031: $lastidx = $idx{$item};
6032: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6033: .'<select name="'.$item.'"'.$chgstr.'>';
6034: for (my $k=0; $k<=$maxnum; $k++) {
6035: my $vpos = $k+1;
6036: my $selstr;
6037: if ($k == $i) {
6038: $selstr = ' selected="selected" ';
6039: }
6040: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6041: }
1.160.6.29 raeburn 6042: $datatable .= '</select></span></td><td>';
1.120 raeburn 6043: if ($parent eq 'instcode' || $parent eq 'communities') {
6044: $datatable .= '<span class="LC_nobreak">'
6045: .$default_names{$parent}.'</span>';
6046: if ($parent eq 'instcode') {
6047: $datatable .= '<br /><span class="LC_nobreak">('
6048: .&mt('with institutional codes')
6049: .')</span></td><td'.$colattrib.'>';
6050: } else {
6051: $datatable .= '<table><tr><td>';
6052: }
6053: $datatable .= '<span class="LC_nobreak">'
6054: .'<label><input type="radio" name="'
6055: .$parent.'" value="1" checked="checked" />'
6056: .&mt('Display').'</label>';
6057: if ($parent eq 'instcode') {
6058: $datatable .= ' ';
6059: } else {
6060: $datatable .= '</span></td></tr><tr><td>'
6061: .'<span class="LC_nobreak">';
6062: }
6063: $datatable .= '<label><input type="radio" name="'
6064: .$parent.'" value="0" />'
6065: .&mt('Do not display').'</label></span>';
6066: if ($parent eq 'communities') {
6067: $datatable .= '</td></tr></table>';
6068: }
6069: $datatable .= '</td>';
1.57 raeburn 6070: } else {
6071: $datatable .= $parent
1.160.6.29 raeburn 6072: .' <span class="LC_nobreak"><label>'
6073: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6074: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6075: }
6076: my $depth = 1;
6077: push(@path,$parent);
6078: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6079: pop(@path);
6080: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6081: $itemcount ++;
6082: }
1.48 raeburn 6083: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6084: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6085: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6086: for (my $k=0; $k<=$maxnum; $k++) {
6087: my $vpos = $k+1;
6088: my $selstr;
1.57 raeburn 6089: if ($k == $numtop) {
1.48 raeburn 6090: $selstr = ' selected="selected" ';
6091: }
6092: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6093: }
1.59 bisitz 6094: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6095: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6096: .'</tr>'."\n";
1.48 raeburn 6097: $itemcount ++;
1.120 raeburn 6098: foreach my $default ('instcode','communities') {
6099: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6100: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6101: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6102: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6103: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6104: for (my $k=0; $k<=$maxnum; $k++) {
6105: my $vpos = $k+1;
6106: my $selstr;
6107: if ($k == $maxnum) {
6108: $selstr = ' selected="selected" ';
6109: }
6110: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6111: }
1.120 raeburn 6112: $datatable .= '</select></span></td>'.
6113: '<td><span class="LC_nobreak">'.
6114: $default_names{$default}.'</span>';
6115: if ($default eq 'instcode') {
6116: $datatable .= '<br /><span class="LC_nobreak">('
6117: .&mt('with institutional codes').')</span>';
6118: }
6119: $datatable .= '</td>'
6120: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6121: .&mt('Display').'</label> '
6122: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6123: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6124: }
6125: }
6126: }
1.57 raeburn 6127: } else {
6128: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6129: }
6130: } else {
1.160.6.87 raeburn 6131: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 6132: .&initialize_categories($itemcount);
1.48 raeburn 6133: }
1.57 raeburn 6134: $$rowtotal += $itemcount;
1.48 raeburn 6135: }
6136: return $datatable;
6137: }
6138:
1.69 raeburn 6139: sub print_serverstatuses {
6140: my ($dom,$settings,$rowtotal) = @_;
6141: my $datatable;
6142: my @pages = &serverstatus_pages();
6143: my (%namedaccess,%machineaccess);
6144: foreach my $type (@pages) {
6145: $namedaccess{$type} = '';
6146: $machineaccess{$type}= '';
6147: }
6148: if (ref($settings) eq 'HASH') {
6149: foreach my $type (@pages) {
6150: if (exists($settings->{$type})) {
6151: if (ref($settings->{$type}) eq 'HASH') {
6152: foreach my $key (keys(%{$settings->{$type}})) {
6153: if ($key eq 'namedusers') {
6154: $namedaccess{$type} = $settings->{$type}->{$key};
6155: } elsif ($key eq 'machines') {
6156: $machineaccess{$type} = $settings->{$type}->{$key};
6157: }
6158: }
6159: }
6160: }
6161: }
6162: }
1.81 raeburn 6163: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6164: my $rownum = 0;
6165: my $css_class;
6166: foreach my $type (@pages) {
6167: $rownum ++;
6168: $css_class = $rownum%2?' class="LC_odd_row"':'';
6169: $datatable .= '<tr'.$css_class.'>'.
6170: '<td><span class="LC_nobreak">'.
6171: $titles->{$type}.'</span></td>'.
6172: '<td class="LC_left_item">'.
6173: '<input type="text" name="'.$type.'_namedusers" '.
6174: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6175: '<td class="LC_right_item">'.
6176: '<span class="LC_nobreak">'.
6177: '<input type="text" name="'.$type.'_machines" '.
6178: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 6179: '</span></td></tr>'."\n";
1.69 raeburn 6180: }
6181: $$rowtotal += $rownum;
6182: return $datatable;
6183: }
6184:
6185: sub serverstatus_pages {
6186: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 6187: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 6188: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 6189: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6190: }
6191:
1.160.6.40 raeburn 6192: sub defaults_javascript {
6193: my ($settings) = @_;
1.160.6.80 raeburn 6194: 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.');
6195: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6196: &js_escape(\$intauthcheck);
6197: &js_escape(\$intauthcost);
6198: my $intauthjs = <<"ENDSCRIPT";
6199:
6200: function warnIntAuth(field) {
6201: if (field.name == 'intauth_check') {
6202: if (field.value == '2') {
6203: alert('$intauthcheck');
6204: }
6205: }
6206: if (field.name == 'intauth_cost') {
6207: field.value.replace(/\s/g,'');
6208: if (field.value != '') {
6209: var regexdigit=/^\\d+\$/;
6210: if (!regexdigit.test(field.value)) {
6211: alert('$intauthcost');
6212: }
6213: }
6214: }
6215: return;
6216: }
6217:
6218: ENDSCRIPT
6219:
6220: if (ref($settings) ne 'HASH') {
6221: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6222: }
1.160.6.40 raeburn 6223: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6224: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6225: if ($maxnum eq '') {
6226: $maxnum = 0;
6227: }
6228: $maxnum ++;
1.160.6.51 raeburn 6229: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 6230: return <<"ENDSCRIPT";
6231: <script type="text/javascript">
6232: // <![CDATA[
6233: function reorderTypes(form,caller) {
6234: var changedVal;
6235: $jstext
6236: var newpos = 'addinststatus_pos';
6237: var current = new Array;
6238: var maxh = $maxnum;
6239: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6240: var oldVal;
6241: if (caller == newpos) {
6242: changedVal = newitemVal;
6243: } else {
6244: var curritem = 'inststatus_pos_'+caller;
6245: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6246: current[newitemVal] = newpos;
6247: }
6248: for (var i=0; i<inststatuses.length; i++) {
6249: if (inststatuses[i] != caller) {
6250: var elementName = 'inststatus_pos_'+inststatuses[i];
6251: if (form.elements[elementName]) {
6252: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6253: current[currVal] = elementName;
6254: }
6255: }
6256: }
6257: for (var j=0; j<maxh; j++) {
6258: if (current[j] == undefined) {
6259: oldVal = j;
6260: }
6261: }
6262: if (oldVal < changedVal) {
6263: for (var k=oldVal+1; k<=changedVal ; k++) {
6264: var elementName = current[k];
6265: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6266: }
6267: } else {
6268: for (var k=changedVal; k<oldVal; k++) {
6269: var elementName = current[k];
6270: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6271: }
6272: }
6273: return;
6274: }
6275:
1.160.6.80 raeburn 6276: $intauthjs
6277:
1.160.6.40 raeburn 6278: // ]]>
6279: </script>
6280:
6281: ENDSCRIPT
1.160.6.80 raeburn 6282: } else {
6283: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40 raeburn 6284: }
6285: }
6286:
1.49 raeburn 6287: sub coursecategories_javascript {
6288: my ($settings) = @_;
1.57 raeburn 6289: my ($output,$jstext,$cathash);
1.49 raeburn 6290: if (ref($settings) eq 'HASH') {
1.57 raeburn 6291: $cathash = $settings->{'cats'};
6292: }
6293: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6294: my (@cats,@jsarray,%idx);
1.57 raeburn 6295: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6296: if (@jsarray > 0) {
6297: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6298: for (my $i=0; $i<@jsarray; $i++) {
6299: if (ref($jsarray[$i]) eq 'ARRAY') {
6300: my $catstr = join('","',@{$jsarray[$i]});
6301: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6302: }
6303: }
6304: }
6305: } else {
6306: $jstext = ' var categories = Array(1);'."\n".
6307: ' categories[0] = Array("instcode_pos");'."\n";
6308: }
1.160.6.42 raeburn 6309: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6310: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 6311: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6312: &js_escape(\$instcode_reserved);
6313: &js_escape(\$communities_reserved);
6314: &js_escape(\$choose_again);
1.49 raeburn 6315: $output = <<"ENDSCRIPT";
6316: <script type="text/javascript">
1.109 raeburn 6317: // <![CDATA[
1.49 raeburn 6318: function reorderCats(form,parent,item,idx) {
6319: var changedVal;
6320: $jstext
6321: var newpos = 'addcategory_pos';
6322: if (parent == '') {
6323: var has_instcode = 0;
6324: var maxtop = categories[idx].length;
6325: for (var j=0; j<maxtop; j++) {
6326: if (categories[idx][j] == 'instcode::0') {
6327: has_instcode == 1;
6328: }
6329: }
6330: if (has_instcode == 0) {
6331: categories[idx][maxtop] = 'instcode_pos';
6332: }
6333: } else {
6334: newpos += '_'+parent;
6335: }
6336: var maxh = 1 + categories[idx].length;
6337: var current = new Array;
6338: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6339: if (item == newpos) {
6340: changedVal = newitemVal;
6341: } else {
6342: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6343: current[newitemVal] = newpos;
6344: }
6345: for (var i=0; i<categories[idx].length; i++) {
6346: var elementName = categories[idx][i];
6347: if (elementName != item) {
6348: if (form.elements[elementName]) {
6349: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6350: current[currVal] = elementName;
6351: }
6352: }
6353: }
6354: var oldVal;
6355: for (var j=0; j<maxh; j++) {
6356: if (current[j] == undefined) {
6357: oldVal = j;
6358: }
6359: }
6360: if (oldVal < changedVal) {
6361: for (var k=oldVal+1; k<=changedVal ; k++) {
6362: var elementName = current[k];
6363: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6364: }
6365: } else {
6366: for (var k=changedVal; k<oldVal; k++) {
6367: var elementName = current[k];
6368: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6369: }
6370: }
6371: return;
6372: }
1.120 raeburn 6373:
6374: function categoryCheck(form) {
6375: if (form.elements['addcategory_name'].value == 'instcode') {
6376: alert('$instcode_reserved\\n$choose_again');
6377: return false;
6378: }
6379: if (form.elements['addcategory_name'].value == 'communities') {
6380: alert('$communities_reserved\\n$choose_again');
6381: return false;
6382: }
6383: return true;
6384: }
6385:
1.109 raeburn 6386: // ]]>
1.49 raeburn 6387: </script>
6388:
6389: ENDSCRIPT
6390: return $output;
6391: }
6392:
1.48 raeburn 6393: sub initialize_categories {
6394: my ($itemcount) = @_;
1.120 raeburn 6395: my ($datatable,$css_class,$chgstr);
6396: my %default_names = (
6397: instcode => 'Official courses (with institutional codes)',
6398: communities => 'Communities',
6399: );
6400: my $select0 = ' selected="selected"';
6401: my $select1 = '';
6402: foreach my $default ('instcode','communities') {
6403: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 6404: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 6405: if ($default eq 'communities') {
6406: $select1 = $select0;
6407: $select0 = '';
6408: }
6409: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6410: .'<select name="'.$default.'_pos">'
6411: .'<option value="0"'.$select0.'>1</option>'
6412: .'<option value="1"'.$select1.'>2</option>'
6413: .'<option value="2">3</option></select> '
6414: .$default_names{$default}
6415: .'</span></td><td><span class="LC_nobreak">'
6416: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6417: .&mt('Display').'</label> <label>'
6418: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6419: .'</label></span></td></tr>';
1.120 raeburn 6420: $itemcount ++;
6421: }
1.48 raeburn 6422: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6423: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6424: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6425: .'<select name="addcategory_pos"'.$chgstr.'>'
6426: .'<option value="0">1</option>'
6427: .'<option value="1">2</option>'
6428: .'<option value="2" selected="selected">3</option></select> '
1.160.6.87 raeburn 6429: .&mt('Add category').'</span></td><tda<span class="LC_nobreak">>'.&mt('Name:')
6430: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
6431: .'</td></tr>';
1.48 raeburn 6432: return $datatable;
6433: }
6434:
6435: sub build_category_rows {
1.49 raeburn 6436: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6437: my ($text,$name,$item,$chgstr);
1.48 raeburn 6438: if (ref($cats) eq 'ARRAY') {
6439: my $maxdepth = scalar(@{$cats});
6440: if (ref($cats->[$depth]) eq 'HASH') {
6441: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6442: my $numchildren = @{$cats->[$depth]{$parent}};
6443: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 6444: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6445: my ($idxnum,$parent_name,$parent_item);
6446: my $higher = $depth - 1;
6447: if ($higher == 0) {
6448: $parent_name = &escape($parent).'::'.$higher;
6449: } else {
6450: if (ref($path) eq 'ARRAY') {
6451: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6452: }
6453: }
6454: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6455: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6456: if ($j < $numchildren) {
1.48 raeburn 6457: $name = $cats->[$depth]{$parent}[$j];
6458: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6459: $idxnum = $idx->{$item};
6460: } else {
6461: $name = $parent_name;
6462: $item = $parent_item;
1.48 raeburn 6463: }
1.49 raeburn 6464: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6465: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6466: for (my $i=0; $i<=$numchildren; $i++) {
6467: my $vpos = $i+1;
6468: my $selstr;
6469: if ($j == $i) {
6470: $selstr = ' selected="selected" ';
6471: }
6472: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6473: }
6474: $text .= '</select> ';
6475: if ($j < $numchildren) {
6476: my $deeper = $depth+1;
6477: $text .= $name.' '
6478: .'<label><input type="checkbox" name="deletecategory" value="'
6479: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6480: if(ref($path) eq 'ARRAY') {
6481: push(@{$path},$name);
1.49 raeburn 6482: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6483: pop(@{$path});
6484: }
6485: } else {
1.160.6.87 raeburn 6486: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 6487: if ($j == $numchildren) {
6488: $text .= $name;
6489: } else {
6490: $text .= $item;
6491: }
6492: $text .= '" value="" />';
6493: }
6494: $text .= '</td></tr>';
6495: }
6496: $text .= '</table></td>';
6497: } else {
6498: my $higher = $depth-1;
6499: if ($higher == 0) {
6500: $name = &escape($parent).'::'.$higher;
6501: } else {
6502: if (ref($path) eq 'ARRAY') {
6503: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6504: }
6505: }
6506: my $colspan;
6507: if ($parent ne 'instcode') {
6508: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 6509: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 6510: }
6511: }
6512: }
6513: }
6514: return $text;
6515: }
6516:
1.33 raeburn 6517: sub modifiable_userdata_row {
1.160.6.35 raeburn 6518: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6519: my ($role,$rolename,$statustype);
6520: $role = $item;
1.160.6.34 raeburn 6521: if ($context eq 'cancreate') {
1.160.6.35 raeburn 6522: if ($item =~ /^emailusername_(.+)$/) {
6523: $statustype = $1;
6524: $role = 'emailusername';
6525: if (ref($usertypes) eq 'HASH') {
6526: if ($usertypes->{$statustype}) {
6527: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6528: } else {
6529: $rolename = &mt('Data provided by user');
6530: }
6531: }
1.160.6.34 raeburn 6532: }
6533: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6534: if (ref($usertypes) eq 'HASH') {
6535: $rolename = $usertypes->{$role};
6536: } else {
6537: $rolename = $role;
6538: }
1.33 raeburn 6539: } else {
1.63 raeburn 6540: if ($role eq 'cr') {
6541: $rolename = &mt('Custom role');
6542: } else {
6543: $rolename = &Apache::lonnet::plaintext($role);
6544: }
1.33 raeburn 6545: }
1.160.6.34 raeburn 6546: my (@fields,%fieldtitles);
6547: if (ref($fieldsref) eq 'ARRAY') {
6548: @fields = @{$fieldsref};
6549: } else {
6550: @fields = ('lastname','firstname','middlename','generation',
6551: 'permanentemail','id');
6552: }
6553: if ((ref($titlesref) eq 'HASH')) {
6554: %fieldtitles = %{$titlesref};
6555: } else {
6556: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6557: }
1.33 raeburn 6558: my $output;
6559: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6560: $output = '<tr '.$css_class.'>'.
6561: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6562: '<td class="LC_left_item" colspan="2"><table>';
6563: my $rem;
6564: my %checks;
6565: if (ref($settings) eq 'HASH') {
6566: if (ref($settings->{$context}) eq 'HASH') {
6567: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 6568: my $hashref = $settings->{$context}->{$role};
6569: if ($role eq 'emailusername') {
6570: if ($statustype) {
6571: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6572: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 6573: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 6574: foreach my $field (@fields) {
6575: if ($hashref->{$field}) {
6576: $checks{$field} = $hashref->{$field};
6577: }
6578: }
6579: }
6580: }
6581: }
6582: } else {
6583: if (ref($hashref) eq 'HASH') {
6584: foreach my $field (@fields) {
6585: if ($hashref->{$field}) {
6586: $checks{$field} = ' checked="checked" ';
6587: }
6588: }
1.33 raeburn 6589: }
6590: }
6591: }
6592: }
6593: }
1.160.6.39 raeburn 6594:
1.33 raeburn 6595: for (my $i=0; $i<@fields; $i++) {
6596: my $rem = $i%($numinrow);
6597: if ($rem == 0) {
6598: if ($i > 0) {
6599: $output .= '</tr>';
6600: }
6601: $output .= '<tr>';
6602: }
6603: my $check = ' ';
1.160.6.35 raeburn 6604: unless ($role eq 'emailusername') {
6605: if (exists($checks{$fields[$i]})) {
6606: $check = $checks{$fields[$i]}
6607: } else {
6608: if ($role eq 'st') {
6609: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 6610: $check = ' checked="checked" ';
1.160.6.35 raeburn 6611: }
1.33 raeburn 6612: }
6613: }
6614: }
6615: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 6616: '<span class="LC_nobreak">';
6617: if ($role eq 'emailusername') {
6618: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6619: $checks{$fields[$i]} = 'omit';
6620: }
6621: foreach my $option ('required','optional','omit') {
6622: my $checked='';
6623: if ($checks{$fields[$i]} eq $option) {
6624: $checked='checked="checked" ';
6625: }
6626: $output .= '<label>'.
6627: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6628: &mt($option).'</label>'.(' ' x2);
6629: }
6630: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6631: } else {
6632: $output .= '<label>'.
6633: '<input type="checkbox" name="canmodify_'.$role.'" '.
6634: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6635: '</label>';
6636: }
6637: $output .= '</span></td>';
1.33 raeburn 6638: $rem = @fields%($numinrow);
6639: }
6640: my $colsleft = $numinrow - $rem;
6641: if ($colsleft > 1 ) {
6642: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6643: ' </td>';
6644: } elsif ($colsleft == 1) {
6645: $output .= '<td class="LC_left_item"> </td>';
6646: }
6647: $output .= '</tr></table></td></tr>';
6648: return $output;
6649: }
1.28 raeburn 6650:
1.93 raeburn 6651: sub insttypes_row {
1.160.6.34 raeburn 6652: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6653: my %lt = &Apache::lonlocal::texthash (
6654: cansearch => 'Users allowed to search',
6655: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6656: lockablenames => 'User preference to lock name',
1.93 raeburn 6657: );
6658: my $showdom;
6659: if ($context eq 'cansearch') {
6660: $showdom = ' ('.$dom.')';
6661: }
1.160.6.5 raeburn 6662: my $class = 'LC_left_item';
6663: if ($context eq 'statustocreate') {
6664: $class = 'LC_right_item';
6665: }
1.160.6.34 raeburn 6666: my $css_class = ' class="LC_odd_row"';
6667: if ($rownum ne '') {
6668: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6669: }
6670: my $output = '<tr'.$css_class.'>'.
6671: '<td>'.$lt{$context}.$showdom.
6672: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6673: my $rem;
6674: if (ref($types) eq 'ARRAY') {
6675: for (my $i=0; $i<@{$types}; $i++) {
6676: if (defined($usertypes->{$types->[$i]})) {
6677: my $rem = $i%($numinrow);
6678: if ($rem == 0) {
6679: if ($i > 0) {
6680: $output .= '</tr>';
6681: }
6682: $output .= '<tr>';
1.23 raeburn 6683: }
1.26 raeburn 6684: my $check = ' ';
1.99 raeburn 6685: if (ref($settings) eq 'HASH') {
6686: if (ref($settings->{$context}) eq 'ARRAY') {
6687: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6688: $check = ' checked="checked" ';
6689: }
6690: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6691: $check = ' checked="checked" ';
6692: }
1.23 raeburn 6693: }
1.26 raeburn 6694: $output .= '<td class="LC_left_item">'.
6695: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6696: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6697: 'value="'.$types->[$i].'"'.$check.'/>'.
6698: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6699: }
6700: }
1.26 raeburn 6701: $rem = @{$types}%($numinrow);
1.23 raeburn 6702: }
6703: my $colsleft = $numinrow - $rem;
1.160.6.87 raeburn 6704: if ($rem == 0) {
1.131 raeburn 6705: $output .= '<tr>';
6706: }
1.23 raeburn 6707: if ($colsleft > 1) {
1.25 raeburn 6708: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6709: } else {
1.25 raeburn 6710: $output .= '<td class="LC_left_item">';
1.23 raeburn 6711: }
6712: my $defcheck = ' ';
1.99 raeburn 6713: if (ref($settings) eq 'HASH') {
6714: if (ref($settings->{$context}) eq 'ARRAY') {
6715: if (grep(/^default$/,@{$settings->{$context}})) {
6716: $defcheck = ' checked="checked" ';
6717: }
6718: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6719: $defcheck = ' checked="checked" ';
6720: }
1.23 raeburn 6721: }
1.25 raeburn 6722: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6723: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6724: 'value="default"'.$defcheck.'/>'.
6725: $othertitle.'</label></span></td>'.
6726: '</tr></table></td></tr>';
6727: return $output;
1.23 raeburn 6728: }
6729:
6730: sub sorted_searchtitles {
6731: my %searchtitles = &Apache::lonlocal::texthash(
6732: 'uname' => 'username',
6733: 'lastname' => 'last name',
6734: 'lastfirst' => 'last name, first name',
6735: );
6736: my @titleorder = ('uname','lastname','lastfirst');
6737: return (\%searchtitles,\@titleorder);
6738: }
6739:
1.25 raeburn 6740: sub sorted_searchtypes {
6741: my %srchtypes_desc = (
6742: exact => 'is exact match',
6743: contains => 'contains ..',
6744: begins => 'begins with ..',
6745: );
6746: my @srchtypeorder = ('exact','begins','contains');
6747: return (\%srchtypes_desc,\@srchtypeorder);
6748: }
6749:
1.3 raeburn 6750: sub usertype_update_row {
6751: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6752: my $datatable;
6753: my $numinrow = 4;
6754: foreach my $type (@{$types}) {
6755: if (defined($usertypes->{$type})) {
6756: $$rownums ++;
6757: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6758: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6759: '</td><td class="LC_left_item"><table>';
6760: for (my $i=0; $i<@{$fields}; $i++) {
6761: my $rem = $i%($numinrow);
6762: if ($rem == 0) {
6763: if ($i > 0) {
6764: $datatable .= '</tr>';
6765: }
6766: $datatable .= '<tr>';
6767: }
6768: my $check = ' ';
1.39 raeburn 6769: if (ref($settings) eq 'HASH') {
6770: if (ref($settings->{'fields'}) eq 'HASH') {
6771: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6772: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6773: $check = ' checked="checked" ';
6774: }
1.3 raeburn 6775: }
6776: }
6777: }
6778:
6779: if ($i == @{$fields}-1) {
6780: my $colsleft = $numinrow - $rem;
6781: if ($colsleft > 1) {
6782: $datatable .= '<td colspan="'.$colsleft.'">';
6783: } else {
6784: $datatable .= '<td>';
6785: }
6786: } else {
6787: $datatable .= '<td>';
6788: }
1.8 raeburn 6789: $datatable .= '<span class="LC_nobreak"><label>'.
6790: '<input type="checkbox" name="updateable_'.$type.
6791: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6792: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6793: }
6794: $datatable .= '</tr></table></td></tr>';
6795: }
6796: }
6797: return $datatable;
1.1 raeburn 6798: }
6799:
6800: sub modify_login {
1.160.6.24 raeburn 6801: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 6802: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6803: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6804: %title = ( coursecatalog => 'Display course catalog',
6805: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 6806: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 6807: newuser => 'Link for visitors to create a user account',
6808: loginheader => 'Log-in box header');
6809: @offon = ('off','on');
1.112 raeburn 6810: if (ref($domconfig{login}) eq 'HASH') {
6811: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6812: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6813: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6814: }
6815: }
6816: }
1.9 raeburn 6817: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6818: \%domconfig,\%loginhash);
1.160.6.14 raeburn 6819: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6820: foreach my $item (@toggles) {
6821: $loginhash{login}{$item} = $env{'form.'.$item};
6822: }
1.41 raeburn 6823: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6824: if (ref($colchanges{'login'}) eq 'HASH') {
6825: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6826: \%loginhash);
6827: }
1.110 raeburn 6828:
1.149 raeburn 6829: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 6830: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6831: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6832: if (keys(%servers) > 1) {
6833: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6834: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6835: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6836: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6837: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6838: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6839: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6840: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6841: $changes{'loginvia'}{$lonhost} = 1;
6842: } else {
6843: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6844: $changes{'loginvia'}{$lonhost} = 1;
6845: }
6846: } else {
6847: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6848: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6849: $changes{'loginvia'}{$lonhost} = 1;
6850: }
6851: }
6852: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6853: foreach my $item (@loginvia_attribs) {
6854: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6855: }
6856: } else {
6857: foreach my $item (@loginvia_attribs) {
6858: my $new = $env{'form.'.$lonhost.'_'.$item};
6859: if (($item eq 'serverpath') && ($new eq 'custom')) {
6860: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6861: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6862: $new = '/';
6863: }
6864: }
6865: if (($item eq 'custompath') &&
6866: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6867: $new = '';
6868: }
6869: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6870: $changes{'loginvia'}{$lonhost} = 1;
6871: }
6872: if ($item eq 'exempt') {
1.160.6.56 raeburn 6873: $new = &check_exempt_addresses($new);
1.128 raeburn 6874: }
6875: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6876: }
6877: }
1.112 raeburn 6878: } else {
1.128 raeburn 6879: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6880: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6881: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6882: foreach my $item (@loginvia_attribs) {
6883: my $new = $env{'form.'.$lonhost.'_'.$item};
6884: if (($item eq 'serverpath') && ($new eq 'custom')) {
6885: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6886: $new = '/';
6887: }
6888: }
6889: if (($item eq 'custompath') &&
6890: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6891: $new = '';
6892: }
6893: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6894: }
1.110 raeburn 6895: }
6896: }
6897: }
6898: }
1.119 raeburn 6899:
1.160.6.5 raeburn 6900: my $servadm = $r->dir_config('lonAdmEMail');
6901: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6902: if (ref($domconfig{'login'}) eq 'HASH') {
6903: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6904: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6905: if ($lang eq 'nolang') {
6906: push(@currlangs,$lang);
6907: } elsif (defined($langchoices{$lang})) {
6908: push(@currlangs,$lang);
6909: } else {
6910: next;
6911: }
6912: }
6913: }
6914: }
6915: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6916: if (@currlangs > 0) {
6917: foreach my $lang (@currlangs) {
6918: if (grep(/^\Q$lang\E$/,@delurls)) {
6919: $changes{'helpurl'}{$lang} = 1;
6920: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6921: $changes{'helpurl'}{$lang} = 1;
6922: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6923: push(@newlangs,$lang);
6924: } else {
6925: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6926: }
6927: }
6928: }
6929: unless (grep(/^nolang$/,@currlangs)) {
6930: if ($env{'form.loginhelpurl_nolang.filename'}) {
6931: $changes{'helpurl'}{'nolang'} = 1;
6932: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6933: push(@newlangs,'nolang');
6934: }
6935: }
6936: if ($env{'form.loginhelpurl_add_lang'}) {
6937: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6938: ($env{'form.loginhelpurl_add_file.filename'})) {
6939: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6940: $addedfile = $env{'form.loginhelpurl_add_lang'};
6941: }
6942: }
6943: if ((@newlangs > 0) || ($addedfile)) {
6944: my $error;
6945: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6946: if ($configuserok eq 'ok') {
6947: if ($switchserver) {
6948: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6949: } elsif ($author_ok eq 'ok') {
6950: my @allnew = @newlangs;
6951: if ($addedfile ne '') {
6952: push(@allnew,$addedfile);
6953: }
6954: foreach my $lang (@allnew) {
6955: my $formelem = 'loginhelpurl_'.$lang;
6956: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6957: $formelem = 'loginhelpurl_add_file';
6958: }
6959: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6960: "help/$lang",'','',$newfile{$lang});
6961: if ($result eq 'ok') {
6962: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6963: $changes{'helpurl'}{$lang} = 1;
6964: } else {
6965: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6966: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6967: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6968: (!grep(/^\Q$lang\E$/,@delurls))) {
6969: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6970: }
6971: }
6972: }
6973: } else {
6974: $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);
6975: }
6976: } else {
6977: $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);
6978: }
6979: if ($error) {
6980: &Apache::lonnet::logthis($error);
6981: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6982: }
6983: }
1.160.6.56 raeburn 6984:
6985: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6986: if (ref($domconfig{'login'}) eq 'HASH') {
6987: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6988: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6989: if ($domservers{$lonhost}) {
6990: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6991: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 6992: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 6993: }
6994: }
6995: }
6996: }
6997: }
6998: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6999: foreach my $lonhost (sort(keys(%domservers))) {
7000: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7001: $changes{'headtag'}{$lonhost} = 1;
7002: } else {
7003: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
7004: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
7005: }
7006: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
7007: push(@newhosts,$lonhost);
7008: } elsif ($currheadtagurls{$lonhost}) {
7009: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
7010: if ($currexempt{$lonhost}) {
7011: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
7012: $changes{'headtag'}{$lonhost} = 1;
7013: }
7014: } elsif ($possexempt{$lonhost}) {
7015: $changes{'headtag'}{$lonhost} = 1;
7016: }
7017: if ($possexempt{$lonhost}) {
7018: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7019: }
7020: }
7021: }
7022: }
7023: if (@newhosts) {
7024: my $error;
7025: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
7026: if ($configuserok eq 'ok') {
7027: if ($switchserver) {
7028: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
7029: } elsif ($author_ok eq 'ok') {
7030: foreach my $lonhost (@newhosts) {
7031: my $formelem = 'loginheadtag_'.$lonhost;
7032: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
7033: "login/headtag/$lonhost",'','',
7034: $env{'form.loginheadtag_'.$lonhost.'.filename'});
7035: if ($result eq 'ok') {
7036: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
7037: $changes{'headtag'}{$lonhost} = 1;
7038: if ($possexempt{$lonhost}) {
7039: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7040: }
7041: } else {
7042: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7043: $newheadtagurls{$lonhost},$result);
7044: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7045: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7046: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7047: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7048: }
7049: }
7050: }
7051: } else {
7052: $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);
7053: }
7054: } else {
7055: $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);
7056: }
7057: if ($error) {
7058: &Apache::lonnet::logthis($error);
7059: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7060: }
7061: }
1.160.6.5 raeburn 7062: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7063:
7064: my $defaulthelpfile = '/adm/loginproblems.html';
7065: my $defaulttext = &mt('Default in use');
7066:
1.1 raeburn 7067: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7068: $dom);
7069: if ($putresult eq 'ok') {
1.160.6.14 raeburn 7070: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7071: my %defaultchecked = (
7072: 'coursecatalog' => 'on',
1.160.6.14 raeburn 7073: 'helpdesk' => 'on',
1.42 raeburn 7074: 'adminmail' => 'off',
1.43 raeburn 7075: 'newuser' => 'off',
1.42 raeburn 7076: );
1.55 raeburn 7077: if (ref($domconfig{'login'}) eq 'HASH') {
7078: foreach my $item (@toggles) {
7079: if ($defaultchecked{$item} eq 'on') {
7080: if (($domconfig{'login'}{$item} eq '0') &&
7081: ($env{'form.'.$item} eq '1')) {
7082: $changes{$item} = 1;
7083: } elsif (($domconfig{'login'}{$item} eq '' ||
7084: $domconfig{'login'}{$item} eq '1') &&
7085: ($env{'form.'.$item} eq '0')) {
7086: $changes{$item} = 1;
7087: }
7088: } elsif ($defaultchecked{$item} eq 'off') {
7089: if (($domconfig{'login'}{$item} eq '1') &&
7090: ($env{'form.'.$item} eq '0')) {
7091: $changes{$item} = 1;
7092: } elsif (($domconfig{'login'}{$item} eq '' ||
7093: $domconfig{'login'}{$item} eq '0') &&
7094: ($env{'form.'.$item} eq '1')) {
7095: $changes{$item} = 1;
7096: }
1.42 raeburn 7097: }
7098: }
1.41 raeburn 7099: }
1.6 raeburn 7100: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7101: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7102: if (ref($lastactref) eq 'HASH') {
7103: $lastactref->{'domainconfig'} = 1;
7104: }
1.1 raeburn 7105: $resulttext = &mt('Changes made:').'<ul>';
7106: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7107: if ($item eq 'loginvia') {
1.112 raeburn 7108: if (ref($changes{$item}) eq 'HASH') {
7109: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7110: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7111: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7112: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7113: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7114: $protocol = 'http' if ($protocol ne 'https');
7115: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7116:
7117: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7118: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7119: } else {
7120: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7121: }
7122: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7123: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7124: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7125: }
7126: $resulttext .= '</li>';
7127: } else {
7128: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7129: }
1.112 raeburn 7130: } else {
1.128 raeburn 7131: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7132: }
7133: }
1.128 raeburn 7134: $resulttext .= '</ul></li>';
1.112 raeburn 7135: }
1.160.6.5 raeburn 7136: } elsif ($item eq 'helpurl') {
7137: if (ref($changes{$item}) eq 'HASH') {
7138: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7139: if (grep(/^\Q$lang\E$/,@delurls)) {
7140: my ($chg,$link);
7141: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7142: if ($lang eq 'nolang') {
7143: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7144: } else {
7145: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7146: }
7147: $resulttext .= '<li>'.$chg.'</li>';
7148: } else {
7149: my $chg;
7150: if ($lang eq 'nolang') {
7151: $chg = &mt('custom log-in help file for no preferred language');
7152: } else {
7153: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7154: }
7155: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7156: $loginhash{'login'}{'helpurl'}{$lang}.
7157: '?inhibitmenu=yes',$chg,600,500).
7158: '</li>';
7159: }
7160: }
7161: }
1.160.6.56 raeburn 7162: } elsif ($item eq 'headtag') {
7163: if (ref($changes{$item}) eq 'HASH') {
7164: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7165: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7166: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7167: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7168: $resulttext .= '<li><a href="'.
7169: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7170: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7171: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7172: if ($possexempt{$lonhost}) {
7173: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7174: } else {
7175: $resulttext .= &mt('included for any client IP');
7176: }
7177: $resulttext .= '</li>';
7178: }
7179: }
7180: }
1.160.6.5 raeburn 7181: } elsif ($item eq 'captcha') {
7182: if (ref($loginhash{'login'}) eq 'HASH') {
7183: my $chgtxt;
7184: if ($loginhash{'login'}{$item} eq 'notused') {
7185: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7186: } else {
7187: my %captchas = &captcha_phrases();
7188: if ($captchas{$loginhash{'login'}{$item}}) {
7189: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7190: } else {
7191: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7192: }
7193: }
7194: $resulttext .= '<li>'.$chgtxt.'</li>';
7195: }
7196: } elsif ($item eq 'recaptchakeys') {
7197: if (ref($loginhash{'login'}) eq 'HASH') {
7198: my ($privkey,$pubkey);
7199: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7200: $pubkey = $loginhash{'login'}{$item}{'public'};
7201: $privkey = $loginhash{'login'}{$item}{'private'};
7202: }
7203: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7204: if (!$pubkey) {
7205: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7206: } else {
7207: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7208: }
7209: if (!$privkey) {
7210: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7211: } else {
1.160.6.53 raeburn 7212: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 7213: }
7214: $chgtxt .= '</ul>';
7215: $resulttext .= '<li>'.$chgtxt.'</li>';
7216: }
1.160.6.69 raeburn 7217: } elsif ($item eq 'recaptchaversion') {
7218: if (ref($loginhash{'login'}) eq 'HASH') {
7219: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
7220: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
7221: '</li>';
7222: }
7223: }
1.41 raeburn 7224: } else {
7225: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7226: }
1.1 raeburn 7227: }
1.6 raeburn 7228: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7229: } else {
7230: $resulttext = &mt('No changes made to log-in page settings');
7231: }
7232: } else {
1.11 albertel 7233: $resulttext = '<span class="LC_error">'.
7234: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7235: }
1.6 raeburn 7236: if ($errors) {
1.9 raeburn 7237: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7238: $errors.'</ul>';
7239: }
7240: return $resulttext;
7241: }
7242:
1.160.6.56 raeburn 7243: sub check_exempt_addresses {
7244: my ($iplist) = @_;
7245: $iplist =~ s/^\s+//;
7246: $iplist =~ s/\s+$//;
7247: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7248: my (@okips,$new);
7249: foreach my $ip (@poss_ips) {
7250: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7251: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7252: push(@okips,$ip);
7253: }
7254: }
7255: }
7256: if (@okips > 0) {
7257: $new = join(',',@okips);
7258: } else {
7259: $new = '';
7260: }
7261: return $new;
7262: }
7263:
1.6 raeburn 7264: sub color_font_choices {
7265: my %choices =
7266: &Apache::lonlocal::texthash (
7267: img => "Header",
7268: bgs => "Background colors",
7269: links => "Link colors",
1.55 raeburn 7270: images => "Images",
1.6 raeburn 7271: font => "Font color",
1.160.6.22 raeburn 7272: fontmenu => "Font menu",
1.76 raeburn 7273: pgbg => "Page",
1.6 raeburn 7274: tabbg => "Header",
7275: sidebg => "Border",
7276: link => "Link",
7277: alink => "Active link",
7278: vlink => "Visited link",
7279: );
7280: return %choices;
7281: }
7282:
7283: sub modify_rolecolors {
1.160.6.24 raeburn 7284: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7285: my ($resulttext,%rolehash);
7286: $rolehash{'rolecolors'} = {};
1.55 raeburn 7287: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7288: if ($domconfig{'rolecolors'} eq '') {
7289: $domconfig{'rolecolors'} = {};
7290: }
7291: }
1.9 raeburn 7292: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7293: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7294: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7295: $dom);
7296: if ($putresult eq 'ok') {
7297: if (keys(%changes) > 0) {
1.41 raeburn 7298: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7299: if (ref($lastactref) eq 'HASH') {
7300: $lastactref->{'domainconfig'} = 1;
7301: }
1.6 raeburn 7302: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7303: $rolehash{'rolecolors'});
7304: } else {
7305: $resulttext = &mt('No changes made to default color schemes');
7306: }
7307: } else {
1.11 albertel 7308: $resulttext = '<span class="LC_error">'.
7309: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7310: }
7311: if ($errors) {
7312: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7313: $errors.'</ul>';
7314: }
7315: return $resulttext;
7316: }
7317:
7318: sub modify_colors {
1.9 raeburn 7319: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7320: my (%changes,%choices);
1.51 raeburn 7321: my @bgs;
1.6 raeburn 7322: my @links = ('link','alink','vlink');
1.41 raeburn 7323: my @logintext;
1.6 raeburn 7324: my @images;
7325: my $servadm = $r->dir_config('lonAdmEMail');
7326: my $errors;
1.160.6.22 raeburn 7327: my %defaults;
1.6 raeburn 7328: foreach my $role (@{$roles}) {
7329: if ($role eq 'login') {
1.12 raeburn 7330: %choices = &login_choices();
1.41 raeburn 7331: @logintext = ('textcol','bgcol');
1.12 raeburn 7332: } else {
7333: %choices = &color_font_choices();
7334: }
7335: if ($role eq 'login') {
1.41 raeburn 7336: @images = ('img','logo','domlogo','login');
1.51 raeburn 7337: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7338: } else {
7339: @images = ('img');
1.160.6.22 raeburn 7340: @bgs = ('pgbg','tabbg','sidebg');
7341: }
7342: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7343: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7344: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7345: }
7346: if ($role eq 'login') {
7347: foreach my $item (@logintext) {
1.160.6.39 raeburn 7348: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7349: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7350: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7351: }
7352: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 7353: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7354: }
7355: }
7356: } else {
1.160.6.39 raeburn 7357: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7358: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7359: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7360: }
7361: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 7362: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7363: }
1.6 raeburn 7364: }
1.160.6.22 raeburn 7365: foreach my $item (@bgs) {
1.160.6.39 raeburn 7366: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7367: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7368: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7369: }
7370: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 7371: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7372: }
7373: }
7374: foreach my $item (@links) {
1.160.6.39 raeburn 7375: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7376: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7377: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7378: }
7379: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 7380: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7381: }
1.6 raeburn 7382: }
1.46 raeburn 7383: my ($configuserok,$author_ok,$switchserver) =
7384: &config_check($dom,$confname,$servadm);
1.9 raeburn 7385: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7386: if (ref($domconfig->{$role}) ne 'HASH') {
7387: $domconfig->{$role} = {};
7388: }
1.8 raeburn 7389: foreach my $img (@images) {
1.70 raeburn 7390: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7391: if (defined($env{'form.login_showlogo_'.$img})) {
7392: $confhash->{$role}{'showlogo'}{$img} = 1;
7393: } else {
7394: $confhash->{$role}{'showlogo'}{$img} = 0;
7395: }
7396: }
1.18 albertel 7397: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7398: && !defined($domconfig->{$role}{$img})
7399: && !$env{'form.'.$role.'_del_'.$img}
7400: && $env{'form.'.$role.'_import_'.$img}) {
7401: # import the old configured image from the .tab setting
7402: # if they haven't provided a new one
7403: $domconfig->{$role}{$img} =
7404: $env{'form.'.$role.'_import_'.$img};
7405: }
1.6 raeburn 7406: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7407: my $error;
1.6 raeburn 7408: if ($configuserok eq 'ok') {
1.9 raeburn 7409: if ($switchserver) {
1.12 raeburn 7410: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7411: } else {
7412: if ($author_ok eq 'ok') {
7413: my ($result,$logourl) =
7414: &publishlogo($r,'upload',$role.'_'.$img,
7415: $dom,$confname,$img,$width,$height);
7416: if ($result eq 'ok') {
7417: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7418: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7419: } else {
1.12 raeburn 7420: $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 7421: }
7422: } else {
1.46 raeburn 7423: $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 7424: }
7425: }
7426: } else {
1.46 raeburn 7427: $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 7428: }
7429: if ($error) {
1.8 raeburn 7430: &Apache::lonnet::logthis($error);
1.11 albertel 7431: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7432: }
7433: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7434: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7435: my $error;
7436: if ($configuserok eq 'ok') {
7437: # is confname an author?
7438: if ($switchserver eq '') {
7439: if ($author_ok eq 'ok') {
7440: my ($result,$logourl) =
7441: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7442: $dom,$confname,$img,$width,$height);
7443: if ($result eq 'ok') {
7444: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7445: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7446: }
7447: }
7448: }
7449: }
1.6 raeburn 7450: }
7451: }
7452: }
7453: if (ref($domconfig) eq 'HASH') {
7454: if (ref($domconfig->{$role}) eq 'HASH') {
7455: foreach my $img (@images) {
7456: if ($domconfig->{$role}{$img} ne '') {
7457: if ($env{'form.'.$role.'_del_'.$img}) {
7458: $confhash->{$role}{$img} = '';
1.12 raeburn 7459: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7460: } else {
1.9 raeburn 7461: if ($confhash->{$role}{$img} eq '') {
7462: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7463: }
1.6 raeburn 7464: }
7465: } else {
7466: if ($env{'form.'.$role.'_del_'.$img}) {
7467: $confhash->{$role}{$img} = '';
1.12 raeburn 7468: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7469: }
7470: }
1.70 raeburn 7471: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7472: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7473: if ($confhash->{$role}{'showlogo'}{$img} ne
7474: $domconfig->{$role}{'showlogo'}{$img}) {
7475: $changes{$role}{'showlogo'}{$img} = 1;
7476: }
7477: } else {
7478: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7479: $changes{$role}{'showlogo'}{$img} = 1;
7480: }
7481: }
7482: }
7483: }
1.6 raeburn 7484: if ($domconfig->{$role}{'font'} ne '') {
7485: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7486: $changes{$role}{'font'} = 1;
7487: }
7488: } else {
7489: if ($confhash->{$role}{'font'}) {
7490: $changes{$role}{'font'} = 1;
7491: }
7492: }
1.107 raeburn 7493: if ($role ne 'login') {
7494: if ($domconfig->{$role}{'fontmenu'} ne '') {
7495: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7496: $changes{$role}{'fontmenu'} = 1;
7497: }
7498: } else {
7499: if ($confhash->{$role}{'fontmenu'}) {
7500: $changes{$role}{'fontmenu'} = 1;
7501: }
1.97 tempelho 7502: }
7503: }
1.6 raeburn 7504: foreach my $item (@bgs) {
7505: if ($domconfig->{$role}{$item} ne '') {
7506: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7507: $changes{$role}{'bgs'}{$item} = 1;
7508: }
7509: } else {
7510: if ($confhash->{$role}{$item}) {
7511: $changes{$role}{'bgs'}{$item} = 1;
7512: }
7513: }
7514: }
7515: foreach my $item (@links) {
7516: if ($domconfig->{$role}{$item} ne '') {
7517: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7518: $changes{$role}{'links'}{$item} = 1;
7519: }
7520: } else {
7521: if ($confhash->{$role}{$item}) {
7522: $changes{$role}{'links'}{$item} = 1;
7523: }
7524: }
7525: }
1.41 raeburn 7526: foreach my $item (@logintext) {
7527: if ($domconfig->{$role}{$item} ne '') {
7528: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7529: $changes{$role}{'logintext'}{$item} = 1;
7530: }
7531: } else {
7532: if ($confhash->{$role}{$item}) {
7533: $changes{$role}{'logintext'}{$item} = 1;
7534: }
7535: }
7536: }
1.6 raeburn 7537: } else {
7538: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7539: \@logintext,$confhash,\%changes);
1.6 raeburn 7540: }
7541: } else {
7542: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7543: \@logintext,$confhash,\%changes);
1.6 raeburn 7544: }
7545: }
7546: return ($errors,%changes);
7547: }
7548:
1.46 raeburn 7549: sub config_check {
7550: my ($dom,$confname,$servadm) = @_;
7551: my ($configuserok,$author_ok,$switchserver,%currroles);
7552: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7553: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7554: $confname,$servadm);
7555: if ($configuserok eq 'ok') {
7556: $switchserver = &check_switchserver($dom,$confname);
7557: if ($switchserver eq '') {
7558: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7559: }
7560: }
7561: return ($configuserok,$author_ok,$switchserver);
7562: }
7563:
1.6 raeburn 7564: sub default_change_checker {
1.41 raeburn 7565: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7566: foreach my $item (@{$links}) {
7567: if ($confhash->{$role}{$item}) {
7568: $changes->{$role}{'links'}{$item} = 1;
7569: }
7570: }
7571: foreach my $item (@{$bgs}) {
7572: if ($confhash->{$role}{$item}) {
7573: $changes->{$role}{'bgs'}{$item} = 1;
7574: }
7575: }
1.41 raeburn 7576: foreach my $item (@{$logintext}) {
7577: if ($confhash->{$role}{$item}) {
7578: $changes->{$role}{'logintext'}{$item} = 1;
7579: }
7580: }
1.6 raeburn 7581: foreach my $img (@{$images}) {
7582: if ($env{'form.'.$role.'_del_'.$img}) {
7583: $confhash->{$role}{$img} = '';
1.12 raeburn 7584: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7585: }
1.70 raeburn 7586: if ($role eq 'login') {
7587: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7588: $changes->{$role}{'showlogo'}{$img} = 1;
7589: }
7590: }
1.6 raeburn 7591: }
7592: if ($confhash->{$role}{'font'}) {
7593: $changes->{$role}{'font'} = 1;
7594: }
1.48 raeburn 7595: }
1.6 raeburn 7596:
7597: sub display_colorchgs {
7598: my ($dom,$changes,$roles,$confhash) = @_;
7599: my (%choices,$resulttext);
7600: if (!grep(/^login$/,@{$roles})) {
7601: $resulttext = &mt('Changes made:').'<br />';
7602: }
7603: foreach my $role (@{$roles}) {
7604: if ($role eq 'login') {
7605: %choices = &login_choices();
7606: } else {
7607: %choices = &color_font_choices();
7608: }
7609: if (ref($changes->{$role}) eq 'HASH') {
7610: if ($role ne 'login') {
7611: $resulttext .= '<h4>'.&mt($role).'</h4>';
7612: }
7613: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7614: if ($role ne 'login') {
7615: $resulttext .= '<ul>';
7616: }
7617: if (ref($changes->{$role}{$key}) eq 'HASH') {
7618: if ($role ne 'login') {
7619: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7620: }
7621: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7622: if (($role eq 'login') && ($key eq 'showlogo')) {
7623: if ($confhash->{$role}{$key}{$item}) {
7624: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7625: } else {
7626: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7627: }
7628: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7629: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7630: } else {
1.12 raeburn 7631: my $newitem = $confhash->{$role}{$item};
7632: if ($key eq 'images') {
7633: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7634: }
7635: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7636: }
7637: }
7638: if ($role ne 'login') {
7639: $resulttext .= '</ul></li>';
7640: }
7641: } else {
7642: if ($confhash->{$role}{$key} eq '') {
7643: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7644: } else {
7645: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7646: }
7647: }
7648: if ($role ne 'login') {
7649: $resulttext .= '</ul>';
7650: }
7651: }
7652: }
7653: }
1.3 raeburn 7654: return $resulttext;
1.1 raeburn 7655: }
7656:
1.9 raeburn 7657: sub thumb_dimensions {
7658: return ('200','50');
7659: }
7660:
1.16 raeburn 7661: sub check_dimensions {
7662: my ($inputfile) = @_;
7663: my ($fullwidth,$fullheight);
7664: if ($inputfile =~ m|^[/\w.\-]+$|) {
7665: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7666: my $imageinfo = <PIPE>;
7667: if (!close(PIPE)) {
7668: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7669: }
7670: chomp($imageinfo);
7671: my ($fullsize) =
1.21 raeburn 7672: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7673: if ($fullsize) {
7674: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7675: }
7676: }
7677: }
7678: return ($fullwidth,$fullheight);
7679: }
7680:
1.9 raeburn 7681: sub check_configuser {
7682: my ($uhome,$dom,$confname,$servadm) = @_;
7683: my ($configuserok,%currroles);
7684: if ($uhome eq 'no_host') {
7685: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7686: my $configpass = &LONCAPA::Enrollment::create_password();
7687: $configuserok =
7688: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7689: $configpass,'','','','','',undef,$servadm);
7690: } else {
7691: $configuserok = 'ok';
7692: %currroles =
7693: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7694: }
7695: return ($configuserok,%currroles);
7696: }
7697:
7698: sub check_authorstatus {
7699: my ($dom,$confname,%currroles) = @_;
7700: my $author_ok;
1.40 raeburn 7701: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7702: my $start = time;
7703: my $end = 0;
7704: $author_ok =
7705: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7706: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7707: } else {
7708: $author_ok = 'ok';
7709: }
7710: return $author_ok;
7711: }
7712:
7713: sub publishlogo {
1.46 raeburn 7714: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 7715: my ($output,$fname,$logourl);
7716: if ($action eq 'upload') {
7717: $fname=$env{'form.'.$formname.'.filename'};
7718: chop($env{'form.'.$formname});
7719: } else {
7720: ($fname) = ($formname =~ /([^\/]+)$/);
7721: }
1.46 raeburn 7722: if ($savefileas ne '') {
7723: $fname = $savefileas;
7724: }
1.9 raeburn 7725: $fname=&Apache::lonnet::clean_filename($fname);
7726: # See if there is anything left
7727: unless ($fname) { return ('error: no uploaded file'); }
7728: $fname="$subdir/$fname";
1.160.6.5 raeburn 7729: my $docroot=$r->dir_config('lonDocRoot');
7730: my $filepath="$docroot/priv";
7731: my $relpath = "$dom/$confname";
1.9 raeburn 7732: my ($fnamepath,$file,$fetchthumb);
7733: $file=$fname;
7734: if ($fname=~m|/|) {
7735: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7736: }
1.160.6.26 raeburn 7737: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7738: my $count;
1.160.6.5 raeburn 7739: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7740: $filepath.="/$parts[$count]";
7741: if ((-e $filepath)!=1) {
7742: mkdir($filepath,02770);
7743: }
7744: }
7745: # Check for bad extension and disallow upload
7746: if ($file=~/\.(\w+)$/ &&
7747: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7748: $output =
1.160.6.25 raeburn 7749: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7750: } elsif ($file=~/\.(\w+)$/ &&
7751: !defined(&Apache::loncommon::fileembstyle($1))) {
7752: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7753: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 7754: $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 7755: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 7756: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7757: } else {
7758: my $source = $filepath.'/'.$file;
7759: my $logfile;
1.160.6.88 raeburn 7760: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 7761: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7762: }
7763: print $logfile
7764: "\n================= Publish ".localtime()." ================\n".
7765: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7766: # Save the file
1.160.6.88 raeburn 7767: if (!open(FH,">",$source)) {
1.9 raeburn 7768: &Apache::lonnet::logthis('Failed to create '.$source);
7769: return (&mt('Failed to create file'));
7770: }
7771: if ($action eq 'upload') {
7772: if (!print FH ($env{'form.'.$formname})) {
7773: &Apache::lonnet::logthis('Failed to write to '.$source);
7774: return (&mt('Failed to write file'));
7775: }
7776: } else {
7777: my $original = &Apache::lonnet::filelocation('',$formname);
7778: if(!copy($original,$source)) {
7779: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7780: return (&mt('Failed to write file'));
7781: }
7782: }
7783: close(FH);
7784: chmod(0660, $source); # Permissions to rw-rw---.
7785:
7786: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7787: my $copyfile=$targetdir.'/'.$file;
7788:
7789: my @parts=split(/\//,$targetdir);
7790: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7791: for (my $count=5;$count<=$#parts;$count++) {
7792: $path.="/$parts[$count]";
7793: if (!-e $path) {
7794: print $logfile "\nCreating directory ".$path;
7795: mkdir($path,02770);
7796: }
7797: }
7798: my $versionresult;
7799: if (-e $copyfile) {
7800: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7801: } else {
7802: $versionresult = 'ok';
7803: }
7804: if ($versionresult eq 'ok') {
7805: if (copy($source,$copyfile)) {
7806: print $logfile "\nCopied original source to ".$copyfile."\n";
7807: $output = 'ok';
7808: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7809: push(@{$modified_urls},[$copyfile,$source]);
7810: my $metaoutput =
7811: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7812: unless ($registered_cleanup) {
7813: my $handlers = $r->get_handlers('PerlCleanupHandler');
7814: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7815: $registered_cleanup=1;
7816: }
1.9 raeburn 7817: } else {
7818: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7819: $output = &mt('Failed to copy file to RES space').", $!";
7820: }
7821: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7822: my $inputfile = $filepath.'/'.$file;
7823: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7824: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7825: if ($fullwidth ne '' && $fullheight ne '') {
7826: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7827: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 7828: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
7829: system({$args[0]} @args);
1.16 raeburn 7830: chmod(0660, $filepath.'/tn-'.$file);
7831: if (-e $outfile) {
7832: my $copyfile=$targetdir.'/tn-'.$file;
7833: if (copy($outfile,$copyfile)) {
7834: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7835: my $thumb_metaoutput =
7836: &write_metadata($dom,$confname,$formname,
7837: $targetdir,'tn-'.$file,$logfile);
7838: push(@{$modified_urls},[$copyfile,$outfile]);
7839: unless ($registered_cleanup) {
7840: my $handlers = $r->get_handlers('PerlCleanupHandler');
7841: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7842: $registered_cleanup=1;
7843: }
1.16 raeburn 7844: } else {
7845: print $logfile "\nUnable to write ".$copyfile.
7846: ':'.$!."\n";
7847: }
7848: }
1.9 raeburn 7849: }
7850: }
7851: }
7852: } else {
7853: $output = $versionresult;
7854: }
7855: }
7856: return ($output,$logourl);
7857: }
7858:
7859: sub logo_versioning {
7860: my ($targetdir,$file,$logfile) = @_;
7861: my $target = $targetdir.'/'.$file;
7862: my ($maxversion,$fn,$extn,$output);
7863: $maxversion = 0;
7864: if ($file =~ /^(.+)\.(\w+)$/) {
7865: $fn=$1;
7866: $extn=$2;
7867: }
7868: opendir(DIR,$targetdir);
7869: while (my $filename=readdir(DIR)) {
7870: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7871: $maxversion=($1>$maxversion)?$1:$maxversion;
7872: }
7873: }
7874: $maxversion++;
7875: print $logfile "\nCreating old version ".$maxversion."\n";
7876: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7877: if (copy($target,$copyfile)) {
7878: print $logfile "Copied old target to ".$copyfile."\n";
7879: $copyfile=$copyfile.'.meta';
7880: if (copy($target.'.meta',$copyfile)) {
7881: print $logfile "Copied old target metadata to ".$copyfile."\n";
7882: $output = 'ok';
7883: } else {
7884: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7885: $output = &mt('Failed to copy old meta').", $!, ";
7886: }
7887: } else {
7888: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7889: $output = &mt('Failed to copy old target').", $!, ";
7890: }
7891: return $output;
7892: }
7893:
7894: sub write_metadata {
7895: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7896: my (%metadatafields,%metadatakeys,$output);
7897: $metadatafields{'title'}=$formname;
7898: $metadatafields{'creationdate'}=time;
7899: $metadatafields{'lastrevisiondate'}=time;
7900: $metadatafields{'copyright'}='public';
7901: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7902: $env{'user.domain'};
7903: $metadatafields{'authorspace'}=$confname.':'.$dom;
7904: $metadatafields{'domain'}=$dom;
7905: {
7906: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7907: my $mfh;
1.160.6.88 raeburn 7908: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 7909: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7910: unless ($_=~/\./) {
7911: my $unikey=$_;
7912: $unikey=~/^([A-Za-z]+)/;
7913: my $tag=$1;
7914: $tag=~tr/A-Z/a-z/;
7915: print $mfh "\n\<$tag";
7916: foreach (split(/\,/,$metadatakeys{$unikey})) {
7917: my $value=$metadatafields{$unikey.'.'.$_};
7918: $value=~s/\"/\'\'/g;
7919: print $mfh ' '.$_.'="'.$value.'"';
7920: }
7921: print $mfh '>'.
7922: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7923: .'</'.$tag.'>';
7924: }
7925: }
7926: $output = 'ok';
7927: print $logfile "\nWrote metadata";
7928: close($mfh);
7929: } else {
7930: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7931: $output = &mt('Could not write metadata');
7932: }
7933: }
1.155 raeburn 7934: return $output;
7935: }
7936:
7937: sub notifysubscribed {
7938: foreach my $targetsource (@{$modified_urls}){
7939: next unless (ref($targetsource) eq 'ARRAY');
7940: my ($target,$source)=@{$targetsource};
7941: if ($source ne '') {
1.160.6.88 raeburn 7942: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 7943: print $logfh "\nCleanup phase: Notifications\n";
7944: my @subscribed=&subscribed_hosts($target);
7945: foreach my $subhost (@subscribed) {
7946: print $logfh "\nNotifying host ".$subhost.':';
7947: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7948: print $logfh $reply;
7949: }
7950: my @subscribedmeta=&subscribed_hosts("$target.meta");
7951: foreach my $subhost (@subscribedmeta) {
7952: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7953: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7954: $subhost);
7955: print $logfh $reply;
7956: }
7957: print $logfh "\n============ Done ============\n";
1.160 raeburn 7958: close($logfh);
1.155 raeburn 7959: }
7960: }
7961: }
7962: return OK;
7963: }
7964:
7965: sub subscribed_hosts {
7966: my ($target) = @_;
7967: my @subscribed;
1.160.6.88 raeburn 7968: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 7969: while (my $subline=<$fh>) {
7970: if ($subline =~ /^($match_lonid):/) {
7971: my $host = $1;
7972: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7973: unless (grep(/^\Q$host\E$/,@subscribed)) {
7974: push(@subscribed,$host);
7975: }
7976: }
7977: }
7978: }
7979: }
7980: return @subscribed;
1.9 raeburn 7981: }
7982:
7983: sub check_switchserver {
7984: my ($dom,$confname) = @_;
7985: my ($allowed,$switchserver);
7986: my $home = &Apache::lonnet::homeserver($confname,$dom);
7987: if ($home eq 'no_host') {
7988: $home = &Apache::lonnet::domain($dom,'primary');
7989: }
7990: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7991: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7992: if (!$allowed) {
1.160.6.11 raeburn 7993: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7994: }
7995: return $switchserver;
7996: }
7997:
1.1 raeburn 7998: sub modify_quotas {
1.160.6.30 raeburn 7999: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 8000: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 8001: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 8002: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
8003: $validationfieldsref);
1.86 raeburn 8004: if ($action eq 'quotas') {
8005: $context = 'tools';
1.160.6.26 raeburn 8006: } else {
1.86 raeburn 8007: $context = $action;
8008: }
8009: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 8010: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 8011: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 8012: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
8013: %titles = &courserequest_titles();
8014: $toolregexp = join('|',@usertools);
8015: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 8016: $confname = $dom.'-domainconfig';
8017: my $servadm = $r->dir_config('lonAdmEMail');
8018: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 8019: ($validationitemsref,$validationnamesref,$validationfieldsref) =
8020: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 8021: } elsif ($context eq 'requestauthor') {
8022: @usertools = ('author');
8023: %titles = &authorrequest_titles();
1.86 raeburn 8024: } else {
1.160.6.4 raeburn 8025: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 8026: %titles = &tool_titles();
1.86 raeburn 8027: }
1.160.6.27 raeburn 8028: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 8029: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8030: foreach my $key (keys(%env)) {
1.101 raeburn 8031: if ($context eq 'requestcourses') {
8032: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
8033: my $item = $1;
8034: my $type = $2;
8035: if ($type =~ /^limit_(.+)/) {
8036: $limithash{$item}{$1} = $env{$key};
8037: } else {
8038: $confhash{$item}{$type} = $env{$key};
8039: }
8040: }
1.160.6.5 raeburn 8041: } elsif ($context eq 'requestauthor') {
8042: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8043: $confhash{$1} = $env{$key};
8044: }
1.101 raeburn 8045: } else {
1.86 raeburn 8046: if ($key =~ /^form\.quota_(.+)$/) {
8047: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 8048: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8049: $confhash{'authorquota'}{$1} = $env{$key};
8050: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8051: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8052: }
1.72 raeburn 8053: }
8054: }
1.160.6.5 raeburn 8055: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 8056: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8057: @approvalnotify = sort(@approvalnotify);
8058: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 8059: my @crstypes = ('official','unofficial','community','textbook');
8060: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8061: foreach my $type (@hasuniquecode) {
8062: if (grep(/^\Q$type\E$/,@crstypes)) {
8063: $confhash{'uniquecode'}{$type} = 1;
8064: }
8065: }
1.160.6.46 raeburn 8066: my (%newbook,%allpos);
1.160.6.30 raeburn 8067: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8068: foreach my $type ('textbooks','templates') {
8069: @{$allpos{$type}} = ();
8070: my $invalid;
8071: if ($type eq 'textbooks') {
8072: $invalid = &mt('Invalid LON-CAPA course for textbook');
8073: } else {
8074: $invalid = &mt('Invalid LON-CAPA course for template');
8075: }
8076: if ($env{'form.'.$type.'_addbook'}) {
8077: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8078: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8079: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8080: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8081: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8082: } else {
8083: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8084: my $position = $env{'form.'.$type.'_addbook_pos'};
8085: $position =~ s/\D+//g;
8086: if ($position ne '') {
8087: $allpos{$type}[$position] = $newbook{$type};
8088: }
1.160.6.30 raeburn 8089: }
1.160.6.46 raeburn 8090: } else {
8091: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 8092: }
8093: }
1.160.6.46 raeburn 8094: }
1.160.6.30 raeburn 8095: }
1.102 raeburn 8096: if (ref($domconfig{$action}) eq 'HASH') {
8097: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8098: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8099: $changes{'notify'}{'approval'} = 1;
8100: }
8101: } else {
1.144 raeburn 8102: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8103: $changes{'notify'}{'approval'} = 1;
8104: }
8105: }
1.160.6.30 raeburn 8106: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8107: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8108: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8109: unless ($confhash{'uniquecode'}{$crstype}) {
8110: $changes{'uniquecode'} = 1;
8111: }
8112: }
8113: unless ($changes{'uniquecode'}) {
8114: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8115: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8116: $changes{'uniquecode'} = 1;
8117: }
8118: }
8119: }
8120: } else {
8121: $changes{'uniquecode'} = 1;
8122: }
8123: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8124: $changes{'uniquecode'} = 1;
8125: }
8126: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8127: foreach my $type ('textbooks','templates') {
8128: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8129: my %deletions;
8130: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8131: if (@todelete) {
8132: map { $deletions{$_} = 1; } @todelete;
8133: }
8134: my %imgdeletions;
8135: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8136: if (@todeleteimages) {
8137: map { $imgdeletions{$_} = 1; } @todeleteimages;
8138: }
8139: my $maxnum = $env{'form.'.$type.'_maxnum'};
8140: for (my $i=0; $i<=$maxnum; $i++) {
8141: my $itemid = $env{'form.'.$type.'_id_'.$i};
8142: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8143: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8144: if ($deletions{$key}) {
8145: if ($domconfig{$action}{$type}{$key}{'image'}) {
8146: #FIXME need to obsolete item in RES space
8147: }
8148: next;
8149: } else {
8150: my $newpos = $env{'form.'.$itemid};
8151: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 8152: foreach my $item ('subject','title','publisher','author') {
8153: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8154: ($type eq 'templates'));
1.160.6.46 raeburn 8155: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8156: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8157: $changes{$type}{$key} = 1;
8158: }
8159: }
8160: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 8161: }
1.160.6.46 raeburn 8162: if ($imgdeletions{$key}) {
8163: $changes{$type}{$key} = 1;
8164: #FIXME need to obsolete item in RES space
8165: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8166: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 8167: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
8168: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
8169: } else {
8170: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
8171: $cdom,$cnum,$type,$configuserok,
8172: $switchserver,$author_ok);
8173: if ($imgurl) {
8174: $confhash{$type}{$key}{'image'} = $imgurl;
8175: $changes{$type}{$key} = 1;
8176: }
8177: if ($error) {
8178: &Apache::lonnet::logthis($error);
8179: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8180: }
1.160.6.46 raeburn 8181: }
8182: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8183: $confhash{$type}{$key}{'image'} =
8184: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 8185: }
8186: }
8187: }
8188: }
8189: }
8190: }
1.102 raeburn 8191: } else {
1.144 raeburn 8192: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8193: $changes{'notify'}{'approval'} = 1;
8194: }
1.160.6.30 raeburn 8195: if (ref($confhash{'uniquecode'} eq 'HASH')) {
8196: $changes{'uniquecode'} = 1;
8197: }
8198: }
8199: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8200: foreach my $type ('textbooks','templates') {
8201: if ($newbook{$type}) {
8202: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 8203: foreach my $item ('subject','title','publisher','author') {
8204: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8205: ($type eq 'template'));
1.160.6.46 raeburn 8206: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8207: if ($env{'form.'.$type.'_addbook_'.$item}) {
8208: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8209: }
8210: }
8211: if ($type eq 'textbooks') {
8212: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8213: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 8214: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
8215: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
8216: } else {
8217: my ($imageurl,$error) =
8218: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
8219: $configuserok,$switchserver,$author_ok);
8220: if ($imageurl) {
8221: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
8222: }
8223: if ($error) {
8224: &Apache::lonnet::logthis($error);
8225: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
8226: }
1.160.6.46 raeburn 8227: }
8228: }
1.160.6.30 raeburn 8229: }
8230: }
1.160.6.46 raeburn 8231: if (@{$allpos{$type}} > 0) {
8232: my $idx = 0;
8233: foreach my $item (@{$allpos{$type}}) {
8234: if ($item ne '') {
8235: $confhash{$type}{$item}{'order'} = $idx;
8236: if (ref($domconfig{$action}) eq 'HASH') {
8237: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8238: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8239: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8240: $changes{$type}{$item} = 1;
8241: }
1.160.6.30 raeburn 8242: }
8243: }
8244: }
1.160.6.46 raeburn 8245: $idx ++;
1.160.6.30 raeburn 8246: }
8247: }
8248: }
8249: }
1.160.6.39 raeburn 8250: if (ref($validationitemsref) eq 'ARRAY') {
8251: foreach my $item (@{$validationitemsref}) {
8252: if ($item eq 'fields') {
8253: my @changed;
8254: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8255: if (@{$confhash{'validation'}{$item}} > 0) {
8256: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8257: }
1.160.6.65 raeburn 8258: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8259: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8260: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8261: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8262: $domconfig{'requestcourses'}{'validation'}{$item});
8263: } else {
8264: @changed = @{$confhash{'validation'}{$item}};
8265: }
1.160.6.39 raeburn 8266: } else {
8267: @changed = @{$confhash{'validation'}{$item}};
8268: }
8269: } else {
8270: @changed = @{$confhash{'validation'}{$item}};
8271: }
8272: if (@changed) {
8273: if ($confhash{'validation'}{$item}) {
8274: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8275: } else {
8276: $changes{'validation'}{$item} = &mt('None');
8277: }
8278: }
8279: } else {
8280: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8281: if ($item eq 'markup') {
8282: if ($env{'form.requestcourses_validation_'.$item}) {
8283: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8284: }
8285: }
1.160.6.65 raeburn 8286: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8287: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8288: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8289: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8290: }
8291: } else {
8292: if ($confhash{'validation'}{$item} ne '') {
8293: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8294: }
1.160.6.39 raeburn 8295: }
8296: } else {
8297: if ($confhash{'validation'}{$item} ne '') {
8298: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8299: }
8300: }
8301: }
8302: }
8303: }
8304: if ($env{'form.validationdc'}) {
8305: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 8306: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 8307: if (exists($domcoords{$newval})) {
8308: $confhash{'validation'}{'dc'} = $newval;
8309: }
8310: }
8311: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 8312: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8313: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8314: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8315: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8316: if ($confhash{'validation'}{'dc'} eq '') {
8317: $changes{'validation'}{'dc'} = &mt('None');
8318: } else {
8319: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8320: }
1.160.6.39 raeburn 8321: }
1.160.6.65 raeburn 8322: } elsif ($confhash{'validation'}{'dc'} ne '') {
8323: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 8324: }
8325: } elsif ($confhash{'validation'}{'dc'} ne '') {
8326: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8327: }
8328: } elsif ($confhash{'validation'}{'dc'} ne '') {
8329: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8330: }
1.160.6.65 raeburn 8331: } else {
8332: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8333: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8334: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8335: $changes{'validation'}{'dc'} = &mt('None');
8336: }
8337: }
1.160.6.39 raeburn 8338: }
8339: }
1.102 raeburn 8340: }
8341: } else {
1.86 raeburn 8342: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 8343: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8344: }
1.72 raeburn 8345: foreach my $item (@usertools) {
8346: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8347: my $unset;
1.101 raeburn 8348: if ($context eq 'requestcourses') {
1.104 raeburn 8349: $unset = '0';
8350: if ($type eq '_LC_adv') {
8351: $unset = '';
8352: }
1.101 raeburn 8353: if ($confhash{$item}{$type} eq 'autolimit') {
8354: $confhash{$item}{$type} .= '=';
8355: unless ($limithash{$item}{$type} =~ /\D/) {
8356: $confhash{$item}{$type} .= $limithash{$item}{$type};
8357: }
8358: }
1.160.6.5 raeburn 8359: } elsif ($context eq 'requestauthor') {
8360: $unset = '0';
8361: if ($type eq '_LC_adv') {
8362: $unset = '';
8363: }
1.72 raeburn 8364: } else {
1.101 raeburn 8365: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8366: $confhash{$item}{$type} = 1;
8367: } else {
8368: $confhash{$item}{$type} = 0;
8369: }
1.72 raeburn 8370: }
1.86 raeburn 8371: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 8372: if ($action eq 'requestauthor') {
8373: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8374: $changes{$type} = 1;
8375: }
8376: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8377: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8378: $changes{$item}{$type} = 1;
8379: }
8380: } else {
8381: if ($context eq 'requestcourses') {
1.104 raeburn 8382: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8383: $changes{$item}{$type} = 1;
8384: }
8385: } else {
8386: if (!$confhash{$item}{$type}) {
8387: $changes{$item}{$type} = 1;
8388: }
8389: }
8390: }
8391: } else {
8392: if ($context eq 'requestcourses') {
1.104 raeburn 8393: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8394: $changes{$item}{$type} = 1;
8395: }
1.160.6.5 raeburn 8396: } elsif ($context eq 'requestauthor') {
8397: if ($confhash{$type} ne $unset) {
8398: $changes{$type} = 1;
8399: }
1.72 raeburn 8400: } else {
8401: if (!$confhash{$item}{$type}) {
8402: $changes{$item}{$type} = 1;
8403: }
8404: }
8405: }
1.1 raeburn 8406: }
8407: }
1.160.6.5 raeburn 8408: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8409: if (ref($domconfig{'quotas'}) eq 'HASH') {
8410: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8411: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8412: if (exists($confhash{'defaultquota'}{$key})) {
8413: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8414: $changes{'defaultquota'}{$key} = 1;
8415: }
8416: } else {
8417: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8418: }
8419: }
1.86 raeburn 8420: } else {
8421: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8422: if (exists($confhash{'defaultquota'}{$key})) {
8423: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8424: $changes{'defaultquota'}{$key} = 1;
8425: }
8426: } else {
8427: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8428: }
1.1 raeburn 8429: }
8430: }
1.160.6.20 raeburn 8431: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8432: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8433: if (exists($confhash{'authorquota'}{$key})) {
8434: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8435: $changes{'authorquota'}{$key} = 1;
8436: }
8437: } else {
8438: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8439: }
8440: }
8441: }
1.1 raeburn 8442: }
1.86 raeburn 8443: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8444: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8445: if (ref($domconfig{'quotas'}) eq 'HASH') {
8446: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8447: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8448: $changes{'defaultquota'}{$key} = 1;
8449: }
8450: } else {
8451: if (!exists($domconfig{'quotas'}{$key})) {
8452: $changes{'defaultquota'}{$key} = 1;
8453: }
1.72 raeburn 8454: }
8455: } else {
1.86 raeburn 8456: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8457: }
1.1 raeburn 8458: }
8459: }
1.160.6.20 raeburn 8460: if (ref($confhash{'authorquota'}) eq 'HASH') {
8461: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8462: if (ref($domconfig{'quotas'}) eq 'HASH') {
8463: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8464: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8465: $changes{'authorquota'}{$key} = 1;
8466: }
8467: } else {
8468: $changes{'authorquota'}{$key} = 1;
8469: }
8470: } else {
8471: $changes{'authorquota'}{$key} = 1;
8472: }
8473: }
8474: }
1.1 raeburn 8475: }
1.72 raeburn 8476:
1.160.6.5 raeburn 8477: if ($context eq 'requestauthor') {
8478: $domdefaults{'requestauthor'} = \%confhash;
8479: } else {
8480: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 8481: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 8482: $domdefaults{$key} = $confhash{$key};
8483: }
1.160.6.5 raeburn 8484: }
1.72 raeburn 8485: }
1.160.6.5 raeburn 8486:
1.1 raeburn 8487: my %quotahash = (
1.86 raeburn 8488: $action => { %confhash }
1.1 raeburn 8489: );
8490: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8491: $dom);
8492: if ($putresult eq 'ok') {
8493: if (keys(%changes) > 0) {
1.72 raeburn 8494: my $cachetime = 24*60*60;
8495: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 8496: if (ref($lastactref) eq 'HASH') {
8497: $lastactref->{'domdefaults'} = 1;
8498: }
1.1 raeburn 8499: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 8500: unless (($context eq 'requestcourses') ||
8501: ($context eq 'requestauthor')) {
1.86 raeburn 8502: if (ref($changes{'defaultquota'}) eq 'HASH') {
8503: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8504: foreach my $type (@{$types},'default') {
8505: if (defined($changes{'defaultquota'}{$type})) {
8506: my $typetitle = $usertypes->{$type};
8507: if ($type eq 'default') {
8508: $typetitle = $othertitle;
8509: }
1.160.6.28 raeburn 8510: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8511: }
8512: }
1.86 raeburn 8513: $resulttext .= '</ul></li>';
1.72 raeburn 8514: }
1.160.6.20 raeburn 8515: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 8516: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 8517: foreach my $type (@{$types},'default') {
8518: if (defined($changes{'authorquota'}{$type})) {
8519: my $typetitle = $usertypes->{$type};
8520: if ($type eq 'default') {
8521: $typetitle = $othertitle;
8522: }
1.160.6.28 raeburn 8523: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 8524: }
8525: }
8526: $resulttext .= '</ul></li>';
8527: }
1.72 raeburn 8528: }
1.80 raeburn 8529: my %newenv;
1.72 raeburn 8530: foreach my $item (@usertools) {
1.160.6.5 raeburn 8531: my (%haschgs,%inconf);
8532: if ($context eq 'requestauthor') {
8533: %haschgs = %changes;
8534: %inconf = %confhash;
8535: } else {
8536: if (ref($changes{$item}) eq 'HASH') {
8537: %haschgs = %{$changes{$item}};
8538: }
8539: if (ref($confhash{$item}) eq 'HASH') {
8540: %inconf = %{$confhash{$item}};
8541: }
8542: }
8543: if (keys(%haschgs) > 0) {
1.80 raeburn 8544: my $newacc =
8545: &Apache::lonnet::usertools_access($env{'user.name'},
8546: $env{'user.domain'},
1.86 raeburn 8547: $item,'reload',$context);
1.160.6.5 raeburn 8548: if (($context eq 'requestcourses') ||
8549: ($context eq 'requestauthor')) {
1.108 raeburn 8550: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8551: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8552: }
8553: } else {
8554: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8555: $newenv{'environment.availabletools.'.$item} = $newacc;
8556: }
1.80 raeburn 8557: }
1.160.6.5 raeburn 8558: unless ($context eq 'requestauthor') {
8559: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8560: }
1.72 raeburn 8561: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 8562: if ($haschgs{$type}) {
1.72 raeburn 8563: my $typetitle = $usertypes->{$type};
8564: if ($type eq 'default') {
8565: $typetitle = $othertitle;
8566: } elsif ($type eq '_LC_adv') {
8567: $typetitle = 'LON-CAPA Advanced Users';
8568: }
1.160.6.5 raeburn 8569: if ($inconf{$type}) {
1.101 raeburn 8570: if ($context eq 'requestcourses') {
8571: my $cond;
1.160.6.5 raeburn 8572: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8573: if ($1 eq '') {
8574: $cond = &mt('(Automatic processing of any request).');
8575: } else {
8576: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8577: }
8578: } else {
1.160.6.5 raeburn 8579: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8580: }
8581: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 8582: } elsif ($context eq 'requestauthor') {
8583: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8584: $titles{$inconf{$type}},$typetitle);
8585:
1.101 raeburn 8586: } else {
8587: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8588: }
1.72 raeburn 8589: } else {
1.104 raeburn 8590: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 8591: if ($inconf{$type} eq '0') {
1.104 raeburn 8592: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8593: } else {
8594: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8595: }
8596: } else {
8597: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8598: }
1.72 raeburn 8599: }
8600: }
1.26 raeburn 8601: }
1.160.6.5 raeburn 8602: unless ($context eq 'requestauthor') {
8603: $resulttext .= '</ul></li>';
8604: }
1.26 raeburn 8605: }
1.1 raeburn 8606: }
1.160.6.5 raeburn 8607: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8608: if (ref($changes{'notify'}) eq 'HASH') {
8609: if ($changes{'notify'}{'approval'}) {
8610: if (ref($confhash{'notify'}) eq 'HASH') {
8611: if ($confhash{'notify'}{'approval'}) {
8612: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8613: } else {
1.160.6.5 raeburn 8614: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8615: }
8616: }
8617: }
8618: }
8619: }
1.160.6.30 raeburn 8620: if ($action eq 'requestcourses') {
8621: my @offon = ('off','on');
8622: if ($changes{'uniquecode'}) {
8623: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8624: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8625: $resulttext .= '<li>'.
8626: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8627: '</li>';
8628: } else {
8629: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8630: '</li>';
8631: }
8632: }
1.160.6.46 raeburn 8633: foreach my $type ('textbooks','templates') {
8634: if (ref($changes{$type}) eq 'HASH') {
8635: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8636: foreach my $key (sort(keys(%{$changes{$type}}))) {
8637: my %coursehash = &Apache::lonnet::coursedescription($key);
8638: my $coursetitle = $coursehash{'description'};
8639: my $position = $confhash{$type}{$key}{'order'} + 1;
8640: $resulttext .= '<li>';
1.160.6.47 raeburn 8641: foreach my $item ('subject','title','publisher','author') {
8642: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8643: ($type eq 'templates'));
1.160.6.46 raeburn 8644: my $name = $item.':';
8645: $name =~ s/^(\w)/\U$1/;
8646: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8647: }
8648: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8649: if ($type eq 'textbooks') {
8650: if ($confhash{$type}{$key}{'image'}) {
8651: $resulttext .= ' '.&mt('Image: [_1]',
8652: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8653: ' alt="Textbook cover" />').'<br />';
8654: }
8655: }
8656: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 8657: }
1.160.6.46 raeburn 8658: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 8659: }
8660: }
1.160.6.39 raeburn 8661: if (ref($changes{'validation'}) eq 'HASH') {
8662: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8663: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8664: foreach my $item (@{$validationitemsref}) {
8665: if (exists($changes{'validation'}{$item})) {
8666: if ($item eq 'markup') {
8667: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8668: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8669: } else {
8670: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8671: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8672: }
8673: }
8674: }
8675: if (exists($changes{'validation'}{'dc'})) {
8676: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8677: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8678: }
8679: }
8680: }
1.160.6.30 raeburn 8681: }
1.1 raeburn 8682: $resulttext .= '</ul>';
1.80 raeburn 8683: if (keys(%newenv)) {
8684: &Apache::lonnet::appenv(\%newenv);
8685: }
1.1 raeburn 8686: } else {
1.86 raeburn 8687: if ($context eq 'requestcourses') {
8688: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 8689: } elsif ($context eq 'requestauthor') {
8690: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8691: } else {
1.90 weissno 8692: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8693: }
1.1 raeburn 8694: }
8695: } else {
1.11 albertel 8696: $resulttext = '<span class="LC_error">'.
8697: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8698: }
1.160.6.30 raeburn 8699: if ($errors) {
8700: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8701: '<ul>'.$errors.'</ul></p>';
8702: }
1.3 raeburn 8703: return $resulttext;
1.1 raeburn 8704: }
8705:
1.160.6.30 raeburn 8706: sub process_textbook_image {
1.160.6.46 raeburn 8707: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 8708: my $filename = $env{'form.'.$caller.'.filename'};
8709: my ($error,$url);
8710: my ($width,$height) = (50,50);
8711: if ($configuserok eq 'ok') {
8712: if ($switchserver) {
8713: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8714: $switchserver);
8715: } elsif ($author_ok eq 'ok') {
8716: my ($result,$imageurl) =
8717: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 8718: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 8719: if ($result eq 'ok') {
8720: $url = $imageurl;
8721: } else {
8722: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8723: }
8724: } else {
8725: $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);
8726: }
8727: } else {
8728: $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);
8729: }
8730: return ($url,$error);
8731: }
8732:
1.3 raeburn 8733: sub modify_autoenroll {
1.160.6.24 raeburn 8734: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 8735: my ($resulttext,%changes);
8736: my %currautoenroll;
8737: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
8738: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
8739: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
8740: }
8741: }
8742: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
8743: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 8744: sender => 'Sender for notification messages',
1.160.6.68 raeburn 8745: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
8746: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 8747: my @offon = ('off','on');
1.17 raeburn 8748: my $sender_uname = $env{'form.sender_uname'};
8749: my $sender_domain = $env{'form.sender_domain'};
8750: if ($sender_domain eq '') {
8751: $sender_uname = '';
8752: } elsif ($sender_uname eq '') {
8753: $sender_domain = '';
8754: }
1.129 raeburn 8755: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 8756: my $failsafe = $env{'form.autoenroll_failsafe'};
8757: $failsafe =~ s{^\s+|\s+$}{}g;
8758: if ($failsafe =~ /\D/) {
8759: undef($failsafe);
8760: }
1.1 raeburn 8761: my %autoenrollhash = (
1.129 raeburn 8762: autoenroll => { 'run' => $env{'form.autoenroll_run'},
8763: 'sender_uname' => $sender_uname,
8764: 'sender_domain' => $sender_domain,
8765: 'co-owners' => $coowners,
1.160.6.68 raeburn 8766: 'autofailsafe' => $failsafe,
1.1 raeburn 8767: }
8768: );
1.4 raeburn 8769: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
8770: $dom);
1.1 raeburn 8771: if ($putresult eq 'ok') {
8772: if (exists($currautoenroll{'run'})) {
8773: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
8774: $changes{'run'} = 1;
8775: }
8776: } elsif ($autorun) {
8777: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 8778: $changes{'run'} = 1;
1.1 raeburn 8779: }
8780: }
1.17 raeburn 8781: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 8782: $changes{'sender'} = 1;
8783: }
1.17 raeburn 8784: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 8785: $changes{'sender'} = 1;
8786: }
1.129 raeburn 8787: if ($currautoenroll{'co-owners'} ne '') {
8788: if ($currautoenroll{'co-owners'} ne $coowners) {
8789: $changes{'coowners'} = 1;
8790: }
8791: } elsif ($coowners) {
8792: $changes{'coowners'} = 1;
1.160.6.68 raeburn 8793: }
8794: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
8795: $changes{'autofailsafe'} = 1;
8796: }
1.1 raeburn 8797: if (keys(%changes) > 0) {
8798: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 8799: if ($changes{'run'}) {
1.1 raeburn 8800: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
8801: }
8802: if ($changes{'sender'}) {
1.17 raeburn 8803: if ($sender_uname eq '' || $sender_domain eq '') {
8804: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
8805: } else {
8806: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
8807: }
1.1 raeburn 8808: }
1.129 raeburn 8809: if ($changes{'coowners'}) {
8810: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
8811: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8812: if (ref($lastactref) eq 'HASH') {
8813: $lastactref->{'domainconfig'} = 1;
8814: }
1.129 raeburn 8815: }
1.160.6.68 raeburn 8816: if ($changes{'autofailsafe'}) {
8817: if ($failsafe ne '') {
1.160.6.82 raeburn 8818: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 8819: } else {
1.160.6.82 raeburn 8820: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 8821: }
8822: &Apache::lonnet::get_domain_defaults($dom,1);
8823: if (ref($lastactref) eq 'HASH') {
8824: $lastactref->{'domdefaults'} = 1;
8825: }
8826: }
1.1 raeburn 8827: $resulttext .= '</ul>';
8828: } else {
8829: $resulttext = &mt('No changes made to auto-enrollment settings');
8830: }
8831: } else {
1.11 albertel 8832: $resulttext = '<span class="LC_error">'.
8833: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8834: }
1.3 raeburn 8835: return $resulttext;
1.1 raeburn 8836: }
8837:
8838: sub modify_autoupdate {
1.3 raeburn 8839: my ($dom,%domconfig) = @_;
1.1 raeburn 8840: my ($resulttext,%currautoupdate,%fields,%changes);
8841: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
8842: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
8843: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
8844: }
8845: }
8846: my @offon = ('off','on');
8847: my %title = &Apache::lonlocal::texthash (
8848: run => 'Auto-update:',
8849: classlists => 'Updates to user information in classlists?'
8850: );
1.44 raeburn 8851: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8852: my %fieldtitles = &Apache::lonlocal::texthash (
8853: id => 'Student/Employee ID',
1.20 raeburn 8854: permanentemail => 'E-mail address',
1.1 raeburn 8855: lastname => 'Last Name',
8856: firstname => 'First Name',
8857: middlename => 'Middle Name',
1.132 raeburn 8858: generation => 'Generation',
1.1 raeburn 8859: );
1.142 raeburn 8860: $othertitle = &mt('All users');
1.1 raeburn 8861: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8862: $othertitle = &mt('Other users');
1.1 raeburn 8863: }
8864: foreach my $key (keys(%env)) {
8865: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8866: my ($usertype,$item) = ($1,$2);
8867: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8868: if ($usertype eq 'default') {
8869: push(@{$fields{$1}},$2);
8870: } elsif (ref($types) eq 'ARRAY') {
8871: if (grep(/^\Q$usertype\E$/,@{$types})) {
8872: push(@{$fields{$1}},$2);
8873: }
8874: }
8875: }
1.1 raeburn 8876: }
8877: }
1.131 raeburn 8878: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8879: @lockablenames = sort(@lockablenames);
8880: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8881: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8882: if (@changed) {
8883: $changes{'lockablenames'} = 1;
8884: }
8885: } else {
8886: if (@lockablenames) {
8887: $changes{'lockablenames'} = 1;
8888: }
8889: }
1.1 raeburn 8890: my %updatehash = (
8891: autoupdate => { run => $env{'form.autoupdate_run'},
8892: classlists => $env{'form.classlists'},
8893: fields => {%fields},
1.131 raeburn 8894: lockablenames => \@lockablenames,
1.1 raeburn 8895: }
8896: );
8897: foreach my $key (keys(%currautoupdate)) {
8898: if (($key eq 'run') || ($key eq 'classlists')) {
8899: if (exists($updatehash{autoupdate}{$key})) {
8900: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8901: $changes{$key} = 1;
8902: }
8903: }
8904: } elsif ($key eq 'fields') {
8905: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8906: foreach my $item (@{$types},'default') {
1.1 raeburn 8907: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8908: my $change = 0;
8909: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8910: if (!exists($fields{$item})) {
8911: $change = 1;
1.132 raeburn 8912: last;
1.1 raeburn 8913: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8914: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8915: $change = 1;
1.132 raeburn 8916: last;
1.1 raeburn 8917: }
8918: }
8919: }
8920: if ($change) {
8921: push(@{$changes{$key}},$item);
8922: }
1.26 raeburn 8923: }
1.1 raeburn 8924: }
8925: }
1.131 raeburn 8926: } elsif ($key eq 'lockablenames') {
8927: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8928: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8929: if (@changed) {
8930: $changes{'lockablenames'} = 1;
8931: }
8932: } else {
8933: if (@lockablenames) {
8934: $changes{'lockablenames'} = 1;
8935: }
8936: }
8937: }
8938: }
8939: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8940: if (@lockablenames) {
8941: $changes{'lockablenames'} = 1;
1.1 raeburn 8942: }
8943: }
1.26 raeburn 8944: foreach my $item (@{$types},'default') {
8945: if (defined($fields{$item})) {
8946: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8947: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8948: my $change = 0;
8949: if (ref($fields{$item}) eq 'ARRAY') {
8950: foreach my $type (@{$fields{$item}}) {
8951: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
8952: $change = 1;
8953: last;
8954: }
8955: }
8956: }
8957: if ($change) {
8958: push(@{$changes{'fields'}},$item);
8959: }
8960: } else {
1.26 raeburn 8961: push(@{$changes{'fields'}},$item);
8962: }
8963: } else {
8964: push(@{$changes{'fields'}},$item);
1.1 raeburn 8965: }
8966: }
8967: }
8968: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8969: $dom);
8970: if ($putresult eq 'ok') {
8971: if (keys(%changes) > 0) {
8972: $resulttext = &mt('Changes made:').'<ul>';
8973: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 8974: if ($key eq 'lockablenames') {
8975: $resulttext .= '<li>';
8976: if (@lockablenames) {
8977: $usertypes->{'default'} = $othertitle;
8978: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8979: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8980: } else {
8981: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8982: }
8983: $resulttext .= '</li>';
8984: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8985: foreach my $item (@{$changes{$key}}) {
8986: my @newvalues;
8987: foreach my $type (@{$fields{$item}}) {
8988: push(@newvalues,$fieldtitles{$type});
8989: }
1.3 raeburn 8990: my $newvaluestr;
8991: if (@newvalues > 0) {
8992: $newvaluestr = join(', ',@newvalues);
8993: } else {
8994: $newvaluestr = &mt('none');
1.6 raeburn 8995: }
1.1 raeburn 8996: if ($item eq 'default') {
1.26 raeburn 8997: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8998: } else {
1.26 raeburn 8999: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 9000: }
9001: }
9002: } else {
9003: my $newvalue;
9004: if ($key eq 'run') {
9005: $newvalue = $offon[$env{'form.autoupdate_run'}];
9006: } else {
9007: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 9008: }
1.1 raeburn 9009: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
9010: }
9011: }
9012: $resulttext .= '</ul>';
9013: } else {
1.3 raeburn 9014: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 9015: }
9016: } else {
1.11 albertel 9017: $resulttext = '<span class="LC_error">'.
9018: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 9019: }
1.3 raeburn 9020: return $resulttext;
1.1 raeburn 9021: }
9022:
1.125 raeburn 9023: sub modify_autocreate {
9024: my ($dom,%domconfig) = @_;
9025: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
9026: if (ref($domconfig{'autocreate'}) eq 'HASH') {
9027: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
9028: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
9029: }
9030: }
9031: my %title= ( xml => 'Auto-creation of courses in XML course description files',
9032: req => 'Auto-creation of validated requests for official courses',
9033: xmldc => 'Identity of course creator of courses from XML files',
9034: );
9035: my @types = ('xml','req');
9036: foreach my $item (@types) {
9037: $newvals{$item} = $env{'form.autocreate_'.$item};
9038: $newvals{$item} =~ s/\D//g;
9039: $newvals{$item} = 0 if ($newvals{$item} eq '');
9040: }
9041: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 9042: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 9043: unless (exists($domcoords{$newvals{'xmldc'}})) {
9044: $newvals{'xmldc'} = '';
9045: }
9046: %autocreatehash = (
9047: autocreate => { xml => $newvals{'xml'},
9048: req => $newvals{'req'},
9049: }
9050: );
9051: if ($newvals{'xmldc'} ne '') {
9052: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9053: }
9054: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9055: $dom);
9056: if ($putresult eq 'ok') {
9057: my @items = @types;
9058: if ($newvals{'xml'}) {
9059: push(@items,'xmldc');
9060: }
9061: foreach my $item (@items) {
9062: if (exists($currautocreate{$item})) {
9063: if ($currautocreate{$item} ne $newvals{$item}) {
9064: $changes{$item} = 1;
9065: }
9066: } elsif ($newvals{$item}) {
9067: $changes{$item} = 1;
9068: }
9069: }
9070: if (keys(%changes) > 0) {
9071: my @offon = ('off','on');
9072: $resulttext = &mt('Changes made:').'<ul>';
9073: foreach my $item (@types) {
9074: if ($changes{$item}) {
9075: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 9076: $resulttext .= '<li>'.
9077: &mt("$title{$item} set to [_1]$newtxt [_2]",
9078: '<b>','</b>').
9079: '</li>';
1.125 raeburn 9080: }
9081: }
9082: if ($changes{'xmldc'}) {
9083: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9084: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 9085: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9086: }
9087: $resulttext .= '</ul>';
9088: } else {
9089: $resulttext = &mt('No changes made to auto-creation settings');
9090: }
9091: } else {
9092: $resulttext = '<span class="LC_error">'.
9093: &mt('An error occurred: [_1]',$putresult).'</span>';
9094: }
9095: return $resulttext;
9096: }
9097:
1.23 raeburn 9098: sub modify_directorysrch {
1.160.6.81 raeburn 9099: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 9100: my ($resulttext,%changes);
9101: my %currdirsrch;
9102: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9103: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9104: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9105: }
9106: }
1.160.6.72 raeburn 9107: my %title = ( available => 'Institutional directory search available',
9108: localonly => 'Other domains can search institution',
9109: lcavailable => 'LON-CAPA directory search available',
9110: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9111: searchby => 'Search types',
9112: searchtypes => 'Search latitude');
9113: my @offon = ('off','on');
1.24 raeburn 9114: my @otherdoms = ('Yes','No');
1.23 raeburn 9115:
1.25 raeburn 9116: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9117: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9118: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9119:
1.44 raeburn 9120: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9121: if (keys(%{$usertypes}) == 0) {
9122: @cansearch = ('default');
9123: } else {
9124: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9125: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9126: if (!grep(/^\Q$type\E$/,@cansearch)) {
9127: push(@{$changes{'cansearch'}},$type);
9128: }
1.23 raeburn 9129: }
1.26 raeburn 9130: foreach my $type (@cansearch) {
9131: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9132: push(@{$changes{'cansearch'}},$type);
9133: }
1.23 raeburn 9134: }
1.26 raeburn 9135: } else {
9136: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9137: }
9138: }
9139:
9140: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9141: foreach my $by (@{$currdirsrch{'searchby'}}) {
9142: if (!grep(/^\Q$by\E$/,@searchby)) {
9143: push(@{$changes{'searchby'}},$by);
9144: }
9145: }
9146: foreach my $by (@searchby) {
9147: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9148: push(@{$changes{'searchby'}},$by);
9149: }
9150: }
9151: } else {
9152: push(@{$changes{'searchby'}},@searchby);
9153: }
1.25 raeburn 9154:
9155: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9156: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9157: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9158: push(@{$changes{'searchtypes'}},$type);
9159: }
9160: }
9161: foreach my $type (@searchtypes) {
9162: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9163: push(@{$changes{'searchtypes'}},$type);
9164: }
9165: }
9166: } else {
9167: if (exists($currdirsrch{'searchtypes'})) {
9168: foreach my $type (@searchtypes) {
9169: if ($type ne $currdirsrch{'searchtypes'}) {
9170: push(@{$changes{'searchtypes'}},$type);
9171: }
9172: }
9173: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9174: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9175: }
9176: } else {
9177: push(@{$changes{'searchtypes'}},@searchtypes);
9178: }
9179: }
9180:
1.23 raeburn 9181: my %dirsrch_hash = (
9182: directorysrch => { available => $env{'form.dirsrch_available'},
9183: cansearch => \@cansearch,
1.160.6.72 raeburn 9184: localonly => $env{'form.dirsrch_instlocalonly'},
9185: lclocalonly => $env{'form.dirsrch_domlocalonly'},
9186: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9187: searchby => \@searchby,
1.25 raeburn 9188: searchtypes => \@searchtypes,
1.23 raeburn 9189: }
9190: );
9191: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9192: $dom);
9193: if ($putresult eq 'ok') {
9194: if (exists($currdirsrch{'available'})) {
9195: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9196: $changes{'available'} = 1;
9197: }
9198: } else {
9199: if ($env{'form.dirsrch_available'} eq '1') {
9200: $changes{'available'} = 1;
9201: }
9202: }
1.160.6.72 raeburn 9203: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 9204: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
9205: $changes{'lcavailable'} = 1;
9206: }
1.24 raeburn 9207: } else {
1.160.6.72 raeburn 9208: if ($env{'form.dirsrch_lcavailable'} eq '1') {
9209: $changes{'lcavailable'} = 1;
9210: }
9211: }
9212: if (exists($currdirsrch{'localonly'})) {
9213: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9214: $changes{'localonly'} = 1;
9215: }
1.160.6.72 raeburn 9216: } else {
9217: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
9218: $changes{'localonly'} = 1;
9219: }
9220: }
9221: if (exists($currdirsrch{'lclocalonly'})) {
9222: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
9223: $changes{'lclocalonly'} = 1;
9224: }
9225: } else {
9226: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
9227: $changes{'lclocalonly'} = 1;
9228: }
1.24 raeburn 9229: }
1.23 raeburn 9230: if (keys(%changes) > 0) {
9231: $resulttext = &mt('Changes made:').'<ul>';
9232: if ($changes{'available'}) {
9233: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9234: }
1.160.6.72 raeburn 9235: if ($changes{'lcavailable'}) {
9236: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
9237: }
1.24 raeburn 9238: if ($changes{'localonly'}) {
1.160.6.72 raeburn 9239: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
9240: }
9241: if ($changes{'lclocalonly'}) {
9242: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 9243: }
1.23 raeburn 9244: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9245: my $chgtext;
1.26 raeburn 9246: if (ref($usertypes) eq 'HASH') {
9247: if (keys(%{$usertypes}) > 0) {
9248: foreach my $type (@{$types}) {
9249: if (grep(/^\Q$type\E$/,@cansearch)) {
9250: $chgtext .= $usertypes->{$type}.'; ';
9251: }
9252: }
9253: if (grep(/^default$/,@cansearch)) {
9254: $chgtext .= $othertitle;
9255: } else {
9256: $chgtext =~ s/\; $//;
9257: }
1.160.6.13 raeburn 9258: $resulttext .=
9259: '<li>'.
9260: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9261: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9262: '</li>';
1.23 raeburn 9263: }
9264: }
9265: }
9266: if (ref($changes{'searchby'}) eq 'ARRAY') {
9267: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9268: my $chgtext;
9269: foreach my $type (@{$titleorder}) {
9270: if (grep(/^\Q$type\E$/,@searchby)) {
9271: if (defined($searchtitles->{$type})) {
9272: $chgtext .= $searchtitles->{$type}.'; ';
9273: }
9274: }
9275: }
9276: $chgtext =~ s/\; $//;
9277: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9278: }
1.25 raeburn 9279: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9280: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9281: my $chgtext;
9282: foreach my $type (@{$srchtypeorder}) {
9283: if (grep(/^\Q$type\E$/,@searchtypes)) {
9284: if (defined($srchtypes_desc->{$type})) {
9285: $chgtext .= $srchtypes_desc->{$type}.'; ';
9286: }
9287: }
9288: }
9289: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 9290: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9291: }
9292: $resulttext .= '</ul>';
1.160.6.81 raeburn 9293: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
9294: if (ref($lastactref) eq 'HASH') {
9295: $lastactref->{'directorysrch'} = 1;
9296: }
1.23 raeburn 9297: } else {
1.160.6.72 raeburn 9298: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9299: }
9300: } else {
9301: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9302: &mt('An error occurred: [_1]',$putresult).'</span>';
9303: }
9304: return $resulttext;
9305: }
9306:
1.28 raeburn 9307: sub modify_contacts {
1.160.6.24 raeburn 9308: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9309: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9310: if (ref($domconfig{'contacts'}) eq 'HASH') {
9311: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9312: $currsetting{$key} = $domconfig{'contacts'}{$key};
9313: }
9314: }
1.160.6.78 raeburn 9315: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 9316: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 9317: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.91! raeburn 9318: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail',hostipmail');
1.160.6.23 raeburn 9319: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 9320: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 9321: foreach my $type (@mailings) {
9322: @{$newsetting{$type}} =
9323: &Apache::loncommon::get_env_multiple('form.'.$type);
9324: foreach my $item (@contacts) {
9325: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9326: $contacts_hash{contacts}{$type}{$item} = 1;
9327: } else {
9328: $contacts_hash{contacts}{$type}{$item} = 0;
9329: }
1.160.6.78 raeburn 9330: }
1.28 raeburn 9331: $others{$type} = $env{'form.'.$type.'_others'};
9332: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 9333: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9334: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9335: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 9336: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
9337: $includestr{$type} = $env{'form.'.$type.'_includestr'};
9338: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
9339: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
9340: }
1.134 raeburn 9341: }
1.28 raeburn 9342: }
9343: foreach my $item (@contacts) {
9344: $to{$item} = $env{'form.'.$item};
9345: $contacts_hash{'contacts'}{$item} = $to{$item};
9346: }
1.160.6.23 raeburn 9347: foreach my $item (@toggles) {
9348: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9349: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9350: }
9351: }
1.160.6.78 raeburn 9352: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
9353: foreach my $field (@{$fields}) {
9354: if (ref($possoptions->{$field}) eq 'ARRAY') {
9355: my $value = $env{'form.helpform_'.$field};
9356: $value =~ s/^\s+|\s+$//g;
9357: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
9358: $contacts_hash{contacts}{'helpform'}{$field} = $value;
9359: if ($field eq 'screenshot') {
9360: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
9361: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
9362: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
9363: }
9364: }
9365: }
9366: }
9367: }
9368: }
1.28 raeburn 9369: if (keys(%currsetting) > 0) {
9370: foreach my $item (@contacts) {
9371: if ($to{$item} ne $currsetting{$item}) {
9372: $changes{$item} = 1;
9373: }
9374: }
9375: foreach my $type (@mailings) {
9376: foreach my $item (@contacts) {
9377: if (ref($currsetting{$type}) eq 'HASH') {
9378: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9379: push(@{$changes{$type}},$item);
9380: }
9381: } else {
9382: push(@{$changes{$type}},@{$newsetting{$type}});
9383: }
9384: }
9385: if ($others{$type} ne $currsetting{$type}{'others'}) {
9386: push(@{$changes{$type}},'others');
9387: }
1.160.6.78 raeburn 9388: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9389: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9390: push(@{$changes{$type}},'bcc');
9391: }
1.160.6.78 raeburn 9392: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
9393: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
9394: push(@{$changes{$type}},'include');
9395: }
9396: }
9397: }
9398: if (ref($fields) eq 'ARRAY') {
9399: if (ref($currsetting{'helpform'}) eq 'HASH') {
9400: foreach my $field (@{$fields}) {
9401: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
9402: push(@{$changes{'helpform'}},$field);
9403: }
9404: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9405: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
9406: push(@{$changes{'helpform'}},'maxsize');
9407: }
9408: }
9409: }
9410: } else {
9411: foreach my $field (@{$fields}) {
9412: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9413: push(@{$changes{'helpform'}},$field);
9414: }
9415: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9416: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9417: push(@{$changes{'helpform'}},'maxsize');
9418: }
9419: }
9420: }
1.134 raeburn 9421: }
1.28 raeburn 9422: }
9423: } else {
9424: my %default;
9425: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9426: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9427: $default{'errormail'} = 'adminemail';
9428: $default{'packagesmail'} = 'adminemail';
9429: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 9430: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 9431: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9432: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 9433: $default{'updatesmail'} = 'adminemail';
1.160.6.91! raeburn 9434: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 9435: foreach my $item (@contacts) {
9436: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 9437: $changes{$item} = 1;
1.160.6.23 raeburn 9438: }
1.28 raeburn 9439: }
9440: foreach my $type (@mailings) {
9441: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9442: push(@{$changes{$type}},@{$newsetting{$type}});
9443: }
9444: if ($others{$type} ne '') {
9445: push(@{$changes{$type}},'others');
1.134 raeburn 9446: }
1.160.6.78 raeburn 9447: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9448: if ($bcc{$type} ne '') {
9449: push(@{$changes{$type}},'bcc');
9450: }
1.160.6.78 raeburn 9451: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
9452: push(@{$changes{$type}},'include');
9453: }
9454: }
9455: }
9456: if (ref($fields) eq 'ARRAY') {
9457: foreach my $field (@{$fields}) {
9458: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9459: push(@{$changes{'helpform'}},$field);
9460: }
9461: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9462: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9463: push(@{$changes{'helpform'}},'maxsize');
9464: }
9465: }
1.134 raeburn 9466: }
1.28 raeburn 9467: }
9468: }
1.160.6.23 raeburn 9469: foreach my $item (@toggles) {
9470: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9471: $changes{$item} = 1;
9472: } elsif ((!$env{'form.'.$item}) &&
9473: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9474: $changes{$item} = 1;
9475: }
9476: }
1.28 raeburn 9477: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9478: $dom);
9479: if ($putresult eq 'ok') {
9480: if (keys(%changes) > 0) {
1.160.6.24 raeburn 9481: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9482: if (ref($lastactref) eq 'HASH') {
9483: $lastactref->{'domainconfig'} = 1;
9484: }
1.28 raeburn 9485: my ($titles,$short_titles) = &contact_titles();
9486: $resulttext = &mt('Changes made:').'<ul>';
9487: foreach my $item (@contacts) {
9488: if ($changes{$item}) {
9489: $resulttext .= '<li>'.$titles->{$item}.
9490: &mt(' set to: ').
9491: '<span class="LC_cusr_emph">'.
9492: $to{$item}.'</span></li>';
9493: }
9494: }
9495: foreach my $type (@mailings) {
9496: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 9497: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
9498: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
9499: } else {
9500: $resulttext .= '<li>'.$titles->{$type}.': ';
9501: }
1.28 raeburn 9502: my @text;
9503: foreach my $item (@{$newsetting{$type}}) {
9504: push(@text,$short_titles->{$item});
9505: }
9506: if ($others{$type} ne '') {
9507: push(@text,$others{$type});
9508: }
1.160.6.78 raeburn 9509: if (@text) {
9510: $resulttext .= '<span class="LC_cusr_emph">'.
9511: join(', ',@text).'</span>';
9512: }
9513: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9514: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 9515: my $bcctext;
9516: if (@text) {
9517: $bcctext = ' '.&mt('with Bcc to');
9518: } else {
9519: $bcctext = '(Bcc)';
9520: }
9521: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9522: } elsif (!@text) {
9523: $resulttext .= &mt('No one');
1.134 raeburn 9524: }
1.160.6.78 raeburn 9525: if ($includestr{$type} ne '') {
9526: if ($includeloc{$type} eq 'b') {
9527: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
9528: } elsif ($includeloc{$type} eq 's') {
9529: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
9530: }
9531: }
9532: } elsif (!@text) {
9533: $resulttext .= &mt('No recipients');
1.134 raeburn 9534: }
9535: $resulttext .= '</li>';
1.28 raeburn 9536: }
9537: }
1.160.6.23 raeburn 9538: my @offon = ('off','on');
9539: if ($changes{'reporterrors'}) {
9540: $resulttext .= '<li>'.
9541: &mt('E-mail error reports to [_1] set to "'.
9542: $offon[$env{'form.reporterrors'}].'".',
9543: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9544: &mt('LON-CAPA core group - MSU'),600,500)).
9545: '</li>';
9546: }
9547: if ($changes{'reportupdates'}) {
9548: $resulttext .= '<li>'.
9549: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9550: $offon[$env{'form.reportupdates'}].'".',
9551: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9552: &mt('LON-CAPA core group - MSU'),600,500)).
9553: '</li>';
9554: }
1.160.6.78 raeburn 9555: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
9556: my (@optional,@required,@unused,$maxsizechg);
9557: foreach my $field (@{$changes{'helpform'}}) {
9558: if ($field eq 'maxsize') {
9559: $maxsizechg = 1;
9560: next;
9561: }
9562: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
9563: push(@optional,$field);
9564: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
9565: push(@unused,$field);
9566: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
9567: push(@required,$field);
9568: }
9569: }
9570: if (@optional) {
9571: $resulttext .= '<li>'.
9572: &mt('Help form fields changed to "Optional": [_1].',
9573: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
9574: '</li>';
9575: }
9576: if (@required) {
9577: $resulttext .= '<li>'.
9578: &mt('Help form fields changed to "Required": [_1].',
9579: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
9580: '</li>';
9581: }
9582: if (@unused) {
9583: $resulttext .= '<li>'.
9584: &mt('Help form fields changed to "Not shown": [_1].',
9585: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
9586: '</li>';
9587: }
9588: if ($maxsizechg) {
9589: $resulttext .= '<li>'.
9590: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
9591: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
9592: '</li>';
9593:
9594: }
9595: }
1.28 raeburn 9596: $resulttext .= '</ul>';
9597: } else {
1.160.6.78 raeburn 9598: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 9599: }
9600: } else {
9601: $resulttext = '<span class="LC_error">'.
9602: &mt('An error occurred: [_1].',$putresult).'</span>';
9603: }
9604: return $resulttext;
9605: }
9606:
9607: sub modify_usercreation {
1.27 raeburn 9608: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9609: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9610: my $warningmsg;
1.27 raeburn 9611: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9612: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 9613: if ($key eq 'cancreate') {
9614: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9615: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9616: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 9617: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9618: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 9619: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9620: } else {
9621: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9622: }
1.50 raeburn 9623: }
1.43 raeburn 9624: }
1.160.6.34 raeburn 9625: } elsif ($key eq 'email_rule') {
9626: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9627: } else {
9628: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 9629: }
9630: }
1.34 raeburn 9631: }
1.160.6.34 raeburn 9632: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
9633: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
9634: my @contexts = ('author','course','requestcrs');
9635: foreach my $item(@contexts) {
9636: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9637: }
1.34 raeburn 9638: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9639: foreach my $item (@contexts) {
1.160.6.34 raeburn 9640: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9641: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9642: }
1.27 raeburn 9643: }
1.34 raeburn 9644: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9645: foreach my $item (@contexts) {
1.43 raeburn 9646: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9647: if ($cancreate{$item} ne 'any') {
9648: push(@{$changes{'cancreate'}},$item);
9649: }
9650: } else {
9651: if ($cancreate{$item} ne 'none') {
9652: push(@{$changes{'cancreate'}},$item);
9653: }
1.27 raeburn 9654: }
9655: }
9656: } else {
1.43 raeburn 9657: foreach my $item (@contexts) {
1.34 raeburn 9658: push(@{$changes{'cancreate'}},$item);
9659: }
1.27 raeburn 9660: }
1.34 raeburn 9661:
1.27 raeburn 9662: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9663: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9664: if (!grep(/^\Q$type\E$/,@username_rule)) {
9665: push(@{$changes{'username_rule'}},$type);
9666: }
9667: }
9668: foreach my $type (@username_rule) {
9669: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9670: push(@{$changes{'username_rule'}},$type);
9671: }
9672: }
9673: } else {
9674: push(@{$changes{'username_rule'}},@username_rule);
9675: }
9676:
1.32 raeburn 9677: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9678: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9679: if (!grep(/^\Q$type\E$/,@id_rule)) {
9680: push(@{$changes{'id_rule'}},$type);
9681: }
9682: }
9683: foreach my $type (@id_rule) {
9684: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9685: push(@{$changes{'id_rule'}},$type);
9686: }
9687: }
9688: } else {
9689: push(@{$changes{'id_rule'}},@id_rule);
9690: }
9691:
1.43 raeburn 9692: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9693: my @authtypes = ('int','krb4','krb5','loc');
9694: my %authhash;
1.43 raeburn 9695: foreach my $item (@authen_contexts) {
1.28 raeburn 9696: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9697: foreach my $auth (@authtypes) {
9698: if (grep(/^\Q$auth\E$/,@authallowed)) {
9699: $authhash{$item}{$auth} = 1;
9700: } else {
9701: $authhash{$item}{$auth} = 0;
9702: }
9703: }
9704: }
9705: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9706: foreach my $item (@authen_contexts) {
1.28 raeburn 9707: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
9708: foreach my $auth (@authtypes) {
9709: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
9710: push(@{$changes{'authtypes'}},$item);
9711: last;
9712: }
9713: }
9714: }
9715: }
9716: } else {
1.43 raeburn 9717: foreach my $item (@authen_contexts) {
1.28 raeburn 9718: push(@{$changes{'authtypes'}},$item);
9719: }
9720: }
9721:
1.160.6.34 raeburn 9722: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
9723: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
9724: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
9725: $save_usercreate{'id_rule'} = \@id_rule;
9726: $save_usercreate{'username_rule'} = \@username_rule,
9727: $save_usercreate{'authtypes'} = \%authhash;
9728:
1.27 raeburn 9729: my %usercreation_hash = (
1.160.6.34 raeburn 9730: usercreation => \%save_usercreate,
9731: );
1.27 raeburn 9732:
9733: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
9734: $dom);
1.50 raeburn 9735:
1.160.6.34 raeburn 9736: if ($putresult eq 'ok') {
9737: if (keys(%changes) > 0) {
9738: $resulttext = &mt('Changes made:').'<ul>';
9739: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9740: my %lt = &usercreation_types();
9741: foreach my $type (@{$changes{'cancreate'}}) {
9742: my $chgtext = $lt{$type}.', ';
9743: if ($cancreate{$type} eq 'none') {
9744: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
9745: } elsif ($cancreate{$type} eq 'any') {
9746: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
9747: } elsif ($cancreate{$type} eq 'official') {
9748: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
9749: } elsif ($cancreate{$type} eq 'unofficial') {
9750: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
9751: }
9752: $resulttext .= '<li>'.$chgtext.'</li>';
9753: }
9754: }
9755: if (ref($changes{'username_rule'}) eq 'ARRAY') {
9756: my ($rules,$ruleorder) =
9757: &Apache::lonnet::inst_userrules($dom,'username');
9758: my $chgtext = '<ul>';
9759: foreach my $type (@username_rule) {
9760: if (ref($rules->{$type}) eq 'HASH') {
9761: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
9762: }
9763: }
9764: $chgtext .= '</ul>';
9765: if (@username_rule > 0) {
9766: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9767: } else {
9768: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
9769: }
9770: }
9771: if (ref($changes{'id_rule'}) eq 'ARRAY') {
9772: my ($idrules,$idruleorder) =
9773: &Apache::lonnet::inst_userrules($dom,'id');
9774: my $chgtext = '<ul>';
9775: foreach my $type (@id_rule) {
9776: if (ref($idrules->{$type}) eq 'HASH') {
9777: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
9778: }
9779: }
9780: $chgtext .= '</ul>';
9781: if (@id_rule > 0) {
9782: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9783: } else {
9784: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
9785: }
9786: }
9787: my %authname = &authtype_names();
9788: my %context_title = &context_names();
9789: if (ref($changes{'authtypes'}) eq 'ARRAY') {
9790: my $chgtext = '<ul>';
9791: foreach my $type (@{$changes{'authtypes'}}) {
9792: my @allowed;
9793: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
9794: foreach my $auth (@authtypes) {
9795: if ($authhash{$type}{$auth}) {
9796: push(@allowed,$authname{$auth});
9797: }
9798: }
9799: if (@allowed > 0) {
9800: $chgtext .= join(', ',@allowed).'</li>';
9801: } else {
9802: $chgtext .= &mt('none').'</li>';
9803: }
9804: }
9805: $chgtext .= '</ul>';
9806: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
9807: $resulttext .= '</li>';
9808: }
9809: $resulttext .= '</ul>';
9810: } else {
9811: $resulttext = &mt('No changes made to user creation settings');
9812: }
9813: } else {
9814: $resulttext = '<span class="LC_error">'.
9815: &mt('An error occurred: [_1]',$putresult).'</span>';
9816: }
9817: if ($warningmsg ne '') {
9818: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9819: }
9820: return $resulttext;
9821: }
9822:
9823: sub modify_selfcreation {
9824: my ($dom,%domconfig) = @_;
9825: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
9826: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 9827: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9828: if (ref($types) eq 'ARRAY') {
9829: $usertypes->{'default'} = $othertitle;
9830: push(@{$types},'default');
9831: }
1.160.6.34 raeburn 9832: #
9833: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
9834: #
9835: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9836: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9837: if ($key eq 'cancreate') {
9838: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9839: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9840: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9841: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 9842: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 9843: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 9844: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 9845: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9846: } else {
9847: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9848: }
9849: }
9850: }
9851: } elsif ($key eq 'email_rule') {
9852: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9853: } else {
9854: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9855: }
9856: }
9857: }
9858: #
9859: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
9860: #
9861: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9862: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9863: if ($key eq 'selfcreate') {
9864: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
9865: } else {
9866: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
9867: }
9868: }
9869: }
9870:
9871: my @contexts = ('selfcreate');
9872: @{$cancreate{'selfcreate'}} = ();
9873: %{$cancreate{'emailusername'}} = ();
9874: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 9875: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 9876: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 9877: my %selfcreatetypes = (
9878: sso => 'users authenticated by institutional single sign on',
9879: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 9880: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 9881: );
1.160.6.34 raeburn 9882: #
9883: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
9884: # is permitted.
9885: #
1.160.6.40 raeburn 9886:
9887: my @statuses;
9888: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9889: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
9890: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
9891: }
9892: }
9893: push(@statuses,'default');
9894:
1.160.6.35 raeburn 9895: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 9896: if ($item eq 'email') {
1.160.6.40 raeburn 9897: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 9898: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 9899: push(@contexts,'selfcreateprocessing');
9900: foreach my $type (@statuses) {
9901: if ($type eq 'default') {
9902: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
9903: } else {
9904: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
9905: }
9906: }
1.160.6.34 raeburn 9907: }
9908: } else {
9909: if ($env{'form.cancreate_'.$item}) {
9910: push(@{$cancreate{'selfcreate'}},$item);
9911: }
9912: }
9913: }
9914: my (@email_rule,%userinfo,%savecaptcha);
9915: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9916: #
1.160.6.35 raeburn 9917: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9918: # 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 9919: #
1.160.6.40 raeburn 9920:
1.160.6.48 raeburn 9921: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 9922: push(@contexts,'emailusername');
1.160.6.35 raeburn 9923: if (ref($types) eq 'ARRAY') {
9924: foreach my $type (@{$types}) {
9925: if (ref($infofields) eq 'ARRAY') {
9926: foreach my $field (@{$infofields}) {
9927: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9928: $cancreate{'emailusername'}{$type}{$field} = $1;
9929: }
9930: }
1.160.6.34 raeburn 9931: }
9932: }
9933: }
9934: #
9935: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9936: # queued requests for self-creation of account using e-mail address as username
9937: #
9938:
9939: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9940: @approvalnotify = sort(@approvalnotify);
9941: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9942: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9943: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9944: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9945: push(@{$changes{'cancreate'}},'notify');
9946: }
9947: } else {
9948: if ($cancreate{'notify'}{'approval'}) {
9949: push(@{$changes{'cancreate'}},'notify');
9950: }
9951: }
9952: } elsif ($cancreate{'notify'}{'approval'}) {
9953: push(@{$changes{'cancreate'}},'notify');
9954: }
9955:
9956: #
9957: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9958: #
9959: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9960: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9961: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9962: if (@{$curr_usercreation{'email_rule'}} > 0) {
9963: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9964: if (!grep(/^\Q$type\E$/,@email_rule)) {
9965: push(@{$changes{'email_rule'}},$type);
9966: }
9967: }
9968: }
9969: if (@email_rule > 0) {
9970: foreach my $type (@email_rule) {
9971: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9972: push(@{$changes{'email_rule'}},$type);
9973: }
9974: }
9975: }
9976: } elsif (@email_rule > 0) {
9977: push(@{$changes{'email_rule'}},@email_rule);
9978: }
9979: }
9980: #
1.160.6.40 raeburn 9981: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 9982: # institutional log-in.
9983: #
9984: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9985: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9986: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
9987: ($domdefaults{'auth_def'} eq 'localauth'))) {
9988: $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.').' '.
9989: &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.');
9990: }
9991: }
9992: my @fields = ('lastname','firstname','middlename','generation',
9993: 'permanentemail','id');
1.160.6.44 raeburn 9994: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 9995: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9996: #
9997: # Where usernames may created for institutional log-in and/or institutional single sign on:
9998: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9999: # may self-create accounts
10000: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
10001: # which the user may supply, if institutional data is unavailable.
10002: #
10003: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
10004: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 10005: if (@{$types} > 1) {
1.160.6.34 raeburn 10006: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
10007: push(@contexts,'statustocreate');
10008: } else {
10009: undef($cancreate{'statustocreate'});
10010: }
10011: foreach my $type (@{$types}) {
10012: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
10013: foreach my $field (@fields) {
10014: if (grep(/^\Q$field\E$/,@modifiable)) {
10015: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
10016: } else {
10017: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
10018: }
10019: }
10020: }
10021: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
10022: foreach my $type (@{$types}) {
10023: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
10024: foreach my $field (@fields) {
10025: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
10026: $curr_usermodify{'selfcreate'}{$type}{$field}) {
10027: push(@{$changes{'selfcreate'}},$type);
10028: last;
10029: }
10030: }
10031: }
10032: }
10033: } else {
10034: foreach my $type (@{$types}) {
10035: push(@{$changes{'selfcreate'}},$type);
10036: }
10037: }
10038: }
1.160.6.44 raeburn 10039: foreach my $field (@shibfields) {
10040: if ($env{'form.shibenv_'.$field} ne '') {
10041: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10042: }
10043: }
10044: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10045: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10046: foreach my $field (@shibfields) {
10047: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10048: push(@{$changes{'cancreate'}},'shibenv');
10049: }
10050: }
10051: } else {
10052: foreach my $field (@shibfields) {
10053: if ($env{'form.shibenv_'.$field}) {
10054: push(@{$changes{'cancreate'}},'shibenv');
10055: last;
10056: }
10057: }
10058: }
10059: }
1.160.6.34 raeburn 10060: }
10061: foreach my $item (@contexts) {
10062: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10063: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10064: if (ref($cancreate{$item}) eq 'ARRAY') {
10065: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10066: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10067: push(@{$changes{'cancreate'}},$item);
10068: }
10069: }
10070: }
10071: }
10072: if (ref($cancreate{$item}) eq 'ARRAY') {
10073: foreach my $type (@{$cancreate{$item}}) {
10074: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10075: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10076: push(@{$changes{'cancreate'}},$item);
10077: }
10078: }
10079: }
10080: }
10081: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10082: if (ref($cancreate{$item}) eq 'HASH') {
10083: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 10084: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10085: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10086: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10087: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10088: push(@{$changes{'cancreate'}},$item);
10089: }
10090: }
10091: }
1.160.6.40 raeburn 10092: } elsif ($item eq 'selfcreateprocessing') {
10093: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10094: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10095: push(@{$changes{'cancreate'}},$item);
10096: }
10097: }
1.160.6.35 raeburn 10098: } else {
10099: if (!$cancreate{$item}{$curr}) {
10100: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10101: push(@{$changes{'cancreate'}},$item);
10102: }
1.160.6.34 raeburn 10103: }
10104: }
10105: }
10106: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 10107: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10108: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10109: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10110: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10111: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10112: push(@{$changes{'cancreate'}},$item);
10113: }
10114: }
10115: } else {
10116: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10117: push(@{$changes{'cancreate'}},$item);
10118: }
10119: }
10120: }
1.160.6.40 raeburn 10121: } elsif ($item eq 'selfcreateprocessing') {
10122: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10123: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10124: push(@{$changes{'cancreate'}},$item);
10125: }
10126: }
1.160.6.35 raeburn 10127: } else {
10128: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10129: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10130: push(@{$changes{'cancreate'}},$item);
10131: }
1.160.6.34 raeburn 10132: }
10133: }
10134: }
10135: }
10136: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10137: if (ref($cancreate{$item}) eq 'ARRAY') {
10138: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10139: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10140: push(@{$changes{'cancreate'}},$item);
10141: }
10142: }
10143: } elsif (ref($cancreate{$item}) eq 'HASH') {
10144: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10145: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10146: push(@{$changes{'cancreate'}},$item);
10147: }
10148: }
10149: }
10150: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 10151: if (ref($cancreate{$item}) eq 'HASH') {
10152: foreach my $type (keys(%{$cancreate{$item}})) {
10153: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10154: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10155: if ($cancreate{$item}{$type}{$field}) {
10156: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10157: push(@{$changes{'cancreate'}},$item);
10158: }
10159: last;
10160: }
10161: }
10162: }
10163: }
1.160.6.34 raeburn 10164: }
10165: }
10166: }
10167: #
10168: # Populate %save_usercreate hash with updates to self-creation configuration.
10169: #
10170: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10171: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 10172: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 10173: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10174: if (ref($cancreate{'notify'}) eq 'HASH') {
10175: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10176: }
1.160.6.40 raeburn 10177: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10178: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10179: }
1.160.6.34 raeburn 10180: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10181: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10182: }
1.160.6.44 raeburn 10183: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10184: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10185: }
1.160.6.34 raeburn 10186: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.85 raeburn 10187: $save_usercreate{'email_rule'} = \@email_rule;
1.160.6.34 raeburn 10188:
10189: my %userconfig_hash = (
10190: usercreation => \%save_usercreate,
10191: usermodification => \%save_usermodify,
10192: );
10193: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10194: $dom);
10195: #
10196: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10197: #
1.27 raeburn 10198: if ($putresult eq 'ok') {
10199: if (keys(%changes) > 0) {
10200: $resulttext = &mt('Changes made:').'<ul>';
10201: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 10202: my %lt = &selfcreation_types();
1.34 raeburn 10203: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10204: my $chgtext;
1.45 raeburn 10205: if ($type eq 'selfcreate') {
1.50 raeburn 10206: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 10207: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10208: } else {
1.160.6.34 raeburn 10209: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10210: '<ul>';
1.50 raeburn 10211: foreach my $case (@{$cancreate{$type}}) {
10212: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10213: }
10214: $chgtext .= '</ul>';
1.100 raeburn 10215: if (ref($cancreate{$type}) eq 'ARRAY') {
10216: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10217: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10218: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 10219: $chgtext .= '<br />'.
10220: '<span class="LC_warning">'.
10221: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10222: '</span>';
1.100 raeburn 10223: }
10224: }
10225: }
10226: }
1.43 raeburn 10227: }
1.160.6.44 raeburn 10228: } elsif ($type eq 'shibenv') {
10229: if (keys(%{$cancreate{$type}}) == 0) {
10230: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10231: } else {
10232: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10233: '<ul>';
10234: foreach my $field (@shibfields) {
10235: next if ($cancreate{$type}{$field} eq '');
10236: if ($field eq 'inststatus') {
10237: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10238: } else {
10239: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10240: }
10241: }
10242: $chgtext .= '</ul>';
10243: }
1.93 raeburn 10244: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10245: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10246: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10247: if (@{$cancreate{'selfcreate'}} > 0) {
10248: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10249: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10250: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10251: $chgtext .= '<br />'.
10252: '<span class="LC_warning">'.
10253: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10254: '</span>';
10255: }
1.96 raeburn 10256: } elsif (ref($usertypes) eq 'HASH') {
10257: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10258: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10259: } else {
10260: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10261: }
10262: $chgtext .= '<ul>';
10263: foreach my $case (@{$cancreate{$type}}) {
10264: if ($case eq 'default') {
10265: $chgtext .= '<li>'.$othertitle.'</li>';
10266: } else {
10267: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10268: }
10269: }
1.100 raeburn 10270: $chgtext .= '</ul>';
10271: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10272: $chgtext .= '<br /><span class="LC_warning">'.
10273: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10274: '</span>';
1.100 raeburn 10275: }
10276: }
10277: } else {
10278: if (@{$cancreate{$type}} == 0) {
10279: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10280: } else {
10281: $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 10282: }
10283: }
10284: }
1.160.6.40 raeburn 10285: } elsif ($type eq 'selfcreateprocessing') {
10286: my %choices = &Apache::lonlocal::texthash (
10287: automatic => 'Automatic approval',
10288: approval => 'Queued for approval',
10289: );
10290: if (@statuses > 1) {
10291: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10292: '<ul>';
10293: foreach my $type (@statuses) {
10294: if ($type eq 'default') {
10295: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10296: } else {
10297: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10298: }
10299: }
10300: $chgtext .= '</ul>';
10301: } else {
10302: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10303: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10304: }
1.160.6.5 raeburn 10305: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 10306: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 10307: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10308: } else {
10309: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 10310: if ($captchas{$savecaptcha{$type}}) {
10311: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 10312: } else {
10313: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
10314: }
10315: }
10316: } elsif ($type eq 'recaptchakeys') {
10317: my ($privkey,$pubkey);
1.160.6.34 raeburn 10318: if (ref($savecaptcha{$type}) eq 'HASH') {
10319: $pubkey = $savecaptcha{$type}{'public'};
10320: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 10321: }
10322: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10323: if (!$pubkey) {
10324: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10325: } else {
10326: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10327: }
10328: if (!$privkey) {
10329: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10330: } else {
10331: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10332: }
10333: $chgtext .= '</ul>';
1.160.6.69 raeburn 10334: } elsif ($type eq 'recaptchaversion') {
10335: if ($savecaptcha{'captcha'} eq 'recaptcha') {
10336: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
10337: }
1.160.6.34 raeburn 10338: } elsif ($type eq 'emailusername') {
10339: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 10340: if (ref($types) eq 'ARRAY') {
10341: foreach my $type (@{$types}) {
10342: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10343: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 10344: $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 10345: '<ul>';
10346: foreach my $field (@{$infofields}) {
10347: if ($cancreate{'emailusername'}{$type}{$field}) {
10348: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10349: }
10350: }
1.160.6.50 raeburn 10351: $chgtext .= '</ul>';
10352: } else {
10353: $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 10354: }
10355: } else {
1.160.6.50 raeburn 10356: $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 10357: }
10358: }
10359: }
10360: }
10361: } elsif ($type eq 'notify') {
10362: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10363: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10364: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10365: if ($cancreate{'notify'}{'approval'}) {
10366: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10367: }
10368: }
1.43 raeburn 10369: }
1.34 raeburn 10370: }
1.160.6.34 raeburn 10371: if ($chgtext) {
10372: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10373: }
10374: }
10375: }
1.43 raeburn 10376: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10377: my ($emailrules,$emailruleorder) =
10378: &Apache::lonnet::inst_userrules($dom,'email');
10379: my $chgtext = '<ul>';
10380: foreach my $type (@email_rule) {
10381: if (ref($emailrules->{$type}) eq 'HASH') {
10382: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10383: }
10384: }
10385: $chgtext .= '</ul>';
10386: if (@email_rule > 0) {
1.160.6.34 raeburn 10387: $resulttext .= '<li>'.
10388: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10389: $chgtext.
10390: '</li>';
1.43 raeburn 10391: } else {
1.160.6.34 raeburn 10392: $resulttext .= '<li>'.
10393: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10394: '</li>';
1.43 raeburn 10395: }
10396: }
1.160.6.34 raeburn 10397: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10398: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10399: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10400: foreach my $type (@{$changes{'selfcreate'}}) {
10401: my $typename = $type;
10402: if (ref($usertypes) eq 'HASH') {
10403: if ($usertypes->{$type} ne '') {
10404: $typename = $usertypes->{$type};
1.28 raeburn 10405: }
10406: }
1.160.6.34 raeburn 10407: my @modifiable;
10408: $resulttext .= '<li>'.
10409: &mt('Self-creation of account by users with status: [_1]',
10410: '<span class="LC_cusr_emph">'.$typename.'</span>').
10411: ' - '.&mt('modifiable fields (if institutional data blank): ');
10412: foreach my $field (@fields) {
10413: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10414: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
10415: }
10416: }
10417: if (@modifiable > 0) {
10418: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10419: } else {
1.160.6.34 raeburn 10420: $resulttext .= &mt('none');
1.43 raeburn 10421: }
1.160.6.34 raeburn 10422: $resulttext .= '</li>';
1.28 raeburn 10423: }
1.160.6.34 raeburn 10424: $resulttext .= '</ul></li>';
1.28 raeburn 10425: }
1.27 raeburn 10426: $resulttext .= '</ul>';
10427: } else {
1.160.6.34 raeburn 10428: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10429: }
10430: } else {
10431: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10432: &mt('An error occurred: [_1]',$putresult).'</span>';
10433: }
1.43 raeburn 10434: if ($warningmsg ne '') {
10435: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10436: }
1.23 raeburn 10437: return $resulttext;
10438: }
10439:
1.160.6.5 raeburn 10440: sub process_captcha {
10441: my ($container,$changes,$newsettings,$current) = @_;
10442: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10443: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10444: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10445: $newsettings->{'captcha'} = 'original';
10446: }
10447: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
10448: if ($container eq 'cancreate') {
10449: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10450: push(@{$changes->{'cancreate'}},'captcha');
10451: } elsif (!defined($changes->{'cancreate'})) {
10452: $changes->{'cancreate'} = ['captcha'];
10453: }
10454: } else {
10455: $changes->{'captcha'} = 1;
10456: }
10457: }
1.160.6.69 raeburn 10458: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 10459: if ($newsettings->{'captcha'} eq 'recaptcha') {
10460: $newpub = $env{'form.'.$container.'_recaptchapub'};
10461: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 10462: $newpub =~ s/[^\w\-]//g;
10463: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 10464: $newsettings->{'recaptchakeys'} = {
10465: public => $newpub,
10466: private => $newpriv,
10467: };
1.160.6.69 raeburn 10468: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10469: $newversion =~ s/\D//g;
10470: if ($newversion ne '2') {
10471: $newversion = 1;
10472: }
10473: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 10474: }
10475: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10476: $currpub = $current->{'recaptchakeys'}{'public'};
10477: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 10478: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10479: $newsettings->{'recaptchakeys'} = {
10480: public => '',
10481: private => '',
10482: }
10483: }
1.160.6.5 raeburn 10484: }
1.160.6.69 raeburn 10485: if ($current->{'captcha'} eq 'recaptcha') {
10486: $currversion = $current->{'recaptchaversion'};
10487: if ($currversion ne '2') {
10488: $currversion = 1;
10489: }
10490: }
10491: if ($currversion ne $newversion) {
10492: if ($container eq 'cancreate') {
10493: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10494: push(@{$changes->{'cancreate'}},'recaptchaversion');
10495: } elsif (!defined($changes->{'cancreate'})) {
10496: $changes->{'cancreate'} = ['recaptchaversion'];
10497: }
10498: } else {
10499: $changes->{'recaptchaversion'} = 1;
10500: }
10501: }
1.160.6.5 raeburn 10502: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
10503: if ($container eq 'cancreate') {
10504: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10505: push(@{$changes->{'cancreate'}},'recaptchakeys');
10506: } elsif (!defined($changes->{'cancreate'})) {
10507: $changes->{'cancreate'} = ['recaptchakeys'];
10508: }
10509: } else {
10510: $changes->{'recaptchakeys'} = 1;
10511: }
10512: }
10513: return;
10514: }
10515:
1.33 raeburn 10516: sub modify_usermodification {
10517: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 10518: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10519: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10520: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 10521: if ($key eq 'selfcreate') {
10522: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10523: } else {
10524: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10525: }
1.33 raeburn 10526: }
10527: }
1.160.6.34 raeburn 10528: my @contexts = ('author','course');
1.33 raeburn 10529: my %context_title = (
10530: author => 'In author context',
10531: course => 'In course context',
10532: );
10533: my @fields = ('lastname','firstname','middlename','generation',
10534: 'permanentemail','id');
10535: my %roles = (
10536: author => ['ca','aa'],
10537: course => ['st','ep','ta','in','cr'],
10538: );
10539: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10540: foreach my $context (@contexts) {
10541: foreach my $role (@{$roles{$context}}) {
10542: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10543: foreach my $item (@fields) {
10544: if (grep(/^\Q$item\E$/,@modifiable)) {
10545: $modifyhash{$context}{$role}{$item} = 1;
10546: } else {
10547: $modifyhash{$context}{$role}{$item} = 0;
10548: }
10549: }
10550: }
10551: if (ref($curr_usermodification{$context}) eq 'HASH') {
10552: foreach my $role (@{$roles{$context}}) {
10553: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10554: foreach my $field (@fields) {
10555: if ($modifyhash{$context}{$role}{$field} ne
10556: $curr_usermodification{$context}{$role}{$field}) {
10557: push(@{$changes{$context}},$role);
10558: last;
10559: }
10560: }
10561: }
10562: }
10563: } else {
10564: foreach my $context (@contexts) {
10565: foreach my $role (@{$roles{$context}}) {
10566: push(@{$changes{$context}},$role);
10567: }
10568: }
10569: }
10570: }
10571: my %usermodification_hash = (
10572: usermodification => \%modifyhash,
10573: );
10574: my $putresult = &Apache::lonnet::put_dom('configuration',
10575: \%usermodification_hash,$dom);
10576: if ($putresult eq 'ok') {
10577: if (keys(%changes) > 0) {
10578: $resulttext = &mt('Changes made: ').'<ul>';
10579: foreach my $context (@contexts) {
10580: if (ref($changes{$context}) eq 'ARRAY') {
10581: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10582: if (ref($changes{$context}) eq 'ARRAY') {
10583: foreach my $role (@{$changes{$context}}) {
10584: my $rolename;
1.160.6.34 raeburn 10585: if ($role eq 'cr') {
10586: $rolename = &mt('Custom');
1.33 raeburn 10587: } else {
1.160.6.34 raeburn 10588: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10589: }
10590: my @modifiable;
1.160.6.34 raeburn 10591: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10592: foreach my $field (@fields) {
10593: if ($modifyhash{$context}{$role}{$field}) {
10594: push(@modifiable,$fieldtitles{$field});
10595: }
10596: }
10597: if (@modifiable > 0) {
10598: $resulttext .= join(', ',@modifiable);
10599: } else {
10600: $resulttext .= &mt('none');
10601: }
10602: $resulttext .= '</li>';
10603: }
10604: $resulttext .= '</ul></li>';
10605: }
10606: }
10607: }
10608: $resulttext .= '</ul>';
10609: } else {
10610: $resulttext = &mt('No changes made to user modification settings');
10611: }
10612: } else {
10613: $resulttext = '<span class="LC_error">'.
10614: &mt('An error occurred: [_1]',$putresult).'</span>';
10615: }
10616: return $resulttext;
10617: }
10618:
1.43 raeburn 10619: sub modify_defaults {
1.160.6.27 raeburn 10620: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10621: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 10622: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 10623: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
10624: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 10625: my @authtypes = ('internal','krb4','krb5','localauth');
10626: foreach my $item (@items) {
10627: $newvalues{$item} = $env{'form.'.$item};
10628: if ($item eq 'auth_def') {
10629: if ($newvalues{$item} ne '') {
10630: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10631: push(@errors,$item);
10632: }
10633: }
10634: } elsif ($item eq 'lang_def') {
10635: if ($newvalues{$item} ne '') {
10636: if ($newvalues{$item} =~ /^(\w+)/) {
10637: my $langcode = $1;
1.103 raeburn 10638: if ($langcode ne 'x_chef') {
10639: if (code2language($langcode) eq '') {
10640: push(@errors,$item);
10641: }
1.43 raeburn 10642: }
10643: } else {
10644: push(@errors,$item);
10645: }
10646: }
1.54 raeburn 10647: } elsif ($item eq 'timezone_def') {
10648: if ($newvalues{$item} ne '') {
1.62 raeburn 10649: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10650: push(@errors,$item);
10651: }
10652: }
1.68 raeburn 10653: } elsif ($item eq 'datelocale_def') {
10654: if ($newvalues{$item} ne '') {
10655: my @datelocale_ids = DateTime::Locale->ids();
10656: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10657: push(@errors,$item);
10658: }
10659: }
1.141 raeburn 10660: } elsif ($item eq 'portal_def') {
10661: if ($newvalues{$item} ne '') {
10662: 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])\/?$/) {
10663: push(@errors,$item);
10664: }
10665: }
1.160.6.80 raeburn 10666: } elsif ($item eq 'intauth_cost') {
10667: if ($newvalues{$item} ne '') {
10668: if ($newvalues{$item} =~ /\D/) {
10669: push(@errors,$item);
10670: }
10671: }
10672: } elsif ($item eq 'intauth_check') {
10673: if ($newvalues{$item} ne '') {
10674: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
10675: push(@errors,$item);
10676: }
10677: }
10678: } elsif ($item eq 'intauth_switch') {
10679: if ($newvalues{$item} ne '') {
10680: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
10681: push(@errors,$item);
10682: }
10683: }
1.43 raeburn 10684: }
10685: if (grep(/^\Q$item\E$/,@errors)) {
10686: $newvalues{$item} = $domdefaults{$item};
10687: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10688: $changes{$item} = 1;
10689: }
1.72 raeburn 10690: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10691: }
10692: my %defaults_hash = (
1.72 raeburn 10693: defaults => \%newvalues,
10694: );
1.43 raeburn 10695: my $title = &defaults_titles();
1.160.6.40 raeburn 10696:
10697: my $currinststatus;
10698: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10699: $currinststatus = $domconfig{'inststatus'};
10700: } else {
10701: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10702: $currinststatus = {
10703: inststatustypes => $usertypes,
10704: inststatusorder => $types,
10705: inststatusguest => [],
10706: };
10707: }
10708: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10709: my @allpos;
10710: my %guests;
10711: my %alltypes;
10712: my ($currtitles,$currguests,$currorder);
10713: if (ref($currinststatus) eq 'HASH') {
10714: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10715: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10716: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10717: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10718: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10719: }
10720: }
10721: unless (grep(/^\Q$type\E$/,@todelete)) {
10722: my $position = $env{'form.inststatus_pos_'.$type};
10723: $position =~ s/\D+//g;
10724: $allpos[$position] = $type;
10725: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
10726: $alltypes{$type} =~ s/`//g;
10727: if ($env{'form.inststatus_guest_'.$type}) {
10728: $guests{$type} = 1;
10729: }
10730: }
10731: }
10732: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
10733: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
10734: }
10735: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
10736: $currtitles =~ s/,$//;
10737: }
10738: }
10739: if ($env{'form.addinststatus'}) {
10740: my $newtype = $env{'form.addinststatus'};
10741: $newtype =~ s/\W//g;
10742: unless (exists($alltypes{$newtype})) {
10743: if ($env{'form.addinststatus_guest'}) {
10744: $guests{$newtype} = 1;
10745: }
10746: $alltypes{$newtype} = $env{'form.addinststatus_title'};
10747: $alltypes{$newtype} =~ s/`//g;
10748: my $position = $env{'form.addinststatus_pos'};
10749: $position =~ s/\D+//g;
10750: if ($position ne '') {
10751: $allpos[$position] = $newtype;
10752: }
10753: }
10754: }
10755: my (@orderedstatus,@orderedguests);
10756: foreach my $type (@allpos) {
10757: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
10758: push(@orderedstatus,$type);
10759: if ($guests{$type}) {
10760: push(@orderedguests,$type);
10761: }
10762: }
10763: }
10764: foreach my $type (keys(%alltypes)) {
10765: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
10766: delete($alltypes{$type});
10767: }
10768: }
10769: $defaults_hash{'inststatus'} = {
10770: inststatustypes => \%alltypes,
10771: inststatusorder => \@orderedstatus,
10772: inststatusguest => \@orderedguests,
10773: };
10774: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
10775: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
10776: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
10777: }
10778: }
10779: if ($currorder ne join(',',@orderedstatus)) {
10780: $changes{'inststatus'}{'inststatusorder'} = 1;
10781: }
10782: if ($currguests ne join(',',@orderedguests)) {
10783: $changes{'inststatus'}{'inststatusguest'} = 1;
10784: }
10785: my $newtitles;
10786: foreach my $item (@orderedstatus) {
10787: $newtitles .= $alltypes{$item}.',';
10788: }
10789: $newtitles =~ s/,$//;
10790: if ($currtitles ne $newtitles) {
10791: $changes{'inststatus'}{'inststatustypes'} = 1;
10792: }
1.43 raeburn 10793: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
10794: $dom);
10795: if ($putresult eq 'ok') {
10796: if (keys(%changes) > 0) {
10797: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 10798: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 10799: 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";
10800: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 10801: if ($item eq 'inststatus') {
10802: if (ref($changes{'inststatus'}) eq 'HASH') {
10803: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
10804: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
10805: foreach my $type (@orderedstatus) {
10806: $resulttext .= $alltypes{$type}.', ';
10807: }
10808: $resulttext =~ s/, $//;
10809: $resulttext .= '</li>';
10810: }
10811: if ($changes{'inststatus'}{'inststatusguest'}) {
10812: $resulttext .= '<li>';
10813: if (@orderedguests) {
10814: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
10815: foreach my $type (@orderedguests) {
10816: $resulttext .= $alltypes{$type}.', ';
10817: }
10818: $resulttext =~ s/, $//;
10819: } else {
10820: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
10821: }
10822: $resulttext .= '</li>';
10823: }
10824: }
10825: } else {
10826: my $value = $env{'form.'.$item};
10827: if ($value eq '') {
10828: $value = &mt('none');
10829: } elsif ($item eq 'auth_def') {
10830: my %authnames = &authtype_names();
10831: my %shortauth = (
10832: internal => 'int',
10833: krb4 => 'krb4',
10834: krb5 => 'krb5',
10835: localauth => 'loc',
10836: );
10837: $value = $authnames{$shortauth{$value}};
1.160.6.80 raeburn 10838: } elsif ($item eq 'intauth_switch') {
10839: my %optiondesc = &Apache::lonlocal::texthash (
10840: 0 => 'No',
10841: 1 => 'Yes',
10842: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
10843: );
10844: if ($value =~ /^(0|1|2)$/) {
10845: $value = $optiondesc{$value};
10846: } else {
10847: $value = &mt('none -- defaults to No');
10848: }
10849: } elsif ($item eq 'intauth_check') {
10850: my %optiondesc = &Apache::lonlocal::texthash (
10851: 0 => 'No',
10852: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
10853: 2 => 'Yes, disallow login if stored cost is less than domain default',
10854: );
10855: if ($value =~ /^(0|1|2)$/) {
10856: $value = $optiondesc{$value};
10857: } else {
10858: $value = &mt('none -- defaults to No');
10859: }
1.160.6.40 raeburn 10860: }
10861: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
10862: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 10863: }
10864: }
10865: $resulttext .= '</ul>';
10866: $mailmsgtext .= "\n";
10867: my $cachetime = 24*60*60;
1.72 raeburn 10868: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10869: if (ref($lastactref) eq 'HASH') {
10870: $lastactref->{'domdefaults'} = 1;
10871: }
1.68 raeburn 10872: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 10873: my $notify = 1;
10874: if (ref($domconfig{'contacts'}) eq 'HASH') {
10875: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
10876: $notify = 0;
10877: }
10878: }
10879: if ($notify) {
10880: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
10881: "LON-CAPA Domain Settings Change - $dom",
10882: $mailmsgtext);
10883: }
1.54 raeburn 10884: }
1.43 raeburn 10885: } else {
1.54 raeburn 10886: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 10887: }
10888: } else {
10889: $resulttext = '<span class="LC_error">'.
10890: &mt('An error occurred: [_1]',$putresult).'</span>';
10891: }
10892: if (@errors > 0) {
10893: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
10894: foreach my $item (@errors) {
10895: $resulttext .= ' "'.$title->{$item}.'",';
10896: }
10897: $resulttext =~ s/,$//;
10898: }
10899: return $resulttext;
10900: }
10901:
1.46 raeburn 10902: sub modify_scantron {
1.160.6.24 raeburn 10903: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 10904: my ($resulttext,%confhash,%changes,$errors);
10905: my $custom = 'custom.tab';
10906: my $default = 'default.tab';
10907: my $servadm = $r->dir_config('lonAdmEMail');
10908: my ($configuserok,$author_ok,$switchserver) =
10909: &config_check($dom,$confname,$servadm);
10910: if ($env{'form.scantronformat.filename'} ne '') {
10911: my $error;
10912: if ($configuserok eq 'ok') {
10913: if ($switchserver) {
1.130 raeburn 10914: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 10915: } else {
10916: if ($author_ok eq 'ok') {
10917: my ($result,$scantronurl) =
10918: &publishlogo($r,'upload','scantronformat',$dom,
10919: $confname,'scantron','','',$custom);
10920: if ($result eq 'ok') {
10921: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 10922: $changes{'scantronformat'} = 1;
1.46 raeburn 10923: } else {
10924: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
10925: }
10926: } else {
10927: $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);
10928: }
10929: }
10930: } else {
10931: $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);
10932: }
10933: if ($error) {
10934: &Apache::lonnet::logthis($error);
10935: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10936: }
10937: }
1.48 raeburn 10938: if (ref($domconfig{'scantron'}) eq 'HASH') {
10939: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
10940: if ($env{'form.scantronformat_del'}) {
10941: $confhash{'scantron'}{'scantronformat'} = '';
10942: $changes{'scantronformat'} = 1;
1.46 raeburn 10943: }
10944: }
10945: }
10946: if (keys(%confhash) > 0) {
10947: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10948: $dom);
10949: if ($putresult eq 'ok') {
10950: if (keys(%changes) > 0) {
1.48 raeburn 10951: if (ref($confhash{'scantron'}) eq 'HASH') {
10952: $resulttext = &mt('Changes made:').'<ul>';
10953: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 10954: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 10955: } else {
1.130 raeburn 10956: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 10957: }
1.48 raeburn 10958: $resulttext .= '</ul>';
10959: } else {
1.130 raeburn 10960: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 10961: }
10962: $resulttext .= '</ul>';
10963: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10964: if (ref($lastactref) eq 'HASH') {
10965: $lastactref->{'domainconfig'} = 1;
10966: }
1.46 raeburn 10967: } else {
1.130 raeburn 10968: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10969: }
10970: } else {
10971: $resulttext = '<span class="LC_error">'.
10972: &mt('An error occurred: [_1]',$putresult).'</span>';
10973: }
10974: } else {
1.130 raeburn 10975: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10976: }
10977: if ($errors) {
10978: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10979: $errors.'</ul>';
10980: }
10981: return $resulttext;
10982: }
10983:
1.48 raeburn 10984: sub modify_coursecategories {
1.160.6.43 raeburn 10985: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 10986: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10987: $cathash);
1.48 raeburn 10988: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 10989: my @catitems = ('unauth','auth');
10990: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 10991: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 10992: $cathash = $domconfig{'coursecategories'}{'cats'};
10993: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10994: $changes{'togglecats'} = 1;
10995: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10996: }
10997: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10998: $changes{'categorize'} = 1;
10999: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
11000: }
1.120 raeburn 11001: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
11002: $changes{'togglecatscomm'} = 1;
11003: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
11004: }
11005: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
11006: $changes{'categorizecomm'} = 1;
11007: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
11008: }
1.160.6.42 raeburn 11009: foreach my $item (@catitems) {
11010: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11011: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
11012: $changes{$item} = 1;
11013: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11014: }
11015: }
11016: }
1.57 raeburn 11017: } else {
11018: $changes{'togglecats'} = 1;
11019: $changes{'categorize'} = 1;
1.124 raeburn 11020: $changes{'togglecatscomm'} = 1;
11021: $changes{'categorizecomm'} = 1;
1.87 raeburn 11022: $domconfig{'coursecategories'} = {
11023: togglecats => $env{'form.togglecats'},
11024: categorize => $env{'form.categorize'},
1.124 raeburn 11025: togglecatscomm => $env{'form.togglecatscomm'},
11026: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 11027: };
1.160.6.42 raeburn 11028: foreach my $item (@catitems) {
11029: if ($env{'form.coursecat_'.$item} ne 'std') {
11030: $changes{$item} = 1;
11031: }
11032: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
11033: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
11034: }
11035: }
1.57 raeburn 11036: }
11037: if (ref($cathash) eq 'HASH') {
11038: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 11039: push (@deletecategory,'instcode::0');
11040: }
1.120 raeburn 11041: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11042: push(@deletecategory,'communities::0');
11043: }
1.48 raeburn 11044: }
1.57 raeburn 11045: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11046: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11047: if (@deletecategory > 0) {
11048: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 11049: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 11050: foreach my $item (@deletecategory) {
1.57 raeburn 11051: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11052: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11053: $deletions{$item} = 1;
1.57 raeburn 11054: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11055: }
11056: }
11057: }
1.57 raeburn 11058: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11059: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11060: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11061: $reorderings{$item} = 1;
1.57 raeburn 11062: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11063: }
11064: if ($env{'form.addcategory_name_'.$item} ne '') {
11065: my $newcat = $env{'form.addcategory_name_'.$item};
11066: my $newdepth = $depth+1;
11067: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11068: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11069: $adds{$newitem} = 1;
11070: }
11071: if ($env{'form.subcat_'.$item} ne '') {
11072: my $newcat = $env{'form.subcat_'.$item};
11073: my $newdepth = $depth+1;
11074: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11075: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11076: $adds{$newitem} = 1;
11077: }
11078: }
11079: }
11080: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11081: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11082: my $newitem = 'instcode::0';
1.57 raeburn 11083: if ($cathash->{$newitem} eq '') {
11084: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11085: $adds{$newitem} = 1;
11086: }
11087: } else {
11088: my $newitem = 'instcode::0';
1.57 raeburn 11089: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11090: $adds{$newitem} = 1;
11091: }
11092: }
1.120 raeburn 11093: if ($env{'form.communities'} eq '1') {
11094: if (ref($cathash) eq 'HASH') {
11095: my $newitem = 'communities::0';
11096: if ($cathash->{$newitem} eq '') {
11097: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11098: $adds{$newitem} = 1;
11099: }
11100: } else {
11101: my $newitem = 'communities::0';
11102: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11103: $adds{$newitem} = 1;
11104: }
11105: }
1.48 raeburn 11106: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11107: if (($env{'form.addcategory_name'} ne 'instcode') &&
11108: ($env{'form.addcategory_name'} ne 'communities')) {
11109: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11110: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11111: $adds{$newitem} = 1;
11112: }
1.48 raeburn 11113: }
1.57 raeburn 11114: my $putresult;
1.48 raeburn 11115: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11116: if (keys(%deletions) > 0) {
11117: foreach my $key (keys(%deletions)) {
11118: if ($predelallitems{$key} ne '') {
11119: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11120: }
11121: }
11122: }
11123: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11124: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11125: if (ref($chkcats[0]) eq 'ARRAY') {
11126: my $depth = 0;
11127: my $chg = 0;
11128: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11129: my $name = $chkcats[0][$i];
11130: my $item;
11131: if ($name eq '') {
11132: $chg ++;
11133: } else {
11134: $item = &escape($name).'::0';
11135: if ($chg) {
1.57 raeburn 11136: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11137: }
11138: $depth ++;
1.57 raeburn 11139: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11140: $depth --;
11141: }
11142: }
11143: }
1.57 raeburn 11144: }
11145: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11146: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11147: if ($putresult eq 'ok') {
1.57 raeburn 11148: my %title = (
1.120 raeburn 11149: togglecats => 'Show/Hide a course in catalog',
11150: categorize => 'Assign a category to a course',
11151: togglecatscomm => 'Show/Hide a community in catalog',
11152: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11153: );
11154: my %level = (
1.120 raeburn 11155: dom => 'set in Domain ("Modify Course/Community")',
11156: crs => 'set in Course ("Course Configuration")',
11157: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 11158: none => 'No catalog',
11159: std => 'Standard catalog',
11160: domonly => 'Domain-only catalog',
11161: codesrch => 'Code search form',
1.57 raeburn 11162: );
1.48 raeburn 11163: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11164: if ($changes{'togglecats'}) {
11165: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11166: }
11167: if ($changes{'categorize'}) {
11168: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11169: }
1.120 raeburn 11170: if ($changes{'togglecatscomm'}) {
11171: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11172: }
11173: if ($changes{'categorizecomm'}) {
11174: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11175: }
1.160.6.42 raeburn 11176: if ($changes{'unauth'}) {
11177: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11178: }
11179: if ($changes{'auth'}) {
11180: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11181: }
1.57 raeburn 11182: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11183: my $cathash;
11184: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11185: $cathash = $domconfig{'coursecategories'}{'cats'};
11186: } else {
11187: $cathash = {};
11188: }
11189: my (@cats,@trails,%allitems);
11190: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11191: if (keys(%deletions) > 0) {
11192: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11193: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11194: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11195: }
11196: $resulttext .= '</ul></li>';
11197: }
11198: if (keys(%reorderings) > 0) {
11199: my %sort_by_trail;
11200: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11201: foreach my $key (keys(%reorderings)) {
11202: if ($allitems{$key} ne '') {
11203: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11204: }
1.48 raeburn 11205: }
1.57 raeburn 11206: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11207: $resulttext .= '<li>'.$trails[$trail].'</li>';
11208: }
11209: $resulttext .= '</ul></li>';
1.48 raeburn 11210: }
1.57 raeburn 11211: if (keys(%adds) > 0) {
11212: my %sort_by_trail;
11213: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11214: foreach my $key (keys(%adds)) {
11215: if ($allitems{$key} ne '') {
11216: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11217: }
11218: }
11219: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11220: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11221: }
1.57 raeburn 11222: $resulttext .= '</ul></li>';
1.48 raeburn 11223: }
11224: }
11225: $resulttext .= '</ul>';
1.160.6.43 raeburn 11226: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 11227: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11228: if ($changes{'auth'}) {
11229: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11230: }
11231: if ($changes{'unauth'}) {
11232: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11233: }
11234: my $cachetime = 24*60*60;
11235: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 11236: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 11237: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 11238: }
11239: }
1.48 raeburn 11240: } else {
11241: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11242: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11243: }
11244: } else {
1.120 raeburn 11245: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11246: }
11247: return $resulttext;
11248: }
11249:
1.69 raeburn 11250: sub modify_serverstatuses {
11251: my ($dom,%domconfig) = @_;
11252: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11253: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11254: %currserverstatus = %{$domconfig{'serverstatuses'}};
11255: }
11256: my @pages = &serverstatus_pages();
11257: foreach my $type (@pages) {
11258: $newserverstatus{$type}{'namedusers'} = '';
11259: $newserverstatus{$type}{'machines'} = '';
11260: if (defined($env{'form.'.$type.'_namedusers'})) {
11261: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11262: my @okusers;
11263: foreach my $user (@users) {
11264: my ($uname,$udom) = split(/:/,$user);
11265: if (($udom =~ /^$match_domain$/) &&
11266: (&Apache::lonnet::domain($udom)) &&
11267: ($uname =~ /^$match_username$/)) {
11268: if (!grep(/^\Q$user\E/,@okusers)) {
11269: push(@okusers,$user);
11270: }
11271: }
11272: }
11273: if (@okusers > 0) {
11274: @okusers = sort(@okusers);
11275: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11276: }
11277: }
11278: if (defined($env{'form.'.$type.'_machines'})) {
11279: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11280: my @okmachines;
11281: foreach my $ip (@machines) {
11282: my @parts = split(/\./,$ip);
11283: next if (@parts < 4);
11284: my $badip = 0;
11285: for (my $i=0; $i<4; $i++) {
11286: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11287: $badip = 1;
11288: last;
11289: }
11290: }
11291: if (!$badip) {
11292: push(@okmachines,$ip);
11293: }
11294: }
11295: @okmachines = sort(@okmachines);
11296: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11297: }
11298: }
11299: my %serverstatushash = (
11300: serverstatuses => \%newserverstatus,
11301: );
11302: foreach my $type (@pages) {
1.83 raeburn 11303: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11304: my (@current,@new);
1.83 raeburn 11305: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11306: if ($currserverstatus{$type}{$setting} ne '') {
11307: @current = split(/,/,$currserverstatus{$type}{$setting});
11308: }
11309: }
11310: if ($newserverstatus{$type}{$setting} ne '') {
11311: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11312: }
11313: if (@current > 0) {
11314: if (@new > 0) {
11315: foreach my $item (@current) {
11316: if (!grep(/^\Q$item\E$/,@new)) {
11317: $changes{$type}{$setting} = 1;
1.82 raeburn 11318: last;
11319: }
11320: }
1.84 raeburn 11321: foreach my $item (@new) {
11322: if (!grep(/^\Q$item\E$/,@current)) {
11323: $changes{$type}{$setting} = 1;
11324: last;
1.82 raeburn 11325: }
11326: }
11327: } else {
1.83 raeburn 11328: $changes{$type}{$setting} = 1;
1.69 raeburn 11329: }
1.83 raeburn 11330: } elsif (@new > 0) {
11331: $changes{$type}{$setting} = 1;
1.69 raeburn 11332: }
11333: }
11334: }
11335: if (keys(%changes) > 0) {
1.81 raeburn 11336: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11337: my $putresult = &Apache::lonnet::put_dom('configuration',
11338: \%serverstatushash,$dom);
11339: if ($putresult eq 'ok') {
11340: $resulttext .= &mt('Changes made:').'<ul>';
11341: foreach my $type (@pages) {
1.84 raeburn 11342: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11343: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11344: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11345: if ($newserverstatus{$type}{'namedusers'} eq '') {
11346: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11347: } else {
11348: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11349: }
1.84 raeburn 11350: }
11351: if ($changes{$type}{'machines'}) {
1.69 raeburn 11352: if ($newserverstatus{$type}{'machines'} eq '') {
11353: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11354: } else {
11355: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11356: }
11357:
11358: }
11359: $resulttext .= '</ul></li>';
11360: }
11361: }
11362: $resulttext .= '</ul>';
11363: } else {
11364: $resulttext = '<span class="LC_error">'.
11365: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11366:
11367: }
11368: } else {
11369: $resulttext = &mt('No changes made to access to server status pages');
11370: }
11371: return $resulttext;
11372: }
11373:
1.118 jms 11374: sub modify_helpsettings {
1.160.6.77 raeburn 11375: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 11376: my ($resulttext,$errors,%changes,%helphash);
11377: my %defaultchecked = ('submitbugs' => 'on');
11378: my @offon = ('off','on');
1.118 jms 11379: my @toggles = ('submitbugs');
1.160.6.77 raeburn 11380: my %current = ('submitbugs' => '',
11381: 'adhoc' => {},
11382: );
1.118 jms 11383: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 11384: %current = %{$domconfig{'helpsettings'}};
11385: }
1.160.6.77 raeburn 11386: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 11387: foreach my $item (@toggles) {
11388: if ($defaultchecked{$item} eq 'on') {
11389: if ($current{$item} eq '') {
11390: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 11391: $changes{$item} = 1;
11392: }
1.160.6.73 raeburn 11393: } elsif ($current{$item} ne $env{'form.'.$item}) {
11394: $changes{$item} = 1;
11395: }
11396: } elsif ($defaultchecked{$item} eq 'off') {
11397: if ($current{$item} eq '') {
11398: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 11399: $changes{$item} = 1;
11400: }
1.160.6.73 raeburn 11401: } elsif ($current{$item} ne $env{'form.'.$item}) {
11402: $changes{$item} = 1;
11403: }
11404: }
11405: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
11406: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11407: }
11408: }
1.160.6.77 raeburn 11409: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 11410: my $confname = $dom.'-domainconfig';
11411: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 11412: my (@allpos,%newsettings,%changedprivs,$newrole);
11413: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 11414: my @accesstypes = ('all','dh','da','none','status','inc','exc');
11415: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 11416: my %lt = &Apache::lonlocal::texthash(
11417: s => 'system',
11418: d => 'domain',
11419: order => 'Display order',
11420: access => 'Role usage',
1.160.6.79 raeburn 11421: all => 'All with domain helpdesk or helpdesk assistant role',
11422: dh => 'All with domain helpdesk role',
11423: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 11424: none => 'None',
11425: status => 'Determined based on institutional status',
11426: inc => 'Include all, but exclude specific personnel',
11427: exc => 'Exclude all, but include specific personnel',
11428: );
11429: for (my $num=0; $num<=$maxnum; $num++) {
11430: my ($prefix,$identifier,$rolename,%curr);
11431: if ($num == $maxnum) {
11432: next unless ($env{'form.newcusthelp'} == $maxnum);
11433: $identifier = 'custhelp'.$num;
11434: $prefix = 'helproles_'.$num;
11435: $rolename = $env{'form.custhelpname'.$num};
11436: $rolename=~s/[^A-Za-z0-9]//gs;
11437: next if ($rolename eq '');
11438: next if (exists($existing{'rolesdef_'.$rolename}));
11439: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11440: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11441: $newprivs{'c'},$confname,$dom);
11442: if ($result ne 'ok') {
11443: $errors .= '<li><span class="LC_error">'.
11444: &mt('An error occurred storing the new custom role: [_1]',
11445: $result).'</span></li>';
11446: next;
11447: } else {
11448: $changedprivs{$rolename} = \%newprivs;
11449: $newrole = $rolename;
11450: }
11451: } else {
11452: $prefix = 'helproles_'.$num;
11453: $rolename = $env{'form.'.$prefix};
11454: next if ($rolename eq '');
11455: next unless (exists($existing{'rolesdef_'.$rolename}));
11456: $identifier = 'custhelp'.$num;
11457: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11458: my %currprivs;
11459: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
11460: split(/\_/,$existing{'rolesdef_'.$rolename});
11461: foreach my $level ('c','d','s') {
11462: if ($newprivs{$level} ne $currprivs{$level}) {
11463: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11464: $newprivs{'c'},$confname,$dom);
11465: if ($result ne 'ok') {
11466: $errors .= '<li><span class="LC_error">'.
11467: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
11468: $rolename,$result).'</span></li>';
11469: } else {
11470: $changedprivs{$rolename} = \%newprivs;
11471: }
11472: last;
11473: }
11474: }
11475: if (ref($current{'adhoc'}) eq 'HASH') {
11476: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11477: %curr = %{$current{'adhoc'}{$rolename}};
11478: }
11479: }
11480: }
11481: my $newpos = $env{'form.'.$prefix.'_pos'};
11482: $newpos =~ s/\D+//g;
11483: $allpos[$newpos] = $rolename;
11484: my $newdesc = $env{'form.'.$prefix.'_desc'};
11485: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
11486: if ($curr{'desc'}) {
11487: if ($curr{'desc'} ne $newdesc) {
11488: $changes{'customrole'}{$rolename}{'desc'} = 1;
11489: $newsettings{$rolename}{'desc'} = $newdesc;
11490: }
11491: } elsif ($newdesc ne '') {
11492: $changes{'customrole'}{$rolename}{'desc'} = 1;
11493: $newsettings{$rolename}{'desc'} = $newdesc;
11494: }
11495: my $access = $env{'form.'.$prefix.'_access'};
11496: if (grep(/^\Q$access\E$/,@accesstypes)) {
11497: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
11498: if ($access eq 'status') {
11499: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
11500: if (scalar(@statuses) == 0) {
11501: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
11502: } else {
11503: my (@shownstatus,$numtypes);
11504: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11505: if (ref($types) eq 'ARRAY') {
11506: $numtypes = scalar(@{$types});
11507: foreach my $type (sort(@statuses)) {
11508: if ($type eq 'default') {
11509: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11510: } elsif (grep(/^\Q$type\E$/,@{$types})) {
11511: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11512: push(@shownstatus,$usertypes->{$type});
11513: }
1.160.6.73 raeburn 11514: }
11515: }
1.160.6.77 raeburn 11516: if (grep(/^default$/,@statuses)) {
11517: push(@shownstatus,$othertitle);
11518: }
11519: if (scalar(@shownstatus) == 1+$numtypes) {
11520: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
11521: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
11522: } else {
11523: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
11524: if (ref($curr{'status'}) eq 'ARRAY') {
11525: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11526: if (@diffs) {
11527: $changes{'customrole'}{$rolename}{$access} = 1;
11528: }
11529: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11530: $changes{'customrole'}{$rolename}{$access} = 1;
11531: }
11532: }
11533: }
11534: } elsif (($access eq 'inc') || ($access eq 'exc')) {
11535: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
11536: my @newspecstaff;
11537: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11538: foreach my $person (sort(@personnel)) {
11539: if ($domhelpdesk{$person}) {
11540: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
11541: }
11542: }
11543: if (ref($curr{$access}) eq 'ARRAY') {
11544: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11545: if (@diffs) {
11546: $changes{'customrole'}{$rolename}{$access} = 1;
11547: }
11548: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11549: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 11550: }
1.160.6.77 raeburn 11551: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11552: my ($uname,$udom) = split(/:/,$person);
11553: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
11554: }
11555: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 11556: }
1.160.6.77 raeburn 11557: } else {
11558: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
11559: }
11560: unless ($curr{'access'} eq $access) {
11561: $changes{'customrole'}{$rolename}{'access'} = 1;
11562: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 11563: }
11564: }
1.160.6.77 raeburn 11565: if (@allpos > 0) {
11566: my $idx = 0;
11567: foreach my $rolename (@allpos) {
11568: if ($rolename ne '') {
11569: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
11570: if (ref($current{'adhoc'}) eq 'HASH') {
11571: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11572: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
11573: $changes{'customrole'}{$rolename}{'order'} = 1;
11574: $newsettings{$rolename}{'order'} = $idx+1;
11575: }
11576: }
1.160.6.73 raeburn 11577: }
1.160.6.77 raeburn 11578: $idx ++;
1.122 jms 11579: }
11580: }
1.118 jms 11581: }
1.123 jms 11582: my $putresult;
11583: if (keys(%changes) > 0) {
1.160.6.5 raeburn 11584: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
11585: if ($putresult eq 'ok') {
1.160.6.77 raeburn 11586: if (ref($helphash{'helpsettings'}) eq 'HASH') {
11587: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
11588: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
11589: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
11590: }
11591: }
11592: my $cachetime = 24*60*60;
11593: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11594: if (ref($lastactref) eq 'HASH') {
11595: $lastactref->{'domdefaults'} = 1;
11596: }
11597: } else {
11598: $errors .= '<li><span class="LC_error">'.
11599: &mt('An error occurred storing the settings: [_1]',
11600: $putresult).'</span></li>';
11601: }
11602: }
11603: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
11604: $resulttext = &mt('Changes made:').'<ul>';
11605: my (%shownprivs,@levelorder);
11606: @levelorder = ('c','d','s');
11607: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 11608: foreach my $item (sort(keys(%changes))) {
11609: if ($item eq 'submitbugs') {
11610: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11611: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11612: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 11613: } elsif ($item eq 'customrole') {
11614: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 11615: my @keyorder = ('order','desc','access','status','exc','inc');
11616: my %keytext = &Apache::lonlocal::texthash(
11617: order => 'Order',
11618: desc => 'Role description',
11619: access => 'Role usage',
1.160.6.83 raeburn 11620: status => 'Allowed institutional types',
1.160.6.77 raeburn 11621: exc => 'Allowed personnel',
11622: inc => 'Disallowed personnel',
11623: );
1.160.6.73 raeburn 11624: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 11625: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
11626: if ($role eq $newrole) {
11627: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
11628: $role).'<ul>';
11629: } else {
11630: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11631: $role).'<ul>';
11632: }
11633: foreach my $key (@keyorder) {
11634: if ($changes{'customrole'}{$role}{$key}) {
11635: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
11636: $keytext{$key},$newsettings{$role}{$key}).
11637: '</li>';
11638: }
11639: }
11640: if (ref($changedprivs{$role}) eq 'HASH') {
11641: $shownprivs{$role} = 1;
11642: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
11643: foreach my $level (@levelorder) {
11644: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11645: next if ($item eq '');
11646: my ($priv) = split(/\&/,$item,2);
11647: if (&Apache::lonnet::plaintext($priv)) {
11648: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11649: unless ($level eq 'c') {
11650: $resulttext .= ' ('.$lt{$level}.')';
11651: }
11652: $resulttext .= '</li>';
11653: }
11654: }
11655: }
11656: $resulttext .= '</ul>';
11657: }
11658: $resulttext .= '</ul></li>';
11659: }
1.160.6.73 raeburn 11660: }
11661: }
1.160.6.5 raeburn 11662: }
11663: }
11664: }
1.160.6.77 raeburn 11665: if (keys(%changedprivs)) {
11666: foreach my $role (sort(keys(%changedprivs))) {
11667: unless ($shownprivs{$role}) {
11668: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11669: $role).'<ul>'.
11670: '<li>'.&mt('Privileges set to :').'<ul>';
11671: foreach my $level (@levelorder) {
11672: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11673: next if ($item eq '');
11674: my ($priv) = split(/\&/,$item,2);
11675: if (&Apache::lonnet::plaintext($priv)) {
11676: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11677: unless ($level eq 'c') {
11678: $resulttext .= ' ('.$lt{$level}.')';
11679: }
11680: $resulttext .= '</li>';
11681: }
11682: }
11683: }
11684: $resulttext .= '</ul></li></ul></li>';
11685: }
11686: }
11687: }
11688: $resulttext .= '</ul>';
11689: } else {
11690: $resulttext = &mt('No changes made to help settings');
1.118 jms 11691: }
11692: if ($errors) {
1.160.6.5 raeburn 11693: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 11694: $errors.'</ul>';
1.118 jms 11695: }
11696: return $resulttext;
11697: }
11698:
1.121 raeburn 11699: sub modify_coursedefaults {
1.160.6.27 raeburn 11700: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11701: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 11702: my %defaultchecked = (
11703: 'uselcmath' => 'on',
11704: 'usejsme' => 'on'
11705: );
11706: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 11707: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 11708: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
11709: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 11710: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 11711: my %staticdefaults = (
11712: anonsurvey_threshold => 10,
11713: uploadquota => 500,
1.160.6.57 raeburn 11714: postsubmit => 60,
1.160.6.70 raeburn 11715: mysqltables => 172800,
1.160.6.21 raeburn 11716: );
1.160.6.90 raeburn 11717: my %texoptions = (
11718: MathJax => 'MathJax',
11719: mimetex => &mt('Convert to Images'),
11720: tth => &mt('TeX to HTML'),
11721: );
1.121 raeburn 11722: $defaultshash{'coursedefaults'} = {};
11723:
11724: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11725: if ($domconfig{'coursedefaults'} eq '') {
11726: $domconfig{'coursedefaults'} = {};
11727: }
11728: }
11729:
11730: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11731: foreach my $item (@toggles) {
11732: if ($defaultchecked{$item} eq 'on') {
11733: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11734: ($env{'form.'.$item} eq '0')) {
11735: $changes{$item} = 1;
1.160.6.16 raeburn 11736: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11737: $changes{$item} = 1;
11738: }
11739: } elsif ($defaultchecked{$item} eq 'off') {
11740: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11741: ($env{'form.'.$item} eq '1')) {
11742: $changes{$item} = 1;
11743: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11744: $changes{$item} = 1;
11745: }
11746: }
11747: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11748: }
1.160.6.21 raeburn 11749: foreach my $item (@numbers) {
11750: my ($currdef,$newdef);
1.160.6.26 raeburn 11751: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 11752: if ($item eq 'anonsurvey_threshold') {
11753: $currdef = $domconfig{'coursedefaults'}{$item};
11754: $newdef =~ s/\D//g;
11755: if ($newdef eq '' || $newdef < 1) {
11756: $newdef = 1;
11757: }
11758: $defaultshash{'coursedefaults'}{$item} = $newdef;
11759: } else {
1.160.6.70 raeburn 11760: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
11761: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
11762: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 11763: }
11764: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 11765: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 11766: }
11767: if ($currdef ne $newdef) {
11768: if ($item eq 'anonsurvey_threshold') {
11769: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11770: $changes{$item} = 1;
11771: }
1.160.6.70 raeburn 11772: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
11773: my $setting = $1;
11774: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
11775: $changes{$setting} = 1;
1.160.6.21 raeburn 11776: }
11777: }
1.139 raeburn 11778: }
11779: }
1.160.6.90 raeburn 11780: my $texengine;
11781: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
11782: $texengine = $env{'form.texengine'};
11783: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
11784: if ($currdef eq '') {
11785: unless ($texengine eq $Apache::lonnet::deftex) {
11786: $changes{'texengine'} = 1;
11787: }
11788: } elsif ($currdef ne $texengine) {
11789: $changes{'texengine'} = 1;
11790: }
11791: }
11792: if ($texengine ne '') {
11793: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
11794: }
1.160.6.64 raeburn 11795: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11796: my @currclonecode;
11797: if (ref($currclone) eq 'HASH') {
11798: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11799: @currclonecode = @{$currclone->{'instcode'}};
11800: }
11801: }
11802: my $newclone;
11803: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11804: $newclone = $env{'form.canclone'};
11805: }
11806: if ($newclone eq 'instcode') {
11807: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11808: my (%codedefaults,@code_order,@clonecode);
11809: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11810: \@code_order);
11811: foreach my $item (@code_order) {
11812: if (grep(/^\Q$item\E$/,@newcodes)) {
11813: push(@clonecode,$item);
11814: }
11815: }
11816: if (@clonecode) {
11817: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11818: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11819: if (@diffs) {
11820: $changes{'canclone'} = 1;
11821: }
11822: } else {
11823: $newclone eq '';
11824: }
11825: } elsif ($newclone ne '') {
11826: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11827: }
11828: if ($newclone ne $currclone) {
11829: $changes{'canclone'} = 1;
11830: }
1.160.6.57 raeburn 11831: my %credits;
11832: foreach my $type (@types) {
11833: unless ($type eq 'community') {
11834: $credits{$type} = $env{'form.'.$type.'_credits'};
11835: $credits{$type} =~ s/[^\d.]+//g;
11836: }
11837: }
11838: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11839: ($env{'form.coursecredits'} eq '1')) {
11840: $changes{'coursecredits'} = 1;
11841: foreach my $type (keys(%credits)) {
11842: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11843: }
11844: } else {
11845: if ($env{'form.coursecredits'} eq '1') {
11846: foreach my $type (@types) {
11847: unless ($type eq 'community') {
11848: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11849: $changes{'coursecredits'} = 1;
11850: }
11851: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11852: }
11853: }
11854: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11855: foreach my $type (@types) {
11856: unless ($type eq 'community') {
11857: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11858: $changes{'coursecredits'} = 1;
11859: last;
11860: }
11861: }
11862: }
11863: }
11864: }
11865: if ($env{'form.postsubmit'} eq '1') {
11866: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11867: my %currtimeout;
11868: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11869: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11870: $changes{'postsubmit'} = 1;
11871: }
11872: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11873: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11874: }
11875: } else {
11876: $changes{'postsubmit'} = 1;
11877: }
11878: foreach my $type (@types) {
11879: my $timeout = $env{'form.'.$type.'_timeout'};
11880: $timeout =~ s/\D//g;
11881: if ($timeout == $staticdefaults{'postsubmit'}) {
11882: $timeout = '';
11883: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11884: $timeout = '0';
11885: }
11886: unless ($timeout eq '') {
11887: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11888: }
11889: if (exists($currtimeout{$type})) {
11890: if ($timeout ne $currtimeout{$type}) {
11891: $changes{'postsubmit'} = 1;
11892: }
11893: } elsif ($timeout ne '') {
11894: $changes{'postsubmit'} = 1;
11895: }
11896: }
11897: } else {
11898: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11899: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11900: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11901: $changes{'postsubmit'} = 1;
11902: }
11903: } else {
11904: $changes{'postsubmit'} = 1;
11905: }
1.160.6.16 raeburn 11906: }
1.121 raeburn 11907: }
11908: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11909: $dom);
11910: if ($putresult eq 'ok') {
11911: if (keys(%changes) > 0) {
1.160.6.27 raeburn 11912: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 11913: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 11914: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90 raeburn 11915: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
11916: foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57 raeburn 11917: if ($changes{$item}) {
11918: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11919: }
1.160.6.16 raeburn 11920: }
11921: if ($changes{'coursecredits'}) {
11922: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 11923: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11924: $domdefaults{$type.'credits'} =
11925: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11926: }
11927: }
11928: }
11929: if ($changes{'postsubmit'}) {
11930: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11931: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11932: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11933: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11934: $domdefaults{$type.'postsubtimeout'} =
11935: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11936: }
11937: }
1.160.6.16 raeburn 11938: }
11939: }
1.160.6.21 raeburn 11940: if ($changes{'uploadquota'}) {
11941: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11942: foreach my $type (@types) {
11943: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11944: }
11945: }
11946: }
1.160.6.64 raeburn 11947: if ($changes{'canclone'}) {
11948: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11949: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11950: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11951: if (@clonecodes) {
11952: $domdefaults{'canclone'} = join('+',@clonecodes);
11953: }
11954: }
11955: } else {
11956: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11957: }
11958: }
1.121 raeburn 11959: my $cachetime = 24*60*60;
11960: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11961: if (ref($lastactref) eq 'HASH') {
11962: $lastactref->{'domdefaults'} = 1;
11963: }
1.121 raeburn 11964: }
11965: $resulttext = &mt('Changes made:').'<ul>';
11966: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 11967: if ($item eq 'uselcmath') {
1.121 raeburn 11968: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 11969: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 11970: } else {
1.160.6.57 raeburn 11971: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11972: }
11973: } elsif ($item eq 'usejsme') {
11974: if ($env{'form.'.$item} eq '1') {
11975: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11976: } else {
11977: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 11978: }
1.160.6.90 raeburn 11979: } elsif ($item eq 'texengine') {
11980: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
11981: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
11982: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
11983: }
1.139 raeburn 11984: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 11985: $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 11986: } elsif ($item eq 'uploadquota') {
11987: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11988: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11989: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11990: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 11991: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
11992:
1.160.6.21 raeburn 11993: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11994: '</ul>'.
11995: '</li>';
11996: } else {
11997: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11998: }
1.160.6.70 raeburn 11999: } elsif ($item eq 'mysqltables') {
12000: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
12001: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
12002: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
12003: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
12004: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
12005: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
12006: '</ul>'.
12007: '</li>';
12008: } else {
12009: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
12010: }
1.160.6.57 raeburn 12011: } elsif ($item eq 'postsubmit') {
12012: if ($domdefaults{'postsubmit'} eq 'off') {
12013: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
12014: } else {
12015: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
12016: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
12017: $resulttext .= &mt('durations:').'<ul>';
12018: foreach my $type (@types) {
12019: $resulttext .= '<li>';
12020: my $timeout;
12021: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
12022: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
12023: }
12024: my $display;
12025: if ($timeout eq '0') {
12026: $display = &mt('unlimited');
12027: } elsif ($timeout eq '') {
12028: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
12029: } else {
12030: $display = &mt('[quant,_1,second]',$timeout);
12031: }
12032: if ($type eq 'community') {
12033: $resulttext .= &mt('Communities');
12034: } elsif ($type eq 'official') {
12035: $resulttext .= &mt('Official courses');
12036: } elsif ($type eq 'unofficial') {
12037: $resulttext .= &mt('Unofficial courses');
12038: } elsif ($type eq 'textbook') {
12039: $resulttext .= &mt('Textbook courses');
12040: }
12041: $resulttext .= ' -- '.$display.'</li>';
12042: }
12043: $resulttext .= '</ul>';
12044: }
12045: $resulttext .= '</li>';
12046: }
1.160.6.16 raeburn 12047: } elsif ($item eq 'coursecredits') {
12048: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
12049: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 12050: ($domdefaults{'unofficialcredits'} eq '') &&
12051: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 12052: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12053: } else {
12054: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
12055: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
12056: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 12057: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 12058: '</ul>'.
12059: '</li>';
12060: }
12061: } else {
12062: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
12063: }
1.160.6.64 raeburn 12064: } elsif ($item eq 'canclone') {
12065: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12066: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12067: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
12068: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
12069: }
12070: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
12071: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
12072: } else {
12073: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
12074: }
1.140 raeburn 12075: }
1.121 raeburn 12076: }
12077: $resulttext .= '</ul>';
12078: } else {
12079: $resulttext = &mt('No changes made to course defaults');
12080: }
12081: } else {
12082: $resulttext = '<span class="LC_error">'.
12083: &mt('An error occurred: [_1]',$putresult).'</span>';
12084: }
12085: return $resulttext;
12086: }
12087:
1.160.6.37 raeburn 12088: sub modify_selfenrollment {
12089: my ($dom,$lastactref,%domconfig) = @_;
12090: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
12091: my @types = ('official','unofficial','community','textbook');
12092: my %titles = &tool_titles();
12093: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12094: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
12095: $ordered{'default'} = ['types','registered','approval','limit'];
12096:
12097: my (%roles,%shown,%toplevel);
12098: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12099:
12100: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12101: if ($domconfig{'selfenrollment'} eq '') {
12102: $domconfig{'selfenrollment'} = {};
12103: }
12104: }
12105: %toplevel = (
12106: admin => 'Configuration Rights',
12107: default => 'Default settings',
12108: validation => 'Validation of self-enrollment requests',
12109: );
12110: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
12111:
12112: if (ref($ordered{'admin'}) eq 'ARRAY') {
12113: foreach my $item (@{$ordered{'admin'}}) {
12114: foreach my $type (@types) {
12115: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12116: $selfenrollhash{'admin'}{$type}{$item} = 1;
12117: } else {
12118: $selfenrollhash{'admin'}{$type}{$item} = 0;
12119: }
12120: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12121: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12122: if ($selfenrollhash{'admin'}{$type}{$item} ne
12123: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12124: push(@{$changes{'admin'}{$type}},$item);
12125: }
12126: } else {
12127: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12128: push(@{$changes{'admin'}{$type}},$item);
12129: }
12130: }
12131: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12132: push(@{$changes{'admin'}{$type}},$item);
12133: }
12134: }
12135: }
12136: }
12137:
12138: foreach my $item (@{$ordered{'default'}}) {
12139: foreach my $type (@types) {
12140: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12141: if ($item eq 'types') {
12142: unless (($value eq 'all') || ($value eq 'dom')) {
12143: $value = '';
12144: }
12145: } elsif ($item eq 'registered') {
12146: unless ($value eq '1') {
12147: $value = 0;
12148: }
12149: } elsif ($item eq 'approval') {
12150: unless ($value =~ /^[012]$/) {
12151: $value = 0;
12152: }
12153: } else {
12154: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12155: $value = 'none';
12156: }
12157: }
12158: $selfenrollhash{'default'}{$type}{$item} = $value;
12159: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12160: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12161: if ($selfenrollhash{'default'}{$type}{$item} ne
12162: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12163: push(@{$changes{'default'}{$type}},$item);
12164: }
12165: } else {
12166: push(@{$changes{'default'}{$type}},$item);
12167: }
12168: } else {
12169: push(@{$changes{'default'}{$type}},$item);
12170: }
12171: if ($item eq 'limit') {
12172: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12173: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12174: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12175: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12176: }
12177: } else {
12178: $selfenrollhash{'default'}{$type}{'cap'} = '';
12179: }
12180: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12181: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12182: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12183: push(@{$changes{'default'}{$type}},'cap');
12184: }
12185: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12186: push(@{$changes{'default'}{$type}},'cap');
12187: }
12188: }
12189: }
12190: }
12191:
12192: foreach my $item (@{$itemsref}) {
12193: if ($item eq 'fields') {
12194: my @changed;
12195: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12196: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12197: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12198: }
12199: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12200: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12201: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12202: $domconfig{'selfenrollment'}{'validation'}{$item});
12203: } else {
12204: @changed = @{$selfenrollhash{'validation'}{$item}};
12205: }
12206: } else {
12207: @changed = @{$selfenrollhash{'validation'}{$item}};
12208: }
12209: if (@changed) {
12210: if ($selfenrollhash{'validation'}{$item}) {
12211: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12212: } else {
12213: $changes{'validation'}{$item} = &mt('None');
12214: }
12215: }
12216: } else {
12217: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12218: if ($item eq 'markup') {
12219: if ($env{'form.selfenroll_validation_'.$item}) {
12220: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12221: }
12222: }
12223: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12224: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12225: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12226: }
12227: }
12228: }
12229: }
12230:
12231: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12232: $dom);
12233: if ($putresult eq 'ok') {
12234: if (keys(%changes) > 0) {
12235: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12236: $resulttext = &mt('Changes made:').'<ul>';
12237: foreach my $key ('admin','default','validation') {
12238: if (ref($changes{$key}) eq 'HASH') {
12239: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12240: if ($key eq 'validation') {
12241: foreach my $item (@{$itemsref}) {
12242: if (exists($changes{$key}{$item})) {
12243: if ($item eq 'markup') {
12244: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12245: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12246: } else {
12247: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12248: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12249: }
12250: }
12251: }
12252: } else {
12253: foreach my $type (@types) {
12254: if ($type eq 'community') {
12255: $roles{'1'} = &mt('Community personnel');
12256: } else {
12257: $roles{'1'} = &mt('Course personnel');
12258: }
12259: if (ref($changes{$key}{$type}) eq 'ARRAY') {
12260: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12261: if ($key eq 'admin') {
12262: my @mgrdc = ();
12263: if (ref($ordered{$key}) eq 'ARRAY') {
12264: foreach my $item (@{$ordered{'admin'}}) {
12265: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12266: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12267: push(@mgrdc,$item);
12268: }
12269: }
12270: }
12271: if (@mgrdc) {
12272: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12273: } else {
12274: delete($domdefaults{$type.'selfenrolladmdc'});
12275: }
12276: }
12277: } else {
12278: if (ref($ordered{$key}) eq 'ARRAY') {
12279: foreach my $item (@{$ordered{$key}}) {
12280: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12281: $domdefaults{$type.'selfenroll'.$item} =
12282: $selfenrollhash{$key}{$type}{$item};
12283: }
12284: }
12285: }
12286: }
12287: }
12288: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12289: foreach my $item (@{$ordered{$key}}) {
12290: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12291: $resulttext .= '<li>';
12292: if ($key eq 'admin') {
12293: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12294: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12295: } else {
12296: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12297: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12298: }
12299: $resulttext .= '</li>';
12300: }
12301: }
12302: $resulttext .= '</ul></li>';
12303: }
12304: }
12305: $resulttext .= '</ul></li>';
12306: }
12307: }
12308: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12309: my $cachetime = 24*60*60;
12310: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12311: if (ref($lastactref) eq 'HASH') {
12312: $lastactref->{'domdefaults'} = 1;
12313: }
12314: }
12315: }
12316: $resulttext .= '</ul>';
12317: } else {
12318: $resulttext = &mt('No changes made to self-enrollment settings');
12319: }
12320: } else {
12321: $resulttext = '<span class="LC_error">'.
12322: &mt('An error occurred: [_1]',$putresult).'</span>';
12323: }
12324: return $resulttext;
12325: }
12326:
1.137 raeburn 12327: sub modify_usersessions {
1.160.6.27 raeburn 12328: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12329: my @hostingtypes = ('version','excludedomain','includedomain');
12330: my @offloadtypes = ('primary','default');
12331: my %types = (
12332: remote => \@hostingtypes,
12333: hosted => \@hostingtypes,
12334: spares => \@offloadtypes,
12335: );
12336: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12337: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 12338: my (%by_ip,%by_location,@intdoms);
12339: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
12340: my @locations = sort(keys(%by_location));
1.137 raeburn 12341: my (%defaultshash,%changes);
12342: foreach my $prefix (@prefixes) {
12343: $defaultshash{'usersessions'}{$prefix} = {};
12344: }
1.160.6.27 raeburn 12345: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12346: my $resulttext;
1.138 raeburn 12347: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12348: foreach my $prefix (@prefixes) {
1.145 raeburn 12349: next if ($prefix eq 'spares');
12350: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12351: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12352: if ($type eq 'version') {
12353: my $value = $env{'form.'.$prefix.'_'.$type};
12354: my $okvalue;
12355: if ($value ne '') {
12356: if (grep(/^\Q$value\E$/,@lcversions)) {
12357: $okvalue = $value;
12358: }
12359: }
12360: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12361: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12362: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12363: if ($inuse == 0) {
12364: $changes{$prefix}{$type} = 1;
12365: } else {
12366: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12367: $changes{$prefix}{$type} = 1;
12368: }
12369: if ($okvalue ne '') {
12370: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12371: }
12372: }
12373: } else {
12374: if (($inuse == 1) && ($okvalue ne '')) {
12375: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12376: $changes{$prefix}{$type} = 1;
12377: }
12378: }
12379: } else {
12380: if (($inuse == 1) && ($okvalue ne '')) {
12381: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12382: $changes{$prefix}{$type} = 1;
12383: }
12384: }
12385: } else {
12386: if (($inuse == 1) && ($okvalue ne '')) {
12387: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12388: $changes{$prefix}{$type} = 1;
12389: }
12390: }
12391: } else {
12392: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12393: my @okvals;
12394: foreach my $val (@vals) {
1.138 raeburn 12395: if ($val =~ /:/) {
12396: my @items = split(/:/,$val);
12397: foreach my $item (@items) {
12398: if (ref($by_location{$item}) eq 'ARRAY') {
12399: push(@okvals,$item);
12400: }
12401: }
12402: } else {
12403: if (ref($by_location{$val}) eq 'ARRAY') {
12404: push(@okvals,$val);
12405: }
1.137 raeburn 12406: }
12407: }
12408: @okvals = sort(@okvals);
12409: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12410: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12411: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12412: if ($inuse == 0) {
12413: $changes{$prefix}{$type} = 1;
12414: } else {
12415: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12416: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12417: if (@changed > 0) {
12418: $changes{$prefix}{$type} = 1;
12419: }
12420: }
12421: } else {
12422: if ($inuse == 1) {
12423: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12424: $changes{$prefix}{$type} = 1;
12425: }
12426: }
12427: } else {
12428: if ($inuse == 1) {
12429: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12430: $changes{$prefix}{$type} = 1;
12431: }
12432: }
12433: } else {
12434: if ($inuse == 1) {
12435: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12436: $changes{$prefix}{$type} = 1;
12437: }
12438: }
12439: }
12440: }
12441: }
1.145 raeburn 12442:
12443: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12444: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12445: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12446: my $savespares;
12447:
12448: foreach my $lonhost (sort(keys(%servers))) {
12449: my $serverhomeID =
12450: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12451: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12452: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12453: my %spareschg;
12454: foreach my $type (@{$types{'spares'}}) {
12455: my @okspares;
12456: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12457: foreach my $server (@checked) {
1.152 raeburn 12458: if (&Apache::lonnet::hostname($server) ne '') {
12459: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12460: unless (grep(/^\Q$server\E$/,@okspares)) {
12461: push(@okspares,$server);
12462: }
1.145 raeburn 12463: }
12464: }
12465: }
12466: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12467: my $newspare;
1.152 raeburn 12468: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12469: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12470: $newspare = $new;
12471: }
12472: }
1.152 raeburn 12473: my @spares;
12474: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12475: @spares = sort(@okspares,$newspare);
12476: } else {
12477: @spares = sort(@okspares);
12478: }
12479: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12480: if (ref($spareid{$lonhost}) eq 'HASH') {
12481: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12482: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12483: if (@diffs > 0) {
12484: $spareschg{$type} = 1;
12485: }
12486: }
12487: }
12488: }
12489: if (keys(%spareschg) > 0) {
12490: $changes{'spares'}{$lonhost} = \%spareschg;
12491: }
12492: }
1.160.6.61 raeburn 12493: $defaultshash{'usersessions'}{'offloadnow'} = {};
12494: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12495: my @okoffload;
12496: if (@offloadnow) {
12497: foreach my $server (@offloadnow) {
12498: if (&Apache::lonnet::hostname($server) ne '') {
12499: unless (grep(/^\Q$server\E$/,@okoffload)) {
12500: push(@okoffload,$server);
12501: }
12502: }
12503: }
12504: if (@okoffload) {
12505: foreach my $lonhost (@okoffload) {
12506: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12507: }
12508: }
12509: }
1.145 raeburn 12510: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12511: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12512: if (ref($changes{'spares'}) eq 'HASH') {
12513: if (keys(%{$changes{'spares'}}) > 0) {
12514: $savespares = 1;
12515: }
12516: }
12517: } else {
12518: $savespares = 1;
12519: }
1.160.6.61 raeburn 12520: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12521: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12522: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12523: $changes{'offloadnow'} = 1;
12524: last;
12525: }
12526: }
12527: unless ($changes{'offloadnow'}) {
12528: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12529: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12530: $changes{'offloadnow'} = 1;
12531: last;
12532: }
12533: }
12534: }
12535: } elsif (@okoffload) {
12536: $changes{'offloadnow'} = 1;
12537: }
12538: } elsif (@okoffload) {
12539: $changes{'offloadnow'} = 1;
1.145 raeburn 12540: }
1.147 raeburn 12541: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12542: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12543: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12544: $dom);
12545: if ($putresult eq 'ok') {
12546: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12547: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12548: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12549: }
12550: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12551: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12552: }
1.160.6.61 raeburn 12553: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12554: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12555: }
1.137 raeburn 12556: }
12557: my $cachetime = 24*60*60;
12558: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 12559: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 12560: if (ref($lastactref) eq 'HASH') {
12561: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 12562: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 12563: }
1.147 raeburn 12564: if (keys(%changes) > 0) {
12565: my %lt = &usersession_titles();
12566: $resulttext = &mt('Changes made:').'<ul>';
12567: foreach my $prefix (@prefixes) {
12568: if (ref($changes{$prefix}) eq 'HASH') {
12569: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12570: if ($prefix eq 'spares') {
12571: if (ref($changes{$prefix}) eq 'HASH') {
12572: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12573: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12574: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 12575: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12576: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12577: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12578: foreach my $type (@{$types{$prefix}}) {
12579: if ($changes{$prefix}{$lonhost}{$type}) {
12580: my $offloadto = &mt('None');
12581: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12582: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12583: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12584: }
1.145 raeburn 12585: }
1.147 raeburn 12586: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12587: }
1.137 raeburn 12588: }
12589: }
1.147 raeburn 12590: $resulttext .= '</li>';
1.137 raeburn 12591: }
12592: }
1.147 raeburn 12593: } else {
12594: foreach my $type (@{$types{$prefix}}) {
12595: if (defined($changes{$prefix}{$type})) {
12596: my $newvalue;
12597: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12598: if (ref($defaultshash{'usersessions'}{$prefix})) {
12599: if ($type eq 'version') {
12600: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12601: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12602: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12603: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12604: }
1.145 raeburn 12605: }
12606: }
12607: }
1.147 raeburn 12608: if ($newvalue eq '') {
12609: if ($type eq 'version') {
12610: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12611: } else {
12612: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12613: }
1.145 raeburn 12614: } else {
1.147 raeburn 12615: if ($type eq 'version') {
12616: $newvalue .= ' '.&mt('(or later)');
12617: }
12618: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12619: }
1.137 raeburn 12620: }
12621: }
12622: }
1.147 raeburn 12623: $resulttext .= '</ul>';
1.137 raeburn 12624: }
12625: }
1.160.6.61 raeburn 12626: if ($changes{'offloadnow'}) {
12627: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12628: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12629: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12630: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12631: $resulttext .= '<li>'.$lonhost.'</li>';
12632: }
12633: $resulttext .= '</ul>';
12634: } else {
12635: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12636: }
12637: } else {
12638: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12639: }
12640: }
1.147 raeburn 12641: $resulttext .= '</ul>';
12642: } else {
12643: $resulttext = $nochgmsg;
1.137 raeburn 12644: }
12645: } else {
12646: $resulttext = '<span class="LC_error">'.
12647: &mt('An error occurred: [_1]',$putresult).'</span>';
12648: }
12649: } else {
1.147 raeburn 12650: $resulttext = $nochgmsg;
1.137 raeburn 12651: }
12652: return $resulttext;
12653: }
12654:
1.150 raeburn 12655: sub modify_loadbalancing {
12656: my ($dom,%domconfig) = @_;
12657: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12658: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12659: my ($othertitle,$usertypes,$types) =
12660: &Apache::loncommon::sorted_inst_types($dom);
12661: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 12662: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12663: my @sparestypes = ('primary','default');
12664: my %typetitles = &sparestype_titles();
12665: my $resulttext;
1.160.6.7 raeburn 12666: my (%currbalancer,%currtargets,%currrules,%existing);
12667: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12668: %existing = %{$domconfig{'loadbalancing'}};
12669: }
12670: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12671: \%currtargets,\%currrules);
12672: my ($saveloadbalancing,%defaultshash,%changes);
12673: my ($alltypes,$othertypes,$titles) =
12674: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12675: my %ruletitles = &offloadtype_text();
12676: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12677: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12678: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12679: if ($balancer eq '') {
12680: next;
12681: }
12682: if (!exists($servers{$balancer})) {
12683: if (exists($currbalancer{$balancer})) {
12684: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 12685: }
1.160.6.7 raeburn 12686: next;
12687: }
12688: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12689: push(@{$changes{'delete'}},$balancer);
12690: next;
12691: }
12692: if (!exists($currbalancer{$balancer})) {
12693: push(@{$changes{'add'}},$balancer);
12694: }
12695: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12696: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12697: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12698: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12699: $saveloadbalancing = 1;
12700: }
12701: foreach my $sparetype (@sparestypes) {
12702: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12703: my @offloadto;
12704: foreach my $target (@targets) {
12705: if (($servers{$target}) && ($target ne $balancer)) {
12706: if ($sparetype eq 'default') {
12707: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12708: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 12709: }
12710: }
1.160.6.7 raeburn 12711: unless(grep(/^\Q$target\E$/,@offloadto)) {
12712: push(@offloadto,$target);
12713: }
1.150 raeburn 12714: }
12715: }
1.160.6.76 raeburn 12716: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
12717: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
12718: push(@offloadto,$balancer);
12719: }
12720: }
12721: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 12722: }
1.160.6.7 raeburn 12723: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 12724: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 12725: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12726: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 12727: if (@targetdiffs > 0) {
1.160.6.7 raeburn 12728: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12729: }
1.160.6.7 raeburn 12730: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12731: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12732: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12733: }
12734: }
12735: }
12736: } else {
1.160.6.7 raeburn 12737: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
12738: foreach my $sparetype (@sparestypes) {
12739: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12740: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12741: $changes{'curr'}{$balancer}{'targets'} = 1;
12742: }
1.150 raeburn 12743: }
12744: }
1.160.6.7 raeburn 12745: }
1.150 raeburn 12746: }
12747: my $ishomedom;
1.160.6.7 raeburn 12748: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12749: $ishomedom = 1;
1.150 raeburn 12750: }
12751: if (ref($alltypes) eq 'ARRAY') {
12752: foreach my $type (@{$alltypes}) {
12753: my $rule;
1.160.6.7 raeburn 12754: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 12755: (!$ishomedom)) {
1.160.6.7 raeburn 12756: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12757: }
12758: if ($rule eq 'specific') {
1.160.6.55 raeburn 12759: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12760: if (exists($servers{$specifiedhost})) {
12761: $rule = $specifiedhost;
12762: }
1.150 raeburn 12763: }
1.160.6.7 raeburn 12764: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12765: if (ref($currrules{$balancer}) eq 'HASH') {
12766: if ($rule ne $currrules{$balancer}{$type}) {
12767: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12768: }
12769: } elsif ($rule ne '') {
1.160.6.7 raeburn 12770: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12771: }
12772: }
12773: }
1.160.6.7 raeburn 12774: }
12775: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12776: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12777: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12778: $defaultshash{'loadbalancing'} = {};
12779: }
12780: my $putresult = &Apache::lonnet::put_dom('configuration',
12781: \%defaultshash,$dom);
12782: if ($putresult eq 'ok') {
12783: if (keys(%changes) > 0) {
1.160.6.54 raeburn 12784: my %toupdate;
1.160.6.7 raeburn 12785: if (ref($changes{'delete'}) eq 'ARRAY') {
12786: foreach my $balancer (sort(@{$changes{'delete'}})) {
12787: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 12788: $toupdate{$balancer} = 1;
1.150 raeburn 12789: }
1.160.6.7 raeburn 12790: }
12791: if (ref($changes{'add'}) eq 'ARRAY') {
12792: foreach my $balancer (sort(@{$changes{'add'}})) {
12793: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 12794: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12795: }
12796: }
12797: if (ref($changes{'curr'}) eq 'HASH') {
12798: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 12799: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12800: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12801: if ($changes{'curr'}{$balancer}{'targets'}) {
12802: my %offloadstr;
12803: foreach my $sparetype (@sparestypes) {
12804: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12805: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12806: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12807: }
12808: }
1.150 raeburn 12809: }
1.160.6.7 raeburn 12810: if (keys(%offloadstr) == 0) {
12811: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 12812: } else {
1.160.6.7 raeburn 12813: my $showoffload;
12814: foreach my $sparetype (@sparestypes) {
12815: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12816: if (defined($offloadstr{$sparetype})) {
12817: $showoffload .= $offloadstr{$sparetype};
12818: } else {
12819: $showoffload .= &mt('None');
12820: }
12821: $showoffload .= (' 'x3);
12822: }
12823: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 12824: }
12825: }
12826: }
1.160.6.7 raeburn 12827: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12828: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12829: foreach my $type (@{$alltypes}) {
12830: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12831: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12832: my $balancetext;
12833: if ($rule eq '') {
12834: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 12835: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 12836: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12837: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 12838: foreach my $sparetype (@sparestypes) {
12839: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12840: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12841: }
12842: }
1.160.6.55 raeburn 12843: foreach my $item (@{$alltypes}) {
12844: next if ($item =~ /^_LC_ipchange/);
12845: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
12846: if ($hasrule eq 'homeserver') {
12847: map { $toupdate{$_} = 1; } (keys(%libraryservers));
12848: } else {
12849: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
12850: if ($servers{$hasrule}) {
12851: $toupdate{$hasrule} = 1;
12852: }
12853: }
12854: }
12855: }
12856: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
12857: $balancetext = $ruletitles{$rule};
12858: } else {
12859: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12860: $balancetext = $ruletitles{'particular'}.' '.$receiver;
12861: if ($receiver) {
12862: $toupdate{$receiver};
12863: }
12864: }
12865: } else {
12866: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 12867: }
1.160.6.7 raeburn 12868: } else {
12869: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
12870: }
1.160.6.26 raeburn 12871: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 12872: }
12873: }
12874: }
12875: }
1.160.6.54 raeburn 12876: if (keys(%toupdate)) {
12877: my %thismachine;
12878: my $updatedhere;
12879: my $cachetime = 60*60*24;
12880: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12881: foreach my $lonhost (keys(%toupdate)) {
12882: if ($thismachine{$lonhost}) {
12883: unless ($updatedhere) {
12884: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
12885: $defaultshash{'loadbalancing'},
12886: $cachetime);
12887: $updatedhere = 1;
12888: }
12889: } else {
12890: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
12891: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
12892: }
12893: }
12894: }
1.150 raeburn 12895: }
1.160.6.7 raeburn 12896: }
12897: if ($resulttext ne '') {
12898: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 12899: } else {
12900: $resulttext = $nochgmsg;
12901: }
12902: } else {
1.160.6.7 raeburn 12903: $resulttext = $nochgmsg;
1.150 raeburn 12904: }
12905: } else {
1.160.6.7 raeburn 12906: $resulttext = '<span class="LC_error">'.
12907: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 12908: }
12909: } else {
1.160.6.7 raeburn 12910: $resulttext = $nochgmsg;
1.150 raeburn 12911: }
12912: return $resulttext;
12913: }
12914:
1.48 raeburn 12915: sub recurse_check {
12916: my ($chkcats,$categories,$depth,$name) = @_;
12917: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
12918: my $chg = 0;
12919: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
12920: my $category = $chkcats->[$depth]{$name}[$j];
12921: my $item;
12922: if ($category eq '') {
12923: $chg ++;
12924: } else {
12925: my $deeper = $depth + 1;
12926: $item = &escape($category).':'.&escape($name).':'.$depth;
12927: if ($chg) {
12928: $categories->{$item} -= $chg;
12929: }
12930: &recurse_check($chkcats,$categories,$deeper,$category);
12931: $deeper --;
12932: }
12933: }
12934: }
12935: return;
12936: }
12937:
12938: sub recurse_cat_deletes {
12939: my ($item,$coursecategories,$deletions) = @_;
12940: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12941: my $subdepth = $depth + 1;
12942: if (ref($coursecategories) eq 'HASH') {
12943: foreach my $subitem (keys(%{$coursecategories})) {
12944: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
12945: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
12946: delete($coursecategories->{$subitem});
12947: $deletions->{$subitem} = 1;
12948: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 12949: }
1.48 raeburn 12950: }
12951: }
12952: return;
12953: }
12954:
1.125 raeburn 12955: sub active_dc_picker {
1.160.6.16 raeburn 12956: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 12957: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 12958: my @domcoord = keys(%domcoords);
12959: if (keys(%currhash)) {
12960: foreach my $dc (keys(%currhash)) {
12961: unless (exists($domcoords{$dc})) {
12962: push(@domcoord,$dc);
12963: }
12964: }
12965: }
12966: @domcoord = sort(@domcoord);
12967: my $numdcs = scalar(@domcoord);
12968: my $rows = 0;
12969: my $table;
1.125 raeburn 12970: if ($numdcs > 1) {
1.160.6.16 raeburn 12971: $table = '<table>';
12972: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 12973: my $rem = $i%($numinrow);
12974: if ($rem == 0) {
12975: if ($i > 0) {
1.160.6.16 raeburn 12976: $table .= '</tr>';
1.125 raeburn 12977: }
1.160.6.16 raeburn 12978: $table .= '<tr>';
12979: $rows ++;
1.125 raeburn 12980: }
1.160.6.16 raeburn 12981: my $check = '';
12982: if ($inputtype eq 'radio') {
12983: if (keys(%currhash) == 0) {
12984: if (!$i) {
12985: $check = ' checked="checked"';
12986: }
12987: } elsif (exists($currhash{$domcoord[$i]})) {
12988: $check = ' checked="checked"';
12989: }
12990: } else {
12991: if (exists($currhash{$domcoord[$i]})) {
12992: $check = ' checked="checked"';
1.125 raeburn 12993: }
12994: }
1.160.6.16 raeburn 12995: if ($i == @domcoord - 1) {
1.125 raeburn 12996: my $colsleft = $numinrow - $rem;
12997: if ($colsleft > 1) {
1.160.6.16 raeburn 12998: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 12999: } else {
1.160.6.16 raeburn 13000: $table .= '<td class="LC_left_item">';
1.125 raeburn 13001: }
13002: } else {
1.160.6.16 raeburn 13003: $table .= '<td class="LC_left_item">';
13004: }
13005: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
13006: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
13007: $table .= '<span class="LC_nobreak"><label>'.
13008: '<input type="'.$inputtype.'" name="'.$name.'"'.
13009: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
13010: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 13011: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 13012: }
1.160.6.33 raeburn 13013: $table .= '</label></span></td>';
1.125 raeburn 13014: }
1.160.6.16 raeburn 13015: $table .= '</tr></table>';
13016: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 13017: my ($dcname,$dcdom) = split(':',$domcoord[0]);
13018: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 13019: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 13020: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 13021: if ($user ne $dcname.':'.$dcdom) {
13022: $table .= ' ('.$dcname.':'.$dcdom.')';
13023: }
1.160.6.16 raeburn 13024: } else {
13025: my $check;
13026: if (exists($currhash{$domcoord[0]})) {
13027: $check = ' checked="checked"';
13028: }
1.160.6.50 raeburn 13029: $table = '<span class="LC_nobreak"><label>'.
13030: '<input type="checkbox" name="'.$name.'" '.
13031: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 13032: if ($user ne $dcname.':'.$dcdom) {
13033: $table .= ' ('.$dcname.':'.$dcdom.')';
13034: }
13035: $table .= '</label></span>';
1.160.6.16 raeburn 13036: $rows ++;
13037: }
1.125 raeburn 13038: }
1.160.6.16 raeburn 13039: return ($numdcs,$table,$rows);
1.125 raeburn 13040: }
13041:
1.137 raeburn 13042: sub usersession_titles {
13043: return &Apache::lonlocal::texthash(
13044: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
13045: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 13046: spares => 'Servers offloaded to, when busy',
1.137 raeburn 13047: version => 'LON-CAPA version requirement',
1.138 raeburn 13048: excludedomain => 'Allow all, but exclude specific domains',
13049: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 13050: primary => 'Primary (checked first)',
1.154 raeburn 13051: default => 'Default',
1.137 raeburn 13052: );
13053: }
13054:
1.152 raeburn 13055: sub id_for_thisdom {
13056: my (%servers) = @_;
13057: my %altids;
13058: foreach my $server (keys(%servers)) {
13059: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
13060: if ($serverhome ne $server) {
13061: $altids{$serverhome} = $server;
13062: }
13063: }
13064: return %altids;
13065: }
13066:
1.150 raeburn 13067: sub count_servers {
13068: my ($currbalancer,%servers) = @_;
13069: my (@spares,$numspares);
13070: foreach my $lonhost (sort(keys(%servers))) {
13071: next if ($currbalancer eq $lonhost);
13072: push(@spares,$lonhost);
13073: }
13074: if ($currbalancer) {
13075: $numspares = scalar(@spares);
13076: } else {
13077: $numspares = scalar(@spares) - 1;
13078: }
13079: return ($numspares,@spares);
13080: }
13081:
13082: sub lonbalance_targets_js {
1.160.6.7 raeburn 13083: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13084: my $select = &mt('Select');
13085: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13086: if (ref($servers) eq 'HASH') {
13087: $alltargets = join("','",sort(keys(%{$servers})));
13088: my @homedoms;
13089: foreach my $server (sort(keys(%{$servers}))) {
13090: if (&Apache::lonnet::host_domain($server) eq $dom) {
13091: push(@homedoms,'1');
13092: } else {
13093: push(@homedoms,'0');
13094: }
13095: }
13096: $allishome = join("','",@homedoms);
13097: }
13098: if (ref($types) eq 'ARRAY') {
13099: if (@{$types} > 0) {
13100: @alltypes = @{$types};
13101: }
13102: }
13103: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13104: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 13105: my (%currbalancer,%currtargets,%currrules,%existing);
13106: if (ref($settings) eq 'HASH') {
13107: %existing = %{$settings};
13108: }
13109: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13110: \%currtargets,\%currrules);
13111: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13112: return <<"END";
13113:
13114: <script type="text/javascript">
13115: // <![CDATA[
13116:
1.160.6.7 raeburn 13117: currBalancers = new Array('$balancers');
13118:
13119: function toggleTargets(balnum) {
13120: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13121: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13122: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13123: var prevbalancer = prevhostitem.value;
13124: var baltotal = document.getElementById('loadbalancing_total').value;
13125: prevhostitem.value = balancer;
13126: if (prevbalancer != '') {
13127: var prevIdx = currBalancers.indexOf(prevbalancer);
13128: if (prevIdx != -1) {
13129: currBalancers.splice(prevIdx,1);
13130: }
13131: }
1.150 raeburn 13132: if (balancer == '') {
1.160.6.7 raeburn 13133: hideSpares(balnum);
1.150 raeburn 13134: } else {
1.160.6.7 raeburn 13135: var currIdx = currBalancers.indexOf(balancer);
13136: if (currIdx == -1) {
13137: currBalancers.push(balancer);
13138: }
1.150 raeburn 13139: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 13140: var ishomedom = homedoms[lonhostitem.selectedIndex];
13141: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13142: }
1.160.6.7 raeburn 13143: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13144: return;
13145: }
13146:
1.160.6.7 raeburn 13147: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13148: var alltargets = new Array('$alltargets');
13149: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13150: var offloadtypes = new Array('primary','default');
13151:
1.160.6.7 raeburn 13152: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13153: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13154:
1.151 raeburn 13155: for (var i=0; i<offloadtypes.length; i++) {
13156: var count = 0;
13157: for (var j=0; j<alltargets.length; j++) {
13158: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 13159: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13160: item.value = alltargets[j];
13161: item.style.textAlign='left';
13162: item.style.textFace='normal';
13163: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13164: if (currBalancers.indexOf(alltargets[j]) == -1) {
13165: item.disabled = '';
13166: } else {
13167: item.disabled = 'disabled';
13168: item.checked = false;
13169: }
1.151 raeburn 13170: count ++;
13171: }
1.150 raeburn 13172: }
13173: }
1.151 raeburn 13174: for (var k=0; k<insttypes.length; k++) {
13175: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13176: if (ishomedom == 1) {
1.160.6.7 raeburn 13177: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13178: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13179: } else {
1.160.6.7 raeburn 13180: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13181: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13182: }
13183: } else {
1.160.6.7 raeburn 13184: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13185: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13186: }
1.151 raeburn 13187: if ((insttypes[k] != '_LC_external') &&
13188: ((insttypes[k] != '_LC_internetdom') ||
13189: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 13190: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13191: item.options.length = 0;
13192: item.options[0] = new Option("","",true,true);
13193: var idx = 0;
1.151 raeburn 13194: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 13195: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13196: idx ++;
13197: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13198: }
13199: }
13200: }
13201: }
13202: return;
13203: }
13204:
1.160.6.7 raeburn 13205: function hideSpares(balnum) {
1.150 raeburn 13206: var alltargets = new Array('$alltargets');
13207: var insttypes = new Array('$allinsttypes');
13208: var offloadtypes = new Array('primary','default');
13209:
1.160.6.7 raeburn 13210: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13211: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13212:
13213: var total = alltargets.length - 1;
13214: for (var i=0; i<offloadtypes; i++) {
13215: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 13216: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13217: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13218: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13219: }
1.150 raeburn 13220: }
13221: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 13222: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13223: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13224: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 13225: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13226: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13227: }
13228: }
13229: return;
13230: }
13231:
1.160.6.7 raeburn 13232: function checkOffloads(item,balnum,type) {
1.150 raeburn 13233: var alltargets = new Array('$alltargets');
13234: var offloadtypes = new Array('primary','default');
13235: if (item.checked) {
13236: var total = alltargets.length - 1;
13237: var other;
13238: if (type == offloadtypes[0]) {
1.151 raeburn 13239: other = offloadtypes[1];
1.150 raeburn 13240: } else {
1.151 raeburn 13241: other = offloadtypes[0];
1.150 raeburn 13242: }
13243: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 13244: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13245: if (server == item.value) {
1.160.6.7 raeburn 13246: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13247: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13248: }
13249: }
13250: }
13251: }
13252: return;
13253: }
13254:
1.160.6.7 raeburn 13255: function singleServerToggle(balnum,type) {
13256: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13257: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 13258: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13259: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13260:
13261: } else {
1.160.6.7 raeburn 13262: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13263: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13264: }
13265: return;
13266: }
13267:
1.160.6.7 raeburn 13268: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13269: if (type == '_LC_external') {
1.160.6.26 raeburn 13270: return;
1.150 raeburn 13271: }
1.160.6.7 raeburn 13272: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13273: for (var i=0; i<typesRules.length; i++) {
13274: if (formname.elements[typesRules[i]].checked) {
13275: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 13276: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13277: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13278: } else {
1.160.6.7 raeburn 13279: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13280: }
13281: }
13282: }
13283: return;
13284: }
13285:
13286: function balancerDeleteChange(balnum) {
13287: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13288: var baltotal = document.getElementById('loadbalancing_total').value;
13289: var addtarget;
13290: var removetarget;
13291: var action = 'delete';
13292: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13293: var lonhost = hostitem.value;
13294: var currIdx = currBalancers.indexOf(lonhost);
13295: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13296: if (currIdx != -1) {
13297: currBalancers.splice(currIdx,1);
13298: }
13299: addtarget = lonhost;
13300: } else {
13301: if (currIdx == -1) {
13302: currBalancers.push(lonhost);
13303: }
13304: removetarget = lonhost;
13305: action = 'undelete';
13306: }
13307: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13308: }
13309: return;
13310: }
13311:
13312: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13313: if (baltotal > 1) {
13314: var offloadtypes = new Array('primary','default');
13315: var alltargets = new Array('$alltargets');
13316: var insttypes = new Array('$allinsttypes');
13317: for (var i=0; i<baltotal; i++) {
13318: if (i != balnum) {
13319: for (var j=0; j<offloadtypes.length; j++) {
13320: var total = alltargets.length - 1;
13321: for (var k=0; k<total; k++) {
13322: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13323: var server = serveritem.value;
13324: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13325: if (server == addtarget) {
13326: serveritem.disabled = '';
13327: }
13328: }
13329: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13330: if (server == removetarget) {
13331: serveritem.disabled = 'disabled';
13332: serveritem.checked = false;
13333: }
13334: }
13335: }
13336: }
13337: for (var j=0; j<insttypes.length; j++) {
13338: if (insttypes[j] != '_LC_external') {
13339: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13340: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13341: var currSel = singleserver.selectedIndex;
13342: var currVal = singleserver.options[currSel].value;
13343: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13344: var numoptions = singleserver.options.length;
13345: var needsnew = 1;
13346: for (var k=0; k<numoptions; k++) {
13347: if (singleserver.options[k] == addtarget) {
13348: needsnew = 0;
13349: break;
13350: }
13351: }
13352: if (needsnew == 1) {
13353: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13354: }
13355: }
13356: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13357: singleserver.options.length = 0;
13358: if ((currVal) && (currVal != removetarget)) {
13359: singleserver.options[0] = new Option("","",false,false);
13360: } else {
13361: singleserver.options[0] = new Option("","",true,true);
13362: }
13363: var idx = 0;
13364: for (var m=0; m<alltargets.length; m++) {
13365: if (currBalancers.indexOf(alltargets[m]) == -1) {
13366: idx ++;
13367: if (currVal == alltargets[m]) {
13368: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13369: } else {
13370: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13371: }
13372: }
13373: }
13374: }
13375: }
13376: }
13377: }
1.150 raeburn 13378: }
13379: }
13380: }
13381: return;
13382: }
13383:
1.152 raeburn 13384: // ]]>
13385: </script>
13386:
13387: END
13388: }
13389:
13390: sub new_spares_js {
13391: my @sparestypes = ('primary','default');
13392: my $types = join("','",@sparestypes);
13393: my $select = &mt('Select');
13394: return <<"END";
13395:
13396: <script type="text/javascript">
13397: // <![CDATA[
13398:
13399: function updateNewSpares(formname,lonhost) {
13400: var types = new Array('$types');
13401: var include = new Array();
13402: var exclude = new Array();
13403: for (var i=0; i<types.length; i++) {
13404: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13405: for (var j=0; j<spareboxes.length; j++) {
13406: if (formname.elements[spareboxes[j]].checked) {
13407: exclude.push(formname.elements[spareboxes[j]].value);
13408: } else {
13409: include.push(formname.elements[spareboxes[j]].value);
13410: }
13411: }
13412: }
13413: for (var i=0; i<types.length; i++) {
13414: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13415: var selIdx = newSpare.selectedIndex;
13416: var currnew = newSpare.options[selIdx].value;
13417: var okSpares = new Array();
13418: for (var j=0; j<newSpare.options.length; j++) {
13419: var possible = newSpare.options[j].value;
13420: if (possible != '') {
13421: if (exclude.indexOf(possible) == -1) {
13422: okSpares.push(possible);
13423: } else {
13424: if (currnew == possible) {
13425: selIdx = 0;
13426: }
13427: }
13428: }
13429: }
13430: for (var k=0; k<include.length; k++) {
13431: if (okSpares.indexOf(include[k]) == -1) {
13432: okSpares.push(include[k]);
13433: }
13434: }
13435: okSpares.sort();
13436: newSpare.options.length = 0;
13437: if (selIdx == 0) {
13438: newSpare.options[0] = new Option("$select","",true,true);
13439: } else {
13440: newSpare.options[0] = new Option("$select","",false,false);
13441: }
13442: for (var m=0; m<okSpares.length; m++) {
13443: var idx = m+1;
13444: var selThis = 0;
13445: if (selIdx != 0) {
13446: if (okSpares[m] == currnew) {
13447: selThis = 1;
13448: }
13449: }
13450: if (selThis == 1) {
13451: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13452: } else {
13453: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13454: }
13455: }
13456: }
13457: return;
13458: }
13459:
13460: function checkNewSpares(lonhost,type) {
13461: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13462: var chosen = newSpare.options[newSpare.selectedIndex].value;
13463: if (chosen != '') {
13464: var othertype;
13465: var othernewSpare;
13466: if (type == 'primary') {
13467: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13468: }
13469: if (type == 'default') {
13470: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13471: }
13472: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13473: othernewSpare.selectedIndex = 0;
13474: }
13475: }
13476: return;
13477: }
13478:
13479: // ]]>
13480: </script>
13481:
13482: END
13483:
13484: }
13485:
13486: sub common_domprefs_js {
13487: return <<"END";
13488:
13489: <script type="text/javascript">
13490: // <![CDATA[
13491:
1.150 raeburn 13492: function getIndicesByName(formname,item) {
1.152 raeburn 13493: var group = new Array();
1.150 raeburn 13494: for (var i=0;i<formname.elements.length;i++) {
13495: if (formname.elements[i].name == item) {
1.152 raeburn 13496: group.push(formname.elements[i].id);
1.150 raeburn 13497: }
13498: }
1.152 raeburn 13499: return group;
1.150 raeburn 13500: }
13501:
13502: // ]]>
13503: </script>
13504:
13505: END
1.152 raeburn 13506:
1.150 raeburn 13507: }
13508:
1.160.6.5 raeburn 13509: sub recaptcha_js {
13510: my %lt = &captcha_phrases();
13511: return <<"END";
13512:
13513: <script type="text/javascript">
13514: // <![CDATA[
13515:
13516: function updateCaptcha(caller,context) {
13517: var privitem;
13518: var pubitem;
13519: var privtext;
13520: var pubtext;
1.160.6.69 raeburn 13521: var versionitem;
13522: var versiontext;
1.160.6.5 raeburn 13523: if (document.getElementById(context+'_recaptchapub')) {
13524: pubitem = document.getElementById(context+'_recaptchapub');
13525: } else {
13526: return;
13527: }
13528: if (document.getElementById(context+'_recaptchapriv')) {
13529: privitem = document.getElementById(context+'_recaptchapriv');
13530: } else {
13531: return;
13532: }
13533: if (document.getElementById(context+'_recaptchapubtxt')) {
13534: pubtext = document.getElementById(context+'_recaptchapubtxt');
13535: } else {
13536: return;
13537: }
13538: if (document.getElementById(context+'_recaptchaprivtxt')) {
13539: privtext = document.getElementById(context+'_recaptchaprivtxt');
13540: } else {
13541: return;
13542: }
1.160.6.69 raeburn 13543: if (document.getElementById(context+'_recaptchaversion')) {
13544: versionitem = document.getElementById(context+'_recaptchaversion');
13545: } else {
13546: return;
13547: }
13548: if (document.getElementById(context+'_recaptchavertxt')) {
13549: versiontext = document.getElementById(context+'_recaptchavertxt');
13550: } else {
13551: return;
13552: }
1.160.6.5 raeburn 13553: if (caller.checked) {
13554: if (caller.value == 'recaptcha') {
13555: pubitem.type = 'text';
13556: privitem.type = 'text';
13557: pubitem.size = '40';
13558: privitem.size = '40';
13559: pubtext.innerHTML = "$lt{'pub'}";
13560: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 13561: versionitem.type = 'text';
13562: versionitem.size = '3';
13563: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 13564: } else {
13565: pubitem.type = 'hidden';
13566: privitem.type = 'hidden';
1.160.6.69 raeburn 13567: versionitem.type = 'hidden';
1.160.6.5 raeburn 13568: pubtext.innerHTML = '';
13569: privtext.innerHTML = '';
1.160.6.69 raeburn 13570: versiontext.innerHTML = '';
1.160.6.5 raeburn 13571: }
13572: }
13573: return;
13574: }
13575:
13576: // ]]>
13577: </script>
13578:
13579: END
13580:
13581: }
13582:
1.160.6.40 raeburn 13583: sub toggle_display_js {
1.160.6.16 raeburn 13584: return <<"END";
13585:
13586: <script type="text/javascript">
13587: // <![CDATA[
13588:
1.160.6.40 raeburn 13589: function toggleDisplay(domForm,caller) {
13590: if (document.getElementById(caller)) {
13591: var divitem = document.getElementById(caller);
13592: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 13593: var checkval = 1;
13594: var dispval = 'block';
1.160.6.40 raeburn 13595: if (caller == 'emailoptions') {
13596: optionsElement = domForm.cancreate_email;
13597: }
1.160.6.57 raeburn 13598: if (caller == 'studentsubmission') {
13599: optionsElement = domForm.postsubmit;
13600: }
1.160.6.64 raeburn 13601: if (caller == 'cloneinstcode') {
13602: optionsElement = domForm.canclone;
13603: checkval = 'instcode';
13604: }
1.160.6.40 raeburn 13605: if (optionsElement.length) {
1.160.6.16 raeburn 13606: var currval;
1.160.6.40 raeburn 13607: for (var i=0; i<optionsElement.length; i++) {
13608: if (optionsElement[i].checked) {
13609: currval = optionsElement[i].value;
1.160.6.16 raeburn 13610: }
13611: }
1.160.6.64 raeburn 13612: if (currval == checkval) {
13613: divitem.style.display = dispval;
1.160.6.16 raeburn 13614: } else {
1.160.6.40 raeburn 13615: divitem.style.display = 'none';
1.160.6.16 raeburn 13616: }
13617: }
13618: }
13619: return;
13620: }
13621:
13622: // ]]>
13623: </script>
13624:
13625: END
13626:
13627: }
13628:
1.160.6.5 raeburn 13629: sub captcha_phrases {
13630: return &Apache::lonlocal::texthash (
13631: priv => 'Private key',
13632: pub => 'Public key',
13633: original => 'original (CAPTCHA)',
13634: recaptcha => 'successor (ReCAPTCHA)',
13635: notused => 'unused',
1.160.6.69 raeburn 13636: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 13637: );
13638: }
13639:
1.160.6.24 raeburn 13640: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 13641: my ($dom,$cachekeys) = @_;
13642: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 13643: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13644: my %thismachine;
13645: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.81 raeburn 13646: my @posscached = ('domainconfig','domdefaults','usersessions','directorysrch');
1.160.6.61 raeburn 13647: if (keys(%servers)) {
1.160.6.24 raeburn 13648: foreach my $server (keys(%servers)) {
13649: next if ($thismachine{$server});
1.160.6.27 raeburn 13650: my @cached;
13651: foreach my $name (@posscached) {
13652: if ($cachekeys->{$name}) {
13653: push(@cached,&escape($name).':'.&escape($dom));
13654: }
13655: }
13656: if (@cached) {
13657: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13658: }
1.160.6.24 raeburn 13659: }
13660: }
13661: return;
13662: }
13663:
1.3 raeburn 13664: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>