Annotation of loncom/interface/domainprefs.pm, revision 1.1
1.1 ! raeburn 1: # The LearningOnline Network with CAPA
! 2: # Handler to set domain-wide configuration settings
! 3: #
! 4: # Copyright Michigan State University Board of Trustees
! 5: #
! 6: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 7: #
! 8: # LON-CAPA is free software; you can redistribute it and/or modify
! 9: # it under the terms of the GNU General Public License as published by
! 10: # the Free Software Foundation; either version 2 of the License, or
! 11: # (at your option) any later version.
! 12: #
! 13: # LON-CAPA is distributed in the hope that it will be useful,
! 14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 16: # GNU General Public License for more details.
! 17: #
! 18: # You should have received a copy of the GNU General Public License
! 19: # along with LON-CAPA; if not, write to the Free Software
! 20: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
! 21: # /home/httpd/html/adm/gpl.txt
! 22: #
! 23: # http://www.lon-capa.org/
! 24: #
! 25: #
! 26: ###############################################################
! 27: ##############################################################
! 28:
! 29: package Apache::domainprefs;
! 30:
! 31: use strict;
! 32: use Apache::Constants qw(:common :http);
! 33: use Apache::lonnet;
! 34: use Apache::loncommon();
! 35: use Apache::lonhtmlcommon();
! 36: use Apache::lonlocal;
! 37: use LONCAPA();
! 38:
! 39: sub handler {
! 40: my $r=shift;
! 41: if ($r->header_only) {
! 42: &Apache::loncommon::content_type($r,'text/html');
! 43: $r->send_http_header;
! 44: return OK;
! 45: }
! 46:
! 47: my $dom = $env{'request.role.domain'};
! 48: my $domdesc = $Apache::lonnet::domaindescription{$dom};
! 49: if (&Apache::lonnet::allowed('mau',$dom)) {
! 50: &Apache::loncommon::content_type($r,'text/html');
! 51: $r->send_http_header;
! 52: } else {
! 53: $env{'user.error.msg'}=
! 54: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
! 55: return HTTP_NOT_ACCEPTABLE;
! 56: }
! 57: &Apache::lonhtmlcommon::clear_breadcrumbs();
! 58: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
! 59: ['phase']);
! 60: my $phase = $env{'form.phase'};
! 61: if ($phase eq '' || $phase eq 'start') {
! 62: &Apache::lonhtmlcommon::add_breadcrumb
! 63: ({href=>"javascript:changePage(document.$phase,'start')",
! 64: text=>"Choose an action"});
! 65: &print_main_menu($r,$dom,$domdesc);
! 66: } else {
! 67: &Apache::lonhtmlcommon::add_breadcrumb
! 68: ({href=>"javascript:changePage(document.$phase,'start')",
! 69: text=>"Choose an action"});
! 70: if ($phase eq 'login') {
! 71: &Apache::lonhtmlcommon::add_breadcrumb
! 72: ({href=>"javascript:changePage(document.$phase,'$phase')",
! 73: text=>"Configure Log-in page"});
! 74: &print_login($r,$phase,$dom)
! 75: } elsif ($phase eq 'configlogin') {
! 76: &Apache::lonhtmlcommon::add_breadcrumb
! 77: ({href=>"javascript:changePage(document.$phase,'login')",
! 78: text=>"Configure Log-in page"});
! 79: &Apache::lonhtmlcommon::add_breadcrumb
! 80: ({href=>"javascript:changePage(document.$phase,'$phase')",
! 81: text=>"Result"});
! 82: &modify_login($r,$phase,$dom,$domdesc);
! 83: } elsif ($phase eq 'quotas') {
! 84: &Apache::lonhtmlcommon::add_breadcrumb
! 85: ({href=>"javascript:changePage(document.$phase,'$phase')",
! 86: text=>"Default user quotas"});
! 87: &print_quotas($r,$phase,$dom);
! 88: } elsif ($phase eq 'configquotas') {
! 89: &Apache::lonhtmlcommon::add_breadcrumb
! 90: ({href=>"javascript:changePage(document.$phase,'quotas')",
! 91: text=>"Default user quotas"});
! 92: &Apache::lonhtmlcommon::add_breadcrumb
! 93: ({href=>"javascript:changePage(document.$phase,'$phase')",
! 94: text=>"Result"});
! 95: &modify_quotas($r,$phase,$dom,$domdesc);
! 96: } elsif ($phase eq 'autoenroll') {
! 97: &Apache::lonhtmlcommon::add_breadcrumb
! 98: ({href=>"javascript:changePage(document.$phase,'$phase')",
! 99: text=>"Configure Auto-enrollment"});
! 100: &print_autoenroll($r,$phase,$dom);
! 101: } elsif ($phase eq 'configenroll') {
! 102: &Apache::lonhtmlcommon::add_breadcrumb
! 103: ({href=>"javascript:changePage(document.$phase,'autoenroll')",
! 104: text=>"Configure Auto-enrollment"});
! 105: &Apache::lonhtmlcommon::add_breadcrumb
! 106: ({href=>"javascript:changePage(document.$phase,'$phase')",
! 107: text=>"Result"});
! 108: &modify_autoenroll($r,$phase,$dom,$domdesc);
! 109: } elsif ($phase eq 'autoupdate') {
! 110: &Apache::lonhtmlcommon::add_breadcrumb
! 111: ({href=>"javascript:changePage(document.$phase,'$phase')",
! 112: text=>"Configure Auto-update"});
! 113: &print_autoupdate($r,$phase,$dom);
! 114: } elsif ($phase eq 'configupdate') {
! 115: &Apache::lonhtmlcommon::add_breadcrumb
! 116: ({href=>"javascript:changePage(document.$phase,'quotas')",
! 117: text=>"Change settings"});
! 118: &Apache::lonhtmlcommon::add_breadcrumb
! 119: ({href=>"javascript:changePage(document.$phase,'$phase')",
! 120: text=>"Result"});
! 121: &modify_autoupdate($r,$phase,$dom,$domdesc);
! 122: }
! 123: }
! 124: &print_footer($r);
! 125: }
! 126:
! 127: sub print_main_menu {
! 128: my ($r,$dom,$domdesc) = @_;
! 129: my @menu =
! 130: (
! 131: { text => 'Log-in page options',
! 132: help => 'Domain_Log-in_Page',
! 133: phase => 'login',
! 134: },
! 135: { text => 'Default quotas for user portfolios',
! 136: help => 'Default_User_Quota',
! 137: phase => 'quotas',
! 138: },
! 139: { text => 'Auto-enrollment settings',
! 140: help => 'Domain_Auto_Enrollment',
! 141: phase => 'autoenroll',
! 142: },
! 143: { text => 'Auto-update settings',
! 144: help => 'Domain_Auto_Update',
! 145: phase => 'autoupdate',
! 146: },
! 147: );
! 148: my $menu_html = '';
! 149: foreach my $menu_item (@menu) {
! 150: $menu_html.='<p>';
! 151: $menu_html.='<font size="+1">';
! 152: if (exists($menu_item->{'url'})) {
! 153: $menu_html.=qq{<a href="$menu_item->{'url'}">};
! 154: } else {
! 155: $menu_html.=
! 156: qq{<a href="/adm/domainprefs?phase=$menu_item->{'phase'}">};
! 157: }
! 158: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
! 159: if (exists($menu_item->{'help'})) {
! 160: $menu_html.=
! 161: &Apache::loncommon::help_open_topic($menu_item->{'help'});
! 162: }
! 163: $menu_html.='</p>'.$/;
! 164: }
! 165: &print_header($r);
! 166: $r->print($menu_html);
! 167: return;
! 168: }
! 169:
! 170: sub print_header {
! 171: my ($r,$javascript_validations) = @_;
! 172: my $phase = "start";
! 173: if ( exists($env{'form.phase'}) ) {
! 174: $phase = $env{'form.phase'};
! 175: }
! 176: my $js = qq|
! 177: <script type="text/javascript">
! 178: function changePage(formname,newphase) {
! 179: formname.phase.value = newphase;
! 180: if (newphase == 'processparms') {
! 181: return;
! 182: }
! 183: formname.submit();
! 184: }
! 185: </script>
! 186: |;
! 187: $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings', $js));
! 188: my $bread_text = "Domain Settings";
! 189: $r->print(&Apache::lonhtmlcommon::breadcrumbs($bread_text));
! 190: return;
! 191: }
! 192:
! 193: sub print_footer {
! 194: my ($r) = @_;
! 195: $r->print('<br />'.&Apache::loncommon::end_page());
! 196: return;
! 197: }
! 198:
! 199: sub print_login {
! 200: my ($r,$phase,$dom) = @_;
! 201: my %domconfig = &Apache::lonnet::get_dom('configuration',
! 202: ['login'],$dom);
! 203: my $catalogon = ' checked="checked" ';
! 204: my $catalogoff;
! 205: my $adminmailon = ' ';
! 206: my $adminmailoff = ' checked="checked" ';
! 207: if (ref($domconfig{'login'}) eq 'HASH') {
! 208: if ($domconfig{'login'}{'coursecatalog'} eq '0') {
! 209: $catalogoff = $catalogon;
! 210: $catalogon = ' ';
! 211: }
! 212: if ($domconfig{'login'}{'adminmail'} eq '1') {
! 213: $adminmailon = $adminmailoff;
! 214: $adminmailoff = ' ';
! 215: }
! 216: }
! 217: &print_header($r);
! 218: my $datatable=&Apache::loncommon::start_data_table().
! 219: &Apache::loncommon::start_data_table_header_row().
! 220: '<th>'.&mt('Item').'</th><th>'.&mt('Selection').'</th>'.
! 221: &Apache::loncommon::end_data_table_header_row().
! 222: &Apache::loncommon::start_data_table_row().
! 223: '<td>'.&mt('Display Course Catalog link?').'</td>'.
! 224: '<td><nobr><input type="radio" name="coursecatalog"'.
! 225: $catalogon.' value="1" />'.&mt('Yes').' '.
! 226: '<input type="radio" name="coursecatalog"'.
! 227: $catalogoff.'value="0" />'.&mt('No').'</nobr></td>'.
! 228: &Apache::loncommon::end_data_table_row().
! 229: &Apache::loncommon::start_data_table_row().
! 230: '<td>'.&mt("Display Administrator's E-mail Address?").'</td>'.
! 231: '<td><nobr><input type="radio" name="adminmail"'. $adminmailon.' value="1" />'.&mt('Yes').' '.
! 232: '<input type="radio" name="adminmail"'.
! 233: $adminmailoff.'value="0" />'.&mt('No').'</nobr></td>'.
! 234: &Apache::loncommon::end_data_table_row().
! 235: &Apache::loncommon::start_data_table();
! 236: &print_form($r,$datatable,$phase,'configlogin','Change');
! 237: }
! 238:
! 239: sub modify_login {
! 240: my ($r,$phase,$dom,$domdesc) = @_;
! 241: my ($resulttext,%changes);
! 242: my %domconfig = &Apache::lonnet::get_dom('configuration',
! 243: ['login'],$dom);
! 244: my %title = ( coursecatalog => 'Display course catalog',
! 245: adminmail => 'Display administrator E-mail address');
! 246: my @offon = ('off','on');
! 247: my %loginhash = (
! 248: login => { coursecatalog => $env{'form.coursecatalog'},
! 249: adminmail => $env{'form.adminmail'},
! 250: }
! 251: );
! 252: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
! 253: $dom);
! 254: if ($putresult eq 'ok') {
! 255: if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
! 256: ($env{'form.coursecatalog'} eq '1')) {
! 257: $changes{'coursecatalog'} = 1;
! 258: } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
! 259: $domconfig{'login'}{'coursecatalog'} eq '1') &&
! 260: ($env{'form.coursecatalog'} eq '0')) {
! 261: $changes{'coursecatalog'} = 1;
! 262: }
! 263: if (($domconfig{'login'}{'adminmail'} eq '1') &&
! 264: ($env{'form.adminmail'} eq '0')) {
! 265: $changes{'adminmail'} = 1;
! 266: } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
! 267: $domconfig{'login'}{'adminmail'} eq '0') &&
! 268: ($env{'form.adminmail'} eq '1')) {
! 269: $changes{'adminmail'} = 1;
! 270: }
! 271: if (keys(%changes) > 0) {
! 272: $resulttext = &mt('Changes made:').'<ul>';
! 273: foreach my $item (sort(keys(%changes))) {
! 274: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
! 275: }
! 276: $resulttext .= '</ul>';
! 277: } else {
! 278: $resulttext = &mt('No changes made to log-in page settings');
! 279: }
! 280: } else {
! 281: $resulttext = &mt('An error occurred: [_1]',$putresult);
! 282: }
! 283: &print_header($r);
! 284: &print_form($r,$resulttext,$phase,'start','Back to actions menu');
! 285: }
! 286:
! 287: sub print_quotas {
! 288: my ($r,$phase,$dom) = @_;
! 289: my %currquota;
! 290: my %domconfig = &Apache::lonnet::get_dom('configuration',
! 291: ['quotas'],$dom);
! 292: if (ref($domconfig{'quotas'}) eq 'HASH') {
! 293: foreach my $key (keys(%{$domconfig{'quotas'}})) {
! 294: $currquota{$key} = $domconfig{'quotas'}{$key};
! 295: }
! 296: }
! 297: my $datatable=&Apache::loncommon::start_data_table().
! 298: &Apache::loncommon::start_data_table_header_row().
! 299: '<th>'.&mt('User type').'</th><th>'.&mt('Default quota').'</th>'.
! 300: &Apache::loncommon::end_data_table_header_row();
! 301: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
! 302: my $othertitle = "All users";
! 303: my @types;
! 304: if (ref($order) eq 'ARRAY') {
! 305: @types = @{$order};
! 306: }
! 307: if (@types == 0) {
! 308: if (ref($usertypes) eq 'HASH') {
! 309: @types = sort(keys(%{$usertypes}));
! 310: }
! 311: }
! 312: if (@types > 0) {
! 313: foreach my $type (@types) {
! 314: if (defined($usertypes->{$type})) {
! 315: $datatable .= &Apache::loncommon::start_data_table_row().
! 316: '<td>'.$usertypes->{$type}.'</td><td><nobr>'.
! 317: '<input type="text" name="quota_'.$type.
! 318: '" value="'.$currquota{$type}.
! 319: '" size="5" /> Mb</nobr></td>';
! 320: }
! 321: }
! 322: $othertitle = "Other users";
! 323: }
! 324: my $defaultquota = '20';
! 325: if (defined($currquota{'default'})) {
! 326: $defaultquota = $currquota{'default'};
! 327: }
! 328: $datatable .= &Apache::loncommon::start_data_table_row().
! 329: '<td>'.&mt($othertitle).'</td><td><nobr>'.
! 330: '<input type="text" name="default" value="'.
! 331: $defaultquota.'" size="5" /> Mb</nobr></td>'.
! 332: &Apache::loncommon::end_data_table_row().
! 333: &Apache::loncommon::end_data_table();
! 334: &print_header($r);
! 335: &print_form($r,$datatable,$phase,'configquotas','Change');
! 336: }
! 337:
! 338: sub modify_quotas {
! 339: my ($r,$phase,$dom,$domdesc) = @_;
! 340: my ($resulttext,%changes);
! 341: my %domconfig = &Apache::lonnet::get_dom('configuration',
! 342: ['quotas'],$dom);
! 343: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
! 344: my %formhash;
! 345: foreach my $key (keys(%env)) {
! 346: if ($key =~ /^form\.quota_(.+)$/) {
! 347: $formhash{$1} = $env{$key};
! 348: }
! 349: }
! 350: if (ref($domconfig{'quotas'}) eq 'HASH') {
! 351: foreach my $key (keys(%{$domconfig{'quotas'}})) {
! 352: if (exists($formhash{$key})) {
! 353: if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
! 354: $changes{$key} = 1;
! 355: }
! 356: } else {
! 357: $formhash{$key} = $domconfig{'quotas'}{$key};
! 358: }
! 359: }
! 360: }
! 361: foreach my $key (keys(%formhash)) {
! 362: if ($formhash{$key} ne '') {
! 363: if (!exists($domconfig{$key})) {
! 364: $changes{$key} = 1;
! 365: }
! 366: }
! 367: }
! 368: my %quotahash = (
! 369: quotas => {%formhash},
! 370: );
! 371: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
! 372: $dom);
! 373: if ($putresult eq 'ok') {
! 374: if (keys(%changes) > 0) {
! 375: $resulttext = &mt('Changes made:').'<ul>';
! 376: foreach my $item (sort(keys(%changes))) {
! 377: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$usertypes->{$item},$formhash{$item}).'</li>';
! 378: }
! 379: $resulttext .= '</ul>';
! 380: } else {
! 381: $resulttext = &mt('No changes made to default quotas');
! 382: }
! 383: } else {
! 384: $resulttext = &mt('An error occurred: [_1]',$putresult);
! 385: }
! 386: &print_header($r);
! 387: &print_form($r,$resulttext,$phase,'start','Back to actions menu');
! 388: }
! 389:
! 390: sub print_autoenroll {
! 391: my ($r,$phase,$dom) = @_;
! 392: my %currautoenroll;
! 393: my %domconfig = &Apache::lonnet::get_dom('configuration',
! 394: ['autoenroll'],$dom);
! 395: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
! 396: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
! 397: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
! 398: }
! 399: }
! 400: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
! 401: my ($runon,$runoff);
! 402: if (exists($currautoenroll{'run'})) {
! 403: if ($currautoenroll{'run'} eq '0') {
! 404: $runoff = ' checked="checked" ';
! 405: $runon = ' ';
! 406: } else {
! 407: $runon = ' checked="checked" ';
! 408: $runoff = ' ';
! 409: }
! 410: } else {
! 411: if ($autorun) {
! 412: $runon = ' checked="checked" ';
! 413: $runoff = ' ';
! 414: } else {
! 415: $runoff = ' checked="checked" ';
! 416: $runon = ' ';
! 417: }
! 418: }
! 419: my $defdom = $dom;
! 420: if (exists($currautoenroll{'sender_domain'})) {
! 421: $defdom = $currautoenroll{'sender_domain'};
! 422: }
! 423: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
! 424: my $datatable=&Apache::loncommon::start_data_table().
! 425: &Apache::loncommon::start_data_table_header_row().
! 426: '<th>'.&mt('Configuration setting').'</th><th>'.&mt('Value(s)').'</th>'.
! 427: &Apache::loncommon::end_data_table_header_row().
! 428: &Apache::loncommon::start_data_table_row().
! 429: '<td>'.&mt('Auto-enrollment active?').'</td>'. '<td><nobr><input type="radio" name="autoenroll_run"'.
! 430: $runon.' value="1" />'.&mt('Yes').' '.
! 431: '<input type="radio" name="autoenroll_run"'.
! 432: $runoff.'value="0" />'.&mt('No').'</nobr></td>'.
! 433: &Apache::loncommon::end_data_table_row().
! 434: &Apache::loncommon::start_data_table_row().
! 435: '<td>'.&mt('Notification messages - sender').'</td><td><nobr>'.
! 436: &mt('username').': <input type="text" name="sender_uname" value="'.
! 437: $currautoenroll{'sender_uname'}.'" size="10" /> '.&mt('domain').': '.$domform.'</nobr></td>'.
! 438: &Apache::loncommon::end_data_table_row().
! 439: &Apache::loncommon::end_data_table();
! 440: &print_header($r);
! 441: &print_form($r,$datatable,$phase,'configenroll','Change');
! 442: }
! 443:
! 444: sub modify_autoenroll {
! 445: my ($r,$phase,$dom,$domdesc) = @_;
! 446: my ($resulttext,%changes);
! 447: my %currautoenroll;
! 448: my %domconfig = &Apache::lonnet::get_dom('configuration',
! 449: ['autoenroll'],$dom);
! 450: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
! 451: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
! 452: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
! 453: }
! 454: }
! 455: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
! 456: my %title = ( run => 'Auto-enrollment active',
! 457: sender => 'Sender for notification messages');
! 458: my @offon = ('off','on');
! 459: my %autoenrollhash = (
! 460: autoenroll => { run => $env{'form.autoenroll_run'},
! 461: sender_uname => $env{'form.sender_uname'},
! 462: sender_domain => $env{'form.sender_domain'},
! 463:
! 464: }
! 465: );
! 466: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
! 467: $dom);
! 468: if ($putresult eq 'ok') {
! 469: if (exists($currautoenroll{'run'})) {
! 470: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
! 471: $changes{'run'} = 1;
! 472: }
! 473: } elsif ($autorun) {
! 474: if ($env{'form.autoenroll_run'} ne '1') {
! 475: $changes{'run'} = 1;
! 476: }
! 477: }
! 478: if (exists($currautoenroll{sender_uname})) {
! 479: if ($currautoenroll{'sender_uname'} ne $env{'form.sender_uname'}) {
! 480: $changes{'sender'} = 1;
! 481: }
! 482: } else {
! 483: $changes{'sender'} = 1;
! 484: }
! 485: if (exists($currautoenroll{sender_domain})) {
! 486: if ($currautoenroll{'sender_domain'} ne $env{'form.sender_domain'}) {
! 487: $changes{'sender'} = 1;
! 488: }
! 489: } else {
! 490: $changes{'sender'} = 1;
! 491: }
! 492: if (keys(%changes) > 0) {
! 493: $resulttext = &mt('Changes made:').'<ul>';
! 494: if ($changes{'run'}) {
! 495: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
! 496: }
! 497: if ($changes{'sender'}) {
! 498: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$env{'form.sender_uname'}.':'.$env{'form.sender_domain'}).'</li>';
! 499: }
! 500: $resulttext .= '</ul>';
! 501: } else {
! 502: $resulttext = &mt('No changes made to auto-enrollment settings');
! 503: }
! 504: } else {
! 505: $resulttext = &mt('An error occurred: [_1]',$putresult);
! 506: }
! 507: &print_header($r);
! 508: &print_form($r,$resulttext,$phase,'start','Back to actions menu');
! 509: }
! 510:
! 511: sub print_autoupdate {
! 512: my ($r,$phase,$dom) = @_;
! 513: my (%currautoupdate,$datatable);
! 514: my %domconfig = &Apache::lonnet::get_dom('configuration',
! 515: ['autoupdate'],$dom);
! 516: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
! 517: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
! 518: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
! 519: }
! 520: }
! 521: my $updateon = ' ';
! 522: my $updateoff = ' checked="checked" ';
! 523: if ($currautoupdate{'run'} eq '1') {
! 524: $updateon = $updateoff;
! 525: $updateoff = ' ';
! 526: }
! 527: my $classlistson = ' ';
! 528: my $classlistsoff = ' checked="checked" ';
! 529: if ($currautoupdate{'classlists'} eq '1') {
! 530: $classlistson = $classlistsoff;
! 531: $classlistsoff = ' ';
! 532: }
! 533: my %title = (
! 534: run => 'Auto-update enabled?',
! 535: classlists => 'Update information in classlists?',
! 536: );
! 537: $datatable = &Apache::loncommon::start_data_table().
! 538: &Apache::loncommon::start_data_table_header_row().
! 539: '<th>'.&mt('Setting').'</th><th>'.&mt('Value').'</th>'.
! 540: &Apache::loncommon::end_data_table_header_row().
! 541: &Apache::loncommon::start_data_table_row().
! 542: '<td>'.&mt($title{'run'}).'</td>'.
! 543: '<td><nobr><input type="radio" name="autoupdate_run"'.
! 544: $updateon.' value="1" />'.&mt('Yes').' '.
! 545: '<input type="radio" name="autoupdate_run"'.
! 546: $updateoff.'value="0" />'.&mt('No').'</nobr></td>'.
! 547: &Apache::loncommon::end_data_table_row().
! 548: &Apache::loncommon::start_data_table_row().
! 549: '<td>'.&mt($title{'classlists'}).'</td>'.
! 550: '<td><nobr><input type="radio" name="classlists"'.
! 551: $classlistson.' value="1" />'.&mt('Yes').' '.
! 552: '<input type="radio" name="classlists"'.
! 553: $classlistsoff.'value="0" />'.&mt('No').'</nobr></td>'.
! 554: &Apache::loncommon::end_data_table_row().
! 555: &Apache::loncommon::end_data_table().'<br /><br />';
! 556: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
! 557: my @types;
! 558: if (ref($order) eq 'ARRAY') {
! 559: @types = @{$order};
! 560: }
! 561: if (@types == 0) {
! 562: if (ref($usertypes) eq 'HASH') {
! 563: @types = sort(keys(%{$usertypes}));
! 564: }
! 565: }
! 566: my $othertitle = &mt('All users');
! 567: if (keys(%{$usertypes}) > 0) {
! 568: $othertitle = &mt('Other users');
! 569: }
! 570: my @fields = ('lastname','firstname','middlename','gen','email','id');
! 571: my $numinrow = 4;
! 572: my %fieldtitles = &Apache::lonlocal::texthash (
! 573: id => 'Student/Employee ID',
! 574: email => 'E-mail address',
! 575: lastname => 'Last Name',
! 576: firstname => 'First Name',
! 577: middlename => 'Middle Name',
! 578: gen => 'Generation',
! 579: );
! 580: $datatable .= &Apache::loncommon::start_data_table().
! 581: &Apache::loncommon::start_data_table_header_row().
! 582: '<th>'.&mt('User Population').'</th><th>'.&mt('Updateable user data').'</th>'.
! 583: &Apache::loncommon::end_data_table_header_row();
! 584: if (@types > 0) {
! 585: foreach my $type (@types) {
! 586: if (defined($usertypes->{$type})) {
! 587: $datatable .= &Apache::loncommon::start_data_table_row().
! 588: '<td>'.$usertypes->{$type}.'</td><td><table>';
! 589: for (my $i=0; $i<@fields; $i++) {
! 590: my $rem = $i%($numinrow);
! 591: if ($rem == 0) {
! 592: if ($i > 0) {
! 593: $datatable .= '</tr>';
! 594: }
! 595: $datatable .= '<tr>';
! 596: }
! 597: my $check = ' ';
! 598: if (ref($currautoupdate{'fields'}) eq 'HASH') {
! 599: if (ref($currautoupdate{'fields'}{$type}) eq 'ARRAY') {
! 600: if (grep(/^\Q$fields[$i]\E$/,@{$currautoupdate{'fields'}{$type}})) {
! 601: $check = ' checked="checked" ';
! 602: }
! 603: }
! 604: }
! 605: if ($i == @fields-1) {
! 606: my $colsleft = $numinrow - $rem;
! 607: if ($colsleft > 1) {
! 608: $datatable .= '<td colspan="'.$colsleft.'">';
! 609: } else {
! 610: $datatable .= '<td>';
! 611: }
! 612: } else {
! 613: $datatable .= '<td>';
! 614: }
! 615: $datatable .= '<nobr><input type="checkbox" name="updateable_'.
! 616: $type.'_'.$fields[$i].'" '.
! 617: '" value="1"'.$check.'/>'.
! 618: $fieldtitles{$fields[$i]}.'</nobr></td>';
! 619: }
! 620: $datatable .= '</tr></table></td>'.&Apache::loncommon::end_data_table_row();
! 621: }
! 622: }
! 623: }
! 624: $datatable .= &Apache::loncommon::start_data_table_row().
! 625: '<td>'.&mt($othertitle).'</td><td><table>';
! 626: for (my $i=0; $i<@fields; $i++) {
! 627: my $rem = $i%($numinrow);
! 628: if ($rem == 0) {
! 629: if ($i > 0) {
! 630: $datatable .= '</tr>';
! 631: }
! 632: $datatable .= '<tr>';
! 633: }
! 634: my $check = ' ';
! 635: if (ref($currautoupdate{'fields'}) eq 'HASH') {
! 636: if (ref($currautoupdate{'fields'}{'default'}) eq 'ARRAY') {
! 637: if (grep(/^\Q$fields[$i]\E$/,@{$currautoupdate{'fields'}{'default'}})) {
! 638: $check = ' checked="checked" ';
! 639: }
! 640: }
! 641: }
! 642: if ($i == @fields-1) {
! 643: my $colsleft = $numinrow - $rem;
! 644: if ($colsleft > 1) {
! 645: $datatable .= '<td colspan="'.$colsleft.'">';
! 646: } else {
! 647: $datatable .= '<td>';
! 648: }
! 649: } else {
! 650: $datatable .= '<td>';
! 651: }
! 652: $datatable .= '<nobr><input type="checkbox" name="updateable_default_'.
! 653: $fields[$i].'" value="1"'.$check.'/>'.
! 654: $fieldtitles{$fields[$i]}.'</nobr></td>';
! 655: }
! 656: $datatable .= '</tr></table></td>'.
! 657: &Apache::loncommon::end_data_table_row().
! 658: &Apache::loncommon::end_data_table();
! 659: &print_header($r);
! 660: &print_form($r,$datatable,$phase,'configupdate','Change');
! 661: }
! 662:
! 663: sub modify_autoupdate {
! 664: my ($r,$phase,$dom,$domdesc) = @_;
! 665: my ($resulttext,%currautoupdate,%fields,%changes);
! 666: my %domconfig = &Apache::lonnet::get_dom('configuration',
! 667: ['autoupdate'],$dom);
! 668: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
! 669: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
! 670: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
! 671: }
! 672: }
! 673: my @offon = ('off','on');
! 674: my %title = &Apache::lonlocal::texthash (
! 675: run => 'Auto-update:',
! 676: classlists => 'Updates to user information in classlists?'
! 677: );
! 678: my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
! 679: my %fieldtitles = &Apache::lonlocal::texthash (
! 680: id => 'Student/Employee ID',
! 681: email => 'E-mail address',
! 682: lastname => 'Last Name',
! 683: firstname => 'First Name',
! 684: middlename => 'Middle Name',
! 685: gen => 'Generation',
! 686: );
! 687: my $othertitle = &mt('All users');
! 688: if (keys(%{$usertypes}) > 0) {
! 689: $othertitle = "Other users";
! 690: }
! 691: foreach my $key (keys(%env)) {
! 692: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
! 693: push(@{$fields{$1}},$2);
! 694: }
! 695: }
! 696: my %updatehash = (
! 697: autoupdate => { run => $env{'form.autoupdate_run'},
! 698: classlists => $env{'form.classlists'},
! 699: fields => {%fields},
! 700: }
! 701: );
! 702: foreach my $key (keys(%currautoupdate)) {
! 703: if (($key eq 'run') || ($key eq 'classlists')) {
! 704: if (exists($updatehash{autoupdate}{$key})) {
! 705: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
! 706: $changes{$key} = 1;
! 707: }
! 708: }
! 709: } elsif ($key eq 'fields') {
! 710: if (ref($currautoupdate{$key}) eq 'HASH') {
! 711: foreach my $item (keys(%{$currautoupdate{$key}})) {
! 712: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
! 713: my $change = 0;
! 714: foreach my $type (@{$currautoupdate{$key}{$item}}) {
! 715: if (!exists($fields{$item})) {
! 716: $change = 1;
! 717: } elsif (ref($fields{$item}) eq 'ARRAY') {
! 718: if (!grep/^\Q$type\E$/,@{$fields{$item}}) {
! 719: $change = 1;
! 720: }
! 721: }
! 722: }
! 723: if ($change) {
! 724: push(@{$changes{$key}},$item);
! 725: }
! 726: }
! 727: }
! 728: }
! 729: }
! 730: }
! 731: foreach my $key (keys(%fields)) {
! 732: if (ref($currautoupdate{'fields'}) eq 'HASH') {
! 733: if (!exists($currautoupdate{'fields'}{$key})) {
! 734: push(@{$changes{'fields'}},$key);
! 735: }
! 736: } else {
! 737: push(@{$changes{'fields'}},$key);
! 738: }
! 739: }
! 740: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
! 741: $dom);
! 742: if ($putresult eq 'ok') {
! 743: if (keys(%changes) > 0) {
! 744: $resulttext = &mt('Changes made:').'<ul>';
! 745: foreach my $key (sort(keys(%changes))) {
! 746: if (ref($changes{$key}) eq 'ARRAY') {
! 747: foreach my $item (@{$changes{$key}}) {
! 748: my @newvalues;
! 749: foreach my $type (@{$fields{$item}}) {
! 750: push(@newvalues,$fieldtitles{$type});
! 751: }
! 752: my $newvaluestr = join(', ',@newvalues);
! 753: if ($item eq 'default') {
! 754: $resulttext .= '<li>'.&mt("Updates for $othertitle set to: [_1]",$newvaluestr).'</li>';
! 755: } else {
! 756: $resulttext .= '<li>'.&mt("Updates for [_1] set to: [_2]",$usertypes->{$item},$newvaluestr).'</li>';
! 757: }
! 758: }
! 759: } else {
! 760: my $newvalue;
! 761: if ($key eq 'run') {
! 762: $newvalue = $offon[$env{'form.autoupdate_run'}];
! 763: } else {
! 764: $newvalue = $offon[$env{'form.'.$key}];
! 765: }
! 766: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
! 767: }
! 768: }
! 769: $resulttext .= '</ul>';
! 770: } else {
! 771: $resulttext = &mt('No changes made to default quotas');
! 772: }
! 773: } else {
! 774: $resulttext = &mt('An error occurred: [_1]',$putresult);
! 775: }
! 776: &print_header($r);
! 777: &print_form($r,$resulttext,$phase,'start','Back to actions menu');
! 778: }
! 779:
! 780: sub print_form {
! 781: my ($r,$datatable,$phase,$newphase,$button_text) = @_;
! 782: my $button_text = &mt($button_text);
! 783: $r->print(<<ENDDOCUMENT);
! 784: <form action="/adm/domainprefs" method="post" name="$phase">
! 785: <br />
! 786: $datatable
! 787: <br />
! 788: <input type="hidden" name="phase" value="" />
! 789: <input type="button" name="store" value="$button_text" onclick="javascript:changePage(document.$phase,'$newphase')" />
! 790: </form>
! 791: ENDDOCUMENT
! 792: return;
! 793: }
! 794:
! 795: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>