Annotation of loncom/interface/domainprefs.pm, revision 1.138.2.12
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.138.2.12! raeburn 4: # $Id: domainprefs.pm,v 1.138.2.11 2011/10/10 17:57:33 raeburn Exp $
1.2 albertel 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
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
48: for use by individuals affliated with the institution. Accordingly, each domain
49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
89: number of rows displayed on the page, and $action is the context (either quotas
90: or requestcourses).
91:
92: The print_quotas routine was orginally created to display/store information
93: about default quota sizes for portfolio spaces for the different types of
94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
95: but is now also used to manage availability of user tools:
96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
97: used by course owners to request creation of a course.
98:
99: Outputs: 1
100:
101: $datatable - HTML containing form elements which allow settings to be changed.
102:
103: In the case of course requests, radio buttons are displayed for each institutional
104: affiliate type (and also default, and _LC_adv) for each of the course types
105: (official, unofficial and community). In each case the radio buttons allow the
106: selection of one of four values:
107:
1.104 raeburn 108: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 109: which have the following effects:
110:
111: 0
112:
113: =over
114:
115: - course requests are not allowed for this course types/affiliation
116:
117: =back
118:
1.104 raeburn 119: approval
1.101 raeburn 120:
121: =over
122:
123: - course requests must be approved by a Doman Coordinator in the
124: course's domain
125:
126: =back
127:
128: validate
129:
130: =over
131:
132: - an institutional validation (e.g., check requestor is instructor
133: of record) needs to be passed before the course will be created. The required
134: validation is in localenroll.pm on the primary library server for the course
135: domain.
136:
137: =back
138:
139: autolimit
140:
141: =over
142:
1.138.2.8 raeburn 143: - course requests will be processed automatically up to a limit of
1.101 raeburn 144: N requests for the course type for the particular requestor.
145: If N is undefined, there is no limit to the number of course requests
146: which a course owner may submit and have processed automatically.
147:
148: =back
149:
150: =item modify_quotas()
151:
152: =back
153:
154: =cut
155:
1.1 raeburn 156: package Apache::domainprefs;
157:
158: use strict;
159: use Apache::Constants qw(:common :http);
160: use Apache::lonnet;
161: use Apache::loncommon();
162: use Apache::lonhtmlcommon();
163: use Apache::lonlocal;
1.43 raeburn 164: use Apache::lonmsg();
1.91 raeburn 165: use Apache::lonconfigsettings;
1.69 raeburn 166: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 167: use LONCAPA::Enrollment;
1.81 raeburn 168: use LONCAPA::lonauthcgi();
1.9 raeburn 169: use File::Copy;
1.43 raeburn 170: use Locale::Language;
1.62 raeburn 171: use DateTime::TimeZone;
1.68 raeburn 172: use DateTime::Locale;
1.1 raeburn 173:
1.138.2.10 raeburn 174: my $registered_cleanup;
175: my $modified_urls;
176:
1.1 raeburn 177: sub handler {
178: my $r=shift;
179: if ($r->header_only) {
180: &Apache::loncommon::content_type($r,'text/html');
181: $r->send_http_header;
182: return OK;
183: }
184:
1.91 raeburn 185: my $context = 'domain';
1.1 raeburn 186: my $dom = $env{'request.role.domain'};
1.5 albertel 187: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 188: if (&Apache::lonnet::allowed('mau',$dom)) {
189: &Apache::loncommon::content_type($r,'text/html');
190: $r->send_http_header;
191: } else {
192: $env{'user.error.msg'}=
193: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
194: return HTTP_NOT_ACCEPTABLE;
195: }
1.138.2.10 raeburn 196:
197: $registered_cleanup=0;
198: @{$modified_urls}=();
199:
1.1 raeburn 200: &Apache::lonhtmlcommon::clear_breadcrumbs();
201: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 202: ['phase','actions']);
1.30 raeburn 203: my $phase = 'pickactions';
1.3 raeburn 204: if ( exists($env{'form.phase'}) ) {
205: $phase = $env{'form.phase'};
206: }
207: my %domconfig =
1.6 raeburn 208: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 209: 'quotas','autoenroll','autoupdate','autocreate',
210: 'directorysrch','usercreation','usermodification',
211: 'contacts','defaults','scantron','coursecategories',
1.138.2.2 raeburn 212: 'serverstatuses','requestcourses','coursedefaults',
213: 'usersessions'],$dom);
1.43 raeburn 214: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 215: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 216: 'usercreation','usermodification','scantron',
1.138.2.1 raeburn 217: 'requestcourses','coursecategories','serverstatuses',
1.138.2.2 raeburn 218: 'coursedefaults','usersessions');
1.30 raeburn 219: my %prefs = (
220: 'rolecolors' =>
221: { text => 'Default color schemes',
1.67 raeburn 222: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 223: header => [{col1 => 'Student Settings',
224: col2 => '',},
225: {col1 => 'Coordinator Settings',
226: col2 => '',},
227: {col1 => 'Author Settings',
228: col2 => '',},
229: {col1 => 'Administrator Settings',
230: col2 => '',}],
231: },
1.110 raeburn 232: 'login' =>
1.30 raeburn 233: { text => 'Log-in page options',
1.67 raeburn 234: help => 'Domain_Configuration_Login_Page',
1.30 raeburn 235: header => [{col1 => 'Item',
236: col2 => '',}],
237: },
1.110 raeburn 238:
1.43 raeburn 239: 'defaults' =>
1.138.2.5 raeburn 240: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 241: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 242: header => [{col1 => 'Setting',
243: col2 => 'Value'}],
244: },
1.30 raeburn 245: 'quotas' =>
1.133 raeburn 246: { text => 'User blogs, personal information pages, portfolios',
1.67 raeburn 247: help => 'Domain_Configuration_Quotas',
1.77 raeburn 248: header => [{col1 => 'User affiliation',
1.72 raeburn 249: col2 => 'Available tools',
250: col3 => 'Portfolio quota',}],
1.30 raeburn 251: },
252: 'autoenroll' =>
253: { text => 'Auto-enrollment settings',
1.67 raeburn 254: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 255: header => [{col1 => 'Configuration setting',
256: col2 => 'Value(s)'}],
257: },
258: 'autoupdate' =>
259: { text => 'Auto-update settings',
1.67 raeburn 260: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 261: header => [{col1 => 'Setting',
262: col2 => 'Value',},
1.131 raeburn 263: {col1 => 'Setting',
264: col2 => 'Affiliation'},
1.43 raeburn 265: {col1 => 'User population',
1.131 raeburn 266: col2 => 'Updateable user data'}],
1.30 raeburn 267: },
1.125 raeburn 268: 'autocreate' =>
269: { text => 'Auto-course creation settings',
270: help => 'Domain_Configuration_Auto_Creation',
271: header => [{col1 => 'Configuration Setting',
272: col2 => 'Value',}],
273: },
1.30 raeburn 274: 'directorysrch' =>
275: { text => 'Institutional directory searches',
1.67 raeburn 276: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 277: header => [{col1 => 'Setting',
278: col2 => 'Value',}],
279: },
280: 'contacts' =>
281: { text => 'Contact Information',
1.67 raeburn 282: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 283: header => [{col1 => 'Setting',
284: col2 => 'Value',}],
285: },
286:
287: 'usercreation' =>
288: { text => 'User creation',
1.67 raeburn 289: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 290: header => [{col1 => 'Format rule type',
291: col2 => 'Format rules in force'},
1.34 raeburn 292: {col1 => 'User account creation',
293: col2 => 'Usernames which may be created',},
1.30 raeburn 294: {col1 => 'Context',
1.43 raeburn 295: col2 => 'Assignable authentication types'}],
1.30 raeburn 296: },
1.69 raeburn 297: 'usermodification' =>
1.33 raeburn 298: { text => 'User modification',
1.67 raeburn 299: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 300: header => [{col1 => 'Target user has role',
301: col2 => 'User information updateable in author context'},
302: {col1 => 'Target user has role',
1.63 raeburn 303: col2 => 'User information updateable in course context'},
304: {col1 => "Status of user",
305: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 306: },
1.69 raeburn 307: 'scantron' =>
1.95 www 308: { text => 'Bubblesheet format file',
1.67 raeburn 309: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 310: header => [ {col1 => 'Item',
311: col2 => '',
312: }],
313: },
1.86 raeburn 314: 'requestcourses' =>
315: {text => 'Request creation of courses',
316: help => 'Domain_Configuration_Request_Courses',
317: header => [{col1 => 'User affiliation',
1.102 raeburn 318: col2 => 'Availability/Processing of requests',},
319: {col1 => 'Setting',
320: col2 => 'Value'}],
1.86 raeburn 321: },
1.69 raeburn 322: 'coursecategories' =>
1.120 raeburn 323: { text => 'Cataloging of courses/communities',
1.67 raeburn 324: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 325: header => [{col1 => 'Category settings',
1.57 raeburn 326: col2 => '',},
327: {col1 => 'Categories',
328: col2 => '',
329: }],
1.69 raeburn 330: },
331: 'serverstatuses' =>
1.77 raeburn 332: {text => 'Access to server status pages',
1.69 raeburn 333: help => 'Domain_Configuration_Server_Status',
334: header => [{col1 => 'Status Page',
335: col2 => 'Other named users',
336: col3 => 'Specific IPs',
337: }],
338: },
1.118 jms 339: 'helpsettings' =>
340: {text => 'Help page settings',
341: help => 'Domain_Configuration_Help_Settings',
1.122 jms 342: header => [{col1 => 'Authenticated Help Settings',
343: col2 => ''},
344: {col1 => 'Unauthenticated Help Settings',
345: col2 => ''}],
1.118 jms 346: },
1.138.2.2 raeburn 347: 'coursedefaults' =>
1.121 raeburn 348: {text => 'Course/Community defaults',
349: help => 'Domain_Configuration_Course_Defaults',
1.138.2.2 raeburn 350: header => [{col1 => 'Defaults which can be overridden for each course by a DC',
1.138.2.3 raeburn 351: col2 => 'Value',}],
1.121 raeburn 352: },
1.120 raeburn 353: 'privacy' =>
354: {text => 'User Privacy',
355: help => 'Domain_Configuration_User_Privacy',
356: header => [{col1 => 'Setting',
357: col2 => 'Value',}],
358: },
1.137 raeburn 359: 'usersessions' =>
360: {text => 'User session hosting',
361: help => 'Domain_Configuration_User_Sessions',
362: header => [{col1 => 'Hosting of users from other domains',
363: col2 => 'Rules'},
364: {col1 => "Hosting domain's own users elsewhere",
365: col2 => 'Rules'}],
366: },
1.3 raeburn 367: );
1.117 raeburn 368: my %servers = &dom_servers($dom);
1.110 raeburn 369: if (keys(%servers) > 1) {
370: $prefs{'login'} = { text => 'Log-in page options',
371: help => 'Domain_Configuration_Login_Page',
372: header => [{col1 => 'Log-in Service',
373: col2 => 'Server Setting',},
374: {col1 => 'Log-in Page Items',
375: col2 => ''}],
376: };
377: }
1.6 raeburn 378: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 379: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 380: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 381: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 382: text=>"Settings to display/modify"});
1.9 raeburn 383: my $confname = $dom.'-domainconfig';
1.3 raeburn 384: if ($phase eq 'process') {
1.91 raeburn 385: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 386: } elsif ($phase eq 'display') {
1.91 raeburn 387: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname);
1.1 raeburn 388: } else {
1.21 raeburn 389: if (keys(%domconfig) == 0) {
390: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 391: my @ids=&Apache::lonnet::current_machine_ids();
392: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 393: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 394: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 395: my $custom_img_count = 0;
396: foreach my $img (@loginimages) {
397: if ($designhash{$dom.'.login.'.$img} ne '') {
398: $custom_img_count ++;
399: }
400: }
401: foreach my $role (@roles) {
402: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
403: $custom_img_count ++;
404: }
405: }
406: if ($custom_img_count > 0) {
1.94 raeburn 407: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 408: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 409: $r->print(
410: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
411: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
412: &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 />'.
413: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
414: if ($switch_server) {
1.30 raeburn 415: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 416: }
1.91 raeburn 417: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 418: return OK;
419: }
420: }
421: }
1.91 raeburn 422: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 423: }
424: return OK;
425: }
426:
427: sub process_changes {
1.92 raeburn 428: my ($r,$dom,$confname,$action,$roles,$values) = @_;
429: my %domconfig;
430: if (ref($values) eq 'HASH') {
431: %domconfig = %{$values};
432: }
1.3 raeburn 433: my $output;
434: if ($action eq 'login') {
1.9 raeburn 435: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 436: } elsif ($action eq 'rolecolors') {
1.9 raeburn 437: $output = &modify_rolecolors($r,$dom,$confname,$roles,
438: %domconfig);
1.3 raeburn 439: } elsif ($action eq 'quotas') {
1.86 raeburn 440: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 441: } elsif ($action eq 'autoenroll') {
442: $output = &modify_autoenroll($dom,%domconfig);
443: } elsif ($action eq 'autoupdate') {
444: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 445: } elsif ($action eq 'autocreate') {
446: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 447: } elsif ($action eq 'directorysrch') {
448: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 449: } elsif ($action eq 'usercreation') {
1.28 raeburn 450: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 451: } elsif ($action eq 'usermodification') {
452: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 453: } elsif ($action eq 'contacts') {
454: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 455: } elsif ($action eq 'defaults') {
456: $output = &modify_defaults($dom,$r);
1.46 raeburn 457: } elsif ($action eq 'scantron') {
1.48 raeburn 458: $output = &modify_scantron($r,$dom,$confname,%domconfig);
459: } elsif ($action eq 'coursecategories') {
460: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 461: } elsif ($action eq 'serverstatuses') {
462: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 463: } elsif ($action eq 'requestcourses') {
464: $output = &modify_quotas($dom,$action,%domconfig);
1.138.2.2 raeburn 465: } elsif ($action eq 'coursedefaults') {
466: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 467: } elsif ($action eq 'usersessions') {
468: $output = &modify_usersessions($dom,%domconfig);
1.3 raeburn 469: }
470: return $output;
471: }
472:
473: sub print_config_box {
1.9 raeburn 474: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 475: my $rowtotal = 0;
1.49 raeburn 476: my $output;
477: if ($action eq 'coursecategories') {
478: $output = &coursecategories_javascript($settings);
1.91 raeburn 479: }
1.49 raeburn 480: $output .=
1.30 raeburn 481: '<table class="LC_nested_outer">
1.3 raeburn 482: <tr>
1.66 raeburn 483: <th align="left" valign="middle"><span class="LC_nobreak">'.
484: &mt($item->{text}).' '.
485: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
486: '</tr>';
1.30 raeburn 487: $rowtotal ++;
1.110 raeburn 488: my $numheaders = 1;
489: if (ref($item->{'header'}) eq 'ARRAY') {
490: $numheaders = scalar(@{$item->{'header'}});
491: }
492: if ($numheaders > 1) {
1.64 raeburn 493: my $colspan = '';
1.122 jms 494: if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
1.64 raeburn 495: $colspan = ' colspan="2"';
496: }
1.30 raeburn 497: $output .= '
1.3 raeburn 498: <tr>
499: <td>
500: <table class="LC_nested">
501: <tr class="LC_info_row">
1.59 bisitz 502: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
503: <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 504: </tr>';
1.69 raeburn 505: $rowtotal ++;
1.6 raeburn 506: if ($action eq 'autoupdate') {
1.30 raeburn 507: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 508: } elsif ($action eq 'usercreation') {
1.33 raeburn 509: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
510: } elsif ($action eq 'usermodification') {
511: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 512: } elsif ($action eq 'coursecategories') {
513: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 514: } elsif ($action eq 'login') {
515: $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
516: $colspan = ' colspan="2"';
1.102 raeburn 517: } elsif ($action eq 'requestcourses') {
518: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.118 jms 519: } elsif ($action eq 'helpsettings') {
1.122 jms 520: $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 521: } elsif ($action eq 'usersessions') {
1.138.2.4 raeburn 522: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 523: } elsif ($action eq 'rolecolors') {
1.30 raeburn 524: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 525: }
1.30 raeburn 526: $output .= '
1.6 raeburn 527: </table>
528: </td>
529: </tr>
530: <tr>
531: <td>
532: <table class="LC_nested">
533: <tr class="LC_info_row">
1.59 bisitz 534: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 535: $output .= '
1.59 bisitz 536: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 537: </tr>';
538: $rowtotal ++;
1.6 raeburn 539: if ($action eq 'autoupdate') {
1.131 raeburn 540: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
541: </table>
542: </td>
543: </tr>
544: <tr>
545: <td>
546: <table class="LC_nested">
547: <tr class="LC_info_row">
548: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
549: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
550: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
551: $rowtotal ++;
1.28 raeburn 552: } elsif ($action eq 'usercreation') {
1.34 raeburn 553: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
554: </table>
555: </td>
556: </tr>
557: <tr>
558: <td>
559: <table class="LC_nested">
560: <tr class="LC_info_row">
1.59 bisitz 561: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
562: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 563: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
564: $rowtotal ++;
1.33 raeburn 565: } elsif ($action eq 'usermodification') {
1.63 raeburn 566: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
567: </table>
568: </td>
569: </tr>
570: <tr>
571: <td>
572: <table class="LC_nested">
573: <tr class="LC_info_row">
574: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
575: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
576: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
577: $rowtotal ++;
1.57 raeburn 578: } elsif ($action eq 'coursecategories') {
579: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 580: } elsif ($action eq 'login') {
581: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 582: } elsif ($action eq 'requestcourses') {
583: $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
1.122 jms 584: } elsif ($action eq 'helpsettings') {
585: $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
1.137 raeburn 586: } elsif ($action eq 'usersessions') {
587: $output .= &print_usersessions('bottom',$dom,$settings,\$rowtotal);
1.122 jms 588: } elsif ($action eq 'rolecolors') {
1.30 raeburn 589: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 590: </table>
591: </td>
592: </tr>
593: <tr>
594: <td>
595: <table class="LC_nested">
596: <tr class="LC_info_row">
1.69 raeburn 597: <td class="LC_left_item"'.$colspan.' valign="top">'.
598: &mt($item->{'header'}->[2]->{'col1'}).'</td>
599: <td class="LC_right_item" valign="top">'.
600: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 601: </tr>'.
1.30 raeburn 602: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 603: </table>
604: </td>
605: </tr>
606: <tr>
607: <td>
608: <table class="LC_nested">
609: <tr class="LC_info_row">
1.59 bisitz 610: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
611: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 612: </tr>'.
1.30 raeburn 613: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
614: $rowtotal += 2;
1.6 raeburn 615: }
1.3 raeburn 616: } else {
1.30 raeburn 617: $output .= '
1.3 raeburn 618: <tr>
619: <td>
620: <table class="LC_nested">
1.30 raeburn 621: <tr class="LC_info_row">';
1.24 raeburn 622: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 623: $output .= '
1.59 bisitz 624: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 625: } elsif ($action eq 'serverstatuses') {
626: $output .= '
627: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
628: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
629:
1.6 raeburn 630: } else {
1.30 raeburn 631: $output .= '
1.69 raeburn 632: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
633: }
1.72 raeburn 634: if (defined($item->{'header'}->[0]->{'col3'})) {
635: $output .= '<td class="LC_left_item" valign="top">'.
636: &mt($item->{'header'}->[0]->{'col2'});
637: if ($action eq 'serverstatuses') {
638: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
639: }
1.69 raeburn 640: } else {
641: $output .= '<td class="LC_right_item" valign="top">'.
642: &mt($item->{'header'}->[0]->{'col2'});
643: }
644: $output .= '</td>';
645: if ($item->{'header'}->[0]->{'col3'}) {
646: $output .= '<td class="LC_right_item" valign="top">'.
647: &mt($item->{'header'}->[0]->{'col3'});
648: if ($action eq 'serverstatuses') {
649: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
650: }
651: $output .= '</td>';
1.6 raeburn 652: }
1.69 raeburn 653: $output .= '</tr>';
1.48 raeburn 654: $rowtotal ++;
1.3 raeburn 655: if ($action eq 'login') {
1.110 raeburn 656: $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
657: \$rowtotal);
1.3 raeburn 658: } elsif ($action eq 'quotas') {
1.86 raeburn 659: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 660: } elsif ($action eq 'autoenroll') {
1.30 raeburn 661: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 662: } elsif ($action eq 'autocreate') {
663: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 664: } elsif ($action eq 'directorysrch') {
1.30 raeburn 665: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 666: } elsif ($action eq 'contacts') {
1.30 raeburn 667: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 668: } elsif ($action eq 'defaults') {
669: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 670: } elsif ($action eq 'scantron') {
671: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 672: } elsif ($action eq 'serverstatuses') {
673: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.138.2.2 raeburn 674: } elsif ($action eq 'coursedefaults') {
675: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.121 raeburn 676: }
1.3 raeburn 677: }
1.30 raeburn 678: $output .= '
1.3 raeburn 679: </table>
680: </td>
681: </tr>
1.30 raeburn 682: </table><br />';
683: return ($output,$rowtotal);
1.1 raeburn 684: }
685:
1.3 raeburn 686: sub print_login {
1.110 raeburn 687: my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
688: my ($css_class,$datatable);
1.6 raeburn 689: my %choices = &login_choices();
1.110 raeburn 690:
691: if ($position eq 'top') {
1.117 raeburn 692: my %servers = &dom_servers($dom);
1.110 raeburn 693: my $choice = $choices{'disallowlogin'};
694: $css_class = ' class="LC_odd_row"';
1.128 raeburn 695: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 696: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 697: '<th>'.$choices{'server'}.'</th>'.
698: '<th>'.$choices{'serverpath'}.'</th>'.
699: '<th>'.$choices{'custompath'}.'</th>'.
700: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 701: my %disallowed;
702: if (ref($settings) eq 'HASH') {
703: if (ref($settings->{'loginvia'}) eq 'HASH') {
704: %disallowed = %{$settings->{'loginvia'}};
705: }
706: }
707: foreach my $lonhost (sort(keys(%servers))) {
708: my $direct = 'selected="selected"';
1.128 raeburn 709: if (ref($disallowed{$lonhost}) eq 'HASH') {
710: if ($disallowed{$lonhost}{'server'} ne '') {
711: $direct = '';
712: }
1.110 raeburn 713: }
1.115 raeburn 714: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 715: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 716: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
717: '</option>';
718: foreach my $hostid (keys(%servers)) {
1.115 raeburn 719: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 720: my $selected = '';
1.128 raeburn 721: if (ref($disallowed{$lonhost}) eq 'HASH') {
722: if ($hostid eq $disallowed{$lonhost}{'server'}) {
723: $selected = 'selected="selected"';
724: }
1.110 raeburn 725: }
726: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
727: $servers{$hostid}.'</option>';
728: }
1.128 raeburn 729: $datatable .= '</select></td>'.
730: '<td><select name="'.$lonhost.'_serverpath">';
731: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
732: my $pathname = $path;
733: if ($path eq 'custom') {
734: $pathname = &mt('Custom Path').' ->';
735: }
736: my $selected = '';
737: if (ref($disallowed{$lonhost}) eq 'HASH') {
738: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
739: $selected = 'selected="selected"';
740: }
741: } elsif ($path eq '') {
742: $selected = 'selected="selected"';
743: }
744: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
745: }
746: $datatable .= '</select></td>';
747: my ($custom,$exempt);
748: if (ref($disallowed{$lonhost}) eq 'HASH') {
749: $custom = $disallowed{$lonhost}{'custompath'};
750: $exempt = $disallowed{$lonhost}{'exempt'};
751: }
752: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
753: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
754: '</tr>';
1.110 raeburn 755: }
756: $datatable .= '</table></td></tr>';
757: return $datatable;
758: }
759:
1.42 raeburn 760: my %defaultchecked = (
1.43 raeburn 761: 'coursecatalog' => 'on',
762: 'adminmail' => 'off',
763: 'newuser' => 'off',
764: );
1.118 jms 765: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 766: my (%checkedon,%checkedoff);
767: foreach my $item (@toggles) {
768: if ($defaultchecked{$item} eq 'on') {
769: $checkedon{$item} = ' checked="checked" ';
770: $checkedoff{$item} = ' ';
771: } elsif ($defaultchecked{$item} eq 'off') {
772: $checkedoff{$item} = ' checked="checked" ';
773: $checkedon{$item} = ' ';
774: }
775: }
1.41 raeburn 776: my @images = ('img','logo','domlogo','login');
777: my @logintext = ('textcol','bgcol');
1.6 raeburn 778: my @bgs = ('pgbg','mainbg','sidebg');
779: my @links = ('link','alink','vlink');
1.7 albertel 780: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 781: my %defaultdesign = %Apache::loncommon::defaultdesign;
782: my (%is_custom,%designs);
783: my %defaults = (
784: font => $defaultdesign{'login.font'},
785: );
786: foreach my $item (@images) {
787: $defaults{$item} = $defaultdesign{'login.'.$item};
1.70 raeburn 788: $defaults{'showlogo'}{$item} = 1;
1.6 raeburn 789: }
790: foreach my $item (@bgs) {
791: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
792: }
1.41 raeburn 793: foreach my $item (@logintext) {
794: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
795: }
1.6 raeburn 796: foreach my $item (@links) {
797: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
798: }
1.3 raeburn 799: if (ref($settings) eq 'HASH') {
1.42 raeburn 800: foreach my $item (@toggles) {
801: if ($settings->{$item} eq '1') {
802: $checkedon{$item} = ' checked="checked" ';
803: $checkedoff{$item} = ' ';
804: } elsif ($settings->{$item} eq '0') {
805: $checkedoff{$item} = ' checked="checked" ';
806: $checkedon{$item} = ' ';
807: }
1.1 raeburn 808: }
1.6 raeburn 809: foreach my $item (@images) {
1.70 raeburn 810: if (defined($settings->{$item})) {
1.6 raeburn 811: $designs{$item} = $settings->{$item};
812: $is_custom{$item} = 1;
813: }
1.70 raeburn 814: if (defined($settings->{'showlogo'}{$item})) {
815: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
816: }
1.6 raeburn 817: }
1.41 raeburn 818: foreach my $item (@logintext) {
819: if ($settings->{$item} ne '') {
820: $designs{'logintext'}{$item} = $settings->{$item};
821: $is_custom{$item} = 1;
822: }
823: }
1.6 raeburn 824: if ($settings->{'font'} ne '') {
825: $designs{'font'} = $settings->{'font'};
826: $is_custom{'font'} = 1;
827: }
828: foreach my $item (@bgs) {
829: if ($settings->{$item} ne '') {
830: $designs{'bgs'}{$item} = $settings->{$item};
831: $is_custom{$item} = 1;
832: }
833: }
834: foreach my $item (@links) {
835: if ($settings->{$item} ne '') {
836: $designs{'links'}{$item} = $settings->{$item};
837: $is_custom{$item} = 1;
838: }
839: }
840: } else {
841: if ($designhash{$dom.'.login.font'} ne '') {
842: $designs{'font'} = $designhash{$dom.'.login.font'};
843: $is_custom{'font'} = 1;
844: }
1.8 raeburn 845: foreach my $item (@images) {
846: if ($designhash{$dom.'.login.'.$item} ne '') {
847: $designs{$item} = $designhash{$dom.'.login.'.$item};
848: $is_custom{$item} = 1;
849: }
850: }
1.6 raeburn 851: foreach my $item (@bgs) {
852: if ($designhash{$dom.'.login.'.$item} ne '') {
853: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
854: $is_custom{$item} = 1;
855: }
856: }
857: foreach my $item (@links) {
858: if ($designhash{$dom.'.login.'.$item} ne '') {
859: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
860: $is_custom{$item} = 1;
861: }
862: }
1.1 raeburn 863: }
1.6 raeburn 864: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
865: logo => 'Institution Logo',
1.41 raeburn 866: domlogo => 'Domain Logo',
867: login => 'Login box');
1.6 raeburn 868: my $itemcount = 1;
1.42 raeburn 869: foreach my $item (@toggles) {
870: $css_class = $itemcount%2?' class="LC_odd_row"':'';
871: $datatable .=
872: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
873: '</td><td>'.
874: '<span class="LC_nobreak"><label><input type="radio" name="'.
875: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
876: '</label> <label><input type="radio" name="'.$item.'"'.
877: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
878: '</tr>';
879: $itemcount ++;
880: }
1.135 bisitz 881: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1.6 raeburn 882: $datatable .= '</tr></table></td></tr>';
883: return $datatable;
884: }
885:
886: sub login_choices {
887: my %choices =
888: &Apache::lonlocal::texthash (
1.116 bisitz 889: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 890: adminmail => "Display Administrator's E-mail Address?",
891: disallowlogin => "Login page requests redirected",
892: hostid => "Server",
1.128 raeburn 893: server => "Redirect to:",
894: serverpath => "Path",
895: custompath => "Custom",
896: exempt => "Exempt IP(s)",
1.110 raeburn 897: directlogin => "No redirect",
898: newuser => "Link to create a user account",
899: img => "Header",
900: logo => "Main Logo",
901: domlogo => "Domain Logo",
902: login => "Log-in Header",
903: textcol => "Text color",
904: bgcol => "Box color",
905: bgs => "Background colors",
906: links => "Link colors",
907: font => "Font color",
908: pgbg => "Header",
909: mainbg => "Page",
910: sidebg => "Login box",
911: link => "Link",
912: alink => "Active link",
913: vlink => "Visited link",
1.6 raeburn 914: );
915: return %choices;
916: }
917:
918: sub print_rolecolors {
1.30 raeburn 919: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 920: my %choices = &color_font_choices();
921: my @bgs = ('pgbg','tabbg','sidebg');
922: my @links = ('link','alink','vlink');
923: my @images = ('img');
924: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 925: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 926: my %defaultdesign = %Apache::loncommon::defaultdesign;
927: my (%is_custom,%designs);
928: my %defaults = (
929: img => $defaultdesign{$role.'.img'},
930: font => $defaultdesign{$role.'.font'},
1.97 tempelho 931: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 932: );
933: foreach my $item (@bgs) {
934: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
935: }
936: foreach my $item (@links) {
937: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
938: }
939: if (ref($settings) eq 'HASH') {
940: if (ref($settings->{$role}) eq 'HASH') {
941: if ($settings->{$role}->{'img'} ne '') {
942: $designs{'img'} = $settings->{$role}->{'img'};
943: $is_custom{'img'} = 1;
944: }
945: if ($settings->{$role}->{'font'} ne '') {
946: $designs{'font'} = $settings->{$role}->{'font'};
947: $is_custom{'font'} = 1;
948: }
1.97 tempelho 949: if ($settings->{$role}->{'fontmenu'} ne '') {
950: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
951: $is_custom{'fontmenu'} = 1;
952: }
1.6 raeburn 953: foreach my $item (@bgs) {
954: if ($settings->{$role}->{$item} ne '') {
955: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
956: $is_custom{$item} = 1;
957: }
958: }
959: foreach my $item (@links) {
960: if ($settings->{$role}->{$item} ne '') {
961: $designs{'links'}{$item} = $settings->{$role}->{$item};
962: $is_custom{$item} = 1;
963: }
964: }
965: }
966: } else {
967: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
968: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
969: $is_custom{'img'} = 1;
970: }
1.97 tempelho 971: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
972: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
973: $is_custom{'fontmenu'} = 1;
974: }
1.6 raeburn 975: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
976: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
977: $is_custom{'font'} = 1;
978: }
979: foreach my $item (@bgs) {
980: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
981: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
982: $is_custom{$item} = 1;
983:
984: }
985: }
986: foreach my $item (@links) {
987: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
988: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
989: $is_custom{$item} = 1;
990: }
991: }
992: }
993: my $itemcount = 1;
1.30 raeburn 994: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 995: $datatable .= '</tr></table></td></tr>';
996: return $datatable;
997: }
998:
999: sub display_color_options {
1.9 raeburn 1000: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1001: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.6 raeburn 1002: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1003: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1004: '<td>'.$choices->{'font'}.'</td>';
1005: if (!$is_custom->{'font'}) {
1.30 raeburn 1006: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1007: } else {
1008: $datatable .= '<td> </td>';
1009: }
1010: my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8 raeburn 1011: $datatable .= '<td><span class="LC_nobreak">'.
1.6 raeburn 1012: '<input type="text" size="10" name="'.$role.'_font"'.
1.8 raeburn 1013: ' value="'.$designs->{'font'}.'" /> '.$fontlink.
1.30 raeburn 1014: ' <span id="css_'.$role.'_font" style="background-color: '.
1015: $designs->{'font'}.';"> </span>'.
1.8 raeburn 1016: '</span></td></tr>';
1.107 raeburn 1017: unless ($role eq 'login') {
1018: $datatable .= '<tr'.$css_class.'>'.
1019: '<td>'.$choices->{'fontmenu'}.'</td>';
1020: if (!$is_custom->{'fontmenu'}) {
1021: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1022: } else {
1023: $datatable .= '<td> </td>';
1024: }
1025: $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
1026: $datatable .= '<td><span class="LC_nobreak">'.
1027: '<input type="text" size="10" name="'.$role.'_fontmenu"'.
1028: ' value="'.$designs->{'fontmenu'}.'" /> '.$fontlink.
1029: ' <span id="css_'.$role.'_fontmenu" style="background-color: '.
1030: $designs->{'fontmenu'}.';"> </span>'.
1031: '</span></td></tr>';
1.97 tempelho 1032: }
1.9 raeburn 1033: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1034: foreach my $img (@{$images}) {
1.18 albertel 1035: $itemcount ++;
1.6 raeburn 1036: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1037: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1038: '<td>'.$choices->{$img};
1.41 raeburn 1039: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1040: if ($role eq 'login') {
1041: if ($img eq 'login') {
1042: $login_hdr_pick =
1.135 bisitz 1043: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1044: $logincolors =
1045: &login_text_colors($img,$role,$logintext,$phase,$choices,
1046: $designs);
1047: } elsif ($img ne 'domlogo') {
1048: $datatable.= &logo_display_options($img,$defaults,$designs);
1049: }
1050: }
1051: $datatable .= '</td>';
1.6 raeburn 1052: if ($designs->{$img} ne '') {
1053: $imgfile = $designs->{$img};
1.18 albertel 1054: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1055: } else {
1056: $imgfile = $defaults->{$img};
1057: }
1058: if ($imgfile) {
1.9 raeburn 1059: my ($showfile,$fullsize);
1060: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1061: my $urldir = $1;
1062: my $filename = $2;
1063: my @info = &Apache::lonnet::stat_file($designs->{$img});
1064: if (@info) {
1065: my $thumbfile = 'tn-'.$filename;
1066: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1067: if (@thumb) {
1068: $showfile = $urldir.'/'.$thumbfile;
1069: } else {
1070: $showfile = $imgfile;
1071: }
1072: } else {
1073: $showfile = '';
1074: }
1075: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1076: $showfile = $imgfile;
1.6 raeburn 1077: my $imgdir = $1;
1078: my $filename = $2;
1079: if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
1080: $showfile = "/$imgdir/tn-".$filename;
1081: } else {
1082: my $input = "/home/httpd/html".$imgfile;
1083: my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
1084: if (!-e $output) {
1.9 raeburn 1085: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1086: my ($fullwidth,$fullheight) = &check_dimensions($input);
1087: if ($fullwidth ne '' && $fullheight ne '') {
1088: if ($fullwidth > $width && $fullheight > $height) {
1089: my $size = $width.'x'.$height;
1090: system("convert -sample $size $input $output");
1091: $showfile = '/'.$imgdir.'/tn-'.$filename;
1092: }
1093: }
1.6 raeburn 1094: }
1095: }
1.16 raeburn 1096: }
1.6 raeburn 1097: if ($showfile) {
1.40 raeburn 1098: if ($showfile =~ m{^/(adm|res)/}) {
1099: if ($showfile =~ m{^/res/}) {
1100: my $local_showfile =
1101: &Apache::lonnet::filelocation('',$showfile);
1102: &Apache::lonnet::repcopy($local_showfile);
1103: }
1104: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1105: }
1106: if ($imgfile) {
1107: if ($imgfile =~ m{^/(adm|res)/}) {
1108: if ($imgfile =~ m{^/res/}) {
1109: my $local_imgfile =
1110: &Apache::lonnet::filelocation('',$imgfile);
1111: &Apache::lonnet::repcopy($local_imgfile);
1112: }
1113: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1114: } else {
1115: $fullsize = $imgfile;
1116: }
1117: }
1.41 raeburn 1118: $datatable .= '<td>';
1119: if ($img eq 'login') {
1.135 bisitz 1120: $datatable .= $login_hdr_pick;
1121: }
1.41 raeburn 1122: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1123: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1124: } else {
1125: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1126: &mt('Upload:');
1127: }
1128: } else {
1129: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1130: &mt('Upload:');
1131: }
1.9 raeburn 1132: if ($switchserver) {
1133: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1134: } else {
1.135 bisitz 1135: if ($img ne 'login') { # suppress file selection for Log-in header
1136: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1137: }
1.9 raeburn 1138: }
1139: $datatable .= '</td></tr>';
1.6 raeburn 1140: }
1141: $itemcount ++;
1142: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1143: $datatable .= '<tr'.$css_class.'>'.
1144: '<td>'.$choices->{'bgs'}.'</td>';
1145: my $bgs_def;
1146: foreach my $item (@{$bgs}) {
1147: if (!$is_custom->{$item}) {
1.70 raeburn 1148: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 1149: }
1150: }
1151: if ($bgs_def) {
1.8 raeburn 1152: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1153: } else {
1154: $datatable .= '<td> </td>';
1155: }
1156: $datatable .= '<td class="LC_right_item">'.
1157: '<table border="0"><tr>';
1158: foreach my $item (@{$bgs}) {
1159: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1160: $datatable .= '<td align="center">'.$link;
1161: if ($designs->{'bgs'}{$item}) {
1.30 raeburn 1162: $datatable .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';"> </span>';
1.6 raeburn 1163: }
1164: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.41 raeburn 1165: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1166: }
1167: $datatable .= '</tr></table></td></tr>';
1168: $itemcount ++;
1169: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1170: $datatable .= '<tr'.$css_class.'>'.
1171: '<td>'.$choices->{'links'}.'</td>';
1172: my $links_def;
1173: foreach my $item (@{$links}) {
1174: if (!$is_custom->{$item}) {
1.30 raeburn 1175: $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 1176: }
1177: }
1178: if ($links_def) {
1.8 raeburn 1179: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1180: } else {
1181: $datatable .= '<td> </td>';
1182: }
1183: $datatable .= '<td class="LC_right_item">'.
1184: '<table border="0"><tr>';
1185: foreach my $item (@{$links}) {
1.30 raeburn 1186: $datatable .= '<td align="center">'."\n".
1187: &color_pick($phase,$role,$item,$choices->{$item},
1188: $designs->{'links'}{$item});
1.6 raeburn 1189: if ($designs->{'links'}{$item}) {
1.30 raeburn 1190: $datatable.=' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';"> </span>';
1.6 raeburn 1191: }
1192: $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
1193: '" /></td>';
1194: }
1.30 raeburn 1195: $$rowtotal += $itemcount;
1.3 raeburn 1196: return $datatable;
1197: }
1198:
1.70 raeburn 1199: sub logo_display_options {
1200: my ($img,$defaults,$designs) = @_;
1201: my $checkedon;
1202: if (ref($defaults) eq 'HASH') {
1203: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1204: if ($defaults->{'showlogo'}{$img}) {
1205: $checkedon = 'checked="checked" ';
1206: }
1207: }
1208: }
1209: if (ref($designs) eq 'HASH') {
1210: if (ref($designs->{'showlogo'}) eq 'HASH') {
1211: if (defined($designs->{'showlogo'}{$img})) {
1212: if ($designs->{'showlogo'}{$img} == 0) {
1213: $checkedon = '';
1214: } elsif ($designs->{'showlogo'}{$img} == 1) {
1215: $checkedon = 'checked="checked" ';
1216: }
1217: }
1218: }
1219: }
1220: return '<br /><label> <input type="checkbox" name="'.
1221: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1222: &mt('show').'</label>'."\n";
1223: }
1224:
1.41 raeburn 1225: sub login_header_options {
1.135 bisitz 1226: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1227: my $output = '';
1.41 raeburn 1228: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1229: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1230: if (!$is_custom->{'textcol'}) {
1231: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1232: ' ';
1233: }
1234: if (!$is_custom->{'bgcol'}) {
1235: $output .= $choices->{'bgcol'}.': '.
1236: '<span id="css_'.$role.'_font" style="background-color: '.
1237: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1238: }
1239: $output .= '<br />';
1240: }
1241: $output .='<br />';
1242: return $output;
1243: }
1244:
1245: sub login_text_colors {
1246: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1247: my $color_menu = '<table border="0"><tr>';
1248: foreach my $item (@{$logintext}) {
1249: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1250: $color_menu .= '<td align="center">'.$link;
1251: if ($designs->{'logintext'}{$item}) {
1252: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1253: }
1254: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1255: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1256: '<td> </td>';
1257: }
1258: $color_menu .= '</tr></table><br />';
1259: return $color_menu;
1260: }
1261:
1262: sub image_changes {
1263: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1264: my $output;
1.135 bisitz 1265: if ($img eq 'login') {
1266: # suppress image for Log-in header
1267: } elsif (!$is_custom) {
1.70 raeburn 1268: if ($img ne 'domlogo') {
1.41 raeburn 1269: $output .= &mt('Default image:').'<br />';
1270: } else {
1271: $output .= &mt('Default in use:').'<br />';
1272: }
1273: }
1.135 bisitz 1274: if ($img eq 'login') { # suppress image for Log-in header
1275: $output .= '<td>'.$logincolors;
1.41 raeburn 1276: } else {
1.135 bisitz 1277: if ($img_import) {
1278: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1279: }
1280: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1281: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1282: if ($is_custom) {
1283: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1284: '<input type="checkbox" name="'.
1285: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1286: '</label> '.&mt('Replace:').'</span><br />';
1287: } else {
1288: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1289: }
1.41 raeburn 1290: }
1291: return $output;
1292: }
1293:
1.6 raeburn 1294: sub color_pick {
1295: my ($phase,$role,$item,$desc,$curcol) = @_;
1296: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1297: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1298: ');">'.$desc.'</a>';
1299: return $link;
1300: }
1301:
1.3 raeburn 1302: sub print_quotas {
1.86 raeburn 1303: my ($dom,$settings,$rowtotal,$action) = @_;
1304: my $context;
1305: if ($action eq 'quotas') {
1306: $context = 'tools';
1307: } else {
1308: $context = $action;
1309: }
1.101 raeburn 1310: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1311: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1312: my $typecount = 0;
1.101 raeburn 1313: my ($css_class,%titles);
1.86 raeburn 1314: if ($context eq 'requestcourses') {
1.98 raeburn 1315: @usertools = ('official','unofficial','community');
1.106 raeburn 1316: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1317: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1318: %titles = &courserequest_titles();
1.86 raeburn 1319: } else {
1320: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 1321: %titles = &tool_titles();
1.86 raeburn 1322: }
1.26 raeburn 1323: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1324: foreach my $type (@{$types}) {
1.72 raeburn 1325: my $currdefquota;
1.86 raeburn 1326: unless ($context eq 'requestcourses') {
1327: if (ref($settings) eq 'HASH') {
1328: if (ref($settings->{defaultquota}) eq 'HASH') {
1329: $currdefquota = $settings->{defaultquota}->{$type};
1330: } else {
1331: $currdefquota = $settings->{$type};
1332: }
1.78 raeburn 1333: }
1.72 raeburn 1334: }
1.3 raeburn 1335: if (defined($usertypes->{$type})) {
1336: $typecount ++;
1337: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1338: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1339: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1340: '<td class="LC_left_item">';
1.101 raeburn 1341: if ($context eq 'requestcourses') {
1342: $datatable .= '<table><tr>';
1343: }
1344: my %cell;
1.72 raeburn 1345: foreach my $item (@usertools) {
1.101 raeburn 1346: if ($context eq 'requestcourses') {
1347: my ($curroption,$currlimit);
1348: if (ref($settings) eq 'HASH') {
1349: if (ref($settings->{$item}) eq 'HASH') {
1350: $curroption = $settings->{$item}->{$type};
1351: if ($curroption =~ /^autolimit=(\d*)$/) {
1352: $currlimit = $1;
1353: }
1354: }
1355: }
1356: if (!$curroption) {
1357: $curroption = 'norequest';
1358: }
1359: $datatable .= '<th>'.$titles{$item}.'</th>';
1360: foreach my $option (@options) {
1361: my $val = $option;
1362: if ($option eq 'norequest') {
1363: $val = 0;
1364: }
1365: if ($option eq 'validate') {
1366: my $canvalidate = 0;
1367: if (ref($validations{$item}) eq 'HASH') {
1368: if ($validations{$item}{$type}) {
1369: $canvalidate = 1;
1370: }
1371: }
1372: next if (!$canvalidate);
1373: }
1374: my $checked = '';
1375: if ($option eq $curroption) {
1376: $checked = ' checked="checked"';
1377: } elsif ($option eq 'autolimit') {
1378: if ($curroption =~ /^autolimit/) {
1379: $checked = ' checked="checked"';
1380: }
1381: }
1382: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1383: '<input type="radio" name="crsreq_'.$item.
1384: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1385: $titles{$option}.'</label>';
1.101 raeburn 1386: if ($option eq 'autolimit') {
1.127 raeburn 1387: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1388: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1389: 'value="'.$currlimit.'" />';
1.101 raeburn 1390: }
1.127 raeburn 1391: $cell{$item} .= '</span> ';
1.103 raeburn 1392: if ($option eq 'autolimit') {
1.127 raeburn 1393: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1394: }
1.101 raeburn 1395: }
1396: } else {
1397: my $checked = 'checked="checked" ';
1398: if (ref($settings) eq 'HASH') {
1399: if (ref($settings->{$item}) eq 'HASH') {
1400: if ($settings->{$item}->{$type} == 0) {
1401: $checked = '';
1402: } elsif ($settings->{$item}->{$type} == 1) {
1403: $checked = 'checked="checked" ';
1404: }
1.78 raeburn 1405: }
1.72 raeburn 1406: }
1.101 raeburn 1407: $datatable .= '<span class="LC_nobreak"><label>'.
1408: '<input type="checkbox" name="'.$context.'_'.$item.
1409: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1410: '</label></span> ';
1.72 raeburn 1411: }
1.101 raeburn 1412: }
1413: if ($context eq 'requestcourses') {
1414: $datatable .= '</tr><tr>';
1415: foreach my $item (@usertools) {
1.106 raeburn 1416: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1417: }
1418: $datatable .= '</tr></table>';
1.72 raeburn 1419: }
1.86 raeburn 1420: $datatable .= '</td>';
1421: unless ($context eq 'requestcourses') {
1422: $datatable .=
1423: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1424: '<input type="text" name="quota_'.$type.
1.72 raeburn 1425: '" value="'.$currdefquota.
1.86 raeburn 1426: '" size="5" /> Mb</span></td>';
1427: }
1428: $datatable .= '</tr>';
1.3 raeburn 1429: }
1430: }
1431: }
1.86 raeburn 1432: unless ($context eq 'requestcourses') {
1433: $defaultquota = '20';
1434: if (ref($settings) eq 'HASH') {
1435: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1436: $defaultquota = $settings->{'defaultquota'}->{'default'};
1437: } elsif (defined($settings->{'default'})) {
1438: $defaultquota = $settings->{'default'};
1439: }
1.3 raeburn 1440: }
1441: }
1442: $typecount ++;
1443: $css_class = $typecount%2?' class="LC_odd_row"':'';
1444: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1445: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1446: '<td class="LC_left_item">';
1.101 raeburn 1447: if ($context eq 'requestcourses') {
1448: $datatable .= '<table><tr>';
1449: }
1450: my %defcell;
1.72 raeburn 1451: foreach my $item (@usertools) {
1.101 raeburn 1452: if ($context eq 'requestcourses') {
1453: my ($curroption,$currlimit);
1454: if (ref($settings) eq 'HASH') {
1455: if (ref($settings->{$item}) eq 'HASH') {
1456: $curroption = $settings->{$item}->{'default'};
1457: if ($curroption =~ /^autolimit=(\d*)$/) {
1458: $currlimit = $1;
1459: }
1460: }
1461: }
1462: if (!$curroption) {
1463: $curroption = 'norequest';
1464: }
1465: $datatable .= '<th>'.$titles{$item}.'</th>';
1466: foreach my $option (@options) {
1467: my $val = $option;
1468: if ($option eq 'norequest') {
1469: $val = 0;
1470: }
1471: if ($option eq 'validate') {
1472: my $canvalidate = 0;
1473: if (ref($validations{$item}) eq 'HASH') {
1474: if ($validations{$item}{'default'}) {
1475: $canvalidate = 1;
1476: }
1477: }
1478: next if (!$canvalidate);
1479: }
1480: my $checked = '';
1481: if ($option eq $curroption) {
1482: $checked = ' checked="checked"';
1483: } elsif ($option eq 'autolimit') {
1484: if ($curroption =~ /^autolimit/) {
1485: $checked = ' checked="checked"';
1486: }
1487: }
1488: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1489: '<input type="radio" name="crsreq_'.$item.
1490: '_default" value="'.$val.'"'.$checked.' />'.
1491: $titles{$option}.'</label>';
1492: if ($option eq 'autolimit') {
1.127 raeburn 1493: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1494: $item.'_limit_default" size="1" '.
1495: 'value="'.$currlimit.'" />';
1496: }
1.127 raeburn 1497: $defcell{$item} .= '</span> ';
1.104 raeburn 1498: if ($option eq 'autolimit') {
1.127 raeburn 1499: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1500: }
1.101 raeburn 1501: }
1502: } else {
1503: my $checked = 'checked="checked" ';
1504: if (ref($settings) eq 'HASH') {
1505: if (ref($settings->{$item}) eq 'HASH') {
1506: if ($settings->{$item}->{'default'} == 0) {
1507: $checked = '';
1508: } elsif ($settings->{$item}->{'default'} == 1) {
1509: $checked = 'checked="checked" ';
1510: }
1.78 raeburn 1511: }
1.72 raeburn 1512: }
1.101 raeburn 1513: $datatable .= '<span class="LC_nobreak"><label>'.
1514: '<input type="checkbox" name="'.$context.'_'.$item.
1515: '" value="default" '.$checked.'/>'.$titles{$item}.
1516: '</label></span> ';
1517: }
1518: }
1519: if ($context eq 'requestcourses') {
1520: $datatable .= '</tr><tr>';
1521: foreach my $item (@usertools) {
1.106 raeburn 1522: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1523: }
1.101 raeburn 1524: $datatable .= '</tr></table>';
1.72 raeburn 1525: }
1.86 raeburn 1526: $datatable .= '</td>';
1527: unless ($context eq 'requestcourses') {
1528: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1529: '<input type="text" name="defaultquota" value="'.
1530: $defaultquota.'" size="5" /> Mb</span></td>';
1531: }
1532: $datatable .= '</tr>';
1.72 raeburn 1533: $typecount ++;
1534: $css_class = $typecount%2?' class="LC_odd_row"':'';
1535: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1536: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1537: if ($context eq 'requestcourses') {
1.109 raeburn 1538: $datatable .= &mt('(overrides affiliation, if set)').
1539: '</td>'.
1540: '<td class="LC_left_item">'.
1541: '<table><tr>';
1.101 raeburn 1542: } else {
1.109 raeburn 1543: $datatable .= &mt('(overrides affiliation, if checked)').
1544: '</td>'.
1545: '<td class="LC_left_item" colspan="2">'.
1546: '<br />';
1.101 raeburn 1547: }
1548: my %advcell;
1.72 raeburn 1549: foreach my $item (@usertools) {
1.101 raeburn 1550: if ($context eq 'requestcourses') {
1551: my ($curroption,$currlimit);
1552: if (ref($settings) eq 'HASH') {
1553: if (ref($settings->{$item}) eq 'HASH') {
1554: $curroption = $settings->{$item}->{'_LC_adv'};
1555: if ($curroption =~ /^autolimit=(\d*)$/) {
1556: $currlimit = $1;
1557: }
1558: }
1559: }
1560: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1561: my $checked = '';
1562: if ($curroption eq '') {
1563: $checked = ' checked="checked"';
1564: }
1565: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1566: '<input type="radio" name="crsreq_'.$item.
1567: '__LC_adv" value=""'.$checked.' />'.
1568: &mt('No override set').'</label></span> ';
1.101 raeburn 1569: foreach my $option (@options) {
1570: my $val = $option;
1571: if ($option eq 'norequest') {
1572: $val = 0;
1573: }
1574: if ($option eq 'validate') {
1575: my $canvalidate = 0;
1576: if (ref($validations{$item}) eq 'HASH') {
1577: if ($validations{$item}{'_LC_adv'}) {
1578: $canvalidate = 1;
1579: }
1580: }
1581: next if (!$canvalidate);
1582: }
1583: my $checked = '';
1.104 raeburn 1584: if ($val eq $curroption) {
1.101 raeburn 1585: $checked = ' checked="checked"';
1586: } elsif ($option eq 'autolimit') {
1587: if ($curroption =~ /^autolimit/) {
1588: $checked = ' checked="checked"';
1589: }
1590: }
1591: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1592: '<input type="radio" name="crsreq_'.$item.
1593: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1594: $titles{$option}.'</label>';
1595: if ($option eq 'autolimit') {
1.127 raeburn 1596: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1597: $item.'_limit__LC_adv" size="1" '.
1598: 'value="'.$currlimit.'" />';
1599: }
1.127 raeburn 1600: $advcell{$item} .= '</span> ';
1.104 raeburn 1601: if ($option eq 'autolimit') {
1.127 raeburn 1602: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1603: }
1.101 raeburn 1604: }
1605: } else {
1606: my $checked = 'checked="checked" ';
1607: if (ref($settings) eq 'HASH') {
1608: if (ref($settings->{$item}) eq 'HASH') {
1609: if ($settings->{$item}->{'_LC_adv'} == 0) {
1610: $checked = '';
1611: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1612: $checked = 'checked="checked" ';
1613: }
1.79 raeburn 1614: }
1.72 raeburn 1615: }
1.101 raeburn 1616: $datatable .= '<span class="LC_nobreak"><label>'.
1617: '<input type="checkbox" name="'.$context.'_'.$item.
1618: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1619: '</label></span> ';
1620: }
1621: }
1622: if ($context eq 'requestcourses') {
1623: $datatable .= '</tr><tr>';
1624: foreach my $item (@usertools) {
1.106 raeburn 1625: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1626: }
1.101 raeburn 1627: $datatable .= '</tr></table>';
1.72 raeburn 1628: }
1.98 raeburn 1629: $datatable .= '</td></tr>';
1.30 raeburn 1630: $$rowtotal += $typecount;
1.3 raeburn 1631: return $datatable;
1632: }
1633:
1.102 raeburn 1634: sub print_courserequestmail {
1635: my ($dom,$settings,$rowtotal) = @_;
1.104 raeburn 1636: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1637: $now = time;
1638: $rows = 0;
1639: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1640: foreach my $server (keys(%dompersonnel)) {
1641: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1642: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1643: if (!grep(/^$uname:$udom$/,@domcoord)) {
1644: push(@domcoord,$uname.':'.$udom);
1645: }
1646: }
1647: }
1648: if (ref($settings) eq 'HASH') {
1649: if (ref($settings->{'notify'}) eq 'HASH') {
1650: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1651: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1652: }
1653: }
1654: }
1.104 raeburn 1655: if (@currapproval) {
1656: foreach my $dc (@currapproval) {
1.102 raeburn 1657: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1658: push(@domcoord,$dc);
1659: }
1660: }
1661: }
1662: @domcoord = sort(@domcoord);
1663: my $numinrow = 4;
1664: my $numdc = @domcoord;
1665: my $css_class = 'class="LC_odd_row"';
1666: $datatable = '<tr'.$css_class.'>'.
1667: ' <td>'.&mt('Receive notification of course requests requiring approval.').
1668: ' </td>'.
1669: ' <td class="LC_left_item">';
1670: if (@domcoord > 0) {
1671: $datatable .= '<table>';
1672: for (my $i=0; $i<$numdc; $i++) {
1673: my $rem = $i%($numinrow);
1674: if ($rem == 0) {
1675: if ($i > 0) {
1676: $datatable .= '</tr>';
1677: }
1678: $datatable .= '<tr>';
1679: $rows ++;
1680: }
1681: my $check = ' ';
1.104 raeburn 1682: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1683: $check = ' checked="checked" ';
1684: }
1685: my ($uname,$udom) = split(':',$domcoord[$i]);
1686: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1687: if ($i == $numdc-1) {
1688: my $colsleft = $numinrow-$rem;
1689: if ($colsleft > 1) {
1690: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1691: } else {
1692: $datatable .= '<td class="LC_left_item">';
1693: }
1694: } else {
1695: $datatable .= '<td class="LC_left_item">';
1696: }
1697: $datatable .= '<span class="LC_nobreak"><label>'.
1698: '<input type="checkbox" name="reqapprovalnotify" '.
1699: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1700: $fullname.'</label></span></td>';
1701: }
1702: $datatable .= '</tr></table>';
1703: } else {
1704: $datatable .= &mt('There are no active Domain Coordinators');
1705: $rows ++;
1706: }
1707: $datatable .='</td></tr>';
1708: $$rowtotal += $rows;
1709: return $datatable;
1710: }
1711:
1.3 raeburn 1712: sub print_autoenroll {
1.30 raeburn 1713: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1714: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1715: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1716: if (ref($settings) eq 'HASH') {
1717: if (exists($settings->{'run'})) {
1718: if ($settings->{'run'} eq '0') {
1719: $runoff = ' checked="checked" ';
1720: $runon = ' ';
1721: } else {
1722: $runon = ' checked="checked" ';
1723: $runoff = ' ';
1724: }
1725: } else {
1726: if ($autorun) {
1727: $runon = ' checked="checked" ';
1728: $runoff = ' ';
1729: } else {
1730: $runoff = ' checked="checked" ';
1731: $runon = ' ';
1732: }
1733: }
1.129 raeburn 1734: if (exists($settings->{'co-owners'})) {
1735: if ($settings->{'co-owners'} eq '0') {
1736: $coownersoff = ' checked="checked" ';
1737: $coownerson = ' ';
1738: } else {
1739: $coownerson = ' checked="checked" ';
1740: $coownersoff = ' ';
1741: }
1742: } else {
1743: $coownersoff = ' checked="checked" ';
1744: $coownerson = ' ';
1745: }
1.3 raeburn 1746: if (exists($settings->{'sender_domain'})) {
1747: $defdom = $settings->{'sender_domain'};
1748: }
1.14 raeburn 1749: } else {
1750: if ($autorun) {
1751: $runon = ' checked="checked" ';
1752: $runoff = ' ';
1753: } else {
1754: $runoff = ' checked="checked" ';
1755: $runon = ' ';
1756: }
1.3 raeburn 1757: }
1758: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1759: my $notif_sender;
1760: if (ref($settings) eq 'HASH') {
1761: $notif_sender = $settings->{'sender_uname'};
1762: }
1.3 raeburn 1763: my $datatable='<tr class="LC_odd_row">'.
1764: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1765: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1766: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1767: $runon.' value="1" />'.&mt('Yes').'</label> '.
1768: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1769: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1770: '</tr><tr>'.
1771: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1772: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1773: &mt('username').': '.
1774: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1775: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 1776: ': '.$domform.'</span></td></tr>'.
1777: '<tr class="LC_odd_row">'.
1778: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
1779: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1780: '<input type="radio" name="autoassign_coowners"'.
1781: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
1782: '<label><input type="radio" name="autoassign_coowners"'.
1783: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1784: '</tr>';
1785: $$rowtotal += 3;
1.3 raeburn 1786: return $datatable;
1787: }
1788:
1789: sub print_autoupdate {
1.30 raeburn 1790: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1791: my $datatable;
1792: if ($position eq 'top') {
1793: my $updateon = ' ';
1794: my $updateoff = ' checked="checked" ';
1795: my $classlistson = ' ';
1796: my $classlistsoff = ' checked="checked" ';
1797: if (ref($settings) eq 'HASH') {
1798: if ($settings->{'run'} eq '1') {
1799: $updateon = $updateoff;
1800: $updateoff = ' ';
1801: }
1802: if ($settings->{'classlists'} eq '1') {
1803: $classlistson = $classlistsoff;
1804: $classlistsoff = ' ';
1805: }
1806: }
1807: my %title = (
1808: run => 'Auto-update active?',
1809: classlists => 'Update information in classlists?',
1810: );
1811: $datatable = '<tr class="LC_odd_row">'.
1812: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1813: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1814: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1815: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1816: '<label><input type="radio" name="autoupdate_run"'.
1817: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1818: '</tr><tr>'.
1819: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1820: '<td class="LC_right_item"><span class="LC_nobreak">'.
1821: '<label><input type="radio" name="classlists"'.
1822: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1823: '<label><input type="radio" name="classlists"'.
1824: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1825: '</tr>';
1.30 raeburn 1826: $$rowtotal += 2;
1.131 raeburn 1827: } elsif ($position eq 'middle') {
1828: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1829: my $numinrow = 3;
1830: my $locknamesettings;
1831: $datatable .= &insttypes_row($settings,$types,$usertypes,
1832: $dom,$numinrow,$othertitle,
1833: 'lockablenames');
1834: $$rowtotal ++;
1.3 raeburn 1835: } else {
1.44 raeburn 1836: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 1837: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 1838: 'permanentemail','id');
1.33 raeburn 1839: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1840: my $numrows = 0;
1.26 raeburn 1841: if (ref($types) eq 'ARRAY') {
1842: if (@{$types} > 0) {
1843: $datatable =
1844: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1845: \@fields,$types,\$numrows);
1.30 raeburn 1846: $$rowtotal += @{$types};
1.26 raeburn 1847: }
1.3 raeburn 1848: }
1849: $datatable .=
1850: &usertype_update_row($settings,{'default' => $othertitle},
1851: \%fieldtitles,\@fields,['default'],
1852: \$numrows);
1.30 raeburn 1853: $$rowtotal ++;
1.3 raeburn 1854: }
1855: return $datatable;
1856: }
1857:
1.125 raeburn 1858: sub print_autocreate {
1859: my ($dom,$settings,$rowtotal) = @_;
1860: my (%createon,%createoff);
1861: my $curr_dc;
1862: my @types = ('xml','req');
1863: if (ref($settings) eq 'HASH') {
1864: foreach my $item (@types) {
1865: $createoff{$item} = ' checked="checked" ';
1866: $createon{$item} = ' ';
1867: if (exists($settings->{$item})) {
1868: if ($settings->{$item}) {
1869: $createon{$item} = ' checked="checked" ';
1870: $createoff{$item} = ' ';
1871: }
1872: }
1873: }
1874: $curr_dc = $settings->{'xmldc'};
1875: } else {
1876: foreach my $item (@types) {
1877: $createoff{$item} = ' checked="checked" ';
1878: $createon{$item} = ' ';
1879: }
1880: }
1881: $$rowtotal += 2;
1882: my $datatable='<tr class="LC_odd_row">'.
1883: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
1884: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1885: '<input type="radio" name="autocreate_xml"'.
1886: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
1887: '<label><input type="radio" name="autocreate_xml"'.
1.138.2.8 raeburn 1888: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
1889: '</td></tr><tr>'.
1890: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
1891: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1892: '<input type="radio" name="autocreate_req"'.
1893: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
1894: '<label><input type="radio" name="autocreate_req"'.
1895: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 1896: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
1897: if ($numdc > 1) {
1.138.2.8 raeburn 1898: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
1899: &mt('Course creation processed as: (choose Dom. Coord.)').
1900: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 1901: $$rowtotal ++ ;
1902: } else {
1.138.2.8 raeburn 1903: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 1904: }
1905: return $datatable;
1906: }
1907:
1.23 raeburn 1908: sub print_directorysrch {
1.30 raeburn 1909: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1910: my $srchon = ' ';
1911: my $srchoff = ' checked="checked" ';
1.25 raeburn 1912: my ($exacton,$containson,$beginson);
1.24 raeburn 1913: my $localon = ' ';
1914: my $localoff = ' checked="checked" ';
1.23 raeburn 1915: if (ref($settings) eq 'HASH') {
1916: if ($settings->{'available'} eq '1') {
1917: $srchon = $srchoff;
1918: $srchoff = ' ';
1919: }
1.24 raeburn 1920: if ($settings->{'localonly'} eq '1') {
1921: $localon = $localoff;
1922: $localoff = ' ';
1923: }
1.25 raeburn 1924: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1925: foreach my $type (@{$settings->{'searchtypes'}}) {
1926: if ($type eq 'exact') {
1927: $exacton = ' checked="checked" ';
1928: } elsif ($type eq 'contains') {
1929: $containson = ' checked="checked" ';
1930: } elsif ($type eq 'begins') {
1931: $beginson = ' checked="checked" ';
1932: }
1933: }
1934: } else {
1935: if ($settings->{'searchtypes'} eq 'exact') {
1936: $exacton = ' checked="checked" ';
1937: } elsif ($settings->{'searchtypes'} eq 'contains') {
1938: $containson = ' checked="checked" ';
1939: } elsif ($settings->{'searchtypes'} eq 'specify') {
1940: $exacton = ' checked="checked" ';
1941: $containson = ' checked="checked" ';
1942: }
1.23 raeburn 1943: }
1944: }
1945: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 1946: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 1947:
1948: my $numinrow = 4;
1.26 raeburn 1949: my $cansrchrow = 0;
1.23 raeburn 1950: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1951: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 1952: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1953: '<input type="radio" name="dirsrch_available"'.
1954: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1955: '<label><input type="radio" name="dirsrch_available"'.
1956: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1957: '</tr><tr>'.
1.30 raeburn 1958: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 1959: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1960: '<input type="radio" name="dirsrch_localonly"'.
1961: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1962: '<label><input type="radio" name="dirsrch_localonly"'.
1963: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 1964: '</tr>';
1.30 raeburn 1965: $$rowtotal += 2;
1.26 raeburn 1966: if (ref($usertypes) eq 'HASH') {
1967: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 1968: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1969: $numinrow,$othertitle,'cansearch');
1.26 raeburn 1970: $cansrchrow = 1;
1971: }
1972: }
1973: if ($cansrchrow) {
1.30 raeburn 1974: $$rowtotal ++;
1.26 raeburn 1975: $datatable .= '<tr>';
1976: } else {
1977: $datatable .= '<tr class="LC_odd_row">';
1978: }
1.30 raeburn 1979: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
1980: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 1981: foreach my $title (@{$titleorder}) {
1982: if (defined($searchtitles->{$title})) {
1983: my $check = ' ';
1.93 raeburn 1984: if (ref($settings) eq 'HASH') {
1.39 raeburn 1985: if (ref($settings->{'searchby'}) eq 'ARRAY') {
1986: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
1987: $check = ' checked="checked" ';
1988: }
1.25 raeburn 1989: }
1990: }
1991: $datatable .= '<td class="LC_left_item">'.
1992: '<span class="LC_nobreak"><label>'.
1993: '<input type="checkbox" name="searchby" '.
1994: 'value="'.$title.'"'.$check.'/>'.
1995: $searchtitles->{$title}.'</label></span></td>';
1996: }
1997: }
1.26 raeburn 1998: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 1999: $$rowtotal ++;
1.26 raeburn 2000: if ($cansrchrow) {
2001: $datatable .= '<tr class="LC_odd_row">';
2002: } else {
2003: $datatable .= '<tr>';
2004: }
1.30 raeburn 2005: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2006: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2007: '<span class="LC_nobreak"><label>'.
2008: '<input type="checkbox" name="searchtypes" '.
2009: $exacton.' value="exact" />'.&mt('Exact match').
2010: '</label> '.
2011: '<label><input type="checkbox" name="searchtypes" '.
2012: $beginson.' value="begins" />'.&mt('Begins with').
2013: '</label> '.
2014: '<label><input type="checkbox" name="searchtypes" '.
2015: $containson.' value="contains" />'.&mt('Contains').
2016: '</label></span></td></tr>';
1.30 raeburn 2017: $$rowtotal ++;
1.25 raeburn 2018: return $datatable;
2019: }
2020:
1.28 raeburn 2021: sub print_contacts {
1.30 raeburn 2022: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2023: my $datatable;
2024: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2025: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2026: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2027: 'requestsmail');
1.28 raeburn 2028: foreach my $type (@mailings) {
2029: $otheremails{$type} = '';
2030: }
1.134 raeburn 2031: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2032: if (ref($settings) eq 'HASH') {
2033: foreach my $item (@contacts) {
2034: if (exists($settings->{$item})) {
2035: $to{$item} = $settings->{$item};
2036: }
2037: }
2038: foreach my $type (@mailings) {
2039: if (exists($settings->{$type})) {
2040: if (ref($settings->{$type}) eq 'HASH') {
2041: foreach my $item (@contacts) {
2042: if ($settings->{$type}{$item}) {
2043: $checked{$type}{$item} = ' checked="checked" ';
2044: }
2045: }
2046: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2047: if ($type eq 'helpdeskmail') {
2048: $bccemails{$type} = $settings->{$type}{'bcc'};
2049: }
1.28 raeburn 2050: }
1.89 raeburn 2051: } elsif ($type eq 'lonstatusmail') {
2052: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2053: }
2054: }
2055: } else {
2056: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2057: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2058: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2059: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2060: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2061: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2062: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2063: }
2064: my ($titles,$short_titles) = &contact_titles();
2065: my $rownum = 0;
2066: my $css_class;
2067: foreach my $item (@contacts) {
1.69 raeburn 2068: $rownum ++;
2069: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2070: $datatable .= '<tr'.$css_class.'>'.
2071: '<td><span class="LC_nobreak">'.$titles->{$item}.
2072: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2073: '<input type="text" name="'.$item.'" value="'.
2074: $to{$item}.'" /></td></tr>';
2075: }
2076: foreach my $type (@mailings) {
1.69 raeburn 2077: $rownum ++;
2078: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2079: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2080: '<td><span class="LC_nobreak">'.
2081: $titles->{$type}.': </span></td>'.
1.28 raeburn 2082: '<td class="LC_left_item">'.
2083: '<span class="LC_nobreak">';
2084: foreach my $item (@contacts) {
2085: $datatable .= '<label>'.
2086: '<input type="checkbox" name="'.$type.'"'.
2087: $checked{$type}{$item}.
2088: ' value="'.$item.'" />'.$short_titles->{$item}.
2089: '</label> ';
2090: }
2091: $datatable .= '</span><br />'.&mt('Others').': '.
2092: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2093: 'value="'.$otheremails{$type}.'" />';
2094: if ($type eq 'helpdeskmail') {
1.136 raeburn 2095: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2096: '<input type="text" name="'.$type.'_bcc" '.
2097: 'value="'.$bccemails{$type}.'" />';
2098: }
2099: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2100: }
1.30 raeburn 2101: $$rowtotal += $rownum;
1.28 raeburn 2102: return $datatable;
2103: }
2104:
1.118 jms 2105: sub print_helpsettings {
1.122 jms 2106:
2107: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
2108: my ($css_class,$datatable);
2109:
2110: my $switchserver = &check_switchserver($dom,$confname);
2111:
2112: my $itemcount = 1;
2113:
2114: if ($position eq 'top') {
2115:
2116: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2117:
2118: %choices =
2119: &Apache::lonlocal::texthash (
2120: submitbugs => 'Display "Submit a bug" link?',
2121: );
2122:
2123: %defaultchecked = ('submitbugs' => 'on');
2124:
2125: @toggles = ('submitbugs',);
2126:
2127: foreach my $item (@toggles) {
2128: if ($defaultchecked{$item} eq 'on') {
2129: $checkedon{$item} = ' checked="checked" ';
2130: $checkedoff{$item} = ' ';
2131: } elsif ($defaultchecked{$item} eq 'off') {
2132: $checkedoff{$item} = ' checked="checked" ';
2133: $checkedon{$item} = ' ';
2134: }
2135: }
2136:
2137: if (ref($settings) eq 'HASH') {
2138: foreach my $item (@toggles) {
2139: if ($settings->{$item} eq '1') {
2140: $checkedon{$item} = ' checked="checked" ';
2141: $checkedoff{$item} = ' ';
2142: } elsif ($settings->{$item} eq '0') {
2143: $checkedoff{$item} = ' checked="checked" ';
2144: $checkedon{$item} = ' ';
2145: }
2146: }
2147: }
2148:
2149: foreach my $item (@toggles) {
2150: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2151: $datatable .=
2152: '<tr'.$css_class.'>
2153: <td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
2154: <td><span class="LC_nobreak"> </span></td>
2155: <td class="LC_right_item"><span class="LC_nobreak">
2156: <label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>
2157: <label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2158: '</span></td>'.
2159: '</tr>';
2160: $itemcount ++;
2161: }
2162:
2163: } else {
2164:
2165: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2166:
2167: $datatable .= '<tr'.$css_class.'>';
2168:
2169: if (ref($settings) eq 'HASH') {
2170: if ($settings->{'loginhelpurl'} ne '') {
2171: my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
2172: $datatable .= '<td width="33%"><span class="LC_left_item"><label><a href="'.$settings->{'loginhelpurl'}.'" target="_blank">'.&mt('Custom Login Page Help File In Use').'</a></label></span></td>';
2173: $datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
2174: } else {
2175: $datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
2176: $datatable .= '<td width="33%"><span class="LC_right_item"> </span></td>';
2177: }
2178: } else {
2179: $datatable .= '<td><span class="LC_left_item"> </span></td>';
2180: $datatable .= '<td><span class="LC_right_item"> </span></td>';
2181: }
2182:
2183: $datatable .= '<td width="33%"><span class="LC_right_item">';
2184: if ($switchserver) {
2185: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2186: } else {
2187: $datatable .= &mt('Upload Custom Login Page Help File:');
2188: $datatable .='<input type="file" name="loginhelpurl" />';
2189: }
2190: $datatable .= '</span></td></tr>';
2191:
2192: }
2193:
2194: return $datatable;
2195:
1.121 raeburn 2196: }
2197:
1.122 jms 2198:
1.121 raeburn 2199: sub radiobutton_prefs {
2200: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2201: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2202: (ref($choices) eq 'HASH'));
2203:
2204: my (%checkedon,%checkedoff,$datatable,$css_class);
2205:
2206: foreach my $item (@{$toggles}) {
2207: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2208: $checkedon{$item} = ' checked="checked" ';
2209: $checkedoff{$item} = ' ';
1.121 raeburn 2210: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2211: $checkedoff{$item} = ' checked="checked" ';
2212: $checkedon{$item} = ' ';
2213: }
2214: }
2215: if (ref($settings) eq 'HASH') {
1.121 raeburn 2216: foreach my $item (@{$toggles}) {
1.118 jms 2217: if ($settings->{$item} eq '1') {
2218: $checkedon{$item} = ' checked="checked" ';
2219: $checkedoff{$item} = ' ';
2220: } elsif ($settings->{$item} eq '0') {
2221: $checkedoff{$item} = ' checked="checked" ';
2222: $checkedon{$item} = ' ';
2223: }
2224: }
1.121 raeburn 2225: }
2226: foreach my $item (@{$toggles}) {
1.118 jms 2227: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2228: $datatable .=
2229: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2230: '</span></td>'.
2231: '<td class="LC_right_item"><span class="LC_nobreak">'.
2232: '<label><input type="radio" name="'.
2233: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2234: '</label> <label><input type="radio" name="'.$item.'" '.
2235: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2236: '</span></td>'.
2237: '</tr>';
2238: $itemcount ++;
1.121 raeburn 2239: }
2240: return ($datatable,$itemcount);
2241: }
2242:
2243: sub print_coursedefaults {
1.138.2.2 raeburn 2244: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2245: my ($css_class,$datatable);
2246: my $itemcount = 1;
1.138.2.2 raeburn 2247: if ($position eq 'top') {
2248: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2249: %choices =
2250: &Apache::lonlocal::texthash (
2251: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2252: );
2253: %defaultchecked = ('canuse_pdfforms' => 'off');
2254: @toggles = ('canuse_pdfforms',);
2255: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2256: \%choices,$itemcount);
1.138.2.2 raeburn 2257: $$rowtotal += $itemcount;
2258: } else {
2259: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2260: my %choices =
2261: &Apache::lonlocal::texthash (
2262: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2263: );
2264: my $currdefresponder;
2265: if (ref($settings) eq 'HASH') {
2266: $currdefresponder = $settings->{'anonsurvey_threshold'};
2267: }
2268: if (!$currdefresponder) {
2269: $currdefresponder = 10;
2270: } elsif ($currdefresponder < 1) {
2271: $currdefresponder = 1;
2272: }
2273: $datatable .=
2274: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2275: '</span></td>'.
2276: '<td class="LC_right_item"><span class="LC_nobreak">'.
2277: '<input type="text" name="anonsurvey_threshold"'.
2278: ' value="'.$currdefresponder.'" size="5" /></span>'.
2279: '</td></tr>';
2280: }
1.121 raeburn 2281: return $datatable;
1.118 jms 2282: }
2283:
1.137 raeburn 2284: sub print_usersessions {
2285: my ($position,$dom,$settings,$rowtotal) = @_;
2286: my ($css_class,$datatable,%checked,%choices);
1.138.2.4 raeburn 2287: my (%by_ip,%by_location,@intdoms);
2288: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
2289: if (keys(%by_location) == 0) {
2290: if ($position eq 'top') {
2291: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
2292: &mt('Nothing to set here, as the cluster to which this domain belongs only contains this institution.');
2293: }
2294: }
1.137 raeburn 2295: my %lt = &usersession_titles();
2296: my $itemcount = 1;
1.138.2.4 raeburn 2297: my $numinrow = 5;
1.137 raeburn 2298: my $prefix;
2299: my @types;
2300: if ($position eq 'top') {
2301: $prefix = 'hosted';
2302: @types = ('excludedomain','includedomain');
2303: } else {
2304: $prefix = 'remote';
2305: @types = ('version','excludedomain','includedomain');
1.138 raeburn 2306: }
1.137 raeburn 2307: my (%current,%checkedon,%checkedoff);
2308: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 2309: my @locations = sort(keys(%by_location));
1.137 raeburn 2310: foreach my $type (@types) {
2311: $checkedon{$type} = '';
2312: $checkedoff{$type} = ' checked="checked"';
2313: }
2314: if (ref($settings) eq 'HASH') {
2315: if (ref($settings->{$prefix}) eq 'HASH') {
2316: foreach my $key (keys(%{$settings->{$prefix}})) {
2317: $current{$key} = $settings->{$prefix}{$key};
2318: if ($key eq 'version') {
2319: if ($current{$key} ne '') {
2320: $checkedon{$key} = ' checked="checked"';
2321: $checkedoff{$key} = '';
2322: }
2323: } elsif (ref($current{$key}) eq 'ARRAY') {
2324: $checkedon{$key} = ' checked="checked"';
2325: $checkedoff{$key} = '';
2326: }
2327: }
2328: }
2329: }
2330: foreach my $type (@types) {
1.138.2.4 raeburn 2331: next if ($type ne 'version' && !@locations);
1.137 raeburn 2332: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2333: $datatable .= '<tr'.$css_class.'>
2334: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2335: <span class="LC_nobreak">
2336: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2337: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2338: if ($type eq 'version') {
2339: my $selector = '<select name="'.$prefix.'_version">';
2340: foreach my $version (@lcversions) {
2341: my $selected = '';
2342: if ($current{'version'} eq $version) {
2343: $selected = ' selected="selected"';
2344: }
2345: $selector .= ' <option value="'.$version.'"'.
2346: $selected.'>'.$version.'</option>';
2347: }
2348: $selector .= '</select> ';
2349: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2350: } else {
2351: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2352: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2353: ' />'.(' 'x2).
2354: '<input type="button" value="'.&mt('uncheck all').'" '.
2355: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2356: "\n".
2357: '</div><div><table>';
2358: my $rem;
1.138 raeburn 2359: for (my $i=0; $i<@locations; $i++) {
2360: my ($showloc,$value,$checkedtype);
2361: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2362: my $ip = $by_location{$locations[$i]}->[0];
2363: if (ref($by_ip{$ip}) eq 'ARRAY') {
2364: $value = join(':',@{$by_ip{$ip}});
2365: $showloc = join(', ',@{$by_ip{$ip}});
2366: if (ref($current{$type}) eq 'ARRAY') {
2367: foreach my $loc (@{$by_ip{$ip}}) {
2368: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2369: $checkedtype = ' checked="checked"';
2370: last;
2371: }
2372: }
2373: }
1.137 raeburn 2374: }
2375: }
2376: $rem = $i%($numinrow);
2377: if ($rem == 0) {
2378: if ($i > 0) {
2379: $datatable .= '</tr>';
2380: }
2381: $datatable .= '<tr>';
2382: }
2383: $datatable .= '<td class="LC_left_item">'.
2384: '<span class="LC_nobreak"><label>'.
2385: '<input type="checkbox" name="'.$prefix.'_'.$type.
1.138 raeburn 2386: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
1.137 raeburn 2387: '</label></span></td>';
2388: }
1.138 raeburn 2389: $rem = @locations%($numinrow);
1.137 raeburn 2390: my $colsleft = $numinrow - $rem;
2391: if ($colsleft > 1 ) {
2392: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2393: ' </td>';
2394: } elsif ($colsleft == 1) {
2395: $datatable .= '<td class="LC_left_item"> </td>';
2396: }
2397: $datatable .= '</tr></table>';
2398: }
2399: $datatable .= '</td></tr>';
2400: $itemcount ++;
2401: }
2402: $$rowtotal += $itemcount;
2403: return $datatable;
2404: }
2405:
1.138 raeburn 2406: sub build_location_hashes {
2407: my ($intdoms,$by_ip,$by_location) = @_;
2408: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2409: (ref($by_location) eq 'HASH'));
2410: my %iphost = &Apache::lonnet::get_iphost();
2411: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2412: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2413: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2414: foreach my $id (@{$iphost{$primary_ip}}) {
2415: my $intdom = &Apache::lonnet::internet_dom($id);
2416: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2417: push(@{$intdoms},$intdom);
2418: }
2419: }
2420: }
2421: foreach my $ip (keys(%iphost)) {
2422: if (ref($iphost{$ip}) eq 'ARRAY') {
2423: foreach my $id (@{$iphost{$ip}}) {
2424: my $location = &Apache::lonnet::internet_dom($id);
2425: if ($location) {
2426: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2427: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2428: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2429: push(@{$by_ip->{$ip}},$location);
2430: }
2431: } else {
2432: $by_ip->{$ip} = [$location];
2433: }
2434: }
2435: }
2436: }
2437: }
2438: foreach my $ip (sort(keys(%{$by_ip}))) {
2439: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2440: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2441: my $first = $by_ip->{$ip}->[0];
2442: if (ref($by_location->{$first}) eq 'ARRAY') {
2443: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2444: push(@{$by_location->{$first}},$ip);
2445: }
2446: } else {
2447: $by_location->{$first} = [$ip];
2448: }
2449: }
2450: }
2451: return;
2452: }
2453:
1.28 raeburn 2454: sub contact_titles {
2455: my %titles = &Apache::lonlocal::texthash (
2456: 'supportemail' => 'Support E-mail address',
1.69 raeburn 2457: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 2458: 'errormail' => 'Error reports to be e-mailed to',
2459: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 2460: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
2461: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 2462: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 2463: );
2464: my %short_titles = &Apache::lonlocal::texthash (
2465: adminemail => 'Admin E-mail address',
2466: supportemail => 'Support E-mail',
2467: );
2468: return (\%titles,\%short_titles);
2469: }
2470:
1.72 raeburn 2471: sub tool_titles {
2472: my %titles = &Apache::lonlocal::texthash (
1.90 weissno 2473: aboutme => 'Personal Information Page',
1.86 raeburn 2474: blog => 'Blog',
2475: portfolio => 'Portfolio',
1.88 bisitz 2476: official => 'Official courses (with institutional codes)',
2477: unofficial => 'Unofficial courses',
1.98 raeburn 2478: community => 'Communities',
1.86 raeburn 2479: );
1.72 raeburn 2480: return %titles;
2481: }
2482:
1.101 raeburn 2483: sub courserequest_titles {
2484: my %titles = &Apache::lonlocal::texthash (
2485: official => 'Official',
2486: unofficial => 'Unofficial',
2487: community => 'Communities',
2488: norequest => 'Not allowed',
1.104 raeburn 2489: approval => 'Approval by Dom. Coord.',
1.101 raeburn 2490: validate => 'With validation',
2491: autolimit => 'Numerical limit',
1.103 raeburn 2492: unlimited => '(blank for unlimited)',
1.101 raeburn 2493: );
2494: return %titles;
2495: }
2496:
2497: sub courserequest_conditions {
2498: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 2499: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 2500: validate => '(Processing of request subject to instittutional validation).',
2501: );
2502: return %conditions;
2503: }
2504:
2505:
1.27 raeburn 2506: sub print_usercreation {
1.30 raeburn 2507: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 2508: my $numinrow = 4;
1.28 raeburn 2509: my $datatable;
2510: if ($position eq 'top') {
1.30 raeburn 2511: $$rowtotal ++;
1.34 raeburn 2512: my $rowcount = 0;
1.32 raeburn 2513: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 2514: if (ref($rules) eq 'HASH') {
2515: if (keys(%{$rules}) > 0) {
1.32 raeburn 2516: $datatable .= &user_formats_row('username',$settings,$rules,
2517: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 2518: $$rowtotal ++;
1.32 raeburn 2519: $rowcount ++;
2520: }
2521: }
2522: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
2523: if (ref($idrules) eq 'HASH') {
2524: if (keys(%{$idrules}) > 0) {
2525: $datatable .= &user_formats_row('id',$settings,$idrules,
2526: $idruleorder,$numinrow,$rowcount);
2527: $$rowtotal ++;
2528: $rowcount ++;
1.28 raeburn 2529: }
2530: }
1.43 raeburn 2531: my ($emailrules,$emailruleorder) =
2532: &Apache::lonnet::inst_userrules($dom,'email');
2533: if (ref($emailrules) eq 'HASH') {
2534: if (keys(%{$emailrules}) > 0) {
2535: $datatable .= &user_formats_row('email',$settings,$emailrules,
2536: $emailruleorder,$numinrow,$rowcount);
2537: $$rowtotal ++;
2538: $rowcount ++;
2539: }
2540: }
1.39 raeburn 2541: if ($rowcount == 0) {
2542: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
2543: $$rowtotal ++;
2544: $rowcount ++;
2545: }
1.34 raeburn 2546: } elsif ($position eq 'middle') {
1.100 raeburn 2547: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 2548: my ($rules,$ruleorder) =
2549: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 2550: my %lt = &usercreation_types();
2551: my %checked;
1.50 raeburn 2552: my @selfcreate;
1.34 raeburn 2553: if (ref($settings) eq 'HASH') {
2554: if (ref($settings->{'cancreate'}) eq 'HASH') {
2555: foreach my $item (@creators) {
2556: $checked{$item} = $settings->{'cancreate'}{$item};
2557: }
1.50 raeburn 2558: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
2559: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
2560: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
2561: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
2562: @selfcreate = ('email','login','sso');
2563: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
2564: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
2565: }
2566: }
1.34 raeburn 2567: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
2568: foreach my $item (@creators) {
2569: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
2570: $checked{$item} = 'none';
2571: }
2572: }
2573: }
2574: }
2575: my $rownum = 0;
2576: foreach my $item (@creators) {
2577: $rownum ++;
1.50 raeburn 2578: if ($item ne 'selfcreate') {
2579: if ($checked{$item} eq '') {
1.43 raeburn 2580: $checked{$item} = 'any';
2581: }
1.34 raeburn 2582: }
2583: my $css_class;
2584: if ($rownum%2) {
2585: $css_class = '';
2586: } else {
2587: $css_class = ' class="LC_odd_row" ';
2588: }
2589: $datatable .= '<tr'.$css_class.'>'.
2590: '<td><span class="LC_nobreak">'.$lt{$item}.
2591: '</span></td><td align="right">';
1.50 raeburn 2592: my @options;
1.45 raeburn 2593: if ($item eq 'selfcreate') {
1.43 raeburn 2594: push(@options,('email','login','sso'));
2595: } else {
1.50 raeburn 2596: @options = ('any');
1.43 raeburn 2597: if (ref($rules) eq 'HASH') {
2598: if (keys(%{$rules}) > 0) {
2599: push(@options,('official','unofficial'));
2600: }
1.37 raeburn 2601: }
1.50 raeburn 2602: push(@options,'none');
1.37 raeburn 2603: }
2604: foreach my $option (@options) {
1.50 raeburn 2605: my $type = 'radio';
1.34 raeburn 2606: my $check = ' ';
1.50 raeburn 2607: if ($item eq 'selfcreate') {
2608: $type = 'checkbox';
2609: if (grep(/^\Q$option\E$/,@selfcreate)) {
2610: $check = ' checked="checked" ';
2611: }
2612: } else {
2613: if ($checked{$item} eq $option) {
2614: $check = ' checked="checked" ';
2615: }
1.34 raeburn 2616: }
2617: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 2618: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 2619: $item.'" value="'.$option.'"'.$check.'/> '.
2620: $lt{$option}.'</label> </span>';
2621: }
2622: $datatable .= '</td></tr>';
2623: }
1.93 raeburn 2624: my ($othertitle,$usertypes,$types) =
2625: &Apache::loncommon::sorted_inst_types($dom);
2626: if (ref($usertypes) eq 'HASH') {
2627: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 2628: my $createsettings;
2629: if (ref($settings) eq 'HASH') {
2630: $createsettings = $settings->{cancreate};
2631: }
2632: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 2633: $dom,$numinrow,$othertitle,
2634: 'statustocreate');
2635: $$rowtotal ++;
2636: }
2637: }
1.28 raeburn 2638: } else {
2639: my @contexts = ('author','course','domain');
2640: my @authtypes = ('int','krb4','krb5','loc');
2641: my %checked;
2642: if (ref($settings) eq 'HASH') {
2643: if (ref($settings->{'authtypes'}) eq 'HASH') {
2644: foreach my $item (@contexts) {
2645: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
2646: foreach my $auth (@authtypes) {
2647: if ($settings->{'authtypes'}{$item}{$auth}) {
2648: $checked{$item}{$auth} = ' checked="checked" ';
2649: }
2650: }
2651: }
2652: }
1.27 raeburn 2653: }
1.35 raeburn 2654: } else {
2655: foreach my $item (@contexts) {
1.36 raeburn 2656: foreach my $auth (@authtypes) {
1.35 raeburn 2657: $checked{$item}{$auth} = ' checked="checked" ';
2658: }
2659: }
1.27 raeburn 2660: }
1.28 raeburn 2661: my %title = &context_names();
2662: my %authname = &authtype_names();
2663: my $rownum = 0;
2664: my $css_class;
2665: foreach my $item (@contexts) {
2666: if ($rownum%2) {
2667: $css_class = '';
2668: } else {
2669: $css_class = ' class="LC_odd_row" ';
2670: }
1.30 raeburn 2671: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 2672: '<td>'.$title{$item}.
2673: '</td><td class="LC_left_item">'.
2674: '<span class="LC_nobreak">';
2675: foreach my $auth (@authtypes) {
2676: $datatable .= '<label>'.
2677: '<input type="checkbox" name="'.$item.'_auth" '.
2678: $checked{$item}{$auth}.' value="'.$auth.'" />'.
2679: $authname{$auth}.'</label> ';
2680: }
2681: $datatable .= '</span></td></tr>';
2682: $rownum ++;
1.27 raeburn 2683: }
1.30 raeburn 2684: $$rowtotal += $rownum;
1.27 raeburn 2685: }
2686: return $datatable;
2687: }
2688:
1.32 raeburn 2689: sub user_formats_row {
2690: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
2691: my $output;
2692: my %text = (
2693: 'username' => 'new usernames',
2694: 'id' => 'IDs',
1.45 raeburn 2695: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 2696: );
2697: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
2698: $output = '<tr '.$css_class.'>'.
1.63 raeburn 2699: '<td><span class="LC_nobreak">';
2700: if ($type eq 'email') {
2701: $output .= &mt("Formats disallowed for $text{$type}: ");
2702: } else {
2703: $output .= &mt("Format rules to check for $text{$type}: ");
2704: }
2705: $output .= '</span></td>'.
2706: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 2707: my $rem;
2708: if (ref($ruleorder) eq 'ARRAY') {
2709: for (my $i=0; $i<@{$ruleorder}; $i++) {
2710: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
2711: my $rem = $i%($numinrow);
2712: if ($rem == 0) {
2713: if ($i > 0) {
2714: $output .= '</tr>';
2715: }
2716: $output .= '<tr>';
2717: }
2718: my $check = ' ';
1.39 raeburn 2719: if (ref($settings) eq 'HASH') {
2720: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
2721: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
2722: $check = ' checked="checked" ';
2723: }
1.27 raeburn 2724: }
2725: }
2726: $output .= '<td class="LC_left_item">'.
2727: '<span class="LC_nobreak"><label>'.
1.32 raeburn 2728: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 2729: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
2730: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
2731: }
2732: }
2733: $rem = @{$ruleorder}%($numinrow);
2734: }
2735: my $colsleft = $numinrow - $rem;
2736: if ($colsleft > 1 ) {
2737: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2738: ' </td>';
2739: } elsif ($colsleft == 1) {
2740: $output .= '<td class="LC_left_item"> </td>';
2741: }
2742: $output .= '</tr></table></td></tr>';
2743: return $output;
2744: }
2745:
1.34 raeburn 2746: sub usercreation_types {
2747: my %lt = &Apache::lonlocal::texthash (
2748: author => 'When adding a co-author',
2749: course => 'When adding a user to a course',
1.100 raeburn 2750: requestcrs => 'When requesting a course',
1.45 raeburn 2751: selfcreate => 'User creates own account',
1.34 raeburn 2752: any => 'Any',
2753: official => 'Institutional only ',
2754: unofficial => 'Non-institutional only',
1.85 schafran 2755: email => 'E-mail address',
1.43 raeburn 2756: login => 'Institutional Login',
2757: sso => 'SSO',
1.34 raeburn 2758: none => 'None',
2759: );
2760: return %lt;
1.48 raeburn 2761: }
1.34 raeburn 2762:
1.28 raeburn 2763: sub authtype_names {
2764: my %lt = &Apache::lonlocal::texthash(
2765: int => 'Internal',
2766: krb4 => 'Kerberos 4',
2767: krb5 => 'Kerberos 5',
2768: loc => 'Local',
2769: );
2770: return %lt;
2771: }
2772:
2773: sub context_names {
2774: my %context_title = &Apache::lonlocal::texthash(
2775: author => 'Creating users when an Author',
2776: course => 'Creating users when in a course',
2777: domain => 'Creating users when a Domain Coordinator',
2778: );
2779: return %context_title;
2780: }
2781:
1.33 raeburn 2782: sub print_usermodification {
2783: my ($position,$dom,$settings,$rowtotal) = @_;
2784: my $numinrow = 4;
2785: my ($context,$datatable,$rowcount);
2786: if ($position eq 'top') {
2787: $rowcount = 0;
2788: $context = 'author';
2789: foreach my $role ('ca','aa') {
2790: $datatable .= &modifiable_userdata_row($context,$role,$settings,
2791: $numinrow,$rowcount);
2792: $$rowtotal ++;
2793: $rowcount ++;
2794: }
1.63 raeburn 2795: } elsif ($position eq 'middle') {
1.33 raeburn 2796: $context = 'course';
2797: $rowcount = 0;
2798: foreach my $role ('st','ep','ta','in','cr') {
2799: $datatable .= &modifiable_userdata_row($context,$role,$settings,
2800: $numinrow,$rowcount);
2801: $$rowtotal ++;
2802: $rowcount ++;
2803: }
1.63 raeburn 2804: } elsif ($position eq 'bottom') {
2805: $context = 'selfcreate';
2806: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2807: $usertypes->{'default'} = $othertitle;
2808: if (ref($types) eq 'ARRAY') {
2809: push(@{$types},'default');
2810: $usertypes->{'default'} = $othertitle;
2811: foreach my $status (@{$types}) {
2812: $datatable .= &modifiable_userdata_row($context,$status,$settings,
2813: $numinrow,$rowcount,$usertypes);
2814: $$rowtotal ++;
2815: $rowcount ++;
2816: }
2817: }
1.33 raeburn 2818: }
2819: return $datatable;
2820: }
2821:
1.43 raeburn 2822: sub print_defaults {
2823: my ($dom,$rowtotal) = @_;
1.68 raeburn 2824: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.138.2.5 raeburn 2825: 'datelocale_def','portal_def');
1.43 raeburn 2826: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.138.2.5 raeburn 2827: my $titles = &defaults_titles($dom);
1.43 raeburn 2828: my $rownum = 0;
2829: my ($datatable,$css_class);
2830: foreach my $item (@items) {
2831: if ($rownum%2) {
2832: $css_class = '';
2833: } else {
2834: $css_class = ' class="LC_odd_row" ';
2835: }
2836: $datatable .= '<tr'.$css_class.'>'.
2837: '<td><span class="LC_nobreak">'.$titles->{$item}.
2838: '</span></td><td class="LC_right_item">';
2839: if ($item eq 'auth_def') {
2840: my @authtypes = ('internal','krb4','krb5','localauth');
2841: my %shortauth = (
2842: internal => 'int',
2843: krb4 => 'krb4',
2844: krb5 => 'krb5',
2845: localauth => 'loc'
2846: );
2847: my %authnames = &authtype_names();
2848: foreach my $auth (@authtypes) {
2849: my $checked = ' ';
2850: if ($domdefaults{$item} eq $auth) {
2851: $checked = ' checked="checked" ';
2852: }
2853: $datatable .= '<label><input type="radio" name="'.$item.
2854: '" value="'.$auth.'"'.$checked.'/>'.
2855: $authnames{$shortauth{$auth}}.'</label> ';
2856: }
1.54 raeburn 2857: } elsif ($item eq 'timezone_def') {
2858: my $includeempty = 1;
2859: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 2860: } elsif ($item eq 'datelocale_def') {
2861: my $includeempty = 1;
2862: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 2863: } else {
1.138.2.6 raeburn 2864: my $size;
1.138.2.5 raeburn 2865: if ($item eq 'portal_def') {
2866: $size = ' size="25"';
2867: }
1.43 raeburn 2868: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.138.2.5 raeburn 2869: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 2870: }
2871: $datatable .= '</td></tr>';
2872: $rownum ++;
2873: }
2874: $$rowtotal += $rownum;
2875: return $datatable;
2876: }
2877:
2878: sub defaults_titles {
1.138.2.5 raeburn 2879: my ($dom) = @_;
1.43 raeburn 2880: my %titles = &Apache::lonlocal::texthash (
2881: 'auth_def' => 'Default authentication type',
2882: 'auth_arg_def' => 'Default authentication argument',
2883: 'lang_def' => 'Default language',
1.54 raeburn 2884: 'timezone_def' => 'Default timezone',
1.68 raeburn 2885: 'datelocale_def' => 'Default locale for dates',
1.138.2.5 raeburn 2886: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 2887: );
1.138.2.5 raeburn 2888: if ($dom) {
2889: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
2890: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
2891: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
2892: $protocol = 'http' if ($protocol ne 'https');
2893: if ($uint_dom) {
2894: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
2895: $uint_dom);
2896: }
2897: }
1.43 raeburn 2898: return (\%titles);
2899: }
2900:
1.46 raeburn 2901: sub print_scantronformat {
2902: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
2903: my $itemcount = 1;
1.60 raeburn 2904: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
2905: %confhash);
1.46 raeburn 2906: my $switchserver = &check_switchserver($dom,$confname);
2907: my %lt = &Apache::lonlocal::texthash (
1.95 www 2908: default => 'Default bubblesheet format file error',
2909: custom => 'Custom bubblesheet format file error',
1.46 raeburn 2910: );
2911: my %scantronfiles = (
2912: default => 'default.tab',
2913: custom => 'custom.tab',
2914: );
2915: foreach my $key (keys(%scantronfiles)) {
2916: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
2917: .$scantronfiles{$key};
2918: }
2919: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
2920: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
2921: if (!$switchserver) {
2922: my $servadm = $r->dir_config('lonAdmEMail');
2923: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
2924: if ($configuserok eq 'ok') {
2925: if ($author_ok eq 'ok') {
2926: my %legacyfile = (
2927: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
2928: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
2929: );
2930: my %md5chk;
2931: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2932: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
2933: chomp($md5chk{$type});
1.46 raeburn 2934: }
2935: if ($md5chk{'default'} ne $md5chk{'custom'}) {
2936: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2937: ($scantronurls{$type},my $error) =
1.46 raeburn 2938: &legacy_scantronformat($r,$dom,$confname,
2939: $type,$legacyfile{$type},
2940: $scantronurls{$type},
2941: $scantronfiles{$type});
1.60 raeburn 2942: if ($error ne '') {
2943: $error{$type} = $error;
2944: }
2945: }
2946: if (keys(%error) == 0) {
2947: $is_custom = 1;
2948: $confhash{'scantron'}{'scantronformat'} =
2949: $scantronurls{'custom'};
2950: my $putresult =
2951: &Apache::lonnet::put_dom('configuration',
2952: \%confhash,$dom);
2953: if ($putresult ne 'ok') {
2954: $error{'custom'} =
2955: '<span class="LC_error">'.
2956: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2957: }
1.46 raeburn 2958: }
2959: } else {
1.60 raeburn 2960: ($scantronurls{'default'},my $error) =
1.46 raeburn 2961: &legacy_scantronformat($r,$dom,$confname,
2962: 'default',$legacyfile{'default'},
2963: $scantronurls{'default'},
2964: $scantronfiles{'default'});
1.60 raeburn 2965: if ($error eq '') {
2966: $confhash{'scantron'}{'scantronformat'} = '';
2967: my $putresult =
2968: &Apache::lonnet::put_dom('configuration',
2969: \%confhash,$dom);
2970: if ($putresult ne 'ok') {
2971: $error{'default'} =
2972: '<span class="LC_error">'.
2973: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2974: }
2975: } else {
2976: $error{'default'} = $error;
2977: }
1.46 raeburn 2978: }
2979: }
2980: }
2981: } else {
1.95 www 2982: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 2983: }
2984: }
2985: if (ref($settings) eq 'HASH') {
2986: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
2987: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
2988: if ((!@info) || ($info[0] eq 'no_such_dir')) {
2989: $scantronurl = '';
2990: } else {
2991: $scantronurl = $settings->{'scantronformat'};
2992: }
2993: $is_custom = 1;
2994: } else {
2995: $scantronurl = $scantronurls{'default'};
2996: }
2997: } else {
1.60 raeburn 2998: if ($is_custom) {
2999: $scantronurl = $scantronurls{'custom'};
3000: } else {
3001: $scantronurl = $scantronurls{'default'};
3002: }
1.46 raeburn 3003: }
3004: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3005: $datatable .= '<tr'.$css_class.'>';
3006: if (!$is_custom) {
1.65 raeburn 3007: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3008: '<span class="LC_nobreak">';
1.46 raeburn 3009: if ($scantronurl) {
3010: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3011: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3012: } else {
3013: $datatable = &mt('File unavailable for display');
3014: }
1.65 raeburn 3015: $datatable .= '</span></td>';
1.60 raeburn 3016: if (keys(%error) == 0) {
3017: $datatable .= '<td valign="bottom">';
3018: if (!$switchserver) {
3019: $datatable .= &mt('Upload:').'<br />';
3020: }
3021: } else {
3022: my $errorstr;
3023: foreach my $key (sort(keys(%error))) {
3024: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3025: }
3026: $datatable .= '<td>'.$errorstr;
3027: }
1.46 raeburn 3028: } else {
3029: if (keys(%error) > 0) {
3030: my $errorstr;
3031: foreach my $key (sort(keys(%error))) {
3032: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3033: }
1.60 raeburn 3034: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3035: } elsif ($scantronurl) {
1.65 raeburn 3036: $datatable .= '<td><span class="LC_nobreak">'.
3037: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3038: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3039: '<input type="checkbox" name="scantronformat_del"'.
3040: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3041: '<td><span class="LC_nobreak"> '.
3042: &mt('Replace:').'</span><br />';
1.46 raeburn 3043: }
3044: }
3045: if (keys(%error) == 0) {
3046: if ($switchserver) {
3047: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3048: } else {
1.65 raeburn 3049: $datatable .='<span class="LC_nobreak"> '.
3050: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3051: }
3052: }
3053: $datatable .= '</td></tr>';
3054: $$rowtotal ++;
3055: return $datatable;
3056: }
3057:
3058: sub legacy_scantronformat {
3059: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3060: my ($url,$error);
3061: my @statinfo = &Apache::lonnet::stat_file($newurl);
3062: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3063: (my $result,$url) =
3064: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3065: '','',$newfile);
3066: if ($result ne 'ok') {
1.130 raeburn 3067: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3068: }
3069: }
3070: return ($url,$error);
3071: }
1.43 raeburn 3072:
1.49 raeburn 3073: sub print_coursecategories {
1.57 raeburn 3074: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3075: my $datatable;
3076: if ($position eq 'top') {
3077: my $toggle_cats_crs = ' ';
3078: my $toggle_cats_dom = ' checked="checked" ';
3079: my $can_cat_crs = ' ';
3080: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3081: my $toggle_catscomm_comm = ' ';
3082: my $toggle_catscomm_dom = ' checked="checked" ';
3083: my $can_catcomm_comm = ' ';
3084: my $can_catcomm_dom = ' checked="checked" ';
3085:
1.57 raeburn 3086: if (ref($settings) eq 'HASH') {
3087: if ($settings->{'togglecats'} eq 'crs') {
3088: $toggle_cats_crs = $toggle_cats_dom;
3089: $toggle_cats_dom = ' ';
3090: }
3091: if ($settings->{'categorize'} eq 'crs') {
3092: $can_cat_crs = $can_cat_dom;
3093: $can_cat_dom = ' ';
3094: }
1.120 raeburn 3095: if ($settings->{'togglecatscomm'} eq 'comm') {
3096: $toggle_catscomm_comm = $toggle_catscomm_dom;
3097: $toggle_catscomm_dom = ' ';
3098: }
3099: if ($settings->{'categorizecomm'} eq 'comm') {
3100: $can_catcomm_comm = $can_catcomm_dom;
3101: $can_catcomm_dom = ' ';
3102: }
1.57 raeburn 3103: }
3104: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3105: togglecats => 'Show/Hide a course in catalog',
3106: togglecatscomm => 'Show/Hide a community in catalog',
3107: categorize => 'Assign a category to a course',
3108: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3109: );
3110: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3111: dom => 'Set in Domain',
3112: crs => 'Set in Course',
3113: comm => 'Set in Community',
1.57 raeburn 3114: );
3115: $datatable = '<tr class="LC_odd_row">'.
3116: '<td>'.$title{'togglecats'}.'</td>'.
3117: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3118: '<input type="radio" name="togglecats"'.
3119: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3120: '<label><input type="radio" name="togglecats"'.
3121: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3122: '</tr><tr>'.
3123: '<td>'.$title{'categorize'}.'</td>'.
3124: '<td class="LC_right_item"><span class="LC_nobreak">'.
3125: '<label><input type="radio" name="categorize"'.
3126: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3127: '<label><input type="radio" name="categorize"'.
3128: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3129: '</tr><tr class="LC_odd_row">'.
3130: '<td>'.$title{'togglecatscomm'}.'</td>'.
3131: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3132: '<input type="radio" name="togglecatscomm"'.
3133: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3134: '<label><input type="radio" name="togglecatscomm"'.
3135: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3136: '</tr><tr>'.
3137: '<td>'.$title{'categorizecomm'}.'</td>'.
3138: '<td class="LC_right_item"><span class="LC_nobreak">'.
3139: '<label><input type="radio" name="categorizecomm"'.
3140: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3141: '<label><input type="radio" name="categorizecomm"'.
3142: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3143: '</tr>';
1.120 raeburn 3144: $$rowtotal += 4;
1.57 raeburn 3145: } else {
3146: my $css_class;
3147: my $itemcount = 1;
3148: my $cathash;
3149: if (ref($settings) eq 'HASH') {
3150: $cathash = $settings->{'cats'};
3151: }
3152: if (ref($cathash) eq 'HASH') {
3153: my (@cats,@trails,%allitems,%idx,@jsarray);
3154: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
3155: \%allitems,\%idx,\@jsarray);
3156: my $maxdepth = scalar(@cats);
3157: my $colattrib = '';
3158: if ($maxdepth > 2) {
3159: $colattrib = ' colspan="2" ';
3160: }
3161: my @path;
3162: if (@cats > 0) {
3163: if (ref($cats[0]) eq 'ARRAY') {
3164: my $numtop = @{$cats[0]};
3165: my $maxnum = $numtop;
1.120 raeburn 3166: my %default_names = (
3167: instcode => &mt('Official courses'),
3168: communities => &mt('Communities'),
3169: );
3170:
3171: if ((!grep(/^instcode$/,@{$cats[0]})) ||
3172: ($cathash->{'instcode::0'} eq '') ||
3173: (!grep(/^communities$/,@{$cats[0]})) ||
3174: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 3175: $maxnum ++;
3176: }
3177: my $lastidx;
3178: for (my $i=0; $i<$numtop; $i++) {
3179: my $parent = $cats[0][$i];
3180: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3181: my $item = &escape($parent).'::0';
3182: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
3183: $lastidx = $idx{$item};
3184: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3185: .'<select name="'.$item.'"'.$chgstr.'>';
3186: for (my $k=0; $k<=$maxnum; $k++) {
3187: my $vpos = $k+1;
3188: my $selstr;
3189: if ($k == $i) {
3190: $selstr = ' selected="selected" ';
3191: }
3192: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3193: }
3194: $datatable .= '</select></td><td>';
1.120 raeburn 3195: if ($parent eq 'instcode' || $parent eq 'communities') {
3196: $datatable .= '<span class="LC_nobreak">'
3197: .$default_names{$parent}.'</span>';
3198: if ($parent eq 'instcode') {
3199: $datatable .= '<br /><span class="LC_nobreak">('
3200: .&mt('with institutional codes')
3201: .')</span></td><td'.$colattrib.'>';
3202: } else {
3203: $datatable .= '<table><tr><td>';
3204: }
3205: $datatable .= '<span class="LC_nobreak">'
3206: .'<label><input type="radio" name="'
3207: .$parent.'" value="1" checked="checked" />'
3208: .&mt('Display').'</label>';
3209: if ($parent eq 'instcode') {
3210: $datatable .= ' ';
3211: } else {
3212: $datatable .= '</span></td></tr><tr><td>'
3213: .'<span class="LC_nobreak">';
3214: }
3215: $datatable .= '<label><input type="radio" name="'
3216: .$parent.'" value="0" />'
3217: .&mt('Do not display').'</label></span>';
3218: if ($parent eq 'communities') {
3219: $datatable .= '</td></tr></table>';
3220: }
3221: $datatable .= '</td>';
1.57 raeburn 3222: } else {
3223: $datatable .= $parent
3224: .' <label><input type="checkbox" name="deletecategory" '
3225: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
3226: }
3227: my $depth = 1;
3228: push(@path,$parent);
3229: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
3230: pop(@path);
3231: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
3232: $itemcount ++;
3233: }
1.48 raeburn 3234: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 3235: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
3236: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 3237: for (my $k=0; $k<=$maxnum; $k++) {
3238: my $vpos = $k+1;
3239: my $selstr;
1.57 raeburn 3240: if ($k == $numtop) {
1.48 raeburn 3241: $selstr = ' selected="selected" ';
3242: }
3243: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3244: }
1.59 bisitz 3245: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 3246: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
3247: .'</tr>'."\n";
1.48 raeburn 3248: $itemcount ++;
1.120 raeburn 3249: foreach my $default ('instcode','communities') {
3250: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
3251: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3252: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
3253: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
3254: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
3255: for (my $k=0; $k<=$maxnum; $k++) {
3256: my $vpos = $k+1;
3257: my $selstr;
3258: if ($k == $maxnum) {
3259: $selstr = ' selected="selected" ';
3260: }
3261: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 3262: }
1.120 raeburn 3263: $datatable .= '</select></span></td>'.
3264: '<td><span class="LC_nobreak">'.
3265: $default_names{$default}.'</span>';
3266: if ($default eq 'instcode') {
3267: $datatable .= '<br /><span class="LC_nobreak">('
3268: .&mt('with institutional codes').')</span>';
3269: }
3270: $datatable .= '</td>'
3271: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
3272: .&mt('Display').'</label> '
3273: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
3274: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 3275: }
3276: }
3277: }
1.57 raeburn 3278: } else {
3279: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 3280: }
3281: } else {
1.57 raeburn 3282: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
3283: .&initialize_categories($itemcount);
1.48 raeburn 3284: }
1.57 raeburn 3285: $$rowtotal += $itemcount;
1.48 raeburn 3286: }
3287: return $datatable;
3288: }
3289:
1.69 raeburn 3290: sub print_serverstatuses {
3291: my ($dom,$settings,$rowtotal) = @_;
3292: my $datatable;
3293: my @pages = &serverstatus_pages();
3294: my (%namedaccess,%machineaccess);
3295: foreach my $type (@pages) {
3296: $namedaccess{$type} = '';
3297: $machineaccess{$type}= '';
3298: }
3299: if (ref($settings) eq 'HASH') {
3300: foreach my $type (@pages) {
3301: if (exists($settings->{$type})) {
3302: if (ref($settings->{$type}) eq 'HASH') {
3303: foreach my $key (keys(%{$settings->{$type}})) {
3304: if ($key eq 'namedusers') {
3305: $namedaccess{$type} = $settings->{$type}->{$key};
3306: } elsif ($key eq 'machines') {
3307: $machineaccess{$type} = $settings->{$type}->{$key};
3308: }
3309: }
3310: }
3311: }
3312: }
3313: }
1.81 raeburn 3314: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 3315: my $rownum = 0;
3316: my $css_class;
3317: foreach my $type (@pages) {
3318: $rownum ++;
3319: $css_class = $rownum%2?' class="LC_odd_row"':'';
3320: $datatable .= '<tr'.$css_class.'>'.
3321: '<td><span class="LC_nobreak">'.
3322: $titles->{$type}.'</span></td>'.
3323: '<td class="LC_left_item">'.
3324: '<input type="text" name="'.$type.'_namedusers" '.
3325: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
3326: '<td class="LC_right_item">'.
3327: '<span class="LC_nobreak">'.
3328: '<input type="text" name="'.$type.'_machines" '.
3329: 'value="'.$machineaccess{$type}.'" size="10" />'.
3330: '</td></tr>'."\n";
3331: }
3332: $$rowtotal += $rownum;
3333: return $datatable;
3334: }
3335:
3336: sub serverstatus_pages {
3337: return ('userstatus','lonstatus','loncron','server-status','codeversions',
3338: 'clusterstatus','metadata_keywords','metadata_harvest',
1.138.2.12! raeburn 3339: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 3340: }
3341:
1.49 raeburn 3342: sub coursecategories_javascript {
3343: my ($settings) = @_;
1.57 raeburn 3344: my ($output,$jstext,$cathash);
1.49 raeburn 3345: if (ref($settings) eq 'HASH') {
1.57 raeburn 3346: $cathash = $settings->{'cats'};
3347: }
3348: if (ref($cathash) eq 'HASH') {
1.49 raeburn 3349: my (@cats,@jsarray,%idx);
1.57 raeburn 3350: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 3351: if (@jsarray > 0) {
3352: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
3353: for (my $i=0; $i<@jsarray; $i++) {
3354: if (ref($jsarray[$i]) eq 'ARRAY') {
3355: my $catstr = join('","',@{$jsarray[$i]});
3356: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
3357: }
3358: }
3359: }
3360: } else {
3361: $jstext = ' var categories = Array(1);'."\n".
3362: ' categories[0] = Array("instcode_pos");'."\n";
3363: }
1.120 raeburn 3364: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
3365: my $communities_reserved = &mt('The name: "communities" is a reserved category');
3366: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 3367: $output = <<"ENDSCRIPT";
3368: <script type="text/javascript">
1.109 raeburn 3369: // <![CDATA[
1.49 raeburn 3370: function reorderCats(form,parent,item,idx) {
3371: var changedVal;
3372: $jstext
3373: var newpos = 'addcategory_pos';
3374: var current = new Array;
3375: if (parent == '') {
3376: var has_instcode = 0;
3377: var maxtop = categories[idx].length;
3378: for (var j=0; j<maxtop; j++) {
3379: if (categories[idx][j] == 'instcode::0') {
3380: has_instcode == 1;
3381: }
3382: }
3383: if (has_instcode == 0) {
3384: categories[idx][maxtop] = 'instcode_pos';
3385: }
3386: } else {
3387: newpos += '_'+parent;
3388: }
3389: var maxh = 1 + categories[idx].length;
3390: var current = new Array;
3391: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3392: if (item == newpos) {
3393: changedVal = newitemVal;
3394: } else {
3395: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3396: current[newitemVal] = newpos;
3397: }
3398: for (var i=0; i<categories[idx].length; i++) {
3399: var elementName = categories[idx][i];
3400: if (elementName != item) {
3401: if (form.elements[elementName]) {
3402: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3403: current[currVal] = elementName;
3404: }
3405: }
3406: }
3407: var oldVal;
3408: for (var j=0; j<maxh; j++) {
3409: if (current[j] == undefined) {
3410: oldVal = j;
3411: }
3412: }
3413: if (oldVal < changedVal) {
3414: for (var k=oldVal+1; k<=changedVal ; k++) {
3415: var elementName = current[k];
3416: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3417: }
3418: } else {
3419: for (var k=changedVal; k<oldVal; k++) {
3420: var elementName = current[k];
3421: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3422: }
3423: }
3424: return;
3425: }
1.120 raeburn 3426:
3427: function categoryCheck(form) {
3428: if (form.elements['addcategory_name'].value == 'instcode') {
3429: alert('$instcode_reserved\\n$choose_again');
3430: return false;
3431: }
3432: if (form.elements['addcategory_name'].value == 'communities') {
3433: alert('$communities_reserved\\n$choose_again');
3434: return false;
3435: }
3436: return true;
3437: }
3438:
1.109 raeburn 3439: // ]]>
1.49 raeburn 3440: </script>
3441:
3442: ENDSCRIPT
3443: return $output;
3444: }
3445:
1.48 raeburn 3446: sub initialize_categories {
3447: my ($itemcount) = @_;
1.120 raeburn 3448: my ($datatable,$css_class,$chgstr);
3449: my %default_names = (
3450: instcode => 'Official courses (with institutional codes)',
3451: communities => 'Communities',
3452: );
3453: my $select0 = ' selected="selected"';
3454: my $select1 = '';
3455: foreach my $default ('instcode','communities') {
3456: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3457: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
3458: if ($default eq 'communities') {
3459: $select1 = $select0;
3460: $select0 = '';
3461: }
3462: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
3463: .'<select name="'.$default.'_pos">'
3464: .'<option value="0"'.$select0.'>1</option>'
3465: .'<option value="1"'.$select1.'>2</option>'
3466: .'<option value="2">3</option></select> '
3467: .$default_names{$default}
3468: .'</span></td><td><span class="LC_nobreak">'
3469: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
3470: .&mt('Display').'</label> <label>'
3471: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 3472: .'</label></span></td></tr>';
1.120 raeburn 3473: $itemcount ++;
3474: }
1.48 raeburn 3475: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 3476: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 3477: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 3478: .'<select name="addcategory_pos"'.$chgstr.'>'
3479: .'<option value="0">1</option>'
3480: .'<option value="1">2</option>'
3481: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 3482: .&mt('Add category').'</td><td>'.&mt('Name:')
3483: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
3484: return $datatable;
3485: }
3486:
3487: sub build_category_rows {
1.49 raeburn 3488: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
3489: my ($text,$name,$item,$chgstr);
1.48 raeburn 3490: if (ref($cats) eq 'ARRAY') {
3491: my $maxdepth = scalar(@{$cats});
3492: if (ref($cats->[$depth]) eq 'HASH') {
3493: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
3494: my $numchildren = @{$cats->[$depth]{$parent}};
3495: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3496: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 3497: my ($idxnum,$parent_name,$parent_item);
3498: my $higher = $depth - 1;
3499: if ($higher == 0) {
3500: $parent_name = &escape($parent).'::'.$higher;
3501: } else {
3502: if (ref($path) eq 'ARRAY') {
3503: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
3504: }
3505: }
3506: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 3507: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 3508: if ($j < $numchildren) {
1.48 raeburn 3509: $name = $cats->[$depth]{$parent}[$j];
3510: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 3511: $idxnum = $idx->{$item};
3512: } else {
3513: $name = $parent_name;
3514: $item = $parent_item;
1.48 raeburn 3515: }
1.49 raeburn 3516: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
3517: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 3518: for (my $i=0; $i<=$numchildren; $i++) {
3519: my $vpos = $i+1;
3520: my $selstr;
3521: if ($j == $i) {
3522: $selstr = ' selected="selected" ';
3523: }
3524: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
3525: }
3526: $text .= '</select> ';
3527: if ($j < $numchildren) {
3528: my $deeper = $depth+1;
3529: $text .= $name.' '
3530: .'<label><input type="checkbox" name="deletecategory" value="'
3531: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
3532: if(ref($path) eq 'ARRAY') {
3533: push(@{$path},$name);
1.49 raeburn 3534: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 3535: pop(@{$path});
3536: }
3537: } else {
1.59 bisitz 3538: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 3539: if ($j == $numchildren) {
3540: $text .= $name;
3541: } else {
3542: $text .= $item;
3543: }
3544: $text .= '" value="" />';
3545: }
3546: $text .= '</td></tr>';
3547: }
3548: $text .= '</table></td>';
3549: } else {
3550: my $higher = $depth-1;
3551: if ($higher == 0) {
3552: $name = &escape($parent).'::'.$higher;
3553: } else {
3554: if (ref($path) eq 'ARRAY') {
3555: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
3556: }
3557: }
3558: my $colspan;
3559: if ($parent ne 'instcode') {
3560: $colspan = $maxdepth - $depth - 1;
3561: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
3562: }
3563: }
3564: }
3565: }
3566: return $text;
3567: }
3568:
1.33 raeburn 3569: sub modifiable_userdata_row {
1.63 raeburn 3570: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 3571: my $rolename;
1.63 raeburn 3572: if ($context eq 'selfcreate') {
3573: if (ref($usertypes) eq 'HASH') {
3574: $rolename = $usertypes->{$role};
3575: } else {
3576: $rolename = $role;
3577: }
1.33 raeburn 3578: } else {
1.63 raeburn 3579: if ($role eq 'cr') {
3580: $rolename = &mt('Custom role');
3581: } else {
3582: $rolename = &Apache::lonnet::plaintext($role);
3583: }
1.33 raeburn 3584: }
3585: my @fields = ('lastname','firstname','middlename','generation',
3586: 'permanentemail','id');
3587: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3588: my $output;
3589: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3590: $output = '<tr '.$css_class.'>'.
3591: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
3592: '<td class="LC_left_item" colspan="2"><table>';
3593: my $rem;
3594: my %checks;
3595: if (ref($settings) eq 'HASH') {
3596: if (ref($settings->{$context}) eq 'HASH') {
3597: if (ref($settings->{$context}->{$role}) eq 'HASH') {
3598: foreach my $field (@fields) {
3599: if ($settings->{$context}->{$role}->{$field}) {
3600: $checks{$field} = ' checked="checked" ';
3601: }
3602: }
3603: }
3604: }
3605: }
3606: for (my $i=0; $i<@fields; $i++) {
3607: my $rem = $i%($numinrow);
3608: if ($rem == 0) {
3609: if ($i > 0) {
3610: $output .= '</tr>';
3611: }
3612: $output .= '<tr>';
3613: }
3614: my $check = ' ';
3615: if (exists($checks{$fields[$i]})) {
3616: $check = $checks{$fields[$i]}
3617: } else {
3618: if ($role eq 'st') {
3619: if (ref($settings) ne 'HASH') {
3620: $check = ' checked="checked" ';
3621: }
3622: }
3623: }
3624: $output .= '<td class="LC_left_item">'.
3625: '<span class="LC_nobreak"><label>'.
3626: '<input type="checkbox" name="canmodify_'.$role.'" '.
3627: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
3628: '</label></span></td>';
3629: $rem = @fields%($numinrow);
3630: }
3631: my $colsleft = $numinrow - $rem;
3632: if ($colsleft > 1 ) {
3633: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3634: ' </td>';
3635: } elsif ($colsleft == 1) {
3636: $output .= '<td class="LC_left_item"> </td>';
3637: }
3638: $output .= '</tr></table></td></tr>';
3639: return $output;
3640: }
1.28 raeburn 3641:
1.93 raeburn 3642: sub insttypes_row {
3643: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
3644: my %lt = &Apache::lonlocal::texthash (
3645: cansearch => 'Users allowed to search',
3646: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 3647: lockablenames => 'User preference to lock name',
1.93 raeburn 3648: );
3649: my $showdom;
3650: if ($context eq 'cansearch') {
3651: $showdom = ' ('.$dom.')';
3652: }
1.25 raeburn 3653: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 3654: '<td>'.$lt{$context}.$showdom.
1.24 raeburn 3655: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 3656: my $rem;
3657: if (ref($types) eq 'ARRAY') {
3658: for (my $i=0; $i<@{$types}; $i++) {
3659: if (defined($usertypes->{$types->[$i]})) {
3660: my $rem = $i%($numinrow);
3661: if ($rem == 0) {
3662: if ($i > 0) {
3663: $output .= '</tr>';
3664: }
3665: $output .= '<tr>';
1.23 raeburn 3666: }
1.26 raeburn 3667: my $check = ' ';
1.99 raeburn 3668: if (ref($settings) eq 'HASH') {
3669: if (ref($settings->{$context}) eq 'ARRAY') {
3670: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
3671: $check = ' checked="checked" ';
3672: }
3673: } elsif ($context eq 'statustocreate') {
1.26 raeburn 3674: $check = ' checked="checked" ';
3675: }
1.23 raeburn 3676: }
1.26 raeburn 3677: $output .= '<td class="LC_left_item">'.
3678: '<span class="LC_nobreak"><label>'.
1.93 raeburn 3679: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 3680: 'value="'.$types->[$i].'"'.$check.'/>'.
3681: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 3682: }
3683: }
1.26 raeburn 3684: $rem = @{$types}%($numinrow);
1.23 raeburn 3685: }
3686: my $colsleft = $numinrow - $rem;
1.131 raeburn 3687: if (($rem == 0) && (@{$types} > 0)) {
3688: $output .= '<tr>';
3689: }
1.23 raeburn 3690: if ($colsleft > 1) {
1.25 raeburn 3691: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 3692: } else {
1.25 raeburn 3693: $output .= '<td class="LC_left_item">';
1.23 raeburn 3694: }
3695: my $defcheck = ' ';
1.99 raeburn 3696: if (ref($settings) eq 'HASH') {
3697: if (ref($settings->{$context}) eq 'ARRAY') {
3698: if (grep(/^default$/,@{$settings->{$context}})) {
3699: $defcheck = ' checked="checked" ';
3700: }
3701: } elsif ($context eq 'statustocreate') {
1.26 raeburn 3702: $defcheck = ' checked="checked" ';
3703: }
1.23 raeburn 3704: }
1.25 raeburn 3705: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 3706: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 3707: 'value="default"'.$defcheck.'/>'.
3708: $othertitle.'</label></span></td>'.
3709: '</tr></table></td></tr>';
3710: return $output;
1.23 raeburn 3711: }
3712:
3713: sub sorted_searchtitles {
3714: my %searchtitles = &Apache::lonlocal::texthash(
3715: 'uname' => 'username',
3716: 'lastname' => 'last name',
3717: 'lastfirst' => 'last name, first name',
3718: );
3719: my @titleorder = ('uname','lastname','lastfirst');
3720: return (\%searchtitles,\@titleorder);
3721: }
3722:
1.25 raeburn 3723: sub sorted_searchtypes {
3724: my %srchtypes_desc = (
3725: exact => 'is exact match',
3726: contains => 'contains ..',
3727: begins => 'begins with ..',
3728: );
3729: my @srchtypeorder = ('exact','begins','contains');
3730: return (\%srchtypes_desc,\@srchtypeorder);
3731: }
3732:
1.3 raeburn 3733: sub usertype_update_row {
3734: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
3735: my $datatable;
3736: my $numinrow = 4;
3737: foreach my $type (@{$types}) {
3738: if (defined($usertypes->{$type})) {
3739: $$rownums ++;
3740: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
3741: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
3742: '</td><td class="LC_left_item"><table>';
3743: for (my $i=0; $i<@{$fields}; $i++) {
3744: my $rem = $i%($numinrow);
3745: if ($rem == 0) {
3746: if ($i > 0) {
3747: $datatable .= '</tr>';
3748: }
3749: $datatable .= '<tr>';
3750: }
3751: my $check = ' ';
1.39 raeburn 3752: if (ref($settings) eq 'HASH') {
3753: if (ref($settings->{'fields'}) eq 'HASH') {
3754: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
3755: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
3756: $check = ' checked="checked" ';
3757: }
1.3 raeburn 3758: }
3759: }
3760: }
3761:
3762: if ($i == @{$fields}-1) {
3763: my $colsleft = $numinrow - $rem;
3764: if ($colsleft > 1) {
3765: $datatable .= '<td colspan="'.$colsleft.'">';
3766: } else {
3767: $datatable .= '<td>';
3768: }
3769: } else {
3770: $datatable .= '<td>';
3771: }
1.8 raeburn 3772: $datatable .= '<span class="LC_nobreak"><label>'.
3773: '<input type="checkbox" name="updateable_'.$type.
3774: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
3775: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 3776: }
3777: $datatable .= '</tr></table></td></tr>';
3778: }
3779: }
3780: return $datatable;
1.1 raeburn 3781: }
3782:
3783: sub modify_login {
1.9 raeburn 3784: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 3785: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 3786: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 3787: adminmail => 'Display administrator E-mail address',
1.43 raeburn 3788: newuser => 'Link for visitors to create a user account',
1.41 raeburn 3789: loginheader => 'Log-in box header');
1.3 raeburn 3790: my @offon = ('off','on');
1.112 raeburn 3791: my %curr_loginvia;
3792: if (ref($domconfig{login}) eq 'HASH') {
3793: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
3794: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
3795: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
3796: }
3797: }
3798: }
1.6 raeburn 3799: my %loginhash;
1.9 raeburn 3800: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
3801: \%domconfig,\%loginhash);
1.118 jms 3802: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 3803: foreach my $item (@toggles) {
3804: $loginhash{login}{$item} = $env{'form.'.$item};
3805: }
1.41 raeburn 3806: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 3807: if (ref($colchanges{'login'}) eq 'HASH') {
3808: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
3809: \%loginhash);
3810: }
1.110 raeburn 3811:
1.117 raeburn 3812: my %servers = &dom_servers($dom);
1.128 raeburn 3813: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 3814: if (keys(%servers) > 1) {
3815: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 3816: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
3817: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
3818: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
3819: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
3820: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
3821: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
3822: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
3823: $changes{'loginvia'}{$lonhost} = 1;
3824: } else {
3825: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
3826: $changes{'loginvia'}{$lonhost} = 1;
3827: }
3828: } else {
3829: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
3830: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
3831: $changes{'loginvia'}{$lonhost} = 1;
3832: }
3833: }
3834: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
3835: foreach my $item (@loginvia_attribs) {
3836: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
3837: }
3838: } else {
3839: foreach my $item (@loginvia_attribs) {
3840: my $new = $env{'form.'.$lonhost.'_'.$item};
3841: if (($item eq 'serverpath') && ($new eq 'custom')) {
3842: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
3843: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
3844: $new = '/';
3845: }
3846: }
3847: if (($item eq 'custompath') &&
3848: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
3849: $new = '';
3850: }
3851: if ($new ne $curr_loginvia{$lonhost}{$item}) {
3852: $changes{'loginvia'}{$lonhost} = 1;
3853: }
3854: if ($item eq 'exempt') {
3855: $new =~ s/^\s+//;
3856: $new =~ s/\s+$//;
3857: my @poss_ips = split(/\s*[,:]\s*/,$new);
3858: my @okips;
3859: foreach my $ip (@poss_ips) {
3860: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
3861: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
3862: push(@okips,$ip);
3863: }
3864: }
3865: }
3866: if (@okips > 0) {
3867: $new = join(',',@okips);
3868: } else {
3869: $new = '';
3870: }
3871: }
3872:
3873: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
3874: }
3875: }
1.112 raeburn 3876: } else {
1.128 raeburn 3877: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
3878: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 3879: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 3880: foreach my $item (@loginvia_attribs) {
3881: my $new = $env{'form.'.$lonhost.'_'.$item};
3882: if (($item eq 'serverpath') && ($new eq 'custom')) {
3883: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
3884: $new = '/';
3885: }
3886: }
3887: if (($item eq 'custompath') &&
3888: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
3889: $new = '';
3890: }
3891: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
3892: }
1.110 raeburn 3893: }
3894: }
3895: }
3896: }
1.119 raeburn 3897:
1.1 raeburn 3898: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
3899: $dom);
3900: if ($putresult eq 'ok') {
1.118 jms 3901: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 3902: my %defaultchecked = (
3903: 'coursecatalog' => 'on',
3904: 'adminmail' => 'off',
1.43 raeburn 3905: 'newuser' => 'off',
1.42 raeburn 3906: );
1.55 raeburn 3907: if (ref($domconfig{'login'}) eq 'HASH') {
3908: foreach my $item (@toggles) {
3909: if ($defaultchecked{$item} eq 'on') {
3910: if (($domconfig{'login'}{$item} eq '0') &&
3911: ($env{'form.'.$item} eq '1')) {
3912: $changes{$item} = 1;
3913: } elsif (($domconfig{'login'}{$item} eq '' ||
3914: $domconfig{'login'}{$item} eq '1') &&
3915: ($env{'form.'.$item} eq '0')) {
3916: $changes{$item} = 1;
3917: }
3918: } elsif ($defaultchecked{$item} eq 'off') {
3919: if (($domconfig{'login'}{$item} eq '1') &&
3920: ($env{'form.'.$item} eq '0')) {
3921: $changes{$item} = 1;
3922: } elsif (($domconfig{'login'}{$item} eq '' ||
3923: $domconfig{'login'}{$item} eq '0') &&
3924: ($env{'form.'.$item} eq '1')) {
3925: $changes{$item} = 1;
3926: }
1.42 raeburn 3927: }
3928: }
1.41 raeburn 3929: }
1.6 raeburn 3930: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 3931: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 3932: $resulttext = &mt('Changes made:').'<ul>';
3933: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 3934: if ($item eq 'loginvia') {
1.112 raeburn 3935: if (ref($changes{$item}) eq 'HASH') {
3936: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
3937: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 3938: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
3939: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
3940: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
3941: $protocol = 'http' if ($protocol ne 'https');
3942: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
3943:
3944: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
3945: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
3946: } else {
3947: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
3948: }
3949: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
3950: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
3951: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
3952: }
3953: $resulttext .= '</li>';
3954: } else {
3955: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
3956: }
1.112 raeburn 3957: } else {
1.128 raeburn 3958: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 3959: }
3960: }
1.128 raeburn 3961: $resulttext .= '</ul></li>';
1.112 raeburn 3962: }
1.41 raeburn 3963: } else {
3964: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
3965: }
1.1 raeburn 3966: }
1.6 raeburn 3967: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 3968: } else {
3969: $resulttext = &mt('No changes made to log-in page settings');
3970: }
3971: } else {
1.11 albertel 3972: $resulttext = '<span class="LC_error">'.
3973: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3974: }
1.6 raeburn 3975: if ($errors) {
1.9 raeburn 3976: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 3977: $errors.'</ul>';
3978: }
3979: return $resulttext;
3980: }
3981:
3982: sub color_font_choices {
3983: my %choices =
3984: &Apache::lonlocal::texthash (
3985: img => "Header",
3986: bgs => "Background colors",
3987: links => "Link colors",
1.55 raeburn 3988: images => "Images",
1.6 raeburn 3989: font => "Font color",
1.97 tempelho 3990: fontmenu => "Font Menu",
1.76 raeburn 3991: pgbg => "Page",
1.6 raeburn 3992: tabbg => "Header",
3993: sidebg => "Border",
3994: link => "Link",
3995: alink => "Active link",
3996: vlink => "Visited link",
3997: );
3998: return %choices;
3999: }
4000:
4001: sub modify_rolecolors {
1.9 raeburn 4002: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 4003: my ($resulttext,%rolehash);
4004: $rolehash{'rolecolors'} = {};
1.55 raeburn 4005: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
4006: if ($domconfig{'rolecolors'} eq '') {
4007: $domconfig{'rolecolors'} = {};
4008: }
4009: }
1.9 raeburn 4010: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 4011: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
4012: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
4013: $dom);
4014: if ($putresult eq 'ok') {
4015: if (keys(%changes) > 0) {
1.41 raeburn 4016: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 4017: $resulttext = &display_colorchgs($dom,\%changes,$roles,
4018: $rolehash{'rolecolors'});
4019: } else {
4020: $resulttext = &mt('No changes made to default color schemes');
4021: }
4022: } else {
1.11 albertel 4023: $resulttext = '<span class="LC_error">'.
4024: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 4025: }
4026: if ($errors) {
4027: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
4028: $errors.'</ul>';
4029: }
4030: return $resulttext;
4031: }
4032:
4033: sub modify_colors {
1.9 raeburn 4034: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 4035: my (%changes,%choices);
1.51 raeburn 4036: my @bgs;
1.6 raeburn 4037: my @links = ('link','alink','vlink');
1.41 raeburn 4038: my @logintext;
1.6 raeburn 4039: my @images;
4040: my $servadm = $r->dir_config('lonAdmEMail');
4041: my $errors;
4042: foreach my $role (@{$roles}) {
4043: if ($role eq 'login') {
1.12 raeburn 4044: %choices = &login_choices();
1.41 raeburn 4045: @logintext = ('textcol','bgcol');
1.12 raeburn 4046: } else {
4047: %choices = &color_font_choices();
1.107 raeburn 4048: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 4049: }
4050: if ($role eq 'login') {
1.41 raeburn 4051: @images = ('img','logo','domlogo','login');
1.51 raeburn 4052: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 4053: } else {
4054: @images = ('img');
1.51 raeburn 4055: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 4056: }
4057: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 4058: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 4059: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
4060: }
1.46 raeburn 4061: my ($configuserok,$author_ok,$switchserver) =
4062: &config_check($dom,$confname,$servadm);
1.9 raeburn 4063: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 4064: if (ref($domconfig->{$role}) ne 'HASH') {
4065: $domconfig->{$role} = {};
4066: }
1.8 raeburn 4067: foreach my $img (@images) {
1.70 raeburn 4068: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
4069: if (defined($env{'form.login_showlogo_'.$img})) {
4070: $confhash->{$role}{'showlogo'}{$img} = 1;
4071: } else {
4072: $confhash->{$role}{'showlogo'}{$img} = 0;
4073: }
4074: }
1.18 albertel 4075: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
4076: && !defined($domconfig->{$role}{$img})
4077: && !$env{'form.'.$role.'_del_'.$img}
4078: && $env{'form.'.$role.'_import_'.$img}) {
4079: # import the old configured image from the .tab setting
4080: # if they haven't provided a new one
4081: $domconfig->{$role}{$img} =
4082: $env{'form.'.$role.'_import_'.$img};
4083: }
1.6 raeburn 4084: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 4085: my $error;
1.6 raeburn 4086: if ($configuserok eq 'ok') {
1.9 raeburn 4087: if ($switchserver) {
1.12 raeburn 4088: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 4089: } else {
4090: if ($author_ok eq 'ok') {
4091: my ($result,$logourl) =
4092: &publishlogo($r,'upload',$role.'_'.$img,
4093: $dom,$confname,$img,$width,$height);
4094: if ($result eq 'ok') {
4095: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 4096: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4097: } else {
1.12 raeburn 4098: $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 4099: }
4100: } else {
1.46 raeburn 4101: $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 4102: }
4103: }
4104: } else {
1.46 raeburn 4105: $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 4106: }
4107: if ($error) {
1.8 raeburn 4108: &Apache::lonnet::logthis($error);
1.11 albertel 4109: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 4110: }
4111: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 4112: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
4113: my $error;
4114: if ($configuserok eq 'ok') {
4115: # is confname an author?
4116: if ($switchserver eq '') {
4117: if ($author_ok eq 'ok') {
4118: my ($result,$logourl) =
4119: &publishlogo($r,'copy',$domconfig->{$role}{$img},
4120: $dom,$confname,$img,$width,$height);
4121: if ($result eq 'ok') {
4122: $confhash->{$role}{$img} = $logourl;
1.18 albertel 4123: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 4124: }
4125: }
4126: }
4127: }
1.6 raeburn 4128: }
4129: }
4130: }
4131: if (ref($domconfig) eq 'HASH') {
4132: if (ref($domconfig->{$role}) eq 'HASH') {
4133: foreach my $img (@images) {
4134: if ($domconfig->{$role}{$img} ne '') {
4135: if ($env{'form.'.$role.'_del_'.$img}) {
4136: $confhash->{$role}{$img} = '';
1.12 raeburn 4137: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4138: } else {
1.9 raeburn 4139: if ($confhash->{$role}{$img} eq '') {
4140: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
4141: }
1.6 raeburn 4142: }
4143: } else {
4144: if ($env{'form.'.$role.'_del_'.$img}) {
4145: $confhash->{$role}{$img} = '';
1.12 raeburn 4146: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 4147: }
4148: }
1.70 raeburn 4149: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
4150: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
4151: if ($confhash->{$role}{'showlogo'}{$img} ne
4152: $domconfig->{$role}{'showlogo'}{$img}) {
4153: $changes{$role}{'showlogo'}{$img} = 1;
4154: }
4155: } else {
4156: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4157: $changes{$role}{'showlogo'}{$img} = 1;
4158: }
4159: }
4160: }
4161: }
1.6 raeburn 4162: if ($domconfig->{$role}{'font'} ne '') {
4163: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
4164: $changes{$role}{'font'} = 1;
4165: }
4166: } else {
4167: if ($confhash->{$role}{'font'}) {
4168: $changes{$role}{'font'} = 1;
4169: }
4170: }
1.107 raeburn 4171: if ($role ne 'login') {
4172: if ($domconfig->{$role}{'fontmenu'} ne '') {
4173: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
4174: $changes{$role}{'fontmenu'} = 1;
4175: }
4176: } else {
4177: if ($confhash->{$role}{'fontmenu'}) {
4178: $changes{$role}{'fontmenu'} = 1;
4179: }
1.97 tempelho 4180: }
4181: }
1.6 raeburn 4182: foreach my $item (@bgs) {
4183: if ($domconfig->{$role}{$item} ne '') {
4184: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4185: $changes{$role}{'bgs'}{$item} = 1;
4186: }
4187: } else {
4188: if ($confhash->{$role}{$item}) {
4189: $changes{$role}{'bgs'}{$item} = 1;
4190: }
4191: }
4192: }
4193: foreach my $item (@links) {
4194: if ($domconfig->{$role}{$item} ne '') {
4195: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4196: $changes{$role}{'links'}{$item} = 1;
4197: }
4198: } else {
4199: if ($confhash->{$role}{$item}) {
4200: $changes{$role}{'links'}{$item} = 1;
4201: }
4202: }
4203: }
1.41 raeburn 4204: foreach my $item (@logintext) {
4205: if ($domconfig->{$role}{$item} ne '') {
4206: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
4207: $changes{$role}{'logintext'}{$item} = 1;
4208: }
4209: } else {
4210: if ($confhash->{$role}{$item}) {
4211: $changes{$role}{'logintext'}{$item} = 1;
4212: }
4213: }
4214: }
1.6 raeburn 4215: } else {
4216: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4217: \@logintext,$confhash,\%changes);
1.6 raeburn 4218: }
4219: } else {
4220: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 4221: \@logintext,$confhash,\%changes);
1.6 raeburn 4222: }
4223: }
4224: return ($errors,%changes);
4225: }
4226:
1.46 raeburn 4227: sub config_check {
4228: my ($dom,$confname,$servadm) = @_;
4229: my ($configuserok,$author_ok,$switchserver,%currroles);
4230: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
4231: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
4232: $confname,$servadm);
4233: if ($configuserok eq 'ok') {
4234: $switchserver = &check_switchserver($dom,$confname);
4235: if ($switchserver eq '') {
4236: $author_ok = &check_authorstatus($dom,$confname,%currroles);
4237: }
4238: }
4239: return ($configuserok,$author_ok,$switchserver);
4240: }
4241:
1.6 raeburn 4242: sub default_change_checker {
1.41 raeburn 4243: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 4244: foreach my $item (@{$links}) {
4245: if ($confhash->{$role}{$item}) {
4246: $changes->{$role}{'links'}{$item} = 1;
4247: }
4248: }
4249: foreach my $item (@{$bgs}) {
4250: if ($confhash->{$role}{$item}) {
4251: $changes->{$role}{'bgs'}{$item} = 1;
4252: }
4253: }
1.41 raeburn 4254: foreach my $item (@{$logintext}) {
4255: if ($confhash->{$role}{$item}) {
4256: $changes->{$role}{'logintext'}{$item} = 1;
4257: }
4258: }
1.6 raeburn 4259: foreach my $img (@{$images}) {
4260: if ($env{'form.'.$role.'_del_'.$img}) {
4261: $confhash->{$role}{$img} = '';
1.12 raeburn 4262: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 4263: }
1.70 raeburn 4264: if ($role eq 'login') {
4265: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
4266: $changes->{$role}{'showlogo'}{$img} = 1;
4267: }
4268: }
1.6 raeburn 4269: }
4270: if ($confhash->{$role}{'font'}) {
4271: $changes->{$role}{'font'} = 1;
4272: }
1.48 raeburn 4273: }
1.6 raeburn 4274:
4275: sub display_colorchgs {
4276: my ($dom,$changes,$roles,$confhash) = @_;
4277: my (%choices,$resulttext);
4278: if (!grep(/^login$/,@{$roles})) {
4279: $resulttext = &mt('Changes made:').'<br />';
4280: }
4281: foreach my $role (@{$roles}) {
4282: if ($role eq 'login') {
4283: %choices = &login_choices();
4284: } else {
4285: %choices = &color_font_choices();
4286: }
4287: if (ref($changes->{$role}) eq 'HASH') {
4288: if ($role ne 'login') {
4289: $resulttext .= '<h4>'.&mt($role).'</h4>';
4290: }
4291: foreach my $key (sort(keys(%{$changes->{$role}}))) {
4292: if ($role ne 'login') {
4293: $resulttext .= '<ul>';
4294: }
4295: if (ref($changes->{$role}{$key}) eq 'HASH') {
4296: if ($role ne 'login') {
4297: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
4298: }
4299: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 4300: if (($role eq 'login') && ($key eq 'showlogo')) {
4301: if ($confhash->{$role}{$key}{$item}) {
4302: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
4303: } else {
4304: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
4305: }
4306: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 4307: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
4308: } else {
1.12 raeburn 4309: my $newitem = $confhash->{$role}{$item};
4310: if ($key eq 'images') {
4311: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
4312: }
4313: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 4314: }
4315: }
4316: if ($role ne 'login') {
4317: $resulttext .= '</ul></li>';
4318: }
4319: } else {
4320: if ($confhash->{$role}{$key} eq '') {
4321: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
4322: } else {
4323: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
4324: }
4325: }
4326: if ($role ne 'login') {
4327: $resulttext .= '</ul>';
4328: }
4329: }
4330: }
4331: }
1.3 raeburn 4332: return $resulttext;
1.1 raeburn 4333: }
4334:
1.9 raeburn 4335: sub thumb_dimensions {
4336: return ('200','50');
4337: }
4338:
1.16 raeburn 4339: sub check_dimensions {
4340: my ($inputfile) = @_;
4341: my ($fullwidth,$fullheight);
4342: if ($inputfile =~ m|^[/\w.\-]+$|) {
4343: if (open(PIPE,"identify $inputfile 2>&1 |")) {
4344: my $imageinfo = <PIPE>;
4345: if (!close(PIPE)) {
4346: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
4347: }
4348: chomp($imageinfo);
4349: my ($fullsize) =
1.21 raeburn 4350: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 4351: if ($fullsize) {
4352: ($fullwidth,$fullheight) = split(/x/,$fullsize);
4353: }
4354: }
4355: }
4356: return ($fullwidth,$fullheight);
4357: }
4358:
1.9 raeburn 4359: sub check_configuser {
4360: my ($uhome,$dom,$confname,$servadm) = @_;
4361: my ($configuserok,%currroles);
4362: if ($uhome eq 'no_host') {
4363: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
4364: my $configpass = &LONCAPA::Enrollment::create_password();
4365: $configuserok =
4366: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
4367: $configpass,'','','','','',undef,$servadm);
4368: } else {
4369: $configuserok = 'ok';
4370: %currroles =
4371: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
4372: }
4373: return ($configuserok,%currroles);
4374: }
4375:
4376: sub check_authorstatus {
4377: my ($dom,$confname,%currroles) = @_;
4378: my $author_ok;
1.40 raeburn 4379: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 4380: my $start = time;
4381: my $end = 0;
4382: $author_ok =
4383: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 4384: 'au',$end,$start,'','','domconfig');
1.9 raeburn 4385: } else {
4386: $author_ok = 'ok';
4387: }
4388: return $author_ok;
4389: }
4390:
4391: sub publishlogo {
1.46 raeburn 4392: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 4393: my ($output,$fname,$logourl);
4394: if ($action eq 'upload') {
4395: $fname=$env{'form.'.$formname.'.filename'};
4396: chop($env{'form.'.$formname});
4397: } else {
4398: ($fname) = ($formname =~ /([^\/]+)$/);
4399: }
1.46 raeburn 4400: if ($savefileas ne '') {
4401: $fname = $savefileas;
4402: }
1.9 raeburn 4403: $fname=&Apache::lonnet::clean_filename($fname);
4404: # See if there is anything left
4405: unless ($fname) { return ('error: no uploaded file'); }
4406: $fname="$subdir/$fname";
4407: my $filepath='/home/'.$confname.'/public_html';
4408: my ($fnamepath,$file,$fetchthumb);
4409: $file=$fname;
4410: if ($fname=~m|/|) {
4411: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
4412: }
4413: my @parts=split(/\//,$filepath.'/'.$fnamepath);
4414: my $count;
4415: for ($count=4;$count<=$#parts;$count++) {
4416: $filepath.="/$parts[$count]";
4417: if ((-e $filepath)!=1) {
4418: mkdir($filepath,02770);
4419: }
4420: }
4421: # Check for bad extension and disallow upload
4422: if ($file=~/\.(\w+)$/ &&
4423: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
4424: $output =
4425: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
4426: } elsif ($file=~/\.(\w+)$/ &&
4427: !defined(&Apache::loncommon::fileembstyle($1))) {
4428: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
4429: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 4430: $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 4431: } elsif (-d "$filepath/$file") {
4432: $output = &mt('File name is a directory name - rename the file and re-upload');
4433: } else {
4434: my $source = $filepath.'/'.$file;
4435: my $logfile;
4436: if (!open($logfile,">>$source".'.log')) {
4437: return (&mt('No write permission to Construction Space'));
4438: }
4439: print $logfile
4440: "\n================= Publish ".localtime()." ================\n".
4441: $env{'user.name'}.':'.$env{'user.domain'}."\n";
4442: # Save the file
4443: if (!open(FH,'>'.$source)) {
4444: &Apache::lonnet::logthis('Failed to create '.$source);
4445: return (&mt('Failed to create file'));
4446: }
4447: if ($action eq 'upload') {
4448: if (!print FH ($env{'form.'.$formname})) {
4449: &Apache::lonnet::logthis('Failed to write to '.$source);
4450: return (&mt('Failed to write file'));
4451: }
4452: } else {
4453: my $original = &Apache::lonnet::filelocation('',$formname);
4454: if(!copy($original,$source)) {
4455: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
4456: return (&mt('Failed to write file'));
4457: }
4458: }
4459: close(FH);
4460: chmod(0660, $source); # Permissions to rw-rw---.
4461:
4462: my $docroot=$r->dir_config('lonDocRoot');
4463: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
4464: my $copyfile=$targetdir.'/'.$file;
4465:
4466: my @parts=split(/\//,$targetdir);
4467: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
4468: for (my $count=5;$count<=$#parts;$count++) {
4469: $path.="/$parts[$count]";
4470: if (!-e $path) {
4471: print $logfile "\nCreating directory ".$path;
4472: mkdir($path,02770);
4473: }
4474: }
4475: my $versionresult;
4476: if (-e $copyfile) {
4477: $versionresult = &logo_versioning($targetdir,$file,$logfile);
4478: } else {
4479: $versionresult = 'ok';
4480: }
4481: if ($versionresult eq 'ok') {
4482: if (copy($source,$copyfile)) {
4483: print $logfile "\nCopied original source to ".$copyfile."\n";
4484: $output = 'ok';
4485: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.138.2.10 raeburn 4486: push(@{$modified_urls},[$copyfile,$source]);
4487: my $metaoutput =
4488: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
4489: unless ($registered_cleanup) {
4490: my $handlers = $r->get_handlers('PerlCleanupHandler');
4491: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
4492: $registered_cleanup=1;
4493: }
1.9 raeburn 4494: } else {
4495: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
4496: $output = &mt('Failed to copy file to RES space').", $!";
4497: }
4498: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
4499: my $inputfile = $filepath.'/'.$file;
4500: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 4501: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
4502: if ($fullwidth ne '' && $fullheight ne '') {
4503: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
4504: my $thumbsize = $thumbwidth.'x'.$thumbheight;
4505: system("convert -sample $thumbsize $inputfile $outfile");
4506: chmod(0660, $filepath.'/tn-'.$file);
4507: if (-e $outfile) {
4508: my $copyfile=$targetdir.'/tn-'.$file;
4509: if (copy($outfile,$copyfile)) {
4510: print $logfile "\nCopied source to ".$copyfile."\n";
1.138.2.10 raeburn 4511: my $thumb_metaoutput =
4512: &write_metadata($dom,$confname,$formname,
4513: $targetdir,'tn-'.$file,$logfile);
4514: push(@{$modified_urls},[$copyfile,$outfile]);
4515: unless ($registered_cleanup) {
4516: my $handlers = $r->get_handlers('PerlCleanupHandler');
4517: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
4518: $registered_cleanup=1;
4519: }
1.16 raeburn 4520: } else {
4521: print $logfile "\nUnable to write ".$copyfile.
4522: ':'.$!."\n";
4523: }
4524: }
1.9 raeburn 4525: }
4526: }
4527: }
4528: } else {
4529: $output = $versionresult;
4530: }
4531: }
4532: return ($output,$logourl);
4533: }
4534:
4535: sub logo_versioning {
4536: my ($targetdir,$file,$logfile) = @_;
4537: my $target = $targetdir.'/'.$file;
4538: my ($maxversion,$fn,$extn,$output);
4539: $maxversion = 0;
4540: if ($file =~ /^(.+)\.(\w+)$/) {
4541: $fn=$1;
4542: $extn=$2;
4543: }
4544: opendir(DIR,$targetdir);
4545: while (my $filename=readdir(DIR)) {
4546: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
4547: $maxversion=($1>$maxversion)?$1:$maxversion;
4548: }
4549: }
4550: $maxversion++;
4551: print $logfile "\nCreating old version ".$maxversion."\n";
4552: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
4553: if (copy($target,$copyfile)) {
4554: print $logfile "Copied old target to ".$copyfile."\n";
4555: $copyfile=$copyfile.'.meta';
4556: if (copy($target.'.meta',$copyfile)) {
4557: print $logfile "Copied old target metadata to ".$copyfile."\n";
4558: $output = 'ok';
4559: } else {
4560: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
4561: $output = &mt('Failed to copy old meta').", $!, ";
4562: }
4563: } else {
4564: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
4565: $output = &mt('Failed to copy old target').", $!, ";
4566: }
4567: return $output;
4568: }
4569:
4570: sub write_metadata {
4571: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
4572: my (%metadatafields,%metadatakeys,$output);
4573: $metadatafields{'title'}=$formname;
4574: $metadatafields{'creationdate'}=time;
4575: $metadatafields{'lastrevisiondate'}=time;
4576: $metadatafields{'copyright'}='public';
4577: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
4578: $env{'user.domain'};
4579: $metadatafields{'authorspace'}=$confname.':'.$dom;
4580: $metadatafields{'domain'}=$dom;
4581: {
4582: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
4583: my $mfh;
1.138.2.10 raeburn 4584: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
4585: foreach (sort keys %metadatafields) {
4586: unless ($_=~/\./) {
4587: my $unikey=$_;
4588: $unikey=~/^([A-Za-z]+)/;
4589: my $tag=$1;
4590: $tag=~tr/A-Z/a-z/;
4591: print $mfh "\n\<$tag";
4592: foreach (split(/\,/,$metadatakeys{$unikey})) {
4593: my $value=$metadatafields{$unikey.'.'.$_};
4594: $value=~s/\"/\'\'/g;
4595: print $mfh ' '.$_.'="'.$value.'"';
4596: }
4597: print $mfh '>'.
4598: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
4599: .'</'.$tag.'>';
4600: }
4601: }
4602: $output = 'ok';
4603: print $logfile "\nWrote metadata";
4604: close($mfh);
4605: } else {
4606: print $logfile "\nFailed to open metadata file";
1.9 raeburn 4607: $output = &mt('Could not write metadata');
4608: }
4609: }
1.138.2.10 raeburn 4610: return $output;
4611: }
4612:
4613: sub notifysubscribed {
4614: foreach my $targetsource (@{$modified_urls}){
4615: next unless (ref($targetsource) eq 'ARRAY');
4616: my ($target,$source)=@{$targetsource};
4617: if ($source ne '') {
4618: if (open(my $logfh,'>>'.$source.'.log')) {
4619: print $logfh "\nCleanup phase: Notifications\n";
4620: my @subscribed=&subscribed_hosts($target);
4621: foreach my $subhost (@subscribed) {
4622: print $logfh "\nNotifying host ".$subhost.':';
4623: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
4624: print $logfh $reply;
4625: }
4626: my @subscribedmeta=&subscribed_hosts("$target.meta");
4627: foreach my $subhost (@subscribedmeta) {
4628: print $logfh "\nNotifying host for metadata only ".$subhost.':';
4629: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
4630: $subhost);
4631: print $logfh $reply;
4632: }
4633: print $logfh "\n============ Done ============\n";
4634: close(logfh);
4635: }
4636: }
4637: }
4638: return OK;
4639: }
4640:
4641: sub subscribed_hosts {
4642: my ($target) = @_;
4643: my @subscribed;
4644: if (open(my $fh,"<$target.subscription")) {
4645: while (my $subline=<$fh>) {
4646: if ($subline =~ /^($match_lonid):/) {
4647: my $host = $1;
4648: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
4649: unless (grep(/^\Q$host\E$/,@subscribed)) {
4650: push(@subscribed,$host);
4651: }
4652: }
4653: }
4654: }
4655: }
4656: return @subscribed;
1.9 raeburn 4657: }
4658:
4659: sub check_switchserver {
4660: my ($dom,$confname) = @_;
4661: my ($allowed,$switchserver);
4662: my $home = &Apache::lonnet::homeserver($confname,$dom);
4663: if ($home eq 'no_host') {
4664: $home = &Apache::lonnet::domain($dom,'primary');
4665: }
4666: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 4667: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
4668: if (!$allowed) {
4669: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 4670: }
4671: return $switchserver;
4672: }
4673:
1.1 raeburn 4674: sub modify_quotas {
1.86 raeburn 4675: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 4676: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
4677: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 4678: if ($action eq 'quotas') {
4679: $context = 'tools';
4680: } else {
4681: $context = $action;
4682: }
4683: if ($context eq 'requestcourses') {
1.98 raeburn 4684: @usertools = ('official','unofficial','community');
1.106 raeburn 4685: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 4686: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
4687: %titles = &courserequest_titles();
4688: $toolregexp = join('|',@usertools);
4689: %conditions = &courserequest_conditions();
1.86 raeburn 4690: } else {
4691: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 4692: %titles = &tool_titles();
1.86 raeburn 4693: }
1.72 raeburn 4694: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 4695: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 4696: foreach my $key (keys(%env)) {
1.101 raeburn 4697: if ($context eq 'requestcourses') {
4698: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
4699: my $item = $1;
4700: my $type = $2;
4701: if ($type =~ /^limit_(.+)/) {
4702: $limithash{$item}{$1} = $env{$key};
4703: } else {
4704: $confhash{$item}{$type} = $env{$key};
4705: }
4706: }
4707: } else {
1.86 raeburn 4708: if ($key =~ /^form\.quota_(.+)$/) {
4709: $confhash{'defaultquota'}{$1} = $env{$key};
4710: }
1.101 raeburn 4711: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
4712: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
4713: }
1.72 raeburn 4714: }
4715: }
1.102 raeburn 4716: if ($context eq 'requestcourses') {
4717: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
4718: @approvalnotify = sort(@approvalnotify);
4719: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
4720: if (ref($domconfig{$action}) eq 'HASH') {
4721: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
4722: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
4723: $changes{'notify'}{'approval'} = 1;
4724: }
4725: } else {
1.138.2.9 raeburn 4726: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 4727: $changes{'notify'}{'approval'} = 1;
4728: }
4729: }
4730: } else {
1.138.2.9 raeburn 4731: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 4732: $changes{'notify'}{'approval'} = 1;
4733: }
4734: }
4735: } else {
1.86 raeburn 4736: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
4737: }
1.72 raeburn 4738: foreach my $item (@usertools) {
4739: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 4740: my $unset;
1.101 raeburn 4741: if ($context eq 'requestcourses') {
1.104 raeburn 4742: $unset = '0';
4743: if ($type eq '_LC_adv') {
4744: $unset = '';
4745: }
1.101 raeburn 4746: if ($confhash{$item}{$type} eq 'autolimit') {
4747: $confhash{$item}{$type} .= '=';
4748: unless ($limithash{$item}{$type} =~ /\D/) {
4749: $confhash{$item}{$type} .= $limithash{$item}{$type};
4750: }
4751: }
1.72 raeburn 4752: } else {
1.101 raeburn 4753: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
4754: $confhash{$item}{$type} = 1;
4755: } else {
4756: $confhash{$item}{$type} = 0;
4757: }
1.72 raeburn 4758: }
1.86 raeburn 4759: if (ref($domconfig{$action}) eq 'HASH') {
4760: if (ref($domconfig{$action}{$item}) eq 'HASH') {
4761: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
4762: $changes{$item}{$type} = 1;
4763: }
4764: } else {
4765: if ($context eq 'requestcourses') {
1.104 raeburn 4766: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 4767: $changes{$item}{$type} = 1;
4768: }
4769: } else {
4770: if (!$confhash{$item}{$type}) {
4771: $changes{$item}{$type} = 1;
4772: }
4773: }
4774: }
4775: } else {
4776: if ($context eq 'requestcourses') {
1.104 raeburn 4777: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 4778: $changes{$item}{$type} = 1;
4779: }
4780: } else {
4781: if (!$confhash{$item}{$type}) {
4782: $changes{$item}{$type} = 1;
4783: }
4784: }
4785: }
1.1 raeburn 4786: }
4787: }
1.86 raeburn 4788: unless ($context eq 'requestcourses') {
4789: if (ref($domconfig{'quotas'}) eq 'HASH') {
4790: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
4791: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
4792: if (exists($confhash{'defaultquota'}{$key})) {
4793: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
4794: $changes{'defaultquota'}{$key} = 1;
4795: }
4796: } else {
4797: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 4798: }
4799: }
1.86 raeburn 4800: } else {
4801: foreach my $key (keys(%{$domconfig{'quotas'}})) {
4802: if (exists($confhash{'defaultquota'}{$key})) {
4803: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
4804: $changes{'defaultquota'}{$key} = 1;
4805: }
4806: } else {
4807: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 4808: }
1.1 raeburn 4809: }
4810: }
4811: }
1.86 raeburn 4812: if (ref($confhash{'defaultquota'}) eq 'HASH') {
4813: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
4814: if (ref($domconfig{'quotas'}) eq 'HASH') {
4815: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
4816: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
4817: $changes{'defaultquota'}{$key} = 1;
4818: }
4819: } else {
4820: if (!exists($domconfig{'quotas'}{$key})) {
4821: $changes{'defaultquota'}{$key} = 1;
4822: }
1.72 raeburn 4823: }
4824: } else {
1.86 raeburn 4825: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 4826: }
1.1 raeburn 4827: }
4828: }
4829: }
1.72 raeburn 4830:
4831: foreach my $key (keys(%confhash)) {
4832: $domdefaults{$key} = $confhash{$key};
4833: }
4834:
1.1 raeburn 4835: my %quotahash = (
1.86 raeburn 4836: $action => { %confhash }
1.1 raeburn 4837: );
4838: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
4839: $dom);
4840: if ($putresult eq 'ok') {
4841: if (keys(%changes) > 0) {
1.72 raeburn 4842: my $cachetime = 24*60*60;
4843: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
4844:
1.1 raeburn 4845: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 4846: unless ($context eq 'requestcourses') {
4847: if (ref($changes{'defaultquota'}) eq 'HASH') {
4848: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
4849: foreach my $type (@{$types},'default') {
4850: if (defined($changes{'defaultquota'}{$type})) {
4851: my $typetitle = $usertypes->{$type};
4852: if ($type eq 'default') {
4853: $typetitle = $othertitle;
4854: }
4855: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 4856: }
4857: }
1.86 raeburn 4858: $resulttext .= '</ul></li>';
1.72 raeburn 4859: }
4860: }
1.80 raeburn 4861: my %newenv;
1.72 raeburn 4862: foreach my $item (@usertools) {
4863: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 4864: my $newacc =
4865: &Apache::lonnet::usertools_access($env{'user.name'},
4866: $env{'user.domain'},
1.86 raeburn 4867: $item,'reload',$context);
4868: if ($context eq 'requestcourses') {
1.108 raeburn 4869: if ($env{'environment.canrequest.'.$item} ne $newacc) {
4870: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 4871: }
4872: } else {
4873: if ($env{'environment.availabletools.'.$item} ne $newacc) {
4874: $newenv{'environment.availabletools.'.$item} = $newacc;
4875: }
1.80 raeburn 4876: }
1.72 raeburn 4877: $resulttext .= '<li>'.$titles{$item}.'<ul>';
4878: foreach my $type (@{$types},'default','_LC_adv') {
4879: if ($changes{$item}{$type}) {
4880: my $typetitle = $usertypes->{$type};
4881: if ($type eq 'default') {
4882: $typetitle = $othertitle;
4883: } elsif ($type eq '_LC_adv') {
4884: $typetitle = 'LON-CAPA Advanced Users';
4885: }
4886: if ($confhash{$item}{$type}) {
1.101 raeburn 4887: if ($context eq 'requestcourses') {
4888: my $cond;
4889: if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
4890: if ($1 eq '') {
4891: $cond = &mt('(Automatic processing of any request).');
4892: } else {
4893: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
4894: }
4895: } else {
4896: $cond = $conditions{$confhash{$item}{$type}};
4897: }
4898: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
4899: } else {
4900: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
4901: }
1.72 raeburn 4902: } else {
1.104 raeburn 4903: if ($type eq '_LC_adv') {
4904: if ($confhash{$item}{$type} eq '0') {
4905: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
4906: } else {
4907: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
4908: }
4909: } else {
4910: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
4911: }
1.72 raeburn 4912: }
4913: }
1.26 raeburn 4914: }
1.72 raeburn 4915: $resulttext .= '</ul></li>';
1.26 raeburn 4916: }
1.1 raeburn 4917: }
1.102 raeburn 4918: if ($action eq 'requestcourses') {
4919: if (ref($changes{'notify'}) eq 'HASH') {
4920: if ($changes{'notify'}{'approval'}) {
4921: if (ref($confhash{'notify'}) eq 'HASH') {
4922: if ($confhash{'notify'}{'approval'}) {
4923: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
4924: } else {
4925: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
4926: }
4927: }
4928: }
4929: }
4930: }
1.1 raeburn 4931: $resulttext .= '</ul>';
1.80 raeburn 4932: if (keys(%newenv)) {
4933: &Apache::lonnet::appenv(\%newenv);
4934: }
1.1 raeburn 4935: } else {
1.86 raeburn 4936: if ($context eq 'requestcourses') {
4937: $resulttext = &mt('No changes made to rights to request creation of courses.');
4938: } else {
1.90 weissno 4939: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 4940: }
1.1 raeburn 4941: }
4942: } else {
1.11 albertel 4943: $resulttext = '<span class="LC_error">'.
4944: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4945: }
1.3 raeburn 4946: return $resulttext;
1.1 raeburn 4947: }
4948:
1.3 raeburn 4949: sub modify_autoenroll {
4950: my ($dom,%domconfig) = @_;
1.1 raeburn 4951: my ($resulttext,%changes);
4952: my %currautoenroll;
4953: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4954: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
4955: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
4956: }
4957: }
4958: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
4959: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 4960: sender => 'Sender for notification messages',
4961: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 4962: my @offon = ('off','on');
1.17 raeburn 4963: my $sender_uname = $env{'form.sender_uname'};
4964: my $sender_domain = $env{'form.sender_domain'};
4965: if ($sender_domain eq '') {
4966: $sender_uname = '';
4967: } elsif ($sender_uname eq '') {
4968: $sender_domain = '';
4969: }
1.129 raeburn 4970: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 4971: my %autoenrollhash = (
1.129 raeburn 4972: autoenroll => { 'run' => $env{'form.autoenroll_run'},
4973: 'sender_uname' => $sender_uname,
4974: 'sender_domain' => $sender_domain,
4975: 'co-owners' => $coowners,
1.1 raeburn 4976: }
4977: );
1.4 raeburn 4978: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
4979: $dom);
1.1 raeburn 4980: if ($putresult eq 'ok') {
4981: if (exists($currautoenroll{'run'})) {
4982: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
4983: $changes{'run'} = 1;
4984: }
4985: } elsif ($autorun) {
4986: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 4987: $changes{'run'} = 1;
1.1 raeburn 4988: }
4989: }
1.17 raeburn 4990: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 4991: $changes{'sender'} = 1;
4992: }
1.17 raeburn 4993: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 4994: $changes{'sender'} = 1;
4995: }
1.129 raeburn 4996: if ($currautoenroll{'co-owners'} ne '') {
4997: if ($currautoenroll{'co-owners'} ne $coowners) {
4998: $changes{'coowners'} = 1;
4999: }
5000: } elsif ($coowners) {
5001: $changes{'coowners'} = 1;
5002: }
1.1 raeburn 5003: if (keys(%changes) > 0) {
5004: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 5005: if ($changes{'run'}) {
1.1 raeburn 5006: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
5007: }
5008: if ($changes{'sender'}) {
1.17 raeburn 5009: if ($sender_uname eq '' || $sender_domain eq '') {
5010: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
5011: } else {
5012: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
5013: }
1.1 raeburn 5014: }
1.129 raeburn 5015: if ($changes{'coowners'}) {
5016: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
5017: &Apache::loncommon::devalidate_domconfig_cache($dom);
5018: }
1.1 raeburn 5019: $resulttext .= '</ul>';
5020: } else {
5021: $resulttext = &mt('No changes made to auto-enrollment settings');
5022: }
5023: } else {
1.11 albertel 5024: $resulttext = '<span class="LC_error">'.
5025: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5026: }
1.3 raeburn 5027: return $resulttext;
1.1 raeburn 5028: }
5029:
5030: sub modify_autoupdate {
1.3 raeburn 5031: my ($dom,%domconfig) = @_;
1.1 raeburn 5032: my ($resulttext,%currautoupdate,%fields,%changes);
5033: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
5034: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
5035: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
5036: }
5037: }
5038: my @offon = ('off','on');
5039: my %title = &Apache::lonlocal::texthash (
5040: run => 'Auto-update:',
5041: classlists => 'Updates to user information in classlists?'
5042: );
1.44 raeburn 5043: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5044: my %fieldtitles = &Apache::lonlocal::texthash (
5045: id => 'Student/Employee ID',
1.20 raeburn 5046: permanentemail => 'E-mail address',
1.1 raeburn 5047: lastname => 'Last Name',
5048: firstname => 'First Name',
5049: middlename => 'Middle Name',
1.132 raeburn 5050: generation => 'Generation',
1.1 raeburn 5051: );
1.138.2.7 raeburn 5052: $othertitle = &mt('All users');
1.1 raeburn 5053: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 5054: $othertitle = &mt('Other users');
1.1 raeburn 5055: }
5056: foreach my $key (keys(%env)) {
5057: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 5058: my ($usertype,$item) = ($1,$2);
5059: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
5060: if ($usertype eq 'default') {
5061: push(@{$fields{$1}},$2);
5062: } elsif (ref($types) eq 'ARRAY') {
5063: if (grep(/^\Q$usertype\E$/,@{$types})) {
5064: push(@{$fields{$1}},$2);
5065: }
5066: }
5067: }
1.1 raeburn 5068: }
5069: }
1.131 raeburn 5070: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
5071: @lockablenames = sort(@lockablenames);
5072: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
5073: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5074: if (@changed) {
5075: $changes{'lockablenames'} = 1;
5076: }
5077: } else {
5078: if (@lockablenames) {
5079: $changes{'lockablenames'} = 1;
5080: }
5081: }
1.1 raeburn 5082: my %updatehash = (
5083: autoupdate => { run => $env{'form.autoupdate_run'},
5084: classlists => $env{'form.classlists'},
5085: fields => {%fields},
1.131 raeburn 5086: lockablenames => \@lockablenames,
1.1 raeburn 5087: }
5088: );
5089: foreach my $key (keys(%currautoupdate)) {
5090: if (($key eq 'run') || ($key eq 'classlists')) {
5091: if (exists($updatehash{autoupdate}{$key})) {
5092: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
5093: $changes{$key} = 1;
5094: }
5095: }
5096: } elsif ($key eq 'fields') {
5097: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 5098: foreach my $item (@{$types},'default') {
1.1 raeburn 5099: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
5100: my $change = 0;
5101: foreach my $type (@{$currautoupdate{$key}{$item}}) {
5102: if (!exists($fields{$item})) {
5103: $change = 1;
1.132 raeburn 5104: last;
1.1 raeburn 5105: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 5106: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 5107: $change = 1;
1.132 raeburn 5108: last;
1.1 raeburn 5109: }
5110: }
5111: }
5112: if ($change) {
5113: push(@{$changes{$key}},$item);
5114: }
1.26 raeburn 5115: }
1.1 raeburn 5116: }
5117: }
1.131 raeburn 5118: } elsif ($key eq 'lockablenames') {
5119: if (ref($currautoupdate{$key}) eq 'ARRAY') {
5120: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
5121: if (@changed) {
5122: $changes{'lockablenames'} = 1;
5123: }
5124: } else {
5125: if (@lockablenames) {
5126: $changes{'lockablenames'} = 1;
5127: }
5128: }
5129: }
5130: }
5131: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
5132: if (@lockablenames) {
5133: $changes{'lockablenames'} = 1;
1.1 raeburn 5134: }
5135: }
1.26 raeburn 5136: foreach my $item (@{$types},'default') {
5137: if (defined($fields{$item})) {
5138: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 5139: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
5140: my $change = 0;
5141: if (ref($fields{$item}) eq 'ARRAY') {
5142: foreach my $type (@{$fields{$item}}) {
5143: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
5144: $change = 1;
5145: last;
5146: }
5147: }
5148: }
5149: if ($change) {
5150: push(@{$changes{'fields'}},$item);
5151: }
5152: } else {
1.26 raeburn 5153: push(@{$changes{'fields'}},$item);
5154: }
5155: } else {
5156: push(@{$changes{'fields'}},$item);
1.1 raeburn 5157: }
5158: }
5159: }
5160: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
5161: $dom);
5162: if ($putresult eq 'ok') {
5163: if (keys(%changes) > 0) {
5164: $resulttext = &mt('Changes made:').'<ul>';
5165: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 5166: if ($key eq 'lockablenames') {
5167: $resulttext .= '<li>';
5168: if (@lockablenames) {
5169: $usertypes->{'default'} = $othertitle;
5170: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
5171: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
5172: } else {
5173: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
5174: }
5175: $resulttext .= '</li>';
5176: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 5177: foreach my $item (@{$changes{$key}}) {
5178: my @newvalues;
5179: foreach my $type (@{$fields{$item}}) {
5180: push(@newvalues,$fieldtitles{$type});
5181: }
1.3 raeburn 5182: my $newvaluestr;
5183: if (@newvalues > 0) {
5184: $newvaluestr = join(', ',@newvalues);
5185: } else {
5186: $newvaluestr = &mt('none');
1.6 raeburn 5187: }
1.1 raeburn 5188: if ($item eq 'default') {
1.26 raeburn 5189: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 5190: } else {
1.26 raeburn 5191: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 5192: }
5193: }
5194: } else {
5195: my $newvalue;
5196: if ($key eq 'run') {
5197: $newvalue = $offon[$env{'form.autoupdate_run'}];
5198: } else {
5199: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 5200: }
1.1 raeburn 5201: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
5202: }
5203: }
5204: $resulttext .= '</ul>';
5205: } else {
1.3 raeburn 5206: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 5207: }
5208: } else {
1.11 albertel 5209: $resulttext = '<span class="LC_error">'.
5210: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5211: }
1.3 raeburn 5212: return $resulttext;
1.1 raeburn 5213: }
5214:
1.125 raeburn 5215: sub modify_autocreate {
5216: my ($dom,%domconfig) = @_;
5217: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
5218: if (ref($domconfig{'autocreate'}) eq 'HASH') {
5219: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
5220: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
5221: }
5222: }
5223: my %title= ( xml => 'Auto-creation of courses in XML course description files',
5224: req => 'Auto-creation of validated requests for official courses',
5225: xmldc => 'Identity of course creator of courses from XML files',
5226: );
5227: my @types = ('xml','req');
5228: foreach my $item (@types) {
5229: $newvals{$item} = $env{'form.autocreate_'.$item};
5230: $newvals{$item} =~ s/\D//g;
5231: $newvals{$item} = 0 if ($newvals{$item} eq '');
5232: }
5233: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
5234: my %domcoords = &get_active_dcs($dom);
5235: unless (exists($domcoords{$newvals{'xmldc'}})) {
5236: $newvals{'xmldc'} = '';
5237: }
5238: %autocreatehash = (
5239: autocreate => { xml => $newvals{'xml'},
5240: req => $newvals{'req'},
5241: }
5242: );
5243: if ($newvals{'xmldc'} ne '') {
5244: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
5245: }
5246: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
5247: $dom);
5248: if ($putresult eq 'ok') {
5249: my @items = @types;
5250: if ($newvals{'xml'}) {
5251: push(@items,'xmldc');
5252: }
5253: foreach my $item (@items) {
5254: if (exists($currautocreate{$item})) {
5255: if ($currautocreate{$item} ne $newvals{$item}) {
5256: $changes{$item} = 1;
5257: }
5258: } elsif ($newvals{$item}) {
5259: $changes{$item} = 1;
5260: }
5261: }
5262: if (keys(%changes) > 0) {
5263: my @offon = ('off','on');
5264: $resulttext = &mt('Changes made:').'<ul>';
5265: foreach my $item (@types) {
5266: if ($changes{$item}) {
5267: my $newtxt = $offon[$newvals{$item}];
5268: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5269: }
5270: }
5271: if ($changes{'xmldc'}) {
5272: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
5273: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
5274: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
5275: }
5276: $resulttext .= '</ul>';
5277: } else {
5278: $resulttext = &mt('No changes made to auto-creation settings');
5279: }
5280: } else {
5281: $resulttext = '<span class="LC_error">'.
5282: &mt('An error occurred: [_1]',$putresult).'</span>';
5283: }
5284: return $resulttext;
5285: }
5286:
1.23 raeburn 5287: sub modify_directorysrch {
5288: my ($dom,%domconfig) = @_;
5289: my ($resulttext,%changes);
5290: my %currdirsrch;
5291: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
5292: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
5293: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
5294: }
5295: }
5296: my %title = ( available => 'Directory search available',
1.24 raeburn 5297: localonly => 'Other domains can search',
1.23 raeburn 5298: searchby => 'Search types',
5299: searchtypes => 'Search latitude');
5300: my @offon = ('off','on');
1.24 raeburn 5301: my @otherdoms = ('Yes','No');
1.23 raeburn 5302:
1.25 raeburn 5303: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 5304: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
5305: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
5306:
1.44 raeburn 5307: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 5308: if (keys(%{$usertypes}) == 0) {
5309: @cansearch = ('default');
5310: } else {
5311: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
5312: foreach my $type (@{$currdirsrch{'cansearch'}}) {
5313: if (!grep(/^\Q$type\E$/,@cansearch)) {
5314: push(@{$changes{'cansearch'}},$type);
5315: }
1.23 raeburn 5316: }
1.26 raeburn 5317: foreach my $type (@cansearch) {
5318: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
5319: push(@{$changes{'cansearch'}},$type);
5320: }
1.23 raeburn 5321: }
1.26 raeburn 5322: } else {
5323: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 5324: }
5325: }
5326:
5327: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
5328: foreach my $by (@{$currdirsrch{'searchby'}}) {
5329: if (!grep(/^\Q$by\E$/,@searchby)) {
5330: push(@{$changes{'searchby'}},$by);
5331: }
5332: }
5333: foreach my $by (@searchby) {
5334: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
5335: push(@{$changes{'searchby'}},$by);
5336: }
5337: }
5338: } else {
5339: push(@{$changes{'searchby'}},@searchby);
5340: }
1.25 raeburn 5341:
5342: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
5343: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
5344: if (!grep(/^\Q$type\E$/,@searchtypes)) {
5345: push(@{$changes{'searchtypes'}},$type);
5346: }
5347: }
5348: foreach my $type (@searchtypes) {
5349: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
5350: push(@{$changes{'searchtypes'}},$type);
5351: }
5352: }
5353: } else {
5354: if (exists($currdirsrch{'searchtypes'})) {
5355: foreach my $type (@searchtypes) {
5356: if ($type ne $currdirsrch{'searchtypes'}) {
5357: push(@{$changes{'searchtypes'}},$type);
5358: }
5359: }
5360: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
5361: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
5362: }
5363: } else {
5364: push(@{$changes{'searchtypes'}},@searchtypes);
5365: }
5366: }
5367:
1.23 raeburn 5368: my %dirsrch_hash = (
5369: directorysrch => { available => $env{'form.dirsrch_available'},
5370: cansearch => \@cansearch,
1.24 raeburn 5371: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 5372: searchby => \@searchby,
1.25 raeburn 5373: searchtypes => \@searchtypes,
1.23 raeburn 5374: }
5375: );
5376: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
5377: $dom);
5378: if ($putresult eq 'ok') {
5379: if (exists($currdirsrch{'available'})) {
5380: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
5381: $changes{'available'} = 1;
5382: }
5383: } else {
5384: if ($env{'form.dirsrch_available'} eq '1') {
5385: $changes{'available'} = 1;
5386: }
5387: }
1.24 raeburn 5388: if (exists($currdirsrch{'localonly'})) {
5389: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
5390: $changes{'localonly'} = 1;
5391: }
5392: } else {
5393: if ($env{'form.dirsrch_localonly'} eq '1') {
5394: $changes{'localonly'} = 1;
5395: }
5396: }
1.23 raeburn 5397: if (keys(%changes) > 0) {
5398: $resulttext = &mt('Changes made:').'<ul>';
5399: if ($changes{'available'}) {
5400: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
5401: }
1.24 raeburn 5402: if ($changes{'localonly'}) {
5403: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
5404: }
5405:
1.23 raeburn 5406: if (ref($changes{'cansearch'}) eq 'ARRAY') {
5407: my $chgtext;
1.26 raeburn 5408: if (ref($usertypes) eq 'HASH') {
5409: if (keys(%{$usertypes}) > 0) {
5410: foreach my $type (@{$types}) {
5411: if (grep(/^\Q$type\E$/,@cansearch)) {
5412: $chgtext .= $usertypes->{$type}.'; ';
5413: }
5414: }
5415: if (grep(/^default$/,@cansearch)) {
5416: $chgtext .= $othertitle;
5417: } else {
5418: $chgtext =~ s/\; $//;
5419: }
5420: $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
1.23 raeburn 5421: }
5422: }
5423: }
5424: if (ref($changes{'searchby'}) eq 'ARRAY') {
5425: my ($searchtitles,$titleorder) = &sorted_searchtitles();
5426: my $chgtext;
5427: foreach my $type (@{$titleorder}) {
5428: if (grep(/^\Q$type\E$/,@searchby)) {
5429: if (defined($searchtitles->{$type})) {
5430: $chgtext .= $searchtitles->{$type}.'; ';
5431: }
5432: }
5433: }
5434: $chgtext =~ s/\; $//;
5435: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
5436: }
1.25 raeburn 5437: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
5438: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
5439: my $chgtext;
5440: foreach my $type (@{$srchtypeorder}) {
5441: if (grep(/^\Q$type\E$/,@searchtypes)) {
5442: if (defined($srchtypes_desc->{$type})) {
5443: $chgtext .= $srchtypes_desc->{$type}.'; ';
5444: }
5445: }
5446: }
5447: $chgtext =~ s/\; $//;
5448: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 5449: }
5450: $resulttext .= '</ul>';
5451: } else {
5452: $resulttext = &mt('No changes made to institution directory search settings');
5453: }
5454: } else {
5455: $resulttext = '<span class="LC_error">'.
1.27 raeburn 5456: &mt('An error occurred: [_1]',$putresult).'</span>';
5457: }
5458: return $resulttext;
5459: }
5460:
1.28 raeburn 5461: sub modify_contacts {
5462: my ($dom,%domconfig) = @_;
5463: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
5464: if (ref($domconfig{'contacts'}) eq 'HASH') {
5465: foreach my $key (keys(%{$domconfig{'contacts'}})) {
5466: $currsetting{$key} = $domconfig{'contacts'}{$key};
5467: }
5468: }
1.134 raeburn 5469: my (%others,%to,%bcc);
1.28 raeburn 5470: my @contacts = ('supportemail','adminemail');
1.102 raeburn 5471: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
5472: 'requestsmail');
1.28 raeburn 5473: foreach my $type (@mailings) {
5474: @{$newsetting{$type}} =
5475: &Apache::loncommon::get_env_multiple('form.'.$type);
5476: foreach my $item (@contacts) {
5477: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
5478: $contacts_hash{contacts}{$type}{$item} = 1;
5479: } else {
5480: $contacts_hash{contacts}{$type}{$item} = 0;
5481: }
5482: }
5483: $others{$type} = $env{'form.'.$type.'_others'};
5484: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 5485: if ($type eq 'helpdeskmail') {
5486: $bcc{$type} = $env{'form.'.$type.'_bcc'};
5487: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
5488: }
1.28 raeburn 5489: }
5490: foreach my $item (@contacts) {
5491: $to{$item} = $env{'form.'.$item};
5492: $contacts_hash{'contacts'}{$item} = $to{$item};
5493: }
5494: if (keys(%currsetting) > 0) {
5495: foreach my $item (@contacts) {
5496: if ($to{$item} ne $currsetting{$item}) {
5497: $changes{$item} = 1;
5498: }
5499: }
5500: foreach my $type (@mailings) {
5501: foreach my $item (@contacts) {
5502: if (ref($currsetting{$type}) eq 'HASH') {
5503: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
5504: push(@{$changes{$type}},$item);
5505: }
5506: } else {
5507: push(@{$changes{$type}},@{$newsetting{$type}});
5508: }
5509: }
5510: if ($others{$type} ne $currsetting{$type}{'others'}) {
5511: push(@{$changes{$type}},'others');
5512: }
1.134 raeburn 5513: if ($type eq 'helpdeskmail') {
5514: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
5515: push(@{$changes{$type}},'bcc');
5516: }
5517: }
1.28 raeburn 5518: }
5519: } else {
5520: my %default;
5521: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
5522: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
5523: $default{'errormail'} = 'adminemail';
5524: $default{'packagesmail'} = 'adminemail';
5525: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 5526: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 5527: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 5528: foreach my $item (@contacts) {
5529: if ($to{$item} ne $default{$item}) {
5530: $changes{$item} = 1;
5531: }
5532: }
5533: foreach my $type (@mailings) {
5534: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
5535:
5536: push(@{$changes{$type}},@{$newsetting{$type}});
5537: }
5538: if ($others{$type} ne '') {
5539: push(@{$changes{$type}},'others');
1.134 raeburn 5540: }
5541: if ($type eq 'helpdeskmail') {
5542: if ($bcc{$type} ne '') {
5543: push(@{$changes{$type}},'bcc');
5544: }
5545: }
1.28 raeburn 5546: }
5547: }
5548: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
5549: $dom);
5550: if ($putresult eq 'ok') {
5551: if (keys(%changes) > 0) {
5552: my ($titles,$short_titles) = &contact_titles();
5553: $resulttext = &mt('Changes made:').'<ul>';
5554: foreach my $item (@contacts) {
5555: if ($changes{$item}) {
5556: $resulttext .= '<li>'.$titles->{$item}.
5557: &mt(' set to: ').
5558: '<span class="LC_cusr_emph">'.
5559: $to{$item}.'</span></li>';
5560: }
5561: }
5562: foreach my $type (@mailings) {
5563: if (ref($changes{$type}) eq 'ARRAY') {
5564: $resulttext .= '<li>'.$titles->{$type}.': ';
5565: my @text;
5566: foreach my $item (@{$newsetting{$type}}) {
5567: push(@text,$short_titles->{$item});
5568: }
5569: if ($others{$type} ne '') {
5570: push(@text,$others{$type});
5571: }
5572: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 5573: join(', ',@text).'</span>';
5574: if ($type eq 'helpdeskmail') {
5575: if ($bcc{$type} ne '') {
5576: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
5577: }
5578: }
5579: $resulttext .= '</li>';
1.28 raeburn 5580: }
5581: }
5582: $resulttext .= '</ul>';
5583: } else {
1.34 raeburn 5584: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 5585: }
5586: } else {
5587: $resulttext = '<span class="LC_error">'.
5588: &mt('An error occurred: [_1].',$putresult).'</span>';
5589: }
5590: return $resulttext;
5591: }
5592:
5593: sub modify_usercreation {
1.27 raeburn 5594: my ($dom,%domconfig) = @_;
1.34 raeburn 5595: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 5596: my $warningmsg;
1.27 raeburn 5597: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5598: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
5599: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
5600: }
5601: }
5602: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 5603: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 5604: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 5605: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 5606: foreach my $item(@contexts) {
1.45 raeburn 5607: if ($item eq 'selfcreate') {
1.50 raeburn 5608: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 5609: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
5610: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 5611: if (ref($cancreate{$item}) eq 'ARRAY') {
5612: if (grep(/^login$/,@{$cancreate{$item}})) {
5613: $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.').' '.&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.');
5614: }
1.43 raeburn 5615: }
5616: }
1.50 raeburn 5617: } else {
5618: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 5619: }
1.34 raeburn 5620: }
1.93 raeburn 5621: my ($othertitle,$usertypes,$types) =
5622: &Apache::loncommon::sorted_inst_types($dom);
5623: if (ref($types) eq 'ARRAY') {
5624: if (@{$types} > 0) {
5625: @{$cancreate{'statustocreate'}} =
5626: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 5627: } else {
5628: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 5629: }
5630: push(@contexts,'statustocreate');
5631: }
1.34 raeburn 5632: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
5633: foreach my $item (@contexts) {
1.93 raeburn 5634: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
5635: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 5636: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 5637: if (ref($cancreate{$item}) eq 'ARRAY') {
5638: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
5639: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5640: push(@{$changes{'cancreate'}},$item);
5641: }
1.50 raeburn 5642: }
5643: }
5644: }
5645: } else {
5646: if ($curr_usercreation{'cancreate'}{$item} eq '') {
5647: if (@{$cancreate{$item}} > 0) {
5648: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5649: push(@{$changes{'cancreate'}},$item);
5650: }
5651: }
5652: } else {
5653: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
5654: if (@{$cancreate{$item}} < 3) {
5655: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5656: push(@{$changes{'cancreate'}},$item);
5657: }
5658: }
5659: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
5660: if (@{$cancreate{$item}} > 0) {
5661: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5662: push(@{$changes{'cancreate'}},$item);
5663: }
5664: }
5665: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
5666: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5667: push(@{$changes{'cancreate'}},$item);
5668: }
5669: }
5670: }
5671: }
5672: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5673: foreach my $type (@{$cancreate{$item}}) {
5674: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
5675: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
5676: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5677: push(@{$changes{'cancreate'}},$item);
5678: }
5679: }
5680: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
5681: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
5682: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
5683: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
5684: push(@{$changes{'cancreate'}},$item);
5685: }
5686: }
5687: }
5688: }
5689: }
5690: } else {
5691: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
5692: push(@{$changes{'cancreate'}},$item);
5693: }
5694: }
1.27 raeburn 5695: }
1.34 raeburn 5696: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
5697: foreach my $item (@contexts) {
1.43 raeburn 5698: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 5699: if ($cancreate{$item} ne 'any') {
5700: push(@{$changes{'cancreate'}},$item);
5701: }
5702: } else {
5703: if ($cancreate{$item} ne 'none') {
5704: push(@{$changes{'cancreate'}},$item);
5705: }
1.27 raeburn 5706: }
5707: }
5708: } else {
1.43 raeburn 5709: foreach my $item (@contexts) {
1.34 raeburn 5710: push(@{$changes{'cancreate'}},$item);
5711: }
1.27 raeburn 5712: }
1.34 raeburn 5713:
1.27 raeburn 5714: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
5715: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
5716: if (!grep(/^\Q$type\E$/,@username_rule)) {
5717: push(@{$changes{'username_rule'}},$type);
5718: }
5719: }
5720: foreach my $type (@username_rule) {
5721: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
5722: push(@{$changes{'username_rule'}},$type);
5723: }
5724: }
5725: } else {
5726: push(@{$changes{'username_rule'}},@username_rule);
5727: }
5728:
1.32 raeburn 5729: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
5730: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
5731: if (!grep(/^\Q$type\E$/,@id_rule)) {
5732: push(@{$changes{'id_rule'}},$type);
5733: }
5734: }
5735: foreach my $type (@id_rule) {
5736: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
5737: push(@{$changes{'id_rule'}},$type);
5738: }
5739: }
5740: } else {
5741: push(@{$changes{'id_rule'}},@id_rule);
5742: }
5743:
1.43 raeburn 5744: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
5745: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
5746: if (!grep(/^\Q$type\E$/,@email_rule)) {
5747: push(@{$changes{'email_rule'}},$type);
5748: }
5749: }
5750: foreach my $type (@email_rule) {
5751: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
5752: push(@{$changes{'email_rule'}},$type);
5753: }
5754: }
5755: } else {
5756: push(@{$changes{'email_rule'}},@email_rule);
5757: }
5758:
5759: my @authen_contexts = ('author','course','domain');
1.28 raeburn 5760: my @authtypes = ('int','krb4','krb5','loc');
5761: my %authhash;
1.43 raeburn 5762: foreach my $item (@authen_contexts) {
1.28 raeburn 5763: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
5764: foreach my $auth (@authtypes) {
5765: if (grep(/^\Q$auth\E$/,@authallowed)) {
5766: $authhash{$item}{$auth} = 1;
5767: } else {
5768: $authhash{$item}{$auth} = 0;
5769: }
5770: }
5771: }
5772: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 5773: foreach my $item (@authen_contexts) {
1.28 raeburn 5774: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
5775: foreach my $auth (@authtypes) {
5776: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
5777: push(@{$changes{'authtypes'}},$item);
5778: last;
5779: }
5780: }
5781: }
5782: }
5783: } else {
1.43 raeburn 5784: foreach my $item (@authen_contexts) {
1.28 raeburn 5785: push(@{$changes{'authtypes'}},$item);
5786: }
5787: }
5788:
1.27 raeburn 5789: my %usercreation_hash = (
1.28 raeburn 5790: usercreation => {
1.34 raeburn 5791: cancreate => \%cancreate,
1.27 raeburn 5792: username_rule => \@username_rule,
1.32 raeburn 5793: id_rule => \@id_rule,
1.43 raeburn 5794: email_rule => \@email_rule,
1.32 raeburn 5795: authtypes => \%authhash,
1.27 raeburn 5796: }
5797: );
5798:
5799: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
5800: $dom);
1.50 raeburn 5801:
5802: my %selfcreatetypes = (
5803: sso => 'users authenticated by institutional single sign on',
5804: login => 'users authenticated by institutional log-in',
5805: email => 'users who provide a valid e-mail address for use as the username',
5806: );
1.27 raeburn 5807: if ($putresult eq 'ok') {
5808: if (keys(%changes) > 0) {
5809: $resulttext = &mt('Changes made:').'<ul>';
5810: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 5811: my %lt = &usercreation_types();
5812: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 5813: my $chgtext;
5814: unless ($type eq 'statustocreate') {
5815: $chgtext = $lt{$type}.', ';
5816: }
1.45 raeburn 5817: if ($type eq 'selfcreate') {
1.50 raeburn 5818: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 5819: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 5820: } else {
1.100 raeburn 5821: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 5822: foreach my $case (@{$cancreate{$type}}) {
5823: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
5824: }
5825: $chgtext .= '</ul>';
1.100 raeburn 5826: if (ref($cancreate{$type}) eq 'ARRAY') {
5827: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
5828: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
5829: if (@{$cancreate{'statustocreate'}} == 0) {
5830: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
5831: }
5832: }
5833: }
5834: }
1.43 raeburn 5835: }
1.93 raeburn 5836: } elsif ($type eq 'statustocreate') {
1.96 raeburn 5837: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
5838: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
5839: if (@{$cancreate{'selfcreate'}} > 0) {
5840: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 5841:
5842: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 5843: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 5844: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
5845: }
1.96 raeburn 5846: } elsif (ref($usertypes) eq 'HASH') {
5847: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 5848: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
5849: } else {
5850: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
5851: }
5852: $chgtext .= '<ul>';
5853: foreach my $case (@{$cancreate{$type}}) {
5854: if ($case eq 'default') {
5855: $chgtext .= '<li>'.$othertitle.'</li>';
5856: } else {
5857: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 5858: }
5859: }
1.100 raeburn 5860: $chgtext .= '</ul>';
5861: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
5862: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
5863: }
5864: }
5865: } else {
5866: if (@{$cancreate{$type}} == 0) {
5867: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
5868: } else {
5869: $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 5870: }
5871: }
5872: }
1.43 raeburn 5873: } else {
5874: if ($cancreate{$type} eq 'none') {
5875: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
5876: } elsif ($cancreate{$type} eq 'any') {
5877: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
5878: } elsif ($cancreate{$type} eq 'official') {
5879: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
5880: } elsif ($cancreate{$type} eq 'unofficial') {
5881: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
5882: }
1.34 raeburn 5883: }
5884: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 5885: }
5886: }
5887: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 5888: my ($rules,$ruleorder) =
5889: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 5890: my $chgtext = '<ul>';
5891: foreach my $type (@username_rule) {
5892: if (ref($rules->{$type}) eq 'HASH') {
5893: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
5894: }
5895: }
5896: $chgtext .= '</ul>';
5897: if (@username_rule > 0) {
5898: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
5899: } else {
1.28 raeburn 5900: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 5901: }
5902: }
1.32 raeburn 5903: if (ref($changes{'id_rule'}) eq 'ARRAY') {
5904: my ($idrules,$idruleorder) =
5905: &Apache::lonnet::inst_userrules($dom,'id');
5906: my $chgtext = '<ul>';
5907: foreach my $type (@id_rule) {
5908: if (ref($idrules->{$type}) eq 'HASH') {
5909: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
5910: }
5911: }
5912: $chgtext .= '</ul>';
5913: if (@id_rule > 0) {
5914: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
5915: } else {
5916: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
5917: }
5918: }
1.43 raeburn 5919: if (ref($changes{'email_rule'}) eq 'ARRAY') {
5920: my ($emailrules,$emailruleorder) =
5921: &Apache::lonnet::inst_userrules($dom,'email');
5922: my $chgtext = '<ul>';
5923: foreach my $type (@email_rule) {
5924: if (ref($emailrules->{$type}) eq 'HASH') {
5925: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
5926: }
5927: }
5928: $chgtext .= '</ul>';
5929: if (@email_rule > 0) {
5930: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
5931: } else {
5932: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
5933: }
5934: }
5935:
1.28 raeburn 5936: my %authname = &authtype_names();
5937: my %context_title = &context_names();
5938: if (ref($changes{'authtypes'}) eq 'ARRAY') {
5939: my $chgtext = '<ul>';
5940: foreach my $type (@{$changes{'authtypes'}}) {
5941: my @allowed;
5942: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
5943: foreach my $auth (@authtypes) {
5944: if ($authhash{$type}{$auth}) {
5945: push(@allowed,$authname{$auth});
5946: }
5947: }
1.43 raeburn 5948: if (@allowed > 0) {
5949: $chgtext .= join(', ',@allowed).'</li>';
5950: } else {
5951: $chgtext .= &mt('none').'</li>';
5952: }
1.28 raeburn 5953: }
5954: $chgtext .= '</ul>';
5955: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
5956: $resulttext .= '</li>';
5957: }
1.27 raeburn 5958: $resulttext .= '</ul>';
5959: } else {
1.28 raeburn 5960: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 5961: }
5962: } else {
5963: $resulttext = '<span class="LC_error">'.
1.23 raeburn 5964: &mt('An error occurred: [_1]',$putresult).'</span>';
5965: }
1.43 raeburn 5966: if ($warningmsg ne '') {
5967: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
5968: }
1.23 raeburn 5969: return $resulttext;
5970: }
5971:
1.33 raeburn 5972: sub modify_usermodification {
5973: my ($dom,%domconfig) = @_;
5974: my ($resulttext,%curr_usermodification,%changes);
5975: if (ref($domconfig{'usermodification'}) eq 'HASH') {
5976: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
5977: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
5978: }
5979: }
1.63 raeburn 5980: my @contexts = ('author','course','selfcreate');
1.33 raeburn 5981: my %context_title = (
5982: author => 'In author context',
5983: course => 'In course context',
1.63 raeburn 5984: selfcreate => 'When self creating account',
1.33 raeburn 5985: );
5986: my @fields = ('lastname','firstname','middlename','generation',
5987: 'permanentemail','id');
5988: my %roles = (
5989: author => ['ca','aa'],
5990: course => ['st','ep','ta','in','cr'],
5991: );
1.63 raeburn 5992: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5993: if (ref($types) eq 'ARRAY') {
5994: push(@{$types},'default');
5995: $usertypes->{'default'} = $othertitle;
5996: }
5997: $roles{'selfcreate'} = $types;
1.33 raeburn 5998: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
5999: my %modifyhash;
6000: foreach my $context (@contexts) {
6001: foreach my $role (@{$roles{$context}}) {
6002: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
6003: foreach my $item (@fields) {
6004: if (grep(/^\Q$item\E$/,@modifiable)) {
6005: $modifyhash{$context}{$role}{$item} = 1;
6006: } else {
6007: $modifyhash{$context}{$role}{$item} = 0;
6008: }
6009: }
6010: }
6011: if (ref($curr_usermodification{$context}) eq 'HASH') {
6012: foreach my $role (@{$roles{$context}}) {
6013: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
6014: foreach my $field (@fields) {
6015: if ($modifyhash{$context}{$role}{$field} ne
6016: $curr_usermodification{$context}{$role}{$field}) {
6017: push(@{$changes{$context}},$role);
6018: last;
6019: }
6020: }
6021: }
6022: }
6023: } else {
6024: foreach my $context (@contexts) {
6025: foreach my $role (@{$roles{$context}}) {
6026: push(@{$changes{$context}},$role);
6027: }
6028: }
6029: }
6030: }
6031: my %usermodification_hash = (
6032: usermodification => \%modifyhash,
6033: );
6034: my $putresult = &Apache::lonnet::put_dom('configuration',
6035: \%usermodification_hash,$dom);
6036: if ($putresult eq 'ok') {
6037: if (keys(%changes) > 0) {
6038: $resulttext = &mt('Changes made: ').'<ul>';
6039: foreach my $context (@contexts) {
6040: if (ref($changes{$context}) eq 'ARRAY') {
6041: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
6042: if (ref($changes{$context}) eq 'ARRAY') {
6043: foreach my $role (@{$changes{$context}}) {
6044: my $rolename;
1.63 raeburn 6045: if ($context eq 'selfcreate') {
6046: $rolename = $role;
6047: if (ref($usertypes) eq 'HASH') {
6048: if ($usertypes->{$role} ne '') {
6049: $rolename = $usertypes->{$role};
6050: }
6051: }
1.33 raeburn 6052: } else {
1.63 raeburn 6053: if ($role eq 'cr') {
6054: $rolename = &mt('Custom');
6055: } else {
6056: $rolename = &Apache::lonnet::plaintext($role);
6057: }
1.33 raeburn 6058: }
6059: my @modifiable;
1.63 raeburn 6060: if ($context eq 'selfcreate') {
1.126 bisitz 6061: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
1.63 raeburn 6062: } else {
6063: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
6064: }
1.33 raeburn 6065: foreach my $field (@fields) {
6066: if ($modifyhash{$context}{$role}{$field}) {
6067: push(@modifiable,$fieldtitles{$field});
6068: }
6069: }
6070: if (@modifiable > 0) {
6071: $resulttext .= join(', ',@modifiable);
6072: } else {
6073: $resulttext .= &mt('none');
6074: }
6075: $resulttext .= '</li>';
6076: }
6077: $resulttext .= '</ul></li>';
6078: }
6079: }
6080: }
6081: $resulttext .= '</ul>';
6082: } else {
6083: $resulttext = &mt('No changes made to user modification settings');
6084: }
6085: } else {
6086: $resulttext = '<span class="LC_error">'.
6087: &mt('An error occurred: [_1]',$putresult).'</span>';
6088: }
6089: return $resulttext;
6090: }
6091:
1.43 raeburn 6092: sub modify_defaults {
6093: my ($dom,$r) = @_;
6094: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
6095: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.138.2.5 raeburn 6096: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 6097: my @authtypes = ('internal','krb4','krb5','localauth');
6098: foreach my $item (@items) {
6099: $newvalues{$item} = $env{'form.'.$item};
6100: if ($item eq 'auth_def') {
6101: if ($newvalues{$item} ne '') {
6102: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
6103: push(@errors,$item);
6104: }
6105: }
6106: } elsif ($item eq 'lang_def') {
6107: if ($newvalues{$item} ne '') {
6108: if ($newvalues{$item} =~ /^(\w+)/) {
6109: my $langcode = $1;
1.103 raeburn 6110: if ($langcode ne 'x_chef') {
6111: if (code2language($langcode) eq '') {
6112: push(@errors,$item);
6113: }
1.43 raeburn 6114: }
6115: } else {
6116: push(@errors,$item);
6117: }
6118: }
1.54 raeburn 6119: } elsif ($item eq 'timezone_def') {
6120: if ($newvalues{$item} ne '') {
1.62 raeburn 6121: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 6122: push(@errors,$item);
6123: }
6124: }
1.68 raeburn 6125: } elsif ($item eq 'datelocale_def') {
6126: if ($newvalues{$item} ne '') {
6127: my @datelocale_ids = DateTime::Locale->ids();
6128: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
6129: push(@errors,$item);
6130: }
6131: }
1.138.2.5 raeburn 6132: } elsif ($item eq 'portal_def') {
6133: if ($newvalues{$item} ne '') {
6134: 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])\/?$/) {
6135: push(@errors,$item);
6136: }
6137: }
1.43 raeburn 6138: }
6139: if (grep(/^\Q$item\E$/,@errors)) {
6140: $newvalues{$item} = $domdefaults{$item};
6141: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
6142: $changes{$item} = 1;
6143: }
1.72 raeburn 6144: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 6145: }
6146: my %defaults_hash = (
1.72 raeburn 6147: defaults => \%newvalues,
6148: );
1.43 raeburn 6149: my $title = &defaults_titles();
6150: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
6151: $dom);
6152: if ($putresult eq 'ok') {
6153: if (keys(%changes) > 0) {
6154: $resulttext = &mt('Changes made:').'<ul>';
6155: my $version = $r->dir_config('lonVersion');
6156: 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";
6157: foreach my $item (sort(keys(%changes))) {
6158: my $value = $env{'form.'.$item};
6159: if ($value eq '') {
6160: $value = &mt('none');
6161: } elsif ($item eq 'auth_def') {
6162: my %authnames = &authtype_names();
6163: my %shortauth = (
6164: internal => 'int',
6165: krb4 => 'krb4',
6166: krb5 => 'krb5',
6167: localauth => 'loc',
6168: );
6169: $value = $authnames{$shortauth{$value}};
6170: }
6171: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
6172: $mailmsgtext .= "$title->{$item} set to $value\n";
6173: }
6174: $resulttext .= '</ul>';
6175: $mailmsgtext .= "\n";
6176: my $cachetime = 24*60*60;
1.72 raeburn 6177: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 6178: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 6179: my $sysmail = $r->dir_config('lonSysEMail');
6180: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
6181: }
1.43 raeburn 6182: } else {
1.54 raeburn 6183: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 6184: }
6185: } else {
6186: $resulttext = '<span class="LC_error">'.
6187: &mt('An error occurred: [_1]',$putresult).'</span>';
6188: }
6189: if (@errors > 0) {
6190: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
6191: foreach my $item (@errors) {
6192: $resulttext .= ' "'.$title->{$item}.'",';
6193: }
6194: $resulttext =~ s/,$//;
6195: }
6196: return $resulttext;
6197: }
6198:
1.46 raeburn 6199: sub modify_scantron {
1.48 raeburn 6200: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 6201: my ($resulttext,%confhash,%changes,$errors);
6202: my $custom = 'custom.tab';
6203: my $default = 'default.tab';
6204: my $servadm = $r->dir_config('lonAdmEMail');
6205: my ($configuserok,$author_ok,$switchserver) =
6206: &config_check($dom,$confname,$servadm);
6207: if ($env{'form.scantronformat.filename'} ne '') {
6208: my $error;
6209: if ($configuserok eq 'ok') {
6210: if ($switchserver) {
1.130 raeburn 6211: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 6212: } else {
6213: if ($author_ok eq 'ok') {
6214: my ($result,$scantronurl) =
6215: &publishlogo($r,'upload','scantronformat',$dom,
6216: $confname,'scantron','','',$custom);
6217: if ($result eq 'ok') {
6218: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 6219: $changes{'scantronformat'} = 1;
1.46 raeburn 6220: } else {
6221: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
6222: }
6223: } else {
6224: $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);
6225: }
6226: }
6227: } else {
6228: $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);
6229: }
6230: if ($error) {
6231: &Apache::lonnet::logthis($error);
6232: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6233: }
6234: }
1.48 raeburn 6235: if (ref($domconfig{'scantron'}) eq 'HASH') {
6236: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
6237: if ($env{'form.scantronformat_del'}) {
6238: $confhash{'scantron'}{'scantronformat'} = '';
6239: $changes{'scantronformat'} = 1;
1.46 raeburn 6240: }
6241: }
6242: }
6243: if (keys(%confhash) > 0) {
6244: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
6245: $dom);
6246: if ($putresult eq 'ok') {
6247: if (keys(%changes) > 0) {
1.48 raeburn 6248: if (ref($confhash{'scantron'}) eq 'HASH') {
6249: $resulttext = &mt('Changes made:').'<ul>';
6250: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 6251: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 6252: } else {
1.130 raeburn 6253: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 6254: }
1.48 raeburn 6255: $resulttext .= '</ul>';
6256: } else {
1.130 raeburn 6257: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 6258: }
6259: $resulttext .= '</ul>';
6260: &Apache::loncommon::devalidate_domconfig_cache($dom);
6261: } else {
1.130 raeburn 6262: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6263: }
6264: } else {
6265: $resulttext = '<span class="LC_error">'.
6266: &mt('An error occurred: [_1]',$putresult).'</span>';
6267: }
6268: } else {
1.130 raeburn 6269: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 6270: }
6271: if ($errors) {
6272: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6273: $errors.'</ul>';
6274: }
6275: return $resulttext;
6276: }
6277:
1.48 raeburn 6278: sub modify_coursecategories {
6279: my ($dom,%domconfig) = @_;
1.57 raeburn 6280: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
6281: $cathash);
1.48 raeburn 6282: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 6283: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 6284: $cathash = $domconfig{'coursecategories'}{'cats'};
6285: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
6286: $changes{'togglecats'} = 1;
6287: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
6288: }
6289: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
6290: $changes{'categorize'} = 1;
6291: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
6292: }
1.120 raeburn 6293: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
6294: $changes{'togglecatscomm'} = 1;
6295: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
6296: }
6297: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
6298: $changes{'categorizecomm'} = 1;
6299: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
6300: }
1.57 raeburn 6301: } else {
6302: $changes{'togglecats'} = 1;
6303: $changes{'categorize'} = 1;
1.124 raeburn 6304: $changes{'togglecatscomm'} = 1;
6305: $changes{'categorizecomm'} = 1;
1.87 raeburn 6306: $domconfig{'coursecategories'} = {
6307: togglecats => $env{'form.togglecats'},
6308: categorize => $env{'form.categorize'},
1.124 raeburn 6309: togglecatscomm => $env{'form.togglecatscomm'},
6310: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 6311: };
1.57 raeburn 6312: }
6313: if (ref($cathash) eq 'HASH') {
6314: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 6315: push (@deletecategory,'instcode::0');
6316: }
1.120 raeburn 6317: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
6318: push(@deletecategory,'communities::0');
6319: }
1.48 raeburn 6320: }
1.57 raeburn 6321: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
6322: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6323: if (@deletecategory > 0) {
6324: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 6325: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 6326: foreach my $item (@deletecategory) {
1.57 raeburn 6327: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
6328: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 6329: $deletions{$item} = 1;
1.57 raeburn 6330: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 6331: }
6332: }
6333: }
1.57 raeburn 6334: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 6335: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 6336: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 6337: $reorderings{$item} = 1;
1.57 raeburn 6338: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 6339: }
6340: if ($env{'form.addcategory_name_'.$item} ne '') {
6341: my $newcat = $env{'form.addcategory_name_'.$item};
6342: my $newdepth = $depth+1;
6343: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6344: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 6345: $adds{$newitem} = 1;
6346: }
6347: if ($env{'form.subcat_'.$item} ne '') {
6348: my $newcat = $env{'form.subcat_'.$item};
6349: my $newdepth = $depth+1;
6350: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 6351: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 6352: $adds{$newitem} = 1;
6353: }
6354: }
6355: }
6356: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 6357: if (ref($cathash) eq 'HASH') {
1.48 raeburn 6358: my $newitem = 'instcode::0';
1.57 raeburn 6359: if ($cathash->{$newitem} eq '') {
6360: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6361: $adds{$newitem} = 1;
6362: }
6363: } else {
6364: my $newitem = 'instcode::0';
1.57 raeburn 6365: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 6366: $adds{$newitem} = 1;
6367: }
6368: }
1.120 raeburn 6369: if ($env{'form.communities'} eq '1') {
6370: if (ref($cathash) eq 'HASH') {
6371: my $newitem = 'communities::0';
6372: if ($cathash->{$newitem} eq '') {
6373: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6374: $adds{$newitem} = 1;
6375: }
6376: } else {
6377: my $newitem = 'communities::0';
6378: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
6379: $adds{$newitem} = 1;
6380: }
6381: }
1.48 raeburn 6382: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 6383: if (($env{'form.addcategory_name'} ne 'instcode') &&
6384: ($env{'form.addcategory_name'} ne 'communities')) {
6385: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
6386: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
6387: $adds{$newitem} = 1;
6388: }
1.48 raeburn 6389: }
1.57 raeburn 6390: my $putresult;
1.48 raeburn 6391: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6392: if (keys(%deletions) > 0) {
6393: foreach my $key (keys(%deletions)) {
6394: if ($predelallitems{$key} ne '') {
6395: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
6396: }
6397: }
6398: }
6399: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 6400: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 6401: if (ref($chkcats[0]) eq 'ARRAY') {
6402: my $depth = 0;
6403: my $chg = 0;
6404: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
6405: my $name = $chkcats[0][$i];
6406: my $item;
6407: if ($name eq '') {
6408: $chg ++;
6409: } else {
6410: $item = &escape($name).'::0';
6411: if ($chg) {
1.57 raeburn 6412: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 6413: }
6414: $depth ++;
1.57 raeburn 6415: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 6416: $depth --;
6417: }
6418: }
6419: }
1.57 raeburn 6420: }
6421: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6422: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 6423: if ($putresult eq 'ok') {
1.57 raeburn 6424: my %title = (
1.120 raeburn 6425: togglecats => 'Show/Hide a course in catalog',
6426: categorize => 'Assign a category to a course',
6427: togglecatscomm => 'Show/Hide a community in catalog',
6428: categorizecomm => 'Assign a category to a community',
1.57 raeburn 6429: );
6430: my %level = (
1.120 raeburn 6431: dom => 'set in Domain ("Modify Course/Community")',
6432: crs => 'set in Course ("Course Configuration")',
6433: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 6434: );
1.48 raeburn 6435: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 6436: if ($changes{'togglecats'}) {
6437: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
6438: }
6439: if ($changes{'categorize'}) {
6440: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 6441: }
1.120 raeburn 6442: if ($changes{'togglecatscomm'}) {
6443: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
6444: }
6445: if ($changes{'categorizecomm'}) {
6446: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
6447: }
1.57 raeburn 6448: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
6449: my $cathash;
6450: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6451: $cathash = $domconfig{'coursecategories'}{'cats'};
6452: } else {
6453: $cathash = {};
6454: }
6455: my (@cats,@trails,%allitems);
6456: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
6457: if (keys(%deletions) > 0) {
6458: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
6459: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
6460: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
6461: }
6462: $resulttext .= '</ul></li>';
6463: }
6464: if (keys(%reorderings) > 0) {
6465: my %sort_by_trail;
6466: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
6467: foreach my $key (keys(%reorderings)) {
6468: if ($allitems{$key} ne '') {
6469: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6470: }
1.48 raeburn 6471: }
1.57 raeburn 6472: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6473: $resulttext .= '<li>'.$trails[$trail].'</li>';
6474: }
6475: $resulttext .= '</ul></li>';
1.48 raeburn 6476: }
1.57 raeburn 6477: if (keys(%adds) > 0) {
6478: my %sort_by_trail;
6479: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
6480: foreach my $key (keys(%adds)) {
6481: if ($allitems{$key} ne '') {
6482: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
6483: }
6484: }
6485: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
6486: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 6487: }
1.57 raeburn 6488: $resulttext .= '</ul></li>';
1.48 raeburn 6489: }
6490: }
6491: $resulttext .= '</ul>';
6492: } else {
6493: $resulttext = '<span class="LC_error">'.
1.57 raeburn 6494: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 6495: }
6496: } else {
1.120 raeburn 6497: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 6498: }
6499: return $resulttext;
6500: }
6501:
1.69 raeburn 6502: sub modify_serverstatuses {
6503: my ($dom,%domconfig) = @_;
6504: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
6505: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
6506: %currserverstatus = %{$domconfig{'serverstatuses'}};
6507: }
6508: my @pages = &serverstatus_pages();
6509: foreach my $type (@pages) {
6510: $newserverstatus{$type}{'namedusers'} = '';
6511: $newserverstatus{$type}{'machines'} = '';
6512: if (defined($env{'form.'.$type.'_namedusers'})) {
6513: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
6514: my @okusers;
6515: foreach my $user (@users) {
6516: my ($uname,$udom) = split(/:/,$user);
6517: if (($udom =~ /^$match_domain$/) &&
6518: (&Apache::lonnet::domain($udom)) &&
6519: ($uname =~ /^$match_username$/)) {
6520: if (!grep(/^\Q$user\E/,@okusers)) {
6521: push(@okusers,$user);
6522: }
6523: }
6524: }
6525: if (@okusers > 0) {
6526: @okusers = sort(@okusers);
6527: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
6528: }
6529: }
6530: if (defined($env{'form.'.$type.'_machines'})) {
6531: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
6532: my @okmachines;
6533: foreach my $ip (@machines) {
6534: my @parts = split(/\./,$ip);
6535: next if (@parts < 4);
6536: my $badip = 0;
6537: for (my $i=0; $i<4; $i++) {
6538: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
6539: $badip = 1;
6540: last;
6541: }
6542: }
6543: if (!$badip) {
6544: push(@okmachines,$ip);
6545: }
6546: }
6547: @okmachines = sort(@okmachines);
6548: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
6549: }
6550: }
6551: my %serverstatushash = (
6552: serverstatuses => \%newserverstatus,
6553: );
6554: foreach my $type (@pages) {
1.83 raeburn 6555: foreach my $setting ('namedusers','machines') {
1.84 raeburn 6556: my (@current,@new);
1.83 raeburn 6557: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 6558: if ($currserverstatus{$type}{$setting} ne '') {
6559: @current = split(/,/,$currserverstatus{$type}{$setting});
6560: }
6561: }
6562: if ($newserverstatus{$type}{$setting} ne '') {
6563: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 6564: }
6565: if (@current > 0) {
6566: if (@new > 0) {
6567: foreach my $item (@current) {
6568: if (!grep(/^\Q$item\E$/,@new)) {
6569: $changes{$type}{$setting} = 1;
1.82 raeburn 6570: last;
6571: }
6572: }
1.84 raeburn 6573: foreach my $item (@new) {
6574: if (!grep(/^\Q$item\E$/,@current)) {
6575: $changes{$type}{$setting} = 1;
6576: last;
1.82 raeburn 6577: }
6578: }
6579: } else {
1.83 raeburn 6580: $changes{$type}{$setting} = 1;
1.69 raeburn 6581: }
1.83 raeburn 6582: } elsif (@new > 0) {
6583: $changes{$type}{$setting} = 1;
1.69 raeburn 6584: }
6585: }
6586: }
6587: if (keys(%changes) > 0) {
1.81 raeburn 6588: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 6589: my $putresult = &Apache::lonnet::put_dom('configuration',
6590: \%serverstatushash,$dom);
6591: if ($putresult eq 'ok') {
6592: $resulttext .= &mt('Changes made:').'<ul>';
6593: foreach my $type (@pages) {
1.84 raeburn 6594: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 6595: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 6596: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 6597: if ($newserverstatus{$type}{'namedusers'} eq '') {
6598: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
6599: } else {
6600: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
6601: }
1.84 raeburn 6602: }
6603: if ($changes{$type}{'machines'}) {
1.69 raeburn 6604: if ($newserverstatus{$type}{'machines'} eq '') {
6605: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
6606: } else {
6607: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
6608: }
6609:
6610: }
6611: $resulttext .= '</ul></li>';
6612: }
6613: }
6614: $resulttext .= '</ul>';
6615: } else {
6616: $resulttext = '<span class="LC_error">'.
6617: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
6618:
6619: }
6620: } else {
6621: $resulttext = &mt('No changes made to access to server status pages');
6622: }
6623: return $resulttext;
6624: }
6625:
1.118 jms 6626: sub modify_helpsettings {
1.122 jms 6627: my ($r,$dom,$confname,%domconfig) = @_;
1.118 jms 6628: my ($resulttext,$errors,%changes,%helphash);
6629:
1.122 jms 6630: my $customhelpfile = $env{'form.loginhelpurl.filename'};
6631: my $defaulthelpfile = 'defaulthelp.html';
6632: my $servadm = $r->dir_config('lonAdmEMail');
6633: my ($configuserok,$author_ok,$switchserver) =
6634: &config_check($dom,$confname,$servadm);
6635:
1.118 jms 6636: my %defaultchecked = ('submitbugs' => 'on');
6637: my @offon = ('off','on');
1.122 jms 6638: my %title = ( submitbugs => 'Display link for users to submit a bug',
6639: loginhelpurl => 'Unauthenticated login help page set to custom file');
6640:
1.118 jms 6641: my @toggles = ('submitbugs');
6642:
6643: $helphash{'helpsettings'} = {};
6644:
6645: if (ref($domconfig{'helpsettings'}) ne 'HASH') {
6646: if ($domconfig{'helpsettings'} eq '') {
6647: $domconfig{'helpsettings'} = {};
6648: }
6649: }
6650:
6651: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
6652:
6653: foreach my $item (@toggles) {
6654:
6655: if ($defaultchecked{$item} eq 'on') {
6656: if (($domconfig{'helpsettings'}{$item} eq '') &&
6657: ($env{'form.'.$item} eq '0')) {
6658: $changes{$item} = 1;
6659: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
6660: $changes{$item} = 1;
6661: }
6662: } elsif ($defaultchecked{$item} eq 'off') {
6663: if (($domconfig{'helpsettings'}{$item} eq '') &&
6664: ($env{'form.'.$item} eq '1')) {
6665: $changes{$item} = 1;
6666: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
6667: $changes{$item} = 1;
6668: }
6669: }
6670: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
1.122 jms 6671: }
6672:
6673: if ($customhelpfile ne '') {
6674: my $error;
6675: if ($configuserok eq 'ok') {
6676: if ($switchserver) {
6677: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
6678: } else {
6679: if ($author_ok eq 'ok') {
6680: my ($result,$loginhelpurl) =
6681: &publishlogo($r,'upload','loginhelpurl',$dom,
6682: $confname,'help','','',$customhelpfile);
6683: if ($result eq 'ok') {
6684: $helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
6685: $changes{'loginhelpurl'} = 1;
6686: } else {
6687: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
6688: }
6689: } else {
6690: $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].",$customhelpfile,$confname,$dom,$author_ok);
6691: }
6692: }
6693: } else {
6694: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok);
6695: }
6696: if ($error) {
6697: &Apache::lonnet::logthis($error);
6698: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
6699: }
6700: }
6701:
6702: if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
6703: if ($env{'form.loginhelpurl_del'}) {
6704: $helphash{'helpsettings'}{'loginhelpurl'} = '';
6705: $changes{'loginhelpurl'} = 1;
6706: }
6707: }
1.118 jms 6708: }
6709:
1.123 jms 6710:
6711: my $putresult;
6712:
6713: if (keys(%changes) > 0) {
6714: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
6715: } else {
6716: $putresult = 'ok';
6717: }
1.118 jms 6718:
6719: if ($putresult eq 'ok') {
6720: if (keys(%changes) > 0) {
6721: $resulttext = &mt('Changes made:').'<ul>';
6722: foreach my $item (sort(keys(%changes))) {
6723: if ($item eq 'submitbugs') {
6724: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
6725: }
1.122 jms 6726: if ($item eq 'loginhelpurl') {
6727: if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
6728: $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
6729: } else {
6730: $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
6731: }
6732: }
1.118 jms 6733: }
6734: $resulttext .= '</ul>';
6735: } else {
6736: $resulttext = &mt('No changes made to help settings');
6737: }
6738: } else {
6739: $resulttext = '<span class="LC_error">'.
6740: &mt('An error occurred: [_1]',$putresult).'</span>';
6741: }
6742: if ($errors) {
6743: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
6744: $errors.'</ul>';
6745: }
6746: return $resulttext;
6747: }
6748:
1.121 raeburn 6749: sub modify_coursedefaults {
6750: my ($dom,%domconfig) = @_;
6751: my ($resulttext,$errors,%changes,%defaultshash);
6752: my %defaultchecked = ('canuse_pdfforms' => 'off');
6753: my @offon = ('off','on');
1.138.2.2 raeburn 6754: my @toggles = ();
1.121 raeburn 6755:
6756: $defaultshash{'coursedefaults'} = {};
6757:
6758: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
6759: if ($domconfig{'coursedefaults'} eq '') {
6760: $domconfig{'coursedefaults'} = {};
6761: }
6762: }
6763:
6764: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
6765: foreach my $item (@toggles) {
6766: if ($defaultchecked{$item} eq 'on') {
6767: if (($domconfig{'coursedefaults'}{$item} eq '') &&
6768: ($env{'form.'.$item} eq '0')) {
6769: $changes{$item} = 1;
6770: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
6771: $changes{$item} = 1;
6772: }
6773: } elsif ($defaultchecked{$item} eq 'off') {
6774: if (($domconfig{'coursedefaults'}{$item} eq '') &&
6775: ($env{'form.'.$item} eq '1')) {
6776: $changes{$item} = 1;
6777: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
6778: $changes{$item} = 1;
6779: }
6780: }
6781: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
6782: }
1.138.2.2 raeburn 6783: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
6784: my $newdefresponder = $env{'form.anonsurvey_threshold'};
6785: $newdefresponder =~ s/\D//g;
6786: if ($newdefresponder eq '' || $newdefresponder < 1) {
6787: $newdefresponder = 1;
6788: }
6789: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
6790: if ($currdefresponder ne $newdefresponder) {
6791: unless ($currdefresponder eq '' && $newdefresponder == 10) {
6792: $changes{'anonsurvey_threshold'} = 1;
6793: }
6794: }
1.121 raeburn 6795: }
6796: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
6797: $dom);
6798: if ($putresult eq 'ok') {
6799: if (keys(%changes) > 0) {
6800: if ($changes{'canuse_pdfforms'}) {
6801: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6802: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
6803: my $cachetime = 24*60*60;
6804: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
6805: }
6806: $resulttext = &mt('Changes made:').'<ul>';
6807: foreach my $item (sort(keys(%changes))) {
6808: if ($item eq 'canuse_pdfforms') {
6809: if ($env{'form.'.$item} eq '1') {
6810: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
6811: } else {
6812: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
6813: }
1.138.2.2 raeburn 6814: } elsif ($item eq 'anonsurvey_threshold') {
6815: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.121 raeburn 6816: }
6817: }
6818: $resulttext .= '</ul>';
6819: } else {
6820: $resulttext = &mt('No changes made to course defaults');
6821: }
6822: } else {
6823: $resulttext = '<span class="LC_error">'.
6824: &mt('An error occurred: [_1]',$putresult).'</span>';
6825: }
6826: return $resulttext;
6827: }
6828:
1.137 raeburn 6829: sub modify_usersessions {
6830: my ($dom,%domconfig) = @_;
6831: my @types = ('version','excludedomain','includedomain');
6832: my @prefixes = ('remote','hosted');
6833: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 6834: my (%by_ip,%by_location,@intdoms);
6835: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
6836: my @locations = sort(keys(%by_location));
1.137 raeburn 6837: my (%defaultshash,%changes);
6838: foreach my $prefix (@prefixes) {
6839: $defaultshash{'usersessions'}{$prefix} = {};
6840: }
6841: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6842: my $resulttext;
1.138 raeburn 6843: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 6844: foreach my $prefix (@prefixes) {
6845: foreach my $type (@types) {
6846: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
6847: if ($type eq 'version') {
6848: my $value = $env{'form.'.$prefix.'_'.$type};
6849: my $okvalue;
6850: if ($value ne '') {
6851: if (grep(/^\Q$value\E$/,@lcversions)) {
6852: $okvalue = $value;
6853: }
6854: }
6855: if (ref($domconfig{'usersessions'}) eq 'HASH') {
6856: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
6857: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
6858: if ($inuse == 0) {
6859: $changes{$prefix}{$type} = 1;
6860: } else {
6861: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
6862: $changes{$prefix}{$type} = 1;
6863: }
6864: if ($okvalue ne '') {
6865: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
6866: }
6867: }
6868: } else {
6869: if (($inuse == 1) && ($okvalue ne '')) {
6870: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
6871: $changes{$prefix}{$type} = 1;
6872: }
6873: }
6874: } else {
6875: if (($inuse == 1) && ($okvalue ne '')) {
6876: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
6877: $changes{$prefix}{$type} = 1;
6878: }
6879: }
6880: } else {
6881: if (($inuse == 1) && ($okvalue ne '')) {
6882: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
6883: $changes{$prefix}{$type} = 1;
6884: }
6885: }
6886: } else {
6887: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
6888: my @okvals;
6889: foreach my $val (@vals) {
1.138 raeburn 6890: if ($val =~ /:/) {
6891: my @items = split(/:/,$val);
6892: foreach my $item (@items) {
6893: if (ref($by_location{$item}) eq 'ARRAY') {
6894: push(@okvals,$item);
6895: }
6896: }
6897: } else {
6898: if (ref($by_location{$val}) eq 'ARRAY') {
6899: push(@okvals,$val);
6900: }
1.137 raeburn 6901: }
6902: }
6903: @okvals = sort(@okvals);
6904: if (ref($domconfig{'usersessions'}) eq 'HASH') {
6905: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
6906: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
6907: if ($inuse == 0) {
6908: $changes{$prefix}{$type} = 1;
6909: } else {
6910: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
6911: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
6912: if (@changed > 0) {
6913: $changes{$prefix}{$type} = 1;
6914: }
6915: }
6916: } else {
6917: if ($inuse == 1) {
6918: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
6919: $changes{$prefix}{$type} = 1;
6920: }
6921: }
6922: } else {
6923: if ($inuse == 1) {
6924: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
6925: $changes{$prefix}{$type} = 1;
6926: }
6927: }
6928: } else {
6929: if ($inuse == 1) {
6930: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
6931: $changes{$prefix}{$type} = 1;
6932: }
6933: }
6934: }
6935: }
6936: }
6937: if (keys(%changes) > 0) {
6938: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
6939: $dom);
6940: if ($putresult eq 'ok') {
6941: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
6942: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
6943: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
6944: }
6945: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
6946: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
6947: }
6948: }
6949: my $cachetime = 24*60*60;
6950: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
6951: my %lt = &usersession_titles();
6952: $resulttext = &mt('Changes made:').'<ul>';
6953: foreach my $prefix (@prefixes) {
6954: if (ref($changes{$prefix}) eq 'HASH') {
6955: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
6956: foreach my $type (@types) {
6957: if (defined($changes{$prefix}{$type})) {
6958: my $newvalue;
6959: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
6960: if (ref($defaultshash{'usersessions'}{$prefix})) {
6961: if ($type eq 'version') {
6962: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
6963: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
6964: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
6965: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
6966: }
6967: }
6968: }
6969: }
6970: if ($newvalue eq '') {
6971: if ($type eq 'version') {
6972: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
6973: } else {
6974: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
6975: }
6976: } else {
6977: if ($type eq 'version') {
6978: $newvalue .= ' '.&mt('(or later)');
6979: }
6980: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
6981: }
6982: }
6983: }
6984: $resulttext .= '</ul>';
6985: }
6986: }
6987: $resulttext .= '</ul>';
6988: } else {
6989: $resulttext = '<span class="LC_error">'.
6990: &mt('An error occurred: [_1]',$putresult).'</span>';
6991: }
6992: } else {
6993: $resulttext = &mt('No changes made to settings for user session hosting.');
6994: }
6995: return $resulttext;
6996: }
6997:
1.48 raeburn 6998: sub recurse_check {
6999: my ($chkcats,$categories,$depth,$name) = @_;
7000: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
7001: my $chg = 0;
7002: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
7003: my $category = $chkcats->[$depth]{$name}[$j];
7004: my $item;
7005: if ($category eq '') {
7006: $chg ++;
7007: } else {
7008: my $deeper = $depth + 1;
7009: $item = &escape($category).':'.&escape($name).':'.$depth;
7010: if ($chg) {
7011: $categories->{$item} -= $chg;
7012: }
7013: &recurse_check($chkcats,$categories,$deeper,$category);
7014: $deeper --;
7015: }
7016: }
7017: }
7018: return;
7019: }
7020:
7021: sub recurse_cat_deletes {
7022: my ($item,$coursecategories,$deletions) = @_;
7023: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
7024: my $subdepth = $depth + 1;
7025: if (ref($coursecategories) eq 'HASH') {
7026: foreach my $subitem (keys(%{$coursecategories})) {
7027: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
7028: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
7029: delete($coursecategories->{$subitem});
7030: $deletions->{$subitem} = 1;
7031: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
7032: }
7033: }
7034: }
7035: return;
7036: }
7037:
1.117 raeburn 7038: sub dom_servers {
7039: my ($dom) = @_;
7040: my (%uniqservers,%servers);
7041: my $primaryserver = &Apache::lonnet::hostname(&Apache::lonnet::domain($dom,'primary'));
7042: my @machinedoms = &Apache::lonnet::machine_domains($primaryserver);
7043: foreach my $mdom (@machinedoms) {
7044: my %currservers = %servers;
7045: my %server = &Apache::lonnet::get_servers($mdom);
7046: %servers = (%currservers,%server);
7047: }
7048: my %by_hostname;
7049: foreach my $id (keys(%servers)) {
7050: push(@{$by_hostname{$servers{$id}}},$id);
7051: }
7052: foreach my $hostname (sort(keys(%by_hostname))) {
7053: if (@{$by_hostname{$hostname}} > 1) {
7054: my $match = 0;
7055: foreach my $id (@{$by_hostname{$hostname}}) {
7056: if (&Apache::lonnet::host_domain($id) eq $dom) {
7057: $uniqservers{$id} = $hostname;
7058: $match = 1;
7059: }
7060: }
7061: unless ($match) {
7062: $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
7063: }
7064: } else {
7065: $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
7066: }
7067: }
7068: return %uniqservers;
7069: }
7070:
1.125 raeburn 7071: sub get_active_dcs {
7072: my ($dom) = @_;
7073: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
7074: my %domcoords;
7075: my $numdcs = 0;
7076: my $now = time;
7077: foreach my $server (keys(%dompersonnel)) {
7078: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
7079: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
7080: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
7081: if (($end eq '') || ($end == 0) || ($end > $now)) {
7082: if ($start <= $now) {
7083: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
7084: }
7085: }
7086: }
7087: }
7088: return %domcoords;
7089: }
7090:
7091: sub active_dc_picker {
7092: my ($dom,$curr_dc) = @_;
7093: my %domcoords = &get_active_dcs($dom);
7094: my @dcs = sort(keys(%domcoords));
7095: my $numdcs = scalar(@dcs);
7096: my $datatable;
7097: my $numinrow = 2;
7098: if ($numdcs > 1) {
7099: $datatable = '<table>';
7100: for (my $i=0; $i<@dcs; $i++) {
7101: my $rem = $i%($numinrow);
7102: if ($rem == 0) {
7103: if ($i > 0) {
7104: $datatable .= '</tr>';
7105: }
7106: $datatable .= '<tr>';
7107: }
7108: my $check = ' ';
7109: if ($curr_dc eq '') {
7110: if (!$i) {
7111: $check = ' checked="checked" ';
7112: }
7113: } elsif ($dcs[$i] eq $curr_dc) {
7114: $check = ' checked="checked" ';
7115: }
7116: if ($i == @dcs - 1) {
7117: my $colsleft = $numinrow - $rem;
7118: if ($colsleft > 1) {
7119: $datatable .= '<td colspan="'.$colsleft.'">';
7120: } else {
7121: $datatable .= '<td>';
7122: }
7123: } else {
7124: $datatable .= '<td>';
7125: }
7126: my ($dcname,$dcdom) = split(':',$dcs[$i]);
7127: $datatable .= '<span class="LC_nobreak"><label>'.
7128: '<input type="radio" name="autocreate_xmldc"'.
7129: ' value="'.$dcs[$i].'"'.$check.'/>'.
7130: &Apache::loncommon::plainname($dcname,$dcdom).
7131: '</label></span></td>';
7132: }
7133: $datatable .= '</tr></table>';
7134: } elsif (@dcs) {
7135: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
7136: $dcs[0].'" />';
7137: }
7138: return ($numdcs,$datatable);
7139: }
7140:
1.137 raeburn 7141: sub usersession_titles {
7142: return &Apache::lonlocal::texthash(
7143: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
7144:
7145: remote => 'Hosting of sessions for users in this domain on servers in other domains',
7146: version => 'LON-CAPA version requirement',
1.138 raeburn 7147: excludedomain => 'Allow all, but exclude specific domains',
7148: includedomain => 'Deny all, but include specific domains',
1.137 raeburn 7149: );
7150: }
7151:
1.3 raeburn 7152: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>