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