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