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