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