Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.88
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.88! raeburn 4: # $Id: domainprefs.pm,v 1.160.6.87 2018/09/02 15:22:28 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',
2810: 'updatesmail','idconflictsmail');
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" ';
2887: } elsif ($position eq 'bottom') {
2888: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2889: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
2890: if (ref($fields) eq 'ARRAY') {
2891: foreach my $field (@{$fields}) {
2892: $currfield{$field} = 'yes';
2893: }
2894: }
2895: $maxsize = '1.0';
2896: }
1.28 raeburn 2897: }
2898: my ($titles,$short_titles) = &contact_titles();
2899: my $rownum = 0;
2900: my $css_class;
1.160.6.78 raeburn 2901: if ($position eq 'top') {
2902: foreach my $item (@contacts) {
2903: $css_class = $rownum%2?' class="LC_odd_row"':'';
2904: $datatable .= '<tr'.$css_class.'>'.
2905: '<td><span class="LC_nobreak">'.$titles->{$item}.
2906: '</span></td><td class="LC_right_item">'.
2907: '<input type="text" name="'.$item.'" value="'.
2908: $to{$item}.'" /></td></tr>';
2909: $rownum ++;
2910: }
2911: } else {
2912: foreach my $type (@mailings) {
2913: $css_class = $rownum%2?' class="LC_odd_row"':'';
2914: $datatable .= '<tr'.$css_class.'>'.
2915: '<td><span class="LC_nobreak">'.
2916: $titles->{$type}.': </span></td>'.
2917: '<td class="LC_left_item">';
2918: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2919: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
2920: }
2921: $datatable .= '<span class="LC_nobreak">';
2922: foreach my $item (@contacts) {
2923: $datatable .= '<label>'.
2924: '<input type="checkbox" name="'.$type.'"'.
2925: $checked{$type}{$item}.
2926: ' value="'.$item.'" />'.$short_titles->{$item}.
2927: '</label> ';
2928: }
2929: $datatable .= '</span><br />'.&mt('Others').': '.
2930: '<input type="text" name="'.$type.'_others" '.
2931: 'value="'.$otheremails{$type}.'" />';
2932: my %locchecked;
2933: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
2934: foreach my $loc ('s','b') {
2935: if ($includeloc{$type} eq $loc) {
2936: $locchecked{$loc} = ' checked="checked"';
2937: last;
2938: }
2939: }
2940: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
2941: '<input type="text" name="'.$type.'_bcc" '.
2942: 'value="'.$bccemails{$type}.'" /></fieldset>'.
2943: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
2944: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 2945: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 2946: '<span class="LC_nobreak">'.&mt('Location:').' '.
2947: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
2948: (' 'x2).
2949: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
2950: '</span></fieldset>';
2951: }
2952: $datatable .= '</td></tr>'."\n";
2953: $rownum ++;
2954: }
1.28 raeburn 2955: }
1.160.6.78 raeburn 2956: if ($position eq 'middle') {
2957: my %choices;
2958: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2959: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2960: &mt('LON-CAPA core group - MSU'),600,500));
2961: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2962: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2963: &mt('LON-CAPA core group - MSU'),600,500));
2964: my @toggles = ('reporterrors','reportupdates');
2965: my %defaultchecked = ('reporterrors' => 'on',
2966: 'reportupdates' => 'on');
2967: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2968: \%choices,$rownum);
2969: $datatable .= $reports;
2970: } elsif ($position eq 'bottom') {
1.69 raeburn 2971: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2972: $datatable .= '<tr'.$css_class.'>'.
1.160.6.78 raeburn 2973: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
2974: &mt('(e-mail, subject, and description always shown)').
2975: '</td><td class="LC_left_item">';
2976: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
2977: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
2978: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
2979: foreach my $field (@{$fields}) {
2980: $datatable .= '<tr><td>'.$fieldtitles->{$field};
2981: if (($field eq 'screenshot') || ($field eq 'cc')) {
2982: $datatable .= ' '.&mt('(logged-in users)');
2983: }
2984: $datatable .='</td><td>';
2985: my $clickaction;
2986: if ($field eq 'screenshot') {
2987: $clickaction = ' onclick="screenshotSize(this);"';
2988: }
2989: if (ref($possoptions->{$field}) eq 'ARRAY') {
2990: foreach my $option (@{$possoptions->{$field}}) {
2991: my $checked;
2992: if ($currfield{$field} eq $option) {
2993: $checked = ' checked="checked"';
2994: }
2995: $datatable .= '<span class="LC_nobreak"><label>'.
2996: '<input type="radio" name="helpform_'.$field.'" '.
2997: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
2998: '</label></span>'.(' 'x2);
2999: }
3000: }
3001: if ($field eq 'screenshot') {
3002: my $display;
3003: if ($currfield{$field} eq 'no') {
3004: $display = ' style="display:none"';
3005: }
1.160.6.87 raeburn 3006: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.160.6.78 raeburn 3007: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
3008: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
3009: }
3010: $datatable .= '</td></tr>';
3011: }
3012: $datatable .= '</table>';
1.134 raeburn 3013: }
3014: $datatable .= '</td></tr>'."\n";
1.160.6.23 raeburn 3015: $rownum ++;
1.28 raeburn 3016: }
1.30 raeburn 3017: $$rowtotal += $rownum;
1.28 raeburn 3018: return $datatable;
3019: }
3020:
1.160.6.78 raeburn 3021: sub contacts_javascript {
3022: return <<"ENDSCRIPT";
3023:
3024: <script type="text/javascript">
3025: // <![CDATA[
3026:
3027: function screenshotSize(field) {
3028: if (document.getElementById('help_screenshotsize')) {
3029: if (field.value == 'no') {
3030: document.getElementById('help_screenshotsize').style.display="none";
3031: } else {
3032: document.getElementById('help_screenshotsize').style.display="";
3033: }
3034: }
3035: return;
3036: }
3037:
3038: // ]]>
3039: </script>
3040:
3041: ENDSCRIPT
3042: }
3043:
1.118 jms 3044: sub print_helpsettings {
1.160.6.73 raeburn 3045: my ($position,$dom,$settings,$rowtotal) = @_;
3046: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 3047: my $formname = 'display';
1.160.6.5 raeburn 3048: my ($datatable,$itemcount);
1.160.6.73 raeburn 3049: if ($position eq 'top') {
3050: $itemcount = 1;
3051: my (%choices,%defaultchecked,@toggles);
3052: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
3053: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
3054: &mt('LON-CAPA bug tracker'),600,500));
3055: %defaultchecked = ('submitbugs' => 'on');
3056: @toggles = ('submitbugs');
3057: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3058: \%choices,$itemcount);
3059: $$rowtotal ++;
3060: } else {
3061: my $css_class;
3062: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 3063: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 3064: if (ref($settings) eq 'HASH') {
3065: if (ref($settings->{'adhoc'}) eq 'HASH') {
3066: %current = %{$settings->{'adhoc'}};
3067: }
1.160.6.77 raeburn 3068: }
3069: my $count = 0;
3070: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 3071: if ($key=~/^rolesdef\_(\w+)$/) {
3072: my $rolename = $1;
1.160.6.77 raeburn 3073: my (%privs,$order);
1.160.6.73 raeburn 3074: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
3075: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 3076: if (ref($current{$rolename}) eq 'HASH') {
3077: $order = $current{$rolename}{'order'};
3078: }
3079: if ($order eq '') {
3080: $order = $count;
3081: }
3082: $ordered{$order} = $rolename;
3083: $count++;
1.160.6.73 raeburn 3084: }
3085: }
1.160.6.77 raeburn 3086: my $maxnum = scalar(keys(%ordered));
3087: my @roles_by_num = ();
3088: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3089: push(@roles_by_num,$item);
3090: }
3091: my $context = 'domprefs';
3092: my $crstype = 'Course';
3093: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 3094: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 3095: my ($numstatustypes,@jsarray);
3096: if (ref($types) eq 'ARRAY') {
3097: if (@{$types} > 0) {
3098: $numstatustypes = scalar(@{$types});
3099: push(@accesstypes,'status');
3100: @jsarray = ('bystatus');
3101: }
3102: }
1.160.6.86 raeburn 3103: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 3104: if (keys(%domhelpdesk)) {
3105: push(@accesstypes,('inc','exc'));
3106: push(@jsarray,('notinc','notexc'));
3107: }
3108: my $hiddenstr = join("','",@jsarray);
3109: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 3110: my $context = 'domprefs';
3111: my $crstype = 'Course';
1.160.6.77 raeburn 3112: my $prefix = 'helproles_';
3113: my $add_class = 'LC_hidden';
3114: foreach my $num (@roles_by_num) {
3115: my $role = $ordered{$num};
3116: my ($desc,$access,@statuses);
3117: if (ref($current{$role}) eq 'HASH') {
3118: $desc = $current{$role}{'desc'};
3119: $access = $current{$role}{'access'};
3120: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
3121: @statuses = @{$current{$role}{'insttypes'}};
3122: }
3123: }
3124: if ($desc eq '') {
3125: $desc = $role;
3126: }
3127: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 3128: my %full=();
3129: my %levels= (
3130: course => {},
3131: domain => {},
3132: system => {},
3133: );
3134: my %levelscurrent=(
3135: course => {},
3136: domain => {},
3137: system => {},
3138: );
3139: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
3140: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
3141: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 3142: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
3143: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
3144: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
3145: for (my $k=0; $k<=$maxnum; $k++) {
3146: my $vpos = $k+1;
3147: my $selstr;
3148: if ($k == $num) {
3149: $selstr = ' selected="selected" ';
3150: }
3151: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3152: }
3153: $datatable .= '</select>'.(' 'x2).
3154: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
3155: '</td>'.
3156: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3157: &mt('Name shown to users:').
3158: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
3159: '</fieldset>'.
3160: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
3161: $othertitle,$usertypes,$types,\%domhelpdesk).
3162: '<fieldset>'.
3163: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 3164: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 3165: \%levelscurrent,$identifier,
3166: 'LC_hidden',$prefix.$num.'_privs').
3167: '</fieldset></td>';
1.160.6.73 raeburn 3168: $itemcount ++;
3169: }
3170: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3171: my $newcust = 'custhelp'.$count;
3172: my (%privs,%levelscurrent);
3173: my %full=();
3174: my %levels= (
3175: course => {},
3176: domain => {},
3177: system => {},
3178: );
3179: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
3180: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 3181: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
3182: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
3183: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
3184: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
3185: for (my $k=0; $k<$maxnum+1; $k++) {
3186: my $vpos = $k+1;
3187: my $selstr;
3188: if ($k == $maxnum) {
3189: $selstr = ' selected="selected" ';
3190: }
3191: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3192: }
3193: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 3194: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
3195: '</label></span></td>'.
1.160.6.77 raeburn 3196: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
3197: '<span class="LC_nobreak">'.
3198: &mt('Internal name:').
3199: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
3200: '</span>'.(' 'x4).
3201: '<span class="LC_nobreak">'.
3202: &mt('Name shown to users:').
3203: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
3204: '</span></fieldset>'.
3205: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
3206: $usertypes,$types,\%domhelpdesk).
3207: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 3208: &Apache::lonuserutils::custom_role_header($context,$crstype,
3209: \@templateroles,$newcust).
3210: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
3211: \%levelscurrent,$newcust).
1.160.6.87 raeburn 3212: '</fieldset>'.
3213: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
3214: '</td></tr>';
1.160.6.73 raeburn 3215: $count ++;
3216: $$rowtotal += $count;
3217: }
1.160.6.5 raeburn 3218: return $datatable;
1.121 raeburn 3219: }
3220:
1.160.6.77 raeburn 3221: sub adhocbutton {
3222: my ($prefix,$num,$field,$visibility) = @_;
3223: my %lt = &Apache::lonlocal::texthash(
3224: show => 'Show details',
3225: hide => 'Hide details',
3226: );
3227: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
3228: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
3229: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
3230: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
3231: }
3232:
3233: sub helpsettings_javascript {
3234: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
3235: return unless(ref($roles_by_num) eq 'ARRAY');
3236: my %html_js_lt = &Apache::lonlocal::texthash(
3237: show => 'Show details',
3238: hide => 'Hide details',
3239: );
3240: &html_escape(\%html_js_lt);
3241: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
3242: return <<"ENDSCRIPT";
3243: <script type="text/javascript">
3244: // <![CDATA[
3245:
3246: function reorderHelpRoles(form,item) {
3247: var changedVal;
3248: $jstext
3249: var newpos = 'helproles_${total}_pos';
3250: var maxh = 1 + $total;
3251: var current = new Array();
3252: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3253: if (item == newpos) {
3254: changedVal = newitemVal;
3255: } else {
3256: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3257: current[newitemVal] = newpos;
3258: }
3259: for (var i=0; i<helproles.length; i++) {
3260: var elementName = 'helproles_'+helproles[i]+'_pos';
3261: if (elementName != item) {
3262: if (form.elements[elementName]) {
3263: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3264: current[currVal] = elementName;
3265: }
3266: }
3267: }
3268: var oldVal;
3269: for (var j=0; j<maxh; j++) {
3270: if (current[j] == undefined) {
3271: oldVal = j;
3272: }
3273: }
3274: if (oldVal < changedVal) {
3275: for (var k=oldVal+1; k<=changedVal ; k++) {
3276: var elementName = current[k];
3277: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3278: }
3279: } else {
3280: for (var k=changedVal; k<oldVal; k++) {
3281: var elementName = current[k];
3282: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3283: }
3284: }
3285: return;
3286: }
3287:
3288: function helpdeskAccess(num) {
3289: var curraccess = null;
3290: if (document.$formname.elements['helproles_'+num+'_access'].length) {
3291: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
3292: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
3293: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
3294: }
3295: }
3296: }
3297: var shown = Array();
3298: var hidden = Array();
3299: if (curraccess == 'none') {
3300: hidden = Array('$hiddenstr');
3301: } else {
3302: if (curraccess == 'status') {
3303: shown = Array('bystatus');
3304: hidden = Array('notinc','notexc');
3305: } else {
3306: if (curraccess == 'exc') {
3307: shown = Array('notexc');
3308: hidden = Array('notinc','bystatus');
3309: }
3310: if (curraccess == 'inc') {
3311: shown = Array('notinc');
3312: hidden = Array('notexc','bystatus');
3313: }
1.160.6.79 raeburn 3314: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 3315: hidden = Array('notinc','notexc','bystatus');
3316: }
3317: }
3318: }
3319: if (hidden.length > 0) {
3320: for (var i=0; i<hidden.length; i++) {
3321: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
3322: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
3323: }
3324: }
3325: }
3326: if (shown.length > 0) {
3327: for (var i=0; i<shown.length; i++) {
3328: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
3329: if (shown[i] == 'privs') {
3330: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
3331: } else {
3332: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
3333: }
3334: }
3335: }
3336: }
3337: return;
3338: }
3339:
3340: function toggleHelpdeskItem(num,field) {
3341: if (document.getElementById('helproles_'+num+'_'+field)) {
3342: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
3343: document.getElementById('helproles_'+num+'_'+field).className =
3344: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
3345: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3346: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
3347: }
3348: } else {
3349: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
3350: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
3351: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
3352: }
3353: }
3354: }
3355: return;
3356: }
3357:
3358: // ]]>
3359: </script>
3360:
3361: ENDSCRIPT
3362: }
3363:
3364: sub helpdeskroles_access {
3365: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
3366: $usertypes,$types,$domhelpdesk) = @_;
3367: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
3368: my %lt = &Apache::lonlocal::texthash(
3369: 'rou' => 'Role usage',
3370: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 3371: 'all' => 'All with domain helpdesk or helpdesk assistant role',
3372: 'dh' => 'All with domain helpdesk role',
3373: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 3374: 'none' => 'None',
3375: 'status' => 'Determined based on institutional status',
3376: 'inc' => 'Include all, but exclude specific personnel',
3377: 'exc' => 'Exclude all, but include specific personnel',
3378: );
3379: my %usecheck = (
3380: all => ' checked="checked"',
3381: );
3382: my %displaydiv = (
3383: status => 'none',
3384: inc => 'none',
3385: exc => 'none',
3386: priv => 'block',
3387: );
3388: my $output;
3389: if (ref($current) eq 'HASH') {
3390: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
3391: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
3392: $usecheck{$current->{access}} = $usecheck{'all'};
3393: delete($usecheck{'all'});
3394: if ($current->{access} =~ /^(status|inc|exc)$/) {
3395: my $access = $1;
3396: $displaydiv{$access} = 'inline';
3397: } elsif ($current->{access} eq 'none') {
3398: $displaydiv{'priv'} = 'none';
3399: }
3400: }
3401: }
3402: }
3403: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
3404: '<p>'.$lt{'whi'}.'</p>';
3405: foreach my $access (@{$accesstypes}) {
3406: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
3407: ' onclick="helpdeskAccess('."'$num'".');" />'.
3408: $lt{$access}.'</label>';
3409: if ($access eq 'status') {
3410: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
3411: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
3412: $othertitle,$usertypes,$types).
3413: '</div>';
3414: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
3415: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
3416: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3417: '</div>';
3418: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
3419: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
3420: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
3421: '</div>';
3422: }
3423: $output .= '</p>';
3424: }
3425: $output .= '</fieldset>';
3426: return $output;
3427: }
3428:
1.121 raeburn 3429: sub radiobutton_prefs {
1.160.6.16 raeburn 3430: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57 raeburn 3431: $additional,$align) = @_;
1.121 raeburn 3432: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
3433: (ref($choices) eq 'HASH'));
3434:
3435: my (%checkedon,%checkedoff,$datatable,$css_class);
3436:
3437: foreach my $item (@{$toggles}) {
3438: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 3439: $checkedon{$item} = ' checked="checked" ';
3440: $checkedoff{$item} = ' ';
1.121 raeburn 3441: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 3442: $checkedoff{$item} = ' checked="checked" ';
3443: $checkedon{$item} = ' ';
3444: }
3445: }
3446: if (ref($settings) eq 'HASH') {
1.121 raeburn 3447: foreach my $item (@{$toggles}) {
1.118 jms 3448: if ($settings->{$item} eq '1') {
3449: $checkedon{$item} = ' checked="checked" ';
3450: $checkedoff{$item} = ' ';
3451: } elsif ($settings->{$item} eq '0') {
3452: $checkedoff{$item} = ' checked="checked" ';
3453: $checkedon{$item} = ' ';
3454: }
3455: }
1.121 raeburn 3456: }
1.160.6.16 raeburn 3457: if ($onclick) {
3458: $onclick = ' onclick="'.$onclick.'"';
3459: }
1.121 raeburn 3460: foreach my $item (@{$toggles}) {
1.118 jms 3461: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 3462: $datatable .=
1.160.6.16 raeburn 3463: '<tr'.$css_class.'><td valign="top">'.
3464: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 3465: '</span></td>';
3466: if ($align eq 'left') {
3467: $datatable .= '<td class="LC_left_item">';
3468: } else {
3469: $datatable .= '<td class="LC_right_item">';
3470: }
3471: $datatable .=
3472: '<span class="LC_nobreak">'.
1.118 jms 3473: '<label><input type="radio" name="'.
1.160.6.16 raeburn 3474: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 3475: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.16 raeburn 3476: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
3477: '</span>'.$additional.
3478: '</td>'.
1.118 jms 3479: '</tr>';
3480: $itemcount ++;
1.121 raeburn 3481: }
3482: return ($datatable,$itemcount);
3483: }
3484:
3485: sub print_coursedefaults {
1.139 raeburn 3486: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3487: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 3488: my $itemcount = 1;
1.160.6.16 raeburn 3489: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 3490: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 3491: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
3492: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 3493: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
3494: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
3495: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 3496: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 3497: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16 raeburn 3498: );
1.160.6.21 raeburn 3499: my %staticdefaults = (
3500: anonsurvey_threshold => 10,
3501: uploadquota => 500,
1.160.6.57 raeburn 3502: postsubmit => 60,
1.160.6.70 raeburn 3503: mysqltables => 172800,
1.160.6.21 raeburn 3504: );
1.139 raeburn 3505: if ($position eq 'top') {
1.160.6.57 raeburn 3506: %defaultchecked = (
3507: 'uselcmath' => 'on',
3508: 'usejsme' => 'on',
1.160.6.64 raeburn 3509: 'canclone' => 'none',
1.160.6.57 raeburn 3510: );
3511: @toggles = ('uselcmath','usejsme');
1.139 raeburn 3512: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3513: \%choices,$itemcount);
1.160.6.64 raeburn 3514: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3515: $datatable .=
3516: '<tr'.$css_class.'><td valign="top">'.
3517: '<span class="LC_nobreak">'.$choices{'canclone'}.
3518: '</span></td><td class="LC_left_item">';
3519: my $currcanclone = 'none';
3520: my $onclick;
3521: my @cloneoptions = ('none','domain');
3522: my %clonetitles = (
3523: none => 'No additional course requesters',
3524: domain => "Any course requester in course's domain",
3525: instcode => 'Course requests for official courses ...',
3526: );
3527: my (%codedefaults,@code_order,@posscodes);
3528: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
3529: \@code_order) eq 'ok') {
3530: if (@code_order > 0) {
3531: push(@cloneoptions,'instcode');
3532: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
3533: }
3534: }
3535: if (ref($settings) eq 'HASH') {
3536: if ($settings->{'canclone'}) {
3537: if (ref($settings->{'canclone'}) eq 'HASH') {
3538: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
3539: if (@code_order > 0) {
3540: $currcanclone = 'instcode';
3541: @posscodes = @{$settings->{'canclone'}{'instcode'}};
3542: }
3543: }
3544: } elsif ($settings->{'canclone'} eq 'domain') {
3545: $currcanclone = $settings->{'canclone'};
3546: }
3547: }
3548: }
3549: foreach my $option (@cloneoptions) {
3550: my ($checked,$additional);
3551: if ($currcanclone eq $option) {
3552: $checked = ' checked="checked"';
3553: }
3554: if ($option eq 'instcode') {
3555: if (@code_order) {
3556: my $show = 'none';
3557: if ($checked) {
3558: $show = 'block';
3559: }
3560: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
3561: &mt('Institutional codes for new and cloned course have identical:').
3562: '<br />';
3563: foreach my $item (@code_order) {
3564: my $codechk;
3565: if ($checked) {
3566: if (grep(/^\Q$item\E$/,@posscodes)) {
3567: $codechk = ' checked="checked"';
3568: }
3569: }
3570: $additional .= '<label>'.
3571: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
3572: $item.'</label>';
3573: }
3574: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
3575: }
3576: }
3577: $datatable .=
3578: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
3579: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
3580: '</label> '.$additional.'</span><br />';
3581: }
3582: $datatable .= '</td>'.
3583: '</tr>';
3584: $itemcount ++;
1.139 raeburn 3585: } else {
3586: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 3587: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 3588: my $currusecredits = 0;
1.160.6.57 raeburn 3589: my $postsubmitclient = 1;
1.160.6.30 raeburn 3590: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 3591: if (ref($settings) eq 'HASH') {
3592: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 3593: if (ref($settings->{'uploadquota'}) eq 'HASH') {
3594: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
3595: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
3596: }
3597: }
1.160.6.16 raeburn 3598: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 3599: foreach my $type (@types) {
3600: next if ($type eq 'community');
3601: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
3602: if ($defcredits{$type} ne '') {
3603: $currusecredits = 1;
3604: }
3605: }
3606: }
3607: if (ref($settings->{'postsubmit'}) eq 'HASH') {
3608: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
3609: $postsubmitclient = 0;
3610: foreach my $type (@types) {
3611: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3612: }
3613: } else {
3614: foreach my $type (@types) {
3615: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
3616: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
3617: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
3618: } else {
3619: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3620: }
3621: } else {
3622: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3623: }
3624: }
3625: }
3626: } else {
3627: foreach my $type (@types) {
3628: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 3629: }
3630: }
1.160.6.70 raeburn 3631: if (ref($settings->{'mysqltables'}) eq 'HASH') {
3632: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
3633: $currmysql{$type} = $settings->{'mysqltables'}{$type};
3634: }
3635: } else {
3636: foreach my $type (@types) {
3637: $currmysql{$type} = $staticdefaults{'mysqltables'};
3638: }
3639: }
1.160.6.58 raeburn 3640: } else {
3641: foreach my $type (@types) {
3642: $deftimeout{$type} = $staticdefaults{'postsubmit'};
3643: }
1.139 raeburn 3644: }
3645: if (!$currdefresponder) {
1.160.6.21 raeburn 3646: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 3647: } elsif ($currdefresponder < 1) {
3648: $currdefresponder = 1;
3649: }
1.160.6.21 raeburn 3650: foreach my $type (@types) {
3651: if ($curruploadquota{$type} eq '') {
3652: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
3653: }
3654: }
1.139 raeburn 3655: $datatable .=
1.160.6.16 raeburn 3656: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3657: $choices{'anonsurvey_threshold'}.
1.139 raeburn 3658: '</span></td>'.
3659: '<td class="LC_right_item"><span class="LC_nobreak">'.
3660: '<input type="text" name="anonsurvey_threshold"'.
3661: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 3662: '</td></tr>'."\n";
3663: $itemcount ++;
3664: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3665: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3666: $choices{'uploadquota'}.
3667: '</span></td>'.
3668: '<td align="right" class="LC_right_item">'.
3669: '<table><tr>';
1.160.6.21 raeburn 3670: foreach my $type (@types) {
3671: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3672: '<input type="text" name="uploadquota_'.$type.'"'.
3673: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
3674: }
3675: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 3676: $itemcount ++;
1.160.6.40 raeburn 3677: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 3678: my $display = 'none';
3679: if ($currusecredits) {
3680: $display = 'block';
3681: }
3682: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 3683: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
3684: foreach my $type (@types) {
3685: next if ($type eq 'community');
3686: $additional .= '<td align="center">'.&mt($type).'<br />'.
3687: '<input type="text" name="'.$type.'_credits"'.
3688: ' value="'.$defcredits{$type}.'" size="3" /></td>';
3689: }
3690: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 3691: %defaultchecked = ('coursecredits' => 'off');
3692: @toggles = ('coursecredits');
3693: my $current = {
3694: 'coursecredits' => $currusecredits,
3695: };
3696: (my $table,$itemcount) =
3697: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 3698: \%choices,$itemcount,$onclick,$additional,'left');
3699: $datatable .= $table;
3700: $onclick = "toggleDisplay(this.form,'studentsubmission');";
3701: my $display = 'none';
3702: if ($postsubmitclient) {
3703: $display = 'block';
3704: }
3705: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 3706: &mt('Number of seconds submit is disabled').'<br />'.
3707: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
3708: '<table><tr>';
1.160.6.57 raeburn 3709: foreach my $type (@types) {
3710: $additional .= '<td align="center">'.&mt($type).'<br />'.
3711: '<input type="text" name="'.$type.'_timeout" value="'.
3712: $deftimeout{$type}.'" size="5" /></td>';
3713: }
3714: $additional .= '</tr></table></div>'."\n";
3715: %defaultchecked = ('postsubmit' => 'on');
3716: @toggles = ('postsubmit');
1.160.6.70 raeburn 3717: $current = {
3718: 'postsubmit' => $postsubmitclient,
3719: };
1.160.6.57 raeburn 3720: ($table,$itemcount) =
3721: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
3722: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 3723: $datatable .= $table;
1.160.6.70 raeburn 3724: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3725: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3726: $choices{'mysqltables'}.
3727: '</span></td>'.
3728: '<td align="right" class="LC_right_item">'.
3729: '<table><tr>';
3730: foreach my $type (@types) {
3731: $datatable .= '<td align="center">'.&mt($type).'<br />'.
3732: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 3733: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 3734: }
3735: $datatable .= '</tr></table></td></tr>'."\n";
3736: $itemcount ++;
3737:
1.160.6.37 raeburn 3738: }
3739: $$rowtotal += $itemcount;
3740: return $datatable;
3741: }
3742:
3743: sub print_selfenrollment {
3744: my ($position,$dom,$settings,$rowtotal) = @_;
3745: my ($css_class,$datatable);
3746: my $itemcount = 1;
3747: my @types = ('official','unofficial','community','textbook');
3748: if (($position eq 'top') || ($position eq 'middle')) {
3749: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
3750: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
3751: my @rows;
3752: my $key;
3753: if ($position eq 'top') {
3754: $key = 'admin';
3755: if (ref($rowsref) eq 'ARRAY') {
3756: @rows = @{$rowsref};
3757: }
3758: } elsif ($position eq 'middle') {
3759: $key = 'default';
3760: @rows = ('types','registered','approval','limit');
3761: }
3762: foreach my $row (@rows) {
3763: if (defined($titlesref->{$row})) {
3764: $itemcount ++;
3765: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3766: $datatable .= '<tr'.$css_class.'>'.
3767: '<td>'.$titlesref->{$row}.'</td>'.
3768: '<td class="LC_left_item">'.
3769: '<table><tr>';
3770: my (%current,%currentcap);
3771: if (ref($settings) eq 'HASH') {
3772: if (ref($settings->{$key}) eq 'HASH') {
3773: foreach my $type (@types) {
3774: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3775: $current{$type} = $settings->{$key}->{$type}->{$row};
3776: }
3777: if (($row eq 'limit') && ($key eq 'default')) {
3778: if (ref($settings->{$key}->{$type}) eq 'HASH') {
3779: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
3780: }
3781: }
3782: }
3783: }
3784: }
3785: my %roles = (
3786: '0' => &Apache::lonnet::plaintext('dc'),
3787: );
3788:
3789: foreach my $type (@types) {
3790: unless (($row eq 'registered') && ($key eq 'default')) {
3791: $datatable .= '<th>'.&mt($type).'</th>';
3792: }
3793: }
3794: unless (($row eq 'registered') && ($key eq 'default')) {
3795: $datatable .= '</tr><tr>';
3796: }
3797: foreach my $type (@types) {
3798: if ($type eq 'community') {
3799: $roles{'1'} = &mt('Community personnel');
3800: } else {
3801: $roles{'1'} = &mt('Course personnel');
3802: }
3803: $datatable .= '<td style="vertical-align: top">';
3804: if ($position eq 'top') {
3805: my %checked;
3806: if ($current{$type} eq '0') {
3807: $checked{'0'} = ' checked="checked"';
3808: } else {
3809: $checked{'1'} = ' checked="checked"';
3810: }
3811: foreach my $role ('1','0') {
3812: $datatable .= '<span class="LC_nobreak"><label>'.
3813: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
3814: 'value="'.$role.'"'.$checked{$role}.' />'.
3815: $roles{$role}.'</label></span> ';
3816: }
3817: } else {
3818: if ($row eq 'types') {
3819: my %checked;
3820: if ($current{$type} =~ /^(all|dom)$/) {
3821: $checked{$1} = ' checked="checked"';
3822: } else {
3823: $checked{''} = ' checked="checked"';
3824: }
3825: foreach my $val ('','dom','all') {
3826: $datatable .= '<span class="LC_nobreak"><label>'.
3827: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3828: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3829: }
3830: } elsif ($row eq 'registered') {
3831: my %checked;
3832: if ($current{$type} eq '1') {
3833: $checked{'1'} = ' checked="checked"';
3834: } else {
3835: $checked{'0'} = ' checked="checked"';
3836: }
3837: foreach my $val ('0','1') {
3838: $datatable .= '<span class="LC_nobreak"><label>'.
3839: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3840: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3841: }
3842: } elsif ($row eq 'approval') {
3843: my %checked;
3844: if ($current{$type} =~ /^([12])$/) {
3845: $checked{$1} = ' checked="checked"';
3846: } else {
3847: $checked{'0'} = ' checked="checked"';
3848: }
3849: for my $val (0..2) {
3850: $datatable .= '<span class="LC_nobreak"><label>'.
3851: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3852: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3853: }
3854: } elsif ($row eq 'limit') {
3855: my %checked;
3856: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
3857: $checked{$1} = ' checked="checked"';
3858: } else {
3859: $checked{'none'} = ' checked="checked"';
3860: }
3861: my $cap;
3862: if ($currentcap{$type} =~ /^\d+$/) {
3863: $cap = $currentcap{$type};
3864: }
3865: foreach my $val ('none','allstudents','selfenrolled') {
3866: $datatable .= '<span class="LC_nobreak"><label>'.
3867: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
3868: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
3869: }
3870: $datatable .= '<br />'.
3871: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
3872: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
3873: '</span>';
3874: }
3875: }
3876: $datatable .= '</td>';
3877: }
3878: $datatable .= '</tr>';
3879: }
3880: $datatable .= '</table></td></tr>';
3881: }
3882: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 3883: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
3884: }
3885: $$rowtotal += $itemcount;
3886: return $datatable;
3887: }
3888:
3889: sub print_validation_rows {
3890: my ($caller,$dom,$settings,$rowtotal) = @_;
3891: my ($itemsref,$namesref,$fieldsref);
3892: if ($caller eq 'selfenroll') {
3893: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
3894: } elsif ($caller eq 'requestcourses') {
3895: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
3896: }
3897: my %currvalidation;
3898: if (ref($settings) eq 'HASH') {
3899: if (ref($settings->{'validation'}) eq 'HASH') {
3900: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 3901: }
1.160.6.39 raeburn 3902: }
3903: my $datatable;
3904: my $itemcount = 0;
3905: foreach my $item (@{$itemsref}) {
3906: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
3907: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
3908: $namesref->{$item}.
3909: '</span></td>'.
3910: '<td class="LC_left_item">';
3911: if (($item eq 'url') || ($item eq 'button')) {
3912: $datatable .= '<span class="LC_nobreak">'.
3913: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
3914: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
3915: } elsif ($item eq 'fields') {
3916: my @currfields;
3917: if (ref($currvalidation{$item}) eq 'ARRAY') {
3918: @currfields = @{$currvalidation{$item}};
3919: }
3920: foreach my $field (@{$fieldsref}) {
3921: my $check = '';
3922: if (grep(/^\Q$field\E$/,@currfields)) {
3923: $check = ' checked="checked"';
3924: }
3925: $datatable .= '<span class="LC_nobreak"><label>'.
3926: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
3927: ' value="'.$field.'"'.$check.' />'.$field.
3928: '</label></span> ';
3929: }
3930: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 3931: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 3932: $currvalidation{$item}.
1.160.6.37 raeburn 3933: '</textarea>';
1.160.6.39 raeburn 3934: }
3935: $datatable .= '</td></tr>'."\n";
3936: if (ref($rowtotal)) {
1.160.6.37 raeburn 3937: $itemcount ++;
3938: }
1.139 raeburn 3939: }
1.160.6.39 raeburn 3940: if ($caller eq 'requestcourses') {
3941: my %currhash;
1.160.6.51 raeburn 3942: if (ref($settings) eq 'HASH') {
3943: if (ref($settings->{'validation'}) eq 'HASH') {
3944: if ($settings->{'validation'}{'dc'} ne '') {
3945: $currhash{$settings->{'validation'}{'dc'}} = 1;
3946: }
1.160.6.39 raeburn 3947: }
3948: }
3949: my $numinrow = 2;
3950: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3951: 'validationdc',%currhash);
1.160.6.50 raeburn 3952: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 3953: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 3954: if ($numdc > 1) {
1.160.6.50 raeburn 3955: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 3956: } else {
1.160.6.50 raeburn 3957: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 3958: }
1.160.6.50 raeburn 3959: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 3960: $itemcount ++;
3961: }
3962: if (ref($rowtotal)) {
3963: $$rowtotal += $itemcount;
3964: }
1.121 raeburn 3965: return $datatable;
1.118 jms 3966: }
3967:
1.137 raeburn 3968: sub print_usersessions {
3969: my ($position,$dom,$settings,$rowtotal) = @_;
3970: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 3971: my (%by_ip,%by_location,@intdoms);
3972: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 3973:
3974: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 3975: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 3976: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 3977: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 3978: my $itemcount = 1;
3979: if ($position eq 'top') {
1.152 raeburn 3980: if (keys(%serverhomes) > 1) {
1.145 raeburn 3981: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.61 raeburn 3982: my $curroffloadnow;
3983: if (ref($settings) eq 'HASH') {
3984: if (ref($settings->{'offloadnow'}) eq 'HASH') {
3985: $curroffloadnow = $settings->{'offloadnow'};
3986: }
3987: }
3988: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145 raeburn 3989: } else {
1.140 raeburn 3990: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3991: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 3992: }
1.137 raeburn 3993: } else {
1.145 raeburn 3994: if (keys(%by_location) == 0) {
3995: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 3996: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 3997: } else {
3998: my %lt = &usersession_titles();
3999: my $numinrow = 5;
4000: my $prefix;
4001: my @types;
4002: if ($position eq 'bottom') {
4003: $prefix = 'remote';
4004: @types = ('version','excludedomain','includedomain');
4005: } else {
4006: $prefix = 'hosted';
4007: @types = ('excludedomain','includedomain');
4008: }
4009: my (%current,%checkedon,%checkedoff);
4010: my @lcversions = &Apache::lonnet::all_loncaparevs();
4011: my @locations = sort(keys(%by_location));
4012: foreach my $type (@types) {
4013: $checkedon{$type} = '';
4014: $checkedoff{$type} = ' checked="checked"';
4015: }
4016: if (ref($settings) eq 'HASH') {
4017: if (ref($settings->{$prefix}) eq 'HASH') {
4018: foreach my $key (keys(%{$settings->{$prefix}})) {
4019: $current{$key} = $settings->{$prefix}{$key};
4020: if ($key eq 'version') {
4021: if ($current{$key} ne '') {
4022: $checkedon{$key} = ' checked="checked"';
4023: $checkedoff{$key} = '';
4024: }
4025: } elsif (ref($current{$key}) eq 'ARRAY') {
4026: $checkedon{$key} = ' checked="checked"';
4027: $checkedoff{$key} = '';
4028: }
1.137 raeburn 4029: }
4030: }
4031: }
1.145 raeburn 4032: foreach my $type (@types) {
4033: next if ($type ne 'version' && !@locations);
4034: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4035: $datatable .= '<tr'.$css_class.'>
4036: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
4037: <span class="LC_nobreak">
4038: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
4039: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
4040: if ($type eq 'version') {
4041: my $selector = '<select name="'.$prefix.'_version">';
4042: foreach my $version (@lcversions) {
4043: my $selected = '';
4044: if ($current{'version'} eq $version) {
4045: $selected = ' selected="selected"';
4046: }
4047: $selector .= ' <option value="'.$version.'"'.
4048: $selected.'>'.$version.'</option>';
4049: }
4050: $selector .= '</select> ';
4051: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
4052: } else {
4053: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
4054: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
4055: ' />'.(' 'x2).
4056: '<input type="button" value="'.&mt('uncheck all').'" '.
4057: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
4058: "\n".
4059: '</div><div><table>';
4060: my $rem;
4061: for (my $i=0; $i<@locations; $i++) {
4062: my ($showloc,$value,$checkedtype);
4063: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
4064: my $ip = $by_location{$locations[$i]}->[0];
4065: if (ref($by_ip{$ip}) eq 'ARRAY') {
4066: $value = join(':',@{$by_ip{$ip}});
4067: $showloc = join(', ',@{$by_ip{$ip}});
4068: if (ref($current{$type}) eq 'ARRAY') {
4069: foreach my $loc (@{$by_ip{$ip}}) {
4070: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
4071: $checkedtype = ' checked="checked"';
4072: last;
4073: }
4074: }
1.138 raeburn 4075: }
4076: }
4077: }
1.145 raeburn 4078: $rem = $i%($numinrow);
4079: if ($rem == 0) {
4080: if ($i > 0) {
4081: $datatable .= '</tr>';
4082: }
4083: $datatable .= '<tr>';
4084: }
4085: $datatable .= '<td class="LC_left_item">'.
4086: '<span class="LC_nobreak"><label>'.
4087: '<input type="checkbox" name="'.$prefix.'_'.$type.
4088: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
4089: '</label></span></td>';
1.137 raeburn 4090: }
1.145 raeburn 4091: $rem = @locations%($numinrow);
4092: my $colsleft = $numinrow - $rem;
4093: if ($colsleft > 1 ) {
4094: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4095: ' </td>';
4096: } elsif ($colsleft == 1) {
4097: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 4098: }
1.145 raeburn 4099: $datatable .= '</tr></table>';
1.137 raeburn 4100: }
1.145 raeburn 4101: $datatable .= '</td></tr>';
4102: $itemcount ++;
1.137 raeburn 4103: }
4104: }
4105: }
4106: $$rowtotal += $itemcount;
4107: return $datatable;
4108: }
4109:
1.138 raeburn 4110: sub build_location_hashes {
4111: my ($intdoms,$by_ip,$by_location) = @_;
4112: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
4113: (ref($by_location) eq 'HASH'));
4114: my %iphost = &Apache::lonnet::get_iphost();
4115: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
4116: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
4117: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
4118: foreach my $id (@{$iphost{$primary_ip}}) {
4119: my $intdom = &Apache::lonnet::internet_dom($id);
4120: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
4121: push(@{$intdoms},$intdom);
4122: }
4123: }
4124: }
4125: foreach my $ip (keys(%iphost)) {
4126: if (ref($iphost{$ip}) eq 'ARRAY') {
4127: foreach my $id (@{$iphost{$ip}}) {
4128: my $location = &Apache::lonnet::internet_dom($id);
4129: if ($location) {
4130: next if (grep(/^\Q$location\E$/,@{$intdoms}));
4131: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4132: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
4133: push(@{$by_ip->{$ip}},$location);
4134: }
4135: } else {
4136: $by_ip->{$ip} = [$location];
4137: }
4138: }
4139: }
4140: }
4141: }
4142: foreach my $ip (sort(keys(%{$by_ip}))) {
4143: if (ref($by_ip->{$ip}) eq 'ARRAY') {
4144: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
4145: my $first = $by_ip->{$ip}->[0];
4146: if (ref($by_location->{$first}) eq 'ARRAY') {
4147: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
4148: push(@{$by_location->{$first}},$ip);
4149: }
4150: } else {
4151: $by_location->{$first} = [$ip];
4152: }
4153: }
4154: }
4155: return;
4156: }
4157:
1.145 raeburn 4158: sub current_offloads_to {
4159: my ($dom,$settings,$servers) = @_;
4160: my (%spareid,%otherdomconfigs);
1.152 raeburn 4161: if (ref($servers) eq 'HASH') {
1.145 raeburn 4162: foreach my $lonhost (sort(keys(%{$servers}))) {
4163: my $gotspares;
1.152 raeburn 4164: if (ref($settings) eq 'HASH') {
4165: if (ref($settings->{'spares'}) eq 'HASH') {
4166: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
4167: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
4168: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
4169: $gotspares = 1;
4170: }
1.145 raeburn 4171: }
4172: }
4173: unless ($gotspares) {
4174: my $gotspares;
4175: my $serverhomeID =
4176: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
4177: my $serverhomedom =
4178: &Apache::lonnet::host_domain($serverhomeID);
4179: if ($serverhomedom ne $dom) {
4180: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
4181: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4182: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4183: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4184: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4185: $gotspares = 1;
4186: }
4187: }
4188: } else {
4189: $otherdomconfigs{$serverhomedom} =
4190: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
4191: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
4192: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
4193: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
4194: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
4195: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
4196: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
4197: $gotspares = 1;
4198: }
4199: }
4200: }
4201: }
4202: }
4203: }
4204: }
4205: unless ($gotspares) {
4206: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
4207: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4208: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4209: } else {
4210: my $server_hostname = &Apache::lonnet::hostname($lonhost);
4211: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
4212: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
4213: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
4214: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
4215: } else {
1.150 raeburn 4216: my %what = (
4217: spareid => 1,
4218: );
4219: my ($result,$returnhash) =
4220: &Apache::lonnet::get_remote_globals($lonhost,\%what);
4221: if ($result eq 'ok') {
4222: if (ref($returnhash) eq 'HASH') {
4223: if (ref($returnhash->{'spareid'}) eq 'HASH') {
4224: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
4225: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
4226: }
4227: }
1.145 raeburn 4228: }
4229: }
4230: }
4231: }
4232: }
4233: }
4234: return %spareid;
4235: }
4236:
4237: sub spares_row {
1.160.6.61 raeburn 4238: my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145 raeburn 4239: my $css_class;
4240: my $numinrow = 4;
4241: my $itemcount = 1;
4242: my $datatable;
1.152 raeburn 4243: my %typetitles = &sparestype_titles();
4244: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 4245: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 4246: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
4247: my ($othercontrol,$serverdom);
4248: if ($serverhome ne $server) {
4249: $serverdom = &Apache::lonnet::host_domain($serverhome);
4250: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4251: } else {
4252: $serverdom = &Apache::lonnet::host_domain($server);
4253: if ($serverdom ne $dom) {
4254: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
4255: }
4256: }
4257: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61 raeburn 4258: my $checkednow;
4259: if (ref($curroffloadnow) eq 'HASH') {
4260: if ($curroffloadnow->{$server}) {
4261: $checkednow = ' checked="checked"';
4262: }
4263: }
1.145 raeburn 4264: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
4265: $datatable .= '<tr'.$css_class.'>
4266: <td rowspan="2">
1.160.6.13 raeburn 4267: <span class="LC_nobreak">'.
4268: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 4269: ,'<b>'.$server.'</b>').'</span><br />'.
4270: '<span class="LC_nobreak">'."\n".
4271: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
4272: ' '.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13 raeburn 4273: "\n";
1.145 raeburn 4274: my (%current,%canselect);
1.152 raeburn 4275: my @choices =
4276: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
4277: foreach my $type ('primary','default') {
4278: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 4279: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
4280: my @spares = @{$spareid->{$server}{$type}};
4281: if (@spares > 0) {
1.152 raeburn 4282: if ($othercontrol) {
4283: $current{$type} = join(', ',@spares);
4284: } else {
4285: $current{$type} .= '<table>';
4286: my $numspares = scalar(@spares);
4287: for (my $i=0; $i<@spares; $i++) {
4288: my $rem = $i%($numinrow);
4289: if ($rem == 0) {
4290: if ($i > 0) {
4291: $current{$type} .= '</tr>';
4292: }
4293: $current{$type} .= '<tr>';
1.145 raeburn 4294: }
1.152 raeburn 4295: $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'".');" /> '.
4296: $spareid->{$server}{$type}[$i].
4297: '</label></td>'."\n";
4298: }
4299: my $rem = @spares%($numinrow);
4300: my $colsleft = $numinrow - $rem;
4301: if ($colsleft > 1 ) {
4302: $current{$type} .= '<td colspan="'.$colsleft.
4303: '" class="LC_left_item">'.
4304: ' </td>';
4305: } elsif ($colsleft == 1) {
4306: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 4307: }
1.152 raeburn 4308: $current{$type} .= '</tr></table>';
1.150 raeburn 4309: }
1.145 raeburn 4310: }
4311: }
4312: if ($current{$type} eq '') {
4313: $current{$type} = &mt('None specified');
4314: }
1.152 raeburn 4315: if ($othercontrol) {
4316: if ($type eq 'primary') {
4317: $canselect{$type} = $othercontrol;
4318: }
4319: } else {
4320: $canselect{$type} =
4321: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
4322: '<select name="newspare_'.$type.'_'.$server.'" '.
4323: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
4324: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
4325: if (@choices > 0) {
4326: foreach my $lonhost (@choices) {
4327: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
4328: }
4329: }
4330: $canselect{$type} .= '</select>'."\n";
4331: }
4332: } else {
4333: $current{$type} = &mt('Could not be determined');
4334: if ($type eq 'primary') {
4335: $canselect{$type} = $othercontrol;
4336: }
1.145 raeburn 4337: }
1.152 raeburn 4338: if ($type eq 'default') {
4339: $datatable .= '<tr'.$css_class.'>';
4340: }
4341: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
4342: '<td>'.$current{$type}.'</td>'."\n".
4343: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 4344: }
4345: $itemcount ++;
4346: }
4347: }
4348: $$rowtotal += $itemcount;
4349: return $datatable;
4350: }
4351:
1.152 raeburn 4352: sub possible_newspares {
4353: my ($server,$currspares,$serverhomes,$altids) = @_;
4354: my $serverhostname = &Apache::lonnet::hostname($server);
4355: my %excluded;
4356: if ($serverhostname ne '') {
4357: %excluded = (
4358: $serverhostname => 1,
4359: );
4360: }
4361: if (ref($currspares) eq 'HASH') {
4362: foreach my $type (keys(%{$currspares})) {
4363: if (ref($currspares->{$type}) eq 'ARRAY') {
4364: if (@{$currspares->{$type}} > 0) {
4365: foreach my $curr (@{$currspares->{$type}}) {
4366: my $hostname = &Apache::lonnet::hostname($curr);
4367: $excluded{$hostname} = 1;
4368: }
4369: }
4370: }
4371: }
4372: }
4373: my @choices;
4374: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
4375: if (keys(%{$serverhomes}) > 1) {
4376: foreach my $name (sort(keys(%{$serverhomes}))) {
4377: unless ($excluded{$name}) {
4378: if (exists($altids->{$serverhomes->{$name}})) {
4379: push(@choices,$altids->{$serverhomes->{$name}});
4380: } else {
4381: push(@choices,$serverhomes->{$name});
1.145 raeburn 4382: }
4383: }
4384: }
4385: }
4386: }
1.152 raeburn 4387: return sort(@choices);
1.145 raeburn 4388: }
4389:
1.150 raeburn 4390: sub print_loadbalancing {
4391: my ($dom,$settings,$rowtotal) = @_;
4392: my $primary_id = &Apache::lonnet::domain($dom,'primary');
4393: my $intdom = &Apache::lonnet::internet_dom($primary_id);
4394: my $numinrow = 1;
4395: my $datatable;
4396: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7 raeburn 4397: my (%currbalancer,%currtargets,%currrules,%existing);
4398: if (ref($settings) eq 'HASH') {
4399: %existing = %{$settings};
4400: }
4401: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
4402: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
4403: \%currtargets,\%currrules);
1.150 raeburn 4404: } else {
4405: return;
4406: }
4407: my ($othertitle,$usertypes,$types) =
4408: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 4409: my $rownum = 8;
1.150 raeburn 4410: if (ref($types) eq 'ARRAY') {
4411: $rownum += scalar(@{$types});
4412: }
1.160.6.7 raeburn 4413: my @css_class = ('LC_odd_row','LC_even_row');
4414: my $balnum = 0;
4415: my $islast;
4416: my (@toshow,$disabledtext);
4417: if (keys(%currbalancer) > 0) {
4418: @toshow = sort(keys(%currbalancer));
4419: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
4420: push(@toshow,'');
4421: }
4422: } else {
4423: @toshow = ('');
4424: $disabledtext = &mt('No existing load balancer');
4425: }
4426: foreach my $lonhost (@toshow) {
4427: if ($balnum == scalar(@toshow)-1) {
4428: $islast = 1;
4429: } else {
4430: $islast = 0;
4431: }
4432: my $cssidx = $balnum%2;
4433: my $targets_div_style = 'display: none';
4434: my $disabled_div_style = 'display: block';
4435: my $homedom_div_style = 'display: none';
4436: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
4437: '<td rowspan="'.$rownum.'" valign="top">'.
4438: '<p>';
4439: if ($lonhost eq '') {
4440: $datatable .= '<span class="LC_nobreak">';
4441: if (keys(%currbalancer) > 0) {
4442: $datatable .= &mt('Add balancer:');
4443: } else {
4444: $datatable .= &mt('Enable balancer:');
4445: }
4446: $datatable .= ' '.
4447: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
4448: ' id="loadbalancing_lonhost_'.$balnum.'"'.
4449: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
4450: '<option value="" selected="selected">'.&mt('None').
4451: '</option>'."\n";
4452: foreach my $server (sort(keys(%servers))) {
4453: next if ($currbalancer{$server});
4454: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
4455: }
4456: $datatable .=
4457: '</select>'."\n".
4458: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
4459: } else {
4460: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
4461: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
4462: &mt('Stop balancing').'</label>'.
4463: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
4464: $targets_div_style = 'display: block';
4465: $disabled_div_style = 'display: none';
4466: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
4467: $homedom_div_style = 'display: block';
4468: }
4469: }
4470: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
4471: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
4472: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
4473: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
4474: my ($numspares,@spares) = &count_servers($lonhost,%servers);
4475: my @sparestypes = ('primary','default');
4476: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 4477: my %hostherechecked = (
4478: no => ' checked="checked"',
4479: );
1.160.6.7 raeburn 4480: foreach my $sparetype (@sparestypes) {
4481: my $targettable;
4482: for (my $i=0; $i<$numspares; $i++) {
4483: my $checked;
4484: if (ref($currtargets{$lonhost}) eq 'HASH') {
4485: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4486: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4487: $checked = ' checked="checked"';
4488: }
4489: }
4490: }
4491: my ($chkboxval,$disabled);
4492: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
4493: $chkboxval = $spares[$i];
4494: }
4495: if (exists($currbalancer{$spares[$i]})) {
4496: $disabled = ' disabled="disabled"';
4497: }
4498: $targettable .=
1.160.6.55 raeburn 4499: '<td><span class="LC_nobreak"><label>'.
4500: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 4501: $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 4502: '</span></label></span></td>';
1.160.6.7 raeburn 4503: my $rem = $i%($numinrow);
4504: if ($rem == 0) {
4505: if (($i > 0) && ($i < $numspares-1)) {
4506: $targettable .= '</tr>';
4507: }
4508: if ($i < $numspares-1) {
4509: $targettable .= '<tr>';
1.150 raeburn 4510: }
4511: }
4512: }
1.160.6.7 raeburn 4513: if ($targettable ne '') {
4514: my $rem = $numspares%($numinrow);
4515: my $colsleft = $numinrow - $rem;
4516: if ($colsleft > 1 ) {
4517: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4518: ' </td>';
4519: } elsif ($colsleft == 1) {
4520: $targettable .= '<td class="LC_left_item"> </td>';
4521: }
4522: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
4523: '<table><tr>'.$targettable.'</tr></table><br />';
4524: }
1.160.6.76 raeburn 4525: $hostherechecked{$sparetype} = '';
4526: if (ref($currtargets{$lonhost}) eq 'HASH') {
4527: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
4528: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
4529: $hostherechecked{$sparetype} = ' checked="checked"';
4530: $hostherechecked{'no'} = '';
4531: }
4532: }
4533: }
4534: }
4535: $datatable .= &mt('Hosting on balancer itself').'<br />'.
4536: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
4537: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
4538: foreach my $sparetype (@sparestypes) {
4539: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
4540: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
4541: '</i></label><br />';
1.160.6.7 raeburn 4542: }
4543: $datatable .= '</div></td></tr>'.
4544: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
4545: $othertitle,$usertypes,$types,\%servers,
4546: \%currbalancer,$lonhost,
4547: $targets_div_style,$homedom_div_style,
4548: $css_class[$cssidx],$balnum,$islast);
4549: $$rowtotal += $rownum;
4550: $balnum ++;
4551: }
4552: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
4553: return $datatable;
4554: }
4555:
4556: sub get_loadbalancers_config {
4557: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
4558: return unless ((ref($servers) eq 'HASH') &&
4559: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
4560: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
4561: if (keys(%{$existing}) > 0) {
4562: my $oldlonhost;
4563: foreach my $key (sort(keys(%{$existing}))) {
4564: if ($key eq 'lonhost') {
4565: $oldlonhost = $existing->{'lonhost'};
4566: $currbalancer->{$oldlonhost} = 1;
4567: } elsif ($key eq 'targets') {
4568: if ($oldlonhost) {
4569: $currtargets->{$oldlonhost} = $existing->{'targets'};
4570: }
4571: } elsif ($key eq 'rules') {
4572: if ($oldlonhost) {
4573: $currrules->{$oldlonhost} = $existing->{'rules'};
4574: }
4575: } elsif (ref($existing->{$key}) eq 'HASH') {
4576: $currbalancer->{$key} = 1;
4577: $currtargets->{$key} = $existing->{$key}{'targets'};
4578: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 4579: }
4580: }
1.160.6.7 raeburn 4581: } else {
4582: my ($balancerref,$targetsref) =
4583: &Apache::lonnet::get_lonbalancer_config($servers);
4584: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
4585: foreach my $server (sort(keys(%{$balancerref}))) {
4586: $currbalancer->{$server} = 1;
4587: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 4588: }
4589: }
4590: }
1.160.6.7 raeburn 4591: return;
1.150 raeburn 4592: }
4593:
4594: sub loadbalancing_rules {
4595: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 4596: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
4597: $css_class,$balnum,$islast) = @_;
1.150 raeburn 4598: my $output;
1.160.6.7 raeburn 4599: my $num = 0;
4600: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 4601: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
4602: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
4603: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 4604: $num ++;
1.150 raeburn 4605: my $current;
4606: if (ref($currrules) eq 'HASH') {
4607: $current = $currrules->{$type};
4608: }
1.160.6.55 raeburn 4609: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 4610: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 4611: $current = '';
4612: }
4613: }
4614: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 4615: $servers,$currbalancer,$lonhost,$dom,
4616: $targets_div_style,$homedom_div_style,
4617: $css_class,$balnum,$num,$islast);
1.150 raeburn 4618: }
4619: }
4620: return $output;
4621: }
4622:
4623: sub loadbalancing_titles {
4624: my ($dom,$intdom,$usertypes,$types) = @_;
4625: my %othertypes = (
4626: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
4627: '_LC_author' => &mt('Users from [_1] with author role',$dom),
4628: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
4629: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 4630: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
4631: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 4632: );
1.160.6.26 raeburn 4633: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 4634: if (ref($types) eq 'ARRAY') {
4635: unshift(@alltypes,@{$types},'default');
4636: }
4637: my %titles;
4638: foreach my $type (@alltypes) {
4639: if ($type =~ /^_LC_/) {
4640: $titles{$type} = $othertypes{$type};
4641: } elsif ($type eq 'default') {
4642: $titles{$type} = &mt('All users from [_1]',$dom);
4643: if (ref($types) eq 'ARRAY') {
4644: if (@{$types} > 0) {
4645: $titles{$type} = &mt('Other users from [_1]',$dom);
4646: }
4647: }
4648: } elsif (ref($usertypes) eq 'HASH') {
4649: $titles{$type} = $usertypes->{$type};
4650: }
4651: }
4652: return (\@alltypes,\%othertypes,\%titles);
4653: }
4654:
4655: sub loadbalance_rule_row {
1.160.6.7 raeburn 4656: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
4657: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 4658: my @rulenames;
1.150 raeburn 4659: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 4660: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 4661: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 4662: } else {
1.160.6.26 raeburn 4663: @rulenames = ('default','homeserver');
4664: if ($type eq '_LC_external') {
4665: push(@rulenames,'externalbalancer');
4666: } else {
4667: push(@rulenames,'specific');
4668: }
4669: push(@rulenames,'none');
1.150 raeburn 4670: }
4671: my $style = $targets_div_style;
1.160.6.55 raeburn 4672: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 4673: $style = $homedom_div_style;
4674: }
1.160.6.7 raeburn 4675: my $space;
4676: if ($islast && $num == 1) {
4677: $space = '<div display="inline-block"> </div>';
4678: }
4679: my $output =
4680: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
4681: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
4682: '<td valaign="top">'.$space.
4683: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 4684: for (my $i=0; $i<@rulenames; $i++) {
4685: my $rule = $rulenames[$i];
4686: my ($checked,$extra);
4687: if ($rulenames[$i] eq 'default') {
4688: $rule = '';
4689: }
4690: if ($rulenames[$i] eq 'specific') {
4691: if (ref($servers) eq 'HASH') {
4692: my $default;
4693: if (($current ne '') && (exists($servers->{$current}))) {
4694: $checked = ' checked="checked"';
4695: }
4696: unless ($checked) {
4697: $default = ' selected="selected"';
4698: }
1.160.6.7 raeburn 4699: $extra =
4700: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
4701: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
4702: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
4703: '<option value=""'.$default.'></option>'."\n";
4704: foreach my $server (sort(keys(%{$servers}))) {
4705: if (ref($currbalancer) eq 'HASH') {
4706: next if (exists($currbalancer->{$server}));
4707: }
1.150 raeburn 4708: my $selected;
1.160.6.7 raeburn 4709: if ($server eq $current) {
1.150 raeburn 4710: $selected = ' selected="selected"';
4711: }
1.160.6.7 raeburn 4712: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 4713: }
4714: $extra .= '</select>';
4715: }
4716: } elsif ($rule eq $current) {
4717: $checked = ' checked="checked"';
4718: }
4719: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 4720: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
4721: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
4722: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 4723: ')"'.$checked.' /> ';
1.160.6.56 raeburn 4724: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 4725: $output .= $ruletitles{'particular'};
4726: } else {
4727: $output .= $ruletitles{$rulenames[$i]};
4728: }
4729: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 4730: }
4731: $output .= '</div></td></tr>'."\n";
4732: return $output;
4733: }
4734:
4735: sub offloadtype_text {
4736: my %ruletitles = &Apache::lonlocal::texthash (
4737: 'default' => 'Offloads to default destinations',
4738: 'homeserver' => "Offloads to user's home server",
4739: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
4740: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 4741: 'none' => 'No offload',
1.160.6.26 raeburn 4742: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
4743: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 4744: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 4745: );
4746: return %ruletitles;
4747: }
4748:
4749: sub sparestype_titles {
4750: my %typestitles = &Apache::lonlocal::texthash (
4751: 'primary' => 'primary',
4752: 'default' => 'default',
4753: );
4754: return %typestitles;
4755: }
4756:
1.28 raeburn 4757: sub contact_titles {
4758: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 4759: 'supportemail' => 'Support E-mail address',
4760: 'adminemail' => 'Default Server Admin E-mail address',
4761: 'errormail' => 'Error reports to be e-mailed to',
4762: 'packagesmail' => 'Package update alerts to be e-mailed to',
4763: 'helpdeskmail' => "Helpdesk requests for this domain's users",
4764: 'otherdomsmail' => 'Helpdesk requests for other (unconfigured) domains',
4765: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
4766: 'requestsmail' => 'E-mail from course requests requiring approval',
4767: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 4768: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 4769: );
4770: my %short_titles = &Apache::lonlocal::texthash (
4771: adminemail => 'Admin E-mail address',
4772: supportemail => 'Support E-mail',
4773: );
4774: return (\%titles,\%short_titles);
4775: }
4776:
1.160.6.78 raeburn 4777: sub helpform_fields {
4778: my %titles = &Apache::lonlocal::texthash (
4779: 'username' => 'Name',
4780: 'user' => 'Username/domain',
4781: 'phone' => 'Phone',
4782: 'cc' => 'Cc e-mail',
4783: 'course' => 'Course Details',
4784: 'section' => 'Sections',
4785: 'screenshot' => 'File upload',
4786: );
4787: my @fields = ('username','phone','user','course','section','cc','screenshot');
4788: my %possoptions = (
4789: username => ['yes','no','req'],
4790: phone => ['yes','no','req'],
4791: user => ['yes','no'],
4792: cc => ['yes','no'],
4793: course => ['yes','no'],
4794: section => ['yes','no'],
4795: screenshot => ['yes','no'],
4796: );
4797: my %fieldoptions = &Apache::lonlocal::texthash (
4798: 'yes' => 'Optional',
4799: 'req' => 'Required',
4800: 'no' => "Not shown",
4801: );
4802: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
4803: }
4804:
1.72 raeburn 4805: sub tool_titles {
4806: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 4807: aboutme => 'Personal web page',
1.86 raeburn 4808: blog => 'Blog',
1.160.6.4 raeburn 4809: webdav => 'WebDAV',
1.86 raeburn 4810: portfolio => 'Portfolio',
1.88 bisitz 4811: official => 'Official courses (with institutional codes)',
4812: unofficial => 'Unofficial courses',
1.98 raeburn 4813: community => 'Communities',
1.160.6.30 raeburn 4814: textbook => 'Textbook courses',
1.86 raeburn 4815: );
1.72 raeburn 4816: return %titles;
4817: }
4818:
1.101 raeburn 4819: sub courserequest_titles {
4820: my %titles = &Apache::lonlocal::texthash (
4821: official => 'Official',
4822: unofficial => 'Unofficial',
4823: community => 'Communities',
1.160.6.30 raeburn 4824: textbook => 'Textbook',
1.101 raeburn 4825: norequest => 'Not allowed',
1.104 raeburn 4826: approval => 'Approval by Dom. Coord.',
1.101 raeburn 4827: validate => 'With validation',
4828: autolimit => 'Numerical limit',
1.103 raeburn 4829: unlimited => '(blank for unlimited)',
1.101 raeburn 4830: );
4831: return %titles;
4832: }
4833:
1.160.6.5 raeburn 4834: sub authorrequest_titles {
4835: my %titles = &Apache::lonlocal::texthash (
4836: norequest => 'Not allowed',
4837: approval => 'Approval by Dom. Coord.',
4838: automatic => 'Automatic approval',
4839: );
4840: return %titles;
4841: }
4842:
1.101 raeburn 4843: sub courserequest_conditions {
4844: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 4845: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 4846: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 4847: );
4848: return %conditions;
4849: }
4850:
4851:
1.27 raeburn 4852: sub print_usercreation {
1.30 raeburn 4853: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 4854: my $numinrow = 4;
1.28 raeburn 4855: my $datatable;
4856: if ($position eq 'top') {
1.30 raeburn 4857: $$rowtotal ++;
1.34 raeburn 4858: my $rowcount = 0;
1.32 raeburn 4859: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 4860: if (ref($rules) eq 'HASH') {
4861: if (keys(%{$rules}) > 0) {
1.32 raeburn 4862: $datatable .= &user_formats_row('username',$settings,$rules,
4863: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 4864: $$rowtotal ++;
1.32 raeburn 4865: $rowcount ++;
4866: }
4867: }
4868: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
4869: if (ref($idrules) eq 'HASH') {
4870: if (keys(%{$idrules}) > 0) {
4871: $datatable .= &user_formats_row('id',$settings,$idrules,
4872: $idruleorder,$numinrow,$rowcount);
4873: $$rowtotal ++;
4874: $rowcount ++;
1.28 raeburn 4875: }
4876: }
1.39 raeburn 4877: if ($rowcount == 0) {
4878: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
4879: $$rowtotal ++;
4880: $rowcount ++;
4881: }
1.34 raeburn 4882: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 4883: my @creators = ('author','course','requestcrs');
1.37 raeburn 4884: my ($rules,$ruleorder) =
4885: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 4886: my %lt = &usercreation_types();
4887: my %checked;
4888: if (ref($settings) eq 'HASH') {
4889: if (ref($settings->{'cancreate'}) eq 'HASH') {
4890: foreach my $item (@creators) {
4891: $checked{$item} = $settings->{'cancreate'}{$item};
4892: }
4893: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
4894: foreach my $item (@creators) {
4895: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
4896: $checked{$item} = 'none';
4897: }
4898: }
4899: }
4900: }
4901: my $rownum = 0;
4902: foreach my $item (@creators) {
4903: $rownum ++;
1.160.6.34 raeburn 4904: if ($checked{$item} eq '') {
4905: $checked{$item} = 'any';
1.34 raeburn 4906: }
4907: my $css_class;
4908: if ($rownum%2) {
4909: $css_class = '';
4910: } else {
4911: $css_class = ' class="LC_odd_row" ';
4912: }
4913: $datatable .= '<tr'.$css_class.'>'.
4914: '<td><span class="LC_nobreak">'.$lt{$item}.
4915: '</span></td><td align="right">';
1.160.6.34 raeburn 4916: my @options = ('any');
4917: if (ref($rules) eq 'HASH') {
4918: if (keys(%{$rules}) > 0) {
4919: push(@options,('official','unofficial'));
1.37 raeburn 4920: }
4921: }
1.160.6.34 raeburn 4922: push(@options,'none');
1.37 raeburn 4923: foreach my $option (@options) {
1.50 raeburn 4924: my $type = 'radio';
1.34 raeburn 4925: my $check = ' ';
1.160.6.34 raeburn 4926: if ($checked{$item} eq $option) {
4927: $check = ' checked="checked" ';
1.34 raeburn 4928: }
4929: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 4930: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 4931: $item.'" value="'.$option.'"'.$check.'/> '.
4932: $lt{$option}.'</label> </span>';
4933: }
4934: $datatable .= '</td></tr>';
4935: }
1.28 raeburn 4936: } else {
4937: my @contexts = ('author','course','domain');
4938: my @authtypes = ('int','krb4','krb5','loc');
4939: my %checked;
4940: if (ref($settings) eq 'HASH') {
4941: if (ref($settings->{'authtypes'}) eq 'HASH') {
4942: foreach my $item (@contexts) {
4943: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
4944: foreach my $auth (@authtypes) {
4945: if ($settings->{'authtypes'}{$item}{$auth}) {
4946: $checked{$item}{$auth} = ' checked="checked" ';
4947: }
4948: }
4949: }
4950: }
1.27 raeburn 4951: }
1.35 raeburn 4952: } else {
4953: foreach my $item (@contexts) {
1.36 raeburn 4954: foreach my $auth (@authtypes) {
1.35 raeburn 4955: $checked{$item}{$auth} = ' checked="checked" ';
4956: }
4957: }
1.27 raeburn 4958: }
1.28 raeburn 4959: my %title = &context_names();
4960: my %authname = &authtype_names();
4961: my $rownum = 0;
4962: my $css_class;
4963: foreach my $item (@contexts) {
4964: if ($rownum%2) {
4965: $css_class = '';
4966: } else {
4967: $css_class = ' class="LC_odd_row" ';
4968: }
1.30 raeburn 4969: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 4970: '<td>'.$title{$item}.
4971: '</td><td class="LC_left_item">'.
4972: '<span class="LC_nobreak">';
4973: foreach my $auth (@authtypes) {
4974: $datatable .= '<label>'.
4975: '<input type="checkbox" name="'.$item.'_auth" '.
4976: $checked{$item}{$auth}.' value="'.$auth.'" />'.
4977: $authname{$auth}.'</label> ';
4978: }
4979: $datatable .= '</span></td></tr>';
4980: $rownum ++;
1.27 raeburn 4981: }
1.30 raeburn 4982: $$rowtotal += $rownum;
1.27 raeburn 4983: }
4984: return $datatable;
4985: }
4986:
1.160.6.34 raeburn 4987: sub print_selfcreation {
4988: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40 raeburn 4989: my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34 raeburn 4990: if (ref($settings) eq 'HASH') {
4991: if (ref($settings->{'cancreate'}) eq 'HASH') {
4992: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 4993: if (ref($createsettings) eq 'HASH') {
4994: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
4995: @selfcreate = @{$createsettings->{'selfcreate'}};
4996: } elsif ($createsettings->{'selfcreate'} ne '') {
4997: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
4998: @selfcreate = ('email','login','sso');
4999: } elsif ($createsettings->{'selfcreate'} ne 'none') {
5000: @selfcreate = ($createsettings->{'selfcreate'});
5001: }
5002: }
5003: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
5004: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 5005: }
5006: }
5007: }
5008: }
5009: my %radiohash;
5010: my $numinrow = 4;
5011: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
5012: if ($position eq 'top') {
5013: my %choices = &Apache::lonlocal::texthash (
5014: cancreate_login => 'Institutional Login',
5015: cancreate_sso => 'Institutional Single Sign On',
5016: );
5017: my @toggles = sort(keys(%choices));
5018: my %defaultchecked = (
5019: 'cancreate_login' => 'off',
5020: 'cancreate_sso' => 'off',
5021: );
1.160.6.35 raeburn 5022: my ($onclick,$itemcount);
1.160.6.34 raeburn 5023: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
5024: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 5025: $$rowtotal += $itemcount;
1.160.6.39 raeburn 5026:
1.160.6.34 raeburn 5027: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5028:
5029: if (ref($usertypes) eq 'HASH') {
5030: if (keys(%{$usertypes}) > 0) {
5031: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
5032: $dom,$numinrow,$othertitle,
1.160.6.35 raeburn 5033: 'statustocreate',$$rowtotal);
1.160.6.34 raeburn 5034: $$rowtotal ++;
5035: }
5036: }
1.160.6.44 raeburn 5037: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
5038: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5039: $fieldtitles{'inststatus'} = &mt('Institutional status');
5040: my $rem;
5041: my $numperrow = 2;
5042: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
5043: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 5044: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 5045: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 5046: '<table>'."\n";
1.160.6.44 raeburn 5047: for (my $i=0; $i<@fields; $i++) {
5048: $rem = $i%($numperrow);
5049: if ($rem == 0) {
5050: if ($i > 0) {
5051: $datatable .= '</tr>';
5052: }
5053: $datatable .= '<tr>';
5054: }
5055: my $currval;
1.160.6.51 raeburn 5056: if (ref($createsettings) eq 'HASH') {
5057: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
5058: $currval = $createsettings->{'shibenv'}{$fields[$i]};
5059: }
1.160.6.44 raeburn 5060: }
5061: $datatable .= '<td class="LC_left_item">'.
5062: '<span class="LC_nobreak">'.
5063: '<input type="text" name="shibenv_'.$fields[$i].'" '.
5064: 'value="'.$currval.'" size="10" /> '.
5065: $fieldtitles{$fields[$i]}.'</span></td>';
5066: }
5067: my $colsleft = $numperrow - $rem;
5068: if ($colsleft > 1 ) {
5069: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5070: ' </td>';
5071: } elsif ($colsleft == 1) {
5072: $datatable .= '<td class="LC_left_item"> </td>';
5073: }
5074: $datatable .= '</tr></table></td></tr>';
5075: $$rowtotal ++;
1.160.6.34 raeburn 5076: } elsif ($position eq 'middle') {
5077: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
5078: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5079: $usertypes->{'default'} = $othertitle;
5080: if (ref($types) eq 'ARRAY') {
5081: push(@{$types},'default');
5082: $usertypes->{'default'} = $othertitle;
5083: foreach my $status (@{$types}) {
5084: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35 raeburn 5085: $numinrow,$$rowtotal,$usertypes);
1.160.6.44 raeburn 5086: $$rowtotal ++;
1.160.6.34 raeburn 5087: }
5088: }
5089: } else {
1.160.6.40 raeburn 5090: my %choices = &Apache::lonlocal::texthash (
5091: cancreate_email => 'E-mail address as username',
5092: );
5093: my @toggles = sort(keys(%choices));
5094: my %defaultchecked = (
5095: 'cancreate_email' => 'off',
5096: );
5097: my $itemcount = 0;
5098: my $display = 'none';
5099: if (grep(/^\Qemail\E$/,@selfcreate)) {
5100: $display = 'block';
5101: }
5102: my $onclick = "toggleDisplay(this.form,'emailoptions');";
5103: my $additional = '<div id="emailoptions" style="display: '.$display.'">';
5104: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5105: my $usertypes = {};
5106: my $order = [];
5107: if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
5108: $usertypes = $domdefaults{'inststatustypes'};
5109: $order = $domdefaults{'inststatusguest'};
5110: }
5111: if (ref($order) eq 'ARRAY') {
5112: push(@{$order},'default');
5113: if (@{$order} > 1) {
5114: $usertypes->{'default'} = &mt('Other users');
5115: $additional .= '<table><tr>';
5116: foreach my $status (@{$order}) {
5117: $additional .= '<th>'.$usertypes->{$status}.'</th>';
5118: }
5119: $additional .= '</tr><tr>';
5120: foreach my $status (@{$order}) {
5121: $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34 raeburn 5122: }
1.160.6.40 raeburn 5123: $additional .= '</tr></table>';
1.160.6.34 raeburn 5124: } else {
1.160.6.40 raeburn 5125: $usertypes->{'default'} = &mt('All users');
5126: $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34 raeburn 5127: }
5128: }
1.160.6.40 raeburn 5129: $additional .= '</div>'."\n";
5130:
5131: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44 raeburn 5132: \%choices,$$rowtotal,$onclick,$additional);
5133: $$rowtotal ++;
1.160.6.40 raeburn 5134: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34 raeburn 5135: $$rowtotal ++;
1.160.6.35 raeburn 5136: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5137: $numinrow = 1;
1.160.6.40 raeburn 5138: if (ref($order) eq 'ARRAY') {
5139: foreach my $status (@{$order}) {
1.160.6.35 raeburn 5140: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
5141: $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
5142: $$rowtotal ++;
5143: }
5144: }
1.160.6.34 raeburn 5145: my ($emailrules,$emailruleorder) =
5146: &Apache::lonnet::inst_userrules($dom,'email');
5147: if (ref($emailrules) eq 'HASH') {
5148: if (keys(%{$emailrules}) > 0) {
5149: $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35 raeburn 5150: $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34 raeburn 5151: $$rowtotal ++;
5152: }
5153: }
1.160.6.35 raeburn 5154: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34 raeburn 5155: }
5156: return $datatable;
5157: }
5158:
1.160.6.40 raeburn 5159: sub email_as_username {
5160: my ($rowtotal,$processing,$type) = @_;
5161: my %choices =
5162: &Apache::lonlocal::texthash (
5163: automatic => 'Automatic approval',
5164: approval => 'Queued for approval',
5165: );
5166: my $output;
5167: foreach my $option ('automatic','approval') {
5168: my $checked;
5169: if (ref($processing) eq 'HASH') {
5170: if ($type eq '') {
5171: if (!exists($processing->{'default'})) {
5172: if ($option eq 'automatic') {
5173: $checked = ' checked="checked"';
5174: }
5175: } else {
5176: if ($processing->{'default'} eq $option) {
5177: $checked = ' checked="checked"';
5178: }
5179: }
5180: } else {
5181: if (!exists($processing->{$type})) {
5182: if ($option eq 'automatic') {
5183: $checked = ' checked="checked"';
5184: }
5185: } else {
5186: if ($processing->{$type} eq $option) {
5187: $checked = ' checked="checked"';
5188: }
5189: }
5190: }
5191: } elsif ($option eq 'automatic') {
5192: $checked = ' checked="checked"';
5193: }
5194: my $name = 'cancreate_emailprocess';
5195: if (($type ne '') && ($type ne 'default')) {
5196: $name .= '_'.$type;
5197: }
5198: $output .= '<span class="LC_nobreak"><label>'.
5199: '<input type="radio" name="'.$name.'"'.
5200: $checked.' value="'.$option.'" />'.
5201: $choices{$option}.'</label></span>';
5202: if ($type eq '') {
5203: $output .= ' ';
5204: } else {
5205: $output .= '<br />';
5206: }
5207: }
5208: $$rowtotal ++;
5209: return $output;
5210: }
5211:
1.160.6.5 raeburn 5212: sub captcha_choice {
5213: my ($context,$settings,$itemcount) = @_;
1.160.6.69 raeburn 5214: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
5215: $vertext,$currver);
1.160.6.5 raeburn 5216: my %lt = &captcha_phrases();
5217: $keyentry = 'hidden';
5218: if ($context eq 'cancreate') {
1.160.6.34 raeburn 5219: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 5220: } elsif ($context eq 'login') {
5221: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
5222: }
5223: if (ref($settings) eq 'HASH') {
5224: if ($settings->{'captcha'}) {
5225: $checked{$settings->{'captcha'}} = ' checked="checked"';
5226: } else {
5227: $checked{'original'} = ' checked="checked"';
5228: }
5229: if ($settings->{'captcha'} eq 'recaptcha') {
5230: $pubtext = $lt{'pub'};
5231: $privtext = $lt{'priv'};
5232: $keyentry = 'text';
1.160.6.69 raeburn 5233: $vertext = $lt{'ver'};
5234: $currver = $settings->{'recaptchaversion'};
5235: if ($currver ne '2') {
5236: $currver = 1;
5237: }
1.160.6.5 raeburn 5238: }
5239: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
5240: $currpub = $settings->{'recaptchakeys'}{'public'};
5241: $currpriv = $settings->{'recaptchakeys'}{'private'};
5242: }
5243: } else {
5244: $checked{'original'} = ' checked="checked"';
5245: }
5246: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
5247: my $output = '<tr'.$css_class.'>'.
5248: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
5249: '<table><tr><td>'."\n";
5250: foreach my $option ('original','recaptcha','notused') {
5251: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
5252: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
5253: $lt{$option}.'</label></span>';
5254: unless ($option eq 'notused') {
5255: $output .= (' 'x2)."\n";
5256: }
5257: }
5258: #
5259: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
5260: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
5261: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
5262: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
5263: #
5264: $output .= '</td></tr>'."\n".
5265: '<tr><td>'."\n".
5266: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
5267: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
5268: $currpub.'" size="40" /></span><br />'."\n".
5269: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
5270: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 5271: $currpriv.'" size="40" /></span><br />'.
5272: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
5273: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
5274: $currver.'" size="3" /></span><br />'.
5275: '</td></tr></table>'."\n".
1.160.6.5 raeburn 5276: '</td></tr>';
5277: return $output;
5278: }
5279:
1.32 raeburn 5280: sub user_formats_row {
5281: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
5282: my $output;
5283: my %text = (
5284: 'username' => 'new usernames',
5285: 'id' => 'IDs',
1.45 raeburn 5286: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 5287: );
5288: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
5289: $output = '<tr '.$css_class.'>'.
1.63 raeburn 5290: '<td><span class="LC_nobreak">';
5291: if ($type eq 'email') {
5292: $output .= &mt("Formats disallowed for $text{$type}: ");
5293: } else {
5294: $output .= &mt("Format rules to check for $text{$type}: ");
5295: }
5296: $output .= '</span></td>'.
5297: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 5298: my $rem;
5299: if (ref($ruleorder) eq 'ARRAY') {
5300: for (my $i=0; $i<@{$ruleorder}; $i++) {
5301: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
5302: my $rem = $i%($numinrow);
5303: if ($rem == 0) {
5304: if ($i > 0) {
5305: $output .= '</tr>';
5306: }
5307: $output .= '<tr>';
5308: }
5309: my $check = ' ';
1.39 raeburn 5310: if (ref($settings) eq 'HASH') {
5311: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
5312: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
5313: $check = ' checked="checked" ';
5314: }
1.27 raeburn 5315: }
5316: }
5317: $output .= '<td class="LC_left_item">'.
5318: '<span class="LC_nobreak"><label>'.
1.32 raeburn 5319: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 5320: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
5321: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
5322: }
5323: }
5324: $rem = @{$ruleorder}%($numinrow);
5325: }
5326: my $colsleft = $numinrow - $rem;
5327: if ($colsleft > 1 ) {
5328: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
5329: ' </td>';
5330: } elsif ($colsleft == 1) {
5331: $output .= '<td class="LC_left_item"> </td>';
5332: }
5333: $output .= '</tr></table></td></tr>';
5334: return $output;
5335: }
5336:
1.34 raeburn 5337: sub usercreation_types {
5338: my %lt = &Apache::lonlocal::texthash (
5339: author => 'When adding a co-author',
5340: course => 'When adding a user to a course',
1.100 raeburn 5341: requestcrs => 'When requesting a course',
1.34 raeburn 5342: any => 'Any',
5343: official => 'Institutional only ',
5344: unofficial => 'Non-institutional only',
5345: none => 'None',
5346: );
5347: return %lt;
1.48 raeburn 5348: }
1.34 raeburn 5349:
1.160.6.34 raeburn 5350: sub selfcreation_types {
5351: my %lt = &Apache::lonlocal::texthash (
5352: selfcreate => 'User creates own account',
5353: any => 'Any',
5354: official => 'Institutional only ',
5355: unofficial => 'Non-institutional only',
5356: email => 'E-mail address',
5357: login => 'Institutional Login',
5358: sso => 'SSO',
5359: );
5360: }
5361:
1.28 raeburn 5362: sub authtype_names {
5363: my %lt = &Apache::lonlocal::texthash(
5364: int => 'Internal',
5365: krb4 => 'Kerberos 4',
5366: krb5 => 'Kerberos 5',
5367: loc => 'Local',
5368: );
5369: return %lt;
5370: }
5371:
5372: sub context_names {
5373: my %context_title = &Apache::lonlocal::texthash(
5374: author => 'Creating users when an Author',
5375: course => 'Creating users when in a course',
5376: domain => 'Creating users when a Domain Coordinator',
5377: );
5378: return %context_title;
5379: }
5380:
1.33 raeburn 5381: sub print_usermodification {
5382: my ($position,$dom,$settings,$rowtotal) = @_;
5383: my $numinrow = 4;
5384: my ($context,$datatable,$rowcount);
5385: if ($position eq 'top') {
5386: $rowcount = 0;
5387: $context = 'author';
5388: foreach my $role ('ca','aa') {
5389: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5390: $numinrow,$rowcount);
5391: $$rowtotal ++;
5392: $rowcount ++;
5393: }
1.160.6.37 raeburn 5394: } elsif ($position eq 'bottom') {
1.33 raeburn 5395: $context = 'course';
5396: $rowcount = 0;
5397: foreach my $role ('st','ep','ta','in','cr') {
5398: $datatable .= &modifiable_userdata_row($context,$role,$settings,
5399: $numinrow,$rowcount);
5400: $$rowtotal ++;
5401: $rowcount ++;
5402: }
5403: }
5404: return $datatable;
5405: }
5406:
1.43 raeburn 5407: sub print_defaults {
1.160.6.40 raeburn 5408: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 5409: my $rownum = 0;
1.160.6.80 raeburn 5410: my ($datatable,$css_class,$titles);
5411: unless ($position eq 'bottom') {
5412: $titles = &defaults_titles($dom);
5413: }
1.160.6.40 raeburn 5414: if ($position eq 'top') {
5415: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
5416: 'datelocale_def','portal_def');
5417: my %defaults;
5418: if (ref($settings) eq 'HASH') {
5419: %defaults = %{$settings};
1.43 raeburn 5420: } else {
1.160.6.40 raeburn 5421: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
5422: foreach my $item (@items) {
5423: $defaults{$item} = $domdefaults{$item};
5424: }
1.43 raeburn 5425: }
1.160.6.40 raeburn 5426: foreach my $item (@items) {
5427: if ($rownum%2) {
5428: $css_class = '';
5429: } else {
5430: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 5431: }
1.160.6.40 raeburn 5432: $datatable .= '<tr'.$css_class.'>'.
5433: '<td><span class="LC_nobreak">'.$titles->{$item}.
5434: '</span></td><td class="LC_right_item" colspan="3">';
5435: if ($item eq 'auth_def') {
5436: my @authtypes = ('internal','krb4','krb5','localauth');
5437: my %shortauth = (
5438: internal => 'int',
5439: krb4 => 'krb4',
5440: krb5 => 'krb5',
5441: localauth => 'loc'
5442: );
5443: my %authnames = &authtype_names();
5444: foreach my $auth (@authtypes) {
5445: my $checked = ' ';
5446: if ($defaults{$item} eq $auth) {
5447: $checked = ' checked="checked" ';
5448: }
5449: $datatable .= '<label><input type="radio" name="'.$item.
5450: '" value="'.$auth.'"'.$checked.'/>'.
5451: $authnames{$shortauth{$auth}}.'</label> ';
5452: }
5453: } elsif ($item eq 'timezone_def') {
5454: my $includeempty = 1;
5455: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
5456: } elsif ($item eq 'datelocale_def') {
5457: my $includeempty = 1;
5458: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
5459: } elsif ($item eq 'lang_def') {
1.160.6.63 raeburn 5460: my $includeempty = 1;
5461: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40 raeburn 5462: } else {
5463: my $size;
5464: if ($item eq 'portal_def') {
5465: $size = ' size="25"';
5466: }
5467: $datatable .= '<input type="text" name="'.$item.'" value="'.
5468: $defaults{$item}.'"'.$size.' />';
5469: }
5470: $datatable .= '</td></tr>';
5471: $rownum ++;
5472: }
1.160.6.80 raeburn 5473: } elsif ($position eq 'middle') {
5474: my @items = ('intauth_cost','intauth_check','intauth_switch');
5475: my %defaults;
5476: if (ref($settings) eq 'HASH') {
5477: %defaults = %{$settings};
5478: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
5479: $defaults{'intauth_cost'} = 10;
5480: }
5481: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
5482: $defaults{'intauth_check'} = 0;
5483: }
5484: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
5485: $defaults{'intauth_switch'} = 0;
5486: }
5487: } else {
5488: %defaults = (
5489: 'intauth_cost' => 10,
5490: 'intauth_check' => 0,
5491: 'intauth_switch' => 0,
5492: );
5493: }
5494: foreach my $item (@items) {
5495: if ($rownum%2) {
5496: $css_class = '';
5497: } else {
5498: $css_class = ' class="LC_odd_row" ';
5499: }
5500: $datatable .= '<tr'.$css_class.'>'.
5501: '<td><span class="LC_nobreak">'.$titles->{$item}.
5502: '</span></td><td class="LC_left_item" colspan="3">';
5503: if ($item eq 'intauth_switch') {
5504: my @options = (0,1,2);
5505: my %optiondesc = &Apache::lonlocal::texthash (
5506: 0 => 'No',
5507: 1 => 'Yes',
5508: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
5509: );
5510: $datatable .= '<table width="100%">';
5511: foreach my $option (@options) {
5512: my $checked = ' ';
5513: if ($defaults{$item} eq $option) {
5514: $checked = ' checked="checked"';
5515: }
5516: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5517: '<label><input type="radio" name="'.$item.
5518: '" value="'.$option.'"'.$checked.' />'.
5519: $optiondesc{$option}.'</label></span></td></tr>';
5520: }
5521: $datatable .= '</table>';
5522: } elsif ($item eq 'intauth_check') {
5523: my @options = (0,1,2);
5524: my %optiondesc = &Apache::lonlocal::texthash (
5525: 0 => 'No',
5526: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
5527: 2 => 'Yes, disallow login if stored cost is less than domain default',
5528: );
1.160.6.87 raeburn 5529: $datatable .= '<table width="100%">';
1.160.6.80 raeburn 5530: foreach my $option (@options) {
5531: my $checked = ' ';
5532: my $onclick;
5533: if ($defaults{$item} eq $option) {
5534: $checked = ' checked="checked"';
5535: }
5536: if ($option == 2) {
5537: $onclick = ' onclick="javascript:warnIntAuth(this);"';
5538: }
5539: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
5540: '<label><input type="radio" name="'.$item.
5541: '" value="'.$option.'"'.$checked.$onclick.' />'.
5542: $optiondesc{$option}.'</label></span></td></tr>';
5543: }
5544: $datatable .= '</table>';
5545: } else {
5546: $datatable .= '<input type="text" name="'.$item.'" value="'.
5547: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
5548: }
5549: $datatable .= '</td></tr>';
5550: $rownum ++;
5551: }
1.160.6.40 raeburn 5552: } else {
1.160.6.80 raeburn 5553: my %defaults;
1.160.6.40 raeburn 5554: if (ref($settings) eq 'HASH') {
5555: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
5556: (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
5557: my $maxnum = @{$settings->{'inststatusorder'}};
5558: for (my $i=0; $i<$maxnum; $i++) {
5559: $css_class = $rownum%2?' class="LC_odd_row"':'';
5560: my $item = $settings->{'inststatusorder'}->[$i];
5561: my $title = $settings->{'inststatustypes'}->{$item};
5562: my $guestok;
5563: if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
5564: $guestok = 1;
5565: }
5566: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
5567: $datatable .= '<tr'.$css_class.'>'.
5568: '<td><span class="LC_nobreak">'.
5569: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
5570: for (my $k=0; $k<=$maxnum; $k++) {
5571: my $vpos = $k+1;
5572: my $selstr;
5573: if ($k == $i) {
5574: $selstr = ' selected="selected" ';
5575: }
5576: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5577: }
5578: my ($checkedon,$checkedoff);
5579: $checkedoff = ' checked="checked"';
5580: if ($guestok) {
5581: $checkedon = $checkedoff;
5582: $checkedoff = '';
5583: }
5584: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
5585: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
5586: &mt('delete').'</span></td>'.
5587: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
5588: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
5589: '</span></td>'.
5590: '<td class="LC_right_item"><span class="LC_nobreak">'.
5591: '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
5592: &mt('Yes').'</label>'.(' 'x2).
5593: '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
5594: &mt('No').'</label></span></td></tr>';
5595: }
5596: $css_class = $rownum%2?' class="LC_odd_row"':'';
5597: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
5598: $datatable .= '<tr '.$css_class.'>'.
5599: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
5600: for (my $k=0; $k<=$maxnum; $k++) {
5601: my $vpos = $k+1;
5602: my $selstr;
5603: if ($k == $maxnum) {
5604: $selstr = ' selected="selected" ';
5605: }
5606: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5607: }
5608: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 5609: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 5610: ' '.&mt('(new)').
5611: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
5612: &mt('Name displayed:').
5613: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
5614: '<td class="LC_right_item"><span class="LC_nobreak">'.
5615: '<label><input type="radio" value="1" name="addinststatus_guest" />'.
5616: &mt('Yes').'</label>'.(' 'x2).
5617: '<label><input type="radio" value="0" name="addinststatus_guest" />'.
5618: &mt('No').'</label></span></td></tr>';
5619: '</tr>'."\n";
5620: $rownum ++;
1.141 raeburn 5621: }
1.43 raeburn 5622: }
5623: }
5624: $$rowtotal += $rownum;
5625: return $datatable;
5626: }
5627:
1.160.6.5 raeburn 5628: sub get_languages_hash {
5629: my %langchoices;
5630: foreach my $id (&Apache::loncommon::languageids()) {
5631: my $code = &Apache::loncommon::supportedlanguagecode($id);
5632: if ($code ne '') {
5633: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
5634: }
5635: }
5636: return %langchoices;
5637: }
5638:
1.43 raeburn 5639: sub defaults_titles {
1.141 raeburn 5640: my ($dom) = @_;
1.43 raeburn 5641: my %titles = &Apache::lonlocal::texthash (
5642: 'auth_def' => 'Default authentication type',
5643: 'auth_arg_def' => 'Default authentication argument',
5644: 'lang_def' => 'Default language',
1.54 raeburn 5645: 'timezone_def' => 'Default timezone',
1.68 raeburn 5646: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 5647: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 5648: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
5649: 'intauth_check' => 'Check bcrypt cost if authenticated',
5650: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 5651: );
1.141 raeburn 5652: if ($dom) {
5653: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
5654: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
5655: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
5656: $protocol = 'http' if ($protocol ne 'https');
5657: if ($uint_dom) {
5658: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
5659: $uint_dom);
5660: }
5661: }
1.43 raeburn 5662: return (\%titles);
5663: }
5664:
1.46 raeburn 5665: sub print_scantronformat {
5666: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
5667: my $itemcount = 1;
1.60 raeburn 5668: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
5669: %confhash);
1.46 raeburn 5670: my $switchserver = &check_switchserver($dom,$confname);
5671: my %lt = &Apache::lonlocal::texthash (
1.95 www 5672: default => 'Default bubblesheet format file error',
5673: custom => 'Custom bubblesheet format file error',
1.46 raeburn 5674: );
5675: my %scantronfiles = (
5676: default => 'default.tab',
5677: custom => 'custom.tab',
5678: );
5679: foreach my $key (keys(%scantronfiles)) {
5680: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
5681: .$scantronfiles{$key};
5682: }
5683: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
5684: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
5685: if (!$switchserver) {
5686: my $servadm = $r->dir_config('lonAdmEMail');
5687: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
5688: if ($configuserok eq 'ok') {
5689: if ($author_ok eq 'ok') {
5690: my %legacyfile = (
5691: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
5692: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
5693: );
5694: my %md5chk;
5695: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5696: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
5697: chomp($md5chk{$type});
1.46 raeburn 5698: }
5699: if ($md5chk{'default'} ne $md5chk{'custom'}) {
5700: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 5701: ($scantronurls{$type},my $error) =
1.46 raeburn 5702: &legacy_scantronformat($r,$dom,$confname,
5703: $type,$legacyfile{$type},
5704: $scantronurls{$type},
5705: $scantronfiles{$type});
1.60 raeburn 5706: if ($error ne '') {
5707: $error{$type} = $error;
5708: }
5709: }
5710: if (keys(%error) == 0) {
5711: $is_custom = 1;
5712: $confhash{'scantron'}{'scantronformat'} =
5713: $scantronurls{'custom'};
5714: my $putresult =
5715: &Apache::lonnet::put_dom('configuration',
5716: \%confhash,$dom);
5717: if ($putresult ne 'ok') {
5718: $error{'custom'} =
5719: '<span class="LC_error">'.
5720: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5721: }
1.46 raeburn 5722: }
5723: } else {
1.60 raeburn 5724: ($scantronurls{'default'},my $error) =
1.46 raeburn 5725: &legacy_scantronformat($r,$dom,$confname,
5726: 'default',$legacyfile{'default'},
5727: $scantronurls{'default'},
5728: $scantronfiles{'default'});
1.60 raeburn 5729: if ($error eq '') {
5730: $confhash{'scantron'}{'scantronformat'} = '';
5731: my $putresult =
5732: &Apache::lonnet::put_dom('configuration',
5733: \%confhash,$dom);
5734: if ($putresult ne 'ok') {
5735: $error{'default'} =
5736: '<span class="LC_error">'.
5737: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
5738: }
5739: } else {
5740: $error{'default'} = $error;
5741: }
1.46 raeburn 5742: }
5743: }
5744: }
5745: } else {
1.95 www 5746: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 5747: }
5748: }
5749: if (ref($settings) eq 'HASH') {
5750: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
5751: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
5752: if ((!@info) || ($info[0] eq 'no_such_dir')) {
5753: $scantronurl = '';
5754: } else {
5755: $scantronurl = $settings->{'scantronformat'};
5756: }
5757: $is_custom = 1;
5758: } else {
5759: $scantronurl = $scantronurls{'default'};
5760: }
5761: } else {
1.60 raeburn 5762: if ($is_custom) {
5763: $scantronurl = $scantronurls{'custom'};
5764: } else {
5765: $scantronurl = $scantronurls{'default'};
5766: }
1.46 raeburn 5767: }
5768: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5769: $datatable .= '<tr'.$css_class.'>';
5770: if (!$is_custom) {
1.65 raeburn 5771: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
5772: '<span class="LC_nobreak">';
1.46 raeburn 5773: if ($scantronurl) {
1.160.6.21 raeburn 5774: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
5775: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 5776: } else {
5777: $datatable = &mt('File unavailable for display');
5778: }
1.65 raeburn 5779: $datatable .= '</span></td>';
1.60 raeburn 5780: if (keys(%error) == 0) {
5781: $datatable .= '<td valign="bottom">';
5782: if (!$switchserver) {
5783: $datatable .= &mt('Upload:').'<br />';
5784: }
5785: } else {
5786: my $errorstr;
5787: foreach my $key (sort(keys(%error))) {
5788: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5789: }
5790: $datatable .= '<td>'.$errorstr;
5791: }
1.46 raeburn 5792: } else {
5793: if (keys(%error) > 0) {
5794: my $errorstr;
5795: foreach my $key (sort(keys(%error))) {
5796: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
5797: }
1.60 raeburn 5798: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 5799: } elsif ($scantronurl) {
1.160.6.26 raeburn 5800: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 5801: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 5802: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 5803: $link.
5804: '<label><input type="checkbox" name="scantronformat_del"'.
5805: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 5806: '<td><span class="LC_nobreak"> '.
5807: &mt('Replace:').'</span><br />';
1.46 raeburn 5808: }
5809: }
5810: if (keys(%error) == 0) {
5811: if ($switchserver) {
5812: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5813: } else {
1.65 raeburn 5814: $datatable .='<span class="LC_nobreak"> '.
5815: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 5816: }
5817: }
5818: $datatable .= '</td></tr>';
5819: $$rowtotal ++;
5820: return $datatable;
5821: }
5822:
5823: sub legacy_scantronformat {
5824: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
5825: my ($url,$error);
5826: my @statinfo = &Apache::lonnet::stat_file($newurl);
5827: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
5828: (my $result,$url) =
5829: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
5830: '','',$newfile);
5831: if ($result ne 'ok') {
1.130 raeburn 5832: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 5833: }
5834: }
5835: return ($url,$error);
5836: }
1.43 raeburn 5837:
1.49 raeburn 5838: sub print_coursecategories {
1.57 raeburn 5839: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
5840: my $datatable;
5841: if ($position eq 'top') {
1.160.6.42 raeburn 5842: my (%checked);
5843: my @catitems = ('unauth','auth');
5844: my @cattypes = ('std','domonly','codesrch','none');
5845: $checked{'unauth'} = 'std';
5846: $checked{'auth'} = 'std';
5847: if (ref($settings) eq 'HASH') {
5848: foreach my $type (@cattypes) {
5849: if ($type eq $settings->{'unauth'}) {
5850: $checked{'unauth'} = $type;
5851: }
5852: if ($type eq $settings->{'auth'}) {
5853: $checked{'auth'} = $type;
5854: }
5855: }
5856: }
5857: my %lt = &Apache::lonlocal::texthash (
5858: unauth => 'Catalog type for unauthenticated users',
5859: auth => 'Catalog type for authenticated users',
5860: none => 'No catalog',
5861: std => 'Standard catalog',
5862: domonly => 'Domain-only catalog',
5863: codesrch => "Code search form",
5864: );
5865: my $itemcount = 0;
5866: foreach my $item (@catitems) {
5867: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
5868: $datatable .= '<tr '.$css_class.'>'.
5869: '<td>'.$lt{$item}.'</td>'.
5870: '<td class="LC_right_item"><span class="LC_nobreak">';
5871: foreach my $type (@cattypes) {
5872: my $ischecked;
5873: if ($checked{$item} eq $type) {
5874: $ischecked=' checked="checked"';
5875: }
5876: $datatable .= '<label>'.
5877: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
5878: ' />'.$lt{$type}.'</label> ';
5879: }
1.160.6.87 raeburn 5880: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 5881: $itemcount ++;
5882: }
5883: $$rowtotal += $itemcount;
5884: } elsif ($position eq 'middle') {
1.57 raeburn 5885: my $toggle_cats_crs = ' ';
5886: my $toggle_cats_dom = ' checked="checked" ';
5887: my $can_cat_crs = ' ';
5888: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 5889: my $toggle_catscomm_comm = ' ';
5890: my $toggle_catscomm_dom = ' checked="checked" ';
5891: my $can_catcomm_comm = ' ';
5892: my $can_catcomm_dom = ' checked="checked" ';
5893:
1.57 raeburn 5894: if (ref($settings) eq 'HASH') {
5895: if ($settings->{'togglecats'} eq 'crs') {
5896: $toggle_cats_crs = $toggle_cats_dom;
5897: $toggle_cats_dom = ' ';
5898: }
5899: if ($settings->{'categorize'} eq 'crs') {
5900: $can_cat_crs = $can_cat_dom;
5901: $can_cat_dom = ' ';
5902: }
1.120 raeburn 5903: if ($settings->{'togglecatscomm'} eq 'comm') {
5904: $toggle_catscomm_comm = $toggle_catscomm_dom;
5905: $toggle_catscomm_dom = ' ';
5906: }
5907: if ($settings->{'categorizecomm'} eq 'comm') {
5908: $can_catcomm_comm = $can_catcomm_dom;
5909: $can_catcomm_dom = ' ';
5910: }
1.57 raeburn 5911: }
5912: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 5913: togglecats => 'Show/Hide a course in catalog',
5914: togglecatscomm => 'Show/Hide a community in catalog',
5915: categorize => 'Assign a category to a course',
5916: categorizecomm => 'Assign a category to a community',
1.57 raeburn 5917: );
5918: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 5919: dom => 'Set in Domain',
5920: crs => 'Set in Course',
5921: comm => 'Set in Community',
1.57 raeburn 5922: );
5923: $datatable = '<tr class="LC_odd_row">'.
5924: '<td>'.$title{'togglecats'}.'</td>'.
5925: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5926: '<input type="radio" name="togglecats"'.
5927: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5928: '<label><input type="radio" name="togglecats"'.
5929: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
5930: '</tr><tr>'.
5931: '<td>'.$title{'categorize'}.'</td>'.
5932: '<td class="LC_right_item"><span class="LC_nobreak">'.
5933: '<label><input type="radio" name="categorize"'.
5934: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5935: '<label><input type="radio" name="categorize"'.
5936: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 5937: '</tr><tr class="LC_odd_row">'.
5938: '<td>'.$title{'togglecatscomm'}.'</td>'.
5939: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
5940: '<input type="radio" name="togglecatscomm"'.
5941: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5942: '<label><input type="radio" name="togglecatscomm"'.
5943: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
5944: '</tr><tr>'.
5945: '<td>'.$title{'categorizecomm'}.'</td>'.
5946: '<td class="LC_right_item"><span class="LC_nobreak">'.
5947: '<label><input type="radio" name="categorizecomm"'.
5948: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
5949: '<label><input type="radio" name="categorizecomm"'.
5950: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 5951: '</tr>';
1.120 raeburn 5952: $$rowtotal += 4;
1.57 raeburn 5953: } else {
5954: my $css_class;
5955: my $itemcount = 1;
5956: my $cathash;
5957: if (ref($settings) eq 'HASH') {
5958: $cathash = $settings->{'cats'};
5959: }
5960: if (ref($cathash) eq 'HASH') {
5961: my (@cats,@trails,%allitems,%idx,@jsarray);
5962: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
5963: \%allitems,\%idx,\@jsarray);
5964: my $maxdepth = scalar(@cats);
5965: my $colattrib = '';
5966: if ($maxdepth > 2) {
5967: $colattrib = ' colspan="2" ';
5968: }
5969: my @path;
5970: if (@cats > 0) {
5971: if (ref($cats[0]) eq 'ARRAY') {
5972: my $numtop = @{$cats[0]};
5973: my $maxnum = $numtop;
1.120 raeburn 5974: my %default_names = (
5975: instcode => &mt('Official courses'),
5976: communities => &mt('Communities'),
5977: );
5978:
5979: if ((!grep(/^instcode$/,@{$cats[0]})) ||
5980: ($cathash->{'instcode::0'} eq '') ||
5981: (!grep(/^communities$/,@{$cats[0]})) ||
5982: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 5983: $maxnum ++;
5984: }
5985: my $lastidx;
5986: for (my $i=0; $i<$numtop; $i++) {
5987: my $parent = $cats[0][$i];
5988: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5989: my $item = &escape($parent).'::0';
5990: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
5991: $lastidx = $idx{$item};
5992: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5993: .'<select name="'.$item.'"'.$chgstr.'>';
5994: for (my $k=0; $k<=$maxnum; $k++) {
5995: my $vpos = $k+1;
5996: my $selstr;
5997: if ($k == $i) {
5998: $selstr = ' selected="selected" ';
5999: }
6000: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6001: }
1.160.6.29 raeburn 6002: $datatable .= '</select></span></td><td>';
1.120 raeburn 6003: if ($parent eq 'instcode' || $parent eq 'communities') {
6004: $datatable .= '<span class="LC_nobreak">'
6005: .$default_names{$parent}.'</span>';
6006: if ($parent eq 'instcode') {
6007: $datatable .= '<br /><span class="LC_nobreak">('
6008: .&mt('with institutional codes')
6009: .')</span></td><td'.$colattrib.'>';
6010: } else {
6011: $datatable .= '<table><tr><td>';
6012: }
6013: $datatable .= '<span class="LC_nobreak">'
6014: .'<label><input type="radio" name="'
6015: .$parent.'" value="1" checked="checked" />'
6016: .&mt('Display').'</label>';
6017: if ($parent eq 'instcode') {
6018: $datatable .= ' ';
6019: } else {
6020: $datatable .= '</span></td></tr><tr><td>'
6021: .'<span class="LC_nobreak">';
6022: }
6023: $datatable .= '<label><input type="radio" name="'
6024: .$parent.'" value="0" />'
6025: .&mt('Do not display').'</label></span>';
6026: if ($parent eq 'communities') {
6027: $datatable .= '</td></tr></table>';
6028: }
6029: $datatable .= '</td>';
1.57 raeburn 6030: } else {
6031: $datatable .= $parent
1.160.6.29 raeburn 6032: .' <span class="LC_nobreak"><label>'
6033: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 6034: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
6035: }
6036: my $depth = 1;
6037: push(@path,$parent);
6038: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
6039: pop(@path);
6040: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
6041: $itemcount ++;
6042: }
1.48 raeburn 6043: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 6044: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
6045: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 6046: for (my $k=0; $k<=$maxnum; $k++) {
6047: my $vpos = $k+1;
6048: my $selstr;
1.57 raeburn 6049: if ($k == $numtop) {
1.48 raeburn 6050: $selstr = ' selected="selected" ';
6051: }
6052: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
6053: }
1.59 bisitz 6054: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 6055: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
6056: .'</tr>'."\n";
1.48 raeburn 6057: $itemcount ++;
1.120 raeburn 6058: foreach my $default ('instcode','communities') {
6059: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
6060: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6061: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
6062: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
6063: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
6064: for (my $k=0; $k<=$maxnum; $k++) {
6065: my $vpos = $k+1;
6066: my $selstr;
6067: if ($k == $maxnum) {
6068: $selstr = ' selected="selected" ';
6069: }
6070: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 6071: }
1.120 raeburn 6072: $datatable .= '</select></span></td>'.
6073: '<td><span class="LC_nobreak">'.
6074: $default_names{$default}.'</span>';
6075: if ($default eq 'instcode') {
6076: $datatable .= '<br /><span class="LC_nobreak">('
6077: .&mt('with institutional codes').')</span>';
6078: }
6079: $datatable .= '</td>'
6080: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
6081: .&mt('Display').'</label> '
6082: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
6083: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 6084: }
6085: }
6086: }
1.57 raeburn 6087: } else {
6088: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 6089: }
6090: } else {
1.160.6.87 raeburn 6091: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 6092: .&initialize_categories($itemcount);
1.48 raeburn 6093: }
1.57 raeburn 6094: $$rowtotal += $itemcount;
1.48 raeburn 6095: }
6096: return $datatable;
6097: }
6098:
1.69 raeburn 6099: sub print_serverstatuses {
6100: my ($dom,$settings,$rowtotal) = @_;
6101: my $datatable;
6102: my @pages = &serverstatus_pages();
6103: my (%namedaccess,%machineaccess);
6104: foreach my $type (@pages) {
6105: $namedaccess{$type} = '';
6106: $machineaccess{$type}= '';
6107: }
6108: if (ref($settings) eq 'HASH') {
6109: foreach my $type (@pages) {
6110: if (exists($settings->{$type})) {
6111: if (ref($settings->{$type}) eq 'HASH') {
6112: foreach my $key (keys(%{$settings->{$type}})) {
6113: if ($key eq 'namedusers') {
6114: $namedaccess{$type} = $settings->{$type}->{$key};
6115: } elsif ($key eq 'machines') {
6116: $machineaccess{$type} = $settings->{$type}->{$key};
6117: }
6118: }
6119: }
6120: }
6121: }
6122: }
1.81 raeburn 6123: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6124: my $rownum = 0;
6125: my $css_class;
6126: foreach my $type (@pages) {
6127: $rownum ++;
6128: $css_class = $rownum%2?' class="LC_odd_row"':'';
6129: $datatable .= '<tr'.$css_class.'>'.
6130: '<td><span class="LC_nobreak">'.
6131: $titles->{$type}.'</span></td>'.
6132: '<td class="LC_left_item">'.
6133: '<input type="text" name="'.$type.'_namedusers" '.
6134: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
6135: '<td class="LC_right_item">'.
6136: '<span class="LC_nobreak">'.
6137: '<input type="text" name="'.$type.'_machines" '.
6138: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 6139: '</span></td></tr>'."\n";
1.69 raeburn 6140: }
6141: $$rowtotal += $rownum;
6142: return $datatable;
6143: }
6144:
6145: sub serverstatus_pages {
6146: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 6147: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 6148: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 6149: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 6150: }
6151:
1.160.6.40 raeburn 6152: sub defaults_javascript {
6153: my ($settings) = @_;
1.160.6.80 raeburn 6154: 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.');
6155: my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
6156: &js_escape(\$intauthcheck);
6157: &js_escape(\$intauthcost);
6158: my $intauthjs = <<"ENDSCRIPT";
6159:
6160: function warnIntAuth(field) {
6161: if (field.name == 'intauth_check') {
6162: if (field.value == '2') {
6163: alert('$intauthcheck');
6164: }
6165: }
6166: if (field.name == 'intauth_cost') {
6167: field.value.replace(/\s/g,'');
6168: if (field.value != '') {
6169: var regexdigit=/^\\d+\$/;
6170: if (!regexdigit.test(field.value)) {
6171: alert('$intauthcost');
6172: }
6173: }
6174: }
6175: return;
6176: }
6177:
6178: ENDSCRIPT
6179:
6180: if (ref($settings) ne 'HASH') {
6181: return &Apache::lonhtmlcommon::scripttag($intauthjs);
6182: }
1.160.6.40 raeburn 6183: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
6184: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
6185: if ($maxnum eq '') {
6186: $maxnum = 0;
6187: }
6188: $maxnum ++;
1.160.6.51 raeburn 6189: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 6190: return <<"ENDSCRIPT";
6191: <script type="text/javascript">
6192: // <![CDATA[
6193: function reorderTypes(form,caller) {
6194: var changedVal;
6195: $jstext
6196: var newpos = 'addinststatus_pos';
6197: var current = new Array;
6198: var maxh = $maxnum;
6199: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6200: var oldVal;
6201: if (caller == newpos) {
6202: changedVal = newitemVal;
6203: } else {
6204: var curritem = 'inststatus_pos_'+caller;
6205: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
6206: current[newitemVal] = newpos;
6207: }
6208: for (var i=0; i<inststatuses.length; i++) {
6209: if (inststatuses[i] != caller) {
6210: var elementName = 'inststatus_pos_'+inststatuses[i];
6211: if (form.elements[elementName]) {
6212: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6213: current[currVal] = elementName;
6214: }
6215: }
6216: }
6217: for (var j=0; j<maxh; j++) {
6218: if (current[j] == undefined) {
6219: oldVal = j;
6220: }
6221: }
6222: if (oldVal < changedVal) {
6223: for (var k=oldVal+1; k<=changedVal ; k++) {
6224: var elementName = current[k];
6225: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6226: }
6227: } else {
6228: for (var k=changedVal; k<oldVal; k++) {
6229: var elementName = current[k];
6230: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6231: }
6232: }
6233: return;
6234: }
6235:
1.160.6.80 raeburn 6236: $intauthjs
6237:
1.160.6.40 raeburn 6238: // ]]>
6239: </script>
6240:
6241: ENDSCRIPT
1.160.6.80 raeburn 6242: } else {
6243: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40 raeburn 6244: }
6245: }
6246:
1.49 raeburn 6247: sub coursecategories_javascript {
6248: my ($settings) = @_;
1.57 raeburn 6249: my ($output,$jstext,$cathash);
1.49 raeburn 6250: if (ref($settings) eq 'HASH') {
1.57 raeburn 6251: $cathash = $settings->{'cats'};
6252: }
6253: if (ref($cathash) eq 'HASH') {
1.49 raeburn 6254: my (@cats,@jsarray,%idx);
1.57 raeburn 6255: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 6256: if (@jsarray > 0) {
6257: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
6258: for (my $i=0; $i<@jsarray; $i++) {
6259: if (ref($jsarray[$i]) eq 'ARRAY') {
6260: my $catstr = join('","',@{$jsarray[$i]});
6261: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
6262: }
6263: }
6264: }
6265: } else {
6266: $jstext = ' var categories = Array(1);'."\n".
6267: ' categories[0] = Array("instcode_pos");'."\n";
6268: }
1.160.6.42 raeburn 6269: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
6270: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 6271: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
6272: &js_escape(\$instcode_reserved);
6273: &js_escape(\$communities_reserved);
6274: &js_escape(\$choose_again);
1.49 raeburn 6275: $output = <<"ENDSCRIPT";
6276: <script type="text/javascript">
1.109 raeburn 6277: // <![CDATA[
1.49 raeburn 6278: function reorderCats(form,parent,item,idx) {
6279: var changedVal;
6280: $jstext
6281: var newpos = 'addcategory_pos';
6282: if (parent == '') {
6283: var has_instcode = 0;
6284: var maxtop = categories[idx].length;
6285: for (var j=0; j<maxtop; j++) {
6286: if (categories[idx][j] == 'instcode::0') {
6287: has_instcode == 1;
6288: }
6289: }
6290: if (has_instcode == 0) {
6291: categories[idx][maxtop] = 'instcode_pos';
6292: }
6293: } else {
6294: newpos += '_'+parent;
6295: }
6296: var maxh = 1 + categories[idx].length;
6297: var current = new Array;
6298: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
6299: if (item == newpos) {
6300: changedVal = newitemVal;
6301: } else {
6302: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
6303: current[newitemVal] = newpos;
6304: }
6305: for (var i=0; i<categories[idx].length; i++) {
6306: var elementName = categories[idx][i];
6307: if (elementName != item) {
6308: if (form.elements[elementName]) {
6309: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
6310: current[currVal] = elementName;
6311: }
6312: }
6313: }
6314: var oldVal;
6315: for (var j=0; j<maxh; j++) {
6316: if (current[j] == undefined) {
6317: oldVal = j;
6318: }
6319: }
6320: if (oldVal < changedVal) {
6321: for (var k=oldVal+1; k<=changedVal ; k++) {
6322: var elementName = current[k];
6323: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
6324: }
6325: } else {
6326: for (var k=changedVal; k<oldVal; k++) {
6327: var elementName = current[k];
6328: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
6329: }
6330: }
6331: return;
6332: }
1.120 raeburn 6333:
6334: function categoryCheck(form) {
6335: if (form.elements['addcategory_name'].value == 'instcode') {
6336: alert('$instcode_reserved\\n$choose_again');
6337: return false;
6338: }
6339: if (form.elements['addcategory_name'].value == 'communities') {
6340: alert('$communities_reserved\\n$choose_again');
6341: return false;
6342: }
6343: return true;
6344: }
6345:
1.109 raeburn 6346: // ]]>
1.49 raeburn 6347: </script>
6348:
6349: ENDSCRIPT
6350: return $output;
6351: }
6352:
1.48 raeburn 6353: sub initialize_categories {
6354: my ($itemcount) = @_;
1.120 raeburn 6355: my ($datatable,$css_class,$chgstr);
6356: my %default_names = (
6357: instcode => 'Official courses (with institutional codes)',
6358: communities => 'Communities',
6359: );
6360: my $select0 = ' selected="selected"';
6361: my $select1 = '';
6362: foreach my $default ('instcode','communities') {
6363: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 6364: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 6365: if ($default eq 'communities') {
6366: $select1 = $select0;
6367: $select0 = '';
6368: }
6369: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6370: .'<select name="'.$default.'_pos">'
6371: .'<option value="0"'.$select0.'>1</option>'
6372: .'<option value="1"'.$select1.'>2</option>'
6373: .'<option value="2">3</option></select> '
6374: .$default_names{$default}
6375: .'</span></td><td><span class="LC_nobreak">'
6376: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
6377: .&mt('Display').'</label> <label>'
6378: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 6379: .'</label></span></td></tr>';
1.120 raeburn 6380: $itemcount ++;
6381: }
1.48 raeburn 6382: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 6383: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 6384: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 6385: .'<select name="addcategory_pos"'.$chgstr.'>'
6386: .'<option value="0">1</option>'
6387: .'<option value="1">2</option>'
6388: .'<option value="2" selected="selected">3</option></select> '
1.160.6.87 raeburn 6389: .&mt('Add category').'</span></td><tda<span class="LC_nobreak">>'.&mt('Name:')
6390: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
6391: .'</td></tr>';
1.48 raeburn 6392: return $datatable;
6393: }
6394:
6395: sub build_category_rows {
1.49 raeburn 6396: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
6397: my ($text,$name,$item,$chgstr);
1.48 raeburn 6398: if (ref($cats) eq 'ARRAY') {
6399: my $maxdepth = scalar(@{$cats});
6400: if (ref($cats->[$depth]) eq 'HASH') {
6401: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
6402: my $numchildren = @{$cats->[$depth]{$parent}};
6403: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 6404: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 6405: my ($idxnum,$parent_name,$parent_item);
6406: my $higher = $depth - 1;
6407: if ($higher == 0) {
6408: $parent_name = &escape($parent).'::'.$higher;
6409: } else {
6410: if (ref($path) eq 'ARRAY') {
6411: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6412: }
6413: }
6414: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 6415: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 6416: if ($j < $numchildren) {
1.48 raeburn 6417: $name = $cats->[$depth]{$parent}[$j];
6418: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 6419: $idxnum = $idx->{$item};
6420: } else {
6421: $name = $parent_name;
6422: $item = $parent_item;
1.48 raeburn 6423: }
1.49 raeburn 6424: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
6425: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 6426: for (my $i=0; $i<=$numchildren; $i++) {
6427: my $vpos = $i+1;
6428: my $selstr;
6429: if ($j == $i) {
6430: $selstr = ' selected="selected" ';
6431: }
6432: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
6433: }
6434: $text .= '</select> ';
6435: if ($j < $numchildren) {
6436: my $deeper = $depth+1;
6437: $text .= $name.' '
6438: .'<label><input type="checkbox" name="deletecategory" value="'
6439: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
6440: if(ref($path) eq 'ARRAY') {
6441: push(@{$path},$name);
1.49 raeburn 6442: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 6443: pop(@{$path});
6444: }
6445: } else {
1.160.6.87 raeburn 6446: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 6447: if ($j == $numchildren) {
6448: $text .= $name;
6449: } else {
6450: $text .= $item;
6451: }
6452: $text .= '" value="" />';
6453: }
6454: $text .= '</td></tr>';
6455: }
6456: $text .= '</table></td>';
6457: } else {
6458: my $higher = $depth-1;
6459: if ($higher == 0) {
6460: $name = &escape($parent).'::'.$higher;
6461: } else {
6462: if (ref($path) eq 'ARRAY') {
6463: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
6464: }
6465: }
6466: my $colspan;
6467: if ($parent ne 'instcode') {
6468: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 6469: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 6470: }
6471: }
6472: }
6473: }
6474: return $text;
6475: }
6476:
1.33 raeburn 6477: sub modifiable_userdata_row {
1.160.6.35 raeburn 6478: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
6479: my ($role,$rolename,$statustype);
6480: $role = $item;
1.160.6.34 raeburn 6481: if ($context eq 'cancreate') {
1.160.6.35 raeburn 6482: if ($item =~ /^emailusername_(.+)$/) {
6483: $statustype = $1;
6484: $role = 'emailusername';
6485: if (ref($usertypes) eq 'HASH') {
6486: if ($usertypes->{$statustype}) {
6487: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
6488: } else {
6489: $rolename = &mt('Data provided by user');
6490: }
6491: }
1.160.6.34 raeburn 6492: }
6493: } elsif ($context eq 'selfcreate') {
1.63 raeburn 6494: if (ref($usertypes) eq 'HASH') {
6495: $rolename = $usertypes->{$role};
6496: } else {
6497: $rolename = $role;
6498: }
1.33 raeburn 6499: } else {
1.63 raeburn 6500: if ($role eq 'cr') {
6501: $rolename = &mt('Custom role');
6502: } else {
6503: $rolename = &Apache::lonnet::plaintext($role);
6504: }
1.33 raeburn 6505: }
1.160.6.34 raeburn 6506: my (@fields,%fieldtitles);
6507: if (ref($fieldsref) eq 'ARRAY') {
6508: @fields = @{$fieldsref};
6509: } else {
6510: @fields = ('lastname','firstname','middlename','generation',
6511: 'permanentemail','id');
6512: }
6513: if ((ref($titlesref) eq 'HASH')) {
6514: %fieldtitles = %{$titlesref};
6515: } else {
6516: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
6517: }
1.33 raeburn 6518: my $output;
6519: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
6520: $output = '<tr '.$css_class.'>'.
6521: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
6522: '<td class="LC_left_item" colspan="2"><table>';
6523: my $rem;
6524: my %checks;
6525: if (ref($settings) eq 'HASH') {
6526: if (ref($settings->{$context}) eq 'HASH') {
6527: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 6528: my $hashref = $settings->{$context}->{$role};
6529: if ($role eq 'emailusername') {
6530: if ($statustype) {
6531: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
6532: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 6533: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 6534: foreach my $field (@fields) {
6535: if ($hashref->{$field}) {
6536: $checks{$field} = $hashref->{$field};
6537: }
6538: }
6539: }
6540: }
6541: }
6542: } else {
6543: if (ref($hashref) eq 'HASH') {
6544: foreach my $field (@fields) {
6545: if ($hashref->{$field}) {
6546: $checks{$field} = ' checked="checked" ';
6547: }
6548: }
1.33 raeburn 6549: }
6550: }
6551: }
6552: }
6553: }
1.160.6.39 raeburn 6554:
1.33 raeburn 6555: for (my $i=0; $i<@fields; $i++) {
6556: my $rem = $i%($numinrow);
6557: if ($rem == 0) {
6558: if ($i > 0) {
6559: $output .= '</tr>';
6560: }
6561: $output .= '<tr>';
6562: }
6563: my $check = ' ';
1.160.6.35 raeburn 6564: unless ($role eq 'emailusername') {
6565: if (exists($checks{$fields[$i]})) {
6566: $check = $checks{$fields[$i]}
6567: } else {
6568: if ($role eq 'st') {
6569: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 6570: $check = ' checked="checked" ';
1.160.6.35 raeburn 6571: }
1.33 raeburn 6572: }
6573: }
6574: }
6575: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 6576: '<span class="LC_nobreak">';
6577: if ($role eq 'emailusername') {
6578: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
6579: $checks{$fields[$i]} = 'omit';
6580: }
6581: foreach my $option ('required','optional','omit') {
6582: my $checked='';
6583: if ($checks{$fields[$i]} eq $option) {
6584: $checked='checked="checked" ';
6585: }
6586: $output .= '<label>'.
6587: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
6588: &mt($option).'</label>'.(' ' x2);
6589: }
6590: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
6591: } else {
6592: $output .= '<label>'.
6593: '<input type="checkbox" name="canmodify_'.$role.'" '.
6594: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
6595: '</label>';
6596: }
6597: $output .= '</span></td>';
1.33 raeburn 6598: $rem = @fields%($numinrow);
6599: }
6600: my $colsleft = $numinrow - $rem;
6601: if ($colsleft > 1 ) {
6602: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6603: ' </td>';
6604: } elsif ($colsleft == 1) {
6605: $output .= '<td class="LC_left_item"> </td>';
6606: }
6607: $output .= '</tr></table></td></tr>';
6608: return $output;
6609: }
1.28 raeburn 6610:
1.93 raeburn 6611: sub insttypes_row {
1.160.6.34 raeburn 6612: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93 raeburn 6613: my %lt = &Apache::lonlocal::texthash (
6614: cansearch => 'Users allowed to search',
6615: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 6616: lockablenames => 'User preference to lock name',
1.93 raeburn 6617: );
6618: my $showdom;
6619: if ($context eq 'cansearch') {
6620: $showdom = ' ('.$dom.')';
6621: }
1.160.6.5 raeburn 6622: my $class = 'LC_left_item';
6623: if ($context eq 'statustocreate') {
6624: $class = 'LC_right_item';
6625: }
1.160.6.34 raeburn 6626: my $css_class = ' class="LC_odd_row"';
6627: if ($rownum ne '') {
6628: $css_class = ($rownum%2? ' class="LC_odd_row"':'');
6629: }
6630: my $output = '<tr'.$css_class.'>'.
6631: '<td>'.$lt{$context}.$showdom.
6632: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 6633: my $rem;
6634: if (ref($types) eq 'ARRAY') {
6635: for (my $i=0; $i<@{$types}; $i++) {
6636: if (defined($usertypes->{$types->[$i]})) {
6637: my $rem = $i%($numinrow);
6638: if ($rem == 0) {
6639: if ($i > 0) {
6640: $output .= '</tr>';
6641: }
6642: $output .= '<tr>';
1.23 raeburn 6643: }
1.26 raeburn 6644: my $check = ' ';
1.99 raeburn 6645: if (ref($settings) eq 'HASH') {
6646: if (ref($settings->{$context}) eq 'ARRAY') {
6647: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
6648: $check = ' checked="checked" ';
6649: }
6650: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6651: $check = ' checked="checked" ';
6652: }
1.23 raeburn 6653: }
1.26 raeburn 6654: $output .= '<td class="LC_left_item">'.
6655: '<span class="LC_nobreak"><label>'.
1.93 raeburn 6656: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 6657: 'value="'.$types->[$i].'"'.$check.'/>'.
6658: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 6659: }
6660: }
1.26 raeburn 6661: $rem = @{$types}%($numinrow);
1.23 raeburn 6662: }
6663: my $colsleft = $numinrow - $rem;
1.160.6.87 raeburn 6664: if ($rem == 0) {
1.131 raeburn 6665: $output .= '<tr>';
6666: }
1.23 raeburn 6667: if ($colsleft > 1) {
1.25 raeburn 6668: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 6669: } else {
1.25 raeburn 6670: $output .= '<td class="LC_left_item">';
1.23 raeburn 6671: }
6672: my $defcheck = ' ';
1.99 raeburn 6673: if (ref($settings) eq 'HASH') {
6674: if (ref($settings->{$context}) eq 'ARRAY') {
6675: if (grep(/^default$/,@{$settings->{$context}})) {
6676: $defcheck = ' checked="checked" ';
6677: }
6678: } elsif ($context eq 'statustocreate') {
1.26 raeburn 6679: $defcheck = ' checked="checked" ';
6680: }
1.23 raeburn 6681: }
1.25 raeburn 6682: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 6683: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 6684: 'value="default"'.$defcheck.'/>'.
6685: $othertitle.'</label></span></td>'.
6686: '</tr></table></td></tr>';
6687: return $output;
1.23 raeburn 6688: }
6689:
6690: sub sorted_searchtitles {
6691: my %searchtitles = &Apache::lonlocal::texthash(
6692: 'uname' => 'username',
6693: 'lastname' => 'last name',
6694: 'lastfirst' => 'last name, first name',
6695: );
6696: my @titleorder = ('uname','lastname','lastfirst');
6697: return (\%searchtitles,\@titleorder);
6698: }
6699:
1.25 raeburn 6700: sub sorted_searchtypes {
6701: my %srchtypes_desc = (
6702: exact => 'is exact match',
6703: contains => 'contains ..',
6704: begins => 'begins with ..',
6705: );
6706: my @srchtypeorder = ('exact','begins','contains');
6707: return (\%srchtypes_desc,\@srchtypeorder);
6708: }
6709:
1.3 raeburn 6710: sub usertype_update_row {
6711: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
6712: my $datatable;
6713: my $numinrow = 4;
6714: foreach my $type (@{$types}) {
6715: if (defined($usertypes->{$type})) {
6716: $$rownums ++;
6717: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
6718: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
6719: '</td><td class="LC_left_item"><table>';
6720: for (my $i=0; $i<@{$fields}; $i++) {
6721: my $rem = $i%($numinrow);
6722: if ($rem == 0) {
6723: if ($i > 0) {
6724: $datatable .= '</tr>';
6725: }
6726: $datatable .= '<tr>';
6727: }
6728: my $check = ' ';
1.39 raeburn 6729: if (ref($settings) eq 'HASH') {
6730: if (ref($settings->{'fields'}) eq 'HASH') {
6731: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
6732: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
6733: $check = ' checked="checked" ';
6734: }
1.3 raeburn 6735: }
6736: }
6737: }
6738:
6739: if ($i == @{$fields}-1) {
6740: my $colsleft = $numinrow - $rem;
6741: if ($colsleft > 1) {
6742: $datatable .= '<td colspan="'.$colsleft.'">';
6743: } else {
6744: $datatable .= '<td>';
6745: }
6746: } else {
6747: $datatable .= '<td>';
6748: }
1.8 raeburn 6749: $datatable .= '<span class="LC_nobreak"><label>'.
6750: '<input type="checkbox" name="updateable_'.$type.
6751: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
6752: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 6753: }
6754: $datatable .= '</tr></table></td></tr>';
6755: }
6756: }
6757: return $datatable;
1.1 raeburn 6758: }
6759:
6760: sub modify_login {
1.160.6.24 raeburn 6761: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 6762: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
6763: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
6764: %title = ( coursecatalog => 'Display course catalog',
6765: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 6766: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 6767: newuser => 'Link for visitors to create a user account',
6768: loginheader => 'Log-in box header');
6769: @offon = ('off','on');
1.112 raeburn 6770: if (ref($domconfig{login}) eq 'HASH') {
6771: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
6772: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
6773: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
6774: }
6775: }
6776: }
1.9 raeburn 6777: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
6778: \%domconfig,\%loginhash);
1.160.6.14 raeburn 6779: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 6780: foreach my $item (@toggles) {
6781: $loginhash{login}{$item} = $env{'form.'.$item};
6782: }
1.41 raeburn 6783: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 6784: if (ref($colchanges{'login'}) eq 'HASH') {
6785: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
6786: \%loginhash);
6787: }
1.110 raeburn 6788:
1.149 raeburn 6789: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 6790: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 6791: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 6792: if (keys(%servers) > 1) {
6793: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 6794: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
6795: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
6796: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
6797: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
6798: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
6799: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6800: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6801: $changes{'loginvia'}{$lonhost} = 1;
6802: } else {
6803: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
6804: $changes{'loginvia'}{$lonhost} = 1;
6805: }
6806: } else {
6807: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6808: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
6809: $changes{'loginvia'}{$lonhost} = 1;
6810: }
6811: }
6812: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
6813: foreach my $item (@loginvia_attribs) {
6814: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
6815: }
6816: } else {
6817: foreach my $item (@loginvia_attribs) {
6818: my $new = $env{'form.'.$lonhost.'_'.$item};
6819: if (($item eq 'serverpath') && ($new eq 'custom')) {
6820: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
6821: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6822: $new = '/';
6823: }
6824: }
6825: if (($item eq 'custompath') &&
6826: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6827: $new = '';
6828: }
6829: if ($new ne $curr_loginvia{$lonhost}{$item}) {
6830: $changes{'loginvia'}{$lonhost} = 1;
6831: }
6832: if ($item eq 'exempt') {
1.160.6.56 raeburn 6833: $new = &check_exempt_addresses($new);
1.128 raeburn 6834: }
6835: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6836: }
6837: }
1.112 raeburn 6838: } else {
1.128 raeburn 6839: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
6840: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 6841: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 6842: foreach my $item (@loginvia_attribs) {
6843: my $new = $env{'form.'.$lonhost.'_'.$item};
6844: if (($item eq 'serverpath') && ($new eq 'custom')) {
6845: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
6846: $new = '/';
6847: }
6848: }
6849: if (($item eq 'custompath') &&
6850: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
6851: $new = '';
6852: }
6853: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
6854: }
1.110 raeburn 6855: }
6856: }
6857: }
6858: }
1.119 raeburn 6859:
1.160.6.5 raeburn 6860: my $servadm = $r->dir_config('lonAdmEMail');
6861: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
6862: if (ref($domconfig{'login'}) eq 'HASH') {
6863: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
6864: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
6865: if ($lang eq 'nolang') {
6866: push(@currlangs,$lang);
6867: } elsif (defined($langchoices{$lang})) {
6868: push(@currlangs,$lang);
6869: } else {
6870: next;
6871: }
6872: }
6873: }
6874: }
6875: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
6876: if (@currlangs > 0) {
6877: foreach my $lang (@currlangs) {
6878: if (grep(/^\Q$lang\E$/,@delurls)) {
6879: $changes{'helpurl'}{$lang} = 1;
6880: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
6881: $changes{'helpurl'}{$lang} = 1;
6882: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
6883: push(@newlangs,$lang);
6884: } else {
6885: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6886: }
6887: }
6888: }
6889: unless (grep(/^nolang$/,@currlangs)) {
6890: if ($env{'form.loginhelpurl_nolang.filename'}) {
6891: $changes{'helpurl'}{'nolang'} = 1;
6892: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
6893: push(@newlangs,'nolang');
6894: }
6895: }
6896: if ($env{'form.loginhelpurl_add_lang'}) {
6897: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
6898: ($env{'form.loginhelpurl_add_file.filename'})) {
6899: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
6900: $addedfile = $env{'form.loginhelpurl_add_lang'};
6901: }
6902: }
6903: if ((@newlangs > 0) || ($addedfile)) {
6904: my $error;
6905: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6906: if ($configuserok eq 'ok') {
6907: if ($switchserver) {
6908: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6909: } elsif ($author_ok eq 'ok') {
6910: my @allnew = @newlangs;
6911: if ($addedfile ne '') {
6912: push(@allnew,$addedfile);
6913: }
6914: foreach my $lang (@allnew) {
6915: my $formelem = 'loginhelpurl_'.$lang;
6916: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
6917: $formelem = 'loginhelpurl_add_file';
6918: }
6919: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6920: "help/$lang",'','',$newfile{$lang});
6921: if ($result eq 'ok') {
6922: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
6923: $changes{'helpurl'}{$lang} = 1;
6924: } else {
6925: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
6926: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
6927: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
6928: (!grep(/^\Q$lang\E$/,@delurls))) {
6929: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
6930: }
6931: }
6932: }
6933: } else {
6934: $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);
6935: }
6936: } else {
6937: $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);
6938: }
6939: if ($error) {
6940: &Apache::lonnet::logthis($error);
6941: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6942: }
6943: }
1.160.6.56 raeburn 6944:
6945: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
6946: if (ref($domconfig{'login'}) eq 'HASH') {
6947: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
6948: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
6949: if ($domservers{$lonhost}) {
6950: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
6951: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 6952: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 6953: }
6954: }
6955: }
6956: }
6957: }
6958: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
6959: foreach my $lonhost (sort(keys(%domservers))) {
6960: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
6961: $changes{'headtag'}{$lonhost} = 1;
6962: } else {
6963: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
6964: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
6965: }
6966: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
6967: push(@newhosts,$lonhost);
6968: } elsif ($currheadtagurls{$lonhost}) {
6969: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
6970: if ($currexempt{$lonhost}) {
6971: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
6972: $changes{'headtag'}{$lonhost} = 1;
6973: }
6974: } elsif ($possexempt{$lonhost}) {
6975: $changes{'headtag'}{$lonhost} = 1;
6976: }
6977: if ($possexempt{$lonhost}) {
6978: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
6979: }
6980: }
6981: }
6982: }
6983: if (@newhosts) {
6984: my $error;
6985: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
6986: if ($configuserok eq 'ok') {
6987: if ($switchserver) {
6988: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
6989: } elsif ($author_ok eq 'ok') {
6990: foreach my $lonhost (@newhosts) {
6991: my $formelem = 'loginheadtag_'.$lonhost;
6992: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
6993: "login/headtag/$lonhost",'','',
6994: $env{'form.loginheadtag_'.$lonhost.'.filename'});
6995: if ($result eq 'ok') {
6996: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
6997: $changes{'headtag'}{$lonhost} = 1;
6998: if ($possexempt{$lonhost}) {
6999: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
7000: }
7001: } else {
7002: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
7003: $newheadtagurls{$lonhost},$result);
7004: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
7005: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
7006: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
7007: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
7008: }
7009: }
7010: }
7011: } else {
7012: $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);
7013: }
7014: } else {
7015: $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);
7016: }
7017: if ($error) {
7018: &Apache::lonnet::logthis($error);
7019: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7020: }
7021: }
1.160.6.5 raeburn 7022: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
7023:
7024: my $defaulthelpfile = '/adm/loginproblems.html';
7025: my $defaulttext = &mt('Default in use');
7026:
1.1 raeburn 7027: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
7028: $dom);
7029: if ($putresult eq 'ok') {
1.160.6.14 raeburn 7030: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 7031: my %defaultchecked = (
7032: 'coursecatalog' => 'on',
1.160.6.14 raeburn 7033: 'helpdesk' => 'on',
1.42 raeburn 7034: 'adminmail' => 'off',
1.43 raeburn 7035: 'newuser' => 'off',
1.42 raeburn 7036: );
1.55 raeburn 7037: if (ref($domconfig{'login'}) eq 'HASH') {
7038: foreach my $item (@toggles) {
7039: if ($defaultchecked{$item} eq 'on') {
7040: if (($domconfig{'login'}{$item} eq '0') &&
7041: ($env{'form.'.$item} eq '1')) {
7042: $changes{$item} = 1;
7043: } elsif (($domconfig{'login'}{$item} eq '' ||
7044: $domconfig{'login'}{$item} eq '1') &&
7045: ($env{'form.'.$item} eq '0')) {
7046: $changes{$item} = 1;
7047: }
7048: } elsif ($defaultchecked{$item} eq 'off') {
7049: if (($domconfig{'login'}{$item} eq '1') &&
7050: ($env{'form.'.$item} eq '0')) {
7051: $changes{$item} = 1;
7052: } elsif (($domconfig{'login'}{$item} eq '' ||
7053: $domconfig{'login'}{$item} eq '0') &&
7054: ($env{'form.'.$item} eq '1')) {
7055: $changes{$item} = 1;
7056: }
1.42 raeburn 7057: }
7058: }
1.41 raeburn 7059: }
1.6 raeburn 7060: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 7061: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7062: if (ref($lastactref) eq 'HASH') {
7063: $lastactref->{'domainconfig'} = 1;
7064: }
1.1 raeburn 7065: $resulttext = &mt('Changes made:').'<ul>';
7066: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 7067: if ($item eq 'loginvia') {
1.112 raeburn 7068: if (ref($changes{$item}) eq 'HASH') {
7069: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
7070: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 7071: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
7072: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
7073: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
7074: $protocol = 'http' if ($protocol ne 'https');
7075: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
7076:
7077: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
7078: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
7079: } else {
7080: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
7081: }
7082: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
7083: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
7084: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
7085: }
7086: $resulttext .= '</li>';
7087: } else {
7088: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
7089: }
1.112 raeburn 7090: } else {
1.128 raeburn 7091: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 7092: }
7093: }
1.128 raeburn 7094: $resulttext .= '</ul></li>';
1.112 raeburn 7095: }
1.160.6.5 raeburn 7096: } elsif ($item eq 'helpurl') {
7097: if (ref($changes{$item}) eq 'HASH') {
7098: foreach my $lang (sort(keys(%{$changes{$item}}))) {
7099: if (grep(/^\Q$lang\E$/,@delurls)) {
7100: my ($chg,$link);
7101: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
7102: if ($lang eq 'nolang') {
7103: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
7104: } else {
7105: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
7106: }
7107: $resulttext .= '<li>'.$chg.'</li>';
7108: } else {
7109: my $chg;
7110: if ($lang eq 'nolang') {
7111: $chg = &mt('custom log-in help file for no preferred language');
7112: } else {
7113: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
7114: }
7115: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
7116: $loginhash{'login'}{'helpurl'}{$lang}.
7117: '?inhibitmenu=yes',$chg,600,500).
7118: '</li>';
7119: }
7120: }
7121: }
1.160.6.56 raeburn 7122: } elsif ($item eq 'headtag') {
7123: if (ref($changes{$item}) eq 'HASH') {
7124: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
7125: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
7126: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
7127: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
7128: $resulttext .= '<li><a href="'.
7129: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
7130: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
7131: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
7132: if ($possexempt{$lonhost}) {
7133: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
7134: } else {
7135: $resulttext .= &mt('included for any client IP');
7136: }
7137: $resulttext .= '</li>';
7138: }
7139: }
7140: }
1.160.6.5 raeburn 7141: } elsif ($item eq 'captcha') {
7142: if (ref($loginhash{'login'}) eq 'HASH') {
7143: my $chgtxt;
7144: if ($loginhash{'login'}{$item} eq 'notused') {
7145: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
7146: } else {
7147: my %captchas = &captcha_phrases();
7148: if ($captchas{$loginhash{'login'}{$item}}) {
7149: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
7150: } else {
7151: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
7152: }
7153: }
7154: $resulttext .= '<li>'.$chgtxt.'</li>';
7155: }
7156: } elsif ($item eq 'recaptchakeys') {
7157: if (ref($loginhash{'login'}) eq 'HASH') {
7158: my ($privkey,$pubkey);
7159: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
7160: $pubkey = $loginhash{'login'}{$item}{'public'};
7161: $privkey = $loginhash{'login'}{$item}{'private'};
7162: }
7163: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
7164: if (!$pubkey) {
7165: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
7166: } else {
7167: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7168: }
7169: if (!$privkey) {
7170: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
7171: } else {
1.160.6.53 raeburn 7172: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 7173: }
7174: $chgtxt .= '</ul>';
7175: $resulttext .= '<li>'.$chgtxt.'</li>';
7176: }
1.160.6.69 raeburn 7177: } elsif ($item eq 'recaptchaversion') {
7178: if (ref($loginhash{'login'}) eq 'HASH') {
7179: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
7180: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
7181: '</li>';
7182: }
7183: }
1.41 raeburn 7184: } else {
7185: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
7186: }
1.1 raeburn 7187: }
1.6 raeburn 7188: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 7189: } else {
7190: $resulttext = &mt('No changes made to log-in page settings');
7191: }
7192: } else {
1.11 albertel 7193: $resulttext = '<span class="LC_error">'.
7194: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 7195: }
1.6 raeburn 7196: if ($errors) {
1.9 raeburn 7197: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 7198: $errors.'</ul>';
7199: }
7200: return $resulttext;
7201: }
7202:
1.160.6.56 raeburn 7203: sub check_exempt_addresses {
7204: my ($iplist) = @_;
7205: $iplist =~ s/^\s+//;
7206: $iplist =~ s/\s+$//;
7207: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
7208: my (@okips,$new);
7209: foreach my $ip (@poss_ips) {
7210: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
7211: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
7212: push(@okips,$ip);
7213: }
7214: }
7215: }
7216: if (@okips > 0) {
7217: $new = join(',',@okips);
7218: } else {
7219: $new = '';
7220: }
7221: return $new;
7222: }
7223:
1.6 raeburn 7224: sub color_font_choices {
7225: my %choices =
7226: &Apache::lonlocal::texthash (
7227: img => "Header",
7228: bgs => "Background colors",
7229: links => "Link colors",
1.55 raeburn 7230: images => "Images",
1.6 raeburn 7231: font => "Font color",
1.160.6.22 raeburn 7232: fontmenu => "Font menu",
1.76 raeburn 7233: pgbg => "Page",
1.6 raeburn 7234: tabbg => "Header",
7235: sidebg => "Border",
7236: link => "Link",
7237: alink => "Active link",
7238: vlink => "Visited link",
7239: );
7240: return %choices;
7241: }
7242:
7243: sub modify_rolecolors {
1.160.6.24 raeburn 7244: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 7245: my ($resulttext,%rolehash);
7246: $rolehash{'rolecolors'} = {};
1.55 raeburn 7247: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
7248: if ($domconfig{'rolecolors'} eq '') {
7249: $domconfig{'rolecolors'} = {};
7250: }
7251: }
1.9 raeburn 7252: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 7253: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
7254: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
7255: $dom);
7256: if ($putresult eq 'ok') {
7257: if (keys(%changes) > 0) {
1.41 raeburn 7258: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 7259: if (ref($lastactref) eq 'HASH') {
7260: $lastactref->{'domainconfig'} = 1;
7261: }
1.6 raeburn 7262: $resulttext = &display_colorchgs($dom,\%changes,$roles,
7263: $rolehash{'rolecolors'});
7264: } else {
7265: $resulttext = &mt('No changes made to default color schemes');
7266: }
7267: } else {
1.11 albertel 7268: $resulttext = '<span class="LC_error">'.
7269: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 7270: }
7271: if ($errors) {
7272: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7273: $errors.'</ul>';
7274: }
7275: return $resulttext;
7276: }
7277:
7278: sub modify_colors {
1.9 raeburn 7279: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 7280: my (%changes,%choices);
1.51 raeburn 7281: my @bgs;
1.6 raeburn 7282: my @links = ('link','alink','vlink');
1.41 raeburn 7283: my @logintext;
1.6 raeburn 7284: my @images;
7285: my $servadm = $r->dir_config('lonAdmEMail');
7286: my $errors;
1.160.6.22 raeburn 7287: my %defaults;
1.6 raeburn 7288: foreach my $role (@{$roles}) {
7289: if ($role eq 'login') {
1.12 raeburn 7290: %choices = &login_choices();
1.41 raeburn 7291: @logintext = ('textcol','bgcol');
1.12 raeburn 7292: } else {
7293: %choices = &color_font_choices();
7294: }
7295: if ($role eq 'login') {
1.41 raeburn 7296: @images = ('img','logo','domlogo','login');
1.51 raeburn 7297: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 7298: } else {
7299: @images = ('img');
1.160.6.22 raeburn 7300: @bgs = ('pgbg','tabbg','sidebg');
7301: }
7302: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
7303: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
7304: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
7305: }
7306: if ($role eq 'login') {
7307: foreach my $item (@logintext) {
1.160.6.39 raeburn 7308: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7309: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7310: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7311: }
7312: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 7313: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7314: }
7315: }
7316: } else {
1.160.6.39 raeburn 7317: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
7318: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
7319: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
7320: }
7321: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 7322: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
7323: }
1.6 raeburn 7324: }
1.160.6.22 raeburn 7325: foreach my $item (@bgs) {
1.160.6.39 raeburn 7326: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7327: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7328: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7329: }
7330: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 7331: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7332: }
7333: }
7334: foreach my $item (@links) {
1.160.6.39 raeburn 7335: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
7336: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
7337: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
7338: }
7339: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 7340: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
7341: }
1.6 raeburn 7342: }
1.46 raeburn 7343: my ($configuserok,$author_ok,$switchserver) =
7344: &config_check($dom,$confname,$servadm);
1.9 raeburn 7345: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 7346: if (ref($domconfig->{$role}) ne 'HASH') {
7347: $domconfig->{$role} = {};
7348: }
1.8 raeburn 7349: foreach my $img (@images) {
1.70 raeburn 7350: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
7351: if (defined($env{'form.login_showlogo_'.$img})) {
7352: $confhash->{$role}{'showlogo'}{$img} = 1;
7353: } else {
7354: $confhash->{$role}{'showlogo'}{$img} = 0;
7355: }
7356: }
1.18 albertel 7357: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
7358: && !defined($domconfig->{$role}{$img})
7359: && !$env{'form.'.$role.'_del_'.$img}
7360: && $env{'form.'.$role.'_import_'.$img}) {
7361: # import the old configured image from the .tab setting
7362: # if they haven't provided a new one
7363: $domconfig->{$role}{$img} =
7364: $env{'form.'.$role.'_import_'.$img};
7365: }
1.6 raeburn 7366: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 7367: my $error;
1.6 raeburn 7368: if ($configuserok eq 'ok') {
1.9 raeburn 7369: if ($switchserver) {
1.12 raeburn 7370: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 7371: } else {
7372: if ($author_ok eq 'ok') {
7373: my ($result,$logourl) =
7374: &publishlogo($r,'upload',$role.'_'.$img,
7375: $dom,$confname,$img,$width,$height);
7376: if ($result eq 'ok') {
7377: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 7378: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7379: } else {
1.12 raeburn 7380: $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 7381: }
7382: } else {
1.46 raeburn 7383: $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 7384: }
7385: }
7386: } else {
1.46 raeburn 7387: $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 7388: }
7389: if ($error) {
1.8 raeburn 7390: &Apache::lonnet::logthis($error);
1.11 albertel 7391: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 7392: }
7393: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 7394: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
7395: my $error;
7396: if ($configuserok eq 'ok') {
7397: # is confname an author?
7398: if ($switchserver eq '') {
7399: if ($author_ok eq 'ok') {
7400: my ($result,$logourl) =
7401: &publishlogo($r,'copy',$domconfig->{$role}{$img},
7402: $dom,$confname,$img,$width,$height);
7403: if ($result eq 'ok') {
7404: $confhash->{$role}{$img} = $logourl;
1.18 albertel 7405: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 7406: }
7407: }
7408: }
7409: }
1.6 raeburn 7410: }
7411: }
7412: }
7413: if (ref($domconfig) eq 'HASH') {
7414: if (ref($domconfig->{$role}) eq 'HASH') {
7415: foreach my $img (@images) {
7416: if ($domconfig->{$role}{$img} ne '') {
7417: if ($env{'form.'.$role.'_del_'.$img}) {
7418: $confhash->{$role}{$img} = '';
1.12 raeburn 7419: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7420: } else {
1.9 raeburn 7421: if ($confhash->{$role}{$img} eq '') {
7422: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
7423: }
1.6 raeburn 7424: }
7425: } else {
7426: if ($env{'form.'.$role.'_del_'.$img}) {
7427: $confhash->{$role}{$img} = '';
1.12 raeburn 7428: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 7429: }
7430: }
1.70 raeburn 7431: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
7432: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
7433: if ($confhash->{$role}{'showlogo'}{$img} ne
7434: $domconfig->{$role}{'showlogo'}{$img}) {
7435: $changes{$role}{'showlogo'}{$img} = 1;
7436: }
7437: } else {
7438: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7439: $changes{$role}{'showlogo'}{$img} = 1;
7440: }
7441: }
7442: }
7443: }
1.6 raeburn 7444: if ($domconfig->{$role}{'font'} ne '') {
7445: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
7446: $changes{$role}{'font'} = 1;
7447: }
7448: } else {
7449: if ($confhash->{$role}{'font'}) {
7450: $changes{$role}{'font'} = 1;
7451: }
7452: }
1.107 raeburn 7453: if ($role ne 'login') {
7454: if ($domconfig->{$role}{'fontmenu'} ne '') {
7455: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
7456: $changes{$role}{'fontmenu'} = 1;
7457: }
7458: } else {
7459: if ($confhash->{$role}{'fontmenu'}) {
7460: $changes{$role}{'fontmenu'} = 1;
7461: }
1.97 tempelho 7462: }
7463: }
1.6 raeburn 7464: foreach my $item (@bgs) {
7465: if ($domconfig->{$role}{$item} ne '') {
7466: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7467: $changes{$role}{'bgs'}{$item} = 1;
7468: }
7469: } else {
7470: if ($confhash->{$role}{$item}) {
7471: $changes{$role}{'bgs'}{$item} = 1;
7472: }
7473: }
7474: }
7475: foreach my $item (@links) {
7476: if ($domconfig->{$role}{$item} ne '') {
7477: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7478: $changes{$role}{'links'}{$item} = 1;
7479: }
7480: } else {
7481: if ($confhash->{$role}{$item}) {
7482: $changes{$role}{'links'}{$item} = 1;
7483: }
7484: }
7485: }
1.41 raeburn 7486: foreach my $item (@logintext) {
7487: if ($domconfig->{$role}{$item} ne '') {
7488: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
7489: $changes{$role}{'logintext'}{$item} = 1;
7490: }
7491: } else {
7492: if ($confhash->{$role}{$item}) {
7493: $changes{$role}{'logintext'}{$item} = 1;
7494: }
7495: }
7496: }
1.6 raeburn 7497: } else {
7498: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7499: \@logintext,$confhash,\%changes);
1.6 raeburn 7500: }
7501: } else {
7502: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 7503: \@logintext,$confhash,\%changes);
1.6 raeburn 7504: }
7505: }
7506: return ($errors,%changes);
7507: }
7508:
1.46 raeburn 7509: sub config_check {
7510: my ($dom,$confname,$servadm) = @_;
7511: my ($configuserok,$author_ok,$switchserver,%currroles);
7512: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
7513: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
7514: $confname,$servadm);
7515: if ($configuserok eq 'ok') {
7516: $switchserver = &check_switchserver($dom,$confname);
7517: if ($switchserver eq '') {
7518: $author_ok = &check_authorstatus($dom,$confname,%currroles);
7519: }
7520: }
7521: return ($configuserok,$author_ok,$switchserver);
7522: }
7523:
1.6 raeburn 7524: sub default_change_checker {
1.41 raeburn 7525: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 7526: foreach my $item (@{$links}) {
7527: if ($confhash->{$role}{$item}) {
7528: $changes->{$role}{'links'}{$item} = 1;
7529: }
7530: }
7531: foreach my $item (@{$bgs}) {
7532: if ($confhash->{$role}{$item}) {
7533: $changes->{$role}{'bgs'}{$item} = 1;
7534: }
7535: }
1.41 raeburn 7536: foreach my $item (@{$logintext}) {
7537: if ($confhash->{$role}{$item}) {
7538: $changes->{$role}{'logintext'}{$item} = 1;
7539: }
7540: }
1.6 raeburn 7541: foreach my $img (@{$images}) {
7542: if ($env{'form.'.$role.'_del_'.$img}) {
7543: $confhash->{$role}{$img} = '';
1.12 raeburn 7544: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 7545: }
1.70 raeburn 7546: if ($role eq 'login') {
7547: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
7548: $changes->{$role}{'showlogo'}{$img} = 1;
7549: }
7550: }
1.6 raeburn 7551: }
7552: if ($confhash->{$role}{'font'}) {
7553: $changes->{$role}{'font'} = 1;
7554: }
1.48 raeburn 7555: }
1.6 raeburn 7556:
7557: sub display_colorchgs {
7558: my ($dom,$changes,$roles,$confhash) = @_;
7559: my (%choices,$resulttext);
7560: if (!grep(/^login$/,@{$roles})) {
7561: $resulttext = &mt('Changes made:').'<br />';
7562: }
7563: foreach my $role (@{$roles}) {
7564: if ($role eq 'login') {
7565: %choices = &login_choices();
7566: } else {
7567: %choices = &color_font_choices();
7568: }
7569: if (ref($changes->{$role}) eq 'HASH') {
7570: if ($role ne 'login') {
7571: $resulttext .= '<h4>'.&mt($role).'</h4>';
7572: }
7573: foreach my $key (sort(keys(%{$changes->{$role}}))) {
7574: if ($role ne 'login') {
7575: $resulttext .= '<ul>';
7576: }
7577: if (ref($changes->{$role}{$key}) eq 'HASH') {
7578: if ($role ne 'login') {
7579: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
7580: }
7581: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 7582: if (($role eq 'login') && ($key eq 'showlogo')) {
7583: if ($confhash->{$role}{$key}{$item}) {
7584: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
7585: } else {
7586: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
7587: }
7588: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 7589: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
7590: } else {
1.12 raeburn 7591: my $newitem = $confhash->{$role}{$item};
7592: if ($key eq 'images') {
7593: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
7594: }
7595: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 7596: }
7597: }
7598: if ($role ne 'login') {
7599: $resulttext .= '</ul></li>';
7600: }
7601: } else {
7602: if ($confhash->{$role}{$key} eq '') {
7603: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
7604: } else {
7605: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
7606: }
7607: }
7608: if ($role ne 'login') {
7609: $resulttext .= '</ul>';
7610: }
7611: }
7612: }
7613: }
1.3 raeburn 7614: return $resulttext;
1.1 raeburn 7615: }
7616:
1.9 raeburn 7617: sub thumb_dimensions {
7618: return ('200','50');
7619: }
7620:
1.16 raeburn 7621: sub check_dimensions {
7622: my ($inputfile) = @_;
7623: my ($fullwidth,$fullheight);
7624: if ($inputfile =~ m|^[/\w.\-]+$|) {
7625: if (open(PIPE,"identify $inputfile 2>&1 |")) {
7626: my $imageinfo = <PIPE>;
7627: if (!close(PIPE)) {
7628: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
7629: }
7630: chomp($imageinfo);
7631: my ($fullsize) =
1.21 raeburn 7632: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 7633: if ($fullsize) {
7634: ($fullwidth,$fullheight) = split(/x/,$fullsize);
7635: }
7636: }
7637: }
7638: return ($fullwidth,$fullheight);
7639: }
7640:
1.9 raeburn 7641: sub check_configuser {
7642: my ($uhome,$dom,$confname,$servadm) = @_;
7643: my ($configuserok,%currroles);
7644: if ($uhome eq 'no_host') {
7645: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
7646: my $configpass = &LONCAPA::Enrollment::create_password();
7647: $configuserok =
7648: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
7649: $configpass,'','','','','',undef,$servadm);
7650: } else {
7651: $configuserok = 'ok';
7652: %currroles =
7653: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
7654: }
7655: return ($configuserok,%currroles);
7656: }
7657:
7658: sub check_authorstatus {
7659: my ($dom,$confname,%currroles) = @_;
7660: my $author_ok;
1.40 raeburn 7661: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 7662: my $start = time;
7663: my $end = 0;
7664: $author_ok =
7665: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 7666: 'au',$end,$start,'','','domconfig');
1.9 raeburn 7667: } else {
7668: $author_ok = 'ok';
7669: }
7670: return $author_ok;
7671: }
7672:
7673: sub publishlogo {
1.46 raeburn 7674: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 7675: my ($output,$fname,$logourl);
7676: if ($action eq 'upload') {
7677: $fname=$env{'form.'.$formname.'.filename'};
7678: chop($env{'form.'.$formname});
7679: } else {
7680: ($fname) = ($formname =~ /([^\/]+)$/);
7681: }
1.46 raeburn 7682: if ($savefileas ne '') {
7683: $fname = $savefileas;
7684: }
1.9 raeburn 7685: $fname=&Apache::lonnet::clean_filename($fname);
7686: # See if there is anything left
7687: unless ($fname) { return ('error: no uploaded file'); }
7688: $fname="$subdir/$fname";
1.160.6.5 raeburn 7689: my $docroot=$r->dir_config('lonDocRoot');
7690: my $filepath="$docroot/priv";
7691: my $relpath = "$dom/$confname";
1.9 raeburn 7692: my ($fnamepath,$file,$fetchthumb);
7693: $file=$fname;
7694: if ($fname=~m|/|) {
7695: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
7696: }
1.160.6.26 raeburn 7697: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 7698: my $count;
1.160.6.5 raeburn 7699: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 7700: $filepath.="/$parts[$count]";
7701: if ((-e $filepath)!=1) {
7702: mkdir($filepath,02770);
7703: }
7704: }
7705: # Check for bad extension and disallow upload
7706: if ($file=~/\.(\w+)$/ &&
7707: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
7708: $output =
1.160.6.25 raeburn 7709: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 7710: } elsif ($file=~/\.(\w+)$/ &&
7711: !defined(&Apache::loncommon::fileembstyle($1))) {
7712: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
7713: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 7714: $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 7715: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 7716: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 7717: } else {
7718: my $source = $filepath.'/'.$file;
7719: my $logfile;
1.160.6.88! raeburn 7720: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 7721: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 7722: }
7723: print $logfile
7724: "\n================= Publish ".localtime()." ================\n".
7725: $env{'user.name'}.':'.$env{'user.domain'}."\n";
7726: # Save the file
1.160.6.88! raeburn 7727: if (!open(FH,">",$source)) {
1.9 raeburn 7728: &Apache::lonnet::logthis('Failed to create '.$source);
7729: return (&mt('Failed to create file'));
7730: }
7731: if ($action eq 'upload') {
7732: if (!print FH ($env{'form.'.$formname})) {
7733: &Apache::lonnet::logthis('Failed to write to '.$source);
7734: return (&mt('Failed to write file'));
7735: }
7736: } else {
7737: my $original = &Apache::lonnet::filelocation('',$formname);
7738: if(!copy($original,$source)) {
7739: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
7740: return (&mt('Failed to write file'));
7741: }
7742: }
7743: close(FH);
7744: chmod(0660, $source); # Permissions to rw-rw---.
7745:
7746: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
7747: my $copyfile=$targetdir.'/'.$file;
7748:
7749: my @parts=split(/\//,$targetdir);
7750: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
7751: for (my $count=5;$count<=$#parts;$count++) {
7752: $path.="/$parts[$count]";
7753: if (!-e $path) {
7754: print $logfile "\nCreating directory ".$path;
7755: mkdir($path,02770);
7756: }
7757: }
7758: my $versionresult;
7759: if (-e $copyfile) {
7760: $versionresult = &logo_versioning($targetdir,$file,$logfile);
7761: } else {
7762: $versionresult = 'ok';
7763: }
7764: if ($versionresult eq 'ok') {
7765: if (copy($source,$copyfile)) {
7766: print $logfile "\nCopied original source to ".$copyfile."\n";
7767: $output = 'ok';
7768: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 7769: push(@{$modified_urls},[$copyfile,$source]);
7770: my $metaoutput =
7771: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
7772: unless ($registered_cleanup) {
7773: my $handlers = $r->get_handlers('PerlCleanupHandler');
7774: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7775: $registered_cleanup=1;
7776: }
1.9 raeburn 7777: } else {
7778: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
7779: $output = &mt('Failed to copy file to RES space').", $!";
7780: }
7781: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
7782: my $inputfile = $filepath.'/'.$file;
7783: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 7784: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
7785: if ($fullwidth ne '' && $fullheight ne '') {
7786: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
7787: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88! raeburn 7788: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
! 7789: system({$args[0]} @args);
1.16 raeburn 7790: chmod(0660, $filepath.'/tn-'.$file);
7791: if (-e $outfile) {
7792: my $copyfile=$targetdir.'/tn-'.$file;
7793: if (copy($outfile,$copyfile)) {
7794: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 7795: my $thumb_metaoutput =
7796: &write_metadata($dom,$confname,$formname,
7797: $targetdir,'tn-'.$file,$logfile);
7798: push(@{$modified_urls},[$copyfile,$outfile]);
7799: unless ($registered_cleanup) {
7800: my $handlers = $r->get_handlers('PerlCleanupHandler');
7801: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
7802: $registered_cleanup=1;
7803: }
1.16 raeburn 7804: } else {
7805: print $logfile "\nUnable to write ".$copyfile.
7806: ':'.$!."\n";
7807: }
7808: }
1.9 raeburn 7809: }
7810: }
7811: }
7812: } else {
7813: $output = $versionresult;
7814: }
7815: }
7816: return ($output,$logourl);
7817: }
7818:
7819: sub logo_versioning {
7820: my ($targetdir,$file,$logfile) = @_;
7821: my $target = $targetdir.'/'.$file;
7822: my ($maxversion,$fn,$extn,$output);
7823: $maxversion = 0;
7824: if ($file =~ /^(.+)\.(\w+)$/) {
7825: $fn=$1;
7826: $extn=$2;
7827: }
7828: opendir(DIR,$targetdir);
7829: while (my $filename=readdir(DIR)) {
7830: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
7831: $maxversion=($1>$maxversion)?$1:$maxversion;
7832: }
7833: }
7834: $maxversion++;
7835: print $logfile "\nCreating old version ".$maxversion."\n";
7836: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
7837: if (copy($target,$copyfile)) {
7838: print $logfile "Copied old target to ".$copyfile."\n";
7839: $copyfile=$copyfile.'.meta';
7840: if (copy($target.'.meta',$copyfile)) {
7841: print $logfile "Copied old target metadata to ".$copyfile."\n";
7842: $output = 'ok';
7843: } else {
7844: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
7845: $output = &mt('Failed to copy old meta').", $!, ";
7846: }
7847: } else {
7848: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
7849: $output = &mt('Failed to copy old target').", $!, ";
7850: }
7851: return $output;
7852: }
7853:
7854: sub write_metadata {
7855: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
7856: my (%metadatafields,%metadatakeys,$output);
7857: $metadatafields{'title'}=$formname;
7858: $metadatafields{'creationdate'}=time;
7859: $metadatafields{'lastrevisiondate'}=time;
7860: $metadatafields{'copyright'}='public';
7861: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
7862: $env{'user.domain'};
7863: $metadatafields{'authorspace'}=$confname.':'.$dom;
7864: $metadatafields{'domain'}=$dom;
7865: {
7866: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
7867: my $mfh;
1.160.6.88! raeburn 7868: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 7869: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 7870: unless ($_=~/\./) {
7871: my $unikey=$_;
7872: $unikey=~/^([A-Za-z]+)/;
7873: my $tag=$1;
7874: $tag=~tr/A-Z/a-z/;
7875: print $mfh "\n\<$tag";
7876: foreach (split(/\,/,$metadatakeys{$unikey})) {
7877: my $value=$metadatafields{$unikey.'.'.$_};
7878: $value=~s/\"/\'\'/g;
7879: print $mfh ' '.$_.'="'.$value.'"';
7880: }
7881: print $mfh '>'.
7882: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
7883: .'</'.$tag.'>';
7884: }
7885: }
7886: $output = 'ok';
7887: print $logfile "\nWrote metadata";
7888: close($mfh);
7889: } else {
7890: print $logfile "\nFailed to open metadata file";
1.9 raeburn 7891: $output = &mt('Could not write metadata');
7892: }
7893: }
1.155 raeburn 7894: return $output;
7895: }
7896:
7897: sub notifysubscribed {
7898: foreach my $targetsource (@{$modified_urls}){
7899: next unless (ref($targetsource) eq 'ARRAY');
7900: my ($target,$source)=@{$targetsource};
7901: if ($source ne '') {
1.160.6.88! raeburn 7902: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 7903: print $logfh "\nCleanup phase: Notifications\n";
7904: my @subscribed=&subscribed_hosts($target);
7905: foreach my $subhost (@subscribed) {
7906: print $logfh "\nNotifying host ".$subhost.':';
7907: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
7908: print $logfh $reply;
7909: }
7910: my @subscribedmeta=&subscribed_hosts("$target.meta");
7911: foreach my $subhost (@subscribedmeta) {
7912: print $logfh "\nNotifying host for metadata only ".$subhost.':';
7913: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
7914: $subhost);
7915: print $logfh $reply;
7916: }
7917: print $logfh "\n============ Done ============\n";
1.160 raeburn 7918: close($logfh);
1.155 raeburn 7919: }
7920: }
7921: }
7922: return OK;
7923: }
7924:
7925: sub subscribed_hosts {
7926: my ($target) = @_;
7927: my @subscribed;
1.160.6.88! raeburn 7928: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 7929: while (my $subline=<$fh>) {
7930: if ($subline =~ /^($match_lonid):/) {
7931: my $host = $1;
7932: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
7933: unless (grep(/^\Q$host\E$/,@subscribed)) {
7934: push(@subscribed,$host);
7935: }
7936: }
7937: }
7938: }
7939: }
7940: return @subscribed;
1.9 raeburn 7941: }
7942:
7943: sub check_switchserver {
7944: my ($dom,$confname) = @_;
7945: my ($allowed,$switchserver);
7946: my $home = &Apache::lonnet::homeserver($confname,$dom);
7947: if ($home eq 'no_host') {
7948: $home = &Apache::lonnet::domain($dom,'primary');
7949: }
7950: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 7951: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
7952: if (!$allowed) {
1.160.6.11 raeburn 7953: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 7954: }
7955: return $switchserver;
7956: }
7957:
1.1 raeburn 7958: sub modify_quotas {
1.160.6.30 raeburn 7959: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 7960: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 7961: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 7962: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
7963: $validationfieldsref);
1.86 raeburn 7964: if ($action eq 'quotas') {
7965: $context = 'tools';
1.160.6.26 raeburn 7966: } else {
1.86 raeburn 7967: $context = $action;
7968: }
7969: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 7970: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 7971: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 7972: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
7973: %titles = &courserequest_titles();
7974: $toolregexp = join('|',@usertools);
7975: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 7976: $confname = $dom.'-domainconfig';
7977: my $servadm = $r->dir_config('lonAdmEMail');
7978: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 7979: ($validationitemsref,$validationnamesref,$validationfieldsref) =
7980: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 7981: } elsif ($context eq 'requestauthor') {
7982: @usertools = ('author');
7983: %titles = &authorrequest_titles();
1.86 raeburn 7984: } else {
1.160.6.4 raeburn 7985: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 7986: %titles = &tool_titles();
1.86 raeburn 7987: }
1.160.6.27 raeburn 7988: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 7989: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 7990: foreach my $key (keys(%env)) {
1.101 raeburn 7991: if ($context eq 'requestcourses') {
7992: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
7993: my $item = $1;
7994: my $type = $2;
7995: if ($type =~ /^limit_(.+)/) {
7996: $limithash{$item}{$1} = $env{$key};
7997: } else {
7998: $confhash{$item}{$type} = $env{$key};
7999: }
8000: }
1.160.6.5 raeburn 8001: } elsif ($context eq 'requestauthor') {
8002: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
8003: $confhash{$1} = $env{$key};
8004: }
1.101 raeburn 8005: } else {
1.86 raeburn 8006: if ($key =~ /^form\.quota_(.+)$/) {
8007: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 8008: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
8009: $confhash{'authorquota'}{$1} = $env{$key};
8010: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 8011: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
8012: }
1.72 raeburn 8013: }
8014: }
1.160.6.5 raeburn 8015: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 8016: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 8017: @approvalnotify = sort(@approvalnotify);
8018: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 8019: my @crstypes = ('official','unofficial','community','textbook');
8020: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
8021: foreach my $type (@hasuniquecode) {
8022: if (grep(/^\Q$type\E$/,@crstypes)) {
8023: $confhash{'uniquecode'}{$type} = 1;
8024: }
8025: }
1.160.6.46 raeburn 8026: my (%newbook,%allpos);
1.160.6.30 raeburn 8027: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8028: foreach my $type ('textbooks','templates') {
8029: @{$allpos{$type}} = ();
8030: my $invalid;
8031: if ($type eq 'textbooks') {
8032: $invalid = &mt('Invalid LON-CAPA course for textbook');
8033: } else {
8034: $invalid = &mt('Invalid LON-CAPA course for template');
8035: }
8036: if ($env{'form.'.$type.'_addbook'}) {
8037: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
8038: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
8039: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
8040: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
8041: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
8042: } else {
8043: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
8044: my $position = $env{'form.'.$type.'_addbook_pos'};
8045: $position =~ s/\D+//g;
8046: if ($position ne '') {
8047: $allpos{$type}[$position] = $newbook{$type};
8048: }
1.160.6.30 raeburn 8049: }
1.160.6.46 raeburn 8050: } else {
8051: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 8052: }
8053: }
1.160.6.46 raeburn 8054: }
1.160.6.30 raeburn 8055: }
1.102 raeburn 8056: if (ref($domconfig{$action}) eq 'HASH') {
8057: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
8058: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
8059: $changes{'notify'}{'approval'} = 1;
8060: }
8061: } else {
1.144 raeburn 8062: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8063: $changes{'notify'}{'approval'} = 1;
8064: }
8065: }
1.160.6.30 raeburn 8066: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
8067: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8068: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
8069: unless ($confhash{'uniquecode'}{$crstype}) {
8070: $changes{'uniquecode'} = 1;
8071: }
8072: }
8073: unless ($changes{'uniquecode'}) {
8074: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
8075: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
8076: $changes{'uniquecode'} = 1;
8077: }
8078: }
8079: }
8080: } else {
8081: $changes{'uniquecode'} = 1;
8082: }
8083: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
8084: $changes{'uniquecode'} = 1;
8085: }
8086: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8087: foreach my $type ('textbooks','templates') {
8088: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8089: my %deletions;
8090: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
8091: if (@todelete) {
8092: map { $deletions{$_} = 1; } @todelete;
8093: }
8094: my %imgdeletions;
8095: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
8096: if (@todeleteimages) {
8097: map { $imgdeletions{$_} = 1; } @todeleteimages;
8098: }
8099: my $maxnum = $env{'form.'.$type.'_maxnum'};
8100: for (my $i=0; $i<=$maxnum; $i++) {
8101: my $itemid = $env{'form.'.$type.'_id_'.$i};
8102: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
8103: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
8104: if ($deletions{$key}) {
8105: if ($domconfig{$action}{$type}{$key}{'image'}) {
8106: #FIXME need to obsolete item in RES space
8107: }
8108: next;
8109: } else {
8110: my $newpos = $env{'form.'.$itemid};
8111: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 8112: foreach my $item ('subject','title','publisher','author') {
8113: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8114: ($type eq 'templates'));
1.160.6.46 raeburn 8115: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
8116: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
8117: $changes{$type}{$key} = 1;
8118: }
8119: }
8120: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 8121: }
1.160.6.46 raeburn 8122: if ($imgdeletions{$key}) {
8123: $changes{$type}{$key} = 1;
8124: #FIXME need to obsolete item in RES space
8125: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
8126: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88! raeburn 8127: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
! 8128: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
! 8129: } else {
! 8130: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
! 8131: $cdom,$cnum,$type,$configuserok,
! 8132: $switchserver,$author_ok);
! 8133: if ($imgurl) {
! 8134: $confhash{$type}{$key}{'image'} = $imgurl;
! 8135: $changes{$type}{$key} = 1;
! 8136: }
! 8137: if ($error) {
! 8138: &Apache::lonnet::logthis($error);
! 8139: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
! 8140: }
1.160.6.46 raeburn 8141: }
8142: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
8143: $confhash{$type}{$key}{'image'} =
8144: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 8145: }
8146: }
8147: }
8148: }
8149: }
8150: }
1.102 raeburn 8151: } else {
1.144 raeburn 8152: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 8153: $changes{'notify'}{'approval'} = 1;
8154: }
1.160.6.30 raeburn 8155: if (ref($confhash{'uniquecode'} eq 'HASH')) {
8156: $changes{'uniquecode'} = 1;
8157: }
8158: }
8159: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 8160: foreach my $type ('textbooks','templates') {
8161: if ($newbook{$type}) {
8162: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 8163: foreach my $item ('subject','title','publisher','author') {
8164: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8165: ($type eq 'template'));
1.160.6.46 raeburn 8166: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
8167: if ($env{'form.'.$type.'_addbook_'.$item}) {
8168: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
8169: }
8170: }
8171: if ($type eq 'textbooks') {
8172: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
8173: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88! raeburn 8174: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
! 8175: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
! 8176: } else {
! 8177: my ($imageurl,$error) =
! 8178: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
! 8179: $configuserok,$switchserver,$author_ok);
! 8180: if ($imageurl) {
! 8181: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
! 8182: }
! 8183: if ($error) {
! 8184: &Apache::lonnet::logthis($error);
! 8185: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
! 8186: }
1.160.6.46 raeburn 8187: }
8188: }
1.160.6.30 raeburn 8189: }
8190: }
1.160.6.46 raeburn 8191: if (@{$allpos{$type}} > 0) {
8192: my $idx = 0;
8193: foreach my $item (@{$allpos{$type}}) {
8194: if ($item ne '') {
8195: $confhash{$type}{$item}{'order'} = $idx;
8196: if (ref($domconfig{$action}) eq 'HASH') {
8197: if (ref($domconfig{$action}{$type}) eq 'HASH') {
8198: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
8199: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
8200: $changes{$type}{$item} = 1;
8201: }
1.160.6.30 raeburn 8202: }
8203: }
8204: }
1.160.6.46 raeburn 8205: $idx ++;
1.160.6.30 raeburn 8206: }
8207: }
8208: }
8209: }
1.160.6.39 raeburn 8210: if (ref($validationitemsref) eq 'ARRAY') {
8211: foreach my $item (@{$validationitemsref}) {
8212: if ($item eq 'fields') {
8213: my @changed;
8214: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
8215: if (@{$confhash{'validation'}{$item}} > 0) {
8216: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
8217: }
1.160.6.65 raeburn 8218: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8219: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8220: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
8221: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
8222: $domconfig{'requestcourses'}{'validation'}{$item});
8223: } else {
8224: @changed = @{$confhash{'validation'}{$item}};
8225: }
1.160.6.39 raeburn 8226: } else {
8227: @changed = @{$confhash{'validation'}{$item}};
8228: }
8229: } else {
8230: @changed = @{$confhash{'validation'}{$item}};
8231: }
8232: if (@changed) {
8233: if ($confhash{'validation'}{$item}) {
8234: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
8235: } else {
8236: $changes{'validation'}{$item} = &mt('None');
8237: }
8238: }
8239: } else {
8240: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
8241: if ($item eq 'markup') {
8242: if ($env{'form.requestcourses_validation_'.$item}) {
8243: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
8244: }
8245: }
1.160.6.65 raeburn 8246: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8247: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8248: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
8249: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8250: }
8251: } else {
8252: if ($confhash{'validation'}{$item} ne '') {
8253: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8254: }
1.160.6.39 raeburn 8255: }
8256: } else {
8257: if ($confhash{'validation'}{$item} ne '') {
8258: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
8259: }
8260: }
8261: }
8262: }
8263: }
8264: if ($env{'form.validationdc'}) {
8265: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 8266: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 8267: if (exists($domcoords{$newval})) {
8268: $confhash{'validation'}{'dc'} = $newval;
8269: }
8270: }
8271: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 8272: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8273: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8274: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8275: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
8276: if ($confhash{'validation'}{'dc'} eq '') {
8277: $changes{'validation'}{'dc'} = &mt('None');
8278: } else {
8279: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8280: }
1.160.6.39 raeburn 8281: }
1.160.6.65 raeburn 8282: } elsif ($confhash{'validation'}{'dc'} ne '') {
8283: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 8284: }
8285: } elsif ($confhash{'validation'}{'dc'} ne '') {
8286: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8287: }
8288: } elsif ($confhash{'validation'}{'dc'} ne '') {
8289: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
8290: }
1.160.6.65 raeburn 8291: } else {
8292: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
8293: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
8294: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
8295: $changes{'validation'}{'dc'} = &mt('None');
8296: }
8297: }
1.160.6.39 raeburn 8298: }
8299: }
1.102 raeburn 8300: }
8301: } else {
1.86 raeburn 8302: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 8303: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 8304: }
1.72 raeburn 8305: foreach my $item (@usertools) {
8306: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 8307: my $unset;
1.101 raeburn 8308: if ($context eq 'requestcourses') {
1.104 raeburn 8309: $unset = '0';
8310: if ($type eq '_LC_adv') {
8311: $unset = '';
8312: }
1.101 raeburn 8313: if ($confhash{$item}{$type} eq 'autolimit') {
8314: $confhash{$item}{$type} .= '=';
8315: unless ($limithash{$item}{$type} =~ /\D/) {
8316: $confhash{$item}{$type} .= $limithash{$item}{$type};
8317: }
8318: }
1.160.6.5 raeburn 8319: } elsif ($context eq 'requestauthor') {
8320: $unset = '0';
8321: if ($type eq '_LC_adv') {
8322: $unset = '';
8323: }
1.72 raeburn 8324: } else {
1.101 raeburn 8325: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
8326: $confhash{$item}{$type} = 1;
8327: } else {
8328: $confhash{$item}{$type} = 0;
8329: }
1.72 raeburn 8330: }
1.86 raeburn 8331: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 8332: if ($action eq 'requestauthor') {
8333: if ($domconfig{$action}{$type} ne $confhash{$type}) {
8334: $changes{$type} = 1;
8335: }
8336: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 8337: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
8338: $changes{$item}{$type} = 1;
8339: }
8340: } else {
8341: if ($context eq 'requestcourses') {
1.104 raeburn 8342: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 8343: $changes{$item}{$type} = 1;
8344: }
8345: } else {
8346: if (!$confhash{$item}{$type}) {
8347: $changes{$item}{$type} = 1;
8348: }
8349: }
8350: }
8351: } else {
8352: if ($context eq 'requestcourses') {
1.104 raeburn 8353: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 8354: $changes{$item}{$type} = 1;
8355: }
1.160.6.5 raeburn 8356: } elsif ($context eq 'requestauthor') {
8357: if ($confhash{$type} ne $unset) {
8358: $changes{$type} = 1;
8359: }
1.72 raeburn 8360: } else {
8361: if (!$confhash{$item}{$type}) {
8362: $changes{$item}{$type} = 1;
8363: }
8364: }
8365: }
1.1 raeburn 8366: }
8367: }
1.160.6.5 raeburn 8368: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 8369: if (ref($domconfig{'quotas'}) eq 'HASH') {
8370: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8371: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
8372: if (exists($confhash{'defaultquota'}{$key})) {
8373: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
8374: $changes{'defaultquota'}{$key} = 1;
8375: }
8376: } else {
8377: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 8378: }
8379: }
1.86 raeburn 8380: } else {
8381: foreach my $key (keys(%{$domconfig{'quotas'}})) {
8382: if (exists($confhash{'defaultquota'}{$key})) {
8383: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
8384: $changes{'defaultquota'}{$key} = 1;
8385: }
8386: } else {
8387: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 8388: }
1.1 raeburn 8389: }
8390: }
1.160.6.20 raeburn 8391: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8392: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
8393: if (exists($confhash{'authorquota'}{$key})) {
8394: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
8395: $changes{'authorquota'}{$key} = 1;
8396: }
8397: } else {
8398: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
8399: }
8400: }
8401: }
1.1 raeburn 8402: }
1.86 raeburn 8403: if (ref($confhash{'defaultquota'}) eq 'HASH') {
8404: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
8405: if (ref($domconfig{'quotas'}) eq 'HASH') {
8406: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
8407: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
8408: $changes{'defaultquota'}{$key} = 1;
8409: }
8410: } else {
8411: if (!exists($domconfig{'quotas'}{$key})) {
8412: $changes{'defaultquota'}{$key} = 1;
8413: }
1.72 raeburn 8414: }
8415: } else {
1.86 raeburn 8416: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 8417: }
1.1 raeburn 8418: }
8419: }
1.160.6.20 raeburn 8420: if (ref($confhash{'authorquota'}) eq 'HASH') {
8421: foreach my $key (keys(%{$confhash{'authorquota'}})) {
8422: if (ref($domconfig{'quotas'}) eq 'HASH') {
8423: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
8424: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
8425: $changes{'authorquota'}{$key} = 1;
8426: }
8427: } else {
8428: $changes{'authorquota'}{$key} = 1;
8429: }
8430: } else {
8431: $changes{'authorquota'}{$key} = 1;
8432: }
8433: }
8434: }
1.1 raeburn 8435: }
1.72 raeburn 8436:
1.160.6.5 raeburn 8437: if ($context eq 'requestauthor') {
8438: $domdefaults{'requestauthor'} = \%confhash;
8439: } else {
8440: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 8441: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 8442: $domdefaults{$key} = $confhash{$key};
8443: }
1.160.6.5 raeburn 8444: }
1.72 raeburn 8445: }
1.160.6.5 raeburn 8446:
1.1 raeburn 8447: my %quotahash = (
1.86 raeburn 8448: $action => { %confhash }
1.1 raeburn 8449: );
8450: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
8451: $dom);
8452: if ($putresult eq 'ok') {
8453: if (keys(%changes) > 0) {
1.72 raeburn 8454: my $cachetime = 24*60*60;
8455: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 8456: if (ref($lastactref) eq 'HASH') {
8457: $lastactref->{'domdefaults'} = 1;
8458: }
1.1 raeburn 8459: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 8460: unless (($context eq 'requestcourses') ||
8461: ($context eq 'requestauthor')) {
1.86 raeburn 8462: if (ref($changes{'defaultquota'}) eq 'HASH') {
8463: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
8464: foreach my $type (@{$types},'default') {
8465: if (defined($changes{'defaultquota'}{$type})) {
8466: my $typetitle = $usertypes->{$type};
8467: if ($type eq 'default') {
8468: $typetitle = $othertitle;
8469: }
1.160.6.28 raeburn 8470: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 8471: }
8472: }
1.86 raeburn 8473: $resulttext .= '</ul></li>';
1.72 raeburn 8474: }
1.160.6.20 raeburn 8475: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 8476: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 8477: foreach my $type (@{$types},'default') {
8478: if (defined($changes{'authorquota'}{$type})) {
8479: my $typetitle = $usertypes->{$type};
8480: if ($type eq 'default') {
8481: $typetitle = $othertitle;
8482: }
1.160.6.28 raeburn 8483: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 8484: }
8485: }
8486: $resulttext .= '</ul></li>';
8487: }
1.72 raeburn 8488: }
1.80 raeburn 8489: my %newenv;
1.72 raeburn 8490: foreach my $item (@usertools) {
1.160.6.5 raeburn 8491: my (%haschgs,%inconf);
8492: if ($context eq 'requestauthor') {
8493: %haschgs = %changes;
8494: %inconf = %confhash;
8495: } else {
8496: if (ref($changes{$item}) eq 'HASH') {
8497: %haschgs = %{$changes{$item}};
8498: }
8499: if (ref($confhash{$item}) eq 'HASH') {
8500: %inconf = %{$confhash{$item}};
8501: }
8502: }
8503: if (keys(%haschgs) > 0) {
1.80 raeburn 8504: my $newacc =
8505: &Apache::lonnet::usertools_access($env{'user.name'},
8506: $env{'user.domain'},
1.86 raeburn 8507: $item,'reload',$context);
1.160.6.5 raeburn 8508: if (($context eq 'requestcourses') ||
8509: ($context eq 'requestauthor')) {
1.108 raeburn 8510: if ($env{'environment.canrequest.'.$item} ne $newacc) {
8511: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 8512: }
8513: } else {
8514: if ($env{'environment.availabletools.'.$item} ne $newacc) {
8515: $newenv{'environment.availabletools.'.$item} = $newacc;
8516: }
1.80 raeburn 8517: }
1.160.6.5 raeburn 8518: unless ($context eq 'requestauthor') {
8519: $resulttext .= '<li>'.$titles{$item}.'<ul>';
8520: }
1.72 raeburn 8521: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 8522: if ($haschgs{$type}) {
1.72 raeburn 8523: my $typetitle = $usertypes->{$type};
8524: if ($type eq 'default') {
8525: $typetitle = $othertitle;
8526: } elsif ($type eq '_LC_adv') {
8527: $typetitle = 'LON-CAPA Advanced Users';
8528: }
1.160.6.5 raeburn 8529: if ($inconf{$type}) {
1.101 raeburn 8530: if ($context eq 'requestcourses') {
8531: my $cond;
1.160.6.5 raeburn 8532: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 8533: if ($1 eq '') {
8534: $cond = &mt('(Automatic processing of any request).');
8535: } else {
8536: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
8537: }
8538: } else {
1.160.6.5 raeburn 8539: $cond = $conditions{$inconf{$type}};
1.101 raeburn 8540: }
8541: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 8542: } elsif ($context eq 'requestauthor') {
8543: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
8544: $titles{$inconf{$type}},$typetitle);
8545:
1.101 raeburn 8546: } else {
8547: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
8548: }
1.72 raeburn 8549: } else {
1.104 raeburn 8550: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 8551: if ($inconf{$type} eq '0') {
1.104 raeburn 8552: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8553: } else {
8554: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
8555: }
8556: } else {
8557: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
8558: }
1.72 raeburn 8559: }
8560: }
1.26 raeburn 8561: }
1.160.6.5 raeburn 8562: unless ($context eq 'requestauthor') {
8563: $resulttext .= '</ul></li>';
8564: }
1.26 raeburn 8565: }
1.1 raeburn 8566: }
1.160.6.5 raeburn 8567: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 8568: if (ref($changes{'notify'}) eq 'HASH') {
8569: if ($changes{'notify'}{'approval'}) {
8570: if (ref($confhash{'notify'}) eq 'HASH') {
8571: if ($confhash{'notify'}{'approval'}) {
8572: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
8573: } else {
1.160.6.5 raeburn 8574: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 8575: }
8576: }
8577: }
8578: }
8579: }
1.160.6.30 raeburn 8580: if ($action eq 'requestcourses') {
8581: my @offon = ('off','on');
8582: if ($changes{'uniquecode'}) {
8583: if (ref($confhash{'uniquecode'}) eq 'HASH') {
8584: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
8585: $resulttext .= '<li>'.
8586: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
8587: '</li>';
8588: } else {
8589: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
8590: '</li>';
8591: }
8592: }
1.160.6.46 raeburn 8593: foreach my $type ('textbooks','templates') {
8594: if (ref($changes{$type}) eq 'HASH') {
8595: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
8596: foreach my $key (sort(keys(%{$changes{$type}}))) {
8597: my %coursehash = &Apache::lonnet::coursedescription($key);
8598: my $coursetitle = $coursehash{'description'};
8599: my $position = $confhash{$type}{$key}{'order'} + 1;
8600: $resulttext .= '<li>';
1.160.6.47 raeburn 8601: foreach my $item ('subject','title','publisher','author') {
8602: next if ((($item eq 'author') || ($item eq 'publisher')) &&
8603: ($type eq 'templates'));
1.160.6.46 raeburn 8604: my $name = $item.':';
8605: $name =~ s/^(\w)/\U$1/;
8606: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
8607: }
8608: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
8609: if ($type eq 'textbooks') {
8610: if ($confhash{$type}{$key}{'image'}) {
8611: $resulttext .= ' '.&mt('Image: [_1]',
8612: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
8613: ' alt="Textbook cover" />').'<br />';
8614: }
8615: }
8616: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 8617: }
1.160.6.46 raeburn 8618: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 8619: }
8620: }
1.160.6.39 raeburn 8621: if (ref($changes{'validation'}) eq 'HASH') {
8622: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
8623: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
8624: foreach my $item (@{$validationitemsref}) {
8625: if (exists($changes{'validation'}{$item})) {
8626: if ($item eq 'markup') {
8627: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8628: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
8629: } else {
8630: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
8631: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
8632: }
8633: }
8634: }
8635: if (exists($changes{'validation'}{'dc'})) {
8636: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
8637: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
8638: }
8639: }
8640: }
1.160.6.30 raeburn 8641: }
1.1 raeburn 8642: $resulttext .= '</ul>';
1.80 raeburn 8643: if (keys(%newenv)) {
8644: &Apache::lonnet::appenv(\%newenv);
8645: }
1.1 raeburn 8646: } else {
1.86 raeburn 8647: if ($context eq 'requestcourses') {
8648: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 8649: } elsif ($context eq 'requestauthor') {
8650: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 8651: } else {
1.90 weissno 8652: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 8653: }
1.1 raeburn 8654: }
8655: } else {
1.11 albertel 8656: $resulttext = '<span class="LC_error">'.
8657: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8658: }
1.160.6.30 raeburn 8659: if ($errors) {
8660: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
8661: '<ul>'.$errors.'</ul></p>';
8662: }
1.3 raeburn 8663: return $resulttext;
1.1 raeburn 8664: }
8665:
1.160.6.30 raeburn 8666: sub process_textbook_image {
1.160.6.46 raeburn 8667: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 8668: my $filename = $env{'form.'.$caller.'.filename'};
8669: my ($error,$url);
8670: my ($width,$height) = (50,50);
8671: if ($configuserok eq 'ok') {
8672: if ($switchserver) {
8673: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
8674: $switchserver);
8675: } elsif ($author_ok eq 'ok') {
8676: my ($result,$imageurl) =
8677: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88! raeburn 8678: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 8679: if ($result eq 'ok') {
8680: $url = $imageurl;
8681: } else {
8682: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
8683: }
8684: } else {
8685: $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);
8686: }
8687: } else {
8688: $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);
8689: }
8690: return ($url,$error);
8691: }
8692:
1.3 raeburn 8693: sub modify_autoenroll {
1.160.6.24 raeburn 8694: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 8695: my ($resulttext,%changes);
8696: my %currautoenroll;
8697: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
8698: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
8699: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
8700: }
8701: }
8702: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
8703: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 8704: sender => 'Sender for notification messages',
1.160.6.68 raeburn 8705: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
8706: failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 8707: my @offon = ('off','on');
1.17 raeburn 8708: my $sender_uname = $env{'form.sender_uname'};
8709: my $sender_domain = $env{'form.sender_domain'};
8710: if ($sender_domain eq '') {
8711: $sender_uname = '';
8712: } elsif ($sender_uname eq '') {
8713: $sender_domain = '';
8714: }
1.129 raeburn 8715: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68 raeburn 8716: my $failsafe = $env{'form.autoenroll_failsafe'};
8717: $failsafe =~ s{^\s+|\s+$}{}g;
8718: if ($failsafe =~ /\D/) {
8719: undef($failsafe);
8720: }
1.1 raeburn 8721: my %autoenrollhash = (
1.129 raeburn 8722: autoenroll => { 'run' => $env{'form.autoenroll_run'},
8723: 'sender_uname' => $sender_uname,
8724: 'sender_domain' => $sender_domain,
8725: 'co-owners' => $coowners,
1.160.6.68 raeburn 8726: 'autofailsafe' => $failsafe,
1.1 raeburn 8727: }
8728: );
1.4 raeburn 8729: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
8730: $dom);
1.1 raeburn 8731: if ($putresult eq 'ok') {
8732: if (exists($currautoenroll{'run'})) {
8733: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
8734: $changes{'run'} = 1;
8735: }
8736: } elsif ($autorun) {
8737: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 8738: $changes{'run'} = 1;
1.1 raeburn 8739: }
8740: }
1.17 raeburn 8741: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 8742: $changes{'sender'} = 1;
8743: }
1.17 raeburn 8744: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 8745: $changes{'sender'} = 1;
8746: }
1.129 raeburn 8747: if ($currautoenroll{'co-owners'} ne '') {
8748: if ($currautoenroll{'co-owners'} ne $coowners) {
8749: $changes{'coowners'} = 1;
8750: }
8751: } elsif ($coowners) {
8752: $changes{'coowners'} = 1;
1.160.6.68 raeburn 8753: }
8754: if ($currautoenroll{'autofailsafe'} ne $failsafe) {
8755: $changes{'autofailsafe'} = 1;
8756: }
1.1 raeburn 8757: if (keys(%changes) > 0) {
8758: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 8759: if ($changes{'run'}) {
1.1 raeburn 8760: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
8761: }
8762: if ($changes{'sender'}) {
1.17 raeburn 8763: if ($sender_uname eq '' || $sender_domain eq '') {
8764: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
8765: } else {
8766: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
8767: }
1.1 raeburn 8768: }
1.129 raeburn 8769: if ($changes{'coowners'}) {
8770: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
8771: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 8772: if (ref($lastactref) eq 'HASH') {
8773: $lastactref->{'domainconfig'} = 1;
8774: }
1.129 raeburn 8775: }
1.160.6.68 raeburn 8776: if ($changes{'autofailsafe'}) {
8777: if ($failsafe ne '') {
1.160.6.82 raeburn 8778: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68 raeburn 8779: } else {
1.160.6.82 raeburn 8780: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68 raeburn 8781: }
8782: &Apache::lonnet::get_domain_defaults($dom,1);
8783: if (ref($lastactref) eq 'HASH') {
8784: $lastactref->{'domdefaults'} = 1;
8785: }
8786: }
1.1 raeburn 8787: $resulttext .= '</ul>';
8788: } else {
8789: $resulttext = &mt('No changes made to auto-enrollment settings');
8790: }
8791: } else {
1.11 albertel 8792: $resulttext = '<span class="LC_error">'.
8793: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8794: }
1.3 raeburn 8795: return $resulttext;
1.1 raeburn 8796: }
8797:
8798: sub modify_autoupdate {
1.3 raeburn 8799: my ($dom,%domconfig) = @_;
1.1 raeburn 8800: my ($resulttext,%currautoupdate,%fields,%changes);
8801: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
8802: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
8803: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
8804: }
8805: }
8806: my @offon = ('off','on');
8807: my %title = &Apache::lonlocal::texthash (
8808: run => 'Auto-update:',
8809: classlists => 'Updates to user information in classlists?'
8810: );
1.44 raeburn 8811: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 8812: my %fieldtitles = &Apache::lonlocal::texthash (
8813: id => 'Student/Employee ID',
1.20 raeburn 8814: permanentemail => 'E-mail address',
1.1 raeburn 8815: lastname => 'Last Name',
8816: firstname => 'First Name',
8817: middlename => 'Middle Name',
1.132 raeburn 8818: generation => 'Generation',
1.1 raeburn 8819: );
1.142 raeburn 8820: $othertitle = &mt('All users');
1.1 raeburn 8821: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 8822: $othertitle = &mt('Other users');
1.1 raeburn 8823: }
8824: foreach my $key (keys(%env)) {
8825: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 8826: my ($usertype,$item) = ($1,$2);
8827: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
8828: if ($usertype eq 'default') {
8829: push(@{$fields{$1}},$2);
8830: } elsif (ref($types) eq 'ARRAY') {
8831: if (grep(/^\Q$usertype\E$/,@{$types})) {
8832: push(@{$fields{$1}},$2);
8833: }
8834: }
8835: }
1.1 raeburn 8836: }
8837: }
1.131 raeburn 8838: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
8839: @lockablenames = sort(@lockablenames);
8840: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
8841: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8842: if (@changed) {
8843: $changes{'lockablenames'} = 1;
8844: }
8845: } else {
8846: if (@lockablenames) {
8847: $changes{'lockablenames'} = 1;
8848: }
8849: }
1.1 raeburn 8850: my %updatehash = (
8851: autoupdate => { run => $env{'form.autoupdate_run'},
8852: classlists => $env{'form.classlists'},
8853: fields => {%fields},
1.131 raeburn 8854: lockablenames => \@lockablenames,
1.1 raeburn 8855: }
8856: );
8857: foreach my $key (keys(%currautoupdate)) {
8858: if (($key eq 'run') || ($key eq 'classlists')) {
8859: if (exists($updatehash{autoupdate}{$key})) {
8860: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
8861: $changes{$key} = 1;
8862: }
8863: }
8864: } elsif ($key eq 'fields') {
8865: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 8866: foreach my $item (@{$types},'default') {
1.1 raeburn 8867: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
8868: my $change = 0;
8869: foreach my $type (@{$currautoupdate{$key}{$item}}) {
8870: if (!exists($fields{$item})) {
8871: $change = 1;
1.132 raeburn 8872: last;
1.1 raeburn 8873: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 8874: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 8875: $change = 1;
1.132 raeburn 8876: last;
1.1 raeburn 8877: }
8878: }
8879: }
8880: if ($change) {
8881: push(@{$changes{$key}},$item);
8882: }
1.26 raeburn 8883: }
1.1 raeburn 8884: }
8885: }
1.131 raeburn 8886: } elsif ($key eq 'lockablenames') {
8887: if (ref($currautoupdate{$key}) eq 'ARRAY') {
8888: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
8889: if (@changed) {
8890: $changes{'lockablenames'} = 1;
8891: }
8892: } else {
8893: if (@lockablenames) {
8894: $changes{'lockablenames'} = 1;
8895: }
8896: }
8897: }
8898: }
8899: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
8900: if (@lockablenames) {
8901: $changes{'lockablenames'} = 1;
1.1 raeburn 8902: }
8903: }
1.26 raeburn 8904: foreach my $item (@{$types},'default') {
8905: if (defined($fields{$item})) {
8906: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 8907: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
8908: my $change = 0;
8909: if (ref($fields{$item}) eq 'ARRAY') {
8910: foreach my $type (@{$fields{$item}}) {
8911: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
8912: $change = 1;
8913: last;
8914: }
8915: }
8916: }
8917: if ($change) {
8918: push(@{$changes{'fields'}},$item);
8919: }
8920: } else {
1.26 raeburn 8921: push(@{$changes{'fields'}},$item);
8922: }
8923: } else {
8924: push(@{$changes{'fields'}},$item);
1.1 raeburn 8925: }
8926: }
8927: }
8928: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
8929: $dom);
8930: if ($putresult eq 'ok') {
8931: if (keys(%changes) > 0) {
8932: $resulttext = &mt('Changes made:').'<ul>';
8933: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 8934: if ($key eq 'lockablenames') {
8935: $resulttext .= '<li>';
8936: if (@lockablenames) {
8937: $usertypes->{'default'} = $othertitle;
8938: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
8939: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
8940: } else {
8941: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
8942: }
8943: $resulttext .= '</li>';
8944: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 8945: foreach my $item (@{$changes{$key}}) {
8946: my @newvalues;
8947: foreach my $type (@{$fields{$item}}) {
8948: push(@newvalues,$fieldtitles{$type});
8949: }
1.3 raeburn 8950: my $newvaluestr;
8951: if (@newvalues > 0) {
8952: $newvaluestr = join(', ',@newvalues);
8953: } else {
8954: $newvaluestr = &mt('none');
1.6 raeburn 8955: }
1.1 raeburn 8956: if ($item eq 'default') {
1.26 raeburn 8957: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 8958: } else {
1.26 raeburn 8959: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 8960: }
8961: }
8962: } else {
8963: my $newvalue;
8964: if ($key eq 'run') {
8965: $newvalue = $offon[$env{'form.autoupdate_run'}];
8966: } else {
8967: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 8968: }
1.1 raeburn 8969: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
8970: }
8971: }
8972: $resulttext .= '</ul>';
8973: } else {
1.3 raeburn 8974: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 8975: }
8976: } else {
1.11 albertel 8977: $resulttext = '<span class="LC_error">'.
8978: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 8979: }
1.3 raeburn 8980: return $resulttext;
1.1 raeburn 8981: }
8982:
1.125 raeburn 8983: sub modify_autocreate {
8984: my ($dom,%domconfig) = @_;
8985: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
8986: if (ref($domconfig{'autocreate'}) eq 'HASH') {
8987: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
8988: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
8989: }
8990: }
8991: my %title= ( xml => 'Auto-creation of courses in XML course description files',
8992: req => 'Auto-creation of validated requests for official courses',
8993: xmldc => 'Identity of course creator of courses from XML files',
8994: );
8995: my @types = ('xml','req');
8996: foreach my $item (@types) {
8997: $newvals{$item} = $env{'form.autocreate_'.$item};
8998: $newvals{$item} =~ s/\D//g;
8999: $newvals{$item} = 0 if ($newvals{$item} eq '');
9000: }
9001: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 9002: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 9003: unless (exists($domcoords{$newvals{'xmldc'}})) {
9004: $newvals{'xmldc'} = '';
9005: }
9006: %autocreatehash = (
9007: autocreate => { xml => $newvals{'xml'},
9008: req => $newvals{'req'},
9009: }
9010: );
9011: if ($newvals{'xmldc'} ne '') {
9012: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
9013: }
9014: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
9015: $dom);
9016: if ($putresult eq 'ok') {
9017: my @items = @types;
9018: if ($newvals{'xml'}) {
9019: push(@items,'xmldc');
9020: }
9021: foreach my $item (@items) {
9022: if (exists($currautocreate{$item})) {
9023: if ($currautocreate{$item} ne $newvals{$item}) {
9024: $changes{$item} = 1;
9025: }
9026: } elsif ($newvals{$item}) {
9027: $changes{$item} = 1;
9028: }
9029: }
9030: if (keys(%changes) > 0) {
9031: my @offon = ('off','on');
9032: $resulttext = &mt('Changes made:').'<ul>';
9033: foreach my $item (@types) {
9034: if ($changes{$item}) {
9035: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 9036: $resulttext .= '<li>'.
9037: &mt("$title{$item} set to [_1]$newtxt [_2]",
9038: '<b>','</b>').
9039: '</li>';
1.125 raeburn 9040: }
9041: }
9042: if ($changes{'xmldc'}) {
9043: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
9044: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 9045: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 9046: }
9047: $resulttext .= '</ul>';
9048: } else {
9049: $resulttext = &mt('No changes made to auto-creation settings');
9050: }
9051: } else {
9052: $resulttext = '<span class="LC_error">'.
9053: &mt('An error occurred: [_1]',$putresult).'</span>';
9054: }
9055: return $resulttext;
9056: }
9057:
1.23 raeburn 9058: sub modify_directorysrch {
1.160.6.81 raeburn 9059: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 9060: my ($resulttext,%changes);
9061: my %currdirsrch;
9062: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9063: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
9064: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
9065: }
9066: }
1.160.6.72 raeburn 9067: my %title = ( available => 'Institutional directory search available',
9068: localonly => 'Other domains can search institution',
9069: lcavailable => 'LON-CAPA directory search available',
9070: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 9071: searchby => 'Search types',
9072: searchtypes => 'Search latitude');
9073: my @offon = ('off','on');
1.24 raeburn 9074: my @otherdoms = ('Yes','No');
1.23 raeburn 9075:
1.25 raeburn 9076: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 9077: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
9078: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
9079:
1.44 raeburn 9080: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 9081: if (keys(%{$usertypes}) == 0) {
9082: @cansearch = ('default');
9083: } else {
9084: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
9085: foreach my $type (@{$currdirsrch{'cansearch'}}) {
9086: if (!grep(/^\Q$type\E$/,@cansearch)) {
9087: push(@{$changes{'cansearch'}},$type);
9088: }
1.23 raeburn 9089: }
1.26 raeburn 9090: foreach my $type (@cansearch) {
9091: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
9092: push(@{$changes{'cansearch'}},$type);
9093: }
1.23 raeburn 9094: }
1.26 raeburn 9095: } else {
9096: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 9097: }
9098: }
9099:
9100: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
9101: foreach my $by (@{$currdirsrch{'searchby'}}) {
9102: if (!grep(/^\Q$by\E$/,@searchby)) {
9103: push(@{$changes{'searchby'}},$by);
9104: }
9105: }
9106: foreach my $by (@searchby) {
9107: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
9108: push(@{$changes{'searchby'}},$by);
9109: }
9110: }
9111: } else {
9112: push(@{$changes{'searchby'}},@searchby);
9113: }
1.25 raeburn 9114:
9115: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
9116: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
9117: if (!grep(/^\Q$type\E$/,@searchtypes)) {
9118: push(@{$changes{'searchtypes'}},$type);
9119: }
9120: }
9121: foreach my $type (@searchtypes) {
9122: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
9123: push(@{$changes{'searchtypes'}},$type);
9124: }
9125: }
9126: } else {
9127: if (exists($currdirsrch{'searchtypes'})) {
9128: foreach my $type (@searchtypes) {
9129: if ($type ne $currdirsrch{'searchtypes'}) {
9130: push(@{$changes{'searchtypes'}},$type);
9131: }
9132: }
9133: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
9134: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
9135: }
9136: } else {
9137: push(@{$changes{'searchtypes'}},@searchtypes);
9138: }
9139: }
9140:
1.23 raeburn 9141: my %dirsrch_hash = (
9142: directorysrch => { available => $env{'form.dirsrch_available'},
9143: cansearch => \@cansearch,
1.160.6.72 raeburn 9144: localonly => $env{'form.dirsrch_instlocalonly'},
9145: lclocalonly => $env{'form.dirsrch_domlocalonly'},
9146: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 9147: searchby => \@searchby,
1.25 raeburn 9148: searchtypes => \@searchtypes,
1.23 raeburn 9149: }
9150: );
9151: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
9152: $dom);
9153: if ($putresult eq 'ok') {
9154: if (exists($currdirsrch{'available'})) {
9155: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
9156: $changes{'available'} = 1;
9157: }
9158: } else {
9159: if ($env{'form.dirsrch_available'} eq '1') {
9160: $changes{'available'} = 1;
9161: }
9162: }
1.160.6.72 raeburn 9163: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 9164: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
9165: $changes{'lcavailable'} = 1;
9166: }
1.24 raeburn 9167: } else {
1.160.6.72 raeburn 9168: if ($env{'form.dirsrch_lcavailable'} eq '1') {
9169: $changes{'lcavailable'} = 1;
9170: }
9171: }
9172: if (exists($currdirsrch{'localonly'})) {
9173: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 9174: $changes{'localonly'} = 1;
9175: }
1.160.6.72 raeburn 9176: } else {
9177: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
9178: $changes{'localonly'} = 1;
9179: }
9180: }
9181: if (exists($currdirsrch{'lclocalonly'})) {
9182: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
9183: $changes{'lclocalonly'} = 1;
9184: }
9185: } else {
9186: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
9187: $changes{'lclocalonly'} = 1;
9188: }
1.24 raeburn 9189: }
1.23 raeburn 9190: if (keys(%changes) > 0) {
9191: $resulttext = &mt('Changes made:').'<ul>';
9192: if ($changes{'available'}) {
9193: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
9194: }
1.160.6.72 raeburn 9195: if ($changes{'lcavailable'}) {
9196: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
9197: }
1.24 raeburn 9198: if ($changes{'localonly'}) {
1.160.6.72 raeburn 9199: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
9200: }
9201: if ($changes{'lclocalonly'}) {
9202: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 9203: }
1.23 raeburn 9204: if (ref($changes{'cansearch'}) eq 'ARRAY') {
9205: my $chgtext;
1.26 raeburn 9206: if (ref($usertypes) eq 'HASH') {
9207: if (keys(%{$usertypes}) > 0) {
9208: foreach my $type (@{$types}) {
9209: if (grep(/^\Q$type\E$/,@cansearch)) {
9210: $chgtext .= $usertypes->{$type}.'; ';
9211: }
9212: }
9213: if (grep(/^default$/,@cansearch)) {
9214: $chgtext .= $othertitle;
9215: } else {
9216: $chgtext =~ s/\; $//;
9217: }
1.160.6.13 raeburn 9218: $resulttext .=
9219: '<li>'.
9220: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
9221: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
9222: '</li>';
1.23 raeburn 9223: }
9224: }
9225: }
9226: if (ref($changes{'searchby'}) eq 'ARRAY') {
9227: my ($searchtitles,$titleorder) = &sorted_searchtitles();
9228: my $chgtext;
9229: foreach my $type (@{$titleorder}) {
9230: if (grep(/^\Q$type\E$/,@searchby)) {
9231: if (defined($searchtitles->{$type})) {
9232: $chgtext .= $searchtitles->{$type}.'; ';
9233: }
9234: }
9235: }
9236: $chgtext =~ s/\; $//;
9237: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
9238: }
1.25 raeburn 9239: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
9240: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
9241: my $chgtext;
9242: foreach my $type (@{$srchtypeorder}) {
9243: if (grep(/^\Q$type\E$/,@searchtypes)) {
9244: if (defined($srchtypes_desc->{$type})) {
9245: $chgtext .= $srchtypes_desc->{$type}.'; ';
9246: }
9247: }
9248: }
9249: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 9250: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 9251: }
9252: $resulttext .= '</ul>';
1.160.6.81 raeburn 9253: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
9254: if (ref($lastactref) eq 'HASH') {
9255: $lastactref->{'directorysrch'} = 1;
9256: }
1.23 raeburn 9257: } else {
1.160.6.72 raeburn 9258: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 9259: }
9260: } else {
9261: $resulttext = '<span class="LC_error">'.
1.27 raeburn 9262: &mt('An error occurred: [_1]',$putresult).'</span>';
9263: }
9264: return $resulttext;
9265: }
9266:
1.28 raeburn 9267: sub modify_contacts {
1.160.6.24 raeburn 9268: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 9269: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
9270: if (ref($domconfig{'contacts'}) eq 'HASH') {
9271: foreach my $key (keys(%{$domconfig{'contacts'}})) {
9272: $currsetting{$key} = $domconfig{'contacts'}{$key};
9273: }
9274: }
1.160.6.78 raeburn 9275: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 9276: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 9277: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
9278: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.160.6.23 raeburn 9279: my @toggles = ('reporterrors','reportupdates');
1.160.6.78 raeburn 9280: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 9281: foreach my $type (@mailings) {
9282: @{$newsetting{$type}} =
9283: &Apache::loncommon::get_env_multiple('form.'.$type);
9284: foreach my $item (@contacts) {
9285: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
9286: $contacts_hash{contacts}{$type}{$item} = 1;
9287: } else {
9288: $contacts_hash{contacts}{$type}{$item} = 0;
9289: }
1.160.6.78 raeburn 9290: }
1.28 raeburn 9291: $others{$type} = $env{'form.'.$type.'_others'};
9292: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 9293: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9294: $bcc{$type} = $env{'form.'.$type.'_bcc'};
9295: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 9296: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
9297: $includestr{$type} = $env{'form.'.$type.'_includestr'};
9298: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
9299: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
9300: }
1.134 raeburn 9301: }
1.28 raeburn 9302: }
9303: foreach my $item (@contacts) {
9304: $to{$item} = $env{'form.'.$item};
9305: $contacts_hash{'contacts'}{$item} = $to{$item};
9306: }
1.160.6.23 raeburn 9307: foreach my $item (@toggles) {
9308: if ($env{'form.'.$item} =~ /^(0|1)$/) {
9309: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
9310: }
9311: }
1.160.6.78 raeburn 9312: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
9313: foreach my $field (@{$fields}) {
9314: if (ref($possoptions->{$field}) eq 'ARRAY') {
9315: my $value = $env{'form.helpform_'.$field};
9316: $value =~ s/^\s+|\s+$//g;
9317: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
9318: $contacts_hash{contacts}{'helpform'}{$field} = $value;
9319: if ($field eq 'screenshot') {
9320: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
9321: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
9322: $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
9323: }
9324: }
9325: }
9326: }
9327: }
9328: }
1.28 raeburn 9329: if (keys(%currsetting) > 0) {
9330: foreach my $item (@contacts) {
9331: if ($to{$item} ne $currsetting{$item}) {
9332: $changes{$item} = 1;
9333: }
9334: }
9335: foreach my $type (@mailings) {
9336: foreach my $item (@contacts) {
9337: if (ref($currsetting{$type}) eq 'HASH') {
9338: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
9339: push(@{$changes{$type}},$item);
9340: }
9341: } else {
9342: push(@{$changes{$type}},@{$newsetting{$type}});
9343: }
9344: }
9345: if ($others{$type} ne $currsetting{$type}{'others'}) {
9346: push(@{$changes{$type}},'others');
9347: }
1.160.6.78 raeburn 9348: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9349: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
9350: push(@{$changes{$type}},'bcc');
9351: }
1.160.6.78 raeburn 9352: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
9353: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
9354: push(@{$changes{$type}},'include');
9355: }
9356: }
9357: }
9358: if (ref($fields) eq 'ARRAY') {
9359: if (ref($currsetting{'helpform'}) eq 'HASH') {
9360: foreach my $field (@{$fields}) {
9361: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
9362: push(@{$changes{'helpform'}},$field);
9363: }
9364: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9365: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
9366: push(@{$changes{'helpform'}},'maxsize');
9367: }
9368: }
9369: }
9370: } else {
9371: foreach my $field (@{$fields}) {
9372: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9373: push(@{$changes{'helpform'}},$field);
9374: }
9375: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9376: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9377: push(@{$changes{'helpform'}},'maxsize');
9378: }
9379: }
9380: }
1.134 raeburn 9381: }
1.28 raeburn 9382: }
9383: } else {
9384: my %default;
9385: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
9386: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
9387: $default{'errormail'} = 'adminemail';
9388: $default{'packagesmail'} = 'adminemail';
9389: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 9390: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 9391: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 9392: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 9393: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 9394: foreach my $item (@contacts) {
9395: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 9396: $changes{$item} = 1;
1.160.6.23 raeburn 9397: }
1.28 raeburn 9398: }
9399: foreach my $type (@mailings) {
9400: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
9401: push(@{$changes{$type}},@{$newsetting{$type}});
9402: }
9403: if ($others{$type} ne '') {
9404: push(@{$changes{$type}},'others');
1.134 raeburn 9405: }
1.160.6.78 raeburn 9406: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9407: if ($bcc{$type} ne '') {
9408: push(@{$changes{$type}},'bcc');
9409: }
1.160.6.78 raeburn 9410: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
9411: push(@{$changes{$type}},'include');
9412: }
9413: }
9414: }
9415: if (ref($fields) eq 'ARRAY') {
9416: foreach my $field (@{$fields}) {
9417: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
9418: push(@{$changes{'helpform'}},$field);
9419: }
9420: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
9421: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
9422: push(@{$changes{'helpform'}},'maxsize');
9423: }
9424: }
1.134 raeburn 9425: }
1.28 raeburn 9426: }
9427: }
1.160.6.23 raeburn 9428: foreach my $item (@toggles) {
9429: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
9430: $changes{$item} = 1;
9431: } elsif ((!$env{'form.'.$item}) &&
9432: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
9433: $changes{$item} = 1;
9434: }
9435: }
1.28 raeburn 9436: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
9437: $dom);
9438: if ($putresult eq 'ok') {
9439: if (keys(%changes) > 0) {
1.160.6.24 raeburn 9440: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 9441: if (ref($lastactref) eq 'HASH') {
9442: $lastactref->{'domainconfig'} = 1;
9443: }
1.28 raeburn 9444: my ($titles,$short_titles) = &contact_titles();
9445: $resulttext = &mt('Changes made:').'<ul>';
9446: foreach my $item (@contacts) {
9447: if ($changes{$item}) {
9448: $resulttext .= '<li>'.$titles->{$item}.
9449: &mt(' set to: ').
9450: '<span class="LC_cusr_emph">'.
9451: $to{$item}.'</span></li>';
9452: }
9453: }
9454: foreach my $type (@mailings) {
9455: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 9456: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
9457: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
9458: } else {
9459: $resulttext .= '<li>'.$titles->{$type}.': ';
9460: }
1.28 raeburn 9461: my @text;
9462: foreach my $item (@{$newsetting{$type}}) {
9463: push(@text,$short_titles->{$item});
9464: }
9465: if ($others{$type} ne '') {
9466: push(@text,$others{$type});
9467: }
1.160.6.78 raeburn 9468: if (@text) {
9469: $resulttext .= '<span class="LC_cusr_emph">'.
9470: join(', ',@text).'</span>';
9471: }
9472: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 9473: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 9474: my $bcctext;
9475: if (@text) {
9476: $bcctext = ' '.&mt('with Bcc to');
9477: } else {
9478: $bcctext = '(Bcc)';
9479: }
9480: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
9481: } elsif (!@text) {
9482: $resulttext .= &mt('No one');
1.134 raeburn 9483: }
1.160.6.78 raeburn 9484: if ($includestr{$type} ne '') {
9485: if ($includeloc{$type} eq 'b') {
9486: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
9487: } elsif ($includeloc{$type} eq 's') {
9488: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
9489: }
9490: }
9491: } elsif (!@text) {
9492: $resulttext .= &mt('No recipients');
1.134 raeburn 9493: }
9494: $resulttext .= '</li>';
1.28 raeburn 9495: }
9496: }
1.160.6.23 raeburn 9497: my @offon = ('off','on');
9498: if ($changes{'reporterrors'}) {
9499: $resulttext .= '<li>'.
9500: &mt('E-mail error reports to [_1] set to "'.
9501: $offon[$env{'form.reporterrors'}].'".',
9502: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9503: &mt('LON-CAPA core group - MSU'),600,500)).
9504: '</li>';
9505: }
9506: if ($changes{'reportupdates'}) {
9507: $resulttext .= '<li>'.
9508: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
9509: $offon[$env{'form.reportupdates'}].'".',
9510: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
9511: &mt('LON-CAPA core group - MSU'),600,500)).
9512: '</li>';
9513: }
1.160.6.78 raeburn 9514: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
9515: my (@optional,@required,@unused,$maxsizechg);
9516: foreach my $field (@{$changes{'helpform'}}) {
9517: if ($field eq 'maxsize') {
9518: $maxsizechg = 1;
9519: next;
9520: }
9521: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
9522: push(@optional,$field);
9523: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
9524: push(@unused,$field);
9525: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
9526: push(@required,$field);
9527: }
9528: }
9529: if (@optional) {
9530: $resulttext .= '<li>'.
9531: &mt('Help form fields changed to "Optional": [_1].',
9532: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
9533: '</li>';
9534: }
9535: if (@required) {
9536: $resulttext .= '<li>'.
9537: &mt('Help form fields changed to "Required": [_1].',
9538: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
9539: '</li>';
9540: }
9541: if (@unused) {
9542: $resulttext .= '<li>'.
9543: &mt('Help form fields changed to "Not shown": [_1].',
9544: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
9545: '</li>';
9546: }
9547: if ($maxsizechg) {
9548: $resulttext .= '<li>'.
9549: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
9550: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
9551: '</li>';
9552:
9553: }
9554: }
1.28 raeburn 9555: $resulttext .= '</ul>';
9556: } else {
1.160.6.78 raeburn 9557: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 9558: }
9559: } else {
9560: $resulttext = '<span class="LC_error">'.
9561: &mt('An error occurred: [_1].',$putresult).'</span>';
9562: }
9563: return $resulttext;
9564: }
9565:
9566: sub modify_usercreation {
1.27 raeburn 9567: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 9568: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 9569: my $warningmsg;
1.27 raeburn 9570: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9571: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 9572: if ($key eq 'cancreate') {
9573: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9574: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9575: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69 raeburn 9576: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
9577: ($item eq 'recaptchaversion')) {
1.160.6.34 raeburn 9578: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9579: } else {
9580: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9581: }
1.50 raeburn 9582: }
1.43 raeburn 9583: }
1.160.6.34 raeburn 9584: } elsif ($key eq 'email_rule') {
9585: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9586: } else {
9587: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 9588: }
9589: }
1.34 raeburn 9590: }
1.160.6.34 raeburn 9591: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
9592: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
9593: my @contexts = ('author','course','requestcrs');
9594: foreach my $item(@contexts) {
9595: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 9596: }
1.34 raeburn 9597: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9598: foreach my $item (@contexts) {
1.160.6.34 raeburn 9599: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
9600: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 9601: }
1.27 raeburn 9602: }
1.34 raeburn 9603: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
9604: foreach my $item (@contexts) {
1.43 raeburn 9605: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 9606: if ($cancreate{$item} ne 'any') {
9607: push(@{$changes{'cancreate'}},$item);
9608: }
9609: } else {
9610: if ($cancreate{$item} ne 'none') {
9611: push(@{$changes{'cancreate'}},$item);
9612: }
1.27 raeburn 9613: }
9614: }
9615: } else {
1.43 raeburn 9616: foreach my $item (@contexts) {
1.34 raeburn 9617: push(@{$changes{'cancreate'}},$item);
9618: }
1.27 raeburn 9619: }
1.34 raeburn 9620:
1.27 raeburn 9621: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
9622: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
9623: if (!grep(/^\Q$type\E$/,@username_rule)) {
9624: push(@{$changes{'username_rule'}},$type);
9625: }
9626: }
9627: foreach my $type (@username_rule) {
9628: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
9629: push(@{$changes{'username_rule'}},$type);
9630: }
9631: }
9632: } else {
9633: push(@{$changes{'username_rule'}},@username_rule);
9634: }
9635:
1.32 raeburn 9636: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
9637: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
9638: if (!grep(/^\Q$type\E$/,@id_rule)) {
9639: push(@{$changes{'id_rule'}},$type);
9640: }
9641: }
9642: foreach my $type (@id_rule) {
9643: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
9644: push(@{$changes{'id_rule'}},$type);
9645: }
9646: }
9647: } else {
9648: push(@{$changes{'id_rule'}},@id_rule);
9649: }
9650:
1.43 raeburn 9651: my @authen_contexts = ('author','course','domain');
1.28 raeburn 9652: my @authtypes = ('int','krb4','krb5','loc');
9653: my %authhash;
1.43 raeburn 9654: foreach my $item (@authen_contexts) {
1.28 raeburn 9655: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
9656: foreach my $auth (@authtypes) {
9657: if (grep(/^\Q$auth\E$/,@authallowed)) {
9658: $authhash{$item}{$auth} = 1;
9659: } else {
9660: $authhash{$item}{$auth} = 0;
9661: }
9662: }
9663: }
9664: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 9665: foreach my $item (@authen_contexts) {
1.28 raeburn 9666: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
9667: foreach my $auth (@authtypes) {
9668: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
9669: push(@{$changes{'authtypes'}},$item);
9670: last;
9671: }
9672: }
9673: }
9674: }
9675: } else {
1.43 raeburn 9676: foreach my $item (@authen_contexts) {
1.28 raeburn 9677: push(@{$changes{'authtypes'}},$item);
9678: }
9679: }
9680:
1.160.6.34 raeburn 9681: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
9682: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
9683: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
9684: $save_usercreate{'id_rule'} = \@id_rule;
9685: $save_usercreate{'username_rule'} = \@username_rule,
9686: $save_usercreate{'authtypes'} = \%authhash;
9687:
1.27 raeburn 9688: my %usercreation_hash = (
1.160.6.34 raeburn 9689: usercreation => \%save_usercreate,
9690: );
1.27 raeburn 9691:
9692: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
9693: $dom);
1.50 raeburn 9694:
1.160.6.34 raeburn 9695: if ($putresult eq 'ok') {
9696: if (keys(%changes) > 0) {
9697: $resulttext = &mt('Changes made:').'<ul>';
9698: if (ref($changes{'cancreate'}) eq 'ARRAY') {
9699: my %lt = &usercreation_types();
9700: foreach my $type (@{$changes{'cancreate'}}) {
9701: my $chgtext = $lt{$type}.', ';
9702: if ($cancreate{$type} eq 'none') {
9703: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
9704: } elsif ($cancreate{$type} eq 'any') {
9705: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
9706: } elsif ($cancreate{$type} eq 'official') {
9707: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
9708: } elsif ($cancreate{$type} eq 'unofficial') {
9709: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
9710: }
9711: $resulttext .= '<li>'.$chgtext.'</li>';
9712: }
9713: }
9714: if (ref($changes{'username_rule'}) eq 'ARRAY') {
9715: my ($rules,$ruleorder) =
9716: &Apache::lonnet::inst_userrules($dom,'username');
9717: my $chgtext = '<ul>';
9718: foreach my $type (@username_rule) {
9719: if (ref($rules->{$type}) eq 'HASH') {
9720: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
9721: }
9722: }
9723: $chgtext .= '</ul>';
9724: if (@username_rule > 0) {
9725: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9726: } else {
9727: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
9728: }
9729: }
9730: if (ref($changes{'id_rule'}) eq 'ARRAY') {
9731: my ($idrules,$idruleorder) =
9732: &Apache::lonnet::inst_userrules($dom,'id');
9733: my $chgtext = '<ul>';
9734: foreach my $type (@id_rule) {
9735: if (ref($idrules->{$type}) eq 'HASH') {
9736: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
9737: }
9738: }
9739: $chgtext .= '</ul>';
9740: if (@id_rule > 0) {
9741: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
9742: } else {
9743: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
9744: }
9745: }
9746: my %authname = &authtype_names();
9747: my %context_title = &context_names();
9748: if (ref($changes{'authtypes'}) eq 'ARRAY') {
9749: my $chgtext = '<ul>';
9750: foreach my $type (@{$changes{'authtypes'}}) {
9751: my @allowed;
9752: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
9753: foreach my $auth (@authtypes) {
9754: if ($authhash{$type}{$auth}) {
9755: push(@allowed,$authname{$auth});
9756: }
9757: }
9758: if (@allowed > 0) {
9759: $chgtext .= join(', ',@allowed).'</li>';
9760: } else {
9761: $chgtext .= &mt('none').'</li>';
9762: }
9763: }
9764: $chgtext .= '</ul>';
9765: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
9766: $resulttext .= '</li>';
9767: }
9768: $resulttext .= '</ul>';
9769: } else {
9770: $resulttext = &mt('No changes made to user creation settings');
9771: }
9772: } else {
9773: $resulttext = '<span class="LC_error">'.
9774: &mt('An error occurred: [_1]',$putresult).'</span>';
9775: }
9776: if ($warningmsg ne '') {
9777: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
9778: }
9779: return $resulttext;
9780: }
9781:
9782: sub modify_selfcreation {
9783: my ($dom,%domconfig) = @_;
9784: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
9785: my (%save_usercreate,%save_usermodify);
1.160.6.35 raeburn 9786: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
9787: if (ref($types) eq 'ARRAY') {
9788: $usertypes->{'default'} = $othertitle;
9789: push(@{$types},'default');
9790: }
1.160.6.34 raeburn 9791: #
9792: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
9793: #
9794: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9795: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
9796: if ($key eq 'cancreate') {
9797: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
9798: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
9799: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
9800: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
1.160.6.69 raeburn 9801: ($item eq 'recaptchaversion') ||
1.160.6.40 raeburn 9802: ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44 raeburn 9803: ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34 raeburn 9804: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9805: } else {
9806: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
9807: }
9808: }
9809: }
9810: } elsif ($key eq 'email_rule') {
9811: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
9812: } else {
9813: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
9814: }
9815: }
9816: }
9817: #
9818: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
9819: #
9820: if (ref($domconfig{'usermodification'}) eq 'HASH') {
9821: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
9822: if ($key eq 'selfcreate') {
9823: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
9824: } else {
9825: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
9826: }
9827: }
9828: }
9829:
9830: my @contexts = ('selfcreate');
9831: @{$cancreate{'selfcreate'}} = ();
9832: %{$cancreate{'emailusername'}} = ();
9833: @{$cancreate{'statustocreate'}} = ();
1.160.6.40 raeburn 9834: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 9835: %{$cancreate{'shibenv'}} = ();
1.50 raeburn 9836: my %selfcreatetypes = (
9837: sso => 'users authenticated by institutional single sign on',
9838: login => 'users authenticated by institutional log-in',
1.160.6.40 raeburn 9839: email => 'users who provide a valid e-mail address for use as username',
1.50 raeburn 9840: );
1.160.6.34 raeburn 9841: #
9842: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
9843: # is permitted.
9844: #
1.160.6.40 raeburn 9845:
9846: my @statuses;
9847: if (ref($domconfig{'inststatus'}) eq 'HASH') {
9848: if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
9849: @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
9850: }
9851: }
9852: push(@statuses,'default');
9853:
1.160.6.35 raeburn 9854: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 9855: if ($item eq 'email') {
1.160.6.40 raeburn 9856: if ($env{'form.cancreate_email'}) {
1.160.6.34 raeburn 9857: push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40 raeburn 9858: push(@contexts,'selfcreateprocessing');
9859: foreach my $type (@statuses) {
9860: if ($type eq 'default') {
9861: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
9862: } else {
9863: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
9864: }
9865: }
1.160.6.34 raeburn 9866: }
9867: } else {
9868: if ($env{'form.cancreate_'.$item}) {
9869: push(@{$cancreate{'selfcreate'}},$item);
9870: }
9871: }
9872: }
9873: my (@email_rule,%userinfo,%savecaptcha);
9874: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
9875: #
1.160.6.35 raeburn 9876: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
9877: # 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 9878: #
1.160.6.40 raeburn 9879:
1.160.6.48 raeburn 9880: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 9881: push(@contexts,'emailusername');
1.160.6.35 raeburn 9882: if (ref($types) eq 'ARRAY') {
9883: foreach my $type (@{$types}) {
9884: if (ref($infofields) eq 'ARRAY') {
9885: foreach my $field (@{$infofields}) {
9886: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
9887: $cancreate{'emailusername'}{$type}{$field} = $1;
9888: }
9889: }
1.160.6.34 raeburn 9890: }
9891: }
9892: }
9893: #
9894: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
9895: # queued requests for self-creation of account using e-mail address as username
9896: #
9897:
9898: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
9899: @approvalnotify = sort(@approvalnotify);
9900: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
9901: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
9902: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
9903: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
9904: push(@{$changes{'cancreate'}},'notify');
9905: }
9906: } else {
9907: if ($cancreate{'notify'}{'approval'}) {
9908: push(@{$changes{'cancreate'}},'notify');
9909: }
9910: }
9911: } elsif ($cancreate{'notify'}{'approval'}) {
9912: push(@{$changes{'cancreate'}},'notify');
9913: }
9914:
9915: #
9916: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
9917: #
9918: @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
9919: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
9920: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
9921: if (@{$curr_usercreation{'email_rule'}} > 0) {
9922: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
9923: if (!grep(/^\Q$type\E$/,@email_rule)) {
9924: push(@{$changes{'email_rule'}},$type);
9925: }
9926: }
9927: }
9928: if (@email_rule > 0) {
9929: foreach my $type (@email_rule) {
9930: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
9931: push(@{$changes{'email_rule'}},$type);
9932: }
9933: }
9934: }
9935: } elsif (@email_rule > 0) {
9936: push(@{$changes{'email_rule'}},@email_rule);
9937: }
9938: }
9939: #
1.160.6.40 raeburn 9940: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 9941: # institutional log-in.
9942: #
9943: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
9944: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9945: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
9946: ($domdefaults{'auth_def'} eq 'localauth'))) {
9947: $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.').' '.
9948: &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.');
9949: }
9950: }
9951: my @fields = ('lastname','firstname','middlename','generation',
9952: 'permanentemail','id');
1.160.6.44 raeburn 9953: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 9954: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9955: #
9956: # Where usernames may created for institutional log-in and/or institutional single sign on:
9957: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
9958: # may self-create accounts
9959: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
9960: # which the user may supply, if institutional data is unavailable.
9961: #
9962: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
9963: if (ref($types) eq 'ARRAY') {
1.160.6.35 raeburn 9964: if (@{$types} > 1) {
1.160.6.34 raeburn 9965: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
9966: push(@contexts,'statustocreate');
9967: } else {
9968: undef($cancreate{'statustocreate'});
9969: }
9970: foreach my $type (@{$types}) {
9971: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
9972: foreach my $field (@fields) {
9973: if (grep(/^\Q$field\E$/,@modifiable)) {
9974: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
9975: } else {
9976: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
9977: }
9978: }
9979: }
9980: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
9981: foreach my $type (@{$types}) {
9982: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
9983: foreach my $field (@fields) {
9984: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
9985: $curr_usermodify{'selfcreate'}{$type}{$field}) {
9986: push(@{$changes{'selfcreate'}},$type);
9987: last;
9988: }
9989: }
9990: }
9991: }
9992: } else {
9993: foreach my $type (@{$types}) {
9994: push(@{$changes{'selfcreate'}},$type);
9995: }
9996: }
9997: }
1.160.6.44 raeburn 9998: foreach my $field (@shibfields) {
9999: if ($env{'form.shibenv_'.$field} ne '') {
10000: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
10001: }
10002: }
10003: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
10004: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
10005: foreach my $field (@shibfields) {
10006: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
10007: push(@{$changes{'cancreate'}},'shibenv');
10008: }
10009: }
10010: } else {
10011: foreach my $field (@shibfields) {
10012: if ($env{'form.shibenv_'.$field}) {
10013: push(@{$changes{'cancreate'}},'shibenv');
10014: last;
10015: }
10016: }
10017: }
10018: }
1.160.6.34 raeburn 10019: }
10020: foreach my $item (@contexts) {
10021: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
10022: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
10023: if (ref($cancreate{$item}) eq 'ARRAY') {
10024: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
10025: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10026: push(@{$changes{'cancreate'}},$item);
10027: }
10028: }
10029: }
10030: }
10031: if (ref($cancreate{$item}) eq 'ARRAY') {
10032: foreach my $type (@{$cancreate{$item}}) {
10033: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
10034: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10035: push(@{$changes{'cancreate'}},$item);
10036: }
10037: }
10038: }
10039: }
10040: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
10041: if (ref($cancreate{$item}) eq 'HASH') {
10042: foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35 raeburn 10043: if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
10044: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
10045: unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
10046: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10047: push(@{$changes{'cancreate'}},$item);
10048: }
10049: }
10050: }
1.160.6.40 raeburn 10051: } elsif ($item eq 'selfcreateprocessing') {
10052: if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
10053: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10054: push(@{$changes{'cancreate'}},$item);
10055: }
10056: }
1.160.6.35 raeburn 10057: } else {
10058: if (!$cancreate{$item}{$curr}) {
10059: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10060: push(@{$changes{'cancreate'}},$item);
10061: }
1.160.6.34 raeburn 10062: }
10063: }
10064: }
10065: foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35 raeburn 10066: if (ref($cancreate{$item}{$field}) eq 'HASH') {
10067: foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
10068: if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
10069: unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
10070: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10071: push(@{$changes{'cancreate'}},$item);
10072: }
10073: }
10074: } else {
10075: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10076: push(@{$changes{'cancreate'}},$item);
10077: }
10078: }
10079: }
1.160.6.40 raeburn 10080: } elsif ($item eq 'selfcreateprocessing') {
10081: if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
10082: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10083: push(@{$changes{'cancreate'}},$item);
10084: }
10085: }
1.160.6.35 raeburn 10086: } else {
10087: if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
10088: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10089: push(@{$changes{'cancreate'}},$item);
10090: }
1.160.6.34 raeburn 10091: }
10092: }
10093: }
10094: }
10095: } elsif ($curr_usercreation{'cancreate'}{$item}) {
10096: if (ref($cancreate{$item}) eq 'ARRAY') {
10097: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
10098: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10099: push(@{$changes{'cancreate'}},$item);
10100: }
10101: }
10102: } elsif (ref($cancreate{$item}) eq 'HASH') {
10103: if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
10104: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10105: push(@{$changes{'cancreate'}},$item);
10106: }
10107: }
10108: }
10109: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 10110: if (ref($cancreate{$item}) eq 'HASH') {
10111: foreach my $type (keys(%{$cancreate{$item}})) {
10112: if (ref($cancreate{$item}{$type}) eq 'HASH') {
10113: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
10114: if ($cancreate{$item}{$type}{$field}) {
10115: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
10116: push(@{$changes{'cancreate'}},$item);
10117: }
10118: last;
10119: }
10120: }
10121: }
10122: }
1.160.6.34 raeburn 10123: }
10124: }
10125: }
10126: #
10127: # Populate %save_usercreate hash with updates to self-creation configuration.
10128: #
10129: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
10130: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 10131: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 10132: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
10133: if (ref($cancreate{'notify'}) eq 'HASH') {
10134: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
10135: }
1.160.6.40 raeburn 10136: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
10137: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
10138: }
1.160.6.34 raeburn 10139: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10140: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
10141: }
1.160.6.44 raeburn 10142: if (ref($cancreate{'shibenv'}) eq 'HASH') {
10143: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
10144: }
1.160.6.34 raeburn 10145: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.85 raeburn 10146: $save_usercreate{'email_rule'} = \@email_rule;
1.160.6.34 raeburn 10147:
10148: my %userconfig_hash = (
10149: usercreation => \%save_usercreate,
10150: usermodification => \%save_usermodify,
10151: );
10152: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
10153: $dom);
10154: #
10155: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
10156: #
1.27 raeburn 10157: if ($putresult eq 'ok') {
10158: if (keys(%changes) > 0) {
10159: $resulttext = &mt('Changes made:').'<ul>';
10160: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 10161: my %lt = &selfcreation_types();
1.34 raeburn 10162: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 10163: my $chgtext;
1.45 raeburn 10164: if ($type eq 'selfcreate') {
1.50 raeburn 10165: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 10166: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 10167: } else {
1.160.6.34 raeburn 10168: $chgtext .= &mt('Self-creation of a new account is permitted for:').
10169: '<ul>';
1.50 raeburn 10170: foreach my $case (@{$cancreate{$type}}) {
10171: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
10172: }
10173: $chgtext .= '</ul>';
1.100 raeburn 10174: if (ref($cancreate{$type}) eq 'ARRAY') {
10175: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
10176: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
10177: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34 raeburn 10178: $chgtext .= '<br />'.
10179: '<span class="LC_warning">'.
10180: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10181: '</span>';
1.100 raeburn 10182: }
10183: }
10184: }
10185: }
1.43 raeburn 10186: }
1.160.6.44 raeburn 10187: } elsif ($type eq 'shibenv') {
10188: if (keys(%{$cancreate{$type}}) == 0) {
10189: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information');
10190: } else {
10191: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
10192: '<ul>';
10193: foreach my $field (@shibfields) {
10194: next if ($cancreate{$type}{$field} eq '');
10195: if ($field eq 'inststatus') {
10196: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
10197: } else {
10198: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
10199: }
10200: }
10201: $chgtext .= '</ul>';
10202: }
1.93 raeburn 10203: } elsif ($type eq 'statustocreate') {
1.96 raeburn 10204: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
10205: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
10206: if (@{$cancreate{'selfcreate'}} > 0) {
10207: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 10208: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 10209: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10210: $chgtext .= '<br />'.
10211: '<span class="LC_warning">'.
10212: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
10213: '</span>';
10214: }
1.96 raeburn 10215: } elsif (ref($usertypes) eq 'HASH') {
10216: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 10217: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
10218: } else {
10219: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
10220: }
10221: $chgtext .= '<ul>';
10222: foreach my $case (@{$cancreate{$type}}) {
10223: if ($case eq 'default') {
10224: $chgtext .= '<li>'.$othertitle.'</li>';
10225: } else {
10226: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 10227: }
10228: }
1.100 raeburn 10229: $chgtext .= '</ul>';
10230: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 10231: $chgtext .= '<br /><span class="LC_warning">'.
10232: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
10233: '</span>';
1.100 raeburn 10234: }
10235: }
10236: } else {
10237: if (@{$cancreate{$type}} == 0) {
10238: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
10239: } else {
10240: $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 10241: }
10242: }
10243: }
1.160.6.40 raeburn 10244: } elsif ($type eq 'selfcreateprocessing') {
10245: my %choices = &Apache::lonlocal::texthash (
10246: automatic => 'Automatic approval',
10247: approval => 'Queued for approval',
10248: );
10249: if (@statuses > 1) {
10250: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:').
10251: '<ul>';
10252: foreach my $type (@statuses) {
10253: if ($type eq 'default') {
10254: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10255: } else {
10256: $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
10257: }
10258: }
10259: $chgtext .= '</ul>';
10260: } else {
10261: $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
10262: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
10263: }
1.160.6.5 raeburn 10264: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 10265: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 10266: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
10267: } else {
10268: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 10269: if ($captchas{$savecaptcha{$type}}) {
10270: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 10271: } else {
10272: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
10273: }
10274: }
10275: } elsif ($type eq 'recaptchakeys') {
10276: my ($privkey,$pubkey);
1.160.6.34 raeburn 10277: if (ref($savecaptcha{$type}) eq 'HASH') {
10278: $pubkey = $savecaptcha{$type}{'public'};
10279: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 10280: }
10281: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
10282: if (!$pubkey) {
10283: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
10284: } else {
10285: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10286: }
10287: if (!$privkey) {
10288: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
10289: } else {
10290: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
10291: }
10292: $chgtext .= '</ul>';
1.160.6.69 raeburn 10293: } elsif ($type eq 'recaptchaversion') {
10294: if ($savecaptcha{'captcha'} eq 'recaptcha') {
10295: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
10296: }
1.160.6.34 raeburn 10297: } elsif ($type eq 'emailusername') {
10298: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35 raeburn 10299: if (ref($types) eq 'ARRAY') {
10300: foreach my $type (@{$types}) {
10301: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
10302: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50 raeburn 10303: $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 10304: '<ul>';
10305: foreach my $field (@{$infofields}) {
10306: if ($cancreate{'emailusername'}{$type}{$field}) {
10307: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
10308: }
10309: }
1.160.6.50 raeburn 10310: $chgtext .= '</ul>';
10311: } else {
10312: $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 10313: }
10314: } else {
1.160.6.50 raeburn 10315: $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 10316: }
10317: }
10318: }
10319: }
10320: } elsif ($type eq 'notify') {
10321: $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
10322: if (ref($changes{'cancreate'}) eq 'ARRAY') {
10323: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
10324: if ($cancreate{'notify'}{'approval'}) {
10325: $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
10326: }
10327: }
1.43 raeburn 10328: }
1.34 raeburn 10329: }
1.160.6.34 raeburn 10330: if ($chgtext) {
10331: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 10332: }
10333: }
10334: }
1.43 raeburn 10335: if (ref($changes{'email_rule'}) eq 'ARRAY') {
10336: my ($emailrules,$emailruleorder) =
10337: &Apache::lonnet::inst_userrules($dom,'email');
10338: my $chgtext = '<ul>';
10339: foreach my $type (@email_rule) {
10340: if (ref($emailrules->{$type}) eq 'HASH') {
10341: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
10342: }
10343: }
10344: $chgtext .= '</ul>';
10345: if (@email_rule > 0) {
1.160.6.34 raeburn 10346: $resulttext .= '<li>'.
10347: &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
10348: $chgtext.
10349: '</li>';
1.43 raeburn 10350: } else {
1.160.6.34 raeburn 10351: $resulttext .= '<li>'.
10352: &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
10353: '</li>';
1.43 raeburn 10354: }
10355: }
1.160.6.34 raeburn 10356: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
10357: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
10358: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10359: foreach my $type (@{$changes{'selfcreate'}}) {
10360: my $typename = $type;
10361: if (ref($usertypes) eq 'HASH') {
10362: if ($usertypes->{$type} ne '') {
10363: $typename = $usertypes->{$type};
1.28 raeburn 10364: }
10365: }
1.160.6.34 raeburn 10366: my @modifiable;
10367: $resulttext .= '<li>'.
10368: &mt('Self-creation of account by users with status: [_1]',
10369: '<span class="LC_cusr_emph">'.$typename.'</span>').
10370: ' - '.&mt('modifiable fields (if institutional data blank): ');
10371: foreach my $field (@fields) {
10372: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
10373: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
10374: }
10375: }
10376: if (@modifiable > 0) {
10377: $resulttext .= join(', ',@modifiable);
1.43 raeburn 10378: } else {
1.160.6.34 raeburn 10379: $resulttext .= &mt('none');
1.43 raeburn 10380: }
1.160.6.34 raeburn 10381: $resulttext .= '</li>';
1.28 raeburn 10382: }
1.160.6.34 raeburn 10383: $resulttext .= '</ul></li>';
1.28 raeburn 10384: }
1.27 raeburn 10385: $resulttext .= '</ul>';
10386: } else {
1.160.6.34 raeburn 10387: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 10388: }
10389: } else {
10390: $resulttext = '<span class="LC_error">'.
1.23 raeburn 10391: &mt('An error occurred: [_1]',$putresult).'</span>';
10392: }
1.43 raeburn 10393: if ($warningmsg ne '') {
10394: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
10395: }
1.23 raeburn 10396: return $resulttext;
10397: }
10398:
1.160.6.5 raeburn 10399: sub process_captcha {
10400: my ($container,$changes,$newsettings,$current) = @_;
10401: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
10402: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
10403: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
10404: $newsettings->{'captcha'} = 'original';
10405: }
10406: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
10407: if ($container eq 'cancreate') {
10408: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10409: push(@{$changes->{'cancreate'}},'captcha');
10410: } elsif (!defined($changes->{'cancreate'})) {
10411: $changes->{'cancreate'} = ['captcha'];
10412: }
10413: } else {
10414: $changes->{'captcha'} = 1;
10415: }
10416: }
1.160.6.69 raeburn 10417: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 10418: if ($newsettings->{'captcha'} eq 'recaptcha') {
10419: $newpub = $env{'form.'.$container.'_recaptchapub'};
10420: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 10421: $newpub =~ s/[^\w\-]//g;
10422: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 10423: $newsettings->{'recaptchakeys'} = {
10424: public => $newpub,
10425: private => $newpriv,
10426: };
1.160.6.69 raeburn 10427: $newversion = $env{'form.'.$container.'_recaptchaversion'};
10428: $newversion =~ s/\D//g;
10429: if ($newversion ne '2') {
10430: $newversion = 1;
10431: }
10432: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 10433: }
10434: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
10435: $currpub = $current->{'recaptchakeys'}{'public'};
10436: $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 10437: unless ($newsettings->{'captcha'} eq 'recaptcha') {
10438: $newsettings->{'recaptchakeys'} = {
10439: public => '',
10440: private => '',
10441: }
10442: }
1.160.6.5 raeburn 10443: }
1.160.6.69 raeburn 10444: if ($current->{'captcha'} eq 'recaptcha') {
10445: $currversion = $current->{'recaptchaversion'};
10446: if ($currversion ne '2') {
10447: $currversion = 1;
10448: }
10449: }
10450: if ($currversion ne $newversion) {
10451: if ($container eq 'cancreate') {
10452: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10453: push(@{$changes->{'cancreate'}},'recaptchaversion');
10454: } elsif (!defined($changes->{'cancreate'})) {
10455: $changes->{'cancreate'} = ['recaptchaversion'];
10456: }
10457: } else {
10458: $changes->{'recaptchaversion'} = 1;
10459: }
10460: }
1.160.6.5 raeburn 10461: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
10462: if ($container eq 'cancreate') {
10463: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
10464: push(@{$changes->{'cancreate'}},'recaptchakeys');
10465: } elsif (!defined($changes->{'cancreate'})) {
10466: $changes->{'cancreate'} = ['recaptchakeys'];
10467: }
10468: } else {
10469: $changes->{'recaptchakeys'} = 1;
10470: }
10471: }
10472: return;
10473: }
10474:
1.33 raeburn 10475: sub modify_usermodification {
10476: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 10477: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 10478: if (ref($domconfig{'usermodification'}) eq 'HASH') {
10479: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 10480: if ($key eq 'selfcreate') {
10481: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
10482: } else {
10483: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
10484: }
1.33 raeburn 10485: }
10486: }
1.160.6.34 raeburn 10487: my @contexts = ('author','course');
1.33 raeburn 10488: my %context_title = (
10489: author => 'In author context',
10490: course => 'In course context',
10491: );
10492: my @fields = ('lastname','firstname','middlename','generation',
10493: 'permanentemail','id');
10494: my %roles = (
10495: author => ['ca','aa'],
10496: course => ['st','ep','ta','in','cr'],
10497: );
10498: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10499: foreach my $context (@contexts) {
10500: foreach my $role (@{$roles{$context}}) {
10501: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
10502: foreach my $item (@fields) {
10503: if (grep(/^\Q$item\E$/,@modifiable)) {
10504: $modifyhash{$context}{$role}{$item} = 1;
10505: } else {
10506: $modifyhash{$context}{$role}{$item} = 0;
10507: }
10508: }
10509: }
10510: if (ref($curr_usermodification{$context}) eq 'HASH') {
10511: foreach my $role (@{$roles{$context}}) {
10512: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
10513: foreach my $field (@fields) {
10514: if ($modifyhash{$context}{$role}{$field} ne
10515: $curr_usermodification{$context}{$role}{$field}) {
10516: push(@{$changes{$context}},$role);
10517: last;
10518: }
10519: }
10520: }
10521: }
10522: } else {
10523: foreach my $context (@contexts) {
10524: foreach my $role (@{$roles{$context}}) {
10525: push(@{$changes{$context}},$role);
10526: }
10527: }
10528: }
10529: }
10530: my %usermodification_hash = (
10531: usermodification => \%modifyhash,
10532: );
10533: my $putresult = &Apache::lonnet::put_dom('configuration',
10534: \%usermodification_hash,$dom);
10535: if ($putresult eq 'ok') {
10536: if (keys(%changes) > 0) {
10537: $resulttext = &mt('Changes made: ').'<ul>';
10538: foreach my $context (@contexts) {
10539: if (ref($changes{$context}) eq 'ARRAY') {
10540: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
10541: if (ref($changes{$context}) eq 'ARRAY') {
10542: foreach my $role (@{$changes{$context}}) {
10543: my $rolename;
1.160.6.34 raeburn 10544: if ($role eq 'cr') {
10545: $rolename = &mt('Custom');
1.33 raeburn 10546: } else {
1.160.6.34 raeburn 10547: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 10548: }
10549: my @modifiable;
1.160.6.34 raeburn 10550: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 10551: foreach my $field (@fields) {
10552: if ($modifyhash{$context}{$role}{$field}) {
10553: push(@modifiable,$fieldtitles{$field});
10554: }
10555: }
10556: if (@modifiable > 0) {
10557: $resulttext .= join(', ',@modifiable);
10558: } else {
10559: $resulttext .= &mt('none');
10560: }
10561: $resulttext .= '</li>';
10562: }
10563: $resulttext .= '</ul></li>';
10564: }
10565: }
10566: }
10567: $resulttext .= '</ul>';
10568: } else {
10569: $resulttext = &mt('No changes made to user modification settings');
10570: }
10571: } else {
10572: $resulttext = '<span class="LC_error">'.
10573: &mt('An error occurred: [_1]',$putresult).'</span>';
10574: }
10575: return $resulttext;
10576: }
10577:
1.43 raeburn 10578: sub modify_defaults {
1.160.6.27 raeburn 10579: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 10580: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 10581: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 10582: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
10583: 'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43 raeburn 10584: my @authtypes = ('internal','krb4','krb5','localauth');
10585: foreach my $item (@items) {
10586: $newvalues{$item} = $env{'form.'.$item};
10587: if ($item eq 'auth_def') {
10588: if ($newvalues{$item} ne '') {
10589: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
10590: push(@errors,$item);
10591: }
10592: }
10593: } elsif ($item eq 'lang_def') {
10594: if ($newvalues{$item} ne '') {
10595: if ($newvalues{$item} =~ /^(\w+)/) {
10596: my $langcode = $1;
1.103 raeburn 10597: if ($langcode ne 'x_chef') {
10598: if (code2language($langcode) eq '') {
10599: push(@errors,$item);
10600: }
1.43 raeburn 10601: }
10602: } else {
10603: push(@errors,$item);
10604: }
10605: }
1.54 raeburn 10606: } elsif ($item eq 'timezone_def') {
10607: if ($newvalues{$item} ne '') {
1.62 raeburn 10608: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 10609: push(@errors,$item);
10610: }
10611: }
1.68 raeburn 10612: } elsif ($item eq 'datelocale_def') {
10613: if ($newvalues{$item} ne '') {
10614: my @datelocale_ids = DateTime::Locale->ids();
10615: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
10616: push(@errors,$item);
10617: }
10618: }
1.141 raeburn 10619: } elsif ($item eq 'portal_def') {
10620: if ($newvalues{$item} ne '') {
10621: 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])\/?$/) {
10622: push(@errors,$item);
10623: }
10624: }
1.160.6.80 raeburn 10625: } elsif ($item eq 'intauth_cost') {
10626: if ($newvalues{$item} ne '') {
10627: if ($newvalues{$item} =~ /\D/) {
10628: push(@errors,$item);
10629: }
10630: }
10631: } elsif ($item eq 'intauth_check') {
10632: if ($newvalues{$item} ne '') {
10633: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
10634: push(@errors,$item);
10635: }
10636: }
10637: } elsif ($item eq 'intauth_switch') {
10638: if ($newvalues{$item} ne '') {
10639: unless ($newvalues{$item} =~ /^(0|1|2)$/) {
10640: push(@errors,$item);
10641: }
10642: }
1.43 raeburn 10643: }
10644: if (grep(/^\Q$item\E$/,@errors)) {
10645: $newvalues{$item} = $domdefaults{$item};
10646: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
10647: $changes{$item} = 1;
10648: }
1.72 raeburn 10649: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 10650: }
10651: my %defaults_hash = (
1.72 raeburn 10652: defaults => \%newvalues,
10653: );
1.43 raeburn 10654: my $title = &defaults_titles();
1.160.6.40 raeburn 10655:
10656: my $currinststatus;
10657: if (ref($domconfig{'inststatus'}) eq 'HASH') {
10658: $currinststatus = $domconfig{'inststatus'};
10659: } else {
10660: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
10661: $currinststatus = {
10662: inststatustypes => $usertypes,
10663: inststatusorder => $types,
10664: inststatusguest => [],
10665: };
10666: }
10667: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
10668: my @allpos;
10669: my %guests;
10670: my %alltypes;
10671: my ($currtitles,$currguests,$currorder);
10672: if (ref($currinststatus) eq 'HASH') {
10673: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
10674: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
10675: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
10676: if ($currinststatus->{inststatustypes}->{$type} ne '') {
10677: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
10678: }
10679: }
10680: unless (grep(/^\Q$type\E$/,@todelete)) {
10681: my $position = $env{'form.inststatus_pos_'.$type};
10682: $position =~ s/\D+//g;
10683: $allpos[$position] = $type;
10684: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
10685: $alltypes{$type} =~ s/`//g;
10686: if ($env{'form.inststatus_guest_'.$type}) {
10687: $guests{$type} = 1;
10688: }
10689: }
10690: }
10691: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
10692: $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
10693: }
10694: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
10695: $currtitles =~ s/,$//;
10696: }
10697: }
10698: if ($env{'form.addinststatus'}) {
10699: my $newtype = $env{'form.addinststatus'};
10700: $newtype =~ s/\W//g;
10701: unless (exists($alltypes{$newtype})) {
10702: if ($env{'form.addinststatus_guest'}) {
10703: $guests{$newtype} = 1;
10704: }
10705: $alltypes{$newtype} = $env{'form.addinststatus_title'};
10706: $alltypes{$newtype} =~ s/`//g;
10707: my $position = $env{'form.addinststatus_pos'};
10708: $position =~ s/\D+//g;
10709: if ($position ne '') {
10710: $allpos[$position] = $newtype;
10711: }
10712: }
10713: }
10714: my (@orderedstatus,@orderedguests);
10715: foreach my $type (@allpos) {
10716: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
10717: push(@orderedstatus,$type);
10718: if ($guests{$type}) {
10719: push(@orderedguests,$type);
10720: }
10721: }
10722: }
10723: foreach my $type (keys(%alltypes)) {
10724: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
10725: delete($alltypes{$type});
10726: }
10727: }
10728: $defaults_hash{'inststatus'} = {
10729: inststatustypes => \%alltypes,
10730: inststatusorder => \@orderedstatus,
10731: inststatusguest => \@orderedguests,
10732: };
10733: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
10734: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
10735: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
10736: }
10737: }
10738: if ($currorder ne join(',',@orderedstatus)) {
10739: $changes{'inststatus'}{'inststatusorder'} = 1;
10740: }
10741: if ($currguests ne join(',',@orderedguests)) {
10742: $changes{'inststatus'}{'inststatusguest'} = 1;
10743: }
10744: my $newtitles;
10745: foreach my $item (@orderedstatus) {
10746: $newtitles .= $alltypes{$item}.',';
10747: }
10748: $newtitles =~ s/,$//;
10749: if ($currtitles ne $newtitles) {
10750: $changes{'inststatus'}{'inststatustypes'} = 1;
10751: }
1.43 raeburn 10752: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
10753: $dom);
10754: if ($putresult eq 'ok') {
10755: if (keys(%changes) > 0) {
10756: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 10757: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 10758: 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";
10759: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 10760: if ($item eq 'inststatus') {
10761: if (ref($changes{'inststatus'}) eq 'HASH') {
10762: if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
10763: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
10764: foreach my $type (@orderedstatus) {
10765: $resulttext .= $alltypes{$type}.', ';
10766: }
10767: $resulttext =~ s/, $//;
10768: $resulttext .= '</li>';
10769: }
10770: if ($changes{'inststatus'}{'inststatusguest'}) {
10771: $resulttext .= '<li>';
10772: if (@orderedguests) {
10773: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
10774: foreach my $type (@orderedguests) {
10775: $resulttext .= $alltypes{$type}.', ';
10776: }
10777: $resulttext =~ s/, $//;
10778: } else {
10779: $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
10780: }
10781: $resulttext .= '</li>';
10782: }
10783: }
10784: } else {
10785: my $value = $env{'form.'.$item};
10786: if ($value eq '') {
10787: $value = &mt('none');
10788: } elsif ($item eq 'auth_def') {
10789: my %authnames = &authtype_names();
10790: my %shortauth = (
10791: internal => 'int',
10792: krb4 => 'krb4',
10793: krb5 => 'krb5',
10794: localauth => 'loc',
10795: );
10796: $value = $authnames{$shortauth{$value}};
1.160.6.80 raeburn 10797: } elsif ($item eq 'intauth_switch') {
10798: my %optiondesc = &Apache::lonlocal::texthash (
10799: 0 => 'No',
10800: 1 => 'Yes',
10801: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
10802: );
10803: if ($value =~ /^(0|1|2)$/) {
10804: $value = $optiondesc{$value};
10805: } else {
10806: $value = &mt('none -- defaults to No');
10807: }
10808: } elsif ($item eq 'intauth_check') {
10809: my %optiondesc = &Apache::lonlocal::texthash (
10810: 0 => 'No',
10811: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
10812: 2 => 'Yes, disallow login if stored cost is less than domain default',
10813: );
10814: if ($value =~ /^(0|1|2)$/) {
10815: $value = $optiondesc{$value};
10816: } else {
10817: $value = &mt('none -- defaults to No');
10818: }
1.160.6.40 raeburn 10819: }
10820: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
10821: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 10822: }
10823: }
10824: $resulttext .= '</ul>';
10825: $mailmsgtext .= "\n";
10826: my $cachetime = 24*60*60;
1.72 raeburn 10827: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 10828: if (ref($lastactref) eq 'HASH') {
10829: $lastactref->{'domdefaults'} = 1;
10830: }
1.68 raeburn 10831: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 10832: my $notify = 1;
10833: if (ref($domconfig{'contacts'}) eq 'HASH') {
10834: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
10835: $notify = 0;
10836: }
10837: }
10838: if ($notify) {
10839: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
10840: "LON-CAPA Domain Settings Change - $dom",
10841: $mailmsgtext);
10842: }
1.54 raeburn 10843: }
1.43 raeburn 10844: } else {
1.54 raeburn 10845: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 10846: }
10847: } else {
10848: $resulttext = '<span class="LC_error">'.
10849: &mt('An error occurred: [_1]',$putresult).'</span>';
10850: }
10851: if (@errors > 0) {
10852: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
10853: foreach my $item (@errors) {
10854: $resulttext .= ' "'.$title->{$item}.'",';
10855: }
10856: $resulttext =~ s/,$//;
10857: }
10858: return $resulttext;
10859: }
10860:
1.46 raeburn 10861: sub modify_scantron {
1.160.6.24 raeburn 10862: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 10863: my ($resulttext,%confhash,%changes,$errors);
10864: my $custom = 'custom.tab';
10865: my $default = 'default.tab';
10866: my $servadm = $r->dir_config('lonAdmEMail');
10867: my ($configuserok,$author_ok,$switchserver) =
10868: &config_check($dom,$confname,$servadm);
10869: if ($env{'form.scantronformat.filename'} ne '') {
10870: my $error;
10871: if ($configuserok eq 'ok') {
10872: if ($switchserver) {
1.130 raeburn 10873: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 10874: } else {
10875: if ($author_ok eq 'ok') {
10876: my ($result,$scantronurl) =
10877: &publishlogo($r,'upload','scantronformat',$dom,
10878: $confname,'scantron','','',$custom);
10879: if ($result eq 'ok') {
10880: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 10881: $changes{'scantronformat'} = 1;
1.46 raeburn 10882: } else {
10883: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
10884: }
10885: } else {
10886: $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);
10887: }
10888: }
10889: } else {
10890: $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);
10891: }
10892: if ($error) {
10893: &Apache::lonnet::logthis($error);
10894: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10895: }
10896: }
1.48 raeburn 10897: if (ref($domconfig{'scantron'}) eq 'HASH') {
10898: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
10899: if ($env{'form.scantronformat_del'}) {
10900: $confhash{'scantron'}{'scantronformat'} = '';
10901: $changes{'scantronformat'} = 1;
1.46 raeburn 10902: }
10903: }
10904: }
10905: if (keys(%confhash) > 0) {
10906: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
10907: $dom);
10908: if ($putresult eq 'ok') {
10909: if (keys(%changes) > 0) {
1.48 raeburn 10910: if (ref($confhash{'scantron'}) eq 'HASH') {
10911: $resulttext = &mt('Changes made:').'<ul>';
10912: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 10913: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 10914: } else {
1.130 raeburn 10915: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 10916: }
1.48 raeburn 10917: $resulttext .= '</ul>';
10918: } else {
1.130 raeburn 10919: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 10920: }
10921: $resulttext .= '</ul>';
10922: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10923: if (ref($lastactref) eq 'HASH') {
10924: $lastactref->{'domainconfig'} = 1;
10925: }
1.46 raeburn 10926: } else {
1.130 raeburn 10927: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10928: }
10929: } else {
10930: $resulttext = '<span class="LC_error">'.
10931: &mt('An error occurred: [_1]',$putresult).'</span>';
10932: }
10933: } else {
1.130 raeburn 10934: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 10935: }
10936: if ($errors) {
10937: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10938: $errors.'</ul>';
10939: }
10940: return $resulttext;
10941: }
10942:
1.48 raeburn 10943: sub modify_coursecategories {
1.160.6.43 raeburn 10944: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 10945: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
10946: $cathash);
1.48 raeburn 10947: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 10948: my @catitems = ('unauth','auth');
10949: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 10950: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 10951: $cathash = $domconfig{'coursecategories'}{'cats'};
10952: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
10953: $changes{'togglecats'} = 1;
10954: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
10955: }
10956: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
10957: $changes{'categorize'} = 1;
10958: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
10959: }
1.120 raeburn 10960: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
10961: $changes{'togglecatscomm'} = 1;
10962: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
10963: }
10964: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
10965: $changes{'categorizecomm'} = 1;
10966: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
10967: }
1.160.6.42 raeburn 10968: foreach my $item (@catitems) {
10969: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10970: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
10971: $changes{$item} = 1;
10972: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10973: }
10974: }
10975: }
1.57 raeburn 10976: } else {
10977: $changes{'togglecats'} = 1;
10978: $changes{'categorize'} = 1;
1.124 raeburn 10979: $changes{'togglecatscomm'} = 1;
10980: $changes{'categorizecomm'} = 1;
1.87 raeburn 10981: $domconfig{'coursecategories'} = {
10982: togglecats => $env{'form.togglecats'},
10983: categorize => $env{'form.categorize'},
1.124 raeburn 10984: togglecatscomm => $env{'form.togglecatscomm'},
10985: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 10986: };
1.160.6.42 raeburn 10987: foreach my $item (@catitems) {
10988: if ($env{'form.coursecat_'.$item} ne 'std') {
10989: $changes{$item} = 1;
10990: }
10991: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
10992: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
10993: }
10994: }
1.57 raeburn 10995: }
10996: if (ref($cathash) eq 'HASH') {
10997: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 10998: push (@deletecategory,'instcode::0');
10999: }
1.120 raeburn 11000: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
11001: push(@deletecategory,'communities::0');
11002: }
1.48 raeburn 11003: }
1.57 raeburn 11004: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
11005: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11006: if (@deletecategory > 0) {
11007: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 11008: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 11009: foreach my $item (@deletecategory) {
1.57 raeburn 11010: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
11011: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 11012: $deletions{$item} = 1;
1.57 raeburn 11013: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 11014: }
11015: }
11016: }
1.57 raeburn 11017: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 11018: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 11019: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 11020: $reorderings{$item} = 1;
1.57 raeburn 11021: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 11022: }
11023: if ($env{'form.addcategory_name_'.$item} ne '') {
11024: my $newcat = $env{'form.addcategory_name_'.$item};
11025: my $newdepth = $depth+1;
11026: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11027: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 11028: $adds{$newitem} = 1;
11029: }
11030: if ($env{'form.subcat_'.$item} ne '') {
11031: my $newcat = $env{'form.subcat_'.$item};
11032: my $newdepth = $depth+1;
11033: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 11034: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 11035: $adds{$newitem} = 1;
11036: }
11037: }
11038: }
11039: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 11040: if (ref($cathash) eq 'HASH') {
1.48 raeburn 11041: my $newitem = 'instcode::0';
1.57 raeburn 11042: if ($cathash->{$newitem} eq '') {
11043: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11044: $adds{$newitem} = 1;
11045: }
11046: } else {
11047: my $newitem = 'instcode::0';
1.57 raeburn 11048: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 11049: $adds{$newitem} = 1;
11050: }
11051: }
1.120 raeburn 11052: if ($env{'form.communities'} eq '1') {
11053: if (ref($cathash) eq 'HASH') {
11054: my $newitem = 'communities::0';
11055: if ($cathash->{$newitem} eq '') {
11056: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11057: $adds{$newitem} = 1;
11058: }
11059: } else {
11060: my $newitem = 'communities::0';
11061: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
11062: $adds{$newitem} = 1;
11063: }
11064: }
1.48 raeburn 11065: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 11066: if (($env{'form.addcategory_name'} ne 'instcode') &&
11067: ($env{'form.addcategory_name'} ne 'communities')) {
11068: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
11069: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
11070: $adds{$newitem} = 1;
11071: }
1.48 raeburn 11072: }
1.57 raeburn 11073: my $putresult;
1.48 raeburn 11074: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11075: if (keys(%deletions) > 0) {
11076: foreach my $key (keys(%deletions)) {
11077: if ($predelallitems{$key} ne '') {
11078: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
11079: }
11080: }
11081: }
11082: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 11083: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 11084: if (ref($chkcats[0]) eq 'ARRAY') {
11085: my $depth = 0;
11086: my $chg = 0;
11087: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
11088: my $name = $chkcats[0][$i];
11089: my $item;
11090: if ($name eq '') {
11091: $chg ++;
11092: } else {
11093: $item = &escape($name).'::0';
11094: if ($chg) {
1.57 raeburn 11095: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 11096: }
11097: $depth ++;
1.57 raeburn 11098: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 11099: $depth --;
11100: }
11101: }
11102: }
1.57 raeburn 11103: }
11104: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11105: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 11106: if ($putresult eq 'ok') {
1.57 raeburn 11107: my %title = (
1.120 raeburn 11108: togglecats => 'Show/Hide a course in catalog',
11109: categorize => 'Assign a category to a course',
11110: togglecatscomm => 'Show/Hide a community in catalog',
11111: categorizecomm => 'Assign a category to a community',
1.57 raeburn 11112: );
11113: my %level = (
1.120 raeburn 11114: dom => 'set in Domain ("Modify Course/Community")',
11115: crs => 'set in Course ("Course Configuration")',
11116: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 11117: none => 'No catalog',
11118: std => 'Standard catalog',
11119: domonly => 'Domain-only catalog',
11120: codesrch => 'Code search form',
1.57 raeburn 11121: );
1.48 raeburn 11122: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 11123: if ($changes{'togglecats'}) {
11124: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
11125: }
11126: if ($changes{'categorize'}) {
11127: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 11128: }
1.120 raeburn 11129: if ($changes{'togglecatscomm'}) {
11130: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
11131: }
11132: if ($changes{'categorizecomm'}) {
11133: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
11134: }
1.160.6.42 raeburn 11135: if ($changes{'unauth'}) {
11136: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
11137: }
11138: if ($changes{'auth'}) {
11139: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
11140: }
1.57 raeburn 11141: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
11142: my $cathash;
11143: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
11144: $cathash = $domconfig{'coursecategories'}{'cats'};
11145: } else {
11146: $cathash = {};
11147: }
11148: my (@cats,@trails,%allitems);
11149: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
11150: if (keys(%deletions) > 0) {
11151: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
11152: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
11153: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
11154: }
11155: $resulttext .= '</ul></li>';
11156: }
11157: if (keys(%reorderings) > 0) {
11158: my %sort_by_trail;
11159: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
11160: foreach my $key (keys(%reorderings)) {
11161: if ($allitems{$key} ne '') {
11162: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11163: }
1.48 raeburn 11164: }
1.57 raeburn 11165: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11166: $resulttext .= '<li>'.$trails[$trail].'</li>';
11167: }
11168: $resulttext .= '</ul></li>';
1.48 raeburn 11169: }
1.57 raeburn 11170: if (keys(%adds) > 0) {
11171: my %sort_by_trail;
11172: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
11173: foreach my $key (keys(%adds)) {
11174: if ($allitems{$key} ne '') {
11175: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
11176: }
11177: }
11178: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
11179: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 11180: }
1.57 raeburn 11181: $resulttext .= '</ul></li>';
1.48 raeburn 11182: }
11183: }
11184: $resulttext .= '</ul>';
1.160.6.43 raeburn 11185: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 11186: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11187: if ($changes{'auth'}) {
11188: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
11189: }
11190: if ($changes{'unauth'}) {
11191: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
11192: }
11193: my $cachetime = 24*60*60;
11194: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 11195: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 11196: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 11197: }
11198: }
1.48 raeburn 11199: } else {
11200: $resulttext = '<span class="LC_error">'.
1.57 raeburn 11201: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 11202: }
11203: } else {
1.120 raeburn 11204: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 11205: }
11206: return $resulttext;
11207: }
11208:
1.69 raeburn 11209: sub modify_serverstatuses {
11210: my ($dom,%domconfig) = @_;
11211: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
11212: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
11213: %currserverstatus = %{$domconfig{'serverstatuses'}};
11214: }
11215: my @pages = &serverstatus_pages();
11216: foreach my $type (@pages) {
11217: $newserverstatus{$type}{'namedusers'} = '';
11218: $newserverstatus{$type}{'machines'} = '';
11219: if (defined($env{'form.'.$type.'_namedusers'})) {
11220: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
11221: my @okusers;
11222: foreach my $user (@users) {
11223: my ($uname,$udom) = split(/:/,$user);
11224: if (($udom =~ /^$match_domain$/) &&
11225: (&Apache::lonnet::domain($udom)) &&
11226: ($uname =~ /^$match_username$/)) {
11227: if (!grep(/^\Q$user\E/,@okusers)) {
11228: push(@okusers,$user);
11229: }
11230: }
11231: }
11232: if (@okusers > 0) {
11233: @okusers = sort(@okusers);
11234: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
11235: }
11236: }
11237: if (defined($env{'form.'.$type.'_machines'})) {
11238: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
11239: my @okmachines;
11240: foreach my $ip (@machines) {
11241: my @parts = split(/\./,$ip);
11242: next if (@parts < 4);
11243: my $badip = 0;
11244: for (my $i=0; $i<4; $i++) {
11245: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
11246: $badip = 1;
11247: last;
11248: }
11249: }
11250: if (!$badip) {
11251: push(@okmachines,$ip);
11252: }
11253: }
11254: @okmachines = sort(@okmachines);
11255: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
11256: }
11257: }
11258: my %serverstatushash = (
11259: serverstatuses => \%newserverstatus,
11260: );
11261: foreach my $type (@pages) {
1.83 raeburn 11262: foreach my $setting ('namedusers','machines') {
1.84 raeburn 11263: my (@current,@new);
1.83 raeburn 11264: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 11265: if ($currserverstatus{$type}{$setting} ne '') {
11266: @current = split(/,/,$currserverstatus{$type}{$setting});
11267: }
11268: }
11269: if ($newserverstatus{$type}{$setting} ne '') {
11270: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 11271: }
11272: if (@current > 0) {
11273: if (@new > 0) {
11274: foreach my $item (@current) {
11275: if (!grep(/^\Q$item\E$/,@new)) {
11276: $changes{$type}{$setting} = 1;
1.82 raeburn 11277: last;
11278: }
11279: }
1.84 raeburn 11280: foreach my $item (@new) {
11281: if (!grep(/^\Q$item\E$/,@current)) {
11282: $changes{$type}{$setting} = 1;
11283: last;
1.82 raeburn 11284: }
11285: }
11286: } else {
1.83 raeburn 11287: $changes{$type}{$setting} = 1;
1.69 raeburn 11288: }
1.83 raeburn 11289: } elsif (@new > 0) {
11290: $changes{$type}{$setting} = 1;
1.69 raeburn 11291: }
11292: }
11293: }
11294: if (keys(%changes) > 0) {
1.81 raeburn 11295: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11296: my $putresult = &Apache::lonnet::put_dom('configuration',
11297: \%serverstatushash,$dom);
11298: if ($putresult eq 'ok') {
11299: $resulttext .= &mt('Changes made:').'<ul>';
11300: foreach my $type (@pages) {
1.84 raeburn 11301: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 11302: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 11303: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 11304: if ($newserverstatus{$type}{'namedusers'} eq '') {
11305: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
11306: } else {
11307: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
11308: }
1.84 raeburn 11309: }
11310: if ($changes{$type}{'machines'}) {
1.69 raeburn 11311: if ($newserverstatus{$type}{'machines'} eq '') {
11312: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
11313: } else {
11314: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
11315: }
11316:
11317: }
11318: $resulttext .= '</ul></li>';
11319: }
11320: }
11321: $resulttext .= '</ul>';
11322: } else {
11323: $resulttext = '<span class="LC_error">'.
11324: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
11325:
11326: }
11327: } else {
11328: $resulttext = &mt('No changes made to access to server status pages');
11329: }
11330: return $resulttext;
11331: }
11332:
1.118 jms 11333: sub modify_helpsettings {
1.160.6.77 raeburn 11334: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 11335: my ($resulttext,$errors,%changes,%helphash);
11336: my %defaultchecked = ('submitbugs' => 'on');
11337: my @offon = ('off','on');
1.118 jms 11338: my @toggles = ('submitbugs');
1.160.6.77 raeburn 11339: my %current = ('submitbugs' => '',
11340: 'adhoc' => {},
11341: );
1.118 jms 11342: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 11343: %current = %{$domconfig{'helpsettings'}};
11344: }
1.160.6.77 raeburn 11345: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 11346: foreach my $item (@toggles) {
11347: if ($defaultchecked{$item} eq 'on') {
11348: if ($current{$item} eq '') {
11349: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 11350: $changes{$item} = 1;
11351: }
1.160.6.73 raeburn 11352: } elsif ($current{$item} ne $env{'form.'.$item}) {
11353: $changes{$item} = 1;
11354: }
11355: } elsif ($defaultchecked{$item} eq 'off') {
11356: if ($current{$item} eq '') {
11357: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 11358: $changes{$item} = 1;
11359: }
1.160.6.73 raeburn 11360: } elsif ($current{$item} ne $env{'form.'.$item}) {
11361: $changes{$item} = 1;
11362: }
11363: }
11364: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
11365: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
11366: }
11367: }
1.160.6.77 raeburn 11368: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 11369: my $confname = $dom.'-domainconfig';
11370: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 11371: my (@allpos,%newsettings,%changedprivs,$newrole);
11372: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 11373: my @accesstypes = ('all','dh','da','none','status','inc','exc');
11374: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 11375: my %lt = &Apache::lonlocal::texthash(
11376: s => 'system',
11377: d => 'domain',
11378: order => 'Display order',
11379: access => 'Role usage',
1.160.6.79 raeburn 11380: all => 'All with domain helpdesk or helpdesk assistant role',
11381: dh => 'All with domain helpdesk role',
11382: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 11383: none => 'None',
11384: status => 'Determined based on institutional status',
11385: inc => 'Include all, but exclude specific personnel',
11386: exc => 'Exclude all, but include specific personnel',
11387: );
11388: for (my $num=0; $num<=$maxnum; $num++) {
11389: my ($prefix,$identifier,$rolename,%curr);
11390: if ($num == $maxnum) {
11391: next unless ($env{'form.newcusthelp'} == $maxnum);
11392: $identifier = 'custhelp'.$num;
11393: $prefix = 'helproles_'.$num;
11394: $rolename = $env{'form.custhelpname'.$num};
11395: $rolename=~s/[^A-Za-z0-9]//gs;
11396: next if ($rolename eq '');
11397: next if (exists($existing{'rolesdef_'.$rolename}));
11398: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11399: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11400: $newprivs{'c'},$confname,$dom);
11401: if ($result ne 'ok') {
11402: $errors .= '<li><span class="LC_error">'.
11403: &mt('An error occurred storing the new custom role: [_1]',
11404: $result).'</span></li>';
11405: next;
11406: } else {
11407: $changedprivs{$rolename} = \%newprivs;
11408: $newrole = $rolename;
11409: }
11410: } else {
11411: $prefix = 'helproles_'.$num;
11412: $rolename = $env{'form.'.$prefix};
11413: next if ($rolename eq '');
11414: next unless (exists($existing{'rolesdef_'.$rolename}));
11415: $identifier = 'custhelp'.$num;
11416: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
11417: my %currprivs;
11418: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
11419: split(/\_/,$existing{'rolesdef_'.$rolename});
11420: foreach my $level ('c','d','s') {
11421: if ($newprivs{$level} ne $currprivs{$level}) {
11422: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
11423: $newprivs{'c'},$confname,$dom);
11424: if ($result ne 'ok') {
11425: $errors .= '<li><span class="LC_error">'.
11426: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
11427: $rolename,$result).'</span></li>';
11428: } else {
11429: $changedprivs{$rolename} = \%newprivs;
11430: }
11431: last;
11432: }
11433: }
11434: if (ref($current{'adhoc'}) eq 'HASH') {
11435: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11436: %curr = %{$current{'adhoc'}{$rolename}};
11437: }
11438: }
11439: }
11440: my $newpos = $env{'form.'.$prefix.'_pos'};
11441: $newpos =~ s/\D+//g;
11442: $allpos[$newpos] = $rolename;
11443: my $newdesc = $env{'form.'.$prefix.'_desc'};
11444: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
11445: if ($curr{'desc'}) {
11446: if ($curr{'desc'} ne $newdesc) {
11447: $changes{'customrole'}{$rolename}{'desc'} = 1;
11448: $newsettings{$rolename}{'desc'} = $newdesc;
11449: }
11450: } elsif ($newdesc ne '') {
11451: $changes{'customrole'}{$rolename}{'desc'} = 1;
11452: $newsettings{$rolename}{'desc'} = $newdesc;
11453: }
11454: my $access = $env{'form.'.$prefix.'_access'};
11455: if (grep(/^\Q$access\E$/,@accesstypes)) {
11456: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
11457: if ($access eq 'status') {
11458: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
11459: if (scalar(@statuses) == 0) {
11460: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
11461: } else {
11462: my (@shownstatus,$numtypes);
11463: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11464: if (ref($types) eq 'ARRAY') {
11465: $numtypes = scalar(@{$types});
11466: foreach my $type (sort(@statuses)) {
11467: if ($type eq 'default') {
11468: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11469: } elsif (grep(/^\Q$type\E$/,@{$types})) {
11470: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
11471: push(@shownstatus,$usertypes->{$type});
11472: }
1.160.6.73 raeburn 11473: }
11474: }
1.160.6.77 raeburn 11475: if (grep(/^default$/,@statuses)) {
11476: push(@shownstatus,$othertitle);
11477: }
11478: if (scalar(@shownstatus) == 1+$numtypes) {
11479: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
11480: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
11481: } else {
11482: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
11483: if (ref($curr{'status'}) eq 'ARRAY') {
11484: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11485: if (@diffs) {
11486: $changes{'customrole'}{$rolename}{$access} = 1;
11487: }
11488: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11489: $changes{'customrole'}{$rolename}{$access} = 1;
11490: }
11491: }
11492: }
11493: } elsif (($access eq 'inc') || ($access eq 'exc')) {
11494: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
11495: my @newspecstaff;
11496: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
11497: foreach my $person (sort(@personnel)) {
11498: if ($domhelpdesk{$person}) {
11499: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
11500: }
11501: }
11502: if (ref($curr{$access}) eq 'ARRAY') {
11503: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
11504: if (@diffs) {
11505: $changes{'customrole'}{$rolename}{$access} = 1;
11506: }
11507: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11508: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 11509: }
1.160.6.77 raeburn 11510: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
11511: my ($uname,$udom) = split(/:/,$person);
11512: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
11513: }
11514: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 11515: }
1.160.6.77 raeburn 11516: } else {
11517: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
11518: }
11519: unless ($curr{'access'} eq $access) {
11520: $changes{'customrole'}{$rolename}{'access'} = 1;
11521: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 11522: }
11523: }
1.160.6.77 raeburn 11524: if (@allpos > 0) {
11525: my $idx = 0;
11526: foreach my $rolename (@allpos) {
11527: if ($rolename ne '') {
11528: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
11529: if (ref($current{'adhoc'}) eq 'HASH') {
11530: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
11531: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
11532: $changes{'customrole'}{$rolename}{'order'} = 1;
11533: $newsettings{$rolename}{'order'} = $idx+1;
11534: }
11535: }
1.160.6.73 raeburn 11536: }
1.160.6.77 raeburn 11537: $idx ++;
1.122 jms 11538: }
11539: }
1.118 jms 11540: }
1.123 jms 11541: my $putresult;
11542: if (keys(%changes) > 0) {
1.160.6.5 raeburn 11543: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
11544: if ($putresult eq 'ok') {
1.160.6.77 raeburn 11545: if (ref($helphash{'helpsettings'}) eq 'HASH') {
11546: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
11547: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
11548: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
11549: }
11550: }
11551: my $cachetime = 24*60*60;
11552: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
11553: if (ref($lastactref) eq 'HASH') {
11554: $lastactref->{'domdefaults'} = 1;
11555: }
11556: } else {
11557: $errors .= '<li><span class="LC_error">'.
11558: &mt('An error occurred storing the settings: [_1]',
11559: $putresult).'</span></li>';
11560: }
11561: }
11562: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
11563: $resulttext = &mt('Changes made:').'<ul>';
11564: my (%shownprivs,@levelorder);
11565: @levelorder = ('c','d','s');
11566: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 11567: foreach my $item (sort(keys(%changes))) {
11568: if ($item eq 'submitbugs') {
11569: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
11570: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
11571: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 11572: } elsif ($item eq 'customrole') {
11573: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 11574: my @keyorder = ('order','desc','access','status','exc','inc');
11575: my %keytext = &Apache::lonlocal::texthash(
11576: order => 'Order',
11577: desc => 'Role description',
11578: access => 'Role usage',
1.160.6.83 raeburn 11579: status => 'Allowed institutional types',
1.160.6.77 raeburn 11580: exc => 'Allowed personnel',
11581: inc => 'Disallowed personnel',
11582: );
1.160.6.73 raeburn 11583: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 11584: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
11585: if ($role eq $newrole) {
11586: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
11587: $role).'<ul>';
11588: } else {
11589: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11590: $role).'<ul>';
11591: }
11592: foreach my $key (@keyorder) {
11593: if ($changes{'customrole'}{$role}{$key}) {
11594: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
11595: $keytext{$key},$newsettings{$role}{$key}).
11596: '</li>';
11597: }
11598: }
11599: if (ref($changedprivs{$role}) eq 'HASH') {
11600: $shownprivs{$role} = 1;
11601: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
11602: foreach my $level (@levelorder) {
11603: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11604: next if ($item eq '');
11605: my ($priv) = split(/\&/,$item,2);
11606: if (&Apache::lonnet::plaintext($priv)) {
11607: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11608: unless ($level eq 'c') {
11609: $resulttext .= ' ('.$lt{$level}.')';
11610: }
11611: $resulttext .= '</li>';
11612: }
11613: }
11614: }
11615: $resulttext .= '</ul>';
11616: }
11617: $resulttext .= '</ul></li>';
11618: }
1.160.6.73 raeburn 11619: }
11620: }
1.160.6.5 raeburn 11621: }
11622: }
11623: }
1.160.6.77 raeburn 11624: if (keys(%changedprivs)) {
11625: foreach my $role (sort(keys(%changedprivs))) {
11626: unless ($shownprivs{$role}) {
11627: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
11628: $role).'<ul>'.
11629: '<li>'.&mt('Privileges set to :').'<ul>';
11630: foreach my $level (@levelorder) {
11631: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
11632: next if ($item eq '');
11633: my ($priv) = split(/\&/,$item,2);
11634: if (&Apache::lonnet::plaintext($priv)) {
11635: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
11636: unless ($level eq 'c') {
11637: $resulttext .= ' ('.$lt{$level}.')';
11638: }
11639: $resulttext .= '</li>';
11640: }
11641: }
11642: }
11643: $resulttext .= '</ul></li></ul></li>';
11644: }
11645: }
11646: }
11647: $resulttext .= '</ul>';
11648: } else {
11649: $resulttext = &mt('No changes made to help settings');
1.118 jms 11650: }
11651: if ($errors) {
1.160.6.5 raeburn 11652: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 11653: $errors.'</ul>';
1.118 jms 11654: }
11655: return $resulttext;
11656: }
11657:
1.121 raeburn 11658: sub modify_coursedefaults {
1.160.6.27 raeburn 11659: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 11660: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 11661: my %defaultchecked = (
11662: 'uselcmath' => 'on',
11663: 'usejsme' => 'on'
11664: );
11665: my @toggles = ('uselcmath','usejsme');
1.160.6.21 raeburn 11666: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 11667: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
11668: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 11669: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 11670: my %staticdefaults = (
11671: anonsurvey_threshold => 10,
11672: uploadquota => 500,
1.160.6.57 raeburn 11673: postsubmit => 60,
1.160.6.70 raeburn 11674: mysqltables => 172800,
1.160.6.21 raeburn 11675: );
1.121 raeburn 11676:
11677: $defaultshash{'coursedefaults'} = {};
11678:
11679: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
11680: if ($domconfig{'coursedefaults'} eq '') {
11681: $domconfig{'coursedefaults'} = {};
11682: }
11683: }
11684:
11685: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
11686: foreach my $item (@toggles) {
11687: if ($defaultchecked{$item} eq 'on') {
11688: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11689: ($env{'form.'.$item} eq '0')) {
11690: $changes{$item} = 1;
1.160.6.16 raeburn 11691: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 11692: $changes{$item} = 1;
11693: }
11694: } elsif ($defaultchecked{$item} eq 'off') {
11695: if (($domconfig{'coursedefaults'}{$item} eq '') &&
11696: ($env{'form.'.$item} eq '1')) {
11697: $changes{$item} = 1;
11698: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
11699: $changes{$item} = 1;
11700: }
11701: }
11702: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
11703: }
1.160.6.21 raeburn 11704: foreach my $item (@numbers) {
11705: my ($currdef,$newdef);
1.160.6.26 raeburn 11706: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 11707: if ($item eq 'anonsurvey_threshold') {
11708: $currdef = $domconfig{'coursedefaults'}{$item};
11709: $newdef =~ s/\D//g;
11710: if ($newdef eq '' || $newdef < 1) {
11711: $newdef = 1;
11712: }
11713: $defaultshash{'coursedefaults'}{$item} = $newdef;
11714: } else {
1.160.6.70 raeburn 11715: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
11716: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
11717: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 11718: }
11719: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 11720: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 11721: }
11722: if ($currdef ne $newdef) {
11723: my $staticdef;
11724: if ($item eq 'anonsurvey_threshold') {
11725: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
11726: $changes{$item} = 1;
11727: }
1.160.6.70 raeburn 11728: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
11729: my $setting = $1;
11730: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
11731: $changes{$setting} = 1;
1.160.6.21 raeburn 11732: }
11733: }
1.139 raeburn 11734: }
11735: }
1.160.6.64 raeburn 11736: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
11737: my @currclonecode;
11738: if (ref($currclone) eq 'HASH') {
11739: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
11740: @currclonecode = @{$currclone->{'instcode'}};
11741: }
11742: }
11743: my $newclone;
11744: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
11745: $newclone = $env{'form.canclone'};
11746: }
11747: if ($newclone eq 'instcode') {
11748: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
11749: my (%codedefaults,@code_order,@clonecode);
11750: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
11751: \@code_order);
11752: foreach my $item (@code_order) {
11753: if (grep(/^\Q$item\E$/,@newcodes)) {
11754: push(@clonecode,$item);
11755: }
11756: }
11757: if (@clonecode) {
11758: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
11759: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
11760: if (@diffs) {
11761: $changes{'canclone'} = 1;
11762: }
11763: } else {
11764: $newclone eq '';
11765: }
11766: } elsif ($newclone ne '') {
11767: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
11768: }
11769: if ($newclone ne $currclone) {
11770: $changes{'canclone'} = 1;
11771: }
1.160.6.57 raeburn 11772: my %credits;
11773: foreach my $type (@types) {
11774: unless ($type eq 'community') {
11775: $credits{$type} = $env{'form.'.$type.'_credits'};
11776: $credits{$type} =~ s/[^\d.]+//g;
11777: }
11778: }
11779: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
11780: ($env{'form.coursecredits'} eq '1')) {
11781: $changes{'coursecredits'} = 1;
11782: foreach my $type (keys(%credits)) {
11783: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11784: }
11785: } else {
11786: if ($env{'form.coursecredits'} eq '1') {
11787: foreach my $type (@types) {
11788: unless ($type eq 'community') {
11789: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
11790: $changes{'coursecredits'} = 1;
11791: }
11792: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
11793: }
11794: }
11795: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11796: foreach my $type (@types) {
11797: unless ($type eq 'community') {
11798: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
11799: $changes{'coursecredits'} = 1;
11800: last;
11801: }
11802: }
11803: }
11804: }
11805: }
11806: if ($env{'form.postsubmit'} eq '1') {
11807: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
11808: my %currtimeout;
11809: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11810: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
11811: $changes{'postsubmit'} = 1;
11812: }
11813: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11814: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
11815: }
11816: } else {
11817: $changes{'postsubmit'} = 1;
11818: }
11819: foreach my $type (@types) {
11820: my $timeout = $env{'form.'.$type.'_timeout'};
11821: $timeout =~ s/\D//g;
11822: if ($timeout == $staticdefaults{'postsubmit'}) {
11823: $timeout = '';
11824: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
11825: $timeout = '0';
11826: }
11827: unless ($timeout eq '') {
11828: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
11829: }
11830: if (exists($currtimeout{$type})) {
11831: if ($timeout ne $currtimeout{$type}) {
11832: $changes{'postsubmit'} = 1;
11833: }
11834: } elsif ($timeout ne '') {
11835: $changes{'postsubmit'} = 1;
11836: }
11837: }
11838: } else {
11839: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
11840: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11841: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
11842: $changes{'postsubmit'} = 1;
11843: }
11844: } else {
11845: $changes{'postsubmit'} = 1;
11846: }
1.160.6.16 raeburn 11847: }
1.121 raeburn 11848: }
11849: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11850: $dom);
11851: if ($putresult eq 'ok') {
11852: if (keys(%changes) > 0) {
1.160.6.27 raeburn 11853: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 11854: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 11855: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70 raeburn 11856: ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57 raeburn 11857: foreach my $item ('uselcmath','usejsme') {
11858: if ($changes{$item}) {
11859: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
11860: }
1.160.6.16 raeburn 11861: }
11862: if ($changes{'coursecredits'}) {
11863: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 11864: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
11865: $domdefaults{$type.'credits'} =
11866: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
11867: }
11868: }
11869: }
11870: if ($changes{'postsubmit'}) {
11871: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11872: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
11873: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11874: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
11875: $domdefaults{$type.'postsubtimeout'} =
11876: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11877: }
11878: }
1.160.6.16 raeburn 11879: }
11880: }
1.160.6.21 raeburn 11881: if ($changes{'uploadquota'}) {
11882: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11883: foreach my $type (@types) {
11884: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
11885: }
11886: }
11887: }
1.160.6.64 raeburn 11888: if ($changes{'canclone'}) {
11889: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
11890: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
11891: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
11892: if (@clonecodes) {
11893: $domdefaults{'canclone'} = join('+',@clonecodes);
11894: }
11895: }
11896: } else {
11897: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
11898: }
11899: }
1.121 raeburn 11900: my $cachetime = 24*60*60;
11901: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 11902: if (ref($lastactref) eq 'HASH') {
11903: $lastactref->{'domdefaults'} = 1;
11904: }
1.121 raeburn 11905: }
11906: $resulttext = &mt('Changes made:').'<ul>';
11907: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 11908: if ($item eq 'uselcmath') {
1.121 raeburn 11909: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 11910: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 11911: } else {
1.160.6.57 raeburn 11912: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
11913: }
11914: } elsif ($item eq 'usejsme') {
11915: if ($env{'form.'.$item} eq '1') {
11916: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
11917: } else {
11918: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 11919: }
1.139 raeburn 11920: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 11921: $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 11922: } elsif ($item eq 'uploadquota') {
11923: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
11924: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
11925: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
11926: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 11927: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
11928:
1.160.6.21 raeburn 11929: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
11930: '</ul>'.
11931: '</li>';
11932: } else {
11933: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
11934: }
1.160.6.70 raeburn 11935: } elsif ($item eq 'mysqltables') {
11936: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
11937: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
11938: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
11939: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
11940: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
11941: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
11942: '</ul>'.
11943: '</li>';
11944: } else {
11945: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
11946: }
1.160.6.57 raeburn 11947: } elsif ($item eq 'postsubmit') {
11948: if ($domdefaults{'postsubmit'} eq 'off') {
11949: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
11950: } else {
11951: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
11952: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
11953: $resulttext .= &mt('durations:').'<ul>';
11954: foreach my $type (@types) {
11955: $resulttext .= '<li>';
11956: my $timeout;
11957: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
11958: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
11959: }
11960: my $display;
11961: if ($timeout eq '0') {
11962: $display = &mt('unlimited');
11963: } elsif ($timeout eq '') {
11964: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
11965: } else {
11966: $display = &mt('[quant,_1,second]',$timeout);
11967: }
11968: if ($type eq 'community') {
11969: $resulttext .= &mt('Communities');
11970: } elsif ($type eq 'official') {
11971: $resulttext .= &mt('Official courses');
11972: } elsif ($type eq 'unofficial') {
11973: $resulttext .= &mt('Unofficial courses');
11974: } elsif ($type eq 'textbook') {
11975: $resulttext .= &mt('Textbook courses');
11976: }
11977: $resulttext .= ' -- '.$display.'</li>';
11978: }
11979: $resulttext .= '</ul>';
11980: }
11981: $resulttext .= '</li>';
11982: }
1.160.6.16 raeburn 11983: } elsif ($item eq 'coursecredits') {
11984: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
11985: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 11986: ($domdefaults{'unofficialcredits'} eq '') &&
11987: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 11988: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11989: } else {
11990: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
11991: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
11992: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 11993: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 11994: '</ul>'.
11995: '</li>';
11996: }
11997: } else {
11998: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
11999: }
1.160.6.64 raeburn 12000: } elsif ($item eq 'canclone') {
12001: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
12002: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
12003: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
12004: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
12005: }
12006: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
12007: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
12008: } else {
12009: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
12010: }
1.140 raeburn 12011: }
1.121 raeburn 12012: }
12013: $resulttext .= '</ul>';
12014: } else {
12015: $resulttext = &mt('No changes made to course defaults');
12016: }
12017: } else {
12018: $resulttext = '<span class="LC_error">'.
12019: &mt('An error occurred: [_1]',$putresult).'</span>';
12020: }
12021: return $resulttext;
12022: }
12023:
1.160.6.37 raeburn 12024: sub modify_selfenrollment {
12025: my ($dom,$lastactref,%domconfig) = @_;
12026: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
12027: my @types = ('official','unofficial','community','textbook');
12028: my %titles = &tool_titles();
12029: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
12030: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
12031: $ordered{'default'} = ['types','registered','approval','limit'];
12032:
12033: my (%roles,%shown,%toplevel);
12034: $roles{'0'} = &Apache::lonnet::plaintext('dc');
12035:
12036: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
12037: if ($domconfig{'selfenrollment'} eq '') {
12038: $domconfig{'selfenrollment'} = {};
12039: }
12040: }
12041: %toplevel = (
12042: admin => 'Configuration Rights',
12043: default => 'Default settings',
12044: validation => 'Validation of self-enrollment requests',
12045: );
12046: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
12047:
12048: if (ref($ordered{'admin'}) eq 'ARRAY') {
12049: foreach my $item (@{$ordered{'admin'}}) {
12050: foreach my $type (@types) {
12051: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
12052: $selfenrollhash{'admin'}{$type}{$item} = 1;
12053: } else {
12054: $selfenrollhash{'admin'}{$type}{$item} = 0;
12055: }
12056: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
12057: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
12058: if ($selfenrollhash{'admin'}{$type}{$item} ne
12059: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
12060: push(@{$changes{'admin'}{$type}},$item);
12061: }
12062: } else {
12063: if (!$selfenrollhash{'admin'}{$type}{$item}) {
12064: push(@{$changes{'admin'}{$type}},$item);
12065: }
12066: }
12067: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
12068: push(@{$changes{'admin'}{$type}},$item);
12069: }
12070: }
12071: }
12072: }
12073:
12074: foreach my $item (@{$ordered{'default'}}) {
12075: foreach my $type (@types) {
12076: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
12077: if ($item eq 'types') {
12078: unless (($value eq 'all') || ($value eq 'dom')) {
12079: $value = '';
12080: }
12081: } elsif ($item eq 'registered') {
12082: unless ($value eq '1') {
12083: $value = 0;
12084: }
12085: } elsif ($item eq 'approval') {
12086: unless ($value =~ /^[012]$/) {
12087: $value = 0;
12088: }
12089: } else {
12090: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12091: $value = 'none';
12092: }
12093: }
12094: $selfenrollhash{'default'}{$type}{$item} = $value;
12095: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
12096: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12097: if ($selfenrollhash{'default'}{$type}{$item} ne
12098: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
12099: push(@{$changes{'default'}{$type}},$item);
12100: }
12101: } else {
12102: push(@{$changes{'default'}{$type}},$item);
12103: }
12104: } else {
12105: push(@{$changes{'default'}{$type}},$item);
12106: }
12107: if ($item eq 'limit') {
12108: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
12109: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
12110: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
12111: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
12112: }
12113: } else {
12114: $selfenrollhash{'default'}{$type}{'cap'} = '';
12115: }
12116: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
12117: if ($selfenrollhash{'default'}{$type}{'cap'} ne
12118: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
12119: push(@{$changes{'default'}{$type}},'cap');
12120: }
12121: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
12122: push(@{$changes{'default'}{$type}},'cap');
12123: }
12124: }
12125: }
12126: }
12127:
12128: foreach my $item (@{$itemsref}) {
12129: if ($item eq 'fields') {
12130: my @changed;
12131: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
12132: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
12133: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
12134: }
12135: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12136: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
12137: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
12138: $domconfig{'selfenrollment'}{'validation'}{$item});
12139: } else {
12140: @changed = @{$selfenrollhash{'validation'}{$item}};
12141: }
12142: } else {
12143: @changed = @{$selfenrollhash{'validation'}{$item}};
12144: }
12145: if (@changed) {
12146: if ($selfenrollhash{'validation'}{$item}) {
12147: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
12148: } else {
12149: $changes{'validation'}{$item} = &mt('None');
12150: }
12151: }
12152: } else {
12153: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
12154: if ($item eq 'markup') {
12155: if ($env{'form.selfenroll_validation_'.$item}) {
12156: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12157: }
12158: }
12159: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
12160: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
12161: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
12162: }
12163: }
12164: }
12165: }
12166:
12167: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
12168: $dom);
12169: if ($putresult eq 'ok') {
12170: if (keys(%changes) > 0) {
12171: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12172: $resulttext = &mt('Changes made:').'<ul>';
12173: foreach my $key ('admin','default','validation') {
12174: if (ref($changes{$key}) eq 'HASH') {
12175: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
12176: if ($key eq 'validation') {
12177: foreach my $item (@{$itemsref}) {
12178: if (exists($changes{$key}{$item})) {
12179: if ($item eq 'markup') {
12180: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12181: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
12182: } else {
12183: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
12184: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
12185: }
12186: }
12187: }
12188: } else {
12189: foreach my $type (@types) {
12190: if ($type eq 'community') {
12191: $roles{'1'} = &mt('Community personnel');
12192: } else {
12193: $roles{'1'} = &mt('Course personnel');
12194: }
12195: if (ref($changes{$key}{$type}) eq 'ARRAY') {
12196: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12197: if ($key eq 'admin') {
12198: my @mgrdc = ();
12199: if (ref($ordered{$key}) eq 'ARRAY') {
12200: foreach my $item (@{$ordered{'admin'}}) {
12201: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
12202: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
12203: push(@mgrdc,$item);
12204: }
12205: }
12206: }
12207: if (@mgrdc) {
12208: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
12209: } else {
12210: delete($domdefaults{$type.'selfenrolladmdc'});
12211: }
12212: }
12213: } else {
12214: if (ref($ordered{$key}) eq 'ARRAY') {
12215: foreach my $item (@{$ordered{$key}}) {
12216: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12217: $domdefaults{$type.'selfenroll'.$item} =
12218: $selfenrollhash{$key}{$type}{$item};
12219: }
12220: }
12221: }
12222: }
12223: }
12224: $resulttext .= '<li>'.$titles{$type}.'<ul>';
12225: foreach my $item (@{$ordered{$key}}) {
12226: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
12227: $resulttext .= '<li>';
12228: if ($key eq 'admin') {
12229: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
12230: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
12231: } else {
12232: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
12233: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
12234: }
12235: $resulttext .= '</li>';
12236: }
12237: }
12238: $resulttext .= '</ul></li>';
12239: }
12240: }
12241: $resulttext .= '</ul></li>';
12242: }
12243: }
12244: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
12245: my $cachetime = 24*60*60;
12246: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12247: if (ref($lastactref) eq 'HASH') {
12248: $lastactref->{'domdefaults'} = 1;
12249: }
12250: }
12251: }
12252: $resulttext .= '</ul>';
12253: } else {
12254: $resulttext = &mt('No changes made to self-enrollment settings');
12255: }
12256: } else {
12257: $resulttext = '<span class="LC_error">'.
12258: &mt('An error occurred: [_1]',$putresult).'</span>';
12259: }
12260: return $resulttext;
12261: }
12262:
1.137 raeburn 12263: sub modify_usersessions {
1.160.6.27 raeburn 12264: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 12265: my @hostingtypes = ('version','excludedomain','includedomain');
12266: my @offloadtypes = ('primary','default');
12267: my %types = (
12268: remote => \@hostingtypes,
12269: hosted => \@hostingtypes,
12270: spares => \@offloadtypes,
12271: );
12272: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 12273: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 12274: my (%by_ip,%by_location,@intdoms);
12275: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
12276: my @locations = sort(keys(%by_location));
1.137 raeburn 12277: my (%defaultshash,%changes);
12278: foreach my $prefix (@prefixes) {
12279: $defaultshash{'usersessions'}{$prefix} = {};
12280: }
1.160.6.27 raeburn 12281: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 12282: my $resulttext;
1.138 raeburn 12283: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 12284: foreach my $prefix (@prefixes) {
1.145 raeburn 12285: next if ($prefix eq 'spares');
12286: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 12287: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
12288: if ($type eq 'version') {
12289: my $value = $env{'form.'.$prefix.'_'.$type};
12290: my $okvalue;
12291: if ($value ne '') {
12292: if (grep(/^\Q$value\E$/,@lcversions)) {
12293: $okvalue = $value;
12294: }
12295: }
12296: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12297: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12298: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
12299: if ($inuse == 0) {
12300: $changes{$prefix}{$type} = 1;
12301: } else {
12302: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
12303: $changes{$prefix}{$type} = 1;
12304: }
12305: if ($okvalue ne '') {
12306: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12307: }
12308: }
12309: } else {
12310: if (($inuse == 1) && ($okvalue ne '')) {
12311: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12312: $changes{$prefix}{$type} = 1;
12313: }
12314: }
12315: } else {
12316: if (($inuse == 1) && ($okvalue ne '')) {
12317: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12318: $changes{$prefix}{$type} = 1;
12319: }
12320: }
12321: } else {
12322: if (($inuse == 1) && ($okvalue ne '')) {
12323: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
12324: $changes{$prefix}{$type} = 1;
12325: }
12326: }
12327: } else {
12328: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
12329: my @okvals;
12330: foreach my $val (@vals) {
1.138 raeburn 12331: if ($val =~ /:/) {
12332: my @items = split(/:/,$val);
12333: foreach my $item (@items) {
12334: if (ref($by_location{$item}) eq 'ARRAY') {
12335: push(@okvals,$item);
12336: }
12337: }
12338: } else {
12339: if (ref($by_location{$val}) eq 'ARRAY') {
12340: push(@okvals,$val);
12341: }
1.137 raeburn 12342: }
12343: }
12344: @okvals = sort(@okvals);
12345: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12346: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
12347: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12348: if ($inuse == 0) {
12349: $changes{$prefix}{$type} = 1;
12350: } else {
12351: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12352: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
12353: if (@changed > 0) {
12354: $changes{$prefix}{$type} = 1;
12355: }
12356: }
12357: } else {
12358: if ($inuse == 1) {
12359: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12360: $changes{$prefix}{$type} = 1;
12361: }
12362: }
12363: } else {
12364: if ($inuse == 1) {
12365: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12366: $changes{$prefix}{$type} = 1;
12367: }
12368: }
12369: } else {
12370: if ($inuse == 1) {
12371: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
12372: $changes{$prefix}{$type} = 1;
12373: }
12374: }
12375: }
12376: }
12377: }
1.145 raeburn 12378:
12379: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 12380: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 12381: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
12382: my $savespares;
12383:
12384: foreach my $lonhost (sort(keys(%servers))) {
12385: my $serverhomeID =
12386: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 12387: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 12388: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
12389: my %spareschg;
12390: foreach my $type (@{$types{'spares'}}) {
12391: my @okspares;
12392: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
12393: foreach my $server (@checked) {
1.152 raeburn 12394: if (&Apache::lonnet::hostname($server) ne '') {
12395: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
12396: unless (grep(/^\Q$server\E$/,@okspares)) {
12397: push(@okspares,$server);
12398: }
1.145 raeburn 12399: }
12400: }
12401: }
12402: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
12403: my $newspare;
1.152 raeburn 12404: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
12405: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 12406: $newspare = $new;
12407: }
12408: }
1.152 raeburn 12409: my @spares;
12410: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
12411: @spares = sort(@okspares,$newspare);
12412: } else {
12413: @spares = sort(@okspares);
12414: }
12415: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 12416: if (ref($spareid{$lonhost}) eq 'HASH') {
12417: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 12418: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 12419: if (@diffs > 0) {
12420: $spareschg{$type} = 1;
12421: }
12422: }
12423: }
12424: }
12425: if (keys(%spareschg) > 0) {
12426: $changes{'spares'}{$lonhost} = \%spareschg;
12427: }
12428: }
1.160.6.61 raeburn 12429: $defaultshash{'usersessions'}{'offloadnow'} = {};
12430: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
12431: my @okoffload;
12432: if (@offloadnow) {
12433: foreach my $server (@offloadnow) {
12434: if (&Apache::lonnet::hostname($server) ne '') {
12435: unless (grep(/^\Q$server\E$/,@okoffload)) {
12436: push(@okoffload,$server);
12437: }
12438: }
12439: }
12440: if (@okoffload) {
12441: foreach my $lonhost (@okoffload) {
12442: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
12443: }
12444: }
12445: }
1.145 raeburn 12446: if (ref($domconfig{'usersessions'}) eq 'HASH') {
12447: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
12448: if (ref($changes{'spares'}) eq 'HASH') {
12449: if (keys(%{$changes{'spares'}}) > 0) {
12450: $savespares = 1;
12451: }
12452: }
12453: } else {
12454: $savespares = 1;
12455: }
1.160.6.61 raeburn 12456: if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
12457: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
12458: unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
12459: $changes{'offloadnow'} = 1;
12460: last;
12461: }
12462: }
12463: unless ($changes{'offloadnow'}) {
12464: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
12465: unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
12466: $changes{'offloadnow'} = 1;
12467: last;
12468: }
12469: }
12470: }
12471: } elsif (@okoffload) {
12472: $changes{'offloadnow'} = 1;
12473: }
12474: } elsif (@okoffload) {
12475: $changes{'offloadnow'} = 1;
1.145 raeburn 12476: }
1.147 raeburn 12477: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
12478: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 12479: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12480: $dom);
12481: if ($putresult eq 'ok') {
12482: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12483: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
12484: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
12485: }
12486: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
12487: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
12488: }
1.160.6.61 raeburn 12489: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12490: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
12491: }
1.137 raeburn 12492: }
12493: my $cachetime = 24*60*60;
12494: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 12495: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 12496: if (ref($lastactref) eq 'HASH') {
12497: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 12498: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 12499: }
1.147 raeburn 12500: if (keys(%changes) > 0) {
12501: my %lt = &usersession_titles();
12502: $resulttext = &mt('Changes made:').'<ul>';
12503: foreach my $prefix (@prefixes) {
12504: if (ref($changes{$prefix}) eq 'HASH') {
12505: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
12506: if ($prefix eq 'spares') {
12507: if (ref($changes{$prefix}) eq 'HASH') {
12508: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
12509: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 12510: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 12511: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
12512: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 12513: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
12514: foreach my $type (@{$types{$prefix}}) {
12515: if ($changes{$prefix}{$lonhost}{$type}) {
12516: my $offloadto = &mt('None');
12517: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
12518: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
12519: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
12520: }
1.145 raeburn 12521: }
1.147 raeburn 12522: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 12523: }
1.137 raeburn 12524: }
12525: }
1.147 raeburn 12526: $resulttext .= '</li>';
1.137 raeburn 12527: }
12528: }
1.147 raeburn 12529: } else {
12530: foreach my $type (@{$types{$prefix}}) {
12531: if (defined($changes{$prefix}{$type})) {
12532: my $newvalue;
12533: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
12534: if (ref($defaultshash{'usersessions'}{$prefix})) {
12535: if ($type eq 'version') {
12536: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
12537: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
12538: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
12539: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
12540: }
1.145 raeburn 12541: }
12542: }
12543: }
1.147 raeburn 12544: if ($newvalue eq '') {
12545: if ($type eq 'version') {
12546: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
12547: } else {
12548: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
12549: }
1.145 raeburn 12550: } else {
1.147 raeburn 12551: if ($type eq 'version') {
12552: $newvalue .= ' '.&mt('(or later)');
12553: }
12554: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 12555: }
1.137 raeburn 12556: }
12557: }
12558: }
1.147 raeburn 12559: $resulttext .= '</ul>';
1.137 raeburn 12560: }
12561: }
1.160.6.61 raeburn 12562: if ($changes{'offloadnow'}) {
12563: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
12564: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
12565: $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
12566: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
12567: $resulttext .= '<li>'.$lonhost.'</li>';
12568: }
12569: $resulttext .= '</ul>';
12570: } else {
12571: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
12572: }
12573: } else {
12574: $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
12575: }
12576: }
1.147 raeburn 12577: $resulttext .= '</ul>';
12578: } else {
12579: $resulttext = $nochgmsg;
1.137 raeburn 12580: }
12581: } else {
12582: $resulttext = '<span class="LC_error">'.
12583: &mt('An error occurred: [_1]',$putresult).'</span>';
12584: }
12585: } else {
1.147 raeburn 12586: $resulttext = $nochgmsg;
1.137 raeburn 12587: }
12588: return $resulttext;
12589: }
12590:
1.150 raeburn 12591: sub modify_loadbalancing {
12592: my ($dom,%domconfig) = @_;
12593: my $primary_id = &Apache::lonnet::domain($dom,'primary');
12594: my $intdom = &Apache::lonnet::internet_dom($primary_id);
12595: my ($othertitle,$usertypes,$types) =
12596: &Apache::loncommon::sorted_inst_types($dom);
12597: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 12598: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 12599: my @sparestypes = ('primary','default');
12600: my %typetitles = &sparestype_titles();
12601: my $resulttext;
1.160.6.7 raeburn 12602: my (%currbalancer,%currtargets,%currrules,%existing);
12603: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12604: %existing = %{$domconfig{'loadbalancing'}};
12605: }
12606: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
12607: \%currtargets,\%currrules);
12608: my ($saveloadbalancing,%defaultshash,%changes);
12609: my ($alltypes,$othertypes,$titles) =
12610: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
12611: my %ruletitles = &offloadtype_text();
12612: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
12613: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
12614: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
12615: if ($balancer eq '') {
12616: next;
12617: }
12618: if (!exists($servers{$balancer})) {
12619: if (exists($currbalancer{$balancer})) {
12620: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 12621: }
1.160.6.7 raeburn 12622: next;
12623: }
12624: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
12625: push(@{$changes{'delete'}},$balancer);
12626: next;
12627: }
12628: if (!exists($currbalancer{$balancer})) {
12629: push(@{$changes{'add'}},$balancer);
12630: }
12631: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
12632: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
12633: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
12634: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
12635: $saveloadbalancing = 1;
12636: }
12637: foreach my $sparetype (@sparestypes) {
12638: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
12639: my @offloadto;
12640: foreach my $target (@targets) {
12641: if (($servers{$target}) && ($target ne $balancer)) {
12642: if ($sparetype eq 'default') {
12643: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
12644: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 12645: }
12646: }
1.160.6.7 raeburn 12647: unless(grep(/^\Q$target\E$/,@offloadto)) {
12648: push(@offloadto,$target);
12649: }
1.150 raeburn 12650: }
12651: }
1.160.6.76 raeburn 12652: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
12653: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
12654: push(@offloadto,$balancer);
12655: }
12656: }
12657: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 12658: }
1.160.6.7 raeburn 12659: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 12660: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 12661: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
12662: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 12663: if (@targetdiffs > 0) {
1.160.6.7 raeburn 12664: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12665: }
1.160.6.7 raeburn 12666: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12667: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12668: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 12669: }
12670: }
12671: }
12672: } else {
1.160.6.7 raeburn 12673: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
12674: foreach my $sparetype (@sparestypes) {
12675: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12676: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12677: $changes{'curr'}{$balancer}{'targets'} = 1;
12678: }
1.150 raeburn 12679: }
12680: }
1.160.6.7 raeburn 12681: }
1.150 raeburn 12682: }
12683: my $ishomedom;
1.160.6.7 raeburn 12684: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
12685: $ishomedom = 1;
1.150 raeburn 12686: }
12687: if (ref($alltypes) eq 'ARRAY') {
12688: foreach my $type (@{$alltypes}) {
12689: my $rule;
1.160.6.7 raeburn 12690: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 12691: (!$ishomedom)) {
1.160.6.7 raeburn 12692: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
12693: }
12694: if ($rule eq 'specific') {
1.160.6.55 raeburn 12695: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
12696: if (exists($servers{$specifiedhost})) {
12697: $rule = $specifiedhost;
12698: }
1.150 raeburn 12699: }
1.160.6.7 raeburn 12700: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
12701: if (ref($currrules{$balancer}) eq 'HASH') {
12702: if ($rule ne $currrules{$balancer}{$type}) {
12703: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12704: }
12705: } elsif ($rule ne '') {
1.160.6.7 raeburn 12706: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 12707: }
12708: }
12709: }
1.160.6.7 raeburn 12710: }
12711: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
12712: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
12713: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
12714: $defaultshash{'loadbalancing'} = {};
12715: }
12716: my $putresult = &Apache::lonnet::put_dom('configuration',
12717: \%defaultshash,$dom);
12718: if ($putresult eq 'ok') {
12719: if (keys(%changes) > 0) {
1.160.6.54 raeburn 12720: my %toupdate;
1.160.6.7 raeburn 12721: if (ref($changes{'delete'}) eq 'ARRAY') {
12722: foreach my $balancer (sort(@{$changes{'delete'}})) {
12723: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 12724: $toupdate{$balancer} = 1;
1.150 raeburn 12725: }
1.160.6.7 raeburn 12726: }
12727: if (ref($changes{'add'}) eq 'ARRAY') {
12728: foreach my $balancer (sort(@{$changes{'add'}})) {
12729: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 12730: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12731: }
12732: }
12733: if (ref($changes{'curr'}) eq 'HASH') {
12734: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 12735: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 12736: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
12737: if ($changes{'curr'}{$balancer}{'targets'}) {
12738: my %offloadstr;
12739: foreach my $sparetype (@sparestypes) {
12740: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12741: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
12742: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12743: }
12744: }
1.150 raeburn 12745: }
1.160.6.7 raeburn 12746: if (keys(%offloadstr) == 0) {
12747: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 12748: } else {
1.160.6.7 raeburn 12749: my $showoffload;
12750: foreach my $sparetype (@sparestypes) {
12751: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
12752: if (defined($offloadstr{$sparetype})) {
12753: $showoffload .= $offloadstr{$sparetype};
12754: } else {
12755: $showoffload .= &mt('None');
12756: }
12757: $showoffload .= (' 'x3);
12758: }
12759: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 12760: }
12761: }
12762: }
1.160.6.7 raeburn 12763: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
12764: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
12765: foreach my $type (@{$alltypes}) {
12766: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
12767: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12768: my $balancetext;
12769: if ($rule eq '') {
12770: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 12771: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 12772: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
12773: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 12774: foreach my $sparetype (@sparestypes) {
12775: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
12776: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
12777: }
12778: }
1.160.6.55 raeburn 12779: foreach my $item (@{$alltypes}) {
12780: next if ($item =~ /^_LC_ipchange/);
12781: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
12782: if ($hasrule eq 'homeserver') {
12783: map { $toupdate{$_} = 1; } (keys(%libraryservers));
12784: } else {
12785: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
12786: if ($servers{$hasrule}) {
12787: $toupdate{$hasrule} = 1;
12788: }
12789: }
12790: }
12791: }
12792: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
12793: $balancetext = $ruletitles{$rule};
12794: } else {
12795: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
12796: $balancetext = $ruletitles{'particular'}.' '.$receiver;
12797: if ($receiver) {
12798: $toupdate{$receiver};
12799: }
12800: }
12801: } else {
12802: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 12803: }
1.160.6.7 raeburn 12804: } else {
12805: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
12806: }
1.160.6.26 raeburn 12807: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 12808: }
12809: }
12810: }
12811: }
1.160.6.54 raeburn 12812: if (keys(%toupdate)) {
12813: my %thismachine;
12814: my $updatedhere;
12815: my $cachetime = 60*60*24;
12816: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
12817: foreach my $lonhost (keys(%toupdate)) {
12818: if ($thismachine{$lonhost}) {
12819: unless ($updatedhere) {
12820: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
12821: $defaultshash{'loadbalancing'},
12822: $cachetime);
12823: $updatedhere = 1;
12824: }
12825: } else {
12826: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
12827: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
12828: }
12829: }
12830: }
1.150 raeburn 12831: }
1.160.6.7 raeburn 12832: }
12833: if ($resulttext ne '') {
12834: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 12835: } else {
12836: $resulttext = $nochgmsg;
12837: }
12838: } else {
1.160.6.7 raeburn 12839: $resulttext = $nochgmsg;
1.150 raeburn 12840: }
12841: } else {
1.160.6.7 raeburn 12842: $resulttext = '<span class="LC_error">'.
12843: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 12844: }
12845: } else {
1.160.6.7 raeburn 12846: $resulttext = $nochgmsg;
1.150 raeburn 12847: }
12848: return $resulttext;
12849: }
12850:
1.48 raeburn 12851: sub recurse_check {
12852: my ($chkcats,$categories,$depth,$name) = @_;
12853: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
12854: my $chg = 0;
12855: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
12856: my $category = $chkcats->[$depth]{$name}[$j];
12857: my $item;
12858: if ($category eq '') {
12859: $chg ++;
12860: } else {
12861: my $deeper = $depth + 1;
12862: $item = &escape($category).':'.&escape($name).':'.$depth;
12863: if ($chg) {
12864: $categories->{$item} -= $chg;
12865: }
12866: &recurse_check($chkcats,$categories,$deeper,$category);
12867: $deeper --;
12868: }
12869: }
12870: }
12871: return;
12872: }
12873:
12874: sub recurse_cat_deletes {
12875: my ($item,$coursecategories,$deletions) = @_;
12876: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
12877: my $subdepth = $depth + 1;
12878: if (ref($coursecategories) eq 'HASH') {
12879: foreach my $subitem (keys(%{$coursecategories})) {
12880: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
12881: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
12882: delete($coursecategories->{$subitem});
12883: $deletions->{$subitem} = 1;
12884: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 12885: }
1.48 raeburn 12886: }
12887: }
12888: return;
12889: }
12890:
1.125 raeburn 12891: sub active_dc_picker {
1.160.6.16 raeburn 12892: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 12893: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 12894: my @domcoord = keys(%domcoords);
12895: if (keys(%currhash)) {
12896: foreach my $dc (keys(%currhash)) {
12897: unless (exists($domcoords{$dc})) {
12898: push(@domcoord,$dc);
12899: }
12900: }
12901: }
12902: @domcoord = sort(@domcoord);
12903: my $numdcs = scalar(@domcoord);
12904: my $rows = 0;
12905: my $table;
1.125 raeburn 12906: if ($numdcs > 1) {
1.160.6.16 raeburn 12907: $table = '<table>';
12908: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 12909: my $rem = $i%($numinrow);
12910: if ($rem == 0) {
12911: if ($i > 0) {
1.160.6.16 raeburn 12912: $table .= '</tr>';
1.125 raeburn 12913: }
1.160.6.16 raeburn 12914: $table .= '<tr>';
12915: $rows ++;
1.125 raeburn 12916: }
1.160.6.16 raeburn 12917: my $check = '';
12918: if ($inputtype eq 'radio') {
12919: if (keys(%currhash) == 0) {
12920: if (!$i) {
12921: $check = ' checked="checked"';
12922: }
12923: } elsif (exists($currhash{$domcoord[$i]})) {
12924: $check = ' checked="checked"';
12925: }
12926: } else {
12927: if (exists($currhash{$domcoord[$i]})) {
12928: $check = ' checked="checked"';
1.125 raeburn 12929: }
12930: }
1.160.6.16 raeburn 12931: if ($i == @domcoord - 1) {
1.125 raeburn 12932: my $colsleft = $numinrow - $rem;
12933: if ($colsleft > 1) {
1.160.6.16 raeburn 12934: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 12935: } else {
1.160.6.16 raeburn 12936: $table .= '<td class="LC_left_item">';
1.125 raeburn 12937: }
12938: } else {
1.160.6.16 raeburn 12939: $table .= '<td class="LC_left_item">';
12940: }
12941: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
12942: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
12943: $table .= '<span class="LC_nobreak"><label>'.
12944: '<input type="'.$inputtype.'" name="'.$name.'"'.
12945: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
12946: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 12947: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 12948: }
1.160.6.33 raeburn 12949: $table .= '</label></span></td>';
1.125 raeburn 12950: }
1.160.6.16 raeburn 12951: $table .= '</tr></table>';
12952: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 12953: my ($dcname,$dcdom) = split(':',$domcoord[0]);
12954: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 12955: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 12956: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 12957: if ($user ne $dcname.':'.$dcdom) {
12958: $table .= ' ('.$dcname.':'.$dcdom.')';
12959: }
1.160.6.16 raeburn 12960: } else {
12961: my $check;
12962: if (exists($currhash{$domcoord[0]})) {
12963: $check = ' checked="checked"';
12964: }
1.160.6.50 raeburn 12965: $table = '<span class="LC_nobreak"><label>'.
12966: '<input type="checkbox" name="'.$name.'" '.
12967: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 12968: if ($user ne $dcname.':'.$dcdom) {
12969: $table .= ' ('.$dcname.':'.$dcdom.')';
12970: }
12971: $table .= '</label></span>';
1.160.6.16 raeburn 12972: $rows ++;
12973: }
1.125 raeburn 12974: }
1.160.6.16 raeburn 12975: return ($numdcs,$table,$rows);
1.125 raeburn 12976: }
12977:
1.137 raeburn 12978: sub usersession_titles {
12979: return &Apache::lonlocal::texthash(
12980: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
12981: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 12982: spares => 'Servers offloaded to, when busy',
1.137 raeburn 12983: version => 'LON-CAPA version requirement',
1.138 raeburn 12984: excludedomain => 'Allow all, but exclude specific domains',
12985: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 12986: primary => 'Primary (checked first)',
1.154 raeburn 12987: default => 'Default',
1.137 raeburn 12988: );
12989: }
12990:
1.152 raeburn 12991: sub id_for_thisdom {
12992: my (%servers) = @_;
12993: my %altids;
12994: foreach my $server (keys(%servers)) {
12995: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
12996: if ($serverhome ne $server) {
12997: $altids{$serverhome} = $server;
12998: }
12999: }
13000: return %altids;
13001: }
13002:
1.150 raeburn 13003: sub count_servers {
13004: my ($currbalancer,%servers) = @_;
13005: my (@spares,$numspares);
13006: foreach my $lonhost (sort(keys(%servers))) {
13007: next if ($currbalancer eq $lonhost);
13008: push(@spares,$lonhost);
13009: }
13010: if ($currbalancer) {
13011: $numspares = scalar(@spares);
13012: } else {
13013: $numspares = scalar(@spares) - 1;
13014: }
13015: return ($numspares,@spares);
13016: }
13017:
13018: sub lonbalance_targets_js {
1.160.6.7 raeburn 13019: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 13020: my $select = &mt('Select');
13021: my ($alltargets,$allishome,$allinsttypes,@alltypes);
13022: if (ref($servers) eq 'HASH') {
13023: $alltargets = join("','",sort(keys(%{$servers})));
13024: my @homedoms;
13025: foreach my $server (sort(keys(%{$servers}))) {
13026: if (&Apache::lonnet::host_domain($server) eq $dom) {
13027: push(@homedoms,'1');
13028: } else {
13029: push(@homedoms,'0');
13030: }
13031: }
13032: $allishome = join("','",@homedoms);
13033: }
13034: if (ref($types) eq 'ARRAY') {
13035: if (@{$types} > 0) {
13036: @alltypes = @{$types};
13037: }
13038: }
13039: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
13040: $allinsttypes = join("','",@alltypes);
1.160.6.7 raeburn 13041: my (%currbalancer,%currtargets,%currrules,%existing);
13042: if (ref($settings) eq 'HASH') {
13043: %existing = %{$settings};
13044: }
13045: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
13046: \%currtargets,\%currrules);
13047: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 13048: return <<"END";
13049:
13050: <script type="text/javascript">
13051: // <![CDATA[
13052:
1.160.6.7 raeburn 13053: currBalancers = new Array('$balancers');
13054:
13055: function toggleTargets(balnum) {
13056: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13057: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
13058: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
13059: var prevbalancer = prevhostitem.value;
13060: var baltotal = document.getElementById('loadbalancing_total').value;
13061: prevhostitem.value = balancer;
13062: if (prevbalancer != '') {
13063: var prevIdx = currBalancers.indexOf(prevbalancer);
13064: if (prevIdx != -1) {
13065: currBalancers.splice(prevIdx,1);
13066: }
13067: }
1.150 raeburn 13068: if (balancer == '') {
1.160.6.7 raeburn 13069: hideSpares(balnum);
1.150 raeburn 13070: } else {
1.160.6.7 raeburn 13071: var currIdx = currBalancers.indexOf(balancer);
13072: if (currIdx == -1) {
13073: currBalancers.push(balancer);
13074: }
1.150 raeburn 13075: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 13076: var ishomedom = homedoms[lonhostitem.selectedIndex];
13077: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 13078: }
1.160.6.7 raeburn 13079: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 13080: return;
13081: }
13082:
1.160.6.7 raeburn 13083: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 13084: var alltargets = new Array('$alltargets');
13085: var insttypes = new Array('$allinsttypes');
1.151 raeburn 13086: var offloadtypes = new Array('primary','default');
13087:
1.160.6.7 raeburn 13088: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
13089: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 13090:
1.151 raeburn 13091: for (var i=0; i<offloadtypes.length; i++) {
13092: var count = 0;
13093: for (var j=0; j<alltargets.length; j++) {
13094: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 13095: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
13096: item.value = alltargets[j];
13097: item.style.textAlign='left';
13098: item.style.textFace='normal';
13099: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
13100: if (currBalancers.indexOf(alltargets[j]) == -1) {
13101: item.disabled = '';
13102: } else {
13103: item.disabled = 'disabled';
13104: item.checked = false;
13105: }
1.151 raeburn 13106: count ++;
13107: }
1.150 raeburn 13108: }
13109: }
1.151 raeburn 13110: for (var k=0; k<insttypes.length; k++) {
13111: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 13112: if (ishomedom == 1) {
1.160.6.7 raeburn 13113: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13114: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13115: } else {
1.160.6.7 raeburn 13116: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13117: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 13118: }
13119: } else {
1.160.6.7 raeburn 13120: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
13121: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 13122: }
1.151 raeburn 13123: if ((insttypes[k] != '_LC_external') &&
13124: ((insttypes[k] != '_LC_internetdom') ||
13125: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 13126: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
13127: item.options.length = 0;
13128: item.options[0] = new Option("","",true,true);
13129: var idx = 0;
1.151 raeburn 13130: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 13131: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
13132: idx ++;
13133: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 13134: }
13135: }
13136: }
13137: }
13138: return;
13139: }
13140:
1.160.6.7 raeburn 13141: function hideSpares(balnum) {
1.150 raeburn 13142: var alltargets = new Array('$alltargets');
13143: var insttypes = new Array('$allinsttypes');
13144: var offloadtypes = new Array('primary','default');
13145:
1.160.6.7 raeburn 13146: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
13147: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 13148:
13149: var total = alltargets.length - 1;
13150: for (var i=0; i<offloadtypes; i++) {
13151: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 13152: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
13153: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
13154: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 13155: }
1.150 raeburn 13156: }
13157: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 13158: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
13159: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 13160: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 13161: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
13162: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 13163: }
13164: }
13165: return;
13166: }
13167:
1.160.6.7 raeburn 13168: function checkOffloads(item,balnum,type) {
1.150 raeburn 13169: var alltargets = new Array('$alltargets');
13170: var offloadtypes = new Array('primary','default');
13171: if (item.checked) {
13172: var total = alltargets.length - 1;
13173: var other;
13174: if (type == offloadtypes[0]) {
1.151 raeburn 13175: other = offloadtypes[1];
1.150 raeburn 13176: } else {
1.151 raeburn 13177: other = offloadtypes[0];
1.150 raeburn 13178: }
13179: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 13180: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 13181: if (server == item.value) {
1.160.6.7 raeburn 13182: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
13183: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 13184: }
13185: }
13186: }
13187: }
13188: return;
13189: }
13190:
1.160.6.7 raeburn 13191: function singleServerToggle(balnum,type) {
13192: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 13193: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 13194: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
13195: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13196:
13197: } else {
1.160.6.7 raeburn 13198: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
13199: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 13200: }
13201: return;
13202: }
13203:
1.160.6.7 raeburn 13204: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 13205: if (type == '_LC_external') {
1.160.6.26 raeburn 13206: return;
1.150 raeburn 13207: }
1.160.6.7 raeburn 13208: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 13209: for (var i=0; i<typesRules.length; i++) {
13210: if (formname.elements[typesRules[i]].checked) {
13211: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 13212: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
13213: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 13214: } else {
1.160.6.7 raeburn 13215: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
13216: }
13217: }
13218: }
13219: return;
13220: }
13221:
13222: function balancerDeleteChange(balnum) {
13223: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
13224: var baltotal = document.getElementById('loadbalancing_total').value;
13225: var addtarget;
13226: var removetarget;
13227: var action = 'delete';
13228: if (document.getElementById('loadbalancing_delete_'+balnum)) {
13229: var lonhost = hostitem.value;
13230: var currIdx = currBalancers.indexOf(lonhost);
13231: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
13232: if (currIdx != -1) {
13233: currBalancers.splice(currIdx,1);
13234: }
13235: addtarget = lonhost;
13236: } else {
13237: if (currIdx == -1) {
13238: currBalancers.push(lonhost);
13239: }
13240: removetarget = lonhost;
13241: action = 'undelete';
13242: }
13243: balancerChange(balnum,baltotal,action,addtarget,removetarget);
13244: }
13245: return;
13246: }
13247:
13248: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
13249: if (baltotal > 1) {
13250: var offloadtypes = new Array('primary','default');
13251: var alltargets = new Array('$alltargets');
13252: var insttypes = new Array('$allinsttypes');
13253: for (var i=0; i<baltotal; i++) {
13254: if (i != balnum) {
13255: for (var j=0; j<offloadtypes.length; j++) {
13256: var total = alltargets.length - 1;
13257: for (var k=0; k<total; k++) {
13258: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
13259: var server = serveritem.value;
13260: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13261: if (server == addtarget) {
13262: serveritem.disabled = '';
13263: }
13264: }
13265: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13266: if (server == removetarget) {
13267: serveritem.disabled = 'disabled';
13268: serveritem.checked = false;
13269: }
13270: }
13271: }
13272: }
13273: for (var j=0; j<insttypes.length; j++) {
13274: if (insttypes[j] != '_LC_external') {
13275: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
13276: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
13277: var currSel = singleserver.selectedIndex;
13278: var currVal = singleserver.options[currSel].value;
13279: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
13280: var numoptions = singleserver.options.length;
13281: var needsnew = 1;
13282: for (var k=0; k<numoptions; k++) {
13283: if (singleserver.options[k] == addtarget) {
13284: needsnew = 0;
13285: break;
13286: }
13287: }
13288: if (needsnew == 1) {
13289: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
13290: }
13291: }
13292: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
13293: singleserver.options.length = 0;
13294: if ((currVal) && (currVal != removetarget)) {
13295: singleserver.options[0] = new Option("","",false,false);
13296: } else {
13297: singleserver.options[0] = new Option("","",true,true);
13298: }
13299: var idx = 0;
13300: for (var m=0; m<alltargets.length; m++) {
13301: if (currBalancers.indexOf(alltargets[m]) == -1) {
13302: idx ++;
13303: if (currVal == alltargets[m]) {
13304: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
13305: } else {
13306: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
13307: }
13308: }
13309: }
13310: }
13311: }
13312: }
13313: }
1.150 raeburn 13314: }
13315: }
13316: }
13317: return;
13318: }
13319:
1.152 raeburn 13320: // ]]>
13321: </script>
13322:
13323: END
13324: }
13325:
13326: sub new_spares_js {
13327: my @sparestypes = ('primary','default');
13328: my $types = join("','",@sparestypes);
13329: my $select = &mt('Select');
13330: return <<"END";
13331:
13332: <script type="text/javascript">
13333: // <![CDATA[
13334:
13335: function updateNewSpares(formname,lonhost) {
13336: var types = new Array('$types');
13337: var include = new Array();
13338: var exclude = new Array();
13339: for (var i=0; i<types.length; i++) {
13340: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
13341: for (var j=0; j<spareboxes.length; j++) {
13342: if (formname.elements[spareboxes[j]].checked) {
13343: exclude.push(formname.elements[spareboxes[j]].value);
13344: } else {
13345: include.push(formname.elements[spareboxes[j]].value);
13346: }
13347: }
13348: }
13349: for (var i=0; i<types.length; i++) {
13350: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
13351: var selIdx = newSpare.selectedIndex;
13352: var currnew = newSpare.options[selIdx].value;
13353: var okSpares = new Array();
13354: for (var j=0; j<newSpare.options.length; j++) {
13355: var possible = newSpare.options[j].value;
13356: if (possible != '') {
13357: if (exclude.indexOf(possible) == -1) {
13358: okSpares.push(possible);
13359: } else {
13360: if (currnew == possible) {
13361: selIdx = 0;
13362: }
13363: }
13364: }
13365: }
13366: for (var k=0; k<include.length; k++) {
13367: if (okSpares.indexOf(include[k]) == -1) {
13368: okSpares.push(include[k]);
13369: }
13370: }
13371: okSpares.sort();
13372: newSpare.options.length = 0;
13373: if (selIdx == 0) {
13374: newSpare.options[0] = new Option("$select","",true,true);
13375: } else {
13376: newSpare.options[0] = new Option("$select","",false,false);
13377: }
13378: for (var m=0; m<okSpares.length; m++) {
13379: var idx = m+1;
13380: var selThis = 0;
13381: if (selIdx != 0) {
13382: if (okSpares[m] == currnew) {
13383: selThis = 1;
13384: }
13385: }
13386: if (selThis == 1) {
13387: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
13388: } else {
13389: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
13390: }
13391: }
13392: }
13393: return;
13394: }
13395:
13396: function checkNewSpares(lonhost,type) {
13397: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
13398: var chosen = newSpare.options[newSpare.selectedIndex].value;
13399: if (chosen != '') {
13400: var othertype;
13401: var othernewSpare;
13402: if (type == 'primary') {
13403: othernewSpare = document.getElementById('newspare_default_'+lonhost);
13404: }
13405: if (type == 'default') {
13406: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
13407: }
13408: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
13409: othernewSpare.selectedIndex = 0;
13410: }
13411: }
13412: return;
13413: }
13414:
13415: // ]]>
13416: </script>
13417:
13418: END
13419:
13420: }
13421:
13422: sub common_domprefs_js {
13423: return <<"END";
13424:
13425: <script type="text/javascript">
13426: // <![CDATA[
13427:
1.150 raeburn 13428: function getIndicesByName(formname,item) {
1.152 raeburn 13429: var group = new Array();
1.150 raeburn 13430: for (var i=0;i<formname.elements.length;i++) {
13431: if (formname.elements[i].name == item) {
1.152 raeburn 13432: group.push(formname.elements[i].id);
1.150 raeburn 13433: }
13434: }
1.152 raeburn 13435: return group;
1.150 raeburn 13436: }
13437:
13438: // ]]>
13439: </script>
13440:
13441: END
1.152 raeburn 13442:
1.150 raeburn 13443: }
13444:
1.160.6.5 raeburn 13445: sub recaptcha_js {
13446: my %lt = &captcha_phrases();
13447: return <<"END";
13448:
13449: <script type="text/javascript">
13450: // <![CDATA[
13451:
13452: function updateCaptcha(caller,context) {
13453: var privitem;
13454: var pubitem;
13455: var privtext;
13456: var pubtext;
1.160.6.69 raeburn 13457: var versionitem;
13458: var versiontext;
1.160.6.5 raeburn 13459: if (document.getElementById(context+'_recaptchapub')) {
13460: pubitem = document.getElementById(context+'_recaptchapub');
13461: } else {
13462: return;
13463: }
13464: if (document.getElementById(context+'_recaptchapriv')) {
13465: privitem = document.getElementById(context+'_recaptchapriv');
13466: } else {
13467: return;
13468: }
13469: if (document.getElementById(context+'_recaptchapubtxt')) {
13470: pubtext = document.getElementById(context+'_recaptchapubtxt');
13471: } else {
13472: return;
13473: }
13474: if (document.getElementById(context+'_recaptchaprivtxt')) {
13475: privtext = document.getElementById(context+'_recaptchaprivtxt');
13476: } else {
13477: return;
13478: }
1.160.6.69 raeburn 13479: if (document.getElementById(context+'_recaptchaversion')) {
13480: versionitem = document.getElementById(context+'_recaptchaversion');
13481: } else {
13482: return;
13483: }
13484: if (document.getElementById(context+'_recaptchavertxt')) {
13485: versiontext = document.getElementById(context+'_recaptchavertxt');
13486: } else {
13487: return;
13488: }
1.160.6.5 raeburn 13489: if (caller.checked) {
13490: if (caller.value == 'recaptcha') {
13491: pubitem.type = 'text';
13492: privitem.type = 'text';
13493: pubitem.size = '40';
13494: privitem.size = '40';
13495: pubtext.innerHTML = "$lt{'pub'}";
13496: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 13497: versionitem.type = 'text';
13498: versionitem.size = '3';
13499: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 13500: } else {
13501: pubitem.type = 'hidden';
13502: privitem.type = 'hidden';
1.160.6.69 raeburn 13503: versionitem.type = 'hidden';
1.160.6.5 raeburn 13504: pubtext.innerHTML = '';
13505: privtext.innerHTML = '';
1.160.6.69 raeburn 13506: versiontext.innerHTML = '';
1.160.6.5 raeburn 13507: }
13508: }
13509: return;
13510: }
13511:
13512: // ]]>
13513: </script>
13514:
13515: END
13516:
13517: }
13518:
1.160.6.40 raeburn 13519: sub toggle_display_js {
1.160.6.16 raeburn 13520: return <<"END";
13521:
13522: <script type="text/javascript">
13523: // <![CDATA[
13524:
1.160.6.40 raeburn 13525: function toggleDisplay(domForm,caller) {
13526: if (document.getElementById(caller)) {
13527: var divitem = document.getElementById(caller);
13528: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 13529: var checkval = 1;
13530: var dispval = 'block';
1.160.6.40 raeburn 13531: if (caller == 'emailoptions') {
13532: optionsElement = domForm.cancreate_email;
13533: }
1.160.6.57 raeburn 13534: if (caller == 'studentsubmission') {
13535: optionsElement = domForm.postsubmit;
13536: }
1.160.6.64 raeburn 13537: if (caller == 'cloneinstcode') {
13538: optionsElement = domForm.canclone;
13539: checkval = 'instcode';
13540: }
1.160.6.40 raeburn 13541: if (optionsElement.length) {
1.160.6.16 raeburn 13542: var currval;
1.160.6.40 raeburn 13543: for (var i=0; i<optionsElement.length; i++) {
13544: if (optionsElement[i].checked) {
13545: currval = optionsElement[i].value;
1.160.6.16 raeburn 13546: }
13547: }
1.160.6.64 raeburn 13548: if (currval == checkval) {
13549: divitem.style.display = dispval;
1.160.6.16 raeburn 13550: } else {
1.160.6.40 raeburn 13551: divitem.style.display = 'none';
1.160.6.16 raeburn 13552: }
13553: }
13554: }
13555: return;
13556: }
13557:
13558: // ]]>
13559: </script>
13560:
13561: END
13562:
13563: }
13564:
1.160.6.5 raeburn 13565: sub captcha_phrases {
13566: return &Apache::lonlocal::texthash (
13567: priv => 'Private key',
13568: pub => 'Public key',
13569: original => 'original (CAPTCHA)',
13570: recaptcha => 'successor (ReCAPTCHA)',
13571: notused => 'unused',
1.160.6.69 raeburn 13572: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 13573: );
13574: }
13575:
1.160.6.24 raeburn 13576: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 13577: my ($dom,$cachekeys) = @_;
13578: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 13579: my %servers = &Apache::lonnet::internet_dom_servers($dom);
13580: my %thismachine;
13581: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.81 raeburn 13582: my @posscached = ('domainconfig','domdefaults','usersessions','directorysrch');
1.160.6.61 raeburn 13583: if (keys(%servers)) {
1.160.6.24 raeburn 13584: foreach my $server (keys(%servers)) {
13585: next if ($thismachine{$server});
1.160.6.27 raeburn 13586: my @cached;
13587: foreach my $name (@posscached) {
13588: if ($cachekeys->{$name}) {
13589: push(@cached,&escape($name).':'.&escape($dom));
13590: }
13591: }
13592: if (@cached) {
13593: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
13594: }
1.160.6.24 raeburn 13595: }
13596: }
13597: return;
13598: }
13599:
1.3 raeburn 13600: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>