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