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