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