Annotation of loncom/interface/domainprefs.pm, revision 1.102.2.2
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.102.2.2! raeburn 4: # $Id: domainprefs.pm,v 1.102.2.1 2009/08/13 20:38:45 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') {
! 1351: $datatable .= &mt('(overrides affiliation, if set)');
! 1352: } else {
! 1353: $datatable .= &mt('(overrides affiliation, if checked)');
! 1354: }
! 1355: $datatable .= '</td>'.
1.101 raeburn 1356: if ($context eq 'requestcourses') {
1357: $datatable .= '<table><tr>';
1358: } else {
1359: $datatable .= '<br />';
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">
2666: function reorderCats(form,parent,item,idx) {
2667: var changedVal;
2668: $jstext
2669: var newpos = 'addcategory_pos';
2670: var current = new Array;
2671: if (parent == '') {
2672: var has_instcode = 0;
2673: var maxtop = categories[idx].length;
2674: for (var j=0; j<maxtop; j++) {
2675: if (categories[idx][j] == 'instcode::0') {
2676: has_instcode == 1;
2677: }
2678: }
2679: if (has_instcode == 0) {
2680: categories[idx][maxtop] = 'instcode_pos';
2681: }
2682: } else {
2683: newpos += '_'+parent;
2684: }
2685: var maxh = 1 + categories[idx].length;
2686: var current = new Array;
2687: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2688: if (item == newpos) {
2689: changedVal = newitemVal;
2690: } else {
2691: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2692: current[newitemVal] = newpos;
2693: }
2694: for (var i=0; i<categories[idx].length; i++) {
2695: var elementName = categories[idx][i];
2696: if (elementName != item) {
2697: if (form.elements[elementName]) {
2698: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2699: current[currVal] = elementName;
2700: }
2701: }
2702: }
2703: var oldVal;
2704: for (var j=0; j<maxh; j++) {
2705: if (current[j] == undefined) {
2706: oldVal = j;
2707: }
2708: }
2709: if (oldVal < changedVal) {
2710: for (var k=oldVal+1; k<=changedVal ; k++) {
2711: var elementName = current[k];
2712: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2713: }
2714: } else {
2715: for (var k=changedVal; k<oldVal; k++) {
2716: var elementName = current[k];
2717: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2718: }
2719: }
2720: return;
2721: }
2722: </script>
2723:
2724: ENDSCRIPT
2725: return $output;
2726: }
2727:
1.48 raeburn 2728: sub initialize_categories {
2729: my ($itemcount) = @_;
2730: my $datatable;
2731: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2732: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','0'".');"';
2733:
1.48 raeburn 2734: $datatable = '<tr '.$css_class.'><td><span class="LC_nobreak">'
2735: .'<select name="instcode_pos"><option value="0" selected="selected">1</option>'
2736: .'<option value="1">2</option></select> '
2737: .&mt('Official courses (with institutional codes)')
2738: .'</span></td><td><span class="LC_nobreak">'
2739: .'<label><input type="radio" name="instcode" value="1" checked="checked" />'
2740: .&mt('Display').'</label> <label>'
2741: .'<input type="radio" name="instcode" value="0" />'.&mt('Do not display')
2742: .'</label></span></td></tr>';
2743: $itemcount ++;
2744: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2745: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 2746: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.53 raeburn 2747: .'<select name="addcategory_pos"'.$chgstr.'><option value="0">1</option>'
1.48 raeburn 2748: .'<option value="1" selected="selected">2</option></select> '
2749: .&mt('Add category').'</td><td>'.&mt('Name:')
2750: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
2751: return $datatable;
2752: }
2753:
2754: sub build_category_rows {
1.49 raeburn 2755: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
2756: my ($text,$name,$item,$chgstr);
1.48 raeburn 2757: if (ref($cats) eq 'ARRAY') {
2758: my $maxdepth = scalar(@{$cats});
2759: if (ref($cats->[$depth]) eq 'HASH') {
2760: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
2761: my $numchildren = @{$cats->[$depth]{$parent}};
2762: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
2763: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 2764: my ($idxnum,$parent_name,$parent_item);
2765: my $higher = $depth - 1;
2766: if ($higher == 0) {
2767: $parent_name = &escape($parent).'::'.$higher;
2768: } else {
2769: if (ref($path) eq 'ARRAY') {
2770: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2771: }
2772: }
2773: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 2774: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 2775: if ($j < $numchildren) {
1.48 raeburn 2776: $name = $cats->[$depth]{$parent}[$j];
2777: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 2778: $idxnum = $idx->{$item};
2779: } else {
2780: $name = $parent_name;
2781: $item = $parent_item;
1.48 raeburn 2782: }
1.49 raeburn 2783: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
2784: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 2785: for (my $i=0; $i<=$numchildren; $i++) {
2786: my $vpos = $i+1;
2787: my $selstr;
2788: if ($j == $i) {
2789: $selstr = ' selected="selected" ';
2790: }
2791: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
2792: }
2793: $text .= '</select> ';
2794: if ($j < $numchildren) {
2795: my $deeper = $depth+1;
2796: $text .= $name.' '
2797: .'<label><input type="checkbox" name="deletecategory" value="'
2798: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
2799: if(ref($path) eq 'ARRAY') {
2800: push(@{$path},$name);
1.49 raeburn 2801: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 2802: pop(@{$path});
2803: }
2804: } else {
1.59 bisitz 2805: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 2806: if ($j == $numchildren) {
2807: $text .= $name;
2808: } else {
2809: $text .= $item;
2810: }
2811: $text .= '" value="" />';
2812: }
2813: $text .= '</td></tr>';
2814: }
2815: $text .= '</table></td>';
2816: } else {
2817: my $higher = $depth-1;
2818: if ($higher == 0) {
2819: $name = &escape($parent).'::'.$higher;
2820: } else {
2821: if (ref($path) eq 'ARRAY') {
2822: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2823: }
2824: }
2825: my $colspan;
2826: if ($parent ne 'instcode') {
2827: $colspan = $maxdepth - $depth - 1;
2828: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
2829: }
2830: }
2831: }
2832: }
2833: return $text;
2834: }
2835:
1.33 raeburn 2836: sub modifiable_userdata_row {
1.63 raeburn 2837: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 2838: my $rolename;
1.63 raeburn 2839: if ($context eq 'selfcreate') {
2840: if (ref($usertypes) eq 'HASH') {
2841: $rolename = $usertypes->{$role};
2842: } else {
2843: $rolename = $role;
2844: }
1.33 raeburn 2845: } else {
1.63 raeburn 2846: if ($role eq 'cr') {
2847: $rolename = &mt('Custom role');
2848: } else {
2849: $rolename = &Apache::lonnet::plaintext($role);
2850: }
1.33 raeburn 2851: }
2852: my @fields = ('lastname','firstname','middlename','generation',
2853: 'permanentemail','id');
2854: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2855: my $output;
2856: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
2857: $output = '<tr '.$css_class.'>'.
2858: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
2859: '<td class="LC_left_item" colspan="2"><table>';
2860: my $rem;
2861: my %checks;
2862: if (ref($settings) eq 'HASH') {
2863: if (ref($settings->{$context}) eq 'HASH') {
2864: if (ref($settings->{$context}->{$role}) eq 'HASH') {
2865: foreach my $field (@fields) {
2866: if ($settings->{$context}->{$role}->{$field}) {
2867: $checks{$field} = ' checked="checked" ';
2868: }
2869: }
2870: }
2871: }
2872: }
2873: for (my $i=0; $i<@fields; $i++) {
2874: my $rem = $i%($numinrow);
2875: if ($rem == 0) {
2876: if ($i > 0) {
2877: $output .= '</tr>';
2878: }
2879: $output .= '<tr>';
2880: }
2881: my $check = ' ';
2882: if (exists($checks{$fields[$i]})) {
2883: $check = $checks{$fields[$i]}
2884: } else {
2885: if ($role eq 'st') {
2886: if (ref($settings) ne 'HASH') {
2887: $check = ' checked="checked" ';
2888: }
2889: }
2890: }
2891: $output .= '<td class="LC_left_item">'.
2892: '<span class="LC_nobreak"><label>'.
2893: '<input type="checkbox" name="canmodify_'.$role.'" '.
2894: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
2895: '</label></span></td>';
2896: $rem = @fields%($numinrow);
2897: }
2898: my $colsleft = $numinrow - $rem;
2899: if ($colsleft > 1 ) {
2900: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2901: ' </td>';
2902: } elsif ($colsleft == 1) {
2903: $output .= '<td class="LC_left_item"> </td>';
2904: }
2905: $output .= '</tr></table></td></tr>';
2906: return $output;
2907: }
1.28 raeburn 2908:
1.93 raeburn 2909: sub insttypes_row {
2910: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
2911: my %lt = &Apache::lonlocal::texthash (
2912: cansearch => 'Users allowed to search',
2913: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
2914: );
2915: my $showdom;
2916: if ($context eq 'cansearch') {
2917: $showdom = ' ('.$dom.')';
2918: }
1.25 raeburn 2919: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 2920: '<td>'.$lt{$context}.$showdom.
1.24 raeburn 2921: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 2922: my $rem;
2923: if (ref($types) eq 'ARRAY') {
2924: for (my $i=0; $i<@{$types}; $i++) {
2925: if (defined($usertypes->{$types->[$i]})) {
2926: my $rem = $i%($numinrow);
2927: if ($rem == 0) {
2928: if ($i > 0) {
2929: $output .= '</tr>';
2930: }
2931: $output .= '<tr>';
1.23 raeburn 2932: }
1.26 raeburn 2933: my $check = ' ';
1.99 raeburn 2934: if (ref($settings) eq 'HASH') {
2935: if (ref($settings->{$context}) eq 'ARRAY') {
2936: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
2937: $check = ' checked="checked" ';
2938: }
2939: } elsif ($context eq 'statustocreate') {
1.26 raeburn 2940: $check = ' checked="checked" ';
2941: }
1.23 raeburn 2942: }
1.26 raeburn 2943: $output .= '<td class="LC_left_item">'.
2944: '<span class="LC_nobreak"><label>'.
1.93 raeburn 2945: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 2946: 'value="'.$types->[$i].'"'.$check.'/>'.
2947: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 2948: }
2949: }
1.26 raeburn 2950:
2951: $rem = @{$types}%($numinrow);
1.23 raeburn 2952: }
2953: my $colsleft = $numinrow - $rem;
2954: if ($colsleft > 1) {
1.25 raeburn 2955: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 2956: } else {
1.25 raeburn 2957: $output .= '<td class="LC_left_item">';
1.23 raeburn 2958: }
2959: my $defcheck = ' ';
1.99 raeburn 2960: if (ref($settings) eq 'HASH') {
2961: if (ref($settings->{$context}) eq 'ARRAY') {
2962: if (grep(/^default$/,@{$settings->{$context}})) {
2963: $defcheck = ' checked="checked" ';
2964: }
2965: } elsif ($context eq 'statustocreate') {
1.26 raeburn 2966: $defcheck = ' checked="checked" ';
2967: }
1.23 raeburn 2968: }
1.25 raeburn 2969: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 2970: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 2971: 'value="default"'.$defcheck.'/>'.
2972: $othertitle.'</label></span></td>'.
2973: '</tr></table></td></tr>';
2974: return $output;
1.23 raeburn 2975: }
2976:
2977: sub sorted_searchtitles {
2978: my %searchtitles = &Apache::lonlocal::texthash(
2979: 'uname' => 'username',
2980: 'lastname' => 'last name',
2981: 'lastfirst' => 'last name, first name',
2982: );
2983: my @titleorder = ('uname','lastname','lastfirst');
2984: return (\%searchtitles,\@titleorder);
2985: }
2986:
1.25 raeburn 2987: sub sorted_searchtypes {
2988: my %srchtypes_desc = (
2989: exact => 'is exact match',
2990: contains => 'contains ..',
2991: begins => 'begins with ..',
2992: );
2993: my @srchtypeorder = ('exact','begins','contains');
2994: return (\%srchtypes_desc,\@srchtypeorder);
2995: }
2996:
1.3 raeburn 2997: sub usertype_update_row {
2998: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
2999: my $datatable;
3000: my $numinrow = 4;
3001: foreach my $type (@{$types}) {
3002: if (defined($usertypes->{$type})) {
3003: $$rownums ++;
3004: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
3005: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
3006: '</td><td class="LC_left_item"><table>';
3007: for (my $i=0; $i<@{$fields}; $i++) {
3008: my $rem = $i%($numinrow);
3009: if ($rem == 0) {
3010: if ($i > 0) {
3011: $datatable .= '</tr>';
3012: }
3013: $datatable .= '<tr>';
3014: }
3015: my $check = ' ';
1.39 raeburn 3016: if (ref($settings) eq 'HASH') {
3017: if (ref($settings->{'fields'}) eq 'HASH') {
3018: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
3019: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
3020: $check = ' checked="checked" ';
3021: }
1.3 raeburn 3022: }
3023: }
3024: }
3025:
3026: if ($i == @{$fields}-1) {
3027: my $colsleft = $numinrow - $rem;
3028: if ($colsleft > 1) {
3029: $datatable .= '<td colspan="'.$colsleft.'">';
3030: } else {
3031: $datatable .= '<td>';
3032: }
3033: } else {
3034: $datatable .= '<td>';
3035: }
1.8 raeburn 3036: $datatable .= '<span class="LC_nobreak"><label>'.
3037: '<input type="checkbox" name="updateable_'.$type.
3038: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
3039: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 3040: }
3041: $datatable .= '</tr></table></td></tr>';
3042: }
3043: }
3044: return $datatable;
1.1 raeburn 3045: }
3046:
3047: sub modify_login {
1.9 raeburn 3048: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 3049: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 3050: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 3051: adminmail => 'Display administrator E-mail address',
1.43 raeburn 3052: newuser => 'Link for visitors to create a user account',
1.41 raeburn 3053: loginheader => 'Log-in box header');
1.3 raeburn 3054: my @offon = ('off','on');
1.6 raeburn 3055: my %loginhash;
1.9 raeburn 3056: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
3057: \%domconfig,\%loginhash);
1.43 raeburn 3058: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 3059: foreach my $item (@toggles) {
3060: $loginhash{login}{$item} = $env{'form.'.$item};
3061: }
1.41 raeburn 3062: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 3063: if (ref($colchanges{'login'}) eq 'HASH') {
3064: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
3065: \%loginhash);
3066: }
1.1 raeburn 3067: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
3068: $dom);
3069: if ($putresult eq 'ok') {
1.43 raeburn 3070: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 3071: my %defaultchecked = (
3072: 'coursecatalog' => 'on',
3073: 'adminmail' => 'off',
1.43 raeburn 3074: 'newuser' => 'off',
1.42 raeburn 3075: );
1.55 raeburn 3076: if (ref($domconfig{'login'}) eq 'HASH') {
3077: foreach my $item (@toggles) {
3078: if ($defaultchecked{$item} eq 'on') {
3079: if (($domconfig{'login'}{$item} eq '0') &&
3080: ($env{'form.'.$item} eq '1')) {
3081: $changes{$item} = 1;
3082: } elsif (($domconfig{'login'}{$item} eq '' ||
3083: $domconfig{'login'}{$item} eq '1') &&
3084: ($env{'form.'.$item} eq '0')) {
3085: $changes{$item} = 1;
3086: }
3087: } elsif ($defaultchecked{$item} eq 'off') {
3088: if (($domconfig{'login'}{$item} eq '1') &&
3089: ($env{'form.'.$item} eq '0')) {
3090: $changes{$item} = 1;
3091: } elsif (($domconfig{'login'}{$item} eq '' ||
3092: $domconfig{'login'}{$item} eq '0') &&
3093: ($env{'form.'.$item} eq '1')) {
3094: $changes{$item} = 1;
3095: }
1.42 raeburn 3096: }
3097: }
1.55 raeburn 3098: if (($domconfig{'login'}{'loginheader'} eq 'text') &&
3099: ($env{'form.loginheader'} eq 'image')) {
3100: $changes{'loginheader'} = 1;
3101: } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
3102: $domconfig{'login'}{'loginheader'} eq 'image') &&
3103: ($env{'form.loginheader'} eq 'text')) {
3104: $changes{'loginheader'} = 1;
3105: }
1.41 raeburn 3106: }
1.6 raeburn 3107: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 3108: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 3109: $resulttext = &mt('Changes made:').'<ul>';
3110: foreach my $item (sort(keys(%changes))) {
1.41 raeburn 3111: if ($item eq 'loginheader') {
3112: $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
3113: } else {
3114: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
3115: }
1.1 raeburn 3116: }
1.6 raeburn 3117: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 3118: } else {
3119: $resulttext = &mt('No changes made to log-in page settings');
3120: }
3121: } else {
1.11 albertel 3122: $resulttext = '<span class="LC_error">'.
3123: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3124: }
1.6 raeburn 3125: if ($errors) {
1.9 raeburn 3126: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 3127: $errors.'</ul>';
3128: }
3129: return $resulttext;
3130: }
3131:
3132: sub color_font_choices {
3133: my %choices =
3134: &Apache::lonlocal::texthash (
3135: img => "Header",
3136: bgs => "Background colors",
3137: links => "Link colors",
1.55 raeburn 3138: images => "Images",
1.6 raeburn 3139: font => "Font color",
1.76 raeburn 3140: pgbg => "Page",
1.6 raeburn 3141: tabbg => "Header",
3142: sidebg => "Border",
3143: link => "Link",
3144: alink => "Active link",
3145: vlink => "Visited link",
3146: );
3147: return %choices;
3148: }
3149:
3150: sub modify_rolecolors {
1.9 raeburn 3151: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 3152: my ($resulttext,%rolehash);
3153: $rolehash{'rolecolors'} = {};
1.55 raeburn 3154: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
3155: if ($domconfig{'rolecolors'} eq '') {
3156: $domconfig{'rolecolors'} = {};
3157: }
3158: }
1.9 raeburn 3159: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 3160: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
3161: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
3162: $dom);
3163: if ($putresult eq 'ok') {
3164: if (keys(%changes) > 0) {
1.41 raeburn 3165: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 3166: $resulttext = &display_colorchgs($dom,\%changes,$roles,
3167: $rolehash{'rolecolors'});
3168: } else {
3169: $resulttext = &mt('No changes made to default color schemes');
3170: }
3171: } else {
1.11 albertel 3172: $resulttext = '<span class="LC_error">'.
3173: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 3174: }
3175: if ($errors) {
3176: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
3177: $errors.'</ul>';
3178: }
3179: return $resulttext;
3180: }
3181:
3182: sub modify_colors {
1.9 raeburn 3183: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 3184: my (%changes,%choices);
1.51 raeburn 3185: my @bgs;
1.6 raeburn 3186: my @links = ('link','alink','vlink');
1.41 raeburn 3187: my @logintext;
1.6 raeburn 3188: my @images;
3189: my $servadm = $r->dir_config('lonAdmEMail');
3190: my $errors;
3191: foreach my $role (@{$roles}) {
3192: if ($role eq 'login') {
1.12 raeburn 3193: %choices = &login_choices();
1.41 raeburn 3194: @logintext = ('textcol','bgcol');
1.12 raeburn 3195: } else {
3196: %choices = &color_font_choices();
3197: }
3198: if ($role eq 'login') {
1.41 raeburn 3199: @images = ('img','logo','domlogo','login');
1.51 raeburn 3200: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 3201: } else {
3202: @images = ('img');
1.51 raeburn 3203: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 3204: }
3205: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 3206: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 3207: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
3208: }
1.46 raeburn 3209: my ($configuserok,$author_ok,$switchserver) =
3210: &config_check($dom,$confname,$servadm);
1.9 raeburn 3211: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 3212: if (ref($domconfig->{$role}) ne 'HASH') {
3213: $domconfig->{$role} = {};
3214: }
1.8 raeburn 3215: foreach my $img (@images) {
1.70 raeburn 3216: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
3217: if (defined($env{'form.login_showlogo_'.$img})) {
3218: $confhash->{$role}{'showlogo'}{$img} = 1;
3219: } else {
3220: $confhash->{$role}{'showlogo'}{$img} = 0;
3221: }
3222: }
1.18 albertel 3223: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
3224: && !defined($domconfig->{$role}{$img})
3225: && !$env{'form.'.$role.'_del_'.$img}
3226: && $env{'form.'.$role.'_import_'.$img}) {
3227: # import the old configured image from the .tab setting
3228: # if they haven't provided a new one
3229: $domconfig->{$role}{$img} =
3230: $env{'form.'.$role.'_import_'.$img};
3231: }
1.6 raeburn 3232: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 3233: my $error;
1.6 raeburn 3234: if ($configuserok eq 'ok') {
1.9 raeburn 3235: if ($switchserver) {
1.12 raeburn 3236: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 3237: } else {
3238: if ($author_ok eq 'ok') {
3239: my ($result,$logourl) =
3240: &publishlogo($r,'upload',$role.'_'.$img,
3241: $dom,$confname,$img,$width,$height);
3242: if ($result eq 'ok') {
3243: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 3244: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 3245: } else {
1.12 raeburn 3246: $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 3247: }
3248: } else {
1.46 raeburn 3249: $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 3250: }
3251: }
3252: } else {
1.46 raeburn 3253: $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 3254: }
3255: if ($error) {
1.8 raeburn 3256: &Apache::lonnet::logthis($error);
1.11 albertel 3257: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 3258: }
3259: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 3260: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
3261: my $error;
3262: if ($configuserok eq 'ok') {
3263: # is confname an author?
3264: if ($switchserver eq '') {
3265: if ($author_ok eq 'ok') {
3266: my ($result,$logourl) =
3267: &publishlogo($r,'copy',$domconfig->{$role}{$img},
3268: $dom,$confname,$img,$width,$height);
3269: if ($result eq 'ok') {
3270: $confhash->{$role}{$img} = $logourl;
1.18 albertel 3271: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 3272: }
3273: }
3274: }
3275: }
1.6 raeburn 3276: }
3277: }
3278: }
3279: if (ref($domconfig) eq 'HASH') {
3280: if (ref($domconfig->{$role}) eq 'HASH') {
3281: foreach my $img (@images) {
3282: if ($domconfig->{$role}{$img} ne '') {
3283: if ($env{'form.'.$role.'_del_'.$img}) {
3284: $confhash->{$role}{$img} = '';
1.12 raeburn 3285: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3286: } else {
1.9 raeburn 3287: if ($confhash->{$role}{$img} eq '') {
3288: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
3289: }
1.6 raeburn 3290: }
3291: } else {
3292: if ($env{'form.'.$role.'_del_'.$img}) {
3293: $confhash->{$role}{$img} = '';
1.12 raeburn 3294: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3295: }
3296: }
1.70 raeburn 3297: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
3298: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
3299: if ($confhash->{$role}{'showlogo'}{$img} ne
3300: $domconfig->{$role}{'showlogo'}{$img}) {
3301: $changes{$role}{'showlogo'}{$img} = 1;
3302: }
3303: } else {
3304: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3305: $changes{$role}{'showlogo'}{$img} = 1;
3306: }
3307: }
3308: }
3309: }
1.6 raeburn 3310: if ($domconfig->{$role}{'font'} ne '') {
3311: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
3312: $changes{$role}{'font'} = 1;
3313: }
3314: } else {
3315: if ($confhash->{$role}{'font'}) {
3316: $changes{$role}{'font'} = 1;
3317: }
3318: }
3319: foreach my $item (@bgs) {
3320: if ($domconfig->{$role}{$item} ne '') {
3321: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3322: $changes{$role}{'bgs'}{$item} = 1;
3323: }
3324: } else {
3325: if ($confhash->{$role}{$item}) {
3326: $changes{$role}{'bgs'}{$item} = 1;
3327: }
3328: }
3329: }
3330: foreach my $item (@links) {
3331: if ($domconfig->{$role}{$item} ne '') {
3332: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3333: $changes{$role}{'links'}{$item} = 1;
3334: }
3335: } else {
3336: if ($confhash->{$role}{$item}) {
3337: $changes{$role}{'links'}{$item} = 1;
3338: }
3339: }
3340: }
1.41 raeburn 3341: foreach my $item (@logintext) {
3342: if ($domconfig->{$role}{$item} ne '') {
3343: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3344: $changes{$role}{'logintext'}{$item} = 1;
3345: }
3346: } else {
3347: if ($confhash->{$role}{$item}) {
3348: $changes{$role}{'logintext'}{$item} = 1;
3349: }
3350: }
3351: }
1.6 raeburn 3352: } else {
3353: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3354: \@logintext,$confhash,\%changes);
1.6 raeburn 3355: }
3356: } else {
3357: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3358: \@logintext,$confhash,\%changes);
1.6 raeburn 3359: }
3360: }
3361: return ($errors,%changes);
3362: }
3363:
1.46 raeburn 3364: sub config_check {
3365: my ($dom,$confname,$servadm) = @_;
3366: my ($configuserok,$author_ok,$switchserver,%currroles);
3367: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
3368: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
3369: $confname,$servadm);
3370: if ($configuserok eq 'ok') {
3371: $switchserver = &check_switchserver($dom,$confname);
3372: if ($switchserver eq '') {
3373: $author_ok = &check_authorstatus($dom,$confname,%currroles);
3374: }
3375: }
3376: return ($configuserok,$author_ok,$switchserver);
3377: }
3378:
1.6 raeburn 3379: sub default_change_checker {
1.41 raeburn 3380: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 3381: foreach my $item (@{$links}) {
3382: if ($confhash->{$role}{$item}) {
3383: $changes->{$role}{'links'}{$item} = 1;
3384: }
3385: }
3386: foreach my $item (@{$bgs}) {
3387: if ($confhash->{$role}{$item}) {
3388: $changes->{$role}{'bgs'}{$item} = 1;
3389: }
3390: }
1.41 raeburn 3391: foreach my $item (@{$logintext}) {
3392: if ($confhash->{$role}{$item}) {
3393: $changes->{$role}{'logintext'}{$item} = 1;
3394: }
3395: }
1.6 raeburn 3396: foreach my $img (@{$images}) {
3397: if ($env{'form.'.$role.'_del_'.$img}) {
3398: $confhash->{$role}{$img} = '';
1.12 raeburn 3399: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 3400: }
1.70 raeburn 3401: if ($role eq 'login') {
3402: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3403: $changes->{$role}{'showlogo'}{$img} = 1;
3404: }
3405: }
1.6 raeburn 3406: }
3407: if ($confhash->{$role}{'font'}) {
3408: $changes->{$role}{'font'} = 1;
3409: }
1.48 raeburn 3410: }
1.6 raeburn 3411:
3412: sub display_colorchgs {
3413: my ($dom,$changes,$roles,$confhash) = @_;
3414: my (%choices,$resulttext);
3415: if (!grep(/^login$/,@{$roles})) {
3416: $resulttext = &mt('Changes made:').'<br />';
3417: }
3418: foreach my $role (@{$roles}) {
3419: if ($role eq 'login') {
3420: %choices = &login_choices();
3421: } else {
3422: %choices = &color_font_choices();
3423: }
3424: if (ref($changes->{$role}) eq 'HASH') {
3425: if ($role ne 'login') {
3426: $resulttext .= '<h4>'.&mt($role).'</h4>';
3427: }
3428: foreach my $key (sort(keys(%{$changes->{$role}}))) {
3429: if ($role ne 'login') {
3430: $resulttext .= '<ul>';
3431: }
3432: if (ref($changes->{$role}{$key}) eq 'HASH') {
3433: if ($role ne 'login') {
3434: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
3435: }
3436: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 3437: if (($role eq 'login') && ($key eq 'showlogo')) {
3438: if ($confhash->{$role}{$key}{$item}) {
3439: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
3440: } else {
3441: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
3442: }
3443: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 3444: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
3445: } else {
1.12 raeburn 3446: my $newitem = $confhash->{$role}{$item};
3447: if ($key eq 'images') {
3448: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
3449: }
3450: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 3451: }
3452: }
3453: if ($role ne 'login') {
3454: $resulttext .= '</ul></li>';
3455: }
3456: } else {
3457: if ($confhash->{$role}{$key} eq '') {
3458: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
3459: } else {
3460: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
3461: }
3462: }
3463: if ($role ne 'login') {
3464: $resulttext .= '</ul>';
3465: }
3466: }
3467: }
3468: }
1.3 raeburn 3469: return $resulttext;
1.1 raeburn 3470: }
3471:
1.9 raeburn 3472: sub thumb_dimensions {
3473: return ('200','50');
3474: }
3475:
1.16 raeburn 3476: sub check_dimensions {
3477: my ($inputfile) = @_;
3478: my ($fullwidth,$fullheight);
3479: if ($inputfile =~ m|^[/\w.\-]+$|) {
3480: if (open(PIPE,"identify $inputfile 2>&1 |")) {
3481: my $imageinfo = <PIPE>;
3482: if (!close(PIPE)) {
3483: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
3484: }
3485: chomp($imageinfo);
3486: my ($fullsize) =
1.21 raeburn 3487: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 3488: if ($fullsize) {
3489: ($fullwidth,$fullheight) = split(/x/,$fullsize);
3490: }
3491: }
3492: }
3493: return ($fullwidth,$fullheight);
3494: }
3495:
1.9 raeburn 3496: sub check_configuser {
3497: my ($uhome,$dom,$confname,$servadm) = @_;
3498: my ($configuserok,%currroles);
3499: if ($uhome eq 'no_host') {
3500: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
3501: my $configpass = &LONCAPA::Enrollment::create_password();
3502: $configuserok =
3503: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
3504: $configpass,'','','','','',undef,$servadm);
3505: } else {
3506: $configuserok = 'ok';
3507: %currroles =
3508: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
3509: }
3510: return ($configuserok,%currroles);
3511: }
3512:
3513: sub check_authorstatus {
3514: my ($dom,$confname,%currroles) = @_;
3515: my $author_ok;
1.40 raeburn 3516: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 3517: my $start = time;
3518: my $end = 0;
3519: $author_ok =
3520: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 3521: 'au',$end,$start,'','','domconfig');
1.9 raeburn 3522: } else {
3523: $author_ok = 'ok';
3524: }
3525: return $author_ok;
3526: }
3527:
3528: sub publishlogo {
1.46 raeburn 3529: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 3530: my ($output,$fname,$logourl);
3531: if ($action eq 'upload') {
3532: $fname=$env{'form.'.$formname.'.filename'};
3533: chop($env{'form.'.$formname});
3534: } else {
3535: ($fname) = ($formname =~ /([^\/]+)$/);
3536: }
1.46 raeburn 3537: if ($savefileas ne '') {
3538: $fname = $savefileas;
3539: }
1.9 raeburn 3540: $fname=&Apache::lonnet::clean_filename($fname);
3541: # See if there is anything left
3542: unless ($fname) { return ('error: no uploaded file'); }
3543: $fname="$subdir/$fname";
3544: my $filepath='/home/'.$confname.'/public_html';
3545: my ($fnamepath,$file,$fetchthumb);
3546: $file=$fname;
3547: if ($fname=~m|/|) {
3548: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
3549: }
3550: my @parts=split(/\//,$filepath.'/'.$fnamepath);
3551: my $count;
3552: for ($count=4;$count<=$#parts;$count++) {
3553: $filepath.="/$parts[$count]";
3554: if ((-e $filepath)!=1) {
3555: mkdir($filepath,02770);
3556: }
3557: }
3558: # Check for bad extension and disallow upload
3559: if ($file=~/\.(\w+)$/ &&
3560: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
3561: $output =
3562: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
3563: } elsif ($file=~/\.(\w+)$/ &&
3564: !defined(&Apache::loncommon::fileembstyle($1))) {
3565: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
3566: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 3567: $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 3568: } elsif (-d "$filepath/$file") {
3569: $output = &mt('File name is a directory name - rename the file and re-upload');
3570: } else {
3571: my $source = $filepath.'/'.$file;
3572: my $logfile;
3573: if (!open($logfile,">>$source".'.log')) {
3574: return (&mt('No write permission to Construction Space'));
3575: }
3576: print $logfile
3577: "\n================= Publish ".localtime()." ================\n".
3578: $env{'user.name'}.':'.$env{'user.domain'}."\n";
3579: # Save the file
3580: if (!open(FH,'>'.$source)) {
3581: &Apache::lonnet::logthis('Failed to create '.$source);
3582: return (&mt('Failed to create file'));
3583: }
3584: if ($action eq 'upload') {
3585: if (!print FH ($env{'form.'.$formname})) {
3586: &Apache::lonnet::logthis('Failed to write to '.$source);
3587: return (&mt('Failed to write file'));
3588: }
3589: } else {
3590: my $original = &Apache::lonnet::filelocation('',$formname);
3591: if(!copy($original,$source)) {
3592: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
3593: return (&mt('Failed to write file'));
3594: }
3595: }
3596: close(FH);
3597: chmod(0660, $source); # Permissions to rw-rw---.
3598:
3599: my $docroot=$r->dir_config('lonDocRoot');
3600: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
3601: my $copyfile=$targetdir.'/'.$file;
3602:
3603: my @parts=split(/\//,$targetdir);
3604: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
3605: for (my $count=5;$count<=$#parts;$count++) {
3606: $path.="/$parts[$count]";
3607: if (!-e $path) {
3608: print $logfile "\nCreating directory ".$path;
3609: mkdir($path,02770);
3610: }
3611: }
3612: my $versionresult;
3613: if (-e $copyfile) {
3614: $versionresult = &logo_versioning($targetdir,$file,$logfile);
3615: } else {
3616: $versionresult = 'ok';
3617: }
3618: if ($versionresult eq 'ok') {
3619: if (copy($source,$copyfile)) {
3620: print $logfile "\nCopied original source to ".$copyfile."\n";
3621: $output = 'ok';
3622: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
3623: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
3624: } else {
3625: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
3626: $output = &mt('Failed to copy file to RES space').", $!";
3627: }
3628: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
3629: my $inputfile = $filepath.'/'.$file;
3630: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 3631: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
3632: if ($fullwidth ne '' && $fullheight ne '') {
3633: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
3634: my $thumbsize = $thumbwidth.'x'.$thumbheight;
3635: system("convert -sample $thumbsize $inputfile $outfile");
3636: chmod(0660, $filepath.'/tn-'.$file);
3637: if (-e $outfile) {
3638: my $copyfile=$targetdir.'/tn-'.$file;
3639: if (copy($outfile,$copyfile)) {
3640: print $logfile "\nCopied source to ".$copyfile."\n";
3641: &write_metadata($dom,$confname,$formname,
3642: $targetdir,'tn-'.$file,$logfile);
3643: } else {
3644: print $logfile "\nUnable to write ".$copyfile.
3645: ':'.$!."\n";
3646: }
3647: }
1.9 raeburn 3648: }
3649: }
3650: }
3651: } else {
3652: $output = $versionresult;
3653: }
3654: }
3655: return ($output,$logourl);
3656: }
3657:
3658: sub logo_versioning {
3659: my ($targetdir,$file,$logfile) = @_;
3660: my $target = $targetdir.'/'.$file;
3661: my ($maxversion,$fn,$extn,$output);
3662: $maxversion = 0;
3663: if ($file =~ /^(.+)\.(\w+)$/) {
3664: $fn=$1;
3665: $extn=$2;
3666: }
3667: opendir(DIR,$targetdir);
3668: while (my $filename=readdir(DIR)) {
3669: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
3670: $maxversion=($1>$maxversion)?$1:$maxversion;
3671: }
3672: }
3673: $maxversion++;
3674: print $logfile "\nCreating old version ".$maxversion."\n";
3675: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
3676: if (copy($target,$copyfile)) {
3677: print $logfile "Copied old target to ".$copyfile."\n";
3678: $copyfile=$copyfile.'.meta';
3679: if (copy($target.'.meta',$copyfile)) {
3680: print $logfile "Copied old target metadata to ".$copyfile."\n";
3681: $output = 'ok';
3682: } else {
3683: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
3684: $output = &mt('Failed to copy old meta').", $!, ";
3685: }
3686: } else {
3687: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
3688: $output = &mt('Failed to copy old target').", $!, ";
3689: }
3690: return $output;
3691: }
3692:
3693: sub write_metadata {
3694: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
3695: my (%metadatafields,%metadatakeys,$output);
3696: $metadatafields{'title'}=$formname;
3697: $metadatafields{'creationdate'}=time;
3698: $metadatafields{'lastrevisiondate'}=time;
3699: $metadatafields{'copyright'}='public';
3700: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
3701: $env{'user.domain'};
3702: $metadatafields{'authorspace'}=$confname.':'.$dom;
3703: $metadatafields{'domain'}=$dom;
3704: {
3705: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
3706: my $mfh;
3707: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
3708: $output = &mt('Could not write metadata');
3709: }
3710: foreach (sort keys %metadatafields) {
3711: unless ($_=~/\./) {
3712: my $unikey=$_;
3713: $unikey=~/^([A-Za-z]+)/;
3714: my $tag=$1;
3715: $tag=~tr/A-Z/a-z/;
3716: print $mfh "\n\<$tag";
3717: foreach (split(/\,/,$metadatakeys{$unikey})) {
3718: my $value=$metadatafields{$unikey.'.'.$_};
3719: $value=~s/\"/\'\'/g;
3720: print $mfh ' '.$_.'="'.$value.'"';
3721: }
3722: print $mfh '>'.
3723: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
3724: .'</'.$tag.'>';
3725: }
3726: }
3727: $output = 'ok';
3728: print $logfile "\nWrote metadata";
3729: close($mfh);
3730: }
3731: }
3732:
3733: sub check_switchserver {
3734: my ($dom,$confname) = @_;
3735: my ($allowed,$switchserver);
3736: my $home = &Apache::lonnet::homeserver($confname,$dom);
3737: if ($home eq 'no_host') {
3738: $home = &Apache::lonnet::domain($dom,'primary');
3739: }
3740: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 3741: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3742: if (!$allowed) {
3743: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 3744: }
3745: return $switchserver;
3746: }
3747:
1.1 raeburn 3748: sub modify_quotas {
1.86 raeburn 3749: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 3750: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
3751: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 3752: if ($action eq 'quotas') {
3753: $context = 'tools';
3754: } else {
3755: $context = $action;
3756: }
3757: if ($context eq 'requestcourses') {
1.98 raeburn 3758: @usertools = ('official','unofficial','community');
1.102.2.2! raeburn 3759: @options =('norequest','approval','autolimit','validate');
1.101 raeburn 3760: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
3761: %titles = &courserequest_titles();
3762: $toolregexp = join('|',@usertools);
3763: %conditions = &courserequest_conditions();
1.86 raeburn 3764: } else {
3765: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 3766: %titles = &tool_titles();
1.86 raeburn 3767: }
1.72 raeburn 3768: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 3769: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 3770: foreach my $key (keys(%env)) {
1.101 raeburn 3771: if ($context eq 'requestcourses') {
3772: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
3773: my $item = $1;
3774: my $type = $2;
3775: if ($type =~ /^limit_(.+)/) {
3776: $limithash{$item}{$1} = $env{$key};
3777: } else {
3778: $confhash{$item}{$type} = $env{$key};
3779: }
3780: }
3781: } else {
1.86 raeburn 3782: if ($key =~ /^form\.quota_(.+)$/) {
3783: $confhash{'defaultquota'}{$1} = $env{$key};
3784: }
1.101 raeburn 3785: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
3786: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
3787: }
1.72 raeburn 3788: }
3789: }
1.102 raeburn 3790: if ($context eq 'requestcourses') {
3791: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
3792: @approvalnotify = sort(@approvalnotify);
3793: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
3794: if (ref($domconfig{$action}) eq 'HASH') {
3795: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
3796: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
3797: $changes{'notify'}{'approval'} = 1;
3798: }
3799: } else {
3800: if ($domconfig{$action}{'notify'}{'approval'}) {
3801: $changes{'notify'}{'approval'} = 1;
3802: }
3803: }
3804: } else {
3805: if ($domconfig{$action}{'notify'}{'approval'}) {
3806: $changes{'notify'}{'approval'} = 1;
3807: }
3808: }
3809: } else {
1.86 raeburn 3810: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
3811: }
1.72 raeburn 3812: foreach my $item (@usertools) {
3813: foreach my $type (@{$types},'default','_LC_adv') {
1.102.2.2! raeburn 3814: my $unset;
1.101 raeburn 3815: if ($context eq 'requestcourses') {
1.102.2.2! raeburn 3816: $unset = '0';
! 3817: if ($type eq '_LC_adv') {
! 3818: $unset = '';
! 3819: }
1.101 raeburn 3820: if ($confhash{$item}{$type} eq 'autolimit') {
3821: $confhash{$item}{$type} .= '=';
3822: unless ($limithash{$item}{$type} =~ /\D/) {
3823: $confhash{$item}{$type} .= $limithash{$item}{$type};
3824: }
3825: }
1.72 raeburn 3826: } else {
1.101 raeburn 3827: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
3828: $confhash{$item}{$type} = 1;
3829: } else {
3830: $confhash{$item}{$type} = 0;
3831: }
1.72 raeburn 3832: }
1.86 raeburn 3833: if (ref($domconfig{$action}) eq 'HASH') {
3834: if (ref($domconfig{$action}{$item}) eq 'HASH') {
3835: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
3836: $changes{$item}{$type} = 1;
3837: }
3838: } else {
3839: if ($context eq 'requestcourses') {
1.102.2.2! raeburn 3840: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 3841: $changes{$item}{$type} = 1;
3842: }
3843: } else {
3844: if (!$confhash{$item}{$type}) {
3845: $changes{$item}{$type} = 1;
3846: }
3847: }
3848: }
3849: } else {
3850: if ($context eq 'requestcourses') {
1.102.2.2! raeburn 3851: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 3852: $changes{$item}{$type} = 1;
3853: }
3854: } else {
3855: if (!$confhash{$item}{$type}) {
3856: $changes{$item}{$type} = 1;
3857: }
3858: }
3859: }
1.1 raeburn 3860: }
3861: }
1.86 raeburn 3862: unless ($context eq 'requestcourses') {
3863: if (ref($domconfig{'quotas'}) eq 'HASH') {
3864: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
3865: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
3866: if (exists($confhash{'defaultquota'}{$key})) {
3867: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
3868: $changes{'defaultquota'}{$key} = 1;
3869: }
3870: } else {
3871: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 3872: }
3873: }
1.86 raeburn 3874: } else {
3875: foreach my $key (keys(%{$domconfig{'quotas'}})) {
3876: if (exists($confhash{'defaultquota'}{$key})) {
3877: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
3878: $changes{'defaultquota'}{$key} = 1;
3879: }
3880: } else {
3881: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 3882: }
1.1 raeburn 3883: }
3884: }
3885: }
1.86 raeburn 3886: if (ref($confhash{'defaultquota'}) eq 'HASH') {
3887: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
3888: if (ref($domconfig{'quotas'}) eq 'HASH') {
3889: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
3890: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
3891: $changes{'defaultquota'}{$key} = 1;
3892: }
3893: } else {
3894: if (!exists($domconfig{'quotas'}{$key})) {
3895: $changes{'defaultquota'}{$key} = 1;
3896: }
1.72 raeburn 3897: }
3898: } else {
1.86 raeburn 3899: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 3900: }
1.1 raeburn 3901: }
3902: }
3903: }
1.72 raeburn 3904:
3905: foreach my $key (keys(%confhash)) {
3906: $domdefaults{$key} = $confhash{$key};
3907: }
3908:
1.1 raeburn 3909: my %quotahash = (
1.86 raeburn 3910: $action => { %confhash }
1.1 raeburn 3911: );
3912: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
3913: $dom);
3914: if ($putresult eq 'ok') {
3915: if (keys(%changes) > 0) {
1.72 raeburn 3916: my $cachetime = 24*60*60;
3917: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
3918:
1.1 raeburn 3919: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 3920: unless ($context eq 'requestcourses') {
3921: if (ref($changes{'defaultquota'}) eq 'HASH') {
3922: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
3923: foreach my $type (@{$types},'default') {
3924: if (defined($changes{'defaultquota'}{$type})) {
3925: my $typetitle = $usertypes->{$type};
3926: if ($type eq 'default') {
3927: $typetitle = $othertitle;
3928: }
3929: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 3930: }
3931: }
1.86 raeburn 3932: $resulttext .= '</ul></li>';
1.72 raeburn 3933: }
3934: }
1.80 raeburn 3935: my %newenv;
1.72 raeburn 3936: foreach my $item (@usertools) {
3937: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 3938: my $newacc =
3939: &Apache::lonnet::usertools_access($env{'user.name'},
3940: $env{'user.domain'},
1.86 raeburn 3941: $item,'reload',$context);
3942: if ($context eq 'requestcourses') {
1.102.2.2! raeburn 3943: if ($env{'environment.canrequest.'.$item} ne $newacc) {
! 3944: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 3945: }
3946: } else {
3947: if ($env{'environment.availabletools.'.$item} ne $newacc) {
3948: $newenv{'environment.availabletools.'.$item} = $newacc;
3949: }
1.80 raeburn 3950: }
1.72 raeburn 3951: $resulttext .= '<li>'.$titles{$item}.'<ul>';
3952: foreach my $type (@{$types},'default','_LC_adv') {
3953: if ($changes{$item}{$type}) {
3954: my $typetitle = $usertypes->{$type};
3955: if ($type eq 'default') {
3956: $typetitle = $othertitle;
3957: } elsif ($type eq '_LC_adv') {
3958: $typetitle = 'LON-CAPA Advanced Users';
3959: }
3960: if ($confhash{$item}{$type}) {
1.101 raeburn 3961: if ($context eq 'requestcourses') {
3962: my $cond;
3963: if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
3964: if ($1 eq '') {
3965: $cond = &mt('(Automatic processing of any request).');
3966: } else {
3967: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
3968: }
3969: } else {
3970: $cond = $conditions{$confhash{$item}{$type}};
3971: }
3972: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
3973: } else {
3974: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
3975: }
1.72 raeburn 3976: } else {
1.102.2.2! raeburn 3977: if ($type eq '_LC_adv') {
! 3978: if ($confhash{$item}{$type} eq '0') {
! 3979: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
! 3980: } else {
! 3981: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
! 3982: }
! 3983: } else {
! 3984: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
! 3985: }
1.72 raeburn 3986: }
3987: }
1.26 raeburn 3988: }
1.72 raeburn 3989: $resulttext .= '</ul></li>';
1.26 raeburn 3990: }
1.1 raeburn 3991: }
1.102 raeburn 3992: if ($action eq 'requestcourses') {
3993: if (ref($changes{'notify'}) eq 'HASH') {
3994: if ($changes{'notify'}{'approval'}) {
3995: if (ref($confhash{'notify'}) eq 'HASH') {
3996: if ($confhash{'notify'}{'approval'}) {
3997: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
3998: } else {
3999: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
4000: }
4001: }
4002: }
4003: }
4004: }
1.1 raeburn 4005: $resulttext .= '</ul>';
1.80 raeburn 4006: if (keys(%newenv)) {
4007: &Apache::lonnet::appenv(\%newenv);
4008: }
1.1 raeburn 4009: } else {
1.86 raeburn 4010: if ($context eq 'requestcourses') {
4011: $resulttext = &mt('No changes made to rights to request creation of courses.');
4012: } else {
1.90 weissno 4013: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 4014: }
1.1 raeburn 4015: }
4016: } else {
1.11 albertel 4017: $resulttext = '<span class="LC_error">'.
4018: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4019: }
1.3 raeburn 4020: return $resulttext;
1.1 raeburn 4021: }
4022:
1.3 raeburn 4023: sub modify_autoenroll {
4024: my ($dom,%domconfig) = @_;
1.1 raeburn 4025: my ($resulttext,%changes);
4026: my %currautoenroll;
4027: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4028: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
4029: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
4030: }
4031: }
4032: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
4033: my %title = ( run => 'Auto-enrollment active',
4034: sender => 'Sender for notification messages');
4035: my @offon = ('off','on');
1.17 raeburn 4036: my $sender_uname = $env{'form.sender_uname'};
4037: my $sender_domain = $env{'form.sender_domain'};
4038: if ($sender_domain eq '') {
4039: $sender_uname = '';
4040: } elsif ($sender_uname eq '') {
4041: $sender_domain = '';
4042: }
1.1 raeburn 4043: my %autoenrollhash = (
4044: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 4045: sender_uname => $sender_uname,
4046: sender_domain => $sender_domain,
1.1 raeburn 4047:
4048: }
4049: );
1.4 raeburn 4050: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
4051: $dom);
1.1 raeburn 4052: if ($putresult eq 'ok') {
4053: if (exists($currautoenroll{'run'})) {
4054: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
4055: $changes{'run'} = 1;
4056: }
4057: } elsif ($autorun) {
4058: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 4059: $changes{'run'} = 1;
1.1 raeburn 4060: }
4061: }
1.17 raeburn 4062: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 4063: $changes{'sender'} = 1;
4064: }
1.17 raeburn 4065: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 4066: $changes{'sender'} = 1;
4067: }
4068: if (keys(%changes) > 0) {
4069: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 4070: if ($changes{'run'}) {
1.1 raeburn 4071: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
4072: }
4073: if ($changes{'sender'}) {
1.17 raeburn 4074: if ($sender_uname eq '' || $sender_domain eq '') {
4075: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
4076: } else {
4077: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
4078: }
1.1 raeburn 4079: }
4080: $resulttext .= '</ul>';
4081: } else {
4082: $resulttext = &mt('No changes made to auto-enrollment settings');
4083: }
4084: } else {
1.11 albertel 4085: $resulttext = '<span class="LC_error">'.
4086: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4087: }
1.3 raeburn 4088: return $resulttext;
1.1 raeburn 4089: }
4090:
4091: sub modify_autoupdate {
1.3 raeburn 4092: my ($dom,%domconfig) = @_;
1.1 raeburn 4093: my ($resulttext,%currautoupdate,%fields,%changes);
4094: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
4095: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
4096: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
4097: }
4098: }
4099: my @offon = ('off','on');
4100: my %title = &Apache::lonlocal::texthash (
4101: run => 'Auto-update:',
4102: classlists => 'Updates to user information in classlists?'
4103: );
1.44 raeburn 4104: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 4105: my %fieldtitles = &Apache::lonlocal::texthash (
4106: id => 'Student/Employee ID',
1.20 raeburn 4107: permanentemail => 'E-mail address',
1.1 raeburn 4108: lastname => 'Last Name',
4109: firstname => 'First Name',
4110: middlename => 'Middle Name',
4111: gen => 'Generation',
4112: );
4113: my $othertitle = &mt('All users');
4114: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 4115: $othertitle = &mt('Other users');
1.1 raeburn 4116: }
4117: foreach my $key (keys(%env)) {
4118: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
4119: push(@{$fields{$1}},$2);
4120: }
4121: }
4122: my %updatehash = (
4123: autoupdate => { run => $env{'form.autoupdate_run'},
4124: classlists => $env{'form.classlists'},
4125: fields => {%fields},
4126: }
4127: );
4128: foreach my $key (keys(%currautoupdate)) {
4129: if (($key eq 'run') || ($key eq 'classlists')) {
4130: if (exists($updatehash{autoupdate}{$key})) {
4131: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
4132: $changes{$key} = 1;
4133: }
4134: }
4135: } elsif ($key eq 'fields') {
4136: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 4137: foreach my $item (@{$types},'default') {
1.1 raeburn 4138: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
4139: my $change = 0;
4140: foreach my $type (@{$currautoupdate{$key}{$item}}) {
4141: if (!exists($fields{$item})) {
4142: $change = 1;
4143: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 4144: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 4145: $change = 1;
4146: }
4147: }
4148: }
4149: if ($change) {
4150: push(@{$changes{$key}},$item);
4151: }
1.26 raeburn 4152: }
1.1 raeburn 4153: }
4154: }
4155: }
4156: }
1.26 raeburn 4157: foreach my $item (@{$types},'default') {
4158: if (defined($fields{$item})) {
4159: if (ref($currautoupdate{'fields'}) eq 'HASH') {
4160: if (!exists($currautoupdate{'fields'}{$item})) {
4161: push(@{$changes{'fields'}},$item);
4162: }
4163: } else {
4164: push(@{$changes{'fields'}},$item);
1.1 raeburn 4165: }
4166: }
4167: }
4168: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
4169: $dom);
4170: if ($putresult eq 'ok') {
4171: if (keys(%changes) > 0) {
4172: $resulttext = &mt('Changes made:').'<ul>';
4173: foreach my $key (sort(keys(%changes))) {
4174: if (ref($changes{$key}) eq 'ARRAY') {
4175: foreach my $item (@{$changes{$key}}) {
4176: my @newvalues;
4177: foreach my $type (@{$fields{$item}}) {
4178: push(@newvalues,$fieldtitles{$type});
4179: }
1.3 raeburn 4180: my $newvaluestr;
4181: if (@newvalues > 0) {
4182: $newvaluestr = join(', ',@newvalues);
4183: } else {
4184: $newvaluestr = &mt('none');
1.6 raeburn 4185: }
1.1 raeburn 4186: if ($item eq 'default') {
1.26 raeburn 4187: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 4188: } else {
1.26 raeburn 4189: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 4190: }
4191: }
4192: } else {
4193: my $newvalue;
4194: if ($key eq 'run') {
4195: $newvalue = $offon[$env{'form.autoupdate_run'}];
4196: } else {
4197: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 4198: }
1.1 raeburn 4199: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
4200: }
4201: }
4202: $resulttext .= '</ul>';
4203: } else {
1.3 raeburn 4204: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 4205: }
4206: } else {
1.11 albertel 4207: $resulttext = '<span class="LC_error">'.
4208: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4209: }
1.3 raeburn 4210: return $resulttext;
1.1 raeburn 4211: }
4212:
1.23 raeburn 4213: sub modify_directorysrch {
4214: my ($dom,%domconfig) = @_;
4215: my ($resulttext,%changes);
4216: my %currdirsrch;
4217: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
4218: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
4219: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
4220: }
4221: }
4222: my %title = ( available => 'Directory search available',
1.24 raeburn 4223: localonly => 'Other domains can search',
1.23 raeburn 4224: searchby => 'Search types',
4225: searchtypes => 'Search latitude');
4226: my @offon = ('off','on');
1.24 raeburn 4227: my @otherdoms = ('Yes','No');
1.23 raeburn 4228:
1.25 raeburn 4229: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 4230: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
4231: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
4232:
1.44 raeburn 4233: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 4234: if (keys(%{$usertypes}) == 0) {
4235: @cansearch = ('default');
4236: } else {
4237: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
4238: foreach my $type (@{$currdirsrch{'cansearch'}}) {
4239: if (!grep(/^\Q$type\E$/,@cansearch)) {
4240: push(@{$changes{'cansearch'}},$type);
4241: }
1.23 raeburn 4242: }
1.26 raeburn 4243: foreach my $type (@cansearch) {
4244: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
4245: push(@{$changes{'cansearch'}},$type);
4246: }
1.23 raeburn 4247: }
1.26 raeburn 4248: } else {
4249: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 4250: }
4251: }
4252:
4253: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
4254: foreach my $by (@{$currdirsrch{'searchby'}}) {
4255: if (!grep(/^\Q$by\E$/,@searchby)) {
4256: push(@{$changes{'searchby'}},$by);
4257: }
4258: }
4259: foreach my $by (@searchby) {
4260: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
4261: push(@{$changes{'searchby'}},$by);
4262: }
4263: }
4264: } else {
4265: push(@{$changes{'searchby'}},@searchby);
4266: }
1.25 raeburn 4267:
4268: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
4269: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
4270: if (!grep(/^\Q$type\E$/,@searchtypes)) {
4271: push(@{$changes{'searchtypes'}},$type);
4272: }
4273: }
4274: foreach my $type (@searchtypes) {
4275: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
4276: push(@{$changes{'searchtypes'}},$type);
4277: }
4278: }
4279: } else {
4280: if (exists($currdirsrch{'searchtypes'})) {
4281: foreach my $type (@searchtypes) {
4282: if ($type ne $currdirsrch{'searchtypes'}) {
4283: push(@{$changes{'searchtypes'}},$type);
4284: }
4285: }
4286: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
4287: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
4288: }
4289: } else {
4290: push(@{$changes{'searchtypes'}},@searchtypes);
4291: }
4292: }
4293:
1.23 raeburn 4294: my %dirsrch_hash = (
4295: directorysrch => { available => $env{'form.dirsrch_available'},
4296: cansearch => \@cansearch,
1.24 raeburn 4297: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 4298: searchby => \@searchby,
1.25 raeburn 4299: searchtypes => \@searchtypes,
1.23 raeburn 4300: }
4301: );
4302: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
4303: $dom);
4304: if ($putresult eq 'ok') {
4305: if (exists($currdirsrch{'available'})) {
4306: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
4307: $changes{'available'} = 1;
4308: }
4309: } else {
4310: if ($env{'form.dirsrch_available'} eq '1') {
4311: $changes{'available'} = 1;
4312: }
4313: }
1.24 raeburn 4314: if (exists($currdirsrch{'localonly'})) {
4315: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
4316: $changes{'localonly'} = 1;
4317: }
4318: } else {
4319: if ($env{'form.dirsrch_localonly'} eq '1') {
4320: $changes{'localonly'} = 1;
4321: }
4322: }
1.23 raeburn 4323: if (keys(%changes) > 0) {
4324: $resulttext = &mt('Changes made:').'<ul>';
4325: if ($changes{'available'}) {
4326: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
4327: }
1.24 raeburn 4328: if ($changes{'localonly'}) {
4329: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
4330: }
4331:
1.23 raeburn 4332: if (ref($changes{'cansearch'}) eq 'ARRAY') {
4333: my $chgtext;
1.26 raeburn 4334: if (ref($usertypes) eq 'HASH') {
4335: if (keys(%{$usertypes}) > 0) {
4336: foreach my $type (@{$types}) {
4337: if (grep(/^\Q$type\E$/,@cansearch)) {
4338: $chgtext .= $usertypes->{$type}.'; ';
4339: }
4340: }
4341: if (grep(/^default$/,@cansearch)) {
4342: $chgtext .= $othertitle;
4343: } else {
4344: $chgtext =~ s/\; $//;
4345: }
4346: $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 4347: }
4348: }
4349: }
4350: if (ref($changes{'searchby'}) eq 'ARRAY') {
4351: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4352: my $chgtext;
4353: foreach my $type (@{$titleorder}) {
4354: if (grep(/^\Q$type\E$/,@searchby)) {
4355: if (defined($searchtitles->{$type})) {
4356: $chgtext .= $searchtitles->{$type}.'; ';
4357: }
4358: }
4359: }
4360: $chgtext =~ s/\; $//;
4361: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
4362: }
1.25 raeburn 4363: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
4364: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
4365: my $chgtext;
4366: foreach my $type (@{$srchtypeorder}) {
4367: if (grep(/^\Q$type\E$/,@searchtypes)) {
4368: if (defined($srchtypes_desc->{$type})) {
4369: $chgtext .= $srchtypes_desc->{$type}.'; ';
4370: }
4371: }
4372: }
4373: $chgtext =~ s/\; $//;
4374: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 4375: }
4376: $resulttext .= '</ul>';
4377: } else {
4378: $resulttext = &mt('No changes made to institution directory search settings');
4379: }
4380: } else {
4381: $resulttext = '<span class="LC_error">'.
1.27 raeburn 4382: &mt('An error occurred: [_1]',$putresult).'</span>';
4383: }
4384: return $resulttext;
4385: }
4386:
1.28 raeburn 4387: sub modify_contacts {
4388: my ($dom,%domconfig) = @_;
4389: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
4390: if (ref($domconfig{'contacts'}) eq 'HASH') {
4391: foreach my $key (keys(%{$domconfig{'contacts'}})) {
4392: $currsetting{$key} = $domconfig{'contacts'}{$key};
4393: }
4394: }
4395: my (%others,%to);
4396: my @contacts = ('supportemail','adminemail');
1.102 raeburn 4397: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
4398: 'requestsmail');
1.28 raeburn 4399: foreach my $type (@mailings) {
4400: @{$newsetting{$type}} =
4401: &Apache::loncommon::get_env_multiple('form.'.$type);
4402: foreach my $item (@contacts) {
4403: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
4404: $contacts_hash{contacts}{$type}{$item} = 1;
4405: } else {
4406: $contacts_hash{contacts}{$type}{$item} = 0;
4407: }
4408: }
4409: $others{$type} = $env{'form.'.$type.'_others'};
4410: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
4411: }
4412: foreach my $item (@contacts) {
4413: $to{$item} = $env{'form.'.$item};
4414: $contacts_hash{'contacts'}{$item} = $to{$item};
4415: }
4416: if (keys(%currsetting) > 0) {
4417: foreach my $item (@contacts) {
4418: if ($to{$item} ne $currsetting{$item}) {
4419: $changes{$item} = 1;
4420: }
4421: }
4422: foreach my $type (@mailings) {
4423: foreach my $item (@contacts) {
4424: if (ref($currsetting{$type}) eq 'HASH') {
4425: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
4426: push(@{$changes{$type}},$item);
4427: }
4428: } else {
4429: push(@{$changes{$type}},@{$newsetting{$type}});
4430: }
4431: }
4432: if ($others{$type} ne $currsetting{$type}{'others'}) {
4433: push(@{$changes{$type}},'others');
4434: }
4435: }
4436: } else {
4437: my %default;
4438: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4439: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4440: $default{'errormail'} = 'adminemail';
4441: $default{'packagesmail'} = 'adminemail';
4442: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 4443: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 4444: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 4445: foreach my $item (@contacts) {
4446: if ($to{$item} ne $default{$item}) {
4447: $changes{$item} = 1;
4448: }
4449: }
4450: foreach my $type (@mailings) {
4451: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
4452:
4453: push(@{$changes{$type}},@{$newsetting{$type}});
4454: }
4455: if ($others{$type} ne '') {
4456: push(@{$changes{$type}},'others');
4457: }
4458: }
4459: }
4460: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
4461: $dom);
4462: if ($putresult eq 'ok') {
4463: if (keys(%changes) > 0) {
4464: my ($titles,$short_titles) = &contact_titles();
4465: $resulttext = &mt('Changes made:').'<ul>';
4466: foreach my $item (@contacts) {
4467: if ($changes{$item}) {
4468: $resulttext .= '<li>'.$titles->{$item}.
4469: &mt(' set to: ').
4470: '<span class="LC_cusr_emph">'.
4471: $to{$item}.'</span></li>';
4472: }
4473: }
4474: foreach my $type (@mailings) {
4475: if (ref($changes{$type}) eq 'ARRAY') {
4476: $resulttext .= '<li>'.$titles->{$type}.': ';
4477: my @text;
4478: foreach my $item (@{$newsetting{$type}}) {
4479: push(@text,$short_titles->{$item});
4480: }
4481: if ($others{$type} ne '') {
4482: push(@text,$others{$type});
4483: }
4484: $resulttext .= '<span class="LC_cusr_emph">'.
4485: join(', ',@text).'</span></li>';
4486: }
4487: }
4488: $resulttext .= '</ul>';
4489: } else {
1.34 raeburn 4490: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 4491: }
4492: } else {
4493: $resulttext = '<span class="LC_error">'.
4494: &mt('An error occurred: [_1].',$putresult).'</span>';
4495: }
4496: return $resulttext;
4497: }
4498:
4499: sub modify_usercreation {
1.27 raeburn 4500: my ($dom,%domconfig) = @_;
1.34 raeburn 4501: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 4502: my $warningmsg;
1.27 raeburn 4503: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4504: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
4505: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
4506: }
4507: }
4508: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 4509: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 4510: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 4511: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 4512: foreach my $item(@contexts) {
1.45 raeburn 4513: if ($item eq 'selfcreate') {
1.50 raeburn 4514: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 4515: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4516: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 4517: if (ref($cancreate{$item}) eq 'ARRAY') {
4518: if (grep(/^login$/,@{$cancreate{$item}})) {
4519: $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.');
4520: }
1.43 raeburn 4521: }
4522: }
1.50 raeburn 4523: } else {
4524: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 4525: }
1.34 raeburn 4526: }
1.93 raeburn 4527: my ($othertitle,$usertypes,$types) =
4528: &Apache::loncommon::sorted_inst_types($dom);
4529: if (ref($types) eq 'ARRAY') {
4530: if (@{$types} > 0) {
4531: @{$cancreate{'statustocreate'}} =
4532: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.102.2.2! raeburn 4533: } else {
! 4534: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 4535: }
4536: push(@contexts,'statustocreate');
4537: }
1.34 raeburn 4538: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
4539: foreach my $item (@contexts) {
1.93 raeburn 4540: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
4541: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 4542: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.102.2.2! raeburn 4543: if (ref($cancreate{$item}) eq 'ARRAY') {
! 4544: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
! 4545: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
! 4546: push(@{$changes{'cancreate'}},$item);
! 4547: }
1.50 raeburn 4548: }
4549: }
4550: }
4551: } else {
4552: if ($curr_usercreation{'cancreate'}{$item} eq '') {
4553: if (@{$cancreate{$item}} > 0) {
4554: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4555: push(@{$changes{'cancreate'}},$item);
4556: }
4557: }
4558: } else {
4559: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
4560: if (@{$cancreate{$item}} < 3) {
4561: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4562: push(@{$changes{'cancreate'}},$item);
4563: }
4564: }
4565: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
4566: if (@{$cancreate{$item}} > 0) {
4567: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4568: push(@{$changes{'cancreate'}},$item);
4569: }
4570: }
4571: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
4572: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4573: push(@{$changes{'cancreate'}},$item);
4574: }
4575: }
4576: }
4577: }
4578: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4579: foreach my $type (@{$cancreate{$item}}) {
4580: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
4581: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
4582: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4583: push(@{$changes{'cancreate'}},$item);
4584: }
4585: }
4586: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
4587: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
4588: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
4589: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4590: push(@{$changes{'cancreate'}},$item);
4591: }
4592: }
4593: }
4594: }
4595: }
4596: } else {
4597: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
4598: push(@{$changes{'cancreate'}},$item);
4599: }
4600: }
1.27 raeburn 4601: }
1.34 raeburn 4602: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
4603: foreach my $item (@contexts) {
1.43 raeburn 4604: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 4605: if ($cancreate{$item} ne 'any') {
4606: push(@{$changes{'cancreate'}},$item);
4607: }
4608: } else {
4609: if ($cancreate{$item} ne 'none') {
4610: push(@{$changes{'cancreate'}},$item);
4611: }
1.27 raeburn 4612: }
4613: }
4614: } else {
1.43 raeburn 4615: foreach my $item (@contexts) {
1.34 raeburn 4616: push(@{$changes{'cancreate'}},$item);
4617: }
1.27 raeburn 4618: }
1.34 raeburn 4619:
1.27 raeburn 4620: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
4621: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
4622: if (!grep(/^\Q$type\E$/,@username_rule)) {
4623: push(@{$changes{'username_rule'}},$type);
4624: }
4625: }
4626: foreach my $type (@username_rule) {
4627: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
4628: push(@{$changes{'username_rule'}},$type);
4629: }
4630: }
4631: } else {
4632: push(@{$changes{'username_rule'}},@username_rule);
4633: }
4634:
1.32 raeburn 4635: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
4636: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
4637: if (!grep(/^\Q$type\E$/,@id_rule)) {
4638: push(@{$changes{'id_rule'}},$type);
4639: }
4640: }
4641: foreach my $type (@id_rule) {
4642: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
4643: push(@{$changes{'id_rule'}},$type);
4644: }
4645: }
4646: } else {
4647: push(@{$changes{'id_rule'}},@id_rule);
4648: }
4649:
1.43 raeburn 4650: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
4651: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
4652: if (!grep(/^\Q$type\E$/,@email_rule)) {
4653: push(@{$changes{'email_rule'}},$type);
4654: }
4655: }
4656: foreach my $type (@email_rule) {
4657: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
4658: push(@{$changes{'email_rule'}},$type);
4659: }
4660: }
4661: } else {
4662: push(@{$changes{'email_rule'}},@email_rule);
4663: }
4664:
4665: my @authen_contexts = ('author','course','domain');
1.28 raeburn 4666: my @authtypes = ('int','krb4','krb5','loc');
4667: my %authhash;
1.43 raeburn 4668: foreach my $item (@authen_contexts) {
1.28 raeburn 4669: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
4670: foreach my $auth (@authtypes) {
4671: if (grep(/^\Q$auth\E$/,@authallowed)) {
4672: $authhash{$item}{$auth} = 1;
4673: } else {
4674: $authhash{$item}{$auth} = 0;
4675: }
4676: }
4677: }
4678: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 4679: foreach my $item (@authen_contexts) {
1.28 raeburn 4680: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
4681: foreach my $auth (@authtypes) {
4682: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
4683: push(@{$changes{'authtypes'}},$item);
4684: last;
4685: }
4686: }
4687: }
4688: }
4689: } else {
1.43 raeburn 4690: foreach my $item (@authen_contexts) {
1.28 raeburn 4691: push(@{$changes{'authtypes'}},$item);
4692: }
4693: }
4694:
1.27 raeburn 4695: my %usercreation_hash = (
1.28 raeburn 4696: usercreation => {
1.34 raeburn 4697: cancreate => \%cancreate,
1.27 raeburn 4698: username_rule => \@username_rule,
1.32 raeburn 4699: id_rule => \@id_rule,
1.43 raeburn 4700: email_rule => \@email_rule,
1.32 raeburn 4701: authtypes => \%authhash,
1.27 raeburn 4702: }
4703: );
4704:
4705: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
4706: $dom);
1.50 raeburn 4707:
4708: my %selfcreatetypes = (
4709: sso => 'users authenticated by institutional single sign on',
4710: login => 'users authenticated by institutional log-in',
4711: email => 'users who provide a valid e-mail address for use as the username',
4712: );
1.27 raeburn 4713: if ($putresult eq 'ok') {
4714: if (keys(%changes) > 0) {
4715: $resulttext = &mt('Changes made:').'<ul>';
4716: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 4717: my %lt = &usercreation_types();
4718: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 4719: my $chgtext;
4720: unless ($type eq 'statustocreate') {
4721: $chgtext = $lt{$type}.', ';
4722: }
1.45 raeburn 4723: if ($type eq 'selfcreate') {
1.50 raeburn 4724: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 4725: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 4726: } else {
1.100 raeburn 4727: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 4728: foreach my $case (@{$cancreate{$type}}) {
4729: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
4730: }
4731: $chgtext .= '</ul>';
1.100 raeburn 4732: if (ref($cancreate{$type}) eq 'ARRAY') {
4733: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
4734: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
4735: if (@{$cancreate{'statustocreate'}} == 0) {
4736: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
4737: }
4738: }
4739: }
4740: }
1.43 raeburn 4741: }
1.93 raeburn 4742: } elsif ($type eq 'statustocreate') {
1.96 raeburn 4743: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
4744: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
4745: if (@{$cancreate{'selfcreate'}} > 0) {
4746: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 4747:
4748: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 4749: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 4750: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
4751: }
1.96 raeburn 4752: } elsif (ref($usertypes) eq 'HASH') {
4753: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 4754: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
4755: } else {
4756: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
4757: }
4758: $chgtext .= '<ul>';
4759: foreach my $case (@{$cancreate{$type}}) {
4760: if ($case eq 'default') {
4761: $chgtext .= '<li>'.$othertitle.'</li>';
4762: } else {
4763: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 4764: }
4765: }
1.100 raeburn 4766: $chgtext .= '</ul>';
4767: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
4768: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
4769: }
4770: }
4771: } else {
4772: if (@{$cancreate{$type}} == 0) {
4773: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
4774: } else {
4775: $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 4776: }
4777: }
4778: }
1.43 raeburn 4779: } else {
4780: if ($cancreate{$type} eq 'none') {
4781: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
4782: } elsif ($cancreate{$type} eq 'any') {
4783: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
4784: } elsif ($cancreate{$type} eq 'official') {
4785: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
4786: } elsif ($cancreate{$type} eq 'unofficial') {
4787: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
4788: }
1.34 raeburn 4789: }
4790: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 4791: }
4792: }
4793: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 4794: my ($rules,$ruleorder) =
4795: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 4796: my $chgtext = '<ul>';
4797: foreach my $type (@username_rule) {
4798: if (ref($rules->{$type}) eq 'HASH') {
4799: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
4800: }
4801: }
4802: $chgtext .= '</ul>';
4803: if (@username_rule > 0) {
4804: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4805: } else {
1.28 raeburn 4806: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 4807: }
4808: }
1.32 raeburn 4809: if (ref($changes{'id_rule'}) eq 'ARRAY') {
4810: my ($idrules,$idruleorder) =
4811: &Apache::lonnet::inst_userrules($dom,'id');
4812: my $chgtext = '<ul>';
4813: foreach my $type (@id_rule) {
4814: if (ref($idrules->{$type}) eq 'HASH') {
4815: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
4816: }
4817: }
4818: $chgtext .= '</ul>';
4819: if (@id_rule > 0) {
4820: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4821: } else {
4822: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
4823: }
4824: }
1.43 raeburn 4825: if (ref($changes{'email_rule'}) eq 'ARRAY') {
4826: my ($emailrules,$emailruleorder) =
4827: &Apache::lonnet::inst_userrules($dom,'email');
4828: my $chgtext = '<ul>';
4829: foreach my $type (@email_rule) {
4830: if (ref($emailrules->{$type}) eq 'HASH') {
4831: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
4832: }
4833: }
4834: $chgtext .= '</ul>';
4835: if (@email_rule > 0) {
4836: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
4837: } else {
4838: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
4839: }
4840: }
4841:
1.28 raeburn 4842: my %authname = &authtype_names();
4843: my %context_title = &context_names();
4844: if (ref($changes{'authtypes'}) eq 'ARRAY') {
4845: my $chgtext = '<ul>';
4846: foreach my $type (@{$changes{'authtypes'}}) {
4847: my @allowed;
4848: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
4849: foreach my $auth (@authtypes) {
4850: if ($authhash{$type}{$auth}) {
4851: push(@allowed,$authname{$auth});
4852: }
4853: }
1.43 raeburn 4854: if (@allowed > 0) {
4855: $chgtext .= join(', ',@allowed).'</li>';
4856: } else {
4857: $chgtext .= &mt('none').'</li>';
4858: }
1.28 raeburn 4859: }
4860: $chgtext .= '</ul>';
4861: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
4862: $resulttext .= '</li>';
4863: }
1.27 raeburn 4864: $resulttext .= '</ul>';
4865: } else {
1.28 raeburn 4866: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 4867: }
4868: } else {
4869: $resulttext = '<span class="LC_error">'.
1.23 raeburn 4870: &mt('An error occurred: [_1]',$putresult).'</span>';
4871: }
1.43 raeburn 4872: if ($warningmsg ne '') {
4873: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
4874: }
1.23 raeburn 4875: return $resulttext;
4876: }
4877:
1.33 raeburn 4878: sub modify_usermodification {
4879: my ($dom,%domconfig) = @_;
4880: my ($resulttext,%curr_usermodification,%changes);
4881: if (ref($domconfig{'usermodification'}) eq 'HASH') {
4882: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
4883: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
4884: }
4885: }
1.63 raeburn 4886: my @contexts = ('author','course','selfcreate');
1.33 raeburn 4887: my %context_title = (
4888: author => 'In author context',
4889: course => 'In course context',
1.63 raeburn 4890: selfcreate => 'When self creating account',
1.33 raeburn 4891: );
4892: my @fields = ('lastname','firstname','middlename','generation',
4893: 'permanentemail','id');
4894: my %roles = (
4895: author => ['ca','aa'],
4896: course => ['st','ep','ta','in','cr'],
4897: );
1.63 raeburn 4898: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4899: if (ref($types) eq 'ARRAY') {
4900: push(@{$types},'default');
4901: $usertypes->{'default'} = $othertitle;
4902: }
4903: $roles{'selfcreate'} = $types;
1.33 raeburn 4904: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4905: my %modifyhash;
4906: foreach my $context (@contexts) {
4907: foreach my $role (@{$roles{$context}}) {
4908: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
4909: foreach my $item (@fields) {
4910: if (grep(/^\Q$item\E$/,@modifiable)) {
4911: $modifyhash{$context}{$role}{$item} = 1;
4912: } else {
4913: $modifyhash{$context}{$role}{$item} = 0;
4914: }
4915: }
4916: }
4917: if (ref($curr_usermodification{$context}) eq 'HASH') {
4918: foreach my $role (@{$roles{$context}}) {
4919: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
4920: foreach my $field (@fields) {
4921: if ($modifyhash{$context}{$role}{$field} ne
4922: $curr_usermodification{$context}{$role}{$field}) {
4923: push(@{$changes{$context}},$role);
4924: last;
4925: }
4926: }
4927: }
4928: }
4929: } else {
4930: foreach my $context (@contexts) {
4931: foreach my $role (@{$roles{$context}}) {
4932: push(@{$changes{$context}},$role);
4933: }
4934: }
4935: }
4936: }
4937: my %usermodification_hash = (
4938: usermodification => \%modifyhash,
4939: );
4940: my $putresult = &Apache::lonnet::put_dom('configuration',
4941: \%usermodification_hash,$dom);
4942: if ($putresult eq 'ok') {
4943: if (keys(%changes) > 0) {
4944: $resulttext = &mt('Changes made: ').'<ul>';
4945: foreach my $context (@contexts) {
4946: if (ref($changes{$context}) eq 'ARRAY') {
4947: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
4948: if (ref($changes{$context}) eq 'ARRAY') {
4949: foreach my $role (@{$changes{$context}}) {
4950: my $rolename;
1.63 raeburn 4951: if ($context eq 'selfcreate') {
4952: $rolename = $role;
4953: if (ref($usertypes) eq 'HASH') {
4954: if ($usertypes->{$role} ne '') {
4955: $rolename = $usertypes->{$role};
4956: }
4957: }
1.33 raeburn 4958: } else {
1.63 raeburn 4959: if ($role eq 'cr') {
4960: $rolename = &mt('Custom');
4961: } else {
4962: $rolename = &Apache::lonnet::plaintext($role);
4963: }
1.33 raeburn 4964: }
4965: my @modifiable;
1.63 raeburn 4966: if ($context eq 'selfcreate') {
4967: $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): ');
4968: } else {
4969: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
4970: }
1.33 raeburn 4971: foreach my $field (@fields) {
4972: if ($modifyhash{$context}{$role}{$field}) {
4973: push(@modifiable,$fieldtitles{$field});
4974: }
4975: }
4976: if (@modifiable > 0) {
4977: $resulttext .= join(', ',@modifiable);
4978: } else {
4979: $resulttext .= &mt('none');
4980: }
4981: $resulttext .= '</li>';
4982: }
4983: $resulttext .= '</ul></li>';
4984: }
4985: }
4986: }
4987: $resulttext .= '</ul>';
4988: } else {
4989: $resulttext = &mt('No changes made to user modification settings');
4990: }
4991: } else {
4992: $resulttext = '<span class="LC_error">'.
4993: &mt('An error occurred: [_1]',$putresult).'</span>';
4994: }
4995: return $resulttext;
4996: }
4997:
1.43 raeburn 4998: sub modify_defaults {
4999: my ($dom,$r) = @_;
5000: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
5001: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.68 raeburn 5002: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
1.43 raeburn 5003: my @authtypes = ('internal','krb4','krb5','localauth');
5004: foreach my $item (@items) {
5005: $newvalues{$item} = $env{'form.'.$item};
5006: if ($item eq 'auth_def') {
5007: if ($newvalues{$item} ne '') {
5008: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
5009: push(@errors,$item);
5010: }
5011: }
5012: } elsif ($item eq 'lang_def') {
5013: if ($newvalues{$item} ne '') {
5014: if ($newvalues{$item} =~ /^(\w+)/) {
5015: my $langcode = $1;
1.102.2.2! raeburn 5016: if ($langcode ne 'x_chef') {
! 5017: if (code2language($langcode) eq '') {
! 5018: push(@errors,$item);
! 5019: }
1.43 raeburn 5020: }
5021: } else {
5022: push(@errors,$item);
5023: }
5024: }
1.54 raeburn 5025: } elsif ($item eq 'timezone_def') {
5026: if ($newvalues{$item} ne '') {
1.62 raeburn 5027: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 5028: push(@errors,$item);
5029: }
5030: }
1.68 raeburn 5031: } elsif ($item eq 'datelocale_def') {
5032: if ($newvalues{$item} ne '') {
5033: my @datelocale_ids = DateTime::Locale->ids();
5034: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
5035: push(@errors,$item);
5036: }
5037: }
1.43 raeburn 5038: }
5039: if (grep(/^\Q$item\E$/,@errors)) {
5040: $newvalues{$item} = $domdefaults{$item};
5041: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
5042: $changes{$item} = 1;
5043: }
1.72 raeburn 5044: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 5045: }
5046: my %defaults_hash = (
1.72 raeburn 5047: defaults => \%newvalues,
5048: );
1.43 raeburn 5049: my $title = &defaults_titles();
5050: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
5051: $dom);
5052: if ($putresult eq 'ok') {
5053: if (keys(%changes) > 0) {
5054: $resulttext = &mt('Changes made:').'<ul>';
5055: my $version = $r->dir_config('lonVersion');
5056: 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";
5057: foreach my $item (sort(keys(%changes))) {
5058: my $value = $env{'form.'.$item};
5059: if ($value eq '') {
5060: $value = &mt('none');
5061: } elsif ($item eq 'auth_def') {
5062: my %authnames = &authtype_names();
5063: my %shortauth = (
5064: internal => 'int',
5065: krb4 => 'krb4',
5066: krb5 => 'krb5',
5067: localauth => 'loc',
5068: );
5069: $value = $authnames{$shortauth{$value}};
5070: }
5071: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
5072: $mailmsgtext .= "$title->{$item} set to $value\n";
5073: }
5074: $resulttext .= '</ul>';
5075: $mailmsgtext .= "\n";
5076: my $cachetime = 24*60*60;
1.72 raeburn 5077: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 5078: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 5079: my $sysmail = $r->dir_config('lonSysEMail');
5080: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
5081: }
1.43 raeburn 5082: } else {
1.54 raeburn 5083: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 5084: }
5085: } else {
5086: $resulttext = '<span class="LC_error">'.
5087: &mt('An error occurred: [_1]',$putresult).'</span>';
5088: }
5089: if (@errors > 0) {
5090: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
5091: foreach my $item (@errors) {
5092: $resulttext .= ' "'.$title->{$item}.'",';
5093: }
5094: $resulttext =~ s/,$//;
5095: }
5096: return $resulttext;
5097: }
5098:
1.46 raeburn 5099: sub modify_scantron {
1.48 raeburn 5100: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 5101: my ($resulttext,%confhash,%changes,$errors);
5102: my $custom = 'custom.tab';
5103: my $default = 'default.tab';
5104: my $servadm = $r->dir_config('lonAdmEMail');
5105: my ($configuserok,$author_ok,$switchserver) =
5106: &config_check($dom,$confname,$servadm);
5107: if ($env{'form.scantronformat.filename'} ne '') {
5108: my $error;
5109: if ($configuserok eq 'ok') {
5110: if ($switchserver) {
5111: $error = &mt("Upload of scantron format file is not permitted to this server: [_1]",$switchserver);
5112: } else {
5113: if ($author_ok eq 'ok') {
5114: my ($result,$scantronurl) =
5115: &publishlogo($r,'upload','scantronformat',$dom,
5116: $confname,'scantron','','',$custom);
5117: if ($result eq 'ok') {
5118: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 5119: $changes{'scantronformat'} = 1;
1.46 raeburn 5120: } else {
5121: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
5122: }
5123: } else {
5124: $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);
5125: }
5126: }
5127: } else {
5128: $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);
5129: }
5130: if ($error) {
5131: &Apache::lonnet::logthis($error);
5132: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5133: }
5134: }
1.48 raeburn 5135: if (ref($domconfig{'scantron'}) eq 'HASH') {
5136: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5137: if ($env{'form.scantronformat_del'}) {
5138: $confhash{'scantron'}{'scantronformat'} = '';
5139: $changes{'scantronformat'} = 1;
1.46 raeburn 5140: }
5141: }
5142: }
5143: if (keys(%confhash) > 0) {
5144: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
5145: $dom);
5146: if ($putresult eq 'ok') {
5147: if (keys(%changes) > 0) {
1.48 raeburn 5148: if (ref($confhash{'scantron'}) eq 'HASH') {
5149: $resulttext = &mt('Changes made:').'<ul>';
5150: if ($confhash{'scantron'}{'scantronformat'} eq '') {
5151: $resulttext .= '<li>'.&mt('[_1] scantron format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
5152: } else {
5153: $resulttext .= '<li>'.&mt('Custom scantron format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 5154: }
1.48 raeburn 5155: $resulttext .= '</ul>';
5156: } else {
5157: $resulttext = &mt('Changes made to scantron format file.');
1.46 raeburn 5158: }
5159: $resulttext .= '</ul>';
5160: &Apache::loncommon::devalidate_domconfig_cache($dom);
5161: } else {
5162: $resulttext = &mt('No changes made to scantron format file');
5163: }
5164: } else {
5165: $resulttext = '<span class="LC_error">'.
5166: &mt('An error occurred: [_1]',$putresult).'</span>';
5167: }
5168: } else {
5169: $resulttext = &mt('No changes made to scantron format file');
5170: }
5171: if ($errors) {
5172: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5173: $errors.'</ul>';
5174: }
5175: return $resulttext;
5176: }
5177:
1.48 raeburn 5178: sub modify_coursecategories {
5179: my ($dom,%domconfig) = @_;
1.57 raeburn 5180: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
5181: $cathash);
1.48 raeburn 5182: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 5183: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 5184: $cathash = $domconfig{'coursecategories'}{'cats'};
5185: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
5186: $changes{'togglecats'} = 1;
5187: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
5188: }
5189: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
5190: $changes{'categorize'} = 1;
5191: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
5192: }
5193: } else {
5194: $changes{'togglecats'} = 1;
5195: $changes{'categorize'} = 1;
1.87 raeburn 5196: $domconfig{'coursecategories'} = {
5197: togglecats => $env{'form.togglecats'},
5198: categorize => $env{'form.categorize'},
5199: };
1.57 raeburn 5200: }
5201: if (ref($cathash) eq 'HASH') {
5202: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 5203: push (@deletecategory,'instcode::0');
5204: }
1.48 raeburn 5205: }
1.57 raeburn 5206: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
5207: if (ref($cathash) eq 'HASH') {
1.48 raeburn 5208: if (@deletecategory > 0) {
5209: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 5210: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 5211: foreach my $item (@deletecategory) {
1.57 raeburn 5212: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
5213: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 5214: $deletions{$item} = 1;
1.57 raeburn 5215: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 5216: }
5217: }
5218: }
1.57 raeburn 5219: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 5220: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 5221: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 5222: $reorderings{$item} = 1;
1.57 raeburn 5223: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 5224: }
5225: if ($env{'form.addcategory_name_'.$item} ne '') {
5226: my $newcat = $env{'form.addcategory_name_'.$item};
5227: my $newdepth = $depth+1;
5228: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 5229: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 5230: $adds{$newitem} = 1;
5231: }
5232: if ($env{'form.subcat_'.$item} ne '') {
5233: my $newcat = $env{'form.subcat_'.$item};
5234: my $newdepth = $depth+1;
5235: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 5236: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 5237: $adds{$newitem} = 1;
5238: }
5239: }
5240: }
5241: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 5242: if (ref($cathash) eq 'HASH') {
1.48 raeburn 5243: my $newitem = 'instcode::0';
1.57 raeburn 5244: if ($cathash->{$newitem} eq '') {
5245: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 5246: $adds{$newitem} = 1;
5247: }
5248: } else {
5249: my $newitem = 'instcode::0';
1.57 raeburn 5250: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 5251: $adds{$newitem} = 1;
5252: }
5253: }
5254: if ($env{'form.addcategory_name'} ne '') {
5255: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
1.57 raeburn 5256: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
1.48 raeburn 5257: $adds{$newitem} = 1;
5258: }
1.57 raeburn 5259: my $putresult;
1.48 raeburn 5260: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
5261: if (keys(%deletions) > 0) {
5262: foreach my $key (keys(%deletions)) {
5263: if ($predelallitems{$key} ne '') {
5264: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
5265: }
5266: }
5267: }
5268: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 5269: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 5270: if (ref($chkcats[0]) eq 'ARRAY') {
5271: my $depth = 0;
5272: my $chg = 0;
5273: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
5274: my $name = $chkcats[0][$i];
5275: my $item;
5276: if ($name eq '') {
5277: $chg ++;
5278: } else {
5279: $item = &escape($name).'::0';
5280: if ($chg) {
1.57 raeburn 5281: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 5282: }
5283: $depth ++;
1.57 raeburn 5284: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 5285: $depth --;
5286: }
5287: }
5288: }
1.57 raeburn 5289: }
5290: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
5291: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 5292: if ($putresult eq 'ok') {
1.57 raeburn 5293: my %title = (
5294: togglecats => 'Show/Hide a course in the catalog',
5295: categorize => 'Category assigned to course',
5296: );
5297: my %level = (
5298: dom => 'set from "Modify Course" (Domain)',
5299: crs => 'set from "Parameters" (Course)',
5300: );
1.48 raeburn 5301: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 5302: if ($changes{'togglecats'}) {
5303: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
5304: }
5305: if ($changes{'categorize'}) {
5306: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 5307: }
1.57 raeburn 5308: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
5309: my $cathash;
5310: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5311: $cathash = $domconfig{'coursecategories'}{'cats'};
5312: } else {
5313: $cathash = {};
5314: }
5315: my (@cats,@trails,%allitems);
5316: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
5317: if (keys(%deletions) > 0) {
5318: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
5319: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
5320: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
5321: }
5322: $resulttext .= '</ul></li>';
5323: }
5324: if (keys(%reorderings) > 0) {
5325: my %sort_by_trail;
5326: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
5327: foreach my $key (keys(%reorderings)) {
5328: if ($allitems{$key} ne '') {
5329: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
5330: }
1.48 raeburn 5331: }
1.57 raeburn 5332: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
5333: $resulttext .= '<li>'.$trails[$trail].'</li>';
5334: }
5335: $resulttext .= '</ul></li>';
1.48 raeburn 5336: }
1.57 raeburn 5337: if (keys(%adds) > 0) {
5338: my %sort_by_trail;
5339: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
5340: foreach my $key (keys(%adds)) {
5341: if ($allitems{$key} ne '') {
5342: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
5343: }
5344: }
5345: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
5346: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 5347: }
1.57 raeburn 5348: $resulttext .= '</ul></li>';
1.48 raeburn 5349: }
5350: }
5351: $resulttext .= '</ul>';
5352: } else {
5353: $resulttext = '<span class="LC_error">'.
1.57 raeburn 5354: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 5355: }
5356: } else {
5357: $resulttext = &mt('No changes made to course categories');
5358: }
5359: return $resulttext;
5360: }
5361:
1.69 raeburn 5362: sub modify_serverstatuses {
5363: my ($dom,%domconfig) = @_;
5364: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
5365: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
5366: %currserverstatus = %{$domconfig{'serverstatuses'}};
5367: }
5368: my @pages = &serverstatus_pages();
5369: foreach my $type (@pages) {
5370: $newserverstatus{$type}{'namedusers'} = '';
5371: $newserverstatus{$type}{'machines'} = '';
5372: if (defined($env{'form.'.$type.'_namedusers'})) {
5373: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
5374: my @okusers;
5375: foreach my $user (@users) {
5376: my ($uname,$udom) = split(/:/,$user);
5377: if (($udom =~ /^$match_domain$/) &&
5378: (&Apache::lonnet::domain($udom)) &&
5379: ($uname =~ /^$match_username$/)) {
5380: if (!grep(/^\Q$user\E/,@okusers)) {
5381: push(@okusers,$user);
5382: }
5383: }
5384: }
5385: if (@okusers > 0) {
5386: @okusers = sort(@okusers);
5387: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
5388: }
5389: }
5390: if (defined($env{'form.'.$type.'_machines'})) {
5391: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
5392: my @okmachines;
5393: foreach my $ip (@machines) {
5394: my @parts = split(/\./,$ip);
5395: next if (@parts < 4);
5396: my $badip = 0;
5397: for (my $i=0; $i<4; $i++) {
5398: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
5399: $badip = 1;
5400: last;
5401: }
5402: }
5403: if (!$badip) {
5404: push(@okmachines,$ip);
5405: }
5406: }
5407: @okmachines = sort(@okmachines);
5408: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
5409: }
5410: }
5411: my %serverstatushash = (
5412: serverstatuses => \%newserverstatus,
5413: );
5414: my %changes;
5415: foreach my $type (@pages) {
1.83 raeburn 5416: foreach my $setting ('namedusers','machines') {
1.84 raeburn 5417: my (@current,@new);
1.83 raeburn 5418: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 5419: if ($currserverstatus{$type}{$setting} ne '') {
5420: @current = split(/,/,$currserverstatus{$type}{$setting});
5421: }
5422: }
5423: if ($newserverstatus{$type}{$setting} ne '') {
5424: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 5425: }
5426: if (@current > 0) {
5427: if (@new > 0) {
5428: foreach my $item (@current) {
5429: if (!grep(/^\Q$item\E$/,@new)) {
5430: $changes{$type}{$setting} = 1;
1.82 raeburn 5431: last;
5432: }
5433: }
1.84 raeburn 5434: foreach my $item (@new) {
5435: if (!grep(/^\Q$item\E$/,@current)) {
5436: $changes{$type}{$setting} = 1;
5437: last;
1.82 raeburn 5438: }
5439: }
5440: } else {
1.83 raeburn 5441: $changes{$type}{$setting} = 1;
1.69 raeburn 5442: }
1.83 raeburn 5443: } elsif (@new > 0) {
5444: $changes{$type}{$setting} = 1;
1.69 raeburn 5445: }
5446: }
5447: }
5448: if (keys(%changes) > 0) {
1.81 raeburn 5449: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5450: my $putresult = &Apache::lonnet::put_dom('configuration',
5451: \%serverstatushash,$dom);
5452: if ($putresult eq 'ok') {
5453: $resulttext .= &mt('Changes made:').'<ul>';
5454: foreach my $type (@pages) {
1.84 raeburn 5455: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 5456: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 5457: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 5458: if ($newserverstatus{$type}{'namedusers'} eq '') {
5459: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
5460: } else {
5461: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
5462: }
1.84 raeburn 5463: }
5464: if ($changes{$type}{'machines'}) {
1.69 raeburn 5465: if ($newserverstatus{$type}{'machines'} eq '') {
5466: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
5467: } else {
5468: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
5469: }
5470:
5471: }
5472: $resulttext .= '</ul></li>';
5473: }
5474: }
5475: $resulttext .= '</ul>';
5476: } else {
5477: $resulttext = '<span class="LC_error">'.
5478: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
5479:
5480: }
5481: } else {
5482: $resulttext = &mt('No changes made to access to server status pages');
5483: }
5484: return $resulttext;
5485: }
5486:
1.48 raeburn 5487: sub recurse_check {
5488: my ($chkcats,$categories,$depth,$name) = @_;
5489: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
5490: my $chg = 0;
5491: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
5492: my $category = $chkcats->[$depth]{$name}[$j];
5493: my $item;
5494: if ($category eq '') {
5495: $chg ++;
5496: } else {
5497: my $deeper = $depth + 1;
5498: $item = &escape($category).':'.&escape($name).':'.$depth;
5499: if ($chg) {
5500: $categories->{$item} -= $chg;
5501: }
5502: &recurse_check($chkcats,$categories,$deeper,$category);
5503: $deeper --;
5504: }
5505: }
5506: }
5507: return;
5508: }
5509:
5510: sub recurse_cat_deletes {
5511: my ($item,$coursecategories,$deletions) = @_;
5512: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
5513: my $subdepth = $depth + 1;
5514: if (ref($coursecategories) eq 'HASH') {
5515: foreach my $subitem (keys(%{$coursecategories})) {
5516: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
5517: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
5518: delete($coursecategories->{$subitem});
5519: $deletions->{$subitem} = 1;
5520: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
5521: }
5522: }
5523: }
5524: return;
5525: }
5526:
1.3 raeburn 5527: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>