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