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