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