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