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