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