Annotation of loncom/interface/lonmodifycourse.pm, revision 1.52

1.20      albertel    1: # The LearningOnline Network with CAPA
1.28      raeburn     2: # handler for DC-only modifiable course settings
1.20      albertel    3: #
1.52    ! raeburn     4: # $Id: lonmodifycourse.pm,v 1.51 2010/03/15 19:10:59 raeburn Exp $
1.20      albertel    5: #
1.3       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: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       raeburn    28: package Apache::lonmodifycourse;
                     29: 
                     30: use strict;
                     31: use Apache::Constants qw(:common :http);
                     32: use Apache::lonnet;
                     33: use Apache::loncommon;
1.28      raeburn    34: use Apache::lonhtmlcommon;
1.1       raeburn    35: use Apache::lonlocal;
1.36      raeburn    36: use Apache::lonuserutils;
1.28      raeburn    37: use Apache::lonpickcourse;
1.1       raeburn    38: use lib '/home/httpd/lib/perl';
1.25      www        39: use LONCAPA;
1.1       raeburn    40: 
1.28      raeburn    41: sub get_dc_settable {
1.48      raeburn    42:     my ($type) = @_;
                     43:     if ($type eq 'Community') {
                     44:         return ('courseowner');
                     45:     } else {
                     46:         return ('courseowner','coursecode','authtype','autharg');
                     47:     }
                     48: }
                     49: 
                     50: sub autoenroll_keys {
                     51:     my $internals = ['coursecode','courseowner','authtype','autharg','autoadds','autodrops',
1.50      raeburn    52:                          'autostart','autoend','sectionnums','crosslistings',
                     53:                          'co-owners'];
1.48      raeburn    54:     my $accessdates = ['default_enrollment_start_date','default_enrollment_end_date'];
                     55:     return ($internals,$accessdates);
1.28      raeburn    56: }
                     57: 
1.38      raeburn    58: sub catalog_settable {
1.49      raeburn    59:     my ($confhash,$type) = @_;
1.38      raeburn    60:     my @settable;
                     61:     if (ref($confhash) eq 'HASH') {
1.49      raeburn    62:         if ($type eq 'Community') {
                     63:             if ($confhash->{'togglecatscomm'} ne 'comm') {
                     64:                 push(@settable,'togglecats');
                     65:             }
                     66:             if ($confhash->{'categorizecomm'} ne 'comm') {
                     67:                 push(@settable,'categorize');
                     68:             }
                     69:         } else {
                     70:             if ($confhash->{'togglecats'} ne 'crs') {
                     71:                 push(@settable,'togglecats');
                     72:             }
                     73:             if ($confhash->{'categorize'} ne 'crs') {
                     74:                 push(@settable,'categorize');
                     75:             }
1.38      raeburn    76:         }
                     77:     } else {
                     78:         push(@settable,('togglecats','categorize'));
                     79:     }
                     80:     return @settable;
                     81: }
                     82: 
1.28      raeburn    83: sub get_enrollment_settings {
                     84:     my ($cdom,$cnum) = @_;
1.48      raeburn    85:     my ($internals,$accessdates) = &autoenroll_keys();
                     86:     my @items;
                     87:     if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) { 
                     88:         @items = map { 'internal.'.$_; } (@{$internals});
                     89:         push(@items,@{$accessdates});
                     90:     }
                     91:     my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
1.28      raeburn    92:     my %enrollvar;
                     93:     $enrollvar{'autharg'} = '';
                     94:     $enrollvar{'authtype'} = '';
1.48      raeburn    95:     foreach my $item (keys(%settings)) {
1.28      raeburn    96:         if ($item =~ m/^internal\.(.+)$/) {
                     97:             my $type = $1;
                     98:             if ( ($type eq "autoadds") || ($type eq "autodrops") ) {
                     99:                 if ($settings{$item} == 1) {
                    100:                     $enrollvar{$type} = "ON";
                    101:                 } else {
                    102:                     $enrollvar{$type} = "OFF";
1.10      raeburn   103:                 }
1.28      raeburn   104:             } elsif ( ($type eq "autostart") || ($type eq "autoend") ) {
                    105:                 if ( ($type eq "autoend") && ($settings{$item} == 0) ) {
1.48      raeburn   106:                     $enrollvar{$type} = &mt('No end date');
1.28      raeburn   107:                 } else {
1.48      raeburn   108:                     $enrollvar{$type} = &Apache::lonlocal::locallocaltime($settings{$item});
1.14      raeburn   109:                 }
1.50      raeburn   110:             } elsif (($type eq 'sectionnums') || ($type eq 'co-owners')) {
1.28      raeburn   111:                 $enrollvar{$type} = $settings{$item};
                    112:                 $enrollvar{$type} =~ s/,/, /g;
                    113:             } elsif ($type eq "authtype"
                    114:                      || $type eq "autharg"    || $type eq "coursecode"
                    115:                      || $type eq "crosslistings") {
                    116:                 $enrollvar{$type} = $settings{$item};
                    117:             } elsif ($type eq 'courseowner') {
                    118:                 if ($settings{$item} =~ /^[^:]+:[^:]+$/) {
                    119:                     $enrollvar{$type} = $settings{$item};
                    120:                 } else {
                    121:                     if ($settings{$item} ne '') {
                    122:                         $enrollvar{$type} = $settings{$item}.':'.$cdom;
1.26      raeburn   123:                     }
1.1       raeburn   124:                 }
1.28      raeburn   125:             }
                    126:         } elsif ($item =~ m/^default_enrollment_(start|end)_date$/) {
                    127:             my $type = $1;
                    128:             if ( ($type eq 'end') && ($settings{$item} == 0) ) {
1.48      raeburn   129:                 $enrollvar{$item} = &mt('No end date');
1.28      raeburn   130:             } elsif ( ($type eq 'start') && ($settings{$item} eq '') ) {
                    131:                 $enrollvar{$item} = 'When enrolled';
                    132:             } else {
1.48      raeburn   133:                 $enrollvar{$item} = &Apache::lonlocal::locallocaltime($settings{$item});
1.1       raeburn   134:             }
                    135:         }
                    136:     }
1.28      raeburn   137:     return %enrollvar;
                    138: }
                    139: 
                    140: sub print_course_search_page {
                    141:     my ($r,$dom,$domdesc) = @_;
1.48      raeburn   142:     my $action = '/adm/modifycourse';
                    143:     my $type = $env{'form.type'};
                    144:     if (!defined($env{'form.type'})) {
                    145:         $type = 'Course';
                    146:     }
                    147:     &print_header($r,$type);
1.28      raeburn   148:     my $filterlist = ['descriptfilter',
                    149:                       'instcodefilter','ownerfilter',
1.44      raeburn   150:                       'coursefilter'];
1.28      raeburn   151:     my $filter = {};
1.48      raeburn   152:     my ($numtitles,$cctitle,$dctitle);
                    153:     my $ccrole = 'cc';
                    154:     if ($type eq 'Community') {
                    155:         $ccrole = 'co';
1.46      raeburn   156:     }
1.48      raeburn   157:     $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.46      raeburn   158:     $dctitle = &Apache::lonnet::plaintext('dc');
                    159:     $r->print(&Apache::lonpickcourse::js_changer());
1.48      raeburn   160:     if ($type eq 'Community') {
                    161:         $r->print('<h3>'.&mt('Search for a community in the [_1] domain',$domdesc).'</h3>');
                    162:     } else {
                    163:         $r->print('<h3>'.&mt('Search for a course in the [_1] domain',$domdesc).'</h3>');
1.46      raeburn   164:     }   
1.28      raeburn   165:     $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
1.44      raeburn   166:                              undef,undef,$filter,$action,\$numtitles,'modifycourse'));
1.48      raeburn   167:     if ($type eq 'Community') {
                    168:         $r->print(&mt('Actions available after searching for a community:').'<ul>'.
                    169:                   '<li>'.&mt('Enter the community with the role of [_1]',$cctitle).'</li>'."\n".
                    170:                   '<li>'.&mt('View or modify community settings which only a [_1] may modify.',$dctitle).
                    171:                   '</li>'."\n".'</ul>');
                    172:     } else {
                    173:         $r->print(&mt('Actions available after searching for a course:').'<ul>'.
                    174:                   '<li>'.&mt('Enter the course with the role of [_1]',$cctitle).'</li>'."\n".
                    175:                   '<li>'.&mt('View or modify course settings which only a [_1] may modify.',$dctitle).
                    176:                   '</li>'."\n".'</ul>');
                    177:     }
1.28      raeburn   178: }
                    179: 
                    180: sub print_course_selection_page {
                    181:     my ($r,$dom,$domdesc) = @_;
1.48      raeburn   182:     my $type = $env{'form.type'};
                    183:     if (!defined($type)) {
                    184:         $type = 'Course';
                    185:     }
                    186:     &print_header($r,$type);
1.28      raeburn   187: 
                    188: # Criteria for course search 
                    189:     my $filterlist = ['descriptfilter',
                    190:                       'instcodefilter','ownerfilter',
                    191:                       'ownerdomfilter','coursefilter'];
                    192:     my %filter;
                    193:     my $action = '/adm/modifycourse';
                    194:     my $dctitle = &Apache::lonnet::plaintext('dc');
1.46      raeburn   195:     my $numtitles;
                    196:     $r->print(&Apache::lonpickcourse::js_changer());
1.48      raeburn   197:     $r->print(&mt('Revise your search criteria for this domain').' ('.$domdesc.').<br />');
1.28      raeburn   198:     $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
1.46      raeburn   199:                                        undef,undef,\%filter,$action,\$numtitles));
1.28      raeburn   200:     $filter{'domainfilter'} = $dom;
                    201:     my %courses = &Apache::lonpickcourse::search_courses($r,$type,0,
1.46      raeburn   202:                                                          \%filter,$numtitles);
                    203:     &Apache::lonpickcourse::display_matched_courses($r,$type,0,$action,undef,undef,undef,
1.28      raeburn   204:                                                     %courses);
1.1       raeburn   205:     return;
                    206: }
                    207: 
1.28      raeburn   208: sub print_modification_menu {
1.48      raeburn   209:     my ($r,$cdesc,$domdesc,$dom,$type) = @_;
                    210:     &print_header($r,$type);
                    211:     my ($ccrole,$setquota_text,$setparams_text,$cat_text);
                    212:     if ($type eq 'Community') {
                    213:         $ccrole = 'co';
                    214:     } else {
                    215:         $ccrole = 'cc';
                    216:     } 
1.37      raeburn   217:     my $action = '/adm/modifycourse';
1.48      raeburn   218:     if ($type eq 'Community') {
                    219:         $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a community.');
                    220:         $setparams_text = 'View/Modify community owner';
                    221:         $cat_text = 'View/Modify catalog settings for community';
                    222:     } else {
                    223:         $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a course.');
                    224:         $setparams_text = 'View/Modify course owner, institutional code, and default authentication';
                    225:         $cat_text = 'View/Modify catalog settings for course'; 
                    226:     }
1.28      raeburn   227:     my @menu =
                    228:         (
1.48      raeburn   229:           { text => $setparams_text,
                    230:              phase => 'setparms',
                    231:           },
                    232:           { text  => 'View/Modify quota for group portfolio files',
1.28      raeburn   233:             phase => 'setquota',
1.48      raeburn   234:           }
                    235:     );
1.38      raeburn   236:     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
1.49      raeburn   237:     my @additional_params = &catalog_settable($domconf{'coursecategories'},$type);
1.38      raeburn   238:     if (@additional_params > 0) {
1.48      raeburn   239:         push (@menu, { text => $cat_text,
1.38      raeburn   240:                        phase => 'catsettings',
                    241:                      });
                    242:     }
1.48      raeburn   243:     unless ($type eq 'Community') {
                    244:         push(@menu,
                    245:            { text  => 'Display current settings for automated enrollment',
                    246:             phase => 'viewparms',
                    247:            }
                    248:         );
                    249:     }
                    250:     my $menu_html = '<h3>'.&mt('View/Modify settings for: ').
                    251:                     ' <span class="LC_nobreak">'.$cdesc.'</span></h3>'."\n";
                    252:     if ($type eq 'Community') {
                    253:         $menu_html .= &mt('Although almost all community settings can be modified by a Coordinator, the following may only be set or modified by a Domain Coordinator:');
                    254:     } else {
                    255:         $menu_html .= &mt('Although almost all course settings can be modified by a Course Coordinator, the following may only be set or modified by a Domain Coordinator:');
                    256:     }
                    257:     $menu_html .= '<ul>';
                    258:     if ($type eq 'Community') {
                    259:         $menu_html .= '<li>'.&mt('Community owner (permitted to assign Coordinator roles in the community).').'</li>';
                    260:     } else {
                    261:         $menu_html .=  '<li>'.&mt('Course owner (permitted to assign Course Coordinator roles in the course).').'</li>'.
                    262:                        '<li>'.&mt("Institutional code and default authentication (both required for auto-enrollment of students from institutional datafeeds).").'</li>';
                    263:     }
                    264:     $menu_html .= '<li>'.$setquota_text.'</li>'."\n";
1.38      raeburn   265:     foreach my $item (@additional_params) {
1.48      raeburn   266:         if ($type eq 'Community') {
                    267:             if ($item eq 'togglecats') {
                    268:                 $menu_html .= '  <li>'.&mt('Hiding/unhiding a community from the catalog (although can be [_1]configured[_2] to be modifiable by a Coordinator in community context).','<a href="/adm/domainprefs?actions=coursecategories&phase=display">','</a>').'</li>'."\n";
                    269:             } elsif ($item eq 'categorize') {
                    270:                 $menu_html .= '  <li>'.&mt('Manual cataloging of a community (although can be [_1]configured[_2] to be modifiable by a Coordinator in community context).','<a href="/adm/domainprefs?actions=coursecategories&phase=display">','</a>').'</li>'."\n";
                    271:             }
                    272:         } else {
                    273:             if ($item eq 'togglecats') {
                    274:                 $menu_html .= '  <li>'.&mt('Hiding/unhiding a course from the course catalog (although can be [_1]configured[_2] to be modifiable by a Course Coordinator in course context).','<a href="/adm/domainprefs?actions=coursecategories&phase=display">','</a>').'</li>'."\n";
                    275:             } elsif ($item eq 'categorize') {
                    276:                 $menu_html .= '  <li>'.&mt('Manual cataloging of a course (although can be [_1]configured[_2] to be modifiable by a Course Coordinator in course context).','<a href="/adm/domainprefs?actions=coursecategories&phase=display">','</a>').'</li>'."\n";
                    277:             }
1.38      raeburn   278:         }
                    279:     }
                    280:     $menu_html .= ' </ul>
1.37      raeburn   281: <form name="menu" method="post" action="'.$action.'" />'."\n".
                    282:     &hidden_form_elements();
1.28      raeburn   283:     foreach my $menu_item (@menu) {
1.48      raeburn   284:         $menu_html.='<h3>';
1.28      raeburn   285:         $menu_html.=
                    286:                 qq|<a href="javascript:changePage(document.menu,'$menu_item->{'phase'}')">|;
1.48      raeburn   287:         $menu_html.= &mt($menu_item->{'text'}).'</a>';
                    288:         $menu_html.='</h3>';
1.3       raeburn   289:     }
1.28      raeburn   290:     
                    291:     $r->print($menu_html);
                    292:     return;
                    293: }
                    294: 
1.37      raeburn   295: sub print_ccrole_selected {
1.48      raeburn   296:     my ($r,$type) = @_;
                    297:     &print_header($r,$type);
1.37      raeburn   298:     my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
                    299:     $r->print('<form name="ccrole" method="post" action="/adm/roles">
                    300: <input type="hidden" name="selectrole" value="1" />
                    301: <input type="hidden" name="newrole" value="cc./'.$cdom.'/'.$cnum.'" />
                    302: </form>');
                    303: }
                    304: 
1.28      raeburn   305: sub print_settings_display {
                    306:     my ($r,$cdom,$cnum,$cdesc,$type) = @_;
                    307:     my %enrollvar = &get_enrollment_settings($cdom,$cnum);
1.48      raeburn   308:     my %longtype = &course_settings_descrip($type);
1.28      raeburn   309:     my %lt = &Apache::lonlocal::texthash(
1.48      raeburn   310:             'valu' => 'Current value',
                    311:             'cour' => 'Current settings are:',
                    312:             'cose' => "Settings which control auto-enrollment using classlists from your institution's student information system fall into two groups:",
                    313:             'dcon' => 'Modifiable only by Domain Coordinator',
                    314:             'back' => 'Pick another action',
1.28      raeburn   315:     );
1.48      raeburn   316:     my $ccrole = 'cc';
                    317:     if ($type eq 'Community') {
                    318:        $ccrole = 'co';
                    319:     }
                    320:     my $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.28      raeburn   321:     my $dctitle = &Apache::lonnet::plaintext('dc');
1.48      raeburn   322:     my @modifiable_params = &get_dc_settable($type);
                    323:     my ($internals,$accessdates) = &autoenroll_keys();
                    324:     my @items;
                    325:     if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) {
                    326:         @items =  (@{$internals},@{$accessdates});
                    327:     }
1.28      raeburn   328:     my $disp_table = &Apache::loncommon::start_data_table()."\n".
                    329:                      &Apache::loncommon::start_data_table_header_row()."\n".
1.48      raeburn   330:                      "<th>&nbsp;</th>\n".
1.28      raeburn   331:                      "<th>$lt{'valu'}</th>\n".
                    332:                      "<th>$lt{'dcon'}</th>\n".
                    333:                      &Apache::loncommon::end_data_table_header_row()."\n";
1.48      raeburn   334:     foreach my $item (@items) {
1.28      raeburn   335:         $disp_table .= &Apache::loncommon::start_data_table_row()."\n".
1.48      raeburn   336:                        "<td><b>$longtype{$item}</b></td>\n".
                    337:                        "<td>$enrollvar{$item}</td>\n";
                    338:         if (grep(/^\Q$item\E$/,@modifiable_params)) {
1.50      raeburn   339:             $disp_table .= '<td align="right">'.&mt('Yes').'</td>'."\n";
1.28      raeburn   340:         } else {
1.48      raeburn   341:             $disp_table .= '<td align="right">'.&mt('No').'</td>'."\n";
1.28      raeburn   342:         }
                    343:         $disp_table .= &Apache::loncommon::end_data_table_row()."\n";
1.3       raeburn   344:     }
1.28      raeburn   345:     $disp_table .= &Apache::loncommon::end_data_table()."\n";
1.48      raeburn   346:     &print_header($r,$type);
                    347:     my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
                    348:     my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
                    349:                                          '=1&destinationurl=/adm/populate','&<>"'); 
                    350:     $r->print('<h3>'.&mt('Current automated enrollment settings for:').
                    351:               ' <span class="LC_nobreak">'.$cdesc.'</span></h3>'.
                    352:               '<form action="/adm/modifycourse" method="post" name="viewparms">'."\n".
                    353:               '<p>'.$lt{'cose'}.'<ul>'.
                    354:               '<li>'.&mt('Settings modifiable by a [_1] via the [_2]Automated Enrollment Manager[_3] in a course.',$cctitle,'<a href="'.$escuri.'">','</a>').'</li>'.
                    355:               '<li>'.&mt('Settings modifiable by a [_1] via [_2]View/Modify course owner, institutional code, and default authentication[_3].',$dctitle,'<a href="javascript:changePage(document.viewparms,'."'setparms'".');">','</a>')."\n".
                    356:               '</li></ul></p>'.
                    357:               '<p>'.$lt{'cour'}.'</p><p>'.$disp_table.'</p><p>'.
                    358:               '<a href="javascript:changePage(document.viewparms,'."'menu'".')">'.$lt{'back'}.'</a>'."\n".
                    359:               &hidden_form_elements().
                    360:               '</p></form>'
                    361:      );
1.28      raeburn   362: }
1.3       raeburn   363: 
1.28      raeburn   364: sub print_setquota {
                    365:     my ($r,$cdom,$cnum,$cdesc,$type) = @_;
                    366:     my %lt = &Apache::lonlocal::texthash(
1.48      raeburn   367:                 'cquo' => 'Disk space for storage of group portfolio files for:',
1.28      raeburn   368:                 'gpqu' => 'Course portfolio files disk space',
1.42      schafran  369:                 'modi' => 'Save',
1.48      raeburn   370:                 'back' => 'Pick another action',
1.28      raeburn   371:     );
1.48      raeburn   372:     if ($type eq 'Community') {
                    373:         $lt{'gpqu'} = &mt('Community portfolio files disk space');
                    374:     }
1.28      raeburn   375:     my %settings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
                    376:     my $coursequota = $settings{'internal.coursequota'};
                    377:     if ($coursequota eq '') {
                    378:         $coursequota = 20;
1.3       raeburn   379:     }
1.48      raeburn   380:     &print_header($r,$type);
1.28      raeburn   381:     my $hidden_elements = &hidden_form_elements();
1.48      raeburn   382:     my $helpitem = &Apache::loncommon::help_open_topic('Modify_Course_Quota');
1.28      raeburn   383:     $r->print(<<ENDDOCUMENT);
                    384: <form action="/adm/modifycourse" method="post" name="setquota">
1.48      raeburn   385: <h3>$lt{'cquo'} <span class="LC_nobreak">$cdesc</span></h3>
1.28      raeburn   386: <p>
1.48      raeburn   387: $helpitem $lt{'gpqu'}: <input type="text" size="4" name="coursequota" value="$coursequota" /> Mb &nbsp;&nbsp;&nbsp;&nbsp;
1.28      raeburn   388: <input type="button" onClick="javascript:verify_quota(this.form)" value="$lt{'modi'}" />
                    389: </p>
                    390: $hidden_elements
                    391: <a href="javascript:changePage(document.setquota,'menu')">$lt{'back'}</a>
                    392: </form>
                    393: ENDDOCUMENT
                    394:     return;
                    395: }
1.3       raeburn   396: 
1.38      raeburn   397: sub print_catsettings {
1.48      raeburn   398:     my ($r,$cdom,$cnum,$cdesc,$type) = @_;
                    399:     &print_header($r,$type);
1.38      raeburn   400:     my %lt = &Apache::lonlocal::texthash(
1.48      raeburn   401:                                          'back'    => 'Pick another action',
                    402:                                          'catset'  => 'Catalog Settings for Course',
                    403:                                          'visi'    => 'Visibility in Course/Community Catalog',
                    404:                                          'exclude' => 'Exclude from course catalog:',
                    405:                                          'categ'   => 'Categorize Course',
                    406:                                          'assi'    => 'Assign one or more categories and/or subcategories to this course.'
1.38      raeburn   407:                                         );
1.48      raeburn   408:     if ($type eq 'Community') {
                    409:         $lt{'catset'} = &mt('Catalog Settings for Community');
                    410:         $lt{'exclude'} = &mt('Exclude from course catalog');
                    411:         $lt{'categ'} = &mt('Categorize Community');
1.49      raeburn   412:         $lt{'assi'} = &mt('Assign one or more subcategories to this community.');
1.48      raeburn   413:     }
1.38      raeburn   414:     $r->print('<form action="/adm/modifycourse" method="post" name="catsettings">'.
1.48      raeburn   415:               '<h3>'.$lt{'catset'}.' <span class="LC_nobreak">'.$cdesc.'</span></h3>');
1.38      raeburn   416:     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
1.49      raeburn   417:     my @cat_params = &catalog_settable($domconf{'coursecategories'},$type);
1.38      raeburn   418:     if (@cat_params > 0) {
                    419:         my %currsettings = 
                    420:             &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
                    421:         if (grep(/^togglecats$/,@cat_params)) {
                    422:             my $excludeon = '';
                    423:             my $excludeoff = ' checked="checked" ';
                    424:             if ($currsettings{'hidefromcat'} eq 'yes') {
                    425:                 $excludeon = $excludeoff;
                    426:                 $excludeoff = ''; 
                    427:             }
1.48      raeburn   428:             $r->print('<br /><h4>'.$lt{'visi'}.'</h4>'.
                    429:                       $lt{'exclude'}.
                    430:                       '&nbsp;<label><input name="hidefromcat" type="radio" value="yes" '.$excludeon.' />'.&mt('Yes').'</label>&nbsp;&nbsp;&nbsp;<label><input name="hidefromcat" type="radio" value="" '.$excludeoff.' />'.&mt('No').'</label><br /><p>');
                    431:             if ($type eq 'Community') {
                    432:                 $r->print(&mt("If a community has been categorized using at least one of the categories defined for communities in the domain, it will be listed in the domain's publicly accessible Course/Community Catalog, unless excluded."));
                    433:             } else {
                    434:                 $r->print(&mt("Unless excluded, a course will be listed in the domain's publicly accessible Course/Community Catalog, if at least one of the following applies").':<ul>'.
                    435:                           '<li>'.&mt('Auto-cataloging is enabled and the course is assigned an institutional code.').'</li>'.
                    436:                           '<li>'.&mt('The course has been categorized using at least one of the course categories defined for the domain.').'</li></ul>');
                    437:             }
                    438:             $r->print('</ul></p>');
1.38      raeburn   439:         }
                    440:         if (grep(/^categorize$/,@cat_params)) {
1.48      raeburn   441:             $r->print('<br /><h4>'.$lt{'categ'}.'</h4>');
1.38      raeburn   442:             if (ref($domconf{'coursecategories'}) eq 'HASH') {
                    443:                 my $cathash = $domconf{'coursecategories'}{'cats'};
                    444:                 if (ref($cathash) eq 'HASH') {
1.48      raeburn   445:                     $r->print($lt{'assi'}.'<br /><br />'.
1.38      raeburn   446:                               &Apache::loncommon::assign_categories_table($cathash,
1.49      raeburn   447:                                                      $currsettings{'categories'},$type));
1.38      raeburn   448:                 } else {
                    449:                     $r->print(&mt('No categories defined for this domain'));
                    450:                 }
                    451:             } else {
                    452:                 $r->print(&mt('No categories defined for this domain'));
                    453:             }
1.48      raeburn   454:             unless ($type eq 'Community') { 
                    455:                 $r->print('<p>'.&mt('If auto-cataloging based on institutional code is enabled in the domain, a course will continue to be listed in the catalog of official courses, in addition to receiving a listing under any manually assigned categor(ies).').'</p>');
                    456:             }
1.38      raeburn   457:         }
1.48      raeburn   458:         $r->print('<p><input type="button" name="chgcatsettings" value="'.
                    459:                   &mt('Save').'" onclick="javascript:changePage(document.catsettings,'."'processcat'".');" /></p>');
1.38      raeburn   460:     } else {
1.48      raeburn   461:         $r->print('<span class="LC_warning">');
                    462:         if ($type eq 'Community') {
                    463:             $r->print(&mt('Catalog settings in this domain are set in community context via "Community Configuration".'));
                    464:         } else {
                    465:             $r->print(&mt('Catalog settings in this domain are set in course context via "Course Configuration".'));
                    466:         }
                    467:         $r->print('</span><br /><br />'."\n".
1.38      raeburn   468:                   '<a href="javascript:changePage(document.catsettings,'."'menu'".');">'.
                    469:                   $lt{'back'}.'</a>');
                    470:     }
                    471:     $r->print(&hidden_form_elements().'</form>'."\n");
                    472:     return;
                    473: }
                    474: 
1.28      raeburn   475: sub print_course_modification_page {
1.48      raeburn   476:     my ($r,$cdom,$cnum,$cdesc,$type) = @_;
1.2       raeburn   477:     my %lt=&Apache::lonlocal::texthash(
                    478:             'actv' => "Active",
                    479:             'inac' => "Inactive",
                    480:             'ownr' => "Owner",
                    481:             'name' => "Name",
1.26      raeburn   482:             'unme' => "Username:Domain",
1.2       raeburn   483:             'stus' => "Status",
1.48      raeburn   484:             'nocc' => 'There is currently no owner set for this course.',
1.32      raeburn   485:             'gobt' => "Save",
1.2       raeburn   486:     );
1.48      raeburn   487:     my ($ownertable,$ccrole,$javascript_validations,$authenitems,$ccname);
                    488:     my %enrollvar = &get_enrollment_settings($cdom,$cnum);
                    489:     if ($type eq 'Community') {
                    490:         $ccrole = 'co';
                    491:         $lt{'nocc'} = &mt('There is currently no owner set for this community.');
                    492:     } else {
                    493:         $ccrole ='cc';
                    494:         ($javascript_validations,$authenitems) = &gather_authenitems($cdom,\%enrollvar);
                    495:     }
                    496:     $ccname = &Apache::lonnet::plaintext($ccrole,$type);
                    497:     my %roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,'','',[$ccrole]);
                    498:     my (@local_ccs,%cc_status,%pname);
                    499:     foreach my $item (keys(%roleshash)) {
                    500:         my ($uname,$udom) = split(/:/,$item);
                    501:         if (!grep(/^\Q$uname\E:\Q$udom\E$/,@local_ccs)) {
                    502:             push(@local_ccs,$uname.':'.$udom);
                    503:             $pname{$uname.':'.$udom} = &Apache::loncommon::plainname($uname,$udom);
                    504:             $cc_status{$uname.':'.$udom} = $lt{'actv'};
1.1       raeburn   505:         }
                    506:     }
1.48      raeburn   507:     if (($enrollvar{'courseowner'} ne '') && 
                    508:         (!grep(/^$enrollvar{'courseowner'}$/,@local_ccs))) {
                    509:         push(@local_ccs,$enrollvar{'courseowner'});
1.26      raeburn   510:         my ($owneruname,$ownerdom) = split(/:/,$enrollvar{'courseowner'});
                    511:         $pname{$enrollvar{'courseowner'}} = 
                    512:                          &Apache::loncommon::plainname($owneruname,$ownerdom);
1.48      raeburn   513:         my $active_cc = &Apache::loncommon::check_user_status($ownerdom,$owneruname,
                    514:                                                               $cdom,$cnum,$ccrole);
1.19      raeburn   515:         if ($active_cc eq 'active') {
1.2       raeburn   516:             $cc_status{$enrollvar{'courseowner'}} = $lt{'actv'};
1.1       raeburn   517:         } else {
1.2       raeburn   518:             $cc_status{$enrollvar{'courseowner'}} = $lt{'inac'};
1.1       raeburn   519:         }
                    520:     }
1.48      raeburn   521:     @local_ccs = sort(@local_ccs);
                    522:     if (@local_ccs == 0) {
                    523:         $ownertable = $lt{'nocc'};
                    524:     } else {
                    525:         my $numlocalcc = scalar(@local_ccs);
                    526:         $ownertable = '<input type="hidden" name="numlocalcc" value="'.$numlocalcc.'" />'.
                    527:                       &Apache::loncommon::start_data_table()."\n".
                    528:                       &Apache::loncommon::start_data_table_header_row()."\n".
                    529:                       '<th>'.$lt{'ownr'}.'</th>'.
                    530:                       '<th>'.$lt{'name'}.'</th>'.
                    531:                       '<th>'.$lt{'unme'}.'</th>'.
                    532:                       '<th>'.$lt{'stus'}.'</th>'.
                    533:                       &Apache::loncommon::end_data_table_header_row()."\n";
                    534:         foreach my $cc (@local_ccs) {
                    535:             $ownertable .= &Apache::loncommon::start_data_table_row()."\n";
                    536:             if ($cc eq $enrollvar{'courseowner'}) {
                    537:                   $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" checked="checked" /></td>'."\n";
                    538:             } else {
                    539:                 $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" /></td>'."\n";
                    540:             }
                    541:             $ownertable .= 
                    542:                  '<td>'.$pname{$cc}.'</td>'."\n".
                    543:                  '<td>'.$cc.'</td>'."\n".
                    544:                  '<td>'.$cc_status{$cc}.' '.$ccname.'</td>'."\n".
                    545:                  &Apache::loncommon::end_data_table_row()."\n";
                    546:         }
                    547:         $ownertable .= &Apache::loncommon::end_data_table();
                    548:     }
                    549:     &print_header($r,$type,$javascript_validations);
                    550:     my $dctitle = &Apache::lonnet::plaintext('dc');
                    551:     my $mainheader = &modifiable_only_title($type);
                    552:     my $hidden_elements = &hidden_form_elements();
                    553:     $r->print('<form action="/adm/modifycourse" method="post" name="'.$env{'form.phase'}.'">'."\n".
                    554:               '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3><p>'.
                    555:               &Apache::lonhtmlcommon::start_pick_box());
                    556:     if ($type eq 'Community') {
                    557:         $r->print(&Apache::lonhtmlcommon::row_title(
                    558:                   &Apache::loncommon::help_open_topic('Modify_Community_Owner').
                    559:                   '&nbsp;'.&mt('Community Owner'))."\n");
                    560:     } else {
                    561:         $r->print(&Apache::lonhtmlcommon::row_title(
                    562:                       &Apache::loncommon::help_open_topic('Modify_Course_Instcode').
                    563:                       '&nbsp;'.&mt('Course Code'))."\n".
                    564:                   '<input type="text" size="10" name="coursecode" value="'.$enrollvar{'coursecode'}.'" />'.
                    565:                   &Apache::lonhtmlcommon::row_closure().
                    566:                   &Apache::lonhtmlcommon::row_title(
                    567:                      &Apache::loncommon::help_open_topic('Modify_Course_Defaultauth').
                    568:                      '&nbsp;'.&mt('Default Authentication method'))."\n".
                    569:                   $authenitems."\n".
                    570:                   &Apache::lonhtmlcommon::row_closure().
                    571:                   &Apache::lonhtmlcommon::row_title(
                    572:                       &Apache::loncommon::help_open_topic('Modify_Course_Owner').
                    573:                       '&nbsp;'.&mt('Course Owner'))."\n");
                    574:     }
                    575:     $r->print($ownertable."\n".&Apache::lonhtmlcommon::row_closure(1).
                    576:               &Apache::lonhtmlcommon::end_pick_box().'</p><p>'.$hidden_elements.
                    577:               '<input type="button" onclick="javascript:changePage(this.form,'."'processparms'".');');
                    578:     if ($type eq 'Community') {
                    579:         $r->print('this.form.submit();"');
                    580:     } else {
                    581:         $r->print('javascript:verify_message(this.form);"');
                    582:     }
                    583:     $r->print('value="'.$lt{'gobt'}.'" /></p></form>');
                    584:     return;
                    585: }
                    586: 
                    587: sub modifiable_only_title {
                    588:     my ($type) = @_;
                    589:     my $dctitle = &Apache::lonnet::plaintext('dc');
                    590:     if ($type eq 'Community') {
                    591:         return &mt('Community settings modifiable only by [_1] for:',$dctitle);
                    592:     } else {
                    593:         return &mt('Course settings modifiable only by [_1] for:',$dctitle);
                    594:     }
                    595: }
1.24      albertel  596: 
1.48      raeburn   597: sub gather_authenitems {
                    598:     my ($cdom,$enrollvar) = @_;
1.28      raeburn   599:     my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($cdom);
1.2       raeburn   600:     my $curr_authtype = '';
                    601:     my $curr_authfield = '';
1.48      raeburn   602:     if (ref($enrollvar) eq 'HASH') {
                    603:         if ($enrollvar->{'authtype'} =~ /^krb/) {
                    604:             $curr_authtype = 'krb';
                    605:         } elsif ($enrollvar->{'authtype'} eq 'internal' ) {
                    606:             $curr_authtype = 'int';
                    607:         } elsif ($enrollvar->{'authtype'} eq 'localauth' ) {
                    608:             $curr_authtype = 'loc';
                    609:         }
1.2       raeburn   610:     }
                    611:     unless ($curr_authtype eq '') {
                    612:         $curr_authfield = $curr_authtype.'arg';
1.33      raeburn   613:     }
1.48      raeburn   614:     my $javascript_validations = 
                    615:         &Apache::lonuserutils::javascript_validations('modifycourse',$krbdefdom,
                    616:                                                       $curr_authtype,$curr_authfield);
1.35      raeburn   617:     my %param = ( formname => 'document.'.$env{'form.phase'},
1.48      raeburn   618:            kerb_def_dom => $krbdefdom,
                    619:            kerb_def_auth => $krbdef,
1.2       raeburn   620:            mode => 'modifycourse',
                    621:            curr_authtype => $curr_authtype,
1.48      raeburn   622:            curr_autharg => $enrollvar->{'autharg'}
                    623:         );
1.32      raeburn   624:     my (%authform,$authenitems);
                    625:     $authform{'krb'} = &Apache::loncommon::authform_kerberos(%param);
                    626:     $authform{'int'} = &Apache::loncommon::authform_internal(%param);
                    627:     $authform{'loc'} = &Apache::loncommon::authform_local(%param);
                    628:     foreach my $item ('krb','int','loc') {
                    629:         if ($authform{$item} ne '') {
                    630:             $authenitems .= $authform{$item}.'<br />';
                    631:         }
1.1       raeburn   632:     }
1.48      raeburn   633:     return($javascript_validations,$authenitems);
1.1       raeburn   634: }
                    635: 
                    636: sub modify_course {
1.30      raeburn   637:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
1.48      raeburn   638:     my %longtype = &course_settings_descrip($type);
1.50      raeburn   639:     my @items = ('internal.courseowner','description','internal.co-owners',
                    640:                  'internal.pendingco-owners');
1.48      raeburn   641:     unless ($type eq 'Community') {
                    642:         push(@items,('internal.coursecode','internal.authtype','internal.autharg',
                    643:                      'internal.sectionnums','internal.crosslistings'));
1.1       raeburn   644:     }
1.48      raeburn   645:     my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
                    646:     my $description = $settings{'description'};
                    647:     my ($ccrole,$response,$chgresponse,$nochgresponse,$reply,%currattr,%newattr,%cenv,%changed,
                    648:         @changes,@nochanges,@sections,@xlists,@warnings);
                    649:     my @modifiable_params = &get_dc_settable($type);
1.28      raeburn   650:     foreach my $param (@modifiable_params) {
1.48      raeburn   651:         $currattr{$param} = $settings{'internal.'.$param};
1.1       raeburn   652:     }
1.48      raeburn   653:     if ($type eq 'Community') {
                    654:         %changed = ( owner  => 0 );
                    655:         $ccrole = 'co';
                    656:     } else {
                    657:         %changed = ( code  => 0,
                    658:                      owner => 0,
                    659:                    );
                    660:         $ccrole = 'cc';
                    661:         unless ($settings{'internal.sectionnums'} eq '') {
                    662:             if ($settings{'internal.sectionnums'} =~ m/,/) {
                    663:                 @sections = split/,/,$settings{'internal.sectionnums'};
                    664:             } else {
                    665:                 $sections[0] = $settings{'internal.sectionnums'};
                    666:             }
                    667:         }
                    668:         unless ($settings{'internal.crosslistings'} eq'') {
                    669:             if ($settings{'internal.crosslistings'} =~ m/,/) {
                    670:                 @xlists = split/,/,$settings{'internal.crosslistings'};
                    671:             } else {
                    672:                 $xlists[0] = $settings{'internal.crosslistings'};
                    673:             }
                    674:         }
                    675:         if ($env{'form.login'} eq 'krb') {
                    676:             $newattr{'authtype'} = $env{'form.login'};
                    677:             $newattr{'authtype'} .= $env{'form.krbver'};
                    678:             $newattr{'autharg'} = $env{'form.krbarg'};
                    679:         } elsif ($env{'form.login'} eq 'int') {
                    680:             $newattr{'authtype'} ='internal';
                    681:             if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
                    682:                 $newattr{'autharg'} = $env{'form.intarg'};
                    683:             }
                    684:         } elsif ($env{'form.login'} eq 'loc') {
                    685:             $newattr{'authtype'} = 'localauth';
                    686:             if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
                    687:                 $newattr{'autharg'} = $env{'form.locarg'};
                    688:             }
                    689:         }
                    690:         if ( $newattr{'authtype'}=~ /^krb/) {
                    691:             if ($newattr{'autharg'}  eq '') {
                    692:                 push(@warnings,
                    693:                            &mt('As you did not include the default Kerberos domain'
1.45      bisitz    694:                           .' to be used for authentication in this class, the'
                    695:                           .' institutional data used by the automated'
                    696:                           .' enrollment process must include the Kerberos'
1.48      raeburn   697:                           .' domain for each new student.'));
                    698:             }
                    699:         }
                    700: 
                    701:         if ( exists($env{'form.coursecode'}) ) {
                    702:             $newattr{'coursecode'}=$env{'form.coursecode'};
                    703:             unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
                    704:                 $changed{'code'} = 1;
                    705:             }
1.1       raeburn   706:         }
                    707:     }
                    708: 
1.16      albertel  709:     if ( exists($env{'form.courseowner'}) ) {
                    710:         $newattr{'courseowner'}=$env{'form.courseowner'};
1.14      raeburn   711:         unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
1.38      raeburn   712:             $changed{'owner'} = 1;
1.1       raeburn   713:         } 
                    714:     }
1.48      raeburn   715: 
1.50      raeburn   716:     if ($changed{'owner'} || $changed{'code'}) {
1.38      raeburn   717:         my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,
                    718:                                                     undef,undef,'.');
                    719:         if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
1.48      raeburn   720:             if ($changed{'code'}) {
                    721:                 $crsinfo{$env{'form.pickedcourse'}}{'inst_code'} = $env{'form.coursecode'};
                    722:             }
                    723:             if ($changed{'owner'}) {
                    724:                 $crsinfo{$env{'form.pickedcourse'}}{'owner'} = $env{'form.courseowner'};
                    725:             }
1.38      raeburn   726:             my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
                    727:             my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
1.50      raeburn   728:             if ($putres eq 'ok') {
                    729:                 &update_coowners($cdom,$cnum,$chome,\%settings,\%newattr);
                    730:             }
1.38      raeburn   731:         }
1.14      raeburn   732:     }
1.28      raeburn   733:     foreach my $param (@modifiable_params) {
                    734:         if ($currattr{$param} eq $newattr{$param}) {
                    735:             push(@nochanges,$param);
1.1       raeburn   736:         } else {
1.48      raeburn   737:             $cenv{'internal.'.$param} = $newattr{$param};
1.28      raeburn   738:             push(@changes,$param);
1.1       raeburn   739:         }
                    740:     }
                    741:     if (@changes > 0) {
1.48      raeburn   742:         $chgresponse = &mt("The following settings have been changed:<br/><ul>");
1.1       raeburn   743:     }
1.48      raeburn   744:     if (@nochanges > 0) {
                    745:         $nochgresponse = &mt("The following settings remain unchanged:<br/><ul>");
1.1       raeburn   746:     }
1.33      raeburn   747:     if (@changes > 0) {
1.28      raeburn   748:         my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
1.1       raeburn   749:         if ($putreply !~ /^ok$/) {
1.48      raeburn   750:             $response = '<p class="LC_error">'.
                    751:                         &mt('There was a problem processing your requested changes.').'<br />';
                    752:             if ($type eq 'Community') {
                    753:                 $response .= &mt('Settings for this community have been left unchanged.');
                    754:             } else {
                    755:                 $response .= &mt('Settings for this course have been left unchanged.');
                    756:             }
                    757:             $response .= '<br/>'.&mt('Error: ').$putreply.'</p>';
1.1       raeburn   758:         } else {
1.28      raeburn   759:             foreach my $attr (@modifiable_params) {
1.48      raeburn   760:                 if (grep/^\Q$attr\E$/,@changes) {
                    761: 	            $chgresponse .= '<li>'.$longtype{$attr}.' '.&mt('now set to:').' "'.$newattr{$attr}.'".</li>';
1.1       raeburn   762:                 } else {
1.48      raeburn   763: 	            $nochgresponse .= '<li>'.$longtype{$attr}.' '.&mt('still set to:').' "'.$currattr{$attr}.'".</li>';
1.1       raeburn   764:                 }
                    765:             }
1.48      raeburn   766:             if (($type ne 'Community') && ($changed{'code'} || $changed{'owner'})) {
1.1       raeburn   767:                 if ( $newattr{'courseowner'} eq '') {
1.48      raeburn   768: 	            push(@warnings,&mt('There is no owner associated with this LON-CAPA course.').
                    769:                                    '<br />'.&mt('If automated enrollment at your institution requires validation of course owners, automated enrollment will fail.'));
1.1       raeburn   770:                 } else {
                    771: 	            if (@sections > 0) {
1.38      raeburn   772:                         if ($changed{'code'}) {
1.2       raeburn   773: 	                    foreach my $sec (@sections) {
                    774: 		                if ($sec =~ m/^(.+):/) {
1.48      raeburn   775:                                     my $instsec = $1;
1.8       raeburn   776: 		                    my $inst_course_id = $newattr{'coursecode'}.$1;
1.28      raeburn   777:                                     my $course_check = &Apache::lonnet::auto_validate_courseID($cnum,$cdom,$inst_course_id);
1.7       raeburn   778: 			            if ($course_check eq 'ok') {
1.28      raeburn   779:                                         my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'});
1.48      raeburn   780: 			                unless ($outcome eq 'ok') {
                    781:                                
                    782: 				            push(@warnings,&mt('If automatic enrollment is enabled for "[_1]" automated enrollment may fail for "[_2]" - section: [_3], for the following reason: "[_4]"',$description,$newattr{'coursecode'},$instsec,$outcome).'<br/>');
1.1       raeburn   783: 			                }
                    784: 			            } else {
1.48      raeburn   785:                                         push(@warnings,&mt('If automatic enrollment is enabled for "[_1]" automated enrollment may fail for "[_2]" - section: [_3], for the following reason: "[_4]"',$description,$newattr{'coursecode'},$instsec,$course_check));
1.1       raeburn   786: 			            }
                    787: 		                } else {
1.48      raeburn   788: 			            push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section: [_3], because this is not a valid section entry.',$description,$newattr{'coursecode'},$sec));
1.1       raeburn   789: 		                }
                    790: 		            }
1.38      raeburn   791: 	                } elsif ($changed{'owner'}) {
1.4       raeburn   792:                             foreach my $sec (@sections) {
                    793:                                 if ($sec =~ m/^(.+):/) {
1.48      raeburn   794:                                     my $instsec = $1;
                    795:                                     my $inst_course_id = $newattr{'coursecode'}.$instsec;
1.28      raeburn   796:                                     my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'});
1.4       raeburn   797:                                     unless ($outcome eq 'ok') {
1.48      raeburn   798:                                         push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section [_3] for the following reason: "[_4]".',$description,$newattr{'coursecode'},$instsec,$outcome));
1.4       raeburn   799:                                     }
                    800:                                 } else {
1.48      raeburn   801:                                     push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section [_3] because this is not a valid section entry.',$description,$newattr{'coursecode'},$sec));
1.4       raeburn   802:                                 }
                    803:                             }
                    804:                         }
1.1       raeburn   805: 	            } else {
1.48      raeburn   806: 	                push(@warnings,&mt('As no section numbers are currently listed for "[_1]" automated enrollment will not occur for any sections of institutional course code: "[_2]".',$description,$newattr{'coursecode'}));
1.1       raeburn   807: 	            }
1.38      raeburn   808: 	            if ( (@xlists > 0) && ($changed{'owner'}) ) {
1.1       raeburn   809: 	                foreach my $xlist (@xlists) {
                    810: 		            if ($xlist =~ m/^(.+):/) {
1.48      raeburn   811:                                 my $instxlist = $1;
                    812:                                 my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$instxlist,$newattr{'courseowner'});
1.1       raeburn   813: 		                unless ($outcome eq 'ok') {
1.48      raeburn   814: 			            push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for crosslisted class "[_2]" for the following reason: "[_3]".',$description,$instxlist,$outcome));
1.1       raeburn   815: 		                }
1.28      raeburn   816: 		            }
1.1       raeburn   817: 	                }
                    818: 	            }
                    819:                 }
                    820:             }
                    821:         }
1.2       raeburn   822:     } else {
1.28      raeburn   823:         foreach my $attr (@modifiable_params) {
1.48      raeburn   824:             $nochgresponse .= '<li>'.$longtype{$attr}.' '.&mt('still set to').' "'.$currattr{$attr}.'".</li>';
1.2       raeburn   825:         }
1.1       raeburn   826:     }
                    827: 
                    828:     if (@changes > 0) {
                    829:         $chgresponse .= "</ul><br/><br/>";
                    830:     }
                    831:     if (@nochanges > 0) {
                    832:         $nochgresponse .=  "</ul><br/><br/>";
                    833:     }
1.48      raeburn   834:     my ($warning,$numwarnings);
                    835:     my $numwarnings = scalar(@warnings); 
                    836:     if ($numwarnings) {
                    837:         $warning = &mt('The following [quant,_1,warning was,warnings were] generated when applying your changes to automated enrollment:',$numwarnings).'<p><ul>';
                    838:         foreach my $warn (@warnings) {
                    839:             $warning .= '<li><span class="LC_warning">'.$warn.'</span></li>';
                    840:         }
                    841:         $warning .= '</ul></p>';
1.1       raeburn   842:     }
1.48      raeburn   843:     if ($response) {
                    844:         $reply = $response;
                    845:     } else {
1.1       raeburn   846:         $reply = $chgresponse.$nochgresponse.$warning;
                    847:     }
1.48      raeburn   848:     &print_header($r,$type);
                    849:     my $mainheader = &modifiable_only_title($type);
                    850:     $reply = '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3>'."\n".
                    851:              '<p>'.$reply.'</p>'."\n".
1.28      raeburn   852:              '<form action="/adm/modifycourse" method="post" name="processparms">'.
                    853:              &hidden_form_elements().
1.48      raeburn   854:              '<a href="javascript:changePage(document.processparms,'."'menu'".')">'.
                    855:              &mt('Pick another action').'</a>';
                    856:     if ($numwarnings) {
                    857:         my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
                    858:         my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
                    859:                                              '=1&destinationurl=/adm/populate','&<>"');
                    860: 
                    861:         $reply .= '<br /><a href="'.$escuri.'">'.
                    862:                   &mt('Go to Automated Enrollment Manager for course').'</a>';
                    863:     }
                    864:     $reply .= '</form>';
1.3       raeburn   865:     $r->print($reply);
1.28      raeburn   866:     return;
                    867: }
                    868: 
1.50      raeburn   869: sub update_coowners {
                    870:     my ($cdom,$cnum,$chome,$settings,$newattr) = @_;
                    871:     return unless ((ref($settings) eq 'HASH') && (ref($newattr) eq 'HASH'));
                    872:     my %designhash = &Apache::loncommon::get_domainconf($cdom);
                    873:     my (%cchash,$autocoowners);
                    874:     if ($designhash{$cdom.'.autoassign.co-owners'}) {
                    875:         $autocoowners = 1;
                    876:         %cchash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc']);
                    877:     }
                    878:     if ($settings->{'internal.courseowner'} ne $newattr->{'courseowner'}) {
                    879:         my $oldowner_to_coowner;
1.51      raeburn   880:         my @types = ('co-owners');
1.50      raeburn   881:         if (($newattr->{'coursecode'}) && ($autocoowners)) {
                    882:             my $oldowner = $settings->{'internal.courseowner'};
                    883:             if ($cchash{$oldowner.':cc'}) {
1.51      raeburn   884:                 my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$oldowner);
                    885:                 if ($result eq 'valid') {
                    886:                     if ($settings->{'internal.co-owner'}) {
                    887:                         my @current = split(',',$settings->{'internal.co-owners'});
                    888:                         unless (grep(/^\Q$oldowner\E$/,@current)) {
                    889:                             $oldowner_to_coowner = 1;
                    890:                         }
                    891:                     } else {
1.50      raeburn   892:                         $oldowner_to_coowner = 1;
                    893:                     }
                    894:                 }
                    895:             }
1.51      raeburn   896:         } else {
                    897:             push(@types,'pendingco-owners');
1.50      raeburn   898:         }
1.51      raeburn   899:         foreach my $type (@types) {
1.50      raeburn   900:             if ($settings->{'internal.'.$type}) {
                    901:                 my @current = split(',',$settings->{'internal.'.$type});
                    902:                 my $newowner = $newattr->{'courseowner'};
                    903:                 my @newvalues = ();
                    904:                 if (($newowner ne '') && (grep(/^\Q$newowner\E$/,@current))) {
                    905:                     foreach my $person (@current) {
                    906:                         unless ($person eq $newowner) {
                    907:                             push(@newvalues,$person);
                    908:                         }
                    909:                     }
                    910:                 } else {
                    911:                     @newvalues = @current;
                    912:                 }
                    913:                 if ($oldowner_to_coowner) {
                    914:                     push(@newvalues,$settings->{'internal.courseowner'});
                    915:                     @newvalues = sort(@newvalues);
                    916:                 }
                    917:                 my $newownstr = join(',',@newvalues);
                    918:                 if ($newownstr ne $settings->{'internal.'.$type}) {
                    919:                     if ($type eq 'co-owners') {
                    920:                         my $deleted = '';
                    921:                         unless (@newvalues) {
                    922:                             $deleted = 1;
                    923:                         }
                    924:                         &Apache::lonnet::store_coowners($cdom,$cnum,$chome,
                    925:                                                         $deleted,@newvalues);
                    926:                     } else {
                    927:                         my $pendingcoowners;
                    928:                         my $cid = $cdom.'_'.$cnum;
                    929:                         if (@newvalues) {
                    930:                             $pendingcoowners = join(',',@newvalues);
                    931:                             my %pendinghash = (
                    932:                                 'internal.pendingco-owners' => $pendingcoowners,
                    933:                             );
1.52    ! raeburn   934:                             my $putresult = &Apache::lonnet::put('environment',\%pendinghash,$cdom,$cnum);
1.50      raeburn   935:                             if ($putresult eq 'ok') {
                    936:                                 if ($env{'course.'.$cid.'.num'} eq $cnum) {
1.52    ! raeburn   937:                                     &Apache::lonnet::appenv({'course.'.$cid.'.internal.pendingco-owners' => $pendingcoowners});
1.50      raeburn   938:                                 }
                    939:                             }
                    940:                         } else {
                    941:                             my $delresult = &Apache::lonnet::del('environment',['internal.pendingco-owners'],$cdom,$cnum);
                    942:                             if ($delresult eq 'ok') {
                    943:                                 if ($env{'course.'.$cid.'.internal.pendingco-owners'}) {
                    944:                                     &Apache::lonnet::delenv('course.'.$cid.'.internal.pendingco-owners');
                    945:                                 }
                    946:                             }
                    947:                         }
                    948:                     }
                    949:                 } elsif ($oldowner_to_coowner) {
                    950:                     &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
                    951:                                          $settings->{'internal.courseowner'});
                    952: 
                    953:                 }
                    954:             } elsif ($oldowner_to_coowner) {
                    955:                 &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
                    956:                                      $settings->{'internal.courseowner'});
                    957:             }
                    958:         }
                    959:     }
                    960:     if ($settings->{'internal.coursecode'} ne $newattr->{'coursecode'}) {
                    961:         if ($newattr->{'coursecode'} ne '') {
                    962:             my %designhash = &Apache::loncommon::get_domainconf($cdom);
                    963:             if ($designhash{$cdom.'.autoassign.co-owners'}) {
                    964:                 my @newcoowners = ();
                    965:                 if ($settings->{'internal.co-owners'}) {
                    966:                     my @currcoown = split(',',$settings->{'internal.coowners'});
                    967:                     my ($updatecoowners,$delcoowners);
                    968:                     foreach my $person (@currcoown) {
1.51      raeburn   969:                         my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$person);
1.50      raeburn   970:                         if ($result eq 'valid') {
                    971:                             push(@newcoowners,$person);
                    972:                         }
                    973:                     }
                    974:                     foreach my $item (sort(keys(%cchash))) {
                    975:                         my ($uname,$udom,$urole) = split(':',$item);
1.51      raeburn   976:                         next if ($uname.':'.$udom eq $newattr->{'courseowner'});
1.50      raeburn   977:                         unless (grep(/^\Q$uname\E:\Q$udom\E$/,@newcoowners)) {
1.51      raeburn   978:                             my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$uname.':'.$udom);
                    979:                             if ($result eq 'valid') {
                    980:                                 push(@newcoowners,$uname.':'.$udom);
                    981:                             }
1.50      raeburn   982:                         }
                    983:                     }
                    984:                     if (@newcoowners) {
                    985:                         my $coowners = join(',',sort(@newcoowners));
                    986:                         unless ($coowners eq $settings->{'internal.co-owners'}) {
                    987:                             $updatecoowners = 1;
                    988:                         }
                    989:                     } else {
                    990:                         $delcoowners = 1;
                    991:                     }
                    992:                     if ($updatecoowners || $delcoowners) {
                    993:                         &Apache::lonnet::store_coowners($cdom,$cnum,$chome,
                    994:                                                         $delcoowners,@newcoowners);
                    995:                     }
                    996:                 } else {
                    997:                     foreach my $item (sort(keys(%cchash))) {
                    998:                         my ($uname,$udom,$urole) = split(':',$item);
                    999:                         push(@newcoowners,$uname.':'.$udom);
                   1000:                     }
                   1001:                     if (@newcoowners) {
                   1002:                         &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
                   1003:                                                         @newcoowners);
                   1004:                     }
                   1005:                 }
                   1006:             }
                   1007:         }
                   1008:     }
                   1009:     return;
                   1010: }
                   1011: 
1.28      raeburn  1012: sub modify_quota {
1.48      raeburn  1013:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
                   1014:     &print_header($r,$type);
                   1015:     $r->print('<form action="/adm/modifycourse" method="post" name="processquota">'."\n".
                   1016:               '<h3>'.&mt('Disk space for storage of group portfolio files for:').
                   1017:               ' <span class="LC_nobreak">'.$cdesc.'</span></h3><br />');
1.28      raeburn  1018:     my %oldsettings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
                   1019:     my $defaultquota = 20;
                   1020:     if ($env{'form.coursequota'} ne '') {
                   1021:         my $newquota = $env{'form.coursequota'};
                   1022:         if ($newquota =~ /^\s*(\d+\.?\d*|\.\d+)\s*$/) {
                   1023:             $newquota = $1;
                   1024:             if ($oldsettings{'internal.coursequota'} eq $env{'form.coursequota'}) {
1.48      raeburn  1025:                 $r->print(&mt('The disk space allocated for group portfolio files remains unchanged as [_1] Mb.',$env{'form.coursequota'}));
1.28      raeburn  1026:             } else {
                   1027:                 my %cenv = (
                   1028:                            'internal.coursequota' => $env{'form.coursequota'},
                   1029:                            );
                   1030:                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
                   1031:                                                     $cnum);
                   1032:                 if (($oldsettings{'internal.coursequota'} eq '') && 
                   1033:                     ($env{'form.coursequota'} == $defaultquota)) {
1.48      raeburn  1034:                     if ($type eq 'Community') {
                   1035:                          $r->print(&mt('The disk space allocated for group portfolio files in this community is the default quota for this domain: [_1] Mb.',$defaultquota));
                   1036:                     } else {
                   1037:                          $r->print(&mt('The disk space allocated for group portfolio files in this course is the default quota for this domain: [_1] Mb.',$defaultquota));
                   1038:                     }
1.28      raeburn  1039:                 } else {
                   1040:                     if ($putreply eq 'ok') {
                   1041:                         my %updatedsettings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
1.48      raeburn  1042:                         $r->print(&mt('The disk space allocated for group portfolio files is now: [_1] Mb.',$updatedsettings{'internal.coursequota'}));
1.28      raeburn  1043:                         my $usage = &Apache::longroup::sum_quotas($cdom.'_'.$cnum);
                   1044:                         if ($usage >= $updatedsettings{'internal.coursequota'}) {
                   1045:                             my $newoverquota;
                   1046:                             if ($usage < $oldsettings{'internal.coursequota'}) {
                   1047:                                 $newoverquota = 'now';
                   1048:                             }
1.48      raeburn  1049:                             $r->print('<p>');
                   1050:                             if ($type eq 'Community') {
                   1051:                                 $r->print(&mt('Disk usage [_1] exceeds the quota for this community.',$newoverquota).' '.
                   1052:                                           &mt('Upload of new portfolio files and assignment of a non-zero Mb quota to new groups in the community will not be possible until some files have been deleted, and total usage is below community quota.'));
                   1053:                             } else {
                   1054:                                 $r->print(&mt('Disk usage [_1] exceeds the quota for this course.',$newoverquota).' '.
                   1055:                                           &mt('Upload of new portfolio files and assignment of a non-zero Mb quota to new groups in the course will not be possible until some files have been deleted, and total usage is below course quota.'));
                   1056:                             }
                   1057:                             $r->print('</p>');
1.28      raeburn  1058:                         }
                   1059:                     } else {
1.48      raeburn  1060:                         $r->print(&mt('An error occurred storing the quota for group portfolio files: ').
                   1061:                                   $putreply);
1.28      raeburn  1062:                     }
                   1063:                 }
                   1064:             }
                   1065:         } else {
                   1066:             $r->print(&mt('The new quota requested contained invalid characters, so the quota is unchanged.'));
                   1067:         }
                   1068:     }
1.48      raeburn  1069:     $r->print('<p>'.
                   1070:               '<a href="javascript:changePage(document.processquota,'."'menu'".')">'.
                   1071:               &mt('Pick another action').'</a>');
1.28      raeburn  1072:     $r->print(&hidden_form_elements().'</form>');
                   1073:     return;
1.1       raeburn  1074: }
                   1075: 
1.38      raeburn  1076: sub modify_catsettings {
1.48      raeburn  1077:     my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
                   1078:     &print_header($r,$type);
                   1079:     my ($ccrole,%desc);
                   1080:     if ($type eq 'Community') {
                   1081:         $desc{'hidefromcat'} = &mt('Excluded from community catalog');
                   1082:         $desc{'categories'} = &mt('Assigned categories for this community');
                   1083:         $ccrole = 'co';
                   1084:     } else {
                   1085:         $desc{'hidefromcat'} = &mt('Excluded from course catalog');
                   1086:         $desc{'categories'} = &mt('Assigned categories for this course');
                   1087:         $ccrole = 'cc';
                   1088:     }
1.38      raeburn  1089:     $r->print('
                   1090: <form action="/adm/modifycourse" method="post" name="processcat">
                   1091: <h3>'.&mt('Category settings').'</h3>');
                   1092:     my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
1.49      raeburn  1093:     my @cat_params = &catalog_settable($domconf{'coursecategories'},$type);
1.38      raeburn  1094:     if (@cat_params > 0) {
                   1095:         my (%cenv,@changes,@nochanges);
                   1096:         my %currsettings =
                   1097:             &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
                   1098:         my (@newcategories,%showitem); 
                   1099:         if (grep(/^togglecats$/,@cat_params)) {
                   1100:             if ($currsettings{'hidefromcat'} ne $env{'form.hidefromcat'}) {
                   1101:                 push(@changes,'hidefromcat');
                   1102:                 $cenv{'hidefromcat'} = $env{'form.hidefromcat'};
                   1103:             } else {
                   1104:                 push(@nochanges,'hidefromcat');
                   1105:             }
                   1106:             if ($env{'form.hidefromcat'} eq 'yes') {
                   1107:                 $showitem{'hidefromcat'} = '"'.&mt('Yes')."'";
                   1108:             } else {
                   1109:                 $showitem{'hidefromcat'} = '"'.&mt('No').'"';
                   1110:             }
                   1111:         }
                   1112:         if (grep(/^categorize$/,@cat_params)) {
                   1113:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   1114:             if (ref($domconf{'coursecategories'}) eq 'HASH') {
                   1115:                 my $cathash = $domconf{'coursecategories'}{'cats'};
                   1116:                 if (ref($cathash) eq 'HASH') {
                   1117:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   1118:                                                            \%allitems,\%idx,\@jsarray);
                   1119:                 }
                   1120:             }
                   1121:             @newcategories =  &Apache::loncommon::get_env_multiple('form.usecategory');
                   1122:             if (@newcategories == 0) {
                   1123:                 $showitem{'categories'} = '"'.&mt('None').'"';
                   1124:             } else {
                   1125:                 $showitem{'categories'} = '<ul>';
                   1126:                 foreach my $item (@newcategories) {
                   1127:                     $showitem{'categories'} .= '<li>'.$trails[$allitems{$item}].'</li>';
                   1128:                 }
                   1129:                 $showitem{'categories'} .= '</ul>';
                   1130:             }
                   1131:             my $catchg = 0;
                   1132:             if ($currsettings{'categories'} ne '') {
                   1133:                 my @currcategories = split('&',$currsettings{'categories'});
                   1134:                 foreach my $cat (@currcategories) {
                   1135:                     if (!grep(/^\Q$cat\E$/,@newcategories)) {
                   1136:                         $catchg = 1;
                   1137:                         last;
                   1138:                     }
                   1139:                 }
                   1140:                 if (!$catchg) {
                   1141:                     foreach my $cat (@newcategories) {
                   1142:                         if (!grep(/^\Q$cat\E$/,@currcategories)) {
                   1143:                             $catchg = 1;
                   1144:                             last;                     
                   1145:                         } 
                   1146:                     } 
                   1147:                 }
                   1148:             } else {
                   1149:                 if (@newcategories > 0) {
                   1150:                     $catchg = 1;
                   1151:                 }
                   1152:             }
                   1153:             if ($catchg) {
                   1154:                 $cenv{'categories'} = join('&',@newcategories);
                   1155:                 push(@changes,'categories');
                   1156:             } else {
                   1157:                 push(@nochanges,'categories');
                   1158:             }
                   1159:             if (@changes > 0) {
                   1160:                 my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
                   1161:                 if ($putreply eq 'ok') {
                   1162:                     my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
                   1163:                                                                 $cnum,undef,undef,'.');
                   1164:                     if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
                   1165:                         if (grep(/^hidefromcat$/,@changes)) {
                   1166:                             $crsinfo{$env{'form.pickedcourse'}}{'hidefromcat'} = $env{'form.hidefromcat'};
                   1167:                         }
                   1168:                         if (grep(/^categories$/,@changes)) {
                   1169:                             $crsinfo{$env{'form.pickedcourse'}}{'categories'} = $cenv{'categories'};
                   1170:                         }
                   1171:                         my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
                   1172:                         my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
                   1173:                     }
1.48      raeburn  1174:                     $r->print(&mt('The following changes occurred:').'<ul>');
1.38      raeburn  1175:                     foreach my $item (@changes) {
1.48      raeburn  1176:                         $r->print('<li>'.&mt('[_1] now set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
1.38      raeburn  1177:                     }
                   1178:                     $r->print('</ul><br />');
                   1179:                 }
                   1180:             }
                   1181:             if (@nochanges > 0) {
1.48      raeburn  1182:                 $r->print(&mt('The following were unchanged:').'<ul>');
1.38      raeburn  1183:                 foreach my $item (@nochanges) {
1.48      raeburn  1184:                     $r->print('<li>'.&mt('[_1] still set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
1.38      raeburn  1185:                 }
                   1186:                 $r->print('</ul>');
                   1187:             }
                   1188:         }
                   1189:     } else {
1.48      raeburn  1190:         my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
                   1191:         my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
                   1192:                                              '=1&destinationurl=/adm/courseprefs','&<>"');
                   1193:         if ($type eq 'Community') {
                   1194:             $r->print(&mt('Category settings for communities in this domain should be modified in community context (via "[_1]Community Configuration[_2]").','<a href="$escuri">','</a>').'<br />');
                   1195:         } else {
                   1196:             $r->print(&mt('Category settings for courses in this domain should be modified in course context (via "[_1]Course Configuration[_2]").','<a href="$escuri">','</a>').'<br />');
                   1197:         }
1.38      raeburn  1198:     }
                   1199:     $r->print('<br />'."\n".
                   1200:               '<a href="javascript:changePage(document.processcat,'."'menu'".')">'.
1.48      raeburn  1201:               &mt('Pick another action').'</a>');
1.38      raeburn  1202:     $r->print(&hidden_form_elements().'</form>');
                   1203:     return;
                   1204: }
                   1205: 
1.1       raeburn  1206: sub print_header {
1.48      raeburn  1207:     my ($r,$type,$javascript_validations) = @_;
1.28      raeburn  1208:     my $phase = "start";
                   1209:     if ( exists($env{'form.phase'}) ) {
                   1210:         $phase = $env{'form.phase'};
                   1211:     }
                   1212:     my $js = qq|
                   1213: <script type="text/javascript">
                   1214: function changePage(formname,newphase) {
                   1215:     formname.phase.value = newphase;
                   1216:     if (newphase == 'processparms') {
                   1217:         return;
1.1       raeburn  1218:     }
1.28      raeburn  1219:     formname.submit();
                   1220: }
                   1221: </script>
                   1222: |;
                   1223:     if ($phase eq 'setparms') {
                   1224: 	$js .= qq|
                   1225: <script  type="text/javascript">
                   1226: $javascript_validations
                   1227: </script>
                   1228: |;
                   1229:     } elsif ($phase eq 'courselist') {
                   1230:         $js .= qq|
                   1231: <script type="text/javascript">
                   1232: function gochoose(cname,cdom,cdesc) {
                   1233:     document.courselist.pickedcourse.value = cdom+'_'+cname;
                   1234:     document.courselist.submit();
                   1235: }
                   1236: </script>
                   1237: |;
                   1238:     } elsif ($phase eq 'setquota') {
                   1239:         $js .= <<'ENDSCRIPT';
                   1240: <script type="text/javascript">
                   1241: function verify_quota(formname) {
                   1242:     var newquota = formname.coursequota.value; 
                   1243:     var num_reg = /^\s*(\d+\.?\d*|\.\d+)\s*$/;
                   1244:     if (num_reg.test(newquota)) {
                   1245:         changePage(formname,'processquota');
1.1       raeburn  1246:     } else {
1.28      raeburn  1247:         alert("The quota you entered contained invalid characters.\nYou must enter a number");
1.1       raeburn  1248:     }
1.28      raeburn  1249:     return;
                   1250: }
                   1251: </script>
                   1252: ENDSCRIPT
1.1       raeburn  1253:     }
1.37      raeburn  1254:     my $starthash;
                   1255:     if ($env{'form.phase'} eq 'ccrole') {
                   1256:         $starthash = {
                   1257:            add_entries => {'onload' => "javascript:document.ccrole.submit();"},
                   1258:                      };
                   1259:     }
1.48      raeburn  1260:     $r->print(&Apache::loncommon::start_page('View/Modify Course/Community Settings',
1.37      raeburn  1261: 					     $js,$starthash));
1.48      raeburn  1262:     my $bread_text = "View/Modify Courses/Communities";
                   1263:     if ($type eq 'Community') {
                   1264:         $bread_text = 'Community Settings';
1.41      raeburn  1265:     } else {
1.48      raeburn  1266:         $bread_text = 'Course Settings';
1.41      raeburn  1267:     }
1.48      raeburn  1268:     $r->print(&Apache::lonhtmlcommon::breadcrumbs($bread_text));
1.5       raeburn  1269:     return;
1.1       raeburn  1270: }
                   1271: 
                   1272: sub print_footer {
1.23      albertel 1273:     my ($r) = @_;
                   1274:     $r->print('<br />'.&Apache::loncommon::end_page());
1.5       raeburn  1275:     return;
1.3       raeburn  1276: }
                   1277: 
                   1278: sub check_course {
1.28      raeburn  1279:     my ($r,$dom,$domdesc) = @_;
                   1280:     my ($ok_course,$description,$instcode,$owner);
1.35      raeburn  1281:     my %args = (
                   1282:                  one_time => 1,
                   1283:                );
                   1284:     my %coursehash = 
                   1285:         &Apache::lonnet::coursedescription($env{'form.pickedcourse'},\%args);
                   1286:     my $cnum = $coursehash{'num'};
                   1287:     my $cdom = $coursehash{'domain'};
                   1288:     if ($cdom eq $dom) {
                   1289:         my $description;
                   1290:         my %courseIDs = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
1.38      raeburn  1291:                                                       $cnum,undef,undef,'.');
1.35      raeburn  1292:         if (keys(%courseIDs) > 0) {
                   1293:             $ok_course = 'ok';
                   1294:             my ($instcode,$owner);
                   1295:             if (ref($courseIDs{$cdom.'_'.$cnum}) eq 'HASH') {
                   1296:                 $description = $courseIDs{$cdom.'_'.$cnum}{'description'};
                   1297:                 $instcode = $courseIDs{$cdom.'_'.$cnum}{'inst_code'};
                   1298:                 $owner = $courseIDs{$cdom.'_'.$cnum}{'owner'};          
                   1299:             } else {
                   1300:                 ($description,$instcode,$owner) = 
                   1301:                                    split(/:/,$courseIDs{$cdom.'_'.$cnum});
                   1302:             }
                   1303:             $description = &unescape($description);
                   1304:             $instcode = &unescape($instcode);
                   1305:             if ($instcode) {
                   1306:                 $description .= " ($instcode)";
1.5       raeburn  1307:             }
1.35      raeburn  1308:             return ($ok_course,$description);
1.3       raeburn  1309:         }
                   1310:     }
1.1       raeburn  1311: }
                   1312: 
1.28      raeburn  1313: sub course_settings_descrip {
1.48      raeburn  1314:     my ($type) = @_;
                   1315:     my %longtype;
                   1316:     if ($type eq 'Community') {
                   1317:          %longtype = &Apache::lonlocal::texthash(
                   1318:                       'courseowner' => "Username:domain of community owner",
1.50      raeburn  1319:                       'co-owners'   => "Username:domain of each co-owner",
1.48      raeburn  1320:          );
                   1321:     } else {
                   1322:          %longtype = &Apache::lonlocal::texthash(
1.28      raeburn  1323:                       'authtype' => 'Default authentication method',
                   1324:                       'autharg'  => 'Default authentication parameter',
                   1325:                       'autoadds' => 'Automated adds',
                   1326:                       'autodrops' => 'Automated drops',
                   1327:                       'autostart' => 'Date of first automated enrollment',
                   1328:                       'autoend' => 'Date of last automated enrollment',
                   1329:                       'default_enrollment_start_date' => 'Date of first student access',
                   1330:                       'default_enrollment_end_date' => 'Date of last student access',
                   1331:                       'coursecode' => 'Official course code',
                   1332:                       'courseowner' => "Username:domain of course owner",
1.50      raeburn  1333:                       'co-owners'   => "Username:domain of each co-owner",
1.28      raeburn  1334:                       'notifylist' => 'Course Coordinators to be notified of enrollment changes',
1.48      raeburn  1335:                       'sectionnums' => 'Course section number:LON-CAPA section',
                   1336:                       'crosslistings' => 'Crosslisted class:LON-CAPA section',
                   1337:          );
                   1338:     }
1.28      raeburn  1339:     return %longtype;
                   1340: }
                   1341: 
                   1342: sub hidden_form_elements {
                   1343:     my $hidden_elements = 
1.46      raeburn  1344:       &Apache::lonhtmlcommon::echo_form_input(['gosearch','updater','coursecode',
1.37      raeburn  1345:           'prevphase','numlocalcc','courseowner','login','coursequota','intarg',
1.38      raeburn  1346:           'locarg','krbarg','krbver','counter','hidefromcat','usecategory'])."\n".
1.37      raeburn  1347:           '<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />';
1.28      raeburn  1348:     return $hidden_elements;
                   1349: }
1.1       raeburn  1350: 
                   1351: sub handler {
                   1352:     my $r = shift;
                   1353:     if ($r->header_only) {
                   1354:         &Apache::loncommon::content_type($r,'text/html');
                   1355:         $r->send_http_header;
                   1356:         return OK;
                   1357:     }
1.28      raeburn  1358:     my $dom = $env{'request.role.domain'};
1.31      albertel 1359:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.28      raeburn  1360:     if (&Apache::lonnet::allowed('ccc',$dom)) {
1.1       raeburn  1361:         &Apache::loncommon::content_type($r,'text/html');
                   1362:         $r->send_http_header;
                   1363: 
1.28      raeburn  1364:         &Apache::lonhtmlcommon::clear_breadcrumbs();
                   1365: 
                   1366:         my $phase = $env{'form.phase'};
1.46      raeburn  1367:         if ($env{'form.updater'}) {
                   1368:             $phase = '';
                   1369:         }
1.37      raeburn  1370:         if ($phase eq '') {
                   1371:             &Apache::lonhtmlcommon::add_breadcrumb
1.28      raeburn  1372:             ({href=>"/adm/modifycourse",
1.48      raeburn  1373:               text=>"Course/Community search"});
1.28      raeburn  1374:             &print_course_search_page($r,$dom,$domdesc);
1.1       raeburn  1375:         } else {
1.37      raeburn  1376:             my $firstform = $phase;
                   1377:             if ($phase eq 'courselist') {
                   1378:                 $firstform = 'filterpicker';
1.48      raeburn  1379:             }
                   1380:             my $choose_text;
                   1381:             my $type = $env{'form.type'};
                   1382:             if ($type eq '') {
                   1383:                 $type = 'Course';
                   1384:             }
                   1385:             if ($type eq 'Community') {
                   1386:                 $choose_text = "Choose a community";
                   1387:             } else {
                   1388:                 $choose_text = "Choose a course";
1.37      raeburn  1389:             } 
1.28      raeburn  1390:             &Apache::lonhtmlcommon::add_breadcrumb
1.37      raeburn  1391:             ({href=>"javascript:changePage(document.$firstform,'')",
1.48      raeburn  1392:               text=>"Course/Community search"},
1.37      raeburn  1393:               {href=>"javascript:changePage(document.$phase,'courselist')",
1.48      raeburn  1394:               text=>$choose_text});
1.28      raeburn  1395:             if ($phase eq 'courselist') {
                   1396:                 &print_course_selection_page($r,$dom,$domdesc);
                   1397:             } else {
                   1398:                 my ($checked,$cdesc) = &check_course($r,$dom,$domdesc);
                   1399:                 if ($checked eq 'ok') {
1.48      raeburn  1400:                     my $enter_text;
                   1401:                     if ($type eq 'Community') {
                   1402:                         $enter_text = 'Enter community';
                   1403:                     } else {
                   1404:                         $enter_text = 'Enter course';
                   1405:                     }
1.28      raeburn  1406:                     if ($phase eq 'menu') {
1.37      raeburn  1407:                         &Apache::lonhtmlcommon::add_breadcrumb
                   1408:                         ({href=>"javascript:changePage(document.$phase,'menu')",
                   1409:                           text=>"Pick action"});
1.48      raeburn  1410:                         &print_modification_menu($r,$cdesc,$domdesc,$dom,$type);
1.37      raeburn  1411:                     } elsif ($phase eq 'ccrole') {
                   1412:                         &Apache::lonhtmlcommon::add_breadcrumb
                   1413:                          ({href=>"javascript:changePage(document.$phase,'ccrole')",
1.48      raeburn  1414:                            text=>$enter_text});
                   1415:                         &print_ccrole_selected($r,$type);
1.28      raeburn  1416:                     } else {
1.37      raeburn  1417:                         &Apache::lonhtmlcommon::add_breadcrumb
                   1418:                         ({href=>"javascript:changePage(document.$phase,'menu')",
                   1419:                           text=>"Pick action"});
1.28      raeburn  1420:                         my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
                   1421:                         if ($phase eq 'setquota') {
                   1422:                             &Apache::lonhtmlcommon::add_breadcrumb
                   1423:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   1424:                               text=>"Set quota"});
1.38      raeburn  1425:                             &print_setquota($r,$cdom,$cnum,$cdesc,$type);
1.28      raeburn  1426:                         } elsif ($phase eq 'processquota') { 
                   1427:                             &Apache::lonhtmlcommon::add_breadcrumb
                   1428:                             ({href=>"javascript:changePage(document.$phase,'setquota')",
                   1429:                               text=>"Set quota"});
                   1430:                             &Apache::lonhtmlcommon::add_breadcrumb
                   1431:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   1432:                               text=>"Result"});
1.48      raeburn  1433:                             &modify_quota($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.28      raeburn  1434:                         } elsif ($phase eq 'viewparms') {  
                   1435:                             &Apache::lonhtmlcommon::add_breadcrumb
                   1436:                             ({href=>"javascript:changePage(document.$phase,'viewparms')",
                   1437:                               text=>"Display settings"});
                   1438:                             &print_settings_display($r,$cdom,$cnum,$cdesc,$type);
                   1439:                         } elsif ($phase eq 'setparms') {
                   1440:                             &Apache::lonhtmlcommon::add_breadcrumb
                   1441:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   1442:                               text=>"Change settings"});
1.48      raeburn  1443:                             &print_course_modification_page($r,$cdom,$cnum,$cdesc,$type);
1.28      raeburn  1444:                         } elsif ($phase eq 'processparms') {
                   1445:                             &Apache::lonhtmlcommon::add_breadcrumb
                   1446:                             ({href=>"javascript:changePage(document.$phase,'setparms')",
                   1447:                               text=>"Change settings"});
                   1448:                             &Apache::lonhtmlcommon::add_breadcrumb
                   1449:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   1450:                               text=>"Result"});
1.30      raeburn  1451:                             &modify_course($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.38      raeburn  1452:                         } elsif ($phase eq 'catsettings') {
                   1453:                             &Apache::lonhtmlcommon::add_breadcrumb
                   1454:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   1455:                               text=>"Catalog settings"});
                   1456:                             &print_catsettings($r,$cdom,$cnum,$cdesc,$type);
                   1457:                         } elsif ($phase eq 'processcat') {
                   1458:                             &Apache::lonhtmlcommon::add_breadcrumb
                   1459:                             ({href=>"javascript:changePage(document.$phase,'catsettings')",
                   1460:                               text=>"Catalog settings"});
                   1461:                             &Apache::lonhtmlcommon::add_breadcrumb
                   1462:                             ({href=>"javascript:changePage(document.$phase,'$phase')",
                   1463:                               text=>"Result"});
1.48      raeburn  1464:                             &modify_catsettings($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.28      raeburn  1465:                         }
                   1466:                     }
                   1467:                 } else {
1.48      raeburn  1468:                     $r->print('<span class="LC_error">');
                   1469:                     if ($type eq 'Community') {
                   1470:                         $r->print(&mt('The course you selected is not a valid course in this domain'));
                   1471:                     } else {
                   1472:                         $r->print(&mt('The community you selected is not a valid community in this domain'));
                   1473:                     }
                   1474:                     $r->print(" ($domdesc)</span>");
1.28      raeburn  1475:                 }
                   1476:             }
1.1       raeburn  1477:         }
1.28      raeburn  1478:         &print_footer($r);
1.1       raeburn  1479:     } else {
1.16      albertel 1480:         $env{'user.error.msg'}=
1.48      raeburn  1481:         "/adm/modifycourse:ccc:0:0:Cannot modify course/community settings";
1.1       raeburn  1482:         return HTTP_NOT_ACCEPTABLE;
                   1483:     }
                   1484:     return OK;
                   1485: }
                   1486: 
                   1487: 1;
                   1488: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>