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