Annotation of loncom/interface/domainprefs.pm, revision 1.109
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.109 ! raeburn 4: # $Id: domainprefs.pm,v 1.108 2009/08/22 21:10:32 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.109 ! raeburn 1376: $datatable .= &mt('(overrides affiliation, if set)').
! 1377: '</td>'.
! 1378: '<td class="LC_left_item">'.
! 1379: '<table><tr>';
1.101 raeburn 1380: } else {
1.109 ! raeburn 1381: $datatable .= &mt('(overrides affiliation, if checked)').
! 1382: '</td>'.
! 1383: '<td class="LC_left_item" colspan="2">'.
! 1384: '<br />';
1.101 raeburn 1385: }
1386: my %advcell;
1.72 raeburn 1387: foreach my $item (@usertools) {
1.101 raeburn 1388: if ($context eq 'requestcourses') {
1389: my ($curroption,$currlimit);
1390: if (ref($settings) eq 'HASH') {
1391: if (ref($settings->{$item}) eq 'HASH') {
1392: $curroption = $settings->{$item}->{'_LC_adv'};
1393: if ($curroption =~ /^autolimit=(\d*)$/) {
1394: $currlimit = $1;
1395: }
1396: }
1397: }
1398: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1399: my $checked = '';
1400: if ($curroption eq '') {
1401: $checked = ' checked="checked"';
1402: }
1403: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1404: '<input type="radio" name="crsreq_'.$item.
1405: '__LC_adv" value=""'.$checked.' />'.
1406: &mt('No override set').'</label></span> ';
1.101 raeburn 1407: foreach my $option (@options) {
1408: my $val = $option;
1409: if ($option eq 'norequest') {
1410: $val = 0;
1411: }
1412: if ($option eq 'validate') {
1413: my $canvalidate = 0;
1414: if (ref($validations{$item}) eq 'HASH') {
1415: if ($validations{$item}{'_LC_adv'}) {
1416: $canvalidate = 1;
1417: }
1418: }
1419: next if (!$canvalidate);
1420: }
1421: my $checked = '';
1.104 raeburn 1422: if ($val eq $curroption) {
1.101 raeburn 1423: $checked = ' checked="checked"';
1424: } elsif ($option eq 'autolimit') {
1425: if ($curroption =~ /^autolimit/) {
1426: $checked = ' checked="checked"';
1427: }
1428: }
1429: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1430: '<input type="radio" name="crsreq_'.$item.
1431: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1432: $titles{$option}.'</label>';
1433: if ($option eq 'autolimit') {
1434: $advcell{$item} .= '<input type="text" name="crsreq_'.
1435: $item.'_limit__LC_adv" size="1" '.
1436: 'value="'.$currlimit.'" />';
1437: }
1438: $advcell{$item} .= '</span> ';
1.104 raeburn 1439: if ($option eq 'autolimit') {
1440: $advcell{$item} .= $titles{'unlimited'}
1441: }
1.101 raeburn 1442: }
1443: } else {
1444: my $checked = 'checked="checked" ';
1445: if (ref($settings) eq 'HASH') {
1446: if (ref($settings->{$item}) eq 'HASH') {
1447: if ($settings->{$item}->{'_LC_adv'} == 0) {
1448: $checked = '';
1449: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1450: $checked = 'checked="checked" ';
1451: }
1.79 raeburn 1452: }
1.72 raeburn 1453: }
1.101 raeburn 1454: $datatable .= '<span class="LC_nobreak"><label>'.
1455: '<input type="checkbox" name="'.$context.'_'.$item.
1456: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1457: '</label></span> ';
1458: }
1459: }
1460: if ($context eq 'requestcourses') {
1461: $datatable .= '</tr><tr>';
1462: foreach my $item (@usertools) {
1.106 raeburn 1463: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1464: }
1.101 raeburn 1465: $datatable .= '</tr></table>';
1.72 raeburn 1466: }
1.98 raeburn 1467: $datatable .= '</td></tr>';
1.30 raeburn 1468: $$rowtotal += $typecount;
1.3 raeburn 1469: return $datatable;
1470: }
1471:
1.102 raeburn 1472: sub print_courserequestmail {
1473: my ($dom,$settings,$rowtotal) = @_;
1.104 raeburn 1474: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1475: $now = time;
1476: $rows = 0;
1477: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1478: foreach my $server (keys(%dompersonnel)) {
1479: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1480: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1481: if (!grep(/^$uname:$udom$/,@domcoord)) {
1482: push(@domcoord,$uname.':'.$udom);
1483: }
1484: }
1485: }
1486: if (ref($settings) eq 'HASH') {
1487: if (ref($settings->{'notify'}) eq 'HASH') {
1488: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1489: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1490: }
1491: }
1492: }
1.104 raeburn 1493: if (@currapproval) {
1494: foreach my $dc (@currapproval) {
1.102 raeburn 1495: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1496: push(@domcoord,$dc);
1497: }
1498: }
1499: }
1500: @domcoord = sort(@domcoord);
1501: my $numinrow = 4;
1502: my $numdc = @domcoord;
1503: my $css_class = 'class="LC_odd_row"';
1504: $datatable = '<tr'.$css_class.'>'.
1505: ' <td>'.&mt('Receive notification of course requests requiring approval.').
1506: ' </td>'.
1507: ' <td class="LC_left_item">';
1508: if (@domcoord > 0) {
1509: $datatable .= '<table>';
1510: for (my $i=0; $i<$numdc; $i++) {
1511: my $rem = $i%($numinrow);
1512: if ($rem == 0) {
1513: if ($i > 0) {
1514: $datatable .= '</tr>';
1515: }
1516: $datatable .= '<tr>';
1517: $rows ++;
1518: }
1519: my $check = ' ';
1.104 raeburn 1520: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1521: $check = ' checked="checked" ';
1522: }
1523: my ($uname,$udom) = split(':',$domcoord[$i]);
1524: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1525: if ($i == $numdc-1) {
1526: my $colsleft = $numinrow-$rem;
1527: if ($colsleft > 1) {
1528: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1529: } else {
1530: $datatable .= '<td class="LC_left_item">';
1531: }
1532: } else {
1533: $datatable .= '<td class="LC_left_item">';
1534: }
1535: $datatable .= '<span class="LC_nobreak"><label>'.
1536: '<input type="checkbox" name="reqapprovalnotify" '.
1537: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1538: $fullname.'</label></span></td>';
1539: }
1540: $datatable .= '</tr></table>';
1541: } else {
1542: $datatable .= &mt('There are no active Domain Coordinators');
1543: $rows ++;
1544: }
1545: $datatable .='</td></tr>';
1546: $$rowtotal += $rows;
1547: return $datatable;
1548: }
1549:
1.3 raeburn 1550: sub print_autoenroll {
1.30 raeburn 1551: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1552: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.17 raeburn 1553: my ($defdom,$runon,$runoff);
1.3 raeburn 1554: if (ref($settings) eq 'HASH') {
1555: if (exists($settings->{'run'})) {
1556: if ($settings->{'run'} eq '0') {
1557: $runoff = ' checked="checked" ';
1558: $runon = ' ';
1559: } else {
1560: $runon = ' checked="checked" ';
1561: $runoff = ' ';
1562: }
1563: } else {
1564: if ($autorun) {
1565: $runon = ' checked="checked" ';
1566: $runoff = ' ';
1567: } else {
1568: $runoff = ' checked="checked" ';
1569: $runon = ' ';
1570: }
1571: }
1572: if (exists($settings->{'sender_domain'})) {
1573: $defdom = $settings->{'sender_domain'};
1574: }
1.14 raeburn 1575: } else {
1576: if ($autorun) {
1577: $runon = ' checked="checked" ';
1578: $runoff = ' ';
1579: } else {
1580: $runoff = ' checked="checked" ';
1581: $runon = ' ';
1582: }
1.3 raeburn 1583: }
1584: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 1585: my $notif_sender;
1586: if (ref($settings) eq 'HASH') {
1587: $notif_sender = $settings->{'sender_uname'};
1588: }
1.3 raeburn 1589: my $datatable='<tr class="LC_odd_row">'.
1590: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 1591: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1592: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 1593: $runon.' value="1" />'.&mt('Yes').'</label> '.
1594: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 1595: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1596: '</tr><tr>'.
1597: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 1598: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1599: &mt('username').': '.
1600: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 1601: $notif_sender.'" size="10" /> '.&mt('domain').
1.8 raeburn 1602: ': '.$domform.'</span></td></tr>';
1.30 raeburn 1603: $$rowtotal += 2;
1.3 raeburn 1604: return $datatable;
1605: }
1606:
1607: sub print_autoupdate {
1.30 raeburn 1608: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 1609: my $datatable;
1610: if ($position eq 'top') {
1611: my $updateon = ' ';
1612: my $updateoff = ' checked="checked" ';
1613: my $classlistson = ' ';
1614: my $classlistsoff = ' checked="checked" ';
1615: if (ref($settings) eq 'HASH') {
1616: if ($settings->{'run'} eq '1') {
1617: $updateon = $updateoff;
1618: $updateoff = ' ';
1619: }
1620: if ($settings->{'classlists'} eq '1') {
1621: $classlistson = $classlistsoff;
1622: $classlistsoff = ' ';
1623: }
1624: }
1625: my %title = (
1626: run => 'Auto-update active?',
1627: classlists => 'Update information in classlists?',
1628: );
1629: $datatable = '<tr class="LC_odd_row">'.
1630: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 1631: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 1632: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 1633: $updateon.' value="1" />'.&mt('Yes').'</label> '.
1634: '<label><input type="radio" name="autoupdate_run"'.
1635: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1636: '</tr><tr>'.
1637: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 1638: '<td class="LC_right_item"><span class="LC_nobreak">'.
1639: '<label><input type="radio" name="classlists"'.
1640: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
1641: '<label><input type="radio" name="classlists"'.
1642: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 1643: '</tr>';
1.30 raeburn 1644: $$rowtotal += 2;
1.3 raeburn 1645: } else {
1.44 raeburn 1646: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.20 raeburn 1647: my @fields = ('lastname','firstname','middlename','gen',
1648: 'permanentemail','id');
1.33 raeburn 1649: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 1650: my $numrows = 0;
1.26 raeburn 1651: if (ref($types) eq 'ARRAY') {
1652: if (@{$types} > 0) {
1653: $datatable =
1654: &usertype_update_row($settings,$usertypes,\%fieldtitles,
1655: \@fields,$types,\$numrows);
1.30 raeburn 1656: $$rowtotal += @{$types};
1.26 raeburn 1657: }
1.3 raeburn 1658: }
1659: $datatable .=
1660: &usertype_update_row($settings,{'default' => $othertitle},
1661: \%fieldtitles,\@fields,['default'],
1662: \$numrows);
1.30 raeburn 1663: $$rowtotal ++;
1.3 raeburn 1664: }
1665: return $datatable;
1666: }
1667:
1.23 raeburn 1668: sub print_directorysrch {
1.30 raeburn 1669: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 1670: my $srchon = ' ';
1671: my $srchoff = ' checked="checked" ';
1.25 raeburn 1672: my ($exacton,$containson,$beginson);
1.24 raeburn 1673: my $localon = ' ';
1674: my $localoff = ' checked="checked" ';
1.23 raeburn 1675: if (ref($settings) eq 'HASH') {
1676: if ($settings->{'available'} eq '1') {
1677: $srchon = $srchoff;
1678: $srchoff = ' ';
1679: }
1.24 raeburn 1680: if ($settings->{'localonly'} eq '1') {
1681: $localon = $localoff;
1682: $localoff = ' ';
1683: }
1.25 raeburn 1684: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
1685: foreach my $type (@{$settings->{'searchtypes'}}) {
1686: if ($type eq 'exact') {
1687: $exacton = ' checked="checked" ';
1688: } elsif ($type eq 'contains') {
1689: $containson = ' checked="checked" ';
1690: } elsif ($type eq 'begins') {
1691: $beginson = ' checked="checked" ';
1692: }
1693: }
1694: } else {
1695: if ($settings->{'searchtypes'} eq 'exact') {
1696: $exacton = ' checked="checked" ';
1697: } elsif ($settings->{'searchtypes'} eq 'contains') {
1698: $containson = ' checked="checked" ';
1699: } elsif ($settings->{'searchtypes'} eq 'specify') {
1700: $exacton = ' checked="checked" ';
1701: $containson = ' checked="checked" ';
1702: }
1.23 raeburn 1703: }
1704: }
1705: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 1706: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 1707:
1708: my $numinrow = 4;
1.26 raeburn 1709: my $cansrchrow = 0;
1.23 raeburn 1710: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 1711: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 1712: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1713: '<input type="radio" name="dirsrch_available"'.
1714: $srchon.' value="1" />'.&mt('Yes').'</label> '.
1715: '<label><input type="radio" name="dirsrch_available"'.
1716: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
1717: '</tr><tr>'.
1.30 raeburn 1718: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 1719: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1720: '<input type="radio" name="dirsrch_localonly"'.
1721: $localoff.' value="0" />'.&mt('Yes').'</label> '.
1722: '<label><input type="radio" name="dirsrch_localonly"'.
1723: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 1724: '</tr>';
1.30 raeburn 1725: $$rowtotal += 2;
1.26 raeburn 1726: if (ref($usertypes) eq 'HASH') {
1727: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 1728: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1729: $numinrow,$othertitle,'cansearch');
1.26 raeburn 1730: $cansrchrow = 1;
1731: }
1732: }
1733: if ($cansrchrow) {
1.30 raeburn 1734: $$rowtotal ++;
1.26 raeburn 1735: $datatable .= '<tr>';
1736: } else {
1737: $datatable .= '<tr class="LC_odd_row">';
1738: }
1.30 raeburn 1739: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
1740: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 1741: foreach my $title (@{$titleorder}) {
1742: if (defined($searchtitles->{$title})) {
1743: my $check = ' ';
1.93 raeburn 1744: if (ref($settings) eq 'HASH') {
1.39 raeburn 1745: if (ref($settings->{'searchby'}) eq 'ARRAY') {
1746: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
1747: $check = ' checked="checked" ';
1748: }
1.25 raeburn 1749: }
1750: }
1751: $datatable .= '<td class="LC_left_item">'.
1752: '<span class="LC_nobreak"><label>'.
1753: '<input type="checkbox" name="searchby" '.
1754: 'value="'.$title.'"'.$check.'/>'.
1755: $searchtitles->{$title}.'</label></span></td>';
1756: }
1757: }
1.26 raeburn 1758: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 1759: $$rowtotal ++;
1.26 raeburn 1760: if ($cansrchrow) {
1761: $datatable .= '<tr class="LC_odd_row">';
1762: } else {
1763: $datatable .= '<tr>';
1764: }
1.30 raeburn 1765: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 1766: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 1767: '<span class="LC_nobreak"><label>'.
1768: '<input type="checkbox" name="searchtypes" '.
1769: $exacton.' value="exact" />'.&mt('Exact match').
1770: '</label> '.
1771: '<label><input type="checkbox" name="searchtypes" '.
1772: $beginson.' value="begins" />'.&mt('Begins with').
1773: '</label> '.
1774: '<label><input type="checkbox" name="searchtypes" '.
1775: $containson.' value="contains" />'.&mt('Contains').
1776: '</label></span></td></tr>';
1.30 raeburn 1777: $$rowtotal ++;
1.25 raeburn 1778: return $datatable;
1779: }
1780:
1.28 raeburn 1781: sub print_contacts {
1.30 raeburn 1782: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 1783: my $datatable;
1784: my @contacts = ('adminemail','supportemail');
1785: my (%checked,%to,%otheremails);
1.102 raeburn 1786: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1787: 'requestsmail');
1.28 raeburn 1788: foreach my $type (@mailings) {
1789: $otheremails{$type} = '';
1790: }
1791: if (ref($settings) eq 'HASH') {
1792: foreach my $item (@contacts) {
1793: if (exists($settings->{$item})) {
1794: $to{$item} = $settings->{$item};
1795: }
1796: }
1797: foreach my $type (@mailings) {
1798: if (exists($settings->{$type})) {
1799: if (ref($settings->{$type}) eq 'HASH') {
1800: foreach my $item (@contacts) {
1801: if ($settings->{$type}{$item}) {
1802: $checked{$type}{$item} = ' checked="checked" ';
1803: }
1804: }
1805: $otheremails{$type} = $settings->{$type}{'others'};
1806: }
1.89 raeburn 1807: } elsif ($type eq 'lonstatusmail') {
1808: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 1809: }
1810: }
1811: } else {
1812: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
1813: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
1814: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
1815: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 1816: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
1817: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 1818: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 1819: }
1820: my ($titles,$short_titles) = &contact_titles();
1821: my $rownum = 0;
1822: my $css_class;
1823: foreach my $item (@contacts) {
1.69 raeburn 1824: $rownum ++;
1825: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 1826: $datatable .= '<tr'.$css_class.'>'.
1827: '<td><span class="LC_nobreak">'.$titles->{$item}.
1828: '</span></td><td class="LC_right_item">'.
1.28 raeburn 1829: '<input type="text" name="'.$item.'" value="'.
1830: $to{$item}.'" /></td></tr>';
1831: }
1832: foreach my $type (@mailings) {
1.69 raeburn 1833: $rownum ++;
1834: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 1835: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 1836: '<td><span class="LC_nobreak">'.
1837: $titles->{$type}.': </span></td>'.
1.28 raeburn 1838: '<td class="LC_left_item">'.
1839: '<span class="LC_nobreak">';
1840: foreach my $item (@contacts) {
1841: $datatable .= '<label>'.
1842: '<input type="checkbox" name="'.$type.'"'.
1843: $checked{$type}{$item}.
1844: ' value="'.$item.'" />'.$short_titles->{$item}.
1845: '</label> ';
1846: }
1847: $datatable .= '</span><br />'.&mt('Others').': '.
1848: '<input type="text" name="'.$type.'_others" '.
1849: 'value="'.$otheremails{$type}.'" />'.
1850: '</td></tr>'."\n";
1851: }
1.30 raeburn 1852: $$rowtotal += $rownum;
1.28 raeburn 1853: return $datatable;
1854: }
1855:
1856: sub contact_titles {
1857: my %titles = &Apache::lonlocal::texthash (
1858: 'supportemail' => 'Support E-mail address',
1.69 raeburn 1859: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 1860: 'errormail' => 'Error reports to be e-mailed to',
1861: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 1862: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
1863: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 1864: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 1865: );
1866: my %short_titles = &Apache::lonlocal::texthash (
1867: adminemail => 'Admin E-mail address',
1868: supportemail => 'Support E-mail',
1869: );
1870: return (\%titles,\%short_titles);
1871: }
1872:
1.72 raeburn 1873: sub tool_titles {
1874: my %titles = &Apache::lonlocal::texthash (
1.90 weissno 1875: aboutme => 'Personal Information Page',
1.86 raeburn 1876: blog => 'Blog',
1877: portfolio => 'Portfolio',
1.88 bisitz 1878: official => 'Official courses (with institutional codes)',
1879: unofficial => 'Unofficial courses',
1.98 raeburn 1880: community => 'Communities',
1.86 raeburn 1881: );
1.72 raeburn 1882: return %titles;
1883: }
1884:
1.101 raeburn 1885: sub courserequest_titles {
1886: my %titles = &Apache::lonlocal::texthash (
1887: official => 'Official',
1888: unofficial => 'Unofficial',
1889: community => 'Communities',
1890: norequest => 'Not allowed',
1.104 raeburn 1891: approval => 'Approval by Dom. Coord.',
1.101 raeburn 1892: validate => 'With validation',
1893: autolimit => 'Numerical limit',
1.103 raeburn 1894: unlimited => '(blank for unlimited)',
1.101 raeburn 1895: );
1896: return %titles;
1897: }
1898:
1899: sub courserequest_conditions {
1900: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 1901: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 1902: validate => '(Processing of request subject to instittutional validation).',
1903: );
1904: return %conditions;
1905: }
1906:
1907:
1.27 raeburn 1908: sub print_usercreation {
1.30 raeburn 1909: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 1910: my $numinrow = 4;
1.28 raeburn 1911: my $datatable;
1912: if ($position eq 'top') {
1.30 raeburn 1913: $$rowtotal ++;
1.34 raeburn 1914: my $rowcount = 0;
1.32 raeburn 1915: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 1916: if (ref($rules) eq 'HASH') {
1917: if (keys(%{$rules}) > 0) {
1.32 raeburn 1918: $datatable .= &user_formats_row('username',$settings,$rules,
1919: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 1920: $$rowtotal ++;
1.32 raeburn 1921: $rowcount ++;
1922: }
1923: }
1924: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
1925: if (ref($idrules) eq 'HASH') {
1926: if (keys(%{$idrules}) > 0) {
1927: $datatable .= &user_formats_row('id',$settings,$idrules,
1928: $idruleorder,$numinrow,$rowcount);
1929: $$rowtotal ++;
1930: $rowcount ++;
1.28 raeburn 1931: }
1932: }
1.43 raeburn 1933: my ($emailrules,$emailruleorder) =
1934: &Apache::lonnet::inst_userrules($dom,'email');
1935: if (ref($emailrules) eq 'HASH') {
1936: if (keys(%{$emailrules}) > 0) {
1937: $datatable .= &user_formats_row('email',$settings,$emailrules,
1938: $emailruleorder,$numinrow,$rowcount);
1939: $$rowtotal ++;
1940: $rowcount ++;
1941: }
1942: }
1.39 raeburn 1943: if ($rowcount == 0) {
1944: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
1945: $$rowtotal ++;
1946: $rowcount ++;
1947: }
1.34 raeburn 1948: } elsif ($position eq 'middle') {
1.100 raeburn 1949: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 1950: my ($rules,$ruleorder) =
1951: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 1952: my %lt = &usercreation_types();
1953: my %checked;
1.50 raeburn 1954: my @selfcreate;
1.34 raeburn 1955: if (ref($settings) eq 'HASH') {
1956: if (ref($settings->{'cancreate'}) eq 'HASH') {
1957: foreach my $item (@creators) {
1958: $checked{$item} = $settings->{'cancreate'}{$item};
1959: }
1.50 raeburn 1960: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
1961: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
1962: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
1963: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
1964: @selfcreate = ('email','login','sso');
1965: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
1966: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
1967: }
1968: }
1.34 raeburn 1969: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
1970: foreach my $item (@creators) {
1971: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
1972: $checked{$item} = 'none';
1973: }
1974: }
1975: }
1976: }
1977: my $rownum = 0;
1978: foreach my $item (@creators) {
1979: $rownum ++;
1.50 raeburn 1980: if ($item ne 'selfcreate') {
1981: if ($checked{$item} eq '') {
1.43 raeburn 1982: $checked{$item} = 'any';
1983: }
1.34 raeburn 1984: }
1985: my $css_class;
1986: if ($rownum%2) {
1987: $css_class = '';
1988: } else {
1989: $css_class = ' class="LC_odd_row" ';
1990: }
1991: $datatable .= '<tr'.$css_class.'>'.
1992: '<td><span class="LC_nobreak">'.$lt{$item}.
1993: '</span></td><td align="right">';
1.50 raeburn 1994: my @options;
1.45 raeburn 1995: if ($item eq 'selfcreate') {
1.43 raeburn 1996: push(@options,('email','login','sso'));
1997: } else {
1.50 raeburn 1998: @options = ('any');
1.43 raeburn 1999: if (ref($rules) eq 'HASH') {
2000: if (keys(%{$rules}) > 0) {
2001: push(@options,('official','unofficial'));
2002: }
1.37 raeburn 2003: }
1.50 raeburn 2004: push(@options,'none');
1.37 raeburn 2005: }
2006: foreach my $option (@options) {
1.50 raeburn 2007: my $type = 'radio';
1.34 raeburn 2008: my $check = ' ';
1.50 raeburn 2009: if ($item eq 'selfcreate') {
2010: $type = 'checkbox';
2011: if (grep(/^\Q$option\E$/,@selfcreate)) {
2012: $check = ' checked="checked" ';
2013: }
2014: } else {
2015: if ($checked{$item} eq $option) {
2016: $check = ' checked="checked" ';
2017: }
1.34 raeburn 2018: }
2019: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 2020: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 2021: $item.'" value="'.$option.'"'.$check.'/> '.
2022: $lt{$option}.'</label> </span>';
2023: }
2024: $datatable .= '</td></tr>';
2025: }
1.93 raeburn 2026: my ($othertitle,$usertypes,$types) =
2027: &Apache::loncommon::sorted_inst_types($dom);
2028: if (ref($usertypes) eq 'HASH') {
2029: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 2030: my $createsettings;
2031: if (ref($settings) eq 'HASH') {
2032: $createsettings = $settings->{cancreate};
2033: }
2034: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 2035: $dom,$numinrow,$othertitle,
2036: 'statustocreate');
2037: $$rowtotal ++;
2038: }
2039: }
1.28 raeburn 2040: } else {
2041: my @contexts = ('author','course','domain');
2042: my @authtypes = ('int','krb4','krb5','loc');
2043: my %checked;
2044: if (ref($settings) eq 'HASH') {
2045: if (ref($settings->{'authtypes'}) eq 'HASH') {
2046: foreach my $item (@contexts) {
2047: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
2048: foreach my $auth (@authtypes) {
2049: if ($settings->{'authtypes'}{$item}{$auth}) {
2050: $checked{$item}{$auth} = ' checked="checked" ';
2051: }
2052: }
2053: }
2054: }
1.27 raeburn 2055: }
1.35 raeburn 2056: } else {
2057: foreach my $item (@contexts) {
1.36 raeburn 2058: foreach my $auth (@authtypes) {
1.35 raeburn 2059: $checked{$item}{$auth} = ' checked="checked" ';
2060: }
2061: }
1.27 raeburn 2062: }
1.28 raeburn 2063: my %title = &context_names();
2064: my %authname = &authtype_names();
2065: my $rownum = 0;
2066: my $css_class;
2067: foreach my $item (@contexts) {
2068: if ($rownum%2) {
2069: $css_class = '';
2070: } else {
2071: $css_class = ' class="LC_odd_row" ';
2072: }
1.30 raeburn 2073: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 2074: '<td>'.$title{$item}.
2075: '</td><td class="LC_left_item">'.
2076: '<span class="LC_nobreak">';
2077: foreach my $auth (@authtypes) {
2078: $datatable .= '<label>'.
2079: '<input type="checkbox" name="'.$item.'_auth" '.
2080: $checked{$item}{$auth}.' value="'.$auth.'" />'.
2081: $authname{$auth}.'</label> ';
2082: }
2083: $datatable .= '</span></td></tr>';
2084: $rownum ++;
1.27 raeburn 2085: }
1.30 raeburn 2086: $$rowtotal += $rownum;
1.27 raeburn 2087: }
2088: return $datatable;
2089: }
2090:
1.32 raeburn 2091: sub user_formats_row {
2092: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
2093: my $output;
2094: my %text = (
2095: 'username' => 'new usernames',
2096: 'id' => 'IDs',
1.45 raeburn 2097: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 2098: );
2099: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
2100: $output = '<tr '.$css_class.'>'.
1.63 raeburn 2101: '<td><span class="LC_nobreak">';
2102: if ($type eq 'email') {
2103: $output .= &mt("Formats disallowed for $text{$type}: ");
2104: } else {
2105: $output .= &mt("Format rules to check for $text{$type}: ");
2106: }
2107: $output .= '</span></td>'.
2108: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 2109: my $rem;
2110: if (ref($ruleorder) eq 'ARRAY') {
2111: for (my $i=0; $i<@{$ruleorder}; $i++) {
2112: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
2113: my $rem = $i%($numinrow);
2114: if ($rem == 0) {
2115: if ($i > 0) {
2116: $output .= '</tr>';
2117: }
2118: $output .= '<tr>';
2119: }
2120: my $check = ' ';
1.39 raeburn 2121: if (ref($settings) eq 'HASH') {
2122: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
2123: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
2124: $check = ' checked="checked" ';
2125: }
1.27 raeburn 2126: }
2127: }
2128: $output .= '<td class="LC_left_item">'.
2129: '<span class="LC_nobreak"><label>'.
1.32 raeburn 2130: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 2131: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
2132: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
2133: }
2134: }
2135: $rem = @{$ruleorder}%($numinrow);
2136: }
2137: my $colsleft = $numinrow - $rem;
2138: if ($colsleft > 1 ) {
2139: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2140: ' </td>';
2141: } elsif ($colsleft == 1) {
2142: $output .= '<td class="LC_left_item"> </td>';
2143: }
2144: $output .= '</tr></table></td></tr>';
2145: return $output;
2146: }
2147:
1.34 raeburn 2148: sub usercreation_types {
2149: my %lt = &Apache::lonlocal::texthash (
2150: author => 'When adding a co-author',
2151: course => 'When adding a user to a course',
1.100 raeburn 2152: requestcrs => 'When requesting a course',
1.45 raeburn 2153: selfcreate => 'User creates own account',
1.34 raeburn 2154: any => 'Any',
2155: official => 'Institutional only ',
2156: unofficial => 'Non-institutional only',
1.85 schafran 2157: email => 'E-mail address',
1.43 raeburn 2158: login => 'Institutional Login',
2159: sso => 'SSO',
1.34 raeburn 2160: none => 'None',
2161: );
2162: return %lt;
1.48 raeburn 2163: }
1.34 raeburn 2164:
1.28 raeburn 2165: sub authtype_names {
2166: my %lt = &Apache::lonlocal::texthash(
2167: int => 'Internal',
2168: krb4 => 'Kerberos 4',
2169: krb5 => 'Kerberos 5',
2170: loc => 'Local',
2171: );
2172: return %lt;
2173: }
2174:
2175: sub context_names {
2176: my %context_title = &Apache::lonlocal::texthash(
2177: author => 'Creating users when an Author',
2178: course => 'Creating users when in a course',
2179: domain => 'Creating users when a Domain Coordinator',
2180: );
2181: return %context_title;
2182: }
2183:
1.33 raeburn 2184: sub print_usermodification {
2185: my ($position,$dom,$settings,$rowtotal) = @_;
2186: my $numinrow = 4;
2187: my ($context,$datatable,$rowcount);
2188: if ($position eq 'top') {
2189: $rowcount = 0;
2190: $context = 'author';
2191: foreach my $role ('ca','aa') {
2192: $datatable .= &modifiable_userdata_row($context,$role,$settings,
2193: $numinrow,$rowcount);
2194: $$rowtotal ++;
2195: $rowcount ++;
2196: }
1.63 raeburn 2197: } elsif ($position eq 'middle') {
1.33 raeburn 2198: $context = 'course';
2199: $rowcount = 0;
2200: foreach my $role ('st','ep','ta','in','cr') {
2201: $datatable .= &modifiable_userdata_row($context,$role,$settings,
2202: $numinrow,$rowcount);
2203: $$rowtotal ++;
2204: $rowcount ++;
2205: }
1.63 raeburn 2206: } elsif ($position eq 'bottom') {
2207: $context = 'selfcreate';
2208: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2209: $usertypes->{'default'} = $othertitle;
2210: if (ref($types) eq 'ARRAY') {
2211: push(@{$types},'default');
2212: $usertypes->{'default'} = $othertitle;
2213: foreach my $status (@{$types}) {
2214: $datatable .= &modifiable_userdata_row($context,$status,$settings,
2215: $numinrow,$rowcount,$usertypes);
2216: $$rowtotal ++;
2217: $rowcount ++;
2218: }
2219: }
1.33 raeburn 2220: }
2221: return $datatable;
2222: }
2223:
1.43 raeburn 2224: sub print_defaults {
2225: my ($dom,$rowtotal) = @_;
1.68 raeburn 2226: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
2227: 'datelocale_def');
1.43 raeburn 2228: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
2229: my $titles = &defaults_titles();
2230: my $rownum = 0;
2231: my ($datatable,$css_class);
2232: foreach my $item (@items) {
2233: if ($rownum%2) {
2234: $css_class = '';
2235: } else {
2236: $css_class = ' class="LC_odd_row" ';
2237: }
2238: $datatable .= '<tr'.$css_class.'>'.
2239: '<td><span class="LC_nobreak">'.$titles->{$item}.
2240: '</span></td><td class="LC_right_item">';
2241: if ($item eq 'auth_def') {
2242: my @authtypes = ('internal','krb4','krb5','localauth');
2243: my %shortauth = (
2244: internal => 'int',
2245: krb4 => 'krb4',
2246: krb5 => 'krb5',
2247: localauth => 'loc'
2248: );
2249: my %authnames = &authtype_names();
2250: foreach my $auth (@authtypes) {
2251: my $checked = ' ';
2252: if ($domdefaults{$item} eq $auth) {
2253: $checked = ' checked="checked" ';
2254: }
2255: $datatable .= '<label><input type="radio" name="'.$item.
2256: '" value="'.$auth.'"'.$checked.'/>'.
2257: $authnames{$shortauth{$auth}}.'</label> ';
2258: }
1.54 raeburn 2259: } elsif ($item eq 'timezone_def') {
2260: my $includeempty = 1;
2261: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 2262: } elsif ($item eq 'datelocale_def') {
2263: my $includeempty = 1;
2264: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.43 raeburn 2265: } else {
2266: $datatable .= '<input type="text" name="'.$item.'" value="'.
2267: $domdefaults{$item}.'" />';
2268: }
2269: $datatable .= '</td></tr>';
2270: $rownum ++;
2271: }
2272: $$rowtotal += $rownum;
2273: return $datatable;
2274: }
2275:
2276: sub defaults_titles {
2277: my %titles = &Apache::lonlocal::texthash (
2278: 'auth_def' => 'Default authentication type',
2279: 'auth_arg_def' => 'Default authentication argument',
2280: 'lang_def' => 'Default language',
1.54 raeburn 2281: 'timezone_def' => 'Default timezone',
1.68 raeburn 2282: 'datelocale_def' => 'Default locale for dates',
1.43 raeburn 2283: );
2284: return (\%titles);
2285: }
2286:
1.46 raeburn 2287: sub print_scantronformat {
2288: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
2289: my $itemcount = 1;
1.60 raeburn 2290: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
2291: %confhash);
1.46 raeburn 2292: my $switchserver = &check_switchserver($dom,$confname);
2293: my %lt = &Apache::lonlocal::texthash (
1.95 www 2294: default => 'Default bubblesheet format file error',
2295: custom => 'Custom bubblesheet format file error',
1.46 raeburn 2296: );
2297: my %scantronfiles = (
2298: default => 'default.tab',
2299: custom => 'custom.tab',
2300: );
2301: foreach my $key (keys(%scantronfiles)) {
2302: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
2303: .$scantronfiles{$key};
2304: }
2305: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
2306: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
2307: if (!$switchserver) {
2308: my $servadm = $r->dir_config('lonAdmEMail');
2309: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
2310: if ($configuserok eq 'ok') {
2311: if ($author_ok eq 'ok') {
2312: my %legacyfile = (
2313: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
2314: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
2315: );
2316: my %md5chk;
2317: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2318: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
2319: chomp($md5chk{$type});
1.46 raeburn 2320: }
2321: if ($md5chk{'default'} ne $md5chk{'custom'}) {
2322: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 2323: ($scantronurls{$type},my $error) =
1.46 raeburn 2324: &legacy_scantronformat($r,$dom,$confname,
2325: $type,$legacyfile{$type},
2326: $scantronurls{$type},
2327: $scantronfiles{$type});
1.60 raeburn 2328: if ($error ne '') {
2329: $error{$type} = $error;
2330: }
2331: }
2332: if (keys(%error) == 0) {
2333: $is_custom = 1;
2334: $confhash{'scantron'}{'scantronformat'} =
2335: $scantronurls{'custom'};
2336: my $putresult =
2337: &Apache::lonnet::put_dom('configuration',
2338: \%confhash,$dom);
2339: if ($putresult ne 'ok') {
2340: $error{'custom'} =
2341: '<span class="LC_error">'.
2342: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2343: }
1.46 raeburn 2344: }
2345: } else {
1.60 raeburn 2346: ($scantronurls{'default'},my $error) =
1.46 raeburn 2347: &legacy_scantronformat($r,$dom,$confname,
2348: 'default',$legacyfile{'default'},
2349: $scantronurls{'default'},
2350: $scantronfiles{'default'});
1.60 raeburn 2351: if ($error eq '') {
2352: $confhash{'scantron'}{'scantronformat'} = '';
2353: my $putresult =
2354: &Apache::lonnet::put_dom('configuration',
2355: \%confhash,$dom);
2356: if ($putresult ne 'ok') {
2357: $error{'default'} =
2358: '<span class="LC_error">'.
2359: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
2360: }
2361: } else {
2362: $error{'default'} = $error;
2363: }
1.46 raeburn 2364: }
2365: }
2366: }
2367: } else {
1.95 www 2368: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 2369: }
2370: }
2371: if (ref($settings) eq 'HASH') {
2372: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
2373: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
2374: if ((!@info) || ($info[0] eq 'no_such_dir')) {
2375: $scantronurl = '';
2376: } else {
2377: $scantronurl = $settings->{'scantronformat'};
2378: }
2379: $is_custom = 1;
2380: } else {
2381: $scantronurl = $scantronurls{'default'};
2382: }
2383: } else {
1.60 raeburn 2384: if ($is_custom) {
2385: $scantronurl = $scantronurls{'custom'};
2386: } else {
2387: $scantronurl = $scantronurls{'default'};
2388: }
1.46 raeburn 2389: }
2390: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2391: $datatable .= '<tr'.$css_class.'>';
2392: if (!$is_custom) {
1.65 raeburn 2393: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
2394: '<span class="LC_nobreak">';
1.46 raeburn 2395: if ($scantronurl) {
2396: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
2397: &mt('Default scantron format file').'</a>';
2398: } else {
2399: $datatable = &mt('File unavailable for display');
2400: }
1.65 raeburn 2401: $datatable .= '</span></td>';
1.60 raeburn 2402: if (keys(%error) == 0) {
2403: $datatable .= '<td valign="bottom">';
2404: if (!$switchserver) {
2405: $datatable .= &mt('Upload:').'<br />';
2406: }
2407: } else {
2408: my $errorstr;
2409: foreach my $key (sort(keys(%error))) {
2410: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
2411: }
2412: $datatable .= '<td>'.$errorstr;
2413: }
1.46 raeburn 2414: } else {
2415: if (keys(%error) > 0) {
2416: my $errorstr;
2417: foreach my $key (sort(keys(%error))) {
2418: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
2419: }
1.60 raeburn 2420: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 2421: } elsif ($scantronurl) {
1.65 raeburn 2422: $datatable .= '<td><span class="LC_nobreak">'.
2423: '<a href="'.$scantronurl.'" target="_blank">'.
2424: &mt('Custom scantron format file').'</a><label>'.
2425: '<input type="checkbox" name="scantronformat_del"'.
2426: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
2427: '<td><span class="LC_nobreak"> '.
2428: &mt('Replace:').'</span><br />';
1.46 raeburn 2429: }
2430: }
2431: if (keys(%error) == 0) {
2432: if ($switchserver) {
2433: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2434: } else {
1.65 raeburn 2435: $datatable .='<span class="LC_nobreak"> '.
2436: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 2437: }
2438: }
2439: $datatable .= '</td></tr>';
2440: $$rowtotal ++;
2441: return $datatable;
2442: }
2443:
2444: sub legacy_scantronformat {
2445: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
2446: my ($url,$error);
2447: my @statinfo = &Apache::lonnet::stat_file($newurl);
2448: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
2449: (my $result,$url) =
2450: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
2451: '','',$newfile);
2452: if ($result ne 'ok') {
2453: $error = &mt("An error occurred publishing the [_1] scantron format file in RES space. Error was: [_2].",$newfile,$result);
2454: }
2455: }
2456: return ($url,$error);
2457: }
1.43 raeburn 2458:
1.49 raeburn 2459: sub print_coursecategories {
1.57 raeburn 2460: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
2461: my $datatable;
2462: if ($position eq 'top') {
2463: my $toggle_cats_crs = ' ';
2464: my $toggle_cats_dom = ' checked="checked" ';
2465: my $can_cat_crs = ' ';
2466: my $can_cat_dom = ' checked="checked" ';
2467: if (ref($settings) eq 'HASH') {
2468: if ($settings->{'togglecats'} eq 'crs') {
2469: $toggle_cats_crs = $toggle_cats_dom;
2470: $toggle_cats_dom = ' ';
2471: }
2472: if ($settings->{'categorize'} eq 'crs') {
2473: $can_cat_crs = $can_cat_dom;
2474: $can_cat_dom = ' ';
2475: }
2476: }
2477: my %title = &Apache::lonlocal::texthash (
2478: togglecats => 'Show/Hide a course in the catalog',
2479: categorize => 'Assign a category to a course',
2480: );
2481: my %level = &Apache::lonlocal::texthash (
2482: dom => 'Set in "Modify Course" (Domain)',
1.60 raeburn 2483: crs => 'Set in "Modify Parameters" (Course)',
1.57 raeburn 2484: );
2485: $datatable = '<tr class="LC_odd_row">'.
2486: '<td>'.$title{'togglecats'}.'</td>'.
2487: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2488: '<input type="radio" name="togglecats"'.
2489: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2490: '<label><input type="radio" name="togglecats"'.
2491: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
2492: '</tr><tr>'.
2493: '<td>'.$title{'categorize'}.'</td>'.
2494: '<td class="LC_right_item"><span class="LC_nobreak">'.
2495: '<label><input type="radio" name="categorize"'.
2496: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
2497: '<label><input type="radio" name="categorize"'.
2498: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
2499: '</tr>';
2500: $$rowtotal += 2;
2501: } else {
2502: my $css_class;
2503: my $itemcount = 1;
2504: my $cathash;
2505: if (ref($settings) eq 'HASH') {
2506: $cathash = $settings->{'cats'};
2507: }
2508: if (ref($cathash) eq 'HASH') {
2509: my (@cats,@trails,%allitems,%idx,@jsarray);
2510: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
2511: \%allitems,\%idx,\@jsarray);
2512: my $maxdepth = scalar(@cats);
2513: my $colattrib = '';
2514: if ($maxdepth > 2) {
2515: $colattrib = ' colspan="2" ';
2516: }
2517: my @path;
2518: if (@cats > 0) {
2519: if (ref($cats[0]) eq 'ARRAY') {
2520: my $numtop = @{$cats[0]};
2521: my $maxnum = $numtop;
2522: if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
2523: $maxnum ++;
2524: }
2525: my $lastidx;
2526: for (my $i=0; $i<$numtop; $i++) {
2527: my $parent = $cats[0][$i];
2528: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2529: my $item = &escape($parent).'::0';
2530: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
2531: $lastidx = $idx{$item};
2532: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
2533: .'<select name="'.$item.'"'.$chgstr.'>';
2534: for (my $k=0; $k<=$maxnum; $k++) {
2535: my $vpos = $k+1;
2536: my $selstr;
2537: if ($k == $i) {
2538: $selstr = ' selected="selected" ';
2539: }
2540: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2541: }
2542: $datatable .= '</select></td><td>';
2543: if ($parent eq 'instcode') {
2544: $datatable .= '<span class="LC_nobreak">'.&mt('Official courses')
2545: .'</span><br /><span class="LC_nobreak">('
2546: .&mt('with institutional codes').')</span></td>'
2547: .'<td'.$colattrib.'><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" checked="checked" />'
2548: .&mt('Display').'</label> '
2549: .'<label><input type="radio" name="instcode" value="0" />'
2550: .&mt('Do not display').'</label></span></td>';
2551: } else {
2552: $datatable .= $parent
2553: .' <label><input type="checkbox" name="deletecategory" '
2554: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
2555: }
2556: my $depth = 1;
2557: push(@path,$parent);
2558: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
2559: pop(@path);
2560: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
2561: $itemcount ++;
2562: }
1.48 raeburn 2563: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 2564: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
2565: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 2566: for (my $k=0; $k<=$maxnum; $k++) {
2567: my $vpos = $k+1;
2568: my $selstr;
1.57 raeburn 2569: if ($k == $numtop) {
1.48 raeburn 2570: $selstr = ' selected="selected" ';
2571: }
2572: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2573: }
1.59 bisitz 2574: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 2575: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
2576: .'</tr>'."\n";
1.48 raeburn 2577: $itemcount ++;
1.57 raeburn 2578: if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
2579: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2580: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"';
2581: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
2582: '<span class="LC_nobreak"><select name="instcode_pos"'.$chgstr.'>';
2583: for (my $k=0; $k<=$maxnum; $k++) {
2584: my $vpos = $k+1;
2585: my $selstr;
2586: if ($k == $maxnum) {
2587: $selstr = ' selected="selected" ';
2588: }
2589: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.48 raeburn 2590: }
1.57 raeburn 2591: $datatable .= '</select></span></td><td><span class="LC_nobreak">'
2592: .&mt('Official courses').'</span>'.'<br /><span class="LC_nobreak">('
2593: .&mt('with institutional codes').')</span></td>'
2594: .'<td><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" />'
2595: .&mt('Display').'</label> '
2596: .'<label><input type="radio" name="instcode" value="0" checked="checked"/>'
2597: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 2598: }
2599: }
1.57 raeburn 2600: } else {
2601: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 2602: }
2603: } else {
1.57 raeburn 2604: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
2605: .&initialize_categories($itemcount);
1.48 raeburn 2606: }
1.57 raeburn 2607: $$rowtotal += $itemcount;
1.48 raeburn 2608: }
2609: return $datatable;
2610: }
2611:
1.69 raeburn 2612: sub print_serverstatuses {
2613: my ($dom,$settings,$rowtotal) = @_;
2614: my $datatable;
2615: my @pages = &serverstatus_pages();
2616: my (%namedaccess,%machineaccess);
2617: foreach my $type (@pages) {
2618: $namedaccess{$type} = '';
2619: $machineaccess{$type}= '';
2620: }
2621: if (ref($settings) eq 'HASH') {
2622: foreach my $type (@pages) {
2623: if (exists($settings->{$type})) {
2624: if (ref($settings->{$type}) eq 'HASH') {
2625: foreach my $key (keys(%{$settings->{$type}})) {
2626: if ($key eq 'namedusers') {
2627: $namedaccess{$type} = $settings->{$type}->{$key};
2628: } elsif ($key eq 'machines') {
2629: $machineaccess{$type} = $settings->{$type}->{$key};
2630: }
2631: }
2632: }
2633: }
2634: }
2635: }
1.81 raeburn 2636: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 2637: my $rownum = 0;
2638: my $css_class;
2639: foreach my $type (@pages) {
2640: $rownum ++;
2641: $css_class = $rownum%2?' class="LC_odd_row"':'';
2642: $datatable .= '<tr'.$css_class.'>'.
2643: '<td><span class="LC_nobreak">'.
2644: $titles->{$type}.'</span></td>'.
2645: '<td class="LC_left_item">'.
2646: '<input type="text" name="'.$type.'_namedusers" '.
2647: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
2648: '<td class="LC_right_item">'.
2649: '<span class="LC_nobreak">'.
2650: '<input type="text" name="'.$type.'_machines" '.
2651: 'value="'.$machineaccess{$type}.'" size="10" />'.
2652: '</td></tr>'."\n";
2653: }
2654: $$rowtotal += $rownum;
2655: return $datatable;
2656: }
2657:
2658: sub serverstatus_pages {
2659: return ('userstatus','lonstatus','loncron','server-status','codeversions',
2660: 'clusterstatus','metadata_keywords','metadata_harvest',
2661: 'takeoffline','takeonline','showenv');
2662: }
2663:
1.49 raeburn 2664: sub coursecategories_javascript {
2665: my ($settings) = @_;
1.57 raeburn 2666: my ($output,$jstext,$cathash);
1.49 raeburn 2667: if (ref($settings) eq 'HASH') {
1.57 raeburn 2668: $cathash = $settings->{'cats'};
2669: }
2670: if (ref($cathash) eq 'HASH') {
1.49 raeburn 2671: my (@cats,@jsarray,%idx);
1.57 raeburn 2672: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 2673: if (@jsarray > 0) {
2674: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
2675: for (my $i=0; $i<@jsarray; $i++) {
2676: if (ref($jsarray[$i]) eq 'ARRAY') {
2677: my $catstr = join('","',@{$jsarray[$i]});
2678: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
2679: }
2680: }
2681: }
2682: } else {
2683: $jstext = ' var categories = Array(1);'."\n".
2684: ' categories[0] = Array("instcode_pos");'."\n";
2685: }
2686: $output = <<"ENDSCRIPT";
2687: <script type="text/javascript">
1.109 ! raeburn 2688: // <![CDATA[
1.49 raeburn 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: }
1.109 ! raeburn 2745: // ]]>
1.49 raeburn 2746: </script>
2747:
2748: ENDSCRIPT
2749: return $output;
2750: }
2751:
1.48 raeburn 2752: sub initialize_categories {
2753: my ($itemcount) = @_;
2754: my $datatable;
2755: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2756: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','0'".');"';
2757:
1.48 raeburn 2758: $datatable = '<tr '.$css_class.'><td><span class="LC_nobreak">'
2759: .'<select name="instcode_pos"><option value="0" selected="selected">1</option>'
2760: .'<option value="1">2</option></select> '
2761: .&mt('Official courses (with institutional codes)')
2762: .'</span></td><td><span class="LC_nobreak">'
2763: .'<label><input type="radio" name="instcode" value="1" checked="checked" />'
2764: .&mt('Display').'</label> <label>'
2765: .'<input type="radio" name="instcode" value="0" />'.&mt('Do not display')
2766: .'</label></span></td></tr>';
2767: $itemcount ++;
2768: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 2769: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 2770: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.53 raeburn 2771: .'<select name="addcategory_pos"'.$chgstr.'><option value="0">1</option>'
1.48 raeburn 2772: .'<option value="1" selected="selected">2</option></select> '
2773: .&mt('Add category').'</td><td>'.&mt('Name:')
2774: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
2775: return $datatable;
2776: }
2777:
2778: sub build_category_rows {
1.49 raeburn 2779: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
2780: my ($text,$name,$item,$chgstr);
1.48 raeburn 2781: if (ref($cats) eq 'ARRAY') {
2782: my $maxdepth = scalar(@{$cats});
2783: if (ref($cats->[$depth]) eq 'HASH') {
2784: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
2785: my $numchildren = @{$cats->[$depth]{$parent}};
2786: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
2787: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 2788: my ($idxnum,$parent_name,$parent_item);
2789: my $higher = $depth - 1;
2790: if ($higher == 0) {
2791: $parent_name = &escape($parent).'::'.$higher;
2792: } else {
2793: if (ref($path) eq 'ARRAY') {
2794: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2795: }
2796: }
2797: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 2798: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 2799: if ($j < $numchildren) {
1.48 raeburn 2800: $name = $cats->[$depth]{$parent}[$j];
2801: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 2802: $idxnum = $idx->{$item};
2803: } else {
2804: $name = $parent_name;
2805: $item = $parent_item;
1.48 raeburn 2806: }
1.49 raeburn 2807: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
2808: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 2809: for (my $i=0; $i<=$numchildren; $i++) {
2810: my $vpos = $i+1;
2811: my $selstr;
2812: if ($j == $i) {
2813: $selstr = ' selected="selected" ';
2814: }
2815: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
2816: }
2817: $text .= '</select> ';
2818: if ($j < $numchildren) {
2819: my $deeper = $depth+1;
2820: $text .= $name.' '
2821: .'<label><input type="checkbox" name="deletecategory" value="'
2822: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
2823: if(ref($path) eq 'ARRAY') {
2824: push(@{$path},$name);
1.49 raeburn 2825: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 2826: pop(@{$path});
2827: }
2828: } else {
1.59 bisitz 2829: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 2830: if ($j == $numchildren) {
2831: $text .= $name;
2832: } else {
2833: $text .= $item;
2834: }
2835: $text .= '" value="" />';
2836: }
2837: $text .= '</td></tr>';
2838: }
2839: $text .= '</table></td>';
2840: } else {
2841: my $higher = $depth-1;
2842: if ($higher == 0) {
2843: $name = &escape($parent).'::'.$higher;
2844: } else {
2845: if (ref($path) eq 'ARRAY') {
2846: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
2847: }
2848: }
2849: my $colspan;
2850: if ($parent ne 'instcode') {
2851: $colspan = $maxdepth - $depth - 1;
2852: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
2853: }
2854: }
2855: }
2856: }
2857: return $text;
2858: }
2859:
1.33 raeburn 2860: sub modifiable_userdata_row {
1.63 raeburn 2861: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 2862: my $rolename;
1.63 raeburn 2863: if ($context eq 'selfcreate') {
2864: if (ref($usertypes) eq 'HASH') {
2865: $rolename = $usertypes->{$role};
2866: } else {
2867: $rolename = $role;
2868: }
1.33 raeburn 2869: } else {
1.63 raeburn 2870: if ($role eq 'cr') {
2871: $rolename = &mt('Custom role');
2872: } else {
2873: $rolename = &Apache::lonnet::plaintext($role);
2874: }
1.33 raeburn 2875: }
2876: my @fields = ('lastname','firstname','middlename','generation',
2877: 'permanentemail','id');
2878: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
2879: my $output;
2880: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
2881: $output = '<tr '.$css_class.'>'.
2882: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
2883: '<td class="LC_left_item" colspan="2"><table>';
2884: my $rem;
2885: my %checks;
2886: if (ref($settings) eq 'HASH') {
2887: if (ref($settings->{$context}) eq 'HASH') {
2888: if (ref($settings->{$context}->{$role}) eq 'HASH') {
2889: foreach my $field (@fields) {
2890: if ($settings->{$context}->{$role}->{$field}) {
2891: $checks{$field} = ' checked="checked" ';
2892: }
2893: }
2894: }
2895: }
2896: }
2897: for (my $i=0; $i<@fields; $i++) {
2898: my $rem = $i%($numinrow);
2899: if ($rem == 0) {
2900: if ($i > 0) {
2901: $output .= '</tr>';
2902: }
2903: $output .= '<tr>';
2904: }
2905: my $check = ' ';
2906: if (exists($checks{$fields[$i]})) {
2907: $check = $checks{$fields[$i]}
2908: } else {
2909: if ($role eq 'st') {
2910: if (ref($settings) ne 'HASH') {
2911: $check = ' checked="checked" ';
2912: }
2913: }
2914: }
2915: $output .= '<td class="LC_left_item">'.
2916: '<span class="LC_nobreak"><label>'.
2917: '<input type="checkbox" name="canmodify_'.$role.'" '.
2918: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
2919: '</label></span></td>';
2920: $rem = @fields%($numinrow);
2921: }
2922: my $colsleft = $numinrow - $rem;
2923: if ($colsleft > 1 ) {
2924: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2925: ' </td>';
2926: } elsif ($colsleft == 1) {
2927: $output .= '<td class="LC_left_item"> </td>';
2928: }
2929: $output .= '</tr></table></td></tr>';
2930: return $output;
2931: }
1.28 raeburn 2932:
1.93 raeburn 2933: sub insttypes_row {
2934: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
2935: my %lt = &Apache::lonlocal::texthash (
2936: cansearch => 'Users allowed to search',
2937: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
2938: );
2939: my $showdom;
2940: if ($context eq 'cansearch') {
2941: $showdom = ' ('.$dom.')';
2942: }
1.25 raeburn 2943: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 2944: '<td>'.$lt{$context}.$showdom.
1.24 raeburn 2945: '</td><td class="LC_left_item" colspan="2"><table>';
1.26 raeburn 2946: my $rem;
2947: if (ref($types) eq 'ARRAY') {
2948: for (my $i=0; $i<@{$types}; $i++) {
2949: if (defined($usertypes->{$types->[$i]})) {
2950: my $rem = $i%($numinrow);
2951: if ($rem == 0) {
2952: if ($i > 0) {
2953: $output .= '</tr>';
2954: }
2955: $output .= '<tr>';
1.23 raeburn 2956: }
1.26 raeburn 2957: my $check = ' ';
1.99 raeburn 2958: if (ref($settings) eq 'HASH') {
2959: if (ref($settings->{$context}) eq 'ARRAY') {
2960: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
2961: $check = ' checked="checked" ';
2962: }
2963: } elsif ($context eq 'statustocreate') {
1.26 raeburn 2964: $check = ' checked="checked" ';
2965: }
1.23 raeburn 2966: }
1.26 raeburn 2967: $output .= '<td class="LC_left_item">'.
2968: '<span class="LC_nobreak"><label>'.
1.93 raeburn 2969: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 2970: 'value="'.$types->[$i].'"'.$check.'/>'.
2971: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 2972: }
2973: }
1.26 raeburn 2974:
2975: $rem = @{$types}%($numinrow);
1.23 raeburn 2976: }
2977: my $colsleft = $numinrow - $rem;
2978: if ($colsleft > 1) {
1.25 raeburn 2979: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 2980: } else {
1.25 raeburn 2981: $output .= '<td class="LC_left_item">';
1.23 raeburn 2982: }
2983: my $defcheck = ' ';
1.99 raeburn 2984: if (ref($settings) eq 'HASH') {
2985: if (ref($settings->{$context}) eq 'ARRAY') {
2986: if (grep(/^default$/,@{$settings->{$context}})) {
2987: $defcheck = ' checked="checked" ';
2988: }
2989: } elsif ($context eq 'statustocreate') {
1.26 raeburn 2990: $defcheck = ' checked="checked" ';
2991: }
1.23 raeburn 2992: }
1.25 raeburn 2993: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 2994: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 2995: 'value="default"'.$defcheck.'/>'.
2996: $othertitle.'</label></span></td>'.
2997: '</tr></table></td></tr>';
2998: return $output;
1.23 raeburn 2999: }
3000:
3001: sub sorted_searchtitles {
3002: my %searchtitles = &Apache::lonlocal::texthash(
3003: 'uname' => 'username',
3004: 'lastname' => 'last name',
3005: 'lastfirst' => 'last name, first name',
3006: );
3007: my @titleorder = ('uname','lastname','lastfirst');
3008: return (\%searchtitles,\@titleorder);
3009: }
3010:
1.25 raeburn 3011: sub sorted_searchtypes {
3012: my %srchtypes_desc = (
3013: exact => 'is exact match',
3014: contains => 'contains ..',
3015: begins => 'begins with ..',
3016: );
3017: my @srchtypeorder = ('exact','begins','contains');
3018: return (\%srchtypes_desc,\@srchtypeorder);
3019: }
3020:
1.3 raeburn 3021: sub usertype_update_row {
3022: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
3023: my $datatable;
3024: my $numinrow = 4;
3025: foreach my $type (@{$types}) {
3026: if (defined($usertypes->{$type})) {
3027: $$rownums ++;
3028: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
3029: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
3030: '</td><td class="LC_left_item"><table>';
3031: for (my $i=0; $i<@{$fields}; $i++) {
3032: my $rem = $i%($numinrow);
3033: if ($rem == 0) {
3034: if ($i > 0) {
3035: $datatable .= '</tr>';
3036: }
3037: $datatable .= '<tr>';
3038: }
3039: my $check = ' ';
1.39 raeburn 3040: if (ref($settings) eq 'HASH') {
3041: if (ref($settings->{'fields'}) eq 'HASH') {
3042: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
3043: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
3044: $check = ' checked="checked" ';
3045: }
1.3 raeburn 3046: }
3047: }
3048: }
3049:
3050: if ($i == @{$fields}-1) {
3051: my $colsleft = $numinrow - $rem;
3052: if ($colsleft > 1) {
3053: $datatable .= '<td colspan="'.$colsleft.'">';
3054: } else {
3055: $datatable .= '<td>';
3056: }
3057: } else {
3058: $datatable .= '<td>';
3059: }
1.8 raeburn 3060: $datatable .= '<span class="LC_nobreak"><label>'.
3061: '<input type="checkbox" name="updateable_'.$type.
3062: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
3063: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 3064: }
3065: $datatable .= '</tr></table></td></tr>';
3066: }
3067: }
3068: return $datatable;
1.1 raeburn 3069: }
3070:
3071: sub modify_login {
1.9 raeburn 3072: my ($r,$dom,$confname,%domconfig) = @_;
1.6 raeburn 3073: my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1 raeburn 3074: my %title = ( coursecatalog => 'Display course catalog',
1.41 raeburn 3075: adminmail => 'Display administrator E-mail address',
1.43 raeburn 3076: newuser => 'Link for visitors to create a user account',
1.41 raeburn 3077: loginheader => 'Log-in box header');
1.3 raeburn 3078: my @offon = ('off','on');
1.6 raeburn 3079: my %loginhash;
1.9 raeburn 3080: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
3081: \%domconfig,\%loginhash);
1.43 raeburn 3082: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 3083: foreach my $item (@toggles) {
3084: $loginhash{login}{$item} = $env{'form.'.$item};
3085: }
1.41 raeburn 3086: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 3087: if (ref($colchanges{'login'}) eq 'HASH') {
3088: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
3089: \%loginhash);
3090: }
1.1 raeburn 3091: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
3092: $dom);
3093: if ($putresult eq 'ok') {
1.43 raeburn 3094: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 3095: my %defaultchecked = (
3096: 'coursecatalog' => 'on',
3097: 'adminmail' => 'off',
1.43 raeburn 3098: 'newuser' => 'off',
1.42 raeburn 3099: );
1.55 raeburn 3100: if (ref($domconfig{'login'}) eq 'HASH') {
3101: foreach my $item (@toggles) {
3102: if ($defaultchecked{$item} eq 'on') {
3103: if (($domconfig{'login'}{$item} eq '0') &&
3104: ($env{'form.'.$item} eq '1')) {
3105: $changes{$item} = 1;
3106: } elsif (($domconfig{'login'}{$item} eq '' ||
3107: $domconfig{'login'}{$item} eq '1') &&
3108: ($env{'form.'.$item} eq '0')) {
3109: $changes{$item} = 1;
3110: }
3111: } elsif ($defaultchecked{$item} eq 'off') {
3112: if (($domconfig{'login'}{$item} eq '1') &&
3113: ($env{'form.'.$item} eq '0')) {
3114: $changes{$item} = 1;
3115: } elsif (($domconfig{'login'}{$item} eq '' ||
3116: $domconfig{'login'}{$item} eq '0') &&
3117: ($env{'form.'.$item} eq '1')) {
3118: $changes{$item} = 1;
3119: }
1.42 raeburn 3120: }
3121: }
1.55 raeburn 3122: if (($domconfig{'login'}{'loginheader'} eq 'text') &&
3123: ($env{'form.loginheader'} eq 'image')) {
3124: $changes{'loginheader'} = 1;
3125: } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
3126: $domconfig{'login'}{'loginheader'} eq 'image') &&
3127: ($env{'form.loginheader'} eq 'text')) {
3128: $changes{'loginheader'} = 1;
3129: }
1.41 raeburn 3130: }
1.6 raeburn 3131: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 3132: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 3133: $resulttext = &mt('Changes made:').'<ul>';
3134: foreach my $item (sort(keys(%changes))) {
1.41 raeburn 3135: if ($item eq 'loginheader') {
3136: $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
3137: } else {
3138: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
3139: }
1.1 raeburn 3140: }
1.6 raeburn 3141: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 3142: } else {
3143: $resulttext = &mt('No changes made to log-in page settings');
3144: }
3145: } else {
1.11 albertel 3146: $resulttext = '<span class="LC_error">'.
3147: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 3148: }
1.6 raeburn 3149: if ($errors) {
1.9 raeburn 3150: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 3151: $errors.'</ul>';
3152: }
3153: return $resulttext;
3154: }
3155:
3156: sub color_font_choices {
3157: my %choices =
3158: &Apache::lonlocal::texthash (
3159: img => "Header",
3160: bgs => "Background colors",
3161: links => "Link colors",
1.55 raeburn 3162: images => "Images",
1.6 raeburn 3163: font => "Font color",
1.97 tempelho 3164: fontmenu => "Font Menu",
1.76 raeburn 3165: pgbg => "Page",
1.6 raeburn 3166: tabbg => "Header",
3167: sidebg => "Border",
3168: link => "Link",
3169: alink => "Active link",
3170: vlink => "Visited link",
3171: );
3172: return %choices;
3173: }
3174:
3175: sub modify_rolecolors {
1.9 raeburn 3176: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 3177: my ($resulttext,%rolehash);
3178: $rolehash{'rolecolors'} = {};
1.55 raeburn 3179: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
3180: if ($domconfig{'rolecolors'} eq '') {
3181: $domconfig{'rolecolors'} = {};
3182: }
3183: }
1.9 raeburn 3184: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 3185: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
3186: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
3187: $dom);
3188: if ($putresult eq 'ok') {
3189: if (keys(%changes) > 0) {
1.41 raeburn 3190: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 3191: $resulttext = &display_colorchgs($dom,\%changes,$roles,
3192: $rolehash{'rolecolors'});
3193: } else {
3194: $resulttext = &mt('No changes made to default color schemes');
3195: }
3196: } else {
1.11 albertel 3197: $resulttext = '<span class="LC_error">'.
3198: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 3199: }
3200: if ($errors) {
3201: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
3202: $errors.'</ul>';
3203: }
3204: return $resulttext;
3205: }
3206:
3207: sub modify_colors {
1.9 raeburn 3208: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 3209: my (%changes,%choices);
1.51 raeburn 3210: my @bgs;
1.6 raeburn 3211: my @links = ('link','alink','vlink');
1.41 raeburn 3212: my @logintext;
1.6 raeburn 3213: my @images;
3214: my $servadm = $r->dir_config('lonAdmEMail');
3215: my $errors;
3216: foreach my $role (@{$roles}) {
3217: if ($role eq 'login') {
1.12 raeburn 3218: %choices = &login_choices();
1.41 raeburn 3219: @logintext = ('textcol','bgcol');
1.12 raeburn 3220: } else {
3221: %choices = &color_font_choices();
1.107 raeburn 3222: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 3223: }
3224: if ($role eq 'login') {
1.41 raeburn 3225: @images = ('img','logo','domlogo','login');
1.51 raeburn 3226: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 3227: } else {
3228: @images = ('img');
1.51 raeburn 3229: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 3230: }
3231: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 3232: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 3233: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
3234: }
1.46 raeburn 3235: my ($configuserok,$author_ok,$switchserver) =
3236: &config_check($dom,$confname,$servadm);
1.9 raeburn 3237: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 3238: if (ref($domconfig->{$role}) ne 'HASH') {
3239: $domconfig->{$role} = {};
3240: }
1.8 raeburn 3241: foreach my $img (@images) {
1.70 raeburn 3242: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
3243: if (defined($env{'form.login_showlogo_'.$img})) {
3244: $confhash->{$role}{'showlogo'}{$img} = 1;
3245: } else {
3246: $confhash->{$role}{'showlogo'}{$img} = 0;
3247: }
3248: }
1.18 albertel 3249: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
3250: && !defined($domconfig->{$role}{$img})
3251: && !$env{'form.'.$role.'_del_'.$img}
3252: && $env{'form.'.$role.'_import_'.$img}) {
3253: # import the old configured image from the .tab setting
3254: # if they haven't provided a new one
3255: $domconfig->{$role}{$img} =
3256: $env{'form.'.$role.'_import_'.$img};
3257: }
1.6 raeburn 3258: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 3259: my $error;
1.6 raeburn 3260: if ($configuserok eq 'ok') {
1.9 raeburn 3261: if ($switchserver) {
1.12 raeburn 3262: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 3263: } else {
3264: if ($author_ok eq 'ok') {
3265: my ($result,$logourl) =
3266: &publishlogo($r,'upload',$role.'_'.$img,
3267: $dom,$confname,$img,$width,$height);
3268: if ($result eq 'ok') {
3269: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 3270: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 3271: } else {
1.12 raeburn 3272: $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 3273: }
3274: } else {
1.46 raeburn 3275: $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 3276: }
3277: }
3278: } else {
1.46 raeburn 3279: $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 3280: }
3281: if ($error) {
1.8 raeburn 3282: &Apache::lonnet::logthis($error);
1.11 albertel 3283: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 3284: }
3285: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 3286: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
3287: my $error;
3288: if ($configuserok eq 'ok') {
3289: # is confname an author?
3290: if ($switchserver eq '') {
3291: if ($author_ok eq 'ok') {
3292: my ($result,$logourl) =
3293: &publishlogo($r,'copy',$domconfig->{$role}{$img},
3294: $dom,$confname,$img,$width,$height);
3295: if ($result eq 'ok') {
3296: $confhash->{$role}{$img} = $logourl;
1.18 albertel 3297: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 3298: }
3299: }
3300: }
3301: }
1.6 raeburn 3302: }
3303: }
3304: }
3305: if (ref($domconfig) eq 'HASH') {
3306: if (ref($domconfig->{$role}) eq 'HASH') {
3307: foreach my $img (@images) {
3308: if ($domconfig->{$role}{$img} ne '') {
3309: if ($env{'form.'.$role.'_del_'.$img}) {
3310: $confhash->{$role}{$img} = '';
1.12 raeburn 3311: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3312: } else {
1.9 raeburn 3313: if ($confhash->{$role}{$img} eq '') {
3314: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
3315: }
1.6 raeburn 3316: }
3317: } else {
3318: if ($env{'form.'.$role.'_del_'.$img}) {
3319: $confhash->{$role}{$img} = '';
1.12 raeburn 3320: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 3321: }
3322: }
1.70 raeburn 3323: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
3324: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
3325: if ($confhash->{$role}{'showlogo'}{$img} ne
3326: $domconfig->{$role}{'showlogo'}{$img}) {
3327: $changes{$role}{'showlogo'}{$img} = 1;
3328: }
3329: } else {
3330: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3331: $changes{$role}{'showlogo'}{$img} = 1;
3332: }
3333: }
3334: }
3335: }
1.6 raeburn 3336: if ($domconfig->{$role}{'font'} ne '') {
3337: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
3338: $changes{$role}{'font'} = 1;
3339: }
3340: } else {
3341: if ($confhash->{$role}{'font'}) {
3342: $changes{$role}{'font'} = 1;
3343: }
3344: }
1.107 raeburn 3345: if ($role ne 'login') {
3346: if ($domconfig->{$role}{'fontmenu'} ne '') {
3347: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
3348: $changes{$role}{'fontmenu'} = 1;
3349: }
3350: } else {
3351: if ($confhash->{$role}{'fontmenu'}) {
3352: $changes{$role}{'fontmenu'} = 1;
3353: }
1.97 tempelho 3354: }
3355: }
1.6 raeburn 3356: foreach my $item (@bgs) {
3357: if ($domconfig->{$role}{$item} ne '') {
3358: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3359: $changes{$role}{'bgs'}{$item} = 1;
3360: }
3361: } else {
3362: if ($confhash->{$role}{$item}) {
3363: $changes{$role}{'bgs'}{$item} = 1;
3364: }
3365: }
3366: }
3367: foreach my $item (@links) {
3368: if ($domconfig->{$role}{$item} ne '') {
3369: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3370: $changes{$role}{'links'}{$item} = 1;
3371: }
3372: } else {
3373: if ($confhash->{$role}{$item}) {
3374: $changes{$role}{'links'}{$item} = 1;
3375: }
3376: }
3377: }
1.41 raeburn 3378: foreach my $item (@logintext) {
3379: if ($domconfig->{$role}{$item} ne '') {
3380: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
3381: $changes{$role}{'logintext'}{$item} = 1;
3382: }
3383: } else {
3384: if ($confhash->{$role}{$item}) {
3385: $changes{$role}{'logintext'}{$item} = 1;
3386: }
3387: }
3388: }
1.6 raeburn 3389: } else {
3390: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3391: \@logintext,$confhash,\%changes);
1.6 raeburn 3392: }
3393: } else {
3394: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 3395: \@logintext,$confhash,\%changes);
1.6 raeburn 3396: }
3397: }
3398: return ($errors,%changes);
3399: }
3400:
1.46 raeburn 3401: sub config_check {
3402: my ($dom,$confname,$servadm) = @_;
3403: my ($configuserok,$author_ok,$switchserver,%currroles);
3404: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
3405: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
3406: $confname,$servadm);
3407: if ($configuserok eq 'ok') {
3408: $switchserver = &check_switchserver($dom,$confname);
3409: if ($switchserver eq '') {
3410: $author_ok = &check_authorstatus($dom,$confname,%currroles);
3411: }
3412: }
3413: return ($configuserok,$author_ok,$switchserver);
3414: }
3415:
1.6 raeburn 3416: sub default_change_checker {
1.41 raeburn 3417: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 3418: foreach my $item (@{$links}) {
3419: if ($confhash->{$role}{$item}) {
3420: $changes->{$role}{'links'}{$item} = 1;
3421: }
3422: }
3423: foreach my $item (@{$bgs}) {
3424: if ($confhash->{$role}{$item}) {
3425: $changes->{$role}{'bgs'}{$item} = 1;
3426: }
3427: }
1.41 raeburn 3428: foreach my $item (@{$logintext}) {
3429: if ($confhash->{$role}{$item}) {
3430: $changes->{$role}{'logintext'}{$item} = 1;
3431: }
3432: }
1.6 raeburn 3433: foreach my $img (@{$images}) {
3434: if ($env{'form.'.$role.'_del_'.$img}) {
3435: $confhash->{$role}{$img} = '';
1.12 raeburn 3436: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 3437: }
1.70 raeburn 3438: if ($role eq 'login') {
3439: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
3440: $changes->{$role}{'showlogo'}{$img} = 1;
3441: }
3442: }
1.6 raeburn 3443: }
3444: if ($confhash->{$role}{'font'}) {
3445: $changes->{$role}{'font'} = 1;
3446: }
1.48 raeburn 3447: }
1.6 raeburn 3448:
3449: sub display_colorchgs {
3450: my ($dom,$changes,$roles,$confhash) = @_;
3451: my (%choices,$resulttext);
3452: if (!grep(/^login$/,@{$roles})) {
3453: $resulttext = &mt('Changes made:').'<br />';
3454: }
3455: foreach my $role (@{$roles}) {
3456: if ($role eq 'login') {
3457: %choices = &login_choices();
3458: } else {
3459: %choices = &color_font_choices();
3460: }
3461: if (ref($changes->{$role}) eq 'HASH') {
3462: if ($role ne 'login') {
3463: $resulttext .= '<h4>'.&mt($role).'</h4>';
3464: }
3465: foreach my $key (sort(keys(%{$changes->{$role}}))) {
3466: if ($role ne 'login') {
3467: $resulttext .= '<ul>';
3468: }
3469: if (ref($changes->{$role}{$key}) eq 'HASH') {
3470: if ($role ne 'login') {
3471: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
3472: }
3473: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 3474: if (($role eq 'login') && ($key eq 'showlogo')) {
3475: if ($confhash->{$role}{$key}{$item}) {
3476: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
3477: } else {
3478: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
3479: }
3480: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 3481: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
3482: } else {
1.12 raeburn 3483: my $newitem = $confhash->{$role}{$item};
3484: if ($key eq 'images') {
3485: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
3486: }
3487: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 3488: }
3489: }
3490: if ($role ne 'login') {
3491: $resulttext .= '</ul></li>';
3492: }
3493: } else {
3494: if ($confhash->{$role}{$key} eq '') {
3495: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
3496: } else {
3497: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
3498: }
3499: }
3500: if ($role ne 'login') {
3501: $resulttext .= '</ul>';
3502: }
3503: }
3504: }
3505: }
1.3 raeburn 3506: return $resulttext;
1.1 raeburn 3507: }
3508:
1.9 raeburn 3509: sub thumb_dimensions {
3510: return ('200','50');
3511: }
3512:
1.16 raeburn 3513: sub check_dimensions {
3514: my ($inputfile) = @_;
3515: my ($fullwidth,$fullheight);
3516: if ($inputfile =~ m|^[/\w.\-]+$|) {
3517: if (open(PIPE,"identify $inputfile 2>&1 |")) {
3518: my $imageinfo = <PIPE>;
3519: if (!close(PIPE)) {
3520: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
3521: }
3522: chomp($imageinfo);
3523: my ($fullsize) =
1.21 raeburn 3524: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 3525: if ($fullsize) {
3526: ($fullwidth,$fullheight) = split(/x/,$fullsize);
3527: }
3528: }
3529: }
3530: return ($fullwidth,$fullheight);
3531: }
3532:
1.9 raeburn 3533: sub check_configuser {
3534: my ($uhome,$dom,$confname,$servadm) = @_;
3535: my ($configuserok,%currroles);
3536: if ($uhome eq 'no_host') {
3537: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
3538: my $configpass = &LONCAPA::Enrollment::create_password();
3539: $configuserok =
3540: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
3541: $configpass,'','','','','',undef,$servadm);
3542: } else {
3543: $configuserok = 'ok';
3544: %currroles =
3545: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
3546: }
3547: return ($configuserok,%currroles);
3548: }
3549:
3550: sub check_authorstatus {
3551: my ($dom,$confname,%currroles) = @_;
3552: my $author_ok;
1.40 raeburn 3553: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 3554: my $start = time;
3555: my $end = 0;
3556: $author_ok =
3557: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 3558: 'au',$end,$start,'','','domconfig');
1.9 raeburn 3559: } else {
3560: $author_ok = 'ok';
3561: }
3562: return $author_ok;
3563: }
3564:
3565: sub publishlogo {
1.46 raeburn 3566: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 3567: my ($output,$fname,$logourl);
3568: if ($action eq 'upload') {
3569: $fname=$env{'form.'.$formname.'.filename'};
3570: chop($env{'form.'.$formname});
3571: } else {
3572: ($fname) = ($formname =~ /([^\/]+)$/);
3573: }
1.46 raeburn 3574: if ($savefileas ne '') {
3575: $fname = $savefileas;
3576: }
1.9 raeburn 3577: $fname=&Apache::lonnet::clean_filename($fname);
3578: # See if there is anything left
3579: unless ($fname) { return ('error: no uploaded file'); }
3580: $fname="$subdir/$fname";
3581: my $filepath='/home/'.$confname.'/public_html';
3582: my ($fnamepath,$file,$fetchthumb);
3583: $file=$fname;
3584: if ($fname=~m|/|) {
3585: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
3586: }
3587: my @parts=split(/\//,$filepath.'/'.$fnamepath);
3588: my $count;
3589: for ($count=4;$count<=$#parts;$count++) {
3590: $filepath.="/$parts[$count]";
3591: if ((-e $filepath)!=1) {
3592: mkdir($filepath,02770);
3593: }
3594: }
3595: # Check for bad extension and disallow upload
3596: if ($file=~/\.(\w+)$/ &&
3597: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
3598: $output =
3599: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
3600: } elsif ($file=~/\.(\w+)$/ &&
3601: !defined(&Apache::loncommon::fileembstyle($1))) {
3602: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
3603: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 3604: $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 3605: } elsif (-d "$filepath/$file") {
3606: $output = &mt('File name is a directory name - rename the file and re-upload');
3607: } else {
3608: my $source = $filepath.'/'.$file;
3609: my $logfile;
3610: if (!open($logfile,">>$source".'.log')) {
3611: return (&mt('No write permission to Construction Space'));
3612: }
3613: print $logfile
3614: "\n================= Publish ".localtime()." ================\n".
3615: $env{'user.name'}.':'.$env{'user.domain'}."\n";
3616: # Save the file
3617: if (!open(FH,'>'.$source)) {
3618: &Apache::lonnet::logthis('Failed to create '.$source);
3619: return (&mt('Failed to create file'));
3620: }
3621: if ($action eq 'upload') {
3622: if (!print FH ($env{'form.'.$formname})) {
3623: &Apache::lonnet::logthis('Failed to write to '.$source);
3624: return (&mt('Failed to write file'));
3625: }
3626: } else {
3627: my $original = &Apache::lonnet::filelocation('',$formname);
3628: if(!copy($original,$source)) {
3629: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
3630: return (&mt('Failed to write file'));
3631: }
3632: }
3633: close(FH);
3634: chmod(0660, $source); # Permissions to rw-rw---.
3635:
3636: my $docroot=$r->dir_config('lonDocRoot');
3637: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
3638: my $copyfile=$targetdir.'/'.$file;
3639:
3640: my @parts=split(/\//,$targetdir);
3641: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
3642: for (my $count=5;$count<=$#parts;$count++) {
3643: $path.="/$parts[$count]";
3644: if (!-e $path) {
3645: print $logfile "\nCreating directory ".$path;
3646: mkdir($path,02770);
3647: }
3648: }
3649: my $versionresult;
3650: if (-e $copyfile) {
3651: $versionresult = &logo_versioning($targetdir,$file,$logfile);
3652: } else {
3653: $versionresult = 'ok';
3654: }
3655: if ($versionresult eq 'ok') {
3656: if (copy($source,$copyfile)) {
3657: print $logfile "\nCopied original source to ".$copyfile."\n";
3658: $output = 'ok';
3659: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
3660: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
3661: } else {
3662: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
3663: $output = &mt('Failed to copy file to RES space').", $!";
3664: }
3665: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
3666: my $inputfile = $filepath.'/'.$file;
3667: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 3668: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
3669: if ($fullwidth ne '' && $fullheight ne '') {
3670: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
3671: my $thumbsize = $thumbwidth.'x'.$thumbheight;
3672: system("convert -sample $thumbsize $inputfile $outfile");
3673: chmod(0660, $filepath.'/tn-'.$file);
3674: if (-e $outfile) {
3675: my $copyfile=$targetdir.'/tn-'.$file;
3676: if (copy($outfile,$copyfile)) {
3677: print $logfile "\nCopied source to ".$copyfile."\n";
3678: &write_metadata($dom,$confname,$formname,
3679: $targetdir,'tn-'.$file,$logfile);
3680: } else {
3681: print $logfile "\nUnable to write ".$copyfile.
3682: ':'.$!."\n";
3683: }
3684: }
1.9 raeburn 3685: }
3686: }
3687: }
3688: } else {
3689: $output = $versionresult;
3690: }
3691: }
3692: return ($output,$logourl);
3693: }
3694:
3695: sub logo_versioning {
3696: my ($targetdir,$file,$logfile) = @_;
3697: my $target = $targetdir.'/'.$file;
3698: my ($maxversion,$fn,$extn,$output);
3699: $maxversion = 0;
3700: if ($file =~ /^(.+)\.(\w+)$/) {
3701: $fn=$1;
3702: $extn=$2;
3703: }
3704: opendir(DIR,$targetdir);
3705: while (my $filename=readdir(DIR)) {
3706: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
3707: $maxversion=($1>$maxversion)?$1:$maxversion;
3708: }
3709: }
3710: $maxversion++;
3711: print $logfile "\nCreating old version ".$maxversion."\n";
3712: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
3713: if (copy($target,$copyfile)) {
3714: print $logfile "Copied old target to ".$copyfile."\n";
3715: $copyfile=$copyfile.'.meta';
3716: if (copy($target.'.meta',$copyfile)) {
3717: print $logfile "Copied old target metadata to ".$copyfile."\n";
3718: $output = 'ok';
3719: } else {
3720: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
3721: $output = &mt('Failed to copy old meta').", $!, ";
3722: }
3723: } else {
3724: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
3725: $output = &mt('Failed to copy old target').", $!, ";
3726: }
3727: return $output;
3728: }
3729:
3730: sub write_metadata {
3731: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
3732: my (%metadatafields,%metadatakeys,$output);
3733: $metadatafields{'title'}=$formname;
3734: $metadatafields{'creationdate'}=time;
3735: $metadatafields{'lastrevisiondate'}=time;
3736: $metadatafields{'copyright'}='public';
3737: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
3738: $env{'user.domain'};
3739: $metadatafields{'authorspace'}=$confname.':'.$dom;
3740: $metadatafields{'domain'}=$dom;
3741: {
3742: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
3743: my $mfh;
3744: unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
3745: $output = &mt('Could not write metadata');
3746: }
3747: foreach (sort keys %metadatafields) {
3748: unless ($_=~/\./) {
3749: my $unikey=$_;
3750: $unikey=~/^([A-Za-z]+)/;
3751: my $tag=$1;
3752: $tag=~tr/A-Z/a-z/;
3753: print $mfh "\n\<$tag";
3754: foreach (split(/\,/,$metadatakeys{$unikey})) {
3755: my $value=$metadatafields{$unikey.'.'.$_};
3756: $value=~s/\"/\'\'/g;
3757: print $mfh ' '.$_.'="'.$value.'"';
3758: }
3759: print $mfh '>'.
3760: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
3761: .'</'.$tag.'>';
3762: }
3763: }
3764: $output = 'ok';
3765: print $logfile "\nWrote metadata";
3766: close($mfh);
3767: }
3768: }
3769:
3770: sub check_switchserver {
3771: my ($dom,$confname) = @_;
3772: my ($allowed,$switchserver);
3773: my $home = &Apache::lonnet::homeserver($confname,$dom);
3774: if ($home eq 'no_host') {
3775: $home = &Apache::lonnet::domain($dom,'primary');
3776: }
3777: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 3778: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
3779: if (!$allowed) {
3780: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 3781: }
3782: return $switchserver;
3783: }
3784:
1.1 raeburn 3785: sub modify_quotas {
1.86 raeburn 3786: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 3787: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
3788: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 3789: if ($action eq 'quotas') {
3790: $context = 'tools';
3791: } else {
3792: $context = $action;
3793: }
3794: if ($context eq 'requestcourses') {
1.98 raeburn 3795: @usertools = ('official','unofficial','community');
1.106 raeburn 3796: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 3797: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
3798: %titles = &courserequest_titles();
3799: $toolregexp = join('|',@usertools);
3800: %conditions = &courserequest_conditions();
1.86 raeburn 3801: } else {
3802: @usertools = ('aboutme','blog','portfolio');
1.101 raeburn 3803: %titles = &tool_titles();
1.86 raeburn 3804: }
1.72 raeburn 3805: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 3806: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 3807: foreach my $key (keys(%env)) {
1.101 raeburn 3808: if ($context eq 'requestcourses') {
3809: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
3810: my $item = $1;
3811: my $type = $2;
3812: if ($type =~ /^limit_(.+)/) {
3813: $limithash{$item}{$1} = $env{$key};
3814: } else {
3815: $confhash{$item}{$type} = $env{$key};
3816: }
3817: }
3818: } else {
1.86 raeburn 3819: if ($key =~ /^form\.quota_(.+)$/) {
3820: $confhash{'defaultquota'}{$1} = $env{$key};
3821: }
1.101 raeburn 3822: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
3823: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
3824: }
1.72 raeburn 3825: }
3826: }
1.102 raeburn 3827: if ($context eq 'requestcourses') {
3828: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
3829: @approvalnotify = sort(@approvalnotify);
3830: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
3831: if (ref($domconfig{$action}) eq 'HASH') {
3832: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
3833: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
3834: $changes{'notify'}{'approval'} = 1;
3835: }
3836: } else {
3837: if ($domconfig{$action}{'notify'}{'approval'}) {
3838: $changes{'notify'}{'approval'} = 1;
3839: }
3840: }
3841: } else {
3842: if ($domconfig{$action}{'notify'}{'approval'}) {
3843: $changes{'notify'}{'approval'} = 1;
3844: }
3845: }
3846: } else {
1.86 raeburn 3847: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
3848: }
1.72 raeburn 3849: foreach my $item (@usertools) {
3850: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 3851: my $unset;
1.101 raeburn 3852: if ($context eq 'requestcourses') {
1.104 raeburn 3853: $unset = '0';
3854: if ($type eq '_LC_adv') {
3855: $unset = '';
3856: }
1.101 raeburn 3857: if ($confhash{$item}{$type} eq 'autolimit') {
3858: $confhash{$item}{$type} .= '=';
3859: unless ($limithash{$item}{$type} =~ /\D/) {
3860: $confhash{$item}{$type} .= $limithash{$item}{$type};
3861: }
3862: }
1.72 raeburn 3863: } else {
1.101 raeburn 3864: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
3865: $confhash{$item}{$type} = 1;
3866: } else {
3867: $confhash{$item}{$type} = 0;
3868: }
1.72 raeburn 3869: }
1.86 raeburn 3870: if (ref($domconfig{$action}) eq 'HASH') {
3871: if (ref($domconfig{$action}{$item}) eq 'HASH') {
3872: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
3873: $changes{$item}{$type} = 1;
3874: }
3875: } else {
3876: if ($context eq 'requestcourses') {
1.104 raeburn 3877: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 3878: $changes{$item}{$type} = 1;
3879: }
3880: } else {
3881: if (!$confhash{$item}{$type}) {
3882: $changes{$item}{$type} = 1;
3883: }
3884: }
3885: }
3886: } else {
3887: if ($context eq 'requestcourses') {
1.104 raeburn 3888: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 3889: $changes{$item}{$type} = 1;
3890: }
3891: } else {
3892: if (!$confhash{$item}{$type}) {
3893: $changes{$item}{$type} = 1;
3894: }
3895: }
3896: }
1.1 raeburn 3897: }
3898: }
1.86 raeburn 3899: unless ($context eq 'requestcourses') {
3900: if (ref($domconfig{'quotas'}) eq 'HASH') {
3901: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
3902: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
3903: if (exists($confhash{'defaultquota'}{$key})) {
3904: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
3905: $changes{'defaultquota'}{$key} = 1;
3906: }
3907: } else {
3908: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 3909: }
3910: }
1.86 raeburn 3911: } else {
3912: foreach my $key (keys(%{$domconfig{'quotas'}})) {
3913: if (exists($confhash{'defaultquota'}{$key})) {
3914: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
3915: $changes{'defaultquota'}{$key} = 1;
3916: }
3917: } else {
3918: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 3919: }
1.1 raeburn 3920: }
3921: }
3922: }
1.86 raeburn 3923: if (ref($confhash{'defaultquota'}) eq 'HASH') {
3924: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
3925: if (ref($domconfig{'quotas'}) eq 'HASH') {
3926: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
3927: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
3928: $changes{'defaultquota'}{$key} = 1;
3929: }
3930: } else {
3931: if (!exists($domconfig{'quotas'}{$key})) {
3932: $changes{'defaultquota'}{$key} = 1;
3933: }
1.72 raeburn 3934: }
3935: } else {
1.86 raeburn 3936: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 3937: }
1.1 raeburn 3938: }
3939: }
3940: }
1.72 raeburn 3941:
3942: foreach my $key (keys(%confhash)) {
3943: $domdefaults{$key} = $confhash{$key};
3944: }
3945:
1.1 raeburn 3946: my %quotahash = (
1.86 raeburn 3947: $action => { %confhash }
1.1 raeburn 3948: );
3949: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
3950: $dom);
3951: if ($putresult eq 'ok') {
3952: if (keys(%changes) > 0) {
1.72 raeburn 3953: my $cachetime = 24*60*60;
3954: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
3955:
1.1 raeburn 3956: $resulttext = &mt('Changes made:').'<ul>';
1.86 raeburn 3957: unless ($context eq 'requestcourses') {
3958: if (ref($changes{'defaultquota'}) eq 'HASH') {
3959: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
3960: foreach my $type (@{$types},'default') {
3961: if (defined($changes{'defaultquota'}{$type})) {
3962: my $typetitle = $usertypes->{$type};
3963: if ($type eq 'default') {
3964: $typetitle = $othertitle;
3965: }
3966: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 3967: }
3968: }
1.86 raeburn 3969: $resulttext .= '</ul></li>';
1.72 raeburn 3970: }
3971: }
1.80 raeburn 3972: my %newenv;
1.72 raeburn 3973: foreach my $item (@usertools) {
3974: if (ref($changes{$item}) eq 'HASH') {
1.80 raeburn 3975: my $newacc =
3976: &Apache::lonnet::usertools_access($env{'user.name'},
3977: $env{'user.domain'},
1.86 raeburn 3978: $item,'reload',$context);
3979: if ($context eq 'requestcourses') {
1.108 raeburn 3980: if ($env{'environment.canrequest.'.$item} ne $newacc) {
3981: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 3982: }
3983: } else {
3984: if ($env{'environment.availabletools.'.$item} ne $newacc) {
3985: $newenv{'environment.availabletools.'.$item} = $newacc;
3986: }
1.80 raeburn 3987: }
1.72 raeburn 3988: $resulttext .= '<li>'.$titles{$item}.'<ul>';
3989: foreach my $type (@{$types},'default','_LC_adv') {
3990: if ($changes{$item}{$type}) {
3991: my $typetitle = $usertypes->{$type};
3992: if ($type eq 'default') {
3993: $typetitle = $othertitle;
3994: } elsif ($type eq '_LC_adv') {
3995: $typetitle = 'LON-CAPA Advanced Users';
3996: }
3997: if ($confhash{$item}{$type}) {
1.101 raeburn 3998: if ($context eq 'requestcourses') {
3999: my $cond;
4000: if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
4001: if ($1 eq '') {
4002: $cond = &mt('(Automatic processing of any request).');
4003: } else {
4004: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
4005: }
4006: } else {
4007: $cond = $conditions{$confhash{$item}{$type}};
4008: }
4009: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
4010: } else {
4011: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
4012: }
1.72 raeburn 4013: } else {
1.104 raeburn 4014: if ($type eq '_LC_adv') {
4015: if ($confhash{$item}{$type} eq '0') {
4016: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
4017: } else {
4018: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
4019: }
4020: } else {
4021: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
4022: }
1.72 raeburn 4023: }
4024: }
1.26 raeburn 4025: }
1.72 raeburn 4026: $resulttext .= '</ul></li>';
1.26 raeburn 4027: }
1.1 raeburn 4028: }
1.102 raeburn 4029: if ($action eq 'requestcourses') {
4030: if (ref($changes{'notify'}) eq 'HASH') {
4031: if ($changes{'notify'}{'approval'}) {
4032: if (ref($confhash{'notify'}) eq 'HASH') {
4033: if ($confhash{'notify'}{'approval'}) {
4034: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
4035: } else {
4036: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
4037: }
4038: }
4039: }
4040: }
4041: }
1.1 raeburn 4042: $resulttext .= '</ul>';
1.80 raeburn 4043: if (keys(%newenv)) {
4044: &Apache::lonnet::appenv(\%newenv);
4045: }
1.1 raeburn 4046: } else {
1.86 raeburn 4047: if ($context eq 'requestcourses') {
4048: $resulttext = &mt('No changes made to rights to request creation of courses.');
4049: } else {
1.90 weissno 4050: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 4051: }
1.1 raeburn 4052: }
4053: } else {
1.11 albertel 4054: $resulttext = '<span class="LC_error">'.
4055: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4056: }
1.3 raeburn 4057: return $resulttext;
1.1 raeburn 4058: }
4059:
1.3 raeburn 4060: sub modify_autoenroll {
4061: my ($dom,%domconfig) = @_;
1.1 raeburn 4062: my ($resulttext,%changes);
4063: my %currautoenroll;
4064: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4065: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
4066: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
4067: }
4068: }
4069: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
4070: my %title = ( run => 'Auto-enrollment active',
4071: sender => 'Sender for notification messages');
4072: my @offon = ('off','on');
1.17 raeburn 4073: my $sender_uname = $env{'form.sender_uname'};
4074: my $sender_domain = $env{'form.sender_domain'};
4075: if ($sender_domain eq '') {
4076: $sender_uname = '';
4077: } elsif ($sender_uname eq '') {
4078: $sender_domain = '';
4079: }
1.1 raeburn 4080: my %autoenrollhash = (
4081: autoenroll => { run => $env{'form.autoenroll_run'},
1.17 raeburn 4082: sender_uname => $sender_uname,
4083: sender_domain => $sender_domain,
1.1 raeburn 4084:
4085: }
4086: );
1.4 raeburn 4087: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
4088: $dom);
1.1 raeburn 4089: if ($putresult eq 'ok') {
4090: if (exists($currautoenroll{'run'})) {
4091: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
4092: $changes{'run'} = 1;
4093: }
4094: } elsif ($autorun) {
4095: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 4096: $changes{'run'} = 1;
1.1 raeburn 4097: }
4098: }
1.17 raeburn 4099: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 4100: $changes{'sender'} = 1;
4101: }
1.17 raeburn 4102: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 4103: $changes{'sender'} = 1;
4104: }
4105: if (keys(%changes) > 0) {
4106: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 4107: if ($changes{'run'}) {
1.1 raeburn 4108: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
4109: }
4110: if ($changes{'sender'}) {
1.17 raeburn 4111: if ($sender_uname eq '' || $sender_domain eq '') {
4112: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
4113: } else {
4114: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
4115: }
1.1 raeburn 4116: }
4117: $resulttext .= '</ul>';
4118: } else {
4119: $resulttext = &mt('No changes made to auto-enrollment settings');
4120: }
4121: } else {
1.11 albertel 4122: $resulttext = '<span class="LC_error">'.
4123: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4124: }
1.3 raeburn 4125: return $resulttext;
1.1 raeburn 4126: }
4127:
4128: sub modify_autoupdate {
1.3 raeburn 4129: my ($dom,%domconfig) = @_;
1.1 raeburn 4130: my ($resulttext,%currautoupdate,%fields,%changes);
4131: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
4132: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
4133: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
4134: }
4135: }
4136: my @offon = ('off','on');
4137: my %title = &Apache::lonlocal::texthash (
4138: run => 'Auto-update:',
4139: classlists => 'Updates to user information in classlists?'
4140: );
1.44 raeburn 4141: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 4142: my %fieldtitles = &Apache::lonlocal::texthash (
4143: id => 'Student/Employee ID',
1.20 raeburn 4144: permanentemail => 'E-mail address',
1.1 raeburn 4145: lastname => 'Last Name',
4146: firstname => 'First Name',
4147: middlename => 'Middle Name',
4148: gen => 'Generation',
4149: );
4150: my $othertitle = &mt('All users');
4151: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 4152: $othertitle = &mt('Other users');
1.1 raeburn 4153: }
4154: foreach my $key (keys(%env)) {
4155: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
4156: push(@{$fields{$1}},$2);
4157: }
4158: }
4159: my %updatehash = (
4160: autoupdate => { run => $env{'form.autoupdate_run'},
4161: classlists => $env{'form.classlists'},
4162: fields => {%fields},
4163: }
4164: );
4165: foreach my $key (keys(%currautoupdate)) {
4166: if (($key eq 'run') || ($key eq 'classlists')) {
4167: if (exists($updatehash{autoupdate}{$key})) {
4168: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
4169: $changes{$key} = 1;
4170: }
4171: }
4172: } elsif ($key eq 'fields') {
4173: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 4174: foreach my $item (@{$types},'default') {
1.1 raeburn 4175: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
4176: my $change = 0;
4177: foreach my $type (@{$currautoupdate{$key}{$item}}) {
4178: if (!exists($fields{$item})) {
4179: $change = 1;
4180: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 4181: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 4182: $change = 1;
4183: }
4184: }
4185: }
4186: if ($change) {
4187: push(@{$changes{$key}},$item);
4188: }
1.26 raeburn 4189: }
1.1 raeburn 4190: }
4191: }
4192: }
4193: }
1.26 raeburn 4194: foreach my $item (@{$types},'default') {
4195: if (defined($fields{$item})) {
4196: if (ref($currautoupdate{'fields'}) eq 'HASH') {
4197: if (!exists($currautoupdate{'fields'}{$item})) {
4198: push(@{$changes{'fields'}},$item);
4199: }
4200: } else {
4201: push(@{$changes{'fields'}},$item);
1.1 raeburn 4202: }
4203: }
4204: }
4205: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
4206: $dom);
4207: if ($putresult eq 'ok') {
4208: if (keys(%changes) > 0) {
4209: $resulttext = &mt('Changes made:').'<ul>';
4210: foreach my $key (sort(keys(%changes))) {
4211: if (ref($changes{$key}) eq 'ARRAY') {
4212: foreach my $item (@{$changes{$key}}) {
4213: my @newvalues;
4214: foreach my $type (@{$fields{$item}}) {
4215: push(@newvalues,$fieldtitles{$type});
4216: }
1.3 raeburn 4217: my $newvaluestr;
4218: if (@newvalues > 0) {
4219: $newvaluestr = join(', ',@newvalues);
4220: } else {
4221: $newvaluestr = &mt('none');
1.6 raeburn 4222: }
1.1 raeburn 4223: if ($item eq 'default') {
1.26 raeburn 4224: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 4225: } else {
1.26 raeburn 4226: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 4227: }
4228: }
4229: } else {
4230: my $newvalue;
4231: if ($key eq 'run') {
4232: $newvalue = $offon[$env{'form.autoupdate_run'}];
4233: } else {
4234: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 4235: }
1.1 raeburn 4236: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
4237: }
4238: }
4239: $resulttext .= '</ul>';
4240: } else {
1.3 raeburn 4241: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 4242: }
4243: } else {
1.11 albertel 4244: $resulttext = '<span class="LC_error">'.
4245: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4246: }
1.3 raeburn 4247: return $resulttext;
1.1 raeburn 4248: }
4249:
1.23 raeburn 4250: sub modify_directorysrch {
4251: my ($dom,%domconfig) = @_;
4252: my ($resulttext,%changes);
4253: my %currdirsrch;
4254: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
4255: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
4256: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
4257: }
4258: }
4259: my %title = ( available => 'Directory search available',
1.24 raeburn 4260: localonly => 'Other domains can search',
1.23 raeburn 4261: searchby => 'Search types',
4262: searchtypes => 'Search latitude');
4263: my @offon = ('off','on');
1.24 raeburn 4264: my @otherdoms = ('Yes','No');
1.23 raeburn 4265:
1.25 raeburn 4266: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 4267: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
4268: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
4269:
1.44 raeburn 4270: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 4271: if (keys(%{$usertypes}) == 0) {
4272: @cansearch = ('default');
4273: } else {
4274: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
4275: foreach my $type (@{$currdirsrch{'cansearch'}}) {
4276: if (!grep(/^\Q$type\E$/,@cansearch)) {
4277: push(@{$changes{'cansearch'}},$type);
4278: }
1.23 raeburn 4279: }
1.26 raeburn 4280: foreach my $type (@cansearch) {
4281: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
4282: push(@{$changes{'cansearch'}},$type);
4283: }
1.23 raeburn 4284: }
1.26 raeburn 4285: } else {
4286: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 4287: }
4288: }
4289:
4290: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
4291: foreach my $by (@{$currdirsrch{'searchby'}}) {
4292: if (!grep(/^\Q$by\E$/,@searchby)) {
4293: push(@{$changes{'searchby'}},$by);
4294: }
4295: }
4296: foreach my $by (@searchby) {
4297: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
4298: push(@{$changes{'searchby'}},$by);
4299: }
4300: }
4301: } else {
4302: push(@{$changes{'searchby'}},@searchby);
4303: }
1.25 raeburn 4304:
4305: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
4306: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
4307: if (!grep(/^\Q$type\E$/,@searchtypes)) {
4308: push(@{$changes{'searchtypes'}},$type);
4309: }
4310: }
4311: foreach my $type (@searchtypes) {
4312: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
4313: push(@{$changes{'searchtypes'}},$type);
4314: }
4315: }
4316: } else {
4317: if (exists($currdirsrch{'searchtypes'})) {
4318: foreach my $type (@searchtypes) {
4319: if ($type ne $currdirsrch{'searchtypes'}) {
4320: push(@{$changes{'searchtypes'}},$type);
4321: }
4322: }
4323: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
4324: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
4325: }
4326: } else {
4327: push(@{$changes{'searchtypes'}},@searchtypes);
4328: }
4329: }
4330:
1.23 raeburn 4331: my %dirsrch_hash = (
4332: directorysrch => { available => $env{'form.dirsrch_available'},
4333: cansearch => \@cansearch,
1.24 raeburn 4334: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 4335: searchby => \@searchby,
1.25 raeburn 4336: searchtypes => \@searchtypes,
1.23 raeburn 4337: }
4338: );
4339: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
4340: $dom);
4341: if ($putresult eq 'ok') {
4342: if (exists($currdirsrch{'available'})) {
4343: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
4344: $changes{'available'} = 1;
4345: }
4346: } else {
4347: if ($env{'form.dirsrch_available'} eq '1') {
4348: $changes{'available'} = 1;
4349: }
4350: }
1.24 raeburn 4351: if (exists($currdirsrch{'localonly'})) {
4352: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
4353: $changes{'localonly'} = 1;
4354: }
4355: } else {
4356: if ($env{'form.dirsrch_localonly'} eq '1') {
4357: $changes{'localonly'} = 1;
4358: }
4359: }
1.23 raeburn 4360: if (keys(%changes) > 0) {
4361: $resulttext = &mt('Changes made:').'<ul>';
4362: if ($changes{'available'}) {
4363: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
4364: }
1.24 raeburn 4365: if ($changes{'localonly'}) {
4366: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
4367: }
4368:
1.23 raeburn 4369: if (ref($changes{'cansearch'}) eq 'ARRAY') {
4370: my $chgtext;
1.26 raeburn 4371: if (ref($usertypes) eq 'HASH') {
4372: if (keys(%{$usertypes}) > 0) {
4373: foreach my $type (@{$types}) {
4374: if (grep(/^\Q$type\E$/,@cansearch)) {
4375: $chgtext .= $usertypes->{$type}.'; ';
4376: }
4377: }
4378: if (grep(/^default$/,@cansearch)) {
4379: $chgtext .= $othertitle;
4380: } else {
4381: $chgtext =~ s/\; $//;
4382: }
4383: $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 4384: }
4385: }
4386: }
4387: if (ref($changes{'searchby'}) eq 'ARRAY') {
4388: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4389: my $chgtext;
4390: foreach my $type (@{$titleorder}) {
4391: if (grep(/^\Q$type\E$/,@searchby)) {
4392: if (defined($searchtitles->{$type})) {
4393: $chgtext .= $searchtitles->{$type}.'; ';
4394: }
4395: }
4396: }
4397: $chgtext =~ s/\; $//;
4398: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
4399: }
1.25 raeburn 4400: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
4401: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
4402: my $chgtext;
4403: foreach my $type (@{$srchtypeorder}) {
4404: if (grep(/^\Q$type\E$/,@searchtypes)) {
4405: if (defined($srchtypes_desc->{$type})) {
4406: $chgtext .= $srchtypes_desc->{$type}.'; ';
4407: }
4408: }
4409: }
4410: $chgtext =~ s/\; $//;
4411: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 4412: }
4413: $resulttext .= '</ul>';
4414: } else {
4415: $resulttext = &mt('No changes made to institution directory search settings');
4416: }
4417: } else {
4418: $resulttext = '<span class="LC_error">'.
1.27 raeburn 4419: &mt('An error occurred: [_1]',$putresult).'</span>';
4420: }
4421: return $resulttext;
4422: }
4423:
1.28 raeburn 4424: sub modify_contacts {
4425: my ($dom,%domconfig) = @_;
4426: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
4427: if (ref($domconfig{'contacts'}) eq 'HASH') {
4428: foreach my $key (keys(%{$domconfig{'contacts'}})) {
4429: $currsetting{$key} = $domconfig{'contacts'}{$key};
4430: }
4431: }
4432: my (%others,%to);
4433: my @contacts = ('supportemail','adminemail');
1.102 raeburn 4434: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
4435: 'requestsmail');
1.28 raeburn 4436: foreach my $type (@mailings) {
4437: @{$newsetting{$type}} =
4438: &Apache::loncommon::get_env_multiple('form.'.$type);
4439: foreach my $item (@contacts) {
4440: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
4441: $contacts_hash{contacts}{$type}{$item} = 1;
4442: } else {
4443: $contacts_hash{contacts}{$type}{$item} = 0;
4444: }
4445: }
4446: $others{$type} = $env{'form.'.$type.'_others'};
4447: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
4448: }
4449: foreach my $item (@contacts) {
4450: $to{$item} = $env{'form.'.$item};
4451: $contacts_hash{'contacts'}{$item} = $to{$item};
4452: }
4453: if (keys(%currsetting) > 0) {
4454: foreach my $item (@contacts) {
4455: if ($to{$item} ne $currsetting{$item}) {
4456: $changes{$item} = 1;
4457: }
4458: }
4459: foreach my $type (@mailings) {
4460: foreach my $item (@contacts) {
4461: if (ref($currsetting{$type}) eq 'HASH') {
4462: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
4463: push(@{$changes{$type}},$item);
4464: }
4465: } else {
4466: push(@{$changes{$type}},@{$newsetting{$type}});
4467: }
4468: }
4469: if ($others{$type} ne $currsetting{$type}{'others'}) {
4470: push(@{$changes{$type}},'others');
4471: }
4472: }
4473: } else {
4474: my %default;
4475: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4476: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4477: $default{'errormail'} = 'adminemail';
4478: $default{'packagesmail'} = 'adminemail';
4479: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 4480: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 4481: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 4482: foreach my $item (@contacts) {
4483: if ($to{$item} ne $default{$item}) {
4484: $changes{$item} = 1;
4485: }
4486: }
4487: foreach my $type (@mailings) {
4488: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
4489:
4490: push(@{$changes{$type}},@{$newsetting{$type}});
4491: }
4492: if ($others{$type} ne '') {
4493: push(@{$changes{$type}},'others');
4494: }
4495: }
4496: }
4497: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
4498: $dom);
4499: if ($putresult eq 'ok') {
4500: if (keys(%changes) > 0) {
4501: my ($titles,$short_titles) = &contact_titles();
4502: $resulttext = &mt('Changes made:').'<ul>';
4503: foreach my $item (@contacts) {
4504: if ($changes{$item}) {
4505: $resulttext .= '<li>'.$titles->{$item}.
4506: &mt(' set to: ').
4507: '<span class="LC_cusr_emph">'.
4508: $to{$item}.'</span></li>';
4509: }
4510: }
4511: foreach my $type (@mailings) {
4512: if (ref($changes{$type}) eq 'ARRAY') {
4513: $resulttext .= '<li>'.$titles->{$type}.': ';
4514: my @text;
4515: foreach my $item (@{$newsetting{$type}}) {
4516: push(@text,$short_titles->{$item});
4517: }
4518: if ($others{$type} ne '') {
4519: push(@text,$others{$type});
4520: }
4521: $resulttext .= '<span class="LC_cusr_emph">'.
4522: join(', ',@text).'</span></li>';
4523: }
4524: }
4525: $resulttext .= '</ul>';
4526: } else {
1.34 raeburn 4527: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 4528: }
4529: } else {
4530: $resulttext = '<span class="LC_error">'.
4531: &mt('An error occurred: [_1].',$putresult).'</span>';
4532: }
4533: return $resulttext;
4534: }
4535:
4536: sub modify_usercreation {
1.27 raeburn 4537: my ($dom,%domconfig) = @_;
1.34 raeburn 4538: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 4539: my $warningmsg;
1.27 raeburn 4540: if (ref($domconfig{'usercreation'}) eq 'HASH') {
4541: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
4542: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
4543: }
4544: }
4545: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 4546: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 4547: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 4548: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 4549: foreach my $item(@contexts) {
1.45 raeburn 4550: if ($item eq 'selfcreate') {
1.50 raeburn 4551: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 4552: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
4553: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 4554: if (ref($cancreate{$item}) eq 'ARRAY') {
4555: if (grep(/^login$/,@{$cancreate{$item}})) {
4556: $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.');
4557: }
1.43 raeburn 4558: }
4559: }
1.50 raeburn 4560: } else {
4561: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 4562: }
1.34 raeburn 4563: }
1.93 raeburn 4564: my ($othertitle,$usertypes,$types) =
4565: &Apache::loncommon::sorted_inst_types($dom);
4566: if (ref($types) eq 'ARRAY') {
4567: if (@{$types} > 0) {
4568: @{$cancreate{'statustocreate'}} =
4569: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 4570: } else {
4571: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 4572: }
4573: push(@contexts,'statustocreate');
4574: }
1.34 raeburn 4575: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
4576: foreach my $item (@contexts) {
1.93 raeburn 4577: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
4578: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 4579: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 4580: if (ref($cancreate{$item}) eq 'ARRAY') {
4581: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
4582: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4583: push(@{$changes{'cancreate'}},$item);
4584: }
1.50 raeburn 4585: }
4586: }
4587: }
4588: } else {
4589: if ($curr_usercreation{'cancreate'}{$item} eq '') {
4590: if (@{$cancreate{$item}} > 0) {
4591: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4592: push(@{$changes{'cancreate'}},$item);
4593: }
4594: }
4595: } else {
4596: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
4597: if (@{$cancreate{$item}} < 3) {
4598: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4599: push(@{$changes{'cancreate'}},$item);
4600: }
4601: }
4602: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
4603: if (@{$cancreate{$item}} > 0) {
4604: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4605: push(@{$changes{'cancreate'}},$item);
4606: }
4607: }
4608: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
4609: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4610: push(@{$changes{'cancreate'}},$item);
4611: }
4612: }
4613: }
4614: }
4615: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4616: foreach my $type (@{$cancreate{$item}}) {
4617: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
4618: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
4619: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4620: push(@{$changes{'cancreate'}},$item);
4621: }
4622: }
4623: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
4624: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
4625: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
4626: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
4627: push(@{$changes{'cancreate'}},$item);
4628: }
4629: }
4630: }
4631: }
4632: }
4633: } else {
4634: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
4635: push(@{$changes{'cancreate'}},$item);
4636: }
4637: }
1.27 raeburn 4638: }
1.34 raeburn 4639: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
4640: foreach my $item (@contexts) {
1.43 raeburn 4641: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 4642: if ($cancreate{$item} ne 'any') {
4643: push(@{$changes{'cancreate'}},$item);
4644: }
4645: } else {
4646: if ($cancreate{$item} ne 'none') {
4647: push(@{$changes{'cancreate'}},$item);
4648: }
1.27 raeburn 4649: }
4650: }
4651: } else {
1.43 raeburn 4652: foreach my $item (@contexts) {
1.34 raeburn 4653: push(@{$changes{'cancreate'}},$item);
4654: }
1.27 raeburn 4655: }
1.34 raeburn 4656:
1.27 raeburn 4657: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
4658: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
4659: if (!grep(/^\Q$type\E$/,@username_rule)) {
4660: push(@{$changes{'username_rule'}},$type);
4661: }
4662: }
4663: foreach my $type (@username_rule) {
4664: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
4665: push(@{$changes{'username_rule'}},$type);
4666: }
4667: }
4668: } else {
4669: push(@{$changes{'username_rule'}},@username_rule);
4670: }
4671:
1.32 raeburn 4672: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
4673: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
4674: if (!grep(/^\Q$type\E$/,@id_rule)) {
4675: push(@{$changes{'id_rule'}},$type);
4676: }
4677: }
4678: foreach my $type (@id_rule) {
4679: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
4680: push(@{$changes{'id_rule'}},$type);
4681: }
4682: }
4683: } else {
4684: push(@{$changes{'id_rule'}},@id_rule);
4685: }
4686:
1.43 raeburn 4687: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
4688: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
4689: if (!grep(/^\Q$type\E$/,@email_rule)) {
4690: push(@{$changes{'email_rule'}},$type);
4691: }
4692: }
4693: foreach my $type (@email_rule) {
4694: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
4695: push(@{$changes{'email_rule'}},$type);
4696: }
4697: }
4698: } else {
4699: push(@{$changes{'email_rule'}},@email_rule);
4700: }
4701:
4702: my @authen_contexts = ('author','course','domain');
1.28 raeburn 4703: my @authtypes = ('int','krb4','krb5','loc');
4704: my %authhash;
1.43 raeburn 4705: foreach my $item (@authen_contexts) {
1.28 raeburn 4706: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
4707: foreach my $auth (@authtypes) {
4708: if (grep(/^\Q$auth\E$/,@authallowed)) {
4709: $authhash{$item}{$auth} = 1;
4710: } else {
4711: $authhash{$item}{$auth} = 0;
4712: }
4713: }
4714: }
4715: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 4716: foreach my $item (@authen_contexts) {
1.28 raeburn 4717: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
4718: foreach my $auth (@authtypes) {
4719: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
4720: push(@{$changes{'authtypes'}},$item);
4721: last;
4722: }
4723: }
4724: }
4725: }
4726: } else {
1.43 raeburn 4727: foreach my $item (@authen_contexts) {
1.28 raeburn 4728: push(@{$changes{'authtypes'}},$item);
4729: }
4730: }
4731:
1.27 raeburn 4732: my %usercreation_hash = (
1.28 raeburn 4733: usercreation => {
1.34 raeburn 4734: cancreate => \%cancreate,
1.27 raeburn 4735: username_rule => \@username_rule,
1.32 raeburn 4736: id_rule => \@id_rule,
1.43 raeburn 4737: email_rule => \@email_rule,
1.32 raeburn 4738: authtypes => \%authhash,
1.27 raeburn 4739: }
4740: );
4741:
4742: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
4743: $dom);
1.50 raeburn 4744:
4745: my %selfcreatetypes = (
4746: sso => 'users authenticated by institutional single sign on',
4747: login => 'users authenticated by institutional log-in',
4748: email => 'users who provide a valid e-mail address for use as the username',
4749: );
1.27 raeburn 4750: if ($putresult eq 'ok') {
4751: if (keys(%changes) > 0) {
4752: $resulttext = &mt('Changes made:').'<ul>';
4753: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 4754: my %lt = &usercreation_types();
4755: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 4756: my $chgtext;
4757: unless ($type eq 'statustocreate') {
4758: $chgtext = $lt{$type}.', ';
4759: }
1.45 raeburn 4760: if ($type eq 'selfcreate') {
1.50 raeburn 4761: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 4762: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 4763: } else {
1.100 raeburn 4764: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 4765: foreach my $case (@{$cancreate{$type}}) {
4766: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
4767: }
4768: $chgtext .= '</ul>';
1.100 raeburn 4769: if (ref($cancreate{$type}) eq 'ARRAY') {
4770: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
4771: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
4772: if (@{$cancreate{'statustocreate'}} == 0) {
4773: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
4774: }
4775: }
4776: }
4777: }
1.43 raeburn 4778: }
1.93 raeburn 4779: } elsif ($type eq 'statustocreate') {
1.96 raeburn 4780: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
4781: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
4782: if (@{$cancreate{'selfcreate'}} > 0) {
4783: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 4784:
4785: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 4786: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 4787: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
4788: }
1.96 raeburn 4789: } elsif (ref($usertypes) eq 'HASH') {
4790: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 4791: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
4792: } else {
4793: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
4794: }
4795: $chgtext .= '<ul>';
4796: foreach my $case (@{$cancreate{$type}}) {
4797: if ($case eq 'default') {
4798: $chgtext .= '<li>'.$othertitle.'</li>';
4799: } else {
4800: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 4801: }
4802: }
1.100 raeburn 4803: $chgtext .= '</ul>';
4804: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
4805: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
4806: }
4807: }
4808: } else {
4809: if (@{$cancreate{$type}} == 0) {
4810: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
4811: } else {
4812: $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 4813: }
4814: }
4815: }
1.43 raeburn 4816: } else {
4817: if ($cancreate{$type} eq 'none') {
4818: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
4819: } elsif ($cancreate{$type} eq 'any') {
4820: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
4821: } elsif ($cancreate{$type} eq 'official') {
4822: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
4823: } elsif ($cancreate{$type} eq 'unofficial') {
4824: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
4825: }
1.34 raeburn 4826: }
4827: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 4828: }
4829: }
4830: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 4831: my ($rules,$ruleorder) =
4832: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 4833: my $chgtext = '<ul>';
4834: foreach my $type (@username_rule) {
4835: if (ref($rules->{$type}) eq 'HASH') {
4836: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
4837: }
4838: }
4839: $chgtext .= '</ul>';
4840: if (@username_rule > 0) {
4841: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4842: } else {
1.28 raeburn 4843: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 4844: }
4845: }
1.32 raeburn 4846: if (ref($changes{'id_rule'}) eq 'ARRAY') {
4847: my ($idrules,$idruleorder) =
4848: &Apache::lonnet::inst_userrules($dom,'id');
4849: my $chgtext = '<ul>';
4850: foreach my $type (@id_rule) {
4851: if (ref($idrules->{$type}) eq 'HASH') {
4852: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
4853: }
4854: }
4855: $chgtext .= '</ul>';
4856: if (@id_rule > 0) {
4857: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
4858: } else {
4859: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
4860: }
4861: }
1.43 raeburn 4862: if (ref($changes{'email_rule'}) eq 'ARRAY') {
4863: my ($emailrules,$emailruleorder) =
4864: &Apache::lonnet::inst_userrules($dom,'email');
4865: my $chgtext = '<ul>';
4866: foreach my $type (@email_rule) {
4867: if (ref($emailrules->{$type}) eq 'HASH') {
4868: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
4869: }
4870: }
4871: $chgtext .= '</ul>';
4872: if (@email_rule > 0) {
4873: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
4874: } else {
4875: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
4876: }
4877: }
4878:
1.28 raeburn 4879: my %authname = &authtype_names();
4880: my %context_title = &context_names();
4881: if (ref($changes{'authtypes'}) eq 'ARRAY') {
4882: my $chgtext = '<ul>';
4883: foreach my $type (@{$changes{'authtypes'}}) {
4884: my @allowed;
4885: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
4886: foreach my $auth (@authtypes) {
4887: if ($authhash{$type}{$auth}) {
4888: push(@allowed,$authname{$auth});
4889: }
4890: }
1.43 raeburn 4891: if (@allowed > 0) {
4892: $chgtext .= join(', ',@allowed).'</li>';
4893: } else {
4894: $chgtext .= &mt('none').'</li>';
4895: }
1.28 raeburn 4896: }
4897: $chgtext .= '</ul>';
4898: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
4899: $resulttext .= '</li>';
4900: }
1.27 raeburn 4901: $resulttext .= '</ul>';
4902: } else {
1.28 raeburn 4903: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 4904: }
4905: } else {
4906: $resulttext = '<span class="LC_error">'.
1.23 raeburn 4907: &mt('An error occurred: [_1]',$putresult).'</span>';
4908: }
1.43 raeburn 4909: if ($warningmsg ne '') {
4910: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
4911: }
1.23 raeburn 4912: return $resulttext;
4913: }
4914:
1.33 raeburn 4915: sub modify_usermodification {
4916: my ($dom,%domconfig) = @_;
4917: my ($resulttext,%curr_usermodification,%changes);
4918: if (ref($domconfig{'usermodification'}) eq 'HASH') {
4919: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
4920: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
4921: }
4922: }
1.63 raeburn 4923: my @contexts = ('author','course','selfcreate');
1.33 raeburn 4924: my %context_title = (
4925: author => 'In author context',
4926: course => 'In course context',
1.63 raeburn 4927: selfcreate => 'When self creating account',
1.33 raeburn 4928: );
4929: my @fields = ('lastname','firstname','middlename','generation',
4930: 'permanentemail','id');
4931: my %roles = (
4932: author => ['ca','aa'],
4933: course => ['st','ep','ta','in','cr'],
4934: );
1.63 raeburn 4935: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4936: if (ref($types) eq 'ARRAY') {
4937: push(@{$types},'default');
4938: $usertypes->{'default'} = $othertitle;
4939: }
4940: $roles{'selfcreate'} = $types;
1.33 raeburn 4941: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4942: my %modifyhash;
4943: foreach my $context (@contexts) {
4944: foreach my $role (@{$roles{$context}}) {
4945: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
4946: foreach my $item (@fields) {
4947: if (grep(/^\Q$item\E$/,@modifiable)) {
4948: $modifyhash{$context}{$role}{$item} = 1;
4949: } else {
4950: $modifyhash{$context}{$role}{$item} = 0;
4951: }
4952: }
4953: }
4954: if (ref($curr_usermodification{$context}) eq 'HASH') {
4955: foreach my $role (@{$roles{$context}}) {
4956: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
4957: foreach my $field (@fields) {
4958: if ($modifyhash{$context}{$role}{$field} ne
4959: $curr_usermodification{$context}{$role}{$field}) {
4960: push(@{$changes{$context}},$role);
4961: last;
4962: }
4963: }
4964: }
4965: }
4966: } else {
4967: foreach my $context (@contexts) {
4968: foreach my $role (@{$roles{$context}}) {
4969: push(@{$changes{$context}},$role);
4970: }
4971: }
4972: }
4973: }
4974: my %usermodification_hash = (
4975: usermodification => \%modifyhash,
4976: );
4977: my $putresult = &Apache::lonnet::put_dom('configuration',
4978: \%usermodification_hash,$dom);
4979: if ($putresult eq 'ok') {
4980: if (keys(%changes) > 0) {
4981: $resulttext = &mt('Changes made: ').'<ul>';
4982: foreach my $context (@contexts) {
4983: if (ref($changes{$context}) eq 'ARRAY') {
4984: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
4985: if (ref($changes{$context}) eq 'ARRAY') {
4986: foreach my $role (@{$changes{$context}}) {
4987: my $rolename;
1.63 raeburn 4988: if ($context eq 'selfcreate') {
4989: $rolename = $role;
4990: if (ref($usertypes) eq 'HASH') {
4991: if ($usertypes->{$role} ne '') {
4992: $rolename = $usertypes->{$role};
4993: }
4994: }
1.33 raeburn 4995: } else {
1.63 raeburn 4996: if ($role eq 'cr') {
4997: $rolename = &mt('Custom');
4998: } else {
4999: $rolename = &Apache::lonnet::plaintext($role);
5000: }
1.33 raeburn 5001: }
5002: my @modifiable;
1.63 raeburn 5003: if ($context eq 'selfcreate') {
5004: $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): ');
5005: } else {
5006: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
5007: }
1.33 raeburn 5008: foreach my $field (@fields) {
5009: if ($modifyhash{$context}{$role}{$field}) {
5010: push(@modifiable,$fieldtitles{$field});
5011: }
5012: }
5013: if (@modifiable > 0) {
5014: $resulttext .= join(', ',@modifiable);
5015: } else {
5016: $resulttext .= &mt('none');
5017: }
5018: $resulttext .= '</li>';
5019: }
5020: $resulttext .= '</ul></li>';
5021: }
5022: }
5023: }
5024: $resulttext .= '</ul>';
5025: } else {
5026: $resulttext = &mt('No changes made to user modification settings');
5027: }
5028: } else {
5029: $resulttext = '<span class="LC_error">'.
5030: &mt('An error occurred: [_1]',$putresult).'</span>';
5031: }
5032: return $resulttext;
5033: }
5034:
1.43 raeburn 5035: sub modify_defaults {
5036: my ($dom,$r) = @_;
5037: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
5038: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.68 raeburn 5039: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
1.43 raeburn 5040: my @authtypes = ('internal','krb4','krb5','localauth');
5041: foreach my $item (@items) {
5042: $newvalues{$item} = $env{'form.'.$item};
5043: if ($item eq 'auth_def') {
5044: if ($newvalues{$item} ne '') {
5045: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
5046: push(@errors,$item);
5047: }
5048: }
5049: } elsif ($item eq 'lang_def') {
5050: if ($newvalues{$item} ne '') {
5051: if ($newvalues{$item} =~ /^(\w+)/) {
5052: my $langcode = $1;
1.103 raeburn 5053: if ($langcode ne 'x_chef') {
5054: if (code2language($langcode) eq '') {
5055: push(@errors,$item);
5056: }
1.43 raeburn 5057: }
5058: } else {
5059: push(@errors,$item);
5060: }
5061: }
1.54 raeburn 5062: } elsif ($item eq 'timezone_def') {
5063: if ($newvalues{$item} ne '') {
1.62 raeburn 5064: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 5065: push(@errors,$item);
5066: }
5067: }
1.68 raeburn 5068: } elsif ($item eq 'datelocale_def') {
5069: if ($newvalues{$item} ne '') {
5070: my @datelocale_ids = DateTime::Locale->ids();
5071: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
5072: push(@errors,$item);
5073: }
5074: }
1.43 raeburn 5075: }
5076: if (grep(/^\Q$item\E$/,@errors)) {
5077: $newvalues{$item} = $domdefaults{$item};
5078: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
5079: $changes{$item} = 1;
5080: }
1.72 raeburn 5081: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 5082: }
5083: my %defaults_hash = (
1.72 raeburn 5084: defaults => \%newvalues,
5085: );
1.43 raeburn 5086: my $title = &defaults_titles();
5087: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
5088: $dom);
5089: if ($putresult eq 'ok') {
5090: if (keys(%changes) > 0) {
5091: $resulttext = &mt('Changes made:').'<ul>';
5092: my $version = $r->dir_config('lonVersion');
5093: 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";
5094: foreach my $item (sort(keys(%changes))) {
5095: my $value = $env{'form.'.$item};
5096: if ($value eq '') {
5097: $value = &mt('none');
5098: } elsif ($item eq 'auth_def') {
5099: my %authnames = &authtype_names();
5100: my %shortauth = (
5101: internal => 'int',
5102: krb4 => 'krb4',
5103: krb5 => 'krb5',
5104: localauth => 'loc',
5105: );
5106: $value = $authnames{$shortauth{$value}};
5107: }
5108: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
5109: $mailmsgtext .= "$title->{$item} set to $value\n";
5110: }
5111: $resulttext .= '</ul>';
5112: $mailmsgtext .= "\n";
5113: my $cachetime = 24*60*60;
1.72 raeburn 5114: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 5115: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 5116: my $sysmail = $r->dir_config('lonSysEMail');
5117: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
5118: }
1.43 raeburn 5119: } else {
1.54 raeburn 5120: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 5121: }
5122: } else {
5123: $resulttext = '<span class="LC_error">'.
5124: &mt('An error occurred: [_1]',$putresult).'</span>';
5125: }
5126: if (@errors > 0) {
5127: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
5128: foreach my $item (@errors) {
5129: $resulttext .= ' "'.$title->{$item}.'",';
5130: }
5131: $resulttext =~ s/,$//;
5132: }
5133: return $resulttext;
5134: }
5135:
1.46 raeburn 5136: sub modify_scantron {
1.48 raeburn 5137: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 5138: my ($resulttext,%confhash,%changes,$errors);
5139: my $custom = 'custom.tab';
5140: my $default = 'default.tab';
5141: my $servadm = $r->dir_config('lonAdmEMail');
5142: my ($configuserok,$author_ok,$switchserver) =
5143: &config_check($dom,$confname,$servadm);
5144: if ($env{'form.scantronformat.filename'} ne '') {
5145: my $error;
5146: if ($configuserok eq 'ok') {
5147: if ($switchserver) {
5148: $error = &mt("Upload of scantron format file is not permitted to this server: [_1]",$switchserver);
5149: } else {
5150: if ($author_ok eq 'ok') {
5151: my ($result,$scantronurl) =
5152: &publishlogo($r,'upload','scantronformat',$dom,
5153: $confname,'scantron','','',$custom);
5154: if ($result eq 'ok') {
5155: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 5156: $changes{'scantronformat'} = 1;
1.46 raeburn 5157: } else {
5158: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
5159: }
5160: } else {
5161: $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);
5162: }
5163: }
5164: } else {
5165: $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);
5166: }
5167: if ($error) {
5168: &Apache::lonnet::logthis($error);
5169: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
5170: }
5171: }
1.48 raeburn 5172: if (ref($domconfig{'scantron'}) eq 'HASH') {
5173: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
5174: if ($env{'form.scantronformat_del'}) {
5175: $confhash{'scantron'}{'scantronformat'} = '';
5176: $changes{'scantronformat'} = 1;
1.46 raeburn 5177: }
5178: }
5179: }
5180: if (keys(%confhash) > 0) {
5181: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
5182: $dom);
5183: if ($putresult eq 'ok') {
5184: if (keys(%changes) > 0) {
1.48 raeburn 5185: if (ref($confhash{'scantron'}) eq 'HASH') {
5186: $resulttext = &mt('Changes made:').'<ul>';
5187: if ($confhash{'scantron'}{'scantronformat'} eq '') {
5188: $resulttext .= '<li>'.&mt('[_1] scantron format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
5189: } else {
5190: $resulttext .= '<li>'.&mt('Custom scantron format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 5191: }
1.48 raeburn 5192: $resulttext .= '</ul>';
5193: } else {
5194: $resulttext = &mt('Changes made to scantron format file.');
1.46 raeburn 5195: }
5196: $resulttext .= '</ul>';
5197: &Apache::loncommon::devalidate_domconfig_cache($dom);
5198: } else {
5199: $resulttext = &mt('No changes made to scantron format file');
5200: }
5201: } else {
5202: $resulttext = '<span class="LC_error">'.
5203: &mt('An error occurred: [_1]',$putresult).'</span>';
5204: }
5205: } else {
5206: $resulttext = &mt('No changes made to scantron format file');
5207: }
5208: if ($errors) {
5209: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5210: $errors.'</ul>';
5211: }
5212: return $resulttext;
5213: }
5214:
1.48 raeburn 5215: sub modify_coursecategories {
5216: my ($dom,%domconfig) = @_;
1.57 raeburn 5217: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
5218: $cathash);
1.48 raeburn 5219: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 5220: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 5221: $cathash = $domconfig{'coursecategories'}{'cats'};
5222: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
5223: $changes{'togglecats'} = 1;
5224: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
5225: }
5226: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
5227: $changes{'categorize'} = 1;
5228: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
5229: }
5230: } else {
5231: $changes{'togglecats'} = 1;
5232: $changes{'categorize'} = 1;
1.87 raeburn 5233: $domconfig{'coursecategories'} = {
5234: togglecats => $env{'form.togglecats'},
5235: categorize => $env{'form.categorize'},
5236: };
1.57 raeburn 5237: }
5238: if (ref($cathash) eq 'HASH') {
5239: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 5240: push (@deletecategory,'instcode::0');
5241: }
1.48 raeburn 5242: }
1.57 raeburn 5243: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
5244: if (ref($cathash) eq 'HASH') {
1.48 raeburn 5245: if (@deletecategory > 0) {
5246: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 5247: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 5248: foreach my $item (@deletecategory) {
1.57 raeburn 5249: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
5250: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 5251: $deletions{$item} = 1;
1.57 raeburn 5252: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 5253: }
5254: }
5255: }
1.57 raeburn 5256: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 5257: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 5258: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 5259: $reorderings{$item} = 1;
1.57 raeburn 5260: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 5261: }
5262: if ($env{'form.addcategory_name_'.$item} ne '') {
5263: my $newcat = $env{'form.addcategory_name_'.$item};
5264: my $newdepth = $depth+1;
5265: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 5266: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 5267: $adds{$newitem} = 1;
5268: }
5269: if ($env{'form.subcat_'.$item} ne '') {
5270: my $newcat = $env{'form.subcat_'.$item};
5271: my $newdepth = $depth+1;
5272: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 5273: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 5274: $adds{$newitem} = 1;
5275: }
5276: }
5277: }
5278: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 5279: if (ref($cathash) eq 'HASH') {
1.48 raeburn 5280: my $newitem = 'instcode::0';
1.57 raeburn 5281: if ($cathash->{$newitem} eq '') {
5282: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 5283: $adds{$newitem} = 1;
5284: }
5285: } else {
5286: my $newitem = 'instcode::0';
1.57 raeburn 5287: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 5288: $adds{$newitem} = 1;
5289: }
5290: }
5291: if ($env{'form.addcategory_name'} ne '') {
5292: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
1.57 raeburn 5293: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
1.48 raeburn 5294: $adds{$newitem} = 1;
5295: }
1.57 raeburn 5296: my $putresult;
1.48 raeburn 5297: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
5298: if (keys(%deletions) > 0) {
5299: foreach my $key (keys(%deletions)) {
5300: if ($predelallitems{$key} ne '') {
5301: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
5302: }
5303: }
5304: }
5305: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 5306: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 5307: if (ref($chkcats[0]) eq 'ARRAY') {
5308: my $depth = 0;
5309: my $chg = 0;
5310: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
5311: my $name = $chkcats[0][$i];
5312: my $item;
5313: if ($name eq '') {
5314: $chg ++;
5315: } else {
5316: $item = &escape($name).'::0';
5317: if ($chg) {
1.57 raeburn 5318: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 5319: }
5320: $depth ++;
1.57 raeburn 5321: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 5322: $depth --;
5323: }
5324: }
5325: }
1.57 raeburn 5326: }
5327: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
5328: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 5329: if ($putresult eq 'ok') {
1.57 raeburn 5330: my %title = (
5331: togglecats => 'Show/Hide a course in the catalog',
5332: categorize => 'Category assigned to course',
5333: );
5334: my %level = (
5335: dom => 'set from "Modify Course" (Domain)',
5336: crs => 'set from "Parameters" (Course)',
5337: );
1.48 raeburn 5338: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 5339: if ($changes{'togglecats'}) {
5340: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
5341: }
5342: if ($changes{'categorize'}) {
5343: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 5344: }
1.57 raeburn 5345: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
5346: my $cathash;
5347: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
5348: $cathash = $domconfig{'coursecategories'}{'cats'};
5349: } else {
5350: $cathash = {};
5351: }
5352: my (@cats,@trails,%allitems);
5353: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
5354: if (keys(%deletions) > 0) {
5355: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
5356: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
5357: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
5358: }
5359: $resulttext .= '</ul></li>';
5360: }
5361: if (keys(%reorderings) > 0) {
5362: my %sort_by_trail;
5363: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
5364: foreach my $key (keys(%reorderings)) {
5365: if ($allitems{$key} ne '') {
5366: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
5367: }
1.48 raeburn 5368: }
1.57 raeburn 5369: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
5370: $resulttext .= '<li>'.$trails[$trail].'</li>';
5371: }
5372: $resulttext .= '</ul></li>';
1.48 raeburn 5373: }
1.57 raeburn 5374: if (keys(%adds) > 0) {
5375: my %sort_by_trail;
5376: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
5377: foreach my $key (keys(%adds)) {
5378: if ($allitems{$key} ne '') {
5379: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
5380: }
5381: }
5382: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
5383: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 5384: }
1.57 raeburn 5385: $resulttext .= '</ul></li>';
1.48 raeburn 5386: }
5387: }
5388: $resulttext .= '</ul>';
5389: } else {
5390: $resulttext = '<span class="LC_error">'.
1.57 raeburn 5391: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 5392: }
5393: } else {
5394: $resulttext = &mt('No changes made to course categories');
5395: }
5396: return $resulttext;
5397: }
5398:
1.69 raeburn 5399: sub modify_serverstatuses {
5400: my ($dom,%domconfig) = @_;
5401: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
5402: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
5403: %currserverstatus = %{$domconfig{'serverstatuses'}};
5404: }
5405: my @pages = &serverstatus_pages();
5406: foreach my $type (@pages) {
5407: $newserverstatus{$type}{'namedusers'} = '';
5408: $newserverstatus{$type}{'machines'} = '';
5409: if (defined($env{'form.'.$type.'_namedusers'})) {
5410: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
5411: my @okusers;
5412: foreach my $user (@users) {
5413: my ($uname,$udom) = split(/:/,$user);
5414: if (($udom =~ /^$match_domain$/) &&
5415: (&Apache::lonnet::domain($udom)) &&
5416: ($uname =~ /^$match_username$/)) {
5417: if (!grep(/^\Q$user\E/,@okusers)) {
5418: push(@okusers,$user);
5419: }
5420: }
5421: }
5422: if (@okusers > 0) {
5423: @okusers = sort(@okusers);
5424: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
5425: }
5426: }
5427: if (defined($env{'form.'.$type.'_machines'})) {
5428: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
5429: my @okmachines;
5430: foreach my $ip (@machines) {
5431: my @parts = split(/\./,$ip);
5432: next if (@parts < 4);
5433: my $badip = 0;
5434: for (my $i=0; $i<4; $i++) {
5435: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
5436: $badip = 1;
5437: last;
5438: }
5439: }
5440: if (!$badip) {
5441: push(@okmachines,$ip);
5442: }
5443: }
5444: @okmachines = sort(@okmachines);
5445: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
5446: }
5447: }
5448: my %serverstatushash = (
5449: serverstatuses => \%newserverstatus,
5450: );
5451: my %changes;
5452: foreach my $type (@pages) {
1.83 raeburn 5453: foreach my $setting ('namedusers','machines') {
1.84 raeburn 5454: my (@current,@new);
1.83 raeburn 5455: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 5456: if ($currserverstatus{$type}{$setting} ne '') {
5457: @current = split(/,/,$currserverstatus{$type}{$setting});
5458: }
5459: }
5460: if ($newserverstatus{$type}{$setting} ne '') {
5461: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 5462: }
5463: if (@current > 0) {
5464: if (@new > 0) {
5465: foreach my $item (@current) {
5466: if (!grep(/^\Q$item\E$/,@new)) {
5467: $changes{$type}{$setting} = 1;
1.82 raeburn 5468: last;
5469: }
5470: }
1.84 raeburn 5471: foreach my $item (@new) {
5472: if (!grep(/^\Q$item\E$/,@current)) {
5473: $changes{$type}{$setting} = 1;
5474: last;
1.82 raeburn 5475: }
5476: }
5477: } else {
1.83 raeburn 5478: $changes{$type}{$setting} = 1;
1.69 raeburn 5479: }
1.83 raeburn 5480: } elsif (@new > 0) {
5481: $changes{$type}{$setting} = 1;
1.69 raeburn 5482: }
5483: }
5484: }
5485: if (keys(%changes) > 0) {
1.81 raeburn 5486: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 5487: my $putresult = &Apache::lonnet::put_dom('configuration',
5488: \%serverstatushash,$dom);
5489: if ($putresult eq 'ok') {
5490: $resulttext .= &mt('Changes made:').'<ul>';
5491: foreach my $type (@pages) {
1.84 raeburn 5492: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 5493: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 5494: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 5495: if ($newserverstatus{$type}{'namedusers'} eq '') {
5496: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
5497: } else {
5498: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
5499: }
1.84 raeburn 5500: }
5501: if ($changes{$type}{'machines'}) {
1.69 raeburn 5502: if ($newserverstatus{$type}{'machines'} eq '') {
5503: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
5504: } else {
5505: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
5506: }
5507:
5508: }
5509: $resulttext .= '</ul></li>';
5510: }
5511: }
5512: $resulttext .= '</ul>';
5513: } else {
5514: $resulttext = '<span class="LC_error">'.
5515: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
5516:
5517: }
5518: } else {
5519: $resulttext = &mt('No changes made to access to server status pages');
5520: }
5521: return $resulttext;
5522: }
5523:
1.48 raeburn 5524: sub recurse_check {
5525: my ($chkcats,$categories,$depth,$name) = @_;
5526: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
5527: my $chg = 0;
5528: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
5529: my $category = $chkcats->[$depth]{$name}[$j];
5530: my $item;
5531: if ($category eq '') {
5532: $chg ++;
5533: } else {
5534: my $deeper = $depth + 1;
5535: $item = &escape($category).':'.&escape($name).':'.$depth;
5536: if ($chg) {
5537: $categories->{$item} -= $chg;
5538: }
5539: &recurse_check($chkcats,$categories,$deeper,$category);
5540: $deeper --;
5541: }
5542: }
5543: }
5544: return;
5545: }
5546:
5547: sub recurse_cat_deletes {
5548: my ($item,$coursecategories,$deletions) = @_;
5549: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
5550: my $subdepth = $depth + 1;
5551: if (ref($coursecategories) eq 'HASH') {
5552: foreach my $subitem (keys(%{$coursecategories})) {
5553: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
5554: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
5555: delete($coursecategories->{$subitem});
5556: $deletions->{$subitem} = 1;
5557: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
5558: }
5559: }
5560: }
5561: return;
5562: }
5563:
1.3 raeburn 5564: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>