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