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