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