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