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