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