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