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