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