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