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